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