@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,106 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Id } from './id.js';
|
|
3
|
+
import { CurrencyCode } from './money.js';
|
|
4
|
+
import { withPersistenceMeta } from '@rfc0/effect-runner';
|
|
5
|
+
export const BudgetPeriod = z.enum(['monthly']);
|
|
6
|
+
// Entity tag for this aggregate's `Persistable`s.
|
|
7
|
+
export const BUDGET_ENTITY_TAG = 'budget';
|
|
8
|
+
/** `limit` is this module's own vocabulary for the `limit_amount` column — `adapters/budgets.ts`
|
|
9
|
+
* maps the rename. */
|
|
10
|
+
export const BudgetSchema = z.object({
|
|
11
|
+
id: Id.describe('Unique budget identifier'),
|
|
12
|
+
categoryId: Id.describe("The budgeted node's id — a top-level category or sub-category (categories.id)"),
|
|
13
|
+
currency: CurrencyCode.describe('Currency this limit is denominated in; spend is measured same-currency only (no implicit conversion)'),
|
|
14
|
+
limit: z.number().positive().describe('Spending limit for the period, full units of currency'),
|
|
15
|
+
period: BudgetPeriod.describe('How often the limit applies; monthly is the only period for now'),
|
|
16
|
+
});
|
|
17
|
+
// `Budget` plus the optimistic-concurrency `version` token. Never sent over the wire.
|
|
18
|
+
export const BudgetEntitySchema = withPersistenceMeta(BudgetSchema);
|
|
19
|
+
/** Read projection actually returned to callers — `category`/`subCategory` display names instead
|
|
20
|
+
* of the internal `categoryId` FK, mirroring `RecurringRuleView` (models/recurring.ts). */
|
|
21
|
+
export const BudgetViewSchema = BudgetSchema.omit({ categoryId: true }).extend({
|
|
22
|
+
category: z.string().min(1).describe("Top-level category name — the sub-category's parent, when set"),
|
|
23
|
+
subCategory: z
|
|
24
|
+
.string()
|
|
25
|
+
.min(1)
|
|
26
|
+
.optional()
|
|
27
|
+
.describe('Sub-category name, present only when this budget targets a sub-category rather than its parent'),
|
|
28
|
+
});
|
|
29
|
+
// `.describe()` is domain information. Defaults split by intent: integrity defaults live here
|
|
30
|
+
// (`period` is required — a real value the domain always needs); quality-of-life convenience
|
|
31
|
+
// defaults live at the wire boundary (`wire/in/budgets.ts` defaults `period` to `monthly`),
|
|
32
|
+
// mirroring `models/category.ts`'s `CreateCategorySchema`/`wire/in/categories.ts` split.
|
|
33
|
+
export const CreateBudgetSchema = z.object({
|
|
34
|
+
category: z
|
|
35
|
+
.string()
|
|
36
|
+
.min(1)
|
|
37
|
+
.optional()
|
|
38
|
+
.describe('Category name to budget — provide exactly one of category/subCategory'),
|
|
39
|
+
subCategory: z
|
|
40
|
+
.string()
|
|
41
|
+
.min(1)
|
|
42
|
+
.optional()
|
|
43
|
+
.describe('Sub-category name to budget — provide exactly one of category/subCategory'),
|
|
44
|
+
currency: CurrencyCode.describe('Currency this limit is denominated in and measured against'),
|
|
45
|
+
limit: z.number().positive().describe('Spending limit for the period, full units of currency'),
|
|
46
|
+
period: BudgetPeriod.describe('How often the limit applies'),
|
|
47
|
+
});
|
|
48
|
+
export const UpdateBudgetSchema = z.object({
|
|
49
|
+
id: Id.describe('Budget id, from create_budget or list_budgets'),
|
|
50
|
+
limit: z.number().positive().optional().describe('New spending limit'),
|
|
51
|
+
period: BudgetPeriod.optional().describe('New period'),
|
|
52
|
+
});
|
|
53
|
+
/** The flat, ungrouped shape a budget row correlates to once matched against its own spend —
|
|
54
|
+
* `groupStatusByCategory` reshapes it into the grouped-by-category response. */
|
|
55
|
+
export const BudgetStatusEntrySchema = BudgetViewSchema.extend({
|
|
56
|
+
spentEffective: z
|
|
57
|
+
.number()
|
|
58
|
+
.describe('Sum of effective (cleared), expense-only, same-currency spend against this target in the period'),
|
|
59
|
+
spentPending: z
|
|
60
|
+
.number()
|
|
61
|
+
.describe('Sum of pending (not yet cleared), expense-only, same-currency spend against this target in the period'),
|
|
62
|
+
});
|
|
63
|
+
/** One measure's reading against a budget's limit. Over-budget is reported as-is — `pct` is never
|
|
64
|
+
* clamped or flagged as an error. */
|
|
65
|
+
export const BudgetMeasureSchema = z.object({
|
|
66
|
+
amount: z.number().describe("This measure's spend amount"),
|
|
67
|
+
pct: z.number().describe('amount / limit; exceeds 1 when over budget'),
|
|
68
|
+
});
|
|
69
|
+
/** One budget's status within its category group — `category` is lifted to the group itself
|
|
70
|
+
* (`BudgetStatusGroupSchema`), so a line only needs `subCategory` to distinguish a sub-category's
|
|
71
|
+
* own line from its parent category's. `remaining` stays a single top-level number, reported
|
|
72
|
+
* against `committed` (the planning-relevant headroom) rather than per-measure. */
|
|
73
|
+
export const BudgetStatusLineSchema = BudgetStatusEntrySchema.omit({
|
|
74
|
+
category: true,
|
|
75
|
+
spentEffective: true,
|
|
76
|
+
spentPending: true,
|
|
77
|
+
}).extend({
|
|
78
|
+
effective: BudgetMeasureSchema.describe('Cleared spend (status = effective) against the limit'),
|
|
79
|
+
committed: BudgetMeasureSchema.describe('Cleared + pending spend (status IN (effective, pending)) against the limit — the earmark-aware measure'),
|
|
80
|
+
pending: BudgetMeasureSchema.describe('committed - effective, surfaced for convenience'),
|
|
81
|
+
remaining: z.number().describe('limit - committed.amount; negative when over budget'),
|
|
82
|
+
});
|
|
83
|
+
/** One coherent unit per category (Feature Design 015's "no cross-currency total" decision): every
|
|
84
|
+
* budget targeting this category or one of its sub-categories, as per-currency/per-target lines —
|
|
85
|
+
* never summed across currencies or across category/sub-category. */
|
|
86
|
+
export const BudgetStatusGroupSchema = z.object({
|
|
87
|
+
category: z.string().min(1).describe('Top-level category name'),
|
|
88
|
+
lines: z
|
|
89
|
+
.array(BudgetStatusLineSchema)
|
|
90
|
+
.min(1)
|
|
91
|
+
.describe("This category's own budget (if any) and/or each of its sub-categories' own budgets"),
|
|
92
|
+
});
|
|
93
|
+
export const budgetErrors = {
|
|
94
|
+
targetRequired: {
|
|
95
|
+
code: 'validation',
|
|
96
|
+
issues: ['exactly one of category or subCategory is required'],
|
|
97
|
+
},
|
|
98
|
+
notExpenseCategory: (category) => ({ code: 'not_expense_category', category }),
|
|
99
|
+
duplicate: (target, currency, period) => ({
|
|
100
|
+
code: 'duplicate_budget',
|
|
101
|
+
category: target.category,
|
|
102
|
+
subCategory: target.subCategory,
|
|
103
|
+
currency,
|
|
104
|
+
period,
|
|
105
|
+
}),
|
|
106
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Id } from './id.js';
|
|
3
|
+
export const CategoryKind = z.enum(['expense', 'income', 'both']);
|
|
4
|
+
export const categoryKindLabels = {
|
|
5
|
+
expense: { en: 'Expense', pt: 'Despesa', es: 'Gasto' },
|
|
6
|
+
income: { en: 'Income', pt: 'Receita', es: 'Ingreso' },
|
|
7
|
+
both: { en: 'Both', pt: 'Ambos', es: 'Ambos' },
|
|
8
|
+
};
|
|
9
|
+
export const LocalizedNamesSchema = z.record(z.string().min(1), z.string().min(1)).nullable();
|
|
10
|
+
// `.describe()` is domain information — it states what each field is and represents.
|
|
11
|
+
// Defaults split by intent: integrity defaults (a value that must exist for the entity to be
|
|
12
|
+
// valid) live here; quality-of-life convenience defaults live at the wire boundary
|
|
13
|
+
// (see wire/in/categories.ts), keeping the domain contract honest about what is required.
|
|
14
|
+
export const CategorySchema = z.object({
|
|
15
|
+
id: Id,
|
|
16
|
+
name: z.string().min(1).describe('Category display name'),
|
|
17
|
+
kind: CategoryKind.describe('expense | income | both — controls which transaction types may use this category'),
|
|
18
|
+
kindLabel: z.string().optional(),
|
|
19
|
+
names: LocalizedNamesSchema.describe('Locale-keyed display names for default categories; null for user-created'),
|
|
20
|
+
});
|
|
21
|
+
export const CreateCategorySchema = CategorySchema.omit({ id: true, kindLabel: true, names: true });
|
|
22
|
+
// Entity tag for this aggregate's `Persistable`s — shared by both a top-level category and a
|
|
23
|
+
// sub-category (same table, `parentId` set or not).
|
|
24
|
+
export const CATEGORY_ENTITY_TAG = 'category';
|
|
25
|
+
/** Sub-category read projection — includes parent info joined from [:BELONGS_TO]->(:Category). */
|
|
26
|
+
export const SubCategorySchema = z.object({
|
|
27
|
+
id: Id,
|
|
28
|
+
name: z.string().min(1).describe('Sub-category display name'),
|
|
29
|
+
parentId: Id.describe('Parent category ID'),
|
|
30
|
+
parentName: z.string().min(1).describe('Parent category name'),
|
|
31
|
+
kind: CategoryKind.describe('Inherited from the parent category'),
|
|
32
|
+
kindLabel: z.string().optional(),
|
|
33
|
+
});
|
|
34
|
+
// Base for wire/in/categories.ts's own CreateSubCategorySchema (`.omit({ id: true })`).
|
|
35
|
+
export const CreateSubCategorySchema = z.object({
|
|
36
|
+
id: Id,
|
|
37
|
+
name: z.string().min(1).describe('Sub-category display name'),
|
|
38
|
+
parentId: Id.describe('ID of the parent category'),
|
|
39
|
+
});
|
|
40
|
+
export const categoryErrors = {
|
|
41
|
+
duplicateName: (entity, name) => ({
|
|
42
|
+
code: 'duplicate_name',
|
|
43
|
+
entity,
|
|
44
|
+
name,
|
|
45
|
+
}),
|
|
46
|
+
inUse: (entity, name, references) => ({
|
|
47
|
+
code: 'in_use',
|
|
48
|
+
entity,
|
|
49
|
+
name,
|
|
50
|
+
references,
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { reasonOf } from './error.js';
|
|
3
|
+
/** Why a client's configuration file could not be used (expected failures of `setup`). */
|
|
4
|
+
export const ClientConfigFailureCode = z.enum(['read_failed', 'write_failed']);
|
|
5
|
+
export const clientConfigFailures = {
|
|
6
|
+
readFailed: (path, cause) => ({
|
|
7
|
+
code: ClientConfigFailureCode.enum.read_failed,
|
|
8
|
+
path,
|
|
9
|
+
reason: reasonOf(cause),
|
|
10
|
+
warnings: [],
|
|
11
|
+
}),
|
|
12
|
+
writeFailed: (path, cause, warnings = []) => ({
|
|
13
|
+
code: ClientConfigFailureCode.enum.write_failed,
|
|
14
|
+
path,
|
|
15
|
+
reason: reasonOf(cause),
|
|
16
|
+
warnings,
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { IsoDate, PeriodSchema } from './date.js';
|
|
3
|
+
import { ConvertedTotalSchema } from './currency-rate.js';
|
|
4
|
+
import { Id } from './id.js';
|
|
5
|
+
import { CurrencyCode } from './money.js';
|
|
6
|
+
/** Analysis modes for `find_correlations`. Whitelisted enum, mirroring `aggregate_spending`'s
|
|
7
|
+
* `groupBy` (ADR-011). */
|
|
8
|
+
export const FindCorrelationsAnalysis = z.enum([
|
|
9
|
+
'spending_shifts',
|
|
10
|
+
'budget_fit',
|
|
11
|
+
'merchant_concentration',
|
|
12
|
+
'recurring_candidates',
|
|
13
|
+
]);
|
|
14
|
+
// QoL defaults applied at the MCP boundary, not baked into the schema — mirrors aggregate_spending.
|
|
15
|
+
export const DEFAULT_BASELINE_MONTHS = 3;
|
|
16
|
+
export const DEFAULT_MIN_DELTA_PCT = 20;
|
|
17
|
+
export const DEFAULT_SLACK_PCT = 20;
|
|
18
|
+
export const DEFAULT_OVER_PCT = 20;
|
|
19
|
+
export const DEFAULT_TOP_N = 5;
|
|
20
|
+
export const DEFAULT_LOOKBACK_MONTHS = 6;
|
|
21
|
+
export const DEFAULT_MIN_OCCURRENCES = 3;
|
|
22
|
+
// A small cushion above the trailing average for `suggestedLimit` (budget_fit) — a limit set
|
|
23
|
+
// exactly at the average would be exceeded by any normal month-to-month variance.
|
|
24
|
+
export const SUGGESTED_LIMIT_MARGIN_PCT = 10;
|
|
25
|
+
// Fixed tolerance constants for `detectRecurringCadence` — not caller-adjustable like
|
|
26
|
+
// `lookbackMonths`/`minOccurrences`. A real month is 28-31 days; ±5 around a 30-day nominal gap
|
|
27
|
+
// covers every calendar month length without also accepting a weekly or quarterly pattern.
|
|
28
|
+
export const CADENCE_NOMINAL_GAP_DAYS = 30;
|
|
29
|
+
export const CADENCE_DAY_TOLERANCE_DAYS = 5;
|
|
30
|
+
export const CADENCE_AMOUNT_TOLERANCE_PCT = 10;
|
|
31
|
+
// Shared between minDeltaPct's own field description below and the tool's registered description
|
|
32
|
+
// (diplomat/mcp/tools/correlations.ts), so the two can't drift apart.
|
|
33
|
+
export const NEW_CATEGORY_ALWAYS_SURFACED_NOTE = 'a brand-new category with no baseline spend at all is always surfaced regardless of this threshold';
|
|
34
|
+
export const FindCorrelationsSchema = z.object({
|
|
35
|
+
analysis: FindCorrelationsAnalysis.describe('Which correlation analysis to run'),
|
|
36
|
+
// Requiredness is enforced per-mode in controllers/correlations.ts via `hasPeriod`, not here —
|
|
37
|
+
// mirrors aggregate_spending's own from/to-or-period flexibility.
|
|
38
|
+
month: PeriodSchema.shape.month
|
|
39
|
+
.optional()
|
|
40
|
+
.describe('Reference month (1-12) — spending_shifts/budget_fit/merchant_concentration measure this month against ' +
|
|
41
|
+
'its trailing baseline; not used by recurring_candidates'),
|
|
42
|
+
year: PeriodSchema.shape.year.optional().describe('Reference year — not used by recurring_candidates'),
|
|
43
|
+
baselineMonths: z
|
|
44
|
+
.number()
|
|
45
|
+
.int()
|
|
46
|
+
.min(1)
|
|
47
|
+
.max(24)
|
|
48
|
+
.optional()
|
|
49
|
+
.describe(`Trailing window size in months averaged into the baseline (default ${DEFAULT_BASELINE_MONTHS})`),
|
|
50
|
+
minDeltaPct: z
|
|
51
|
+
.number()
|
|
52
|
+
.min(0)
|
|
53
|
+
.optional()
|
|
54
|
+
.describe(`Only surface categories whose |deltaPct| is at least this percentage (default ${DEFAULT_MIN_DELTA_PCT}); ` +
|
|
55
|
+
NEW_CATEGORY_ALWAYS_SURFACED_NOTE),
|
|
56
|
+
slackPct: z
|
|
57
|
+
.number()
|
|
58
|
+
.min(0)
|
|
59
|
+
.optional()
|
|
60
|
+
.describe(`budget_fit: how far below the limit the baseline can sit before the budget is "generous" — ` +
|
|
61
|
+
`percentage (default ${DEFAULT_SLACK_PCT})`),
|
|
62
|
+
overPct: z
|
|
63
|
+
.number()
|
|
64
|
+
.min(0)
|
|
65
|
+
.optional()
|
|
66
|
+
.describe(`budget_fit: how far above the limit the baseline can sit before the budget is "unrealistic" — ` +
|
|
67
|
+
`percentage (default ${DEFAULT_OVER_PCT})`),
|
|
68
|
+
category: z
|
|
69
|
+
.string()
|
|
70
|
+
.min(1)
|
|
71
|
+
.optional()
|
|
72
|
+
.describe('merchant_concentration: restrict to a single category by name (default: every category)'),
|
|
73
|
+
topN: z
|
|
74
|
+
.number()
|
|
75
|
+
.int()
|
|
76
|
+
.min(1)
|
|
77
|
+
.max(50)
|
|
78
|
+
.optional()
|
|
79
|
+
.describe(`merchant_concentration: top merchants to return per category (default ${DEFAULT_TOP_N})`),
|
|
80
|
+
lookbackMonths: z
|
|
81
|
+
.number()
|
|
82
|
+
.int()
|
|
83
|
+
.min(1)
|
|
84
|
+
.max(36)
|
|
85
|
+
.optional()
|
|
86
|
+
.describe(`recurring_candidates: months of transaction history to scan for a recurring pattern, ending today ` +
|
|
87
|
+
`(default ${DEFAULT_LOOKBACK_MONTHS})`),
|
|
88
|
+
minOccurrences: z
|
|
89
|
+
.number()
|
|
90
|
+
.int()
|
|
91
|
+
.min(2)
|
|
92
|
+
.max(24)
|
|
93
|
+
.optional()
|
|
94
|
+
.describe(`recurring_candidates: minimum qualifying occurrences within the lookback window to flag a candidate ` +
|
|
95
|
+
`(default ${DEFAULT_MIN_OCCURRENCES})`),
|
|
96
|
+
displayCurrency: CurrencyCode.optional().describe('Also return a converted grand total in this currency for spending_shifts/budget_fit/merchant_concentration ' +
|
|
97
|
+
'(recurring_candidates is unaffected — its candidates are proposed rules, not per-currency spend totals)'),
|
|
98
|
+
});
|
|
99
|
+
export const SpendingShiftDirection = z.enum(['up', 'down']);
|
|
100
|
+
export const SpendingShiftSchema = z.object({
|
|
101
|
+
category: z.string().min(1).describe('Top-level category name — sub-category spend rolls up into its parent'),
|
|
102
|
+
currency: CurrencyCode,
|
|
103
|
+
current: z.number().describe('Effective, expense-only total for the reference month'),
|
|
104
|
+
baseline: z.number().describe('Average monthly effective expense total over the preceding baselineMonths'),
|
|
105
|
+
deltaPct: z
|
|
106
|
+
.number()
|
|
107
|
+
.nullable()
|
|
108
|
+
.describe('(current - baseline) / baseline, as a percentage; null when there is no baseline spend at all ' +
|
|
109
|
+
'(a brand-new category), not a divide-by-zero'),
|
|
110
|
+
direction: SpendingShiftDirection.describe("'up' for increased or brand-new spend, 'down' for decreased spend"),
|
|
111
|
+
});
|
|
112
|
+
export const SpendingShiftsResultSchema = z.object({
|
|
113
|
+
analysis: z.literal(FindCorrelationsAnalysis.enum.spending_shifts),
|
|
114
|
+
month: PeriodSchema.shape.month,
|
|
115
|
+
year: PeriodSchema.shape.year,
|
|
116
|
+
shifts: z
|
|
117
|
+
.array(SpendingShiftSchema)
|
|
118
|
+
.describe('Sorted by |deltaPct| descending; brand-new-spend categories (deltaPct: null) sort first'),
|
|
119
|
+
converted: ConvertedTotalSchema.optional().describe("Opt-in converted grand total of the reference month's effective, expense-only spend across every " +
|
|
120
|
+
'currency — present only when displayCurrency was supplied'),
|
|
121
|
+
});
|
|
122
|
+
/** `realistic`/`generous` are unambiguous; the design doc left the over-budget bucket's name
|
|
123
|
+
* undecided ("tight/unrealistic") — `unrealistic` chosen as the more informative of the two, one
|
|
124
|
+
* verdict, not two. */
|
|
125
|
+
export const BudgetFitVerdict = z.enum(['realistic', 'unrealistic', 'generous']);
|
|
126
|
+
export const BudgetFitLineSchema = z.object({
|
|
127
|
+
id: Id.describe('Budget id — identifies the budget to update in order to apply suggestedLimit'),
|
|
128
|
+
category: z.string().min(1).describe("Top-level category name — the sub-category's parent, when set"),
|
|
129
|
+
subCategory: z
|
|
130
|
+
.string()
|
|
131
|
+
.min(1)
|
|
132
|
+
.optional()
|
|
133
|
+
.describe('Sub-category name, present only when this budget targets a sub-category rather than its parent'),
|
|
134
|
+
currency: CurrencyCode,
|
|
135
|
+
limit: z.number().describe("This budget's current limit"),
|
|
136
|
+
current: z.number().describe('Effective, expense-only total for the reference month'),
|
|
137
|
+
baseline: z.number().describe('Average monthly effective expense total over the preceding baselineMonths'),
|
|
138
|
+
verdict: BudgetFitVerdict.describe('realistic: baseline within tolerance of limit. unrealistic: baseline materially over limit — ' +
|
|
139
|
+
'consistently over-budget. generous: baseline well under limit.'),
|
|
140
|
+
suggestedLimit: z.number().describe('A more realistic limit given actual spend: baseline plus a small margin'),
|
|
141
|
+
});
|
|
142
|
+
export const UnbudgetedSpendSchema = z.object({
|
|
143
|
+
category: z.string().min(1).describe('Top-level category name with material spend but no budget at all'),
|
|
144
|
+
currency: CurrencyCode,
|
|
145
|
+
baseline: z.number().describe('Average monthly effective expense total over the preceding baselineMonths'),
|
|
146
|
+
suggestedLimit: z.number().describe('A starting limit given actual spend: baseline plus a small margin'),
|
|
147
|
+
});
|
|
148
|
+
export const BudgetFitResultSchema = z.object({
|
|
149
|
+
analysis: z.literal(FindCorrelationsAnalysis.enum.budget_fit),
|
|
150
|
+
month: PeriodSchema.shape.month,
|
|
151
|
+
year: PeriodSchema.shape.year,
|
|
152
|
+
budgeted: z
|
|
153
|
+
.array(BudgetFitLineSchema)
|
|
154
|
+
.describe('Every existing budget, with a verdict on whether its limit matches actual spend'),
|
|
155
|
+
unbudgeted: z
|
|
156
|
+
.array(UnbudgetedSpendSchema)
|
|
157
|
+
.describe('Categories with an established (nonzero baseline) spend pattern but no budget at all'),
|
|
158
|
+
converted: ConvertedTotalSchema.optional().describe('Opt-in converted grand total of committed (effective + pending) spend matched to a budget, across every ' +
|
|
159
|
+
'currency — the same measure the budget status converts; present only when displayCurrency was supplied'),
|
|
160
|
+
});
|
|
161
|
+
export const MerchantShareSchema = z.object({
|
|
162
|
+
merchant: z.string().min(1).describe('Merchant key, or a localized "Unknown" when the transaction has none'),
|
|
163
|
+
spent: z.number().describe('Effective expense total for this merchant within the category'),
|
|
164
|
+
share: z.number().describe('spent / categoryTotal, as a 0-1 fraction'),
|
|
165
|
+
cumulativeShare: z.number().describe('Running total of share, in descending-spend order, through this merchant'),
|
|
166
|
+
});
|
|
167
|
+
export const CategoryConcentrationSchema = z.object({
|
|
168
|
+
category: z.string().min(1).describe('Top-level category name — sub-category spend rolls up into its parent'),
|
|
169
|
+
currency: CurrencyCode,
|
|
170
|
+
categoryTotal: z.number().describe('Total effective expense in this category for the period'),
|
|
171
|
+
merchants: z.array(MerchantShareSchema).describe('Top `topN` merchants by spend, descending'),
|
|
172
|
+
othersSpent: z.number().describe('categoryTotal minus the sum of the returned merchants — the long tail'),
|
|
173
|
+
});
|
|
174
|
+
export const MerchantConcentrationResultSchema = z.object({
|
|
175
|
+
analysis: z.literal(FindCorrelationsAnalysis.enum.merchant_concentration),
|
|
176
|
+
month: PeriodSchema.shape.month,
|
|
177
|
+
year: PeriodSchema.shape.year,
|
|
178
|
+
categories: z
|
|
179
|
+
.array(CategoryConcentrationSchema)
|
|
180
|
+
.describe('One entry per (category, currency) with spend in the period; sorted by category name'),
|
|
181
|
+
converted: ConvertedTotalSchema.optional().describe('Opt-in converted grand total of the per-currency spend the concentration is computed over (each ' +
|
|
182
|
+
"currency's categoryTotal, summed once — not each merchant line) — present only when displayCurrency " +
|
|
183
|
+
'was supplied'),
|
|
184
|
+
});
|
|
185
|
+
export const RecurringCandidateSchema = z.object({
|
|
186
|
+
merchant: z.string().min(1).describe('Normalized merchant key — the `merchant` of the recurring rule to create'),
|
|
187
|
+
typicalAmount: z.number().describe('Average amount across the qualifying occurrences'),
|
|
188
|
+
currency: CurrencyCode,
|
|
189
|
+
category: z.string().min(1).describe("Category of the merchant's most recent occurrence"),
|
|
190
|
+
occurrences: z.number().int().describe('Number of qualifying transactions within the lookback window'),
|
|
191
|
+
lastDate: IsoDate.describe('Date of the most recent occurrence'),
|
|
192
|
+
suggestedNextDue: IsoDate.describe("lastDate advanced one cadence — ready to be the recurring rule's startDate"),
|
|
193
|
+
});
|
|
194
|
+
export const RecurringCandidatesResultSchema = z.object({
|
|
195
|
+
analysis: z.literal(FindCorrelationsAnalysis.enum.recurring_candidates),
|
|
196
|
+
candidates: z
|
|
197
|
+
.array(RecurringCandidateSchema)
|
|
198
|
+
.describe('Sorted by occurrences descending, then merchant; excludes merchants already backing a rule'),
|
|
199
|
+
});
|
|
200
|
+
export const FindCorrelationsResultSchema = z.discriminatedUnion('analysis', [
|
|
201
|
+
SpendingShiftsResultSchema,
|
|
202
|
+
BudgetFitResultSchema,
|
|
203
|
+
MerchantConcentrationResultSchema,
|
|
204
|
+
RecurringCandidatesResultSchema,
|
|
205
|
+
]);
|
|
206
|
+
export const findCorrelationsErrors = {
|
|
207
|
+
unhandledAnalysis: (analysis) => ({
|
|
208
|
+
code: 'validation',
|
|
209
|
+
issues: [`Unhandled analysis "${analysis}"`],
|
|
210
|
+
}),
|
|
211
|
+
missingPeriod: (analysis) => ({
|
|
212
|
+
code: 'validation',
|
|
213
|
+
issues: [`analysis "${analysis}" requires month and year`],
|
|
214
|
+
}),
|
|
215
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BillQuerySchema } from './bill.js';
|
|
3
|
+
import { Id } from './id.js';
|
|
4
|
+
import { CurrencyCode } from './money.js';
|
|
5
|
+
import { withPersistenceMeta } from '@rfc0/effect-runner';
|
|
6
|
+
import { CreateTransactionSchema, STATEMENT_ITEMS_DESCRIPTION, STATEMENT_RAW_INPUT_DESCRIPTION, UpdateTransactionSchema, } from './transaction.js';
|
|
7
|
+
import { validationWithRemedy, } from './error.js';
|
|
8
|
+
import { Remedy } from './remedy.js';
|
|
9
|
+
// `.describe()` is domain information — it states what each field is and represents.
|
|
10
|
+
// Defaults split by intent: integrity defaults (a value that must exist for the entity to be
|
|
11
|
+
// valid) live here; quality-of-life convenience defaults live at the wire boundary
|
|
12
|
+
// (see wire/in/credit-cards.ts), keeping the domain contract honest about what is required.
|
|
13
|
+
export const CreditCardSchema = z.object({
|
|
14
|
+
id: Id,
|
|
15
|
+
name: z.string().min(1).describe('Card display name'),
|
|
16
|
+
currency: CurrencyCode.describe('Card currency (ISO code); fixed at creation'),
|
|
17
|
+
closingDay: z
|
|
18
|
+
.number()
|
|
19
|
+
.int()
|
|
20
|
+
.min(1)
|
|
21
|
+
.max(28)
|
|
22
|
+
.describe('Day the bill (fatura) closes; transactions after it go to next month'),
|
|
23
|
+
dueDay: z.number().int().min(1).max(28).describe('Day the bill is due for payment'),
|
|
24
|
+
limit: z.number().positive().optional().describe('Credit limit'),
|
|
25
|
+
accountId: Id.describe('Internal liability account (ADR-010)'),
|
|
26
|
+
paymentAccountId: Id.optional().describe('Default paying account for bill payment'),
|
|
27
|
+
});
|
|
28
|
+
// Entity tag for this aggregate's `Persistable`s.
|
|
29
|
+
export const CREDIT_CARD_ENTITY_TAG = 'creditCard';
|
|
30
|
+
// `CreditCard` plus the optimistic-concurrency `version` token. Never sent over the wire.
|
|
31
|
+
export const CreditCardEntitySchema = withPersistenceMeta(CreditCardSchema);
|
|
32
|
+
export const CreateCreditCardSchema = CreditCardSchema.omit({
|
|
33
|
+
id: true,
|
|
34
|
+
accountId: true,
|
|
35
|
+
paymentAccountId: true,
|
|
36
|
+
}).extend({
|
|
37
|
+
paymentAccount: z.string().min(1).optional().describe('Default paying account name for bill payment'),
|
|
38
|
+
});
|
|
39
|
+
/** Card-aggregate update schema (mirrors `UpdateAccountSchema`, Feature Design 007): identifies the
|
|
40
|
+
* card by its current `name`; `newName` renames it. `currency` is fixed once a card exists — it's
|
|
41
|
+
* baked into the card's internal account and every existing transaction's denormalized currency —
|
|
42
|
+
* so, like `UpdateCardTransactionSchema`'s `account` field, it's kept reachable (not omitted) so
|
|
43
|
+
* the controller can reject it with a helpful `cardErrors.currencyChangeRejected` rather than have
|
|
44
|
+
* it silently stripped by zod's default unknown-key behavior. */
|
|
45
|
+
export const UpdateCreditCardSchema = CreditCardSchema.omit({
|
|
46
|
+
id: true,
|
|
47
|
+
currency: true,
|
|
48
|
+
accountId: true,
|
|
49
|
+
paymentAccountId: true,
|
|
50
|
+
})
|
|
51
|
+
.partial({ closingDay: true, dueDay: true })
|
|
52
|
+
.extend({
|
|
53
|
+
currency: CreditCardSchema.shape.currency
|
|
54
|
+
.optional()
|
|
55
|
+
.describe("Rejected: a card's currency is fixed at creation. Sending this field returns a validation " +
|
|
56
|
+
'error rather than silently no-oping — present only so that error can be raised, not because ' +
|
|
57
|
+
'the currency is changeable'),
|
|
58
|
+
newName: z.string().min(1).optional().describe('New card name'),
|
|
59
|
+
paymentAccount: z.string().min(1).optional().describe('New default paying account name for bill payment'),
|
|
60
|
+
});
|
|
61
|
+
/** Natural input for a credit-card purchase (ADR-016): the transaction core's minimal
|
|
62
|
+
* `CreateTransactionSchema` (ADR-019) plus `card` (required — the card's own internal liability
|
|
63
|
+
* account is always the destination) and bill-assignment (`billMonth`/`billYear`) — both are
|
|
64
|
+
* credit-card-only vocabulary the core no longer carries. Depends on the transaction core's schema
|
|
65
|
+
* (aggregate → core, the allowed direction) — never the reverse. `.strict()`: `account` is a
|
|
66
|
+
* meaningful field on the sibling aggregate schema (`AddAccountMovementSchema`), not a
|
|
67
|
+
* server-managed one — a caller who mistakenly sends it here should get a validation error, not
|
|
68
|
+
* have it silently stripped by zod's default unknown-key behavior (REST boundary only; the MCP
|
|
69
|
+
* tool's inputSchema is a raw shape, which the MCP SDK reconstructs into its own non-strict object
|
|
70
|
+
* internally). */
|
|
71
|
+
export const AddCardPurchaseSchema = CreateTransactionSchema.extend({
|
|
72
|
+
card: z.string().min(1).describe('Credit card name — joins the cycle bill'),
|
|
73
|
+
billMonth: BillQuerySchema.shape.month
|
|
74
|
+
.optional()
|
|
75
|
+
.describe('Explicit target bill cycle month (1-12) for a card transaction; overrides cycle-based auto-assignment. ' +
|
|
76
|
+
'Provide with billYear together; requires card. Auto-creates the bill if that cycle has none yet'),
|
|
77
|
+
billYear: BillQuerySchema.shape.year.optional().describe('Explicit target bill cycle year; provide with billMonth'),
|
|
78
|
+
}).strict();
|
|
79
|
+
/** A single line of an `import_card_statement` request (ADR-017 step 2): same shape as
|
|
80
|
+
* `AddCardPurchaseSchema` minus `card` (fixed once, at the statement's top level — single-source,
|
|
81
|
+
* no per-line card) and minus `rawInput`/`subCategory`/`tags` (statement-level concerns: `rawInput`
|
|
82
|
+
* belongs to the whole pasted statement, and bulk import classifies automatically rather than
|
|
83
|
+
* taking a sub-category or tags per line — the same reduced shape the retired god bulk item
|
|
84
|
+
* carried). */
|
|
85
|
+
export const ImportCardStatementItemSchema = AddCardPurchaseSchema.omit({
|
|
86
|
+
card: true,
|
|
87
|
+
rawInput: true,
|
|
88
|
+
subCategory: true,
|
|
89
|
+
tags: true,
|
|
90
|
+
}).strict();
|
|
91
|
+
/** Credit-card statement import (ADR-017 step 2): single-source — every item is a purchase on the
|
|
92
|
+
* ONE card named here, joining each line's own cycle bill via `addCardPurchase`. Replaces the god
|
|
93
|
+
* `create_transactions_bulk`'s per-line card routing entirely (a statement can't carry a
|
|
94
|
+
* conflicting per-line owner by construction). */
|
|
95
|
+
export const ImportCardStatementSchema = z.object({
|
|
96
|
+
card: z.string().min(1).describe('Credit card name — every item in this statement is a purchase on this one card'),
|
|
97
|
+
items: z.array(ImportCardStatementItemSchema).min(1).max(200).describe(STATEMENT_ITEMS_DESCRIPTION),
|
|
98
|
+
rawInput: z.string().optional().describe(STATEMENT_RAW_INPUT_DESCRIPTION),
|
|
99
|
+
});
|
|
100
|
+
/** Card-aggregate update schema (ADR-017/ADR-019): `.extend`s the core's minimal
|
|
101
|
+
* `UpdateTransactionSchema` with `account` — kept reachable (not omitted) so it can be explicitly
|
|
102
|
+
* rejected with a helpful message (`cardErrors.accountChangeRejectedForCard`) rather than a generic
|
|
103
|
+
* `.strict()` unrecognized-key error — and `billMonth`/`billYear`, genuine card-only reassignment
|
|
104
|
+
* vocabulary. `.strict()` still rejects truly foreign fields at the REST boundary (MCP tool args
|
|
105
|
+
* are reconstructed as a non-strict shape by the SDK). */
|
|
106
|
+
export const UpdateCardTransactionSchema = UpdateTransactionSchema.extend({
|
|
107
|
+
account: z
|
|
108
|
+
.string()
|
|
109
|
+
.min(1)
|
|
110
|
+
.optional()
|
|
111
|
+
.describe("Rejected: a card transaction is always funded by the card's own internal account. Sending this " +
|
|
112
|
+
'field returns a validation error rather than reassigning it — present only so that error can be ' +
|
|
113
|
+
'raised, not because the account is changeable'),
|
|
114
|
+
billMonth: BillQuerySchema.shape.month
|
|
115
|
+
.optional()
|
|
116
|
+
.describe('Reassign to this bill cycle month (1-12) — the transaction must already be a card transaction. ' +
|
|
117
|
+
'Provide with billYear together. Rejected if the current or target bill is paid; auto-creates the ' +
|
|
118
|
+
'target bill if that cycle has none yet'),
|
|
119
|
+
billYear: BillQuerySchema.shape.year
|
|
120
|
+
.optional()
|
|
121
|
+
.describe('Reassignment target bill cycle year; provide with billMonth'),
|
|
122
|
+
}).strict();
|
|
123
|
+
/** `deleteCreditCard`'s dry-run response (`controllers/credit-card/credit-card.ts`) — named so the
|
|
124
|
+
* string can't drift between the response and its own test's assertion, matching
|
|
125
|
+
* `DELETE_TRANSACTION_CONFIRM_HINT` (`models/transaction.ts`)'s reason for existing. */
|
|
126
|
+
export const DELETE_CREDIT_CARD_CONFIRM_HINT = 'Destructive action: show what would be deleted to the user and call again with confirm: true.';
|
|
127
|
+
const PAID_BILL_IMMUTABLE_MESSAGE = 'this bill is paid; its transactions cannot be added, removed, or reassigned — revert the bill payment first';
|
|
128
|
+
export const cardErrors = {
|
|
129
|
+
duplicateName: (name) => ({ code: 'duplicate_name', entity: 'credit_card', name }),
|
|
130
|
+
currencyMismatch: (cardCurrency, accountCurrency) => ({
|
|
131
|
+
code: 'validation',
|
|
132
|
+
issues: [`currency mismatch: card is ${cardCurrency}, payment account is ${accountCurrency}`],
|
|
133
|
+
}),
|
|
134
|
+
// Field-tied to billMonth/billYear (ADR-019 step 1: moved from models/transaction.ts's
|
|
135
|
+
// transactionErrors, where the core used to raise them itself — the core no longer carries these
|
|
136
|
+
// fields at all, so only the credit-card aggregate, which owns them, can raise these now).
|
|
137
|
+
billPeriodIncomplete: {
|
|
138
|
+
code: 'validation',
|
|
139
|
+
issues: ['billMonth and billYear must be provided together'],
|
|
140
|
+
},
|
|
141
|
+
billAssignmentRequiresCard: {
|
|
142
|
+
code: 'validation',
|
|
143
|
+
issues: [
|
|
144
|
+
'billMonth/billYear require a credit-card transaction; provide `card` (create) or the transaction must already have one (update)',
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
paidBillImmutable: validationWithRemedy(PAID_BILL_IMMUTABLE_MESSAGE, Remedy.enum.revert_bill_payment),
|
|
148
|
+
accountChangeRejectedForCard: {
|
|
149
|
+
code: 'validation',
|
|
150
|
+
issues: ["cannot change the account of a card transaction; it is always funded by the card's own internal account"],
|
|
151
|
+
},
|
|
152
|
+
currencyChangeRejected: {
|
|
153
|
+
code: 'validation',
|
|
154
|
+
issues: ["cannot change a credit card's currency; it is fixed at creation"],
|
|
155
|
+
},
|
|
156
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Id } from './id.js';
|
|
3
|
+
import { CurrencyCode } from './money.js';
|
|
4
|
+
import { withPersistenceMeta } from '@rfc0/effect-runner';
|
|
5
|
+
// Entity tag for this aggregate's `Persistable`s.
|
|
6
|
+
export const CURRENCY_RATE_ENTITY_TAG = 'currency_rate';
|
|
7
|
+
/** Agent/scheduler-supplied external data (ADR-026 Phase 2) — decoded at the boundary like any
|
|
8
|
+
* other input, never treated as authoritative beyond its own `asOf`. */
|
|
9
|
+
export const SetExchangeRateSchema = z.object({
|
|
10
|
+
from: CurrencyCode.describe('Base currency — 1 unit of this equals `rate` units of `to`'),
|
|
11
|
+
to: CurrencyCode.describe('Quote currency — the unit `rate` is expressed in'),
|
|
12
|
+
rate: z.number().positive().describe('1 unit of `from` = `rate` units of `to`, as of `asOf`'),
|
|
13
|
+
asOf: z.string().datetime({ offset: true }).describe('ISO 8601 timestamp this rate was observed/sourced'),
|
|
14
|
+
source: z.string().min(1).optional().describe('Free-text provenance, e.g. "PTAX", "coingecko"'),
|
|
15
|
+
});
|
|
16
|
+
/** `from`/`to` are this module's own vocabulary for the `from_code`/`to_code` columns —
|
|
17
|
+
* `adapters/currency-rates.ts` maps the rename. */
|
|
18
|
+
export const CurrencyRateSchema = z.object({
|
|
19
|
+
id: Id.describe('Unique exchange rate identifier'),
|
|
20
|
+
fromCode: CurrencyCode.describe('Base currency — 1 unit of this equals `rate` units of toCode'),
|
|
21
|
+
toCode: CurrencyCode.describe('Quote currency — the unit `rate` is expressed in'),
|
|
22
|
+
rate: z.number().positive().describe('1 unit of fromCode = `rate` units of toCode, as of `asOf`'),
|
|
23
|
+
asOf: z
|
|
24
|
+
.string()
|
|
25
|
+
.datetime({ offset: true })
|
|
26
|
+
.describe('ISO 8601 timestamp this rate was observed/sourced (agent-supplied)'),
|
|
27
|
+
source: z
|
|
28
|
+
.string()
|
|
29
|
+
.min(1)
|
|
30
|
+
.nullable()
|
|
31
|
+
.describe('Free-text provenance (e.g. "PTAX", "coingecko"), or null if unspecified'),
|
|
32
|
+
});
|
|
33
|
+
// `CurrencyRate` plus the optimistic-concurrency `version` token. Never sent over the wire.
|
|
34
|
+
export const CurrencyRateEntitySchema = withPersistenceMeta(CurrencyRateSchema);
|
|
35
|
+
/** Read projection actually returned to callers — `from`/`to` instead of the internal
|
|
36
|
+
* `fromCode`/`toCode`, mirroring `BudgetView`'s `limit` rename (models/budget.ts). No `id`/`version`:
|
|
37
|
+
* a rate is addressed by its (from, to) pair, never by id, from the caller's perspective. */
|
|
38
|
+
export const CurrencyRateViewSchema = z.object({
|
|
39
|
+
from: CurrencyCode.describe('Base currency'),
|
|
40
|
+
to: CurrencyCode.describe('Quote currency'),
|
|
41
|
+
rate: z.number().positive().describe('1 unit of `from` = `rate` units of `to`, as of `asOf`'),
|
|
42
|
+
asOf: z.string().datetime({ offset: true }).describe('ISO 8601 timestamp this rate was observed/sourced'),
|
|
43
|
+
source: z.string().min(1).optional().describe('Free-text provenance, e.g. "PTAX", "coingecko"'),
|
|
44
|
+
});
|
|
45
|
+
/** A single balance's read-time valuation against a base currency (ADR-026 Phase 3) — omitted by
|
|
46
|
+
* the caller building the response when unconvertible (no rate on file for the pair). */
|
|
47
|
+
export const ConvertedValueSchema = z.object({
|
|
48
|
+
baseCurrency: CurrencyCode.describe('The currency this value is expressed in'),
|
|
49
|
+
value: z.number().describe('Amount converted to baseCurrency, rounded to its own decimals'),
|
|
50
|
+
rate: z.number().positive().describe('Exchange rate applied (1 when the source currency already is baseCurrency)'),
|
|
51
|
+
asOf: z.string().datetime({ offset: true }).describe('When the applied rate was observed/sourced'),
|
|
52
|
+
stale: z.boolean().describe('True when the rate is older than its class staleness threshold'),
|
|
53
|
+
});
|
|
54
|
+
/** Why a currency was left out of a `displayCurrency` grand total — currently the only reason is a
|
|
55
|
+
* missing rate to the target; a named enum keeps the wire value out of raw string literals, same
|
|
56
|
+
* as any other domain vocabulary. */
|
|
57
|
+
export const ExclusionReason = z.enum(['no_rate']);
|
|
58
|
+
export const ExcludedCurrencySchema = z.object({
|
|
59
|
+
currency: CurrencyCode.describe('Currency left out of the converted total'),
|
|
60
|
+
reason: ExclusionReason.describe('Why this currency could not be converted to the display currency'),
|
|
61
|
+
});
|
|
62
|
+
/** A converted grand total across a per-currency read's own currencies — the generalized
|
|
63
|
+
* `consolidatedNetWorth` shape, reusable by any per-currency read that wants an opt-in
|
|
64
|
+
* converted total on top of its unchanged per-currency lines. */
|
|
65
|
+
export const ConvertedTotalSchema = z.object({
|
|
66
|
+
displayCurrency: CurrencyCode.describe('Currency the grand total is expressed in'),
|
|
67
|
+
total: z.number().describe('Sum of every convertible per-currency amount, rounded to displayCurrency decimals'),
|
|
68
|
+
stale: z.boolean().describe('True when any contributing rate is older than its class staleness threshold'),
|
|
69
|
+
asOf: z
|
|
70
|
+
.string()
|
|
71
|
+
.datetime({ offset: true })
|
|
72
|
+
.nullable()
|
|
73
|
+
.describe('Oldest contributing rate timestamp, or null when nothing was converted'),
|
|
74
|
+
excluded: z.array(ExcludedCurrencySchema).describe('Currencies with no rate to displayCurrency, left out of total'),
|
|
75
|
+
});
|
|
76
|
+
export const currencyRateErrors = {
|
|
77
|
+
samePair: {
|
|
78
|
+
code: 'validation',
|
|
79
|
+
issues: ['from and to currencies must differ'],
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
export const CRYPTO_CURRENCIES = new Set([CurrencyCode.enum.USDC, CurrencyCode.enum.BTC]);
|
|
83
|
+
export const MS_PER_HOUR = 60 * 60 * 1000;
|