@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
@@ -18,9 +18,8 @@ var __extends = (this && this.__extends) || (function () {
18
18
  import { ConsoleLogger as Logger } from '../Logger';
19
19
  import { defaultConfig, getCurrTime } from './Utils';
20
20
  import { StorageCache } from './StorageCache';
21
- import { asserts } from '../Util/errors/AssertError';
22
- import { STORAGE_CACHE_EXCEPTION } from '../Util/Constants';
23
21
  import { getCurrSizeKey } from './Utils/CacheUtils';
22
+ import { assert, CacheErrorCode } from './Utils/errorHelpers';
24
23
  var logger = new Logger('Cache');
25
24
  /**
26
25
  * Customized storage based on the SessionStorage or LocalStorage with LRU implemented
@@ -33,10 +32,7 @@ var BrowserStorageCacheClass = /** @class */ (function (_super) {
33
32
  */
34
33
  function BrowserStorageCacheClass(config) {
35
34
  var _this = _super.call(this, config) || this;
36
- asserts(!!_this.cacheConfig.storage, {
37
- name: STORAGE_CACHE_EXCEPTION,
38
- message: 'Storage is not defined in the cache config',
39
- });
35
+ assert(!!_this.cacheConfig.storage, CacheErrorCode.NoCacheStorage);
40
36
  _this.cacheConfig.storage = _this.cacheConfig.storage;
41
37
  _this.getItem = _this.getItem.bind(_this);
42
38
  _this.setItem = _this.setItem.bind(_this);
@@ -44,10 +40,7 @@ var BrowserStorageCacheClass = /** @class */ (function (_super) {
44
40
  return _this;
45
41
  }
46
42
  BrowserStorageCacheClass.prototype.getStorage = function () {
47
- asserts(!!this.cacheConfig.storage, {
48
- name: STORAGE_CACHE_EXCEPTION,
49
- message: 'Storage is not defined in the cache config',
50
- });
43
+ assert(!!this.cacheConfig.storage, CacheErrorCode.NoCacheStorage);
51
44
  return this.cacheConfig.storage;
52
45
  };
53
46
  /**
@@ -94,10 +87,7 @@ var BrowserStorageCacheClass = /** @class */ (function (_super) {
94
87
  */
95
88
  BrowserStorageCacheClass.prototype._isExpired = function (key) {
96
89
  var text = this.getStorage().getItem(key);
97
- asserts(text !== null, {
98
- name: STORAGE_CACHE_EXCEPTION,
99
- message: "Item not found in the storage by the key: ".concat(key, "."),
100
- });
90
+ assert(text !== null, CacheErrorCode.NoCacheItem, "Key: ".concat(key));
101
91
  var item = JSON.parse(text);
102
92
  if (getCurrTime() >= item.expires) {
103
93
  return true;
@@ -113,10 +103,7 @@ var BrowserStorageCacheClass = /** @class */ (function (_super) {
113
103
  */
114
104
  BrowserStorageCacheClass.prototype._removeItem = function (prefixedKey, size) {
115
105
  var item = this.getStorage().getItem(prefixedKey);
116
- asserts(item !== null, {
117
- name: STORAGE_CACHE_EXCEPTION,
118
- message: "Item not found in the storage by the key: ".concat(prefixedKey, "."),
119
- });
106
+ assert(item !== null, CacheErrorCode.NoCacheItem, "Key: ".concat(prefixedKey));
120
107
  var itemSize = size !== null && size !== void 0 ? size : JSON.parse(item).byteSize;
121
108
  this._decreaseCurSizeInBytes(itemSize);
122
109
  // remove the cache item
@@ -29,9 +29,8 @@ var __values = (this && this.__values) || function(o) {
29
29
  import { CacheList, getCurrTime, CacheObject } from './Utils';
30
30
  import { StorageCache } from './StorageCache';
31
31
  import { ConsoleLogger as Logger } from '../Logger';
32
- import { asserts } from '../Util/errors/AssertError';
33
- import { STORAGE_CACHE_EXCEPTION } from '../Util/Constants';
34
32
  import { getCurrSizeKey } from './Utils/CacheUtils';
33
+ import { assert, CacheErrorCode } from './Utils/errorHelpers';
35
34
  var logger = new Logger('InMemoryCache');
36
35
  /**
37
36
  * Customized in-memory cache with LRU implemented
@@ -86,10 +85,7 @@ var InMemoryCacheClass = /** @class */ (function (_super) {
86
85
  */
87
86
  InMemoryCacheClass.prototype._isExpired = function (key) {
88
87
  var text = CacheObject.getItem(key);
89
- asserts(text !== null, {
90
- name: STORAGE_CACHE_EXCEPTION,
91
- message: 'item from storage is null',
92
- });
88
+ assert(text !== null, CacheErrorCode.NoCacheItem, "Key: ".concat(key));
93
89
  var item = JSON.parse(text);
94
90
  if (getCurrTime() >= item.expires) {
95
91
  return true;
@@ -107,10 +103,7 @@ var InMemoryCacheClass = /** @class */ (function (_super) {
107
103
  this.cacheList[listIdx].removeItem(prefixedKey);
108
104
  // decrease the current size of the cache
109
105
  var item = CacheObject.getItem(prefixedKey);
110
- asserts(item !== null, {
111
- name: STORAGE_CACHE_EXCEPTION,
112
- message: 'item from storage is null',
113
- });
106
+ assert(item !== null, CacheErrorCode.NoCacheItem, "Key: ".concat(prefixedKey));
114
107
  this._decreaseCurSizeInBytes(JSON.parse(item).byteSize);
115
108
  // finally remove the item from memory
116
109
  CacheObject.removeItem(prefixedKey);
@@ -11,8 +11,7 @@ var __values = (this && this.__values) || function(o) {
11
11
  };
12
12
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
13
13
  };
14
- import { asserts } from '../../Util/errors/AssertError';
15
- import { CACHE_LIST_EXCEPTION } from '../../Util/Constants';
14
+ import { assert, CacheErrorCode } from './errorHelpers';
16
15
  var DoubleLinkedNode = /** @class */ (function () {
17
16
  function DoubleLinkedNode(keyVal) {
18
17
  this.key = keyVal ? keyVal : '';
@@ -54,10 +53,7 @@ var CacheList = /** @class */ (function () {
54
53
  this.head.nextNode = node;
55
54
  node.nextNode = tmp;
56
55
  node.prevNode = this.head;
57
- asserts(tmp !== null, {
58
- name: CACHE_LIST_EXCEPTION,
59
- message: 'previous node is null',
60
- });
56
+ assert(tmp !== null, CacheErrorCode.NullPreviousNode);
61
57
  tmp.prevNode = node;
62
58
  this.length = this.length + 1;
63
59
  };
@@ -67,14 +63,8 @@ var CacheList = /** @class */ (function () {
67
63
  * @param node
68
64
  */
69
65
  CacheList.prototype.removeNode = function (node) {
70
- asserts(node.prevNode !== null, {
71
- name: CACHE_LIST_EXCEPTION,
72
- message: 'previous node is null',
73
- });
74
- asserts(node.nextNode !== null, {
75
- name: CACHE_LIST_EXCEPTION,
76
- message: 'nextNode node is null',
77
- });
66
+ assert(node.prevNode !== null, CacheErrorCode.NullPreviousNode);
67
+ assert(node.nextNode !== null, CacheErrorCode.NullNextNode);
78
68
  node.prevNode.nextNode = node.nextNode;
79
69
  node.nextNode.prevNode = node.prevNode;
80
70
  node.prevNode = null;
@@ -111,10 +101,7 @@ var CacheList = /** @class */ (function () {
111
101
  * @return the LAST Recently Visited key
112
102
  */
113
103
  CacheList.prototype.getLastItem = function () {
114
- asserts(this.tail.prevNode !== null, {
115
- name: CACHE_LIST_EXCEPTION,
116
- message: 'previous node is null',
117
- });
104
+ assert(this.tail.prevNode !== null, CacheErrorCode.NullPreviousNode);
118
105
  return this.tail.prevNode.key;
119
106
  };
120
107
  /**
@@ -0,0 +1,8 @@
1
+ import { AssertionFunction } from '../../types';
2
+ export declare enum CacheErrorCode {
3
+ NoCacheItem = "NoCacheItem",
4
+ NoCacheStorage = "NoCacheStorage",
5
+ NullNextNode = "NullNextNode",
6
+ NullPreviousNode = "NullPreviousNode"
7
+ }
8
+ export declare const assert: AssertionFunction<CacheErrorCode>;
@@ -0,0 +1,26 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var _a;
4
+ import { createAssertionFunction } from '../../errors';
5
+ export var CacheErrorCode;
6
+ (function (CacheErrorCode) {
7
+ CacheErrorCode["NoCacheItem"] = "NoCacheItem";
8
+ CacheErrorCode["NoCacheStorage"] = "NoCacheStorage";
9
+ CacheErrorCode["NullNextNode"] = "NullNextNode";
10
+ CacheErrorCode["NullPreviousNode"] = "NullPreviousNode";
11
+ })(CacheErrorCode || (CacheErrorCode = {}));
12
+ var cacheErrorMap = (_a = {},
13
+ _a[CacheErrorCode.NoCacheItem] = {
14
+ message: 'Item not found in the cache storage.',
15
+ },
16
+ _a[CacheErrorCode.NoCacheStorage] = {
17
+ message: 'Storage is not defined in the cache config.',
18
+ },
19
+ _a[CacheErrorCode.NullNextNode] = {
20
+ message: 'Next node is null.',
21
+ },
22
+ _a[CacheErrorCode.NullPreviousNode] = {
23
+ message: 'Previous node is null.',
24
+ },
25
+ _a);
26
+ export var assert = createAssertionFunction(cacheErrorMap);
@@ -38,7 +38,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
38
  };
39
39
  import { ConsoleLogger as Logger } from '../Logger';
40
40
  import { NO_HUBCALLBACK_PROVIDED_EXCEPTION } from '../Util/Constants';
41
- import { AmplifyError } from '../Util/Errors';
41
+ import { AmplifyError } from '../errors';
42
42
  export var AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
43
43
  ? Symbol.for('amplify_default')
44
44
  : '@@amplify_default');
@@ -14,4 +14,9 @@ export type AuthHubEventData =
14
14
  /** Dispatched when there is an error in the refresh of tokens.*/
15
15
  | {
16
16
  event: 'tokenRefresh_failure';
17
+ }
18
+ /** Dispatched when there is a customState passed in the options of the `signInWithRedirect` API.*/
19
+ | {
20
+ event: 'customOAuthState';
21
+ data: string;
17
22
  };
@@ -0,0 +1,5 @@
1
+ import { AssertionFunction } from '../types';
2
+ export declare enum I18nErrorCode {
3
+ NotConfigured = "NotConfigured"
4
+ }
5
+ export declare const assert: AssertionFunction<I18nErrorCode>;
@@ -0,0 +1,14 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var _a;
4
+ import { createAssertionFunction } from '../errors';
5
+ export var I18nErrorCode;
6
+ (function (I18nErrorCode) {
7
+ I18nErrorCode["NotConfigured"] = "NotConfigured";
8
+ })(I18nErrorCode || (I18nErrorCode = {}));
9
+ var i18nErrorMap = (_a = {},
10
+ _a[I18nErrorCode.NotConfigured] = {
11
+ message: 'i18n is not configured.',
12
+ },
13
+ _a);
14
+ export var assert = createAssertionFunction(i18nErrorMap);
@@ -2,8 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { I18n as I18nClass } from './I18n';
4
4
  import { ConsoleLogger as Logger } from '../Logger';
5
- import { asserts } from '../Util/errors/AssertError';
6
- import { I18N_EXCEPTION } from '../Util/Constants';
5
+ import { assert, I18nErrorCode } from './errorHelpers';
7
6
  var logger = new Logger('I18n');
8
7
  var _config = { language: null };
9
8
  var _i18n = null;
@@ -56,10 +55,7 @@ var I18n = /** @class */ (function () {
56
55
  */
57
56
  I18n.setLanguage = function (lang) {
58
57
  I18n.checkConfig();
59
- asserts(!!_i18n, {
60
- name: I18N_EXCEPTION,
61
- message: 'I18N is not configured',
62
- });
58
+ assert(!!_i18n, I18nErrorCode.NotConfigured);
63
59
  return _i18n.setLanguage(lang);
64
60
  };
65
61
  /**
@@ -74,10 +70,7 @@ var I18n = /** @class */ (function () {
74
70
  if (!I18n.checkConfig()) {
75
71
  return typeof defVal === 'undefined' ? key : defVal;
76
72
  }
77
- asserts(!!_i18n, {
78
- name: I18N_EXCEPTION,
79
- message: 'I18N is not configured',
80
- });
73
+ assert(!!_i18n, I18nErrorCode.NotConfigured);
81
74
  return _i18n.get(key, defVal);
82
75
  };
83
76
  /**
@@ -91,10 +84,7 @@ var I18n = /** @class */ (function () {
91
84
  */
92
85
  I18n.putVocabulariesForLanguage = function (language, vocabularies) {
93
86
  I18n.checkConfig();
94
- asserts(!!_i18n, {
95
- name: I18N_EXCEPTION,
96
- message: 'I18N is not configured',
97
- });
87
+ assert(!!_i18n, I18nErrorCode.NotConfigured);
98
88
  return _i18n.putVocabulariesForLanguage(language, vocabularies);
99
89
  };
100
90
  /**
@@ -108,10 +98,7 @@ var I18n = /** @class */ (function () {
108
98
  */
109
99
  I18n.putVocabularies = function (vocabularies) {
110
100
  I18n.checkConfig();
111
- asserts(!!_i18n, {
112
- name: I18N_EXCEPTION,
113
- message: 'I18N is not configured',
114
- });
101
+ assert(!!_i18n, I18nErrorCode.NotConfigured);
115
102
  return _i18n.putVocabularies(vocabularies);
116
103
  };
117
104
  I18n.checkConfig = function () {
@@ -1 +1 @@
1
- export declare const version = "6.0.1-console-preview.4432977.0+4432977";
1
+ export declare const version = "6.0.1-console-preview.67f944e.0+67f944e";
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export var version = '6.0.1-console-preview.4432977.0+4432977';
2
+ export var version = '6.0.1-console-preview.67f944e.0+67f944e';
@@ -1,23 +1,10 @@
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
- */
15
3
  import { ConsoleLogger as Logger } from '../Logger';
16
4
  import { isBrowser } from '../Util/JS';
17
5
  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';
6
+ import { AmplifyError } from '../errors';
7
+ import { assert, ServiceWorkerErrorCode } from './errorHelpers';
21
8
  /**
22
9
  * Provides a means to registering a service worker in the browser
23
10
  * and communicating with it via postMessage events.
@@ -40,10 +27,7 @@ var ServiceWorkerClass = /** @class */ (function () {
40
27
  * Get the currently active service worker
41
28
  */
42
29
  get: function () {
43
- asserts(this._serviceWorker !== undefined, {
44
- name: SERVICE_WORKER_EXCEPTION,
45
- message: 'Service Worker instance is undefined',
46
- });
30
+ assert(this._serviceWorker !== undefined, ServiceWorkerErrorCode.UndefinedInstance);
47
31
  return this._serviceWorker;
48
32
  },
49
33
  enumerable: false,
@@ -91,7 +75,7 @@ var ServiceWorkerClass = /** @class */ (function () {
91
75
  .catch(function (error) {
92
76
  _this._logger.debug("Service Worker Registration Failed ".concat(error));
93
77
  return reject(new AmplifyError({
94
- name: SERVICE_WORKER_EXCEPTION,
78
+ name: ServiceWorkerErrorCode.Unavailable,
95
79
  message: 'Service Worker not available',
96
80
  underlyingError: error,
97
81
  }));
@@ -99,7 +83,7 @@ var ServiceWorkerClass = /** @class */ (function () {
99
83
  }
100
84
  else {
101
85
  return reject(new AmplifyError({
102
- name: SERVICE_WORKER_EXCEPTION,
86
+ name: ServiceWorkerErrorCode.Unavailable,
103
87
  message: 'Service Worker not available',
104
88
  }));
105
89
  }
@@ -118,17 +102,11 @@ var ServiceWorkerClass = /** @class */ (function () {
118
102
  */
119
103
  ServiceWorkerClass.prototype.enablePush = function (publicKey) {
120
104
  var _this = this;
121
- asserts(this._registration !== undefined, {
122
- name: SERVICE_WORKER_EXCEPTION,
123
- message: 'Service Worker registration is undefined',
124
- });
105
+ assert(this._registration !== undefined, ServiceWorkerErrorCode.UndefinedRegistration);
125
106
  this._publicKey = publicKey;
126
107
  return new Promise(function (resolve, reject) {
127
108
  if (isBrowser()) {
128
- asserts(_this._registration !== undefined, {
129
- name: SERVICE_WORKER_EXCEPTION,
130
- message: 'Service Worker registration is undefined',
131
- });
109
+ assert(_this._registration !== undefined, ServiceWorkerErrorCode.UndefinedRegistration);
132
110
  _this._registration.pushManager.getSubscription().then(function (subscription) {
133
111
  if (subscription) {
134
112
  _this._subscription = subscription;
@@ -154,7 +132,7 @@ var ServiceWorkerClass = /** @class */ (function () {
154
132
  }
155
133
  else {
156
134
  return reject(new AmplifyError({
157
- name: SERVICE_WORKER_EXCEPTION,
135
+ name: ServiceWorkerErrorCode.Unavailable,
158
136
  message: 'Service Worker not available',
159
137
  }));
160
138
  }
@@ -0,0 +1,7 @@
1
+ import { AssertionFunction } from '../types';
2
+ export declare enum ServiceWorkerErrorCode {
3
+ UndefinedInstance = "UndefinedInstance",
4
+ UndefinedRegistration = "UndefinedRegistration",
5
+ Unavailable = "Unavailable"
6
+ }
7
+ export declare const assert: AssertionFunction<ServiceWorkerErrorCode>;
@@ -0,0 +1,22 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var _a;
4
+ import { createAssertionFunction } from '../errors';
5
+ export var ServiceWorkerErrorCode;
6
+ (function (ServiceWorkerErrorCode) {
7
+ ServiceWorkerErrorCode["UndefinedInstance"] = "UndefinedInstance";
8
+ ServiceWorkerErrorCode["UndefinedRegistration"] = "UndefinedRegistration";
9
+ ServiceWorkerErrorCode["Unavailable"] = "Unavailable";
10
+ })(ServiceWorkerErrorCode || (ServiceWorkerErrorCode = {}));
11
+ var serviceWorkerErrorMap = (_a = {},
12
+ _a[ServiceWorkerErrorCode.UndefinedInstance] = {
13
+ message: 'Service Worker instance is undefined.',
14
+ },
15
+ _a[ServiceWorkerErrorCode.UndefinedRegistration] = {
16
+ message: 'Service Worker registration is undefined.',
17
+ },
18
+ _a[ServiceWorkerErrorCode.Unavailable] = {
19
+ message: 'Service Worker not available.',
20
+ },
21
+ _a);
22
+ export var assert = createAssertionFunction(serviceWorkerErrorMap);
@@ -3,10 +3,4 @@ export declare const NO_CREDS_ERROR_STRING = "No credentials";
3
3
  export declare const RETRY_ERROR_CODES: string[];
4
4
  export declare const INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER: string | symbol;
5
5
  export declare const USER_AGENT_HEADER = "x-amz-user-agent";
6
- export declare const AUTH_CONFING_EXCEPTION = "AuthConfigException";
7
- export declare const CACHE_LIST_EXCEPTION = "CacheListException";
8
- export declare const I18N_EXCEPTION = "I18NException";
9
- export declare const SERVICE_WORKER_EXCEPTION = "ServiceWorkerException";
10
- export declare const STORAGE_CACHE_EXCEPTION = "StorageCacheException";
11
- export declare const APPLICATION_ID_EXCEPTION = "ApplicationIdException";
12
6
  export declare const NO_HUBCALLBACK_PROVIDED_EXCEPTION = "NoHubcallbackProvidedException";
@@ -17,10 +17,4 @@ export var INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER = hasSymbol
17
17
  : '@@INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER';
18
18
  export var USER_AGENT_HEADER = 'x-amz-user-agent';
19
19
  // Error exception code constants
20
- export var AUTH_CONFING_EXCEPTION = 'AuthConfigException';
21
- export var CACHE_LIST_EXCEPTION = 'CacheListException';
22
- export var I18N_EXCEPTION = 'I18NException';
23
- export var SERVICE_WORKER_EXCEPTION = 'ServiceWorkerException';
24
- export var STORAGE_CACHE_EXCEPTION = 'StorageCacheException';
25
- export var APPLICATION_ID_EXCEPTION = 'ApplicationIdException';
26
20
  export var NO_HUBCALLBACK_PROVIDED_EXCEPTION = 'NoHubcallbackProvidedException';
@@ -1,4 +1,4 @@
1
- import { AmplifyError } from '../../libraryUtils';
1
+ import { AmplifyError } from '../../errors';
2
2
  export declare class AmplifyServerContextError extends AmplifyError {
3
3
  constructor({ message, recoverySuggestion, underlyingError, }: {
4
4
  message: string;
@@ -15,7 +15,7 @@ var __extends = (this && this.__extends) || (function () {
15
15
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
16
  };
17
17
  })();
18
- import { AmplifyError } from '../../libraryUtils';
18
+ import { AmplifyError } from '../../errors';
19
19
  var AmplifyServerContextError = /** @class */ (function (_super) {
20
20
  __extends(AmplifyServerContextError, _super);
21
21
  function AmplifyServerContextError(_a) {
@@ -1,10 +1,4 @@
1
- import { ErrorParams } from '../types/errors';
2
- export declare function missingConfig(name: string): Error;
3
- export declare function invalidParameter(name: string): Error;
4
- export declare enum AmplifyErrorString {
5
- UNKNOWN = "UnknownError",
6
- PLATFORM_NOT_SUPPORTED_ERROR = "PlatformNotSupportedError"
7
- }
1
+ import { AmplifyErrorParams } from '../types/errors';
8
2
  export declare class AmplifyError extends Error {
9
3
  underlyingError?: Error | unknown;
10
4
  recoverySuggestion?: string;
@@ -16,6 +10,5 @@ export declare class AmplifyError extends Error {
16
10
  * @param recoverySuggestion suggestion to recover from the error.
17
11
  *
18
12
  */
19
- constructor({ message, name, recoverySuggestion, underlyingError, }: ErrorParams);
13
+ constructor({ message, name, recoverySuggestion, underlyingError, }: AmplifyErrorParams);
20
14
  }
21
- export declare const PlatformNotSupportedError: AmplifyError;
@@ -15,17 +15,6 @@ var __extends = (this && this.__extends) || (function () {
15
15
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
16
  };
17
17
  })();
18
- export function missingConfig(name) {
19
- return new Error('Missing config value of ' + name);
20
- }
21
- export function invalidParameter(name) {
22
- return new Error('Invalid parameter value of ' + name);
23
- }
24
- export var AmplifyErrorString;
25
- (function (AmplifyErrorString) {
26
- AmplifyErrorString["UNKNOWN"] = "UnknownError";
27
- AmplifyErrorString["PLATFORM_NOT_SUPPORTED_ERROR"] = "PlatformNotSupportedError";
28
- })(AmplifyErrorString || (AmplifyErrorString = {}));
29
18
  var AmplifyError = /** @class */ (function (_super) {
30
19
  __extends(AmplifyError, _super);
31
20
  /**
@@ -51,7 +40,3 @@ var AmplifyError = /** @class */ (function (_super) {
51
40
  return AmplifyError;
52
41
  }(Error));
53
42
  export { AmplifyError };
54
- export var PlatformNotSupportedError = new AmplifyError({
55
- name: AmplifyErrorString.PLATFORM_NOT_SUPPORTED_ERROR,
56
- message: 'Function not supported on current platform',
57
- });
@@ -0,0 +1,4 @@
1
+ import { AmplifyError } from './AmplifyError';
2
+ export declare class PlatformNotSupportedError extends AmplifyError {
3
+ constructor();
4
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var __extends = (this && this.__extends) || (function () {
4
+ var extendStatics = function (d, b) {
5
+ extendStatics = Object.setPrototypeOf ||
6
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
+ return extendStatics(d, b);
9
+ };
10
+ return function (d, b) {
11
+ if (typeof b !== "function" && b !== null)
12
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
+ extendStatics(d, b);
14
+ function __() { this.constructor = d; }
15
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
+ };
17
+ })();
18
+ import { AmplifyErrorCode } from '../types';
19
+ import { AmplifyError } from './AmplifyError';
20
+ var PlatformNotSupportedError = /** @class */ (function (_super) {
21
+ __extends(PlatformNotSupportedError, _super);
22
+ function PlatformNotSupportedError() {
23
+ return _super.call(this, {
24
+ name: AmplifyErrorCode.PlatformNotSupported,
25
+ message: 'Function not supported on current platform',
26
+ }) || this;
27
+ }
28
+ return PlatformNotSupportedError;
29
+ }(AmplifyError));
30
+ export { PlatformNotSupportedError };
@@ -0,0 +1,3 @@
1
+ import { AmplifyErrorMap, AssertionFunction } from '../types';
2
+ import { AmplifyError } from './AmplifyError';
3
+ export declare const createAssertionFunction: (errorMap: AmplifyErrorMap, AssertionError?: typeof AmplifyError) => AssertionFunction;
@@ -0,0 +1,18 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { AmplifyError } from './AmplifyError';
4
+ export var createAssertionFunction = function (errorMap, AssertionError) {
5
+ if (AssertionError === void 0) { AssertionError = AmplifyError; }
6
+ return function (assertion, name, additionalContext) {
7
+ var _a = errorMap[name], message = _a.message, recoverySuggestion = _a.recoverySuggestion;
8
+ if (!assertion) {
9
+ throw new AssertionError({
10
+ name: name,
11
+ message: additionalContext
12
+ ? "".concat(message, " ").concat(additionalContext)
13
+ : message,
14
+ recoverySuggestion: recoverySuggestion,
15
+ });
16
+ }
17
+ };
18
+ };
@@ -0,0 +1,3 @@
1
+ export { AmplifyError } from './AmplifyError';
2
+ export { createAssertionFunction } from './createAssertionFunction';
3
+ export { PlatformNotSupportedError } from './PlatformNotSupportedError';
@@ -0,0 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export { AmplifyError } from './AmplifyError';
4
+ export { createAssertionFunction } from './createAssertionFunction';
5
+ export { PlatformNotSupportedError } from './PlatformNotSupportedError';
@@ -1,7 +1,7 @@
1
1
  export { Hub } from './Hub';
2
2
  export { HubCapsule, HubCallback, HubPayload } from './Hub/types';
3
3
  export { TokenProvider, AuthTokens, FetchAuthSessionOptions, AWSCredentialsAndIdentityIdProvider, AWSCredentialsAndIdentityId, Identity, OAuthConfig, CognitoUserPoolConfig, } from './singleton/Auth/types';
4
- export { AuthConfig, AuthUserPoolConfig, AuthUserPoolAndIdentityPoolConfig, StorageAccessLevel, StorageConfig, GetCredentialsOptions, ResourcesConfig, LibraryOptions, AnalyticsConfig, } from './singleton/types';
4
+ export { AuthConfig, AuthUserPoolConfig, AuthUserPoolAndIdentityPoolConfig, StorageAccessLevel, StorageConfig, GetCredentialsOptions, ResourcesConfig, LibraryOptions, AnalyticsConfig, GeoConfig, } from './singleton/types';
5
5
  export { Amplify, fetchAuthSession, AmplifyClass as AmplifyClassV6, clearCredentials, } from './singleton';
6
6
  export { getCredentialsForIdentity, getId, GetCredentialsForIdentityInput, GetCredentialsForIdentityOutput, } from './AwsClients/CognitoIdentity';
7
7
  export { UserProfile } from './types';
@@ -2,7 +2,7 @@ export { isBrowser, filenameToContentType, generateRandomString, isEmpty, isStri
2
2
  export { parseAWSExports } from './parseAWSExports';
3
3
  export { LegacyConfig } from './singleton/types';
4
4
  export { JWT, StrictUnion, CognitoIdentityPoolConfig, JwtPayload, } from './singleton/Auth/types';
5
- export { decodeJWT, assertTokenProviderConfig, assertIdentityPooIdConfig, assertOAuthConfig, } from './singleton/Auth/utils';
5
+ export { decodeJWT, assertTokenProviderConfig, assertIdentityPoolIdConfig, assertOAuthConfig, } from './singleton/Auth/utils';
6
6
  export { isTokenExpired } from './singleton/Auth';
7
7
  export { GraphQLAuthModeKeys } from './singleton/API/types';
8
8
  export { Signer } from './Signer';
@@ -15,9 +15,8 @@ export declare const Constants: {
15
15
  };
16
16
  export { ServiceWorker } from './ServiceWorker';
17
17
  export { AWS_CLOUDWATCH_CATEGORY, BackgroundManagerNotOpenError, BackgroundProcessManager, BackgroundProcessManagerState, DateUtils, Mutex, NO_CREDS_ERROR_STRING, NonRetryableError, RETRY_ERROR_CODES, Reachability, isNonRetryableError, jitteredBackoff, jitteredExponentialRetry, retry, urlSafeDecode, urlSafeEncode, } from './Util';
18
- export { asserts } from './Util/errors/AssertError';
19
- export { invalidParameter, missingConfig, AmplifyError, AmplifyErrorString, } from './Util/Errors';
20
- export { ErrorParams, AmplifyErrorMap, ServiceError } from './types';
18
+ export { AmplifyError, PlatformNotSupportedError, createAssertionFunction, } from './errors';
19
+ export { AmplifyErrorCode, AmplifyErrorMap, AmplifyErrorParams, AssertionFunction, ServiceError, } from './types';
21
20
  export { INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER, USER_AGENT_HEADER, } from './Util/Constants';
22
21
  export { fetchAuthSession } from './singleton/apis/internal/fetchAuthSession';
23
22
  export { AMPLIFY_SYMBOL } from './Hub';
@@ -8,7 +8,7 @@ utils for use throughout the library.
8
8
  export { isBrowser, filenameToContentType, generateRandomString, isEmpty, isStrictObject, isTextFile, isWebWorker, makeQuerablePromise, objectLessAttributes, sortByField, transferKeyToLowerCase, transferKeyToUpperCase, } from './Util/JS';
9
9
  export { parseAWSExports } from './parseAWSExports';
10
10
  // Auth utilities
11
- export { decodeJWT, assertTokenProviderConfig, assertIdentityPooIdConfig, assertOAuthConfig, } from './singleton/Auth/utils';
11
+ export { decodeJWT, assertTokenProviderConfig, assertIdentityPoolIdConfig, assertOAuthConfig, } from './singleton/Auth/utils';
12
12
  export { isTokenExpired } from './singleton/Auth';
13
13
  export { Signer } from './Signer';
14
14
  // Logging utilities
@@ -25,8 +25,8 @@ export var Constants = {
25
25
  export { ServiceWorker } from './ServiceWorker';
26
26
  // Other utilities & constants
27
27
  export { AWS_CLOUDWATCH_CATEGORY, BackgroundManagerNotOpenError, BackgroundProcessManager, BackgroundProcessManagerState, DateUtils, Mutex, NO_CREDS_ERROR_STRING, NonRetryableError, RETRY_ERROR_CODES, Reachability, isNonRetryableError, jitteredBackoff, jitteredExponentialRetry, retry, urlSafeDecode, urlSafeEncode, } from './Util';
28
- export { asserts } from './Util/errors/AssertError';
29
- export { invalidParameter, missingConfig, AmplifyError, AmplifyErrorString, } from './Util/Errors';
28
+ export { AmplifyError, PlatformNotSupportedError, createAssertionFunction, } from './errors';
29
+ export { AmplifyErrorCode, } from './types';
30
30
  export { INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER, USER_AGENT_HEADER, } from './Util/Constants';
31
31
  export { fetchAuthSession } from './singleton/apis/internal/fetchAuthSession';
32
32
  export { AMPLIFY_SYMBOL } from './Hub';
@@ -72,7 +72,9 @@ export var parseAWSExports = function (config) {
72
72
  if (geo) {
73
73
  var amazon_location_service = geo.amazon_location_service;
74
74
  amplifyConfig.Geo = amazon_location_service
75
- ? { AmazonLocationService: amazon_location_service }
75
+ ? {
76
+ LocationService: __assign(__assign({}, amazon_location_service), { searchIndices: amazon_location_service.search_indices, region: amazon_location_service.region }),
77
+ }
76
78
  : __assign({}, geo);
77
79
  }
78
80
  return amplifyConfig;