@waiaas/daemon 2.0.0-rc.1

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 (480) hide show
  1. package/dist/api/error-hints.d.ts +15 -0
  2. package/dist/api/error-hints.d.ts.map +1 -0
  3. package/dist/api/error-hints.js +71 -0
  4. package/dist/api/error-hints.js.map +1 -0
  5. package/dist/api/index.d.ts +11 -0
  6. package/dist/api/index.d.ts.map +1 -0
  7. package/dist/api/index.js +14 -0
  8. package/dist/api/index.js.map +1 -0
  9. package/dist/api/middleware/address-validation.d.ts +38 -0
  10. package/dist/api/middleware/address-validation.d.ts.map +1 -0
  11. package/dist/api/middleware/address-validation.js +134 -0
  12. package/dist/api/middleware/address-validation.js.map +1 -0
  13. package/dist/api/middleware/csp.d.ts +17 -0
  14. package/dist/api/middleware/csp.d.ts.map +1 -0
  15. package/dist/api/middleware/csp.js +31 -0
  16. package/dist/api/middleware/csp.js.map +1 -0
  17. package/dist/api/middleware/error-handler.d.ts +16 -0
  18. package/dist/api/middleware/error-handler.d.ts.map +1 -0
  19. package/dist/api/middleware/error-handler.js +46 -0
  20. package/dist/api/middleware/error-handler.js.map +1 -0
  21. package/dist/api/middleware/host-guard.d.ts +11 -0
  22. package/dist/api/middleware/host-guard.d.ts.map +1 -0
  23. package/dist/api/middleware/host-guard.js +25 -0
  24. package/dist/api/middleware/host-guard.js.map +1 -0
  25. package/dist/api/middleware/index.d.ts +13 -0
  26. package/dist/api/middleware/index.d.ts.map +1 -0
  27. package/dist/api/middleware/index.js +13 -0
  28. package/dist/api/middleware/index.js.map +1 -0
  29. package/dist/api/middleware/kill-switch-guard.d.ts +19 -0
  30. package/dist/api/middleware/kill-switch-guard.d.ts.map +1 -0
  31. package/dist/api/middleware/kill-switch-guard.js +49 -0
  32. package/dist/api/middleware/kill-switch-guard.js.map +1 -0
  33. package/dist/api/middleware/master-auth.d.ts +15 -0
  34. package/dist/api/middleware/master-auth.d.ts.map +1 -0
  35. package/dist/api/middleware/master-auth.js +35 -0
  36. package/dist/api/middleware/master-auth.js.map +1 -0
  37. package/dist/api/middleware/owner-auth.d.ts +30 -0
  38. package/dist/api/middleware/owner-auth.d.ts.map +1 -0
  39. package/dist/api/middleware/owner-auth.js +133 -0
  40. package/dist/api/middleware/owner-auth.js.map +1 -0
  41. package/dist/api/middleware/request-id.d.ts +10 -0
  42. package/dist/api/middleware/request-id.d.ts.map +1 -0
  43. package/dist/api/middleware/request-id.js +18 -0
  44. package/dist/api/middleware/request-id.js.map +1 -0
  45. package/dist/api/middleware/request-logger.d.ts +9 -0
  46. package/dist/api/middleware/request-logger.d.ts.map +1 -0
  47. package/dist/api/middleware/request-logger.js +18 -0
  48. package/dist/api/middleware/request-logger.js.map +1 -0
  49. package/dist/api/middleware/session-auth.d.ts +21 -0
  50. package/dist/api/middleware/session-auth.d.ts.map +1 -0
  51. package/dist/api/middleware/session-auth.js +51 -0
  52. package/dist/api/middleware/session-auth.js.map +1 -0
  53. package/dist/api/middleware/siwe-verify.d.ts +31 -0
  54. package/dist/api/middleware/siwe-verify.d.ts.map +1 -0
  55. package/dist/api/middleware/siwe-verify.js +55 -0
  56. package/dist/api/middleware/siwe-verify.js.map +1 -0
  57. package/dist/api/routes/actions.d.ts +56 -0
  58. package/dist/api/routes/actions.d.ts.map +1 -0
  59. package/dist/api/routes/actions.js +291 -0
  60. package/dist/api/routes/actions.js.map +1 -0
  61. package/dist/api/routes/admin.d.ts +99 -0
  62. package/dist/api/routes/admin.d.ts.map +1 -0
  63. package/dist/api/routes/admin.js +1304 -0
  64. package/dist/api/routes/admin.js.map +1 -0
  65. package/dist/api/routes/display-currency-helper.d.ts +26 -0
  66. package/dist/api/routes/display-currency-helper.d.ts.map +1 -0
  67. package/dist/api/routes/display-currency-helper.js +47 -0
  68. package/dist/api/routes/display-currency-helper.js.map +1 -0
  69. package/dist/api/routes/health.d.ts +14 -0
  70. package/dist/api/routes/health.d.ts.map +1 -0
  71. package/dist/api/routes/health.js +47 -0
  72. package/dist/api/routes/health.js.map +1 -0
  73. package/dist/api/routes/index.d.ts +15 -0
  74. package/dist/api/routes/index.d.ts.map +1 -0
  75. package/dist/api/routes/index.js +15 -0
  76. package/dist/api/routes/index.js.map +1 -0
  77. package/dist/api/routes/mcp.d.ts +30 -0
  78. package/dist/api/routes/mcp.d.ts.map +1 -0
  79. package/dist/api/routes/mcp.js +156 -0
  80. package/dist/api/routes/mcp.js.map +1 -0
  81. package/dist/api/routes/nonce.d.ts +20 -0
  82. package/dist/api/routes/nonce.d.ts.map +1 -0
  83. package/dist/api/routes/nonce.js +48 -0
  84. package/dist/api/routes/nonce.js.map +1 -0
  85. package/dist/api/routes/openapi-schemas.d.ts +2281 -0
  86. package/dist/api/routes/openapi-schemas.d.ts.map +1 -0
  87. package/dist/api/routes/openapi-schemas.js +770 -0
  88. package/dist/api/routes/openapi-schemas.js.map +1 -0
  89. package/dist/api/routes/policies.d.ts +29 -0
  90. package/dist/api/routes/policies.d.ts.map +1 -0
  91. package/dist/api/routes/policies.js +332 -0
  92. package/dist/api/routes/policies.js.map +1 -0
  93. package/dist/api/routes/sessions.d.ts +35 -0
  94. package/dist/api/routes/sessions.d.ts.map +1 -0
  95. package/dist/api/routes/sessions.js +347 -0
  96. package/dist/api/routes/sessions.js.map +1 -0
  97. package/dist/api/routes/skills.d.ts +9 -0
  98. package/dist/api/routes/skills.d.ts.map +1 -0
  99. package/dist/api/routes/skills.js +59 -0
  100. package/dist/api/routes/skills.js.map +1 -0
  101. package/dist/api/routes/tokens.d.ts +25 -0
  102. package/dist/api/routes/tokens.d.ts.map +1 -0
  103. package/dist/api/routes/tokens.js +161 -0
  104. package/dist/api/routes/tokens.js.map +1 -0
  105. package/dist/api/routes/transactions.d.ts +68 -0
  106. package/dist/api/routes/transactions.d.ts.map +1 -0
  107. package/dist/api/routes/transactions.js +576 -0
  108. package/dist/api/routes/transactions.js.map +1 -0
  109. package/dist/api/routes/utils.d.ts +9 -0
  110. package/dist/api/routes/utils.d.ts.map +1 -0
  111. package/dist/api/routes/utils.js +52 -0
  112. package/dist/api/routes/utils.js.map +1 -0
  113. package/dist/api/routes/wallet.d.ts +36 -0
  114. package/dist/api/routes/wallet.d.ts.map +1 -0
  115. package/dist/api/routes/wallet.js +358 -0
  116. package/dist/api/routes/wallet.js.map +1 -0
  117. package/dist/api/routes/wallets.d.ts +43 -0
  118. package/dist/api/routes/wallets.d.ts.map +1 -0
  119. package/dist/api/routes/wallets.js +630 -0
  120. package/dist/api/routes/wallets.js.map +1 -0
  121. package/dist/api/routes/wc.d.ts +46 -0
  122. package/dist/api/routes/wc.d.ts.map +1 -0
  123. package/dist/api/routes/wc.js +354 -0
  124. package/dist/api/routes/wc.js.map +1 -0
  125. package/dist/api/routes/x402.d.ts +61 -0
  126. package/dist/api/routes/x402.d.ts.map +1 -0
  127. package/dist/api/routes/x402.js +493 -0
  128. package/dist/api/routes/x402.js.map +1 -0
  129. package/dist/api/server.d.ts +81 -0
  130. package/dist/api/server.d.ts.map +1 -0
  131. package/dist/api/server.js +406 -0
  132. package/dist/api/server.js.map +1 -0
  133. package/dist/index.d.ts +35 -0
  134. package/dist/index.d.ts.map +1 -0
  135. package/dist/index.js +43 -0
  136. package/dist/index.js.map +1 -0
  137. package/dist/infrastructure/action/action-provider-registry.d.ts +77 -0
  138. package/dist/infrastructure/action/action-provider-registry.d.ts.map +1 -0
  139. package/dist/infrastructure/action/action-provider-registry.js +239 -0
  140. package/dist/infrastructure/action/action-provider-registry.js.map +1 -0
  141. package/dist/infrastructure/action/api-key-store.d.ts +60 -0
  142. package/dist/infrastructure/action/api-key-store.d.ts.map +1 -0
  143. package/dist/infrastructure/action/api-key-store.js +130 -0
  144. package/dist/infrastructure/action/api-key-store.js.map +1 -0
  145. package/dist/infrastructure/action/index.d.ts +10 -0
  146. package/dist/infrastructure/action/index.d.ts.map +1 -0
  147. package/dist/infrastructure/action/index.js +9 -0
  148. package/dist/infrastructure/action/index.js.map +1 -0
  149. package/dist/infrastructure/adapter-pool.d.ts +50 -0
  150. package/dist/infrastructure/adapter-pool.d.ts.map +1 -0
  151. package/dist/infrastructure/adapter-pool.js +110 -0
  152. package/dist/infrastructure/adapter-pool.js.map +1 -0
  153. package/dist/infrastructure/backup/backup-service.d.ts +53 -0
  154. package/dist/infrastructure/backup/backup-service.d.ts.map +1 -0
  155. package/dist/infrastructure/backup/backup-service.js +158 -0
  156. package/dist/infrastructure/backup/backup-service.js.map +1 -0
  157. package/dist/infrastructure/backup/index.d.ts +2 -0
  158. package/dist/infrastructure/backup/index.d.ts.map +1 -0
  159. package/dist/infrastructure/backup/index.js +2 -0
  160. package/dist/infrastructure/backup/index.js.map +1 -0
  161. package/dist/infrastructure/config/index.d.ts +8 -0
  162. package/dist/infrastructure/config/index.d.ts.map +1 -0
  163. package/dist/infrastructure/config/index.js +7 -0
  164. package/dist/infrastructure/config/index.js.map +1 -0
  165. package/dist/infrastructure/config/loader.d.ts +555 -0
  166. package/dist/infrastructure/config/loader.d.ts.map +1 -0
  167. package/dist/infrastructure/config/loader.js +311 -0
  168. package/dist/infrastructure/config/loader.js.map +1 -0
  169. package/dist/infrastructure/database/checks.d.ts +19 -0
  170. package/dist/infrastructure/database/checks.d.ts.map +1 -0
  171. package/dist/infrastructure/database/checks.js +27 -0
  172. package/dist/infrastructure/database/checks.js.map +1 -0
  173. package/dist/infrastructure/database/compatibility.d.ts +36 -0
  174. package/dist/infrastructure/database/compatibility.d.ts.map +1 -0
  175. package/dist/infrastructure/database/compatibility.js +75 -0
  176. package/dist/infrastructure/database/compatibility.js.map +1 -0
  177. package/dist/infrastructure/database/connection.d.ts +36 -0
  178. package/dist/infrastructure/database/connection.d.ts.map +1 -0
  179. package/dist/infrastructure/database/connection.js +47 -0
  180. package/dist/infrastructure/database/connection.js.map +1 -0
  181. package/dist/infrastructure/database/id.d.ts +17 -0
  182. package/dist/infrastructure/database/id.d.ts.map +1 -0
  183. package/dist/infrastructure/database/id.js +20 -0
  184. package/dist/infrastructure/database/id.js.map +1 -0
  185. package/dist/infrastructure/database/index.d.ts +15 -0
  186. package/dist/infrastructure/database/index.d.ts.map +1 -0
  187. package/dist/infrastructure/database/index.js +12 -0
  188. package/dist/infrastructure/database/index.js.map +1 -0
  189. package/dist/infrastructure/database/migrate.d.ts +76 -0
  190. package/dist/infrastructure/database/migrate.d.ts.map +1 -0
  191. package/dist/infrastructure/database/migrate.js +1214 -0
  192. package/dist/infrastructure/database/migrate.js.map +1 -0
  193. package/dist/infrastructure/database/schema.d.ts +2352 -0
  194. package/dist/infrastructure/database/schema.d.ts.map +1 -0
  195. package/dist/infrastructure/database/schema.js +288 -0
  196. package/dist/infrastructure/database/schema.js.map +1 -0
  197. package/dist/infrastructure/jwt/index.d.ts +2 -0
  198. package/dist/infrastructure/jwt/index.d.ts.map +1 -0
  199. package/dist/infrastructure/jwt/index.js +2 -0
  200. package/dist/infrastructure/jwt/index.js.map +1 -0
  201. package/dist/infrastructure/jwt/jwt-secret-manager.d.ts +58 -0
  202. package/dist/infrastructure/jwt/jwt-secret-manager.d.ts.map +1 -0
  203. package/dist/infrastructure/jwt/jwt-secret-manager.js +222 -0
  204. package/dist/infrastructure/jwt/jwt-secret-manager.js.map +1 -0
  205. package/dist/infrastructure/keystore/crypto.d.ts +62 -0
  206. package/dist/infrastructure/keystore/crypto.d.ts.map +1 -0
  207. package/dist/infrastructure/keystore/crypto.js +89 -0
  208. package/dist/infrastructure/keystore/crypto.js.map +1 -0
  209. package/dist/infrastructure/keystore/index.d.ts +4 -0
  210. package/dist/infrastructure/keystore/index.d.ts.map +1 -0
  211. package/dist/infrastructure/keystore/index.js +5 -0
  212. package/dist/infrastructure/keystore/index.js.map +1 -0
  213. package/dist/infrastructure/keystore/keystore.d.ts +115 -0
  214. package/dist/infrastructure/keystore/keystore.d.ts.map +1 -0
  215. package/dist/infrastructure/keystore/keystore.js +327 -0
  216. package/dist/infrastructure/keystore/keystore.js.map +1 -0
  217. package/dist/infrastructure/keystore/memory.d.ts +45 -0
  218. package/dist/infrastructure/keystore/memory.d.ts.map +1 -0
  219. package/dist/infrastructure/keystore/memory.js +105 -0
  220. package/dist/infrastructure/keystore/memory.js.map +1 -0
  221. package/dist/infrastructure/oracle/coingecko-forex.d.ts +35 -0
  222. package/dist/infrastructure/oracle/coingecko-forex.d.ts.map +1 -0
  223. package/dist/infrastructure/oracle/coingecko-forex.js +69 -0
  224. package/dist/infrastructure/oracle/coingecko-forex.js.map +1 -0
  225. package/dist/infrastructure/oracle/coingecko-oracle.d.ts +73 -0
  226. package/dist/infrastructure/oracle/coingecko-oracle.d.ts.map +1 -0
  227. package/dist/infrastructure/oracle/coingecko-oracle.js +199 -0
  228. package/dist/infrastructure/oracle/coingecko-oracle.js.map +1 -0
  229. package/dist/infrastructure/oracle/coingecko-platform-ids.d.ts +32 -0
  230. package/dist/infrastructure/oracle/coingecko-platform-ids.d.ts.map +1 -0
  231. package/dist/infrastructure/oracle/coingecko-platform-ids.js +30 -0
  232. package/dist/infrastructure/oracle/coingecko-platform-ids.js.map +1 -0
  233. package/dist/infrastructure/oracle/forex-currencies.d.ts +36 -0
  234. package/dist/infrastructure/oracle/forex-currencies.d.ts.map +1 -0
  235. package/dist/infrastructure/oracle/forex-currencies.js +71 -0
  236. package/dist/infrastructure/oracle/forex-currencies.js.map +1 -0
  237. package/dist/infrastructure/oracle/forex-rate-service.d.ts +51 -0
  238. package/dist/infrastructure/oracle/forex-rate-service.d.ts.map +1 -0
  239. package/dist/infrastructure/oracle/forex-rate-service.js +149 -0
  240. package/dist/infrastructure/oracle/forex-rate-service.js.map +1 -0
  241. package/dist/infrastructure/oracle/index.d.ts +18 -0
  242. package/dist/infrastructure/oracle/index.d.ts.map +1 -0
  243. package/dist/infrastructure/oracle/index.js +19 -0
  244. package/dist/infrastructure/oracle/index.js.map +1 -0
  245. package/dist/infrastructure/oracle/oracle-chain.d.ts +101 -0
  246. package/dist/infrastructure/oracle/oracle-chain.d.ts.map +1 -0
  247. package/dist/infrastructure/oracle/oracle-chain.js +163 -0
  248. package/dist/infrastructure/oracle/oracle-chain.js.map +1 -0
  249. package/dist/infrastructure/oracle/oracle-errors.d.ts +42 -0
  250. package/dist/infrastructure/oracle/oracle-errors.d.ts.map +1 -0
  251. package/dist/infrastructure/oracle/oracle-errors.js +53 -0
  252. package/dist/infrastructure/oracle/oracle-errors.js.map +1 -0
  253. package/dist/infrastructure/oracle/price-age.d.ts +38 -0
  254. package/dist/infrastructure/oracle/price-age.d.ts.map +1 -0
  255. package/dist/infrastructure/oracle/price-age.js +44 -0
  256. package/dist/infrastructure/oracle/price-age.js.map +1 -0
  257. package/dist/infrastructure/oracle/price-cache.d.ts +99 -0
  258. package/dist/infrastructure/oracle/price-cache.d.ts.map +1 -0
  259. package/dist/infrastructure/oracle/price-cache.js +173 -0
  260. package/dist/infrastructure/oracle/price-cache.js.map +1 -0
  261. package/dist/infrastructure/oracle/pyth-feed-ids.d.ts +31 -0
  262. package/dist/infrastructure/oracle/pyth-feed-ids.d.ts.map +1 -0
  263. package/dist/infrastructure/oracle/pyth-feed-ids.js +44 -0
  264. package/dist/infrastructure/oracle/pyth-feed-ids.js.map +1 -0
  265. package/dist/infrastructure/oracle/pyth-oracle.d.ts +69 -0
  266. package/dist/infrastructure/oracle/pyth-oracle.d.ts.map +1 -0
  267. package/dist/infrastructure/oracle/pyth-oracle.js +149 -0
  268. package/dist/infrastructure/oracle/pyth-oracle.js.map +1 -0
  269. package/dist/infrastructure/settings/hot-reload.d.ts +71 -0
  270. package/dist/infrastructure/settings/hot-reload.d.ts.map +1 -0
  271. package/dist/infrastructure/settings/hot-reload.js +315 -0
  272. package/dist/infrastructure/settings/hot-reload.js.map +1 -0
  273. package/dist/infrastructure/settings/index.d.ts +13 -0
  274. package/dist/infrastructure/settings/index.d.ts.map +1 -0
  275. package/dist/infrastructure/settings/index.js +10 -0
  276. package/dist/infrastructure/settings/index.js.map +1 -0
  277. package/dist/infrastructure/settings/setting-keys.d.ts +28 -0
  278. package/dist/infrastructure/settings/setting-keys.d.ts.map +1 -0
  279. package/dist/infrastructure/settings/setting-keys.js +105 -0
  280. package/dist/infrastructure/settings/setting-keys.js.map +1 -0
  281. package/dist/infrastructure/settings/settings-crypto.d.ts +39 -0
  282. package/dist/infrastructure/settings/settings-crypto.d.ts.map +1 -0
  283. package/dist/infrastructure/settings/settings-crypto.js +73 -0
  284. package/dist/infrastructure/settings/settings-crypto.js.map +1 -0
  285. package/dist/infrastructure/settings/settings-service.d.ts +82 -0
  286. package/dist/infrastructure/settings/settings-service.d.ts.map +1 -0
  287. package/dist/infrastructure/settings/settings-service.js +267 -0
  288. package/dist/infrastructure/settings/settings-service.js.map +1 -0
  289. package/dist/infrastructure/telegram/index.d.ts +6 -0
  290. package/dist/infrastructure/telegram/index.d.ts.map +1 -0
  291. package/dist/infrastructure/telegram/index.js +5 -0
  292. package/dist/infrastructure/telegram/index.js.map +1 -0
  293. package/dist/infrastructure/telegram/telegram-api.d.ts +35 -0
  294. package/dist/infrastructure/telegram/telegram-api.d.ts.map +1 -0
  295. package/dist/infrastructure/telegram/telegram-api.js +82 -0
  296. package/dist/infrastructure/telegram/telegram-api.js.map +1 -0
  297. package/dist/infrastructure/telegram/telegram-auth.d.ts +57 -0
  298. package/dist/infrastructure/telegram/telegram-auth.d.ts.map +1 -0
  299. package/dist/infrastructure/telegram/telegram-auth.js +88 -0
  300. package/dist/infrastructure/telegram/telegram-auth.js.map +1 -0
  301. package/dist/infrastructure/telegram/telegram-bot-service.d.ts +95 -0
  302. package/dist/infrastructure/telegram/telegram-bot-service.d.ts.map +1 -0
  303. package/dist/infrastructure/telegram/telegram-bot-service.js +564 -0
  304. package/dist/infrastructure/telegram/telegram-bot-service.js.map +1 -0
  305. package/dist/infrastructure/telegram/telegram-keyboard.d.ts +27 -0
  306. package/dist/infrastructure/telegram/telegram-keyboard.d.ts.map +1 -0
  307. package/dist/infrastructure/telegram/telegram-keyboard.js +52 -0
  308. package/dist/infrastructure/telegram/telegram-keyboard.js.map +1 -0
  309. package/dist/infrastructure/telegram/telegram-types.d.ts +43 -0
  310. package/dist/infrastructure/telegram/telegram-types.d.ts.map +1 -0
  311. package/dist/infrastructure/telegram/telegram-types.js +8 -0
  312. package/dist/infrastructure/telegram/telegram-types.js.map +1 -0
  313. package/dist/infrastructure/token-registry/builtin-tokens.d.ts +39 -0
  314. package/dist/infrastructure/token-registry/builtin-tokens.d.ts.map +1 -0
  315. package/dist/infrastructure/token-registry/builtin-tokens.js +135 -0
  316. package/dist/infrastructure/token-registry/builtin-tokens.js.map +1 -0
  317. package/dist/infrastructure/token-registry/index.d.ts +8 -0
  318. package/dist/infrastructure/token-registry/index.d.ts.map +1 -0
  319. package/dist/infrastructure/token-registry/index.js +8 -0
  320. package/dist/infrastructure/token-registry/index.js.map +1 -0
  321. package/dist/infrastructure/token-registry/token-registry-service.d.ts +49 -0
  322. package/dist/infrastructure/token-registry/token-registry-service.d.ts.map +1 -0
  323. package/dist/infrastructure/token-registry/token-registry-service.js +93 -0
  324. package/dist/infrastructure/token-registry/token-registry-service.js.map +1 -0
  325. package/dist/infrastructure/version/index.d.ts +5 -0
  326. package/dist/infrastructure/version/index.d.ts.map +1 -0
  327. package/dist/infrastructure/version/index.js +5 -0
  328. package/dist/infrastructure/version/index.js.map +1 -0
  329. package/dist/infrastructure/version/version-check-service.d.ts +35 -0
  330. package/dist/infrastructure/version/version-check-service.d.ts.map +1 -0
  331. package/dist/infrastructure/version/version-check-service.js +92 -0
  332. package/dist/infrastructure/version/version-check-service.js.map +1 -0
  333. package/dist/lifecycle/daemon.d.ts +103 -0
  334. package/dist/lifecycle/daemon.d.ts.map +1 -0
  335. package/dist/lifecycle/daemon.js +934 -0
  336. package/dist/lifecycle/daemon.js.map +1 -0
  337. package/dist/lifecycle/index.d.ts +9 -0
  338. package/dist/lifecycle/index.d.ts.map +1 -0
  339. package/dist/lifecycle/index.js +9 -0
  340. package/dist/lifecycle/index.js.map +1 -0
  341. package/dist/lifecycle/signal-handler.d.ts +18 -0
  342. package/dist/lifecycle/signal-handler.d.ts.map +1 -0
  343. package/dist/lifecycle/signal-handler.js +37 -0
  344. package/dist/lifecycle/signal-handler.js.map +1 -0
  345. package/dist/lifecycle/workers.d.ts +46 -0
  346. package/dist/lifecycle/workers.d.ts.map +1 -0
  347. package/dist/lifecycle/workers.js +101 -0
  348. package/dist/lifecycle/workers.js.map +1 -0
  349. package/dist/notifications/channels/discord.d.ts +10 -0
  350. package/dist/notifications/channels/discord.d.ts.map +1 -0
  351. package/dist/notifications/channels/discord.js +54 -0
  352. package/dist/notifications/channels/discord.js.map +1 -0
  353. package/dist/notifications/channels/ntfy.d.ts +13 -0
  354. package/dist/notifications/channels/ntfy.d.ts.map +1 -0
  355. package/dist/notifications/channels/ntfy.js +58 -0
  356. package/dist/notifications/channels/ntfy.js.map +1 -0
  357. package/dist/notifications/channels/slack.d.ts +10 -0
  358. package/dist/notifications/channels/slack.d.ts.map +1 -0
  359. package/dist/notifications/channels/slack.js +55 -0
  360. package/dist/notifications/channels/slack.js.map +1 -0
  361. package/dist/notifications/channels/telegram.d.ts +10 -0
  362. package/dist/notifications/channels/telegram.d.ts.map +1 -0
  363. package/dist/notifications/channels/telegram.js +40 -0
  364. package/dist/notifications/channels/telegram.js.map +1 -0
  365. package/dist/notifications/index.d.ts +9 -0
  366. package/dist/notifications/index.d.ts.map +1 -0
  367. package/dist/notifications/index.js +7 -0
  368. package/dist/notifications/index.js.map +1 -0
  369. package/dist/notifications/notification-service.d.ts +75 -0
  370. package/dist/notifications/notification-service.d.ts.map +1 -0
  371. package/dist/notifications/notification-service.js +213 -0
  372. package/dist/notifications/notification-service.js.map +1 -0
  373. package/dist/notifications/templates/message-templates.d.ts +12 -0
  374. package/dist/notifications/templates/message-templates.d.ts.map +1 -0
  375. package/dist/notifications/templates/message-templates.js +22 -0
  376. package/dist/notifications/templates/message-templates.js.map +1 -0
  377. package/dist/pipeline/database-policy-engine.d.ts +286 -0
  378. package/dist/pipeline/database-policy-engine.d.ts.map +1 -0
  379. package/dist/pipeline/database-policy-engine.js +992 -0
  380. package/dist/pipeline/database-policy-engine.js.map +1 -0
  381. package/dist/pipeline/default-policy-engine.d.ts +26 -0
  382. package/dist/pipeline/default-policy-engine.d.ts.map +1 -0
  383. package/dist/pipeline/default-policy-engine.js +25 -0
  384. package/dist/pipeline/default-policy-engine.js.map +1 -0
  385. package/dist/pipeline/index.d.ts +9 -0
  386. package/dist/pipeline/index.d.ts.map +1 -0
  387. package/dist/pipeline/index.js +9 -0
  388. package/dist/pipeline/index.js.map +1 -0
  389. package/dist/pipeline/network-resolver.d.ts +22 -0
  390. package/dist/pipeline/network-resolver.d.ts.map +1 -0
  391. package/dist/pipeline/network-resolver.js +32 -0
  392. package/dist/pipeline/network-resolver.js.map +1 -0
  393. package/dist/pipeline/pipeline.d.ts +72 -0
  394. package/dist/pipeline/pipeline.d.ts.map +1 -0
  395. package/dist/pipeline/pipeline.js +87 -0
  396. package/dist/pipeline/pipeline.js.map +1 -0
  397. package/dist/pipeline/resolve-effective-amount-usd.d.ts +41 -0
  398. package/dist/pipeline/resolve-effective-amount-usd.d.ts.map +1 -0
  399. package/dist/pipeline/resolve-effective-amount-usd.js +208 -0
  400. package/dist/pipeline/resolve-effective-amount-usd.js.map +1 -0
  401. package/dist/pipeline/sign-only.d.ts +99 -0
  402. package/dist/pipeline/sign-only.d.ts.map +1 -0
  403. package/dist/pipeline/sign-only.js +267 -0
  404. package/dist/pipeline/sign-only.js.map +1 -0
  405. package/dist/pipeline/sleep.d.ts +6 -0
  406. package/dist/pipeline/sleep.d.ts.map +1 -0
  407. package/dist/pipeline/sleep.js +8 -0
  408. package/dist/pipeline/sleep.js.map +1 -0
  409. package/dist/pipeline/stages.d.ts +82 -0
  410. package/dist/pipeline/stages.d.ts.map +1 -0
  411. package/dist/pipeline/stages.js +784 -0
  412. package/dist/pipeline/stages.js.map +1 -0
  413. package/dist/services/autostop-rules.d.ts +79 -0
  414. package/dist/services/autostop-rules.d.ts.map +1 -0
  415. package/dist/services/autostop-rules.js +174 -0
  416. package/dist/services/autostop-rules.js.map +1 -0
  417. package/dist/services/autostop-service.d.ts +82 -0
  418. package/dist/services/autostop-service.d.ts.map +1 -0
  419. package/dist/services/autostop-service.js +223 -0
  420. package/dist/services/autostop-service.js.map +1 -0
  421. package/dist/services/kill-switch-service.d.ts +118 -0
  422. package/dist/services/kill-switch-service.d.ts.map +1 -0
  423. package/dist/services/kill-switch-service.js +291 -0
  424. package/dist/services/kill-switch-service.js.map +1 -0
  425. package/dist/services/monitoring/balance-monitor-service.d.ts +65 -0
  426. package/dist/services/monitoring/balance-monitor-service.d.ts.map +1 -0
  427. package/dist/services/monitoring/balance-monitor-service.js +207 -0
  428. package/dist/services/monitoring/balance-monitor-service.js.map +1 -0
  429. package/dist/services/wc-session-service.d.ts +123 -0
  430. package/dist/services/wc-session-service.d.ts.map +1 -0
  431. package/dist/services/wc-session-service.js +363 -0
  432. package/dist/services/wc-session-service.js.map +1 -0
  433. package/dist/services/wc-signing-bridge.d.ts +60 -0
  434. package/dist/services/wc-signing-bridge.d.ts.map +1 -0
  435. package/dist/services/wc-signing-bridge.js +334 -0
  436. package/dist/services/wc-signing-bridge.js.map +1 -0
  437. package/dist/services/wc-storage.d.ts +32 -0
  438. package/dist/services/wc-storage.d.ts.map +1 -0
  439. package/dist/services/wc-storage.js +64 -0
  440. package/dist/services/wc-storage.js.map +1 -0
  441. package/dist/services/x402/payment-signer.d.ts +88 -0
  442. package/dist/services/x402/payment-signer.d.ts.map +1 -0
  443. package/dist/services/x402/payment-signer.js +311 -0
  444. package/dist/services/x402/payment-signer.js.map +1 -0
  445. package/dist/services/x402/ssrf-guard.d.ts +27 -0
  446. package/dist/services/x402/ssrf-guard.d.ts.map +1 -0
  447. package/dist/services/x402/ssrf-guard.js +236 -0
  448. package/dist/services/x402/ssrf-guard.js.map +1 -0
  449. package/dist/services/x402/x402-domain-policy.d.ts +50 -0
  450. package/dist/services/x402/x402-domain-policy.d.ts.map +1 -0
  451. package/dist/services/x402/x402-domain-policy.js +78 -0
  452. package/dist/services/x402/x402-domain-policy.js.map +1 -0
  453. package/dist/services/x402/x402-handler.d.ts +71 -0
  454. package/dist/services/x402/x402-handler.d.ts.map +1 -0
  455. package/dist/services/x402/x402-handler.js +195 -0
  456. package/dist/services/x402/x402-handler.js.map +1 -0
  457. package/dist/services/x402/x402-usd-resolver.d.ts +26 -0
  458. package/dist/services/x402/x402-usd-resolver.d.ts.map +1 -0
  459. package/dist/services/x402/x402-usd-resolver.js +79 -0
  460. package/dist/services/x402/x402-usd-resolver.js.map +1 -0
  461. package/dist/workflow/approval-workflow.d.ts +103 -0
  462. package/dist/workflow/approval-workflow.d.ts.map +1 -0
  463. package/dist/workflow/approval-workflow.js +202 -0
  464. package/dist/workflow/approval-workflow.js.map +1 -0
  465. package/dist/workflow/delay-queue.d.ts +78 -0
  466. package/dist/workflow/delay-queue.d.ts.map +1 -0
  467. package/dist/workflow/delay-queue.js +174 -0
  468. package/dist/workflow/delay-queue.js.map +1 -0
  469. package/dist/workflow/index.d.ts +11 -0
  470. package/dist/workflow/index.d.ts.map +1 -0
  471. package/dist/workflow/index.js +9 -0
  472. package/dist/workflow/index.js.map +1 -0
  473. package/dist/workflow/owner-state.d.ts +97 -0
  474. package/dist/workflow/owner-state.d.ts.map +1 -0
  475. package/dist/workflow/owner-state.js +168 -0
  476. package/dist/workflow/owner-state.js.map +1 -0
  477. package/package.json +71 -0
  478. package/public/admin/assets/index-BPoUSH8W.css +1 -0
  479. package/public/admin/assets/index-CDi1qoXB.js +1 -0
  480. package/public/admin/index.html +13 -0
@@ -0,0 +1,9 @@
1
+ export { NotificationService } from './notification-service.js';
2
+ export type { NotificationServiceConfig } from './notification-service.js';
3
+ export { TelegramChannel } from './channels/telegram.js';
4
+ export { DiscordChannel } from './channels/discord.js';
5
+ export { NtfyChannel } from './channels/ntfy.js';
6
+ export { SlackChannel } from './channels/slack.js';
7
+ export { getNotificationMessage } from './templates/message-templates.js';
8
+ export type { NotificationMessage } from './templates/message-templates.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notifications/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,YAAY,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,YAAY,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { NotificationService } from './notification-service.js';
2
+ export { TelegramChannel } from './channels/telegram.js';
3
+ export { DiscordChannel } from './channels/discord.js';
4
+ export { NtfyChannel } from './channels/ntfy.js';
5
+ export { SlackChannel } from './channels/slack.js';
6
+ export { getNotificationMessage } from './templates/message-templates.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/notifications/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * NotificationService orchestrator: priority-based delivery with fallback,
3
+ * broadcast mode for critical events, per-channel rate limiting, and
4
+ * CRITICAL audit_log on total failure.
5
+ *
6
+ * @see docs/35-notification-architecture.md
7
+ */
8
+ import type { INotificationChannel } from '@waiaas/core';
9
+ import type { NotificationEventType, SupportedLocale } from '@waiaas/core';
10
+ import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
11
+ import * as schema from '../infrastructure/database/schema.js';
12
+ export interface NotificationServiceConfig {
13
+ locale: SupportedLocale;
14
+ rateLimitRpm: number;
15
+ }
16
+ export declare class NotificationService {
17
+ private channels;
18
+ private db;
19
+ private config;
20
+ private rateLimitMap;
21
+ constructor(opts?: {
22
+ db?: BetterSQLite3Database<typeof schema>;
23
+ config?: Partial<NotificationServiceConfig>;
24
+ });
25
+ /** Add initialized channel to the service. */
26
+ addChannel(channel: INotificationChannel): void;
27
+ /** Get list of configured channel names. */
28
+ getChannelNames(): string[];
29
+ /** Get list of configured channels (for admin test send). */
30
+ getChannels(): INotificationChannel[];
31
+ /**
32
+ * Replace all notification channels with new instances.
33
+ * Used by hot-reload when notification credentials change.
34
+ * Old channels are discarded (no cleanup needed -- they're stateless HTTP clients).
35
+ */
36
+ replaceChannels(newChannels: INotificationChannel[]): void;
37
+ /**
38
+ * Update config (locale, rateLimitRpm) without replacing channels.
39
+ */
40
+ updateConfig(config: Partial<NotificationServiceConfig>): void;
41
+ /**
42
+ * Send notification via priority-based delivery with fallback.
43
+ * Tries channels in order; on failure, falls back to next channel.
44
+ * For broadcast events, sends to ALL channels.
45
+ */
46
+ notify(eventType: NotificationEventType, walletId: string, vars?: Record<string, string>, details?: Record<string, unknown>): Promise<void>;
47
+ /**
48
+ * Send to ALL channels simultaneously (for critical events).
49
+ * If ALL channels fail, logs CRITICAL to audit_log.
50
+ */
51
+ private broadcast;
52
+ /**
53
+ * Priority-based fallback: try channels in order, stop on first success.
54
+ * If all fail, log CRITICAL to audit_log.
55
+ */
56
+ private sendWithFallback;
57
+ /**
58
+ * Send to a single channel with rate limit check.
59
+ */
60
+ private sendToChannel;
61
+ /** Check if channel is rate limited (sliding window). */
62
+ private isRateLimited;
63
+ /** Record a successful send for rate limiting. */
64
+ private recordSend;
65
+ /**
66
+ * Record notification delivery result to notification_logs table.
67
+ * Fire-and-forget: errors are swallowed to never block the pipeline.
68
+ */
69
+ private logDelivery;
70
+ /**
71
+ * Log CRITICAL failure to audit_log when all channels fail.
72
+ */
73
+ private logCriticalFailure;
74
+ }
75
+ //# sourceMappingURL=notification-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification-service.d.ts","sourceRoot":"","sources":["../../src/notifications/notification-service.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAuB,MAAM,cAAc,CAAC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,MAAM,MAAM,sCAAsC,CAAC;AAU/D,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,eAAe,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,EAAE,CAAqD;IAC/D,OAAO,CAAC,MAAM,CAAiE;IAG/E,OAAO,CAAC,YAAY,CAA+B;gBAEvC,IAAI,CAAC,EAAE;QACjB,EAAE,CAAC,EAAE,qBAAqB,CAAC,OAAO,MAAM,CAAC,CAAC;QAC1C,MAAM,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;KAC7C;IAKD,8CAA8C;IAC9C,UAAU,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI;IAI/C,4CAA4C;IAC5C,eAAe,IAAI,MAAM,EAAE;IAI3B,6DAA6D;IAC7D,WAAW,IAAI,oBAAoB,EAAE;IAIrC;;;;OAIG;IACH,eAAe,CAAC,WAAW,EAAE,oBAAoB,EAAE,GAAG,IAAI;IAM1D;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,IAAI;IAI9D;;;;OAIG;IACG,MAAM,CACV,SAAS,EAAE,qBAAqB,EAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAmBhB;;;OAGG;YACW,SAAS;IAmBvB;;;OAGG;YACW,gBAAgB;IAgB9B;;OAEG;YACW,aAAa;IAa3B,yDAAyD;IACzD,OAAO,CAAC,aAAa;IAUrB,kDAAkD;IAClD,OAAO,CAAC,UAAU;IAMlB;;;OAGG;IACH,OAAO,CAAC,WAAW;IA2BnB;;OAEG;YACW,kBAAkB;CAuCjC"}
@@ -0,0 +1,213 @@
1
+ /**
2
+ * NotificationService orchestrator: priority-based delivery with fallback,
3
+ * broadcast mode for critical events, per-channel rate limiting, and
4
+ * CRITICAL audit_log on total failure.
5
+ *
6
+ * @see docs/35-notification-architecture.md
7
+ */
8
+ import { getNotificationMessage } from './templates/message-templates.js';
9
+ import * as schema from '../infrastructure/database/schema.js';
10
+ import { generateId } from '../infrastructure/database/id.js';
11
+ // Broadcast event types -- sent to ALL channels simultaneously
12
+ const BROADCAST_EVENTS = new Set([
13
+ 'KILL_SWITCH_ACTIVATED',
14
+ 'KILL_SWITCH_RECOVERED',
15
+ 'AUTO_STOP_TRIGGERED',
16
+ ]);
17
+ export class NotificationService {
18
+ channels = [];
19
+ db = null;
20
+ config = { locale: 'en', rateLimitRpm: 20 };
21
+ // Rate limiter: Map<channelName, timestamps[]>
22
+ rateLimitMap = new Map();
23
+ constructor(opts) {
24
+ if (opts?.db)
25
+ this.db = opts.db;
26
+ if (opts?.config)
27
+ this.config = { ...this.config, ...opts.config };
28
+ }
29
+ /** Add initialized channel to the service. */
30
+ addChannel(channel) {
31
+ this.channels.push(channel);
32
+ }
33
+ /** Get list of configured channel names. */
34
+ getChannelNames() {
35
+ return this.channels.map((c) => c.name);
36
+ }
37
+ /** Get list of configured channels (for admin test send). */
38
+ getChannels() {
39
+ return [...this.channels];
40
+ }
41
+ /**
42
+ * Replace all notification channels with new instances.
43
+ * Used by hot-reload when notification credentials change.
44
+ * Old channels are discarded (no cleanup needed -- they're stateless HTTP clients).
45
+ */
46
+ replaceChannels(newChannels) {
47
+ this.channels = [...newChannels];
48
+ // Reset rate limiter for all channels (fresh start with new credentials)
49
+ this.rateLimitMap.clear();
50
+ }
51
+ /**
52
+ * Update config (locale, rateLimitRpm) without replacing channels.
53
+ */
54
+ updateConfig(config) {
55
+ this.config = { ...this.config, ...config };
56
+ }
57
+ /**
58
+ * Send notification via priority-based delivery with fallback.
59
+ * Tries channels in order; on failure, falls back to next channel.
60
+ * For broadcast events, sends to ALL channels.
61
+ */
62
+ async notify(eventType, walletId, vars, details) {
63
+ if (this.channels.length === 0)
64
+ return; // No channels configured
65
+ const { title, body } = getNotificationMessage(eventType, this.config.locale, vars);
66
+ const payload = {
67
+ eventType,
68
+ walletId,
69
+ message: `${title}\n${body}`,
70
+ details,
71
+ timestamp: Math.floor(Date.now() / 1000),
72
+ };
73
+ if (BROADCAST_EVENTS.has(eventType)) {
74
+ await this.broadcast(payload);
75
+ }
76
+ else {
77
+ await this.sendWithFallback(payload);
78
+ }
79
+ }
80
+ /**
81
+ * Send to ALL channels simultaneously (for critical events).
82
+ * If ALL channels fail, logs CRITICAL to audit_log.
83
+ */
84
+ async broadcast(payload) {
85
+ const results = await Promise.allSettled(this.channels.map(async (ch) => {
86
+ try {
87
+ await this.sendToChannel(ch, payload);
88
+ }
89
+ catch (err) {
90
+ const errorMsg = err instanceof Error ? err.message : String(err);
91
+ this.logDelivery(ch.name, payload, 'failed', errorMsg);
92
+ throw err; // re-throw so allSettled records rejection
93
+ }
94
+ }));
95
+ const allFailed = results.every((r) => r.status === 'rejected');
96
+ if (allFailed) {
97
+ await this.logCriticalFailure(payload, results);
98
+ }
99
+ }
100
+ /**
101
+ * Priority-based fallback: try channels in order, stop on first success.
102
+ * If all fail, log CRITICAL to audit_log.
103
+ */
104
+ async sendWithFallback(payload) {
105
+ for (const channel of this.channels) {
106
+ try {
107
+ await this.sendToChannel(channel, payload);
108
+ return; // Success -- stop trying
109
+ }
110
+ catch (err) {
111
+ // Log failed delivery attempt
112
+ const errorMsg = err instanceof Error ? err.message : String(err);
113
+ this.logDelivery(channel.name, payload, 'failed', errorMsg);
114
+ continue;
115
+ }
116
+ }
117
+ // All channels failed
118
+ await this.logCriticalFailure(payload);
119
+ }
120
+ /**
121
+ * Send to a single channel with rate limit check.
122
+ */
123
+ async sendToChannel(channel, payload) {
124
+ if (this.isRateLimited(channel.name)) {
125
+ throw new Error(`Rate limited: ${channel.name}`);
126
+ }
127
+ await channel.send(payload);
128
+ this.recordSend(channel.name);
129
+ // Log successful delivery
130
+ this.logDelivery(channel.name, payload, 'sent');
131
+ }
132
+ /** Check if channel is rate limited (sliding window). */
133
+ isRateLimited(channelName) {
134
+ const now = Date.now();
135
+ const windowMs = 60_000; // 1 minute
136
+ const timestamps = this.rateLimitMap.get(channelName) ?? [];
137
+ // Remove entries older than window
138
+ const recent = timestamps.filter((t) => now - t < windowMs);
139
+ this.rateLimitMap.set(channelName, recent);
140
+ return recent.length >= this.config.rateLimitRpm;
141
+ }
142
+ /** Record a successful send for rate limiting. */
143
+ recordSend(channelName) {
144
+ const timestamps = this.rateLimitMap.get(channelName) ?? [];
145
+ timestamps.push(Date.now());
146
+ this.rateLimitMap.set(channelName, timestamps);
147
+ }
148
+ /**
149
+ * Record notification delivery result to notification_logs table.
150
+ * Fire-and-forget: errors are swallowed to never block the pipeline.
151
+ */
152
+ logDelivery(channelName, payload, status, error) {
153
+ if (!this.db)
154
+ return;
155
+ try {
156
+ this.db
157
+ .insert(schema.notificationLogs)
158
+ .values({
159
+ id: generateId(),
160
+ eventType: payload.eventType,
161
+ walletId: payload.walletId,
162
+ channel: channelName,
163
+ status,
164
+ error: error ?? null,
165
+ message: payload.message ?? null,
166
+ createdAt: new Date(payload.timestamp * 1000),
167
+ })
168
+ .run();
169
+ }
170
+ catch {
171
+ // Fire-and-forget: swallow DB errors to never block notification flow
172
+ }
173
+ }
174
+ /**
175
+ * Log CRITICAL failure to audit_log when all channels fail.
176
+ */
177
+ async logCriticalFailure(payload, results) {
178
+ if (!this.db) {
179
+ console.error('CRITICAL: All notification channels failed, no DB for audit log', {
180
+ eventType: payload.eventType,
181
+ walletId: payload.walletId,
182
+ });
183
+ return;
184
+ }
185
+ try {
186
+ const errorDetails = results
187
+ ? results
188
+ .filter((r) => r.status === 'rejected')
189
+ .map((r) => String(r.reason))
190
+ .join('; ')
191
+ : 'All channels failed';
192
+ this.db
193
+ .insert(schema.auditLog)
194
+ .values({
195
+ timestamp: new Date(payload.timestamp * 1000),
196
+ eventType: 'NOTIFICATION_TOTAL_FAILURE',
197
+ actor: 'system',
198
+ walletId: payload.walletId,
199
+ details: JSON.stringify({
200
+ originalEvent: payload.eventType,
201
+ message: payload.message,
202
+ errors: errorDetails,
203
+ }),
204
+ severity: 'critical',
205
+ })
206
+ .run();
207
+ }
208
+ catch (err) {
209
+ console.error('CRITICAL: Failed to write audit log for notification failure', err);
210
+ }
211
+ }
212
+ }
213
+ //# sourceMappingURL=notification-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification-service.js","sourceRoot":"","sources":["../../src/notifications/notification-service.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,MAAM,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAE9D,+DAA+D;AAC/D,MAAM,gBAAgB,GAAgB,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E,OAAO,CAAC,QAAQ;gBAC1B,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;oBACtB,aAAa,EAAE,OAAO,CAAC,SAAS;oBAChC,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,MAAM,EAAE,YAAY;iBACrB,CAAC;gBACF,QAAQ,EAAE,UAAU;aACrB,CAAC;iBACD,GAAG,EAAE,CAAC;QACX,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,8DAA8D,EAAE,GAAG,CAAC,CAAC;QACrF,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import type { NotificationEventType } from '@waiaas/core';
2
+ import { type SupportedLocale } from '@waiaas/core';
3
+ export interface NotificationMessage {
4
+ title: string;
5
+ body: string;
6
+ }
7
+ /**
8
+ * Get a notification message for a given event type and locale,
9
+ * with template variables interpolated.
10
+ */
11
+ export declare function getNotificationMessage(eventType: NotificationEventType, locale: SupportedLocale, vars?: Record<string, string>): NotificationMessage;
12
+ //# sourceMappingURL=message-templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-templates.d.ts","sourceRoot":"","sources":["../../../src/notifications/templates/message-templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,qBAAqB,EAChC,MAAM,EAAE,eAAe,EACvB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,mBAAmB,CAkBrB"}
@@ -0,0 +1,22 @@
1
+ import { getMessages } from '@waiaas/core';
2
+ /**
3
+ * Get a notification message for a given event type and locale,
4
+ * with template variables interpolated.
5
+ */
6
+ export function getNotificationMessage(eventType, locale, vars) {
7
+ const messages = getMessages(locale);
8
+ const template = messages.notifications[eventType];
9
+ let { title, body } = template;
10
+ // Interpolate {variable} placeholders
11
+ if (vars) {
12
+ for (const [key, value] of Object.entries(vars)) {
13
+ title = title.replaceAll(`{${key}}`, value);
14
+ body = body.replaceAll(`{${key}}`, value);
15
+ }
16
+ }
17
+ // Remove un-substituted {display_amount} placeholder (optional variable)
18
+ title = title.replaceAll('{display_amount}', '');
19
+ body = body.replaceAll('{display_amount}', '');
20
+ return { title: title.trim(), body: body.trim() };
21
+ }
22
+ //# sourceMappingURL=message-templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-templates.js","sourceRoot":"","sources":["../../../src/notifications/templates/message-templates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAwB,MAAM,cAAc,CAAC;AAOjE;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,SAAgC,EAChC,MAAuB,EACvB,IAA6B;IAE7B,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACnD,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;IAE/B,sCAAsC;IACtC,IAAI,IAAI,EAAE,CAAC;QACT,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;YAC5C,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED,yEAAyE;IACzE,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;IACjD,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;IAE/C,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;AACpD,CAAC"}
@@ -0,0 +1,286 @@
1
+ /**
2
+ * DatabasePolicyEngine - v1.2 DB-backed policy engine with network scoping.
3
+ *
4
+ * Evaluates transactions against policies stored in the policies table.
5
+ * Supports SPENDING_LIMIT (4-tier classification), WHITELIST (address filtering),
6
+ * ALLOWED_NETWORKS (network whitelist, permissive default),
7
+ * ALLOWED_TOKENS (token transfer whitelist, default deny),
8
+ * CONTRACT_WHITELIST (contract call whitelist, default deny),
9
+ * METHOD_WHITELIST (optional method-level restriction for contract calls),
10
+ * APPROVED_SPENDERS (approve spender whitelist, default deny),
11
+ * APPROVE_AMOUNT_LIMIT (unlimited approve block + amount cap),
12
+ * and APPROVE_TIER_OVERRIDE (forced tier for APPROVE transactions).
13
+ *
14
+ * Algorithm:
15
+ * 1. Load enabled policies for wallet (wallet-specific + global), ORDER BY priority DESC
16
+ * 2. If no policies found, return INSTANT passthrough (Phase 7 compat)
17
+ * 3. Resolve overrides: 4-level priority (wallet+network > wallet+null > global+network > global+null)
18
+ * 4. Evaluate WHITELIST: deny if toAddress not in allowed_addresses
19
+ * 4a.5. Evaluate ALLOWED_NETWORKS: deny if network not in allowed list (permissive default)
20
+ * 4b. Evaluate ALLOWED_TOKENS: deny TOKEN_TRANSFER if no policy or token not whitelisted
21
+ * 4c. Evaluate CONTRACT_WHITELIST: deny CONTRACT_CALL if no policy or contract not whitelisted
22
+ * 4d. Evaluate METHOD_WHITELIST: deny CONTRACT_CALL if method selector not whitelisted (optional)
23
+ * 4e. Evaluate APPROVED_SPENDERS: deny APPROVE if no policy or spender not approved
24
+ * 4f. Evaluate APPROVE_AMOUNT_LIMIT: deny APPROVE if unlimited or exceeds max amount
25
+ * 4g. Evaluate APPROVE_TIER_OVERRIDE: force tier for APPROVE (defaults to APPROVAL, skips SPENDING_LIMIT)
26
+ * 5. Evaluate SPENDING_LIMIT: classify amount into INSTANT/NOTIFY/DELAY/APPROVAL
27
+ *
28
+ * TOCTOU Prevention (evaluateAndReserve):
29
+ * Uses BEGIN IMMEDIATE to serialize concurrent policy evaluations.
30
+ * reserved_amount tracks pending amounts to prevent two requests from both passing
31
+ * under the same spending limit.
32
+ *
33
+ * @see docs/33-time-lock-approval-mechanism.md
34
+ * @see docs/71-policy-engine-network-extension-design.md
35
+ */
36
+ import type { IPolicyEngine, PolicyEvaluation } from '@waiaas/core';
37
+ import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
38
+ import type { Database as SQLiteDatabase } from 'better-sqlite3';
39
+ import type * as schema from '../infrastructure/database/schema.js';
40
+ import type { SettingsService } from '../infrastructure/settings/settings-service.js';
41
+ /** Transaction parameter for policy evaluation. */
42
+ interface TransactionParam {
43
+ type: string;
44
+ amount: string;
45
+ toAddress: string;
46
+ chain: string;
47
+ /** Resolved network for ALLOWED_NETWORKS evaluation + network scoping. */
48
+ network?: string;
49
+ /** Token address for ALLOWED_TOKENS evaluation (TOKEN_TRANSFER only). */
50
+ tokenAddress?: string;
51
+ /** Contract address for CONTRACT_WHITELIST evaluation (CONTRACT_CALL only). */
52
+ contractAddress?: string;
53
+ /** Function selector (4-byte hex, e.g. '0x12345678') for METHOD_WHITELIST evaluation (CONTRACT_CALL only). */
54
+ selector?: string;
55
+ /** Spender address for APPROVED_SPENDERS evaluation (APPROVE only). */
56
+ spenderAddress?: string;
57
+ /** Approve amount in raw units for APPROVE_AMOUNT_LIMIT evaluation (APPROVE only). */
58
+ approveAmount?: string;
59
+ }
60
+ /**
61
+ * DB-backed policy engine with SPENDING_LIMIT 4-tier, WHITELIST, ALLOWED_NETWORKS,
62
+ * ALLOWED_TOKENS, CONTRACT_WHITELIST, METHOD_WHITELIST, APPROVED_SPENDERS,
63
+ * APPROVE_AMOUNT_LIMIT, and APPROVE_TIER_OVERRIDE evaluation.
64
+ *
65
+ * Network scoping: policies can target specific networks via the `network` column.
66
+ * 4-level override priority: wallet+network > wallet+null > global+network > global+null.
67
+ *
68
+ * Constructor takes a Drizzle DB instance typed with the full schema,
69
+ * and optionally a raw better-sqlite3 Database instance for BEGIN IMMEDIATE transactions.
70
+ */
71
+ export declare class DatabasePolicyEngine implements IPolicyEngine {
72
+ private readonly db;
73
+ private readonly sqlite;
74
+ private readonly settingsService;
75
+ constructor(db: BetterSQLite3Database<typeof schema>, sqlite?: SQLiteDatabase, settingsService?: SettingsService);
76
+ /**
77
+ * Evaluate a transaction against DB-stored policies.
78
+ */
79
+ evaluate(walletId: string, transaction: TransactionParam): Promise<PolicyEvaluation>;
80
+ /**
81
+ * Evaluate a batch of instructions using 2-stage policy evaluation.
82
+ *
83
+ * Phase A: Evaluate each instruction individually against its applicable policies.
84
+ * All-or-Nothing: if any instruction is denied, entire batch is denied.
85
+ *
86
+ * Phase B: Sum native amounts (TRANSFER.amount) and evaluate
87
+ * aggregate against SPENDING_LIMIT. If batch contains APPROVE, apply
88
+ * APPROVE_TIER_OVERRIDE and take max(amount tier, approve tier).
89
+ *
90
+ * @param walletId - Wallet whose policies to evaluate
91
+ * @param instructions - Array of instruction parameters (same shape as TransactionParam)
92
+ * @returns PolicyEvaluation with final tier or denial with violation details
93
+ */
94
+ evaluateBatch(walletId: string, instructions: TransactionParam[], batchUsdAmount?: number): Promise<PolicyEvaluation>;
95
+ /**
96
+ * Evaluate applicable policies for a single instruction in a batch.
97
+ *
98
+ * Only evaluates type-specific policies:
99
+ * - TRANSFER: WHITELIST
100
+ * - TOKEN_TRANSFER: WHITELIST + ALLOWED_TOKENS
101
+ * - CONTRACT_CALL: CONTRACT_WHITELIST + METHOD_WHITELIST
102
+ * - APPROVE: APPROVED_SPENDERS + APPROVE_AMOUNT_LIMIT
103
+ *
104
+ * Does NOT evaluate SPENDING_LIMIT (that's Phase B aggregate) or
105
+ * APPROVE_TIER_OVERRIDE (that's Phase B).
106
+ *
107
+ * Returns null if all policies pass, PolicyEvaluation with allowed=false if denied.
108
+ */
109
+ private evaluateInstructionPolicies;
110
+ /**
111
+ * Evaluate transaction and reserve amount atomically using BEGIN IMMEDIATE.
112
+ *
113
+ * This method:
114
+ * 1. Begins an IMMEDIATE transaction (exclusive write lock)
115
+ * 2. Loads policies (same as evaluate)
116
+ * 3. For SPENDING_LIMIT: computes current reserved total from PENDING/QUEUED txs
117
+ * 4. Adds current request amount to reserved total
118
+ * 5. Evaluates against limits with reserved total considered
119
+ * 6. If allowed: sets reserved_amount on the transaction row
120
+ * 7. Commits
121
+ *
122
+ * @param walletId - The wallet whose policies to evaluate
123
+ * @param transaction - Transaction details for evaluation
124
+ * @param txId - The transaction ID to update with reserved_amount
125
+ * @returns PolicyEvaluation result
126
+ * @throws Error if sqlite instance not provided in constructor
127
+ */
128
+ evaluateAndReserve(walletId: string, transaction: TransactionParam, txId: string, usdAmount?: number): PolicyEvaluation;
129
+ /**
130
+ * Release a reserved amount on a transaction.
131
+ * Called when transaction reaches FAILED/CANCELLED/EXPIRED state.
132
+ *
133
+ * @param txId - The transaction ID to clear reservation for
134
+ */
135
+ releaseReservation(txId: string): void;
136
+ /**
137
+ * Get cumulative USD spent by wallet within a time window.
138
+ * Includes both confirmed amounts (amount_usd) and pending reservations (reserved_amount_usd).
139
+ *
140
+ * CONFIRMED/SIGNED: counted via amount_usd (confirmed or about to be broadcasted).
141
+ * PENDING/QUEUED: counted via reserved_amount_usd (awaiting processing, not yet confirmed).
142
+ * Deduplication: SIGNED is in the first query only (amount_usd). PENDING/QUEUED in second only.
143
+ */
144
+ private getCumulativeUsdSpent;
145
+ /**
146
+ * Resolve policy overrides with 4-level priority:
147
+ * 1. wallet-specific + network-specific (highest)
148
+ * 2. wallet-specific + all-networks
149
+ * 3. global + network-specific
150
+ * 4. global + all-networks (lowest)
151
+ *
152
+ * For each policy type, one policy is selected.
153
+ * Lower priority entries are inserted first, higher priority entries overwrite.
154
+ * Key: typeMap[row.type] (same as current -- no composite key needed, PLCY-D03).
155
+ *
156
+ * Backward compat: when all policies have network=NULL,
157
+ * phases 2+4 collapse into current 2-level (wallet > global) behavior.
158
+ */
159
+ private resolveOverrides;
160
+ /**
161
+ * Evaluate ALLOWED_NETWORKS policy.
162
+ *
163
+ * Logic:
164
+ * - Applies to ALL 5 transaction types (TRANSFER, TOKEN_TRANSFER, CONTRACT_CALL, APPROVE, BATCH)
165
+ * - If no ALLOWED_NETWORKS policy exists: return null (permissive default -- all networks allowed)
166
+ * - If policy exists: check if resolvedNetwork is in rules.networks[].network
167
+ * -> If found: return null (continue to next evaluation)
168
+ * -> If not found: deny with reason 'Network not in allowed list'
169
+ * - Comparison: case-insensitive (toLowerCase)
170
+ * - Tier: INSTANT (immediate denial)
171
+ *
172
+ * Returns PolicyEvaluation if denied, null if allowed (or no policy).
173
+ */
174
+ private evaluateAllowedNetworks;
175
+ /**
176
+ * Evaluate WHITELIST policy.
177
+ * Returns PolicyEvaluation if denied, null if allowed (or no whitelist).
178
+ */
179
+ private evaluateWhitelist;
180
+ /**
181
+ * Evaluate ALLOWED_TOKENS policy.
182
+ *
183
+ * Logic:
184
+ * - Only applies to TOKEN_TRANSFER transaction type
185
+ * - If transaction type is TOKEN_TRANSFER and no ALLOWED_TOKENS policy exists:
186
+ * -> deny with reason 'Token transfer not allowed: no ALLOWED_TOKENS policy configured'
187
+ * - If ALLOWED_TOKENS policy exists, check if transaction's token address is in rules.tokens[].address:
188
+ * -> If found: return null (continue to next evaluation)
189
+ * -> If not found: deny with reason 'Token not in allowed list: {tokenAddress}'
190
+ * - For non-TOKEN_TRANSFER types: return null (not applicable)
191
+ *
192
+ * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
193
+ */
194
+ private evaluateAllowedTokens;
195
+ /**
196
+ * Evaluate CONTRACT_WHITELIST policy.
197
+ *
198
+ * Logic:
199
+ * - Only applies to CONTRACT_CALL transaction type
200
+ * - If transaction type is CONTRACT_CALL and no CONTRACT_WHITELIST policy exists:
201
+ * -> deny with reason 'Contract calls disabled: no CONTRACT_WHITELIST policy configured'
202
+ * - If CONTRACT_WHITELIST policy exists, check if contract address is in rules.contracts[].address:
203
+ * -> If found: return null (continue to next evaluation)
204
+ * -> If not found: deny with reason 'Contract not whitelisted: {address}'
205
+ * - For non-CONTRACT_CALL types: return null (not applicable)
206
+ *
207
+ * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
208
+ */
209
+ private evaluateContractWhitelist;
210
+ /**
211
+ * Evaluate METHOD_WHITELIST policy.
212
+ *
213
+ * Logic:
214
+ * - Only applies to CONTRACT_CALL transaction type
215
+ * - If no METHOD_WHITELIST policy exists: return null (method restriction is optional)
216
+ * - If METHOD_WHITELIST policy exists, find matching entry for transaction's contract address:
217
+ * -> If no entry for this contract: return null (no method restriction for this contract)
218
+ * -> If entry found, check if transaction's selector is in entry.selectors:
219
+ * -> If found: return null (method allowed)
220
+ * -> If not found: deny with reason 'Method not whitelisted: {selector} on contract {address}'
221
+ *
222
+ * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
223
+ */
224
+ private evaluateMethodWhitelist;
225
+ /**
226
+ * Evaluate APPROVED_SPENDERS policy.
227
+ *
228
+ * Logic:
229
+ * - Only applies to APPROVE transaction type
230
+ * - If transaction type is APPROVE and no APPROVED_SPENDERS policy exists:
231
+ * -> deny with reason 'Token approvals disabled: no APPROVED_SPENDERS policy configured'
232
+ * - If APPROVED_SPENDERS policy exists, check if transaction's spenderAddress is in rules.spenders[]:
233
+ * -> If found: return null (continue evaluation)
234
+ * -> If not found: deny with reason 'Spender not in approved list: {address}'
235
+ * - Case-insensitive comparison (EVM addresses)
236
+ *
237
+ * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
238
+ */
239
+ private evaluateApprovedSpenders;
240
+ /**
241
+ * Evaluate APPROVE_AMOUNT_LIMIT policy.
242
+ *
243
+ * Logic:
244
+ * - Only applies to APPROVE transaction type
245
+ * - Checks for unlimited approve amounts (>= UNLIMITED_THRESHOLD)
246
+ * - Checks for amount cap (maxAmount)
247
+ * - If no policy exists: default block_unlimited=true (block unlimited approvals)
248
+ *
249
+ * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
250
+ */
251
+ private evaluateApproveAmountLimit;
252
+ /**
253
+ * Evaluate APPROVE_TIER_OVERRIDE policy.
254
+ *
255
+ * Logic:
256
+ * - Only applies to APPROVE transaction type
257
+ * - If no APPROVE_TIER_OVERRIDE policy exists: return APPROVAL tier (default: Owner approval required)
258
+ * - If policy exists: return configured tier
259
+ * - This is a FINAL result -- skips SPENDING_LIMIT entirely for APPROVE transactions
260
+ *
261
+ * Returns PolicyEvaluation (always returns result for APPROVE type, null for others).
262
+ */
263
+ private evaluateApproveTierOverride;
264
+ /**
265
+ * Evaluate SPENDING_LIMIT policy.
266
+ * Returns PolicyEvaluation with tier classification, or null if no spending limit.
267
+ *
268
+ * Phase 127: usdAmount가 전달되고 rules에 USD 임계값이 설정되어 있으면,
269
+ * 네이티브 티어와 USD 티어 중 더 보수적인(높은) 티어를 채택한다.
270
+ */
271
+ private evaluateSpendingLimit;
272
+ /**
273
+ * Evaluate native amount tier (extracted from evaluateSpendingLimit).
274
+ */
275
+ private evaluateNativeTier;
276
+ /**
277
+ * Check if rules have any USD thresholds configured.
278
+ */
279
+ private hasUsdThresholds;
280
+ /**
281
+ * Evaluate USD amount tier.
282
+ */
283
+ private evaluateUsdTier;
284
+ }
285
+ export {};
286
+ //# sourceMappingURL=database-policy-engine.d.ts.map