@docbrasil/api-systemmanager 1.1.84 → 1.1.85
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/api/dispatch.js +14 -44
- package/dist/bundle.cjs +17 -47
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +4 -3
- package/docs/Dispatch.html +10 -9
- package/docs/dispatch.js.html +14 -44
- package/index.js +3 -3
- package/package.json +1 -1
package/doc/api.md
CHANGED
|
@@ -5440,8 +5440,9 @@ Get the Axios client.
|
|
|
5440
5440
|
Create a dedicated Axios client for Akamai routes.
|
|
5441
5441
|
In DEV there is no NGiNX to translate the Authorization JWT into the
|
|
5442
5442
|
x-api-key / x-user-id / x-organization-id headers that Akamai expects.
|
|
5443
|
-
When
|
|
5444
|
-
|
|
5443
|
+
When a headerBuilder function is supplied, the client adds a request
|
|
5444
|
+
interceptor that replaces the Authorization header with the x-* headers
|
|
5445
|
+
returned by the function.
|
|
5445
5446
|
|
|
5446
5447
|
**Kind**: instance method of [<code>Dispatch</code>](#Dispatch)
|
|
5447
5448
|
**Access**: public
|
|
@@ -5450,7 +5451,7 @@ decodes the JWT and sets those headers automatically.
|
|
|
5450
5451
|
| --- | --- | --- |
|
|
5451
5452
|
| url | <code>string</code> | The Akamai base URL (e.g., http://localhost:9008 in DEV). |
|
|
5452
5453
|
| [options] | <code>object</code> | Optional configuration |
|
|
5453
|
-
| [options.
|
|
5454
|
+
| [options.headerBuilder] | <code>function</code> | A function that returns an object with the Akamai headers (x-api-key, x-user-id, x-organization-id, x-country). Called at request time so it can read live application state (e.g., auth store). |
|
|
5454
5455
|
|
|
5455
5456
|
<a name="Dispatch+getAkamaiClient"></a>
|
|
5456
5457
|
|
package/docs/Dispatch.html
CHANGED
|
@@ -387,7 +387,7 @@ for backward compatibility (e.g., PROD where NGiNX proxies all routes).
|
|
|
387
387
|
<p class="tag-source">
|
|
388
388
|
<a href="dispatch.js.html" class="button">View Source</a>
|
|
389
389
|
<span>
|
|
390
|
-
<a href="dispatch.js.html">dispatch.js</a>, <a href="dispatch.js.html#
|
|
390
|
+
<a href="dispatch.js.html">dispatch.js</a>, <a href="dispatch.js.html#line247">line 247</a>
|
|
391
391
|
</span>
|
|
392
392
|
</p>
|
|
393
393
|
|
|
@@ -820,8 +820,9 @@ for backward compatibility (e.g., PROD where NGiNX proxies all routes).
|
|
|
820
820
|
Create a dedicated Axios client for Akamai routes.
|
|
821
821
|
In DEV there is no NGiNX to translate the Authorization JWT into the
|
|
822
822
|
x-api-key / x-user-id / x-organization-id headers that Akamai expects.
|
|
823
|
-
When
|
|
824
|
-
|
|
823
|
+
When a headerBuilder function is supplied, the client adds a request
|
|
824
|
+
interceptor that replaces the Authorization header with the x-* headers
|
|
825
|
+
returned by the function.
|
|
825
826
|
</div>
|
|
826
827
|
|
|
827
828
|
|
|
@@ -928,13 +929,13 @@ decodes the JWT and sets those headers automatically.
|
|
|
928
929
|
|
|
929
930
|
<tr class="deep-level-1">
|
|
930
931
|
|
|
931
|
-
<td class="name"><code>
|
|
932
|
+
<td class="name"><code>headerBuilder</code></td>
|
|
932
933
|
|
|
933
934
|
|
|
934
935
|
<td class="type">
|
|
935
936
|
|
|
936
937
|
|
|
937
|
-
<code class="param-type">
|
|
938
|
+
<code class="param-type">function</code>
|
|
938
939
|
|
|
939
940
|
|
|
940
941
|
|
|
@@ -954,9 +955,9 @@ decodes the JWT and sets those headers automatically.
|
|
|
954
955
|
|
|
955
956
|
|
|
956
957
|
|
|
957
|
-
<td class="description last">
|
|
958
|
-
|
|
959
|
-
|
|
958
|
+
<td class="description last">A function that returns an object
|
|
959
|
+
with the Akamai headers (x-api-key, x-user-id, x-organization-id, x-country).
|
|
960
|
+
Called at request time so it can read live application state (e.g., auth store).</td>
|
|
960
961
|
</tr>
|
|
961
962
|
|
|
962
963
|
|
|
@@ -1006,7 +1007,7 @@ decodes the JWT and sets those headers automatically.
|
|
|
1006
1007
|
<p class="tag-source">
|
|
1007
1008
|
<a href="dispatch.js.html" class="button">View Source</a>
|
|
1008
1009
|
<span>
|
|
1009
|
-
<a href="dispatch.js.html">dispatch.js</a>, <a href="dispatch.js.html#
|
|
1010
|
+
<a href="dispatch.js.html">dispatch.js</a>, <a href="dispatch.js.html#line216">line 216</a>
|
|
1010
1011
|
</span>
|
|
1011
1012
|
</p>
|
|
1012
1013
|
|
package/docs/dispatch.js.html
CHANGED
|
@@ -286,38 +286,18 @@ class Dispatch {
|
|
|
286
286
|
return this._client;
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
/**
|
|
290
|
-
* @description Decode the payload of a JWT token (base64url → JSON).
|
|
291
|
-
* Does NOT verify the signature — used only to extract claims for header building.
|
|
292
|
-
* @param {string} token JWT token string
|
|
293
|
-
* @return {object|null} Decoded payload or null on failure
|
|
294
|
-
* @private
|
|
295
|
-
*/
|
|
296
|
-
_decodeJwtPayload(token) {
|
|
297
|
-
try {
|
|
298
|
-
const parts = token.split('.');
|
|
299
|
-
if (parts.length !== 3) return null;
|
|
300
|
-
const base64 = parts[1].replace(/-/g, '+').replace(/_/g, '/');
|
|
301
|
-
const json = decodeURIComponent(
|
|
302
|
-
atob(base64).split('').map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join('')
|
|
303
|
-
);
|
|
304
|
-
return JSON.parse(json);
|
|
305
|
-
} catch (e) {
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
289
|
/**
|
|
311
290
|
* @description Create a dedicated Axios client for Akamai routes.
|
|
312
291
|
* In DEV there is no NGiNX to translate the Authorization JWT into the
|
|
313
292
|
* x-api-key / x-user-id / x-organization-id headers that Akamai expects.
|
|
314
|
-
* When
|
|
315
|
-
*
|
|
293
|
+
* When a headerBuilder function is supplied, the client adds a request
|
|
294
|
+
* interceptor that replaces the Authorization header with the x-* headers
|
|
295
|
+
* returned by the function.
|
|
316
296
|
* @param {string} url The Akamai base URL (e.g., http://localhost:9008 in DEV).
|
|
317
297
|
* @param {object} [options] Optional configuration
|
|
318
|
-
* @param {
|
|
319
|
-
*
|
|
320
|
-
*
|
|
298
|
+
* @param {function} [options.headerBuilder] A function that returns an object
|
|
299
|
+
* with the Akamai headers (x-api-key, x-user-id, x-organization-id, x-country).
|
|
300
|
+
* Called at request time so it can read live application state (e.g., auth store).
|
|
321
301
|
* @public
|
|
322
302
|
*/
|
|
323
303
|
setAkamaiBaseUrl(url, options = {}) {
|
|
@@ -330,25 +310,15 @@ class Dispatch {
|
|
|
330
310
|
withCredentials: true
|
|
331
311
|
});
|
|
332
312
|
|
|
333
|
-
// When
|
|
334
|
-
if (options.
|
|
335
|
-
const apiKey = options.apiKey;
|
|
336
|
-
|
|
313
|
+
// When a headerBuilder is provided, add interceptor to replace Authorization with Akamai headers
|
|
314
|
+
if (typeof options.headerBuilder === 'function') {
|
|
337
315
|
self._akamaiClient.interceptors.request.use((config) => {
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
config.headers['x-organization-id'] = payload.orgId || payload.organizationId;
|
|
345
|
-
if (payload.language) {
|
|
346
|
-
config.headers['x-country'] = payload.language;
|
|
347
|
-
}
|
|
348
|
-
// Remove the Authorization header — Akamai doesn't use it
|
|
349
|
-
delete config.headers.Authorization;
|
|
350
|
-
delete config.headers.authorization;
|
|
351
|
-
}
|
|
316
|
+
const headers = options.headerBuilder();
|
|
317
|
+
if (headers) {
|
|
318
|
+
Object.assign(config.headers, headers);
|
|
319
|
+
// Remove the Authorization header — Akamai doesn't use it
|
|
320
|
+
delete config.headers.Authorization;
|
|
321
|
+
delete config.headers.authorization;
|
|
352
322
|
}
|
|
353
323
|
return config;
|
|
354
324
|
});
|
package/index.js
CHANGED
|
@@ -87,7 +87,7 @@ class API {
|
|
|
87
87
|
|
|
88
88
|
// If akamaiUri was provided in options, configure the Akamai client
|
|
89
89
|
if (self.options.akamaiUri) {
|
|
90
|
-
self.dispatch.setAkamaiBaseUrl(self.options.akamaiUri, {
|
|
90
|
+
self.dispatch.setAkamaiBaseUrl(self.options.akamaiUri, { headerBuilder: self.options.akamaiHeaderBuilder });
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -95,8 +95,8 @@ class API {
|
|
|
95
95
|
* @description Set the Akamai base URL for agent/AI routes.
|
|
96
96
|
* @param {string} url The Akamai base URL.
|
|
97
97
|
* @param {object} [options] Optional configuration
|
|
98
|
-
* @param {
|
|
99
|
-
*
|
|
98
|
+
* @param {function} [options.headerBuilder] Function returning Akamai headers.
|
|
99
|
+
* Called at request time — can read live app state (e.g., auth store).
|
|
100
100
|
* @public
|
|
101
101
|
*/
|
|
102
102
|
setAkamaiBaseUrl(url, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docbrasil/api-systemmanager",
|
|
3
3
|
"description": "Module API System Manager",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.85",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"htmldoc": "rm -rf docs && jsdoc api/** -d docs -t ./node_modules/better-docs",
|
|
7
7
|
"doc": "rm -rf doc && mkdir doc && jsdoc2md api/**/* api/* > doc/api.md",
|