@aws-amplify/core 5.8.2 → 6.0.1-console-preview.f63250a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/lib/Amplify.d.ts +18 -17
- package/lib/Amplify.js +9 -0
- package/lib/AwsClients/CognitoIdentity/base.d.ts +3 -10
- package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +3 -17
- package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +8 -8
- package/lib/AwsClients/CognitoIdentity/getId.d.ts +3 -17
- package/lib/AwsClients/Pinpoint/base.d.ts +2 -10
- package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +3 -17
- package/lib/AwsClients/Pinpoint/getInAppMessages.js +1 -1
- package/lib/AwsClients/Pinpoint/putEvents.d.ts +3 -17
- package/lib/AwsClients/Pinpoint/putEvents.js +6 -0
- package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +3 -17
- package/lib/AwsClients/Pinpoint/updateEndpoint.js +2 -2
- package/lib/Cache/AsyncStorageCache.d.ts +154 -0
- package/lib/Cache/AsyncStorageCache.js +744 -0
- package/lib/Cache/BrowserStorageCache.d.ts +166 -0
- package/lib/Cache/BrowserStorageCache.js +469 -0
- package/lib/Cache/InMemoryCache.d.ts +129 -0
- package/lib/Cache/InMemoryCache.js +349 -0
- package/lib/Cache/StorageCache.d.ts +39 -0
- package/lib/Cache/StorageCache.js +121 -0
- package/lib/Cache/Utils/CacheList.d.ts +89 -0
- package/lib/Cache/Utils/CacheList.js +196 -0
- package/lib/Cache/Utils/CacheUtils.d.ts +25 -0
- package/lib/Cache/Utils/CacheUtils.js +88 -0
- package/lib/Cache/Utils/index.d.ts +2 -0
- package/lib/Cache/Utils/index.js +16 -0
- package/lib/Cache/reactnative.d.ts +3 -0
- package/lib/Cache/reactnative.js +8 -0
- package/lib/Cache/types/Cache.d.ts +55 -0
- package/lib/Cache/types/Cache.js +4 -0
- package/lib/Cache/types/index.d.ts +1 -0
- package/lib/Cache/types/index.js +19 -0
- package/lib/ClientDevice/android.js +3 -2
- package/lib/ClientDevice/ios.d.ts +2 -2
- package/lib/ClientDevice/ios.js +3 -2
- package/lib/ClientDevice/reactnative.js +3 -2
- package/lib/Credentials.d.ts +1 -1
- package/lib/Credentials.js +2 -1
- package/lib/Errors.d.ts +19 -0
- package/lib/Errors.js +50 -1
- package/lib/Hub.js +1 -0
- package/lib/I18n/I18n.d.ts +29 -9
- package/lib/I18n/I18n.js +30 -5
- package/lib/I18n/index.d.ts +18 -5
- package/lib/I18n/index.js +35 -5
- package/lib/I18n/types.d.ts +4 -1
- package/lib/I18n/types.js +3 -0
- package/lib/JS.d.ts +6 -6
- package/lib/Logger/ConsoleLogger.d.ts +11 -11
- package/lib/OAuthHelper/GoogleOAuth.js +2 -1
- package/lib/Platform/detectFramework.js +2 -1
- package/lib/Platform/detection/Next.d.ts +1 -1
- package/lib/Platform/detection/React.js +1 -0
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/Providers/AWSCloudWatchProvider.d.ts +2 -2
- package/lib/Providers/AWSCloudWatchProvider.js +35 -12
- package/lib/RNComponents/index.d.ts +1 -1
- package/lib/RNComponents/reactnative.js +3 -2
- package/lib/ServiceWorker/ServiceWorker.d.ts +4 -4
- package/lib/ServiceWorker/ServiceWorker.js +37 -11
- package/lib/Signer.d.ts +14 -1
- package/lib/StorageHelper/cookieStorage.d.ts +13 -0
- package/lib/StorageHelper/cookieStorage.js +167 -0
- package/lib/StorageHelper/inMemoryStorage.d.ts +10 -0
- package/lib/StorageHelper/inMemoryStorage.js +82 -0
- package/lib/StorageHelper/index.d.ts +7 -3
- package/lib/StorageHelper/index.js +9 -1
- package/lib/StorageHelper/localStorage.d.ts +32 -0
- package/lib/StorageHelper/localStorage.js +114 -0
- package/lib/StorageHelper/reactnative.d.ts +71 -1
- package/lib/StorageHelper/reactnative.js +154 -10
- package/lib/StorageHelper/sessionStorage.d.ts +32 -0
- package/lib/StorageHelper/sessionStorage.js +114 -0
- package/lib/UniversalStorage/index.d.ts +2 -2
- package/lib/Util/BackgroundProcessManager.d.ts +2 -2
- package/lib/Util/BackgroundProcessManager.js +1 -0
- package/lib/Util/DateUtils.d.ts +12 -1
- package/lib/Util/Reachability.js +7 -5
- package/lib/Util/Reachability.native.d.ts +3 -2
- package/lib/Util/StringUtils.js +3 -10
- package/lib/Util/errors/AssertError.d.ts +2 -0
- package/lib/Util/errors/AssertError.js +11 -0
- package/lib/clients/middleware/retry/defaultRetryDecider.d.ts +1 -1
- package/lib/clients/middleware/retry/defaultRetryDecider.js +17 -13
- package/lib/clients/middleware/retry/isClockSkewError.js +1 -1
- package/lib/clients/middleware/retry/middleware.d.ts +1 -1
- package/lib/clients/middleware/retry/middleware.js +13 -13
- package/lib/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +1 -1
- package/lib/clients/serde/responseInfo.js +1 -1
- package/lib/clients/types/aws.d.ts +4 -0
- package/lib/clients/types/index.d.ts +1 -1
- package/lib/constants.d.ts +7 -0
- package/lib/constants.js +9 -1
- package/lib/index.d.ts +18 -4
- package/lib/index.js +32 -5
- package/lib/parseAWSExports.d.ts +1 -1
- package/lib/singleton/Auth/index.d.ts +30 -0
- package/lib/singleton/Auth/index.js +133 -0
- package/lib/singleton/Auth/types.d.ts +95 -0
- package/lib/singleton/Auth/types.js +6 -0
- package/lib/singleton/Auth/utils/index.d.ts +5 -0
- package/lib/singleton/Auth/utils/index.js +52 -0
- package/lib/singleton/Storage/types.d.ts +14 -0
- package/lib/singleton/Storage/types.js +4 -0
- package/lib/singleton/index.d.ts +46 -0
- package/lib/singleton/index.js +147 -0
- package/lib/singleton/types.d.ts +21 -0
- package/lib/singleton/types.js +4 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types.d.ts +31 -1
- package/lib/types/types.js +2 -0
- package/lib-esm/Amplify.d.ts +18 -17
- package/lib-esm/Amplify.js +9 -0
- package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +3 -10
- package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +3 -17
- package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +8 -8
- package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +3 -17
- package/lib-esm/AwsClients/Pinpoint/base.d.ts +2 -10
- package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +3 -17
- package/lib-esm/AwsClients/Pinpoint/getInAppMessages.js +1 -1
- package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +3 -17
- package/lib-esm/AwsClients/Pinpoint/putEvents.js +6 -0
- package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +3 -17
- package/lib-esm/AwsClients/Pinpoint/updateEndpoint.js +2 -2
- package/lib-esm/Cache/AsyncStorageCache.d.ts +154 -0
- package/lib-esm/Cache/AsyncStorageCache.js +737 -0
- package/lib-esm/Cache/BrowserStorageCache.d.ts +166 -0
- package/lib-esm/Cache/BrowserStorageCache.js +466 -0
- package/lib-esm/Cache/InMemoryCache.d.ts +129 -0
- package/lib-esm/Cache/InMemoryCache.js +346 -0
- package/lib-esm/Cache/StorageCache.d.ts +39 -0
- package/lib-esm/Cache/StorageCache.js +118 -0
- package/lib-esm/Cache/Utils/CacheList.d.ts +89 -0
- package/lib-esm/Cache/Utils/CacheList.js +194 -0
- package/lib-esm/Cache/Utils/CacheUtils.d.ts +25 -0
- package/lib-esm/Cache/Utils/CacheUtils.js +81 -0
- package/lib-esm/Cache/Utils/index.d.ts +2 -0
- package/lib-esm/Cache/Utils/index.js +4 -0
- package/lib-esm/Cache/reactnative.d.ts +3 -0
- package/lib-esm/Cache/reactnative.js +6 -0
- package/lib-esm/Cache/types/Cache.d.ts +55 -0
- package/lib-esm/Cache/types/Cache.js +3 -0
- package/lib-esm/Cache/types/index.d.ts +1 -0
- package/lib-esm/Cache/types/index.js +3 -0
- package/lib-esm/ClientDevice/android.js +1 -0
- package/lib-esm/ClientDevice/ios.d.ts +2 -2
- package/lib-esm/ClientDevice/ios.js +1 -0
- package/lib-esm/ClientDevice/reactnative.js +1 -0
- package/lib-esm/Credentials.d.ts +1 -1
- package/lib-esm/Credentials.js +2 -1
- package/lib-esm/Errors.d.ts +19 -0
- package/lib-esm/Errors.js +49 -0
- package/lib-esm/Hub.js +1 -0
- package/lib-esm/I18n/I18n.d.ts +29 -9
- package/lib-esm/I18n/I18n.js +30 -5
- package/lib-esm/I18n/index.d.ts +18 -5
- package/lib-esm/I18n/index.js +35 -5
- package/lib-esm/I18n/types.d.ts +4 -1
- package/lib-esm/I18n/types.js +3 -0
- package/lib-esm/JS.d.ts +6 -6
- package/lib-esm/Logger/ConsoleLogger.d.ts +11 -11
- package/lib-esm/OAuthHelper/GoogleOAuth.js +2 -1
- package/lib-esm/Platform/detectFramework.js +2 -1
- package/lib-esm/Platform/detection/Next.d.ts +1 -1
- package/lib-esm/Platform/detection/React.js +1 -0
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/Providers/AWSCloudWatchProvider.d.ts +2 -2
- package/lib-esm/Providers/AWSCloudWatchProvider.js +33 -10
- package/lib-esm/RNComponents/index.d.ts +1 -1
- package/lib-esm/RNComponents/reactnative.js +1 -0
- package/lib-esm/ServiceWorker/ServiceWorker.d.ts +4 -4
- package/lib-esm/ServiceWorker/ServiceWorker.js +37 -11
- package/lib-esm/Signer.d.ts +14 -1
- package/lib-esm/StorageHelper/cookieStorage.d.ts +13 -0
- package/lib-esm/StorageHelper/cookieStorage.js +141 -0
- package/lib-esm/StorageHelper/inMemoryStorage.d.ts +10 -0
- package/lib-esm/StorageHelper/inMemoryStorage.js +79 -0
- package/lib-esm/StorageHelper/index.d.ts +7 -3
- package/lib-esm/StorageHelper/index.js +4 -0
- package/lib-esm/StorageHelper/localStorage.d.ts +32 -0
- package/lib-esm/StorageHelper/localStorage.js +111 -0
- package/lib-esm/StorageHelper/reactnative.d.ts +71 -1
- package/lib-esm/StorageHelper/reactnative.js +153 -9
- package/lib-esm/StorageHelper/sessionStorage.d.ts +32 -0
- package/lib-esm/StorageHelper/sessionStorage.js +111 -0
- package/lib-esm/UniversalStorage/index.d.ts +2 -2
- package/lib-esm/Util/BackgroundProcessManager.d.ts +2 -2
- package/lib-esm/Util/BackgroundProcessManager.js +1 -0
- package/lib-esm/Util/DateUtils.d.ts +12 -1
- package/lib-esm/Util/Reachability.js +5 -3
- package/lib-esm/Util/Reachability.native.d.ts +3 -2
- package/lib-esm/Util/StringUtils.js +3 -10
- package/lib-esm/Util/errors/AssertError.d.ts +2 -0
- package/lib-esm/Util/errors/AssertError.js +7 -0
- package/lib-esm/clients/middleware/retry/defaultRetryDecider.d.ts +1 -1
- package/lib-esm/clients/middleware/retry/defaultRetryDecider.js +17 -13
- package/lib-esm/clients/middleware/retry/isClockSkewError.js +1 -1
- package/lib-esm/clients/middleware/retry/middleware.d.ts +1 -1
- package/lib-esm/clients/middleware/retry/middleware.js +13 -13
- package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +1 -1
- package/lib-esm/clients/serde/responseInfo.js +1 -1
- package/lib-esm/clients/types/aws.d.ts +4 -0
- package/lib-esm/clients/types/index.d.ts +1 -1
- package/lib-esm/constants.d.ts +7 -0
- package/lib-esm/constants.js +8 -0
- package/lib-esm/index.d.ts +18 -4
- package/lib-esm/index.js +15 -3
- package/lib-esm/parseAWSExports.d.ts +1 -1
- package/lib-esm/singleton/Auth/index.d.ts +30 -0
- package/lib-esm/singleton/Auth/index.js +129 -0
- package/lib-esm/singleton/Auth/types.d.ts +95 -0
- package/lib-esm/singleton/Auth/types.js +5 -0
- package/lib-esm/singleton/Auth/utils/index.d.ts +5 -0
- package/lib-esm/singleton/Auth/utils/index.js +45 -0
- package/lib-esm/singleton/Storage/types.d.ts +14 -0
- package/lib-esm/singleton/Storage/types.js +3 -0
- package/lib-esm/singleton/index.d.ts +46 -0
- package/lib-esm/singleton/index.js +143 -0
- package/lib-esm/singleton/types.d.ts +21 -0
- package/lib-esm/singleton/types.js +3 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/types.d.ts +31 -1
- package/lib-esm/types/types.js +2 -0
- package/package.json +38 -15
- package/src/Amplify.ts +9 -3
- package/src/AwsClients/CognitoIdentity/base.ts +2 -1
- package/src/AwsClients/CognitoIdentity/getCredentialsForIdentity.ts +13 -6
- package/src/AwsClients/Pinpoint/base.ts +6 -2
- package/src/AwsClients/Pinpoint/getInAppMessages.ts +1 -1
- package/src/AwsClients/Pinpoint/putEvents.ts +6 -0
- package/src/AwsClients/Pinpoint/updateEndpoint.ts +2 -2
- package/src/Cache/AsyncStorageCache.ts +500 -0
- package/src/Cache/BrowserStorageCache.ts +517 -0
- package/src/Cache/CHANGELOG.md +1227 -0
- package/src/Cache/InMemoryCache.ts +354 -0
- package/src/Cache/StorageCache.ts +157 -0
- package/src/Cache/Utils/CacheList.ts +198 -0
- package/src/Cache/Utils/CacheUtils.ts +92 -0
- package/src/Cache/Utils/index.ts +11 -0
- package/src/Cache/reactnative.ts +9 -0
- package/src/Cache/types/Cache.ts +75 -0
- package/src/Cache/types/index.ts +4 -0
- package/src/ClientDevice/android.ts +1 -1
- package/src/ClientDevice/ios.ts +2 -2
- package/src/ClientDevice/reactnative.ts +1 -1
- package/src/Credentials.ts +19 -17
- package/src/Errors.ts +41 -0
- package/src/Hub.ts +1 -0
- package/src/I18n/I18n.ts +40 -12
- package/src/I18n/index.ts +45 -12
- package/src/I18n/types.ts +3 -0
- package/src/JS.ts +24 -17
- package/src/Logger/ConsoleLogger.ts +10 -10
- package/src/OAuthHelper/FacebookOAuth.ts +2 -2
- package/src/OAuthHelper/GoogleOAuth.ts +9 -6
- package/src/Platform/detectFramework.ts +1 -1
- package/src/Platform/detection/React.ts +5 -3
- package/src/Platform/version.ts +1 -1
- package/src/Providers/AWSCloudWatchProvider.ts +39 -14
- package/src/RNComponents/index.ts +1 -1
- package/src/RNComponents/reactnative.ts +1 -1
- package/src/ServiceWorker/ServiceWorker.ts +58 -18
- package/src/Signer.ts +22 -3
- package/src/StorageHelper/cookieStorage.ts +99 -0
- package/src/StorageHelper/inMemoryStorage.ts +32 -0
- package/src/StorageHelper/index.ts +6 -1
- package/src/StorageHelper/localStorage.ts +60 -0
- package/src/StorageHelper/reactnative.ts +94 -14
- package/src/StorageHelper/sessionStorage.ts +60 -0
- package/src/Util/BackgroundProcessManager.ts +33 -9
- package/src/Util/DateUtils.ts +14 -5
- package/src/Util/Reachability.native.ts +3 -2
- package/src/Util/Reachability.ts +9 -7
- package/src/Util/Retry.ts +2 -1
- package/src/Util/StringUtils.ts +3 -10
- package/src/Util/errors/AssertError.ts +11 -0
- package/src/clients/handlers/fetch.ts +2 -2
- package/src/clients/middleware/retry/defaultRetryDecider.ts +12 -6
- package/src/clients/middleware/retry/isClockSkewError.ts +1 -1
- package/src/clients/middleware/retry/middleware.ts +9 -9
- package/src/clients/middleware/signing/middleware.ts +1 -1
- package/src/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.ts +1 -1
- package/src/clients/serde/responseInfo.ts +2 -1
- package/src/clients/types/aws.ts +10 -0
- package/src/clients/types/index.ts +1 -0
- package/src/constants.ts +16 -0
- package/src/global.d.ts +11 -0
- package/src/index.ts +66 -4
- package/src/parseAWSExports.ts +1 -1
- package/src/singleton/Auth/index.ts +113 -0
- package/src/singleton/Auth/types.ts +129 -0
- package/src/singleton/Auth/utils/index.ts +68 -0
- package/src/singleton/Storage/types.ts +21 -0
- package/src/singleton/index.ts +131 -0
- package/src/singleton/types.ts +48 -0
- package/src/types/types.ts +38 -1
package/src/JS.ts
CHANGED
|
@@ -47,7 +47,11 @@ const MIME_MAP = [
|
|
|
47
47
|
|
|
48
48
|
export const isEmpty = (obj = {}) => Object.keys(obj).length === 0;
|
|
49
49
|
|
|
50
|
-
export const sortByField = (
|
|
50
|
+
export const sortByField = (
|
|
51
|
+
list: any[],
|
|
52
|
+
field: string | number,
|
|
53
|
+
dir: string
|
|
54
|
+
) => {
|
|
51
55
|
if (!list || !list.sort) {
|
|
52
56
|
return false;
|
|
53
57
|
}
|
|
@@ -78,7 +82,10 @@ export const sortByField = (list, field, dir) => {
|
|
|
78
82
|
return true;
|
|
79
83
|
};
|
|
80
84
|
|
|
81
|
-
export const objectLessAttributes = (
|
|
85
|
+
export const objectLessAttributes = (
|
|
86
|
+
obj: Record<string, any>,
|
|
87
|
+
less: string | string[]
|
|
88
|
+
) => {
|
|
82
89
|
const ret = Object.assign({}, obj);
|
|
83
90
|
if (less) {
|
|
84
91
|
if (typeof less === 'string') {
|
|
@@ -94,7 +101,7 @@ export const objectLessAttributes = (obj, less) => {
|
|
|
94
101
|
};
|
|
95
102
|
|
|
96
103
|
export const filenameToContentType = (
|
|
97
|
-
filename,
|
|
104
|
+
filename: string,
|
|
98
105
|
defVal = 'application/octet-stream'
|
|
99
106
|
) => {
|
|
100
107
|
const name = filename.toLowerCase();
|
|
@@ -103,7 +110,7 @@ export const filenameToContentType = (
|
|
|
103
110
|
return filtered.length > 0 ? filtered[0].type : defVal;
|
|
104
111
|
};
|
|
105
112
|
|
|
106
|
-
export const isTextFile = contentType => {
|
|
113
|
+
export const isTextFile = (contentType: string) => {
|
|
107
114
|
const type = contentType.toLowerCase();
|
|
108
115
|
if (type.startsWith('text/')) {
|
|
109
116
|
return true;
|
|
@@ -125,7 +132,7 @@ export const generateRandomString = () => {
|
|
|
125
132
|
return result;
|
|
126
133
|
};
|
|
127
134
|
|
|
128
|
-
export const makeQuerablePromise = promise => {
|
|
135
|
+
export const makeQuerablePromise = (promise: any) => {
|
|
129
136
|
if (promise.isResolved) return promise;
|
|
130
137
|
|
|
131
138
|
let isPending = true;
|
|
@@ -133,12 +140,12 @@ export const makeQuerablePromise = promise => {
|
|
|
133
140
|
let isFullfilled = false;
|
|
134
141
|
|
|
135
142
|
const result = promise.then(
|
|
136
|
-
data => {
|
|
143
|
+
(data: unknown) => {
|
|
137
144
|
isFullfilled = true;
|
|
138
145
|
isPending = false;
|
|
139
146
|
return data;
|
|
140
147
|
},
|
|
141
|
-
e => {
|
|
148
|
+
(e: unknown) => {
|
|
142
149
|
isRejected = true;
|
|
143
150
|
isPending = false;
|
|
144
151
|
throw e;
|
|
@@ -156,7 +163,7 @@ export const isWebWorker = () => {
|
|
|
156
163
|
if (typeof self === 'undefined') {
|
|
157
164
|
return false;
|
|
158
165
|
}
|
|
159
|
-
const selfContext = self as { WorkerGlobalScope
|
|
166
|
+
const selfContext = self as { WorkerGlobalScope?: any };
|
|
160
167
|
return (
|
|
161
168
|
typeof selfContext.WorkerGlobalScope !== 'undefined' &&
|
|
162
169
|
self instanceof selfContext.WorkerGlobalScope
|
|
@@ -184,12 +191,12 @@ export const browserOrNode = () => {
|
|
|
184
191
|
* @param {Array} whiteListForChildren - whitelist its children keys from being transferred
|
|
185
192
|
*/
|
|
186
193
|
export const transferKeyToLowerCase = (
|
|
187
|
-
obj,
|
|
188
|
-
whiteListForItself = [],
|
|
189
|
-
whiteListForChildren = []
|
|
194
|
+
obj: Record<string, any>,
|
|
195
|
+
whiteListForItself: string[] = [],
|
|
196
|
+
whiteListForChildren: string[] = []
|
|
190
197
|
) => {
|
|
191
198
|
if (!isStrictObject(obj)) return obj;
|
|
192
|
-
const ret = {};
|
|
199
|
+
const ret: Record<string, any> = {};
|
|
193
200
|
|
|
194
201
|
for (const key in obj) {
|
|
195
202
|
if (obj.hasOwnProperty(key)) {
|
|
@@ -217,12 +224,12 @@ export const transferKeyToLowerCase = (
|
|
|
217
224
|
* @param {Array} whiteListForChildren - whitelist its children keys from being transferred
|
|
218
225
|
*/
|
|
219
226
|
export const transferKeyToUpperCase = (
|
|
220
|
-
obj,
|
|
221
|
-
whiteListForItself = [],
|
|
222
|
-
whiteListForChildren = []
|
|
227
|
+
obj: Record<string, any>,
|
|
228
|
+
whiteListForItself: string[] = [],
|
|
229
|
+
whiteListForChildren: string[] = []
|
|
223
230
|
) => {
|
|
224
231
|
if (!isStrictObject(obj)) return obj;
|
|
225
|
-
const ret = {};
|
|
232
|
+
const ret: Record<string, any> = {};
|
|
226
233
|
|
|
227
234
|
for (const key in obj) {
|
|
228
235
|
if (obj.hasOwnProperty(key)) {
|
|
@@ -247,7 +254,7 @@ export const transferKeyToUpperCase = (
|
|
|
247
254
|
* which means it's not Array, Function, Number, String, Boolean or Null
|
|
248
255
|
* @param obj the Object
|
|
249
256
|
*/
|
|
250
|
-
export const isStrictObject = obj => {
|
|
257
|
+
export const isStrictObject = (obj: any) => {
|
|
251
258
|
return (
|
|
252
259
|
obj instanceof Object &&
|
|
253
260
|
!(obj instanceof Array) &&
|
|
@@ -6,7 +6,7 @@ import { LoggingProvider } from '../types';
|
|
|
6
6
|
import { AWS_CLOUDWATCH_CATEGORY } from '../Util/Constants';
|
|
7
7
|
import { Logger } from './logger-interface';
|
|
8
8
|
|
|
9
|
-
const LOG_LEVELS = {
|
|
9
|
+
const LOG_LEVELS: Record<string, number> = {
|
|
10
10
|
VERBOSE: 1,
|
|
11
11
|
DEBUG: 2,
|
|
12
12
|
INFO: 3,
|
|
@@ -30,7 +30,7 @@ export class ConsoleLogger implements Logger {
|
|
|
30
30
|
name: string;
|
|
31
31
|
level: LOG_TYPE | string;
|
|
32
32
|
private _pluggables: LoggingProvider[];
|
|
33
|
-
private _config
|
|
33
|
+
private _config?: object;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* @constructor
|
|
@@ -44,7 +44,7 @@ export class ConsoleLogger implements Logger {
|
|
|
44
44
|
|
|
45
45
|
static LOG_LEVEL = null;
|
|
46
46
|
|
|
47
|
-
_padding(n) {
|
|
47
|
+
_padding(n: number) {
|
|
48
48
|
return n < 10 ? '0' + n : '' + n;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -74,7 +74,7 @@ export class ConsoleLogger implements Logger {
|
|
|
74
74
|
* @param {LOG_TYPE|string} type - log type, default INFO
|
|
75
75
|
* @param {string|object} msg - Logging message or object
|
|
76
76
|
*/
|
|
77
|
-
_log(type: LOG_TYPE | string, ...msg) {
|
|
77
|
+
_log(type: LOG_TYPE | string, ...msg: any) {
|
|
78
78
|
let logger_level_name = this.level;
|
|
79
79
|
if (ConsoleLogger.LOG_LEVEL) {
|
|
80
80
|
logger_level_name = ConsoleLogger.LOG_LEVEL;
|
|
@@ -130,7 +130,7 @@ export class ConsoleLogger implements Logger {
|
|
|
130
130
|
* @memeberof Logger
|
|
131
131
|
* @param {string|object} msg - Logging message or object
|
|
132
132
|
*/
|
|
133
|
-
log(...msg) {
|
|
133
|
+
log(...msg: any) {
|
|
134
134
|
this._log(LOG_TYPE.INFO, ...msg);
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -140,7 +140,7 @@ export class ConsoleLogger implements Logger {
|
|
|
140
140
|
* @memeberof Logger
|
|
141
141
|
* @param {string|object} msg - Logging message or object
|
|
142
142
|
*/
|
|
143
|
-
info(...msg) {
|
|
143
|
+
info(...msg: any) {
|
|
144
144
|
this._log(LOG_TYPE.INFO, ...msg);
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -150,7 +150,7 @@ export class ConsoleLogger implements Logger {
|
|
|
150
150
|
* @memeberof Logger
|
|
151
151
|
* @param {string|object} msg - Logging message or object
|
|
152
152
|
*/
|
|
153
|
-
warn(...msg) {
|
|
153
|
+
warn(...msg: any) {
|
|
154
154
|
this._log(LOG_TYPE.WARN, ...msg);
|
|
155
155
|
}
|
|
156
156
|
|
|
@@ -160,7 +160,7 @@ export class ConsoleLogger implements Logger {
|
|
|
160
160
|
* @memeberof Logger
|
|
161
161
|
* @param {string|object} msg - Logging message or object
|
|
162
162
|
*/
|
|
163
|
-
error(...msg) {
|
|
163
|
+
error(...msg: any) {
|
|
164
164
|
this._log(LOG_TYPE.ERROR, ...msg);
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -170,7 +170,7 @@ export class ConsoleLogger implements Logger {
|
|
|
170
170
|
* @memeberof Logger
|
|
171
171
|
* @param {string|object} msg - Logging message or object
|
|
172
172
|
*/
|
|
173
|
-
debug(...msg) {
|
|
173
|
+
debug(...msg: any) {
|
|
174
174
|
this._log(LOG_TYPE.DEBUG, ...msg);
|
|
175
175
|
}
|
|
176
176
|
|
|
@@ -180,7 +180,7 @@ export class ConsoleLogger implements Logger {
|
|
|
180
180
|
* @memeberof Logger
|
|
181
181
|
* @param {string|object} msg - Logging message or object
|
|
182
182
|
*/
|
|
183
|
-
verbose(...msg) {
|
|
183
|
+
verbose(...msg: any) {
|
|
184
184
|
this._log(LOG_TYPE.VERBOSE, ...msg);
|
|
185
185
|
}
|
|
186
186
|
|
|
@@ -42,7 +42,7 @@ export class FacebookOAuth {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
private _refreshFacebookTokenImpl() {
|
|
45
|
-
let fb = null;
|
|
45
|
+
let fb: any = null;
|
|
46
46
|
if (browserOrNode().isBrowser) fb = window['FB'];
|
|
47
47
|
if (!fb) {
|
|
48
48
|
const errorMessage = 'no fb sdk available';
|
|
@@ -52,7 +52,7 @@ export class FacebookOAuth {
|
|
|
52
52
|
|
|
53
53
|
return new Promise((res, rej) => {
|
|
54
54
|
fb.getLoginStatus(
|
|
55
|
-
fbResponse => {
|
|
55
|
+
(fbResponse: any) => {
|
|
56
56
|
if (!fbResponse || !fbResponse.authResponse) {
|
|
57
57
|
const errorMessage =
|
|
58
58
|
'no response from facebook when refreshing the jwt token';
|
|
@@ -43,7 +43,7 @@ export class GoogleOAuth {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
private _refreshGoogleTokenImpl() {
|
|
46
|
-
let ga = null;
|
|
46
|
+
let ga: any = null;
|
|
47
47
|
if (browserOrNode().isBrowser)
|
|
48
48
|
ga = window['gapi'] && window['gapi'].auth2 ? window['gapi'].auth2 : null;
|
|
49
49
|
if (!ga) {
|
|
@@ -53,7 +53,7 @@ export class GoogleOAuth {
|
|
|
53
53
|
|
|
54
54
|
return new Promise((res, rej) => {
|
|
55
55
|
ga.getAuthInstance()
|
|
56
|
-
.then(googleAuth => {
|
|
56
|
+
.then((googleAuth: any) => {
|
|
57
57
|
if (!googleAuth) {
|
|
58
58
|
logger.debug('google Auth undefined');
|
|
59
59
|
rej(new NonRetryableError('google Auth undefined'));
|
|
@@ -65,12 +65,15 @@ export class GoogleOAuth {
|
|
|
65
65
|
logger.debug('refreshing the google access token');
|
|
66
66
|
googleUser
|
|
67
67
|
.reloadAuthResponse()
|
|
68
|
-
.then(authResponse => {
|
|
68
|
+
.then((authResponse: any) => {
|
|
69
69
|
const { id_token, expires_at } = authResponse;
|
|
70
70
|
res({ token: id_token, expires_at });
|
|
71
71
|
})
|
|
72
|
-
.catch(err => {
|
|
73
|
-
if (
|
|
72
|
+
.catch((err: unknown) => {
|
|
73
|
+
if (
|
|
74
|
+
err &&
|
|
75
|
+
(err as { error: string }).error === 'network_error'
|
|
76
|
+
) {
|
|
74
77
|
// Not using NonRetryableError so handler will be retried
|
|
75
78
|
rej('Network error reloading google auth response');
|
|
76
79
|
} else {
|
|
@@ -85,7 +88,7 @@ export class GoogleOAuth {
|
|
|
85
88
|
rej(new NonRetryableError('User is not signed in with Google'));
|
|
86
89
|
}
|
|
87
90
|
})
|
|
88
|
-
.catch(err => {
|
|
91
|
+
.catch((err: unknown) => {
|
|
89
92
|
logger.debug('Failed to refresh google token', err);
|
|
90
93
|
rej(new NonRetryableError('Failed to refresh google token'));
|
|
91
94
|
});
|
|
@@ -25,7 +25,7 @@ export const detectFramework = (): Framework => {
|
|
|
25
25
|
// So we don't need to notify the observers again so the observer
|
|
26
26
|
// can be removed after the final notice.
|
|
27
27
|
while (frameworkChangeObservers.length) {
|
|
28
|
-
frameworkChangeObservers.pop()();
|
|
28
|
+
frameworkChangeObservers.pop()?.();
|
|
29
29
|
}
|
|
30
30
|
} else {
|
|
31
31
|
// The first run of detectFramework:
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { documentExists, processExists
|
|
4
|
+
import { documentExists, processExists } from './helpers';
|
|
5
5
|
|
|
6
6
|
// Tested with react 18.2 - built using Vite
|
|
7
7
|
|
|
8
8
|
export function reactWebDetect() {
|
|
9
|
-
const elementKeyPrefixedWithReact = key => {
|
|
9
|
+
const elementKeyPrefixedWithReact = (key: string) => {
|
|
10
10
|
return key.startsWith('_react') || key.startsWith('__react');
|
|
11
11
|
};
|
|
12
|
-
const elementIsReactEnabled = element => {
|
|
12
|
+
const elementIsReactEnabled = (element: Element) => {
|
|
13
13
|
return Object.keys(element).find(elementKeyPrefixedWithReact);
|
|
14
14
|
};
|
|
15
15
|
const allElementsWithId = () => Array.from(document.querySelectorAll('[id]'));
|
|
@@ -24,3 +24,5 @@ export function reactSSRDetect() {
|
|
|
24
24
|
!!Object.keys(process.env).find(key => key.includes('react'))
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
// use the some
|
package/src/Platform/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '6.0.1-console-preview.f63250a.0+f63250a';
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
CloudWatchDataTracker,
|
|
31
31
|
LoggingProvider,
|
|
32
32
|
} from '../types/types';
|
|
33
|
-
import { Credentials } from '
|
|
33
|
+
import { Credentials } from '../Credentials';
|
|
34
34
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
35
35
|
import { getAmplifyUserAgentObject } from '../Platform';
|
|
36
36
|
import { parseAWSExports } from '../parseAWSExports';
|
|
@@ -43,6 +43,8 @@ import {
|
|
|
43
43
|
NO_CREDS_ERROR_STRING,
|
|
44
44
|
RETRY_ERROR_CODES,
|
|
45
45
|
} from '../Util/Constants';
|
|
46
|
+
import { asserts } from '../Util/errors/AssertError';
|
|
47
|
+
import { AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION } from '../constants';
|
|
46
48
|
|
|
47
49
|
const logger = new Logger('AWSCloudWatch');
|
|
48
50
|
|
|
@@ -50,10 +52,10 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
50
52
|
static readonly PROVIDER_NAME = AWS_CLOUDWATCH_PROVIDER_NAME;
|
|
51
53
|
static readonly CATEGORY = AWS_CLOUDWATCH_CATEGORY;
|
|
52
54
|
|
|
53
|
-
private _config
|
|
55
|
+
private _config?: AWSCloudWatchProviderOptions;
|
|
54
56
|
private _dataTracker: CloudWatchDataTracker;
|
|
55
57
|
private _currentLogBatch: InputLogEvent[];
|
|
56
|
-
private _timer;
|
|
58
|
+
private _timer?: NodeJS.Timer;
|
|
57
59
|
private _nextSequenceToken: string | undefined;
|
|
58
60
|
|
|
59
61
|
constructor(config?: AWSCloudWatchProviderOptions) {
|
|
@@ -213,7 +215,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
213
215
|
|
|
214
216
|
private async _validateLogGroupExistsAndCreate(
|
|
215
217
|
logGroupName: string
|
|
216
|
-
): Promise<LogGroup> {
|
|
218
|
+
): Promise<LogGroup | null> {
|
|
217
219
|
if (this._dataTracker.verifiedLogGroup) {
|
|
218
220
|
return this._dataTracker.verifiedLogGroup;
|
|
219
221
|
}
|
|
@@ -256,7 +258,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
256
258
|
private async _validateLogStreamExists(
|
|
257
259
|
logGroupName: string,
|
|
258
260
|
logStreamName: string
|
|
259
|
-
): Promise<LogStream> {
|
|
261
|
+
): Promise<LogStream | null> {
|
|
260
262
|
try {
|
|
261
263
|
const credentialsOK = await this._ensureCredentials();
|
|
262
264
|
if (!credentialsOK) {
|
|
@@ -298,7 +300,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
298
300
|
|
|
299
301
|
private async _sendLogEvents(
|
|
300
302
|
params: PutLogEventsCommandInput
|
|
301
|
-
): Promise<PutLogEventsCommandOutput> {
|
|
303
|
+
): Promise<PutLogEventsCommandOutput | undefined> {
|
|
302
304
|
try {
|
|
303
305
|
const credentialsOK = await this._ensureCredentials();
|
|
304
306
|
if (!credentialsOK) {
|
|
@@ -318,6 +320,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
318
320
|
}
|
|
319
321
|
|
|
320
322
|
private _initCloudWatchLogs() {
|
|
323
|
+
assertsAWSClouldWatchOptions(this._config);
|
|
321
324
|
return new CloudWatchLogsClient({
|
|
322
325
|
region: this._config.region,
|
|
323
326
|
credentials: this._config.credentials,
|
|
@@ -328,7 +331,8 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
328
331
|
|
|
329
332
|
private async _ensureCredentials() {
|
|
330
333
|
return await Credentials.get()
|
|
331
|
-
.then(credentials => {
|
|
334
|
+
.then((credentials: any) => {
|
|
335
|
+
assertsAWSClouldWatchOptions(this._config);
|
|
332
336
|
if (!credentials) return false;
|
|
333
337
|
const cred = Credentials.shear(credentials);
|
|
334
338
|
logger.debug('set credentials for logging', cred);
|
|
@@ -336,13 +340,14 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
336
340
|
|
|
337
341
|
return true;
|
|
338
342
|
})
|
|
339
|
-
.catch(error => {
|
|
343
|
+
.catch((error: unknown) => {
|
|
340
344
|
logger.warn('ensure credentials error', error);
|
|
341
345
|
return false;
|
|
342
346
|
});
|
|
343
347
|
}
|
|
344
348
|
|
|
345
|
-
private async _getNextSequenceToken(): Promise<string> {
|
|
349
|
+
private async _getNextSequenceToken(): Promise<string | undefined> {
|
|
350
|
+
assertsAWSClouldWatchOptions(this._config);
|
|
346
351
|
if (this._nextSequenceToken && this._nextSequenceToken.length > 0) {
|
|
347
352
|
return this._nextSequenceToken;
|
|
348
353
|
}
|
|
@@ -354,6 +359,14 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
354
359
|
* ...the log stream does exist but has no logs written to it yet
|
|
355
360
|
*/
|
|
356
361
|
try {
|
|
362
|
+
asserts(this._config.logGroupName !== undefined, {
|
|
363
|
+
name: AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION,
|
|
364
|
+
message: ' log group name is undefined',
|
|
365
|
+
});
|
|
366
|
+
asserts(this._config.logStreamName !== undefined, {
|
|
367
|
+
name: AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION,
|
|
368
|
+
message: ' log stream name is undefined',
|
|
369
|
+
});
|
|
357
370
|
await this._validateLogGroupExistsAndCreate(this._config.logGroupName);
|
|
358
371
|
|
|
359
372
|
this._nextSequenceToken = undefined;
|
|
@@ -374,7 +387,10 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
374
387
|
}
|
|
375
388
|
}
|
|
376
389
|
|
|
377
|
-
private async _safeUploadLogEvents(): Promise<
|
|
390
|
+
private async _safeUploadLogEvents(): Promise<
|
|
391
|
+
PutLogEventsCommandOutput | undefined
|
|
392
|
+
> {
|
|
393
|
+
assertsAWSClouldWatchOptions(this._config);
|
|
378
394
|
try {
|
|
379
395
|
/**
|
|
380
396
|
* CloudWatch has restrictions on the size of the log events that get sent up.
|
|
@@ -400,7 +416,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
400
416
|
this._dataTracker.eventUploadInProgress = true;
|
|
401
417
|
const sendLogEventsResponse = await this._sendLogEvents(putLogsPayload);
|
|
402
418
|
|
|
403
|
-
this._nextSequenceToken = sendLogEventsResponse
|
|
419
|
+
this._nextSequenceToken = sendLogEventsResponse?.nextSequenceToken;
|
|
404
420
|
this._dataTracker.eventUploadInProgress = false;
|
|
405
421
|
this._currentLogBatch = [];
|
|
406
422
|
|
|
@@ -408,7 +424,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
408
424
|
} catch (err) {
|
|
409
425
|
logger.error(`error during _safeUploadLogEvents: ${err}`);
|
|
410
426
|
|
|
411
|
-
if (RETRY_ERROR_CODES.includes(err.name)) {
|
|
427
|
+
if (err instanceof Error && RETRY_ERROR_CODES.includes(err.name)) {
|
|
412
428
|
this._getNewSequenceTokenAndSubmit({
|
|
413
429
|
logEvents: this._currentLogBatch,
|
|
414
430
|
logGroupName: this._config.logGroupName,
|
|
@@ -443,7 +459,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
443
459
|
const errString = `Log entry exceeds maximum size for CloudWatch logs. Log size: ${eventSize}. Truncating log message.`;
|
|
444
460
|
logger.warn(errString);
|
|
445
461
|
|
|
446
|
-
currentEvent.message = currentEvent.message
|
|
462
|
+
currentEvent.message = currentEvent.message?.substring(0, eventSize);
|
|
447
463
|
}
|
|
448
464
|
|
|
449
465
|
if (totalByteSize + eventSize > AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE)
|
|
@@ -462,7 +478,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
462
478
|
|
|
463
479
|
private async _getNewSequenceTokenAndSubmit(
|
|
464
480
|
payload: PutLogEventsCommandInput
|
|
465
|
-
): Promise<PutLogEventsCommandOutput> {
|
|
481
|
+
): Promise<PutLogEventsCommandOutput | undefined> {
|
|
466
482
|
try {
|
|
467
483
|
this._nextSequenceToken = undefined;
|
|
468
484
|
this._dataTracker.eventUploadInProgress = true;
|
|
@@ -512,4 +528,13 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
512
528
|
}
|
|
513
529
|
}
|
|
514
530
|
|
|
531
|
+
function assertsAWSClouldWatchOptions(
|
|
532
|
+
options?: AWSCloudWatchProviderOptions
|
|
533
|
+
): asserts options {
|
|
534
|
+
return asserts(options !== undefined, {
|
|
535
|
+
name: AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION,
|
|
536
|
+
message: 'AWSCloudWatchProviderOptions cannot be undefined',
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
|
|
515
540
|
export { AWSCloudWatchProvider };
|
|
@@ -6,7 +6,7 @@ import { StorageHelper } from '../StorageHelper';
|
|
|
6
6
|
|
|
7
7
|
export const Linking = {};
|
|
8
8
|
export const AppState = {
|
|
9
|
-
addEventListener: (action, handler) => undefined,
|
|
9
|
+
addEventListener: (action: any, handler: any) => undefined,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
// if not in react native, just use local storage
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
3
|
+
// @ts-ignore
|
|
4
4
|
import { Linking, AppState } from 'react-native';
|
|
5
5
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
6
6
|
export { Linking, AppState, AsyncStorage };
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
16
16
|
import { browserOrNode } from '../JS';
|
|
17
17
|
import { Amplify } from '../Amplify';
|
|
18
|
+
import { asserts } from '../Util/errors/AssertError';
|
|
19
|
+
import { AmplifyError } from '../Errors';
|
|
20
|
+
import { SERVICE_WORKER_EXCEPTION } from '../constants';
|
|
18
21
|
/**
|
|
19
22
|
* Provides a means to registering a service worker in the browser
|
|
20
23
|
* and communicating with it via postMessage events.
|
|
@@ -29,17 +32,17 @@ import { Amplify } from '../Amplify';
|
|
|
29
32
|
*/
|
|
30
33
|
export class ServiceWorkerClass {
|
|
31
34
|
// The active service worker will be set once it is registered
|
|
32
|
-
private _serviceWorker
|
|
35
|
+
private _serviceWorker?: ServiceWorker;
|
|
33
36
|
|
|
34
37
|
// The service worker registration object
|
|
35
|
-
private _registration
|
|
38
|
+
private _registration?: ServiceWorkerRegistration;
|
|
36
39
|
|
|
37
40
|
// The application server public key for Push
|
|
38
41
|
// https://web-push-codelab.glitch.me/
|
|
39
|
-
private _publicKey
|
|
42
|
+
private _publicKey?: string;
|
|
40
43
|
|
|
41
44
|
// push subscription
|
|
42
|
-
private _subscription
|
|
45
|
+
private _subscription?: PushSubscription;
|
|
43
46
|
|
|
44
47
|
// The AWS Amplify logger
|
|
45
48
|
private _logger: Logger = new Logger('ServiceWorker');
|
|
@@ -50,6 +53,11 @@ export class ServiceWorkerClass {
|
|
|
50
53
|
* Get the currently active service worker
|
|
51
54
|
*/
|
|
52
55
|
get serviceWorker(): ServiceWorker {
|
|
56
|
+
asserts(this._serviceWorker !== undefined, {
|
|
57
|
+
name: SERVICE_WORKER_EXCEPTION,
|
|
58
|
+
message: 'Service Worker instance is undefined',
|
|
59
|
+
});
|
|
60
|
+
|
|
53
61
|
return this._serviceWorker;
|
|
54
62
|
}
|
|
55
63
|
|
|
@@ -91,10 +99,21 @@ export class ServiceWorkerClass {
|
|
|
91
99
|
})
|
|
92
100
|
.catch(error => {
|
|
93
101
|
this._logger.debug(`Service Worker Registration Failed ${error}`);
|
|
94
|
-
return reject(
|
|
102
|
+
return reject(
|
|
103
|
+
new AmplifyError({
|
|
104
|
+
name: SERVICE_WORKER_EXCEPTION,
|
|
105
|
+
message: 'Service Worker not available',
|
|
106
|
+
underlyingError: error,
|
|
107
|
+
})
|
|
108
|
+
);
|
|
95
109
|
});
|
|
96
110
|
} else {
|
|
97
|
-
return reject(
|
|
111
|
+
return reject(
|
|
112
|
+
new AmplifyError({
|
|
113
|
+
name: SERVICE_WORKER_EXCEPTION,
|
|
114
|
+
message: 'Service Worker not available',
|
|
115
|
+
})
|
|
116
|
+
);
|
|
98
117
|
}
|
|
99
118
|
});
|
|
100
119
|
}
|
|
@@ -111,10 +130,17 @@ export class ServiceWorkerClass {
|
|
|
111
130
|
* - reject(Error)
|
|
112
131
|
*/
|
|
113
132
|
enablePush(publicKey: string) {
|
|
114
|
-
|
|
133
|
+
asserts(this._registration !== undefined, {
|
|
134
|
+
name: SERVICE_WORKER_EXCEPTION,
|
|
135
|
+
message: 'Service Worker registration is undefined',
|
|
136
|
+
});
|
|
115
137
|
this._publicKey = publicKey;
|
|
116
138
|
return new Promise((resolve, reject) => {
|
|
117
139
|
if (browserOrNode().isBrowser) {
|
|
140
|
+
asserts(this._registration !== undefined, {
|
|
141
|
+
name: SERVICE_WORKER_EXCEPTION,
|
|
142
|
+
message: 'Service Worker registration is undefined',
|
|
143
|
+
});
|
|
118
144
|
this._registration.pushManager.getSubscription().then(subscription => {
|
|
119
145
|
if (subscription) {
|
|
120
146
|
this._subscription = subscription;
|
|
@@ -124,11 +150,10 @@ export class ServiceWorkerClass {
|
|
|
124
150
|
resolve(subscription);
|
|
125
151
|
} else {
|
|
126
152
|
this._logger.debug(`User is NOT subscribed to push`);
|
|
127
|
-
return this._registration.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
})
|
|
153
|
+
return this._registration!.pushManager.subscribe({
|
|
154
|
+
userVisibleOnly: true,
|
|
155
|
+
applicationServerKey: this._urlB64ToUint8Array(publicKey),
|
|
156
|
+
})
|
|
132
157
|
.then(subscription => {
|
|
133
158
|
this._subscription = subscription;
|
|
134
159
|
this._logger.debug(
|
|
@@ -142,7 +167,12 @@ export class ServiceWorkerClass {
|
|
|
142
167
|
}
|
|
143
168
|
});
|
|
144
169
|
} else {
|
|
145
|
-
return reject(
|
|
170
|
+
return reject(
|
|
171
|
+
new AmplifyError({
|
|
172
|
+
name: SERVICE_WORKER_EXCEPTION,
|
|
173
|
+
message: 'Service Worker not available',
|
|
174
|
+
})
|
|
175
|
+
);
|
|
146
176
|
}
|
|
147
177
|
});
|
|
148
178
|
}
|
|
@@ -187,11 +217,12 @@ export class ServiceWorkerClass {
|
|
|
187
217
|
* https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/state
|
|
188
218
|
**/
|
|
189
219
|
_setupListeners() {
|
|
190
|
-
this.
|
|
191
|
-
const currentState = this.
|
|
220
|
+
this.serviceWorker.addEventListener('statechange', event => {
|
|
221
|
+
const currentState = this.serviceWorker.state;
|
|
192
222
|
this._logger.debug(`ServiceWorker statechange: ${currentState}`);
|
|
193
|
-
|
|
194
|
-
|
|
223
|
+
Amplify.Analytics;
|
|
224
|
+
if (isAmplifyWithAnalytics(Amplify)) {
|
|
225
|
+
(Amplify as AmplifyWithAnalytics).Analytics.record({
|
|
195
226
|
name: 'ServiceWorker',
|
|
196
227
|
attributes: {
|
|
197
228
|
state: currentState,
|
|
@@ -199,8 +230,17 @@ export class ServiceWorkerClass {
|
|
|
199
230
|
});
|
|
200
231
|
}
|
|
201
232
|
});
|
|
202
|
-
this.
|
|
233
|
+
this.serviceWorker.addEventListener('message', event => {
|
|
203
234
|
this._logger.debug(`ServiceWorker message event: ${event}`);
|
|
204
235
|
});
|
|
205
236
|
}
|
|
206
237
|
}
|
|
238
|
+
|
|
239
|
+
type AmplifyWithAnalytics = {
|
|
240
|
+
Analytics: {
|
|
241
|
+
record: Function;
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
function isAmplifyWithAnalytics(amplify: any): amplify is AmplifyWithAnalytics {
|
|
245
|
+
return amplify.Analytics && typeof amplify.Analytics.record === 'function';
|
|
246
|
+
}
|
package/src/Signer.ts
CHANGED
|
@@ -49,7 +49,21 @@ export class Signer {
|
|
|
49
49
|
*
|
|
50
50
|
* @returns {object} Signed HTTP request
|
|
51
51
|
*/
|
|
52
|
-
static sign(
|
|
52
|
+
static sign(
|
|
53
|
+
request: {
|
|
54
|
+
headers: any;
|
|
55
|
+
body?: BodyInit;
|
|
56
|
+
data?: any;
|
|
57
|
+
url: string;
|
|
58
|
+
method: string;
|
|
59
|
+
},
|
|
60
|
+
accessInfo: {
|
|
61
|
+
access_key: string;
|
|
62
|
+
secret_key: string;
|
|
63
|
+
session_token: string;
|
|
64
|
+
},
|
|
65
|
+
serviceInfo: { service: string; region: string }
|
|
66
|
+
) {
|
|
53
67
|
request.headers = request.headers || {};
|
|
54
68
|
|
|
55
69
|
if (request.body && !request.data) {
|
|
@@ -61,7 +75,7 @@ export class Signer {
|
|
|
61
75
|
const requestToSign = {
|
|
62
76
|
...request,
|
|
63
77
|
body: request.data,
|
|
64
|
-
url: new URL(request.url
|
|
78
|
+
url: new URL(request.url),
|
|
65
79
|
};
|
|
66
80
|
|
|
67
81
|
const options = getOptions(requestToSign, accessInfo, serviceInfo);
|
|
@@ -130,7 +144,12 @@ export class Signer {
|
|
|
130
144
|
}
|
|
131
145
|
}
|
|
132
146
|
|
|
133
|
-
const getOptions = (
|
|
147
|
+
const getOptions = (
|
|
148
|
+
request: { url: URL } & Record<string, any>,
|
|
149
|
+
accessInfo: { access_key: string; secret_key: string; session_token: string },
|
|
150
|
+
serviceInfo: { service: string; region: string },
|
|
151
|
+
expiration?: number
|
|
152
|
+
) => {
|
|
134
153
|
const { access_key, secret_key, session_token } = accessInfo ?? {};
|
|
135
154
|
const { region: urlRegion, service: urlService } = parseServiceInfo(
|
|
136
155
|
request.url
|