@ama-sdk/core 10.3.0-prerelease.9 → 10.3.0-rc.1
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 +36 -18
- package/cjs/clients/api-beacon-client.js +61 -19
- package/cjs/clients/api-fetch-client.js +60 -18
- package/cjs/fwk/api.helper.spec.js +20 -20
- package/cjs/fwk/api.helpers.js +14 -14
- 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 +253 -0
- package/cjs/utils/index.js +1 -0
- package/cjs/utils/json-token.js +30 -30
- package/cjs/utils/json-token.spec.js +31 -31
- package/cli/clear-index.cjs.map +1 -0
- package/cli/files-pack.cjs.map +1 -0
- package/esm2015/clients/api-angular-client.js +40 -22
- package/esm2015/clients/api-beacon-client.js +62 -20
- package/esm2015/clients/api-fetch-client.js +64 -22
- package/esm2015/clients/index.js +2 -2
- package/esm2015/fwk/api.helper.spec.js +21 -21
- package/esm2015/fwk/api.helpers.js +14 -14
- 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 +245 -0
- package/esm2015/utils/index.js +6 -5
- package/esm2015/utils/json-token.js +32 -32
- package/esm2015/utils/json-token.spec.js +32 -32
- package/package.json +7 -7
- package/schematics/ng-add/index.js.map +1 -0
- package/schematics/ng-add/schema.js.map +1 -0
- package/src/clients/api-angular-client.d.ts +6 -3
- package/src/clients/api-angular-client.d.ts.map +1 -1
- package/src/clients/api-angular-client.js +23 -11
- package/src/clients/api-angular-client.js.map +1 -1
- package/src/clients/api-beacon-client.d.ts +7 -5
- package/src/clients/api-beacon-client.d.ts.map +1 -1
- package/src/clients/api-beacon-client.js +22 -14
- package/src/clients/api-beacon-client.js.map +1 -1
- package/src/clients/api-fetch-client.d.ts +5 -3
- package/src/clients/api-fetch-client.d.ts.map +1 -1
- package/src/clients/api-fetch-client.js +22 -11
- package/src/clients/api-fetch-client.js.map +1 -1
- package/src/fwk/api.helpers.d.ts +1 -1
- package/src/fwk/api.helpers.d.ts.map +1 -1
- package/src/fwk/api.helpers.js +1 -1
- package/src/fwk/api.helpers.js.map +1 -1
- package/src/fwk/core/api-client.d.ts +36 -1
- package/src/fwk/core/api-client.d.ts.map +1 -1
- package/src/fwk/core/api-client.js.map +1 -1
- package/src/plugins/core/plugin.d.ts +6 -1
- package/src/plugins/core/plugin.d.ts.map +1 -1
- package/src/plugins/core/reply-plugin.d.ts +0 -2
- package/src/plugins/core/reply-plugin.d.ts.map +1 -1
- package/src/utils/generic-api.d.ts +39 -0
- package/src/utils/generic-api.d.ts.map +1 -0
- package/src/utils/generic-api.js +43 -0
- package/src/utils/generic-api.js.map +1 -0
- package/src/utils/index.d.ts +1 -0
- package/src/utils/index.d.ts.map +1 -1
- package/src/utils/index.js +1 -0
- package/src/utils/index.js.map +1 -1
|
@@ -33,13 +33,13 @@ function _object_spread(target) {
|
|
|
33
33
|
}
|
|
34
34
|
return target;
|
|
35
35
|
}
|
|
36
|
-
describe(
|
|
36
|
+
describe('Exception Reply Plugin', function() {
|
|
37
37
|
var reviver = jest.fn();
|
|
38
38
|
var contextError = {
|
|
39
|
-
apiName:
|
|
40
|
-
operationId:
|
|
39
|
+
apiName: 'api',
|
|
40
|
+
operationId: 'ope'
|
|
41
41
|
};
|
|
42
|
-
it(
|
|
42
|
+
it('should throw on empty data and contains errors key if DAPI', function() {
|
|
43
43
|
var plugin = new _exceptionreply.ExceptionReply();
|
|
44
44
|
var runner = plugin.load(_object_spread({
|
|
45
45
|
reviver: reviver,
|
|
@@ -47,7 +47,7 @@ describe("Exception Reply Plugin", function() {
|
|
|
47
47
|
response: {
|
|
48
48
|
ok: true,
|
|
49
49
|
status: 200,
|
|
50
|
-
statusText:
|
|
50
|
+
statusText: 'test'
|
|
51
51
|
}
|
|
52
52
|
}, contextError));
|
|
53
53
|
var data = {
|
|
@@ -55,9 +55,9 @@ describe("Exception Reply Plugin", function() {
|
|
|
55
55
|
};
|
|
56
56
|
expect(function() {
|
|
57
57
|
return runner.transform(data);
|
|
58
|
-
}).toThrow(new _errors.EmptyResponseError(
|
|
58
|
+
}).toThrow(new _errors.EmptyResponseError('test', data, contextError));
|
|
59
59
|
});
|
|
60
|
-
it(
|
|
60
|
+
it('should not throw on empty data and no errors key if DAPI', function() {
|
|
61
61
|
var plugin = new _exceptionreply.ExceptionReply();
|
|
62
62
|
var runner = plugin.load({
|
|
63
63
|
reviver: reviver,
|
|
@@ -65,7 +65,7 @@ describe("Exception Reply Plugin", function() {
|
|
|
65
65
|
response: {
|
|
66
66
|
ok: true,
|
|
67
67
|
status: 200,
|
|
68
|
-
statusText:
|
|
68
|
+
statusText: 'test'
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
var data = {};
|
|
@@ -73,7 +73,7 @@ describe("Exception Reply Plugin", function() {
|
|
|
73
73
|
return runner.transform(data);
|
|
74
74
|
}).not.toThrow();
|
|
75
75
|
});
|
|
76
|
-
it(
|
|
76
|
+
it('should not throw on empty data if not DAPI', function() {
|
|
77
77
|
var plugin = new _exceptionreply.ExceptionReply();
|
|
78
78
|
var runner = plugin.load({
|
|
79
79
|
reviver: reviver,
|
|
@@ -81,7 +81,7 @@ describe("Exception Reply Plugin", function() {
|
|
|
81
81
|
response: {
|
|
82
82
|
ok: true,
|
|
83
83
|
status: 200,
|
|
84
|
-
statusText:
|
|
84
|
+
statusText: 'test'
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
var data = {};
|
|
@@ -89,7 +89,7 @@ describe("Exception Reply Plugin", function() {
|
|
|
89
89
|
return runner.transform(data);
|
|
90
90
|
}).not.toThrow();
|
|
91
91
|
});
|
|
92
|
-
it(
|
|
92
|
+
it('should throw on nok status', function() {
|
|
93
93
|
var plugin = new _exceptionreply.ExceptionReply();
|
|
94
94
|
var runner = plugin.load(_object_spread({
|
|
95
95
|
reviver: reviver,
|
|
@@ -97,7 +97,7 @@ describe("Exception Reply Plugin", function() {
|
|
|
97
97
|
response: {
|
|
98
98
|
ok: false,
|
|
99
99
|
status: 444,
|
|
100
|
-
statusText:
|
|
100
|
+
statusText: 'test'
|
|
101
101
|
}
|
|
102
102
|
}, contextError));
|
|
103
103
|
var data = {
|
|
@@ -105,9 +105,9 @@ describe("Exception Reply Plugin", function() {
|
|
|
105
105
|
};
|
|
106
106
|
expect(function() {
|
|
107
107
|
return runner.transform(data);
|
|
108
|
-
}).toThrow(new _errors.RequestFailedError(
|
|
108
|
+
}).toThrow(new _errors.RequestFailedError('test', 444, data, contextError));
|
|
109
109
|
});
|
|
110
|
-
it(
|
|
110
|
+
it('should not throw if there is already an exception', function() {
|
|
111
111
|
var plugin = new _exceptionreply.ExceptionReply();
|
|
112
112
|
var runner = plugin.load({
|
|
113
113
|
reviver: reviver,
|
|
@@ -115,7 +115,7 @@ describe("Exception Reply Plugin", function() {
|
|
|
115
115
|
response: {
|
|
116
116
|
ok: false,
|
|
117
117
|
status: 444,
|
|
118
|
-
statusText:
|
|
118
|
+
statusText: 'test'
|
|
119
119
|
},
|
|
120
120
|
exception: new Error()
|
|
121
121
|
});
|
|
@@ -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
|