@ama-sdk/core 10.3.0-prerelease.66 → 10.3.0-prerelease.67
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 +4 -4
- package/cjs/clients/api-beacon-client.js +4 -4
- package/cjs/clients/api-fetch-client.js +4 -4
- package/cjs/fwk/api.helper.spec.js +20 -20
- package/cjs/fwk/api.helpers.js +13 -13
- 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 +4 -4
- package/cjs/utils/json-token.js +30 -30
- package/cjs/utils/json-token.spec.js +31 -31
- package/esm2015/clients/api-angular-client.js +8 -8
- package/esm2015/clients/api-beacon-client.js +5 -5
- package/esm2015/clients/api-fetch-client.js +8 -8
- package/esm2015/clients/index.js +2 -2
- package/esm2015/fwk/api.helper.spec.js +21 -21
- package/esm2015/fwk/api.helpers.js +13 -13
- 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 +5 -5
- package/esm2015/utils/index.js +6 -6
- package/esm2015/utils/json-token.js +32 -32
- package/esm2015/utils/json-token.spec.js +32 -32
- package/package.json +5 -5
|
@@ -94,7 +94,7 @@ var FetchCacheRequest = /*#__PURE__*/ function() {
|
|
|
94
94
|
*/ _define_property(this, "shouldAddCacheControlHeaders", void 0);
|
|
95
95
|
this.fetchCache = fetchCache;
|
|
96
96
|
this.cacheControl = cacheControl;
|
|
97
|
-
this.shouldAddCacheControlHeaders = typeof shouldAddCacheControlHeaders !==
|
|
97
|
+
this.shouldAddCacheControlHeaders = typeof shouldAddCacheControlHeaders !== 'undefined' ? shouldAddCacheControlHeaders : typeof fetch === 'undefined' || fetch.polyfill;
|
|
98
98
|
}
|
|
99
99
|
_create_class(FetchCacheRequest, [
|
|
100
100
|
{
|
|
@@ -104,9 +104,9 @@ var FetchCacheRequest = /*#__PURE__*/ function() {
|
|
|
104
104
|
return {
|
|
105
105
|
transform: function(data) {
|
|
106
106
|
if (_this.cacheControl && _this.shouldAddCacheControlHeaders) {
|
|
107
|
-
data.headers.set(
|
|
108
|
-
if (_this.cacheControl ===
|
|
109
|
-
data.headers.set(
|
|
107
|
+
data.headers.set('Cache-Control', "".concat(_this.cacheControl));
|
|
108
|
+
if (_this.cacheControl === 'no-cache') {
|
|
109
|
+
data.headers.set('Pragma', 'no-cache');
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
return _object_spread_props(_object_spread({}, data), {
|
|
@@ -127,7 +127,7 @@ function _ts_generator(thisArg, body) {
|
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
describe(
|
|
130
|
+
describe('Fetch API cache Request Plugin', function() {
|
|
131
131
|
var globalFetchBackup;
|
|
132
132
|
beforeEach(function() {
|
|
133
133
|
globalFetchBackup = fetch;
|
|
@@ -135,88 +135,88 @@ describe("Fetch API cache Request Plugin", function() {
|
|
|
135
135
|
afterEach(function() {
|
|
136
136
|
global.fetch = globalFetchBackup;
|
|
137
137
|
});
|
|
138
|
-
it(
|
|
138
|
+
it('cache should be set correctly', /*#__PURE__*/ _async_to_generator(function() {
|
|
139
139
|
var options, plugin, cache;
|
|
140
140
|
return _ts_generator(this, function(_state) {
|
|
141
141
|
switch(_state.label){
|
|
142
142
|
case 0:
|
|
143
143
|
options = {
|
|
144
144
|
headers: new Headers(),
|
|
145
|
-
basePath:
|
|
146
|
-
method:
|
|
145
|
+
basePath: 'http://test.com/truc',
|
|
146
|
+
method: 'get'
|
|
147
147
|
};
|
|
148
|
-
plugin = new _fetchcacherequest.FetchCacheRequest(
|
|
148
|
+
plugin = new _fetchcacherequest.FetchCacheRequest('force-cache');
|
|
149
149
|
return [
|
|
150
150
|
4,
|
|
151
151
|
plugin.load().transform(options)
|
|
152
152
|
];
|
|
153
153
|
case 1:
|
|
154
154
|
cache = _state.sent().cache;
|
|
155
|
-
expect(cache).toBe(
|
|
155
|
+
expect(cache).toBe('force-cache');
|
|
156
156
|
return [
|
|
157
157
|
2
|
|
158
158
|
];
|
|
159
159
|
}
|
|
160
160
|
});
|
|
161
161
|
}));
|
|
162
|
-
it(
|
|
162
|
+
it('should set Cache-Control and Pragma header to no-cache in the request', /*#__PURE__*/ _async_to_generator(function() {
|
|
163
163
|
var options, plugin, headerCacheControl, headerPragma;
|
|
164
164
|
return _ts_generator(this, function(_state) {
|
|
165
165
|
switch(_state.label){
|
|
166
166
|
case 0:
|
|
167
167
|
options = {
|
|
168
168
|
headers: new Headers(),
|
|
169
|
-
basePath:
|
|
170
|
-
method:
|
|
169
|
+
basePath: 'http://test.com/truc',
|
|
170
|
+
method: 'get'
|
|
171
171
|
};
|
|
172
172
|
global.fetch = {
|
|
173
173
|
polyfill: true
|
|
174
174
|
};
|
|
175
|
-
plugin = new _fetchcacherequest.FetchCacheRequest(
|
|
175
|
+
plugin = new _fetchcacherequest.FetchCacheRequest('force-cache', 'no-cache');
|
|
176
176
|
return [
|
|
177
177
|
4,
|
|
178
178
|
plugin.load().transform(options)
|
|
179
179
|
];
|
|
180
180
|
case 1:
|
|
181
|
-
headerCacheControl = _state.sent().headers.get(
|
|
181
|
+
headerCacheControl = _state.sent().headers.get('Cache-Control');
|
|
182
182
|
return [
|
|
183
183
|
4,
|
|
184
184
|
plugin.load().transform(options)
|
|
185
185
|
];
|
|
186
186
|
case 2:
|
|
187
|
-
headerPragma = _state.sent().headers.get(
|
|
188
|
-
expect(headerCacheControl).toEqual(
|
|
189
|
-
expect(headerPragma).toEqual(
|
|
187
|
+
headerPragma = _state.sent().headers.get('Pragma');
|
|
188
|
+
expect(headerCacheControl).toEqual('no-cache');
|
|
189
|
+
expect(headerPragma).toEqual('no-cache');
|
|
190
190
|
return [
|
|
191
191
|
2
|
|
192
192
|
];
|
|
193
193
|
}
|
|
194
194
|
});
|
|
195
195
|
}));
|
|
196
|
-
it(
|
|
196
|
+
it('should not set Cache-Control header in the request', /*#__PURE__*/ _async_to_generator(function() {
|
|
197
197
|
var options, plugin, headerCacheControl, headerPragma;
|
|
198
198
|
return _ts_generator(this, function(_state) {
|
|
199
199
|
switch(_state.label){
|
|
200
200
|
case 0:
|
|
201
201
|
options = {
|
|
202
202
|
headers: new Headers(),
|
|
203
|
-
basePath:
|
|
204
|
-
method:
|
|
203
|
+
basePath: 'http://test.com/truc',
|
|
204
|
+
method: 'get'
|
|
205
205
|
};
|
|
206
206
|
global.fetch = function() {};
|
|
207
|
-
plugin = new _fetchcacherequest.FetchCacheRequest(
|
|
207
|
+
plugin = new _fetchcacherequest.FetchCacheRequest('force-cache', 'no-cache');
|
|
208
208
|
return [
|
|
209
209
|
4,
|
|
210
210
|
plugin.load().transform(options)
|
|
211
211
|
];
|
|
212
212
|
case 1:
|
|
213
|
-
headerCacheControl = _state.sent().headers.get(
|
|
213
|
+
headerCacheControl = _state.sent().headers.get('Cache-Control');
|
|
214
214
|
return [
|
|
215
215
|
4,
|
|
216
216
|
plugin.load().transform(options)
|
|
217
217
|
];
|
|
218
218
|
case 2:
|
|
219
|
-
headerPragma = _state.sent().headers.get(
|
|
219
|
+
headerPragma = _state.sent().headers.get('Pragma');
|
|
220
220
|
expect(headerCacheControl).toBeNull();
|
|
221
221
|
expect(headerPragma).toBeNull();
|
|
222
222
|
return [
|
|
@@ -43,7 +43,7 @@ function _define_property(obj, key, value) {
|
|
|
43
43
|
var FetchCredentialsRequest = /*#__PURE__*/ function() {
|
|
44
44
|
"use strict";
|
|
45
45
|
function FetchCredentialsRequest() {
|
|
46
|
-
var credentialsValue = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] :
|
|
46
|
+
var credentialsValue = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 'same-origin';
|
|
47
47
|
_class_call_check(this, FetchCredentialsRequest);
|
|
48
48
|
/**
|
|
49
49
|
* Value that will be set as the "credentials" option of the fetch API.
|
|
@@ -127,13 +127,13 @@ function _ts_generator(thisArg, body) {
|
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
describe(
|
|
130
|
+
describe('Fetch API credentials Request Plugin', function() {
|
|
131
131
|
var options = {
|
|
132
132
|
headers: new Headers(),
|
|
133
|
-
basePath:
|
|
134
|
-
method:
|
|
133
|
+
basePath: 'http://test.com/truc',
|
|
134
|
+
method: 'get'
|
|
135
135
|
};
|
|
136
|
-
it(
|
|
136
|
+
it('credentials should be set to same-origin by default', /*#__PURE__*/ _async_to_generator(function() {
|
|
137
137
|
var plugin, runner, cred;
|
|
138
138
|
return _ts_generator(this, function(_state) {
|
|
139
139
|
switch(_state.label){
|
|
@@ -152,19 +152,19 @@ describe("Fetch API credentials Request Plugin", function() {
|
|
|
152
152
|
];
|
|
153
153
|
case 2:
|
|
154
154
|
cred = _state.sent().credentials;
|
|
155
|
-
expect(cred).toBe(
|
|
155
|
+
expect(cred).toBe('same-origin');
|
|
156
156
|
return [
|
|
157
157
|
2
|
|
158
158
|
];
|
|
159
159
|
}
|
|
160
160
|
});
|
|
161
161
|
}));
|
|
162
|
-
it(
|
|
162
|
+
it('credentials should be set correctly', /*#__PURE__*/ _async_to_generator(function() {
|
|
163
163
|
var plugin, runner, cred;
|
|
164
164
|
return _ts_generator(this, function(_state) {
|
|
165
165
|
switch(_state.label){
|
|
166
166
|
case 0:
|
|
167
|
-
plugin = new _fetchcredentialsrequest.FetchCredentialsRequest(
|
|
167
|
+
plugin = new _fetchcredentialsrequest.FetchCredentialsRequest('include');
|
|
168
168
|
runner = plugin.load();
|
|
169
169
|
return [
|
|
170
170
|
4,
|
|
@@ -178,7 +178,7 @@ describe("Fetch API credentials Request Plugin", function() {
|
|
|
178
178
|
];
|
|
179
179
|
case 2:
|
|
180
180
|
cred = _state.sent().credentials;
|
|
181
|
-
expect(cred).toBe(
|
|
181
|
+
expect(cred).toBe('include');
|
|
182
182
|
return [
|
|
183
183
|
2
|
|
184
184
|
];
|
|
@@ -43,7 +43,7 @@ function _define_property(obj, key, value) {
|
|
|
43
43
|
var JsonTokenReply = /*#__PURE__*/ function() {
|
|
44
44
|
"use strict";
|
|
45
45
|
function JsonTokenReply() {
|
|
46
|
-
var storageTokenKey = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] :
|
|
46
|
+
var storageTokenKey = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 'DP_SDK_AUTH_TOKEN', sharedMemory = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
47
47
|
_class_call_check(this, JsonTokenReply);
|
|
48
48
|
_define_property(this, "storageTokenKey", void 0);
|
|
49
49
|
_define_property(this, "sharedMemory", void 0);
|
|
@@ -60,15 +60,15 @@ var JsonTokenReply = /*#__PURE__*/ function() {
|
|
|
60
60
|
if (!context.response) {
|
|
61
61
|
return data;
|
|
62
62
|
}
|
|
63
|
-
if (context.response.headers.has(
|
|
64
|
-
var token = context.response.headers.get(
|
|
65
|
-
if (typeof sessionStorage !==
|
|
63
|
+
if (context.response.headers.has('Authorization')) {
|
|
64
|
+
var token = context.response.headers.get('Authorization');
|
|
65
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
66
66
|
sessionStorage.setItem(_this.storageTokenKey, token);
|
|
67
67
|
} else {
|
|
68
68
|
_this.sharedMemory[_this.storageTokenKey] = token;
|
|
69
69
|
}
|
|
70
70
|
} else {
|
|
71
|
-
if (typeof sessionStorage !==
|
|
71
|
+
if (typeof sessionStorage !== 'undefined') {
|
|
72
72
|
sessionStorage.removeItem(_this.storageTokenKey);
|
|
73
73
|
} else {
|
|
74
74
|
_this.sharedMemory[_this.storageTokenKey] = undefined;
|
|
@@ -43,7 +43,7 @@ function _define_property(obj, key, value) {
|
|
|
43
43
|
var JsonTokenRequest = /*#__PURE__*/ function() {
|
|
44
44
|
"use strict";
|
|
45
45
|
function JsonTokenRequest() {
|
|
46
|
-
var storageTokenKey = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] :
|
|
46
|
+
var storageTokenKey = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 'DP_SDK_AUTH_TOKEN', sharedMemory = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
47
47
|
_class_call_check(this, JsonTokenRequest);
|
|
48
48
|
_define_property(this, "storageTokenKey", void 0);
|
|
49
49
|
_define_property(this, "sharedMemory", void 0);
|
|
@@ -58,10 +58,10 @@ var JsonTokenRequest = /*#__PURE__*/ function() {
|
|
|
58
58
|
return {
|
|
59
59
|
transform: function(data) {
|
|
60
60
|
// Handle Authorization Tokens
|
|
61
|
-
var token = typeof sessionStorage !==
|
|
61
|
+
var token = typeof sessionStorage !== 'undefined' ? sessionStorage.getItem(_this.storageTokenKey) : _this.sharedMemory[_this.storageTokenKey];
|
|
62
62
|
if (token) {
|
|
63
|
-
data.credentials =
|
|
64
|
-
data.headers.append(
|
|
63
|
+
data.credentials = 'same-origin';
|
|
64
|
+
data.headers.append('Authorization', token);
|
|
65
65
|
}
|
|
66
66
|
return data;
|
|
67
67
|
}
|
|
@@ -129,25 +129,25 @@ function _ts_generator(thisArg, body) {
|
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
describe(
|
|
133
|
-
var tokenValue =
|
|
134
|
-
var tokenKey =
|
|
135
|
-
describe(
|
|
132
|
+
describe('Json Token', function() {
|
|
133
|
+
var tokenValue = 'tokenValue';
|
|
134
|
+
var tokenKey = 'testToken';
|
|
135
|
+
describe('request plugin', function() {
|
|
136
136
|
var defaultGetParams = {
|
|
137
|
-
defaultTest:
|
|
137
|
+
defaultTest: 'ok'
|
|
138
138
|
};
|
|
139
|
-
var defaultBody =
|
|
139
|
+
var defaultBody = 'default';
|
|
140
140
|
var options;
|
|
141
141
|
beforeEach(function() {
|
|
142
142
|
options = {
|
|
143
|
-
method:
|
|
143
|
+
method: 'get',
|
|
144
144
|
queryParams: defaultGetParams,
|
|
145
145
|
headers: new Headers(),
|
|
146
146
|
body: defaultBody,
|
|
147
|
-
basePath:
|
|
147
|
+
basePath: 'http://test.com/truc'
|
|
148
148
|
};
|
|
149
149
|
});
|
|
150
|
-
it(
|
|
150
|
+
it('should add Authorization header', /*#__PURE__*/ _async_to_generator(function() {
|
|
151
151
|
var memory, plugin, runner, result;
|
|
152
152
|
return _ts_generator(this, function(_state) {
|
|
153
153
|
switch(_state.label){
|
|
@@ -157,8 +157,8 @@ describe("Json Token", function() {
|
|
|
157
157
|
};
|
|
158
158
|
plugin = new _jsontokenrequest.JsonTokenRequest(tokenKey, memory);
|
|
159
159
|
runner = plugin.load();
|
|
160
|
-
if (typeof window !==
|
|
161
|
-
jest.spyOn(window.sessionStorage,
|
|
160
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
161
|
+
jest.spyOn(window.sessionStorage, 'getItem').mockImplementation(function() {
|
|
162
162
|
return tokenValue;
|
|
163
163
|
});
|
|
164
164
|
}
|
|
@@ -168,18 +168,18 @@ describe("Json Token", function() {
|
|
|
168
168
|
];
|
|
169
169
|
case 1:
|
|
170
170
|
result = _state.sent();
|
|
171
|
-
if (typeof window !==
|
|
171
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
172
172
|
expect(window.sessionStorage.getItem).toHaveBeenCalledWith(tokenKey);
|
|
173
173
|
}
|
|
174
|
-
expect(result.credentials).toBe(
|
|
175
|
-
expect(result.headers.get(
|
|
174
|
+
expect(result.credentials).toBe('same-origin');
|
|
175
|
+
expect(result.headers.get('Authorization')).toBe(tokenValue);
|
|
176
176
|
return [
|
|
177
177
|
2
|
|
178
178
|
];
|
|
179
179
|
}
|
|
180
180
|
});
|
|
181
181
|
}));
|
|
182
|
-
it(
|
|
182
|
+
it('should not add Authorization if no token', /*#__PURE__*/ _async_to_generator(function() {
|
|
183
183
|
var memory, plugin, runner, result;
|
|
184
184
|
return _ts_generator(this, function(_state) {
|
|
185
185
|
switch(_state.label){
|
|
@@ -189,8 +189,8 @@ describe("Json Token", function() {
|
|
|
189
189
|
};
|
|
190
190
|
plugin = new _jsontokenrequest.JsonTokenRequest(tokenKey, memory);
|
|
191
191
|
runner = plugin.load();
|
|
192
|
-
if (typeof window !==
|
|
193
|
-
jest.spyOn(window.sessionStorage,
|
|
192
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
193
|
+
jest.spyOn(window.sessionStorage, 'getItem').mockImplementation();
|
|
194
194
|
}
|
|
195
195
|
return [
|
|
196
196
|
4,
|
|
@@ -198,11 +198,11 @@ describe("Json Token", function() {
|
|
|
198
198
|
];
|
|
199
199
|
case 1:
|
|
200
200
|
result = _state.sent();
|
|
201
|
-
if (typeof window !==
|
|
201
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
202
202
|
expect(window.sessionStorage.getItem).toHaveBeenCalledWith(tokenKey);
|
|
203
203
|
}
|
|
204
204
|
expect(result.credentials).toBeUndefined();
|
|
205
|
-
expect(result.headers.get(
|
|
205
|
+
expect(result.headers.get('Authorization')).toBeNull();
|
|
206
206
|
return [
|
|
207
207
|
2
|
|
208
208
|
];
|
|
@@ -210,9 +210,9 @@ describe("Json Token", function() {
|
|
|
210
210
|
});
|
|
211
211
|
}));
|
|
212
212
|
});
|
|
213
|
-
describe(
|
|
213
|
+
describe('reply plugin', function() {
|
|
214
214
|
var reviver = jest.fn();
|
|
215
|
-
it(
|
|
215
|
+
it('should store the received token', /*#__PURE__*/ _async_to_generator(function() {
|
|
216
216
|
var memory, plugin, runner, data;
|
|
217
217
|
return _ts_generator(this, function(_state) {
|
|
218
218
|
switch(_state.label){
|
|
@@ -232,8 +232,8 @@ describe("Json Token", function() {
|
|
|
232
232
|
}
|
|
233
233
|
});
|
|
234
234
|
data = {};
|
|
235
|
-
if (typeof window !==
|
|
236
|
-
jest.spyOn(window.sessionStorage,
|
|
235
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
236
|
+
jest.spyOn(window.sessionStorage, 'setItem').mockImplementation();
|
|
237
237
|
}
|
|
238
238
|
return [
|
|
239
239
|
4,
|
|
@@ -241,7 +241,7 @@ describe("Json Token", function() {
|
|
|
241
241
|
];
|
|
242
242
|
case 1:
|
|
243
243
|
_state.sent();
|
|
244
|
-
if (typeof window !==
|
|
244
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
245
245
|
expect(window.sessionStorage.setItem).toHaveBeenCalledWith(tokenKey, tokenValue);
|
|
246
246
|
} else {
|
|
247
247
|
expect(memory.testToken).toBe(tokenValue);
|
|
@@ -232,7 +232,7 @@ var KeepaliveRequest = /*#__PURE__*/ function() {
|
|
|
232
232
|
switch(_state.label){
|
|
233
233
|
case 0:
|
|
234
234
|
customHeaders = new Headers();
|
|
235
|
-
customHeaders.set(
|
|
235
|
+
customHeaders.set('Content-Type', 'application/json');
|
|
236
236
|
_state.label = 1;
|
|
237
237
|
case 1:
|
|
238
238
|
_state.trys.push([
|
|
@@ -243,7 +243,7 @@ var KeepaliveRequest = /*#__PURE__*/ function() {
|
|
|
243
243
|
]);
|
|
244
244
|
return [
|
|
245
245
|
4,
|
|
246
|
-
fetch(
|
|
246
|
+
fetch('', {
|
|
247
247
|
headers: customHeaders,
|
|
248
248
|
keepalive: true
|
|
249
249
|
})
|
|
@@ -127,13 +127,13 @@ function _ts_generator(thisArg, body) {
|
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
describe(
|
|
130
|
+
describe('Keepalive Request Plugin', function() {
|
|
131
131
|
var options = {
|
|
132
132
|
headers: new Headers(),
|
|
133
|
-
basePath:
|
|
134
|
-
method:
|
|
133
|
+
basePath: 'http://test.com/truc',
|
|
134
|
+
method: 'get'
|
|
135
135
|
};
|
|
136
|
-
it(
|
|
136
|
+
it('keepalive should be set to true', /*#__PURE__*/ _async_to_generator(function() {
|
|
137
137
|
var plugin, runner, keepalive;
|
|
138
138
|
return _ts_generator(this, function(_state) {
|
|
139
139
|
switch(_state.label){
|
|
@@ -189,14 +189,14 @@ function _sha256() {
|
|
|
189
189
|
utf8 = new TextEncoder().encode(value);
|
|
190
190
|
return [
|
|
191
191
|
4,
|
|
192
|
-
(globalThis.crypto || require(
|
|
192
|
+
(globalThis.crypto || require('node:crypto').webcrypto).subtle.digest('SHA-256', utf8)
|
|
193
193
|
];
|
|
194
194
|
case 1:
|
|
195
195
|
hashBuffer = _state.sent();
|
|
196
196
|
hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
197
197
|
hashHex = hashArray.map(function(bytes) {
|
|
198
|
-
return bytes.toString(16).padStart(2,
|
|
199
|
-
}).join(
|
|
198
|
+
return bytes.toString(16).padStart(2, '0');
|
|
199
|
+
}).join('');
|
|
200
200
|
return [
|
|
201
201
|
2,
|
|
202
202
|
hashHex
|
|
@@ -208,17 +208,17 @@ function _sha256() {
|
|
|
208
208
|
}
|
|
209
209
|
function hmacSHA256(value, secretKey) {
|
|
210
210
|
try {
|
|
211
|
-
var createHmac = require(
|
|
212
|
-
return createHmac(
|
|
211
|
+
var createHmac = require('node:crypto').createHmac;
|
|
212
|
+
return createHmac('sha256', secretKey).update(value, 'latin1').digest('base64');
|
|
213
213
|
} catch (err) {
|
|
214
|
-
throw new Error(
|
|
214
|
+
throw new Error('Crypto module is not available.');
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
218
|
* Header definition of the JWS used for the API Manager authentication
|
|
219
219
|
*/ var jwsHeader = {
|
|
220
|
-
alg:
|
|
221
|
-
typ:
|
|
220
|
+
alg: 'HS256',
|
|
221
|
+
typ: 'JWT'
|
|
222
222
|
};
|
|
223
223
|
var MicroGatewayMiddlewareAuthenticationRequest = /*#__PURE__*/ function() {
|
|
224
224
|
"use strict";
|
|
@@ -253,8 +253,8 @@ var MicroGatewayMiddlewareAuthenticationRequest = /*#__PURE__*/ function() {
|
|
|
253
253
|
/**
|
|
254
254
|
* Method used to encode a string in base64
|
|
255
255
|
*/ _define_property(this, "base64Encoder", void 0);
|
|
256
|
-
if (typeof window !==
|
|
257
|
-
throw new Error(
|
|
256
|
+
if (typeof window !== 'undefined') {
|
|
257
|
+
throw new Error('The plugin can only be used in a NodeJS context');
|
|
258
258
|
}
|
|
259
259
|
this.applicationId = options.applicationId;
|
|
260
260
|
this.expIntervalInSec = options.expIntervalInSec;
|
|
@@ -373,7 +373,7 @@ var MicroGatewayMiddlewareAuthenticationRequest = /*#__PURE__*/ function() {
|
|
|
373
373
|
];
|
|
374
374
|
case 1:
|
|
375
375
|
token = _state.sent();
|
|
376
|
-
data.headers.append(
|
|
376
|
+
data.headers.append('Authorization', "Bearer ".concat(token));
|
|
377
377
|
return [
|
|
378
378
|
2,
|
|
379
379
|
data
|
|
@@ -146,10 +146,10 @@ function _ts_generator(thisArg, body) {
|
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
var authHeaderKey =
|
|
150
|
-
var authHeaderPrefix =
|
|
151
|
-
var baseUrl =
|
|
152
|
-
var routePath =
|
|
149
|
+
var authHeaderKey = 'Authorization';
|
|
150
|
+
var authHeaderPrefix = 'Bearer ';
|
|
151
|
+
var baseUrl = 'https://domain.com';
|
|
152
|
+
var routePath = '/v2/shopping/air-offers';
|
|
153
153
|
var options;
|
|
154
154
|
var FakeHeader = function FakeHeader() {
|
|
155
155
|
"use strict";
|
|
@@ -167,26 +167,26 @@ var FakeHeader = function FakeHeader() {
|
|
|
167
167
|
});
|
|
168
168
|
};
|
|
169
169
|
var jsonAuthTokenOptions = {
|
|
170
|
-
applicationId:
|
|
171
|
-
apiKey:
|
|
170
|
+
applicationId: '6X_MG__tester@test.com__PDT',
|
|
171
|
+
apiKey: 'dummy4P1K3Y',
|
|
172
172
|
expIntervalInSec: 60,
|
|
173
|
-
secret:
|
|
173
|
+
secret: 'super-secret',
|
|
174
174
|
context: {
|
|
175
|
-
oid:
|
|
175
|
+
oid: 'NCE1A0955'
|
|
176
176
|
}
|
|
177
177
|
};
|
|
178
|
-
describe(
|
|
178
|
+
describe('JSON auth token request plugin', function() {
|
|
179
179
|
beforeEach(function() {
|
|
180
180
|
options = {
|
|
181
181
|
basePath: "".concat(baseUrl).concat(routePath),
|
|
182
182
|
headers: new FakeHeader(),
|
|
183
|
-
method:
|
|
183
|
+
method: 'GET'
|
|
184
184
|
};
|
|
185
185
|
});
|
|
186
186
|
afterAll(function() {
|
|
187
187
|
global.sessionStorage = undefined;
|
|
188
188
|
});
|
|
189
|
-
it(
|
|
189
|
+
it('should add a Bearer in the header', /*#__PURE__*/ _async_to_generator(function() {
|
|
190
190
|
var _result_headers_get, plugin, result;
|
|
191
191
|
return _ts_generator(this, function(_state) {
|
|
192
192
|
switch(_state.label){
|
|
@@ -206,7 +206,7 @@ describe("JSON auth token request plugin", function() {
|
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
}));
|
|
209
|
-
it(
|
|
209
|
+
it('should check that the jws token is well formatted', /*#__PURE__*/ _async_to_generator(function() {
|
|
210
210
|
var plugin, result, token, tokenParts;
|
|
211
211
|
return _ts_generator(this, function(_state) {
|
|
212
212
|
switch(_state.label){
|
|
@@ -218,8 +218,8 @@ describe("JSON auth token request plugin", function() {
|
|
|
218
218
|
];
|
|
219
219
|
case 1:
|
|
220
220
|
result = _state.sent();
|
|
221
|
-
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix,
|
|
222
|
-
tokenParts = token.split(
|
|
221
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
222
|
+
tokenParts = token.split('.');
|
|
223
223
|
expect(token).toBeDefined();
|
|
224
224
|
expect(tokenParts.length).toEqual(3);
|
|
225
225
|
return [
|
|
@@ -228,7 +228,7 @@ describe("JSON auth token request plugin", function() {
|
|
|
228
228
|
}
|
|
229
229
|
});
|
|
230
230
|
}));
|
|
231
|
-
it(
|
|
231
|
+
it('should check that the header is properly set', /*#__PURE__*/ _async_to_generator(function() {
|
|
232
232
|
var base64URLDecoder, plugin, result, token, tokenParts, header;
|
|
233
233
|
return _ts_generator(this, function(_state) {
|
|
234
234
|
switch(_state.label){
|
|
@@ -241,21 +241,21 @@ describe("JSON auth token request plugin", function() {
|
|
|
241
241
|
];
|
|
242
242
|
case 1:
|
|
243
243
|
result = _state.sent();
|
|
244
|
-
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix,
|
|
244
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
245
245
|
expect(token).toBeDefined();
|
|
246
|
-
tokenParts = token.split(
|
|
246
|
+
tokenParts = token.split('.');
|
|
247
247
|
header = JSON.parse(base64URLDecoder(tokenParts[0]));
|
|
248
248
|
expect(header.alg).toBeDefined();
|
|
249
|
-
expect(header.alg).toEqual(
|
|
249
|
+
expect(header.alg).toEqual('HS256');
|
|
250
250
|
expect(header.typ).toBeDefined();
|
|
251
|
-
expect(header.typ).toEqual(
|
|
251
|
+
expect(header.typ).toEqual('JWT');
|
|
252
252
|
return [
|
|
253
253
|
2
|
|
254
254
|
];
|
|
255
255
|
}
|
|
256
256
|
});
|
|
257
257
|
}));
|
|
258
|
-
it(
|
|
258
|
+
it('should check that the payload is properly set', /*#__PURE__*/ _async_to_generator(function() {
|
|
259
259
|
var base64URLDecoder, base64Decoder, plugin, result, token, tokenParts, payload, context;
|
|
260
260
|
return _ts_generator(this, function(_state) {
|
|
261
261
|
switch(_state.label){
|
|
@@ -269,9 +269,9 @@ describe("JSON auth token request plugin", function() {
|
|
|
269
269
|
];
|
|
270
270
|
case 1:
|
|
271
271
|
result = _state.sent();
|
|
272
|
-
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix,
|
|
272
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
273
273
|
expect(token).toBeDefined();
|
|
274
|
-
tokenParts = token.split(
|
|
274
|
+
tokenParts = token.split('.');
|
|
275
275
|
payload = JSON.parse(base64URLDecoder(tokenParts[1]));
|
|
276
276
|
expect(payload.jti).toBeDefined();
|
|
277
277
|
expect(payload.iat).toBeDefined();
|
|
@@ -288,7 +288,7 @@ describe("JSON auth token request plugin", function() {
|
|
|
288
288
|
}
|
|
289
289
|
});
|
|
290
290
|
}));
|
|
291
|
-
it(
|
|
291
|
+
it('should check the signature validity', /*#__PURE__*/ _async_to_generator(function() {
|
|
292
292
|
var base64URLDecoder, base64UrlEncoder, plugin, result, token, tokenParts, header, payload, signature, secretKey, _, message, signCheck;
|
|
293
293
|
return _ts_generator(this, function(_state) {
|
|
294
294
|
switch(_state.label){
|
|
@@ -302,8 +302,8 @@ describe("JSON auth token request plugin", function() {
|
|
|
302
302
|
];
|
|
303
303
|
case 1:
|
|
304
304
|
result = _state.sent();
|
|
305
|
-
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix,
|
|
306
|
-
tokenParts = token.split(
|
|
305
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
306
|
+
tokenParts = token.split('.');
|
|
307
307
|
header = JSON.parse(base64URLDecoder(tokenParts[0]));
|
|
308
308
|
payload = JSON.parse(base64URLDecoder(tokenParts[1]));
|
|
309
309
|
signature = tokenParts[2];
|
|
@@ -187,7 +187,7 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
|
|
|
187
187
|
if (!context.apiClient.options.requestPlugins.some(function(plugin) {
|
|
188
188
|
return _instanceof(plugin, _mockinterceptrequest.MockInterceptRequest);
|
|
189
189
|
})) {
|
|
190
|
-
throw new Error(
|
|
190
|
+
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
191
191
|
}
|
|
192
192
|
var _this = this;
|
|
193
193
|
return {
|
|
@@ -211,11 +211,11 @@ var MockInterceptFetch = /*#__PURE__*/ function() {
|
|
|
211
211
|
responsePromise
|
|
212
212
|
];
|
|
213
213
|
}
|
|
214
|
-
if (!(typeof _this.options.delayTiming !==
|
|
214
|
+
if (!(typeof _this.options.delayTiming !== 'undefined')) return [
|
|
215
215
|
3,
|
|
216
216
|
6
|
|
217
217
|
];
|
|
218
|
-
if (!(typeof _this.options.delayTiming ===
|
|
218
|
+
if (!(typeof _this.options.delayTiming === 'number')) return [
|
|
219
219
|
3,
|
|
220
220
|
2
|
|
221
221
|
];
|