@adaskothebeast/axios-interceptor 6.0.0 → 8.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaskothebeast/axios-interceptor",
3
- "version": "6.0.0",
3
+ "version": "8.0.0",
4
4
  "license": "MIT",
5
5
  "author": "Adam Pluciński <adaskothebeast@gmail.com> (https://github.com/adaskothebeast)",
6
6
  "repository": {
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "homepage": "https://github.com/AdaskoTheBeAsT/date-interceptors",
14
14
  "peerDependencies": {
15
- "axios": "1.10.0",
15
+ "axios": "^1.13.2",
16
16
  "tslib": "^2.8.1"
17
17
  },
18
18
  "types": "./src/index.d.ts",
@@ -1,23 +1,49 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
  /**
3
- * Class for managing the axios instance
3
+ * Class for managing axios instances with date conversion interceptors.
4
+ *
5
+ * Note: Each call to createInstance() or createInstanceWithMultipleInterceptors()
6
+ * creates a NEW axios instance. If you need to reuse the same instance across your
7
+ * application, store the returned instance and pass it around rather than calling
8
+ * createInstance() multiple times.
4
9
  */
5
10
  export declare class AxiosInstanceManager {
6
- private static cachedInstance;
7
11
  /**
8
- * Creates an axios instance with a response interceptor
9
- * @param interceptFunc Function to be called when a response is received
10
- * @returns AxiosInstance
12
+ * Creates a new axios instance with a response interceptor.
13
+ *
14
+ * @param interceptFunc Function to be called when a response is received.
15
+ * This function will be called with response.data and
16
+ * should mutate the data in-place to convert date strings.
17
+ * @returns A new AxiosInstance configured with the provided interceptor
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
22
+ *
23
+ * const axiosInstance = AxiosInstanceManager.createInstance(hierarchicalConvertToDate);
24
+ *
25
+ * // Reuse this instance throughout your app
26
+ * const response = await axiosInstance.get('/api/users');
27
+ * ```
11
28
  */
12
29
  static createInstance(interceptFunc: (data: unknown) => void): AxiosInstance;
13
30
  /**
14
- * Creates an axios instance with multiple response interceptors
15
- * @param interceptFunctions Array of functions to be called when a response is received
16
- * @returns AxiosInstance
31
+ * Creates a new axios instance with multiple response interceptors.
32
+ * Interceptors are applied in the order they appear in the array.
33
+ *
34
+ * @param interceptFunctions Array of functions to be called when a response is received.
35
+ * Each function will be called with response.data in sequence.
36
+ * @returns A new AxiosInstance configured with the provided interceptors
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
41
+ *
42
+ * const axiosInstance = AxiosInstanceManager.createInstanceWithMultipleInterceptors([
43
+ * hierarchicalConvertToDate,
44
+ * (data) => console.log('Response data:', data),
45
+ * ]);
46
+ * ```
17
47
  */
18
48
  static createInstanceWithMultipleInterceptors(interceptFunctions: ((data: unknown) => void)[]): AxiosInstance;
19
- /**
20
- * Resets the cached instance
21
- */
22
- static resetInstance(): void;
23
49
  }
@@ -3,56 +3,76 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AxiosInstanceManager = void 0;
4
4
  const axios_1 = require("axios");
5
5
  /**
6
- * Class for managing the axios instance
6
+ * Class for managing axios instances with date conversion interceptors.
7
+ *
8
+ * Note: Each call to createInstance() or createInstanceWithMultipleInterceptors()
9
+ * creates a NEW axios instance. If you need to reuse the same instance across your
10
+ * application, store the returned instance and pass it around rather than calling
11
+ * createInstance() multiple times.
7
12
  */
8
13
  class AxiosInstanceManager {
9
- static cachedInstance = null;
10
14
  /**
11
- * Creates an axios instance with a response interceptor
12
- * @param interceptFunc Function to be called when a response is received
13
- * @returns AxiosInstance
15
+ * Creates a new axios instance with a response interceptor.
16
+ *
17
+ * @param interceptFunc Function to be called when a response is received.
18
+ * This function will be called with response.data and
19
+ * should mutate the data in-place to convert date strings.
20
+ * @returns A new AxiosInstance configured with the provided interceptor
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
25
+ *
26
+ * const axiosInstance = AxiosInstanceManager.createInstance(hierarchicalConvertToDate);
27
+ *
28
+ * // Reuse this instance throughout your app
29
+ * const response = await axiosInstance.get('/api/users');
30
+ * ```
14
31
  */
15
32
  static createInstance(interceptFunc) {
16
- if (this.cachedInstance) {
17
- return this.cachedInstance;
18
- }
19
33
  const instance = axios_1.default.create();
20
34
  instance.interceptors.response.use((response) => {
21
- interceptFunc(response.data);
35
+ if (response.data != null) {
36
+ interceptFunc(response.data);
37
+ }
22
38
  return response;
23
39
  }, (error) => {
24
40
  return Promise.reject(error);
25
41
  });
26
- this.cachedInstance = instance;
27
42
  return instance;
28
43
  }
29
44
  /**
30
- * Creates an axios instance with multiple response interceptors
31
- * @param interceptFunctions Array of functions to be called when a response is received
32
- * @returns AxiosInstance
45
+ * Creates a new axios instance with multiple response interceptors.
46
+ * Interceptors are applied in the order they appear in the array.
47
+ *
48
+ * @param interceptFunctions Array of functions to be called when a response is received.
49
+ * Each function will be called with response.data in sequence.
50
+ * @returns A new AxiosInstance configured with the provided interceptors
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
55
+ *
56
+ * const axiosInstance = AxiosInstanceManager.createInstanceWithMultipleInterceptors([
57
+ * hierarchicalConvertToDate,
58
+ * (data) => console.log('Response data:', data),
59
+ * ]);
60
+ * ```
33
61
  */
34
62
  static createInstanceWithMultipleInterceptors(interceptFunctions) {
35
- if (this.cachedInstance) {
36
- return this.cachedInstance;
37
- }
38
63
  const instance = axios_1.default.create();
39
64
  instance.interceptors.response.use((response) => {
40
- for (const interceptFunc of interceptFunctions) {
41
- interceptFunc(response.data);
65
+ if (response.data != null) {
66
+ for (const interceptFunc of interceptFunctions) {
67
+ interceptFunc(response.data);
68
+ }
42
69
  }
43
70
  return response;
44
71
  }, (error) => {
45
72
  return Promise.reject(error);
46
73
  });
47
- this.cachedInstance = instance;
48
74
  return instance;
49
75
  }
50
- /**
51
- * Resets the cached instance
52
- */
53
- static resetInstance() {
54
- this.cachedInstance = null;
55
- }
56
76
  }
57
77
  exports.AxiosInstanceManager = AxiosInstanceManager;
58
78
  //# sourceMappingURL=axios-instance-manager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"axios-instance-manager.js","sourceRoot":"","sources":["../../../../../libs/axios-interceptor/src/lib/axios-instance-manager.ts"],"names":[],"mappings":";;;AAAA,iCAA6C;AAE7C;;GAEG;AACH,MAAa,oBAAoB;IACvB,MAAM,CAAC,cAAc,GAAyB,IAAI,CAAC;IAE3D;;;;OAIG;IACI,MAAM,CAAC,cAAc,CAC1B,aAAsC;QAEtC,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,cAAc,CAAC;QAC7B,CAAC;QAED,MAAM,QAAQ,GAAG,eAAK,CAAC,MAAM,EAAE,CAAC;QAEhC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAChC,CAAC,QAAQ,EAAE,EAAE;YACX,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAE7B,OAAO,QAAQ,CAAC;QAClB,CAAC,EACD,CAAC,KAAY,EAAE,EAAE;YACf,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC,CACF,CAAC;QAEF,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAE/B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,sCAAsC,CAClD,kBAA+C;QAE/C,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,cAAc,CAAC;QAC7B,CAAC;QAED,MAAM,QAAQ,GAAG,eAAK,CAAC,MAAM,EAAE,CAAC;QAEhC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAChC,CAAC,QAAQ,EAAE,EAAE;YACX,KAAK,MAAM,aAAa,IAAI,kBAAkB,EAAE,CAAC;gBAC/C,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC,EACD,CAAC,KAAY,EAAE,EAAE;YACf,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC,CACF,CAAC;QAEF,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAE/B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,aAAa;QACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IAC7B,CAAC;;AAtEH,oDAuEC"}
1
+ {"version":3,"file":"axios-instance-manager.js","sourceRoot":"","sources":["../../../../../libs/axios-interceptor/src/lib/axios-instance-manager.ts"],"names":[],"mappings":";;;AAAA,iCAA6C;AAE7C;;;;;;;GAOG;AACH,MAAa,oBAAoB;IAC/B;;;;;;;;;;;;;;;;;OAiBG;IACI,MAAM,CAAC,cAAc,CAC1B,aAAsC;QAEtC,MAAM,QAAQ,GAAG,eAAK,CAAC,MAAM,EAAE,CAAC;QAEhC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAChC,CAAC,QAAQ,EAAE,EAAE;YACX,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;gBAC1B,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC,EACD,CAAC,KAAY,EAAE,EAAE;YACf,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACI,MAAM,CAAC,sCAAsC,CAClD,kBAA+C;QAE/C,MAAM,QAAQ,GAAG,eAAK,CAAC,MAAM,EAAE,CAAC;QAEhC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAChC,CAAC,QAAQ,EAAE,EAAE;YACX,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;gBAC1B,KAAK,MAAM,aAAa,IAAI,kBAAkB,EAAE,CAAC;oBAC/C,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC,EACD,CAAC,KAAY,EAAE,EAAE;YACf,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA9ED,oDA8EC"}