@aws-amplify/core 6.0.1-console-preview.67f944e.0 → 6.0.1-console-preview.0bbe168.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/AwsClients/Pinpoint/getInAppMessages.d.ts +1 -1
- package/lib/AwsClients/Pinpoint/putEvents.d.ts +1 -1
- package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +1 -1
- package/lib/BackgroundProcessManager/BackgroundManagerNotOpenError.d.ts +3 -0
- package/lib/BackgroundProcessManager/BackgroundManagerNotOpenError.js +28 -0
- package/{lib-esm/Util → lib/BackgroundProcessManager}/BackgroundProcessManager.d.ts +1 -23
- package/lib/{Util → BackgroundProcessManager}/BackgroundProcessManager.js +13 -56
- package/lib/BackgroundProcessManager/index.d.ts +1 -0
- package/lib/BackgroundProcessManager/index.js +7 -0
- package/lib/BackgroundProcessManager/types.d.ts +41 -0
- package/lib/BackgroundProcessManager/types.js +23 -0
- package/lib/Hub/index.js +2 -2
- package/lib/Logger/ConsoleLogger.js +2 -2
- package/lib/{Util → Mutex}/Mutex.d.ts +2 -15
- package/lib/{Util → Mutex}/Mutex.js +2 -1
- package/lib/Mutex/index.d.ts +1 -0
- package/lib/Mutex/index.js +7 -0
- package/lib/Mutex/types.d.ts +13 -0
- package/lib/Mutex/types.js +4 -0
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/Reachability/Reachability.d.ts +6 -0
- package/lib/Reachability/Reachability.js +29 -0
- package/lib/Reachability/Reachability.native.d.ts +6 -0
- package/lib/{Util → Reachability}/Reachability.native.js +8 -10
- package/lib/Reachability/index.d.ts +1 -0
- package/lib/Reachability/index.js +7 -0
- package/lib/Reachability/types.d.ts +3 -0
- package/lib/Reachability/types.js +4 -0
- package/lib/ServiceWorker/ServiceWorker.js +2 -2
- package/lib/{Signer.js → Signer/Signer.js} +3 -3
- package/lib/Signer/index.d.ts +1 -0
- package/lib/Signer/index.js +7 -0
- package/lib/clients/middleware/retry/jitteredBackoff.js +2 -2
- package/lib/{Util/Constants.d.ts → constants.d.ts} +0 -2
- package/lib/{Util/Constants.js → constants.js} +1 -6
- package/lib/libraryUtils.d.ts +7 -6
- package/lib/libraryUtils.js +37 -49
- package/lib/providers/pinpoint/apis/updateEndpoint.d.ts +1 -1
- package/lib/providers/pinpoint/apis/updateEndpoint.js +7 -5
- package/lib/providers/pinpoint/types/pinpoint.d.ts +1 -0
- package/lib/singleton/Auth/utils/index.js +2 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/core.d.ts +4 -1
- package/lib/utils/convert/base64/base64Decoder.d.ts +2 -0
- package/lib/utils/convert/base64/base64Decoder.js +11 -0
- package/lib/utils/convert/base64/base64Encoder.d.ts +2 -0
- package/lib/utils/convert/base64/base64Encoder.js +18 -0
- package/lib/utils/convert/base64/bytesToString.d.ts +1 -0
- package/lib/utils/convert/base64/bytesToString.js +9 -0
- package/lib/utils/convert/index.d.ts +2 -0
- package/lib/utils/convert/index.js +9 -0
- package/lib/utils/convert/types.d.ts +9 -0
- package/lib/utils/convert/types.js +4 -0
- package/lib/utils/generateRandomString.d.ts +1 -0
- package/lib/utils/generateRandomString.js +14 -0
- package/lib/utils/globalHelpers/index.d.ts +3 -0
- package/lib/utils/globalHelpers/index.js +50 -0
- package/lib/utils/globalHelpers/index.native.d.ts +5 -0
- package/lib/utils/globalHelpers/index.native.js +27 -0
- package/lib/utils/index.d.ts +6 -0
- package/lib/utils/index.js +21 -0
- package/lib/utils/isBrowser.d.ts +1 -0
- package/lib/utils/isBrowser.js +9 -0
- package/lib/utils/isWebWorker.d.ts +1 -0
- package/lib/utils/isWebWorker.js +14 -0
- package/lib/utils/retry/NonRetryableError.d.ts +4 -0
- package/lib/utils/retry/NonRetryableError.js +30 -0
- package/lib/utils/retry/constants.d.ts +1 -0
- package/lib/utils/retry/constants.js +6 -0
- package/lib/utils/retry/index.d.ts +5 -0
- package/lib/utils/retry/index.js +15 -0
- package/lib/utils/retry/isNonRetryableError.d.ts +2 -0
- package/lib/utils/retry/isNonRetryableError.js +10 -0
- package/lib/utils/retry/jitteredBackoff.d.ts +6 -0
- package/lib/utils/retry/jitteredBackoff.js +20 -0
- package/lib/utils/retry/jitteredExponentialRetry.d.ts +5 -0
- package/lib/utils/retry/jitteredExponentialRetry.js +17 -0
- package/lib/utils/retry/retry.d.ts +6 -0
- package/lib/{Util/Retry.js → utils/retry/retry.js} +6 -57
- package/lib/utils/urlSafeDecode.d.ts +1 -0
- package/lib/{Util/StringUtils.js → utils/urlSafeDecode.js} +2 -9
- package/lib/utils/urlSafeEncode.d.ts +1 -0
- package/lib/utils/urlSafeEncode.js +12 -0
- package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +1 -1
- package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +1 -1
- package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +1 -1
- package/lib-esm/BackgroundProcessManager/BackgroundManagerNotOpenError.d.ts +3 -0
- package/lib-esm/BackgroundProcessManager/BackgroundManagerNotOpenError.js +25 -0
- package/{lib/Util → lib-esm/BackgroundProcessManager}/BackgroundProcessManager.d.ts +1 -23
- package/lib-esm/{Util → BackgroundProcessManager}/BackgroundProcessManager.js +4 -47
- package/lib-esm/BackgroundProcessManager/index.d.ts +1 -0
- package/lib-esm/BackgroundProcessManager/index.js +3 -0
- package/lib-esm/BackgroundProcessManager/types.d.ts +41 -0
- package/lib-esm/BackgroundProcessManager/types.js +20 -0
- package/lib-esm/Hub/index.js +1 -1
- package/lib-esm/Logger/ConsoleLogger.js +1 -1
- package/lib-esm/{Util → Mutex}/Mutex.d.ts +2 -15
- package/lib-esm/{Util → Mutex}/Mutex.js +1 -1
- package/lib-esm/Mutex/index.d.ts +1 -0
- package/lib-esm/Mutex/index.js +3 -0
- package/lib-esm/Mutex/types.d.ts +13 -0
- package/lib-esm/Mutex/types.js +3 -0
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/Reachability/Reachability.d.ts +6 -0
- package/lib-esm/Reachability/Reachability.js +26 -0
- package/lib-esm/Reachability/Reachability.native.d.ts +6 -0
- package/lib-esm/{Util → Reachability}/Reachability.native.js +6 -6
- package/lib-esm/Reachability/index.d.ts +1 -0
- package/lib-esm/Reachability/index.js +3 -0
- package/lib-esm/Reachability/types.d.ts +3 -0
- package/lib-esm/Reachability/types.js +3 -0
- package/lib-esm/ServiceWorker/ServiceWorker.js +1 -1
- package/lib-esm/{Signer.js → Signer/Signer.js} +2 -2
- package/lib-esm/Signer/index.d.ts +1 -0
- package/lib-esm/Signer/index.js +3 -0
- package/lib-esm/clients/middleware/retry/jitteredBackoff.js +1 -1
- package/lib-esm/{Util/Constants.d.ts → constants.d.ts} +0 -2
- package/lib-esm/{Util/Constants.js → constants.js} +0 -5
- package/lib-esm/libraryUtils.d.ts +7 -6
- package/lib-esm/libraryUtils.js +8 -8
- package/lib-esm/providers/pinpoint/apis/updateEndpoint.d.ts +1 -1
- package/lib-esm/providers/pinpoint/apis/updateEndpoint.js +7 -5
- package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +1 -0
- package/lib-esm/singleton/Auth/utils/index.js +2 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/core.d.ts +4 -1
- package/lib-esm/utils/convert/base64/base64Decoder.d.ts +2 -0
- package/lib-esm/utils/convert/base64/base64Decoder.js +8 -0
- package/lib-esm/utils/convert/base64/base64Encoder.d.ts +2 -0
- package/lib-esm/utils/convert/base64/base64Encoder.js +15 -0
- package/lib-esm/utils/convert/base64/bytesToString.d.ts +1 -0
- package/lib-esm/utils/convert/base64/bytesToString.js +5 -0
- package/lib-esm/utils/convert/index.d.ts +2 -0
- package/lib-esm/utils/convert/index.js +4 -0
- package/lib-esm/utils/convert/types.d.ts +9 -0
- package/lib-esm/utils/convert/types.js +3 -0
- package/lib-esm/utils/generateRandomString.d.ts +1 -0
- package/lib-esm/utils/generateRandomString.js +10 -0
- package/lib-esm/utils/globalHelpers/index.d.ts +3 -0
- package/lib-esm/utils/globalHelpers/index.js +44 -0
- package/lib-esm/utils/globalHelpers/index.native.d.ts +5 -0
- package/lib-esm/utils/globalHelpers/index.native.js +21 -0
- package/lib-esm/utils/index.d.ts +6 -0
- package/lib-esm/utils/index.js +8 -0
- package/lib-esm/utils/isBrowser.d.ts +1 -0
- package/lib-esm/utils/isBrowser.js +5 -0
- package/lib-esm/utils/isWebWorker.d.ts +1 -0
- package/lib-esm/utils/isWebWorker.js +10 -0
- package/lib-esm/utils/retry/NonRetryableError.d.ts +4 -0
- package/lib-esm/utils/retry/NonRetryableError.js +27 -0
- package/lib-esm/utils/retry/constants.d.ts +1 -0
- package/lib-esm/utils/retry/constants.js +3 -0
- package/lib-esm/utils/retry/index.d.ts +5 -0
- package/lib-esm/utils/retry/index.js +7 -0
- package/lib-esm/utils/retry/isNonRetryableError.d.ts +2 -0
- package/lib-esm/utils/retry/isNonRetryableError.js +6 -0
- package/lib-esm/utils/retry/jitteredBackoff.d.ts +6 -0
- package/lib-esm/utils/retry/jitteredBackoff.js +16 -0
- package/lib-esm/utils/retry/jitteredExponentialRetry.d.ts +5 -0
- package/lib-esm/utils/retry/jitteredExponentialRetry.js +13 -0
- package/lib-esm/utils/retry/retry.d.ts +6 -0
- package/lib-esm/{Util/Retry.js → utils/retry/retry.js} +4 -52
- package/lib-esm/{Util/StringUtils.d.ts → utils/urlSafeDecode.d.ts} +0 -1
- package/lib-esm/{Util/StringUtils.js → utils/urlSafeDecode.js} +0 -6
- package/{lib/Util/StringUtils.d.ts → lib-esm/utils/urlSafeEncode.d.ts} +0 -1
- package/lib-esm/utils/urlSafeEncode.js +8 -0
- package/package.json +7 -4
- package/src/BackgroundProcessManager/BackgroundManagerNotOpenError.ts +8 -0
- package/src/{Util → BackgroundProcessManager}/BackgroundProcessManager.ts +4 -58
- package/src/BackgroundProcessManager/index.ts +4 -0
- package/src/BackgroundProcessManager/types.ts +49 -0
- package/src/Hub/index.ts +1 -1
- package/src/Logger/ConsoleLogger.ts +1 -1
- package/src/{Util → Mutex}/Mutex.ts +2 -20
- package/src/Mutex/index.ts +4 -0
- package/src/Mutex/types.ts +20 -0
- package/src/Platform/version.ts +1 -1
- package/src/{Util → Reachability}/Reachability.native.ts +4 -11
- package/src/Reachability/Reachability.ts +35 -0
- package/src/Reachability/index.ts +4 -0
- package/src/Reachability/types.ts +6 -0
- package/src/ServiceWorker/ServiceWorker.ts +1 -1
- package/src/{Signer.ts → Signer/Signer.ts} +2 -2
- package/src/Signer/index.ts +4 -0
- package/src/clients/middleware/retry/jitteredBackoff.ts +1 -1
- package/src/{Util/Constants.ts → constants.ts} +0 -5
- package/src/libraryUtils.ts +16 -35
- package/src/providers/pinpoint/apis/updateEndpoint.ts +19 -3
- package/src/providers/pinpoint/types/pinpoint.ts +1 -0
- package/src/singleton/Auth/utils/index.ts +2 -1
- package/src/types/core.ts +4 -1
- package/src/utils/convert/base64/base64Decoder.ts +11 -0
- package/src/utils/convert/base64/base64Encoder.ts +18 -0
- package/src/utils/convert/base64/bytesToString.ts +6 -0
- package/src/utils/convert/index.ts +5 -0
- package/src/utils/convert/types.ts +17 -0
- package/src/utils/generateRandomString.ts +16 -0
- package/src/utils/globalHelpers/index.native.ts +28 -0
- package/src/utils/globalHelpers/index.ts +54 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/isBrowser.ts +5 -0
- package/src/utils/isWebWorker.ts +13 -0
- package/src/utils/retry/NonRetryableError.ts +9 -0
- package/src/utils/retry/constants.ts +4 -0
- package/src/utils/retry/index.ts +8 -0
- package/src/utils/retry/isNonRetryableError.ts +9 -0
- package/src/utils/retry/jitteredBackoff.ts +21 -0
- package/src/utils/retry/jitteredExponentialRetry.ts +18 -0
- package/src/{Util/Retry.ts → utils/retry/retry.ts} +4 -44
- package/src/{Util/StringUtils.ts → utils/urlSafeDecode.ts} +0 -6
- package/src/utils/urlSafeEncode.ts +9 -0
- package/lib/Util/JS.d.ts +0 -29
- package/lib/Util/JS.js +0 -214
- package/lib/Util/Reachability.d.ts +0 -13
- package/lib/Util/Reachability.js +0 -69
- package/lib/Util/Reachability.native.d.ts +0 -12
- package/lib/Util/Retry.d.ts +0 -21
- package/lib/Util/index.d.ts +0 -7
- package/lib/Util/index.js +0 -31
- package/lib-esm/Util/JS.d.ts +0 -29
- package/lib-esm/Util/JS.js +0 -199
- package/lib-esm/Util/Reachability.d.ts +0 -13
- package/lib-esm/Util/Reachability.js +0 -64
- package/lib-esm/Util/Reachability.native.d.ts +0 -12
- package/lib-esm/Util/Retry.d.ts +0 -21
- package/lib-esm/Util/index.d.ts +0 -7
- package/lib-esm/Util/index.js +0 -9
- package/src/Util/JS.ts +0 -255
- package/src/Util/Reachability.ts +0 -58
- package/src/Util/index.ts +0 -23
- /package/lib/{Util → Signer}/DateUtils.d.ts +0 -0
- /package/lib/{Util → Signer}/DateUtils.js +0 -0
- /package/lib/{Signer.d.ts → Signer/Signer.d.ts} +0 -0
- /package/lib-esm/{Util → Signer}/DateUtils.d.ts +0 -0
- /package/lib-esm/{Util → Signer}/DateUtils.js +0 -0
- /package/lib-esm/{Signer.d.ts → Signer/Signer.d.ts} +0 -0
- /package/src/{Util → Signer}/DateUtils.ts +0 -0
|
@@ -24,25 +24,9 @@
|
|
|
24
24
|
* THE SOFTWARE.
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
acquire(): Promise<MutexInterface.Releaser>;
|
|
27
|
+
import { MutexInterface } from './types';
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
isLocked(): boolean;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
namespace MutexInterface {
|
|
36
|
-
export interface Releaser {
|
|
37
|
-
(): void;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface Worker<T> {
|
|
41
|
-
(): Promise<T> | T;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
class Mutex implements MutexInterface {
|
|
29
|
+
export class Mutex implements MutexInterface {
|
|
46
30
|
isLocked(): boolean {
|
|
47
31
|
return this._pending;
|
|
48
32
|
}
|
|
@@ -92,5 +76,3 @@ class Mutex implements MutexInterface {
|
|
|
92
76
|
private _queue: Array<(release: MutexInterface.Releaser) => void> = [];
|
|
93
77
|
private _pending = false;
|
|
94
78
|
}
|
|
95
|
-
|
|
96
|
-
export default Mutex;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export interface MutexInterface {
|
|
5
|
+
acquire(): Promise<MutexInterface.Releaser>;
|
|
6
|
+
|
|
7
|
+
runExclusive<T>(callback: MutexInterface.Worker<T>): Promise<T>;
|
|
8
|
+
|
|
9
|
+
isLocked(): boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export namespace MutexInterface {
|
|
13
|
+
export interface Releaser {
|
|
14
|
+
(): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Worker<T> {
|
|
18
|
+
(): Promise<T> | T;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/Platform/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '6.0.1-console-preview.
|
|
2
|
+
export const version = '6.0.1-console-preview.0bbe168.0+0bbe168';
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import Observable from '
|
|
4
|
-
import { ConsoleLogger as Logger } from '../Logger';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
5
4
|
import type NetInfo from '@react-native-community/netinfo';
|
|
5
|
+
import { ConsoleLogger as Logger } from '../Logger';
|
|
6
|
+
import { NetworkStatus } from './types';
|
|
6
7
|
|
|
7
8
|
const logger = new Logger('Reachability', 'DEBUG');
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
online: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default class ReachabilityNavigator implements Reachability {
|
|
10
|
+
export class Reachability {
|
|
14
11
|
networkMonitor(netInfo?: typeof NetInfo): Observable<NetworkStatus> {
|
|
15
12
|
/**
|
|
16
13
|
* Here netinfo refers to @react-native-community/netinfo
|
|
@@ -45,7 +42,3 @@ export default class ReachabilityNavigator implements Reachability {
|
|
|
45
42
|
});
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
|
-
|
|
49
|
-
interface Reachability {
|
|
50
|
-
networkMonitor(netInfo?: typeof NetInfo): Observable<NetworkStatus>;
|
|
51
|
-
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { CompletionObserver, Observable } from 'rxjs';
|
|
5
|
+
import { isWebWorker } from '../libraryUtils';
|
|
6
|
+
import { NetworkStatus } from './types';
|
|
7
|
+
|
|
8
|
+
export class Reachability {
|
|
9
|
+
private static _observers: Array<CompletionObserver<NetworkStatus>> = [];
|
|
10
|
+
|
|
11
|
+
networkMonitor(_?: unknown): Observable<NetworkStatus> {
|
|
12
|
+
const globalObj = isWebWorker() ? self : window;
|
|
13
|
+
|
|
14
|
+
return new Observable(observer => {
|
|
15
|
+
observer.next({ online: globalObj.navigator.onLine });
|
|
16
|
+
|
|
17
|
+
const notifyOnline = () => observer.next({ online: true });
|
|
18
|
+
const notifyOffline = () => observer.next({ online: false });
|
|
19
|
+
|
|
20
|
+
globalObj.addEventListener('online', notifyOnline);
|
|
21
|
+
globalObj.addEventListener('offline', notifyOffline);
|
|
22
|
+
|
|
23
|
+
Reachability._observers.push(observer);
|
|
24
|
+
|
|
25
|
+
return () => {
|
|
26
|
+
globalObj.removeEventListener('online', notifyOnline);
|
|
27
|
+
globalObj.removeEventListener('offline', notifyOffline);
|
|
28
|
+
|
|
29
|
+
Reachability._observers = Reachability._observers.filter(
|
|
30
|
+
_observer => _observer !== observer
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
5
|
-
import { isBrowser } from '../
|
|
5
|
+
import { isBrowser } from '../utils';
|
|
6
6
|
import { Amplify } from '../Amplify';
|
|
7
7
|
import { AmplifyError } from '../errors';
|
|
8
8
|
import { assert, ServiceWorkerErrorCode } from './errorHelpers';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { DateUtils } from './
|
|
4
|
+
import { DateUtils } from './DateUtils';
|
|
5
5
|
import {
|
|
6
6
|
presignUrl,
|
|
7
7
|
signRequest,
|
|
8
8
|
TOKEN_QUERY_PARAM,
|
|
9
|
-
} from '
|
|
9
|
+
} from '../clients/middleware/signing/signer/signatureV4';
|
|
10
10
|
|
|
11
11
|
const IOT_SERVICE_NAME = 'iotdevicegateway';
|
|
12
12
|
// Best practice regex to parse the service and region from an AWS endpoint
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { RetryOptions } from './middleware';
|
|
5
5
|
// TODO: [v6] The separate retry utility is used by Data packages now and will replaced by retry middleware.
|
|
6
|
-
import { jitteredBackoff as jitteredBackoffUtil } from '../../../
|
|
6
|
+
import { jitteredBackoff as jitteredBackoffUtil } from '../../../utils';
|
|
7
7
|
|
|
8
8
|
const DEFAULT_MAX_DELAY_MS = 5 * 60 * 1000;
|
|
9
9
|
|
|
@@ -3,11 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
// Logging constants
|
|
5
5
|
export const AWS_CLOUDWATCH_CATEGORY = 'Logging';
|
|
6
|
-
export const NO_CREDS_ERROR_STRING = 'No credentials';
|
|
7
|
-
export const RETRY_ERROR_CODES = [
|
|
8
|
-
'ResourceNotFoundException',
|
|
9
|
-
'InvalidSequenceTokenException',
|
|
10
|
-
];
|
|
11
6
|
|
|
12
7
|
/**
|
|
13
8
|
* This Symbol is used to reference an internal-only PubSub provider that
|
package/src/libraryUtils.ts
CHANGED
|
@@ -5,21 +5,19 @@
|
|
|
5
5
|
This file maps top-level exports from `@aws-amplify/core/internals/utils`. These are intended to be internal
|
|
6
6
|
utils for use throughout the library.
|
|
7
7
|
*/
|
|
8
|
-
//
|
|
8
|
+
// Core utilities
|
|
9
9
|
export {
|
|
10
|
-
isBrowser,
|
|
11
|
-
filenameToContentType,
|
|
12
10
|
generateRandomString,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
isTextFile,
|
|
11
|
+
isBrowser,
|
|
12
|
+
isNonRetryableError,
|
|
16
13
|
isWebWorker,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
jitteredBackoff,
|
|
15
|
+
jitteredExponentialRetry,
|
|
16
|
+
NonRetryableError,
|
|
17
|
+
retry,
|
|
18
|
+
urlSafeDecode,
|
|
19
|
+
urlSafeEncode,
|
|
20
|
+
} from './utils';
|
|
23
21
|
export { parseAWSExports } from './parseAWSExports';
|
|
24
22
|
export { LegacyConfig } from './singleton/types';
|
|
25
23
|
export {
|
|
@@ -43,7 +41,6 @@ export { Signer } from './Signer';
|
|
|
43
41
|
export { ConsoleLogger, ConsoleLogger as Logger } from './Logger';
|
|
44
42
|
|
|
45
43
|
// Platform & device utils
|
|
46
|
-
import { Platform } from './Platform';
|
|
47
44
|
export { ClientDevice } from './ClientDevice';
|
|
48
45
|
export {
|
|
49
46
|
Platform,
|
|
@@ -66,32 +63,14 @@ export {
|
|
|
66
63
|
PushNotificationAction,
|
|
67
64
|
StorageAction,
|
|
68
65
|
} from './Platform/types';
|
|
69
|
-
export const Constants = {
|
|
70
|
-
userAgent: Platform.userAgent,
|
|
71
|
-
};
|
|
72
66
|
|
|
73
67
|
// Service worker
|
|
74
68
|
export { ServiceWorker } from './ServiceWorker';
|
|
75
69
|
|
|
76
70
|
// Other utilities & constants
|
|
77
|
-
export {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
BackgroundProcessManager,
|
|
81
|
-
BackgroundProcessManagerState,
|
|
82
|
-
DateUtils,
|
|
83
|
-
Mutex,
|
|
84
|
-
NO_CREDS_ERROR_STRING,
|
|
85
|
-
NonRetryableError,
|
|
86
|
-
RETRY_ERROR_CODES,
|
|
87
|
-
Reachability,
|
|
88
|
-
isNonRetryableError,
|
|
89
|
-
jitteredBackoff,
|
|
90
|
-
jitteredExponentialRetry,
|
|
91
|
-
retry,
|
|
92
|
-
urlSafeDecode,
|
|
93
|
-
urlSafeEncode,
|
|
94
|
-
} from './Util';
|
|
71
|
+
export { BackgroundProcessManager } from './BackgroundProcessManager';
|
|
72
|
+
export { Mutex } from './Mutex';
|
|
73
|
+
export { Reachability } from './Reachability';
|
|
95
74
|
export {
|
|
96
75
|
AmplifyError,
|
|
97
76
|
PlatformNotSupportedError,
|
|
@@ -107,6 +86,8 @@ export {
|
|
|
107
86
|
export {
|
|
108
87
|
INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
|
|
109
88
|
USER_AGENT_HEADER,
|
|
110
|
-
} from './
|
|
89
|
+
} from './constants';
|
|
111
90
|
export { fetchAuthSession } from './singleton/apis/internal/fetchAuthSession';
|
|
112
91
|
export { AMPLIFY_SYMBOL } from './Hub';
|
|
92
|
+
export { base64Decoder, base64Encoder } from './utils/convert';
|
|
93
|
+
export { getCrypto } from './utils/globalHelpers';
|
|
@@ -22,6 +22,7 @@ export const updateEndpoint = async ({
|
|
|
22
22
|
identityId,
|
|
23
23
|
optOut,
|
|
24
24
|
region,
|
|
25
|
+
userAttributes,
|
|
25
26
|
userId,
|
|
26
27
|
userProfile,
|
|
27
28
|
userAgentValue,
|
|
@@ -29,7 +30,15 @@ export const updateEndpoint = async ({
|
|
|
29
30
|
const endpointId = await getEndpointId(appId, category);
|
|
30
31
|
// only generate a new endpoint id if one was not found in cache
|
|
31
32
|
const createdEndpointId = !endpointId ? uuidv4() : undefined;
|
|
32
|
-
const {
|
|
33
|
+
const {
|
|
34
|
+
customProperties,
|
|
35
|
+
demographic,
|
|
36
|
+
email,
|
|
37
|
+
location,
|
|
38
|
+
metrics,
|
|
39
|
+
name,
|
|
40
|
+
plan,
|
|
41
|
+
} = userProfile ?? {};
|
|
33
42
|
const clientInfo = ClientDevice.clientInfo();
|
|
34
43
|
const mergedDemographic = {
|
|
35
44
|
appVersion: clientInfo.appVersion,
|
|
@@ -39,6 +48,13 @@ export const updateEndpoint = async ({
|
|
|
39
48
|
platform: clientInfo.platform,
|
|
40
49
|
...demographic,
|
|
41
50
|
};
|
|
51
|
+
const shouldAddAttributes = email || customProperties || name || plan;
|
|
52
|
+
const attributes = {
|
|
53
|
+
...(email && { email: [email] }),
|
|
54
|
+
...(name && { name: [name] }),
|
|
55
|
+
...(plan && { plan: [plan] }),
|
|
56
|
+
...customProperties,
|
|
57
|
+
};
|
|
42
58
|
const input: UpdateEndpointInput = {
|
|
43
59
|
ApplicationId: appId,
|
|
44
60
|
EndpointId: endpointId ?? createdEndpointId,
|
|
@@ -47,7 +63,7 @@ export const updateEndpoint = async ({
|
|
|
47
63
|
EffectiveDate: new Date().toISOString(),
|
|
48
64
|
ChannelType: channelType,
|
|
49
65
|
Address: address,
|
|
50
|
-
Attributes: attributes,
|
|
66
|
+
Attributes: shouldAddAttributes ? attributes : undefined,
|
|
51
67
|
Demographic: {
|
|
52
68
|
AppVersion: mergedDemographic.appVersion,
|
|
53
69
|
Locale: mergedDemographic.locale,
|
|
@@ -70,7 +86,7 @@ export const updateEndpoint = async ({
|
|
|
70
86
|
OptOut: optOut,
|
|
71
87
|
User: {
|
|
72
88
|
UserId: userId ?? identityId,
|
|
73
|
-
UserAttributes:
|
|
89
|
+
UserAttributes: userAttributes,
|
|
74
90
|
},
|
|
75
91
|
},
|
|
76
92
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { AuthConfigurationErrorCode, assert } from './errorHelpers';
|
|
4
|
+
import { base64Decoder } from '../../../utils/convert';
|
|
4
5
|
|
|
5
6
|
import {
|
|
6
7
|
AuthConfig,
|
|
@@ -97,6 +98,6 @@ export function decodeJWT(token: string): JWT {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
function base64ToBytes(base64: string): Uint8Array {
|
|
100
|
-
const binString =
|
|
101
|
+
const binString = base64Decoder.convert(base64);
|
|
101
102
|
return Uint8Array.from(binString, m => m.codePointAt(0) || 0);
|
|
102
103
|
}
|
package/src/types/core.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface AmplifyConfig {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export type UserProfile = {
|
|
19
|
-
|
|
19
|
+
customProperties?: Record<string, string[]>;
|
|
20
20
|
demographic?: {
|
|
21
21
|
appVersion?: string;
|
|
22
22
|
locale?: string;
|
|
@@ -27,6 +27,7 @@ export type UserProfile = {
|
|
|
27
27
|
platformVersion?: string;
|
|
28
28
|
timezone?: string;
|
|
29
29
|
};
|
|
30
|
+
email?: string;
|
|
30
31
|
location?: {
|
|
31
32
|
city?: string;
|
|
32
33
|
country?: string;
|
|
@@ -36,6 +37,8 @@ export type UserProfile = {
|
|
|
36
37
|
region?: string;
|
|
37
38
|
};
|
|
38
39
|
metrics?: Record<string, number>;
|
|
40
|
+
name?: string;
|
|
41
|
+
plan?: string;
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { getAtob } from '../../globalHelpers';
|
|
5
|
+
import { Base64Decoder } from '../types';
|
|
6
|
+
|
|
7
|
+
export const base64Decoder: Base64Decoder = {
|
|
8
|
+
convert(input) {
|
|
9
|
+
return getAtob()(input);
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { getBtoa } from '../../globalHelpers';
|
|
5
|
+
import { Base64Encoder } from '../types';
|
|
6
|
+
import { bytesToString } from './bytesToString';
|
|
7
|
+
|
|
8
|
+
export const base64Encoder: Base64Encoder = {
|
|
9
|
+
convert(input, { urlSafe } = { urlSafe: false }) {
|
|
10
|
+
const inputStr = typeof input === 'string' ? input : bytesToString(input);
|
|
11
|
+
const encodedStr = getBtoa()(inputStr);
|
|
12
|
+
|
|
13
|
+
// see details about the char replacing at https://datatracker.ietf.org/doc/html/rfc4648#section-5
|
|
14
|
+
return urlSafe
|
|
15
|
+
? encodedStr.replace(/\+/g, '-').replace(/\//g, '_')
|
|
16
|
+
: encodedStr;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export interface Base64EncoderConvertOptions {
|
|
5
|
+
urlSafe: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface Base64Encoder {
|
|
9
|
+
convert(
|
|
10
|
+
input: Uint8Array | string,
|
|
11
|
+
options?: Base64EncoderConvertOptions
|
|
12
|
+
): string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Base64Decoder {
|
|
16
|
+
convert(input: string): string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export const generateRandomString = (length: number) => {
|
|
5
|
+
const STATE_CHARSET =
|
|
6
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
7
|
+
let result = '';
|
|
8
|
+
|
|
9
|
+
for (let i = 0; i < length; i++) {
|
|
10
|
+
result += STATE_CHARSET.charAt(
|
|
11
|
+
Math.floor(Math.random() * STATE_CHARSET.length)
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import 'react-native-get-random-values';
|
|
5
|
+
import { encode, decode } from 'base-64';
|
|
6
|
+
import { AmplifyError } from '../../errors';
|
|
7
|
+
|
|
8
|
+
export const getCrypto = () => {
|
|
9
|
+
if (
|
|
10
|
+
typeof crypto !== 'undefined' &&
|
|
11
|
+
typeof crypto.getRandomValues === 'function'
|
|
12
|
+
) {
|
|
13
|
+
return crypto;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
throw new AmplifyError({
|
|
17
|
+
name: 'MissingPolyfill',
|
|
18
|
+
message: 'Cannot resolve the `crypto` function from the environment.',
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const getBtoa = () => {
|
|
23
|
+
return encode;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const getAtob = () => {
|
|
27
|
+
return decode;
|
|
28
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AmplifyError } from '../../errors';
|
|
5
|
+
|
|
6
|
+
export const getCrypto = () => {
|
|
7
|
+
if (typeof window === 'object' && typeof window.crypto === 'object') {
|
|
8
|
+
return window.crypto;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Next.js global polyfill
|
|
12
|
+
if (typeof crypto === 'object') {
|
|
13
|
+
return crypto;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
throw new AmplifyError({
|
|
17
|
+
name: 'MissingPolyfill',
|
|
18
|
+
message: 'Cannot resolve the `crypto` function from the environment.',
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const getBtoa = () => {
|
|
23
|
+
// browser
|
|
24
|
+
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
25
|
+
return window.btoa;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Next.js global polyfill
|
|
29
|
+
if (typeof btoa === 'function') {
|
|
30
|
+
return btoa;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
throw new AmplifyError({
|
|
34
|
+
name: 'Base64EncoderError',
|
|
35
|
+
message: 'Cannot resolve the `btoa` function from the environment.',
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const getAtob = () => {
|
|
40
|
+
// browser
|
|
41
|
+
if (typeof window !== 'undefined' && typeof window.atob === 'function') {
|
|
42
|
+
return window.atob;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Next.js global polyfill
|
|
46
|
+
if (typeof atob === 'function') {
|
|
47
|
+
return atob;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new AmplifyError({
|
|
51
|
+
name: 'Base64EncoderError',
|
|
52
|
+
message: 'Cannot resolve the `atob` function from the environment.',
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export { generateRandomString } from './generateRandomString';
|
|
5
|
+
export { isBrowser } from './isBrowser';
|
|
6
|
+
export { isWebWorker } from './isWebWorker';
|
|
7
|
+
export {
|
|
8
|
+
NonRetryableError,
|
|
9
|
+
isNonRetryableError,
|
|
10
|
+
jitteredBackoff,
|
|
11
|
+
jitteredExponentialRetry,
|
|
12
|
+
retry,
|
|
13
|
+
} from './retry';
|
|
14
|
+
export { urlSafeDecode } from './urlSafeDecode';
|
|
15
|
+
export { urlSafeEncode } from './urlSafeEncode';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export const isWebWorker = () => {
|
|
5
|
+
if (typeof self === 'undefined') {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const selfContext = self as { WorkerGlobalScope?: any };
|
|
9
|
+
return (
|
|
10
|
+
typeof selfContext.WorkerGlobalScope !== 'undefined' &&
|
|
11
|
+
self instanceof selfContext.WorkerGlobalScope
|
|
12
|
+
);
|
|
13
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export { NonRetryableError } from './NonRetryableError';
|
|
5
|
+
export { isNonRetryableError } from './isNonRetryableError';
|
|
6
|
+
export { jitteredBackoff } from './jitteredBackoff';
|
|
7
|
+
export { jitteredExponentialRetry } from './jitteredExponentialRetry';
|
|
8
|
+
export { retry } from './retry';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { NonRetryableError } from './NonRetryableError';
|
|
5
|
+
|
|
6
|
+
export const isNonRetryableError = (obj: any): obj is NonRetryableError => {
|
|
7
|
+
const key: keyof NonRetryableError = 'nonRetryable';
|
|
8
|
+
return obj && obj[key];
|
|
9
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { DelayFunction } from '../../types';
|
|
5
|
+
import { MAX_DELAY_MS } from './constants';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @private
|
|
9
|
+
* Internal use of Amplify only
|
|
10
|
+
*/
|
|
11
|
+
export function jitteredBackoff(
|
|
12
|
+
maxDelayMs: number = MAX_DELAY_MS
|
|
13
|
+
): DelayFunction {
|
|
14
|
+
const BASE_TIME_MS = 100;
|
|
15
|
+
const JITTER_FACTOR = 100;
|
|
16
|
+
|
|
17
|
+
return attempt => {
|
|
18
|
+
const delay = 2 ** attempt * BASE_TIME_MS + JITTER_FACTOR * Math.random();
|
|
19
|
+
return delay > maxDelayMs ? false : delay;
|
|
20
|
+
};
|
|
21
|
+
}
|