@rfc0/patty 0.0.0-stage → 1.0.2

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 (465) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +214 -2
  3. package/dist/adapters/access-tokens.js +7 -0
  4. package/dist/adapters/accounts.js +37 -0
  5. package/dist/adapters/auth.js +11 -0
  6. package/dist/adapters/bills.js +32 -0
  7. package/dist/adapters/budgets.js +29 -0
  8. package/dist/adapters/categories.js +32 -0
  9. package/dist/adapters/client-grants.js +7 -0
  10. package/dist/adapters/credit-cards.js +33 -0
  11. package/dist/adapters/currencies.js +2 -0
  12. package/dist/adapters/currency-rates.js +18 -0
  13. package/dist/adapters/dashboards.js +43 -0
  14. package/dist/adapters/demo.js +13 -0
  15. package/dist/adapters/instance-settings.js +7 -0
  16. package/dist/adapters/invites.js +7 -0
  17. package/dist/adapters/recurring.js +55 -0
  18. package/dist/adapters/sessions.js +7 -0
  19. package/dist/adapters/settings.js +4 -0
  20. package/dist/adapters/setup-codes.js +7 -0
  21. package/dist/adapters/tags.js +9 -0
  22. package/dist/adapters/transactions.js +95 -0
  23. package/dist/adapters/users.js +7 -0
  24. package/dist/common/build-version.js +5 -0
  25. package/dist/common/errors.js +118 -0
  26. package/dist/common/net.js +71 -0
  27. package/dist/common/result.js +7 -0
  28. package/dist/composition/auth.js +106 -0
  29. package/dist/composition/boot.js +27 -0
  30. package/dist/composition/cli.js +86 -0
  31. package/dist/composition/demo/seed.js +92 -0
  32. package/dist/composition/demo/shell.js +107 -0
  33. package/dist/composition/export.js +89 -0
  34. package/dist/composition/http.js +110 -0
  35. package/dist/composition/import.js +55 -0
  36. package/dist/composition/lazy-modules.js +2 -0
  37. package/dist/composition/runtime.js +115 -0
  38. package/dist/composition/sign-in/interpreter.js +154 -0
  39. package/dist/composition/sign-in/server.js +36 -0
  40. package/dist/composition/sign-in/wiring.js +23 -0
  41. package/dist/composition/stdio.js +69 -0
  42. package/dist/config.js +136 -0
  43. package/dist/controllers/account/account.js +88 -0
  44. package/dist/controllers/account/transaction.js +119 -0
  45. package/dist/controllers/account/transfer.js +34 -0
  46. package/dist/controllers/aggregate.js +40 -0
  47. package/dist/controllers/auth/access-tokens.js +61 -0
  48. package/dist/controllers/auth/grants.js +136 -0
  49. package/dist/controllers/auth/key-export.js +20 -0
  50. package/dist/controllers/auth/owner.js +80 -0
  51. package/dist/controllers/auth/password.js +35 -0
  52. package/dist/controllers/auth/session.js +50 -0
  53. package/dist/controllers/auth/step-up.js +8 -0
  54. package/dist/controllers/auth/users.js +183 -0
  55. package/dist/controllers/budgets.js +87 -0
  56. package/dist/controllers/categories.js +67 -0
  57. package/dist/controllers/correlations.js +112 -0
  58. package/dist/controllers/credit-card/bill.js +105 -0
  59. package/dist/controllers/credit-card/credit-card.js +129 -0
  60. package/dist/controllers/credit-card/transaction.js +181 -0
  61. package/dist/controllers/currencies.js +1 -0
  62. package/dist/controllers/currency-rates.js +40 -0
  63. package/dist/controllers/dashboards.js +68 -0
  64. package/dist/controllers/demo/seed.js +31 -0
  65. package/dist/controllers/demo/tour.js +12 -0
  66. package/dist/controllers/deps.js +6 -0
  67. package/dist/controllers/instance.js +6 -0
  68. package/dist/controllers/merchants.js +12 -0
  69. package/dist/controllers/recurring.js +70 -0
  70. package/dist/controllers/resolve.js +37 -0
  71. package/dist/controllers/settings.js +47 -0
  72. package/dist/controllers/status.js +19 -0
  73. package/dist/controllers/summary.js +21 -0
  74. package/dist/controllers/tags.js +19 -0
  75. package/dist/controllers/transaction/bulk.js +6 -0
  76. package/dist/controllers/transaction/core.js +49 -0
  77. package/dist/controllers/transaction/read.js +28 -0
  78. package/dist/diplomat/auth/credentials.js +58 -0
  79. package/dist/diplomat/auth/sign-in-store.js +18 -0
  80. package/dist/diplomat/cli/commands/auth.js +100 -0
  81. package/dist/diplomat/cli/commands/db.js +72 -0
  82. package/dist/diplomat/cli/commands/demo.js +68 -0
  83. package/dist/diplomat/cli/commands/key.js +119 -0
  84. package/dist/diplomat/cli/commands/login.js +151 -0
  85. package/dist/diplomat/cli/commands/setup.js +132 -0
  86. package/dist/diplomat/cli/commands/users.js +123 -0
  87. package/dist/diplomat/cli/commands.js +61 -0
  88. package/dist/diplomat/cli/export-file.js +37 -0
  89. package/dist/diplomat/cli/import-file.js +44 -0
  90. package/dist/diplomat/cli/io.js +61 -0
  91. package/dist/diplomat/cli/key-export-approval.js +37 -0
  92. package/dist/diplomat/cli/messages.js +96 -0
  93. package/dist/diplomat/cli/prompt.js +74 -0
  94. package/dist/diplomat/cli/terminal.js +81 -0
  95. package/dist/diplomat/client-config/clients.js +150 -0
  96. package/dist/diplomat/client-config/merge.js +41 -0
  97. package/dist/diplomat/db/bootstrap.js +98 -0
  98. package/dist/diplomat/db/database-files.js +147 -0
  99. package/dist/diplomat/db/driver.js +167 -0
  100. package/dist/diplomat/db/effects.js +101 -0
  101. package/dist/diplomat/db/engine.js +9 -0
  102. package/dist/diplomat/db/export.js +22 -0
  103. package/dist/diplomat/db/file-lock.js +82 -0
  104. package/dist/diplomat/db/key-lock.js +14 -0
  105. package/dist/diplomat/db/locale-cache.js +23 -0
  106. package/dist/diplomat/db/migration-barrier.js +57 -0
  107. package/dist/diplomat/db/migration-journal.js +18 -0
  108. package/dist/diplomat/db/migration-lock.js +15 -0
  109. package/dist/diplomat/db/migrations.js +11 -0
  110. package/dist/diplomat/db/present.js +17 -0
  111. package/dist/diplomat/db/queries/aggregate-whitelist.js +35 -0
  112. package/dist/diplomat/db/queries/filters.js +59 -0
  113. package/dist/diplomat/db/queries/fts.js +18 -0
  114. package/dist/diplomat/db/queries/scope.js +8 -0
  115. package/dist/diplomat/db/queries/transaction-select.js +26 -0
  116. package/dist/diplomat/db/queries/tx-predicates.js +13 -0
  117. package/dist/diplomat/db/repos/access-tokens.js +27 -0
  118. package/dist/diplomat/db/repos/accounts.js +91 -0
  119. package/dist/diplomat/db/repos/bills.js +93 -0
  120. package/dist/diplomat/db/repos/budgets.js +72 -0
  121. package/dist/diplomat/db/repos/categories.js +53 -0
  122. package/dist/diplomat/db/repos/client-grants.js +67 -0
  123. package/dist/diplomat/db/repos/correlations.js +66 -0
  124. package/dist/diplomat/db/repos/credit-cards.js +67 -0
  125. package/dist/diplomat/db/repos/currencies.js +8 -0
  126. package/dist/diplomat/db/repos/currency-rates.js +40 -0
  127. package/dist/diplomat/db/repos/dashboards.js +123 -0
  128. package/dist/diplomat/db/repos/health.js +12 -0
  129. package/dist/diplomat/db/repos/instance-settings.js +14 -0
  130. package/dist/diplomat/db/repos/instance.js +58 -0
  131. package/dist/diplomat/db/repos/invites.js +43 -0
  132. package/dist/diplomat/db/repos/merchants.js +121 -0
  133. package/dist/diplomat/db/repos/recurring.js +29 -0
  134. package/dist/diplomat/db/repos/sessions.js +19 -0
  135. package/dist/diplomat/db/repos/settings.js +41 -0
  136. package/dist/diplomat/db/repos/setup-codes.js +28 -0
  137. package/dist/diplomat/db/repos/sub-categories.js +67 -0
  138. package/dist/diplomat/db/repos/tags.js +51 -0
  139. package/dist/diplomat/db/repos/transaction-tags.js +57 -0
  140. package/dist/diplomat/db/repos/transactions.js +163 -0
  141. package/dist/diplomat/db/repos/users.js +47 -0
  142. package/dist/diplomat/db/safety-copy.js +87 -0
  143. package/dist/diplomat/db/schema.js +348 -0
  144. package/dist/diplomat/db/seed/categories.js +112 -0
  145. package/dist/diplomat/db/seed/currencies.js +9 -0
  146. package/dist/diplomat/db/seed/demo/br.js +98 -0
  147. package/dist/diplomat/db/seed/demo/co.js +89 -0
  148. package/dist/diplomat/db/seed/demo/index.js +12 -0
  149. package/dist/diplomat/db/seed/demo/mx.js +90 -0
  150. package/dist/diplomat/db/seed/demo/shared.js +39 -0
  151. package/dist/diplomat/db/seed/demo/us.js +90 -0
  152. package/dist/diplomat/db/seed/merchant-rules.js +188 -0
  153. package/dist/diplomat/db/sqlite-errors.js +40 -0
  154. package/dist/diplomat/db/tenancy-integrity.js +45 -0
  155. package/dist/diplomat/db/version-guard.js +16 -0
  156. package/dist/diplomat/http/auth-pages.js +41 -0
  157. package/dist/diplomat/http/auth-paths.js +46 -0
  158. package/dist/diplomat/http/bearer.js +15 -0
  159. package/dist/diplomat/http/connect-pages.js +51 -0
  160. package/dist/diplomat/http/context.js +17 -0
  161. package/dist/diplomat/http/cookies.js +27 -0
  162. package/dist/diplomat/http/form-pages.js +38 -0
  163. package/dist/diplomat/http/hooks/auth.js +106 -0
  164. package/dist/diplomat/http/hooks/demo-marker.js +59 -0
  165. package/dist/diplomat/http/openapi.js +73 -0
  166. package/dist/diplomat/http/principal.js +1 -0
  167. package/dist/diplomat/http/rate-limiter.js +78 -0
  168. package/dist/diplomat/http/remedy.js +26 -0
  169. package/dist/diplomat/http/respond.js +50 -0
  170. package/dist/diplomat/http/routes/account.js +226 -0
  171. package/dist/diplomat/http/routes/aggregate.js +28 -0
  172. package/dist/diplomat/http/routes/auth.js +105 -0
  173. package/dist/diplomat/http/routes/budget.js +34 -0
  174. package/dist/diplomat/http/routes/category.js +109 -0
  175. package/dist/diplomat/http/routes/connect.js +124 -0
  176. package/dist/diplomat/http/routes/credit-card.js +263 -0
  177. package/dist/diplomat/http/routes/currency-rates.js +60 -0
  178. package/dist/diplomat/http/routes/currency.js +16 -0
  179. package/dist/diplomat/http/routes/dashboard.js +93 -0
  180. package/dist/diplomat/http/routes/invite.js +63 -0
  181. package/dist/diplomat/http/routes/recurring.js +65 -0
  182. package/dist/diplomat/http/routes/settings.js +38 -0
  183. package/dist/diplomat/http/routes/summary.js +23 -0
  184. package/dist/diplomat/http/routes/system.js +29 -0
  185. package/dist/diplomat/http/routes/tag.js +51 -0
  186. package/dist/diplomat/http/routes/tokens.js +72 -0
  187. package/dist/diplomat/http/routes/transaction.js +55 -0
  188. package/dist/diplomat/http/routes/transfer.js +35 -0
  189. package/dist/diplomat/http/routes/ui.js +110 -0
  190. package/dist/diplomat/http/routes/users.js +156 -0
  191. package/dist/diplomat/http/routes/well-known.js +26 -0
  192. package/dist/diplomat/http/routes.js +85 -0
  193. package/dist/diplomat/http/session.js +34 -0
  194. package/dist/diplomat/http/token-pages.js +75 -0
  195. package/dist/diplomat/http/ui-files.js +21 -0
  196. package/dist/diplomat/http/user-pages.js +93 -0
  197. package/dist/diplomat/mcp/annotations.js +8 -0
  198. package/dist/diplomat/mcp/auth-info.js +20 -0
  199. package/dist/diplomat/mcp/context.js +14 -0
  200. package/dist/diplomat/mcp/definition.js +3 -0
  201. package/dist/diplomat/mcp/gate.js +15 -0
  202. package/dist/diplomat/mcp/instructions.js +19 -0
  203. package/dist/diplomat/mcp/prompts.js +125 -0
  204. package/dist/diplomat/mcp/register.js +12 -0
  205. package/dist/diplomat/mcp/remedy.js +17 -0
  206. package/dist/diplomat/mcp/resources.js +93 -0
  207. package/dist/diplomat/mcp/respond.js +20 -0
  208. package/dist/diplomat/mcp/route.js +62 -0
  209. package/dist/diplomat/mcp/scopes.js +53 -0
  210. package/dist/diplomat/mcp/server.js +26 -0
  211. package/dist/diplomat/mcp/shared.js +5 -0
  212. package/dist/diplomat/mcp/stdio-session.js +94 -0
  213. package/dist/diplomat/mcp/stdio.js +23 -0
  214. package/dist/diplomat/mcp/tool-name.js +59 -0
  215. package/dist/diplomat/mcp/tools/account.js +218 -0
  216. package/dist/diplomat/mcp/tools/aggregate.js +32 -0
  217. package/dist/diplomat/mcp/tools/budget.js +99 -0
  218. package/dist/diplomat/mcp/tools/category.js +103 -0
  219. package/dist/diplomat/mcp/tools/correlations.js +70 -0
  220. package/dist/diplomat/mcp/tools/credit-card.js +239 -0
  221. package/dist/diplomat/mcp/tools/currency-rates.js +62 -0
  222. package/dist/diplomat/mcp/tools/dashboard.js +75 -0
  223. package/dist/diplomat/mcp/tools/index.js +31 -0
  224. package/dist/diplomat/mcp/tools/recurring.js +62 -0
  225. package/dist/diplomat/mcp/tools/summary.js +30 -0
  226. package/dist/diplomat/mcp/tools/system.js +83 -0
  227. package/dist/diplomat/mcp/tools/tag.js +48 -0
  228. package/dist/diplomat/mcp/tools/transaction.js +53 -0
  229. package/dist/diplomat/mcp/tools/transfer.js +28 -0
  230. package/dist/diplomat/mcp/tour.js +87 -0
  231. package/dist/logic/account.js +79 -0
  232. package/dist/logic/aggregate.js +37 -0
  233. package/dist/logic/auth/bearer.js +35 -0
  234. package/dist/logic/auth/grant.js +126 -0
  235. package/dist/logic/auth/key-export.js +10 -0
  236. package/dist/logic/auth/keychain.js +3 -0
  237. package/dist/logic/auth/message.js +22 -0
  238. package/dist/logic/auth/origin.js +57 -0
  239. package/dist/logic/auth/owner.js +22 -0
  240. package/dist/logic/auth/password.js +3 -0
  241. package/dist/logic/auth/redact.js +25 -0
  242. package/dist/logic/auth/revoke.js +28 -0
  243. package/dist/logic/auth/scope.js +17 -0
  244. package/dist/logic/auth/session.js +30 -0
  245. package/dist/logic/auth/sign-in-flow.js +305 -0
  246. package/dist/logic/auth/time.js +2 -0
  247. package/dist/logic/auth/token.js +74 -0
  248. package/dist/logic/auth/user-plans.js +84 -0
  249. package/dist/logic/auth/users.js +78 -0
  250. package/dist/logic/balance.js +2 -0
  251. package/dist/logic/bill.js +74 -0
  252. package/dist/logic/budget.js +78 -0
  253. package/dist/logic/category.js +37 -0
  254. package/dist/logic/classify.js +21 -0
  255. package/dist/logic/correlations.js +147 -0
  256. package/dist/logic/credit-card.js +2 -0
  257. package/dist/logic/currency-rate.js +69 -0
  258. package/dist/logic/dashboard.js +40 -0
  259. package/dist/logic/demo/database.js +30 -0
  260. package/dist/logic/demo/plan.js +308 -0
  261. package/dist/logic/demo/tour.js +33 -0
  262. package/dist/logic/export-destination.js +12 -0
  263. package/dist/logic/key-import.js +15 -0
  264. package/dist/logic/locale.js +5 -0
  265. package/dist/logic/localize.js +12 -0
  266. package/dist/logic/merchant.js +31 -0
  267. package/dist/logic/migration.js +1 -0
  268. package/dist/logic/money.js +12 -0
  269. package/dist/logic/period.js +45 -0
  270. package/dist/logic/persistence.js +48 -0
  271. package/dist/logic/recurring.js +51 -0
  272. package/dist/logic/resolve.js +44 -0
  273. package/dist/logic/summary.js +29 -0
  274. package/dist/logic/tag.js +13 -0
  275. package/dist/logic/transaction.js +197 -0
  276. package/dist/main.js +42 -0
  277. package/dist/models/account.js +197 -0
  278. package/dist/models/aggregate.js +61 -0
  279. package/dist/models/auth/bearer.js +11 -0
  280. package/dist/models/auth/entity.js +17 -0
  281. package/dist/models/auth/errors.js +42 -0
  282. package/dist/models/auth/grant.js +58 -0
  283. package/dist/models/auth/key-export.js +11 -0
  284. package/dist/models/auth/message.js +50 -0
  285. package/dist/models/auth/mode.js +7 -0
  286. package/dist/models/auth/origin.js +16 -0
  287. package/dist/models/auth/owner.js +36 -0
  288. package/dist/models/auth/password.js +24 -0
  289. package/dist/models/auth/principal.js +26 -0
  290. package/dist/models/auth/redact.js +4 -0
  291. package/dist/models/auth/scope.js +9 -0
  292. package/dist/models/auth/session.js +19 -0
  293. package/dist/models/auth/sign-in-flow.js +102 -0
  294. package/dist/models/auth/sign-in.js +41 -0
  295. package/dist/models/auth/time.js +5 -0
  296. package/dist/models/auth/token.js +50 -0
  297. package/dist/models/auth/users.js +52 -0
  298. package/dist/models/bill.js +55 -0
  299. package/dist/models/budget.js +106 -0
  300. package/dist/models/category.js +52 -0
  301. package/dist/models/client-config.js +18 -0
  302. package/dist/models/correlations.js +215 -0
  303. package/dist/models/credit-card.js +156 -0
  304. package/dist/models/currency-rate.js +83 -0
  305. package/dist/models/dashboard.js +54 -0
  306. package/dist/models/database.js +16 -0
  307. package/dist/models/date.js +8 -0
  308. package/dist/models/demo/core.js +58 -0
  309. package/dist/models/demo/tour.js +41 -0
  310. package/dist/models/encryption-key.js +2 -0
  311. package/dist/models/error.js +13 -0
  312. package/dist/models/export.js +9 -0
  313. package/dist/models/id.js +2 -0
  314. package/dist/models/instance.js +7 -0
  315. package/dist/models/key-import.js +6 -0
  316. package/dist/models/locale.js +25 -0
  317. package/dist/models/merchant.js +12 -0
  318. package/dist/models/money.js +14 -0
  319. package/dist/models/package.js +12 -0
  320. package/dist/models/page.js +56 -0
  321. package/dist/models/persistence.js +1 -0
  322. package/dist/models/prompts.js +5 -0
  323. package/dist/models/recurring.js +54 -0
  324. package/dist/models/remedy.js +17 -0
  325. package/dist/models/resolution.js +1 -0
  326. package/dist/models/startup.js +7 -0
  327. package/dist/models/summary.js +24 -0
  328. package/dist/models/tag.js +14 -0
  329. package/dist/models/tenancy.js +10 -0
  330. package/dist/models/transaction-tag.js +6 -0
  331. package/dist/models/transaction.js +275 -0
  332. package/dist/wire/db/access-tokens.js +1 -0
  333. package/dist/wire/db/accounts.js +7 -0
  334. package/dist/wire/db/aggregate.js +16 -0
  335. package/dist/wire/db/bills.js +14 -0
  336. package/dist/wire/db/budgets.js +33 -0
  337. package/dist/wire/db/categories.js +14 -0
  338. package/dist/wire/db/client-grants.js +1 -0
  339. package/dist/wire/db/correlations.js +49 -0
  340. package/dist/wire/db/credit-cards.js +1 -0
  341. package/dist/wire/db/currencies.js +1 -0
  342. package/dist/wire/db/currency-rates.js +1 -0
  343. package/dist/wire/db/dashboards.js +1 -0
  344. package/dist/wire/db/instance-settings.js +1 -0
  345. package/dist/wire/db/invites.js +1 -0
  346. package/dist/wire/db/merchants.js +18 -0
  347. package/dist/wire/db/recurring.js +19 -0
  348. package/dist/wire/db/sessions.js +1 -0
  349. package/dist/wire/db/settings.js +1 -0
  350. package/dist/wire/db/setup-codes.js +1 -0
  351. package/dist/wire/db/tags.js +1 -0
  352. package/dist/wire/db/tenancy.js +1 -0
  353. package/dist/wire/db/transactions.js +89 -0
  354. package/dist/wire/db/users.js +1 -0
  355. package/dist/wire/in/accounts.js +26 -0
  356. package/dist/wire/in/aggregate.js +10 -0
  357. package/dist/wire/in/auth.js +107 -0
  358. package/dist/wire/in/bills.js +11 -0
  359. package/dist/wire/in/budgets.js +11 -0
  360. package/dist/wire/in/categories.js +9 -0
  361. package/dist/wire/in/cli.js +106 -0
  362. package/dist/wire/in/coerce.js +6 -0
  363. package/dist/wire/in/common.js +17 -0
  364. package/dist/wire/in/credit-cards.js +16 -0
  365. package/dist/wire/in/currency-rates.js +8 -0
  366. package/dist/wire/in/period.js +7 -0
  367. package/dist/wire/in/recurring.js +6 -0
  368. package/dist/wire/in/settings.js +5 -0
  369. package/dist/wire/in/summary.js +5 -0
  370. package/dist/wire/in/tags.js +2 -0
  371. package/dist/wire/in/transactions.js +31 -0
  372. package/dist/wire/out/bills.js +9 -0
  373. package/dist/wire/out/budgets.js +10 -0
  374. package/dist/wire/out/client-config.js +2 -0
  375. package/dist/wire/out/common.js +4 -0
  376. package/dist/wire/out/credit-cards.js +15 -0
  377. package/dist/wire/out/currency-rates.js +11 -0
  378. package/dist/wire/out/errors.js +58 -0
  379. package/dist/wire/out/recurring.js +6 -0
  380. package/dist/wire/out/status.js +10 -0
  381. package/dist/wire/out/summary.js +9 -0
  382. package/dist/wire/out/transactions.js +52 -0
  383. package/drizzle/0000_futuristic_umar.sql +124 -0
  384. package/drizzle/0001_fts5_search.sql +23 -0
  385. package/drizzle/0002_rename_graph_to_history.sql +7 -0
  386. package/drizzle/0003_lyrical_hairball.sql +2 -0
  387. package/drizzle/0004_misty_ikaris.sql +7 -0
  388. package/drizzle/0005_credit-liability-accounts.sql +14 -0
  389. package/drizzle/0006_smart_aqueduct.sql +1 -0
  390. package/drizzle/0007_add_dashboards.sql +5 -0
  391. package/drizzle/0008_yummy_madripoor.sql +1 -0
  392. package/drizzle/0009_version_groundwork.sql +9 -0
  393. package/drizzle/0010_category_merchant_association_cascade.sql +16 -0
  394. package/drizzle/0011_dashboard_id_normalization.sql +16 -0
  395. package/drizzle/0012_hot_the_spike.sql +12 -0
  396. package/drizzle/0013_recurring_rules_merchant.sql +1 -0
  397. package/drizzle/0014_dashboard_source_discriminator.sql +17 -0
  398. package/drizzle/0015_currencies_decimals.sql +1 -0
  399. package/drizzle/0016_unusual_zaran.sql +13 -0
  400. package/drizzle/0017_premium_blur.sql +1 -0
  401. package/drizzle/0018_auth_identity.sql +39 -0
  402. package/drizzle/0019_access_tokens.sql +16 -0
  403. package/drizzle/0020_stdio_sign_in.sql +27 -0
  404. package/drizzle/0021_tenancy_data.sql +289 -0
  405. package/drizzle/0022_user_management.sql +17 -0
  406. package/drizzle/0023_instance_settings_row.sql +2 -0
  407. package/drizzle/0024_credentials_changed_at.sql +2 -0
  408. package/drizzle/0025_instance_kind.sql +2 -0
  409. package/drizzle/0026_demo_seeded_at.sql +2 -0
  410. package/drizzle/0027_demo_country.sql +2 -0
  411. package/drizzle/0028_reset_sign_ins.sql +2 -0
  412. package/drizzle/meta/0000_snapshot.json +894 -0
  413. package/drizzle/meta/0003_snapshot.json +910 -0
  414. package/drizzle/meta/0004_snapshot.json +951 -0
  415. package/drizzle/meta/0005_snapshot.json +991 -0
  416. package/drizzle/meta/0006_snapshot.json +998 -0
  417. package/drizzle/meta/0007_snapshot.json +1029 -0
  418. package/drizzle/meta/0008_snapshot.json +1049 -0
  419. package/drizzle/meta/0009_snapshot.json +1121 -0
  420. package/drizzle/meta/0010_snapshot.json +1121 -0
  421. package/drizzle/meta/0011_snapshot.json +1136 -0
  422. package/drizzle/meta/0012_snapshot.json +1227 -0
  423. package/drizzle/meta/0013_snapshot.json +1247 -0
  424. package/drizzle/meta/0014_snapshot.json +1267 -0
  425. package/drizzle/meta/0015_snapshot.json +1275 -0
  426. package/drizzle/meta/0016_snapshot.json +1371 -0
  427. package/drizzle/meta/0017_snapshot.json +1392 -0
  428. package/drizzle/meta/0018_snapshot.json +1603 -0
  429. package/drizzle/meta/0019_snapshot.json +1713 -0
  430. package/drizzle/meta/0020_snapshot.json +1904 -0
  431. package/drizzle/meta/0021_snapshot.json +2186 -0
  432. package/drizzle/meta/0022_snapshot.json +2311 -0
  433. package/drizzle/meta/0023_snapshot.json +2311 -0
  434. package/drizzle/meta/0024_snapshot.json +2318 -0
  435. package/drizzle/meta/0025_snapshot.json +2326 -0
  436. package/drizzle/meta/0026_snapshot.json +2333 -0
  437. package/drizzle/meta/0027_snapshot.json +2340 -0
  438. package/drizzle/meta/0028_snapshot.json +2340 -0
  439. package/drizzle/meta/_journal.json +209 -0
  440. package/package.json +106 -4
  441. package/skills/dashboard-building/SKILL.md +201 -0
  442. package/skills/patty-tour/SKILL.md +34 -0
  443. package/ui/app.css +758 -0
  444. package/ui/app.js +543 -0
  445. package/ui/connect-result.html +16 -0
  446. package/ui/connect.html +53 -0
  447. package/ui/dashboards/accounts.html +3189 -0
  448. package/ui/dashboards/budget.html +1734 -0
  449. package/ui/dashboards/cards.html +4032 -0
  450. package/ui/dashboards/categories.html +4694 -0
  451. package/ui/dashboards/comparative.html +2475 -0
  452. package/ui/dashboards/dashboards.html +839 -0
  453. package/ui/dashboards/overview.html +2405 -0
  454. package/ui/dashboards/pending.html +2973 -0
  455. package/ui/dashboards/projections.html +2528 -0
  456. package/ui/dashboards/tags.html +1365 -0
  457. package/ui/invite.html +44 -0
  458. package/ui/login.html +26 -0
  459. package/ui/money.js +175 -0
  460. package/ui/setup.html +29 -0
  461. package/ui/shell.html +96 -0
  462. package/ui/token-created.html +24 -0
  463. package/ui/tokens.html +58 -0
  464. package/ui/user-invited.html +27 -0
  465. package/ui/users.html +60 -0
@@ -0,0 +1,12 @@
1
+ import { DemoCountry } from '../../../../models/demo/core.js';
2
+ import { BR_PACK } from './br.js';
3
+ import { CO_PACK } from './co.js';
4
+ import { MX_PACK } from './mx.js';
5
+ import { US_PACK } from './us.js';
6
+ /** One pack per country: the `Record` key type makes a missing country a compile error. */
7
+ export const DEMO_PACKS = {
8
+ [DemoCountry.enum.br]: BR_PACK,
9
+ [DemoCountry.enum.us]: US_PACK,
10
+ [DemoCountry.enum.mx]: MX_PACK,
11
+ [DemoCountry.enum.co]: CO_PACK,
12
+ };
@@ -0,0 +1,90 @@
1
+ import { DemoCountry, DemoFunding } from '../../../../models/demo/core.js';
2
+ import { TOUR_FACTS } from '../../../../models/demo/tour.js';
3
+ import { Locale } from '../../../../models/locale.js';
4
+ import { CurrencyCode } from '../../../../models/money.js';
5
+ import { DefaultCategoryId } from '../categories.js';
6
+ import { BUDGET_SHAPES, fixedLine, pendingLine, SPANISH_TAGS, spendLine, tripItem } from './shared.js';
7
+ const C = DefaultCategoryId.enum;
8
+ const F = DemoFunding.enum;
9
+ const WORK = SPANISH_TAGS.work;
10
+ const FAMILY = SPANISH_TAGS.family;
11
+ /** Mexico: es, MXN — Nu México, BBVA México and Banorte, a trip to Oaxaca. */
12
+ export const MX_PACK = {
13
+ country: DemoCountry.enum.mx,
14
+ locale: Locale.enum.es,
15
+ currency: CurrencyCode.enum.MXN,
16
+ amountStep: 0.5,
17
+ usdRate: 18.5,
18
+ accounts: {
19
+ checking: { name: 'BBVA México', initialBalance: 28000 },
20
+ savings: { name: 'Nu México Cajita', initialBalance: 65000 },
21
+ investment: { name: 'Banorte Inversión', initialBalance: 150000 },
22
+ wallet: { name: 'Efectivo', initialBalance: 1500 },
23
+ usdc: { name: 'USDC Cripto', initialBalance: 450 },
24
+ btc: { name: 'BTC Cripto', initialBalance: 0.0185 },
25
+ },
26
+ cards: {
27
+ primary: { name: 'Nu México Tarjeta', closingDay: 4, dueDay: 24, limit: 60000 },
28
+ secondary: { name: 'Banorte Oro', closingDay: 21, dueDay: 8, limit: 80000 },
29
+ },
30
+ tags: [WORK, FAMILY],
31
+ salary: fixedLine(C['cat-salary'], 'Nómina Empresa', 32000, 15),
32
+ rent: fixedLine(C['cat-housing'], 'Renta', 9500, 3),
33
+ subscriptions: [
34
+ fixedLine(C['cat-subscriptions'], 'Netflix', 219, 12),
35
+ fixedLine(C['cat-subscriptions'], 'Spotify', 129, 15),
36
+ fixedLine(C['cat-health'], 'Gimnasio Smart Fit', 449, 8),
37
+ fixedLine(C['cat-utilities'], 'Internet Telmex Infinitum', 499, 20),
38
+ ],
39
+ freelance: fixedLine(C['cat-extra-income'], 'Proyecto freelance', 7500, 18),
40
+ spending: [
41
+ spendLine(F.primaryCard, C['cat-food'], 'Soriana', [650, 1500], 2),
42
+ spendLine(F.wallet, C['cat-food'], 'Oxxo', [40, 180], 4),
43
+ spendLine(F.wallet, C['cat-food'], 'Mercado de Coyoacán', [150, 400], 2),
44
+ spendLine(F.primaryCard, C['cat-food'], 'Rappi', [140, 380], 4),
45
+ spendLine(F.wallet, C['cat-food'], 'Tacos El Califa', [120, 280], 2),
46
+ spendLine(F.checking, C['cat-food'], 'Panadería La Esperanza', [60, 180], 2),
47
+ spendLine(F.primaryCard, C['cat-food'], 'Comida con cliente', [350, 800], 1, WORK),
48
+ spendLine(F.primaryCard, C['cat-transport'], 'DiDi', [55, 180], 5),
49
+ spendLine(F.secondaryCard, C['cat-transport'], 'Uber', [70, 210], 2),
50
+ spendLine(F.secondaryCard, C['cat-transport'], 'Gasolinera Pemex', [600, 900], 2),
51
+ spendLine(F.wallet, C['cat-transport'], 'Estacionamiento', [40, 90], 1),
52
+ spendLine(F.checking, C['cat-health'], 'Farmacias del Ahorro', [120, 600], 2),
53
+ spendLine(F.checking, C['cat-health'], 'Consulta Dr. Hernández', [700, 700], 1),
54
+ spendLine(F.primaryCard, C['cat-leisure'], 'Cinépolis', [120, 300], 1),
55
+ spendLine(F.secondaryCard, C['cat-leisure'], 'Bar La Ópera', [350, 900], 2),
56
+ spendLine(F.secondaryCard, C['cat-shopping'], 'Liverpool', [600, 2400], 1),
57
+ spendLine(F.primaryCard, C['cat-shopping'], 'Mercado Libre', [300, 1500], 1),
58
+ spendLine(F.secondaryCard, C['cat-shopping'], 'Amazon México', [250, 1800], 1),
59
+ spendLine(F.secondaryCard, C['cat-shopping'], 'Regalo para la familia', [400, 1100], 1, FAMILY),
60
+ spendLine(F.checking, C['cat-utilities'], 'Recibo de luz CFE', [400, 750], 1),
61
+ spendLine(F.checking, C['cat-utilities'], 'Recibo de agua', [200, 350], 1),
62
+ spendLine(F.checking, C['cat-education'], 'Curso de inglés', [1800, 1800], 1),
63
+ ],
64
+ transfers: {
65
+ savings: { description: 'Ahorro mensual', amount: 4000 },
66
+ investment: { description: 'Aportación a inversión', amount: 3000 },
67
+ wallet: { description: 'Retiro para efectivo', amount: 1500 },
68
+ },
69
+ pending: [
70
+ pendingLine(C['cat-housing'], 'Mantenimiento del edificio', 1400, 5),
71
+ pendingLine(C['cat-transport'], 'Seguro del auto', 1100, 8),
72
+ pendingLine(C['cat-extra-income'], 'Reembolso de gastos', 1800, 3, true),
73
+ ],
74
+ budgets: BUDGET_SHAPES,
75
+ trip: {
76
+ destination: TOUR_FACTS[DemoCountry.enum.mx].destination,
77
+ items: [
78
+ tripItem(0, F.primaryCard, C['cat-travel'], 'Vuelo Viva Aerobus a Oaxaca', 2450),
79
+ tripItem(0, F.primaryCard, C['cat-travel'], 'Hotel Casa Oaxaca', 5200),
80
+ tripItem(0, F.checking, C['cat-transport'], 'Taxi del aeropuerto de Oaxaca', 320),
81
+ tripItem(1, F.secondaryCard, C['cat-food'], 'Cena en Casa Oaxaca restaurante', 1380),
82
+ tripItem(1, F.secondaryCard, C['cat-transport'], 'Renta de auto Oaxaca', 1900),
83
+ tripItem(2, F.secondaryCard, C['cat-leisure'], 'Tour a Hierve el Agua Oaxaca', 780),
84
+ tripItem(3, F.wallet, C['cat-food'], 'Comida en el Mercado 20 de Noviembre Oaxaca', 420),
85
+ tripItem(4, F.secondaryCard, C['cat-shopping'], 'Artesanías y mezcal Oaxaca', 1650),
86
+ tripItem(4, F.primaryCard, C['cat-food'], 'Desayuno y mole en Oaxaca', 560),
87
+ tripItem(5, F.checking, C['cat-transport'], 'Taxi al aeropuerto de Oaxaca', 340),
88
+ ],
89
+ },
90
+ };
@@ -0,0 +1,39 @@
1
+ import * as R from 'remeda';
2
+ import { DemoFunding, } from '../../../../models/demo/core.js';
3
+ import { CATEGORIES, DefaultCategoryId } from '../categories.js';
4
+ /** A seeded category's canonical (English) name — the one every locale's category lookup resolves. */
5
+ export const CATEGORY_NAME = R.mapToObj(CATEGORIES, (category) => [
6
+ category.id,
7
+ category.name,
8
+ ]);
9
+ const C = DefaultCategoryId.enum;
10
+ /** The two tags the Spanish packs (Mexico and Colombia) share. */
11
+ export const SPANISH_TAGS = { work: 'trabajo', family: 'familia' };
12
+ /** Budgets are sized against last month's spend: food and leisure were over budget, the rest comfortably under. */
13
+ export const BUDGET_SHAPES = [
14
+ { category: CATEGORY_NAME[C['cat-food']], factor: 0.75 },
15
+ { category: CATEGORY_NAME[C['cat-leisure']], factor: 0.8 },
16
+ { category: CATEGORY_NAME[C['cat-transport']], factor: 1.3 },
17
+ { category: CATEGORY_NAME[C['cat-shopping']], factor: 1.35 },
18
+ { category: CATEGORY_NAME[C['cat-health']], factor: 1.5 },
19
+ ];
20
+ /** A recurring purchase, written the way a pack reads: where, what, how much, how often. */
21
+ export const spendLine = (via, category, description, range, perMonth, tag) => ({
22
+ description,
23
+ category: CATEGORY_NAME[category],
24
+ via,
25
+ min: range[0],
26
+ max: range[1],
27
+ perMonth,
28
+ ...(tag ? { tag } : {}),
29
+ });
30
+ export const fixedLine = (category, description, amount, day) => ({ description, category: CATEGORY_NAME[category], amount, day });
31
+ export const tripItem = (dayOffset, via, category, description, amount) => ({ description, category: CATEGORY_NAME[category], via, amount, dayOffset });
32
+ export const pendingLine = (category, description, amount, daysAhead, income = false) => ({
33
+ description,
34
+ category: CATEGORY_NAME[category],
35
+ via: DemoFunding.enum.checking,
36
+ amount,
37
+ daysAhead,
38
+ ...(income ? { income } : {}),
39
+ });
@@ -0,0 +1,90 @@
1
+ import { DemoCountry, DemoFunding } from '../../../../models/demo/core.js';
2
+ import { TOUR_FACTS } from '../../../../models/demo/tour.js';
3
+ import { Locale } from '../../../../models/locale.js';
4
+ import { CurrencyCode } from '../../../../models/money.js';
5
+ import { DefaultCategoryId } from '../categories.js';
6
+ import { BUDGET_SHAPES, fixedLine, pendingLine, spendLine, tripItem } from './shared.js';
7
+ const C = DefaultCategoryId.enum;
8
+ const F = DemoFunding.enum;
9
+ const WORK = 'work';
10
+ const FAMILY = 'family';
11
+ /** United States: en, USD — Chase, Amex and Nubank, a trip to Denver. */
12
+ export const US_PACK = {
13
+ country: DemoCountry.enum.us,
14
+ locale: Locale.enum.en,
15
+ currency: CurrencyCode.enum.USD,
16
+ amountStep: 0.01,
17
+ usdRate: 1,
18
+ accounts: {
19
+ checking: { name: 'Chase Checking', initialBalance: 4200 },
20
+ savings: { name: 'Nubank Savings', initialBalance: 9500 },
21
+ investment: { name: 'Fidelity Brokerage', initialBalance: 28000 },
22
+ wallet: { name: 'Cash Wallet', initialBalance: 150 },
23
+ usdc: { name: 'USDC Wallet', initialBalance: 600 },
24
+ btc: { name: 'BTC Wallet', initialBalance: 0.0185 },
25
+ },
26
+ cards: {
27
+ primary: { name: 'Chase Sapphire', closingDay: 5, dueDay: 28, limit: 9000 },
28
+ secondary: { name: 'Amex Gold', closingDay: 18, dueDay: 12, limit: 12000 },
29
+ },
30
+ tags: [WORK, FAMILY],
31
+ salary: fixedLine(C['cat-salary'], 'Paycheck Acme Corp', 5400, 1),
32
+ rent: fixedLine(C['cat-housing'], 'Rent Maple Apartments', 1850, 3),
33
+ subscriptions: [
34
+ fixedLine(C['cat-subscriptions'], 'Netflix', 15.49, 12),
35
+ fixedLine(C['cat-subscriptions'], 'Spotify', 11.99, 15),
36
+ fixedLine(C['cat-health'], 'Planet Fitness membership', 24.99, 8),
37
+ fixedLine(C['cat-utilities'], 'Xfinity internet', 69.99, 20),
38
+ ],
39
+ freelance: fixedLine(C['cat-extra-income'], 'Freelance design project', 1400, 18),
40
+ spending: [
41
+ spendLine(F.primaryCard, C['cat-food'], 'Whole Foods', [70, 190], 2),
42
+ spendLine(F.checking, C['cat-food'], "Trader Joe's", [45, 120], 2),
43
+ spendLine(F.wallet, C['cat-food'], 'Farmers market', [20, 45], 2),
44
+ spendLine(F.primaryCard, C['cat-food'], 'DoorDash', [22, 55], 4),
45
+ spendLine(F.secondaryCard, C['cat-food'], 'Chipotle', [12, 19], 3),
46
+ spendLine(F.wallet, C['cat-food'], 'Blue Bottle Coffee', [5, 11], 4),
47
+ spendLine(F.primaryCard, C['cat-food'], 'Client lunch', [40, 90], 1, WORK),
48
+ spendLine(F.primaryCard, C['cat-transport'], 'Lyft', [11, 38], 5),
49
+ spendLine(F.checking, C['cat-transport'], 'Uber', [12, 34], 2),
50
+ spendLine(F.secondaryCard, C['cat-transport'], 'Shell gas station', [38, 65], 2),
51
+ spendLine(F.wallet, C['cat-transport'], 'Parking Impark', [8, 22], 1),
52
+ spendLine(F.checking, C['cat-health'], 'CVS Pharmacy', [12, 60], 2),
53
+ spendLine(F.checking, C['cat-health'], 'Dr. Patel copay', [35, 35], 1),
54
+ spendLine(F.primaryCard, C['cat-leisure'], 'AMC Theatres', [14, 32], 1),
55
+ spendLine(F.secondaryCard, C['cat-leisure'], 'The Tipsy Crow', [40, 110], 2),
56
+ spendLine(F.secondaryCard, C['cat-shopping'], 'Amazon', [22, 180], 2),
57
+ spendLine(F.primaryCard, C['cat-shopping'], 'Target', [30, 140], 1),
58
+ spendLine(F.secondaryCard, C['cat-shopping'], 'Nike Store', [60, 140], 1),
59
+ spendLine(F.secondaryCard, C['cat-shopping'], 'Gift for the family', [40, 120], 1, FAMILY),
60
+ spendLine(F.checking, C['cat-utilities'], 'PG&E electric bill', [70, 130], 1),
61
+ spendLine(F.checking, C['cat-utilities'], 'City water bill', [35, 60], 1),
62
+ spendLine(F.secondaryCard, C['cat-education'], 'Coursera', [49, 49], 1),
63
+ ],
64
+ transfers: {
65
+ savings: { description: 'Monthly savings', amount: 800 },
66
+ investment: { description: 'Brokerage contribution', amount: 500 },
67
+ wallet: { description: 'ATM cash withdrawal', amount: 120 },
68
+ },
69
+ pending: [
70
+ pendingLine(C['cat-housing'], 'HOA fee', 220, 5),
71
+ pendingLine(C['cat-transport'], 'Car insurance', 140, 8),
72
+ pendingLine(C['cat-extra-income'], 'Expense reimbursement', 320, 3, true),
73
+ ],
74
+ budgets: BUDGET_SHAPES,
75
+ trip: {
76
+ destination: TOUR_FACTS[DemoCountry.enum.us].destination,
77
+ items: [
78
+ tripItem(0, F.primaryCard, C['cat-travel'], 'United Airlines flight to Denver', 412),
79
+ tripItem(0, F.primaryCard, C['cat-travel'], 'Hotel Monaco Denver', 890),
80
+ tripItem(0, F.checking, C['cat-transport'], 'Lyft from Denver airport', 48),
81
+ tripItem(1, F.secondaryCard, C['cat-food'], 'Dinner at Tavernetta Denver', 168),
82
+ tripItem(1, F.secondaryCard, C['cat-transport'], 'Rental car Hertz Denver', 245),
83
+ tripItem(2, F.secondaryCard, C['cat-leisure'], 'Red Rocks Amphitheatre tickets Denver', 120),
84
+ tripItem(3, F.wallet, C['cat-food'], 'Lunch at Union Station Denver', 38),
85
+ tripItem(4, F.secondaryCard, C['cat-shopping'], 'Gifts at Larimer Square Denver', 96),
86
+ tripItem(4, F.primaryCard, C['cat-food'], 'Dinner at Rioja Denver', 142),
87
+ tripItem(5, F.checking, C['cat-transport'], 'Lyft to Denver airport', 52),
88
+ ],
89
+ },
90
+ };
@@ -0,0 +1,188 @@
1
+ import { z } from 'zod';
2
+ import { DefaultCategoryId } from './categories.js';
3
+ const D = DefaultCategoryId.enum;
4
+ /**
5
+ * A seed merchant rule maps a normalized merchant **key** (matched as a substring of the
6
+ * normalized transaction description) to a canonical category **slug**. Identity is the slug —
7
+ * never a localized name — so the rules are language-independent in their target; only the
8
+ * *keys* vary by language.
9
+ *
10
+ * Authoring rules (matching is `description LIKE '%key%'`, ties broken by longer key):
11
+ * - Keys must be normalized: lowercase, accent-free, letters + single spaces only (mirror
12
+ * `logic/merchant.ts#normalizeMerchant`). They are re-normalized at seed time, so authoring
13
+ * them already-normalized is belt-and-suspenders, not required.
14
+ * - Prefer distinctive keys of 4+ characters. Avoid short tokens that embed in unrelated words
15
+ * (`gas` ⊂ `gasolina`, `tax` ⊂ `taxi`, `bar` ⊂ `embarque`) — they misfire.
16
+ * - When a longer, more specific key should win over a generic one (e.g. `uber eats`→food over
17
+ * `uber`→transport), add both: the length tiebreak resolves it.
18
+ */
19
+ export const MerchantRule = z.object({
20
+ key: z.string().min(1),
21
+ category: DefaultCategoryId,
22
+ });
23
+ // ─── Language-agnostic brands ──────────────────────────────────────────────────
24
+ // Recognised regardless of locale, so a mixed statement (a Brazilian with Uber, Netflix
25
+ // and iFood) classifies out of the box. Longer-first where a brand must beat a generic key.
26
+ const brandRules = [
27
+ // Ride-hailing & mobility
28
+ { key: 'uber eats', category: D['cat-food'] }, // longer than 'uber' → wins the tiebreak
29
+ { key: 'uber', category: D['cat-transport'] },
30
+ { key: 'lyft', category: D['cat-transport'] },
31
+ { key: 'cabify', category: D['cat-transport'] },
32
+ { key: 'didi', category: D['cat-transport'] },
33
+ // Food delivery
34
+ { key: 'ifood', category: D['cat-food'] },
35
+ { key: 'rappi', category: D['cat-food'] },
36
+ { key: 'doordash', category: D['cat-food'] },
37
+ { key: 'deliveroo', category: D['cat-food'] },
38
+ { key: 'glovo', category: D['cat-food'] },
39
+ // Streaming & subscriptions
40
+ { key: 'netflix', category: D['cat-subscriptions'] },
41
+ { key: 'spotify', category: D['cat-subscriptions'] },
42
+ { key: 'disney', category: D['cat-subscriptions'] },
43
+ { key: 'youtube premium', category: D['cat-subscriptions'] },
44
+ { key: 'hbo', category: D['cat-subscriptions'] },
45
+ { key: 'paramount', category: D['cat-subscriptions'] },
46
+ // Marketplaces & retail
47
+ { key: 'amazon prime', category: D['cat-subscriptions'] }, // longer than 'amazon' → wins
48
+ { key: 'amazon', category: D['cat-shopping'] },
49
+ { key: 'mercado livre', category: D['cat-shopping'] }, // longer than 'mercado' (food) → wins
50
+ { key: 'mercado libre', category: D['cat-shopping'] },
51
+ { key: 'aliexpress', category: D['cat-shopping'] },
52
+ { key: 'shopee', category: D['cat-shopping'] },
53
+ { key: 'walmart', category: D['cat-shopping'] },
54
+ // Travel
55
+ { key: 'airbnb', category: D['cat-travel'] },
56
+ { key: 'booking com', category: D['cat-travel'] },
57
+ { key: 'latam', category: D['cat-travel'] },
58
+ ];
59
+ // ─── English keyword pack ───────────────────────────────────────────────────────
60
+ const enRules = [
61
+ { key: 'restaurant', category: D['cat-food'] },
62
+ { key: 'grocery', category: D['cat-food'] },
63
+ { key: 'supermarket', category: D['cat-food'] },
64
+ { key: 'bakery', category: D['cat-food'] },
65
+ { key: 'coffee', category: D['cat-food'] },
66
+ // Transport (avoid bare 'gas' — it embeds in 'gasoline'; use specific keys)
67
+ { key: 'gas station', category: D['cat-transport'] },
68
+ { key: 'gasoline', category: D['cat-transport'] },
69
+ { key: 'fuel', category: D['cat-transport'] },
70
+ { key: 'parking', category: D['cat-transport'] },
71
+ { key: 'taxi', category: D['cat-transport'] },
72
+ { key: 'rent', category: D['cat-housing'] },
73
+ { key: 'mortgage', category: D['cat-housing'] },
74
+ { key: 'electric', category: D['cat-utilities'] },
75
+ { key: 'water bill', category: D['cat-utilities'] },
76
+ { key: 'internet', category: D['cat-utilities'] },
77
+ { key: 'mobile', category: D['cat-utilities'] },
78
+ { key: 'pharmacy', category: D['cat-health'] },
79
+ { key: 'doctor', category: D['cat-health'] },
80
+ { key: 'dentist', category: D['cat-health'] },
81
+ { key: 'hospital', category: D['cat-health'] },
82
+ { key: 'school', category: D['cat-education'] },
83
+ { key: 'university', category: D['cat-education'] },
84
+ { key: 'tuition', category: D['cat-education'] },
85
+ { key: 'cinema', category: D['cat-leisure'] },
86
+ { key: 'theater', category: D['cat-leisure'] },
87
+ { key: 'hotel', category: D['cat-travel'] },
88
+ { key: 'airline', category: D['cat-travel'] },
89
+ { key: 'flight', category: D['cat-travel'] },
90
+ { key: 'salary', category: D['cat-salary'] },
91
+ { key: 'payroll', category: D['cat-salary'] },
92
+ // Taxes (avoid bare 'tax' — it embeds in 'taxi')
93
+ { key: 'income tax', category: D['cat-taxes'] },
94
+ ];
95
+ // ─── Portuguese (BR/PT) keyword pack ────────────────────────────────────────────
96
+ const ptRules = [
97
+ { key: 'restaurante', category: D['cat-food'] },
98
+ { key: 'lanchonete', category: D['cat-food'] },
99
+ { key: 'padaria', category: D['cat-food'] },
100
+ { key: 'mercado', category: D['cat-food'] },
101
+ { key: 'supermercado', category: D['cat-food'] },
102
+ { key: 'acougue', category: D['cat-food'] },
103
+ { key: 'hortifruti', category: D['cat-food'] },
104
+ // Transporte (sem 'gas' isolado — colide com 'gasolina')
105
+ { key: 'posto', category: D['cat-transport'] },
106
+ { key: 'gasolina', category: D['cat-transport'] },
107
+ { key: 'combustivel', category: D['cat-transport'] },
108
+ { key: 'estacionamento', category: D['cat-transport'] },
109
+ { key: 'pedagio', category: D['cat-transport'] },
110
+ { key: 'metro', category: D['cat-transport'] },
111
+ { key: 'aluguel', category: D['cat-housing'] },
112
+ { key: 'condominio', category: D['cat-housing'] },
113
+ { key: 'conta de luz', category: D['cat-utilities'] },
114
+ { key: 'energia', category: D['cat-utilities'] },
115
+ { key: 'conta de agua', category: D['cat-utilities'] },
116
+ { key: 'internet', category: D['cat-utilities'] },
117
+ { key: 'telefone', category: D['cat-utilities'] },
118
+ { key: 'farmacia', category: D['cat-health'] },
119
+ { key: 'drogaria', category: D['cat-health'] },
120
+ { key: 'medico', category: D['cat-health'] },
121
+ { key: 'dentista', category: D['cat-health'] },
122
+ { key: 'hospital', category: D['cat-health'] },
123
+ { key: 'academia', category: D['cat-health'] },
124
+ { key: 'escola', category: D['cat-education'] },
125
+ { key: 'faculdade', category: D['cat-education'] },
126
+ { key: 'mensalidade', category: D['cat-education'] },
127
+ { key: 'curso', category: D['cat-education'] },
128
+ { key: 'cinema', category: D['cat-leisure'] },
129
+ { key: 'teatro', category: D['cat-leisure'] },
130
+ { key: 'hotel', category: D['cat-travel'] },
131
+ { key: 'pousada', category: D['cat-travel'] },
132
+ { key: 'passagem', category: D['cat-travel'] },
133
+ { key: 'salario', category: D['cat-salary'] },
134
+ { key: 'imposto', category: D['cat-taxes'] },
135
+ { key: 'iptu', category: D['cat-taxes'] },
136
+ { key: 'ipva', category: D['cat-taxes'] },
137
+ { key: 'darf', category: D['cat-taxes'] },
138
+ ];
139
+ // ─── Spanish keyword pack ───────────────────────────────────────────────────────
140
+ const esRules = [
141
+ { key: 'restaurante', category: D['cat-food'] },
142
+ { key: 'cafeteria', category: D['cat-food'] },
143
+ { key: 'panaderia', category: D['cat-food'] },
144
+ { key: 'supermercado', category: D['cat-food'] },
145
+ { key: 'mercado', category: D['cat-food'] },
146
+ { key: 'carniceria', category: D['cat-food'] },
147
+ // Transporte (sin 'gas' suelto — colisiona con 'gasolina')
148
+ { key: 'gasolinera', category: D['cat-transport'] },
149
+ { key: 'gasolina', category: D['cat-transport'] },
150
+ { key: 'combustible', category: D['cat-transport'] },
151
+ { key: 'estacionamiento', category: D['cat-transport'] },
152
+ { key: 'peaje', category: D['cat-transport'] },
153
+ { key: 'metro', category: D['cat-transport'] },
154
+ { key: 'alquiler', category: D['cat-housing'] },
155
+ { key: 'hipoteca', category: D['cat-housing'] },
156
+ { key: 'comunidad', category: D['cat-housing'] },
157
+ { key: 'electricidad', category: D['cat-utilities'] },
158
+ { key: 'recibo de luz', category: D['cat-utilities'] },
159
+ { key: 'agua', category: D['cat-utilities'] },
160
+ { key: 'internet', category: D['cat-utilities'] },
161
+ { key: 'telefono', category: D['cat-utilities'] },
162
+ { key: 'farmacia', category: D['cat-health'] },
163
+ { key: 'medico', category: D['cat-health'] },
164
+ { key: 'dentista', category: D['cat-health'] },
165
+ { key: 'hospital', category: D['cat-health'] },
166
+ { key: 'gimnasio', category: D['cat-health'] },
167
+ { key: 'colegio', category: D['cat-education'] },
168
+ { key: 'universidad', category: D['cat-education'] },
169
+ { key: 'matricula', category: D['cat-education'] },
170
+ { key: 'curso', category: D['cat-education'] },
171
+ { key: 'cine', category: D['cat-leisure'] },
172
+ { key: 'teatro', category: D['cat-leisure'] },
173
+ { key: 'hotel', category: D['cat-travel'] },
174
+ { key: 'vuelo', category: D['cat-travel'] },
175
+ { key: 'pasaje', category: D['cat-travel'] },
176
+ { key: 'nomina', category: D['cat-salary'] },
177
+ { key: 'salario', category: D['cat-salary'] },
178
+ { key: 'sueldo', category: D['cat-salary'] },
179
+ { key: 'impuesto', category: D['cat-taxes'] },
180
+ { key: 'hacienda', category: D['cat-taxes'] },
181
+ ];
182
+ /**
183
+ * Canonical default merchant rules, additive across languages: brands + en/pt/es unioned and
184
+ * loaded for every user (locale drives display names, never which rules apply). Keys are
185
+ * re-normalized and deduped by (key, category) at seed time (`bootstrap.ts`). Add a locale by
186
+ * appending a new pack here.
187
+ */
188
+ export const DEFAULT_MERCHANT_RULES = [...brandRules, ...enRules, ...ptRules, ...esRules];
@@ -0,0 +1,40 @@
1
+ import { LibsqlError } from '@libsql/client';
2
+ // A UNIQUE-constraint error on an `id`-keyed insert can only be some OTHER unique column on the
3
+ // table — an `id` collision is already absorbed by `versionedTableApplier`'s own
4
+ // `onConflictDoNothing` (scoped to `id`) and never throws in the first place.
5
+ const SQLITE_UNIQUE_CONSTRAINT_CODE = 'SQLITE_CONSTRAINT_UNIQUE';
6
+ // A row referencing the one a versioned delete is removing was inserted after that delete's own
7
+ // flow read its point-in-time state — the same kind of "the world changed since we read" race a
8
+ // stale `version` reports, just surfaced by the FK check instead.
9
+ const SQLITE_FOREIGN_KEY_CONSTRAINT_CODE = 'SQLITE_CONSTRAINT_FOREIGNKEY';
10
+ // The base result code shared by every busy variant (plain SQLITE_BUSY, and the more specific
11
+ // SQLITE_BUSY_SNAPSHOT/SQLITE_BUSY_RECOVERY WAL raises under checkpoint starvation) — matched on
12
+ // `.code`, not `.extendedCode`, so all of them are caught by one check (ADR-024).
13
+ const SQLITE_BUSY_CODE = 'SQLITE_BUSY';
14
+ const matchesExtendedCode = (cause, extendedCode) => {
15
+ for (let current = cause; current instanceof Error; current = current.cause) {
16
+ if (current instanceof LibsqlError)
17
+ return current.extendedCode === extendedCode;
18
+ }
19
+ return false;
20
+ };
21
+ const matchesCode = (cause, code) => {
22
+ for (let current = cause; current instanceof Error; current = current.cause) {
23
+ if (current instanceof LibsqlError)
24
+ return current.code === code;
25
+ }
26
+ return false;
27
+ };
28
+ /** Walks the `.cause` chain rather than assuming exactly one level of wrapping (drizzle's
29
+ * `DrizzleQueryError` wraps the driver's own `LibsqlError`) — robust to an extra or missing
30
+ * wrapping layer. Used by appliers that need to recognize a non-`id` unique-constraint race and
31
+ * rethrow it as a `VersionConflict` instead of a raw 500. */
32
+ export const isUniqueConstraintViolation = (cause) => matchesExtendedCode(cause, SQLITE_UNIQUE_CONSTRAINT_CODE);
33
+ /** Same `.cause`-chain walk as `isUniqueConstraintViolation`, for a versioned delete that failed
34
+ * because some other row now references the one being removed. */
35
+ export const isForeignKeyConstraintViolation = (cause) => matchesExtendedCode(cause, SQLITE_FOREIGN_KEY_CONSTRAINT_CODE);
36
+ /** Same `.cause`-chain walk, matched on the base `.code` so every busy variant is covered by one
37
+ * check. A transient physical lock-contention condition (busy_timeout exhausted, or a WAL
38
+ * checkpoint-starvation snapshot conflict) — `applyBatch` (`diplomat/db/effects.ts`) treats it as
39
+ * retryable the same way it treats a `VersionConflict` (ADR-024). */
40
+ export const isSqliteBusy = (cause) => matchesCode(cause, SQLITE_BUSY_CODE);
@@ -0,0 +1,45 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import { SQLiteSyncDialect } from 'drizzle-orm/sqlite-core';
3
+ import * as R from 'remeda';
4
+ import { DefaultCategoryId } from './seed/categories.js';
5
+ import { z } from 'zod';
6
+ import { LOG_PREFIX } from '../../models/package.js';
7
+ export const OWNED_TABLES = [
8
+ 'accounts',
9
+ 'credit_cards',
10
+ 'bills',
11
+ 'transactions',
12
+ 'tags',
13
+ 'budgets',
14
+ 'recurring_rules',
15
+ ];
16
+ export const SHARED_OR_OWNED_TABLES = ['categories', 'merchant_category', 'dashboards'];
17
+ const USER_KEYED_TABLES = ['user_settings'];
18
+ const CountRowSchema = z.object({ count: z.coerce.number() });
19
+ const KNOWN_USER = sql `user_id IN (SELECT id FROM users)`;
20
+ const dialect = new SQLiteSyncDialect();
21
+ /** A shared category must be a seeded one: with the owner missing, the backfill would silently share the owner's. */
22
+ const SEEDED_CATEGORY_IDS = sql.join(DefaultCategoryId.options.map((id) => sql `${id}`), sql `, `);
23
+ const orphanConditionOf = (table) => table === 'categories'
24
+ ? sql `(user_id IS NOT NULL AND NOT (${KNOWN_USER})) OR (user_id IS NULL AND id NOT IN (${SEEDED_CATEGORY_IDS}))`
25
+ : sql `user_id IS NOT NULL AND NOT (${KNOWN_USER})`;
26
+ const checks = [
27
+ ...OWNED_TABLES.map((table) => [table, sql `user_id IS NULL OR NOT (${KNOWN_USER})`]),
28
+ ...SHARED_OR_OWNED_TABLES.map((table) => [table, orphanConditionOf(table)]),
29
+ ...USER_KEYED_TABLES.map((table) => [table, sql `NOT (${KNOWN_USER})`]),
30
+ ];
31
+ const orphanCount = async (db, [table, orphanCondition]) => {
32
+ const { sql: text, params } = dialect.sqlToQuery(sql `SELECT COUNT(*) AS count FROM ${sql.identifier(table)} WHERE ${orphanCondition}`);
33
+ const { rows } = await db.execute({ sql: text, args: params });
34
+ return [table, CountRowSchema.parse(rows[0]).count];
35
+ };
36
+ export const findRowsWithoutKnownUser = async (db) => R.pipe(await Promise.all(checks.map((check) => orphanCount(db, check))), R.filter(([, count]) => count > 0), R.fromEntries());
37
+ export const tenancyIntegrityMessage = (violations) => `${LOG_PREFIX} refusing to start — after the tenancy migration some rows belong to no known user (` +
38
+ R.pipe(Object.entries(violations), R.map(([table, count]) => `${table}: ${count}`), R.join(', ')) +
39
+ '). The migration was rolled back and the database is unchanged; restore from the .bak file next to it if in doubt.';
40
+ /** Throws so the surrounding transaction rolls back. */
41
+ export const assertOwnedRowsHaveKnownUsers = async (db) => {
42
+ const violations = await findRowsWithoutKnownUser(db);
43
+ if (Object.keys(violations).length > 0)
44
+ throw new Error(tenancyIntegrityMessage(violations));
45
+ };
@@ -0,0 +1,16 @@
1
+ import * as R from 'remeda';
2
+ import { version } from '../../common/build-version.js';
3
+ import { errAsync, okAsync, ResultAsync } from 'neverthrow';
4
+ import { isDatabaseAhead } from '../../logic/migration.js';
5
+ import { databaseErrors } from '../../models/database.js';
6
+ import { lastAppliedMillis, readJournal } from './migration-journal.js';
7
+ /**
8
+ * Says whether to go on: an error when the database's newest applied migration is newer than the newest this build
9
+ * ships — a stale `npx` or global install pointed at a database a later release has migrated. Read-only: the only
10
+ * things it touches are `__drizzle_migrations` and the journal, and it runs before anything is copied, migrated or
11
+ * seeded (`bootstrap` calls it first), so a refusal writes nothing.
12
+ */
13
+ export const checkDatabaseNotAhead = (db, migrationsFolder) => ResultAsync.fromSafePromise(lastAppliedMillis(db)).andThen((applied) => {
14
+ const newestKnown = R.firstBy(readJournal(migrationsFolder), [({ when }) => when, 'desc'])?.when ?? 0;
15
+ return isDatabaseAhead(applied, newestKnown) ? errAsync(databaseErrors.ahead(version)) : okAsync(undefined);
16
+ });
@@ -0,0 +1,41 @@
1
+ import { TERMINAL_SETUP_HINT } from '../../models/auth/message.js';
2
+ import { PASSWORD_MIN_LENGTH } from '../../models/auth/password.js';
3
+ import { LOGIN_PATH, SETUP_PATH, UI_APP_CSS_PATH } from './auth-paths.js';
4
+ import { readCached, UI_ROOT } from './ui-files.js';
5
+ const LOGIN_TEMPLATE_PATH = `${UI_ROOT}/login.html`;
6
+ const SETUP_TEMPLATE_PATH = `${UI_ROOT}/setup.html`;
7
+ const HTML_ESCAPES = {
8
+ '&': '&',
9
+ '<': '&lt;',
10
+ '>': '&gt;',
11
+ '"': '&quot;',
12
+ "'": '&#39;',
13
+ };
14
+ export const escapeHtml = (text) => text.replace(/[&<>"']/g, (char) => HTML_ESCAPES[char] ?? char);
15
+ const PLACEHOLDER = /\{\{(\w+)\}\}/g;
16
+ /** Substitutes `{{name}}` placeholders. Values are inserted verbatim, so callers pass only constants or
17
+ * `escapeHtml`'d text; an unknown placeholder becomes empty rather than leaking its name. */
18
+ export const fillTemplate = (template, values) => template.replace(PLACEHOLDER, (_match, name) => values[name] ?? '');
19
+ const ISO_MINUTE_LENGTH = 16;
20
+ /** `2026-10-09T12:34:56.000Z` → `2026-10-09 12:34 UTC`; absolute, so a page needs no script or locale. */
21
+ export const formatMinute = (iso) => `${iso.slice(0, ISO_MINUTE_LENGTH).replace('T', ' ')} UTC`;
22
+ // Typed by the enum, so a new access level cannot exist without a label — shared by the token form and the consent
23
+ // form, whose <option>/radio values are the very values their schemas accept.
24
+ export const ACCESS_LABEL = {
25
+ read: 'Read only — list and query, never change anything',
26
+ write: 'Read and write — can also record, edit and delete',
27
+ };
28
+ export const errorBlock = (message) => message === undefined ? '' : `<p class="auth-error" role="alert">${escapeHtml(message)}</p>`;
29
+ export const renderLoginPage = async (fields) => fillTemplate(await readCached(LOGIN_TEMPLATE_PATH), {
30
+ stylesheet: UI_APP_CSS_PATH,
31
+ action: LOGIN_PATH,
32
+ next: escapeHtml(fields.next),
33
+ error: errorBlock(fields.error),
34
+ });
35
+ export const renderSetupPage = async (fields) => fillTemplate(await readCached(SETUP_TEMPLATE_PATH), {
36
+ stylesheet: UI_APP_CSS_PATH,
37
+ action: SETUP_PATH,
38
+ passwordMinLength: String(PASSWORD_MIN_LENGTH),
39
+ terminalHint: escapeHtml(TERMINAL_SETUP_HINT),
40
+ error: errorBlock(fields.error),
41
+ });
@@ -0,0 +1,46 @@
1
+ import { API_PATH_PREFIX, MCP_PATH, MCP_PRM_PATH, PRM_WELL_KNOWN_PATH } from '../../models/auth/bearer.js';
2
+ import { CONNECT_PATH, INVITE_PATH, UI_ROOT_PATH } from '../../models/auth/origin.js';
3
+ import { UserAction } from '../../models/auth/users.js';
4
+ /** Route paths of the HTTP surface that authentication itself needs to name — one home, so the auth
5
+ * hook, the auth routes, the UI routes and the health route can never disagree on a literal. */
6
+ export const HEALTH_PATH = '/api/health';
7
+ export { API_PATH_PREFIX, CONNECT_PATH, INVITE_PATH, MCP_PATH, MCP_PRM_PATH, PRM_WELL_KNOWN_PATH, UI_ROOT_PATH };
8
+ // Two segments on purpose: `/ui/:name` is the one-segment dashboard namespace, and a dashboard may be named anything
9
+ // (including `tokens`), so token management must live outside it.
10
+ export const TOKENS_PATH = `${UI_ROOT_PATH}/access/tokens`;
11
+ export const TOKEN_REVOKE_PATH = `${TOKENS_PATH}/:id/revoke`;
12
+ // User management: admin-only pages, two segments under /ui/access for the same reason as the token pages.
13
+ export const USERS_PATH = `${UI_ROOT_PATH}/access/users`;
14
+ export const USERS_CAP_PATH = `${USERS_PATH}/sign-in-cap`;
15
+ const userActionPath = (action) => `${USERS_PATH}/:id/${action}`;
16
+ export const USER_REISSUE_PATH = userActionPath(UserAction.enum.reissue);
17
+ export const USER_DISABLE_PATH = userActionPath(UserAction.enum.disable);
18
+ export const USER_ENABLE_PATH = userActionPath(UserAction.enum.enable);
19
+ export const USER_ROLE_PATH = userActionPath(UserAction.enum.role);
20
+ /** The URL one user's action form posts to. */
21
+ export const userActionUrl = (userId, action) => userActionPath(action).replace(':id', encodeURIComponent(userId));
22
+ export const LOGIN_PATH = `${UI_ROOT_PATH}/login`;
23
+ export const SETUP_PATH = `${UI_ROOT_PATH}/setup`;
24
+ export const LOGOUT_PATH = `${UI_ROOT_PATH}/logout`;
25
+ export const UI_APP_CSS_PATH = `${UI_ROOT_PATH}/assets/app.css`;
26
+ /** After a form POST (login, setup, logout) the browser is sent on with a GET. */
27
+ export const SEE_OTHER = 303;
28
+ const GET_METHODS = ['GET', 'HEAD'];
29
+ const FORM_METHODS = ['GET', 'HEAD', 'POST'];
30
+ /**
31
+ * The ENTIRE unauthenticated surface: liveness, the three pages that create a session, and
32
+ * the one static asset those pages use. Matched against the route's registered pattern + method, never
33
+ * the raw URL, so path tricks cannot reach it; anything absent here — including a path no route
34
+ * matches — needs a credential. The Protected Resource Metadata (RFC 9728) is public by definition: a client
35
+ * reads it from the 401 challenge, before it holds any token. `/oauth/*` joins in Phase 3.
36
+ */
37
+ export const PUBLIC_ROUTES = {
38
+ [HEALTH_PATH]: GET_METHODS,
39
+ [LOGIN_PATH]: FORM_METHODS,
40
+ [SETUP_PATH]: FORM_METHODS,
41
+ [INVITE_PATH]: FORM_METHODS,
42
+ [UI_APP_CSS_PATH]: GET_METHODS,
43
+ [PRM_WELL_KNOWN_PATH]: GET_METHODS,
44
+ [MCP_PRM_PATH]: GET_METHODS,
45
+ };
46
+ export const isPublicRoute = (routePattern, method) => routePattern !== undefined && (PUBLIC_ROUTES[routePattern]?.includes(method.toUpperCase()) ?? false);
@@ -0,0 +1,15 @@
1
+ import { bearerChallenge, resourceMetadataUrl } from '../../logic/auth/bearer.js';
2
+ import { resourceOrigin } from '../../logic/auth/origin.js';
3
+ import { replyError } from './respond.js';
4
+ const WWW_AUTHENTICATE = 'www-authenticate';
5
+ /**
6
+ * Reject a request with a Bearer challenge (RFC 6750 §3, MCP authorization): the status follows the error, the
7
+ * `WWW-Authenticate` value is built in one place (`logic/auth/bearer.ts`'s `bearerChallenge`) and only its origin is
8
+ * resolved here, from `PUBLIC_URL` or the request's own loopback host. Shared by the auth hook and the MCP route's
9
+ * per-tool scope check so the two can never word a challenge differently.
10
+ */
11
+ export const rejectWithChallenge = (req, reply, publicUrl, error) => {
12
+ const origin = resourceOrigin(publicUrl, req.headers.host);
13
+ const metadataUrl = origin === null ? null : resourceMetadataUrl(origin);
14
+ return replyError(reply.header(WWW_AUTHENTICATE, bearerChallenge(error, metadataUrl)), error);
15
+ };