@ama-sdk/core 12.1.8 → 12.1.11

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.
Files changed (111) hide show
  1. package/cjs/clients/api-angular-client.js +13 -18
  2. package/cjs/clients/api-fetch-client.js +16 -21
  3. package/cjs/fwk/api.helpers.js +11 -11
  4. package/cjs/fwk/date.js +5 -5
  5. package/cjs/fwk/errors.js +7 -7
  6. package/cjs/fwk/mocks/alf-mock-adapter.js +58 -60
  7. package/cjs/fwk/mocks/base-mock-adapter.js +15 -19
  8. package/cjs/fwk/mocks/helpers.js +3 -3
  9. package/cjs/fwk/param-serialization.js +6 -6
  10. package/cjs/fwk/reviver.js +4 -4
  11. package/cjs/plugins/abort/abort.spec.js +83 -81
  12. package/cjs/plugins/additional-params/additional-params.request.js +18 -25
  13. package/cjs/plugins/additional-params/additional-params.spec.js +194 -186
  14. package/cjs/plugins/api-configuration-override/api-configuration-override.request.js +10 -17
  15. package/cjs/plugins/api-configuration-override/api-configuration-override.spec.js +83 -81
  16. package/cjs/plugins/api-key/api-key.request.js +12 -19
  17. package/cjs/plugins/api-key/api-key.spec.js +50 -50
  18. package/cjs/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +25 -36
  19. package/cjs/plugins/bot-protection-fingerprint/bot-protection-fingerprint.spec.js +343 -327
  20. package/cjs/plugins/client-facts/client-facts.request.js +18 -25
  21. package/cjs/plugins/client-facts/client-facts.spec.js +218 -208
  22. package/cjs/plugins/concurrent/concurrent.fetch.js +12 -20
  23. package/cjs/plugins/concurrent/concurrent.spec.js +99 -99
  24. package/cjs/plugins/custom-info/custom-info.spec.js +90 -90
  25. package/cjs/plugins/fetch-cache/fetch-cache.spec.js +100 -98
  26. package/cjs/plugins/fetch-credentials/fetch-credentials.spec.js +60 -60
  27. package/cjs/plugins/json-token/json-token.spec.js +109 -107
  28. package/cjs/plugins/keepalive/keepalive.request.js +7 -12
  29. package/cjs/plugins/keepalive/keepalive.spec.js +32 -34
  30. package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.helpers.js +11 -23
  31. package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +18 -28
  32. package/cjs/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +212 -204
  33. package/cjs/plugins/mock-intercept/mock-intercept.angular.js +94 -100
  34. package/cjs/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
  35. package/cjs/plugins/mock-intercept/mock-intercept.interface.js +3 -3
  36. package/cjs/plugins/mock-intercept/mock-intercept.request.js +12 -19
  37. package/cjs/plugins/mock-intercept/mock-intercept.spec.js +245 -237
  38. package/cjs/plugins/perf-metric/perf-metric.fetch.js +11 -18
  39. package/cjs/plugins/pii-tokenizer/pii-tokenizer.request.js +19 -27
  40. package/cjs/plugins/pii-tokenizer/pii-tokenizer.spec.js +404 -386
  41. package/cjs/plugins/raw-response-info/raw-response-info.spec.js +67 -67
  42. package/cjs/plugins/retry/retry.fetch.js +18 -27
  43. package/cjs/plugins/retry/retry.spec.js +233 -225
  44. package/cjs/plugins/reviver/reviver.spec.js +88 -86
  45. package/cjs/plugins/session-id/session-id.spec.js +98 -94
  46. package/cjs/plugins/si-token/si-token.spec.js +27 -29
  47. package/cjs/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js +17 -24
  48. package/cjs/plugins/simple-api-key-authentication/simple-api-key-authentication.spec.js +199 -191
  49. package/cjs/plugins/timeout/timeout.fetch.js +16 -22
  50. package/cjs/plugins/timeout/timeout.spec.js +211 -205
  51. package/cjs/plugins/url-rewrite/url-rewrite.request.js +9 -16
  52. package/cjs/plugins/url-rewrite/url-rewrite.spec.js +48 -48
  53. package/cjs/plugins/wait-for/wait-for.fetch.js +19 -29
  54. package/cjs/plugins/wait-for/wait-for.spec.js +211 -203
  55. package/cjs/utils/crypto.js +15 -27
  56. package/cjs/utils/generic-api.js +9 -14
  57. package/cjs/utils/json-token.js +19 -26
  58. package/cjs/utils/json-token.spec.js +495 -497
  59. package/cjs/utils/mime-types.js +3 -3
  60. package/esm2015/clients/api-angular-client.js +13 -18
  61. package/esm2015/clients/api-fetch-client.js +16 -21
  62. package/esm2015/fwk/mocks/alf-mock-adapter.js +58 -60
  63. package/esm2015/fwk/mocks/base-mock-adapter.js +15 -19
  64. package/esm2015/plugins/abort/abort.spec.js +83 -81
  65. package/esm2015/plugins/additional-params/additional-params.request.js +15 -22
  66. package/esm2015/plugins/additional-params/additional-params.spec.js +194 -186
  67. package/esm2015/plugins/api-configuration-override/api-configuration-override.request.js +10 -17
  68. package/esm2015/plugins/api-configuration-override/api-configuration-override.spec.js +83 -81
  69. package/esm2015/plugins/api-key/api-key.request.js +12 -19
  70. package/esm2015/plugins/api-key/api-key.spec.js +50 -50
  71. package/esm2015/plugins/bot-protection-fingerprint/bot-protection-fingerprint.request.js +21 -32
  72. package/esm2015/plugins/bot-protection-fingerprint/bot-protection-fingerprint.spec.js +343 -327
  73. package/esm2015/plugins/client-facts/client-facts.request.js +15 -22
  74. package/esm2015/plugins/client-facts/client-facts.spec.js +218 -208
  75. package/esm2015/plugins/concurrent/concurrent.fetch.js +12 -20
  76. package/esm2015/plugins/concurrent/concurrent.spec.js +99 -99
  77. package/esm2015/plugins/custom-info/custom-info.spec.js +90 -90
  78. package/esm2015/plugins/fetch-cache/fetch-cache.spec.js +100 -98
  79. package/esm2015/plugins/fetch-credentials/fetch-credentials.spec.js +60 -60
  80. package/esm2015/plugins/json-token/json-token.spec.js +109 -107
  81. package/esm2015/plugins/keepalive/keepalive.request.js +7 -12
  82. package/esm2015/plugins/keepalive/keepalive.spec.js +32 -34
  83. package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.helpers.js +8 -20
  84. package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.request.js +18 -28
  85. package/esm2015/plugins/mgw-mdw-auth/mgw-mdw-auth.spec.js +212 -204
  86. package/esm2015/plugins/mock-intercept/mock-intercept.angular.js +94 -100
  87. package/esm2015/plugins/mock-intercept/mock-intercept.fetch.js +15 -22
  88. package/esm2015/plugins/mock-intercept/mock-intercept.request.js +12 -19
  89. package/esm2015/plugins/mock-intercept/mock-intercept.spec.js +245 -237
  90. package/esm2015/plugins/perf-metric/perf-metric.fetch.js +11 -18
  91. package/esm2015/plugins/pii-tokenizer/pii-tokenizer.request.js +15 -23
  92. package/esm2015/plugins/pii-tokenizer/pii-tokenizer.spec.js +404 -386
  93. package/esm2015/plugins/raw-response-info/raw-response-info.spec.js +67 -67
  94. package/esm2015/plugins/retry/retry.fetch.js +18 -27
  95. package/esm2015/plugins/retry/retry.spec.js +233 -225
  96. package/esm2015/plugins/reviver/reviver.spec.js +88 -86
  97. package/esm2015/plugins/session-id/session-id.spec.js +98 -94
  98. package/esm2015/plugins/si-token/si-token.spec.js +27 -29
  99. package/esm2015/plugins/simple-api-key-authentication/simple-api-key-authentication.request.js +17 -24
  100. package/esm2015/plugins/simple-api-key-authentication/simple-api-key-authentication.spec.js +199 -191
  101. package/esm2015/plugins/timeout/timeout.fetch.js +13 -19
  102. package/esm2015/plugins/timeout/timeout.spec.js +211 -205
  103. package/esm2015/plugins/url-rewrite/url-rewrite.request.js +9 -16
  104. package/esm2015/plugins/url-rewrite/url-rewrite.spec.js +48 -48
  105. package/esm2015/plugins/wait-for/wait-for.fetch.js +19 -29
  106. package/esm2015/plugins/wait-for/wait-for.spec.js +211 -203
  107. package/esm2015/utils/crypto.js +8 -20
  108. package/esm2015/utils/generic-api.js +9 -14
  109. package/esm2015/utils/json-token.js +10 -17
  110. package/esm2015/utils/json-token.spec.js +495 -497
  111. package/package.json +6 -6
@@ -80,7 +80,7 @@ function _object_spread_props(target, source) {
80
80
  return target;
81
81
  }
82
82
  function _ts_generator(thisArg, body) {
83
- var f, y, t, g, _ = {
83
+ var f, y, t, _ = {
84
84
  label: 0,
85
85
  sent: function() {
86
86
  if (t[0] & 1) throw t[1];
@@ -88,12 +88,8 @@ function _ts_generator(thisArg, body) {
88
88
  },
89
89
  trys: [],
90
90
  ops: []
91
- };
92
- return g = {
93
- next: verb(0),
94
- "throw": verb(1),
95
- "return": verb(2)
96
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
91
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
92
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
97
93
  return this;
98
94
  }), g;
99
95
  function verb(n) {
@@ -106,7 +102,7 @@ function _ts_generator(thisArg, body) {
106
102
  }
107
103
  function step(op) {
108
104
  if (f) throw new TypeError("Generator is already executing.");
109
- while(_)try {
105
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
110
106
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
111
107
  if (y = 0, t) op = [
112
108
  op[0] & 2,
@@ -204,382 +200,404 @@ describe('Tokenizer Request Plugin', function() {
204
200
  afterEach(function() {
205
201
  jest.restoreAllMocks();
206
202
  });
207
- it('should replace sensitive parameters with tokens', /*#__PURE__*/ _async_to_generator(function() {
208
- var plugin, runner, result;
209
- return _ts_generator(this, function(_state) {
210
- switch(_state.label){
211
- case 0:
212
- plugin = new PiiTokenizerRequest({
213
- applicationId: 'app-id'
214
- });
215
- runner = plugin.load();
216
- return [
217
- 4,
218
- runner.transform(_object_spread_props(_object_spread({}, options), {
219
- tokenizedOptions: tokenizedOptions
220
- }))
221
- ];
222
- case 1:
223
- result = _state.sent();
224
- expect(result.basePath).toEqual('http://test.com/path/$pathParamToken$');
225
- expect(result.queryParams.classicParam).toEqual('classicParamValue');
226
- expect(result.queryParams.sensitiveParam).toEqual('$sensitiveParamToken$');
227
- expect(result.headers.get('ama-client-facts')).not.toBeNull();
228
- return [
229
- 2
230
- ];
231
- }
232
- });
233
- }));
234
- it('should put token-value associations in custom header if provided', /*#__PURE__*/ _async_to_generator(function() {
235
- var plugin, runner, result;
236
- return _ts_generator(this, function(_state) {
237
- switch(_state.label){
238
- case 0:
239
- plugin = new PiiTokenizerRequest({
240
- applicationId: 'app-id',
241
- headerName: 'custom-header'
242
- });
243
- runner = plugin.load();
244
- return [
245
- 4,
246
- runner.transform(_object_spread_props(_object_spread({}, options), {
247
- tokenizedOptions: tokenizedOptions
248
- }))
249
- ];
250
- case 1:
251
- result = _state.sent();
252
- expect(result.headers.get('ama-client-facts')).toBeNull();
253
- expect(result.headers.get('custom-header')).not.toBeNull();
254
- return [
255
- 2
256
- ];
257
- }
258
- });
259
- }));
260
- it('should keep default parameters and print an error if tokenization is disabled', /*#__PURE__*/ _async_to_generator(function() {
261
- var plugin, runner, result;
262
- return _ts_generator(this, function(_state) {
263
- switch(_state.label){
264
- case 0:
265
- plugin = new PiiTokenizerRequest({
266
- applicationId: 'app-id'
267
- });
268
- runner = plugin.load();
269
- return [
270
- 4,
271
- runner.transform(options)
272
- ];
273
- case 1:
274
- result = _state.sent();
275
- expect(result.basePath).toEqual('http://test.com/path/pathParamValue');
276
- expect(result.queryParams.classicParam).toEqual('classicParamValue');
277
- expect(result.queryParams.sensitiveParam).toEqual('sensitiveParamValue');
278
- expect(result.headers.get('ama-client-facts')).toBeNull();
279
- // eslint-disable-next-line no-console -- not calling console.error but expect if it has been called or not
280
- expect(console.error).toHaveBeenCalled();
281
- return [
282
- 2
283
- ];
284
- }
285
- });
286
- }));
287
- it('should keep default parameters if no token-value associations is provided', /*#__PURE__*/ _async_to_generator(function() {
288
- var plugin, runner, result;
289
- return _ts_generator(this, function(_state) {
290
- switch(_state.label){
291
- case 0:
292
- plugin = new PiiTokenizerRequest({
293
- applicationId: 'app-id'
294
- });
295
- runner = plugin.load();
296
- return [
297
- 4,
298
- runner.transform(_object_spread_props(_object_spread({}, options), {
299
- tokenizedOptions: _object_spread_props(_object_spread({}, tokenizedOptions), {
300
- values: {}
301
- })
302
- }))
303
- ];
304
- case 1:
305
- result = _state.sent();
306
- expect(result.basePath).toEqual('http://test.com/path/pathParamValue');
307
- expect(result.queryParams.classicParam).toEqual('classicParamValue');
308
- expect(result.queryParams.sensitiveParam).toEqual('sensitiveParamValue');
309
- expect(result.headers.get('ama-client-facts')).toBeNull();
310
- // eslint-disable-next-line no-console -- not calling console.error but expect if it has been called or not
311
- expect(console.error).not.toHaveBeenCalled();
312
- return [
313
- 2
314
- ];
315
- }
316
- });
317
- }));
318
- it('should use JWT if no key specified', /*#__PURE__*/ _async_to_generator(function() {
319
- var mockJweEncoder, mockJwtEncoder, plugin, runner;
320
- return _ts_generator(this, function(_state) {
321
- switch(_state.label){
322
- case 0:
323
- mockJweEncoder = jest.spyOn(jsonToken, 'createJweEncoder');
324
- mockJwtEncoder = jest.spyOn(jsonToken, 'createJwtEncoder');
325
- plugin = new PiiTokenizerRequest({
326
- applicationId: 'app-id'
327
- });
328
- runner = plugin.load();
329
- return [
330
- 4,
331
- runner.transform(_object_spread_props(_object_spread({}, options), {
332
- tokenizedOptions: tokenizedOptions
333
- }))
334
- ];
335
- case 1:
336
- _state.sent();
337
- expect(mockJweEncoder).not.toHaveBeenCalled();
338
- expect(mockJwtEncoder).toHaveBeenCalled();
339
- return [
340
- 2
341
- ];
342
- }
343
- });
344
- }));
345
- it('should use JWE if a key is specified', /*#__PURE__*/ _async_to_generator(function() {
346
- var key, mockJweEncoder, mockJwtEncoder, plugin, runner, result, expectedJwePayload;
347
- return _ts_generator(this, function(_state) {
348
- switch(_state.label){
349
- case 0:
350
- jest.spyOn(Date, 'now').mockImplementation(function() {
351
- return 0;
352
- });
353
- key = {
354
- publicKey: 'myPublicKey',
355
- keyId: 'TEST'
356
- };
357
- mockJweEncoder = jest.fn().mockResolvedValue('myJweToken');
358
- jest.spyOn(jsonToken, 'createJweEncoder').mockImplementation(function() {
359
- return mockJweEncoder;
360
- });
361
- mockJwtEncoder = jest.spyOn(jsonToken, 'createJwtEncoder');
362
- plugin = new PiiTokenizerRequest({
363
- applicationId: 'app-id',
364
- key: key
365
- });
366
- runner = plugin.load();
367
- return [
368
- 4,
369
- runner.transform(_object_spread_props(_object_spread({}, options), {
370
- tokenizedOptions: tokenizedOptions
371
- }))
372
- ];
373
- case 1:
374
- result = _state.sent();
375
- expectedJwePayload = {
376
- 'ama-tokens': {
377
- $pathParamToken$: 'pathParamValue',
378
- $sensitiveParamToken$: 'sensitiveParamValue'
379
- },
380
- exp: 3600,
381
- iat: 0,
382
- iss: 'app-id',
383
- sub: 'pii'
384
- };
385
- expect(result.headers.get('ama-client-facts')).toEqual('myJweToken');
386
- expect(mockJweEncoder).toHaveBeenCalledWith(key, expectedJwePayload, [
387
- 'iss',
388
- 'sub'
389
- ]);
390
- expect(mockJwtEncoder).not.toHaveBeenCalled();
391
- return [
392
- 2
393
- ];
394
- }
395
- });
396
- }));
397
- it('should throw by default if an exception is raised for JWE encoder', /*#__PURE__*/ _async_to_generator(function() {
398
- var key, mockJweEncoder, plugin, runner;
399
- return _ts_generator(this, function(_state) {
400
- switch(_state.label){
401
- case 0:
402
- key = {
403
- publicKey: 'myPublicKey',
404
- keyId: 'TEST'
405
- };
406
- mockJweEncoder = jest.fn().mockRejectedValue('Error creating JWE');
407
- jest.spyOn(jsonToken, 'createJweEncoder').mockImplementation(function() {
408
- return mockJweEncoder;
409
- });
410
- plugin = new PiiTokenizerRequest({
411
- applicationId: 'app-id',
412
- key: key
413
- });
414
- runner = plugin.load();
415
- return [
416
- 4,
417
- expect(runner.transform(_object_spread_props(_object_spread({}, options), {
418
- tokenizedOptions: tokenizedOptions
419
- }))).rejects.toThrow()
420
- ];
421
- case 1:
422
- _state.sent();
423
- expect(mockJweEncoder).toHaveBeenCalled();
424
- // eslint-disable-next-line no-console -- not calling console.error but expect if it has been called or not
425
- expect(console.error).not.toHaveBeenCalled();
426
- return [
427
- 2
428
- ];
429
- }
430
- });
431
- }));
432
- it('should handle errors silently if an exception is raised for JWE encoder', /*#__PURE__*/ _async_to_generator(function() {
433
- var key, mockJweEncoder, plugin, runner;
434
- return _ts_generator(this, function(_state) {
435
- switch(_state.label){
436
- case 0:
437
- key = {
438
- publicKey: 'myPublicKey',
439
- keyId: 'TEST'
440
- };
441
- mockJweEncoder = jest.fn().mockRejectedValue('Error creating JWE');
442
- jest.spyOn(jsonToken, 'createJweEncoder').mockImplementation(function() {
443
- return mockJweEncoder;
444
- });
445
- plugin = new PiiTokenizerRequest({
446
- applicationId: 'app-id',
447
- key: key,
448
- silent: true
449
- });
450
- runner = plugin.load();
451
- return [
452
- 4,
453
- expect(runner.transform(_object_spread_props(_object_spread({}, options), {
454
- tokenizedOptions: tokenizedOptions
455
- }))).resolves.toBeDefined()
456
- ];
457
- case 1:
458
- _state.sent();
459
- expect(mockJweEncoder).toHaveBeenCalled();
460
- // eslint-disable-next-line no-console -- not calling console.error but expect if it has been called or not
461
- expect(console.error).toHaveBeenCalled();
462
- return [
463
- 2
464
- ];
465
- }
466
- });
467
- }));
468
- it('should skip PII tokenization and put DeepLink token in corresponding header when DeepLink token is provided', /*#__PURE__*/ _async_to_generator(function() {
469
- var plugin, runner, deepLinkOptions, metadata, result;
470
- return _ts_generator(this, function(_state) {
471
- switch(_state.label){
472
- case 0:
473
- plugin = new PiiTokenizerRequest({
474
- applicationId: 'app-id'
475
- });
476
- runner = plugin.load();
477
- deepLinkOptions = {
478
- token: 'myDeepLinkToken'
479
- };
480
- metadata = {
481
- deepLinkOptions: deepLinkOptions
482
- };
483
- options.basePath = 'http://test.com/path/$pathParamToken$';
484
- options.queryParams = {
485
- classicParam: 'classicParamValue',
486
- sensitiveParam: '$sensitiveParamToken$'
487
- };
488
- return [
489
- 4,
490
- runner.transform(_object_spread_props(_object_spread({}, options), {
491
- tokenizedOptions: _object_spread_props(_object_spread({}, tokenizedOptions), {
492
- values: {}
493
- }),
494
- metadata: metadata
495
- }))
496
- ];
497
- case 1:
498
- result = _state.sent();
499
- expect(result.basePath).toEqual('http://test.com/path/$pathParamToken$');
500
- expect(result.queryParams.classicParam).toEqual('classicParamValue');
501
- expect(result.queryParams.sensitiveParam).toEqual('$sensitiveParamToken$');
502
- expect(result.headers.get('ama-client-facts')).toEqual('myDeepLinkToken');
503
- // eslint-disable-next-line no-console -- not calling console.error but expect if it has been called or not
504
- expect(console.error).not.toHaveBeenCalled();
505
- return [
506
- 2
507
- ];
508
- }
509
- });
510
- }));
511
- it('should put DeepLink challenge answers in corresponding header when provided', /*#__PURE__*/ _async_to_generator(function() {
512
- var plugin, runner, deepLinkOptions, metadata, result;
513
- return _ts_generator(this, function(_state) {
514
- switch(_state.label){
515
- case 0:
516
- plugin = new PiiTokenizerRequest({
517
- applicationId: 'app-id'
518
- });
519
- runner = plugin.load();
520
- deepLinkOptions = {
521
- token: 'myDeepLinkToken',
522
- challengeAnswers: {
523
- lastName: 'Doe'
524
- }
525
- };
526
- metadata = {
527
- deepLinkOptions: deepLinkOptions
528
- };
529
- options.basePath = 'http://test.com/path/$pathParamToken$';
530
- options.queryParams = {
531
- classicParam: 'classicParamValue',
532
- sensitiveParam: '$sensitiveParamToken$'
533
- };
534
- return [
535
- 4,
536
- runner.transform(_object_spread_props(_object_spread({}, options), {
537
- tokenizedOptions: _object_spread_props(_object_spread({}, tokenizedOptions), {
538
- values: {}
539
- }),
540
- metadata: metadata
541
- }))
542
- ];
543
- case 1:
544
- result = _state.sent();
545
- expect(result.basePath).toEqual('http://test.com/path/$pathParamToken$');
546
- expect(result.queryParams.classicParam).toEqual('classicParamValue');
547
- expect(result.queryParams.sensitiveParam).toEqual('$sensitiveParamToken$');
548
- expect(result.headers.get('ama-client-facts')).toEqual('myDeepLinkToken');
549
- expect(result.headers.get('ama-client-facts-challenge')).toEqual('{"lastName":"Doe"}');
550
- return [
551
- 2
552
- ];
553
- }
554
- });
555
- }));
556
- it('Should not loose additional parameters not expected for the actual request', /*#__PURE__*/ _async_to_generator(function() {
557
- var plugin, runner, result;
558
- return _ts_generator(this, function(_state) {
559
- switch(_state.label){
560
- case 0:
561
- plugin = new PiiTokenizerRequest({
562
- applicationId: 'app-id'
563
- });
564
- runner = plugin.load();
565
- options.basePath = 'http://test.com/path/pathParamValue';
566
- options.queryParams = _object_spread_props(_object_spread({}, options.queryParams), {
567
- additionalParam: 'foo'
568
- });
569
- return [
570
- 4,
571
- runner.transform(_object_spread_props(_object_spread({}, options), {
572
- tokenizedOptions: tokenizedOptions
573
- }))
574
- ];
575
- case 1:
576
- result = _state.sent();
577
- expect(result.basePath).toEqual('http://test.com/path/$pathParamToken$');
578
- expect(result.queryParams.additionalParam).toEqual('foo');
579
- return [
580
- 2
581
- ];
582
- }
583
- });
584
- }));
203
+ it('should replace sensitive parameters with tokens', function() {
204
+ return _async_to_generator(function() {
205
+ var plugin, runner, result;
206
+ return _ts_generator(this, function(_state) {
207
+ switch(_state.label){
208
+ case 0:
209
+ plugin = new PiiTokenizerRequest({
210
+ applicationId: 'app-id'
211
+ });
212
+ runner = plugin.load();
213
+ return [
214
+ 4,
215
+ runner.transform(_object_spread_props(_object_spread({}, options), {
216
+ tokenizedOptions: tokenizedOptions
217
+ }))
218
+ ];
219
+ case 1:
220
+ result = _state.sent();
221
+ expect(result.basePath).toEqual('http://test.com/path/$pathParamToken$');
222
+ expect(result.queryParams.classicParam).toEqual('classicParamValue');
223
+ expect(result.queryParams.sensitiveParam).toEqual('$sensitiveParamToken$');
224
+ expect(result.headers.get('ama-client-facts')).not.toBeNull();
225
+ return [
226
+ 2
227
+ ];
228
+ }
229
+ });
230
+ })();
231
+ });
232
+ it('should put token-value associations in custom header if provided', function() {
233
+ return _async_to_generator(function() {
234
+ var plugin, runner, result;
235
+ return _ts_generator(this, function(_state) {
236
+ switch(_state.label){
237
+ case 0:
238
+ plugin = new PiiTokenizerRequest({
239
+ applicationId: 'app-id',
240
+ headerName: 'custom-header'
241
+ });
242
+ runner = plugin.load();
243
+ return [
244
+ 4,
245
+ runner.transform(_object_spread_props(_object_spread({}, options), {
246
+ tokenizedOptions: tokenizedOptions
247
+ }))
248
+ ];
249
+ case 1:
250
+ result = _state.sent();
251
+ expect(result.headers.get('ama-client-facts')).toBeNull();
252
+ expect(result.headers.get('custom-header')).not.toBeNull();
253
+ return [
254
+ 2
255
+ ];
256
+ }
257
+ });
258
+ })();
259
+ });
260
+ it('should keep default parameters and print an error if tokenization is disabled', function() {
261
+ return _async_to_generator(function() {
262
+ var plugin, runner, result;
263
+ return _ts_generator(this, function(_state) {
264
+ switch(_state.label){
265
+ case 0:
266
+ plugin = new PiiTokenizerRequest({
267
+ applicationId: 'app-id'
268
+ });
269
+ runner = plugin.load();
270
+ return [
271
+ 4,
272
+ runner.transform(options)
273
+ ];
274
+ case 1:
275
+ result = _state.sent();
276
+ expect(result.basePath).toEqual('http://test.com/path/pathParamValue');
277
+ expect(result.queryParams.classicParam).toEqual('classicParamValue');
278
+ expect(result.queryParams.sensitiveParam).toEqual('sensitiveParamValue');
279
+ expect(result.headers.get('ama-client-facts')).toBeNull();
280
+ // eslint-disable-next-line no-console -- not calling console.error but expect if it has been called or not
281
+ expect(console.error).toHaveBeenCalled();
282
+ return [
283
+ 2
284
+ ];
285
+ }
286
+ });
287
+ })();
288
+ });
289
+ it('should keep default parameters if no token-value associations is provided', function() {
290
+ return _async_to_generator(function() {
291
+ var plugin, runner, result;
292
+ return _ts_generator(this, function(_state) {
293
+ switch(_state.label){
294
+ case 0:
295
+ plugin = new PiiTokenizerRequest({
296
+ applicationId: 'app-id'
297
+ });
298
+ runner = plugin.load();
299
+ return [
300
+ 4,
301
+ runner.transform(_object_spread_props(_object_spread({}, options), {
302
+ tokenizedOptions: _object_spread_props(_object_spread({}, tokenizedOptions), {
303
+ values: {}
304
+ })
305
+ }))
306
+ ];
307
+ case 1:
308
+ result = _state.sent();
309
+ expect(result.basePath).toEqual('http://test.com/path/pathParamValue');
310
+ expect(result.queryParams.classicParam).toEqual('classicParamValue');
311
+ expect(result.queryParams.sensitiveParam).toEqual('sensitiveParamValue');
312
+ expect(result.headers.get('ama-client-facts')).toBeNull();
313
+ // eslint-disable-next-line no-console -- not calling console.error but expect if it has been called or not
314
+ expect(console.error).not.toHaveBeenCalled();
315
+ return [
316
+ 2
317
+ ];
318
+ }
319
+ });
320
+ })();
321
+ });
322
+ it('should use JWT if no key specified', function() {
323
+ return _async_to_generator(function() {
324
+ var mockJweEncoder, mockJwtEncoder, plugin, runner;
325
+ return _ts_generator(this, function(_state) {
326
+ switch(_state.label){
327
+ case 0:
328
+ mockJweEncoder = jest.spyOn(jsonToken, 'createJweEncoder');
329
+ mockJwtEncoder = jest.spyOn(jsonToken, 'createJwtEncoder');
330
+ plugin = new PiiTokenizerRequest({
331
+ applicationId: 'app-id'
332
+ });
333
+ runner = plugin.load();
334
+ return [
335
+ 4,
336
+ runner.transform(_object_spread_props(_object_spread({}, options), {
337
+ tokenizedOptions: tokenizedOptions
338
+ }))
339
+ ];
340
+ case 1:
341
+ _state.sent();
342
+ expect(mockJweEncoder).not.toHaveBeenCalled();
343
+ expect(mockJwtEncoder).toHaveBeenCalled();
344
+ return [
345
+ 2
346
+ ];
347
+ }
348
+ });
349
+ })();
350
+ });
351
+ it('should use JWE if a key is specified', function() {
352
+ return _async_to_generator(function() {
353
+ var key, mockJweEncoder, mockJwtEncoder, plugin, runner, result, expectedJwePayload;
354
+ return _ts_generator(this, function(_state) {
355
+ switch(_state.label){
356
+ case 0:
357
+ jest.spyOn(Date, 'now').mockImplementation(function() {
358
+ return 0;
359
+ });
360
+ key = {
361
+ publicKey: 'myPublicKey',
362
+ keyId: 'TEST'
363
+ };
364
+ mockJweEncoder = jest.fn().mockResolvedValue('myJweToken');
365
+ jest.spyOn(jsonToken, 'createJweEncoder').mockImplementation(function() {
366
+ return mockJweEncoder;
367
+ });
368
+ mockJwtEncoder = jest.spyOn(jsonToken, 'createJwtEncoder');
369
+ plugin = new PiiTokenizerRequest({
370
+ applicationId: 'app-id',
371
+ key: key
372
+ });
373
+ runner = plugin.load();
374
+ return [
375
+ 4,
376
+ runner.transform(_object_spread_props(_object_spread({}, options), {
377
+ tokenizedOptions: tokenizedOptions
378
+ }))
379
+ ];
380
+ case 1:
381
+ result = _state.sent();
382
+ expectedJwePayload = {
383
+ 'ama-tokens': {
384
+ $pathParamToken$: 'pathParamValue',
385
+ $sensitiveParamToken$: 'sensitiveParamValue'
386
+ },
387
+ exp: 3600,
388
+ iat: 0,
389
+ iss: 'app-id',
390
+ sub: 'pii'
391
+ };
392
+ expect(result.headers.get('ama-client-facts')).toEqual('myJweToken');
393
+ expect(mockJweEncoder).toHaveBeenCalledWith(key, expectedJwePayload, [
394
+ 'iss',
395
+ 'sub'
396
+ ]);
397
+ expect(mockJwtEncoder).not.toHaveBeenCalled();
398
+ return [
399
+ 2
400
+ ];
401
+ }
402
+ });
403
+ })();
404
+ });
405
+ it('should throw by default if an exception is raised for JWE encoder', function() {
406
+ return _async_to_generator(function() {
407
+ var key, mockJweEncoder, plugin, runner;
408
+ return _ts_generator(this, function(_state) {
409
+ switch(_state.label){
410
+ case 0:
411
+ key = {
412
+ publicKey: 'myPublicKey',
413
+ keyId: 'TEST'
414
+ };
415
+ mockJweEncoder = jest.fn().mockRejectedValue('Error creating JWE');
416
+ jest.spyOn(jsonToken, 'createJweEncoder').mockImplementation(function() {
417
+ return mockJweEncoder;
418
+ });
419
+ plugin = new PiiTokenizerRequest({
420
+ applicationId: 'app-id',
421
+ key: key
422
+ });
423
+ runner = plugin.load();
424
+ return [
425
+ 4,
426
+ expect(runner.transform(_object_spread_props(_object_spread({}, options), {
427
+ tokenizedOptions: tokenizedOptions
428
+ }))).rejects.toThrow()
429
+ ];
430
+ case 1:
431
+ _state.sent();
432
+ expect(mockJweEncoder).toHaveBeenCalled();
433
+ // eslint-disable-next-line no-console -- not calling console.error but expect if it has been called or not
434
+ expect(console.error).not.toHaveBeenCalled();
435
+ return [
436
+ 2
437
+ ];
438
+ }
439
+ });
440
+ })();
441
+ });
442
+ it('should handle errors silently if an exception is raised for JWE encoder', function() {
443
+ return _async_to_generator(function() {
444
+ var key, mockJweEncoder, plugin, runner;
445
+ return _ts_generator(this, function(_state) {
446
+ switch(_state.label){
447
+ case 0:
448
+ key = {
449
+ publicKey: 'myPublicKey',
450
+ keyId: 'TEST'
451
+ };
452
+ mockJweEncoder = jest.fn().mockRejectedValue('Error creating JWE');
453
+ jest.spyOn(jsonToken, 'createJweEncoder').mockImplementation(function() {
454
+ return mockJweEncoder;
455
+ });
456
+ plugin = new PiiTokenizerRequest({
457
+ applicationId: 'app-id',
458
+ key: key,
459
+ silent: true
460
+ });
461
+ runner = plugin.load();
462
+ return [
463
+ 4,
464
+ expect(runner.transform(_object_spread_props(_object_spread({}, options), {
465
+ tokenizedOptions: tokenizedOptions
466
+ }))).resolves.toBeDefined()
467
+ ];
468
+ case 1:
469
+ _state.sent();
470
+ expect(mockJweEncoder).toHaveBeenCalled();
471
+ // eslint-disable-next-line no-console -- not calling console.error but expect if it has been called or not
472
+ expect(console.error).toHaveBeenCalled();
473
+ return [
474
+ 2
475
+ ];
476
+ }
477
+ });
478
+ })();
479
+ });
480
+ it('should skip PII tokenization and put DeepLink token in corresponding header when DeepLink token is provided', function() {
481
+ return _async_to_generator(function() {
482
+ var plugin, runner, deepLinkOptions, metadata, result;
483
+ return _ts_generator(this, function(_state) {
484
+ switch(_state.label){
485
+ case 0:
486
+ plugin = new PiiTokenizerRequest({
487
+ applicationId: 'app-id'
488
+ });
489
+ runner = plugin.load();
490
+ deepLinkOptions = {
491
+ token: 'myDeepLinkToken'
492
+ };
493
+ metadata = {
494
+ deepLinkOptions: deepLinkOptions
495
+ };
496
+ options.basePath = 'http://test.com/path/$pathParamToken$';
497
+ options.queryParams = {
498
+ classicParam: 'classicParamValue',
499
+ sensitiveParam: '$sensitiveParamToken$'
500
+ };
501
+ return [
502
+ 4,
503
+ runner.transform(_object_spread_props(_object_spread({}, options), {
504
+ tokenizedOptions: _object_spread_props(_object_spread({}, tokenizedOptions), {
505
+ values: {}
506
+ }),
507
+ metadata: metadata
508
+ }))
509
+ ];
510
+ case 1:
511
+ result = _state.sent();
512
+ expect(result.basePath).toEqual('http://test.com/path/$pathParamToken$');
513
+ expect(result.queryParams.classicParam).toEqual('classicParamValue');
514
+ expect(result.queryParams.sensitiveParam).toEqual('$sensitiveParamToken$');
515
+ expect(result.headers.get('ama-client-facts')).toEqual('myDeepLinkToken');
516
+ // eslint-disable-next-line no-console -- not calling console.error but expect if it has been called or not
517
+ expect(console.error).not.toHaveBeenCalled();
518
+ return [
519
+ 2
520
+ ];
521
+ }
522
+ });
523
+ })();
524
+ });
525
+ it('should put DeepLink challenge answers in corresponding header when provided', function() {
526
+ return _async_to_generator(function() {
527
+ var plugin, runner, deepLinkOptions, metadata, result;
528
+ return _ts_generator(this, function(_state) {
529
+ switch(_state.label){
530
+ case 0:
531
+ plugin = new PiiTokenizerRequest({
532
+ applicationId: 'app-id'
533
+ });
534
+ runner = plugin.load();
535
+ deepLinkOptions = {
536
+ token: 'myDeepLinkToken',
537
+ challengeAnswers: {
538
+ lastName: 'Doe'
539
+ }
540
+ };
541
+ metadata = {
542
+ deepLinkOptions: deepLinkOptions
543
+ };
544
+ options.basePath = 'http://test.com/path/$pathParamToken$';
545
+ options.queryParams = {
546
+ classicParam: 'classicParamValue',
547
+ sensitiveParam: '$sensitiveParamToken$'
548
+ };
549
+ return [
550
+ 4,
551
+ runner.transform(_object_spread_props(_object_spread({}, options), {
552
+ tokenizedOptions: _object_spread_props(_object_spread({}, tokenizedOptions), {
553
+ values: {}
554
+ }),
555
+ metadata: metadata
556
+ }))
557
+ ];
558
+ case 1:
559
+ result = _state.sent();
560
+ expect(result.basePath).toEqual('http://test.com/path/$pathParamToken$');
561
+ expect(result.queryParams.classicParam).toEqual('classicParamValue');
562
+ expect(result.queryParams.sensitiveParam).toEqual('$sensitiveParamToken$');
563
+ expect(result.headers.get('ama-client-facts')).toEqual('myDeepLinkToken');
564
+ expect(result.headers.get('ama-client-facts-challenge')).toEqual('{"lastName":"Doe"}');
565
+ return [
566
+ 2
567
+ ];
568
+ }
569
+ });
570
+ })();
571
+ });
572
+ it('Should not loose additional parameters not expected for the actual request', function() {
573
+ return _async_to_generator(function() {
574
+ var plugin, runner, result;
575
+ return _ts_generator(this, function(_state) {
576
+ switch(_state.label){
577
+ case 0:
578
+ plugin = new PiiTokenizerRequest({
579
+ applicationId: 'app-id'
580
+ });
581
+ runner = plugin.load();
582
+ options.basePath = 'http://test.com/path/pathParamValue';
583
+ options.queryParams = _object_spread_props(_object_spread({}, options.queryParams), {
584
+ additionalParam: 'foo'
585
+ });
586
+ return [
587
+ 4,
588
+ runner.transform(_object_spread_props(_object_spread({}, options), {
589
+ tokenizedOptions: tokenizedOptions
590
+ }))
591
+ ];
592
+ case 1:
593
+ result = _state.sent();
594
+ expect(result.basePath).toEqual('http://test.com/path/$pathParamToken$');
595
+ expect(result.queryParams.additionalParam).toEqual('foo');
596
+ return [
597
+ 2
598
+ ];
599
+ }
600
+ });
601
+ })();
602
+ });
585
603
  });