@0xkey-io/react-wallet-kit 0.1.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 (326) hide show
  1. package/LICENSE +201 -0
  2. package/README.MD +116 -0
  3. package/dist/_virtual/_rollupPluginBabelHelpers.mjs +307 -0
  4. package/dist/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -0
  5. package/dist/components/auth/Action.d.ts +10 -0
  6. package/dist/components/auth/Action.d.ts.map +1 -0
  7. package/dist/components/auth/Action.js +76 -0
  8. package/dist/components/auth/Action.js.map +1 -0
  9. package/dist/components/auth/Action.mjs +97 -0
  10. package/dist/components/auth/Action.mjs.map +1 -0
  11. package/dist/components/auth/Email.d.ts +6 -0
  12. package/dist/components/auth/Email.d.ts.map +1 -0
  13. package/dist/components/auth/Email.js +77 -0
  14. package/dist/components/auth/Email.js.map +1 -0
  15. package/dist/components/auth/Email.mjs +98 -0
  16. package/dist/components/auth/Email.mjs.map +1 -0
  17. package/dist/components/auth/OAuth.d.ts +13 -0
  18. package/dist/components/auth/OAuth.d.ts.map +1 -0
  19. package/dist/components/auth/OAuth.js +63 -0
  20. package/dist/components/auth/OAuth.js.map +1 -0
  21. package/dist/components/auth/OAuth.mjs +68 -0
  22. package/dist/components/auth/OAuth.mjs.map +1 -0
  23. package/dist/components/auth/OTP.d.ts +21 -0
  24. package/dist/components/auth/OTP.d.ts.map +1 -0
  25. package/dist/components/auth/OTP.js +218 -0
  26. package/dist/components/auth/OTP.js.map +1 -0
  27. package/dist/components/auth/OTP.mjs +301 -0
  28. package/dist/components/auth/OTP.mjs.map +1 -0
  29. package/dist/components/auth/OrSeparator.d.ts +2 -0
  30. package/dist/components/auth/OrSeparator.d.ts.map +1 -0
  31. package/dist/components/auth/OrSeparator.js +20 -0
  32. package/dist/components/auth/OrSeparator.js.map +1 -0
  33. package/dist/components/auth/OrSeparator.mjs +18 -0
  34. package/dist/components/auth/OrSeparator.mjs.map +1 -0
  35. package/dist/components/auth/Passkey.d.ts +7 -0
  36. package/dist/components/auth/Passkey.d.ts.map +1 -0
  37. package/dist/components/auth/Passkey.js +34 -0
  38. package/dist/components/auth/Passkey.js.map +1 -0
  39. package/dist/components/auth/Passkey.mjs +30 -0
  40. package/dist/components/auth/Passkey.mjs.map +1 -0
  41. package/dist/components/auth/Phone.d.ts +6 -0
  42. package/dist/components/auth/Phone.d.ts.map +1 -0
  43. package/dist/components/auth/Phone.js +67 -0
  44. package/dist/components/auth/Phone.js.map +1 -0
  45. package/dist/components/auth/Phone.mjs +92 -0
  46. package/dist/components/auth/Phone.mjs.map +1 -0
  47. package/dist/components/auth/Wallet.d.ts +34 -0
  48. package/dist/components/auth/Wallet.d.ts.map +1 -0
  49. package/dist/components/auth/Wallet.js +517 -0
  50. package/dist/components/auth/Wallet.js.map +1 -0
  51. package/dist/components/auth/Wallet.mjs +618 -0
  52. package/dist/components/auth/Wallet.mjs.map +1 -0
  53. package/dist/components/auth/index.d.ts +9 -0
  54. package/dist/components/auth/index.d.ts.map +1 -0
  55. package/dist/components/auth/index.js +457 -0
  56. package/dist/components/auth/index.js.map +1 -0
  57. package/dist/components/auth/index.mjs +672 -0
  58. package/dist/components/auth/index.mjs.map +1 -0
  59. package/dist/components/design/Buttons.d.ts +29 -0
  60. package/dist/components/design/Buttons.d.ts.map +1 -0
  61. package/dist/components/design/Buttons.js +87 -0
  62. package/dist/components/design/Buttons.js.map +1 -0
  63. package/dist/components/design/Buttons.mjs +79 -0
  64. package/dist/components/design/Buttons.mjs.map +1 -0
  65. package/dist/components/design/Failure.d.ts +9 -0
  66. package/dist/components/design/Failure.d.ts.map +1 -0
  67. package/dist/components/design/Failure.js +33 -0
  68. package/dist/components/design/Failure.js.map +1 -0
  69. package/dist/components/design/Failure.mjs +34 -0
  70. package/dist/components/design/Failure.mjs.map +1 -0
  71. package/dist/components/design/Inputs.d.ts +9 -0
  72. package/dist/components/design/Inputs.d.ts.map +1 -0
  73. package/dist/components/design/Inputs.js +135 -0
  74. package/dist/components/design/Inputs.js.map +1 -0
  75. package/dist/components/design/Inputs.mjs +133 -0
  76. package/dist/components/design/Inputs.mjs.map +1 -0
  77. package/dist/components/design/Lottie/Dynamic.d.ts +2 -0
  78. package/dist/components/design/Lottie/Dynamic.d.ts.map +1 -0
  79. package/dist/components/design/Lottie/Dynamic.js +9 -0
  80. package/dist/components/design/Lottie/Dynamic.js.map +1 -0
  81. package/dist/components/design/Lottie/Dynamic.mjs +24 -0
  82. package/dist/components/design/Lottie/Dynamic.mjs.map +1 -0
  83. package/dist/components/design/Lottie/Wrapper.d.ts +8 -0
  84. package/dist/components/design/Lottie/Wrapper.d.ts.map +1 -0
  85. package/dist/components/design/Lottie/Wrapper.js +26 -0
  86. package/dist/components/design/Lottie/Wrapper.js.map +1 -0
  87. package/dist/components/design/Lottie/Wrapper.mjs +42 -0
  88. package/dist/components/design/Lottie/Wrapper.mjs.map +1 -0
  89. package/dist/components/design/Spinners.d.ts +9 -0
  90. package/dist/components/design/Spinners.d.ts.map +1 -0
  91. package/dist/components/design/Spinners.js +38 -0
  92. package/dist/components/design/Spinners.js.map +1 -0
  93. package/dist/components/design/Spinners.mjs +37 -0
  94. package/dist/components/design/Spinners.mjs.map +1 -0
  95. package/dist/components/design/Success.d.ts +8 -0
  96. package/dist/components/design/Success.d.ts.map +1 -0
  97. package/dist/components/design/Success.js +82 -0
  98. package/dist/components/design/Success.js.map +1 -0
  99. package/dist/components/design/Success.mjs +86 -0
  100. package/dist/components/design/Success.mjs.map +1 -0
  101. package/dist/components/design/Svg.d.ts +13 -0
  102. package/dist/components/design/Svg.d.ts.map +1 -0
  103. package/dist/components/design/Svg.js +165 -0
  104. package/dist/components/design/Svg.js.map +1 -0
  105. package/dist/components/design/Svg.mjs +161 -0
  106. package/dist/components/design/Svg.mjs.map +1 -0
  107. package/dist/components/export/Export.d.ts +13 -0
  108. package/dist/components/export/Export.d.ts.map +1 -0
  109. package/dist/components/export/Export.js +169 -0
  110. package/dist/components/export/Export.js.map +1 -0
  111. package/dist/components/export/Export.mjs +213 -0
  112. package/dist/components/export/Export.mjs.map +1 -0
  113. package/dist/components/export/ExportWarning.d.ts +15 -0
  114. package/dist/components/export/ExportWarning.d.ts.map +1 -0
  115. package/dist/components/export/ExportWarning.js +141 -0
  116. package/dist/components/export/ExportWarning.js.map +1 -0
  117. package/dist/components/export/ExportWarning.mjs +174 -0
  118. package/dist/components/export/ExportWarning.mjs.map +1 -0
  119. package/dist/components/import/Import.d.ts +20 -0
  120. package/dist/components/import/Import.d.ts.map +1 -0
  121. package/dist/components/import/Import.js +290 -0
  122. package/dist/components/import/Import.js.map +1 -0
  123. package/dist/components/import/Import.mjs +422 -0
  124. package/dist/components/import/Import.mjs.map +1 -0
  125. package/dist/components/onramp/OnRamp.d.ts +14 -0
  126. package/dist/components/onramp/OnRamp.d.ts.map +1 -0
  127. package/dist/components/onramp/OnRamp.js +61 -0
  128. package/dist/components/onramp/OnRamp.js.map +1 -0
  129. package/dist/components/onramp/OnRamp.mjs +79 -0
  130. package/dist/components/onramp/OnRamp.mjs.map +1 -0
  131. package/dist/components/send-transaction/SendTransaction.d.ts +12 -0
  132. package/dist/components/send-transaction/SendTransaction.d.ts.map +1 -0
  133. package/dist/components/send-transaction/SendTransaction.js +65 -0
  134. package/dist/components/send-transaction/SendTransaction.js.map +1 -0
  135. package/dist/components/send-transaction/SendTransaction.mjs +89 -0
  136. package/dist/components/send-transaction/SendTransaction.mjs.map +1 -0
  137. package/dist/components/send-transaction/helpers.d.ts +4 -0
  138. package/dist/components/send-transaction/helpers.d.ts.map +1 -0
  139. package/dist/components/send-transaction/helpers.js +37 -0
  140. package/dist/components/send-transaction/helpers.js.map +1 -0
  141. package/dist/components/send-transaction/helpers.mjs +34 -0
  142. package/dist/components/send-transaction/helpers.mjs.map +1 -0
  143. package/dist/components/sign/Message.d.ts +18 -0
  144. package/dist/components/sign/Message.d.ts.map +1 -0
  145. package/dist/components/sign/Message.js +132 -0
  146. package/dist/components/sign/Message.js.map +1 -0
  147. package/dist/components/sign/Message.mjs +148 -0
  148. package/dist/components/sign/Message.mjs.map +1 -0
  149. package/dist/components/user/ConnectWallet.d.ts +8 -0
  150. package/dist/components/user/ConnectWallet.d.ts.map +1 -0
  151. package/dist/components/user/ConnectWallet.js +114 -0
  152. package/dist/components/user/ConnectWallet.js.map +1 -0
  153. package/dist/components/user/ConnectWallet.mjs +194 -0
  154. package/dist/components/user/ConnectWallet.mjs.map +1 -0
  155. package/dist/components/user/RemoveEmail.d.ts +12 -0
  156. package/dist/components/user/RemoveEmail.d.ts.map +1 -0
  157. package/dist/components/user/RemoveEmail.js +105 -0
  158. package/dist/components/user/RemoveEmail.js.map +1 -0
  159. package/dist/components/user/RemoveEmail.mjs +124 -0
  160. package/dist/components/user/RemoveEmail.mjs.map +1 -0
  161. package/dist/components/user/RemoveOAuthProvider.d.ts +12 -0
  162. package/dist/components/user/RemoveOAuthProvider.d.ts.map +1 -0
  163. package/dist/components/user/RemoveOAuthProvider.js +110 -0
  164. package/dist/components/user/RemoveOAuthProvider.js.map +1 -0
  165. package/dist/components/user/RemoveOAuthProvider.mjs +131 -0
  166. package/dist/components/user/RemoveOAuthProvider.mjs.map +1 -0
  167. package/dist/components/user/RemovePasskey.d.ts +12 -0
  168. package/dist/components/user/RemovePasskey.d.ts.map +1 -0
  169. package/dist/components/user/RemovePasskey.js +114 -0
  170. package/dist/components/user/RemovePasskey.js.map +1 -0
  171. package/dist/components/user/RemovePasskey.mjs +135 -0
  172. package/dist/components/user/RemovePasskey.mjs.map +1 -0
  173. package/dist/components/user/RemovePhoneNumber.d.ts +12 -0
  174. package/dist/components/user/RemovePhoneNumber.d.ts.map +1 -0
  175. package/dist/components/user/RemovePhoneNumber.js +105 -0
  176. package/dist/components/user/RemovePhoneNumber.js.map +1 -0
  177. package/dist/components/user/RemovePhoneNumber.mjs +124 -0
  178. package/dist/components/user/RemovePhoneNumber.mjs.map +1 -0
  179. package/dist/components/user/UpdateEmail.d.ts +12 -0
  180. package/dist/components/user/UpdateEmail.d.ts.map +1 -0
  181. package/dist/components/user/UpdateEmail.js +154 -0
  182. package/dist/components/user/UpdateEmail.js.map +1 -0
  183. package/dist/components/user/UpdateEmail.mjs +197 -0
  184. package/dist/components/user/UpdateEmail.mjs.map +1 -0
  185. package/dist/components/user/UpdatePhoneNumber.d.ts +12 -0
  186. package/dist/components/user/UpdatePhoneNumber.d.ts.map +1 -0
  187. package/dist/components/user/UpdatePhoneNumber.js +151 -0
  188. package/dist/components/user/UpdatePhoneNumber.js.map +1 -0
  189. package/dist/components/user/UpdatePhoneNumber.mjs +198 -0
  190. package/dist/components/user/UpdatePhoneNumber.mjs.map +1 -0
  191. package/dist/components/user/UpdateUserName.d.ts +13 -0
  192. package/dist/components/user/UpdateUserName.d.ts.map +1 -0
  193. package/dist/components/user/UpdateUserName.js +113 -0
  194. package/dist/components/user/UpdateUserName.js.map +1 -0
  195. package/dist/components/user/UpdateUserName.mjs +139 -0
  196. package/dist/components/user/UpdateUserName.mjs.map +1 -0
  197. package/dist/components/verify/Verify.d.ts +9 -0
  198. package/dist/components/verify/Verify.d.ts.map +1 -0
  199. package/dist/components/verify/Verify.js +121 -0
  200. package/dist/components/verify/Verify.js.map +1 -0
  201. package/dist/components/verify/Verify.mjs +149 -0
  202. package/dist/components/verify/Verify.mjs.map +1 -0
  203. package/dist/index.d.ts +25 -0
  204. package/dist/index.d.ts.map +1 -0
  205. package/dist/index.js +74 -0
  206. package/dist/index.js.map +1 -0
  207. package/dist/index.mjs +8 -0
  208. package/dist/index.mjs.map +1 -0
  209. package/dist/providers/ZeroXKeyProvider.d.ts +9 -0
  210. package/dist/providers/ZeroXKeyProvider.d.ts.map +1 -0
  211. package/dist/providers/ZeroXKeyProvider.js +36 -0
  212. package/dist/providers/ZeroXKeyProvider.js.map +1 -0
  213. package/dist/providers/ZeroXKeyProvider.mjs +34 -0
  214. package/dist/providers/ZeroXKeyProvider.mjs.map +1 -0
  215. package/dist/providers/client/Hook.d.ts +4 -0
  216. package/dist/providers/client/Hook.d.ts.map +1 -0
  217. package/dist/providers/client/Hook.js +15 -0
  218. package/dist/providers/client/Hook.js.map +1 -0
  219. package/dist/providers/client/Hook.mjs +13 -0
  220. package/dist/providers/client/Hook.mjs.map +1 -0
  221. package/dist/providers/client/Provider.d.ts +39 -0
  222. package/dist/providers/client/Provider.d.ts.map +1 -0
  223. package/dist/providers/client/Provider.js +3934 -0
  224. package/dist/providers/client/Provider.js.map +1 -0
  225. package/dist/providers/client/Provider.mjs +6895 -0
  226. package/dist/providers/client/Provider.mjs.map +1 -0
  227. package/dist/providers/client/Types.d.ts +711 -0
  228. package/dist/providers/client/Types.d.ts.map +1 -0
  229. package/dist/providers/client/Types.js +10 -0
  230. package/dist/providers/client/Types.js.map +1 -0
  231. package/dist/providers/client/Types.mjs +8 -0
  232. package/dist/providers/client/Types.mjs.map +1 -0
  233. package/dist/providers/index.d.ts +5 -0
  234. package/dist/providers/index.d.ts.map +1 -0
  235. package/dist/providers/modal/Hook.d.ts +4 -0
  236. package/dist/providers/modal/Hook.d.ts.map +1 -0
  237. package/dist/providers/modal/Hook.js +15 -0
  238. package/dist/providers/modal/Hook.js.map +1 -0
  239. package/dist/providers/modal/Hook.mjs +13 -0
  240. package/dist/providers/modal/Hook.mjs.map +1 -0
  241. package/dist/providers/modal/Provider.d.ts +27 -0
  242. package/dist/providers/modal/Provider.d.ts.map +1 -0
  243. package/dist/providers/modal/Provider.js +48 -0
  244. package/dist/providers/modal/Provider.js.map +1 -0
  245. package/dist/providers/modal/Provider.mjs +68 -0
  246. package/dist/providers/modal/Provider.mjs.map +1 -0
  247. package/dist/providers/modal/Root.d.ts +7 -0
  248. package/dist/providers/modal/Root.d.ts.map +1 -0
  249. package/dist/providers/modal/Root.js +345 -0
  250. package/dist/providers/modal/Root.js.map +1 -0
  251. package/dist/providers/modal/Root.mjs +352 -0
  252. package/dist/providers/modal/Root.mjs.map +1 -0
  253. package/dist/providers/theme/Overrides.d.ts +18 -0
  254. package/dist/providers/theme/Overrides.d.ts.map +1 -0
  255. package/dist/providers/theme/Overrides.js +35 -0
  256. package/dist/providers/theme/Overrides.js.map +1 -0
  257. package/dist/providers/theme/Overrides.mjs +37 -0
  258. package/dist/providers/theme/Overrides.mjs.map +1 -0
  259. package/dist/styles.css +1 -0
  260. package/dist/tests/oauth-test.d.ts +2 -0
  261. package/dist/tests/oauth-test.d.ts.map +1 -0
  262. package/dist/tests/timers-test.d.ts +2 -0
  263. package/dist/tests/timers-test.d.ts.map +1 -0
  264. package/dist/tests/utils-test.d.ts +2 -0
  265. package/dist/tests/utils-test.d.ts.map +1 -0
  266. package/dist/typedoc-entry/index.d.ts +5 -0
  267. package/dist/typedoc-entry/index.d.ts.map +1 -0
  268. package/dist/types/base.d.ts +178 -0
  269. package/dist/types/base.d.ts.map +1 -0
  270. package/dist/types/base.js +55 -0
  271. package/dist/types/base.js.map +1 -0
  272. package/dist/types/base.mjs +50 -0
  273. package/dist/types/base.mjs.map +1 -0
  274. package/dist/types/method-types.d.ts +258 -0
  275. package/dist/types/method-types.d.ts.map +1 -0
  276. package/dist/utils/oauth/completion.d.ts +132 -0
  277. package/dist/utils/oauth/completion.d.ts.map +1 -0
  278. package/dist/utils/oauth/completion.js +136 -0
  279. package/dist/utils/oauth/completion.js.map +1 -0
  280. package/dist/utils/oauth/completion.mjs +176 -0
  281. package/dist/utils/oauth/completion.mjs.map +1 -0
  282. package/dist/utils/oauth/config.d.ts +34 -0
  283. package/dist/utils/oauth/config.d.ts.map +1 -0
  284. package/dist/utils/oauth/config.js +69 -0
  285. package/dist/utils/oauth/config.js.map +1 -0
  286. package/dist/utils/oauth/config.mjs +54 -0
  287. package/dist/utils/oauth/config.mjs.map +1 -0
  288. package/dist/utils/oauth/helpers.d.ts +13 -0
  289. package/dist/utils/oauth/helpers.d.ts.map +1 -0
  290. package/dist/utils/oauth/helpers.js +38 -0
  291. package/dist/utils/oauth/helpers.js.map +1 -0
  292. package/dist/utils/oauth/helpers.mjs +35 -0
  293. package/dist/utils/oauth/helpers.mjs.map +1 -0
  294. package/dist/utils/oauth/index.d.ts +7 -0
  295. package/dist/utils/oauth/index.d.ts.map +1 -0
  296. package/dist/utils/oauth/pkce.d.ts +14 -0
  297. package/dist/utils/oauth/pkce.d.ts.map +1 -0
  298. package/dist/utils/oauth/pkce.js +48 -0
  299. package/dist/utils/oauth/pkce.js.map +1 -0
  300. package/dist/utils/oauth/pkce.mjs +85 -0
  301. package/dist/utils/oauth/pkce.mjs.map +1 -0
  302. package/dist/utils/oauth/storage.d.ts +48 -0
  303. package/dist/utils/oauth/storage.d.ts.map +1 -0
  304. package/dist/utils/oauth/storage.js +87 -0
  305. package/dist/utils/oauth/storage.js.map +1 -0
  306. package/dist/utils/oauth/storage.mjs +78 -0
  307. package/dist/utils/oauth/storage.mjs.map +1 -0
  308. package/dist/utils/oauth/url.d.ts +94 -0
  309. package/dist/utils/oauth/url.d.ts.map +1 -0
  310. package/dist/utils/oauth/url.js +224 -0
  311. package/dist/utils/oauth/url.js.map +1 -0
  312. package/dist/utils/oauth/url.mjs +230 -0
  313. package/dist/utils/oauth/url.mjs.map +1 -0
  314. package/dist/utils/timers.d.ts +73 -0
  315. package/dist/utils/timers.d.ts.map +1 -0
  316. package/dist/utils/timers.js +133 -0
  317. package/dist/utils/timers.js.map +1 -0
  318. package/dist/utils/timers.mjs +142 -0
  319. package/dist/utils/timers.mjs.map +1 -0
  320. package/dist/utils/utils.d.ts +40 -0
  321. package/dist/utils/utils.d.ts.map +1 -0
  322. package/dist/utils/utils.js +116 -0
  323. package/dist/utils/utils.js.map +1 -0
  324. package/dist/utils/utils.mjs +164 -0
  325. package/dist/utils/utils.mjs.map +1 -0
  326. package/package.json +91 -0
@@ -0,0 +1,230 @@
1
+ import { createForOfIteratorHelper as _createForOfIteratorHelper, slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.mjs';
2
+ import { OAuthProviders } from '@0xkey-io/sdk-types';
3
+ import { OAUTH_PROVIDER_CONFIGS, popupWidth, popupHeight } from './config.mjs';
4
+
5
+ /**
6
+ * Builds the OAuth state parameter string
7
+ */
8
+ function buildOAuthState(params) {
9
+ var provider = params.provider,
10
+ flow = params.flow,
11
+ publicKey = params.publicKey,
12
+ nonce = params.nonce,
13
+ additionalState = params.additionalState;
14
+ var state = "provider=".concat(provider, "&flow=").concat(flow, "&publicKey=").concat(encodeURIComponent(publicKey));
15
+ if (nonce) {
16
+ state += "&nonce=".concat(nonce);
17
+ }
18
+ if (additionalState) {
19
+ var extra = Object.entries(additionalState).map(function (_ref) {
20
+ var _ref2 = _slicedToArray(_ref, 2),
21
+ k = _ref2[0],
22
+ v = _ref2[1];
23
+ return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(v));
24
+ }).join("&");
25
+ if (extra) {
26
+ state += "&".concat(extra);
27
+ }
28
+ }
29
+ return state;
30
+ }
31
+ /**
32
+ * Opens a centered OAuth popup window
33
+ */
34
+ function openOAuthPopup() {
35
+ var width = popupWidth;
36
+ var height = popupHeight;
37
+ var left = window.screenX + (window.innerWidth - width) / 2;
38
+ var top = window.screenY + (window.innerHeight - height) / 2;
39
+ return window.open("about:blank", "_blank", "width=".concat(width, ",height=").concat(height, ",top=").concat(top, ",left=").concat(left, ",scrollbars=yes,resizable=yes"));
40
+ }
41
+ /**
42
+ * Redirects to OAuth provider URL
43
+ */
44
+ function redirectToOAuthProvider(url) {
45
+ window.location.href = url;
46
+ var timeLimit = 5 * 60 * 1000; // 5 minutes
47
+ return new Promise(function (_, reject) {
48
+ var timeout = setTimeout(function () {
49
+ reject(new Error("Authentication timed out."));
50
+ }, timeLimit);
51
+ window.addEventListener("beforeunload", function () {
52
+ return clearTimeout(timeout);
53
+ });
54
+ });
55
+ }
56
+ /**
57
+ * Cleans up OAuth parameters from URL (removes hash and search)
58
+ */
59
+ function cleanupOAuthUrl() {
60
+ window.history.replaceState(null, document.title, window.location.pathname);
61
+ }
62
+ /**
63
+ * Cleans up OAuth hash from URL but preserves search parameters
64
+ */
65
+ function cleanupOAuthUrlPreserveSearch() {
66
+ window.history.replaceState(null, document.title, window.location.pathname + window.location.search);
67
+ }
68
+ /**
69
+ * Parses the OAuth state parameter string into an object
70
+ */
71
+ function parseStateParam(stateParam) {
72
+ if (!stateParam) return {};
73
+ var result = {};
74
+ var pairs = stateParam.split("&");
75
+ var _iterator = _createForOfIteratorHelper(pairs),
76
+ _step;
77
+ try {
78
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
79
+ var pair = _step.value;
80
+ var _pair$split = pair.split("="),
81
+ _pair$split2 = _slicedToArray(_pair$split, 2),
82
+ key = _pair$split2[0],
83
+ value = _pair$split2[1];
84
+ if (key && value !== undefined) {
85
+ result[key] = decodeURIComponent(value);
86
+ }
87
+ }
88
+ } catch (err) {
89
+ _iterator.e(err);
90
+ } finally {
91
+ _iterator.f();
92
+ }
93
+ return result;
94
+ }
95
+ /**
96
+ * Unified OAuth response parser for both popup and redirect flows.
97
+ * Handles both:
98
+ * - PKCE flows (Facebook, Discord, X): code in search parameters
99
+ * - Non-PKCE flows (Google, Apple): id_token in hash parameters
100
+ * - Apple's non-standard hash format where state parameters are directly embedded
101
+ *
102
+ * @param url - The full URL to parse (from popup or redirect)
103
+ * @param expectedProvider - Optional provider if already known (for popup flows)
104
+ * @returns Parsed OAuth response data including tokens, codes, and state parameters, or null if invalid
105
+ */
106
+ function parseOAuthResponse(url, expectedProvider) {
107
+ var idToken = null;
108
+ var authCode = null;
109
+ var stateString = null;
110
+ var parsedUrl = new URL(url);
111
+ var search = parsedUrl.search.substring(1); // Remove leading '?'
112
+ var hash = parsedUrl.hash.substring(1); // Remove leading '#'
113
+ // Handle PKCE flows (code in search parameters)
114
+ if (search && search.includes("code=")) {
115
+ var searchParams = new URLSearchParams(search);
116
+ authCode = searchParams.get("code");
117
+ stateString = searchParams.get("state");
118
+ }
119
+ // Handle non-PKCE flows (id_token in hash)
120
+ else if (hash) {
121
+ // Handle Apple's non-standard format: state=provider=apple&flow=redirect&...&code=...&id_token=...
122
+ if (hash.startsWith("state=provider=apple")) {
123
+ // Extract id_token from the end
124
+ var idTokenMatch = hash.match(/id_token=([^&]+)$/);
125
+ idToken = idTokenMatch ? idTokenMatch[1] : null;
126
+ // Extract state content between "state=" and "&code="
127
+ var stateEndIndex = hash.indexOf("&code=");
128
+ if (stateEndIndex !== -1) {
129
+ stateString = hash.substring(6, stateEndIndex); // Remove "state=" prefix
130
+ }
131
+ } else {
132
+ // Standard OAuth format - parse as URLSearchParams
133
+ var hashParams = new URLSearchParams(hash);
134
+ idToken = hashParams.get("id_token");
135
+ stateString = hashParams.get("state");
136
+ }
137
+ }
138
+ // Parse state parameters
139
+ var _parseStateParam = parseStateParam(stateString),
140
+ provider = _parseStateParam.provider,
141
+ flow = _parseStateParam.flow,
142
+ publicKey = _parseStateParam.publicKey,
143
+ openModal = _parseStateParam.openModal,
144
+ sessionKey = _parseStateParam.sessionKey,
145
+ oauthIntent = _parseStateParam.oauthIntent,
146
+ nonce = _parseStateParam.nonce,
147
+ redirectUri = _parseStateParam.redirectUri;
148
+ // If we have an expected provider (popup flow), validate it matches
149
+ if (expectedProvider) {
150
+ var config = OAUTH_PROVIDER_CONFIGS[expectedProvider];
151
+ if (config.usesPKCE) {
152
+ // PKCE providers must have authCode and matching provider in state
153
+ if (!authCode || !stateString || provider !== expectedProvider) {
154
+ return null;
155
+ }
156
+ } else {
157
+ // Non-PKCE providers must have idToken
158
+ if (!idToken) {
159
+ return null;
160
+ }
161
+ }
162
+ }
163
+ return {
164
+ idToken: idToken,
165
+ authCode: authCode,
166
+ provider: provider !== null && provider !== void 0 ? provider : null,
167
+ flow: flow !== null && flow !== void 0 ? flow : null,
168
+ publicKey: publicKey !== null && publicKey !== void 0 ? publicKey : null,
169
+ openModal: openModal !== null && openModal !== void 0 ? openModal : null,
170
+ sessionKey: sessionKey !== null && sessionKey !== void 0 ? sessionKey : undefined,
171
+ oauthIntent: oauthIntent !== null && oauthIntent !== void 0 ? oauthIntent : null,
172
+ nonce: nonce !== null && nonce !== void 0 ? nonce : null,
173
+ redirectUri: redirectUri !== null && redirectUri !== void 0 ? redirectUri : null
174
+ };
175
+ }
176
+ /**
177
+ * Builds the complete OAuth authorization URL for a provider
178
+ */
179
+ function buildOAuthUrl(params) {
180
+ var provider = params.provider,
181
+ clientId = params.clientId,
182
+ redirectUri = params.redirectUri,
183
+ publicKey = params.publicKey,
184
+ nonce = params.nonce,
185
+ flow = params.flow,
186
+ codeChallenge = params.codeChallenge,
187
+ additionalState = params.additionalState;
188
+ var config = OAUTH_PROVIDER_CONFIGS[provider];
189
+ var authUrl = new URL(config.authUrl);
190
+ authUrl.searchParams.set("client_id", clientId);
191
+ authUrl.searchParams.set("redirect_uri", redirectUri);
192
+ authUrl.searchParams.set("response_type", config.responseType);
193
+ if (config.scopes) {
194
+ authUrl.searchParams.set("scope", config.scopes);
195
+ }
196
+ if (config.responseMode) {
197
+ authUrl.searchParams.set("response_mode", config.responseMode);
198
+ }
199
+ // PKCE parameters
200
+ if (config.usesPKCE && codeChallenge) {
201
+ authUrl.searchParams.set("code_challenge", codeChallenge);
202
+ authUrl.searchParams.set("code_challenge_method", "S256");
203
+ }
204
+ // Nonce handling - some providers want it in URL params, others in state
205
+ if (config.nonceInParams) {
206
+ authUrl.searchParams.set("nonce", nonce);
207
+ }
208
+ // Google-specific: prompt for account selection
209
+ if (provider === OAuthProviders.GOOGLE) {
210
+ authUrl.searchParams.set("prompt", "select_account");
211
+ }
212
+ // Build state parameter
213
+ var stateParams = {
214
+ provider: provider,
215
+ flow: flow,
216
+ publicKey: publicKey
217
+ };
218
+ // Include nonce in state for providers that need it there (not in URL params)
219
+ if (!config.nonceInParams) {
220
+ stateParams.nonce = nonce;
221
+ }
222
+ if (additionalState) {
223
+ stateParams.additionalState = additionalState;
224
+ }
225
+ authUrl.searchParams.set("state", buildOAuthState(stateParams));
226
+ return authUrl.toString();
227
+ }
228
+
229
+ export { buildOAuthState, buildOAuthUrl, cleanupOAuthUrl, cleanupOAuthUrlPreserveSearch, openOAuthPopup, parseOAuthResponse, parseStateParam, redirectToOAuthProvider };
230
+ //# sourceMappingURL=url.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.mjs","sources":["../../../src/utils/oauth/url.ts"],"sourcesContent":[null],"names":["buildOAuthState","params","provider","flow","publicKey","nonce","additionalState","state","concat","encodeURIComponent","extra","Object","entries","map","_ref","_ref2","_slicedToArray","k","v","join","openOAuthPopup","width","popupWidth","height","popupHeight","left","window","screenX","innerWidth","top","screenY","innerHeight","open","redirectToOAuthProvider","url","location","href","timeLimit","Promise","_","reject","timeout","setTimeout","Error","addEventListener","clearTimeout","cleanupOAuthUrl","history","replaceState","document","title","pathname","cleanupOAuthUrlPreserveSearch","search","parseStateParam","stateParam","result","pairs","split","_iterator","_createForOfIteratorHelper","_step","s","n","done","pair","value","_pair$split","_pair$split2","key","undefined","decodeURIComponent","err","e","f","parseOAuthResponse","expectedProvider","idToken","authCode","stateString","parsedUrl","URL","substring","hash","includes","searchParams","URLSearchParams","get","startsWith","idTokenMatch","match","stateEndIndex","indexOf","hashParams","_parseStateParam","openModal","sessionKey","oauthIntent","redirectUri","config","OAUTH_PROVIDER_CONFIGS","usesPKCE","buildOAuthUrl","clientId","codeChallenge","authUrl","set","responseType","scopes","responseMode","nonceInParams","OAuthProviders","GOOGLE","stateParams","toString"],"mappings":";;;;AAGA;;AAEG;AACG,SAAUA,eAAeA,CAACC,MAM/B,EAAA;AACC,EAAA,IAAQC,QAAQ,GAA8CD,MAAM,CAA5DC,QAAQ;IAAEC,IAAI,GAAwCF,MAAM,CAAlDE,IAAI;IAAEC,SAAS,GAA6BH,MAAM,CAA5CG,SAAS;IAAEC,KAAK,GAAsBJ,MAAM,CAAjCI,KAAK;IAAEC,eAAe,GAAKL,MAAM,CAA1BK,eAAe;AACzD,EAAA,IAAIC,KAAK,GAAA,WAAA,CAAAC,MAAA,CAAeN,QAAQ,YAAAM,MAAA,CAASL,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CAACU,YAAY,CAAC;AAChE,EAAA;AAEA;AACA,EAAA,IAAIV,MAAM,CAACE,QAAQ,IAAIG,aAAa,EAAE;IACpCC,OAAO,CAACpB,YAAY,CAACqB,GAAG,CAAC,gBAAgB,EAAEF,aAAa,CAAC;IACzDC,OAAO,CAACpB,YAAY,CAACqB,GAAG,CAAC,uBAAuB,EAAE,MAAM,CAAC;AAC3D,EAAA;AAEA;EACA,IAAIP,MAAM,CAACW,aAAa,EAAE;IACxBL,OAAO,CAACpB,YAAY,CAACqB,GAAG,CAAC,OAAO,EAAErG,KAAK,CAAC;AAC1C,EAAA;AAEA;AACA,EAAA,IAAIH,QAAQ,KAAK6G,cAAc,CAACC,MAAM,EAAE;IACtCP,OAAO,CAACpB,YAAY,CAACqB,GAAG,CAAC,QAAQ,EAAE,gBAAgB,CAAC;AACtD,EAAA;AAEA;AACA,EAAA,IAAMO,WAAW,GAA0C;AACzD/G,IAAAA,QAAQ,EAARA,QAAQ;AACRC,IAAAA,IAAI,EAAJA,IAAI;AACJC,IAAAA,SAAS,EAATA;GACD;AACD;AACA,EAAA,IAAI,CAAC+F,MAAM,CAACW,aAAa,EAAE;IACzBG,WAAW,CAAC5G,KAAK,GAAGA,KAAK;AAC3B,EAAA;AACA,EAAA,IAAIC,eAAe,EAAE;IACnB2G,WAAW,CAAC3G,eAAe,GAAGA,eAAe;AAC/C,EAAA;EACAmG,OAAO,CAACpB,YAAY,CAACqB,GAAG,CAAC,OAAO,EAAE1G,eAAe,CAACiH,WAAW,CAAC,CAAC;AAE/D,EAAA,OAAOR,OAAO,CAACS,QAAQ,EAAE;AAC3B;;;;"}
@@ -0,0 +1,73 @@
1
+ export type TimerController = {
2
+ clear: () => void;
3
+ };
4
+ export type TimerMap = Record<string, TimerController>;
5
+ export declare const MAX_DELAY_MS = 2147483647;
6
+ /**
7
+ * @internal A drop-in replacement for `setTimeout` that supports arbitrarily long delays.
8
+ *
9
+ * ### Why?
10
+ * Browsers clamp `setTimeout` delays to a 32-bit signed integer,
11
+ * i.e. a maximum of ~24.8 days (`2_147_483_647ms`). Any larger value
12
+ * will fire almost immediately. This helper safely schedules timeouts
13
+ * that can be months or years into the future.
14
+ *
15
+ * ### How it works
16
+ * - On call, we record a fixed **target timestamp** (`now + delayMs`).
17
+ * - We schedule a single "leg" of at most ~24.8 days into the future,
18
+ * with an internal `tick` function as the callback.
19
+ * - When a leg expires, `tick` checks how much time is left:
20
+ * - If `remaining > 0`, it schedules the next leg (`min(MAX_DELAY_MS, remaining)`).
21
+ * - If `remaining <= 0`, the full delay has passed and we finally call your `cb()`.
22
+ * - At any time, only **one** leg is active. Calling `.clear()` cancels
23
+ * the current leg and prevents further hops.
24
+ *
25
+ * ### Benefits
26
+ * - Works seamlessly for both short and very long delays.
27
+ * - Survives tab sleep / system suspend: when the tab wakes,
28
+ * `tick` re-checks the target timestamp and fires immediately if overdue.
29
+ * - No drift accumulation: each hop recalculates based on the fixed target,
30
+ * so you always land as close as possible to the intended deadline.
31
+ *
32
+ * ### Example
33
+ * ```ts
34
+ * const controller = setCappedTimeout(() => {
35
+ * console.log("A whole year later!");
36
+ * }, 1000 * 60 * 60 * 24 * 365);
37
+ *
38
+ * // Cancel if needed
39
+ * controller.clear();
40
+ * ```
41
+ *
42
+ * @param cb - Function to run once the full delay has elapsed.
43
+ * @param delayMs - Delay in milliseconds (can exceed 2_147_483_647).
44
+ * @returns A controller with a `.clear()` method to cancel the timeout.
45
+ */
46
+ export declare function setCappedTimeout(cb: () => void, delayMs: number): TimerController;
47
+ /** @internal Simple one-shot timeout that still returns a controller for uniformity. */
48
+ export declare function setTimeoutController(cb: () => void, delayMs: number): TimerController;
49
+ /** @internal Replace any existing timer for `key` with `controller`. */
50
+ export declare function putTimer(map: TimerMap, key: string, controller: TimerController): void;
51
+ /** @internal Clear a specific key (noop if missing). */
52
+ export declare function clearKey(map: TimerMap, key: string): void;
53
+ /** @internal Clear several keys at once (noop on missing). */
54
+ export declare function clearKeys(map: TimerMap, keys: string[]): void;
55
+ /** @internal Clear all timers in the map. */
56
+ export declare function clearAll(map: TimerMap): void;
57
+ /**
58
+ * @internal Convenience: set a capped timeout directly into the map for `key`.
59
+ * @param map The map to store the timer in (pass in the ref to the timer map)
60
+ * @param key The key to associate with the timer
61
+ * @param cb The callback to invoke when the timer expires
62
+ * @param delayMs The delay in milliseconds before the timer expires
63
+ * */
64
+ export declare function setCappedTimeoutInMap(map: TimerMap, key: string, cb: () => void, delayMs: number): void;
65
+ /**
66
+ * @internal Convenience: set a regular (short) timeout into the map for `key`.
67
+ * @param map The map to store the timer in (pass in the ref to the timer map)
68
+ * @param key The key to associate with the timer
69
+ * @param cb The callback to invoke when the timer expires
70
+ * @param delayMs The delay in milliseconds before the timer expires
71
+ */
72
+ export declare function setTimeoutInMap(map: TimerMap, key: string, cb: () => void, delayMs: number): void;
73
+ //# sourceMappingURL=timers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timers.d.ts","sourceRoot":"","sources":["../../src/utils/timers.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,IAAI,CAAA;CAAE,CAAC;AACpD,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAEvD,eAAO,MAAM,YAAY,aAAgB,CAAC;AAO1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,MAAM,IAAI,EACd,OAAO,EAAE,MAAM,GACd,eAAe,CAuBjB;AAED,wFAAwF;AACxF,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,MAAM,IAAI,EACd,OAAO,EAAE,MAAM,GACd,eAAe,CAIjB;AAED,wEAAwE;AACxE,wBAAgB,QAAQ,CACtB,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,eAAe,QAI5B;AAED,wDAAwD;AACxD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,QAGlD;AAED,8DAA8D;AAC9D,wBAAgB,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,QAEtD;AAED,6CAA6C;AAC7C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,QAKrC;AAED;;;;;;KAMK;AACL,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,IAAI,EACd,OAAO,EAAE,MAAM,QAGhB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,IAAI,EACd,OAAO,EAAE,MAAM,QAGhB"}
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+
3
+ // This file contains utility functions for managing timers and timeouts for session management.
4
+ // Unfortunately, the delay param in Node Timeouts is a 32-bit signed integer, meaning it can only represent delays up to ~24.8 days.
5
+ // This file provides functions to handle long delays by breaking them into smaller chunks.
6
+ // These functions are separate from the normal utils function to reduce clutter and improve visibility.
7
+ // Use `setTimeoutInMap` for short, frequent nudges (10s), and `setCappedTimeoutInMap` for anything that could exceed ~24.8 days.
8
+ const MAX_DELAY_MS = 2_147_483_647; // ~24.8 days
9
+ /** @internal */
10
+ function toIntMs(x) {
11
+ return Math.max(0, Math.floor(Number.isFinite(x) ? x : 0));
12
+ }
13
+ /**
14
+ * @internal A drop-in replacement for `setTimeout` that supports arbitrarily long delays.
15
+ *
16
+ * ### Why?
17
+ * Browsers clamp `setTimeout` delays to a 32-bit signed integer,
18
+ * i.e. a maximum of ~24.8 days (`2_147_483_647ms`). Any larger value
19
+ * will fire almost immediately. This helper safely schedules timeouts
20
+ * that can be months or years into the future.
21
+ *
22
+ * ### How it works
23
+ * - On call, we record a fixed **target timestamp** (`now + delayMs`).
24
+ * - We schedule a single "leg" of at most ~24.8 days into the future,
25
+ * with an internal `tick` function as the callback.
26
+ * - When a leg expires, `tick` checks how much time is left:
27
+ * - If `remaining > 0`, it schedules the next leg (`min(MAX_DELAY_MS, remaining)`).
28
+ * - If `remaining <= 0`, the full delay has passed and we finally call your `cb()`.
29
+ * - At any time, only **one** leg is active. Calling `.clear()` cancels
30
+ * the current leg and prevents further hops.
31
+ *
32
+ * ### Benefits
33
+ * - Works seamlessly for both short and very long delays.
34
+ * - Survives tab sleep / system suspend: when the tab wakes,
35
+ * `tick` re-checks the target timestamp and fires immediately if overdue.
36
+ * - No drift accumulation: each hop recalculates based on the fixed target,
37
+ * so you always land as close as possible to the intended deadline.
38
+ *
39
+ * ### Example
40
+ * ```ts
41
+ * const controller = setCappedTimeout(() => {
42
+ * console.log("A whole year later!");
43
+ * }, 1000 * 60 * 60 * 24 * 365);
44
+ *
45
+ * // Cancel if needed
46
+ * controller.clear();
47
+ * ```
48
+ *
49
+ * @param cb - Function to run once the full delay has elapsed.
50
+ * @param delayMs - Delay in milliseconds (can exceed 2_147_483_647).
51
+ * @returns A controller with a `.clear()` method to cancel the timeout.
52
+ */
53
+ function setCappedTimeout(cb, delayMs) {
54
+ const target = Date.now() + toIntMs(delayMs);
55
+ let handle;
56
+ const tick = () => {
57
+ const remaining = target - Date.now();
58
+ if (remaining <= 0) {
59
+ cb();
60
+ return;
61
+ }
62
+ handle = window.setTimeout(tick, Math.min(MAX_DELAY_MS, remaining));
63
+ };
64
+ tick();
65
+ return {
66
+ clear() {
67
+ if (handle !== undefined) {
68
+ window.clearTimeout(handle);
69
+ handle = undefined;
70
+ }
71
+ }
72
+ };
73
+ }
74
+ /** @internal Simple one-shot timeout that still returns a controller for uniformity. */
75
+ function setTimeoutController(cb, delayMs) {
76
+ const ms = toIntMs(delayMs);
77
+ let id = window.setTimeout(cb, ms);
78
+ return {
79
+ clear: () => window.clearTimeout(id)
80
+ };
81
+ }
82
+ /** @internal Replace any existing timer for `key` with `controller`. */
83
+ function putTimer(map, key, controller) {
84
+ map[key]?.clear?.();
85
+ map[key] = controller;
86
+ }
87
+ /** @internal Clear a specific key (noop if missing). */
88
+ function clearKey(map, key) {
89
+ map[key]?.clear?.();
90
+ delete map[key];
91
+ }
92
+ /** @internal Clear several keys at once (noop on missing). */
93
+ function clearKeys(map, keys) {
94
+ for (const k of keys) clearKey(map, k);
95
+ }
96
+ /** @internal Clear all timers in the map. */
97
+ function clearAll(map) {
98
+ for (const k of Object.keys(map)) {
99
+ map[k]?.clear?.();
100
+ delete map[k];
101
+ }
102
+ }
103
+ /**
104
+ * @internal Convenience: set a capped timeout directly into the map for `key`.
105
+ * @param map The map to store the timer in (pass in the ref to the timer map)
106
+ * @param key The key to associate with the timer
107
+ * @param cb The callback to invoke when the timer expires
108
+ * @param delayMs The delay in milliseconds before the timer expires
109
+ * */
110
+ function setCappedTimeoutInMap(map, key, cb, delayMs) {
111
+ putTimer(map, key, setCappedTimeout(cb, delayMs));
112
+ }
113
+ /**
114
+ * @internal Convenience: set a regular (short) timeout into the map for `key`.
115
+ * @param map The map to store the timer in (pass in the ref to the timer map)
116
+ * @param key The key to associate with the timer
117
+ * @param cb The callback to invoke when the timer expires
118
+ * @param delayMs The delay in milliseconds before the timer expires
119
+ */
120
+ function setTimeoutInMap(map, key, cb, delayMs) {
121
+ putTimer(map, key, setTimeoutController(cb, delayMs));
122
+ }
123
+
124
+ exports.MAX_DELAY_MS = MAX_DELAY_MS;
125
+ exports.clearAll = clearAll;
126
+ exports.clearKey = clearKey;
127
+ exports.clearKeys = clearKeys;
128
+ exports.putTimer = putTimer;
129
+ exports.setCappedTimeout = setCappedTimeout;
130
+ exports.setCappedTimeoutInMap = setCappedTimeoutInMap;
131
+ exports.setTimeoutController = setTimeoutController;
132
+ exports.setTimeoutInMap = setTimeoutInMap;
133
+ //# sourceMappingURL=timers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timers.js","sources":["../../src/utils/timers.ts"],"sourcesContent":[null],"names":["MAX_DELAY_MS","toIntMs","x","Math","max","floor","Number","isFinite","setCappedTimeout","cb","delayMs","target","Date","now","handle","tick","remaining","window","setTimeout","min","clear","undefined","clearTimeout","setTimeoutController","ms","id","putTimer","map","key","controller","clearKey","clearKeys","keys","k","clearAll","Object","setCappedTimeoutInMap","setTimeoutInMap"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAMO,MAAMA,YAAY,GAAG,cAAc;AAE1C;AACA,SAASC,OAAOA,CAACC,CAAS,EAAA;EACxB,OAAOC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,KAAK,CAACC,MAAM,CAACC,QAAQ,CAACL,CAAC,CAAC,GAAGA,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5D;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCG;AACG,SAAUM,gBAAgBA,CAC9BC,EAAc,EACdC,OAAe,EAAA;EAEf,MAAMC,MAAM,GAAGC,IAAI,CAACC,GAAG,EAAE,GAAGZ,OAAO,CAACS,OAAO,CAAC;AAC5C,EAAA,IAAII,MAA0B;EAE9B,MAAMC,IAAI,GAAGA,MAAK;IAChB,MAAMC,SAAS,GAAGL,MAAM,GAAGC,IAAI,CAACC,GAAG,EAAE;IACrC,IAAIG,SAAS,IAAI,CAAC,EAAE;AAClBP,MAAAA,EAAE,EAAE;AACJ,MAAA;AACF,IAAA;AACAK,IAAAA,MAAM,GAAGG,MAAM,CAACC,UAAU,CAACH,IAAI,EAAEZ,IAAI,CAACgB,GAAG,CAACnB,YAAY,EAAEgB,SAAS,CAAC,CAAC;EACrE,CAAC;AAEDD,EAAAA,IAAI,EAAE;EAEN,OAAO;AACLK,IAAAA,KAAKA,GAAA;MACH,IAAIN,MAAM,KAAKO,SAAS,EAAE;AACxBJ,QAAAA,MAAM,CAACK,YAAY,CAACR,MAAM,CAAC;AAC3BA,QAAAA,MAAM,GAAGO,SAAS;AACpB,MAAA;AACF,IAAA;GACD;AACH;AAEA;AACM,SA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EACbC,GAAW,EACXnB,EAAc,EACdC,OAAe,EAAA;EAEfgB,QAAQ,CAACC,GAAG,EAAEC,GAAG,EAAEL,oBAAoB,CAACd,EAAE,EAAEC,OAAO,CAAC,CAAC;AACvD;;;;;;;;;;;;"}
@@ -0,0 +1,142 @@
1
+ import { createForOfIteratorHelper as _createForOfIteratorHelper } from '../_virtual/_rollupPluginBabelHelpers.mjs';
2
+
3
+ // This file contains utility functions for managing timers and timeouts for session management.
4
+ // Unfortunately, the delay param in Node Timeouts is a 32-bit signed integer, meaning it can only represent delays up to ~24.8 days.
5
+ // This file provides functions to handle long delays by breaking them into smaller chunks.
6
+ // These functions are separate from the normal utils function to reduce clutter and improve visibility.
7
+ // Use `setTimeoutInMap` for short, frequent nudges (10s), and `setCappedTimeoutInMap` for anything that could exceed ~24.8 days.
8
+ var MAX_DELAY_MS = 2147483647; // ~24.8 days
9
+ /** @internal */
10
+ function toIntMs(x) {
11
+ return Math.max(0, Math.floor(Number.isFinite(x) ? x : 0));
12
+ }
13
+ /**
14
+ * @internal A drop-in replacement for `setTimeout` that supports arbitrarily long delays.
15
+ *
16
+ * ### Why?
17
+ * Browsers clamp `setTimeout` delays to a 32-bit signed integer,
18
+ * i.e. a maximum of ~24.8 days (`2_147_483_647ms`). Any larger value
19
+ * will fire almost immediately. This helper safely schedules timeouts
20
+ * that can be months or years into the future.
21
+ *
22
+ * ### How it works
23
+ * - On call, we record a fixed **target timestamp** (`now + delayMs`).
24
+ * - We schedule a single "leg" of at most ~24.8 days into the future,
25
+ * with an internal `tick` function as the callback.
26
+ * - When a leg expires, `tick` checks how much time is left:
27
+ * - If `remaining > 0`, it schedules the next leg (`min(MAX_DELAY_MS, remaining)`).
28
+ * - If `remaining <= 0`, the full delay has passed and we finally call your `cb()`.
29
+ * - At any time, only **one** leg is active. Calling `.clear()` cancels
30
+ * the current leg and prevents further hops.
31
+ *
32
+ * ### Benefits
33
+ * - Works seamlessly for both short and very long delays.
34
+ * - Survives tab sleep / system suspend: when the tab wakes,
35
+ * `tick` re-checks the target timestamp and fires immediately if overdue.
36
+ * - No drift accumulation: each hop recalculates based on the fixed target,
37
+ * so you always land as close as possible to the intended deadline.
38
+ *
39
+ * ### Example
40
+ * ```ts
41
+ * const controller = setCappedTimeout(() => {
42
+ * console.log("A whole year later!");
43
+ * }, 1000 * 60 * 60 * 24 * 365);
44
+ *
45
+ * // Cancel if needed
46
+ * controller.clear();
47
+ * ```
48
+ *
49
+ * @param cb - Function to run once the full delay has elapsed.
50
+ * @param delayMs - Delay in milliseconds (can exceed 2_147_483_647).
51
+ * @returns A controller with a `.clear()` method to cancel the timeout.
52
+ */
53
+ function setCappedTimeout(cb, delayMs) {
54
+ var target = Date.now() + toIntMs(delayMs);
55
+ var handle;
56
+ var _tick = function tick() {
57
+ var remaining = target - Date.now();
58
+ if (remaining <= 0) {
59
+ cb();
60
+ return;
61
+ }
62
+ handle = window.setTimeout(_tick, Math.min(MAX_DELAY_MS, remaining));
63
+ };
64
+ _tick();
65
+ return {
66
+ clear: function clear() {
67
+ if (handle !== undefined) {
68
+ window.clearTimeout(handle);
69
+ handle = undefined;
70
+ }
71
+ }
72
+ };
73
+ }
74
+ /** @internal Simple one-shot timeout that still returns a controller for uniformity. */
75
+ function setTimeoutController(cb, delayMs) {
76
+ var ms = toIntMs(delayMs);
77
+ var id = window.setTimeout(cb, ms);
78
+ return {
79
+ clear: function clear() {
80
+ return window.clearTimeout(id);
81
+ }
82
+ };
83
+ }
84
+ /** @internal Replace any existing timer for `key` with `controller`. */
85
+ function putTimer(map, key, controller) {
86
+ var _map$key, _map$key$clear;
87
+ (_map$key = map[key]) === null || _map$key === void 0 ? void 0 : (_map$key$clear = _map$key.clear) === null || _map$key$clear === void 0 ? void 0 : _map$key$clear.call(_map$key);
88
+ map[key] = controller;
89
+ }
90
+ /** @internal Clear a specific key (noop if missing). */
91
+ function clearKey(map, key) {
92
+ var _map$key2, _map$key2$clear;
93
+ (_map$key2 = map[key]) === null || _map$key2 === void 0 ? void 0 : (_map$key2$clear = _map$key2.clear) === null || _map$key2$clear === void 0 ? void 0 : _map$key2$clear.call(_map$key2);
94
+ delete map[key];
95
+ }
96
+ /** @internal Clear several keys at once (noop on missing). */
97
+ function clearKeys(map, keys) {
98
+ var _iterator = _createForOfIteratorHelper(keys),
99
+ _step;
100
+ try {
101
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
102
+ var k = _step.value;
103
+ clearKey(map, k);
104
+ }
105
+ } catch (err) {
106
+ _iterator.e(err);
107
+ } finally {
108
+ _iterator.f();
109
+ }
110
+ }
111
+ /** @internal Clear all timers in the map. */
112
+ function clearAll(map) {
113
+ for (var _i = 0, _Object$keys = Object.keys(map); _i < _Object$keys.length; _i++) {
114
+ var _map$k, _map$k$clear;
115
+ var k = _Object$keys[_i];
116
+ (_map$k = map[k]) === null || _map$k === void 0 ? void 0 : (_map$k$clear = _map$k.clear) === null || _map$k$clear === void 0 ? void 0 : _map$k$clear.call(_map$k);
117
+ delete map[k];
118
+ }
119
+ }
120
+ /**
121
+ * @internal Convenience: set a capped timeout directly into the map for `key`.
122
+ * @param map The map to store the timer in (pass in the ref to the timer map)
123
+ * @param key The key to associate with the timer
124
+ * @param cb The callback to invoke when the timer expires
125
+ * @param delayMs The delay in milliseconds before the timer expires
126
+ * */
127
+ function setCappedTimeoutInMap(map, key, cb, delayMs) {
128
+ putTimer(map, key, setCappedTimeout(cb, delayMs));
129
+ }
130
+ /**
131
+ * @internal Convenience: set a regular (short) timeout into the map for `key`.
132
+ * @param map The map to store the timer in (pass in the ref to the timer map)
133
+ * @param key The key to associate with the timer
134
+ * @param cb The callback to invoke when the timer expires
135
+ * @param delayMs The delay in milliseconds before the timer expires
136
+ */
137
+ function setTimeoutInMap(map, key, cb, delayMs) {
138
+ putTimer(map, key, setTimeoutController(cb, delayMs));
139
+ }
140
+
141
+ export { MAX_DELAY_MS, clearAll, clearKey, clearKeys, putTimer, setCappedTimeout, setCappedTimeoutInMap, setTimeoutController, setTimeoutInMap };
142
+ //# sourceMappingURL=timers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timers.mjs","sources":["../../src/utils/timers.ts"],"sourcesContent":[null],"names":["MAX_DELAY_MS","toIntMs","x","Math","max","floor","Number","isFinite","setCappedTimeout","cb","delayMs","target","Date","now","handle","tick","remaining","window","setTimeout","min","clear","undefined","clearTimeout","setTimeoutController","ms","id","putTimer","map","key","controller","_map$key","_map$key$clear","call","clearKey","_map$key2","_map$key2$clear","clearKeys","keys","_iterator","_createForOfIteratorHelper","_step","s","n","done","k","value","err","e","f","clearAll","_i","_Object$keys","Object","length","_map$k","_map$k$clear","setCappedTimeoutInMap","setTimeoutInMap"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAMO,IAAMA,YAAY,GAAG,WAAc;AAE1C;AACA,SAASC,OAAOA,CAACC,CAAS,EAAA;EACxB,OAAOC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,KAAK,CAACC,MAAM,CAACC,QAAQ,CAACL,CAAC,CAAC,GAAGA,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5D;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCG;AACG,SAAUM,gBAAgBA,CAC9BC,EAAc,EACdC,OAAe,EAAA;EAEf,IAAMC,MAAM,GAAGC,IAAI,CAACC,GAAG,EAAE,GAAGZ,OAAO,CAACS,OAAO,CAAC;AAC5C,EAAA,IAAII,MAA0B;AAE9B,EAAA,IAAMC,KAAI,GAAG,SAAPA,IAAIA,GAAQ;IAChB,IAAMC,SAAS,GAAGL,MAAM,GAAGC,IAAI,CAACC,GAAG,EAAE;IACrC,IAAIG,SAAS,IAAI,CAAC,EAAE;AAClBP,MAAAA,EAAE,EAAE;AACJ,MAAA;AACF,IAAA;AACAK,IAAAA,MAAM,GAAGG,MAAM,CAACC,UAAU,CAACH,KAAI,EAAEZ,IAAI,CAACgB,GAAG,CAACnB,YAAY,EAAEgB,SAAS,CAA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;;;AAMK;AACC,SAAUY,qBAAqBA,CACnC7B,GAAa,EACbC,GAAW,EACXnB,EAAc,EACdC,OAAe,EAAA;EAEfgB,QAAQ,CAACC,GAAG,EAAEC,GAAG,EAAEpB,gBAAgB,CAACC,EAAE,EAAEC,OAAO,CAAC,CAAC;AACnD;AAEA;;;;;;AAMG;AACG,SAAU+C,eAAeA,CAC7B9B,GAAa,EACbC,GAAW,EACXnB,EAAc,EACdC,OAAe,EAAA;EAEfgB,QAAQ,CAACC,GAAG,EAAEC,GAAG,EAAEL,oBAAoB,CAACd,EAAE,EAAEC,OAAO,CAAC,CAAC;AACvD;;;;"}
@@ -0,0 +1,40 @@
1
+ import { Session, ZeroXKeyError, ZeroXKeyErrorCodes } from "@0xkey-io/sdk-types";
2
+ import { type Wallet, WalletProvider } from "@0xkey-io/core";
3
+ export declare const SESSION_WARNING_THRESHOLD_MS: number;
4
+ export declare const authErrors: {
5
+ passkey: {
6
+ createFailed: string;
7
+ loginFailed: string;
8
+ timeoutOrNotAllowed: string;
9
+ };
10
+ otp: {
11
+ sendFailed: string;
12
+ invalidEmail: string;
13
+ invalidPhone: string;
14
+ };
15
+ oauth: {
16
+ loginFailed: string;
17
+ };
18
+ wallet: {
19
+ loginFailed: string;
20
+ noPublicKey: string;
21
+ };
22
+ suborg: {
23
+ fetchFailed: string;
24
+ createFailed: string;
25
+ };
26
+ };
27
+ export declare const useDebouncedCallback: <T extends (...args: any[]) => void>(fn: T, wait?: number) => T;
28
+ export declare const isValidSession: (session?: Session | undefined) => boolean;
29
+ export declare function withZeroXKeyErrorHandling<T>(fn: () => Promise<T>, sessionExpireFn?: () => Promise<void>, callbacks?: {
30
+ onError?: (error: ZeroXKeyError) => void;
31
+ }, fallbackMessage?: string, fallbackCode?: ZeroXKeyErrorCodes): Promise<T>;
32
+ export declare function useScreenSize(): {
33
+ width: number;
34
+ height: number;
35
+ isMobile: boolean;
36
+ };
37
+ export declare function isWalletConnect(wallet: WalletProvider): boolean;
38
+ export declare function useWalletProviderState(initialState?: WalletProvider[]): readonly [WalletProvider[], (newProviders: WalletProvider[]) => void];
39
+ export declare function mergeWalletsWithoutDuplicates(existingWallets: Wallet[], newWallets: Wallet[]): Wallet[];
40
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,aAAa,EACb,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,KAAK,MAAM,EACX,cAAc,EAEf,MAAM,gBAAgB,CAAC;AAExB,eAAO,MAAM,4BAA4B,QAAY,CAAC;AAEtD,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;CAgCtB,CAAC;AAEF,eAAO,MAAM,oBAAoB,uBAAwB,GAAG,EAAE,KAAK,IAAI,MACjE,CAAC,oBAEJ,CAgBF,CAAC;AAEF,eAAO,MAAM,cAAc,aAAc,OAAO,GAAG,SAAS,KAAG,OAE9D,CAAC;AAEF,wBAAsB,yBAAyB,CAAC,CAAC,EAC/C,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,eAAe,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACrC,SAAS,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;CAAE,EACxD,eAAe,SAA8B,EAC7C,YAAY,qBAA6B,GACxC,OAAO,CAAC,CAAC,CAAC,CAqCZ;AAGD,wBAAgB,aAAa;;;;EAyB5B;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAE/D;AAED,wBAAgB,sBAAsB,CAAC,YAAY,GAAE,cAAc,EAAO,8CA2BvD,cAAc,EAAE,WAWlC;AAED,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,MAAM,EAAE,EACzB,UAAU,EAAE,MAAM,EAAE,GACnB,MAAM,EAAE,CAMV"}