@aws-amplify/core 5.8.2 → 6.0.1-console-preview.7919075.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 +160 -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 +156 -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 +144 -0
- package/src/singleton/types.ts +48 -0
- package/src/types/types.ts +38 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { CacheConfig } from '../types';
|
|
5
|
+
import { StorageHelper } from '../../StorageHelper';
|
|
6
|
+
/**
|
|
7
|
+
* Default cache config
|
|
8
|
+
*/
|
|
9
|
+
export const defaultConfig: CacheConfig = {
|
|
10
|
+
keyPrefix: 'aws-amplify-cache',
|
|
11
|
+
capacityInBytes: 1048576, // 1MB
|
|
12
|
+
itemMaxSize: 210000, // about 200kb
|
|
13
|
+
defaultTTL: 259200000, // about 3 days
|
|
14
|
+
defaultPriority: 5,
|
|
15
|
+
warningThreshold: 0.8,
|
|
16
|
+
// the storage helper will check if localStorage exists,
|
|
17
|
+
// if not, will use a in-memory object instead
|
|
18
|
+
storage: new StorageHelper().getStorage(),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* return the byte size of the string
|
|
23
|
+
* @param str
|
|
24
|
+
*/
|
|
25
|
+
export function getByteLength(str: string): number {
|
|
26
|
+
let ret: number = 0;
|
|
27
|
+
ret = str.length;
|
|
28
|
+
|
|
29
|
+
for (let i = str.length; i >= 0; i -= 1) {
|
|
30
|
+
const charCode: number = str.charCodeAt(i);
|
|
31
|
+
if (charCode > 0x7f && charCode <= 0x7ff) {
|
|
32
|
+
ret += 1;
|
|
33
|
+
} else if (charCode > 0x7ff && charCode <= 0xffff) {
|
|
34
|
+
ret += 2;
|
|
35
|
+
}
|
|
36
|
+
// trail surrogate
|
|
37
|
+
if (charCode >= 0xdc00 && charCode <= 0xdfff) {
|
|
38
|
+
i -= 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return ret;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* get current time
|
|
47
|
+
*/
|
|
48
|
+
export function getCurrTime(): number {
|
|
49
|
+
const currTime = new Date();
|
|
50
|
+
return currTime.getTime();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* check if passed value is an integer
|
|
55
|
+
*/
|
|
56
|
+
export function isInteger(value?: number): boolean {
|
|
57
|
+
if (Number.isInteger) {
|
|
58
|
+
return Number.isInteger(value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return _isInteger(value);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function _isInteger(value?: number): boolean {
|
|
65
|
+
return (
|
|
66
|
+
typeof value === 'number' && isFinite(value) && Math.floor(value) === value
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* provide an object as the in-memory cache
|
|
72
|
+
*/
|
|
73
|
+
let store: Record<string, string> = {};
|
|
74
|
+
export class CacheObject {
|
|
75
|
+
static clear(): void {
|
|
76
|
+
store = {};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static getItem(key: string): string | null {
|
|
80
|
+
return store[key] || null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static setItem(key: string, value: string): void {
|
|
84
|
+
store[key] = value;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static removeItem(key: string): void {
|
|
88
|
+
delete store[key];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const getCurrSizeKey = (keyPrefix: string) => keyPrefix + 'CurSize';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
CacheObject,
|
|
6
|
+
defaultConfig,
|
|
7
|
+
getByteLength,
|
|
8
|
+
getCurrTime,
|
|
9
|
+
isInteger,
|
|
10
|
+
} from './CacheUtils';
|
|
11
|
+
export { default as CacheList } from './CacheList';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Cache, AsyncStorageCache } from './AsyncStorageCache';
|
|
5
|
+
|
|
6
|
+
export { AsyncStorageCache };
|
|
7
|
+
|
|
8
|
+
// Standard `Cache` export to maintain interoperability with React Native
|
|
9
|
+
export { Cache };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Cache Interface
|
|
6
|
+
*/
|
|
7
|
+
export interface ICache {
|
|
8
|
+
/** Put item into cache */
|
|
9
|
+
setItem(key: string, value: any, options?: CacheItemOptions): void;
|
|
10
|
+
|
|
11
|
+
/** Get item from cache */
|
|
12
|
+
getItem(key: string, options?: CacheItemOptions): any;
|
|
13
|
+
|
|
14
|
+
/** Remove item from cache */
|
|
15
|
+
removeItem(key: string): void;
|
|
16
|
+
|
|
17
|
+
/** Remove all items from cache */
|
|
18
|
+
clear(): void;
|
|
19
|
+
|
|
20
|
+
/** Get all keys form cache */
|
|
21
|
+
getAllKeys(): string[] | Promise<string[]>;
|
|
22
|
+
|
|
23
|
+
/** Get current size of the cache */
|
|
24
|
+
getCacheCurSize(): number | Promise<number>;
|
|
25
|
+
|
|
26
|
+
/** create a new instance with customized config */
|
|
27
|
+
createInstance(config: CacheConfig): ICache;
|
|
28
|
+
|
|
29
|
+
/** change current configuration */
|
|
30
|
+
configure(config: CacheConfig): CacheConfig;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Cache instance options
|
|
35
|
+
*/
|
|
36
|
+
export interface CacheConfig {
|
|
37
|
+
/** Prepend to key to avoid conflicts */
|
|
38
|
+
keyPrefix: string;
|
|
39
|
+
|
|
40
|
+
/** Cache capacity, in bytes */
|
|
41
|
+
capacityInBytes: number;
|
|
42
|
+
|
|
43
|
+
/** Max size of one item */
|
|
44
|
+
itemMaxSize: number;
|
|
45
|
+
|
|
46
|
+
/** Time to live, in milliseconds */
|
|
47
|
+
defaultTTL: number;
|
|
48
|
+
|
|
49
|
+
/** Warn when over threshold percentage of capacity, maximum 1 */
|
|
50
|
+
warningThreshold: number;
|
|
51
|
+
|
|
52
|
+
/** default priority number put on cached items */
|
|
53
|
+
defaultPriority: number;
|
|
54
|
+
|
|
55
|
+
storage?: Storage;
|
|
56
|
+
|
|
57
|
+
Cache?: Cache;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface CacheItem {
|
|
61
|
+
key: string;
|
|
62
|
+
data: any;
|
|
63
|
+
timestamp: number;
|
|
64
|
+
visitedTime: number;
|
|
65
|
+
priority: number;
|
|
66
|
+
expires: number;
|
|
67
|
+
type: string;
|
|
68
|
+
byteSize: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface CacheItemOptions {
|
|
72
|
+
priority?: number;
|
|
73
|
+
expires?: number;
|
|
74
|
+
callback?: Function;
|
|
75
|
+
}
|
package/src/ClientDevice/ios.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
3
|
+
// @ts-ignore: missing type definition
|
|
4
4
|
import { Platform, Dimensions } from 'react-native';
|
|
5
5
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
6
6
|
|
|
@@ -21,7 +21,7 @@ export const clientInfo = () => {
|
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
function dimToMake(dim) {
|
|
24
|
+
function dimToMake(dim:{height:number, width:number;}) {
|
|
25
25
|
let { height, width } = dim;
|
|
26
26
|
if (height < width) {
|
|
27
27
|
const tmp = height;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
3
|
+
// @ts-ignore: missing type definition
|
|
4
4
|
import { Platform } from 'react-native';
|
|
5
5
|
import { clientInfo as iOSClientInfo } from './ios';
|
|
6
6
|
import { clientInfo as androidClientInfo } from './android';
|
package/src/Credentials.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
4
|
import { ConsoleLogger as Logger } from './Logger';
|
|
@@ -35,11 +36,12 @@ export class CredentialsClass {
|
|
|
35
36
|
private _config;
|
|
36
37
|
private _credentials;
|
|
37
38
|
private _credentials_source;
|
|
38
|
-
private _gettingCredPromise = null;
|
|
39
|
+
private _gettingCredPromise: any = null;
|
|
39
40
|
private _refreshHandlers = {};
|
|
40
41
|
private _storage;
|
|
41
42
|
private _storageSync;
|
|
42
43
|
private _identityId;
|
|
44
|
+
// @ts-ignore
|
|
43
45
|
private _nextCredentialsRefresh: number;
|
|
44
46
|
|
|
45
47
|
// Allow `Auth` to be injected for SSR, but Auth isn't a required dependency for Credentials
|
|
@@ -126,7 +128,7 @@ export class CredentialsClass {
|
|
|
126
128
|
|
|
127
129
|
// Some use-cases don't require Auth for signing in, but use Credentials for guest users (e.g. Analytics)
|
|
128
130
|
// Prefer locally scoped `Auth`, but fallback to registered `Amplify.Auth` global otherwise.
|
|
129
|
-
const { Auth = Amplify.Auth } = this;
|
|
131
|
+
const { Auth = Amplify.Auth } = this as any;
|
|
130
132
|
|
|
131
133
|
if (!Auth || typeof Auth.currentUserCredentials !== 'function') {
|
|
132
134
|
// If Auth module is not imported, do a best effort to get guest credentials
|
|
@@ -296,10 +298,10 @@ export class CredentialsClass {
|
|
|
296
298
|
});
|
|
297
299
|
return {
|
|
298
300
|
identityId: this._identityId,
|
|
299
|
-
accessKeyId: Credentials
|
|
300
|
-
secretAccessKey: Credentials
|
|
301
|
-
sessionToken: Credentials
|
|
302
|
-
expiration: Credentials
|
|
301
|
+
accessKeyId: Credentials!.AccessKeyId,
|
|
302
|
+
secretAccessKey: Credentials!.SecretKey,
|
|
303
|
+
sessionToken: Credentials!.SessionToken,
|
|
304
|
+
expiration: Credentials!.Expiration,
|
|
303
305
|
};
|
|
304
306
|
};
|
|
305
307
|
let credentials = guestCredentialsProvider().catch(async err => {
|
|
@@ -334,10 +336,10 @@ export class CredentialsClass {
|
|
|
334
336
|
|
|
335
337
|
return {
|
|
336
338
|
identityId: IdentityId,
|
|
337
|
-
accessKeyId: Credentials
|
|
338
|
-
secretAccessKey: Credentials
|
|
339
|
-
sessionToken: Credentials
|
|
340
|
-
expiration: Credentials
|
|
339
|
+
accessKeyId: Credentials!.AccessKeyId,
|
|
340
|
+
secretAccessKey: Credentials!.SecretKey,
|
|
341
|
+
sessionToken: Credentials!.SessionToken,
|
|
342
|
+
expiration: Credentials!.Expiration,
|
|
341
343
|
};
|
|
342
344
|
};
|
|
343
345
|
|
|
@@ -399,10 +401,10 @@ export class CredentialsClass {
|
|
|
399
401
|
});
|
|
400
402
|
return {
|
|
401
403
|
identityId: identity_id,
|
|
402
|
-
accessKeyId: Credentials
|
|
403
|
-
secretAccessKey: Credentials
|
|
404
|
-
sessionToken: Credentials
|
|
405
|
-
expiration: Credentials
|
|
404
|
+
accessKeyId: Credentials!.AccessKeyId,
|
|
405
|
+
secretAccessKey: Credentials!.SecretKey,
|
|
406
|
+
sessionToken: Credentials!.SessionToken,
|
|
407
|
+
expiration: Credentials!.Expiration,
|
|
406
408
|
};
|
|
407
409
|
};
|
|
408
410
|
|
|
@@ -460,10 +462,10 @@ export class CredentialsClass {
|
|
|
460
462
|
// single source of truth for the primary identity associated with the logins
|
|
461
463
|
// only if a guest identity is used for a first-time user, that guest identity will become its primary identity
|
|
462
464
|
IdentityId: primaryIdentityId,
|
|
463
|
-
} = await getCredentialsForIdentity(cognitoConfig, {
|
|
465
|
+
} = (await getCredentialsForIdentity(cognitoConfig, {
|
|
464
466
|
IdentityId: guestIdentityId || generatedOrRetrievedIdentityId,
|
|
465
467
|
Logins: logins,
|
|
466
|
-
});
|
|
468
|
+
})) as { Credentials: any; IdentityId: string };
|
|
467
469
|
|
|
468
470
|
this._identityId = primaryIdentityId;
|
|
469
471
|
if (guestIdentityId) {
|
|
@@ -576,7 +578,7 @@ export class CredentialsClass {
|
|
|
576
578
|
}
|
|
577
579
|
|
|
578
580
|
/* operations on local stored guest identity */
|
|
579
|
-
private async _getGuestIdentityId(): Promise<string> {
|
|
581
|
+
private async _getGuestIdentityId(): Promise<string | undefined> {
|
|
580
582
|
const { identityPoolId } = this._config;
|
|
581
583
|
try {
|
|
582
584
|
await this._storageSync;
|
package/src/Errors.ts
CHANGED
|
@@ -1,9 +1,50 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { ErrorParams } from './types/types';
|
|
5
|
+
|
|
4
6
|
export function missingConfig(name: string) {
|
|
5
7
|
return new Error('Missing config value of ' + name);
|
|
6
8
|
}
|
|
7
9
|
export function invalidParameter(name: string) {
|
|
8
10
|
return new Error('Invalid parameter value of ' + name);
|
|
9
11
|
}
|
|
12
|
+
|
|
13
|
+
export enum AmplifyErrorString {
|
|
14
|
+
UNKNOWN = 'UnknownError',
|
|
15
|
+
PLATFORM_NOT_SUPPORTED_ERROR = 'PlatformNotSupportedError',
|
|
16
|
+
}
|
|
17
|
+
export class AmplifyError extends Error {
|
|
18
|
+
underlyingError?: Error | unknown;
|
|
19
|
+
recoverySuggestion?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Constructs an AmplifyError.
|
|
22
|
+
*
|
|
23
|
+
* @param message text that describes the main problem.
|
|
24
|
+
* @param underlyingError the underlying cause of the error.
|
|
25
|
+
* @param recoverySuggestion suggestion to recover from the error.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
constructor({
|
|
29
|
+
message,
|
|
30
|
+
name,
|
|
31
|
+
recoverySuggestion,
|
|
32
|
+
underlyingError,
|
|
33
|
+
}: ErrorParams) {
|
|
34
|
+
super(message);
|
|
35
|
+
|
|
36
|
+
this.name = name;
|
|
37
|
+
this.underlyingError = underlyingError;
|
|
38
|
+
this.recoverySuggestion = recoverySuggestion;
|
|
39
|
+
|
|
40
|
+
// Hack for making the custom error class work when transpiled to es5
|
|
41
|
+
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
42
|
+
this.constructor = AmplifyError;
|
|
43
|
+
Object.setPrototypeOf(this, AmplifyError.prototype);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const PlatformNotSupportedError = new AmplifyError({
|
|
48
|
+
name: AmplifyErrorString.PLATFORM_NOT_SUPPORTED_ERROR,
|
|
49
|
+
message: 'Function not supported on current platform',
|
|
50
|
+
});
|
package/src/Hub.ts
CHANGED
package/src/I18n/I18n.ts
CHANGED
|
@@ -1,39 +1,54 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { I18nOptions } from './types';
|
|
5
4
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
5
|
+
import { AmplifyV6 } from '../singleton';
|
|
6
|
+
import { I18nOptions } from './types';
|
|
6
7
|
|
|
7
8
|
const logger = new Logger('I18n');
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
* Language
|
|
11
|
+
* Language translation utility.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
11
14
|
*/
|
|
12
15
|
export class I18n {
|
|
13
16
|
/**
|
|
14
17
|
* @private
|
|
15
18
|
*/
|
|
16
|
-
_options: I18nOptions = null;
|
|
19
|
+
_options: I18nOptions | null = null;
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* @private
|
|
20
23
|
*/
|
|
21
|
-
_lang = null;
|
|
24
|
+
_lang?: string | null = null;
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* @private
|
|
25
28
|
*/
|
|
26
|
-
_dict = {};
|
|
29
|
+
_dict: Record<string, any> = {};
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* @constructor
|
|
30
33
|
* Initialize with configurations
|
|
31
34
|
* @param {Object} options
|
|
35
|
+
*
|
|
36
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
32
37
|
*/
|
|
33
|
-
constructor(
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
constructor() {}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Sets the default language from the configuration when required.
|
|
42
|
+
*
|
|
43
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
44
|
+
*/
|
|
45
|
+
setDefaultLanguage() {
|
|
46
|
+
if (!this._lang) {
|
|
47
|
+
const i18nConfig = AmplifyV6.getConfig().I18n;
|
|
48
|
+
this._lang = i18nConfig?.language;
|
|
49
|
+
}
|
|
36
50
|
|
|
51
|
+
// Default to window language if not set in config
|
|
37
52
|
if (
|
|
38
53
|
!this._lang &&
|
|
39
54
|
typeof window !== 'undefined' &&
|
|
@@ -50,6 +65,8 @@ export class I18n {
|
|
|
50
65
|
* @method
|
|
51
66
|
* Explicitly setting language
|
|
52
67
|
* @param {String} lang
|
|
68
|
+
*
|
|
69
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
53
70
|
*/
|
|
54
71
|
setLanguage(lang: string) {
|
|
55
72
|
this._lang = lang;
|
|
@@ -60,8 +77,10 @@ export class I18n {
|
|
|
60
77
|
* Get value
|
|
61
78
|
* @param {String} key
|
|
62
79
|
* @param {String} defVal - Default value
|
|
80
|
+
*
|
|
81
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
63
82
|
*/
|
|
64
|
-
get(key, defVal = undefined) {
|
|
83
|
+
get(key: string, defVal: string | undefined = undefined) {
|
|
65
84
|
if (!this._lang) {
|
|
66
85
|
return typeof defVal !== 'undefined' ? defVal : key;
|
|
67
86
|
}
|
|
@@ -88,8 +107,10 @@ export class I18n {
|
|
|
88
107
|
* @param {String} key
|
|
89
108
|
* @param {String} language - Specified langurage to be used
|
|
90
109
|
* @param {String} defVal - Default value
|
|
110
|
+
*
|
|
111
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
91
112
|
*/
|
|
92
|
-
getByLanguage(key, language, defVal = null) {
|
|
113
|
+
getByLanguage(key: string, language: string, defVal: string | null = null) {
|
|
93
114
|
if (!language) {
|
|
94
115
|
return defVal;
|
|
95
116
|
}
|
|
@@ -107,8 +128,13 @@ export class I18n {
|
|
|
107
128
|
* Add vocabularies for one language
|
|
108
129
|
* @param {String} language - Language of the dictionary
|
|
109
130
|
* @param {Object} vocabularies - Object that has key-value as dictionary entry
|
|
131
|
+
*
|
|
132
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
110
133
|
*/
|
|
111
|
-
putVocabulariesForLanguage(
|
|
134
|
+
putVocabulariesForLanguage(
|
|
135
|
+
language: string,
|
|
136
|
+
vocabularies: Record<string, any>
|
|
137
|
+
) {
|
|
112
138
|
let lang_dict = this._dict[language];
|
|
113
139
|
if (!lang_dict) {
|
|
114
140
|
lang_dict = this._dict[language] = {};
|
|
@@ -121,8 +147,10 @@ export class I18n {
|
|
|
121
147
|
* Add vocabularies for one language
|
|
122
148
|
* @param {Object} vocabularies - Object that has language as key,
|
|
123
149
|
* vocabularies of each language as value
|
|
150
|
+
*
|
|
151
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
124
152
|
*/
|
|
125
|
-
putVocabularies(vocabularies) {
|
|
153
|
+
putVocabularies(vocabularies: Record<string, any>) {
|
|
126
154
|
Object.keys(vocabularies).map(key => {
|
|
127
155
|
this.putVocabulariesForLanguage(key, vocabularies[key]);
|
|
128
156
|
});
|
package/src/I18n/index.ts
CHANGED
|
@@ -4,15 +4,19 @@
|
|
|
4
4
|
import { I18n as I18nClass } from './I18n';
|
|
5
5
|
|
|
6
6
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
7
|
-
import {
|
|
7
|
+
import { I18nOptions } from './types';
|
|
8
|
+
import { asserts } from '../Util/errors/AssertError';
|
|
9
|
+
import { I18N_EXCEPTION } from '../constants';
|
|
8
10
|
|
|
9
11
|
const logger = new Logger('I18n');
|
|
10
12
|
|
|
11
|
-
let _config = null;
|
|
12
|
-
let _i18n = null;
|
|
13
|
+
let _config: I18nOptions = { language: null };
|
|
14
|
+
let _i18n: I18nClass | null = null;
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Export I18n APIs
|
|
18
|
+
*
|
|
19
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
16
20
|
*/
|
|
17
21
|
export class I18n {
|
|
18
22
|
/**
|
|
@@ -21,7 +25,7 @@ export class I18n {
|
|
|
21
25
|
* Configure I18n part
|
|
22
26
|
* @param {Object} config - Configuration of the I18n
|
|
23
27
|
*/
|
|
24
|
-
static configure(config) {
|
|
28
|
+
static configure(config: Record<string, any>) {
|
|
25
29
|
logger.debug('configure I18n');
|
|
26
30
|
if (!config) {
|
|
27
31
|
return _config;
|
|
@@ -42,23 +46,30 @@ export class I18n {
|
|
|
42
46
|
* @static
|
|
43
47
|
* @method
|
|
44
48
|
* Create an instance of I18n for the library
|
|
49
|
+
*
|
|
50
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
45
51
|
*/
|
|
46
52
|
static createInstance() {
|
|
47
53
|
logger.debug('create I18n instance');
|
|
48
54
|
if (_i18n) {
|
|
49
55
|
return;
|
|
50
56
|
}
|
|
51
|
-
_i18n = new I18nClass(
|
|
57
|
+
_i18n = new I18nClass();
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
/**
|
|
55
61
|
* @static @method
|
|
56
62
|
* Explicitly setting language
|
|
57
63
|
* @param {String} lang
|
|
64
|
+
*
|
|
65
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
58
66
|
*/
|
|
59
|
-
static setLanguage(lang) {
|
|
67
|
+
static setLanguage(lang: string) {
|
|
60
68
|
I18n.checkConfig();
|
|
61
|
-
|
|
69
|
+
asserts(!!_i18n, {
|
|
70
|
+
name: I18N_EXCEPTION,
|
|
71
|
+
message: 'I18N is not configured',
|
|
72
|
+
});
|
|
62
73
|
return _i18n.setLanguage(lang);
|
|
63
74
|
}
|
|
64
75
|
|
|
@@ -67,11 +78,17 @@ export class I18n {
|
|
|
67
78
|
* Get value
|
|
68
79
|
* @param {String} key
|
|
69
80
|
* @param {String} defVal - Default value
|
|
81
|
+
*
|
|
82
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
70
83
|
*/
|
|
71
|
-
static get(key, defVal
|
|
84
|
+
static get(key: string, defVal?: string) {
|
|
72
85
|
if (!I18n.checkConfig()) {
|
|
73
86
|
return typeof defVal === 'undefined' ? key : defVal;
|
|
74
87
|
}
|
|
88
|
+
asserts(!!_i18n, {
|
|
89
|
+
name: I18N_EXCEPTION,
|
|
90
|
+
message: 'I18N is not configured',
|
|
91
|
+
});
|
|
75
92
|
|
|
76
93
|
return _i18n.get(key, defVal);
|
|
77
94
|
}
|
|
@@ -82,9 +99,18 @@ export class I18n {
|
|
|
82
99
|
* Add vocabularies for one language
|
|
83
100
|
* @param {String} langurage - Language of the dictionary
|
|
84
101
|
* @param {Object} vocabularies - Object that has key-value as dictionary entry
|
|
102
|
+
*
|
|
103
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
85
104
|
*/
|
|
86
|
-
static putVocabulariesForLanguage(
|
|
105
|
+
static putVocabulariesForLanguage(
|
|
106
|
+
language: string,
|
|
107
|
+
vocabularies: Record<string, string>
|
|
108
|
+
) {
|
|
87
109
|
I18n.checkConfig();
|
|
110
|
+
asserts(!!_i18n, {
|
|
111
|
+
name: I18N_EXCEPTION,
|
|
112
|
+
message: 'I18N is not configured',
|
|
113
|
+
});
|
|
88
114
|
|
|
89
115
|
return _i18n.putVocabulariesForLanguage(language, vocabularies);
|
|
90
116
|
}
|
|
@@ -95,20 +121,27 @@ export class I18n {
|
|
|
95
121
|
* Add vocabularies for one language
|
|
96
122
|
* @param {Object} vocabularies - Object that has language as key,
|
|
97
123
|
* vocabularies of each language as value
|
|
124
|
+
*
|
|
125
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
98
126
|
*/
|
|
99
|
-
static putVocabularies(vocabularies) {
|
|
127
|
+
static putVocabularies(vocabularies: Record<string, string>) {
|
|
100
128
|
I18n.checkConfig();
|
|
129
|
+
asserts(!!_i18n, {
|
|
130
|
+
name: I18N_EXCEPTION,
|
|
131
|
+
message: 'I18N is not configured',
|
|
132
|
+
});
|
|
101
133
|
|
|
102
134
|
return _i18n.putVocabularies(vocabularies);
|
|
103
135
|
}
|
|
104
136
|
|
|
105
137
|
public static checkConfig() {
|
|
106
138
|
if (!_i18n) {
|
|
107
|
-
|
|
139
|
+
I18n.createInstance();
|
|
108
140
|
}
|
|
109
141
|
|
|
110
142
|
return true;
|
|
111
143
|
}
|
|
112
144
|
}
|
|
113
145
|
|
|
114
|
-
|
|
146
|
+
// Create an instance of I18n in the static class
|
|
147
|
+
I18n.createInstance();
|
package/src/I18n/types.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
|
|
6
|
+
*/
|
|
4
7
|
export class I18nOptions {
|
|
5
8
|
language = null;
|
|
6
9
|
}
|