@aws-amplify/core 5.8.2 → 6.0.1-console-preview.f63250a.0
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/README.md +3 -0
- package/lib/Amplify.d.ts +18 -17
- package/lib/Amplify.js +9 -0
- package/lib/AwsClients/CognitoIdentity/base.d.ts +3 -10
- package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +3 -17
- package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +8 -8
- package/lib/AwsClients/CognitoIdentity/getId.d.ts +3 -17
- package/lib/AwsClients/Pinpoint/base.d.ts +2 -10
- package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +3 -17
- package/lib/AwsClients/Pinpoint/getInAppMessages.js +1 -1
- package/lib/AwsClients/Pinpoint/putEvents.d.ts +3 -17
- package/lib/AwsClients/Pinpoint/putEvents.js +6 -0
- package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +3 -17
- package/lib/AwsClients/Pinpoint/updateEndpoint.js +2 -2
- package/lib/Cache/AsyncStorageCache.d.ts +154 -0
- package/lib/Cache/AsyncStorageCache.js +744 -0
- package/lib/Cache/BrowserStorageCache.d.ts +166 -0
- package/lib/Cache/BrowserStorageCache.js +469 -0
- package/lib/Cache/InMemoryCache.d.ts +129 -0
- package/lib/Cache/InMemoryCache.js +349 -0
- package/lib/Cache/StorageCache.d.ts +39 -0
- package/lib/Cache/StorageCache.js +121 -0
- package/lib/Cache/Utils/CacheList.d.ts +89 -0
- package/lib/Cache/Utils/CacheList.js +196 -0
- package/lib/Cache/Utils/CacheUtils.d.ts +25 -0
- package/lib/Cache/Utils/CacheUtils.js +88 -0
- package/lib/Cache/Utils/index.d.ts +2 -0
- package/lib/Cache/Utils/index.js +16 -0
- package/lib/Cache/reactnative.d.ts +3 -0
- package/lib/Cache/reactnative.js +8 -0
- package/lib/Cache/types/Cache.d.ts +55 -0
- package/lib/Cache/types/Cache.js +4 -0
- package/lib/Cache/types/index.d.ts +1 -0
- package/lib/Cache/types/index.js +19 -0
- package/lib/ClientDevice/android.js +3 -2
- package/lib/ClientDevice/ios.d.ts +2 -2
- package/lib/ClientDevice/ios.js +3 -2
- package/lib/ClientDevice/reactnative.js +3 -2
- package/lib/Credentials.d.ts +1 -1
- package/lib/Credentials.js +2 -1
- package/lib/Errors.d.ts +19 -0
- package/lib/Errors.js +50 -1
- package/lib/Hub.js +1 -0
- package/lib/I18n/I18n.d.ts +29 -9
- package/lib/I18n/I18n.js +30 -5
- package/lib/I18n/index.d.ts +18 -5
- package/lib/I18n/index.js +35 -5
- package/lib/I18n/types.d.ts +4 -1
- package/lib/I18n/types.js +3 -0
- package/lib/JS.d.ts +6 -6
- package/lib/Logger/ConsoleLogger.d.ts +11 -11
- package/lib/OAuthHelper/GoogleOAuth.js +2 -1
- package/lib/Platform/detectFramework.js +2 -1
- package/lib/Platform/detection/Next.d.ts +1 -1
- package/lib/Platform/detection/React.js +1 -0
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/Providers/AWSCloudWatchProvider.d.ts +2 -2
- package/lib/Providers/AWSCloudWatchProvider.js +35 -12
- package/lib/RNComponents/index.d.ts +1 -1
- package/lib/RNComponents/reactnative.js +3 -2
- package/lib/ServiceWorker/ServiceWorker.d.ts +4 -4
- package/lib/ServiceWorker/ServiceWorker.js +37 -11
- package/lib/Signer.d.ts +14 -1
- package/lib/StorageHelper/cookieStorage.d.ts +13 -0
- package/lib/StorageHelper/cookieStorage.js +167 -0
- package/lib/StorageHelper/inMemoryStorage.d.ts +10 -0
- package/lib/StorageHelper/inMemoryStorage.js +82 -0
- package/lib/StorageHelper/index.d.ts +7 -3
- package/lib/StorageHelper/index.js +9 -1
- package/lib/StorageHelper/localStorage.d.ts +32 -0
- package/lib/StorageHelper/localStorage.js +114 -0
- package/lib/StorageHelper/reactnative.d.ts +71 -1
- package/lib/StorageHelper/reactnative.js +154 -10
- package/lib/StorageHelper/sessionStorage.d.ts +32 -0
- package/lib/StorageHelper/sessionStorage.js +114 -0
- package/lib/UniversalStorage/index.d.ts +2 -2
- package/lib/Util/BackgroundProcessManager.d.ts +2 -2
- package/lib/Util/BackgroundProcessManager.js +1 -0
- package/lib/Util/DateUtils.d.ts +12 -1
- package/lib/Util/Reachability.js +7 -5
- package/lib/Util/Reachability.native.d.ts +3 -2
- package/lib/Util/StringUtils.js +3 -10
- package/lib/Util/errors/AssertError.d.ts +2 -0
- package/lib/Util/errors/AssertError.js +11 -0
- package/lib/clients/middleware/retry/defaultRetryDecider.d.ts +1 -1
- package/lib/clients/middleware/retry/defaultRetryDecider.js +17 -13
- package/lib/clients/middleware/retry/isClockSkewError.js +1 -1
- package/lib/clients/middleware/retry/middleware.d.ts +1 -1
- package/lib/clients/middleware/retry/middleware.js +13 -13
- package/lib/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +1 -1
- package/lib/clients/serde/responseInfo.js +1 -1
- package/lib/clients/types/aws.d.ts +4 -0
- package/lib/clients/types/index.d.ts +1 -1
- package/lib/constants.d.ts +7 -0
- package/lib/constants.js +9 -1
- package/lib/index.d.ts +18 -4
- package/lib/index.js +32 -5
- package/lib/parseAWSExports.d.ts +1 -1
- package/lib/singleton/Auth/index.d.ts +30 -0
- package/lib/singleton/Auth/index.js +133 -0
- package/lib/singleton/Auth/types.d.ts +95 -0
- package/lib/singleton/Auth/types.js +6 -0
- package/lib/singleton/Auth/utils/index.d.ts +5 -0
- package/lib/singleton/Auth/utils/index.js +52 -0
- package/lib/singleton/Storage/types.d.ts +14 -0
- package/lib/singleton/Storage/types.js +4 -0
- package/lib/singleton/index.d.ts +46 -0
- package/lib/singleton/index.js +147 -0
- package/lib/singleton/types.d.ts +21 -0
- package/lib/singleton/types.js +4 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types.d.ts +31 -1
- package/lib/types/types.js +2 -0
- package/lib-esm/Amplify.d.ts +18 -17
- package/lib-esm/Amplify.js +9 -0
- package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +3 -10
- package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +3 -17
- package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +8 -8
- package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +3 -17
- package/lib-esm/AwsClients/Pinpoint/base.d.ts +2 -10
- package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +3 -17
- package/lib-esm/AwsClients/Pinpoint/getInAppMessages.js +1 -1
- package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +3 -17
- package/lib-esm/AwsClients/Pinpoint/putEvents.js +6 -0
- package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +3 -17
- package/lib-esm/AwsClients/Pinpoint/updateEndpoint.js +2 -2
- package/lib-esm/Cache/AsyncStorageCache.d.ts +154 -0
- package/lib-esm/Cache/AsyncStorageCache.js +737 -0
- package/lib-esm/Cache/BrowserStorageCache.d.ts +166 -0
- package/lib-esm/Cache/BrowserStorageCache.js +466 -0
- package/lib-esm/Cache/InMemoryCache.d.ts +129 -0
- package/lib-esm/Cache/InMemoryCache.js +346 -0
- package/lib-esm/Cache/StorageCache.d.ts +39 -0
- package/lib-esm/Cache/StorageCache.js +118 -0
- package/lib-esm/Cache/Utils/CacheList.d.ts +89 -0
- package/lib-esm/Cache/Utils/CacheList.js +194 -0
- package/lib-esm/Cache/Utils/CacheUtils.d.ts +25 -0
- package/lib-esm/Cache/Utils/CacheUtils.js +81 -0
- package/lib-esm/Cache/Utils/index.d.ts +2 -0
- package/lib-esm/Cache/Utils/index.js +4 -0
- package/lib-esm/Cache/reactnative.d.ts +3 -0
- package/lib-esm/Cache/reactnative.js +6 -0
- package/lib-esm/Cache/types/Cache.d.ts +55 -0
- package/lib-esm/Cache/types/Cache.js +3 -0
- package/lib-esm/Cache/types/index.d.ts +1 -0
- package/lib-esm/Cache/types/index.js +3 -0
- package/lib-esm/ClientDevice/android.js +1 -0
- package/lib-esm/ClientDevice/ios.d.ts +2 -2
- package/lib-esm/ClientDevice/ios.js +1 -0
- package/lib-esm/ClientDevice/reactnative.js +1 -0
- package/lib-esm/Credentials.d.ts +1 -1
- package/lib-esm/Credentials.js +2 -1
- package/lib-esm/Errors.d.ts +19 -0
- package/lib-esm/Errors.js +49 -0
- package/lib-esm/Hub.js +1 -0
- package/lib-esm/I18n/I18n.d.ts +29 -9
- package/lib-esm/I18n/I18n.js +30 -5
- package/lib-esm/I18n/index.d.ts +18 -5
- package/lib-esm/I18n/index.js +35 -5
- package/lib-esm/I18n/types.d.ts +4 -1
- package/lib-esm/I18n/types.js +3 -0
- package/lib-esm/JS.d.ts +6 -6
- package/lib-esm/Logger/ConsoleLogger.d.ts +11 -11
- package/lib-esm/OAuthHelper/GoogleOAuth.js +2 -1
- package/lib-esm/Platform/detectFramework.js +2 -1
- package/lib-esm/Platform/detection/Next.d.ts +1 -1
- package/lib-esm/Platform/detection/React.js +1 -0
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/Providers/AWSCloudWatchProvider.d.ts +2 -2
- package/lib-esm/Providers/AWSCloudWatchProvider.js +33 -10
- package/lib-esm/RNComponents/index.d.ts +1 -1
- package/lib-esm/RNComponents/reactnative.js +1 -0
- package/lib-esm/ServiceWorker/ServiceWorker.d.ts +4 -4
- package/lib-esm/ServiceWorker/ServiceWorker.js +37 -11
- package/lib-esm/Signer.d.ts +14 -1
- package/lib-esm/StorageHelper/cookieStorage.d.ts +13 -0
- package/lib-esm/StorageHelper/cookieStorage.js +141 -0
- package/lib-esm/StorageHelper/inMemoryStorage.d.ts +10 -0
- package/lib-esm/StorageHelper/inMemoryStorage.js +79 -0
- package/lib-esm/StorageHelper/index.d.ts +7 -3
- package/lib-esm/StorageHelper/index.js +4 -0
- package/lib-esm/StorageHelper/localStorage.d.ts +32 -0
- package/lib-esm/StorageHelper/localStorage.js +111 -0
- package/lib-esm/StorageHelper/reactnative.d.ts +71 -1
- package/lib-esm/StorageHelper/reactnative.js +153 -9
- package/lib-esm/StorageHelper/sessionStorage.d.ts +32 -0
- package/lib-esm/StorageHelper/sessionStorage.js +111 -0
- package/lib-esm/UniversalStorage/index.d.ts +2 -2
- package/lib-esm/Util/BackgroundProcessManager.d.ts +2 -2
- package/lib-esm/Util/BackgroundProcessManager.js +1 -0
- package/lib-esm/Util/DateUtils.d.ts +12 -1
- package/lib-esm/Util/Reachability.js +5 -3
- package/lib-esm/Util/Reachability.native.d.ts +3 -2
- package/lib-esm/Util/StringUtils.js +3 -10
- package/lib-esm/Util/errors/AssertError.d.ts +2 -0
- package/lib-esm/Util/errors/AssertError.js +7 -0
- package/lib-esm/clients/middleware/retry/defaultRetryDecider.d.ts +1 -1
- package/lib-esm/clients/middleware/retry/defaultRetryDecider.js +17 -13
- package/lib-esm/clients/middleware/retry/isClockSkewError.js +1 -1
- package/lib-esm/clients/middleware/retry/middleware.d.ts +1 -1
- package/lib-esm/clients/middleware/retry/middleware.js +13 -13
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +1 -1
- package/lib-esm/clients/serde/responseInfo.js +1 -1
- package/lib-esm/clients/types/aws.d.ts +4 -0
- package/lib-esm/clients/types/index.d.ts +1 -1
- package/lib-esm/constants.d.ts +7 -0
- package/lib-esm/constants.js +8 -0
- package/lib-esm/index.d.ts +18 -4
- package/lib-esm/index.js +15 -3
- package/lib-esm/parseAWSExports.d.ts +1 -1
- package/lib-esm/singleton/Auth/index.d.ts +30 -0
- package/lib-esm/singleton/Auth/index.js +129 -0
- package/lib-esm/singleton/Auth/types.d.ts +95 -0
- package/lib-esm/singleton/Auth/types.js +5 -0
- package/lib-esm/singleton/Auth/utils/index.d.ts +5 -0
- package/lib-esm/singleton/Auth/utils/index.js +45 -0
- package/lib-esm/singleton/Storage/types.d.ts +14 -0
- package/lib-esm/singleton/Storage/types.js +3 -0
- package/lib-esm/singleton/index.d.ts +46 -0
- package/lib-esm/singleton/index.js +143 -0
- package/lib-esm/singleton/types.d.ts +21 -0
- package/lib-esm/singleton/types.js +3 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/types.d.ts +31 -1
- package/lib-esm/types/types.js +2 -0
- package/package.json +38 -15
- package/src/Amplify.ts +9 -3
- package/src/AwsClients/CognitoIdentity/base.ts +2 -1
- package/src/AwsClients/CognitoIdentity/getCredentialsForIdentity.ts +13 -6
- package/src/AwsClients/Pinpoint/base.ts +6 -2
- package/src/AwsClients/Pinpoint/getInAppMessages.ts +1 -1
- package/src/AwsClients/Pinpoint/putEvents.ts +6 -0
- package/src/AwsClients/Pinpoint/updateEndpoint.ts +2 -2
- package/src/Cache/AsyncStorageCache.ts +500 -0
- package/src/Cache/BrowserStorageCache.ts +517 -0
- package/src/Cache/CHANGELOG.md +1227 -0
- package/src/Cache/InMemoryCache.ts +354 -0
- package/src/Cache/StorageCache.ts +157 -0
- package/src/Cache/Utils/CacheList.ts +198 -0
- package/src/Cache/Utils/CacheUtils.ts +92 -0
- package/src/Cache/Utils/index.ts +11 -0
- package/src/Cache/reactnative.ts +9 -0
- package/src/Cache/types/Cache.ts +75 -0
- package/src/Cache/types/index.ts +4 -0
- package/src/ClientDevice/android.ts +1 -1
- package/src/ClientDevice/ios.ts +2 -2
- package/src/ClientDevice/reactnative.ts +1 -1
- package/src/Credentials.ts +19 -17
- package/src/Errors.ts +41 -0
- package/src/Hub.ts +1 -0
- package/src/I18n/I18n.ts +40 -12
- package/src/I18n/index.ts +45 -12
- package/src/I18n/types.ts +3 -0
- package/src/JS.ts +24 -17
- package/src/Logger/ConsoleLogger.ts +10 -10
- package/src/OAuthHelper/FacebookOAuth.ts +2 -2
- package/src/OAuthHelper/GoogleOAuth.ts +9 -6
- package/src/Platform/detectFramework.ts +1 -1
- package/src/Platform/detection/React.ts +5 -3
- package/src/Platform/version.ts +1 -1
- package/src/Providers/AWSCloudWatchProvider.ts +39 -14
- package/src/RNComponents/index.ts +1 -1
- package/src/RNComponents/reactnative.ts +1 -1
- package/src/ServiceWorker/ServiceWorker.ts +58 -18
- package/src/Signer.ts +22 -3
- package/src/StorageHelper/cookieStorage.ts +99 -0
- package/src/StorageHelper/inMemoryStorage.ts +32 -0
- package/src/StorageHelper/index.ts +6 -1
- package/src/StorageHelper/localStorage.ts +60 -0
- package/src/StorageHelper/reactnative.ts +94 -14
- package/src/StorageHelper/sessionStorage.ts +60 -0
- package/src/Util/BackgroundProcessManager.ts +33 -9
- package/src/Util/DateUtils.ts +14 -5
- package/src/Util/Reachability.native.ts +3 -2
- package/src/Util/Reachability.ts +9 -7
- package/src/Util/Retry.ts +2 -1
- package/src/Util/StringUtils.ts +3 -10
- package/src/Util/errors/AssertError.ts +11 -0
- package/src/clients/handlers/fetch.ts +2 -2
- package/src/clients/middleware/retry/defaultRetryDecider.ts +12 -6
- package/src/clients/middleware/retry/isClockSkewError.ts +1 -1
- package/src/clients/middleware/retry/middleware.ts +9 -9
- package/src/clients/middleware/signing/middleware.ts +1 -1
- package/src/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.ts +1 -1
- package/src/clients/serde/responseInfo.ts +2 -1
- package/src/clients/types/aws.ts +10 -0
- package/src/clients/types/index.ts +1 -0
- package/src/constants.ts +16 -0
- package/src/global.d.ts +11 -0
- package/src/index.ts +66 -4
- package/src/parseAWSExports.ts +1 -1
- package/src/singleton/Auth/index.ts +113 -0
- package/src/singleton/Auth/types.ts +129 -0
- package/src/singleton/Auth/utils/index.ts +68 -0
- package/src/singleton/Storage/types.ts +21 -0
- package/src/singleton/index.ts +131 -0
- package/src/singleton/types.ts +48 -0
- package/src/types/types.ts +38 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import * as Cookies from 'js-cookie';
|
|
5
|
+
import {
|
|
6
|
+
CookieStorageData,
|
|
7
|
+
KeyValueStorageInterface,
|
|
8
|
+
SameSite,
|
|
9
|
+
} from '../types';
|
|
10
|
+
|
|
11
|
+
export class CookieStorage implements KeyValueStorageInterface {
|
|
12
|
+
domain?: string;
|
|
13
|
+
path: string;
|
|
14
|
+
expires?: number; // days;
|
|
15
|
+
secure?: boolean;
|
|
16
|
+
sameSite?: SameSite;
|
|
17
|
+
|
|
18
|
+
constructor(data: CookieStorageData = {}) {
|
|
19
|
+
if (data.domain) {
|
|
20
|
+
this.domain = data.domain;
|
|
21
|
+
}
|
|
22
|
+
if (data.path) {
|
|
23
|
+
this.path = data.path;
|
|
24
|
+
} else {
|
|
25
|
+
this.path = '/';
|
|
26
|
+
}
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(data, 'expires')) {
|
|
28
|
+
this.expires = data.expires;
|
|
29
|
+
} else {
|
|
30
|
+
this.expires = 365;
|
|
31
|
+
}
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(data, 'secure')) {
|
|
33
|
+
this.secure = data.secure;
|
|
34
|
+
} else {
|
|
35
|
+
this.secure = true;
|
|
36
|
+
}
|
|
37
|
+
if (data.hasOwnProperty('sameSite')) {
|
|
38
|
+
if (
|
|
39
|
+
!data.sameSite ||
|
|
40
|
+
!['strict', 'lax', 'none'].includes(data.sameSite)
|
|
41
|
+
) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
'The sameSite value of cookieStorage must be "lax", "strict" or "none".'
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (data.sameSite === 'none' && !this.secure) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
'sameSite = None requires the Secure attribute in latest browser versions.'
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
this.sameSite = data.sameSite;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
56
|
+
const options: CookieStorageData = {
|
|
57
|
+
path: this.path,
|
|
58
|
+
expires: this.expires,
|
|
59
|
+
domain: this.domain,
|
|
60
|
+
secure: this.secure,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (this.sameSite) {
|
|
64
|
+
options.sameSite = this.sameSite;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Cookies.set(key, value, options);
|
|
68
|
+
return Cookies.get(key);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async getItem(key: string): Promise<string> {
|
|
72
|
+
return Cookies.get(key);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async removeItem(key: string): Promise<void> {
|
|
76
|
+
const options: CookieStorageData = {
|
|
77
|
+
path: this.path,
|
|
78
|
+
expires: this.expires,
|
|
79
|
+
domain: this.domain,
|
|
80
|
+
secure: this.secure,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (this.sameSite) {
|
|
84
|
+
options.sameSite = this.sameSite;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
Cookies.remove(key, options);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async clear(): Promise<void> {
|
|
91
|
+
const cookies = Cookies.get();
|
|
92
|
+
const numKeys = Object.keys(cookies).length;
|
|
93
|
+
const promiseArray: Promise<void>[] = [];
|
|
94
|
+
for (let index = 0; index < numKeys; ++index) {
|
|
95
|
+
promiseArray.push(this.removeItem(Object.keys(cookies)[index]));
|
|
96
|
+
}
|
|
97
|
+
await Promise.all(promiseArray);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { KeyValueStorageInterface } from '../types';
|
|
5
|
+
|
|
6
|
+
class MemoryKeyValueStorageClass implements KeyValueStorageInterface {
|
|
7
|
+
myStorage: Record<string, string> = {};
|
|
8
|
+
|
|
9
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
10
|
+
this.myStorage[key] = value;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async getItem(key: string): Promise<string | null> {
|
|
15
|
+
return this.myStorage[key];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async removeItem(key: string): Promise<void> {
|
|
19
|
+
delete this.myStorage[key];
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async clear(): Promise<void> {
|
|
24
|
+
Object.keys(this.myStorage).forEach(key => {
|
|
25
|
+
delete this.myStorage[key];
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const MemoryKeyValueStorage = new MemoryKeyValueStorageClass();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
let dataMemory = {};
|
|
4
|
+
let dataMemory: Record<string, string> = {};
|
|
5
5
|
|
|
6
6
|
/** @class */
|
|
7
7
|
export class MemoryStorage {
|
|
@@ -71,3 +71,8 @@ export class StorageHelper {
|
|
|
71
71
|
return this.storageWindow;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
|
|
75
|
+
export { SessionStorage } from './sessionStorage';
|
|
76
|
+
export { LocalStorage } from './localStorage';
|
|
77
|
+
export { MemoryKeyValueStorage } from './inMemoryStorage';
|
|
78
|
+
export { CookieStorage } from './cookieStorage';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { KeyValueStorageInterface } from "../types";
|
|
5
|
+
import { PlatformNotSupportedError } from '../Errors';
|
|
6
|
+
|
|
7
|
+
class LocalStorageClass implements KeyValueStorageInterface {
|
|
8
|
+
storage?: Storage;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
if (typeof window !== undefined) {
|
|
12
|
+
try {
|
|
13
|
+
this.storage = window?.localStorage;
|
|
14
|
+
} catch (error) {}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This is used to set a specific item in storage
|
|
20
|
+
* @param {string} key - the key for the item
|
|
21
|
+
* @param {object} value - the value
|
|
22
|
+
* @returns {string} value that was set
|
|
23
|
+
*/
|
|
24
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
25
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
26
|
+
this.storage.setItem(key, value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* This is used to get a specific key from storage
|
|
31
|
+
* @param {string} key - the key for the item
|
|
32
|
+
* This is used to clear the storage
|
|
33
|
+
* @returns {string} the data item
|
|
34
|
+
*/
|
|
35
|
+
async getItem(key: string): Promise<string | null> {
|
|
36
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
37
|
+
return this.storage.getItem(key);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* This is used to remove an item from storage
|
|
42
|
+
* @param {string} key - the key being set
|
|
43
|
+
* @returns {string} value - value that was deleted
|
|
44
|
+
*/
|
|
45
|
+
async removeItem(key: string): Promise<void> {
|
|
46
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
47
|
+
this.storage.removeItem(key);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* This is used to clear the storage
|
|
52
|
+
* @returns {string} nothing
|
|
53
|
+
*/
|
|
54
|
+
async clear(): Promise<void> {
|
|
55
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
56
|
+
this.storage.clear();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const LocalStorage = new LocalStorageClass();
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
4
|
+
import { KeyValueStorageInterface } from '../types';
|
|
4
5
|
|
|
5
6
|
const MEMORY_KEY_PREFIX = '@MemoryStorage:';
|
|
6
|
-
let dataMemory = {};
|
|
7
|
+
let dataMemory: Record<string, string | null> = {};
|
|
7
8
|
|
|
8
9
|
/** @class */
|
|
9
10
|
class MemoryStorage {
|
|
10
|
-
static syncPromise = null;
|
|
11
|
+
static syncPromise: Promise<void> | null = null;
|
|
11
12
|
/**
|
|
12
13
|
* This is used to set a specific item in storage
|
|
13
14
|
* @param {string} key - the key for the item
|
|
14
15
|
* @param {object} value - the value
|
|
15
16
|
* @returns {string} value that was set
|
|
16
17
|
*/
|
|
17
|
-
static setItem(key, value) {
|
|
18
|
+
static setItem(key: string, value: string) {
|
|
18
19
|
if (value) {
|
|
19
20
|
AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value);
|
|
20
21
|
dataMemory[key] = value;
|
|
@@ -28,7 +29,7 @@ class MemoryStorage {
|
|
|
28
29
|
* This is used to clear the storage
|
|
29
30
|
* @returns {string} the data item
|
|
30
31
|
*/
|
|
31
|
-
static getItem(key) {
|
|
32
|
+
static getItem(key: string) {
|
|
32
33
|
return Object.prototype.hasOwnProperty.call(dataMemory, key)
|
|
33
34
|
? dataMemory[key]
|
|
34
35
|
: undefined;
|
|
@@ -39,7 +40,7 @@ class MemoryStorage {
|
|
|
39
40
|
* @param {string} key - the key being set
|
|
40
41
|
* @returns {string} value - value that was deleted
|
|
41
42
|
*/
|
|
42
|
-
static removeItem(key) {
|
|
43
|
+
static removeItem(key: string) {
|
|
43
44
|
AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key);
|
|
44
45
|
return delete dataMemory[key];
|
|
45
46
|
}
|
|
@@ -62,17 +63,19 @@ class MemoryStorage {
|
|
|
62
63
|
MemoryStorage.syncPromise = new Promise<void>((res, rej) => {
|
|
63
64
|
AsyncStorage.getAllKeys((errKeys, keys) => {
|
|
64
65
|
if (errKeys) rej(errKeys);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
|
|
67
|
+
const memoryKeys =
|
|
68
|
+
keys?.filter(key => key.startsWith(MEMORY_KEY_PREFIX)) ?? [];
|
|
69
|
+
|
|
68
70
|
AsyncStorage.multiGet(memoryKeys, (err, stores) => {
|
|
69
71
|
if (err) rej(err);
|
|
70
|
-
stores
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
stores &&
|
|
73
|
+
stores.map((result, index, store) => {
|
|
74
|
+
const key = store[index][0];
|
|
75
|
+
const value = store[index][1];
|
|
76
|
+
const memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
|
|
77
|
+
dataMemory[memoryKey] = value;
|
|
78
|
+
});
|
|
76
79
|
res();
|
|
77
80
|
});
|
|
78
81
|
});
|
|
@@ -100,3 +103,80 @@ export class StorageHelper {
|
|
|
100
103
|
return this.storageWindow;
|
|
101
104
|
}
|
|
102
105
|
}
|
|
106
|
+
|
|
107
|
+
class AsyncStorageClass implements KeyValueStorageInterface {
|
|
108
|
+
syncPromise: Promise<void> | null = null;
|
|
109
|
+
/**
|
|
110
|
+
* This is used to set a specific item in storage
|
|
111
|
+
* @param {string} key - the key for the item
|
|
112
|
+
* @param {object} value - the value
|
|
113
|
+
* @returns {string} value that was set
|
|
114
|
+
*/
|
|
115
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
116
|
+
if (value) {
|
|
117
|
+
await AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value);
|
|
118
|
+
dataMemory[key] = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* This is used to get a specific key from storage
|
|
124
|
+
* @param {string} key - the key for the item
|
|
125
|
+
* This is used to clear the storage
|
|
126
|
+
* @returns {string} the data item
|
|
127
|
+
*/
|
|
128
|
+
async getItem(key: string): Promise<string | null> {
|
|
129
|
+
return Object.prototype.hasOwnProperty.call(dataMemory, key)
|
|
130
|
+
? dataMemory[key]
|
|
131
|
+
: null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* This is used to remove an item from storage
|
|
136
|
+
* @param {string} key - the key being set
|
|
137
|
+
* @returns {string} value - value that was deleted
|
|
138
|
+
*/
|
|
139
|
+
async removeItem(key: string): Promise<void> {
|
|
140
|
+
await AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key);
|
|
141
|
+
delete dataMemory[key];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* This is used to clear the storage
|
|
146
|
+
* @returns {string} nothing
|
|
147
|
+
*/
|
|
148
|
+
async clear(): Promise<void> {
|
|
149
|
+
dataMemory = {};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
|
|
154
|
+
* @returns {void}
|
|
155
|
+
*/
|
|
156
|
+
async sync() {
|
|
157
|
+
if (!this.syncPromise) {
|
|
158
|
+
this.syncPromise = new Promise<void>((res, rej) => {
|
|
159
|
+
AsyncStorage.getAllKeys((errKeys, keys) => {
|
|
160
|
+
if (errKeys) rej(errKeys);
|
|
161
|
+
const memoryKeys =
|
|
162
|
+
keys?.filter(key => key.startsWith(MEMORY_KEY_PREFIX)) ?? [];
|
|
163
|
+
|
|
164
|
+
AsyncStorage.multiGet(memoryKeys, (err, stores) => {
|
|
165
|
+
if (err) rej(err);
|
|
166
|
+
stores &&
|
|
167
|
+
stores.map((result, index, store) => {
|
|
168
|
+
const key = store[index][0];
|
|
169
|
+
const value = store[index][1];
|
|
170
|
+
const memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
|
|
171
|
+
dataMemory[memoryKey] = value;
|
|
172
|
+
});
|
|
173
|
+
res();
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// TODO: Add this to the react-native Amplify package.
|
|
182
|
+
export const AsyncStorageKeyValue = new AsyncStorageClass();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { PlatformNotSupportedError } from '../Errors';
|
|
5
|
+
import { KeyValueStorageInterface } from '../types';
|
|
6
|
+
|
|
7
|
+
class SessionStorageClass implements KeyValueStorageInterface {
|
|
8
|
+
storage?: Storage;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
if (typeof window !== undefined) {
|
|
12
|
+
try {
|
|
13
|
+
this.storage = window?.sessionStorage;
|
|
14
|
+
} catch (error) {}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This is used to set a specific item in storage
|
|
20
|
+
* @param {string} key - the key for the item
|
|
21
|
+
* @param {object} value - the value
|
|
22
|
+
* @returns {string} value that was set
|
|
23
|
+
*/
|
|
24
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
25
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
26
|
+
this.storage.setItem(key, value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* This is used to get a specific key from storage
|
|
31
|
+
* @param {string} key - the key for the item
|
|
32
|
+
* This is used to clear the storage
|
|
33
|
+
* @returns {string} the data item
|
|
34
|
+
*/
|
|
35
|
+
async getItem(key: string): Promise<string | null> {
|
|
36
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
37
|
+
return this.storage.getItem(key);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* This is used to remove an item from storage
|
|
42
|
+
* @param {string} key - the key being set
|
|
43
|
+
* @returns {string} value - value that was deleted
|
|
44
|
+
*/
|
|
45
|
+
async removeItem(key: string): Promise<void> {
|
|
46
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
47
|
+
this.storage.removeItem(key);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* This is used to clear the storage
|
|
52
|
+
* @returns {string} nothing
|
|
53
|
+
*/
|
|
54
|
+
async clear(): Promise<void> {
|
|
55
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
56
|
+
this.storage.clear();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const SessionStorage = new SessionStorageClass();
|
|
@@ -85,10 +85,19 @@ export class BackgroundProcessManager {
|
|
|
85
85
|
* @param job The inner job manager to await.
|
|
86
86
|
* @param description Optional description to help identify pending jobs.
|
|
87
87
|
*/
|
|
88
|
-
add(job: BackgroundProcessManager, description?: string)
|
|
88
|
+
add<T>(job: BackgroundProcessManager, description?: string): Promise<T>;
|
|
89
89
|
|
|
90
|
-
add(
|
|
91
|
-
|
|
90
|
+
add<T>(
|
|
91
|
+
jobOrDescription?:
|
|
92
|
+
| string
|
|
93
|
+
| BackgroundProcessManager
|
|
94
|
+
| ((...args: any) => Promise<T>),
|
|
95
|
+
optionalDescription?: string
|
|
96
|
+
) {
|
|
97
|
+
let job:
|
|
98
|
+
| BackgroundProcessManager
|
|
99
|
+
| ((...args: any) => Promise<T>)
|
|
100
|
+
| undefined;
|
|
92
101
|
let description: string;
|
|
93
102
|
|
|
94
103
|
if (typeof jobOrDescription === 'string') {
|
|
@@ -96,7 +105,7 @@ export class BackgroundProcessManager {
|
|
|
96
105
|
description = jobOrDescription;
|
|
97
106
|
} else {
|
|
98
107
|
job = jobOrDescription;
|
|
99
|
-
description = optionalDescription
|
|
108
|
+
description = optionalDescription!;
|
|
100
109
|
}
|
|
101
110
|
|
|
102
111
|
const error = this.closedFailure(description);
|
|
@@ -149,12 +158,15 @@ export class BackgroundProcessManager {
|
|
|
149
158
|
job: (onTerminate: Promise<void>) => Promise<T>,
|
|
150
159
|
description?: string
|
|
151
160
|
): Promise<T>;
|
|
152
|
-
private addFunction(
|
|
161
|
+
private addFunction<T>(
|
|
162
|
+
job: (() => Promise<T>) | ((onTerminate: Promise<void>) => Promise<T>),
|
|
163
|
+
description?: string
|
|
164
|
+
) {
|
|
153
165
|
// the function we call when we want to try to terminate this job.
|
|
154
166
|
let terminate;
|
|
155
167
|
|
|
156
168
|
// the promise the job can opt into listening to for termination.
|
|
157
|
-
const onTerminate = new Promise(resolve => {
|
|
169
|
+
const onTerminate = new Promise<void>(resolve => {
|
|
158
170
|
terminate = resolve;
|
|
159
171
|
});
|
|
160
172
|
|
|
@@ -164,7 +176,11 @@ export class BackgroundProcessManager {
|
|
|
164
176
|
// depending on what the job gives back, register the result
|
|
165
177
|
// so we can monitor for completion.
|
|
166
178
|
if (typeof jobResult?.then === 'function') {
|
|
167
|
-
this.registerPromise(
|
|
179
|
+
this.registerPromise(
|
|
180
|
+
jobResult,
|
|
181
|
+
terminate as unknown as () => void,
|
|
182
|
+
description
|
|
183
|
+
);
|
|
168
184
|
}
|
|
169
185
|
|
|
170
186
|
// At the end of the day, or you know, method call, it doesn't matter
|
|
@@ -208,7 +224,11 @@ export class BackgroundProcessManager {
|
|
|
208
224
|
terminate = resolveTerminate;
|
|
209
225
|
});
|
|
210
226
|
|
|
211
|
-
this.registerPromise(
|
|
227
|
+
this.registerPromise(
|
|
228
|
+
promise,
|
|
229
|
+
terminate as unknown as () => void,
|
|
230
|
+
description
|
|
231
|
+
);
|
|
212
232
|
|
|
213
233
|
return {
|
|
214
234
|
resolve,
|
|
@@ -355,7 +375,9 @@ export class BackgroundProcessManager {
|
|
|
355
375
|
// reasonable to expect the termination call to fail. Hence,
|
|
356
376
|
// not logging as an error.
|
|
357
377
|
console.warn(
|
|
358
|
-
`Failed to send termination signal to job. Error: ${
|
|
378
|
+
`Failed to send termination signal to job. Error: ${
|
|
379
|
+
(error as Error).message
|
|
380
|
+
}`,
|
|
359
381
|
job
|
|
360
382
|
);
|
|
361
383
|
}
|
|
@@ -449,3 +471,5 @@ type JobEntry = {
|
|
|
449
471
|
*/
|
|
450
472
|
description?: string;
|
|
451
473
|
};
|
|
474
|
+
|
|
475
|
+
const process = new BackgroundProcessManager();
|
package/src/Util/DateUtils.ts
CHANGED
|
@@ -10,8 +10,17 @@
|
|
|
10
10
|
// Comment - TODO: remove
|
|
11
11
|
|
|
12
12
|
const FIVE_MINUTES_IN_MS = 1000 * 60 * 5;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
type DateUtils = {
|
|
14
|
+
clockOffset: number;
|
|
15
|
+
getDateWithClockOffset: () => Date;
|
|
16
|
+
getClockOffset: () => number;
|
|
17
|
+
getHeaderStringFromDate: (date: Date) => string;
|
|
18
|
+
getDateFromHeaderString: (header: string) => Date;
|
|
19
|
+
isClockSkewed: (serverDate: Date) => boolean;
|
|
20
|
+
isClockSkewError: (error: any) => boolean;
|
|
21
|
+
setClockOffset: (offset: number) => void;
|
|
22
|
+
};
|
|
23
|
+
export const DateUtils: DateUtils = {
|
|
15
24
|
/**
|
|
16
25
|
* Milliseconds to offset the date to compensate for clock skew between device & services
|
|
17
26
|
*/
|
|
@@ -37,9 +46,9 @@ export const DateUtils = {
|
|
|
37
46
|
},
|
|
38
47
|
|
|
39
48
|
getDateFromHeaderString(header: string) {
|
|
40
|
-
const [,
|
|
49
|
+
const [,year, month, day, hour, minute, second] = header.match(
|
|
41
50
|
/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2}).+/
|
|
42
|
-
);
|
|
51
|
+
) as any[];
|
|
43
52
|
|
|
44
53
|
return new Date(
|
|
45
54
|
Date.UTC(
|
|
@@ -62,7 +71,7 @@ export const DateUtils = {
|
|
|
62
71
|
);
|
|
63
72
|
},
|
|
64
73
|
|
|
65
|
-
isClockSkewError(error: any) {
|
|
74
|
+
isClockSkewError(error: { response: { headers: any } }) {
|
|
66
75
|
if (!error.response || !error.response.headers) {
|
|
67
76
|
return false;
|
|
68
77
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import Observable from 'zen-observable-ts';
|
|
4
4
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
5
|
+
import type NetInfo from '@react-native-community/netinfo';
|
|
5
6
|
|
|
6
7
|
const logger = new Logger('Reachability', 'DEBUG');
|
|
7
8
|
|
|
@@ -10,7 +11,7 @@ type NetworkStatus = {
|
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
export default class ReachabilityNavigator implements Reachability {
|
|
13
|
-
networkMonitor(netInfo?:
|
|
14
|
+
networkMonitor(netInfo?: typeof NetInfo): Observable<NetworkStatus> {
|
|
14
15
|
/**
|
|
15
16
|
* Here netinfo refers to @react-native-community/netinfo
|
|
16
17
|
* This is needed in React Native to enable network detection
|
|
@@ -46,5 +47,5 @@ export default class ReachabilityNavigator implements Reachability {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
interface Reachability {
|
|
49
|
-
networkMonitor(netInfo?:
|
|
50
|
+
networkMonitor(netInfo?: typeof NetInfo): Observable<NetworkStatus>;
|
|
50
51
|
}
|
package/src/Util/Reachability.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { browserOrNode, isWebWorker } from '@aws-amplify/core';
|
|
4
3
|
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
4
|
+
import { browserOrNode, isWebWorker } from '../JS';
|
|
5
5
|
|
|
6
6
|
type NetworkStatus = {
|
|
7
7
|
online: boolean;
|
|
@@ -34,9 +34,10 @@ export default class ReachabilityNavigator implements Reachability {
|
|
|
34
34
|
globalObj.removeEventListener('online', notifyOnline);
|
|
35
35
|
globalObj.removeEventListener('offline', notifyOffline);
|
|
36
36
|
|
|
37
|
-
ReachabilityNavigator._observers =
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
ReachabilityNavigator._observers =
|
|
38
|
+
ReachabilityNavigator._observers.filter(
|
|
39
|
+
_observer => _observer !== observer
|
|
40
|
+
);
|
|
40
41
|
};
|
|
41
42
|
});
|
|
42
43
|
}
|
|
@@ -45,9 +46,10 @@ export default class ReachabilityNavigator implements Reachability {
|
|
|
45
46
|
private static _observerOverride(status: NetworkStatus): void {
|
|
46
47
|
for (const observer of ReachabilityNavigator._observers) {
|
|
47
48
|
if (observer.closed) {
|
|
48
|
-
ReachabilityNavigator._observers =
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
ReachabilityNavigator._observers =
|
|
50
|
+
ReachabilityNavigator._observers.filter(
|
|
51
|
+
_observer => _observer !== observer
|
|
52
|
+
);
|
|
51
53
|
continue;
|
|
52
54
|
}
|
|
53
55
|
observer.next(status);
|
package/src/Util/Retry.ts
CHANGED
|
@@ -37,7 +37,7 @@ export async function retry<T>(
|
|
|
37
37
|
let wakeUp: any = () => {}; // will be replaced with a resolver()
|
|
38
38
|
|
|
39
39
|
// used after the loop if terminated while waiting for a timer.
|
|
40
|
-
let lastError:
|
|
40
|
+
let lastError: unknown;
|
|
41
41
|
|
|
42
42
|
onTerminate &&
|
|
43
43
|
onTerminate.then(() => {
|
|
@@ -61,6 +61,7 @@ export async function retry<T>(
|
|
|
61
61
|
try {
|
|
62
62
|
return resolve(await functionToRetry(...args));
|
|
63
63
|
} catch (err) {
|
|
64
|
+
|
|
64
65
|
lastError = err;
|
|
65
66
|
logger.debug(`error on ${functionToRetry.name}`, err);
|
|
66
67
|
|
package/src/Util/StringUtils.ts
CHANGED
|
@@ -3,18 +3,11 @@
|
|
|
3
3
|
export function urlSafeEncode(str: string) {
|
|
4
4
|
return str
|
|
5
5
|
.split('')
|
|
6
|
-
.map(char =>
|
|
7
|
-
char
|
|
8
|
-
.charCodeAt(0)
|
|
9
|
-
.toString(16)
|
|
10
|
-
.padStart(2, '0')
|
|
11
|
-
)
|
|
6
|
+
.map(char => char.charCodeAt(0).toString(16).padStart(2, '0'))
|
|
12
7
|
.join('');
|
|
13
8
|
}
|
|
14
9
|
|
|
15
10
|
export function urlSafeDecode(hex: string) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
.map(char => String.fromCharCode(parseInt(char, 16)))
|
|
19
|
-
.join('');
|
|
11
|
+
const matchArr = hex.match(/.{2}/g) || [];
|
|
12
|
+
return matchArr.map(char => String.fromCharCode(parseInt(char, 16))).join('');
|
|
20
13
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { AmplifyError } from '../../Errors';
|
|
4
|
+
import { ErrorParams } from '../../types';
|
|
5
|
+
|
|
6
|
+
export function asserts(
|
|
7
|
+
assertion: boolean,
|
|
8
|
+
errorParams: ErrorParams
|
|
9
|
+
): asserts assertion {
|
|
10
|
+
if (!assertion) throw new AmplifyError(errorParams);
|
|
11
|
+
}
|
|
@@ -32,8 +32,8 @@ export const fetchTransferHandler: TransferHandler<
|
|
|
32
32
|
throw e;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const responseHeaders = {};
|
|
36
|
-
resp.headers?.forEach((value, key) => {
|
|
35
|
+
const responseHeaders: Record<string, string> = {};
|
|
36
|
+
resp.headers?.forEach((value: string, key: string) => {
|
|
37
37
|
responseHeaders[key.toLowerCase()] = value;
|
|
38
38
|
});
|
|
39
39
|
const httpResponse = {
|