@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,58 @@
1
+ import { z } from 'zod';
2
+ import { withPersistenceMeta } from '@rfc0/effect-runner';
3
+ import { Id } from '../id.js';
4
+ import { Scope } from './scope.js';
5
+ import { CLIENT_NAME_MAX_LENGTH, CLIENT_VERSION_MAX_LENGTH, ProfileSchema } from './sign-in.js';
6
+ import { DAY_MS, HOUR_MS, MINUTE_MS } from './time.js';
7
+ import { TokenAccess } from './token.js';
8
+ /** How long a stdio sign-in lasts, chosen by the person who approves it. `session` is kept in the stdio process's
9
+ * memory only and never reaches the keychain; the others are saved. Counted absolutely from approval — use never
10
+ * extends it. */
11
+ export const SignInDuration = z.enum(['session', '24h', '7d', '30d']);
12
+ /** `patty login` runs in a shell that exits, so it has no "this session" to tie a sign-in to. */
13
+ export const LoginDuration = SignInDuration.exclude([SignInDuration.enum.session]);
14
+ export const DEFAULT_SIGN_IN_DURATION = SignInDuration.enum['24h'];
15
+ /** A "this session only" sign-in is revoked when its process exits; this cap covers a process that died instead. */
16
+ export const SESSION_SIGN_IN_CAP_MS = 12 * HOUR_MS;
17
+ export const SIGN_IN_DURATION_MS = {
18
+ session: SESSION_SIGN_IN_CAP_MS,
19
+ '24h': DAY_MS,
20
+ '7d': 7 * DAY_MS,
21
+ '30d': 30 * DAY_MS,
22
+ };
23
+ /** The longest any sign-in may last (an admin may lower it after ADR-033 Phase 4, never raise it). */
24
+ export const MAX_SIGN_IN_DURATION_MS = SIGN_IN_DURATION_MS['30d'];
25
+ /** The device-style grant: the stdio process (or `patty login`) asks, a person approves in the browser. */
26
+ export const GrantStatus = z.enum(['pending', 'approved', 'denied', 'redeemed', 'expired']);
27
+ /** Who asked: an MCP client over stdio, or `patty login` in a shell. Decides whether `session` is offered. */
28
+ export const GrantChannel = z.enum(['stdio', 'cli']);
29
+ export const CLIENT_GRANT_TTL_MS = 10 * MINUTE_MS;
30
+ /** A user code is 8 Crockford base32 symbols (40 bits), shown `XXXX-XXXX`. */
31
+ export const USER_CODE_LENGTH = 8;
32
+ /** A fresh user code colliding with a still-pending one is astronomically unlikely; this bounds the retry anyway. */
33
+ export const USER_CODE_ATTEMPTS = 5;
34
+ export const ClientGrantEntitySchema = withPersistenceMeta(z.object({
35
+ id: Id,
36
+ deviceCodeHash: z.string().describe('sha256 of the device code — the code itself lives only in the asking process'),
37
+ userCode: z.string().describe('Normalized (no dash, upper-case); shown as XXXX-XXXX'),
38
+ clientName: z.string().max(CLIENT_NAME_MAX_LENGTH),
39
+ clientVersion: z.string().max(CLIENT_VERSION_MAX_LENGTH),
40
+ profile: ProfileSchema,
41
+ channel: GrantChannel,
42
+ /** What the asker would like pre-selected on the consent page (`patty login --scope/--duration`). */
43
+ hintAccess: TokenAccess.nullable(),
44
+ hintDuration: SignInDuration.nullable(),
45
+ status: GrantStatus,
46
+ userId: Id.nullable().describe('The user who approved — null until approved'),
47
+ scopes: z.array(Scope).min(1).nullable(),
48
+ duration: SignInDuration.nullable(),
49
+ createdAt: z.string(),
50
+ approvedAt: z.string().nullable(),
51
+ expiresAt: z.string(),
52
+ }));
53
+ /** What redeeming a device code answers. Only `signed_in` carries the (one-time) plaintext token. */
54
+ export const RedeemKind = z.enum(['pending', 'denied', 'expired', 'invalid', 'signed_in']);
55
+ /** What `logic/auth/grant.ts`'s `redeemPlan` decides before anything is written: the four non-minting answers, or
56
+ * `mint`. */
57
+ export const RedeemPlanKind = z.enum(['pending', 'denied', 'expired', 'invalid', 'mint']);
58
+ export const INVALID_REDEEM = { kind: RedeemPlanKind.enum.invalid };
@@ -0,0 +1,11 @@
1
+ /** The pause after a wrong administrator answer before the next prompt: each attempt already costs a full password
2
+ * check, and this keeps a script driving a terminal from trying faster than a person could. */
3
+ export const STEP_UP_RETRY_DELAY_MS = 1000;
4
+ /** The one answer that confirms writing the key file; anything else cancels. */
5
+ export const KEY_EXPORT_CONFIRMATION_ANSWER = 'yes';
6
+ /** The database could not be read to check an administrator. Says why; never carries a key or a hash. */
7
+ export const USERS_UNREADABLE_CODE = 'users_unreadable';
8
+ export const usersUnreadable = (reason) => ({ code: USERS_UNREADABLE_CODE, reason });
9
+ /** The person looked at the warning and did not confirm. */
10
+ export const EXPORT_DECLINED_CODE = 'export_declined';
11
+ export const EXPORT_DECLINED = { code: EXPORT_DECLINED_CODE };
@@ -0,0 +1,50 @@
1
+ import { NPX_COMMAND, PRODUCT_NAME } from '../package.js';
2
+ import { TOKEN_ENV_VAR } from './sign-in.js';
3
+ /** The terminal route to the same owner claim as `/ui/setup` — shown wherever the setup code is. */
4
+ export const TERMINAL_SETUP_COMMAND = `${NPX_COMMAND} auth setup`;
5
+ export const TERMINAL_SETUP_HINT = `or run \`${TERMINAL_SETUP_COMMAND}\` in a terminal`;
6
+ export const AUTH_MESSAGES = {
7
+ invalidCredentials: 'Invalid username or password.',
8
+ invalidSetupCode: `That setup code is not valid or has expired. Restart ${PRODUCT_NAME} to get a new one.`,
9
+ setupUnavailable: 'Setup has already been completed. Log in instead.',
10
+ unknownUser: 'No such user.',
11
+ ownerUnclaimed: `The owner has no login yet. Run \`${TERMINAL_SETUP_COMMAND}\` first.`,
12
+ rateLimited: 'Too many attempts. Wait a few minutes and try again.',
13
+ unauthenticated: 'Authentication required.',
14
+ crossOrigin: 'Cross-origin request rejected.',
15
+ crossOriginUnknownOrigin: "Cross-origin check could not determine this instance's own origin — set PUBLIC_URL to its external URL.",
16
+ tryAgain: 'Could not complete the request. Try again.',
17
+ invalidToken: 'The access token is invalid, expired or revoked.',
18
+ invalidPassword: 'That password is not correct.',
19
+ insufficientScope: 'The access token does not grant the scope this operation needs.',
20
+ unknownToken: 'No such access token.',
21
+ sessionRequired: 'Access tokens can only be managed from a signed-in browser session.',
22
+ invalidGrant: 'This sign-in request is not valid, has expired, or was already answered.',
23
+ adminRequired: 'Only an administrator can manage users.',
24
+ usernameTaken: 'That username is already taken.',
25
+ cannotChangeSelf: 'You cannot disable or demote yourself. Ask another administrator.',
26
+ lastAdmin: 'That would leave the instance without an active administrator.',
27
+ invalidInvite: 'That invite is not valid, has expired, or was already used. Ask an administrator for a new one.',
28
+ userDisabled: 'That user is disabled. Enable them first.',
29
+ prmNeedsOrigin: 'This instance cannot say what its own origin is — set PUBLIC_URL to its external URL to publish its ' +
30
+ 'Protected Resource Metadata.',
31
+ nonLoopbackRequest: `Request host/origin is not loopback — ${PRODUCT_NAME} without authentication only answers 127.0.0.1, localhost or ` +
32
+ '::1. To use another hostname, set PUBLIC_URL (which turns authentication on).',
33
+ };
34
+ /** The headings of the user-management result pages. */
35
+ export const USER_PAGE_HEADINGS = { inviteCreated: 'Invite created', newInvite: 'New invite' };
36
+ export const HTTP_ENV_VAR = 'PATTY_HTTP';
37
+ /** What a stdio session says when it cannot act as anyone (ADR-034 §2). One template per situation, built here so
38
+ * the wording — and the pinned command in it — exists once. None of them may carry a secret: the link holds the
39
+ * user code only, and a rejected `PATTY_TOKEN` is never echoed. */
40
+ const SIGN_IN_PREFIX = `${PRODUCT_NAME}:`;
41
+ export const STDIO_MESSAGES = {
42
+ notSignedIn: (connectUrl, userCode) => `${SIGN_IN_PREFIX} not signed in. Open ${connectUrl} and confirm the code ${userCode}.`,
43
+ notSignedInWithoutHttp: `${SIGN_IN_PREFIX} not signed in. The browser sign-in needs the HTTP dashboard (${HTTP_ENV_VAR}=false here): run ` +
44
+ `\`${NPX_COMMAND} login\` in a terminal, or set ${TOKEN_ENV_VAR} in this client's environment.`,
45
+ ownerUnclaimedHint: ` Owner not set up yet? Run \`${NPX_COMMAND} auth setup\`.`,
46
+ invalidEnvToken: `${SIGN_IN_PREFIX} ${TOKEN_ENV_VAR} is not a valid access token (malformed, expired or revoked). Create a new one on ` +
47
+ `the Access page of the dashboard, or remove ${TOKEN_ENV_VAR} from this client's environment to sign in with ` +
48
+ `the browser instead.`,
49
+ cannotVerify: `${SIGN_IN_PREFIX} could not check the sign-in just now. Try again.`,
50
+ };
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ /** Whether the HTTP surface demands a session. `disabled` is an explicit, loopback-only opt-out. */
3
+ export const AuthMode = z.enum(['required', 'disabled']);
4
+ /** What `PATTY_AUTH` means when unset — on every surface, loopback included. */
5
+ export const DEFAULT_AUTH_MODE = AuthMode.enum.required;
6
+ /** The environment variable that sets it. */
7
+ export const AUTH_ENV_VAR = 'PATTY_AUTH';
@@ -0,0 +1,16 @@
1
+ import { READ_METHODS } from './scope.js';
2
+ /** The browser surface's root path — redirects are validated against it and `diplomat/http` mounts on it. */
3
+ export const UI_ROOT_PATH = '/ui';
4
+ export const isUiPath = (path) => path === UI_ROOT_PATH || path.startsWith(`${UI_ROOT_PATH}/`);
5
+ export const SAFE_METHODS = new Set([...READ_METHODS, 'OPTIONS']);
6
+ export const OPAQUE_ORIGIN = 'null';
7
+ export const WEB_PROTOCOLS = new Set(['http:', 'https:']);
8
+ /** Where a login or setup lands when the caller named no (valid) destination. */
9
+ export const DEFAULT_LANDING_PATH = UI_ROOT_PATH;
10
+ /** The connect page: a one-segment path under `/ui`, reached from a link the stdio process prints. */
11
+ export const CONNECT_PATH = `${UI_ROOT_PATH}/connect`;
12
+ export const CONNECT_CODE_PARAM = 'code';
13
+ export const CONNECT_PASSWORD_PARAM = 'password';
14
+ /** The invite page: the link an admin hands a new user, `…/ui/access/invite?code=…`; the code may also be typed in. */
15
+ export const INVITE_PATH = `${UI_ROOT_PATH}/access/invite`;
16
+ export const INVITE_CODE_PARAM = 'code';
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ import { withPersistenceMeta } from '@rfc0/effect-runner';
3
+ import { Id } from '../id.js';
4
+ import { MINUTE_MS } from './time.js';
5
+ export const UserRole = z.enum(['admin', 'member']);
6
+ /** The owner is inserted by migration on every database (ADR-033 §7) — this id must match the
7
+ * `INSERT` in `drizzle/0018_auth_identity.sql`; `test/integration/db/owner-migration.test.ts` pins it. */
8
+ export const OWNER_USER_ID = 'user-owner';
9
+ /** There is at most ONE setup code: issuing replaces it in place (ADR-033 §2), so concurrent starters can
10
+ * never leave two valid codes — the loser of the race retries into an update. */
11
+ export const SETUP_CODE_ID = 'setup-code';
12
+ export const SETUP_CODE_TTL_MS = 30 * MINUTE_MS;
13
+ export const SETUP_CODE_GROUP_SIZE = 4;
14
+ export const SETUP_CODE_GROUP_SEPARATOR = '-';
15
+ export const NON_ALPHANUMERIC = /[^A-Za-z0-9]/g;
16
+ /** Persistence-side user. `username`/`passwordHash` stay null until the owner is claimed (§7). */
17
+ export const UserEntitySchema = withPersistenceMeta(z.object({
18
+ id: Id,
19
+ username: z.string().nullable().describe('Normalized (trimmed, lower-cased) login name'),
20
+ passwordHash: z.string().nullable().describe('argon2id PHC string'),
21
+ role: UserRole,
22
+ createdAt: z.string(),
23
+ disabledAt: z.string().nullable(),
24
+ lastLoginAt: z.string().nullable().describe('When this user last started a session — null until their first login'),
25
+ credentialsChangedAt: z
26
+ .string()
27
+ .nullable()
28
+ .describe('When this user’s set of ways in last changed — a credential was issued or ended; null if never'),
29
+ }));
30
+ export const SetupCodeEntitySchema = withPersistenceMeta(z.object({
31
+ id: Id,
32
+ codeHash: z.string().describe('sha256 of the setup code — the code itself is never stored'),
33
+ createdAt: z.string(),
34
+ expiresAt: z.string(),
35
+ usedAt: z.string().nullable(),
36
+ }));
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ export const PASSWORD_MIN_LENGTH = 12;
3
+ // Argon2 caps nothing, but an unbounded body is a CPU/memory lever for anyone who can reach /ui/login.
4
+ export const PASSWORD_MAX_LENGTH = 1024;
5
+ export const USERNAME_MIN_LENGTH = 3;
6
+ export const USERNAME_MAX_LENGTH = 64;
7
+ const USERNAME_PATTERN = /^[\p{L}\p{N}._@+-]+$/u;
8
+ export const PasswordSchema = z
9
+ .string()
10
+ .min(PASSWORD_MIN_LENGTH, `password must be at least ${PASSWORD_MIN_LENGTH} characters`)
11
+ .max(PASSWORD_MAX_LENGTH);
12
+ /** Stored form of a username — what makes the UNIQUE index case-insensitive. Every schema that accepts a
13
+ * username normalizes through it, so a `LoginInput`/`ClaimOwnerInput` reaching a controller already holds it. */
14
+ export const normalizeUsername = (raw) => raw.trim().normalize('NFKC').toLowerCase();
15
+ // Normalize FIRST, then validate the stored form: NFKC can expand a character (`ffi` → `ffi`), so checking the
16
+ // length of the raw input would let the schema emit a username longer than its own policy allows.
17
+ export const UsernameSchema = z
18
+ .string()
19
+ .transform(normalizeUsername)
20
+ .pipe(z
21
+ .string()
22
+ .min(USERNAME_MIN_LENGTH, `username must be at least ${USERNAME_MIN_LENGTH} characters`)
23
+ .max(USERNAME_MAX_LENGTH)
24
+ .regex(USERNAME_PATTERN, 'username may contain letters, digits and . _ @ + -'));
@@ -0,0 +1,26 @@
1
+ import { z } from 'zod';
2
+ import { Id } from '../id.js';
3
+ import { OWNER_USER_ID, UserRole } from './owner.js';
4
+ import { ALL_SCOPES, Scope } from './scope.js';
5
+ /** How a request authenticated, so the edge can tell a browser session from a bearer token from the trusted
6
+ * owner of an auth-disabled run, and a stdio sign-in (ADR-034) from either. */
7
+ export const PrincipalVia = z.enum(['session', 'token', 'owner', 'stdio']);
8
+ /** What a request acts as — resolved at the HTTP edge from the session or bearer token (or the owner, when
9
+ * auth is disabled or on stdio) and, from Phase 4, threaded into controllers as an explicit argument.
10
+ * A session and the owner hold every scope; a token holds the scopes it was minted with. */
11
+ export const PrincipalSchema = z.object({
12
+ userId: Id,
13
+ role: UserRole,
14
+ scopes: z.array(Scope),
15
+ via: PrincipalVia,
16
+ /** The access token this request presented — only when `via` is `token`. */
17
+ tokenId: Id.optional(),
18
+ /** The browser session this request presented — only when `via` is `session`. */
19
+ sessionId: Id.optional(),
20
+ });
21
+ export const OWNER_PRINCIPAL = {
22
+ userId: OWNER_USER_ID,
23
+ role: UserRole.enum.admin,
24
+ scopes: [...ALL_SCOPES],
25
+ via: PrincipalVia.enum.owner,
26
+ };
@@ -0,0 +1,4 @@
1
+ import { INVITE_CODE_PARAM } from './origin.js';
2
+ export const SECRET_QUERY_PARAMS = [INVITE_CODE_PARAM];
3
+ export const REDACTED = '[Redacted]';
4
+ export const NAME_VALUE_SEPARATOR = '=';
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+ /** What a credential may do (ADR-033 §3). `patty:write` implies `patty:read` — see `logic/auth/scope.ts`'s
3
+ * `hasScope`. The values are the OAuth scope strings clients see in challenges and metadata. */
4
+ export const Scope = z.enum(['patty:read', 'patty:write']);
5
+ export const ALL_SCOPES = Scope.options;
6
+ export const READ_SCOPE = Scope.enum['patty:read'];
7
+ export const WRITE_SCOPE = Scope.enum['patty:write'];
8
+ export const READ_METHODS = ['GET', 'HEAD'];
9
+ export const MCP_TOOLS_CALL_METHOD = 'tools/call';
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { withPersistenceMeta } from '@rfc0/effect-runner';
3
+ import { Id } from '../id.js';
4
+ import { DAY_MS, MINUTE_MS } from './time.js';
5
+ /** A session dies after this long without being seen (sliding)… */
6
+ export const SESSION_IDLE_TTL_MS = DAY_MS;
7
+ /** `last_seen_at`/`expires_at` are rewritten at most this often — not on every request. */
8
+ export const SESSION_TOUCH_INTERVAL_MS = 5 * MINUTE_MS;
9
+ /** A session never outlives this, however active — also the browser cookie's lifetime (the server's sliding
10
+ * idle expiry decides validity; the cookie just must not expire before the server would). */
11
+ export const SESSION_ABSOLUTE_MAX_MS = 30 * DAY_MS;
12
+ export const SessionEntitySchema = withPersistenceMeta(z.object({
13
+ id: Id,
14
+ userId: Id,
15
+ tokenHash: z.string().describe('sha256 of the session token — the token itself is never stored'),
16
+ createdAt: z.string(),
17
+ lastSeenAt: z.string(),
18
+ expiresAt: z.string(),
19
+ }));
@@ -0,0 +1,102 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The sign-in protocol, as data (ADR-034): where a stdio session or a `patty login` stands (`SignInState`), what it
4
+ * has just learned (`SignInObservation`) and what the shell is asked to do about it (`SignInEffect`). The decisions are
5
+ * `logic/auth/sign-in-flow.ts`'s `nextStep`; `src/composition/sign-in/interpreter.ts` only executes effects and reports
6
+ * what happened.
7
+ */
8
+ export const SignInStateKind = z.enum(['idle', 'pending', 'signed_in', 'denied', 'expired', 'cancelled', 'failed']);
9
+ export const IDLE = { kind: SignInStateKind.enum.idle };
10
+ /** Where a credential came from: the environment, this process's memory, or the keychain. */
11
+ export const CredentialSource = z.enum(['env', 'held', 'saved']);
12
+ /** What looking a credential up came to: usable, rejected, or "could not tell" (the lookup itself failed). */
13
+ export const CheckKind = z.enum(['ok', 'invalid', 'failure']);
14
+ /** Redeeming a device code: what the controller answered, or the message of the error it failed with. */
15
+ export const REDEEM_ERROR_KIND = 'error';
16
+ /** Who is waiting on an answer: a gated request (`ask`) or a poll tick (`poll`) — a poll never asks again. */
17
+ export const Continuation = z.enum(['ask', 'poll']);
18
+ /** What a keychain lookup was for, and what to do once a guarded clear has run. */
19
+ export const LoadPurpose = z.enum(['resolve', 'logout']);
20
+ export const ClearNext = z.enum(['load_saved', 'ask', 'signed_out']);
21
+ /** Why a page is opened, why the owner is looked at, and why a credential is revoked. */
22
+ export const PagePurpose = z.enum(['login', 'new_request', 'instructions']);
23
+ export const OwnerPurpose = z.enum(['login', 'instructions']);
24
+ export const RevokeReason = z.enum(['keychain_refused', 'logout', 'close']);
25
+ export const ObservationKind = z.enum([
26
+ // Fed by an edge.
27
+ 'requested',
28
+ 'ticked',
29
+ 'login_requested',
30
+ 'logout_requested',
31
+ 'interrupted',
32
+ 'closed',
33
+ 'errored',
34
+ // The answer to an asking effect.
35
+ 'credential_checked',
36
+ 'saved_loaded',
37
+ 'saved_unreadable',
38
+ 'saved_cleared',
39
+ 'owner_checked',
40
+ 'page_named',
41
+ 'page_served',
42
+ 'grant_started',
43
+ 'grant_failed',
44
+ 'redeemed',
45
+ 'saved',
46
+ 'revoked',
47
+ ]);
48
+ export const EffectKind = z.enum([
49
+ // Asking: the shell reports one observation back.
50
+ 'check_credential',
51
+ 'load_saved',
52
+ 'clear_saved_if',
53
+ 'save_credential',
54
+ 'revoke_credential',
55
+ 'name_page',
56
+ 'serve_page',
57
+ 'start_grant',
58
+ 'redeem_grant',
59
+ 'check_owner',
60
+ // Telling: nothing comes back.
61
+ 'close_page',
62
+ 'wait',
63
+ 'present',
64
+ ]);
65
+ const E = EffectKind.enum;
66
+ /** The asking effects: a step ends with at most one of them, and it is the last. */
67
+ export const ASKING_EFFECT_KINDS = new Set([
68
+ E.check_credential,
69
+ E.load_saved,
70
+ E.clear_saved_if,
71
+ E.save_credential,
72
+ E.revoke_credential,
73
+ E.name_page,
74
+ E.serve_page,
75
+ E.start_grant,
76
+ E.redeem_grant,
77
+ E.check_owner,
78
+ ]);
79
+ export const PresentationKind = z.enum([
80
+ // A stdio request's answer.
81
+ 'granted',
82
+ 'invalid_env_token',
83
+ 'cannot_verify',
84
+ 'instructions',
85
+ // `patty login` / `logout`.
86
+ 'auth_disabled',
87
+ 'owner_unclaimed',
88
+ 'open',
89
+ 'waiting',
90
+ 'signed_in',
91
+ 'denied',
92
+ 'expired',
93
+ 'cancelled',
94
+ 'failed',
95
+ 'keychain_refused',
96
+ 'keychain_refused_still_active',
97
+ 'signed_out',
98
+ 'not_signed_in',
99
+ 'logout_failed',
100
+ 'keychain_unreadable',
101
+ ]);
102
+ export const CLOSE_PAGE = { kind: E.close_page };
@@ -0,0 +1,41 @@
1
+ import { z } from 'zod';
2
+ import { reasonOf } from '../error.js';
3
+ import { SECOND_MS } from './time.js';
4
+ /** How often a pending sign-in is checked for its approval. */
5
+ export const GRANT_POLL_INTERVAL_MS = 2 * SECOND_MS;
6
+ export const CLIENT_NAME_MAX_LENGTH = 80;
7
+ export const CLIENT_VERSION_MAX_LENGTH = 32;
8
+ export const PROFILE_MAX_LENGTH = 64;
9
+ export const DEFAULT_PROFILE = 'default';
10
+ export const UNKNOWN_CLIENT_NAME = 'Unknown MCP client';
11
+ export const UNKNOWN_CLIENT_VERSION = 'unknown';
12
+ export const CLI_CLIENT_NAME = 'patty login';
13
+ /** The consent page's wording for the memory-only duration: it names the client that asked, if it said who it was. */
14
+ export const SESSION_ONLY_LABEL = {
15
+ named: (clientName) => `This ${clientName} session only`,
16
+ unnamed: 'This session only',
17
+ };
18
+ /** `PATTY_PROFILE` names which saved sign-in a stdio process uses; it ends up in a keychain account name. */
19
+ export const ProfileSchema = z
20
+ .string()
21
+ .trim()
22
+ .min(1)
23
+ .max(PROFILE_MAX_LENGTH)
24
+ .regex(/^[A-Za-z0-9._-]+$/, 'profile may contain letters, digits and . _ -');
25
+ export const TOKEN_ENV_VAR = 'PATTY_TOKEN';
26
+ export const PROFILE_ENV_VAR = 'PATTY_PROFILE';
27
+ /** The OS keychain entry of a saved sign-in: service `patty` (shared with the database key), account
28
+ * `signin:<profile>:<dbId>` — `dbId` makes a development database and a production one keep apart. */
29
+ export const KEYCHAIN_SERVICE = 'patty';
30
+ export const DB_KEY_KEYCHAIN_ACCOUNT = 'db-encryption-key';
31
+ export const SIGN_IN_ACCOUNT_PREFIX = 'signin';
32
+ export const DB_ID_LENGTH = 12;
33
+ /** The OS keychain could not be read — as opposed to holding nothing. A locked or missing keychain must not look like
34
+ * "not signed in" to a command that is about to tell a person they are signed out. */
35
+ export const KeychainFailureCode = z.enum(['keychain_unavailable']);
36
+ export const keychainFailures = {
37
+ unavailable: (cause) => ({
38
+ code: KeychainFailureCode.enum.keychain_unavailable,
39
+ reason: reasonOf(cause),
40
+ }),
41
+ };
@@ -0,0 +1,5 @@
1
+ /** Millisecond units the auth lifetimes are written in. */
2
+ export const SECOND_MS = 1000;
3
+ export const MINUTE_MS = 60 * SECOND_MS;
4
+ export const HOUR_MS = 60 * MINUTE_MS;
5
+ export const DAY_MS = 24 * HOUR_MS;
@@ -0,0 +1,50 @@
1
+ import { z } from 'zod';
2
+ import { withPersistenceMeta } from '@rfc0/effect-runner';
3
+ import { Id } from '../id.js';
4
+ import { READ_SCOPE, Scope, WRITE_SCOPE } from './scope.js';
5
+ /** Every personal access token starts with this, so a leaked one is greppable (ADR-033 §3). */
6
+ export const TOKEN_PREFIX = 'ptk_';
7
+ /** How many characters of the random part are kept, in clear, to tell tokens apart in the list. */
8
+ export const TOKEN_DISPLAY_PREFIX_RANDOM_CHARS = 6;
9
+ export const TOKEN_NAME_MAX_LENGTH = 80;
10
+ /** The MCP `AuthInfo.clientId` of a request made with a personal access token: `pat:<token id>`. */
11
+ export const PAT_CLIENT_ID_PREFIX = 'pat:';
12
+ export const MAX_TOKEN_LENGTH = 256;
13
+ /** Expiry choices for a new token — there is no "never". A legacy row may still hold a null `expires_at`. */
14
+ export const TokenExpiry = z.enum(['30', '90', '365']);
15
+ /** What the token form preselects. */
16
+ export const DEFAULT_TOKEN_EXPIRY = TokenExpiry.enum['90'];
17
+ export const TOKEN_EXPIRY_DAYS = {
18
+ [TokenExpiry.enum['30']]: 30,
19
+ [TokenExpiry.enum['90']]: 90,
20
+ [TokenExpiry.enum['365']]: 365,
21
+ };
22
+ /** The two access levels the token form offers; `write` includes `read`. */
23
+ export const TokenAccess = z.enum(['read', 'write']);
24
+ export const TOKEN_ACCESS_SCOPES = {
25
+ [TokenAccess.enum.read]: [READ_SCOPE],
26
+ [TokenAccess.enum.write]: [READ_SCOPE, WRITE_SCOPE],
27
+ };
28
+ /** What minted an access token: a person at the token page (`pat`, ADR-033) or the stdio sign-in flow (`stdio`,
29
+ * ADR-034). Both are the same row, authenticated, listed and revoked the same way. */
30
+ export const AccessTokenKind = z.enum(['pat', 'stdio']);
31
+ /** A personal access token (ADR-033 §3) or a stdio sign-in (ADR-034 §3). Only `sha256(token)` and a display prefix
32
+ * are stored. */
33
+ export const AccessTokenEntitySchema = withPersistenceMeta(z.object({
34
+ id: Id,
35
+ userId: Id,
36
+ kind: AccessTokenKind,
37
+ /** The MCP client's self-reported name — a stdio sign-in only, `null` for a PAT. */
38
+ clientName: z.string().nullable(),
39
+ /** The `PATTY_PROFILE` this sign-in belongs to — a stdio sign-in only. */
40
+ profile: z.string().nullable(),
41
+ name: z.string().min(1).max(TOKEN_NAME_MAX_LENGTH),
42
+ tokenHash: z.string().describe('sha256 of the token — the token itself is never stored'),
43
+ prefix: z.string().describe('`ptk_` + the first characters of the random part, for display only'),
44
+ scopes: z.array(Scope).min(1),
45
+ createdAt: z.string(),
46
+ lastUsedAt: z.string().nullable(),
47
+ expiresAt: z.string().nullable(),
48
+ revokedAt: z.string().nullable(),
49
+ }));
50
+ export const TokenStatus = z.enum(['active', 'expired', 'revoked']);
@@ -0,0 +1,52 @@
1
+ import { z } from 'zod';
2
+ import { withPersistenceMeta } from '@rfc0/effect-runner';
3
+ import { Id } from '../id.js';
4
+ import { DemoCountry } from '../demo/core.js';
5
+ import { InstanceKind } from '../instance.js';
6
+ import { LoginDuration } from './grant.js';
7
+ import { HOUR_MS } from './time.js';
8
+ /** How long an invite link stays usable. After that an admin issues a new one. */
9
+ export const INVITE_TTL_HOURS = 72;
10
+ export const INVITE_TTL_MS = INVITE_TTL_HOURS * HOUR_MS;
11
+ /**
12
+ * The longest a stdio sign-in may last on this instance. Only the saved durations are offered as a cap: "this session
13
+ * only" is always shorter than any of them, so it is never above the cap.
14
+ */
15
+ export const SignInCap = LoginDuration;
16
+ export const DEFAULT_SIGN_IN_CAP = SignInCap.enum['30d'];
17
+ /** The `settings` table holds one instance-wide row. */
18
+ export const INSTANCE_SETTINGS_ID = 'singleton';
19
+ export const InstanceSettingsEntitySchema = withPersistenceMeta(z.object({
20
+ id: Id,
21
+ maxSignInDuration: SignInCap,
22
+ instanceKind: InstanceKind,
23
+ demoSeededAt: z.string().nullable(),
24
+ demoCountry: DemoCountry.nullable(),
25
+ }));
26
+ /** An invitation to claim one unclaimed user row. Only the code's sha256 is stored. */
27
+ export const InviteEntitySchema = withPersistenceMeta(z.object({
28
+ id: Id,
29
+ userId: Id.describe('The invited user: the row the claim updates'),
30
+ codeHash: z.string().describe('sha256 of the normalized invite code — the code itself is never stored'),
31
+ createdBy: Id.nullable().describe('The admin who issued it; null when the trusted terminal did'),
32
+ createdAt: z.string(),
33
+ expiresAt: z.string(),
34
+ usedAt: z.string().nullable(),
35
+ }));
36
+ /** The actions a row of the users page offers on one user: the last segment of each action's URL. */
37
+ export const UserAction = z.enum(['reissue', 'disable', 'enable', 'role']);
38
+ /** The actions that can take an active admin away. */
39
+ export const AdminChange = z.enum(['disable', 'demote', 'reissue']);
40
+ export const UserStatus = z.enum(['invited', 'active', 'disabled']);
41
+ /**
42
+ * Who is asking for a user-management action. A browser admin acts through a session (and re-types their password for
43
+ * the actions that ask for it); the terminal is the trusted local operator: it holds the database key, so it has no
44
+ * session, no user and no step-up.
45
+ */
46
+ export const ActorKind = z.enum(['terminal', 'session']);
47
+ export const CHANGE_BLOCKS_SELF = {
48
+ [AdminChange.enum.disable]: true,
49
+ [AdminChange.enum.demote]: true,
50
+ [AdminChange.enum.reissue]: false,
51
+ };
52
+ export const NO_REVOCATIONS = { sessionsEnded: 0, tokensRevoked: 0 };
@@ -0,0 +1,55 @@
1
+ import { z } from 'zod';
2
+ import { IsoDate } from './date.js';
3
+ import { Id } from './id.js';
4
+ import { withPersistenceMeta } from '@rfc0/effect-runner';
5
+ export const BillStatus = z.enum(['open', 'closed', 'paid']);
6
+ export const billStatusLabels = {
7
+ open: { en: 'Open', pt: 'Aberta', es: 'Abierta' },
8
+ closed: { en: 'Closed', pt: 'Fechada', es: 'Cerrada' },
9
+ paid: { en: 'Paid', pt: 'Paga', es: 'Pagada' },
10
+ };
11
+ // `.describe()` is domain information — it states what each field is and represents.
12
+ export const BillSchema = z.object({
13
+ id: Id,
14
+ month: z.number().int().min(1).max(12).describe('Billing cycle month (1–12)'),
15
+ year: z.number().int().min(2000).max(2100).describe('Billing cycle year'),
16
+ closeDate: IsoDate.describe('Date the billing cycle closes'),
17
+ dueDate: IsoDate.describe('Payment due date'),
18
+ status: BillStatus.describe('open | closed | paid'),
19
+ statusLabel: z.string().optional().describe('Localized status label'),
20
+ paymentTransactionId: Id.optional().describe('Id of the transfer transaction that paid this bill. Absent for open/closed bills, and for paid bills ' +
21
+ 'settled with a non-positive total (no transfer was created)'),
22
+ });
23
+ // Internal persistence-side entity: `Bill` plus `version` and the credit-card FK (neither on the
24
+ // wire — mirrors `models/account.ts`'s `AccountEntitySchema` split).
25
+ export const RawBillSchema = withPersistenceMeta(BillSchema).extend({
26
+ creditCardId: Id.describe('Owning credit card id; internal, never on wire/out'),
27
+ });
28
+ // Mirrors `models/account.ts`'s `ACCOUNT_ENTITY_TAG`.
29
+ export const BILL_ENTITY_TAG = 'bill';
30
+ export const BillQuerySchema = z.object({
31
+ card: z.string().min(1).describe('Credit card name'),
32
+ month: BillSchema.shape.month,
33
+ year: BillSchema.shape.year,
34
+ });
35
+ export const PayBillSchema = BillQuerySchema.extend({
36
+ account: z.string().min(1).optional().describe('Paying account name (overrides card default)'),
37
+ paymentDate: IsoDate.optional().describe('Date the payment occurred (defaults to today); must not be in the future'),
38
+ });
39
+ export const billErrors = {
40
+ notFound: (card, month, year) => ({
41
+ code: 'unknown_bill',
42
+ card,
43
+ month,
44
+ year,
45
+ }),
46
+ noPayingAccount: {
47
+ code: 'validation',
48
+ issues: ['no paying account: pass `account` or set `paymentAccount` on the card'],
49
+ },
50
+ futurePaymentDate: (date) => ({
51
+ code: 'validation',
52
+ issues: [`payment date ${date} is in the future: a bill payment records a payment that already occurred`],
53
+ }),
54
+ };
55
+ export const BILL_PAYMENT_KEY_PREFIX = 'billpay-';