abbot-http-client 0.0.29 → 0.0.30

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 CHANGED
@@ -122,9 +122,9 @@ var Cryp = class {
122
122
  keyBuffer;
123
123
  iv;
124
124
  algConfig;
125
- constructor(cryptProps) {
125
+ constructor(cryptProps, apiKey) {
126
126
  this.ivText = cryptProps.iv;
127
- this.key = cryptProps.keyValue ? cryptProps.keyValue : ES.d(ES.b2a(AbbotHttp.getConfig().app.apiKey));
127
+ this.key = cryptProps.keyValue ? cryptProps.keyValue : ES.d(ES.b2a(apiKey));
128
128
  this.keyBuffer = import_crypto_ts.enc.Utf8.parse(this.key);
129
129
  this.iv = import_crypto_ts.enc.Utf8.parse(this.ivText);
130
130
  this.algConfig = { mode: import_crypto_ts.mode.CBC, padding: import_crypto_ts.pad.PKCS7, iv: this.iv };
@@ -200,14 +200,11 @@ function axiosConf(cfg) {
200
200
 
201
201
  // src/http.ts
202
202
  var AbbotHttp = class {
203
- static config = defaultConfig;
204
- static initConfig(config) {
203
+ config = defaultConfig;
204
+ initConfig(config) {
205
205
  this.config = this.deepMerge(this.config, config);
206
206
  }
207
- static getConfig() {
208
- return this.config;
209
- }
210
- static deepMerge(target, source) {
207
+ deepMerge(target, source) {
211
208
  for (const key in source) {
212
209
  const srcVal = source[key];
213
210
  if (srcVal && typeof srcVal === "object" && !Array.isArray(srcVal)) {
@@ -218,7 +215,7 @@ var AbbotHttp = class {
218
215
  }
219
216
  return target;
220
217
  }
221
- static createAxiosInstance(option) {
218
+ createAxiosInstance(option) {
222
219
  const axios2 = axiosConf(this.config);
223
220
  if (this.config.useAxiosInterceptors) {
224
221
  const { cryp, iv } = this.prepareRequestConfig(option);
@@ -271,7 +268,7 @@ var AbbotHttp = class {
271
268
  }
272
269
  return axios2;
273
270
  }
274
- static prepareRequestConfig(option) {
271
+ prepareRequestConfig(option) {
275
272
  const iv = Secure.createId();
276
273
  if (this.config.devMode) {
277
274
  console.log({
@@ -279,14 +276,17 @@ var AbbotHttp = class {
279
276
  keyValue: option?.isInit ? void 0 : this.config.app.encKey
280
277
  });
281
278
  }
282
- const cryp = new Cryp({
283
- iv,
284
- keyValue: option?.isInit ? void 0 : this.config.app.encKey
285
- });
279
+ const cryp = new Cryp(
280
+ {
281
+ iv,
282
+ keyValue: option?.isInit ? void 0 : this.config.app.encKey
283
+ },
284
+ this.config.app.apiKey
285
+ );
286
286
  const form = new URLSearchParams();
287
287
  return { cryp, iv, form };
288
288
  }
289
- static createAxiosRequestObj(iv) {
289
+ createAxiosRequestObj(iv) {
290
290
  const headers = {
291
291
  "data-code": iv
292
292
  };
@@ -298,7 +298,7 @@ var AbbotHttp = class {
298
298
  }
299
299
  return headers;
300
300
  }
301
- static habdleError(error, cryp) {
301
+ habdleError(error, cryp) {
302
302
  const err = {
303
303
  message: error.message,
304
304
  code: error.code,
@@ -369,7 +369,7 @@ var AbbotHttp = class {
369
369
  );
370
370
  }
371
371
  }
372
- static async post(url, param, option) {
372
+ async post(url, param, option) {
373
373
  const axios2 = this.createAxiosInstance(option);
374
374
  if (!this.config.useAxiosInterceptors) {
375
375
  const { cryp, iv, form } = this.prepareRequestConfig(option);
@@ -392,7 +392,7 @@ var AbbotHttp = class {
392
392
  return response;
393
393
  }
394
394
  }
395
- static async get(url, option) {
395
+ async get(url, option) {
396
396
  const axios2 = this.createAxiosInstance(option);
397
397
  if (!this.config.useAxiosInterceptors) {
398
398
  const { cryp, iv } = this.prepareRequestConfig(option);
@@ -412,7 +412,7 @@ var AbbotHttp = class {
412
412
  return response;
413
413
  }
414
414
  }
415
- static async uploadFile(url, file, param1, param2, param3) {
415
+ async uploadFile(url, file, param1, param2, param3) {
416
416
  let response;
417
417
  const formData = new FormData();
418
418
  if (file instanceof Array) {
@@ -441,6 +441,9 @@ var AbbotHttp = class {
441
441
  }
442
442
  return response;
443
443
  }
444
+ getConfig() {
445
+ return this.config;
446
+ }
444
447
  };
445
448
  // Annotate the CommonJS export names for ESM import in node:
446
449
  0 && (module.exports = {
package/dist/index.d.cts CHANGED
@@ -9,7 +9,7 @@ declare class Cryp {
9
9
  constructor(cryptProps: {
10
10
  iv: string;
11
11
  keyValue?: string;
12
- });
12
+ }, apiKey: string);
13
13
  encrypt(textValue?: string): string;
14
14
  decrypt<T>(encryptedValue?: string): T | null;
15
15
  }
@@ -53,22 +53,22 @@ interface AbbotResponse$1<T> {
53
53
  data: T;
54
54
  }
55
55
  declare class AbbotHttp {
56
- protected static config: AbbotConfig;
57
- static initConfig(config: DeepPartial<AbbotConfig>): void;
58
- static getConfig(): AbbotConfig;
59
- protected static deepMerge<T>(target: T, source: DeepPartial<T>): T;
60
- protected static createAxiosInstance(option?: Partial<MethodOption>): AxiosInstance;
61
- protected static prepareRequestConfig(option?: Partial<MethodOption>): {
56
+ protected config: AbbotConfig;
57
+ initConfig(config: DeepPartial<AbbotConfig>): void;
58
+ protected deepMerge<T>(target: T, source: DeepPartial<T>): T;
59
+ protected createAxiosInstance(option?: Partial<MethodOption>): AxiosInstance;
60
+ protected prepareRequestConfig(option?: Partial<MethodOption>): {
62
61
  cryp: Cryp;
63
62
  iv: string;
64
63
  form: URLSearchParams;
65
64
  };
66
- protected static createAxiosRequestObj(iv: string): Record<string, any>;
67
- protected static habdleError(error: any, cryp: Cryp): Promise<never>;
68
- static post<T>(url: string, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
69
- static get<T>(url: string, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
70
- static uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
71
- static uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
65
+ protected createAxiosRequestObj(iv: string): Record<string, any>;
66
+ protected habdleError(error: any, cryp: Cryp): Promise<never>;
67
+ post<T>(url: string, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
68
+ get<T>(url: string, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
69
+ uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
70
+ uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
71
+ getConfig(): AbbotConfig;
72
72
  }
73
73
 
74
74
  declare function catchError<T, E extends new (err?: any) => Error>(promise: Promise<T>, errorToCatch?: E[]): Promise<[undefined, T] | [InstanceType<E>]>;
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ declare class Cryp {
9
9
  constructor(cryptProps: {
10
10
  iv: string;
11
11
  keyValue?: string;
12
- });
12
+ }, apiKey: string);
13
13
  encrypt(textValue?: string): string;
14
14
  decrypt<T>(encryptedValue?: string): T | null;
15
15
  }
@@ -53,22 +53,22 @@ interface AbbotResponse$1<T> {
53
53
  data: T;
54
54
  }
55
55
  declare class AbbotHttp {
56
- protected static config: AbbotConfig;
57
- static initConfig(config: DeepPartial<AbbotConfig>): void;
58
- static getConfig(): AbbotConfig;
59
- protected static deepMerge<T>(target: T, source: DeepPartial<T>): T;
60
- protected static createAxiosInstance(option?: Partial<MethodOption>): AxiosInstance;
61
- protected static prepareRequestConfig(option?: Partial<MethodOption>): {
56
+ protected config: AbbotConfig;
57
+ initConfig(config: DeepPartial<AbbotConfig>): void;
58
+ protected deepMerge<T>(target: T, source: DeepPartial<T>): T;
59
+ protected createAxiosInstance(option?: Partial<MethodOption>): AxiosInstance;
60
+ protected prepareRequestConfig(option?: Partial<MethodOption>): {
62
61
  cryp: Cryp;
63
62
  iv: string;
64
63
  form: URLSearchParams;
65
64
  };
66
- protected static createAxiosRequestObj(iv: string): Record<string, any>;
67
- protected static habdleError(error: any, cryp: Cryp): Promise<never>;
68
- static post<T>(url: string, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
69
- static get<T>(url: string, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
70
- static uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
71
- static uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
65
+ protected createAxiosRequestObj(iv: string): Record<string, any>;
66
+ protected habdleError(error: any, cryp: Cryp): Promise<never>;
67
+ post<T>(url: string, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
68
+ get<T>(url: string, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
69
+ uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
70
+ uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse$1<T>>;
71
+ getConfig(): AbbotConfig;
72
72
  }
73
73
 
74
74
  declare function catchError<T, E extends new (err?: any) => Error>(promise: Promise<T>, errorToCatch?: E[]): Promise<[undefined, T] | [InstanceType<E>]>;
package/dist/index.js CHANGED
@@ -85,9 +85,9 @@ var Cryp = class {
85
85
  keyBuffer;
86
86
  iv;
87
87
  algConfig;
88
- constructor(cryptProps) {
88
+ constructor(cryptProps, apiKey) {
89
89
  this.ivText = cryptProps.iv;
90
- this.key = cryptProps.keyValue ? cryptProps.keyValue : ES.d(ES.b2a(AbbotHttp.getConfig().app.apiKey));
90
+ this.key = cryptProps.keyValue ? cryptProps.keyValue : ES.d(ES.b2a(apiKey));
91
91
  this.keyBuffer = enc.Utf8.parse(this.key);
92
92
  this.iv = enc.Utf8.parse(this.ivText);
93
93
  this.algConfig = { mode: mode.CBC, padding: pad.PKCS7, iv: this.iv };
@@ -163,14 +163,11 @@ function axiosConf(cfg) {
163
163
 
164
164
  // src/http.ts
165
165
  var AbbotHttp = class {
166
- static config = defaultConfig;
167
- static initConfig(config) {
166
+ config = defaultConfig;
167
+ initConfig(config) {
168
168
  this.config = this.deepMerge(this.config, config);
169
169
  }
170
- static getConfig() {
171
- return this.config;
172
- }
173
- static deepMerge(target, source) {
170
+ deepMerge(target, source) {
174
171
  for (const key in source) {
175
172
  const srcVal = source[key];
176
173
  if (srcVal && typeof srcVal === "object" && !Array.isArray(srcVal)) {
@@ -181,7 +178,7 @@ var AbbotHttp = class {
181
178
  }
182
179
  return target;
183
180
  }
184
- static createAxiosInstance(option) {
181
+ createAxiosInstance(option) {
185
182
  const axios2 = axiosConf(this.config);
186
183
  if (this.config.useAxiosInterceptors) {
187
184
  const { cryp, iv } = this.prepareRequestConfig(option);
@@ -234,7 +231,7 @@ var AbbotHttp = class {
234
231
  }
235
232
  return axios2;
236
233
  }
237
- static prepareRequestConfig(option) {
234
+ prepareRequestConfig(option) {
238
235
  const iv = Secure.createId();
239
236
  if (this.config.devMode) {
240
237
  console.log({
@@ -242,14 +239,17 @@ var AbbotHttp = class {
242
239
  keyValue: option?.isInit ? void 0 : this.config.app.encKey
243
240
  });
244
241
  }
245
- const cryp = new Cryp({
246
- iv,
247
- keyValue: option?.isInit ? void 0 : this.config.app.encKey
248
- });
242
+ const cryp = new Cryp(
243
+ {
244
+ iv,
245
+ keyValue: option?.isInit ? void 0 : this.config.app.encKey
246
+ },
247
+ this.config.app.apiKey
248
+ );
249
249
  const form = new URLSearchParams();
250
250
  return { cryp, iv, form };
251
251
  }
252
- static createAxiosRequestObj(iv) {
252
+ createAxiosRequestObj(iv) {
253
253
  const headers = {
254
254
  "data-code": iv
255
255
  };
@@ -261,7 +261,7 @@ var AbbotHttp = class {
261
261
  }
262
262
  return headers;
263
263
  }
264
- static habdleError(error, cryp) {
264
+ habdleError(error, cryp) {
265
265
  const err = {
266
266
  message: error.message,
267
267
  code: error.code,
@@ -332,7 +332,7 @@ var AbbotHttp = class {
332
332
  );
333
333
  }
334
334
  }
335
- static async post(url, param, option) {
335
+ async post(url, param, option) {
336
336
  const axios2 = this.createAxiosInstance(option);
337
337
  if (!this.config.useAxiosInterceptors) {
338
338
  const { cryp, iv, form } = this.prepareRequestConfig(option);
@@ -355,7 +355,7 @@ var AbbotHttp = class {
355
355
  return response;
356
356
  }
357
357
  }
358
- static async get(url, option) {
358
+ async get(url, option) {
359
359
  const axios2 = this.createAxiosInstance(option);
360
360
  if (!this.config.useAxiosInterceptors) {
361
361
  const { cryp, iv } = this.prepareRequestConfig(option);
@@ -375,7 +375,7 @@ var AbbotHttp = class {
375
375
  return response;
376
376
  }
377
377
  }
378
- static async uploadFile(url, file, param1, param2, param3) {
378
+ async uploadFile(url, file, param1, param2, param3) {
379
379
  let response;
380
380
  const formData = new FormData();
381
381
  if (file instanceof Array) {
@@ -404,6 +404,9 @@ var AbbotHttp = class {
404
404
  }
405
405
  return response;
406
406
  }
407
+ getConfig() {
408
+ return this.config;
409
+ }
407
410
  };
408
411
  export {
409
412
  AbbotHttp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abbot-http-client",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "This package helps Abbot team to handle all the axios requests.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",