@aws-amplify/core 5.8.2 → 6.0.1-console-preview.7919075.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 +160 -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 +156 -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 +144 -0
  299. package/src/singleton/types.ts +48 -0
  300. package/src/types/types.ts +38 -1
package/src/JS.ts CHANGED
@@ -47,7 +47,11 @@ const MIME_MAP = [
47
47
 
48
48
  export const isEmpty = (obj = {}) => Object.keys(obj).length === 0;
49
49
 
50
- export const sortByField = (list, field, dir) => {
50
+ export const sortByField = (
51
+ list: any[],
52
+ field: string | number,
53
+ dir: string
54
+ ) => {
51
55
  if (!list || !list.sort) {
52
56
  return false;
53
57
  }
@@ -78,7 +82,10 @@ export const sortByField = (list, field, dir) => {
78
82
  return true;
79
83
  };
80
84
 
81
- export const objectLessAttributes = (obj, less) => {
85
+ export const objectLessAttributes = (
86
+ obj: Record<string, any>,
87
+ less: string | string[]
88
+ ) => {
82
89
  const ret = Object.assign({}, obj);
83
90
  if (less) {
84
91
  if (typeof less === 'string') {
@@ -94,7 +101,7 @@ export const objectLessAttributes = (obj, less) => {
94
101
  };
95
102
 
96
103
  export const filenameToContentType = (
97
- filename,
104
+ filename: string,
98
105
  defVal = 'application/octet-stream'
99
106
  ) => {
100
107
  const name = filename.toLowerCase();
@@ -103,7 +110,7 @@ export const filenameToContentType = (
103
110
  return filtered.length > 0 ? filtered[0].type : defVal;
104
111
  };
105
112
 
106
- export const isTextFile = contentType => {
113
+ export const isTextFile = (contentType: string) => {
107
114
  const type = contentType.toLowerCase();
108
115
  if (type.startsWith('text/')) {
109
116
  return true;
@@ -125,7 +132,7 @@ export const generateRandomString = () => {
125
132
  return result;
126
133
  };
127
134
 
128
- export const makeQuerablePromise = promise => {
135
+ export const makeQuerablePromise = (promise: any) => {
129
136
  if (promise.isResolved) return promise;
130
137
 
131
138
  let isPending = true;
@@ -133,12 +140,12 @@ export const makeQuerablePromise = promise => {
133
140
  let isFullfilled = false;
134
141
 
135
142
  const result = promise.then(
136
- data => {
143
+ (data: unknown) => {
137
144
  isFullfilled = true;
138
145
  isPending = false;
139
146
  return data;
140
147
  },
141
- e => {
148
+ (e: unknown) => {
142
149
  isRejected = true;
143
150
  isPending = false;
144
151
  throw e;
@@ -156,7 +163,7 @@ export const isWebWorker = () => {
156
163
  if (typeof self === 'undefined') {
157
164
  return false;
158
165
  }
159
- const selfContext = self as { WorkerGlobalScope? };
166
+ const selfContext = self as { WorkerGlobalScope?: any };
160
167
  return (
161
168
  typeof selfContext.WorkerGlobalScope !== 'undefined' &&
162
169
  self instanceof selfContext.WorkerGlobalScope
@@ -184,12 +191,12 @@ export const browserOrNode = () => {
184
191
  * @param {Array} whiteListForChildren - whitelist its children keys from being transferred
185
192
  */
186
193
  export const transferKeyToLowerCase = (
187
- obj,
188
- whiteListForItself = [],
189
- whiteListForChildren = []
194
+ obj: Record<string, any>,
195
+ whiteListForItself: string[] = [],
196
+ whiteListForChildren: string[] = []
190
197
  ) => {
191
198
  if (!isStrictObject(obj)) return obj;
192
- const ret = {};
199
+ const ret: Record<string, any> = {};
193
200
 
194
201
  for (const key in obj) {
195
202
  if (obj.hasOwnProperty(key)) {
@@ -217,12 +224,12 @@ export const transferKeyToLowerCase = (
217
224
  * @param {Array} whiteListForChildren - whitelist its children keys from being transferred
218
225
  */
219
226
  export const transferKeyToUpperCase = (
220
- obj,
221
- whiteListForItself = [],
222
- whiteListForChildren = []
227
+ obj: Record<string, any>,
228
+ whiteListForItself: string[] = [],
229
+ whiteListForChildren: string[] = []
223
230
  ) => {
224
231
  if (!isStrictObject(obj)) return obj;
225
- const ret = {};
232
+ const ret: Record<string, any> = {};
226
233
 
227
234
  for (const key in obj) {
228
235
  if (obj.hasOwnProperty(key)) {
@@ -247,7 +254,7 @@ export const transferKeyToUpperCase = (
247
254
  * which means it's not Array, Function, Number, String, Boolean or Null
248
255
  * @param obj the Object
249
256
  */
250
- export const isStrictObject = obj => {
257
+ export const isStrictObject = (obj: any) => {
251
258
  return (
252
259
  obj instanceof Object &&
253
260
  !(obj instanceof Array) &&
@@ -6,7 +6,7 @@ import { LoggingProvider } from '../types';
6
6
  import { AWS_CLOUDWATCH_CATEGORY } from '../Util/Constants';
7
7
  import { Logger } from './logger-interface';
8
8
 
9
- const LOG_LEVELS = {
9
+ const LOG_LEVELS: Record<string, number> = {
10
10
  VERBOSE: 1,
11
11
  DEBUG: 2,
12
12
  INFO: 3,
@@ -30,7 +30,7 @@ export class ConsoleLogger implements Logger {
30
30
  name: string;
31
31
  level: LOG_TYPE | string;
32
32
  private _pluggables: LoggingProvider[];
33
- private _config: object;
33
+ private _config?: object;
34
34
 
35
35
  /**
36
36
  * @constructor
@@ -44,7 +44,7 @@ export class ConsoleLogger implements Logger {
44
44
 
45
45
  static LOG_LEVEL = null;
46
46
 
47
- _padding(n) {
47
+ _padding(n: number) {
48
48
  return n < 10 ? '0' + n : '' + n;
49
49
  }
50
50
 
@@ -74,7 +74,7 @@ export class ConsoleLogger implements Logger {
74
74
  * @param {LOG_TYPE|string} type - log type, default INFO
75
75
  * @param {string|object} msg - Logging message or object
76
76
  */
77
- _log(type: LOG_TYPE | string, ...msg) {
77
+ _log(type: LOG_TYPE | string, ...msg: any) {
78
78
  let logger_level_name = this.level;
79
79
  if (ConsoleLogger.LOG_LEVEL) {
80
80
  logger_level_name = ConsoleLogger.LOG_LEVEL;
@@ -130,7 +130,7 @@ export class ConsoleLogger implements Logger {
130
130
  * @memeberof Logger
131
131
  * @param {string|object} msg - Logging message or object
132
132
  */
133
- log(...msg) {
133
+ log(...msg: any) {
134
134
  this._log(LOG_TYPE.INFO, ...msg);
135
135
  }
136
136
 
@@ -140,7 +140,7 @@ export class ConsoleLogger implements Logger {
140
140
  * @memeberof Logger
141
141
  * @param {string|object} msg - Logging message or object
142
142
  */
143
- info(...msg) {
143
+ info(...msg: any) {
144
144
  this._log(LOG_TYPE.INFO, ...msg);
145
145
  }
146
146
 
@@ -150,7 +150,7 @@ export class ConsoleLogger implements Logger {
150
150
  * @memeberof Logger
151
151
  * @param {string|object} msg - Logging message or object
152
152
  */
153
- warn(...msg) {
153
+ warn(...msg: any) {
154
154
  this._log(LOG_TYPE.WARN, ...msg);
155
155
  }
156
156
 
@@ -160,7 +160,7 @@ export class ConsoleLogger implements Logger {
160
160
  * @memeberof Logger
161
161
  * @param {string|object} msg - Logging message or object
162
162
  */
163
- error(...msg) {
163
+ error(...msg: any) {
164
164
  this._log(LOG_TYPE.ERROR, ...msg);
165
165
  }
166
166
 
@@ -170,7 +170,7 @@ export class ConsoleLogger implements Logger {
170
170
  * @memeberof Logger
171
171
  * @param {string|object} msg - Logging message or object
172
172
  */
173
- debug(...msg) {
173
+ debug(...msg: any) {
174
174
  this._log(LOG_TYPE.DEBUG, ...msg);
175
175
  }
176
176
 
@@ -180,7 +180,7 @@ export class ConsoleLogger implements Logger {
180
180
  * @memeberof Logger
181
181
  * @param {string|object} msg - Logging message or object
182
182
  */
183
- verbose(...msg) {
183
+ verbose(...msg: any) {
184
184
  this._log(LOG_TYPE.VERBOSE, ...msg);
185
185
  }
186
186
 
@@ -42,7 +42,7 @@ export class FacebookOAuth {
42
42
  }
43
43
 
44
44
  private _refreshFacebookTokenImpl() {
45
- let fb = null;
45
+ let fb: any = null;
46
46
  if (browserOrNode().isBrowser) fb = window['FB'];
47
47
  if (!fb) {
48
48
  const errorMessage = 'no fb sdk available';
@@ -52,7 +52,7 @@ export class FacebookOAuth {
52
52
 
53
53
  return new Promise((res, rej) => {
54
54
  fb.getLoginStatus(
55
- fbResponse => {
55
+ (fbResponse: any) => {
56
56
  if (!fbResponse || !fbResponse.authResponse) {
57
57
  const errorMessage =
58
58
  'no response from facebook when refreshing the jwt token';
@@ -43,7 +43,7 @@ export class GoogleOAuth {
43
43
  }
44
44
 
45
45
  private _refreshGoogleTokenImpl() {
46
- let ga = null;
46
+ let ga: any = null;
47
47
  if (browserOrNode().isBrowser)
48
48
  ga = window['gapi'] && window['gapi'].auth2 ? window['gapi'].auth2 : null;
49
49
  if (!ga) {
@@ -53,7 +53,7 @@ export class GoogleOAuth {
53
53
 
54
54
  return new Promise((res, rej) => {
55
55
  ga.getAuthInstance()
56
- .then(googleAuth => {
56
+ .then((googleAuth: any) => {
57
57
  if (!googleAuth) {
58
58
  logger.debug('google Auth undefined');
59
59
  rej(new NonRetryableError('google Auth undefined'));
@@ -65,12 +65,15 @@ export class GoogleOAuth {
65
65
  logger.debug('refreshing the google access token');
66
66
  googleUser
67
67
  .reloadAuthResponse()
68
- .then(authResponse => {
68
+ .then((authResponse: any) => {
69
69
  const { id_token, expires_at } = authResponse;
70
70
  res({ token: id_token, expires_at });
71
71
  })
72
- .catch(err => {
73
- if (err && err.error === 'network_error') {
72
+ .catch((err: unknown) => {
73
+ if (
74
+ err &&
75
+ (err as { error: string }).error === 'network_error'
76
+ ) {
74
77
  // Not using NonRetryableError so handler will be retried
75
78
  rej('Network error reloading google auth response');
76
79
  } else {
@@ -85,7 +88,7 @@ export class GoogleOAuth {
85
88
  rej(new NonRetryableError('User is not signed in with Google'));
86
89
  }
87
90
  })
88
- .catch(err => {
91
+ .catch((err: unknown) => {
89
92
  logger.debug('Failed to refresh google token', err);
90
93
  rej(new NonRetryableError('Failed to refresh google token'));
91
94
  });
@@ -25,7 +25,7 @@ export const detectFramework = (): Framework => {
25
25
  // So we don't need to notify the observers again so the observer
26
26
  // can be removed after the final notice.
27
27
  while (frameworkChangeObservers.length) {
28
- frameworkChangeObservers.pop()();
28
+ frameworkChangeObservers.pop()?.();
29
29
  }
30
30
  } else {
31
31
  // The first run of detectFramework:
@@ -1,15 +1,15 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { documentExists, processExists, windowExists } from './helpers';
4
+ import { documentExists, processExists } from './helpers';
5
5
 
6
6
  // Tested with react 18.2 - built using Vite
7
7
 
8
8
  export function reactWebDetect() {
9
- const elementKeyPrefixedWithReact = key => {
9
+ const elementKeyPrefixedWithReact = (key: string) => {
10
10
  return key.startsWith('_react') || key.startsWith('__react');
11
11
  };
12
- const elementIsReactEnabled = element => {
12
+ const elementIsReactEnabled = (element: Element) => {
13
13
  return Object.keys(element).find(elementKeyPrefixedWithReact);
14
14
  };
15
15
  const allElementsWithId = () => Array.from(document.querySelectorAll('[id]'));
@@ -24,3 +24,5 @@ export function reactSSRDetect() {
24
24
  !!Object.keys(process.env).find(key => key.includes('react'))
25
25
  );
26
26
  }
27
+
28
+ // use the some
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '5.3.8';
2
+ export const version = '6.0.1-console-preview.7919075.0+7919075';
@@ -30,7 +30,7 @@ import {
30
30
  CloudWatchDataTracker,
31
31
  LoggingProvider,
32
32
  } from '../types/types';
33
- import { Credentials } from '../..';
33
+ import { Credentials } from '../Credentials';
34
34
  import { ConsoleLogger as Logger } from '../Logger';
35
35
  import { getAmplifyUserAgentObject } from '../Platform';
36
36
  import { parseAWSExports } from '../parseAWSExports';
@@ -43,6 +43,8 @@ import {
43
43
  NO_CREDS_ERROR_STRING,
44
44
  RETRY_ERROR_CODES,
45
45
  } from '../Util/Constants';
46
+ import { asserts } from '../Util/errors/AssertError';
47
+ import { AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION } from '../constants';
46
48
 
47
49
  const logger = new Logger('AWSCloudWatch');
48
50
 
@@ -50,10 +52,10 @@ class AWSCloudWatchProvider implements LoggingProvider {
50
52
  static readonly PROVIDER_NAME = AWS_CLOUDWATCH_PROVIDER_NAME;
51
53
  static readonly CATEGORY = AWS_CLOUDWATCH_CATEGORY;
52
54
 
53
- private _config: AWSCloudWatchProviderOptions;
55
+ private _config?: AWSCloudWatchProviderOptions;
54
56
  private _dataTracker: CloudWatchDataTracker;
55
57
  private _currentLogBatch: InputLogEvent[];
56
- private _timer;
58
+ private _timer?: NodeJS.Timer;
57
59
  private _nextSequenceToken: string | undefined;
58
60
 
59
61
  constructor(config?: AWSCloudWatchProviderOptions) {
@@ -213,7 +215,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
213
215
 
214
216
  private async _validateLogGroupExistsAndCreate(
215
217
  logGroupName: string
216
- ): Promise<LogGroup> {
218
+ ): Promise<LogGroup | null> {
217
219
  if (this._dataTracker.verifiedLogGroup) {
218
220
  return this._dataTracker.verifiedLogGroup;
219
221
  }
@@ -256,7 +258,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
256
258
  private async _validateLogStreamExists(
257
259
  logGroupName: string,
258
260
  logStreamName: string
259
- ): Promise<LogStream> {
261
+ ): Promise<LogStream | null> {
260
262
  try {
261
263
  const credentialsOK = await this._ensureCredentials();
262
264
  if (!credentialsOK) {
@@ -298,7 +300,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
298
300
 
299
301
  private async _sendLogEvents(
300
302
  params: PutLogEventsCommandInput
301
- ): Promise<PutLogEventsCommandOutput> {
303
+ ): Promise<PutLogEventsCommandOutput | undefined> {
302
304
  try {
303
305
  const credentialsOK = await this._ensureCredentials();
304
306
  if (!credentialsOK) {
@@ -318,6 +320,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
318
320
  }
319
321
 
320
322
  private _initCloudWatchLogs() {
323
+ assertsAWSClouldWatchOptions(this._config);
321
324
  return new CloudWatchLogsClient({
322
325
  region: this._config.region,
323
326
  credentials: this._config.credentials,
@@ -328,7 +331,8 @@ class AWSCloudWatchProvider implements LoggingProvider {
328
331
 
329
332
  private async _ensureCredentials() {
330
333
  return await Credentials.get()
331
- .then(credentials => {
334
+ .then((credentials: any) => {
335
+ assertsAWSClouldWatchOptions(this._config);
332
336
  if (!credentials) return false;
333
337
  const cred = Credentials.shear(credentials);
334
338
  logger.debug('set credentials for logging', cred);
@@ -336,13 +340,14 @@ class AWSCloudWatchProvider implements LoggingProvider {
336
340
 
337
341
  return true;
338
342
  })
339
- .catch(error => {
343
+ .catch((error: unknown) => {
340
344
  logger.warn('ensure credentials error', error);
341
345
  return false;
342
346
  });
343
347
  }
344
348
 
345
- private async _getNextSequenceToken(): Promise<string> {
349
+ private async _getNextSequenceToken(): Promise<string | undefined> {
350
+ assertsAWSClouldWatchOptions(this._config);
346
351
  if (this._nextSequenceToken && this._nextSequenceToken.length > 0) {
347
352
  return this._nextSequenceToken;
348
353
  }
@@ -354,6 +359,14 @@ class AWSCloudWatchProvider implements LoggingProvider {
354
359
  * ...the log stream does exist but has no logs written to it yet
355
360
  */
356
361
  try {
362
+ asserts(this._config.logGroupName !== undefined, {
363
+ name: AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION,
364
+ message: ' log group name is undefined',
365
+ });
366
+ asserts(this._config.logStreamName !== undefined, {
367
+ name: AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION,
368
+ message: ' log stream name is undefined',
369
+ });
357
370
  await this._validateLogGroupExistsAndCreate(this._config.logGroupName);
358
371
 
359
372
  this._nextSequenceToken = undefined;
@@ -374,7 +387,10 @@ class AWSCloudWatchProvider implements LoggingProvider {
374
387
  }
375
388
  }
376
389
 
377
- private async _safeUploadLogEvents(): Promise<PutLogEventsCommandOutput> {
390
+ private async _safeUploadLogEvents(): Promise<
391
+ PutLogEventsCommandOutput | undefined
392
+ > {
393
+ assertsAWSClouldWatchOptions(this._config);
378
394
  try {
379
395
  /**
380
396
  * CloudWatch has restrictions on the size of the log events that get sent up.
@@ -400,7 +416,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
400
416
  this._dataTracker.eventUploadInProgress = true;
401
417
  const sendLogEventsResponse = await this._sendLogEvents(putLogsPayload);
402
418
 
403
- this._nextSequenceToken = sendLogEventsResponse.nextSequenceToken;
419
+ this._nextSequenceToken = sendLogEventsResponse?.nextSequenceToken;
404
420
  this._dataTracker.eventUploadInProgress = false;
405
421
  this._currentLogBatch = [];
406
422
 
@@ -408,7 +424,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
408
424
  } catch (err) {
409
425
  logger.error(`error during _safeUploadLogEvents: ${err}`);
410
426
 
411
- if (RETRY_ERROR_CODES.includes(err.name)) {
427
+ if (err instanceof Error && RETRY_ERROR_CODES.includes(err.name)) {
412
428
  this._getNewSequenceTokenAndSubmit({
413
429
  logEvents: this._currentLogBatch,
414
430
  logGroupName: this._config.logGroupName,
@@ -443,7 +459,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
443
459
  const errString = `Log entry exceeds maximum size for CloudWatch logs. Log size: ${eventSize}. Truncating log message.`;
444
460
  logger.warn(errString);
445
461
 
446
- currentEvent.message = currentEvent.message.substring(0, eventSize);
462
+ currentEvent.message = currentEvent.message?.substring(0, eventSize);
447
463
  }
448
464
 
449
465
  if (totalByteSize + eventSize > AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE)
@@ -462,7 +478,7 @@ class AWSCloudWatchProvider implements LoggingProvider {
462
478
 
463
479
  private async _getNewSequenceTokenAndSubmit(
464
480
  payload: PutLogEventsCommandInput
465
- ): Promise<PutLogEventsCommandOutput> {
481
+ ): Promise<PutLogEventsCommandOutput | undefined> {
466
482
  try {
467
483
  this._nextSequenceToken = undefined;
468
484
  this._dataTracker.eventUploadInProgress = true;
@@ -512,4 +528,13 @@ class AWSCloudWatchProvider implements LoggingProvider {
512
528
  }
513
529
  }
514
530
 
531
+ function assertsAWSClouldWatchOptions(
532
+ options?: AWSCloudWatchProviderOptions
533
+ ): asserts options {
534
+ return asserts(options !== undefined, {
535
+ name: AWS_CLOUD_WATCH_PROVIDER_OPTIONS_EXCEPTION,
536
+ message: 'AWSCloudWatchProviderOptions cannot be undefined',
537
+ });
538
+ }
539
+
515
540
  export { AWSCloudWatchProvider };
@@ -6,7 +6,7 @@ import { StorageHelper } from '../StorageHelper';
6
6
 
7
7
  export const Linking = {};
8
8
  export const AppState = {
9
- addEventListener: (action, handler) => undefined,
9
+ addEventListener: (action: any, handler: any) => undefined,
10
10
  };
11
11
 
12
12
  // if not in react native, just use local storage
@@ -1,6 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
-
3
+ // @ts-ignore
4
4
  import { Linking, AppState } from 'react-native';
5
5
  import AsyncStorage from '@react-native-async-storage/async-storage';
6
6
  export { Linking, AppState, AsyncStorage };
@@ -15,6 +15,9 @@
15
15
  import { ConsoleLogger as Logger } from '../Logger';
16
16
  import { browserOrNode } from '../JS';
17
17
  import { Amplify } from '../Amplify';
18
+ import { asserts } from '../Util/errors/AssertError';
19
+ import { AmplifyError } from '../Errors';
20
+ import { SERVICE_WORKER_EXCEPTION } from '../constants';
18
21
  /**
19
22
  * Provides a means to registering a service worker in the browser
20
23
  * and communicating with it via postMessage events.
@@ -29,17 +32,17 @@ import { Amplify } from '../Amplify';
29
32
  */
30
33
  export class ServiceWorkerClass {
31
34
  // The active service worker will be set once it is registered
32
- private _serviceWorker: ServiceWorker;
35
+ private _serviceWorker?: ServiceWorker;
33
36
 
34
37
  // The service worker registration object
35
- private _registration: ServiceWorkerRegistration;
38
+ private _registration?: ServiceWorkerRegistration;
36
39
 
37
40
  // The application server public key for Push
38
41
  // https://web-push-codelab.glitch.me/
39
- private _publicKey: string;
42
+ private _publicKey?: string;
40
43
 
41
44
  // push subscription
42
- private _subscription: PushSubscription;
45
+ private _subscription?: PushSubscription;
43
46
 
44
47
  // The AWS Amplify logger
45
48
  private _logger: Logger = new Logger('ServiceWorker');
@@ -50,6 +53,11 @@ export class ServiceWorkerClass {
50
53
  * Get the currently active service worker
51
54
  */
52
55
  get serviceWorker(): ServiceWorker {
56
+ asserts(this._serviceWorker !== undefined, {
57
+ name: SERVICE_WORKER_EXCEPTION,
58
+ message: 'Service Worker instance is undefined',
59
+ });
60
+
53
61
  return this._serviceWorker;
54
62
  }
55
63
 
@@ -91,10 +99,21 @@ export class ServiceWorkerClass {
91
99
  })
92
100
  .catch(error => {
93
101
  this._logger.debug(`Service Worker Registration Failed ${error}`);
94
- return reject(error);
102
+ return reject(
103
+ new AmplifyError({
104
+ name: SERVICE_WORKER_EXCEPTION,
105
+ message: 'Service Worker not available',
106
+ underlyingError: error,
107
+ })
108
+ );
95
109
  });
96
110
  } else {
97
- return reject(new Error('Service Worker not available'));
111
+ return reject(
112
+ new AmplifyError({
113
+ name: SERVICE_WORKER_EXCEPTION,
114
+ message: 'Service Worker not available',
115
+ })
116
+ );
98
117
  }
99
118
  });
100
119
  }
@@ -111,10 +130,17 @@ export class ServiceWorkerClass {
111
130
  * - reject(Error)
112
131
  */
113
132
  enablePush(publicKey: string) {
114
- if (!this._registration) throw new Error('Service Worker not registered');
133
+ asserts(this._registration !== undefined, {
134
+ name: SERVICE_WORKER_EXCEPTION,
135
+ message: 'Service Worker registration is undefined',
136
+ });
115
137
  this._publicKey = publicKey;
116
138
  return new Promise((resolve, reject) => {
117
139
  if (browserOrNode().isBrowser) {
140
+ asserts(this._registration !== undefined, {
141
+ name: SERVICE_WORKER_EXCEPTION,
142
+ message: 'Service Worker registration is undefined',
143
+ });
118
144
  this._registration.pushManager.getSubscription().then(subscription => {
119
145
  if (subscription) {
120
146
  this._subscription = subscription;
@@ -124,11 +150,10 @@ export class ServiceWorkerClass {
124
150
  resolve(subscription);
125
151
  } else {
126
152
  this._logger.debug(`User is NOT subscribed to push`);
127
- return this._registration.pushManager
128
- .subscribe({
129
- userVisibleOnly: true,
130
- applicationServerKey: this._urlB64ToUint8Array(publicKey),
131
- })
153
+ return this._registration!.pushManager.subscribe({
154
+ userVisibleOnly: true,
155
+ applicationServerKey: this._urlB64ToUint8Array(publicKey),
156
+ })
132
157
  .then(subscription => {
133
158
  this._subscription = subscription;
134
159
  this._logger.debug(
@@ -142,7 +167,12 @@ export class ServiceWorkerClass {
142
167
  }
143
168
  });
144
169
  } else {
145
- return reject(new Error('Service Worker not available'));
170
+ return reject(
171
+ new AmplifyError({
172
+ name: SERVICE_WORKER_EXCEPTION,
173
+ message: 'Service Worker not available',
174
+ })
175
+ );
146
176
  }
147
177
  });
148
178
  }
@@ -187,11 +217,12 @@ export class ServiceWorkerClass {
187
217
  * https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/state
188
218
  **/
189
219
  _setupListeners() {
190
- this._serviceWorker.addEventListener('statechange', event => {
191
- const currentState = this._serviceWorker.state;
220
+ this.serviceWorker.addEventListener('statechange', event => {
221
+ const currentState = this.serviceWorker.state;
192
222
  this._logger.debug(`ServiceWorker statechange: ${currentState}`);
193
- if (Amplify.Analytics && typeof Amplify.Analytics.record === 'function') {
194
- Amplify.Analytics.record({
223
+ Amplify.Analytics;
224
+ if (isAmplifyWithAnalytics(Amplify)) {
225
+ (Amplify as AmplifyWithAnalytics).Analytics.record({
195
226
  name: 'ServiceWorker',
196
227
  attributes: {
197
228
  state: currentState,
@@ -199,8 +230,17 @@ export class ServiceWorkerClass {
199
230
  });
200
231
  }
201
232
  });
202
- this._serviceWorker.addEventListener('message', event => {
233
+ this.serviceWorker.addEventListener('message', event => {
203
234
  this._logger.debug(`ServiceWorker message event: ${event}`);
204
235
  });
205
236
  }
206
237
  }
238
+
239
+ type AmplifyWithAnalytics = {
240
+ Analytics: {
241
+ record: Function;
242
+ };
243
+ };
244
+ function isAmplifyWithAnalytics(amplify: any): amplify is AmplifyWithAnalytics {
245
+ return amplify.Analytics && typeof amplify.Analytics.record === 'function';
246
+ }
package/src/Signer.ts CHANGED
@@ -49,7 +49,21 @@ export class Signer {
49
49
  *
50
50
  * @returns {object} Signed HTTP request
51
51
  */
52
- static sign(request, accessInfo, serviceInfo) {
52
+ static sign(
53
+ request: {
54
+ headers: any;
55
+ body?: BodyInit;
56
+ data?: any;
57
+ url: string;
58
+ method: string;
59
+ },
60
+ accessInfo: {
61
+ access_key: string;
62
+ secret_key: string;
63
+ session_token: string;
64
+ },
65
+ serviceInfo: { service: string; region: string }
66
+ ) {
53
67
  request.headers = request.headers || {};
54
68
 
55
69
  if (request.body && !request.data) {
@@ -61,7 +75,7 @@ export class Signer {
61
75
  const requestToSign = {
62
76
  ...request,
63
77
  body: request.data,
64
- url: new URL(request.url as string),
78
+ url: new URL(request.url),
65
79
  };
66
80
 
67
81
  const options = getOptions(requestToSign, accessInfo, serviceInfo);
@@ -130,7 +144,12 @@ export class Signer {
130
144
  }
131
145
  }
132
146
 
133
- const getOptions = (request, accessInfo, serviceInfo, expiration?) => {
147
+ const getOptions = (
148
+ request: { url: URL } & Record<string, any>,
149
+ accessInfo: { access_key: string; secret_key: string; session_token: string },
150
+ serviceInfo: { service: string; region: string },
151
+ expiration?: number
152
+ ) => {
134
153
  const { access_key, secret_key, session_token } = accessInfo ?? {};
135
154
  const { region: urlRegion, service: urlService } = parseServiceInfo(
136
155
  request.url