Skip to content

Commit 2b7783d

Browse files
authored
Do not override base url (#836)
## Changes The constructor of line-bot-sdk-nodejs client modifies the given config, which should ideally behave immutably. Reusing the config as is can lead to unexpected behavior(see below sample `#2`). This change ensures that the config is not unintentionally overwritten. ## How to reproduce this (normal) ```ts // #1 (it works, but `config`'s baseURL is updated expectedly) const config = { channelAccessToken: "token-token", }; const blobClient = new messagingApi.MessagingApiBlobClient(config); // config.baseURL -> https://api-data.line.me (Unexpected, but it works) ``` (this issue) Executing the following code does not set `api.line-data.me`. A workaround is to clone the config, but this is not convenient and debugging can be troublesome. ```ts // #2 (blob doesn't work, because the first unexpected update blocks blob client uses expected baseURL) const config = { channelAccessToken: "token-token", }; const client = new messagingApi.MessagingApiClient(config); // config.baseURL -> https://api.line.me const blobClient = new messagingApi.MessagingApiBlobClient(config); // config.baseURL -> https://api.line.me, not https://api-data.line.me (Unexpected, and it won't work) ```
1 parent f986b45 commit 2b7783d

File tree

12 files changed

+34
-44
lines changed

12 files changed

+34
-44
lines changed

generator/src/main/resources/line-bot-sdk-nodejs-generator/api-single.pebble

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ export class {{operations.classname}} {
3030
private httpClient: HTTPFetchClient;
3131

3232
constructor(config: httpClientConfig) {
33-
if (!config.baseURL) {
34-
config.baseURL = '{{endpoint(operations.classname)}}';
35-
}
33+
const baseURL = config.baseURL || '{{endpoint(operations.classname)}}';
3634
this.httpClient = new HTTPFetchClient({
3735
defaultHeaders: {
3836
{% if authMethods != null -%}
3937
Authorization: "Bearer " + config.channelAccessToken,
4038
{% endif -%}
4139
},
42-
baseURL: config.baseURL,
40+
baseURL: baseURL,
4341
});
4442
}
4543

lib/channel-access-token/api/channelAccessTokenClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ export class ChannelAccessTokenClient {
3939
private httpClient: HTTPFetchClient;
4040

4141
constructor(config: httpClientConfig) {
42-
if (!config.baseURL) {
43-
config.baseURL = "https://api.line.me";
44-
}
42+
const baseURL = config.baseURL || "https://api.line.me";
4543
this.httpClient = new HTTPFetchClient({
4644
defaultHeaders: {},
47-
baseURL: config.baseURL,
45+
baseURL: baseURL,
4846
});
4947
}
5048

lib/insight/api/insightClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ export class InsightClient {
3939
private httpClient: HTTPFetchClient;
4040

4141
constructor(config: httpClientConfig) {
42-
if (!config.baseURL) {
43-
config.baseURL = "https://api.line.me";
44-
}
42+
const baseURL = config.baseURL || "https://api.line.me";
4543
this.httpClient = new HTTPFetchClient({
4644
defaultHeaders: {
4745
Authorization: "Bearer " + config.channelAccessToken,
4846
},
49-
baseURL: config.baseURL,
47+
baseURL: baseURL,
5048
});
5149
}
5250

lib/liff/api/liffClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ export class LiffClient {
3838
private httpClient: HTTPFetchClient;
3939

4040
constructor(config: httpClientConfig) {
41-
if (!config.baseURL) {
42-
config.baseURL = "https://api.line.me";
43-
}
41+
const baseURL = config.baseURL || "https://api.line.me";
4442
this.httpClient = new HTTPFetchClient({
4543
defaultHeaders: {
4644
Authorization: "Bearer " + config.channelAccessToken,
4745
},
48-
baseURL: config.baseURL,
46+
baseURL: baseURL,
4947
});
5048
}
5149

lib/manage-audience/api/manageAudienceBlobClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ export class ManageAudienceBlobClient {
3535
private httpClient: HTTPFetchClient;
3636

3737
constructor(config: httpClientConfig) {
38-
if (!config.baseURL) {
39-
config.baseURL = "https://api-data.line.me";
40-
}
38+
const baseURL = config.baseURL || "https://api-data.line.me";
4139
this.httpClient = new HTTPFetchClient({
4240
defaultHeaders: {
4341
Authorization: "Bearer " + config.channelAccessToken,
4442
},
45-
baseURL: config.baseURL,
43+
baseURL: baseURL,
4644
});
4745
}
4846

lib/manage-audience/api/manageAudienceClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ export class ManageAudienceClient {
4949
private httpClient: HTTPFetchClient;
5050

5151
constructor(config: httpClientConfig) {
52-
if (!config.baseURL) {
53-
config.baseURL = "https://api.line.me";
54-
}
52+
const baseURL = config.baseURL || "https://api.line.me";
5553
this.httpClient = new HTTPFetchClient({
5654
defaultHeaders: {
5755
Authorization: "Bearer " + config.channelAccessToken,
5856
},
59-
baseURL: config.baseURL,
57+
baseURL: baseURL,
6058
});
6159
}
6260

lib/messaging-api/api/messagingApiBlobClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ export class MessagingApiBlobClient {
3535
private httpClient: HTTPFetchClient;
3636

3737
constructor(config: httpClientConfig) {
38-
if (!config.baseURL) {
39-
config.baseURL = "https://api-data.line.me";
40-
}
38+
const baseURL = config.baseURL || "https://api-data.line.me";
4139
this.httpClient = new HTTPFetchClient({
4240
defaultHeaders: {
4341
Authorization: "Bearer " + config.channelAccessToken,
4442
},
45-
baseURL: config.baseURL,
43+
baseURL: baseURL,
4644
});
4745
}
4846

lib/messaging-api/api/messagingApiClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,12 @@ export class MessagingApiClient {
8181
private httpClient: HTTPFetchClient;
8282

8383
constructor(config: httpClientConfig) {
84-
if (!config.baseURL) {
85-
config.baseURL = "https://api.line.me";
86-
}
84+
const baseURL = config.baseURL || "https://api.line.me";
8785
this.httpClient = new HTTPFetchClient({
8886
defaultHeaders: {
8987
Authorization: "Bearer " + config.channelAccessToken,
9088
},
91-
baseURL: config.baseURL,
89+
baseURL: baseURL,
9290
});
9391
}
9492

lib/module-attach/api/lineModuleAttachClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ export class LineModuleAttachClient {
3535
private httpClient: HTTPFetchClient;
3636

3737
constructor(config: httpClientConfig) {
38-
if (!config.baseURL) {
39-
config.baseURL = "https://manager.line.biz";
40-
}
38+
const baseURL = config.baseURL || "https://manager.line.biz";
4139
this.httpClient = new HTTPFetchClient({
4240
defaultHeaders: {
4341
Authorization: "Bearer " + config.channelAccessToken,
4442
},
45-
baseURL: config.baseURL,
43+
baseURL: baseURL,
4644
});
4745
}
4846

lib/module/api/lineModuleClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ export class LineModuleClient {
3737
private httpClient: HTTPFetchClient;
3838

3939
constructor(config: httpClientConfig) {
40-
if (!config.baseURL) {
41-
config.baseURL = "https://api.line.me";
42-
}
40+
const baseURL = config.baseURL || "https://api.line.me";
4341
this.httpClient = new HTTPFetchClient({
4442
defaultHeaders: {
4543
Authorization: "Bearer " + config.channelAccessToken,
4644
},
47-
baseURL: config.baseURL,
45+
baseURL: baseURL,
4846
});
4947
}
5048

0 commit comments

Comments
 (0)