@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,263 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as accountAdapters from '../../../adapters/accounts.js';
|
|
3
|
+
import * as billAdapters from '../../../adapters/bills.js';
|
|
4
|
+
import * as creditCardAdapters from '../../../adapters/credit-cards.js';
|
|
5
|
+
import * as transactionAdapters from '../../../adapters/transactions.js';
|
|
6
|
+
import { getBill, payBill, revertBillPayment } from '../../../controllers/credit-card/bill.js';
|
|
7
|
+
import { createCreditCard, deleteCreditCard, listCreditCards, updateCreditCard, } from '../../../controllers/credit-card/credit-card.js';
|
|
8
|
+
import { addCardPurchase, deleteCardTransaction, importCardStatement, updateCardTransaction, } from '../../../controllers/credit-card/transaction.js';
|
|
9
|
+
import { buildBulkResult } from '../../../controllers/transaction/bulk.js';
|
|
10
|
+
import { BillSchema } from '../../../models/bill.js';
|
|
11
|
+
import { CreditCardSchema } from '../../../models/credit-card.js';
|
|
12
|
+
import { TransactionSource, TransactionViewSchema } from '../../../models/transaction.js';
|
|
13
|
+
import { BillQuery, PayBill, } from '../../../wire/in/bills.js';
|
|
14
|
+
import * as wireInCreditCards from '../../../wire/in/credit-cards.js';
|
|
15
|
+
import { BillViewOut } from '../../../wire/out/bills.js';
|
|
16
|
+
import { DeleteCreditCardResultOut } from '../../../wire/out/credit-cards.js';
|
|
17
|
+
import { BulkResultOut, CreateTransactionOut, DeleteTransactionOut } from '../../../wire/out/transactions.js';
|
|
18
|
+
import { REMEDY_ROUTE } from '../remedy.js';
|
|
19
|
+
import { jsonBody, okResponse } from '../openapi.js';
|
|
20
|
+
import { conflict409, confirmQuery, idParam, isConfirmed, nameParam, notFound404, parse, pathParam, send, sendUpsert, validation422, } from '../respond.js';
|
|
21
|
+
import { READ_SCOPE, WRITE_SCOPE } from '../../../models/auth/scope.js';
|
|
22
|
+
const CREDIT_CARDS_TAG = 'CreditCards';
|
|
23
|
+
const BILLS_TAG = 'Bills';
|
|
24
|
+
const addCardPurchaseRoute = {
|
|
25
|
+
method: 'post',
|
|
26
|
+
scope: WRITE_SCOPE,
|
|
27
|
+
path: '/api/credit-cards/purchases',
|
|
28
|
+
tags: [CREDIT_CARDS_TAG],
|
|
29
|
+
summary: 'Add a credit-card purchase',
|
|
30
|
+
request: { body: jsonBody(wireInCreditCards.AddCardPurchaseSchema) },
|
|
31
|
+
responses: {
|
|
32
|
+
200: okResponse('Existing purchase returned (idempotent replay)', CreateTransactionOut),
|
|
33
|
+
201: okResponse('Purchase recorded', CreateTransactionOut),
|
|
34
|
+
404: notFound404,
|
|
35
|
+
409: conflict409,
|
|
36
|
+
422: validation422,
|
|
37
|
+
},
|
|
38
|
+
handler: async (req, reply, scope) => {
|
|
39
|
+
const { deps, runEffects } = scope();
|
|
40
|
+
const wireIn = parse(wireInCreditCards.AddCardPurchaseSchema, req.body, reply);
|
|
41
|
+
if (!wireIn)
|
|
42
|
+
return reply;
|
|
43
|
+
const model = creditCardAdapters.addCardPurchaseWireInToModel(wireIn);
|
|
44
|
+
const flow = () => addCardPurchase(deps, model, TransactionSource.enum.rest)
|
|
45
|
+
.map(billAdapters.outcomeToDb)
|
|
46
|
+
.map(transactionAdapters.outcomeToDb);
|
|
47
|
+
return sendUpsert(reply, (await runEffects(flow)).map(transactionAdapters.createResultToWireOut));
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
const importCardStatementRoute = {
|
|
51
|
+
method: 'post',
|
|
52
|
+
scope: WRITE_SCOPE,
|
|
53
|
+
path: '/api/credit-cards/statement',
|
|
54
|
+
tags: [CREDIT_CARDS_TAG],
|
|
55
|
+
summary: 'Import a credit-card statement',
|
|
56
|
+
request: { body: jsonBody(wireInCreditCards.ImportCardStatementSchema) },
|
|
57
|
+
responses: { 201: okResponse('Import result', BulkResultOut), 422: validation422 },
|
|
58
|
+
// Orchestration (plan → run each line → bulk result) that belongs in a controller; kept as one named step here
|
|
59
|
+
// until the controllers can hand back the adapted flow (the adapters are the edge's).
|
|
60
|
+
handler: async (req, reply, scope) => {
|
|
61
|
+
const { deps, runEffectsSequence } = scope();
|
|
62
|
+
const wireIn = parse(wireInCreditCards.ImportCardStatementSchema, req.body, reply);
|
|
63
|
+
if (!wireIn)
|
|
64
|
+
return reply;
|
|
65
|
+
const plan = await importCardStatement(deps, creditCardAdapters.importCardStatementWireInToModel(wireIn), TransactionSource.enum.import);
|
|
66
|
+
const outcomes = await runEffectsSequence(plan.lines, (line) => () => plan.flowFor(line)().map(billAdapters.outcomeToDb).map(transactionAdapters.outcomeToDb));
|
|
67
|
+
return reply.status(201).send(transactionAdapters.bulkResultToWireOut(buildBulkResult(outcomes, plan.lines)));
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const listCreditCardsRoute = {
|
|
71
|
+
method: 'get',
|
|
72
|
+
scope: READ_SCOPE,
|
|
73
|
+
path: '/api/credit-cards',
|
|
74
|
+
tags: [CREDIT_CARDS_TAG],
|
|
75
|
+
summary: 'List credit cards',
|
|
76
|
+
responses: { 200: okResponse('Credit cards', z.array(CreditCardSchema)) },
|
|
77
|
+
handler: async (_req, _reply, scope) => listCreditCards(scope().deps),
|
|
78
|
+
};
|
|
79
|
+
const createCreditCardRoute = {
|
|
80
|
+
...REMEDY_ROUTE.create_credit_card,
|
|
81
|
+
scope: WRITE_SCOPE,
|
|
82
|
+
tags: [CREDIT_CARDS_TAG],
|
|
83
|
+
summary: 'Create credit card',
|
|
84
|
+
request: { body: jsonBody(wireInCreditCards.CreateCreditCardSchema) },
|
|
85
|
+
responses: {
|
|
86
|
+
201: okResponse('Credit card created', CreditCardSchema),
|
|
87
|
+
404: notFound404,
|
|
88
|
+
409: conflict409,
|
|
89
|
+
422: validation422,
|
|
90
|
+
},
|
|
91
|
+
handler: async (req, reply, scope) => {
|
|
92
|
+
const { deps, runEffects } = scope();
|
|
93
|
+
const wireIn = parse(wireInCreditCards.CreateCreditCardSchema, req.body, reply);
|
|
94
|
+
if (!wireIn)
|
|
95
|
+
return reply;
|
|
96
|
+
const flow = () => createCreditCard(deps, creditCardAdapters.wireInToModel(wireIn))
|
|
97
|
+
.map(accountAdapters.outcomeToDb)
|
|
98
|
+
.map(creditCardAdapters.outcomeToDb);
|
|
99
|
+
return send(reply, await runEffects(flow), 201);
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
const updateCreditCardRoute = {
|
|
103
|
+
...REMEDY_ROUTE.update_credit_card,
|
|
104
|
+
scope: WRITE_SCOPE,
|
|
105
|
+
tags: [CREDIT_CARDS_TAG],
|
|
106
|
+
summary: 'Update credit card',
|
|
107
|
+
request: { params: nameParam, body: jsonBody(wireInCreditCards.UpdateCreditCardSchema.omit({ name: true })) },
|
|
108
|
+
responses: {
|
|
109
|
+
200: okResponse('Credit card updated', CreditCardSchema),
|
|
110
|
+
404: notFound404,
|
|
111
|
+
409: conflict409,
|
|
112
|
+
422: validation422,
|
|
113
|
+
},
|
|
114
|
+
handler: async (req, reply, scope) => {
|
|
115
|
+
const { deps, runEffects } = scope();
|
|
116
|
+
const name = pathParam(req, 'name');
|
|
117
|
+
const wireIn = parse(wireInCreditCards.UpdateCreditCardSchema, { ...(req.body ?? {}), name }, reply);
|
|
118
|
+
if (!wireIn)
|
|
119
|
+
return reply;
|
|
120
|
+
const flow = () => updateCreditCard(deps, creditCardAdapters.updateWireInToModel(wireIn))
|
|
121
|
+
.map(accountAdapters.outcomeToDb)
|
|
122
|
+
.map(creditCardAdapters.outcomeToDb);
|
|
123
|
+
return send(reply, await runEffects(flow));
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
const deleteCreditCardRoute = {
|
|
127
|
+
...REMEDY_ROUTE.delete_credit_card,
|
|
128
|
+
scope: WRITE_SCOPE,
|
|
129
|
+
tags: [CREDIT_CARDS_TAG],
|
|
130
|
+
summary: 'Delete credit card',
|
|
131
|
+
request: { params: nameParam, query: confirmQuery },
|
|
132
|
+
responses: {
|
|
133
|
+
200: okResponse('Deleted, or dry-run preview when confirm is omitted', DeleteCreditCardResultOut),
|
|
134
|
+
404: notFound404,
|
|
135
|
+
409: conflict409,
|
|
136
|
+
},
|
|
137
|
+
handler: async (req, reply, scope) => {
|
|
138
|
+
const { deps, runEffects } = scope();
|
|
139
|
+
const input = { card: pathParam(req, 'name'), confirm: isConfirmed(req) };
|
|
140
|
+
const flow = () => deleteCreditCard(deps, input)
|
|
141
|
+
.map(creditCardAdapters.outcomeToDb)
|
|
142
|
+
.map(accountAdapters.outcomeToDb)
|
|
143
|
+
.map(billAdapters.outcomeToDb)
|
|
144
|
+
.map(transactionAdapters.outcomeToDb);
|
|
145
|
+
return send(reply, await runEffects(flow));
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
const getBillRoute = {
|
|
149
|
+
method: 'get',
|
|
150
|
+
scope: READ_SCOPE,
|
|
151
|
+
path: '/api/bills',
|
|
152
|
+
tags: [BILLS_TAG],
|
|
153
|
+
summary: 'Get a credit card bill (fatura)',
|
|
154
|
+
request: { query: BillQuery },
|
|
155
|
+
responses: {
|
|
156
|
+
200: okResponse('Bill with items', BillViewOut),
|
|
157
|
+
404: notFound404,
|
|
158
|
+
409: conflict409,
|
|
159
|
+
422: validation422,
|
|
160
|
+
},
|
|
161
|
+
handler: async (req, reply, scope) => {
|
|
162
|
+
const input = parse(BillQuery, req.query, reply);
|
|
163
|
+
if (!input)
|
|
164
|
+
return reply;
|
|
165
|
+
return send(reply, await getBill(scope().deps, input));
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
const payBillRoute = {
|
|
169
|
+
...REMEDY_ROUTE.pay_bill,
|
|
170
|
+
scope: WRITE_SCOPE,
|
|
171
|
+
tags: [BILLS_TAG],
|
|
172
|
+
summary: 'Pay a credit card bill',
|
|
173
|
+
request: { body: jsonBody(PayBill) },
|
|
174
|
+
responses: { 200: okResponse('Bill paid', BillSchema), 404: notFound404, 409: conflict409, 422: validation422 },
|
|
175
|
+
handler: async (req, reply, scope) => {
|
|
176
|
+
const { deps, runEffects } = scope();
|
|
177
|
+
const input = parse(PayBill, req.body, reply);
|
|
178
|
+
if (!input)
|
|
179
|
+
return reply;
|
|
180
|
+
const flow = () => payBill(deps, { ...input, source: TransactionSource.enum.rest })
|
|
181
|
+
.map(billAdapters.outcomeToDb)
|
|
182
|
+
.map(transactionAdapters.outcomeToDb);
|
|
183
|
+
return send(reply, await runEffects(flow));
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
const revertBillPaymentRoute = {
|
|
187
|
+
...REMEDY_ROUTE.revert_bill_payment,
|
|
188
|
+
scope: WRITE_SCOPE,
|
|
189
|
+
tags: [BILLS_TAG],
|
|
190
|
+
summary: 'Revert a credit card bill payment',
|
|
191
|
+
request: { body: jsonBody(BillQuery) },
|
|
192
|
+
responses: {
|
|
193
|
+
200: okResponse('Bill payment reverted (or no-op if not paid)', BillSchema),
|
|
194
|
+
404: notFound404,
|
|
195
|
+
409: conflict409,
|
|
196
|
+
422: validation422,
|
|
197
|
+
},
|
|
198
|
+
handler: async (req, reply, scope) => {
|
|
199
|
+
const { deps, runEffects } = scope();
|
|
200
|
+
const input = parse(BillQuery, req.body, reply);
|
|
201
|
+
if (!input)
|
|
202
|
+
return reply;
|
|
203
|
+
const flow = () => revertBillPayment(deps, input).map(billAdapters.outcomeToDb).map(transactionAdapters.outcomeToDb);
|
|
204
|
+
return send(reply, await runEffects(flow));
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
const updateCardTransactionRoute = {
|
|
208
|
+
...REMEDY_ROUTE.update_card_transaction,
|
|
209
|
+
scope: WRITE_SCOPE,
|
|
210
|
+
tags: [CREDIT_CARDS_TAG],
|
|
211
|
+
summary: 'Update a credit-card transaction',
|
|
212
|
+
request: {
|
|
213
|
+
params: idParam,
|
|
214
|
+
body: jsonBody(wireInCreditCards.UpdateCardTransactionSchema.omit({ id: true })),
|
|
215
|
+
},
|
|
216
|
+
responses: {
|
|
217
|
+
200: okResponse('Transaction updated', TransactionViewSchema),
|
|
218
|
+
404: notFound404,
|
|
219
|
+
409: conflict409,
|
|
220
|
+
422: validation422,
|
|
221
|
+
},
|
|
222
|
+
handler: async (req, reply, scope) => {
|
|
223
|
+
const { deps, runEffects } = scope();
|
|
224
|
+
const id = pathParam(req, 'id');
|
|
225
|
+
const wireIn = parse(wireInCreditCards.UpdateCardTransactionSchema, { ...req.body, id }, reply);
|
|
226
|
+
if (!wireIn)
|
|
227
|
+
return reply;
|
|
228
|
+
const model = creditCardAdapters.updateCardTransactionWireInToModel(wireIn);
|
|
229
|
+
const flow = () => updateCardTransaction(deps, model).map(billAdapters.outcomeToDb).map(transactionAdapters.outcomeToDb);
|
|
230
|
+
return send(reply, await runEffects(flow));
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
const deleteCardTransactionRoute = {
|
|
234
|
+
...REMEDY_ROUTE.delete_card_transaction,
|
|
235
|
+
scope: WRITE_SCOPE,
|
|
236
|
+
tags: [CREDIT_CARDS_TAG],
|
|
237
|
+
summary: 'Delete a credit-card transaction',
|
|
238
|
+
request: { params: idParam, query: confirmQuery },
|
|
239
|
+
responses: {
|
|
240
|
+
200: okResponse('Deleted, or dry-run preview when confirm is omitted', DeleteTransactionOut),
|
|
241
|
+
404: notFound404,
|
|
242
|
+
422: validation422,
|
|
243
|
+
},
|
|
244
|
+
handler: async (req, reply, scope) => {
|
|
245
|
+
const { deps, runEffects } = scope();
|
|
246
|
+
const input = { id: pathParam(req, 'id'), confirm: isConfirmed(req) };
|
|
247
|
+
const flow = () => deleteCardTransaction(deps, input).map(billAdapters.outcomeToDb).map(transactionAdapters.outcomeToDb);
|
|
248
|
+
return send(reply, (await runEffects(flow)).map(transactionAdapters.deleteResultToWireOut));
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
export const creditCardRoutes = [
|
|
252
|
+
addCardPurchaseRoute,
|
|
253
|
+
importCardStatementRoute,
|
|
254
|
+
listCreditCardsRoute,
|
|
255
|
+
createCreditCardRoute,
|
|
256
|
+
updateCreditCardRoute,
|
|
257
|
+
deleteCreditCardRoute,
|
|
258
|
+
getBillRoute,
|
|
259
|
+
payBillRoute,
|
|
260
|
+
revertBillPaymentRoute,
|
|
261
|
+
updateCardTransactionRoute,
|
|
262
|
+
deleteCardTransactionRoute,
|
|
263
|
+
];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { listExchangeRates, setExchangeRate } from '../../../controllers/currency-rates.js';
|
|
3
|
+
import { buildBulkResult } from '../../../logic/currency-rate.js';
|
|
4
|
+
import { CurrencyRateViewSchema, SetExchangeRateSchema } from '../../../models/currency-rate.js';
|
|
5
|
+
import * as currencyRateAdapters from '../../../adapters/currency-rates.js';
|
|
6
|
+
import { SetExchangeRatesSchema } from '../../../wire/in/currency-rates.js';
|
|
7
|
+
import { BulkSetExchangeRatesOut } from '../../../wire/out/currency-rates.js';
|
|
8
|
+
import { jsonBody, okResponse } from '../openapi.js';
|
|
9
|
+
import { parse, send, validation422 } from '../respond.js';
|
|
10
|
+
import { READ_SCOPE, WRITE_SCOPE } from '../../../models/auth/scope.js';
|
|
11
|
+
const EXCHANGE_RATES_TAG = 'Exchange rates';
|
|
12
|
+
const listExchangeRatesRoute = {
|
|
13
|
+
method: 'get',
|
|
14
|
+
scope: READ_SCOPE,
|
|
15
|
+
path: '/api/exchange-rates',
|
|
16
|
+
tags: [EXCHANGE_RATES_TAG],
|
|
17
|
+
summary: 'List exchange rates',
|
|
18
|
+
responses: { 200: okResponse('Exchange rates', z.array(CurrencyRateViewSchema)) },
|
|
19
|
+
handler: async (_req, _reply, scope) => listExchangeRates(scope().deps),
|
|
20
|
+
};
|
|
21
|
+
const setExchangeRateRoute = {
|
|
22
|
+
method: 'post',
|
|
23
|
+
scope: WRITE_SCOPE,
|
|
24
|
+
path: '/api/exchange-rates',
|
|
25
|
+
tags: [EXCHANGE_RATES_TAG],
|
|
26
|
+
summary: 'Set exchange rate (upsert)',
|
|
27
|
+
request: { body: jsonBody(SetExchangeRateSchema) },
|
|
28
|
+
responses: { 200: okResponse('Rate upserted', CurrencyRateViewSchema), 422: validation422 },
|
|
29
|
+
handler: async (req, reply, scope) => {
|
|
30
|
+
const { deps, runEffects } = scope();
|
|
31
|
+
const input = parse(SetExchangeRateSchema, req.body, reply);
|
|
32
|
+
if (!input)
|
|
33
|
+
return reply;
|
|
34
|
+
const flow = () => setExchangeRate(deps, input).map(currencyRateAdapters.outcomeToDb);
|
|
35
|
+
return send(reply, await runEffects(flow));
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
const setExchangeRatesRoute = {
|
|
39
|
+
method: 'post',
|
|
40
|
+
scope: WRITE_SCOPE,
|
|
41
|
+
path: '/api/exchange-rates/bulk',
|
|
42
|
+
tags: [EXCHANGE_RATES_TAG],
|
|
43
|
+
summary: 'Set exchange rates (bulk upsert, partial success)',
|
|
44
|
+
request: { body: jsonBody(SetExchangeRatesSchema) },
|
|
45
|
+
responses: { 200: okResponse('Bulk upsert result', BulkSetExchangeRatesOut), 422: validation422 },
|
|
46
|
+
// Orchestration (plan → run each item → bulk result) that belongs in a controller; kept as one named step here.
|
|
47
|
+
handler: async (req, reply, scope) => {
|
|
48
|
+
const { deps, runEffectsSequence } = scope();
|
|
49
|
+
const input = parse(SetExchangeRatesSchema, req.body, reply);
|
|
50
|
+
if (!input)
|
|
51
|
+
return reply;
|
|
52
|
+
const outcomes = await runEffectsSequence(input.rates, (item) => () => setExchangeRate(deps, item).map(currencyRateAdapters.outcomeToDb));
|
|
53
|
+
return reply.send(currencyRateAdapters.bulkResultToWireOut(buildBulkResult(input.rates, outcomes)));
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
export const currencyRateRoutes = [
|
|
57
|
+
listExchangeRatesRoute,
|
|
58
|
+
setExchangeRateRoute,
|
|
59
|
+
setExchangeRatesRoute,
|
|
60
|
+
];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { listCurrencies } from '../../../controllers/currencies.js';
|
|
3
|
+
import { CurrencySchema } from '../../../models/money.js';
|
|
4
|
+
import { okResponse } from '../openapi.js';
|
|
5
|
+
import { READ_SCOPE } from '../../../models/auth/scope.js';
|
|
6
|
+
const CURRENCIES_TAG = 'Currencies';
|
|
7
|
+
const listCurrenciesRoute = {
|
|
8
|
+
method: 'get',
|
|
9
|
+
scope: READ_SCOPE,
|
|
10
|
+
path: '/api/currencies',
|
|
11
|
+
tags: [CURRENCIES_TAG],
|
|
12
|
+
summary: 'List currencies',
|
|
13
|
+
responses: { 200: okResponse('Currencies', z.array(CurrencySchema)) },
|
|
14
|
+
handler: async (_req, _reply, scope) => listCurrencies(scope().deps),
|
|
15
|
+
};
|
|
16
|
+
export const currencyRoutes = [listCurrenciesRoute];
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as dashboardAdapters from '../../../adapters/dashboards.js';
|
|
3
|
+
import { deleteDashboard, getDashboard, listDashboards, renameDashboard, saveDashboard, } from '../../../controllers/dashboards.js';
|
|
4
|
+
import { DashboardListItemSchema, DashboardSchema, RenameDashboardSchema, SaveDashboardSchema, } from '../../../models/dashboard.js';
|
|
5
|
+
import { DeletedOut } from '../../../wire/out/common.js';
|
|
6
|
+
import { jsonBody, okResponse } from '../openapi.js';
|
|
7
|
+
import { CACHE_CONTROL_NO_CACHE, conflict409, nameParam, notFound404, parse, pathParam, send, validation422, } from '../respond.js';
|
|
8
|
+
import { READ_SCOPE, WRITE_SCOPE } from '../../../models/auth/scope.js';
|
|
9
|
+
const DASHBOARDS_TAG = 'Dashboards';
|
|
10
|
+
const renameDashboardBody = RenameDashboardSchema.pick({ newName: true });
|
|
11
|
+
const listDashboardsRoute = {
|
|
12
|
+
method: 'get',
|
|
13
|
+
scope: READ_SCOPE,
|
|
14
|
+
path: '/api/dashboards',
|
|
15
|
+
tags: [DASHBOARDS_TAG],
|
|
16
|
+
summary: 'List dashboards',
|
|
17
|
+
responses: { 200: okResponse('Dashboards (HTML omitted)', z.array(DashboardListItemSchema)) },
|
|
18
|
+
handler: async (_req, _reply, scope) => listDashboards(scope().deps),
|
|
19
|
+
};
|
|
20
|
+
const getDashboardRoute = {
|
|
21
|
+
method: 'get',
|
|
22
|
+
scope: READ_SCOPE,
|
|
23
|
+
path: '/api/dashboards/:name',
|
|
24
|
+
tags: [DASHBOARDS_TAG],
|
|
25
|
+
summary: 'Get a dashboard as JSON',
|
|
26
|
+
request: { params: nameParam },
|
|
27
|
+
responses: { 200: okResponse('Dashboard', DashboardSchema), 404: notFound404 },
|
|
28
|
+
handler: async (req, reply, scope) => {
|
|
29
|
+
const result = await getDashboard(scope().deps, pathParam(req, 'name'));
|
|
30
|
+
reply.header('cache-control', CACHE_CONTROL_NO_CACHE);
|
|
31
|
+
return send(reply, result);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const saveDashboardRoute = {
|
|
35
|
+
method: 'post',
|
|
36
|
+
scope: WRITE_SCOPE,
|
|
37
|
+
path: '/api/dashboards',
|
|
38
|
+
tags: [DASHBOARDS_TAG],
|
|
39
|
+
summary: 'Save (upsert) a dashboard',
|
|
40
|
+
request: { body: jsonBody(SaveDashboardSchema) },
|
|
41
|
+
responses: { 200: okResponse('Dashboard saved', DashboardSchema), 422: validation422 },
|
|
42
|
+
handler: async (req, reply, scope) => {
|
|
43
|
+
const { deps, runEffects } = scope();
|
|
44
|
+
const wireIn = parse(SaveDashboardSchema, req.body, reply);
|
|
45
|
+
if (!wireIn)
|
|
46
|
+
return reply;
|
|
47
|
+
const flow = () => saveDashboard(deps, wireIn.name, wireIn.html).map(dashboardAdapters.outcomeToDb);
|
|
48
|
+
return send(reply, await runEffects(flow));
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const deleteDashboardRoute = {
|
|
52
|
+
method: 'delete',
|
|
53
|
+
scope: WRITE_SCOPE,
|
|
54
|
+
path: '/api/dashboards/:name',
|
|
55
|
+
tags: [DASHBOARDS_TAG],
|
|
56
|
+
summary: 'Delete dashboard',
|
|
57
|
+
request: { params: nameParam },
|
|
58
|
+
responses: { 200: okResponse('Dashboard deleted', DeletedOut) },
|
|
59
|
+
handler: async (req, reply, scope) => {
|
|
60
|
+
const { deps, runEffects } = scope();
|
|
61
|
+
const flow = () => deleteDashboard(deps, pathParam(req, 'name')).map(dashboardAdapters.outcomeToDb);
|
|
62
|
+
return send(reply, await runEffects(flow));
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
const renameDashboardRoute = {
|
|
66
|
+
method: 'post',
|
|
67
|
+
scope: WRITE_SCOPE,
|
|
68
|
+
path: '/api/dashboards/:name/rename',
|
|
69
|
+
tags: [DASHBOARDS_TAG],
|
|
70
|
+
summary: 'Rename a dashboard',
|
|
71
|
+
request: { params: nameParam, body: jsonBody(renameDashboardBody) },
|
|
72
|
+
responses: {
|
|
73
|
+
200: okResponse('Dashboard renamed', DashboardSchema),
|
|
74
|
+
404: notFound404,
|
|
75
|
+
409: conflict409,
|
|
76
|
+
422: validation422,
|
|
77
|
+
},
|
|
78
|
+
handler: async (req, reply, scope) => {
|
|
79
|
+
const { deps, runEffects } = scope();
|
|
80
|
+
const wireIn = parse(renameDashboardBody, req.body, reply);
|
|
81
|
+
if (!wireIn)
|
|
82
|
+
return reply;
|
|
83
|
+
const flow = () => renameDashboard(deps, pathParam(req, 'name'), wireIn.newName).map(dashboardAdapters.outcomeToDb);
|
|
84
|
+
return send(reply, await runEffects(flow));
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
export const dashboardRoutes = [
|
|
88
|
+
listDashboardsRoute,
|
|
89
|
+
getDashboardRoute,
|
|
90
|
+
saveDashboardRoute,
|
|
91
|
+
deleteDashboardRoute,
|
|
92
|
+
renameDashboardRoute,
|
|
93
|
+
];
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { httpStatus } from '../../../common/errors.js';
|
|
2
|
+
import { claimInvite } from '../../../controllers/auth/users.js';
|
|
3
|
+
import { normalizeInviteCode } from '../../../logic/auth/users.js';
|
|
4
|
+
import { authErrors } from '../../../models/auth/errors.js';
|
|
5
|
+
import { AUTH_MESSAGES } from '../../../models/auth/message.js';
|
|
6
|
+
import { DEFAULT_LANDING_PATH, INVITE_CODE_PARAM } from '../../../models/auth/origin.js';
|
|
7
|
+
import { validation } from '../../../models/error.js';
|
|
8
|
+
import { ClaimedCodeEchoSchema, ClaimInviteFormSchema, InviteQuerySchema } from '../../../wire/in/auth.js';
|
|
9
|
+
import { INVITE_PATH, SEE_OTHER } from '../auth-paths.js';
|
|
10
|
+
import { sessionCookie } from '../cookies.js';
|
|
11
|
+
import { addFormParser, FORM_BODY_LIMIT_BYTES, SECRET_URL_HEADERS, page } from '../form-pages.js';
|
|
12
|
+
import { createAttemptLimiter } from '../rate-limiter.js';
|
|
13
|
+
import { renderInvitePage } from '../user-pages.js';
|
|
14
|
+
const INVALID_FORM_STATUS = httpStatus(validation([]));
|
|
15
|
+
// What each refusal says on the claim page; every other failure is the generic "try again".
|
|
16
|
+
const REFUSAL_MESSAGE = {
|
|
17
|
+
[authErrors.invalidInvite.code]: AUTH_MESSAGES.invalidInvite,
|
|
18
|
+
[authErrors.rateLimited.code]: AUTH_MESSAGES.rateLimited,
|
|
19
|
+
};
|
|
20
|
+
const messageFor = (error) => REFUSAL_MESSAGE[error.code] ?? AUTH_MESSAGES.tryAgain;
|
|
21
|
+
// The link carries the code in its query string, so every answer from this page — the form and its failures — keeps
|
|
22
|
+
// the path and query out of any `Referer`.
|
|
23
|
+
const claimPage = async (reply, status, fields) => page(reply, status, await renderInvitePage(fields), SECRET_URL_HEADERS);
|
|
24
|
+
const showInvite = async (req, reply) => claimPage(reply, 200, { code: InviteQuerySchema.safeParse(req.query).data?.[INVITE_CODE_PARAM] ?? '' });
|
|
25
|
+
const submitClaim = (ctx, limiter) => async (req, reply) => {
|
|
26
|
+
const parsed = ClaimInviteFormSchema.safeParse(req.body);
|
|
27
|
+
const { code } = ClaimedCodeEchoSchema.parse(req.body ?? {});
|
|
28
|
+
if (!parsed.success) {
|
|
29
|
+
return claimPage(reply, INVALID_FORM_STATUS, {
|
|
30
|
+
code,
|
|
31
|
+
error: parsed.error.issues[0]?.message ?? AUTH_MESSAGES.tryAgain,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// Keyed by the code (hashed in memory), alongside the client address: guessing one invite is limited as a whole.
|
|
35
|
+
const key = ctx.deps.secrets.hashSecret(normalizeInviteCode(parsed.data.code));
|
|
36
|
+
if (limiter.isLimited(req.ip, key)) {
|
|
37
|
+
return claimPage(reply, httpStatus(authErrors.rateLimited), { code, error: AUTH_MESSAGES.rateLimited });
|
|
38
|
+
}
|
|
39
|
+
const claimed = await limiter.attempt(req.ip, key, () => ctx.runEffects(() => claimInvite(ctx.deps, parsed.data)));
|
|
40
|
+
if (claimed.isErr()) {
|
|
41
|
+
if (claimed.error.code !== authErrors.invalidInvite.code)
|
|
42
|
+
limiter.forgive(req.ip, key);
|
|
43
|
+
return claimPage(reply, httpStatus(claimed.error), { code, error: messageFor(claimed.error) });
|
|
44
|
+
}
|
|
45
|
+
limiter.recordSuccess(req.ip, key);
|
|
46
|
+
return reply
|
|
47
|
+
.header('set-cookie', sessionCookie(claimed.value.token, ctx.secureCookie))
|
|
48
|
+
.redirect(DEFAULT_LANDING_PATH, SEE_OTHER);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* `/ui/access/invite`: where an invited person chooses their password. Public like `/ui/setup` — they have
|
|
52
|
+
* no login yet — so it is rate-limited the same way and its POST is Origin-checked whenever a browser declares one. The
|
|
53
|
+
* code may come in the link or be typed; it is single-use, expires, and is never logged. On success the person lands
|
|
54
|
+
* signed in. Thin: parse the form, throttle, run the `controllers/auth/users.ts` flow, set the cookie.
|
|
55
|
+
*/
|
|
56
|
+
export const registerInviteRoutes = (app, ctx) => {
|
|
57
|
+
const limiter = createAttemptLimiter();
|
|
58
|
+
void app.register(async (scope) => {
|
|
59
|
+
addFormParser(scope);
|
|
60
|
+
scope.get(INVITE_PATH, showInvite);
|
|
61
|
+
scope.post(INVITE_PATH, { bodyLimit: FORM_BODY_LIMIT_BYTES }, submitClaim(ctx, limiter));
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as recurringAdapters from '../../../adapters/recurring.js';
|
|
3
|
+
import * as transactionAdapters from '../../../adapters/transactions.js';
|
|
4
|
+
import { applyDueRecurring, createRecurring, listRecurring } from '../../../controllers/recurring.js';
|
|
5
|
+
import { RecurringRuleViewSchema } from '../../../models/recurring.js';
|
|
6
|
+
import * as wireInRecurring from '../../../wire/in/recurring.js';
|
|
7
|
+
import { ApplyDueResultOut } from '../../../wire/out/recurring.js';
|
|
8
|
+
import { jsonBody, okResponse } from '../openapi.js';
|
|
9
|
+
import { conflict409, notFound404, parse, parseOrIssue, send, validation422 } from '../respond.js';
|
|
10
|
+
import { READ_SCOPE, WRITE_SCOPE } from '../../../models/auth/scope.js';
|
|
11
|
+
const RECURRING_TAG = 'Recurring';
|
|
12
|
+
const INVALID_THROUGH_DATE_ISSUE = 'invalid through date';
|
|
13
|
+
const listRecurringRoute = {
|
|
14
|
+
method: 'get',
|
|
15
|
+
scope: READ_SCOPE,
|
|
16
|
+
path: '/api/recurring',
|
|
17
|
+
tags: [RECURRING_TAG],
|
|
18
|
+
summary: 'List recurring rules',
|
|
19
|
+
responses: { 200: okResponse('Recurring rules', z.array(RecurringRuleViewSchema)) },
|
|
20
|
+
handler: async (_req, _reply, scope) => listRecurring(scope().deps),
|
|
21
|
+
};
|
|
22
|
+
const createRecurringRoute = {
|
|
23
|
+
method: 'post',
|
|
24
|
+
scope: WRITE_SCOPE,
|
|
25
|
+
path: '/api/recurring',
|
|
26
|
+
tags: [RECURRING_TAG],
|
|
27
|
+
summary: 'Create recurring rule',
|
|
28
|
+
request: { body: jsonBody(wireInRecurring.CreateRecurringSchema) },
|
|
29
|
+
responses: {
|
|
30
|
+
201: okResponse('Recurring rule created', RecurringRuleViewSchema),
|
|
31
|
+
404: notFound404,
|
|
32
|
+
409: conflict409,
|
|
33
|
+
422: validation422,
|
|
34
|
+
},
|
|
35
|
+
handler: async (req, reply, scope) => {
|
|
36
|
+
const { deps, runEffects } = scope();
|
|
37
|
+
const wireIn = parse(wireInRecurring.CreateRecurringSchema, req.body, reply);
|
|
38
|
+
if (!wireIn)
|
|
39
|
+
return reply;
|
|
40
|
+
const flow = () => createRecurring(deps, recurringAdapters.wireInToModel(wireIn)).map(recurringAdapters.outcomeToDb);
|
|
41
|
+
return send(reply, await runEffects(flow), 201);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const applyDueRecurringRoute = {
|
|
45
|
+
method: 'post',
|
|
46
|
+
scope: WRITE_SCOPE,
|
|
47
|
+
path: '/api/recurring/apply-due',
|
|
48
|
+
tags: [RECURRING_TAG],
|
|
49
|
+
summary: 'Materialize due recurring rules',
|
|
50
|
+
request: { body: jsonBody(wireInRecurring.ApplyDueBodySchema) },
|
|
51
|
+
responses: {
|
|
52
|
+
200: okResponse('Applied recurring rules', ApplyDueResultOut),
|
|
53
|
+
409: conflict409,
|
|
54
|
+
422: validation422,
|
|
55
|
+
},
|
|
56
|
+
handler: async (req, reply, scope) => {
|
|
57
|
+
const { deps, runEffects } = scope();
|
|
58
|
+
const input = parseOrIssue(wireInRecurring.ApplyDueBodySchema, req.body ?? {}, reply, INVALID_THROUGH_DATE_ISSUE);
|
|
59
|
+
if (!input)
|
|
60
|
+
return reply;
|
|
61
|
+
const flow = () => applyDueRecurring(deps, input).map(recurringAdapters.outcomeToDb).map(transactionAdapters.outcomeToDb);
|
|
62
|
+
return send(reply, await runEffects(flow));
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
export const recurringRoutes = [listRecurringRoute, createRecurringRoute, applyDueRecurringRoute];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getPreferences, setBaseCurrency } from '../../../controllers/settings.js';
|
|
2
|
+
import { PreferencesSchema } from '../../../models/locale.js';
|
|
3
|
+
import * as settingsAdapters from '../../../adapters/settings.js';
|
|
4
|
+
import { SetBaseCurrencySchema } from '../../../wire/in/settings.js';
|
|
5
|
+
import { jsonBody, okResponse } from '../openapi.js';
|
|
6
|
+
import { parse, send, validation422 } from '../respond.js';
|
|
7
|
+
import { READ_SCOPE, WRITE_SCOPE } from '../../../models/auth/scope.js';
|
|
8
|
+
const SETTINGS_TAG = 'Settings';
|
|
9
|
+
const getPreferencesRoute = {
|
|
10
|
+
method: 'get',
|
|
11
|
+
scope: READ_SCOPE,
|
|
12
|
+
path: '/api/preferences',
|
|
13
|
+
tags: [SETTINGS_TAG],
|
|
14
|
+
summary: 'Get user preferences',
|
|
15
|
+
responses: { 200: okResponse('Preferences', PreferencesSchema) },
|
|
16
|
+
handler: async (_req, _reply, scope) => getPreferences(scope().deps),
|
|
17
|
+
};
|
|
18
|
+
const setBaseCurrencyRoute = {
|
|
19
|
+
method: 'post',
|
|
20
|
+
scope: WRITE_SCOPE,
|
|
21
|
+
path: '/api/settings/base-currency',
|
|
22
|
+
tags: [SETTINGS_TAG],
|
|
23
|
+
summary: 'Set base currency',
|
|
24
|
+
request: { body: jsonBody(SetBaseCurrencySchema) },
|
|
25
|
+
responses: {
|
|
26
|
+
200: okResponse('Base currency updated', PreferencesSchema.pick({ baseCurrency: true })),
|
|
27
|
+
422: validation422,
|
|
28
|
+
},
|
|
29
|
+
handler: async (req, reply, scope) => {
|
|
30
|
+
const { deps, runEffects } = scope();
|
|
31
|
+
const input = parse(SetBaseCurrencySchema, req.body, reply);
|
|
32
|
+
if (!input)
|
|
33
|
+
return reply;
|
|
34
|
+
const flow = () => setBaseCurrency(deps, input).map(settingsAdapters.outcomeToDb);
|
|
35
|
+
return send(reply, await runEffects(flow));
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
export const settingsRoutes = [getPreferencesRoute, setBaseCurrencyRoute];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getSpendingSummary } from '../../../controllers/summary.js';
|
|
2
|
+
import { SpendingSummaryOut } from '../../../wire/out/summary.js';
|
|
3
|
+
import { SummaryQuerySchema } from '../../../wire/in/summary.js';
|
|
4
|
+
import { okResponse } from '../openapi.js';
|
|
5
|
+
import { parse, validation422 } from '../respond.js';
|
|
6
|
+
import { READ_SCOPE } from '../../../models/auth/scope.js';
|
|
7
|
+
const SUMMARY_TAG = 'Summary';
|
|
8
|
+
const getSpendingSummaryRoute = {
|
|
9
|
+
method: 'get',
|
|
10
|
+
scope: READ_SCOPE,
|
|
11
|
+
path: '/api/summary',
|
|
12
|
+
tags: [SUMMARY_TAG],
|
|
13
|
+
summary: 'Get spending summary',
|
|
14
|
+
request: { query: SummaryQuerySchema },
|
|
15
|
+
responses: { 200: okResponse('Spending summary', SpendingSummaryOut), 422: validation422 },
|
|
16
|
+
handler: async (req, reply, scope) => {
|
|
17
|
+
const input = parse(SummaryQuerySchema, req.query, reply);
|
|
18
|
+
if (!input)
|
|
19
|
+
return reply;
|
|
20
|
+
return reply.send(await getSpendingSummary(scope().deps, input, input.displayCurrency));
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export const summaryRoutes = [getSpendingSummaryRoute];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getHealth, getStatus } from '../../../controllers/status.js';
|
|
2
|
+
import { HealthOut, StatusOut } from '../../../wire/out/status.js';
|
|
3
|
+
import { HEALTH_PATH } from '../auth-paths.js';
|
|
4
|
+
import { okResponse } from '../openapi.js';
|
|
5
|
+
import { READ_SCOPE } from '../../../models/auth/scope.js';
|
|
6
|
+
const SYSTEM_TAG = 'System';
|
|
7
|
+
const healthRoute = (publicDeps) => ({
|
|
8
|
+
method: 'get',
|
|
9
|
+
scope: READ_SCOPE,
|
|
10
|
+
path: HEALTH_PATH,
|
|
11
|
+
tags: [SYSTEM_TAG],
|
|
12
|
+
summary: 'Liveness and database probe — the only unauthenticated /api route (ADR-033 §6)',
|
|
13
|
+
responses: { 200: okResponse('OK', HealthOut) },
|
|
14
|
+
handler: async () => getHealth(publicDeps),
|
|
15
|
+
});
|
|
16
|
+
const statusRoute = (version) => ({
|
|
17
|
+
method: 'get',
|
|
18
|
+
scope: READ_SCOPE,
|
|
19
|
+
path: '/api/status',
|
|
20
|
+
tags: [SYSTEM_TAG],
|
|
21
|
+
summary: 'Server status',
|
|
22
|
+
responses: { 200: okResponse('Server status', StatusOut) },
|
|
23
|
+
handler: async (_req, _reply, scope) => getStatus(scope().deps, version),
|
|
24
|
+
});
|
|
25
|
+
/** The one module that needs the context: health is public (no principal), status reports the version. */
|
|
26
|
+
export const systemRoutes = ({ publicDeps, version }) => [
|
|
27
|
+
healthRoute(publicDeps),
|
|
28
|
+
statusRoute(version),
|
|
29
|
+
];
|