tapimo 0.0.2 → 0.2.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.
Files changed (517) hide show
  1. package/README.md +38 -16
  2. package/dist/ApiKey.d.ts +14 -11
  3. package/dist/ApiKey.d.ts.map +1 -1
  4. package/dist/ApiKey.js +11 -12
  5. package/dist/ApiKey.js.map +1 -1
  6. package/dist/ApiKeys.d.ts +207 -0
  7. package/dist/ApiKeys.d.ts.map +1 -0
  8. package/dist/ApiKeys.js +282 -0
  9. package/dist/ApiKeys.js.map +1 -0
  10. package/dist/App.d.ts +6771 -3819
  11. package/dist/App.d.ts.map +1 -1
  12. package/dist/App.js +145 -317
  13. package/dist/App.js.map +1 -1
  14. package/dist/Handler.d.ts +86 -0
  15. package/dist/Handler.d.ts.map +1 -0
  16. package/dist/Handler.js +83 -0
  17. package/dist/Handler.js.map +1 -0
  18. package/dist/Scope.d.ts +14 -4
  19. package/dist/Scope.d.ts.map +1 -1
  20. package/dist/Scope.js +16 -4
  21. package/dist/Scope.js.map +1 -1
  22. package/dist/Webhooks.d.ts +5 -7
  23. package/dist/Webhooks.d.ts.map +1 -1
  24. package/dist/Webhooks.js +11 -4
  25. package/dist/Webhooks.js.map +1 -1
  26. package/dist/admin/Access.d.ts +1 -3
  27. package/dist/admin/Access.d.ts.map +1 -1
  28. package/dist/admin/Access.js +1 -3
  29. package/dist/admin/Access.js.map +1 -1
  30. package/dist/admin/App.d.ts +167 -205
  31. package/dist/admin/App.d.ts.map +1 -1
  32. package/dist/admin/App.js +2 -4
  33. package/dist/admin/App.js.map +1 -1
  34. package/dist/admin/apps/api-keys.d.ts +105 -5
  35. package/dist/admin/apps/api-keys.d.ts.map +1 -1
  36. package/dist/admin/apps/api-keys.js +75 -9
  37. package/dist/admin/apps/api-keys.js.map +1 -1
  38. package/dist/admin/apps/scopes.d.ts +6 -0
  39. package/dist/admin/apps/scopes.d.ts.map +1 -1
  40. package/dist/admin/apps/verified-tokens.d.ts +35 -149
  41. package/dist/admin/apps/verified-tokens.d.ts.map +1 -1
  42. package/dist/admin/apps/verified-tokens.js +18 -39
  43. package/dist/admin/apps/verified-tokens.js.map +1 -1
  44. package/dist/admin/ui.generated.d.ts +1 -1
  45. package/dist/admin/ui.generated.js +1 -1
  46. package/dist/apps/data/App.d.ts +19176 -0
  47. package/dist/apps/data/App.d.ts.map +1 -0
  48. package/dist/apps/data/App.js +236 -0
  49. package/dist/apps/data/App.js.map +1 -0
  50. package/dist/apps/data/index.d.ts +3 -0
  51. package/dist/apps/data/index.d.ts.map +1 -0
  52. package/dist/apps/data/index.js +3 -0
  53. package/dist/apps/data/index.js.map +1 -0
  54. package/dist/apps/{activities.d.ts → data/routes/activities.d.ts} +32 -32
  55. package/dist/apps/{activities.d.ts.map → data/routes/activities.d.ts.map} +1 -1
  56. package/dist/apps/{activities.js → data/routes/activities.js} +13 -13
  57. package/dist/apps/data/routes/activities.js.map +1 -0
  58. package/dist/apps/{addresses.d.ts → data/routes/addresses.d.ts} +22 -22
  59. package/dist/apps/{addresses.d.ts.map → data/routes/addresses.d.ts.map} +1 -1
  60. package/dist/apps/{addresses.js → data/routes/addresses.js} +5 -5
  61. package/dist/apps/data/routes/addresses.js.map +1 -0
  62. package/dist/apps/{balances.d.ts → data/routes/balances.d.ts} +49 -49
  63. package/dist/apps/data/routes/balances.d.ts.map +1 -0
  64. package/dist/apps/{balances.js → data/routes/balances.js} +42 -11
  65. package/dist/apps/data/routes/balances.js.map +1 -0
  66. package/dist/apps/{blocks.d.ts → data/routes/blocks.d.ts} +47 -47
  67. package/dist/apps/data/routes/blocks.d.ts.map +1 -0
  68. package/dist/apps/{blocks.js → data/routes/blocks.js} +13 -13
  69. package/dist/apps/data/routes/blocks.js.map +1 -0
  70. package/dist/apps/{coingecko.d.ts → data/routes/coingecko.d.ts} +183 -183
  71. package/dist/apps/data/routes/coingecko.d.ts.map +1 -0
  72. package/dist/apps/{coingecko.js → data/routes/coingecko.js} +13 -13
  73. package/dist/apps/data/routes/coingecko.js.map +1 -0
  74. package/dist/apps/{exchanges.d.ts → data/routes/exchanges.d.ts} +460 -460
  75. package/dist/apps/data/routes/exchanges.d.ts.map +1 -0
  76. package/dist/apps/{exchanges.js → data/routes/exchanges.js} +19 -19
  77. package/dist/apps/data/routes/exchanges.js.map +1 -0
  78. package/dist/apps/{fee-amm.d.ts → data/routes/fee-amm.d.ts} +94 -94
  79. package/dist/apps/data/routes/fee-amm.d.ts.map +1 -0
  80. package/dist/apps/{fee-amm.js → data/routes/fee-amm.js} +17 -17
  81. package/dist/apps/data/routes/fee-amm.js.map +1 -0
  82. package/dist/apps/{indexer.d.ts → data/routes/indexer.d.ts} +4 -4
  83. package/dist/apps/data/routes/indexer.d.ts.map +1 -0
  84. package/dist/apps/{indexer.js → data/routes/indexer.js} +13 -9
  85. package/dist/apps/data/routes/indexer.js.map +1 -0
  86. package/dist/apps/{receipts.d.ts → data/routes/receipts.d.ts} +6 -6
  87. package/dist/apps/data/routes/receipts.d.ts.map +1 -0
  88. package/dist/apps/{receipts.js → data/routes/receipts.js} +12 -12
  89. package/dist/apps/data/routes/receipts.js.map +1 -0
  90. package/dist/apps/{rpc.d.ts → data/routes/rpc.d.ts} +4 -4
  91. package/dist/apps/data/routes/rpc.d.ts.map +1 -0
  92. package/dist/apps/{rpc.js → data/routes/rpc.js} +6 -6
  93. package/dist/apps/data/routes/rpc.js.map +1 -0
  94. package/dist/apps/{tokenlist.d.ts → data/routes/tokenlist.d.ts} +4 -4
  95. package/dist/apps/data/routes/tokenlist.d.ts.map +1 -0
  96. package/dist/apps/{tokenlist.js → data/routes/tokenlist.js} +8 -8
  97. package/dist/apps/data/routes/tokenlist.js.map +1 -0
  98. package/dist/apps/{tokens.d.ts → data/routes/tokens.d.ts} +11 -11
  99. package/dist/apps/data/routes/tokens.d.ts.map +1 -0
  100. package/dist/apps/{tokens.js → data/routes/tokens.js} +19 -19
  101. package/dist/apps/data/routes/tokens.js.map +1 -0
  102. package/dist/apps/{transactions.d.ts → data/routes/transactions.d.ts} +288 -288
  103. package/dist/apps/data/routes/transactions.d.ts.map +1 -0
  104. package/dist/apps/{transactions.js → data/routes/transactions.js} +13 -13
  105. package/dist/apps/data/routes/transactions.js.map +1 -0
  106. package/dist/apps/{transfers.d.ts → data/routes/transfers.d.ts} +35 -35
  107. package/dist/apps/data/routes/transfers.d.ts.map +1 -0
  108. package/dist/apps/{transfers.js → data/routes/transfers.js} +13 -13
  109. package/dist/apps/data/routes/transfers.js.map +1 -0
  110. package/dist/apps/{verified-tokens.d.ts → data/routes/verified-tokens.d.ts} +42 -42
  111. package/dist/apps/data/routes/verified-tokens.d.ts.map +1 -0
  112. package/dist/apps/{verified-tokens.js → data/routes/verified-tokens.js} +9 -9
  113. package/dist/apps/data/routes/verified-tokens.js.map +1 -0
  114. package/dist/apps/{webhooks.d.ts → data/routes/webhooks.d.ts} +66 -63
  115. package/dist/apps/{webhooks.d.ts.map → data/routes/webhooks.d.ts.map} +1 -1
  116. package/dist/apps/{webhooks.js → data/routes/webhooks.js} +67 -59
  117. package/dist/apps/data/routes/webhooks.js.map +1 -0
  118. package/dist/apps/docs/App.d.ts +27 -0
  119. package/dist/apps/docs/App.d.ts.map +1 -0
  120. package/dist/apps/docs/App.js +122 -0
  121. package/dist/apps/docs/App.js.map +1 -0
  122. package/dist/{internal/OpenApi.fonts.d.ts → apps/docs/fonts.d.ts} +1 -1
  123. package/dist/apps/docs/fonts.d.ts.map +1 -0
  124. package/dist/{internal/OpenApi.fonts.js → apps/docs/fonts.js} +1 -1
  125. package/dist/apps/docs/fonts.js.map +1 -0
  126. package/dist/apps/docs/index.d.ts +2 -0
  127. package/dist/apps/docs/index.d.ts.map +1 -0
  128. package/dist/apps/docs/index.js +2 -0
  129. package/dist/apps/docs/index.js.map +1 -0
  130. package/dist/{internal/OpenApi.logo.d.ts → apps/docs/logo.d.ts} +1 -1
  131. package/dist/apps/docs/logo.d.ts.map +1 -0
  132. package/dist/{internal/OpenApi.logo.js → apps/docs/logo.js} +1 -1
  133. package/dist/apps/docs/logo.js.map +1 -0
  134. package/dist/apps/index.d.ts +4 -0
  135. package/dist/apps/index.d.ts.map +1 -0
  136. package/dist/apps/index.js +4 -0
  137. package/dist/apps/index.js.map +1 -0
  138. package/dist/apps/metadata.d.ts +7 -0
  139. package/dist/apps/metadata.d.ts.map +1 -0
  140. package/dist/apps/metadata.js +15 -0
  141. package/dist/apps/metadata.js.map +1 -0
  142. package/dist/apps/platform/App.d.ts +2985 -0
  143. package/dist/apps/platform/App.d.ts.map +1 -0
  144. package/dist/apps/platform/App.js +74 -0
  145. package/dist/apps/platform/App.js.map +1 -0
  146. package/dist/apps/platform/index.d.ts +2 -0
  147. package/dist/apps/platform/index.d.ts.map +1 -0
  148. package/dist/apps/platform/index.js +2 -0
  149. package/dist/apps/platform/index.js.map +1 -0
  150. package/dist/apps/platform/routes/api-keys.d.ts +681 -0
  151. package/dist/apps/platform/routes/api-keys.d.ts.map +1 -0
  152. package/dist/apps/platform/routes/api-keys.js +328 -0
  153. package/dist/apps/platform/routes/api-keys.js.map +1 -0
  154. package/dist/apps/platform/routes/invitations.d.ts +733 -0
  155. package/dist/apps/platform/routes/invitations.d.ts.map +1 -0
  156. package/dist/apps/platform/routes/invitations.js +413 -0
  157. package/dist/apps/platform/routes/invitations.js.map +1 -0
  158. package/dist/apps/platform/routes/me.d.ts +95 -0
  159. package/dist/apps/platform/routes/me.d.ts.map +1 -0
  160. package/dist/apps/platform/routes/me.js +81 -0
  161. package/dist/apps/platform/routes/me.js.map +1 -0
  162. package/dist/apps/platform/routes/members.d.ts +554 -0
  163. package/dist/apps/platform/routes/members.d.ts.map +1 -0
  164. package/dist/apps/platform/routes/members.js +251 -0
  165. package/dist/apps/platform/routes/members.js.map +1 -0
  166. package/dist/apps/platform/routes/orgs.d.ts +582 -0
  167. package/dist/apps/platform/routes/orgs.d.ts.map +1 -0
  168. package/dist/apps/platform/routes/orgs.js +265 -0
  169. package/dist/apps/platform/routes/orgs.js.map +1 -0
  170. package/dist/apps/platform/routes/projects.d.ts +740 -0
  171. package/dist/apps/platform/routes/projects.d.ts.map +1 -0
  172. package/dist/apps/platform/routes/projects.js +286 -0
  173. package/dist/apps/platform/routes/projects.js.map +1 -0
  174. package/dist/apps/relay/App.d.ts +41 -0
  175. package/dist/apps/relay/App.d.ts.map +1 -0
  176. package/dist/apps/relay/App.js +103 -0
  177. package/dist/apps/relay/App.js.map +1 -0
  178. package/dist/apps/relay/Sponsorships.d.ts +107 -0
  179. package/dist/apps/relay/Sponsorships.d.ts.map +1 -0
  180. package/dist/apps/relay/Sponsorships.js +193 -0
  181. package/dist/apps/relay/Sponsorships.js.map +1 -0
  182. package/dist/apps/relay/index.d.ts +3 -0
  183. package/dist/apps/relay/index.d.ts.map +1 -0
  184. package/dist/apps/relay/index.js +3 -0
  185. package/dist/apps/relay/index.js.map +1 -0
  186. package/dist/{Cli.d.ts → cli/Cli.d.ts} +13 -2
  187. package/dist/cli/Cli.d.ts.map +1 -0
  188. package/dist/cli/Cli.js +19 -0
  189. package/dist/cli/Cli.js.map +1 -0
  190. package/dist/cli/bin.d.ts +3 -0
  191. package/dist/cli/bin.d.ts.map +1 -0
  192. package/dist/cli/bin.js +4 -0
  193. package/dist/cli/bin.js.map +1 -0
  194. package/dist/cli/commands/admin.d.ts +15 -0
  195. package/dist/cli/commands/admin.d.ts.map +1 -0
  196. package/dist/cli/commands/admin.js +60 -0
  197. package/dist/cli/commands/admin.js.map +1 -0
  198. package/dist/cloudflare.d.ts +7 -0
  199. package/dist/cloudflare.d.ts.map +1 -1
  200. package/dist/cloudflare.js +9 -0
  201. package/dist/cloudflare.js.map +1 -1
  202. package/dist/db/Db.d.ts +113 -0
  203. package/dist/db/Db.d.ts.map +1 -0
  204. package/dist/db/Db.js +402 -0
  205. package/dist/db/Db.js.map +1 -0
  206. package/dist/db/Schema.d.ts +168 -0
  207. package/dist/db/Schema.d.ts.map +1 -0
  208. package/dist/db/Schema.js +229 -0
  209. package/dist/db/Schema.js.map +1 -0
  210. package/dist/db/tables/invitations.d.ts +84 -0
  211. package/dist/db/tables/invitations.d.ts.map +1 -0
  212. package/dist/db/tables/invitations.js +165 -0
  213. package/dist/db/tables/invitations.js.map +1 -0
  214. package/dist/db/tables/memberships.d.ts +108 -0
  215. package/dist/db/tables/memberships.d.ts.map +1 -0
  216. package/dist/db/tables/memberships.js +153 -0
  217. package/dist/db/tables/memberships.js.map +1 -0
  218. package/dist/db/tables/organizations.d.ts +123 -0
  219. package/dist/db/tables/organizations.d.ts.map +1 -0
  220. package/dist/db/tables/organizations.js +170 -0
  221. package/dist/db/tables/organizations.js.map +1 -0
  222. package/dist/db/tables/projects.d.ts +65 -0
  223. package/dist/db/tables/projects.d.ts.map +1 -0
  224. package/dist/db/tables/projects.js +75 -0
  225. package/dist/db/tables/projects.js.map +1 -0
  226. package/dist/db/tables/sponsoredTransactions.d.ts +120 -0
  227. package/dist/db/tables/sponsoredTransactions.d.ts.map +1 -0
  228. package/dist/db/tables/sponsoredTransactions.js +161 -0
  229. package/dist/db/tables/sponsoredTransactions.js.map +1 -0
  230. package/dist/db/tables/users.d.ts +48 -0
  231. package/dist/db/tables/users.d.ts.map +1 -0
  232. package/dist/db/tables/users.js +65 -0
  233. package/dist/db/tables/users.js.map +1 -0
  234. package/dist/db/tables/verifiedTokens.d.ts +53 -0
  235. package/dist/db/tables/verifiedTokens.d.ts.map +1 -0
  236. package/dist/db/tables/verifiedTokens.js +74 -0
  237. package/dist/db/tables/verifiedTokens.js.map +1 -0
  238. package/dist/db/tables/webhookDeliveries.d.ts +71 -0
  239. package/dist/db/tables/webhookDeliveries.d.ts.map +1 -0
  240. package/dist/db/tables/webhookDeliveries.js +119 -0
  241. package/dist/db/tables/webhookDeliveries.js.map +1 -0
  242. package/dist/db/tables/webhookSubscriptions.d.ts +158 -0
  243. package/dist/db/tables/webhookSubscriptions.d.ts.map +1 -0
  244. package/dist/db/tables/webhookSubscriptions.js +272 -0
  245. package/dist/db/tables/webhookSubscriptions.js.map +1 -0
  246. package/dist/handlers/internal/executionError.d.ts +25 -0
  247. package/dist/handlers/internal/executionError.d.ts.map +1 -0
  248. package/dist/handlers/internal/executionError.js +186 -0
  249. package/dist/handlers/internal/executionError.js.map +1 -0
  250. package/dist/handlers/internal/multisig.d.ts +233 -0
  251. package/dist/handlers/internal/multisig.d.ts.map +1 -0
  252. package/dist/handlers/internal/multisig.js +542 -0
  253. package/dist/handlers/internal/multisig.js.map +1 -0
  254. package/dist/handlers/internal/requestListener.d.ts +124 -0
  255. package/dist/handlers/internal/requestListener.d.ts.map +1 -0
  256. package/dist/handlers/internal/requestListener.js +173 -0
  257. package/dist/handlers/internal/requestListener.js.map +1 -0
  258. package/dist/handlers/internal/sponsorship.d.ts +113 -0
  259. package/dist/handlers/internal/sponsorship.d.ts.map +1 -0
  260. package/dist/handlers/internal/sponsorship.js +128 -0
  261. package/dist/handlers/internal/sponsorship.js.map +1 -0
  262. package/dist/handlers/internal/types.d.ts +284 -0
  263. package/dist/handlers/internal/types.d.ts.map +1 -0
  264. package/dist/handlers/internal/types.js +2 -0
  265. package/dist/handlers/internal/types.js.map +1 -0
  266. package/dist/handlers/internal/utils.d.ts +34 -0
  267. package/dist/handlers/internal/utils.d.ts.map +1 -0
  268. package/dist/handlers/internal/utils.js +131 -0
  269. package/dist/handlers/internal/utils.js.map +1 -0
  270. package/dist/handlers/relay.d.ts +123 -0
  271. package/dist/handlers/relay.d.ts.map +1 -0
  272. package/dist/handlers/relay.js +1278 -0
  273. package/dist/handlers/relay.js.map +1 -0
  274. package/dist/index.d.ts +4 -2
  275. package/dist/index.d.ts.map +1 -1
  276. package/dist/index.js +4 -2
  277. package/dist/index.js.map +1 -1
  278. package/dist/internal/Auth.d.ts +224 -16
  279. package/dist/internal/Auth.d.ts.map +1 -1
  280. package/dist/internal/Auth.js +572 -33
  281. package/dist/internal/Auth.js.map +1 -1
  282. package/dist/internal/Log.d.ts +7 -3
  283. package/dist/internal/Log.d.ts.map +1 -1
  284. package/dist/internal/Log.js +4 -0
  285. package/dist/internal/Log.js.map +1 -1
  286. package/dist/internal/OpenApi.d.ts +0 -19
  287. package/dist/internal/OpenApi.d.ts.map +1 -1
  288. package/dist/internal/OpenApi.js +0 -57
  289. package/dist/internal/OpenApi.js.map +1 -1
  290. package/dist/internal/RpcSchema.d.ts +10 -0
  291. package/dist/internal/RpcSchema.d.ts.map +1 -0
  292. package/dist/internal/RpcSchema.js +2 -0
  293. package/dist/internal/RpcSchema.js.map +1 -0
  294. package/dist/internal/Store.d.ts +49 -4
  295. package/dist/internal/Store.d.ts.map +1 -1
  296. package/dist/internal/Store.js +81 -5
  297. package/dist/internal/Store.js.map +1 -1
  298. package/dist/internal/VerifiedTokens.d.ts +15 -34
  299. package/dist/internal/VerifiedTokens.d.ts.map +1 -1
  300. package/dist/internal/VerifiedTokens.js +115 -159
  301. package/dist/internal/VerifiedTokens.js.map +1 -1
  302. package/dist/internal/Viem.d.ts +84 -0
  303. package/dist/internal/Viem.d.ts.map +1 -1
  304. package/dist/internal/Webhooks.d.ts +50 -36
  305. package/dist/internal/Webhooks.d.ts.map +1 -1
  306. package/dist/internal/Webhooks.js +92 -205
  307. package/dist/internal/Webhooks.js.map +1 -1
  308. package/package.json +37 -6
  309. package/src/ApiKey.test.ts +3 -3
  310. package/src/ApiKey.ts +11 -12
  311. package/src/ApiKeys.test.ts +278 -0
  312. package/src/ApiKeys.ts +358 -0
  313. package/src/App.test-d.ts +1 -1
  314. package/src/App.test.ts +40508 -19083
  315. package/src/App.ts +239 -416
  316. package/src/Client.test-d.ts +307 -16
  317. package/src/Handler.ts +154 -0
  318. package/src/Scope.ts +17 -4
  319. package/src/Webhooks.test.ts +8 -7
  320. package/src/Webhooks.ts +13 -7
  321. package/src/admin/Access.ts +1 -3
  322. package/src/admin/App.ts +19 -24
  323. package/src/admin/apps/api-keys.test.ts +70 -18
  324. package/src/admin/apps/api-keys.ts +92 -9
  325. package/src/admin/apps/scopes.test.ts +8 -0
  326. package/src/admin/apps/verified-tokens.test.ts +3 -30
  327. package/src/admin/apps/verified-tokens.ts +18 -37
  328. package/src/admin/ui.generated.ts +1 -1
  329. package/src/apps/composition.test.ts +66 -0
  330. package/src/apps/data/App.ts +295 -0
  331. package/src/apps/data/index.ts +2 -0
  332. package/src/apps/{activities.test.ts → data/routes/activities.test.ts} +3 -3
  333. package/src/apps/{activities.ts → data/routes/activities.ts} +15 -15
  334. package/src/apps/{addresses.ts → data/routes/addresses.ts} +6 -6
  335. package/src/apps/{balances.test.ts → data/routes/balances.test.ts} +6 -5
  336. package/src/apps/{balances.ts → data/routes/balances.ts} +46 -12
  337. package/src/apps/{blocks.test.ts → data/routes/blocks.test.ts} +4 -4
  338. package/src/apps/{blocks.ts → data/routes/blocks.ts} +14 -14
  339. package/src/apps/{coingecko.test.ts → data/routes/coingecko.test.ts} +2 -2
  340. package/src/apps/{coingecko.ts → data/routes/coingecko.ts} +14 -14
  341. package/src/apps/{exchanges.test.ts → data/routes/exchanges.test.ts} +2 -2
  342. package/src/apps/{exchanges.ts → data/routes/exchanges.ts} +20 -20
  343. package/src/apps/{fee-amm.test.ts → data/routes/fee-amm.test.ts} +3 -3
  344. package/src/apps/{fee-amm.ts → data/routes/fee-amm.ts} +18 -18
  345. package/src/apps/{indexer.test.ts → data/routes/indexer.test.ts} +27 -6
  346. package/src/apps/{indexer.ts → data/routes/indexer.ts} +13 -10
  347. package/src/apps/{receipts.test.ts → data/routes/receipts.test.ts} +4 -4
  348. package/src/apps/{receipts.ts → data/routes/receipts.ts} +13 -13
  349. package/src/apps/{rpc.test.ts → data/routes/rpc.test.ts} +142 -13
  350. package/src/apps/{rpc.ts → data/routes/rpc.ts} +7 -7
  351. package/src/apps/{tokenlist.test.ts → data/routes/tokenlist.test.ts} +8 -10
  352. package/src/apps/{tokenlist.ts → data/routes/tokenlist.ts} +9 -9
  353. package/src/apps/{tokens.test.ts → data/routes/tokens.test.ts} +6 -5
  354. package/src/apps/{tokens.ts → data/routes/tokens.ts} +20 -20
  355. package/src/apps/{transactions.test.ts → data/routes/transactions.test.ts} +4 -4
  356. package/src/apps/{transactions.ts → data/routes/transactions.ts} +15 -15
  357. package/src/apps/{transfers.test.ts → data/routes/transfers.test.ts} +3 -3
  358. package/src/apps/{transfers.ts → data/routes/transfers.ts} +15 -15
  359. package/src/apps/{verified-tokens.test.ts → data/routes/verified-tokens.test.ts} +27 -15
  360. package/src/apps/{verified-tokens.ts → data/routes/verified-tokens.ts} +10 -10
  361. package/src/apps/{webhooks.test.ts → data/routes/webhooks.test.ts} +137 -150
  362. package/src/apps/{webhooks.ts → data/routes/webhooks.ts} +83 -81
  363. package/src/apps/docs/App.ts +136 -0
  364. package/src/apps/docs/index.ts +1 -0
  365. package/src/apps/index.ts +3 -0
  366. package/src/apps/metadata.ts +23 -0
  367. package/src/apps/platform/App.ts +130 -0
  368. package/src/apps/platform/index.ts +1 -0
  369. package/src/apps/platform/routes/api-keys.test.ts +330 -0
  370. package/src/apps/platform/routes/api-keys.ts +427 -0
  371. package/src/apps/platform/routes/invitations.test.ts +361 -0
  372. package/src/apps/platform/routes/invitations.ts +519 -0
  373. package/src/apps/platform/routes/me.test.ts +121 -0
  374. package/src/apps/platform/routes/me.ts +106 -0
  375. package/src/apps/platform/routes/members.test.ts +195 -0
  376. package/src/apps/platform/routes/members.ts +313 -0
  377. package/src/apps/platform/routes/orgs.test.ts +313 -0
  378. package/src/apps/platform/routes/orgs.ts +343 -0
  379. package/src/apps/platform/routes/projects.test.ts +181 -0
  380. package/src/apps/platform/routes/projects.ts +367 -0
  381. package/src/apps/relay/App.test.ts +484 -0
  382. package/src/apps/relay/App.ts +128 -0
  383. package/src/apps/relay/Sponsorships.test.ts +375 -0
  384. package/src/apps/relay/Sponsorships.ts +305 -0
  385. package/src/apps/relay/index.ts +2 -0
  386. package/src/{Cli.test.ts → cli/Cli.test.ts} +10 -9
  387. package/src/{Cli.ts → cli/Cli.ts} +16 -9
  388. package/src/cli/bin.ts +4 -0
  389. package/src/cli/commands/admin.test.ts +71 -0
  390. package/src/cli/commands/admin.ts +60 -0
  391. package/src/cloudflare.ts +10 -0
  392. package/src/db/Db.test.ts +84 -0
  393. package/src/db/Db.ts +542 -0
  394. package/src/db/Schema.ts +301 -0
  395. package/src/db/tables/invitations.ts +198 -0
  396. package/src/db/tables/memberships.ts +208 -0
  397. package/src/db/tables/organizations.test.ts +160 -0
  398. package/src/db/tables/organizations.ts +232 -0
  399. package/src/db/tables/projects.ts +107 -0
  400. package/src/db/tables/sponsoredTransactions.test.ts +218 -0
  401. package/src/db/tables/sponsoredTransactions.ts +236 -0
  402. package/src/db/tables/users.ts +85 -0
  403. package/src/db/tables/verifiedTokens.ts +111 -0
  404. package/src/db/tables/webhookDeliveries.ts +159 -0
  405. package/src/db/tables/webhookSubscriptions.ts +358 -0
  406. package/src/handlers/internal/executionError.ts +207 -0
  407. package/src/handlers/internal/multisig.test.ts +818 -0
  408. package/src/handlers/internal/multisig.ts +823 -0
  409. package/src/handlers/internal/requestListener.ts +273 -0
  410. package/src/handlers/internal/sponsorship.ts +245 -0
  411. package/src/handlers/internal/types.ts +378 -0
  412. package/src/handlers/internal/utils.ts +153 -0
  413. package/src/handlers/relay.test.ts +2035 -0
  414. package/src/handlers/relay.ts +1623 -0
  415. package/src/index.ts +4 -2
  416. package/src/internal/Auth.test.ts +337 -21
  417. package/src/internal/Auth.ts +783 -44
  418. package/src/internal/Cursor.test.ts +3 -2
  419. package/src/internal/Log.test.ts +1 -1
  420. package/src/internal/Log.ts +11 -3
  421. package/src/internal/MetricSink.ts +1 -1
  422. package/src/internal/OpenApi.ts +0 -59
  423. package/src/internal/RateLimit.test.ts +1 -1
  424. package/src/internal/RpcSchema.ts +10 -0
  425. package/src/internal/Store.test.ts +150 -10
  426. package/src/internal/Store.ts +136 -11
  427. package/src/internal/Tidx.local.test.ts +1 -1
  428. package/src/internal/VerifiedTokens.test.ts +99 -115
  429. package/src/internal/VerifiedTokens.ts +123 -175
  430. package/src/internal/WebhookDestination.test.ts +1 -1
  431. package/src/internal/Webhooks.test.ts +111 -111
  432. package/src/internal/Webhooks.ts +103 -221
  433. package/dist/ApiKeySource.d.ts +0 -166
  434. package/dist/ApiKeySource.d.ts.map +0 -1
  435. package/dist/ApiKeySource.js +0 -234
  436. package/dist/ApiKeySource.js.map +0 -1
  437. package/dist/Cli.d.ts.map +0 -1
  438. package/dist/Cli.js +0 -13
  439. package/dist/Cli.js.map +0 -1
  440. package/dist/apps/activities.js.map +0 -1
  441. package/dist/apps/addresses.js.map +0 -1
  442. package/dist/apps/balances.d.ts.map +0 -1
  443. package/dist/apps/balances.js.map +0 -1
  444. package/dist/apps/blocks.d.ts.map +0 -1
  445. package/dist/apps/blocks.js.map +0 -1
  446. package/dist/apps/coingecko.d.ts.map +0 -1
  447. package/dist/apps/coingecko.js.map +0 -1
  448. package/dist/apps/exchanges.d.ts.map +0 -1
  449. package/dist/apps/exchanges.js.map +0 -1
  450. package/dist/apps/fee-amm.d.ts.map +0 -1
  451. package/dist/apps/fee-amm.js.map +0 -1
  452. package/dist/apps/indexer.d.ts.map +0 -1
  453. package/dist/apps/indexer.js.map +0 -1
  454. package/dist/apps/receipts.d.ts.map +0 -1
  455. package/dist/apps/receipts.js.map +0 -1
  456. package/dist/apps/rpc.d.ts.map +0 -1
  457. package/dist/apps/rpc.js.map +0 -1
  458. package/dist/apps/tokenlist.d.ts.map +0 -1
  459. package/dist/apps/tokenlist.js.map +0 -1
  460. package/dist/apps/tokens.d.ts.map +0 -1
  461. package/dist/apps/tokens.js.map +0 -1
  462. package/dist/apps/transactions.d.ts.map +0 -1
  463. package/dist/apps/transactions.js.map +0 -1
  464. package/dist/apps/transfers.d.ts.map +0 -1
  465. package/dist/apps/transfers.js.map +0 -1
  466. package/dist/apps/verified-tokens.d.ts.map +0 -1
  467. package/dist/apps/verified-tokens.js.map +0 -1
  468. package/dist/apps/webhooks.js.map +0 -1
  469. package/dist/internal/OpenApi.fonts.d.ts.map +0 -1
  470. package/dist/internal/OpenApi.fonts.js.map +0 -1
  471. package/dist/internal/OpenApi.logo.d.ts.map +0 -1
  472. package/dist/internal/OpenApi.logo.js.map +0 -1
  473. package/seeds/31318/icons/0x20c0000000000000000000000000000000000000.svg +0 -1
  474. package/seeds/31318/icons/0x20c0000000000000000000000000000000000001.svg +0 -1
  475. package/seeds/31318/icons/0x20c0000000000000000000000000000000000002.svg +0 -1
  476. package/seeds/31318/icons/0x20c0000000000000000000000000000000000003.svg +0 -1
  477. package/seeds/31318/verified-tokens.json +0 -30
  478. package/seeds/4217/icons/0x20c0000000000000000000000000000000000000.svg +0 -25
  479. package/seeds/4217/icons/0x20c000000000000000000000048c8f36df1c9a4a.svg +0 -1
  480. package/seeds/4217/icons/0x20c0000000000000000000000520792dcccccccc.svg +0 -1
  481. package/seeds/4217/icons/0x20c0000000000000000000000a6da882d075a4c3.svg +0 -4
  482. package/seeds/4217/icons/0x20c000000000000000000000111111111e910f0f.svg +0 -30
  483. package/seeds/4217/icons/0x20c00000000000000000000014f22ca97301eb73.svg +0 -1
  484. package/seeds/4217/icons/0x20c0000000000000000000001621e21f71cf12fb.svg +0 -1
  485. package/seeds/4217/icons/0x20c0000000000000000000002f52d5cc21a3207b.svg +0 -1
  486. package/seeds/4217/icons/0x20c0000000000000000000003158081efd85bfc2.svg +0 -11
  487. package/seeds/4217/icons/0x20c0000000000000000000003554d28269e0f3c2.svg +0 -1
  488. package/seeds/4217/icons/0x20c000000000000000000000383a23bacb546ab9.svg +0 -1
  489. package/seeds/4217/icons/0x20c00000000000000000000042109aef2f8b28e1.png +0 -0
  490. package/seeds/4217/icons/0x20c0000000000000000000005c0bac7cef389a11.svg +0 -1
  491. package/seeds/4217/icons/0x20c0000000000000000000006fd9a167923ba194.png +0 -0
  492. package/seeds/4217/icons/0x20c0000000000000000000007f7ba549dd0251b9.svg +0 -1
  493. package/seeds/4217/icons/0x20c0000000000000000000008191667423f70e67.svg +0 -5
  494. package/seeds/4217/icons/0x20c0000000000000000000008ee4fcff88888888.svg +0 -1
  495. package/seeds/4217/icons/0x20c0000000000000000000009a4a4b17e0dc6651.svg +0 -1
  496. package/seeds/4217/icons/0x20c000000000000000000000ab02d39df30bd17e.svg +0 -1
  497. package/seeds/4217/icons/0x20c000000000000000000000ae247a1130450f09.svg +0 -1
  498. package/seeds/4217/icons/0x20c000000000000000000000aeed2ec36a54d0e5.svg +0 -1
  499. package/seeds/4217/icons/0x20c000000000000000000000b9537d11c60e8b50.svg +0 -1
  500. package/seeds/4217/icons/0x20c000000000000000000000bd95bfb69fbe6ce3.svg +0 -1
  501. package/seeds/4217/icons/0x20c000000000000000000000c412ec89d0c08be5.svg +0 -1
  502. package/seeds/4217/icons/0x20c000000000000000000000f047dd7018e50367.png +0 -0
  503. package/seeds/4217/verified-tokens.json +0 -177
  504. package/seeds/42431/icons/0x20c0000000000000000000000000000000000000.svg +0 -25
  505. package/seeds/42431/icons/0x20c0000000000000000000000000000000000001.svg +0 -1
  506. package/seeds/42431/icons/0x20c0000000000000000000000000000000000002.svg +0 -1
  507. package/seeds/42431/icons/0x20c0000000000000000000000000000000000003.svg +0 -1
  508. package/seeds/42431/icons/0x20c0000000000000000000009e8d7eb59b783726.svg +0 -1
  509. package/seeds/42431/icons/0x20c000000000000000000000d72572838bbee59c.svg +0 -1
  510. package/seeds/42431/verified-tokens.json +0 -44
  511. package/seeds/openrpc/README.md +0 -27
  512. package/seeds/openrpc/execution-apis.json +0 -8989
  513. package/src/ApiKeySource.test-d.ts +0 -11
  514. package/src/ApiKeySource.test.ts +0 -295
  515. package/src/ApiKeySource.ts +0 -303
  516. /package/src/{internal/OpenApi.fonts.ts → apps/docs/fonts.ts} +0 -0
  517. /package/src/{internal/OpenApi.logo.ts → apps/docs/logo.ts} +0 -0
@@ -0,0 +1,301 @@
1
+ import * as z from 'zod/mini'
2
+
3
+ import type * as Webhooks from '../internal/Webhooks.js'
4
+
5
+ // Row schemas for database tables (`zod/mini`), the source of truth each
6
+ // `tables/` module derives its `Table` type from. Nullable fields map to
7
+ // nullable columns; the domain layer converts `null` back to absent fields.
8
+ // Domain-owned unions and jsonb values stay typed by their owning module via
9
+ // `z.custom` (type-only imports) so the two cannot drift.
10
+
11
+ /** A pending, expiring offer of organization membership. */
12
+ export const Invitation = z.object({
13
+ acceptedAt: z
14
+ .nullable(z.string())
15
+ .check(z.describe('When the invitation was accepted (ISO 8601), or null while pending.')),
16
+ createdAt: z.string().check(z.describe('When the invitation was created (ISO 8601).')),
17
+ email: z
18
+ .string()
19
+ .check(z.describe('Invitee email (stored lowercase); matched against verified emails.')),
20
+ expiresAt: z.string().check(z.describe('When the invitation expires (ISO 8601).')),
21
+ id: z
22
+ .string()
23
+ .check(
24
+ z.describe('Opaque invitation id (`inv_…`).'),
25
+ z.meta({ examples: ['inv_1a2b3c4d5e6f7g8h9j0k1m2n'] }),
26
+ ),
27
+ invitedBy: z.string().check(z.describe('User id (`usr_…`) that created the invitation.')),
28
+ orgId: z.string().check(z.describe('Organization id (`org_…`) the invitation joins.')),
29
+ revokedAt: z
30
+ .nullable(z.string())
31
+ .check(z.describe('When the invitation was revoked (ISO 8601), or null.')),
32
+ role: z
33
+ .enum(['admin', 'member', 'owner'])
34
+ .check(z.describe('Role granted when the invitation is accepted.')),
35
+ })
36
+
37
+ /** Columns of the `invitations` table. */
38
+ export type Invitation = z.output<typeof Invitation>
39
+
40
+ /** A user's role within an organization. */
41
+ export const Membership = z.object({
42
+ createdAt: z.string().check(z.describe('When the membership was created (ISO 8601).')),
43
+ orgId: z.string().check(z.describe('Organization id (`org_…`).')),
44
+ role: z
45
+ .enum(['admin', 'member', 'owner'])
46
+ .check(z.describe("The member's role within the organization.")),
47
+ updatedAt: z.string().check(z.describe('When the membership was last updated (ISO 8601).')),
48
+ userId: z.string().check(z.describe('Member user id (`usr_…`).')),
49
+ })
50
+
51
+ /** Columns of the `memberships` table. */
52
+ export type Membership = z.output<typeof Membership>
53
+
54
+ /** An organization, the top-level tenant that owns API keys. */
55
+ export const Organization = z.object({
56
+ createdAt: z.string().check(z.describe('When the organization was created (ISO 8601).')),
57
+ createdBy: z
58
+ .nullable(z.string())
59
+ .check(z.describe('Identity that created the organization (e.g. admin email), or null.')),
60
+ id: z
61
+ .string()
62
+ .check(
63
+ z.describe('Opaque organization id (`org_…`).'),
64
+ z.meta({ examples: ['org_1a2b3c4d5e6f7g8h9j0k1m2n'] }),
65
+ ),
66
+ name: z
67
+ .string()
68
+ .check(z.describe('Human-readable organization name.'), z.meta({ examples: ['Acme, Inc.'] })),
69
+ updatedAt: z.string().check(z.describe('When the organization was last updated (ISO 8601).')),
70
+ userId: z
71
+ .nullable(z.string())
72
+ .check(
73
+ z.describe('Owning user id (`usr_…`), or null for organizations created by the super admin.'),
74
+ ),
75
+ })
76
+
77
+ /** Columns of the `organizations` table. */
78
+ export type Organization = z.output<typeof Organization>
79
+
80
+ /** A project: an app or integration within an organization. */
81
+ export const Project = z.object({
82
+ createdAt: z.string().check(z.describe('When the project was created (ISO 8601).')),
83
+ id: z
84
+ .string()
85
+ .check(
86
+ z.describe('Opaque project id (`prj_…`).'),
87
+ z.meta({ examples: ['prj_1a2b3c4d5e6f7g8h9j0k1m2n'] }),
88
+ ),
89
+ name: z
90
+ .string()
91
+ .check(z.describe('Human-readable project name.'), z.meta({ examples: ['Checkout'] })),
92
+ orgId: z.string().check(z.describe('Owning organization id (`org_…`).')),
93
+ updatedAt: z.string().check(z.describe('When the project was last updated (ISO 8601).')),
94
+ })
95
+
96
+ /** Columns of the `projects` table. */
97
+ export type Project = z.output<typeof Project>
98
+
99
+ /** A transaction sponsored by the managed fee payer — the billable unit of fee payer spend. */
100
+ export const SponsoredTransaction = z.object({
101
+ apiKeyId: z.string().check(z.describe('API key id (`key_…`) that requested sponsorship.')),
102
+ billable: z
103
+ .boolean()
104
+ .check(z.describe('Whether the sponsorship accrues billable spend; false for sandbox.')),
105
+ chainId: z.number().check(z.describe('Chain the sponsored transaction targets.')),
106
+ createdAt: z.string().check(z.describe('When the sponsorship was recorded (ISO 8601).')),
107
+ environment: z
108
+ .enum(['production', 'sandbox'])
109
+ .check(z.describe('Key environment the sponsorship was requested under.')),
110
+ feeAmount: z
111
+ .nullable(z.string())
112
+ .check(z.describe('Actual fee paid in fee-token base units, or null until finalized.')),
113
+ feeToken: z
114
+ .nullable(z.string())
115
+ .check(z.describe('Fee token address, or null when the chain default applied.')),
116
+ finalizedAt: z
117
+ .nullable(z.string())
118
+ .check(z.describe('When the sponsorship reached a terminal status (ISO 8601), or null.')),
119
+ id: z
120
+ .string()
121
+ .check(
122
+ z.describe('Opaque sponsored-transaction id (`stx_…`).'),
123
+ z.meta({ examples: ['stx_1a2b3c4d5e6f7g8h9j0k1m2n'] }),
124
+ ),
125
+ orgId: z.string().check(z.describe('Organization id (`org_…`) the spend attributes to.')),
126
+ projectId: z.string().check(z.describe('Project id (`prj_…`) the spend attributes to.')),
127
+ signPayload: z
128
+ .string()
129
+ .check(z.describe('Fee-payer sign payload — a stable identity for the sponsored envelope.')),
130
+ status: z
131
+ .enum(['failed', 'finalized', 'pending'])
132
+ .check(z.describe('Pending until a receipt finalizes it or the pending TTL fails it.')),
133
+ transaction: z
134
+ .string()
135
+ .check(z.describe('Serialized sponsored transaction, kept for durable observability.')),
136
+ transactionHash: z
137
+ .nullable(z.string())
138
+ .check(z.describe('Transaction hash, or null for fill intents until reconciled.')),
139
+ })
140
+
141
+ /** Columns of the `sponsored_transactions` table. */
142
+ export type SponsoredTransaction = z.output<typeof SponsoredTransaction>
143
+
144
+ /** A developer identity. */
145
+ export const User = z.object({
146
+ address: z
147
+ .nullable(z.string())
148
+ .check(
149
+ z.describe(
150
+ 'Wallet address that signs in as this user (stored lowercase), or null for non-wallet identities.',
151
+ ),
152
+ ),
153
+ createdAt: z.string().check(z.describe('When the user was created (ISO 8601).')),
154
+ email: z
155
+ .nullable(z.string())
156
+ .check(z.describe('Verified email from the wallet identity token, or null.')),
157
+ id: z
158
+ .string()
159
+ .check(
160
+ z.describe('Opaque user id (`usr_…`).'),
161
+ z.meta({ examples: ['usr_1a2b3c4d5e6f7g8h9j0k1m2n'] }),
162
+ ),
163
+ updatedAt: z.string().check(z.describe('When the user was last updated (ISO 8601).')),
164
+ })
165
+
166
+ /** Columns of the `users` table. */
167
+ export type User = z.output<typeof User>
168
+
169
+ /**
170
+ * A verified token: one row per curated token, ordered by `position` (list
171
+ * order is canonical and surfaced to clients). Addresses are stored lowercase;
172
+ * case-insensitive symbol uniqueness is enforced by a functional index on
173
+ * `lower(symbol)`.
174
+ */
175
+ export const VerifiedToken = z.object({
176
+ address: z.string().check(z.describe('Verified TIP-20 token contract address (lowercase).')),
177
+ chainId: z.number().check(z.int(), z.describe('Chain the token belongs to.')),
178
+ currency: z.string().check(z.describe('Display currency, e.g. `USD`.')),
179
+ decimals: z.number().check(z.int(), z.describe('Decimal precision.')),
180
+ logoUri: z.nullable(z.string()).check(z.describe('Curated HTTPS logo URL, or null.')),
181
+ name: z.string().check(z.describe('Display name.')),
182
+ position: z
183
+ .number()
184
+ .check(z.int(), z.describe("Zero-based position in the chain's canonical list order.")),
185
+ symbol: z.string().check(z.describe('Ticker symbol.'), z.meta({ examples: ['USDC'] })),
186
+ })
187
+
188
+ /** Columns of the `verified_tokens` table. */
189
+ export type VerifiedToken = z.output<typeof VerifiedToken>
190
+
191
+ /**
192
+ * A chain's verified-token list metadata — the opaque `version` that drives
193
+ * the soft-refresh cache and `If-Match` preconditions, bumped on every publish.
194
+ */
195
+ export const VerifiedTokenList = z.object({
196
+ chainId: z.number().check(z.int(), z.describe('Chain the list belongs to.')),
197
+ updatedAt: z.string().check(z.describe('ISO timestamp of the last publish.')),
198
+ version: z
199
+ .string()
200
+ .check(z.describe('Opaque list version (`<epoch-ms>_<hex>`); changes on every publish.')),
201
+ })
202
+
203
+ /** Columns of the `verified_token_lists` table. */
204
+ export type VerifiedTokenList = z.output<typeof VerifiedTokenList>
205
+
206
+ /**
207
+ * A webhook subscription. The `Webhooks.Owner` union maps to (`ownerType`,
208
+ * `ownerId`); jsonb object columns round-trip as parsed values. `pollerCursor`
209
+ * replaces the old per-subscription cursor key.
210
+ */
211
+ export const WebhookSubscription = z.object({
212
+ chainId: z.number().check(z.int(), z.describe('Chain the subscription listens on.')),
213
+ context: z
214
+ .nullable(z.custom<Webhooks.Context>())
215
+ .check(z.describe('Human context (`jsonb`), or null.')),
216
+ createdAt: z.string().check(z.describe('ISO timestamp of creation.')),
217
+ destination: z
218
+ .custom<Webhooks.Destination>()
219
+ .check(z.describe('Delivery destination (`jsonb`).')),
220
+ eventType: z
221
+ .custom<Webhooks.EventType>()
222
+ .check(z.describe('Event type the subscription listens to.')),
223
+ expiresAt: z
224
+ .nullable(z.string())
225
+ .check(z.describe('ISO expiry timestamp (MPP-owned subscriptions), or null.')),
226
+ failureCount: z
227
+ .number()
228
+ .check(z.int(), z.describe('Consecutive delivery failures; drives auto-disable.')),
229
+ filters: z
230
+ .custom<Webhooks.Subscription['filters']>()
231
+ .check(z.describe('Event-type-specific filter predicates (`jsonb`).')),
232
+ id: z
233
+ .string()
234
+ .check(
235
+ z.describe('Subscription id (`wh_…`, lexically time-ordered).'),
236
+ z.meta({ examples: ['wh_0000019c1a2b3c4d5e6f7g8h'] }),
237
+ ),
238
+ lastDeliveryAt: z
239
+ .nullable(z.string())
240
+ .check(z.describe('ISO timestamp of the last successful delivery, or null.')),
241
+ ownerId: z
242
+ .string()
243
+ .check(z.describe('Owner identifier: `orgId` for `api_key` owners, `payer` for `mpp`.')),
244
+ ownerType: z.custom<Webhooks.Owner['type']>().check(z.describe('Owner kind.')),
245
+ pollerCursor: z
246
+ .nullable(z.string())
247
+ .check(z.describe('Poller keyset cursor, or null before the first tick.')),
248
+ secret: z.string().check(z.describe('HMAC signing secret.')),
249
+ status: z.custom<Webhooks.Status>().check(z.describe('Lifecycle status.')),
250
+ updatedAt: z
251
+ .string()
252
+ .check(z.describe('ISO timestamp of the last mutation (`pollerCursor` writes excluded).')),
253
+ })
254
+
255
+ /** Columns of the `webhook_subscriptions` table. */
256
+ export type WebhookSubscription = z.output<typeof WebhookSubscription>
257
+
258
+ /**
259
+ * A webhook delivery attempt. Rows are invisible past `expiresAt` (the
260
+ * retention deadline that replaces the old store TTL) and pruned by the
261
+ * poller; deleting a subscription cascades to its rows.
262
+ */
263
+ export const WebhookDelivery = z.object({
264
+ attempt: z
265
+ .number()
266
+ .check(
267
+ z.int(),
268
+ z.describe('Consecutive attempt number (1-based) at the time of the delivery.'),
269
+ ),
270
+ createdAt: z.string().check(z.describe('ISO timestamp the attempt was recorded.')),
271
+ envelope: z
272
+ .custom<Webhooks.Envelope>()
273
+ .check(z.describe('The exact envelope that was sent (`jsonb`), for verbatim replay.')),
274
+ error: z
275
+ .nullable(z.string())
276
+ .check(z.describe('Failure reason when `status` is `failed`, or null.')),
277
+ eventId: z.string().check(z.describe('Idempotent event id the delivery carried (`evt_…`).')),
278
+ expiresAt: z
279
+ .string()
280
+ .check(z.describe('ISO retention deadline; rows past it are invisible and pruned.')),
281
+ id: z
282
+ .string()
283
+ .check(
284
+ z.describe('Delivery id (`whd_…`, lexically time-ordered).'),
285
+ z.meta({ examples: ['whd_0000019c1a2b3c4d5e6f7g8h'] }),
286
+ ),
287
+ requestUrl: z.string().check(z.describe('Subscriber callback URL the attempt targeted.')),
288
+ responseMs: z
289
+ .nullable(z.number())
290
+ .check(z.describe('Wall-clock duration of the attempt in ms, or null.')),
291
+ responseStatus: z
292
+ .nullable(z.number())
293
+ .check(z.describe('HTTP response status, or null when no response was received.')),
294
+ status: z.custom<Webhooks.DeliveryStatus>().check(z.describe('Outcome status.')),
295
+ subscriptionId: z
296
+ .string()
297
+ .check(z.describe('Owning subscription id (`wh_…`); FK with `ON DELETE CASCADE`.')),
298
+ })
299
+
300
+ /** Columns of the `webhook_deliveries` table. */
301
+ export type WebhookDelivery = z.output<typeof WebhookDelivery>
@@ -0,0 +1,198 @@
1
+ import type { Selectable } from 'kysely'
2
+ import { nanoid } from 'nanoid'
3
+
4
+ import type * as Db from '../Db.js'
5
+ import type * as db_Schema from '../Schema.js'
6
+ import * as Memberships from './memberships.js'
7
+
8
+ /** Columns of the `invitations` table, derived from `Schema.Invitation`. */
9
+ export type Table = db_Schema.Invitation
10
+
11
+ /** A stored invitation row. */
12
+ export type Record = Selectable<Table>
13
+
14
+ /**
15
+ * Inserts an invitation and returns the stored record. Emails are stored
16
+ * lowercase so matching against verified emails is case-insensitive. Re-inviting
17
+ * a live (pending) (org, email) refreshes that row — role, inviter, expiry —
18
+ * rather than accumulating duplicates, matching the `invitations_pending_unique`
19
+ * partial index.
20
+ *
21
+ * @param db - The database.
22
+ * @param input - The invitation to insert.
23
+ * @returns The stored record.
24
+ */
25
+ export function create(db: Db.Db, input: create.Input): Promise<Record> {
26
+ const now = new Date().toISOString()
27
+ return db.kysely
28
+ .insertInto('invitations')
29
+ .values({
30
+ acceptedAt: null,
31
+ createdAt: now,
32
+ email: input.email.toLowerCase(),
33
+ expiresAt: input.expiresAt,
34
+ id: `inv_${nanoid()}`,
35
+ invitedBy: input.invitedBy,
36
+ orgId: input.orgId,
37
+ revokedAt: null,
38
+ role: input.role,
39
+ })
40
+ .onConflict((oc) =>
41
+ oc
42
+ .columns(['orgId', 'email'])
43
+ .where('acceptedAt', 'is', null)
44
+ .where('revokedAt', 'is', null)
45
+ .doUpdateSet({
46
+ createdAt: now,
47
+ expiresAt: input.expiresAt,
48
+ invitedBy: input.invitedBy,
49
+ role: input.role,
50
+ }),
51
+ )
52
+ .returningAll()
53
+ .executeTakeFirstOrThrow()
54
+ }
55
+
56
+ export declare namespace create {
57
+ /** Fields accepted when inserting an invitation. */
58
+ type Input = {
59
+ /** Invitee email. */
60
+ email: string
61
+ /** When the invitation expires (ISO 8601). */
62
+ expiresAt: string
63
+ /** User id (`usr_…`) creating the invitation. */
64
+ invitedBy: string
65
+ /** Organization id (`org_…`) the invitation joins. */
66
+ orgId: string
67
+ /** Role granted on accept. */
68
+ role: Memberships.Role
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Reads an invitation by id.
74
+ *
75
+ * @param db - The database.
76
+ * @param id - The invitation id (`inv_…`).
77
+ * @returns The record, or `undefined` when absent.
78
+ */
79
+ export function get(db: Db.Db, id: string): Promise<Record | undefined> {
80
+ return db.kysely.selectFrom('invitations').selectAll().where('id', '=', id).executeTakeFirst()
81
+ }
82
+
83
+ /**
84
+ * Lists an organization's pending invitations (unaccepted, unrevoked,
85
+ * unexpired), newest first.
86
+ *
87
+ * @param db - The database.
88
+ * @param orgId - The organization id (`org_…`).
89
+ * @returns The records.
90
+ */
91
+ export function listByOrg(db: Db.Db, orgId: string): Promise<Record[]> {
92
+ return pending(db).where('orgId', '=', orgId).orderBy('createdAt', 'desc').execute()
93
+ }
94
+
95
+ /**
96
+ * Lists pending invitations addressed to an email, joined with the inviting
97
+ * organization's name, newest first.
98
+ *
99
+ * @param db - The database.
100
+ * @param email - The invitee email (matched lowercase).
101
+ * @returns The records with `orgName` from the organization row.
102
+ */
103
+ export function listByEmail(db: Db.Db, email: string): Promise<(Record & { orgName: string })[]> {
104
+ return db.kysely
105
+ .selectFrom('invitations')
106
+ .innerJoin('organizations', 'organizations.id', 'invitations.orgId')
107
+ .where('invitations.acceptedAt', 'is', null)
108
+ .where('invitations.revokedAt', 'is', null)
109
+ .where('invitations.expiresAt', '>', new Date().toISOString())
110
+ .where('invitations.email', '=', email.toLowerCase())
111
+ .selectAll('invitations')
112
+ .select('organizations.name as orgName')
113
+ .orderBy('invitations.createdAt', 'desc')
114
+ .execute()
115
+ }
116
+
117
+ /**
118
+ * Revokes a pending invitation.
119
+ *
120
+ * @param db - The database.
121
+ * @param id - The invitation id (`inv_…`).
122
+ * @returns The revoked record, or `undefined` when absent or already settled.
123
+ */
124
+ export function revoke(db: Db.Db, id: string): Promise<Record | undefined> {
125
+ const now = new Date().toISOString()
126
+ return db.kysely
127
+ .updateTable('invitations')
128
+ .set({ revokedAt: now })
129
+ .where('id', '=', id)
130
+ .where('acceptedAt', 'is', null)
131
+ .where('revokedAt', 'is', null)
132
+ .returningAll()
133
+ .executeTakeFirst()
134
+ }
135
+
136
+ /**
137
+ * Accepts a pending invitation into a membership, atomically: the conditional
138
+ * update settles the invitation exactly once (double accepts lose the race).
139
+ * A new member is inserted at the invited role; an existing member is only ever
140
+ * elevated to it — accepting never demotes (which could strip the last owner).
141
+ *
142
+ * @param db - The database.
143
+ * @param id - The invitation id (`inv_…`).
144
+ * @param userId - The accepting user id (`usr_…`).
145
+ * @returns The accepted record, or `undefined` when absent, settled, or expired.
146
+ */
147
+ export function accept(db: Db.Db, id: string, userId: string): Promise<Record | undefined> {
148
+ const now = new Date().toISOString()
149
+ return db.kysely.transaction().execute(async (trx) => {
150
+ const invitation = await trx
151
+ .updateTable('invitations')
152
+ .set({ acceptedAt: now })
153
+ .where('id', '=', id)
154
+ .where('acceptedAt', 'is', null)
155
+ .where('revokedAt', 'is', null)
156
+ .where('expiresAt', '>', now)
157
+ .returningAll()
158
+ .executeTakeFirst()
159
+ if (!invitation) return undefined
160
+ const existing = await trx
161
+ .selectFrom('memberships')
162
+ .selectAll()
163
+ .where('orgId', '=', invitation.orgId)
164
+ .where('userId', '=', userId)
165
+ .executeTakeFirst()
166
+ if (!existing)
167
+ await trx
168
+ .insertInto('memberships')
169
+ .values({
170
+ createdAt: now,
171
+ orgId: invitation.orgId,
172
+ role: invitation.role,
173
+ updatedAt: now,
174
+ userId,
175
+ })
176
+ // A concurrent accept/join could insert first; keep that membership.
177
+ .onConflict((oc) => oc.columns(['orgId', 'userId']).doNothing())
178
+ .execute()
179
+ else if (Memberships.rank[invitation.role] > Memberships.rank[existing.role])
180
+ await trx
181
+ .updateTable('memberships')
182
+ .set({ role: invitation.role, updatedAt: now })
183
+ .where('orgId', '=', invitation.orgId)
184
+ .where('userId', '=', userId)
185
+ .execute()
186
+ return invitation
187
+ })
188
+ }
189
+
190
+ /** Base query selecting pending invitations (unaccepted, unrevoked, unexpired). */
191
+ function pending(db: Db.Db) {
192
+ return db.kysely
193
+ .selectFrom('invitations')
194
+ .selectAll()
195
+ .where('acceptedAt', 'is', null)
196
+ .where('revokedAt', 'is', null)
197
+ .where('expiresAt', '>', new Date().toISOString())
198
+ }