@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.
- package/LICENSE +201 -0
- package/README.md +214 -2
- package/dist/adapters/access-tokens.js +7 -0
- package/dist/adapters/accounts.js +37 -0
- package/dist/adapters/auth.js +11 -0
- package/dist/adapters/bills.js +32 -0
- package/dist/adapters/budgets.js +29 -0
- package/dist/adapters/categories.js +32 -0
- package/dist/adapters/client-grants.js +7 -0
- package/dist/adapters/credit-cards.js +33 -0
- package/dist/adapters/currencies.js +2 -0
- package/dist/adapters/currency-rates.js +18 -0
- package/dist/adapters/dashboards.js +43 -0
- package/dist/adapters/demo.js +13 -0
- package/dist/adapters/instance-settings.js +7 -0
- package/dist/adapters/invites.js +7 -0
- package/dist/adapters/recurring.js +55 -0
- package/dist/adapters/sessions.js +7 -0
- package/dist/adapters/settings.js +4 -0
- package/dist/adapters/setup-codes.js +7 -0
- package/dist/adapters/tags.js +9 -0
- package/dist/adapters/transactions.js +95 -0
- package/dist/adapters/users.js +7 -0
- package/dist/common/build-version.js +5 -0
- package/dist/common/errors.js +118 -0
- package/dist/common/net.js +71 -0
- package/dist/common/result.js +7 -0
- package/dist/composition/auth.js +106 -0
- package/dist/composition/boot.js +27 -0
- package/dist/composition/cli.js +86 -0
- package/dist/composition/demo/seed.js +92 -0
- package/dist/composition/demo/shell.js +107 -0
- package/dist/composition/export.js +89 -0
- package/dist/composition/http.js +110 -0
- package/dist/composition/import.js +55 -0
- package/dist/composition/lazy-modules.js +2 -0
- package/dist/composition/runtime.js +115 -0
- package/dist/composition/sign-in/interpreter.js +154 -0
- package/dist/composition/sign-in/server.js +36 -0
- package/dist/composition/sign-in/wiring.js +23 -0
- package/dist/composition/stdio.js +69 -0
- package/dist/config.js +136 -0
- package/dist/controllers/account/account.js +88 -0
- package/dist/controllers/account/transaction.js +119 -0
- package/dist/controllers/account/transfer.js +34 -0
- package/dist/controllers/aggregate.js +40 -0
- package/dist/controllers/auth/access-tokens.js +61 -0
- package/dist/controllers/auth/grants.js +136 -0
- package/dist/controllers/auth/key-export.js +20 -0
- package/dist/controllers/auth/owner.js +80 -0
- package/dist/controllers/auth/password.js +35 -0
- package/dist/controllers/auth/session.js +50 -0
- package/dist/controllers/auth/step-up.js +8 -0
- package/dist/controllers/auth/users.js +183 -0
- package/dist/controllers/budgets.js +87 -0
- package/dist/controllers/categories.js +67 -0
- package/dist/controllers/correlations.js +112 -0
- package/dist/controllers/credit-card/bill.js +105 -0
- package/dist/controllers/credit-card/credit-card.js +129 -0
- package/dist/controllers/credit-card/transaction.js +181 -0
- package/dist/controllers/currencies.js +1 -0
- package/dist/controllers/currency-rates.js +40 -0
- package/dist/controllers/dashboards.js +68 -0
- package/dist/controllers/demo/seed.js +31 -0
- package/dist/controllers/demo/tour.js +12 -0
- package/dist/controllers/deps.js +6 -0
- package/dist/controllers/instance.js +6 -0
- package/dist/controllers/merchants.js +12 -0
- package/dist/controllers/recurring.js +70 -0
- package/dist/controllers/resolve.js +37 -0
- package/dist/controllers/settings.js +47 -0
- package/dist/controllers/status.js +19 -0
- package/dist/controllers/summary.js +21 -0
- package/dist/controllers/tags.js +19 -0
- package/dist/controllers/transaction/bulk.js +6 -0
- package/dist/controllers/transaction/core.js +49 -0
- package/dist/controllers/transaction/read.js +28 -0
- package/dist/diplomat/auth/credentials.js +58 -0
- package/dist/diplomat/auth/sign-in-store.js +18 -0
- package/dist/diplomat/cli/commands/auth.js +100 -0
- package/dist/diplomat/cli/commands/db.js +72 -0
- package/dist/diplomat/cli/commands/demo.js +68 -0
- package/dist/diplomat/cli/commands/key.js +119 -0
- package/dist/diplomat/cli/commands/login.js +151 -0
- package/dist/diplomat/cli/commands/setup.js +132 -0
- package/dist/diplomat/cli/commands/users.js +123 -0
- package/dist/diplomat/cli/commands.js +61 -0
- package/dist/diplomat/cli/export-file.js +37 -0
- package/dist/diplomat/cli/import-file.js +44 -0
- package/dist/diplomat/cli/io.js +61 -0
- package/dist/diplomat/cli/key-export-approval.js +37 -0
- package/dist/diplomat/cli/messages.js +96 -0
- package/dist/diplomat/cli/prompt.js +74 -0
- package/dist/diplomat/cli/terminal.js +81 -0
- package/dist/diplomat/client-config/clients.js +150 -0
- package/dist/diplomat/client-config/merge.js +41 -0
- package/dist/diplomat/db/bootstrap.js +98 -0
- package/dist/diplomat/db/database-files.js +147 -0
- package/dist/diplomat/db/driver.js +167 -0
- package/dist/diplomat/db/effects.js +101 -0
- package/dist/diplomat/db/engine.js +9 -0
- package/dist/diplomat/db/export.js +22 -0
- package/dist/diplomat/db/file-lock.js +82 -0
- package/dist/diplomat/db/key-lock.js +14 -0
- package/dist/diplomat/db/locale-cache.js +23 -0
- package/dist/diplomat/db/migration-barrier.js +57 -0
- package/dist/diplomat/db/migration-journal.js +18 -0
- package/dist/diplomat/db/migration-lock.js +15 -0
- package/dist/diplomat/db/migrations.js +11 -0
- package/dist/diplomat/db/present.js +17 -0
- package/dist/diplomat/db/queries/aggregate-whitelist.js +35 -0
- package/dist/diplomat/db/queries/filters.js +59 -0
- package/dist/diplomat/db/queries/fts.js +18 -0
- package/dist/diplomat/db/queries/scope.js +8 -0
- package/dist/diplomat/db/queries/transaction-select.js +26 -0
- package/dist/diplomat/db/queries/tx-predicates.js +13 -0
- package/dist/diplomat/db/repos/access-tokens.js +27 -0
- package/dist/diplomat/db/repos/accounts.js +91 -0
- package/dist/diplomat/db/repos/bills.js +93 -0
- package/dist/diplomat/db/repos/budgets.js +72 -0
- package/dist/diplomat/db/repos/categories.js +53 -0
- package/dist/diplomat/db/repos/client-grants.js +67 -0
- package/dist/diplomat/db/repos/correlations.js +66 -0
- package/dist/diplomat/db/repos/credit-cards.js +67 -0
- package/dist/diplomat/db/repos/currencies.js +8 -0
- package/dist/diplomat/db/repos/currency-rates.js +40 -0
- package/dist/diplomat/db/repos/dashboards.js +123 -0
- package/dist/diplomat/db/repos/health.js +12 -0
- package/dist/diplomat/db/repos/instance-settings.js +14 -0
- package/dist/diplomat/db/repos/instance.js +58 -0
- package/dist/diplomat/db/repos/invites.js +43 -0
- package/dist/diplomat/db/repos/merchants.js +121 -0
- package/dist/diplomat/db/repos/recurring.js +29 -0
- package/dist/diplomat/db/repos/sessions.js +19 -0
- package/dist/diplomat/db/repos/settings.js +41 -0
- package/dist/diplomat/db/repos/setup-codes.js +28 -0
- package/dist/diplomat/db/repos/sub-categories.js +67 -0
- package/dist/diplomat/db/repos/tags.js +51 -0
- package/dist/diplomat/db/repos/transaction-tags.js +57 -0
- package/dist/diplomat/db/repos/transactions.js +163 -0
- package/dist/diplomat/db/repos/users.js +47 -0
- package/dist/diplomat/db/safety-copy.js +87 -0
- package/dist/diplomat/db/schema.js +348 -0
- package/dist/diplomat/db/seed/categories.js +112 -0
- package/dist/diplomat/db/seed/currencies.js +9 -0
- package/dist/diplomat/db/seed/demo/br.js +98 -0
- package/dist/diplomat/db/seed/demo/co.js +89 -0
- package/dist/diplomat/db/seed/demo/index.js +12 -0
- package/dist/diplomat/db/seed/demo/mx.js +90 -0
- package/dist/diplomat/db/seed/demo/shared.js +39 -0
- package/dist/diplomat/db/seed/demo/us.js +90 -0
- package/dist/diplomat/db/seed/merchant-rules.js +188 -0
- package/dist/diplomat/db/sqlite-errors.js +40 -0
- package/dist/diplomat/db/tenancy-integrity.js +45 -0
- package/dist/diplomat/db/version-guard.js +16 -0
- package/dist/diplomat/http/auth-pages.js +41 -0
- package/dist/diplomat/http/auth-paths.js +46 -0
- package/dist/diplomat/http/bearer.js +15 -0
- package/dist/diplomat/http/connect-pages.js +51 -0
- package/dist/diplomat/http/context.js +17 -0
- package/dist/diplomat/http/cookies.js +27 -0
- package/dist/diplomat/http/form-pages.js +38 -0
- package/dist/diplomat/http/hooks/auth.js +106 -0
- package/dist/diplomat/http/hooks/demo-marker.js +59 -0
- package/dist/diplomat/http/openapi.js +73 -0
- package/dist/diplomat/http/principal.js +1 -0
- package/dist/diplomat/http/rate-limiter.js +78 -0
- package/dist/diplomat/http/remedy.js +26 -0
- package/dist/diplomat/http/respond.js +50 -0
- package/dist/diplomat/http/routes/account.js +226 -0
- package/dist/diplomat/http/routes/aggregate.js +28 -0
- package/dist/diplomat/http/routes/auth.js +105 -0
- package/dist/diplomat/http/routes/budget.js +34 -0
- package/dist/diplomat/http/routes/category.js +109 -0
- package/dist/diplomat/http/routes/connect.js +124 -0
- package/dist/diplomat/http/routes/credit-card.js +263 -0
- package/dist/diplomat/http/routes/currency-rates.js +60 -0
- package/dist/diplomat/http/routes/currency.js +16 -0
- package/dist/diplomat/http/routes/dashboard.js +93 -0
- package/dist/diplomat/http/routes/invite.js +63 -0
- package/dist/diplomat/http/routes/recurring.js +65 -0
- package/dist/diplomat/http/routes/settings.js +38 -0
- package/dist/diplomat/http/routes/summary.js +23 -0
- package/dist/diplomat/http/routes/system.js +29 -0
- package/dist/diplomat/http/routes/tag.js +51 -0
- package/dist/diplomat/http/routes/tokens.js +72 -0
- package/dist/diplomat/http/routes/transaction.js +55 -0
- package/dist/diplomat/http/routes/transfer.js +35 -0
- package/dist/diplomat/http/routes/ui.js +110 -0
- package/dist/diplomat/http/routes/users.js +156 -0
- package/dist/diplomat/http/routes/well-known.js +26 -0
- package/dist/diplomat/http/routes.js +85 -0
- package/dist/diplomat/http/session.js +34 -0
- package/dist/diplomat/http/token-pages.js +75 -0
- package/dist/diplomat/http/ui-files.js +21 -0
- package/dist/diplomat/http/user-pages.js +93 -0
- package/dist/diplomat/mcp/annotations.js +8 -0
- package/dist/diplomat/mcp/auth-info.js +20 -0
- package/dist/diplomat/mcp/context.js +14 -0
- package/dist/diplomat/mcp/definition.js +3 -0
- package/dist/diplomat/mcp/gate.js +15 -0
- package/dist/diplomat/mcp/instructions.js +19 -0
- package/dist/diplomat/mcp/prompts.js +125 -0
- package/dist/diplomat/mcp/register.js +12 -0
- package/dist/diplomat/mcp/remedy.js +17 -0
- package/dist/diplomat/mcp/resources.js +93 -0
- package/dist/diplomat/mcp/respond.js +20 -0
- package/dist/diplomat/mcp/route.js +62 -0
- package/dist/diplomat/mcp/scopes.js +53 -0
- package/dist/diplomat/mcp/server.js +26 -0
- package/dist/diplomat/mcp/shared.js +5 -0
- package/dist/diplomat/mcp/stdio-session.js +94 -0
- package/dist/diplomat/mcp/stdio.js +23 -0
- package/dist/diplomat/mcp/tool-name.js +59 -0
- package/dist/diplomat/mcp/tools/account.js +218 -0
- package/dist/diplomat/mcp/tools/aggregate.js +32 -0
- package/dist/diplomat/mcp/tools/budget.js +99 -0
- package/dist/diplomat/mcp/tools/category.js +103 -0
- package/dist/diplomat/mcp/tools/correlations.js +70 -0
- package/dist/diplomat/mcp/tools/credit-card.js +239 -0
- package/dist/diplomat/mcp/tools/currency-rates.js +62 -0
- package/dist/diplomat/mcp/tools/dashboard.js +75 -0
- package/dist/diplomat/mcp/tools/index.js +31 -0
- package/dist/diplomat/mcp/tools/recurring.js +62 -0
- package/dist/diplomat/mcp/tools/summary.js +30 -0
- package/dist/diplomat/mcp/tools/system.js +83 -0
- package/dist/diplomat/mcp/tools/tag.js +48 -0
- package/dist/diplomat/mcp/tools/transaction.js +53 -0
- package/dist/diplomat/mcp/tools/transfer.js +28 -0
- package/dist/diplomat/mcp/tour.js +87 -0
- package/dist/logic/account.js +79 -0
- package/dist/logic/aggregate.js +37 -0
- package/dist/logic/auth/bearer.js +35 -0
- package/dist/logic/auth/grant.js +126 -0
- package/dist/logic/auth/key-export.js +10 -0
- package/dist/logic/auth/keychain.js +3 -0
- package/dist/logic/auth/message.js +22 -0
- package/dist/logic/auth/origin.js +57 -0
- package/dist/logic/auth/owner.js +22 -0
- package/dist/logic/auth/password.js +3 -0
- package/dist/logic/auth/redact.js +25 -0
- package/dist/logic/auth/revoke.js +28 -0
- package/dist/logic/auth/scope.js +17 -0
- package/dist/logic/auth/session.js +30 -0
- package/dist/logic/auth/sign-in-flow.js +305 -0
- package/dist/logic/auth/time.js +2 -0
- package/dist/logic/auth/token.js +74 -0
- package/dist/logic/auth/user-plans.js +84 -0
- package/dist/logic/auth/users.js +78 -0
- package/dist/logic/balance.js +2 -0
- package/dist/logic/bill.js +74 -0
- package/dist/logic/budget.js +78 -0
- package/dist/logic/category.js +37 -0
- package/dist/logic/classify.js +21 -0
- package/dist/logic/correlations.js +147 -0
- package/dist/logic/credit-card.js +2 -0
- package/dist/logic/currency-rate.js +69 -0
- package/dist/logic/dashboard.js +40 -0
- package/dist/logic/demo/database.js +30 -0
- package/dist/logic/demo/plan.js +308 -0
- package/dist/logic/demo/tour.js +33 -0
- package/dist/logic/export-destination.js +12 -0
- package/dist/logic/key-import.js +15 -0
- package/dist/logic/locale.js +5 -0
- package/dist/logic/localize.js +12 -0
- package/dist/logic/merchant.js +31 -0
- package/dist/logic/migration.js +1 -0
- package/dist/logic/money.js +12 -0
- package/dist/logic/period.js +45 -0
- package/dist/logic/persistence.js +48 -0
- package/dist/logic/recurring.js +51 -0
- package/dist/logic/resolve.js +44 -0
- package/dist/logic/summary.js +29 -0
- package/dist/logic/tag.js +13 -0
- package/dist/logic/transaction.js +197 -0
- package/dist/main.js +42 -0
- package/dist/models/account.js +197 -0
- package/dist/models/aggregate.js +61 -0
- package/dist/models/auth/bearer.js +11 -0
- package/dist/models/auth/entity.js +17 -0
- package/dist/models/auth/errors.js +42 -0
- package/dist/models/auth/grant.js +58 -0
- package/dist/models/auth/key-export.js +11 -0
- package/dist/models/auth/message.js +50 -0
- package/dist/models/auth/mode.js +7 -0
- package/dist/models/auth/origin.js +16 -0
- package/dist/models/auth/owner.js +36 -0
- package/dist/models/auth/password.js +24 -0
- package/dist/models/auth/principal.js +26 -0
- package/dist/models/auth/redact.js +4 -0
- package/dist/models/auth/scope.js +9 -0
- package/dist/models/auth/session.js +19 -0
- package/dist/models/auth/sign-in-flow.js +102 -0
- package/dist/models/auth/sign-in.js +41 -0
- package/dist/models/auth/time.js +5 -0
- package/dist/models/auth/token.js +50 -0
- package/dist/models/auth/users.js +52 -0
- package/dist/models/bill.js +55 -0
- package/dist/models/budget.js +106 -0
- package/dist/models/category.js +52 -0
- package/dist/models/client-config.js +18 -0
- package/dist/models/correlations.js +215 -0
- package/dist/models/credit-card.js +156 -0
- package/dist/models/currency-rate.js +83 -0
- package/dist/models/dashboard.js +54 -0
- package/dist/models/database.js +16 -0
- package/dist/models/date.js +8 -0
- package/dist/models/demo/core.js +58 -0
- package/dist/models/demo/tour.js +41 -0
- package/dist/models/encryption-key.js +2 -0
- package/dist/models/error.js +13 -0
- package/dist/models/export.js +9 -0
- package/dist/models/id.js +2 -0
- package/dist/models/instance.js +7 -0
- package/dist/models/key-import.js +6 -0
- package/dist/models/locale.js +25 -0
- package/dist/models/merchant.js +12 -0
- package/dist/models/money.js +14 -0
- package/dist/models/package.js +12 -0
- package/dist/models/page.js +56 -0
- package/dist/models/persistence.js +1 -0
- package/dist/models/prompts.js +5 -0
- package/dist/models/recurring.js +54 -0
- package/dist/models/remedy.js +17 -0
- package/dist/models/resolution.js +1 -0
- package/dist/models/startup.js +7 -0
- package/dist/models/summary.js +24 -0
- package/dist/models/tag.js +14 -0
- package/dist/models/tenancy.js +10 -0
- package/dist/models/transaction-tag.js +6 -0
- package/dist/models/transaction.js +275 -0
- package/dist/wire/db/access-tokens.js +1 -0
- package/dist/wire/db/accounts.js +7 -0
- package/dist/wire/db/aggregate.js +16 -0
- package/dist/wire/db/bills.js +14 -0
- package/dist/wire/db/budgets.js +33 -0
- package/dist/wire/db/categories.js +14 -0
- package/dist/wire/db/client-grants.js +1 -0
- package/dist/wire/db/correlations.js +49 -0
- package/dist/wire/db/credit-cards.js +1 -0
- package/dist/wire/db/currencies.js +1 -0
- package/dist/wire/db/currency-rates.js +1 -0
- package/dist/wire/db/dashboards.js +1 -0
- package/dist/wire/db/instance-settings.js +1 -0
- package/dist/wire/db/invites.js +1 -0
- package/dist/wire/db/merchants.js +18 -0
- package/dist/wire/db/recurring.js +19 -0
- package/dist/wire/db/sessions.js +1 -0
- package/dist/wire/db/settings.js +1 -0
- package/dist/wire/db/setup-codes.js +1 -0
- package/dist/wire/db/tags.js +1 -0
- package/dist/wire/db/tenancy.js +1 -0
- package/dist/wire/db/transactions.js +89 -0
- package/dist/wire/db/users.js +1 -0
- package/dist/wire/in/accounts.js +26 -0
- package/dist/wire/in/aggregate.js +10 -0
- package/dist/wire/in/auth.js +107 -0
- package/dist/wire/in/bills.js +11 -0
- package/dist/wire/in/budgets.js +11 -0
- package/dist/wire/in/categories.js +9 -0
- package/dist/wire/in/cli.js +106 -0
- package/dist/wire/in/coerce.js +6 -0
- package/dist/wire/in/common.js +17 -0
- package/dist/wire/in/credit-cards.js +16 -0
- package/dist/wire/in/currency-rates.js +8 -0
- package/dist/wire/in/period.js +7 -0
- package/dist/wire/in/recurring.js +6 -0
- package/dist/wire/in/settings.js +5 -0
- package/dist/wire/in/summary.js +5 -0
- package/dist/wire/in/tags.js +2 -0
- package/dist/wire/in/transactions.js +31 -0
- package/dist/wire/out/bills.js +9 -0
- package/dist/wire/out/budgets.js +10 -0
- package/dist/wire/out/client-config.js +2 -0
- package/dist/wire/out/common.js +4 -0
- package/dist/wire/out/credit-cards.js +15 -0
- package/dist/wire/out/currency-rates.js +11 -0
- package/dist/wire/out/errors.js +58 -0
- package/dist/wire/out/recurring.js +6 -0
- package/dist/wire/out/status.js +10 -0
- package/dist/wire/out/summary.js +9 -0
- package/dist/wire/out/transactions.js +52 -0
- package/drizzle/0000_futuristic_umar.sql +124 -0
- package/drizzle/0001_fts5_search.sql +23 -0
- package/drizzle/0002_rename_graph_to_history.sql +7 -0
- package/drizzle/0003_lyrical_hairball.sql +2 -0
- package/drizzle/0004_misty_ikaris.sql +7 -0
- package/drizzle/0005_credit-liability-accounts.sql +14 -0
- package/drizzle/0006_smart_aqueduct.sql +1 -0
- package/drizzle/0007_add_dashboards.sql +5 -0
- package/drizzle/0008_yummy_madripoor.sql +1 -0
- package/drizzle/0009_version_groundwork.sql +9 -0
- package/drizzle/0010_category_merchant_association_cascade.sql +16 -0
- package/drizzle/0011_dashboard_id_normalization.sql +16 -0
- package/drizzle/0012_hot_the_spike.sql +12 -0
- package/drizzle/0013_recurring_rules_merchant.sql +1 -0
- package/drizzle/0014_dashboard_source_discriminator.sql +17 -0
- package/drizzle/0015_currencies_decimals.sql +1 -0
- package/drizzle/0016_unusual_zaran.sql +13 -0
- package/drizzle/0017_premium_blur.sql +1 -0
- package/drizzle/0018_auth_identity.sql +39 -0
- package/drizzle/0019_access_tokens.sql +16 -0
- package/drizzle/0020_stdio_sign_in.sql +27 -0
- package/drizzle/0021_tenancy_data.sql +289 -0
- package/drizzle/0022_user_management.sql +17 -0
- package/drizzle/0023_instance_settings_row.sql +2 -0
- package/drizzle/0024_credentials_changed_at.sql +2 -0
- package/drizzle/0025_instance_kind.sql +2 -0
- package/drizzle/0026_demo_seeded_at.sql +2 -0
- package/drizzle/0027_demo_country.sql +2 -0
- package/drizzle/0028_reset_sign_ins.sql +2 -0
- package/drizzle/meta/0000_snapshot.json +894 -0
- package/drizzle/meta/0003_snapshot.json +910 -0
- package/drizzle/meta/0004_snapshot.json +951 -0
- package/drizzle/meta/0005_snapshot.json +991 -0
- package/drizzle/meta/0006_snapshot.json +998 -0
- package/drizzle/meta/0007_snapshot.json +1029 -0
- package/drizzle/meta/0008_snapshot.json +1049 -0
- package/drizzle/meta/0009_snapshot.json +1121 -0
- package/drizzle/meta/0010_snapshot.json +1121 -0
- package/drizzle/meta/0011_snapshot.json +1136 -0
- package/drizzle/meta/0012_snapshot.json +1227 -0
- package/drizzle/meta/0013_snapshot.json +1247 -0
- package/drizzle/meta/0014_snapshot.json +1267 -0
- package/drizzle/meta/0015_snapshot.json +1275 -0
- package/drizzle/meta/0016_snapshot.json +1371 -0
- package/drizzle/meta/0017_snapshot.json +1392 -0
- package/drizzle/meta/0018_snapshot.json +1603 -0
- package/drizzle/meta/0019_snapshot.json +1713 -0
- package/drizzle/meta/0020_snapshot.json +1904 -0
- package/drizzle/meta/0021_snapshot.json +2186 -0
- package/drizzle/meta/0022_snapshot.json +2311 -0
- package/drizzle/meta/0023_snapshot.json +2311 -0
- package/drizzle/meta/0024_snapshot.json +2318 -0
- package/drizzle/meta/0025_snapshot.json +2326 -0
- package/drizzle/meta/0026_snapshot.json +2333 -0
- package/drizzle/meta/0027_snapshot.json +2340 -0
- package/drizzle/meta/0028_snapshot.json +2340 -0
- package/drizzle/meta/_journal.json +209 -0
- package/package.json +106 -4
- package/skills/dashboard-building/SKILL.md +201 -0
- package/skills/patty-tour/SKILL.md +34 -0
- package/ui/app.css +758 -0
- package/ui/app.js +543 -0
- package/ui/connect-result.html +16 -0
- package/ui/connect.html +53 -0
- package/ui/dashboards/accounts.html +3189 -0
- package/ui/dashboards/budget.html +1734 -0
- package/ui/dashboards/cards.html +4032 -0
- package/ui/dashboards/categories.html +4694 -0
- package/ui/dashboards/comparative.html +2475 -0
- package/ui/dashboards/dashboards.html +839 -0
- package/ui/dashboards/overview.html +2405 -0
- package/ui/dashboards/pending.html +2973 -0
- package/ui/dashboards/projections.html +2528 -0
- package/ui/dashboards/tags.html +1365 -0
- package/ui/invite.html +44 -0
- package/ui/login.html +26 -0
- package/ui/money.js +175 -0
- package/ui/setup.html +29 -0
- package/ui/shell.html +96 -0
- package/ui/token-created.html +24 -0
- package/ui/tokens.html +58 -0
- package/ui/user-invited.html +27 -0
- package/ui/users.html +60 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { LocalizedNamesSchema } from './category.js';
|
|
3
|
+
import { IsoDate, PeriodSchema, RangeFrom, RangeTo } from './date.js';
|
|
4
|
+
import { Id } from './id.js';
|
|
5
|
+
import { CurrencyCode, Money } from './money.js';
|
|
6
|
+
import { cursorSchema, PageRequestSchema, SortDirection } from './page.js';
|
|
7
|
+
import { withPersistenceMeta } from '@rfc0/effect-runner';
|
|
8
|
+
import { validationWithRemedy } from './error.js';
|
|
9
|
+
import { Remedy } from './remedy.js';
|
|
10
|
+
/** Whether the transaction has cleared or is still expected. Default is date-aware when omitted. */
|
|
11
|
+
export const TransactionStatus = z.enum(['pending', 'effective']);
|
|
12
|
+
export const transactionStatusLabels = {
|
|
13
|
+
pending: { en: 'Pending', pt: 'Pendente', es: 'Pendiente' },
|
|
14
|
+
effective: { en: 'Effective', pt: 'Efetivada', es: 'Efectiva' },
|
|
15
|
+
};
|
|
16
|
+
/** 'transfer' moves value between accounts: FROM + TO edges, excluded from summaries. */
|
|
17
|
+
export const TransactionType = z.enum(['expense', 'income', 'transfer']);
|
|
18
|
+
export const transactionTypeLabels = {
|
|
19
|
+
expense: { en: 'Expense', pt: 'Despesa', es: 'Gasto' },
|
|
20
|
+
income: { en: 'Income', pt: 'Receita', es: 'Ingreso' },
|
|
21
|
+
transfer: { en: 'Transfer', pt: 'Transferência', es: 'Transferencia' },
|
|
22
|
+
};
|
|
23
|
+
/** Types accepted by add_card_purchase / add_account_expense / add_account_income /
|
|
24
|
+
* import_card_statement / import_account_statement — transfers go through create_transfer. */
|
|
25
|
+
export const MovementType = z.enum(['expense', 'income']);
|
|
26
|
+
export const ClassificationMethod = z.enum(['rule', 'history', 'user', 'none']);
|
|
27
|
+
export const ClassificationSchema = z.object({
|
|
28
|
+
method: ClassificationMethod,
|
|
29
|
+
confidence: z.number().min(0).max(1),
|
|
30
|
+
});
|
|
31
|
+
export const UNCLASSIFIED = { method: ClassificationMethod.enum.none, confidence: 0 };
|
|
32
|
+
export const TransactionSource = z.enum(['mcp', 'rest', 'import']);
|
|
33
|
+
/** search_transactions whitelisted sort fields (ADR-011/014): the only values diplomat/db's
|
|
34
|
+
* ORDER BY fragment map accepts — caller text never reaches SQL structure. */
|
|
35
|
+
export const TransactionSortField = z.enum(['date', 'amount']);
|
|
36
|
+
/** Structural shape only — `resolveCursorKey` (logic/transaction.ts) is what checks `key.value`
|
|
37
|
+
* is actually well-formed for its own `sort` field, alongside the sort/dir-match check it
|
|
38
|
+
* already does; that's a cross-field business rule, not a schema shape. */
|
|
39
|
+
export const TransactionCursorSchema = cursorSchema(TransactionSortField);
|
|
40
|
+
export const NOTE_MAX_LENGTH = 1000;
|
|
41
|
+
// Shared statement-import field descriptions (ADR-017 step 2) — both ImportCardStatementItemSchema
|
|
42
|
+
// (models/credit-card.ts) and ImportAccountStatementItemSchema/ImportCardStatementSchema/
|
|
43
|
+
// ImportAccountStatementSchema reuse these verbatim; named once here so the two aggregate schemas
|
|
44
|
+
// never copy-paste the same describe() text (code-quality.md "constants over literals").
|
|
45
|
+
export const STATEMENT_ITEMS_DESCRIPTION = 'Statement lines to import';
|
|
46
|
+
export const STATEMENT_RAW_INPUT_DESCRIPTION = 'The original pasted statement text';
|
|
47
|
+
// Shared by CreateTransactionSchema (below) and CreateTransferSchema (models/account.ts) — named
|
|
48
|
+
// once so the two never copy-paste the same describe() text (code-quality.md "constants over
|
|
49
|
+
// literals").
|
|
50
|
+
export const DISCRIMINATOR_DESCRIPTION = 'Distinguishes genuinely-separate transactions that would otherwise be identical (e.g. two identical purchases the same day)';
|
|
51
|
+
// `.describe()` is domain information — it states what each field is and represents.
|
|
52
|
+
// Defaults split by intent: integrity defaults (a value that must exist for the entity to be
|
|
53
|
+
// valid) live here; quality-of-life convenience defaults live at the wire boundary
|
|
54
|
+
// (see wire/in/transactions.ts), keeping the domain contract honest about what is required.
|
|
55
|
+
/** Domain entity: core node properties + edge refs handed to the persistence diplomat. */
|
|
56
|
+
export const TransactionSchema = z.object({
|
|
57
|
+
id: Id,
|
|
58
|
+
description: z.string().min(1).describe('What was paid/received'),
|
|
59
|
+
amount: Money.describe('Positive amount in full units (reais/dollars)'),
|
|
60
|
+
type: TransactionType,
|
|
61
|
+
status: TransactionStatus,
|
|
62
|
+
date: IsoDate.describe('Transaction date (YYYY-MM-DD)'),
|
|
63
|
+
currency: CurrencyCode.describe('Transaction currency (ISO code)'),
|
|
64
|
+
source: TransactionSource,
|
|
65
|
+
classification: ClassificationSchema,
|
|
66
|
+
rawInput: z.string().optional().describe('Original user phrasing, for audit'),
|
|
67
|
+
note: z
|
|
68
|
+
.string()
|
|
69
|
+
.min(1)
|
|
70
|
+
.max(NOTE_MAX_LENGTH)
|
|
71
|
+
.optional()
|
|
72
|
+
.describe('Free-form memo (observação) — distinct from description/rawInput/tags'),
|
|
73
|
+
refs: z.object({
|
|
74
|
+
accountId: Id.optional(),
|
|
75
|
+
toAccountId: Id.optional(),
|
|
76
|
+
cardId: Id.optional(),
|
|
77
|
+
billId: Id.optional(),
|
|
78
|
+
categoryId: Id.optional(),
|
|
79
|
+
subCategoryId: Id.optional(),
|
|
80
|
+
merchantKey: z.string().optional(),
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
// The transaction aggregate owns its own entity tag (ADR-021), mirroring `models/account.ts`'s
|
|
84
|
+
// `ACCOUNT_ENTITY_TAG` — `@rfc0/effect-runner`'s `Persistable` is generic over any entity's
|
|
85
|
+
// tag/model and never lists this constant itself.
|
|
86
|
+
export const TRANSACTION_ENTITY_TAG = 'transaction';
|
|
87
|
+
/** Read projection: Transaction with joined reference names (account, category, merchant, …). */
|
|
88
|
+
export const TransactionViewSchema = z.object({
|
|
89
|
+
id: Id,
|
|
90
|
+
description: z.string().min(1),
|
|
91
|
+
amount: Money,
|
|
92
|
+
type: TransactionType,
|
|
93
|
+
typeLabel: z.string().optional(),
|
|
94
|
+
status: TransactionStatus,
|
|
95
|
+
statusLabel: z.string().optional(),
|
|
96
|
+
date: IsoDate,
|
|
97
|
+
currency: CurrencyCode,
|
|
98
|
+
source: TransactionSource,
|
|
99
|
+
idempotencyKey: z.string().min(1),
|
|
100
|
+
classification: ClassificationSchema,
|
|
101
|
+
rawInput: z.string().optional(),
|
|
102
|
+
note: z.string().min(1).max(NOTE_MAX_LENGTH).optional(),
|
|
103
|
+
accountId: Id.optional(),
|
|
104
|
+
accountName: z.string().optional(),
|
|
105
|
+
/** Destination account — present only on type 'transfer'. */
|
|
106
|
+
toAccountId: Id.optional(),
|
|
107
|
+
toAccountName: z.string().optional(),
|
|
108
|
+
cardId: Id.optional(),
|
|
109
|
+
cardName: z.string().optional(),
|
|
110
|
+
/** The bill (fatura) this card transaction currently belongs to — absent for account transactions. */
|
|
111
|
+
billId: Id.optional(),
|
|
112
|
+
categoryId: Id.optional(),
|
|
113
|
+
categoryName: z.string().optional(),
|
|
114
|
+
subCategoryId: Id.optional(),
|
|
115
|
+
subCategoryName: z.string().optional(),
|
|
116
|
+
merchant: z.string().optional(),
|
|
117
|
+
tags: z.array(z.string().min(1)).default([]),
|
|
118
|
+
});
|
|
119
|
+
/** Internal projection carrying the raw localized-names maps from the DB, plus the optimistic-
|
|
120
|
+
* concurrency `version` token (ADR-021) an account-context update/delete reads before deciding
|
|
121
|
+
* its `Persistable`. Used only in the adapter→controller pipeline; stripped before serialization
|
|
122
|
+
* (`logic/transaction.ts`'s `addLocalizedLabels` drops both `*Names` and `version`). */
|
|
123
|
+
export const RawTransactionViewSchema = withPersistenceMeta(TransactionViewSchema).extend({
|
|
124
|
+
categoryNames: LocalizedNamesSchema.optional(),
|
|
125
|
+
subCategoryNames: LocalizedNamesSchema.optional(),
|
|
126
|
+
});
|
|
127
|
+
// ─── Input contracts ──────────────────────────────────────────
|
|
128
|
+
// Zod-first, types inferred. Wire derives from these (re-export / extend).
|
|
129
|
+
/**
|
|
130
|
+
* A category-or-subcategory-by-name selection — how a transaction create/update/search request
|
|
131
|
+
* references a category. Embedded (not the category/sub-category entities themselves, which live
|
|
132
|
+
* in models/category.ts).
|
|
133
|
+
*/
|
|
134
|
+
export const CategoryFieldsSchema = z.object({
|
|
135
|
+
category: z.string().min(1).optional().describe('Category name'),
|
|
136
|
+
subCategory: z.string().min(1).optional().describe('Sub-category name (implies its parent category)'),
|
|
137
|
+
});
|
|
138
|
+
/** Minimal shared movement vocabulary (ADR-019) — the transaction core's create input. Names no
|
|
139
|
+
* context field (`account`, `card`, `billMonth`/`billYear`): each aggregate `.extend`s this schema
|
|
140
|
+
* with its own vocabulary (`models/credit-card.ts`, `models/account.ts`) rather than the core
|
|
141
|
+
* carrying the union and aggregates `.omit`-ing what isn't theirs. */
|
|
142
|
+
export const CreateTransactionSchema = z.object({
|
|
143
|
+
description: z.string().min(1).describe('What was paid/received, e.g. "Uber para o aeroporto"'),
|
|
144
|
+
amount: Money.describe('Positive amount in full units (reais/dollars)'),
|
|
145
|
+
type: MovementType.describe('expense | income'),
|
|
146
|
+
status: TransactionStatus.optional().describe('Omit for date-aware default (future → pending, today/past → effective). ' +
|
|
147
|
+
'"effective" = cleared, counts in balances/summaries. ' +
|
|
148
|
+
'"pending" = expected, excluded until confirmed.'),
|
|
149
|
+
date: IsoDate.optional().describe('YYYY-MM-DD; defaults to today'),
|
|
150
|
+
// Spread first so a future CategoryFieldsSchema field is picked up here automatically; the
|
|
151
|
+
// explicit category/subCategory below override just the .describe() for this create context.
|
|
152
|
+
...CategoryFieldsSchema.shape,
|
|
153
|
+
category: CategoryFieldsSchema.shape.category.describe('Category name; omit to auto-classify. Must match transaction type kind'),
|
|
154
|
+
subCategory: CategoryFieldsSchema.shape.subCategory.describe('Sub-category name (implies its parent — do not set both)'),
|
|
155
|
+
currency: CurrencyCode.optional().describe('Transaction currency; resolved from account/card when omitted'),
|
|
156
|
+
discriminator: z.string().min(1).optional().describe(DISCRIMINATOR_DESCRIPTION),
|
|
157
|
+
rawInput: z.string().optional().describe('Original user phrasing, for audit'),
|
|
158
|
+
note: z.string().min(1).max(NOTE_MAX_LENGTH).optional().describe('Free-form memo (observação)'),
|
|
159
|
+
tags: z.array(z.string().min(1)).optional().describe('Labels to attach, e.g. ["work", "travel"]'),
|
|
160
|
+
});
|
|
161
|
+
/** Shared base for the aggregate-specific update tools (ADR-017), mirroring how
|
|
162
|
+
* CreateTransactionSchema is the minimal shared base for add_card_purchase/add_account_expense/
|
|
163
|
+
* add_account_income (ADR-019) — `UpdateCardTransactionSchema` (models/credit-card.ts) and
|
|
164
|
+
* `UpdateAccountTransactionSchema` (models/account.ts) `.extend` this one with their own context
|
|
165
|
+
* fields (`billMonth`/`billYear`, `account`), rather than this schema carrying them for the
|
|
166
|
+
* aggregates to `.omit`. */
|
|
167
|
+
export const UpdateTransactionSchema = z.object({
|
|
168
|
+
id: z.string().min(1).describe('Transaction id'),
|
|
169
|
+
description: z.string().min(1).optional().describe('Updated description'),
|
|
170
|
+
amount: Money.optional().describe('Updated amount in full units'),
|
|
171
|
+
type: MovementType.optional().describe('Updated movement type'),
|
|
172
|
+
date: IsoDate.optional().describe('Updated date (YYYY-MM-DD)'),
|
|
173
|
+
...CategoryFieldsSchema.shape,
|
|
174
|
+
category: CategoryFieldsSchema.shape.category.describe('New category name (user correction). Do not set with subCategory'),
|
|
175
|
+
subCategory: CategoryFieldsSchema.shape.subCategory.describe('New sub-category name (implies parent; do not set with category)'),
|
|
176
|
+
note: z
|
|
177
|
+
.string()
|
|
178
|
+
.max(NOTE_MAX_LENGTH)
|
|
179
|
+
.optional()
|
|
180
|
+
.describe('Free-form memo. Empty string clears; omit to leave unchanged'),
|
|
181
|
+
tags: z
|
|
182
|
+
.array(z.string().min(1))
|
|
183
|
+
.optional()
|
|
184
|
+
.describe('Replaces the full tag set when provided; pass [] to remove all'),
|
|
185
|
+
});
|
|
186
|
+
/** Confirm input: flips a `pending` transaction to `effective`, optionally correcting `amount`/
|
|
187
|
+
* `date` in the same call — the only edit surface confirm exposes (reclassifying stays
|
|
188
|
+
* `update_*`'s job). Both fields are rejected on a transfer/bill-payment (`isTransfer`,
|
|
189
|
+
* `logic/transaction.ts`); a plain status-only confirm of one is still fine. */
|
|
190
|
+
export const ConfirmTransactionSchema = z.object({
|
|
191
|
+
id: z.string().min(1).describe('Transaction id (from search_transactions with status: "pending")'),
|
|
192
|
+
amount: Money.optional().describe('Corrected amount, applied together with the confirm — account/card movements only, rejected for a transfer/bill-payment'),
|
|
193
|
+
date: IsoDate.optional().describe('Corrected date (YYYY-MM-DD), applied together with the confirm — account/card movements only, rejected for a ' +
|
|
194
|
+
'transfer/bill-payment; the resolved date (this, or the existing date if omitted) must not be in the future'),
|
|
195
|
+
});
|
|
196
|
+
/** Delete input shape (ADR-017): identical for the card and account transaction deletes
|
|
197
|
+
* — delete carries zero aggregate-specific data, so unlike update it has no per-aggregate variant. */
|
|
198
|
+
export const DeleteTransactionSchema = z.object({
|
|
199
|
+
id: z.string().min(1).describe('Transaction id'),
|
|
200
|
+
confirm: z.boolean().default(false).describe('Must be true to actually delete'),
|
|
201
|
+
});
|
|
202
|
+
export const SearchTransactionsSchema = z.object({
|
|
203
|
+
month: PeriodSchema.shape.month.describe('Filter by month (1-12), with year — alternative to from/to').optional(),
|
|
204
|
+
year: PeriodSchema.shape.year.describe('Filter by year, with month — alternative to from/to').optional(),
|
|
205
|
+
from: RangeFrom,
|
|
206
|
+
to: RangeTo,
|
|
207
|
+
type: TransactionType.optional().describe('Filter by type (expense/income/transfer)'),
|
|
208
|
+
status: TransactionStatus.optional().describe('"pending" to list scheduled transactions; omit for all'),
|
|
209
|
+
...CategoryFieldsSchema.shape,
|
|
210
|
+
category: CategoryFieldsSchema.shape.category.describe('Filter by category name'),
|
|
211
|
+
subCategory: CategoryFieldsSchema.shape.subCategory.describe('Filter to transactions with this sub-category'),
|
|
212
|
+
account: z.string().min(1).optional().describe('Filter by account name'),
|
|
213
|
+
text: z.string().optional().describe('Free-text search in description'),
|
|
214
|
+
tags: z.array(z.string().min(1)).optional().describe('Filter to transactions having any of these tags'),
|
|
215
|
+
...PageRequestSchema.shape,
|
|
216
|
+
sort: TransactionSortField.describe('Field to sort by: date or amount. Default: date'),
|
|
217
|
+
dir: SortDirection.describe('Sort direction: asc or desc. Default: desc'),
|
|
218
|
+
});
|
|
219
|
+
/** A CategoryFields name resolved to ids — categoryId is always the top-level category's id. */
|
|
220
|
+
export const CategorySelectionSchema = z.object({
|
|
221
|
+
categoryId: Id.describe("Resolved category id (the sub-category's parent id, when a sub-category was resolved)"),
|
|
222
|
+
categoryName: z.string().min(1).describe('Resolved category display name'),
|
|
223
|
+
subCategoryId: Id.optional().describe('Resolved sub-category id, present only when a sub-category was selected'),
|
|
224
|
+
});
|
|
225
|
+
/** Shared by every aggregate's delete dry-run response (`controllers/transaction/core.ts`'s
|
|
226
|
+
* `deleteTransaction`, used by the credit-card aggregate; the account aggregate's own FC/IS
|
|
227
|
+
* `deleteAccountTransaction`, `controllers/account/transaction.ts`) — named once so the two never
|
|
228
|
+
* copy-paste the same literal (code-quality.md "constants over literals"). */
|
|
229
|
+
export const DELETE_TRANSACTION_CONFIRM_HINT = 'Destructive action: show the transaction to the user and call again with confirm: true.';
|
|
230
|
+
const CONFIRM_EDIT_NOT_ALLOWED_MESSAGE = "cannot edit amount/date of a transfer or bill-payment transaction at confirm — correct a transfer's " +
|
|
231
|
+
'amount/date by updating it, a bill payment by paying or reverting its bill, then confirm';
|
|
232
|
+
const WRONG_OPERATION_MESSAGE = 'this transaction is not owned by this operation; use the one for its other aggregate instead';
|
|
233
|
+
export const transactionErrors = {
|
|
234
|
+
notFound: (id) => ({
|
|
235
|
+
code: 'unknown_transaction',
|
|
236
|
+
id,
|
|
237
|
+
}),
|
|
238
|
+
categoryKindMismatch: (transactionType, categoryName, categoryKind) => ({
|
|
239
|
+
code: 'category_kind_mismatch',
|
|
240
|
+
transactionType,
|
|
241
|
+
categoryName,
|
|
242
|
+
categoryKind,
|
|
243
|
+
// Phrased flow-agnostically: raised by flows that have a settable `type` field (card purchase, updates) and by
|
|
244
|
+
// ones where the movement kind is the flow itself (account expense/income — no `type` to "set"), so the hint
|
|
245
|
+
// names the remedy in terms every caller can act on.
|
|
246
|
+
hint: `Category "${categoryName}" is ${categoryKind}-only; use a matching category, or record this as ${categoryKind === 'income' ? 'income' : 'an expense'} instead`,
|
|
247
|
+
}),
|
|
248
|
+
exclusiveCategorySubCategory: {
|
|
249
|
+
code: 'validation',
|
|
250
|
+
issues: ['provide category OR subCategory, not both — subCategory implies its parent category'],
|
|
251
|
+
},
|
|
252
|
+
exclusiveCategorySubCategoryUpdate: {
|
|
253
|
+
code: 'validation',
|
|
254
|
+
issues: ['provide category OR subCategory, not both'],
|
|
255
|
+
},
|
|
256
|
+
exclusivePeriodRange: {
|
|
257
|
+
code: 'validation',
|
|
258
|
+
issues: ['provide month/year OR from/to, not both'],
|
|
259
|
+
},
|
|
260
|
+
invalidCursor: {
|
|
261
|
+
code: 'validation',
|
|
262
|
+
issues: ['cursor is malformed, stale, or does not match the requested sort/dir — start a fresh first page'],
|
|
263
|
+
},
|
|
264
|
+
// The effective ⇒ not-future-dated invariant, enforced at confirm.
|
|
265
|
+
cannotConfirmFutureDated: (date) => ({
|
|
266
|
+
code: 'validation',
|
|
267
|
+
issues: [`cannot confirm: ${date} is in the future — an effective transaction's date is never in the future`],
|
|
268
|
+
}),
|
|
269
|
+
confirmEditNotAllowedForTransfer: validationWithRemedy(CONFIRM_EDIT_NOT_ALLOWED_MESSAGE, Remedy.enum.update_account_transaction),
|
|
270
|
+
// ADR-017 ownership guard: raised by whichever of the four aggregate-specific update/delete operations
|
|
271
|
+
// was used on a transaction it does not own — a guard, not a dispatcher (the caller re-addresses
|
|
272
|
+
// the operation named by the remedy; nothing here re-routes on their behalf).
|
|
273
|
+
wrongOperation: (remedy) => validationWithRemedy(WRONG_OPERATION_MESSAGE, remedy),
|
|
274
|
+
};
|
|
275
|
+
export const LOW_CONFIDENCE_THRESHOLD = 0.6;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CurrencyCode } from '../../models/money.js';
|
|
3
|
+
import { parseCategoryNames } from './categories.js';
|
|
4
|
+
export const AggregateDbRowSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
key: z.string().nullable(),
|
|
7
|
+
label: z.string().nullable(),
|
|
8
|
+
label_names: z.string().nullable().default(null),
|
|
9
|
+
currency: CurrencyCode,
|
|
10
|
+
value: z.number(),
|
|
11
|
+
count: z.number().int(),
|
|
12
|
+
})
|
|
13
|
+
.transform(({ label_names, ...rest }) => ({
|
|
14
|
+
...rest,
|
|
15
|
+
labelNames: parseCategoryNames(label_names),
|
|
16
|
+
}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// Bill row from the raw SELECT (snake_case). Loose; BillSchema.parse enforces the status
|
|
3
|
+
// enum and date formats downstream. Joined columns (e.g. card_name) are read separately.
|
|
4
|
+
export const BillRowSchema = z.object({
|
|
5
|
+
id: z.string(),
|
|
6
|
+
credit_card_id: z.string(),
|
|
7
|
+
month: z.number(),
|
|
8
|
+
year: z.number(),
|
|
9
|
+
close_date: z.string(),
|
|
10
|
+
due_date: z.string(),
|
|
11
|
+
status: z.string(),
|
|
12
|
+
payment_transaction_id: z.string().nullable(),
|
|
13
|
+
version: z.number(),
|
|
14
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BudgetPeriod } from '../../models/budget.js';
|
|
3
|
+
import { CurrencyCode } from '../../models/money.js';
|
|
4
|
+
import { parseCategoryNames } from './categories.js';
|
|
5
|
+
/** Shared shape of the budget-with-target self-join row (`diplomat/db/repos/budgets.ts`) — stays a
|
|
6
|
+
* hand schema like `SubCategoryRowSchema` (`wire/db/categories.ts`) until the raw reads are
|
|
7
|
+
* unified under drizzle-orm/zod. `node_parent_id` null means the budgeted node is itself a
|
|
8
|
+
* top-level category; set means it's a sub-category, with `parent_name`/`parent_names`
|
|
9
|
+
* describing its parent. `target_id` (`node.id`, == `b.category_id`) is for `logic/budget.ts` to
|
|
10
|
+
* match this row against spend itself (ADR-028). */
|
|
11
|
+
const budgetTargetRowShape = {
|
|
12
|
+
id: z.string(),
|
|
13
|
+
currency: CurrencyCode,
|
|
14
|
+
limit_amount: z.number(),
|
|
15
|
+
period: BudgetPeriod,
|
|
16
|
+
target_id: z.string(),
|
|
17
|
+
node_name: z.string(),
|
|
18
|
+
node_names: z.string().nullable().default(null),
|
|
19
|
+
node_parent_id: z.string().nullable(),
|
|
20
|
+
parent_name: z.string().nullable(),
|
|
21
|
+
parent_names: z.string().nullable().default(null),
|
|
22
|
+
};
|
|
23
|
+
const shapeTargetRow = ({ limit_amount, target_id, node_name, node_names, node_parent_id, parent_name, parent_names, ...rest }) => ({
|
|
24
|
+
...rest,
|
|
25
|
+
limit: limit_amount,
|
|
26
|
+
targetId: target_id,
|
|
27
|
+
nodeName: node_name,
|
|
28
|
+
nodeNames: parseCategoryNames(node_names),
|
|
29
|
+
nodeParentId: node_parent_id,
|
|
30
|
+
parentName: parent_name,
|
|
31
|
+
parentNames: parseCategoryNames(parent_names),
|
|
32
|
+
});
|
|
33
|
+
export const BudgetViewRowSchema = z.object({ ...budgetTargetRowShape, version: z.number() }).transform(shapeTargetRow);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { LocalizedNamesSchema } from '../../models/category.js';
|
|
3
|
+
// Sub-category row from the raw self-join SELECT (snake_case + joined parent_name).
|
|
4
|
+
// Stays a hand schema until the raw reads are unified under drizzle-orm/zod (see migration issue).
|
|
5
|
+
export const SubCategoryRowSchema = z.object({
|
|
6
|
+
id: z.string(),
|
|
7
|
+
name: z.string(),
|
|
8
|
+
parent_id: z.string(),
|
|
9
|
+
parent_name: z.string(),
|
|
10
|
+
kind: z.string(),
|
|
11
|
+
});
|
|
12
|
+
/** Decodes a joined category's `names` JSON column — `null` when the join found no category or
|
|
13
|
+
* the category is user-created. Shared by aggregate/summary/correlations queries. */
|
|
14
|
+
export const parseCategoryNames = (raw) => raw ? LocalizedNamesSchema.parse(JSON.parse(raw)) : null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CurrencyCode } from '../../models/money.js';
|
|
3
|
+
import { parseCategoryNames } from './categories.js';
|
|
4
|
+
/** `current`/`baseline_total` are raw SUMs — `logic/correlations.ts`'s `toSpendingShift` divides
|
|
5
|
+
* `baselineTotal` by `baselineMonths` and derives `deltaPct`/`direction` from the pair. */
|
|
6
|
+
export const SpendingShiftDbRowSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
category: z.string().min(1),
|
|
9
|
+
category_names: z.string().nullable().default(null),
|
|
10
|
+
currency: CurrencyCode,
|
|
11
|
+
current: z.number(),
|
|
12
|
+
baseline_total: z.number(),
|
|
13
|
+
})
|
|
14
|
+
.transform(({ category_names, baseline_total, ...rest }) => ({
|
|
15
|
+
...rest,
|
|
16
|
+
categoryNames: parseCategoryNames(category_names),
|
|
17
|
+
baselineTotal: baseline_total,
|
|
18
|
+
}));
|
|
19
|
+
/** One (category, currency, merchant) row — `merchant_key` is nullable (no merchant classified);
|
|
20
|
+
* `logic/correlations.ts`'s `shapeMerchantConcentration` resolves the display fallback. */
|
|
21
|
+
export const MerchantSpendDbRowSchema = z
|
|
22
|
+
.object({
|
|
23
|
+
category: z.string().min(1),
|
|
24
|
+
category_names: z.string().nullable().default(null),
|
|
25
|
+
currency: CurrencyCode,
|
|
26
|
+
merchant_key: z.string().nullable(),
|
|
27
|
+
spent: z.number(),
|
|
28
|
+
})
|
|
29
|
+
.transform(({ category_names, merchant_key, ...rest }) => ({
|
|
30
|
+
...rest,
|
|
31
|
+
categoryNames: parseCategoryNames(category_names),
|
|
32
|
+
merchantKey: merchant_key,
|
|
33
|
+
}));
|
|
34
|
+
/** One qualifying transaction row for recurring-candidate detection — `merchant_key` is always
|
|
35
|
+
* non-null (the repo query filters it), unlike `MerchantSpendDbRowSchema`'s nullable one. */
|
|
36
|
+
export const RecurringCandidateDbRowSchema = z
|
|
37
|
+
.object({
|
|
38
|
+
merchant_key: z.string().min(1),
|
|
39
|
+
currency: CurrencyCode,
|
|
40
|
+
category: z.string().min(1),
|
|
41
|
+
category_names: z.string().nullable().default(null),
|
|
42
|
+
date: z.string(),
|
|
43
|
+
amount: z.number(),
|
|
44
|
+
})
|
|
45
|
+
.transform(({ merchant_key, category_names, ...rest }) => ({
|
|
46
|
+
...rest,
|
|
47
|
+
merchantKey: merchant_key,
|
|
48
|
+
categoryNames: parseCategoryNames(category_names),
|
|
49
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { parseCategoryNames } from './categories.js';
|
|
3
|
+
/** One row of the `merchants/top` repo query — `category_name`/`category_names` are both null
|
|
4
|
+
* when the merchant's transactions carry no category at all (`logic`/controller resolves the
|
|
5
|
+
* display fallback, same pattern as `MerchantSpendDbRowSchema`). */
|
|
6
|
+
export const MerchantTopDbRowSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
merchant: z.string().min(1),
|
|
9
|
+
transaction_count: z.number(),
|
|
10
|
+
category_name: z.string().nullable(),
|
|
11
|
+
category_names: z.string().nullable().default(null),
|
|
12
|
+
})
|
|
13
|
+
.transform(({ transaction_count, category_name, category_names, ...rest }) => ({
|
|
14
|
+
...rest,
|
|
15
|
+
transactionCount: transaction_count,
|
|
16
|
+
categoryName: category_name,
|
|
17
|
+
categoryNames: parseCategoryNames(category_names),
|
|
18
|
+
}));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// Recurring-rule row from the raw SELECT (snake_case + joined account/category names).
|
|
3
|
+
// Loose; RecurringRuleViewSchema.parse/RecurringRuleEntitySchema.parse enforce enums and date
|
|
4
|
+
// formats downstream.
|
|
5
|
+
export const RecurringRowSchema = z.object({
|
|
6
|
+
id: z.string(),
|
|
7
|
+
description: z.string(),
|
|
8
|
+
amount: z.number(),
|
|
9
|
+
type: z.string(),
|
|
10
|
+
period: z.string(),
|
|
11
|
+
next_due: z.string(),
|
|
12
|
+
currency: z.string(),
|
|
13
|
+
account_id: z.string().nullable(),
|
|
14
|
+
account_name: z.string().nullable(),
|
|
15
|
+
category_id: z.string().nullable(),
|
|
16
|
+
category_name: z.string().nullable(),
|
|
17
|
+
merchant_key: z.string().nullable(),
|
|
18
|
+
version: z.number().int(),
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CurrencyCode } from '../../models/money.js';
|
|
3
|
+
import { MovementType, TransactionSortField, TransactionStatus } from '../../models/transaction.js';
|
|
4
|
+
import { parseCategoryNames } from './categories.js';
|
|
5
|
+
// The columns dbToModel consumes from the full transaction SELECT (node columns +
|
|
6
|
+
// LEFT JOINed related names/tags). Decoded at the boundary before mapping to the model;
|
|
7
|
+
// unrelated columns the SELECT may also return are ignored by z.object.
|
|
8
|
+
export const TransactionRowSchema = z.object({
|
|
9
|
+
id: z.string(),
|
|
10
|
+
description: z.string(),
|
|
11
|
+
amount: z.number(),
|
|
12
|
+
type: z.string(),
|
|
13
|
+
status: TransactionStatus,
|
|
14
|
+
date: z.string(),
|
|
15
|
+
currency: z.string(),
|
|
16
|
+
source: z.string(),
|
|
17
|
+
idempotency_key: z.string(),
|
|
18
|
+
classification_method: z.string(),
|
|
19
|
+
confidence: z.number(),
|
|
20
|
+
raw_input: z.string().nullable(),
|
|
21
|
+
note: z.string().nullable(),
|
|
22
|
+
from_account_id: z.string().nullable(),
|
|
23
|
+
from_account_name: z.string().nullable(),
|
|
24
|
+
to_account_id: z.string().nullable(),
|
|
25
|
+
to_account_name: z.string().nullable(),
|
|
26
|
+
credit_card_id: z.string().nullable(),
|
|
27
|
+
credit_card_name: z.string().nullable(),
|
|
28
|
+
bill_id: z.string().nullable(),
|
|
29
|
+
category_id: z.string().nullable(),
|
|
30
|
+
category_name: z.string().nullable(),
|
|
31
|
+
category_names: z.string().nullable().default(null),
|
|
32
|
+
subcategory_id: z.string().nullable(),
|
|
33
|
+
subcategory_name: z.string().nullable(),
|
|
34
|
+
subcategory_names: z.string().nullable().default(null),
|
|
35
|
+
merchant_key: z.string().nullable(),
|
|
36
|
+
tags: z.string().nullable(), // JSON array from json_group_array
|
|
37
|
+
version: z.number().int().nonnegative(),
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* ADR-011/014 whitelist: the only column each `search_transactions` sort field may resolve to.
|
|
41
|
+
* The caller-selected `sort` enum picks a fixed, developer-authored column name here — caller
|
|
42
|
+
* text never reaches `ORDER BY`. Plain db-column facts (this file's existing job — see
|
|
43
|
+
* `TransactionRowSchema`), not query composition: `diplomat/db/repos/transactions.ts` is the only
|
|
44
|
+
* place that turns a name from this map into an actual SQL fragment (`sql.raw`).
|
|
45
|
+
*/
|
|
46
|
+
export const ORDER_BY_COLUMN = {
|
|
47
|
+
[TransactionSortField.enum.date]: 't.date',
|
|
48
|
+
[TransactionSortField.enum.amount]: 't.amount',
|
|
49
|
+
};
|
|
50
|
+
export const SummaryRowSchema = z
|
|
51
|
+
.object({
|
|
52
|
+
currency: CurrencyCode,
|
|
53
|
+
type: MovementType,
|
|
54
|
+
category: z.string().nullable(),
|
|
55
|
+
category_names: z.string().nullable().default(null),
|
|
56
|
+
total: z.number(),
|
|
57
|
+
count: z.number(),
|
|
58
|
+
})
|
|
59
|
+
.transform(({ category_names, ...rest }) => ({
|
|
60
|
+
...rest,
|
|
61
|
+
categoryNames: parseCategoryNames(category_names),
|
|
62
|
+
}));
|
|
63
|
+
export const CategorySpendRowSchema = z
|
|
64
|
+
.object({
|
|
65
|
+
currency: CurrencyCode,
|
|
66
|
+
category_id: z.string(),
|
|
67
|
+
subcategory_id: z.string().nullable(),
|
|
68
|
+
effective: z.number(),
|
|
69
|
+
pending: z.number(),
|
|
70
|
+
})
|
|
71
|
+
.transform(({ category_id, subcategory_id, ...rest }) => ({
|
|
72
|
+
...rest,
|
|
73
|
+
categoryId: category_id,
|
|
74
|
+
subCategoryId: subcategory_id,
|
|
75
|
+
}));
|
|
76
|
+
export const CategoryWindowedSpendRowSchema = z
|
|
77
|
+
.object({
|
|
78
|
+
currency: CurrencyCode,
|
|
79
|
+
category_id: z.string(),
|
|
80
|
+
subcategory_id: z.string().nullable(),
|
|
81
|
+
current: z.number(),
|
|
82
|
+
baseline_total: z.number(),
|
|
83
|
+
})
|
|
84
|
+
.transform(({ category_id, subcategory_id, baseline_total, ...rest }) => ({
|
|
85
|
+
...rest,
|
|
86
|
+
categoryId: category_id,
|
|
87
|
+
subCategoryId: subcategory_id,
|
|
88
|
+
baselineTotal: baseline_total,
|
|
89
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CurrencyCode } from '../../models/money.js';
|
|
3
|
+
import * as modelAccount from '../../models/account.js';
|
|
4
|
+
import { IsoDateQuerySchema } from './coerce.js';
|
|
5
|
+
// The boundary owns quality-of-life defaults; the domain keeps these fields required (not-null).
|
|
6
|
+
// Default currency follows the default language (en → USD); default type is the most common account.
|
|
7
|
+
export const CreateAccountSchema = modelAccount.CreateAccountSchema.extend({
|
|
8
|
+
type: modelAccount.CreateAccountSchema.shape.type.default(modelAccount.AccountType.enum.checking),
|
|
9
|
+
currency: modelAccount.CreateAccountSchema.shape.currency.default(CurrencyCode.enum.USD),
|
|
10
|
+
});
|
|
11
|
+
export const UpdateAccountSchema = modelAccount.UpdateAccountSchema;
|
|
12
|
+
// Pass-through — no boundary-only defaults needed; every field required by the domain schema is
|
|
13
|
+
// already required here.
|
|
14
|
+
export const AddAccountMovementSchema = modelAccount.AddAccountMovementSchema;
|
|
15
|
+
// Pass-through — no boundary-only defaults needed.
|
|
16
|
+
export const UpdateAccountTransactionSchema = modelAccount.UpdateAccountTransactionSchema;
|
|
17
|
+
// Pass-through — no boundary-only defaults needed.
|
|
18
|
+
export const CreateTransferSchema = modelAccount.CreateTransferSchema;
|
|
19
|
+
// Pass-through — no boundary-only defaults needed.
|
|
20
|
+
export const ImportAccountStatementSchema = modelAccount.ImportAccountStatementSchema;
|
|
21
|
+
export const AccountsQuerySchema = z.object({ type: modelAccount.AccountType.optional() });
|
|
22
|
+
export const AccountBalancesQuerySchema = z.object({
|
|
23
|
+
account: z.string().optional(),
|
|
24
|
+
type: modelAccount.AccountType.optional(),
|
|
25
|
+
projectedAsOf: IsoDateQuerySchema.optional(),
|
|
26
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { AggregateMetric, AggregateSort, AggregateSpendingSchema } from '../../models/aggregate.js';
|
|
3
|
+
import { coerceToNumber } from './coerce.js';
|
|
4
|
+
export const AggregateSpendingInputSchema = AggregateSpendingSchema.extend({
|
|
5
|
+
metric: AggregateSpendingSchema.shape.metric.default(AggregateMetric.enum.sum),
|
|
6
|
+
sort: AggregateSpendingSchema.shape.sort.default(AggregateSort.enum.desc),
|
|
7
|
+
limit: z.preprocess(coerceToNumber, AggregateSpendingSchema.shape.limit.default(50)),
|
|
8
|
+
month: z.preprocess(coerceToNumber, AggregateSpendingSchema.shape.month),
|
|
9
|
+
year: z.preprocess(coerceToNumber, AggregateSpendingSchema.shape.year),
|
|
10
|
+
});
|