tapimo 0.1.0 → 0.3.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/README.md +57 -16
- package/dist/ApiKey.d.ts +4 -1
- package/dist/ApiKey.d.ts.map +1 -1
- package/dist/ApiKey.js +6 -2
- package/dist/ApiKey.js.map +1 -1
- package/dist/ApiKeys.d.ts +98 -3
- package/dist/ApiKeys.d.ts.map +1 -1
- package/dist/ApiKeys.js +150 -1
- package/dist/ApiKeys.js.map +1 -1
- package/dist/App.d.ts +7917 -2315
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js +141 -329
- package/dist/App.js.map +1 -1
- package/dist/Scope.d.ts +20 -4
- package/dist/Scope.d.ts.map +1 -1
- package/dist/Scope.js +23 -4
- package/dist/Scope.js.map +1 -1
- package/dist/Webhooks.d.ts +2 -2
- package/dist/Webhooks.d.ts.map +1 -1
- package/dist/Webhooks.js +2 -2
- package/dist/Webhooks.js.map +1 -1
- package/dist/admin/App.d.ts +203 -120
- package/dist/admin/App.d.ts.map +1 -1
- package/dist/admin/apps/api-keys.d.ts +111 -6
- package/dist/admin/apps/api-keys.d.ts.map +1 -1
- package/dist/admin/apps/api-keys.js +67 -0
- package/dist/admin/apps/api-keys.js.map +1 -1
- package/dist/admin/apps/scopes.d.ts +12 -1
- package/dist/admin/apps/scopes.d.ts.map +1 -1
- package/dist/admin/apps/scopes.js +3 -0
- package/dist/admin/apps/scopes.js.map +1 -1
- package/dist/admin/apps/verified-tokens.d.ts +116 -116
- package/dist/admin/apps/verified-tokens.js +1 -1
- package/dist/admin/apps/verified-tokens.js.map +1 -1
- package/dist/admin/ui.generated.d.ts +1 -1
- package/dist/admin/ui.generated.js +13 -13
- package/dist/admin/ui.generated.js.map +1 -1
- package/dist/analytics/Analytics.d.ts +151 -0
- package/dist/analytics/Analytics.d.ts.map +1 -0
- package/dist/analytics/Analytics.js +212 -0
- package/dist/analytics/Analytics.js.map +1 -0
- package/dist/analytics/tables/requestEvents.d.ts +215 -0
- package/dist/analytics/tables/requestEvents.d.ts.map +1 -0
- package/dist/analytics/tables/requestEvents.js +264 -0
- package/dist/analytics/tables/requestEvents.js.map +1 -0
- package/dist/apps/data/App.d.ts +19576 -0
- package/dist/apps/data/App.d.ts.map +1 -0
- package/dist/apps/data/App.js +272 -0
- package/dist/apps/data/App.js.map +1 -0
- package/dist/apps/data/index.d.ts +3 -0
- package/dist/apps/data/index.d.ts.map +1 -0
- package/dist/apps/data/index.js +3 -0
- package/dist/apps/data/index.js.map +1 -0
- package/dist/apps/{activities.d.ts → data/routes/activities.d.ts} +32 -32
- package/dist/apps/{activities.d.ts.map → data/routes/activities.d.ts.map} +1 -1
- package/dist/apps/{activities.js → data/routes/activities.js} +13 -13
- package/dist/apps/data/routes/activities.js.map +1 -0
- package/dist/apps/{addresses.d.ts → data/routes/addresses.d.ts} +22 -22
- package/dist/apps/{addresses.d.ts.map → data/routes/addresses.d.ts.map} +1 -1
- package/dist/apps/{addresses.js → data/routes/addresses.js} +5 -5
- package/dist/apps/data/routes/addresses.js.map +1 -0
- package/dist/apps/{balances.d.ts → data/routes/balances.d.ts} +4 -4
- package/dist/apps/data/routes/balances.d.ts.map +1 -0
- package/dist/apps/{balances.js → data/routes/balances.js} +42 -11
- package/dist/apps/data/routes/balances.js.map +1 -0
- package/dist/apps/{blocks.d.ts → data/routes/blocks.d.ts} +47 -47
- package/dist/apps/data/routes/blocks.d.ts.map +1 -0
- package/dist/apps/{blocks.js → data/routes/blocks.js} +13 -13
- package/dist/apps/data/routes/blocks.js.map +1 -0
- package/dist/apps/{coingecko.d.ts → data/routes/coingecko.d.ts} +8 -8
- package/dist/apps/data/routes/coingecko.d.ts.map +1 -0
- package/dist/apps/{coingecko.js → data/routes/coingecko.js} +13 -13
- package/dist/apps/data/routes/coingecko.js.map +1 -0
- package/dist/apps/{exchanges.d.ts → data/routes/exchanges.d.ts} +108 -108
- package/dist/apps/data/routes/exchanges.d.ts.map +1 -0
- package/dist/apps/{exchanges.js → data/routes/exchanges.js} +19 -19
- package/dist/apps/data/routes/exchanges.js.map +1 -0
- package/dist/apps/{fee-amm.d.ts → data/routes/fee-amm.d.ts} +39 -39
- package/dist/apps/data/routes/fee-amm.d.ts.map +1 -0
- package/dist/apps/{fee-amm.js → data/routes/fee-amm.js} +17 -17
- package/dist/apps/data/routes/fee-amm.js.map +1 -0
- package/dist/apps/data/routes/funding.d.ts +765 -0
- package/dist/apps/data/routes/funding.d.ts.map +1 -0
- package/dist/apps/data/routes/funding.js +383 -0
- package/dist/apps/data/routes/funding.js.map +1 -0
- package/dist/apps/{indexer.d.ts → data/routes/indexer.d.ts} +4 -4
- package/dist/apps/data/routes/indexer.d.ts.map +1 -0
- package/dist/apps/{indexer.js → data/routes/indexer.js} +13 -9
- package/dist/apps/data/routes/indexer.js.map +1 -0
- package/dist/apps/{receipts.d.ts → data/routes/receipts.d.ts} +49 -49
- package/dist/apps/data/routes/receipts.d.ts.map +1 -0
- package/dist/apps/{receipts.js → data/routes/receipts.js} +14 -20
- package/dist/apps/data/routes/receipts.js.map +1 -0
- package/dist/apps/{rpc.d.ts → data/routes/rpc.d.ts} +33 -40
- package/dist/apps/data/routes/rpc.d.ts.map +1 -0
- package/dist/apps/{rpc.js → data/routes/rpc.js} +35 -7
- package/dist/apps/data/routes/rpc.js.map +1 -0
- package/dist/apps/{tokenlist.d.ts → data/routes/tokenlist.d.ts} +40 -40
- package/dist/apps/data/routes/tokenlist.d.ts.map +1 -0
- package/dist/apps/{tokenlist.js → data/routes/tokenlist.js} +8 -8
- package/dist/apps/data/routes/tokenlist.js.map +1 -0
- package/dist/apps/{tokens.d.ts → data/routes/tokens.d.ts} +468 -468
- package/dist/apps/data/routes/tokens.d.ts.map +1 -0
- package/dist/apps/{tokens.js → data/routes/tokens.js} +19 -19
- package/dist/apps/data/routes/tokens.js.map +1 -0
- package/dist/apps/{transactions.d.ts → data/routes/transactions.d.ts} +304 -304
- package/dist/apps/data/routes/transactions.d.ts.map +1 -0
- package/dist/apps/{transactions.js → data/routes/transactions.js} +13 -13
- package/dist/apps/data/routes/transactions.js.map +1 -0
- package/dist/apps/{transfers.d.ts → data/routes/transfers.d.ts} +62 -62
- package/dist/apps/data/routes/transfers.d.ts.map +1 -0
- package/dist/apps/{transfers.js → data/routes/transfers.js} +13 -13
- package/dist/apps/data/routes/transfers.js.map +1 -0
- package/dist/apps/{verified-tokens.d.ts → data/routes/verified-tokens.d.ts} +6 -6
- package/dist/apps/data/routes/verified-tokens.d.ts.map +1 -0
- package/dist/apps/{verified-tokens.js → data/routes/verified-tokens.js} +9 -9
- package/dist/apps/data/routes/verified-tokens.js.map +1 -0
- package/dist/apps/{webhooks.d.ts → data/routes/webhooks.d.ts} +17 -17
- package/dist/apps/{webhooks.d.ts.map → data/routes/webhooks.d.ts.map} +1 -1
- package/dist/apps/{webhooks.js → data/routes/webhooks.js} +38 -34
- package/dist/apps/data/routes/webhooks.js.map +1 -0
- package/dist/apps/docs/App.d.ts +29 -0
- package/dist/apps/docs/App.d.ts.map +1 -0
- package/dist/apps/docs/App.js +54 -0
- package/dist/apps/docs/App.js.map +1 -0
- package/dist/{internal/OpenApi.fonts.d.ts → apps/docs/fonts.d.ts} +1 -1
- package/dist/apps/docs/fonts.d.ts.map +1 -0
- package/dist/{internal/OpenApi.fonts.js → apps/docs/fonts.js} +1 -1
- package/dist/apps/docs/fonts.js.map +1 -0
- package/dist/apps/docs/index.d.ts +2 -0
- package/dist/apps/docs/index.d.ts.map +1 -0
- package/dist/apps/docs/index.js +2 -0
- package/dist/apps/docs/index.js.map +1 -0
- package/dist/{internal/OpenApi.logo.d.ts → apps/docs/logo.d.ts} +1 -1
- package/dist/apps/docs/logo.d.ts.map +1 -0
- package/dist/{internal/OpenApi.logo.js → apps/docs/logo.js} +1 -1
- package/dist/apps/docs/logo.js.map +1 -0
- package/dist/apps/docs/reference.d.ts +21 -0
- package/dist/apps/docs/reference.d.ts.map +1 -0
- package/dist/apps/docs/reference.js +112 -0
- package/dist/apps/docs/reference.js.map +1 -0
- package/dist/apps/index.d.ts +5 -0
- package/dist/apps/index.d.ts.map +1 -0
- package/dist/apps/index.js +5 -0
- package/dist/apps/index.js.map +1 -0
- package/dist/apps/mcp.d.ts +76 -0
- package/dist/apps/mcp.d.ts.map +1 -0
- package/dist/apps/mcp.js +188 -0
- package/dist/apps/mcp.js.map +1 -0
- package/dist/apps/metadata.d.ts +7 -0
- package/dist/apps/metadata.d.ts.map +1 -0
- package/dist/apps/metadata.js +15 -0
- package/dist/apps/metadata.js.map +1 -0
- package/dist/apps/platform/App.d.ts +5262 -0
- package/dist/apps/platform/App.d.ts.map +1 -0
- package/dist/apps/platform/App.js +84 -0
- package/dist/apps/platform/App.js.map +1 -0
- package/dist/apps/platform/Billing.d.ts +279 -0
- package/dist/apps/platform/Billing.d.ts.map +1 -0
- package/dist/apps/platform/Billing.js +477 -0
- package/dist/apps/platform/Billing.js.map +1 -0
- package/dist/apps/platform/index.d.ts +3 -0
- package/dist/apps/platform/index.d.ts.map +1 -0
- package/dist/apps/platform/index.js +3 -0
- package/dist/apps/platform/index.js.map +1 -0
- package/dist/apps/platform/routes/api-keys.d.ts +973 -0
- package/dist/apps/platform/routes/api-keys.d.ts.map +1 -0
- package/dist/apps/platform/routes/api-keys.js +430 -0
- package/dist/apps/platform/routes/api-keys.js.map +1 -0
- package/dist/apps/platform/routes/billing.d.ts +1520 -0
- package/dist/apps/platform/routes/billing.d.ts.map +1 -0
- package/dist/apps/platform/routes/billing.js +795 -0
- package/dist/apps/platform/routes/billing.js.map +1 -0
- package/dist/apps/platform/routes/invitations.d.ts +851 -0
- package/dist/apps/platform/routes/invitations.d.ts.map +1 -0
- package/dist/apps/platform/routes/invitations.js +471 -0
- package/dist/apps/platform/routes/invitations.js.map +1 -0
- package/dist/apps/platform/routes/me.d.ts +95 -0
- package/dist/apps/platform/routes/me.d.ts.map +1 -0
- package/dist/apps/platform/routes/me.js +81 -0
- package/dist/apps/platform/routes/me.js.map +1 -0
- package/dist/apps/platform/routes/members.d.ts +554 -0
- package/dist/apps/platform/routes/members.d.ts.map +1 -0
- package/dist/apps/platform/routes/members.js +251 -0
- package/dist/apps/platform/routes/members.js.map +1 -0
- package/dist/apps/platform/routes/orgs.d.ts +596 -0
- package/dist/apps/platform/routes/orgs.d.ts.map +1 -0
- package/dist/apps/platform/routes/orgs.js +276 -0
- package/dist/apps/platform/routes/orgs.js.map +1 -0
- package/dist/apps/platform/routes/projects.d.ts +740 -0
- package/dist/apps/platform/routes/projects.d.ts.map +1 -0
- package/dist/apps/platform/routes/projects.js +286 -0
- package/dist/apps/platform/routes/projects.js.map +1 -0
- package/dist/apps/platform/routes/scopes.d.ts +107 -0
- package/dist/apps/platform/routes/scopes.d.ts.map +1 -0
- package/dist/apps/platform/routes/scopes.js +66 -0
- package/dist/apps/platform/routes/scopes.js.map +1 -0
- package/dist/apps/platform/routes/usage.d.ts +588 -0
- package/dist/apps/platform/routes/usage.d.ts.map +1 -0
- package/dist/apps/platform/routes/usage.js +391 -0
- package/dist/apps/platform/routes/usage.js.map +1 -0
- package/dist/apps/relay/App.d.ts +44 -0
- package/dist/apps/relay/App.d.ts.map +1 -0
- package/dist/apps/relay/App.js +211 -0
- package/dist/apps/relay/App.js.map +1 -0
- package/dist/apps/relay/Sponsorships.d.ts +107 -0
- package/dist/apps/relay/Sponsorships.d.ts.map +1 -0
- package/dist/apps/relay/Sponsorships.js +194 -0
- package/dist/apps/relay/Sponsorships.js.map +1 -0
- package/dist/apps/relay/index.d.ts +3 -0
- package/dist/apps/relay/index.d.ts.map +1 -0
- package/dist/apps/relay/index.js +3 -0
- package/dist/apps/relay/index.js.map +1 -0
- package/dist/cli/Cli.d.ts +9 -2
- package/dist/cli/Cli.d.ts.map +1 -1
- package/dist/cli/Cli.js +12 -4
- package/dist/cli/Cli.js.map +1 -1
- package/dist/cli/commands/admin.d.ts +5 -1
- package/dist/cli/commands/admin.d.ts.map +1 -1
- package/dist/cli/commands/admin.js +82 -3
- package/dist/cli/commands/admin.js.map +1 -1
- package/dist/db/Db.d.ts +17 -0
- package/dist/db/Db.d.ts.map +1 -1
- package/dist/db/Db.js +254 -0
- package/dist/db/Db.js.map +1 -1
- package/dist/db/Schema.d.ts +159 -0
- package/dist/db/Schema.d.ts.map +1 -1
- package/dist/db/Schema.js +187 -2
- package/dist/db/Schema.js.map +1 -1
- package/dist/db/tables/billingSettings.d.ts +55 -0
- package/dist/db/tables/billingSettings.d.ts.map +1 -0
- package/dist/db/tables/billingSettings.js +70 -0
- package/dist/db/tables/billingSettings.js.map +1 -0
- package/dist/db/tables/invitations.d.ts +84 -0
- package/dist/db/tables/invitations.d.ts.map +1 -0
- package/dist/db/tables/invitations.js +165 -0
- package/dist/db/tables/invitations.js.map +1 -0
- package/dist/db/tables/memberships.d.ts +108 -0
- package/dist/db/tables/memberships.d.ts.map +1 -0
- package/dist/db/tables/memberships.js +153 -0
- package/dist/db/tables/memberships.js.map +1 -0
- package/dist/db/tables/organizations.d.ts +48 -0
- package/dist/db/tables/organizations.d.ts.map +1 -1
- package/dist/db/tables/organizations.js +97 -2
- package/dist/db/tables/organizations.js.map +1 -1
- package/dist/db/tables/projects.d.ts +65 -0
- package/dist/db/tables/projects.d.ts.map +1 -0
- package/dist/db/tables/projects.js +75 -0
- package/dist/db/tables/projects.js.map +1 -0
- package/dist/db/tables/requestUsage.d.ts +121 -0
- package/dist/db/tables/requestUsage.d.ts.map +1 -0
- package/dist/db/tables/requestUsage.js +150 -0
- package/dist/db/tables/requestUsage.js.map +1 -0
- package/dist/db/tables/sponsoredTransactions.d.ts +239 -0
- package/dist/db/tables/sponsoredTransactions.d.ts.map +1 -0
- package/dist/db/tables/sponsoredTransactions.js +314 -0
- package/dist/db/tables/sponsoredTransactions.js.map +1 -0
- package/dist/db/tables/stripeCustomers.d.ts +81 -0
- package/dist/db/tables/stripeCustomers.d.ts.map +1 -0
- package/dist/db/tables/stripeCustomers.js +120 -0
- package/dist/db/tables/stripeCustomers.js.map +1 -0
- package/dist/db/tables/users.d.ts +48 -0
- package/dist/db/tables/users.d.ts.map +1 -0
- package/dist/db/tables/users.js +65 -0
- package/dist/db/tables/users.js.map +1 -0
- package/dist/handlers/internal/executionError.d.ts.map +1 -1
- package/dist/handlers/internal/executionError.js +2 -0
- package/dist/handlers/internal/executionError.js.map +1 -1
- package/dist/handlers/internal/multisig.d.ts +2 -6
- package/dist/handlers/internal/multisig.d.ts.map +1 -1
- package/dist/handlers/internal/multisig.js +11 -36
- package/dist/handlers/internal/multisig.js.map +1 -1
- package/dist/handlers/internal/sponsorship.d.ts +35 -2
- package/dist/handlers/internal/sponsorship.d.ts.map +1 -1
- package/dist/handlers/internal/sponsorship.js +53 -14
- package/dist/handlers/internal/sponsorship.js.map +1 -1
- package/dist/handlers/internal/utils.d.ts +10 -3
- package/dist/handlers/internal/utils.d.ts.map +1 -1
- package/dist/handlers/internal/utils.js +14 -6
- package/dist/handlers/internal/utils.js.map +1 -1
- package/dist/handlers/relay.d.ts +6 -2
- package/dist/handlers/relay.d.ts.map +1 -1
- package/dist/handlers/relay.js +16 -2
- package/dist/handlers/relay.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/Auth.d.ts +222 -6
- package/dist/internal/Auth.d.ts.map +1 -1
- package/dist/internal/Auth.js +625 -74
- package/dist/internal/Auth.js.map +1 -1
- package/dist/internal/Cache.d.ts.map +1 -1
- package/dist/internal/Cache.js +4 -1
- package/dist/internal/Cache.js.map +1 -1
- package/dist/internal/EdgeCache.d.ts +10 -0
- package/dist/internal/EdgeCache.d.ts.map +1 -1
- package/dist/internal/EdgeCache.js +39 -8
- package/dist/internal/EdgeCache.js.map +1 -1
- package/dist/internal/Fees.d.ts +27 -0
- package/dist/internal/Fees.d.ts.map +1 -0
- package/dist/internal/Fees.js +48 -0
- package/dist/internal/Fees.js.map +1 -0
- package/dist/internal/FundingRoutes.d.ts +183 -0
- package/dist/internal/FundingRoutes.d.ts.map +1 -0
- package/dist/internal/FundingRoutes.js +490 -0
- package/dist/internal/FundingRoutes.js.map +1 -0
- package/dist/internal/Id.d.ts +15 -0
- package/dist/internal/Id.d.ts.map +1 -0
- package/dist/internal/Id.js +22 -0
- package/dist/internal/Id.js.map +1 -0
- package/dist/internal/Log.d.ts +9 -3
- package/dist/internal/Log.d.ts.map +1 -1
- package/dist/internal/Log.js +7 -0
- package/dist/internal/Log.js.map +1 -1
- package/dist/internal/OpenApi.d.ts +10 -20
- package/dist/internal/OpenApi.d.ts.map +1 -1
- package/dist/internal/OpenApi.js +8 -58
- package/dist/internal/OpenApi.js.map +1 -1
- package/dist/internal/RateLimit.d.ts +25 -0
- package/dist/internal/RateLimit.d.ts.map +1 -1
- package/dist/internal/RateLimit.js +51 -0
- package/dist/internal/RateLimit.js.map +1 -1
- package/dist/internal/Response.d.ts +1 -1
- package/dist/internal/Response.d.ts.map +1 -1
- package/dist/internal/Schema.d.ts +8 -0
- package/dist/internal/Schema.d.ts.map +1 -1
- package/dist/internal/Schema.js +7 -0
- package/dist/internal/Schema.js.map +1 -1
- package/dist/internal/Store.d.ts +7 -1
- package/dist/internal/Store.d.ts.map +1 -1
- package/dist/internal/Store.js +16 -2
- package/dist/internal/Store.js.map +1 -1
- package/dist/internal/Viem.d.ts +84 -0
- package/dist/internal/Viem.d.ts.map +1 -1
- package/dist/internal/Webhooks.d.ts +1 -1
- package/dist/internal/Webhooks.d.ts.map +1 -1
- package/dist/internal/Webhooks.js +3 -3
- package/dist/internal/Webhooks.js.map +1 -1
- package/package.json +33 -6
- package/src/ApiKey.ts +10 -2
- package/src/ApiKeys.test.ts +155 -1
- package/src/ApiKeys.ts +203 -1
- package/src/App.test.ts +64 -75741
- package/src/App.ts +218 -420
- package/src/Client.test-d.ts +657 -15
- package/src/Scope.ts +26 -4
- package/src/Webhooks.ts +2 -2
- package/src/admin/apps/api-keys.test.ts +51 -0
- package/src/admin/apps/api-keys.ts +84 -0
- package/src/admin/apps/scopes.test.ts +11 -1
- package/src/admin/apps/scopes.ts +3 -0
- package/src/admin/apps/verified-tokens.ts +1 -1
- package/src/admin/ui/src/components/Page.tsx +2 -3
- package/src/admin/ui/src/routes/__root.tsx +2 -2
- package/src/admin/ui/src/routes/api-keys.tsx +2 -2
- package/src/admin/ui.generated.ts +13 -13
- package/src/analytics/Analytics.test.ts +527 -0
- package/src/analytics/Analytics.ts +318 -0
- package/src/analytics/tables/requestEvents.ts +523 -0
- package/src/apps/composition.test.ts +66 -0
- package/src/apps/data/App.test.ts +72 -0
- package/src/apps/data/App.ts +330 -0
- package/src/apps/data/index.ts +2 -0
- package/src/apps/{activities.test.ts → data/routes/activities.test.ts} +3 -3
- package/src/apps/{activities.ts → data/routes/activities.ts} +15 -15
- package/src/apps/{addresses.ts → data/routes/addresses.ts} +6 -6
- package/src/apps/{balances.test.ts → data/routes/balances.test.ts} +2 -2
- package/src/apps/{balances.ts → data/routes/balances.ts} +46 -12
- package/src/apps/{blocks.test.ts → data/routes/blocks.test.ts} +3 -3
- package/src/apps/{blocks.ts → data/routes/blocks.ts} +14 -14
- package/src/apps/{coingecko.test.ts → data/routes/coingecko.test.ts} +2 -2
- package/src/apps/{coingecko.ts → data/routes/coingecko.ts} +14 -14
- package/src/apps/{exchanges.test.ts → data/routes/exchanges.test.ts} +1 -1
- package/src/apps/{exchanges.ts → data/routes/exchanges.ts} +20 -20
- package/src/apps/{fee-amm.test.ts → data/routes/fee-amm.test.ts} +3 -3
- package/src/apps/{fee-amm.ts → data/routes/fee-amm.ts} +18 -18
- package/src/apps/data/routes/funding.test.ts +214 -0
- package/src/apps/data/routes/funding.ts +584 -0
- package/src/apps/{indexer.test.ts → data/routes/indexer.test.ts} +26 -5
- package/src/apps/{indexer.ts → data/routes/indexer.ts} +13 -10
- package/src/apps/{receipts.test.ts → data/routes/receipts.test.ts} +3 -3
- package/src/apps/{receipts.ts → data/routes/receipts.ts} +15 -22
- package/src/apps/{rpc.test.ts → data/routes/rpc.test.ts} +122 -7
- package/src/apps/{rpc.ts → data/routes/rpc.ts} +38 -8
- package/src/apps/{tokenlist.test.ts → data/routes/tokenlist.test.ts} +3 -3
- package/src/apps/{tokenlist.ts → data/routes/tokenlist.ts} +9 -9
- package/src/apps/{tokens.test.ts → data/routes/tokens.test.ts} +2 -2
- package/src/apps/{tokens.ts → data/routes/tokens.ts} +20 -20
- package/src/apps/{transactions.test.ts → data/routes/transactions.test.ts} +3 -3
- package/src/apps/{transactions.ts → data/routes/transactions.ts} +15 -15
- package/src/apps/{transfers.test.ts → data/routes/transfers.test.ts} +2 -2
- package/src/apps/{transfers.ts → data/routes/transfers.ts} +15 -15
- package/src/apps/{verified-tokens.test.ts → data/routes/verified-tokens.test.ts} +3 -3
- package/src/apps/{verified-tokens.ts → data/routes/verified-tokens.ts} +10 -10
- package/src/apps/{webhooks.test.ts → data/routes/webhooks.test.ts} +7 -7
- package/src/apps/{webhooks.ts → data/routes/webhooks.ts} +50 -43
- package/src/apps/docs/App.ts +65 -0
- package/src/apps/docs/index.ts +1 -0
- package/src/apps/docs/reference.ts +132 -0
- package/src/apps/index.ts +4 -0
- package/src/apps/mcp.test.ts +206 -0
- package/src/apps/mcp.ts +250 -0
- package/src/apps/metadata.ts +23 -0
- package/src/apps/platform/App.ts +169 -0
- package/src/apps/platform/Billing.test.ts +530 -0
- package/src/apps/platform/Billing.ts +682 -0
- package/src/apps/platform/index.ts +2 -0
- package/src/apps/platform/routes/api-keys.test.ts +493 -0
- package/src/apps/platform/routes/api-keys.ts +543 -0
- package/src/apps/platform/routes/billing.test.ts +1100 -0
- package/src/apps/platform/routes/billing.ts +966 -0
- package/src/apps/platform/routes/invitations.test.ts +409 -0
- package/src/apps/platform/routes/invitations.ts +587 -0
- package/src/apps/platform/routes/me.test.ts +351 -0
- package/src/apps/platform/routes/me.ts +106 -0
- package/src/apps/platform/routes/members.test.ts +195 -0
- package/src/apps/platform/routes/members.ts +313 -0
- package/src/apps/platform/routes/orgs.test.ts +313 -0
- package/src/apps/platform/routes/orgs.ts +365 -0
- package/src/apps/platform/routes/projects.test.ts +181 -0
- package/src/apps/platform/routes/projects.ts +367 -0
- package/src/apps/platform/routes/scopes.test.ts +29 -0
- package/src/apps/platform/routes/scopes.ts +85 -0
- package/src/apps/platform/routes/usage.test.ts +422 -0
- package/src/apps/platform/routes/usage.ts +527 -0
- package/src/apps/relay/App.test.ts +933 -0
- package/src/apps/relay/App.ts +236 -0
- package/src/apps/relay/Sponsorships.test.ts +375 -0
- package/src/apps/relay/Sponsorships.ts +306 -0
- package/src/apps/relay/index.ts +2 -0
- package/src/cli/Cli.test.ts +25 -2
- package/src/cli/Cli.ts +18 -3
- package/src/cli/commands/admin.test.ts +83 -0
- package/src/cli/commands/admin.ts +91 -3
- package/src/db/Db.ts +296 -0
- package/src/db/Schema.ts +241 -2
- package/src/db/tables/billingSettings.test.ts +87 -0
- package/src/db/tables/billingSettings.ts +108 -0
- package/src/db/tables/invitations.ts +198 -0
- package/src/db/tables/memberships.ts +208 -0
- package/src/db/tables/organizations.test.ts +38 -2
- package/src/db/tables/organizations.ts +117 -2
- package/src/db/tables/projects.ts +107 -0
- package/src/db/tables/requestUsage.ts +231 -0
- package/src/db/tables/sponsoredTransactions.test.ts +325 -0
- package/src/db/tables/sponsoredTransactions.ts +464 -0
- package/src/db/tables/stripeCustomers.test.ts +109 -0
- package/src/db/tables/stripeCustomers.ts +162 -0
- package/src/db/tables/users.ts +85 -0
- package/src/handlers/internal/executionError.ts +2 -0
- package/src/handlers/internal/multisig.test.ts +84 -10
- package/src/handlers/internal/multisig.ts +15 -50
- package/src/handlers/internal/sponsorship.ts +106 -20
- package/src/handlers/internal/utils.ts +19 -7
- package/src/handlers/{internal/relay.localnet.test.ts → relay.test.ts} +2 -2
- package/src/handlers/relay.ts +23 -5
- package/src/index.ts +1 -0
- package/src/internal/Auth.test.ts +491 -25
- package/src/internal/Auth.ts +839 -84
- package/src/internal/Cache.ts +5 -1
- package/src/internal/Cursor.test.ts +3 -2
- package/src/internal/EdgeCache.test.ts +27 -4
- package/src/internal/EdgeCache.ts +47 -9
- package/src/internal/Fees.test.ts +32 -0
- package/src/internal/Fees.ts +51 -0
- package/src/internal/FundingRoutes.ts +583 -0
- package/src/internal/Id.test.ts +17 -0
- package/src/internal/Id.ts +24 -0
- package/src/internal/Log.test.ts +2 -1
- package/src/internal/Log.ts +16 -3
- package/src/internal/MetricSink.ts +1 -1
- package/src/internal/OpenApi.ts +12 -60
- package/src/internal/RateLimit.test.ts +84 -0
- package/src/internal/RateLimit.ts +70 -0
- package/src/internal/Response.ts +1 -1
- package/src/internal/Schema.ts +8 -0
- package/src/internal/Store.test.ts +52 -0
- package/src/internal/Store.ts +24 -5
- package/src/internal/Tidx.local.test.ts +1 -1
- package/src/internal/VerifiedTokens.test.ts +1 -1
- package/src/internal/WebhookDestination.test.ts +1 -1
- package/src/internal/Webhooks.test.ts +7 -7
- package/src/internal/Webhooks.ts +4 -4
- package/dist/apps/activities.js.map +0 -1
- package/dist/apps/addresses.js.map +0 -1
- package/dist/apps/balances.d.ts.map +0 -1
- package/dist/apps/balances.js.map +0 -1
- package/dist/apps/blocks.d.ts.map +0 -1
- package/dist/apps/blocks.js.map +0 -1
- package/dist/apps/coingecko.d.ts.map +0 -1
- package/dist/apps/coingecko.js.map +0 -1
- package/dist/apps/exchanges.d.ts.map +0 -1
- package/dist/apps/exchanges.js.map +0 -1
- package/dist/apps/fee-amm.d.ts.map +0 -1
- package/dist/apps/fee-amm.js.map +0 -1
- package/dist/apps/indexer.d.ts.map +0 -1
- package/dist/apps/indexer.js.map +0 -1
- package/dist/apps/receipts.d.ts.map +0 -1
- package/dist/apps/receipts.js.map +0 -1
- package/dist/apps/rpc.d.ts.map +0 -1
- package/dist/apps/rpc.js.map +0 -1
- package/dist/apps/tokenlist.d.ts.map +0 -1
- package/dist/apps/tokenlist.js.map +0 -1
- package/dist/apps/tokens.d.ts.map +0 -1
- package/dist/apps/tokens.js.map +0 -1
- package/dist/apps/transactions.d.ts.map +0 -1
- package/dist/apps/transactions.js.map +0 -1
- package/dist/apps/transfers.d.ts.map +0 -1
- package/dist/apps/transfers.js.map +0 -1
- package/dist/apps/verified-tokens.d.ts.map +0 -1
- package/dist/apps/verified-tokens.js.map +0 -1
- package/dist/apps/webhooks.js.map +0 -1
- package/dist/internal/OpenApi.fonts.d.ts.map +0 -1
- package/dist/internal/OpenApi.fonts.js.map +0 -1
- package/dist/internal/OpenApi.logo.d.ts.map +0 -1
- package/dist/internal/OpenApi.logo.js.map +0 -1
- package/src/handlers/internal/multisig.localnet.test.ts +0 -146
- /package/src/{internal/OpenApi.fonts.ts → apps/docs/fonts.ts} +0 -0
- /package/src/{internal/OpenApi.logo.ts → apps/docs/logo.ts} +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Selectable } from 'kysely'
|
|
2
|
-
import { nanoid } from 'nanoid'
|
|
3
2
|
|
|
3
|
+
import * as Id from '../../internal/Id.js'
|
|
4
4
|
import type * as Db from '../Db.js'
|
|
5
5
|
import type * as db_Schema from '../Schema.js'
|
|
6
|
+
import type * as Memberships from './memberships.js'
|
|
6
7
|
|
|
7
8
|
/** Columns of the `organizations` table, derived from `Schema.Organization`. */
|
|
8
9
|
export type Table = db_Schema.Organization
|
|
@@ -25,9 +26,10 @@ export function create(db: Db.Db, input: create.Input): Promise<Record> {
|
|
|
25
26
|
.values({
|
|
26
27
|
createdAt: now,
|
|
27
28
|
createdBy: input.createdBy ?? null,
|
|
28
|
-
id: input.id ??
|
|
29
|
+
id: input.id ?? Id.generate('org'),
|
|
29
30
|
name: input.name,
|
|
30
31
|
updatedAt: now,
|
|
32
|
+
userId: input.userId ?? null,
|
|
31
33
|
})
|
|
32
34
|
.returningAll()
|
|
33
35
|
.executeTakeFirstOrThrow()
|
|
@@ -42,9 +44,84 @@ export declare namespace create {
|
|
|
42
44
|
id?: string | undefined
|
|
43
45
|
/** Human-readable organization name. */
|
|
44
46
|
name: string
|
|
47
|
+
/** Owning user id (`usr_…`); null for organizations created by the super admin. */
|
|
48
|
+
userId?: string | undefined
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Inserts an organization owned by `userId` — the org row plus its `owner`
|
|
54
|
+
* membership, atomically.
|
|
55
|
+
*
|
|
56
|
+
* @param db - The database.
|
|
57
|
+
* @param input - The organization to insert.
|
|
58
|
+
* @returns The stored record.
|
|
59
|
+
*/
|
|
60
|
+
export function createOwned(db: Db.Db, input: createOwned.Input): Promise<Record> {
|
|
61
|
+
const now = new Date().toISOString()
|
|
62
|
+
return db.kysely.transaction().execute(async (trx) => {
|
|
63
|
+
const record = await trx
|
|
64
|
+
.insertInto('organizations')
|
|
65
|
+
.values({
|
|
66
|
+
createdAt: now,
|
|
67
|
+
createdBy: input.userId,
|
|
68
|
+
id: Id.generate('org'),
|
|
69
|
+
name: input.name,
|
|
70
|
+
updatedAt: now,
|
|
71
|
+
userId: input.userId,
|
|
72
|
+
})
|
|
73
|
+
.returningAll()
|
|
74
|
+
.executeTakeFirstOrThrow()
|
|
75
|
+
await trx
|
|
76
|
+
.insertInto('memberships')
|
|
77
|
+
.values({
|
|
78
|
+
createdAt: now,
|
|
79
|
+
orgId: record.id,
|
|
80
|
+
role: 'owner',
|
|
81
|
+
updatedAt: now,
|
|
82
|
+
userId: input.userId,
|
|
83
|
+
})
|
|
84
|
+
.execute()
|
|
85
|
+
return record
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export declare namespace createOwned {
|
|
90
|
+
/** Fields accepted when inserting a user-owned organization. */
|
|
91
|
+
type Input = {
|
|
92
|
+
/** Human-readable organization name. */
|
|
93
|
+
name: string
|
|
94
|
+
/** Owning user id (`usr_…`), granted the `owner` membership. */
|
|
95
|
+
userId: string
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Deletes an organization and its owned rows atomically.
|
|
101
|
+
*
|
|
102
|
+
* @param db - The database.
|
|
103
|
+
* @param id - The organization id (`org_…`).
|
|
104
|
+
* @returns Whether the organization existed and was deleted.
|
|
105
|
+
*/
|
|
106
|
+
export function deleteOrganization(db: Db.Db, id: string): Promise<boolean> {
|
|
107
|
+
return db.kysely.transaction().execute(async (trx) => {
|
|
108
|
+
await trx
|
|
109
|
+
.deleteFrom('webhook_subscriptions')
|
|
110
|
+
.where('ownerType', '=', 'api_key')
|
|
111
|
+
.where('ownerId', '=', id)
|
|
112
|
+
.execute()
|
|
113
|
+
await trx.deleteFrom('billing_settings').where('orgId', '=', id).execute()
|
|
114
|
+
await trx.deleteFrom('invitations').where('orgId', '=', id).execute()
|
|
115
|
+
await trx.deleteFrom('memberships').where('orgId', '=', id).execute()
|
|
116
|
+
await trx.deleteFrom('projects').where('orgId', '=', id).execute()
|
|
117
|
+
await trx.deleteFrom('request_usage_buckets').where('orgId', '=', id).execute()
|
|
118
|
+
await trx.deleteFrom('request_usage_meter_events').where('orgId', '=', id).execute()
|
|
119
|
+
await trx.deleteFrom('stripe_customers').where('orgId', '=', id).execute()
|
|
120
|
+
const result = await trx.deleteFrom('organizations').where('id', '=', id).executeTakeFirst()
|
|
121
|
+
return result.numDeletedRows > 0n
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
48
125
|
/**
|
|
49
126
|
* Reads an organization by id.
|
|
50
127
|
*
|
|
@@ -66,6 +143,44 @@ export function list(db: Db.Db): Promise<Record[]> {
|
|
|
66
143
|
return db.kysely.selectFrom('organizations').selectAll().orderBy('createdAt', 'desc').execute()
|
|
67
144
|
}
|
|
68
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Lists organizations owned by `userId`, newest first.
|
|
148
|
+
*
|
|
149
|
+
* @param db - The database.
|
|
150
|
+
* @param userId - The owning user id (`usr_…`).
|
|
151
|
+
* @returns The records.
|
|
152
|
+
*/
|
|
153
|
+
export function listByUser(db: Db.Db, userId: string): Promise<Record[]> {
|
|
154
|
+
return db.kysely
|
|
155
|
+
.selectFrom('organizations')
|
|
156
|
+
.selectAll()
|
|
157
|
+
.where('userId', '=', userId)
|
|
158
|
+
.orderBy('createdAt', 'desc')
|
|
159
|
+
.execute()
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Lists organizations `userId` is a member of (any role), newest first. Each
|
|
164
|
+
* row carries the caller's membership `role`.
|
|
165
|
+
*
|
|
166
|
+
* @param db - The database.
|
|
167
|
+
* @param userId - The member user id (`usr_…`).
|
|
168
|
+
* @returns The records.
|
|
169
|
+
*/
|
|
170
|
+
export function listByMember(
|
|
171
|
+
db: Db.Db,
|
|
172
|
+
userId: string,
|
|
173
|
+
): Promise<(Record & { role: Memberships.Role })[]> {
|
|
174
|
+
return db.kysely
|
|
175
|
+
.selectFrom('organizations')
|
|
176
|
+
.innerJoin('memberships', 'memberships.orgId', 'organizations.id')
|
|
177
|
+
.where('memberships.userId', '=', userId)
|
|
178
|
+
.selectAll('organizations')
|
|
179
|
+
.select('memberships.role')
|
|
180
|
+
.orderBy('organizations.createdAt', 'desc')
|
|
181
|
+
.execute()
|
|
182
|
+
}
|
|
183
|
+
|
|
69
184
|
/**
|
|
70
185
|
* Renames an organization, bumping `updatedAt`.
|
|
71
186
|
*
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { Selectable } from 'kysely'
|
|
2
|
+
|
|
3
|
+
import * as Id from '../../internal/Id.js'
|
|
4
|
+
import type * as Db from '../Db.js'
|
|
5
|
+
import type * as db_Schema from '../Schema.js'
|
|
6
|
+
|
|
7
|
+
/** Columns of the `projects` table, derived from `Schema.Project`. */
|
|
8
|
+
export type Table = db_Schema.Project
|
|
9
|
+
|
|
10
|
+
/** A stored project row. */
|
|
11
|
+
export type Record = Selectable<Table>
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Inserts a project and returns the stored record.
|
|
15
|
+
*
|
|
16
|
+
* @param db - The database.
|
|
17
|
+
* @param input - The project to insert.
|
|
18
|
+
* @returns The stored record.
|
|
19
|
+
*/
|
|
20
|
+
export function create(db: Db.Db, input: create.Input): Promise<Record> {
|
|
21
|
+
const now = new Date().toISOString()
|
|
22
|
+
return db.kysely
|
|
23
|
+
.insertInto('projects')
|
|
24
|
+
.values({
|
|
25
|
+
createdAt: now,
|
|
26
|
+
id: Id.generate('prj'),
|
|
27
|
+
name: input.name,
|
|
28
|
+
orgId: input.orgId,
|
|
29
|
+
updatedAt: now,
|
|
30
|
+
})
|
|
31
|
+
.returningAll()
|
|
32
|
+
.executeTakeFirstOrThrow()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export declare namespace create {
|
|
36
|
+
/** Fields accepted when inserting a project. */
|
|
37
|
+
type Input = {
|
|
38
|
+
/** Human-readable project name. */
|
|
39
|
+
name: string
|
|
40
|
+
/** Owning organization id (`org_…`). */
|
|
41
|
+
orgId: string
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Deletes a project.
|
|
47
|
+
*
|
|
48
|
+
* @param db - The database.
|
|
49
|
+
* @param id - The project id (`prj_…`).
|
|
50
|
+
* @returns Whether the project existed and was deleted.
|
|
51
|
+
*/
|
|
52
|
+
export async function deleteProject(db: Db.Db, id: string): Promise<boolean> {
|
|
53
|
+
const result = await db.kysely.deleteFrom('projects').where('id', '=', id).executeTakeFirst()
|
|
54
|
+
return result.numDeletedRows > 0n
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Reads a project by id.
|
|
59
|
+
*
|
|
60
|
+
* @param db - The database.
|
|
61
|
+
* @param id - The project id (`prj_…`).
|
|
62
|
+
* @returns The record, or `undefined` when absent.
|
|
63
|
+
*/
|
|
64
|
+
export function get(db: Db.Db, id: string): Promise<Record | undefined> {
|
|
65
|
+
return db.kysely.selectFrom('projects').selectAll().where('id', '=', id).executeTakeFirst()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Lists an organization's projects, newest first.
|
|
70
|
+
*
|
|
71
|
+
* @param db - The database.
|
|
72
|
+
* @param orgId - The owning organization id (`org_…`).
|
|
73
|
+
* @returns The records.
|
|
74
|
+
*/
|
|
75
|
+
export function listByOrg(db: Db.Db, orgId: string): Promise<Record[]> {
|
|
76
|
+
return db.kysely
|
|
77
|
+
.selectFrom('projects')
|
|
78
|
+
.selectAll()
|
|
79
|
+
.where('orgId', '=', orgId)
|
|
80
|
+
.orderBy('createdAt', 'desc')
|
|
81
|
+
.execute()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Renames a project, bumping `updatedAt`.
|
|
86
|
+
*
|
|
87
|
+
* @param db - The database.
|
|
88
|
+
* @param id - The project id (`prj_…`).
|
|
89
|
+
* @param input - The fields to update.
|
|
90
|
+
* @returns The updated record, or `undefined` when absent.
|
|
91
|
+
*/
|
|
92
|
+
export function update(db: Db.Db, id: string, input: update.Input): Promise<Record | undefined> {
|
|
93
|
+
return db.kysely
|
|
94
|
+
.updateTable('projects')
|
|
95
|
+
.set({ name: input.name, updatedAt: new Date().toISOString() })
|
|
96
|
+
.where('id', '=', id)
|
|
97
|
+
.returningAll()
|
|
98
|
+
.executeTakeFirst()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export declare namespace update {
|
|
102
|
+
/** Mutable project fields. */
|
|
103
|
+
type Input = {
|
|
104
|
+
/** New human-readable project name. */
|
|
105
|
+
name: string
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { type ColumnType, type Selectable, sql } from 'kysely'
|
|
2
|
+
|
|
3
|
+
import type * as Db from '../Db.js'
|
|
4
|
+
import type * as db_Schema from '../Schema.js'
|
|
5
|
+
|
|
6
|
+
/** A `bigint` count column: read as a string from pg, written as a number. */
|
|
7
|
+
type Count = ColumnType<string, number, number>
|
|
8
|
+
|
|
9
|
+
/** Environment a request-usage row attributes to. */
|
|
10
|
+
export type Environment = db_Schema.RequestUsageBucket['environment']
|
|
11
|
+
|
|
12
|
+
/** Exactly-once state of a meter event. */
|
|
13
|
+
export type State = db_Schema.RequestUsageMeterEvent['state']
|
|
14
|
+
|
|
15
|
+
/** Columns of the `request_usage_buckets` table (pg representation). */
|
|
16
|
+
export type BucketTable = {
|
|
17
|
+
bucketStart: string
|
|
18
|
+
environment: Environment
|
|
19
|
+
orgId: string
|
|
20
|
+
reportedCount: Count
|
|
21
|
+
updatedAt: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Columns of the `request_usage_meter_events` table (pg representation). */
|
|
25
|
+
export type MeterEventTable = {
|
|
26
|
+
bucketStart: string
|
|
27
|
+
deltaCount: Count
|
|
28
|
+
environment: Environment
|
|
29
|
+
error: string | null
|
|
30
|
+
firstAttemptedAt: string
|
|
31
|
+
identifier: string
|
|
32
|
+
orgId: string
|
|
33
|
+
reason: string | null
|
|
34
|
+
reportedAt: string | null
|
|
35
|
+
sequence: number
|
|
36
|
+
state: State
|
|
37
|
+
stripeCustomerId: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A stored per-hour request-count watermark. */
|
|
41
|
+
export type Bucket = db_Schema.RequestUsageBucket
|
|
42
|
+
|
|
43
|
+
/** A stored request-count meter event. */
|
|
44
|
+
export type MeterEvent = db_Schema.RequestUsageMeterEvent
|
|
45
|
+
|
|
46
|
+
/** Identifies one hourly bucket for an org in an environment. */
|
|
47
|
+
export type BucketKey = {
|
|
48
|
+
/** UTC hour start (ISO 8601). */
|
|
49
|
+
bucketStart: string
|
|
50
|
+
/** Environment the requests were served under. */
|
|
51
|
+
environment: Environment
|
|
52
|
+
/** Organization id (`org_…`). */
|
|
53
|
+
orgId: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Reads a bucket watermark.
|
|
58
|
+
*
|
|
59
|
+
* @param db - The database.
|
|
60
|
+
* @param key - The bucket key.
|
|
61
|
+
* @returns The watermark, or `undefined` when none has been reported yet.
|
|
62
|
+
*/
|
|
63
|
+
export async function getBucket(db: Db.Db, key: BucketKey): Promise<Bucket | undefined> {
|
|
64
|
+
const row = await db.kysely
|
|
65
|
+
.selectFrom('request_usage_buckets')
|
|
66
|
+
.selectAll()
|
|
67
|
+
.where('orgId', '=', key.orgId)
|
|
68
|
+
.where('environment', '=', key.environment)
|
|
69
|
+
.where('bucketStart', '=', key.bucketStart)
|
|
70
|
+
.executeTakeFirst()
|
|
71
|
+
return row ? toBucket(row) : undefined
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Lists the meter events still awaiting a Stripe acknowledgement in an
|
|
76
|
+
* environment, oldest first — the reporter's crash-recovery drive.
|
|
77
|
+
*
|
|
78
|
+
* @param db - The database.
|
|
79
|
+
* @param environment - The environment to scan.
|
|
80
|
+
* @returns The pending meter events.
|
|
81
|
+
*/
|
|
82
|
+
export async function listPending(db: Db.Db, environment: Environment): Promise<MeterEvent[]> {
|
|
83
|
+
const rows = await db.kysely
|
|
84
|
+
.selectFrom('request_usage_meter_events')
|
|
85
|
+
.selectAll()
|
|
86
|
+
.where('environment', '=', environment)
|
|
87
|
+
.where('state', '=', 'pending')
|
|
88
|
+
.orderBy('firstAttemptedAt', 'asc')
|
|
89
|
+
.orderBy('identifier', 'asc')
|
|
90
|
+
.execute()
|
|
91
|
+
return rows.map(toMeterEvent)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Counts the meter events already reported for a bucket — the next delta's
|
|
96
|
+
* `sequence`, so a new seal never collides with a settled one.
|
|
97
|
+
*
|
|
98
|
+
* @param db - The database.
|
|
99
|
+
* @param key - The bucket key.
|
|
100
|
+
* @returns The count of reported events for the bucket.
|
|
101
|
+
*/
|
|
102
|
+
export async function countReported(db: Db.Db, key: BucketKey): Promise<number> {
|
|
103
|
+
const row = await db.kysely
|
|
104
|
+
.selectFrom('request_usage_meter_events')
|
|
105
|
+
.select((eb) => eb.fn.countAll<string>().as('count'))
|
|
106
|
+
.where('orgId', '=', key.orgId)
|
|
107
|
+
.where('environment', '=', key.environment)
|
|
108
|
+
.where('bucketStart', '=', key.bucketStart)
|
|
109
|
+
.where('state', '=', 'reported')
|
|
110
|
+
.executeTakeFirstOrThrow()
|
|
111
|
+
return Number(row.count)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Inserts a frozen `pending` meter event, claiming a delta. Idempotent on the
|
|
116
|
+
* deterministic `identifier`: a re-seal after a crash resolves to the existing
|
|
117
|
+
* row rather than duplicating the delta.
|
|
118
|
+
*
|
|
119
|
+
* @param db - The database.
|
|
120
|
+
* @param input - The event to insert.
|
|
121
|
+
* @returns Whether this call inserted the row.
|
|
122
|
+
*/
|
|
123
|
+
export async function insertPending(db: Db.Db, input: insertPending.Input): Promise<boolean> {
|
|
124
|
+
const now = new Date().toISOString()
|
|
125
|
+
const inserted = await db.kysely
|
|
126
|
+
.insertInto('request_usage_meter_events')
|
|
127
|
+
.values({
|
|
128
|
+
bucketStart: input.bucketStart,
|
|
129
|
+
deltaCount: input.deltaCount,
|
|
130
|
+
environment: input.environment,
|
|
131
|
+
error: null,
|
|
132
|
+
firstAttemptedAt: now,
|
|
133
|
+
identifier: input.identifier,
|
|
134
|
+
orgId: input.orgId,
|
|
135
|
+
reason: null,
|
|
136
|
+
reportedAt: null,
|
|
137
|
+
sequence: input.sequence,
|
|
138
|
+
state: 'pending',
|
|
139
|
+
stripeCustomerId: input.stripeCustomerId,
|
|
140
|
+
})
|
|
141
|
+
.onConflict((oc) => oc.doNothing())
|
|
142
|
+
.returning('identifier')
|
|
143
|
+
.executeTakeFirst()
|
|
144
|
+
return Boolean(inserted)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export declare namespace insertPending {
|
|
148
|
+
/** Fields accepted when sealing a pending meter event. */
|
|
149
|
+
type Input = {
|
|
150
|
+
/** UTC hour start the delta bills for (ISO 8601). */
|
|
151
|
+
bucketStart: string
|
|
152
|
+
/** Frozen request count this event bills (positive). */
|
|
153
|
+
deltaCount: number
|
|
154
|
+
/** Environment the requests were served under. */
|
|
155
|
+
environment: Environment
|
|
156
|
+
/** Deterministic id; also the Stripe identifier and idempotency key. */
|
|
157
|
+
identifier: string
|
|
158
|
+
/** Organization id (`org_…`). */
|
|
159
|
+
orgId: string
|
|
160
|
+
/** Delta sequence within the bucket. */
|
|
161
|
+
sequence: number
|
|
162
|
+
/** Stripe customer id the event bills against. */
|
|
163
|
+
stripeCustomerId: string
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Marks a pending event reported and advances its bucket watermark by the
|
|
169
|
+
* event's frozen delta, atomically. A no-op once reported, so a retry after a
|
|
170
|
+
* crash between the Stripe ack and this write never double-advances.
|
|
171
|
+
*
|
|
172
|
+
* @param db - The database.
|
|
173
|
+
* @param identifier - The event identifier.
|
|
174
|
+
* @param at - When Stripe acknowledged the event (ISO 8601).
|
|
175
|
+
* @returns Whether this call settled the event (false when already reported).
|
|
176
|
+
*/
|
|
177
|
+
export function settle(db: Db.Db, identifier: string, at: string): Promise<boolean> {
|
|
178
|
+
return db.transaction(async (tx) => {
|
|
179
|
+
const updated = await tx.kysely
|
|
180
|
+
.updateTable('request_usage_meter_events')
|
|
181
|
+
.set({ error: null, reportedAt: at, state: 'reported' })
|
|
182
|
+
.where('identifier', '=', identifier)
|
|
183
|
+
.where('state', '=', 'pending')
|
|
184
|
+
.returningAll()
|
|
185
|
+
.executeTakeFirst()
|
|
186
|
+
if (!updated) return false
|
|
187
|
+
await tx.kysely
|
|
188
|
+
.insertInto('request_usage_buckets')
|
|
189
|
+
.values({
|
|
190
|
+
bucketStart: updated.bucketStart,
|
|
191
|
+
environment: updated.environment,
|
|
192
|
+
orgId: updated.orgId,
|
|
193
|
+
reportedCount: Number(updated.deltaCount),
|
|
194
|
+
updatedAt: at,
|
|
195
|
+
})
|
|
196
|
+
.onConflict((oc) =>
|
|
197
|
+
oc.columns(['orgId', 'environment', 'bucketStart']).doUpdateSet({
|
|
198
|
+
reportedCount: sql`request_usage_buckets.reported_count + ${updated.deltaCount}`,
|
|
199
|
+
updatedAt: at,
|
|
200
|
+
}),
|
|
201
|
+
)
|
|
202
|
+
.execute()
|
|
203
|
+
return true
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Records a transient failure on a pending event; it stays pending for retry.
|
|
209
|
+
*
|
|
210
|
+
* @param db - The database.
|
|
211
|
+
* @param identifier - The event identifier.
|
|
212
|
+
* @param error - The failure detail.
|
|
213
|
+
*/
|
|
214
|
+
export async function markError(db: Db.Db, identifier: string, error: string): Promise<void> {
|
|
215
|
+
await db.kysely
|
|
216
|
+
.updateTable('request_usage_meter_events')
|
|
217
|
+
.set({ error: error.slice(0, 500) })
|
|
218
|
+
.where('identifier', '=', identifier)
|
|
219
|
+
.where('state', '=', 'pending')
|
|
220
|
+
.execute()
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Maps a bucket row to its domain record. */
|
|
224
|
+
function toBucket(row: Selectable<BucketTable>): Bucket {
|
|
225
|
+
return { ...row, reportedCount: Number(row.reportedCount) }
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Maps a meter-event row to its domain record. */
|
|
229
|
+
function toMeterEvent(row: Selectable<MeterEventTable>): MeterEvent {
|
|
230
|
+
return { ...row, deltaCount: Number(row.deltaCount) }
|
|
231
|
+
}
|