@aws-amplify/core 6.0.1-console-preview.814dea6.0 → 6.0.1-console-preview.047a1dd.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/CognitoIdentity/base.d.ts +12 -4
- package/lib/AwsClients/CognitoIdentity/base.js +1 -0
- package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +15 -3
- package/lib/AwsClients/CognitoIdentity/getId.d.ts +15 -3
- package/lib/AwsClients/Pinpoint/base.d.ts +10 -2
- package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +17 -3
- package/lib/AwsClients/Pinpoint/putEvents.d.ts +17 -3
- package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +17 -3
- package/lib/Cache/Utils/CacheUtils.js +2 -4
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/ServiceWorker/ServiceWorker.js +1 -1
- package/lib/Util/JS.d.ts +1 -4
- package/lib/Util/JS.js +4 -11
- package/lib/Util/Reachability.js +0 -3
- package/lib/clients/handlers/authenticated.d.ts +1 -1
- package/lib/clients/handlers/fetch.d.ts +0 -1
- package/lib/clients/handlers/fetch.js +2 -2
- package/lib/clients/handlers/unauthenticated.d.ts +1 -1
- package/lib/clients/internal/composeServiceApi.d.ts +5 -3
- package/lib/clients/types/aws.d.ts +1 -5
- package/lib/clients/types/http.d.ts +8 -0
- package/lib/clients/types/index.d.ts +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.js +6 -10
- package/lib/libraryUtils.d.ts +3 -3
- package/lib/libraryUtils.js +5 -10
- package/lib/parseAWSExports.js +20 -1
- package/lib/providers/pinpoint/apis/record.d.ts +2 -2
- package/lib/providers/pinpoint/apis/record.js +3 -3
- package/lib/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
- package/lib/providers/pinpoint/types/buffer.d.ts +1 -1
- package/lib/providers/pinpoint/types/pinpoint.d.ts +3 -3
- package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +7 -5
- package/lib/providers/pinpoint/utils/isAppInForeground.d.ts +1 -0
- package/lib/{RNComponents → providers/pinpoint/utils}/isAppInForeground.js +1 -4
- package/lib/providers/pinpoint/utils/isAppInForeground.native.d.ts +1 -0
- package/lib/providers/pinpoint/utils/isAppInForeground.native.js +9 -0
- package/lib/singleton/API/types.d.ts +34 -0
- package/lib/singleton/API/types.js +2 -0
- package/lib/singleton/Amplify.d.ts +2 -2
- package/lib/singleton/Amplify.js +9 -1
- package/lib/singleton/Auth/index.d.ts +2 -1
- package/lib/singleton/Auth/index.js +22 -12
- package/lib/singleton/Auth/utils/index.js +3 -3
- package/lib/singleton/Storage/types.d.ts +5 -0
- package/lib/singleton/types.d.ts +10 -1
- package/lib/{StorageHelper/cookieStorage.d.ts → storage/CookieStorage.d.ts} +4 -3
- package/lib/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +35 -83
- package/lib/storage/CookieStorage.native.d.ts +7 -0
- package/lib/storage/CookieStorage.native.js +32 -0
- package/lib/storage/DefaultStorage.d.ts +7 -0
- package/lib/storage/DefaultStorage.js +33 -0
- package/{lib-esm/StorageHelper/localStorage.d.ts → lib/storage/DefaultStorage.native.d.ts} +7 -6
- package/lib/{StorageHelper/sessionStorage.js → storage/DefaultStorage.native.js} +46 -43
- package/lib/storage/InMemoryStorage.d.ts +12 -0
- package/lib/storage/InMemoryStorage.js +41 -0
- package/lib/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
- package/lib/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +13 -15
- package/lib/storage/SessionStorage.d.ts +7 -0
- package/lib/storage/SessionStorage.js +33 -0
- package/lib/storage/index.d.ts +7 -0
- package/lib/storage/index.js +14 -0
- package/lib/storage/utils.d.ts +10 -0
- package/lib/storage/utils.js +26 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/storage.d.ts +3 -0
- package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +12 -4
- package/lib-esm/AwsClients/CognitoIdentity/base.js +1 -0
- package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +15 -3
- package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +15 -3
- package/lib-esm/AwsClients/Pinpoint/base.d.ts +10 -2
- package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +17 -3
- package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +17 -3
- package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +17 -3
- package/lib-esm/Cache/Utils/CacheUtils.js +2 -4
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/ServiceWorker/ServiceWorker.js +2 -2
- package/lib-esm/Util/JS.d.ts +1 -4
- package/lib-esm/Util/JS.js +2 -9
- package/lib-esm/Util/Reachability.js +1 -4
- package/lib-esm/clients/handlers/authenticated.d.ts +1 -1
- package/lib-esm/clients/handlers/fetch.d.ts +0 -1
- package/lib-esm/clients/handlers/fetch.js +2 -2
- package/lib-esm/clients/handlers/unauthenticated.d.ts +1 -1
- package/lib-esm/clients/internal/composeServiceApi.d.ts +5 -3
- package/lib-esm/clients/types/aws.d.ts +1 -5
- package/lib-esm/clients/types/http.d.ts +8 -0
- package/lib-esm/clients/types/index.d.ts +1 -1
- package/lib-esm/index.d.ts +1 -2
- package/lib-esm/index.js +1 -2
- package/lib-esm/libraryUtils.d.ts +3 -3
- package/lib-esm/libraryUtils.js +2 -3
- package/lib-esm/parseAWSExports.js +20 -1
- package/lib-esm/providers/pinpoint/apis/record.d.ts +2 -2
- package/lib-esm/providers/pinpoint/apis/record.js +3 -3
- package/lib-esm/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
- package/lib-esm/providers/pinpoint/types/buffer.d.ts +1 -1
- package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +3 -3
- package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +7 -5
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.js +3 -0
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.js +5 -0
- package/lib-esm/singleton/API/types.d.ts +34 -0
- package/lib-esm/singleton/API/types.js +1 -0
- package/lib-esm/singleton/Amplify.d.ts +2 -2
- package/lib-esm/singleton/Amplify.js +9 -1
- package/lib-esm/singleton/Auth/index.d.ts +2 -1
- package/lib-esm/singleton/Auth/index.js +22 -12
- package/lib-esm/singleton/Auth/utils/index.js +3 -3
- package/lib-esm/singleton/Storage/types.d.ts +5 -0
- package/lib-esm/singleton/types.d.ts +10 -1
- package/lib-esm/{StorageHelper/cookieStorage.d.ts → storage/CookieStorage.d.ts} +4 -3
- package/lib-esm/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +36 -61
- package/lib-esm/storage/CookieStorage.native.d.ts +7 -0
- package/lib-esm/storage/CookieStorage.native.js +29 -0
- package/lib-esm/storage/DefaultStorage.d.ts +7 -0
- package/lib-esm/storage/DefaultStorage.js +30 -0
- package/{lib/StorageHelper/localStorage.d.ts → lib-esm/storage/DefaultStorage.native.d.ts} +7 -6
- package/lib-esm/{StorageHelper/sessionStorage.js → storage/DefaultStorage.native.js} +45 -42
- package/lib-esm/storage/InMemoryStorage.d.ts +12 -0
- package/lib-esm/storage/InMemoryStorage.js +38 -0
- package/lib-esm/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
- package/lib-esm/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +12 -14
- package/lib-esm/storage/SessionStorage.d.ts +7 -0
- package/lib-esm/storage/SessionStorage.js +30 -0
- package/lib-esm/storage/index.d.ts +7 -0
- package/lib-esm/storage/index.js +10 -0
- package/lib-esm/storage/utils.d.ts +10 -0
- package/lib-esm/storage/utils.js +21 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/storage.d.ts +3 -0
- package/package.json +3 -6
- package/src/AwsClients/CognitoIdentity/base.ts +2 -2
- package/src/AwsClients/Pinpoint/base.ts +2 -6
- package/src/Cache/Utils/CacheUtils.ts +2 -4
- package/src/Platform/version.ts +1 -1
- package/src/ServiceWorker/ServiceWorker.ts +2 -2
- package/src/Util/JS.ts +2 -13
- package/src/Util/Reachability.ts +1 -5
- package/src/clients/handlers/authenticated.ts +2 -1
- package/src/clients/handlers/fetch.ts +2 -2
- package/src/clients/handlers/unauthenticated.ts +2 -1
- package/src/clients/internal/composeServiceApi.ts +10 -3
- package/src/clients/types/aws.ts +4 -11
- package/src/clients/types/http.ts +8 -0
- package/src/clients/types/index.ts +0 -1
- package/src/index.ts +4 -8
- package/src/libraryUtils.ts +3 -4
- package/src/parseAWSExports.ts +26 -0
- package/src/providers/pinpoint/apis/record.ts +8 -8
- package/src/providers/pinpoint/apis/updateEndpoint.ts +2 -2
- package/src/providers/pinpoint/types/buffer.ts +1 -1
- package/src/providers/pinpoint/types/pinpoint.ts +8 -7
- package/src/providers/pinpoint/utils/PinpointEventBuffer.ts +16 -12
- package/src/providers/pinpoint/utils/isAppInForeground.native.ts +7 -0
- package/src/providers/pinpoint/utils/isAppInForeground.ts +4 -0
- package/src/singleton/API/types.ts +31 -0
- package/src/singleton/Amplify.ts +12 -3
- package/src/singleton/Auth/index.ts +9 -2
- package/src/singleton/Auth/utils/index.ts +3 -3
- package/src/singleton/Storage/types.ts +6 -2
- package/src/singleton/types.ts +11 -1
- package/src/storage/CookieStorage.native.ts +13 -0
- package/src/storage/CookieStorage.ts +72 -0
- package/src/storage/DefaultStorage.native.ts +78 -0
- package/src/storage/DefaultStorage.ts +14 -0
- package/src/storage/InMemoryStorage.ts +36 -0
- package/src/{StorageHelper/sessionStorage.ts → storage/KeyValueStorage.ts} +10 -13
- package/src/storage/SessionStorage.ts +14 -0
- package/src/storage/index.ts +13 -0
- package/src/storage/utils.ts +22 -0
- package/src/types/storage.ts +4 -0
- package/lib/OAuthHelper/FacebookOAuth.d.ts +0 -6
- package/lib/OAuthHelper/FacebookOAuth.js +0 -124
- package/lib/OAuthHelper/GoogleOAuth.d.ts +0 -6
- package/lib/OAuthHelper/GoogleOAuth.js +0 -134
- package/lib/OAuthHelper/index.d.ts +0 -4
- package/lib/OAuthHelper/index.js +0 -9
- package/lib/RNComponents/index.d.ts +0 -6
- package/lib/RNComponents/index.js +0 -16
- package/lib/RNComponents/reactnative.d.ts +0 -3
- package/lib/RNComponents/reactnative.js +0 -14
- package/lib/StorageHelper/inMemoryStorage.d.ts +0 -10
- package/lib/StorageHelper/inMemoryStorage.js +0 -82
- package/lib/StorageHelper/index.d.ts +0 -45
- package/lib/StorageHelper/index.js +0 -83
- package/lib/StorageHelper/reactnative.d.ts +0 -83
- package/lib/StorageHelper/reactnative.js +0 -250
- package/lib-esm/OAuthHelper/FacebookOAuth.d.ts +0 -6
- package/lib-esm/OAuthHelper/FacebookOAuth.js +0 -121
- package/lib-esm/OAuthHelper/GoogleOAuth.d.ts +0 -6
- package/lib-esm/OAuthHelper/GoogleOAuth.js +0 -131
- package/lib-esm/OAuthHelper/index.d.ts +0 -4
- package/lib-esm/OAuthHelper/index.js +0 -6
- package/lib-esm/RNComponents/index.d.ts +0 -6
- package/lib-esm/RNComponents/index.js +0 -13
- package/lib-esm/RNComponents/isAppInForeground.js +0 -6
- package/lib-esm/RNComponents/reactnative.d.ts +0 -3
- package/lib-esm/RNComponents/reactnative.js +0 -6
- package/lib-esm/StorageHelper/inMemoryStorage.d.ts +0 -10
- package/lib-esm/StorageHelper/inMemoryStorage.js +0 -79
- package/lib-esm/StorageHelper/index.d.ts +0 -45
- package/lib-esm/StorageHelper/index.js +0 -76
- package/lib-esm/StorageHelper/reactnative.d.ts +0 -83
- package/lib-esm/StorageHelper/reactnative.js +0 -244
- package/src/OAuthHelper/FacebookOAuth.ts +0 -83
- package/src/OAuthHelper/GoogleOAuth.ts +0 -97
- package/src/OAuthHelper/index.ts +0 -7
- package/src/RNComponents/index.ts +0 -16
- package/src/RNComponents/isAppInForeground.ts +0 -8
- package/src/RNComponents/reactnative.ts +0 -6
- package/src/StorageHelper/cookieStorage.ts +0 -99
- package/src/StorageHelper/inMemoryStorage.ts +0 -32
- package/src/StorageHelper/index.ts +0 -78
- package/src/StorageHelper/localStorage.ts +0 -60
- package/src/StorageHelper/reactnative.ts +0 -182
- /package/lib-esm/{RNComponents → providers/pinpoint/utils}/isAppInForeground.d.ts +0 -0
- /package/{lib/RNComponents/isAppInForeground.d.ts → lib-esm/providers/pinpoint/utils/isAppInForeground.native.d.ts} +0 -0
package/src/singleton/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { APIConfig, LibraryAPIOptions } from './API/types';
|
|
4
5
|
import { AnalyticsConfig } from './Analytics/types';
|
|
5
6
|
import {
|
|
6
7
|
AuthConfig,
|
|
@@ -17,8 +18,15 @@ import {
|
|
|
17
18
|
StorageConfig,
|
|
18
19
|
} from './Storage/types';
|
|
19
20
|
|
|
21
|
+
export type LegacyConfig = {
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated The field should not be used.
|
|
24
|
+
*/
|
|
25
|
+
aws_project_region?: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
20
28
|
export type ResourcesConfig = {
|
|
21
|
-
|
|
29
|
+
API?: APIConfig;
|
|
22
30
|
Analytics?: AnalyticsConfig;
|
|
23
31
|
Auth?: AuthConfig;
|
|
24
32
|
// Cache?: CacheConfig;
|
|
@@ -31,12 +39,14 @@ export type ResourcesConfig = {
|
|
|
31
39
|
};
|
|
32
40
|
|
|
33
41
|
export type LibraryOptions = {
|
|
42
|
+
API?: LibraryAPIOptions;
|
|
34
43
|
Auth?: LibraryAuthOptions;
|
|
35
44
|
Storage?: LibraryStorageOptions;
|
|
36
45
|
ssr?: boolean;
|
|
37
46
|
};
|
|
38
47
|
|
|
39
48
|
export {
|
|
49
|
+
APIConfig,
|
|
40
50
|
AuthConfig,
|
|
41
51
|
AuthUserPoolConfig,
|
|
42
52
|
AuthIdentityPoolConfig,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { KeyValueStorage } from './KeyValueStorage';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class CookieStorage extends KeyValueStorage {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
get as getJsCookie,
|
|
6
|
+
remove as removeJsCookie,
|
|
7
|
+
set as setJsCookie,
|
|
8
|
+
} from 'js-cookie';
|
|
9
|
+
import {
|
|
10
|
+
CookieStorageData,
|
|
11
|
+
KeyValueStorageInterface,
|
|
12
|
+
SameSite,
|
|
13
|
+
} from '../types';
|
|
14
|
+
|
|
15
|
+
export class CookieStorage implements KeyValueStorageInterface {
|
|
16
|
+
path: string;
|
|
17
|
+
domain?: string;
|
|
18
|
+
expires?: number;
|
|
19
|
+
sameSite?: SameSite;
|
|
20
|
+
secure?: boolean;
|
|
21
|
+
|
|
22
|
+
constructor(data: CookieStorageData = {}) {
|
|
23
|
+
const { path, domain, expires, sameSite, secure } = data;
|
|
24
|
+
this.domain = domain;
|
|
25
|
+
this.path = path ? path : '/';
|
|
26
|
+
this.expires = data.hasOwnProperty('expires') ? expires : 365;
|
|
27
|
+
this.secure = data.hasOwnProperty('secure') ? secure : true;
|
|
28
|
+
|
|
29
|
+
if (data.hasOwnProperty('sameSite')) {
|
|
30
|
+
if (!sameSite || !['strict', 'lax', 'none'].includes(sameSite)) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
'The sameSite value of cookieStorage must be "lax", "strict" or "none".'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (sameSite === 'none' && !this.secure) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
'sameSite = None requires the Secure attribute in latest browser versions.'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
this.sameSite = sameSite;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async setItem(key: string, value: string) {
|
|
45
|
+
setJsCookie(key, value, this.getData());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async getItem(key: string) {
|
|
49
|
+
const item = getJsCookie(key);
|
|
50
|
+
return item ?? null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async removeItem(key: string) {
|
|
54
|
+
removeJsCookie(key, this.getData());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async clear() {
|
|
58
|
+
const cookie = getJsCookie();
|
|
59
|
+
const promises = Object.keys(cookie).map(key => this.removeItem(key));
|
|
60
|
+
await Promise.all(promises);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private getData(): CookieStorageData {
|
|
64
|
+
return {
|
|
65
|
+
path: this.path,
|
|
66
|
+
expires: this.expires,
|
|
67
|
+
domain: this.domain,
|
|
68
|
+
secure: this.secure,
|
|
69
|
+
...(this.sameSite && { sameSite: this.sameSite }),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { AsyncStorageStatic } from '@react-native-async-storage/async-storage';
|
|
5
|
+
import { AmplifyError } from '../libraryUtils';
|
|
6
|
+
import { KeyValueStorageInterface } from '../types';
|
|
7
|
+
|
|
8
|
+
const ASYNC_STORAGE_MODULE = '@react-native-async-storage/async-storage';
|
|
9
|
+
const MEMORY_KEY_PREFIX = '@MemoryStorage:';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export class DefaultStorage implements KeyValueStorageInterface {
|
|
15
|
+
private asyncStorage?: AsyncStorageStatic;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This is used to set a specific item in storage
|
|
19
|
+
* @param {string} key - the key for the item
|
|
20
|
+
* @param {object} value - the value
|
|
21
|
+
* @returns {string} value that was set
|
|
22
|
+
*/
|
|
23
|
+
setItem(key: string, value: string) {
|
|
24
|
+
this.assertModule(this.asyncStorage);
|
|
25
|
+
return this.asyncStorage.setItem(`${MEMORY_KEY_PREFIX}${key}`, value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* This is used to get a specific key from storage
|
|
30
|
+
* @param {string} key - the key for the item
|
|
31
|
+
* This is used to clear the storage
|
|
32
|
+
* @returns {string} the data item
|
|
33
|
+
*/
|
|
34
|
+
getItem(key: string) {
|
|
35
|
+
this.assertModule(this.asyncStorage);
|
|
36
|
+
return this.asyncStorage.getItem(`${MEMORY_KEY_PREFIX}${key}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* This is used to remove an item from storage
|
|
41
|
+
* @param {string} key - the key being set
|
|
42
|
+
* @returns {string} value - value that was deleted
|
|
43
|
+
*/
|
|
44
|
+
removeItem(key: string): Promise<void> {
|
|
45
|
+
this.assertModule(this.asyncStorage);
|
|
46
|
+
return this.asyncStorage.removeItem(`${MEMORY_KEY_PREFIX}${key}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* This is used to clear the storage
|
|
51
|
+
* @returns {string} nothing
|
|
52
|
+
*/
|
|
53
|
+
async clear(): Promise<void> {
|
|
54
|
+
this.assertModule(this.asyncStorage);
|
|
55
|
+
const allKeys = await this.asyncStorage.getAllKeys();
|
|
56
|
+
return this.asyncStorage.multiRemove(
|
|
57
|
+
allKeys.filter(key => key.startsWith(MEMORY_KEY_PREFIX))
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private assertModule(
|
|
62
|
+
asyncStorage?: AsyncStorageStatic
|
|
63
|
+
): asserts asyncStorage {
|
|
64
|
+
if (!!asyncStorage) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
this.asyncStorage = require(ASYNC_STORAGE_MODULE)
|
|
69
|
+
.default as AsyncStorageStatic;
|
|
70
|
+
} catch (err) {
|
|
71
|
+
throw new AmplifyError({
|
|
72
|
+
name: 'NativeModuleException',
|
|
73
|
+
message: `Unable to find ${ASYNC_STORAGE_MODULE}`,
|
|
74
|
+
recoverySuggestion: `Make sure to install ${ASYNC_STORAGE_MODULE}`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { KeyValueStorage } from './KeyValueStorage';
|
|
5
|
+
import { getDefaultStorageWithFallback } from './utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class DefaultStorage extends KeyValueStorage {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(getDefaultStorageWithFallback());
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export class InMemoryStorage implements Storage {
|
|
8
|
+
storage = new Map<string, string>();
|
|
9
|
+
|
|
10
|
+
get length() {
|
|
11
|
+
return this.storage.size;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
key(index: number) {
|
|
15
|
+
if (index > this.length - 1) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return Array.from(this.storage.keys())[index];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setItem(key: string, value: string) {
|
|
22
|
+
this.storage.set(key, value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getItem(key: string) {
|
|
26
|
+
return this.storage.get(key) ?? null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
removeItem(key: string) {
|
|
30
|
+
this.storage.delete(key);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
clear() {
|
|
34
|
+
this.storage.clear();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -4,15 +4,14 @@
|
|
|
4
4
|
import { PlatformNotSupportedError } from '../Util/Errors';
|
|
5
5
|
import { KeyValueStorageInterface } from '../types';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class KeyValueStorage implements KeyValueStorageInterface {
|
|
8
11
|
storage?: Storage;
|
|
9
12
|
|
|
10
|
-
constructor() {
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
this.storage = window?.sessionStorage;
|
|
14
|
-
} catch (error) {}
|
|
15
|
-
}
|
|
13
|
+
constructor(storage?: Storage) {
|
|
14
|
+
this.storage = storage;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -21,7 +20,7 @@ class SessionStorageClass implements KeyValueStorageInterface {
|
|
|
21
20
|
* @param {object} value - the value
|
|
22
21
|
* @returns {string} value that was set
|
|
23
22
|
*/
|
|
24
|
-
async setItem(key: string, value: string)
|
|
23
|
+
async setItem(key: string, value: string) {
|
|
25
24
|
if (!this.storage) throw PlatformNotSupportedError;
|
|
26
25
|
this.storage.setItem(key, value);
|
|
27
26
|
}
|
|
@@ -32,7 +31,7 @@ class SessionStorageClass implements KeyValueStorageInterface {
|
|
|
32
31
|
* This is used to clear the storage
|
|
33
32
|
* @returns {string} the data item
|
|
34
33
|
*/
|
|
35
|
-
async getItem(key: string)
|
|
34
|
+
async getItem(key: string) {
|
|
36
35
|
if (!this.storage) throw PlatformNotSupportedError;
|
|
37
36
|
return this.storage.getItem(key);
|
|
38
37
|
}
|
|
@@ -42,7 +41,7 @@ class SessionStorageClass implements KeyValueStorageInterface {
|
|
|
42
41
|
* @param {string} key - the key being set
|
|
43
42
|
* @returns {string} value - value that was deleted
|
|
44
43
|
*/
|
|
45
|
-
async removeItem(key: string)
|
|
44
|
+
async removeItem(key: string) {
|
|
46
45
|
if (!this.storage) throw PlatformNotSupportedError;
|
|
47
46
|
this.storage.removeItem(key);
|
|
48
47
|
}
|
|
@@ -51,10 +50,8 @@ class SessionStorageClass implements KeyValueStorageInterface {
|
|
|
51
50
|
* This is used to clear the storage
|
|
52
51
|
* @returns {string} nothing
|
|
53
52
|
*/
|
|
54
|
-
async clear()
|
|
53
|
+
async clear() {
|
|
55
54
|
if (!this.storage) throw PlatformNotSupportedError;
|
|
56
55
|
this.storage.clear();
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
export const SessionStorage = new SessionStorageClass();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { KeyValueStorage } from './KeyValueStorage';
|
|
5
|
+
import { getSessionStorageWithFallback } from './utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class SessionStorage extends KeyValueStorage {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(getSessionStorageWithFallback());
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { DefaultStorage } from './DefaultStorage';
|
|
5
|
+
import { InMemoryStorage } from './InMemoryStorage';
|
|
6
|
+
import { KeyValueStorage } from './KeyValueStorage';
|
|
7
|
+
import { SessionStorage } from './SessionStorage';
|
|
8
|
+
|
|
9
|
+
export { CookieStorage } from './CookieStorage';
|
|
10
|
+
|
|
11
|
+
export const defaultStorage = new DefaultStorage();
|
|
12
|
+
export const sessionStorage = new SessionStorage();
|
|
13
|
+
export const sharedInMemoryStorage = new KeyValueStorage(new InMemoryStorage());
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { InMemoryStorage } from './InMemoryStorage';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
* @returns Either a reference to window.localStorage or an in-memory storage as fallback
|
|
9
|
+
*/
|
|
10
|
+
export const getDefaultStorageWithFallback = (): Storage =>
|
|
11
|
+
typeof window !== 'undefined' && window.localStorage
|
|
12
|
+
? window.localStorage
|
|
13
|
+
: new InMemoryStorage();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
* @returns Either a reference to window.sessionStorage or an in-memory storage as fallback
|
|
18
|
+
*/
|
|
19
|
+
export const getSessionStorageWithFallback = (): Storage =>
|
|
20
|
+
typeof window !== 'undefined' && window.sessionStorage
|
|
21
|
+
? window.sessionStorage
|
|
22
|
+
: new InMemoryStorage();
|
package/src/types/storage.ts
CHANGED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.FacebookOAuth = void 0;
|
|
40
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
41
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
42
|
-
var Logger_1 = require("../Logger");
|
|
43
|
-
var JS_1 = require("../Util/JS");
|
|
44
|
-
var Util_1 = require("../Util");
|
|
45
|
-
var logger = new Logger_1.ConsoleLogger('CognitoCredentials');
|
|
46
|
-
var waitForInit = new Promise(function (res, rej) {
|
|
47
|
-
if (!(0, JS_1.browserOrNode)().isBrowser) {
|
|
48
|
-
logger.debug('not in the browser, directly resolved');
|
|
49
|
-
return res();
|
|
50
|
-
}
|
|
51
|
-
var fb = window['FB'];
|
|
52
|
-
if (fb) {
|
|
53
|
-
logger.debug('FB SDK already loaded');
|
|
54
|
-
return res();
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
setTimeout(function () {
|
|
58
|
-
return res();
|
|
59
|
-
}, 2000);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
var FacebookOAuth = /** @class */ (function () {
|
|
63
|
-
function FacebookOAuth() {
|
|
64
|
-
this.initialized = false;
|
|
65
|
-
this.refreshFacebookToken = this.refreshFacebookToken.bind(this);
|
|
66
|
-
this._refreshFacebookTokenImpl = this._refreshFacebookTokenImpl.bind(this);
|
|
67
|
-
}
|
|
68
|
-
FacebookOAuth.prototype.refreshFacebookToken = function () {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
-
return __generator(this, function (_a) {
|
|
71
|
-
switch (_a.label) {
|
|
72
|
-
case 0:
|
|
73
|
-
if (!!this.initialized) return [3 /*break*/, 2];
|
|
74
|
-
logger.debug('need to wait for the Facebook SDK loaded');
|
|
75
|
-
return [4 /*yield*/, waitForInit];
|
|
76
|
-
case 1:
|
|
77
|
-
_a.sent();
|
|
78
|
-
this.initialized = true;
|
|
79
|
-
logger.debug('finish waiting');
|
|
80
|
-
_a.label = 2;
|
|
81
|
-
case 2: return [2 /*return*/, this._refreshFacebookTokenImpl()];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
FacebookOAuth.prototype._refreshFacebookTokenImpl = function () {
|
|
87
|
-
var fb = null;
|
|
88
|
-
if ((0, JS_1.browserOrNode)().isBrowser)
|
|
89
|
-
fb = window['FB'];
|
|
90
|
-
if (!fb) {
|
|
91
|
-
var errorMessage = 'no fb sdk available';
|
|
92
|
-
logger.debug(errorMessage);
|
|
93
|
-
return Promise.reject(new Util_1.NonRetryableError(errorMessage));
|
|
94
|
-
}
|
|
95
|
-
return new Promise(function (res, rej) {
|
|
96
|
-
fb.getLoginStatus(function (fbResponse) {
|
|
97
|
-
if (!fbResponse || !fbResponse.authResponse) {
|
|
98
|
-
var errorMessage = 'no response from facebook when refreshing the jwt token';
|
|
99
|
-
logger.debug(errorMessage);
|
|
100
|
-
// There is no definitive indication for a network error in
|
|
101
|
-
// fbResponse, so we are treating it as an invalid token.
|
|
102
|
-
rej(new Util_1.NonRetryableError(errorMessage));
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
var response = fbResponse.authResponse;
|
|
106
|
-
var accessToken = response.accessToken, expiresIn = response.expiresIn;
|
|
107
|
-
var date = new Date();
|
|
108
|
-
var expires_at = expiresIn * 1000 + date.getTime();
|
|
109
|
-
if (!accessToken) {
|
|
110
|
-
var errorMessage = 'the jwtToken is undefined';
|
|
111
|
-
logger.debug(errorMessage);
|
|
112
|
-
rej(new Util_1.NonRetryableError(errorMessage));
|
|
113
|
-
}
|
|
114
|
-
res({
|
|
115
|
-
token: accessToken,
|
|
116
|
-
expires_at: expires_at,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}, { scope: 'public_profile,email' });
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
return FacebookOAuth;
|
|
123
|
-
}());
|
|
124
|
-
exports.FacebookOAuth = FacebookOAuth;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.GoogleOAuth = void 0;
|
|
40
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
41
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
42
|
-
var Logger_1 = require("../Logger");
|
|
43
|
-
var JS_1 = require("../Util/JS");
|
|
44
|
-
var Util_1 = require("../Util");
|
|
45
|
-
var logger = new Logger_1.ConsoleLogger('CognitoCredentials');
|
|
46
|
-
var waitForInit = new Promise(function (res, rej) {
|
|
47
|
-
if (!(0, JS_1.browserOrNode)().isBrowser) {
|
|
48
|
-
logger.debug('not in the browser, directly resolved');
|
|
49
|
-
return res();
|
|
50
|
-
}
|
|
51
|
-
var ga = window['gapi'] && window['gapi'].auth2 ? window['gapi'].auth2 : null;
|
|
52
|
-
if (ga) {
|
|
53
|
-
logger.debug('google api already loaded');
|
|
54
|
-
return res();
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
setTimeout(function () {
|
|
58
|
-
return res();
|
|
59
|
-
}, 2000);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
var GoogleOAuth = /** @class */ (function () {
|
|
63
|
-
function GoogleOAuth() {
|
|
64
|
-
this.initialized = false;
|
|
65
|
-
this.refreshGoogleToken = this.refreshGoogleToken.bind(this);
|
|
66
|
-
this._refreshGoogleTokenImpl = this._refreshGoogleTokenImpl.bind(this);
|
|
67
|
-
}
|
|
68
|
-
GoogleOAuth.prototype.refreshGoogleToken = function () {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
-
return __generator(this, function (_a) {
|
|
71
|
-
switch (_a.label) {
|
|
72
|
-
case 0:
|
|
73
|
-
if (!!this.initialized) return [3 /*break*/, 2];
|
|
74
|
-
logger.debug('need to wait for the Google SDK loaded');
|
|
75
|
-
return [4 /*yield*/, waitForInit];
|
|
76
|
-
case 1:
|
|
77
|
-
_a.sent();
|
|
78
|
-
this.initialized = true;
|
|
79
|
-
logger.debug('finish waiting');
|
|
80
|
-
_a.label = 2;
|
|
81
|
-
case 2: return [2 /*return*/, this._refreshGoogleTokenImpl()];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
GoogleOAuth.prototype._refreshGoogleTokenImpl = function () {
|
|
87
|
-
var ga = null;
|
|
88
|
-
if ((0, JS_1.browserOrNode)().isBrowser)
|
|
89
|
-
ga = window['gapi'] && window['gapi'].auth2 ? window['gapi'].auth2 : null;
|
|
90
|
-
if (!ga) {
|
|
91
|
-
logger.debug('no gapi auth2 available');
|
|
92
|
-
return Promise.reject('no gapi auth2 available');
|
|
93
|
-
}
|
|
94
|
-
return new Promise(function (res, rej) {
|
|
95
|
-
ga.getAuthInstance()
|
|
96
|
-
.then(function (googleAuth) {
|
|
97
|
-
if (!googleAuth) {
|
|
98
|
-
logger.debug('google Auth undefined');
|
|
99
|
-
rej(new Util_1.NonRetryableError('google Auth undefined'));
|
|
100
|
-
}
|
|
101
|
-
var googleUser = googleAuth.currentUser.get();
|
|
102
|
-
// refresh the token
|
|
103
|
-
if (googleUser.isSignedIn()) {
|
|
104
|
-
logger.debug('refreshing the google access token');
|
|
105
|
-
googleUser
|
|
106
|
-
.reloadAuthResponse()
|
|
107
|
-
.then(function (authResponse) {
|
|
108
|
-
var id_token = authResponse.id_token, expires_at = authResponse.expires_at;
|
|
109
|
-
res({ token: id_token, expires_at: expires_at });
|
|
110
|
-
})
|
|
111
|
-
.catch(function (err) {
|
|
112
|
-
if (err &&
|
|
113
|
-
err.error === 'network_error') {
|
|
114
|
-
// Not using NonRetryableError so handler will be retried
|
|
115
|
-
rej('Network error reloading google auth response');
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
rej(new Util_1.NonRetryableError('Failed to reload google auth response'));
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
rej(new Util_1.NonRetryableError('User is not signed in with Google'));
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
.catch(function (err) {
|
|
127
|
-
logger.debug('Failed to refresh google token', err);
|
|
128
|
-
rej(new Util_1.NonRetryableError('Failed to refresh google token'));
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
return GoogleOAuth;
|
|
133
|
-
}());
|
|
134
|
-
exports.GoogleOAuth = GoogleOAuth;
|
package/lib/OAuthHelper/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FacebookOAuth = exports.GoogleOAuth = void 0;
|
|
4
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
var GoogleOAuth_1 = require("./GoogleOAuth");
|
|
7
|
-
var FacebookOAuth_1 = require("./FacebookOAuth");
|
|
8
|
-
exports.GoogleOAuth = new GoogleOAuth_1.GoogleOAuth();
|
|
9
|
-
exports.FacebookOAuth = new FacebookOAuth_1.FacebookOAuth();
|