@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.
Files changed (122) hide show
  1. package/lib/Cache/Utils/CacheUtils.js +4 -2
  2. package/lib/Platform/version.d.ts +1 -1
  3. package/lib/Platform/version.js +1 -1
  4. package/lib/RNComponents/index.d.ts +6 -0
  5. package/lib/RNComponents/index.js +16 -0
  6. package/lib/{providers/pinpoint/utils → RNComponents}/isAppInForeground.js +4 -1
  7. package/lib/RNComponents/reactnative.d.ts +3 -0
  8. package/lib/RNComponents/reactnative.js +14 -0
  9. package/lib/{storage/CookieStorage.d.ts → StorageHelper/cookieStorage.d.ts} +3 -4
  10. package/lib/{storage/CookieStorage.js → StorageHelper/cookieStorage.js} +83 -35
  11. package/lib/StorageHelper/inMemoryStorage.d.ts +10 -0
  12. package/lib/StorageHelper/inMemoryStorage.js +82 -0
  13. package/lib/StorageHelper/index.d.ts +45 -0
  14. package/lib/StorageHelper/index.js +83 -0
  15. package/lib/{storage/DefaultStorage.native.d.ts → StorageHelper/localStorage.d.ts} +6 -7
  16. package/lib/{storage/KeyValueStorage.js → StorageHelper/localStorage.js} +15 -13
  17. package/lib/StorageHelper/reactnative.d.ts +83 -0
  18. package/lib/StorageHelper/reactnative.js +250 -0
  19. package/lib/{storage/KeyValueStorage.d.ts → StorageHelper/sessionStorage.d.ts} +4 -5
  20. package/lib/{storage/DefaultStorage.native.js → StorageHelper/sessionStorage.js} +43 -46
  21. package/lib/index.d.ts +1 -1
  22. package/lib/index.js +8 -6
  23. package/lib/libraryUtils.d.ts +1 -0
  24. package/lib/libraryUtils.js +5 -1
  25. package/lib/parseAWSExports.js +1 -20
  26. package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +5 -7
  27. package/lib/singleton/types.d.ts +1 -4
  28. package/lib/tsconfig.tsbuildinfo +1 -1
  29. package/lib/types/storage.d.ts +0 -3
  30. package/lib-esm/Cache/Utils/CacheUtils.js +4 -2
  31. package/lib-esm/Platform/version.d.ts +1 -1
  32. package/lib-esm/Platform/version.js +1 -1
  33. package/lib-esm/RNComponents/index.d.ts +6 -0
  34. package/lib-esm/RNComponents/index.js +13 -0
  35. package/lib-esm/RNComponents/isAppInForeground.js +6 -0
  36. package/lib-esm/RNComponents/reactnative.d.ts +3 -0
  37. package/lib-esm/RNComponents/reactnative.js +6 -0
  38. package/lib-esm/{storage/CookieStorage.d.ts → StorageHelper/cookieStorage.d.ts} +3 -4
  39. package/lib-esm/{storage/CookieStorage.js → StorageHelper/cookieStorage.js} +61 -36
  40. package/lib-esm/StorageHelper/inMemoryStorage.d.ts +10 -0
  41. package/lib-esm/StorageHelper/inMemoryStorage.js +79 -0
  42. package/lib-esm/StorageHelper/index.d.ts +45 -0
  43. package/lib-esm/StorageHelper/index.js +76 -0
  44. package/lib-esm/{storage/DefaultStorage.native.d.ts → StorageHelper/localStorage.d.ts} +6 -7
  45. package/lib-esm/{storage/KeyValueStorage.js → StorageHelper/localStorage.js} +14 -12
  46. package/lib-esm/StorageHelper/reactnative.d.ts +83 -0
  47. package/lib-esm/StorageHelper/reactnative.js +244 -0
  48. package/lib-esm/{storage/KeyValueStorage.d.ts → StorageHelper/sessionStorage.d.ts} +4 -5
  49. package/lib-esm/{storage/DefaultStorage.native.js → StorageHelper/sessionStorage.js} +42 -45
  50. package/lib-esm/index.d.ts +1 -1
  51. package/lib-esm/index.js +1 -1
  52. package/lib-esm/libraryUtils.d.ts +1 -0
  53. package/lib-esm/libraryUtils.js +1 -0
  54. package/lib-esm/parseAWSExports.js +1 -20
  55. package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +5 -7
  56. package/lib-esm/singleton/types.d.ts +1 -4
  57. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  58. package/lib-esm/types/storage.d.ts +0 -3
  59. package/package.json +4 -3
  60. package/src/Cache/Utils/CacheUtils.ts +4 -2
  61. package/src/Platform/version.ts +1 -1
  62. package/src/RNComponents/index.ts +16 -0
  63. package/src/RNComponents/isAppInForeground.ts +8 -0
  64. package/src/RNComponents/reactnative.ts +6 -0
  65. package/src/StorageHelper/cookieStorage.ts +99 -0
  66. package/src/StorageHelper/inMemoryStorage.ts +32 -0
  67. package/src/StorageHelper/index.ts +78 -0
  68. package/src/StorageHelper/localStorage.ts +60 -0
  69. package/src/StorageHelper/reactnative.ts +182 -0
  70. package/src/{storage/KeyValueStorage.ts → StorageHelper/sessionStorage.ts} +13 -10
  71. package/src/index.ts +6 -4
  72. package/src/libraryUtils.ts +1 -0
  73. package/src/parseAWSExports.ts +0 -26
  74. package/src/providers/pinpoint/utils/PinpointEventBuffer.ts +12 -16
  75. package/src/singleton/types.ts +1 -4
  76. package/src/types/storage.ts +0 -4
  77. package/lib/providers/pinpoint/utils/isAppInForeground.native.d.ts +0 -1
  78. package/lib/providers/pinpoint/utils/isAppInForeground.native.js +0 -9
  79. package/lib/singleton/API/types.d.ts +0 -34
  80. package/lib/singleton/API/types.js +0 -2
  81. package/lib/storage/CookieStorage.native.d.ts +0 -7
  82. package/lib/storage/CookieStorage.native.js +0 -32
  83. package/lib/storage/DefaultStorage.d.ts +0 -7
  84. package/lib/storage/DefaultStorage.js +0 -33
  85. package/lib/storage/InMemoryStorage.d.ts +0 -12
  86. package/lib/storage/InMemoryStorage.js +0 -41
  87. package/lib/storage/SessionStorage.d.ts +0 -7
  88. package/lib/storage/SessionStorage.js +0 -33
  89. package/lib/storage/index.d.ts +0 -7
  90. package/lib/storage/index.js +0 -14
  91. package/lib/storage/utils.d.ts +0 -10
  92. package/lib/storage/utils.js +0 -26
  93. package/lib-esm/providers/pinpoint/utils/isAppInForeground.js +0 -3
  94. package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.d.ts +0 -1
  95. package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.js +0 -5
  96. package/lib-esm/singleton/API/types.d.ts +0 -34
  97. package/lib-esm/singleton/API/types.js +0 -1
  98. package/lib-esm/storage/CookieStorage.native.d.ts +0 -7
  99. package/lib-esm/storage/CookieStorage.native.js +0 -29
  100. package/lib-esm/storage/DefaultStorage.d.ts +0 -7
  101. package/lib-esm/storage/DefaultStorage.js +0 -30
  102. package/lib-esm/storage/InMemoryStorage.d.ts +0 -12
  103. package/lib-esm/storage/InMemoryStorage.js +0 -38
  104. package/lib-esm/storage/SessionStorage.d.ts +0 -7
  105. package/lib-esm/storage/SessionStorage.js +0 -30
  106. package/lib-esm/storage/index.d.ts +0 -7
  107. package/lib-esm/storage/index.js +0 -10
  108. package/lib-esm/storage/utils.d.ts +0 -10
  109. package/lib-esm/storage/utils.js +0 -21
  110. package/src/providers/pinpoint/utils/isAppInForeground.native.ts +0 -7
  111. package/src/providers/pinpoint/utils/isAppInForeground.ts +0 -4
  112. package/src/singleton/API/types.ts +0 -31
  113. package/src/storage/CookieStorage.native.ts +0 -13
  114. package/src/storage/CookieStorage.ts +0 -72
  115. package/src/storage/DefaultStorage.native.ts +0 -78
  116. package/src/storage/DefaultStorage.ts +0 -14
  117. package/src/storage/InMemoryStorage.ts +0 -36
  118. package/src/storage/SessionStorage.ts +0 -14
  119. package/src/storage/index.ts +0 -13
  120. package/src/storage/utils.ts +0 -22
  121. /package/lib/{providers/pinpoint/utils → RNComponents}/isAppInForeground.d.ts +0 -0
  122. /package/lib-esm/{providers/pinpoint/utils → RNComponents}/isAppInForeground.d.ts +0 -0
@@ -3,7 +3,7 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.getCurrSizeKey = exports.CacheObject = exports.isInteger = exports.getCurrTime = exports.getByteLength = exports.defaultConfig = void 0;
6
- var utils_1 = require("../../storage/utils");
6
+ var StorageHelper_1 = require("../../StorageHelper");
7
7
  /**
8
8
  * Default cache config
9
9
  */
@@ -14,7 +14,9 @@ exports.defaultConfig = {
14
14
  defaultTTL: 259200000,
15
15
  defaultPriority: 5,
16
16
  warningThreshold: 0.8,
17
- storage: (0, utils_1.getDefaultStorageWithFallback)(),
17
+ // the storage helper will check if localStorage exists,
18
+ // if not, will use a in-memory object instead
19
+ storage: new StorageHelper_1.StorageHelper().getStorage(),
18
20
  };
19
21
  /**
20
22
  * return the byte size of the string
@@ -1 +1 @@
1
- export declare const version = "6.0.1-console-preview.047a1dd.0+047a1dd";
1
+ export declare const version = "6.0.1-next.51e478e.0+51e478e";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // generated by genversion
5
- exports.version = '6.0.1-console-preview.047a1dd.0+047a1dd';
5
+ exports.version = '6.0.1-next.51e478e.0+51e478e';
@@ -0,0 +1,6 @@
1
+ export declare const Linking: {};
2
+ export declare const AppState: {
3
+ addEventListener: (action: any, handler: any) => undefined;
4
+ currentState: string;
5
+ };
6
+ export declare const AsyncStorage: any;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.AsyncStorage = exports.AppState = exports.Linking = void 0;
6
+ var JS_1 = require("../Util/JS");
7
+ var StorageHelper_1 = require("../StorageHelper");
8
+ exports.Linking = {};
9
+ exports.AppState = {
10
+ addEventListener: function (action, handler) { return undefined; },
11
+ currentState: 'active',
12
+ };
13
+ // if not in react native, just use local storage
14
+ exports.AsyncStorage = (0, JS_1.isBrowser)()
15
+ ? new StorageHelper_1.StorageHelper().getStorage()
16
+ : undefined;
@@ -3,5 +3,8 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.isAppInForeground = void 0;
6
- var isAppInForeground = function () { return true; };
6
+ var _1 = require(".");
7
+ var isAppInForeground = function () {
8
+ return _1.AppState.currentState === 'active';
9
+ };
7
10
  exports.isAppInForeground = isAppInForeground;
@@ -0,0 +1,3 @@
1
+ import { Linking, AppState } from 'react-native';
2
+ import AsyncStorage from '@react-native-async-storage/async-storage';
3
+ export { Linking, AppState, AsyncStorage };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AsyncStorage = exports.AppState = exports.Linking = void 0;
7
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
8
+ // SPDX-License-Identifier: Apache-2.0
9
+ // @ts-ignore
10
+ var react_native_1 = require("react-native");
11
+ Object.defineProperty(exports, "Linking", { enumerable: true, get: function () { return react_native_1.Linking; } });
12
+ Object.defineProperty(exports, "AppState", { enumerable: true, get: function () { return react_native_1.AppState; } });
13
+ var async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
14
+ exports.AsyncStorage = async_storage_1.default;
@@ -1,14 +1,13 @@
1
1
  import { CookieStorageData, KeyValueStorageInterface, SameSite } from '../types';
2
2
  export declare class CookieStorage implements KeyValueStorageInterface {
3
- path: string;
4
3
  domain?: string;
4
+ path: string;
5
5
  expires?: number;
6
- sameSite?: SameSite;
7
6
  secure?: boolean;
7
+ sameSite?: SameSite;
8
8
  constructor(data?: CookieStorageData);
9
9
  setItem(key: string, value: string): Promise<void>;
10
- getItem(key: string): Promise<string | null>;
10
+ getItem(key: string): Promise<string>;
11
11
  removeItem(key: string): Promise<void>;
12
12
  clear(): Promise<void>;
13
- private getData;
14
13
  }
@@ -1,16 +1,26 @@
1
1
  "use strict";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- var __assign = (this && this.__assign) || function () {
5
- __assign = Object.assign || function(t) {
6
- for (var s, i = 1, n = arguments.length; i < n; i++) {
7
- s = arguments[i];
8
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
9
- t[p] = s[p];
10
- }
11
- return t;
12
- };
13
- return __assign.apply(this, arguments);
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
14
24
  };
15
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
16
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -50,60 +60,101 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
50
60
  };
51
61
  Object.defineProperty(exports, "__esModule", { value: true });
52
62
  exports.CookieStorage = void 0;
53
- var js_cookie_1 = require("js-cookie");
63
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
64
+ // SPDX-License-Identifier: Apache-2.0
65
+ // @ts-ignore
66
+ var Cookies = __importStar(require("js-cookie"));
54
67
  var CookieStorage = /** @class */ (function () {
55
68
  function CookieStorage(data) {
56
69
  if (data === void 0) { data = {}; }
57
- var path = data.path, domain = data.domain, expires = data.expires, sameSite = data.sameSite, secure = data.secure;
58
- this.domain = domain;
59
- this.path = path ? path : '/';
60
- this.expires = data.hasOwnProperty('expires') ? expires : 365;
61
- this.secure = data.hasOwnProperty('secure') ? secure : true;
70
+ if (data.domain) {
71
+ this.domain = data.domain;
72
+ }
73
+ if (data.path) {
74
+ this.path = data.path;
75
+ }
76
+ else {
77
+ this.path = '/';
78
+ }
79
+ if (Object.prototype.hasOwnProperty.call(data, 'expires')) {
80
+ this.expires = data.expires;
81
+ }
82
+ else {
83
+ this.expires = 365;
84
+ }
85
+ if (Object.prototype.hasOwnProperty.call(data, 'secure')) {
86
+ this.secure = data.secure;
87
+ }
88
+ else {
89
+ this.secure = true;
90
+ }
62
91
  if (data.hasOwnProperty('sameSite')) {
63
- if (!sameSite || !['strict', 'lax', 'none'].includes(sameSite)) {
92
+ if (!data.sameSite ||
93
+ !['strict', 'lax', 'none'].includes(data.sameSite)) {
64
94
  throw new Error('The sameSite value of cookieStorage must be "lax", "strict" or "none".');
65
95
  }
66
- if (sameSite === 'none' && !this.secure) {
96
+ if (data.sameSite === 'none' && !this.secure) {
67
97
  throw new Error('sameSite = None requires the Secure attribute in latest browser versions.');
68
98
  }
69
- this.sameSite = sameSite;
99
+ this.sameSite = data.sameSite;
70
100
  }
71
101
  }
72
102
  CookieStorage.prototype.setItem = function (key, value) {
73
103
  return __awaiter(this, void 0, void 0, function () {
104
+ var options;
74
105
  return __generator(this, function (_a) {
75
- (0, js_cookie_1.set)(key, value, this.getData());
76
- return [2 /*return*/];
106
+ options = {
107
+ path: this.path,
108
+ expires: this.expires,
109
+ domain: this.domain,
110
+ secure: this.secure,
111
+ };
112
+ if (this.sameSite) {
113
+ options.sameSite = this.sameSite;
114
+ }
115
+ Cookies.set(key, value, options);
116
+ return [2 /*return*/, Cookies.get(key)];
77
117
  });
78
118
  });
79
119
  };
80
120
  CookieStorage.prototype.getItem = function (key) {
81
121
  return __awaiter(this, void 0, void 0, function () {
82
- var item;
83
122
  return __generator(this, function (_a) {
84
- item = (0, js_cookie_1.get)(key);
85
- return [2 /*return*/, item !== null && item !== void 0 ? item : null];
123
+ return [2 /*return*/, Cookies.get(key)];
86
124
  });
87
125
  });
88
126
  };
89
127
  CookieStorage.prototype.removeItem = function (key) {
90
128
  return __awaiter(this, void 0, void 0, function () {
129
+ var options;
91
130
  return __generator(this, function (_a) {
92
- (0, js_cookie_1.remove)(key, this.getData());
131
+ options = {
132
+ path: this.path,
133
+ expires: this.expires,
134
+ domain: this.domain,
135
+ secure: this.secure,
136
+ };
137
+ if (this.sameSite) {
138
+ options.sameSite = this.sameSite;
139
+ }
140
+ Cookies.remove(key, options);
93
141
  return [2 /*return*/];
94
142
  });
95
143
  });
96
144
  };
97
145
  CookieStorage.prototype.clear = function () {
98
146
  return __awaiter(this, void 0, void 0, function () {
99
- var cookie, promises;
100
- var _this = this;
147
+ var cookies, numKeys, promiseArray, index;
101
148
  return __generator(this, function (_a) {
102
149
  switch (_a.label) {
103
150
  case 0:
104
- cookie = (0, js_cookie_1.get)();
105
- promises = Object.keys(cookie).map(function (key) { return _this.removeItem(key); });
106
- return [4 /*yield*/, Promise.all(promises)];
151
+ cookies = Cookies.get();
152
+ numKeys = Object.keys(cookies).length;
153
+ promiseArray = [];
154
+ for (index = 0; index < numKeys; ++index) {
155
+ promiseArray.push(this.removeItem(Object.keys(cookies)[index]));
156
+ }
157
+ return [4 /*yield*/, Promise.all(promiseArray)];
107
158
  case 1:
108
159
  _a.sent();
109
160
  return [2 /*return*/];
@@ -111,9 +162,6 @@ var CookieStorage = /** @class */ (function () {
111
162
  });
112
163
  });
113
164
  };
114
- CookieStorage.prototype.getData = function () {
115
- return __assign({ path: this.path, expires: this.expires, domain: this.domain, secure: this.secure }, (this.sameSite && { sameSite: this.sameSite }));
116
- };
117
165
  return CookieStorage;
118
166
  }());
119
167
  exports.CookieStorage = CookieStorage;
@@ -0,0 +1,10 @@
1
+ import { KeyValueStorageInterface } from '../types';
2
+ declare class MemoryKeyValueStorageClass implements KeyValueStorageInterface {
3
+ myStorage: Record<string, string>;
4
+ setItem(key: string, value: string): Promise<void>;
5
+ getItem(key: string): Promise<string | null>;
6
+ removeItem(key: string): Promise<void>;
7
+ clear(): Promise<void>;
8
+ }
9
+ export declare const MemoryKeyValueStorage: MemoryKeyValueStorageClass;
10
+ export {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
+ return new (P || (P = Promise))(function (resolve, reject) {
7
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11
+ });
12
+ };
13
+ var __generator = (this && this.__generator) || function (thisArg, body) {
14
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
15
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
16
+ function verb(n) { return function (v) { return step([n, v]); }; }
17
+ function step(op) {
18
+ if (f) throw new TypeError("Generator is already executing.");
19
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
20
+ 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;
21
+ if (y = 0, t) op = [op[0] & 2, t.value];
22
+ switch (op[0]) {
23
+ case 0: case 1: t = op; break;
24
+ case 4: _.label++; return { value: op[1], done: false };
25
+ case 5: _.label++; y = op[1]; op = [0]; continue;
26
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
27
+ default:
28
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
29
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
30
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
31
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
32
+ if (t[2]) _.ops.pop();
33
+ _.trys.pop(); continue;
34
+ }
35
+ op = body.call(thisArg, _);
36
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
37
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
38
+ }
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.MemoryKeyValueStorage = void 0;
42
+ var MemoryKeyValueStorageClass = /** @class */ (function () {
43
+ function MemoryKeyValueStorageClass() {
44
+ this.myStorage = {};
45
+ }
46
+ MemoryKeyValueStorageClass.prototype.setItem = function (key, value) {
47
+ return __awaiter(this, void 0, void 0, function () {
48
+ return __generator(this, function (_a) {
49
+ this.myStorage[key] = value;
50
+ return [2 /*return*/];
51
+ });
52
+ });
53
+ };
54
+ MemoryKeyValueStorageClass.prototype.getItem = function (key) {
55
+ return __awaiter(this, void 0, void 0, function () {
56
+ return __generator(this, function (_a) {
57
+ return [2 /*return*/, this.myStorage[key]];
58
+ });
59
+ });
60
+ };
61
+ MemoryKeyValueStorageClass.prototype.removeItem = function (key) {
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ return __generator(this, function (_a) {
64
+ delete this.myStorage[key];
65
+ return [2 /*return*/];
66
+ });
67
+ });
68
+ };
69
+ MemoryKeyValueStorageClass.prototype.clear = function () {
70
+ return __awaiter(this, void 0, void 0, function () {
71
+ var _this = this;
72
+ return __generator(this, function (_a) {
73
+ Object.keys(this.myStorage).forEach(function (key) {
74
+ delete _this.myStorage[key];
75
+ });
76
+ return [2 /*return*/];
77
+ });
78
+ });
79
+ };
80
+ return MemoryKeyValueStorageClass;
81
+ }());
82
+ exports.MemoryKeyValueStorage = new MemoryKeyValueStorageClass();
@@ -0,0 +1,45 @@
1
+ /** @class */
2
+ export declare class MemoryStorage {
3
+ /**
4
+ * This is used to set a specific item in storage
5
+ * @param {string} key - the key for the item
6
+ * @param {object} value - the value
7
+ * @returns {string} value that was set
8
+ */
9
+ static setItem(key: string, value: any): string;
10
+ /**
11
+ * This is used to get a specific key from storage
12
+ * @param {string} key - the key for the item
13
+ * This is used to clear the storage
14
+ * @returns {string} the data item
15
+ */
16
+ static getItem(key: string): string | undefined;
17
+ /**
18
+ * This is used to remove an item from storage
19
+ * @param {string} key - the key being set
20
+ * @returns {string} value - value that was deleted
21
+ */
22
+ static removeItem(key: string): boolean;
23
+ /**
24
+ * This is used to clear the storage
25
+ * @returns {string} nothing
26
+ */
27
+ static clear(): Record<string, string>;
28
+ }
29
+ export declare class StorageHelper {
30
+ private storageWindow;
31
+ /**
32
+ * This is used to get a storage object
33
+ * @returns {object} the storage
34
+ */
35
+ constructor();
36
+ /**
37
+ * This is used to return the storage
38
+ * @returns {object} the storage
39
+ */
40
+ getStorage(): any;
41
+ }
42
+ export { SessionStorage } from './sessionStorage';
43
+ export { LocalStorage } from './localStorage';
44
+ export { MemoryKeyValueStorage } from './inMemoryStorage';
45
+ export { CookieStorage } from './cookieStorage';
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.CookieStorage = exports.MemoryKeyValueStorage = exports.LocalStorage = exports.SessionStorage = exports.StorageHelper = exports.MemoryStorage = void 0;
6
+ var dataMemory = {};
7
+ /** @class */
8
+ var MemoryStorage = /** @class */ (function () {
9
+ function MemoryStorage() {
10
+ }
11
+ /**
12
+ * This is used to set a specific item in storage
13
+ * @param {string} key - the key for the item
14
+ * @param {object} value - the value
15
+ * @returns {string} value that was set
16
+ */
17
+ MemoryStorage.setItem = function (key, value) {
18
+ dataMemory[key] = value;
19
+ return dataMemory[key];
20
+ };
21
+ /**
22
+ * This is used to get a specific key from storage
23
+ * @param {string} key - the key for the item
24
+ * This is used to clear the storage
25
+ * @returns {string} the data item
26
+ */
27
+ MemoryStorage.getItem = function (key) {
28
+ return Object.prototype.hasOwnProperty.call(dataMemory, key)
29
+ ? dataMemory[key]
30
+ : undefined;
31
+ };
32
+ /**
33
+ * This is used to remove an item from storage
34
+ * @param {string} key - the key being set
35
+ * @returns {string} value - value that was deleted
36
+ */
37
+ MemoryStorage.removeItem = function (key) {
38
+ return delete dataMemory[key];
39
+ };
40
+ /**
41
+ * This is used to clear the storage
42
+ * @returns {string} nothing
43
+ */
44
+ MemoryStorage.clear = function () {
45
+ dataMemory = {};
46
+ return dataMemory;
47
+ };
48
+ return MemoryStorage;
49
+ }());
50
+ exports.MemoryStorage = MemoryStorage;
51
+ var StorageHelper = /** @class */ (function () {
52
+ /**
53
+ * This is used to get a storage object
54
+ * @returns {object} the storage
55
+ */
56
+ function StorageHelper() {
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
+ }
62
+ catch (exception) {
63
+ this.storageWindow = MemoryStorage;
64
+ }
65
+ }
66
+ /**
67
+ * This is used to return the storage
68
+ * @returns {object} the storage
69
+ */
70
+ StorageHelper.prototype.getStorage = function () {
71
+ return this.storageWindow;
72
+ };
73
+ return StorageHelper;
74
+ }());
75
+ exports.StorageHelper = StorageHelper;
76
+ var sessionStorage_1 = require("./sessionStorage");
77
+ Object.defineProperty(exports, "SessionStorage", { enumerable: true, get: function () { return sessionStorage_1.SessionStorage; } });
78
+ var localStorage_1 = require("./localStorage");
79
+ Object.defineProperty(exports, "LocalStorage", { enumerable: true, get: function () { return localStorage_1.LocalStorage; } });
80
+ var inMemoryStorage_1 = require("./inMemoryStorage");
81
+ Object.defineProperty(exports, "MemoryKeyValueStorage", { enumerable: true, get: function () { return inMemoryStorage_1.MemoryKeyValueStorage; } });
82
+ var cookieStorage_1 = require("./cookieStorage");
83
+ Object.defineProperty(exports, "CookieStorage", { enumerable: true, get: function () { return cookieStorage_1.CookieStorage; } });
@@ -1,9 +1,7 @@
1
- import { KeyValueStorageInterface } from '../types';
2
- /**
3
- * @internal
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 {};
@@ -38,14 +38,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  }
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.KeyValueStorage = void 0;
41
+ exports.LocalStorage = void 0;
42
42
  var Errors_1 = require("../Util/Errors");
43
- /**
44
- * @internal
45
- */
46
- var KeyValueStorage = /** @class */ (function () {
47
- function KeyValueStorage(storage) {
48
- this.storage = storage;
43
+ var LocalStorageClass = /** @class */ (function () {
44
+ function LocalStorageClass() {
45
+ if (typeof window !== undefined) {
46
+ try {
47
+ this.storage = window === null || window === void 0 ? void 0 : window.localStorage;
48
+ }
49
+ catch (error) { }
50
+ }
49
51
  }
50
52
  /**
51
53
  * This is used to set a specific item in storage
@@ -53,7 +55,7 @@ var KeyValueStorage = /** @class */ (function () {
53
55
  * @param {object} value - the value
54
56
  * @returns {string} value that was set
55
57
  */
56
- KeyValueStorage.prototype.setItem = function (key, value) {
58
+ LocalStorageClass.prototype.setItem = function (key, value) {
57
59
  return __awaiter(this, void 0, void 0, function () {
58
60
  return __generator(this, function (_a) {
59
61
  if (!this.storage)
@@ -69,7 +71,7 @@ var KeyValueStorage = /** @class */ (function () {
69
71
  * This is used to clear the storage
70
72
  * @returns {string} the data item
71
73
  */
72
- KeyValueStorage.prototype.getItem = function (key) {
74
+ LocalStorageClass.prototype.getItem = function (key) {
73
75
  return __awaiter(this, void 0, void 0, function () {
74
76
  return __generator(this, function (_a) {
75
77
  if (!this.storage)
@@ -83,7 +85,7 @@ var KeyValueStorage = /** @class */ (function () {
83
85
  * @param {string} key - the key being set
84
86
  * @returns {string} value - value that was deleted
85
87
  */
86
- KeyValueStorage.prototype.removeItem = function (key) {
88
+ LocalStorageClass.prototype.removeItem = function (key) {
87
89
  return __awaiter(this, void 0, void 0, function () {
88
90
  return __generator(this, function (_a) {
89
91
  if (!this.storage)
@@ -97,7 +99,7 @@ var KeyValueStorage = /** @class */ (function () {
97
99
  * This is used to clear the storage
98
100
  * @returns {string} nothing
99
101
  */
100
- KeyValueStorage.prototype.clear = function () {
102
+ LocalStorageClass.prototype.clear = function () {
101
103
  return __awaiter(this, void 0, void 0, function () {
102
104
  return __generator(this, function (_a) {
103
105
  if (!this.storage)
@@ -107,6 +109,6 @@ var KeyValueStorage = /** @class */ (function () {
107
109
  });
108
110
  });
109
111
  };
110
- return KeyValueStorage;
112
+ return LocalStorageClass;
111
113
  }());
112
- exports.KeyValueStorage = KeyValueStorage;
114
+ exports.LocalStorage = new LocalStorageClass();