@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
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { CacheConfig } from '../types';
5
- import { StorageHelper } from '../../StorageHelper';
5
+ import { getDefaultStorageWithFallback } from '../../storage/utils';
6
6
  /**
7
7
  * Default cache config
8
8
  */
@@ -13,9 +13,7 @@ export const defaultConfig: CacheConfig = {
13
13
  defaultTTL: 259200000, // about 3 days
14
14
  defaultPriority: 5,
15
15
  warningThreshold: 0.8,
16
- // the storage helper will check if localStorage exists,
17
- // if not, will use a in-memory object instead
18
- storage: new StorageHelper().getStorage(),
16
+ storage: getDefaultStorageWithFallback(),
19
17
  };
20
18
 
21
19
  /**
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '6.0.1-console-preview.814dea6.0+814dea6';
2
+ export const version = '6.0.1-console-preview.047a1dd.0+047a1dd';
@@ -13,7 +13,7 @@
13
13
  * and limitations under the License.
14
14
  */
15
15
  import { ConsoleLogger as Logger } from '../Logger';
16
- import { browserOrNode } from '../Util/JS';
16
+ import { isBrowser } from '../Util/JS';
17
17
  import { Amplify } from '../Amplify';
18
18
  import { asserts } from '../Util/errors/AssertError';
19
19
  import { AmplifyError } from '../Util/Errors';
@@ -136,7 +136,7 @@ export class ServiceWorkerClass {
136
136
  });
137
137
  this._publicKey = publicKey;
138
138
  return new Promise((resolve, reject) => {
139
- if (browserOrNode().isBrowser) {
139
+ if (isBrowser()) {
140
140
  asserts(this._registration !== undefined, {
141
141
  name: SERVICE_WORKER_EXCEPTION,
142
142
  message: 'Service Worker registration is undefined',
package/src/Util/JS.ts CHANGED
@@ -170,19 +170,8 @@ export const isWebWorker = () => {
170
170
  );
171
171
  };
172
172
 
173
- export const browserOrNode = () => {
174
- const isBrowser =
175
- typeof window !== 'undefined' && typeof window.document !== 'undefined';
176
- const isNode =
177
- typeof process !== 'undefined' &&
178
- process.versions != null &&
179
- process.versions.node != null;
180
-
181
- return {
182
- isBrowser,
183
- isNode,
184
- };
185
- };
173
+ export const isBrowser = () =>
174
+ typeof window !== 'undefined' && typeof window.document !== 'undefined';
186
175
 
187
176
  /**
188
177
  * transfer the first letter of the keys to lowercase
@@ -1,7 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import Observable, { ZenObservable } from 'zen-observable-ts';
4
- import { browserOrNode, isWebWorker } from './JS';
4
+ import { isWebWorker } from './JS';
5
5
 
6
6
  type NetworkStatus = {
7
7
  online: boolean;
@@ -13,10 +13,6 @@ export default class ReachabilityNavigator implements Reachability {
13
13
  > = [];
14
14
 
15
15
  networkMonitor(netInfo?: any): Observable<NetworkStatus> {
16
- if (browserOrNode().isNode) {
17
- return Observable.from([{ online: true }]);
18
- }
19
-
20
16
  const globalObj = isWebWorker() ? self : window;
21
17
 
22
18
  return new Observable(observer => {
@@ -11,7 +11,8 @@ import { HttpRequest, HttpResponse } from '../types';
11
11
  export const authenticatedHandler = composeTransferHandler<
12
12
  [UserAgentOptions, RetryOptions<HttpResponse>, SigningOptions],
13
13
  HttpRequest,
14
- HttpResponse
14
+ HttpResponse,
15
+ typeof fetchTransferHandler
15
16
  >(fetchTransferHandler, [
16
17
  userAgentMiddleware,
17
18
  retryMiddleware,
@@ -1,7 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import 'isomorphic-unfetch'; // TODO: remove this dependency in v6
5
4
  import { HttpRequest, HttpResponse, HttpTransferOptions } from '../types/http';
6
5
  import { TransferHandler } from '../types/core';
7
6
  import { withMemoization } from '../utils/memoization';
@@ -14,7 +13,7 @@ export const fetchTransferHandler: TransferHandler<
14
13
  HttpRequest,
15
14
  HttpResponse,
16
15
  HttpTransferOptions
17
- > = async ({ url, method, headers, body }, { abortSignal }) => {
16
+ > = async ({ url, method, headers, body }, { abortSignal, cache }) => {
18
17
  let resp: Response;
19
18
  try {
20
19
  resp = await fetch(url, {
@@ -22,6 +21,7 @@ export const fetchTransferHandler: TransferHandler<
22
21
  headers,
23
22
  body: shouldSendBody(method) ? body : undefined,
24
23
  signal: abortSignal,
24
+ cache,
25
25
  });
26
26
  } catch (e) {
27
27
  // TODO: needs to revise error handling in v6
@@ -10,5 +10,6 @@ import { HttpRequest, HttpResponse } from '../types';
10
10
  export const unauthenticatedHandler = composeTransferHandler<
11
11
  [UserAgentOptions, RetryOptions<HttpResponse>],
12
12
  HttpRequest,
13
- HttpResponse
13
+ HttpResponse,
14
+ typeof fetchTransferHandler
14
15
  >(fetchTransferHandler, [userAgentMiddleware, retryMiddleware]);
@@ -29,7 +29,7 @@ export const composeServiceApi = <
29
29
  ServiceClientOptions &
30
30
  Partial<DefaultConfig> &
31
31
  InferEndpointResolverOptionType<DefaultConfig>,
32
- keyof DefaultConfig
32
+ DefaultConfig
33
33
  >,
34
34
  input: Input
35
35
  ) => {
@@ -54,8 +54,15 @@ export const composeServiceApi = <
54
54
  };
55
55
  };
56
56
 
57
- type OptionalizeKey<T, K extends keyof T> = Omit<T, K> & {
58
- [P in K & keyof T]?: T[P];
57
+ type OptionalizeKey<InputType, InputDefaultsType> = {
58
+ [KeyWithDefaultValue in keyof InputDefaultsType]?: KeyWithDefaultValue extends keyof InputType
59
+ ? InputType[KeyWithDefaultValue]
60
+ : never;
61
+ } & {
62
+ [KeyWithoutDefaultValue in keyof Omit<
63
+ InputType,
64
+ keyof InputDefaultsType
65
+ >]: InputType[KeyWithoutDefaultValue];
59
66
  };
60
67
 
61
68
  type InferEndpointResolverOptionType<T> = T extends {
@@ -5,7 +5,10 @@ import { MetadataBearer } from '@aws-sdk/types';
5
5
  import { Endpoint } from './core';
6
6
  import { HttpResponse } from './http';
7
7
 
8
- export type { Credentials, MetadataBearer } from '@aws-sdk/types';
8
+ export type {
9
+ AwsCredentialIdentity as Credentials,
10
+ MetadataBearer,
11
+ } from '@aws-sdk/types';
9
12
 
10
13
  export type SourceData = string | ArrayBuffer | ArrayBufferView;
11
14
 
@@ -26,13 +29,3 @@ export interface ServiceClientOptions {
26
29
  export type ErrorParser = (
27
30
  response?: HttpResponse
28
31
  ) => Promise<(Error & MetadataBearer) | undefined>;
29
-
30
- /**
31
- * Default config options for the `composeServiceApi`.
32
- */
33
- export type DefaultConfigOptions<
34
- TransferHandlerOptions extends Record<string, unknown> = Record<
35
- string,
36
- unknown
37
- >
38
- > = Partial<TransferHandlerOptions & ServiceClientOptions>;
@@ -34,6 +34,14 @@ export interface HttpResponse extends Response {
34
34
 
35
35
  export interface HttpTransferOptions {
36
36
  abortSignal?: AbortSignal;
37
+ /**
38
+ * Cache mode for the request. Note that this is only effective when the underlying HTTP handler is fetch.
39
+ * For XHR handler, or Node.js `"http(s)"` module or running on React Native, this option is ignored.
40
+ * Instead, you can configure the `Cache-Control` headers to achieve similar effects.
41
+ * @default 'default'
42
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/cache}
43
+ */
44
+ cache?: RequestCache;
37
45
  }
38
46
 
39
47
  export type HttpTransferHandler = TransferHandler<
@@ -22,5 +22,4 @@ export {
22
22
  EndpointResolverOptions,
23
23
  ErrorParser,
24
24
  ServiceClientOptions,
25
- DefaultConfigOptions,
26
25
  } from './aws';
package/src/index.ts CHANGED
@@ -50,13 +50,11 @@ export { UserProfile } from './types';
50
50
 
51
51
  // Storage helpers
52
52
  export {
53
- StorageHelper,
54
- MemoryStorage,
55
- LocalStorage,
56
53
  CookieStorage,
57
- SessionStorage,
58
- MemoryKeyValueStorage,
59
- } from './StorageHelper';
54
+ defaultStorage,
55
+ sessionStorage,
56
+ sharedInMemoryStorage,
57
+ } from './storage';
60
58
  export { KeyValueStorageInterface } from './types';
61
59
 
62
60
  // Cache exports
@@ -67,5 +65,3 @@ export { BrowserStorageCache as Cache }; // Maintain interoperability with React
67
65
 
68
66
  // Internationalization utilities
69
67
  export { I18n } from './I18n';
70
-
71
- export { parseAWSExports } from './parseAWSExports';
@@ -7,7 +7,7 @@ utils for use throughout the library.
7
7
  */
8
8
  // JS utilities
9
9
  export {
10
- browserOrNode,
10
+ isBrowser,
11
11
  filenameToContentType,
12
12
  generateRandomString,
13
13
  isEmpty,
@@ -20,7 +20,8 @@ export {
20
20
  transferKeyToLowerCase,
21
21
  transferKeyToUpperCase,
22
22
  } from './Util/JS';
23
-
23
+ export { parseAWSExports } from './parseAWSExports';
24
+ export { LegacyConfig } from './singleton/types';
24
25
  export {
25
26
  JWT,
26
27
  StrictUnion,
@@ -96,8 +97,6 @@ export {
96
97
  AmplifyError,
97
98
  AmplifyErrorString,
98
99
  } from './Util/Errors';
99
- export { FacebookOAuth, GoogleOAuth } from './OAuthHelper';
100
- export { AppState, AsyncStorage, Linking } from './RNComponents';
101
100
  export { ErrorParams, AmplifyErrorMap, ServiceError } from './types';
102
101
  export {
103
102
  INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
@@ -3,6 +3,12 @@
3
3
  import { OAuthConfig } from './singleton/Auth/types';
4
4
  import { ResourcesConfig } from './singleton/types';
5
5
 
6
+ const authTypeMapping: Record<any, any> = {
7
+ API_KEY: 'apiKey',
8
+ AWS_IAM: 'iam',
9
+ AMAZON_COGNITO_USER_POOLS: 'jwt',
10
+ };
11
+
6
12
  /**
7
13
  * This utility converts the `aws-exports.js` file generated by the Amplify CLI into a {@link ResourcesConfig} object
8
14
  * consumable by Amplify.
@@ -11,10 +17,15 @@ import { ResourcesConfig } from './singleton/types';
11
17
  *
12
18
  * @returns A {@link ResourcesConfig} object.
13
19
  */
20
+
14
21
  export const parseAWSExports = (
15
22
  config: Record<string, any> = {}
16
23
  ): ResourcesConfig => {
17
24
  const {
25
+ aws_appsync_apiKey,
26
+ aws_appsync_authenticationType,
27
+ aws_appsync_graphqlEndpoint,
28
+ aws_appsync_region,
18
29
  aws_cognito_identity_pool_id,
19
30
  aws_cognito_sign_up_verification_method,
20
31
  aws_mandatory_sign_in,
@@ -40,6 +51,21 @@ export const parseAWSExports = (
40
51
  };
41
52
  }
42
53
 
54
+ // TODO: Need to support all API configurations
55
+ // API
56
+ if (aws_appsync_graphqlEndpoint) {
57
+ amplifyConfig.API = {
58
+ AppSync: {
59
+ defaultAuthMode: {
60
+ type: authTypeMapping[aws_appsync_authenticationType],
61
+ apiKey: aws_appsync_apiKey,
62
+ },
63
+ endpoint: aws_appsync_graphqlEndpoint,
64
+ region: aws_appsync_region,
65
+ },
66
+ };
67
+ }
68
+
43
69
  // Auth
44
70
  if (aws_cognito_identity_pool_id || aws_user_pools_id) {
45
71
  amplifyConfig.Auth = {
@@ -2,9 +2,9 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { v4 as uuid } from 'uuid';
5
- import { PinpointRecordParameters, PinpointSession } from '../types';
5
+ import { PinpointRecordInput, PinpointSession } from '../types';
6
6
  import { getEndpointId } from '../utils';
7
- import {
7
+ import {
8
8
  BUFFER_SIZE,
9
9
  FLUSH_INTERVAL,
10
10
  FLUSH_SIZE,
@@ -28,11 +28,11 @@ export const record = async ({
28
28
  identityId,
29
29
  region,
30
30
  userAgentValue,
31
- }: PinpointRecordParameters): Promise<void> => {
31
+ }: PinpointRecordInput): Promise<void> => {
32
32
  const timestampISOString = new Date().toISOString();
33
33
  const eventId = uuid();
34
34
  let endpointId = await getEndpointId(appId, category);
35
-
35
+
36
36
  // Prepare event buffer if required
37
37
  const buffer = getEventBuffer({
38
38
  appId,
@@ -43,7 +43,7 @@ export const record = async ({
43
43
  identityId,
44
44
  region,
45
45
  resendLimit: RESEND_LIMIT,
46
- userAgentValue
46
+ userAgentValue,
47
47
  });
48
48
 
49
49
  // Prepare a Pinpoint endpoint via updateEndpoint if one does not already exist, which will generate and cache an
@@ -64,7 +64,7 @@ export const record = async ({
64
64
  if (!endpointId) {
65
65
  throw new AmplifyError({
66
66
  name: 'ENDPOINT_NOT_CREATED',
67
- message: 'Endpoint was not created.'
67
+ message: 'Endpoint was not created.',
68
68
  });
69
69
  }
70
70
 
@@ -77,7 +77,7 @@ export const record = async ({
77
77
  StartTimestamp: timestampISOString,
78
78
  };
79
79
  }
80
-
80
+
81
81
  // Push event to buffer
82
82
  buffer.push({
83
83
  eventId,
@@ -85,6 +85,6 @@ export const record = async ({
85
85
  event,
86
86
  session,
87
87
  timestamp: timestampISOString,
88
- resendLimit: RESEND_LIMIT
88
+ resendLimit: RESEND_LIMIT,
89
89
  });
90
90
  };
@@ -7,7 +7,7 @@ import {
7
7
  updateEndpoint as clientUpdateEndpoint,
8
8
  UpdateEndpointInput,
9
9
  } from '../../../AwsClients/Pinpoint';
10
- import { PinpointUpdateEndpointParameters } from '../types';
10
+ import { PinpointUpdateEndpointInput } from '../types';
11
11
  import { cacheEndpointId, getEndpointId } from '../utils';
12
12
 
13
13
  /**
@@ -25,7 +25,7 @@ export const updateEndpoint = async ({
25
25
  userId,
26
26
  userProfile,
27
27
  userAgentValue,
28
- }: PinpointUpdateEndpointParameters): Promise<void> => {
28
+ }: PinpointUpdateEndpointInput): Promise<void> => {
29
29
  const endpointId = await getEndpointId(appId, category);
30
30
  // only generate a new endpoint id if one was not found in cache
31
31
  const createdEndpointId = !endpointId ? uuidv4() : undefined;
@@ -7,7 +7,7 @@ import { PinpointAnalyticsEvent, PinpointSession } from './pinpoint';
7
7
  export type EventBufferConfig = {
8
8
  appId: string;
9
9
  bufferSize: number;
10
- credentials: AuthSession['credentials'];
10
+ credentials: Required<AuthSession>['credentials'];
11
11
  identityId: AuthSession['identityId'];
12
12
  flushInterval: number;
13
13
  flushSize: number;
@@ -38,18 +38,19 @@ export type PinpointAnalyticsEvent = {
38
38
  type PinpointCommonParameters = {
39
39
  appId: string;
40
40
  category: SupportedCategory;
41
- credentials: AuthSession['credentials'];
41
+ credentials: Required<AuthSession>['credentials'];
42
42
  identityId?: AuthSession['identityId'];
43
43
  region: string;
44
44
  userAgentValue?: string;
45
45
  };
46
46
 
47
- export type PinpointUpdateEndpointParameters = PinpointCommonParameters & PinpointServiceOptions & {
48
- channelType?: SupportedChannelType;
49
- userId?: string;
50
- userProfile?: UserProfile;
51
- };
47
+ export type PinpointUpdateEndpointInput = PinpointCommonParameters &
48
+ PinpointServiceOptions & {
49
+ channelType?: SupportedChannelType;
50
+ userId?: string;
51
+ userProfile?: UserProfile;
52
+ };
52
53
 
53
- export type PinpointRecordParameters = PinpointCommonParameters & {
54
+ export type PinpointRecordInput = PinpointCommonParameters & {
54
55
  event: PinpointAnalyticsEvent;
55
56
  };
@@ -8,14 +8,14 @@ import {
8
8
  PutEventsInput,
9
9
  PutEventsOutput,
10
10
  } from '../../../AwsClients/Pinpoint';
11
- import {
11
+ import {
12
12
  EventBufferConfig,
13
13
  BufferedEvent,
14
14
  BufferedEventMap,
15
- EventBuffer
15
+ EventBuffer,
16
16
  } from '../types/buffer';
17
17
  import { AuthSession } from '../../../singleton/Auth/types';
18
- import { isAppInForeground } from '../../../RNComponents/isAppInForeground';
18
+ import { isAppInForeground } from './isAppInForeground';
19
19
 
20
20
  const logger = new Logger('PinpointEventBuffer');
21
21
  const RETRYABLE_CODES = [429, 500];
@@ -39,7 +39,9 @@ export class PinpointEventBuffer {
39
39
 
40
40
  public push(event: BufferedEvent) {
41
41
  if (this._buffer.length >= this._config.bufferSize) {
42
- logger.debug('Exceeded Pinpoint event buffer limits, event dropped.', { eventId: event.eventId });
42
+ logger.debug('Exceeded Pinpoint event buffer limits, event dropped.', {
43
+ eventId: event.eventId,
44
+ });
43
45
 
44
46
  return;
45
47
  }
@@ -112,16 +114,18 @@ export class PinpointEventBuffer {
112
114
  }
113
115
  }
114
116
 
115
- private _generateBatchEventParams(eventMap: BufferedEventMap): PutEventsInput {
117
+ private _generateBatchEventParams(
118
+ eventMap: BufferedEventMap
119
+ ): PutEventsInput {
116
120
  const batchItem: Record<string, EventsBatch> = {};
117
121
 
118
122
  Object.values(eventMap).forEach(item => {
119
123
  const { event, timestamp, endpointId, eventId, session } = item;
120
124
  const { name, attributes, metrics } = event;
121
-
125
+
122
126
  batchItem[endpointId] = {
123
127
  Endpoint: {
124
- ...batchItem[endpointId]?.Endpoint
128
+ ...batchItem[endpointId]?.Endpoint,
125
129
  },
126
130
  Events: {
127
131
  ...batchItem[endpointId]?.Events,
@@ -131,11 +135,11 @@ export class PinpointEventBuffer {
131
135
  Attributes: attributes,
132
136
  Metrics: metrics,
133
137
  Session: session,
134
- }
138
+ },
135
139
  },
136
140
  };
137
141
  });
138
-
142
+
139
143
  return {
140
144
  ApplicationId: this._config.appId,
141
145
  EventsRequest: {
@@ -200,7 +204,7 @@ export class PinpointEventBuffer {
200
204
  logger.warn('Pinpoint event failed to send.', {
201
205
  eventId,
202
206
  name,
203
- message: Message
207
+ message: Message,
204
208
  });
205
209
  });
206
210
  });
@@ -222,7 +226,7 @@ export class PinpointEventBuffer {
222
226
  logger.debug('Resending event.', {
223
227
  eventId,
224
228
  name,
225
- remainingAttempts: bufferedEvent.resendLimit
229
+ remainingAttempts: bufferedEvent.resendLimit,
226
230
  });
227
231
  eligibleEvents.push({ [eventId!]: bufferedEvent });
228
232
  return;
@@ -230,7 +234,7 @@ export class PinpointEventBuffer {
230
234
 
231
235
  logger.debug('No retry attempts remaining for event.', {
232
236
  eventId,
233
- name
237
+ name,
234
238
  });
235
239
  });
236
240
 
@@ -0,0 +1,7 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // @ts-ignore: missing type definition
5
+ import { AppState } from 'react-native';
6
+
7
+ export const isAppInForeground = () => AppState.currentState === 'active';
@@ -0,0 +1,4 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export const isAppInForeground = () => true;
@@ -0,0 +1,31 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export type LibraryAPIOptions = {
4
+ AppSync: {
5
+ query: string;
6
+ variables?: object;
7
+ authMode?: any;
8
+ authToken?: string;
9
+ /**
10
+ * @deprecated This property should not be used
11
+ */
12
+ userAgentSuffix?: string;
13
+ };
14
+ customHeaders: Function;
15
+ };
16
+
17
+ export type APIConfig = {
18
+ AppSync?: {
19
+ defaultAuthMode?: GraphQLAuthMode;
20
+ region?: string;
21
+ endpoint?: string;
22
+ modelIntrospectionSchema?: any;
23
+ };
24
+ };
25
+
26
+ export type GraphQLAuthMode =
27
+ | { type: 'apiKey'; apiKey: string }
28
+ | { type: 'jwt'; token: 'id' | 'access' }
29
+ | { type: 'iam' }
30
+ | { type: 'lambda' }
31
+ | { type: 'custom' };
@@ -2,7 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AuthClass } from './Auth';
4
4
  import { Hub, AMPLIFY_SYMBOL } from '../Hub';
5
- import { LibraryOptions, ResourcesConfig } from './types';
5
+ import { LegacyConfig, LibraryOptions, ResourcesConfig } from './types';
6
+ import { parseAWSExports } from '../parseAWSExports';
6
7
 
7
8
  // TODO(v6): add default AuthTokenStore for each platform
8
9
 
@@ -33,12 +34,20 @@ export class AmplifyClass {
33
34
  * @param libraryOptions - Additional options for customizing the behavior of the library.
34
35
  */
35
36
  configure(
36
- resourcesConfig: ResourcesConfig,
37
+ resourcesConfig: ResourcesConfig | LegacyConfig,
37
38
  libraryOptions: LibraryOptions = {}
38
39
  ): void {
40
+ let resolvedResourceConfig: ResourcesConfig;
41
+
42
+ if (Object.keys(resourcesConfig).some(key => key.startsWith('aws_'))) {
43
+ resolvedResourceConfig = parseAWSExports(resourcesConfig);
44
+ } else {
45
+ resolvedResourceConfig = resourcesConfig as ResourcesConfig;
46
+ }
47
+
39
48
  this.resourcesConfig = mergeResourceConfig(
40
49
  this.resourcesConfig,
41
- resourcesConfig
50
+ resolvedResourceConfig
42
51
  );
43
52
 
44
53
  this.libraryOptions = mergeLibraryOptions(
@@ -52,8 +52,7 @@ export class AuthClass {
52
52
  let userSub: string | undefined;
53
53
 
54
54
  // Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
55
- tokens =
56
- (await this.authOptions?.tokenProvider?.getTokens(options)) ?? undefined;
55
+ tokens = await this.getTokens(options);
57
56
 
58
57
  if (tokens) {
59
58
  userSub = tokens.accessToken?.payload?.sub;
@@ -93,4 +92,12 @@ export class AuthClass {
93
92
  return await this.authOptions.credentialsProvider.clearCredentialsAndIdentityId();
94
93
  }
95
94
  }
95
+
96
+ async getTokens(
97
+ options: FetchAuthSessionOptions
98
+ ): Promise<AuthTokens | undefined> {
99
+ return (
100
+ (await this.authOptions?.tokenProvider?.getTokens(options)) ?? undefined
101
+ );
102
+ }
96
103
  }
@@ -63,10 +63,10 @@ export function assertIdentityPooIdConfig(
63
63
  ): asserts cognitoConfig is CognitoIdentityPoolConfig {
64
64
  const validConfig = !!cognitoConfig?.identityPoolId;
65
65
  return asserts(validConfig, {
66
- name: 'AuthIdentityPoolIdException',
67
- message: 'Auth IdentityPoolId not configured',
66
+ name: 'InvalidIdentityPoolIdException',
67
+ message: 'Invalid identity pool id provided.',
68
68
  recoverySuggestion:
69
- 'Make sure to call Amplify.configure in your app with a valid IdentityPoolId',
69
+ 'Make sure a valid identityPoolId is given in the config.',
70
70
  });
71
71
  }
72
72
 
@@ -7,8 +7,13 @@ export interface StorageConfig {
7
7
  S3: {
8
8
  bucket?: string;
9
9
  region?: string;
10
+ /**
11
+ * Internal-only configuration for testing purpose. You should not use this.
12
+ *
13
+ * @internal
14
+ */
10
15
  dangerouslyConnectToHttpEndpointForTesting?: string;
11
- }
16
+ };
12
17
  }
13
18
 
14
19
  type StoragePrefixResolver = (params: {
@@ -16,7 +21,6 @@ type StoragePrefixResolver = (params: {
16
21
  targetIdentityId?: string;
17
22
  }) => Promise<string>;
18
23
 
19
- // TODO[AllanZhengYP]: need to finalize the decision whether to move defaultAccessLevel to StorageConfig
20
24
  export interface LibraryStorageOptions {
21
25
  S3: {
22
26
  prefixResolver?: StoragePrefixResolver;