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,527 @@
|
|
|
1
|
+
import type * as Log from '../internal/Log.js'
|
|
2
|
+
import * as Analytics from './Analytics.js'
|
|
3
|
+
import * as RequestEvents from './tables/requestEvents.js'
|
|
4
|
+
|
|
5
|
+
const context = { enabled: true, environment: 'test', service: 'api' }
|
|
6
|
+
|
|
7
|
+
const entry = {
|
|
8
|
+
duration: 12.3,
|
|
9
|
+
level: 'info',
|
|
10
|
+
method: 'GET',
|
|
11
|
+
path: '/v1/transactions',
|
|
12
|
+
requestId: 'req-1',
|
|
13
|
+
route: '/v1/transactions',
|
|
14
|
+
status: 200,
|
|
15
|
+
} satisfies Log.Entry
|
|
16
|
+
|
|
17
|
+
const clickHouse = {
|
|
18
|
+
database: 'tempo_api',
|
|
19
|
+
password: 'secret',
|
|
20
|
+
url: 'https://clickhouse.test',
|
|
21
|
+
user: 'reader',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Baseline stored row for insert/queue tests. */
|
|
25
|
+
const row = {
|
|
26
|
+
billing_active: null,
|
|
27
|
+
duration_ms: 12.3,
|
|
28
|
+
environment: 'test',
|
|
29
|
+
error_code: null,
|
|
30
|
+
key_environment: null,
|
|
31
|
+
key_id: null,
|
|
32
|
+
method: 'GET',
|
|
33
|
+
org_id: null,
|
|
34
|
+
project_id: null,
|
|
35
|
+
principal_type: 'unknown',
|
|
36
|
+
rate_limit_scope: null,
|
|
37
|
+
request_id: 'req-1',
|
|
38
|
+
route: '/v1/transactions',
|
|
39
|
+
service: 'api',
|
|
40
|
+
status: 200,
|
|
41
|
+
timestamp: '2026-01-01 00:00:00.000',
|
|
42
|
+
} satisfies Analytics.Event
|
|
43
|
+
|
|
44
|
+
afterEach(() => vi.unstubAllGlobals())
|
|
45
|
+
|
|
46
|
+
describe('clickhouse', () => {
|
|
47
|
+
test('insert posts NDJSON rows scoped to the database', async () => {
|
|
48
|
+
const fetch = vi
|
|
49
|
+
.fn<typeof globalThis.fetch>()
|
|
50
|
+
.mockResolvedValue(new Response('', { status: 200 }))
|
|
51
|
+
vi.stubGlobal('fetch', fetch)
|
|
52
|
+
|
|
53
|
+
await Analytics.clickhouse(clickHouse).insert('request_events', [row])
|
|
54
|
+
|
|
55
|
+
const url = new URL(String(fetch.mock.calls[0]![0]))
|
|
56
|
+
expect(url.searchParams.get('database')).toBe('tempo_api')
|
|
57
|
+
expect(url.searchParams.get('query')).toBe('INSERT INTO `request_events` FORMAT JSONEachRow')
|
|
58
|
+
const init = fetch.mock.calls[0]![1]
|
|
59
|
+
expect(init?.body).toBe(`${JSON.stringify(row)}\n`)
|
|
60
|
+
expect(init?.headers).toMatchObject({
|
|
61
|
+
Authorization: `Basic ${btoa('reader:secret')}`,
|
|
62
|
+
'Content-Type': 'application/x-ndjson',
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('insert skips empty batches', async () => {
|
|
67
|
+
const fetch = vi.fn<typeof globalThis.fetch>()
|
|
68
|
+
vi.stubGlobal('fetch', fetch)
|
|
69
|
+
|
|
70
|
+
await Analytics.clickhouse(clickHouse).insert('request_events', [])
|
|
71
|
+
|
|
72
|
+
expect(fetch).not.toHaveBeenCalled()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('insert throws InsertError on a non-2xx response', async () => {
|
|
76
|
+
vi.stubGlobal(
|
|
77
|
+
'fetch',
|
|
78
|
+
vi
|
|
79
|
+
.fn<typeof globalThis.fetch>()
|
|
80
|
+
.mockResolvedValue(new Response('table missing', { status: 404 })),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
await expect(
|
|
84
|
+
Analytics.clickhouse(clickHouse).insert('request_events', [row]),
|
|
85
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
86
|
+
`[Analytics.InsertError: ClickHouse insert failed with status 404: table missing]`,
|
|
87
|
+
)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('query posts the statement in the body and returns rows', async () => {
|
|
91
|
+
const fetch = vi
|
|
92
|
+
.fn<typeof globalThis.fetch>()
|
|
93
|
+
.mockResolvedValue(new Response(JSON.stringify({ data: [{ requests: 1 }] }), { status: 200 })) // prettier-ignore
|
|
94
|
+
vi.stubGlobal('fetch', fetch)
|
|
95
|
+
|
|
96
|
+
const rows = await Analytics.clickhouse(clickHouse).query('SELECT count() AS requests')
|
|
97
|
+
|
|
98
|
+
expect(rows).toEqual([{ requests: 1 }])
|
|
99
|
+
const url = new URL(String(fetch.mock.calls[0]![0]))
|
|
100
|
+
expect(url.searchParams.get('database')).toBe('tempo_api')
|
|
101
|
+
expect(url.searchParams.get('query')).toBeNull()
|
|
102
|
+
expect(String(fetch.mock.calls[0]![1]?.body)).toBe('SELECT count() AS requests FORMAT JSON')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('query throws QueryError on a non-2xx response', async () => {
|
|
106
|
+
vi.stubGlobal(
|
|
107
|
+
'fetch',
|
|
108
|
+
vi
|
|
109
|
+
.fn<typeof globalThis.fetch>()
|
|
110
|
+
.mockResolvedValue(new Response('syntax error', { status: 400 })),
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
await expect(
|
|
114
|
+
Analytics.clickhouse(clickHouse).query('SELECT'),
|
|
115
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
116
|
+
`[Analytics.QueryError: ClickHouse query failed with status 400: syntax error]`,
|
|
117
|
+
)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('rejects invalid table identifiers', async () => {
|
|
121
|
+
vi.stubGlobal('fetch', vi.fn<typeof globalThis.fetch>())
|
|
122
|
+
|
|
123
|
+
await expect(
|
|
124
|
+
Analytics.clickhouse(clickHouse).insert('bad`name' as 'request_events', [row]),
|
|
125
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
126
|
+
`[Analytics.ConfigError: Invalid ClickHouse identifier: bad\`name]`,
|
|
127
|
+
)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('migrate applies every migration when guards are unsatisfied', async () => {
|
|
131
|
+
// Guards report their columns missing, so every migration's DDL applies.
|
|
132
|
+
const fetch = vi.fn<typeof globalThis.fetch>().mockImplementation(async (_url, init) => {
|
|
133
|
+
if (String(init?.body).includes('system.columns'))
|
|
134
|
+
return new Response(JSON.stringify({ data: [{ applied: 0 }] }), { status: 200 })
|
|
135
|
+
return new Response('', { status: 200 })
|
|
136
|
+
})
|
|
137
|
+
vi.stubGlobal('fetch', fetch)
|
|
138
|
+
|
|
139
|
+
await Analytics.clickhouse(clickHouse).migrate()
|
|
140
|
+
|
|
141
|
+
const url = new URL(String(fetch.mock.calls[0]![0]))
|
|
142
|
+
expect(url.searchParams.get('database')).toBe('tempo_api')
|
|
143
|
+
const bodies = fetch.mock.calls.map((call) => String(call[1]?.body))
|
|
144
|
+
for (const migration of Analytics.migrations) expect(bodies).toContain(migration.sql)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('migrate skips a guarded migration when its guard is satisfied', async () => {
|
|
148
|
+
// Guards report their columns present (fresh DB from the baseline CREATE),
|
|
149
|
+
// so the guarded ALTER is skipped, sparing a scoped user the ALTER grant.
|
|
150
|
+
const fetch = vi.fn<typeof globalThis.fetch>().mockImplementation(async (_url, init) => {
|
|
151
|
+
if (String(init?.body).includes('system.columns'))
|
|
152
|
+
return new Response(JSON.stringify({ data: [{ applied: 1 }] }), { status: 200 })
|
|
153
|
+
return new Response('', { status: 200 })
|
|
154
|
+
})
|
|
155
|
+
vi.stubGlobal('fetch', fetch)
|
|
156
|
+
|
|
157
|
+
await Analytics.clickhouse(clickHouse).migrate()
|
|
158
|
+
|
|
159
|
+
const bodies = fetch.mock.calls.map((call) => String(call[1]?.body))
|
|
160
|
+
const guarded = Analytics.migrations.find((migration) => migration.guard)!
|
|
161
|
+
expect(bodies).not.toContain(guarded.sql)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
test('migrate throws MigrateError on a non-2xx response', async () => {
|
|
165
|
+
vi.stubGlobal(
|
|
166
|
+
'fetch',
|
|
167
|
+
vi.fn<typeof globalThis.fetch>().mockResolvedValue(new Response('denied', { status: 403 })),
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
await expect(Analytics.clickhouse(clickHouse).migrate()).rejects.toThrow(Analytics.MigrateError)
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
describe('migrations', () => {
|
|
175
|
+
test('the migrations declare every request_events column', () => {
|
|
176
|
+
// The baseline CREATE declares every column; later ALTERs re-patch tables
|
|
177
|
+
// that predate a column (e.g. billing columns for existing production).
|
|
178
|
+
const sql = Analytics.migrations.map((migration) => migration.sql).join('\n')
|
|
179
|
+
for (const column of Object.keys(row)) expect(sql).toContain(column)
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
describe('get', () => {
|
|
184
|
+
test('resolves factories and passes stores through', () => {
|
|
185
|
+
const store = Analytics.clickhouse(clickHouse)
|
|
186
|
+
expect(Analytics.get(store)).toBe(store)
|
|
187
|
+
expect(Analytics.get(() => store)).toBe(store)
|
|
188
|
+
})
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
describe('createQueueSink', () => {
|
|
192
|
+
test('enqueues one row per entry', async () => {
|
|
193
|
+
const send = vi.fn<(message: Analytics.Event) => Promise<void>>().mockResolvedValue(undefined)
|
|
194
|
+
const sink = Analytics.createQueueSink({ send })(context)
|
|
195
|
+
|
|
196
|
+
await sink(entry)
|
|
197
|
+
|
|
198
|
+
expect(send).toHaveBeenCalledTimes(1)
|
|
199
|
+
const row = send.mock.calls[0]![0]
|
|
200
|
+
expect({
|
|
201
|
+
billing_active: row.billing_active,
|
|
202
|
+
duration_ms: row.duration_ms,
|
|
203
|
+
environment: row.environment,
|
|
204
|
+
error_code: row.error_code,
|
|
205
|
+
key_environment: row.key_environment,
|
|
206
|
+
key_id: row.key_id,
|
|
207
|
+
method: row.method,
|
|
208
|
+
org_id: row.org_id,
|
|
209
|
+
principal_type: row.principal_type,
|
|
210
|
+
project_id: row.project_id,
|
|
211
|
+
rate_limit_scope: row.rate_limit_scope,
|
|
212
|
+
request_id: row.request_id,
|
|
213
|
+
route: row.route,
|
|
214
|
+
service: row.service,
|
|
215
|
+
status: row.status,
|
|
216
|
+
timestamp: '<timestamp>',
|
|
217
|
+
}).toMatchInlineSnapshot(`
|
|
218
|
+
{
|
|
219
|
+
"billing_active": null,
|
|
220
|
+
"duration_ms": 12.3,
|
|
221
|
+
"environment": "test",
|
|
222
|
+
"error_code": null,
|
|
223
|
+
"key_environment": null,
|
|
224
|
+
"key_id": null,
|
|
225
|
+
"method": "GET",
|
|
226
|
+
"org_id": null,
|
|
227
|
+
"principal_type": "unknown",
|
|
228
|
+
"project_id": null,
|
|
229
|
+
"rate_limit_scope": null,
|
|
230
|
+
"request_id": "req-1",
|
|
231
|
+
"route": "/v1/transactions",
|
|
232
|
+
"service": "api",
|
|
233
|
+
"status": 200,
|
|
234
|
+
"timestamp": "<timestamp>",
|
|
235
|
+
}
|
|
236
|
+
`)
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
test('retries a failed send once with the same row', async () => {
|
|
240
|
+
const send = vi
|
|
241
|
+
.fn<(message: Analytics.Event) => Promise<void>>()
|
|
242
|
+
.mockRejectedValueOnce(new Error('Unknown Internal Error (15000)'))
|
|
243
|
+
.mockResolvedValueOnce(undefined)
|
|
244
|
+
const sink = Analytics.createQueueSink({ send })(context)
|
|
245
|
+
|
|
246
|
+
await sink(entry)
|
|
247
|
+
|
|
248
|
+
expect(send).toHaveBeenCalledTimes(2)
|
|
249
|
+
expect(send.mock.calls[1]![0]).toBe(send.mock.calls[0]![0])
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
test('records API-key attribution for API-key principals', async () => {
|
|
253
|
+
const send = vi.fn<(message: Analytics.Event) => Promise<void>>().mockResolvedValue(undefined)
|
|
254
|
+
const sink = Analytics.createQueueSink({ send })(context)
|
|
255
|
+
|
|
256
|
+
await sink({
|
|
257
|
+
...entry,
|
|
258
|
+
principal: {
|
|
259
|
+
billingActive: true,
|
|
260
|
+
environment: 'production',
|
|
261
|
+
id: 'key_1',
|
|
262
|
+
orgId: 'org_1',
|
|
263
|
+
projectId: 'prj_1',
|
|
264
|
+
type: 'api_key',
|
|
265
|
+
},
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
expect(send.mock.calls[0]![0]).toMatchObject({
|
|
269
|
+
billing_active: 1,
|
|
270
|
+
key_environment: 'production',
|
|
271
|
+
project_id: 'prj_1',
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
test('rethrows when the retry also fails', async () => {
|
|
276
|
+
const send = vi
|
|
277
|
+
.fn<(message: Analytics.Event) => Promise<void>>()
|
|
278
|
+
.mockRejectedValue(new Error('Unknown Internal Error (15000)'))
|
|
279
|
+
const sink = Analytics.createQueueSink({ send })(context)
|
|
280
|
+
|
|
281
|
+
await expect(sink(entry)).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
282
|
+
`[Error: Unknown Internal Error (15000)]`,
|
|
283
|
+
)
|
|
284
|
+
expect(send).toHaveBeenCalledTimes(2)
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
test('drops entries when disabled', async () => {
|
|
288
|
+
const send = vi.fn<(message: Analytics.Event) => Promise<void>>()
|
|
289
|
+
const sink = Analytics.createQueueSink({ send })({ ...context, enabled: false })
|
|
290
|
+
|
|
291
|
+
await sink(entry)
|
|
292
|
+
|
|
293
|
+
expect(send).not.toHaveBeenCalled()
|
|
294
|
+
})
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
describe('handleQueue', () => {
|
|
298
|
+
/** Fake store and one queued message with ack/retry spies. */
|
|
299
|
+
function fixture() {
|
|
300
|
+
const insert = vi.fn((_table: 'request_events', _rows: readonly Analytics.Event[]) =>
|
|
301
|
+
Promise.resolve(),
|
|
302
|
+
)
|
|
303
|
+
const store = { insert, migrate: () => Promise.resolve(), query: () => Promise.resolve([]) }
|
|
304
|
+
const message = { ack: vi.fn(), body: row, retry: vi.fn() }
|
|
305
|
+
return { insert, message, store }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
test('ignores batches from other queues', async () => {
|
|
309
|
+
const { insert, message, store } = fixture()
|
|
310
|
+
|
|
311
|
+
const handled = await Analytics.handleQueue(store, {
|
|
312
|
+
messages: [message],
|
|
313
|
+
queue: 'webhook-deliveries',
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
expect(handled).toBe(false)
|
|
317
|
+
expect(insert).not.toHaveBeenCalled()
|
|
318
|
+
expect(message.ack).not.toHaveBeenCalled()
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
test('matches an overridden queue name instead of the default', async () => {
|
|
322
|
+
const { insert, message, store } = fixture()
|
|
323
|
+
|
|
324
|
+
const handled = await Analytics.handleQueue(
|
|
325
|
+
store,
|
|
326
|
+
{ messages: [message], queue: 'api-pr-7-request-analytics' },
|
|
327
|
+
{ queue: 'api-pr-7-request-analytics' },
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
expect(handled).toBe(true)
|
|
331
|
+
expect(insert).toHaveBeenCalledWith('request_events', [row])
|
|
332
|
+
|
|
333
|
+
const defaultNamed = await Analytics.handleQueue(
|
|
334
|
+
store,
|
|
335
|
+
{ messages: [message], queue: Analytics.queueName },
|
|
336
|
+
{ queue: 'api-pr-7-request-analytics' },
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
expect(defaultNamed).toBe(false)
|
|
340
|
+
expect(insert).toHaveBeenCalledTimes(1)
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
test('inserts the batch and acks each message', async () => {
|
|
344
|
+
const { insert, message, store } = fixture()
|
|
345
|
+
|
|
346
|
+
const handled = await Analytics.handleQueue(store, {
|
|
347
|
+
messages: [message],
|
|
348
|
+
queue: Analytics.queueName,
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
expect(handled).toBe(true)
|
|
352
|
+
expect(insert).toHaveBeenCalledWith('request_events', [row])
|
|
353
|
+
expect(message.ack).toHaveBeenCalledTimes(1)
|
|
354
|
+
expect(message.retry).not.toHaveBeenCalled()
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
test('retries every message when the insert fails', async () => {
|
|
358
|
+
vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
359
|
+
const { insert, message, store } = fixture()
|
|
360
|
+
insert.mockRejectedValueOnce(new Error('clickhouse down'))
|
|
361
|
+
|
|
362
|
+
const handled = await Analytics.handleQueue(store, {
|
|
363
|
+
messages: [message],
|
|
364
|
+
queue: Analytics.queueName,
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
expect(handled).toBe(true)
|
|
368
|
+
expect(message.ack).not.toHaveBeenCalled()
|
|
369
|
+
expect(message.retry).toHaveBeenCalledTimes(1)
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
test('resolves factory sources at the leaf', async () => {
|
|
373
|
+
const { insert, message, store } = fixture()
|
|
374
|
+
|
|
375
|
+
await Analytics.handleQueue(() => store, { messages: [message], queue: Analytics.queueName })
|
|
376
|
+
|
|
377
|
+
expect(insert).toHaveBeenCalledTimes(1)
|
|
378
|
+
})
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
describe('readProjectUsage', () => {
|
|
382
|
+
test('scopes attributed project rows without current key inventory', async () => {
|
|
383
|
+
const fetch = vi
|
|
384
|
+
.fn<typeof globalThis.fetch>()
|
|
385
|
+
.mockImplementation(async () => new Response(JSON.stringify({ data: [] }), { status: 200 }))
|
|
386
|
+
vi.stubGlobal('fetch', fetch)
|
|
387
|
+
|
|
388
|
+
const usage = await RequestEvents.readProjectUsage(Analytics.clickhouse(clickHouse), {
|
|
389
|
+
attributions: [{ environment: 'sandbox', projectId: 'prj_1' }],
|
|
390
|
+
from: '2026-01-01T00:00:00.000Z',
|
|
391
|
+
interval: 'day',
|
|
392
|
+
orgId: 'org_1',
|
|
393
|
+
to: '2026-01-02T00:00:00.000Z',
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
const query = String(fetch.mock.calls[0]![1]?.body)
|
|
397
|
+
expect(query).toContain(`org_id = 'org_1'`)
|
|
398
|
+
expect(query).toContain(`project_id = 'prj_1'`)
|
|
399
|
+
expect(query).toContain(`key_environment = 'sandbox'`)
|
|
400
|
+
expect(query).not.toContain('key_id IN')
|
|
401
|
+
expect(query).toContain('LIMIT 100')
|
|
402
|
+
expect(new URL(String(fetch.mock.calls[0]![0])).searchParams.get('query')).toBeNull()
|
|
403
|
+
expect(usage).toMatchObject({
|
|
404
|
+
from: '2026-01-01T00:00:00.000Z',
|
|
405
|
+
interval: 'day',
|
|
406
|
+
to: '2026-01-02T00:00:00.000Z',
|
|
407
|
+
totals: { averageDurationMs: 0, errors: 0, requests: 0 },
|
|
408
|
+
})
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
test('keeps legacy rows scoped to project keys without global org filtering', async () => {
|
|
412
|
+
const fetch = vi
|
|
413
|
+
.fn<typeof globalThis.fetch>()
|
|
414
|
+
.mockImplementation(async () => new Response(JSON.stringify({ data: [] }), { status: 200 }))
|
|
415
|
+
vi.stubGlobal('fetch', fetch)
|
|
416
|
+
|
|
417
|
+
await RequestEvents.readProjectUsage(Analytics.clickhouse(clickHouse), {
|
|
418
|
+
attributions: [
|
|
419
|
+
{ environment: 'sandbox', projectId: 'prj_1' },
|
|
420
|
+
{ apiKeyIds: ['key_1', 'key_2'], environment: 'sandbox', projectId: null },
|
|
421
|
+
],
|
|
422
|
+
from: '2026-01-01T00:00:00.000Z',
|
|
423
|
+
interval: 'hour',
|
|
424
|
+
orgId: 'org_1',
|
|
425
|
+
to: '2026-01-01T01:00:00.000Z',
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
const query = String(fetch.mock.calls[0]![1]?.body)
|
|
429
|
+
expect(query).toContain(`(org_id = 'org_1' AND project_id = 'prj_1'`)
|
|
430
|
+
expect(query).toContain(`(project_id IS NULL AND key_id IN ('key_1', 'key_2')`)
|
|
431
|
+
expect(query).toContain(`(key_environment = 'sandbox' OR key_environment IS NULL)`)
|
|
432
|
+
expect(query).not.toContain(`org_id = 'org_1' AND project_id IS NULL`)
|
|
433
|
+
})
|
|
434
|
+
|
|
435
|
+
test('scopes to the whole organization when a project id is absent', async () => {
|
|
436
|
+
const fetch = vi
|
|
437
|
+
.fn<typeof globalThis.fetch>()
|
|
438
|
+
.mockImplementation(async () => new Response(JSON.stringify({ data: [] }), { status: 200 }))
|
|
439
|
+
vi.stubGlobal('fetch', fetch)
|
|
440
|
+
|
|
441
|
+
await RequestEvents.readProjectUsage(Analytics.clickhouse(clickHouse), {
|
|
442
|
+
attributions: [
|
|
443
|
+
{ environment: 'sandbox' },
|
|
444
|
+
{ apiKeyIds: ['key_1'], environment: 'sandbox', projectId: null },
|
|
445
|
+
],
|
|
446
|
+
from: '2026-01-01T00:00:00.000Z',
|
|
447
|
+
interval: 'day',
|
|
448
|
+
orgId: 'org_1',
|
|
449
|
+
to: '2026-01-02T00:00:00.000Z',
|
|
450
|
+
})
|
|
451
|
+
|
|
452
|
+
const query = String(fetch.mock.calls[0]![1]?.body)
|
|
453
|
+
// Org-wide term matches any project without a `project_id` predicate.
|
|
454
|
+
expect(query).toContain(`(org_id = 'org_1' AND key_environment = 'sandbox')`)
|
|
455
|
+
expect(query).toContain(`(project_id IS NULL AND key_id IN ('key_1')`)
|
|
456
|
+
expect(query).not.toContain(`project_id = 'prj`)
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
test.each(['production', 'sandbox'] as const)(
|
|
460
|
+
'readBillableCounts dedupes on request_id and gates %s correctly',
|
|
461
|
+
async (environment) => {
|
|
462
|
+
const fetch = vi
|
|
463
|
+
.fn<typeof globalThis.fetch>()
|
|
464
|
+
.mockResolvedValue(new Response(JSON.stringify({ data: [] }), { status: 200 }))
|
|
465
|
+
vi.stubGlobal('fetch', fetch)
|
|
466
|
+
|
|
467
|
+
await RequestEvents.readBillableCounts(Analytics.clickhouse(clickHouse), {
|
|
468
|
+
environment,
|
|
469
|
+
from: '2026-01-01T00:00:00.000Z',
|
|
470
|
+
to: '2026-01-01T12:00:00.000Z',
|
|
471
|
+
})
|
|
472
|
+
|
|
473
|
+
const query = String(fetch.mock.calls[0]![1]?.body)
|
|
474
|
+
// Deduped, never a raw count(), so queue retries never over-bill.
|
|
475
|
+
expect(query).toContain('uniqExact(request_id)')
|
|
476
|
+
expect(query).toContain(`principal_type = 'api_key'`)
|
|
477
|
+
expect(query).toContain(`key_environment = '${environment}'`)
|
|
478
|
+
// Sandbox rows bill only when billing was active at request time.
|
|
479
|
+
if (environment === 'sandbox') expect(query).toContain('billing_active = 1')
|
|
480
|
+
else expect(query).not.toContain('billing_active = 1')
|
|
481
|
+
},
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
test('maps grouped rows into the usage response', async () => {
|
|
485
|
+
const fetch = vi.fn<typeof globalThis.fetch>().mockImplementation(async (_url, init) => {
|
|
486
|
+
const sql = String(init?.body)
|
|
487
|
+
const data = (() => {
|
|
488
|
+
if (sql.includes('GROUP BY key_id'))
|
|
489
|
+
return [{ averageDurationMs: '12.3', errors: '1', key_id: 'key_1', requests: '10' }]
|
|
490
|
+
if (sql.includes('GROUP BY route'))
|
|
491
|
+
return [{ averageDurationMs: 12.3, errors: 1, requests: 10, route: '/v1/tokens' }]
|
|
492
|
+
if (sql.includes('GROUP BY status'))
|
|
493
|
+
return [
|
|
494
|
+
{ requests: 9, status: 200 },
|
|
495
|
+
{ requests: '1', status: '500' },
|
|
496
|
+
]
|
|
497
|
+
if (sql.includes('formatDateTime'))
|
|
498
|
+
return [{ errors: 1, requests: 10, time: '2026-01-01T00:00:00.000Z' }]
|
|
499
|
+
return [{ averageDurationMs: '12.3', errors: '1', requests: '10' }]
|
|
500
|
+
})()
|
|
501
|
+
return new Response(JSON.stringify({ data }), { status: 200 })
|
|
502
|
+
})
|
|
503
|
+
vi.stubGlobal('fetch', fetch)
|
|
504
|
+
|
|
505
|
+
const usage = await RequestEvents.readProjectUsage(Analytics.clickhouse(clickHouse), {
|
|
506
|
+
attributions: [{ projectId: 'prj_1' }],
|
|
507
|
+
from: '2026-01-01T00:00:00.000Z',
|
|
508
|
+
interval: 'day',
|
|
509
|
+
orgId: 'org_1',
|
|
510
|
+
to: '2026-01-02T00:00:00.000Z',
|
|
511
|
+
})
|
|
512
|
+
|
|
513
|
+
expect(usage).toEqual({
|
|
514
|
+
byKey: [{ apiKeyId: 'key_1', averageDurationMs: 12.3, errors: 1, requests: 10 }],
|
|
515
|
+
byRoute: [{ averageDurationMs: 12.3, errors: 1, requests: 10, route: '/v1/tokens' }],
|
|
516
|
+
byStatus: [
|
|
517
|
+
{ requests: 9, status: 200 },
|
|
518
|
+
{ requests: 1, status: 500 },
|
|
519
|
+
],
|
|
520
|
+
from: '2026-01-01T00:00:00.000Z',
|
|
521
|
+
interval: 'day',
|
|
522
|
+
series: [{ errors: 1, requests: 10, time: '2026-01-01T00:00:00.000Z' }],
|
|
523
|
+
to: '2026-01-02T00:00:00.000Z',
|
|
524
|
+
totals: { averageDurationMs: 12.3, errors: 1, requests: 10 },
|
|
525
|
+
})
|
|
526
|
+
})
|
|
527
|
+
})
|