@aws-amplify/core 5.8.2 → 6.0.1-console-preview.f63250a.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 (300) hide show
  1. package/README.md +3 -0
  2. package/lib/Amplify.d.ts +18 -17
  3. package/lib/Amplify.js +9 -0
  4. package/lib/AwsClients/CognitoIdentity/base.d.ts +3 -10
  5. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +3 -17
  6. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +8 -8
  7. package/lib/AwsClients/CognitoIdentity/getId.d.ts +3 -17
  8. package/lib/AwsClients/Pinpoint/base.d.ts +2 -10
  9. package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +3 -17
  10. package/lib/AwsClients/Pinpoint/getInAppMessages.js +1 -1
  11. package/lib/AwsClients/Pinpoint/putEvents.d.ts +3 -17
  12. package/lib/AwsClients/Pinpoint/putEvents.js +6 -0
  13. package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +3 -17
  14. package/lib/AwsClients/Pinpoint/updateEndpoint.js +2 -2
  15. package/lib/Cache/AsyncStorageCache.d.ts +154 -0
  16. package/lib/Cache/AsyncStorageCache.js +744 -0
  17. package/lib/Cache/BrowserStorageCache.d.ts +166 -0
  18. package/lib/Cache/BrowserStorageCache.js +469 -0
  19. package/lib/Cache/InMemoryCache.d.ts +129 -0
  20. package/lib/Cache/InMemoryCache.js +349 -0
  21. package/lib/Cache/StorageCache.d.ts +39 -0
  22. package/lib/Cache/StorageCache.js +121 -0
  23. package/lib/Cache/Utils/CacheList.d.ts +89 -0
  24. package/lib/Cache/Utils/CacheList.js +196 -0
  25. package/lib/Cache/Utils/CacheUtils.d.ts +25 -0
  26. package/lib/Cache/Utils/CacheUtils.js +88 -0
  27. package/lib/Cache/Utils/index.d.ts +2 -0
  28. package/lib/Cache/Utils/index.js +16 -0
  29. package/lib/Cache/reactnative.d.ts +3 -0
  30. package/lib/Cache/reactnative.js +8 -0
  31. package/lib/Cache/types/Cache.d.ts +55 -0
  32. package/lib/Cache/types/Cache.js +4 -0
  33. package/lib/Cache/types/index.d.ts +1 -0
  34. package/lib/Cache/types/index.js +19 -0
  35. package/lib/ClientDevice/android.js +3 -2
  36. package/lib/ClientDevice/ios.d.ts +2 -2
  37. package/lib/ClientDevice/ios.js +3 -2
  38. package/lib/ClientDevice/reactnative.js +3 -2
  39. package/lib/Credentials.d.ts +1 -1
  40. package/lib/Credentials.js +2 -1
  41. package/lib/Errors.d.ts +19 -0
  42. package/lib/Errors.js +50 -1
  43. package/lib/Hub.js +1 -0
  44. package/lib/I18n/I18n.d.ts +29 -9
  45. package/lib/I18n/I18n.js +30 -5
  46. package/lib/I18n/index.d.ts +18 -5
  47. package/lib/I18n/index.js +35 -5
  48. package/lib/I18n/types.d.ts +4 -1
  49. package/lib/I18n/types.js +3 -0
  50. package/lib/JS.d.ts +6 -6
  51. package/lib/Logger/ConsoleLogger.d.ts +11 -11
  52. package/lib/OAuthHelper/GoogleOAuth.js +2 -1
  53. package/lib/Platform/detectFramework.js +2 -1
  54. package/lib/Platform/detection/Next.d.ts +1 -1
  55. package/lib/Platform/detection/React.js +1 -0
  56. package/lib/Platform/version.d.ts +1 -1
  57. package/lib/Platform/version.js +1 -1
  58. package/lib/Providers/AWSCloudWatchProvider.d.ts +2 -2
  59. package/lib/Providers/AWSCloudWatchProvider.js +35 -12
  60. package/lib/RNComponents/index.d.ts +1 -1
  61. package/lib/RNComponents/reactnative.js +3 -2
  62. package/lib/ServiceWorker/ServiceWorker.d.ts +4 -4
  63. package/lib/ServiceWorker/ServiceWorker.js +37 -11
  64. package/lib/Signer.d.ts +14 -1
  65. package/lib/StorageHelper/cookieStorage.d.ts +13 -0
  66. package/lib/StorageHelper/cookieStorage.js +167 -0
  67. package/lib/StorageHelper/inMemoryStorage.d.ts +10 -0
  68. package/lib/StorageHelper/inMemoryStorage.js +82 -0
  69. package/lib/StorageHelper/index.d.ts +7 -3
  70. package/lib/StorageHelper/index.js +9 -1
  71. package/lib/StorageHelper/localStorage.d.ts +32 -0
  72. package/lib/StorageHelper/localStorage.js +114 -0
  73. package/lib/StorageHelper/reactnative.d.ts +71 -1
  74. package/lib/StorageHelper/reactnative.js +154 -10
  75. package/lib/StorageHelper/sessionStorage.d.ts +32 -0
  76. package/lib/StorageHelper/sessionStorage.js +114 -0
  77. package/lib/UniversalStorage/index.d.ts +2 -2
  78. package/lib/Util/BackgroundProcessManager.d.ts +2 -2
  79. package/lib/Util/BackgroundProcessManager.js +1 -0
  80. package/lib/Util/DateUtils.d.ts +12 -1
  81. package/lib/Util/Reachability.js +7 -5
  82. package/lib/Util/Reachability.native.d.ts +3 -2
  83. package/lib/Util/StringUtils.js +3 -10
  84. package/lib/Util/errors/AssertError.d.ts +2 -0
  85. package/lib/Util/errors/AssertError.js +11 -0
  86. package/lib/clients/middleware/retry/defaultRetryDecider.d.ts +1 -1
  87. package/lib/clients/middleware/retry/defaultRetryDecider.js +17 -13
  88. package/lib/clients/middleware/retry/isClockSkewError.js +1 -1
  89. package/lib/clients/middleware/retry/middleware.d.ts +1 -1
  90. package/lib/clients/middleware/retry/middleware.js +13 -13
  91. package/lib/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +1 -1
  92. package/lib/clients/serde/responseInfo.js +1 -1
  93. package/lib/clients/types/aws.d.ts +4 -0
  94. package/lib/clients/types/index.d.ts +1 -1
  95. package/lib/constants.d.ts +7 -0
  96. package/lib/constants.js +9 -1
  97. package/lib/index.d.ts +18 -4
  98. package/lib/index.js +32 -5
  99. package/lib/parseAWSExports.d.ts +1 -1
  100. package/lib/singleton/Auth/index.d.ts +30 -0
  101. package/lib/singleton/Auth/index.js +133 -0
  102. package/lib/singleton/Auth/types.d.ts +95 -0
  103. package/lib/singleton/Auth/types.js +6 -0
  104. package/lib/singleton/Auth/utils/index.d.ts +5 -0
  105. package/lib/singleton/Auth/utils/index.js +52 -0
  106. package/lib/singleton/Storage/types.d.ts +14 -0
  107. package/lib/singleton/Storage/types.js +4 -0
  108. package/lib/singleton/index.d.ts +46 -0
  109. package/lib/singleton/index.js +147 -0
  110. package/lib/singleton/types.d.ts +21 -0
  111. package/lib/singleton/types.js +4 -0
  112. package/lib/tsconfig.tsbuildinfo +1 -1
  113. package/lib/types/types.d.ts +31 -1
  114. package/lib/types/types.js +2 -0
  115. package/lib-esm/Amplify.d.ts +18 -17
  116. package/lib-esm/Amplify.js +9 -0
  117. package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +3 -10
  118. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +3 -17
  119. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +8 -8
  120. package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +3 -17
  121. package/lib-esm/AwsClients/Pinpoint/base.d.ts +2 -10
  122. package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +3 -17
  123. package/lib-esm/AwsClients/Pinpoint/getInAppMessages.js +1 -1
  124. package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +3 -17
  125. package/lib-esm/AwsClients/Pinpoint/putEvents.js +6 -0
  126. package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +3 -17
  127. package/lib-esm/AwsClients/Pinpoint/updateEndpoint.js +2 -2
  128. package/lib-esm/Cache/AsyncStorageCache.d.ts +154 -0
  129. package/lib-esm/Cache/AsyncStorageCache.js +737 -0
  130. package/lib-esm/Cache/BrowserStorageCache.d.ts +166 -0
  131. package/lib-esm/Cache/BrowserStorageCache.js +466 -0
  132. package/lib-esm/Cache/InMemoryCache.d.ts +129 -0
  133. package/lib-esm/Cache/InMemoryCache.js +346 -0
  134. package/lib-esm/Cache/StorageCache.d.ts +39 -0
  135. package/lib-esm/Cache/StorageCache.js +118 -0
  136. package/lib-esm/Cache/Utils/CacheList.d.ts +89 -0
  137. package/lib-esm/Cache/Utils/CacheList.js +194 -0
  138. package/lib-esm/Cache/Utils/CacheUtils.d.ts +25 -0
  139. package/lib-esm/Cache/Utils/CacheUtils.js +81 -0
  140. package/lib-esm/Cache/Utils/index.d.ts +2 -0
  141. package/lib-esm/Cache/Utils/index.js +4 -0
  142. package/lib-esm/Cache/reactnative.d.ts +3 -0
  143. package/lib-esm/Cache/reactnative.js +6 -0
  144. package/lib-esm/Cache/types/Cache.d.ts +55 -0
  145. package/lib-esm/Cache/types/Cache.js +3 -0
  146. package/lib-esm/Cache/types/index.d.ts +1 -0
  147. package/lib-esm/Cache/types/index.js +3 -0
  148. package/lib-esm/ClientDevice/android.js +1 -0
  149. package/lib-esm/ClientDevice/ios.d.ts +2 -2
  150. package/lib-esm/ClientDevice/ios.js +1 -0
  151. package/lib-esm/ClientDevice/reactnative.js +1 -0
  152. package/lib-esm/Credentials.d.ts +1 -1
  153. package/lib-esm/Credentials.js +2 -1
  154. package/lib-esm/Errors.d.ts +19 -0
  155. package/lib-esm/Errors.js +49 -0
  156. package/lib-esm/Hub.js +1 -0
  157. package/lib-esm/I18n/I18n.d.ts +29 -9
  158. package/lib-esm/I18n/I18n.js +30 -5
  159. package/lib-esm/I18n/index.d.ts +18 -5
  160. package/lib-esm/I18n/index.js +35 -5
  161. package/lib-esm/I18n/types.d.ts +4 -1
  162. package/lib-esm/I18n/types.js +3 -0
  163. package/lib-esm/JS.d.ts +6 -6
  164. package/lib-esm/Logger/ConsoleLogger.d.ts +11 -11
  165. package/lib-esm/OAuthHelper/GoogleOAuth.js +2 -1
  166. package/lib-esm/Platform/detectFramework.js +2 -1
  167. package/lib-esm/Platform/detection/Next.d.ts +1 -1
  168. package/lib-esm/Platform/detection/React.js +1 -0
  169. package/lib-esm/Platform/version.d.ts +1 -1
  170. package/lib-esm/Platform/version.js +1 -1
  171. package/lib-esm/Providers/AWSCloudWatchProvider.d.ts +2 -2
  172. package/lib-esm/Providers/AWSCloudWatchProvider.js +33 -10
  173. package/lib-esm/RNComponents/index.d.ts +1 -1
  174. package/lib-esm/RNComponents/reactnative.js +1 -0
  175. package/lib-esm/ServiceWorker/ServiceWorker.d.ts +4 -4
  176. package/lib-esm/ServiceWorker/ServiceWorker.js +37 -11
  177. package/lib-esm/Signer.d.ts +14 -1
  178. package/lib-esm/StorageHelper/cookieStorage.d.ts +13 -0
  179. package/lib-esm/StorageHelper/cookieStorage.js +141 -0
  180. package/lib-esm/StorageHelper/inMemoryStorage.d.ts +10 -0
  181. package/lib-esm/StorageHelper/inMemoryStorage.js +79 -0
  182. package/lib-esm/StorageHelper/index.d.ts +7 -3
  183. package/lib-esm/StorageHelper/index.js +4 -0
  184. package/lib-esm/StorageHelper/localStorage.d.ts +32 -0
  185. package/lib-esm/StorageHelper/localStorage.js +111 -0
  186. package/lib-esm/StorageHelper/reactnative.d.ts +71 -1
  187. package/lib-esm/StorageHelper/reactnative.js +153 -9
  188. package/lib-esm/StorageHelper/sessionStorage.d.ts +32 -0
  189. package/lib-esm/StorageHelper/sessionStorage.js +111 -0
  190. package/lib-esm/UniversalStorage/index.d.ts +2 -2
  191. package/lib-esm/Util/BackgroundProcessManager.d.ts +2 -2
  192. package/lib-esm/Util/BackgroundProcessManager.js +1 -0
  193. package/lib-esm/Util/DateUtils.d.ts +12 -1
  194. package/lib-esm/Util/Reachability.js +5 -3
  195. package/lib-esm/Util/Reachability.native.d.ts +3 -2
  196. package/lib-esm/Util/StringUtils.js +3 -10
  197. package/lib-esm/Util/errors/AssertError.d.ts +2 -0
  198. package/lib-esm/Util/errors/AssertError.js +7 -0
  199. package/lib-esm/clients/middleware/retry/defaultRetryDecider.d.ts +1 -1
  200. package/lib-esm/clients/middleware/retry/defaultRetryDecider.js +17 -13
  201. package/lib-esm/clients/middleware/retry/isClockSkewError.js +1 -1
  202. package/lib-esm/clients/middleware/retry/middleware.d.ts +1 -1
  203. package/lib-esm/clients/middleware/retry/middleware.js +13 -13
  204. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +1 -1
  205. package/lib-esm/clients/serde/responseInfo.js +1 -1
  206. package/lib-esm/clients/types/aws.d.ts +4 -0
  207. package/lib-esm/clients/types/index.d.ts +1 -1
  208. package/lib-esm/constants.d.ts +7 -0
  209. package/lib-esm/constants.js +8 -0
  210. package/lib-esm/index.d.ts +18 -4
  211. package/lib-esm/index.js +15 -3
  212. package/lib-esm/parseAWSExports.d.ts +1 -1
  213. package/lib-esm/singleton/Auth/index.d.ts +30 -0
  214. package/lib-esm/singleton/Auth/index.js +129 -0
  215. package/lib-esm/singleton/Auth/types.d.ts +95 -0
  216. package/lib-esm/singleton/Auth/types.js +5 -0
  217. package/lib-esm/singleton/Auth/utils/index.d.ts +5 -0
  218. package/lib-esm/singleton/Auth/utils/index.js +45 -0
  219. package/lib-esm/singleton/Storage/types.d.ts +14 -0
  220. package/lib-esm/singleton/Storage/types.js +3 -0
  221. package/lib-esm/singleton/index.d.ts +46 -0
  222. package/lib-esm/singleton/index.js +143 -0
  223. package/lib-esm/singleton/types.d.ts +21 -0
  224. package/lib-esm/singleton/types.js +3 -0
  225. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  226. package/lib-esm/types/types.d.ts +31 -1
  227. package/lib-esm/types/types.js +2 -0
  228. package/package.json +38 -15
  229. package/src/Amplify.ts +9 -3
  230. package/src/AwsClients/CognitoIdentity/base.ts +2 -1
  231. package/src/AwsClients/CognitoIdentity/getCredentialsForIdentity.ts +13 -6
  232. package/src/AwsClients/Pinpoint/base.ts +6 -2
  233. package/src/AwsClients/Pinpoint/getInAppMessages.ts +1 -1
  234. package/src/AwsClients/Pinpoint/putEvents.ts +6 -0
  235. package/src/AwsClients/Pinpoint/updateEndpoint.ts +2 -2
  236. package/src/Cache/AsyncStorageCache.ts +500 -0
  237. package/src/Cache/BrowserStorageCache.ts +517 -0
  238. package/src/Cache/CHANGELOG.md +1227 -0
  239. package/src/Cache/InMemoryCache.ts +354 -0
  240. package/src/Cache/StorageCache.ts +157 -0
  241. package/src/Cache/Utils/CacheList.ts +198 -0
  242. package/src/Cache/Utils/CacheUtils.ts +92 -0
  243. package/src/Cache/Utils/index.ts +11 -0
  244. package/src/Cache/reactnative.ts +9 -0
  245. package/src/Cache/types/Cache.ts +75 -0
  246. package/src/Cache/types/index.ts +4 -0
  247. package/src/ClientDevice/android.ts +1 -1
  248. package/src/ClientDevice/ios.ts +2 -2
  249. package/src/ClientDevice/reactnative.ts +1 -1
  250. package/src/Credentials.ts +19 -17
  251. package/src/Errors.ts +41 -0
  252. package/src/Hub.ts +1 -0
  253. package/src/I18n/I18n.ts +40 -12
  254. package/src/I18n/index.ts +45 -12
  255. package/src/I18n/types.ts +3 -0
  256. package/src/JS.ts +24 -17
  257. package/src/Logger/ConsoleLogger.ts +10 -10
  258. package/src/OAuthHelper/FacebookOAuth.ts +2 -2
  259. package/src/OAuthHelper/GoogleOAuth.ts +9 -6
  260. package/src/Platform/detectFramework.ts +1 -1
  261. package/src/Platform/detection/React.ts +5 -3
  262. package/src/Platform/version.ts +1 -1
  263. package/src/Providers/AWSCloudWatchProvider.ts +39 -14
  264. package/src/RNComponents/index.ts +1 -1
  265. package/src/RNComponents/reactnative.ts +1 -1
  266. package/src/ServiceWorker/ServiceWorker.ts +58 -18
  267. package/src/Signer.ts +22 -3
  268. package/src/StorageHelper/cookieStorage.ts +99 -0
  269. package/src/StorageHelper/inMemoryStorage.ts +32 -0
  270. package/src/StorageHelper/index.ts +6 -1
  271. package/src/StorageHelper/localStorage.ts +60 -0
  272. package/src/StorageHelper/reactnative.ts +94 -14
  273. package/src/StorageHelper/sessionStorage.ts +60 -0
  274. package/src/Util/BackgroundProcessManager.ts +33 -9
  275. package/src/Util/DateUtils.ts +14 -5
  276. package/src/Util/Reachability.native.ts +3 -2
  277. package/src/Util/Reachability.ts +9 -7
  278. package/src/Util/Retry.ts +2 -1
  279. package/src/Util/StringUtils.ts +3 -10
  280. package/src/Util/errors/AssertError.ts +11 -0
  281. package/src/clients/handlers/fetch.ts +2 -2
  282. package/src/clients/middleware/retry/defaultRetryDecider.ts +12 -6
  283. package/src/clients/middleware/retry/isClockSkewError.ts +1 -1
  284. package/src/clients/middleware/retry/middleware.ts +9 -9
  285. package/src/clients/middleware/signing/middleware.ts +1 -1
  286. package/src/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.ts +1 -1
  287. package/src/clients/serde/responseInfo.ts +2 -1
  288. package/src/clients/types/aws.ts +10 -0
  289. package/src/clients/types/index.ts +1 -0
  290. package/src/constants.ts +16 -0
  291. package/src/global.d.ts +11 -0
  292. package/src/index.ts +66 -4
  293. package/src/parseAWSExports.ts +1 -1
  294. package/src/singleton/Auth/index.ts +113 -0
  295. package/src/singleton/Auth/types.ts +129 -0
  296. package/src/singleton/Auth/utils/index.ts +68 -0
  297. package/src/singleton/Storage/types.ts +21 -0
  298. package/src/singleton/index.ts +131 -0
  299. package/src/singleton/types.ts +48 -0
  300. package/src/types/types.ts +38 -1
@@ -43,20 +43,21 @@ import { isClockSkewError } from './isClockSkewError';
43
43
  */
44
44
  export var getRetryDecider = function (errorParser) {
45
45
  return function (response, error) { return __awaiter(void 0, void 0, void 0, function () {
46
- var errorCode, _a, statusCode;
47
- var _b;
48
- return __generator(this, function (_c) {
49
- switch (_c.label) {
46
+ var parsedError, _a, errorCode, statusCode;
47
+ var _b, _c;
48
+ return __generator(this, function (_d) {
49
+ switch (_d.label) {
50
50
  case 0:
51
- if (!(error !== null && error !== void 0)) return [3 /*break*/, 1];
52
- _a = error;
51
+ if (!((_b = error) !== null && _b !== void 0)) return [3 /*break*/, 1];
52
+ _a = _b;
53
53
  return [3 /*break*/, 3];
54
54
  case 1: return [4 /*yield*/, errorParser(response)];
55
55
  case 2:
56
- _a = (_c.sent());
57
- _c.label = 3;
56
+ _a = (_d.sent());
57
+ _d.label = 3;
58
58
  case 3:
59
- errorCode = ((_b = _a) !== null && _b !== void 0 ? _b : {}).name;
59
+ parsedError = (_c = _a) !== null && _c !== void 0 ? _c : undefined;
60
+ errorCode = parsedError === null || parsedError === void 0 ? void 0 : parsedError['code'];
60
61
  statusCode = response === null || response === void 0 ? void 0 : response.statusCode;
61
62
  return [2 /*return*/, (isConnectionError(error) ||
62
63
  isThrottlingError(statusCode, errorCode) ||
@@ -88,10 +89,13 @@ var TIMEOUT_ERROR_CODES = [
88
89
  'RequestTimeoutException',
89
90
  ];
90
91
  var isThrottlingError = function (statusCode, errorCode) {
91
- return statusCode === 429 || THROTTLING_ERROR_CODES.includes(errorCode);
92
+ return statusCode === 429 ||
93
+ (!!errorCode && THROTTLING_ERROR_CODES.includes(errorCode));
94
+ };
95
+ var isConnectionError = function (error) {
96
+ return (error === null || error === void 0 ? void 0 : error['name']) === 'Network error';
92
97
  };
93
- var isConnectionError = function (error) { return (error === null || error === void 0 ? void 0 : error.name) === 'Network error'; };
94
98
  var isServerSideError = function (statusCode, errorCode) {
95
- return [500, 502, 503, 504].includes(statusCode) ||
96
- TIMEOUT_ERROR_CODES.includes(errorCode);
99
+ return (!!statusCode && [500, 502, 503, 504].includes(statusCode)) ||
100
+ (!!errorCode && TIMEOUT_ERROR_CODES.includes(errorCode));
97
101
  };
@@ -19,5 +19,5 @@ var CLOCK_SKEW_ERROR_CODES = [
19
19
  * @internal
20
20
  */
21
21
  export var isClockSkewError = function (errorCode) {
22
- return CLOCK_SKEW_ERROR_CODES.includes(errorCode);
22
+ return !!errorCode && CLOCK_SKEW_ERROR_CODES.includes(errorCode);
23
23
  };
@@ -30,4 +30,4 @@ export interface RetryOptions<TResponse = Response> {
30
30
  /**
31
31
  * Retry middleware
32
32
  */
33
- export declare const retryMiddleware: <TInput = Request, TOutput = Response>({ maxAttempts, retryDecider, computeDelay, abortSignal, }: RetryOptions<TOutput>) => (next: MiddlewareHandler<TInput, TOutput>, context: MiddlewareContext) => (request: TInput) => Promise<TOutput>;
33
+ export declare const retryMiddleware: <TInput = Request, TOutput = Response>({ maxAttempts, retryDecider, computeDelay, abortSignal, }: RetryOptions<TOutput>) => (next: MiddlewareHandler<TInput, TOutput>, context: MiddlewareContext) => (request: TInput) => Promise<NonNullable<TOutput>>;
@@ -58,11 +58,11 @@ export var retryMiddleware = function (_a) {
58
58
  }
59
59
  return function (next, context) {
60
60
  return function retryMiddleware(request) {
61
- var _a;
61
+ var _a, _b, _c;
62
62
  return __awaiter(this, void 0, void 0, function () {
63
63
  var error, attemptsCount, response, handleTerminalErrorOrResponse, e_1, delay;
64
- return __generator(this, function (_b) {
65
- switch (_b.label) {
64
+ return __generator(this, function (_d) {
65
+ switch (_d.label) {
66
66
  case 0:
67
67
  attemptsCount = (_a = context.attemptsCount) !== null && _a !== void 0 ? _a : 0;
68
68
  handleTerminalErrorOrResponse = function () {
@@ -75,38 +75,38 @@ export var retryMiddleware = function (_a) {
75
75
  throw error;
76
76
  }
77
77
  };
78
- _b.label = 1;
78
+ _d.label = 1;
79
79
  case 1:
80
80
  if (!(!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) && attemptsCount < maxAttempts)) return [3 /*break*/, 11];
81
- _b.label = 2;
81
+ _d.label = 2;
82
82
  case 2:
83
- _b.trys.push([2, 4, , 5]);
83
+ _d.trys.push([2, 4, , 5]);
84
84
  return [4 /*yield*/, next(request)];
85
85
  case 3:
86
- response = _b.sent();
86
+ response = _d.sent();
87
87
  error = undefined;
88
88
  return [3 /*break*/, 5];
89
89
  case 4:
90
- e_1 = _b.sent();
90
+ e_1 = _d.sent();
91
91
  error = e_1;
92
92
  response = undefined;
93
93
  return [3 /*break*/, 5];
94
94
  case 5:
95
95
  // context.attemptsCount may be updated after calling next handler which may retry the request by itself.
96
96
  attemptsCount =
97
- context.attemptsCount > attemptsCount
98
- ? context.attemptsCount
97
+ ((_b = context.attemptsCount) !== null && _b !== void 0 ? _b : 0) > attemptsCount
98
+ ? (_c = context.attemptsCount) !== null && _c !== void 0 ? _c : 0
99
99
  : attemptsCount + 1;
100
100
  context.attemptsCount = attemptsCount;
101
101
  return [4 /*yield*/, retryDecider(response, error)];
102
102
  case 6:
103
- if (!_b.sent()) return [3 /*break*/, 9];
103
+ if (!_d.sent()) return [3 /*break*/, 9];
104
104
  if (!(!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) && attemptsCount < maxAttempts)) return [3 /*break*/, 8];
105
105
  delay = computeDelay(attemptsCount);
106
106
  return [4 /*yield*/, cancellableSleep(delay, abortSignal)];
107
107
  case 7:
108
- _b.sent();
109
- _b.label = 8;
108
+ _d.sent();
109
+ _d.label = 8;
110
110
  case 8: return [3 /*break*/, 1];
111
111
  case 9: return [2 /*return*/, handleTerminalErrorOrResponse()];
112
112
  case 10: return [3 /*break*/, 1];
@@ -11,7 +11,7 @@ import { toHex } from '@aws-sdk/util-hex-encoding';
11
11
  * @returns `Uint8Array` created from the data as input to a hash function.
12
12
  */
13
13
  export var getHashedData = function (key, data) {
14
- var sha256 = new Sha256(key);
14
+ var sha256 = new Sha256(key !== null && key !== void 0 ? key : undefined);
15
15
  sha256.update(data);
16
16
  // TODO: V6 flip to async digest
17
17
  var hashedData = sha256.digestSync();
@@ -17,5 +17,5 @@ export var parseMetadata = function (response) {
17
17
  return __assign(__assign({}, (isMetadataBearer(response) ? response.$metadata : {})), { httpStatusCode: statusCode, requestId: (_b = (_a = headers['x-amzn-requestid']) !== null && _a !== void 0 ? _a : headers['x-amzn-request-id']) !== null && _b !== void 0 ? _b : headers['x-amz-request-id'], extendedRequestId: headers['x-amz-id-2'], cfId: headers['x-amz-cf-id'] });
18
18
  };
19
19
  var isMetadataBearer = function (response) {
20
- return typeof (response === null || response === void 0 ? void 0 : response['$metadata']) === 'object';
20
+ return typeof (response === null || response === void 0 ? void 0 : response.$metadata) === 'object';
21
21
  };
@@ -18,3 +18,7 @@ export interface ServiceClientOptions {
18
18
  * This function is protocol-specific (e.g. JSON, XML, etc.)
19
19
  */
20
20
  export type ErrorParser = (response?: HttpResponse) => Promise<(Error & MetadataBearer) | undefined>;
21
+ /**
22
+ * Default config options for the `composeServiceApi`.
23
+ */
24
+ export type DefaultConfigOptions<TransferHandlerOptions extends Record<string, unknown> = Record<string, unknown>> = Partial<TransferHandlerOptions & ServiceClientOptions>;
@@ -1,3 +1,3 @@
1
1
  export { Middleware, MiddlewareHandler, Request, Response, TransferHandler, Endpoint, } from './core';
2
2
  export { Headers, HttpRequest, HttpResponse, HttpTransferHandler, HttpTransferOptions, ResponseBodyMixin, } from './http';
3
- export { Credentials, EndpointResolverOptions, ErrorParser, ServiceClientOptions, } from './aws';
3
+ export { Credentials, EndpointResolverOptions, ErrorParser, ServiceClientOptions, DefaultConfigOptions, } from './aws';
@@ -1,2 +1,9 @@
1
1
  export declare const INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER: string | symbol;
2
2
  export declare const USER_AGENT_HEADER = "x-amz-user-agent";
3
+ export declare const AUTH_CONFING_EXCEPTION = "AuthConfigException";
4
+ export declare const AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION = "AWSCloudWatchProviderOptionsException";
5
+ export declare const CACHE_LIST_EXCEPTION = "CacheListException";
6
+ export declare const I18N_EXCEPTION = "I18NException";
7
+ export declare const SERVICE_WORKER_EXCEPTION = "ServiceWorkerException";
8
+ export declare const STORAGE_CACHE_EXCEPTION = "StorageCacheException";
9
+ export declare const APPLICATION_ID_EXCEPTION = "ApplicationIdException";
@@ -9,3 +9,11 @@ export var INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER = hasSymbol
9
9
  ? Symbol.for('INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER')
10
10
  : '@@INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER';
11
11
  export var USER_AGENT_HEADER = 'x-amz-user-agent';
12
+ // Error exception code constants
13
+ export var AUTH_CONFING_EXCEPTION = 'AuthConfigException';
14
+ export var AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION = 'AWSCloudWatchProviderOptionsException';
15
+ export var CACHE_LIST_EXCEPTION = 'CacheListException';
16
+ export var I18N_EXCEPTION = 'I18NException';
17
+ export var SERVICE_WORKER_EXCEPTION = 'ServiceWorkerException';
18
+ export var STORAGE_CACHE_EXCEPTION = 'StorageCacheException';
19
+ export var APPLICATION_ID_EXCEPTION = 'ApplicationIdException';
@@ -1,9 +1,9 @@
1
1
  import { Amplify } from './Amplify';
2
- export { Amplify } from './Amplify';
2
+ export { Amplify };
3
3
  export { AmplifyClass } from './Amplify';
4
4
  export { ClientDevice } from './ClientDevice';
5
5
  export { ConsoleLogger, ConsoleLogger as Logger } from './Logger';
6
- export { invalidParameter, missingConfig } from './Errors';
6
+ export { invalidParameter, missingConfig, AmplifyError, AmplifyErrorString, } from './Errors';
7
7
  export { Hub, HubCapsule, HubCallback, HubPayload } from './Hub';
8
8
  export { I18n } from './I18n';
9
9
  export { browserOrNode, filenameToContentType, generateRandomString, isEmpty, isStrictObject, isTextFile, isWebWorker, makeQuerablePromise, objectLessAttributes, sortByField, transferKeyToLowerCase, transferKeyToUpperCase, } from './JS';
@@ -14,8 +14,8 @@ export { FacebookOAuth, GoogleOAuth } from './OAuthHelper';
14
14
  export { AppState, AsyncStorage, Linking } from './RNComponents';
15
15
  export { Credentials, CredentialsClass } from './Credentials';
16
16
  export { ServiceWorker } from './ServiceWorker';
17
- export { ICredentials } from './types';
18
- export { StorageHelper, MemoryStorage } from './StorageHelper';
17
+ export { ICredentials, ErrorParams, AmplifyErrorMap, ServiceError, KeyValueStorageInterface, } from './types';
18
+ export { StorageHelper, MemoryStorage, LocalStorage, CookieStorage, SessionStorage, MemoryKeyValueStorage, } from './StorageHelper';
19
19
  export { UniversalStorage } from './UniversalStorage';
20
20
  export { Platform, getAmplifyUserAgentObject, getAmplifyUserAgent, } from './Platform';
21
21
  export { ApiAction, AuthAction, AnalyticsAction, Category, CustomUserAgentDetails, DataStoreAction, Framework, GeoAction, InteractionsAction, InAppMessagingAction, PredictionsAction, PubSubAction, PushNotificationAction, StorageAction, } from './Platform/types';
@@ -24,6 +24,20 @@ export declare const Constants: {
24
24
  userAgent: string;
25
25
  };
26
26
  export { AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, BackgroundManagerNotOpenError, BackgroundProcessManager, BackgroundProcessManagerState, DateUtils, Mutex, NO_CREDS_ERROR_STRING, NonRetryableError, RETRY_ERROR_CODES, Reachability, isNonRetryableError, jitteredBackoff, jitteredExponentialRetry, retry, urlSafeDecode, urlSafeEncode, } from './Util';
27
+ import { BrowserStorageCache } from './Cache/BrowserStorageCache';
28
+ export { asserts } from './Util/errors/AssertError';
29
+ export { isTokenExpired } from './singleton/Auth';
30
+ export { InMemoryCache } from './Cache/InMemoryCache';
31
+ export { CacheConfig } from './Cache/types';
32
+ export { ICache } from './Cache/types';
33
+ export { BrowserStorageCache };
34
+ export { BrowserStorageCache as Cache };
35
+ export { decodeJWT, assertTokenProviderConfig, assertIdentityPooIdConfig, } from './singleton/Auth/utils';
36
+ export { TokenProvider, AuthTokens, FetchAuthSessionOptions, AWSCredentialsAndIdentityIdProvider, AWSCredentialsAndIdentityId, Identity, } from './singleton/Auth/types';
37
+ export { AuthConfig, UserPoolConfig, UserPoolConfigAndIdentityPoolConfig, StorageAccessLevel, StorageConfig, GetCredentialsOptions, } from './singleton/types';
38
+ export { getCredentialsForIdentity, getId, GetCredentialsForIdentityInput, GetCredentialsForIdentityOutput, } from './AwsClients/CognitoIdentity';
39
+ export { AmplifyV6, fetchAuthSession } from './singleton';
40
+ export { LibraryOptions, ResourcesConfig } from './singleton/types';
27
41
  /**
28
42
  * @deprecated use named import
29
43
  */
package/lib-esm/index.js CHANGED
@@ -2,11 +2,11 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Amplify } from './Amplify';
4
4
  import { Platform } from './Platform';
5
- export { Amplify } from './Amplify';
5
+ export { Amplify };
6
6
  export { AmplifyClass } from './Amplify';
7
7
  export { ClientDevice } from './ClientDevice';
8
8
  export { ConsoleLogger, ConsoleLogger as Logger } from './Logger';
9
- export { invalidParameter, missingConfig } from './Errors';
9
+ export { invalidParameter, missingConfig, AmplifyError, AmplifyErrorString, } from './Errors';
10
10
  export { Hub } from './Hub';
11
11
  export { I18n } from './I18n';
12
12
  export { browserOrNode, filenameToContentType, generateRandomString, isEmpty, isStrictObject, isTextFile, isWebWorker, makeQuerablePromise, objectLessAttributes, sortByField, transferKeyToLowerCase, transferKeyToUpperCase, } from './JS';
@@ -17,7 +17,7 @@ export { FacebookOAuth, GoogleOAuth } from './OAuthHelper';
17
17
  export { AppState, AsyncStorage, Linking } from './RNComponents';
18
18
  export { Credentials, CredentialsClass } from './Credentials';
19
19
  export { ServiceWorker } from './ServiceWorker';
20
- export { StorageHelper, MemoryStorage } from './StorageHelper';
20
+ export { StorageHelper, MemoryStorage, LocalStorage, CookieStorage, SessionStorage, MemoryKeyValueStorage, } from './StorageHelper';
21
21
  export { UniversalStorage } from './UniversalStorage';
22
22
  export { Platform, getAmplifyUserAgentObject, getAmplifyUserAgent, } from './Platform';
23
23
  export { ApiAction, AuthAction, AnalyticsAction, Category, DataStoreAction, Framework, GeoAction, InteractionsAction, InAppMessagingAction, PredictionsAction, PubSubAction, PushNotificationAction, StorageAction, } from './Platform/types';
@@ -26,6 +26,18 @@ export var Constants = {
26
26
  userAgent: Platform.userAgent,
27
27
  };
28
28
  export { AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, BackgroundManagerNotOpenError, BackgroundProcessManager, BackgroundProcessManagerState, DateUtils, Mutex, NO_CREDS_ERROR_STRING, NonRetryableError, RETRY_ERROR_CODES, Reachability, isNonRetryableError, jitteredBackoff, jitteredExponentialRetry, retry, urlSafeDecode, urlSafeEncode, } from './Util';
29
+ // Cache exports
30
+ import { BrowserStorageCache } from './Cache/BrowserStorageCache';
31
+ export { asserts } from './Util/errors/AssertError';
32
+ export { isTokenExpired } from './singleton/Auth';
33
+ export { InMemoryCache } from './Cache/InMemoryCache';
34
+ export { BrowserStorageCache };
35
+ export { BrowserStorageCache as Cache }; // Maintain interoperability with React Native
36
+ // Singleton exports
37
+ export { decodeJWT, assertTokenProviderConfig, assertIdentityPooIdConfig, } from './singleton/Auth/utils';
38
+ // AWSClients exports
39
+ export { getCredentialsForIdentity, getId, } from './AwsClients/CognitoIdentity';
40
+ export { AmplifyV6, fetchAuthSession } from './singleton';
29
41
  /**
30
42
  * @deprecated use named import
31
43
  */
@@ -1,2 +1,2 @@
1
1
  import { AmplifyConfig } from './types';
2
- export declare const parseAWSExports: (config: any) => AmplifyConfig;
2
+ export declare const parseAWSExports: (config: Record<string, any>) => AmplifyConfig;
@@ -0,0 +1,30 @@
1
+ import { Observable } from 'rxjs';
2
+ import { AuthConfig, AuthSession, FetchAuthSessionOptions, LibraryAuthOptions } from './types';
3
+ export declare function isTokenExpired({ expiresAt, clockDrift, }: {
4
+ expiresAt: number;
5
+ clockDrift: number;
6
+ }): boolean;
7
+ export declare class AuthClass {
8
+ private authSessionObservers;
9
+ private authConfig?;
10
+ private authOptions?;
11
+ constructor();
12
+ /**
13
+ * Configure Auth category
14
+ *
15
+ * @internal
16
+ *
17
+ * @param authResourcesConfig - Resources configurations required by Auth providers.
18
+ * @param authOptions - Client options used by library
19
+ *
20
+ * @returns void
21
+ */
22
+ configure(authResourcesConfig: AuthConfig, authOptions?: LibraryAuthOptions): void;
23
+ fetchAuthSession(options?: FetchAuthSessionOptions): Promise<AuthSession>;
24
+ /**
25
+ * Obtain an Observable that notifies on session changes
26
+ *
27
+ * @returns Observable<AmplifyUserSession>
28
+ */
29
+ listenSessionChanges(): Observable<AuthSession>;
30
+ }
@@ -0,0 +1,129 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
38
+ // SPDX-License-Identifier: Apache-2.0
39
+ import { Observable } from 'rxjs';
40
+ import { asserts } from '../../Util/errors/AssertError';
41
+ import { AUTH_CONFING_EXCEPTION } from '../../constants';
42
+ export function isTokenExpired(_a) {
43
+ var expiresAt = _a.expiresAt, clockDrift = _a.clockDrift;
44
+ var currentTime = Date.now();
45
+ return currentTime + clockDrift > expiresAt;
46
+ }
47
+ var AuthClass = /** @class */ (function () {
48
+ function AuthClass() {
49
+ this.authSessionObservers = new Set();
50
+ }
51
+ /**
52
+ * Configure Auth category
53
+ *
54
+ * @internal
55
+ *
56
+ * @param authResourcesConfig - Resources configurations required by Auth providers.
57
+ * @param authOptions - Client options used by library
58
+ *
59
+ * @returns void
60
+ */
61
+ AuthClass.prototype.configure = function (authResourcesConfig, authOptions) {
62
+ this.authConfig = authResourcesConfig;
63
+ this.authOptions = authOptions;
64
+ };
65
+ AuthClass.prototype.fetchAuthSession = function (options) {
66
+ var _a, _b, _c, _d, _e, _f, _g;
67
+ if (options === void 0) { options = {}; }
68
+ return __awaiter(this, void 0, void 0, function () {
69
+ var tokens, credentialsAndIdentityId;
70
+ return __generator(this, function (_h) {
71
+ switch (_h.label) {
72
+ case 0: return [4 /*yield*/, ((_b = (_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.tokenProvider) === null || _b === void 0 ? void 0 : _b.getTokens(options))];
73
+ case 1:
74
+ // Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
75
+ tokens =
76
+ (_c = (_h.sent())) !== null && _c !== void 0 ? _c : undefined;
77
+ asserts(!!this.authConfig, {
78
+ name: AUTH_CONFING_EXCEPTION,
79
+ message: 'AuthConfig is required',
80
+ recoverySuggestion: 'call Amplify.configure in your app with a valid AuthConfig',
81
+ });
82
+ if (!tokens) return [3 /*break*/, 3];
83
+ return [4 /*yield*/, ((_e = (_d = this.authOptions) === null || _d === void 0 ? void 0 : _d.credentialsProvider) === null || _e === void 0 ? void 0 : _e.getCredentialsAndIdentityId({
84
+ authConfig: this.authConfig,
85
+ tokens: tokens,
86
+ authenticated: true,
87
+ forceRefresh: options.forceRefresh,
88
+ }))];
89
+ case 2:
90
+ // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
91
+ credentialsAndIdentityId =
92
+ _h.sent();
93
+ return [3 /*break*/, 5];
94
+ case 3: return [4 /*yield*/, ((_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.credentialsProvider) === null || _g === void 0 ? void 0 : _g.getCredentialsAndIdentityId({
95
+ authConfig: this.authConfig,
96
+ authenticated: false,
97
+ forceRefresh: options.forceRefresh,
98
+ }))];
99
+ case 4:
100
+ // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
101
+ credentialsAndIdentityId =
102
+ _h.sent();
103
+ _h.label = 5;
104
+ case 5: return [2 /*return*/, {
105
+ tokens: tokens,
106
+ credentials: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.credentials,
107
+ identityId: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.identityId,
108
+ }];
109
+ }
110
+ });
111
+ });
112
+ };
113
+ /**
114
+ * Obtain an Observable that notifies on session changes
115
+ *
116
+ * @returns Observable<AmplifyUserSession>
117
+ */
118
+ AuthClass.prototype.listenSessionChanges = function () {
119
+ var _this = this;
120
+ return new Observable(function (observer) {
121
+ _this.authSessionObservers.add(observer);
122
+ return function () {
123
+ _this.authSessionObservers.delete(observer);
124
+ };
125
+ });
126
+ };
127
+ return AuthClass;
128
+ }());
129
+ export { AuthClass };
@@ -0,0 +1,95 @@
1
+ interface JwtPayloadStandardFields {
2
+ exp?: number;
3
+ iss?: string;
4
+ aud?: string | string[];
5
+ nbf?: number;
6
+ iat?: number;
7
+ scope?: string;
8
+ jti?: string;
9
+ }
10
+ /** JSON type */
11
+ type Json = null | string | number | boolean | Json[] | JsonObject;
12
+ /** JSON Object type */
13
+ type JsonObject = {
14
+ [name: string]: Json;
15
+ };
16
+ type JwtPayload = JwtPayloadStandardFields & JsonObject;
17
+ export type JWT = {
18
+ payload: JwtPayload;
19
+ toString: () => string;
20
+ };
21
+ export type JWTCreator = (stringJWT: string) => JWT;
22
+ export type AuthSession = {
23
+ tokens?: AuthTokens;
24
+ credentials?: AWSCredentials;
25
+ identityId?: string;
26
+ };
27
+ export type LibraryAuthOptions = {
28
+ tokenProvider?: TokenProvider;
29
+ credentialsProvider?: AWSCredentialsAndIdentityIdProvider;
30
+ };
31
+ export type Identity = {
32
+ id: string;
33
+ type: 'guest' | 'primary';
34
+ };
35
+ export interface AWSCredentialsAndIdentityIdProvider {
36
+ getCredentialsAndIdentityId: (getCredentialsOptions: GetCredentialsOptions) => Promise<AWSCredentialsAndIdentityId>;
37
+ clearCredentials: () => void;
38
+ }
39
+ export type TokenProvider = {
40
+ getTokens: ({ forceRefresh, }: {
41
+ forceRefresh?: boolean;
42
+ }) => Promise<AuthTokens | null>;
43
+ };
44
+ export type FetchAuthSessionOptions = {
45
+ forceRefresh?: boolean;
46
+ };
47
+ export type AuthTokens = {
48
+ idToken?: JWT;
49
+ accessToken: JWT;
50
+ };
51
+ export type AuthConfig = IdentityPoolConfig | UserPoolConfig | UserPoolConfigAndIdentityPoolConfig;
52
+ export type IdentityPoolConfig = {
53
+ identityPoolId: string;
54
+ userPoolWebClientId?: never;
55
+ userPoolId?: never;
56
+ clientMetadata?: never;
57
+ isMandatorySignInEnabled?: never;
58
+ };
59
+ export type UserPoolConfig = {
60
+ userPoolWebClientId: string;
61
+ userPoolId: string;
62
+ identityPoolId?: never;
63
+ clientMetadata?: Record<string, string>;
64
+ };
65
+ export type UserPoolConfigAndIdentityPoolConfig = {
66
+ userPoolWebClientId: string;
67
+ userPoolId: string;
68
+ identityPoolId: string;
69
+ clientMetadata?: Record<string, string>;
70
+ isMandatorySignInEnabled?: boolean;
71
+ };
72
+ export type GetCredentialsOptions = GetCredentialsAuthenticatedUser | GetCredentialsUnauthenticatedUser;
73
+ type GetCredentialsAuthenticatedUser = {
74
+ authenticated: true;
75
+ forceRefresh?: boolean;
76
+ authConfig: AuthConfig;
77
+ tokens?: AuthTokens;
78
+ };
79
+ type GetCredentialsUnauthenticatedUser = {
80
+ authenticated: false;
81
+ forceRefresh?: boolean;
82
+ authConfig: AuthConfig;
83
+ tokens?: never;
84
+ };
85
+ export type AWSCredentialsAndIdentityId = {
86
+ credentials: AWSCredentials;
87
+ identityId?: string;
88
+ };
89
+ type AWSCredentials = {
90
+ accessKeyId: string;
91
+ secretAccessKey: string;
92
+ sessionToken?: string;
93
+ expiration?: Date;
94
+ };
95
+ export {};
@@ -0,0 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // From https://github.com/awslabs/aws-jwt-verify/blob/main/src/safe-json-parse.ts
4
+ // From https://github.com/awslabs/aws-jwt-verify/blob/main/src/jwt-model.ts
5
+ export {};
@@ -0,0 +1,5 @@
1
+ import { AuthConfig, IdentityPoolConfig, JWT, UserPoolConfig, UserPoolConfigAndIdentityPoolConfig } from '../types';
2
+ export declare function assertTokenProviderConfig(authConfig?: AuthConfig): asserts authConfig is UserPoolConfig;
3
+ export declare function assertIdentityPooIdConfig(authConfig: AuthConfig): asserts authConfig is IdentityPoolConfig;
4
+ export declare function assertUserPoolAndIdentityPooConfig(authConfig: AuthConfig): asserts authConfig is UserPoolConfigAndIdentityPoolConfig;
5
+ export declare function decodeJWT(token: string): JWT;
@@ -0,0 +1,45 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Buffer } from 'buffer';
4
+ import { asserts } from '../../../Util/errors/AssertError';
5
+ export function assertTokenProviderConfig(authConfig) {
6
+ var validConfig = !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.userPoolId) && !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.userPoolWebClientId);
7
+ return asserts(validConfig, {
8
+ name: 'AuthTokenConfigException',
9
+ message: 'Auth Token Provider not configured',
10
+ recoverySuggestion: 'Make sure to call Amplify.configure in your app',
11
+ });
12
+ }
13
+ export function assertIdentityPooIdConfig(authConfig) {
14
+ var validConfig = !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.identityPoolId);
15
+ return asserts(validConfig, {
16
+ name: 'AuthIdentityPoolIdException',
17
+ message: 'Auth IdentityPoolId not configured',
18
+ recoverySuggestion: 'Make sure to call Amplify.configure in your app with a valid IdentityPoolId',
19
+ });
20
+ }
21
+ export function assertUserPoolAndIdentityPooConfig(authConfig) {
22
+ var validConfig = !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.identityPoolId) && !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.userPoolId);
23
+ return asserts(validConfig, {
24
+ name: 'AuthUserPoolAndIdentityPoolException',
25
+ message: 'Auth UserPool and IdentityPool not configured',
26
+ recoverySuggestion: 'Make sure to call Amplify.configure in your app with UserPoolId and IdentityPoolId',
27
+ });
28
+ }
29
+ export function decodeJWT(token) {
30
+ var tokenSplitted = token.split('.');
31
+ if (tokenSplitted.length !== 3) {
32
+ throw new Error('Invalid token');
33
+ }
34
+ var payloadString = tokenSplitted[1];
35
+ var payload = JSON.parse(Buffer.from(payloadString, 'base64').toString('utf8'));
36
+ try {
37
+ return {
38
+ toString: function () { return token; },
39
+ payload: payload,
40
+ };
41
+ }
42
+ catch (err) {
43
+ throw new Error('Invalid token payload');
44
+ }
45
+ }
@@ -0,0 +1,14 @@
1
+ export type StorageAccessLevel = 'guest' | 'protected' | 'private';
2
+ export interface StorageConfig {
3
+ bucket?: string;
4
+ region?: string;
5
+ }
6
+ type StoragePrefixResolver = (params: {
7
+ accessLevel: StorageAccessLevel;
8
+ targetIdentityId?: string;
9
+ }) => Promise<string>;
10
+ export interface LibraryStorageOptions {
11
+ prefixResolver?: StoragePrefixResolver;
12
+ defaultAccessLevel?: StorageAccessLevel;
13
+ }
14
+ export {};
@@ -0,0 +1,3 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export {};