@ama-sdk/core 10.3.0-prerelease.8 → 10.3.0-rc.0
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
|
@@ -122,10 +122,10 @@ function _ts_generator(thisArg, body) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
import { akamaiTelemetryRetrieverFactory, BotProtectionFingerprintRequest, impervaProtectionRetrieverFactory } from
|
|
126
|
-
describe(
|
|
127
|
-
describe(
|
|
128
|
-
describe(
|
|
125
|
+
import { akamaiTelemetryRetrieverFactory, BotProtectionFingerprintRequest, impervaProtectionRetrieverFactory } from './bot-protection-fingerprint.request';
|
|
126
|
+
describe('BotProtectionFingerprint', function() {
|
|
127
|
+
describe('Retrievers', function() {
|
|
128
|
+
describe('impervaProtectionRetrieverFactory', function() {
|
|
129
129
|
var consoleMock;
|
|
130
130
|
var windowBackup;
|
|
131
131
|
var tokenValue;
|
|
@@ -137,12 +137,12 @@ describe("BotProtectionFingerprint", function() {
|
|
|
137
137
|
};
|
|
138
138
|
var protectionReject = {
|
|
139
139
|
token: function() {
|
|
140
|
-
return Promise.reject(
|
|
140
|
+
return Promise.reject('error');
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
143
|
var registerEvent = function(protection) {
|
|
144
144
|
var delay = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
|
|
145
|
-
Object.defineProperty(global.window,
|
|
145
|
+
Object.defineProperty(global.window, 'protectionLoaded', {
|
|
146
146
|
set: function(handler) {
|
|
147
147
|
setTimeout(function() {
|
|
148
148
|
return handler(protection || protectionResolve);
|
|
@@ -152,19 +152,19 @@ describe("BotProtectionFingerprint", function() {
|
|
|
152
152
|
});
|
|
153
153
|
};
|
|
154
154
|
beforeEach(function() {
|
|
155
|
-
consoleMock = jest.spyOn(console,
|
|
155
|
+
consoleMock = jest.spyOn(console, 'error').mockImplementation();
|
|
156
156
|
windowBackup = global.window;
|
|
157
157
|
// eslint-disable-next-line no-global-assign
|
|
158
158
|
global.window = {};
|
|
159
159
|
retriever = impervaProtectionRetrieverFactory(50, 50);
|
|
160
|
-
tokenValue =
|
|
160
|
+
tokenValue = 'dummyToken';
|
|
161
161
|
});
|
|
162
162
|
afterEach(function() {
|
|
163
163
|
// eslint-disable-next-line no-global-assign
|
|
164
164
|
global.window = windowBackup;
|
|
165
165
|
consoleMock.mockReset();
|
|
166
166
|
});
|
|
167
|
-
it(
|
|
167
|
+
it('Should return undefined and log if no Protection object is received.', /*#__PURE__*/ _async_to_generator(function() {
|
|
168
168
|
var promise;
|
|
169
169
|
return _ts_generator(this, function(_state) {
|
|
170
170
|
switch(_state.label){
|
|
@@ -192,7 +192,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
192
192
|
}
|
|
193
193
|
});
|
|
194
194
|
}));
|
|
195
|
-
it(
|
|
195
|
+
it('Should return undefined and log if no Protection object is received within configured timeout.', /*#__PURE__*/ _async_to_generator(function() {
|
|
196
196
|
var promise;
|
|
197
197
|
return _ts_generator(this, function(_state) {
|
|
198
198
|
switch(_state.label){
|
|
@@ -221,7 +221,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
221
221
|
}
|
|
222
222
|
});
|
|
223
223
|
}));
|
|
224
|
-
it(
|
|
224
|
+
it('Should return undefined and log if token promise rejected.', /*#__PURE__*/ _async_to_generator(function() {
|
|
225
225
|
var promise;
|
|
226
226
|
return _ts_generator(this, function(_state) {
|
|
227
227
|
switch(_state.label){
|
|
@@ -250,7 +250,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
250
250
|
}
|
|
251
251
|
});
|
|
252
252
|
}));
|
|
253
|
-
it(
|
|
253
|
+
it('Should return the token if everything happened within timeout values.', /*#__PURE__*/ _async_to_generator(function() {
|
|
254
254
|
var promise, newPromise;
|
|
255
255
|
return _ts_generator(this, function(_state) {
|
|
256
256
|
switch(_state.label){
|
|
@@ -271,7 +271,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
271
271
|
expect.apply(void 0, [
|
|
272
272
|
_state.sent()
|
|
273
273
|
]).toBe(tokenValue);
|
|
274
|
-
tokenValue =
|
|
274
|
+
tokenValue = 'newToken';
|
|
275
275
|
newPromise = retriever();
|
|
276
276
|
return [
|
|
277
277
|
4,
|
|
@@ -296,51 +296,51 @@ describe("BotProtectionFingerprint", function() {
|
|
|
296
296
|
});
|
|
297
297
|
}));
|
|
298
298
|
});
|
|
299
|
-
describe(
|
|
300
|
-
it(
|
|
299
|
+
describe('akamaiTelemetryRetrieverFactory', function() {
|
|
300
|
+
it('Should return undefined if bmak object doesn\'t exist.', function() {
|
|
301
301
|
expect(akamaiTelemetryRetrieverFactory()()).toBeUndefined();
|
|
302
302
|
expect(akamaiTelemetryRetrieverFactory({})()).toBeUndefined();
|
|
303
303
|
// eslint-disable-next-line @typescript-eslint/naming-convention,camelcase
|
|
304
304
|
expect(akamaiTelemetryRetrieverFactory({
|
|
305
|
-
get_telemetry:
|
|
305
|
+
get_telemetry: 'test'
|
|
306
306
|
})()).toBeUndefined();
|
|
307
307
|
});
|
|
308
|
-
it(
|
|
308
|
+
it('Should return telemetry', function() {
|
|
309
309
|
// eslint-disable-next-line @typescript-eslint/naming-convention,camelcase
|
|
310
310
|
expect(akamaiTelemetryRetrieverFactory({
|
|
311
311
|
get_telemetry: function() {
|
|
312
|
-
return
|
|
312
|
+
return 'telemetryValue';
|
|
313
313
|
}
|
|
314
|
-
})()).toBe(
|
|
314
|
+
})()).toBe('telemetryValue');
|
|
315
315
|
global.window = {};
|
|
316
316
|
// eslint-disable-next-line @typescript-eslint/naming-convention,camelcase
|
|
317
317
|
global.window.bmak = {
|
|
318
318
|
get_telemetry: function() {
|
|
319
|
-
return
|
|
319
|
+
return 'telemetryValue2';
|
|
320
320
|
}
|
|
321
321
|
};
|
|
322
|
-
expect(akamaiTelemetryRetrieverFactory()()).toBe(
|
|
322
|
+
expect(akamaiTelemetryRetrieverFactory()()).toBe('telemetryValue2');
|
|
323
323
|
global.window = undefined;
|
|
324
324
|
});
|
|
325
325
|
});
|
|
326
326
|
});
|
|
327
|
-
describe(
|
|
327
|
+
describe('Plug-in', function() {
|
|
328
328
|
var mockedRequest;
|
|
329
329
|
var mockedFingerprint;
|
|
330
330
|
var fingerprintRetriever;
|
|
331
|
-
var destinationHeaderName =
|
|
331
|
+
var destinationHeaderName = 'test-header';
|
|
332
332
|
beforeEach(function() {
|
|
333
333
|
mockedFingerprint = undefined;
|
|
334
334
|
mockedRequest = {
|
|
335
|
-
method:
|
|
336
|
-
basePath:
|
|
335
|
+
method: 'get',
|
|
336
|
+
basePath: 'toto',
|
|
337
337
|
headers: new Headers()
|
|
338
338
|
};
|
|
339
339
|
fingerprintRetriever = jest.fn().mockImplementation(function() {
|
|
340
340
|
return mockedFingerprint;
|
|
341
341
|
});
|
|
342
342
|
});
|
|
343
|
-
it(
|
|
343
|
+
it('Should add the fingerprint header if a fingerprint is found.', /*#__PURE__*/ _async_to_generator(function() {
|
|
344
344
|
var plugin, newRequest;
|
|
345
345
|
return _ts_generator(this, function(_state) {
|
|
346
346
|
switch(_state.label){
|
|
@@ -351,7 +351,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
351
351
|
pollerOptions: undefined,
|
|
352
352
|
pollOnlyOnce: false
|
|
353
353
|
}).load();
|
|
354
|
-
mockedFingerprint =
|
|
354
|
+
mockedFingerprint = 'fingerprint';
|
|
355
355
|
return [
|
|
356
356
|
4,
|
|
357
357
|
plugin.transform(mockedRequest)
|
|
@@ -366,7 +366,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
366
366
|
}
|
|
367
367
|
});
|
|
368
368
|
}));
|
|
369
|
-
it(
|
|
369
|
+
it('Should\' add the fingerprint header if no fingerprint is found with no poller.', /*#__PURE__*/ _async_to_generator(function() {
|
|
370
370
|
var plugin, newRequest;
|
|
371
371
|
return _ts_generator(this, function(_state) {
|
|
372
372
|
switch(_state.label){
|
|
@@ -391,7 +391,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
391
391
|
}
|
|
392
392
|
});
|
|
393
393
|
}));
|
|
394
|
-
it(
|
|
394
|
+
it('Should add the fingerprint header if there is no fingerprint after the configured poller has finished running.', /*#__PURE__*/ _async_to_generator(function() {
|
|
395
395
|
var plugin, newRequestPromise, newRequest;
|
|
396
396
|
return _ts_generator(this, function(_state) {
|
|
397
397
|
switch(_state.label){
|
|
@@ -426,7 +426,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
426
426
|
}
|
|
427
427
|
});
|
|
428
428
|
}));
|
|
429
|
-
it(
|
|
429
|
+
it('Should add the fingerprint header if initially not found but added before the poller ended.', /*#__PURE__*/ _async_to_generator(function() {
|
|
430
430
|
var plugin, newRequestPromise, newRequest;
|
|
431
431
|
return _ts_generator(this, function(_state) {
|
|
432
432
|
switch(_state.label){
|
|
@@ -441,7 +441,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
441
441
|
pollOnlyOnce: false
|
|
442
442
|
}).load();
|
|
443
443
|
setTimeout(function() {
|
|
444
|
-
return mockedFingerprint =
|
|
444
|
+
return mockedFingerprint = 'fingerprint';
|
|
445
445
|
}, 350);
|
|
446
446
|
newRequestPromise = plugin.transform(mockedRequest);
|
|
447
447
|
return [
|
|
@@ -450,7 +450,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
450
450
|
];
|
|
451
451
|
case 1:
|
|
452
452
|
_state.sent();
|
|
453
|
-
mockedFingerprint =
|
|
453
|
+
mockedFingerprint = 'fingerprint';
|
|
454
454
|
return [
|
|
455
455
|
4,
|
|
456
456
|
jest.runAllTimersAsync()
|
|
@@ -471,7 +471,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
471
471
|
}
|
|
472
472
|
});
|
|
473
473
|
}));
|
|
474
|
-
it(
|
|
474
|
+
it('Should poll twice if configured.', /*#__PURE__*/ _async_to_generator(function() {
|
|
475
475
|
var plugin, promise;
|
|
476
476
|
return _ts_generator(this, function(_state) {
|
|
477
477
|
switch(_state.label){
|
|
@@ -519,7 +519,7 @@ describe("BotProtectionFingerprint", function() {
|
|
|
519
519
|
}
|
|
520
520
|
});
|
|
521
521
|
}));
|
|
522
|
-
it(
|
|
522
|
+
it('Shouldn\'t poll twice if configured.', /*#__PURE__*/ _async_to_generator(function() {
|
|
523
523
|
var plugin, promise;
|
|
524
524
|
return _ts_generator(this, function(_state) {
|
|
525
525
|
switch(_state.label){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './bot-protection-fingerprint.request';
|
|
@@ -169,14 +169,14 @@ function _ts_generator(thisArg, body) {
|
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
import { createJwtEncoder } from
|
|
172
|
+
import { createJwtEncoder } from '../../utils/json-token';
|
|
173
173
|
/**
|
|
174
174
|
* Creates a JWT encoding function which transforms the provided Facts as a unsecured JWT format https://tools.ietf.org/html/rfc7519#section-6
|
|
175
175
|
*/ export function createJwtFactsEncoder() {
|
|
176
176
|
var jwtEncoder = createJwtEncoder();
|
|
177
177
|
var jwtPayload = function(data) {
|
|
178
178
|
return _object_spread({
|
|
179
|
-
sub:
|
|
179
|
+
sub: 'fact'
|
|
180
180
|
}, data);
|
|
181
181
|
};
|
|
182
182
|
return function(data) {
|
|
@@ -257,7 +257,7 @@ import { createJwtEncoder } from "../../utils/json-token";
|
|
|
257
257
|
/** Global facts that will be sent with every request */ _define_property(this, "globalFacts", void 0);
|
|
258
258
|
/** Private facts that will be sent as-is with every request */ _define_property(this, "privateFacts", void 0);
|
|
259
259
|
_define_property(this, "jwtEncoder", createJwtFactsEncoder());
|
|
260
|
-
this.headerName = options.headerName ||
|
|
260
|
+
this.headerName = options.headerName || 'ama-client-facts';
|
|
261
261
|
this.globalFacts = options.initialGlobalFacts;
|
|
262
262
|
this.privateFacts = options.privateFacts;
|
|
263
263
|
this.factsFactory = options.factsFactory;
|
|
@@ -292,7 +292,7 @@ import { createJwtEncoder } from "../../utils/json-token";
|
|
|
292
292
|
return _ts_generator(this, function(_state) {
|
|
293
293
|
switch(_state.label){
|
|
294
294
|
case 0:
|
|
295
|
-
if (!(typeof _this.factsFactory ===
|
|
295
|
+
if (!(typeof _this.factsFactory === 'function')) return [
|
|
296
296
|
3,
|
|
297
297
|
2
|
|
298
298
|
];
|
|
@@ -150,37 +150,37 @@ function _ts_generator(thisArg, body) {
|
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
import { ClientFactsRequestPlugin, createJwtFactsEncoder } from
|
|
153
|
+
import { ClientFactsRequestPlugin, createJwtFactsEncoder } from './client-facts.request';
|
|
154
154
|
var defaultFacts = {
|
|
155
|
-
foo:
|
|
156
|
-
bar:
|
|
155
|
+
foo: 'one',
|
|
156
|
+
bar: 'two'
|
|
157
157
|
};
|
|
158
158
|
var specificFacts = {
|
|
159
|
-
bar:
|
|
160
|
-
specific:
|
|
159
|
+
bar: 'three',
|
|
160
|
+
specific: 'I am specific'
|
|
161
161
|
};
|
|
162
|
-
var encryptedPrivateFacts =
|
|
162
|
+
var encryptedPrivateFacts = 'GuTVpr8JxjTj1Umlmph5h5sP00c2RfIUjJIw5iYMHarSXA8sYUIuEKTUDdC5fVkcmKXi4qd3W5y/VGQcKCo0bba3JlfBGviegpGVRvug/vfH2VYTsUyAyBFdcG+CiI4dY+0/Nn48G656KxRygBkxmg==';
|
|
163
163
|
var jwtFactsEncoder = createJwtFactsEncoder();
|
|
164
|
-
var defaultHeader =
|
|
165
|
-
describe(
|
|
164
|
+
var defaultHeader = 'ama-client-facts';
|
|
165
|
+
describe('Client Facts request plugin', function() {
|
|
166
166
|
var options;
|
|
167
167
|
var specificOptions;
|
|
168
168
|
beforeEach(function() {
|
|
169
169
|
options = {
|
|
170
|
-
basePath:
|
|
170
|
+
basePath: 'dummypath',
|
|
171
171
|
headers: new Headers(),
|
|
172
|
-
method:
|
|
172
|
+
method: 'GET'
|
|
173
173
|
};
|
|
174
174
|
specificOptions = {
|
|
175
|
-
basePath:
|
|
175
|
+
basePath: '/order',
|
|
176
176
|
headers: new Headers(),
|
|
177
|
-
method:
|
|
177
|
+
method: 'POST'
|
|
178
178
|
};
|
|
179
179
|
});
|
|
180
|
-
it(
|
|
181
|
-
expect(jwtFactsEncoder(defaultFacts)).toEqual(
|
|
180
|
+
it('Should encode the public facts as unsecured JWT', function() {
|
|
181
|
+
expect(jwtFactsEncoder(defaultFacts)).toEqual('eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJzdWIiOiJmYWN0IiwiZm9vIjoib25lIiwiYmFyIjoidHdvIn0.');
|
|
182
182
|
});
|
|
183
|
-
it(
|
|
183
|
+
it('Should apply global facts to every requests to the default header', /*#__PURE__*/ _async_to_generator(function() {
|
|
184
184
|
var plugin, firstOptions, secondOptions;
|
|
185
185
|
return _ts_generator(this, function(_state) {
|
|
186
186
|
switch(_state.label){
|
|
@@ -211,14 +211,14 @@ describe("Client Facts request plugin", function() {
|
|
|
211
211
|
}
|
|
212
212
|
});
|
|
213
213
|
}));
|
|
214
|
-
it(
|
|
214
|
+
it('Should allow to configure header name', /*#__PURE__*/ _async_to_generator(function() {
|
|
215
215
|
var plugin, newOptions;
|
|
216
216
|
return _ts_generator(this, function(_state) {
|
|
217
217
|
switch(_state.label){
|
|
218
218
|
case 0:
|
|
219
219
|
plugin = new ClientFactsRequestPlugin({
|
|
220
220
|
initialGlobalFacts: defaultFacts,
|
|
221
|
-
headerName:
|
|
221
|
+
headerName: 'dummy'
|
|
222
222
|
});
|
|
223
223
|
return [
|
|
224
224
|
4,
|
|
@@ -226,7 +226,7 @@ describe("Client Facts request plugin", function() {
|
|
|
226
226
|
];
|
|
227
227
|
case 1:
|
|
228
228
|
newOptions = _state.sent();
|
|
229
|
-
expect(newOptions.headers.has(
|
|
229
|
+
expect(newOptions.headers.has('dummy')).toBeTruthy();
|
|
230
230
|
expect(newOptions.headers.has(defaultHeader)).toBeFalsy();
|
|
231
231
|
return [
|
|
232
232
|
2
|
|
@@ -234,7 +234,7 @@ describe("Client Facts request plugin", function() {
|
|
|
234
234
|
}
|
|
235
235
|
});
|
|
236
236
|
}));
|
|
237
|
-
it(
|
|
237
|
+
it('Should allow to change facts via a function', /*#__PURE__*/ _async_to_generator(function() {
|
|
238
238
|
var plugin, newOptions;
|
|
239
239
|
return _ts_generator(this, function(_state) {
|
|
240
240
|
switch(_state.label){
|
|
@@ -243,7 +243,7 @@ describe("Client Facts request plugin", function() {
|
|
|
243
243
|
initialGlobalFacts: defaultFacts
|
|
244
244
|
});
|
|
245
245
|
plugin.setGlobalFacts({
|
|
246
|
-
foo:
|
|
246
|
+
foo: 'bar'
|
|
247
247
|
});
|
|
248
248
|
return [
|
|
249
249
|
4,
|
|
@@ -253,7 +253,7 @@ describe("Client Facts request plugin", function() {
|
|
|
253
253
|
newOptions = _state.sent();
|
|
254
254
|
expect(newOptions.headers.has(defaultHeader)).toBeTruthy();
|
|
255
255
|
expect(newOptions.headers.get(defaultHeader)).toEqual(jwtFactsEncoder({
|
|
256
|
-
foo:
|
|
256
|
+
foo: 'bar'
|
|
257
257
|
}));
|
|
258
258
|
return [
|
|
259
259
|
2
|
|
@@ -261,14 +261,14 @@ describe("Client Facts request plugin", function() {
|
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
263
|
}));
|
|
264
|
-
it(
|
|
264
|
+
it('Should allow to return facts only for specific requests thanks to factories', /*#__PURE__*/ _async_to_generator(function() {
|
|
265
265
|
var plugin, newOptions, newSpecificOptions;
|
|
266
266
|
return _ts_generator(this, function(_state) {
|
|
267
267
|
switch(_state.label){
|
|
268
268
|
case 0:
|
|
269
269
|
plugin = new ClientFactsRequestPlugin({
|
|
270
270
|
factsFactory: function(request) {
|
|
271
|
-
if (request.basePath.includes(
|
|
271
|
+
if (request.basePath.includes('/order') && request.method !== 'GET') {
|
|
272
272
|
return specificFacts;
|
|
273
273
|
}
|
|
274
274
|
return {};
|
|
@@ -295,7 +295,7 @@ describe("Client Facts request plugin", function() {
|
|
|
295
295
|
}
|
|
296
296
|
});
|
|
297
297
|
}));
|
|
298
|
-
it(
|
|
298
|
+
it('Should allow to set private facts', /*#__PURE__*/ _async_to_generator(function() {
|
|
299
299
|
var plugin, newOptions;
|
|
300
300
|
return _ts_generator(this, function(_state) {
|
|
301
301
|
switch(_state.label){
|
|
@@ -317,7 +317,7 @@ describe("Client Facts request plugin", function() {
|
|
|
317
317
|
}
|
|
318
318
|
});
|
|
319
319
|
}));
|
|
320
|
-
it(
|
|
320
|
+
it('Specific facts should have priority over global facts', /*#__PURE__*/ _async_to_generator(function() {
|
|
321
321
|
var plugin, newSpecificOptions;
|
|
322
322
|
return _ts_generator(this, function(_state) {
|
|
323
323
|
switch(_state.label){
|
|
@@ -325,7 +325,7 @@ describe("Client Facts request plugin", function() {
|
|
|
325
325
|
plugin = new ClientFactsRequestPlugin({
|
|
326
326
|
initialGlobalFacts: defaultFacts,
|
|
327
327
|
factsFactory: function(request) {
|
|
328
|
-
if (request.basePath.includes(
|
|
328
|
+
if (request.basePath.includes('/order') && request.method !== 'GET') {
|
|
329
329
|
return specificFacts;
|
|
330
330
|
}
|
|
331
331
|
return {};
|
|
@@ -345,14 +345,14 @@ describe("Client Facts request plugin", function() {
|
|
|
345
345
|
}
|
|
346
346
|
});
|
|
347
347
|
}));
|
|
348
|
-
it(
|
|
348
|
+
it('Factories should be allowed to be asynchronous and return a Promise of facts', /*#__PURE__*/ _async_to_generator(function() {
|
|
349
349
|
var plugin, promise, newSpecificOptions;
|
|
350
350
|
return _ts_generator(this, function(_state) {
|
|
351
351
|
switch(_state.label){
|
|
352
352
|
case 0:
|
|
353
353
|
plugin = new ClientFactsRequestPlugin({
|
|
354
354
|
factsFactory: function(request) {
|
|
355
|
-
if (request.basePath.includes(
|
|
355
|
+
if (request.basePath.includes('/order') && request.method !== 'GET') {
|
|
356
356
|
return new Promise(function(resolve) {
|
|
357
357
|
return setTimeout(function() {
|
|
358
358
|
return resolve(specificFacts);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './client-facts.request';
|
|
@@ -122,9 +122,9 @@ function _ts_generator(thisArg, body) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
import { ConcurrentFetch } from
|
|
126
|
-
describe(
|
|
127
|
-
it(
|
|
125
|
+
import { ConcurrentFetch } from './concurrent.fetch';
|
|
126
|
+
describe('Concurrent Fetch Plugin', function() {
|
|
127
|
+
it('should start if the limit is not reach', /*#__PURE__*/ _async_to_generator(function() {
|
|
128
128
|
var plugin, runner, canStart;
|
|
129
129
|
return _ts_generator(this, function(_state) {
|
|
130
130
|
switch(_state.label){
|
|
@@ -145,7 +145,7 @@ describe("Concurrent Fetch Plugin", function() {
|
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
147
|
}));
|
|
148
|
-
it(
|
|
148
|
+
it('should retrieve the fetchcall in the pool', function() {
|
|
149
149
|
var plugin = new ConcurrentFetch(3);
|
|
150
150
|
var call = new Promise(function(resolve) {
|
|
151
151
|
return setTimeout(function() {
|
|
@@ -162,7 +162,7 @@ describe("Concurrent Fetch Plugin", function() {
|
|
|
162
162
|
void plugin.load({}).transform(test);
|
|
163
163
|
expect(plugin.pool[2]).toBe(test);
|
|
164
164
|
});
|
|
165
|
-
it(
|
|
165
|
+
it('should start only when the pool is available', /*#__PURE__*/ _async_to_generator(function() {
|
|
166
166
|
var plugin, resolves, call0, call1, result, runner1, canStart1, runner2, pCanStart2;
|
|
167
167
|
return _ts_generator(this, function(_state) {
|
|
168
168
|
switch(_state.label){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './concurrent.fetch';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from './plugin';
|
|
2
|
+
export * from './fetch-plugin';
|
|
3
|
+
export * from './request-plugin';
|
|
4
|
+
export * from './reply-plugin';
|
|
@@ -122,16 +122,16 @@ function _ts_generator(thisArg, body) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
import { ApiTypes } from
|
|
126
|
-
import { CustomInfoReply } from
|
|
127
|
-
describe(
|
|
128
|
-
it(
|
|
125
|
+
import { ApiTypes } from '../../fwk/api';
|
|
126
|
+
import { CustomInfoReply } from './custom-info.reply';
|
|
127
|
+
describe('Custom info reply plugin', function() {
|
|
128
|
+
it('should add the content of the custom information in the reply', /*#__PURE__*/ _async_to_generator(function() {
|
|
129
129
|
var customInfo, plugin, runner, newData;
|
|
130
130
|
return _ts_generator(this, function(_state) {
|
|
131
131
|
switch(_state.label){
|
|
132
132
|
case 0:
|
|
133
133
|
customInfo = {
|
|
134
|
-
key:
|
|
134
|
+
key: 'value',
|
|
135
135
|
nested: {
|
|
136
136
|
field: 10
|
|
137
137
|
}
|
|
@@ -148,7 +148,7 @@ describe("Custom info reply plugin", function() {
|
|
|
148
148
|
case 1:
|
|
149
149
|
newData = _state.sent();
|
|
150
150
|
expect(newData.customInfo).toEqual({
|
|
151
|
-
key:
|
|
151
|
+
key: 'value',
|
|
152
152
|
nested: {
|
|
153
153
|
field: 10
|
|
154
154
|
}
|
|
@@ -159,18 +159,18 @@ describe("Custom info reply plugin", function() {
|
|
|
159
159
|
}
|
|
160
160
|
});
|
|
161
161
|
}));
|
|
162
|
-
it(
|
|
162
|
+
it('should merge the contents of the two custom info', /*#__PURE__*/ _async_to_generator(function() {
|
|
163
163
|
var customInfo1, plugin1, customInfo2, plugin2, runner1, runner2, newData, _;
|
|
164
164
|
return _ts_generator(this, function(_state) {
|
|
165
165
|
switch(_state.label){
|
|
166
166
|
case 0:
|
|
167
167
|
customInfo1 = {
|
|
168
|
-
key0:
|
|
169
|
-
key1:
|
|
168
|
+
key0: 'dummy',
|
|
169
|
+
key1: 'value'
|
|
170
170
|
};
|
|
171
171
|
plugin1 = new CustomInfoReply(customInfo1);
|
|
172
172
|
customInfo2 = {
|
|
173
|
-
key1:
|
|
173
|
+
key1: 'override',
|
|
174
174
|
key2: 42
|
|
175
175
|
};
|
|
176
176
|
plugin2 = new CustomInfoReply(customInfo2);
|
|
@@ -197,8 +197,8 @@ describe("Custom info reply plugin", function() {
|
|
|
197
197
|
case 2:
|
|
198
198
|
newData = _state.sent();
|
|
199
199
|
expect(newData.customInfo).toEqual({
|
|
200
|
-
key0:
|
|
201
|
-
key1:
|
|
200
|
+
key0: 'dummy',
|
|
201
|
+
key1: 'override',
|
|
202
202
|
key2: 42
|
|
203
203
|
});
|
|
204
204
|
return [
|
|
@@ -207,19 +207,19 @@ describe("Custom info reply plugin", function() {
|
|
|
207
207
|
}
|
|
208
208
|
});
|
|
209
209
|
}));
|
|
210
|
-
it(
|
|
210
|
+
it('should invalidate custom info', function() {
|
|
211
211
|
var plugin = new CustomInfoReply({});
|
|
212
212
|
var data = {
|
|
213
|
-
originalData:
|
|
213
|
+
originalData: 'OK'
|
|
214
214
|
};
|
|
215
215
|
expect(plugin.hasCustomInfo(data)).toBeFalsy();
|
|
216
216
|
});
|
|
217
|
-
it(
|
|
217
|
+
it('should validate custom info', function() {
|
|
218
218
|
var plugin = new CustomInfoReply({});
|
|
219
219
|
var data = {
|
|
220
|
-
originalData:
|
|
220
|
+
originalData: 'OK',
|
|
221
221
|
customInfo: {
|
|
222
|
-
a:
|
|
222
|
+
a: 'b'
|
|
223
223
|
}
|
|
224
224
|
};
|
|
225
225
|
expect(plugin.hasCustomInfo(data)).toBeTruthy();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './custom-info.reply';
|
|
@@ -30,8 +30,8 @@ function _define_property(obj, key, value) {
|
|
|
30
30
|
}
|
|
31
31
|
return obj;
|
|
32
32
|
}
|
|
33
|
-
import { ApiTypes } from
|
|
34
|
-
import { EmptyResponseError, RequestFailedError } from
|
|
33
|
+
import { ApiTypes } from '../../fwk/api';
|
|
34
|
+
import { EmptyResponseError, RequestFailedError } from '../../fwk/errors';
|
|
35
35
|
/**
|
|
36
36
|
* Plugin to fire an exception on wrong response / data
|
|
37
37
|
*/ export var ExceptionReply = /*#__PURE__*/ function() {
|
|
@@ -59,8 +59,8 @@ import { EmptyResponseError, RequestFailedError } from "../../fwk/errors";
|
|
|
59
59
|
};
|
|
60
60
|
var error;
|
|
61
61
|
if (!context.response) {
|
|
62
|
-
error = new EmptyResponseError(
|
|
63
|
-
} else if (context.apiType === ApiTypes.DAPI && context.response.status === 200 && (!res || !res.data && typeof res.errors !==
|
|
62
|
+
error = new EmptyResponseError('Fail to Fetch', undefined, errorContext);
|
|
63
|
+
} else if (context.apiType === ApiTypes.DAPI && context.response.status === 200 && (!res || !res.data && typeof res.errors !== 'undefined' // Some DAPI replies have data as optional, so we only throw if response contains errors
|
|
64
64
|
)) {
|
|
65
65
|
error = new EmptyResponseError(context.response.statusText, res, errorContext);
|
|
66
66
|
} else if (!context.response.ok) {
|