@aws-amplify/core 6.0.1-console-preview.f63250a.0 → 6.0.1-console-preview.e8aa063.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/internals/adapter-core/package.json +8 -0
- package/internals/providers/pinpoint/package.json +8 -0
- package/internals/utils/package.json +7 -0
- package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +1 -1
- package/lib/AwsClients/CognitoIdentity/getId.d.ts +1 -1
- package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +1 -1
- package/lib/AwsClients/Pinpoint/index.d.ts +1 -1
- package/lib/AwsClients/Pinpoint/putEvents.d.ts +1 -1
- package/lib/AwsClients/Pinpoint/putEvents.js +2 -2
- package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +1 -1
- package/lib/Cache/AsyncStorageCache.js +3 -3
- package/lib/Cache/BrowserStorageCache.js +5 -5
- package/lib/Cache/InMemoryCache.js +3 -3
- package/lib/Cache/StorageCache.js +1 -1
- package/lib/Cache/Utils/CacheList.js +5 -5
- package/lib/Credentials.js +2 -5
- package/lib/{Hub.d.ts → Hub/index.d.ts} +5 -21
- package/lib/Hub/index.js +151 -0
- package/lib/Hub/types/AuthTypes.d.ts +11 -0
- package/lib/Hub/types/HubTypes.d.ts +28 -0
- package/lib/Hub/types/HubTypes.js +4 -0
- package/lib/Hub/types/index.d.ts +2 -0
- package/lib/Hub/types/index.js +20 -0
- package/lib/I18n/I18n.js +1 -1
- package/lib/I18n/index.js +5 -5
- package/lib/OAuthHelper/FacebookOAuth.js +1 -1
- package/lib/OAuthHelper/GoogleOAuth.js +1 -1
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/RNComponents/index.d.ts +1 -0
- package/lib/RNComponents/index.js +2 -1
- package/lib/RNComponents/isAppInForeground.d.ts +1 -0
- package/lib/RNComponents/isAppInForeground.js +10 -0
- package/lib/ServiceWorker/ServiceWorker.js +9 -9
- package/lib/StorageHelper/localStorage.js +1 -1
- package/lib/StorageHelper/sessionStorage.js +1 -1
- package/lib/UniversalStorage/index.js +1 -1
- package/lib/Util/Constants.d.ts +12 -8
- package/lib/Util/Constants.js +21 -15
- package/lib/{Errors.d.ts → Util/Errors.d.ts} +1 -1
- package/lib/Util/Reachability.js +1 -1
- package/lib/Util/errors/AssertError.js +1 -1
- package/lib/Util/index.d.ts +1 -1
- package/lib/Util/index.js +1 -5
- package/lib/adapterCore/error/AmplifyServerContextError.d.ts +8 -0
- package/lib/adapterCore/error/AmplifyServerContextError.js +35 -0
- package/lib/adapterCore/error/index.d.ts +1 -0
- package/lib/adapterCore/error/index.js +7 -0
- package/lib/adapterCore/index.d.ts +2 -0
- package/lib/adapterCore/index.js +11 -0
- package/lib/adapterCore/serverContext/index.d.ts +2 -0
- package/lib/adapterCore/serverContext/index.js +9 -0
- package/lib/adapterCore/serverContext/serverContext.d.ts +20 -0
- package/lib/adapterCore/serverContext/serverContext.js +42 -0
- package/lib/adapterCore/serverContext/serverContextRegistry.d.ts +6 -0
- package/lib/adapterCore/serverContext/serverContextRegistry.js +24 -0
- package/lib/adapterCore/serverContext/types/amplifyServer.d.ts +16 -0
- package/lib/adapterCore/serverContext/types/amplifyServer.js +4 -0
- package/lib/adapterCore/serverContext/types/cookieStorage.d.ts +31 -0
- package/lib/adapterCore/serverContext/types/cookieStorage.js +4 -0
- package/lib/adapterCore/serverContext/types/index.d.ts +4 -0
- package/lib/adapterCore/serverContext/types/index.js +4 -0
- package/lib/clients/handlers/fetch.js +1 -0
- package/lib/clients/internal/composeServiceApi.d.ts +5 -2
- package/lib/index.d.ts +11 -32
- package/lib/index.js +19 -100
- package/lib/libraryUtils.d.ts +21 -0
- package/lib/libraryUtils.js +105 -0
- package/lib/providers/pinpoint/apis/index.d.ts +2 -0
- package/lib/providers/pinpoint/apis/index.js +9 -0
- package/lib/providers/pinpoint/apis/record.d.ts +5 -0
- package/lib/providers/pinpoint/apis/record.js +120 -0
- package/lib/providers/pinpoint/apis/updateEndpoint.d.ts +5 -0
- package/lib/providers/pinpoint/apis/updateEndpoint.js +120 -0
- package/lib/providers/pinpoint/index.d.ts +2 -0
- package/lib/providers/pinpoint/index.js +19 -0
- package/lib/providers/pinpoint/types/buffer.d.ts +25 -0
- package/lib/providers/pinpoint/types/buffer.js +4 -0
- package/lib/providers/pinpoint/types/index.d.ts +1 -0
- package/lib/providers/pinpoint/types/index.js +19 -0
- package/lib/providers/pinpoint/types/pinpoint.d.ts +40 -0
- package/lib/providers/pinpoint/types/pinpoint.js +4 -0
- package/lib/providers/pinpoint/utils/PinpointEventBuffer.d.ts +23 -0
- package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +278 -0
- package/lib/providers/pinpoint/utils/cacheEndpointId.d.ts +7 -0
- package/lib/providers/pinpoint/utils/cacheEndpointId.js +61 -0
- package/lib/providers/pinpoint/utils/constants.d.ts +4 -0
- package/lib/providers/pinpoint/utils/constants.js +10 -0
- package/lib/providers/pinpoint/utils/getCacheKey.d.ts +7 -0
- package/lib/providers/pinpoint/utils/getCacheKey.js +13 -0
- package/lib/providers/pinpoint/utils/getEndpointId.d.ts +7 -0
- package/lib/providers/pinpoint/utils/getEndpointId.js +62 -0
- package/lib/providers/pinpoint/utils/getEventBuffer.d.ts +8 -0
- package/lib/providers/pinpoint/utils/getEventBuffer.js +48 -0
- package/lib/providers/pinpoint/utils/index.d.ts +3 -0
- package/lib/providers/pinpoint/utils/index.js +11 -0
- package/lib/server.d.ts +1 -0
- package/lib/server.js +7 -0
- package/lib/singleton/Amplify.d.ts +36 -0
- package/lib/singleton/Amplify.js +138 -0
- package/lib/singleton/Analytics/types.d.ts +2 -0
- package/lib/singleton/Analytics/types.js +4 -0
- package/lib/singleton/Auth/index.js +15 -12
- package/lib/singleton/Auth/types.d.ts +28 -3
- package/lib/singleton/Auth/utils/index.d.ts +3 -2
- package/lib/singleton/Auth/utils/index.js +15 -1
- package/lib/singleton/Storage/types.d.ts +6 -2
- package/lib/singleton/apis/fetchAuthSession.d.ts +2 -0
- package/lib/singleton/apis/fetchAuthSession.js +11 -0
- package/lib/singleton/apis/internal/fetchAuthSession.d.ts +3 -0
- package/lib/singleton/apis/internal/fetchAuthSession.js +9 -0
- package/lib/singleton/apis/server/fetchAuthSession.d.ts +3 -0
- package/lib/singleton/apis/server/fetchAuthSession.js +11 -0
- package/lib/singleton/index.d.ts +2 -46
- package/lib/singleton/index.js +7 -144
- package/lib/singleton/types.d.ts +3 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/core.d.ts +47 -0
- package/lib/types/core.js +4 -0
- package/lib/types/errors.d.ts +16 -0
- package/lib/types/errors.js +4 -0
- package/lib/types/index.d.ts +4 -1
- package/lib/types/index.js +6 -3
- package/lib/types/logging.d.ts +13 -0
- package/lib/types/logging.js +4 -0
- package/lib/types/storage.d.ts +14 -0
- package/lib/types/storage.js +4 -0
- package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +1 -1
- package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +1 -1
- package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +1 -1
- package/lib-esm/AwsClients/Pinpoint/index.d.ts +1 -1
- package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +1 -1
- package/lib-esm/AwsClients/Pinpoint/putEvents.js +1 -1
- package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +1 -1
- package/lib-esm/Cache/AsyncStorageCache.js +1 -1
- package/lib-esm/Cache/BrowserStorageCache.js +1 -1
- package/lib-esm/Cache/InMemoryCache.js +1 -1
- package/lib-esm/Cache/StorageCache.js +2 -2
- package/lib-esm/Cache/Utils/CacheList.js +1 -1
- package/lib-esm/Credentials.js +2 -5
- package/lib-esm/{Hub.d.ts → Hub/index.d.ts} +5 -21
- package/lib-esm/Hub/index.js +148 -0
- package/lib-esm/Hub/types/AuthTypes.d.ts +11 -0
- package/lib-esm/Hub/types/HubTypes.d.ts +28 -0
- package/lib-esm/Hub/types/HubTypes.js +3 -0
- package/lib-esm/Hub/types/index.d.ts +2 -0
- package/lib-esm/Hub/types/index.js +4 -0
- package/lib-esm/I18n/I18n.js +2 -2
- package/lib-esm/I18n/index.js +1 -1
- package/lib-esm/OAuthHelper/FacebookOAuth.js +1 -1
- package/lib-esm/OAuthHelper/GoogleOAuth.js +1 -1
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/RNComponents/index.d.ts +1 -0
- package/lib-esm/RNComponents/index.js +2 -1
- package/lib-esm/RNComponents/isAppInForeground.d.ts +1 -0
- package/lib-esm/RNComponents/isAppInForeground.js +6 -0
- package/lib-esm/ServiceWorker/ServiceWorker.js +3 -3
- package/lib-esm/StorageHelper/localStorage.js +1 -1
- package/lib-esm/StorageHelper/sessionStorage.js +1 -1
- package/lib-esm/UniversalStorage/index.js +1 -1
- package/lib-esm/Util/Constants.d.ts +12 -8
- package/lib-esm/Util/Constants.js +20 -8
- package/lib-esm/{Errors.d.ts → Util/Errors.d.ts} +1 -1
- package/lib-esm/Util/Reachability.js +1 -1
- package/lib-esm/Util/errors/AssertError.js +1 -1
- package/lib-esm/Util/index.d.ts +1 -1
- package/lib-esm/Util/index.js +1 -1
- package/lib-esm/adapterCore/error/AmplifyServerContextError.d.ts +8 -0
- package/lib-esm/adapterCore/error/AmplifyServerContextError.js +32 -0
- package/lib-esm/adapterCore/error/index.d.ts +1 -0
- package/lib-esm/adapterCore/error/index.js +3 -0
- package/lib-esm/adapterCore/index.d.ts +2 -0
- package/lib-esm/adapterCore/index.js +4 -0
- package/lib-esm/adapterCore/serverContext/index.d.ts +2 -0
- package/lib-esm/adapterCore/serverContext/index.js +3 -0
- package/lib-esm/adapterCore/serverContext/serverContext.d.ts +20 -0
- package/lib-esm/adapterCore/serverContext/serverContext.js +36 -0
- package/lib-esm/adapterCore/serverContext/serverContextRegistry.d.ts +6 -0
- package/lib-esm/adapterCore/serverContext/serverContextRegistry.js +21 -0
- package/lib-esm/adapterCore/serverContext/types/amplifyServer.d.ts +16 -0
- package/lib-esm/adapterCore/serverContext/types/amplifyServer.js +3 -0
- package/lib-esm/adapterCore/serverContext/types/cookieStorage.d.ts +31 -0
- package/lib-esm/adapterCore/serverContext/types/cookieStorage.js +3 -0
- package/lib-esm/adapterCore/serverContext/types/index.d.ts +4 -0
- package/lib-esm/adapterCore/serverContext/types/index.js +3 -0
- package/lib-esm/clients/handlers/fetch.js +1 -0
- package/lib-esm/clients/internal/composeServiceApi.d.ts +5 -2
- package/lib-esm/index.d.ts +11 -32
- package/lib-esm/index.js +11 -29
- package/lib-esm/libraryUtils.d.ts +21 -0
- package/lib-esm/libraryUtils.js +33 -0
- package/lib-esm/providers/pinpoint/apis/index.d.ts +2 -0
- package/lib-esm/providers/pinpoint/apis/index.js +4 -0
- package/lib-esm/providers/pinpoint/apis/record.d.ts +5 -0
- package/lib-esm/providers/pinpoint/apis/record.js +116 -0
- package/lib-esm/providers/pinpoint/apis/updateEndpoint.d.ts +5 -0
- package/lib-esm/providers/pinpoint/apis/updateEndpoint.js +116 -0
- package/lib-esm/providers/pinpoint/index.d.ts +2 -0
- package/lib-esm/providers/pinpoint/index.js +3 -0
- package/lib-esm/providers/pinpoint/types/buffer.d.ts +25 -0
- package/lib-esm/providers/pinpoint/types/buffer.js +3 -0
- package/lib-esm/providers/pinpoint/types/index.d.ts +1 -0
- package/lib-esm/providers/pinpoint/types/index.js +3 -0
- package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +40 -0
- package/lib-esm/providers/pinpoint/types/pinpoint.js +3 -0
- package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.d.ts +23 -0
- package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +275 -0
- package/lib-esm/providers/pinpoint/utils/cacheEndpointId.d.ts +7 -0
- package/lib-esm/providers/pinpoint/utils/cacheEndpointId.js +57 -0
- package/lib-esm/providers/pinpoint/utils/constants.d.ts +4 -0
- package/lib-esm/providers/pinpoint/utils/constants.js +7 -0
- package/lib-esm/providers/pinpoint/utils/getCacheKey.d.ts +7 -0
- package/lib-esm/providers/pinpoint/utils/getCacheKey.js +9 -0
- package/lib-esm/providers/pinpoint/utils/getEndpointId.d.ts +7 -0
- package/lib-esm/providers/pinpoint/utils/getEndpointId.js +58 -0
- package/lib-esm/providers/pinpoint/utils/getEventBuffer.d.ts +8 -0
- package/lib-esm/providers/pinpoint/utils/getEventBuffer.js +44 -0
- package/lib-esm/providers/pinpoint/utils/index.d.ts +3 -0
- package/lib-esm/providers/pinpoint/utils/index.js +5 -0
- package/lib-esm/server.d.ts +1 -0
- package/lib-esm/server.js +3 -0
- package/lib-esm/singleton/Amplify.d.ts +36 -0
- package/lib-esm/singleton/Amplify.js +135 -0
- package/lib-esm/singleton/Analytics/types.d.ts +2 -0
- package/lib-esm/singleton/Analytics/types.js +3 -0
- package/lib-esm/singleton/Auth/index.js +14 -11
- package/lib-esm/singleton/Auth/types.d.ts +28 -3
- package/lib-esm/singleton/Auth/utils/index.d.ts +3 -2
- package/lib-esm/singleton/Auth/utils/index.js +13 -0
- package/lib-esm/singleton/Storage/types.d.ts +6 -2
- package/lib-esm/singleton/apis/fetchAuthSession.d.ts +2 -0
- package/lib-esm/singleton/apis/fetchAuthSession.js +7 -0
- package/lib-esm/singleton/apis/internal/fetchAuthSession.d.ts +3 -0
- package/lib-esm/singleton/apis/internal/fetchAuthSession.js +5 -0
- package/lib-esm/singleton/apis/server/fetchAuthSession.d.ts +3 -0
- package/lib-esm/singleton/apis/server/fetchAuthSession.js +7 -0
- package/lib-esm/singleton/index.d.ts +2 -46
- package/lib-esm/singleton/index.js +2 -141
- package/lib-esm/singleton/types.d.ts +3 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/core.d.ts +47 -0
- package/lib-esm/types/core.js +3 -0
- package/lib-esm/types/errors.d.ts +16 -0
- package/lib-esm/types/errors.js +3 -0
- package/lib-esm/types/index.d.ts +4 -1
- package/lib-esm/types/index.js +4 -1
- package/lib-esm/types/logging.d.ts +13 -0
- package/lib-esm/types/logging.js +3 -0
- package/lib-esm/types/storage.d.ts +14 -0
- package/lib-esm/types/storage.js +3 -0
- package/package.json +15 -12
- package/server/package.json +8 -0
- package/src/AwsClients/Pinpoint/index.ts +1 -1
- package/src/AwsClients/Pinpoint/putEvents.ts +1 -1
- package/src/Cache/AsyncStorageCache.ts +1 -1
- package/src/Cache/BrowserStorageCache.ts +1 -1
- package/src/Cache/InMemoryCache.ts +1 -1
- package/src/Cache/StorageCache.ts +2 -2
- package/src/Cache/Utils/CacheList.ts +1 -1
- package/src/Credentials.ts +2 -8
- package/src/Hub/index.ts +204 -0
- package/src/Hub/types/AuthTypes.ts +10 -0
- package/src/Hub/types/HubTypes.ts +46 -0
- package/src/{Providers → Hub/types}/index.ts +3 -1
- package/src/I18n/I18n.ts +2 -2
- package/src/I18n/index.ts +1 -1
- package/src/Logger/ConsoleLogger.ts +1 -2
- package/src/OAuthHelper/FacebookOAuth.ts +1 -1
- package/src/OAuthHelper/GoogleOAuth.ts +1 -1
- package/src/Platform/version.ts +1 -1
- package/src/RNComponents/index.ts +2 -1
- package/src/RNComponents/isAppInForeground.ts +8 -0
- package/src/ServiceWorker/ServiceWorker.ts +3 -3
- package/src/StorageHelper/localStorage.ts +1 -1
- package/src/StorageHelper/sessionStorage.ts +1 -1
- package/src/UniversalStorage/index.ts +1 -1
- package/src/Util/Constants.ts +25 -16
- package/src/{Errors.ts → Util/Errors.ts} +1 -1
- package/src/Util/Reachability.ts +1 -1
- package/src/Util/errors/AssertError.ts +1 -1
- package/src/Util/index.ts +0 -4
- package/src/adapterCore/error/AmplifyServerContextError.ts +23 -0
- package/src/adapterCore/error/index.ts +4 -0
- package/src/adapterCore/index.ts +11 -0
- package/src/adapterCore/serverContext/index.ts +10 -0
- package/src/adapterCore/serverContext/serverContext.ts +54 -0
- package/src/adapterCore/serverContext/serverContextRegistry.ts +31 -0
- package/src/adapterCore/serverContext/types/amplifyServer.ts +29 -0
- package/src/adapterCore/serverContext/types/cookieStorage.ts +43 -0
- package/src/adapterCore/serverContext/types/index.ts +9 -0
- package/src/clients/handlers/fetch.ts +1 -0
- package/src/clients/internal/composeServiceApi.ts +13 -4
- package/src/index.ts +40 -120
- package/src/libraryUtils.ts +102 -0
- package/src/providers/pinpoint/apis/index.ts +5 -0
- package/src/providers/pinpoint/apis/record.ts +90 -0
- package/src/providers/pinpoint/apis/updateEndpoint.ts +82 -0
- package/src/providers/pinpoint/index.ts +5 -0
- package/src/providers/pinpoint/types/buffer.ts +32 -0
- package/{lib-esm/Providers/index.js → src/providers/pinpoint/types/index.ts} +2 -1
- package/src/providers/pinpoint/types/pinpoint.ts +55 -0
- package/src/providers/pinpoint/utils/PinpointEventBuffer.ts +248 -0
- package/src/providers/pinpoint/utils/cacheEndpointId.ts +27 -0
- package/src/providers/pinpoint/utils/constants.ts +8 -0
- package/src/providers/pinpoint/utils/getCacheKey.ts +16 -0
- package/src/providers/pinpoint/utils/getEndpointId.ts +20 -0
- package/src/providers/pinpoint/utils/getEventBuffer.ts +60 -0
- package/src/providers/pinpoint/utils/index.ts +6 -0
- package/src/server.ts +4 -0
- package/src/singleton/Amplify.ts +121 -0
- package/src/singleton/Analytics/types.ts +6 -0
- package/src/singleton/Auth/index.ts +7 -5
- package/src/singleton/Auth/types.ts +38 -6
- package/src/singleton/Auth/utils/index.ts +27 -1
- package/src/singleton/Storage/types.ts +6 -3
- package/src/singleton/apis/fetchAuthSession.ts +12 -0
- package/src/singleton/apis/internal/fetchAuthSession.ts +12 -0
- package/src/singleton/apis/server/fetchAuthSession.ts +16 -0
- package/src/singleton/index.ts +2 -128
- package/src/singleton/types.ts +4 -4
- package/src/types/core.ts +58 -0
- package/src/types/errors.ts +21 -0
- package/src/types/index.ts +5 -1
- package/src/types/logging.ts +24 -0
- package/src/types/storage.ts +19 -0
- package/lib/Hub.js +0 -220
- package/lib/Providers/AWSCloudWatchProvider.d.ts +0 -34
- package/lib/Providers/AWSCloudWatchProvider.js +0 -619
- package/lib/Providers/index.d.ts +0 -1
- package/lib/Providers/index.js +0 -7
- package/lib/constants.d.ts +0 -9
- package/lib/constants.js +0 -22
- package/lib/types/types.d.ts +0 -76
- package/lib-esm/Hub.js +0 -217
- package/lib-esm/Providers/AWSCloudWatchProvider.d.ts +0 -34
- package/lib-esm/Providers/AWSCloudWatchProvider.js +0 -616
- package/lib-esm/Providers/index.d.ts +0 -1
- package/lib-esm/constants.d.ts +0 -9
- package/lib-esm/constants.js +0 -19
- package/lib-esm/types/types.d.ts +0 -76
- package/src/Hub.ts +0 -236
- package/src/Providers/AWSCloudWatchProvider.ts +0 -540
- package/src/constants.ts +0 -31
- package/src/types/types.ts +0 -104
- /package/lib/{types/types.js → Hub/types/AuthTypes.js} +0 -0
- /package/lib/{Errors.js → Util/Errors.js} +0 -0
- /package/lib/{JS.d.ts → Util/JS.d.ts} +0 -0
- /package/lib/{JS.js → Util/JS.js} +0 -0
- /package/lib-esm/{types/types.js → Hub/types/AuthTypes.js} +0 -0
- /package/lib-esm/{Errors.js → Util/Errors.js} +0 -0
- /package/lib-esm/{JS.d.ts → Util/JS.d.ts} +0 -0
- /package/lib-esm/{JS.js → Util/JS.js} +0 -0
- /package/src/{JS.ts → Util/JS.ts} +0 -0
|
@@ -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 { EventBufferConfig } from '../types/buffer';
|
|
5
|
+
import { PinpointEventBuffer } from './PinpointEventBuffer';
|
|
6
|
+
import { BUFFER_SIZE, FLUSH_INTERVAL, FLUSH_SIZE, RESEND_LIMIT } from './constants';
|
|
7
|
+
|
|
8
|
+
// Map of buffers by region -> appId
|
|
9
|
+
const eventBufferMap: Record<string, Record<string, PinpointEventBuffer>> = {};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns a PinpointEventBuffer instance for the specified region & app ID, creating one if it does not yet exist.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export const getEventBuffer = ({
|
|
17
|
+
appId,
|
|
18
|
+
bufferSize = BUFFER_SIZE,
|
|
19
|
+
credentials,
|
|
20
|
+
flushInterval = FLUSH_INTERVAL,
|
|
21
|
+
flushSize = FLUSH_SIZE,
|
|
22
|
+
identityId,
|
|
23
|
+
region,
|
|
24
|
+
resendLimit = RESEND_LIMIT,
|
|
25
|
+
userAgentValue
|
|
26
|
+
}: EventBufferConfig): PinpointEventBuffer => {
|
|
27
|
+
if (eventBufferMap[region]?.[appId]) {
|
|
28
|
+
const buffer = eventBufferMap[region][appId];
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
If the identity has changed flush out the buffer and create a new instance. The old instance will be garbage
|
|
32
|
+
collected.
|
|
33
|
+
*/
|
|
34
|
+
if (buffer.identityHasChanged(identityId)) {
|
|
35
|
+
buffer.flush();
|
|
36
|
+
} else {
|
|
37
|
+
return buffer;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const buffer = new PinpointEventBuffer({
|
|
42
|
+
appId,
|
|
43
|
+
bufferSize,
|
|
44
|
+
credentials,
|
|
45
|
+
flushInterval,
|
|
46
|
+
flushSize,
|
|
47
|
+
identityId,
|
|
48
|
+
region,
|
|
49
|
+
resendLimit,
|
|
50
|
+
userAgentValue
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (!eventBufferMap[region]) {
|
|
54
|
+
eventBufferMap[region] = {};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
eventBufferMap[region][appId] = buffer;
|
|
58
|
+
|
|
59
|
+
return buffer;
|
|
60
|
+
};
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { AuthClass } from './Auth';
|
|
4
|
+
import { Hub, AMPLIFY_SYMBOL } from '../Hub';
|
|
5
|
+
import { LibraryOptions, ResourcesConfig } from './types';
|
|
6
|
+
|
|
7
|
+
// TODO(v6): add default AuthTokenStore for each platform
|
|
8
|
+
|
|
9
|
+
export class AmplifyClass {
|
|
10
|
+
resourcesConfig: ResourcesConfig;
|
|
11
|
+
libraryOptions: LibraryOptions;
|
|
12
|
+
/**
|
|
13
|
+
* Cross-category Auth utilities.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
public readonly Auth: AuthClass;
|
|
18
|
+
constructor() {
|
|
19
|
+
this.resourcesConfig = {};
|
|
20
|
+
this.Auth = new AuthClass();
|
|
21
|
+
|
|
22
|
+
// TODO(v6): add default providers for getting started
|
|
23
|
+
this.libraryOptions = {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Configures Amplify for use with your back-end resources.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* `configure` can be used to specify additional library options where available for supported categories.
|
|
31
|
+
*
|
|
32
|
+
* @param resourceConfig - Back-end resource configuration. Typically provided via the `aws-exports.js` file.
|
|
33
|
+
* @param libraryOptions - Additional options for customizing the behavior of the library.
|
|
34
|
+
*/
|
|
35
|
+
configure(
|
|
36
|
+
resourcesConfig: ResourcesConfig,
|
|
37
|
+
libraryOptions: LibraryOptions = {}
|
|
38
|
+
): void {
|
|
39
|
+
this.resourcesConfig = mergeResourceConfig(
|
|
40
|
+
this.resourcesConfig,
|
|
41
|
+
resourcesConfig
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
this.libraryOptions = mergeLibraryOptions(
|
|
45
|
+
this.libraryOptions,
|
|
46
|
+
libraryOptions
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
this.Auth.configure(this.resourcesConfig.Auth!, this.libraryOptions.Auth);
|
|
50
|
+
|
|
51
|
+
Hub.dispatch(
|
|
52
|
+
'core',
|
|
53
|
+
{
|
|
54
|
+
event: 'configure',
|
|
55
|
+
data: resourcesConfig,
|
|
56
|
+
},
|
|
57
|
+
'Configure',
|
|
58
|
+
AMPLIFY_SYMBOL
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Provides access to the current back-end resource configuration for the Library.
|
|
64
|
+
*
|
|
65
|
+
* @returns Returns the current back-end resource configuration.
|
|
66
|
+
*/
|
|
67
|
+
getConfig(): ResourcesConfig {
|
|
68
|
+
return JSON.parse(JSON.stringify(this.resourcesConfig));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The `Amplify` utility is used to configure the library.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* `Amplify` is responsible for orchestrating cross-category communication within the library.
|
|
77
|
+
*/
|
|
78
|
+
export const Amplify = new AmplifyClass();
|
|
79
|
+
|
|
80
|
+
// TODO(v6): validate until which level this will nested, during Amplify.configure API review.
|
|
81
|
+
function mergeResourceConfig(
|
|
82
|
+
existingConfig: ResourcesConfig,
|
|
83
|
+
newConfig: ResourcesConfig
|
|
84
|
+
): ResourcesConfig {
|
|
85
|
+
const resultConfig: Record<string, any> = {};
|
|
86
|
+
|
|
87
|
+
for (const category of Object.keys(existingConfig)) {
|
|
88
|
+
resultConfig[category] = existingConfig[category as keyof ResourcesConfig];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const key of Object.keys(newConfig).filter(key => key !== 'ssr')) {
|
|
92
|
+
resultConfig[key] = {
|
|
93
|
+
...resultConfig[key],
|
|
94
|
+
...newConfig[key as Exclude<keyof ResourcesConfig, 'ssr'>],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
resultConfig.ssr = newConfig.ssr;
|
|
99
|
+
|
|
100
|
+
return resultConfig;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function mergeLibraryOptions(
|
|
104
|
+
existingConfig: LibraryOptions,
|
|
105
|
+
newConfig: LibraryOptions
|
|
106
|
+
): LibraryOptions {
|
|
107
|
+
const resultConfig: Record<string, any> = {};
|
|
108
|
+
|
|
109
|
+
for (const category of Object.keys(existingConfig)) {
|
|
110
|
+
resultConfig[category] = existingConfig[category as keyof LibraryOptions];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (const category of Object.keys(newConfig)) {
|
|
114
|
+
resultConfig[category] = {
|
|
115
|
+
...resultConfig[category],
|
|
116
|
+
...newConfig[category as keyof LibraryOptions],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return resultConfig;
|
|
121
|
+
}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
LibraryAuthOptions,
|
|
12
12
|
} from './types';
|
|
13
13
|
import { asserts } from '../../Util/errors/AssertError';
|
|
14
|
-
import { AUTH_CONFING_EXCEPTION } from '../../
|
|
14
|
+
import { AUTH_CONFING_EXCEPTION } from '../../Util/Constants';
|
|
15
15
|
|
|
16
16
|
export function isTokenExpired({
|
|
17
17
|
expiresAt,
|
|
@@ -57,15 +57,17 @@ export class AuthClass {
|
|
|
57
57
|
let tokens: AuthTokens | undefined;
|
|
58
58
|
let credentialsAndIdentityId: AWSCredentialsAndIdentityId | undefined;
|
|
59
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
60
|
asserts(!!this.authConfig, {
|
|
64
61
|
name: AUTH_CONFING_EXCEPTION,
|
|
65
62
|
message: 'AuthConfig is required',
|
|
66
63
|
recoverySuggestion:
|
|
67
64
|
'call Amplify.configure in your app with a valid AuthConfig',
|
|
68
65
|
});
|
|
66
|
+
|
|
67
|
+
// Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
|
|
68
|
+
tokens =
|
|
69
|
+
(await this.authOptions?.tokenProvider?.getTokens(options)) ?? undefined;
|
|
70
|
+
|
|
69
71
|
if (tokens) {
|
|
70
72
|
// getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
|
|
71
73
|
credentialsAndIdentityId =
|
|
@@ -77,7 +79,7 @@ export class AuthClass {
|
|
|
77
79
|
forceRefresh: options.forceRefresh,
|
|
78
80
|
}
|
|
79
81
|
);
|
|
80
|
-
} else {
|
|
82
|
+
} else if (!this.authConfig.isMandatorySignInEnabled) {
|
|
81
83
|
// getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
|
|
82
84
|
credentialsAndIdentityId =
|
|
83
85
|
await this.authOptions?.credentialsProvider?.getCredentialsAndIdentityId(
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
// From https://github.com/awslabs/aws-jwt-verify/blob/main/src/safe-json-parse.ts
|
|
4
4
|
// From https://github.com/awslabs/aws-jwt-verify/blob/main/src/jwt-model.ts
|
|
5
5
|
|
|
6
|
-
import { Credentials } from '@aws-sdk/types';
|
|
7
|
-
|
|
8
6
|
interface JwtPayloadStandardFields {
|
|
9
7
|
exp?: number; // expires: https://tools.ietf.org/html/rfc7519#section-4.1.4
|
|
10
8
|
iss?: string; // issuer: https://tools.ietf.org/html/rfc7519#section-4.1.1
|
|
@@ -56,7 +54,7 @@ export interface AWSCredentialsAndIdentityIdProvider {
|
|
|
56
54
|
export type TokenProvider = {
|
|
57
55
|
getTokens: ({
|
|
58
56
|
forceRefresh,
|
|
59
|
-
}
|
|
57
|
+
}?: {
|
|
60
58
|
forceRefresh?: boolean;
|
|
61
59
|
}) => Promise<AuthTokens | null>;
|
|
62
60
|
};
|
|
@@ -70,10 +68,19 @@ export type AuthTokens = {
|
|
|
70
68
|
accessToken: JWT;
|
|
71
69
|
};
|
|
72
70
|
|
|
73
|
-
export type AuthConfig =
|
|
71
|
+
export type AuthConfig = StrictUnion<
|
|
74
72
|
| IdentityPoolConfig
|
|
75
73
|
| UserPoolConfig
|
|
76
|
-
|
|
|
74
|
+
| UserPoolConfigWithOAuth
|
|
75
|
+
| UserPoolConfigAndIdentityPoolConfig
|
|
76
|
+
| UserPoolConfigAndIdentityPoolConfigWithOAuth
|
|
77
|
+
>;
|
|
78
|
+
|
|
79
|
+
type UnionKeys<T> = T extends T ? keyof T : never;
|
|
80
|
+
type StrictUnionHelper<T, TAll> = T extends any
|
|
81
|
+
? T & Partial<Record<Exclude<UnionKeys<TAll>, keyof T>, never>>
|
|
82
|
+
: never;
|
|
83
|
+
type StrictUnion<T> = StrictUnionHelper<T, T>;
|
|
77
84
|
|
|
78
85
|
export type IdentityPoolConfig = {
|
|
79
86
|
identityPoolId: string;
|
|
@@ -90,6 +97,22 @@ export type UserPoolConfig = {
|
|
|
90
97
|
clientMetadata?: Record<string, string>;
|
|
91
98
|
};
|
|
92
99
|
|
|
100
|
+
export type UserPoolConfigWithOAuth = {
|
|
101
|
+
userPoolWebClientId: string;
|
|
102
|
+
userPoolId: string;
|
|
103
|
+
identityPoolId?: never;
|
|
104
|
+
clientMetadata?: Record<string, string>;
|
|
105
|
+
oauth: OAuthConfig;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export type OAuthConfig = {
|
|
109
|
+
domain: string;
|
|
110
|
+
scopes: Array<string>;
|
|
111
|
+
redirectSignIn: string;
|
|
112
|
+
redirectSignOut: string;
|
|
113
|
+
responseType: string;
|
|
114
|
+
};
|
|
115
|
+
|
|
93
116
|
export type UserPoolConfigAndIdentityPoolConfig = {
|
|
94
117
|
userPoolWebClientId: string;
|
|
95
118
|
userPoolId: string;
|
|
@@ -98,6 +121,15 @@ export type UserPoolConfigAndIdentityPoolConfig = {
|
|
|
98
121
|
isMandatorySignInEnabled?: boolean;
|
|
99
122
|
};
|
|
100
123
|
|
|
124
|
+
export type UserPoolConfigAndIdentityPoolConfigWithOAuth = {
|
|
125
|
+
userPoolWebClientId: string;
|
|
126
|
+
userPoolId: string;
|
|
127
|
+
identityPoolId: string;
|
|
128
|
+
clientMetadata?: Record<string, string>;
|
|
129
|
+
isMandatorySignInEnabled?: boolean;
|
|
130
|
+
oauth: OAuthConfig;
|
|
131
|
+
};
|
|
132
|
+
|
|
101
133
|
export type GetCredentialsOptions =
|
|
102
134
|
| GetCredentialsAuthenticatedUser
|
|
103
135
|
| GetCredentialsUnauthenticatedUser;
|
|
@@ -106,7 +138,7 @@ type GetCredentialsAuthenticatedUser = {
|
|
|
106
138
|
authenticated: true;
|
|
107
139
|
forceRefresh?: boolean;
|
|
108
140
|
authConfig: AuthConfig;
|
|
109
|
-
tokens
|
|
141
|
+
tokens: AuthTokens;
|
|
110
142
|
};
|
|
111
143
|
|
|
112
144
|
type GetCredentialsUnauthenticatedUser = {
|
|
@@ -8,11 +8,17 @@ import {
|
|
|
8
8
|
JWT,
|
|
9
9
|
UserPoolConfig,
|
|
10
10
|
UserPoolConfigAndIdentityPoolConfig,
|
|
11
|
+
UserPoolConfigAndIdentityPoolConfigWithOAuth,
|
|
12
|
+
UserPoolConfigWithOAuth,
|
|
11
13
|
} from '../types';
|
|
12
14
|
|
|
13
15
|
export function assertTokenProviderConfig(
|
|
14
16
|
authConfig?: AuthConfig
|
|
15
|
-
): asserts authConfig is
|
|
17
|
+
): asserts authConfig is
|
|
18
|
+
| UserPoolConfigAndIdentityPoolConfigWithOAuth
|
|
19
|
+
| UserPoolConfigWithOAuth
|
|
20
|
+
| UserPoolConfigAndIdentityPoolConfig
|
|
21
|
+
| UserPoolConfig {
|
|
16
22
|
const validConfig =
|
|
17
23
|
!!authConfig?.userPoolId && !!authConfig?.userPoolWebClientId;
|
|
18
24
|
return asserts(validConfig, {
|
|
@@ -22,6 +28,26 @@ export function assertTokenProviderConfig(
|
|
|
22
28
|
});
|
|
23
29
|
}
|
|
24
30
|
|
|
31
|
+
export function assertOAuthConfig(
|
|
32
|
+
authConfig?: AuthConfig
|
|
33
|
+
): asserts authConfig is
|
|
34
|
+
| UserPoolConfigAndIdentityPoolConfigWithOAuth
|
|
35
|
+
| UserPoolConfigWithOAuth {
|
|
36
|
+
assertTokenProviderConfig(authConfig);
|
|
37
|
+
const validOAuthConfig =
|
|
38
|
+
!!authConfig.oauth?.domain &&
|
|
39
|
+
!!authConfig.oauth?.redirectSignOut &&
|
|
40
|
+
!!authConfig.oauth?.redirectSignIn &&
|
|
41
|
+
!!authConfig.oauth?.responseType;
|
|
42
|
+
|
|
43
|
+
return asserts(validOAuthConfig, {
|
|
44
|
+
name: 'OAuthNotConfigureException',
|
|
45
|
+
message: 'oauth param not configured',
|
|
46
|
+
recoverySuggestion:
|
|
47
|
+
'Make sure to call Amplify.configure with oauth parameter in your app',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
25
51
|
export function assertIdentityPooIdConfig(
|
|
26
52
|
authConfig: AuthConfig
|
|
27
53
|
): asserts authConfig is IdentityPoolConfig {
|
|
@@ -6,6 +6,7 @@ export type StorageAccessLevel = 'guest' | 'protected' | 'private';
|
|
|
6
6
|
export interface StorageConfig {
|
|
7
7
|
bucket?: string;
|
|
8
8
|
region?: string;
|
|
9
|
+
dangerouslyConnectToHttpEndpointForTesting?: string;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
type StoragePrefixResolver = (params: {
|
|
@@ -13,9 +14,11 @@ type StoragePrefixResolver = (params: {
|
|
|
13
14
|
targetIdentityId?: string;
|
|
14
15
|
}) => Promise<string>;
|
|
15
16
|
|
|
16
|
-
// TODO[AllanZhengYP]: support isObjectLockEnabled config to S3 plugin config
|
|
17
17
|
// TODO[AllanZhengYP]: need to finalize the decision whether to move defaultAccessLevel to StorageConfig
|
|
18
18
|
export interface LibraryStorageOptions {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
AWSS3: {
|
|
20
|
+
prefixResolver?: StoragePrefixResolver;
|
|
21
|
+
defaultAccessLevel?: StorageAccessLevel;
|
|
22
|
+
isObjectLockEnabled?: boolean;
|
|
23
|
+
};
|
|
21
24
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { fetchAuthSession as fetchAuthSessionInternal } from './internal/fetchAuthSession';
|
|
5
|
+
import { Amplify } from '../Amplify';
|
|
6
|
+
import { AuthSession, FetchAuthSessionOptions } from '../Auth/types';
|
|
7
|
+
|
|
8
|
+
export const fetchAuthSession = (
|
|
9
|
+
options?: FetchAuthSessionOptions
|
|
10
|
+
): Promise<AuthSession> => {
|
|
11
|
+
return fetchAuthSessionInternal(Amplify, options);
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AmplifyClass } from '../../Amplify';
|
|
5
|
+
import { AuthSession, FetchAuthSessionOptions } from '../../Auth/types';
|
|
6
|
+
|
|
7
|
+
export const fetchAuthSession = (
|
|
8
|
+
amplify: AmplifyClass,
|
|
9
|
+
options?: FetchAuthSessionOptions
|
|
10
|
+
): Promise<AuthSession> => {
|
|
11
|
+
return amplify.Auth.fetchAuthSession(options);
|
|
12
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AmplifyServer, getAmplifyServerContext } from '../../../adapterCore';
|
|
5
|
+
import { AuthSession, FetchAuthSessionOptions } from '../../Auth/types';
|
|
6
|
+
import { fetchAuthSession as fetchAuthSessionInternal } from '../internal/fetchAuthSession';
|
|
7
|
+
|
|
8
|
+
export const fetchAuthSession = (
|
|
9
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
10
|
+
options?: FetchAuthSessionOptions
|
|
11
|
+
): Promise<AuthSession> => {
|
|
12
|
+
return fetchAuthSessionInternal(
|
|
13
|
+
getAmplifyServerContext(contextSpec).amplify,
|
|
14
|
+
options
|
|
15
|
+
);
|
|
16
|
+
};
|
package/src/singleton/index.ts
CHANGED
|
@@ -1,131 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { AuthClass } from './Auth';
|
|
4
|
-
import { Hub } from '../Hub';
|
|
5
|
-
import { LibraryOptions, ResourcesConfig } from './types';
|
|
6
|
-
import { AmplifyError } from '../Errors';
|
|
7
|
-
import { FetchAuthSessionOptions } from './Auth/types';
|
|
8
3
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class AmplifyClass {
|
|
12
|
-
resourcesConfig: ResourcesConfig;
|
|
13
|
-
libraryOptions: LibraryOptions;
|
|
14
|
-
/**
|
|
15
|
-
* Cross-category Auth utilities.
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
public readonly Auth: AuthClass;
|
|
20
|
-
constructor() {
|
|
21
|
-
this.resourcesConfig = {};
|
|
22
|
-
this.Auth = new AuthClass();
|
|
23
|
-
|
|
24
|
-
// TODO(v6): add default providers for getting started
|
|
25
|
-
this.libraryOptions = {};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Configures Amplify for use with your back-end resources.
|
|
30
|
-
*
|
|
31
|
-
* @remarks
|
|
32
|
-
* `configure` can be used to specify additional library options where available for supported categories.
|
|
33
|
-
*
|
|
34
|
-
* @param resourceConfig - Back-end resource configuration. Typically provided via the `aws-exports.js` file.
|
|
35
|
-
* @param libraryOptions - Additional options for customizing the behavior of the library.
|
|
36
|
-
*/
|
|
37
|
-
configure(
|
|
38
|
-
resourcesConfig: ResourcesConfig,
|
|
39
|
-
libraryOptions: LibraryOptions = {}
|
|
40
|
-
): void {
|
|
41
|
-
this.resourcesConfig = mergeResourceConfig(
|
|
42
|
-
this.resourcesConfig,
|
|
43
|
-
resourcesConfig
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
this.libraryOptions = mergeLibraryOptions(
|
|
47
|
-
this.libraryOptions,
|
|
48
|
-
libraryOptions
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
this.Auth.configure(this.resourcesConfig.Auth!, this.libraryOptions.Auth);
|
|
52
|
-
|
|
53
|
-
Hub.dispatch(
|
|
54
|
-
'core',
|
|
55
|
-
{
|
|
56
|
-
event: 'configure',
|
|
57
|
-
data: resourcesConfig,
|
|
58
|
-
},
|
|
59
|
-
'Configure'
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Provides access to the current back-end resource configuration for the Library.
|
|
65
|
-
*
|
|
66
|
-
* @returns Returns the current back-end resource configuration.
|
|
67
|
-
*/
|
|
68
|
-
getConfig(): ResourcesConfig {
|
|
69
|
-
return JSON.parse(JSON.stringify(this.resourcesConfig));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* The `Amplify` utility is used to configure the library.
|
|
75
|
-
*
|
|
76
|
-
* @remarks
|
|
77
|
-
* `Amplify` is responsible for orchestrating cross-category communication within the library.
|
|
78
|
-
*/
|
|
79
|
-
export const AmplifyV6 = new AmplifyClass();
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Returns current session tokens and credentials
|
|
83
|
-
*
|
|
84
|
-
* @param options{FetchAuthSessionOptions} - Options for fetching session.
|
|
85
|
-
*
|
|
86
|
-
* @returns Returns a promise that will resolve with fresh authentication tokens.
|
|
87
|
-
*/
|
|
88
|
-
export const fetchAuthSession = (options: FetchAuthSessionOptions) => {
|
|
89
|
-
return AmplifyV6.Auth.fetchAuthSession(options);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// TODO(v6): validate until which level this will nested, during Amplify.configure API review.
|
|
93
|
-
function mergeResourceConfig(
|
|
94
|
-
existingConfig: ResourcesConfig,
|
|
95
|
-
newConfig: ResourcesConfig
|
|
96
|
-
): ResourcesConfig {
|
|
97
|
-
const resultConfig: Record<string, any> = {};
|
|
98
|
-
|
|
99
|
-
for (const category of Object.keys(existingConfig)) {
|
|
100
|
-
resultConfig[category] = existingConfig[category as keyof ResourcesConfig];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
for (const category of Object.keys(newConfig)) {
|
|
104
|
-
resultConfig[category] = {
|
|
105
|
-
...resultConfig[category],
|
|
106
|
-
...newConfig[category as keyof ResourcesConfig],
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return resultConfig;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function mergeLibraryOptions(
|
|
114
|
-
existingConfig: LibraryOptions,
|
|
115
|
-
newConfig: LibraryOptions
|
|
116
|
-
): LibraryOptions {
|
|
117
|
-
const resultConfig: Record<string, any> = {};
|
|
118
|
-
|
|
119
|
-
for (const category of Object.keys(existingConfig)) {
|
|
120
|
-
resultConfig[category] = existingConfig[category as keyof LibraryOptions];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
for (const category of Object.keys(newConfig)) {
|
|
124
|
-
resultConfig[category] = {
|
|
125
|
-
...resultConfig[category],
|
|
126
|
-
...newConfig[category as keyof LibraryOptions],
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return resultConfig;
|
|
131
|
-
}
|
|
4
|
+
export { AmplifyClass, Amplify } from './Amplify';
|
|
5
|
+
export { fetchAuthSession } from './apis/fetchAuthSession';
|
package/src/singleton/types.ts
CHANGED
|
@@ -1,6 +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
|
+
import { AnalyticsConfig } from './Analytics/types';
|
|
4
5
|
import {
|
|
5
6
|
AuthConfig,
|
|
6
7
|
LibraryAuthOptions,
|
|
@@ -14,14 +15,12 @@ import {
|
|
|
14
15
|
StorageAccessLevel,
|
|
15
16
|
StorageConfig,
|
|
16
17
|
} from './Storage/types';
|
|
17
|
-
import {
|
|
18
|
-
CacheConfig
|
|
19
|
-
} from '../Cache/types';
|
|
18
|
+
import { CacheConfig } from '../Cache/types';
|
|
20
19
|
import { I18nOptions } from '../I18n/types';
|
|
21
20
|
|
|
22
21
|
export type ResourcesConfig = {
|
|
23
22
|
API?: {};
|
|
24
|
-
Analytics?:
|
|
23
|
+
Analytics?: AnalyticsConfig;
|
|
25
24
|
Auth?: AuthConfig;
|
|
26
25
|
Cache?: CacheConfig;
|
|
27
26
|
DataStore?: {};
|
|
@@ -30,6 +29,7 @@ export type ResourcesConfig = {
|
|
|
30
29
|
Notifications?: {};
|
|
31
30
|
Predictions?: {};
|
|
32
31
|
Storage?: StorageConfig;
|
|
32
|
+
ssr?: boolean;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export type LibraryOptions = {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export interface AmplifyConfig {
|
|
5
|
+
Analytics?: object;
|
|
6
|
+
Auth?: object;
|
|
7
|
+
API?: object;
|
|
8
|
+
Logging?: object;
|
|
9
|
+
Storage?: object;
|
|
10
|
+
Cache?: object;
|
|
11
|
+
Geo?: object;
|
|
12
|
+
Notifications?: {
|
|
13
|
+
InAppMessaging?: object;
|
|
14
|
+
};
|
|
15
|
+
ssr?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type UserProfile = {
|
|
19
|
+
attributes?: Record<string, string[]>;
|
|
20
|
+
demographic?: {
|
|
21
|
+
appVersion?: string;
|
|
22
|
+
locale?: string;
|
|
23
|
+
make?: string;
|
|
24
|
+
model?: string;
|
|
25
|
+
modelVersion?: string;
|
|
26
|
+
platform?: string;
|
|
27
|
+
platformVersion?: string;
|
|
28
|
+
timezone?: string;
|
|
29
|
+
};
|
|
30
|
+
location?: {
|
|
31
|
+
city?: string;
|
|
32
|
+
country?: string;
|
|
33
|
+
latitude?: number;
|
|
34
|
+
longitude?: number;
|
|
35
|
+
postalCode?: string;
|
|
36
|
+
region?: string;
|
|
37
|
+
};
|
|
38
|
+
metrics?: Record<string, number>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export interface ICredentials {
|
|
42
|
+
accessKeyId: string;
|
|
43
|
+
sessionToken: string;
|
|
44
|
+
secretAccessKey: string;
|
|
45
|
+
identityId: string;
|
|
46
|
+
authenticated: boolean;
|
|
47
|
+
// Long term creds do not provide an expiration date
|
|
48
|
+
expiration?: Date;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export type DelayFunction = (
|
|
55
|
+
attempt: number,
|
|
56
|
+
args?: any[],
|
|
57
|
+
error?: unknown
|
|
58
|
+
) => number | false;
|
|
@@ -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 ErrorParams = {
|
|
5
|
+
message: string;
|
|
6
|
+
name: string;
|
|
7
|
+
recoverySuggestion?: string;
|
|
8
|
+
underlyingError?: Error | unknown;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type AmplifyErrorMap<ErrorCode extends string> = {
|
|
12
|
+
[name in ErrorCode]: {
|
|
13
|
+
message: string;
|
|
14
|
+
recoverySuggestion?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ServiceError = {
|
|
19
|
+
name: string;
|
|
20
|
+
message: string;
|
|
21
|
+
};
|