@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
|
@@ -154,9 +154,8 @@ function _ts_generator(thisArg, body) {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
import { v4 } from
|
|
158
|
-
import {
|
|
159
|
-
import { createBase64Encoder, createBase64UrlEncoder } from "../../utils/json-token";
|
|
157
|
+
import { v4 } from 'uuid';
|
|
158
|
+
import { base64EncodeUrl, createBase64Encoder, createBase64UrlEncoder } from '../../utils/json-token';
|
|
160
159
|
/**
|
|
161
160
|
* Computes the SHA256 digest of the given string
|
|
162
161
|
* @param value Value to hash
|
|
@@ -165,36 +164,24 @@ import { createBase64Encoder, createBase64UrlEncoder } from "../../utils/json-to
|
|
|
165
164
|
}
|
|
166
165
|
function _sha256() {
|
|
167
166
|
_sha256 = _async_to_generator(function(value) {
|
|
167
|
+
var utf8, hashBuffer, hashArray, hashHex;
|
|
168
168
|
return _ts_generator(this, function(_state) {
|
|
169
169
|
switch(_state.label){
|
|
170
170
|
case 0:
|
|
171
|
-
|
|
172
|
-
3,
|
|
173
|
-
2
|
|
174
|
-
];
|
|
171
|
+
utf8 = new TextEncoder().encode(value);
|
|
175
172
|
return [
|
|
176
173
|
4,
|
|
177
|
-
crypto.subtle.digest(
|
|
174
|
+
(globalThis.crypto || require('node:crypto').webcrypto).subtle.digest('SHA-256', utf8)
|
|
178
175
|
];
|
|
179
176
|
case 1:
|
|
177
|
+
hashBuffer = _state.sent();
|
|
178
|
+
hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
179
|
+
hashHex = hashArray.map(function(bytes) {
|
|
180
|
+
return bytes.toString(16).padStart(2, '0');
|
|
181
|
+
}).join('');
|
|
180
182
|
return [
|
|
181
183
|
2,
|
|
182
|
-
|
|
183
|
-
_state.sent()
|
|
184
|
-
])
|
|
185
|
-
];
|
|
186
|
-
case 2:
|
|
187
|
-
// NodeJS
|
|
188
|
-
try {
|
|
189
|
-
return [
|
|
190
|
-
2,
|
|
191
|
-
ab2str(require("node:crypto").createHash("sha256").update(value).digest("latin1"))
|
|
192
|
-
];
|
|
193
|
-
} catch (err) {
|
|
194
|
-
throw new Error("Crypto module is not available.");
|
|
195
|
-
}
|
|
196
|
-
return [
|
|
197
|
-
2
|
|
184
|
+
hashHex
|
|
198
185
|
];
|
|
199
186
|
}
|
|
200
187
|
});
|
|
@@ -209,16 +196,17 @@ function _sha256() {
|
|
|
209
196
|
* @param secretKey Secret cryptographic key
|
|
210
197
|
*/ export function hmacSHA256(value, secretKey) {
|
|
211
198
|
try {
|
|
212
|
-
|
|
199
|
+
var createHmac = require('node:crypto').createHmac;
|
|
200
|
+
return createHmac('sha256', secretKey).update(value, 'latin1').digest('base64');
|
|
213
201
|
} catch (err) {
|
|
214
|
-
throw new Error(
|
|
202
|
+
throw new Error('Crypto module is not available.');
|
|
215
203
|
}
|
|
216
204
|
}
|
|
217
205
|
/**
|
|
218
206
|
* Header definition of the JWS used for the API Manager authentication
|
|
219
207
|
*/ var jwsHeader = {
|
|
220
|
-
alg:
|
|
221
|
-
typ:
|
|
208
|
+
alg: 'HS256',
|
|
209
|
+
typ: 'JWT'
|
|
222
210
|
};
|
|
223
211
|
/**
|
|
224
212
|
* Plugin to send a JWS to authenticate on the API Manager.
|
|
@@ -256,8 +244,8 @@ function _sha256() {
|
|
|
256
244
|
/**
|
|
257
245
|
* Method used to encode a string in base64
|
|
258
246
|
*/ _define_property(this, "base64Encoder", void 0);
|
|
259
|
-
if (typeof window !==
|
|
260
|
-
throw new Error(
|
|
247
|
+
if (typeof window !== 'undefined') {
|
|
248
|
+
throw new Error('The plugin can only be used in a NodeJS context');
|
|
261
249
|
}
|
|
262
250
|
this.applicationId = options.applicationId;
|
|
263
251
|
this.expIntervalInSec = options.expIntervalInSec;
|
|
@@ -273,14 +261,16 @@ function _sha256() {
|
|
|
273
261
|
value: /**
|
|
274
262
|
* Generates payload with minimal information
|
|
275
263
|
*/ function generatePayload() {
|
|
276
|
-
var
|
|
277
|
-
var
|
|
264
|
+
var nonce = this.base64Encoder(v4().toString());
|
|
265
|
+
var nowInSeconds = Math.floor(Date.now() / 1000);
|
|
266
|
+
var expTime = nowInSeconds + this.expIntervalInSec;
|
|
267
|
+
var context = this.base64Encoder(JSON.stringify(this.context));
|
|
278
268
|
return {
|
|
279
269
|
iss: this.applicationId,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
context:
|
|
270
|
+
exp: "".concat(expTime),
|
|
271
|
+
jti: nonce,
|
|
272
|
+
iat: "".concat(nowInSeconds),
|
|
273
|
+
context: context
|
|
284
274
|
};
|
|
285
275
|
}
|
|
286
276
|
},
|
|
@@ -293,20 +283,21 @@ function _sha256() {
|
|
|
293
283
|
*/ function generateMicroGatewayAuthenticationSignatureKey(payload, basePath) {
|
|
294
284
|
var _this = this;
|
|
295
285
|
return _async_to_generator(function() {
|
|
296
|
-
var
|
|
286
|
+
var subKeyString, keyString, _;
|
|
297
287
|
return _ts_generator(this, function(_state) {
|
|
298
288
|
switch(_state.label){
|
|
299
289
|
case 0:
|
|
290
|
+
subKeyString = _this.secret + payload.jti + payload.iat + basePath;
|
|
300
291
|
_ = _this.apiKey;
|
|
301
292
|
return [
|
|
302
293
|
4,
|
|
303
|
-
sha256(
|
|
294
|
+
sha256(subKeyString)
|
|
304
295
|
];
|
|
305
296
|
case 1:
|
|
306
|
-
|
|
297
|
+
keyString = _ + _state.sent();
|
|
307
298
|
return [
|
|
308
299
|
2,
|
|
309
|
-
sha256(
|
|
300
|
+
sha256(keyString)
|
|
310
301
|
];
|
|
311
302
|
}
|
|
312
303
|
});
|
|
@@ -322,7 +313,8 @@ function _sha256() {
|
|
|
322
313
|
*/ function sign(payload, secretKey) {
|
|
323
314
|
var message = "".concat(this.base64UrlEncoder(JSON.stringify(jwsHeader)), ".").concat(this.base64UrlEncoder(JSON.stringify(payload)));
|
|
324
315
|
var signature = hmacSHA256(message, secretKey);
|
|
325
|
-
|
|
316
|
+
var encodedSignature = base64EncodeUrl(signature);
|
|
317
|
+
return "".concat(message, ".").concat(encodedSignature);
|
|
326
318
|
}
|
|
327
319
|
},
|
|
328
320
|
{
|
|
@@ -372,7 +364,7 @@ function _sha256() {
|
|
|
372
364
|
];
|
|
373
365
|
case 1:
|
|
374
366
|
token = _state.sent();
|
|
375
|
-
data.headers.append("Bearer "
|
|
367
|
+
data.headers.append('Authorization', "Bearer ".concat(token));
|
|
376
368
|
return [
|
|
377
369
|
2,
|
|
378
370
|
data
|
|
@@ -140,9 +140,12 @@ function _ts_generator(thisArg, body) {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
import { createBase64Decoder, createBase64UrlDecoder, createBase64UrlEncoder } from
|
|
144
|
-
import { hmacSHA256, MicroGatewayMiddlewareAuthenticationRequest, sha256 } from
|
|
145
|
-
var authHeaderKey =
|
|
143
|
+
import { base64EncodeUrl, createBase64Decoder, createBase64UrlDecoder, createBase64UrlEncoder } from '../../utils/json-token';
|
|
144
|
+
import { hmacSHA256, MicroGatewayMiddlewareAuthenticationRequest, sha256 } from './mgw-mdw-auth.request';
|
|
145
|
+
var authHeaderKey = 'Authorization';
|
|
146
|
+
var authHeaderPrefix = 'Bearer ';
|
|
147
|
+
var baseUrl = 'https://domain.com';
|
|
148
|
+
var routePath = '/v2/shopping/air-offers';
|
|
146
149
|
var options;
|
|
147
150
|
var FakeHeader = function FakeHeader() {
|
|
148
151
|
"use strict";
|
|
@@ -160,27 +163,27 @@ var FakeHeader = function FakeHeader() {
|
|
|
160
163
|
});
|
|
161
164
|
};
|
|
162
165
|
var jsonAuthTokenOptions = {
|
|
163
|
-
applicationId:
|
|
164
|
-
apiKey:
|
|
166
|
+
applicationId: '6X_MG__tester@test.com__PDT',
|
|
167
|
+
apiKey: 'dummy4P1K3Y',
|
|
165
168
|
expIntervalInSec: 60,
|
|
166
|
-
secret:
|
|
169
|
+
secret: 'super-secret',
|
|
167
170
|
context: {
|
|
168
|
-
oid:
|
|
171
|
+
oid: 'NCE1A0955'
|
|
169
172
|
}
|
|
170
173
|
};
|
|
171
|
-
describe(
|
|
174
|
+
describe('JSON auth token request plugin', function() {
|
|
172
175
|
beforeEach(function() {
|
|
173
176
|
options = {
|
|
174
|
-
basePath: "
|
|
177
|
+
basePath: "".concat(baseUrl).concat(routePath),
|
|
175
178
|
headers: new FakeHeader(),
|
|
176
|
-
method:
|
|
179
|
+
method: 'GET'
|
|
177
180
|
};
|
|
178
181
|
});
|
|
179
182
|
afterAll(function() {
|
|
180
183
|
global.sessionStorage = undefined;
|
|
181
184
|
});
|
|
182
|
-
it(
|
|
183
|
-
var plugin, result;
|
|
185
|
+
it('should add a Bearer in the header', /*#__PURE__*/ _async_to_generator(function() {
|
|
186
|
+
var _result_headers_get, plugin, result;
|
|
184
187
|
return _ts_generator(this, function(_state) {
|
|
185
188
|
switch(_state.label){
|
|
186
189
|
case 0:
|
|
@@ -192,13 +195,14 @@ describe("JSON auth token request plugin", function() {
|
|
|
192
195
|
case 1:
|
|
193
196
|
result = _state.sent();
|
|
194
197
|
expect(result.headers.has(authHeaderKey)).toBeTruthy();
|
|
198
|
+
expect((_result_headers_get = result.headers.get(authHeaderKey)) === null || _result_headers_get === void 0 ? void 0 : _result_headers_get.startsWith(authHeaderPrefix)).toBeTruthy();
|
|
195
199
|
return [
|
|
196
200
|
2
|
|
197
201
|
];
|
|
198
202
|
}
|
|
199
203
|
});
|
|
200
204
|
}));
|
|
201
|
-
it(
|
|
205
|
+
it('should check that the jws token is well formatted', /*#__PURE__*/ _async_to_generator(function() {
|
|
202
206
|
var plugin, result, token, tokenParts;
|
|
203
207
|
return _ts_generator(this, function(_state) {
|
|
204
208
|
switch(_state.label){
|
|
@@ -210,8 +214,8 @@ describe("JSON auth token request plugin", function() {
|
|
|
210
214
|
];
|
|
211
215
|
case 1:
|
|
212
216
|
result = _state.sent();
|
|
213
|
-
token = result.headers.get(authHeaderKey);
|
|
214
|
-
tokenParts = token.split(
|
|
217
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
218
|
+
tokenParts = token.split('.');
|
|
215
219
|
expect(token).toBeDefined();
|
|
216
220
|
expect(tokenParts.length).toEqual(3);
|
|
217
221
|
return [
|
|
@@ -220,7 +224,7 @@ describe("JSON auth token request plugin", function() {
|
|
|
220
224
|
}
|
|
221
225
|
});
|
|
222
226
|
}));
|
|
223
|
-
it(
|
|
227
|
+
it('should check that the header is properly set', /*#__PURE__*/ _async_to_generator(function() {
|
|
224
228
|
var base64URLDecoder, plugin, result, token, tokenParts, header;
|
|
225
229
|
return _ts_generator(this, function(_state) {
|
|
226
230
|
switch(_state.label){
|
|
@@ -233,21 +237,21 @@ describe("JSON auth token request plugin", function() {
|
|
|
233
237
|
];
|
|
234
238
|
case 1:
|
|
235
239
|
result = _state.sent();
|
|
236
|
-
token = result.headers.get(authHeaderKey);
|
|
240
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
237
241
|
expect(token).toBeDefined();
|
|
238
|
-
tokenParts = token.split(
|
|
242
|
+
tokenParts = token.split('.');
|
|
239
243
|
header = JSON.parse(base64URLDecoder(tokenParts[0]));
|
|
240
244
|
expect(header.alg).toBeDefined();
|
|
241
|
-
expect(header.alg).toEqual(
|
|
245
|
+
expect(header.alg).toEqual('HS256');
|
|
242
246
|
expect(header.typ).toBeDefined();
|
|
243
|
-
expect(header.typ).toEqual(
|
|
247
|
+
expect(header.typ).toEqual('JWT');
|
|
244
248
|
return [
|
|
245
249
|
2
|
|
246
250
|
];
|
|
247
251
|
}
|
|
248
252
|
});
|
|
249
253
|
}));
|
|
250
|
-
it(
|
|
254
|
+
it('should check that the payload is properly set', /*#__PURE__*/ _async_to_generator(function() {
|
|
251
255
|
var base64URLDecoder, base64Decoder, plugin, result, token, tokenParts, payload, context;
|
|
252
256
|
return _ts_generator(this, function(_state) {
|
|
253
257
|
switch(_state.label){
|
|
@@ -261,9 +265,9 @@ describe("JSON auth token request plugin", function() {
|
|
|
261
265
|
];
|
|
262
266
|
case 1:
|
|
263
267
|
result = _state.sent();
|
|
264
|
-
token = result.headers.get(authHeaderKey);
|
|
268
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
265
269
|
expect(token).toBeDefined();
|
|
266
|
-
tokenParts = token.split(
|
|
270
|
+
tokenParts = token.split('.');
|
|
267
271
|
payload = JSON.parse(base64URLDecoder(tokenParts[1]));
|
|
268
272
|
expect(payload.jti).toBeDefined();
|
|
269
273
|
expect(payload.iat).toBeDefined();
|
|
@@ -280,7 +284,7 @@ describe("JSON auth token request plugin", function() {
|
|
|
280
284
|
}
|
|
281
285
|
});
|
|
282
286
|
}));
|
|
283
|
-
it(
|
|
287
|
+
it('should check the signature validity', /*#__PURE__*/ _async_to_generator(function() {
|
|
284
288
|
var base64URLDecoder, base64UrlEncoder, plugin, result, token, tokenParts, header, payload, signature, secretKey, _, message, signCheck;
|
|
285
289
|
return _ts_generator(this, function(_state) {
|
|
286
290
|
switch(_state.label){
|
|
@@ -294,15 +298,15 @@ describe("JSON auth token request plugin", function() {
|
|
|
294
298
|
];
|
|
295
299
|
case 1:
|
|
296
300
|
result = _state.sent();
|
|
297
|
-
token = result.headers.get(authHeaderKey);
|
|
298
|
-
tokenParts = token.split(
|
|
301
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
302
|
+
tokenParts = token.split('.');
|
|
299
303
|
header = JSON.parse(base64URLDecoder(tokenParts[0]));
|
|
300
304
|
payload = JSON.parse(base64URLDecoder(tokenParts[1]));
|
|
301
305
|
signature = tokenParts[2];
|
|
302
306
|
_ = jsonAuthTokenOptions.apiKey;
|
|
303
307
|
return [
|
|
304
308
|
4,
|
|
305
|
-
sha256(jsonAuthTokenOptions.secret + payload.jti + payload.iat
|
|
309
|
+
sha256(jsonAuthTokenOptions.secret + payload.jti + payload.iat + routePath)
|
|
306
310
|
];
|
|
307
311
|
case 2:
|
|
308
312
|
return [
|
|
@@ -315,7 +319,7 @@ describe("JSON auth token request plugin", function() {
|
|
|
315
319
|
secretKey = _state.sent();
|
|
316
320
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
317
321
|
message = "".concat(base64UrlEncoder(JSON.stringify(header)), ".").concat(base64UrlEncoder(JSON.stringify(payload)));
|
|
318
|
-
signCheck =
|
|
322
|
+
signCheck = base64EncodeUrl(hmacSHA256(message, secretKey));
|
|
319
323
|
expect(signature).toEqual(signCheck);
|
|
320
324
|
return [
|
|
321
325
|
2
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './mock-intercept.request';
|
|
2
|
+
export * from './mock-intercept.fetch';
|
|
@@ -161,8 +161,8 @@ function _ts_generator(thisArg, body) {
|
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
import { CUSTOM_MOCK_OPERATION_ID_HEADER } from
|
|
165
|
-
import { MockInterceptRequest } from
|
|
164
|
+
import { CUSTOM_MOCK_OPERATION_ID_HEADER } from './mock-intercept.interface';
|
|
165
|
+
import { MockInterceptRequest } from './mock-intercept.request';
|
|
166
166
|
/**
|
|
167
167
|
* Plugin to mock and intercept the fetch of SDK
|
|
168
168
|
*
|
|
@@ -182,7 +182,7 @@ import { MockInterceptRequest } from "./mock-intercept.request";
|
|
|
182
182
|
if (!context.apiClient.options.requestPlugins.some(function(plugin) {
|
|
183
183
|
return _instanceof(plugin, MockInterceptRequest);
|
|
184
184
|
})) {
|
|
185
|
-
throw new Error(
|
|
185
|
+
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
186
186
|
}
|
|
187
187
|
var _this = this;
|
|
188
188
|
return {
|
|
@@ -206,11 +206,11 @@ import { MockInterceptRequest } from "./mock-intercept.request";
|
|
|
206
206
|
responsePromise
|
|
207
207
|
];
|
|
208
208
|
}
|
|
209
|
-
if (!(typeof _this.options.delayTiming !==
|
|
209
|
+
if (!(typeof _this.options.delayTiming !== 'undefined')) return [
|
|
210
210
|
3,
|
|
211
211
|
6
|
|
212
212
|
];
|
|
213
|
-
if (!(typeof _this.options.delayTiming ===
|
|
213
|
+
if (!(typeof _this.options.delayTiming === 'number')) return [
|
|
214
214
|
3,
|
|
215
215
|
2
|
|
216
216
|
];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** Custom Mock Header for Operation ID */ export var CUSTOM_MOCK_OPERATION_ID_HEADER =
|
|
2
|
-
/** Custom Mock Header for Original Request */ export var CUSTOM_MOCK_REQUEST_HEADER =
|
|
1
|
+
/** Custom Mock Header for Operation ID */ export var CUSTOM_MOCK_OPERATION_ID_HEADER = 'X-mock-operation-id';
|
|
2
|
+
/** Custom Mock Header for Original Request */ export var CUSTOM_MOCK_REQUEST_HEADER = 'X-mock-request';
|
|
@@ -193,7 +193,7 @@ function _ts_generator(thisArg, body) {
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
import { CUSTOM_MOCK_OPERATION_ID_HEADER, CUSTOM_MOCK_REQUEST_HEADER } from
|
|
196
|
+
import { CUSTOM_MOCK_OPERATION_ID_HEADER, CUSTOM_MOCK_REQUEST_HEADER } from './mock-intercept.interface';
|
|
197
197
|
/**
|
|
198
198
|
* Plugin to intercept an API request for mock purposes
|
|
199
199
|
*/ export var MockInterceptRequest = /*#__PURE__*/ function() {
|
|
@@ -233,7 +233,7 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, CUSTOM_MOCK_REQUEST_HEADER } from "./m
|
|
|
233
233
|
];
|
|
234
234
|
}
|
|
235
235
|
requestOption = _object_spread_props(_object_spread({}, data), {
|
|
236
|
-
method: data.method ||
|
|
236
|
+
method: data.method || 'GET'
|
|
237
237
|
});
|
|
238
238
|
return [
|
|
239
239
|
4,
|
|
@@ -246,7 +246,7 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, CUSTOM_MOCK_REQUEST_HEADER } from "./m
|
|
|
246
246
|
blob = new Blob([
|
|
247
247
|
text
|
|
248
248
|
], {
|
|
249
|
-
type:
|
|
249
|
+
type: 'application/json'
|
|
250
250
|
});
|
|
251
251
|
basePath = URL.createObjectURL(blob);
|
|
252
252
|
headers = data.headers || new Headers();
|
|
@@ -255,7 +255,7 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, CUSTOM_MOCK_REQUEST_HEADER } from "./m
|
|
|
255
255
|
return [
|
|
256
256
|
2,
|
|
257
257
|
{
|
|
258
|
-
method:
|
|
258
|
+
method: 'GET',
|
|
259
259
|
basePath: basePath,
|
|
260
260
|
headers: headers
|
|
261
261
|
}
|
|
@@ -135,16 +135,16 @@ function _ts_generator(thisArg, body) {
|
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
import { SequentialMockAdapter } from
|
|
139
|
-
import { MockInterceptFetch } from
|
|
140
|
-
import { CUSTOM_MOCK_OPERATION_ID_HEADER } from
|
|
141
|
-
import { MockInterceptRequest } from
|
|
138
|
+
import { SequentialMockAdapter } from '../../fwk';
|
|
139
|
+
import { MockInterceptFetch } from './mock-intercept.fetch';
|
|
140
|
+
import { CUSTOM_MOCK_OPERATION_ID_HEADER } from './mock-intercept.interface';
|
|
141
|
+
import { MockInterceptRequest } from './mock-intercept.request';
|
|
142
142
|
var testMock = {
|
|
143
143
|
mockData: {}
|
|
144
144
|
};
|
|
145
145
|
var getMockSpy = jest.fn().mockReturnValue(testMock);
|
|
146
146
|
var getLatestMockSpy = jest.fn().mockReturnValue(testMock);
|
|
147
|
-
var retrieveOperationIdSpy = jest.fn().mockReturnValue(Promise.resolve(
|
|
147
|
+
var retrieveOperationIdSpy = jest.fn().mockReturnValue(Promise.resolve('testOperation'));
|
|
148
148
|
var initializeSpy = jest.fn().mockReturnValue(Promise.resolve());
|
|
149
149
|
var testMockAdapter = {
|
|
150
150
|
getMock: getMockSpy,
|
|
@@ -160,13 +160,13 @@ var requestPlugins = [
|
|
|
160
160
|
var apiClient = {
|
|
161
161
|
options: {
|
|
162
162
|
requestPlugins: requestPlugins,
|
|
163
|
-
basePath:
|
|
163
|
+
basePath: 'test',
|
|
164
164
|
replyPlugins: []
|
|
165
165
|
}
|
|
166
166
|
};
|
|
167
|
-
describe(
|
|
168
|
-
describe(
|
|
169
|
-
it(
|
|
167
|
+
describe('Mock intercept', function() {
|
|
168
|
+
describe('request plugin', function() {
|
|
169
|
+
it('should do nothing if disabled is true', /*#__PURE__*/ _async_to_generator(function() {
|
|
170
170
|
var plugin, originalRequest, loaded;
|
|
171
171
|
return _ts_generator(this, function(_state) {
|
|
172
172
|
switch(_state.label){
|
|
@@ -176,11 +176,11 @@ describe("Mock intercept", function() {
|
|
|
176
176
|
adapter: testMockAdapter
|
|
177
177
|
});
|
|
178
178
|
originalRequest = {
|
|
179
|
-
method:
|
|
179
|
+
method: 'get',
|
|
180
180
|
headers: new Headers({
|
|
181
|
-
test:
|
|
181
|
+
test: 'true'
|
|
182
182
|
}),
|
|
183
|
-
basePath:
|
|
183
|
+
basePath: 'myurl'
|
|
184
184
|
};
|
|
185
185
|
loaded = plugin.load();
|
|
186
186
|
return [
|
|
@@ -198,7 +198,7 @@ describe("Mock intercept", function() {
|
|
|
198
198
|
}
|
|
199
199
|
});
|
|
200
200
|
}));
|
|
201
|
-
it.skip(
|
|
201
|
+
it.skip('should intercept the request', /*#__PURE__*/ _async_to_generator(function() {
|
|
202
202
|
var plugin, originalRequest, loaded, transformed, res;
|
|
203
203
|
return _ts_generator(this, function(_state) {
|
|
204
204
|
switch(_state.label){
|
|
@@ -209,10 +209,10 @@ describe("Mock intercept", function() {
|
|
|
209
209
|
});
|
|
210
210
|
originalRequest = {
|
|
211
211
|
headers: new Headers({
|
|
212
|
-
test:
|
|
212
|
+
test: 'true'
|
|
213
213
|
}),
|
|
214
|
-
basePath:
|
|
215
|
-
method:
|
|
214
|
+
basePath: 'myurl',
|
|
215
|
+
method: 'PATCH'
|
|
216
216
|
};
|
|
217
217
|
loaded = plugin.load();
|
|
218
218
|
transformed = loaded.transform(originalRequest);
|
|
@@ -232,8 +232,8 @@ describe("Mock intercept", function() {
|
|
|
232
232
|
});
|
|
233
233
|
}));
|
|
234
234
|
});
|
|
235
|
-
describe(
|
|
236
|
-
describe(
|
|
235
|
+
describe('fetch plugin', function() {
|
|
236
|
+
describe('when using an initialization function', function() {
|
|
237
237
|
var plugin;
|
|
238
238
|
var asyncMockAdapter;
|
|
239
239
|
beforeEach(function() {
|
|
@@ -247,17 +247,17 @@ describe("Mock intercept", function() {
|
|
|
247
247
|
adapter: asyncMockAdapter
|
|
248
248
|
});
|
|
249
249
|
});
|
|
250
|
-
it(
|
|
250
|
+
it('should call initialize fn', /*#__PURE__*/ _async_to_generator(function() {
|
|
251
251
|
var loadedPlugin, testData;
|
|
252
252
|
return _ts_generator(this, function(_state) {
|
|
253
253
|
switch(_state.label){
|
|
254
254
|
case 0:
|
|
255
255
|
loadedPlugin = plugin.load({
|
|
256
256
|
fetchPlugins: [],
|
|
257
|
-
url:
|
|
257
|
+
url: 'myurl',
|
|
258
258
|
apiClient: apiClient,
|
|
259
259
|
options: {
|
|
260
|
-
headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER,
|
|
260
|
+
headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
263
|
testData = {
|
|
@@ -271,24 +271,24 @@ describe("Mock intercept", function() {
|
|
|
271
271
|
_state.sent();
|
|
272
272
|
expect(initializeSpy).toHaveBeenCalled();
|
|
273
273
|
expect(getMockSpy).not.toHaveBeenCalled();
|
|
274
|
-
expect(getLatestMockSpy).toHaveBeenCalledWith(
|
|
274
|
+
expect(getLatestMockSpy).toHaveBeenCalledWith('testOperation');
|
|
275
275
|
return [
|
|
276
276
|
2
|
|
277
277
|
];
|
|
278
278
|
}
|
|
279
279
|
});
|
|
280
280
|
}));
|
|
281
|
-
it(
|
|
281
|
+
it('should throw if there is no request plugin', function() {
|
|
282
282
|
var config = {
|
|
283
283
|
fetchPlugins: [],
|
|
284
|
-
url:
|
|
284
|
+
url: 'myurl',
|
|
285
285
|
apiClient: {
|
|
286
286
|
options: {
|
|
287
287
|
requestPlugins: []
|
|
288
288
|
}
|
|
289
289
|
},
|
|
290
290
|
options: {
|
|
291
|
-
headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER,
|
|
291
|
+
headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
292
292
|
}
|
|
293
293
|
};
|
|
294
294
|
expect(function() {
|
|
@@ -297,8 +297,8 @@ describe("Mock intercept", function() {
|
|
|
297
297
|
});
|
|
298
298
|
});
|
|
299
299
|
});
|
|
300
|
-
describe(
|
|
301
|
-
it(
|
|
300
|
+
describe('with delay', function() {
|
|
301
|
+
it('should delay the response of the specific number', /*#__PURE__*/ _async_to_generator(function() {
|
|
302
302
|
var plugin, loadedPlugin, callback, run;
|
|
303
303
|
return _ts_generator(this, function(_state) {
|
|
304
304
|
switch(_state.label){
|
|
@@ -309,10 +309,10 @@ describe("Mock intercept", function() {
|
|
|
309
309
|
});
|
|
310
310
|
loadedPlugin = plugin.load({
|
|
311
311
|
fetchPlugins: [],
|
|
312
|
-
url:
|
|
312
|
+
url: '',
|
|
313
313
|
apiClient: apiClient,
|
|
314
314
|
options: {
|
|
315
|
-
headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER,
|
|
315
|
+
headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
316
316
|
}
|
|
317
317
|
});
|
|
318
318
|
callback = jest.fn();
|
|
@@ -343,7 +343,7 @@ describe("Mock intercept", function() {
|
|
|
343
343
|
}
|
|
344
344
|
});
|
|
345
345
|
}));
|
|
346
|
-
it(
|
|
346
|
+
it('should delay the response based on callback', /*#__PURE__*/ _async_to_generator(function() {
|
|
347
347
|
var plugin, loadedPlugin, callback, run;
|
|
348
348
|
return _ts_generator(this, function(_state) {
|
|
349
349
|
switch(_state.label){
|
|
@@ -356,10 +356,10 @@ describe("Mock intercept", function() {
|
|
|
356
356
|
});
|
|
357
357
|
loadedPlugin = plugin.load({
|
|
358
358
|
fetchPlugins: [],
|
|
359
|
-
url:
|
|
359
|
+
url: '',
|
|
360
360
|
apiClient: apiClient,
|
|
361
361
|
options: {
|
|
362
|
-
headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER,
|
|
362
|
+
headers: new Headers(_define_property({}, CUSTOM_MOCK_OPERATION_ID_HEADER, 'testOperation'))
|
|
363
363
|
}
|
|
364
364
|
});
|
|
365
365
|
callback = jest.fn();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './perf-metric.fetch';
|
|
@@ -193,7 +193,7 @@ function _ts_generator(thisArg, body) {
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
import { v4 } from
|
|
196
|
+
import { v4 } from 'uuid';
|
|
197
197
|
/**
|
|
198
198
|
* Performance metric plugin.
|
|
199
199
|
*/ export var PerformanceMetricPlugin = /*#__PURE__*/ function() {
|
|
@@ -215,7 +215,7 @@ import { v4 } from "uuid";
|
|
|
215
215
|
*/ _define_property(this, "getTime", Date.now);
|
|
216
216
|
this.onMarkComplete = options ? options.onMarkComplete : this.onMarkComplete;
|
|
217
217
|
this.onMarkError = options ? options.onMarkError : this.onMarkError;
|
|
218
|
-
if (typeof window !==
|
|
218
|
+
if (typeof window !== 'undefined' && !!window.performance && !!window.performance.now) {
|
|
219
219
|
this.getTime = function() {
|
|
220
220
|
return window.performance.now();
|
|
221
221
|
};
|