@rfc0/patty 0.0.0-stage → 1.0.0
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 +493 -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 +1716 -0
- package/ui/dashboards/cards.html +4032 -0
- package/ui/dashboards/categories.html +4694 -0
- package/ui/dashboards/comparative.html +2464 -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 +2517 -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,43 @@
|
|
|
1
|
+
import { DASHBOARD_ENTITY_TAG, DashboardEntitySchema, DashboardListItemSchema, DashboardSchema, DashboardSource, } from '../models/dashboard.js';
|
|
2
|
+
import * as persistence from '../logic/persistence.js';
|
|
3
|
+
/** `resolvedHtml` is the content the repo already read — from `row.html` for `source: inline`, or
|
|
4
|
+
* from `path` under `ui/dashboards/` for `source: file` (the file read is I/O, so it happens in
|
|
5
|
+
* the repo, never here; this stays a pure field mapping either way). */
|
|
6
|
+
export const dbToModel = (row, resolvedHtml) => DashboardSchema.parse({ name: row.name, html: resolvedHtml, updatedAt: row.updatedAt, source: row.source });
|
|
7
|
+
export const dbToListItem = (row) => DashboardListItemSchema.parse({ name: row.name, updatedAt: row.updatedAt, source: row.source });
|
|
8
|
+
/** Read variant carrying `id`/`version`/`path` and `shared` — for `findByName`'s full-row read, which rename needs to
|
|
9
|
+
* build a version-guarded `Persistable` that preserves the row's source/path unchanged. */
|
|
10
|
+
export const dbToEntity = (row, resolvedHtml, shared) => DashboardEntitySchema.parse({
|
|
11
|
+
id: row.id,
|
|
12
|
+
name: row.name,
|
|
13
|
+
html: resolvedHtml,
|
|
14
|
+
updatedAt: row.updatedAt,
|
|
15
|
+
version: row.version,
|
|
16
|
+
source: row.source,
|
|
17
|
+
path: row.path,
|
|
18
|
+
shared,
|
|
19
|
+
});
|
|
20
|
+
// Not the identity function (unlike most entities' modelToDb): a source: 'file' row's stored
|
|
21
|
+
// `html` is always null (content lives on disk) and a source: 'inline' row's stored `path` is
|
|
22
|
+
// always null — this is where "exactly one of html/path per source" (ADR-027 Phase 2) is enforced
|
|
23
|
+
// on the write side, mirroring the schema's own CHECK constraint.
|
|
24
|
+
export const modelToDb = (entity) => entity.source === DashboardSource.enum.file
|
|
25
|
+
? {
|
|
26
|
+
id: entity.id,
|
|
27
|
+
name: entity.name,
|
|
28
|
+
html: null,
|
|
29
|
+
updatedAt: entity.updatedAt,
|
|
30
|
+
version: entity.version,
|
|
31
|
+
source: entity.source,
|
|
32
|
+
path: entity.path,
|
|
33
|
+
}
|
|
34
|
+
: {
|
|
35
|
+
id: entity.id,
|
|
36
|
+
name: entity.name,
|
|
37
|
+
html: entity.html,
|
|
38
|
+
updatedAt: entity.updatedAt,
|
|
39
|
+
version: entity.version,
|
|
40
|
+
source: entity.source,
|
|
41
|
+
path: null,
|
|
42
|
+
};
|
|
43
|
+
export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(DASHBOARD_ENTITY_TAG, modelToDb);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as R from 'remeda';
|
|
2
|
+
import * as accountAdapters from './accounts.js';
|
|
3
|
+
import * as billAdapters from './bills.js';
|
|
4
|
+
import * as budgetAdapters from './budgets.js';
|
|
5
|
+
import * as creditCardAdapters from './credit-cards.js';
|
|
6
|
+
import * as currencyRateAdapters from './currency-rates.js';
|
|
7
|
+
import * as recurringAdapters from './recurring.js';
|
|
8
|
+
import * as settingsAdapters from './settings.js';
|
|
9
|
+
import * as tagAdapters from './tags.js';
|
|
10
|
+
import * as transactionAdapters from './transactions.js';
|
|
11
|
+
/** The demo seeder runs one flow after another through one runner; each adapter only rewrites its own entity's tag, so
|
|
12
|
+
* applying them all in turn adapts whichever flow just ran (docs/write-path.md § From model to row). */
|
|
13
|
+
export const outcomeToDb = (outcome) => R.pipe(outcome, settingsAdapters.outcomeToDb, accountAdapters.outcomeToDb, creditCardAdapters.outcomeToDb, billAdapters.outcomeToDb, budgetAdapters.outcomeToDb, currencyRateAdapters.outcomeToDb, recurringAdapters.outcomeToDb, tagAdapters.outcomeToDb, transactionAdapters.outcomeToDb);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as persistence from '../logic/persistence.js';
|
|
2
|
+
import { INSTANCE_SETTINGS_ENTITY_TAG } from '../models/auth/entity.js';
|
|
3
|
+
import { InstanceSettingsEntitySchema } from '../models/auth/users.js';
|
|
4
|
+
export const dbToModel = (row) => InstanceSettingsEntitySchema.parse(row);
|
|
5
|
+
/** A versioned `InstanceSettingsEntity` is already row-shaped. */
|
|
6
|
+
export const modelToDb = (entity) => entity;
|
|
7
|
+
export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(INSTANCE_SETTINGS_ENTITY_TAG, modelToDb);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as persistence from '../logic/persistence.js';
|
|
2
|
+
import { INVITE_ENTITY_TAG } from '../models/auth/entity.js';
|
|
3
|
+
import { InviteEntitySchema } from '../models/auth/users.js';
|
|
4
|
+
export const dbToModel = (row) => InviteEntitySchema.parse(row);
|
|
5
|
+
/** A versioned `InviteEntity` is already row-shaped. */
|
|
6
|
+
export const modelToDb = (entity) => entity;
|
|
7
|
+
export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(INVITE_ENTITY_TAG, modelToDb);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RECURRING_ENTITY_TAG, RecurringRuleEntitySchema, RecurringRuleViewSchema, } from '../models/recurring.js';
|
|
2
|
+
import * as persistence from '../logic/persistence.js';
|
|
3
|
+
import { RecurringRowSchema } from '../wire/db/recurring.js';
|
|
4
|
+
export const wireInToModel = (input) => input;
|
|
5
|
+
export const dbToModel = (record) => {
|
|
6
|
+
const row = RecurringRowSchema.parse(record);
|
|
7
|
+
return RecurringRuleViewSchema.parse({
|
|
8
|
+
id: row.id,
|
|
9
|
+
description: row.description,
|
|
10
|
+
amount: row.amount,
|
|
11
|
+
type: row.type,
|
|
12
|
+
period: row.period,
|
|
13
|
+
nextDue: row.next_due,
|
|
14
|
+
currency: row.currency,
|
|
15
|
+
accountId: row.account_id ?? undefined,
|
|
16
|
+
accountName: row.account_name ?? undefined,
|
|
17
|
+
categoryId: row.category_id ?? undefined,
|
|
18
|
+
categoryName: row.category_name ?? undefined,
|
|
19
|
+
merchantKey: row.merchant_key ?? undefined,
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
/** Read variant carrying `version`, no joined display names — a due rule is never displayed, only
|
|
23
|
+
* used to build a version-guarded `Persistable`. */
|
|
24
|
+
export const dbToEntity = (record) => {
|
|
25
|
+
const row = RecurringRowSchema.parse(record);
|
|
26
|
+
return RecurringRuleEntitySchema.parse({
|
|
27
|
+
id: row.id,
|
|
28
|
+
description: row.description,
|
|
29
|
+
amount: row.amount,
|
|
30
|
+
type: row.type,
|
|
31
|
+
period: row.period,
|
|
32
|
+
nextDue: row.next_due,
|
|
33
|
+
currency: row.currency,
|
|
34
|
+
accountId: row.account_id ?? undefined,
|
|
35
|
+
categoryId: row.category_id ?? undefined,
|
|
36
|
+
merchantKey: row.merchant_key ?? undefined,
|
|
37
|
+
version: row.version,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
/** Entity → row for the versioned unit of work (ADR-021) — the only recurring-rule write path that
|
|
41
|
+
* needs `version` on the wire-db row. */
|
|
42
|
+
export const modelToDb = (entity) => ({
|
|
43
|
+
id: entity.id,
|
|
44
|
+
description: entity.description,
|
|
45
|
+
amount: entity.amount,
|
|
46
|
+
type: entity.type,
|
|
47
|
+
period: entity.period,
|
|
48
|
+
nextDue: entity.nextDue,
|
|
49
|
+
currency: entity.currency,
|
|
50
|
+
accountId: entity.accountId ?? null,
|
|
51
|
+
categoryId: entity.categoryId ?? null,
|
|
52
|
+
merchantKey: entity.merchantKey ?? null,
|
|
53
|
+
version: entity.version,
|
|
54
|
+
});
|
|
55
|
+
export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(RECURRING_ENTITY_TAG, modelToDb);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as persistence from '../logic/persistence.js';
|
|
2
|
+
import { SESSION_ENTITY_TAG } from '../models/auth/entity.js';
|
|
3
|
+
import { SessionEntitySchema } from '../models/auth/session.js';
|
|
4
|
+
export const dbToModel = (row) => SessionEntitySchema.parse(row);
|
|
5
|
+
/** A versioned `SessionEntity` is already row-shaped. */
|
|
6
|
+
export const modelToDb = (entity) => entity;
|
|
7
|
+
export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(SESSION_ENTITY_TAG, modelToDb);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { USER_SETTINGS_ENTITY_TAG } from '../models/locale.js';
|
|
2
|
+
import * as persistence from '../logic/persistence.js';
|
|
3
|
+
export const modelToDb = (entity) => entity;
|
|
4
|
+
export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(USER_SETTINGS_ENTITY_TAG, modelToDb);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as persistence from '../logic/persistence.js';
|
|
2
|
+
import { SETUP_CODE_ENTITY_TAG } from '../models/auth/entity.js';
|
|
3
|
+
import { SetupCodeEntitySchema } from '../models/auth/owner.js';
|
|
4
|
+
export const dbToModel = (row) => SetupCodeEntitySchema.parse(row);
|
|
5
|
+
/** A versioned `SetupCodeEntity` is already row-shaped. */
|
|
6
|
+
export const modelToDb = (entity) => entity;
|
|
7
|
+
export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(SETUP_CODE_ENTITY_TAG, modelToDb);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TAG_ENTITY_TAG, TagEntitySchema, TagSchema } from '../models/tag.js';
|
|
2
|
+
import * as persistence from '../logic/persistence.js';
|
|
3
|
+
export const dbToModel = (row) => TagSchema.parse({ id: row.id, name: row.name });
|
|
4
|
+
/** Read variant carrying `version` — for `deleteTag`, which needs it to build a version-guarded
|
|
5
|
+
* `Persistable`. */
|
|
6
|
+
export const dbToEntity = (row) => TagEntitySchema.parse({ id: row.id, name: row.name, version: row.version });
|
|
7
|
+
/** Entity → row for the versioned unit of work — a `Tag` is already row-shaped once versioned. */
|
|
8
|
+
export const modelToDb = (entity) => entity;
|
|
9
|
+
export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(TAG_ENTITY_TAG, modelToDb);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { RawTransactionViewSchema, TRANSACTION_ENTITY_TAG, } from '../models/transaction.js';
|
|
2
|
+
import { LocalizedNamesSchema } from '../models/category.js';
|
|
3
|
+
import { formatAppError } from '../common/errors.js';
|
|
4
|
+
import * as persistence from '../logic/persistence.js';
|
|
5
|
+
import { TransactionRowSchema } from '../wire/db/transactions.js';
|
|
6
|
+
import { BulkResultOut, CreateTransactionOut, DeleteTransactionOut, } from '../wire/out/transactions.js';
|
|
7
|
+
export const optional = (value) => value ?? undefined;
|
|
8
|
+
export const parseTags = (json) => (json ? JSON.parse(json) : []).filter((tag) => typeof tag === 'string');
|
|
9
|
+
export const parseNames = (json) => json !== null ? LocalizedNamesSchema.parse(JSON.parse(json)) : null;
|
|
10
|
+
export const dbToModel = (record) => {
|
|
11
|
+
const row = TransactionRowSchema.parse(record);
|
|
12
|
+
return RawTransactionViewSchema.parse({
|
|
13
|
+
id: row.id,
|
|
14
|
+
description: row.description,
|
|
15
|
+
amount: row.amount,
|
|
16
|
+
type: row.type,
|
|
17
|
+
status: row.status,
|
|
18
|
+
date: row.date,
|
|
19
|
+
currency: row.currency,
|
|
20
|
+
source: row.source,
|
|
21
|
+
idempotencyKey: row.idempotency_key,
|
|
22
|
+
classification: {
|
|
23
|
+
method: row.classification_method,
|
|
24
|
+
confidence: row.confidence,
|
|
25
|
+
},
|
|
26
|
+
rawInput: optional(row.raw_input),
|
|
27
|
+
note: optional(row.note),
|
|
28
|
+
accountId: optional(row.from_account_id),
|
|
29
|
+
accountName: optional(row.from_account_name),
|
|
30
|
+
toAccountId: optional(row.to_account_id),
|
|
31
|
+
toAccountName: optional(row.to_account_name),
|
|
32
|
+
cardId: optional(row.credit_card_id),
|
|
33
|
+
cardName: optional(row.credit_card_name),
|
|
34
|
+
billId: optional(row.bill_id),
|
|
35
|
+
categoryId: optional(row.category_id),
|
|
36
|
+
categoryName: optional(row.category_name),
|
|
37
|
+
categoryNames: parseNames(row.category_names),
|
|
38
|
+
subCategoryId: optional(row.subcategory_id),
|
|
39
|
+
subCategoryName: optional(row.subcategory_name),
|
|
40
|
+
subCategoryNames: parseNames(row.subcategory_names),
|
|
41
|
+
merchant: optional(row.merchant_key),
|
|
42
|
+
tags: parseTags(row.tags),
|
|
43
|
+
version: row.version,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
export const modelToDb = (entity) => ({
|
|
47
|
+
props: {
|
|
48
|
+
id: entity.id,
|
|
49
|
+
description: entity.description,
|
|
50
|
+
amount: entity.amount,
|
|
51
|
+
type: entity.type,
|
|
52
|
+
status: entity.status,
|
|
53
|
+
date: entity.date,
|
|
54
|
+
currency: entity.currency,
|
|
55
|
+
source: entity.source,
|
|
56
|
+
classificationMethod: entity.classification.method,
|
|
57
|
+
confidence: entity.classification.confidence,
|
|
58
|
+
rawInput: entity.rawInput ?? null,
|
|
59
|
+
note: entity.note ?? null,
|
|
60
|
+
},
|
|
61
|
+
refs: {
|
|
62
|
+
accountId: entity.refs.accountId ?? null,
|
|
63
|
+
toAccountId: entity.refs.toAccountId ?? null,
|
|
64
|
+
cardId: entity.refs.cardId ?? null,
|
|
65
|
+
billId: entity.refs.billId ?? null,
|
|
66
|
+
categoryId: entity.refs.categoryId ?? null,
|
|
67
|
+
subCategoryId: entity.refs.subCategoryId ?? null,
|
|
68
|
+
merchantKey: entity.refs.merchantKey ?? null,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
export const entityToDb = (entity) => {
|
|
72
|
+
const { props, refs } = modelToDb(entity);
|
|
73
|
+
return {
|
|
74
|
+
...props,
|
|
75
|
+
fromAccountId: refs.accountId,
|
|
76
|
+
toAccountId: refs.toAccountId,
|
|
77
|
+
creditCardId: refs.cardId,
|
|
78
|
+
billId: refs.billId,
|
|
79
|
+
categoryId: refs.categoryId,
|
|
80
|
+
subcategoryId: refs.subCategoryId,
|
|
81
|
+
merchantKey: refs.merchantKey,
|
|
82
|
+
version: entity.version,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(TRANSACTION_ENTITY_TAG, entityToDb);
|
|
86
|
+
// ─── wire/in→model ───────────────────────────────────────────────────────────
|
|
87
|
+
export const searchWireInToModel = (input) => input;
|
|
88
|
+
export const confirmWireInToModel = (input) => input;
|
|
89
|
+
// ─── model→wire/out ──────────────────────────────────────────────────────────
|
|
90
|
+
export const createResultToWireOut = (result) => CreateTransactionOut.parse(result);
|
|
91
|
+
const bulkItemToWireOut = (item) => item.status === 'error'
|
|
92
|
+
? { status: 'error', description: item.description, error: formatAppError(item.error) }
|
|
93
|
+
: item;
|
|
94
|
+
export const bulkResultToWireOut = (result) => BulkResultOut.parse({ summary: result.summary, items: result.items.map(bulkItemToWireOut) });
|
|
95
|
+
export const deleteResultToWireOut = (result) => DeleteTransactionOut.parse(result);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as persistence from '../logic/persistence.js';
|
|
2
|
+
import { USER_ENTITY_TAG } from '../models/auth/entity.js';
|
|
3
|
+
import { UserEntitySchema } from '../models/auth/owner.js';
|
|
4
|
+
export const dbToModel = (row) => UserEntitySchema.parse(row);
|
|
5
|
+
/** A versioned `UserEntity` is already row-shaped. */
|
|
6
|
+
export const modelToDb = (entity) => entity;
|
|
7
|
+
export const { persistableToDb, outcomeToDb } = persistence.entityDbAdapter(USER_ENTITY_TAG, modelToDb);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
/** This build's version, from the package it was published as (`0.0.0-development` from a checkout). `src/common`
|
|
4
|
+
* and `dist/common` both sit two levels below the package root. */
|
|
5
|
+
export const { version } = require('../../package.json');
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { AUTH_MESSAGES } from '../models/auth/message.js';
|
|
2
|
+
const withCode = (code, detail) => `${code}: ${detail}`;
|
|
3
|
+
const formatCandidates = (e) => withCode(e.code, `"${e.query}" (candidates: ${e.candidates.join(', ')})`);
|
|
4
|
+
const formatHint = (e) => withCode(e.code, e.hint);
|
|
5
|
+
const formatMessage = (message) => (e) => withCode(e.code, message);
|
|
6
|
+
const LOOKUP_FORMATTERS = {
|
|
7
|
+
unknown_account: formatCandidates,
|
|
8
|
+
ambiguous_account: formatCandidates,
|
|
9
|
+
unknown_category: formatCandidates,
|
|
10
|
+
ambiguous_category: formatCandidates,
|
|
11
|
+
unknown_sub_category: formatCandidates,
|
|
12
|
+
ambiguous_sub_category: formatCandidates,
|
|
13
|
+
unknown_card: formatCandidates,
|
|
14
|
+
ambiguous_card: formatCandidates,
|
|
15
|
+
unknown_dashboard: formatCandidates,
|
|
16
|
+
unknown_budget: formatCandidates,
|
|
17
|
+
};
|
|
18
|
+
const DOMAIN_FORMATTERS = {
|
|
19
|
+
validation: (e) => withCode(e.code, e.issues.join(', ')),
|
|
20
|
+
category_kind_mismatch: formatHint,
|
|
21
|
+
duplicate_name: (e) => withCode(e.code, `${e.entity} "${e.name}"`),
|
|
22
|
+
in_use: (e) => e.entity === 'account'
|
|
23
|
+
? `${e.code}: ${e.entity} "${e.name}" (transactions: ${e.references.transactions}, recurring: ${e.references.recurring}, cards: ${e.references.cards})`
|
|
24
|
+
: `${e.code}: ${e.entity} "${e.name}" (transactions: ${e.references.transactions}, recurring: ${e.references.recurring}, subCategories: ${e.references.subCategories})`,
|
|
25
|
+
unknown_transaction: (e) => withCode(e.code, e.id),
|
|
26
|
+
unknown_bill: (e) => withCode(e.code, `${e.card} ${e.year}-${String(e.month).padStart(2, '0')}`),
|
|
27
|
+
not_expense_category: (e) => withCode(e.code, `"${e.category}" is not an expense-eligible category`),
|
|
28
|
+
duplicate_budget: (e) => withCode(e.code, `${e.category}${e.subCategory ? `/${e.subCategory}` : ''} (${e.currency}, ${e.period})`),
|
|
29
|
+
conflict: formatMessage('concurrent update, please retry'),
|
|
30
|
+
};
|
|
31
|
+
const AUTH_FORMATTERS = {
|
|
32
|
+
unauthenticated: formatMessage(AUTH_MESSAGES.unauthenticated),
|
|
33
|
+
invalid_credentials: formatMessage(AUTH_MESSAGES.invalidCredentials),
|
|
34
|
+
invalid_setup_code: formatMessage(AUTH_MESSAGES.invalidSetupCode),
|
|
35
|
+
setup_unavailable: formatMessage(AUTH_MESSAGES.setupUnavailable),
|
|
36
|
+
unknown_user: (e) => withCode(e.code, `${AUTH_MESSAGES.unknownUser} (${e.username})`),
|
|
37
|
+
owner_unclaimed: formatMessage(AUTH_MESSAGES.ownerUnclaimed),
|
|
38
|
+
rate_limited: formatMessage(AUTH_MESSAGES.rateLimited),
|
|
39
|
+
forbidden_origin: formatHint,
|
|
40
|
+
invalid_token: formatMessage(AUTH_MESSAGES.invalidToken),
|
|
41
|
+
insufficient_scope: (e) => withCode(e.code, `${AUTH_MESSAGES.insufficientScope} (needs ${e.scope})`),
|
|
42
|
+
unknown_token: (e) => withCode(e.code, `${AUTH_MESSAGES.unknownToken} (${e.id})`),
|
|
43
|
+
resource_metadata_unavailable: formatHint,
|
|
44
|
+
session_required: formatMessage(AUTH_MESSAGES.sessionRequired),
|
|
45
|
+
invalid_grant: formatMessage(AUTH_MESSAGES.invalidGrant),
|
|
46
|
+
admin_required: formatMessage(AUTH_MESSAGES.adminRequired),
|
|
47
|
+
username_taken: (e) => withCode(e.code, `${AUTH_MESSAGES.usernameTaken} (${e.username})`),
|
|
48
|
+
cannot_change_self: formatMessage(AUTH_MESSAGES.cannotChangeSelf),
|
|
49
|
+
last_admin: formatMessage(AUTH_MESSAGES.lastAdmin),
|
|
50
|
+
invalid_invite: formatMessage(AUTH_MESSAGES.invalidInvite),
|
|
51
|
+
user_disabled: formatMessage(AUTH_MESSAGES.userDisabled),
|
|
52
|
+
};
|
|
53
|
+
const FORMATTERS = {
|
|
54
|
+
...LOOKUP_FORMATTERS,
|
|
55
|
+
...DOMAIN_FORMATTERS,
|
|
56
|
+
...AUTH_FORMATTERS,
|
|
57
|
+
};
|
|
58
|
+
export const formatAppError = (e) => FORMATTERS[e.code](e);
|
|
59
|
+
const STATUS = {
|
|
60
|
+
notFound: 404,
|
|
61
|
+
unauthorized: 401,
|
|
62
|
+
forbidden: 403,
|
|
63
|
+
tooManyRequests: 429,
|
|
64
|
+
conflict: 409,
|
|
65
|
+
unprocessable: 422,
|
|
66
|
+
};
|
|
67
|
+
const HTTP_STATUS = {
|
|
68
|
+
unknown_account: STATUS.notFound,
|
|
69
|
+
unknown_category: STATUS.notFound,
|
|
70
|
+
unknown_sub_category: STATUS.notFound,
|
|
71
|
+
unknown_card: STATUS.notFound,
|
|
72
|
+
unknown_transaction: STATUS.notFound,
|
|
73
|
+
unknown_bill: STATUS.notFound,
|
|
74
|
+
unknown_dashboard: STATUS.notFound,
|
|
75
|
+
unknown_budget: STATUS.notFound,
|
|
76
|
+
unknown_token: STATUS.notFound,
|
|
77
|
+
unknown_user: STATUS.notFound,
|
|
78
|
+
invalid_grant: STATUS.notFound,
|
|
79
|
+
admin_required: STATUS.notFound,
|
|
80
|
+
resource_metadata_unavailable: STATUS.notFound,
|
|
81
|
+
unauthenticated: STATUS.unauthorized,
|
|
82
|
+
invalid_credentials: STATUS.unauthorized,
|
|
83
|
+
invalid_token: STATUS.unauthorized,
|
|
84
|
+
invalid_setup_code: STATUS.forbidden,
|
|
85
|
+
invalid_invite: STATUS.forbidden,
|
|
86
|
+
forbidden_origin: STATUS.forbidden,
|
|
87
|
+
insufficient_scope: STATUS.forbidden,
|
|
88
|
+
session_required: STATUS.forbidden,
|
|
89
|
+
rate_limited: STATUS.tooManyRequests,
|
|
90
|
+
ambiguous_account: STATUS.conflict,
|
|
91
|
+
ambiguous_category: STATUS.conflict,
|
|
92
|
+
ambiguous_sub_category: STATUS.conflict,
|
|
93
|
+
ambiguous_card: STATUS.conflict,
|
|
94
|
+
duplicate_name: STATUS.conflict,
|
|
95
|
+
duplicate_budget: STATUS.conflict,
|
|
96
|
+
in_use: STATUS.conflict,
|
|
97
|
+
conflict: STATUS.conflict,
|
|
98
|
+
setup_unavailable: STATUS.conflict,
|
|
99
|
+
username_taken: STATUS.conflict,
|
|
100
|
+
cannot_change_self: STATUS.conflict,
|
|
101
|
+
last_admin: STATUS.conflict,
|
|
102
|
+
user_disabled: STATUS.conflict,
|
|
103
|
+
owner_unclaimed: STATUS.conflict,
|
|
104
|
+
category_kind_mismatch: STATUS.unprocessable,
|
|
105
|
+
not_expense_category: STATUS.unprocessable,
|
|
106
|
+
validation: STATUS.unprocessable,
|
|
107
|
+
};
|
|
108
|
+
export const httpStatus = (e) => HTTP_STATUS[e.code];
|
|
109
|
+
/**
|
|
110
|
+
* Where an error's `remedy` (a domain operation) becomes words: each edge passes the function that names that
|
|
111
|
+
* operation in its own vocabulary, so the domain never has to.
|
|
112
|
+
*/
|
|
113
|
+
export const withRemedyHint = (error, hintFor) => {
|
|
114
|
+
if (!('remedy' in error) || error.remedy === undefined)
|
|
115
|
+
return error;
|
|
116
|
+
const { remedy, ...rest } = error;
|
|
117
|
+
return { ...rest, hint: hintFor(remedy) };
|
|
118
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { LOG_PREFIX } from '../models/package.js';
|
|
2
|
+
/**
|
|
3
|
+
* Loopback-only bind host for the HTTP surface (sidecar and pure http mode). Deliberately
|
|
4
|
+
* NOT '::' or '0.0.0.0': this API is unauthenticated (ADR-013 assumes local-first, no auth),
|
|
5
|
+
* and binding the wildcard address makes it reachable from any device on the same LAN, not
|
|
6
|
+
* just this machine — verified empirically, not just in theory.
|
|
7
|
+
*/
|
|
8
|
+
export const LOOPBACK_HOST = '127.0.0.1';
|
|
9
|
+
/** The scheme every origin this server prints or compares for itself starts with (it serves plain HTTP). */
|
|
10
|
+
export const HTTP_SCHEME_PREFIX = 'http://';
|
|
11
|
+
/** Bind addresses meaning "every interface" — not a URL anyone can open. */
|
|
12
|
+
export const IPV4_WILDCARD_HOST = '0.0.0.0';
|
|
13
|
+
export const IPV6_WILDCARD_HOST = '::';
|
|
14
|
+
const WILDCARD_HOSTS = new Set([IPV4_WILDCARD_HOST, IPV6_WILDCARD_HOST]);
|
|
15
|
+
/** Browsers key cookies by host, not port — a second loopback name is how a temporary app gets cookies of its own. */
|
|
16
|
+
export const LOCALHOST_NAME = 'localhost';
|
|
17
|
+
const IPV6_LOOPBACK_HOST = '::1';
|
|
18
|
+
const IPV4_LOOPBACK_BLOCK = /^127\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
|
|
19
|
+
const MAX_IPV4_OCTET = 255;
|
|
20
|
+
const stripBrackets = (host) => (host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host);
|
|
21
|
+
/**
|
|
22
|
+
* True for a host that only this machine can reach: `localhost`, `::1`, or anything in 127.0.0.0/8.
|
|
23
|
+
* A wildcard bind is deliberately NOT loopback — it listens on every interface. Used both to derive
|
|
24
|
+
* the auth default from `HOST` and to refuse an unauthenticated non-loopback bind (ADR-033 §1).
|
|
25
|
+
*/
|
|
26
|
+
export const isLoopbackHost = (host) => {
|
|
27
|
+
const normalized = stripBrackets(host.trim().toLowerCase());
|
|
28
|
+
if (normalized === LOCALHOST_NAME || normalized === IPV6_LOOPBACK_HOST)
|
|
29
|
+
return true;
|
|
30
|
+
const octets = IPV4_LOOPBACK_BLOCK.exec(normalized)?.slice(1).map(Number);
|
|
31
|
+
return octets !== undefined && octets.every((octet) => octet <= MAX_IPV4_OCTET);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Origin (`http://host:port`) a user can actually open for a server bound to `host`. A wildcard
|
|
35
|
+
* bind is reachable through the machine's own loopback (e.g. a container's host-side port
|
|
36
|
+
* publish), so it prints `LOOPBACK_HOST`; any other host prints itself (IPv6 literals bracketed).
|
|
37
|
+
*/
|
|
38
|
+
export const httpOrigin = (host, port) => {
|
|
39
|
+
const reachableHost = WILDCARD_HOSTS.has(host) ? LOOPBACK_HOST : host;
|
|
40
|
+
return `${HTTP_SCHEME_PREFIX}${reachableHost.includes(':') ? `[${reachableHost}]` : reachableHost}:${port}`;
|
|
41
|
+
};
|
|
42
|
+
export const DASHBOARD_PATH = '/ui/overview';
|
|
43
|
+
export const isPortInUse = (e) => typeof e === 'object' &&
|
|
44
|
+
e !== null &&
|
|
45
|
+
e.code === 'EADDRINUSE' &&
|
|
46
|
+
typeof e.port === 'number';
|
|
47
|
+
/** Fatal (pure http) EADDRINUSE message: the retry command plus the URL the client should use. The
|
|
48
|
+
* error's own bind `address` names the host actually bound; absent, the default loopback applies. */
|
|
49
|
+
export const portInUseMessage = ({ port, address }) => `${LOG_PREFIX} ${portInUseReason(port)}.\n` +
|
|
50
|
+
`Set a different port and retry, e.g. PORT=${port + 1} patty\n` +
|
|
51
|
+
`Then point your MCP client at ${httpOrigin(address ?? LOOPBACK_HOST, port + 1)}/mcp`;
|
|
52
|
+
/** Shared wording for both the fatal (pure http) and non-fatal (sidecar) EADDRINUSE messages. */
|
|
53
|
+
export const portInUseReason = (port) => `port ${port} is already in use (another service or MCP server is on it)`;
|
|
54
|
+
/** The hostname of a `Host` request header (port stripped, IPv6 unbracketed), or `null` if it is not a
|
|
55
|
+
* well-formed host. A `Host` is an authority — `host[:port]` and nothing else — so userinfo (`x@host`), a path,
|
|
56
|
+
* query or fragment (`host/x`, which a backslash also introduces) make it malformed rather than being quietly
|
|
57
|
+
* ignored by the URL parser: a malformed header is never trusted as loopback. */
|
|
58
|
+
export const hostnameOfHostHeader = (hostHeader) => {
|
|
59
|
+
try {
|
|
60
|
+
const parsed = new URL(`${HTTP_SCHEME_PREFIX}${hostHeader}`);
|
|
61
|
+
const isBareAuthority = parsed.username === '' &&
|
|
62
|
+
parsed.password === '' &&
|
|
63
|
+
parsed.pathname === '/' &&
|
|
64
|
+
parsed.search === '' &&
|
|
65
|
+
parsed.hash === '';
|
|
66
|
+
return isBareAuthority ? stripBrackets(parsed.hostname) : null;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { err, ok } from 'neverthrow';
|
|
2
|
+
/** Lift a nullable into Result — `yield* okOr(maybe, error)` in safeTry pipelines. */
|
|
3
|
+
export const okOr = (value, error) => value != null ? ok(value) : err(error);
|
|
4
|
+
/** Declarative precondition — `yield* guard(cond, error)` short-circuits when violated. */
|
|
5
|
+
export const guard = (condition, error) => condition ? ok(undefined) : err(error);
|
|
6
|
+
/** A pure guard's verdict as a Result: `null` = allowed, otherwise the refusal. */
|
|
7
|
+
export const orRefuse = (refusal) => refusal === null ? ok(undefined) : err(refusal);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import * as authAdapters from '../adapters/auth.js';
|
|
3
|
+
import { formatAppError } from '../common/errors.js';
|
|
4
|
+
import { McpTransport } from '../config.js';
|
|
5
|
+
import { issueSetupCode } from '../controllers/auth/owner.js';
|
|
6
|
+
import { pruneExpiredSessions } from '../controllers/auth/session.js';
|
|
7
|
+
import { pruneExpiredGrants } from '../controllers/auth/grants.js';
|
|
8
|
+
import { pruneExpiredInvites } from '../controllers/auth/users.js';
|
|
9
|
+
import { createSignInFor } from './sign-in/wiring.js';
|
|
10
|
+
import { accessTokenApplier, accessTokensRepo } from '../diplomat/db/repos/access-tokens.js';
|
|
11
|
+
import { clientGrantApplier, clientGrantsRepo } from '../diplomat/db/repos/client-grants.js';
|
|
12
|
+
import { instanceSettingsApplier, instanceSettingsRepo } from '../diplomat/db/repos/instance-settings.js';
|
|
13
|
+
import { inviteApplier, invitesRepo } from '../diplomat/db/repos/invites.js';
|
|
14
|
+
import { sessionApplier, sessionsRepo } from '../diplomat/db/repos/sessions.js';
|
|
15
|
+
import { setupCodeApplier, setupCodesRepo } from '../diplomat/db/repos/setup-codes.js';
|
|
16
|
+
import { userApplier, usersRepo } from '../diplomat/db/repos/users.js';
|
|
17
|
+
import { SETUP_PATH } from '../diplomat/http/auth-paths.js';
|
|
18
|
+
import { DISABLED_AUTH } from '../diplomat/http/context.js';
|
|
19
|
+
import { setupBanner } from '../logic/auth/message.js';
|
|
20
|
+
import { ACCESS_TOKEN_ENTITY_TAG, CLIENT_GRANT_ENTITY_TAG, INSTANCE_SETTINGS_ENTITY_TAG, INVITE_ENTITY_TAG, SESSION_ENTITY_TAG, SETUP_CODE_ENTITY_TAG, USER_ENTITY_TAG, } from '../models/auth/entity.js';
|
|
21
|
+
import { AuthMode } from '../models/auth/mode.js';
|
|
22
|
+
import { LOG_PREFIX } from '../models/package.js';
|
|
23
|
+
/**
|
|
24
|
+
* Lazily imports the credential primitives so `@node-rs/argon2`'s native module is never loaded unless
|
|
25
|
+
* an auth flow can run — an explicit `PATTY_AUTH=disabled` stdio run starts exactly as it did before ADR-033.
|
|
26
|
+
*/
|
|
27
|
+
export const loadCredentialsModule = () => import('../diplomat/auth/credentials.js');
|
|
28
|
+
/** The auth flows touch seven entities (user, session, setup code, access token, client grant, invite, instance
|
|
29
|
+
* settings) and the shell
|
|
30
|
+
* adapts model→row for each exactly once, here, before the generic runner sees the batch
|
|
31
|
+
* (docs/write-path.md § From model to row). */
|
|
32
|
+
export const bindAuthRunEffects = (runEffects) => (flow) => runEffects(() => flow().map(authAdapters.outcomeToDb));
|
|
33
|
+
export const AUTH_APPLIERS = {
|
|
34
|
+
[USER_ENTITY_TAG]: userApplier,
|
|
35
|
+
[SESSION_ENTITY_TAG]: sessionApplier,
|
|
36
|
+
[ACCESS_TOKEN_ENTITY_TAG]: accessTokenApplier,
|
|
37
|
+
[CLIENT_GRANT_ENTITY_TAG]: clientGrantApplier,
|
|
38
|
+
[SETUP_CODE_ENTITY_TAG]: setupCodeApplier,
|
|
39
|
+
[INVITE_ENTITY_TAG]: inviteApplier,
|
|
40
|
+
[INSTANCE_SETTINGS_ENTITY_TAG]: instanceSettingsApplier,
|
|
41
|
+
};
|
|
42
|
+
export const createAuthDeps = async (db) => {
|
|
43
|
+
const { createSecrets } = await loadCredentialsModule();
|
|
44
|
+
return {
|
|
45
|
+
users: usersRepo(db),
|
|
46
|
+
sessions: sessionsRepo(db),
|
|
47
|
+
accessTokens: accessTokensRepo(db),
|
|
48
|
+
clientGrants: clientGrantsRepo(db),
|
|
49
|
+
invites: invitesRepo(db),
|
|
50
|
+
instanceSettings: instanceSettingsRepo(db),
|
|
51
|
+
setupCodes: setupCodesRepo(db),
|
|
52
|
+
clock: () => new Date(),
|
|
53
|
+
newId: () => randomUUID(),
|
|
54
|
+
secrets: await createSecrets(),
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const isSecureOrigin = (publicUrl) => publicUrl?.startsWith('https://') ?? false;
|
|
58
|
+
/** Whether anything will serve HTTP in this run — sessions only matter if so. */
|
|
59
|
+
export const httpSurfaceEnabled = (config) => config.MCP_TRANSPORT === McpTransport.enum.http || config.PATTY_HTTP;
|
|
60
|
+
const NO_SETUP_TO_ISSUE = async () => undefined;
|
|
61
|
+
const housekeeping = async (run, deps) => {
|
|
62
|
+
const sessions = await run(() => pruneExpiredSessions(deps));
|
|
63
|
+
if (sessions.isErr())
|
|
64
|
+
throw new Error(`${LOG_PREFIX} could not prune expired sessions — ${formatAppError(sessions.error)}`);
|
|
65
|
+
const grants = await run(() => pruneExpiredGrants(deps));
|
|
66
|
+
if (grants.isErr())
|
|
67
|
+
throw new Error(`${LOG_PREFIX} could not prune expired sign-ins — ${formatAppError(grants.error)}`);
|
|
68
|
+
const invites = await run(() => pruneExpiredInvites(deps));
|
|
69
|
+
if (invites.isErr())
|
|
70
|
+
throw new Error(`${LOG_PREFIX} could not prune expired invites — ${formatAppError(invites.error)}`);
|
|
71
|
+
};
|
|
72
|
+
export const prepareAuth = async (config, db, runEffects) => {
|
|
73
|
+
if (config.PATTY_AUTH === AuthMode.enum.disabled) {
|
|
74
|
+
return { auth: DISABLED_AUTH, stdio: null, issueAndAnnounceSetup: NO_SETUP_TO_ISSUE };
|
|
75
|
+
}
|
|
76
|
+
const deps = await createAuthDeps(db);
|
|
77
|
+
const run = bindAuthRunEffects(runEffects);
|
|
78
|
+
await housekeeping(run, deps);
|
|
79
|
+
const stdio = config.MCP_TRANSPORT === McpTransport.enum.stdio
|
|
80
|
+
? {
|
|
81
|
+
signIn: (profile, origin) => createSignInFor({ config, db, deps, run }, { profile, origin, canServePage: config.PATTY_HTTP }),
|
|
82
|
+
}
|
|
83
|
+
: null;
|
|
84
|
+
if (!httpSurfaceEnabled(config))
|
|
85
|
+
return { auth: DISABLED_AUTH, stdio, issueAndAnnounceSetup: NO_SETUP_TO_ISSUE };
|
|
86
|
+
return {
|
|
87
|
+
auth: {
|
|
88
|
+
mode: AuthMode.enum.required,
|
|
89
|
+
deps,
|
|
90
|
+
runEffects: run,
|
|
91
|
+
publicUrl: config.PUBLIC_URL,
|
|
92
|
+
secureCookie: isSecureOrigin(config.PUBLIC_URL),
|
|
93
|
+
},
|
|
94
|
+
stdio,
|
|
95
|
+
issueAndAnnounceSetup: async (boundOrigin, announce = console.error) => {
|
|
96
|
+
const issued = await run(() => issueSetupCode(deps, config.PATTY_AUTH));
|
|
97
|
+
if (issued.isErr())
|
|
98
|
+
throw new Error(`${LOG_PREFIX} could not issue a setup code — ${formatAppError(issued.error)}`);
|
|
99
|
+
const code = issued.value;
|
|
100
|
+
if (!code)
|
|
101
|
+
return;
|
|
102
|
+
const origin = config.PUBLIC_URL ?? boundOrigin;
|
|
103
|
+
announce(setupBanner({ code: code.code, setupUrl: `${origin}${SETUP_PATH}`, expiresAt: code.expiresAt }));
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { err, ok, safeTry } from 'neverthrow';
|
|
2
|
+
import { bootstrap } from '../diplomat/db/bootstrap.js';
|
|
3
|
+
import { databaseExists } from '../diplomat/db/database-files.js';
|
|
4
|
+
import { closeDatabase, openDatabase } from '../diplomat/db/driver.js';
|
|
5
|
+
import { demoNotReady } from '../models/demo/core.js';
|
|
6
|
+
import { isDemoInstance } from '../models/instance.js';
|
|
7
|
+
import { prepareAuth } from './auth.js';
|
|
8
|
+
import { createRuntime } from './runtime.js';
|
|
9
|
+
/**
|
|
10
|
+
* What every server start shares, in order: open the database, bootstrap it (version guard, safety copy, migrations,
|
|
11
|
+
* seed), assemble the runtime, and decide what demands a login (ADR-033, ADR-034). `stdio.ts` and `http.ts` then
|
|
12
|
+
* differ only in what they serve.
|
|
13
|
+
*/
|
|
14
|
+
export const boot = (config) => safeTry(async function* () {
|
|
15
|
+
// Never create a file (least of all the real database's) just to look.
|
|
16
|
+
if (config.PATTY_DEMO && !databaseExists(config.DB_PATH))
|
|
17
|
+
return err(demoNotReady(config.DB_PATH));
|
|
18
|
+
const db = await openDatabase(config);
|
|
19
|
+
yield* bootstrap(db);
|
|
20
|
+
const runtime = createRuntime(db, config);
|
|
21
|
+
if (config.PATTY_DEMO && !isDemoInstance(await runtime.instanceKind())) {
|
|
22
|
+
closeDatabase(db);
|
|
23
|
+
return err(demoNotReady(config.DB_PATH));
|
|
24
|
+
}
|
|
25
|
+
const prepared = await prepareAuth(config, db, runtime.authRunEffects);
|
|
26
|
+
return ok({ db, runtime, prepared });
|
|
27
|
+
});
|