@docbrasil/api-systemmanager 1.1.83 → 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 +27 -2
- package/dist/bundle.cjs +33 -5
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +9 -2
- package/docs/Dispatch.html +91 -3
- package/docs/dispatch.js.html +27 -2
- package/index.js +6 -3
- package/package.json +1 -1
package/api/dispatch.js
CHANGED
|
@@ -201,16 +201,41 @@ class Dispatch {
|
|
|
201
201
|
|
|
202
202
|
/**
|
|
203
203
|
* @description Create a dedicated Axios client for Akamai routes.
|
|
204
|
+
* In DEV there is no NGiNX to translate the Authorization JWT into the
|
|
205
|
+
* x-api-key / x-user-id / x-organization-id headers that Akamai expects.
|
|
206
|
+
* When a headerBuilder function is supplied, the client adds a request
|
|
207
|
+
* interceptor that replaces the Authorization header with the x-* headers
|
|
208
|
+
* returned by the function.
|
|
204
209
|
* @param {string} url The Akamai base URL (e.g., http://localhost:9008 in DEV).
|
|
210
|
+
* @param {object} [options] Optional configuration
|
|
211
|
+
* @param {function} [options.headerBuilder] A function that returns an object
|
|
212
|
+
* with the Akamai headers (x-api-key, x-user-id, x-organization-id, x-country).
|
|
213
|
+
* Called at request time so it can read live application state (e.g., auth store).
|
|
205
214
|
* @public
|
|
206
215
|
*/
|
|
207
|
-
setAkamaiBaseUrl(url) {
|
|
216
|
+
setAkamaiBaseUrl(url, options = {}) {
|
|
208
217
|
Joi.assert(url, Joi.string().required());
|
|
209
218
|
|
|
210
|
-
|
|
219
|
+
const self = this;
|
|
220
|
+
|
|
221
|
+
self._akamaiClient = Axios.create({
|
|
211
222
|
baseURL: url,
|
|
212
223
|
withCredentials: true
|
|
213
224
|
});
|
|
225
|
+
|
|
226
|
+
// When a headerBuilder is provided, add interceptor to replace Authorization with Akamai headers
|
|
227
|
+
if (typeof options.headerBuilder === 'function') {
|
|
228
|
+
self._akamaiClient.interceptors.request.use((config) => {
|
|
229
|
+
const headers = options.headerBuilder();
|
|
230
|
+
if (headers) {
|
|
231
|
+
Object.assign(config.headers, headers);
|
|
232
|
+
// Remove the Authorization header — Akamai doesn't use it
|
|
233
|
+
delete config.headers.Authorization;
|
|
234
|
+
delete config.headers.authorization;
|
|
235
|
+
}
|
|
236
|
+
return config;
|
|
237
|
+
});
|
|
238
|
+
}
|
|
214
239
|
}
|
|
215
240
|
|
|
216
241
|
/**
|
package/dist/bundle.cjs
CHANGED
|
@@ -213,16 +213,41 @@ class Dispatch {
|
|
|
213
213
|
|
|
214
214
|
/**
|
|
215
215
|
* @description Create a dedicated Axios client for Akamai routes.
|
|
216
|
+
* In DEV there is no NGiNX to translate the Authorization JWT into the
|
|
217
|
+
* x-api-key / x-user-id / x-organization-id headers that Akamai expects.
|
|
218
|
+
* When a headerBuilder function is supplied, the client adds a request
|
|
219
|
+
* interceptor that replaces the Authorization header with the x-* headers
|
|
220
|
+
* returned by the function.
|
|
216
221
|
* @param {string} url The Akamai base URL (e.g., http://localhost:9008 in DEV).
|
|
222
|
+
* @param {object} [options] Optional configuration
|
|
223
|
+
* @param {function} [options.headerBuilder] A function that returns an object
|
|
224
|
+
* with the Akamai headers (x-api-key, x-user-id, x-organization-id, x-country).
|
|
225
|
+
* Called at request time so it can read live application state (e.g., auth store).
|
|
217
226
|
* @public
|
|
218
227
|
*/
|
|
219
|
-
setAkamaiBaseUrl(url) {
|
|
228
|
+
setAkamaiBaseUrl(url, options = {}) {
|
|
220
229
|
Joi__default["default"].assert(url, Joi__default["default"].string().required());
|
|
221
230
|
|
|
222
|
-
|
|
231
|
+
const self = this;
|
|
232
|
+
|
|
233
|
+
self._akamaiClient = Axios__default["default"].create({
|
|
223
234
|
baseURL: url,
|
|
224
235
|
withCredentials: true
|
|
225
236
|
});
|
|
237
|
+
|
|
238
|
+
// When a headerBuilder is provided, add interceptor to replace Authorization with Akamai headers
|
|
239
|
+
if (typeof options.headerBuilder === 'function') {
|
|
240
|
+
self._akamaiClient.interceptors.request.use((config) => {
|
|
241
|
+
const headers = options.headerBuilder();
|
|
242
|
+
if (headers) {
|
|
243
|
+
Object.assign(config.headers, headers);
|
|
244
|
+
// Remove the Authorization header — Akamai doesn't use it
|
|
245
|
+
delete config.headers.Authorization;
|
|
246
|
+
delete config.headers.authorization;
|
|
247
|
+
}
|
|
248
|
+
return config;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
226
251
|
}
|
|
227
252
|
|
|
228
253
|
/**
|
|
@@ -16557,17 +16582,20 @@ class API {
|
|
|
16557
16582
|
|
|
16558
16583
|
// If akamaiUri was provided in options, configure the Akamai client
|
|
16559
16584
|
if (self.options.akamaiUri) {
|
|
16560
|
-
self.dispatch.setAkamaiBaseUrl(self.options.akamaiUri);
|
|
16585
|
+
self.dispatch.setAkamaiBaseUrl(self.options.akamaiUri, { headerBuilder: self.options.akamaiHeaderBuilder });
|
|
16561
16586
|
}
|
|
16562
16587
|
}
|
|
16563
16588
|
|
|
16564
16589
|
/**
|
|
16565
16590
|
* @description Set the Akamai base URL for agent/AI routes.
|
|
16566
16591
|
* @param {string} url The Akamai base URL.
|
|
16592
|
+
* @param {object} [options] Optional configuration
|
|
16593
|
+
* @param {function} [options.headerBuilder] Function returning Akamai headers.
|
|
16594
|
+
* Called at request time — can read live app state (e.g., auth store).
|
|
16567
16595
|
* @public
|
|
16568
16596
|
*/
|
|
16569
|
-
setAkamaiBaseUrl(url) {
|
|
16570
|
-
this.dispatch.setAkamaiBaseUrl(url);
|
|
16597
|
+
setAkamaiBaseUrl(url, options = {}) {
|
|
16598
|
+
this.dispatch.setAkamaiBaseUrl(url, options);
|
|
16571
16599
|
}
|
|
16572
16600
|
}
|
|
16573
16601
|
|