@dynamic-labs/utils 0.19.0-alpha.2 → 0.19.0-alpha.20

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 (103) hide show
  1. package/CHANGELOG.md +279 -0
  2. package/package.json +7 -4
  3. package/src/CancellablePromise/CancellablePromise.cjs +128 -26
  4. package/src/CancellablePromise/CancellablePromise.d.ts +54 -9
  5. package/src/CancellablePromise/CancellablePromise.js +128 -26
  6. package/src/CancellablePromise/index.d.ts +1 -1
  7. package/src/bigIntToHex/bigIntToHex.cjs +15 -0
  8. package/src/bigIntToHex/bigIntToHex.d.ts +1 -0
  9. package/src/bigIntToHex/bigIntToHex.js +11 -0
  10. package/src/bigIntToHex/index.d.ts +1 -0
  11. package/src/bufferToBase64.cjs +5 -5
  12. package/src/bufferToBase64.d.ts +1 -1
  13. package/src/bufferToBase64.js +5 -5
  14. package/src/errors/AccountExistsError.cjs +6 -6
  15. package/src/errors/AccountExistsError.d.ts +13 -13
  16. package/src/errors/AccountExistsError.js +6 -6
  17. package/src/errors/ChainalysisError.cjs +5 -5
  18. package/src/errors/ChainalysisError.d.ts +5 -5
  19. package/src/errors/ChainalysisError.js +5 -5
  20. package/src/errors/CustomError.cjs +16 -16
  21. package/src/errors/CustomError.d.ts +11 -11
  22. package/src/errors/CustomError.js +16 -16
  23. package/src/errors/DynamicError.cjs +1 -1
  24. package/src/errors/DynamicError.d.ts +3 -3
  25. package/src/errors/DynamicError.js +1 -1
  26. package/src/errors/EmailAlreadyExistsError.cjs +4 -4
  27. package/src/errors/EmailAlreadyExistsError.d.ts +4 -4
  28. package/src/errors/EmailAlreadyExistsError.js +4 -4
  29. package/src/errors/EmailProviderError.cjs +4 -4
  30. package/src/errors/EmailProviderError.d.ts +4 -4
  31. package/src/errors/EmailProviderError.js +4 -4
  32. package/src/errors/EmailVerificationError.cjs +4 -4
  33. package/src/errors/EmailVerificationError.d.ts +4 -4
  34. package/src/errors/EmailVerificationError.js +4 -4
  35. package/src/errors/GateBlockedError.cjs +5 -5
  36. package/src/errors/GateBlockedError.d.ts +5 -5
  37. package/src/errors/GateBlockedError.js +5 -5
  38. package/src/errors/MissingEnvironmentIdError.cjs +4 -4
  39. package/src/errors/MissingEnvironmentIdError.d.ts +4 -4
  40. package/src/errors/MissingEnvironmentIdError.js +4 -4
  41. package/src/errors/NoAccessError.cjs +6 -6
  42. package/src/errors/NoAccessError.d.ts +9 -9
  43. package/src/errors/NoAccessError.js +6 -6
  44. package/src/errors/NotSupportedError.cjs +1 -1
  45. package/src/errors/NotSupportedError.d.ts +3 -3
  46. package/src/errors/NotSupportedError.js +1 -1
  47. package/src/errors/SocialAccountAlreadyExistsError.cjs +13 -0
  48. package/src/errors/SocialAccountAlreadyExistsError.d.ts +4 -0
  49. package/src/errors/SocialAccountAlreadyExistsError.js +9 -0
  50. package/src/errors/UserHasAccountWithEmailError.cjs +5 -5
  51. package/src/errors/UserHasAccountWithEmailError.d.ts +5 -5
  52. package/src/errors/UserHasAccountWithEmailError.js +5 -5
  53. package/src/errors/UsernameAlreadyExistsError.cjs +4 -4
  54. package/src/errors/UsernameAlreadyExistsError.d.ts +4 -4
  55. package/src/errors/UsernameAlreadyExistsError.js +4 -4
  56. package/src/errors/WalletNotDeployedError.cjs +4 -4
  57. package/src/errors/WalletNotDeployedError.d.ts +4 -4
  58. package/src/errors/WalletNotDeployedError.js +4 -4
  59. package/src/errors/WalletUsedError.cjs +4 -4
  60. package/src/errors/WalletUsedError.d.ts +4 -4
  61. package/src/errors/WalletUsedError.js +4 -4
  62. package/src/errors/index.d.ts +16 -15
  63. package/src/getOrMapViemChain.cjs +77 -0
  64. package/src/getOrMapViemChain.d.ts +11 -0
  65. package/src/getOrMapViemChain.js +51 -0
  66. package/src/getProvidersFromWindow.cjs +38 -0
  67. package/src/getProvidersFromWindow.d.ts +7 -0
  68. package/src/getProvidersFromWindow.js +34 -0
  69. package/src/index.cjs +22 -0
  70. package/src/index.d.ts +15 -8
  71. package/src/index.js +9 -1
  72. package/src/isBigInt/index.d.ts +1 -0
  73. package/src/isBigInt/isBigInt.cjs +7 -0
  74. package/src/isBigInt/isBigInt.d.ts +1 -0
  75. package/src/isBigInt/isBigInt.js +3 -0
  76. package/src/isFunction/index.d.ts +1 -1
  77. package/src/isFunction/isFunction.cjs +1 -1
  78. package/src/isFunction/isFunction.d.ts +1 -1
  79. package/src/isFunction/isFunction.js +1 -1
  80. package/src/isMobile.cjs +122 -56
  81. package/src/isMobile.d.ts +18 -15
  82. package/src/isMobile.js +120 -57
  83. package/src/last.cjs +21 -0
  84. package/src/last.d.ts +15 -0
  85. package/src/last.js +17 -0
  86. package/src/localStorageAsync.cjs +17 -17
  87. package/src/localStorageAsync.d.ts +3 -3
  88. package/src/localStorageAsync.js +17 -17
  89. package/src/logger/index.d.ts +1 -0
  90. package/src/logger/logger.cjs +9 -0
  91. package/src/logger/logger.d.ts +2 -0
  92. package/src/logger/logger.js +5 -0
  93. package/src/parseChainId.d.ts +1 -1
  94. package/src/parseEvmNetworks.cjs +6 -6
  95. package/src/parseEvmNetworks.d.ts +2 -2
  96. package/src/parseEvmNetworks.js +6 -6
  97. package/src/retryableFn.cjs +53 -0
  98. package/src/retryableFn.d.ts +14 -0
  99. package/src/retryableFn.js +48 -0
  100. package/src/sleep/index.d.ts +1 -0
  101. package/src/sleep/sleep.cjs +12 -0
  102. package/src/sleep/sleep.d.ts +11 -0
  103. package/src/sleep/sleep.js +8 -0
package/CHANGELOG.md CHANGED
@@ -1,4 +1,283 @@
1
1
 
2
+ ## [0.19.0-alpha.20](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.19...v0.19.0-alpha.20) (2023-10-23)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * consider logged in on connect-and-sign only if there's a user ([#3643](https://github.com/dynamic-labs/DynamicAuth/issues/3643)) ([85d0f37](https://github.com/dynamic-labs/DynamicAuth/commit/85d0f37e98a6727bb8749fcd725d8f598c59f728))
8
+
9
+ ## [0.19.0-alpha.19](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.18...v0.19.0-alpha.19) (2023-10-20)
10
+
11
+ ## [0.19.0-alpha.18](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.17...v0.19.0-alpha.18) (2023-10-20)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * allow overriding contracts on Wagmi Chains ([#3106](https://github.com/dynamic-labs/DynamicAuth/issues/3106)) ([1a809f3](https://github.com/dynamic-labs/DynamicAuth/commit/1a809f3c2880b6581b58fb277188eac3a39da89a))
17
+ * await createEmbeddedWallet in useSocialAuth ([#3636](https://github.com/dynamic-labs/DynamicAuth/issues/3636)) ([6d5a6a6](https://github.com/dynamic-labs/DynamicAuth/commit/6d5a6a68c9adb79914fee4d4d17a47a3c79eec6d))
18
+ * disconnect wallet if not able to query address ([#3304](https://github.com/dynamic-labs/DynamicAuth/issues/3304)) ([d6fe979](https://github.com/dynamic-labs/DynamicAuth/commit/d6fe97931e35d9d38cf8525b44fc78326780b9a7))
19
+ * don't show user profile when reconnecting a primary social wallet ([#3614](https://github.com/dynamic-labs/DynamicAuth/issues/3614)) ([802243d](https://github.com/dynamic-labs/DynamicAuth/commit/802243d37963ca95d04373989e97d66e1753d8be))
20
+ * dynamic widget showing connect when in connect-only and signing with email/social ([#3632](https://github.com/dynamic-labs/DynamicAuth/issues/3632)) ([850a229](https://github.com/dynamic-labs/DynamicAuth/commit/850a229a72669b0e16154feafaec9618c820a036))
21
+
22
+ ## [0.19.0-alpha.17](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.16...v0.19.0-alpha.17) (2023-10-19)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * memoize createEmbeddedWallet so sync passkey is not called multiple times ([#3612](https://github.com/dynamic-labs/DynamicAuth/issues/3612)) ([11d53e9](https://github.com/dynamic-labs/DynamicAuth/commit/11d53e9bf3e7c4ceb4be7dede96e6facd07a6767))
28
+ * revert any changes of the form of the wallet connector key ([#3608](https://github.com/dynamic-labs/DynamicAuth/issues/3608)) ([f0e2a89](https://github.com/dynamic-labs/DynamicAuth/commit/f0e2a8988047e7533cbfc52eee06d6752c5aa9c4))
29
+
30
+ ## [0.19.0-alpha.16](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.15...v0.19.0-alpha.16) (2023-10-17)
31
+
32
+
33
+ ### ⚠ BREAKING CHANGES
34
+
35
+ * ethers extension integration and rename provider methods (#3573)
36
+
37
+ ### Features
38
+
39
+ * add onDisconnect ([#3572](https://github.com/dynamic-labs/DynamicAuth/issues/3572)) ([3e612f7](https://github.com/dynamic-labs/DynamicAuth/commit/3e612f72540781b9246a47ac12a7c979fb6c0d88))
40
+ * user callback on passkey creation complete ([#3591](https://github.com/dynamic-labs/DynamicAuth/issues/3591)) ([92d5f7d](https://github.com/dynamic-labs/DynamicAuth/commit/92d5f7df2ac1cc06338f7e9e75125f7bb71455ab))
41
+
42
+
43
+ ### Bug Fixes
44
+
45
+ * argentX in-browser wallet ([#3588](https://github.com/dynamic-labs/DynamicAuth/issues/3588)) ([7f3b22d](https://github.com/dynamic-labs/DynamicAuth/commit/7f3b22d003182aa0d84406086a313fc4de25e4a8))
46
+ * display a better message when transaction amount decimals are invalid ([#3577](https://github.com/dynamic-labs/DynamicAuth/issues/3577)) ([0238d9b](https://github.com/dynamic-labs/DynamicAuth/commit/0238d9b7712d6a52aec89193c751224dd8fd8b17))
47
+ * remove passkey success view ([#3536](https://github.com/dynamic-labs/DynamicAuth/issues/3536)) ([b559de9](https://github.com/dynamic-labs/DynamicAuth/commit/b559de9c83096ed98e9f073b998ac08f876af24e))
48
+ * **wagmi-connector:** use wallets list to sync wagmi client ([#3563](https://github.com/dynamic-labs/DynamicAuth/issues/3563)) ([1d551b9](https://github.com/dynamic-labs/DynamicAuth/commit/1d551b933aefe0c535285d68c2e6f819cd321e62))
49
+
50
+
51
+ * ethers extension integration and rename provider methods ([#3573](https://github.com/dynamic-labs/DynamicAuth/issues/3573)) ([efd73c3](https://github.com/dynamic-labs/DynamicAuth/commit/efd73c3b8121df9a7d4ec8c1fb6c4fd76ecce6df))
52
+
53
+ ## [0.19.0-alpha.15](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.14...v0.19.0-alpha.15) (2023-10-11)
54
+
55
+ ## [0.19.0-alpha.14](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.13...v0.19.0-alpha.14) (2023-10-10)
56
+
57
+
58
+ ### ⚠ BREAKING CHANGES
59
+
60
+ * remove numberOfWallets (#3521)
61
+
62
+ ### Features
63
+
64
+ * add embedded widget components ([#3533](https://github.com/dynamic-labs/DynamicAuth/issues/3533)) ([513cba8](https://github.com/dynamic-labs/DynamicAuth/commit/513cba8e7694544122ff9cce3aa1aea0a0c23986))
65
+ * add ethers extension support to wallet-connectors ([#3544](https://github.com/dynamic-labs/DynamicAuth/issues/3544)) ([3c09ba5](https://github.com/dynamic-labs/DynamicAuth/commit/3c09ba58b0f2c745df60a87b1820abbbfc1b95b7))
66
+ * add switch network for turnkey wallets ([#3539](https://github.com/dynamic-labs/DynamicAuth/issues/3539)) ([1bcbbb2](https://github.com/dynamic-labs/DynamicAuth/commit/1bcbbb2bd4e333d47ce4c93d4bd4b1f29a80c1f4))
67
+ * editable copy for switch network view ([#3561](https://github.com/dynamic-labs/DynamicAuth/issues/3561)) ([4dea2f1](https://github.com/dynamic-labs/DynamicAuth/commit/4dea2f159ee0675d5b9ba1cb412d75e5e211b3d1))
68
+
69
+
70
+ ### Bug Fixes
71
+
72
+ * always call connectSucess callback after successfully connecting wallet ([#3562](https://github.com/dynamic-labs/DynamicAuth/issues/3562)) ([2587ff8](https://github.com/dynamic-labs/DynamicAuth/commit/2587ff8a915f61793b15bfa1289689514344fc75))
73
+ * don't let user update email if they have an embedded wallet ([#3552](https://github.com/dynamic-labs/DynamicAuth/issues/3552)) ([c710cce](https://github.com/dynamic-labs/DynamicAuth/commit/c710cce22c7a54004f56c8fc68f8c4075f5f9e51))
74
+ * embedded widget rerender bug ([#3545](https://github.com/dynamic-labs/DynamicAuth/issues/3545)) ([27ed979](https://github.com/dynamic-labs/DynamicAuth/commit/27ed979618ac7d9e912381faebbf61ec9e9e839c))
75
+ * sync passkey should not throw error ([#3535](https://github.com/dynamic-labs/DynamicAuth/issues/3535)) ([0336ba6](https://github.com/dynamic-labs/DynamicAuth/commit/0336ba65bf1cc4394e4f005f273baea26326784a))
76
+ * wrap eth wallet connector rpc calls in retry function ([#3497](https://github.com/dynamic-labs/DynamicAuth/issues/3497)) ([7800b45](https://github.com/dynamic-labs/DynamicAuth/commit/7800b45dc93f20731ee643e89e84d57765387778))
77
+
78
+
79
+ * remove numberOfWallets ([#3521](https://github.com/dynamic-labs/DynamicAuth/issues/3521)) ([0174297](https://github.com/dynamic-labs/DynamicAuth/commit/017429745d08b7b1edc23bc4da43bc01b4ef1cd4))
80
+
81
+ ## [0.19.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.12...v0.19.0-alpha.13) (2023-10-04)
82
+
83
+
84
+ ### Features
85
+
86
+ * add ethers 5/6 util methods for converting connectors to ethers classes ([#3435](https://github.com/dynamic-labs/DynamicAuth/issues/3435)) ([5f4da48](https://github.com/dynamic-labs/DynamicAuth/commit/5f4da48526dbce4be2d437fc93f4cc8ddded73c5))
87
+ * show goerli icon on network button and a warning message ([#3494](https://github.com/dynamic-labs/DynamicAuth/issues/3494)) ([64851a3](https://github.com/dynamic-labs/DynamicAuth/commit/64851a3d60ba19dd164690dcb26056cad2d22e61))
88
+
89
+
90
+ ### Bug Fixes
91
+
92
+ * fix broken test ([#3520](https://github.com/dynamic-labs/DynamicAuth/issues/3520)) ([d7a3bd4](https://github.com/dynamic-labs/DynamicAuth/commit/d7a3bd4c71309a2df8106cae3f8f03f4aaedaa56))
93
+ * **handleWalletsToConnect:** require wallet connector in the props ([#3512](https://github.com/dynamic-labs/DynamicAuth/issues/3512)) ([ddc0d19](https://github.com/dynamic-labs/DynamicAuth/commit/ddc0d19c9996f4fd52d19aad837fdf1e632d1b3d))
94
+ * use providers redirect url in getOauthLoginUrl function ([#3519](https://github.com/dynamic-labs/DynamicAuth/issues/3519)) ([3f8601d](https://github.com/dynamic-labs/DynamicAuth/commit/3f8601d47d2fc6aa65f3a6890b1b9a4b93c9e9f6))
95
+ * **wagmi-connector:** set websocket rpc to wagmi client ([#3474](https://github.com/dynamic-labs/DynamicAuth/issues/3474)) ([c94a43e](https://github.com/dynamic-labs/DynamicAuth/commit/c94a43ea9be11352313eafb2cd42c5f4941562a3))
96
+
97
+ ## [0.19.0-alpha.12](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.11...v0.19.0-alpha.12) (2023-10-03)
98
+
99
+
100
+ ### Features
101
+
102
+ * filter wallet list for wallets which have not been connected ([#3499](https://github.com/dynamic-labs/DynamicAuth/issues/3499)) ([10e531f](https://github.com/dynamic-labs/DynamicAuth/commit/10e531f0836b029ab43713b9b2c7ecf273a4018c))
103
+ * passkey flow copies should be fully editable ([#3504](https://github.com/dynamic-labs/DynamicAuth/issues/3504)) ([390392c](https://github.com/dynamic-labs/DynamicAuth/commit/390392cc5c95afd0226f29a72560c295fa2be391))
104
+
105
+
106
+ ### Bug Fixes
107
+
108
+ * remove useEffect in useSetWalletConnectorVerifiedCredentials to avoid race conditions ([#3495](https://github.com/dynamic-labs/DynamicAuth/issues/3495)) ([aa17676](https://github.com/dynamic-labs/DynamicAuth/commit/aa176761f324806000317db1f683d545ec642619))
109
+ * show android touch id icon for those with it available on passkey intro ([#3503](https://github.com/dynamic-labs/DynamicAuth/issues/3503)) ([4017f16](https://github.com/dynamic-labs/DynamicAuth/commit/4017f16fe0b0ceeb03f064ac9e9d34b71764b242))
110
+
111
+ ## [0.19.0-alpha.11](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.10...v0.19.0-alpha.11) (2023-10-02)
112
+
113
+
114
+ ### Bug Fixes
115
+
116
+ * **AuthProviderIcon:** ensure social icon shows up ([#3439](https://github.com/dynamic-labs/DynamicAuth/issues/3439)) ([5064f28](https://github.com/dynamic-labs/DynamicAuth/commit/5064f28af9125699c8e23597812c6c526bb8a213))
117
+ * fix passkey on Windows ([#3440](https://github.com/dynamic-labs/DynamicAuth/issues/3440)) ([c0da96c](https://github.com/dynamic-labs/DynamicAuth/commit/c0da96c17c6c10a736fb394b6b1e6be3ccd616b2))
118
+ * missing popper provider ([#3488](https://github.com/dynamic-labs/DynamicAuth/issues/3488)) ([d7ca76e](https://github.com/dynamic-labs/DynamicAuth/commit/d7ca76e21dc5e842c316a654cb20d9dd115d7204))
119
+ * passkey intro view should have a logout button ([#3466](https://github.com/dynamic-labs/DynamicAuth/issues/3466)) ([7ae626f](https://github.com/dynamic-labs/DynamicAuth/commit/7ae626fd2b2b6f685e48257c38ed00dae95d06e4))
120
+ * passkey intro view should not be closed until user create wallet ([#3458](https://github.com/dynamic-labs/DynamicAuth/issues/3458)) ([651459b](https://github.com/dynamic-labs/DynamicAuth/commit/651459b8d8a4ad131381ed8de52c9ef0c42191df))
121
+ * removing weird passkey intro logout button hover background ([#3490](https://github.com/dynamic-labs/DynamicAuth/issues/3490)) ([1adedfa](https://github.com/dynamic-labs/DynamicAuth/commit/1adedfaf87e6fd01e8528ff43ccf75fcb020ef65))
122
+ * resolve promise if there's no error, even if result is falsy ([#3477](https://github.com/dynamic-labs/DynamicAuth/issues/3477)) ([1b570dc](https://github.com/dynamic-labs/DynamicAuth/commit/1b570dc8ae6b104567790d93ebb57efed032ba1c))
123
+ * return promise from createEmbeddedWallet ([#3476](https://github.com/dynamic-labs/DynamicAuth/issues/3476)) ([5a9591e](https://github.com/dynamic-labs/DynamicAuth/commit/5a9591e0808d5d16fb886901902d763eabd8ec61))
124
+ * utilize the wallet connector key when looking up the wallet in localstorage during getWalletConnectorByKey ([#3386](https://github.com/dynamic-labs/DynamicAuth/issues/3386)) ([13a8ef4](https://github.com/dynamic-labs/DynamicAuth/commit/13a8ef4581e7799cc467bddb7cd1435dc4ab4de5))
125
+
126
+ ## [0.19.0-alpha.10](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.9...v0.19.0-alpha.10) (2023-09-28)
127
+
128
+
129
+ ### ⚠ BREAKING CHANGES
130
+
131
+ * change magic walletProvider from custodialService to embeddedWallet (#3429)
132
+
133
+ ### Features
134
+
135
+ * allow passkey setup after social sign in ([#3410](https://github.com/dynamic-labs/DynamicAuth/issues/3410)) ([d225a63](https://github.com/dynamic-labs/DynamicAuth/commit/d225a63544284422589990c4e872430f7eb88f07))
136
+ * create useEmbeddedWallet hook to trigger embedded wallet creation ([#3437](https://github.com/dynamic-labs/DynamicAuth/issues/3437)) ([d79c558](https://github.com/dynamic-labs/DynamicAuth/commit/d79c558d31deacb293823c2fe42d006d0645b470))
137
+ * **passkey:** direct user to passkey intro view when enabled ([#3393](https://github.com/dynamic-labs/DynamicAuth/issues/3393)) ([e02e0dc](https://github.com/dynamic-labs/DynamicAuth/commit/e02e0dcaa87dbbd56665868ff637156cea23f574))
138
+ * **wcv2:** add support for dynamic network configuration to wallet connect ([#3332](https://github.com/dynamic-labs/DynamicAuth/issues/3332)) ([a285360](https://github.com/dynamic-labs/DynamicAuth/commit/a2853606e1065a252cab37fa693db1c51cd3ac55))
139
+
140
+
141
+ ### Bug Fixes
142
+
143
+ * don't filter out disabled providers in settings so we can access their data ([#3407](https://github.com/dynamic-labs/DynamicAuth/issues/3407)) ([0f68e88](https://github.com/dynamic-labs/DynamicAuth/commit/0f68e887fed40777c8e539b20e9598edf76e612b))
144
+ * don't show error until passkey enabled check promise is fulfilled ([#3446](https://github.com/dynamic-labs/DynamicAuth/issues/3446)) ([101ac98](https://github.com/dynamic-labs/DynamicAuth/commit/101ac980aa56a1cd3d3fdda68ddac6ad7779727e))
145
+ * **DYN-2732:** wait for networks to fetch ([#3431](https://github.com/dynamic-labs/DynamicAuth/issues/3431)) ([e66e86c](https://github.com/dynamic-labs/DynamicAuth/commit/e66e86cefd826b04dcde3474e0ed169b41f7b715))
146
+ * error handling for non-supported devices ([#3397](https://github.com/dynamic-labs/DynamicAuth/issues/3397)) ([e5cc7e6](https://github.com/dynamic-labs/DynamicAuth/commit/e5cc7e65c05da132c325c57cf06e33cac86440f9))
147
+ * error handling when creating passkey ([#3416](https://github.com/dynamic-labs/DynamicAuth/issues/3416)) ([3274df4](https://github.com/dynamic-labs/DynamicAuth/commit/3274df4f7bd2a00ad0776392f55a8493c9bc2b60))
148
+ * passkey icon breaks line into 2 on mobile ([#3426](https://github.com/dynamic-labs/DynamicAuth/issues/3426)) ([2dd045b](https://github.com/dynamic-labs/DynamicAuth/commit/2dd045b04d4cc4806e653c10a22412d8a5c3b9fc))
149
+ * set primary wallet id when passkey is already set up ([#3419](https://github.com/dynamic-labs/DynamicAuth/issues/3419)) ([496555f](https://github.com/dynamic-labs/DynamicAuth/commit/496555fd8e239601880a3fcd38519d09b3c35bd5))
150
+ * signing messages with backpack ([#3398](https://github.com/dynamic-labs/DynamicAuth/issues/3398)) ([a68d3da](https://github.com/dynamic-labs/DynamicAuth/commit/a68d3da97e2b2c8f555d9126e0ab400343d7bec1))
151
+ * social signing icon loading after logout ([#3417](https://github.com/dynamic-labs/DynamicAuth/issues/3417)) ([3ac0f19](https://github.com/dynamic-labs/DynamicAuth/commit/3ac0f194f9a55795718fb6ca6f44ab2fe87eeb06))
152
+ * trigger passkey flow after email kyc verification ([#3434](https://github.com/dynamic-labs/DynamicAuth/issues/3434)) ([a6fc353](https://github.com/dynamic-labs/DynamicAuth/commit/a6fc353f6dfe9fd5ee67139a8fae6c37c947cd14))
153
+ * trigger passkey flow after onboarding ([#3428](https://github.com/dynamic-labs/DynamicAuth/issues/3428)) ([fa81643](https://github.com/dynamic-labs/DynamicAuth/commit/fa81643575c0fe6174e6521810fcdf139dc259e6))
154
+ * **turnkey:** sign message with viem and current address ([#3433](https://github.com/dynamic-labs/DynamicAuth/issues/3433)) ([025ffac](https://github.com/dynamic-labs/DynamicAuth/commit/025ffac4a9bf1e4526894f242c1cd882c0e10b45))
155
+ * use correct authenticator type in passkey creation params ([#3411](https://github.com/dynamic-labs/DynamicAuth/issues/3411)) ([eefbf01](https://github.com/dynamic-labs/DynamicAuth/commit/eefbf01aa7962e95db80ff19676fa582da756d11))
156
+ * **use-element-by-id:** include pointer events style rule to ensure modal is interactive ([#3396](https://github.com/dynamic-labs/DynamicAuth/issues/3396)) ([15077d4](https://github.com/dynamic-labs/DynamicAuth/commit/15077d4752379924f35ff889b05f03bdf6c051bf))
157
+
158
+
159
+ * change magic walletProvider from custodialService to embeddedWallet ([#3429](https://github.com/dynamic-labs/DynamicAuth/issues/3429)) ([c617439](https://github.com/dynamic-labs/DynamicAuth/commit/c617439d745cff81d415a042d2187a98b29318da))
160
+
161
+ ## [0.19.0-alpha.9](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.8...v0.19.0-alpha.9) (2023-09-21)
162
+
163
+
164
+ ### Features
165
+
166
+ * allow enabling multi wallet in connect-only mode ([#3367](https://github.com/dynamic-labs/DynamicAuth/issues/3367)) ([8ef68a2](https://github.com/dynamic-labs/DynamicAuth/commit/8ef68a295738db5353fcddc54985744313a5474b))
167
+ * move injected wallets configuration to the cdn ([#3077](https://github.com/dynamic-labs/DynamicAuth/issues/3077)) ([291183b](https://github.com/dynamic-labs/DynamicAuth/commit/291183b8daf124577d1049152a2556b6f2a85758))
168
+ * passkey setup completed view ([#3358](https://github.com/dynamic-labs/DynamicAuth/issues/3358)) ([020faf6](https://github.com/dynamic-labs/DynamicAuth/commit/020faf63815e232c64ac8626f747b2997adbaa02))
169
+ * **rohithv/gvty-326:** check if email is real before sending ([#3361](https://github.com/dynamic-labs/DynamicAuth/issues/3361)) ([db554f3](https://github.com/dynamic-labs/DynamicAuth/commit/db554f344707e3c3701012ecc09b67be2aaebba4))
170
+ * safe guard wrong locale override keys ([#3329](https://github.com/dynamic-labs/DynamicAuth/issues/3329)) ([b2cf96b](https://github.com/dynamic-labs/DynamicAuth/commit/b2cf96b55fdd2705335ad942fe8e1c1109bf4134))
171
+ * secure account with passkey view ([#3356](https://github.com/dynamic-labs/DynamicAuth/issues/3356)) ([9d58c44](https://github.com/dynamic-labs/DynamicAuth/commit/9d58c4472f1967ff5201bae6556c7d88a33d6276))
172
+
173
+
174
+ ### Bug Fixes
175
+
176
+ * better handling of window opener to mitigate window opener for social linking ([#3379](https://github.com/dynamic-labs/DynamicAuth/issues/3379)) ([e784061](https://github.com/dynamic-labs/DynamicAuth/commit/e784061ab190d314976213e321516bbb256627e7))
177
+ * change buttom copy when cannot link a wallet ([#3364](https://github.com/dynamic-labs/DynamicAuth/issues/3364)) ([5428a60](https://github.com/dynamic-labs/DynamicAuth/commit/5428a60abcbbd9c47e9227a53610ee5975bac379))
178
+ * **DynamicWidget:** goToInitialView when closing send balance ([#3333](https://github.com/dynamic-labs/DynamicAuth/issues/3333)) ([7ea40ec](https://github.com/dynamic-labs/DynamicAuth/commit/7ea40ec3827c40e3340e5ecfa2153e59c05a79f1))
179
+ * **EmailMagicWalletConnector:** to only cancel the verification if user clicks back ([#3374](https://github.com/dynamic-labs/DynamicAuth/issues/3374)) ([1111a18](https://github.com/dynamic-labs/DynamicAuth/commit/1111a186b7b84066e89d385c0bd9c064d0326eae))
180
+ * **embedded-wallet:** display sign typed data message ([#3316](https://github.com/dynamic-labs/DynamicAuth/issues/3316)) ([0014c8b](https://github.com/dynamic-labs/DynamicAuth/commit/0014c8b4250cf9db92b554f02b4e46f3aba2d943))
181
+ * missing translation keys ([#3325](https://github.com/dynamic-labs/DynamicAuth/issues/3325)) ([0e7c383](https://github.com/dynamic-labs/DynamicAuth/commit/0e7c3838a0eb8b49298e59b2919e16994a2d6b19))
182
+ * only set scope/prompt in oauth query params when they're defined ([#3324](https://github.com/dynamic-labs/DynamicAuth/issues/3324)) ([9e8aa2d](https://github.com/dynamic-labs/DynamicAuth/commit/9e8aa2d186fff563607dc836017b918af79718ce))
183
+ * pass the network param on wallet transfers ([#3307](https://github.com/dynamic-labs/DynamicAuth/issues/3307)) ([faf89fd](https://github.com/dynamic-labs/DynamicAuth/commit/faf89fdbfa690a87ae91d7f09c3647b4160b53ad))
184
+ * send primaryWalletId when available to unlinkOauth ([#3342](https://github.com/dynamic-labs/DynamicAuth/issues/3342)) ([0da0ae2](https://github.com/dynamic-labs/DynamicAuth/commit/0da0ae23040f7683000223109446a516c6d7b212))
185
+ * twitter sign-in with dynamic ([#3313](https://github.com/dynamic-labs/DynamicAuth/issues/3313)) ([c77dae4](https://github.com/dynamic-labs/DynamicAuth/commit/c77dae41dbdc02c84f3d3f5f3338136efd5766f9))
186
+ * use social profile photo for profile icon whenever available ([#3298](https://github.com/dynamic-labs/DynamicAuth/issues/3298)) ([143303b](https://github.com/dynamic-labs/DynamicAuth/commit/143303ba5e24d16aaa362f1888e3942bdef59602))
187
+ * wallet transition in the bridge ([#3270](https://github.com/dynamic-labs/DynamicAuth/issues/3270)) ([143cf47](https://github.com/dynamic-labs/DynamicAuth/commit/143cf47e0cd4806780f5b3f527ace2d6c0208534)), closes [#3268](https://github.com/dynamic-labs/DynamicAuth/issues/3268) [#3243](https://github.com/dynamic-labs/DynamicAuth/issues/3243)
188
+ * **wallet-connect:** prevent connector from connecting after logout ([#3345](https://github.com/dynamic-labs/DynamicAuth/issues/3345)) ([9bada77](https://github.com/dynamic-labs/DynamicAuth/commit/9bada7775c5ac7a4fdb5ad8d4d21691335e06936))
189
+
190
+ ## [0.19.0-alpha.8](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.7...v0.19.0-alpha.8) (2023-09-11)
191
+
192
+
193
+ ### Features
194
+
195
+ * add onSignedMessage callback ([#3118](https://github.com/dynamic-labs/DynamicAuth/issues/3118)) ([acc36f6](https://github.com/dynamic-labs/DynamicAuth/commit/acc36f6cf584eb05a019027475a6e2e413fd6bd5))
196
+ * add social sign-in without embedded wallet ([#3172](https://github.com/dynamic-labs/DynamicAuth/issues/3172)) ([ff1acc6](https://github.com/dynamic-labs/DynamicAuth/commit/ff1acc6d9753ba745ac01c5ef6d26f2e4291b752))
197
+ * show default wallet icon when image breaks ([#3234](https://github.com/dynamic-labs/DynamicAuth/issues/3234)) ([657e6bb](https://github.com/dynamic-labs/DynamicAuth/commit/657e6bbc1cdcd840562d25194a827ea833237c1a))
198
+
199
+
200
+ ### Bug Fixes
201
+
202
+ * catch error sending sdkSettings and log warning ([#3274](https://github.com/dynamic-labs/DynamicAuth/issues/3274)) ([fcbe01b](https://github.com/dynamic-labs/DynamicAuth/commit/fcbe01bc733a73f38aebd6ffb0969b040dd2f781))
203
+ * detect if oauth popup is blocked and throw error ([#3250](https://github.com/dynamic-labs/DynamicAuth/issues/3250)) ([b87ddf3](https://github.com/dynamic-labs/DynamicAuth/commit/b87ddf399104e29c56566abbbecab6ff947992d6))
204
+ * display error message to user if social account already exits ([#3258](https://github.com/dynamic-labs/DynamicAuth/issues/3258)) ([bb52cb4](https://github.com/dynamic-labs/DynamicAuth/commit/bb52cb4ae42d89310d435584ed4ece126f9b6a4a))
205
+ * don't call callbacks if window closed due to oauth process complete ([#3252](https://github.com/dynamic-labs/DynamicAuth/issues/3252)) ([09a3c73](https://github.com/dynamic-labs/DynamicAuth/commit/09a3c73446aa337f24e0875cd4a0af617ea8ca84))
206
+ * issue where unexpected token would occur when bundlers defined process.env ([#3283](https://github.com/dynamic-labs/DynamicAuth/issues/3283)) ([d31d0a4](https://github.com/dynamic-labs/DynamicAuth/commit/d31d0a4011256f59cb3760acdc2c3dfe6c5b504a))
207
+ * login view layout updates ([#3231](https://github.com/dynamic-labs/DynamicAuth/issues/3231)) ([7762d06](https://github.com/dynamic-labs/DynamicAuth/commit/7762d067bdd4b3f313a15308262f18dac0b961ab))
208
+ * **MagicWalletConnector:** remove async from getWeb3Provider method ([#3230](https://github.com/dynamic-labs/DynamicAuth/issues/3230)) ([69356e9](https://github.com/dynamic-labs/DynamicAuth/commit/69356e9b0bd1800acdf24fc96c72b094b595eaa7))
209
+ * remove react component props from sending to sdk api ([#3282](https://github.com/dynamic-labs/DynamicAuth/issues/3282)) ([b0d8f2b](https://github.com/dynamic-labs/DynamicAuth/commit/b0d8f2b9dd0856a5a7bd862f6c3499b65ec29f64))
210
+ * seprate ls checks for dynamiccontext and wagmi settings ([#3275](https://github.com/dynamic-labs/DynamicAuth/issues/3275)) ([aa4e756](https://github.com/dynamic-labs/DynamicAuth/commit/aa4e756a10310ce216b5942d0d6845f7092a89a2))
211
+ * use context to handle social sign-in and display message while processing ([#3216](https://github.com/dynamic-labs/DynamicAuth/issues/3216)) ([0e3ce73](https://github.com/dynamic-labs/DynamicAuth/commit/0e3ce73eafbb8d5725377c9a8cbd86a82d6c525f))
212
+ * **wallet-connect-v2:** use appropriate default chain id with WC v2 ([#3218](https://github.com/dynamic-labs/DynamicAuth/issues/3218)) ([2e6e7be](https://github.com/dynamic-labs/DynamicAuth/commit/2e6e7beb801ea5a8dc7429970bcd1e705610d605))
213
+
214
+ ## [0.19.0-alpha.7](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.6...v0.19.0-alpha.7) (2023-08-31)
215
+
216
+
217
+ ### Features
218
+
219
+ * include deepLinkPreference option for wallet connect deep linking mode ([#3174](https://github.com/dynamic-labs/DynamicAuth/issues/3174)) ([f715948](https://github.com/dynamic-labs/DynamicAuth/commit/f715948050ddab52373ab742ea47cfc0879842ae))
220
+ * add option to disable the locked wallet view ([#3184](https://github.com/dynamic-labs/DynamicAuth/issues/3184)) ([d9a1290](https://github.com/dynamic-labs/DynamicAuth/commit/d9a1290214b7f86337abb544acd96f65ffe37759))
221
+ * migrate starknet version to v5 ([#3153](https://github.com/dynamic-labs/DynamicAuth/issues/3153)) ([b674011](https://github.com/dynamic-labs/DynamicAuth/commit/b67401133bf75d416118b51be11e3f099d2e2cda))
222
+ * add editable text with react i18next ([#3170](https://github.com/dynamic-labs/DynamicAuth/issues/3170)) ([a46b2ca](https://github.com/dynamic-labs/DynamicAuth/commit/a46b2ca880a4e14356024d2936920f72c8bc447e))
223
+
224
+
225
+ ### Bug Fixes
226
+
227
+ * allow to select L2 wallet after changing L1 network ([#3158](https://github.com/dynamic-labs/DynamicAuth/issues/3158)) ([cf68472](https://github.com/dynamic-labs/DynamicAuth/commit/cf6847270181f7fd33537ac1ff2a03e70b67daf2))
228
+ * allow user to cancel magic login to choose another email ([#3123](https://github.com/dynamic-labs/DynamicAuth/issues/3123)) ([cd73d6d](https://github.com/dynamic-labs/DynamicAuth/commit/cd73d6d0500c313dda01bca6245c52d2d8fca93a))
229
+ * verify email OTP when email is updated ([#3168](https://github.com/dynamic-labs/DynamicAuth/issues/3168)) ([641eeb6](https://github.com/dynamic-labs/DynamicAuth/commit/641eeb685b0c9d77cc72912f29b137c699c192f0))
230
+ * end connector session when unlinking in bridge ([#3120](https://github.com/dynamic-labs/DynamicAuth/issues/3120)) ([4c15da2](https://github.com/dynamic-labs/DynamicAuth/commit/4c15da27646c7bd176f6080dee6d76833e30f8a1))
231
+ * improves loading the sdk setting once per session ([#3189](https://github.com/dynamic-labs/DynamicAuth/issues/3189)) ([c9b0241](https://github.com/dynamic-labs/DynamicAuth/commit/c9b0241da28d2a73c90fd7643280c8632772c90b))
232
+ * update wallet address when switching network on bridge ([#3171](https://github.com/dynamic-labs/DynamicAuth/issues/3171)) ([f35f35e](https://github.com/dynamic-labs/DynamicAuth/commit/f35f35e632bcf88794884b66e0466cdf2e924812))
233
+ * updates the user email when updateUserWithModal method is used ([#3186](https://github.com/dynamic-labs/DynamicAuth/issues/3186)) ([8c71863](https://github.com/dynamic-labs/DynamicAuth/commit/8c718632cef0165328b929c27b6eef313641458d))
234
+ * sign message for embedded wallet when auth mode is connect only ([#3185](https://github.com/dynamic-labs/DynamicAuth/issues/3185)) ([0e3859c](https://github.com/dynamic-labs/DynamicAuth/commit/0e3859cfc738d3ecf8f19976e5cdaebc0c4f01c9))
235
+ * sync wagmi with wallet connector ([#3149](https://github.com/dynamic-labs/DynamicAuth/issues/3149)) ([3216e15](https://github.com/dynamic-labs/DynamicAuth/commit/3216e1570ac12ded6b3ce50b7efb762fe6814815))
236
+
237
+ ## [0.19.0-alpha.6](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.5...v0.19.0-alpha.6) (2023-08-25)
238
+
239
+
240
+ ### Features
241
+
242
+ * optionally split up email and social and change their display order in login view ([#3125](https://github.com/dynamic-labs/DynamicAuth/issues/3125)) ([ee82d26](https://github.com/dynamic-labs/DynamicAuth/commit/ee82d264eb3cb7f4ca7eb33369ef5409fe6860e4))
243
+ * post a connection request for second wallet ([#3113](https://github.com/dynamic-labs/DynamicAuth/issues/3113)) ([630aefa](https://github.com/dynamic-labs/DynamicAuth/commit/630aefa5ce83278082db1e3cd419c03e4fd081c7))
244
+
245
+
246
+ ### Bug Fixes
247
+
248
+ * fix bug where user was not able to confirm last wallet transfer ([#3102](https://github.com/dynamic-labs/DynamicAuth/issues/3102)) ([453b4c2](https://github.com/dynamic-labs/DynamicAuth/commit/453b4c20ea8f09d92dda11cdf92ddab562096d6f))
249
+ * fix github social linking icon on dark mode ([#3126](https://github.com/dynamic-labs/DynamicAuth/issues/3126)) ([6a8f3e3](https://github.com/dynamic-labs/DynamicAuth/commit/6a8f3e3d6e43d76b428e169fd5ead9ee0e2ec43d))
250
+ * fix issue with detecting oauth window closed before finishing linking ([#3124](https://github.com/dynamic-labs/DynamicAuth/issues/3124)) ([6a80ee9](https://github.com/dynamic-labs/DynamicAuth/commit/6a80ee97deb54e5b62bf2285d71b03c36802c5d2))
251
+ * stop calling handleLogOut prematurely ([#3135](https://github.com/dynamic-labs/DynamicAuth/issues/3135)) ([e7c81ad](https://github.com/dynamic-labs/DynamicAuth/commit/e7c81ad7e9e9cff03e5d2ca1e0fb7cfea083d06e))
252
+
253
+ ## [0.19.0-alpha.5](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.4...v0.19.0-alpha.5) (2023-08-24)
254
+
255
+
256
+ ### Bug Fixes
257
+
258
+ * send wagmi settings only once when DynamicWagmiConnector loads ([#3103](https://github.com/dynamic-labs/DynamicAuth/issues/3103)) ([8bba505](https://github.com/dynamic-labs/DynamicAuth/commit/8bba505f84f6f3567743397a3f1274a3840a7700))
259
+
260
+ ## [0.19.0-alpha.4](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.3...v0.19.0-alpha.4) (2023-08-23)
261
+
262
+
263
+ ### Features
264
+
265
+ * **GVTY-142:** support both emailOnly and dynamic as login with email provider ([#3025](https://github.com/dynamic-labs/DynamicAuth/issues/3025)) ([a4c43d3](https://github.com/dynamic-labs/DynamicAuth/commit/a4c43d36c44026df747530bc60193e73b77b9020))
266
+
267
+
268
+ ### Bug Fixes
269
+
270
+ * jumps when entering OTP code on IOS ([#3036](https://github.com/dynamic-labs/DynamicAuth/issues/3036)) ([f87eade](https://github.com/dynamic-labs/DynamicAuth/commit/f87eadeab9b7ea0c3f55d5d6d682a916868f2a58))
271
+ * log user out when magic session expires ([#3085](https://github.com/dynamic-labs/DynamicAuth/issues/3085)) ([fd5a328](https://github.com/dynamic-labs/DynamicAuth/commit/fd5a328dc41074c05413e0da82e82bb41bc803a1))
272
+ * switching network after connecting L1 wallet breaks bridge flow ([#3054](https://github.com/dynamic-labs/DynamicAuth/issues/3054)) ([e119f2b](https://github.com/dynamic-labs/DynamicAuth/commit/e119f2b23f3e6eedb0d2798dcf025bd401d78002))
273
+
274
+ ## [0.19.0-alpha.3](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.2...v0.19.0-alpha.3) (2023-08-22)
275
+
276
+
277
+ ### Bug Fixes
278
+
279
+ * multiwallet toolkit toggle not persisted after page refresh ([#3070](https://github.com/dynamic-labs/DynamicAuth/issues/3070)) ([ca454a7](https://github.com/dynamic-labs/DynamicAuth/commit/ca454a7aace415dbfaeef3f16f8e0d5b79b2d142))
280
+
2
281
  ## [0.19.0-alpha.2](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.1...v0.19.0-alpha.2) (2023-08-21)
3
282
 
4
283
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/utils",
3
- "version": "0.19.0-alpha.2",
3
+ "version": "0.19.0-alpha.20",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -25,8 +25,11 @@
25
25
  },
26
26
  "./package.json": "./package.json"
27
27
  },
28
- "dependencies": {
29
- "@dynamic-labs/types": "0.19.0-alpha.2"
28
+ "peerDependencies": {
29
+ "viem": "^1.5.3"
30
30
  },
31
- "peerDependencies": {}
31
+ "dependencies": {
32
+ "@dynamic-labs/logger": "0.19.0-alpha.20",
33
+ "@dynamic-labs/types": "0.19.0-alpha.20"
34
+ }
32
35
  }
@@ -2,32 +2,134 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- class CancellablePromise extends Promise {
6
- constructor(executor) {
7
- super((resolve, reject) => {
8
- executor((val) => {
9
- if (this.isCancelled)
10
- return;
11
- resolve(val);
12
- }, (err) => {
13
- if (this.isCancelled)
14
- return;
15
- reject(err);
16
- });
17
- });
18
- this._controller = new AbortController();
19
- }
20
- get isCancelled() {
21
- return this._controller.signal.aborted;
22
- }
23
- cancel() {
24
- this._controller.abort();
25
- }
26
- static fromPromise(promise) {
27
- return new CancellablePromise((resolve, reject) => {
28
- promise.then(resolve).catch(reject);
29
- });
30
- }
5
+ var logger = require('../logger/logger.cjs');
6
+
7
+ /* eslint-disable multiline-comment-style */
8
+ const defaultCancel = () => {
9
+ logger.logger.error("Tried to cancel CancellablePromise without ever assigning it's '_cancel' method");
10
+ };
11
+ /** An extension of Promise that allows you to explicitly cancel a promise with an external reference to it.
12
+ * Cancelling CancellablePromise causes it to reject with reason set to the parameter passed to the cancel method.
13
+ * When CancellablePromise rejects, it provides a boolean to indicate whether it was cancelled, alongside the reason.
14
+ *
15
+ * @example
16
+ * // Cancelling this promise
17
+ * const promise = new CancellablePromise(() => {}).onCancel(console.log)
18
+ * promise.cancel('User cancelled')
19
+ *
20
+ * // Setting up listeners for resolve, cancel and reject
21
+ * // (notice calling catch after onCancel prevents catch from being called by cancellation)
22
+ * new CancellablePromise(() => {})
23
+ * .then(() => console.log('Promise resolved'))
24
+ * .onCancel(() => console.log('Promise was cancelled'))
25
+ * .catch(() => console.log('Promise was rejected but NOT cancelled'))
26
+ *
27
+ * // Telling whether catch was cause of cancel or not
28
+ * new CancellablePromise(() => {})
29
+ * .then(() => console.log('Promise resolved'))
30
+ * .catch(({ reason, wasCancelled }) => console.log('Promise was rejected. Cancelled: ' + wasCancelled))
31
+ */
32
+ class CancellablePromise extends Promise {
33
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
+ internalCancel(reason) {
35
+ defaultCancel();
36
+ }
37
+ constructor(executor) {
38
+ let superReject = defaultCancel;
39
+ let superResolve = () => { };
40
+ super((resolve, reject) => {
41
+ superReject = reject;
42
+ superResolve = resolve;
43
+ });
44
+ this.internalIsCancelled = false;
45
+ this.isSettled = false;
46
+ executor((value) => {
47
+ if (!this.isCancelled && !this.isSettled)
48
+ superResolve(value);
49
+ this.isSettled = true;
50
+ }, (reason) => {
51
+ if (!this.isCancelled && !this.isSettled)
52
+ superReject(reason);
53
+ this.isSettled = true;
54
+ });
55
+ this.internalCancel = superReject;
56
+ }
57
+ /** Whether this CancellablePromise was cancelled. */
58
+ get isCancelled() {
59
+ return this.internalIsCancelled;
60
+ }
61
+ /** Cancels the promise. This causes the promise to reject with { wasCancelled: true, reason: reason }
62
+ * where the reason is the provided argument.
63
+ * @returns The cancelled promise.
64
+ */
65
+ cancel(reason) {
66
+ if (this.isSettled)
67
+ return this;
68
+ this.internalIsCancelled = true;
69
+ this.internalCancel(reason);
70
+ this.isSettled = true;
71
+ return this;
72
+ }
73
+ internalOnCancel(listener, options) {
74
+ const newPromise = new CancellablePromise((resolve, reject) => {
75
+ this.internalThen(resolve, ({ wasCancelled, reason }) => {
76
+ if (wasCancelled)
77
+ resolve(listener(reason));
78
+ else
79
+ reject(reason);
80
+ }, { ignoreOnCancel: true });
81
+ });
82
+ /** Tie the new promise's cancel to this promise's cancel */
83
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreOnCancel)) {
84
+ newPromise.internalOnCancel((reason) => {
85
+ this.cancel(reason);
86
+ }, { ignoreOnCancel: true });
87
+ }
88
+ return newPromise;
89
+ }
90
+ /** Allows reacting to this CancellablePromise being cancelled */
91
+ onCancel(listener) {
92
+ return this.internalOnCancel(listener);
93
+ }
94
+ internalThen(onFulfilled, onRejected, options) {
95
+ /** Create a catch handler that is undefined if the received callback is undefined */
96
+ const catchHandler = onRejected
97
+ ? (reason) => onRejected({ reason, wasCancelled: this.isCancelled })
98
+ : onRejected;
99
+ // /** Create the CancellablePromise we will returned, associated to the then promise */
100
+ const newPromise = CancellablePromise.fromPromise(super.then(onFulfilled, catchHandler));
101
+ /** Tie the new promise's cancel to this promise's cancel */
102
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreOnCancel)) {
103
+ newPromise.internalOnCancel((reason) => {
104
+ this.cancel(reason);
105
+ }, { ignoreOnCancel: true });
106
+ }
107
+ return newPromise;
108
+ }
109
+ then(onFulfilled, onRejected) {
110
+ return this.internalThen(onFulfilled, onRejected);
111
+ }
112
+ catch(onRejected) {
113
+ return this.then(undefined, onRejected);
114
+ }
115
+ finally(onFinally) {
116
+ return this.then((value) => {
117
+ onFinally === null || onFinally === void 0 ? void 0 : onFinally();
118
+ return value;
119
+ }, (reason) => {
120
+ onFinally === null || onFinally === void 0 ? void 0 : onFinally();
121
+ throw reason;
122
+ });
123
+ }
124
+ /** Generates a CancellablePromise from a Promise. If a CancellablePromise is passed, it's returned unscathed.
125
+ * WARNING: unless you attach a method to reject the original Promise with the "onCancel" param.
126
+ * cancelling the resulting CancellablePromise does NOT affect the original Promise. */
127
+ static fromPromise(promise) {
128
+ if ('internalIsCancelled' in promise)
129
+ return promise;
130
+ const newPromise = new CancellablePromise((resolve, reject) => promise.then(resolve, reject));
131
+ return newPromise;
132
+ }
31
133
  }
32
134
 
33
135
  exports.CancellablePromise = CancellablePromise;
@@ -1,9 +1,54 @@
1
- type Executor<T> = (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void;
2
- export declare class CancellablePromise<T> extends Promise<T> {
3
- _controller: AbortController;
4
- constructor(executor: Executor<T>);
5
- get isCancelled(): boolean;
6
- cancel(): void;
7
- static fromPromise<T>(promise: Promise<T>): CancellablePromise<T>;
8
- }
9
- export {};
1
+ type Executor<T> = (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void;
2
+ type CancelListener<TResult = never> = (reason?: unknown) => TResult;
3
+ /** An extension of Promise that allows you to explicitly cancel a promise with an external reference to it.
4
+ * Cancelling CancellablePromise causes it to reject with reason set to the parameter passed to the cancel method.
5
+ * When CancellablePromise rejects, it provides a boolean to indicate whether it was cancelled, alongside the reason.
6
+ *
7
+ * @example
8
+ * // Cancelling this promise
9
+ * const promise = new CancellablePromise(() => {}).onCancel(console.log)
10
+ * promise.cancel('User cancelled')
11
+ *
12
+ * // Setting up listeners for resolve, cancel and reject
13
+ * // (notice calling catch after onCancel prevents catch from being called by cancellation)
14
+ * new CancellablePromise(() => {})
15
+ * .then(() => console.log('Promise resolved'))
16
+ * .onCancel(() => console.log('Promise was cancelled'))
17
+ * .catch(() => console.log('Promise was rejected but NOT cancelled'))
18
+ *
19
+ * // Telling whether catch was cause of cancel or not
20
+ * new CancellablePromise(() => {})
21
+ * .then(() => console.log('Promise resolved'))
22
+ * .catch(({ reason, wasCancelled }) => console.log('Promise was rejected. Cancelled: ' + wasCancelled))
23
+ */
24
+ export declare class CancellablePromise<T> extends Promise<T> {
25
+ private internalIsCancelled;
26
+ private isSettled;
27
+ private internalCancel;
28
+ constructor(executor: Executor<T>);
29
+ /** Whether this CancellablePromise was cancelled. */
30
+ get isCancelled(): boolean;
31
+ /** Cancels the promise. This causes the promise to reject with { wasCancelled: true, reason: reason }
32
+ * where the reason is the provided argument.
33
+ * @returns The cancelled promise.
34
+ */
35
+ cancel(reason?: unknown): this;
36
+ private internalOnCancel;
37
+ /** Allows reacting to this CancellablePromise being cancelled */
38
+ onCancel<TResult = never>(listener: CancelListener<TResult>): CancellablePromise<T | TResult>;
39
+ private internalThen;
40
+ then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: {
41
+ reason: unknown;
42
+ wasCancelled: boolean;
43
+ }) => TResult2 | PromiseLike<TResult2>) | null): CancellablePromise<TResult1 | TResult2>;
44
+ catch<TResult = never>(onRejected?: ((reason: {
45
+ reason: unknown;
46
+ wasCancelled: boolean;
47
+ }) => TResult | PromiseLike<TResult>) | null): CancellablePromise<T | TResult>;
48
+ finally(onFinally?: (() => void) | null): CancellablePromise<T>;
49
+ /** Generates a CancellablePromise from a Promise. If a CancellablePromise is passed, it's returned unscathed.
50
+ * WARNING: unless you attach a method to reject the original Promise with the "onCancel" param.
51
+ * cancelling the resulting CancellablePromise does NOT affect the original Promise. */
52
+ static fromPromise<T>(promise: Promise<T> | CancellablePromise<T>): CancellablePromise<T>;
53
+ }
54
+ export {};