@aws-amplify/core 6.0.1-console-preview.047a1dd.0 → 6.0.1-next.51e478e.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/Cache/Utils/CacheUtils.js +4 -2
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/RNComponents/index.d.ts +6 -0
- package/lib/RNComponents/index.js +16 -0
- package/lib/{providers/pinpoint/utils → RNComponents}/isAppInForeground.js +4 -1
- package/lib/RNComponents/reactnative.d.ts +3 -0
- package/lib/RNComponents/reactnative.js +14 -0
- package/lib/{storage/CookieStorage.d.ts → StorageHelper/cookieStorage.d.ts} +3 -4
- package/lib/{storage/CookieStorage.js → StorageHelper/cookieStorage.js} +83 -35
- package/lib/StorageHelper/inMemoryStorage.d.ts +10 -0
- package/lib/StorageHelper/inMemoryStorage.js +82 -0
- package/lib/StorageHelper/index.d.ts +45 -0
- package/lib/StorageHelper/index.js +83 -0
- package/lib/{storage/DefaultStorage.native.d.ts → StorageHelper/localStorage.d.ts} +6 -7
- package/lib/{storage/KeyValueStorage.js → StorageHelper/localStorage.js} +15 -13
- package/lib/StorageHelper/reactnative.d.ts +83 -0
- package/lib/StorageHelper/reactnative.js +250 -0
- package/lib/{storage/KeyValueStorage.d.ts → StorageHelper/sessionStorage.d.ts} +4 -5
- package/lib/{storage/DefaultStorage.native.js → StorageHelper/sessionStorage.js} +43 -46
- package/lib/index.d.ts +1 -1
- package/lib/index.js +8 -6
- package/lib/libraryUtils.d.ts +1 -0
- package/lib/libraryUtils.js +5 -1
- package/lib/parseAWSExports.js +1 -20
- package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +5 -7
- package/lib/singleton/types.d.ts +1 -4
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/storage.d.ts +0 -3
- package/lib-esm/Cache/Utils/CacheUtils.js +4 -2
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/RNComponents/index.d.ts +6 -0
- package/lib-esm/RNComponents/index.js +13 -0
- package/lib-esm/RNComponents/isAppInForeground.js +6 -0
- package/lib-esm/RNComponents/reactnative.d.ts +3 -0
- package/lib-esm/RNComponents/reactnative.js +6 -0
- package/lib-esm/{storage/CookieStorage.d.ts → StorageHelper/cookieStorage.d.ts} +3 -4
- package/lib-esm/{storage/CookieStorage.js → StorageHelper/cookieStorage.js} +61 -36
- package/lib-esm/StorageHelper/inMemoryStorage.d.ts +10 -0
- package/lib-esm/StorageHelper/inMemoryStorage.js +79 -0
- package/lib-esm/StorageHelper/index.d.ts +45 -0
- package/lib-esm/StorageHelper/index.js +76 -0
- package/lib-esm/{storage/DefaultStorage.native.d.ts → StorageHelper/localStorage.d.ts} +6 -7
- package/lib-esm/{storage/KeyValueStorage.js → StorageHelper/localStorage.js} +14 -12
- package/lib-esm/StorageHelper/reactnative.d.ts +83 -0
- package/lib-esm/StorageHelper/reactnative.js +244 -0
- package/lib-esm/{storage/KeyValueStorage.d.ts → StorageHelper/sessionStorage.d.ts} +4 -5
- package/lib-esm/{storage/DefaultStorage.native.js → StorageHelper/sessionStorage.js} +42 -45
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/libraryUtils.d.ts +1 -0
- package/lib-esm/libraryUtils.js +1 -0
- package/lib-esm/parseAWSExports.js +1 -20
- package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +5 -7
- package/lib-esm/singleton/types.d.ts +1 -4
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/storage.d.ts +0 -3
- package/package.json +4 -3
- package/src/Cache/Utils/CacheUtils.ts +4 -2
- package/src/Platform/version.ts +1 -1
- package/src/RNComponents/index.ts +16 -0
- package/src/RNComponents/isAppInForeground.ts +8 -0
- package/src/RNComponents/reactnative.ts +6 -0
- package/src/StorageHelper/cookieStorage.ts +99 -0
- package/src/StorageHelper/inMemoryStorage.ts +32 -0
- package/src/StorageHelper/index.ts +78 -0
- package/src/StorageHelper/localStorage.ts +60 -0
- package/src/StorageHelper/reactnative.ts +182 -0
- package/src/{storage/KeyValueStorage.ts → StorageHelper/sessionStorage.ts} +13 -10
- package/src/index.ts +6 -4
- package/src/libraryUtils.ts +1 -0
- package/src/parseAWSExports.ts +0 -26
- package/src/providers/pinpoint/utils/PinpointEventBuffer.ts +12 -16
- package/src/singleton/types.ts +1 -4
- package/src/types/storage.ts +0 -4
- package/lib/providers/pinpoint/utils/isAppInForeground.native.d.ts +0 -1
- package/lib/providers/pinpoint/utils/isAppInForeground.native.js +0 -9
- package/lib/singleton/API/types.d.ts +0 -34
- package/lib/singleton/API/types.js +0 -2
- package/lib/storage/CookieStorage.native.d.ts +0 -7
- package/lib/storage/CookieStorage.native.js +0 -32
- package/lib/storage/DefaultStorage.d.ts +0 -7
- package/lib/storage/DefaultStorage.js +0 -33
- package/lib/storage/InMemoryStorage.d.ts +0 -12
- package/lib/storage/InMemoryStorage.js +0 -41
- package/lib/storage/SessionStorage.d.ts +0 -7
- package/lib/storage/SessionStorage.js +0 -33
- package/lib/storage/index.d.ts +0 -7
- package/lib/storage/index.js +0 -14
- package/lib/storage/utils.d.ts +0 -10
- package/lib/storage/utils.js +0 -26
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.js +0 -3
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.d.ts +0 -1
- package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.js +0 -5
- package/lib-esm/singleton/API/types.d.ts +0 -34
- package/lib-esm/singleton/API/types.js +0 -1
- package/lib-esm/storage/CookieStorage.native.d.ts +0 -7
- package/lib-esm/storage/CookieStorage.native.js +0 -29
- package/lib-esm/storage/DefaultStorage.d.ts +0 -7
- package/lib-esm/storage/DefaultStorage.js +0 -30
- package/lib-esm/storage/InMemoryStorage.d.ts +0 -12
- package/lib-esm/storage/InMemoryStorage.js +0 -38
- package/lib-esm/storage/SessionStorage.d.ts +0 -7
- package/lib-esm/storage/SessionStorage.js +0 -30
- package/lib-esm/storage/index.d.ts +0 -7
- package/lib-esm/storage/index.js +0 -10
- package/lib-esm/storage/utils.d.ts +0 -10
- package/lib-esm/storage/utils.js +0 -21
- package/src/providers/pinpoint/utils/isAppInForeground.native.ts +0 -7
- package/src/providers/pinpoint/utils/isAppInForeground.ts +0 -4
- package/src/singleton/API/types.ts +0 -31
- package/src/storage/CookieStorage.native.ts +0 -13
- package/src/storage/CookieStorage.ts +0 -72
- package/src/storage/DefaultStorage.native.ts +0 -78
- package/src/storage/DefaultStorage.ts +0 -14
- package/src/storage/InMemoryStorage.ts +0 -36
- package/src/storage/SessionStorage.ts +0 -14
- package/src/storage/index.ts +0 -13
- package/src/storage/utils.ts +0 -22
- /package/lib/{providers/pinpoint/utils → RNComponents}/isAppInForeground.d.ts +0 -0
- /package/lib-esm/{providers/pinpoint/utils → RNComponents}/isAppInForeground.d.ts +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import * as Cookies from 'js-cookie';
|
|
5
|
+
import {
|
|
6
|
+
CookieStorageData,
|
|
7
|
+
KeyValueStorageInterface,
|
|
8
|
+
SameSite,
|
|
9
|
+
} from '../types';
|
|
10
|
+
|
|
11
|
+
export class CookieStorage implements KeyValueStorageInterface {
|
|
12
|
+
domain?: string;
|
|
13
|
+
path: string;
|
|
14
|
+
expires?: number; // days;
|
|
15
|
+
secure?: boolean;
|
|
16
|
+
sameSite?: SameSite;
|
|
17
|
+
|
|
18
|
+
constructor(data: CookieStorageData = {}) {
|
|
19
|
+
if (data.domain) {
|
|
20
|
+
this.domain = data.domain;
|
|
21
|
+
}
|
|
22
|
+
if (data.path) {
|
|
23
|
+
this.path = data.path;
|
|
24
|
+
} else {
|
|
25
|
+
this.path = '/';
|
|
26
|
+
}
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(data, 'expires')) {
|
|
28
|
+
this.expires = data.expires;
|
|
29
|
+
} else {
|
|
30
|
+
this.expires = 365;
|
|
31
|
+
}
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(data, 'secure')) {
|
|
33
|
+
this.secure = data.secure;
|
|
34
|
+
} else {
|
|
35
|
+
this.secure = true;
|
|
36
|
+
}
|
|
37
|
+
if (data.hasOwnProperty('sameSite')) {
|
|
38
|
+
if (
|
|
39
|
+
!data.sameSite ||
|
|
40
|
+
!['strict', 'lax', 'none'].includes(data.sameSite)
|
|
41
|
+
) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
'The sameSite value of cookieStorage must be "lax", "strict" or "none".'
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (data.sameSite === 'none' && !this.secure) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
'sameSite = None requires the Secure attribute in latest browser versions.'
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
this.sameSite = data.sameSite;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
56
|
+
const options: CookieStorageData = {
|
|
57
|
+
path: this.path,
|
|
58
|
+
expires: this.expires,
|
|
59
|
+
domain: this.domain,
|
|
60
|
+
secure: this.secure,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (this.sameSite) {
|
|
64
|
+
options.sameSite = this.sameSite;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Cookies.set(key, value, options);
|
|
68
|
+
return Cookies.get(key);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async getItem(key: string): Promise<string> {
|
|
72
|
+
return Cookies.get(key);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async removeItem(key: string): Promise<void> {
|
|
76
|
+
const options: CookieStorageData = {
|
|
77
|
+
path: this.path,
|
|
78
|
+
expires: this.expires,
|
|
79
|
+
domain: this.domain,
|
|
80
|
+
secure: this.secure,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (this.sameSite) {
|
|
84
|
+
options.sameSite = this.sameSite;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
Cookies.remove(key, options);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async clear(): Promise<void> {
|
|
91
|
+
const cookies = Cookies.get();
|
|
92
|
+
const numKeys = Object.keys(cookies).length;
|
|
93
|
+
const promiseArray: Promise<void>[] = [];
|
|
94
|
+
for (let index = 0; index < numKeys; ++index) {
|
|
95
|
+
promiseArray.push(this.removeItem(Object.keys(cookies)[index]));
|
|
96
|
+
}
|
|
97
|
+
await Promise.all(promiseArray);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { KeyValueStorageInterface } from '../types';
|
|
5
|
+
|
|
6
|
+
class MemoryKeyValueStorageClass implements KeyValueStorageInterface {
|
|
7
|
+
myStorage: Record<string, string> = {};
|
|
8
|
+
|
|
9
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
10
|
+
this.myStorage[key] = value;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async getItem(key: string): Promise<string | null> {
|
|
15
|
+
return this.myStorage[key];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async removeItem(key: string): Promise<void> {
|
|
19
|
+
delete this.myStorage[key];
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async clear(): Promise<void> {
|
|
24
|
+
Object.keys(this.myStorage).forEach(key => {
|
|
25
|
+
delete this.myStorage[key];
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const MemoryKeyValueStorage = new MemoryKeyValueStorageClass();
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
let dataMemory: Record<string, string> = {};
|
|
5
|
+
|
|
6
|
+
/** @class */
|
|
7
|
+
export class MemoryStorage {
|
|
8
|
+
/**
|
|
9
|
+
* This is used to set a specific item in storage
|
|
10
|
+
* @param {string} key - the key for the item
|
|
11
|
+
* @param {object} value - the value
|
|
12
|
+
* @returns {string} value that was set
|
|
13
|
+
*/
|
|
14
|
+
static setItem(key: string, value: any) {
|
|
15
|
+
dataMemory[key] = value;
|
|
16
|
+
return dataMemory[key];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This is used to get a specific key from storage
|
|
21
|
+
* @param {string} key - the key for the item
|
|
22
|
+
* This is used to clear the storage
|
|
23
|
+
* @returns {string} the data item
|
|
24
|
+
*/
|
|
25
|
+
static getItem(key: string) {
|
|
26
|
+
return Object.prototype.hasOwnProperty.call(dataMemory, key)
|
|
27
|
+
? dataMemory[key]
|
|
28
|
+
: undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* This is used to remove an item from storage
|
|
33
|
+
* @param {string} key - the key being set
|
|
34
|
+
* @returns {string} value - value that was deleted
|
|
35
|
+
*/
|
|
36
|
+
static removeItem(key: string) {
|
|
37
|
+
return delete dataMemory[key];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* This is used to clear the storage
|
|
42
|
+
* @returns {string} nothing
|
|
43
|
+
*/
|
|
44
|
+
static clear() {
|
|
45
|
+
dataMemory = {};
|
|
46
|
+
return dataMemory;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class StorageHelper {
|
|
51
|
+
private storageWindow: any;
|
|
52
|
+
/**
|
|
53
|
+
* This is used to get a storage object
|
|
54
|
+
* @returns {object} the storage
|
|
55
|
+
*/
|
|
56
|
+
constructor() {
|
|
57
|
+
try {
|
|
58
|
+
this.storageWindow = window.localStorage;
|
|
59
|
+
this.storageWindow.setItem('aws.amplify.test-ls', 1);
|
|
60
|
+
this.storageWindow.removeItem('aws.amplify.test-ls');
|
|
61
|
+
} catch (exception) {
|
|
62
|
+
this.storageWindow = MemoryStorage;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This is used to return the storage
|
|
68
|
+
* @returns {object} the storage
|
|
69
|
+
*/
|
|
70
|
+
getStorage(): any {
|
|
71
|
+
return this.storageWindow;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { SessionStorage } from './sessionStorage';
|
|
76
|
+
export { LocalStorage } from './localStorage';
|
|
77
|
+
export { MemoryKeyValueStorage } from './inMemoryStorage';
|
|
78
|
+
export { CookieStorage } from './cookieStorage';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { KeyValueStorageInterface } from "../types";
|
|
5
|
+
import { PlatformNotSupportedError } from '../Util/Errors';
|
|
6
|
+
|
|
7
|
+
class LocalStorageClass implements KeyValueStorageInterface {
|
|
8
|
+
storage?: Storage;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
if (typeof window !== undefined) {
|
|
12
|
+
try {
|
|
13
|
+
this.storage = window?.localStorage;
|
|
14
|
+
} catch (error) {}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This is used to set a specific item in storage
|
|
20
|
+
* @param {string} key - the key for the item
|
|
21
|
+
* @param {object} value - the value
|
|
22
|
+
* @returns {string} value that was set
|
|
23
|
+
*/
|
|
24
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
25
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
26
|
+
this.storage.setItem(key, value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* This is used to get a specific key from storage
|
|
31
|
+
* @param {string} key - the key for the item
|
|
32
|
+
* This is used to clear the storage
|
|
33
|
+
* @returns {string} the data item
|
|
34
|
+
*/
|
|
35
|
+
async getItem(key: string): Promise<string | null> {
|
|
36
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
37
|
+
return this.storage.getItem(key);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* This is used to remove an item from storage
|
|
42
|
+
* @param {string} key - the key being set
|
|
43
|
+
* @returns {string} value - value that was deleted
|
|
44
|
+
*/
|
|
45
|
+
async removeItem(key: string): Promise<void> {
|
|
46
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
47
|
+
this.storage.removeItem(key);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* This is used to clear the storage
|
|
52
|
+
* @returns {string} nothing
|
|
53
|
+
*/
|
|
54
|
+
async clear(): Promise<void> {
|
|
55
|
+
if (!this.storage) throw PlatformNotSupportedError;
|
|
56
|
+
this.storage.clear();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const LocalStorage = new LocalStorageClass();
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
4
|
+
import { KeyValueStorageInterface } from '../types';
|
|
5
|
+
|
|
6
|
+
const MEMORY_KEY_PREFIX = '@MemoryStorage:';
|
|
7
|
+
let dataMemory: Record<string, string | null> = {};
|
|
8
|
+
|
|
9
|
+
/** @class */
|
|
10
|
+
class MemoryStorage {
|
|
11
|
+
static syncPromise: Promise<void> | null = null;
|
|
12
|
+
/**
|
|
13
|
+
* This is used to set a specific item in storage
|
|
14
|
+
* @param {string} key - the key for the item
|
|
15
|
+
* @param {object} value - the value
|
|
16
|
+
* @returns {string} value that was set
|
|
17
|
+
*/
|
|
18
|
+
static setItem(key: string, value: string) {
|
|
19
|
+
if (value) {
|
|
20
|
+
AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value);
|
|
21
|
+
dataMemory[key] = value;
|
|
22
|
+
return dataMemory[key];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* This is used to get a specific key from storage
|
|
28
|
+
* @param {string} key - the key for the item
|
|
29
|
+
* This is used to clear the storage
|
|
30
|
+
* @returns {string} the data item
|
|
31
|
+
*/
|
|
32
|
+
static getItem(key: string) {
|
|
33
|
+
return Object.prototype.hasOwnProperty.call(dataMemory, key)
|
|
34
|
+
? dataMemory[key]
|
|
35
|
+
: undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* This is used to remove an item from storage
|
|
40
|
+
* @param {string} key - the key being set
|
|
41
|
+
* @returns {string} value - value that was deleted
|
|
42
|
+
*/
|
|
43
|
+
static removeItem(key: string) {
|
|
44
|
+
AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key);
|
|
45
|
+
return delete dataMemory[key];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* This is used to clear the storage
|
|
50
|
+
* @returns {string} nothing
|
|
51
|
+
*/
|
|
52
|
+
static clear() {
|
|
53
|
+
dataMemory = {};
|
|
54
|
+
return dataMemory;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
|
|
59
|
+
* @returns {void}
|
|
60
|
+
*/
|
|
61
|
+
static sync() {
|
|
62
|
+
if (!MemoryStorage.syncPromise) {
|
|
63
|
+
MemoryStorage.syncPromise = new Promise<void>((res, rej) => {
|
|
64
|
+
AsyncStorage.getAllKeys((errKeys, keys) => {
|
|
65
|
+
if (errKeys) rej(errKeys);
|
|
66
|
+
|
|
67
|
+
const memoryKeys =
|
|
68
|
+
keys?.filter(key => key.startsWith(MEMORY_KEY_PREFIX)) ?? [];
|
|
69
|
+
|
|
70
|
+
AsyncStorage.multiGet(memoryKeys, (err, stores) => {
|
|
71
|
+
if (err) rej(err);
|
|
72
|
+
stores &&
|
|
73
|
+
stores.map((result, index, store) => {
|
|
74
|
+
const key = store[index][0];
|
|
75
|
+
const value = store[index][1];
|
|
76
|
+
const memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
|
|
77
|
+
dataMemory[memoryKey] = value;
|
|
78
|
+
});
|
|
79
|
+
res();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return MemoryStorage.syncPromise;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class StorageHelper {
|
|
89
|
+
private storageWindow;
|
|
90
|
+
/**
|
|
91
|
+
* This is used to get a storage object
|
|
92
|
+
* @returns {object} the storage
|
|
93
|
+
*/
|
|
94
|
+
constructor() {
|
|
95
|
+
this.storageWindow = MemoryStorage;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* This is used to return the storage
|
|
100
|
+
* @returns {object} the storage
|
|
101
|
+
*/
|
|
102
|
+
getStorage() {
|
|
103
|
+
return this.storageWindow;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
class AsyncStorageClass implements KeyValueStorageInterface {
|
|
108
|
+
syncPromise: Promise<void> | null = null;
|
|
109
|
+
/**
|
|
110
|
+
* This is used to set a specific item in storage
|
|
111
|
+
* @param {string} key - the key for the item
|
|
112
|
+
* @param {object} value - the value
|
|
113
|
+
* @returns {string} value that was set
|
|
114
|
+
*/
|
|
115
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
116
|
+
if (value) {
|
|
117
|
+
await AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value);
|
|
118
|
+
dataMemory[key] = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* This is used to get a specific key from storage
|
|
124
|
+
* @param {string} key - the key for the item
|
|
125
|
+
* This is used to clear the storage
|
|
126
|
+
* @returns {string} the data item
|
|
127
|
+
*/
|
|
128
|
+
async getItem(key: string): Promise<string | null> {
|
|
129
|
+
return Object.prototype.hasOwnProperty.call(dataMemory, key)
|
|
130
|
+
? dataMemory[key]
|
|
131
|
+
: null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* This is used to remove an item from storage
|
|
136
|
+
* @param {string} key - the key being set
|
|
137
|
+
* @returns {string} value - value that was deleted
|
|
138
|
+
*/
|
|
139
|
+
async removeItem(key: string): Promise<void> {
|
|
140
|
+
await AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key);
|
|
141
|
+
delete dataMemory[key];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* This is used to clear the storage
|
|
146
|
+
* @returns {string} nothing
|
|
147
|
+
*/
|
|
148
|
+
async clear(): Promise<void> {
|
|
149
|
+
dataMemory = {};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
|
|
154
|
+
* @returns {void}
|
|
155
|
+
*/
|
|
156
|
+
async sync() {
|
|
157
|
+
if (!this.syncPromise) {
|
|
158
|
+
this.syncPromise = new Promise<void>((res, rej) => {
|
|
159
|
+
AsyncStorage.getAllKeys((errKeys, keys) => {
|
|
160
|
+
if (errKeys) rej(errKeys);
|
|
161
|
+
const memoryKeys =
|
|
162
|
+
keys?.filter(key => key.startsWith(MEMORY_KEY_PREFIX)) ?? [];
|
|
163
|
+
|
|
164
|
+
AsyncStorage.multiGet(memoryKeys, (err, stores) => {
|
|
165
|
+
if (err) rej(err);
|
|
166
|
+
stores &&
|
|
167
|
+
stores.map((result, index, store) => {
|
|
168
|
+
const key = store[index][0];
|
|
169
|
+
const value = store[index][1];
|
|
170
|
+
const memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
|
|
171
|
+
dataMemory[memoryKey] = value;
|
|
172
|
+
});
|
|
173
|
+
res();
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// TODO: Add this to the react-native Amplify package.
|
|
182
|
+
export const AsyncStorageKeyValue = new AsyncStorageClass();
|
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
import { PlatformNotSupportedError } from '../Util/Errors';
|
|
5
5
|
import { KeyValueStorageInterface } from '../types';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export class KeyValueStorage implements KeyValueStorageInterface {
|
|
7
|
+
class SessionStorageClass implements KeyValueStorageInterface {
|
|
11
8
|
storage?: Storage;
|
|
12
9
|
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
10
|
+
constructor() {
|
|
11
|
+
if (typeof window !== undefined) {
|
|
12
|
+
try {
|
|
13
|
+
this.storage = window?.sessionStorage;
|
|
14
|
+
} catch (error) {}
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -20,7 +21,7 @@ export class KeyValueStorage implements KeyValueStorageInterface {
|
|
|
20
21
|
* @param {object} value - the value
|
|
21
22
|
* @returns {string} value that was set
|
|
22
23
|
*/
|
|
23
|
-
async setItem(key: string, value: string) {
|
|
24
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
24
25
|
if (!this.storage) throw PlatformNotSupportedError;
|
|
25
26
|
this.storage.setItem(key, value);
|
|
26
27
|
}
|
|
@@ -31,7 +32,7 @@ export class KeyValueStorage implements KeyValueStorageInterface {
|
|
|
31
32
|
* This is used to clear the storage
|
|
32
33
|
* @returns {string} the data item
|
|
33
34
|
*/
|
|
34
|
-
async getItem(key: string) {
|
|
35
|
+
async getItem(key: string): Promise<string | null> {
|
|
35
36
|
if (!this.storage) throw PlatformNotSupportedError;
|
|
36
37
|
return this.storage.getItem(key);
|
|
37
38
|
}
|
|
@@ -41,7 +42,7 @@ export class KeyValueStorage implements KeyValueStorageInterface {
|
|
|
41
42
|
* @param {string} key - the key being set
|
|
42
43
|
* @returns {string} value - value that was deleted
|
|
43
44
|
*/
|
|
44
|
-
async removeItem(key: string) {
|
|
45
|
+
async removeItem(key: string): Promise<void> {
|
|
45
46
|
if (!this.storage) throw PlatformNotSupportedError;
|
|
46
47
|
this.storage.removeItem(key);
|
|
47
48
|
}
|
|
@@ -50,8 +51,10 @@ export class KeyValueStorage implements KeyValueStorageInterface {
|
|
|
50
51
|
* This is used to clear the storage
|
|
51
52
|
* @returns {string} nothing
|
|
52
53
|
*/
|
|
53
|
-
async clear() {
|
|
54
|
+
async clear(): Promise<void> {
|
|
54
55
|
if (!this.storage) throw PlatformNotSupportedError;
|
|
55
56
|
this.storage.clear();
|
|
56
57
|
}
|
|
57
58
|
}
|
|
59
|
+
|
|
60
|
+
export const SessionStorage = new SessionStorageClass();
|
package/src/index.ts
CHANGED
|
@@ -50,11 +50,13 @@ export { UserProfile } from './types';
|
|
|
50
50
|
|
|
51
51
|
// Storage helpers
|
|
52
52
|
export {
|
|
53
|
+
StorageHelper,
|
|
54
|
+
MemoryStorage,
|
|
55
|
+
LocalStorage,
|
|
53
56
|
CookieStorage,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} from './storage';
|
|
57
|
+
SessionStorage,
|
|
58
|
+
MemoryKeyValueStorage,
|
|
59
|
+
} from './StorageHelper';
|
|
58
60
|
export { KeyValueStorageInterface } from './types';
|
|
59
61
|
|
|
60
62
|
// Cache exports
|
package/src/libraryUtils.ts
CHANGED
|
@@ -97,6 +97,7 @@ export {
|
|
|
97
97
|
AmplifyError,
|
|
98
98
|
AmplifyErrorString,
|
|
99
99
|
} from './Util/Errors';
|
|
100
|
+
export { AppState, AsyncStorage, Linking } from './RNComponents';
|
|
100
101
|
export { ErrorParams, AmplifyErrorMap, ServiceError } from './types';
|
|
101
102
|
export {
|
|
102
103
|
INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
|
package/src/parseAWSExports.ts
CHANGED
|
@@ -3,12 +3,6 @@
|
|
|
3
3
|
import { OAuthConfig } from './singleton/Auth/types';
|
|
4
4
|
import { ResourcesConfig } from './singleton/types';
|
|
5
5
|
|
|
6
|
-
const authTypeMapping: Record<any, any> = {
|
|
7
|
-
API_KEY: 'apiKey',
|
|
8
|
-
AWS_IAM: 'iam',
|
|
9
|
-
AMAZON_COGNITO_USER_POOLS: 'jwt',
|
|
10
|
-
};
|
|
11
|
-
|
|
12
6
|
/**
|
|
13
7
|
* This utility converts the `aws-exports.js` file generated by the Amplify CLI into a {@link ResourcesConfig} object
|
|
14
8
|
* consumable by Amplify.
|
|
@@ -17,15 +11,10 @@ const authTypeMapping: Record<any, any> = {
|
|
|
17
11
|
*
|
|
18
12
|
* @returns A {@link ResourcesConfig} object.
|
|
19
13
|
*/
|
|
20
|
-
|
|
21
14
|
export const parseAWSExports = (
|
|
22
15
|
config: Record<string, any> = {}
|
|
23
16
|
): ResourcesConfig => {
|
|
24
17
|
const {
|
|
25
|
-
aws_appsync_apiKey,
|
|
26
|
-
aws_appsync_authenticationType,
|
|
27
|
-
aws_appsync_graphqlEndpoint,
|
|
28
|
-
aws_appsync_region,
|
|
29
18
|
aws_cognito_identity_pool_id,
|
|
30
19
|
aws_cognito_sign_up_verification_method,
|
|
31
20
|
aws_mandatory_sign_in,
|
|
@@ -51,21 +40,6 @@ export const parseAWSExports = (
|
|
|
51
40
|
};
|
|
52
41
|
}
|
|
53
42
|
|
|
54
|
-
// TODO: Need to support all API configurations
|
|
55
|
-
// API
|
|
56
|
-
if (aws_appsync_graphqlEndpoint) {
|
|
57
|
-
amplifyConfig.API = {
|
|
58
|
-
AppSync: {
|
|
59
|
-
defaultAuthMode: {
|
|
60
|
-
type: authTypeMapping[aws_appsync_authenticationType],
|
|
61
|
-
apiKey: aws_appsync_apiKey,
|
|
62
|
-
},
|
|
63
|
-
endpoint: aws_appsync_graphqlEndpoint,
|
|
64
|
-
region: aws_appsync_region,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
43
|
// Auth
|
|
70
44
|
if (aws_cognito_identity_pool_id || aws_user_pools_id) {
|
|
71
45
|
amplifyConfig.Auth = {
|
|
@@ -8,14 +8,14 @@ import {
|
|
|
8
8
|
PutEventsInput,
|
|
9
9
|
PutEventsOutput,
|
|
10
10
|
} from '../../../AwsClients/Pinpoint';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
12
|
EventBufferConfig,
|
|
13
13
|
BufferedEvent,
|
|
14
14
|
BufferedEventMap,
|
|
15
|
-
EventBuffer
|
|
15
|
+
EventBuffer
|
|
16
16
|
} from '../types/buffer';
|
|
17
17
|
import { AuthSession } from '../../../singleton/Auth/types';
|
|
18
|
-
import { isAppInForeground } from '
|
|
18
|
+
import { isAppInForeground } from '../../../RNComponents/isAppInForeground';
|
|
19
19
|
|
|
20
20
|
const logger = new Logger('PinpointEventBuffer');
|
|
21
21
|
const RETRYABLE_CODES = [429, 500];
|
|
@@ -39,9 +39,7 @@ export class PinpointEventBuffer {
|
|
|
39
39
|
|
|
40
40
|
public push(event: BufferedEvent) {
|
|
41
41
|
if (this._buffer.length >= this._config.bufferSize) {
|
|
42
|
-
logger.debug('Exceeded Pinpoint event buffer limits, event dropped.', {
|
|
43
|
-
eventId: event.eventId,
|
|
44
|
-
});
|
|
42
|
+
logger.debug('Exceeded Pinpoint event buffer limits, event dropped.', { eventId: event.eventId });
|
|
45
43
|
|
|
46
44
|
return;
|
|
47
45
|
}
|
|
@@ -114,18 +112,16 @@ export class PinpointEventBuffer {
|
|
|
114
112
|
}
|
|
115
113
|
}
|
|
116
114
|
|
|
117
|
-
private _generateBatchEventParams(
|
|
118
|
-
eventMap: BufferedEventMap
|
|
119
|
-
): PutEventsInput {
|
|
115
|
+
private _generateBatchEventParams(eventMap: BufferedEventMap): PutEventsInput {
|
|
120
116
|
const batchItem: Record<string, EventsBatch> = {};
|
|
121
117
|
|
|
122
118
|
Object.values(eventMap).forEach(item => {
|
|
123
119
|
const { event, timestamp, endpointId, eventId, session } = item;
|
|
124
120
|
const { name, attributes, metrics } = event;
|
|
125
|
-
|
|
121
|
+
|
|
126
122
|
batchItem[endpointId] = {
|
|
127
123
|
Endpoint: {
|
|
128
|
-
...batchItem[endpointId]?.Endpoint
|
|
124
|
+
...batchItem[endpointId]?.Endpoint
|
|
129
125
|
},
|
|
130
126
|
Events: {
|
|
131
127
|
...batchItem[endpointId]?.Events,
|
|
@@ -135,11 +131,11 @@ export class PinpointEventBuffer {
|
|
|
135
131
|
Attributes: attributes,
|
|
136
132
|
Metrics: metrics,
|
|
137
133
|
Session: session,
|
|
138
|
-
}
|
|
134
|
+
}
|
|
139
135
|
},
|
|
140
136
|
};
|
|
141
137
|
});
|
|
142
|
-
|
|
138
|
+
|
|
143
139
|
return {
|
|
144
140
|
ApplicationId: this._config.appId,
|
|
145
141
|
EventsRequest: {
|
|
@@ -204,7 +200,7 @@ export class PinpointEventBuffer {
|
|
|
204
200
|
logger.warn('Pinpoint event failed to send.', {
|
|
205
201
|
eventId,
|
|
206
202
|
name,
|
|
207
|
-
message: Message
|
|
203
|
+
message: Message
|
|
208
204
|
});
|
|
209
205
|
});
|
|
210
206
|
});
|
|
@@ -226,7 +222,7 @@ export class PinpointEventBuffer {
|
|
|
226
222
|
logger.debug('Resending event.', {
|
|
227
223
|
eventId,
|
|
228
224
|
name,
|
|
229
|
-
remainingAttempts: bufferedEvent.resendLimit
|
|
225
|
+
remainingAttempts: bufferedEvent.resendLimit
|
|
230
226
|
});
|
|
231
227
|
eligibleEvents.push({ [eventId!]: bufferedEvent });
|
|
232
228
|
return;
|
|
@@ -234,7 +230,7 @@ export class PinpointEventBuffer {
|
|
|
234
230
|
|
|
235
231
|
logger.debug('No retry attempts remaining for event.', {
|
|
236
232
|
eventId,
|
|
237
|
-
name
|
|
233
|
+
name
|
|
238
234
|
});
|
|
239
235
|
});
|
|
240
236
|
|