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
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import type { Selectable } from 'kysely';
|
|
2
|
+
import type * as Db from '../Db.js';
|
|
3
|
+
import type * as db_Schema from '../Schema.js';
|
|
4
|
+
/** Columns of the `sponsored_transactions` table, derived from `Schema.SponsoredTransaction`. */
|
|
5
|
+
export type Table = db_Schema.SponsoredTransaction;
|
|
6
|
+
/** A stored sponsored-transaction row. */
|
|
7
|
+
export type Record = Selectable<Table>;
|
|
8
|
+
/**
|
|
9
|
+
* Records one sponsorship commitment as `pending`, keyed by its fee-payer
|
|
10
|
+
* sign payload. Written after fee-payer signing and before any broadcast, so
|
|
11
|
+
* no sponsored transaction goes unrecorded; a later recording site for the
|
|
12
|
+
* same envelope (raw submission after a fill intent) upgrades the row with
|
|
13
|
+
* its transaction hash, reopening failed rows for finalization.
|
|
14
|
+
*
|
|
15
|
+
* @param db - The database.
|
|
16
|
+
* @param input - Attribution and envelope facts captured at signing time.
|
|
17
|
+
* @returns The stored record.
|
|
18
|
+
*/
|
|
19
|
+
export declare function upsert(db: Db.Db, input: upsert.Input): Promise<Record>;
|
|
20
|
+
export declare namespace upsert {
|
|
21
|
+
/** Attribution and envelope facts recorded at sponsorship time. */
|
|
22
|
+
type Input = {
|
|
23
|
+
/** API key id (`key_…`) that requested sponsorship. */
|
|
24
|
+
apiKeyId: string;
|
|
25
|
+
/** Whether the sponsorship accrues billable spend; false for sandbox. */
|
|
26
|
+
billable: boolean;
|
|
27
|
+
/** Chain the sponsored transaction targets. */
|
|
28
|
+
chainId: number;
|
|
29
|
+
/** Lowercase fee currency snapshot (`usd`), when resolved. */
|
|
30
|
+
currency?: string | undefined;
|
|
31
|
+
/** Key environment the sponsorship was requested under. */
|
|
32
|
+
environment: Table['environment'];
|
|
33
|
+
/** Signed fee cap (`gas × maxFeePerGas`) in base units, when known. */
|
|
34
|
+
feeMax?: string | undefined;
|
|
35
|
+
/** Fee token the sponsorship resolved, when known. */
|
|
36
|
+
feeToken?: string | undefined;
|
|
37
|
+
/** Organization id (`org_…`) the spend attributes to. */
|
|
38
|
+
orgId: string;
|
|
39
|
+
/** Project id (`prj_…`) the spend attributes to. */
|
|
40
|
+
projectId: string;
|
|
41
|
+
/** Fee-payer sign payload — a stable identity for the sponsored envelope. */
|
|
42
|
+
signPayload: string;
|
|
43
|
+
/** Serialized sponsored transaction, kept for observability beyond log retention. */
|
|
44
|
+
transaction: string;
|
|
45
|
+
/** Transaction hash; omit for fill intents, whose senders have not signed yet. */
|
|
46
|
+
transactionHash?: string | undefined;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Reads one sponsorship row by id.
|
|
51
|
+
*
|
|
52
|
+
* @param db - The database.
|
|
53
|
+
* @param id - The sponsored-transaction id (`stx_…`).
|
|
54
|
+
* @returns The record, or `undefined` when absent.
|
|
55
|
+
*/
|
|
56
|
+
export declare function get(db: Db.Db, id: string): Promise<Record | undefined>;
|
|
57
|
+
/**
|
|
58
|
+
* Lists pending sponsorships, oldest first, for the finalization job.
|
|
59
|
+
*
|
|
60
|
+
* @param db - The database.
|
|
61
|
+
* @param options - Paging options.
|
|
62
|
+
* @returns The pending records.
|
|
63
|
+
*/
|
|
64
|
+
export declare function listPending(db: Db.Db, options?: listPending.Options): Promise<Record[]>;
|
|
65
|
+
export declare namespace listPending {
|
|
66
|
+
/** Options for {@link listPending}. */
|
|
67
|
+
type Options = {
|
|
68
|
+
/** Maximum rows to return. */
|
|
69
|
+
limit?: number | undefined;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Lists hash-less fill intents, oldest first, for the reconciliation pass.
|
|
74
|
+
* Failed intents are included only when the caller supplies a recovery floor.
|
|
75
|
+
*
|
|
76
|
+
* @param db - The database.
|
|
77
|
+
* @param options - Paging options.
|
|
78
|
+
* @returns The pending intents.
|
|
79
|
+
*/
|
|
80
|
+
export declare function listIntents(db: Db.Db, options?: listIntents.Options): Promise<Record[]>;
|
|
81
|
+
export declare namespace listIntents {
|
|
82
|
+
/** Options for {@link listIntents}. */
|
|
83
|
+
type Options = listPending.Options & {
|
|
84
|
+
/** Include failed intents whose terminal timestamp is at or after this ISO timestamp. */
|
|
85
|
+
failedSince?: string | undefined;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Fills a reconciled intent's transaction hash and reopens failed intents.
|
|
90
|
+
* A no-op once another pass already assigned the hash.
|
|
91
|
+
*
|
|
92
|
+
* @param db - The database.
|
|
93
|
+
* @param id - The sponsored-transaction id (`stx_…`).
|
|
94
|
+
* @param transactionHash - The matched on-chain transaction hash.
|
|
95
|
+
*/
|
|
96
|
+
export declare function assignTransactionHash(db: Db.Db, id: string, transactionHash: string): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Transitions a pending sponsorship to `finalized` with the receipt's actual
|
|
99
|
+
* fee. A no-op when the row is no longer pending (idempotent re-runs).
|
|
100
|
+
*
|
|
101
|
+
* @param db - The database.
|
|
102
|
+
* @param id - The sponsored-transaction id (`stx_…`).
|
|
103
|
+
* @param input - The finalized fee facts.
|
|
104
|
+
*/
|
|
105
|
+
export declare function finalize(db: Db.Db, id: string, input: finalize.Input): Promise<void>;
|
|
106
|
+
export declare namespace finalize {
|
|
107
|
+
/** Fee facts resolved from the transaction receipt. */
|
|
108
|
+
type Input = {
|
|
109
|
+
/** Actual fee paid in fee-token base units. */
|
|
110
|
+
feeAmount: string;
|
|
111
|
+
/** When the sponsorship finalized (ISO 8601). */
|
|
112
|
+
finalizedAt: string;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Transitions a pending sponsorship to `failed` (never landed within the
|
|
117
|
+
* pending TTL). A no-op when the row is no longer pending.
|
|
118
|
+
*
|
|
119
|
+
* @param db - The database.
|
|
120
|
+
* @param id - The sponsored-transaction id (`stx_…`).
|
|
121
|
+
* @param finalizedAt - When the sponsorship was marked failed (ISO 8601).
|
|
122
|
+
*/
|
|
123
|
+
export declare function fail(db: Db.Db, id: string, finalizedAt: string): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Records a sponsorship and enforces the period spend limit atomically. A
|
|
126
|
+
* per-org advisory lock serializes concurrent sponsorships so each one's
|
|
127
|
+
* signed cap is counted before the limit check; without it a burst reads
|
|
128
|
+
* pre-burst spend and overshoots. Throws {@link PeriodSpendLimitError} (rolling
|
|
129
|
+
* back the row) when the limit would be exceeded.
|
|
130
|
+
*
|
|
131
|
+
* @param db - The database (primary; never a cached replica).
|
|
132
|
+
* @param input - The sponsorship to record.
|
|
133
|
+
* @param limit - The period spend limit to enforce.
|
|
134
|
+
* @returns The stored record.
|
|
135
|
+
*/
|
|
136
|
+
export declare function reserve(db: Db.Db, input: upsert.Input, limit: reserve.Limit): Promise<Record>;
|
|
137
|
+
export declare namespace reserve {
|
|
138
|
+
/** The period spend limit enforced by {@link reserve}. */
|
|
139
|
+
type Limit = {
|
|
140
|
+
/** Chains whose spend counts (mainnet chain ids). */
|
|
141
|
+
chainIds: readonly number[];
|
|
142
|
+
/** Limit in fee-token base units. */
|
|
143
|
+
max: bigint;
|
|
144
|
+
/** Window start (ISO 8601). */
|
|
145
|
+
since: string;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Billable spend committed since a cutoff, in fee-token base units: finalized
|
|
150
|
+
* rows at their actual fee plus pending rows at their signed fee cap, so
|
|
151
|
+
* in-flight sponsorships consume limit budget until receipts land.
|
|
152
|
+
*
|
|
153
|
+
* @param db - The database.
|
|
154
|
+
* @param options - Aggregation scope.
|
|
155
|
+
* @returns The committed spend in base units.
|
|
156
|
+
*/
|
|
157
|
+
export declare function spend(db: Db.Db, options: spend.Options): Promise<bigint>;
|
|
158
|
+
export declare namespace spend {
|
|
159
|
+
/** Options for {@link spend}. */
|
|
160
|
+
type Options = {
|
|
161
|
+
/** Chains whose spend counts (mainnet chain ids). */
|
|
162
|
+
chainIds: readonly number[];
|
|
163
|
+
/** Environment whose spend counts; production mirrors the billing gate, sandbox is display-only. Defaults to `production`. */
|
|
164
|
+
environment?: Table['environment'] | undefined;
|
|
165
|
+
/** Organization id (`org_…`) the spend attributes to. */
|
|
166
|
+
orgId: string;
|
|
167
|
+
/** Window start (ISO 8601); rows created earlier are out of scope. */
|
|
168
|
+
since: string;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Sponsorship usage bucketed by time for one organization: row counts and
|
|
173
|
+
* committed fees per bucket. Fee semantics mirror {@link spend}: finalized
|
|
174
|
+
* rows at their actual fee, pending rows at their signed cap, failed rows at
|
|
175
|
+
* zero. Buckets with no rows are omitted.
|
|
176
|
+
*
|
|
177
|
+
* @param db - The database.
|
|
178
|
+
* @param options - Aggregation scope.
|
|
179
|
+
* @returns Time-ordered usage buckets.
|
|
180
|
+
*/
|
|
181
|
+
export declare function usage(db: Db.Db, options: usage.Options): Promise<usage.Bucket[]>;
|
|
182
|
+
export declare namespace usage {
|
|
183
|
+
/** One time bucket of sponsorship usage. */
|
|
184
|
+
type Bucket = {
|
|
185
|
+
/** Sponsored transactions recorded in the bucket, any status. */
|
|
186
|
+
count: number;
|
|
187
|
+
/** Committed fees in fee-token base units: finalized fees plus pending caps. */
|
|
188
|
+
feeTotal: bigint;
|
|
189
|
+
/** Bucket start (ISO 8601), aligned to UTC calendar boundaries. */
|
|
190
|
+
timestamp: string;
|
|
191
|
+
};
|
|
192
|
+
/** Options for {@link usage}. */
|
|
193
|
+
type Options = {
|
|
194
|
+
/** Key environment to restrict to; omit for all. */
|
|
195
|
+
environment?: Table['environment'] | undefined;
|
|
196
|
+
/** Window start (ISO 8601), inclusive. */
|
|
197
|
+
from: string;
|
|
198
|
+
/** Bucket width, aligned to UTC calendar boundaries. */
|
|
199
|
+
interval: 'day' | 'hour' | 'month' | 'week';
|
|
200
|
+
/** Organization id (`org_…`) the usage attributes to. */
|
|
201
|
+
orgId: string;
|
|
202
|
+
/** Project id (`prj_…`) to restrict to; omit for all. */
|
|
203
|
+
projectId?: string | undefined;
|
|
204
|
+
/** Window end (ISO 8601), exclusive. */
|
|
205
|
+
to: string;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Lists finalized billable rows not yet reported to the billing meter, oldest
|
|
210
|
+
* first, for the metering job.
|
|
211
|
+
*
|
|
212
|
+
* @param db - The database.
|
|
213
|
+
* @param options - Reporting scope.
|
|
214
|
+
* @returns The unreported records.
|
|
215
|
+
*/
|
|
216
|
+
export declare function listUnreported(db: Db.Db, options: listUnreported.Options): Promise<Record[]>;
|
|
217
|
+
export declare namespace listUnreported {
|
|
218
|
+
/** Options for {@link listUnreported}. */
|
|
219
|
+
type Options = {
|
|
220
|
+
/** Chains whose spend is metered (mainnet chain ids). */
|
|
221
|
+
chainIds: readonly number[];
|
|
222
|
+
/** Maximum rows to return. */
|
|
223
|
+
limit?: number | undefined;
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Marks a row as reported to the billing meter. A no-op once marked — the
|
|
228
|
+
* durable exactly-once guard for the metering job.
|
|
229
|
+
*
|
|
230
|
+
* @param db - The database.
|
|
231
|
+
* @param id - The sponsored-transaction id (`stx_…`).
|
|
232
|
+
* @param at - When the report was acknowledged (ISO 8601).
|
|
233
|
+
*/
|
|
234
|
+
export declare function markReported(db: Db.Db, id: string, at: string): Promise<void>;
|
|
235
|
+
/** Thrown by {@link reserve} when recording would exceed the org's period spend limit. */
|
|
236
|
+
export declare class PeriodSpendLimitError extends Error {
|
|
237
|
+
name: string;
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=sponsoredTransactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sponsoredTransactions.d.ts","sourceRoot":"","sources":["../../../src/db/tables/sponsoredTransactions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,UAAU,EAAE,MAAM,QAAQ,CAAA;AAI3D,OAAO,KAAK,KAAK,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,KAAK,KAAK,SAAS,MAAM,cAAc,CAAA;AAE9C,iGAAiG;AACjG,MAAM,MAAM,KAAK,GAAG,SAAS,CAAC,oBAAoB,CAAA;AAElD,0CAA0C;AAC1C,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;AAEtC;;;;;;;;;;GAUG;AACH,wBAAsB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CA0C5E;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,mEAAmE;IACnE,KAAK,KAAK,GAAG;QACX,uDAAuD;QACvD,QAAQ,EAAE,MAAM,CAAA;QAChB,yEAAyE;QACzE,QAAQ,EAAE,OAAO,CAAA;QACjB,+CAA+C;QAC/C,OAAO,EAAE,MAAM,CAAA;QACf,8DAA8D;QAC9D,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC7B,2DAA2D;QAC3D,WAAW,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;QACj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MAAM,EAAE,CAAC,CAa5F;AAED,MAAM,CAAC,OAAO,WAAW,cAAc,CAAC;IACtC,0CAA0C;IAC1C,KAAK,OAAO,GAAG;QACb,yDAAyD;QACzD,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;QAC3B,8BAA8B;QAC9B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAC3B,CAAA;CACF;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOnF;AAaD,0FAA0F;AAC1F,qBAAa,qBAAsB,SAAQ,KAAK;IACrC,IAAI,SAAgD;CAC9D"}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { sql } from 'kysely';
|
|
2
|
+
import * as Id from '../../internal/Id.js';
|
|
3
|
+
/**
|
|
4
|
+
* Records one sponsorship commitment as `pending`, keyed by its fee-payer
|
|
5
|
+
* sign payload. Written after fee-payer signing and before any broadcast, so
|
|
6
|
+
* no sponsored transaction goes unrecorded; a later recording site for the
|
|
7
|
+
* same envelope (raw submission after a fill intent) upgrades the row with
|
|
8
|
+
* its transaction hash, reopening failed rows for finalization.
|
|
9
|
+
*
|
|
10
|
+
* @param db - The database.
|
|
11
|
+
* @param input - Attribution and envelope facts captured at signing time.
|
|
12
|
+
* @returns The stored record.
|
|
13
|
+
*/
|
|
14
|
+
export async function upsert(db, input) {
|
|
15
|
+
const record = {
|
|
16
|
+
apiKeyId: input.apiKeyId,
|
|
17
|
+
billable: input.billable,
|
|
18
|
+
chainId: input.chainId,
|
|
19
|
+
createdAt: new Date().toISOString(),
|
|
20
|
+
currency: input.currency ?? null,
|
|
21
|
+
environment: input.environment,
|
|
22
|
+
feeAmount: null,
|
|
23
|
+
feeMax: input.feeMax ?? null,
|
|
24
|
+
feeToken: input.feeToken ?? null,
|
|
25
|
+
finalizedAt: null,
|
|
26
|
+
id: Id.generate('stx'),
|
|
27
|
+
meterReportedAt: null,
|
|
28
|
+
orgId: input.orgId,
|
|
29
|
+
projectId: input.projectId,
|
|
30
|
+
signPayload: input.signPayload,
|
|
31
|
+
status: 'pending',
|
|
32
|
+
transaction: input.transaction,
|
|
33
|
+
transactionHash: input.transactionHash ?? null,
|
|
34
|
+
};
|
|
35
|
+
return await db.kysely
|
|
36
|
+
.insertInto('sponsored_transactions')
|
|
37
|
+
.values(record)
|
|
38
|
+
.onConflict((oc) => oc.column('signPayload').doUpdateSet((eb) => ({
|
|
39
|
+
// Same sign payload = same envelope = same cap; only fills older nulls.
|
|
40
|
+
currency: eb.fn.coalesce(eb.ref('sponsored_transactions.currency'), eb.ref('excluded.currency')), // prettier-ignore
|
|
41
|
+
feeMax: eb.fn.coalesce(eb.ref('sponsored_transactions.feeMax'), eb.ref('excluded.feeMax')),
|
|
42
|
+
// A raw submission fills the intent's hash; a duplicate intent never
|
|
43
|
+
// clears an already-known hash.
|
|
44
|
+
transactionHash: eb.fn.coalesce(eb.ref('excluded.transactionHash'), eb.ref('sponsored_transactions.transactionHash')),
|
|
45
|
+
createdAt: sql `CASE WHEN ${eb.ref('sponsored_transactions.status')} = 'failed' THEN ${eb.ref('excluded.createdAt')} ELSE ${eb.ref('sponsored_transactions.createdAt')} END`,
|
|
46
|
+
finalizedAt: sql `CASE WHEN ${eb.ref('sponsored_transactions.status')} = 'failed' THEN NULL ELSE ${eb.ref('sponsored_transactions.finalizedAt')} END`,
|
|
47
|
+
status: sql `CASE WHEN ${eb.ref('sponsored_transactions.status')} = 'failed' THEN 'pending' ELSE ${eb.ref('sponsored_transactions.status')} END`,
|
|
48
|
+
})))
|
|
49
|
+
.returningAll()
|
|
50
|
+
.executeTakeFirstOrThrow();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Reads one sponsorship row by id.
|
|
54
|
+
*
|
|
55
|
+
* @param db - The database.
|
|
56
|
+
* @param id - The sponsored-transaction id (`stx_…`).
|
|
57
|
+
* @returns The record, or `undefined` when absent.
|
|
58
|
+
*/
|
|
59
|
+
export function get(db, id) {
|
|
60
|
+
return db.kysely
|
|
61
|
+
.selectFrom('sponsored_transactions')
|
|
62
|
+
.selectAll()
|
|
63
|
+
.where('id', '=', id)
|
|
64
|
+
.executeTakeFirst();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Lists pending sponsorships, oldest first, for the finalization job.
|
|
68
|
+
*
|
|
69
|
+
* @param db - The database.
|
|
70
|
+
* @param options - Paging options.
|
|
71
|
+
* @returns The pending records.
|
|
72
|
+
*/
|
|
73
|
+
export function listPending(db, options = {}) {
|
|
74
|
+
let query = db.kysely
|
|
75
|
+
.selectFrom('sponsored_transactions')
|
|
76
|
+
.selectAll()
|
|
77
|
+
.where('status', '=', 'pending')
|
|
78
|
+
// `id` breaks same-millisecond `createdAt` ties for a deterministic scan.
|
|
79
|
+
.orderBy('createdAt', 'asc')
|
|
80
|
+
.orderBy('id', 'asc');
|
|
81
|
+
if (options.limit !== undefined)
|
|
82
|
+
query = query.limit(options.limit);
|
|
83
|
+
return query.execute();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Lists hash-less fill intents, oldest first, for the reconciliation pass.
|
|
87
|
+
* Failed intents are included only when the caller supplies a recovery floor.
|
|
88
|
+
*
|
|
89
|
+
* @param db - The database.
|
|
90
|
+
* @param options - Paging options.
|
|
91
|
+
* @returns The pending intents.
|
|
92
|
+
*/
|
|
93
|
+
export function listIntents(db, options = {}) {
|
|
94
|
+
let query = db.kysely
|
|
95
|
+
.selectFrom('sponsored_transactions')
|
|
96
|
+
.selectAll()
|
|
97
|
+
.where(intentStatus(options.failedSince))
|
|
98
|
+
.where('transactionHash', 'is', null)
|
|
99
|
+
// `pending` sorts after `failed`; descending keeps active intents first.
|
|
100
|
+
.orderBy('status', 'desc')
|
|
101
|
+
.orderBy('createdAt', 'asc')
|
|
102
|
+
.orderBy('id', 'asc');
|
|
103
|
+
if (options.limit !== undefined)
|
|
104
|
+
query = query.limit(options.limit);
|
|
105
|
+
return query.execute();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Fills a reconciled intent's transaction hash and reopens failed intents.
|
|
109
|
+
* A no-op once another pass already assigned the hash.
|
|
110
|
+
*
|
|
111
|
+
* @param db - The database.
|
|
112
|
+
* @param id - The sponsored-transaction id (`stx_…`).
|
|
113
|
+
* @param transactionHash - The matched on-chain transaction hash.
|
|
114
|
+
*/
|
|
115
|
+
export async function assignTransactionHash(db, id, transactionHash) {
|
|
116
|
+
await db.kysely
|
|
117
|
+
.updateTable('sponsored_transactions')
|
|
118
|
+
.set({ finalizedAt: null, status: 'pending', transactionHash })
|
|
119
|
+
.where('id', '=', id)
|
|
120
|
+
.where('status', 'in', ['failed', 'pending'])
|
|
121
|
+
.where('transactionHash', 'is', null)
|
|
122
|
+
.execute();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Transitions a pending sponsorship to `finalized` with the receipt's actual
|
|
126
|
+
* fee. A no-op when the row is no longer pending (idempotent re-runs).
|
|
127
|
+
*
|
|
128
|
+
* @param db - The database.
|
|
129
|
+
* @param id - The sponsored-transaction id (`stx_…`).
|
|
130
|
+
* @param input - The finalized fee facts.
|
|
131
|
+
*/
|
|
132
|
+
export async function finalize(db, id, input) {
|
|
133
|
+
await db.kysely
|
|
134
|
+
.updateTable('sponsored_transactions')
|
|
135
|
+
.set({ feeAmount: input.feeAmount, finalizedAt: input.finalizedAt, status: 'finalized' })
|
|
136
|
+
.where('id', '=', id)
|
|
137
|
+
.where('status', '=', 'pending')
|
|
138
|
+
.execute();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Transitions a pending sponsorship to `failed` (never landed within the
|
|
142
|
+
* pending TTL). A no-op when the row is no longer pending.
|
|
143
|
+
*
|
|
144
|
+
* @param db - The database.
|
|
145
|
+
* @param id - The sponsored-transaction id (`stx_…`).
|
|
146
|
+
* @param finalizedAt - When the sponsorship was marked failed (ISO 8601).
|
|
147
|
+
*/
|
|
148
|
+
export async function fail(db, id, finalizedAt) {
|
|
149
|
+
await db.kysely
|
|
150
|
+
.updateTable('sponsored_transactions')
|
|
151
|
+
.set({ finalizedAt, status: 'failed' })
|
|
152
|
+
.where('id', '=', id)
|
|
153
|
+
.where('status', '=', 'pending')
|
|
154
|
+
.execute();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Records a sponsorship and enforces the period spend limit atomically. A
|
|
158
|
+
* per-org advisory lock serializes concurrent sponsorships so each one's
|
|
159
|
+
* signed cap is counted before the limit check; without it a burst reads
|
|
160
|
+
* pre-burst spend and overshoots. Throws {@link PeriodSpendLimitError} (rolling
|
|
161
|
+
* back the row) when the limit would be exceeded.
|
|
162
|
+
*
|
|
163
|
+
* @param db - The database (primary; never a cached replica).
|
|
164
|
+
* @param input - The sponsorship to record.
|
|
165
|
+
* @param limit - The period spend limit to enforce.
|
|
166
|
+
* @returns The stored record.
|
|
167
|
+
*/
|
|
168
|
+
export async function reserve(db, input, limit) {
|
|
169
|
+
return db.transaction(async (tx) => {
|
|
170
|
+
// `hashtext` maps the org id into the advisory-lock keyspace; the class
|
|
171
|
+
// namespaces it against other advisory-lock users. Released at tx end.
|
|
172
|
+
await sql `select pg_advisory_xact_lock(${billingLockClass}, hashtext(${input.orgId}))`.execute(tx.kysely); // prettier-ignore
|
|
173
|
+
const record = await upsert(tx, input);
|
|
174
|
+
if (record.billable) {
|
|
175
|
+
const committed = await spend(tx, {
|
|
176
|
+
chainIds: limit.chainIds,
|
|
177
|
+
orgId: input.orgId,
|
|
178
|
+
since: limit.since,
|
|
179
|
+
});
|
|
180
|
+
if (committed > limit.max)
|
|
181
|
+
throw new PeriodSpendLimitError();
|
|
182
|
+
}
|
|
183
|
+
return record;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/** Advisory-lock class namespacing per-org sponsorship serialization. */
|
|
187
|
+
const billingLockClass = 1112294220;
|
|
188
|
+
/**
|
|
189
|
+
* Billable spend committed since a cutoff, in fee-token base units: finalized
|
|
190
|
+
* rows at their actual fee plus pending rows at their signed fee cap, so
|
|
191
|
+
* in-flight sponsorships consume limit budget until receipts land.
|
|
192
|
+
*
|
|
193
|
+
* @param db - The database.
|
|
194
|
+
* @param options - Aggregation scope.
|
|
195
|
+
* @returns The committed spend in base units.
|
|
196
|
+
*/
|
|
197
|
+
export async function spend(db, options) {
|
|
198
|
+
const { chainIds, environment = 'production', orgId, since } = options;
|
|
199
|
+
const query = db.kysely
|
|
200
|
+
.selectFrom('sponsored_transactions')
|
|
201
|
+
.select([
|
|
202
|
+
sql `coalesce(sum(case when status = 'finalized' then fee_amount::numeric else 0 end), 0)`.as('finalized'), // prettier-ignore
|
|
203
|
+
sql `coalesce(sum(case when status = 'pending' then fee_max::numeric else 0 end), 0)`.as('pending'), // prettier-ignore
|
|
204
|
+
])
|
|
205
|
+
.where('orgId', '=', orgId)
|
|
206
|
+
.where('environment', '=', environment)
|
|
207
|
+
// Redundant with the CASE arms, but lets the billing index's
|
|
208
|
+
// (org_id, status, created_at) shape serve the range scan.
|
|
209
|
+
.where('status', 'in', ['finalized', 'pending'])
|
|
210
|
+
.where('chainId', 'in', [...chainIds])
|
|
211
|
+
.where('createdAt', '>=', since);
|
|
212
|
+
// Production mirrors the sponsorship gate — only billable rows count. Sandbox
|
|
213
|
+
// rows are non-billable by construction, so the figure is display-only.
|
|
214
|
+
const row = await (environment === 'production' ? query.where('billable', '=', true) : query) //
|
|
215
|
+
.executeTakeFirstOrThrow();
|
|
216
|
+
return BigInt(row.finalized) + BigInt(row.pending);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Sponsorship usage bucketed by time for one organization: row counts and
|
|
220
|
+
* committed fees per bucket. Fee semantics mirror {@link spend}: finalized
|
|
221
|
+
* rows at their actual fee, pending rows at their signed cap, failed rows at
|
|
222
|
+
* zero. Buckets with no rows are omitted.
|
|
223
|
+
*
|
|
224
|
+
* @param db - The database.
|
|
225
|
+
* @param options - Aggregation scope.
|
|
226
|
+
* @returns Time-ordered usage buckets.
|
|
227
|
+
*/
|
|
228
|
+
export async function usage(db, options) {
|
|
229
|
+
// TODO: convert to an OLAP-friendly approach (rollup table or columnar store)
|
|
230
|
+
// when per-org range scans grow slow.
|
|
231
|
+
const { environment, from, interval, orgId, projectId, to } = options;
|
|
232
|
+
// `sql.lit` inlines the enum-validated interval so the GROUP BY expression
|
|
233
|
+
// matches the SELECT expression textually; truncation happens in UTC wall
|
|
234
|
+
// time regardless of the session time zone.
|
|
235
|
+
const bucket = sql `date_trunc(${sql.lit(interval)}, (created_at::timestamptz) at time zone 'UTC')`;
|
|
236
|
+
let query = db.kysely
|
|
237
|
+
.selectFrom('sponsored_transactions')
|
|
238
|
+
.select([
|
|
239
|
+
sql `to_char(${bucket}, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')`.as('timestamp'),
|
|
240
|
+
sql `count(*)`.as('count'),
|
|
241
|
+
sql `coalesce(sum(case when status = 'finalized' then fee_amount::numeric when status = 'pending' then fee_max::numeric else 0 end), 0)`.as('feeTotal'), // prettier-ignore
|
|
242
|
+
])
|
|
243
|
+
.where('orgId', '=', orgId)
|
|
244
|
+
// Text-range bounds keep the (org_id, created_at) index serving the scan.
|
|
245
|
+
.where('createdAt', '>=', from)
|
|
246
|
+
.where('createdAt', '<', to)
|
|
247
|
+
.groupBy(bucket)
|
|
248
|
+
.orderBy(bucket);
|
|
249
|
+
if (environment !== undefined)
|
|
250
|
+
query = query.where('environment', '=', environment);
|
|
251
|
+
if (projectId !== undefined)
|
|
252
|
+
query = query.where('projectId', '=', projectId);
|
|
253
|
+
const rows = await query.execute();
|
|
254
|
+
return rows.map((row) => ({
|
|
255
|
+
count: Number(row.count),
|
|
256
|
+
feeTotal: BigInt(row.feeTotal),
|
|
257
|
+
timestamp: row.timestamp,
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Lists finalized billable rows not yet reported to the billing meter, oldest
|
|
262
|
+
* first, for the metering job.
|
|
263
|
+
*
|
|
264
|
+
* @param db - The database.
|
|
265
|
+
* @param options - Reporting scope.
|
|
266
|
+
* @returns The unreported records.
|
|
267
|
+
*/
|
|
268
|
+
export function listUnreported(db, options) {
|
|
269
|
+
let query = db.kysely
|
|
270
|
+
.selectFrom('sponsored_transactions')
|
|
271
|
+
.selectAll()
|
|
272
|
+
.where('status', '=', 'finalized')
|
|
273
|
+
.where('billable', '=', true)
|
|
274
|
+
.where('chainId', 'in', [...options.chainIds])
|
|
275
|
+
.where('meterReportedAt', 'is', null)
|
|
276
|
+
// `id` breaks same-millisecond `finalizedAt` ties for a deterministic scan.
|
|
277
|
+
.orderBy('finalizedAt', 'asc')
|
|
278
|
+
.orderBy('id', 'asc');
|
|
279
|
+
if (options.limit !== undefined)
|
|
280
|
+
query = query.limit(options.limit);
|
|
281
|
+
return query.execute();
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Marks a row as reported to the billing meter. A no-op once marked — the
|
|
285
|
+
* durable exactly-once guard for the metering job.
|
|
286
|
+
*
|
|
287
|
+
* @param db - The database.
|
|
288
|
+
* @param id - The sponsored-transaction id (`stx_…`).
|
|
289
|
+
* @param at - When the report was acknowledged (ISO 8601).
|
|
290
|
+
*/
|
|
291
|
+
export async function markReported(db, id, at) {
|
|
292
|
+
await db.kysely
|
|
293
|
+
.updateTable('sponsored_transactions')
|
|
294
|
+
.set({ meterReportedAt: at })
|
|
295
|
+
.where('id', '=', id)
|
|
296
|
+
.where('meterReportedAt', 'is', null)
|
|
297
|
+
.execute();
|
|
298
|
+
}
|
|
299
|
+
/** Intent status predicate; failed rows are recovery candidates only briefly. */
|
|
300
|
+
function intentStatus(failedSince) {
|
|
301
|
+
return (eb) => {
|
|
302
|
+
if (failedSince === undefined)
|
|
303
|
+
return eb('status', '=', 'pending');
|
|
304
|
+
return eb.or([
|
|
305
|
+
eb('status', '=', 'pending'),
|
|
306
|
+
eb.and([eb('status', '=', 'failed'), eb('finalizedAt', '>=', failedSince)]),
|
|
307
|
+
]);
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/** Thrown by {@link reserve} when recording would exceed the org's period spend limit. */
|
|
311
|
+
export class PeriodSpendLimitError extends Error {
|
|
312
|
+
name = 'SponsoredTransactions.PeriodSpendLimitError';
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=sponsoredTransactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sponsoredTransactions.js","sourceRoot":"","sources":["../../../src/db/tables/sponsoredTransactions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAE5B,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAU1C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,EAAS,EAAE,KAAmB;IACzD,MAAM,MAAM,GAAW;QACrB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,IAAI;QAChC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,IAAI;QAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,IAAI;QAChC,WAAW,EAAE,IAAI;QACjB,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;QACtB,eAAe,EAAE,IAAI;QACrB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,MAAM,EAAE,SAA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AE,CAAC,QAAQ,EAAE,GAAG,EAAE,SAAS,CAAC;YAC5B,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,aAAa,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;SAC5E,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC;AAED,0FAA0F;AAC1F,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACrC,IAAI,GAAG,6CAA6C,CAAA;CAC9D"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Selectable } from 'kysely';
|
|
2
|
+
import type * as Db from '../Db.js';
|
|
3
|
+
import type * as db_Schema from '../Schema.js';
|
|
4
|
+
/** Columns of the `stripe_customers` table, derived from `Schema.StripeCustomer`. */
|
|
5
|
+
export type Table = db_Schema.StripeCustomer;
|
|
6
|
+
/** A stored Stripe billing-source row. */
|
|
7
|
+
export type Record = Selectable<Table>;
|
|
8
|
+
/** A billing status. */
|
|
9
|
+
export type Status = Record['status'];
|
|
10
|
+
/** Billing statuses; `active` alone opens the production sponsorship gate. */
|
|
11
|
+
export declare const statuses: readonly ["active", "canceled", "none", "past_due"];
|
|
12
|
+
/**
|
|
13
|
+
* Inserts a Stripe billing source (status `none`) and returns the stored record.
|
|
14
|
+
* Idempotent per organization: a concurrent first-checkout race resolves to
|
|
15
|
+
* the winner's row — the loser's Stripe customer stays orphaned in Stripe,
|
|
16
|
+
* which is harmless.
|
|
17
|
+
*
|
|
18
|
+
* @param db - The database.
|
|
19
|
+
* @param input - The Stripe source to insert.
|
|
20
|
+
* @returns The stored record.
|
|
21
|
+
*/
|
|
22
|
+
export declare function create(db: Db.Db, input: create.Input): Promise<Record>;
|
|
23
|
+
export declare namespace create {
|
|
24
|
+
/** Fields accepted when inserting a Stripe billing source. */
|
|
25
|
+
type Input = {
|
|
26
|
+
/** Environment this source backs; defaults to `production`. */
|
|
27
|
+
environment?: Record['environment'] | undefined;
|
|
28
|
+
/** Organization id (`org_…`) the Stripe source belongs to. */
|
|
29
|
+
orgId: string;
|
|
30
|
+
/** Stripe customer id backing this account. */
|
|
31
|
+
stripeCustomerId: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Deletes an organization's Stripe billing source. The Stripe customer is never
|
|
36
|
+
* deleted; its invoice history stays in Stripe for audit.
|
|
37
|
+
*
|
|
38
|
+
* @param db - The database.
|
|
39
|
+
* @param orgId - The organization id (`org_…`).
|
|
40
|
+
* @returns Whether a Stripe source existed and was deleted.
|
|
41
|
+
*/
|
|
42
|
+
export declare function deleteByOrg(db: Db.Db, orgId: string): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Reads an organization's Stripe billing source.
|
|
45
|
+
*
|
|
46
|
+
* @param db - The database.
|
|
47
|
+
* @param orgId - The organization id (`org_…`).
|
|
48
|
+
* @param environment - The environment to read; defaults to `production`.
|
|
49
|
+
* @returns The stored record, or `undefined` when the org has none.
|
|
50
|
+
*/
|
|
51
|
+
export declare function get(db: Db.Db, orgId: string, environment?: Record['environment']): Promise<Record | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Lists every billing source in an environment — the driver set for the cron
|
|
54
|
+
* job that reconciles cached billing snapshots (e.g. API-key records) against
|
|
55
|
+
* this authoritative table.
|
|
56
|
+
*
|
|
57
|
+
* @param db - The database.
|
|
58
|
+
* @param environment - The environment to enumerate.
|
|
59
|
+
* @returns The stored records for that environment.
|
|
60
|
+
*/
|
|
61
|
+
export declare function listByEnvironment(db: Db.Db, environment: Record['environment']): Promise<Record[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Reads a Stripe billing source by its customer id — the webhook handler's
|
|
64
|
+
* lookup for inbound events.
|
|
65
|
+
*
|
|
66
|
+
* @param db - The database.
|
|
67
|
+
* @param stripeCustomerId - The Stripe customer id.
|
|
68
|
+
* @returns The stored record, or `undefined` for unknown customers.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getByCustomer(db: Db.Db, stripeCustomerId: string): Promise<Record | undefined>;
|
|
71
|
+
/**
|
|
72
|
+
* Sets an organization's billing status.
|
|
73
|
+
*
|
|
74
|
+
* @param db - The database.
|
|
75
|
+
* @param orgId - The organization id (`org_…`).
|
|
76
|
+
* @param status - The derived status to persist.
|
|
77
|
+
* @param environment - The environment to update; defaults to `production`.
|
|
78
|
+
* @returns The updated record, or `undefined` when the org has no Stripe source.
|
|
79
|
+
*/
|
|
80
|
+
export declare function setStatus(db: Db.Db, orgId: string, status: Status, environment?: Record['environment']): Promise<Record | undefined>;
|
|
81
|
+
//# sourceMappingURL=stripeCustomers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripeCustomers.d.ts","sourceRoot":"","sources":["../../../src/db/tables/stripeCustomers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAExC,OAAO,KAAK,KAAK,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,KAAK,KAAK,SAAS,MAAM,cAAc,CAAA;AAE9C,qFAAqF;AACrF,MAAM,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAA;AAE5C,0CAA0C;AAC1C,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;AAEtC,wBAAwB;AACxB,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;AAErC,8EAA8E;AAC9E,eAAO,MAAM,QAAQ,qDAAkF,CAAA;AAEvG;;;;;;;;;GASG;AACH,wBAAsB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAyB5E;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,8DAA8D;IAC9D,KAAK,KAAK,GAAG;QACX,+DAA+D;QAC/D,WAA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