@aws-amplify/core 6.0.1-api-v6-models.9351bcf.0 → 6.0.1-api-v6-models.58f2536.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/lib/BackgroundProcessManager/BackgroundManagerNotOpenError.js +4 -21
- package/lib/BackgroundProcessManager/BackgroundProcessManager.js +126 -245
- package/lib/Cache/StorageCache.js +32 -92
- package/lib/Cache/StorageCache.native.js +38 -140
- package/lib/Cache/StorageCacheCommon.js +271 -600
- package/lib/Cache/index.js +1 -1
- package/lib/Cache/utils/CacheList.js +42 -66
- package/lib/Cache/utils/cacheHelpers.js +6 -8
- package/lib/Cache/utils/errorHelpers.js +6 -7
- package/lib/Hub/index.js +34 -74
- package/lib/I18n/I18n.js +24 -39
- package/lib/I18n/errorHelpers.js +4 -5
- package/lib/I18n/index.js +24 -27
- package/lib/I18n/types.js +3 -4
- package/lib/Logger/ConsoleLogger.js +53 -129
- package/lib/Mutex/Mutex.js +15 -19
- package/lib/Platform/customUserAgent.js +13 -26
- package/lib/Platform/detectFramework.js +12 -13
- package/lib/Platform/detection/Angular.js +4 -5
- package/lib/Platform/detection/Expo.js +1 -1
- package/lib/Platform/detection/Next.js +1 -1
- package/lib/Platform/detection/Nuxt.js +1 -1
- package/lib/Platform/detection/React.js +5 -5
- package/lib/Platform/detection/Svelte.js +2 -2
- package/lib/Platform/detection/Vue.js +1 -1
- package/lib/Platform/detection/Web.js +1 -1
- package/lib/Platform/detection/helpers.js +7 -7
- package/lib/Platform/detection/index.js +13 -13
- package/lib/Platform/index.js +26 -55
- package/lib/Platform/types.d.ts +1 -1
- package/lib/Platform/types.js +1 -1
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/Reachability/Reachability.js +20 -48
- package/lib/Reachability/Reachability.native.js +12 -16
- package/lib/ServiceWorker/ServiceWorker.js +80 -136
- package/lib/ServiceWorker/errorHelpers.js +6 -7
- package/lib/Signer/DateUtils.d.ts +9 -0
- package/lib/Signer/DateUtils.js +19 -28
- package/lib/Signer/Signer.d.ts +9 -0
- package/lib/Signer/Signer.js +58 -54
- package/lib/adapterCore/error/AmplifyServerContextError.js +9 -27
- package/lib/adapterCore/serverContext/serverContext.js +8 -8
- package/lib/adapterCore/serverContext/serverContextRegistry.js +6 -6
- package/lib/awsClients/cognitoIdentity/base.js +25 -73
- package/lib/awsClients/cognitoIdentity/getCredentialsForIdentity.js +24 -68
- package/lib/awsClients/cognitoIdentity/getId.js +19 -62
- package/lib/awsClients/pinpoint/base.js +12 -15
- package/lib/awsClients/pinpoint/errorHelpers.js +4 -5
- package/lib/awsClients/pinpoint/getInAppMessages.js +24 -68
- package/lib/awsClients/pinpoint/putEvents.js +26 -70
- package/lib/awsClients/pinpoint/updateEndpoint.js +28 -72
- package/lib/clients/endpoints/getDnsSuffix.js +7 -29
- package/lib/clients/handlers/authenticated.js +5 -5
- package/lib/clients/handlers/fetch.js +41 -98
- package/lib/clients/handlers/unauthenticated.js +4 -4
- package/lib/clients/internal/composeServiceApi.js +17 -67
- package/lib/clients/internal/composeTransferHandler.js +9 -11
- package/lib/clients/middleware/retry/defaultRetryDecider.js +18 -75
- package/lib/clients/middleware/retry/isClockSkewError.js +2 -4
- package/lib/clients/middleware/retry/jitteredBackoff.js +5 -5
- package/lib/clients/middleware/retry/middleware.js +61 -125
- package/lib/clients/middleware/signing/middleware.js +24 -86
- package/lib/clients/middleware/signing/signer/signatureV4/index.js +0 -1
- package/lib/clients/middleware/signing/signer/signatureV4/presignUrl.js +21 -56
- package/lib/clients/middleware/signing/signer/signatureV4/signRequest.js +14 -25
- package/lib/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +7 -7
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalHeaders.js +8 -30
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalQueryString.js +11 -38
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.js +13 -17
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.js +5 -8
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getCredentialScope.js +2 -2
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getFormattedDates.js +3 -3
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getHashedPayload.js +7 -11
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getSignature.js +9 -10
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getSignedHeaders.js +4 -6
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getSigningKey.js +8 -8
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.js +15 -16
- package/lib/clients/middleware/signing/signer/signatureV4/utils/getStringToSign.js +2 -4
- package/lib/clients/middleware/signing/utils/extendedEncodeURIComponent.js +3 -5
- package/lib/clients/middleware/signing/utils/getSkewCorrectedDate.js +1 -3
- package/lib/clients/middleware/signing/utils/getUpdatedSystemClockOffset.js +2 -2
- package/lib/clients/middleware/signing/utils/isClockSkewed.js +4 -6
- package/lib/clients/middleware/userAgent/middleware.js +14 -63
- package/lib/clients/serde/json.js +30 -96
- package/lib/clients/serde/responseInfo.js +12 -18
- package/lib/clients/utils/memoization.js +3 -3
- package/lib/constants.js +1 -1
- package/lib/errors/AmplifyError.js +9 -28
- package/lib/errors/PlatformNotSupportedError.js +7 -24
- package/lib/errors/createAssertionFunction.js +12 -15
- package/lib/errors/errorHelpers.js +7 -8
- package/lib/index.d.ts +1 -1
- package/lib/libraryUtils.d.ts +4 -0
- package/lib/libraryUtils.js +13 -3
- package/lib/parseAWSExports.js +109 -100
- package/lib/providers/kinesis/types/kinesis.d.ts +1 -1
- package/lib/providers/kinesis-firehose/types/kinesis-firehose.d.ts +1 -1
- package/lib/providers/personalize/types/personalize.d.ts +1 -1
- package/lib/providers/pinpoint/apis/flushEvents.js +8 -8
- package/lib/providers/pinpoint/apis/record.js +58 -93
- package/lib/providers/pinpoint/apis/updateEndpoint.js +65 -112
- package/lib/providers/pinpoint/types/pinpoint.d.ts +3 -1
- package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +105 -196
- package/lib/providers/pinpoint/utils/cacheEndpointId.js +12 -49
- package/lib/providers/pinpoint/utils/getCacheKey.js +2 -2
- package/lib/providers/pinpoint/utils/getEndpointId.js +7 -51
- package/lib/providers/pinpoint/utils/getEventBuffer.js +19 -21
- package/lib/providers/pinpoint/utils/isAppInForeground.js +1 -1
- package/lib/providers/pinpoint/utils/isAppInForeground.native.js +2 -2
- package/lib/providers/pinpoint/utils/resolveEndpointId.js +20 -71
- package/lib/singleton/Amplify.d.ts +4 -0
- package/lib/singleton/Amplify.js +21 -103
- package/lib/singleton/Analytics/types.d.ts +5 -1
- package/lib/singleton/Auth/index.js +48 -115
- package/lib/singleton/Auth/types.d.ts +2 -2
- package/lib/singleton/Auth/utils/errorHelpers.js +7 -8
- package/lib/singleton/Auth/utils/index.js +18 -19
- package/lib/singleton/Predictions/types.d.ts +49 -0
- package/lib/singleton/Predictions/types.js +4 -0
- package/lib/singleton/apis/clearCredentials.js +1 -1
- package/lib/singleton/apis/fetchAuthSession.js +3 -3
- package/lib/singleton/apis/internal/fetchAuthSession.js +1 -1
- package/lib/singleton/apis/server/fetchAuthSession.js +3 -3
- package/lib/singleton/types.d.ts +3 -1
- package/lib/storage/CookieStorage.js +29 -99
- package/lib/storage/CookieStorage.native.js +5 -22
- package/lib/storage/DefaultStorage.js +6 -23
- package/lib/storage/DefaultStorage.native.js +18 -64
- package/lib/storage/InMemoryStorage.js +17 -23
- package/lib/storage/KeyValueStorage.js +24 -80
- package/lib/storage/SessionStorage.js +6 -23
- package/lib/storage/index.js +4 -4
- package/lib/storage/utils.js +7 -11
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/WordArray.d.ts +7 -0
- package/lib/utils/WordArray.js +49 -0
- package/lib/utils/amplifyUrl/index.js +2 -2
- package/lib/utils/amplifyUrl/polyfill.native.js +1 -1
- package/lib/utils/amplifyUuid/index.d.ts +1 -1
- package/lib/utils/amplifyUuid/index.js +2 -2
- package/lib/utils/amplifyUuid/polyfill.native.js +1 -1
- package/lib/utils/convert/base64/base64Decoder.js +2 -2
- package/lib/utils/convert/base64/base64Encoder.js +5 -6
- package/lib/utils/convert/base64/bytesToString.js +1 -1
- package/lib/utils/cryptoSecureRandomInt.d.ts +1 -0
- package/lib/utils/cryptoSecureRandomInt.js +16 -0
- package/lib/utils/deepFreeze.js +6 -28
- package/lib/utils/generateRandomString.js +4 -4
- package/lib/utils/getClientInfo/getClientInfo.android.js +7 -7
- package/lib/utils/getClientInfo/getClientInfo.ios.js +12 -12
- package/lib/utils/getClientInfo/getClientInfo.js +16 -16
- package/lib/utils/globalHelpers/index.js +4 -4
- package/lib/utils/globalHelpers/index.native.js +6 -6
- package/lib/utils/isBrowser.js +1 -3
- package/lib/utils/isWebWorker.js +2 -2
- package/lib/utils/retry/NonRetryableError.js +5 -23
- package/lib/utils/retry/isNonRetryableError.js +2 -2
- package/lib/utils/retry/jitteredBackoff.js +6 -7
- package/lib/utils/retry/jitteredExponentialRetry.js +4 -7
- package/lib/utils/retry/retry.js +50 -140
- package/lib/utils/sessionListener/SessionListener.js +17 -19
- package/lib/utils/sessionListener/SessionListener.native.js +18 -22
- package/lib/utils/sessionListener/constants.d.ts +2 -0
- package/lib/utils/sessionListener/constants.js +8 -0
- package/lib/utils/sessionListener/index.d.ts +1 -0
- package/lib/utils/sessionListener/index.js +5 -2
- package/lib/utils/urlSafeDecode.js +2 -2
- package/lib/utils/urlSafeEncode.js +1 -1
- package/lib-esm/BackgroundProcessManager/BackgroundManagerNotOpenError.js +4 -22
- package/lib-esm/BackgroundProcessManager/BackgroundProcessManager.js +124 -244
- package/lib-esm/Cache/StorageCache.js +26 -87
- package/lib-esm/Cache/StorageCache.native.js +33 -136
- package/lib-esm/Cache/StorageCacheCommon.js +267 -597
- package/lib-esm/Cache/constants.js +2 -2
- package/lib-esm/Cache/index.js +1 -1
- package/lib-esm/Cache/utils/CacheList.js +41 -66
- package/lib-esm/Cache/utils/cacheHelpers.js +5 -7
- package/lib-esm/Cache/utils/errorHelpers.js +6 -7
- package/lib-esm/Hub/index.js +34 -75
- package/lib-esm/I18n/I18n.js +23 -39
- package/lib-esm/I18n/errorHelpers.js +4 -5
- package/lib-esm/I18n/index.js +21 -25
- package/lib-esm/I18n/types.js +3 -5
- package/lib-esm/Logger/ConsoleLogger.js +52 -128
- package/lib-esm/Mutex/Mutex.js +15 -20
- package/lib-esm/Platform/customUserAgent.js +13 -26
- package/lib-esm/Platform/detectFramework.js +11 -12
- package/lib-esm/Platform/detection/Angular.js +3 -4
- package/lib-esm/Platform/detection/React.js +4 -4
- package/lib-esm/Platform/detection/Svelte.js +1 -1
- package/lib-esm/Platform/detection/helpers.js +7 -7
- package/lib-esm/Platform/detection/index.js +3 -3
- package/lib-esm/Platform/index.js +23 -52
- package/lib-esm/Platform/types.d.ts +1 -1
- package/lib-esm/Platform/types.js +1 -1
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/Reachability/Reachability.js +18 -46
- package/lib-esm/Reachability/Reachability.native.js +10 -15
- package/lib-esm/ServiceWorker/ServiceWorker.js +74 -131
- package/lib-esm/ServiceWorker/errorHelpers.js +6 -7
- package/lib-esm/Signer/DateUtils.d.ts +9 -0
- package/lib-esm/Signer/DateUtils.js +20 -29
- package/lib-esm/Signer/Signer.d.ts +9 -0
- package/lib-esm/Signer/Signer.js +54 -51
- package/lib-esm/adapterCore/error/AmplifyServerContextError.js +8 -27
- package/lib-esm/adapterCore/serverContext/serverContext.js +6 -6
- package/lib-esm/adapterCore/serverContext/serverContextRegistry.js +7 -7
- package/lib-esm/awsClients/cognitoIdentity/base.js +21 -69
- package/lib-esm/awsClients/cognitoIdentity/getCredentialsForIdentity.js +22 -66
- package/lib-esm/awsClients/cognitoIdentity/getId.js +17 -60
- package/lib-esm/awsClients/pinpoint/base.js +8 -11
- package/lib-esm/awsClients/pinpoint/errorHelpers.js +4 -5
- package/lib-esm/awsClients/pinpoint/getInAppMessages.js +19 -63
- package/lib-esm/awsClients/pinpoint/putEvents.js +20 -64
- package/lib-esm/awsClients/pinpoint/updateEndpoint.js +23 -67
- package/lib-esm/clients/endpoints/getDnsSuffix.js +6 -28
- package/lib-esm/clients/endpoints/partitions.js +2 -2
- package/lib-esm/clients/handlers/authenticated.js +1 -1
- package/lib-esm/clients/handlers/fetch.js +40 -97
- package/lib-esm/clients/handlers/unauthenticated.js +1 -1
- package/lib-esm/clients/internal/composeServiceApi.js +17 -67
- package/lib-esm/clients/internal/composeTransferHandler.js +9 -11
- package/lib-esm/clients/middleware/retry/defaultRetryDecider.js +17 -74
- package/lib-esm/clients/middleware/retry/isClockSkewError.js +2 -4
- package/lib-esm/clients/middleware/retry/jitteredBackoff.js +4 -4
- package/lib-esm/clients/middleware/retry/middleware.js +61 -125
- package/lib-esm/clients/middleware/signing/middleware.js +21 -83
- package/lib-esm/clients/middleware/signing/signer/signatureV4/constants.js +17 -17
- package/lib-esm/clients/middleware/signing/signer/signatureV4/index.js +0 -1
- package/lib-esm/clients/middleware/signing/signer/signatureV4/presignUrl.js +17 -52
- package/lib-esm/clients/middleware/signing/signer/signatureV4/signRequest.js +10 -21
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +5 -5
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalHeaders.js +8 -30
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalQueryString.js +11 -38
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.js +8 -12
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.js +5 -8
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCredentialScope.js +1 -1
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getFormattedDates.js +3 -3
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getHashedPayload.js +5 -9
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSignature.js +5 -6
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSignedHeaders.js +4 -6
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSigningKey.js +6 -6
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.js +13 -14
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getStringToSign.js +1 -3
- package/lib-esm/clients/middleware/signing/utils/extendedEncodeURIComponent.js +3 -5
- package/lib-esm/clients/middleware/signing/utils/getSkewCorrectedDate.js +1 -3
- package/lib-esm/clients/middleware/signing/utils/getUpdatedSystemClockOffset.js +1 -1
- package/lib-esm/clients/middleware/signing/utils/isClockSkewed.js +3 -5
- package/lib-esm/clients/middleware/userAgent/middleware.js +14 -63
- package/lib-esm/clients/serde/json.js +29 -95
- package/lib-esm/clients/serde/responseInfo.js +11 -17
- package/lib-esm/clients/utils/memoization.js +3 -3
- package/lib-esm/constants.js +5 -5
- package/lib-esm/errors/AmplifyError.js +9 -29
- package/lib-esm/errors/PlatformNotSupportedError.js +5 -23
- package/lib-esm/errors/createAssertionFunction.js +11 -14
- package/lib-esm/errors/errorHelpers.js +6 -7
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/libraryUtils.d.ts +4 -0
- package/lib-esm/libraryUtils.js +4 -0
- package/lib-esm/parseAWSExports.js +108 -99
- package/lib-esm/providers/kinesis/types/kinesis.d.ts +1 -1
- package/lib-esm/providers/kinesis-firehose/types/kinesis-firehose.d.ts +1 -1
- package/lib-esm/providers/personalize/types/personalize.d.ts +1 -1
- package/lib-esm/providers/pinpoint/apis/flushEvents.js +6 -6
- package/lib-esm/providers/pinpoint/apis/record.js +54 -89
- package/lib-esm/providers/pinpoint/apis/updateEndpoint.js +61 -108
- package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +3 -1
- package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +102 -194
- package/lib-esm/providers/pinpoint/utils/cacheEndpointId.js +10 -47
- package/lib-esm/providers/pinpoint/utils/constants.js +4 -4
- package/lib-esm/providers/pinpoint/utils/getCacheKey.js +2 -2
- package/lib-esm/providers/pinpoint/utils/getEndpointId.js +5 -49
- package/lib-esm/providers/pinpoint/utils/getEventBuffer.js +17 -19
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.js +1 -1
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.js +1 -1
- package/lib-esm/providers/pinpoint/utils/resolveEndpointId.js +16 -67
- package/lib-esm/singleton/Amplify.d.ts +4 -0
- package/lib-esm/singleton/Amplify.js +18 -101
- package/lib-esm/singleton/Analytics/types.d.ts +5 -1
- package/lib-esm/singleton/Auth/index.js +48 -116
- package/lib-esm/singleton/Auth/types.d.ts +2 -2
- package/lib-esm/singleton/Auth/utils/errorHelpers.js +7 -8
- package/lib-esm/singleton/Auth/utils/index.js +16 -17
- package/lib-esm/singleton/Predictions/types.d.ts +49 -0
- package/lib-esm/singleton/Predictions/types.js +3 -0
- package/lib-esm/singleton/apis/fetchAuthSession.js +1 -1
- package/lib-esm/singleton/apis/internal/fetchAuthSession.js +1 -1
- package/lib-esm/singleton/apis/server/fetchAuthSession.js +1 -1
- package/lib-esm/singleton/types.d.ts +3 -1
- package/lib-esm/storage/CookieStorage.js +28 -99
- package/lib-esm/storage/CookieStorage.native.js +4 -22
- package/lib-esm/storage/DefaultStorage.js +4 -22
- package/lib-esm/storage/DefaultStorage.native.js +17 -64
- package/lib-esm/storage/InMemoryStorage.js +17 -24
- package/lib-esm/storage/KeyValueStorage.js +23 -80
- package/lib-esm/storage/SessionStorage.js +4 -22
- package/lib-esm/storage/index.js +3 -3
- package/lib-esm/storage/utils.js +6 -10
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/utils/WordArray.d.ts +7 -0
- package/lib-esm/utils/WordArray.js +46 -0
- package/lib-esm/utils/amplifyUrl/index.js +2 -2
- package/lib-esm/utils/amplifyUuid/index.d.ts +1 -1
- package/lib-esm/utils/amplifyUuid/index.js +1 -1
- package/lib-esm/utils/convert/base64/base64Decoder.js +2 -2
- package/lib-esm/utils/convert/base64/base64Encoder.js +4 -5
- package/lib-esm/utils/convert/base64/bytesToString.js +1 -1
- package/lib-esm/utils/cryptoSecureRandomInt.d.ts +1 -0
- package/lib-esm/utils/cryptoSecureRandomInt.js +12 -0
- package/lib-esm/utils/deepFreeze.js +6 -28
- package/lib-esm/utils/generateRandomString.js +4 -4
- package/lib-esm/utils/getClientInfo/getClientInfo.android.js +5 -5
- package/lib-esm/utils/getClientInfo/getClientInfo.ios.js +10 -10
- package/lib-esm/utils/getClientInfo/getClientInfo.js +15 -15
- package/lib-esm/utils/globalHelpers/index.js +3 -3
- package/lib-esm/utils/globalHelpers/index.native.js +4 -4
- package/lib-esm/utils/isBrowser.js +1 -3
- package/lib-esm/utils/isWebWorker.js +2 -2
- package/lib-esm/utils/retry/NonRetryableError.js +5 -24
- package/lib-esm/utils/retry/constants.js +1 -1
- package/lib-esm/utils/retry/isNonRetryableError.js +2 -2
- package/lib-esm/utils/retry/jitteredBackoff.js +5 -6
- package/lib-esm/utils/retry/jitteredExponentialRetry.js +1 -4
- package/lib-esm/utils/retry/retry.js +48 -138
- package/lib-esm/utils/sessionListener/SessionListener.js +16 -19
- package/lib-esm/utils/sessionListener/SessionListener.native.js +17 -22
- package/lib-esm/utils/sessionListener/constants.d.ts +2 -0
- package/lib-esm/utils/sessionListener/constants.js +5 -0
- package/lib-esm/utils/sessionListener/index.d.ts +1 -0
- package/lib-esm/utils/sessionListener/index.js +2 -1
- package/lib-esm/utils/urlSafeDecode.js +2 -2
- package/lib-esm/utils/urlSafeEncode.js +1 -1
- package/package.json +11 -24
- package/src/Cache/types/index.ts +4 -4
- package/src/Platform/types.ts +1 -1
- package/src/Platform/version.ts +1 -1
- package/src/Signer/DateUtils.ts +10 -2
- package/src/Signer/Signer.ts +9 -2
- package/src/clients/middleware/signing/signer/signatureV4/index.ts +0 -1
- package/src/index.ts +1 -0
- package/src/libraryUtils.ts +7 -1
- package/src/parseAWSExports.ts +45 -6
- package/src/providers/kinesis/types/kinesis.ts +1 -1
- package/src/providers/kinesis-firehose/types/kinesis-firehose.ts +1 -1
- package/src/providers/personalize/types/personalize.ts +1 -1
- package/src/providers/pinpoint/apis/record.ts +22 -5
- package/src/providers/pinpoint/types/pinpoint.ts +3 -1
- package/src/singleton/Amplify.ts +9 -52
- package/src/singleton/Analytics/types.ts +9 -4
- package/src/singleton/Auth/types.ts +2 -2
- package/src/singleton/Predictions/types.ts +61 -0
- package/src/singleton/types.ts +3 -1
- package/src/utils/WordArray.ts +57 -0
- package/src/utils/amplifyUuid/index.ts +1 -1
- package/src/utils/cryptoSecureRandomInt.ts +14 -0
- package/src/utils/sessionListener/constants.ts +6 -0
- package/src/utils/sessionListener/index.ts +1 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Default cache config
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export const defaultConfig = {
|
|
7
7
|
keyPrefix: 'aws-amplify-cache',
|
|
8
8
|
capacityInBytes: 1048576,
|
|
9
9
|
itemMaxSize: 210000,
|
|
@@ -11,4 +11,4 @@ export var defaultConfig = {
|
|
|
11
11
|
defaultPriority: 5,
|
|
12
12
|
warningThreshold: 0.8,
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export const currentSizeKey = 'CurSize';
|
package/lib-esm/Cache/index.js
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
var __values = (this && this.__values) || function(o) {
|
|
4
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
5
|
-
if (m) return m.call(o);
|
|
6
|
-
if (o && typeof o.length === "number") return {
|
|
7
|
-
next: function () {
|
|
8
|
-
if (o && i >= o.length) o = void 0;
|
|
9
|
-
return { value: o && o[i++], done: !o };
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
13
|
-
};
|
|
14
3
|
import { assert, CacheErrorCode } from './errorHelpers';
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
class DoubleLinkedNode {
|
|
5
|
+
constructor(keyVal) {
|
|
17
6
|
this.key = keyVal ? keyVal : '';
|
|
18
7
|
this.prevNode = null;
|
|
19
8
|
this.nextNode = null;
|
|
20
9
|
}
|
|
21
|
-
|
|
22
|
-
}());
|
|
10
|
+
}
|
|
23
11
|
/**
|
|
24
12
|
* double linked list plus a hash table inside
|
|
25
13
|
* each key in the cache stored as a node in the list
|
|
@@ -31,11 +19,11 @@ var DoubleLinkedNode = /** @class */ (function () {
|
|
|
31
19
|
* @member hashtable - the hashtable which maps cache key to list node
|
|
32
20
|
* @member length - length of the list
|
|
33
21
|
*/
|
|
34
|
-
|
|
22
|
+
export class CacheList {
|
|
35
23
|
/**
|
|
36
24
|
* initialization
|
|
37
25
|
*/
|
|
38
|
-
|
|
26
|
+
constructor() {
|
|
39
27
|
this.head = new DoubleLinkedNode();
|
|
40
28
|
this.tail = new DoubleLinkedNode();
|
|
41
29
|
this.hashtable = {};
|
|
@@ -48,21 +36,21 @@ var CacheList = /** @class */ (function () {
|
|
|
48
36
|
*
|
|
49
37
|
* @param node
|
|
50
38
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
insertNodeToHead(node) {
|
|
40
|
+
const tmp = this.head.nextNode;
|
|
53
41
|
this.head.nextNode = node;
|
|
54
42
|
node.nextNode = tmp;
|
|
55
43
|
node.prevNode = this.head;
|
|
56
44
|
assert(tmp !== null, CacheErrorCode.NullPreviousNode);
|
|
57
45
|
tmp.prevNode = node;
|
|
58
46
|
this.length = this.length + 1;
|
|
59
|
-
}
|
|
47
|
+
}
|
|
60
48
|
/**
|
|
61
49
|
* remove node
|
|
62
50
|
*
|
|
63
51
|
* @param node
|
|
64
52
|
*/
|
|
65
|
-
|
|
53
|
+
removeNode(node) {
|
|
66
54
|
assert(node.prevNode !== null, CacheErrorCode.NullPreviousNode);
|
|
67
55
|
assert(node.nextNode !== null, CacheErrorCode.NullNextNode);
|
|
68
56
|
node.prevNode.nextNode = node.nextNode;
|
|
@@ -70,112 +58,99 @@ var CacheList = /** @class */ (function () {
|
|
|
70
58
|
node.prevNode = null;
|
|
71
59
|
node.nextNode = null;
|
|
72
60
|
this.length = this.length - 1;
|
|
73
|
-
}
|
|
61
|
+
}
|
|
74
62
|
/**
|
|
75
63
|
* @return true if list is empty
|
|
76
64
|
*/
|
|
77
|
-
|
|
65
|
+
isEmpty() {
|
|
78
66
|
return this.length === 0;
|
|
79
|
-
}
|
|
67
|
+
}
|
|
80
68
|
/**
|
|
81
69
|
* refresh node so it is rotated to the head
|
|
82
70
|
*
|
|
83
71
|
* @param key - key of the node
|
|
84
72
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
refresh(key) {
|
|
74
|
+
const node = this.hashtable[key];
|
|
87
75
|
this.removeNode(node);
|
|
88
76
|
this.insertNodeToHead(node);
|
|
89
|
-
}
|
|
77
|
+
}
|
|
90
78
|
/**
|
|
91
79
|
* insert new node to the head and add it in the hashtable
|
|
92
80
|
*
|
|
93
81
|
* @param key - the key of the node
|
|
94
82
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
83
|
+
insertItem(key) {
|
|
84
|
+
const node = new DoubleLinkedNode(key);
|
|
97
85
|
this.hashtable[key] = node;
|
|
98
86
|
this.insertNodeToHead(node);
|
|
99
|
-
}
|
|
87
|
+
}
|
|
100
88
|
/**
|
|
101
89
|
* @return the LAST Recently Visited key
|
|
102
90
|
*/
|
|
103
|
-
|
|
91
|
+
getLastItem() {
|
|
104
92
|
assert(this.tail.prevNode !== null, CacheErrorCode.NullPreviousNode);
|
|
105
93
|
return this.tail.prevNode.key;
|
|
106
|
-
}
|
|
94
|
+
}
|
|
107
95
|
/**
|
|
108
96
|
* remove the cache key from the list and hashtable
|
|
109
97
|
* @param key - the key of the node
|
|
110
98
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
99
|
+
removeItem(key) {
|
|
100
|
+
const removedItem = this.hashtable[key];
|
|
113
101
|
this.removeNode(removedItem);
|
|
114
102
|
delete this.hashtable[key];
|
|
115
|
-
}
|
|
103
|
+
}
|
|
116
104
|
/**
|
|
117
105
|
* @return length of the list
|
|
118
106
|
*/
|
|
119
|
-
|
|
107
|
+
getSize() {
|
|
120
108
|
return this.length;
|
|
121
|
-
}
|
|
109
|
+
}
|
|
122
110
|
/**
|
|
123
111
|
* @return true if the key is in the hashtable
|
|
124
112
|
* @param key
|
|
125
113
|
*/
|
|
126
|
-
|
|
114
|
+
containsKey(key) {
|
|
127
115
|
return key in this.hashtable;
|
|
128
|
-
}
|
|
116
|
+
}
|
|
129
117
|
/**
|
|
130
118
|
* clean up the list and hashtable
|
|
131
119
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
var key = _c.value;
|
|
137
|
-
if (this.hashtable.hasOwnProperty(key)) {
|
|
138
|
-
delete this.hashtable[key];
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
143
|
-
finally {
|
|
144
|
-
try {
|
|
145
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
120
|
+
clearList() {
|
|
121
|
+
for (const key of Object.keys(this.hashtable)) {
|
|
122
|
+
if (this.hashtable.hasOwnProperty(key)) {
|
|
123
|
+
delete this.hashtable[key];
|
|
146
124
|
}
|
|
147
|
-
finally { if (e_1) throw e_1.error; }
|
|
148
125
|
}
|
|
149
126
|
this.head.nextNode = this.tail;
|
|
150
127
|
this.tail.prevNode = this.head;
|
|
151
128
|
this.length = 0;
|
|
152
|
-
}
|
|
129
|
+
}
|
|
153
130
|
/**
|
|
154
131
|
* @return all keys in the hashtable
|
|
155
132
|
*/
|
|
156
|
-
|
|
133
|
+
getKeys() {
|
|
157
134
|
return Object.keys(this.hashtable);
|
|
158
|
-
}
|
|
135
|
+
}
|
|
159
136
|
/**
|
|
160
137
|
* mainly for test
|
|
161
138
|
*
|
|
162
139
|
* @param key
|
|
163
140
|
* @return true if key is the head node
|
|
164
141
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
142
|
+
isHeadNode(key) {
|
|
143
|
+
const node = this.hashtable[key];
|
|
167
144
|
return node.prevNode === this.head;
|
|
168
|
-
}
|
|
145
|
+
}
|
|
169
146
|
/**
|
|
170
147
|
* mainly for test
|
|
171
148
|
*
|
|
172
149
|
* @param key
|
|
173
150
|
* @return true if key is the tail node
|
|
174
151
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
152
|
+
isTailNode(key) {
|
|
153
|
+
const node = this.hashtable[key];
|
|
177
154
|
return node.nextNode === this.tail;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
}());
|
|
181
|
-
export { CacheList };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -6,10 +6,10 @@ import { currentSizeKey } from '../constants';
|
|
|
6
6
|
* @param str
|
|
7
7
|
*/
|
|
8
8
|
export function getByteLength(str) {
|
|
9
|
-
|
|
9
|
+
let ret = 0;
|
|
10
10
|
ret = str.length;
|
|
11
|
-
for (
|
|
12
|
-
|
|
11
|
+
for (let i = str.length; i >= 0; i -= 1) {
|
|
12
|
+
const charCode = str.charCodeAt(i);
|
|
13
13
|
if (charCode > 0x7f && charCode <= 0x7ff) {
|
|
14
14
|
ret += 1;
|
|
15
15
|
}
|
|
@@ -27,7 +27,7 @@ export function getByteLength(str) {
|
|
|
27
27
|
* get current time
|
|
28
28
|
*/
|
|
29
29
|
export function getCurrentTime() {
|
|
30
|
-
|
|
30
|
+
const currentTime = new Date();
|
|
31
31
|
return currentTime.getTime();
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
@@ -39,6 +39,4 @@ export function isInteger(value) {
|
|
|
39
39
|
}
|
|
40
40
|
return (typeof value === 'number' && isFinite(value) && Math.floor(value) === value);
|
|
41
41
|
}
|
|
42
|
-
export
|
|
43
|
-
return "".concat(keyPrefix).concat(currentSizeKey);
|
|
44
|
-
};
|
|
42
|
+
export const getCurrentSizeKey = (keyPrefix) => `${keyPrefix}${currentSizeKey}`;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
var _a;
|
|
4
3
|
import { createAssertionFunction } from '../../errors';
|
|
5
4
|
export var CacheErrorCode;
|
|
6
5
|
(function (CacheErrorCode) {
|
|
@@ -8,15 +7,15 @@ export var CacheErrorCode;
|
|
|
8
7
|
CacheErrorCode["NullNextNode"] = "NullNextNode";
|
|
9
8
|
CacheErrorCode["NullPreviousNode"] = "NullPreviousNode";
|
|
10
9
|
})(CacheErrorCode || (CacheErrorCode = {}));
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const cacheErrorMap = {
|
|
11
|
+
[CacheErrorCode.NoCacheItem]: {
|
|
13
12
|
message: 'Item not found in the cache storage.',
|
|
14
13
|
},
|
|
15
|
-
|
|
14
|
+
[CacheErrorCode.NullNextNode]: {
|
|
16
15
|
message: 'Next node is null.',
|
|
17
16
|
},
|
|
18
|
-
|
|
17
|
+
[CacheErrorCode.NullPreviousNode]: {
|
|
19
18
|
message: 'Previous node is null.',
|
|
20
19
|
},
|
|
21
|
-
|
|
22
|
-
export
|
|
20
|
+
};
|
|
21
|
+
export const assert = createAssertionFunction(cacheErrorMap);
|
package/lib-esm/Hub/index.js
CHANGED
|
@@ -1,50 +1,14 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
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 __read = (this && this.__read) || function (o, n) {
|
|
15
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
16
|
-
if (!m) return o;
|
|
17
|
-
var i = m.call(o), r, ar = [], e;
|
|
18
|
-
try {
|
|
19
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
20
|
-
}
|
|
21
|
-
catch (error) { e = { error: error }; }
|
|
22
|
-
finally {
|
|
23
|
-
try {
|
|
24
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
25
|
-
}
|
|
26
|
-
finally { if (e) throw e.error; }
|
|
27
|
-
}
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
31
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
32
|
-
if (ar || !(i in from)) {
|
|
33
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
34
|
-
ar[i] = from[i];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
38
|
-
};
|
|
39
3
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
40
4
|
import { NO_HUBCALLBACK_PROVIDED_EXCEPTION } from '../constants';
|
|
41
5
|
import { AmplifyError } from '../errors';
|
|
42
|
-
export
|
|
6
|
+
export const AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
|
|
43
7
|
? Symbol.for('amplify_default')
|
|
44
8
|
: '@@amplify_default');
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
9
|
+
const logger = new Logger('Hub');
|
|
10
|
+
export class HubClass {
|
|
11
|
+
constructor(name) {
|
|
48
12
|
this.listeners = new Map();
|
|
49
13
|
this.protectedChannels = [
|
|
50
14
|
'core',
|
|
@@ -65,29 +29,28 @@ var HubClass = /** @class */ (function () {
|
|
|
65
29
|
* @remarks
|
|
66
30
|
* This private method is for internal use only. Instead of calling Hub.remove, call the result of Hub.listen.
|
|
67
31
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
32
|
+
_remove(channel, listener) {
|
|
33
|
+
const holder = this.listeners.get(channel);
|
|
70
34
|
if (!holder) {
|
|
71
|
-
logger.warn(
|
|
35
|
+
logger.warn(`No listeners for ${channel}`);
|
|
72
36
|
return;
|
|
73
37
|
}
|
|
74
|
-
this.listeners.set(channel,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
HubClass.prototype.dispatch = function (channel, payload, source, ampSymbol) {
|
|
38
|
+
this.listeners.set(channel, [
|
|
39
|
+
...holder.filter(({ callback }) => callback !== listener),
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
dispatch(channel, payload, source, ampSymbol) {
|
|
80
43
|
if (typeof channel === 'string' &&
|
|
81
44
|
this.protectedChannels.indexOf(channel) > -1) {
|
|
82
|
-
|
|
45
|
+
const hasAccess = ampSymbol === AMPLIFY_SYMBOL;
|
|
83
46
|
if (!hasAccess) {
|
|
84
|
-
logger.warn(
|
|
47
|
+
logger.warn(`WARNING: ${channel} is protected and dispatching on it can have unintended consequences`);
|
|
85
48
|
}
|
|
86
49
|
}
|
|
87
|
-
|
|
88
|
-
channel
|
|
89
|
-
payload:
|
|
90
|
-
source
|
|
50
|
+
const capsule = {
|
|
51
|
+
channel,
|
|
52
|
+
payload: { ...payload },
|
|
53
|
+
source,
|
|
91
54
|
patternInfo: [],
|
|
92
55
|
};
|
|
93
56
|
try {
|
|
@@ -96,11 +59,9 @@ var HubClass = /** @class */ (function () {
|
|
|
96
59
|
catch (e) {
|
|
97
60
|
logger.error(e);
|
|
98
61
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (listenerName === void 0) { listenerName = 'noname'; }
|
|
103
|
-
var cb;
|
|
62
|
+
}
|
|
63
|
+
listen(channel, callback, listenerName = 'noname') {
|
|
64
|
+
let cb;
|
|
104
65
|
if (typeof callback !== 'function') {
|
|
105
66
|
throw new AmplifyError({
|
|
106
67
|
name: NO_HUBCALLBACK_PROVIDED_EXCEPTION,
|
|
@@ -111,7 +72,7 @@ var HubClass = /** @class */ (function () {
|
|
|
111
72
|
// Needs to be casted as a more generic type
|
|
112
73
|
cb = callback;
|
|
113
74
|
}
|
|
114
|
-
|
|
75
|
+
let holder = this.listeners.get(channel);
|
|
115
76
|
if (!holder) {
|
|
116
77
|
holder = [];
|
|
117
78
|
this.listeners.set(channel, holder);
|
|
@@ -120,16 +81,16 @@ var HubClass = /** @class */ (function () {
|
|
|
120
81
|
name: listenerName,
|
|
121
82
|
callback: cb,
|
|
122
83
|
});
|
|
123
|
-
return
|
|
124
|
-
|
|
84
|
+
return () => {
|
|
85
|
+
this._remove(channel, cb);
|
|
125
86
|
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
87
|
+
}
|
|
88
|
+
_toListeners(capsule) {
|
|
89
|
+
const { channel, payload } = capsule;
|
|
90
|
+
const holder = this.listeners.get(channel);
|
|
130
91
|
if (holder) {
|
|
131
|
-
holder.forEach(
|
|
132
|
-
logger.debug(
|
|
92
|
+
holder.forEach(listener => {
|
|
93
|
+
logger.debug(`Dispatching to ${channel} with `, payload);
|
|
133
94
|
try {
|
|
134
95
|
listener.callback(capsule);
|
|
135
96
|
}
|
|
@@ -138,18 +99,16 @@ var HubClass = /** @class */ (function () {
|
|
|
138
99
|
}
|
|
139
100
|
});
|
|
140
101
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
}());
|
|
144
|
-
export { HubClass };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
145
104
|
/*We export a __default__ instance of HubClass to use it as a
|
|
146
105
|
pseudo Singleton for the main messaging bus, however you can still create
|
|
147
106
|
your own instance of HubClass() for a separate "private bus" of events.*/
|
|
148
|
-
export
|
|
107
|
+
export const Hub = new HubClass('__default__');
|
|
149
108
|
/**
|
|
150
109
|
* @internal
|
|
151
110
|
*
|
|
152
111
|
* Internal hub used for core Amplify functionality. Not intended for use outside of Amplify.
|
|
153
112
|
*
|
|
154
113
|
*/
|
|
155
|
-
export
|
|
114
|
+
export const HubInternal = new HubClass('internal-hub');
|
package/lib-esm/I18n/I18n.js
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
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
3
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
15
|
-
|
|
4
|
+
const logger = new Logger('I18n');
|
|
16
5
|
/**
|
|
17
6
|
* Language translation utility.
|
|
18
7
|
*/
|
|
19
|
-
|
|
8
|
+
export class I18n {
|
|
20
9
|
/**
|
|
21
10
|
* @constructor
|
|
22
11
|
* Initialize with configurations
|
|
23
12
|
* @param {Object} options
|
|
24
13
|
*/
|
|
25
|
-
|
|
14
|
+
constructor() {
|
|
26
15
|
/**
|
|
27
16
|
* @private
|
|
28
17
|
*/
|
|
@@ -39,7 +28,7 @@ var I18n = /** @class */ (function () {
|
|
|
39
28
|
/**
|
|
40
29
|
* Sets the default language from the configuration when required.
|
|
41
30
|
*/
|
|
42
|
-
|
|
31
|
+
setDefaultLanguage() {
|
|
43
32
|
// Default to window language if not set in instance
|
|
44
33
|
if (!this._lang &&
|
|
45
34
|
typeof window !== 'undefined' &&
|
|
@@ -48,28 +37,27 @@ var I18n = /** @class */ (function () {
|
|
|
48
37
|
this._lang = window.navigator.language;
|
|
49
38
|
}
|
|
50
39
|
logger.debug(this._lang);
|
|
51
|
-
}
|
|
40
|
+
}
|
|
52
41
|
/**
|
|
53
42
|
* @method
|
|
54
43
|
* Explicitly setting language
|
|
55
44
|
* @param {String} lang
|
|
56
45
|
*/
|
|
57
|
-
|
|
46
|
+
setLanguage(lang) {
|
|
58
47
|
this._lang = lang;
|
|
59
|
-
}
|
|
48
|
+
}
|
|
60
49
|
/**
|
|
61
50
|
* @method
|
|
62
51
|
* Get value
|
|
63
52
|
* @param {String} key
|
|
64
53
|
* @param {String} defVal - Default value
|
|
65
54
|
*/
|
|
66
|
-
|
|
67
|
-
if (defVal === void 0) { defVal = undefined; }
|
|
55
|
+
get(key, defVal = undefined) {
|
|
68
56
|
if (!this._lang) {
|
|
69
57
|
return typeof defVal !== 'undefined' ? defVal : key;
|
|
70
58
|
}
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
const lang = this._lang;
|
|
60
|
+
let val = this.getByLanguage(key, lang);
|
|
73
61
|
if (val) {
|
|
74
62
|
return val;
|
|
75
63
|
}
|
|
@@ -80,7 +68,7 @@ var I18n = /** @class */ (function () {
|
|
|
80
68
|
return val;
|
|
81
69
|
}
|
|
82
70
|
return typeof defVal !== 'undefined' ? defVal : key;
|
|
83
|
-
}
|
|
71
|
+
}
|
|
84
72
|
/**
|
|
85
73
|
* @method
|
|
86
74
|
* Get value according to specified language
|
|
@@ -88,42 +76,38 @@ var I18n = /** @class */ (function () {
|
|
|
88
76
|
* @param {String} language - Specified langurage to be used
|
|
89
77
|
* @param {String} defVal - Default value
|
|
90
78
|
*/
|
|
91
|
-
|
|
92
|
-
if (defVal === void 0) { defVal = null; }
|
|
79
|
+
getByLanguage(key, language, defVal = null) {
|
|
93
80
|
if (!language) {
|
|
94
81
|
return defVal;
|
|
95
82
|
}
|
|
96
|
-
|
|
83
|
+
const lang_dict = this._dict[language];
|
|
97
84
|
if (!lang_dict) {
|
|
98
85
|
return defVal;
|
|
99
86
|
}
|
|
100
87
|
return lang_dict[key];
|
|
101
|
-
}
|
|
88
|
+
}
|
|
102
89
|
/**
|
|
103
90
|
* @method
|
|
104
91
|
* Add vocabularies for one language
|
|
105
92
|
* @param {String} language - Language of the dictionary
|
|
106
93
|
* @param {Object} vocabularies - Object that has key-value as dictionary entry
|
|
107
94
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
95
|
+
putVocabulariesForLanguage(language, vocabularies) {
|
|
96
|
+
let lang_dict = this._dict[language];
|
|
110
97
|
if (!lang_dict) {
|
|
111
98
|
lang_dict = this._dict[language] = {};
|
|
112
99
|
}
|
|
113
|
-
this._dict[language] =
|
|
114
|
-
}
|
|
100
|
+
this._dict[language] = { ...lang_dict, ...vocabularies };
|
|
101
|
+
}
|
|
115
102
|
/**
|
|
116
103
|
* @method
|
|
117
104
|
* Add vocabularies for one language
|
|
118
105
|
* @param {Object} vocabularies - Object that has language as key,
|
|
119
106
|
* vocabularies of each language as value
|
|
120
107
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
_this.putVocabulariesForLanguage(key, vocabularies[key]);
|
|
108
|
+
putVocabularies(vocabularies) {
|
|
109
|
+
Object.keys(vocabularies).map(key => {
|
|
110
|
+
this.putVocabulariesForLanguage(key, vocabularies[key]);
|
|
125
111
|
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
}());
|
|
129
|
-
export { I18n };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
var _a;
|
|
4
3
|
import { createAssertionFunction } from '../errors';
|
|
5
4
|
export var I18nErrorCode;
|
|
6
5
|
(function (I18nErrorCode) {
|
|
7
6
|
I18nErrorCode["NotConfigured"] = "NotConfigured";
|
|
8
7
|
})(I18nErrorCode || (I18nErrorCode = {}));
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const i18nErrorMap = {
|
|
9
|
+
[I18nErrorCode.NotConfigured]: {
|
|
11
10
|
message: 'i18n is not configured.',
|
|
12
11
|
},
|
|
13
|
-
|
|
14
|
-
export
|
|
12
|
+
};
|
|
13
|
+
export const assert = createAssertionFunction(i18nErrorMap);
|