@arrowsphere/api-client 3.180.0 → 3.181.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/CHANGELOG.md CHANGED
@@ -3,6 +3,11 @@
3
3
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4
4
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
+ ## [3.181.0] - 2025.03.14
7
+
8
+ ### Updated
9
+ - [Axios] update lib to version 1.8.2
10
+
6
11
  ## [3.180.0] - 2025.03.13
7
12
 
8
13
  ### Added
@@ -5,25 +5,56 @@ export declare type AxiosSingletonConfiguration = {
5
5
  export declare class AxiosSingleton {
6
6
  private static _axiosInstance;
7
7
  private static _isLogging;
8
+ /**
9
+ * Get the singleton instance of Axios.
10
+ * @param configuration - Configuration object for AxiosSingleton.
11
+ *
12
+ * @returns The Axios instance.
13
+ */
8
14
  static getInstance(configuration?: AxiosSingletonConfiguration): AxiosInstance;
15
+ /**
16
+ * Initialize the request interceptor.
17
+ */
9
18
  private static _initializedRequestInterceptor;
19
+ /**
20
+ * Initialize the response interceptor.
21
+ */
10
22
  private static _initializedResponseInterceptor;
11
23
  /**
12
- * @param request - Axios Request
13
- * @param isLogging - Must log
24
+ * Handle the request before it is sent.
25
+ *
26
+ * @param request - The Axios request configuration.
27
+ * @param isLogging - Whether logging is enabled.
28
+ *
29
+ * @returns The modified request configuration.
14
30
  */
15
31
  private static _handleRequest;
16
32
  /**
17
- * @param response - Axios Response
18
- * @param isLogging - Must log
33
+ * Handle the response after it is received.
34
+ *
35
+ * @param response - The Axios response.
36
+ * @param isLogging - Whether logging is enabled.
37
+ *
38
+ * @returns The modified response.
19
39
  */
20
40
  private static _handleResponse;
21
41
  /**
22
- * @param request - Axios Request
42
+ * Clean the response log by removing sensitive information.
43
+ *
44
+ * @param response - The Axios response.
45
+ *
46
+ * @returns The sanitized response.
23
47
  */
24
- private static cleanRequestLog;
48
+ private static cleanResponseLog;
25
49
  /**
26
- * @param response - Axios Response
50
+ * Sanitize an object by obfuscating sensitive fields.
51
+ * This function is recursive and supports circular references using WeakMap.
52
+ *
53
+ * @param obj - The object to sanitize.
54
+ * @param fieldsToObfuscate - List of keys whose values should be replaced with '***'. Defaults to ["authorization", "x-api-key", "password", "token"].
55
+ * @param seen - Internal map to track processed objects and prevent infinite loops. Defaults to new WeakMap().
56
+ *
57
+ * @returns A new sanitized object with sensitive data obfuscated or removed.
27
58
  */
28
- private static cleanResponseLog;
59
+ private static sanitizeObject;
29
60
  }
@@ -5,8 +5,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.AxiosSingleton = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
- const lodash_1 = require("lodash");
8
+ var DefaultObfuscateFields;
9
+ (function (DefaultObfuscateFields) {
10
+ DefaultObfuscateFields["API_KEY"] = "apiKey";
11
+ DefaultObfuscateFields["PASSWORD"] = "password";
12
+ DefaultObfuscateFields["AUTHORIZATION"] = "Authorization";
13
+ DefaultObfuscateFields["NEW_PASSWORD"] = "newPassword";
14
+ DefaultObfuscateFields["OLD_PASSWORD"] = "oldPassword";
15
+ })(DefaultObfuscateFields || (DefaultObfuscateFields = {}));
9
16
  class AxiosSingleton {
17
+ /**
18
+ * Get the singleton instance of Axios.
19
+ * @param configuration - Configuration object for AxiosSingleton.
20
+ *
21
+ * @returns The Axios instance.
22
+ */
10
23
  static getInstance(configuration = {}) {
11
24
  this._isLogging = !!configuration.isLogging;
12
25
  if (!AxiosSingleton._axiosInstance) {
@@ -17,25 +30,39 @@ class AxiosSingleton {
17
30
  }
18
31
  return AxiosSingleton._axiosInstance;
19
32
  }
33
+ /**
34
+ * Initialize the request interceptor.
35
+ */
20
36
  static _initializedRequestInterceptor() {
21
37
  this._axiosInstance.interceptors.request.use((req) => this._handleRequest(req, this._isLogging));
22
38
  }
39
+ /**
40
+ * Initialize the response interceptor.
41
+ */
23
42
  static _initializedResponseInterceptor() {
24
43
  this._axiosInstance.interceptors.response.use((req) => this._handleResponse(req, this._isLogging));
25
44
  }
26
45
  /**
27
- * @param request - Axios Request
28
- * @param isLogging - Must log
46
+ * Handle the request before it is sent.
47
+ *
48
+ * @param request - The Axios request configuration.
49
+ * @param isLogging - Whether logging is enabled.
50
+ *
51
+ * @returns The modified request configuration.
29
52
  */
30
53
  static _handleRequest(request, isLogging = false) {
31
54
  if (isLogging) {
32
- console.info('AXIOS - Request : ', AxiosSingleton.cleanRequestLog(request));
55
+ console.info('AXIOS - Request : ', AxiosSingleton.sanitizeObject(request));
33
56
  }
34
57
  return request;
35
58
  }
36
59
  /**
37
- * @param response - Axios Response
38
- * @param isLogging - Must log
60
+ * Handle the response after it is received.
61
+ *
62
+ * @param response - The Axios response.
63
+ * @param isLogging - Whether logging is enabled.
64
+ *
65
+ * @returns The modified response.
39
66
  */
40
67
  static _handleResponse(response, isLogging = false) {
41
68
  if (isLogging) {
@@ -44,34 +71,68 @@ class AxiosSingleton {
44
71
  return response;
45
72
  }
46
73
  /**
47
- * @param request - Axios Request
74
+ * Clean the response log by removing sensitive information.
75
+ *
76
+ * @param response - The Axios response.
77
+ *
78
+ * @returns The sanitized response.
48
79
  */
49
- static cleanRequestLog(request) {
50
- var _a, _b, _c, _d;
51
- const tempRequest = (0, lodash_1.cloneDeep)(request);
52
- if ((_a = tempRequest.headers) === null || _a === void 0 ? void 0 : _a.apiKey) {
53
- const apiKey = (_b = tempRequest.headers) === null || _b === void 0 ? void 0 : _b.apiKey;
54
- tempRequest.headers.apiKey =
55
- '****************************' + apiKey.substring(apiKey.length - 4);
56
- }
57
- if ((_d = (_c = tempRequest.data) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.password) {
58
- tempRequest.data.user.password = '***********';
59
- }
60
- return tempRequest;
80
+ static cleanResponseLog(response) {
81
+ delete response.request;
82
+ return AxiosSingleton.sanitizeObject(response);
61
83
  }
62
84
  /**
63
- * @param response - Axios Response
85
+ * Sanitize an object by obfuscating sensitive fields.
86
+ * This function is recursive and supports circular references using WeakMap.
87
+ *
88
+ * @param obj - The object to sanitize.
89
+ * @param fieldsToObfuscate - List of keys whose values should be replaced with '***'. Defaults to ["authorization", "x-api-key", "password", "token"].
90
+ * @param seen - Internal map to track processed objects and prevent infinite loops. Defaults to new WeakMap().
91
+ *
92
+ * @returns A new sanitized object with sensitive data obfuscated or removed.
64
93
  */
65
- static cleanResponseLog(response) {
66
- var _a, _b;
67
- const tempResponse = (0, lodash_1.cloneDeep)(response);
68
- if ((_a = tempResponse.config.headers) === null || _a === void 0 ? void 0 : _a.apiKey) {
69
- const apiKey = (_b = tempResponse.config.headers) === null || _b === void 0 ? void 0 : _b.apiKey;
70
- tempResponse.config.headers.apiKey =
71
- '****************************' + apiKey.substring(apiKey.length - 4);
94
+ static sanitizeObject(obj, fieldsToObfuscate = [
95
+ DefaultObfuscateFields.API_KEY,
96
+ DefaultObfuscateFields.PASSWORD,
97
+ DefaultObfuscateFields.AUTHORIZATION,
98
+ DefaultObfuscateFields.NEW_PASSWORD,
99
+ DefaultObfuscateFields.OLD_PASSWORD,
100
+ ], seen = new WeakMap()) {
101
+ if (!obj || typeof obj !== 'object')
102
+ return obj;
103
+ // Vérifie si l'objet a déjà été traité (évite les boucles infinies)
104
+ if (seen.has(obj))
105
+ return seen.get(obj);
106
+ // Crée une copie de l'objet pour éviter de le modifier directement
107
+ const sanitizedCopy = Array.isArray(obj) ? [] : {};
108
+ // Stocke l'objet dans WeakMap avant la récursion
109
+ seen.set(obj, sanitizedCopy);
110
+ for (const [key, value] of Object.entries(obj)) {
111
+ if (fieldsToObfuscate
112
+ .map((field) => field.toUpperCase())
113
+ .includes(key.toUpperCase())) {
114
+ let obfuscatedFields = '';
115
+ switch (key.toUpperCase()) {
116
+ case DefaultObfuscateFields.API_KEY.toUpperCase():
117
+ case DefaultObfuscateFields.AUTHORIZATION.toUpperCase():
118
+ obfuscatedFields =
119
+ '****************************' +
120
+ value.substring(value.length - 4);
121
+ break;
122
+ default:
123
+ obfuscatedFields = '***';
124
+ break;
125
+ }
126
+ sanitizedCopy[key] = obfuscatedFields;
127
+ }
128
+ else if (typeof value === 'object' && value !== null) {
129
+ sanitizedCopy[key] = AxiosSingleton.sanitizeObject(value, fieldsToObfuscate, seen); // 🔄 Récursion avec WeakMap
130
+ }
131
+ else {
132
+ sanitizedCopy[key] = value;
133
+ }
72
134
  }
73
- delete tempResponse.request;
74
- return tempResponse;
135
+ return sanitizedCopy;
75
136
  }
76
137
  }
77
138
  exports.AxiosSingleton = AxiosSingleton;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/ArrowSphere/nodejs-api-client.git"
6
6
  },
7
- "version": "3.180.0",
7
+ "version": "3.181.0",
8
8
  "description": "Node.js client for ArrowSphere's public API",
9
9
  "main": "build/index.js",
10
10
  "types": "build/index.d.ts",
@@ -82,7 +82,7 @@
82
82
  "test": "tests"
83
83
  },
84
84
  "dependencies": {
85
- "axios": "1.1.3",
85
+ "axios": "1.8.2",
86
86
  "graphql": "^16.3.0",
87
87
  "graphql-request": "4.2.0",
88
88
  "json-to-graphql-query": "^2.2.5",