@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,30 @@
|
|
|
1
|
+
import { err, ok } from 'neverthrow';
|
|
2
|
+
import { DemoFailureCode, DemoProbeAbsence, } from '../../models/demo/core.js';
|
|
3
|
+
import { InstanceKind } from '../../models/instance.js';
|
|
4
|
+
/** `createdHere`: this run owns the file, so a failed seed may remove it. */
|
|
5
|
+
/** The refusals that need no look at the file — and must come before anything is created beside it, a lock file
|
|
6
|
+
* included: the real database, and a symlink. */
|
|
7
|
+
export const refusalWithoutProbe = ({ isRealDatabase, isAlias, }) => {
|
|
8
|
+
if (isRealDatabase)
|
|
9
|
+
return DemoFailureCode.enum.real_database;
|
|
10
|
+
return isAlias ? DemoFailureCode.enum.not_demo : null;
|
|
11
|
+
};
|
|
12
|
+
export const planDemoDatabase = (facts) => {
|
|
13
|
+
const { reset, probe, holdsData } = facts;
|
|
14
|
+
const early = refusalWithoutProbe(facts);
|
|
15
|
+
if (early !== null)
|
|
16
|
+
return err(early);
|
|
17
|
+
if (probe === DemoProbeAbsence.enum.unreadable)
|
|
18
|
+
return err(DemoFailureCode.enum.not_demo);
|
|
19
|
+
if (probe === InstanceKind.enum.standard && (reset || holdsData))
|
|
20
|
+
return err(DemoFailureCode.enum.not_demo);
|
|
21
|
+
const deleteFirst = reset && probe === InstanceKind.enum.demo;
|
|
22
|
+
return ok({ deleteFirst, createdHere: deleteFirst || probe === DemoProbeAbsence.enum.missing });
|
|
23
|
+
};
|
|
24
|
+
const FAILURE_OF_STATUS = {
|
|
25
|
+
seeded: null,
|
|
26
|
+
present: null,
|
|
27
|
+
interrupted: DemoFailureCode.enum.interrupted,
|
|
28
|
+
not_demo: DemoFailureCode.enum.not_demo,
|
|
29
|
+
};
|
|
30
|
+
export const failureOfSeedStatus = (status) => FAILURE_OF_STATUS[status];
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import * as R from 'remeda';
|
|
3
|
+
import { billPeriodFor } from '../bill.js';
|
|
4
|
+
import { roundToDecimals } from '../money.js';
|
|
5
|
+
import { addDays } from '../period.js';
|
|
6
|
+
import { MovementType, TransactionStatus } from '../../models/transaction.js';
|
|
7
|
+
import { AccountType } from '../../models/account.js';
|
|
8
|
+
import { DEFAULT_DEMO_COUNTRY, DEMO_SEED_FRESH, DemoCountry, DemoFunding, DemoSeedStatus, DemoStepKind, } from '../../models/demo/core.js';
|
|
9
|
+
import { BudgetPeriod } from '../../models/budget.js';
|
|
10
|
+
import { isDemoInstance } from '../../models/instance.js';
|
|
11
|
+
import { Locale, LocaleSource } from '../../models/locale.js';
|
|
12
|
+
import { CurrencyCode, FIAT_DECIMALS } from '../../models/money.js';
|
|
13
|
+
import { RecurringPeriod } from '../../models/recurring.js';
|
|
14
|
+
/** The generator is a pure function of this seed, the country pack and today's date. */
|
|
15
|
+
export const DEMO_SEED = 'patty-demo';
|
|
16
|
+
/** The last four full months plus the current one, so the dashboards always look current. */
|
|
17
|
+
export const DEMO_MONTHS_BACK = 4;
|
|
18
|
+
/** One bitcoin in US dollars, for the demo's USDC/BTC position (a demo price, not a quote). */
|
|
19
|
+
export const DEMO_BTC_USD_PRICE = 100_000;
|
|
20
|
+
export const DEMO_RATE_SOURCE = 'demo';
|
|
21
|
+
const TRIP_MONTH_OFFSET = -2;
|
|
22
|
+
const TRIP_START_DAY = 10;
|
|
23
|
+
const FREELANCE_MONTH_OFFSETS = [-3, -1];
|
|
24
|
+
const SAVINGS_TRANSFER_DAY = 6;
|
|
25
|
+
const INVESTMENT_TRANSFER_DAY = 7;
|
|
26
|
+
const WALLET_TRANSFER_DAY = 12;
|
|
27
|
+
const SPEND_PREFIX = { main: 'main', global: 'global' };
|
|
28
|
+
const STEP = DemoStepKind.enum;
|
|
29
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
30
|
+
const isoDate = (year, month, day) => `${year}-${pad(month)}-${pad(day)}`;
|
|
31
|
+
const parseDate = (date) => {
|
|
32
|
+
const [year = 0, month = 0, day = 0] = date.split('-').map(Number);
|
|
33
|
+
return { year, month, day };
|
|
34
|
+
};
|
|
35
|
+
const daysInMonth = ({ year, month }) => new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
36
|
+
const shiftMonth = ({ year, month }, delta) => {
|
|
37
|
+
const index = year * 12 + (month - 1) + delta;
|
|
38
|
+
const shiftedYear = Math.floor(index / 12);
|
|
39
|
+
return { year: shiftedYear, month: index - shiftedYear * 12 + 1 };
|
|
40
|
+
};
|
|
41
|
+
const monthContext = (today, offset) => {
|
|
42
|
+
const now = parseDate(today);
|
|
43
|
+
const shifted = shiftMonth(now, offset);
|
|
44
|
+
const days = daysInMonth(shifted);
|
|
45
|
+
return { ...shifted, offset, days, lastDay: offset === 0 ? Math.min(now.day, days) : days };
|
|
46
|
+
};
|
|
47
|
+
const windowOf = (today) => R.range(-DEMO_MONTHS_BACK, 1).map((offset) => monthContext(today, offset));
|
|
48
|
+
const dateIn = (month, day) => isoDate(month.year, month.month, Math.min(day, daysInMonth(month)));
|
|
49
|
+
/** A number in [0, 1) that depends only on the seed and the parts: the whole generator's source of "randomness". */
|
|
50
|
+
const unit = (...parts) => createHash('sha256')
|
|
51
|
+
.update([DEMO_SEED, ...parts].join('|'))
|
|
52
|
+
.digest()
|
|
53
|
+
.readUInt32BE(0) /
|
|
54
|
+
2 ** 32;
|
|
55
|
+
const roundToStep = (value, step) => roundToDecimals(Math.max(step, Math.round(value / step) * step), FIAT_DECIMALS);
|
|
56
|
+
const amountBetween = (pack, min, max, key) => roundToStep(min + unit(key, 'amount') * (max - min), pack.amountStep);
|
|
57
|
+
const fundingOf = (pack, via) => {
|
|
58
|
+
const byFunding = {
|
|
59
|
+
[DemoFunding.enum.checking]: { account: pack.accounts.checking.name },
|
|
60
|
+
[DemoFunding.enum.wallet]: { account: pack.accounts.wallet.name },
|
|
61
|
+
[DemoFunding.enum.primaryCard]: { card: pack.cards.primary.name },
|
|
62
|
+
[DemoFunding.enum.secondaryCard]: { card: pack.cards.secondary.name },
|
|
63
|
+
[DemoFunding.enum.global]: { account: pack.global?.name ?? pack.accounts.checking.name },
|
|
64
|
+
};
|
|
65
|
+
return byFunding[via];
|
|
66
|
+
};
|
|
67
|
+
const optionalFields = ({ tag, pending }) => ({
|
|
68
|
+
...(tag ? { tags: [tag] } : {}),
|
|
69
|
+
...(pending ? { status: TransactionStatus.enum.pending } : {}),
|
|
70
|
+
});
|
|
71
|
+
const spendStep = (funding, spend) => {
|
|
72
|
+
const { description, category, amount, date, discriminator } = spend;
|
|
73
|
+
const common = { description, category, amount, date, discriminator, ...optionalFields(spend) };
|
|
74
|
+
return 'card' in funding
|
|
75
|
+
? { kind: STEP.purchase, date, input: { ...common, card: funding.card, type: MovementType.enum.expense } }
|
|
76
|
+
: { kind: STEP.expense, date, input: { ...common, account: funding.account } };
|
|
77
|
+
};
|
|
78
|
+
const spendOccurrence = (pack, prefix, month, line, lineIndex) => (occurrence) => {
|
|
79
|
+
const key = [prefix, lineIndex, month.offset, occurrence].join('|');
|
|
80
|
+
const day = 1 + Math.floor(unit(key, 'day') * month.days);
|
|
81
|
+
if (day > month.lastDay)
|
|
82
|
+
return [];
|
|
83
|
+
const spend = {
|
|
84
|
+
description: line.description,
|
|
85
|
+
category: line.category,
|
|
86
|
+
amount: amountBetween(pack, line.min, line.max, key),
|
|
87
|
+
date: dateIn(month, day),
|
|
88
|
+
discriminator: key,
|
|
89
|
+
tag: line.tag,
|
|
90
|
+
};
|
|
91
|
+
return [spendStep(fundingOf(pack, line.via), spend)];
|
|
92
|
+
};
|
|
93
|
+
const spendStepsOf = (pack, prefix, lines, months) => R.flatMap(months, (month) => R.flatMap(lines, (line, lineIndex) => R.flatMap(R.range(0, line.perMonth), spendOccurrence(pack, prefix, month, line, lineIndex))));
|
|
94
|
+
const tripStepsOf = (pack, today) => {
|
|
95
|
+
const start = dateIn(shiftMonth(parseDate(today), TRIP_MONTH_OFFSET), TRIP_START_DAY);
|
|
96
|
+
return pack.trip.items.map((item, index) => {
|
|
97
|
+
const date = addDays(start, item.dayOffset);
|
|
98
|
+
const spend = {
|
|
99
|
+
...R.pick(item, ['description', 'category', 'amount']),
|
|
100
|
+
date,
|
|
101
|
+
discriminator: `trip|${index}`,
|
|
102
|
+
};
|
|
103
|
+
return spendStep(fundingOf(pack, item.via), spend);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const pendingStepOf = (pack, today) => (line, index) => {
|
|
107
|
+
const date = addDays(today, line.daysAhead);
|
|
108
|
+
const { description, category, amount } = line;
|
|
109
|
+
const common = { description, category, amount, date, account: pack.accounts.checking.name };
|
|
110
|
+
const input = { ...common, discriminator: `pending|${index}`, status: TransactionStatus.enum.pending };
|
|
111
|
+
return { kind: line.income ? STEP.income : STEP.expense, date, input };
|
|
112
|
+
};
|
|
113
|
+
const recurringStepOf = (pack, start, type) => (line) => ({
|
|
114
|
+
kind: STEP.recurring,
|
|
115
|
+
date: dateIn(start, 1),
|
|
116
|
+
input: {
|
|
117
|
+
description: line.description,
|
|
118
|
+
amount: line.amount,
|
|
119
|
+
type,
|
|
120
|
+
period: RecurringPeriod.enum.monthly,
|
|
121
|
+
startDate: dateIn(start, line.day),
|
|
122
|
+
account: pack.accounts.checking.name,
|
|
123
|
+
category: line.category,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
const freelanceStepsOf = (pack, today) => FREELANCE_MONTH_OFFSETS.map((offset) => monthContext(today, offset)).map((month) => {
|
|
127
|
+
const { description, category, amount, day } = pack.freelance;
|
|
128
|
+
const date = dateIn(month, day);
|
|
129
|
+
const input = { description, category, amount, date, account: pack.accounts.checking.name };
|
|
130
|
+
return { kind: STEP.income, date, input: { ...input, discriminator: `freelance|${month.offset}` } };
|
|
131
|
+
});
|
|
132
|
+
const transferStepsOf = (pack, months) => {
|
|
133
|
+
const transfers = [
|
|
134
|
+
{ to: pack.accounts.savings.name, day: SAVINGS_TRANSFER_DAY, line: pack.transfers.savings },
|
|
135
|
+
{ to: pack.accounts.investment.name, day: INVESTMENT_TRANSFER_DAY, line: pack.transfers.investment },
|
|
136
|
+
{ to: pack.accounts.wallet.name, day: WALLET_TRANSFER_DAY, line: pack.transfers.wallet },
|
|
137
|
+
];
|
|
138
|
+
return R.flatMap(months, (month) => R.pipe(transfers, R.filter(({ day }) => day <= month.lastDay), R.map(({ to, day, line }) => {
|
|
139
|
+
const date = dateIn(month, day);
|
|
140
|
+
const { description, amount } = line;
|
|
141
|
+
return {
|
|
142
|
+
kind: STEP.transfer,
|
|
143
|
+
date,
|
|
144
|
+
input: { from: pack.accounts.checking.name, to, amount, date, description },
|
|
145
|
+
};
|
|
146
|
+
})));
|
|
147
|
+
};
|
|
148
|
+
const isCardPurchase = (step) => step.kind === STEP.purchase;
|
|
149
|
+
const payAndMaybeClose = (card, closesLast, periods) => (period, index) => {
|
|
150
|
+
const { month, year, dueDate } = period;
|
|
151
|
+
const pay = {
|
|
152
|
+
kind: STEP.payBill,
|
|
153
|
+
date: dueDate,
|
|
154
|
+
input: { card: card.name, month, year, paymentDate: dueDate },
|
|
155
|
+
};
|
|
156
|
+
const revert = { kind: STEP.revertBill, date: dueDate, input: { card: card.name, month, year } };
|
|
157
|
+
return closesLast && index === periods.length - 1 ? [pay, revert] : [pay];
|
|
158
|
+
};
|
|
159
|
+
/** Every bill whose due date has passed is paid; the secondary card's latest one is paid and then reverted, so it
|
|
160
|
+
* ends `closed` (a payment made from the wrong account and taken back). Bills still to come stay `open`. */
|
|
161
|
+
const billStepsOf = (pack, purchases, today) => {
|
|
162
|
+
const cards = [
|
|
163
|
+
{ card: pack.cards.primary, closesLast: false },
|
|
164
|
+
{ card: pack.cards.secondary, closesLast: true },
|
|
165
|
+
];
|
|
166
|
+
return R.flatMap(cards, ({ card, closesLast }) => {
|
|
167
|
+
const periods = R.pipe(purchases, R.filter(isCardPurchase), R.filter((step) => step.input.card === card.name), R.map((step) => billPeriodFor(step.date, card.closingDay, card.dueDay)), R.uniqueBy((period) => `${period.month}-${period.year}`), R.filter((period) => period.dueDate <= today), R.sortBy((period) => period.dueDate));
|
|
168
|
+
return R.flatMap(periods, payAndMaybeClose(card, closesLast, periods));
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
const isSpend = (step) => step.kind === STEP.expense || step.kind === STEP.purchase;
|
|
172
|
+
/** A purchase on the pack's foreign-currency account: it never counts against a budget in the pack's currency. */
|
|
173
|
+
const isForeignFunded = (pack, step) => step.kind === STEP.expense && pack.global !== undefined && step.input.account === pack.global.name;
|
|
174
|
+
/** Budgets are sized against the last full month's spend: a factor under 1 is a budget that month already blew. */
|
|
175
|
+
const budgetStepsOf = (pack, spending, today, start) => {
|
|
176
|
+
const lastMonth = monthContext(today, -1);
|
|
177
|
+
const prefix = `${lastMonth.year}-${pad(lastMonth.month)}-`;
|
|
178
|
+
const spentByCategory = R.pipe(spending, R.filter(isSpend), R.filter((step) => !isForeignFunded(pack, step)), R.filter((step) => step.date.startsWith(prefix)), R.groupBy((step) => step.input.category ?? ''), R.mapValues(R.sumBy((step) => step.input.amount)));
|
|
179
|
+
return R.pipe(pack.budgets, R.filter(({ category }) => (spentByCategory[category] ?? 0) > 0), R.map(({ category, factor }) => ({
|
|
180
|
+
kind: STEP.budget,
|
|
181
|
+
date: start,
|
|
182
|
+
input: {
|
|
183
|
+
category,
|
|
184
|
+
currency: pack.currency,
|
|
185
|
+
limit: roundToStep((spentByCategory[category] ?? 0) * factor, pack.amountStep),
|
|
186
|
+
period: BudgetPeriod.enum.monthly,
|
|
187
|
+
},
|
|
188
|
+
})));
|
|
189
|
+
};
|
|
190
|
+
const ratesStepsOf = (pack, ratesAsOf, start) => {
|
|
191
|
+
const usdc = pack.usdRate;
|
|
192
|
+
const btc = pack.usdRate * DEMO_BTC_USD_PRICE;
|
|
193
|
+
const quoted = [
|
|
194
|
+
{ from: CurrencyCode.enum.USDC, rate: usdc },
|
|
195
|
+
{ from: CurrencyCode.enum.BTC, rate: btc },
|
|
196
|
+
...(pack.global ? [{ from: CurrencyCode.enum.USD, rate: pack.usdRate }] : []),
|
|
197
|
+
];
|
|
198
|
+
return R.pipe(quoted, R.filter(({ from }) => from !== pack.currency), R.map(({ from, rate }) => ({
|
|
199
|
+
kind: STEP.rate,
|
|
200
|
+
date: start,
|
|
201
|
+
input: { from, to: pack.currency, rate, asOf: ratesAsOf, source: DEMO_RATE_SOURCE },
|
|
202
|
+
})));
|
|
203
|
+
};
|
|
204
|
+
const accountStepOf = (start) => (type, currency, spec) => ({
|
|
205
|
+
kind: STEP.account,
|
|
206
|
+
date: start,
|
|
207
|
+
input: { name: spec.name, type, currency, initialBalance: spec.initialBalance },
|
|
208
|
+
});
|
|
209
|
+
const accountStepsOf = (pack, start) => {
|
|
210
|
+
const account = accountStepOf(start);
|
|
211
|
+
const { accounts, global, currency } = pack;
|
|
212
|
+
return [
|
|
213
|
+
account(AccountType.enum.checking, currency, accounts.checking),
|
|
214
|
+
account(AccountType.enum.savings, currency, accounts.savings),
|
|
215
|
+
account(AccountType.enum.investment, currency, accounts.investment),
|
|
216
|
+
account(AccountType.enum.wallet, currency, accounts.wallet),
|
|
217
|
+
account(AccountType.enum.investment, CurrencyCode.enum.USDC, accounts.usdc),
|
|
218
|
+
account(AccountType.enum.investment, CurrencyCode.enum.BTC, accounts.btc),
|
|
219
|
+
...(global ? [account(AccountType.enum.checking, CurrencyCode.enum.USD, global)] : []),
|
|
220
|
+
];
|
|
221
|
+
};
|
|
222
|
+
const cardStepsOf = (pack, start) => [pack.cards.primary, pack.cards.secondary].map((card) => ({
|
|
223
|
+
kind: STEP.card,
|
|
224
|
+
date: start,
|
|
225
|
+
input: {
|
|
226
|
+
name: card.name,
|
|
227
|
+
currency: pack.currency,
|
|
228
|
+
closingDay: card.closingDay,
|
|
229
|
+
dueDay: card.dueDay,
|
|
230
|
+
limit: card.limit,
|
|
231
|
+
paymentAccount: pack.accounts.checking.name,
|
|
232
|
+
},
|
|
233
|
+
}));
|
|
234
|
+
const recurringStepsOf = (pack, start) => {
|
|
235
|
+
const month = parseDate(start);
|
|
236
|
+
return [
|
|
237
|
+
recurringStepOf(pack, month, MovementType.enum.income)(pack.salary),
|
|
238
|
+
...[pack.rent, ...pack.subscriptions].map(recurringStepOf(pack, month, MovementType.enum.expense)),
|
|
239
|
+
];
|
|
240
|
+
};
|
|
241
|
+
const setupStepsOf = (pack, ratesAsOf, start) => [
|
|
242
|
+
{ kind: STEP.locale, date: start, input: { locale: pack.locale, source: LocaleSource.enum.explicit } },
|
|
243
|
+
{ kind: STEP.baseCurrency, date: start, input: { baseCurrency: pack.currency } },
|
|
244
|
+
...accountStepsOf(pack, start),
|
|
245
|
+
...cardStepsOf(pack, start),
|
|
246
|
+
...pack.tags.map((name) => ({ kind: STEP.tag, date: start, name })),
|
|
247
|
+
...ratesStepsOf(pack, ratesAsOf, start),
|
|
248
|
+
...recurringStepsOf(pack, start),
|
|
249
|
+
];
|
|
250
|
+
/**
|
|
251
|
+
* The whole demo as an ordered list of writes, each to be run through the real flow of the same name with the clock
|
|
252
|
+
* set to its date (`min(date, today)` — a pending item is dated ahead of today). Pure: a function of the seed, the
|
|
253
|
+
* country pack, `today` and the instant the exchange rates are observed at (`ratesAsOf`, a full timestamp: a rate
|
|
254
|
+
* stamped earlier than the seed would read as stale at once).
|
|
255
|
+
* Dated steps sort stably, so the setup (dated at the window's start) leads, a bill is paid
|
|
256
|
+
* after the purchases it holds (its due date follows its closing date), and recurring rules materialize last.
|
|
257
|
+
*/
|
|
258
|
+
export const planDemo = (pack, today, ratesAsOf) => {
|
|
259
|
+
const months = windowOf(today);
|
|
260
|
+
const first = months[0] ?? monthContext(today, 0);
|
|
261
|
+
const start = dateIn(first, 1);
|
|
262
|
+
const spending = [
|
|
263
|
+
...spendStepsOf(pack, SPEND_PREFIX.main, pack.spending, months),
|
|
264
|
+
...spendStepsOf(pack, SPEND_PREFIX.global, pack.global?.spending ?? [], months),
|
|
265
|
+
...tripStepsOf(pack, today),
|
|
266
|
+
];
|
|
267
|
+
return R.sortBy([
|
|
268
|
+
...setupStepsOf(pack, ratesAsOf, start),
|
|
269
|
+
...budgetStepsOf(pack, spending, today, start),
|
|
270
|
+
...spending,
|
|
271
|
+
...transferStepsOf(pack, months),
|
|
272
|
+
...freelanceStepsOf(pack, today),
|
|
273
|
+
...billStepsOf(pack, spending, today),
|
|
274
|
+
...pack.pending.map(pendingStepOf(pack, today)),
|
|
275
|
+
{ kind: STEP.applyDue, date: today, through: today },
|
|
276
|
+
], (step) => step.date);
|
|
277
|
+
};
|
|
278
|
+
/** The clock a step runs at: its own date, except a step dated ahead of today (a pending item), which runs at today. */
|
|
279
|
+
export const clockDateOf = (step, today) => (step.date > today ? today : step.date);
|
|
280
|
+
/** The optional script between language and region (`Latn`) is four letters, and skipped. The region is the subtag
|
|
281
|
+
* right after it; anything later (a `-u-co-…` extension) is never a region. */
|
|
282
|
+
const SCRIPT_SUBTAG = /^[A-Za-z]{4}$/;
|
|
283
|
+
const REGION_COUNTRY = {
|
|
284
|
+
BR: DemoCountry.enum.br,
|
|
285
|
+
US: DemoCountry.enum.us,
|
|
286
|
+
MX: DemoCountry.enum.mx,
|
|
287
|
+
CO: DemoCountry.enum.co,
|
|
288
|
+
};
|
|
289
|
+
const LANGUAGE_COUNTRY = {
|
|
290
|
+
[Locale.enum.pt]: DemoCountry.enum.br,
|
|
291
|
+
[Locale.enum.es]: DemoCountry.enum.mx,
|
|
292
|
+
[Locale.enum.en]: DemoCountry.enum.us,
|
|
293
|
+
};
|
|
294
|
+
/** The demo's default country for an OS locale tag (`es-CO`, `pt_BR.UTF-8`): its region when it is one of the four,
|
|
295
|
+
* else its language, else the default. */
|
|
296
|
+
export const resolveDemoCountry = (osLocale) => {
|
|
297
|
+
const [language = '', ...subtags] = (osLocale ?? '').replace(/[.@].*$/, '').split(/[-_]/);
|
|
298
|
+
const [next, afterScript] = subtags;
|
|
299
|
+
const region = (next !== undefined && SCRIPT_SUBTAG.test(next) ? afterScript : next) ?? '';
|
|
300
|
+
return REGION_COUNTRY[region.toUpperCase()] ?? LANGUAGE_COUNTRY[language.toLowerCase()] ?? DEFAULT_DEMO_COUNTRY;
|
|
301
|
+
};
|
|
302
|
+
export const demoSeedStart = ({ hasUserData, kind, seededAt, }) => {
|
|
303
|
+
if (!hasUserData)
|
|
304
|
+
return DEMO_SEED_FRESH;
|
|
305
|
+
if (!isDemoInstance(kind))
|
|
306
|
+
return DemoSeedStatus.enum.not_demo;
|
|
307
|
+
return seededAt === null ? DemoSeedStatus.enum.interrupted : DemoSeedStatus.enum.present;
|
|
308
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as R from 'remeda';
|
|
2
|
+
import { DemoCountry } from '../../models/demo/core.js';
|
|
3
|
+
import { InstanceKind } from '../../models/instance.js';
|
|
4
|
+
import { CurrencyCode } from '../../models/money.js';
|
|
5
|
+
import { TOUR_FACTS } from '../../models/demo/tour.js';
|
|
6
|
+
import { resolveDemoCountry } from './plan.js';
|
|
7
|
+
import { addDays } from '../period.js';
|
|
8
|
+
/** Each country pack has a currency of its own, so the base currency the seeder set names the country. */
|
|
9
|
+
const CURRENCY_COUNTRY = {
|
|
10
|
+
[CurrencyCode.enum.BRL]: DemoCountry.enum.br,
|
|
11
|
+
[CurrencyCode.enum.USD]: DemoCountry.enum.us,
|
|
12
|
+
[CurrencyCode.enum.MXN]: DemoCountry.enum.mx,
|
|
13
|
+
[CurrencyCode.enum.COP]: DemoCountry.enum.co,
|
|
14
|
+
};
|
|
15
|
+
/** The demo's country: the one the seeder recorded. A demo seeded before that was recorded is resolved from the
|
|
16
|
+
* base currency its seed stored (Spanish alone cannot tell Mexico from Colombia), then from the language. */
|
|
17
|
+
export const tourCountryOf = (recorded, baseCurrency, locale) => recorded ?? (baseCurrency && CURRENCY_COUNTRY[baseCurrency]) ?? resolveDemoCountry(locale);
|
|
18
|
+
export const standardTourContext = (locale) => ({ kind: InstanceKind.enum.standard, locale });
|
|
19
|
+
/** The demo's tour: its language, the trip's destination and a sample statement dated just before `today`. */
|
|
20
|
+
export const demoTourContext = (locale, country, today) => {
|
|
21
|
+
const { destination, statement } = TOUR_FACTS[country];
|
|
22
|
+
return {
|
|
23
|
+
kind: InstanceKind.enum.demo,
|
|
24
|
+
locale,
|
|
25
|
+
destination,
|
|
26
|
+
statement: R.map(statement, (line) => ({
|
|
27
|
+
date: addDays(today, -line.daysAgo),
|
|
28
|
+
description: line.description,
|
|
29
|
+
amount: line.amount,
|
|
30
|
+
income: line.income ?? false,
|
|
31
|
+
})),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isAbsolute, relative, sep } from 'node:path';
|
|
2
|
+
const PARENT = '..';
|
|
3
|
+
/** Both arguments are real, absolute paths (symlinks already resolved by the shell): `path` is only string math. */
|
|
4
|
+
const isWithin = (container, directory) => {
|
|
5
|
+
const way = relative(container, directory);
|
|
6
|
+
const leavesContainer = way === PARENT || way.startsWith(`${PARENT}${sep}`);
|
|
7
|
+
return way === '' || (!leavesContainer && !isAbsolute(way));
|
|
8
|
+
};
|
|
9
|
+
/** A key must never sit next to the data it unlocks: not in the database's directory, nor under it. */
|
|
10
|
+
export const isBesideData = (dataDirectory, destinationDirectory) => isWithin(dataDirectory, destinationDirectory);
|
|
11
|
+
/** A snapshot must never be aimed at the live database itself. */
|
|
12
|
+
export const isDatabaseFile = (databaseFile, destination) => databaseFile === destination;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EncryptionKey } from '../models/encryption-key.js';
|
|
2
|
+
import { KEY_FILE_LINE_ENDINGS, KEY_FILE_MAX_CHARACTERS, KeyImportRefusal, } from '../models/key-import.js';
|
|
3
|
+
export const decodeKeyFile = (contents) => {
|
|
4
|
+
if (contents.length > KEY_FILE_MAX_CHARACTERS)
|
|
5
|
+
return null;
|
|
6
|
+
const ending = KEY_FILE_LINE_ENDINGS.find((candidate) => contents.endsWith(candidate));
|
|
7
|
+
const parsed = EncryptionKey.safeParse(ending === undefined ? contents : contents.slice(0, -ending.length));
|
|
8
|
+
return parsed.success ? parsed.data : null;
|
|
9
|
+
};
|
|
10
|
+
const REFUSALS = [
|
|
11
|
+
[KeyImportRefusal.enum.key_file_configured, (sources) => sources.keyFileConfigured],
|
|
12
|
+
[KeyImportRefusal.enum.key_env_configured, (sources) => sources.keyEnvConfigured],
|
|
13
|
+
[KeyImportRefusal.enum.keychain_holds_key, (sources) => sources.keychainHoldsKey],
|
|
14
|
+
];
|
|
15
|
+
export const keyImportRefusal = (sources) => REFUSALS.find(([, applies]) => applies(sources))?.[0] ?? null;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CurrencyCode } from '../models/money.js';
|
|
2
|
+
import { Locale, LocaleSource } from '../models/locale.js';
|
|
3
|
+
export const canAutoSwitchLocale = (source, current, wouldChange) => !(source === LocaleSource.enum.inferred && current?.localeSource === LocaleSource.enum.explicit && wouldChange);
|
|
4
|
+
export const localeToBaseCurrency = (locale) => locale === Locale.enum.pt ? CurrencyCode.enum.BRL : CurrencyCode.enum.USD;
|
|
5
|
+
export const resolveBaseCurrency = (stored, locale) => stored ?? localeToBaseCurrency(locale);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { accountTypeLabels } from '../models/account.js';
|
|
2
|
+
import { billStatusLabels } from '../models/bill.js';
|
|
3
|
+
import { categoryKindLabels } from '../models/category.js';
|
|
4
|
+
import { recurringPeriodLabels } from '../models/recurring.js';
|
|
5
|
+
import { transactionStatusLabels, transactionTypeLabels, } from '../models/transaction.js';
|
|
6
|
+
const localize = (map, value, locale) => map[value][locale] ?? map[value].en;
|
|
7
|
+
export const localizeAccountType = (v, l) => localize(accountTypeLabels, v, l);
|
|
8
|
+
export const localizeCategoryKind = (v, l) => localize(categoryKindLabels, v, l);
|
|
9
|
+
export const localizeRecurringPeriod = (v, l) => localize(recurringPeriodLabels, v, l);
|
|
10
|
+
export const localizeBillStatus = (v, l) => localize(billStatusLabels, v, l);
|
|
11
|
+
export const localizeTransactionType = (v, l) => localize(transactionTypeLabels, v, l);
|
|
12
|
+
export const localizeTransactionStatus = (v, l) => localize(transactionStatusLabels, v, l);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MERCHANT_CATEGORY_ENTITY_TAG, MERCHANT_ENTITY_TAG, NOISE_PREFIXES, MERCHANT_LEARNING_WEIGHT_DELTA, } from '../models/merchant.js';
|
|
2
|
+
import { ClassificationMethod } from '../models/transaction.js';
|
|
3
|
+
import { insert } from './persistence.js';
|
|
4
|
+
export const normalizeMerchant = (description) => description
|
|
5
|
+
.toLowerCase()
|
|
6
|
+
.normalize('NFD')
|
|
7
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
8
|
+
.replace(NOISE_PREFIXES, '')
|
|
9
|
+
.replace(/[*_#-]/g, ' ')
|
|
10
|
+
.replace(/\d+/g, ' ')
|
|
11
|
+
.replace(/[^a-z\s]/g, ' ')
|
|
12
|
+
.replace(/\s+/g, ' ')
|
|
13
|
+
.trim();
|
|
14
|
+
export const resolveMerchantCorrection = (existing, newCategoryId) => {
|
|
15
|
+
if (!newCategoryId || newCategoryId === existing.categoryId || !existing.merchant)
|
|
16
|
+
return null;
|
|
17
|
+
return {
|
|
18
|
+
merchantKey: existing.merchant,
|
|
19
|
+
categoryId: newCategoryId,
|
|
20
|
+
weightDelta: MERCHANT_LEARNING_WEIGHT_DELTA,
|
|
21
|
+
origin: ClassificationMethod.enum.history,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export const withMerchant = (persist, merchantKey) => merchantKey ? [insert({ entity: MERCHANT_ENTITY_TAG, model: { key: merchantKey } }), ...persist] : [...persist];
|
|
25
|
+
export const withMerchantLearning = (persist, correction) => correction
|
|
26
|
+
? [
|
|
27
|
+
...persist,
|
|
28
|
+
insert({ entity: MERCHANT_ENTITY_TAG, model: { key: correction.merchantKey } }),
|
|
29
|
+
insert({ entity: MERCHANT_CATEGORY_ENTITY_TAG, model: correction }),
|
|
30
|
+
]
|
|
31
|
+
: [...persist];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isDatabaseAhead = (lastAppliedMillis, newestKnownMillis) => lastAppliedMillis !== undefined && lastAppliedMillis > newestKnownMillis;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as R from 'remeda';
|
|
2
|
+
import { CurrencyCode, FIAT_DECIMALS } from '../models/money.js';
|
|
3
|
+
export const decimalsLookup = (currencies) => {
|
|
4
|
+
const byCode = R.indexBy(currencies, (c) => c.code);
|
|
5
|
+
return (code) => byCode[code]?.decimals ?? FIAT_DECIMALS;
|
|
6
|
+
};
|
|
7
|
+
export const resolveCurrency = (source, input) => source?.currency ?? input.currency ?? CurrencyCode.enum.USD;
|
|
8
|
+
export const roundToDecimals = (value, decimals) => {
|
|
9
|
+
const factor = 10 ** decimals;
|
|
10
|
+
return Math.round((value + Number.EPSILON) * factor) / factor;
|
|
11
|
+
};
|
|
12
|
+
export const roundMoney = (value) => roundToDecimals(value, FIAT_DECIMALS);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isNonNullish } from 'remeda';
|
|
2
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
3
|
+
export const periodRange = ({ month, year }) => {
|
|
4
|
+
const from = `${year}-${pad(month)}-01`;
|
|
5
|
+
const to = month === 12 ? `${year + 1}-01-01` : `${year}-${pad(month + 1)}-01`;
|
|
6
|
+
return { from, to };
|
|
7
|
+
};
|
|
8
|
+
export const toIsoDate = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
9
|
+
/** `date` (`YYYY-MM-DD`) moved by `days`, calendar arithmetic with no time zone in it. */
|
|
10
|
+
export const addDays = (date, days) => {
|
|
11
|
+
const [year = 0, month = 0, day = 0] = date.split('-').map(Number);
|
|
12
|
+
const moved = new Date(Date.UTC(year, month - 1, day + days));
|
|
13
|
+
return `${moved.getUTCFullYear()}-${pad(moved.getUTCMonth() + 1)}-${pad(moved.getUTCDate())}`;
|
|
14
|
+
};
|
|
15
|
+
export const hasPeriod = (input) => isNonNullish(input.month) && isNonNullish(input.year);
|
|
16
|
+
export const hasDateRange = (input) => isNonNullish(input.from) || isNonNullish(input.to);
|
|
17
|
+
export const assertHasPeriodOrRange = (input) => hasPeriod(input) || hasDateRange(input);
|
|
18
|
+
export const assertExclusivePeriodOrRange = (input) => !(hasPeriod(input) && hasDateRange(input));
|
|
19
|
+
export const baselineRange = (period, baselineMonths) => {
|
|
20
|
+
const { from: to } = periodRange(period);
|
|
21
|
+
const monthIndex = period.year * 12 + (period.month - 1) - baselineMonths;
|
|
22
|
+
const year = Math.floor(monthIndex / 12);
|
|
23
|
+
const month = monthIndex - year * 12 + 1;
|
|
24
|
+
return { from: `${year}-${pad(month)}-01`, to };
|
|
25
|
+
};
|
|
26
|
+
export const daysBetween = (a, b) => {
|
|
27
|
+
const [ay, am, ad] = a.split('-').map(Number);
|
|
28
|
+
const [by, bm, bd] = b.split('-').map(Number);
|
|
29
|
+
return Math.round((Date.UTC(by, bm - 1, bd) - Date.UTC(ay, am - 1, ad)) / 86_400_000);
|
|
30
|
+
};
|
|
31
|
+
export const lookbackFrom = (today, lookbackMonths) => {
|
|
32
|
+
const [year, month] = today.split('-').map(Number);
|
|
33
|
+
const monthIndex = year * 12 + (month - 1) - lookbackMonths;
|
|
34
|
+
const fromYear = Math.floor(monthIndex / 12);
|
|
35
|
+
const fromMonth = monthIndex - fromYear * 12 + 1;
|
|
36
|
+
return `${fromYear}-${pad(fromMonth)}-01`;
|
|
37
|
+
};
|
|
38
|
+
export const periodBounds = (input) => hasPeriod(input) ? periodRange({ month: input.month, year: input.year }) : { from: null, to: null };
|
|
39
|
+
export const resolveDateRange = (input) => {
|
|
40
|
+
const range = hasPeriod(input) ? periodRange({ month: input.month, year: input.year }) : null;
|
|
41
|
+
return {
|
|
42
|
+
from: range?.from ?? input.from ?? null,
|
|
43
|
+
to: range?.to ?? input.to ?? null,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as R from 'remeda';
|
|
2
|
+
import { checkVersion, INITIAL_VERSION, PersistOp, } from '@rfc0/effect-runner';
|
|
3
|
+
export const insert = (fields) => ({
|
|
4
|
+
op: PersistOp.enum.insert,
|
|
5
|
+
...fields,
|
|
6
|
+
});
|
|
7
|
+
export const update = (fields) => ({
|
|
8
|
+
op: PersistOp.enum.update,
|
|
9
|
+
...fields,
|
|
10
|
+
});
|
|
11
|
+
export const remove = (fields) => ({
|
|
12
|
+
op: PersistOp.enum.delete,
|
|
13
|
+
...fields,
|
|
14
|
+
});
|
|
15
|
+
export const check = (fields) => checkVersion(fields.entity, fields.id, fields.version);
|
|
16
|
+
export const outcomeFor = (tag, outcomes) => {
|
|
17
|
+
const matches = R.filter(outcomes, (o) => o.entity === tag);
|
|
18
|
+
const [outcome] = matches;
|
|
19
|
+
if (!outcome)
|
|
20
|
+
throw new Error(`outcomeFor: no persist outcome found for entity "${tag}"`);
|
|
21
|
+
if (matches.length > 1)
|
|
22
|
+
throw new Error(`outcomeFor: multiple persist outcomes found for entity "${tag}"`);
|
|
23
|
+
return outcome;
|
|
24
|
+
};
|
|
25
|
+
export const entityDbAdapter = (entity, modelToDb) => {
|
|
26
|
+
const persistableToDb = (p) => {
|
|
27
|
+
if (p.entity !== entity)
|
|
28
|
+
return p;
|
|
29
|
+
switch (p.op) {
|
|
30
|
+
case PersistOp.enum.insert:
|
|
31
|
+
return { ...p, model: modelToDb({ ...p.model, version: INITIAL_VERSION }) };
|
|
32
|
+
case PersistOp.enum.update:
|
|
33
|
+
return { ...p, model: modelToDb(p.model) };
|
|
34
|
+
case PersistOp.enum.delete:
|
|
35
|
+
case PersistOp.enum.check:
|
|
36
|
+
return p;
|
|
37
|
+
default: {
|
|
38
|
+
const _exhaustive = p;
|
|
39
|
+
throw new Error(`entityDbAdapter(${entity}): unhandled persistable op ${JSON.stringify(_exhaustive)}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const outcomeToDb = (outcome) => ({
|
|
44
|
+
...outcome,
|
|
45
|
+
persist: outcome.persist.map(persistableToDb),
|
|
46
|
+
});
|
|
47
|
+
return { persistableToDb, outcomeToDb };
|
|
48
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { purry } from 'remeda';
|
|
2
|
+
import { pickClassification } from './classify.js';
|
|
3
|
+
import { localizeRecurringPeriod } from './localize.js';
|
|
4
|
+
import { normalizeMerchant } from './merchant.js';
|
|
5
|
+
import { resolveCurrency } from './money.js';
|
|
6
|
+
import { MAX_RECURRING_OCCURRENCES_PER_RUN, } from '../models/recurring.js';
|
|
7
|
+
const _withPeriodLabel = (rule, locale) => ({
|
|
8
|
+
...rule,
|
|
9
|
+
periodLabel: localizeRecurringPeriod(rule.period, locale),
|
|
10
|
+
});
|
|
11
|
+
export function withPeriodLabel(...args) {
|
|
12
|
+
return purry(_withPeriodLabel, args);
|
|
13
|
+
}
|
|
14
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
15
|
+
const daysInMonth = (month, year) => new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
16
|
+
const clampDay = (day, month, year) => Math.min(day, daysInMonth(month, year));
|
|
17
|
+
export const nextDue = (current, period) => {
|
|
18
|
+
const [y, m, d] = current.split('-').map(Number);
|
|
19
|
+
if (period === 'weekly') {
|
|
20
|
+
const dt = new Date(Date.UTC(y, m - 1, d + 7));
|
|
21
|
+
return `${dt.getUTCFullYear()}-${pad(dt.getUTCMonth() + 1)}-${pad(dt.getUTCDate())}`;
|
|
22
|
+
}
|
|
23
|
+
if (period === 'monthly') {
|
|
24
|
+
const nm = m === 12 ? 1 : m + 1;
|
|
25
|
+
const ny = m === 12 ? y + 1 : y;
|
|
26
|
+
return `${ny}-${pad(nm)}-${pad(clampDay(d, nm, ny))}`;
|
|
27
|
+
}
|
|
28
|
+
return `${y + 1}-${pad(m)}-${pad(clampDay(d, m, y + 1))}`;
|
|
29
|
+
};
|
|
30
|
+
export const recurringIdempotencyKey = (ruleId, due) => `rec-${ruleId}-${due}`;
|
|
31
|
+
export const dueSchedule = (start, through, period, max = MAX_RECURRING_OCCURRENCES_PER_RUN) => {
|
|
32
|
+
const advance = (due, taken) => taken.length < max && due <= through ? advance(nextDue(due, period), [...taken, due]) : { dates: taken, next: due };
|
|
33
|
+
return advance(start, []);
|
|
34
|
+
};
|
|
35
|
+
export const ruleMerchantKey = (input, candidates) => {
|
|
36
|
+
if (input.merchant)
|
|
37
|
+
return normalizeMerchant(input.merchant) || undefined;
|
|
38
|
+
return pickClassification(candidates).merchantKey ?? (normalizeMerchant(input.description) || undefined);
|
|
39
|
+
};
|
|
40
|
+
export const newRule = (facts) => ({
|
|
41
|
+
id: facts.id,
|
|
42
|
+
description: facts.input.description,
|
|
43
|
+
amount: facts.input.amount,
|
|
44
|
+
type: facts.input.type,
|
|
45
|
+
period: facts.input.period,
|
|
46
|
+
nextDue: facts.input.startDate,
|
|
47
|
+
currency: resolveCurrency(facts.account, facts.input),
|
|
48
|
+
accountId: facts.account?.id,
|
|
49
|
+
categoryId: facts.category?.id,
|
|
50
|
+
merchantKey: ruleMerchantKey(facts.input, facts.candidates),
|
|
51
|
+
});
|