@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
@@ -28,7 +28,7 @@ function _async_to_generator(fn) {
28
28
  };
29
29
  }
30
30
  function _ts_generator(thisArg, body) {
31
- var f, y, t, g, _ = {
31
+ var f, y, t, _ = {
32
32
  label: 0,
33
33
  sent: function() {
34
34
  if (t[0] & 1) throw t[1];
@@ -36,12 +36,8 @@ function _ts_generator(thisArg, body) {
36
36
  },
37
37
  trys: [],
38
38
  ops: []
39
- };
40
- return g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
39
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
40
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
41
  return this;
46
42
  }), g;
47
43
  function verb(n) {
@@ -54,7 +50,7 @@ function _ts_generator(thisArg, body) {
54
50
  }
55
51
  function step(op) {
56
52
  if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
53
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
58
54
  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;
59
55
  if (y = 0, t) op = [
60
56
  op[0] & 2,
@@ -131,94 +127,100 @@ describe('Fetch API cache Request Plugin', function() {
131
127
  afterEach(function() {
132
128
  global.fetch = globalFetchBackup;
133
129
  });
134
- it('cache should be set correctly', /*#__PURE__*/ _async_to_generator(function() {
135
- var options, plugin, cache;
136
- return _ts_generator(this, function(_state) {
137
- switch(_state.label){
138
- case 0:
139
- options = {
140
- headers: new Headers(),
141
- basePath: 'http://test.com/truc',
142
- method: 'get'
143
- };
144
- plugin = new FetchCacheRequest('force-cache');
145
- return [
146
- 4,
147
- plugin.load().transform(options)
148
- ];
149
- case 1:
150
- cache = _state.sent().cache;
151
- expect(cache).toBe('force-cache');
152
- return [
153
- 2
154
- ];
155
- }
156
- });
157
- }));
158
- it('should set Cache-Control and Pragma header to no-cache in the request', /*#__PURE__*/ _async_to_generator(function() {
159
- var options, plugin, headerCacheControl, headerPragma;
160
- return _ts_generator(this, function(_state) {
161
- switch(_state.label){
162
- case 0:
163
- options = {
164
- headers: new Headers(),
165
- basePath: 'http://test.com/truc',
166
- method: 'get'
167
- };
168
- global.fetch = {
169
- polyfill: true
170
- };
171
- plugin = new FetchCacheRequest('force-cache', 'no-cache');
172
- return [
173
- 4,
174
- plugin.load().transform(options)
175
- ];
176
- case 1:
177
- headerCacheControl = _state.sent().headers.get('Cache-Control');
178
- return [
179
- 4,
180
- plugin.load().transform(options)
181
- ];
182
- case 2:
183
- headerPragma = _state.sent().headers.get('Pragma');
184
- expect(headerCacheControl).toEqual('no-cache');
185
- expect(headerPragma).toEqual('no-cache');
186
- return [
187
- 2
188
- ];
189
- }
190
- });
191
- }));
192
- it('should not set Cache-Control header in the request', /*#__PURE__*/ _async_to_generator(function() {
193
- var options, plugin, headerCacheControl, headerPragma;
194
- return _ts_generator(this, function(_state) {
195
- switch(_state.label){
196
- case 0:
197
- options = {
198
- headers: new Headers(),
199
- basePath: 'http://test.com/truc',
200
- method: 'get'
201
- };
202
- global.fetch = function() {};
203
- plugin = new FetchCacheRequest('force-cache', 'no-cache');
204
- return [
205
- 4,
206
- plugin.load().transform(options)
207
- ];
208
- case 1:
209
- headerCacheControl = _state.sent().headers.get('Cache-Control');
210
- return [
211
- 4,
212
- plugin.load().transform(options)
213
- ];
214
- case 2:
215
- headerPragma = _state.sent().headers.get('Pragma');
216
- expect(headerCacheControl).toBeNull();
217
- expect(headerPragma).toBeNull();
218
- return [
219
- 2
220
- ];
221
- }
222
- });
223
- }));
130
+ it('cache should be set correctly', function() {
131
+ return _async_to_generator(function() {
132
+ var options, plugin, cache;
133
+ return _ts_generator(this, function(_state) {
134
+ switch(_state.label){
135
+ case 0:
136
+ options = {
137
+ headers: new Headers(),
138
+ basePath: 'http://test.com/truc',
139
+ method: 'get'
140
+ };
141
+ plugin = new FetchCacheRequest('force-cache');
142
+ return [
143
+ 4,
144
+ plugin.load().transform(options)
145
+ ];
146
+ case 1:
147
+ cache = _state.sent().cache;
148
+ expect(cache).toBe('force-cache');
149
+ return [
150
+ 2
151
+ ];
152
+ }
153
+ });
154
+ })();
155
+ });
156
+ it('should set Cache-Control and Pragma header to no-cache in the request', function() {
157
+ return _async_to_generator(function() {
158
+ var options, plugin, headerCacheControl, headerPragma;
159
+ return _ts_generator(this, function(_state) {
160
+ switch(_state.label){
161
+ case 0:
162
+ options = {
163
+ headers: new Headers(),
164
+ basePath: 'http://test.com/truc',
165
+ method: 'get'
166
+ };
167
+ global.fetch = {
168
+ polyfill: true
169
+ };
170
+ plugin = new FetchCacheRequest('force-cache', 'no-cache');
171
+ return [
172
+ 4,
173
+ plugin.load().transform(options)
174
+ ];
175
+ case 1:
176
+ headerCacheControl = _state.sent().headers.get('Cache-Control');
177
+ return [
178
+ 4,
179
+ plugin.load().transform(options)
180
+ ];
181
+ case 2:
182
+ headerPragma = _state.sent().headers.get('Pragma');
183
+ expect(headerCacheControl).toEqual('no-cache');
184
+ expect(headerPragma).toEqual('no-cache');
185
+ return [
186
+ 2
187
+ ];
188
+ }
189
+ });
190
+ })();
191
+ });
192
+ it('should not set Cache-Control header in the request', function() {
193
+ return _async_to_generator(function() {
194
+ var options, plugin, headerCacheControl, headerPragma;
195
+ return _ts_generator(this, function(_state) {
196
+ switch(_state.label){
197
+ case 0:
198
+ options = {
199
+ headers: new Headers(),
200
+ basePath: 'http://test.com/truc',
201
+ method: 'get'
202
+ };
203
+ global.fetch = function() {};
204
+ plugin = new FetchCacheRequest('force-cache', 'no-cache');
205
+ return [
206
+ 4,
207
+ plugin.load().transform(options)
208
+ ];
209
+ case 1:
210
+ headerCacheControl = _state.sent().headers.get('Cache-Control');
211
+ return [
212
+ 4,
213
+ plugin.load().transform(options)
214
+ ];
215
+ case 2:
216
+ headerPragma = _state.sent().headers.get('Pragma');
217
+ expect(headerCacheControl).toBeNull();
218
+ expect(headerPragma).toBeNull();
219
+ return [
220
+ 2
221
+ ];
222
+ }
223
+ });
224
+ })();
225
+ });
224
226
  });
@@ -28,7 +28,7 @@ function _async_to_generator(fn) {
28
28
  };
29
29
  }
30
30
  function _ts_generator(thisArg, body) {
31
- var f, y, t, g, _ = {
31
+ var f, y, t, _ = {
32
32
  label: 0,
33
33
  sent: function() {
34
34
  if (t[0] & 1) throw t[1];
@@ -36,12 +36,8 @@ function _ts_generator(thisArg, body) {
36
36
  },
37
37
  trys: [],
38
38
  ops: []
39
- };
40
- return g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
39
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
40
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
41
  return this;
46
42
  }), g;
47
43
  function verb(n) {
@@ -54,7 +50,7 @@ function _ts_generator(thisArg, body) {
54
50
  }
55
51
  function step(op) {
56
52
  if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
53
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
58
54
  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;
59
55
  if (y = 0, t) op = [
60
56
  op[0] & 2,
@@ -129,56 +125,60 @@ describe('Fetch API credentials Request Plugin', function() {
129
125
  basePath: 'http://test.com/truc',
130
126
  method: 'get'
131
127
  };
132
- it('credentials should be set to same-origin by default', /*#__PURE__*/ _async_to_generator(function() {
133
- var plugin, runner, _ref, cred;
134
- return _ts_generator(this, function(_state) {
135
- switch(_state.label){
136
- case 0:
137
- plugin = new FetchCredentialsRequest();
138
- runner = plugin.load();
139
- return [
140
- 4,
141
- runner.transform(options)
142
- ];
143
- case 1:
144
- _state.sent();
145
- return [
146
- 4,
147
- plugin.load().transform(options)
148
- ];
149
- case 2:
150
- _ref = _state.sent(), cred = _ref.credentials;
151
- expect(cred).toBe('same-origin');
152
- return [
153
- 2
154
- ];
155
- }
156
- });
157
- }));
158
- it('credentials should be set correctly', /*#__PURE__*/ _async_to_generator(function() {
159
- var plugin, runner, _ref, cred;
160
- return _ts_generator(this, function(_state) {
161
- switch(_state.label){
162
- case 0:
163
- plugin = new FetchCredentialsRequest('include');
164
- runner = plugin.load();
165
- return [
166
- 4,
167
- runner.transform(options)
168
- ];
169
- case 1:
170
- _state.sent();
171
- return [
172
- 4,
173
- plugin.load().transform(options)
174
- ];
175
- case 2:
176
- _ref = _state.sent(), cred = _ref.credentials;
177
- expect(cred).toBe('include');
178
- return [
179
- 2
180
- ];
181
- }
182
- });
183
- }));
128
+ it('credentials should be set to same-origin by default', function() {
129
+ return _async_to_generator(function() {
130
+ var plugin, runner, _ref, cred;
131
+ return _ts_generator(this, function(_state) {
132
+ switch(_state.label){
133
+ case 0:
134
+ plugin = new FetchCredentialsRequest();
135
+ runner = plugin.load();
136
+ return [
137
+ 4,
138
+ runner.transform(options)
139
+ ];
140
+ case 1:
141
+ _state.sent();
142
+ return [
143
+ 4,
144
+ plugin.load().transform(options)
145
+ ];
146
+ case 2:
147
+ _ref = _state.sent(), cred = _ref.credentials;
148
+ expect(cred).toBe('same-origin');
149
+ return [
150
+ 2
151
+ ];
152
+ }
153
+ });
154
+ })();
155
+ });
156
+ it('credentials should be set correctly', function() {
157
+ return _async_to_generator(function() {
158
+ var plugin, runner, _ref, cred;
159
+ return _ts_generator(this, function(_state) {
160
+ switch(_state.label){
161
+ case 0:
162
+ plugin = new FetchCredentialsRequest('include');
163
+ runner = plugin.load();
164
+ return [
165
+ 4,
166
+ runner.transform(options)
167
+ ];
168
+ case 1:
169
+ _state.sent();
170
+ return [
171
+ 4,
172
+ plugin.load().transform(options)
173
+ ];
174
+ case 2:
175
+ _ref = _state.sent(), cred = _ref.credentials;
176
+ expect(cred).toBe('include');
177
+ return [
178
+ 2
179
+ ];
180
+ }
181
+ });
182
+ })();
183
+ });
184
184
  });
@@ -28,7 +28,7 @@ function _async_to_generator(fn) {
28
28
  };
29
29
  }
30
30
  function _ts_generator(thisArg, body) {
31
- var f, y, t, g, _ = {
31
+ var f, y, t, _ = {
32
32
  label: 0,
33
33
  sent: function() {
34
34
  if (t[0] & 1) throw t[1];
@@ -36,12 +36,8 @@ function _ts_generator(thisArg, body) {
36
36
  },
37
37
  trys: [],
38
38
  ops: []
39
- };
40
- return g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
39
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
40
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
41
  return this;
46
42
  }), g;
47
43
  function verb(n) {
@@ -54,7 +50,7 @@ function _ts_generator(thisArg, body) {
54
50
  }
55
51
  function step(op) {
56
52
  if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
53
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
58
54
  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;
59
55
  if (y = 0, t) op = [
60
56
  op[0] & 2,
@@ -143,108 +139,114 @@ describe('Json Token', function() {
143
139
  basePath: 'http://test.com/truc'
144
140
  };
145
141
  });
146
- it('should add Authorization header', /*#__PURE__*/ _async_to_generator(function() {
147
- var memory, plugin, runner, result;
148
- return _ts_generator(this, function(_state) {
149
- switch(_state.label){
150
- case 0:
151
- memory = {
152
- testToken: tokenValue
153
- };
154
- plugin = new JsonTokenRequest(tokenKey, memory);
155
- runner = plugin.load();
156
- if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
157
- jest.spyOn(window.sessionStorage, 'getItem').mockImplementation(function() {
158
- return tokenValue;
159
- });
160
- }
161
- return [
162
- 4,
163
- runner.transform(options)
164
- ];
165
- case 1:
166
- result = _state.sent();
167
- if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
168
- /* eslint-disable jest/no-conditional-expect -- the same condition is verified above to set up the checked spy */ expect(window.sessionStorage.getItem).toHaveBeenCalledWith(tokenKey);
169
- /* eslint-enable jest/no-conditional-expect */ }
170
- expect(result.credentials).toBe('same-origin');
171
- expect(result.headers.get('Authorization')).toBe(tokenValue);
172
- return [
173
- 2
174
- ];
175
- }
176
- });
177
- }));
178
- it('should not add Authorization if no token', /*#__PURE__*/ _async_to_generator(function() {
179
- var memory, plugin, runner, result;
180
- return _ts_generator(this, function(_state) {
181
- switch(_state.label){
182
- case 0:
183
- memory = {
184
- testToken: undefined
185
- };
186
- plugin = new JsonTokenRequest(tokenKey, memory);
187
- runner = plugin.load();
188
- if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
189
- jest.spyOn(window.sessionStorage, 'getItem').mockImplementation();
190
- }
191
- return [
192
- 4,
193
- runner.transform(options)
194
- ];
195
- case 1:
196
- result = _state.sent();
197
- if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
198
- /* eslint-disable jest/no-conditional-expect -- the same condition is verified above to set up the checked spy */ expect(window.sessionStorage.getItem).toHaveBeenCalledWith(tokenKey);
199
- /* eslint-enable jest/no-conditional-expect */ }
200
- expect(result.credentials).toBeUndefined();
201
- expect(result.headers.get('Authorization')).toBeNull();
202
- return [
203
- 2
204
- ];
205
- }
206
- });
207
- }));
142
+ it('should add Authorization header', function() {
143
+ return _async_to_generator(function() {
144
+ var memory, plugin, runner, result;
145
+ return _ts_generator(this, function(_state) {
146
+ switch(_state.label){
147
+ case 0:
148
+ memory = {
149
+ testToken: tokenValue
150
+ };
151
+ plugin = new JsonTokenRequest(tokenKey, memory);
152
+ runner = plugin.load();
153
+ if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
154
+ jest.spyOn(window.sessionStorage, 'getItem').mockImplementation(function() {
155
+ return tokenValue;
156
+ });
157
+ }
158
+ return [
159
+ 4,
160
+ runner.transform(options)
161
+ ];
162
+ case 1:
163
+ result = _state.sent();
164
+ if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
165
+ /* eslint-disable jest/no-conditional-expect -- the same condition is verified above to set up the checked spy */ expect(window.sessionStorage.getItem).toHaveBeenCalledWith(tokenKey);
166
+ /* eslint-enable jest/no-conditional-expect */ }
167
+ expect(result.credentials).toBe('same-origin');
168
+ expect(result.headers.get('Authorization')).toBe(tokenValue);
169
+ return [
170
+ 2
171
+ ];
172
+ }
173
+ });
174
+ })();
175
+ });
176
+ it('should not add Authorization if no token', function() {
177
+ return _async_to_generator(function() {
178
+ var memory, plugin, runner, result;
179
+ return _ts_generator(this, function(_state) {
180
+ switch(_state.label){
181
+ case 0:
182
+ memory = {
183
+ testToken: undefined
184
+ };
185
+ plugin = new JsonTokenRequest(tokenKey, memory);
186
+ runner = plugin.load();
187
+ if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
188
+ jest.spyOn(window.sessionStorage, 'getItem').mockImplementation();
189
+ }
190
+ return [
191
+ 4,
192
+ runner.transform(options)
193
+ ];
194
+ case 1:
195
+ result = _state.sent();
196
+ if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
197
+ /* eslint-disable jest/no-conditional-expect -- the same condition is verified above to set up the checked spy */ expect(window.sessionStorage.getItem).toHaveBeenCalledWith(tokenKey);
198
+ /* eslint-enable jest/no-conditional-expect */ }
199
+ expect(result.credentials).toBeUndefined();
200
+ expect(result.headers.get('Authorization')).toBeNull();
201
+ return [
202
+ 2
203
+ ];
204
+ }
205
+ });
206
+ })();
207
+ });
208
208
  });
209
209
  describe('reply plugin', function() {
210
210
  var reviver = jest.fn();
211
- it('should store the received token', /*#__PURE__*/ _async_to_generator(function() {
212
- var memory, plugin, runner, data;
213
- return _ts_generator(this, function(_state) {
214
- switch(_state.label){
215
- case 0:
216
- memory = {
217
- testToken: undefined
218
- };
219
- plugin = new JsonTokenReply(tokenKey, memory);
220
- runner = plugin.load({
221
- reviver: reviver,
222
- apiType: ApiTypes.DEFAULT,
223
- response: {
224
- headers: new Headers({
225
- Authorization: tokenValue
226
- })
211
+ it('should store the received token', function() {
212
+ return _async_to_generator(function() {
213
+ var memory, plugin, runner, data;
214
+ return _ts_generator(this, function(_state) {
215
+ switch(_state.label){
216
+ case 0:
217
+ memory = {
218
+ testToken: undefined
219
+ };
220
+ plugin = new JsonTokenReply(tokenKey, memory);
221
+ runner = plugin.load({
222
+ reviver: reviver,
223
+ apiType: ApiTypes.DEFAULT,
224
+ response: {
225
+ headers: new Headers({
226
+ Authorization: tokenValue
227
+ })
228
+ }
229
+ });
230
+ data = {};
231
+ if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
232
+ jest.spyOn(window.sessionStorage, 'setItem').mockImplementation();
227
233
  }
228
- });
229
- data = {};
230
- if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
231
- jest.spyOn(window.sessionStorage, 'setItem').mockImplementation();
232
- }
233
- return [
234
- 4,
235
- runner.transform(data)
236
- ];
237
- case 1:
238
- _state.sent();
239
- if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
240
- /* eslint-disable jest/no-conditional-expect -- the same condition is verified above to set up the checked spy */ expect(window.sessionStorage.setItem).toHaveBeenCalledWith(tokenKey, tokenValue);
241
- /* eslint-enable jest/no-conditional-expect */ }
242
- expect(memory.testToken).toBe(tokenValue);
243
- return [
244
- 2
245
- ];
246
- }
247
- });
248
- }));
234
+ return [
235
+ 4,
236
+ runner.transform(data)
237
+ ];
238
+ case 1:
239
+ _state.sent();
240
+ if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
241
+ /* eslint-disable jest/no-conditional-expect -- the same condition is verified above to set up the checked spy */ expect(window.sessionStorage.setItem).toHaveBeenCalledWith(tokenKey, tokenValue);
242
+ /* eslint-enable jest/no-conditional-expect */ }
243
+ expect(memory.testToken).toBe(tokenValue);
244
+ return [
245
+ 2
246
+ ];
247
+ }
248
+ });
249
+ })();
250
+ });
249
251
  });
250
252
  });