@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,54 @@
1
+ import { z } from 'zod';
2
+ import { Id } from './id.js';
3
+ import { withPersistenceMeta } from '@rfc0/effect-runner';
4
+ import { validation } from './error.js';
5
+ // A generous ceiling for a data-less dashboard fragment (the baseline template is ~20KB, down from
6
+ // ~30KB pre-ADR-027 now that shared chrome/CSS/Chart.js moved to the shell) — bounds worst-case DB
7
+ // growth and the cost of the render-ability check's vm.Script compile step (logic/dashboard.ts)
8
+ // against an oversized save, without constraining realistic dashboard sizes.
9
+ export const DASHBOARD_HTML_MAX_LENGTH = 500_000;
10
+ // ADR-027 Phase 2: `source` is the sole default/custom discriminator (no separate `kind` column).
11
+ // `file` — content resolved from a repo-relative .html file under ui/dashboards/ at read time;
12
+ // only bootstrap ever registers one (never save_dashboard — see dashboardErrors/saveDashboard).
13
+ // `inline` — content stored in the `dashboards.html` column, as before Phase 2.
14
+ export const DashboardSource = z.enum(['inline', 'file']);
15
+ export const DashboardSchema = z.object({
16
+ name: z.string().min(1).describe('Dashboard identifier, used as the /ui/:name path segment (e.g. "overview")'),
17
+ html: z
18
+ .string()
19
+ .max(DASHBOARD_HTML_MAX_LENGTH)
20
+ .describe("Content fragment (sections + script) rendered into the app shell's #content (GET /ui) — not a full " +
21
+ 'HTML page: no <!doctype>/<html>/<head>/<style> root, the shell already provides those. Must fetch ' +
22
+ 'data from /api on load — never embeds financial data'),
23
+ updatedAt: z.string().describe('ISO 8601 timestamp of the last save'),
24
+ source: DashboardSource.describe('inline: DB-stored, editable via save_dashboard. file: a bundled default read from ui/dashboards/, ' +
25
+ 'read-only at the install location (ADR-027 Phase 2)'),
26
+ });
27
+ export const DashboardListItemSchema = DashboardSchema.omit({ html: true });
28
+ export const SaveDashboardSchema = DashboardSchema.pick({ name: true, html: true });
29
+ export const RenameDashboardSchema = z.object({
30
+ name: DashboardSchema.shape.name.describe('Current dashboard name'),
31
+ newName: DashboardSchema.shape.name.describe('New dashboard name'),
32
+ });
33
+ export const DASHBOARD_ENTITY_TAG = 'dashboard';
34
+ export const DashboardEntitySchema = withPersistenceMeta(DashboardSchema).extend({
35
+ id: Id.describe('internal; never on wire/out'),
36
+ path: z
37
+ .string()
38
+ .nullable()
39
+ .describe('internal; never on wire/out. Repo-relative filename under ui/dashboards/ for source: file rows, ' +
40
+ 'always null for source: inline (ADR-027 Phase 2)'),
41
+ shared: z
42
+ .boolean()
43
+ .describe('internal; never on wire/out. One of the bundled defaults every user sees — nobody may change it'),
44
+ });
45
+ export const dashboardErrors = {
46
+ notFound: (name) => ({ code: 'unknown_dashboard', query: name, candidates: [] }),
47
+ invalidHtml: (issues) => validation(issues),
48
+ duplicateName: (name) => ({ code: 'duplicate_name', entity: 'dashboard', name }),
49
+ };
50
+ export const HTML_DOCUMENT_ROOT_PATTERN = /^\s*<!doctype html|<html[\s>]/i;
51
+ export const SKIPPED_SCRIPT_TYPES = ['application/json', 'application/ld+json', 'importmap', 'module'];
52
+ export const SCRIPT_TAG_PATTERN = /<script((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/script>/gi;
53
+ export const ATTRIBUTE_PATTERN = /([a-zA-Z][-\w:.]*)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
54
+ export const EXTERNAL_SCRIPT_ISSUE = 'no external <script src> allowed in a fragment — the shell already loads Chart.js once; fetch data from /api instead';
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod';
2
+ import { LOG_PREFIX, NPX_COMMAND, PACKAGE_NAME } from './package.js';
3
+ /** A database that a newer build has migrated: an expected failure, not an exception (ADR-034 §7). */
4
+ export const DatabaseAheadCode = z.enum(['database_ahead']);
5
+ export const databaseErrors = {
6
+ ahead: (version) => ({ code: DatabaseAheadCode.enum.database_ahead, version }),
7
+ };
8
+ /** `npm ls -g` is the check for the stale global install that made an old build run in the first place. */
9
+ export const STALE_GLOBAL_CHECK_COMMAND = `npm ls -g ${PACKAGE_NAME}`;
10
+ /**
11
+ * What an older build says when it finds a database migrated by a newer one, and why it refuses to go on (ADR-034 §7):
12
+ * it would run against a schema it does not know — and might seed or write into it. The one wording, no paths and no
13
+ * keys, shared by the server and every CLI command.
14
+ */
15
+ export const databaseAheadMessage = (buildVersion) => `${LOG_PREFIX} this build (v${buildVersion}) is older than your database (it has migrations this version doesn't ` +
16
+ `know). Update with \`${NPX_COMMAND}\`, or check for a stale global install: \`${STALE_GLOBAL_CHECK_COMMAND}\`.`;
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ export const IsoDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'expected YYYY-MM-DD');
3
+ export const RangeFrom = IsoDate.optional().describe('Start date (inclusive, YYYY-MM-DD) — alternative to month/year');
4
+ export const RangeTo = IsoDate.optional().describe('End date (exclusive, YYYY-MM-DD) — alternative to month/year');
5
+ export const PeriodSchema = z.object({
6
+ month: z.number().int().min(1).max(12).describe('Month (1–12)'),
7
+ year: z.number().int().min(2000).max(2100).describe('Calendar year'),
8
+ });
@@ -0,0 +1,58 @@
1
+ import { z } from 'zod';
2
+ import { InstanceKind } from '../instance.js';
3
+ import { validation } from '../error.js';
4
+ import { LOG_PREFIX, NPX_COMMAND } from '../package.js';
5
+ /** The four data sets a demo can be generated for. A language alone cannot choose: Spanish has two. */
6
+ export const DemoCountry = z.enum(['br', 'us', 'mx', 'co']);
7
+ export const DEFAULT_DEMO_COUNTRY = DemoCountry.enum.us;
8
+ /** Public on purpose: the data is fake, so the key protects nothing. */
9
+ export const DEMO_DB_KEY = '0123456789abcdef'.repeat(4);
10
+ export const DEMO_PORT = 51738;
11
+ export const DEMO_SERVER_NAME = 'patty-demo';
12
+ export const DEMO_ENV_VAR = 'PATTY_DEMO';
13
+ export const DEMO_ENV_ON = '1';
14
+ export const DemoNotReadyCode = z.enum(['demo_not_ready']);
15
+ export const demoNotReady = (databasePath) => ({
16
+ code: DemoNotReadyCode.enum.demo_not_ready,
17
+ databasePath,
18
+ });
19
+ export const demoNotReadyMessage = ({ databasePath }) => `${LOG_PREFIX} ${DEMO_ENV_VAR} is set, but ${databasePath} is not a demo database. Create it with: ${NPX_COMMAND} demo`;
20
+ /** Where a generated purchase comes from. The pack names the accounts and cards; the generator maps these to them. */
21
+ export const DemoFunding = z.enum(['checking', 'wallet', 'primaryCard', 'secondaryCard', 'global']);
22
+ export const DemoStepKind = z.enum([
23
+ 'locale',
24
+ 'baseCurrency',
25
+ 'account',
26
+ 'card',
27
+ 'tag',
28
+ 'rate',
29
+ 'recurring',
30
+ 'budget',
31
+ 'expense',
32
+ 'income',
33
+ 'purchase',
34
+ 'transfer',
35
+ 'applyDue',
36
+ 'payBill',
37
+ 'revertBill',
38
+ ]);
39
+ /** `interrupted`: the database holds data but no completion marker. */
40
+ export const DemoSeedStatus = z.enum(['seeded', 'present', 'interrupted', 'not_demo']);
41
+ export const demoErrors = {
42
+ stepFailed: (kind, date, reason) => validation([`demo seed failed at ${kind} (${date}): ${reason}`]),
43
+ };
44
+ export const DemoFailureCode = z.enum([
45
+ 'real_database',
46
+ 'not_demo',
47
+ 'interrupted',
48
+ 'seed_failed',
49
+ 'start_failed',
50
+ 'port_in_use',
51
+ 'busy',
52
+ ]);
53
+ export const demoFailures = {
54
+ of: (code, reason = '') => ({ code, reason }),
55
+ };
56
+ export const DemoProbeAbsence = z.enum(['missing', 'unreadable']);
57
+ export const DemoProbe = DemoProbeAbsence.or(InstanceKind);
58
+ export const DEMO_SEED_FRESH = 'fresh';
@@ -0,0 +1,41 @@
1
+ import { DemoCountry } from './core.js';
2
+ /** Per country, in local terms: a known merchant or two (classified), an income, and one nobody can classify (so the
3
+ * import shows `needs_review`). */
4
+ export const TOUR_FACTS = {
5
+ [DemoCountry.enum.br]: {
6
+ destination: 'Florianópolis',
7
+ statement: [
8
+ { daysAgo: 1, description: 'IFOOD *RESTAURANTE', amount: 54.9 },
9
+ { daysAgo: 2, description: 'UBER *TRIP', amount: 23.4 },
10
+ { daysAgo: 3, description: 'PIX RECEBIDO JOAO', amount: 150, income: true },
11
+ { daysAgo: 4, description: 'PAGTO XPTO 8831', amount: 89 },
12
+ ],
13
+ },
14
+ [DemoCountry.enum.us]: {
15
+ destination: 'Denver',
16
+ statement: [
17
+ { daysAgo: 1, description: 'WHOLE FOODS MARKET', amount: 62.35 },
18
+ { daysAgo: 2, description: 'LYFT *RIDE', amount: 18.2 },
19
+ { daysAgo: 3, description: 'ZELLE FROM JOHN', amount: 120, income: true },
20
+ { daysAgo: 4, description: 'POS DEBIT XPTO 8831', amount: 41 },
21
+ ],
22
+ },
23
+ [DemoCountry.enum.mx]: {
24
+ destination: 'Oaxaca',
25
+ statement: [
26
+ { daysAgo: 1, description: 'OXXO TIENDA', amount: 148.5 },
27
+ { daysAgo: 2, description: 'DIDI VIAJE', amount: 96 },
28
+ { daysAgo: 3, description: 'SPEI RECIBIDO JUAN', amount: 1200, income: true },
29
+ { daysAgo: 4, description: 'COMPRA XPTO 8831', amount: 450 },
30
+ ],
31
+ },
32
+ [DemoCountry.enum.co]: {
33
+ destination: 'Cartagena',
34
+ statement: [
35
+ { daysAgo: 1, description: 'EXITO COMPRA', amount: 142000 },
36
+ { daysAgo: 2, description: 'RAPPI PEDIDO', amount: 38500 },
37
+ { daysAgo: 3, description: 'TRANSFERENCIA RECIBIDA JUAN', amount: 250000, income: true },
38
+ { daysAgo: 4, description: 'COMPRA XPTO 8831', amount: 89000 },
39
+ ],
40
+ },
41
+ };
@@ -0,0 +1,2 @@
1
+ import { z } from 'zod';
2
+ export const EncryptionKey = z.string().regex(/^[0-9a-f]{64}$/i, 'must be a 64-character hex string');
@@ -0,0 +1,13 @@
1
+ /** Shared error primitives — domain vocabulary reused across entity models. */
2
+ export const validation = (issues) => ({ code: 'validation', issues });
3
+ /** A validation failure whose fix is another operation: neutral message, plus the `remedy` to use instead. */
4
+ export const validationWithRemedy = (message, remedy) => ({
5
+ code: 'validation',
6
+ issues: [message],
7
+ remedy,
8
+ });
9
+ export const conflict = { code: 'conflict' };
10
+ export const notFound = (entity, query, candidates) => ({ code: `unknown_${entity}`, query, candidates });
11
+ export const ambiguous = (entity, query, candidates) => ({ code: `ambiguous_${entity}`, query, candidates });
12
+ /** The words of whatever was thrown: an `Error`'s message, else the value as text. */
13
+ export const reasonOf = (cause) => (cause instanceof Error ? cause.message : String(cause));
@@ -0,0 +1,9 @@
1
+ /** Every file PATTY writes for the person to carry elsewhere (the safety copy, `key export`, `db export`) is
2
+ * created owner-only and never over an existing file. */
3
+ export const PRIVATE_FILE_MODE = 0o600;
4
+ /** `open(2)` flags: create the file, failing if anything is already there (a symlink included). */
5
+ export const EXCLUSIVE_CREATE_FLAG = 'wx';
6
+ export const DATABASE_COMPANION_SUFFIXES = ['-wal', '-shm', '-journal'];
7
+ export const DATA_BEARING_SUFFIXES = ['-wal', '-journal'];
8
+ export const FILE_EXISTS_CODE = 'EEXIST';
9
+ export const PRIVATE_DIRECTORY_MODE = 0o700;
@@ -0,0 +1,2 @@
1
+ import { z } from 'zod';
2
+ export const Id = z.string().min(1);
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ import { Locale } from './locale.js';
3
+ /** What the database says it is. Only the demo seeder writes `demo`; every other database is `standard`. */
4
+ export const InstanceKind = z.enum(['standard', 'demo']);
5
+ export const DEFAULT_INSTANCE_KIND = InstanceKind.enum.standard;
6
+ export const isDemoInstance = (kind) => kind === InstanceKind.enum.demo;
7
+ export const DEFAULT_INSTANCE = { kind: DEFAULT_INSTANCE_KIND, locale: Locale.enum.en };
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ export const KeyImportRefusal = z.enum(['key_file_configured', 'key_env_configured', 'keychain_holds_key']);
3
+ export const KEY_FILE_LINE_ENDINGS = ['\r\n', '\n'];
4
+ export const KEY_FILE_MAX_CHARACTERS = 64 + Math.max(...KEY_FILE_LINE_ENDINGS.map((ending) => ending.length));
5
+ export const KEY_LOCK_WAIT_MS = 60_000;
6
+ export const KEY_LOCK_RETRY_MS = 50;
@@ -0,0 +1,25 @@
1
+ import { z } from 'zod';
2
+ import { CurrencyCode } from './money.js';
3
+ import { withPersistenceMeta } from '@rfc0/effect-runner';
4
+ export const Locale = z.enum(['en', 'es', 'pt']);
5
+ export const LocaleSource = z.enum(['default', 'inferred', 'explicit']);
6
+ export const USER_SETTINGS_ENTITY_TAG = 'userSettings';
7
+ export const UserSettingsEntitySchema = withPersistenceMeta(z.object({
8
+ locale: Locale,
9
+ localeSource: LocaleSource,
10
+ // Explicit override; null means "derive from locale" (logic/locale.ts's resolveBaseCurrency,
11
+ // ADR-026 Phase 2) — unlike locale/localeSource, there is no separate explicit/inferred source
12
+ // to track, so a plain nullable column is enough.
13
+ baseCurrency: CurrencyCode.nullable(),
14
+ }));
15
+ export const PreferencesSchema = z.object({
16
+ locale: Locale,
17
+ localeSource: LocaleSource,
18
+ baseCurrency: CurrencyCode.describe('Resolved base currency — the explicit override, or the locale-derived default'),
19
+ });
20
+ export const localeErrors = {
21
+ explicitLocaleBlock: {
22
+ code: 'validation',
23
+ issues: ['Cannot auto-switch locale: user set it explicitly. Use source "explicit" to override.'],
24
+ },
25
+ };
@@ -0,0 +1,12 @@
1
+ /** `key`-only, no `version` — only ever inserted, idempotently, never updated or removed. */
2
+ export const MERCHANT_ENTITY_TAG = 'merchant';
3
+ /** The merchant→category learning edge: `updateAccountTransaction`/`updateCardTransaction` persist
4
+ * a user category correction as this entity's own `Persistable`, in the same atomic batch as the
5
+ * transaction update it came from — not a separate, non-atomic write after the fact. Both decide
6
+ * *which* edge to write via the shared `resolveMerchantCorrection` (`logic/merchant.ts`). */
7
+ export const MERCHANT_CATEGORY_ENTITY_TAG = 'merchantCategory';
8
+ /** Default row cap for `patty://merchants/top` (Feature Design 018) — a reference/vocabulary
9
+ * list, not a tunable report, so a static default rather than a caller-supplied parameter. */
10
+ export const DEFAULT_TOP_MERCHANTS_LIMIT = 20;
11
+ export const NOISE_PREFIXES = /^(pag\*?|pix\s+(enviado|recebido)?|compra\s+(no\s+)?(debito|credito)\s*|dbt\s+|crd\s+|tef\s+)/i;
12
+ export const MERCHANT_LEARNING_WEIGHT_DELTA = 1;
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod';
2
+ export const CurrencyCode = z.enum(['USD', 'BRL', 'MXN', 'COP', 'USDC', 'BTC']);
3
+ export const Money = z.number().positive();
4
+ // Reference metadata for a currency (ADR-026 Phase 1) — lets a client format a code
5
+ // `Intl.NumberFormat`'s currency mode can't handle correctly (USDC throws — 4 letters fail its
6
+ // syntax check; BTC doesn't throw — 3 letters pass, but it silently mis-formats with fiat-shaped
7
+ // precision and no real symbol) via this currency's own symbol + decimals instead.
8
+ export const CurrencySchema = z.object({
9
+ code: CurrencyCode.describe('ISO 4217 code for fiat, a local convention for crypto (USDC/BTC)'),
10
+ symbol: z.string().min(1).describe('Display symbol (e.g. R$, $, ₿)'),
11
+ name: z.string().min(1).describe('Display name'),
12
+ decimals: z.number().int().nonnegative().describe('Fractional digits for display/rounding'),
13
+ });
14
+ export const FIAT_DECIMALS = 2;
@@ -0,0 +1,12 @@
1
+ /** Package identity, shared by every message that tells a person what to run. Every command PATTY prints or
2
+ * documents is `@latest`-pinned: without a version `npx` prefers an installed (possibly stale, global) copy over the
3
+ * registry's. Built from this one constant, never re-typed. */
4
+ export const PACKAGE_NAME = '@rfc0/patty';
5
+ export const PACKAGE_SPEC = `${PACKAGE_NAME}@latest`;
6
+ export const NPX_COMMAND = `npx ${PACKAGE_SPEC}`;
7
+ export const REPOSITORY_URL = 'https://github.com/RafaelFCarneiro/patty';
8
+ /** The product's display name, as a person reads it. Not an identifier: the keychain service, MCP server names, data
9
+ * directory and token prefix are stored or installed names and never derive from it. */
10
+ export const PRODUCT_NAME = 'PATTY';
11
+ /** The prefix of every log and startup-error line this process writes. */
12
+ export const LOG_PREFIX = 'patty:';
@@ -0,0 +1,56 @@
1
+ import { z } from 'zod';
2
+ import { Id } from './id.js';
3
+ /**
4
+ * ADR-014: cursor pagination + whitelisted ordering, shared by every collection endpoint that
5
+ * adopts keyset paging. A named home (the `date.ts`/`money.ts`/`id.ts` convention), not a
6
+ * catch-all — per-entity sort enums (e.g. `TransactionSortField`) stay on their own entity model.
7
+ */
8
+ export const SortDirection = z.enum(['asc', 'desc']);
9
+ export const INCLUDE_TOTAL_DESCRIPTION = 'When true, include `total` — the count of all items matching the filters (costs an extra COUNT query). Default false';
10
+ /** Request fields shared by every cursor-paginated endpoint. QoL defaults (limit → 50, and
11
+ * each entity's sort/dir defaults) are applied at the wire boundary, per the
12
+ * defaults-by-intent rule — this schema only states the bounds/shape. */
13
+ export const PageRequestSchema = z.object({
14
+ cursor: z
15
+ .string()
16
+ .min(1)
17
+ .optional()
18
+ .describe('Opaque continuation token returned as `nextCursor` by a previous page'),
19
+ limit: z.number().int().min(1).max(200).describe('Maximum results per page'),
20
+ includeTotal: z.boolean().optional().describe(INCLUDE_TOTAL_DESCRIPTION),
21
+ });
22
+ /** `{ items, nextCursor?, total? }` — the paginated envelope. `nextCursor` is absent on the
23
+ * last page; `total` is present only when the request opted in via `includeTotal`. */
24
+ export const pageSchema = (itemSchema) => z.object({
25
+ items: z.array(itemSchema),
26
+ nextCursor: z.string().optional().describe('Opaque cursor for the next page; absent on the last page'),
27
+ total: z
28
+ .number()
29
+ .int()
30
+ .optional()
31
+ .describe('Count of all items matching the filters; present only when includeTotal was requested'),
32
+ });
33
+ /** The keyset tiebreaker pair a cursor carries: the sort field's value on the last row of a
34
+ * page, plus the entity id as tiebreaker (same direction as `dir` — ADR-014 Decision 1). */
35
+ export const CursorKeySchema = z.object({ value: z.union([z.string(), z.number()]), id: Id });
36
+ export const CURSOR_VERSION = 1;
37
+ /** Per-entity cursor payload: version + the sort binding it was produced under + the keyset.
38
+ * Opaque to clients — no encryption (local single-user app); opacity is a contract convention,
39
+ * not a security boundary. `sort` is the caller's own whitelisted sort-field enum. */
40
+ export const cursorSchema = (sort) => z.object({ v: z.literal(CURSOR_VERSION), sort, dir: SortDirection, key: CursorKeySchema });
41
+ const CURSOR_TEXT_ENCODING = 'utf8';
42
+ const CURSOR_TOKEN_ENCODING = 'base64url';
43
+ export const encodeCursor = (payload) => Buffer.from(JSON.stringify(payload), CURSOR_TEXT_ENCODING).toString(CURSOR_TOKEN_ENCODING);
44
+ /** Decodes + zod-validates an opaque cursor string against its entity-specific schema. Returns
45
+ * null for anything malformed or stale — callers turn that into a `validation` AppError. */
46
+ export const decodeCursor = (schema, raw) => {
47
+ let json;
48
+ try {
49
+ json = JSON.parse(Buffer.from(raw, CURSOR_TOKEN_ENCODING).toString(CURSOR_TEXT_ENCODING));
50
+ }
51
+ catch {
52
+ return null;
53
+ }
54
+ const parsed = schema.safeParse(json);
55
+ return parsed.success ? parsed.data : null;
56
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ /** Which statement kind the `import_statement` MCP prompt is walking the user through. */
3
+ export const ImportStatementSource = z.enum(['card', 'account']);
4
+ /** The guided-workflow MCP prompts the server registers (Feature Design 019). */
5
+ export const PromptName = z.enum(['monthly_review', 'budget_checkup', 'import_statement', 'tour']);
@@ -0,0 +1,54 @@
1
+ import { z } from 'zod';
2
+ import { IsoDate } from './date.js';
3
+ import { Id } from './id.js';
4
+ import { CurrencyCode, Money } from './money.js';
5
+ import { withPersistenceMeta } from '@rfc0/effect-runner';
6
+ import { MovementType } from './transaction.js';
7
+ export const RecurringPeriod = z.enum(['weekly', 'monthly', 'yearly']);
8
+ export const recurringPeriodLabels = {
9
+ weekly: { en: 'Weekly', pt: 'Semanal', es: 'Semanal' },
10
+ monthly: { en: 'Monthly', pt: 'Mensal', es: 'Mensual' },
11
+ yearly: { en: 'Yearly', pt: 'Anual', es: 'Anual' },
12
+ };
13
+ // `.describe()` is domain information — it states what each field is and represents.
14
+ // Defaults split by intent: integrity defaults (a value that must exist for the entity to be
15
+ // valid) live here; quality-of-life convenience defaults live at the wire boundary,
16
+ // keeping the domain contract honest about what is required.
17
+ export const RecurringRuleSchema = z.object({
18
+ id: Id,
19
+ description: z.string().min(1).describe('What this rule pays for (rent, salary, subscription…)'),
20
+ amount: Money.describe('Recurring amount in full units'),
21
+ type: MovementType.describe('expense | income'),
22
+ period: RecurringPeriod.describe('How often the rule fires'),
23
+ nextDue: IsoDate.describe('Next date this rule should materialize a transaction'),
24
+ currency: CurrencyCode.describe('Currency for materialized transactions'),
25
+ accountId: Id.optional().describe('Target account for materialized transactions'),
26
+ categoryId: Id.optional().describe('Category for materialized transactions'),
27
+ merchantKey: z.string().min(1).optional().describe('Normalized merchant key this rule pays, if known'),
28
+ });
29
+ export const RECURRING_ENTITY_TAG = 'recurring';
30
+ // Never sent over the wire — kept off `RecurringRuleSchema`/`RecurringRuleViewSchema` the same way
31
+ // `AccountEntitySchema` stays off `AccountSchema`.
32
+ export const RecurringRuleEntitySchema = withPersistenceMeta(RecurringRuleSchema);
33
+ export const RecurringRuleViewSchema = RecurringRuleSchema.extend({
34
+ periodLabel: z.string().optional().describe('Localized period label'),
35
+ accountName: z.string().optional().describe('Resolved account name'),
36
+ categoryName: z.string().optional().describe('Resolved category name'),
37
+ });
38
+ export const CreateRecurringSchema = z.object({
39
+ description: z.string().min(1).describe('What this rule pays for (rent, salary, subscription…)'),
40
+ amount: Money.describe('Recurring amount in full units'),
41
+ type: MovementType.describe('expense | income'),
42
+ period: RecurringPeriod.describe('How often the rule fires'),
43
+ startDate: IsoDate.describe('First due date (YYYY-MM-DD)'),
44
+ account: z.string().optional().describe('Account name (resolved by name match)'),
45
+ category: z.string().optional().describe('Category name (resolved by name match)'),
46
+ currency: CurrencyCode.optional().describe('Currency (resolved from account if omitted)'),
47
+ merchant: z
48
+ .string()
49
+ .min(1)
50
+ .optional()
51
+ .describe('Merchant this rule pays (e.g. "Netflix", the landlord) — normalized the same way as a ' +
52
+ 'transaction description; omit to derive it from `description` instead'),
53
+ });
54
+ export const MAX_RECURRING_OCCURRENCES_PER_RUN = 36;
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The domain operation a caller should use instead of the one that was rejected. A domain error carries the operation's
4
+ * name — never an edge's word for it (a tool, a route, a command): each edge translates a remedy into its own
5
+ * vocabulary (`diplomat/mcp/remedy.ts`, `diplomat/http/remedy.ts`).
6
+ */
7
+ export const Remedy = z.enum([
8
+ 'pay_bill',
9
+ 'revert_bill_payment',
10
+ 'create_credit_card',
11
+ 'update_credit_card',
12
+ 'delete_credit_card',
13
+ 'update_account_transaction',
14
+ 'update_card_transaction',
15
+ 'delete_account_transaction',
16
+ 'delete_card_transaction',
17
+ ]);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { databaseAheadMessage, DatabaseAheadCode } from './database.js';
2
+ import { demoNotReadyMessage, DemoNotReadyCode } from './demo/core.js';
3
+ const MESSAGES = {
4
+ [DatabaseAheadCode.enum.database_ahead]: ({ version }) => databaseAheadMessage(version),
5
+ [DemoNotReadyCode.enum.demo_not_ready]: demoNotReadyMessage,
6
+ };
7
+ export const startupRefusalMessage = (refusal) => MESSAGES[refusal.code](refusal);
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ import { CurrencyCode } from './money.js';
3
+ import { MovementType } from './transaction.js';
4
+ export const SummaryRowSchema = z.object({
5
+ currency: CurrencyCode,
6
+ type: MovementType,
7
+ category: z.string().nullable(),
8
+ categoryNames: z.record(z.string(), z.string()).nullable(),
9
+ total: z.number(),
10
+ count: z.number().int(),
11
+ });
12
+ export const CategoryTotalSchema = z.object({
13
+ category: z.string(),
14
+ type: MovementType,
15
+ total: z.number(),
16
+ count: z.number().int(),
17
+ });
18
+ export const CurrencySummarySchema = z.object({
19
+ currency: CurrencyCode,
20
+ income: z.number(),
21
+ expenses: z.number(),
22
+ balance: z.number(),
23
+ byCategory: z.array(CategoryTotalSchema),
24
+ });
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod';
2
+ import { Id } from './id.js';
3
+ import { withPersistenceMeta } from '@rfc0/effect-runner';
4
+ export const TagSchema = z.object({
5
+ id: Id.describe('Unique tag identifier'),
6
+ name: z.string().min(1).describe('Tag display name'),
7
+ });
8
+ // Entity tag for this aggregate's `Persistable`s.
9
+ export const TAG_ENTITY_TAG = 'tag';
10
+ // `Tag` plus the optimistic-concurrency `version` token. Never sent over the wire.
11
+ export const TagEntitySchema = withPersistenceMeta(TagSchema);
12
+ export const tagErrors = {
13
+ duplicateName: (name) => ({ code: 'duplicate_name', entity: 'tag', name }),
14
+ };
@@ -0,0 +1,10 @@
1
+ import { CURRENCY_RATE_ENTITY_TAG } from './currency-rate.js';
2
+ import { validation } from './error.js';
3
+ /** The one message every attempt to change a shared default answers with. */
4
+ export const SHARED_DEFAULT_READ_ONLY_MESSAGE = "Default categories and dashboards are shared by every user and can't be changed or deleted. " +
5
+ 'Create your own instead (a dashboard saved under a default’s name replaces it for you alone).';
6
+ export const sharedDefaultErrors = {
7
+ readOnly: validation([SHARED_DEFAULT_READ_ONLY_MESSAGE]),
8
+ };
9
+ /** Entities every user sees (rates move everyone's valuations): any user's change to them is heard by all. */
10
+ export const SHARED_ENTITY_TAGS = [CURRENCY_RATE_ENTITY_TAG];
@@ -0,0 +1,6 @@
1
+ /** No `id`/`version` — a link table like `merchant_category`. `transactionId` is the flow's own
2
+ * `entity.id`: the minted id on a create, the read row's id on an update. On a
3
+ * duplicate-idempotency-key replay the minted id was never inserted, so the set addresses a row
4
+ * that doesn't exist and the applier no-ops — a duplicate replay never touches tags, matching the
5
+ * first-write-wins treatment the rest of the row already gets (ADR-023 step 3). */
6
+ export const TRANSACTION_TAG_ENTITY_TAG = 'transactionTag';