@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
@@ -5,9 +5,8 @@ import { ConsoleLogger as Logger } from '../Logger';
5
5
  import { defaultConfig, getCurrTime } from './Utils';
6
6
  import { StorageCache } from './StorageCache';
7
7
  import { ICache, CacheConfig, CacheItem, CacheItemOptions } from './types';
8
- import { asserts } from '../Util/errors/AssertError';
9
- import { STORAGE_CACHE_EXCEPTION } from '../Util/Constants';
10
8
  import { getCurrSizeKey } from './Utils/CacheUtils';
9
+ import { assert, CacheErrorCode } from './Utils/errorHelpers';
11
10
 
12
11
  const logger = new Logger('Cache');
13
12
 
@@ -22,20 +21,14 @@ export class BrowserStorageCacheClass extends StorageCache implements ICache {
22
21
  constructor(config?: CacheConfig) {
23
22
  super(config);
24
23
 
25
- asserts(!!this.cacheConfig.storage, {
26
- name: STORAGE_CACHE_EXCEPTION,
27
- message: 'Storage is not defined in the cache config',
28
- });
24
+ assert(!!this.cacheConfig.storage, CacheErrorCode.NoCacheStorage);
29
25
  this.cacheConfig.storage = this.cacheConfig.storage;
30
26
  this.getItem = this.getItem.bind(this);
31
27
  this.setItem = this.setItem.bind(this);
32
28
  this.removeItem = this.removeItem.bind(this);
33
29
  }
34
30
  private getStorage(): Storage {
35
- asserts(!!this.cacheConfig.storage, {
36
- name: STORAGE_CACHE_EXCEPTION,
37
- message: 'Storage is not defined in the cache config',
38
- });
31
+ assert(!!this.cacheConfig.storage, CacheErrorCode.NoCacheStorage);
39
32
  return this.cacheConfig.storage;
40
33
  }
41
34
  /**
@@ -91,10 +84,7 @@ export class BrowserStorageCacheClass extends StorageCache implements ICache {
91
84
  */
92
85
  private _isExpired(key: string): boolean {
93
86
  const text: string | null = this.getStorage().getItem(key);
94
- asserts(text !== null, {
95
- name: STORAGE_CACHE_EXCEPTION,
96
- message: `Item not found in the storage by the key: ${key}.`,
97
- });
87
+ assert(text !== null, CacheErrorCode.NoCacheItem, `Key: ${key}`);
98
88
  const item: CacheItem = JSON.parse(text);
99
89
  if (getCurrTime() >= item.expires) {
100
90
  return true;
@@ -111,10 +101,7 @@ export class BrowserStorageCacheClass extends StorageCache implements ICache {
111
101
  */
112
102
  private _removeItem(prefixedKey: string, size?: number): void {
113
103
  const item = this.getStorage().getItem(prefixedKey);
114
- asserts(item !== null, {
115
- name: STORAGE_CACHE_EXCEPTION,
116
- message: `Item not found in the storage by the key: ${prefixedKey}.`,
117
- });
104
+ assert(item !== null, CacheErrorCode.NoCacheItem, `Key: ${prefixedKey}`);
118
105
  const itemSize: number = size ?? JSON.parse(item).byteSize;
119
106
  this._decreaseCurSizeInBytes(itemSize);
120
107
  // remove the cache item
@@ -1,14 +1,13 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { CacheList, defaultConfig, getCurrTime, CacheObject } from './Utils';
4
+ import { CacheList, getCurrTime, CacheObject } from './Utils';
5
5
 
6
6
  import { StorageCache } from './StorageCache';
7
7
  import { ICache, CacheConfig, CacheItem, CacheItemOptions } from './types';
8
8
  import { ConsoleLogger as Logger } from '../Logger';
9
- import { asserts } from '../Util/errors/AssertError';
10
- import { STORAGE_CACHE_EXCEPTION } from '../Util/Constants';
11
9
  import { getCurrSizeKey } from './Utils/CacheUtils';
10
+ import { assert, CacheErrorCode } from './Utils/errorHelpers';
12
11
 
13
12
  const logger = new Logger('InMemoryCache');
14
13
 
@@ -74,10 +73,7 @@ export class InMemoryCacheClass extends StorageCache implements ICache {
74
73
  private _isExpired(key: string): boolean {
75
74
  const text: string | null = CacheObject.getItem(key);
76
75
 
77
- asserts(text !== null, {
78
- name: STORAGE_CACHE_EXCEPTION,
79
- message: 'item from storage is null',
80
- });
76
+ assert(text !== null, CacheErrorCode.NoCacheItem, `Key: ${key}`);
81
77
  const item: CacheItem = JSON.parse(text);
82
78
  if (getCurrTime() >= item.expires) {
83
79
  return true;
@@ -96,10 +92,7 @@ export class InMemoryCacheClass extends StorageCache implements ICache {
96
92
  this.cacheList[listIdx].removeItem(prefixedKey);
97
93
  // decrease the current size of the cache
98
94
  const item = CacheObject.getItem(prefixedKey);
99
- asserts(item !== null, {
100
- name: STORAGE_CACHE_EXCEPTION,
101
- message: 'item from storage is null',
102
- });
95
+ assert(item !== null, CacheErrorCode.NoCacheItem, `Key: ${prefixedKey}`);
103
96
  this._decreaseCurSizeInBytes(JSON.parse(item).byteSize);
104
97
  // finally remove the item from memory
105
98
  CacheObject.removeItem(prefixedKey);
@@ -1,8 +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 { asserts } from '../../Util/errors/AssertError';
5
- import { CACHE_LIST_EXCEPTION } from '../../Util/Constants';
4
+ import { assert, CacheErrorCode } from './errorHelpers';
6
5
 
7
6
  class DoubleLinkedNode {
8
7
  key: string;
@@ -56,10 +55,7 @@ export default class CacheList {
56
55
  this.head.nextNode = node;
57
56
  node.nextNode = tmp;
58
57
  node.prevNode = this.head;
59
- asserts(tmp !== null, {
60
- name: CACHE_LIST_EXCEPTION,
61
- message: 'previous node is null',
62
- });
58
+ assert(tmp !== null, CacheErrorCode.NullPreviousNode);
63
59
  tmp.prevNode = node;
64
60
 
65
61
  this.length = this.length + 1;
@@ -71,14 +67,8 @@ export default class CacheList {
71
67
  * @param node
72
68
  */
73
69
  private removeNode(node: DoubleLinkedNode): void {
74
- asserts(node.prevNode !== null, {
75
- name: CACHE_LIST_EXCEPTION,
76
- message: 'previous node is null',
77
- });
78
- asserts(node.nextNode !== null, {
79
- name: CACHE_LIST_EXCEPTION,
80
- message: 'nextNode node is null',
81
- });
70
+ assert(node.prevNode !== null, CacheErrorCode.NullPreviousNode);
71
+ assert(node.nextNode !== null, CacheErrorCode.NullNextNode);
82
72
  node.prevNode.nextNode = node.nextNode;
83
73
  node.nextNode.prevNode = node.prevNode;
84
74
 
@@ -121,10 +111,7 @@ export default class CacheList {
121
111
  * @return the LAST Recently Visited key
122
112
  */
123
113
  public getLastItem(): string {
124
- asserts(this.tail.prevNode !== null, {
125
- name: CACHE_LIST_EXCEPTION,
126
- message: 'previous node is null',
127
- });
114
+ assert(this.tail.prevNode !== null, CacheErrorCode.NullPreviousNode);
128
115
  return this.tail.prevNode.key;
129
116
  }
130
117
 
@@ -0,0 +1,30 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { createAssertionFunction } from '../../errors';
5
+ import { AmplifyErrorMap, AssertionFunction } from '../../types';
6
+
7
+ export enum CacheErrorCode {
8
+ NoCacheItem = 'NoCacheItem',
9
+ NoCacheStorage = 'NoCacheStorage',
10
+ NullNextNode = 'NullNextNode',
11
+ NullPreviousNode = 'NullPreviousNode',
12
+ }
13
+
14
+ const cacheErrorMap: AmplifyErrorMap<CacheErrorCode> = {
15
+ [CacheErrorCode.NoCacheItem]: {
16
+ message: 'Item not found in the cache storage.',
17
+ },
18
+ [CacheErrorCode.NoCacheStorage]: {
19
+ message: 'Storage is not defined in the cache config.',
20
+ },
21
+ [CacheErrorCode.NullNextNode]: {
22
+ message: 'Next node is null.',
23
+ },
24
+ [CacheErrorCode.NullPreviousNode]: {
25
+ message: 'Previous node is null.',
26
+ },
27
+ };
28
+
29
+ export const assert: AssertionFunction<CacheErrorCode> =
30
+ createAssertionFunction(cacheErrorMap);
package/src/Hub/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { ConsoleLogger as Logger } from '../Logger';
5
5
  import { NO_HUBCALLBACK_PROVIDED_EXCEPTION } from '../Util/Constants';
6
- import { AmplifyError } from '../Util/Errors';
6
+ import { AmplifyError } from '../errors';
7
7
  import {
8
8
  AmplifyChannel,
9
9
  AmplifyEventData,
@@ -9,4 +9,6 @@ export type AuthHubEventData =
9
9
  /** Dispatched when auth tokens are successfully refreshed.*/
10
10
  | { event: 'tokenRefresh' }
11
11
  /** Dispatched when there is an error in the refresh of tokens.*/
12
- | { event: 'tokenRefresh_failure' };
12
+ | { event: 'tokenRefresh_failure' }
13
+ /** Dispatched when there is a customState passed in the options of the `signInWithRedirect` API.*/
14
+ | { event: 'customOAuthState'; data: string };
@@ -0,0 +1,18 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { createAssertionFunction } from '../errors';
5
+ import { AmplifyErrorMap, AssertionFunction } from '../types';
6
+
7
+ export enum I18nErrorCode {
8
+ NotConfigured = 'NotConfigured',
9
+ }
10
+
11
+ const i18nErrorMap: AmplifyErrorMap<I18nErrorCode> = {
12
+ [I18nErrorCode.NotConfigured]: {
13
+ message: 'i18n is not configured.',
14
+ },
15
+ };
16
+
17
+ export const assert: AssertionFunction<I18nErrorCode> =
18
+ createAssertionFunction(i18nErrorMap);
package/src/I18n/index.ts CHANGED
@@ -5,8 +5,7 @@ import { I18n as I18nClass } from './I18n';
5
5
 
6
6
  import { ConsoleLogger as Logger } from '../Logger';
7
7
  import { I18nOptions } from './types';
8
- import { asserts } from '../Util/errors/AssertError';
9
- import { I18N_EXCEPTION } from '../Util/Constants';
8
+ import { assert, I18nErrorCode } from './errorHelpers';
10
9
 
11
10
  const logger = new Logger('I18n');
12
11
 
@@ -15,7 +14,7 @@ let _i18n: I18nClass | null = null;
15
14
 
16
15
  /**
17
16
  * Export I18n APIs
18
- *
17
+ *
19
18
  * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
20
19
  */
21
20
  export class I18n {
@@ -46,7 +45,7 @@ export class I18n {
46
45
  * @static
47
46
  * @method
48
47
  * Create an instance of I18n for the library
49
- *
48
+ *
50
49
  * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
51
50
  */
52
51
  static createInstance() {
@@ -61,15 +60,13 @@ export class I18n {
61
60
  * @static @method
62
61
  * Explicitly setting language
63
62
  * @param {String} lang
64
- *
63
+ *
65
64
  * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
66
65
  */
67
66
  static setLanguage(lang: string) {
68
67
  I18n.checkConfig();
69
- asserts(!!_i18n, {
70
- name: I18N_EXCEPTION,
71
- message: 'I18N is not configured',
72
- });
68
+ assert(!!_i18n, I18nErrorCode.NotConfigured);
69
+
73
70
  return _i18n.setLanguage(lang);
74
71
  }
75
72
 
@@ -78,17 +75,14 @@ export class I18n {
78
75
  * Get value
79
76
  * @param {String} key
80
77
  * @param {String} defVal - Default value
81
- *
78
+ *
82
79
  * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
83
80
  */
84
81
  static get(key: string, defVal?: string) {
85
82
  if (!I18n.checkConfig()) {
86
83
  return typeof defVal === 'undefined' ? key : defVal;
87
84
  }
88
- asserts(!!_i18n, {
89
- name: I18N_EXCEPTION,
90
- message: 'I18N is not configured',
91
- });
85
+ assert(!!_i18n, I18nErrorCode.NotConfigured);
92
86
 
93
87
  return _i18n.get(key, defVal);
94
88
  }
@@ -99,7 +93,7 @@ export class I18n {
99
93
  * Add vocabularies for one language
100
94
  * @param {String} langurage - Language of the dictionary
101
95
  * @param {Object} vocabularies - Object that has key-value as dictionary entry
102
- *
96
+ *
103
97
  * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
104
98
  */
105
99
  static putVocabulariesForLanguage(
@@ -107,10 +101,7 @@ export class I18n {
107
101
  vocabularies: Record<string, string>
108
102
  ) {
109
103
  I18n.checkConfig();
110
- asserts(!!_i18n, {
111
- name: I18N_EXCEPTION,
112
- message: 'I18N is not configured',
113
- });
104
+ assert(!!_i18n, I18nErrorCode.NotConfigured);
114
105
 
115
106
  return _i18n.putVocabulariesForLanguage(language, vocabularies);
116
107
  }
@@ -121,15 +112,12 @@ export class I18n {
121
112
  * Add vocabularies for one language
122
113
  * @param {Object} vocabularies - Object that has language as key,
123
114
  * vocabularies of each language as value
124
- *
115
+ *
125
116
  * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
126
117
  */
127
118
  static putVocabularies(vocabularies: Record<string, string>) {
128
119
  I18n.checkConfig();
129
- asserts(!!_i18n, {
130
- name: I18N_EXCEPTION,
131
- message: 'I18N is not configured',
132
- });
120
+ assert(!!_i18n, I18nErrorCode.NotConfigured);
133
121
 
134
122
  return _i18n.putVocabularies(vocabularies);
135
123
  }
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '6.0.1-console-preview.4432977.0+4432977';
2
+ export const version = '6.0.1-console-preview.67f944e.0+67f944e';
@@ -1,23 +1,11 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- /**
4
- * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
7
- * the License. A copy of the License is located at
8
- *
9
- * http://aws.amazon.com/apache2.0/
10
- *
11
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
13
- * and limitations under the License.
14
- */
3
+
15
4
  import { ConsoleLogger as Logger } from '../Logger';
16
5
  import { isBrowser } from '../Util/JS';
17
6
  import { Amplify } from '../Amplify';
18
- import { asserts } from '../Util/errors/AssertError';
19
- import { AmplifyError } from '../Util/Errors';
20
- import { SERVICE_WORKER_EXCEPTION } from '../Util/Constants';
7
+ import { AmplifyError } from '../errors';
8
+ import { assert, ServiceWorkerErrorCode } from './errorHelpers';
21
9
  /**
22
10
  * Provides a means to registering a service worker in the browser
23
11
  * and communicating with it via postMessage events.
@@ -53,10 +41,10 @@ export class ServiceWorkerClass {
53
41
  * Get the currently active service worker
54
42
  */
55
43
  get serviceWorker(): ServiceWorker {
56
- asserts(this._serviceWorker !== undefined, {
57
- name: SERVICE_WORKER_EXCEPTION,
58
- message: 'Service Worker instance is undefined',
59
- });
44
+ assert(
45
+ this._serviceWorker !== undefined,
46
+ ServiceWorkerErrorCode.UndefinedInstance
47
+ );
60
48
 
61
49
  return this._serviceWorker;
62
50
  }
@@ -101,7 +89,7 @@ export class ServiceWorkerClass {
101
89
  this._logger.debug(`Service Worker Registration Failed ${error}`);
102
90
  return reject(
103
91
  new AmplifyError({
104
- name: SERVICE_WORKER_EXCEPTION,
92
+ name: ServiceWorkerErrorCode.Unavailable,
105
93
  message: 'Service Worker not available',
106
94
  underlyingError: error,
107
95
  })
@@ -110,7 +98,7 @@ export class ServiceWorkerClass {
110
98
  } else {
111
99
  return reject(
112
100
  new AmplifyError({
113
- name: SERVICE_WORKER_EXCEPTION,
101
+ name: ServiceWorkerErrorCode.Unavailable,
114
102
  message: 'Service Worker not available',
115
103
  })
116
104
  );
@@ -130,17 +118,17 @@ export class ServiceWorkerClass {
130
118
  * - reject(Error)
131
119
  */
132
120
  enablePush(publicKey: string) {
133
- asserts(this._registration !== undefined, {
134
- name: SERVICE_WORKER_EXCEPTION,
135
- message: 'Service Worker registration is undefined',
136
- });
121
+ assert(
122
+ this._registration !== undefined,
123
+ ServiceWorkerErrorCode.UndefinedRegistration
124
+ );
137
125
  this._publicKey = publicKey;
138
126
  return new Promise((resolve, reject) => {
139
127
  if (isBrowser()) {
140
- asserts(this._registration !== undefined, {
141
- name: SERVICE_WORKER_EXCEPTION,
142
- message: 'Service Worker registration is undefined',
143
- });
128
+ assert(
129
+ this._registration !== undefined,
130
+ ServiceWorkerErrorCode.UndefinedRegistration
131
+ );
144
132
  this._registration.pushManager.getSubscription().then(subscription => {
145
133
  if (subscription) {
146
134
  this._subscription = subscription;
@@ -169,7 +157,7 @@ export class ServiceWorkerClass {
169
157
  } else {
170
158
  return reject(
171
159
  new AmplifyError({
172
- name: SERVICE_WORKER_EXCEPTION,
160
+ name: ServiceWorkerErrorCode.Unavailable,
173
161
  message: 'Service Worker not available',
174
162
  })
175
163
  );
@@ -0,0 +1,26 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { createAssertionFunction } from '../errors';
5
+ import { AmplifyErrorMap, AssertionFunction } from '../types';
6
+
7
+ export enum ServiceWorkerErrorCode {
8
+ UndefinedInstance = 'UndefinedInstance',
9
+ UndefinedRegistration = 'UndefinedRegistration',
10
+ Unavailable = 'Unavailable',
11
+ }
12
+
13
+ const serviceWorkerErrorMap: AmplifyErrorMap<ServiceWorkerErrorCode> = {
14
+ [ServiceWorkerErrorCode.UndefinedInstance]: {
15
+ message: 'Service Worker instance is undefined.',
16
+ },
17
+ [ServiceWorkerErrorCode.UndefinedRegistration]: {
18
+ message: 'Service Worker registration is undefined.',
19
+ },
20
+ [ServiceWorkerErrorCode.Unavailable]: {
21
+ message: 'Service Worker not available.',
22
+ },
23
+ };
24
+
25
+ export const assert: AssertionFunction<ServiceWorkerErrorCode> =
26
+ createAssertionFunction(serviceWorkerErrorMap);
@@ -23,11 +23,5 @@ export const INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER = hasSymbol
23
23
  export const USER_AGENT_HEADER = 'x-amz-user-agent';
24
24
 
25
25
  // Error exception code constants
26
- export const AUTH_CONFING_EXCEPTION = 'AuthConfigException';
27
- export const CACHE_LIST_EXCEPTION = 'CacheListException';
28
- export const I18N_EXCEPTION = 'I18NException';
29
- export const SERVICE_WORKER_EXCEPTION = 'ServiceWorkerException';
30
- export const STORAGE_CACHE_EXCEPTION = 'StorageCacheException';
31
- export const APPLICATION_ID_EXCEPTION = 'ApplicationIdException';
32
26
  export const NO_HUBCALLBACK_PROVIDED_EXCEPTION =
33
27
  'NoHubcallbackProvidedException';
@@ -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 { AmplifyError } from '../../libraryUtils';
4
+ import { AmplifyError } from '../../errors';
5
5
 
6
6
  export class AmplifyServerContextError extends AmplifyError {
7
7
  constructor({
@@ -1,19 +1,8 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { ErrorParams } from '../types/errors';
4
+ import { AmplifyErrorParams } from '../types/errors';
5
5
 
6
- export function missingConfig(name: string) {
7
- return new Error('Missing config value of ' + name);
8
- }
9
- export function invalidParameter(name: string) {
10
- return new Error('Invalid parameter value of ' + name);
11
- }
12
-
13
- export enum AmplifyErrorString {
14
- UNKNOWN = 'UnknownError',
15
- PLATFORM_NOT_SUPPORTED_ERROR = 'PlatformNotSupportedError',
16
- }
17
6
  export class AmplifyError extends Error {
18
7
  underlyingError?: Error | unknown;
19
8
  recoverySuggestion?: string;
@@ -30,7 +19,7 @@ export class AmplifyError extends Error {
30
19
  name,
31
20
  recoverySuggestion,
32
21
  underlyingError,
33
- }: ErrorParams) {
22
+ }: AmplifyErrorParams) {
34
23
  super(message);
35
24
 
36
25
  this.name = name;
@@ -43,8 +32,3 @@ export class AmplifyError extends Error {
43
32
  Object.setPrototypeOf(this, AmplifyError.prototype);
44
33
  }
45
34
  }
46
-
47
- export const PlatformNotSupportedError = new AmplifyError({
48
- name: AmplifyErrorString.PLATFORM_NOT_SUPPORTED_ERROR,
49
- message: 'Function not supported on current platform',
50
- });
@@ -0,0 +1,14 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AmplifyErrorCode } from '../types';
5
+ import { AmplifyError } from './AmplifyError';
6
+
7
+ export class PlatformNotSupportedError extends AmplifyError {
8
+ constructor() {
9
+ super({
10
+ name: AmplifyErrorCode.PlatformNotSupported,
11
+ message: 'Function not supported on current platform',
12
+ });
13
+ }
14
+ }
@@ -0,0 +1,23 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AmplifyErrorMap, AssertionFunction } from '../types';
5
+ import { AmplifyError } from './AmplifyError';
6
+
7
+ export const createAssertionFunction =
8
+ (
9
+ errorMap: AmplifyErrorMap,
10
+ AssertionError = AmplifyError
11
+ ): AssertionFunction =>
12
+ (assertion, name, additionalContext) => {
13
+ const { message, recoverySuggestion } = errorMap[name];
14
+ if (!assertion) {
15
+ throw new AssertionError({
16
+ name,
17
+ message: additionalContext
18
+ ? `${message} ${additionalContext}`
19
+ : message,
20
+ recoverySuggestion,
21
+ });
22
+ }
23
+ };
@@ -0,0 +1,6 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { AmplifyError } from './AmplifyError';
5
+ export { createAssertionFunction } from './createAssertionFunction';
6
+ export { PlatformNotSupportedError } from './PlatformNotSupportedError';
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ export {
29
29
  ResourcesConfig,
30
30
  LibraryOptions,
31
31
  AnalyticsConfig,
32
+ GeoConfig,
32
33
  } from './singleton/types';
33
34
  export {
34
35
  Amplify,
@@ -32,7 +32,7 @@ export {
32
32
  export {
33
33
  decodeJWT,
34
34
  assertTokenProviderConfig,
35
- assertIdentityPooIdConfig,
35
+ assertIdentityPoolIdConfig,
36
36
  assertOAuthConfig,
37
37
  } from './singleton/Auth/utils';
38
38
  export { isTokenExpired } from './singleton/Auth';
@@ -92,14 +92,18 @@ export {
92
92
  urlSafeDecode,
93
93
  urlSafeEncode,
94
94
  } from './Util';
95
- export { asserts } from './Util/errors/AssertError';
96
95
  export {
97
- invalidParameter,
98
- missingConfig,
99
96
  AmplifyError,
100
- AmplifyErrorString,
101
- } from './Util/Errors';
102
- export { ErrorParams, AmplifyErrorMap, ServiceError } from './types';
97
+ PlatformNotSupportedError,
98
+ createAssertionFunction,
99
+ } from './errors';
100
+ export {
101
+ AmplifyErrorCode,
102
+ AmplifyErrorMap,
103
+ AmplifyErrorParams,
104
+ AssertionFunction,
105
+ ServiceError,
106
+ } from './types';
103
107
  export {
104
108
  INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
105
109
  USER_AGENT_HEADER,
@@ -99,7 +99,13 @@ export const parseAWSExports = (
99
99
  if (geo) {
100
100
  const { amazon_location_service } = geo;
101
101
  (amplifyConfig as any).Geo = amazon_location_service
102
- ? { AmazonLocationService: amazon_location_service }
102
+ ? {
103
+ LocationService: {
104
+ ...amazon_location_service,
105
+ searchIndices: amazon_location_service.search_indices,
106
+ region: amazon_location_service.region,
107
+ },
108
+ }
103
109
  : { ...geo };
104
110
  }
105
111
 
@@ -12,7 +12,7 @@ import {
12
12
  } from '../utils/constants';
13
13
  import { updateEndpoint } from './updateEndpoint';
14
14
  import { getEventBuffer } from '../utils/getEventBuffer';
15
- import { AmplifyError } from '../../../libraryUtils';
15
+ import { AmplifyError } from '../../../errors';
16
16
 
17
17
  // TODO(v6) Refactor when we add support for session tracking & `autoTrack`
18
18
  let session: PinpointSession;
@@ -0,0 +1,37 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { createAssertionFunction } from '../../../errors';
5
+ import { AmplifyErrorMap, AssertionFunction } from '../../../types';
6
+
7
+ export enum AuthConfigurationErrorCode {
8
+ AuthTokenConfigException = 'AuthTokenConfigException',
9
+ AuthUserPoolAndIdentityPoolException = 'AuthUserPoolAndIdentityPoolException',
10
+ InvalidIdentityPoolIdException = 'InvalidIdentityPoolIdException',
11
+ OAuthNotConfigureException = 'OAuthNotConfigureException',
12
+ }
13
+
14
+ const authConfigurationErrorMap: AmplifyErrorMap<AuthConfigurationErrorCode> = {
15
+ [AuthConfigurationErrorCode.AuthTokenConfigException]: {
16
+ message: 'Auth Token Provider not configured.',
17
+ recoverySuggestion: 'Make sure to call Amplify.configure in your app.',
18
+ },
19
+ [AuthConfigurationErrorCode.AuthUserPoolAndIdentityPoolException]: {
20
+ message: 'Auth UserPool or IdentityPool not configured.',
21
+ recoverySuggestion:
22
+ 'Make sure to call Amplify.configure in your app with UserPoolId and IdentityPoolId.',
23
+ },
24
+ [AuthConfigurationErrorCode.InvalidIdentityPoolIdException]: {
25
+ message: 'Invalid identity pool id provided.',
26
+ recoverySuggestion:
27
+ 'Make sure a valid identityPoolId is given in the config.',
28
+ },
29
+ [AuthConfigurationErrorCode.OAuthNotConfigureException]: {
30
+ message: 'oauth param not configured.',
31
+ recoverySuggestion:
32
+ 'Make sure to call Amplify.configure with oauth parameter in your app.',
33
+ },
34
+ };
35
+
36
+ export const assert: AssertionFunction<AuthConfigurationErrorCode> =
37
+ createAssertionFunction(authConfigurationErrorMap);