abbot-http-client 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +16 -15
- package/dist/index.d.cts +20 -18
- package/dist/index.d.ts +20 -18
- package/dist/index.js +16 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -164,11 +164,12 @@ var CoreHttp = class {
|
|
|
164
164
|
constructor(config) {
|
|
165
165
|
this.config = config;
|
|
166
166
|
}
|
|
167
|
-
createAxiosInstance(
|
|
167
|
+
createAxiosInstance() {
|
|
168
168
|
const axios2 = axiosConf(this.config);
|
|
169
169
|
const iv = Secure.createId();
|
|
170
170
|
const cryp = new Cryp({
|
|
171
|
-
iv
|
|
171
|
+
iv,
|
|
172
|
+
keyValue: ""
|
|
172
173
|
});
|
|
173
174
|
axios2.interceptors.request.use(
|
|
174
175
|
(config) => {
|
|
@@ -193,10 +194,10 @@ var CoreHttp = class {
|
|
|
193
194
|
}
|
|
194
195
|
req.headers.set("data-code", iv);
|
|
195
196
|
if (this.config.app?.trackingId) {
|
|
196
|
-
|
|
197
|
+
config.headers.set("X-Trace-Id", this.config.app.trackingId);
|
|
197
198
|
}
|
|
198
|
-
if (
|
|
199
|
-
|
|
199
|
+
if (this.config.app.userJwt) {
|
|
200
|
+
config.headers.setAuthorization(`Bearer ${this.config.app.userJwt}`);
|
|
200
201
|
}
|
|
201
202
|
return req;
|
|
202
203
|
},
|
|
@@ -282,24 +283,23 @@ var CoreHttp = class {
|
|
|
282
283
|
);
|
|
283
284
|
return axios2;
|
|
284
285
|
}
|
|
285
|
-
async post(url, param
|
|
286
|
-
const axios2 = this.createAxiosInstance(
|
|
286
|
+
async post(url, param) {
|
|
287
|
+
const axios2 = this.createAxiosInstance();
|
|
287
288
|
const response = await axios2.post(url, param);
|
|
288
289
|
return response;
|
|
289
290
|
}
|
|
290
|
-
async get(url
|
|
291
|
-
const axios2 = this.createAxiosInstance(
|
|
291
|
+
async get(url) {
|
|
292
|
+
const axios2 = this.createAxiosInstance();
|
|
292
293
|
const response = await axios2.get(url);
|
|
293
294
|
return response;
|
|
294
295
|
}
|
|
295
|
-
async uploadFile(url, file, param1, param2
|
|
296
|
+
async uploadFile(url, file, param1, param2) {
|
|
296
297
|
let response;
|
|
297
298
|
const formData = new FormData();
|
|
298
299
|
if (file instanceof Array) {
|
|
299
300
|
const fileKeys = param1;
|
|
300
301
|
const param = param2;
|
|
301
|
-
const
|
|
302
|
-
const axios2 = this.createAxiosInstance(jwt);
|
|
302
|
+
const axios2 = this.createAxiosInstance();
|
|
303
303
|
fileKeys.forEach((k, i) => {
|
|
304
304
|
formData.append(k, file[i]);
|
|
305
305
|
});
|
|
@@ -309,8 +309,7 @@ var CoreHttp = class {
|
|
|
309
309
|
response = await axios2.post(url, formData);
|
|
310
310
|
} else {
|
|
311
311
|
const param = param1;
|
|
312
|
-
const
|
|
313
|
-
const axios2 = this.createAxiosInstance(jwt);
|
|
312
|
+
const axios2 = this.createAxiosInstance();
|
|
314
313
|
if (param) {
|
|
315
314
|
formData.append("param", JSON.stringify(param));
|
|
316
315
|
}
|
|
@@ -340,7 +339,9 @@ var cfg = {
|
|
|
340
339
|
redirectUrl: "/login",
|
|
341
340
|
apiKey: "",
|
|
342
341
|
timezone: "Asia/Bangkok",
|
|
343
|
-
trackingId: ""
|
|
342
|
+
trackingId: "",
|
|
343
|
+
ecnKey: void 0,
|
|
344
|
+
userJwt: void 0
|
|
344
345
|
}
|
|
345
346
|
};
|
|
346
347
|
function getConfig() {
|
package/dist/index.d.cts
CHANGED
|
@@ -6,32 +6,34 @@ declare class CoreHttp {
|
|
|
6
6
|
private config;
|
|
7
7
|
constructor(config: AbbotConfig);
|
|
8
8
|
private createAxiosInstance;
|
|
9
|
-
post<T>(url: string, param?: Record<string, any> | null
|
|
10
|
-
get<T>(url: string
|
|
11
|
-
uploadFile<T>(url: string, file: File, param?: Record<string, any> | null
|
|
12
|
-
uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null
|
|
9
|
+
post<T>(url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
10
|
+
get<T>(url: string): Promise<AxiosResponse<T>>;
|
|
11
|
+
uploadFile<T>(url: string, file: File, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
12
|
+
uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
13
13
|
getConfig(): AbbotConfig;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
interface AbbotConfig {
|
|
17
|
-
axios
|
|
18
|
-
baseUrl
|
|
19
|
-
headers
|
|
20
|
-
accept
|
|
21
|
-
lang
|
|
22
|
-
post
|
|
23
|
-
contentType
|
|
17
|
+
axios: {
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
headers: {
|
|
20
|
+
accept: string;
|
|
21
|
+
lang: string;
|
|
22
|
+
post: {
|
|
23
|
+
contentType: string;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
-
timeout
|
|
26
|
+
timeout: number;
|
|
27
27
|
};
|
|
28
|
-
app
|
|
29
|
-
redirectUrl
|
|
30
|
-
apiKey
|
|
31
|
-
timezone
|
|
32
|
-
trackingId
|
|
28
|
+
app: {
|
|
29
|
+
redirectUrl: string;
|
|
30
|
+
apiKey: string;
|
|
31
|
+
timezone: string;
|
|
32
|
+
trackingId: string;
|
|
33
|
+
ecnKey: string | undefined;
|
|
34
|
+
userJwt: string | undefined;
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
|
-
declare function create(config: AbbotConfig): CoreHttp;
|
|
37
|
+
declare function create(config: Partial<AbbotConfig>): CoreHttp;
|
|
36
38
|
|
|
37
39
|
export { type AbbotConfig, catchError, create };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,32 +6,34 @@ declare class CoreHttp {
|
|
|
6
6
|
private config;
|
|
7
7
|
constructor(config: AbbotConfig);
|
|
8
8
|
private createAxiosInstance;
|
|
9
|
-
post<T>(url: string, param?: Record<string, any> | null
|
|
10
|
-
get<T>(url: string
|
|
11
|
-
uploadFile<T>(url: string, file: File, param?: Record<string, any> | null
|
|
12
|
-
uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null
|
|
9
|
+
post<T>(url: string, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
10
|
+
get<T>(url: string): Promise<AxiosResponse<T>>;
|
|
11
|
+
uploadFile<T>(url: string, file: File, param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
12
|
+
uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null): Promise<AxiosResponse<T>>;
|
|
13
13
|
getConfig(): AbbotConfig;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
interface AbbotConfig {
|
|
17
|
-
axios
|
|
18
|
-
baseUrl
|
|
19
|
-
headers
|
|
20
|
-
accept
|
|
21
|
-
lang
|
|
22
|
-
post
|
|
23
|
-
contentType
|
|
17
|
+
axios: {
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
headers: {
|
|
20
|
+
accept: string;
|
|
21
|
+
lang: string;
|
|
22
|
+
post: {
|
|
23
|
+
contentType: string;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
-
timeout
|
|
26
|
+
timeout: number;
|
|
27
27
|
};
|
|
28
|
-
app
|
|
29
|
-
redirectUrl
|
|
30
|
-
apiKey
|
|
31
|
-
timezone
|
|
32
|
-
trackingId
|
|
28
|
+
app: {
|
|
29
|
+
redirectUrl: string;
|
|
30
|
+
apiKey: string;
|
|
31
|
+
timezone: string;
|
|
32
|
+
trackingId: string;
|
|
33
|
+
ecnKey: string | undefined;
|
|
34
|
+
userJwt: string | undefined;
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
|
-
declare function create(config: AbbotConfig): CoreHttp;
|
|
37
|
+
declare function create(config: Partial<AbbotConfig>): CoreHttp;
|
|
36
38
|
|
|
37
39
|
export { type AbbotConfig, catchError, create };
|
package/dist/index.js
CHANGED
|
@@ -127,11 +127,12 @@ var CoreHttp = class {
|
|
|
127
127
|
constructor(config) {
|
|
128
128
|
this.config = config;
|
|
129
129
|
}
|
|
130
|
-
createAxiosInstance(
|
|
130
|
+
createAxiosInstance() {
|
|
131
131
|
const axios2 = axiosConf(this.config);
|
|
132
132
|
const iv = Secure.createId();
|
|
133
133
|
const cryp = new Cryp({
|
|
134
|
-
iv
|
|
134
|
+
iv,
|
|
135
|
+
keyValue: ""
|
|
135
136
|
});
|
|
136
137
|
axios2.interceptors.request.use(
|
|
137
138
|
(config) => {
|
|
@@ -156,10 +157,10 @@ var CoreHttp = class {
|
|
|
156
157
|
}
|
|
157
158
|
req.headers.set("data-code", iv);
|
|
158
159
|
if (this.config.app?.trackingId) {
|
|
159
|
-
|
|
160
|
+
config.headers.set("X-Trace-Id", this.config.app.trackingId);
|
|
160
161
|
}
|
|
161
|
-
if (
|
|
162
|
-
|
|
162
|
+
if (this.config.app.userJwt) {
|
|
163
|
+
config.headers.setAuthorization(`Bearer ${this.config.app.userJwt}`);
|
|
163
164
|
}
|
|
164
165
|
return req;
|
|
165
166
|
},
|
|
@@ -245,24 +246,23 @@ var CoreHttp = class {
|
|
|
245
246
|
);
|
|
246
247
|
return axios2;
|
|
247
248
|
}
|
|
248
|
-
async post(url, param
|
|
249
|
-
const axios2 = this.createAxiosInstance(
|
|
249
|
+
async post(url, param) {
|
|
250
|
+
const axios2 = this.createAxiosInstance();
|
|
250
251
|
const response = await axios2.post(url, param);
|
|
251
252
|
return response;
|
|
252
253
|
}
|
|
253
|
-
async get(url
|
|
254
|
-
const axios2 = this.createAxiosInstance(
|
|
254
|
+
async get(url) {
|
|
255
|
+
const axios2 = this.createAxiosInstance();
|
|
255
256
|
const response = await axios2.get(url);
|
|
256
257
|
return response;
|
|
257
258
|
}
|
|
258
|
-
async uploadFile(url, file, param1, param2
|
|
259
|
+
async uploadFile(url, file, param1, param2) {
|
|
259
260
|
let response;
|
|
260
261
|
const formData = new FormData();
|
|
261
262
|
if (file instanceof Array) {
|
|
262
263
|
const fileKeys = param1;
|
|
263
264
|
const param = param2;
|
|
264
|
-
const
|
|
265
|
-
const axios2 = this.createAxiosInstance(jwt);
|
|
265
|
+
const axios2 = this.createAxiosInstance();
|
|
266
266
|
fileKeys.forEach((k, i) => {
|
|
267
267
|
formData.append(k, file[i]);
|
|
268
268
|
});
|
|
@@ -272,8 +272,7 @@ var CoreHttp = class {
|
|
|
272
272
|
response = await axios2.post(url, formData);
|
|
273
273
|
} else {
|
|
274
274
|
const param = param1;
|
|
275
|
-
const
|
|
276
|
-
const axios2 = this.createAxiosInstance(jwt);
|
|
275
|
+
const axios2 = this.createAxiosInstance();
|
|
277
276
|
if (param) {
|
|
278
277
|
formData.append("param", JSON.stringify(param));
|
|
279
278
|
}
|
|
@@ -303,7 +302,9 @@ var cfg = {
|
|
|
303
302
|
redirectUrl: "/login",
|
|
304
303
|
apiKey: "",
|
|
305
304
|
timezone: "Asia/Bangkok",
|
|
306
|
-
trackingId: ""
|
|
305
|
+
trackingId: "",
|
|
306
|
+
ecnKey: void 0,
|
|
307
|
+
userJwt: void 0
|
|
307
308
|
}
|
|
308
309
|
};
|
|
309
310
|
function getConfig() {
|