@aws-amplify/core 6.0.1-console-preview.7739091.0 → 6.0.1-preview-testing.64b45b1.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 +4 -2
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/RNComponents/index.d.ts +1 -1
- package/lib/RNComponents/index.js +2 -2
- package/{lib-esm/storage/CookieStorage.d.ts → lib/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/clients/handlers/authenticated.d.ts +1 -1
- package/lib/clients/handlers/fetch.js +2 -1
- 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 +0 -4
- package/lib/clients/types/http.d.ts +8 -0
- package/lib/clients/types/index.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +8 -6
- package/lib/parseAWSExports.js +1 -20
- package/lib/providers/pinpoint/types/buffer.d.ts +1 -1
- package/lib/providers/pinpoint/types/pinpoint.d.ts +1 -1
- 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/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 +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 +1 -1
- package/lib-esm/RNComponents/index.js +2 -2
- package/{lib/storage/CookieStorage.d.ts → lib-esm/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/clients/handlers/authenticated.d.ts +1 -1
- package/lib-esm/clients/handlers/fetch.js +2 -1
- 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 +0 -4
- 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 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/parseAWSExports.js +1 -20
- package/lib-esm/providers/pinpoint/types/buffer.d.ts +1 -1
- package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +1 -1
- 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 +3 -3
- package/src/AwsClients/CognitoIdentity/base.ts +2 -2
- package/src/AwsClients/Pinpoint/base.ts +2 -6
- package/src/Cache/Utils/CacheUtils.ts +4 -2
- package/src/Platform/version.ts +1 -1
- package/src/RNComponents/index.ts +2 -2
- 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/clients/handlers/authenticated.ts +2 -1
- package/src/clients/handlers/fetch.ts +2 -1
- package/src/clients/handlers/unauthenticated.ts +2 -1
- package/src/clients/internal/composeServiceApi.ts +10 -3
- package/src/clients/types/aws.ts +0 -10
- package/src/clients/types/http.ts +8 -0
- package/src/clients/types/index.ts +0 -1
- package/src/index.ts +6 -4
- package/src/parseAWSExports.ts +0 -26
- package/src/providers/pinpoint/types/buffer.ts +1 -1
- package/src/providers/pinpoint/types/pinpoint.ts +1 -1
- package/src/singleton/types.ts +1 -4
- package/src/types/storage.ts +0 -4
- 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/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/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/src/Platform/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '6.0.1-
|
|
2
|
+
export const version = '6.0.1-preview-testing.64b45b1.0+64b45b1';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { getDefaultStorageWithFallback } from '../storage/utils';
|
|
5
4
|
import { isBrowser } from '../Util/JS';
|
|
5
|
+
import { StorageHelper } from '../StorageHelper';
|
|
6
6
|
|
|
7
7
|
export const Linking = {};
|
|
8
8
|
export const AppState = {
|
|
@@ -12,5 +12,5 @@ export const AppState = {
|
|
|
12
12
|
|
|
13
13
|
// if not in react native, just use local storage
|
|
14
14
|
export const AsyncStorage = isBrowser()
|
|
15
|
-
?
|
|
15
|
+
? new StorageHelper().getStorage()
|
|
16
16
|
: undefined;
|
|
@@ -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();
|
|
@@ -11,7 +11,8 @@ import { HttpRequest, HttpResponse } from '../types';
|
|
|
11
11
|
export const authenticatedHandler = composeTransferHandler<
|
|
12
12
|
[UserAgentOptions, RetryOptions<HttpResponse>, SigningOptions],
|
|
13
13
|
HttpRequest,
|
|
14
|
-
HttpResponse
|
|
14
|
+
HttpResponse,
|
|
15
|
+
typeof fetchTransferHandler
|
|
15
16
|
>(fetchTransferHandler, [
|
|
16
17
|
userAgentMiddleware,
|
|
17
18
|
retryMiddleware,
|
|
@@ -13,7 +13,7 @@ export const fetchTransferHandler: TransferHandler<
|
|
|
13
13
|
HttpRequest,
|
|
14
14
|
HttpResponse,
|
|
15
15
|
HttpTransferOptions
|
|
16
|
-
> = async ({ url, method, headers, body }, { abortSignal }) => {
|
|
16
|
+
> = async ({ url, method, headers, body }, { abortSignal, cache }) => {
|
|
17
17
|
let resp: Response;
|
|
18
18
|
try {
|
|
19
19
|
resp = await fetch(url, {
|
|
@@ -21,6 +21,7 @@ export const fetchTransferHandler: TransferHandler<
|
|
|
21
21
|
headers,
|
|
22
22
|
body: shouldSendBody(method) ? body : undefined,
|
|
23
23
|
signal: abortSignal,
|
|
24
|
+
cache,
|
|
24
25
|
});
|
|
25
26
|
} catch (e) {
|
|
26
27
|
// TODO: needs to revise error handling in v6
|
|
@@ -10,5 +10,6 @@ import { HttpRequest, HttpResponse } from '../types';
|
|
|
10
10
|
export const unauthenticatedHandler = composeTransferHandler<
|
|
11
11
|
[UserAgentOptions, RetryOptions<HttpResponse>],
|
|
12
12
|
HttpRequest,
|
|
13
|
-
HttpResponse
|
|
13
|
+
HttpResponse,
|
|
14
|
+
typeof fetchTransferHandler
|
|
14
15
|
>(fetchTransferHandler, [userAgentMiddleware, retryMiddleware]);
|
|
@@ -29,7 +29,7 @@ export const composeServiceApi = <
|
|
|
29
29
|
ServiceClientOptions &
|
|
30
30
|
Partial<DefaultConfig> &
|
|
31
31
|
InferEndpointResolverOptionType<DefaultConfig>,
|
|
32
|
-
|
|
32
|
+
DefaultConfig
|
|
33
33
|
>,
|
|
34
34
|
input: Input
|
|
35
35
|
) => {
|
|
@@ -54,8 +54,15 @@ export const composeServiceApi = <
|
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
type OptionalizeKey<
|
|
58
|
-
[
|
|
57
|
+
type OptionalizeKey<InputType, InputDefaultsType> = {
|
|
58
|
+
[KeyWithDefaultValue in keyof InputDefaultsType]?: KeyWithDefaultValue extends keyof InputType
|
|
59
|
+
? InputType[KeyWithDefaultValue]
|
|
60
|
+
: never;
|
|
61
|
+
} & {
|
|
62
|
+
[KeyWithoutDefaultValue in keyof Omit<
|
|
63
|
+
InputType,
|
|
64
|
+
keyof InputDefaultsType
|
|
65
|
+
>]: InputType[KeyWithoutDefaultValue];
|
|
59
66
|
};
|
|
60
67
|
|
|
61
68
|
type InferEndpointResolverOptionType<T> = T extends {
|
package/src/clients/types/aws.ts
CHANGED
|
@@ -26,13 +26,3 @@ export interface ServiceClientOptions {
|
|
|
26
26
|
export type ErrorParser = (
|
|
27
27
|
response?: HttpResponse
|
|
28
28
|
) => Promise<(Error & MetadataBearer) | undefined>;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Default config options for the `composeServiceApi`.
|
|
32
|
-
*/
|
|
33
|
-
export type DefaultConfigOptions<
|
|
34
|
-
TransferHandlerOptions extends Record<string, unknown> = Record<
|
|
35
|
-
string,
|
|
36
|
-
unknown
|
|
37
|
-
>
|
|
38
|
-
> = Partial<TransferHandlerOptions & ServiceClientOptions>;
|
|
@@ -34,6 +34,14 @@ export interface HttpResponse extends Response {
|
|
|
34
34
|
|
|
35
35
|
export interface HttpTransferOptions {
|
|
36
36
|
abortSignal?: AbortSignal;
|
|
37
|
+
/**
|
|
38
|
+
* Cache mode for the request. Note that this is only effective when the underlying HTTP handler is fetch.
|
|
39
|
+
* For XHR handler, or Node.js `"http(s)"` module or running on React Native, this option is ignored.
|
|
40
|
+
* Instead, you can configure the `Cache-Control` headers to achieve similar effects.
|
|
41
|
+
* @default 'default'
|
|
42
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/cache}
|
|
43
|
+
*/
|
|
44
|
+
cache?: RequestCache;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
export type HttpTransferHandler = TransferHandler<
|
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
|