@aws-amplify/core 6.0.1-console-preview.4208d73.0 → 6.0.1-console-preview.431c340.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 (144) 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/providers/pinpoint/apis/updateEndpoint.d.ts +1 -1
  38. package/lib/providers/pinpoint/apis/updateEndpoint.js +7 -5
  39. package/lib/providers/pinpoint/types/pinpoint.d.ts +1 -0
  40. package/lib/singleton/Auth/utils/errorHelpers.d.ts +8 -0
  41. package/lib/singleton/Auth/utils/errorHelpers.js +33 -0
  42. package/lib/singleton/Auth/utils/index.d.ts +1 -1
  43. package/lib/singleton/Auth/utils/index.js +9 -25
  44. package/lib/singleton/Geo/types.d.ts +17 -0
  45. package/lib/singleton/Geo/types.js +4 -0
  46. package/lib/singleton/types.d.ts +3 -1
  47. package/lib/storage/DefaultStorage.native.js +2 -2
  48. package/lib/storage/KeyValueStorage.js +5 -5
  49. package/lib/tsconfig.tsbuildinfo +1 -1
  50. package/lib/types/core.d.ts +4 -1
  51. package/lib/types/errors.d.ts +8 -3
  52. package/lib/types/errors.js +6 -0
  53. package/lib-esm/AwsClients/Pinpoint/errorHelpers.d.ts +5 -0
  54. package/lib-esm/AwsClients/Pinpoint/errorHelpers.js +14 -0
  55. package/lib-esm/AwsClients/Pinpoint/putEvents.js +2 -6
  56. package/lib-esm/Cache/AsyncStorageCache.js +3 -10
  57. package/lib-esm/Cache/BrowserStorageCache.js +5 -18
  58. package/lib-esm/Cache/InMemoryCache.js +3 -10
  59. package/lib-esm/Cache/Utils/CacheList.js +5 -18
  60. package/lib-esm/Cache/Utils/errorHelpers.d.ts +8 -0
  61. package/lib-esm/Cache/Utils/errorHelpers.js +26 -0
  62. package/lib-esm/Hub/index.js +1 -1
  63. package/lib-esm/Hub/types/AuthTypes.d.ts +5 -0
  64. package/lib-esm/I18n/errorHelpers.d.ts +5 -0
  65. package/lib-esm/I18n/errorHelpers.js +14 -0
  66. package/lib-esm/I18n/index.js +5 -18
  67. package/lib-esm/Platform/version.d.ts +1 -1
  68. package/lib-esm/Platform/version.js +1 -1
  69. package/lib-esm/ServiceWorker/ServiceWorker.js +8 -30
  70. package/lib-esm/ServiceWorker/errorHelpers.d.ts +7 -0
  71. package/lib-esm/ServiceWorker/errorHelpers.js +22 -0
  72. package/lib-esm/Util/Constants.d.ts +0 -6
  73. package/lib-esm/Util/Constants.js +0 -6
  74. package/lib-esm/adapterCore/error/AmplifyServerContextError.d.ts +1 -1
  75. package/lib-esm/adapterCore/error/AmplifyServerContextError.js +1 -1
  76. package/lib-esm/{Util/Errors.d.ts → errors/AmplifyError.d.ts} +2 -9
  77. package/lib-esm/{Util/Errors.js → errors/AmplifyError.js} +0 -15
  78. package/lib-esm/errors/PlatformNotSupportedError.d.ts +4 -0
  79. package/lib-esm/errors/PlatformNotSupportedError.js +30 -0
  80. package/lib-esm/errors/createAssertionFunction.d.ts +3 -0
  81. package/lib-esm/errors/createAssertionFunction.js +18 -0
  82. package/lib-esm/errors/index.d.ts +3 -0
  83. package/lib-esm/errors/index.js +5 -0
  84. package/lib-esm/index.d.ts +1 -1
  85. package/lib-esm/libraryUtils.d.ts +3 -4
  86. package/lib-esm/libraryUtils.js +3 -3
  87. package/lib-esm/parseAWSExports.js +3 -1
  88. package/lib-esm/providers/pinpoint/apis/record.js +1 -1
  89. package/lib-esm/providers/pinpoint/apis/updateEndpoint.d.ts +1 -1
  90. package/lib-esm/providers/pinpoint/apis/updateEndpoint.js +7 -5
  91. package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +1 -0
  92. package/lib-esm/singleton/Auth/utils/errorHelpers.d.ts +8 -0
  93. package/lib-esm/singleton/Auth/utils/errorHelpers.js +30 -0
  94. package/lib-esm/singleton/Auth/utils/index.d.ts +1 -1
  95. package/lib-esm/singleton/Auth/utils/index.js +7 -23
  96. package/lib-esm/singleton/Geo/types.d.ts +17 -0
  97. package/lib-esm/singleton/Geo/types.js +3 -0
  98. package/lib-esm/singleton/types.d.ts +3 -1
  99. package/lib-esm/storage/DefaultStorage.native.js +1 -1
  100. package/lib-esm/storage/KeyValueStorage.js +5 -5
  101. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  102. package/lib-esm/types/core.d.ts +4 -1
  103. package/lib-esm/types/errors.d.ts +8 -3
  104. package/lib-esm/types/errors.js +5 -1
  105. package/package.json +2 -2
  106. package/src/AwsClients/Pinpoint/errorHelpers.ts +19 -0
  107. package/src/AwsClients/Pinpoint/putEvents.ts +2 -6
  108. package/src/Cache/AsyncStorageCache.ts +4 -10
  109. package/src/Cache/BrowserStorageCache.ts +5 -18
  110. package/src/Cache/InMemoryCache.ts +4 -11
  111. package/src/Cache/Utils/CacheList.ts +5 -18
  112. package/src/Cache/Utils/errorHelpers.ts +30 -0
  113. package/src/Hub/index.ts +1 -1
  114. package/src/Hub/types/AuthTypes.ts +3 -1
  115. package/src/I18n/errorHelpers.ts +18 -0
  116. package/src/I18n/index.ts +12 -24
  117. package/src/Platform/version.ts +1 -1
  118. package/src/ServiceWorker/ServiceWorker.ts +18 -30
  119. package/src/ServiceWorker/errorHelpers.ts +26 -0
  120. package/src/Util/Constants.ts +0 -6
  121. package/src/adapterCore/error/AmplifyServerContextError.ts +1 -1
  122. package/src/{Util/Errors.ts → errors/AmplifyError.ts} +2 -18
  123. package/src/errors/PlatformNotSupportedError.ts +14 -0
  124. package/src/errors/createAssertionFunction.ts +23 -0
  125. package/src/errors/index.ts +6 -0
  126. package/src/index.ts +1 -0
  127. package/src/libraryUtils.ts +11 -7
  128. package/src/parseAWSExports.ts +7 -1
  129. package/src/providers/pinpoint/apis/record.ts +1 -1
  130. package/src/providers/pinpoint/apis/updateEndpoint.ts +19 -3
  131. package/src/providers/pinpoint/types/pinpoint.ts +1 -0
  132. package/src/singleton/Auth/utils/errorHelpers.ts +37 -0
  133. package/src/singleton/Auth/utils/index.ts +19 -26
  134. package/src/singleton/Geo/types.ts +20 -0
  135. package/src/singleton/types.ts +3 -0
  136. package/src/storage/DefaultStorage.native.ts +1 -1
  137. package/src/storage/KeyValueStorage.ts +5 -5
  138. package/src/types/core.ts +4 -1
  139. package/src/types/errors.ts +14 -3
  140. package/lib/Util/errors/AssertError.d.ts +0 -2
  141. package/lib/Util/errors/AssertError.js +0 -11
  142. package/lib-esm/Util/errors/AssertError.d.ts +0 -2
  143. package/lib-esm/Util/errors/AssertError.js +0 -7
  144. package/src/Util/errors/AssertError.ts +0 -11
@@ -0,0 +1,5 @@
1
+ import { AssertionFunction } from '../../types';
2
+ export declare enum PinpointValidationErrorCode {
3
+ NoAppId = "NoAppId"
4
+ }
5
+ export declare const assert: AssertionFunction<PinpointValidationErrorCode>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var _a;
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.assert = exports.PinpointValidationErrorCode = void 0;
7
+ var errors_1 = require("../../errors");
8
+ var PinpointValidationErrorCode;
9
+ (function (PinpointValidationErrorCode) {
10
+ PinpointValidationErrorCode["NoAppId"] = "NoAppId";
11
+ })(PinpointValidationErrorCode = exports.PinpointValidationErrorCode || (exports.PinpointValidationErrorCode = {}));
12
+ var pinpointValidationErrorMap = (_a = {},
13
+ _a[PinpointValidationErrorCode.NoAppId] = {
14
+ message: 'Missing application id.',
15
+ },
16
+ _a);
17
+ exports.assert = (0, errors_1.createAssertionFunction)(pinpointValidationErrorMap);
@@ -39,19 +39,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.putEvents = void 0;
42
- var AssertError_1 = require("../../Util/errors/AssertError");
43
42
  var authenticated_1 = require("../../clients/handlers/authenticated");
44
43
  var composeServiceApi_1 = require("../../clients/internal/composeServiceApi");
45
44
  var extendedEncodeURIComponent_1 = require("../../clients/middleware/signing/utils/extendedEncodeURIComponent");
46
45
  var serde_1 = require("../../clients/serde");
47
- var Constants_1 = require("../../Util/Constants");
48
46
  var base_1 = require("./base");
47
+ var errorHelpers_1 = require("./errorHelpers");
49
48
  var putEventsSerializer = function (_a, endpoint) {
50
49
  var ApplicationId = _a.ApplicationId, EventsRequest = _a.EventsRequest;
51
- (0, AssertError_1.asserts)(!!ApplicationId, {
52
- name: Constants_1.APPLICATION_ID_EXCEPTION,
53
- message: 'ApplicationId is required for putEvents',
54
- });
50
+ (0, errorHelpers_1.assert)(!!ApplicationId, errorHelpers_1.PinpointValidationErrorCode.NoAppId);
55
51
  var headers = (0, base_1.getSharedHeaders)();
56
52
  var url = new URL(endpoint.url);
57
53
  url.pathname = "v1/apps/".concat((0, extendedEncodeURIComponent_1.extendedEncodeURIComponent)(ApplicationId), "/events");
@@ -62,9 +62,8 @@ exports.AsyncStorage = async_storage_1.default;
62
62
  var Logger_1 = require("../Logger");
63
63
  var StorageCache_1 = require("./StorageCache");
64
64
  var Utils_1 = require("./Utils");
65
- var Constants_1 = require("../Util/Constants");
66
- var AssertError_1 = require("../Util/errors/AssertError");
67
65
  var CacheUtils_1 = require("./Utils/CacheUtils");
66
+ var errorHelpers_1 = require("./Utils/errorHelpers");
68
67
  var logger = new Logger_1.ConsoleLogger('AsyncStorageCache');
69
68
  /*
70
69
  * Customized cache which based on the AsyncStorage with LRU implemented
@@ -163,10 +162,7 @@ var AsyncStorageCache = /** @class */ (function (_super) {
163
162
  case 0: return [4 /*yield*/, async_storage_1.default.getItem(key)];
164
163
  case 1:
165
164
  text = _a.sent();
166
- (0, AssertError_1.asserts)(text !== null, {
167
- name: Constants_1.STORAGE_CACHE_EXCEPTION,
168
- message: "Item not found in the storage by the key: ".concat(key, "."),
169
- });
165
+ (0, errorHelpers_1.assert)(text !== null, errorHelpers_1.CacheErrorCode.NoCacheItem, "Key: ".concat(key));
170
166
  item = JSON.parse(text);
171
167
  if ((0, Utils_1.getCurrTime)() >= item.expires) {
172
168
  return [2 /*return*/, true];
@@ -190,10 +186,7 @@ var AsyncStorageCache = /** @class */ (function (_super) {
190
186
  case 0: return [4 /*yield*/, async_storage_1.default.getItem(prefixedKey)];
191
187
  case 1:
192
188
  config = _a.sent();
193
- (0, AssertError_1.asserts)(!!config, {
194
- name: Constants_1.STORAGE_CACHE_EXCEPTION,
195
- message: "Item not found in the storage by the key: ".concat(prefixedKey, "."),
196
- });
189
+ (0, errorHelpers_1.assert)(!!config, errorHelpers_1.CacheErrorCode.NoCacheItem, "Key: ".concat(prefixedKey));
197
190
  itemSize = size !== null && size !== void 0 ? size : JSON.parse(config).byteSize;
198
191
  // first try to update the current size of the cache
199
192
  return [4 /*yield*/, this._decreaseCurSizeInBytes(itemSize)];
@@ -21,9 +21,8 @@ exports.BrowserStorageCache = exports.BrowserStorageCacheClass = void 0;
21
21
  var Logger_1 = require("../Logger");
22
22
  var Utils_1 = require("./Utils");
23
23
  var StorageCache_1 = require("./StorageCache");
24
- var AssertError_1 = require("../Util/errors/AssertError");
25
- var Constants_1 = require("../Util/Constants");
26
24
  var CacheUtils_1 = require("./Utils/CacheUtils");
25
+ var errorHelpers_1 = require("./Utils/errorHelpers");
27
26
  var logger = new Logger_1.ConsoleLogger('Cache');
28
27
  /**
29
28
  * Customized storage based on the SessionStorage or LocalStorage with LRU implemented
@@ -36,10 +35,7 @@ var BrowserStorageCacheClass = /** @class */ (function (_super) {
36
35
  */
37
36
  function BrowserStorageCacheClass(config) {
38
37
  var _this = _super.call(this, config) || this;
39
- (0, AssertError_1.asserts)(!!_this.cacheConfig.storage, {
40
- name: Constants_1.STORAGE_CACHE_EXCEPTION,
41
- message: 'Storage is not defined in the cache config',
42
- });
38
+ (0, errorHelpers_1.assert)(!!_this.cacheConfig.storage, errorHelpers_1.CacheErrorCode.NoCacheStorage);
43
39
  _this.cacheConfig.storage = _this.cacheConfig.storage;
44
40
  _this.getItem = _this.getItem.bind(_this);
45
41
  _this.setItem = _this.setItem.bind(_this);
@@ -47,10 +43,7 @@ var BrowserStorageCacheClass = /** @class */ (function (_super) {
47
43
  return _this;
48
44
  }
49
45
  BrowserStorageCacheClass.prototype.getStorage = function () {
50
- (0, AssertError_1.asserts)(!!this.cacheConfig.storage, {
51
- name: Constants_1.STORAGE_CACHE_EXCEPTION,
52
- message: 'Storage is not defined in the cache config',
53
- });
46
+ (0, errorHelpers_1.assert)(!!this.cacheConfig.storage, errorHelpers_1.CacheErrorCode.NoCacheStorage);
54
47
  return this.cacheConfig.storage;
55
48
  };
56
49
  /**
@@ -97,10 +90,7 @@ var BrowserStorageCacheClass = /** @class */ (function (_super) {
97
90
  */
98
91
  BrowserStorageCacheClass.prototype._isExpired = function (key) {
99
92
  var text = this.getStorage().getItem(key);
100
- (0, AssertError_1.asserts)(text !== null, {
101
- name: Constants_1.STORAGE_CACHE_EXCEPTION,
102
- message: "Item not found in the storage by the key: ".concat(key, "."),
103
- });
93
+ (0, errorHelpers_1.assert)(text !== null, errorHelpers_1.CacheErrorCode.NoCacheItem, "Key: ".concat(key));
104
94
  var item = JSON.parse(text);
105
95
  if ((0, Utils_1.getCurrTime)() >= item.expires) {
106
96
  return true;
@@ -116,10 +106,7 @@ var BrowserStorageCacheClass = /** @class */ (function (_super) {
116
106
  */
117
107
  BrowserStorageCacheClass.prototype._removeItem = function (prefixedKey, size) {
118
108
  var item = this.getStorage().getItem(prefixedKey);
119
- (0, AssertError_1.asserts)(item !== null, {
120
- name: Constants_1.STORAGE_CACHE_EXCEPTION,
121
- message: "Item not found in the storage by the key: ".concat(prefixedKey, "."),
122
- });
109
+ (0, errorHelpers_1.assert)(item !== null, errorHelpers_1.CacheErrorCode.NoCacheItem, "Key: ".concat(prefixedKey));
123
110
  var itemSize = size !== null && size !== void 0 ? size : JSON.parse(item).byteSize;
124
111
  this._decreaseCurSizeInBytes(itemSize);
125
112
  // remove the cache item
@@ -32,9 +32,8 @@ exports.InMemoryCache = exports.InMemoryCacheClass = void 0;
32
32
  var Utils_1 = require("./Utils");
33
33
  var StorageCache_1 = require("./StorageCache");
34
34
  var Logger_1 = require("../Logger");
35
- var AssertError_1 = require("../Util/errors/AssertError");
36
- var Constants_1 = require("../Util/Constants");
37
35
  var CacheUtils_1 = require("./Utils/CacheUtils");
36
+ var errorHelpers_1 = require("./Utils/errorHelpers");
38
37
  var logger = new Logger_1.ConsoleLogger('InMemoryCache');
39
38
  /**
40
39
  * Customized in-memory cache with LRU implemented
@@ -89,10 +88,7 @@ var InMemoryCacheClass = /** @class */ (function (_super) {
89
88
  */
90
89
  InMemoryCacheClass.prototype._isExpired = function (key) {
91
90
  var text = Utils_1.CacheObject.getItem(key);
92
- (0, AssertError_1.asserts)(text !== null, {
93
- name: Constants_1.STORAGE_CACHE_EXCEPTION,
94
- message: 'item from storage is null',
95
- });
91
+ (0, errorHelpers_1.assert)(text !== null, errorHelpers_1.CacheErrorCode.NoCacheItem, "Key: ".concat(key));
96
92
  var item = JSON.parse(text);
97
93
  if ((0, Utils_1.getCurrTime)() >= item.expires) {
98
94
  return true;
@@ -110,10 +106,7 @@ var InMemoryCacheClass = /** @class */ (function (_super) {
110
106
  this.cacheList[listIdx].removeItem(prefixedKey);
111
107
  // decrease the current size of the cache
112
108
  var item = Utils_1.CacheObject.getItem(prefixedKey);
113
- (0, AssertError_1.asserts)(item !== null, {
114
- name: Constants_1.STORAGE_CACHE_EXCEPTION,
115
- message: 'item from storage is null',
116
- });
109
+ (0, errorHelpers_1.assert)(item !== null, errorHelpers_1.CacheErrorCode.NoCacheItem, "Key: ".concat(prefixedKey));
117
110
  this._decreaseCurSizeInBytes(JSON.parse(item).byteSize);
118
111
  // finally remove the item from memory
119
112
  Utils_1.CacheObject.removeItem(prefixedKey);
@@ -13,8 +13,7 @@ var __values = (this && this.__values) || function(o) {
13
13
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- var AssertError_1 = require("../../Util/errors/AssertError");
17
- var Constants_1 = require("../../Util/Constants");
16
+ var errorHelpers_1 = require("./errorHelpers");
18
17
  var DoubleLinkedNode = /** @class */ (function () {
19
18
  function DoubleLinkedNode(keyVal) {
20
19
  this.key = keyVal ? keyVal : '';
@@ -56,10 +55,7 @@ var CacheList = /** @class */ (function () {
56
55
  this.head.nextNode = node;
57
56
  node.nextNode = tmp;
58
57
  node.prevNode = this.head;
59
- (0, AssertError_1.asserts)(tmp !== null, {
60
- name: Constants_1.CACHE_LIST_EXCEPTION,
61
- message: 'previous node is null',
62
- });
58
+ (0, errorHelpers_1.assert)(tmp !== null, errorHelpers_1.CacheErrorCode.NullPreviousNode);
63
59
  tmp.prevNode = node;
64
60
  this.length = this.length + 1;
65
61
  };
@@ -69,14 +65,8 @@ var CacheList = /** @class */ (function () {
69
65
  * @param node
70
66
  */
71
67
  CacheList.prototype.removeNode = function (node) {
72
- (0, AssertError_1.asserts)(node.prevNode !== null, {
73
- name: Constants_1.CACHE_LIST_EXCEPTION,
74
- message: 'previous node is null',
75
- });
76
- (0, AssertError_1.asserts)(node.nextNode !== null, {
77
- name: Constants_1.CACHE_LIST_EXCEPTION,
78
- message: 'nextNode node is null',
79
- });
68
+ (0, errorHelpers_1.assert)(node.prevNode !== null, errorHelpers_1.CacheErrorCode.NullPreviousNode);
69
+ (0, errorHelpers_1.assert)(node.nextNode !== null, errorHelpers_1.CacheErrorCode.NullNextNode);
80
70
  node.prevNode.nextNode = node.nextNode;
81
71
  node.nextNode.prevNode = node.prevNode;
82
72
  node.prevNode = null;
@@ -113,10 +103,7 @@ var CacheList = /** @class */ (function () {
113
103
  * @return the LAST Recently Visited key
114
104
  */
115
105
  CacheList.prototype.getLastItem = function () {
116
- (0, AssertError_1.asserts)(this.tail.prevNode !== null, {
117
- name: Constants_1.CACHE_LIST_EXCEPTION,
118
- message: 'previous node is null',
119
- });
106
+ (0, errorHelpers_1.assert)(this.tail.prevNode !== null, errorHelpers_1.CacheErrorCode.NullPreviousNode);
120
107
  return this.tail.prevNode.key;
121
108
  };
122
109
  /**
@@ -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,29 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var _a;
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.assert = exports.CacheErrorCode = void 0;
7
+ var errors_1 = require("../../errors");
8
+ var CacheErrorCode;
9
+ (function (CacheErrorCode) {
10
+ CacheErrorCode["NoCacheItem"] = "NoCacheItem";
11
+ CacheErrorCode["NoCacheStorage"] = "NoCacheStorage";
12
+ CacheErrorCode["NullNextNode"] = "NullNextNode";
13
+ CacheErrorCode["NullPreviousNode"] = "NullPreviousNode";
14
+ })(CacheErrorCode = exports.CacheErrorCode || (exports.CacheErrorCode = {}));
15
+ var cacheErrorMap = (_a = {},
16
+ _a[CacheErrorCode.NoCacheItem] = {
17
+ message: 'Item not found in the cache storage.',
18
+ },
19
+ _a[CacheErrorCode.NoCacheStorage] = {
20
+ message: 'Storage is not defined in the cache config.',
21
+ },
22
+ _a[CacheErrorCode.NullNextNode] = {
23
+ message: 'Next node is null.',
24
+ },
25
+ _a[CacheErrorCode.NullPreviousNode] = {
26
+ message: 'Previous node is null.',
27
+ },
28
+ _a);
29
+ exports.assert = (0, errors_1.createAssertionFunction)(cacheErrorMap);
package/lib/Hub/index.js CHANGED
@@ -41,7 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.Hub = exports.HubClass = exports.AMPLIFY_SYMBOL = void 0;
42
42
  var Logger_1 = require("../Logger");
43
43
  var Constants_1 = require("../Util/Constants");
44
- var Errors_1 = require("../Util/Errors");
44
+ var errors_1 = require("../errors");
45
45
  exports.AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
46
46
  ? Symbol.for('amplify_default')
47
47
  : '@@amplify_default');
@@ -105,7 +105,7 @@ var HubClass = /** @class */ (function () {
105
105
  if (listenerName === void 0) { listenerName = 'noname'; }
106
106
  var cb;
107
107
  if (typeof callback !== 'function') {
108
- throw new Errors_1.AmplifyError({
108
+ throw new errors_1.AmplifyError({
109
109
  name: Constants_1.NO_HUBCALLBACK_PROVIDED_EXCEPTION,
110
110
  message: 'No callback supplied to Hub',
111
111
  });
@@ -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,17 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var _a;
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.assert = exports.I18nErrorCode = void 0;
7
+ var errors_1 = require("../errors");
8
+ var I18nErrorCode;
9
+ (function (I18nErrorCode) {
10
+ I18nErrorCode["NotConfigured"] = "NotConfigured";
11
+ })(I18nErrorCode = exports.I18nErrorCode || (exports.I18nErrorCode = {}));
12
+ var i18nErrorMap = (_a = {},
13
+ _a[I18nErrorCode.NotConfigured] = {
14
+ message: 'i18n is not configured.',
15
+ },
16
+ _a);
17
+ exports.assert = (0, errors_1.createAssertionFunction)(i18nErrorMap);
package/lib/I18n/index.js CHANGED
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.I18n = void 0;
6
6
  var I18n_1 = require("./I18n");
7
7
  var Logger_1 = require("../Logger");
8
- var AssertError_1 = require("../Util/errors/AssertError");
9
- var Constants_1 = require("../Util/Constants");
8
+ var errorHelpers_1 = require("./errorHelpers");
10
9
  var logger = new Logger_1.ConsoleLogger('I18n');
11
10
  var _config = { language: null };
12
11
  var _i18n = null;
@@ -59,10 +58,7 @@ var I18n = /** @class */ (function () {
59
58
  */
60
59
  I18n.setLanguage = function (lang) {
61
60
  I18n.checkConfig();
62
- (0, AssertError_1.asserts)(!!_i18n, {
63
- name: Constants_1.I18N_EXCEPTION,
64
- message: 'I18N is not configured',
65
- });
61
+ (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);
66
62
  return _i18n.setLanguage(lang);
67
63
  };
68
64
  /**
@@ -77,10 +73,7 @@ var I18n = /** @class */ (function () {
77
73
  if (!I18n.checkConfig()) {
78
74
  return typeof defVal === 'undefined' ? key : defVal;
79
75
  }
80
- (0, AssertError_1.asserts)(!!_i18n, {
81
- name: Constants_1.I18N_EXCEPTION,
82
- message: 'I18N is not configured',
83
- });
76
+ (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);
84
77
  return _i18n.get(key, defVal);
85
78
  };
86
79
  /**
@@ -94,10 +87,7 @@ var I18n = /** @class */ (function () {
94
87
  */
95
88
  I18n.putVocabulariesForLanguage = function (language, vocabularies) {
96
89
  I18n.checkConfig();
97
- (0, AssertError_1.asserts)(!!_i18n, {
98
- name: Constants_1.I18N_EXCEPTION,
99
- message: 'I18N is not configured',
100
- });
90
+ (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);
101
91
  return _i18n.putVocabulariesForLanguage(language, vocabularies);
102
92
  };
103
93
  /**
@@ -111,10 +101,7 @@ var I18n = /** @class */ (function () {
111
101
  */
112
102
  I18n.putVocabularies = function (vocabularies) {
113
103
  I18n.checkConfig();
114
- (0, AssertError_1.asserts)(!!_i18n, {
115
- name: Constants_1.I18N_EXCEPTION,
116
- message: 'I18N is not configured',
117
- });
104
+ (0, errorHelpers_1.assert)(!!_i18n, errorHelpers_1.I18nErrorCode.NotConfigured);
118
105
  return _i18n.putVocabularies(vocabularies);
119
106
  };
120
107
  I18n.checkConfig = function () {
@@ -1 +1 @@
1
- export declare const version = "6.0.1-console-preview.4208d73.0+4208d73";
1
+ export declare const version = "6.0.1-console-preview.431c340.0+431c340";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // generated by genversion
5
- exports.version = '6.0.1-console-preview.4208d73.0+4208d73';
5
+ exports.version = '6.0.1-console-preview.431c340.0+431c340';
@@ -1,26 +1,13 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServiceWorkerClass = void 0;
4
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
3
  // SPDX-License-Identifier: Apache-2.0
6
- /**
7
- * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
8
- *
9
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
10
- * the License. A copy of the License is located at
11
- *
12
- * http://aws.amazon.com/apache2.0/
13
- *
14
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
15
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
16
- * and limitations under the License.
17
- */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.ServiceWorkerClass = void 0;
18
6
  var Logger_1 = require("../Logger");
19
7
  var JS_1 = require("../Util/JS");
20
8
  var Amplify_1 = require("../Amplify");
21
- var AssertError_1 = require("../Util/errors/AssertError");
22
- var Errors_1 = require("../Util/Errors");
23
- var Constants_1 = require("../Util/Constants");
9
+ var errors_1 = require("../errors");
10
+ var errorHelpers_1 = require("./errorHelpers");
24
11
  /**
25
12
  * Provides a means to registering a service worker in the browser
26
13
  * and communicating with it via postMessage events.
@@ -43,10 +30,7 @@ var ServiceWorkerClass = /** @class */ (function () {
43
30
  * Get the currently active service worker
44
31
  */
45
32
  get: function () {
46
- (0, AssertError_1.asserts)(this._serviceWorker !== undefined, {
47
- name: Constants_1.SERVICE_WORKER_EXCEPTION,
48
- message: 'Service Worker instance is undefined',
49
- });
33
+ (0, errorHelpers_1.assert)(this._serviceWorker !== undefined, errorHelpers_1.ServiceWorkerErrorCode.UndefinedInstance);
50
34
  return this._serviceWorker;
51
35
  },
52
36
  enumerable: false,
@@ -93,16 +77,16 @@ var ServiceWorkerClass = /** @class */ (function () {
93
77
  })
94
78
  .catch(function (error) {
95
79
  _this._logger.debug("Service Worker Registration Failed ".concat(error));
96
- return reject(new Errors_1.AmplifyError({
97
- name: Constants_1.SERVICE_WORKER_EXCEPTION,
80
+ return reject(new errors_1.AmplifyError({
81
+ name: errorHelpers_1.ServiceWorkerErrorCode.Unavailable,
98
82
  message: 'Service Worker not available',
99
83
  underlyingError: error,
100
84
  }));
101
85
  });
102
86
  }
103
87
  else {
104
- return reject(new Errors_1.AmplifyError({
105
- name: Constants_1.SERVICE_WORKER_EXCEPTION,
88
+ return reject(new errors_1.AmplifyError({
89
+ name: errorHelpers_1.ServiceWorkerErrorCode.Unavailable,
106
90
  message: 'Service Worker not available',
107
91
  }));
108
92
  }
@@ -121,17 +105,11 @@ var ServiceWorkerClass = /** @class */ (function () {
121
105
  */
122
106
  ServiceWorkerClass.prototype.enablePush = function (publicKey) {
123
107
  var _this = this;
124
- (0, AssertError_1.asserts)(this._registration !== undefined, {
125
- name: Constants_1.SERVICE_WORKER_EXCEPTION,
126
- message: 'Service Worker registration is undefined',
127
- });
108
+ (0, errorHelpers_1.assert)(this._registration !== undefined, errorHelpers_1.ServiceWorkerErrorCode.UndefinedRegistration);
128
109
  this._publicKey = publicKey;
129
110
  return new Promise(function (resolve, reject) {
130
111
  if ((0, JS_1.isBrowser)()) {
131
- (0, AssertError_1.asserts)(_this._registration !== undefined, {
132
- name: Constants_1.SERVICE_WORKER_EXCEPTION,
133
- message: 'Service Worker registration is undefined',
134
- });
112
+ (0, errorHelpers_1.assert)(_this._registration !== undefined, errorHelpers_1.ServiceWorkerErrorCode.UndefinedRegistration);
135
113
  _this._registration.pushManager.getSubscription().then(function (subscription) {
136
114
  if (subscription) {
137
115
  _this._subscription = subscription;
@@ -156,8 +134,8 @@ var ServiceWorkerClass = /** @class */ (function () {
156
134
  });
157
135
  }
158
136
  else {
159
- return reject(new Errors_1.AmplifyError({
160
- name: Constants_1.SERVICE_WORKER_EXCEPTION,
137
+ return reject(new errors_1.AmplifyError({
138
+ name: errorHelpers_1.ServiceWorkerErrorCode.Unavailable,
161
139
  message: 'Service Worker not available',
162
140
  }));
163
141
  }
@@ -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,25 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var _a;
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.assert = exports.ServiceWorkerErrorCode = void 0;
7
+ var errors_1 = require("../errors");
8
+ var ServiceWorkerErrorCode;
9
+ (function (ServiceWorkerErrorCode) {
10
+ ServiceWorkerErrorCode["UndefinedInstance"] = "UndefinedInstance";
11
+ ServiceWorkerErrorCode["UndefinedRegistration"] = "UndefinedRegistration";
12
+ ServiceWorkerErrorCode["Unavailable"] = "Unavailable";
13
+ })(ServiceWorkerErrorCode = exports.ServiceWorkerErrorCode || (exports.ServiceWorkerErrorCode = {}));
14
+ var serviceWorkerErrorMap = (_a = {},
15
+ _a[ServiceWorkerErrorCode.UndefinedInstance] = {
16
+ message: 'Service Worker instance is undefined.',
17
+ },
18
+ _a[ServiceWorkerErrorCode.UndefinedRegistration] = {
19
+ message: 'Service Worker registration is undefined.',
20
+ },
21
+ _a[ServiceWorkerErrorCode.Unavailable] = {
22
+ message: 'Service Worker not available.',
23
+ },
24
+ _a);
25
+ exports.assert = (0, errors_1.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";
@@ -2,7 +2,7 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.NO_HUBCALLBACK_PROVIDED_EXCEPTION = exports.APPLICATION_ID_EXCEPTION = exports.STORAGE_CACHE_EXCEPTION = exports.SERVICE_WORKER_EXCEPTION = exports.I18N_EXCEPTION = exports.CACHE_LIST_EXCEPTION = exports.AUTH_CONFING_EXCEPTION = exports.USER_AGENT_HEADER = exports.INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER = exports.RETRY_ERROR_CODES = exports.NO_CREDS_ERROR_STRING = exports.AWS_CLOUDWATCH_CATEGORY = void 0;
5
+ exports.NO_HUBCALLBACK_PROVIDED_EXCEPTION = exports.USER_AGENT_HEADER = exports.INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER = exports.RETRY_ERROR_CODES = exports.NO_CREDS_ERROR_STRING = exports.AWS_CLOUDWATCH_CATEGORY = void 0;
6
6
  // Logging constants
7
7
  exports.AWS_CLOUDWATCH_CATEGORY = 'Logging';
8
8
  exports.NO_CREDS_ERROR_STRING = 'No credentials';
@@ -20,10 +20,4 @@ exports.INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER = hasSymbol
20
20
  : '@@INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER';
21
21
  exports.USER_AGENT_HEADER = 'x-amz-user-agent';
22
22
  // Error exception code constants
23
- exports.AUTH_CONFING_EXCEPTION = 'AuthConfigException';
24
- exports.CACHE_LIST_EXCEPTION = 'CacheListException';
25
- exports.I18N_EXCEPTION = 'I18NException';
26
- exports.SERVICE_WORKER_EXCEPTION = 'ServiceWorkerException';
27
- exports.STORAGE_CACHE_EXCEPTION = 'StorageCacheException';
28
- exports.APPLICATION_ID_EXCEPTION = 'ApplicationIdException';
29
23
  exports.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;
@@ -18,7 +18,7 @@ var __extends = (this && this.__extends) || (function () {
18
18
  })();
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.AmplifyServerContextError = void 0;
21
- var libraryUtils_1 = require("../../libraryUtils");
21
+ var errors_1 = require("../../errors");
22
22
  var AmplifyServerContextError = /** @class */ (function (_super) {
23
23
  __extends(AmplifyServerContextError, _super);
24
24
  function AmplifyServerContextError(_a) {
@@ -31,5 +31,5 @@ var AmplifyServerContextError = /** @class */ (function (_super) {
31
31
  }) || this;
32
32
  }
33
33
  return AmplifyServerContextError;
34
- }(libraryUtils_1.AmplifyError));
34
+ }(errors_1.AmplifyError));
35
35
  exports.AmplifyServerContextError = AmplifyServerContextError;
@@ -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;
@@ -17,20 +17,7 @@ var __extends = (this && this.__extends) || (function () {
17
17
  };
18
18
  })();
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.PlatformNotSupportedError = exports.AmplifyError = exports.AmplifyErrorString = exports.invalidParameter = exports.missingConfig = void 0;
21
- function missingConfig(name) {
22
- return new Error('Missing config value of ' + name);
23
- }
24
- exports.missingConfig = missingConfig;
25
- function invalidParameter(name) {
26
- return new Error('Invalid parameter value of ' + name);
27
- }
28
- exports.invalidParameter = invalidParameter;
29
- var AmplifyErrorString;
30
- (function (AmplifyErrorString) {
31
- AmplifyErrorString["UNKNOWN"] = "UnknownError";
32
- AmplifyErrorString["PLATFORM_NOT_SUPPORTED_ERROR"] = "PlatformNotSupportedError";
33
- })(AmplifyErrorString = exports.AmplifyErrorString || (exports.AmplifyErrorString = {}));
20
+ exports.AmplifyError = void 0;
34
21
  var AmplifyError = /** @class */ (function (_super) {
35
22
  __extends(AmplifyError, _super);
36
23
  /**
@@ -56,7 +43,3 @@ var AmplifyError = /** @class */ (function (_super) {
56
43
  return AmplifyError;
57
44
  }(Error));
58
45
  exports.AmplifyError = AmplifyError;
59
- exports.PlatformNotSupportedError = new AmplifyError({
60
- name: AmplifyErrorString.PLATFORM_NOT_SUPPORTED_ERROR,
61
- message: 'Function not supported on current platform',
62
- });
@@ -0,0 +1,4 @@
1
+ import { AmplifyError } from './AmplifyError';
2
+ export declare class PlatformNotSupportedError extends AmplifyError {
3
+ constructor();
4
+ }