@rfc0/patty 0.0.0-stage → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +214 -2
- package/dist/adapters/access-tokens.js +7 -0
- package/dist/adapters/accounts.js +37 -0
- package/dist/adapters/auth.js +11 -0
- package/dist/adapters/bills.js +32 -0
- package/dist/adapters/budgets.js +29 -0
- package/dist/adapters/categories.js +32 -0
- package/dist/adapters/client-grants.js +7 -0
- package/dist/adapters/credit-cards.js +33 -0
- package/dist/adapters/currencies.js +2 -0
- package/dist/adapters/currency-rates.js +18 -0
- package/dist/adapters/dashboards.js +43 -0
- package/dist/adapters/demo.js +13 -0
- package/dist/adapters/instance-settings.js +7 -0
- package/dist/adapters/invites.js +7 -0
- package/dist/adapters/recurring.js +55 -0
- package/dist/adapters/sessions.js +7 -0
- package/dist/adapters/settings.js +4 -0
- package/dist/adapters/setup-codes.js +7 -0
- package/dist/adapters/tags.js +9 -0
- package/dist/adapters/transactions.js +95 -0
- package/dist/adapters/users.js +7 -0
- package/dist/common/build-version.js +5 -0
- package/dist/common/errors.js +118 -0
- package/dist/common/net.js +71 -0
- package/dist/common/result.js +7 -0
- package/dist/composition/auth.js +106 -0
- package/dist/composition/boot.js +27 -0
- package/dist/composition/cli.js +86 -0
- package/dist/composition/demo/seed.js +92 -0
- package/dist/composition/demo/shell.js +107 -0
- package/dist/composition/export.js +89 -0
- package/dist/composition/http.js +110 -0
- package/dist/composition/import.js +55 -0
- package/dist/composition/lazy-modules.js +2 -0
- package/dist/composition/runtime.js +115 -0
- package/dist/composition/sign-in/interpreter.js +154 -0
- package/dist/composition/sign-in/server.js +36 -0
- package/dist/composition/sign-in/wiring.js +23 -0
- package/dist/composition/stdio.js +69 -0
- package/dist/config.js +136 -0
- package/dist/controllers/account/account.js +88 -0
- package/dist/controllers/account/transaction.js +119 -0
- package/dist/controllers/account/transfer.js +34 -0
- package/dist/controllers/aggregate.js +40 -0
- package/dist/controllers/auth/access-tokens.js +61 -0
- package/dist/controllers/auth/grants.js +136 -0
- package/dist/controllers/auth/key-export.js +20 -0
- package/dist/controllers/auth/owner.js +80 -0
- package/dist/controllers/auth/password.js +35 -0
- package/dist/controllers/auth/session.js +50 -0
- package/dist/controllers/auth/step-up.js +8 -0
- package/dist/controllers/auth/users.js +183 -0
- package/dist/controllers/budgets.js +87 -0
- package/dist/controllers/categories.js +67 -0
- package/dist/controllers/correlations.js +112 -0
- package/dist/controllers/credit-card/bill.js +105 -0
- package/dist/controllers/credit-card/credit-card.js +129 -0
- package/dist/controllers/credit-card/transaction.js +181 -0
- package/dist/controllers/currencies.js +1 -0
- package/dist/controllers/currency-rates.js +40 -0
- package/dist/controllers/dashboards.js +68 -0
- package/dist/controllers/demo/seed.js +31 -0
- package/dist/controllers/demo/tour.js +12 -0
- package/dist/controllers/deps.js +6 -0
- package/dist/controllers/instance.js +6 -0
- package/dist/controllers/merchants.js +12 -0
- package/dist/controllers/recurring.js +70 -0
- package/dist/controllers/resolve.js +37 -0
- package/dist/controllers/settings.js +47 -0
- package/dist/controllers/status.js +19 -0
- package/dist/controllers/summary.js +21 -0
- package/dist/controllers/tags.js +19 -0
- package/dist/controllers/transaction/bulk.js +6 -0
- package/dist/controllers/transaction/core.js +49 -0
- package/dist/controllers/transaction/read.js +28 -0
- package/dist/diplomat/auth/credentials.js +58 -0
- package/dist/diplomat/auth/sign-in-store.js +18 -0
- package/dist/diplomat/cli/commands/auth.js +100 -0
- package/dist/diplomat/cli/commands/db.js +72 -0
- package/dist/diplomat/cli/commands/demo.js +68 -0
- package/dist/diplomat/cli/commands/key.js +119 -0
- package/dist/diplomat/cli/commands/login.js +151 -0
- package/dist/diplomat/cli/commands/setup.js +132 -0
- package/dist/diplomat/cli/commands/users.js +123 -0
- package/dist/diplomat/cli/commands.js +61 -0
- package/dist/diplomat/cli/export-file.js +37 -0
- package/dist/diplomat/cli/import-file.js +44 -0
- package/dist/diplomat/cli/io.js +61 -0
- package/dist/diplomat/cli/key-export-approval.js +37 -0
- package/dist/diplomat/cli/messages.js +96 -0
- package/dist/diplomat/cli/prompt.js +74 -0
- package/dist/diplomat/cli/terminal.js +81 -0
- package/dist/diplomat/client-config/clients.js +150 -0
- package/dist/diplomat/client-config/merge.js +41 -0
- package/dist/diplomat/db/bootstrap.js +98 -0
- package/dist/diplomat/db/database-files.js +147 -0
- package/dist/diplomat/db/driver.js +167 -0
- package/dist/diplomat/db/effects.js +101 -0
- package/dist/diplomat/db/engine.js +9 -0
- package/dist/diplomat/db/export.js +22 -0
- package/dist/diplomat/db/file-lock.js +82 -0
- package/dist/diplomat/db/key-lock.js +14 -0
- package/dist/diplomat/db/locale-cache.js +23 -0
- package/dist/diplomat/db/migration-barrier.js +57 -0
- package/dist/diplomat/db/migration-journal.js +18 -0
- package/dist/diplomat/db/migration-lock.js +15 -0
- package/dist/diplomat/db/migrations.js +11 -0
- package/dist/diplomat/db/present.js +17 -0
- package/dist/diplomat/db/queries/aggregate-whitelist.js +35 -0
- package/dist/diplomat/db/queries/filters.js +59 -0
- package/dist/diplomat/db/queries/fts.js +18 -0
- package/dist/diplomat/db/queries/scope.js +8 -0
- package/dist/diplomat/db/queries/transaction-select.js +26 -0
- package/dist/diplomat/db/queries/tx-predicates.js +13 -0
- package/dist/diplomat/db/repos/access-tokens.js +27 -0
- package/dist/diplomat/db/repos/accounts.js +91 -0
- package/dist/diplomat/db/repos/bills.js +93 -0
- package/dist/diplomat/db/repos/budgets.js +72 -0
- package/dist/diplomat/db/repos/categories.js +53 -0
- package/dist/diplomat/db/repos/client-grants.js +67 -0
- package/dist/diplomat/db/repos/correlations.js +66 -0
- package/dist/diplomat/db/repos/credit-cards.js +67 -0
- package/dist/diplomat/db/repos/currencies.js +8 -0
- package/dist/diplomat/db/repos/currency-rates.js +40 -0
- package/dist/diplomat/db/repos/dashboards.js +123 -0
- package/dist/diplomat/db/repos/health.js +12 -0
- package/dist/diplomat/db/repos/instance-settings.js +14 -0
- package/dist/diplomat/db/repos/instance.js +58 -0
- package/dist/diplomat/db/repos/invites.js +43 -0
- package/dist/diplomat/db/repos/merchants.js +121 -0
- package/dist/diplomat/db/repos/recurring.js +29 -0
- package/dist/diplomat/db/repos/sessions.js +19 -0
- package/dist/diplomat/db/repos/settings.js +41 -0
- package/dist/diplomat/db/repos/setup-codes.js +28 -0
- package/dist/diplomat/db/repos/sub-categories.js +67 -0
- package/dist/diplomat/db/repos/tags.js +51 -0
- package/dist/diplomat/db/repos/transaction-tags.js +57 -0
- package/dist/diplomat/db/repos/transactions.js +163 -0
- package/dist/diplomat/db/repos/users.js +47 -0
- package/dist/diplomat/db/safety-copy.js +87 -0
- package/dist/diplomat/db/schema.js +348 -0
- package/dist/diplomat/db/seed/categories.js +112 -0
- package/dist/diplomat/db/seed/currencies.js +9 -0
- package/dist/diplomat/db/seed/demo/br.js +98 -0
- package/dist/diplomat/db/seed/demo/co.js +89 -0
- package/dist/diplomat/db/seed/demo/index.js +12 -0
- package/dist/diplomat/db/seed/demo/mx.js +90 -0
- package/dist/diplomat/db/seed/demo/shared.js +39 -0
- package/dist/diplomat/db/seed/demo/us.js +90 -0
- package/dist/diplomat/db/seed/merchant-rules.js +188 -0
- package/dist/diplomat/db/sqlite-errors.js +40 -0
- package/dist/diplomat/db/tenancy-integrity.js +45 -0
- package/dist/diplomat/db/version-guard.js +16 -0
- package/dist/diplomat/http/auth-pages.js +41 -0
- package/dist/diplomat/http/auth-paths.js +46 -0
- package/dist/diplomat/http/bearer.js +15 -0
- package/dist/diplomat/http/connect-pages.js +51 -0
- package/dist/diplomat/http/context.js +17 -0
- package/dist/diplomat/http/cookies.js +27 -0
- package/dist/diplomat/http/form-pages.js +38 -0
- package/dist/diplomat/http/hooks/auth.js +106 -0
- package/dist/diplomat/http/hooks/demo-marker.js +59 -0
- package/dist/diplomat/http/openapi.js +73 -0
- package/dist/diplomat/http/principal.js +1 -0
- package/dist/diplomat/http/rate-limiter.js +78 -0
- package/dist/diplomat/http/remedy.js +26 -0
- package/dist/diplomat/http/respond.js +50 -0
- package/dist/diplomat/http/routes/account.js +226 -0
- package/dist/diplomat/http/routes/aggregate.js +28 -0
- package/dist/diplomat/http/routes/auth.js +105 -0
- package/dist/diplomat/http/routes/budget.js +34 -0
- package/dist/diplomat/http/routes/category.js +109 -0
- package/dist/diplomat/http/routes/connect.js +124 -0
- package/dist/diplomat/http/routes/credit-card.js +263 -0
- package/dist/diplomat/http/routes/currency-rates.js +60 -0
- package/dist/diplomat/http/routes/currency.js +16 -0
- package/dist/diplomat/http/routes/dashboard.js +93 -0
- package/dist/diplomat/http/routes/invite.js +63 -0
- package/dist/diplomat/http/routes/recurring.js +65 -0
- package/dist/diplomat/http/routes/settings.js +38 -0
- package/dist/diplomat/http/routes/summary.js +23 -0
- package/dist/diplomat/http/routes/system.js +29 -0
- package/dist/diplomat/http/routes/tag.js +51 -0
- package/dist/diplomat/http/routes/tokens.js +72 -0
- package/dist/diplomat/http/routes/transaction.js +55 -0
- package/dist/diplomat/http/routes/transfer.js +35 -0
- package/dist/diplomat/http/routes/ui.js +110 -0
- package/dist/diplomat/http/routes/users.js +156 -0
- package/dist/diplomat/http/routes/well-known.js +26 -0
- package/dist/diplomat/http/routes.js +85 -0
- package/dist/diplomat/http/session.js +34 -0
- package/dist/diplomat/http/token-pages.js +75 -0
- package/dist/diplomat/http/ui-files.js +21 -0
- package/dist/diplomat/http/user-pages.js +93 -0
- package/dist/diplomat/mcp/annotations.js +8 -0
- package/dist/diplomat/mcp/auth-info.js +20 -0
- package/dist/diplomat/mcp/context.js +14 -0
- package/dist/diplomat/mcp/definition.js +3 -0
- package/dist/diplomat/mcp/gate.js +15 -0
- package/dist/diplomat/mcp/instructions.js +19 -0
- package/dist/diplomat/mcp/prompts.js +125 -0
- package/dist/diplomat/mcp/register.js +12 -0
- package/dist/diplomat/mcp/remedy.js +17 -0
- package/dist/diplomat/mcp/resources.js +93 -0
- package/dist/diplomat/mcp/respond.js +20 -0
- package/dist/diplomat/mcp/route.js +62 -0
- package/dist/diplomat/mcp/scopes.js +53 -0
- package/dist/diplomat/mcp/server.js +26 -0
- package/dist/diplomat/mcp/shared.js +5 -0
- package/dist/diplomat/mcp/stdio-session.js +94 -0
- package/dist/diplomat/mcp/stdio.js +23 -0
- package/dist/diplomat/mcp/tool-name.js +59 -0
- package/dist/diplomat/mcp/tools/account.js +218 -0
- package/dist/diplomat/mcp/tools/aggregate.js +32 -0
- package/dist/diplomat/mcp/tools/budget.js +99 -0
- package/dist/diplomat/mcp/tools/category.js +103 -0
- package/dist/diplomat/mcp/tools/correlations.js +70 -0
- package/dist/diplomat/mcp/tools/credit-card.js +239 -0
- package/dist/diplomat/mcp/tools/currency-rates.js +62 -0
- package/dist/diplomat/mcp/tools/dashboard.js +75 -0
- package/dist/diplomat/mcp/tools/index.js +31 -0
- package/dist/diplomat/mcp/tools/recurring.js +62 -0
- package/dist/diplomat/mcp/tools/summary.js +30 -0
- package/dist/diplomat/mcp/tools/system.js +83 -0
- package/dist/diplomat/mcp/tools/tag.js +48 -0
- package/dist/diplomat/mcp/tools/transaction.js +53 -0
- package/dist/diplomat/mcp/tools/transfer.js +28 -0
- package/dist/diplomat/mcp/tour.js +87 -0
- package/dist/logic/account.js +79 -0
- package/dist/logic/aggregate.js +37 -0
- package/dist/logic/auth/bearer.js +35 -0
- package/dist/logic/auth/grant.js +126 -0
- package/dist/logic/auth/key-export.js +10 -0
- package/dist/logic/auth/keychain.js +3 -0
- package/dist/logic/auth/message.js +22 -0
- package/dist/logic/auth/origin.js +57 -0
- package/dist/logic/auth/owner.js +22 -0
- package/dist/logic/auth/password.js +3 -0
- package/dist/logic/auth/redact.js +25 -0
- package/dist/logic/auth/revoke.js +28 -0
- package/dist/logic/auth/scope.js +17 -0
- package/dist/logic/auth/session.js +30 -0
- package/dist/logic/auth/sign-in-flow.js +305 -0
- package/dist/logic/auth/time.js +2 -0
- package/dist/logic/auth/token.js +74 -0
- package/dist/logic/auth/user-plans.js +84 -0
- package/dist/logic/auth/users.js +78 -0
- package/dist/logic/balance.js +2 -0
- package/dist/logic/bill.js +74 -0
- package/dist/logic/budget.js +78 -0
- package/dist/logic/category.js +37 -0
- package/dist/logic/classify.js +21 -0
- package/dist/logic/correlations.js +147 -0
- package/dist/logic/credit-card.js +2 -0
- package/dist/logic/currency-rate.js +69 -0
- package/dist/logic/dashboard.js +40 -0
- package/dist/logic/demo/database.js +30 -0
- package/dist/logic/demo/plan.js +308 -0
- package/dist/logic/demo/tour.js +33 -0
- package/dist/logic/export-destination.js +12 -0
- package/dist/logic/key-import.js +15 -0
- package/dist/logic/locale.js +5 -0
- package/dist/logic/localize.js +12 -0
- package/dist/logic/merchant.js +31 -0
- package/dist/logic/migration.js +1 -0
- package/dist/logic/money.js +12 -0
- package/dist/logic/period.js +45 -0
- package/dist/logic/persistence.js +48 -0
- package/dist/logic/recurring.js +51 -0
- package/dist/logic/resolve.js +44 -0
- package/dist/logic/summary.js +29 -0
- package/dist/logic/tag.js +13 -0
- package/dist/logic/transaction.js +197 -0
- package/dist/main.js +42 -0
- package/dist/models/account.js +197 -0
- package/dist/models/aggregate.js +61 -0
- package/dist/models/auth/bearer.js +11 -0
- package/dist/models/auth/entity.js +17 -0
- package/dist/models/auth/errors.js +42 -0
- package/dist/models/auth/grant.js +58 -0
- package/dist/models/auth/key-export.js +11 -0
- package/dist/models/auth/message.js +50 -0
- package/dist/models/auth/mode.js +7 -0
- package/dist/models/auth/origin.js +16 -0
- package/dist/models/auth/owner.js +36 -0
- package/dist/models/auth/password.js +24 -0
- package/dist/models/auth/principal.js +26 -0
- package/dist/models/auth/redact.js +4 -0
- package/dist/models/auth/scope.js +9 -0
- package/dist/models/auth/session.js +19 -0
- package/dist/models/auth/sign-in-flow.js +102 -0
- package/dist/models/auth/sign-in.js +41 -0
- package/dist/models/auth/time.js +5 -0
- package/dist/models/auth/token.js +50 -0
- package/dist/models/auth/users.js +52 -0
- package/dist/models/bill.js +55 -0
- package/dist/models/budget.js +106 -0
- package/dist/models/category.js +52 -0
- package/dist/models/client-config.js +18 -0
- package/dist/models/correlations.js +215 -0
- package/dist/models/credit-card.js +156 -0
- package/dist/models/currency-rate.js +83 -0
- package/dist/models/dashboard.js +54 -0
- package/dist/models/database.js +16 -0
- package/dist/models/date.js +8 -0
- package/dist/models/demo/core.js +58 -0
- package/dist/models/demo/tour.js +41 -0
- package/dist/models/encryption-key.js +2 -0
- package/dist/models/error.js +13 -0
- package/dist/models/export.js +9 -0
- package/dist/models/id.js +2 -0
- package/dist/models/instance.js +7 -0
- package/dist/models/key-import.js +6 -0
- package/dist/models/locale.js +25 -0
- package/dist/models/merchant.js +12 -0
- package/dist/models/money.js +14 -0
- package/dist/models/package.js +12 -0
- package/dist/models/page.js +56 -0
- package/dist/models/persistence.js +1 -0
- package/dist/models/prompts.js +5 -0
- package/dist/models/recurring.js +54 -0
- package/dist/models/remedy.js +17 -0
- package/dist/models/resolution.js +1 -0
- package/dist/models/startup.js +7 -0
- package/dist/models/summary.js +24 -0
- package/dist/models/tag.js +14 -0
- package/dist/models/tenancy.js +10 -0
- package/dist/models/transaction-tag.js +6 -0
- package/dist/models/transaction.js +275 -0
- package/dist/wire/db/access-tokens.js +1 -0
- package/dist/wire/db/accounts.js +7 -0
- package/dist/wire/db/aggregate.js +16 -0
- package/dist/wire/db/bills.js +14 -0
- package/dist/wire/db/budgets.js +33 -0
- package/dist/wire/db/categories.js +14 -0
- package/dist/wire/db/client-grants.js +1 -0
- package/dist/wire/db/correlations.js +49 -0
- package/dist/wire/db/credit-cards.js +1 -0
- package/dist/wire/db/currencies.js +1 -0
- package/dist/wire/db/currency-rates.js +1 -0
- package/dist/wire/db/dashboards.js +1 -0
- package/dist/wire/db/instance-settings.js +1 -0
- package/dist/wire/db/invites.js +1 -0
- package/dist/wire/db/merchants.js +18 -0
- package/dist/wire/db/recurring.js +19 -0
- package/dist/wire/db/sessions.js +1 -0
- package/dist/wire/db/settings.js +1 -0
- package/dist/wire/db/setup-codes.js +1 -0
- package/dist/wire/db/tags.js +1 -0
- package/dist/wire/db/tenancy.js +1 -0
- package/dist/wire/db/transactions.js +89 -0
- package/dist/wire/db/users.js +1 -0
- package/dist/wire/in/accounts.js +26 -0
- package/dist/wire/in/aggregate.js +10 -0
- package/dist/wire/in/auth.js +107 -0
- package/dist/wire/in/bills.js +11 -0
- package/dist/wire/in/budgets.js +11 -0
- package/dist/wire/in/categories.js +9 -0
- package/dist/wire/in/cli.js +106 -0
- package/dist/wire/in/coerce.js +6 -0
- package/dist/wire/in/common.js +17 -0
- package/dist/wire/in/credit-cards.js +16 -0
- package/dist/wire/in/currency-rates.js +8 -0
- package/dist/wire/in/period.js +7 -0
- package/dist/wire/in/recurring.js +6 -0
- package/dist/wire/in/settings.js +5 -0
- package/dist/wire/in/summary.js +5 -0
- package/dist/wire/in/tags.js +2 -0
- package/dist/wire/in/transactions.js +31 -0
- package/dist/wire/out/bills.js +9 -0
- package/dist/wire/out/budgets.js +10 -0
- package/dist/wire/out/client-config.js +2 -0
- package/dist/wire/out/common.js +4 -0
- package/dist/wire/out/credit-cards.js +15 -0
- package/dist/wire/out/currency-rates.js +11 -0
- package/dist/wire/out/errors.js +58 -0
- package/dist/wire/out/recurring.js +6 -0
- package/dist/wire/out/status.js +10 -0
- package/dist/wire/out/summary.js +9 -0
- package/dist/wire/out/transactions.js +52 -0
- package/drizzle/0000_futuristic_umar.sql +124 -0
- package/drizzle/0001_fts5_search.sql +23 -0
- package/drizzle/0002_rename_graph_to_history.sql +7 -0
- package/drizzle/0003_lyrical_hairball.sql +2 -0
- package/drizzle/0004_misty_ikaris.sql +7 -0
- package/drizzle/0005_credit-liability-accounts.sql +14 -0
- package/drizzle/0006_smart_aqueduct.sql +1 -0
- package/drizzle/0007_add_dashboards.sql +5 -0
- package/drizzle/0008_yummy_madripoor.sql +1 -0
- package/drizzle/0009_version_groundwork.sql +9 -0
- package/drizzle/0010_category_merchant_association_cascade.sql +16 -0
- package/drizzle/0011_dashboard_id_normalization.sql +16 -0
- package/drizzle/0012_hot_the_spike.sql +12 -0
- package/drizzle/0013_recurring_rules_merchant.sql +1 -0
- package/drizzle/0014_dashboard_source_discriminator.sql +17 -0
- package/drizzle/0015_currencies_decimals.sql +1 -0
- package/drizzle/0016_unusual_zaran.sql +13 -0
- package/drizzle/0017_premium_blur.sql +1 -0
- package/drizzle/0018_auth_identity.sql +39 -0
- package/drizzle/0019_access_tokens.sql +16 -0
- package/drizzle/0020_stdio_sign_in.sql +27 -0
- package/drizzle/0021_tenancy_data.sql +289 -0
- package/drizzle/0022_user_management.sql +17 -0
- package/drizzle/0023_instance_settings_row.sql +2 -0
- package/drizzle/0024_credentials_changed_at.sql +2 -0
- package/drizzle/0025_instance_kind.sql +2 -0
- package/drizzle/0026_demo_seeded_at.sql +2 -0
- package/drizzle/0027_demo_country.sql +2 -0
- package/drizzle/0028_reset_sign_ins.sql +2 -0
- package/drizzle/meta/0000_snapshot.json +894 -0
- package/drizzle/meta/0003_snapshot.json +910 -0
- package/drizzle/meta/0004_snapshot.json +951 -0
- package/drizzle/meta/0005_snapshot.json +991 -0
- package/drizzle/meta/0006_snapshot.json +998 -0
- package/drizzle/meta/0007_snapshot.json +1029 -0
- package/drizzle/meta/0008_snapshot.json +1049 -0
- package/drizzle/meta/0009_snapshot.json +1121 -0
- package/drizzle/meta/0010_snapshot.json +1121 -0
- package/drizzle/meta/0011_snapshot.json +1136 -0
- package/drizzle/meta/0012_snapshot.json +1227 -0
- package/drizzle/meta/0013_snapshot.json +1247 -0
- package/drizzle/meta/0014_snapshot.json +1267 -0
- package/drizzle/meta/0015_snapshot.json +1275 -0
- package/drizzle/meta/0016_snapshot.json +1371 -0
- package/drizzle/meta/0017_snapshot.json +1392 -0
- package/drizzle/meta/0018_snapshot.json +1603 -0
- package/drizzle/meta/0019_snapshot.json +1713 -0
- package/drizzle/meta/0020_snapshot.json +1904 -0
- package/drizzle/meta/0021_snapshot.json +2186 -0
- package/drizzle/meta/0022_snapshot.json +2311 -0
- package/drizzle/meta/0023_snapshot.json +2311 -0
- package/drizzle/meta/0024_snapshot.json +2318 -0
- package/drizzle/meta/0025_snapshot.json +2326 -0
- package/drizzle/meta/0026_snapshot.json +2333 -0
- package/drizzle/meta/0027_snapshot.json +2340 -0
- package/drizzle/meta/0028_snapshot.json +2340 -0
- package/drizzle/meta/_journal.json +209 -0
- package/package.json +106 -4
- package/skills/dashboard-building/SKILL.md +201 -0
- package/skills/patty-tour/SKILL.md +34 -0
- package/ui/app.css +758 -0
- package/ui/app.js +543 -0
- package/ui/connect-result.html +16 -0
- package/ui/connect.html +53 -0
- package/ui/dashboards/accounts.html +3189 -0
- package/ui/dashboards/budget.html +1734 -0
- package/ui/dashboards/cards.html +4032 -0
- package/ui/dashboards/categories.html +4694 -0
- package/ui/dashboards/comparative.html +2475 -0
- package/ui/dashboards/dashboards.html +839 -0
- package/ui/dashboards/overview.html +2405 -0
- package/ui/dashboards/pending.html +2973 -0
- package/ui/dashboards/projections.html +2528 -0
- package/ui/dashboards/tags.html +1365 -0
- package/ui/invite.html +44 -0
- package/ui/login.html +26 -0
- package/ui/money.js +175 -0
- package/ui/setup.html +29 -0
- package/ui/shell.html +96 -0
- package/ui/token-created.html +24 -0
- package/ui/tokens.html +58 -0
- package/ui/user-invited.html +27 -0
- package/ui/users.html +60 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { ok, safeTry } from 'neverthrow';
|
|
2
|
+
import * as R from 'remeda';
|
|
3
|
+
import { guard, okOr } from '../../common/result.js';
|
|
4
|
+
import { assertBillPeriodPaired, billEntityFrom, billPeriodKey, billPeriodForCycle, isBillPaid, resolveBillPeriod, } from '../../logic/bill.js';
|
|
5
|
+
import { resolveCurrency } from '../../logic/money.js';
|
|
6
|
+
import { resolveMerchantCorrection, withMerchant, withMerchantLearning } from '../../logic/merchant.js';
|
|
7
|
+
import * as persistence from '../../logic/persistence.js';
|
|
8
|
+
import { toIsoDate } from '../../logic/period.js';
|
|
9
|
+
import { overlayResolvedTags } from '../../logic/tag.js';
|
|
10
|
+
import { addLocalizedLabels, assertExclusiveCategorySubCategory, defaultStatementLines, mergePatch, planNewTransaction, viewFromOutcome, } from '../../logic/transaction.js';
|
|
11
|
+
import { AccountType } from '../../models/account.js';
|
|
12
|
+
import { BILL_ENTITY_TAG, BillStatus } from '../../models/bill.js';
|
|
13
|
+
import { cardErrors, } from '../../models/credit-card.js';
|
|
14
|
+
import { notFound } from '../../models/error.js';
|
|
15
|
+
import { DELETE_TRANSACTION_CONFIRM_HINT, TRANSACTION_ENTITY_TAG, transactionErrors, } from '../../models/transaction.js';
|
|
16
|
+
import { Remedy } from '../../models/remedy.js';
|
|
17
|
+
import { matchCandidatesFor, resolveCardRef, resolveDecimals, resolveLegAccounts, resolveTagLinks, } from '../resolve.js';
|
|
18
|
+
import { decideTransactionUpdate, resolveCategorySelection } from '../transaction/core.js';
|
|
19
|
+
const assertCreditAccountLeg = (deps, tx) => resolveLegAccounts(deps, tx).map((legs) => legs.some((account) => account.type === AccountType.enum.credit));
|
|
20
|
+
const resolveOwnCardId = (existing) => okOr(existing.cardId, cardErrors.paidBillImmutable);
|
|
21
|
+
const touchBill = (bill) => persistence.update({ entity: BILL_ENTITY_TAG, model: billEntityFrom(bill) });
|
|
22
|
+
const openBillInsert = (billId, cardId, period) => persistence.insert({
|
|
23
|
+
entity: BILL_ENTITY_TAG,
|
|
24
|
+
model: {
|
|
25
|
+
id: billId,
|
|
26
|
+
creditCardId: cardId,
|
|
27
|
+
month: period.month,
|
|
28
|
+
year: period.year,
|
|
29
|
+
closeDate: period.closeDate,
|
|
30
|
+
dueDate: period.dueDate,
|
|
31
|
+
status: BillStatus.enum.open,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
const resolveBillWrite = (newId, cardId, period, existingBill) => {
|
|
35
|
+
if (existingBill)
|
|
36
|
+
return { billId: existingBill.id, billPersistable: touchBill(existingBill) };
|
|
37
|
+
const billId = newId();
|
|
38
|
+
return { billId, billPersistable: openBillInsert(billId, cardId, period) };
|
|
39
|
+
};
|
|
40
|
+
const planCardPurchase = (deps, input, source) => safeTry(async function* () {
|
|
41
|
+
yield* guard(assertExclusiveCategorySubCategory(input), transactionErrors.exclusiveCategorySubCategory);
|
|
42
|
+
yield* guard(assertBillPeriodPaired(input), cardErrors.billPeriodIncomplete);
|
|
43
|
+
const card = yield* resolveCardRef(deps, input.card);
|
|
44
|
+
const today = toIsoDate(deps.clock());
|
|
45
|
+
const currency = resolveCurrency(card, input);
|
|
46
|
+
const billPeriod = resolveBillPeriod(input.billMonth, input.billYear, input.date ?? today, card.closingDay, card.dueDay);
|
|
47
|
+
const existingBill = await deps.bills.findByCycle(card.id, billPeriod.month, billPeriod.year);
|
|
48
|
+
yield* guard(!existingBill || !isBillPaid(existingBill), cardErrors.paidBillImmutable);
|
|
49
|
+
const categorySelection = yield* resolveCategorySelection(deps, input, input.type);
|
|
50
|
+
const plan = planNewTransaction({
|
|
51
|
+
id: deps.newId(),
|
|
52
|
+
today,
|
|
53
|
+
input,
|
|
54
|
+
type: input.type,
|
|
55
|
+
source,
|
|
56
|
+
currency,
|
|
57
|
+
decimals: await resolveDecimals(deps, currency),
|
|
58
|
+
funding: {
|
|
59
|
+
refs: { accountId: card.accountId, cardId: card.id },
|
|
60
|
+
sourceId: card.id,
|
|
61
|
+
billPeriodKey: billPeriodKey(billPeriod),
|
|
62
|
+
},
|
|
63
|
+
categorySelection,
|
|
64
|
+
candidates: await matchCandidatesFor(deps, input.description, categorySelection),
|
|
65
|
+
keepsUnmatchedMerchant: false,
|
|
66
|
+
});
|
|
67
|
+
return ok({ ...plan, billPeriod, existingBill, cardId: card.id });
|
|
68
|
+
});
|
|
69
|
+
export const addCardPurchase = (deps, input, source) => safeTry(async function* () {
|
|
70
|
+
const { entity, classification, billPeriod, existingBill, cardId, idempotencyKey } = yield* planCardPurchase(deps, input, source);
|
|
71
|
+
const { billId, billPersistable } = resolveBillWrite(deps.newId, cardId, billPeriod, existingBill);
|
|
72
|
+
const tagLinks = await resolveTagLinks(deps, entity.id, input.tags);
|
|
73
|
+
// The bill leads: the transaction's bill_id FK must resolve within the same batch.
|
|
74
|
+
const persist = [
|
|
75
|
+
billPersistable,
|
|
76
|
+
...withMerchant([
|
|
77
|
+
persistence.insert({
|
|
78
|
+
entity: TRANSACTION_ENTITY_TAG,
|
|
79
|
+
model: { ...entity, refs: { ...entity.refs, billId } },
|
|
80
|
+
idempotencyKey,
|
|
81
|
+
}),
|
|
82
|
+
], entity.refs.merchantKey),
|
|
83
|
+
...(tagLinks ? [tagLinks.persistable] : []),
|
|
84
|
+
];
|
|
85
|
+
const locale = await deps.locale();
|
|
86
|
+
const response = (outcomes) => {
|
|
87
|
+
const outcome = persistence.outcomeFor(TRANSACTION_ENTITY_TAG, outcomes);
|
|
88
|
+
const view = viewFromOutcome(outcome, locale);
|
|
89
|
+
return {
|
|
90
|
+
transaction: tagLinks ? overlayResolvedTags(view, tagLinks.tags, outcomes) : view,
|
|
91
|
+
created: outcome.applied,
|
|
92
|
+
classification,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
return ok({ persist, response });
|
|
96
|
+
});
|
|
97
|
+
export const importCardStatement = async (deps, input, source) => {
|
|
98
|
+
const lines = defaultStatementLines(toIsoDate(deps.clock()), input.items, input.rawInput);
|
|
99
|
+
const localePromise = deps.locale();
|
|
100
|
+
const currenciesPromise = deps.currencies.list();
|
|
101
|
+
const cachedDeps = {
|
|
102
|
+
...deps,
|
|
103
|
+
locale: () => localePromise,
|
|
104
|
+
currencies: { ...deps.currencies, list: () => currenciesPromise },
|
|
105
|
+
};
|
|
106
|
+
const flowFor = (line) => () => addCardPurchase(cachedDeps, { ...line, card: input.card }, source);
|
|
107
|
+
return { lines, flowFor };
|
|
108
|
+
};
|
|
109
|
+
const resolveBillReassignment = (deps, cardId, existing, input) => safeTry(async function* () {
|
|
110
|
+
if (!R.isNonNullish(input.billMonth) || !R.isNonNullish(input.billYear)) {
|
|
111
|
+
return ok({ reassignedBillId: undefined, billPersistables: [] });
|
|
112
|
+
}
|
|
113
|
+
const currentBill = existing.billId ? await deps.bills.findById(existing.billId) : null;
|
|
114
|
+
yield* guard(!currentBill || !isBillPaid(currentBill), cardErrors.paidBillImmutable);
|
|
115
|
+
const card = yield* okOr(await deps.creditCards.findById(cardId), notFound('card', cardId, []));
|
|
116
|
+
const period = billPeriodForCycle(input.billMonth, input.billYear, card.closingDay, card.dueDay);
|
|
117
|
+
const targetBill = await deps.bills.findByCycle(card.id, period.month, period.year);
|
|
118
|
+
yield* guard(!targetBill || !isBillPaid(targetBill), cardErrors.paidBillImmutable);
|
|
119
|
+
const { billId, billPersistable } = resolveBillWrite(deps.newId, card.id, period, targetBill);
|
|
120
|
+
const sameCycle = currentBill?.id === billId;
|
|
121
|
+
const billPersistables = [billPersistable, ...(currentBill && !sameCycle ? [touchBill(currentBill)] : [])];
|
|
122
|
+
return ok({ reassignedBillId: billId, billPersistables });
|
|
123
|
+
});
|
|
124
|
+
const loadOwnCardTransaction = (deps, id) => safeTry(async function* () {
|
|
125
|
+
const existing = yield* okOr(await deps.transactions.getById(id), transactionErrors.notFound(id));
|
|
126
|
+
const isCreditOwned = yield* assertCreditAccountLeg(deps, existing);
|
|
127
|
+
yield* guard(isCreditOwned, transactionErrors.wrongOperation(Remedy.enum.update_account_transaction));
|
|
128
|
+
return ok({ existing, cardId: yield* resolveOwnCardId(existing) });
|
|
129
|
+
});
|
|
130
|
+
const guardCardPatch = (input) => safeTry(function* () {
|
|
131
|
+
yield* guard(assertExclusiveCategorySubCategory(input), transactionErrors.exclusiveCategorySubCategoryUpdate);
|
|
132
|
+
yield* guard(assertBillPeriodPaired(input), cardErrors.billPeriodIncomplete);
|
|
133
|
+
yield* guard(!R.isNonNullish(input.account), cardErrors.accountChangeRejectedForCard);
|
|
134
|
+
return ok();
|
|
135
|
+
});
|
|
136
|
+
export const updateCardTransaction = (deps, input) => safeTry(async function* () {
|
|
137
|
+
const { existing, cardId } = yield* loadOwnCardTransaction(deps, input.id);
|
|
138
|
+
yield* guardCardPatch(input);
|
|
139
|
+
const { reassignedBillId, billPersistables } = yield* resolveBillReassignment(deps, cardId, existing, input);
|
|
140
|
+
const patch = R.omit(input, ['billMonth', 'billYear']);
|
|
141
|
+
const { categorySelection } = yield* decideTransactionUpdate(deps, patch, existing);
|
|
142
|
+
const entity = mergePatch(existing, input, categorySelection, { billId: reassignedBillId });
|
|
143
|
+
const merchantCorrection = resolveMerchantCorrection(existing, entity.refs.categoryId);
|
|
144
|
+
const tagLinks = await resolveTagLinks(deps, entity.id, input.tags);
|
|
145
|
+
const persist = [
|
|
146
|
+
...withMerchantLearning(billPersistables, merchantCorrection),
|
|
147
|
+
persistence.update({ entity: TRANSACTION_ENTITY_TAG, model: { ...entity, version: existing.version } }),
|
|
148
|
+
...(tagLinks ? [tagLinks.persistable] : []),
|
|
149
|
+
];
|
|
150
|
+
const locale = await deps.locale();
|
|
151
|
+
const response = (outcomes) => {
|
|
152
|
+
const view = viewFromOutcome(persistence.outcomeFor(TRANSACTION_ENTITY_TAG, outcomes), locale);
|
|
153
|
+
return tagLinks ? overlayResolvedTags(view, tagLinks.tags, outcomes) : view;
|
|
154
|
+
};
|
|
155
|
+
return ok({ persist, response });
|
|
156
|
+
});
|
|
157
|
+
export const deleteCardTransaction = (deps, input) => safeTry(async function* () {
|
|
158
|
+
const existing = yield* okOr(await deps.transactions.getById(input.id), transactionErrors.notFound(input.id));
|
|
159
|
+
const isCreditOwned = yield* assertCreditAccountLeg(deps, existing);
|
|
160
|
+
yield* guard(isCreditOwned, transactionErrors.wrongOperation(Remedy.enum.delete_account_transaction));
|
|
161
|
+
const bill = existing.billId ? await deps.bills.findById(existing.billId) : null;
|
|
162
|
+
yield* guard(!bill || !isBillPaid(bill), cardErrors.paidBillImmutable);
|
|
163
|
+
const locale = await deps.locale();
|
|
164
|
+
const labeled = addLocalizedLabels(existing, locale);
|
|
165
|
+
if (!input.confirm) {
|
|
166
|
+
return ok({
|
|
167
|
+
persist: [],
|
|
168
|
+
response: {
|
|
169
|
+
deleted: false,
|
|
170
|
+
dryRun: true,
|
|
171
|
+
wouldDelete: labeled,
|
|
172
|
+
hint: DELETE_TRANSACTION_CONFIRM_HINT,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const persist = [
|
|
177
|
+
...(bill ? [touchBill(bill)] : []),
|
|
178
|
+
persistence.remove({ entity: TRANSACTION_ENTITY_TAG, id: existing.id, version: existing.version }),
|
|
179
|
+
];
|
|
180
|
+
return ok({ persist, response: { deleted: true, transaction: labeled } });
|
|
181
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const listCurrencies = (deps) => deps.currencies.list();
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ok, safeTry } from 'neverthrow';
|
|
2
|
+
import { guard } from '../common/result.js';
|
|
3
|
+
import * as persistence from '../logic/persistence.js';
|
|
4
|
+
import { CURRENCY_RATE_ENTITY_TAG, currencyRateErrors, } from '../models/currency-rate.js';
|
|
5
|
+
const toView = (fields) => fields;
|
|
6
|
+
const entityToFields = (entity) => ({
|
|
7
|
+
from: entity.fromCode,
|
|
8
|
+
to: entity.toCode,
|
|
9
|
+
rate: entity.rate,
|
|
10
|
+
asOf: entity.asOf,
|
|
11
|
+
source: entity.source ?? undefined,
|
|
12
|
+
});
|
|
13
|
+
export const setExchangeRate = (deps, input) => safeTry(async function* () {
|
|
14
|
+
yield* guard(input.from !== input.to, currencyRateErrors.samePair);
|
|
15
|
+
const existing = await deps.currencyRates.findByPair(input.from, input.to);
|
|
16
|
+
const fields = {
|
|
17
|
+
from: input.from,
|
|
18
|
+
to: input.to,
|
|
19
|
+
rate: input.rate,
|
|
20
|
+
asOf: input.asOf,
|
|
21
|
+
source: input.source,
|
|
22
|
+
};
|
|
23
|
+
const row = {
|
|
24
|
+
fromCode: fields.from,
|
|
25
|
+
toCode: fields.to,
|
|
26
|
+
rate: fields.rate,
|
|
27
|
+
asOf: fields.asOf,
|
|
28
|
+
source: fields.source ?? null,
|
|
29
|
+
};
|
|
30
|
+
const persist = existing
|
|
31
|
+
? [
|
|
32
|
+
persistence.update({
|
|
33
|
+
entity: CURRENCY_RATE_ENTITY_TAG,
|
|
34
|
+
model: { id: existing.id, ...row, version: existing.version },
|
|
35
|
+
}),
|
|
36
|
+
]
|
|
37
|
+
: [persistence.insert({ entity: CURRENCY_RATE_ENTITY_TAG, model: { id: deps.newId(), ...row } })];
|
|
38
|
+
return ok({ persist, response: toView(fields) });
|
|
39
|
+
});
|
|
40
|
+
export const listExchangeRates = async (deps) => (await deps.currencyRates.list()).map((entity) => toView(entityToFields(entity)));
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ok, safeTry } from 'neverthrow';
|
|
2
|
+
import { guard, okOr } from '../common/result.js';
|
|
3
|
+
import { findHtmlValidationIssues } from '../logic/dashboard.js';
|
|
4
|
+
import * as persistence from '../logic/persistence.js';
|
|
5
|
+
import { DASHBOARD_ENTITY_TAG, DashboardSource, dashboardErrors, } from '../models/dashboard.js';
|
|
6
|
+
import { sharedDefaultErrors } from '../models/tenancy.js';
|
|
7
|
+
export const saveDashboard = (deps, name, html) => safeTry(async function* () {
|
|
8
|
+
const issues = findHtmlValidationIssues(html);
|
|
9
|
+
yield* guard(issues.length === 0, dashboardErrors.invalidHtml(issues));
|
|
10
|
+
const ref = await deps.dashboards.findRefByName(name);
|
|
11
|
+
const dashboard = {
|
|
12
|
+
name,
|
|
13
|
+
html,
|
|
14
|
+
updatedAt: deps.clock().toISOString(),
|
|
15
|
+
source: DashboardSource.enum.inline,
|
|
16
|
+
};
|
|
17
|
+
const persist = ref === null
|
|
18
|
+
? [
|
|
19
|
+
persistence.insert({
|
|
20
|
+
entity: DASHBOARD_ENTITY_TAG,
|
|
21
|
+
model: { ...dashboard, id: deps.newId(), path: null, shared: false },
|
|
22
|
+
}),
|
|
23
|
+
]
|
|
24
|
+
: [
|
|
25
|
+
persistence.update({
|
|
26
|
+
entity: DASHBOARD_ENTITY_TAG,
|
|
27
|
+
model: { ...dashboard, id: ref.id, version: ref.version, path: null, shared: false },
|
|
28
|
+
}),
|
|
29
|
+
];
|
|
30
|
+
return ok({ persist, response: dashboard });
|
|
31
|
+
});
|
|
32
|
+
export const deleteDashboard = (deps, name) => safeTry(async function* () {
|
|
33
|
+
const ref = await deps.dashboards.findRefByName(name);
|
|
34
|
+
if (!ref) {
|
|
35
|
+
yield* guard(!(await deps.dashboards.isDefault(name)), sharedDefaultErrors.readOnly);
|
|
36
|
+
return ok({ persist: [], response: { deleted: false } });
|
|
37
|
+
}
|
|
38
|
+
const persist = [persistence.remove({ entity: DASHBOARD_ENTITY_TAG, id: ref.id, version: ref.version })];
|
|
39
|
+
return ok({ persist, response: { deleted: true } });
|
|
40
|
+
});
|
|
41
|
+
export const renameDashboard = (deps, name, newName) => safeTry(async function* () {
|
|
42
|
+
const entity = yield* okOr(await deps.dashboards.findByName(name), dashboardErrors.notFound(name));
|
|
43
|
+
yield* guard(!entity.shared, sharedDefaultErrors.readOnly);
|
|
44
|
+
if (newName === entity.name) {
|
|
45
|
+
return ok({
|
|
46
|
+
persist: [],
|
|
47
|
+
response: { name: entity.name, html: entity.html, updatedAt: entity.updatedAt, source: entity.source },
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
yield* guard(!(await deps.dashboards.findRefByName(newName)), dashboardErrors.duplicateName(newName));
|
|
51
|
+
const dashboard = {
|
|
52
|
+
name: newName,
|
|
53
|
+
html: entity.html,
|
|
54
|
+
updatedAt: deps.clock().toISOString(),
|
|
55
|
+
source: entity.source,
|
|
56
|
+
};
|
|
57
|
+
const persist = [
|
|
58
|
+
persistence.update({
|
|
59
|
+
entity: DASHBOARD_ENTITY_TAG,
|
|
60
|
+
model: { ...dashboard, id: entity.id, version: entity.version, path: entity.path, shared: false },
|
|
61
|
+
}),
|
|
62
|
+
];
|
|
63
|
+
return ok({ persist, response: dashboard });
|
|
64
|
+
});
|
|
65
|
+
export const listDashboards = (deps) => deps.dashboards.list();
|
|
66
|
+
export const getDashboard = (deps, name) => safeTry(async function* () {
|
|
67
|
+
return ok(yield* okOr(await deps.dashboards.get(name), dashboardErrors.notFound(name)));
|
|
68
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ok, safeTry } from 'neverthrow';
|
|
2
|
+
import { demoSeedStart } from '../../logic/demo/plan.js';
|
|
3
|
+
import * as persistence from '../../logic/persistence.js';
|
|
4
|
+
import { INSTANCE_SETTINGS_ENTITY_TAG } from '../../models/auth/entity.js';
|
|
5
|
+
import { InstanceKind, isDemoInstance } from '../../models/instance.js';
|
|
6
|
+
/** Writes the marker: only the demo seeder calls this. Marking a database that already says `demo` writes nothing. */
|
|
7
|
+
export const markDemoInstance = (deps) => safeTry(async function* () {
|
|
8
|
+
const current = await deps.instanceSettings.get();
|
|
9
|
+
if (isDemoInstance(current.instanceKind))
|
|
10
|
+
return ok({ persist: [], response: current.instanceKind });
|
|
11
|
+
const write = persistence.update({
|
|
12
|
+
entity: INSTANCE_SETTINGS_ENTITY_TAG,
|
|
13
|
+
model: { ...current, instanceKind: InstanceKind.enum.demo },
|
|
14
|
+
});
|
|
15
|
+
return ok({ persist: [write], response: InstanceKind.enum.demo });
|
|
16
|
+
});
|
|
17
|
+
export const completeDemoSeed = (deps, seededAt, country) => safeTry(async function* () {
|
|
18
|
+
const current = await deps.instanceSettings.get();
|
|
19
|
+
if (current.demoSeededAt !== null)
|
|
20
|
+
return ok({ persist: [], response: current.demoSeededAt });
|
|
21
|
+
const write = persistence.update({
|
|
22
|
+
entity: INSTANCE_SETTINGS_ENTITY_TAG,
|
|
23
|
+
model: { ...current, demoSeededAt: seededAt, demoCountry: country },
|
|
24
|
+
});
|
|
25
|
+
return ok({ persist: [write], response: seededAt });
|
|
26
|
+
});
|
|
27
|
+
export const demoSeedStatus = async (deps) => demoSeedStart({
|
|
28
|
+
hasUserData: await deps.instance.hasUserData(),
|
|
29
|
+
kind: await deps.instance.kind(),
|
|
30
|
+
seededAt: (await deps.instanceSettings.get()).demoSeededAt,
|
|
31
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { toIsoDate } from '../../logic/period.js';
|
|
2
|
+
import { demoTourContext, standardTourContext, tourCountryOf } from '../../logic/demo/tour.js';
|
|
3
|
+
import { isDemoInstance } from '../../models/instance.js';
|
|
4
|
+
/** Gather what the database says it is, decide the tour's shape; a standard one never reads a demo's language. */
|
|
5
|
+
export const getTourContext = async (deps) => {
|
|
6
|
+
if (!isDemoInstance(await deps.instance.kind()))
|
|
7
|
+
return standardTourContext(await deps.locale());
|
|
8
|
+
const locale = await deps.instance.locale();
|
|
9
|
+
const stored = await deps.settings.getLocale();
|
|
10
|
+
const country = tourCountryOf(await deps.instance.country(), stored?.baseCurrency ?? null, locale);
|
|
11
|
+
return demoTourContext(locale, country, toIsoDate(deps.clock()));
|
|
12
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DEFAULT_INSTANCE, isDemoInstance } from '../models/instance.js';
|
|
2
|
+
/** The marker, and — only for a demo — the language it speaks. A standard database never reads the locale. */
|
|
3
|
+
export const instanceFactsOf = async (tenancy) => {
|
|
4
|
+
const kind = await tenancy.instanceKind();
|
|
5
|
+
return isDemoInstance(kind) ? { kind, locale: await tenancy.instanceLocale() } : { ...DEFAULT_INSTANCE, kind };
|
|
6
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { localizeCategoryName } from '../logic/category.js';
|
|
2
|
+
import { DEFAULT_TOP_MERCHANTS_LIMIT } from '../models/merchant.js';
|
|
3
|
+
export const topMerchants = async (deps, limit = DEFAULT_TOP_MERCHANTS_LIMIT) => {
|
|
4
|
+
const [locale, rows] = await Promise.all([deps.locale(), deps.merchants.top(limit)]);
|
|
5
|
+
return rows.map((row) => ({
|
|
6
|
+
merchant: row.merchant,
|
|
7
|
+
transactionCount: row.transactionCount,
|
|
8
|
+
categoryName: row.categoryName
|
|
9
|
+
? (localizeCategoryName(row.categoryName, row.categoryNames, locale) ?? row.categoryName)
|
|
10
|
+
: null,
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ok, safeTry } from 'neverthrow';
|
|
2
|
+
import * as R from 'remeda';
|
|
3
|
+
import { normalizeMerchant, withMerchant } from '../logic/merchant.js';
|
|
4
|
+
import * as persistence from '../logic/persistence.js';
|
|
5
|
+
import { dueSchedule, newRule, recurringIdempotencyKey, withPeriodLabel } from '../logic/recurring.js';
|
|
6
|
+
import { toIsoDate } from '../logic/period.js';
|
|
7
|
+
import { defaultStatusFor, viewFromOutcome } from '../logic/transaction.js';
|
|
8
|
+
import { RECURRING_ENTITY_TAG, } from '../models/recurring.js';
|
|
9
|
+
import { ClassificationMethod, TRANSACTION_ENTITY_TAG, TransactionSource, } from '../models/transaction.js';
|
|
10
|
+
import { resolveAccountRef, resolveCategoryRef } from './resolve.js';
|
|
11
|
+
export const listRecurring = async (deps) => {
|
|
12
|
+
const [locale, rules] = await Promise.all([deps.locale(), deps.recurring.list()]);
|
|
13
|
+
return rules.map(withPeriodLabel(locale));
|
|
14
|
+
};
|
|
15
|
+
export const createRecurring = (deps, input) => safeTry(async function* () {
|
|
16
|
+
const account = input.account ? yield* resolveAccountRef(deps, input.account) : null;
|
|
17
|
+
const category = input.category ? yield* resolveCategoryRef(deps, input.category) : null;
|
|
18
|
+
const candidates = input.merchant ? [] : await deps.merchants.matchCandidates(normalizeMerchant(input.description));
|
|
19
|
+
const rule = newRule({ id: deps.newId(), input, account, category, candidates });
|
|
20
|
+
const persist = withMerchant([persistence.insert({ entity: RECURRING_ENTITY_TAG, model: rule })], rule.merchantKey);
|
|
21
|
+
const response = {
|
|
22
|
+
...rule,
|
|
23
|
+
accountName: account?.name,
|
|
24
|
+
categoryName: category?.name,
|
|
25
|
+
};
|
|
26
|
+
return ok({ persist, response });
|
|
27
|
+
});
|
|
28
|
+
const buildOccurrenceEntity = (deps, rule, due, today) => ({
|
|
29
|
+
id: deps.newId(),
|
|
30
|
+
description: rule.description,
|
|
31
|
+
amount: rule.amount,
|
|
32
|
+
type: rule.type,
|
|
33
|
+
status: defaultStatusFor(due, today),
|
|
34
|
+
date: due,
|
|
35
|
+
currency: rule.currency,
|
|
36
|
+
source: TransactionSource.enum.mcp,
|
|
37
|
+
classification: { method: ClassificationMethod.enum.user, confidence: 1 },
|
|
38
|
+
refs: { accountId: rule.accountId, categoryId: rule.categoryId, merchantKey: rule.merchantKey },
|
|
39
|
+
});
|
|
40
|
+
const planRule = (deps, rule, through, today) => {
|
|
41
|
+
const { dates, next } = dueSchedule(rule.nextDue, through, rule.period);
|
|
42
|
+
const occurrences = dates.map((date) => ({
|
|
43
|
+
rule: rule.description,
|
|
44
|
+
date,
|
|
45
|
+
persistable: persistence.insert({
|
|
46
|
+
entity: TRANSACTION_ENTITY_TAG,
|
|
47
|
+
model: buildOccurrenceEntity(deps, rule, date, today),
|
|
48
|
+
idempotencyKey: recurringIdempotencyKey(rule.id, date),
|
|
49
|
+
}),
|
|
50
|
+
}));
|
|
51
|
+
const advance = persistence.update({ entity: RECURRING_ENTITY_TAG, model: { ...rule, nextDue: next } });
|
|
52
|
+
return { occurrences, advance };
|
|
53
|
+
};
|
|
54
|
+
export const applyDueRecurring = (deps, options) => safeTry(async function* () {
|
|
55
|
+
const today = toIsoDate(deps.clock());
|
|
56
|
+
const through = options?.through ?? today;
|
|
57
|
+
const locale = await deps.locale();
|
|
58
|
+
const plans = (await deps.recurring.due(through)).map((rule) => planRule(deps, rule, through, today));
|
|
59
|
+
const occurrences = plans.flatMap((p) => p.occurrences);
|
|
60
|
+
const persist = [...occurrences.map((o) => o.persistable), ...plans.map((p) => p.advance)];
|
|
61
|
+
const response = (outcomes) => {
|
|
62
|
+
const applied = R.pipe(R.zip(occurrences, outcomes.slice(0, occurrences.length)), R.filter(([, outcome]) => outcome.applied), R.map(([occurrence, outcome]) => ({
|
|
63
|
+
rule: occurrence.rule,
|
|
64
|
+
date: occurrence.date,
|
|
65
|
+
transaction: viewFromOutcome(outcome, locale),
|
|
66
|
+
})));
|
|
67
|
+
return { applied, count: applied.length };
|
|
68
|
+
};
|
|
69
|
+
return ok({ persist, response });
|
|
70
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { err, ok, ResultAsync } from 'neverthrow';
|
|
2
|
+
import * as R from 'remeda';
|
|
3
|
+
import { okOr } from '../common/result.js';
|
|
4
|
+
import { buildSynonyms, resolveAndSort } from '../logic/category.js';
|
|
5
|
+
import { normalizeMerchant } from '../logic/merchant.js';
|
|
6
|
+
import { decimalsLookup } from '../logic/money.js';
|
|
7
|
+
import { resolveByName, resolveByNames } from '../logic/resolve.js';
|
|
8
|
+
import { resolveTagIds, resolveTagNames, tagSetPersistable } from '../logic/tag.js';
|
|
9
|
+
import { ambiguous, notFound } from '../models/error.js';
|
|
10
|
+
export const resolutionToResult = (res, kind) => {
|
|
11
|
+
if (res.kind === 'found')
|
|
12
|
+
return ok(res.entity);
|
|
13
|
+
return res.kind === 'none'
|
|
14
|
+
? err(notFound(kind, res.query, res.candidates))
|
|
15
|
+
: err(ambiguous(kind, res.query, res.candidates));
|
|
16
|
+
};
|
|
17
|
+
export const resolveAccountRef = (deps, name) => ResultAsync.fromSafePromise(deps.accounts.list()).andThen((accounts) => resolutionToResult(resolveByName(accounts, name), 'account'));
|
|
18
|
+
export const resolveCategoryRef = (deps, name) => ResultAsync.fromSafePromise(Promise.all([deps.categories.list(), deps.locale()])).andThen(([rawCategories, locale]) => {
|
|
19
|
+
const resolved = resolveAndSort(rawCategories, locale);
|
|
20
|
+
return resolutionToResult(resolveByNames(resolved, name, buildSynonyms(rawCategories)), 'category');
|
|
21
|
+
});
|
|
22
|
+
export const resolveSubCategoryRef = (deps, name) => ResultAsync.fromSafePromise(deps.subCategories.list()).andThen((subCategories) => resolutionToResult(resolveByName(subCategories, name), 'sub_category'));
|
|
23
|
+
export const resolveCardRef = (deps, name) => ResultAsync.fromSafePromise(deps.creditCards.list()).andThen((cards) => resolutionToResult(resolveByName(cards, name), 'card'));
|
|
24
|
+
export const resolveDecimals = async (deps, currency) => decimalsLookup(await deps.currencies.list())(currency);
|
|
25
|
+
export const matchCandidatesFor = async (deps, description, categorySelection) => categorySelection ? [] : deps.merchants.matchCandidates(normalizeMerchant(description));
|
|
26
|
+
export const resolveLegAccounts = (deps, tx) => ResultAsync.combine(R.pipe([tx.accountId, tx.toAccountId], R.filter(R.isNonNullish), R.unique(), R.map((id) => ResultAsync.fromSafePromise(deps.accounts.findById(id)).andThen((account) => okOr(account, notFound('account', id, []))))));
|
|
27
|
+
export const resolveTagLinks = async (deps, transactionId, tagNames) => {
|
|
28
|
+
if (R.isNullish(tagNames))
|
|
29
|
+
return null;
|
|
30
|
+
if (R.isEmpty(tagNames))
|
|
31
|
+
return { persistable: tagSetPersistable(transactionId, []), tags: [] };
|
|
32
|
+
const allTags = await deps.tags.list();
|
|
33
|
+
return {
|
|
34
|
+
persistable: tagSetPersistable(transactionId, resolveTagIds(tagNames, allTags)),
|
|
35
|
+
tags: resolveTagNames(tagNames, allTags),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ok, safeTry } from 'neverthrow';
|
|
2
|
+
import { guard } from '../common/result.js';
|
|
3
|
+
import { canAutoSwitchLocale, resolveBaseCurrency } from '../logic/locale.js';
|
|
4
|
+
import * as persistence from '../logic/persistence.js';
|
|
5
|
+
import { Locale, localeErrors, LocaleSource, USER_SETTINGS_ENTITY_TAG, } from '../models/locale.js';
|
|
6
|
+
export const getPreferences = async (deps) => {
|
|
7
|
+
const row = await deps.settings.getLocale();
|
|
8
|
+
const locale = row?.locale ?? Locale.enum.en;
|
|
9
|
+
return {
|
|
10
|
+
locale,
|
|
11
|
+
localeSource: row?.localeSource ?? LocaleSource.enum.default,
|
|
12
|
+
baseCurrency: resolveBaseCurrency(row?.baseCurrency, locale),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export const setLocale = (deps, input) => safeTry(async function* () {
|
|
16
|
+
const current = await deps.settings.getLocale();
|
|
17
|
+
const wouldChange = current?.locale !== input.locale;
|
|
18
|
+
yield* guard(canAutoSwitchLocale(input.source, current, wouldChange), localeErrors.explicitLocaleBlock);
|
|
19
|
+
if (!wouldChange && current) {
|
|
20
|
+
const response = { locale: current.locale, localeSource: current.localeSource };
|
|
21
|
+
return ok({ persist: [], response });
|
|
22
|
+
}
|
|
23
|
+
const entity = {
|
|
24
|
+
locale: input.locale,
|
|
25
|
+
localeSource: input.source,
|
|
26
|
+
baseCurrency: current?.baseCurrency ?? null,
|
|
27
|
+
};
|
|
28
|
+
const persist = current
|
|
29
|
+
? [persistence.update({ entity: USER_SETTINGS_ENTITY_TAG, model: { ...entity, version: current.version } })]
|
|
30
|
+
: [persistence.insert({ entity: USER_SETTINGS_ENTITY_TAG, model: entity })];
|
|
31
|
+
return ok({ persist, response: { locale: input.locale, localeSource: input.source } });
|
|
32
|
+
});
|
|
33
|
+
export const setBaseCurrency = (deps, input) => safeTry(async function* () {
|
|
34
|
+
const current = await deps.settings.getLocale();
|
|
35
|
+
if (current?.baseCurrency === input.baseCurrency) {
|
|
36
|
+
return ok({ persist: [], response: { baseCurrency: input.baseCurrency } });
|
|
37
|
+
}
|
|
38
|
+
const entity = {
|
|
39
|
+
locale: current?.locale ?? Locale.enum.en,
|
|
40
|
+
localeSource: current?.localeSource ?? LocaleSource.enum.default,
|
|
41
|
+
baseCurrency: input.baseCurrency,
|
|
42
|
+
};
|
|
43
|
+
const persist = current
|
|
44
|
+
? [persistence.update({ entity: USER_SETTINGS_ENTITY_TAG, model: { ...entity, version: current.version } })]
|
|
45
|
+
: [persistence.insert({ entity: USER_SETTINGS_ENTITY_TAG, model: entity })];
|
|
46
|
+
return ok({ persist, response: { baseCurrency: input.baseCurrency } });
|
|
47
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as R from 'remeda';
|
|
2
|
+
import { Locale } from '../models/locale.js';
|
|
3
|
+
import { DEFAULT_INSTANCE_KIND, isDemoInstance } from '../models/instance.js';
|
|
4
|
+
const databaseState = async (deps) => (await deps.health.reachable()) ? 'ok' : 'error';
|
|
5
|
+
export const getHealth = async (deps) => ({
|
|
6
|
+
status: 'ok',
|
|
7
|
+
db: await databaseState(deps),
|
|
8
|
+
});
|
|
9
|
+
export const getStatus = async (deps, version) => R.pipe(await Promise.all([
|
|
10
|
+
databaseState(deps),
|
|
11
|
+
deps.locale().catch(R.constant(Locale.enum.en)),
|
|
12
|
+
deps.instance.kind().catch(R.constant(DEFAULT_INSTANCE_KIND)),
|
|
13
|
+
]), ([db, locale, kind]) => ({
|
|
14
|
+
name: 'patty',
|
|
15
|
+
version,
|
|
16
|
+
db,
|
|
17
|
+
locale,
|
|
18
|
+
demo: isDemoInstance(kind),
|
|
19
|
+
}));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { consolidateInCurrency } from '../logic/currency-rate.js';
|
|
2
|
+
import { decimalsLookup } from '../logic/money.js';
|
|
3
|
+
import { periodRange } from '../logic/period.js';
|
|
4
|
+
import { summarize } from '../logic/summary.js';
|
|
5
|
+
export const getSpendingSummary = async (deps, periodInput, displayCurrency) => {
|
|
6
|
+
const period = { month: periodInput.month, year: periodInput.year };
|
|
7
|
+
const { from, to } = periodRange(period);
|
|
8
|
+
const [rows, locale, currencies] = await Promise.all([
|
|
9
|
+
deps.transactions.summaryRows(from, to),
|
|
10
|
+
deps.locale(),
|
|
11
|
+
deps.currencies.list(),
|
|
12
|
+
]);
|
|
13
|
+
const decimalsFor = decimalsLookup(currencies);
|
|
14
|
+
const currencySummaries = summarize(rows, locale, decimalsFor);
|
|
15
|
+
if (!displayCurrency)
|
|
16
|
+
return { period, currencies: currencySummaries };
|
|
17
|
+
const rates = await deps.currencyRates.list();
|
|
18
|
+
const amounts = currencySummaries.map((c) => ({ currency: c.currency, amount: c.expenses }));
|
|
19
|
+
const converted = consolidateInCurrency(amounts, displayCurrency, rates, deps.clock(), deps.rateStaleness, decimalsFor(displayCurrency));
|
|
20
|
+
return { period, currencies: currencySummaries, converted: { displayCurrency, ...converted } };
|
|
21
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ok, safeTry } from 'neverthrow';
|
|
2
|
+
import { guard } from '../common/result.js';
|
|
3
|
+
import * as persistence from '../logic/persistence.js';
|
|
4
|
+
import { tagErrors, TAG_ENTITY_TAG } from '../models/tag.js';
|
|
5
|
+
export const listTags = (deps) => deps.tags.list();
|
|
6
|
+
const assertTagNameAvailable = async (deps, name) => !(await deps.tags.findByName(name));
|
|
7
|
+
export const createTag = (deps, name) => safeTry(async function* () {
|
|
8
|
+
yield* guard(await assertTagNameAvailable(deps, name), tagErrors.duplicateName(name));
|
|
9
|
+
const tag = { id: deps.newId(), name };
|
|
10
|
+
const persist = [persistence.insert({ entity: TAG_ENTITY_TAG, model: tag })];
|
|
11
|
+
return ok({ persist, response: tag });
|
|
12
|
+
});
|
|
13
|
+
export const deleteTag = (deps, id) => safeTry(async function* () {
|
|
14
|
+
const tag = await deps.tags.findById(id);
|
|
15
|
+
if (!tag)
|
|
16
|
+
return ok({ persist: [], response: { deleted: false } });
|
|
17
|
+
const persist = [persistence.remove({ entity: TAG_ENTITY_TAG, id: tag.id, version: tag.version })];
|
|
18
|
+
return ok({ persist, response: { deleted: true } });
|
|
19
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as R from 'remeda';
|
|
2
|
+
import { summarizeBulkItems, toBulkItemResult } from '../../logic/transaction.js';
|
|
3
|
+
export const buildBulkResult = (outcomes, lines) => {
|
|
4
|
+
const items = R.pipe(R.zip(outcomes, lines), R.map(([outcome, line]) => toBulkItemResult(outcome, line.description)));
|
|
5
|
+
return { summary: summarizeBulkItems(items), items };
|
|
6
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ok, okAsync, safeTry } from 'neverthrow';
|
|
2
|
+
import * as R from 'remeda';
|
|
3
|
+
import { guard, okOr } from '../../common/result.js';
|
|
4
|
+
import * as persistence from '../../logic/persistence.js';
|
|
5
|
+
import { toIsoDate } from '../../logic/period.js';
|
|
6
|
+
import { addLocalizedLabels, assertExclusiveCategorySubCategory, buildTransactionView, entityFromExisting, hasCategory, hasSubCategory, isCategoryKindAllowed, isTransfer, resolveEffectiveType, } from '../../logic/transaction.js';
|
|
7
|
+
import { TRANSACTION_ENTITY_TAG, TransactionStatus, transactionErrors, } from '../../models/transaction.js';
|
|
8
|
+
import { resolveAccountRef, resolveCategoryRef, resolveSubCategoryRef } from '../resolve.js';
|
|
9
|
+
const resolveCategory = (deps, category, movementType) => safeTry(async function* () {
|
|
10
|
+
const cat = yield* resolveCategoryRef(deps, category);
|
|
11
|
+
if (movementType)
|
|
12
|
+
yield* guard(isCategoryKindAllowed(movementType, cat.kind), transactionErrors.categoryKindMismatch(movementType, cat.name, cat.kind));
|
|
13
|
+
return ok({ categoryId: cat.id, categoryName: cat.name });
|
|
14
|
+
});
|
|
15
|
+
const resolveSubCategory = (deps, subCategory, movementType) => safeTry(async function* () {
|
|
16
|
+
const subCat = yield* resolveSubCategoryRef(deps, subCategory);
|
|
17
|
+
if (movementType)
|
|
18
|
+
yield* guard(isCategoryKindAllowed(movementType, subCat.kind), transactionErrors.categoryKindMismatch(movementType, subCat.name, subCat.kind));
|
|
19
|
+
return ok({ categoryId: subCat.parentId, categoryName: subCat.parentName, subCategoryId: subCat.id });
|
|
20
|
+
});
|
|
21
|
+
export const resolveCategorySelection = (deps, input, movementType) => R.conditional(input, [hasSubCategory, (i) => resolveSubCategory(deps, i.subCategory, movementType)], [hasCategory, (i) => resolveCategory(deps, i.category, movementType)], () => okAsync(null));
|
|
22
|
+
export const confirmTransaction = (deps, input) => safeTry(async function* () {
|
|
23
|
+
const existing = yield* okOr(await deps.transactions.getById(input.id), transactionErrors.notFound(input.id));
|
|
24
|
+
const locale = await deps.locale();
|
|
25
|
+
if (existing.status === TransactionStatus.enum.effective) {
|
|
26
|
+
return ok({ persist: [], response: addLocalizedLabels(existing, locale) });
|
|
27
|
+
}
|
|
28
|
+
const hasEdit = input.amount !== undefined || input.date !== undefined;
|
|
29
|
+
yield* guard(!(hasEdit && isTransfer(existing)), transactionErrors.confirmEditNotAllowedForTransfer);
|
|
30
|
+
const date = input.date ?? existing.date;
|
|
31
|
+
yield* guard(date <= toIsoDate(deps.clock()), transactionErrors.cannotConfirmFutureDated(date));
|
|
32
|
+
const entity = {
|
|
33
|
+
...entityFromExisting(existing),
|
|
34
|
+
amount: input.amount ?? existing.amount,
|
|
35
|
+
date,
|
|
36
|
+
status: TransactionStatus.enum.effective,
|
|
37
|
+
};
|
|
38
|
+
const persist = [
|
|
39
|
+
persistence.update({ entity: TRANSACTION_ENTITY_TAG, model: { ...entity, version: existing.version } }),
|
|
40
|
+
];
|
|
41
|
+
return ok({ persist, response: buildTransactionView(locale) });
|
|
42
|
+
});
|
|
43
|
+
export const decideTransactionUpdate = (deps, input, existing) => safeTry(async function* () {
|
|
44
|
+
yield* guard(assertExclusiveCategorySubCategory(input), transactionErrors.exclusiveCategorySubCategoryUpdate);
|
|
45
|
+
const account = R.isNonNullish(input.account) ? yield* resolveAccountRef(deps, input.account) : null;
|
|
46
|
+
const effectiveType = resolveEffectiveType(existing, input);
|
|
47
|
+
const categorySelection = yield* resolveCategorySelection(deps, input, effectiveType);
|
|
48
|
+
return ok({ account, effectiveType, categorySelection });
|
|
49
|
+
});
|