@metamask/snap-networks-utils 1.0.0 → 2.0.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 (360) hide show
  1. package/CHANGELOG.md +63 -1
  2. package/README.md +4 -10
  3. package/dist/index.cjs +102 -5
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +51 -2
  6. package/dist/index.d.cts.map +1 -1
  7. package/dist/index.d.mts +51 -2
  8. package/dist/index.d.mts.map +1 -1
  9. package/dist/index.mjs +32 -1
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/providers/assets/AssetsProvider.cjs +36 -18
  12. package/dist/providers/assets/AssetsProvider.cjs.map +1 -1
  13. package/dist/providers/assets/AssetsProvider.d.cts +30 -2
  14. package/dist/providers/assets/AssetsProvider.d.cts.map +1 -1
  15. package/dist/providers/assets/AssetsProvider.d.mts +30 -2
  16. package/dist/providers/assets/AssetsProvider.d.mts.map +1 -1
  17. package/dist/providers/assets/AssetsProvider.mjs +36 -18
  18. package/dist/providers/assets/AssetsProvider.mjs.map +1 -1
  19. package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.cjs +4 -17
  20. package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.cjs.map +1 -1
  21. package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.mjs +4 -17
  22. package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.mjs.map +1 -1
  23. package/dist/services/analytics/AnalyticsService.cjs +225 -0
  24. package/dist/services/analytics/AnalyticsService.cjs.map +1 -0
  25. package/dist/services/analytics/AnalyticsService.d.cts +175 -0
  26. package/dist/services/analytics/AnalyticsService.d.cts.map +1 -0
  27. package/dist/services/analytics/AnalyticsService.d.mts +175 -0
  28. package/dist/services/analytics/AnalyticsService.d.mts.map +1 -0
  29. package/dist/services/analytics/AnalyticsService.mjs +221 -0
  30. package/dist/services/analytics/AnalyticsService.mjs.map +1 -0
  31. package/dist/ui/ActionHeader/ActionHeader.cjs +23 -0
  32. package/dist/ui/ActionHeader/ActionHeader.cjs.map +1 -0
  33. package/dist/ui/ActionHeader/ActionHeader.d.cts +27 -0
  34. package/dist/ui/ActionHeader/ActionHeader.d.cts.map +1 -0
  35. package/dist/ui/ActionHeader/ActionHeader.d.mts +27 -0
  36. package/dist/ui/ActionHeader/ActionHeader.d.mts.map +1 -0
  37. package/dist/ui/ActionHeader/ActionHeader.mjs +19 -0
  38. package/dist/ui/ActionHeader/ActionHeader.mjs.map +1 -0
  39. package/dist/ui/Asset/Asset.cjs +68 -0
  40. package/dist/ui/Asset/Asset.cjs.map +1 -0
  41. package/dist/ui/Asset/Asset.d.cts +83 -0
  42. package/dist/ui/Asset/Asset.d.cts.map +1 -0
  43. package/dist/ui/Asset/Asset.d.mts +83 -0
  44. package/dist/ui/Asset/Asset.d.mts.map +1 -0
  45. package/dist/ui/Asset/Asset.mjs +60 -0
  46. package/dist/ui/Asset/Asset.mjs.map +1 -0
  47. package/dist/ui/Asset/question-mark.svg +3 -0
  48. package/dist/ui/EstimatedChanges/EstimatedChanges.cjs +57 -0
  49. package/dist/ui/EstimatedChanges/EstimatedChanges.cjs.map +1 -0
  50. package/dist/ui/EstimatedChanges/EstimatedChanges.d.cts +50 -0
  51. package/dist/ui/EstimatedChanges/EstimatedChanges.d.cts.map +1 -0
  52. package/dist/ui/EstimatedChanges/EstimatedChanges.d.mts +50 -0
  53. package/dist/ui/EstimatedChanges/EstimatedChanges.d.mts.map +1 -0
  54. package/dist/ui/EstimatedChanges/EstimatedChanges.mjs +53 -0
  55. package/dist/ui/EstimatedChanges/EstimatedChanges.mjs.map +1 -0
  56. package/dist/ui/TransactionAlert/TransactionAlert.cjs +72 -0
  57. package/dist/ui/TransactionAlert/TransactionAlert.cjs.map +1 -0
  58. package/dist/ui/TransactionAlert/TransactionAlert.d.cts +58 -0
  59. package/dist/ui/TransactionAlert/TransactionAlert.d.cts.map +1 -0
  60. package/dist/ui/TransactionAlert/TransactionAlert.d.mts +58 -0
  61. package/dist/ui/TransactionAlert/TransactionAlert.d.mts.map +1 -0
  62. package/dist/ui/TransactionAlert/TransactionAlert.mjs +68 -0
  63. package/dist/ui/TransactionAlert/TransactionAlert.mjs.map +1 -0
  64. package/dist/utils/async/async.cjs +95 -0
  65. package/dist/utils/async/async.cjs.map +1 -0
  66. package/dist/utils/async/async.d.cts +51 -0
  67. package/dist/utils/async/async.d.cts.map +1 -0
  68. package/dist/utils/async/async.d.mts +51 -0
  69. package/dist/utils/async/async.d.mts.map +1 -0
  70. package/dist/utils/async/async.mjs +88 -0
  71. package/dist/utils/async/async.mjs.map +1 -0
  72. package/dist/utils/buildUrl/buildUrl.cjs +54 -0
  73. package/dist/utils/buildUrl/buildUrl.cjs.map +1 -0
  74. package/dist/utils/buildUrl/buildUrl.d.cts +15 -0
  75. package/dist/utils/buildUrl/buildUrl.d.cts.map +1 -0
  76. package/dist/utils/buildUrl/buildUrl.d.mts +15 -0
  77. package/dist/utils/buildUrl/buildUrl.d.mts.map +1 -0
  78. package/dist/utils/buildUrl/buildUrl.mjs +51 -0
  79. package/dist/utils/buildUrl/buildUrl.mjs.map +1 -0
  80. package/dist/utils/cache/InMemoryCache.cjs +134 -0
  81. package/dist/utils/cache/InMemoryCache.cjs.map +1 -0
  82. package/dist/utils/cache/InMemoryCache.d.cts +29 -0
  83. package/dist/utils/cache/InMemoryCache.d.cts.map +1 -0
  84. package/dist/utils/cache/InMemoryCache.d.mts +29 -0
  85. package/dist/utils/cache/InMemoryCache.d.mts.map +1 -0
  86. package/dist/utils/cache/InMemoryCache.mjs +130 -0
  87. package/dist/utils/cache/InMemoryCache.mjs.map +1 -0
  88. package/dist/utils/cache/StateCache.cjs +193 -0
  89. package/dist/utils/cache/StateCache.cjs.map +1 -0
  90. package/dist/utils/cache/StateCache.d.cts +96 -0
  91. package/dist/utils/cache/StateCache.d.cts.map +1 -0
  92. package/dist/utils/cache/StateCache.d.mts +96 -0
  93. package/dist/utils/cache/StateCache.d.mts.map +1 -0
  94. package/dist/utils/cache/StateCache.mjs +189 -0
  95. package/dist/utils/cache/StateCache.mjs.map +1 -0
  96. package/dist/utils/cache/types.cjs +3 -0
  97. package/dist/utils/cache/types.cjs.map +1 -0
  98. package/dist/utils/cache/types.d.cts +99 -0
  99. package/dist/utils/cache/types.d.cts.map +1 -0
  100. package/dist/utils/cache/types.d.mts +99 -0
  101. package/dist/utils/cache/types.d.mts.map +1 -0
  102. package/dist/utils/cache/types.mjs +2 -0
  103. package/dist/utils/cache/types.mjs.map +1 -0
  104. package/dist/utils/cache/useCache.cjs +82 -0
  105. package/dist/utils/cache/useCache.cjs.map +1 -0
  106. package/dist/utils/cache/useCache.d.cts +57 -0
  107. package/dist/utils/cache/useCache.d.cts.map +1 -0
  108. package/dist/utils/cache/useCache.d.mts +57 -0
  109. package/dist/utils/cache/useCache.d.mts.map +1 -0
  110. package/dist/utils/cache/useCache.mjs +78 -0
  111. package/dist/utils/cache/useCache.mjs.map +1 -0
  112. package/dist/utils/cache/useCacheUntil.cjs +80 -0
  113. package/dist/utils/cache/useCacheUntil.cjs.map +1 -0
  114. package/dist/utils/cache/useCacheUntil.d.cts +54 -0
  115. package/dist/utils/cache/useCacheUntil.d.cts.map +1 -0
  116. package/dist/utils/cache/useCacheUntil.d.mts +54 -0
  117. package/dist/utils/cache/useCacheUntil.d.mts.map +1 -0
  118. package/dist/utils/cache/useCacheUntil.mjs +76 -0
  119. package/dist/utils/cache/useCacheUntil.mjs.map +1 -0
  120. package/dist/utils/config/BaseConfigProvider.cjs +62 -0
  121. package/dist/utils/config/BaseConfigProvider.cjs.map +1 -0
  122. package/dist/utils/config/BaseConfigProvider.d.cts +54 -0
  123. package/dist/utils/config/BaseConfigProvider.d.cts.map +1 -0
  124. package/dist/utils/config/BaseConfigProvider.d.mts +54 -0
  125. package/dist/utils/config/BaseConfigProvider.d.mts.map +1 -0
  126. package/dist/utils/config/BaseConfigProvider.mjs +58 -0
  127. package/dist/utils/config/BaseConfigProvider.mjs.map +1 -0
  128. package/dist/utils/config/envStructs.cjs +69 -0
  129. package/dist/utils/config/envStructs.cjs.map +1 -0
  130. package/dist/utils/config/envStructs.d.cts +57 -0
  131. package/dist/utils/config/envStructs.d.cts.map +1 -0
  132. package/dist/utils/config/envStructs.d.mts +57 -0
  133. package/dist/utils/config/envStructs.d.mts.map +1 -0
  134. package/dist/utils/config/envStructs.mjs +61 -0
  135. package/dist/utils/config/envStructs.mjs.map +1 -0
  136. package/dist/utils/config/environmentStruct.cjs +19 -0
  137. package/dist/utils/config/environmentStruct.cjs.map +1 -0
  138. package/dist/utils/config/environmentStruct.d.cts +20 -0
  139. package/dist/utils/config/environmentStruct.d.cts.map +1 -0
  140. package/dist/utils/config/environmentStruct.d.mts +20 -0
  141. package/dist/utils/config/environmentStruct.d.mts.map +1 -0
  142. package/dist/utils/config/environmentStruct.mjs +16 -0
  143. package/dist/utils/config/environmentStruct.mjs.map +1 -0
  144. package/dist/utils/config/logLevelStruct.cjs +14 -0
  145. package/dist/utils/config/logLevelStruct.cjs.map +1 -0
  146. package/dist/utils/config/logLevelStruct.d.cts +17 -0
  147. package/dist/utils/config/logLevelStruct.d.cts.map +1 -0
  148. package/dist/utils/config/logLevelStruct.d.mts +17 -0
  149. package/dist/utils/config/logLevelStruct.d.mts.map +1 -0
  150. package/dist/utils/config/logLevelStruct.mjs +11 -0
  151. package/dist/utils/config/logLevelStruct.mjs.map +1 -0
  152. package/dist/utils/config/parseEnv.cjs +30 -0
  153. package/dist/utils/config/parseEnv.cjs.map +1 -0
  154. package/dist/utils/config/parseEnv.d.cts +19 -0
  155. package/dist/utils/config/parseEnv.d.cts.map +1 -0
  156. package/dist/utils/config/parseEnv.d.mts +19 -0
  157. package/dist/utils/config/parseEnv.d.mts.map +1 -0
  158. package/dist/utils/config/parseEnv.mjs +26 -0
  159. package/dist/utils/config/parseEnv.mjs.map +1 -0
  160. package/dist/utils/dedupe/InFlightCoalescer.cjs +28 -0
  161. package/dist/utils/dedupe/InFlightCoalescer.cjs.map +1 -0
  162. package/dist/utils/dedupe/InFlightCoalescer.d.cts +12 -0
  163. package/dist/utils/dedupe/InFlightCoalescer.d.cts.map +1 -0
  164. package/dist/utils/dedupe/InFlightCoalescer.d.mts +12 -0
  165. package/dist/utils/dedupe/InFlightCoalescer.d.mts.map +1 -0
  166. package/dist/utils/dedupe/InFlightCoalescer.mjs +24 -0
  167. package/dist/utils/dedupe/InFlightCoalescer.mjs.map +1 -0
  168. package/dist/utils/errors/errors.cjs +44 -0
  169. package/dist/utils/errors/errors.cjs.map +1 -0
  170. package/dist/utils/errors/errors.d.cts +37 -0
  171. package/dist/utils/errors/errors.d.cts.map +1 -0
  172. package/dist/utils/errors/errors.d.mts +37 -0
  173. package/dist/utils/errors/errors.d.mts.map +1 -0
  174. package/dist/utils/errors/errors.mjs +40 -0
  175. package/dist/utils/errors/errors.mjs.map +1 -0
  176. package/dist/utils/errors/index.cjs +18 -0
  177. package/dist/utils/errors/index.cjs.map +1 -0
  178. package/dist/utils/errors/index.d.cts +10 -0
  179. package/dist/utils/errors/index.d.cts.map +1 -0
  180. package/dist/utils/errors/index.d.mts +10 -0
  181. package/dist/utils/errors/index.d.mts.map +1 -0
  182. package/dist/utils/errors/index.mjs +6 -0
  183. package/dist/utils/errors/index.mjs.map +1 -0
  184. package/dist/utils/errors/snapRpcError.cjs +33 -0
  185. package/dist/utils/errors/snapRpcError.cjs.map +1 -0
  186. package/dist/utils/errors/snapRpcError.d.cts +11 -0
  187. package/dist/utils/errors/snapRpcError.d.cts.map +1 -0
  188. package/dist/utils/errors/snapRpcError.d.mts +11 -0
  189. package/dist/utils/errors/snapRpcError.d.mts.map +1 -0
  190. package/dist/utils/errors/snapRpcError.mjs +30 -0
  191. package/dist/utils/errors/snapRpcError.mjs.map +1 -0
  192. package/dist/utils/errors/stringifyReason.cjs +36 -0
  193. package/dist/utils/errors/stringifyReason.cjs.map +1 -0
  194. package/dist/utils/errors/stringifyReason.d.cts +15 -0
  195. package/dist/utils/errors/stringifyReason.d.cts.map +1 -0
  196. package/dist/utils/errors/stringifyReason.d.mts +15 -0
  197. package/dist/utils/errors/stringifyReason.d.mts.map +1 -0
  198. package/dist/utils/errors/stringifyReason.mjs +33 -0
  199. package/dist/utils/errors/stringifyReason.mjs.map +1 -0
  200. package/dist/utils/errors/syncError.cjs +98 -0
  201. package/dist/utils/errors/syncError.cjs.map +1 -0
  202. package/dist/utils/errors/syncError.d.cts +60 -0
  203. package/dist/utils/errors/syncError.d.cts.map +1 -0
  204. package/dist/utils/errors/syncError.d.mts +60 -0
  205. package/dist/utils/errors/syncError.d.mts.map +1 -0
  206. package/dist/utils/errors/syncError.mjs +92 -0
  207. package/dist/utils/errors/syncError.mjs.map +1 -0
  208. package/dist/utils/errors/trackError.cjs +76 -0
  209. package/dist/utils/errors/trackError.cjs.map +1 -0
  210. package/dist/utils/errors/trackError.d.cts +64 -0
  211. package/dist/utils/errors/trackError.d.cts.map +1 -0
  212. package/dist/utils/errors/trackError.d.mts +64 -0
  213. package/dist/utils/errors/trackError.d.mts.map +1 -0
  214. package/dist/utils/errors/trackError.mjs +72 -0
  215. package/dist/utils/errors/trackError.mjs.map +1 -0
  216. package/dist/utils/handlers/wrapSnapHandlers.cjs +57 -0
  217. package/dist/utils/handlers/wrapSnapHandlers.cjs.map +1 -0
  218. package/dist/utils/handlers/wrapSnapHandlers.d.cts +74 -0
  219. package/dist/utils/handlers/wrapSnapHandlers.d.cts.map +1 -0
  220. package/dist/utils/handlers/wrapSnapHandlers.d.mts +74 -0
  221. package/dist/utils/handlers/wrapSnapHandlers.d.mts.map +1 -0
  222. package/dist/utils/handlers/wrapSnapHandlers.mjs +53 -0
  223. package/dist/utils/handlers/wrapSnapHandlers.mjs.map +1 -0
  224. package/dist/utils/keyringAccount/keyringAccount.cjs +25 -0
  225. package/dist/utils/keyringAccount/keyringAccount.cjs.map +1 -0
  226. package/dist/utils/keyringAccount/keyringAccount.d.cts +29 -0
  227. package/dist/utils/keyringAccount/keyringAccount.d.cts.map +1 -0
  228. package/dist/utils/keyringAccount/keyringAccount.d.mts +29 -0
  229. package/dist/utils/keyringAccount/keyringAccount.d.mts.map +1 -0
  230. package/dist/utils/keyringAccount/keyringAccount.mjs +22 -0
  231. package/dist/utils/keyringAccount/keyringAccount.mjs.map +1 -0
  232. package/dist/utils/logger/Logger.cjs +140 -0
  233. package/dist/utils/logger/Logger.cjs.map +1 -0
  234. package/dist/utils/logger/Logger.d.cts +118 -0
  235. package/dist/utils/logger/Logger.d.cts.map +1 -0
  236. package/dist/utils/logger/Logger.d.mts +118 -0
  237. package/dist/utils/logger/Logger.d.mts.map +1 -0
  238. package/dist/utils/logger/Logger.mjs +136 -0
  239. package/dist/utils/logger/Logger.mjs.map +1 -0
  240. package/dist/utils/logger/__mocks__/Logger.cjs +26 -0
  241. package/dist/utils/logger/__mocks__/Logger.cjs.map +1 -0
  242. package/dist/utils/logger/__mocks__/Logger.d.cts +3 -0
  243. package/dist/utils/logger/__mocks__/Logger.d.cts.map +1 -0
  244. package/dist/utils/logger/__mocks__/Logger.d.mts +3 -0
  245. package/dist/utils/logger/__mocks__/Logger.d.mts.map +1 -0
  246. package/dist/utils/logger/__mocks__/Logger.mjs +23 -0
  247. package/dist/utils/logger/__mocks__/Logger.mjs.map +1 -0
  248. package/dist/utils/originPermissions/createOriginPermissions.cjs +30 -0
  249. package/dist/utils/originPermissions/createOriginPermissions.cjs.map +1 -0
  250. package/dist/utils/originPermissions/createOriginPermissions.d.cts +24 -0
  251. package/dist/utils/originPermissions/createOriginPermissions.d.cts.map +1 -0
  252. package/dist/utils/originPermissions/createOriginPermissions.d.mts +24 -0
  253. package/dist/utils/originPermissions/createOriginPermissions.d.mts.map +1 -0
  254. package/dist/utils/originPermissions/createOriginPermissions.mjs +26 -0
  255. package/dist/utils/originPermissions/createOriginPermissions.mjs.map +1 -0
  256. package/dist/utils/originPermissions/validateOrigin.cjs +23 -0
  257. package/dist/utils/originPermissions/validateOrigin.cjs.map +1 -0
  258. package/dist/utils/originPermissions/validateOrigin.d.cts +10 -0
  259. package/dist/utils/originPermissions/validateOrigin.d.cts.map +1 -0
  260. package/dist/utils/originPermissions/validateOrigin.d.mts +10 -0
  261. package/dist/utils/originPermissions/validateOrigin.d.mts.map +1 -0
  262. package/dist/utils/originPermissions/validateOrigin.mjs +19 -0
  263. package/dist/utils/originPermissions/validateOrigin.mjs.map +1 -0
  264. package/dist/utils/proofOfOwnership/proofOfOwnership.cjs +89 -0
  265. package/dist/utils/proofOfOwnership/proofOfOwnership.cjs.map +1 -0
  266. package/dist/utils/proofOfOwnership/proofOfOwnership.d.cts +143 -0
  267. package/dist/utils/proofOfOwnership/proofOfOwnership.d.cts.map +1 -0
  268. package/dist/utils/proofOfOwnership/proofOfOwnership.d.mts +143 -0
  269. package/dist/utils/proofOfOwnership/proofOfOwnership.d.mts.map +1 -0
  270. package/dist/utils/proofOfOwnership/proofOfOwnership.mjs +85 -0
  271. package/dist/utils/proofOfOwnership/proofOfOwnership.mjs.map +1 -0
  272. package/dist/utils/safeMerge/safeMerge.cjs +26 -0
  273. package/dist/utils/safeMerge/safeMerge.cjs.map +1 -0
  274. package/dist/utils/safeMerge/safeMerge.d.cts +17 -0
  275. package/dist/utils/safeMerge/safeMerge.d.cts.map +1 -0
  276. package/dist/utils/safeMerge/safeMerge.d.mts +17 -0
  277. package/dist/utils/safeMerge/safeMerge.d.mts.map +1 -0
  278. package/dist/utils/safeMerge/safeMerge.mjs +22 -0
  279. package/dist/utils/safeMerge/safeMerge.mjs.map +1 -0
  280. package/dist/utils/sanitize/sanitize.cjs +42 -0
  281. package/dist/utils/sanitize/sanitize.cjs.map +1 -0
  282. package/dist/utils/sanitize/sanitize.d.cts +15 -0
  283. package/dist/utils/sanitize/sanitize.d.cts.map +1 -0
  284. package/dist/utils/sanitize/sanitize.d.mts +15 -0
  285. package/dist/utils/sanitize/sanitize.d.mts.map +1 -0
  286. package/dist/utils/sanitize/sanitize.mjs +38 -0
  287. package/dist/utils/sanitize/sanitize.mjs.map +1 -0
  288. package/dist/utils/serialization/serialization.cjs +73 -0
  289. package/dist/utils/serialization/serialization.cjs.map +1 -0
  290. package/dist/utils/serialization/serialization.d.cts +19 -0
  291. package/dist/utils/serialization/serialization.d.cts.map +1 -0
  292. package/dist/utils/serialization/serialization.d.mts +19 -0
  293. package/dist/utils/serialization/serialization.d.mts.map +1 -0
  294. package/dist/utils/serialization/serialization.mjs +69 -0
  295. package/dist/utils/serialization/serialization.mjs.map +1 -0
  296. package/dist/utils/serialization/types.cjs +3 -0
  297. package/dist/utils/serialization/types.cjs.map +1 -0
  298. package/dist/utils/serialization/types.d.cts +8 -0
  299. package/dist/utils/serialization/types.d.cts.map +1 -0
  300. package/dist/utils/serialization/types.d.mts +8 -0
  301. package/dist/utils/serialization/types.d.mts.map +1 -0
  302. package/dist/utils/serialization/types.mjs +2 -0
  303. package/dist/utils/serialization/types.mjs.map +1 -0
  304. package/dist/utils/state/IStateManager.cjs +3 -0
  305. package/dist/utils/state/IStateManager.cjs.map +1 -0
  306. package/dist/utils/state/IStateManager.d.cts +69 -0
  307. package/dist/utils/state/IStateManager.d.cts.map +1 -0
  308. package/dist/utils/state/IStateManager.d.mts +69 -0
  309. package/dist/utils/state/IStateManager.d.mts.map +1 -0
  310. package/dist/utils/state/IStateManager.mjs +2 -0
  311. package/dist/utils/state/IStateManager.mjs.map +1 -0
  312. package/dist/utils/state/InMemoryState.cjs +41 -0
  313. package/dist/utils/state/InMemoryState.cjs.map +1 -0
  314. package/dist/utils/state/InMemoryState.d.cts +18 -0
  315. package/dist/utils/state/InMemoryState.d.cts.map +1 -0
  316. package/dist/utils/state/InMemoryState.d.mts +18 -0
  317. package/dist/utils/state/InMemoryState.d.mts.map +1 -0
  318. package/dist/utils/state/InMemoryState.mjs +38 -0
  319. package/dist/utils/state/InMemoryState.mjs.map +1 -0
  320. package/dist/utils/state/State.cjs +159 -0
  321. package/dist/utils/state/State.cjs.map +1 -0
  322. package/dist/utils/state/State.d.cts +25 -0
  323. package/dist/utils/state/State.d.cts.map +1 -0
  324. package/dist/utils/state/State.d.mts +25 -0
  325. package/dist/utils/state/State.d.mts.map +1 -0
  326. package/dist/utils/state/State.mjs +156 -0
  327. package/dist/utils/state/State.mjs.map +1 -0
  328. package/dist/utils/transactionType/transactionType.cjs +32 -0
  329. package/dist/utils/transactionType/transactionType.cjs.map +1 -0
  330. package/dist/utils/transactionType/transactionType.d.cts +17 -0
  331. package/dist/utils/transactionType/transactionType.d.cts.map +1 -0
  332. package/dist/utils/transactionType/transactionType.d.mts +17 -0
  333. package/dist/utils/transactionType/transactionType.d.mts.map +1 -0
  334. package/dist/utils/transactionType/transactionType.mjs +28 -0
  335. package/dist/utils/transactionType/transactionType.mjs.map +1 -0
  336. package/dist/utils/urlStruct/urlStruct.cjs +96 -0
  337. package/dist/utils/urlStruct/urlStruct.cjs.map +1 -0
  338. package/dist/utils/urlStruct/urlStruct.d.cts +25 -0
  339. package/dist/utils/urlStruct/urlStruct.d.cts.map +1 -0
  340. package/dist/utils/urlStruct/urlStruct.d.mts +25 -0
  341. package/dist/utils/urlStruct/urlStruct.d.mts.map +1 -0
  342. package/dist/utils/urlStruct/urlStruct.mjs +93 -0
  343. package/dist/utils/urlStruct/urlStruct.mjs.map +1 -0
  344. package/dist/utils/uuidStruct/uuidStruct.cjs +12 -0
  345. package/dist/utils/uuidStruct/uuidStruct.cjs.map +1 -0
  346. package/dist/utils/uuidStruct/uuidStruct.d.cts +8 -0
  347. package/dist/utils/uuidStruct/uuidStruct.d.cts.map +1 -0
  348. package/dist/utils/uuidStruct/uuidStruct.d.mts +8 -0
  349. package/dist/utils/uuidStruct/uuidStruct.d.mts.map +1 -0
  350. package/dist/utils/uuidStruct/uuidStruct.mjs +9 -0
  351. package/dist/utils/uuidStruct/uuidStruct.mjs.map +1 -0
  352. package/package.json +33 -13
  353. package/dist/logger.cjs +0 -57
  354. package/dist/logger.cjs.map +0 -1
  355. package/dist/logger.d.cts +0 -30
  356. package/dist/logger.d.cts.map +0 -1
  357. package/dist/logger.d.mts +0 -30
  358. package/dist/logger.d.mts.map +0 -1
  359. package/dist/logger.mjs +0 -53
  360. package/dist/logger.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.cjs","sourceRoot":"","sources":["../../../src/utils/sanitize/sanitize.ts"],"names":[],"mappings":";;AAMA,8DAQC;AAQD,kCAiBC;AAvCD;;;;;GAKG;AACH,SAAgB,yBAAyB,CAAC,KAAa;IACrD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,4CAA4C;IAC5C,4CAA4C;IAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,sCAAsC,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,GAAW;IACrC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,SAAS,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC;IAEjD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9D,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;YACxE,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["/**\n * Removes control characters from a string.\n *\n * @param input - The string to sanitize.\n * @returns The sanitized string.\n */\nexport function sanitizeControlCharacters(input: string): string {\n if (!input || typeof input !== 'string') {\n return '';\n }\n\n // Remove all control characters except tab.\n // eslint-disable-next-line no-control-regex\n return input.replace(/[\\u0000-\\u0008\\u000A-\\u001F\\u007F]/gu, '');\n}\n\n/**\n * Validates and sanitizes a URI.\n *\n * @param uri - The URI to validate and sanitize.\n * @returns The sanitized URI or an empty string if invalid.\n */\nexport function sanitizeUri(uri: string): string {\n if (!uri || typeof uri !== 'string') {\n return '';\n }\n\n const sanitized = sanitizeControlCharacters(uri);\n\n try {\n const url = new URL(sanitized);\n const allowedProtocols = ['http:', 'https:', 'wss:', 'ipfs:'];\n if (!allowedProtocols.includes(url.protocol) || sanitized.length > 2048) {\n return '';\n }\n return sanitized;\n } catch {\n return '';\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Removes control characters from a string.
3
+ *
4
+ * @param input - The string to sanitize.
5
+ * @returns The sanitized string.
6
+ */
7
+ export declare function sanitizeControlCharacters(input: string): string;
8
+ /**
9
+ * Validates and sanitizes a URI.
10
+ *
11
+ * @param uri - The URI to validate and sanitize.
12
+ * @returns The sanitized URI or an empty string if invalid.
13
+ */
14
+ export declare function sanitizeUri(uri: string): string;
15
+ //# sourceMappingURL=sanitize.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.d.cts","sourceRoot":"","sources":["../../../src/utils/sanitize/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ/D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB/C"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Removes control characters from a string.
3
+ *
4
+ * @param input - The string to sanitize.
5
+ * @returns The sanitized string.
6
+ */
7
+ export declare function sanitizeControlCharacters(input: string): string;
8
+ /**
9
+ * Validates and sanitizes a URI.
10
+ *
11
+ * @param uri - The URI to validate and sanitize.
12
+ * @returns The sanitized URI or an empty string if invalid.
13
+ */
14
+ export declare function sanitizeUri(uri: string): string;
15
+ //# sourceMappingURL=sanitize.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.d.mts","sourceRoot":"","sources":["../../../src/utils/sanitize/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ/D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB/C"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Removes control characters from a string.
3
+ *
4
+ * @param input - The string to sanitize.
5
+ * @returns The sanitized string.
6
+ */
7
+ export function sanitizeControlCharacters(input) {
8
+ if (!input || typeof input !== 'string') {
9
+ return '';
10
+ }
11
+ // Remove all control characters except tab.
12
+ // eslint-disable-next-line no-control-regex
13
+ return input.replace(/[\u0000-\u0008\u000A-\u001F\u007F]/gu, '');
14
+ }
15
+ /**
16
+ * Validates and sanitizes a URI.
17
+ *
18
+ * @param uri - The URI to validate and sanitize.
19
+ * @returns The sanitized URI or an empty string if invalid.
20
+ */
21
+ export function sanitizeUri(uri) {
22
+ if (!uri || typeof uri !== 'string') {
23
+ return '';
24
+ }
25
+ const sanitized = sanitizeControlCharacters(uri);
26
+ try {
27
+ const url = new URL(sanitized);
28
+ const allowedProtocols = ['http:', 'https:', 'wss:', 'ipfs:'];
29
+ if (!allowedProtocols.includes(url.protocol) || sanitized.length > 2048) {
30
+ return '';
31
+ }
32
+ return sanitized;
33
+ }
34
+ catch {
35
+ return '';
36
+ }
37
+ }
38
+ //# sourceMappingURL=sanitize.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.mjs","sourceRoot":"","sources":["../../../src/utils/sanitize/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAAa;IACrD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,4CAA4C;IAC5C,4CAA4C;IAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,sCAAsC,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,SAAS,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC;IAEjD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9D,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;YACxE,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["/**\n * Removes control characters from a string.\n *\n * @param input - The string to sanitize.\n * @returns The sanitized string.\n */\nexport function sanitizeControlCharacters(input: string): string {\n if (!input || typeof input !== 'string') {\n return '';\n }\n\n // Remove all control characters except tab.\n // eslint-disable-next-line no-control-regex\n return input.replace(/[\\u0000-\\u0008\\u000A-\\u001F\\u007F]/gu, '');\n}\n\n/**\n * Validates and sanitizes a URI.\n *\n * @param uri - The URI to validate and sanitize.\n * @returns The sanitized URI or an empty string if invalid.\n */\nexport function sanitizeUri(uri: string): string {\n if (!uri || typeof uri !== 'string') {\n return '';\n }\n\n const sanitized = sanitizeControlCharacters(uri);\n\n try {\n const url = new URL(sanitized);\n const allowedProtocols = ['http:', 'https:', 'wss:', 'ipfs:'];\n if (!allowedProtocols.includes(url.protocol) || sanitized.length > 2048) {\n return '';\n }\n return sanitized;\n } catch {\n return '';\n }\n}\n"]}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserialize = exports.serialize = void 0;
4
+ const bignumber_js_1 = require("bignumber.js");
5
+ const lodash_1 = require("lodash");
6
+ /**
7
+ * Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.
8
+ * It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.
9
+ *
10
+ * @param value - The value to serialize.
11
+ * @returns The serialized value.
12
+ */
13
+ const serialize = (value) => (0, lodash_1.cloneDeepWith)(value, (val) => {
14
+ if (val === undefined) {
15
+ return {
16
+ __type: 'undefined',
17
+ };
18
+ }
19
+ if (val instanceof bignumber_js_1.BigNumber) {
20
+ return {
21
+ __type: 'BigNumber',
22
+ value: val.toString(),
23
+ };
24
+ }
25
+ if (typeof val === 'bigint') {
26
+ return {
27
+ __type: 'bigint',
28
+ value: val.toString(),
29
+ };
30
+ }
31
+ if (val instanceof Uint8Array) {
32
+ const binaryString = Array.from(val, (byte) => String.fromCharCode(byte)).join('');
33
+ return {
34
+ __type: 'Uint8Array',
35
+ value: btoa(binaryString),
36
+ };
37
+ }
38
+ // Return undefined to let lodash handle the cloning of other values
39
+ return undefined;
40
+ });
41
+ exports.serialize = serialize;
42
+ /**
43
+ * Deserializes the passed value from a JSON object back to its original values.
44
+ * It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.
45
+ *
46
+ * @param serializedValue - The value to deserialize.
47
+ * @returns The deserialized value.
48
+ */
49
+ const deserialize = (serializedValue) => JSON.parse(JSON.stringify(serializedValue), (_key, value) => {
50
+ if (!value) {
51
+ return value;
52
+ }
53
+ if (value.__type === 'undefined') {
54
+ return undefined;
55
+ }
56
+ if (value.__type === 'BigNumber') {
57
+ return new bignumber_js_1.BigNumber(value.value);
58
+ }
59
+ if (value.__type === 'bigint') {
60
+ return BigInt(value.value);
61
+ }
62
+ if (value.__type === 'Uint8Array') {
63
+ const binaryString = atob(value.value);
64
+ const bytes = new Uint8Array(binaryString.length);
65
+ for (let index = 0; index < binaryString.length; index++) {
66
+ bytes[index] = binaryString.charCodeAt(index);
67
+ }
68
+ return bytes;
69
+ }
70
+ return value;
71
+ });
72
+ exports.deserialize = deserialize;
73
+ //# sourceMappingURL=serialization.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.cjs","sourceRoot":"","sources":["../../../src/utils/serialization/serialization.ts"],"names":[],"mappings":";;;AACA,+CAAyC;AACzC,mCAAuC;AAIvC;;;;;;GAMG;AACI,MAAM,SAAS,GAAG,CAAC,KAAmB,EAAQ,EAAE,CACrD,IAAA,sBAAa,EAAC,KAAK,EAAE,CAAC,GAAY,EAAE,EAAE;IACpC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,MAAM,EAAE,WAAW;SACpB,CAAC;IACJ,CAAC;IAED,IAAI,GAAG,YAAY,wBAAS,EAAE,CAAC;QAC7B,OAAO;YACL,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE;SACtB,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO;YACL,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE;SACtB,CAAC;IACJ,CAAC;IAED,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;QAC9B,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAC5C,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAC1B,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACX,OAAO;YACL,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC;SAC1B,CAAC;IACJ,CAAC;IAED,oEAAoE;IACpE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC,CAAC;AAlCQ,QAAA,SAAS,aAkCjB;AAEL;;;;;;GAMG;AACI,MAAM,WAAW,GAAG,CAAC,eAAqB,EAAgB,EAAE,CACjE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;IAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,IAAI,wBAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;QAClC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAClD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACzD,KAAK,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CAAC;AA5BQ,QAAA,WAAW,eA4BnB","sourcesContent":["import type { Json } from '@metamask/snaps-sdk';\nimport { BigNumber } from 'bignumber.js';\nimport { cloneDeepWith } from 'lodash';\n\nimport type { Serializable } from './types';\n\n/**\n * Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.\n * It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.\n *\n * @param value - The value to serialize.\n * @returns The serialized value.\n */\nexport const serialize = (value: Serializable): Json =>\n cloneDeepWith(value, (val: unknown) => {\n if (val === undefined) {\n return {\n __type: 'undefined',\n };\n }\n\n if (val instanceof BigNumber) {\n return {\n __type: 'BigNumber',\n value: val.toString(),\n };\n }\n\n if (typeof val === 'bigint') {\n return {\n __type: 'bigint',\n value: val.toString(),\n };\n }\n\n if (val instanceof Uint8Array) {\n const binaryString = Array.from(val, (byte) =>\n String.fromCharCode(byte),\n ).join('');\n return {\n __type: 'Uint8Array',\n value: btoa(binaryString),\n };\n }\n\n // Return undefined to let lodash handle the cloning of other values\n return undefined;\n });\n\n/**\n * Deserializes the passed value from a JSON object back to its original values.\n * It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.\n *\n * @param serializedValue - The value to deserialize.\n * @returns The deserialized value.\n */\nexport const deserialize = (serializedValue: Json): Serializable =>\n JSON.parse(JSON.stringify(serializedValue), (_key, value) => {\n if (!value) {\n return value;\n }\n\n if (value.__type === 'undefined') {\n return undefined;\n }\n\n if (value.__type === 'BigNumber') {\n return new BigNumber(value.value);\n }\n\n if (value.__type === 'bigint') {\n return BigInt(value.value);\n }\n\n if (value.__type === 'Uint8Array') {\n const binaryString = atob(value.value);\n const bytes = new Uint8Array(binaryString.length);\n for (let index = 0; index < binaryString.length; index++) {\n bytes[index] = binaryString.charCodeAt(index);\n }\n return bytes;\n }\n\n return value;\n });\n"]}
@@ -0,0 +1,19 @@
1
+ import type { Json } from "@metamask/snaps-sdk";
2
+ import type { Serializable } from "./types.cjs";
3
+ /**
4
+ * Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.
5
+ * It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.
6
+ *
7
+ * @param value - The value to serialize.
8
+ * @returns The serialized value.
9
+ */
10
+ export declare const serialize: (value: Serializable) => Json;
11
+ /**
12
+ * Deserializes the passed value from a JSON object back to its original values.
13
+ * It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.
14
+ *
15
+ * @param serializedValue - The value to deserialize.
16
+ * @returns The deserialized value.
17
+ */
18
+ export declare const deserialize: (serializedValue: Json) => Serializable;
19
+ //# sourceMappingURL=serialization.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.d.cts","sourceRoot":"","sources":["../../../src/utils/serialization/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAIhD,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAgB;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,YAAY,KAAG,IAkC5C,CAAC;AAEL;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,iBAAiB,IAAI,KAAG,YA4BhD,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Json } from "@metamask/snaps-sdk";
2
+ import type { Serializable } from "./types.mjs";
3
+ /**
4
+ * Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.
5
+ * It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.
6
+ *
7
+ * @param value - The value to serialize.
8
+ * @returns The serialized value.
9
+ */
10
+ export declare const serialize: (value: Serializable) => Json;
11
+ /**
12
+ * Deserializes the passed value from a JSON object back to its original values.
13
+ * It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.
14
+ *
15
+ * @param serializedValue - The value to deserialize.
16
+ * @returns The deserialized value.
17
+ */
18
+ export declare const deserialize: (serializedValue: Json) => Serializable;
19
+ //# sourceMappingURL=serialization.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.d.mts","sourceRoot":"","sources":["../../../src/utils/serialization/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAIhD,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAgB;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,YAAY,KAAG,IAkC5C,CAAC;AAEL;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,iBAAiB,IAAI,KAAG,YA4BhD,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import $lodash from "lodash";
3
+ const { cloneDeepWith } = $lodash;
4
+ /**
5
+ * Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.
6
+ * It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.
7
+ *
8
+ * @param value - The value to serialize.
9
+ * @returns The serialized value.
10
+ */
11
+ export const serialize = (value) => cloneDeepWith(value, (val) => {
12
+ if (val === undefined) {
13
+ return {
14
+ __type: 'undefined',
15
+ };
16
+ }
17
+ if (val instanceof BigNumber) {
18
+ return {
19
+ __type: 'BigNumber',
20
+ value: val.toString(),
21
+ };
22
+ }
23
+ if (typeof val === 'bigint') {
24
+ return {
25
+ __type: 'bigint',
26
+ value: val.toString(),
27
+ };
28
+ }
29
+ if (val instanceof Uint8Array) {
30
+ const binaryString = Array.from(val, (byte) => String.fromCharCode(byte)).join('');
31
+ return {
32
+ __type: 'Uint8Array',
33
+ value: btoa(binaryString),
34
+ };
35
+ }
36
+ // Return undefined to let lodash handle the cloning of other values
37
+ return undefined;
38
+ });
39
+ /**
40
+ * Deserializes the passed value from a JSON object back to its original values.
41
+ * It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.
42
+ *
43
+ * @param serializedValue - The value to deserialize.
44
+ * @returns The deserialized value.
45
+ */
46
+ export const deserialize = (serializedValue) => JSON.parse(JSON.stringify(serializedValue), (_key, value) => {
47
+ if (!value) {
48
+ return value;
49
+ }
50
+ if (value.__type === 'undefined') {
51
+ return undefined;
52
+ }
53
+ if (value.__type === 'BigNumber') {
54
+ return new BigNumber(value.value);
55
+ }
56
+ if (value.__type === 'bigint') {
57
+ return BigInt(value.value);
58
+ }
59
+ if (value.__type === 'Uint8Array') {
60
+ const binaryString = atob(value.value);
61
+ const bytes = new Uint8Array(binaryString.length);
62
+ for (let index = 0; index < binaryString.length; index++) {
63
+ bytes[index] = binaryString.charCodeAt(index);
64
+ }
65
+ return bytes;
66
+ }
67
+ return value;
68
+ });
69
+ //# sourceMappingURL=serialization.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.mjs","sourceRoot":"","sources":["../../../src/utils/serialization/serialization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,qBAAqB;;;AAKzC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAmB,EAAQ,EAAE,CACrD,aAAa,CAAC,KAAK,EAAE,CAAC,GAAY,EAAE,EAAE;IACpC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,MAAM,EAAE,WAAW;SACpB,CAAC;IACJ,CAAC;IAED,IAAI,GAAG,YAAY,SAAS,EAAE,CAAC;QAC7B,OAAO;YACL,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE;SACtB,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO;YACL,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE;SACtB,CAAC;IACJ,CAAC;IAED,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;QAC9B,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAC5C,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAC1B,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACX,OAAO;YACL,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC;SAC1B,CAAC;IACJ,CAAC;IAED,oEAAoE;IACpE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC,CAAC;AAEL;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,eAAqB,EAAgB,EAAE,CACjE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;IAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;QAClC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAClD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACzD,KAAK,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/snaps-sdk';\nimport { BigNumber } from 'bignumber.js';\nimport { cloneDeepWith } from 'lodash';\n\nimport type { Serializable } from './types';\n\n/**\n * Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.\n * It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.\n *\n * @param value - The value to serialize.\n * @returns The serialized value.\n */\nexport const serialize = (value: Serializable): Json =>\n cloneDeepWith(value, (val: unknown) => {\n if (val === undefined) {\n return {\n __type: 'undefined',\n };\n }\n\n if (val instanceof BigNumber) {\n return {\n __type: 'BigNumber',\n value: val.toString(),\n };\n }\n\n if (typeof val === 'bigint') {\n return {\n __type: 'bigint',\n value: val.toString(),\n };\n }\n\n if (val instanceof Uint8Array) {\n const binaryString = Array.from(val, (byte) =>\n String.fromCharCode(byte),\n ).join('');\n return {\n __type: 'Uint8Array',\n value: btoa(binaryString),\n };\n }\n\n // Return undefined to let lodash handle the cloning of other values\n return undefined;\n });\n\n/**\n * Deserializes the passed value from a JSON object back to its original values.\n * It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.\n *\n * @param serializedValue - The value to deserialize.\n * @returns The deserialized value.\n */\nexport const deserialize = (serializedValue: Json): Serializable =>\n JSON.parse(JSON.stringify(serializedValue), (_key, value) => {\n if (!value) {\n return value;\n }\n\n if (value.__type === 'undefined') {\n return undefined;\n }\n\n if (value.__type === 'BigNumber') {\n return new BigNumber(value.value);\n }\n\n if (value.__type === 'bigint') {\n return BigInt(value.value);\n }\n\n if (value.__type === 'Uint8Array') {\n const binaryString = atob(value.value);\n const bytes = new Uint8Array(binaryString.length);\n for (let index = 0; index < binaryString.length; index++) {\n bytes[index] = binaryString.charCodeAt(index);\n }\n return bytes;\n }\n\n return value;\n });\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../src/utils/serialization/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/snaps-sdk';\nimport type { BigNumber } from 'bignumber.js';\n\n/**\n * A primitive value that can be serialized to JSON using the `serialize` function.\n */\nexport type Serializable =\n | Json\n | undefined\n | null\n | bigint\n | BigNumber\n | Uint8Array\n | Serializable[]\n | {\n [prop: string]: Serializable;\n };\n"]}
@@ -0,0 +1,8 @@
1
+ import type { Json } from "@metamask/snaps-sdk";
2
+ /**
3
+ * A primitive value that can be serialized to JSON using the `serialize` function.
4
+ */
5
+ export type Serializable = Json | undefined | null | bigint | BigNumber | Uint8Array | Serializable[] | {
6
+ [prop: string]: Serializable;
7
+ };
8
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../src/utils/serialization/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAGhD;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,IAAI,GACJ,SAAS,GACT,IAAI,GACJ,MAAM,GACN,SAAS,GACT,UAAU,GACV,YAAY,EAAE,GACd;IACE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;CAC9B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Json } from "@metamask/snaps-sdk";
2
+ /**
3
+ * A primitive value that can be serialized to JSON using the `serialize` function.
4
+ */
5
+ export type Serializable = Json | undefined | null | bigint | BigNumber | Uint8Array | Serializable[] | {
6
+ [prop: string]: Serializable;
7
+ };
8
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../src/utils/serialization/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAGhD;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,IAAI,GACJ,SAAS,GACT,IAAI,GACJ,MAAM,GACN,SAAS,GACT,UAAU,GACV,YAAY,EAAE,GACd;IACE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;CAC9B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../src/utils/serialization/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/snaps-sdk';\nimport type { BigNumber } from 'bignumber.js';\n\n/**\n * A primitive value that can be serialized to JSON using the `serialize` function.\n */\nexport type Serializable =\n | Json\n | undefined\n | null\n | bigint\n | BigNumber\n | Uint8Array\n | Serializable[]\n | {\n [prop: string]: Serializable;\n };\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IStateManager.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IStateManager.cjs","sourceRoot":"","sources":["../../../src/utils/state/IStateManager.ts"],"names":[],"mappings":"","sourcesContent":["import type { Serializable } from '../serialization/types';\n\nexport type IStateManager<TStateValue extends Record<string, Serializable>> = {\n /**\n * Gets the whole state object.\n *\n * ⚠️ WARNING: Use with caution because it transfers the whole state, which might contain a lot of data.\n * If you need to retrieve only a specific part of the state, use IStateManager.getKey instead.\n */\n get(): Promise<TStateValue>;\n /**\n * Gets the value of the passed key in the state object.\n * The key is the JSON path to the value to get.\n *\n * @returns The value of the key, or undefined if the key does not exist.\n */\n getKey<TResponse extends Serializable>(\n key: string,\n ): Promise<TResponse | undefined>;\n /**\n * Sets the value of the passed key in the state object.\n * The key is a JSON path to the value to set.\n *\n * @param key - The key to set, which is a JSON path to the location.\n * @param value - The value to set.\n */\n setKey(key: string, value: Serializable): Promise<void>;\n /**\n * Atomically reads the current value at `key`, applies `updater`, and writes the result back.\n *\n * Implementations must ensure that no concurrent state write can interleave between the\n * read and the write. This makes the method safe for updates where the next value depends\n * on the current value, such as merging objects.\n *\n * Prefer this over a manual `getKey` + `setKey` sequence whenever the new value depends on\n * the current one.\n *\n * @param key - The JSON-path key to update.\n * @param updater - Receives the current value (or `undefined` when the key is absent) and\n * returns the new value to store.\n */\n setKeyWith<TValue extends Serializable>(\n key: string,\n updater: (currentValue: TValue | undefined) => TValue,\n ): Promise<void>;\n /**\n * Updates the whole state object.\n *\n * Typically used for bulk `set`s or `delete`s, because:\n * - Atomicity: Using a single `state.update` ensures that all changes are applied atomically.\n * - Performance: One round trip instead of many `setKey` / `deleteKey` calls.\n * - State Consistency: Read once, modify in memory, write the complete updated state back.\n *\n * ⚠️ WARNING: Use with caution because:\n * - it will override the whole state.\n * - it transfers the whole state back and forth to the data store.\n *\n * For single updates, use `setKey` or `deleteKey` instead.\n *\n * @param updaterFunction - The function that updates the state.\n * @returns The updated state.\n */\n update(\n updaterFunction: (state: TStateValue) => TStateValue,\n ): Promise<TStateValue>;\n /**\n * Deletes the value of the passed key in the state object.\n * The key is a JSON path to the value to delete.\n */\n deleteKey(key: string): Promise<void>;\n /**\n * Deletes multiple keys in the state object in a single operation.\n * The keys are JSON paths to the values to delete.\n */\n deleteKeys(keys: string[]): Promise<void>;\n};\n"]}
@@ -0,0 +1,69 @@
1
+ import type { Serializable } from "../serialization/types.cjs";
2
+ export type IStateManager<TStateValue extends Record<string, Serializable>> = {
3
+ /**
4
+ * Gets the whole state object.
5
+ *
6
+ * ⚠️ WARNING: Use with caution because it transfers the whole state, which might contain a lot of data.
7
+ * If you need to retrieve only a specific part of the state, use IStateManager.getKey instead.
8
+ */
9
+ get(): Promise<TStateValue>;
10
+ /**
11
+ * Gets the value of the passed key in the state object.
12
+ * The key is the JSON path to the value to get.
13
+ *
14
+ * @returns The value of the key, or undefined if the key does not exist.
15
+ */
16
+ getKey<TResponse extends Serializable>(key: string): Promise<TResponse | undefined>;
17
+ /**
18
+ * Sets the value of the passed key in the state object.
19
+ * The key is a JSON path to the value to set.
20
+ *
21
+ * @param key - The key to set, which is a JSON path to the location.
22
+ * @param value - The value to set.
23
+ */
24
+ setKey(key: string, value: Serializable): Promise<void>;
25
+ /**
26
+ * Atomically reads the current value at `key`, applies `updater`, and writes the result back.
27
+ *
28
+ * Implementations must ensure that no concurrent state write can interleave between the
29
+ * read and the write. This makes the method safe for updates where the next value depends
30
+ * on the current value, such as merging objects.
31
+ *
32
+ * Prefer this over a manual `getKey` + `setKey` sequence whenever the new value depends on
33
+ * the current one.
34
+ *
35
+ * @param key - The JSON-path key to update.
36
+ * @param updater - Receives the current value (or `undefined` when the key is absent) and
37
+ * returns the new value to store.
38
+ */
39
+ setKeyWith<TValue extends Serializable>(key: string, updater: (currentValue: TValue | undefined) => TValue): Promise<void>;
40
+ /**
41
+ * Updates the whole state object.
42
+ *
43
+ * Typically used for bulk `set`s or `delete`s, because:
44
+ * - Atomicity: Using a single `state.update` ensures that all changes are applied atomically.
45
+ * - Performance: One round trip instead of many `setKey` / `deleteKey` calls.
46
+ * - State Consistency: Read once, modify in memory, write the complete updated state back.
47
+ *
48
+ * ⚠️ WARNING: Use with caution because:
49
+ * - it will override the whole state.
50
+ * - it transfers the whole state back and forth to the data store.
51
+ *
52
+ * For single updates, use `setKey` or `deleteKey` instead.
53
+ *
54
+ * @param updaterFunction - The function that updates the state.
55
+ * @returns The updated state.
56
+ */
57
+ update(updaterFunction: (state: TStateValue) => TStateValue): Promise<TStateValue>;
58
+ /**
59
+ * Deletes the value of the passed key in the state object.
60
+ * The key is a JSON path to the value to delete.
61
+ */
62
+ deleteKey(key: string): Promise<void>;
63
+ /**
64
+ * Deletes multiple keys in the state object in a single operation.
65
+ * The keys are JSON paths to the values to delete.
66
+ */
67
+ deleteKeys(keys: string[]): Promise<void>;
68
+ };
69
+ //# sourceMappingURL=IStateManager.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IStateManager.d.cts","sourceRoot":"","sources":["../../../src/utils/state/IStateManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mCAA+B;AAE3D,MAAM,MAAM,aAAa,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,IAAI;IAC5E;;;;;OAKG;IACH,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,SAAS,SAAS,YAAY,EACnC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAClC;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,MAAM,SAAS,YAAY,EACpC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GACpD,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CACJ,eAAe,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,WAAW,GACnD,OAAO,CAAC,WAAW,CAAC,CAAC;IACxB;;;OAGG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C,CAAC"}
@@ -0,0 +1,69 @@
1
+ import type { Serializable } from "../serialization/types.mjs";
2
+ export type IStateManager<TStateValue extends Record<string, Serializable>> = {
3
+ /**
4
+ * Gets the whole state object.
5
+ *
6
+ * ⚠️ WARNING: Use with caution because it transfers the whole state, which might contain a lot of data.
7
+ * If you need to retrieve only a specific part of the state, use IStateManager.getKey instead.
8
+ */
9
+ get(): Promise<TStateValue>;
10
+ /**
11
+ * Gets the value of the passed key in the state object.
12
+ * The key is the JSON path to the value to get.
13
+ *
14
+ * @returns The value of the key, or undefined if the key does not exist.
15
+ */
16
+ getKey<TResponse extends Serializable>(key: string): Promise<TResponse | undefined>;
17
+ /**
18
+ * Sets the value of the passed key in the state object.
19
+ * The key is a JSON path to the value to set.
20
+ *
21
+ * @param key - The key to set, which is a JSON path to the location.
22
+ * @param value - The value to set.
23
+ */
24
+ setKey(key: string, value: Serializable): Promise<void>;
25
+ /**
26
+ * Atomically reads the current value at `key`, applies `updater`, and writes the result back.
27
+ *
28
+ * Implementations must ensure that no concurrent state write can interleave between the
29
+ * read and the write. This makes the method safe for updates where the next value depends
30
+ * on the current value, such as merging objects.
31
+ *
32
+ * Prefer this over a manual `getKey` + `setKey` sequence whenever the new value depends on
33
+ * the current one.
34
+ *
35
+ * @param key - The JSON-path key to update.
36
+ * @param updater - Receives the current value (or `undefined` when the key is absent) and
37
+ * returns the new value to store.
38
+ */
39
+ setKeyWith<TValue extends Serializable>(key: string, updater: (currentValue: TValue | undefined) => TValue): Promise<void>;
40
+ /**
41
+ * Updates the whole state object.
42
+ *
43
+ * Typically used for bulk `set`s or `delete`s, because:
44
+ * - Atomicity: Using a single `state.update` ensures that all changes are applied atomically.
45
+ * - Performance: One round trip instead of many `setKey` / `deleteKey` calls.
46
+ * - State Consistency: Read once, modify in memory, write the complete updated state back.
47
+ *
48
+ * ⚠️ WARNING: Use with caution because:
49
+ * - it will override the whole state.
50
+ * - it transfers the whole state back and forth to the data store.
51
+ *
52
+ * For single updates, use `setKey` or `deleteKey` instead.
53
+ *
54
+ * @param updaterFunction - The function that updates the state.
55
+ * @returns The updated state.
56
+ */
57
+ update(updaterFunction: (state: TStateValue) => TStateValue): Promise<TStateValue>;
58
+ /**
59
+ * Deletes the value of the passed key in the state object.
60
+ * The key is a JSON path to the value to delete.
61
+ */
62
+ deleteKey(key: string): Promise<void>;
63
+ /**
64
+ * Deletes multiple keys in the state object in a single operation.
65
+ * The keys are JSON paths to the values to delete.
66
+ */
67
+ deleteKeys(keys: string[]): Promise<void>;
68
+ };
69
+ //# sourceMappingURL=IStateManager.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IStateManager.d.mts","sourceRoot":"","sources":["../../../src/utils/state/IStateManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mCAA+B;AAE3D,MAAM,MAAM,aAAa,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,IAAI;IAC5E;;;;;OAKG;IACH,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,SAAS,SAAS,YAAY,EACnC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAClC;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,MAAM,SAAS,YAAY,EACpC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GACpD,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CACJ,eAAe,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,WAAW,GACnD,OAAO,CAAC,WAAW,CAAC,CAAC;IACxB;;;OAGG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IStateManager.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IStateManager.mjs","sourceRoot":"","sources":["../../../src/utils/state/IStateManager.ts"],"names":[],"mappings":"","sourcesContent":["import type { Serializable } from '../serialization/types';\n\nexport type IStateManager<TStateValue extends Record<string, Serializable>> = {\n /**\n * Gets the whole state object.\n *\n * ⚠️ WARNING: Use with caution because it transfers the whole state, which might contain a lot of data.\n * If you need to retrieve only a specific part of the state, use IStateManager.getKey instead.\n */\n get(): Promise<TStateValue>;\n /**\n * Gets the value of the passed key in the state object.\n * The key is the JSON path to the value to get.\n *\n * @returns The value of the key, or undefined if the key does not exist.\n */\n getKey<TResponse extends Serializable>(\n key: string,\n ): Promise<TResponse | undefined>;\n /**\n * Sets the value of the passed key in the state object.\n * The key is a JSON path to the value to set.\n *\n * @param key - The key to set, which is a JSON path to the location.\n * @param value - The value to set.\n */\n setKey(key: string, value: Serializable): Promise<void>;\n /**\n * Atomically reads the current value at `key`, applies `updater`, and writes the result back.\n *\n * Implementations must ensure that no concurrent state write can interleave between the\n * read and the write. This makes the method safe for updates where the next value depends\n * on the current value, such as merging objects.\n *\n * Prefer this over a manual `getKey` + `setKey` sequence whenever the new value depends on\n * the current one.\n *\n * @param key - The JSON-path key to update.\n * @param updater - Receives the current value (or `undefined` when the key is absent) and\n * returns the new value to store.\n */\n setKeyWith<TValue extends Serializable>(\n key: string,\n updater: (currentValue: TValue | undefined) => TValue,\n ): Promise<void>;\n /**\n * Updates the whole state object.\n *\n * Typically used for bulk `set`s or `delete`s, because:\n * - Atomicity: Using a single `state.update` ensures that all changes are applied atomically.\n * - Performance: One round trip instead of many `setKey` / `deleteKey` calls.\n * - State Consistency: Read once, modify in memory, write the complete updated state back.\n *\n * ⚠️ WARNING: Use with caution because:\n * - it will override the whole state.\n * - it transfers the whole state back and forth to the data store.\n *\n * For single updates, use `setKey` or `deleteKey` instead.\n *\n * @param updaterFunction - The function that updates the state.\n * @returns The updated state.\n */\n update(\n updaterFunction: (state: TStateValue) => TStateValue,\n ): Promise<TStateValue>;\n /**\n * Deletes the value of the passed key in the state object.\n * The key is a JSON path to the value to delete.\n */\n deleteKey(key: string): Promise<void>;\n /**\n * Deletes multiple keys in the state object in a single operation.\n * The keys are JSON paths to the values to delete.\n */\n deleteKeys(keys: string[]): Promise<void>;\n};\n"]}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryState = void 0;
4
+ const lodash_1 = require("lodash");
5
+ /**
6
+ * A simple implementation of the `IStateManager` interface that relies on an in-memory
7
+ * state. Intended for tests.
8
+ */
9
+ class InMemoryState {
10
+ #state;
11
+ constructor(initialState) {
12
+ this.#state = initialState;
13
+ }
14
+ async get() {
15
+ return this.#state;
16
+ }
17
+ async getKey(key) {
18
+ return (0, lodash_1.get)(this.#state, key);
19
+ }
20
+ async setKey(key, value) {
21
+ (0, lodash_1.set)(this.#state, key, value);
22
+ }
23
+ async setKeyWith(key, updater) {
24
+ const oldValue = (0, lodash_1.get)(this.#state, key);
25
+ (0, lodash_1.set)(this.#state, key, updater(oldValue));
26
+ }
27
+ async update(callback) {
28
+ this.#state = callback(this.#state);
29
+ return this.#state;
30
+ }
31
+ async deleteKey(key) {
32
+ (0, lodash_1.unset)(this.#state, key);
33
+ }
34
+ async deleteKeys(keys) {
35
+ keys.forEach((key) => {
36
+ (0, lodash_1.unset)(this.#state, key);
37
+ });
38
+ }
39
+ }
40
+ exports.InMemoryState = InMemoryState;
41
+ //# sourceMappingURL=InMemoryState.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryState.cjs","sourceRoot":"","sources":["../../../src/utils/state/InMemoryState.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AAKzC;;;GAGG;AACH,MAAa,aAAa;IAGxB,MAAM,CAAc;IAEpB,YAAY,YAAyB;QACnC,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,GAAG;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,MAAM,CACV,GAAW;QAEX,OAAO,IAAA,YAAG,EAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAA0B,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,KAAmB;QAC3C,IAAA,YAAG,EAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,UAAU,CACd,GAAW,EACX,OAAqD;QAErD,MAAM,QAAQ,GAAG,IAAA,YAAG,EAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAuB,CAAC;QAC7D,IAAA,YAAG,EAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,MAAM,CACV,QAA6C;QAE7C,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAW;QACzB,IAAA,cAAK,EAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAc;QAC7B,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,IAAA,cAAK,EAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA/CD,sCA+CC","sourcesContent":["import { get, set, unset } from 'lodash';\n\nimport type { Serializable } from '../serialization/types';\nimport type { IStateManager } from './IStateManager';\n\n/**\n * A simple implementation of the `IStateManager` interface that relies on an in-memory\n * state. Intended for tests.\n */\nexport class InMemoryState<\n TStateValue extends Record<string, Serializable>,\n> implements IStateManager<TStateValue> {\n #state: TStateValue;\n\n constructor(initialState: TStateValue) {\n this.#state = initialState;\n }\n\n async get(): Promise<TStateValue> {\n return this.#state;\n }\n\n async getKey<TResponse extends Serializable>(\n key: string,\n ): Promise<TResponse | undefined> {\n return get(this.#state, key) as TResponse | undefined;\n }\n\n async setKey(key: string, value: Serializable): Promise<void> {\n set(this.#state, key, value);\n }\n\n async setKeyWith<TValue extends Serializable>(\n key: string,\n updater: (currentValue: TValue | undefined) => TValue,\n ): Promise<void> {\n const oldValue = get(this.#state, key) as TValue | undefined;\n set(this.#state, key, updater(oldValue));\n }\n\n async update(\n callback: (state: TStateValue) => TStateValue,\n ): Promise<TStateValue> {\n this.#state = callback(this.#state);\n return this.#state;\n }\n\n async deleteKey(key: string): Promise<void> {\n unset(this.#state, key);\n }\n\n async deleteKeys(keys: string[]): Promise<void> {\n keys.forEach((key) => {\n unset(this.#state, key);\n });\n }\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import type { Serializable } from "../serialization/types.cjs";
2
+ import type { IStateManager } from "./IStateManager.cjs";
3
+ /**
4
+ * A simple implementation of the `IStateManager` interface that relies on an in-memory
5
+ * state. Intended for tests.
6
+ */
7
+ export declare class InMemoryState<TStateValue extends Record<string, Serializable>> implements IStateManager<TStateValue> {
8
+ #private;
9
+ constructor(initialState: TStateValue);
10
+ get(): Promise<TStateValue>;
11
+ getKey<TResponse extends Serializable>(key: string): Promise<TResponse | undefined>;
12
+ setKey(key: string, value: Serializable): Promise<void>;
13
+ setKeyWith<TValue extends Serializable>(key: string, updater: (currentValue: TValue | undefined) => TValue): Promise<void>;
14
+ update(callback: (state: TStateValue) => TStateValue): Promise<TStateValue>;
15
+ deleteKey(key: string): Promise<void>;
16
+ deleteKeys(keys: string[]): Promise<void>;
17
+ }
18
+ //# sourceMappingURL=InMemoryState.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryState.d.cts","sourceRoot":"","sources":["../../../src/utils/state/InMemoryState.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,mCAA+B;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,4BAAwB;AAErD;;;GAGG;AACH,qBAAa,aAAa,CACxB,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAChD,YAAW,aAAa,CAAC,WAAW,CAAC;;gBAGzB,YAAY,EAAE,WAAW;IAI/B,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC;IAI3B,MAAM,CAAC,SAAS,SAAS,YAAY,EACzC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAI3B,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD,UAAU,CAAC,MAAM,SAAS,YAAY,EAC1C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GACpD,OAAO,CAAC,IAAI,CAAC;IAKV,MAAM,CACV,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,WAAW,GAC5C,OAAO,CAAC,WAAW,CAAC;IAKjB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAKhD"}
@@ -0,0 +1,18 @@
1
+ import type { Serializable } from "../serialization/types.mjs";
2
+ import type { IStateManager } from "./IStateManager.mjs";
3
+ /**
4
+ * A simple implementation of the `IStateManager` interface that relies on an in-memory
5
+ * state. Intended for tests.
6
+ */
7
+ export declare class InMemoryState<TStateValue extends Record<string, Serializable>> implements IStateManager<TStateValue> {
8
+ #private;
9
+ constructor(initialState: TStateValue);
10
+ get(): Promise<TStateValue>;
11
+ getKey<TResponse extends Serializable>(key: string): Promise<TResponse | undefined>;
12
+ setKey(key: string, value: Serializable): Promise<void>;
13
+ setKeyWith<TValue extends Serializable>(key: string, updater: (currentValue: TValue | undefined) => TValue): Promise<void>;
14
+ update(callback: (state: TStateValue) => TStateValue): Promise<TStateValue>;
15
+ deleteKey(key: string): Promise<void>;
16
+ deleteKeys(keys: string[]): Promise<void>;
17
+ }
18
+ //# sourceMappingURL=InMemoryState.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryState.d.mts","sourceRoot":"","sources":["../../../src/utils/state/InMemoryState.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,mCAA+B;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,4BAAwB;AAErD;;;GAGG;AACH,qBAAa,aAAa,CACxB,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAChD,YAAW,aAAa,CAAC,WAAW,CAAC;;gBAGzB,YAAY,EAAE,WAAW;IAI/B,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC;IAI3B,MAAM,CAAC,SAAS,SAAS,YAAY,EACzC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAI3B,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD,UAAU,CAAC,MAAM,SAAS,YAAY,EAC1C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GACpD,OAAO,CAAC,IAAI,CAAC;IAKV,MAAM,CACV,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,WAAW,GAC5C,OAAO,CAAC,WAAW,CAAC;IAKjB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAKhD"}