@ama-sdk/core 10.3.0-prerelease.66 → 10.3.0-prerelease.68
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
|
@@ -122,28 +122,28 @@ function _ts_generator(thisArg, body) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
import { ApiTypes } from
|
|
126
|
-
import { JsonTokenReply } from
|
|
127
|
-
import { JsonTokenRequest } from
|
|
128
|
-
describe(
|
|
129
|
-
var tokenValue =
|
|
130
|
-
var tokenKey =
|
|
131
|
-
describe(
|
|
125
|
+
import { ApiTypes } from '../../fwk/api';
|
|
126
|
+
import { JsonTokenReply } from './json-token.reply';
|
|
127
|
+
import { JsonTokenRequest } from './json-token.request';
|
|
128
|
+
describe('Json Token', function() {
|
|
129
|
+
var tokenValue = 'tokenValue';
|
|
130
|
+
var tokenKey = 'testToken';
|
|
131
|
+
describe('request plugin', function() {
|
|
132
132
|
var defaultGetParams = {
|
|
133
|
-
defaultTest:
|
|
133
|
+
defaultTest: 'ok'
|
|
134
134
|
};
|
|
135
|
-
var defaultBody =
|
|
135
|
+
var defaultBody = 'default';
|
|
136
136
|
var options;
|
|
137
137
|
beforeEach(function() {
|
|
138
138
|
options = {
|
|
139
|
-
method:
|
|
139
|
+
method: 'get',
|
|
140
140
|
queryParams: defaultGetParams,
|
|
141
141
|
headers: new Headers(),
|
|
142
142
|
body: defaultBody,
|
|
143
|
-
basePath:
|
|
143
|
+
basePath: 'http://test.com/truc'
|
|
144
144
|
};
|
|
145
145
|
});
|
|
146
|
-
it(
|
|
146
|
+
it('should add Authorization header', /*#__PURE__*/ _async_to_generator(function() {
|
|
147
147
|
var memory, plugin, runner, result;
|
|
148
148
|
return _ts_generator(this, function(_state) {
|
|
149
149
|
switch(_state.label){
|
|
@@ -153,8 +153,8 @@ describe("Json Token", function() {
|
|
|
153
153
|
};
|
|
154
154
|
plugin = new JsonTokenRequest(tokenKey, memory);
|
|
155
155
|
runner = plugin.load();
|
|
156
|
-
if (typeof window !==
|
|
157
|
-
jest.spyOn(window.sessionStorage,
|
|
156
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
157
|
+
jest.spyOn(window.sessionStorage, 'getItem').mockImplementation(function() {
|
|
158
158
|
return tokenValue;
|
|
159
159
|
});
|
|
160
160
|
}
|
|
@@ -164,18 +164,18 @@ describe("Json Token", function() {
|
|
|
164
164
|
];
|
|
165
165
|
case 1:
|
|
166
166
|
result = _state.sent();
|
|
167
|
-
if (typeof window !==
|
|
167
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
168
168
|
expect(window.sessionStorage.getItem).toHaveBeenCalledWith(tokenKey);
|
|
169
169
|
}
|
|
170
|
-
expect(result.credentials).toBe(
|
|
171
|
-
expect(result.headers.get(
|
|
170
|
+
expect(result.credentials).toBe('same-origin');
|
|
171
|
+
expect(result.headers.get('Authorization')).toBe(tokenValue);
|
|
172
172
|
return [
|
|
173
173
|
2
|
|
174
174
|
];
|
|
175
175
|
}
|
|
176
176
|
});
|
|
177
177
|
}));
|
|
178
|
-
it(
|
|
178
|
+
it('should not add Authorization if no token', /*#__PURE__*/ _async_to_generator(function() {
|
|
179
179
|
var memory, plugin, runner, result;
|
|
180
180
|
return _ts_generator(this, function(_state) {
|
|
181
181
|
switch(_state.label){
|
|
@@ -185,8 +185,8 @@ describe("Json Token", function() {
|
|
|
185
185
|
};
|
|
186
186
|
plugin = new JsonTokenRequest(tokenKey, memory);
|
|
187
187
|
runner = plugin.load();
|
|
188
|
-
if (typeof window !==
|
|
189
|
-
jest.spyOn(window.sessionStorage,
|
|
188
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
189
|
+
jest.spyOn(window.sessionStorage, 'getItem').mockImplementation();
|
|
190
190
|
}
|
|
191
191
|
return [
|
|
192
192
|
4,
|
|
@@ -194,11 +194,11 @@ describe("Json Token", function() {
|
|
|
194
194
|
];
|
|
195
195
|
case 1:
|
|
196
196
|
result = _state.sent();
|
|
197
|
-
if (typeof window !==
|
|
197
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
198
198
|
expect(window.sessionStorage.getItem).toHaveBeenCalledWith(tokenKey);
|
|
199
199
|
}
|
|
200
200
|
expect(result.credentials).toBeUndefined();
|
|
201
|
-
expect(result.headers.get(
|
|
201
|
+
expect(result.headers.get('Authorization')).toBeNull();
|
|
202
202
|
return [
|
|
203
203
|
2
|
|
204
204
|
];
|
|
@@ -206,9 +206,9 @@ describe("Json Token", function() {
|
|
|
206
206
|
});
|
|
207
207
|
}));
|
|
208
208
|
});
|
|
209
|
-
describe(
|
|
209
|
+
describe('reply plugin', function() {
|
|
210
210
|
var reviver = jest.fn();
|
|
211
|
-
it(
|
|
211
|
+
it('should store the received token', /*#__PURE__*/ _async_to_generator(function() {
|
|
212
212
|
var memory, plugin, runner, data;
|
|
213
213
|
return _ts_generator(this, function(_state) {
|
|
214
214
|
switch(_state.label){
|
|
@@ -228,8 +228,8 @@ describe("Json Token", function() {
|
|
|
228
228
|
}
|
|
229
229
|
});
|
|
230
230
|
data = {};
|
|
231
|
-
if (typeof window !==
|
|
232
|
-
jest.spyOn(window.sessionStorage,
|
|
231
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
232
|
+
jest.spyOn(window.sessionStorage, 'setItem').mockImplementation();
|
|
233
233
|
}
|
|
234
234
|
return [
|
|
235
235
|
4,
|
|
@@ -237,7 +237,7 @@ describe("Json Token", function() {
|
|
|
237
237
|
];
|
|
238
238
|
case 1:
|
|
239
239
|
_state.sent();
|
|
240
|
-
if (typeof window !==
|
|
240
|
+
if (typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined') {
|
|
241
241
|
expect(window.sessionStorage.setItem).toHaveBeenCalledWith(tokenKey, tokenValue);
|
|
242
242
|
} else {
|
|
243
243
|
expect(memory.testToken).toBe(tokenValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './keepalive.request';
|
|
@@ -224,7 +224,7 @@ function _ts_generator(thisArg, body) {
|
|
|
224
224
|
switch(_state.label){
|
|
225
225
|
case 0:
|
|
226
226
|
customHeaders = new Headers();
|
|
227
|
-
customHeaders.set(
|
|
227
|
+
customHeaders.set('Content-Type', 'application/json');
|
|
228
228
|
_state.label = 1;
|
|
229
229
|
case 1:
|
|
230
230
|
_state.trys.push([
|
|
@@ -235,7 +235,7 @@ function _ts_generator(thisArg, body) {
|
|
|
235
235
|
]);
|
|
236
236
|
return [
|
|
237
237
|
4,
|
|
238
|
-
fetch(
|
|
238
|
+
fetch('', {
|
|
239
239
|
headers: customHeaders,
|
|
240
240
|
keepalive: true
|
|
241
241
|
})
|
|
@@ -122,14 +122,14 @@ function _ts_generator(thisArg, body) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
import { KeepaliveRequest } from
|
|
126
|
-
describe(
|
|
125
|
+
import { KeepaliveRequest } from './keepalive.request';
|
|
126
|
+
describe('Keepalive Request Plugin', function() {
|
|
127
127
|
var options = {
|
|
128
128
|
headers: new Headers(),
|
|
129
|
-
basePath:
|
|
130
|
-
method:
|
|
129
|
+
basePath: 'http://test.com/truc',
|
|
130
|
+
method: 'get'
|
|
131
131
|
};
|
|
132
|
-
it(
|
|
132
|
+
it('keepalive should be set to true', /*#__PURE__*/ _async_to_generator(function() {
|
|
133
133
|
var plugin, runner, keepalive;
|
|
134
134
|
return _ts_generator(this, function(_state) {
|
|
135
135
|
switch(_state.label){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './mgw-mdw-auth.request';
|
|
@@ -154,8 +154,8 @@ function _ts_generator(thisArg, body) {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
import { v4 } from
|
|
158
|
-
import { base64EncodeUrl, createBase64Encoder, createBase64UrlEncoder } from
|
|
157
|
+
import { v4 } from 'uuid';
|
|
158
|
+
import { base64EncodeUrl, createBase64Encoder, createBase64UrlEncoder } from '../../utils/json-token';
|
|
159
159
|
/**
|
|
160
160
|
* Computes the SHA256 digest of the given string
|
|
161
161
|
* @param value Value to hash
|
|
@@ -171,14 +171,14 @@ function _sha256() {
|
|
|
171
171
|
utf8 = new TextEncoder().encode(value);
|
|
172
172
|
return [
|
|
173
173
|
4,
|
|
174
|
-
(globalThis.crypto || require(
|
|
174
|
+
(globalThis.crypto || require('node:crypto').webcrypto).subtle.digest('SHA-256', utf8)
|
|
175
175
|
];
|
|
176
176
|
case 1:
|
|
177
177
|
hashBuffer = _state.sent();
|
|
178
178
|
hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
179
179
|
hashHex = hashArray.map(function(bytes) {
|
|
180
|
-
return bytes.toString(16).padStart(2,
|
|
181
|
-
}).join(
|
|
180
|
+
return bytes.toString(16).padStart(2, '0');
|
|
181
|
+
}).join('');
|
|
182
182
|
return [
|
|
183
183
|
2,
|
|
184
184
|
hashHex
|
|
@@ -196,17 +196,17 @@ function _sha256() {
|
|
|
196
196
|
* @param secretKey Secret cryptographic key
|
|
197
197
|
*/ export function hmacSHA256(value, secretKey) {
|
|
198
198
|
try {
|
|
199
|
-
var createHmac = require(
|
|
200
|
-
return createHmac(
|
|
199
|
+
var createHmac = require('node:crypto').createHmac;
|
|
200
|
+
return createHmac('sha256', secretKey).update(value, 'latin1').digest('base64');
|
|
201
201
|
} catch (err) {
|
|
202
|
-
throw new Error(
|
|
202
|
+
throw new Error('Crypto module is not available.');
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
206
206
|
* Header definition of the JWS used for the API Manager authentication
|
|
207
207
|
*/ var jwsHeader = {
|
|
208
|
-
alg:
|
|
209
|
-
typ:
|
|
208
|
+
alg: 'HS256',
|
|
209
|
+
typ: 'JWT'
|
|
210
210
|
};
|
|
211
211
|
/**
|
|
212
212
|
* Plugin to send a JWS to authenticate on the API Manager.
|
|
@@ -244,8 +244,8 @@ function _sha256() {
|
|
|
244
244
|
/**
|
|
245
245
|
* Method used to encode a string in base64
|
|
246
246
|
*/ _define_property(this, "base64Encoder", void 0);
|
|
247
|
-
if (typeof window !==
|
|
248
|
-
throw new Error(
|
|
247
|
+
if (typeof window !== 'undefined') {
|
|
248
|
+
throw new Error('The plugin can only be used in a NodeJS context');
|
|
249
249
|
}
|
|
250
250
|
this.applicationId = options.applicationId;
|
|
251
251
|
this.expIntervalInSec = options.expIntervalInSec;
|
|
@@ -364,7 +364,7 @@ function _sha256() {
|
|
|
364
364
|
];
|
|
365
365
|
case 1:
|
|
366
366
|
token = _state.sent();
|
|
367
|
-
data.headers.append(
|
|
367
|
+
data.headers.append('Authorization', "Bearer ".concat(token));
|
|
368
368
|
return [
|
|
369
369
|
2,
|
|
370
370
|
data
|
|
@@ -140,12 +140,12 @@ function _ts_generator(thisArg, body) {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
import { base64EncodeUrl, createBase64Decoder, createBase64UrlDecoder, createBase64UrlEncoder } from
|
|
144
|
-
import { hmacSHA256, MicroGatewayMiddlewareAuthenticationRequest, sha256 } from
|
|
145
|
-
var authHeaderKey =
|
|
146
|
-
var authHeaderPrefix =
|
|
147
|
-
var baseUrl =
|
|
148
|
-
var routePath =
|
|
143
|
+
import { base64EncodeUrl, createBase64Decoder, createBase64UrlDecoder, createBase64UrlEncoder } from '../../utils/json-token';
|
|
144
|
+
import { hmacSHA256, MicroGatewayMiddlewareAuthenticationRequest, sha256 } from './mgw-mdw-auth.request';
|
|
145
|
+
var authHeaderKey = 'Authorization';
|
|
146
|
+
var authHeaderPrefix = 'Bearer ';
|
|
147
|
+
var baseUrl = 'https://domain.com';
|
|
148
|
+
var routePath = '/v2/shopping/air-offers';
|
|
149
149
|
var options;
|
|
150
150
|
var FakeHeader = function FakeHeader() {
|
|
151
151
|
"use strict";
|
|
@@ -163,26 +163,26 @@ var FakeHeader = function FakeHeader() {
|
|
|
163
163
|
});
|
|
164
164
|
};
|
|
165
165
|
var jsonAuthTokenOptions = {
|
|
166
|
-
applicationId:
|
|
167
|
-
apiKey:
|
|
166
|
+
applicationId: '6X_MG__tester@test.com__PDT',
|
|
167
|
+
apiKey: 'dummy4P1K3Y',
|
|
168
168
|
expIntervalInSec: 60,
|
|
169
|
-
secret:
|
|
169
|
+
secret: 'super-secret',
|
|
170
170
|
context: {
|
|
171
|
-
oid:
|
|
171
|
+
oid: 'NCE1A0955'
|
|
172
172
|
}
|
|
173
173
|
};
|
|
174
|
-
describe(
|
|
174
|
+
describe('JSON auth token request plugin', function() {
|
|
175
175
|
beforeEach(function() {
|
|
176
176
|
options = {
|
|
177
177
|
basePath: "".concat(baseUrl).concat(routePath),
|
|
178
178
|
headers: new FakeHeader(),
|
|
179
|
-
method:
|
|
179
|
+
method: 'GET'
|
|
180
180
|
};
|
|
181
181
|
});
|
|
182
182
|
afterAll(function() {
|
|
183
183
|
global.sessionStorage = undefined;
|
|
184
184
|
});
|
|
185
|
-
it(
|
|
185
|
+
it('should add a Bearer in the header', /*#__PURE__*/ _async_to_generator(function() {
|
|
186
186
|
var _result_headers_get, plugin, result;
|
|
187
187
|
return _ts_generator(this, function(_state) {
|
|
188
188
|
switch(_state.label){
|
|
@@ -202,7 +202,7 @@ describe("JSON auth token request plugin", function() {
|
|
|
202
202
|
}
|
|
203
203
|
});
|
|
204
204
|
}));
|
|
205
|
-
it(
|
|
205
|
+
it('should check that the jws token is well formatted', /*#__PURE__*/ _async_to_generator(function() {
|
|
206
206
|
var plugin, result, token, tokenParts;
|
|
207
207
|
return _ts_generator(this, function(_state) {
|
|
208
208
|
switch(_state.label){
|
|
@@ -214,8 +214,8 @@ describe("JSON auth token request plugin", function() {
|
|
|
214
214
|
];
|
|
215
215
|
case 1:
|
|
216
216
|
result = _state.sent();
|
|
217
|
-
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix,
|
|
218
|
-
tokenParts = token.split(
|
|
217
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
218
|
+
tokenParts = token.split('.');
|
|
219
219
|
expect(token).toBeDefined();
|
|
220
220
|
expect(tokenParts.length).toEqual(3);
|
|
221
221
|
return [
|
|
@@ -224,7 +224,7 @@ describe("JSON auth token request plugin", function() {
|
|
|
224
224
|
}
|
|
225
225
|
});
|
|
226
226
|
}));
|
|
227
|
-
it(
|
|
227
|
+
it('should check that the header is properly set', /*#__PURE__*/ _async_to_generator(function() {
|
|
228
228
|
var base64URLDecoder, plugin, result, token, tokenParts, header;
|
|
229
229
|
return _ts_generator(this, function(_state) {
|
|
230
230
|
switch(_state.label){
|
|
@@ -237,21 +237,21 @@ describe("JSON auth token request plugin", function() {
|
|
|
237
237
|
];
|
|
238
238
|
case 1:
|
|
239
239
|
result = _state.sent();
|
|
240
|
-
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix,
|
|
240
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
241
241
|
expect(token).toBeDefined();
|
|
242
|
-
tokenParts = token.split(
|
|
242
|
+
tokenParts = token.split('.');
|
|
243
243
|
header = JSON.parse(base64URLDecoder(tokenParts[0]));
|
|
244
244
|
expect(header.alg).toBeDefined();
|
|
245
|
-
expect(header.alg).toEqual(
|
|
245
|
+
expect(header.alg).toEqual('HS256');
|
|
246
246
|
expect(header.typ).toBeDefined();
|
|
247
|
-
expect(header.typ).toEqual(
|
|
247
|
+
expect(header.typ).toEqual('JWT');
|
|
248
248
|
return [
|
|
249
249
|
2
|
|
250
250
|
];
|
|
251
251
|
}
|
|
252
252
|
});
|
|
253
253
|
}));
|
|
254
|
-
it(
|
|
254
|
+
it('should check that the payload is properly set', /*#__PURE__*/ _async_to_generator(function() {
|
|
255
255
|
var base64URLDecoder, base64Decoder, plugin, result, token, tokenParts, payload, context;
|
|
256
256
|
return _ts_generator(this, function(_state) {
|
|
257
257
|
switch(_state.label){
|
|
@@ -265,9 +265,9 @@ describe("JSON auth token request plugin", function() {
|
|
|
265
265
|
];
|
|
266
266
|
case 1:
|
|
267
267
|
result = _state.sent();
|
|
268
|
-
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix,
|
|
268
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
269
269
|
expect(token).toBeDefined();
|
|
270
|
-
tokenParts = token.split(
|
|
270
|
+
tokenParts = token.split('.');
|
|
271
271
|
payload = JSON.parse(base64URLDecoder(tokenParts[1]));
|
|
272
272
|
expect(payload.jti).toBeDefined();
|
|
273
273
|
expect(payload.iat).toBeDefined();
|
|
@@ -284,7 +284,7 @@ describe("JSON auth token request plugin", function() {
|
|
|
284
284
|
}
|
|
285
285
|
});
|
|
286
286
|
}));
|
|
287
|
-
it(
|
|
287
|
+
it('should check the signature validity', /*#__PURE__*/ _async_to_generator(function() {
|
|
288
288
|
var base64URLDecoder, base64UrlEncoder, plugin, result, token, tokenParts, header, payload, signature, secretKey, _, message, signCheck;
|
|
289
289
|
return _ts_generator(this, function(_state) {
|
|
290
290
|
switch(_state.label){
|
|
@@ -298,8 +298,8 @@ describe("JSON auth token request plugin", function() {
|
|
|
298
298
|
];
|
|
299
299
|
case 1:
|
|
300
300
|
result = _state.sent();
|
|
301
|
-
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix,
|
|
302
|
-
tokenParts = token.split(
|
|
301
|
+
token = result.headers.get(authHeaderKey).replace(authHeaderPrefix, '');
|
|
302
|
+
tokenParts = token.split('.');
|
|
303
303
|
header = JSON.parse(base64URLDecoder(tokenParts[0]));
|
|
304
304
|
payload = JSON.parse(base64URLDecoder(tokenParts[1]));
|
|
305
305
|
signature = tokenParts[2];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './mock-intercept.request';
|
|
2
|
+
export * from './mock-intercept.fetch';
|
|
@@ -161,8 +161,8 @@ function _ts_generator(thisArg, body) {
|
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
import { CUSTOM_MOCK_OPERATION_ID_HEADER } from
|
|
165
|
-
import { MockInterceptRequest } from
|
|
164
|
+
import { CUSTOM_MOCK_OPERATION_ID_HEADER } from './mock-intercept.interface';
|
|
165
|
+
import { MockInterceptRequest } from './mock-intercept.request';
|
|
166
166
|
/**
|
|
167
167
|
* Plugin to mock and intercept the fetch of SDK
|
|
168
168
|
*
|
|
@@ -182,7 +182,7 @@ import { MockInterceptRequest } from "./mock-intercept.request";
|
|
|
182
182
|
if (!context.apiClient.options.requestPlugins.some(function(plugin) {
|
|
183
183
|
return _instanceof(plugin, MockInterceptRequest);
|
|
184
184
|
})) {
|
|
185
|
-
throw new Error(
|
|
185
|
+
throw new Error('MockInterceptFetch plugin should be used only with the MockInterceptRequest plugin');
|
|
186
186
|
}
|
|
187
187
|
var _this = this;
|
|
188
188
|
return {
|
|
@@ -206,11 +206,11 @@ import { MockInterceptRequest } from "./mock-intercept.request";
|
|
|
206
206
|
responsePromise
|
|
207
207
|
];
|
|
208
208
|
}
|
|
209
|
-
if (!(typeof _this.options.delayTiming !==
|
|
209
|
+
if (!(typeof _this.options.delayTiming !== 'undefined')) return [
|
|
210
210
|
3,
|
|
211
211
|
6
|
|
212
212
|
];
|
|
213
|
-
if (!(typeof _this.options.delayTiming ===
|
|
213
|
+
if (!(typeof _this.options.delayTiming === 'number')) return [
|
|
214
214
|
3,
|
|
215
215
|
2
|
|
216
216
|
];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** Custom Mock Header for Operation ID */ export var CUSTOM_MOCK_OPERATION_ID_HEADER =
|
|
2
|
-
/** Custom Mock Header for Original Request */ export var CUSTOM_MOCK_REQUEST_HEADER =
|
|
1
|
+
/** Custom Mock Header for Operation ID */ export var CUSTOM_MOCK_OPERATION_ID_HEADER = 'X-mock-operation-id';
|
|
2
|
+
/** Custom Mock Header for Original Request */ export var CUSTOM_MOCK_REQUEST_HEADER = 'X-mock-request';
|
|
@@ -193,7 +193,7 @@ function _ts_generator(thisArg, body) {
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
import { CUSTOM_MOCK_OPERATION_ID_HEADER, CUSTOM_MOCK_REQUEST_HEADER } from
|
|
196
|
+
import { CUSTOM_MOCK_OPERATION_ID_HEADER, CUSTOM_MOCK_REQUEST_HEADER } from './mock-intercept.interface';
|
|
197
197
|
/**
|
|
198
198
|
* Plugin to intercept an API request for mock purposes
|
|
199
199
|
*/ export var MockInterceptRequest = /*#__PURE__*/ function() {
|
|
@@ -233,7 +233,7 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, CUSTOM_MOCK_REQUEST_HEADER } from "./m
|
|
|
233
233
|
];
|
|
234
234
|
}
|
|
235
235
|
requestOption = _object_spread_props(_object_spread({}, data), {
|
|
236
|
-
method: data.method ||
|
|
236
|
+
method: data.method || 'GET'
|
|
237
237
|
});
|
|
238
238
|
return [
|
|
239
239
|
4,
|
|
@@ -246,7 +246,7 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, CUSTOM_MOCK_REQUEST_HEADER } from "./m
|
|
|
246
246
|
blob = new Blob([
|
|
247
247
|
text
|
|
248
248
|
], {
|
|
249
|
-
type:
|
|
249
|
+
type: 'application/json'
|
|
250
250
|
});
|
|
251
251
|
basePath = URL.createObjectURL(blob);
|
|
252
252
|
headers = data.headers || new Headers();
|
|
@@ -255,7 +255,7 @@ import { CUSTOM_MOCK_OPERATION_ID_HEADER, CUSTOM_MOCK_REQUEST_HEADER } from "./m
|
|
|
255
255
|
return [
|
|
256
256
|
2,
|
|
257
257
|
{
|
|
258
|
-
method:
|
|
258
|
+
method: 'GET',
|
|
259
259
|
basePath: basePath,
|
|
260
260
|
headers: headers
|
|
261
261
|
}
|