abbot-http-client 0.0.14 → 0.0.15

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
@@ -340,14 +340,28 @@ var cfg = {
340
340
  app: {
341
341
  redirectUrl: "/login",
342
342
  apiKey: "",
343
- timezone: "Asia/Bangkok"
343
+ timezone: "Asia/Bangkok",
344
+ ecnKey: "",
345
+ trackingId: "",
346
+ userJwt: ""
344
347
  }
345
348
  };
346
349
  function getConfig() {
347
350
  return cfg;
348
351
  }
352
+ function deepMerge(target, source) {
353
+ for (const key in source) {
354
+ const srcVal = source[key];
355
+ if (srcVal && typeof srcVal === "object" && !Array.isArray(srcVal)) {
356
+ target[key] = deepMerge(target[key], srcVal);
357
+ } else if (srcVal !== void 0) {
358
+ target[key] = srcVal;
359
+ }
360
+ }
361
+ return target;
362
+ }
349
363
  function create(config) {
350
- cfg = { ...cfg, ...config };
364
+ cfg = deepMerge(cfg, config);
351
365
  const http = new CoreHttp(cfg);
352
366
  return http;
353
367
  }
package/dist/index.d.cts CHANGED
@@ -16,27 +16,30 @@ declare class CoreHttp {
16
16
  getConfig(): AbbotConfig;
17
17
  }
18
18
 
19
+ type DeepPartial<T> = T extends object ? {
20
+ [P in keyof T]?: DeepPartial<T[P]>;
21
+ } : T;
19
22
  interface AbbotConfig {
20
23
  axios: {
21
24
  baseUrl: string;
22
25
  headers: {
23
- accept?: string;
24
- lang?: string;
25
- post?: {
26
- contentType?: string;
26
+ accept: string;
27
+ lang: string;
28
+ post: {
29
+ contentType: string;
27
30
  };
28
31
  };
29
- timeout?: number;
32
+ timeout: number;
30
33
  };
31
34
  app: {
32
35
  redirectUrl: string;
33
36
  apiKey: string;
34
37
  timezone: string;
35
- trackingId?: string;
36
- ecnKey?: string;
37
- userJwt?: string;
38
+ trackingId: string;
39
+ ecnKey: string;
40
+ userJwt: string;
38
41
  };
39
42
  }
40
- declare function create(config: Partial<AbbotConfig>): CoreHttp;
43
+ declare function create(config: DeepPartial<AbbotConfig>): CoreHttp;
41
44
 
42
45
  export { type AbbotConfig, catchError, create };
package/dist/index.d.ts CHANGED
@@ -16,27 +16,30 @@ declare class CoreHttp {
16
16
  getConfig(): AbbotConfig;
17
17
  }
18
18
 
19
+ type DeepPartial<T> = T extends object ? {
20
+ [P in keyof T]?: DeepPartial<T[P]>;
21
+ } : T;
19
22
  interface AbbotConfig {
20
23
  axios: {
21
24
  baseUrl: string;
22
25
  headers: {
23
- accept?: string;
24
- lang?: string;
25
- post?: {
26
- contentType?: string;
26
+ accept: string;
27
+ lang: string;
28
+ post: {
29
+ contentType: string;
27
30
  };
28
31
  };
29
- timeout?: number;
32
+ timeout: number;
30
33
  };
31
34
  app: {
32
35
  redirectUrl: string;
33
36
  apiKey: string;
34
37
  timezone: string;
35
- trackingId?: string;
36
- ecnKey?: string;
37
- userJwt?: string;
38
+ trackingId: string;
39
+ ecnKey: string;
40
+ userJwt: string;
38
41
  };
39
42
  }
40
- declare function create(config: Partial<AbbotConfig>): CoreHttp;
43
+ declare function create(config: DeepPartial<AbbotConfig>): CoreHttp;
41
44
 
42
45
  export { type AbbotConfig, catchError, create };
package/dist/index.js CHANGED
@@ -303,14 +303,28 @@ var cfg = {
303
303
  app: {
304
304
  redirectUrl: "/login",
305
305
  apiKey: "",
306
- timezone: "Asia/Bangkok"
306
+ timezone: "Asia/Bangkok",
307
+ ecnKey: "",
308
+ trackingId: "",
309
+ userJwt: ""
307
310
  }
308
311
  };
309
312
  function getConfig() {
310
313
  return cfg;
311
314
  }
315
+ function deepMerge(target, source) {
316
+ for (const key in source) {
317
+ const srcVal = source[key];
318
+ if (srcVal && typeof srcVal === "object" && !Array.isArray(srcVal)) {
319
+ target[key] = deepMerge(target[key], srcVal);
320
+ } else if (srcVal !== void 0) {
321
+ target[key] = srcVal;
322
+ }
323
+ }
324
+ return target;
325
+ }
312
326
  function create(config) {
313
- cfg = { ...cfg, ...config };
327
+ cfg = deepMerge(cfg, config);
314
328
  const http = new CoreHttp(cfg);
315
329
  return http;
316
330
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abbot-http-client",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
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",