@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
@@ -3,7 +3,7 @@ import { PinpointAnalyticsEvent, PinpointSession } from './pinpoint';
3
3
  export type EventBufferConfig = {
4
4
  appId: string;
5
5
  bufferSize: number;
6
- credentials: AuthSession['credentials'];
6
+ credentials: Required<AuthSession>['credentials'];
7
7
  identityId: AuthSession['identityId'];
8
8
  flushInterval: number;
9
9
  flushSize: number;
@@ -24,17 +24,17 @@ export type PinpointAnalyticsEvent = {
24
24
  type PinpointCommonParameters = {
25
25
  appId: string;
26
26
  category: SupportedCategory;
27
- credentials: AuthSession['credentials'];
27
+ credentials: Required<AuthSession>['credentials'];
28
28
  identityId?: AuthSession['identityId'];
29
29
  region: string;
30
30
  userAgentValue?: string;
31
31
  };
32
- export type PinpointUpdateEndpointParameters = PinpointCommonParameters & PinpointServiceOptions & {
32
+ export type PinpointUpdateEndpointInput = PinpointCommonParameters & PinpointServiceOptions & {
33
33
  channelType?: SupportedChannelType;
34
34
  userId?: string;
35
35
  userProfile?: UserProfile;
36
36
  };
37
- export type PinpointRecordParameters = PinpointCommonParameters & {
37
+ export type PinpointRecordInput = PinpointCommonParameters & {
38
38
  event: PinpointAnalyticsEvent;
39
39
  };
40
40
  export {};
@@ -77,7 +77,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
77
77
  exports.PinpointEventBuffer = void 0;
78
78
  var Logger_1 = require("../../../Logger");
79
79
  var Pinpoint_1 = require("../../../AwsClients/Pinpoint");
80
- var isAppInForeground_1 = require("../../../RNComponents/isAppInForeground");
80
+ var isAppInForeground_1 = require("./isAppInForeground");
81
81
  var logger = new Logger_1.ConsoleLogger('PinpointEventBuffer');
82
82
  var RETRYABLE_CODES = [429, 500];
83
83
  var ACCEPTED_CODES = [202];
@@ -94,7 +94,9 @@ var PinpointEventBuffer = /** @class */ (function () {
94
94
  PinpointEventBuffer.prototype.push = function (event) {
95
95
  var _a;
96
96
  if (this._buffer.length >= this._config.bufferSize) {
97
- logger.debug('Exceeded Pinpoint event buffer limits, event dropped.', { eventId: event.eventId });
97
+ logger.debug('Exceeded Pinpoint event buffer limits, event dropped.', {
98
+ eventId: event.eventId,
99
+ });
98
100
  return;
99
101
  }
100
102
  this._buffer.push((_a = {}, _a[event.eventId] = event, _a));
@@ -233,7 +235,7 @@ var PinpointEventBuffer = /** @class */ (function () {
233
235
  logger.warn('Pinpoint event failed to send.', {
234
236
  eventId: eventId,
235
237
  name: name,
236
- message: Message
238
+ message: Message,
237
239
  });
238
240
  });
239
241
  });
@@ -253,14 +255,14 @@ var PinpointEventBuffer = /** @class */ (function () {
253
255
  logger.debug('Resending event.', {
254
256
  eventId: eventId,
255
257
  name: name,
256
- remainingAttempts: bufferedEvent.resendLimit
258
+ remainingAttempts: bufferedEvent.resendLimit,
257
259
  });
258
260
  eligibleEvents.push((_a = {}, _a[eventId] = bufferedEvent, _a));
259
261
  return;
260
262
  }
261
263
  logger.debug('No retry attempts remaining for event.', {
262
264
  eventId: eventId,
263
- name: name
265
+ name: name,
264
266
  });
265
267
  });
266
268
  // add the events to the front of the buffer
@@ -0,0 +1 @@
1
+ export declare const isAppInForeground: () => boolean;
@@ -3,8 +3,5 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.isAppInForeground = void 0;
6
- var _1 = require(".");
7
- var isAppInForeground = function () {
8
- return _1.AppState.currentState === 'active';
9
- };
6
+ var isAppInForeground = function () { return true; };
10
7
  exports.isAppInForeground = isAppInForeground;
@@ -0,0 +1 @@
1
+ export declare const isAppInForeground: () => boolean;
@@ -0,0 +1,9 @@
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.isAppInForeground = void 0;
6
+ // @ts-ignore: missing type definition
7
+ var react_native_1 = require("react-native");
8
+ var isAppInForeground = function () { return react_native_1.AppState.currentState === 'active'; };
9
+ exports.isAppInForeground = isAppInForeground;
@@ -0,0 +1,34 @@
1
+ export type LibraryAPIOptions = {
2
+ AppSync: {
3
+ query: string;
4
+ variables?: object;
5
+ authMode?: any;
6
+ authToken?: string;
7
+ /**
8
+ * @deprecated This property should not be used
9
+ */
10
+ userAgentSuffix?: string;
11
+ };
12
+ customHeaders: Function;
13
+ };
14
+ export type APIConfig = {
15
+ AppSync?: {
16
+ defaultAuthMode?: GraphQLAuthMode;
17
+ region?: string;
18
+ endpoint?: string;
19
+ modelIntrospectionSchema?: any;
20
+ };
21
+ };
22
+ export type GraphQLAuthMode = {
23
+ type: 'apiKey';
24
+ apiKey: string;
25
+ } | {
26
+ type: 'jwt';
27
+ token: 'id' | 'access';
28
+ } | {
29
+ type: 'iam';
30
+ } | {
31
+ type: 'lambda';
32
+ } | {
33
+ type: 'custom';
34
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
1
  import { AuthClass } from './Auth';
2
- import { LibraryOptions, ResourcesConfig } from './types';
2
+ import { LegacyConfig, LibraryOptions, ResourcesConfig } from './types';
3
3
  export declare class AmplifyClass {
4
4
  resourcesConfig: ResourcesConfig;
5
5
  libraryOptions: LibraryOptions;
@@ -19,7 +19,7 @@ export declare class AmplifyClass {
19
19
  * @param resourceConfig - Back-end resource configuration. Typically provided via the `aws-exports.js` file.
20
20
  * @param libraryOptions - Additional options for customizing the behavior of the library.
21
21
  */
22
- configure(resourcesConfig: ResourcesConfig, libraryOptions?: LibraryOptions): void;
22
+ configure(resourcesConfig: ResourcesConfig | LegacyConfig, libraryOptions?: LibraryOptions): void;
23
23
  /**
24
24
  * Provides access to the current back-end resource configuration for the Library.
25
25
  *
@@ -27,6 +27,7 @@ exports.Amplify = exports.AmplifyClass = void 0;
27
27
  // SPDX-License-Identifier: Apache-2.0
28
28
  var Auth_1 = require("./Auth");
29
29
  var Hub_1 = require("../Hub");
30
+ var parseAWSExports_1 = require("../parseAWSExports");
30
31
  // TODO(v6): add default AuthTokenStore for each platform
31
32
  var AmplifyClass = /** @class */ (function () {
32
33
  function AmplifyClass() {
@@ -46,7 +47,14 @@ var AmplifyClass = /** @class */ (function () {
46
47
  */
47
48
  AmplifyClass.prototype.configure = function (resourcesConfig, libraryOptions) {
48
49
  if (libraryOptions === void 0) { libraryOptions = {}; }
49
- this.resourcesConfig = mergeResourceConfig(this.resourcesConfig, resourcesConfig);
50
+ var resolvedResourceConfig;
51
+ if (Object.keys(resourcesConfig).some(function (key) { return key.startsWith('aws_'); })) {
52
+ resolvedResourceConfig = (0, parseAWSExports_1.parseAWSExports)(resourcesConfig);
53
+ }
54
+ else {
55
+ resolvedResourceConfig = resourcesConfig;
56
+ }
57
+ this.resourcesConfig = mergeResourceConfig(this.resourcesConfig, resolvedResourceConfig);
50
58
  this.libraryOptions = mergeLibraryOptions(this.libraryOptions, libraryOptions);
51
59
  this.Auth.configure(this.resourcesConfig.Auth, this.libraryOptions.Auth);
52
60
  Hub_1.Hub.dispatch('core', {
@@ -1,4 +1,4 @@
1
- import { AuthConfig, AuthSession, FetchAuthSessionOptions, LibraryAuthOptions } from './types';
1
+ import { AuthConfig, AuthSession, AuthTokens, FetchAuthSessionOptions, LibraryAuthOptions } from './types';
2
2
  export declare function isTokenExpired({ expiresAt, clockDrift, }: {
3
3
  expiresAt: number;
4
4
  clockDrift: number;
@@ -20,4 +20,5 @@ export declare class AuthClass {
20
20
  configure(authResourcesConfig: AuthConfig, authOptions?: LibraryAuthOptions): void;
21
21
  fetchAuthSession(options?: FetchAuthSessionOptions): Promise<AuthSession>;
22
22
  clearCredentials(): Promise<void>;
23
+ getTokens(options: FetchAuthSessionOptions): Promise<AuthTokens | undefined>;
23
24
  }
@@ -61,20 +61,19 @@ var AuthClass = /** @class */ (function () {
61
61
  this.authOptions = authOptions;
62
62
  };
63
63
  AuthClass.prototype.fetchAuthSession = function (options) {
64
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
64
+ var _a, _b, _c, _d, _e, _f;
65
65
  if (options === void 0) { options = {}; }
66
66
  return __awaiter(this, void 0, void 0, function () {
67
67
  var tokens, credentialsAndIdentityId, userSub;
68
- return __generator(this, function (_k) {
69
- switch (_k.label) {
70
- 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))];
68
+ return __generator(this, function (_g) {
69
+ switch (_g.label) {
70
+ case 0: return [4 /*yield*/, this.getTokens(options)];
71
71
  case 1:
72
72
  // Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
73
- tokens =
74
- (_c = (_k.sent())) !== null && _c !== void 0 ? _c : undefined;
73
+ tokens = _g.sent();
75
74
  if (!tokens) return [3 /*break*/, 3];
76
- userSub = (_e = (_d = tokens.accessToken) === null || _d === void 0 ? void 0 : _d.payload) === null || _e === void 0 ? void 0 : _e.sub;
77
- return [4 /*yield*/, ((_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.credentialsProvider) === null || _g === void 0 ? void 0 : _g.getCredentialsAndIdentityId({
75
+ userSub = (_b = (_a = tokens.accessToken) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.sub;
76
+ return [4 /*yield*/, ((_d = (_c = this.authOptions) === null || _c === void 0 ? void 0 : _c.credentialsProvider) === null || _d === void 0 ? void 0 : _d.getCredentialsAndIdentityId({
78
77
  authConfig: this.authConfig,
79
78
  tokens: tokens,
80
79
  authenticated: true,
@@ -83,9 +82,9 @@ var AuthClass = /** @class */ (function () {
83
82
  case 2:
84
83
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
85
84
  credentialsAndIdentityId =
86
- _k.sent();
85
+ _g.sent();
87
86
  return [3 /*break*/, 5];
88
- 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({
87
+ 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({
89
88
  authConfig: this.authConfig,
90
89
  authenticated: false,
91
90
  forceRefresh: options.forceRefresh,
@@ -93,8 +92,8 @@ var AuthClass = /** @class */ (function () {
93
92
  case 4:
94
93
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
95
94
  credentialsAndIdentityId =
96
- _k.sent();
97
- _k.label = 5;
95
+ _g.sent();
96
+ _g.label = 5;
98
97
  case 5: return [2 /*return*/, {
99
98
  tokens: tokens,
100
99
  credentials: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.credentials,
@@ -119,6 +118,17 @@ var AuthClass = /** @class */ (function () {
119
118
  });
120
119
  });
121
120
  };
121
+ AuthClass.prototype.getTokens = function (options) {
122
+ var _a, _b, _c;
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ return __generator(this, function (_d) {
125
+ switch (_d.label) {
126
+ 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))];
127
+ case 1: return [2 /*return*/, ((_c = (_d.sent())) !== null && _c !== void 0 ? _c : undefined)];
128
+ }
129
+ });
130
+ });
131
+ };
122
132
  return AuthClass;
123
133
  }());
124
134
  exports.AuthClass = AuthClass;
@@ -36,9 +36,9 @@ exports.assertOAuthConfig = assertOAuthConfig;
36
36
  function assertIdentityPooIdConfig(cognitoConfig) {
37
37
  var validConfig = !!(cognitoConfig === null || cognitoConfig === void 0 ? void 0 : cognitoConfig.identityPoolId);
38
38
  return (0, AssertError_1.asserts)(validConfig, {
39
- name: 'AuthIdentityPoolIdException',
40
- message: 'Auth IdentityPoolId not configured',
41
- recoverySuggestion: 'Make sure to call Amplify.configure in your app with a valid IdentityPoolId',
39
+ name: 'InvalidIdentityPoolIdException',
40
+ message: 'Invalid identity pool id provided.',
41
+ recoverySuggestion: 'Make sure a valid identityPoolId is given in the config.',
42
42
  });
43
43
  }
44
44
  exports.assertIdentityPooIdConfig = assertIdentityPooIdConfig;
@@ -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,26 +1,16 @@
1
1
  "use strict";
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;
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);
24
14
  };
25
15
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
16
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -60,101 +50,60 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
60
50
  };
61
51
  Object.defineProperty(exports, "__esModule", { value: true });
62
52
  exports.CookieStorage = void 0;
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"));
53
+ var js_cookie_1 = require("js-cookie");
67
54
  var CookieStorage = /** @class */ (function () {
68
55
  function CookieStorage(data) {
69
56
  if (data === void 0) { data = {}; }
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
- }
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;
91
62
  if (data.hasOwnProperty('sameSite')) {
92
- if (!data.sameSite ||
93
- !['strict', 'lax', 'none'].includes(data.sameSite)) {
63
+ if (!sameSite || !['strict', 'lax', 'none'].includes(sameSite)) {
94
64
  throw new Error('The sameSite value of cookieStorage must be "lax", "strict" or "none".');
95
65
  }
96
- if (data.sameSite === 'none' && !this.secure) {
66
+ if (sameSite === 'none' && !this.secure) {
97
67
  throw new Error('sameSite = None requires the Secure attribute in latest browser versions.');
98
68
  }
99
- this.sameSite = data.sameSite;
69
+ this.sameSite = sameSite;
100
70
  }
101
71
  }
102
72
  CookieStorage.prototype.setItem = function (key, value) {
103
73
  return __awaiter(this, void 0, void 0, function () {
104
- var options;
105
74
  return __generator(this, function (_a) {
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)];
75
+ (0, js_cookie_1.set)(key, value, this.getData());
76
+ return [2 /*return*/];
117
77
  });
118
78
  });
119
79
  };
120
80
  CookieStorage.prototype.getItem = function (key) {
121
81
  return __awaiter(this, void 0, void 0, function () {
82
+ var item;
122
83
  return __generator(this, function (_a) {
123
- return [2 /*return*/, Cookies.get(key)];
84
+ item = (0, js_cookie_1.get)(key);
85
+ return [2 /*return*/, item !== null && item !== void 0 ? item : null];
124
86
  });
125
87
  });
126
88
  };
127
89
  CookieStorage.prototype.removeItem = function (key) {
128
90
  return __awaiter(this, void 0, void 0, function () {
129
- var options;
130
91
  return __generator(this, function (_a) {
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);
92
+ (0, js_cookie_1.remove)(key, this.getData());
141
93
  return [2 /*return*/];
142
94
  });
143
95
  });
144
96
  };
145
97
  CookieStorage.prototype.clear = function () {
146
98
  return __awaiter(this, void 0, void 0, function () {
147
- var cookies, numKeys, promiseArray, index;
99
+ var cookie, promises;
100
+ var _this = this;
148
101
  return __generator(this, function (_a) {
149
102
  switch (_a.label) {
150
103
  case 0:
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)];
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)];
158
107
  case 1:
159
108
  _a.sent();
160
109
  return [2 /*return*/];
@@ -162,6 +111,9 @@ var CookieStorage = /** @class */ (function () {
162
111
  });
163
112
  });
164
113
  };
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
+ };
165
117
  return CookieStorage;
166
118
  }());
167
119
  exports.CookieStorage = 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,32 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __extends = (this && this.__extends) || (function () {
5
+ var extendStatics = function (d, b) {
6
+ extendStatics = Object.setPrototypeOf ||
7
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
9
+ return extendStatics(d, b);
10
+ };
11
+ return function (d, b) {
12
+ if (typeof b !== "function" && b !== null)
13
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
14
+ extendStatics(d, b);
15
+ function __() { this.constructor = d; }
16
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17
+ };
18
+ })();
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.CookieStorage = void 0;
21
+ var KeyValueStorage_1 = require("./KeyValueStorage");
22
+ /**
23
+ * @internal
24
+ */
25
+ var CookieStorage = /** @class */ (function (_super) {
26
+ __extends(CookieStorage, _super);
27
+ function CookieStorage() {
28
+ return _super.call(this) || this;
29
+ }
30
+ return CookieStorage;
31
+ }(KeyValueStorage_1.KeyValueStorage));
32
+ exports.CookieStorage = 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,33 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __extends = (this && this.__extends) || (function () {
5
+ var extendStatics = function (d, b) {
6
+ extendStatics = Object.setPrototypeOf ||
7
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
9
+ return extendStatics(d, b);
10
+ };
11
+ return function (d, b) {
12
+ if (typeof b !== "function" && b !== null)
13
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
14
+ extendStatics(d, b);
15
+ function __() { this.constructor = d; }
16
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17
+ };
18
+ })();
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.DefaultStorage = void 0;
21
+ var KeyValueStorage_1 = require("./KeyValueStorage");
22
+ var utils_1 = require("./utils");
23
+ /**
24
+ * @internal
25
+ */
26
+ var DefaultStorage = /** @class */ (function (_super) {
27
+ __extends(DefaultStorage, _super);
28
+ function DefaultStorage() {
29
+ return _super.call(this, (0, utils_1.getDefaultStorageWithFallback)()) || this;
30
+ }
31
+ return DefaultStorage;
32
+ }(KeyValueStorage_1.KeyValueStorage));
33
+ exports.DefaultStorage = 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 {};