@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
|
@@ -10,8 +10,12 @@ import { isClockSkewError } from './isClockSkewError';
|
|
|
10
10
|
*/
|
|
11
11
|
export const getRetryDecider =
|
|
12
12
|
(errorParser: ErrorParser) =>
|
|
13
|
-
async (response?: HttpResponse, error?:
|
|
14
|
-
const
|
|
13
|
+
async (response?: HttpResponse, error?: unknown): Promise<boolean> => {
|
|
14
|
+
const parsedError =
|
|
15
|
+
(error as Error & { code: string }) ??
|
|
16
|
+
(await errorParser(response)) ??
|
|
17
|
+
undefined;
|
|
18
|
+
const errorCode = parsedError?.['code'];
|
|
15
19
|
const statusCode = response?.statusCode;
|
|
16
20
|
return (
|
|
17
21
|
isConnectionError(error) ||
|
|
@@ -45,10 +49,12 @@ const TIMEOUT_ERROR_CODES = [
|
|
|
45
49
|
];
|
|
46
50
|
|
|
47
51
|
const isThrottlingError = (statusCode?: number, errorCode?: string) =>
|
|
48
|
-
statusCode === 429 ||
|
|
52
|
+
statusCode === 429 ||
|
|
53
|
+
(!!errorCode && THROTTLING_ERROR_CODES.includes(errorCode));
|
|
49
54
|
|
|
50
|
-
const isConnectionError = (error?:
|
|
55
|
+
const isConnectionError = (error?: unknown) =>
|
|
56
|
+
(error as Error)?.['name'] === 'Network error';
|
|
51
57
|
|
|
52
58
|
const isServerSideError = (statusCode?: number, errorCode?: string) =>
|
|
53
|
-
[500, 502, 503, 504].includes(statusCode) ||
|
|
54
|
-
TIMEOUT_ERROR_CODES.includes(errorCode);
|
|
59
|
+
(!!statusCode && [500, 502, 503, 504].includes(statusCode)) ||
|
|
60
|
+
(!!errorCode && TIMEOUT_ERROR_CODES.includes(errorCode));
|
|
@@ -56,9 +56,9 @@ export const retryMiddleware = <TInput = Request, TOutput = Response>({
|
|
|
56
56
|
context: MiddlewareContext
|
|
57
57
|
) =>
|
|
58
58
|
async function retryMiddleware(request: TInput) {
|
|
59
|
-
let error:
|
|
60
|
-
let attemptsCount = context.attemptsCount ?? 0;
|
|
61
|
-
let response: TOutput;
|
|
59
|
+
let error: unknown;
|
|
60
|
+
let attemptsCount: number = context.attemptsCount ?? 0;
|
|
61
|
+
let response: TOutput | undefined;
|
|
62
62
|
|
|
63
63
|
// When retry is not needed or max attempts is reached, either error or response will be set. This function handles either cases.
|
|
64
64
|
const handleTerminalErrorOrResponse = () => {
|
|
@@ -66,7 +66,7 @@ export const retryMiddleware = <TInput = Request, TOutput = Response>({
|
|
|
66
66
|
addOrIncrementMetadataAttempts(response, attemptsCount);
|
|
67
67
|
return response;
|
|
68
68
|
} else {
|
|
69
|
-
addOrIncrementMetadataAttempts(error, attemptsCount);
|
|
69
|
+
addOrIncrementMetadataAttempts(error as object, attemptsCount);
|
|
70
70
|
throw error;
|
|
71
71
|
}
|
|
72
72
|
};
|
|
@@ -81,8 +81,8 @@ export const retryMiddleware = <TInput = Request, TOutput = Response>({
|
|
|
81
81
|
}
|
|
82
82
|
// context.attemptsCount may be updated after calling next handler which may retry the request by itself.
|
|
83
83
|
attemptsCount =
|
|
84
|
-
context.attemptsCount > attemptsCount
|
|
85
|
-
? context.attemptsCount
|
|
84
|
+
(context.attemptsCount ?? 0) > attemptsCount
|
|
85
|
+
? context.attemptsCount ?? 0
|
|
86
86
|
: attemptsCount + 1;
|
|
87
87
|
context.attemptsCount = attemptsCount;
|
|
88
88
|
if (await retryDecider(response, error)) {
|
|
@@ -109,8 +109,8 @@ const cancellableSleep = (timeoutMs: number, abortSignal?: AbortSignal) => {
|
|
|
109
109
|
if (abortSignal?.aborted) {
|
|
110
110
|
return Promise.resolve();
|
|
111
111
|
}
|
|
112
|
-
let timeoutId;
|
|
113
|
-
let sleepPromiseResolveFn;
|
|
112
|
+
let timeoutId: number;
|
|
113
|
+
let sleepPromiseResolveFn: Function;
|
|
114
114
|
const sleepPromise = new Promise<void>(resolve => {
|
|
115
115
|
sleepPromiseResolveFn = resolve;
|
|
116
116
|
timeoutId = setTimeout(resolve, timeoutMs);
|
|
@@ -124,7 +124,7 @@ const cancellableSleep = (timeoutMs: number, abortSignal?: AbortSignal) => {
|
|
|
124
124
|
};
|
|
125
125
|
|
|
126
126
|
const addOrIncrementMetadataAttempts = (
|
|
127
|
-
nextHandlerOutput:
|
|
127
|
+
nextHandlerOutput: Record<string, any>,
|
|
128
128
|
attempts: number
|
|
129
129
|
) => {
|
|
130
130
|
if (Object.prototype.toString.call(nextHandlerOutput) !== '[object Object]') {
|
|
@@ -38,7 +38,7 @@ export const signingMiddleware = ({
|
|
|
38
38
|
service,
|
|
39
39
|
uriEscapePath = true,
|
|
40
40
|
}: SigningOptions) => {
|
|
41
|
-
let currentSystemClockOffset;
|
|
41
|
+
let currentSystemClockOffset: number;
|
|
42
42
|
return (next: MiddlewareHandler<HttpRequest, HttpResponse>) =>
|
|
43
43
|
async function signingMiddleware(request: HttpRequest) {
|
|
44
44
|
currentSystemClockOffset = currentSystemClockOffset ?? 0;
|
|
@@ -17,7 +17,7 @@ export const getHashedData = (
|
|
|
17
17
|
key: SourceData | null,
|
|
18
18
|
data: SourceData
|
|
19
19
|
): Uint8Array => {
|
|
20
|
-
const sha256 = new Sha256(key);
|
|
20
|
+
const sha256 = new Sha256(key ?? undefined);
|
|
21
21
|
sha256.update(data);
|
|
22
22
|
// TODO: V6 flip to async digest
|
|
23
23
|
const hashedData = sha256.digestSync();
|
|
@@ -18,5 +18,6 @@ export const parseMetadata = (response: HttpResponse): ResponseMetadata => {
|
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
type IsResponse = { $metadata: any };
|
|
21
22
|
const isMetadataBearer = (response: unknown): response is MetadataBearer =>
|
|
22
|
-
typeof response
|
|
23
|
+
typeof (response as IsResponse)?.$metadata === 'object';
|
package/src/clients/types/aws.ts
CHANGED
|
@@ -26,3 +26,13 @@ export interface ServiceClientOptions {
|
|
|
26
26
|
export type ErrorParser = (
|
|
27
27
|
response?: HttpResponse
|
|
28
28
|
) => Promise<(Error & MetadataBearer) | undefined>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Default config options for the `composeServiceApi`.
|
|
32
|
+
*/
|
|
33
|
+
export type DefaultConfigOptions<
|
|
34
|
+
TransferHandlerOptions extends Record<string, unknown> = Record<
|
|
35
|
+
string,
|
|
36
|
+
unknown
|
|
37
|
+
>
|
|
38
|
+
> = Partial<TransferHandlerOptions & ServiceClientOptions>;
|
package/src/constants.ts
CHANGED
|
@@ -13,3 +13,19 @@ export const INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER = hasSymbol
|
|
|
13
13
|
: '@@INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER';
|
|
14
14
|
|
|
15
15
|
export const USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
16
|
+
|
|
17
|
+
// Error exception code constants
|
|
18
|
+
export const AUTH_CONFING_EXCEPTION = 'AuthConfigException';
|
|
19
|
+
|
|
20
|
+
export const AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION =
|
|
21
|
+
'AWSCloudWatchProviderOptionsException';
|
|
22
|
+
|
|
23
|
+
export const CACHE_LIST_EXCEPTION = 'CacheListException';
|
|
24
|
+
|
|
25
|
+
export const I18N_EXCEPTION = 'I18NException';
|
|
26
|
+
|
|
27
|
+
export const SERVICE_WORKER_EXCEPTION = 'ServiceWorkerException';
|
|
28
|
+
|
|
29
|
+
export const STORAGE_CACHE_EXCEPTION = 'StorageCacheException';
|
|
30
|
+
|
|
31
|
+
export const APPLICATION_ID_EXCEPTION = 'ApplicationIdException';
|
package/src/global.d.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -4,11 +4,16 @@
|
|
|
4
4
|
import { Amplify } from './Amplify';
|
|
5
5
|
import { Platform } from './Platform';
|
|
6
6
|
|
|
7
|
-
export { Amplify }
|
|
7
|
+
export { Amplify };
|
|
8
8
|
export { AmplifyClass } from './Amplify';
|
|
9
9
|
export { ClientDevice } from './ClientDevice';
|
|
10
10
|
export { ConsoleLogger, ConsoleLogger as Logger } from './Logger';
|
|
11
|
-
export {
|
|
11
|
+
export {
|
|
12
|
+
invalidParameter,
|
|
13
|
+
missingConfig,
|
|
14
|
+
AmplifyError,
|
|
15
|
+
AmplifyErrorString,
|
|
16
|
+
} from './Errors';
|
|
12
17
|
export { Hub, HubCapsule, HubCallback, HubPayload } from './Hub';
|
|
13
18
|
export { I18n } from './I18n';
|
|
14
19
|
export {
|
|
@@ -32,8 +37,21 @@ export { FacebookOAuth, GoogleOAuth } from './OAuthHelper';
|
|
|
32
37
|
export { AppState, AsyncStorage, Linking } from './RNComponents';
|
|
33
38
|
export { Credentials, CredentialsClass } from './Credentials';
|
|
34
39
|
export { ServiceWorker } from './ServiceWorker';
|
|
35
|
-
export {
|
|
36
|
-
|
|
40
|
+
export {
|
|
41
|
+
ICredentials,
|
|
42
|
+
ErrorParams,
|
|
43
|
+
AmplifyErrorMap,
|
|
44
|
+
ServiceError,
|
|
45
|
+
KeyValueStorageInterface,
|
|
46
|
+
} from './types';
|
|
47
|
+
export {
|
|
48
|
+
StorageHelper,
|
|
49
|
+
MemoryStorage,
|
|
50
|
+
LocalStorage,
|
|
51
|
+
CookieStorage,
|
|
52
|
+
SessionStorage,
|
|
53
|
+
MemoryKeyValueStorage,
|
|
54
|
+
} from './StorageHelper';
|
|
37
55
|
export { UniversalStorage } from './UniversalStorage';
|
|
38
56
|
export {
|
|
39
57
|
Platform,
|
|
@@ -88,6 +106,50 @@ export {
|
|
|
88
106
|
urlSafeEncode,
|
|
89
107
|
} from './Util';
|
|
90
108
|
|
|
109
|
+
// Cache exports
|
|
110
|
+
import { BrowserStorageCache } from './Cache/BrowserStorageCache';
|
|
111
|
+
export { asserts } from './Util/errors/AssertError';
|
|
112
|
+
export { isTokenExpired } from './singleton/Auth';
|
|
113
|
+
export { InMemoryCache } from './Cache/InMemoryCache';
|
|
114
|
+
export { CacheConfig } from './Cache/types';
|
|
115
|
+
export { ICache } from './Cache/types';
|
|
116
|
+
export { BrowserStorageCache };
|
|
117
|
+
export { BrowserStorageCache as Cache }; // Maintain interoperability with React Native
|
|
118
|
+
|
|
119
|
+
// Singleton exports
|
|
120
|
+
export {
|
|
121
|
+
decodeJWT,
|
|
122
|
+
assertTokenProviderConfig,
|
|
123
|
+
assertIdentityPooIdConfig,
|
|
124
|
+
} from './singleton/Auth/utils';
|
|
125
|
+
export {
|
|
126
|
+
TokenProvider,
|
|
127
|
+
AuthTokens,
|
|
128
|
+
FetchAuthSessionOptions,
|
|
129
|
+
AWSCredentialsAndIdentityIdProvider,
|
|
130
|
+
AWSCredentialsAndIdentityId,
|
|
131
|
+
Identity,
|
|
132
|
+
} from './singleton/Auth/types';
|
|
133
|
+
export {
|
|
134
|
+
AuthConfig,
|
|
135
|
+
UserPoolConfig,
|
|
136
|
+
UserPoolConfigAndIdentityPoolConfig,
|
|
137
|
+
StorageAccessLevel,
|
|
138
|
+
StorageConfig,
|
|
139
|
+
GetCredentialsOptions,
|
|
140
|
+
} from './singleton/types';
|
|
141
|
+
|
|
142
|
+
// AWSClients exports
|
|
143
|
+
export {
|
|
144
|
+
getCredentialsForIdentity,
|
|
145
|
+
getId,
|
|
146
|
+
GetCredentialsForIdentityInput,
|
|
147
|
+
GetCredentialsForIdentityOutput,
|
|
148
|
+
} from './AwsClients/CognitoIdentity';
|
|
149
|
+
|
|
150
|
+
export { AmplifyV6, fetchAuthSession } from './singleton';
|
|
151
|
+
export { LibraryOptions, ResourcesConfig } from './singleton/types';
|
|
152
|
+
|
|
91
153
|
/**
|
|
92
154
|
* @deprecated use named import
|
|
93
155
|
*/
|
package/src/parseAWSExports.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { ConsoleLogger as Logger } from './Logger';
|
|
|
5
5
|
|
|
6
6
|
const logger = new Logger('Parser');
|
|
7
7
|
|
|
8
|
-
export const parseAWSExports = (config): AmplifyConfig => {
|
|
8
|
+
export const parseAWSExports = (config:Record<string,any>): AmplifyConfig => {
|
|
9
9
|
const amplifyConfig: AmplifyConfig = {};
|
|
10
10
|
// Analytics
|
|
11
11
|
if (config['aws_mobile_analytics_app_id']) {
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Observable, Observer } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
AWSCredentialsAndIdentityId,
|
|
7
|
+
AuthConfig,
|
|
8
|
+
AuthSession,
|
|
9
|
+
AuthTokens,
|
|
10
|
+
FetchAuthSessionOptions,
|
|
11
|
+
LibraryAuthOptions,
|
|
12
|
+
} from './types';
|
|
13
|
+
import { asserts } from '../../Util/errors/AssertError';
|
|
14
|
+
import { AUTH_CONFING_EXCEPTION } from '../../constants';
|
|
15
|
+
|
|
16
|
+
export function isTokenExpired({
|
|
17
|
+
expiresAt,
|
|
18
|
+
clockDrift,
|
|
19
|
+
}: {
|
|
20
|
+
expiresAt: number;
|
|
21
|
+
clockDrift: number;
|
|
22
|
+
}): boolean {
|
|
23
|
+
const currentTime = Date.now();
|
|
24
|
+
return currentTime + clockDrift > expiresAt;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class AuthClass {
|
|
28
|
+
private authSessionObservers: Set<Observer<AuthSession>>;
|
|
29
|
+
private authConfig?: AuthConfig;
|
|
30
|
+
private authOptions?: LibraryAuthOptions;
|
|
31
|
+
|
|
32
|
+
constructor() {
|
|
33
|
+
this.authSessionObservers = new Set();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Configure Auth category
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*
|
|
41
|
+
* @param authResourcesConfig - Resources configurations required by Auth providers.
|
|
42
|
+
* @param authOptions - Client options used by library
|
|
43
|
+
*
|
|
44
|
+
* @returns void
|
|
45
|
+
*/
|
|
46
|
+
configure(
|
|
47
|
+
authResourcesConfig: AuthConfig,
|
|
48
|
+
authOptions?: LibraryAuthOptions
|
|
49
|
+
): void {
|
|
50
|
+
this.authConfig = authResourcesConfig;
|
|
51
|
+
this.authOptions = authOptions;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async fetchAuthSession(
|
|
55
|
+
options: FetchAuthSessionOptions = {}
|
|
56
|
+
): Promise<AuthSession> {
|
|
57
|
+
let tokens: AuthTokens | undefined;
|
|
58
|
+
let credentialsAndIdentityId: AWSCredentialsAndIdentityId | undefined;
|
|
59
|
+
|
|
60
|
+
// Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
|
|
61
|
+
tokens =
|
|
62
|
+
(await this.authOptions?.tokenProvider?.getTokens(options)) ?? undefined;
|
|
63
|
+
asserts(!!this.authConfig, {
|
|
64
|
+
name: AUTH_CONFING_EXCEPTION,
|
|
65
|
+
message: 'AuthConfig is required',
|
|
66
|
+
recoverySuggestion:
|
|
67
|
+
'call Amplify.configure in your app with a valid AuthConfig',
|
|
68
|
+
});
|
|
69
|
+
if (tokens) {
|
|
70
|
+
// getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
|
|
71
|
+
credentialsAndIdentityId =
|
|
72
|
+
await this.authOptions?.credentialsProvider?.getCredentialsAndIdentityId(
|
|
73
|
+
{
|
|
74
|
+
authConfig: this.authConfig,
|
|
75
|
+
tokens,
|
|
76
|
+
authenticated: true,
|
|
77
|
+
forceRefresh: options.forceRefresh,
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
} else {
|
|
81
|
+
// getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
|
|
82
|
+
credentialsAndIdentityId =
|
|
83
|
+
await this.authOptions?.credentialsProvider?.getCredentialsAndIdentityId(
|
|
84
|
+
{
|
|
85
|
+
authConfig: this.authConfig,
|
|
86
|
+
authenticated: false,
|
|
87
|
+
forceRefresh: options.forceRefresh,
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
tokens,
|
|
94
|
+
credentials: credentialsAndIdentityId?.credentials,
|
|
95
|
+
identityId: credentialsAndIdentityId?.identityId,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Obtain an Observable that notifies on session changes
|
|
101
|
+
*
|
|
102
|
+
* @returns Observable<AmplifyUserSession>
|
|
103
|
+
*/
|
|
104
|
+
listenSessionChanges(): Observable<AuthSession> {
|
|
105
|
+
return new Observable(observer => {
|
|
106
|
+
this.authSessionObservers.add(observer);
|
|
107
|
+
|
|
108
|
+
return () => {
|
|
109
|
+
this.authSessionObservers.delete(observer);
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// From https://github.com/awslabs/aws-jwt-verify/blob/main/src/safe-json-parse.ts
|
|
4
|
+
// From https://github.com/awslabs/aws-jwt-verify/blob/main/src/jwt-model.ts
|
|
5
|
+
|
|
6
|
+
import { Credentials } from '@aws-sdk/types';
|
|
7
|
+
|
|
8
|
+
interface JwtPayloadStandardFields {
|
|
9
|
+
exp?: number; // expires: https://tools.ietf.org/html/rfc7519#section-4.1.4
|
|
10
|
+
iss?: string; // issuer: https://tools.ietf.org/html/rfc7519#section-4.1.1
|
|
11
|
+
aud?: string | string[]; // audience: https://tools.ietf.org/html/rfc7519#section-4.1.3
|
|
12
|
+
nbf?: number; // not before: https://tools.ietf.org/html/rfc7519#section-4.1.5
|
|
13
|
+
iat?: number; // issued at: https://tools.ietf.org/html/rfc7519#section-4.1.6
|
|
14
|
+
scope?: string; // scopes: https://tools.ietf.org/html/rfc6749#section-3.3
|
|
15
|
+
jti?: string; // JWT ID: https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** JSON type */
|
|
19
|
+
type Json = null | string | number | boolean | Json[] | JsonObject;
|
|
20
|
+
|
|
21
|
+
/** JSON Object type */
|
|
22
|
+
type JsonObject = { [name: string]: Json };
|
|
23
|
+
|
|
24
|
+
type JwtPayload = JwtPayloadStandardFields & JsonObject;
|
|
25
|
+
|
|
26
|
+
export type JWT = {
|
|
27
|
+
payload: JwtPayload;
|
|
28
|
+
toString: () => string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type JWTCreator = (stringJWT: string) => JWT;
|
|
32
|
+
|
|
33
|
+
export type AuthSession = {
|
|
34
|
+
tokens?: AuthTokens;
|
|
35
|
+
credentials?: AWSCredentials;
|
|
36
|
+
identityId?: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type LibraryAuthOptions = {
|
|
40
|
+
tokenProvider?: TokenProvider;
|
|
41
|
+
credentialsProvider?: AWSCredentialsAndIdentityIdProvider;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type Identity = {
|
|
45
|
+
id: string;
|
|
46
|
+
type: 'guest' | 'primary';
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export interface AWSCredentialsAndIdentityIdProvider {
|
|
50
|
+
getCredentialsAndIdentityId: (
|
|
51
|
+
getCredentialsOptions: GetCredentialsOptions
|
|
52
|
+
) => Promise<AWSCredentialsAndIdentityId>;
|
|
53
|
+
clearCredentials: () => void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type TokenProvider = {
|
|
57
|
+
getTokens: ({
|
|
58
|
+
forceRefresh,
|
|
59
|
+
}: {
|
|
60
|
+
forceRefresh?: boolean;
|
|
61
|
+
}) => Promise<AuthTokens | null>;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type FetchAuthSessionOptions = {
|
|
65
|
+
forceRefresh?: boolean;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type AuthTokens = {
|
|
69
|
+
idToken?: JWT;
|
|
70
|
+
accessToken: JWT;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type AuthConfig =
|
|
74
|
+
| IdentityPoolConfig
|
|
75
|
+
| UserPoolConfig
|
|
76
|
+
| UserPoolConfigAndIdentityPoolConfig;
|
|
77
|
+
|
|
78
|
+
export type IdentityPoolConfig = {
|
|
79
|
+
identityPoolId: string;
|
|
80
|
+
userPoolWebClientId?: never;
|
|
81
|
+
userPoolId?: never;
|
|
82
|
+
clientMetadata?: never;
|
|
83
|
+
isMandatorySignInEnabled?: never;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type UserPoolConfig = {
|
|
87
|
+
userPoolWebClientId: string;
|
|
88
|
+
userPoolId: string;
|
|
89
|
+
identityPoolId?: never;
|
|
90
|
+
clientMetadata?: Record<string, string>;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export type UserPoolConfigAndIdentityPoolConfig = {
|
|
94
|
+
userPoolWebClientId: string;
|
|
95
|
+
userPoolId: string;
|
|
96
|
+
identityPoolId: string;
|
|
97
|
+
clientMetadata?: Record<string, string>;
|
|
98
|
+
isMandatorySignInEnabled?: boolean;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type GetCredentialsOptions =
|
|
102
|
+
| GetCredentialsAuthenticatedUser
|
|
103
|
+
| GetCredentialsUnauthenticatedUser;
|
|
104
|
+
|
|
105
|
+
type GetCredentialsAuthenticatedUser = {
|
|
106
|
+
authenticated: true;
|
|
107
|
+
forceRefresh?: boolean;
|
|
108
|
+
authConfig: AuthConfig;
|
|
109
|
+
tokens?: AuthTokens;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
type GetCredentialsUnauthenticatedUser = {
|
|
113
|
+
authenticated: false;
|
|
114
|
+
forceRefresh?: boolean;
|
|
115
|
+
authConfig: AuthConfig;
|
|
116
|
+
tokens?: never;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export type AWSCredentialsAndIdentityId = {
|
|
120
|
+
credentials: AWSCredentials;
|
|
121
|
+
identityId?: string;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
type AWSCredentials = {
|
|
125
|
+
accessKeyId: string;
|
|
126
|
+
secretAccessKey: string;
|
|
127
|
+
sessionToken?: string;
|
|
128
|
+
expiration?: Date;
|
|
129
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import { asserts } from '../../../Util/errors/AssertError';
|
|
5
|
+
import {
|
|
6
|
+
AuthConfig,
|
|
7
|
+
IdentityPoolConfig,
|
|
8
|
+
JWT,
|
|
9
|
+
UserPoolConfig,
|
|
10
|
+
UserPoolConfigAndIdentityPoolConfig,
|
|
11
|
+
} from '../types';
|
|
12
|
+
|
|
13
|
+
export function assertTokenProviderConfig(
|
|
14
|
+
authConfig?: AuthConfig
|
|
15
|
+
): asserts authConfig is UserPoolConfig {
|
|
16
|
+
const validConfig =
|
|
17
|
+
!!authConfig?.userPoolId && !!authConfig?.userPoolWebClientId;
|
|
18
|
+
return asserts(validConfig, {
|
|
19
|
+
name: 'AuthTokenConfigException',
|
|
20
|
+
message: 'Auth Token Provider not configured',
|
|
21
|
+
recoverySuggestion: 'Make sure to call Amplify.configure in your app',
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function assertIdentityPooIdConfig(
|
|
26
|
+
authConfig: AuthConfig
|
|
27
|
+
): asserts authConfig is IdentityPoolConfig {
|
|
28
|
+
const validConfig = !!authConfig?.identityPoolId;
|
|
29
|
+
return asserts(validConfig, {
|
|
30
|
+
name: 'AuthIdentityPoolIdException',
|
|
31
|
+
message: 'Auth IdentityPoolId not configured',
|
|
32
|
+
recoverySuggestion:
|
|
33
|
+
'Make sure to call Amplify.configure in your app with a valid IdentityPoolId',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function assertUserPoolAndIdentityPooConfig(
|
|
38
|
+
authConfig: AuthConfig
|
|
39
|
+
): asserts authConfig is UserPoolConfigAndIdentityPoolConfig {
|
|
40
|
+
const validConfig = !!authConfig?.identityPoolId && !!authConfig?.userPoolId;
|
|
41
|
+
return asserts(validConfig, {
|
|
42
|
+
name: 'AuthUserPoolAndIdentityPoolException',
|
|
43
|
+
message: 'Auth UserPool and IdentityPool not configured',
|
|
44
|
+
recoverySuggestion:
|
|
45
|
+
'Make sure to call Amplify.configure in your app with UserPoolId and IdentityPoolId',
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function decodeJWT(token: string): JWT {
|
|
50
|
+
const tokenSplitted = token.split('.');
|
|
51
|
+
if (tokenSplitted.length !== 3) {
|
|
52
|
+
throw new Error('Invalid token');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const payloadString = tokenSplitted[1];
|
|
56
|
+
const payload = JSON.parse(
|
|
57
|
+
Buffer.from(payloadString, 'base64').toString('utf8')
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
return {
|
|
62
|
+
toString: () => token,
|
|
63
|
+
payload,
|
|
64
|
+
};
|
|
65
|
+
} catch (err) {
|
|
66
|
+
throw new Error('Invalid token payload');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export type StorageAccessLevel = 'guest' | 'protected' | 'private';
|
|
5
|
+
|
|
6
|
+
export interface StorageConfig {
|
|
7
|
+
bucket?: string;
|
|
8
|
+
region?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type StoragePrefixResolver = (params: {
|
|
12
|
+
accessLevel: StorageAccessLevel;
|
|
13
|
+
targetIdentityId?: string;
|
|
14
|
+
}) => Promise<string>;
|
|
15
|
+
|
|
16
|
+
// TODO[AllanZhengYP]: support isObjectLockEnabled config to S3 plugin config
|
|
17
|
+
// TODO[AllanZhengYP]: need to finalize the decision whether to move defaultAccessLevel to StorageConfig
|
|
18
|
+
export interface LibraryStorageOptions {
|
|
19
|
+
prefixResolver?: StoragePrefixResolver;
|
|
20
|
+
defaultAccessLevel?: StorageAccessLevel;
|
|
21
|
+
}
|