@aws-amplify/core 6.0.1-console-preview.4432977.0 → 6.0.1-console-preview.67f944e.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 (133) hide show
  1. package/lib/AwsClients/Pinpoint/errorHelpers.d.ts +5 -0
  2. package/lib/AwsClients/Pinpoint/errorHelpers.js +17 -0
  3. package/lib/AwsClients/Pinpoint/putEvents.js +2 -6
  4. package/lib/Cache/AsyncStorageCache.js +3 -10
  5. package/lib/Cache/BrowserStorageCache.js +5 -18
  6. package/lib/Cache/InMemoryCache.js +3 -10
  7. package/lib/Cache/Utils/CacheList.js +5 -18
  8. package/lib/Cache/Utils/errorHelpers.d.ts +8 -0
  9. package/lib/Cache/Utils/errorHelpers.js +29 -0
  10. package/lib/Hub/index.js +2 -2
  11. package/lib/Hub/types/AuthTypes.d.ts +5 -0
  12. package/lib/I18n/errorHelpers.d.ts +5 -0
  13. package/lib/I18n/errorHelpers.js +17 -0
  14. package/lib/I18n/index.js +5 -18
  15. package/lib/Platform/version.d.ts +1 -1
  16. package/lib/Platform/version.js +1 -1
  17. package/lib/ServiceWorker/ServiceWorker.js +13 -35
  18. package/lib/ServiceWorker/errorHelpers.d.ts +7 -0
  19. package/lib/ServiceWorker/errorHelpers.js +25 -0
  20. package/lib/Util/Constants.d.ts +0 -6
  21. package/lib/Util/Constants.js +1 -7
  22. package/lib/adapterCore/error/AmplifyServerContextError.d.ts +1 -1
  23. package/lib/adapterCore/error/AmplifyServerContextError.js +2 -2
  24. package/lib/{Util/Errors.d.ts → errors/AmplifyError.d.ts} +2 -9
  25. package/lib/{Util/Errors.js → errors/AmplifyError.js} +1 -18
  26. package/lib/errors/PlatformNotSupportedError.d.ts +4 -0
  27. package/lib/errors/PlatformNotSupportedError.js +33 -0
  28. package/lib/errors/createAssertionFunction.d.ts +3 -0
  29. package/lib/errors/createAssertionFunction.js +22 -0
  30. package/lib/errors/index.d.ts +3 -0
  31. package/lib/errors/index.js +11 -0
  32. package/lib/index.d.ts +1 -1
  33. package/lib/libraryUtils.d.ts +3 -4
  34. package/lib/libraryUtils.js +9 -10
  35. package/lib/parseAWSExports.js +3 -1
  36. package/lib/providers/pinpoint/apis/record.js +2 -2
  37. package/lib/singleton/Auth/utils/errorHelpers.d.ts +8 -0
  38. package/lib/singleton/Auth/utils/errorHelpers.js +33 -0
  39. package/lib/singleton/Auth/utils/index.d.ts +1 -1
  40. package/lib/singleton/Auth/utils/index.js +9 -25
  41. package/lib/singleton/Geo/types.d.ts +17 -0
  42. package/lib/singleton/Geo/types.js +4 -0
  43. package/lib/singleton/types.d.ts +3 -1
  44. package/lib/storage/DefaultStorage.native.js +2 -2
  45. package/lib/storage/KeyValueStorage.js +5 -5
  46. package/lib/tsconfig.tsbuildinfo +1 -1
  47. package/lib/types/errors.d.ts +8 -3
  48. package/lib/types/errors.js +6 -0
  49. package/lib-esm/AwsClients/Pinpoint/errorHelpers.d.ts +5 -0
  50. package/lib-esm/AwsClients/Pinpoint/errorHelpers.js +14 -0
  51. package/lib-esm/AwsClients/Pinpoint/putEvents.js +2 -6
  52. package/lib-esm/Cache/AsyncStorageCache.js +3 -10
  53. package/lib-esm/Cache/BrowserStorageCache.js +5 -18
  54. package/lib-esm/Cache/InMemoryCache.js +3 -10
  55. package/lib-esm/Cache/Utils/CacheList.js +5 -18
  56. package/lib-esm/Cache/Utils/errorHelpers.d.ts +8 -0
  57. package/lib-esm/Cache/Utils/errorHelpers.js +26 -0
  58. package/lib-esm/Hub/index.js +1 -1
  59. package/lib-esm/Hub/types/AuthTypes.d.ts +5 -0
  60. package/lib-esm/I18n/errorHelpers.d.ts +5 -0
  61. package/lib-esm/I18n/errorHelpers.js +14 -0
  62. package/lib-esm/I18n/index.js +5 -18
  63. package/lib-esm/Platform/version.d.ts +1 -1
  64. package/lib-esm/Platform/version.js +1 -1
  65. package/lib-esm/ServiceWorker/ServiceWorker.js +8 -30
  66. package/lib-esm/ServiceWorker/errorHelpers.d.ts +7 -0
  67. package/lib-esm/ServiceWorker/errorHelpers.js +22 -0
  68. package/lib-esm/Util/Constants.d.ts +0 -6
  69. package/lib-esm/Util/Constants.js +0 -6
  70. package/lib-esm/adapterCore/error/AmplifyServerContextError.d.ts +1 -1
  71. package/lib-esm/adapterCore/error/AmplifyServerContextError.js +1 -1
  72. package/lib-esm/{Util/Errors.d.ts → errors/AmplifyError.d.ts} +2 -9
  73. package/lib-esm/{Util/Errors.js → errors/AmplifyError.js} +0 -15
  74. package/lib-esm/errors/PlatformNotSupportedError.d.ts +4 -0
  75. package/lib-esm/errors/PlatformNotSupportedError.js +30 -0
  76. package/lib-esm/errors/createAssertionFunction.d.ts +3 -0
  77. package/lib-esm/errors/createAssertionFunction.js +18 -0
  78. package/lib-esm/errors/index.d.ts +3 -0
  79. package/lib-esm/errors/index.js +5 -0
  80. package/lib-esm/index.d.ts +1 -1
  81. package/lib-esm/libraryUtils.d.ts +3 -4
  82. package/lib-esm/libraryUtils.js +3 -3
  83. package/lib-esm/parseAWSExports.js +3 -1
  84. package/lib-esm/providers/pinpoint/apis/record.js +1 -1
  85. package/lib-esm/singleton/Auth/utils/errorHelpers.d.ts +8 -0
  86. package/lib-esm/singleton/Auth/utils/errorHelpers.js +30 -0
  87. package/lib-esm/singleton/Auth/utils/index.d.ts +1 -1
  88. package/lib-esm/singleton/Auth/utils/index.js +7 -23
  89. package/lib-esm/singleton/Geo/types.d.ts +17 -0
  90. package/lib-esm/singleton/Geo/types.js +3 -0
  91. package/lib-esm/singleton/types.d.ts +3 -1
  92. package/lib-esm/storage/DefaultStorage.native.js +1 -1
  93. package/lib-esm/storage/KeyValueStorage.js +5 -5
  94. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  95. package/lib-esm/types/errors.d.ts +8 -3
  96. package/lib-esm/types/errors.js +5 -1
  97. package/package.json +2 -2
  98. package/src/AwsClients/Pinpoint/errorHelpers.ts +19 -0
  99. package/src/AwsClients/Pinpoint/putEvents.ts +2 -6
  100. package/src/Cache/AsyncStorageCache.ts +4 -10
  101. package/src/Cache/BrowserStorageCache.ts +5 -18
  102. package/src/Cache/InMemoryCache.ts +4 -11
  103. package/src/Cache/Utils/CacheList.ts +5 -18
  104. package/src/Cache/Utils/errorHelpers.ts +30 -0
  105. package/src/Hub/index.ts +1 -1
  106. package/src/Hub/types/AuthTypes.ts +3 -1
  107. package/src/I18n/errorHelpers.ts +18 -0
  108. package/src/I18n/index.ts +12 -24
  109. package/src/Platform/version.ts +1 -1
  110. package/src/ServiceWorker/ServiceWorker.ts +18 -30
  111. package/src/ServiceWorker/errorHelpers.ts +26 -0
  112. package/src/Util/Constants.ts +0 -6
  113. package/src/adapterCore/error/AmplifyServerContextError.ts +1 -1
  114. package/src/{Util/Errors.ts → errors/AmplifyError.ts} +2 -18
  115. package/src/errors/PlatformNotSupportedError.ts +14 -0
  116. package/src/errors/createAssertionFunction.ts +23 -0
  117. package/src/errors/index.ts +6 -0
  118. package/src/index.ts +1 -0
  119. package/src/libraryUtils.ts +11 -7
  120. package/src/parseAWSExports.ts +7 -1
  121. package/src/providers/pinpoint/apis/record.ts +1 -1
  122. package/src/singleton/Auth/utils/errorHelpers.ts +37 -0
  123. package/src/singleton/Auth/utils/index.ts +19 -26
  124. package/src/singleton/Geo/types.ts +20 -0
  125. package/src/singleton/types.ts +3 -0
  126. package/src/storage/DefaultStorage.native.ts +1 -1
  127. package/src/storage/KeyValueStorage.ts +5 -5
  128. package/src/types/errors.ts +14 -3
  129. package/lib/Util/errors/AssertError.d.ts +0 -2
  130. package/lib/Util/errors/AssertError.js +0 -11
  131. package/lib-esm/Util/errors/AssertError.d.ts +0 -2
  132. package/lib-esm/Util/errors/AssertError.js +0 -7
  133. package/src/Util/errors/AssertError.ts +0 -11
@@ -1,6 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { asserts } from '../../../Util/errors/AssertError';
3
+ import { AuthConfigurationErrorCode, assert } from './errorHelpers';
4
4
 
5
5
  import {
6
6
  AuthConfig,
@@ -30,11 +30,10 @@ export function assertTokenProviderConfig(
30
30
  !!cognitoConfig.userPoolClientId && !!cognitoConfig.userPoolClientId;
31
31
  }
32
32
 
33
- return asserts(assertionValid, {
34
- name: 'AuthTokenConfigException',
35
- message: 'Auth Token Provider not configured',
36
- recoverySuggestion: 'Make sure to call Amplify.configure in your app',
37
- });
33
+ return assert(
34
+ assertionValid,
35
+ AuthConfigurationErrorCode.AuthTokenConfigException
36
+ );
38
37
  }
39
38
 
40
39
  export function assertOAuthConfig(
@@ -46,15 +45,13 @@ export function assertOAuthConfig(
46
45
  !!cognitoConfig?.loginWith?.oauth?.redirectSignIn &&
47
46
  !!cognitoConfig?.loginWith?.oauth?.responseType;
48
47
 
49
- return asserts(validOAuthConfig, {
50
- name: 'OAuthNotConfigureException',
51
- message: 'oauth param not configured',
52
- recoverySuggestion:
53
- 'Make sure to call Amplify.configure with oauth parameter in your app',
54
- });
48
+ return assert(
49
+ validOAuthConfig,
50
+ AuthConfigurationErrorCode.OAuthNotConfigureException
51
+ );
55
52
  }
56
53
 
57
- export function assertIdentityPooIdConfig(
54
+ export function assertIdentityPoolIdConfig(
58
55
  cognitoConfig?: StrictUnion<
59
56
  | CognitoUserPoolConfig
60
57
  | CognitoUserPoolAndIdentityPoolConfig
@@ -62,25 +59,21 @@ export function assertIdentityPooIdConfig(
62
59
  >
63
60
  ): asserts cognitoConfig is CognitoIdentityPoolConfig {
64
61
  const validConfig = !!cognitoConfig?.identityPoolId;
65
- return asserts(validConfig, {
66
- name: 'InvalidIdentityPoolIdException',
67
- message: 'Invalid identity pool id provided.',
68
- recoverySuggestion:
69
- 'Make sure a valid identityPoolId is given in the config.',
70
- });
62
+ return assert(
63
+ validConfig,
64
+ AuthConfigurationErrorCode.InvalidIdentityPoolIdException
65
+ );
71
66
  }
72
67
 
73
- function assertUserPoolAndIdentityPooConfig(
68
+ function assertUserPoolAndIdentityPoolConfig(
74
69
  authConfig: AuthConfig
75
70
  ): asserts authConfig is AuthUserPoolAndIdentityPoolConfig {
76
71
  const validConfig =
77
72
  !!authConfig?.Cognito.identityPoolId && !!authConfig?.Cognito.userPoolId;
78
- return asserts(validConfig, {
79
- name: 'AuthUserPoolAndIdentityPoolException',
80
- message: 'Auth UserPool and IdentityPool not configured',
81
- recoverySuggestion:
82
- 'Make sure to call Amplify.configure in your app with UserPoolId and IdentityPoolId',
83
- });
73
+ return assert(
74
+ validConfig,
75
+ AuthConfigurationErrorCode.AuthUserPoolAndIdentityPoolException
76
+ );
84
77
  }
85
78
 
86
79
  export function decodeJWT(token: string): JWT {
@@ -0,0 +1,20 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export interface GeoConfig {
5
+ LocationService?: {
6
+ region: string;
7
+ maps?: {
8
+ items: {};
9
+ default: string;
10
+ };
11
+ searchIndices?: {
12
+ items: string[];
13
+ default: string;
14
+ };
15
+ geofenceCollections?: {
16
+ items: string[];
17
+ default: string;
18
+ };
19
+ };
20
+ }
@@ -12,6 +12,7 @@ import {
12
12
  GetCredentialsOptions,
13
13
  CognitoIdentityPoolConfig,
14
14
  } from './Auth/types';
15
+ import { GeoConfig } from './Geo/types';
15
16
  import {
16
17
  LibraryStorageOptions,
17
18
  StorageAccessLevel,
@@ -36,6 +37,7 @@ export type ResourcesConfig = {
36
37
  // Notifications?: {};
37
38
  // Predictions?: {};
38
39
  Storage?: StorageConfig;
40
+ Geo?: GeoConfig;
39
41
  };
40
42
 
41
43
  export type LibraryOptions = {
@@ -56,4 +58,5 @@ export {
56
58
  StorageConfig,
57
59
  AnalyticsConfig,
58
60
  CognitoIdentityPoolConfig,
61
+ GeoConfig,
59
62
  };
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { AsyncStorageStatic } from '@react-native-async-storage/async-storage';
5
- import { AmplifyError } from '../libraryUtils';
5
+ import { AmplifyError } from '../errors';
6
6
  import { KeyValueStorageInterface } from '../types';
7
7
 
8
8
  const ASYNC_STORAGE_MODULE = '@react-native-async-storage/async-storage';
@@ -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 { PlatformNotSupportedError } from '../Util/Errors';
4
+ import { PlatformNotSupportedError } from '../errors';
5
5
  import { KeyValueStorageInterface } from '../types';
6
6
 
7
7
  /**
@@ -21,7 +21,7 @@ export class KeyValueStorage implements KeyValueStorageInterface {
21
21
  * @returns {string} value that was set
22
22
  */
23
23
  async setItem(key: string, value: string) {
24
- if (!this.storage) throw PlatformNotSupportedError;
24
+ if (!this.storage) throw new PlatformNotSupportedError();
25
25
  this.storage.setItem(key, value);
26
26
  }
27
27
 
@@ -32,7 +32,7 @@ export class KeyValueStorage implements KeyValueStorageInterface {
32
32
  * @returns {string} the data item
33
33
  */
34
34
  async getItem(key: string) {
35
- if (!this.storage) throw PlatformNotSupportedError;
35
+ if (!this.storage) throw new PlatformNotSupportedError();
36
36
  return this.storage.getItem(key);
37
37
  }
38
38
 
@@ -42,7 +42,7 @@ export class KeyValueStorage implements KeyValueStorageInterface {
42
42
  * @returns {string} value - value that was deleted
43
43
  */
44
44
  async removeItem(key: string) {
45
- if (!this.storage) throw PlatformNotSupportedError;
45
+ if (!this.storage) throw new PlatformNotSupportedError();
46
46
  this.storage.removeItem(key);
47
47
  }
48
48
 
@@ -51,7 +51,7 @@ export class KeyValueStorage implements KeyValueStorageInterface {
51
51
  * @returns {string} nothing
52
52
  */
53
53
  async clear() {
54
- if (!this.storage) throw PlatformNotSupportedError;
54
+ if (!this.storage) throw new PlatformNotSupportedError();
55
55
  this.storage.clear();
56
56
  }
57
57
  }
@@ -1,14 +1,19 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- export type ErrorParams = {
4
+ export enum AmplifyErrorCode {
5
+ PlatformNotSupported = 'PlatformNotSupported',
6
+ Unknown = 'Unknown',
7
+ }
8
+
9
+ export type AmplifyErrorParams<ErrorCode extends string = string> = {
5
10
  message: string;
6
- name: string;
11
+ name: ErrorCode;
7
12
  recoverySuggestion?: string;
8
13
  underlyingError?: Error | unknown;
9
14
  };
10
15
 
11
- export type AmplifyErrorMap<ErrorCode extends string> = {
16
+ export type AmplifyErrorMap<ErrorCode extends string = string> = {
12
17
  [name in ErrorCode]: {
13
18
  message: string;
14
19
  recoverySuggestion?: string;
@@ -19,3 +24,9 @@ export type ServiceError = {
19
24
  name: string;
20
25
  message: string;
21
26
  };
27
+
28
+ export type AssertionFunction<ErrorCode extends string = string> = (
29
+ assertion: boolean,
30
+ name: ErrorCode,
31
+ additionalContext?: string
32
+ ) => asserts assertion;
@@ -1,2 +0,0 @@
1
- import { ErrorParams } from '../../types';
2
- export declare function asserts(assertion: boolean, errorParams: ErrorParams): asserts assertion;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asserts = void 0;
4
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
- // SPDX-License-Identifier: Apache-2.0
6
- var Errors_1 = require("../Errors");
7
- function asserts(assertion, errorParams) {
8
- if (!assertion)
9
- throw new Errors_1.AmplifyError(errorParams);
10
- }
11
- exports.asserts = asserts;
@@ -1,2 +0,0 @@
1
- import { ErrorParams } from '../../types';
2
- export declare function asserts(assertion: boolean, errorParams: ErrorParams): asserts assertion;
@@ -1,7 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { AmplifyError } from '../Errors';
4
- export function asserts(assertion, errorParams) {
5
- if (!assertion)
6
- throw new AmplifyError(errorParams);
7
- }
@@ -1,11 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { AmplifyError } from '../Errors';
4
- import { ErrorParams } from '../../types';
5
-
6
- export function asserts(
7
- assertion: boolean,
8
- errorParams: ErrorParams
9
- ): asserts assertion {
10
- if (!assertion) throw new AmplifyError(errorParams);
11
- }