@aws-amplify/core 6.0.1-console-preview.814dea6.0 → 6.0.1-console-preview.047a1dd.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/lib/AwsClients/CognitoIdentity/base.d.ts +12 -4
  2. package/lib/AwsClients/CognitoIdentity/base.js +1 -0
  3. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +15 -3
  4. package/lib/AwsClients/CognitoIdentity/getId.d.ts +15 -3
  5. package/lib/AwsClients/Pinpoint/base.d.ts +10 -2
  6. package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +17 -3
  7. package/lib/AwsClients/Pinpoint/putEvents.d.ts +17 -3
  8. package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +17 -3
  9. package/lib/Cache/Utils/CacheUtils.js +2 -4
  10. package/lib/Platform/version.d.ts +1 -1
  11. package/lib/Platform/version.js +1 -1
  12. package/lib/ServiceWorker/ServiceWorker.js +1 -1
  13. package/lib/Util/JS.d.ts +1 -4
  14. package/lib/Util/JS.js +4 -11
  15. package/lib/Util/Reachability.js +0 -3
  16. package/lib/clients/handlers/authenticated.d.ts +1 -1
  17. package/lib/clients/handlers/fetch.d.ts +0 -1
  18. package/lib/clients/handlers/fetch.js +2 -2
  19. package/lib/clients/handlers/unauthenticated.d.ts +1 -1
  20. package/lib/clients/internal/composeServiceApi.d.ts +5 -3
  21. package/lib/clients/types/aws.d.ts +1 -5
  22. package/lib/clients/types/http.d.ts +8 -0
  23. package/lib/clients/types/index.d.ts +1 -1
  24. package/lib/index.d.ts +1 -2
  25. package/lib/index.js +6 -10
  26. package/lib/libraryUtils.d.ts +3 -3
  27. package/lib/libraryUtils.js +5 -10
  28. package/lib/parseAWSExports.js +20 -1
  29. package/lib/providers/pinpoint/apis/record.d.ts +2 -2
  30. package/lib/providers/pinpoint/apis/record.js +3 -3
  31. package/lib/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
  32. package/lib/providers/pinpoint/types/buffer.d.ts +1 -1
  33. package/lib/providers/pinpoint/types/pinpoint.d.ts +3 -3
  34. package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +7 -5
  35. package/lib/providers/pinpoint/utils/isAppInForeground.d.ts +1 -0
  36. package/lib/{RNComponents → providers/pinpoint/utils}/isAppInForeground.js +1 -4
  37. package/lib/providers/pinpoint/utils/isAppInForeground.native.d.ts +1 -0
  38. package/lib/providers/pinpoint/utils/isAppInForeground.native.js +9 -0
  39. package/lib/singleton/API/types.d.ts +34 -0
  40. package/lib/singleton/API/types.js +2 -0
  41. package/lib/singleton/Amplify.d.ts +2 -2
  42. package/lib/singleton/Amplify.js +9 -1
  43. package/lib/singleton/Auth/index.d.ts +2 -1
  44. package/lib/singleton/Auth/index.js +22 -12
  45. package/lib/singleton/Auth/utils/index.js +3 -3
  46. package/lib/singleton/Storage/types.d.ts +5 -0
  47. package/lib/singleton/types.d.ts +10 -1
  48. package/lib/{StorageHelper/cookieStorage.d.ts → storage/CookieStorage.d.ts} +4 -3
  49. package/lib/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +35 -83
  50. package/lib/storage/CookieStorage.native.d.ts +7 -0
  51. package/lib/storage/CookieStorage.native.js +32 -0
  52. package/lib/storage/DefaultStorage.d.ts +7 -0
  53. package/lib/storage/DefaultStorage.js +33 -0
  54. package/{lib-esm/StorageHelper/localStorage.d.ts → lib/storage/DefaultStorage.native.d.ts} +7 -6
  55. package/lib/{StorageHelper/sessionStorage.js → storage/DefaultStorage.native.js} +46 -43
  56. package/lib/storage/InMemoryStorage.d.ts +12 -0
  57. package/lib/storage/InMemoryStorage.js +41 -0
  58. package/lib/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
  59. package/lib/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +13 -15
  60. package/lib/storage/SessionStorage.d.ts +7 -0
  61. package/lib/storage/SessionStorage.js +33 -0
  62. package/lib/storage/index.d.ts +7 -0
  63. package/lib/storage/index.js +14 -0
  64. package/lib/storage/utils.d.ts +10 -0
  65. package/lib/storage/utils.js +26 -0
  66. package/lib/tsconfig.tsbuildinfo +1 -1
  67. package/lib/types/storage.d.ts +3 -0
  68. package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +12 -4
  69. package/lib-esm/AwsClients/CognitoIdentity/base.js +1 -0
  70. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +15 -3
  71. package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +15 -3
  72. package/lib-esm/AwsClients/Pinpoint/base.d.ts +10 -2
  73. package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +17 -3
  74. package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +17 -3
  75. package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +17 -3
  76. package/lib-esm/Cache/Utils/CacheUtils.js +2 -4
  77. package/lib-esm/Platform/version.d.ts +1 -1
  78. package/lib-esm/Platform/version.js +1 -1
  79. package/lib-esm/ServiceWorker/ServiceWorker.js +2 -2
  80. package/lib-esm/Util/JS.d.ts +1 -4
  81. package/lib-esm/Util/JS.js +2 -9
  82. package/lib-esm/Util/Reachability.js +1 -4
  83. package/lib-esm/clients/handlers/authenticated.d.ts +1 -1
  84. package/lib-esm/clients/handlers/fetch.d.ts +0 -1
  85. package/lib-esm/clients/handlers/fetch.js +2 -2
  86. package/lib-esm/clients/handlers/unauthenticated.d.ts +1 -1
  87. package/lib-esm/clients/internal/composeServiceApi.d.ts +5 -3
  88. package/lib-esm/clients/types/aws.d.ts +1 -5
  89. package/lib-esm/clients/types/http.d.ts +8 -0
  90. package/lib-esm/clients/types/index.d.ts +1 -1
  91. package/lib-esm/index.d.ts +1 -2
  92. package/lib-esm/index.js +1 -2
  93. package/lib-esm/libraryUtils.d.ts +3 -3
  94. package/lib-esm/libraryUtils.js +2 -3
  95. package/lib-esm/parseAWSExports.js +20 -1
  96. package/lib-esm/providers/pinpoint/apis/record.d.ts +2 -2
  97. package/lib-esm/providers/pinpoint/apis/record.js +3 -3
  98. package/lib-esm/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
  99. package/lib-esm/providers/pinpoint/types/buffer.d.ts +1 -1
  100. package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +3 -3
  101. package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +7 -5
  102. package/lib-esm/providers/pinpoint/utils/isAppInForeground.js +3 -0
  103. package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.js +5 -0
  104. package/lib-esm/singleton/API/types.d.ts +34 -0
  105. package/lib-esm/singleton/API/types.js +1 -0
  106. package/lib-esm/singleton/Amplify.d.ts +2 -2
  107. package/lib-esm/singleton/Amplify.js +9 -1
  108. package/lib-esm/singleton/Auth/index.d.ts +2 -1
  109. package/lib-esm/singleton/Auth/index.js +22 -12
  110. package/lib-esm/singleton/Auth/utils/index.js +3 -3
  111. package/lib-esm/singleton/Storage/types.d.ts +5 -0
  112. package/lib-esm/singleton/types.d.ts +10 -1
  113. package/lib-esm/{StorageHelper/cookieStorage.d.ts → storage/CookieStorage.d.ts} +4 -3
  114. package/lib-esm/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +36 -61
  115. package/lib-esm/storage/CookieStorage.native.d.ts +7 -0
  116. package/lib-esm/storage/CookieStorage.native.js +29 -0
  117. package/lib-esm/storage/DefaultStorage.d.ts +7 -0
  118. package/lib-esm/storage/DefaultStorage.js +30 -0
  119. package/{lib/StorageHelper/localStorage.d.ts → lib-esm/storage/DefaultStorage.native.d.ts} +7 -6
  120. package/lib-esm/{StorageHelper/sessionStorage.js → storage/DefaultStorage.native.js} +45 -42
  121. package/lib-esm/storage/InMemoryStorage.d.ts +12 -0
  122. package/lib-esm/storage/InMemoryStorage.js +38 -0
  123. package/lib-esm/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
  124. package/lib-esm/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +12 -14
  125. package/lib-esm/storage/SessionStorage.d.ts +7 -0
  126. package/lib-esm/storage/SessionStorage.js +30 -0
  127. package/lib-esm/storage/index.d.ts +7 -0
  128. package/lib-esm/storage/index.js +10 -0
  129. package/lib-esm/storage/utils.d.ts +10 -0
  130. package/lib-esm/storage/utils.js +21 -0
  131. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  132. package/lib-esm/types/storage.d.ts +3 -0
  133. package/package.json +3 -6
  134. package/src/AwsClients/CognitoIdentity/base.ts +2 -2
  135. package/src/AwsClients/Pinpoint/base.ts +2 -6
  136. package/src/Cache/Utils/CacheUtils.ts +2 -4
  137. package/src/Platform/version.ts +1 -1
  138. package/src/ServiceWorker/ServiceWorker.ts +2 -2
  139. package/src/Util/JS.ts +2 -13
  140. package/src/Util/Reachability.ts +1 -5
  141. package/src/clients/handlers/authenticated.ts +2 -1
  142. package/src/clients/handlers/fetch.ts +2 -2
  143. package/src/clients/handlers/unauthenticated.ts +2 -1
  144. package/src/clients/internal/composeServiceApi.ts +10 -3
  145. package/src/clients/types/aws.ts +4 -11
  146. package/src/clients/types/http.ts +8 -0
  147. package/src/clients/types/index.ts +0 -1
  148. package/src/index.ts +4 -8
  149. package/src/libraryUtils.ts +3 -4
  150. package/src/parseAWSExports.ts +26 -0
  151. package/src/providers/pinpoint/apis/record.ts +8 -8
  152. package/src/providers/pinpoint/apis/updateEndpoint.ts +2 -2
  153. package/src/providers/pinpoint/types/buffer.ts +1 -1
  154. package/src/providers/pinpoint/types/pinpoint.ts +8 -7
  155. package/src/providers/pinpoint/utils/PinpointEventBuffer.ts +16 -12
  156. package/src/providers/pinpoint/utils/isAppInForeground.native.ts +7 -0
  157. package/src/providers/pinpoint/utils/isAppInForeground.ts +4 -0
  158. package/src/singleton/API/types.ts +31 -0
  159. package/src/singleton/Amplify.ts +12 -3
  160. package/src/singleton/Auth/index.ts +9 -2
  161. package/src/singleton/Auth/utils/index.ts +3 -3
  162. package/src/singleton/Storage/types.ts +6 -2
  163. package/src/singleton/types.ts +11 -1
  164. package/src/storage/CookieStorage.native.ts +13 -0
  165. package/src/storage/CookieStorage.ts +72 -0
  166. package/src/storage/DefaultStorage.native.ts +78 -0
  167. package/src/storage/DefaultStorage.ts +14 -0
  168. package/src/storage/InMemoryStorage.ts +36 -0
  169. package/src/{StorageHelper/sessionStorage.ts → storage/KeyValueStorage.ts} +10 -13
  170. package/src/storage/SessionStorage.ts +14 -0
  171. package/src/storage/index.ts +13 -0
  172. package/src/storage/utils.ts +22 -0
  173. package/src/types/storage.ts +4 -0
  174. package/lib/OAuthHelper/FacebookOAuth.d.ts +0 -6
  175. package/lib/OAuthHelper/FacebookOAuth.js +0 -124
  176. package/lib/OAuthHelper/GoogleOAuth.d.ts +0 -6
  177. package/lib/OAuthHelper/GoogleOAuth.js +0 -134
  178. package/lib/OAuthHelper/index.d.ts +0 -4
  179. package/lib/OAuthHelper/index.js +0 -9
  180. package/lib/RNComponents/index.d.ts +0 -6
  181. package/lib/RNComponents/index.js +0 -16
  182. package/lib/RNComponents/reactnative.d.ts +0 -3
  183. package/lib/RNComponents/reactnative.js +0 -14
  184. package/lib/StorageHelper/inMemoryStorage.d.ts +0 -10
  185. package/lib/StorageHelper/inMemoryStorage.js +0 -82
  186. package/lib/StorageHelper/index.d.ts +0 -45
  187. package/lib/StorageHelper/index.js +0 -83
  188. package/lib/StorageHelper/reactnative.d.ts +0 -83
  189. package/lib/StorageHelper/reactnative.js +0 -250
  190. package/lib-esm/OAuthHelper/FacebookOAuth.d.ts +0 -6
  191. package/lib-esm/OAuthHelper/FacebookOAuth.js +0 -121
  192. package/lib-esm/OAuthHelper/GoogleOAuth.d.ts +0 -6
  193. package/lib-esm/OAuthHelper/GoogleOAuth.js +0 -131
  194. package/lib-esm/OAuthHelper/index.d.ts +0 -4
  195. package/lib-esm/OAuthHelper/index.js +0 -6
  196. package/lib-esm/RNComponents/index.d.ts +0 -6
  197. package/lib-esm/RNComponents/index.js +0 -13
  198. package/lib-esm/RNComponents/isAppInForeground.js +0 -6
  199. package/lib-esm/RNComponents/reactnative.d.ts +0 -3
  200. package/lib-esm/RNComponents/reactnative.js +0 -6
  201. package/lib-esm/StorageHelper/inMemoryStorage.d.ts +0 -10
  202. package/lib-esm/StorageHelper/inMemoryStorage.js +0 -79
  203. package/lib-esm/StorageHelper/index.d.ts +0 -45
  204. package/lib-esm/StorageHelper/index.js +0 -76
  205. package/lib-esm/StorageHelper/reactnative.d.ts +0 -83
  206. package/lib-esm/StorageHelper/reactnative.js +0 -244
  207. package/src/OAuthHelper/FacebookOAuth.ts +0 -83
  208. package/src/OAuthHelper/GoogleOAuth.ts +0 -97
  209. package/src/OAuthHelper/index.ts +0 -7
  210. package/src/RNComponents/index.ts +0 -16
  211. package/src/RNComponents/isAppInForeground.ts +0 -8
  212. package/src/RNComponents/reactnative.ts +0 -6
  213. package/src/StorageHelper/cookieStorage.ts +0 -99
  214. package/src/StorageHelper/inMemoryStorage.ts +0 -32
  215. package/src/StorageHelper/index.ts +0 -78
  216. package/src/StorageHelper/localStorage.ts +0 -60
  217. package/src/StorageHelper/reactnative.ts +0 -182
  218. /package/lib-esm/{RNComponents → providers/pinpoint/utils}/isAppInForeground.d.ts +0 -0
  219. /package/{lib/RNComponents/isAppInForeground.d.ts → lib-esm/providers/pinpoint/utils/isAppInForeground.native.d.ts} +0 -0
@@ -57,20 +57,19 @@ var AuthClass = /** @class */ (function () {
57
57
  this.authOptions = authOptions;
58
58
  };
59
59
  AuthClass.prototype.fetchAuthSession = function (options) {
60
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
60
+ var _a, _b, _c, _d, _e, _f;
61
61
  if (options === void 0) { options = {}; }
62
62
  return __awaiter(this, void 0, void 0, function () {
63
63
  var tokens, credentialsAndIdentityId, userSub;
64
- return __generator(this, function (_k) {
65
- switch (_k.label) {
66
- case 0: return [4 /*yield*/, ((_b = (_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.tokenProvider) === null || _b === void 0 ? void 0 : _b.getTokens(options))];
64
+ return __generator(this, function (_g) {
65
+ switch (_g.label) {
66
+ case 0: return [4 /*yield*/, this.getTokens(options)];
67
67
  case 1:
68
68
  // Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
69
- tokens =
70
- (_c = (_k.sent())) !== null && _c !== void 0 ? _c : undefined;
69
+ tokens = _g.sent();
71
70
  if (!tokens) return [3 /*break*/, 3];
72
- userSub = (_e = (_d = tokens.accessToken) === null || _d === void 0 ? void 0 : _d.payload) === null || _e === void 0 ? void 0 : _e.sub;
73
- return [4 /*yield*/, ((_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.credentialsProvider) === null || _g === void 0 ? void 0 : _g.getCredentialsAndIdentityId({
71
+ userSub = (_b = (_a = tokens.accessToken) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.sub;
72
+ return [4 /*yield*/, ((_d = (_c = this.authOptions) === null || _c === void 0 ? void 0 : _c.credentialsProvider) === null || _d === void 0 ? void 0 : _d.getCredentialsAndIdentityId({
74
73
  authConfig: this.authConfig,
75
74
  tokens: tokens,
76
75
  authenticated: true,
@@ -79,9 +78,9 @@ var AuthClass = /** @class */ (function () {
79
78
  case 2:
80
79
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
81
80
  credentialsAndIdentityId =
82
- _k.sent();
81
+ _g.sent();
83
82
  return [3 /*break*/, 5];
84
- case 3: return [4 /*yield*/, ((_j = (_h = this.authOptions) === null || _h === void 0 ? void 0 : _h.credentialsProvider) === null || _j === void 0 ? void 0 : _j.getCredentialsAndIdentityId({
83
+ case 3: return [4 /*yield*/, ((_f = (_e = this.authOptions) === null || _e === void 0 ? void 0 : _e.credentialsProvider) === null || _f === void 0 ? void 0 : _f.getCredentialsAndIdentityId({
85
84
  authConfig: this.authConfig,
86
85
  authenticated: false,
87
86
  forceRefresh: options.forceRefresh,
@@ -89,8 +88,8 @@ var AuthClass = /** @class */ (function () {
89
88
  case 4:
90
89
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
91
90
  credentialsAndIdentityId =
92
- _k.sent();
93
- _k.label = 5;
91
+ _g.sent();
92
+ _g.label = 5;
94
93
  case 5: return [2 /*return*/, {
95
94
  tokens: tokens,
96
95
  credentials: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.credentials,
@@ -115,6 +114,17 @@ var AuthClass = /** @class */ (function () {
115
114
  });
116
115
  });
117
116
  };
117
+ AuthClass.prototype.getTokens = function (options) {
118
+ var _a, _b, _c;
119
+ return __awaiter(this, void 0, void 0, function () {
120
+ return __generator(this, function (_d) {
121
+ switch (_d.label) {
122
+ case 0: return [4 /*yield*/, ((_b = (_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.tokenProvider) === null || _b === void 0 ? void 0 : _b.getTokens(options))];
123
+ case 1: return [2 /*return*/, ((_c = (_d.sent())) !== null && _c !== void 0 ? _c : undefined)];
124
+ }
125
+ });
126
+ });
127
+ };
118
128
  return AuthClass;
119
129
  }());
120
130
  export { AuthClass };
@@ -31,9 +31,9 @@ export function assertOAuthConfig(cognitoConfig) {
31
31
  export function assertIdentityPooIdConfig(cognitoConfig) {
32
32
  var validConfig = !!(cognitoConfig === null || cognitoConfig === void 0 ? void 0 : cognitoConfig.identityPoolId);
33
33
  return asserts(validConfig, {
34
- name: 'AuthIdentityPoolIdException',
35
- message: 'Auth IdentityPoolId not configured',
36
- recoverySuggestion: 'Make sure to call Amplify.configure in your app with a valid IdentityPoolId',
34
+ name: 'InvalidIdentityPoolIdException',
35
+ message: 'Invalid identity pool id provided.',
36
+ recoverySuggestion: 'Make sure a valid identityPoolId is given in the config.',
37
37
  });
38
38
  }
39
39
  function assertUserPoolAndIdentityPooConfig(authConfig) {
@@ -3,6 +3,11 @@ export interface StorageConfig {
3
3
  S3: {
4
4
  bucket?: string;
5
5
  region?: string;
6
+ /**
7
+ * Internal-only configuration for testing purpose. You should not use this.
8
+ *
9
+ * @internal
10
+ */
6
11
  dangerouslyConnectToHttpEndpointForTesting?: string;
7
12
  };
8
13
  }
@@ -1,14 +1,23 @@
1
+ import { APIConfig, LibraryAPIOptions } from './API/types';
1
2
  import { AnalyticsConfig } from './Analytics/types';
2
3
  import { AuthConfig, LibraryAuthOptions, AuthUserPoolConfig, AuthIdentityPoolConfig, AuthUserPoolAndIdentityPoolConfig, GetCredentialsOptions, CognitoIdentityPoolConfig } from './Auth/types';
3
4
  import { LibraryStorageOptions, StorageAccessLevel, StorageConfig } from './Storage/types';
5
+ export type LegacyConfig = {
6
+ /**
7
+ * @deprecated The field should not be used.
8
+ */
9
+ aws_project_region?: string;
10
+ };
4
11
  export type ResourcesConfig = {
12
+ API?: APIConfig;
5
13
  Analytics?: AnalyticsConfig;
6
14
  Auth?: AuthConfig;
7
15
  Storage?: StorageConfig;
8
16
  };
9
17
  export type LibraryOptions = {
18
+ API?: LibraryAPIOptions;
10
19
  Auth?: LibraryAuthOptions;
11
20
  Storage?: LibraryStorageOptions;
12
21
  ssr?: boolean;
13
22
  };
14
- export { AuthConfig, AuthUserPoolConfig, AuthIdentityPoolConfig, AuthUserPoolAndIdentityPoolConfig, GetCredentialsOptions, StorageAccessLevel, StorageConfig, AnalyticsConfig, CognitoIdentityPoolConfig, };
23
+ export { APIConfig, AuthConfig, AuthUserPoolConfig, AuthIdentityPoolConfig, AuthUserPoolAndIdentityPoolConfig, GetCredentialsOptions, StorageAccessLevel, StorageConfig, AnalyticsConfig, CognitoIdentityPoolConfig, };
@@ -1,13 +1,14 @@
1
1
  import { CookieStorageData, KeyValueStorageInterface, SameSite } from '../types';
2
2
  export declare class CookieStorage implements KeyValueStorageInterface {
3
- domain?: string;
4
3
  path: string;
4
+ domain?: string;
5
5
  expires?: number;
6
- secure?: boolean;
7
6
  sameSite?: SameSite;
7
+ secure?: boolean;
8
8
  constructor(data?: CookieStorageData);
9
9
  setItem(key: string, value: string): Promise<void>;
10
- getItem(key: string): Promise<string>;
10
+ getItem(key: string): Promise<string | null>;
11
11
  removeItem(key: string): Promise<void>;
12
12
  clear(): Promise<void>;
13
+ private getData;
13
14
  }
@@ -1,3 +1,16 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
1
14
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
15
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
16
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,101 +47,60 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
47
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
48
  }
36
49
  };
37
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
38
- // SPDX-License-Identifier: Apache-2.0
39
- // @ts-ignore
40
- import * as Cookies from 'js-cookie';
50
+ import { get as getJsCookie, remove as removeJsCookie, set as setJsCookie, } from 'js-cookie';
41
51
  var CookieStorage = /** @class */ (function () {
42
52
  function CookieStorage(data) {
43
53
  if (data === void 0) { data = {}; }
44
- if (data.domain) {
45
- this.domain = data.domain;
46
- }
47
- if (data.path) {
48
- this.path = data.path;
49
- }
50
- else {
51
- this.path = '/';
52
- }
53
- if (Object.prototype.hasOwnProperty.call(data, 'expires')) {
54
- this.expires = data.expires;
55
- }
56
- else {
57
- this.expires = 365;
58
- }
59
- if (Object.prototype.hasOwnProperty.call(data, 'secure')) {
60
- this.secure = data.secure;
61
- }
62
- else {
63
- this.secure = true;
64
- }
54
+ var path = data.path, domain = data.domain, expires = data.expires, sameSite = data.sameSite, secure = data.secure;
55
+ this.domain = domain;
56
+ this.path = path ? path : '/';
57
+ this.expires = data.hasOwnProperty('expires') ? expires : 365;
58
+ this.secure = data.hasOwnProperty('secure') ? secure : true;
65
59
  if (data.hasOwnProperty('sameSite')) {
66
- if (!data.sameSite ||
67
- !['strict', 'lax', 'none'].includes(data.sameSite)) {
60
+ if (!sameSite || !['strict', 'lax', 'none'].includes(sameSite)) {
68
61
  throw new Error('The sameSite value of cookieStorage must be "lax", "strict" or "none".');
69
62
  }
70
- if (data.sameSite === 'none' && !this.secure) {
63
+ if (sameSite === 'none' && !this.secure) {
71
64
  throw new Error('sameSite = None requires the Secure attribute in latest browser versions.');
72
65
  }
73
- this.sameSite = data.sameSite;
66
+ this.sameSite = sameSite;
74
67
  }
75
68
  }
76
69
  CookieStorage.prototype.setItem = function (key, value) {
77
70
  return __awaiter(this, void 0, void 0, function () {
78
- var options;
79
71
  return __generator(this, function (_a) {
80
- options = {
81
- path: this.path,
82
- expires: this.expires,
83
- domain: this.domain,
84
- secure: this.secure,
85
- };
86
- if (this.sameSite) {
87
- options.sameSite = this.sameSite;
88
- }
89
- Cookies.set(key, value, options);
90
- return [2 /*return*/, Cookies.get(key)];
72
+ setJsCookie(key, value, this.getData());
73
+ return [2 /*return*/];
91
74
  });
92
75
  });
93
76
  };
94
77
  CookieStorage.prototype.getItem = function (key) {
95
78
  return __awaiter(this, void 0, void 0, function () {
79
+ var item;
96
80
  return __generator(this, function (_a) {
97
- return [2 /*return*/, Cookies.get(key)];
81
+ item = getJsCookie(key);
82
+ return [2 /*return*/, item !== null && item !== void 0 ? item : null];
98
83
  });
99
84
  });
100
85
  };
101
86
  CookieStorage.prototype.removeItem = function (key) {
102
87
  return __awaiter(this, void 0, void 0, function () {
103
- var options;
104
88
  return __generator(this, function (_a) {
105
- options = {
106
- path: this.path,
107
- expires: this.expires,
108
- domain: this.domain,
109
- secure: this.secure,
110
- };
111
- if (this.sameSite) {
112
- options.sameSite = this.sameSite;
113
- }
114
- Cookies.remove(key, options);
89
+ removeJsCookie(key, this.getData());
115
90
  return [2 /*return*/];
116
91
  });
117
92
  });
118
93
  };
119
94
  CookieStorage.prototype.clear = function () {
120
95
  return __awaiter(this, void 0, void 0, function () {
121
- var cookies, numKeys, promiseArray, index;
96
+ var cookie, promises;
97
+ var _this = this;
122
98
  return __generator(this, function (_a) {
123
99
  switch (_a.label) {
124
100
  case 0:
125
- cookies = Cookies.get();
126
- numKeys = Object.keys(cookies).length;
127
- promiseArray = [];
128
- for (index = 0; index < numKeys; ++index) {
129
- promiseArray.push(this.removeItem(Object.keys(cookies)[index]));
130
- }
131
- return [4 /*yield*/, Promise.all(promiseArray)];
101
+ cookie = getJsCookie();
102
+ promises = Object.keys(cookie).map(function (key) { return _this.removeItem(key); });
103
+ return [4 /*yield*/, Promise.all(promises)];
132
104
  case 1:
133
105
  _a.sent();
134
106
  return [2 /*return*/];
@@ -136,6 +108,9 @@ var CookieStorage = /** @class */ (function () {
136
108
  });
137
109
  });
138
110
  };
111
+ CookieStorage.prototype.getData = function () {
112
+ return __assign({ path: this.path, expires: this.expires, domain: this.domain, secure: this.secure }, (this.sameSite && { sameSite: this.sameSite }));
113
+ };
139
114
  return CookieStorage;
140
115
  }());
141
116
  export { CookieStorage };
@@ -0,0 +1,7 @@
1
+ import { KeyValueStorage } from './KeyValueStorage';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class CookieStorage extends KeyValueStorage {
6
+ constructor();
7
+ }
@@ -0,0 +1,29 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var __extends = (this && this.__extends) || (function () {
4
+ var extendStatics = function (d, b) {
5
+ extendStatics = Object.setPrototypeOf ||
6
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
+ return extendStatics(d, b);
9
+ };
10
+ return function (d, b) {
11
+ if (typeof b !== "function" && b !== null)
12
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
+ extendStatics(d, b);
14
+ function __() { this.constructor = d; }
15
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
+ };
17
+ })();
18
+ import { KeyValueStorage } from './KeyValueStorage';
19
+ /**
20
+ * @internal
21
+ */
22
+ var CookieStorage = /** @class */ (function (_super) {
23
+ __extends(CookieStorage, _super);
24
+ function CookieStorage() {
25
+ return _super.call(this) || this;
26
+ }
27
+ return CookieStorage;
28
+ }(KeyValueStorage));
29
+ export { CookieStorage };
@@ -0,0 +1,7 @@
1
+ import { KeyValueStorage } from './KeyValueStorage';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class DefaultStorage extends KeyValueStorage {
6
+ constructor();
7
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var __extends = (this && this.__extends) || (function () {
4
+ var extendStatics = function (d, b) {
5
+ extendStatics = Object.setPrototypeOf ||
6
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
+ return extendStatics(d, b);
9
+ };
10
+ return function (d, b) {
11
+ if (typeof b !== "function" && b !== null)
12
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
+ extendStatics(d, b);
14
+ function __() { this.constructor = d; }
15
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
+ };
17
+ })();
18
+ import { KeyValueStorage } from './KeyValueStorage';
19
+ import { getDefaultStorageWithFallback } from './utils';
20
+ /**
21
+ * @internal
22
+ */
23
+ var DefaultStorage = /** @class */ (function (_super) {
24
+ __extends(DefaultStorage, _super);
25
+ function DefaultStorage() {
26
+ return _super.call(this, getDefaultStorageWithFallback()) || this;
27
+ }
28
+ return DefaultStorage;
29
+ }(KeyValueStorage));
30
+ export { DefaultStorage };
@@ -1,7 +1,9 @@
1
- import { KeyValueStorageInterface } from "../types";
2
- declare class LocalStorageClass implements KeyValueStorageInterface {
3
- storage?: Storage;
4
- constructor();
1
+ import { KeyValueStorageInterface } from '../types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class DefaultStorage implements KeyValueStorageInterface {
6
+ private asyncStorage?;
5
7
  /**
6
8
  * This is used to set a specific item in storage
7
9
  * @param {string} key - the key for the item
@@ -27,6 +29,5 @@ declare class LocalStorageClass implements KeyValueStorageInterface {
27
29
  * @returns {string} nothing
28
30
  */
29
31
  clear(): Promise<void>;
32
+ private assertModule;
30
33
  }
31
- export declare const LocalStorage: LocalStorageClass;
32
- export {};
@@ -36,15 +36,14 @@ 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 { 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
- }
39
+ import { AmplifyError } from '../libraryUtils';
40
+ var ASYNC_STORAGE_MODULE = '@react-native-async-storage/async-storage';
41
+ var MEMORY_KEY_PREFIX = '@MemoryStorage:';
42
+ /**
43
+ * @internal
44
+ */
45
+ var DefaultStorage = /** @class */ (function () {
46
+ function DefaultStorage() {
48
47
  }
49
48
  /**
50
49
  * This is used to set a specific item in storage
@@ -52,15 +51,9 @@ var SessionStorageClass = /** @class */ (function () {
52
51
  * @param {object} value - the value
53
52
  * @returns {string} value that was set
54
53
  */
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
- });
54
+ DefaultStorage.prototype.setItem = function (key, value) {
55
+ this.assertModule(this.asyncStorage);
56
+ return this.asyncStorage.setItem("".concat(MEMORY_KEY_PREFIX).concat(key), value);
64
57
  };
65
58
  /**
66
59
  * This is used to get a specific key from storage
@@ -68,44 +61,54 @@ var SessionStorageClass = /** @class */ (function () {
68
61
  * This is used to clear the storage
69
62
  * @returns {string} the data item
70
63
  */
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
- });
64
+ DefaultStorage.prototype.getItem = function (key) {
65
+ this.assertModule(this.asyncStorage);
66
+ return this.asyncStorage.getItem("".concat(MEMORY_KEY_PREFIX).concat(key));
79
67
  };
80
68
  /**
81
69
  * This is used to remove an item from storage
82
70
  * @param {string} key - the key being set
83
71
  * @returns {string} value - value that was deleted
84
72
  */
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
- });
73
+ DefaultStorage.prototype.removeItem = function (key) {
74
+ this.assertModule(this.asyncStorage);
75
+ return this.asyncStorage.removeItem("".concat(MEMORY_KEY_PREFIX).concat(key));
94
76
  };
95
77
  /**
96
78
  * This is used to clear the storage
97
79
  * @returns {string} nothing
98
80
  */
99
- SessionStorageClass.prototype.clear = function () {
81
+ DefaultStorage.prototype.clear = function () {
100
82
  return __awaiter(this, void 0, void 0, function () {
83
+ var allKeys;
101
84
  return __generator(this, function (_a) {
102
- if (!this.storage)
103
- throw PlatformNotSupportedError;
104
- this.storage.clear();
105
- return [2 /*return*/];
85
+ switch (_a.label) {
86
+ case 0:
87
+ this.assertModule(this.asyncStorage);
88
+ return [4 /*yield*/, this.asyncStorage.getAllKeys()];
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
+ }
106
93
  });
107
94
  });
108
95
  };
109
- return SessionStorageClass;
96
+ DefaultStorage.prototype.assertModule = function (asyncStorage) {
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;
110
113
  }());
111
- export var SessionStorage = new SessionStorageClass();
114
+ export { DefaultStorage };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export declare class InMemoryStorage implements Storage {
5
+ storage: Map<string, string>;
6
+ get length(): number;
7
+ key(index: number): string | null;
8
+ setItem(key: string, value: string): void;
9
+ getItem(key: string): string | null;
10
+ removeItem(key: string): void;
11
+ clear(): void;
12
+ }
@@ -0,0 +1,38 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * @internal
5
+ */
6
+ var InMemoryStorage = /** @class */ (function () {
7
+ function InMemoryStorage() {
8
+ this.storage = new Map();
9
+ }
10
+ Object.defineProperty(InMemoryStorage.prototype, "length", {
11
+ get: function () {
12
+ return this.storage.size;
13
+ },
14
+ enumerable: false,
15
+ configurable: true
16
+ });
17
+ InMemoryStorage.prototype.key = function (index) {
18
+ if (index > this.length - 1) {
19
+ return null;
20
+ }
21
+ return Array.from(this.storage.keys())[index];
22
+ };
23
+ InMemoryStorage.prototype.setItem = function (key, value) {
24
+ this.storage.set(key, value);
25
+ };
26
+ InMemoryStorage.prototype.getItem = function (key) {
27
+ var _a;
28
+ return (_a = this.storage.get(key)) !== null && _a !== void 0 ? _a : null;
29
+ };
30
+ InMemoryStorage.prototype.removeItem = function (key) {
31
+ this.storage.delete(key);
32
+ };
33
+ InMemoryStorage.prototype.clear = function () {
34
+ this.storage.clear();
35
+ };
36
+ return InMemoryStorage;
37
+ }());
38
+ export { InMemoryStorage };
@@ -1,7 +1,10 @@
1
1
  import { KeyValueStorageInterface } from '../types';
2
- declare class SessionStorageClass implements KeyValueStorageInterface {
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class KeyValueStorage implements KeyValueStorageInterface {
3
6
  storage?: Storage;
4
- constructor();
7
+ constructor(storage?: Storage);
5
8
  /**
6
9
  * This is used to set a specific item in storage
7
10
  * @param {string} key - the key for the item
@@ -28,5 +31,3 @@ declare class SessionStorageClass implements KeyValueStorageInterface {
28
31
  */
29
32
  clear(): Promise<void>;
30
33
  }
31
- export declare const SessionStorage: SessionStorageClass;
32
- export {};
@@ -37,14 +37,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  }
38
38
  };
39
39
  import { PlatformNotSupportedError } from '../Util/Errors';
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
- }
40
+ /**
41
+ * @internal
42
+ */
43
+ var KeyValueStorage = /** @class */ (function () {
44
+ function KeyValueStorage(storage) {
45
+ this.storage = storage;
48
46
  }
49
47
  /**
50
48
  * This is used to set a specific item in storage
@@ -52,7 +50,7 @@ var LocalStorageClass = /** @class */ (function () {
52
50
  * @param {object} value - the value
53
51
  * @returns {string} value that was set
54
52
  */
55
- LocalStorageClass.prototype.setItem = function (key, value) {
53
+ KeyValueStorage.prototype.setItem = function (key, value) {
56
54
  return __awaiter(this, void 0, void 0, function () {
57
55
  return __generator(this, function (_a) {
58
56
  if (!this.storage)
@@ -68,7 +66,7 @@ var LocalStorageClass = /** @class */ (function () {
68
66
  * This is used to clear the storage
69
67
  * @returns {string} the data item
70
68
  */
71
- LocalStorageClass.prototype.getItem = function (key) {
69
+ KeyValueStorage.prototype.getItem = function (key) {
72
70
  return __awaiter(this, void 0, void 0, function () {
73
71
  return __generator(this, function (_a) {
74
72
  if (!this.storage)
@@ -82,7 +80,7 @@ var LocalStorageClass = /** @class */ (function () {
82
80
  * @param {string} key - the key being set
83
81
  * @returns {string} value - value that was deleted
84
82
  */
85
- LocalStorageClass.prototype.removeItem = function (key) {
83
+ KeyValueStorage.prototype.removeItem = function (key) {
86
84
  return __awaiter(this, void 0, void 0, function () {
87
85
  return __generator(this, function (_a) {
88
86
  if (!this.storage)
@@ -96,7 +94,7 @@ var LocalStorageClass = /** @class */ (function () {
96
94
  * This is used to clear the storage
97
95
  * @returns {string} nothing
98
96
  */
99
- LocalStorageClass.prototype.clear = function () {
97
+ KeyValueStorage.prototype.clear = function () {
100
98
  return __awaiter(this, void 0, void 0, function () {
101
99
  return __generator(this, function (_a) {
102
100
  if (!this.storage)
@@ -106,6 +104,6 @@ var LocalStorageClass = /** @class */ (function () {
106
104
  });
107
105
  });
108
106
  };
109
- return LocalStorageClass;
107
+ return KeyValueStorage;
110
108
  }());
111
- export var LocalStorage = new LocalStorageClass();
109
+ export { KeyValueStorage };
@@ -0,0 +1,7 @@
1
+ import { KeyValueStorage } from './KeyValueStorage';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class SessionStorage extends KeyValueStorage {
6
+ constructor();
7
+ }