@rebasepro/server 0.23.0 → 0.24.1-canary.g19596ef

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 (287) hide show
  1. package/README.md +28 -3
  2. package/bin/rebase-server.js +4 -2
  3. package/dist/GCSStorageController-DEga1ULx.js +402 -0
  4. package/dist/GCSStorageController-DEga1ULx.js.map +1 -0
  5. package/dist/S3StorageController-Btx-6bJ5.js +480 -0
  6. package/dist/S3StorageController-Btx-6bJ5.js.map +1 -0
  7. package/dist/api/ast-schema-editor.d.ts +92 -1
  8. package/dist/api/errors.d.ts +41 -0
  9. package/dist/api/live-schema-routes.d.ts +64 -10
  10. package/dist/api/logs-routes.d.ts +39 -1
  11. package/dist/api/mount-path.d.ts +30 -0
  12. package/dist/api/mount.d.ts +6 -13
  13. package/dist/api/openapi-generator.d.ts +17 -0
  14. package/dist/api/rest/api-generator.d.ts +97 -11
  15. package/dist/api/rest/auth-collection-writes.d.ts +28 -21
  16. package/dist/api/rest/field-access-query.d.ts +28 -8
  17. package/dist/api/rest/field-ops.d.ts +19 -7
  18. package/dist/api/rest/query-body.d.ts +10 -0
  19. package/dist/api/rest/write-validation.d.ts +9 -7
  20. package/dist/api/schema-editor-routes.d.ts +10 -1
  21. package/dist/api/sql-export-routes.d.ts +8 -0
  22. package/dist/api/types.d.ts +52 -1
  23. package/dist/{ast-schema-editor-Mvr50v_S.js → ast-schema-editor-mCeSC03x.js} +310 -12
  24. package/dist/ast-schema-editor-mCeSC03x.js.map +1 -0
  25. package/dist/auth/access.d.ts +156 -0
  26. package/dist/auth/adapter-middleware.d.ts +2 -1
  27. package/dist/auth/address-ownership.d.ts +16 -1
  28. package/dist/auth/admin-roles-route.d.ts +4 -2
  29. package/dist/auth/admin-roles.d.ts +17 -20
  30. package/dist/auth/admin-user-ops.d.ts +24 -2
  31. package/dist/auth/admin-users-route.d.ts +2 -0
  32. package/dist/auth/api-keys/api-key-middleware.d.ts +64 -56
  33. package/dist/auth/api-keys/api-key-routes.d.ts +44 -11
  34. package/dist/auth/api-keys/api-key-store.d.ts +31 -8
  35. package/dist/auth/api-keys/api-key-types.d.ts +14 -16
  36. package/dist/auth/api-keys/http-operation.d.ts +19 -0
  37. package/dist/auth/api-keys/index.d.ts +11 -11
  38. package/dist/auth/api-keys/key-grant.d.ts +41 -0
  39. package/dist/auth/api-keys/legacy-permissions.d.ts +33 -0
  40. package/dist/auth/auth-hooks.d.ts +46 -7
  41. package/dist/auth/builtin-auth-adapter.d.ts +21 -0
  42. package/dist/auth/cookie-utils.d.ts +7 -0
  43. package/dist/auth/deliverable-address.d.ts +6 -0
  44. package/dist/auth/email-change-routes.d.ts +44 -0
  45. package/dist/auth/expired-token-sweep.d.ts +71 -0
  46. package/dist/auth/impersonation.d.ts +110 -0
  47. package/dist/auth/index.d.ts +4 -2
  48. package/dist/auth/interfaces.d.ts +120 -59
  49. package/dist/auth/jwks-routes.d.ts +5 -1
  50. package/dist/auth/jwt-crypto.d.ts +7 -0
  51. package/dist/auth/jwt-keys.d.ts +4 -0
  52. package/dist/auth/jwt.d.ts +319 -157
  53. package/dist/auth/magic-link-routes.d.ts +5 -6
  54. package/dist/auth/mfa-crypto.d.ts +9 -3
  55. package/dist/auth/mfa-gate.d.ts +4 -2
  56. package/dist/auth/mfa-routes.d.ts +8 -9
  57. package/dist/auth/middleware.d.ts +26 -7
  58. package/dist/auth/otp-routes.d.ts +5 -6
  59. package/dist/auth/passwordless-signup.d.ts +27 -0
  60. package/dist/auth/platform-token.d.ts +122 -0
  61. package/dist/auth/rate-limiter.d.ts +99 -31
  62. package/dist/auth/registration-policy.d.ts +17 -0
  63. package/dist/auth/require-auth.d.ts +1 -1
  64. package/dist/auth/routes.d.ts +61 -0
  65. package/dist/auth/scope-routes.d.ts +22 -0
  66. package/dist/auth/session-routes.d.ts +17 -6
  67. package/dist/auth/token-revocation.d.ts +56 -1
  68. package/dist/auth/user-picking.d.ts +37 -0
  69. package/dist/auth/verify-credential.d.ts +49 -0
  70. package/dist/{auth-B-GIMpDG.js → auth-CSBky1mt.js} +4564 -1929
  71. package/dist/auth-CSBky1mt.js.map +1 -0
  72. package/dist/auth_adapter-CIItCTc8.js +21 -0
  73. package/dist/auth_adapter-CIItCTc8.js.map +1 -0
  74. package/dist/backend/create-backend.d.ts +281 -0
  75. package/dist/backend/default-backend.d.ts +35 -0
  76. package/dist/backend/no-collections.d.ts +19 -0
  77. package/dist/backend/options.d.ts +912 -0
  78. package/dist/backend/scope.d.ts +23 -0
  79. package/dist/backend/services.d.ts +54 -0
  80. package/dist/backend-DTAOsLQc.js.map +1 -1
  81. package/dist/backup/backup-common.d.ts +24 -3
  82. package/dist/backup/backup-routes.d.ts +46 -5
  83. package/dist/backup/backup-schedule.d.ts +33 -0
  84. package/dist/backup/backup-storage.d.ts +16 -0
  85. package/dist/backup/index.d.ts +5 -1
  86. package/dist/backup-DBGRUVTS.js +585 -0
  87. package/dist/backup-DBGRUVTS.js.map +1 -0
  88. package/dist/boot/boot.d.ts +2 -2
  89. package/dist/boot/bundle.d.ts +19 -0
  90. package/dist/boot/driver.d.ts +3 -0
  91. package/dist/boot/env.d.ts +58 -6
  92. package/dist/boot/http-server.d.ts +22 -0
  93. package/dist/boot/options.d.ts +16 -1
  94. package/dist/boot/provision.d.ts +4 -2
  95. package/dist/boot/resource-adapters.d.ts +11 -14
  96. package/dist/boot/runtime-cors.d.ts +17 -0
  97. package/dist/boot/security-headers.d.ts +26 -0
  98. package/dist/boot/sources.d.ts +9 -0
  99. package/dist/boot/static-routing.d.ts +65 -0
  100. package/dist/collection_patch-BRu-BvDv.js +472 -0
  101. package/dist/collection_patch-BRu-BvDv.js.map +1 -0
  102. package/dist/{contract-routes-CbFjuBwa.js → contract-routes-DiFwiLg2.js} +5 -8
  103. package/dist/contract-routes-DiFwiLg2.js.map +1 -0
  104. package/dist/cron/cron-loader.d.ts +77 -18
  105. package/dist/cron/cron-routes.d.ts +1 -1
  106. package/dist/cron/cron-scheduler.d.ts +94 -23
  107. package/dist/cron/cron-store.d.ts +37 -5
  108. package/dist/cron/define-cron.d.ts +6 -2
  109. package/dist/cron/index.d.ts +3 -3
  110. package/dist/cron-loader-NHqRfKF0.js +202 -0
  111. package/dist/cron-loader-NHqRfKF0.js.map +1 -0
  112. package/dist/{cron-routes-eE8nif_b.js → cron-routes-DsH8Jwn5.js} +34 -8
  113. package/dist/cron-routes-DsH8Jwn5.js.map +1 -0
  114. package/dist/{cron-scheduler-B0pLfAix.js → cron-scheduler-D1DT0nw5.js} +349 -65
  115. package/dist/cron-scheduler-D1DT0nw5.js.map +1 -0
  116. package/dist/cron-store-DEpVstUU.js +577 -0
  117. package/dist/cron-store-DEpVstUU.js.map +1 -0
  118. package/dist/{ddl-bootstrap-C6mo0Kmz.js → ddl-bootstrap-BNqi2NZe.js} +2 -2
  119. package/dist/{ddl-bootstrap-C6mo0Kmz.js.map → ddl-bootstrap-BNqi2NZe.js.map} +1 -1
  120. package/dist/email/index.d.ts +2 -2
  121. package/dist/email/smtp-email-service.d.ts +23 -0
  122. package/dist/email/templates.d.ts +22 -0
  123. package/dist/email/types.d.ts +44 -0
  124. package/dist/env.d.ts +1 -39
  125. package/dist/{errors-DWsX4yTd.js → errors-Cqp86KnA.js} +263 -10
  126. package/dist/errors-Cqp86KnA.js.map +1 -0
  127. package/dist/filter-dialect-O1HK6Nvr.js +1628 -0
  128. package/dist/filter-dialect-O1HK6Nvr.js.map +1 -0
  129. package/dist/{function-loader-xnbDAPfa.js → function-loader-DbCSoNJj.js} +69 -39
  130. package/dist/function-loader-DbCSoNJj.js.map +1 -0
  131. package/dist/{function-routes-Chet4-lB.js → function-routes-BSTClQNa.js} +28 -15
  132. package/dist/function-routes-BSTClQNa.js.map +1 -0
  133. package/dist/functions/context.d.ts +26 -6
  134. package/dist/functions/define-function.d.ts +10 -6
  135. package/dist/functions/function-loader.d.ts +75 -18
  136. package/dist/functions/function-routes.d.ts +2 -1
  137. package/dist/functions/guards.d.ts +22 -5
  138. package/dist/functions/index.d.ts +6 -5
  139. package/dist/functions/index.js +148 -50
  140. package/dist/functions/index.js.map +1 -1
  141. package/dist/functions/internal.d.ts +2 -2
  142. package/dist/functions/proxy.d.ts +6 -2
  143. package/dist/functions/request-timeout.d.ts +7 -5
  144. package/dist/history/history-routes.d.ts +9 -0
  145. package/dist/history/retention-sweep.d.ts +81 -0
  146. package/dist/{history-recorder-B4MpJfJK.js → history-recorder-RZ1Ow4YY.js} +4 -4
  147. package/dist/{history-recorder-B4MpJfJK.js.map → history-recorder-RZ1Ow4YY.js.map} +1 -1
  148. package/dist/{history-store-BhxWOuz9.js → history-store-DPofGVDp.js} +2 -2
  149. package/dist/{history-store-BhxWOuz9.js.map → history-store-DPofGVDp.js.map} +1 -1
  150. package/dist/index.d.ts +32 -13
  151. package/dist/index.es.js +25329 -18393
  152. package/dist/index.es.js.map +1 -1
  153. package/dist/init/docs.d.ts +35 -10
  154. package/dist/init/health.d.ts +17 -2
  155. package/dist/init/process-safety.d.ts +7 -2
  156. package/dist/init/shutdown.d.ts +26 -1
  157. package/dist/init.d.ts +49 -811
  158. package/dist/internal-tables-L2t39RdT.js +136 -0
  159. package/dist/internal-tables-L2t39RdT.js.map +1 -0
  160. package/dist/jobs/job-queue.d.ts +8 -0
  161. package/dist/jobs/job-store.d.ts +24 -0
  162. package/dist/jobs/types.d.ts +25 -4
  163. package/dist/{jobs-CazMYhyy.js → jobs-8G-_agld.js} +235 -25
  164. package/dist/jobs-8G-_agld.js.map +1 -0
  165. package/dist/{jwt-DnQHNFCl.js → jwt-CBaFc34Y.js} +546 -447
  166. package/dist/jwt-CBaFc34Y.js.map +1 -0
  167. package/dist/{keys-CogCQpxG.js → keys-COzQ2aE8.js} +3 -17
  168. package/dist/{keys-CogCQpxG.js.map → keys-COzQ2aE8.js.map} +1 -1
  169. package/dist/load-failure-L5hvfDoG.js +80 -0
  170. package/dist/load-failure-L5hvfDoG.js.map +1 -0
  171. package/dist/{logger-DO2PZc4i.js → logger-Bt32sHFw.js} +41 -5
  172. package/dist/logger-Bt32sHFw.js.map +1 -0
  173. package/dist/{logs-routes-Bj4TYYUl.js → logs-routes-DQJhrf-b.js} +48 -8
  174. package/dist/logs-routes-DQJhrf-b.js.map +1 -0
  175. package/dist/mcp/consent-page.d.ts +1 -1
  176. package/dist/mcp/mcp-routes.d.ts +13 -0
  177. package/dist/mcp/mcp-tools.d.ts +23 -9
  178. package/dist/mcp/oauth-metadata.d.ts +21 -16
  179. package/dist/mcp/oauth-routes.d.ts +14 -1
  180. package/dist/metrics/index.d.ts +18 -0
  181. package/dist/metrics/pool-wait.d.ts +50 -0
  182. package/dist/offline-QNQgsPOq-B2yGeXkn.js +3305 -0
  183. package/dist/offline-QNQgsPOq-B2yGeXkn.js.map +1 -0
  184. package/dist/offline-store-Cm5sAX81-CALiO4Gn.js +1915 -0
  185. package/dist/offline-store-Cm5sAX81-CALiO4Gn.js.map +1 -0
  186. package/dist/{openapi-generator-O_O24MAT.js → openapi-generator-CeGW2dLC.js} +455 -80
  187. package/dist/openapi-generator-CeGW2dLC.js.map +1 -0
  188. package/dist/policy-PdzX-Opd.js +121 -0
  189. package/dist/policy-PdzX-Opd.js.map +1 -0
  190. package/dist/project_manifest-R6y_KHms.js +59 -0
  191. package/dist/project_manifest-R6y_KHms.js.map +1 -0
  192. package/dist/{proxy-Czngl3p9.js → proxy-BEKbsil6.js} +5 -4
  193. package/dist/proxy-BEKbsil6.js.map +1 -0
  194. package/dist/{query-parser-DGRVFNM3.js → query-parser-ECxP0nDw.js} +497 -52
  195. package/dist/query-parser-ECxP0nDw.js.map +1 -0
  196. package/dist/{request-timeout-C_4C2BeR.js → request-timeout-BiRelY-U.js} +17 -10
  197. package/dist/request-timeout-BiRelY-U.js.map +1 -0
  198. package/dist/resumable-upload-threshold-CKv-Ry0l.js +24 -0
  199. package/dist/resumable-upload-threshold-CKv-Ry0l.js.map +1 -0
  200. package/dist/schema-edit/apply-schema-change.d.ts +73 -3
  201. package/dist/schema-edit/local-source.d.ts +29 -0
  202. package/dist/schema-edit/project-root.d.ts +3 -2
  203. package/dist/schema-edit/remote-source.d.ts +20 -5
  204. package/dist/schema-edit/source-editor.d.ts +28 -0
  205. package/dist/schema-editor-routes-DRXBAbZy.js +136 -0
  206. package/dist/schema-editor-routes-DRXBAbZy.js.map +1 -0
  207. package/dist/serve-spa.d.ts +58 -0
  208. package/dist/services/outbound-post.d.ts +50 -0
  209. package/dist/services/outbound-url-guard.d.ts +34 -5
  210. package/dist/services/routed-realtime-service.d.ts +16 -0
  211. package/dist/services/webhook-service.d.ts +66 -14
  212. package/dist/singleton.d.ts +9 -5
  213. package/dist/soft-delete-params-CBryZXMq.js +668 -0
  214. package/dist/soft-delete-params-CBryZXMq.js.map +1 -0
  215. package/dist/sql-export-routes-D8ZaRvoR.js +240 -0
  216. package/dist/sql-export-routes-D8ZaRvoR.js.map +1 -0
  217. package/dist/{src-vkcwKXbT.js → src-D5Y3N-S4.js} +440 -20
  218. package/dist/src-D5Y3N-S4.js.map +1 -0
  219. package/dist/storage/GCSStorageController.d.ts +48 -2
  220. package/dist/storage/LocalStorageController.d.ts +69 -2
  221. package/dist/storage/S3StorageController.d.ts +39 -3
  222. package/dist/storage/image-transform.d.ts +15 -0
  223. package/dist/storage/index.d.ts +2 -2
  224. package/dist/storage/maintenance-routes.d.ts +23 -0
  225. package/dist/storage/maintenance.d.ts +126 -0
  226. package/dist/storage/property-limits.d.ts +41 -6
  227. package/dist/storage/rendition-cache.d.ts +9 -11
  228. package/dist/storage/request-keys.d.ts +15 -0
  229. package/dist/storage/request-principals.d.ts +30 -0
  230. package/dist/storage/requested-object.d.ts +74 -0
  231. package/dist/storage/routes.d.ts +52 -14
  232. package/dist/storage/source-variables.d.ts +10 -0
  233. package/dist/storage/streams.d.ts +42 -0
  234. package/dist/storage/tus-handler.d.ts +76 -7
  235. package/dist/storage/types.d.ts +101 -7
  236. package/dist/storage/upload-validation.d.ts +13 -0
  237. package/dist/storage-resumable-VO-cMpse-C_YX71pO.js +125 -0
  238. package/dist/storage-resumable-VO-cMpse-C_YX71pO.js.map +1 -0
  239. package/dist/strings.es-BeZWAodn.js +256 -0
  240. package/dist/strings.es-BeZWAodn.js.map +1 -0
  241. package/dist/upload-validation-CVobI5xO.js +172 -0
  242. package/dist/upload-validation-CVobI5xO.js.map +1 -0
  243. package/dist/utils/byte-size.d.ts +10 -0
  244. package/dist/utils/compression.d.ts +6 -0
  245. package/dist/utils/load-failure.d.ts +14 -0
  246. package/dist/utils/logger.d.ts +21 -0
  247. package/package.json +5 -5
  248. package/dist/GCSStorageController-CjrA4PMo.js +0 -242
  249. package/dist/GCSStorageController-CjrA4PMo.js.map +0 -1
  250. package/dist/S3StorageController-B6pKDNVj.js +0 -264
  251. package/dist/S3StorageController-B6pKDNVj.js.map +0 -1
  252. package/dist/admin-roles-vYdp_Pil.js +0 -36
  253. package/dist/admin-roles-vYdp_Pil.js.map +0 -1
  254. package/dist/admin_block-DxKLmdiv.js +0 -206
  255. package/dist/admin_block-DxKLmdiv.js.map +0 -1
  256. package/dist/ast-schema-editor-Mvr50v_S.js.map +0 -1
  257. package/dist/auth/api-keys/api-key-permission-guard.d.ts +0 -65
  258. package/dist/auth-B-GIMpDG.js.map +0 -1
  259. package/dist/backup-D7YR94N3.js +0 -253
  260. package/dist/backup-D7YR94N3.js.map +0 -1
  261. package/dist/contract-routes-CbFjuBwa.js.map +0 -1
  262. package/dist/cron-loader-DfTj2Hbi.js +0 -118
  263. package/dist/cron-loader-DfTj2Hbi.js.map +0 -1
  264. package/dist/cron-routes-eE8nif_b.js.map +0 -1
  265. package/dist/cron-scheduler-B0pLfAix.js.map +0 -1
  266. package/dist/cron-store-TcoGz-xS.js +0 -305
  267. package/dist/cron-store-TcoGz-xS.js.map +0 -1
  268. package/dist/dynamic-import-X40pTZUQ.js +0 -23
  269. package/dist/dynamic-import-X40pTZUQ.js.map +0 -1
  270. package/dist/errors-DWsX4yTd.js.map +0 -1
  271. package/dist/function-loader-xnbDAPfa.js.map +0 -1
  272. package/dist/function-routes-Chet4-lB.js.map +0 -1
  273. package/dist/jobs-CazMYhyy.js.map +0 -1
  274. package/dist/jwt-DnQHNFCl.js.map +0 -1
  275. package/dist/logger-DO2PZc4i.js.map +0 -1
  276. package/dist/logs-routes-Bj4TYYUl.js.map +0 -1
  277. package/dist/openapi-generator-O_O24MAT.js.map +0 -1
  278. package/dist/proxy-Czngl3p9.js.map +0 -1
  279. package/dist/query-parser-DGRVFNM3.js.map +0 -1
  280. package/dist/request-timeout-C_4C2BeR.js.map +0 -1
  281. package/dist/schema-editor-routes-C5-lh_jO.js +0 -87
  282. package/dist/schema-editor-routes-C5-lh_jO.js.map +0 -1
  283. package/dist/src-pmvW7BFx.js +0 -6688
  284. package/dist/src-pmvW7BFx.js.map +0 -1
  285. package/dist/src-vkcwKXbT.js.map +0 -1
  286. package/dist/types-BfKcm9do.js +0 -39
  287. package/dist/types-BfKcm9do.js.map +0 -1
@@ -16,16 +16,19 @@
16
16
  * - A write can fail with a permission error the tool cannot explain in
17
17
  * detail, because the policy that refused it is not visible from here.
18
18
  *
19
- * `mcp:write` gates whether the mutating tools are *offered* at all. It is a
20
- * second lock, not the main one — a `mcp:write` token still cannot write a row
21
- * the user could not write themselves.
19
+ * The scopes gate which tools are *offered* and which collections each
20
+ * reaches — `data:write:posts` offers the write tools for `posts` alone. That
21
+ * is a second lock, not the main one: a `data:write` token still cannot write
22
+ * a row the user could not write themselves.
22
23
  */
23
24
  import type { AuthAdapter, CollectionConfig, DataDriver } from "@rebasepro/types";
25
+ import type { McpScope } from "./oauth-metadata.js";
24
26
  /** The identity a tool call runs as. Comes from the verified access token. */
25
27
  export interface McpCaller {
26
28
  uid: string;
27
29
  roles: string[];
28
- scope: string;
30
+ /** The scopes granted to this connection — `data:read`, `data:write:posts`, … */
31
+ scopes: string[];
29
32
  clientId: string;
30
33
  }
31
34
  export interface McpToolContext {
@@ -43,15 +46,26 @@ export interface McpToolDefinition {
43
46
  name: string;
44
47
  description: string;
45
48
  inputSchema: Record<string, unknown>;
46
- /** The scope a caller must hold for this tool to be listed or callable. */
47
- requiredScope: "mcp:read" | "mcp:write";
49
+ /**
50
+ * The scope a caller must hold — on at least one collection for the tool
51
+ * to be listed, and on the collection a call names for it to run.
52
+ */
53
+ requiredScope: McpScope;
54
+ /**
55
+ * Whether the reply carries the result a second time, as
56
+ * `structuredContent`. The text block always carries it — it is what a
57
+ * model reads. A result a program consumes (rows, a count, a write's
58
+ * outcome) also goes out as typed data; one only a model reads does not,
59
+ * so the reply is not twice its size. Defaults to true.
60
+ */
61
+ structuredContent?: boolean;
48
62
  run(args: Record<string, unknown>, ctx: McpToolContext): Promise<unknown>;
49
63
  }
50
64
  /** An error whose message is safe to hand back to the model. */
51
65
  export declare class McpToolError extends Error {
52
66
  }
53
67
  export declare const MCP_TOOLS: McpToolDefinition[];
54
- /** The tools a caller holding `scope` may see and call. */
55
- export declare function toolsForScope(scope: string): McpToolDefinition[];
68
+ /** The tools a caller holding `scopes` may see and call: each needs its scope on at least one collection. */
69
+ export declare function toolsForScopes(scopes: readonly string[]): McpToolDefinition[];
56
70
  /** Look up a tool by name, honouring scope — an unlisted tool is not callable. */
57
- export declare function findTool(name: string, scope: string): McpToolDefinition | undefined;
71
+ export declare function findTool(name: string, scopes: readonly string[]): McpToolDefinition | undefined;
@@ -1,20 +1,24 @@
1
1
  /**
2
- * What a token may do at `/mcp`.
2
+ * What a token may do at `/mcp`: the data-plane scopes its tools need, in the
3
+ * vocabulary every other credential uses — `data:read`, `data:write`,
4
+ * `data:delete` — each narrowable to one collection (`data:read:posts`).
3
5
  *
4
- * Two, and no more. RFC 9728 asks `scopes_supported` to be the minimal set that
5
- * makes the resource usable, and the MCP specification's scope-minimization
6
- * guidance points the same way: a client that only needs to read should be able
7
- * to ask for exactly that, and a consent screen listing eleven fine-grained
8
- * permissions is one nobody reads.
9
- *
10
- * They are not a substitute for RLS. A `mcp:read` token still reads through the
11
- * user's own policies — the scope decides whether the tool exists for this
12
- * session, the database decides which rows come back.
6
+ * They are not a substitute for RLS. A `data:read` token still reads through
7
+ * the user's own policies — the scope decides whether a tool exists for this
8
+ * session and which collections it reaches; the database decides which rows
9
+ * come back.
13
10
  */
14
- export declare const MCP_SCOPES: readonly ["mcp:read", "mcp:write"];
11
+ export declare const MCP_SCOPES: readonly ["data:read", "data:write", "data:delete"];
15
12
  export type McpScope = (typeof MCP_SCOPES)[number];
16
13
  /** The scope a client gets when it asks for nothing in particular. */
17
- export declare const DEFAULT_MCP_SCOPE = "mcp:read";
14
+ export declare const DEFAULT_MCP_SCOPE = "data:read";
15
+ /**
16
+ * A scope string as granted before `/mcp` spoke the shared vocabulary, read as
17
+ * what it granted: `mcp:read` was every read, `mcp:write` every create, change
18
+ * and delete. Applied to stored refresh grants and to access tokens still in
19
+ * flight, so a connection made before the change keeps exactly its reach.
20
+ */
21
+ export declare function upgradeStoredMcpScope(scope: string): string;
18
22
  /**
19
23
  * The canonical resource identifier for this server's MCP endpoint.
20
24
  *
@@ -93,12 +97,13 @@ export declare function redirectUriAllowed(candidate: string, registered: string
93
97
  *
94
98
  * An unknown scope is dropped rather than refused. RFC 6749 §3.3 allows either,
95
99
  * and dropping is what keeps a client that asks for `openid profile email` out
96
- * of habit from failing to connect at all — it gets the MCP scopes it is
97
- * entitled to and none of the ones it invented.
100
+ * of habit from failing to connect at all — it gets the data scopes it is
101
+ * entitled to and none of the ones it invented. A collection target is kept:
102
+ * `data:read:posts` is a narrower grant, never a wider one.
98
103
  */
99
104
  export declare function narrowScope(requested: string | undefined | null): string;
100
- /** Does a granted scope string carry this permission? */
101
- export declare function scopeAllows(scope: string, needed: McpScope): boolean;
105
+ /** A granted scope string as the list of scopes it holds. */
106
+ export declare function scopeList(scope: string): string[];
102
107
  /**
103
108
  * The `WWW-Authenticate` value for an unauthenticated request.
104
109
  *
@@ -25,10 +25,17 @@
25
25
  */
26
26
  import { Hono } from "hono";
27
27
  import type { HonoEnv } from "../api/types.js";
28
+ import { type JwtService } from "../auth/jwt.js";
28
29
  import type { AuthRepository } from "../auth/interfaces.js";
29
30
  import type { OAuthStore } from "./oauth-store.js";
30
31
  export interface OAuthRoutesConfig {
31
32
  store: OAuthStore;
33
+ /**
34
+ * The backend this authorization server issues for: its key signs the
35
+ * MCP access tokens and the authorize-request token, and verifies the
36
+ * person's session at consent. The process default when omitted.
37
+ */
38
+ jwt?: JwtService;
32
39
  /** The externally reachable origin of this deployment. */
33
40
  publicUrl: string;
34
41
  /** Where `/mcp` is mounted, e.g. `/mcp`. */
@@ -72,7 +79,13 @@ export declare function createOAuthRoutes(config: OAuthRoutesConfig): Hono<HonoE
72
79
  * means a stored row is never itself the hazard.
73
80
  */
74
81
  export declare function redirectUriProblem(uri: string): string | null;
75
- /** Human-readable consent lines, one per granted scope. */
82
+ /**
83
+ * Human-readable consent lines, one per granted scope.
84
+ *
85
+ * Worded for the person consenting, not taken from the scope catalogue: what
86
+ * they need to read here is that the client gets *their own* access and no
87
+ * more, and which collections it reaches when the grant names some.
88
+ */
76
89
  export declare function describeScopes(scope: string): {
77
90
  scope: string;
78
91
  description: string;
@@ -31,11 +31,24 @@ export type MetricSurface = "data" | "auth" | "storage" | "functions" | "admin"
31
31
  | "other";
32
32
  /** Whether a path is the platform looking in, rather than a request served. */
33
33
  export declare function isUncountedPath(pathname: string): boolean;
34
+ /**
35
+ * How long a query waited for a pooled database connection, in milliseconds —
36
+ * opening one included, when the pool had to. Labelled by data source. See
37
+ * `pool-wait.ts`, which records it, and why it matters there.
38
+ */
39
+ export declare const DB_POOL_WAIT_METRIC = "rebase_db_pool_wait_ms";
40
+ /**
41
+ * Buckets for {@link DB_POOL_WAIT_METRIC}. A checkout from a pool with an idle
42
+ * connection takes well under a millisecond, so the low end is finer than a
43
+ * request's: the interesting number is how much of the tail is above zero.
44
+ */
45
+ export declare const POOL_WAIT_BUCKETS_MS: number[];
34
46
  export declare class MetricsRegistry {
35
47
  private requests;
36
48
  private latency;
37
49
  private gauges;
38
50
  private counters;
51
+ private histograms;
39
52
  readonly startedAt: number;
40
53
  private static labelKey;
41
54
  private static parseLabels;
@@ -51,6 +64,11 @@ export declare class MetricsRegistry {
51
64
  recordRequest(labels: Record<string, string>, durationMs: number): void;
52
65
  incrementCounter(name: string, labels?: Record<string, string>, by?: number): void;
53
66
  setGauge(name: string, value: number, labels?: Record<string, string>): void;
67
+ /**
68
+ * Record one observation in a named histogram. `buckets` are its upper
69
+ * bounds, fixed by the first observation of the series.
70
+ */
71
+ observe(name: string, value: number, labels?: Record<string, string>, buckets?: readonly number[]): void;
54
72
  /** Prometheus escaping: backslash, quote and newline, in that order. */
55
73
  private static formatLabels;
56
74
  /** Group `name -> [[labelKey, value]]` for one-HELP-per-metric rendering. */
@@ -0,0 +1,50 @@
1
+ /**
2
+ * How long queries wait for a pooled database connection.
3
+ *
4
+ * A write holds its connection — and its transaction, and the locks it has
5
+ * taken — for as long as its callbacks run: `beforeSave` runs after the
6
+ * transaction has begun, `afterSave` before it commits. Callbacks that await
7
+ * something slow therefore take connections out of the pool for that long, and
8
+ * once enough of them run at once every other request queues for one. Measured
9
+ * with the default pool of 20: 25 concurrent saves whose `beforeSave` awaited
10
+ * 300 ms made an unrelated one-row read wait 290 ms for a connection.
11
+ *
12
+ * Nothing else shows that queue. Request latency rises, but so it does for a
13
+ * slow query; this histogram says how much of a request was spent waiting for
14
+ * a connection at all. Near zero is a healthy pool.
15
+ *
16
+ * @module
17
+ */
18
+ import { type MetricsRegistry } from "./index.js";
19
+ /** `pg.Pool`'s callback form of `connect`, which `pool.query` uses internally. */
20
+ type ConnectCallback = (err: Error | undefined, client: unknown, done: (release?: unknown) => void) => void;
21
+ /**
22
+ * `connect` as a `pg.Pool` has it: a promise without a callback, the callback
23
+ * with one. Both are timed — transactions check out with the first,
24
+ * `pool.query` with the second.
25
+ */
26
+ export type PoolConnect = (callback?: ConnectCallback) => Promise<unknown> | void;
27
+ /**
28
+ * Time every checkout from `pool`, from the call to the moment a connection is
29
+ * handed over, and report it to `record` in milliseconds. A failed checkout is
30
+ * not recorded: it is an error, not a wait.
31
+ *
32
+ * Wraps `connect` on this pool object only. `false` when the pool has no
33
+ * `connect` to time (a driver that is not pool-based) or is timed already.
34
+ */
35
+ export declare function timePoolCheckouts(pool: {
36
+ connect?: PoolConnect;
37
+ }, record: (waitMs: number) => void): boolean;
38
+ /**
39
+ * Time the checkouts of every pool-based data source into `registry`'s
40
+ * {@link DB_POOL_WAIT_METRIC} histogram, labelled by the source's key.
41
+ */
42
+ export declare function recordPoolWaits(registry: MetricsRegistry, sources: readonly {
43
+ key: string;
44
+ connection: {
45
+ pool?: {
46
+ connect?: PoolConnect;
47
+ };
48
+ };
49
+ }[]): void;
50
+ export {};