@ama-sdk/core 11.0.0-next.0 → 11.0.0-next.1
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/README.md +4 -1
- package/cjs/clients/api-angular-client.js +45 -23
- package/cjs/clients/api-beacon-client.js +64 -20
- package/cjs/clients/api-fetch-client.js +66 -21
- package/cjs/fwk/Reviver.js +7 -7
- package/cjs/fwk/api.helper.spec.js +20 -20
- package/cjs/fwk/api.helpers.js +14 -14
- package/cjs/fwk/core/api-client.js +1 -1
- package/cjs/fwk/core/base-api-constructor.js +1 -1
- package/cjs/fwk/date.js +9 -9
- package/cjs/fwk/date.spec.js +25 -25
- package/cjs/fwk/errors.js +3 -3
- package/cjs/fwk/mocks/alf-mock-adapter.js +4 -4
- package/cjs/fwk/mocks/base-mock-adapter.js +2 -2
- package/cjs/fwk/mocks/helpers.js +3 -3
- package/cjs/fwk/reviver.spec.js +46 -10
- package/cjs/plugins/additional-params/additional-params-sync.request.js +2 -2
- package/cjs/plugins/additional-params/additional-params.request.js +3 -3
- package/cjs/plugins/additional-params/additional-params.spec.js +30 -30
- package/cjs/plugins/api-configuration-override/api-configuration-override.request.js +2 -2
- package/cjs/plugins/api-configuration-override/api-configuration-override.spec.js +13 -13
- package/cjs/plugins/api-key/api-key.request.js +2 -2
- package/cjs/plugins/api-key/api-key.spec.js +11 -11
- package/cjs/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +6 -5
- package/cjs/plugins/bot-protection-fingerprint/bot-protection-fingerprint.spec.js +33 -33
- package/cjs/plugins/client-facts/client-facts.request.js +3 -3
- package/cjs/plugins/client-facts/client-facts.spec.js +27 -27
- package/cjs/plugins/concurrent/concurrent.fetch.js +1 -0
- package/cjs/plugins/concurrent/concurrent.spec.js +4 -4
- package/cjs/plugins/custom-info/custom-info.spec.js +15 -15
- package/cjs/plugins/exception/exception.reply.js +2 -2
- package/cjs/plugins/exception/exception.spec.js +15 -15
- package/cjs/plugins/fetch-cache/fetch-cache.request.js +4 -4
- package/cjs/plugins/fetch-cache/fetch-cache.spec.js +20 -20
- package/cjs/plugins/fetch-credentials/fetch-credentials.request.js +1 -1
- package/cjs/plugins/fetch-credentials/fetch-credentials.spec.js +8 -8
- package/cjs/plugins/json-token/json-token.reply.js +5 -5
- package/cjs/plugins/json-token/json-token.request.js +4 -4
- package/cjs/plugins/json-token/json-token.spec.js +24 -24
- package/cjs/plugins/keepalive/keepalive.request.js +2 -2
- package/cjs/plugins/keepalive/keepalive.spec.js +4 -4
- package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +32 -40
- package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +30 -26
- package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +3 -3
- package/cjs/plugins/mock-intercept/mock-intercept.interface.js +2 -2
- package/cjs/plugins/mock-intercept/mock-intercept.request.js +3 -3
- package/cjs/plugins/mock-intercept/mock-intercept.spec.js +28 -28
- package/cjs/plugins/perf-metric/perf-metric.fetch.js +1 -1
- package/cjs/plugins/perf-metric/perf-metric.probe.spec.js +9 -9
- package/cjs/plugins/pii-tokenizer/pii-tokenizer.request.js +11 -11
- package/cjs/plugins/pii-tokenizer/pii-tokenizer.spec.js +94 -94
- package/cjs/plugins/raw-response-info/raw-response-info.spec.js +12 -12
- package/cjs/plugins/retry/retry.spec.js +20 -20
- package/cjs/plugins/reviver/reviver.reply.js +35 -2
- package/cjs/plugins/reviver/reviver.spec.js +6 -6
- package/cjs/plugins/session-id/session-id.request.js +7 -6
- package/cjs/plugins/session-id/session-id.spec.js +13 -13
- package/cjs/plugins/si-token/si-token.spec.js +9 -9
- package/cjs/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js +4 -4
- package/cjs/plugins/simple-api-key-authentication/simple-api-key-authentication.spec.js +44 -44
- package/cjs/plugins/timeout/timeout.fetch.js +12 -10
- package/cjs/plugins/timeout/timeout.spec.js +13 -13
- package/cjs/plugins/url-rewrite/url-rewrite.spec.js +9 -9
- package/cjs/plugins/wait-for/wait-for.spec.js +9 -9
- package/cjs/utils/crypto.js +14 -14
- package/cjs/utils/generic-api.js +253 -0
- package/cjs/utils/index.js +1 -0
- package/cjs/utils/json-token.js +30 -30
- package/cjs/utils/json-token.spec.js +31 -31
- package/cli/files-pack.cjs +12 -12
- package/cli/files-pack.cjs.map +1 -1
- package/esm2015/clients/api-angular-client.js +49 -27
- package/esm2015/clients/api-beacon-client.js +65 -21
- package/esm2015/clients/api-fetch-client.js +70 -25
- package/esm2015/clients/index.js +2 -2
- package/esm2015/fwk/Reviver.js +10 -7
- package/esm2015/fwk/api.helper.spec.js +21 -21
- package/esm2015/fwk/api.helpers.js +14 -14
- package/esm2015/fwk/core/api-client.js +1 -1
- package/esm2015/fwk/core/base-api-constructor.js +1 -1
- package/esm2015/fwk/core/index.js +2 -2
- package/esm2015/fwk/date.js +9 -9
- package/esm2015/fwk/date.spec.js +26 -26
- package/esm2015/fwk/errors.js +3 -3
- package/esm2015/fwk/index.js +10 -10
- package/esm2015/fwk/mocks/alf-mock-adapter.js +6 -6
- package/esm2015/fwk/mocks/base-mock-adapter.js +3 -3
- package/esm2015/fwk/mocks/helpers.js +3 -3
- package/esm2015/fwk/mocks/index.js +10 -10
- package/esm2015/fwk/mocks/random-mock-adapter.js +1 -1
- package/esm2015/fwk/mocks/sequential-mock-adapter.js +1 -1
- package/esm2015/fwk/reviver.spec.js +47 -11
- package/esm2015/plugins/additional-params/additional-params-sync.request.js +3 -3
- package/esm2015/plugins/additional-params/additional-params.request.js +3 -3
- package/esm2015/plugins/additional-params/additional-params.spec.js +32 -32
- package/esm2015/plugins/additional-params/index.js +2 -2
- package/esm2015/plugins/api-configuration-override/api-configuration-override.request.js +2 -2
- package/esm2015/plugins/api-configuration-override/api-configuration-override.spec.js +14 -14
- package/esm2015/plugins/api-configuration-override/index.js +1 -1
- package/esm2015/plugins/api-key/api-key.request.js +2 -2
- package/esm2015/plugins/api-key/api-key.spec.js +12 -12
- package/esm2015/plugins/api-key/index.js +1 -1
- package/esm2015/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +6 -6
- package/esm2015/plugins/bot-protection-fingerprint/bot-protection-fingerprint.spec.js +34 -34
- package/esm2015/plugins/bot-protection-fingerprint/index.js +1 -1
- package/esm2015/plugins/client-facts/client-facts.request.js +4 -4
- package/esm2015/plugins/client-facts/client-facts.spec.js +28 -28
- package/esm2015/plugins/client-facts/index.js +1 -1
- package/esm2015/plugins/concurrent/concurrent.fetch.js +1 -0
- package/esm2015/plugins/concurrent/concurrent.spec.js +5 -5
- package/esm2015/plugins/concurrent/index.js +1 -1
- package/esm2015/plugins/core/index.js +4 -4
- package/esm2015/plugins/custom-info/custom-info.spec.js +17 -17
- package/esm2015/plugins/custom-info/index.js +1 -1
- package/esm2015/plugins/exception/exception.reply.js +4 -4
- package/esm2015/plugins/exception/exception.spec.js +18 -18
- package/esm2015/plugins/exception/index.js +1 -1
- package/esm2015/plugins/fetch-cache/fetch-cache.request.js +4 -4
- package/esm2015/plugins/fetch-cache/fetch-cache.spec.js +21 -21
- package/esm2015/plugins/fetch-cache/index.js +1 -1
- package/esm2015/plugins/fetch-credentials/fetch-credentials.request.js +1 -1
- package/esm2015/plugins/fetch-credentials/fetch-credentials.spec.js +9 -9
- package/esm2015/plugins/fetch-credentials/index.js +1 -1
- package/esm2015/plugins/index.js +25 -25
- package/esm2015/plugins/json-token/index.js +2 -2
- package/esm2015/plugins/json-token/json-token.reply.js +5 -5
- package/esm2015/plugins/json-token/json-token.request.js +4 -4
- package/esm2015/plugins/json-token/json-token.spec.js +27 -27
- package/esm2015/plugins/keepalive/index.js +1 -1
- package/esm2015/plugins/keepalive/keepalive.request.js +2 -2
- package/esm2015/plugins/keepalive/keepalive.spec.js +5 -5
- package/esm2015/plugins/mgw-mdw-auth/index.js +1 -1
- package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +34 -42
- package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +32 -28
- package/esm2015/plugins/mock-intercept/index.js +2 -2
- package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +5 -5
- package/esm2015/plugins/mock-intercept/mock-intercept.interface.js +2 -2
- package/esm2015/plugins/mock-intercept/mock-intercept.request.js +4 -4
- package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +32 -32
- package/esm2015/plugins/perf-metric/index.js +1 -1
- package/esm2015/plugins/perf-metric/perf-metric.fetch.js +2 -2
- package/esm2015/plugins/perf-metric/perf-metric.probe.spec.js +10 -10
- package/esm2015/plugins/pii-tokenizer/index.js +1 -1
- package/esm2015/plugins/pii-tokenizer/pii-tokenizer.request.js +12 -12
- package/esm2015/plugins/pii-tokenizer/pii-tokenizer.spec.js +96 -96
- package/esm2015/plugins/raw-response-info/index.js +1 -1
- package/esm2015/plugins/raw-response-info/raw-response-info.spec.js +14 -14
- package/esm2015/plugins/retry/index.js +1 -1
- package/esm2015/plugins/retry/retry.fetch.js +1 -1
- package/esm2015/plugins/retry/retry.spec.js +21 -21
- package/esm2015/plugins/reviver/index.js +1 -1
- package/esm2015/plugins/reviver/reviver.reply.js +35 -2
- package/esm2015/plugins/reviver/reviver.spec.js +8 -8
- package/esm2015/plugins/session-id/index.js +1 -1
- package/esm2015/plugins/session-id/session-id.request.js +8 -7
- package/esm2015/plugins/session-id/session-id.spec.js +14 -14
- package/esm2015/plugins/si-token/index.js +1 -1
- package/esm2015/plugins/si-token/si-token.request.js +1 -1
- package/esm2015/plugins/si-token/si-token.spec.js +10 -10
- package/esm2015/plugins/simple-api-key-authentication/index.js +1 -1
- package/esm2015/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js +5 -5
- package/esm2015/plugins/simple-api-key-authentication/simple-api-key-authentication.spec.js +46 -46
- package/esm2015/plugins/timeout/index.js +1 -1
- package/esm2015/plugins/timeout/timeout.fetch.js +13 -11
- package/esm2015/plugins/timeout/timeout.spec.js +15 -15
- package/esm2015/plugins/url-rewrite/index.js +1 -1
- package/esm2015/plugins/url-rewrite/url-rewrite.spec.js +10 -10
- package/esm2015/plugins/wait-for/index.js +1 -1
- package/esm2015/plugins/wait-for/wait-for.spec.js +10 -10
- package/esm2015/public_api.js +4 -4
- package/esm2015/utils/crypto.js +15 -15
- package/esm2015/utils/generic-api.js +245 -0
- package/esm2015/utils/index.js +6 -5
- package/esm2015/utils/json-token.js +32 -32
- package/esm2015/utils/json-token.spec.js +32 -32
- package/package.json +67 -40
- package/schematics/ng-add/index.d.ts +4 -2
- package/schematics/ng-add/index.d.ts.map +1 -1
- package/schematics/ng-add/index.js +58 -40
- package/schematics/ng-add/index.js.map +1 -1
- package/src/clients/api-angular-client.d.ts +6 -3
- package/src/clients/api-angular-client.d.ts.map +1 -1
- package/src/clients/api-angular-client.js +31 -16
- package/src/clients/api-angular-client.js.map +1 -1
- package/src/clients/api-beacon-client.d.ts +7 -5
- package/src/clients/api-beacon-client.d.ts.map +1 -1
- package/src/clients/api-beacon-client.js +24 -14
- package/src/clients/api-beacon-client.js.map +1 -1
- package/src/clients/api-fetch-client.d.ts +5 -3
- package/src/clients/api-fetch-client.d.ts.map +1 -1
- package/src/clients/api-fetch-client.js +26 -14
- package/src/clients/api-fetch-client.js.map +1 -1
- package/src/fwk/Reviver.d.ts +16 -4
- package/src/fwk/Reviver.d.ts.map +1 -1
- package/src/fwk/Reviver.js +9 -6
- package/src/fwk/Reviver.js.map +1 -1
- package/src/fwk/api.helpers.d.ts +1 -1
- package/src/fwk/api.helpers.d.ts.map +1 -1
- package/src/fwk/api.helpers.js +1 -1
- package/src/fwk/api.helpers.js.map +1 -1
- package/src/fwk/core/api-client.d.ts +36 -1
- package/src/fwk/core/api-client.d.ts.map +1 -1
- package/src/fwk/core/api-client.js.map +1 -1
- package/src/fwk/date.js.map +1 -1
- package/src/fwk/mocks/alf-mock-adapter.js.map +1 -1
- package/src/fwk/mocks/base-mock-adapter.js.map +1 -1
- package/src/fwk/mocks/helpers.js.map +1 -1
- package/src/fwk/mocks/random-mock-adapter.js.map +1 -1
- package/src/fwk/mocks/sequential-mock-adapter.js.map +1 -1
- package/src/plugins/additional-params/additional-params-sync.request.js.map +1 -1
- package/src/plugins/additional-params/additional-params.request.js.map +1 -1
- package/src/plugins/api-configuration-override/api-configuration-override.request.js.map +1 -1
- package/src/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.d.ts +1 -1
- package/src/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.d.ts.map +1 -1
- package/src/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +1 -1
- package/src/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js.map +1 -1
- package/src/plugins/client-facts/client-facts.request.js.map +1 -1
- package/src/plugins/concurrent/concurrent.fetch.d.ts.map +1 -1
- package/src/plugins/concurrent/concurrent.fetch.js +1 -0
- package/src/plugins/concurrent/concurrent.fetch.js.map +1 -1
- package/src/plugins/core/plugin.d.ts +6 -1
- package/src/plugins/core/plugin.d.ts.map +1 -1
- package/src/plugins/core/reply-plugin.d.ts +0 -2
- package/src/plugins/core/reply-plugin.d.ts.map +1 -1
- package/src/plugins/core/request-plugin.d.ts +2 -0
- package/src/plugins/core/request-plugin.d.ts.map +1 -1
- package/src/plugins/exception/exception.reply.js.map +1 -1
- package/src/plugins/fetch-cache/fetch-cache.request.js.map +1 -1
- package/src/plugins/json-token/json-token.reply.js.map +1 -1
- package/src/plugins/json-token/json-token.request.js.map +1 -1
- package/src/plugins/keepalive/keepalive.request.js.map +1 -1
- package/src/plugins/mgw-mdw-auth/mgw-mdw-auth.request.d.ts +2 -2
- package/src/plugins/mgw-mdw-auth/mgw-mdw-auth.request.d.ts.map +1 -1
- package/src/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +26 -28
- package/src/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js.map +1 -1
- package/src/plugins/mock-intercept/mock-intercept.fetch.js.map +1 -1
- package/src/plugins/mock-intercept/mock-intercept.request.js.map +1 -1
- package/src/plugins/perf-metric/perf-metric.fetch.js.map +1 -1
- package/src/plugins/pii-tokenizer/pii-tokenizer.request.d.ts.map +1 -1
- package/src/plugins/pii-tokenizer/pii-tokenizer.request.js.map +1 -1
- package/src/plugins/raw-response-info/raw-response-info.reply.js.map +1 -1
- package/src/plugins/retry/retry.fetch.js.map +1 -1
- package/src/plugins/reviver/reviver.reply.d.ts +7 -0
- package/src/plugins/reviver/reviver.reply.d.ts.map +1 -1
- package/src/plugins/reviver/reviver.reply.js +12 -1
- package/src/plugins/reviver/reviver.reply.js.map +1 -1
- package/src/plugins/session-id/session-id.request.d.ts +1 -0
- package/src/plugins/session-id/session-id.request.d.ts.map +1 -1
- package/src/plugins/session-id/session-id.request.js +1 -0
- package/src/plugins/session-id/session-id.request.js.map +1 -1
- package/src/plugins/si-token/si-token.request.js.map +1 -1
- package/src/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js.map +1 -1
- package/src/plugins/timeout/timeout.fetch.d.ts.map +1 -1
- package/src/plugins/timeout/timeout.fetch.js +2 -0
- package/src/plugins/timeout/timeout.fetch.js.map +1 -1
- package/src/plugins/wait-for/wait-for.fetch.js.map +1 -1
- package/src/utils/crypto.js.map +1 -1
- package/src/utils/encoder.js.map +1 -1
- package/src/utils/generic-api.d.ts +39 -0
- package/src/utils/generic-api.d.ts.map +1 -0
- package/src/utils/generic-api.js +43 -0
- package/src/utils/generic-api.js.map +1 -0
- package/src/utils/index.d.ts +1 -0
- package/src/utils/index.d.ts.map +1 -1
- package/src/utils/index.js +1 -0
- package/src/utils/index.js.map +1 -1
- package/src/utils/json-token.d.ts.map +1 -1
- package/src/utils/json-token.js.map +1 -1
|
@@ -193,10 +193,10 @@ function _ts_generator(thisArg, body) {
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
import { ExceptionReply } from
|
|
197
|
-
import { ReviverReply } from
|
|
198
|
-
import { extractQueryParams, filterUndefinedValues, getResponseReviver, prepareUrl, processFormData, tokenizeRequestOptions } from
|
|
199
|
-
import { EmptyResponseError } from
|
|
196
|
+
import { ExceptionReply } from '../plugins/exception';
|
|
197
|
+
import { ReviverReply } from '../plugins/reviver';
|
|
198
|
+
import { extractQueryParams, filterUndefinedValues, getResponseReviver, prepareUrl, processFormData, tokenizeRequestOptions } from '../fwk/api.helpers';
|
|
199
|
+
import { EmptyResponseError } from '../fwk/errors';
|
|
200
200
|
var DEFAULT_OPTIONS = {
|
|
201
201
|
replyPlugins: [
|
|
202
202
|
new ReviverReply(),
|
|
@@ -222,24 +222,18 @@ var DEFAULT_OPTIONS = {
|
|
|
222
222
|
}
|
|
223
223
|
},
|
|
224
224
|
{
|
|
225
|
-
key: "
|
|
226
|
-
value:
|
|
225
|
+
key: "getRequestOptions",
|
|
226
|
+
value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
|
|
227
227
|
var _this = this;
|
|
228
228
|
return _async_to_generator(function() {
|
|
229
|
-
var
|
|
229
|
+
var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
230
230
|
return _ts_generator(this, function(_state) {
|
|
231
231
|
switch(_state.label){
|
|
232
232
|
case 0:
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
queryParams: filterUndefinedValues(queryParams),
|
|
238
|
-
basePath: url,
|
|
239
|
-
tokenizedOptions: tokenizedOptions,
|
|
240
|
-
metadata: metadata
|
|
241
|
-
};
|
|
242
|
-
opts = options;
|
|
233
|
+
opts = _object_spread_props(_object_spread({}, requestOptionsParameters), {
|
|
234
|
+
headers: new Headers(filterUndefinedValues(requestOptionsParameters.headers)),
|
|
235
|
+
queryParams: filterUndefinedValues(requestOptionsParameters.queryParams)
|
|
236
|
+
});
|
|
243
237
|
if (!_this.options.requestPlugins) return [
|
|
244
238
|
3,
|
|
245
239
|
8
|
|
@@ -264,7 +258,8 @@ var DEFAULT_OPTIONS = {
|
|
|
264
258
|
return [
|
|
265
259
|
4,
|
|
266
260
|
plugin.load({
|
|
267
|
-
logger: _this.options.logger
|
|
261
|
+
logger: _this.options.logger,
|
|
262
|
+
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
268
263
|
}).transform(opts)
|
|
269
264
|
];
|
|
270
265
|
case 3:
|
|
@@ -312,6 +307,29 @@ var DEFAULT_OPTIONS = {
|
|
|
312
307
|
})();
|
|
313
308
|
}
|
|
314
309
|
},
|
|
310
|
+
{
|
|
311
|
+
key: "prepareOptions",
|
|
312
|
+
value: /** @inheritdoc */ function prepareOptions(url, method, queryParams, headers, body, tokenizedOptions, metadata, api) {
|
|
313
|
+
var _this = this;
|
|
314
|
+
return _async_to_generator(function() {
|
|
315
|
+
return _ts_generator(this, function(_state) {
|
|
316
|
+
return [
|
|
317
|
+
2,
|
|
318
|
+
_this.getRequestOptions({
|
|
319
|
+
headers: headers,
|
|
320
|
+
method: method,
|
|
321
|
+
basePath: url,
|
|
322
|
+
queryParams: queryParams,
|
|
323
|
+
body: body,
|
|
324
|
+
metadata: metadata,
|
|
325
|
+
tokenizedOptions: tokenizedOptions,
|
|
326
|
+
api: api
|
|
327
|
+
})
|
|
328
|
+
];
|
|
329
|
+
});
|
|
330
|
+
})();
|
|
331
|
+
}
|
|
332
|
+
},
|
|
315
333
|
{
|
|
316
334
|
key: "prepareUrl",
|
|
317
335
|
value: /** @inheritdoc */ function prepareUrl1(url) {
|
|
@@ -336,11 +354,11 @@ var DEFAULT_OPTIONS = {
|
|
|
336
354
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
337
355
|
var _this = this;
|
|
338
356
|
return _async_to_generator(function() {
|
|
339
|
-
var response, root, exception, origin, headers,
|
|
357
|
+
var response, root, exception, origin, headers, asyncResponse, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, pluginRunner, err;
|
|
340
358
|
return _ts_generator(this, function(_state) {
|
|
341
359
|
switch(_state.label){
|
|
342
360
|
case 0:
|
|
343
|
-
origin = options.headers.get(
|
|
361
|
+
origin = options.headers.get('Origin');
|
|
344
362
|
_state.label = 1;
|
|
345
363
|
case 1:
|
|
346
364
|
_state.trys.push([
|
|
@@ -350,14 +368,13 @@ var DEFAULT_OPTIONS = {
|
|
|
350
368
|
4
|
|
351
369
|
]);
|
|
352
370
|
headers = Object.fromEntries(options.headers.entries());
|
|
353
|
-
controller = typeof AbortController !== "undefined" ? new AbortController() : undefined;
|
|
354
|
-
if (controller) {
|
|
355
|
-
options.signal = controller.signal;
|
|
356
|
-
}
|
|
357
371
|
asyncResponse = new Promise(function(resolve, reject) {
|
|
372
|
+
var _options_metadata;
|
|
358
373
|
var data;
|
|
359
|
-
|
|
360
|
-
|
|
374
|
+
var metadataSignal = (_options_metadata = options.metadata) === null || _options_metadata === void 0 ? void 0 : _options_metadata.signal;
|
|
375
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
376
|
+
var subscription = _this.options.httpClient.request(options.method, url, _object_spread_props(_object_spread({}, options), {
|
|
377
|
+
observe: 'response',
|
|
361
378
|
headers: headers
|
|
362
379
|
})).subscribe({
|
|
363
380
|
next: function(res) {
|
|
@@ -370,6 +387,11 @@ var DEFAULT_OPTIONS = {
|
|
|
370
387
|
return resolve(data);
|
|
371
388
|
}
|
|
372
389
|
});
|
|
390
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
391
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.addEventListener('abort', function() {
|
|
392
|
+
subscription.unsubscribe();
|
|
393
|
+
reject(metadataSignal.reason);
|
|
394
|
+
});
|
|
373
395
|
});
|
|
374
396
|
return [
|
|
375
397
|
4,
|
|
@@ -384,7 +406,7 @@ var DEFAULT_OPTIONS = {
|
|
|
384
406
|
];
|
|
385
407
|
case 3:
|
|
386
408
|
e = _state.sent();
|
|
387
|
-
exception = new EmptyResponseError(e.message ||
|
|
409
|
+
exception = new EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
|
|
388
410
|
apiName: apiName,
|
|
389
411
|
operationId: operationId,
|
|
390
412
|
url: url,
|
|
@@ -30,6 +30,13 @@ function _define_property(obj, key, value) {
|
|
|
30
30
|
}
|
|
31
31
|
return obj;
|
|
32
32
|
}
|
|
33
|
+
function _instanceof(left, right) {
|
|
34
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
35
|
+
return !!right[Symbol.hasInstance](left);
|
|
36
|
+
} else {
|
|
37
|
+
return left instanceof right;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
33
40
|
function _object_spread(target) {
|
|
34
41
|
for(var i = 1; i < arguments.length; i++){
|
|
35
42
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -45,7 +52,31 @@ function _object_spread(target) {
|
|
|
45
52
|
}
|
|
46
53
|
return target;
|
|
47
54
|
}
|
|
48
|
-
|
|
55
|
+
function ownKeys(object, enumerableOnly) {
|
|
56
|
+
var keys = Object.keys(object);
|
|
57
|
+
if (Object.getOwnPropertySymbols) {
|
|
58
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
59
|
+
if (enumerableOnly) {
|
|
60
|
+
symbols = symbols.filter(function(sym) {
|
|
61
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
keys.push.apply(keys, symbols);
|
|
65
|
+
}
|
|
66
|
+
return keys;
|
|
67
|
+
}
|
|
68
|
+
function _object_spread_props(target, source) {
|
|
69
|
+
source = source != null ? source : {};
|
|
70
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
71
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
72
|
+
} else {
|
|
73
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
74
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return target;
|
|
78
|
+
}
|
|
79
|
+
import { extractQueryParams, filterUndefinedValues, prepareUrl, processFormData, tokenizeRequestOptions } from '../fwk/api.helpers';
|
|
49
80
|
var DEFAULT_OPTIONS = {
|
|
50
81
|
replyPlugins: [],
|
|
51
82
|
requestPlugins: [],
|
|
@@ -54,8 +85,10 @@ var DEFAULT_OPTIONS = {
|
|
|
54
85
|
/**
|
|
55
86
|
* Determine if the given value is a promise
|
|
56
87
|
* @param value The value to test
|
|
57
|
-
*/
|
|
58
|
-
|
|
88
|
+
*/ // NOTE: the `extends unknown` is required for ESM build with TSC
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
90
|
+
var isPromise = function(value) {
|
|
91
|
+
return _instanceof(value, Promise);
|
|
59
92
|
};
|
|
60
93
|
/**
|
|
61
94
|
* The Beacon API client is an implementation of the API Client using the Navigator Beacon API.
|
|
@@ -65,8 +98,8 @@ var DEFAULT_OPTIONS = {
|
|
|
65
98
|
function ApiBeaconClient(options) {
|
|
66
99
|
_class_call_check(this, ApiBeaconClient);
|
|
67
100
|
/** @inheritdoc */ _define_property(this, "options", void 0);
|
|
68
|
-
if (typeof navigator ===
|
|
69
|
-
throw new Error(
|
|
101
|
+
if (typeof navigator === 'undefined' || !navigator.sendBeacon) {
|
|
102
|
+
throw new Error('Beacon API is not supported in this context');
|
|
70
103
|
}
|
|
71
104
|
this.options = _object_spread({}, DEFAULT_OPTIONS, options);
|
|
72
105
|
}
|
|
@@ -78,28 +111,24 @@ var DEFAULT_OPTIONS = {
|
|
|
78
111
|
}
|
|
79
112
|
},
|
|
80
113
|
{
|
|
81
|
-
key: "
|
|
82
|
-
value: /** @inheritdoc */ function
|
|
83
|
-
if (method.toUpperCase() !==
|
|
84
|
-
throw new Error("Unsupported method: ".concat(method, ". The beacon API only supports POST."));
|
|
114
|
+
key: "getRequestOptions",
|
|
115
|
+
value: /** @inheritdoc */ function getRequestOptions(options) {
|
|
116
|
+
if (options.method.toUpperCase() !== 'POST') {
|
|
117
|
+
throw new Error("Unsupported method: ".concat(options.method, ". The beacon API only supports POST."));
|
|
85
118
|
}
|
|
86
|
-
var
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
queryParams: filterUndefinedValues(queryParams),
|
|
91
|
-
basePath: url,
|
|
92
|
-
tokenizedOptions: tokenizedOptions,
|
|
93
|
-
metadata: metadata
|
|
94
|
-
};
|
|
95
|
-
var opts = options;
|
|
119
|
+
var opts = _object_spread_props(_object_spread({}, options), {
|
|
120
|
+
headers: new Headers(filterUndefinedValues(options.headers)),
|
|
121
|
+
queryParams: filterUndefinedValues(options.queryParams)
|
|
122
|
+
});
|
|
96
123
|
if (this.options.requestPlugins) {
|
|
97
124
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
98
125
|
try {
|
|
99
126
|
for(var _iterator = this.options.requestPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
100
127
|
var plugin = _step.value;
|
|
128
|
+
var _options_api;
|
|
101
129
|
var changedOpt = plugin.load({
|
|
102
|
-
logger: this.options.logger
|
|
130
|
+
logger: this.options.logger,
|
|
131
|
+
apiName: (_options_api = options.api) === null || _options_api === void 0 ? void 0 : _options_api.apiName
|
|
103
132
|
}).transform(opts);
|
|
104
133
|
if (isPromise(changedOpt)) {
|
|
105
134
|
throw new Error("Request plugin ".concat(plugin.constructor.name, " has async transform method. Only sync methods are supported with the Beacon client."));
|
|
@@ -125,6 +154,21 @@ var DEFAULT_OPTIONS = {
|
|
|
125
154
|
return Promise.resolve(opts);
|
|
126
155
|
}
|
|
127
156
|
},
|
|
157
|
+
{
|
|
158
|
+
key: "prepareOptions",
|
|
159
|
+
value: /** @inheritdoc */ function prepareOptions(url, method, queryParams, headers, body, tokenizedOptions, metadata, api) {
|
|
160
|
+
return this.getRequestOptions({
|
|
161
|
+
headers: headers,
|
|
162
|
+
method: method,
|
|
163
|
+
basePath: url,
|
|
164
|
+
queryParams: queryParams,
|
|
165
|
+
body: body,
|
|
166
|
+
metadata: metadata,
|
|
167
|
+
tokenizedOptions: tokenizedOptions,
|
|
168
|
+
api: api
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
},
|
|
128
172
|
{
|
|
129
173
|
key: "prepareUrl",
|
|
130
174
|
value: /** @inheritdoc */ function prepareUrl1(url, queryParameters) {
|
|
@@ -147,7 +191,7 @@ var DEFAULT_OPTIONS = {
|
|
|
147
191
|
key: "processCall",
|
|
148
192
|
value: /** @inheritdoc */ function processCall(url, options, _apiType, _apiName, _revivers, _operationId) {
|
|
149
193
|
var headers = _object_spread({
|
|
150
|
-
type:
|
|
194
|
+
type: 'application/json'
|
|
151
195
|
}, options.headers.entries());
|
|
152
196
|
var blob = new Blob(options.body ? [
|
|
153
197
|
JSON.stringify(options.body)
|
|
@@ -95,6 +95,30 @@ function _object_spread(target) {
|
|
|
95
95
|
}
|
|
96
96
|
return target;
|
|
97
97
|
}
|
|
98
|
+
function ownKeys(object, enumerableOnly) {
|
|
99
|
+
var keys = Object.keys(object);
|
|
100
|
+
if (Object.getOwnPropertySymbols) {
|
|
101
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
102
|
+
if (enumerableOnly) {
|
|
103
|
+
symbols = symbols.filter(function(sym) {
|
|
104
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
keys.push.apply(keys, symbols);
|
|
108
|
+
}
|
|
109
|
+
return keys;
|
|
110
|
+
}
|
|
111
|
+
function _object_spread_props(target, source) {
|
|
112
|
+
source = source != null ? source : {};
|
|
113
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
114
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
115
|
+
} else {
|
|
116
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
117
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return target;
|
|
121
|
+
}
|
|
98
122
|
function _to_consumable_array(arr) {
|
|
99
123
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
100
124
|
}
|
|
@@ -201,10 +225,10 @@ function _ts_generator(thisArg, body) {
|
|
|
201
225
|
};
|
|
202
226
|
}
|
|
203
227
|
}
|
|
204
|
-
import { ExceptionReply } from
|
|
205
|
-
import { ReviverReply } from
|
|
206
|
-
import { extractQueryParams, filterUndefinedValues, getResponseReviver, prepareUrl, processFormData, tokenizeRequestOptions } from
|
|
207
|
-
import { CanceledCallError, EmptyResponseError, ResponseJSONParseError } from
|
|
228
|
+
import { ExceptionReply } from '../plugins/exception';
|
|
229
|
+
import { ReviverReply } from '../plugins/reviver';
|
|
230
|
+
import { extractQueryParams, filterUndefinedValues, getResponseReviver, prepareUrl, processFormData, tokenizeRequestOptions } from '../fwk/api.helpers';
|
|
231
|
+
import { CanceledCallError, EmptyResponseError, ResponseJSONParseError } from '../fwk/errors';
|
|
208
232
|
var DEFAULT_OPTIONS = {
|
|
209
233
|
replyPlugins: [
|
|
210
234
|
new ReviverReply(),
|
|
@@ -236,24 +260,18 @@ var DEFAULT_OPTIONS = {
|
|
|
236
260
|
}
|
|
237
261
|
},
|
|
238
262
|
{
|
|
239
|
-
key: "
|
|
240
|
-
value: /** @inheritdoc */ function
|
|
263
|
+
key: "getRequestOptions",
|
|
264
|
+
value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
|
|
241
265
|
var _this = this;
|
|
242
266
|
return _async_to_generator(function() {
|
|
243
|
-
var
|
|
267
|
+
var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
244
268
|
return _ts_generator(this, function(_state) {
|
|
245
269
|
switch(_state.label){
|
|
246
270
|
case 0:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
queryParams: filterUndefinedValues(queryParams),
|
|
252
|
-
basePath: url,
|
|
253
|
-
tokenizedOptions: tokenizedOptions,
|
|
254
|
-
metadata: metadata
|
|
255
|
-
};
|
|
256
|
-
opts = options;
|
|
271
|
+
opts = _object_spread_props(_object_spread({}, requestOptionsParameters), {
|
|
272
|
+
headers: new Headers(filterUndefinedValues(requestOptionsParameters.headers)),
|
|
273
|
+
queryParams: filterUndefinedValues(requestOptionsParameters.queryParams)
|
|
274
|
+
});
|
|
257
275
|
if (!_this.options.requestPlugins) return [
|
|
258
276
|
3,
|
|
259
277
|
8
|
|
@@ -278,7 +296,8 @@ var DEFAULT_OPTIONS = {
|
|
|
278
296
|
return [
|
|
279
297
|
4,
|
|
280
298
|
plugin.load({
|
|
281
|
-
logger: _this.options.logger
|
|
299
|
+
logger: _this.options.logger,
|
|
300
|
+
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
282
301
|
}).transform(opts)
|
|
283
302
|
];
|
|
284
303
|
case 3:
|
|
@@ -326,6 +345,29 @@ var DEFAULT_OPTIONS = {
|
|
|
326
345
|
})();
|
|
327
346
|
}
|
|
328
347
|
},
|
|
348
|
+
{
|
|
349
|
+
key: "prepareOptions",
|
|
350
|
+
value: /** @inheritdoc */ function prepareOptions(url, method, queryParams, headers, body, tokenizedOptions, metadata, api) {
|
|
351
|
+
var _this = this;
|
|
352
|
+
return _async_to_generator(function() {
|
|
353
|
+
return _ts_generator(this, function(_state) {
|
|
354
|
+
return [
|
|
355
|
+
2,
|
|
356
|
+
_this.getRequestOptions({
|
|
357
|
+
headers: headers,
|
|
358
|
+
method: method,
|
|
359
|
+
basePath: url,
|
|
360
|
+
queryParams: queryParams,
|
|
361
|
+
body: body,
|
|
362
|
+
metadata: metadata,
|
|
363
|
+
tokenizedOptions: tokenizedOptions,
|
|
364
|
+
api: api
|
|
365
|
+
})
|
|
366
|
+
];
|
|
367
|
+
});
|
|
368
|
+
})();
|
|
369
|
+
}
|
|
370
|
+
},
|
|
329
371
|
{
|
|
330
372
|
key: "prepareUrl",
|
|
331
373
|
value: /** @inheritdoc */ function prepareUrl1(url) {
|
|
@@ -344,11 +386,11 @@ var DEFAULT_OPTIONS = {
|
|
|
344
386
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
345
387
|
var _this = this;
|
|
346
388
|
return _async_to_generator(function() {
|
|
347
|
-
var response, asyncResponse, root, body, exception, origin, controller, loadedPlugins, _loadedPlugins, canStart, isCanceledBy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, pluginRunner, err;
|
|
389
|
+
var response, asyncResponse, root, body, exception, origin, _options_metadata, metadataSignal, controller, loadedPlugins, _loadedPlugins, canStart, isCanceledBy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, pluginRunner, err;
|
|
348
390
|
return _ts_generator(this, function(_state) {
|
|
349
391
|
switch(_state.label){
|
|
350
392
|
case 0:
|
|
351
|
-
origin = options.headers.get(
|
|
393
|
+
origin = options.headers.get('Origin');
|
|
352
394
|
_state.label = 1;
|
|
353
395
|
case 1:
|
|
354
396
|
_state.trys.push([
|
|
@@ -357,10 +399,13 @@ var DEFAULT_OPTIONS = {
|
|
|
357
399
|
,
|
|
358
400
|
6
|
|
359
401
|
]);
|
|
402
|
+
metadataSignal = (_options_metadata = options.metadata) === null || _options_metadata === void 0 ? void 0 : _options_metadata.signal;
|
|
403
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
360
404
|
controller = new AbortController();
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
405
|
+
options.signal = controller.signal;
|
|
406
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.addEventListener('abort', function() {
|
|
407
|
+
return controller.abort();
|
|
408
|
+
});
|
|
364
409
|
loadedPlugins = [];
|
|
365
410
|
if (_this.options.fetchPlugins) {
|
|
366
411
|
;
|
|
@@ -436,7 +481,7 @@ var DEFAULT_OPTIONS = {
|
|
|
436
481
|
if (_instanceof(e, CanceledCallError)) {
|
|
437
482
|
exception = e;
|
|
438
483
|
} else {
|
|
439
|
-
exception = new EmptyResponseError(e.message ||
|
|
484
|
+
exception = new EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
|
|
440
485
|
apiName: apiName,
|
|
441
486
|
operationId: operationId,
|
|
442
487
|
url: url,
|
|
@@ -451,7 +496,7 @@ var DEFAULT_OPTIONS = {
|
|
|
451
496
|
try {
|
|
452
497
|
root = body ? JSON.parse(body) : undefined;
|
|
453
498
|
} catch (e) {
|
|
454
|
-
exception = new ResponseJSONParseError(e.message ||
|
|
499
|
+
exception = new ResponseJSONParseError(e.message || 'Fail to parse response body', response && response.status || 0, body, {
|
|
455
500
|
apiName: apiName,
|
|
456
501
|
operationId: operationId,
|
|
457
502
|
url: url,
|
package/esm2015/clients/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './api-beacon-client';
|
|
2
|
+
export * from './api-fetch-client';
|
package/esm2015/fwk/Reviver.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* Used in case of maps (dictionaries): All values of the map must be of the same type. reviveWithType will be called
|
|
3
3
|
* for each of these elements.
|
|
4
4
|
* @param dictionaries
|
|
5
5
|
* @param reviver
|
|
6
|
+
* @param options Reviver options
|
|
6
7
|
*/ export function reviveMap(data) {
|
|
7
|
-
var dictionaries = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null, reviver = arguments.length > 2 ? arguments[2] : void 0;
|
|
8
|
+
var dictionaries = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null, reviver = arguments.length > 2 ? arguments[2] : void 0, options = arguments.length > 3 ? arguments[3] : void 0;
|
|
8
9
|
if (!data) {
|
|
9
10
|
return undefined;
|
|
10
11
|
}
|
|
@@ -12,7 +13,7 @@
|
|
|
12
13
|
for(var key in data){
|
|
13
14
|
// eslint-disable-next-line no-prototype-builtins
|
|
14
15
|
if (data.hasOwnProperty(key)) {
|
|
15
|
-
revived[key] = reviver(data[key], dictionaries);
|
|
16
|
+
revived[key] = reviver(data[key], dictionaries, options);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
return revived;
|
|
@@ -22,13 +23,14 @@
|
|
|
22
23
|
* @param data
|
|
23
24
|
* @param dictionaries
|
|
24
25
|
* @param reviver
|
|
26
|
+
* @param options Reviver options
|
|
25
27
|
*/ export function reviveArray(data) {
|
|
26
|
-
var dictionaries = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null, reviver = arguments.length > 2 ? arguments[2] : void 0;
|
|
28
|
+
var dictionaries = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null, reviver = arguments.length > 2 ? arguments[2] : void 0, options = arguments.length > 3 ? arguments[3] : void 0;
|
|
27
29
|
if (!data) {
|
|
28
30
|
return undefined;
|
|
29
31
|
}
|
|
30
32
|
for(var i = 0; i < data.length; i++){
|
|
31
|
-
data[i] = reviver(data[i], dictionaries);
|
|
33
|
+
data[i] = reviver(data[i], dictionaries, options);
|
|
32
34
|
}
|
|
33
35
|
return data;
|
|
34
36
|
}
|
|
@@ -38,13 +40,14 @@
|
|
|
38
40
|
* @param dictionary : Specific dictionary associated to T
|
|
39
41
|
* @param reviver : Function to revive the Data object, once retrieved from the dictionary.
|
|
40
42
|
* If not passed as argument, the map entry won't be revived
|
|
43
|
+
* @param options Reviver options
|
|
41
44
|
* @returns Map of id : {revived dictionarized item}
|
|
42
|
-
*/ export function reviveDictionarizedArray(ids, dictionary, reviver) {
|
|
45
|
+
*/ export function reviveDictionarizedArray(ids, dictionary, reviver, options) {
|
|
43
46
|
if (!ids) {
|
|
44
47
|
return undefined;
|
|
45
48
|
}
|
|
46
49
|
return ids.reduce(function(map, id) {
|
|
47
|
-
map[id] = reviver ? reviver(dictionary[id], dictionary) : dictionary[id];
|
|
50
|
+
map[id] = reviver ? reviver(dictionary[id], dictionary, options) : dictionary[id];
|
|
48
51
|
return map;
|
|
49
52
|
}, {});
|
|
50
53
|
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable no-console */ import { getResponseReviver } from
|
|
2
|
-
describe(
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable no-console */ import { getResponseReviver } from '@ama-sdk/core';
|
|
2
|
+
describe('getResponseReviver - revivers by status code', function() {
|
|
3
3
|
var revivers = {
|
|
4
4
|
202: jest.fn(),
|
|
5
5
|
201: jest.fn()
|
|
6
6
|
};
|
|
7
7
|
beforeEach(function() {
|
|
8
|
-
jest.spyOn(console,
|
|
8
|
+
jest.spyOn(console, 'error');
|
|
9
9
|
});
|
|
10
10
|
afterEach(function() {
|
|
11
11
|
jest.clearAllMocks();
|
|
12
12
|
});
|
|
13
|
-
it(
|
|
13
|
+
it('should not return a reviver for a non ok response', function() {
|
|
14
14
|
expect(getResponseReviver(revivers, {
|
|
15
15
|
status: 300,
|
|
16
16
|
ok: false
|
|
17
17
|
})).toBe(undefined);
|
|
18
18
|
});
|
|
19
|
-
it(
|
|
19
|
+
it('should return a reason but not reviver for a 204 No Content Response', function() {
|
|
20
20
|
expect(getResponseReviver(revivers, {
|
|
21
21
|
status: 204,
|
|
22
22
|
ok: true
|
|
23
23
|
})).toBe(undefined);
|
|
24
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
24
|
+
expect(console.error).toHaveBeenCalledWith('API status code error for unknown endpoint - 204 response is not defined in the API specification');
|
|
25
25
|
});
|
|
26
|
-
it(
|
|
26
|
+
it('should return the status code\'s reviver', function() {
|
|
27
27
|
expect(getResponseReviver(revivers, {
|
|
28
28
|
status: 202,
|
|
29
29
|
ok: true
|
|
30
|
-
},
|
|
30
|
+
}, 'myEndpoint')).toBe(revivers[202]);
|
|
31
31
|
expect(console.error).not.toHaveBeenCalled();
|
|
32
32
|
});
|
|
33
|
-
it(
|
|
33
|
+
it('should fallback on the first defined status if the status code\'s reviver is not defined', function() {
|
|
34
34
|
expect(getResponseReviver(revivers, {
|
|
35
35
|
status: undefined,
|
|
36
36
|
ok: true
|
|
37
|
-
},
|
|
38
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
37
|
+
}, 'myEndpoint')).toBe(revivers[201]);
|
|
38
|
+
expect(console.error).toHaveBeenCalledWith('API status code error for myEndpoint endpoint - Unknown undefined code returned by the API - Fallback to 201\'s reviver');
|
|
39
39
|
});
|
|
40
|
-
it(
|
|
40
|
+
it('should not fallback on 204 (No Content)\'s reviver', function() {
|
|
41
41
|
var reviversWith204 = {
|
|
42
42
|
204: jest.fn(),
|
|
43
43
|
206: jest.fn()
|
|
@@ -45,33 +45,33 @@ describe("getResponseReviver - revivers by status code", function() {
|
|
|
45
45
|
var fallback = getResponseReviver(reviversWith204, {
|
|
46
46
|
status: 201,
|
|
47
47
|
ok: true
|
|
48
|
-
},
|
|
48
|
+
}, 'myEndpoint');
|
|
49
49
|
expect(fallback).toBe(reviversWith204[206]);
|
|
50
50
|
expect(fallback).not.toBe(reviversWith204[204]);
|
|
51
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
51
|
+
expect(console.error).toHaveBeenCalledWith('API status code error for myEndpoint endpoint - Unknown 201 code returned by the API - Fallback to 206\'s reviver');
|
|
52
52
|
});
|
|
53
|
-
it(
|
|
54
|
-
jest.spyOn(console,
|
|
53
|
+
it('should not fallback if the feature is deactivated', function() {
|
|
54
|
+
jest.spyOn(console, 'log');
|
|
55
55
|
expect(getResponseReviver(revivers, {
|
|
56
56
|
status: 206,
|
|
57
57
|
ok: true
|
|
58
|
-
},
|
|
58
|
+
}, 'myEndpoint', {
|
|
59
59
|
disableFallback: true,
|
|
60
60
|
log: console.log
|
|
61
61
|
})).toBe(undefined);
|
|
62
62
|
expect(console.error).not.toHaveBeenCalled();
|
|
63
|
-
expect(console.log).toHaveBeenCalledWith(
|
|
63
|
+
expect(console.log).toHaveBeenCalledWith('API status code error for myEndpoint endpoint - Missing 206 from API specification - fallback is deactivated, no revive will run on this response');
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
|
-
describe(
|
|
66
|
+
describe('getResponseReviver - reviver as function', function() {
|
|
67
67
|
var reviver = jest.fn();
|
|
68
|
-
it(
|
|
68
|
+
it('should not return a reviver for a non ok response', function() {
|
|
69
69
|
expect(getResponseReviver(reviver, {
|
|
70
70
|
status: 300,
|
|
71
71
|
ok: false
|
|
72
72
|
})).toBe(undefined);
|
|
73
73
|
});
|
|
74
|
-
it(
|
|
74
|
+
it('should only return the reviver if the endpoint reviver is a function or an undefined object', function() {
|
|
75
75
|
expect(getResponseReviver(reviver, {
|
|
76
76
|
status: 200,
|
|
77
77
|
ok: true
|