Skip to content

Commit d9472ee

Browse files
authored
Merge pull request #257 from line/next
Release 7.1.0
2 parents d75cbf8 + 09cfee4 commit d9472ee

File tree

9 files changed

+210
-40
lines changed

9 files changed

+210
-40
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## 7.1.0 (18 Sep 2020)
2+
3+
### Feature
4+
* Messaging API - August 2020 update (#240)(#251)(#258)
5+
* Messaging API - September 2020 update (#248)
6+
* Add Video viewing complete event (#241)
7+
* Channel access token v2.1 support key id (#231)
8+
* OAuth API v2.1 endpoint change (#233)
9+
10+
### Bug fix
11+
* Accept label in richmenu area actions (#246)
12+
* Update dependencies & fix format (#234)(#236)(#238)(#243)(#250)
13+
* fix: fix createUploadAudienceGroup & updateUploadAudienceGroup API doc (#249)
14+
15+
### Misc
16+
* Add Release CI & change release flow (#256)
17+
* Add: build doc github workflow
18+
119
## 7.0.0 (15 June 2020)
220

321
### Breaking Changes

docs/api-reference/client.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class Client {
8383
// AudienceGroup
8484
createUploadAudienceGroup(uploadAudienceGroup: {
8585
description: string;
86-
isIfaAudience: boolean;
87-
audiences: { id: string }[];
86+
isIfaAudience?: boolean;
87+
audiences?: { id: string }[];
8888
uploadDescription?: string;
8989
}) : Promise<{
9090
audienceGroupId: number;
@@ -93,15 +93,36 @@ class Client {
9393
created: number;
9494
requestId: string;
9595
}>
96+
createUploadAudienceGroupByFile(uploadAudienceGroup: {
97+
description: string;
98+
isIfaAudience?: boolean;
99+
uploadDescription?: string;
100+
file: Buffer | Readable;
101+
}) : Promise<{
102+
audienceGroupId: number;
103+
type: "UPLOAD";
104+
description: string;
105+
created: number;
106+
}>
96107
updateUploadAudienceGroup(
97108
uploadAudienceGroup: {
98109
audienceGroupId: number;
99110
description?: string;
100111
uploadDescription?: string;
101112
audiences: { id: string }[];
102113
},
114+
// for set request timeout
103115
httpConfig?: Partial<AxiosRequestConfig>,
104-
): Promise<{}>
116+
) : Promise<{}>
117+
createUploadAudienceGroupByFile(
118+
uploadAudienceGroup: {
119+
audienceGroupId: number;
120+
uploadDescription?: string;
121+
file: Buffer | Readable;
122+
},
123+
// for set request timeout
124+
httpConfig?: Partial<AxiosRequestConfig>,
125+
}) : Promise<{}>
105126
createClickAudienceGroup(clickAudienceGroup: {
106127
description: string;
107128
requestId: string;

lib/client.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { Readable } from "stream";
22
import HTTPClient from "./http";
33
import * as Types from "./types";
44
import { AxiosResponse, AxiosRequestConfig } from "axios";
5-
6-
import { ensureJSON, toArray } from "./utils";
5+
import { createMultipartFormData, ensureJSON, toArray } from "./utils";
76

87
type ChatType = "group" | "room";
98
type RequestOption = {
@@ -455,8 +454,8 @@ export default class Client {
455454

456455
public async createUploadAudienceGroup(uploadAudienceGroup: {
457456
description: string;
458-
isIfaAudience: boolean;
459-
audiences: { id: string }[];
457+
isIfaAudience?: boolean;
458+
audiences?: { id: string }[];
460459
uploadDescription?: string;
461460
}) {
462461
const res = await this.http.post<{
@@ -470,6 +469,25 @@ export default class Client {
470469
return ensureJSON(res);
471470
}
472471

472+
public async createUploadAudienceGroupByFile(uploadAudienceGroup: {
473+
description: string;
474+
isIfaAudience?: boolean;
475+
uploadDescription?: string;
476+
file: Buffer | Readable;
477+
}) {
478+
const file = await this.http.toBuffer(uploadAudienceGroup.file);
479+
const body = createMultipartFormData({ ...uploadAudienceGroup, file });
480+
const res = await this.http.post<{
481+
audienceGroupId: number;
482+
type: "UPLOAD";
483+
description: string;
484+
created: number;
485+
}>(`${DATA_API_PREFIX}/audienceGroup/upload/byFile`, body, {
486+
headers: body.getHeaders(),
487+
});
488+
return ensureJSON(res);
489+
}
490+
473491
public async updateUploadAudienceGroup(
474492
uploadAudienceGroup: {
475493
audienceGroupId: number;
@@ -490,6 +508,26 @@ export default class Client {
490508
return ensureJSON(res);
491509
}
492510

511+
public async updateUploadAudienceGroupByFile(
512+
uploadAudienceGroup: {
513+
audienceGroupId: number;
514+
uploadDescription?: string;
515+
file: Buffer | Readable;
516+
},
517+
// for set request timeout
518+
httpConfig?: Partial<AxiosRequestConfig>,
519+
) {
520+
const file = await this.http.toBuffer(uploadAudienceGroup.file);
521+
const body = createMultipartFormData({ ...uploadAudienceGroup, file });
522+
523+
const res = await this.http.put<{}>(
524+
`${DATA_API_PREFIX}/audienceGroup/upload/byFile`,
525+
body,
526+
{ headers: body.getHeaders(), ...httpConfig },
527+
);
528+
return ensureJSON(res);
529+
}
530+
493531
public async createClickAudienceGroup(clickAudienceGroup: {
494532
description: string;
495533
requestId: string;

lib/http.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,31 @@ export default class HTTPClient {
9696
return res.data;
9797
}
9898

99+
public async toBuffer(data: Buffer | Readable) {
100+
if (Buffer.isBuffer(data)) {
101+
return data;
102+
} else if (data instanceof Readable) {
103+
return await new Promise<Buffer>((resolve, reject) => {
104+
const buffers: Buffer[] = [];
105+
let size = 0;
106+
data.on("data", (chunk: Buffer) => {
107+
buffers.push(chunk);
108+
size += chunk.length;
109+
});
110+
data.on("end", () => resolve(Buffer.concat(buffers, size)));
111+
data.on("error", reject);
112+
});
113+
} else {
114+
throw new Error("invalid data type for binary data");
115+
}
116+
}
117+
99118
public async postBinary<T>(
100119
url: string,
101120
data: Buffer | Readable,
102121
contentType?: string,
103122
): Promise<T> {
104-
const buffer = await (async (): Promise<Buffer> => {
105-
if (Buffer.isBuffer(data)) {
106-
return data;
107-
} else if (data instanceof Readable) {
108-
return new Promise<Buffer>((resolve, reject) => {
109-
const buffers: Buffer[] = [];
110-
let size = 0;
111-
data.on("data", (chunk: Buffer) => {
112-
buffers.push(chunk);
113-
size += chunk.length;
114-
});
115-
data.on("end", () => resolve(Buffer.concat(buffers, size)));
116-
data.on("error", reject);
117-
});
118-
} else {
119-
throw new Error("invalid data type for postBinary");
120-
}
121-
})();
123+
const buffer = await this.toBuffer(data);
122124

123125
const res = await this.instance.post(url, buffer, {
124126
headers: {

lib/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { JSONParseError } from "./exceptions";
2+
import * as FormData from "form-data";
23

34
export function toArray<T>(maybeArr: T | T[]): T[] {
45
return Array.isArray(maybeArr) ? maybeArr : [maybeArr];
@@ -11,3 +12,18 @@ export function ensureJSON<T>(raw: T): T {
1112
throw new JSONParseError("Failed to parse response body as JSON", raw);
1213
}
1314
}
15+
16+
export function createMultipartFormData(
17+
this: FormData | void,
18+
formBody: Record<string, any>,
19+
): FormData {
20+
const formData = this instanceof FormData ? this : new FormData();
21+
Object.entries(formBody).forEach(([key, value]) => {
22+
if (Buffer.isBuffer(value) || value instanceof Uint8Array) {
23+
formData.append(key, value);
24+
} else {
25+
formData.append(key, String(value));
26+
}
27+
});
28+
return formData;
29+
}

package-lock.json

Lines changed: 18 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@line/bot-sdk",
3-
"version": "7.0.0",
3+
"version": "7.1.0",
44
"description": "Node.js SDK for LINE Messaging API",
55
"engines": {
66
"node": ">=10"
@@ -40,7 +40,8 @@
4040
"@types/node": "^14.10.0",
4141
"axios": "^0.20.0",
4242
"body-parser": "^1.19.0",
43-
"file-type": "^15.0.0"
43+
"file-type": "^15.0.0",
44+
"form-data": "^3.0.0"
4445
},
4546
"devDependencies": {
4647
"@types/express": "^4.17.8",

scripts/generate-changelog.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ npm run generate-changelog
99

1010
git add -A
1111
git commit -m "(Changelog CI) Added Changelog"
12-
git push -u origin ${GITHUB_HEAD_REF} --tags
12+
git push -u origin ${GITHUB_HEAD_REF}

0 commit comments

Comments
 (0)