@ama-sdk/core 11.0.0-next.0 → 11.0.0-next.2
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
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# @ama-sdk Core
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@ama-sdk/core)
|
|
4
|
+
[](https://www.npmjs.com/package/@ama-sdk/core)
|
|
5
|
+
|
|
3
6
|
This package contains all the [plugins](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core/src/plugins), helpers and object definitions to dialog with an API following the `ama-sdk` architecture.
|
|
4
7
|
|
|
5
8
|
Please refer to the [ama-sdk-schematics](../schematics/README.md) package for getting started with an API based on `ama-sdk`.
|
|
@@ -46,7 +49,7 @@ A list of API Clients are provided by this package:
|
|
|
46
49
|
### Logs
|
|
47
50
|
|
|
48
51
|
In order to ease the logging in the ama-sdk plugins, it is possible to connect to third-party logging services.
|
|
49
|
-
This can be achieved by adding a `Logger` [implementation](/packages
|
|
52
|
+
This can be achieved by adding a `Logger` [implementation](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core/src/fwk/logger.ts) to the options of an API client.
|
|
50
53
|
|
|
51
54
|
For example, in the Otter showcase application, we could add a `ConsoleLogger` (from `@o3r/core`) as a parameter to the ApiFetchClient:
|
|
52
55
|
|
|
@@ -232,24 +232,18 @@ var ApiAngularClient = /*#__PURE__*/ function() {
|
|
|
232
232
|
}
|
|
233
233
|
},
|
|
234
234
|
{
|
|
235
|
-
key: "
|
|
236
|
-
value:
|
|
235
|
+
key: "getRequestOptions",
|
|
236
|
+
value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
|
|
237
237
|
var _this = this;
|
|
238
238
|
return _async_to_generator(function() {
|
|
239
|
-
var
|
|
239
|
+
var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
240
240
|
return _ts_generator(this, function(_state) {
|
|
241
241
|
switch(_state.label){
|
|
242
242
|
case 0:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
queryParams: (0, _apihelpers.filterUndefinedValues)(queryParams),
|
|
248
|
-
basePath: url,
|
|
249
|
-
tokenizedOptions: tokenizedOptions,
|
|
250
|
-
metadata: metadata
|
|
251
|
-
};
|
|
252
|
-
opts = options;
|
|
243
|
+
opts = _object_spread_props(_object_spread({}, requestOptionsParameters), {
|
|
244
|
+
headers: new Headers((0, _apihelpers.filterUndefinedValues)(requestOptionsParameters.headers)),
|
|
245
|
+
queryParams: (0, _apihelpers.filterUndefinedValues)(requestOptionsParameters.queryParams)
|
|
246
|
+
});
|
|
253
247
|
if (!_this.options.requestPlugins) return [
|
|
254
248
|
3,
|
|
255
249
|
8
|
|
@@ -274,7 +268,8 @@ var ApiAngularClient = /*#__PURE__*/ function() {
|
|
|
274
268
|
return [
|
|
275
269
|
4,
|
|
276
270
|
plugin.load({
|
|
277
|
-
logger: _this.options.logger
|
|
271
|
+
logger: _this.options.logger,
|
|
272
|
+
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
278
273
|
}).transform(opts)
|
|
279
274
|
];
|
|
280
275
|
case 3:
|
|
@@ -322,6 +317,29 @@ var ApiAngularClient = /*#__PURE__*/ function() {
|
|
|
322
317
|
})();
|
|
323
318
|
}
|
|
324
319
|
},
|
|
320
|
+
{
|
|
321
|
+
key: "prepareOptions",
|
|
322
|
+
value: /** @inheritdoc */ function prepareOptions(url, method, queryParams, headers, body, tokenizedOptions, metadata, api) {
|
|
323
|
+
var _this = this;
|
|
324
|
+
return _async_to_generator(function() {
|
|
325
|
+
return _ts_generator(this, function(_state) {
|
|
326
|
+
return [
|
|
327
|
+
2,
|
|
328
|
+
_this.getRequestOptions({
|
|
329
|
+
headers: headers,
|
|
330
|
+
method: method,
|
|
331
|
+
basePath: url,
|
|
332
|
+
queryParams: queryParams,
|
|
333
|
+
body: body,
|
|
334
|
+
metadata: metadata,
|
|
335
|
+
tokenizedOptions: tokenizedOptions,
|
|
336
|
+
api: api
|
|
337
|
+
})
|
|
338
|
+
];
|
|
339
|
+
});
|
|
340
|
+
})();
|
|
341
|
+
}
|
|
342
|
+
},
|
|
325
343
|
{
|
|
326
344
|
key: "prepareUrl",
|
|
327
345
|
value: /** @inheritdoc */ function prepareUrl(url) {
|
|
@@ -346,11 +364,11 @@ var ApiAngularClient = /*#__PURE__*/ function() {
|
|
|
346
364
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
347
365
|
var _this = this;
|
|
348
366
|
return _async_to_generator(function() {
|
|
349
|
-
var response, root, exception, origin, headers,
|
|
367
|
+
var response, root, exception, origin, headers, asyncResponse, e, reviver, replyPlugins, parsedData, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, pluginRunner, err;
|
|
350
368
|
return _ts_generator(this, function(_state) {
|
|
351
369
|
switch(_state.label){
|
|
352
370
|
case 0:
|
|
353
|
-
origin = options.headers.get(
|
|
371
|
+
origin = options.headers.get('Origin');
|
|
354
372
|
_state.label = 1;
|
|
355
373
|
case 1:
|
|
356
374
|
_state.trys.push([
|
|
@@ -360,14 +378,13 @@ var ApiAngularClient = /*#__PURE__*/ function() {
|
|
|
360
378
|
4
|
|
361
379
|
]);
|
|
362
380
|
headers = Object.fromEntries(options.headers.entries());
|
|
363
|
-
controller = typeof AbortController !== "undefined" ? new AbortController() : undefined;
|
|
364
|
-
if (controller) {
|
|
365
|
-
options.signal = controller.signal;
|
|
366
|
-
}
|
|
367
381
|
asyncResponse = new Promise(function(resolve, reject) {
|
|
382
|
+
var _options_metadata;
|
|
368
383
|
var data;
|
|
369
|
-
|
|
370
|
-
|
|
384
|
+
var metadataSignal = (_options_metadata = options.metadata) === null || _options_metadata === void 0 ? void 0 : _options_metadata.signal;
|
|
385
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
386
|
+
var subscription = _this.options.httpClient.request(options.method, url, _object_spread_props(_object_spread({}, options), {
|
|
387
|
+
observe: 'response',
|
|
371
388
|
headers: headers
|
|
372
389
|
})).subscribe({
|
|
373
390
|
next: function(res) {
|
|
@@ -380,6 +397,11 @@ var ApiAngularClient = /*#__PURE__*/ function() {
|
|
|
380
397
|
return resolve(data);
|
|
381
398
|
}
|
|
382
399
|
});
|
|
400
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
401
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.addEventListener('abort', function() {
|
|
402
|
+
subscription.unsubscribe();
|
|
403
|
+
reject(metadataSignal.reason);
|
|
404
|
+
});
|
|
383
405
|
});
|
|
384
406
|
return [
|
|
385
407
|
4,
|
|
@@ -394,7 +416,7 @@ var ApiAngularClient = /*#__PURE__*/ function() {
|
|
|
394
416
|
];
|
|
395
417
|
case 3:
|
|
396
418
|
e = _state.sent();
|
|
397
|
-
exception = new _errors.EmptyResponseError(e.message ||
|
|
419
|
+
exception = new _errors.EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
|
|
398
420
|
apiName: apiName,
|
|
399
421
|
operationId: operationId,
|
|
400
422
|
url: url,
|
|
@@ -41,6 +41,13 @@ function _define_property(obj, key, value) {
|
|
|
41
41
|
}
|
|
42
42
|
return obj;
|
|
43
43
|
}
|
|
44
|
+
function _instanceof(left, right) {
|
|
45
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
46
|
+
return !!right[Symbol.hasInstance](left);
|
|
47
|
+
} else {
|
|
48
|
+
return left instanceof right;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
44
51
|
function _object_spread(target) {
|
|
45
52
|
for(var i = 1; i < arguments.length; i++){
|
|
46
53
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -56,6 +63,30 @@ function _object_spread(target) {
|
|
|
56
63
|
}
|
|
57
64
|
return target;
|
|
58
65
|
}
|
|
66
|
+
function ownKeys(object, enumerableOnly) {
|
|
67
|
+
var keys = Object.keys(object);
|
|
68
|
+
if (Object.getOwnPropertySymbols) {
|
|
69
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
70
|
+
if (enumerableOnly) {
|
|
71
|
+
symbols = symbols.filter(function(sym) {
|
|
72
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
keys.push.apply(keys, symbols);
|
|
76
|
+
}
|
|
77
|
+
return keys;
|
|
78
|
+
}
|
|
79
|
+
function _object_spread_props(target, source) {
|
|
80
|
+
source = source != null ? source : {};
|
|
81
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
82
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
83
|
+
} else {
|
|
84
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
85
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return target;
|
|
89
|
+
}
|
|
59
90
|
var DEFAULT_OPTIONS = {
|
|
60
91
|
replyPlugins: [],
|
|
61
92
|
requestPlugins: [],
|
|
@@ -64,16 +95,18 @@ var DEFAULT_OPTIONS = {
|
|
|
64
95
|
/**
|
|
65
96
|
* Determine if the given value is a promise
|
|
66
97
|
* @param value The value to test
|
|
67
|
-
*/
|
|
68
|
-
|
|
98
|
+
*/ // NOTE: the `extends unknown` is required for ESM build with TSC
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
100
|
+
var isPromise = function(value) {
|
|
101
|
+
return _instanceof(value, Promise);
|
|
69
102
|
};
|
|
70
103
|
var ApiBeaconClient = /*#__PURE__*/ function() {
|
|
71
104
|
"use strict";
|
|
72
105
|
function ApiBeaconClient(options) {
|
|
73
106
|
_class_call_check(this, ApiBeaconClient);
|
|
74
107
|
/** @inheritdoc */ _define_property(this, "options", void 0);
|
|
75
|
-
if (typeof navigator ===
|
|
76
|
-
throw new Error(
|
|
108
|
+
if (typeof navigator === 'undefined' || !navigator.sendBeacon) {
|
|
109
|
+
throw new Error('Beacon API is not supported in this context');
|
|
77
110
|
}
|
|
78
111
|
this.options = _object_spread({}, DEFAULT_OPTIONS, options);
|
|
79
112
|
}
|
|
@@ -85,28 +118,24 @@ var ApiBeaconClient = /*#__PURE__*/ function() {
|
|
|
85
118
|
}
|
|
86
119
|
},
|
|
87
120
|
{
|
|
88
|
-
key: "
|
|
89
|
-
value: /** @inheritdoc */ function
|
|
90
|
-
if (method.toUpperCase() !==
|
|
91
|
-
throw new Error("Unsupported method: ".concat(method, ". The beacon API only supports POST."));
|
|
121
|
+
key: "getRequestOptions",
|
|
122
|
+
value: /** @inheritdoc */ function getRequestOptions(options) {
|
|
123
|
+
if (options.method.toUpperCase() !== 'POST') {
|
|
124
|
+
throw new Error("Unsupported method: ".concat(options.method, ". The beacon API only supports POST."));
|
|
92
125
|
}
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
queryParams: (0, _apihelpers.filterUndefinedValues)(queryParams),
|
|
98
|
-
basePath: url,
|
|
99
|
-
tokenizedOptions: tokenizedOptions,
|
|
100
|
-
metadata: metadata
|
|
101
|
-
};
|
|
102
|
-
var opts = options;
|
|
126
|
+
var opts = _object_spread_props(_object_spread({}, options), {
|
|
127
|
+
headers: new Headers((0, _apihelpers.filterUndefinedValues)(options.headers)),
|
|
128
|
+
queryParams: (0, _apihelpers.filterUndefinedValues)(options.queryParams)
|
|
129
|
+
});
|
|
103
130
|
if (this.options.requestPlugins) {
|
|
104
131
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
105
132
|
try {
|
|
106
133
|
for(var _iterator = this.options.requestPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
107
134
|
var plugin = _step.value;
|
|
135
|
+
var _options_api;
|
|
108
136
|
var changedOpt = plugin.load({
|
|
109
|
-
logger: this.options.logger
|
|
137
|
+
logger: this.options.logger,
|
|
138
|
+
apiName: (_options_api = options.api) === null || _options_api === void 0 ? void 0 : _options_api.apiName
|
|
110
139
|
}).transform(opts);
|
|
111
140
|
if (isPromise(changedOpt)) {
|
|
112
141
|
throw new Error("Request plugin ".concat(plugin.constructor.name, " has async transform method. Only sync methods are supported with the Beacon client."));
|
|
@@ -132,6 +161,21 @@ var ApiBeaconClient = /*#__PURE__*/ function() {
|
|
|
132
161
|
return Promise.resolve(opts);
|
|
133
162
|
}
|
|
134
163
|
},
|
|
164
|
+
{
|
|
165
|
+
key: "prepareOptions",
|
|
166
|
+
value: /** @inheritdoc */ function prepareOptions(url, method, queryParams, headers, body, tokenizedOptions, metadata, api) {
|
|
167
|
+
return this.getRequestOptions({
|
|
168
|
+
headers: headers,
|
|
169
|
+
method: method,
|
|
170
|
+
basePath: url,
|
|
171
|
+
queryParams: queryParams,
|
|
172
|
+
body: body,
|
|
173
|
+
metadata: metadata,
|
|
174
|
+
tokenizedOptions: tokenizedOptions,
|
|
175
|
+
api: api
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
},
|
|
135
179
|
{
|
|
136
180
|
key: "prepareUrl",
|
|
137
181
|
value: /** @inheritdoc */ function prepareUrl(url, queryParameters) {
|
|
@@ -154,7 +198,7 @@ var ApiBeaconClient = /*#__PURE__*/ function() {
|
|
|
154
198
|
key: "processCall",
|
|
155
199
|
value: /** @inheritdoc */ function processCall(url, options, _apiType, _apiName, _revivers, _operationId) {
|
|
156
200
|
var headers = _object_spread({
|
|
157
|
-
type:
|
|
201
|
+
type: 'application/json'
|
|
158
202
|
}, options.headers.entries());
|
|
159
203
|
var blob = new Blob(options.body ? [
|
|
160
204
|
JSON.stringify(options.body)
|
|
@@ -109,6 +109,30 @@ function _object_spread(target) {
|
|
|
109
109
|
}
|
|
110
110
|
return target;
|
|
111
111
|
}
|
|
112
|
+
function ownKeys(object, enumerableOnly) {
|
|
113
|
+
var keys = Object.keys(object);
|
|
114
|
+
if (Object.getOwnPropertySymbols) {
|
|
115
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
116
|
+
if (enumerableOnly) {
|
|
117
|
+
symbols = symbols.filter(function(sym) {
|
|
118
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
keys.push.apply(keys, symbols);
|
|
122
|
+
}
|
|
123
|
+
return keys;
|
|
124
|
+
}
|
|
125
|
+
function _object_spread_props(target, source) {
|
|
126
|
+
source = source != null ? source : {};
|
|
127
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
128
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
129
|
+
} else {
|
|
130
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
131
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return target;
|
|
135
|
+
}
|
|
112
136
|
function _to_consumable_array(arr) {
|
|
113
137
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
114
138
|
}
|
|
@@ -246,24 +270,18 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
246
270
|
}
|
|
247
271
|
},
|
|
248
272
|
{
|
|
249
|
-
key: "
|
|
250
|
-
value: /** @inheritdoc */ function
|
|
273
|
+
key: "getRequestOptions",
|
|
274
|
+
value: /** @inheritdoc */ function getRequestOptions(requestOptionsParameters) {
|
|
251
275
|
var _this = this;
|
|
252
276
|
return _async_to_generator(function() {
|
|
253
|
-
var
|
|
277
|
+
var opts, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _requestOptionsParameters_api, err;
|
|
254
278
|
return _ts_generator(this, function(_state) {
|
|
255
279
|
switch(_state.label){
|
|
256
280
|
case 0:
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
queryParams: (0, _apihelpers.filterUndefinedValues)(queryParams),
|
|
262
|
-
basePath: url,
|
|
263
|
-
tokenizedOptions: tokenizedOptions,
|
|
264
|
-
metadata: metadata
|
|
265
|
-
};
|
|
266
|
-
opts = options;
|
|
281
|
+
opts = _object_spread_props(_object_spread({}, requestOptionsParameters), {
|
|
282
|
+
headers: new Headers((0, _apihelpers.filterUndefinedValues)(requestOptionsParameters.headers)),
|
|
283
|
+
queryParams: (0, _apihelpers.filterUndefinedValues)(requestOptionsParameters.queryParams)
|
|
284
|
+
});
|
|
267
285
|
if (!_this.options.requestPlugins) return [
|
|
268
286
|
3,
|
|
269
287
|
8
|
|
@@ -288,7 +306,8 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
288
306
|
return [
|
|
289
307
|
4,
|
|
290
308
|
plugin.load({
|
|
291
|
-
logger: _this.options.logger
|
|
309
|
+
logger: _this.options.logger,
|
|
310
|
+
apiName: (_requestOptionsParameters_api = requestOptionsParameters.api) === null || _requestOptionsParameters_api === void 0 ? void 0 : _requestOptionsParameters_api.apiName
|
|
292
311
|
}).transform(opts)
|
|
293
312
|
];
|
|
294
313
|
case 3:
|
|
@@ -336,6 +355,29 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
336
355
|
})();
|
|
337
356
|
}
|
|
338
357
|
},
|
|
358
|
+
{
|
|
359
|
+
key: "prepareOptions",
|
|
360
|
+
value: /** @inheritdoc */ function prepareOptions(url, method, queryParams, headers, body, tokenizedOptions, metadata, api) {
|
|
361
|
+
var _this = this;
|
|
362
|
+
return _async_to_generator(function() {
|
|
363
|
+
return _ts_generator(this, function(_state) {
|
|
364
|
+
return [
|
|
365
|
+
2,
|
|
366
|
+
_this.getRequestOptions({
|
|
367
|
+
headers: headers,
|
|
368
|
+
method: method,
|
|
369
|
+
basePath: url,
|
|
370
|
+
queryParams: queryParams,
|
|
371
|
+
body: body,
|
|
372
|
+
metadata: metadata,
|
|
373
|
+
tokenizedOptions: tokenizedOptions,
|
|
374
|
+
api: api
|
|
375
|
+
})
|
|
376
|
+
];
|
|
377
|
+
});
|
|
378
|
+
})();
|
|
379
|
+
}
|
|
380
|
+
},
|
|
339
381
|
{
|
|
340
382
|
key: "prepareUrl",
|
|
341
383
|
value: /** @inheritdoc */ function prepareUrl(url) {
|
|
@@ -354,11 +396,11 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
354
396
|
value: function processCall(url, options, apiType, apiName, revivers, operationId) {
|
|
355
397
|
var _this = this;
|
|
356
398
|
return _async_to_generator(function() {
|
|
357
|
-
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;
|
|
399
|
+
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;
|
|
358
400
|
return _ts_generator(this, function(_state) {
|
|
359
401
|
switch(_state.label){
|
|
360
402
|
case 0:
|
|
361
|
-
origin = options.headers.get(
|
|
403
|
+
origin = options.headers.get('Origin');
|
|
362
404
|
_state.label = 1;
|
|
363
405
|
case 1:
|
|
364
406
|
_state.trys.push([
|
|
@@ -367,10 +409,13 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
367
409
|
,
|
|
368
410
|
6
|
|
369
411
|
]);
|
|
412
|
+
metadataSignal = (_options_metadata = options.metadata) === null || _options_metadata === void 0 ? void 0 : _options_metadata.signal;
|
|
413
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
370
414
|
controller = new AbortController();
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
415
|
+
options.signal = controller.signal;
|
|
416
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.addEventListener('abort', function() {
|
|
417
|
+
return controller.abort();
|
|
418
|
+
});
|
|
374
419
|
loadedPlugins = [];
|
|
375
420
|
if (_this.options.fetchPlugins) {
|
|
376
421
|
;
|
|
@@ -446,7 +491,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
446
491
|
if (_instanceof(e, _errors.CanceledCallError)) {
|
|
447
492
|
exception = e;
|
|
448
493
|
} else {
|
|
449
|
-
exception = new _errors.EmptyResponseError(e.message ||
|
|
494
|
+
exception = new _errors.EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
|
|
450
495
|
apiName: apiName,
|
|
451
496
|
operationId: operationId,
|
|
452
497
|
url: url,
|
|
@@ -461,7 +506,7 @@ var ApiFetchClient = /*#__PURE__*/ function() {
|
|
|
461
506
|
try {
|
|
462
507
|
root = body ? JSON.parse(body) : undefined;
|
|
463
508
|
} catch (e) {
|
|
464
|
-
exception = new _errors.ResponseJSONParseError(e.message ||
|
|
509
|
+
exception = new _errors.ResponseJSONParseError(e.message || 'Fail to parse response body', response && response.status || 0, body, {
|
|
465
510
|
apiName: apiName,
|
|
466
511
|
operationId: operationId,
|
|
467
512
|
url: url,
|
package/cjs/fwk/Reviver.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
@@ -20,7 +20,7 @@ _export(exports, {
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
function reviveMap(data) {
|
|
23
|
-
var dictionaries = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null, reviver = arguments.length > 2 ? arguments[2] : void 0;
|
|
23
|
+
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;
|
|
24
24
|
if (!data) {
|
|
25
25
|
return undefined;
|
|
26
26
|
}
|
|
@@ -28,27 +28,27 @@ function reviveMap(data) {
|
|
|
28
28
|
for(var key in data){
|
|
29
29
|
// eslint-disable-next-line no-prototype-builtins
|
|
30
30
|
if (data.hasOwnProperty(key)) {
|
|
31
|
-
revived[key] = reviver(data[key], dictionaries);
|
|
31
|
+
revived[key] = reviver(data[key], dictionaries, options);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
return revived;
|
|
35
35
|
}
|
|
36
36
|
function reviveArray(data) {
|
|
37
|
-
var dictionaries = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null, reviver = arguments.length > 2 ? arguments[2] : void 0;
|
|
37
|
+
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;
|
|
38
38
|
if (!data) {
|
|
39
39
|
return undefined;
|
|
40
40
|
}
|
|
41
41
|
for(var i = 0; i < data.length; i++){
|
|
42
|
-
data[i] = reviver(data[i], dictionaries);
|
|
42
|
+
data[i] = reviver(data[i], dictionaries, options);
|
|
43
43
|
}
|
|
44
44
|
return data;
|
|
45
45
|
}
|
|
46
|
-
function reviveDictionarizedArray(ids, dictionary, reviver) {
|
|
46
|
+
function reviveDictionarizedArray(ids, dictionary, reviver, options) {
|
|
47
47
|
if (!ids) {
|
|
48
48
|
return undefined;
|
|
49
49
|
}
|
|
50
50
|
return ids.reduce(function(map, id) {
|
|
51
|
-
map[id] = reviver ? reviver(dictionary[id], dictionary) : dictionary[id];
|
|
51
|
+
map[id] = reviver ? reviver(dictionary[id], dictionary, options) : dictionary[id];
|
|
52
52
|
return map;
|
|
53
53
|
}, {});
|
|
54
54
|
}
|
|
@@ -3,45 +3,45 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
var _core = require("@ama-sdk/core");
|
|
6
|
-
describe(
|
|
6
|
+
describe('getResponseReviver - revivers by status code', function() {
|
|
7
7
|
var revivers = {
|
|
8
8
|
202: jest.fn(),
|
|
9
9
|
201: jest.fn()
|
|
10
10
|
};
|
|
11
11
|
beforeEach(function() {
|
|
12
|
-
jest.spyOn(console,
|
|
12
|
+
jest.spyOn(console, 'error');
|
|
13
13
|
});
|
|
14
14
|
afterEach(function() {
|
|
15
15
|
jest.clearAllMocks();
|
|
16
16
|
});
|
|
17
|
-
it(
|
|
17
|
+
it('should not return a reviver for a non ok response', function() {
|
|
18
18
|
expect((0, _core.getResponseReviver)(revivers, {
|
|
19
19
|
status: 300,
|
|
20
20
|
ok: false
|
|
21
21
|
})).toBe(undefined);
|
|
22
22
|
});
|
|
23
|
-
it(
|
|
23
|
+
it('should return a reason but not reviver for a 204 No Content Response', function() {
|
|
24
24
|
expect((0, _core.getResponseReviver)(revivers, {
|
|
25
25
|
status: 204,
|
|
26
26
|
ok: true
|
|
27
27
|
})).toBe(undefined);
|
|
28
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
28
|
+
expect(console.error).toHaveBeenCalledWith('API status code error for unknown endpoint - 204 response is not defined in the API specification');
|
|
29
29
|
});
|
|
30
|
-
it(
|
|
30
|
+
it('should return the status code\'s reviver', function() {
|
|
31
31
|
expect((0, _core.getResponseReviver)(revivers, {
|
|
32
32
|
status: 202,
|
|
33
33
|
ok: true
|
|
34
|
-
},
|
|
34
|
+
}, 'myEndpoint')).toBe(revivers[202]);
|
|
35
35
|
expect(console.error).not.toHaveBeenCalled();
|
|
36
36
|
});
|
|
37
|
-
it(
|
|
37
|
+
it('should fallback on the first defined status if the status code\'s reviver is not defined', function() {
|
|
38
38
|
expect((0, _core.getResponseReviver)(revivers, {
|
|
39
39
|
status: undefined,
|
|
40
40
|
ok: true
|
|
41
|
-
},
|
|
42
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
41
|
+
}, 'myEndpoint')).toBe(revivers[201]);
|
|
42
|
+
expect(console.error).toHaveBeenCalledWith('API status code error for myEndpoint endpoint - Unknown undefined code returned by the API - Fallback to 201\'s reviver');
|
|
43
43
|
});
|
|
44
|
-
it(
|
|
44
|
+
it('should not fallback on 204 (No Content)\'s reviver', function() {
|
|
45
45
|
var reviversWith204 = {
|
|
46
46
|
204: jest.fn(),
|
|
47
47
|
206: jest.fn()
|
|
@@ -49,33 +49,33 @@ describe("getResponseReviver - revivers by status code", function() {
|
|
|
49
49
|
var fallback = (0, _core.getResponseReviver)(reviversWith204, {
|
|
50
50
|
status: 201,
|
|
51
51
|
ok: true
|
|
52
|
-
},
|
|
52
|
+
}, 'myEndpoint');
|
|
53
53
|
expect(fallback).toBe(reviversWith204[206]);
|
|
54
54
|
expect(fallback).not.toBe(reviversWith204[204]);
|
|
55
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
55
|
+
expect(console.error).toHaveBeenCalledWith('API status code error for myEndpoint endpoint - Unknown 201 code returned by the API - Fallback to 206\'s reviver');
|
|
56
56
|
});
|
|
57
|
-
it(
|
|
58
|
-
jest.spyOn(console,
|
|
57
|
+
it('should not fallback if the feature is deactivated', function() {
|
|
58
|
+
jest.spyOn(console, 'log');
|
|
59
59
|
expect((0, _core.getResponseReviver)(revivers, {
|
|
60
60
|
status: 206,
|
|
61
61
|
ok: true
|
|
62
|
-
},
|
|
62
|
+
}, 'myEndpoint', {
|
|
63
63
|
disableFallback: true,
|
|
64
64
|
log: console.log
|
|
65
65
|
})).toBe(undefined);
|
|
66
66
|
expect(console.error).not.toHaveBeenCalled();
|
|
67
|
-
expect(console.log).toHaveBeenCalledWith(
|
|
67
|
+
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');
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
|
-
describe(
|
|
70
|
+
describe('getResponseReviver - reviver as function', function() {
|
|
71
71
|
var reviver = jest.fn();
|
|
72
|
-
it(
|
|
72
|
+
it('should not return a reviver for a non ok response', function() {
|
|
73
73
|
expect((0, _core.getResponseReviver)(reviver, {
|
|
74
74
|
status: 300,
|
|
75
75
|
ok: false
|
|
76
76
|
})).toBe(undefined);
|
|
77
77
|
});
|
|
78
|
-
it(
|
|
78
|
+
it('should only return the reviver if the endpoint reviver is a function or an undefined object', function() {
|
|
79
79
|
expect((0, _core.getResponseReviver)(reviver, {
|
|
80
80
|
status: 200,
|
|
81
81
|
ok: true
|