tapimo 0.1.0 → 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 (385) hide show
  1. package/README.md +28 -15
  2. package/dist/ApiKey.d.ts +3 -1
  3. package/dist/ApiKey.d.ts.map +1 -1
  4. package/dist/ApiKey.js +1 -0
  5. package/dist/ApiKey.js.map +1 -1
  6. package/dist/ApiKeys.d.ts +71 -3
  7. package/dist/ApiKeys.d.ts.map +1 -1
  8. package/dist/ApiKeys.js +117 -1
  9. package/dist/ApiKeys.js.map +1 -1
  10. package/dist/App.d.ts +7139 -4197
  11. package/dist/App.d.ts.map +1 -1
  12. package/dist/App.js +133 -329
  13. package/dist/App.js.map +1 -1
  14. package/dist/Scope.d.ts +11 -4
  15. package/dist/Scope.d.ts.map +1 -1
  16. package/dist/Scope.js +12 -4
  17. package/dist/Scope.js.map +1 -1
  18. package/dist/Webhooks.d.ts +2 -2
  19. package/dist/Webhooks.d.ts.map +1 -1
  20. package/dist/Webhooks.js +2 -2
  21. package/dist/Webhooks.js.map +1 -1
  22. package/dist/admin/App.d.ts +126 -53
  23. package/dist/admin/App.d.ts.map +1 -1
  24. package/dist/admin/apps/api-keys.d.ts +104 -6
  25. package/dist/admin/apps/api-keys.d.ts.map +1 -1
  26. package/dist/admin/apps/api-keys.js +67 -0
  27. package/dist/admin/apps/api-keys.js.map +1 -1
  28. package/dist/admin/apps/scopes.d.ts +4 -1
  29. package/dist/admin/apps/scopes.d.ts.map +1 -1
  30. package/dist/admin/apps/verified-tokens.d.ts +115 -115
  31. package/dist/admin/apps/verified-tokens.js +1 -1
  32. package/dist/admin/apps/verified-tokens.js.map +1 -1
  33. package/dist/admin/ui.generated.d.ts +1 -1
  34. package/dist/admin/ui.generated.js +1 -1
  35. package/dist/apps/data/App.d.ts +19176 -0
  36. package/dist/apps/data/App.d.ts.map +1 -0
  37. package/dist/apps/data/App.js +236 -0
  38. package/dist/apps/data/App.js.map +1 -0
  39. package/dist/apps/data/index.d.ts +3 -0
  40. package/dist/apps/data/index.d.ts.map +1 -0
  41. package/dist/apps/data/index.js +3 -0
  42. package/dist/apps/data/index.js.map +1 -0
  43. package/dist/apps/{activities.d.ts → data/routes/activities.d.ts} +32 -32
  44. package/dist/apps/{activities.d.ts.map → data/routes/activities.d.ts.map} +1 -1
  45. package/dist/apps/{activities.js → data/routes/activities.js} +13 -13
  46. package/dist/apps/data/routes/activities.js.map +1 -0
  47. package/dist/apps/{addresses.d.ts → data/routes/addresses.d.ts} +22 -22
  48. package/dist/apps/{addresses.d.ts.map → data/routes/addresses.d.ts.map} +1 -1
  49. package/dist/apps/{addresses.js → data/routes/addresses.js} +5 -5
  50. package/dist/apps/data/routes/addresses.js.map +1 -0
  51. package/dist/apps/{balances.d.ts → data/routes/balances.d.ts} +49 -49
  52. package/dist/apps/data/routes/balances.d.ts.map +1 -0
  53. package/dist/apps/{balances.js → data/routes/balances.js} +42 -11
  54. package/dist/apps/data/routes/balances.js.map +1 -0
  55. package/dist/apps/{blocks.d.ts → data/routes/blocks.d.ts} +47 -47
  56. package/dist/apps/data/routes/blocks.d.ts.map +1 -0
  57. package/dist/apps/{blocks.js → data/routes/blocks.js} +13 -13
  58. package/dist/apps/data/routes/blocks.js.map +1 -0
  59. package/dist/apps/{coingecko.d.ts → data/routes/coingecko.d.ts} +183 -183
  60. package/dist/apps/data/routes/coingecko.d.ts.map +1 -0
  61. package/dist/apps/{coingecko.js → data/routes/coingecko.js} +13 -13
  62. package/dist/apps/data/routes/coingecko.js.map +1 -0
  63. package/dist/apps/{exchanges.d.ts → data/routes/exchanges.d.ts} +460 -460
  64. package/dist/apps/data/routes/exchanges.d.ts.map +1 -0
  65. package/dist/apps/{exchanges.js → data/routes/exchanges.js} +19 -19
  66. package/dist/apps/data/routes/exchanges.js.map +1 -0
  67. package/dist/apps/{fee-amm.d.ts → data/routes/fee-amm.d.ts} +94 -94
  68. package/dist/apps/data/routes/fee-amm.d.ts.map +1 -0
  69. package/dist/apps/{fee-amm.js → data/routes/fee-amm.js} +17 -17
  70. package/dist/apps/data/routes/fee-amm.js.map +1 -0
  71. package/dist/apps/{indexer.d.ts → data/routes/indexer.d.ts} +4 -4
  72. package/dist/apps/data/routes/indexer.d.ts.map +1 -0
  73. package/dist/apps/{indexer.js → data/routes/indexer.js} +13 -9
  74. package/dist/apps/data/routes/indexer.js.map +1 -0
  75. package/dist/apps/{receipts.d.ts → data/routes/receipts.d.ts} +49 -49
  76. package/dist/apps/data/routes/receipts.d.ts.map +1 -0
  77. package/dist/apps/{receipts.js → data/routes/receipts.js} +12 -12
  78. package/dist/apps/data/routes/receipts.js.map +1 -0
  79. package/dist/apps/{rpc.d.ts → data/routes/rpc.d.ts} +4 -4
  80. package/dist/apps/data/routes/rpc.d.ts.map +1 -0
  81. package/dist/apps/{rpc.js → data/routes/rpc.js} +6 -6
  82. package/dist/apps/data/routes/rpc.js.map +1 -0
  83. package/dist/apps/{tokenlist.d.ts → data/routes/tokenlist.d.ts} +4 -4
  84. package/dist/apps/data/routes/tokenlist.d.ts.map +1 -0
  85. package/dist/apps/{tokenlist.js → data/routes/tokenlist.js} +8 -8
  86. package/dist/apps/data/routes/tokenlist.js.map +1 -0
  87. package/dist/apps/{tokens.d.ts → data/routes/tokens.d.ts} +468 -468
  88. package/dist/apps/data/routes/tokens.d.ts.map +1 -0
  89. package/dist/apps/{tokens.js → data/routes/tokens.js} +19 -19
  90. package/dist/apps/data/routes/tokens.js.map +1 -0
  91. package/dist/apps/{transactions.d.ts → data/routes/transactions.d.ts} +304 -304
  92. package/dist/apps/data/routes/transactions.d.ts.map +1 -0
  93. package/dist/apps/{transactions.js → data/routes/transactions.js} +13 -13
  94. package/dist/apps/data/routes/transactions.js.map +1 -0
  95. package/dist/apps/{transfers.d.ts → data/routes/transfers.d.ts} +6 -6
  96. package/dist/apps/data/routes/transfers.d.ts.map +1 -0
  97. package/dist/apps/{transfers.js → data/routes/transfers.js} +13 -13
  98. package/dist/apps/data/routes/transfers.js.map +1 -0
  99. package/dist/apps/{verified-tokens.d.ts → data/routes/verified-tokens.d.ts} +42 -42
  100. package/dist/apps/data/routes/verified-tokens.d.ts.map +1 -0
  101. package/dist/apps/{verified-tokens.js → data/routes/verified-tokens.js} +9 -9
  102. package/dist/apps/data/routes/verified-tokens.js.map +1 -0
  103. package/dist/apps/{webhooks.d.ts → data/routes/webhooks.d.ts} +62 -62
  104. package/dist/apps/{webhooks.d.ts.map → data/routes/webhooks.d.ts.map} +1 -1
  105. package/dist/apps/{webhooks.js → data/routes/webhooks.js} +30 -26
  106. package/dist/apps/data/routes/webhooks.js.map +1 -0
  107. package/dist/apps/docs/App.d.ts +27 -0
  108. package/dist/apps/docs/App.d.ts.map +1 -0
  109. package/dist/apps/docs/App.js +122 -0
  110. package/dist/apps/docs/App.js.map +1 -0
  111. package/dist/{internal/OpenApi.fonts.d.ts → apps/docs/fonts.d.ts} +1 -1
  112. package/dist/apps/docs/fonts.d.ts.map +1 -0
  113. package/dist/{internal/OpenApi.fonts.js → apps/docs/fonts.js} +1 -1
  114. package/dist/apps/docs/fonts.js.map +1 -0
  115. package/dist/apps/docs/index.d.ts +2 -0
  116. package/dist/apps/docs/index.d.ts.map +1 -0
  117. package/dist/apps/docs/index.js +2 -0
  118. package/dist/apps/docs/index.js.map +1 -0
  119. package/dist/{internal/OpenApi.logo.d.ts → apps/docs/logo.d.ts} +1 -1
  120. package/dist/apps/docs/logo.d.ts.map +1 -0
  121. package/dist/{internal/OpenApi.logo.js → apps/docs/logo.js} +1 -1
  122. package/dist/apps/docs/logo.js.map +1 -0
  123. package/dist/apps/index.d.ts +4 -0
  124. package/dist/apps/index.d.ts.map +1 -0
  125. package/dist/apps/index.js +4 -0
  126. package/dist/apps/index.js.map +1 -0
  127. package/dist/apps/metadata.d.ts +7 -0
  128. package/dist/apps/metadata.d.ts.map +1 -0
  129. package/dist/apps/metadata.js +15 -0
  130. package/dist/apps/metadata.js.map +1 -0
  131. package/dist/apps/platform/App.d.ts +2985 -0
  132. package/dist/apps/platform/App.d.ts.map +1 -0
  133. package/dist/apps/platform/App.js +74 -0
  134. package/dist/apps/platform/App.js.map +1 -0
  135. package/dist/apps/platform/index.d.ts +2 -0
  136. package/dist/apps/platform/index.d.ts.map +1 -0
  137. package/dist/apps/platform/index.js +2 -0
  138. package/dist/apps/platform/index.js.map +1 -0
  139. package/dist/apps/platform/routes/api-keys.d.ts +681 -0
  140. package/dist/apps/platform/routes/api-keys.d.ts.map +1 -0
  141. package/dist/apps/platform/routes/api-keys.js +328 -0
  142. package/dist/apps/platform/routes/api-keys.js.map +1 -0
  143. package/dist/apps/platform/routes/invitations.d.ts +733 -0
  144. package/dist/apps/platform/routes/invitations.d.ts.map +1 -0
  145. package/dist/apps/platform/routes/invitations.js +413 -0
  146. package/dist/apps/platform/routes/invitations.js.map +1 -0
  147. package/dist/apps/platform/routes/me.d.ts +95 -0
  148. package/dist/apps/platform/routes/me.d.ts.map +1 -0
  149. package/dist/apps/platform/routes/me.js +81 -0
  150. package/dist/apps/platform/routes/me.js.map +1 -0
  151. package/dist/apps/platform/routes/members.d.ts +554 -0
  152. package/dist/apps/platform/routes/members.d.ts.map +1 -0
  153. package/dist/apps/platform/routes/members.js +251 -0
  154. package/dist/apps/platform/routes/members.js.map +1 -0
  155. package/dist/apps/platform/routes/orgs.d.ts +582 -0
  156. package/dist/apps/platform/routes/orgs.d.ts.map +1 -0
  157. package/dist/apps/platform/routes/orgs.js +265 -0
  158. package/dist/apps/platform/routes/orgs.js.map +1 -0
  159. package/dist/apps/platform/routes/projects.d.ts +740 -0
  160. package/dist/apps/platform/routes/projects.d.ts.map +1 -0
  161. package/dist/apps/platform/routes/projects.js +286 -0
  162. package/dist/apps/platform/routes/projects.js.map +1 -0
  163. package/dist/apps/relay/App.d.ts +41 -0
  164. package/dist/apps/relay/App.d.ts.map +1 -0
  165. package/dist/apps/relay/App.js +103 -0
  166. package/dist/apps/relay/App.js.map +1 -0
  167. package/dist/apps/relay/Sponsorships.d.ts +107 -0
  168. package/dist/apps/relay/Sponsorships.d.ts.map +1 -0
  169. package/dist/apps/relay/Sponsorships.js +193 -0
  170. package/dist/apps/relay/Sponsorships.js.map +1 -0
  171. package/dist/apps/relay/index.d.ts +3 -0
  172. package/dist/apps/relay/index.d.ts.map +1 -0
  173. package/dist/apps/relay/index.js +3 -0
  174. package/dist/apps/relay/index.js.map +1 -0
  175. package/dist/cli/Cli.d.ts +1 -1
  176. package/dist/cli/Cli.js +1 -1
  177. package/dist/cli/commands/admin.d.ts +1 -1
  178. package/dist/cli/commands/admin.js +2 -2
  179. package/dist/cli/commands/admin.js.map +1 -1
  180. package/dist/db/Db.d.ts +10 -0
  181. package/dist/db/Db.d.ts.map +1 -1
  182. package/dist/db/Db.js +128 -0
  183. package/dist/db/Db.js.map +1 -1
  184. package/dist/db/Schema.d.ts +80 -0
  185. package/dist/db/Schema.d.ts.map +1 -1
  186. package/dist/db/Schema.js +99 -0
  187. package/dist/db/Schema.js.map +1 -1
  188. package/dist/db/tables/invitations.d.ts +84 -0
  189. package/dist/db/tables/invitations.d.ts.map +1 -0
  190. package/dist/db/tables/invitations.js +165 -0
  191. package/dist/db/tables/invitations.js.map +1 -0
  192. package/dist/db/tables/memberships.d.ts +108 -0
  193. package/dist/db/tables/memberships.d.ts.map +1 -0
  194. package/dist/db/tables/memberships.js +153 -0
  195. package/dist/db/tables/memberships.js.map +1 -0
  196. package/dist/db/tables/organizations.d.ts +44 -0
  197. package/dist/db/tables/organizations.d.ts.map +1 -1
  198. package/dist/db/tables/organizations.js +89 -0
  199. package/dist/db/tables/organizations.js.map +1 -1
  200. package/dist/db/tables/projects.d.ts +65 -0
  201. package/dist/db/tables/projects.d.ts.map +1 -0
  202. package/dist/db/tables/projects.js +75 -0
  203. package/dist/db/tables/projects.js.map +1 -0
  204. package/dist/db/tables/sponsoredTransactions.d.ts +120 -0
  205. package/dist/db/tables/sponsoredTransactions.d.ts.map +1 -0
  206. package/dist/db/tables/sponsoredTransactions.js +161 -0
  207. package/dist/db/tables/sponsoredTransactions.js.map +1 -0
  208. package/dist/db/tables/users.d.ts +48 -0
  209. package/dist/db/tables/users.d.ts.map +1 -0
  210. package/dist/db/tables/users.js +65 -0
  211. package/dist/db/tables/users.js.map +1 -0
  212. package/dist/handlers/internal/executionError.d.ts.map +1 -1
  213. package/dist/handlers/internal/executionError.js +2 -0
  214. package/dist/handlers/internal/executionError.js.map +1 -1
  215. package/dist/handlers/internal/multisig.d.ts +2 -6
  216. package/dist/handlers/internal/multisig.d.ts.map +1 -1
  217. package/dist/handlers/internal/multisig.js +11 -36
  218. package/dist/handlers/internal/multisig.js.map +1 -1
  219. package/dist/handlers/internal/sponsorship.d.ts +32 -2
  220. package/dist/handlers/internal/sponsorship.d.ts.map +1 -1
  221. package/dist/handlers/internal/sponsorship.js +34 -9
  222. package/dist/handlers/internal/sponsorship.js.map +1 -1
  223. package/dist/handlers/relay.d.ts +6 -2
  224. package/dist/handlers/relay.d.ts.map +1 -1
  225. package/dist/handlers/relay.js +16 -2
  226. package/dist/handlers/relay.js.map +1 -1
  227. package/dist/internal/Auth.d.ts +208 -6
  228. package/dist/internal/Auth.d.ts.map +1 -1
  229. package/dist/internal/Auth.js +500 -21
  230. package/dist/internal/Auth.js.map +1 -1
  231. package/dist/internal/Log.d.ts +7 -3
  232. package/dist/internal/Log.d.ts.map +1 -1
  233. package/dist/internal/Log.js +4 -0
  234. package/dist/internal/Log.js.map +1 -1
  235. package/dist/internal/OpenApi.d.ts +0 -19
  236. package/dist/internal/OpenApi.d.ts.map +1 -1
  237. package/dist/internal/OpenApi.js +0 -57
  238. package/dist/internal/OpenApi.js.map +1 -1
  239. package/dist/internal/Store.d.ts +7 -1
  240. package/dist/internal/Store.d.ts.map +1 -1
  241. package/dist/internal/Store.js +16 -2
  242. package/dist/internal/Store.js.map +1 -1
  243. package/dist/internal/Viem.d.ts +84 -0
  244. package/dist/internal/Viem.d.ts.map +1 -1
  245. package/dist/internal/Webhooks.d.ts +1 -1
  246. package/dist/internal/Webhooks.d.ts.map +1 -1
  247. package/package.json +31 -5
  248. package/src/ApiKey.ts +1 -0
  249. package/src/ApiKeys.test.ts +104 -1
  250. package/src/ApiKeys.ts +154 -1
  251. package/src/App.test.ts +11187 -179
  252. package/src/App.ts +200 -420
  253. package/src/Client.test-d.ts +306 -15
  254. package/src/Scope.ts +13 -4
  255. package/src/Webhooks.ts +2 -2
  256. package/src/admin/apps/api-keys.test.ts +51 -0
  257. package/src/admin/apps/api-keys.ts +84 -0
  258. package/src/admin/apps/scopes.test.ts +5 -1
  259. package/src/admin/apps/verified-tokens.ts +1 -1
  260. package/src/admin/ui.generated.ts +1 -1
  261. package/src/apps/composition.test.ts +66 -0
  262. package/src/apps/data/App.ts +295 -0
  263. package/src/apps/data/index.ts +2 -0
  264. package/src/apps/{activities.test.ts → data/routes/activities.test.ts} +3 -3
  265. package/src/apps/{activities.ts → data/routes/activities.ts} +15 -15
  266. package/src/apps/{addresses.ts → data/routes/addresses.ts} +6 -6
  267. package/src/apps/{balances.test.ts → data/routes/balances.test.ts} +2 -2
  268. package/src/apps/{balances.ts → data/routes/balances.ts} +46 -12
  269. package/src/apps/{blocks.test.ts → data/routes/blocks.test.ts} +3 -3
  270. package/src/apps/{blocks.ts → data/routes/blocks.ts} +14 -14
  271. package/src/apps/{coingecko.test.ts → data/routes/coingecko.test.ts} +2 -2
  272. package/src/apps/{coingecko.ts → data/routes/coingecko.ts} +14 -14
  273. package/src/apps/{exchanges.test.ts → data/routes/exchanges.test.ts} +1 -1
  274. package/src/apps/{exchanges.ts → data/routes/exchanges.ts} +20 -20
  275. package/src/apps/{fee-amm.test.ts → data/routes/fee-amm.test.ts} +3 -3
  276. package/src/apps/{fee-amm.ts → data/routes/fee-amm.ts} +18 -18
  277. package/src/apps/{indexer.test.ts → data/routes/indexer.test.ts} +26 -5
  278. package/src/apps/{indexer.ts → data/routes/indexer.ts} +13 -10
  279. package/src/apps/{receipts.test.ts → data/routes/receipts.test.ts} +3 -3
  280. package/src/apps/{receipts.ts → data/routes/receipts.ts} +13 -13
  281. package/src/apps/{rpc.test.ts → data/routes/rpc.test.ts} +44 -5
  282. package/src/apps/{rpc.ts → data/routes/rpc.ts} +7 -7
  283. package/src/apps/{tokenlist.test.ts → data/routes/tokenlist.test.ts} +3 -3
  284. package/src/apps/{tokenlist.ts → data/routes/tokenlist.ts} +9 -9
  285. package/src/apps/{tokens.test.ts → data/routes/tokens.test.ts} +2 -2
  286. package/src/apps/{tokens.ts → data/routes/tokens.ts} +20 -20
  287. package/src/apps/{transactions.test.ts → data/routes/transactions.test.ts} +3 -3
  288. package/src/apps/{transactions.ts → data/routes/transactions.ts} +15 -15
  289. package/src/apps/{transfers.test.ts → data/routes/transfers.test.ts} +2 -2
  290. package/src/apps/{transfers.ts → data/routes/transfers.ts} +15 -15
  291. package/src/apps/{verified-tokens.test.ts → data/routes/verified-tokens.test.ts} +3 -3
  292. package/src/apps/{verified-tokens.ts → data/routes/verified-tokens.ts} +10 -10
  293. package/src/apps/{webhooks.test.ts → data/routes/webhooks.test.ts} +6 -6
  294. package/src/apps/{webhooks.ts → data/routes/webhooks.ts} +39 -35
  295. package/src/apps/docs/App.ts +136 -0
  296. package/src/apps/docs/index.ts +1 -0
  297. package/src/apps/index.ts +3 -0
  298. package/src/apps/metadata.ts +23 -0
  299. package/src/apps/platform/App.ts +130 -0
  300. package/src/apps/platform/index.ts +1 -0
  301. package/src/apps/platform/routes/api-keys.test.ts +330 -0
  302. package/src/apps/platform/routes/api-keys.ts +427 -0
  303. package/src/apps/platform/routes/invitations.test.ts +361 -0
  304. package/src/apps/platform/routes/invitations.ts +519 -0
  305. package/src/apps/platform/routes/me.test.ts +121 -0
  306. package/src/apps/platform/routes/me.ts +106 -0
  307. package/src/apps/platform/routes/members.test.ts +195 -0
  308. package/src/apps/platform/routes/members.ts +313 -0
  309. package/src/apps/platform/routes/orgs.test.ts +313 -0
  310. package/src/apps/platform/routes/orgs.ts +343 -0
  311. package/src/apps/platform/routes/projects.test.ts +181 -0
  312. package/src/apps/platform/routes/projects.ts +367 -0
  313. package/src/apps/relay/App.test.ts +484 -0
  314. package/src/apps/relay/App.ts +128 -0
  315. package/src/apps/relay/Sponsorships.test.ts +375 -0
  316. package/src/apps/relay/Sponsorships.ts +305 -0
  317. package/src/apps/relay/index.ts +2 -0
  318. package/src/cli/Cli.ts +1 -1
  319. package/src/cli/commands/admin.ts +2 -2
  320. package/src/db/Db.ts +159 -0
  321. package/src/db/Schema.ts +137 -0
  322. package/src/db/tables/invitations.ts +198 -0
  323. package/src/db/tables/memberships.ts +208 -0
  324. package/src/db/tables/organizations.test.ts +37 -1
  325. package/src/db/tables/organizations.ts +105 -0
  326. package/src/db/tables/projects.ts +107 -0
  327. package/src/db/tables/sponsoredTransactions.test.ts +218 -0
  328. package/src/db/tables/sponsoredTransactions.ts +236 -0
  329. package/src/db/tables/users.ts +85 -0
  330. package/src/handlers/internal/executionError.ts +2 -0
  331. package/src/handlers/internal/multisig.test.ts +84 -10
  332. package/src/handlers/internal/multisig.ts +15 -50
  333. package/src/handlers/internal/sponsorship.ts +74 -15
  334. package/src/handlers/{internal/relay.localnet.test.ts → relay.test.ts} +2 -2
  335. package/src/handlers/relay.ts +23 -5
  336. package/src/internal/Auth.test.ts +316 -0
  337. package/src/internal/Auth.ts +691 -25
  338. package/src/internal/Cursor.test.ts +3 -2
  339. package/src/internal/Log.test.ts +1 -1
  340. package/src/internal/Log.ts +11 -3
  341. package/src/internal/MetricSink.ts +1 -1
  342. package/src/internal/OpenApi.ts +0 -59
  343. package/src/internal/Store.test.ts +52 -0
  344. package/src/internal/Store.ts +24 -5
  345. package/src/internal/Tidx.local.test.ts +1 -1
  346. package/src/internal/VerifiedTokens.test.ts +1 -1
  347. package/src/internal/WebhookDestination.test.ts +1 -1
  348. package/src/internal/Webhooks.test.ts +4 -4
  349. package/src/internal/Webhooks.ts +1 -1
  350. package/dist/apps/activities.js.map +0 -1
  351. package/dist/apps/addresses.js.map +0 -1
  352. package/dist/apps/balances.d.ts.map +0 -1
  353. package/dist/apps/balances.js.map +0 -1
  354. package/dist/apps/blocks.d.ts.map +0 -1
  355. package/dist/apps/blocks.js.map +0 -1
  356. package/dist/apps/coingecko.d.ts.map +0 -1
  357. package/dist/apps/coingecko.js.map +0 -1
  358. package/dist/apps/exchanges.d.ts.map +0 -1
  359. package/dist/apps/exchanges.js.map +0 -1
  360. package/dist/apps/fee-amm.d.ts.map +0 -1
  361. package/dist/apps/fee-amm.js.map +0 -1
  362. package/dist/apps/indexer.d.ts.map +0 -1
  363. package/dist/apps/indexer.js.map +0 -1
  364. package/dist/apps/receipts.d.ts.map +0 -1
  365. package/dist/apps/receipts.js.map +0 -1
  366. package/dist/apps/rpc.d.ts.map +0 -1
  367. package/dist/apps/rpc.js.map +0 -1
  368. package/dist/apps/tokenlist.d.ts.map +0 -1
  369. package/dist/apps/tokenlist.js.map +0 -1
  370. package/dist/apps/tokens.d.ts.map +0 -1
  371. package/dist/apps/tokens.js.map +0 -1
  372. package/dist/apps/transactions.d.ts.map +0 -1
  373. package/dist/apps/transactions.js.map +0 -1
  374. package/dist/apps/transfers.d.ts.map +0 -1
  375. package/dist/apps/transfers.js.map +0 -1
  376. package/dist/apps/verified-tokens.d.ts.map +0 -1
  377. package/dist/apps/verified-tokens.js.map +0 -1
  378. package/dist/apps/webhooks.js.map +0 -1
  379. package/dist/internal/OpenApi.fonts.d.ts.map +0 -1
  380. package/dist/internal/OpenApi.fonts.js.map +0 -1
  381. package/dist/internal/OpenApi.logo.d.ts.map +0 -1
  382. package/dist/internal/OpenApi.logo.js.map +0 -1
  383. package/src/handlers/internal/multisig.localnet.test.ts +0 -146
  384. /package/src/{internal/OpenApi.fonts.ts → apps/docs/fonts.ts} +0 -0
  385. /package/src/{internal/OpenApi.logo.ts → apps/docs/logo.ts} +0 -0
@@ -1,21 +1,154 @@
1
+ import * as Accounts from 'accounts/server';
2
+ import { Hono } from 'hono';
1
3
  import { createMiddleware } from 'hono/factory';
2
4
  import { matchedRoutes } from 'hono/route';
3
5
  import { findTargetHandler } from 'hono/utils/handler';
4
6
  import { Credential } from 'mppx';
5
7
  import { Mppx, tempo } from 'mppx/hono';
8
+ import * as z from 'zod/mini';
6
9
  import * as ApiKey from '../ApiKey.js';
7
10
  import * as ApiKeys from '../ApiKeys.js';
11
+ import * as Db from '../db/Db.js';
12
+ import * as Memberships from '../db/tables/memberships.js';
13
+ import * as Metadata from '../apps/metadata.js';
8
14
  import * as OpenApi from './OpenApi.js';
15
+ import * as Organizations from '../db/tables/organizations.js';
16
+ import * as Projects from '../db/tables/projects.js';
9
17
  import * as RateLimit from './RateLimit.js';
10
18
  import * as Response from './Response.js';
11
19
  import * as Schema from './Schema.js';
12
20
  import * as Scope from '../Scope.js';
21
+ import * as Users from '../db/tables/users.js';
13
22
  import * as Viem from './Viem.js';
14
23
  const policySymbol = Symbol('tempo-api.auth.policy');
15
24
  /** Reads the authenticated principal from a Hono context. */
16
25
  export function getPrincipal(c) {
17
26
  return c.get('principal') ?? null;
18
27
  }
28
+ /**
29
+ * Guards org-scoped routes (`:orgId`). Sessions reach only organizations they
30
+ * are members of; the super admin reaches any. Missing or foreign
31
+ * organizations return `404`, so foreign org ids are indistinguishable from
32
+ * absent ones; a member below the required role gets `403` (the resource is
33
+ * visible to them, the action is not). The resolved organization and
34
+ * membership land on context — read them with {@link org} and
35
+ * {@link membership}.
36
+ */
37
+ export function ensureOrg(options = {}) {
38
+ const { role: minimum = 'member' } = options;
39
+ // Typed loosely (like {@link policy}) so route chains keep their inferred
40
+ // schema; a concrete environment parameter collapses Hono's inference.
41
+ return createMiddleware(async (c, next) => {
42
+ const notFound = () => Response.error(c, {
43
+ code: 'organization_not_found',
44
+ message: 'Organization not found',
45
+ status: 404,
46
+ });
47
+ const orgId = c.req.param('orgId');
48
+ if (!orgId)
49
+ return notFound();
50
+ const principal = getPrincipal(c);
51
+ if (principal?.type !== 'session' && principal?.type !== 'super_admin')
52
+ return notFound();
53
+ const db = Db.get(contextDb(c));
54
+ const record = await Organizations.get(db, orgId);
55
+ if (!record)
56
+ return notFound();
57
+ if (principal.type !== 'super_admin') {
58
+ const member = await Memberships.get(db, orgId, principal.id);
59
+ if (!member)
60
+ return notFound();
61
+ if (Memberships.rank[member.role] < Memberships.rank[minimum])
62
+ return Response.error(c, {
63
+ code: 'forbidden',
64
+ message: `Requires the ${minimum} role`,
65
+ status: 403,
66
+ });
67
+ c.set('membership', member);
68
+ }
69
+ c.set('org', record);
70
+ await next();
71
+ return undefined;
72
+ });
73
+ }
74
+ /**
75
+ * Guards project-scoped routes (`:projectId`) nested under {@link ensureOrg},
76
+ * which must run first. Projects resolve only within the scoped organization;
77
+ * missing or cross-org projects return `404`. The resolved project lands on
78
+ * context — read it with {@link project}.
79
+ */
80
+ export function ensureProject() {
81
+ // Typed loosely (like {@link policy}) so route chains keep their inferred
82
+ // schema; a concrete environment parameter collapses Hono's inference.
83
+ return createMiddleware(async (c, next) => {
84
+ const notFound = () => Response.error(c, {
85
+ code: 'project_not_found',
86
+ message: 'Project not found',
87
+ status: 404,
88
+ });
89
+ const projectId = c.req.param('projectId');
90
+ if (!projectId)
91
+ return notFound();
92
+ const scoped = c.get('org');
93
+ if (!scoped)
94
+ return notFound();
95
+ const record = await Projects.get(Db.get(contextDb(c)), projectId);
96
+ if (!record || record.orgId !== scoped.id)
97
+ return notFound();
98
+ c.set('project', record);
99
+ await next();
100
+ return undefined;
101
+ });
102
+ }
103
+ /**
104
+ * Always false at runtime, but typed as `boolean` so handlers can include a
105
+ * never-reached scope-error branch in Hono's inferred response union (the
106
+ * ensure middlewares produce these `404`s before the handler runs).
107
+ */
108
+ export const narrowScope = false;
109
+ /** Typed org-scope error response for Hono client inference. Never reached at runtime. */
110
+ export function ensureOrgError(c) {
111
+ return Response.error(c, {
112
+ code: 'organization_not_found',
113
+ message: 'Organization not found',
114
+ status: 404,
115
+ });
116
+ }
117
+ /** Typed project-scope error response for Hono client inference. Never reached at runtime. */
118
+ export function ensureProjectError(c) {
119
+ // Project routes run the org scope first, so either not-found can surface.
120
+ const code = c.req.header('tempo-narrow-scope-code') === 'organization_not_found'
121
+ ? 'organization_not_found'
122
+ : 'project_not_found';
123
+ return Response.error(c, {
124
+ code,
125
+ message: 'Project not found',
126
+ status: 404,
127
+ });
128
+ }
129
+ /** Reads the caller's membership resolved by {@link ensureOrg}; `undefined` for `super_admin`. */
130
+ export function membership(c) {
131
+ return c.get('membership');
132
+ }
133
+ /** Reads the organization resolved by {@link ensureOrg}; throws when the middleware did not run. */
134
+ export function org(c) {
135
+ const record = c.get('org');
136
+ if (!record)
137
+ throw new Error('`orgScope` middleware must run before reading the organization');
138
+ return record;
139
+ }
140
+ /** Reads the project resolved by {@link ensureProject}; throws when the middleware did not run. */
141
+ export function project(c) {
142
+ const record = c.get('project');
143
+ if (!record)
144
+ throw new Error('`projectScope` middleware must run before reading the project');
145
+ return record;
146
+ }
147
+ // Reads the app's database source from request context (set by `App.create`
148
+ // from its `db` option).
149
+ function contextDb(c) {
150
+ return c.get('db');
151
+ }
19
152
  /**
20
153
  * Always false at runtime, but typed as `boolean` so handlers can include a
21
154
  * never-reached access-error branch in Hono's inferred response union.
@@ -55,6 +188,31 @@ export function accessError(c) {
55
188
  status: 429,
56
189
  });
57
190
  }
191
+ /** Typed lane-less policy error response for Hono client inference. Never reached at runtime. */
192
+ export function superAdminAccessError(c) {
193
+ const status = Number(c.req.header('tempo-narrow-access-status'));
194
+ if (status === 400)
195
+ return Response.error(c, {
196
+ code: 'api_key_malformed',
197
+ message: 'Malformed API key',
198
+ status: 400,
199
+ });
200
+ if (status === 401) {
201
+ const code = c.req.header('tempo-narrow-access-code') === 'api_key_missing'
202
+ ? 'api_key_missing'
203
+ : 'api_key_invalid';
204
+ return Response.error(c, {
205
+ code,
206
+ message: 'Missing or invalid API key',
207
+ status: 401,
208
+ });
209
+ }
210
+ return Response.error(c, {
211
+ code: 'forbidden',
212
+ message: 'API key not permitted for this route',
213
+ status: 403,
214
+ });
215
+ }
58
216
  /** Typed auth/payment error response for Hono client inference. Never reached at runtime. */
59
217
  export function paidAccessError(c) {
60
218
  const status = Number(c.req.header('tempo-narrow-access-status'));
@@ -68,7 +226,9 @@ export function paidAccessError(c) {
68
226
  export function middleware(options) {
69
227
  const { charge = {}, ...mpp } = options.mpp === false ? {} : (options.mpp ?? {});
70
228
  const defaults = laneDefaults(options);
71
- const base = basePolicy(options, defaults);
229
+ // Default-deny: no lanes open until a route grants them via `policy`.
230
+ // Otherwise the `super_admin` principal bypasses lane checks entirely.
231
+ const base = {};
72
232
  // Keys resolve against the app's KV state store on request context
73
233
  // (`App.create({ kv })`), so the middleware needs no storage wiring; when no
74
234
  // store is configured, every token resolves to `null` (closed).
@@ -104,6 +264,10 @@ export function middleware(options) {
104
264
  }),
105
265
  }),
106
266
  rateLimit: RateLimit.memory(options.rateLimit),
267
+ ...(options.session ? { session: options.session } : {}),
268
+ ...(options.superAdmin?.secret
269
+ ? { superAdmin: { tokenHash: ApiKey.hash(options.superAdmin.secret) } }
270
+ : {}),
107
271
  };
108
272
  return createMiddleware((c, next) => {
109
273
  const route = openApiRoute(c);
@@ -118,6 +282,220 @@ export function middleware(options) {
118
282
  return require(endpointPolicy)(c, next);
119
283
  });
120
284
  }
285
+ /** Zod schemas documenting the session sign-in surface (`/v1/auth/siwe`). */
286
+ var schema;
287
+ (function (schema) {
288
+ const siweMessage = 'api.tempo.xyz wants you to sign in with your Ethereum account:\n0x0000000000000000000000000000000000000000\n\nURI: https://api.tempo.xyz\nVersion: 1\nChain ID: 0\nNonce: 3D0sZfnHqTBmc9tKR\nIssued At: 2026-01-01T00:00:00.000Z\nExpiration Time: 2026-01-01T00:10:00.000Z';
289
+ /** Error body returned by the sign-in handler (SDK shape, not the API error envelope). */
290
+ schema.HandlerError = z.object({
291
+ error: z
292
+ .string()
293
+ .check(z.describe('Human-readable failure reason.'), z.meta({ examples: ['domain mismatch'] })),
294
+ issues: z
295
+ .optional(z.array(z.unknown()))
296
+ .check(z.describe('Field-level validation issues, present on request-schema failures.')),
297
+ });
298
+ /** Schemas for `POST /v1/auth/siwe/challenge`. */
299
+ let challenge;
300
+ (function (challenge) {
301
+ /** Request body. Accepted fields beyond this document pass through to the SDK handler. */
302
+ challenge.Body = z.object({});
303
+ /** Response body. */
304
+ challenge.Response = z.object({
305
+ message: z
306
+ .string()
307
+ .check(z.describe('Single-use EIP-4361 (SIWE) message to sign and submit for verification.'), z.meta({ examples: [siweMessage] })),
308
+ });
309
+ })(challenge = schema.challenge || (schema.challenge = {}));
310
+ /** Schemas for `POST /v1/auth/siwe` (verify). */
311
+ let verify;
312
+ (function (verify) {
313
+ /** Request body. */
314
+ verify.Body = z.object({
315
+ address: z
316
+ .string()
317
+ .check(z.describe('Wallet address that signed the message; becomes the session subject.'), z.meta({ examples: ['0x0000000000000000000000000000000000000001'] })),
318
+ idToken: z.optional(z.string()).check(z.describe('Wallet-minted OIDC identity token (JWT) asserting a verified email, folded onto the session.'), // prettier-ignore
319
+ z.meta({ examples: ['eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIweDAwMDAifQ.c2lnbmF0dXJl'] })),
320
+ keyAuthorization: z.optional(z.string()).check(z.describe('RLP-serialized signed key authorization (TIP-1053) whose witness binds this message; verification recovers over its digest.'), // prettier-ignore
321
+ z.meta({ examples: [`0x${'aa'.repeat(60)}`] })),
322
+ message: z
323
+ .string()
324
+ .check(z.describe('The exact challenge message issued by `POST /v1/auth/siwe/challenge`.'), z.meta({ examples: [siweMessage] })),
325
+ returnToken: z.optional(z.boolean()).check(z.describe('Return the session token in the body instead of setting the session cookie.'), // prettier-ignore
326
+ z.meta({ examples: [true] })),
327
+ signature: z
328
+ .string()
329
+ .check(z.describe('Signature over the challenge message (or the key-authorization digest).'), z.meta({ examples: [`0x${'aa'.repeat(65)}`] })),
330
+ });
331
+ /** Response body. */
332
+ verify.Response = z.object({
333
+ token: z
334
+ .optional(z.string())
335
+ .check(z.describe('Bearer session token; present only when `returnToken` is true.'), z.meta({ examples: ['aa'.repeat(32)] })),
336
+ });
337
+ })(verify = schema.verify || (schema.verify = {}));
338
+ })(schema || (schema = {}));
339
+ /** `{ error }` response for a sign-in handler failure status. */
340
+ function handlerError(description) {
341
+ return {
342
+ content: { 'application/json': { schema: OpenApi.resolver(schema.HandlerError) } },
343
+ description,
344
+ };
345
+ }
346
+ /**
347
+ * Builds the built-in auth pieces from `App.create`'s `auth` option: the
348
+ * session-surface app to mount (when `session` is configured) and the
349
+ * enforcement middleware, wired with the surface's resolver. `auth: false`
350
+ * disables both.
351
+ */
352
+ export function install(options) {
353
+ const { db, kv } = options;
354
+ const { session: options_session, ...options_middleware } = options.auth === false ? {} : (options.auth ?? {});
355
+ if (options_session && !kv)
356
+ throw new Error('`auth.session` requires the `kv` state store: sessions and sign-in challenges persist there.'); // prettier-ignore
357
+ // Session sign-in surface (challenge, verify, logout — SIWE wallet sign-in
358
+ // today) plus the capability the session lane resolves through. Public but
359
+ // policy-gated: the hidden describeRoute engages the middleware for the
360
+ // mounted sub-app, and the public lane rate-limits challenge-store writes.
361
+ const app = (() => {
362
+ if (!options_session || !kv)
363
+ return undefined;
364
+ const { issuer, origin, ttl } = (typeof options_session === 'object' ? options_session.wallet : undefined) ?? {};
365
+ const handler = Accounts.Handler.auth({
366
+ ...(issuer ? { identity: { issuer } } : {}),
367
+ // Sign-in upserts the `users` row keyed by address.
368
+ onAuthenticate: async ({ address }) => {
369
+ await Users.upsertByAddress(Db.get(db), { address });
370
+ },
371
+ // No pinned origin: on Workers the edge proxy headers are trustworthy, so
372
+ // opt in explicitly (the SDK's guard ignores its own Workers default).
373
+ // Off-Workers the SDK keeps throwing until `wallet.origin` is set.
374
+ ...(origin
375
+ ? { origin }
376
+ : globalThis.navigator?.userAgent === 'Cloudflare-Workers'
377
+ ? { trustProxy: true }
378
+ : {}),
379
+ // The app's KV store under the SDK's Kv contract: JSON values,
380
+ // second-based TTLs, `auth:`-prefixed keys disjoint from API-key
381
+ // records. `take` is omitted; the SDK falls back to get+delete.
382
+ store: {
383
+ async delete(key) {
384
+ await kv.store.delete(`auth:${key}`);
385
+ },
386
+ async get(key) {
387
+ const value = await kv.store.get(`auth:${key}`);
388
+ return value === null ? undefined : JSON.parse(value);
389
+ },
390
+ async set(key, value, options) {
391
+ await kv.store.put(`auth:${key}`, JSON.stringify(value), options?.ttl ? { ttl: options.ttl * 1_000 } : {});
392
+ },
393
+ },
394
+ ...(ttl ? { ttl } : {}),
395
+ });
396
+ const session = {
397
+ resolve: async (c) => {
398
+ const payload = await handler.getSession(c.req.raw);
399
+ if (!payload)
400
+ return null;
401
+ const database = Db.get(db);
402
+ const user = await Users.getByAddress(database, payload.address);
403
+ if (!user)
404
+ return null;
405
+ // Fold a newly verified email onto the user row: identity tokens are
406
+ // optional per sign-in, so the column fills lazily.
407
+ if (payload.email && user.email !== payload.email)
408
+ await Users.setEmail(database, user.id, payload.email);
409
+ const email = payload.email ?? user.email ?? undefined;
410
+ return {
411
+ ...(email ? { email } : {}),
412
+ id: user.id,
413
+ identity: { provider: 'wallet', subject: payload.address },
414
+ type: 'session',
415
+ };
416
+ },
417
+ };
418
+ const policy_public = policy({ public: true });
419
+ const describe = OpenApi.describeRoute({ hide: true });
420
+ const app = new Hono()
421
+ .use('/v1/auth/siwe', policy_public, describe)
422
+ .use('/v1/auth/siwe/*', policy_public, describe);
423
+ // Documented operations: pre-routes carrying the OpenAPI metadata and the
424
+ // envelope-shaped body validation; the mounted handler owns behavior.
425
+ // Statement form keeps them off the app type (`hc` surface).
426
+ app.post('/v1/auth/siwe/challenge', policy_public, OpenApi.validate('json', schema.challenge.Body, {
427
+ code: 'body_invalid',
428
+ message: 'Invalid request body',
429
+ }), OpenApi.describeRoute({
430
+ description: 'Issues a single-use SIWE challenge message to sign. The challenge expires after a short TTL.',
431
+ // Overrides the surface-wide hidden mount guard for this documented route.
432
+ hide: false,
433
+ operationId: 'createSiweChallenge',
434
+ responses: {
435
+ 200: {
436
+ content: { 'application/json': { schema: OpenApi.resolver(schema.challenge.Response) } }, // prettier-ignore
437
+ description: 'The challenge message to sign.',
438
+ headers: { ...OpenApi.successHeaders },
439
+ },
440
+ 400: OpenApi.standardError(400, 'Malformed request body.', ['body_invalid']),
441
+ 429: OpenApi.standardError(429, 'Rate limited.'),
442
+ 500: OpenApi.standardError(500, 'Internal server error.'),
443
+ },
444
+ summary: 'Create challenge (SIWE)',
445
+ tags: ['Authentication'],
446
+ }));
447
+ app.post('/v1/auth/siwe', policy_public, OpenApi.validate('json', schema.verify.Body, {
448
+ code: 'body_invalid',
449
+ message: 'Invalid request body',
450
+ }), OpenApi.describeRoute({
451
+ description: 'Verifies the signed challenge and establishes a session. Sets a session cookie by default; pass `returnToken` to receive a bearer token instead.',
452
+ hide: false,
453
+ operationId: 'verifySiwe',
454
+ responses: {
455
+ 200: {
456
+ content: { 'application/json': { schema: OpenApi.resolver(schema.verify.Response) } },
457
+ description: 'Session established. Cookie mode sets `Set-Cookie`; token mode returns `token`.', // prettier-ignore
458
+ headers: {
459
+ ...OpenApi.successHeaders,
460
+ 'Set-Cookie': {
461
+ description: 'Session cookie (`accounts_auth`); omitted when `returnToken` is true.', // prettier-ignore
462
+ schema: { type: 'string' },
463
+ },
464
+ },
465
+ },
466
+ 400: handlerError('Invalid, expired, or mismatched challenge message.'),
467
+ 401: handlerError('Signature or identity verification failed.'),
468
+ 409: handlerError('Challenge nonce already used or unknown.'),
469
+ 429: OpenApi.standardError(429, 'Rate limited.'),
470
+ 500: OpenApi.standardError(500, 'Internal server error.'),
471
+ },
472
+ summary: 'Authenticate (SIWE)',
473
+ tags: ['Authentication'],
474
+ }));
475
+ app.post('/v1/auth/siwe/logout', policy_public, OpenApi.describeRoute({
476
+ description: 'Revokes the current session and clears the session cookie.',
477
+ hide: false,
478
+ operationId: 'siweLogout',
479
+ responses: {
480
+ 204: { description: 'Session revoked and cookie cleared.' },
481
+ 429: OpenApi.standardError(429, 'Rate limited.'),
482
+ 500: OpenApi.standardError(500, 'Internal server error.'),
483
+ },
484
+ summary: 'Sign out',
485
+ tags: ['Authentication'],
486
+ }));
487
+ return Object.assign(
488
+ // The tag joins the `Platform API` group at `platform()`'s chosen slot;
489
+ // group listings filter to defined tags, so it drops out when unmounted.
490
+ Metadata.attach(app.route('/v1/auth/siwe', handler), {
491
+ tags: [{ name: 'Authentication', description: 'Authenticate into the Tempo Platform.' }],
492
+ }), { session });
493
+ })();
494
+ const middleware_ = options.auth === false
495
+ ? undefined
496
+ : middleware({ ...options_middleware, ...(app ? { session: app.session } : {}) });
497
+ return { app, middleware: middleware_ };
498
+ }
121
499
  /** Creates route middleware that contributes an auth policy override. */
122
500
  export function policy(options) {
123
501
  const middleware = createMiddleware((_, next) => next());
@@ -142,21 +520,14 @@ function laneDefaults(options) {
142
520
  },
143
521
  mpp: { charge: {} },
144
522
  public: { rateLimit: public_?.rateLimit ?? { perMinute: 60 } },
523
+ session: true,
145
524
  };
146
525
  }
147
- /**
148
- * Base policy before route overrides. Default-closed except the API-key lane:
149
- * a route that declares nothing is API-key-only, and must opt into the public
150
- * and paid lanes explicitly. This makes a partial override fail safe — omitting
151
- * a lane leaves it closed rather than silently inheriting open access.
152
- */
153
- function basePolicy(options, defaults) {
154
- return options.apiKey === false ? {} : { apiKey: defaults.apiKey };
155
- }
156
526
  function resolvePolicy(base, defaults, overrides, description) {
157
527
  let apiKey = base.apiKey;
158
528
  let mpp = base.mpp;
159
529
  let public_ = base.public;
530
+ let session = base.session;
160
531
  for (const override of overrides) {
161
532
  if (override === false)
162
533
  return undefined;
@@ -165,18 +536,20 @@ function resolvePolicy(base, defaults, overrides, description) {
165
536
  apiKey = resolveApiKeyLane(apiKey, override.apiKey, defaults.apiKey);
166
537
  mpp = resolveMppLane(mpp, override.mpp, defaults.mpp);
167
538
  public_ = resolvePublicLane(public_, override.public, defaults.public);
539
+ session = resolveSessionLane(session, override.session, defaults.session);
168
540
  }
169
541
  // The OpenAPI summary/description rides along as the payment-challenge
170
542
  // description. It is metadata, not a policy override, so it only applies when
171
543
  // the paid lane is actually enabled and has no explicit description already.
172
544
  if (mpp && description !== undefined && mpp.charge.description === undefined)
173
545
  mpp = { charge: { ...mpp.charge, description } };
174
- if (!apiKey && !mpp && !public_)
175
- return undefined;
546
+ // A lane-less policy stays enforced for super admin; only an explicit
547
+ // `false` override opts a route out of auth entirely.
176
548
  return {
177
549
  ...(apiKey ? { apiKey } : {}),
178
550
  ...(mpp ? { mpp } : {}),
179
551
  ...(public_ ? { public: public_ } : {}),
552
+ ...(session ? { session } : {}),
180
553
  };
181
554
  }
182
555
  function resolveApiKeyLane(current, override, default_) {
@@ -212,6 +585,13 @@ function resolvePublicLane(current, override, default_) {
212
585
  const base = current ?? default_;
213
586
  return { rateLimit: override.rateLimit ?? base.rateLimit };
214
587
  }
588
+ function resolveSessionLane(current, override, default_) {
589
+ if (override === undefined)
590
+ return current;
591
+ if (override === false)
592
+ return undefined;
593
+ return current ?? default_;
594
+ }
215
595
  function openApiRoute(c) {
216
596
  const route = matchedRoutes(c)
217
597
  .slice(c.req.routeIndex + 1)
@@ -248,8 +628,8 @@ function policyFromRoute(route) {
248
628
  * Maps each documented operation id to its resolved access lanes by reading the
249
629
  * `policy` overrides co-located on the app's routes. This is the single source
250
630
  * of truth for per-operation `security` and the `402` response in the generated
251
- * OpenAPI document (see `App.create`): the API-key lane is default-on, and the
252
- * public/MPP lanes apply only where a route opts in via {@link policy}.
631
+ * OpenAPI document (see `App.create`): all lanes are default-closed, and an
632
+ * operation surfaces only the lanes its route opts into via {@link policy}.
253
633
  */
254
634
  export function describeAccess(app) {
255
635
  const groups = new Map();
@@ -268,10 +648,11 @@ export function describeAccess(app) {
268
648
  for (const { operationId, overrides } of groups.values()) {
269
649
  if (!operationId)
270
650
  continue;
271
- let apiKey = true;
651
+ let apiKey = false;
272
652
  let scopes = [];
273
653
  let public_ = false;
274
654
  let mpp = false;
655
+ let session = false;
275
656
  for (const override of overrides) {
276
657
  if (override.apiKey !== undefined)
277
658
  apiKey = override.apiKey !== false;
@@ -281,8 +662,10 @@ export function describeAccess(app) {
281
662
  public_ = override.public !== false;
282
663
  if (override.mpp !== undefined)
283
664
  mpp = override.mpp !== false;
665
+ if (override.session !== undefined)
666
+ session = override.session !== false;
284
667
  }
285
- access[operationId] = { mpp, public: public_, scopes: apiKey ? scopes : [] };
668
+ access[operationId] = { apiKey, mpp, public: public_, scopes: apiKey ? scopes : [], session };
286
669
  }
287
670
  return access;
288
671
  }
@@ -334,13 +717,30 @@ export function require(policy) {
334
717
  });
335
718
  const hasPayment = hasPaymentCredential(c) && isPaymentEnabled(auth, policy);
336
719
  if (credential) {
720
+ // The super admin secret precedes key lookup: it is not a stored key.
721
+ // It must never reach KV resolution or scope/quota checks.
722
+ if (auth.superAdmin && ApiKey.hash(credential.token) === auth.superAdmin.tokenHash) {
723
+ c.set('principal', { actor: 'super_admin', id: 'super_admin', type: 'super_admin' });
724
+ return next();
725
+ }
337
726
  const apiKey = await auth.apiKey?.resolve(c, credential.token);
338
- if (!apiKey)
727
+ if (!apiKey) {
728
+ // A bearer session token is indistinguishable from an API key at the
729
+ // header, so a failed key lookup falls through to the session lane
730
+ // before rejecting.
731
+ if (policy.session) {
732
+ const session = await resolveSession(c, auth);
733
+ if (session) {
734
+ c.set('principal', session);
735
+ return next();
736
+ }
737
+ }
339
738
  return jsonError(c, {
340
739
  code: 'api_key_invalid',
341
740
  message: 'Invalid API key',
342
741
  status: 401,
343
742
  });
743
+ }
344
744
  // Sandbox keys are restricted to non-mainnet chains. An explicit
345
745
  // `chainId` of mainnet makes the key unusable for this request, so it is
346
746
  // ignored and the request falls through to the public policy below (as if
@@ -359,6 +759,14 @@ export function require(policy) {
359
759
  c.set('chainId', Viem.chainId.testnet);
360
760
  const principal = principalFromApiKey(apiKey);
361
761
  c.set('principal', principal);
762
+ // Default-deny: routes with no API-key lane allow only the super admin.
763
+ // A valid key is authenticated but forbidden.
764
+ if (!policy.apiKey)
765
+ return jsonError(c, {
766
+ code: 'forbidden',
767
+ message: 'API key not permitted for this route',
768
+ status: 403,
769
+ });
362
770
  const missing = apiKey.scopes.includes(Scope.wildcard)
363
771
  ? []
364
772
  : (policy.apiKey?.scopes.filter((scope) => !apiKey.scopes.includes(scope)) ?? []);
@@ -404,6 +812,16 @@ export function require(policy) {
404
812
  return next();
405
813
  }
406
814
  }
815
+ // Cookie sessions carry no Authorization credential; resolve the session
816
+ // lane before the public/paid lanes so signed-in browsers skip anonymous
817
+ // quotas.
818
+ if (policy.session) {
819
+ const session = await resolveSession(c, auth);
820
+ if (session) {
821
+ c.set('principal', session);
822
+ return next();
823
+ }
824
+ }
407
825
  const publicPrincipal = principalFromPublic(c);
408
826
  if (hasPayment) {
409
827
  c.set('principal', publicPrincipal);
@@ -451,16 +869,55 @@ export function require(policy) {
451
869
  });
452
870
  });
453
871
  }
872
+ /**
873
+ * How long to wait for the rate-limit counter before failing open. A hot
874
+ * counter backend (e.g. a single Durable Object serving one busy quota bucket)
875
+ * can stall for tens of seconds during a storage-latency blip; without this cap
876
+ * every request for that bucket blocks on it, turning a localized backend
877
+ * hiccup into an API-wide latency spike. The abandoned increment still applies
878
+ * server-side — we just stop waiting for it.
879
+ */
880
+ const rateLimitConsumeTimeout = 300;
454
881
  function consumeRateLimit(auth, options) {
455
882
  if (!auth.rateLimit)
456
883
  return Promise.resolve(null);
457
- // Fail open: a rate-limit store error (e.g. a lost Durable Object
458
- // connection) degrades to unenforced quota instead of failing the request.
459
- return auth.rateLimit.consume(options).catch((error) => {
460
- console.error('[auth] rate-limit consume failed; failing open', error);
884
+ // Fail open: a rate-limit store error (e.g. a lost Durable Object connection)
885
+ // or a stall past `rateLimitConsumeTimeout` degrades to unenforced quota
886
+ // instead of failing — or blocking — the request.
887
+ return withTimeout(auth.rateLimit.consume(options), rateLimitConsumeTimeout).catch((error) => {
888
+ // A timeout or Cloudflare Durable Object overload is an expected
889
+ // degradation (a slow/hot counter backend), logged at warn so it stays out
890
+ // of error dashboards; an unexpected store throw is a genuine error.
891
+ if (error instanceof RateLimitTimeoutError || isDurableObjectOverload(error))
892
+ console.warn('[auth] rate-limit consume degraded; failing open', error);
893
+ else
894
+ console.error('[auth] rate-limit consume failed; failing open', error);
461
895
  return null;
462
896
  });
463
897
  }
898
+ function isDurableObjectOverload(error) {
899
+ return (typeof error === 'object' &&
900
+ error !== null &&
901
+ 'overloaded' in error &&
902
+ error.overloaded === true);
903
+ }
904
+ /**
905
+ * Rejects with a {@link RateLimitTimeoutError} if `promise` does not settle
906
+ * within `ms`, clearing the timer on either outcome so it never keeps the
907
+ * isolate alive.
908
+ */
909
+ function withTimeout(promise, ms) {
910
+ return new Promise((resolve, reject) => {
911
+ const timer = setTimeout(() => reject(new RateLimitTimeoutError(ms)), ms);
912
+ promise.then((value) => {
913
+ clearTimeout(timer);
914
+ resolve(value);
915
+ }, (error) => {
916
+ clearTimeout(timer);
917
+ reject(error);
918
+ });
919
+ });
920
+ }
464
921
  /**
465
922
  * Resolves the rate limit for an API-key request against a quota bucket.
466
923
  * Most-specific wins: a per-key per-scope grant is the only thing that pierces a
@@ -571,6 +1028,7 @@ function principalFromApiKey(apiKey) {
571
1028
  environment: apiKey.environment,
572
1029
  id: apiKey.id,
573
1030
  orgId: apiKey.orgId,
1031
+ ...(apiKey.projectId === undefined ? {} : { projectId: apiKey.projectId }),
574
1032
  type: 'api_key',
575
1033
  };
576
1034
  }
@@ -625,6 +1083,20 @@ function setRateLimitHeaders(c, result) {
625
1083
  function contextKv(c) {
626
1084
  return c.get('kv');
627
1085
  }
1086
+ // Resolve the session lane from the auth context's capability. Failures
1087
+ // resolve to `null` so the remaining lanes and the final `401` still apply.
1088
+ async function resolveSession(c, auth) {
1089
+ const session = auth.session;
1090
+ if (!session)
1091
+ return null;
1092
+ try {
1093
+ return await session.resolve(c);
1094
+ }
1095
+ catch (error) {
1096
+ console.error('[auth] session resolve failed; treating as no session', error);
1097
+ return null;
1098
+ }
1099
+ }
628
1100
  /** Maximum resolve-cache entries held per isolate before eviction. */
629
1101
  const cachedMaxEntries = 10_000;
630
1102
  /**
@@ -675,4 +1147,11 @@ function cachedResolve(resolve, options) {
675
1147
  }
676
1148
  };
677
1149
  }
1150
+ /** Thrown when a rate-limit consume exceeds {@link rateLimitConsumeTimeout}. */
1151
+ export class RateLimitTimeoutError extends Error {
1152
+ name = 'Auth.RateLimitTimeoutError';
1153
+ constructor(ms) {
1154
+ super(`Rate-limit consume timed out after ${ms}ms; failing open.`);
1155
+ }
1156
+ }
678
1157
  //# sourceMappingURL=Auth.js.map