@aws-amplify/core 6.0.1-console-preview.deaebd5.0 → 6.0.1-console-preview.b5a42af.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 (80) hide show
  1. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +2 -1
  2. package/lib/AwsClients/CognitoIdentity/getId.d.ts +2 -1
  3. package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +3 -2
  4. package/lib/AwsClients/Pinpoint/putEvents.d.ts +3 -2
  5. package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +3 -2
  6. package/lib/Cache/AsyncStorageCache.d.ts +1 -1
  7. package/lib/Cache/AsyncStorageCache.js +20 -22
  8. package/lib/Platform/version.d.ts +1 -1
  9. package/lib/Platform/version.js +1 -1
  10. package/lib/Reachability/Reachability.native.d.ts +2 -2
  11. package/lib/clients/handlers/fetch.js +2 -1
  12. package/lib/clients/middleware/signing/signer/signatureV4/index.native.d.ts +0 -1
  13. package/lib/clients/middleware/signing/signer/signatureV4/index.native.js +2 -1
  14. package/lib/clients/types/http.d.ts +16 -0
  15. package/lib/libraryUtils.d.ts +1 -1
  16. package/lib/parseAWSExports.js +24 -8
  17. package/lib/providers/pinpoint/index.d.ts +1 -0
  18. package/lib/providers/pinpoint/index.js +3 -0
  19. package/lib/singleton/API/types.d.ts +66 -29
  20. package/lib/singleton/Auth/utils/index.js +1 -1
  21. package/lib/singleton/Notifications/InAppMessaging/types.d.ts +2 -0
  22. package/lib/singleton/Notifications/InAppMessaging/types.js +4 -0
  23. package/lib/singleton/Notifications/types.d.ts +4 -0
  24. package/lib/singleton/Notifications/types.js +4 -0
  25. package/lib/singleton/types.d.ts +2 -0
  26. package/lib/storage/DefaultStorage.native.d.ts +2 -2
  27. package/lib/storage/DefaultStorage.native.js +3 -24
  28. package/lib/tsconfig.tsbuildinfo +1 -1
  29. package/lib/utils/globalHelpers/index.native.d.ts +0 -1
  30. package/lib/utils/globalHelpers/index.native.js +2 -1
  31. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +2 -1
  32. package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +2 -1
  33. package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +3 -2
  34. package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +3 -2
  35. package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +3 -2
  36. package/lib-esm/Cache/AsyncStorageCache.d.ts +1 -1
  37. package/lib-esm/Cache/AsyncStorageCache.js +2 -1
  38. package/lib-esm/Platform/version.d.ts +1 -1
  39. package/lib-esm/Platform/version.js +1 -1
  40. package/lib-esm/Reachability/Reachability.native.d.ts +2 -2
  41. package/lib-esm/clients/handlers/fetch.js +2 -1
  42. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.native.d.ts +0 -1
  43. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.native.js +2 -1
  44. package/lib-esm/clients/types/http.d.ts +16 -0
  45. package/lib-esm/libraryUtils.d.ts +1 -1
  46. package/lib-esm/parseAWSExports.js +24 -8
  47. package/lib-esm/providers/pinpoint/index.d.ts +1 -0
  48. package/lib-esm/providers/pinpoint/index.js +1 -0
  49. package/lib-esm/singleton/API/types.d.ts +66 -29
  50. package/lib-esm/singleton/Auth/utils/index.js +1 -1
  51. package/lib-esm/singleton/Notifications/InAppMessaging/types.d.ts +2 -0
  52. package/lib-esm/singleton/Notifications/InAppMessaging/types.js +3 -0
  53. package/lib-esm/singleton/Notifications/types.d.ts +4 -0
  54. package/lib-esm/singleton/Notifications/types.js +3 -0
  55. package/lib-esm/singleton/types.d.ts +2 -0
  56. package/lib-esm/storage/DefaultStorage.native.d.ts +2 -2
  57. package/lib-esm/storage/DefaultStorage.native.js +3 -24
  58. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  59. package/lib-esm/utils/globalHelpers/index.native.d.ts +0 -1
  60. package/lib-esm/utils/globalHelpers/index.native.js +2 -1
  61. package/package.json +3 -9
  62. package/src/Cache/AsyncStorageCache.ts +2 -1
  63. package/src/Platform/version.ts +1 -1
  64. package/src/Reachability/Reachability.native.ts +4 -2
  65. package/src/clients/handlers/fetch.ts +5 -1
  66. package/src/clients/middleware/signing/signer/signatureV4/index.native.ts +3 -1
  67. package/src/clients/types/http.ts +18 -0
  68. package/src/libraryUtils.ts +1 -1
  69. package/src/parseAWSExports.ts +38 -7
  70. package/src/providers/pinpoint/index.ts +1 -0
  71. package/src/singleton/API/types.ts +77 -26
  72. package/src/singleton/Auth/utils/index.ts +1 -1
  73. package/src/singleton/Notifications/InAppMessaging/types.ts +6 -0
  74. package/src/singleton/Notifications/types.ts +8 -0
  75. package/src/singleton/types.ts +2 -1
  76. package/src/storage/DefaultStorage.native.ts +6 -26
  77. package/src/utils/globalHelpers/index.native.ts +3 -1
  78. package/polyfills/URL/index.ts +0 -14
  79. package/polyfills/URL/tsconfig.json +0 -10
  80. package/polyfills/URL/webpack.config.js +0 -43
@@ -1,4 +1,3 @@
1
- import 'react-native-get-random-values';
2
1
  import { encode, decode } from 'base-64';
3
2
  export declare const getCrypto: () => Crypto;
4
3
  export declare const getBtoa: () => typeof encode;
@@ -1,8 +1,9 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import 'react-native-get-random-values';
3
+ import { loadGetRandomValues } from '@aws-amplify/react-native';
4
4
  import { encode, decode } from 'base-64';
5
5
  import { AmplifyError } from '../../errors';
6
+ loadGetRandomValues();
6
7
  export var getCrypto = function () {
7
8
  if (typeof crypto !== 'undefined' &&
8
9
  typeof crypto.getRandomValues === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/core",
3
- "version": "6.0.1-console-preview.deaebd5.0+deaebd5",
3
+ "version": "6.0.1-console-preview.b5a42af.0+b5a42af",
4
4
  "description": "Core category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -56,7 +56,6 @@
56
56
  "src",
57
57
  "typings.d.ts",
58
58
  "internals",
59
- "polyfills",
60
59
  "server"
61
60
  ],
62
61
  "dependencies": {
@@ -69,16 +68,11 @@
69
68
  "uuid": "^9.0.0"
70
69
  },
71
70
  "devDependencies": {
72
- "@react-native-async-storage/async-storage": "^1.17.12",
73
- "@react-native-community/netinfo": "4.7.0",
74
- "@types/base-64": "1.0.0",
71
+ "@aws-amplify/react-native": "1.0.1-console-preview.b5a42af.0+b5a42af",
75
72
  "@types/js-cookie": "^2.2.7",
76
73
  "@types/uuid": "^9.0.0",
77
- "base-64": "1.0.0",
78
74
  "find": "^0.2.7",
79
75
  "genversion": "^2.2.0",
80
- "react-native": "^0.68.7",
81
- "react-native-get-random-values": "1.9.0",
82
76
  "typescript": "5.0.2"
83
77
  },
84
78
  "size-limit": [
@@ -185,5 +179,5 @@
185
179
  "lib-esm"
186
180
  ]
187
181
  },
188
- "gitHead": "deaebd5a938733ff2b25aaec39c042843ef2289c"
182
+ "gitHead": "b5a42af519fb741bb8056a814addd8804c8f60ec"
189
183
  }
@@ -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
 
4
- import AsyncStorage from '@react-native-async-storage/async-storage';
4
+ import { loadAsyncStorage } from '@aws-amplify/react-native';
5
5
  import { ConsoleLogger as Logger } from '../Logger';
6
6
  import { StorageCache } from './StorageCache';
7
7
  import { defaultConfig, getCurrTime } from './Utils';
@@ -10,6 +10,7 @@ import { getCurrSizeKey } from './Utils/CacheUtils';
10
10
  import { assert, CacheErrorCode } from './Utils/errorHelpers';
11
11
 
12
12
  const logger = new Logger('AsyncStorageCache');
13
+ const AsyncStorage = loadAsyncStorage();
13
14
 
14
15
  /*
15
16
  * Customized cache which based on the AsyncStorage with LRU implemented
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '6.0.1-console-preview.deaebd5.0+deaebd5';
2
+ export const version = '6.0.1-console-preview.b5a42af.0+b5a42af';
@@ -1,14 +1,16 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Observable } from 'rxjs';
4
- import type NetInfo from '@react-native-community/netinfo';
4
+ import { loadNetInfo } from '@aws-amplify/react-native';
5
5
  import { ConsoleLogger as Logger } from '../Logger';
6
6
  import { NetworkStatus } from './types';
7
7
 
8
8
  const logger = new Logger('Reachability', 'DEBUG');
9
9
 
10
10
  export class Reachability {
11
- networkMonitor(netInfo?: typeof NetInfo): Observable<NetworkStatus> {
11
+ networkMonitor(
12
+ netInfo?: ReturnType<typeof loadNetInfo>
13
+ ): Observable<NetworkStatus> {
12
14
  /**
13
15
  * Here netinfo refers to @react-native-community/netinfo
14
16
  * This is needed in React Native to enable network detection
@@ -13,7 +13,10 @@ export const fetchTransferHandler: TransferHandler<
13
13
  HttpRequest,
14
14
  HttpResponse,
15
15
  HttpTransferOptions
16
- > = async ({ url, method, headers, body }, { abortSignal, cache }) => {
16
+ > = async (
17
+ { url, method, headers, body },
18
+ { abortSignal, cache, withCrossDomainCredentials }
19
+ ) => {
17
20
  let resp: Response;
18
21
  try {
19
22
  resp = await fetch(url, {
@@ -22,6 +25,7 @@ export const fetchTransferHandler: TransferHandler<
22
25
  body: shouldSendBody(method) ? body : undefined,
23
26
  signal: abortSignal,
24
27
  cache,
28
+ credentials: withCrossDomainCredentials ? 'include' : 'same-origin',
25
29
  });
26
30
  } catch (e) {
27
31
  // TODO: needs to revise error handling in v6
@@ -1,7 +1,9 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import '@aws-amplify/core/polyfills/URL';
4
+ import { loadUrlPolyfill } from '@aws-amplify/react-native';
5
+
6
+ loadUrlPolyfill();
5
7
 
6
8
  // TODO: V6 replace Signer
7
9
  export { signRequest } from './signRequest';
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { Request, Response, TransferHandler } from './core';
5
+ import type { fetchTransferHandler } from '../handlers/fetch';
5
6
 
6
7
  /**
7
8
  * Use basic Record interface to workaround fetch Header class not available in Node.js
@@ -42,6 +43,23 @@ export interface HttpTransferOptions {
42
43
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/cache}
43
44
  */
44
45
  cache?: RequestCache;
46
+
47
+ /**
48
+ * Internal-only option controls whether or not cross-site Access-Control requests should be made using credentials
49
+ * such as cookies, authorization headers or TLS client certificates. It has no effect on same-origin requests.
50
+ * If set to `true`, the request will include credentials such as cookies, authorization headers, TLS
51
+ * client certificates, and so on. Moreover the response cookies will also be set.
52
+ * If set to `false`, the cross-site request will not include credentials, and the response cookies from a different
53
+ * domain will be ignored.
54
+ *
55
+ * This option is only conformed by {@link fetchTransferHandler | fetchTransferHandler }
56
+ *
57
+ * @default 'same-origin'
58
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials}
59
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials}
60
+ * @internal
61
+ */
62
+ withCrossDomainCredentials?: boolean;
45
63
  }
46
64
 
47
65
  export type HttpTransferHandler = TransferHandler<
@@ -34,7 +34,7 @@ export {
34
34
  assertOAuthConfig,
35
35
  } from './singleton/Auth/utils';
36
36
  export { isTokenExpired } from './singleton/Auth';
37
- export { GraphQLAuthMode, GraphQLAuthModeKeys } from './singleton/API/types';
37
+ export { APIAuthMode, DocumentType } from './singleton/API/types';
38
38
  export { Signer } from './Signer';
39
39
 
40
40
  // Logging utilities
@@ -1,12 +1,18 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ import { ConsoleLogger as Logger } from './Logger';
3
4
  import { OAuthConfig } from './singleton/Auth/types';
4
5
  import { ResourcesConfig } from './singleton/types';
5
6
 
7
+ const logger = new Logger('parseAWSExports');
8
+
6
9
  const authTypeMapping: Record<any, any> = {
7
10
  API_KEY: 'apiKey',
8
11
  AWS_IAM: 'iam',
9
- AMAZON_COGNITO_USER_POOLS: 'jwt',
12
+ AMAZON_COGNITO_USER_POOLS: 'userPool',
13
+ OPENID_CONNECT: 'oidc',
14
+ NONE: 'none',
15
+ LAMBDA: 'lambda',
10
16
  };
11
17
 
12
18
  /**
@@ -38,6 +44,7 @@ export const parseAWSExports = (
38
44
  aws_user_pools_web_client_id,
39
45
  geo,
40
46
  oauth,
47
+ aws_cloud_logic_custom,
41
48
  } = config;
42
49
  const amplifyConfig: ResourcesConfig = {};
43
50
 
@@ -51,17 +58,20 @@ export const parseAWSExports = (
51
58
  };
52
59
  }
53
60
 
54
- // TODO: Need to support all API configurations
55
61
  // API
56
62
  if (aws_appsync_graphqlEndpoint) {
63
+ const defaultAuthMode = authTypeMapping[aws_appsync_authenticationType];
64
+ if (!defaultAuthMode) {
65
+ logger.debug(
66
+ `Invalid authentication type ${aws_appsync_authenticationType}. Falling back to IAM.`
67
+ );
68
+ }
57
69
  amplifyConfig.API = {
58
- AppSync: {
59
- defaultAuthMode: {
60
- type: authTypeMapping[aws_appsync_authenticationType],
61
- apiKey: aws_appsync_apiKey,
62
- },
70
+ GraphQL: {
63
71
  endpoint: aws_appsync_graphqlEndpoint,
72
+ apiKey: aws_appsync_apiKey,
64
73
  region: aws_appsync_region,
74
+ defaultAuthMode: defaultAuthMode ?? 'iam',
65
75
  },
66
76
  };
67
77
  }
@@ -109,6 +119,27 @@ export const parseAWSExports = (
109
119
  : { ...geo };
110
120
  }
111
121
 
122
+ // REST API
123
+ if (aws_cloud_logic_custom) {
124
+ amplifyConfig.API = {
125
+ ...amplifyConfig.API,
126
+ REST: (aws_cloud_logic_custom as any[]).reduce(
127
+ (acc, api: Record<string, any>) => {
128
+ const { name, endpoint, region, service } = api;
129
+ return {
130
+ ...acc,
131
+ [name]: {
132
+ endpoint,
133
+ ...(service ? { service } : undefined),
134
+ ...(region ? { region } : undefined),
135
+ },
136
+ };
137
+ },
138
+ {}
139
+ ),
140
+ };
141
+ }
142
+
112
143
  return amplifyConfig;
113
144
  };
114
145
 
@@ -3,3 +3,4 @@
3
3
 
4
4
  export * from './apis';
5
5
  export { PinpointAnalyticsEvent, PinpointServiceOptions } from './types';
6
+ export { getEndpointId } from './utils';
@@ -1,38 +1,89 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ import { Headers } from '../../clients';
4
+
3
5
  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;
6
+ GraphQL?: {
7
+ // custom headers for given GraphQL service. Will be applied to all operations.
8
+ headers?: (options: {
9
+ query: string;
10
+ variables: Record<string, DocumentType>;
11
+ }) => Promise<Headers>;
12
+ };
13
+ REST?: {
14
+ // custom headers for given REST service. Will be applied to all operations.
15
+ headers?: (options: { apiName: string }) => Promise<Headers>;
13
16
  };
14
- customHeaders: Function;
15
17
  };
16
18
 
17
- export type APIConfig = {
18
- AppSync?: {
19
- defaultAuthMode: GraphQLAuthMode;
20
- region: string;
21
- endpoint: string;
22
- modelIntrospectionSchema?: any;
23
- };
19
+ type APIGraphQLConfig = {
20
+ /**
21
+ * Required GraphQL endpoint, must be a valid URL string.
22
+ */
23
+ endpoint: string;
24
+ /**
25
+ * Optional region string used to sign the request. Required only if the auth mode is 'iam'.
26
+ */
27
+ region?: string;
28
+ /**
29
+ * Optional API key string. Required only if the auth mode is 'apiKey'.
30
+ */
31
+ apiKey?: string;
32
+ /**
33
+ * Custom domain endpoint for GraphQL API.
34
+ */
35
+ customEndpoint?: string;
36
+ /**
37
+ * Optional region string used to sign the request to `customEndpoint`. Effective only if `customEndpoint` is
38
+ * specified, and the auth mode is 'iam'.
39
+ */
40
+ customEndpointRegion?: string;
41
+ /**
42
+ * Default auth mode for all the API calls to given service.
43
+ */
44
+ defaultAuthMode: APIAuthMode;
24
45
  };
25
46
 
26
- export type GraphQLAuthMode =
27
- | { type: 'apiKey'; apiKey: string }
28
- | { type: 'jwt'; token?: 'id' | 'access' }
29
- | { type: 'iam' }
30
- | { type: 'lambda' }
31
- | { type: 'custom' };
47
+ type APIRestConfig = {
48
+ /**
49
+ * Required REST endpoint, must be a valid URL string.
50
+ */
51
+ endpoint: string;
52
+ /**
53
+ * Optional region string used to sign the request with IAM credentials. If Omitted, region will be extracted from
54
+ * the endpoint.
55
+ *
56
+ * @default 'us-east-1'
57
+ */
58
+ region?: string;
59
+ /**
60
+ * Optional service name string to sign the request with IAM credentials.
61
+ *
62
+ * @default 'execute-api'
63
+ */
64
+ service?: string;
65
+ };
32
66
 
33
- export type GraphQLAuthModeKeys =
67
+ export type APIConfig = {
68
+ REST?: Record<string, APIRestConfig>;
69
+ GraphQL?: APIGraphQLConfig;
70
+ };
71
+
72
+ export type APIAuthMode =
34
73
  | 'apiKey'
35
- | 'jwt'
74
+ | 'oidc'
75
+ | 'userPool'
36
76
  | 'iam'
37
77
  | 'lambda'
38
- | 'custom';
78
+ | 'none';
79
+
80
+ /**
81
+ * Type representing a plain JavaScript object that can be serialized to JSON.
82
+ */
83
+ export type DocumentType =
84
+ | null
85
+ | boolean
86
+ | number
87
+ | string
88
+ | DocumentType[]
89
+ | { [prop: string]: DocumentType };
@@ -28,7 +28,7 @@ export function assertTokenProviderConfig(
28
28
  assertionValid = false;
29
29
  } else {
30
30
  assertionValid =
31
- !!cognitoConfig.userPoolClientId && !!cognitoConfig.userPoolClientId;
31
+ !!cognitoConfig.userPoolId && !!cognitoConfig.userPoolClientId;
32
32
  }
33
33
 
34
34
  return assert(
@@ -0,0 +1,6 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { PinpointProviderConfig } from '../../../providers/pinpoint/types';
5
+
6
+ export type InAppMessagingConfig = PinpointProviderConfig;
@@ -0,0 +1,8 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { InAppMessagingConfig } from './InAppMessaging/types';
5
+
6
+ export type NotificationsConfig = {
7
+ InAppMessaging: InAppMessagingConfig;
8
+ };
@@ -19,6 +19,7 @@ import {
19
19
  StorageConfig,
20
20
  } from './Storage/types';
21
21
  import { I18nConfig } from '../I18n/types';
22
+ import { NotificationsConfig } from './Notifications/types';
22
23
 
23
24
  export type LegacyConfig = {
24
25
  /**
@@ -35,7 +36,7 @@ export type ResourcesConfig = {
35
36
  // DataStore?: {};
36
37
  I18n?: I18nConfig;
37
38
  // Interactions?: {};
38
- // Notifications?: {};
39
+ Notifications?: NotificationsConfig;
39
40
  // Predictions?: {};
40
41
  Storage?: StorageConfig;
41
42
  Geo?: GeoConfig;
@@ -1,18 +1,20 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { AsyncStorageStatic } from '@react-native-async-storage/async-storage';
5
- import { AmplifyError } from '../errors';
4
+ import { loadAsyncStorage } from '@aws-amplify/react-native';
6
5
  import { KeyValueStorageInterface } from '../types';
7
6
 
8
- const ASYNC_STORAGE_MODULE = '@react-native-async-storage/async-storage';
9
7
  const MEMORY_KEY_PREFIX = '@MemoryStorage:';
10
8
 
11
9
  /**
12
10
  * @internal
13
11
  */
14
12
  export class DefaultStorage implements KeyValueStorageInterface {
15
- private asyncStorage?: AsyncStorageStatic;
13
+ private asyncStorage: ReturnType<typeof loadAsyncStorage>;
14
+
15
+ constructor() {
16
+ this.asyncStorage = loadAsyncStorage();
17
+ }
16
18
 
17
19
  /**
18
20
  * This is used to set a specific item in storage
@@ -21,7 +23,6 @@ export class DefaultStorage implements KeyValueStorageInterface {
21
23
  * @returns {string} value that was set
22
24
  */
23
25
  setItem(key: string, value: string) {
24
- this.assertModule(this.asyncStorage);
25
26
  return this.asyncStorage.setItem(`${MEMORY_KEY_PREFIX}${key}`, value);
26
27
  }
27
28
 
@@ -32,7 +33,6 @@ export class DefaultStorage implements KeyValueStorageInterface {
32
33
  * @returns {string} the data item
33
34
  */
34
35
  getItem(key: string) {
35
- this.assertModule(this.asyncStorage);
36
36
  return this.asyncStorage.getItem(`${MEMORY_KEY_PREFIX}${key}`);
37
37
  }
38
38
 
@@ -42,7 +42,6 @@ export class DefaultStorage implements KeyValueStorageInterface {
42
42
  * @returns {string} value - value that was deleted
43
43
  */
44
44
  removeItem(key: string): Promise<void> {
45
- this.assertModule(this.asyncStorage);
46
45
  return this.asyncStorage.removeItem(`${MEMORY_KEY_PREFIX}${key}`);
47
46
  }
48
47
 
@@ -51,28 +50,9 @@ export class DefaultStorage implements KeyValueStorageInterface {
51
50
  * @returns {string} nothing
52
51
  */
53
52
  async clear(): Promise<void> {
54
- this.assertModule(this.asyncStorage);
55
53
  const allKeys = await this.asyncStorage.getAllKeys();
56
54
  return this.asyncStorage.multiRemove(
57
55
  allKeys.filter(key => key.startsWith(MEMORY_KEY_PREFIX))
58
56
  );
59
57
  }
60
-
61
- private assertModule(
62
- asyncStorage?: AsyncStorageStatic
63
- ): asserts asyncStorage {
64
- if (!!asyncStorage) {
65
- return;
66
- }
67
- try {
68
- this.asyncStorage = require(ASYNC_STORAGE_MODULE)
69
- .default as AsyncStorageStatic;
70
- } catch (err) {
71
- throw new AmplifyError({
72
- name: 'NativeModuleException',
73
- message: `Unable to find ${ASYNC_STORAGE_MODULE}`,
74
- recoverySuggestion: `Make sure to install ${ASYNC_STORAGE_MODULE}`,
75
- });
76
- }
77
- }
78
58
  }
@@ -1,10 +1,12 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import 'react-native-get-random-values';
4
+ import { loadGetRandomValues } from '@aws-amplify/react-native';
5
5
  import { encode, decode } from 'base-64';
6
6
  import { AmplifyError } from '../../errors';
7
7
 
8
+ loadGetRandomValues();
9
+
8
10
  export const getCrypto = () => {
9
11
  if (
10
12
  typeof crypto !== 'undefined' &&
@@ -1,14 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- /**
4
- * TODO: [v6] remove this polyfill.
5
- *
6
- * The `react-native-url-polyfill` package needs to be bundled because it's
7
- * a commonjs package that would break the users' Jest unit tests, where MJS
8
- * is not supported by default.
9
- */
10
- /*if (process?.env?.NODE_ENV !== 'test') {
11
- // Loading this polyfill in customers' unit tests will cause undefined
12
- // variable error in un-mocked react-native package.
13
- require('react-native-url-polyfill/auto');
14
- }*/
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowSyntheticDefaultImports": true,
4
- "noImplicitAny": true,
5
- "module": "es6",
6
- "target": "es5",
7
- "allowJs": true
8
- },
9
- "files": ["index.ts"]
10
- }
@@ -1,43 +0,0 @@
1
- const path = require('path');
2
-
3
- const rnUrlPolyfillPath = require.resolve('react-native-url-polyfill');
4
- const rnUrlPolyfillMeta = require(path.join(
5
- path.dirname(rnUrlPolyfillPath),
6
- 'package.json'
7
- ));
8
- const rnUrlPolyfillDeps = Object.keys({
9
- ...rnUrlPolyfillMeta.dependencies,
10
- ...rnUrlPolyfillMeta.peerDependencies,
11
- });
12
- const rnUrlPolyfillDepsRegex = rnUrlPolyfillDeps.map(
13
- name => new RegExp(`^${name}\/?`) // match name with optional trailing slash
14
- );
15
-
16
- module.exports = {
17
- name: 'index',
18
- context: path.resolve(__dirname),
19
- entry: {
20
- index: path.join(__dirname, 'index.ts'),
21
- },
22
- output: {
23
- path: path.resolve(__dirname),
24
- filename: '[name].js',
25
- library: {
26
- type: 'commonjs',
27
- },
28
- },
29
- module: {
30
- rules: [
31
- {
32
- test: /\.(ts|tsx)$/i,
33
- loader: 'ts-loader',
34
- exclude: ['/node_modules/'],
35
- },
36
- ],
37
- },
38
- resolve: {
39
- extensions: ['.tsx', '.ts', '.jsx', '.js'],
40
- },
41
- externals: rnUrlPolyfillDepsRegex,
42
- mode: 'production',
43
- };