@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
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { KeyValueStorageInterface } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare class DefaultStorage implements KeyValueStorageInterface {
|
|
6
|
-
private asyncStorage?;
|
|
1
|
+
import { KeyValueStorageInterface } from "../types";
|
|
2
|
+
declare class LocalStorageClass implements KeyValueStorageInterface {
|
|
3
|
+
storage?: Storage;
|
|
4
|
+
constructor();
|
|
7
5
|
/**
|
|
8
6
|
* This is used to set a specific item in storage
|
|
9
7
|
* @param {string} key - the key for the item
|
|
@@ -29,5 +27,6 @@ export declare class DefaultStorage implements KeyValueStorageInterface {
|
|
|
29
27
|
* @returns {string} nothing
|
|
30
28
|
*/
|
|
31
29
|
clear(): Promise<void>;
|
|
32
|
-
private assertModule;
|
|
33
30
|
}
|
|
31
|
+
export declare const LocalStorage: LocalStorageClass;
|
|
32
|
+
export {};
|
|
@@ -37,12 +37,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
import { PlatformNotSupportedError } from '../Util/Errors';
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
var LocalStorageClass = /** @class */ (function () {
|
|
41
|
+
function LocalStorageClass() {
|
|
42
|
+
if (typeof window !== undefined) {
|
|
43
|
+
try {
|
|
44
|
+
this.storage = window === null || window === void 0 ? void 0 : window.localStorage;
|
|
45
|
+
}
|
|
46
|
+
catch (error) { }
|
|
47
|
+
}
|
|
46
48
|
}
|
|
47
49
|
/**
|
|
48
50
|
* This is used to set a specific item in storage
|
|
@@ -50,7 +52,7 @@ var KeyValueStorage = /** @class */ (function () {
|
|
|
50
52
|
* @param {object} value - the value
|
|
51
53
|
* @returns {string} value that was set
|
|
52
54
|
*/
|
|
53
|
-
|
|
55
|
+
LocalStorageClass.prototype.setItem = function (key, value) {
|
|
54
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
55
57
|
return __generator(this, function (_a) {
|
|
56
58
|
if (!this.storage)
|
|
@@ -66,7 +68,7 @@ var KeyValueStorage = /** @class */ (function () {
|
|
|
66
68
|
* This is used to clear the storage
|
|
67
69
|
* @returns {string} the data item
|
|
68
70
|
*/
|
|
69
|
-
|
|
71
|
+
LocalStorageClass.prototype.getItem = function (key) {
|
|
70
72
|
return __awaiter(this, void 0, void 0, function () {
|
|
71
73
|
return __generator(this, function (_a) {
|
|
72
74
|
if (!this.storage)
|
|
@@ -80,7 +82,7 @@ var KeyValueStorage = /** @class */ (function () {
|
|
|
80
82
|
* @param {string} key - the key being set
|
|
81
83
|
* @returns {string} value - value that was deleted
|
|
82
84
|
*/
|
|
83
|
-
|
|
85
|
+
LocalStorageClass.prototype.removeItem = function (key) {
|
|
84
86
|
return __awaiter(this, void 0, void 0, function () {
|
|
85
87
|
return __generator(this, function (_a) {
|
|
86
88
|
if (!this.storage)
|
|
@@ -94,7 +96,7 @@ var KeyValueStorage = /** @class */ (function () {
|
|
|
94
96
|
* This is used to clear the storage
|
|
95
97
|
* @returns {string} nothing
|
|
96
98
|
*/
|
|
97
|
-
|
|
99
|
+
LocalStorageClass.prototype.clear = function () {
|
|
98
100
|
return __awaiter(this, void 0, void 0, function () {
|
|
99
101
|
return __generator(this, function (_a) {
|
|
100
102
|
if (!this.storage)
|
|
@@ -104,6 +106,6 @@ var KeyValueStorage = /** @class */ (function () {
|
|
|
104
106
|
});
|
|
105
107
|
});
|
|
106
108
|
};
|
|
107
|
-
return
|
|
109
|
+
return LocalStorageClass;
|
|
108
110
|
}());
|
|
109
|
-
export
|
|
111
|
+
export var LocalStorage = new LocalStorageClass();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { KeyValueStorageInterface } from '../types';
|
|
2
|
+
/** @class */
|
|
3
|
+
declare class MemoryStorage {
|
|
4
|
+
static syncPromise: Promise<void> | null;
|
|
5
|
+
/**
|
|
6
|
+
* This is used to set a specific item in storage
|
|
7
|
+
* @param {string} key - the key for the item
|
|
8
|
+
* @param {object} value - the value
|
|
9
|
+
* @returns {string} value that was set
|
|
10
|
+
*/
|
|
11
|
+
static setItem(key: string, value: string): string | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* This is used to get a specific key from storage
|
|
14
|
+
* @param {string} key - the key for the item
|
|
15
|
+
* This is used to clear the storage
|
|
16
|
+
* @returns {string} the data item
|
|
17
|
+
*/
|
|
18
|
+
static getItem(key: string): string | null | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* This is used to remove an item from storage
|
|
21
|
+
* @param {string} key - the key being set
|
|
22
|
+
* @returns {string} value - value that was deleted
|
|
23
|
+
*/
|
|
24
|
+
static removeItem(key: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* This is used to clear the storage
|
|
27
|
+
* @returns {string} nothing
|
|
28
|
+
*/
|
|
29
|
+
static clear(): Record<string, string | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
|
|
32
|
+
* @returns {void}
|
|
33
|
+
*/
|
|
34
|
+
static sync(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export declare class StorageHelper {
|
|
37
|
+
private storageWindow;
|
|
38
|
+
/**
|
|
39
|
+
* This is used to get a storage object
|
|
40
|
+
* @returns {object} the storage
|
|
41
|
+
*/
|
|
42
|
+
constructor();
|
|
43
|
+
/**
|
|
44
|
+
* This is used to return the storage
|
|
45
|
+
* @returns {object} the storage
|
|
46
|
+
*/
|
|
47
|
+
getStorage(): typeof MemoryStorage;
|
|
48
|
+
}
|
|
49
|
+
declare class AsyncStorageClass implements KeyValueStorageInterface {
|
|
50
|
+
syncPromise: Promise<void> | null;
|
|
51
|
+
/**
|
|
52
|
+
* This is used to set a specific item in storage
|
|
53
|
+
* @param {string} key - the key for the item
|
|
54
|
+
* @param {object} value - the value
|
|
55
|
+
* @returns {string} value that was set
|
|
56
|
+
*/
|
|
57
|
+
setItem(key: string, value: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* This is used to get a specific key from storage
|
|
60
|
+
* @param {string} key - the key for the item
|
|
61
|
+
* This is used to clear the storage
|
|
62
|
+
* @returns {string} the data item
|
|
63
|
+
*/
|
|
64
|
+
getItem(key: string): Promise<string | null>;
|
|
65
|
+
/**
|
|
66
|
+
* This is used to remove an item from storage
|
|
67
|
+
* @param {string} key - the key being set
|
|
68
|
+
* @returns {string} value - value that was deleted
|
|
69
|
+
*/
|
|
70
|
+
removeItem(key: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* This is used to clear the storage
|
|
73
|
+
* @returns {string} nothing
|
|
74
|
+
*/
|
|
75
|
+
clear(): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
|
|
78
|
+
* @returns {void}
|
|
79
|
+
*/
|
|
80
|
+
sync(): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
export declare const AsyncStorageKeyValue: AsyncStorageClass;
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
38
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
39
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
40
|
+
var MEMORY_KEY_PREFIX = '@MemoryStorage:';
|
|
41
|
+
var dataMemory = {};
|
|
42
|
+
/** @class */
|
|
43
|
+
var MemoryStorage = /** @class */ (function () {
|
|
44
|
+
function MemoryStorage() {
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This is used to set a specific item in storage
|
|
48
|
+
* @param {string} key - the key for the item
|
|
49
|
+
* @param {object} value - the value
|
|
50
|
+
* @returns {string} value that was set
|
|
51
|
+
*/
|
|
52
|
+
MemoryStorage.setItem = function (key, value) {
|
|
53
|
+
if (value) {
|
|
54
|
+
AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value);
|
|
55
|
+
dataMemory[key] = value;
|
|
56
|
+
return dataMemory[key];
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* This is used to get a specific key from storage
|
|
61
|
+
* @param {string} key - the key for the item
|
|
62
|
+
* This is used to clear the storage
|
|
63
|
+
* @returns {string} the data item
|
|
64
|
+
*/
|
|
65
|
+
MemoryStorage.getItem = function (key) {
|
|
66
|
+
return Object.prototype.hasOwnProperty.call(dataMemory, key)
|
|
67
|
+
? dataMemory[key]
|
|
68
|
+
: undefined;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* This is used to remove an item from storage
|
|
72
|
+
* @param {string} key - the key being set
|
|
73
|
+
* @returns {string} value - value that was deleted
|
|
74
|
+
*/
|
|
75
|
+
MemoryStorage.removeItem = function (key) {
|
|
76
|
+
AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key);
|
|
77
|
+
return delete dataMemory[key];
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* This is used to clear the storage
|
|
81
|
+
* @returns {string} nothing
|
|
82
|
+
*/
|
|
83
|
+
MemoryStorage.clear = function () {
|
|
84
|
+
dataMemory = {};
|
|
85
|
+
return dataMemory;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
|
|
89
|
+
* @returns {void}
|
|
90
|
+
*/
|
|
91
|
+
MemoryStorage.sync = function () {
|
|
92
|
+
if (!MemoryStorage.syncPromise) {
|
|
93
|
+
MemoryStorage.syncPromise = new Promise(function (res, rej) {
|
|
94
|
+
AsyncStorage.getAllKeys(function (errKeys, keys) {
|
|
95
|
+
var _a;
|
|
96
|
+
if (errKeys)
|
|
97
|
+
rej(errKeys);
|
|
98
|
+
var memoryKeys = (_a = keys === null || keys === void 0 ? void 0 : keys.filter(function (key) { return key.startsWith(MEMORY_KEY_PREFIX); })) !== null && _a !== void 0 ? _a : [];
|
|
99
|
+
AsyncStorage.multiGet(memoryKeys, function (err, stores) {
|
|
100
|
+
if (err)
|
|
101
|
+
rej(err);
|
|
102
|
+
stores &&
|
|
103
|
+
stores.map(function (result, index, store) {
|
|
104
|
+
var key = store[index][0];
|
|
105
|
+
var value = store[index][1];
|
|
106
|
+
var memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
|
|
107
|
+
dataMemory[memoryKey] = value;
|
|
108
|
+
});
|
|
109
|
+
res();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return MemoryStorage.syncPromise;
|
|
115
|
+
};
|
|
116
|
+
MemoryStorage.syncPromise = null;
|
|
117
|
+
return MemoryStorage;
|
|
118
|
+
}());
|
|
119
|
+
var StorageHelper = /** @class */ (function () {
|
|
120
|
+
/**
|
|
121
|
+
* This is used to get a storage object
|
|
122
|
+
* @returns {object} the storage
|
|
123
|
+
*/
|
|
124
|
+
function StorageHelper() {
|
|
125
|
+
this.storageWindow = MemoryStorage;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* This is used to return the storage
|
|
129
|
+
* @returns {object} the storage
|
|
130
|
+
*/
|
|
131
|
+
StorageHelper.prototype.getStorage = function () {
|
|
132
|
+
return this.storageWindow;
|
|
133
|
+
};
|
|
134
|
+
return StorageHelper;
|
|
135
|
+
}());
|
|
136
|
+
export { StorageHelper };
|
|
137
|
+
var AsyncStorageClass = /** @class */ (function () {
|
|
138
|
+
function AsyncStorageClass() {
|
|
139
|
+
this.syncPromise = null;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* This is used to set a specific item in storage
|
|
143
|
+
* @param {string} key - the key for the item
|
|
144
|
+
* @param {object} value - the value
|
|
145
|
+
* @returns {string} value that was set
|
|
146
|
+
*/
|
|
147
|
+
AsyncStorageClass.prototype.setItem = function (key, value) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
return __generator(this, function (_a) {
|
|
150
|
+
switch (_a.label) {
|
|
151
|
+
case 0:
|
|
152
|
+
if (!value) return [3 /*break*/, 2];
|
|
153
|
+
return [4 /*yield*/, AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value)];
|
|
154
|
+
case 1:
|
|
155
|
+
_a.sent();
|
|
156
|
+
dataMemory[key] = value;
|
|
157
|
+
_a.label = 2;
|
|
158
|
+
case 2: return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* This is used to get a specific key from storage
|
|
165
|
+
* @param {string} key - the key for the item
|
|
166
|
+
* This is used to clear the storage
|
|
167
|
+
* @returns {string} the data item
|
|
168
|
+
*/
|
|
169
|
+
AsyncStorageClass.prototype.getItem = function (key) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
return [2 /*return*/, Object.prototype.hasOwnProperty.call(dataMemory, key)
|
|
173
|
+
? dataMemory[key]
|
|
174
|
+
: null];
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* This is used to remove an item from storage
|
|
180
|
+
* @param {string} key - the key being set
|
|
181
|
+
* @returns {string} value - value that was deleted
|
|
182
|
+
*/
|
|
183
|
+
AsyncStorageClass.prototype.removeItem = function (key) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
+
return __generator(this, function (_a) {
|
|
186
|
+
switch (_a.label) {
|
|
187
|
+
case 0: return [4 /*yield*/, AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key)];
|
|
188
|
+
case 1:
|
|
189
|
+
_a.sent();
|
|
190
|
+
delete dataMemory[key];
|
|
191
|
+
return [2 /*return*/];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* This is used to clear the storage
|
|
198
|
+
* @returns {string} nothing
|
|
199
|
+
*/
|
|
200
|
+
AsyncStorageClass.prototype.clear = function () {
|
|
201
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
202
|
+
return __generator(this, function (_a) {
|
|
203
|
+
dataMemory = {};
|
|
204
|
+
return [2 /*return*/];
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
|
|
210
|
+
* @returns {void}
|
|
211
|
+
*/
|
|
212
|
+
AsyncStorageClass.prototype.sync = function () {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
+
return __generator(this, function (_a) {
|
|
215
|
+
if (!this.syncPromise) {
|
|
216
|
+
this.syncPromise = new Promise(function (res, rej) {
|
|
217
|
+
AsyncStorage.getAllKeys(function (errKeys, keys) {
|
|
218
|
+
var _a;
|
|
219
|
+
if (errKeys)
|
|
220
|
+
rej(errKeys);
|
|
221
|
+
var memoryKeys = (_a = keys === null || keys === void 0 ? void 0 : keys.filter(function (key) { return key.startsWith(MEMORY_KEY_PREFIX); })) !== null && _a !== void 0 ? _a : [];
|
|
222
|
+
AsyncStorage.multiGet(memoryKeys, function (err, stores) {
|
|
223
|
+
if (err)
|
|
224
|
+
rej(err);
|
|
225
|
+
stores &&
|
|
226
|
+
stores.map(function (result, index, store) {
|
|
227
|
+
var key = store[index][0];
|
|
228
|
+
var value = store[index][1];
|
|
229
|
+
var memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
|
|
230
|
+
dataMemory[memoryKey] = value;
|
|
231
|
+
});
|
|
232
|
+
res();
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return [2 /*return*/];
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
return AsyncStorageClass;
|
|
242
|
+
}());
|
|
243
|
+
// TODO: Add this to the react-native Amplify package.
|
|
244
|
+
export var AsyncStorageKeyValue = new AsyncStorageClass();
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { KeyValueStorageInterface } from '../types';
|
|
2
|
-
|
|
3
|
-
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export declare class KeyValueStorage implements KeyValueStorageInterface {
|
|
2
|
+
declare class SessionStorageClass implements KeyValueStorageInterface {
|
|
6
3
|
storage?: Storage;
|
|
7
|
-
constructor(
|
|
4
|
+
constructor();
|
|
8
5
|
/**
|
|
9
6
|
* This is used to set a specific item in storage
|
|
10
7
|
* @param {string} key - the key for the item
|
|
@@ -31,3 +28,5 @@ export declare class KeyValueStorage implements KeyValueStorageInterface {
|
|
|
31
28
|
*/
|
|
32
29
|
clear(): Promise<void>;
|
|
33
30
|
}
|
|
31
|
+
export declare const SessionStorage: SessionStorageClass;
|
|
32
|
+
export {};
|
|
@@ -36,14 +36,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
import {
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
import { PlatformNotSupportedError } from '../Util/Errors';
|
|
40
|
+
var SessionStorageClass = /** @class */ (function () {
|
|
41
|
+
function SessionStorageClass() {
|
|
42
|
+
if (typeof window !== undefined) {
|
|
43
|
+
try {
|
|
44
|
+
this.storage = window === null || window === void 0 ? void 0 : window.sessionStorage;
|
|
45
|
+
}
|
|
46
|
+
catch (error) { }
|
|
47
|
+
}
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
50
|
* This is used to set a specific item in storage
|
|
@@ -51,9 +52,15 @@ var DefaultStorage = /** @class */ (function () {
|
|
|
51
52
|
* @param {object} value - the value
|
|
52
53
|
* @returns {string} value that was set
|
|
53
54
|
*/
|
|
54
|
-
|
|
55
|
-
this
|
|
56
|
-
|
|
55
|
+
SessionStorageClass.prototype.setItem = function (key, value) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
if (!this.storage)
|
|
59
|
+
throw PlatformNotSupportedError;
|
|
60
|
+
this.storage.setItem(key, value);
|
|
61
|
+
return [2 /*return*/];
|
|
62
|
+
});
|
|
63
|
+
});
|
|
57
64
|
};
|
|
58
65
|
/**
|
|
59
66
|
* This is used to get a specific key from storage
|
|
@@ -61,54 +68,44 @@ var DefaultStorage = /** @class */ (function () {
|
|
|
61
68
|
* This is used to clear the storage
|
|
62
69
|
* @returns {string} the data item
|
|
63
70
|
*/
|
|
64
|
-
|
|
65
|
-
this
|
|
66
|
-
|
|
71
|
+
SessionStorageClass.prototype.getItem = function (key) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
if (!this.storage)
|
|
75
|
+
throw PlatformNotSupportedError;
|
|
76
|
+
return [2 /*return*/, this.storage.getItem(key)];
|
|
77
|
+
});
|
|
78
|
+
});
|
|
67
79
|
};
|
|
68
80
|
/**
|
|
69
81
|
* This is used to remove an item from storage
|
|
70
82
|
* @param {string} key - the key being set
|
|
71
83
|
* @returns {string} value - value that was deleted
|
|
72
84
|
*/
|
|
73
|
-
|
|
74
|
-
this
|
|
75
|
-
|
|
85
|
+
SessionStorageClass.prototype.removeItem = function (key) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
if (!this.storage)
|
|
89
|
+
throw PlatformNotSupportedError;
|
|
90
|
+
this.storage.removeItem(key);
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
});
|
|
93
|
+
});
|
|
76
94
|
};
|
|
77
95
|
/**
|
|
78
96
|
* This is used to clear the storage
|
|
79
97
|
* @returns {string} nothing
|
|
80
98
|
*/
|
|
81
|
-
|
|
99
|
+
SessionStorageClass.prototype.clear = function () {
|
|
82
100
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var allKeys;
|
|
84
101
|
return __generator(this, function (_a) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
case 1:
|
|
90
|
-
allKeys = _a.sent();
|
|
91
|
-
return [2 /*return*/, this.asyncStorage.multiRemove(allKeys.filter(function (key) { return key.startsWith(MEMORY_KEY_PREFIX); }))];
|
|
92
|
-
}
|
|
102
|
+
if (!this.storage)
|
|
103
|
+
throw PlatformNotSupportedError;
|
|
104
|
+
this.storage.clear();
|
|
105
|
+
return [2 /*return*/];
|
|
93
106
|
});
|
|
94
107
|
});
|
|
95
108
|
};
|
|
96
|
-
|
|
97
|
-
if (!!asyncStorage) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
this.asyncStorage = require(ASYNC_STORAGE_MODULE)
|
|
102
|
-
.default;
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
throw new AmplifyError({
|
|
106
|
-
name: 'NativeModuleException',
|
|
107
|
-
message: "Unable to find ".concat(ASYNC_STORAGE_MODULE),
|
|
108
|
-
recoverySuggestion: "Make sure to install ".concat(ASYNC_STORAGE_MODULE),
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
return DefaultStorage;
|
|
109
|
+
return SessionStorageClass;
|
|
113
110
|
}());
|
|
114
|
-
export
|
|
111
|
+
export var SessionStorage = new SessionStorageClass();
|
|
@@ -2,4 +2,4 @@ import { RetryOptions } from '../middleware/retry';
|
|
|
2
2
|
import { SigningOptions } from '../middleware/signing';
|
|
3
3
|
import { UserAgentOptions } from '../middleware/userAgent';
|
|
4
4
|
import { HttpRequest, HttpResponse } from '../types';
|
|
5
|
-
export declare const authenticatedHandler: (request: HttpRequest, options: UserAgentOptions & RetryOptions<HttpResponse> & SigningOptions) => Promise<HttpResponse>;
|
|
5
|
+
export declare const authenticatedHandler: (request: HttpRequest, options: UserAgentOptions & RetryOptions<HttpResponse> & SigningOptions & import("../types").HttpTransferOptions) => Promise<HttpResponse>;
|
|
@@ -54,7 +54,7 @@ var shouldSendBody = function (method) {
|
|
|
54
54
|
// TODO[AllanZhengYP]: we need to provide isCanceledError utility
|
|
55
55
|
export var fetchTransferHandler = function (_a, _b) {
|
|
56
56
|
var url = _a.url, method = _a.method, headers = _a.headers, body = _a.body;
|
|
57
|
-
var abortSignal = _b.abortSignal;
|
|
57
|
+
var abortSignal = _b.abortSignal, cache = _b.cache;
|
|
58
58
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
59
59
|
var resp, e_1, responseHeaders, httpResponse, bodyWithMixin;
|
|
60
60
|
var _c, _d;
|
|
@@ -67,6 +67,7 @@ export var fetchTransferHandler = function (_a, _b) {
|
|
|
67
67
|
headers: headers,
|
|
68
68
|
body: shouldSendBody(method) ? body : undefined,
|
|
69
69
|
signal: abortSignal,
|
|
70
|
+
cache: cache,
|
|
70
71
|
})];
|
|
71
72
|
case 1:
|
|
72
73
|
resp = _e.sent();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { RetryOptions } from '../middleware/retry';
|
|
2
2
|
import { UserAgentOptions } from '../middleware/userAgent';
|
|
3
3
|
import { HttpRequest, HttpResponse } from '../types';
|
|
4
|
-
export declare const unauthenticatedHandler: (request: HttpRequest, options: UserAgentOptions & RetryOptions<HttpResponse>) => Promise<HttpResponse>;
|
|
4
|
+
export declare const unauthenticatedHandler: (request: HttpRequest, options: UserAgentOptions & RetryOptions<HttpResponse> & import("../types").HttpTransferOptions) => Promise<HttpResponse>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ServiceClientOptions } from '../types/aws';
|
|
2
2
|
import { TransferHandler, Endpoint } from '../types/core';
|
|
3
3
|
import { HttpRequest, HttpResponse } from '../types/http';
|
|
4
|
-
export declare const composeServiceApi: <TransferHandlerOptions, Input, Output, DefaultConfig>(transferHandler: TransferHandler<HttpRequest, HttpResponse, TransferHandlerOptions>, serializer: (input: Input, endpoint: Endpoint) => Promise<HttpRequest> | HttpRequest, deserializer: (output: HttpResponse) => Promise<Output>, defaultConfig: Partial<DefaultConfig>) => (config: OptionalizeKey<TransferHandlerOptions & ServiceClientOptions & Partial<DefaultConfig> & InferEndpointResolverOptionType<DefaultConfig>,
|
|
5
|
-
type OptionalizeKey<
|
|
6
|
-
[
|
|
4
|
+
export declare const composeServiceApi: <TransferHandlerOptions, Input, Output, DefaultConfig>(transferHandler: TransferHandler<HttpRequest, HttpResponse, TransferHandlerOptions>, serializer: (input: Input, endpoint: Endpoint) => Promise<HttpRequest> | HttpRequest, deserializer: (output: HttpResponse) => Promise<Output>, defaultConfig: Partial<DefaultConfig>) => (config: OptionalizeKey<TransferHandlerOptions & ServiceClientOptions & Partial<DefaultConfig> & InferEndpointResolverOptionType<DefaultConfig>, DefaultConfig>, input: Input) => Promise<Output>;
|
|
5
|
+
type OptionalizeKey<InputType, InputDefaultsType> = {
|
|
6
|
+
[KeyWithDefaultValue in keyof InputDefaultsType]?: KeyWithDefaultValue extends keyof InputType ? InputType[KeyWithDefaultValue] : never;
|
|
7
|
+
} & {
|
|
8
|
+
[KeyWithoutDefaultValue in keyof Omit<InputType, keyof InputDefaultsType>]: InputType[KeyWithoutDefaultValue];
|
|
7
9
|
};
|
|
8
10
|
type InferEndpointResolverOptionType<T> = T extends {
|
|
9
11
|
endpointResolver: (options: infer EndpointOptions) => any;
|
|
@@ -18,7 +18,3 @@ export interface ServiceClientOptions {
|
|
|
18
18
|
* This function is protocol-specific (e.g. JSON, XML, etc.)
|
|
19
19
|
*/
|
|
20
20
|
export type ErrorParser = (response?: HttpResponse) => Promise<(Error & MetadataBearer) | undefined>;
|
|
21
|
-
/**
|
|
22
|
-
* Default config options for the `composeServiceApi`.
|
|
23
|
-
*/
|
|
24
|
-
export type DefaultConfigOptions<TransferHandlerOptions extends Record<string, unknown> = Record<string, unknown>> = Partial<TransferHandlerOptions & ServiceClientOptions>;
|
|
@@ -26,5 +26,13 @@ export interface HttpResponse extends Response {
|
|
|
26
26
|
}
|
|
27
27
|
export interface HttpTransferOptions {
|
|
28
28
|
abortSignal?: AbortSignal;
|
|
29
|
+
/**
|
|
30
|
+
* Cache mode for the request. Note that this is only effective when the underlying HTTP handler is fetch.
|
|
31
|
+
* For XHR handler, or Node.js `"http(s)"` module or running on React Native, this option is ignored.
|
|
32
|
+
* Instead, you can configure the `Cache-Control` headers to achieve similar effects.
|
|
33
|
+
* @default 'default'
|
|
34
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/cache}
|
|
35
|
+
*/
|
|
36
|
+
cache?: RequestCache;
|
|
29
37
|
}
|
|
30
38
|
export type HttpTransferHandler = TransferHandler<HttpRequest, HttpResponse, HttpTransferOptions>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Middleware, MiddlewareHandler, Request, Response, TransferHandler, Endpoint, } from './core';
|
|
2
2
|
export { Headers, HttpRequest, HttpResponse, HttpTransferHandler, HttpTransferOptions, ResponseBodyMixin, } from './http';
|
|
3
|
-
export { Credentials, EndpointResolverOptions, ErrorParser, ServiceClientOptions,
|
|
3
|
+
export { Credentials, EndpointResolverOptions, ErrorParser, ServiceClientOptions, } from './aws';
|
package/lib-esm/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { AuthConfig, AuthUserPoolConfig, AuthUserPoolAndIdentityPoolConfig, Stor
|
|
|
5
5
|
export { Amplify, fetchAuthSession, AmplifyClass as AmplifyClassV6, clearCredentials, } from './singleton';
|
|
6
6
|
export { getCredentialsForIdentity, getId, GetCredentialsForIdentityInput, GetCredentialsForIdentityOutput, } from './AwsClients/CognitoIdentity';
|
|
7
7
|
export { UserProfile } from './types';
|
|
8
|
-
export {
|
|
8
|
+
export { StorageHelper, MemoryStorage, LocalStorage, CookieStorage, SessionStorage, MemoryKeyValueStorage, } from './StorageHelper';
|
|
9
9
|
export { KeyValueStorageInterface } from './types';
|
|
10
10
|
import { BrowserStorageCache } from './Cache/BrowserStorageCache';
|
|
11
11
|
export { InMemoryCache } from './Cache/InMemoryCache';
|
package/lib-esm/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export { Amplify, fetchAuthSession, AmplifyClass as AmplifyClassV6, clearCredent
|
|
|
9
9
|
// AWSClients exports
|
|
10
10
|
export { getCredentialsForIdentity, getId, } from './AwsClients/CognitoIdentity';
|
|
11
11
|
// Storage helpers
|
|
12
|
-
export {
|
|
12
|
+
export { StorageHelper, MemoryStorage, LocalStorage, CookieStorage, SessionStorage, MemoryKeyValueStorage, } from './StorageHelper';
|
|
13
13
|
// Cache exports
|
|
14
14
|
import { BrowserStorageCache } from './Cache/BrowserStorageCache';
|
|
15
15
|
export { InMemoryCache } from './Cache/InMemoryCache';
|