@ama-sdk/core 10.3.0-prerelease.9 → 10.3.0-rc.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/cjs/clients/api-angular-client.js +36 -18
- package/cjs/clients/api-beacon-client.js +61 -19
- package/cjs/clients/api-fetch-client.js +60 -18
- 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 +19 -19
- 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 +5 -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.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 +11 -11
- package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +25 -25
- 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.spec.js +4 -4
- package/cjs/plugins/session-id/session-id.request.js +6 -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 +11 -11
- 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/clear-index.cjs.map +1 -0
- package/cli/files-pack.cjs.map +1 -0
- package/esm2015/clients/api-angular-client.js +40 -22
- package/esm2015/clients/api-beacon-client.js +62 -20
- package/esm2015/clients/api-fetch-client.js +64 -22
- package/esm2015/clients/index.js +2 -2
- 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 +20 -20
- 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 +5 -5
- 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.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 +13 -13
- package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +27 -27
- 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.spec.js +6 -6
- package/esm2015/plugins/session-id/index.js +1 -1
- package/esm2015/plugins/session-id/session-id.request.js +7 -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 +12 -12
- 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 +7 -7
- package/schematics/ng-add/index.js.map +1 -0
- package/schematics/ng-add/schema.js.map +1 -0
- 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 +23 -11
- 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 +22 -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 +22 -11
- package/src/clients/api-fetch-client.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/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/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/cjs/utils/json-token.js
CHANGED
|
@@ -169,11 +169,11 @@ function _ts_generator(thisArg, body) {
|
|
|
169
169
|
// encodeURI escape all non-ASCII characters but we don't want to escape latin non-ascii characters
|
|
170
170
|
// (charCode between 128 and 255).
|
|
171
171
|
return window.btoa(encodeURI(str).replace(/%C2%([89AB][0-9A-F])/g, function(_match, p1) {
|
|
172
|
-
return String.fromCharCode(parseInt(
|
|
172
|
+
return String.fromCharCode(parseInt('0x' + p1, 16));
|
|
173
173
|
}).replace(/%C3%([89AB][0-9A-F])/g, function(_match, p1) {
|
|
174
|
-
return String.fromCharCode(parseInt(
|
|
174
|
+
return String.fromCharCode(parseInt('0xc0', 16) + parseInt('0x' + p1, 16) - parseInt('0x80', 16));
|
|
175
175
|
}).replace(/%([0-9A-F]{2})/g, function(_match, p1) {
|
|
176
|
-
return String.fromCharCode(parseInt(
|
|
176
|
+
return String.fromCharCode(parseInt('0x' + p1, 16));
|
|
177
177
|
}));
|
|
178
178
|
}
|
|
179
179
|
/**
|
|
@@ -183,83 +183,83 @@ function _ts_generator(thisArg, body) {
|
|
|
183
183
|
// Once the provided string is decoded from based64, we convert each character in its hexadecimal
|
|
184
184
|
// value prefixed with the % character to make it URI compatible.
|
|
185
185
|
var hexString = window.atob(str).replace(/./g, function(match) {
|
|
186
|
-
return
|
|
186
|
+
return '%' + match.charCodeAt(0).toString(16);
|
|
187
187
|
});
|
|
188
188
|
return decodeURI(hexString);
|
|
189
189
|
}
|
|
190
190
|
function base64EncodeUrl(str) {
|
|
191
|
-
return str.replace(/\+/g,
|
|
191
|
+
return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
192
192
|
}
|
|
193
193
|
function base64DecodeUrl(str) {
|
|
194
194
|
// Pad out with standard base64 required padding characters
|
|
195
|
-
str = (str +
|
|
196
|
-
return str.replace(/-/g,
|
|
195
|
+
str = (str + '===').slice(0, str.length + str.length % 4);
|
|
196
|
+
return str.replace(/-/g, '+').replace(/_/g, '/');
|
|
197
197
|
}
|
|
198
198
|
function createBase64Encoder() {
|
|
199
199
|
// Web browsers
|
|
200
|
-
if (typeof window !==
|
|
200
|
+
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
201
201
|
return function(data) {
|
|
202
202
|
return base64EncodeUnicode(data);
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
205
|
// NodeJS
|
|
206
|
-
if (typeof Buffer ===
|
|
206
|
+
if (typeof Buffer === 'function') {
|
|
207
207
|
return function(data) {
|
|
208
|
-
return Buffer.from(data).toString(
|
|
208
|
+
return Buffer.from(data).toString('base64');
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
|
-
throw new Error(
|
|
211
|
+
throw new Error('Cannot convert string to base64, both btoa and Buffer are undefined.');
|
|
212
212
|
}
|
|
213
213
|
function createBase64Decoder() {
|
|
214
214
|
// Web browsers
|
|
215
|
-
if (typeof window !==
|
|
215
|
+
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
216
216
|
return function(data) {
|
|
217
217
|
return base64DecodeUnicode(data);
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
220
|
// NodeJS
|
|
221
|
-
if (typeof Buffer ===
|
|
221
|
+
if (typeof Buffer === 'function') {
|
|
222
222
|
return function(data) {
|
|
223
|
-
return Buffer.from(data,
|
|
223
|
+
return Buffer.from(data, 'base64').toString();
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
|
-
throw new Error(
|
|
226
|
+
throw new Error('Cannot convert base64 to string, both atob and Buffer are undefined.');
|
|
227
227
|
}
|
|
228
228
|
function createBase64UrlEncoder() {
|
|
229
229
|
// Web browsers
|
|
230
|
-
if (typeof window !==
|
|
230
|
+
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
231
231
|
return function(data) {
|
|
232
232
|
return base64EncodeUrl(base64EncodeUnicode(data));
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
235
|
// NodeJS
|
|
236
|
-
if (typeof Buffer ===
|
|
236
|
+
if (typeof Buffer === 'function') {
|
|
237
237
|
return function(data) {
|
|
238
|
-
return base64EncodeUrl(Buffer.from(data).toString(
|
|
238
|
+
return base64EncodeUrl(Buffer.from(data).toString('base64'));
|
|
239
239
|
};
|
|
240
240
|
}
|
|
241
|
-
throw new Error(
|
|
241
|
+
throw new Error('Cannot convert string to base64, both btoa and Buffer are undefined.');
|
|
242
242
|
}
|
|
243
243
|
function createBase64UrlDecoder() {
|
|
244
244
|
// Web browsers
|
|
245
|
-
if (typeof window !==
|
|
245
|
+
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
246
246
|
return function(data) {
|
|
247
247
|
return base64DecodeUnicode(base64DecodeUrl(data));
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
250
|
// NodeJS
|
|
251
|
-
if (typeof Buffer ===
|
|
251
|
+
if (typeof Buffer === 'function') {
|
|
252
252
|
return function(data) {
|
|
253
|
-
return Buffer.from(base64DecodeUrl(data),
|
|
253
|
+
return Buffer.from(base64DecodeUrl(data), 'base64').toString();
|
|
254
254
|
};
|
|
255
255
|
}
|
|
256
|
-
throw new Error(
|
|
256
|
+
throw new Error('Cannot convert base64 to string, both atob and Buffer are undefined.');
|
|
257
257
|
}
|
|
258
258
|
function createJwtEncoder() {
|
|
259
259
|
var encoder = createBase64UrlEncoder();
|
|
260
260
|
var jwtHeader = {
|
|
261
|
-
alg:
|
|
262
|
-
typ:
|
|
261
|
+
alg: 'none',
|
|
262
|
+
typ: 'JWT'
|
|
263
263
|
};
|
|
264
264
|
return function(jwtPayload) {
|
|
265
265
|
return "".concat(encoder(JSON.stringify(jwtHeader)), ".").concat(encoder(JSON.stringify(jwtPayload)), ".");
|
|
@@ -268,7 +268,7 @@ function createJwtEncoder() {
|
|
|
268
268
|
function createJweEncoder() {
|
|
269
269
|
var aesTagLengthInBits = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 128, useHeaderAsAAD = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
270
270
|
var base64Encoder = createBase64UrlEncoder();
|
|
271
|
-
var stringEncoder = typeof window.TextEncoder !==
|
|
271
|
+
var stringEncoder = typeof window.TextEncoder !== 'undefined' ? new TextEncoder() : new _encoder.Encoder();
|
|
272
272
|
return function() {
|
|
273
273
|
var _ref = _async_to_generator(function(param, jwePayload, publicProperties) {
|
|
274
274
|
var publicKey, keyId, jweHeader, cek, wrappedCek, iv, serializedHeader, _ref, ciphertext, authenticationTag;
|
|
@@ -277,9 +277,9 @@ function createJweEncoder() {
|
|
|
277
277
|
case 0:
|
|
278
278
|
publicKey = param.publicKey, keyId = param.keyId;
|
|
279
279
|
jweHeader = {
|
|
280
|
-
alg:
|
|
281
|
-
enc:
|
|
282
|
-
typ:
|
|
280
|
+
alg: 'RSA-OAEP-256',
|
|
281
|
+
enc: 'A256GCM',
|
|
282
|
+
typ: 'JWE',
|
|
283
283
|
kid: keyId
|
|
284
284
|
};
|
|
285
285
|
publicProperties.forEach(function(property) {
|
|
@@ -317,7 +317,7 @@ function createJweEncoder() {
|
|
|
317
317
|
_ref = _state.sent(), ciphertext = _ref.ciphertext, authenticationTag = _ref.authenticationTag;
|
|
318
318
|
return [
|
|
319
319
|
2,
|
|
320
|
-
serializedHeader +
|
|
320
|
+
serializedHeader + '.' + base64Encoder((0, _crypto.ab2str)(wrappedCek)) + '.' + base64Encoder((0, _crypto.ab2str)(iv.buffer)) + '.' + base64Encoder((0, _crypto.ab2str)(ciphertext)) + '.' + base64Encoder((0, _crypto.ab2str)(authenticationTag))
|
|
321
321
|
];
|
|
322
322
|
}
|
|
323
323
|
});
|
|
@@ -173,27 +173,27 @@ function _ts_generator(thisArg, body) {
|
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
var crypto = require(
|
|
177
|
-
describe(
|
|
178
|
-
it(
|
|
176
|
+
var crypto = require('node:crypto');
|
|
177
|
+
describe('JSON token utils', function() {
|
|
178
|
+
it('should encode and decode in base64 properly a string that contains characters occupying more than 1 byte', function() {
|
|
179
179
|
var base64Encoder = (0, _jsontoken.createBase64Encoder)();
|
|
180
180
|
var base64Decoder = (0, _jsontoken.createBase64Decoder)();
|
|
181
|
-
var myString =
|
|
181
|
+
var myString = '☸☹☺☻☼☾☿';
|
|
182
182
|
var converted = base64Encoder(myString);
|
|
183
183
|
var original = base64Decoder(converted);
|
|
184
184
|
expect(original).toEqual(myString);
|
|
185
185
|
});
|
|
186
|
-
it(
|
|
186
|
+
it('should encode and decode in base64Url properly a string that contains characters occupying more than 1 byte', function() {
|
|
187
187
|
var base64UrlEncoder = (0, _jsontoken.createBase64UrlEncoder)();
|
|
188
188
|
var base64UrlDecoder = (0, _jsontoken.createBase64UrlDecoder)();
|
|
189
|
-
var myString =
|
|
189
|
+
var myString = '☸☹☺☻☼☾☿';
|
|
190
190
|
var converted = base64UrlEncoder(myString);
|
|
191
191
|
var original = base64UrlDecoder(converted);
|
|
192
192
|
expect(original).toEqual(myString);
|
|
193
193
|
});
|
|
194
194
|
});
|
|
195
|
-
describe(
|
|
196
|
-
it(
|
|
195
|
+
describe('JSON Web Encryption Token', function() {
|
|
196
|
+
it('should generate a proper JWE Token', /*#__PURE__*/ _async_to_generator(function() {
|
|
197
197
|
var expectedJwePayload, expectedJweHeader, expectedIv, cek, expectedJweEncryptedKey, outputAesGcm, jweToken, _jweToken_split, jweHeader, jweEncryptedKey, iv, cipherContent, authenticationTag, decipher, decrypted;
|
|
198
198
|
return _ts_generator(this, function(_state) {
|
|
199
199
|
switch(_state.label){
|
|
@@ -201,20 +201,20 @@ describe("JSON Web Encryption Token", function() {
|
|
|
201
201
|
/* eslint-disable @typescript-eslint/naming-convention */ expectedJwePayload = {
|
|
202
202
|
iat: 0,
|
|
203
203
|
exp: 3600,
|
|
204
|
-
iss:
|
|
205
|
-
sub:
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
204
|
+
iss: 'DEMO_JWE',
|
|
205
|
+
sub: 'pii',
|
|
206
|
+
'ama-tokens': {
|
|
207
|
+
'{orderId}': 'RG287F',
|
|
208
|
+
'{lastName}': 'Doe'
|
|
209
209
|
}
|
|
210
210
|
};
|
|
211
211
|
/* eslint-enable @typescript-eslint/naming-convention */ expectedJweHeader = {
|
|
212
|
-
alg:
|
|
213
|
-
enc:
|
|
214
|
-
typ:
|
|
215
|
-
kid:
|
|
216
|
-
iss:
|
|
217
|
-
sub:
|
|
212
|
+
alg: 'RSA-OAEP-256',
|
|
213
|
+
enc: 'A256GCM',
|
|
214
|
+
typ: 'JWE',
|
|
215
|
+
kid: 'TEST',
|
|
216
|
+
iss: 'DEMO_JWE',
|
|
217
|
+
sub: 'pii'
|
|
218
218
|
};
|
|
219
219
|
expectedIv = new Uint8Array([
|
|
220
220
|
21,
|
|
@@ -644,7 +644,7 @@ describe("JSON Web Encryption Token", function() {
|
|
|
644
644
|
]);
|
|
645
645
|
global.window = {
|
|
646
646
|
btoa: function(data) {
|
|
647
|
-
return Buffer.from(data,
|
|
647
|
+
return Buffer.from(data, 'ascii').toString('base64');
|
|
648
648
|
},
|
|
649
649
|
crypto: {
|
|
650
650
|
getRandomValues: jest.fn().mockReturnValue(expectedIv),
|
|
@@ -658,25 +658,25 @@ describe("JSON Web Encryption Token", function() {
|
|
|
658
658
|
return [
|
|
659
659
|
4,
|
|
660
660
|
(0, _jsontoken.createJweEncoder)(96)({
|
|
661
|
-
publicKey:
|
|
662
|
-
keyId:
|
|
661
|
+
publicKey: 'myPublicKey',
|
|
662
|
+
keyId: 'TEST'
|
|
663
663
|
}, expectedJwePayload, [
|
|
664
|
-
|
|
665
|
-
|
|
664
|
+
'iss',
|
|
665
|
+
'sub'
|
|
666
666
|
])
|
|
667
667
|
];
|
|
668
668
|
case 1:
|
|
669
669
|
jweToken = _state.sent();
|
|
670
670
|
global.window = undefined;
|
|
671
|
-
_jweToken_split = _sliced_to_array(jweToken.split(
|
|
672
|
-
expect(decodeURI(Buffer.from((0, _jsontoken.base64DecodeUrl)(jweHeader),
|
|
673
|
-
expect(Buffer.from((0, _jsontoken.base64DecodeUrl)(jweEncryptedKey),
|
|
674
|
-
expect(Buffer.from((0, _jsontoken.base64DecodeUrl)(iv),
|
|
675
|
-
decipher = crypto.createDecipheriv(
|
|
671
|
+
_jweToken_split = _sliced_to_array(jweToken.split('.'), 5), jweHeader = _jweToken_split[0], jweEncryptedKey = _jweToken_split[1], iv = _jweToken_split[2], cipherContent = _jweToken_split[3], authenticationTag = _jweToken_split[4];
|
|
672
|
+
expect(decodeURI(Buffer.from((0, _jsontoken.base64DecodeUrl)(jweHeader), 'base64').toString())).toEqual(JSON.stringify(expectedJweHeader));
|
|
673
|
+
expect(Buffer.from((0, _jsontoken.base64DecodeUrl)(jweEncryptedKey), 'base64')).toEqual(Buffer.from(expectedJweEncryptedKey));
|
|
674
|
+
expect(Buffer.from((0, _jsontoken.base64DecodeUrl)(iv), 'base64')).toEqual(Buffer.from(expectedIv));
|
|
675
|
+
decipher = crypto.createDecipheriv('aes-256-gcm', cek, Buffer.from((0, _jsontoken.base64DecodeUrl)(iv), 'base64'), {
|
|
676
676
|
authTagLength: 12
|
|
677
677
|
});
|
|
678
|
-
decipher.setAuthTag(Buffer.from((0, _jsontoken.base64DecodeUrl)(authenticationTag),
|
|
679
|
-
decrypted = decipher.update(Buffer.from((0, _jsontoken.base64DecodeUrl)(cipherContent),
|
|
678
|
+
decipher.setAuthTag(Buffer.from((0, _jsontoken.base64DecodeUrl)(authenticationTag), 'base64'));
|
|
679
|
+
decrypted = decipher.update(Buffer.from((0, _jsontoken.base64DecodeUrl)(cipherContent), 'base64'));
|
|
680
680
|
decrypted += decipher.final();
|
|
681
681
|
expect(decrypted.toString()).toEqual(JSON.stringify(expectedJwePayload));
|
|
682
682
|
return [
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clear-index.cjs","sourceRoot":"","sources":["../../cli/clear-index.cts"],"names":[],"mappings":";;AAEA;;GAEG;;AAEH,qCAAmD;AACnD,yCAAoC;AAEpC,MAAM,OAAO,GAAG,IAAA,mBAAO,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEhE,KAAK,CAAC,KAAK,IAAI,EAAE;IACf,MAAM,MAAM,GAAG,MAAM,kBAAE,CAAC,OAAO,CAAC,OAAO,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QAC9B,OAAO,IAAA,sBAAY,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC,CAAC;IAEF,kCAAkC;IAClC,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,EAAC,IAAI,EAAE,UAAU,EAAC,EAAE,EAAE;QACpD,OAAO,KAAK,CAAC,CAAC;YACZ,qCAAO,UAAU,GACd,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,EAAC,GAAG,EAAE,OAAO,EAAC,CAAC,CAAC;iBACxD,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;gBACnD,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;oBAChD,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;oBAC7B,OAAO,aAAa,EAAE,CAAC;gBACzB,CAAC;YACH,CAAC,CAAC,CAAC,CAAC,CAAC;YACP,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;iBACd,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAE1B,4BAA4B;IAC5B,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE,CAAC;QACzB,MAAM,aAAa,EAAE,CAAC;IACxB,CAAC;AACH,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -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) {
|
|
@@ -340,7 +358,7 @@ var DEFAULT_OPTIONS = {
|
|
|
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([
|
|
@@ -356,7 +374,7 @@ var DEFAULT_OPTIONS = {
|
|
|
356
374
|
var metadataSignal = (_options_metadata = options.metadata) === null || _options_metadata === void 0 ? void 0 : _options_metadata.signal;
|
|
357
375
|
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
358
376
|
var subscription = _this.options.httpClient.request(options.method, url, _object_spread_props(_object_spread({}, options), {
|
|
359
|
-
observe:
|
|
377
|
+
observe: 'response',
|
|
360
378
|
headers: headers
|
|
361
379
|
})).subscribe({
|
|
362
380
|
next: function(res) {
|
|
@@ -370,7 +388,7 @@ var DEFAULT_OPTIONS = {
|
|
|
370
388
|
}
|
|
371
389
|
});
|
|
372
390
|
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
373
|
-
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.addEventListener(
|
|
391
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.addEventListener('abort', function() {
|
|
374
392
|
subscription.unsubscribe();
|
|
375
393
|
reject(metadataSignal.reason);
|
|
376
394
|
});
|
|
@@ -388,7 +406,7 @@ var DEFAULT_OPTIONS = {
|
|
|
388
406
|
];
|
|
389
407
|
case 3:
|
|
390
408
|
e = _state.sent();
|
|
391
|
-
exception = new EmptyResponseError(e.message ||
|
|
409
|
+
exception = new EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
|
|
392
410
|
apiName: apiName,
|
|
393
411
|
operationId: operationId,
|
|
394
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: [],
|
|
@@ -57,7 +88,7 @@ var DEFAULT_OPTIONS = {
|
|
|
57
88
|
*/ // NOTE: the `extends unknown` is required for ESM build with TSC
|
|
58
89
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
59
90
|
var isPromise = function(value) {
|
|
60
|
-
return value
|
|
91
|
+
return _instanceof(value, Promise);
|
|
61
92
|
};
|
|
62
93
|
/**
|
|
63
94
|
* The Beacon API client is an implementation of the API Client using the Navigator Beacon API.
|
|
@@ -67,8 +98,8 @@ var isPromise = function(value) {
|
|
|
67
98
|
function ApiBeaconClient(options) {
|
|
68
99
|
_class_call_check(this, ApiBeaconClient);
|
|
69
100
|
/** @inheritdoc */ _define_property(this, "options", void 0);
|
|
70
|
-
if (typeof navigator ===
|
|
71
|
-
throw new Error(
|
|
101
|
+
if (typeof navigator === 'undefined' || !navigator.sendBeacon) {
|
|
102
|
+
throw new Error('Beacon API is not supported in this context');
|
|
72
103
|
}
|
|
73
104
|
this.options = _object_spread({}, DEFAULT_OPTIONS, options);
|
|
74
105
|
}
|
|
@@ -80,28 +111,24 @@ var isPromise = function(value) {
|
|
|
80
111
|
}
|
|
81
112
|
},
|
|
82
113
|
{
|
|
83
|
-
key: "
|
|
84
|
-
value: /** @inheritdoc */ function
|
|
85
|
-
if (method.toUpperCase() !==
|
|
86
|
-
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."));
|
|
87
118
|
}
|
|
88
|
-
var
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
queryParams: filterUndefinedValues(queryParams),
|
|
93
|
-
basePath: url,
|
|
94
|
-
tokenizedOptions: tokenizedOptions,
|
|
95
|
-
metadata: metadata
|
|
96
|
-
};
|
|
97
|
-
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
|
+
});
|
|
98
123
|
if (this.options.requestPlugins) {
|
|
99
124
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
100
125
|
try {
|
|
101
126
|
for(var _iterator = this.options.requestPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
102
127
|
var plugin = _step.value;
|
|
128
|
+
var _options_api;
|
|
103
129
|
var changedOpt = plugin.load({
|
|
104
|
-
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
|
|
105
132
|
}).transform(opts);
|
|
106
133
|
if (isPromise(changedOpt)) {
|
|
107
134
|
throw new Error("Request plugin ".concat(plugin.constructor.name, " has async transform method. Only sync methods are supported with the Beacon client."));
|
|
@@ -127,6 +154,21 @@ var isPromise = function(value) {
|
|
|
127
154
|
return Promise.resolve(opts);
|
|
128
155
|
}
|
|
129
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
|
+
},
|
|
130
172
|
{
|
|
131
173
|
key: "prepareUrl",
|
|
132
174
|
value: /** @inheritdoc */ function prepareUrl1(url, queryParameters) {
|
|
@@ -149,7 +191,7 @@ var isPromise = function(value) {
|
|
|
149
191
|
key: "processCall",
|
|
150
192
|
value: /** @inheritdoc */ function processCall(url, options, _apiType, _apiName, _revivers, _operationId) {
|
|
151
193
|
var headers = _object_spread({
|
|
152
|
-
type:
|
|
194
|
+
type: 'application/json'
|
|
153
195
|
}, options.headers.entries());
|
|
154
196
|
var blob = new Blob(options.body ? [
|
|
155
197
|
JSON.stringify(options.body)
|