@aws-amplify/core 6.0.1-console-preview.f63250a.0 → 6.0.1-console-preview.5dc0b68.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,116 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
14
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
+
function step(op) {
|
|
17
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
20
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
+
switch (op[0]) {
|
|
22
|
+
case 0: case 1: t = op; break;
|
|
23
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
+
default:
|
|
27
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
+
if (t[2]) _.ops.pop();
|
|
32
|
+
_.trys.pop(); continue;
|
|
33
|
+
}
|
|
34
|
+
op = body.call(thisArg, _);
|
|
35
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
import { v4 as uuid } from 'uuid';
|
|
40
|
+
import { getEndpointId } from '../utils';
|
|
41
|
+
import { BUFFER_SIZE, FLUSH_INTERVAL, FLUSH_SIZE, RESEND_LIMIT, } from '../utils/constants';
|
|
42
|
+
import { updateEndpoint } from './updateEndpoint';
|
|
43
|
+
import { getEventBuffer } from '../utils/getEventBuffer';
|
|
44
|
+
import { AmplifyError } from '../../../libraryUtils';
|
|
45
|
+
// TODO(v6) Refactor when we add support for session tracking & `autoTrack`
|
|
46
|
+
var session;
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export var record = function (_a) {
|
|
51
|
+
var appId = _a.appId, category = _a.category, credentials = _a.credentials, event = _a.event, identityId = _a.identityId, region = _a.region, userAgentValue = _a.userAgentValue;
|
|
52
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
+
var timestampISOString, eventId, endpointId, buffer, sessionId;
|
|
54
|
+
return __generator(this, function (_b) {
|
|
55
|
+
switch (_b.label) {
|
|
56
|
+
case 0:
|
|
57
|
+
timestampISOString = new Date().toISOString();
|
|
58
|
+
eventId = uuid();
|
|
59
|
+
return [4 /*yield*/, getEndpointId(appId, category)];
|
|
60
|
+
case 1:
|
|
61
|
+
endpointId = _b.sent();
|
|
62
|
+
buffer = getEventBuffer({
|
|
63
|
+
appId: appId,
|
|
64
|
+
bufferSize: BUFFER_SIZE,
|
|
65
|
+
credentials: credentials,
|
|
66
|
+
flushInterval: FLUSH_INTERVAL,
|
|
67
|
+
flushSize: FLUSH_SIZE,
|
|
68
|
+
identityId: identityId,
|
|
69
|
+
region: region,
|
|
70
|
+
resendLimit: RESEND_LIMIT,
|
|
71
|
+
userAgentValue: userAgentValue
|
|
72
|
+
});
|
|
73
|
+
if (!!endpointId) return [3 /*break*/, 4];
|
|
74
|
+
return [4 /*yield*/, updateEndpoint({
|
|
75
|
+
appId: appId,
|
|
76
|
+
category: category,
|
|
77
|
+
credentials: credentials,
|
|
78
|
+
identityId: identityId,
|
|
79
|
+
region: region,
|
|
80
|
+
userAgentValue: userAgentValue,
|
|
81
|
+
})];
|
|
82
|
+
case 2:
|
|
83
|
+
_b.sent();
|
|
84
|
+
return [4 /*yield*/, getEndpointId(appId, category)];
|
|
85
|
+
case 3:
|
|
86
|
+
endpointId = _b.sent();
|
|
87
|
+
_b.label = 4;
|
|
88
|
+
case 4:
|
|
89
|
+
if (!endpointId) {
|
|
90
|
+
throw new AmplifyError({
|
|
91
|
+
name: 'ENDPOINT_NOT_CREATED',
|
|
92
|
+
message: 'Endpoint was not created.'
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// Generate session if required
|
|
96
|
+
if (!session) {
|
|
97
|
+
sessionId = uuid();
|
|
98
|
+
session = {
|
|
99
|
+
Id: sessionId,
|
|
100
|
+
StartTimestamp: timestampISOString,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// Push event to buffer
|
|
104
|
+
buffer.push({
|
|
105
|
+
eventId: eventId,
|
|
106
|
+
endpointId: endpointId,
|
|
107
|
+
event: event,
|
|
108
|
+
session: session,
|
|
109
|
+
timestamp: timestampISOString,
|
|
110
|
+
resendLimit: RESEND_LIMIT
|
|
111
|
+
});
|
|
112
|
+
return [2 /*return*/];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PinpointUpdateEndpointParameters } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare const updateEndpoint: ({ address, appId, category, channelType, credentials, identityId, optOut, region, userId, userProfile, userAgentValue, }: PinpointUpdateEndpointParameters) => Promise<void>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
var __assign = (this && this.__assign) || function () {
|
|
4
|
+
__assign = Object.assign || function(t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
return __assign.apply(this, arguments);
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
24
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
25
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
26
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
27
|
+
function step(op) {
|
|
28
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
29
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
30
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
31
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
32
|
+
switch (op[0]) {
|
|
33
|
+
case 0: case 1: t = op; break;
|
|
34
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
35
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
36
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
37
|
+
default:
|
|
38
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
39
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
40
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
41
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
42
|
+
if (t[2]) _.ops.pop();
|
|
43
|
+
_.trys.pop(); continue;
|
|
44
|
+
}
|
|
45
|
+
op = body.call(thisArg, _);
|
|
46
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
47
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
51
|
+
import { ClientDevice } from '../../../ClientDevice';
|
|
52
|
+
import { updateEndpoint as clientUpdateEndpoint, } from '../../../AwsClients/Pinpoint';
|
|
53
|
+
import { cacheEndpointId, getEndpointId } from '../utils';
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export var updateEndpoint = function (_a) {
|
|
58
|
+
var address = _a.address, appId = _a.appId, category = _a.category, channelType = _a.channelType, credentials = _a.credentials, identityId = _a.identityId, optOut = _a.optOut, region = _a.region, userId = _a.userId, userProfile = _a.userProfile, userAgentValue = _a.userAgentValue;
|
|
59
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
+
var endpointId, createdEndpointId, _b, attributes, demographic, location, metrics, clientInfo, mergedDemographic, input;
|
|
61
|
+
return __generator(this, function (_c) {
|
|
62
|
+
switch (_c.label) {
|
|
63
|
+
case 0: return [4 /*yield*/, getEndpointId(appId, category)];
|
|
64
|
+
case 1:
|
|
65
|
+
endpointId = _c.sent();
|
|
66
|
+
createdEndpointId = !endpointId ? uuidv4() : undefined;
|
|
67
|
+
_b = userProfile !== null && userProfile !== void 0 ? userProfile : {}, attributes = _b.attributes, demographic = _b.demographic, location = _b.location, metrics = _b.metrics;
|
|
68
|
+
clientInfo = ClientDevice.clientInfo();
|
|
69
|
+
mergedDemographic = __assign({ appVersion: clientInfo.appVersion, make: clientInfo.make, model: clientInfo.model, modelVersion: clientInfo.version, platform: clientInfo.platform }, demographic);
|
|
70
|
+
input = {
|
|
71
|
+
ApplicationId: appId,
|
|
72
|
+
EndpointId: endpointId !== null && endpointId !== void 0 ? endpointId : createdEndpointId,
|
|
73
|
+
EndpointRequest: {
|
|
74
|
+
RequestId: uuidv4(),
|
|
75
|
+
EffectiveDate: new Date().toISOString(),
|
|
76
|
+
ChannelType: channelType,
|
|
77
|
+
Address: address,
|
|
78
|
+
Attributes: attributes,
|
|
79
|
+
Demographic: {
|
|
80
|
+
AppVersion: mergedDemographic.appVersion,
|
|
81
|
+
Locale: mergedDemographic.locale,
|
|
82
|
+
Make: mergedDemographic.make,
|
|
83
|
+
Model: mergedDemographic.model,
|
|
84
|
+
ModelVersion: mergedDemographic.modelVersion,
|
|
85
|
+
Platform: mergedDemographic.platform,
|
|
86
|
+
PlatformVersion: mergedDemographic.platformVersion,
|
|
87
|
+
Timezone: mergedDemographic.timezone,
|
|
88
|
+
},
|
|
89
|
+
Location: {
|
|
90
|
+
City: location === null || location === void 0 ? void 0 : location.city,
|
|
91
|
+
Country: location === null || location === void 0 ? void 0 : location.country,
|
|
92
|
+
Latitude: location === null || location === void 0 ? void 0 : location.latitude,
|
|
93
|
+
Longitude: location === null || location === void 0 ? void 0 : location.longitude,
|
|
94
|
+
PostalCode: location === null || location === void 0 ? void 0 : location.postalCode,
|
|
95
|
+
Region: location === null || location === void 0 ? void 0 : location.region,
|
|
96
|
+
},
|
|
97
|
+
Metrics: metrics,
|
|
98
|
+
OptOut: optOut,
|
|
99
|
+
User: {
|
|
100
|
+
UserId: userId !== null && userId !== void 0 ? userId : identityId,
|
|
101
|
+
UserAttributes: attributes,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
return [4 /*yield*/, clientUpdateEndpoint({ credentials: credentials, region: region, userAgentValue: userAgentValue }, input)];
|
|
106
|
+
case 2:
|
|
107
|
+
_c.sent();
|
|
108
|
+
// if we had to create an endpoint id, we need to now cache it
|
|
109
|
+
if (!!createdEndpointId) {
|
|
110
|
+
cacheEndpointId(appId, category, createdEndpointId);
|
|
111
|
+
}
|
|
112
|
+
return [2 /*return*/];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AuthSession } from '../../../singleton/Auth/types';
|
|
2
|
+
import { PinpointAnalyticsEvent, PinpointSession } from './pinpoint';
|
|
3
|
+
export type EventBufferConfig = {
|
|
4
|
+
appId: string;
|
|
5
|
+
bufferSize: number;
|
|
6
|
+
credentials: AuthSession['credentials'];
|
|
7
|
+
identityId: AuthSession['identityId'];
|
|
8
|
+
flushInterval: number;
|
|
9
|
+
flushSize: number;
|
|
10
|
+
region: string;
|
|
11
|
+
resendLimit: number;
|
|
12
|
+
userAgentValue?: string;
|
|
13
|
+
};
|
|
14
|
+
export type BufferedEvent = {
|
|
15
|
+
endpointId: string;
|
|
16
|
+
eventId: string;
|
|
17
|
+
event: PinpointAnalyticsEvent;
|
|
18
|
+
session: PinpointSession;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
resendLimit: number;
|
|
21
|
+
};
|
|
22
|
+
export type BufferedEventMap = {
|
|
23
|
+
[key: string]: BufferedEvent;
|
|
24
|
+
};
|
|
25
|
+
export type EventBuffer = Array<BufferedEventMap>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pinpoint';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AuthSession } from '../../../singleton/Auth/types';
|
|
2
|
+
import { UserProfile } from '../../../types';
|
|
3
|
+
export type SupportedCategory = 'Analytics' | 'InAppMessaging' | 'PushNotification';
|
|
4
|
+
export type SupportedChannelType = 'APNS' | 'APNS_SANDBOX' | 'GCM' | 'IN_APP';
|
|
5
|
+
export type PinpointProviderConfig = {
|
|
6
|
+
AWSPinpoint: {
|
|
7
|
+
appId: string;
|
|
8
|
+
region: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type PinpointServiceOptions = {
|
|
12
|
+
address?: string;
|
|
13
|
+
optOut?: 'ALL' | 'NONE';
|
|
14
|
+
};
|
|
15
|
+
export type PinpointSession = {
|
|
16
|
+
Id: string;
|
|
17
|
+
StartTimestamp: string;
|
|
18
|
+
};
|
|
19
|
+
export type PinpointAnalyticsEvent = {
|
|
20
|
+
name: string;
|
|
21
|
+
attributes?: Record<string, string>;
|
|
22
|
+
metrics?: Record<string, number>;
|
|
23
|
+
};
|
|
24
|
+
type PinpointCommonParameters = {
|
|
25
|
+
appId: string;
|
|
26
|
+
category: SupportedCategory;
|
|
27
|
+
credentials: AuthSession['credentials'];
|
|
28
|
+
identityId?: AuthSession['identityId'];
|
|
29
|
+
region: string;
|
|
30
|
+
userAgentValue?: string;
|
|
31
|
+
};
|
|
32
|
+
export type PinpointUpdateEndpointParameters = PinpointCommonParameters & PinpointServiceOptions & {
|
|
33
|
+
channelType?: SupportedChannelType;
|
|
34
|
+
userId?: string;
|
|
35
|
+
userProfile?: UserProfile;
|
|
36
|
+
};
|
|
37
|
+
export type PinpointRecordParameters = PinpointCommonParameters & {
|
|
38
|
+
event: PinpointAnalyticsEvent;
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EventBufferConfig, BufferedEvent } from '../types/buffer';
|
|
2
|
+
import { AuthSession } from '../../../singleton/Auth/types';
|
|
3
|
+
export declare class PinpointEventBuffer {
|
|
4
|
+
private _config;
|
|
5
|
+
private _interval;
|
|
6
|
+
private _buffer;
|
|
7
|
+
private _pause;
|
|
8
|
+
private _flush;
|
|
9
|
+
constructor(config: EventBufferConfig);
|
|
10
|
+
push(event: BufferedEvent): void;
|
|
11
|
+
pause(): void;
|
|
12
|
+
resume(): void;
|
|
13
|
+
flush(): void;
|
|
14
|
+
identityHasChanged(identityId: AuthSession['identityId']): boolean;
|
|
15
|
+
private _startLoop;
|
|
16
|
+
private _sendBatch;
|
|
17
|
+
private _putEvents;
|
|
18
|
+
private _generateBatchEventParams;
|
|
19
|
+
private _handlePutEventsFailure;
|
|
20
|
+
private _processPutEventsSuccessResponse;
|
|
21
|
+
private _retry;
|
|
22
|
+
private _bufferToMap;
|
|
23
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
var __assign = (this && this.__assign) || function () {
|
|
4
|
+
__assign = Object.assign || function(t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
return __assign.apply(this, arguments);
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
24
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
25
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
26
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
27
|
+
function step(op) {
|
|
28
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
29
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
30
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
31
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
32
|
+
switch (op[0]) {
|
|
33
|
+
case 0: case 1: t = op; break;
|
|
34
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
35
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
36
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
37
|
+
default:
|
|
38
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
39
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
40
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
41
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
42
|
+
if (t[2]) _.ops.pop();
|
|
43
|
+
_.trys.pop(); continue;
|
|
44
|
+
}
|
|
45
|
+
op = body.call(thisArg, _);
|
|
46
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
47
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
51
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
52
|
+
if (!m) return o;
|
|
53
|
+
var i = m.call(o), r, ar = [], e;
|
|
54
|
+
try {
|
|
55
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
56
|
+
}
|
|
57
|
+
catch (error) { e = { error: error }; }
|
|
58
|
+
finally {
|
|
59
|
+
try {
|
|
60
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
61
|
+
}
|
|
62
|
+
finally { if (e) throw e.error; }
|
|
63
|
+
}
|
|
64
|
+
return ar;
|
|
65
|
+
};
|
|
66
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
67
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
68
|
+
if (ar || !(i in from)) {
|
|
69
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
70
|
+
ar[i] = from[i];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
74
|
+
};
|
|
75
|
+
import { ConsoleLogger as Logger } from '../../../Logger';
|
|
76
|
+
import { putEvents, } from '../../../AwsClients/Pinpoint';
|
|
77
|
+
import { isAppInForeground } from '../../../RNComponents/isAppInForeground';
|
|
78
|
+
var logger = new Logger('PinpointEventBuffer');
|
|
79
|
+
var RETRYABLE_CODES = [429, 500];
|
|
80
|
+
var ACCEPTED_CODES = [202];
|
|
81
|
+
var PinpointEventBuffer = /** @class */ (function () {
|
|
82
|
+
function PinpointEventBuffer(config) {
|
|
83
|
+
this._interval = undefined;
|
|
84
|
+
this._pause = false;
|
|
85
|
+
this._flush = false;
|
|
86
|
+
this._buffer = [];
|
|
87
|
+
this._config = config;
|
|
88
|
+
this._sendBatch = this._sendBatch.bind(this);
|
|
89
|
+
this._startLoop();
|
|
90
|
+
}
|
|
91
|
+
PinpointEventBuffer.prototype.push = function (event) {
|
|
92
|
+
var _a;
|
|
93
|
+
if (this._buffer.length >= this._config.bufferSize) {
|
|
94
|
+
logger.debug('Exceeded Pinpoint event buffer limits, event dropped.', { eventId: event.eventId });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this._buffer.push((_a = {}, _a[event.eventId] = event, _a));
|
|
98
|
+
};
|
|
99
|
+
PinpointEventBuffer.prototype.pause = function () {
|
|
100
|
+
this._pause = true;
|
|
101
|
+
};
|
|
102
|
+
PinpointEventBuffer.prototype.resume = function () {
|
|
103
|
+
this._pause = false;
|
|
104
|
+
};
|
|
105
|
+
PinpointEventBuffer.prototype.flush = function () {
|
|
106
|
+
this._flush = true;
|
|
107
|
+
};
|
|
108
|
+
PinpointEventBuffer.prototype.identityHasChanged = function (identityId) {
|
|
109
|
+
return this._config.identityId !== identityId;
|
|
110
|
+
};
|
|
111
|
+
PinpointEventBuffer.prototype._startLoop = function () {
|
|
112
|
+
if (this._interval) {
|
|
113
|
+
clearInterval(this._interval);
|
|
114
|
+
}
|
|
115
|
+
var flushInterval = this._config.flushInterval;
|
|
116
|
+
this._interval = setInterval(this._sendBatch, flushInterval);
|
|
117
|
+
};
|
|
118
|
+
PinpointEventBuffer.prototype._sendBatch = function () {
|
|
119
|
+
var bufferLength = this._buffer.length;
|
|
120
|
+
if (this._flush && !bufferLength && this._interval) {
|
|
121
|
+
clearInterval(this._interval);
|
|
122
|
+
}
|
|
123
|
+
if (this._pause || !bufferLength || !isAppInForeground()) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
var flushSize = this._config.flushSize;
|
|
127
|
+
var batchSize = Math.min(flushSize, bufferLength);
|
|
128
|
+
var bufferSubset = this._buffer.splice(0, batchSize);
|
|
129
|
+
this._putEvents(bufferSubset);
|
|
130
|
+
};
|
|
131
|
+
PinpointEventBuffer.prototype._putEvents = function (buffer) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
+
var eventMap, batchEventParams, _a, credentials, region, userAgentValue, data, err_1;
|
|
134
|
+
return __generator(this, function (_b) {
|
|
135
|
+
switch (_b.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
eventMap = this._bufferToMap(buffer);
|
|
138
|
+
batchEventParams = this._generateBatchEventParams(eventMap);
|
|
139
|
+
_b.label = 1;
|
|
140
|
+
case 1:
|
|
141
|
+
_b.trys.push([1, 3, , 4]);
|
|
142
|
+
_a = this._config, credentials = _a.credentials, region = _a.region, userAgentValue = _a.userAgentValue;
|
|
143
|
+
return [4 /*yield*/, putEvents({
|
|
144
|
+
credentials: credentials,
|
|
145
|
+
region: region,
|
|
146
|
+
userAgentValue: userAgentValue,
|
|
147
|
+
}, batchEventParams)];
|
|
148
|
+
case 2:
|
|
149
|
+
data = _b.sent();
|
|
150
|
+
this._processPutEventsSuccessResponse(data, eventMap);
|
|
151
|
+
return [3 /*break*/, 4];
|
|
152
|
+
case 3:
|
|
153
|
+
err_1 = _b.sent();
|
|
154
|
+
return [2 /*return*/, this._handlePutEventsFailure(err_1, eventMap)];
|
|
155
|
+
case 4: return [2 /*return*/];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
PinpointEventBuffer.prototype._generateBatchEventParams = function (eventMap) {
|
|
161
|
+
var batchItem = {};
|
|
162
|
+
Object.values(eventMap).forEach(function (item) {
|
|
163
|
+
var _a;
|
|
164
|
+
var _b, _c;
|
|
165
|
+
var event = item.event, timestamp = item.timestamp, endpointId = item.endpointId, eventId = item.eventId, session = item.session;
|
|
166
|
+
var name = event.name, attributes = event.attributes, metrics = event.metrics;
|
|
167
|
+
batchItem[endpointId] = {
|
|
168
|
+
Endpoint: __assign({}, (_b = batchItem[endpointId]) === null || _b === void 0 ? void 0 : _b.Endpoint),
|
|
169
|
+
Events: __assign(__assign({}, (_c = batchItem[endpointId]) === null || _c === void 0 ? void 0 : _c.Events), (_a = {}, _a[eventId] = {
|
|
170
|
+
EventType: name,
|
|
171
|
+
Timestamp: new Date(timestamp).toISOString(),
|
|
172
|
+
Attributes: attributes,
|
|
173
|
+
Metrics: metrics,
|
|
174
|
+
Session: session,
|
|
175
|
+
}, _a)),
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
ApplicationId: this._config.appId,
|
|
180
|
+
EventsRequest: {
|
|
181
|
+
BatchItem: batchItem,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
PinpointEventBuffer.prototype._handlePutEventsFailure = function (err, eventMap) {
|
|
186
|
+
logger.debug('putEvents call to Pinpoint failed.', err);
|
|
187
|
+
var statusCode = err.$metadata && err.$metadata.httpStatusCode;
|
|
188
|
+
if (RETRYABLE_CODES.includes(statusCode)) {
|
|
189
|
+
var retryableEvents = Object.values(eventMap);
|
|
190
|
+
this._retry(retryableEvents);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
PinpointEventBuffer.prototype._processPutEventsSuccessResponse = function (data, eventMap) {
|
|
195
|
+
var _a;
|
|
196
|
+
var _b = ((_a = data.EventsResponse) !== null && _a !== void 0 ? _a : {}).Results, Results = _b === void 0 ? {} : _b;
|
|
197
|
+
var retryableEvents = [];
|
|
198
|
+
Object.entries(Results).forEach(function (_a) {
|
|
199
|
+
var _b;
|
|
200
|
+
var _c = __read(_a, 2), endpointId = _c[0], endpointValues = _c[1];
|
|
201
|
+
var responses = (_b = endpointValues.EventsItemResponse) !== null && _b !== void 0 ? _b : {};
|
|
202
|
+
Object.entries(responses).forEach(function (_a) {
|
|
203
|
+
var _b, _c;
|
|
204
|
+
var _d = __read(_a, 2), eventId = _d[0], eventValues = _d[1];
|
|
205
|
+
var eventObject = eventMap[eventId];
|
|
206
|
+
if (!eventObject) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
var _e = eventValues !== null && eventValues !== void 0 ? eventValues : {}, StatusCode = _e.StatusCode, Message = _e.Message;
|
|
210
|
+
// manually crafting handlers response to keep API consistant
|
|
211
|
+
var response = {
|
|
212
|
+
EventsResponse: {
|
|
213
|
+
Results: (_b = {},
|
|
214
|
+
_b[endpointId] = {
|
|
215
|
+
EventsItemResponse: (_c = {},
|
|
216
|
+
_c[eventId] = { StatusCode: StatusCode, Message: Message },
|
|
217
|
+
_c),
|
|
218
|
+
},
|
|
219
|
+
_b),
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
if (StatusCode && ACCEPTED_CODES.includes(StatusCode)) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (StatusCode && RETRYABLE_CODES.includes(StatusCode)) {
|
|
226
|
+
retryableEvents.push(eventObject);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
var name = eventObject.event.name;
|
|
230
|
+
logger.warn('Pinpoint event failed to send.', {
|
|
231
|
+
eventId: eventId,
|
|
232
|
+
name: name,
|
|
233
|
+
message: Message
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
if (retryableEvents.length) {
|
|
238
|
+
this._retry(retryableEvents);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
PinpointEventBuffer.prototype._retry = function (retryableEvents) {
|
|
242
|
+
var _a;
|
|
243
|
+
// retryable events that haven't reached the resendLimit
|
|
244
|
+
var eligibleEvents = [];
|
|
245
|
+
retryableEvents.forEach(function (bufferedEvent) {
|
|
246
|
+
var _a;
|
|
247
|
+
var eventId = bufferedEvent.eventId;
|
|
248
|
+
var name = bufferedEvent.event.name;
|
|
249
|
+
if (bufferedEvent.resendLimit-- > 0) {
|
|
250
|
+
logger.debug('Resending event.', {
|
|
251
|
+
eventId: eventId,
|
|
252
|
+
name: name,
|
|
253
|
+
remainingAttempts: bufferedEvent.resendLimit
|
|
254
|
+
});
|
|
255
|
+
eligibleEvents.push((_a = {}, _a[eventId] = bufferedEvent, _a));
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
logger.debug('No retry attempts remaining for event.', {
|
|
259
|
+
eventId: eventId,
|
|
260
|
+
name: name
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
// add the events to the front of the buffer
|
|
264
|
+
(_a = this._buffer).unshift.apply(_a, __spreadArray([], __read(eligibleEvents), false));
|
|
265
|
+
};
|
|
266
|
+
PinpointEventBuffer.prototype._bufferToMap = function (buffer) {
|
|
267
|
+
return buffer.reduce(function (acc, curVal) {
|
|
268
|
+
var _a = __read(Object.entries(curVal), 1), _b = __read(_a[0], 2), key = _b[0], value = _b[1];
|
|
269
|
+
acc[key] = value;
|
|
270
|
+
return acc;
|
|
271
|
+
}, {});
|
|
272
|
+
};
|
|
273
|
+
return PinpointEventBuffer;
|
|
274
|
+
}());
|
|
275
|
+
export { PinpointEventBuffer };
|