@ama-sdk/core 10.3.0-prerelease.65 → 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
|
@@ -173,27 +173,27 @@ function _ts_generator(thisArg, body) {
|
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
var crypto = require(
|
|
177
|
-
describe(
|
|
178
|
-
it(
|
|
176
|
+
var crypto = require('node:crypto');
|
|
177
|
+
describe('JSON token utils', function() {
|
|
178
|
+
it('should encode and decode in base64 properly a string that contains characters occupying more than 1 byte', function() {
|
|
179
179
|
var base64Encoder = (0, _jsontoken.createBase64Encoder)();
|
|
180
180
|
var base64Decoder = (0, _jsontoken.createBase64Decoder)();
|
|
181
|
-
var myString =
|
|
181
|
+
var myString = '☸☹☺☻☼☾☿';
|
|
182
182
|
var converted = base64Encoder(myString);
|
|
183
183
|
var original = base64Decoder(converted);
|
|
184
184
|
expect(original).toEqual(myString);
|
|
185
185
|
});
|
|
186
|
-
it(
|
|
186
|
+
it('should encode and decode in base64Url properly a string that contains characters occupying more than 1 byte', function() {
|
|
187
187
|
var base64UrlEncoder = (0, _jsontoken.createBase64UrlEncoder)();
|
|
188
188
|
var base64UrlDecoder = (0, _jsontoken.createBase64UrlDecoder)();
|
|
189
|
-
var myString =
|
|
189
|
+
var myString = '☸☹☺☻☼☾☿';
|
|
190
190
|
var converted = base64UrlEncoder(myString);
|
|
191
191
|
var original = base64UrlDecoder(converted);
|
|
192
192
|
expect(original).toEqual(myString);
|
|
193
193
|
});
|
|
194
194
|
});
|
|
195
|
-
describe(
|
|
196
|
-
it(
|
|
195
|
+
describe('JSON Web Encryption Token', function() {
|
|
196
|
+
it('should generate a proper JWE Token', /*#__PURE__*/ _async_to_generator(function() {
|
|
197
197
|
var expectedJwePayload, expectedJweHeader, expectedIv, cek, expectedJweEncryptedKey, outputAesGcm, jweToken, _jweToken_split, jweHeader, jweEncryptedKey, iv, cipherContent, authenticationTag, decipher, decrypted;
|
|
198
198
|
return _ts_generator(this, function(_state) {
|
|
199
199
|
switch(_state.label){
|
|
@@ -201,20 +201,20 @@ describe("JSON Web Encryption Token", function() {
|
|
|
201
201
|
/* eslint-disable @typescript-eslint/naming-convention */ expectedJwePayload = {
|
|
202
202
|
iat: 0,
|
|
203
203
|
exp: 3600,
|
|
204
|
-
iss:
|
|
205
|
-
sub:
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
204
|
+
iss: 'DEMO_JWE',
|
|
205
|
+
sub: 'pii',
|
|
206
|
+
'ama-tokens': {
|
|
207
|
+
'{orderId}': 'RG287F',
|
|
208
|
+
'{lastName}': 'Doe'
|
|
209
209
|
}
|
|
210
210
|
};
|
|
211
211
|
/* eslint-enable @typescript-eslint/naming-convention */ expectedJweHeader = {
|
|
212
|
-
alg:
|
|
213
|
-
enc:
|
|
214
|
-
typ:
|
|
215
|
-
kid:
|
|
216
|
-
iss:
|
|
217
|
-
sub:
|
|
212
|
+
alg: 'RSA-OAEP-256',
|
|
213
|
+
enc: 'A256GCM',
|
|
214
|
+
typ: 'JWE',
|
|
215
|
+
kid: 'TEST',
|
|
216
|
+
iss: 'DEMO_JWE',
|
|
217
|
+
sub: 'pii'
|
|
218
218
|
};
|
|
219
219
|
expectedIv = new Uint8Array([
|
|
220
220
|
21,
|
|
@@ -644,7 +644,7 @@ describe("JSON Web Encryption Token", function() {
|
|
|
644
644
|
]);
|
|
645
645
|
global.window = {
|
|
646
646
|
btoa: function(data) {
|
|
647
|
-
return Buffer.from(data,
|
|
647
|
+
return Buffer.from(data, 'ascii').toString('base64');
|
|
648
648
|
},
|
|
649
649
|
crypto: {
|
|
650
650
|
getRandomValues: jest.fn().mockReturnValue(expectedIv),
|
|
@@ -658,25 +658,25 @@ describe("JSON Web Encryption Token", function() {
|
|
|
658
658
|
return [
|
|
659
659
|
4,
|
|
660
660
|
(0, _jsontoken.createJweEncoder)(96)({
|
|
661
|
-
publicKey:
|
|
662
|
-
keyId:
|
|
661
|
+
publicKey: 'myPublicKey',
|
|
662
|
+
keyId: 'TEST'
|
|
663
663
|
}, expectedJwePayload, [
|
|
664
|
-
|
|
665
|
-
|
|
664
|
+
'iss',
|
|
665
|
+
'sub'
|
|
666
666
|
])
|
|
667
667
|
];
|
|
668
668
|
case 1:
|
|
669
669
|
jweToken = _state.sent();
|
|
670
670
|
global.window = undefined;
|
|
671
|
-
_jweToken_split = _sliced_to_array(jweToken.split(
|
|
672
|
-
expect(decodeURI(Buffer.from((0, _jsontoken.base64DecodeUrl)(jweHeader),
|
|
673
|
-
expect(Buffer.from((0, _jsontoken.base64DecodeUrl)(jweEncryptedKey),
|
|
674
|
-
expect(Buffer.from((0, _jsontoken.base64DecodeUrl)(iv),
|
|
675
|
-
decipher = crypto.createDecipheriv(
|
|
671
|
+
_jweToken_split = _sliced_to_array(jweToken.split('.'), 5), jweHeader = _jweToken_split[0], jweEncryptedKey = _jweToken_split[1], iv = _jweToken_split[2], cipherContent = _jweToken_split[3], authenticationTag = _jweToken_split[4];
|
|
672
|
+
expect(decodeURI(Buffer.from((0, _jsontoken.base64DecodeUrl)(jweHeader), 'base64').toString())).toEqual(JSON.stringify(expectedJweHeader));
|
|
673
|
+
expect(Buffer.from((0, _jsontoken.base64DecodeUrl)(jweEncryptedKey), 'base64')).toEqual(Buffer.from(expectedJweEncryptedKey));
|
|
674
|
+
expect(Buffer.from((0, _jsontoken.base64DecodeUrl)(iv), 'base64')).toEqual(Buffer.from(expectedIv));
|
|
675
|
+
decipher = crypto.createDecipheriv('aes-256-gcm', cek, Buffer.from((0, _jsontoken.base64DecodeUrl)(iv), 'base64'), {
|
|
676
676
|
authTagLength: 12
|
|
677
677
|
});
|
|
678
|
-
decipher.setAuthTag(Buffer.from((0, _jsontoken.base64DecodeUrl)(authenticationTag),
|
|
679
|
-
decrypted = decipher.update(Buffer.from((0, _jsontoken.base64DecodeUrl)(cipherContent),
|
|
678
|
+
decipher.setAuthTag(Buffer.from((0, _jsontoken.base64DecodeUrl)(authenticationTag), 'base64'));
|
|
679
|
+
decrypted = decipher.update(Buffer.from((0, _jsontoken.base64DecodeUrl)(cipherContent), 'base64'));
|
|
680
680
|
decrypted += decipher.final();
|
|
681
681
|
expect(decrypted.toString()).toEqual(JSON.stringify(expectedJwePayload));
|
|
682
682
|
return [
|
|
@@ -193,10 +193,10 @@ function _ts_generator(thisArg, body) {
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
import { ExceptionReply } from
|
|
197
|
-
import { ReviverReply } from
|
|
198
|
-
import { extractQueryParams, filterUndefinedValues, getResponseReviver, prepareUrl, processFormData, tokenizeRequestOptions } from
|
|
199
|
-
import { EmptyResponseError } from
|
|
196
|
+
import { ExceptionReply } from '../plugins/exception';
|
|
197
|
+
import { ReviverReply } from '../plugins/reviver';
|
|
198
|
+
import { extractQueryParams, filterUndefinedValues, getResponseReviver, prepareUrl, processFormData, tokenizeRequestOptions } from '../fwk/api.helpers';
|
|
199
|
+
import { EmptyResponseError } from '../fwk/errors';
|
|
200
200
|
var DEFAULT_OPTIONS = {
|
|
201
201
|
replyPlugins: [
|
|
202
202
|
new ReviverReply(),
|
|
@@ -358,7 +358,7 @@ var DEFAULT_OPTIONS = {
|
|
|
358
358
|
return _ts_generator(this, function(_state) {
|
|
359
359
|
switch(_state.label){
|
|
360
360
|
case 0:
|
|
361
|
-
origin = options.headers.get(
|
|
361
|
+
origin = options.headers.get('Origin');
|
|
362
362
|
_state.label = 1;
|
|
363
363
|
case 1:
|
|
364
364
|
_state.trys.push([
|
|
@@ -374,7 +374,7 @@ var DEFAULT_OPTIONS = {
|
|
|
374
374
|
var metadataSignal = (_options_metadata = options.metadata) === null || _options_metadata === void 0 ? void 0 : _options_metadata.signal;
|
|
375
375
|
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
376
376
|
var subscription = _this.options.httpClient.request(options.method, url, _object_spread_props(_object_spread({}, options), {
|
|
377
|
-
observe:
|
|
377
|
+
observe: 'response',
|
|
378
378
|
headers: headers
|
|
379
379
|
})).subscribe({
|
|
380
380
|
next: function(res) {
|
|
@@ -388,7 +388,7 @@ var DEFAULT_OPTIONS = {
|
|
|
388
388
|
}
|
|
389
389
|
});
|
|
390
390
|
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
391
|
-
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.addEventListener(
|
|
391
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.addEventListener('abort', function() {
|
|
392
392
|
subscription.unsubscribe();
|
|
393
393
|
reject(metadataSignal.reason);
|
|
394
394
|
});
|
|
@@ -406,7 +406,7 @@ var DEFAULT_OPTIONS = {
|
|
|
406
406
|
];
|
|
407
407
|
case 3:
|
|
408
408
|
e = _state.sent();
|
|
409
|
-
exception = new EmptyResponseError(e.message ||
|
|
409
|
+
exception = new EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
|
|
410
410
|
apiName: apiName,
|
|
411
411
|
operationId: operationId,
|
|
412
412
|
url: url,
|
|
@@ -76,7 +76,7 @@ function _object_spread_props(target, source) {
|
|
|
76
76
|
}
|
|
77
77
|
return target;
|
|
78
78
|
}
|
|
79
|
-
import { extractQueryParams, filterUndefinedValues, prepareUrl, processFormData, tokenizeRequestOptions } from
|
|
79
|
+
import { extractQueryParams, filterUndefinedValues, prepareUrl, processFormData, tokenizeRequestOptions } from '../fwk/api.helpers';
|
|
80
80
|
var DEFAULT_OPTIONS = {
|
|
81
81
|
replyPlugins: [],
|
|
82
82
|
requestPlugins: [],
|
|
@@ -98,8 +98,8 @@ var isPromise = function(value) {
|
|
|
98
98
|
function ApiBeaconClient(options) {
|
|
99
99
|
_class_call_check(this, ApiBeaconClient);
|
|
100
100
|
/** @inheritdoc */ _define_property(this, "options", void 0);
|
|
101
|
-
if (typeof navigator ===
|
|
102
|
-
throw new Error(
|
|
101
|
+
if (typeof navigator === 'undefined' || !navigator.sendBeacon) {
|
|
102
|
+
throw new Error('Beacon API is not supported in this context');
|
|
103
103
|
}
|
|
104
104
|
this.options = _object_spread({}, DEFAULT_OPTIONS, options);
|
|
105
105
|
}
|
|
@@ -113,7 +113,7 @@ var isPromise = function(value) {
|
|
|
113
113
|
{
|
|
114
114
|
key: "getRequestOptions",
|
|
115
115
|
value: /** @inheritdoc */ function getRequestOptions(options) {
|
|
116
|
-
if (options.method.toUpperCase() !==
|
|
116
|
+
if (options.method.toUpperCase() !== 'POST') {
|
|
117
117
|
throw new Error("Unsupported method: ".concat(options.method, ". The beacon API only supports POST."));
|
|
118
118
|
}
|
|
119
119
|
var opts = _object_spread_props(_object_spread({}, options), {
|
|
@@ -191,7 +191,7 @@ var isPromise = function(value) {
|
|
|
191
191
|
key: "processCall",
|
|
192
192
|
value: /** @inheritdoc */ function processCall(url, options, _apiType, _apiName, _revivers, _operationId) {
|
|
193
193
|
var headers = _object_spread({
|
|
194
|
-
type:
|
|
194
|
+
type: 'application/json'
|
|
195
195
|
}, options.headers.entries());
|
|
196
196
|
var blob = new Blob(options.body ? [
|
|
197
197
|
JSON.stringify(options.body)
|
|
@@ -225,10 +225,10 @@ function _ts_generator(thisArg, body) {
|
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
import { ExceptionReply } from
|
|
229
|
-
import { ReviverReply } from
|
|
230
|
-
import { extractQueryParams, filterUndefinedValues, getResponseReviver, prepareUrl, processFormData, tokenizeRequestOptions } from
|
|
231
|
-
import { CanceledCallError, EmptyResponseError, ResponseJSONParseError } from
|
|
228
|
+
import { ExceptionReply } from '../plugins/exception';
|
|
229
|
+
import { ReviverReply } from '../plugins/reviver';
|
|
230
|
+
import { extractQueryParams, filterUndefinedValues, getResponseReviver, prepareUrl, processFormData, tokenizeRequestOptions } from '../fwk/api.helpers';
|
|
231
|
+
import { CanceledCallError, EmptyResponseError, ResponseJSONParseError } from '../fwk/errors';
|
|
232
232
|
var DEFAULT_OPTIONS = {
|
|
233
233
|
replyPlugins: [
|
|
234
234
|
new ReviverReply(),
|
|
@@ -390,7 +390,7 @@ var DEFAULT_OPTIONS = {
|
|
|
390
390
|
return _ts_generator(this, function(_state) {
|
|
391
391
|
switch(_state.label){
|
|
392
392
|
case 0:
|
|
393
|
-
origin = options.headers.get(
|
|
393
|
+
origin = options.headers.get('Origin');
|
|
394
394
|
_state.label = 1;
|
|
395
395
|
case 1:
|
|
396
396
|
_state.trys.push([
|
|
@@ -403,7 +403,7 @@ var DEFAULT_OPTIONS = {
|
|
|
403
403
|
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.throwIfAborted();
|
|
404
404
|
controller = new AbortController();
|
|
405
405
|
options.signal = controller.signal;
|
|
406
|
-
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.addEventListener(
|
|
406
|
+
metadataSignal === null || metadataSignal === void 0 ? void 0 : metadataSignal.addEventListener('abort', function() {
|
|
407
407
|
return controller.abort();
|
|
408
408
|
});
|
|
409
409
|
loadedPlugins = [];
|
|
@@ -481,7 +481,7 @@ var DEFAULT_OPTIONS = {
|
|
|
481
481
|
if (_instanceof(e, CanceledCallError)) {
|
|
482
482
|
exception = e;
|
|
483
483
|
} else {
|
|
484
|
-
exception = new EmptyResponseError(e.message ||
|
|
484
|
+
exception = new EmptyResponseError(e.message || 'Fail to Fetch', undefined, {
|
|
485
485
|
apiName: apiName,
|
|
486
486
|
operationId: operationId,
|
|
487
487
|
url: url,
|
|
@@ -496,7 +496,7 @@ var DEFAULT_OPTIONS = {
|
|
|
496
496
|
try {
|
|
497
497
|
root = body ? JSON.parse(body) : undefined;
|
|
498
498
|
} catch (e) {
|
|
499
|
-
exception = new ResponseJSONParseError(e.message ||
|
|
499
|
+
exception = new ResponseJSONParseError(e.message || 'Fail to parse response body', response && response.status || 0, body, {
|
|
500
500
|
apiName: apiName,
|
|
501
501
|
operationId: operationId,
|
|
502
502
|
url: url,
|
package/esm2015/clients/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './api-beacon-client';
|
|
2
|
+
export * from './api-fetch-client';
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable no-console */ import { getResponseReviver } from
|
|
2
|
-
describe(
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable no-console */ import { getResponseReviver } from '@ama-sdk/core';
|
|
2
|
+
describe('getResponseReviver - revivers by status code', function() {
|
|
3
3
|
var revivers = {
|
|
4
4
|
202: jest.fn(),
|
|
5
5
|
201: jest.fn()
|
|
6
6
|
};
|
|
7
7
|
beforeEach(function() {
|
|
8
|
-
jest.spyOn(console,
|
|
8
|
+
jest.spyOn(console, 'error');
|
|
9
9
|
});
|
|
10
10
|
afterEach(function() {
|
|
11
11
|
jest.clearAllMocks();
|
|
12
12
|
});
|
|
13
|
-
it(
|
|
13
|
+
it('should not return a reviver for a non ok response', function() {
|
|
14
14
|
expect(getResponseReviver(revivers, {
|
|
15
15
|
status: 300,
|
|
16
16
|
ok: false
|
|
17
17
|
})).toBe(undefined);
|
|
18
18
|
});
|
|
19
|
-
it(
|
|
19
|
+
it('should return a reason but not reviver for a 204 No Content Response', function() {
|
|
20
20
|
expect(getResponseReviver(revivers, {
|
|
21
21
|
status: 204,
|
|
22
22
|
ok: true
|
|
23
23
|
})).toBe(undefined);
|
|
24
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
24
|
+
expect(console.error).toHaveBeenCalledWith('API status code error for unknown endpoint - 204 response is not defined in the API specification');
|
|
25
25
|
});
|
|
26
|
-
it(
|
|
26
|
+
it('should return the status code\'s reviver', function() {
|
|
27
27
|
expect(getResponseReviver(revivers, {
|
|
28
28
|
status: 202,
|
|
29
29
|
ok: true
|
|
30
|
-
},
|
|
30
|
+
}, 'myEndpoint')).toBe(revivers[202]);
|
|
31
31
|
expect(console.error).not.toHaveBeenCalled();
|
|
32
32
|
});
|
|
33
|
-
it(
|
|
33
|
+
it('should fallback on the first defined status if the status code\'s reviver is not defined', function() {
|
|
34
34
|
expect(getResponseReviver(revivers, {
|
|
35
35
|
status: undefined,
|
|
36
36
|
ok: true
|
|
37
|
-
},
|
|
38
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
37
|
+
}, 'myEndpoint')).toBe(revivers[201]);
|
|
38
|
+
expect(console.error).toHaveBeenCalledWith('API status code error for myEndpoint endpoint - Unknown undefined code returned by the API - Fallback to 201\'s reviver');
|
|
39
39
|
});
|
|
40
|
-
it(
|
|
40
|
+
it('should not fallback on 204 (No Content)\'s reviver', function() {
|
|
41
41
|
var reviversWith204 = {
|
|
42
42
|
204: jest.fn(),
|
|
43
43
|
206: jest.fn()
|
|
@@ -45,33 +45,33 @@ describe("getResponseReviver - revivers by status code", function() {
|
|
|
45
45
|
var fallback = getResponseReviver(reviversWith204, {
|
|
46
46
|
status: 201,
|
|
47
47
|
ok: true
|
|
48
|
-
},
|
|
48
|
+
}, 'myEndpoint');
|
|
49
49
|
expect(fallback).toBe(reviversWith204[206]);
|
|
50
50
|
expect(fallback).not.toBe(reviversWith204[204]);
|
|
51
|
-
expect(console.error).toHaveBeenCalledWith(
|
|
51
|
+
expect(console.error).toHaveBeenCalledWith('API status code error for myEndpoint endpoint - Unknown 201 code returned by the API - Fallback to 206\'s reviver');
|
|
52
52
|
});
|
|
53
|
-
it(
|
|
54
|
-
jest.spyOn(console,
|
|
53
|
+
it('should not fallback if the feature is deactivated', function() {
|
|
54
|
+
jest.spyOn(console, 'log');
|
|
55
55
|
expect(getResponseReviver(revivers, {
|
|
56
56
|
status: 206,
|
|
57
57
|
ok: true
|
|
58
|
-
},
|
|
58
|
+
}, 'myEndpoint', {
|
|
59
59
|
disableFallback: true,
|
|
60
60
|
log: console.log
|
|
61
61
|
})).toBe(undefined);
|
|
62
62
|
expect(console.error).not.toHaveBeenCalled();
|
|
63
|
-
expect(console.log).toHaveBeenCalledWith(
|
|
63
|
+
expect(console.log).toHaveBeenCalledWith('API status code error for myEndpoint endpoint - Missing 206 from API specification - fallback is deactivated, no revive will run on this response');
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
|
-
describe(
|
|
66
|
+
describe('getResponseReviver - reviver as function', function() {
|
|
67
67
|
var reviver = jest.fn();
|
|
68
|
-
it(
|
|
68
|
+
it('should not return a reviver for a non ok response', function() {
|
|
69
69
|
expect(getResponseReviver(reviver, {
|
|
70
70
|
status: 300,
|
|
71
71
|
ok: false
|
|
72
72
|
})).toBe(undefined);
|
|
73
73
|
});
|
|
74
|
-
it(
|
|
74
|
+
it('should only return the reviver if the endpoint reviver is a function or an undefined object', function() {
|
|
75
75
|
expect(getResponseReviver(reviver, {
|
|
76
76
|
status: 200,
|
|
77
77
|
ok: true
|
|
@@ -79,12 +79,12 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
79
79
|
*/ export function prepareUrl(url) {
|
|
80
80
|
var queryParameters = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
81
81
|
var queryPart = Object.keys(queryParameters).filter(function(name) {
|
|
82
|
-
return typeof queryParameters[name] !==
|
|
82
|
+
return typeof queryParameters[name] !== 'undefined';
|
|
83
83
|
}).map(function(name) {
|
|
84
84
|
return "".concat(name, "=").concat(queryParameters[name]);
|
|
85
|
-
}).join(
|
|
86
|
-
var paramsPrefix = url.indexOf(
|
|
87
|
-
return url + (!queryPart ?
|
|
85
|
+
}).join('&');
|
|
86
|
+
var paramsPrefix = url.indexOf('?') > -1 ? '&' : '?';
|
|
87
|
+
return url + (!queryPart ? '' : paramsPrefix + queryPart);
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Returns a map containing the query parameters
|
|
@@ -92,10 +92,10 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
92
92
|
* @param names
|
|
93
93
|
*/ export function extractQueryParams(data, names) {
|
|
94
94
|
return names.filter(function(name) {
|
|
95
|
-
return typeof data[name] !==
|
|
95
|
+
return typeof data[name] !== 'undefined' && data[name] !== null;
|
|
96
96
|
}).reduce(function(acc, name) {
|
|
97
97
|
var prop = data[name];
|
|
98
|
-
acc[name] = typeof prop.toJSON ===
|
|
98
|
+
acc[name] = typeof prop.toJSON === 'function' ? prop.toJSON() : prop.toString();
|
|
99
99
|
return acc;
|
|
100
100
|
}, {});
|
|
101
101
|
}
|
|
@@ -105,7 +105,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
105
105
|
* @returns an object without undefined values
|
|
106
106
|
*/ export function filterUndefinedValues(object) {
|
|
107
107
|
return !object ? {} : Object.keys(object).filter(function(objectKey) {
|
|
108
|
-
return typeof object[objectKey] !==
|
|
108
|
+
return typeof object[objectKey] !== 'undefined';
|
|
109
109
|
}).reduce(function(acc, objectKey) {
|
|
110
110
|
acc[objectKey] = object[objectKey];
|
|
111
111
|
return acc;
|
|
@@ -120,7 +120,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
120
120
|
* @param type
|
|
121
121
|
*/ export function processFormData(data, type) {
|
|
122
122
|
var encodedData;
|
|
123
|
-
/* eslint-disable guard-for-in */ if (type ===
|
|
123
|
+
/* eslint-disable guard-for-in */ if (type === 'multipart/form-data') {
|
|
124
124
|
var formData = new FormData();
|
|
125
125
|
for(var i in data){
|
|
126
126
|
formData.append(i, data[i]);
|
|
@@ -131,7 +131,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
131
131
|
for(var i1 in data){
|
|
132
132
|
formData1.push("".concat(i1, "=").concat(encodeURIComponent(data[i1])));
|
|
133
133
|
}
|
|
134
|
-
encodedData = formData1.join(
|
|
134
|
+
encodedData = formData1.join('&');
|
|
135
135
|
}
|
|
136
136
|
/* eslint-enable guard-for-in */ return encodedData;
|
|
137
137
|
}
|
|
@@ -188,12 +188,12 @@ endpoint) {
|
|
|
188
188
|
disableFallback: false,
|
|
189
189
|
log: console.error
|
|
190
190
|
};
|
|
191
|
-
var logPrefix = "API status code error for ".concat(endpoint ||
|
|
191
|
+
var logPrefix = "API status code error for ".concat(endpoint || 'unknown', " endpoint");
|
|
192
192
|
var logMsg = options.log || function() {};
|
|
193
193
|
if (!response || !response.ok) {
|
|
194
194
|
return undefined;
|
|
195
195
|
}
|
|
196
|
-
if (typeof revivers ===
|
|
196
|
+
if (typeof revivers === 'function' || typeof revivers === 'undefined') {
|
|
197
197
|
return revivers;
|
|
198
198
|
}
|
|
199
199
|
if (response.status && revivers[response.status]) {
|
|
@@ -219,7 +219,7 @@ endpoint) {
|
|
|
219
219
|
statusCode: Number.MAX_SAFE_INTEGER,
|
|
220
220
|
reviver: undefined
|
|
221
221
|
});
|
|
222
|
-
var fallbackLog = Number.MAX_SAFE_INTEGER !== fallback.statusCode ? "Fallback to ".concat(fallback.statusCode, "'s reviver") :
|
|
223
|
-
logMsg("".concat(logPrefix, " - Unknown ").concat(response.status ||
|
|
222
|
+
var fallbackLog = Number.MAX_SAFE_INTEGER !== fallback.statusCode ? "Fallback to ".concat(fallback.statusCode, "'s reviver") : 'No fallback found';
|
|
223
|
+
logMsg("".concat(logPrefix, " - Unknown ").concat(response.status || 'undefined', " code returned by the API - ").concat(fallbackLog));
|
|
224
224
|
return fallback.reviver;
|
|
225
225
|
}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Check if the object is an Api Client object
|
|
3
3
|
* @param client object to check
|
|
4
4
|
*/ export function isApiClient(client) {
|
|
5
|
-
return client && !!client.options && typeof client.extractQueryParams ===
|
|
5
|
+
return client && !!client.options && typeof client.extractQueryParams === 'function' && typeof client.prepareOptions === 'function' && typeof client.prepareUrl === 'function' && typeof client.processFormData === 'function' && typeof client.processCall === 'function';
|
|
6
6
|
}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Determine if object passed to the constructor is valid
|
|
3
3
|
* @param args
|
|
4
4
|
*/ export function isConstructorObject(args) {
|
|
5
|
-
return !!args && args.length === 1 && !!args[0] && typeof args[0] ===
|
|
5
|
+
return !!args && args.length === 1 && !!args[0] && typeof args[0] === 'object';
|
|
6
6
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './base-api-constructor';
|
|
2
|
+
export * from './api-client';
|
package/esm2015/fwk/date.js
CHANGED
|
@@ -170,7 +170,7 @@ export var _NativeDateClass = Date;
|
|
|
170
170
|
*/ export function pad(val) {
|
|
171
171
|
var digits = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2;
|
|
172
172
|
var str = "".concat(val);
|
|
173
|
-
return
|
|
173
|
+
return '0'.repeat(Math.max(0, digits - str.length)) + str;
|
|
174
174
|
}
|
|
175
175
|
export var CommonDate = /*#__PURE__*/ function(Date1) {
|
|
176
176
|
"use strict";
|
|
@@ -182,15 +182,15 @@ export var CommonDate = /*#__PURE__*/ function(Date1) {
|
|
|
182
182
|
}
|
|
183
183
|
_class_call_check(this, CommonDate);
|
|
184
184
|
if (args) {
|
|
185
|
-
if (typeof args[0] ===
|
|
186
|
-
var idxT = args[0].lastIndexOf(
|
|
185
|
+
if (typeof args[0] === 'string') {
|
|
186
|
+
var idxT = args[0].lastIndexOf('T');
|
|
187
187
|
// TZD = time zone designator (Z or +hh:mm or -hh:mm)
|
|
188
|
-
var idx = args[0].lastIndexOf(
|
|
188
|
+
var idx = args[0].lastIndexOf('Z');
|
|
189
189
|
if (idx < 0) {
|
|
190
|
-
idx = args[0].lastIndexOf(
|
|
190
|
+
idx = args[0].lastIndexOf('+');
|
|
191
191
|
}
|
|
192
192
|
if (idx < 0 && idxT > 0) {
|
|
193
|
-
var relativeIdx = args[0].substring(idxT).lastIndexOf(
|
|
193
|
+
var relativeIdx = args[0].substring(idxT).lastIndexOf('-');
|
|
194
194
|
idx = relativeIdx > 0 ? relativeIdx + idxT : relativeIdx;
|
|
195
195
|
}
|
|
196
196
|
if (idx > 0) {
|
|
@@ -198,7 +198,7 @@ export var CommonDate = /*#__PURE__*/ function(Date1) {
|
|
|
198
198
|
}
|
|
199
199
|
var TIME_ZONE_OFFSET = _construct(Date, _to_consumable_array(args)).getTimezoneOffset();
|
|
200
200
|
if (idxT > 0) {
|
|
201
|
-
args[0] += "".concat(TIME_ZONE_OFFSET < 0 ?
|
|
201
|
+
args[0] += "".concat(TIME_ZONE_OFFSET < 0 ? '+' : '-').concat(pad(Math.floor(Math.abs(TIME_ZONE_OFFSET / 60))), ":").concat(pad(Math.abs(TIME_ZONE_OFFSET % 60)));
|
|
202
202
|
}
|
|
203
203
|
} else if (_instanceof(args[0], CommonDate)) {
|
|
204
204
|
args[0] = args[0];
|
|
@@ -222,7 +222,7 @@ export var CommonDate = /*#__PURE__*/ function(Date1) {
|
|
|
222
222
|
}(_wrap_native_super(Date));
|
|
223
223
|
export var utils;
|
|
224
224
|
(function(utils) {
|
|
225
|
-
|
|
225
|
+
'use strict';
|
|
226
226
|
var _$Date = /*#__PURE__*/ function(CommonDate) {
|
|
227
227
|
_inherits(Date1, CommonDate);
|
|
228
228
|
var _super = _create_super(Date1);
|
|
@@ -231,7 +231,7 @@ export var utils;
|
|
|
231
231
|
args[_key] = arguments[_key];
|
|
232
232
|
}
|
|
233
233
|
_class_call_check(this, Date1);
|
|
234
|
-
if (args && typeof args[0] ===
|
|
234
|
+
if (args && typeof args[0] === 'string' && args[0].lastIndexOf('T') < 0) {
|
|
235
235
|
args[0] = "".concat(args[0], "T00:00:00Z");
|
|
236
236
|
} else if (_instanceof(args[0], _NativeDateClass)) {
|
|
237
237
|
args[0] = "".concat(args[0].getFullYear(), "-").concat(pad(args[0].getMonth() + 1), "-").concat(pad(args[0].getDate()), "T00:00:00Z");
|
package/esm2015/fwk/date.spec.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { utils } from
|
|
2
|
-
describe(
|
|
3
|
-
it(
|
|
1
|
+
import { utils } from './date';
|
|
2
|
+
describe('DateTime', function() {
|
|
3
|
+
it('should support timestamp', function() {
|
|
4
4
|
var ts = new Date().getTime();
|
|
5
5
|
var dateUtils = new utils.DateTime(ts);
|
|
6
6
|
expect(dateUtils.getTime()).toEqual(ts);
|
|
7
7
|
});
|
|
8
|
-
it(
|
|
8
|
+
it('should support DateTime Utils', function() {
|
|
9
9
|
var originalDate = new utils.DateTime(new Date());
|
|
10
10
|
expect(new utils.DateTime(originalDate)).toEqual(originalDate);
|
|
11
11
|
});
|
|
12
|
-
it(
|
|
12
|
+
it('should support a copy constructor', function() {
|
|
13
13
|
var originalDate = new utils.DateTime(new Date());
|
|
14
14
|
expect(new utils.DateTime(originalDate)).toEqual(originalDate);
|
|
15
15
|
});
|
|
16
|
-
it(
|
|
16
|
+
it('should support json conversions', function() {
|
|
17
17
|
var originalDate = new utils.DateTime(new Date());
|
|
18
18
|
var jsonDate = JSON.parse(JSON.stringify(originalDate));
|
|
19
19
|
expect(new utils.DateTime(jsonDate)).toEqual(originalDate);
|
|
20
20
|
});
|
|
21
|
-
it(
|
|
22
|
-
var date1 =
|
|
21
|
+
it('should support date without time', function() {
|
|
22
|
+
var date1 = '1988-06-07';
|
|
23
23
|
var dateCompare = new Date(date1);
|
|
24
24
|
expect(new utils.DateTime(date1)).toEqual(dateCompare);
|
|
25
25
|
});
|
|
26
|
-
it(
|
|
27
|
-
var date1 =
|
|
28
|
-
var dateCompare = new Date(
|
|
26
|
+
it('should support datetime without timezone', function() {
|
|
27
|
+
var date1 = '2015-03-25T12:00:00Z';
|
|
28
|
+
var dateCompare = new Date('2015-03-25');
|
|
29
29
|
dateCompare.setHours(12);
|
|
30
30
|
dateCompare.setMinutes(0);
|
|
31
31
|
var dateUtils = new utils.DateTime(date1);
|
|
32
32
|
expect(dateUtils).toEqual(dateCompare);
|
|
33
33
|
});
|
|
34
|
-
it(
|
|
35
|
-
var date1 =
|
|
36
|
-
var date2 =
|
|
37
|
-
var dateCompare = new Date(
|
|
34
|
+
it('should ignore timezone of datetime', function() {
|
|
35
|
+
var date1 = '2015-03-25T12:00:00-02:00';
|
|
36
|
+
var date2 = '2015-03-25T12:00:00+05:00';
|
|
37
|
+
var dateCompare = new Date('2015-03-25T12:00:00Z');
|
|
38
38
|
dateCompare.setHours(12);
|
|
39
39
|
dateCompare.setMinutes(0);
|
|
40
40
|
expect(new utils.DateTime(date1)).toEqual(dateCompare);
|
|
41
41
|
expect(new utils.DateTime(date2)).toEqual(dateCompare);
|
|
42
42
|
});
|
|
43
|
-
it(
|
|
44
|
-
var dateStr1 =
|
|
45
|
-
var dateStr2 =
|
|
43
|
+
it('should handle daylight change', function() {
|
|
44
|
+
var dateStr1 = '2017-03-23T12:00:00Z';
|
|
45
|
+
var dateStr2 = '2017-04-01T12:00:00Z';
|
|
46
46
|
var date1 = new utils.DateTime(dateStr1);
|
|
47
47
|
var date2 = new utils.DateTime(dateStr2);
|
|
48
48
|
var compareDate1 = new Date(dateStr1);
|
|
@@ -50,28 +50,28 @@ describe("DateTime", function() {
|
|
|
50
50
|
expect(date1.getTimezoneOffset() - date2.getTimezoneOffset()).toBe(compareDate1.getTimezoneOffset() - compareDate2.getTimezoneOffset());
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
|
-
describe(
|
|
54
|
-
it(
|
|
53
|
+
describe('Date', function() {
|
|
54
|
+
it('should support timestamp', function() {
|
|
55
55
|
var ts = new Date().getTime();
|
|
56
56
|
var dateUtils = new utils.Date(ts);
|
|
57
57
|
expect(dateUtils.getTime()).toEqual(ts);
|
|
58
58
|
});
|
|
59
|
-
it(
|
|
59
|
+
it('should support Date Utils', function() {
|
|
60
60
|
var originalDate = new utils.Date(new Date());
|
|
61
61
|
expect(new utils.Date(originalDate)).toEqual(originalDate);
|
|
62
62
|
});
|
|
63
|
-
it(
|
|
63
|
+
it('should support a copy constructor', function() {
|
|
64
64
|
var originalDate = new utils.Date(new Date());
|
|
65
65
|
expect(new utils.Date(originalDate)).toEqual(originalDate);
|
|
66
66
|
});
|
|
67
|
-
it(
|
|
67
|
+
it('should support json conversions', function() {
|
|
68
68
|
var originalDate = new utils.Date(new Date());
|
|
69
69
|
var jsonDate = JSON.parse(JSON.stringify(originalDate));
|
|
70
70
|
expect(new utils.Date(jsonDate)).toEqual(originalDate);
|
|
71
71
|
});
|
|
72
|
-
it(
|
|
73
|
-
var date1 =
|
|
74
|
-
var dateCompare = new utils.DateTime(
|
|
72
|
+
it('should be converted to a Js DateTime', function() {
|
|
73
|
+
var date1 = '1988-06-07';
|
|
74
|
+
var dateCompare = new utils.DateTime('1988-06-07T00:00:00Z');
|
|
75
75
|
expect(new utils.Date(date1)).toEqual(dateCompare);
|
|
76
76
|
});
|
|
77
77
|
});
|