@rebasepro/server 0.23.0 → 0.24.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 (181) hide show
  1. package/README.md +1 -1
  2. package/bin/rebase-server.js +4 -2
  3. package/dist/{GCSStorageController-CjrA4PMo.js → GCSStorageController-BSiP1c-f.js} +22 -8
  4. package/dist/GCSStorageController-BSiP1c-f.js.map +1 -0
  5. package/dist/{S3StorageController-B6pKDNVj.js → S3StorageController-CAwFRgjV.js} +19 -7
  6. package/dist/S3StorageController-CAwFRgjV.js.map +1 -0
  7. package/dist/api/ast-schema-editor.d.ts +92 -1
  8. package/dist/api/errors.d.ts +9 -0
  9. package/dist/api/live-schema-routes.d.ts +38 -8
  10. package/dist/api/logs-routes.d.ts +39 -1
  11. package/dist/api/openapi-generator.d.ts +17 -0
  12. package/dist/api/rest/api-generator.d.ts +44 -10
  13. package/dist/api/rest/write-validation.d.ts +2 -2
  14. package/dist/api/types.d.ts +17 -1
  15. package/dist/{ast-schema-editor-Mvr50v_S.js → ast-schema-editor-CWqS_sLJ.js} +309 -11
  16. package/dist/ast-schema-editor-CWqS_sLJ.js.map +1 -0
  17. package/dist/auth/access.d.ts +105 -0
  18. package/dist/auth/adapter-middleware.d.ts +2 -1
  19. package/dist/auth/address-ownership.d.ts +16 -1
  20. package/dist/auth/admin-roles-route.d.ts +4 -2
  21. package/dist/auth/admin-roles.d.ts +17 -20
  22. package/dist/auth/admin-users-route.d.ts +1 -0
  23. package/dist/auth/api-keys/api-key-middleware.d.ts +56 -55
  24. package/dist/auth/api-keys/api-key-routes.d.ts +41 -11
  25. package/dist/auth/api-keys/api-key-store.d.ts +31 -8
  26. package/dist/auth/api-keys/api-key-types.d.ts +14 -16
  27. package/dist/auth/api-keys/http-operation.d.ts +19 -0
  28. package/dist/auth/api-keys/index.d.ts +11 -11
  29. package/dist/auth/api-keys/key-grant.d.ts +41 -0
  30. package/dist/auth/api-keys/legacy-permissions.d.ts +33 -0
  31. package/dist/auth/auth-hooks.d.ts +46 -7
  32. package/dist/auth/builtin-auth-adapter.d.ts +8 -0
  33. package/dist/auth/cookie-utils.d.ts +7 -0
  34. package/dist/auth/deliverable-address.d.ts +6 -0
  35. package/dist/auth/email-change-routes.d.ts +41 -0
  36. package/dist/auth/expired-token-sweep.d.ts +67 -0
  37. package/dist/auth/impersonation.d.ts +110 -0
  38. package/dist/auth/index.d.ts +4 -2
  39. package/dist/auth/interfaces.d.ts +110 -59
  40. package/dist/auth/jwt.d.ts +49 -3
  41. package/dist/auth/magic-link-routes.d.ts +2 -6
  42. package/dist/auth/mfa-routes.d.ts +2 -9
  43. package/dist/auth/middleware.d.ts +17 -5
  44. package/dist/auth/otp-routes.d.ts +2 -6
  45. package/dist/auth/passwordless-signup.d.ts +27 -0
  46. package/dist/auth/platform-token.d.ts +122 -0
  47. package/dist/auth/rate-limiter.d.ts +41 -0
  48. package/dist/auth/routes.d.ts +45 -0
  49. package/dist/auth/scope-routes.d.ts +22 -0
  50. package/dist/auth/session-routes.d.ts +11 -6
  51. package/dist/auth/token-revocation.d.ts +50 -1
  52. package/dist/auth/verify-credential.d.ts +28 -0
  53. package/dist/{auth-B-GIMpDG.js → auth-DMLngxn_.js} +2159 -569
  54. package/dist/auth-DMLngxn_.js.map +1 -0
  55. package/dist/backend-DTAOsLQc.js.map +1 -1
  56. package/dist/backup/backup-common.d.ts +10 -0
  57. package/dist/backup/backup-routes.d.ts +24 -4
  58. package/dist/backup/backup-schedule.d.ts +33 -0
  59. package/dist/backup/backup-storage.d.ts +14 -0
  60. package/dist/backup/index.d.ts +2 -0
  61. package/dist/backup-CN0s50D2.js +444 -0
  62. package/dist/backup-CN0s50D2.js.map +1 -0
  63. package/dist/boot/bundle.d.ts +19 -0
  64. package/dist/boot/env.d.ts +49 -4
  65. package/dist/boot/security-headers.d.ts +26 -0
  66. package/dist/boot/static-routing.d.ts +56 -0
  67. package/dist/collection_patch-BRu-BvDv.js +472 -0
  68. package/dist/collection_patch-BRu-BvDv.js.map +1 -0
  69. package/dist/{contract-routes-CbFjuBwa.js → contract-routes-fz8i4pxs.js} +17 -4
  70. package/dist/contract-routes-fz8i4pxs.js.map +1 -0
  71. package/dist/cron/cron-scheduler.d.ts +25 -20
  72. package/dist/cron/cron-store.d.ts +6 -2
  73. package/dist/{cron-loader-DfTj2Hbi.js → cron-loader-CwaANlOG.js} +4 -4
  74. package/dist/cron-loader-CwaANlOG.js.map +1 -0
  75. package/dist/{cron-routes-eE8nif_b.js → cron-routes-Bc-SB0Se.js} +10 -7
  76. package/dist/cron-routes-Bc-SB0Se.js.map +1 -0
  77. package/dist/{cron-scheduler-B0pLfAix.js → cron-scheduler-CYQgco86.js} +52 -34
  78. package/dist/cron-scheduler-CYQgco86.js.map +1 -0
  79. package/dist/{cron-store-TcoGz-xS.js → cron-store-D2Q9-Aco.js} +10 -15
  80. package/dist/cron-store-D2Q9-Aco.js.map +1 -0
  81. package/dist/{ddl-bootstrap-C6mo0Kmz.js → ddl-bootstrap-BaqMSa4Y.js} +2 -2
  82. package/dist/{ddl-bootstrap-C6mo0Kmz.js.map → ddl-bootstrap-BaqMSa4Y.js.map} +1 -1
  83. package/dist/email/index.d.ts +2 -2
  84. package/dist/email/templates.d.ts +22 -0
  85. package/dist/email/types.d.ts +26 -0
  86. package/dist/env.d.ts +1 -2
  87. package/dist/{errors-DWsX4yTd.js → errors-D6_y86c5.js} +102 -8
  88. package/dist/errors-D6_y86c5.js.map +1 -0
  89. package/dist/{function-loader-xnbDAPfa.js → function-loader-D7o5Epjj.js} +2 -2
  90. package/dist/{function-loader-xnbDAPfa.js.map → function-loader-D7o5Epjj.js.map} +1 -1
  91. package/dist/{function-routes-Chet4-lB.js → function-routes-CaNG4waN.js} +24 -12
  92. package/dist/function-routes-CaNG4waN.js.map +1 -0
  93. package/dist/functions/context.d.ts +17 -6
  94. package/dist/functions/guards.d.ts +22 -5
  95. package/dist/functions/index.d.ts +2 -2
  96. package/dist/functions/index.js +90 -36
  97. package/dist/functions/index.js.map +1 -1
  98. package/dist/{history-recorder-B4MpJfJK.js → history-recorder-Nr8zLvoU.js} +4 -4
  99. package/dist/{history-recorder-B4MpJfJK.js.map → history-recorder-Nr8zLvoU.js.map} +1 -1
  100. package/dist/{history-store-BhxWOuz9.js → history-store-rcAm_xFR.js} +2 -2
  101. package/dist/{history-store-BhxWOuz9.js.map → history-store-rcAm_xFR.js.map} +1 -1
  102. package/dist/index.d.ts +8 -2
  103. package/dist/index.es.js +3084 -753
  104. package/dist/index.es.js.map +1 -1
  105. package/dist/init/health.d.ts +17 -2
  106. package/dist/init/shutdown.d.ts +10 -0
  107. package/dist/init.d.ts +54 -0
  108. package/dist/{jobs-CazMYhyy.js → jobs-DqYNfquG.js} +5 -5
  109. package/dist/{jobs-CazMYhyy.js.map → jobs-DqYNfquG.js.map} +1 -1
  110. package/dist/{jwt-DnQHNFCl.js → jwt-R6bSPMjk.js} +39 -15
  111. package/dist/{jwt-DnQHNFCl.js.map → jwt-R6bSPMjk.js.map} +1 -1
  112. package/dist/{keys-CogCQpxG.js → keys-GAVZqbqx.js} +3 -17
  113. package/dist/{keys-CogCQpxG.js.map → keys-GAVZqbqx.js.map} +1 -1
  114. package/dist/{logger-DO2PZc4i.js → logger-D-S-hO5e.js} +26 -3
  115. package/dist/logger-D-S-hO5e.js.map +1 -0
  116. package/dist/{logs-routes-Bj4TYYUl.js → logs-routes-DAdv37GI.js} +48 -8
  117. package/dist/logs-routes-DAdv37GI.js.map +1 -0
  118. package/dist/mcp/consent-page.d.ts +1 -1
  119. package/dist/mcp/mcp-routes.d.ts +7 -0
  120. package/dist/mcp/mcp-tools.d.ts +15 -9
  121. package/dist/mcp/oauth-metadata.d.ts +21 -16
  122. package/dist/mcp/oauth-routes.d.ts +7 -1
  123. package/dist/{openapi-generator-O_O24MAT.js → openapi-generator-DAq_XVDu.js} +104 -13
  124. package/dist/openapi-generator-DAq_XVDu.js.map +1 -0
  125. package/dist/{proxy-Czngl3p9.js → proxy-qRlqeUmO.js} +2 -2
  126. package/dist/{proxy-Czngl3p9.js.map → proxy-qRlqeUmO.js.map} +1 -1
  127. package/dist/{query-parser-DGRVFNM3.js → query-parser-BgiKJKvc.js} +6 -56
  128. package/dist/query-parser-BgiKJKvc.js.map +1 -0
  129. package/dist/{request-timeout-C_4C2BeR.js → request-timeout-DgH7j8qO.js} +3 -3
  130. package/dist/{request-timeout-C_4C2BeR.js.map → request-timeout-DgH7j8qO.js.map} +1 -1
  131. package/dist/schema-edit/apply-schema-change.d.ts +63 -3
  132. package/dist/schema-edit/project-root.d.ts +3 -2
  133. package/dist/schema-edit/remote-source.d.ts +9 -4
  134. package/dist/{schema-editor-routes-C5-lh_jO.js → schema-editor-routes-oIyuWl3L.js} +12 -7
  135. package/dist/schema-editor-routes-oIyuWl3L.js.map +1 -0
  136. package/dist/serve-spa.d.ts +58 -0
  137. package/dist/services/routed-realtime-service.d.ts +11 -0
  138. package/dist/soft-delete-params-BWPilMPF.js +59 -0
  139. package/dist/soft-delete-params-BWPilMPF.js.map +1 -0
  140. package/dist/{src-vkcwKXbT.js → src-CatHFUym.js} +439 -20
  141. package/dist/src-CatHFUym.js.map +1 -0
  142. package/dist/{src-pmvW7BFx.js → src-I3aG1PcY.js} +252 -70
  143. package/dist/src-I3aG1PcY.js.map +1 -0
  144. package/dist/storage/GCSStorageController.d.ts +2 -0
  145. package/dist/storage/LocalStorageController.d.ts +2 -0
  146. package/dist/storage/S3StorageController.d.ts +2 -0
  147. package/dist/storage/index.d.ts +2 -2
  148. package/dist/storage/property-limits.d.ts +41 -6
  149. package/dist/storage/request-keys.d.ts +15 -0
  150. package/dist/storage/requested-object.d.ts +74 -0
  151. package/dist/storage/routes.d.ts +36 -18
  152. package/dist/storage/tus-handler.d.ts +30 -5
  153. package/dist/storage/types.d.ts +19 -0
  154. package/dist/types-BfKcm9do.js.map +1 -1
  155. package/dist/utils/logger.d.ts +12 -0
  156. package/package.json +5 -5
  157. package/dist/GCSStorageController-CjrA4PMo.js.map +0 -1
  158. package/dist/S3StorageController-B6pKDNVj.js.map +0 -1
  159. package/dist/admin-roles-vYdp_Pil.js +0 -36
  160. package/dist/admin-roles-vYdp_Pil.js.map +0 -1
  161. package/dist/admin_block-DxKLmdiv.js +0 -206
  162. package/dist/admin_block-DxKLmdiv.js.map +0 -1
  163. package/dist/ast-schema-editor-Mvr50v_S.js.map +0 -1
  164. package/dist/auth/api-keys/api-key-permission-guard.d.ts +0 -65
  165. package/dist/auth-B-GIMpDG.js.map +0 -1
  166. package/dist/backup-D7YR94N3.js +0 -253
  167. package/dist/backup-D7YR94N3.js.map +0 -1
  168. package/dist/contract-routes-CbFjuBwa.js.map +0 -1
  169. package/dist/cron-loader-DfTj2Hbi.js.map +0 -1
  170. package/dist/cron-routes-eE8nif_b.js.map +0 -1
  171. package/dist/cron-scheduler-B0pLfAix.js.map +0 -1
  172. package/dist/cron-store-TcoGz-xS.js.map +0 -1
  173. package/dist/errors-DWsX4yTd.js.map +0 -1
  174. package/dist/function-routes-Chet4-lB.js.map +0 -1
  175. package/dist/logger-DO2PZc4i.js.map +0 -1
  176. package/dist/logs-routes-Bj4TYYUl.js.map +0 -1
  177. package/dist/openapi-generator-O_O24MAT.js.map +0 -1
  178. package/dist/query-parser-DGRVFNM3.js.map +0 -1
  179. package/dist/schema-editor-routes-C5-lh_jO.js.map +0 -1
  180. package/dist/src-pmvW7BFx.js.map +0 -1
  181. package/dist/src-vkcwKXbT.js.map +0 -1
@@ -233,31 +233,33 @@ function defineFunction(definition) {
233
233
  //#endregion
234
234
  //#region src/auth/admin-roles.ts
235
235
  /**
236
- * Which role names carry administrative privilege.
237
- *
238
- * One definition, because there used to be several and they disagreed.
239
- * `requireAdmin` accepted `admin` **or** `schema-admin`; the guard that refuses
240
- * a dangerous `defaultRole` compared against `admin` alone. So
241
- * `AUTH_DEFAULT_ROLE=schema-admin` passed the guard and made every public
242
- * registrant an administrator — and, since a `schema-admin` may edit users, one
243
- * of them could then grant themselves real `admin` and keep it.
244
- *
245
- * The guard and the check have to read the same list or the gap comes back, so
246
- * neither of them owns it.
247
- *
248
- * `schema-admin` is here deliberately: it can reach the schema editor and the
249
- * SQL surfaces, which is administrative by any definition that matters. If a
250
- * genuinely lesser role is added later, it does not belong in this list — it
251
- * belongs in a capability check of its own.
236
+ * The admin role and scope matching, for code that may not import
237
+ * `@rebasepro/types`.
238
+ *
239
+ * The custom-functions surface (`@rebasepro/server/functions`) must bundle for
240
+ * a runtime with no Node built-ins and imports nothing but `hono`, so its
241
+ * guards cannot reach the canonical definitions in `@rebasepro/types`
242
+ * (`ADMIN_ROLE`, `hasAdminRole`, `scopeGrants`). These are the same rules,
243
+ * restated, and `test/admin-roles.test.ts` holds them equal.
244
+ *
245
+ * Everything else imports the `@rebasepro/types` versions.
252
246
  */
253
- var ADMINISTRATIVE_ROLES = ["admin", "schema-admin"];
254
- /** Does this single role name carry administrative privilege? */
255
- function isAdministrativeRole(role) {
256
- return ADMINISTRATIVE_ROLES.includes(role);
247
+ /** The one built-in role. It holds every scope. */
248
+ var ADMIN_ROLE_NAME = "admin";
249
+ /** Does this list of roles include the admin role? */
250
+ function holdsAdminRole(roles) {
251
+ return !!roles?.includes(ADMIN_ROLE_NAME);
257
252
  }
258
- /** Does any role in this list carry administrative privilege? */
259
- function hasAdministrativeRole(roles) {
260
- return !!roles?.some(isAdministrativeRole);
253
+ /**
254
+ * Does a set of held scopes grant `scope`, optionally on one `target`? The
255
+ * unqualified grant covers every target; `scope:target` covers its own.
256
+ */
257
+ function heldScopesGrant(held, scope, target) {
258
+ for (const entry of held) {
259
+ if (entry === scope) return true;
260
+ if (target !== void 0 && entry === `${scope}:${target}`) return true;
261
+ }
262
+ return false;
261
263
  }
262
264
  //#endregion
263
265
  //#region src/functions/context.ts
@@ -310,16 +312,31 @@ function hasRole(c, ...roles) {
310
312
  const held = new Set(getRoles(c));
311
313
  return roles.some((role) => held.has(role));
312
314
  }
315
+ /** Whether the caller holds the `admin` role, which holds every scope. */
316
+ function isAdmin(c) {
317
+ return holdsAdminRole(getRoles(c));
318
+ }
313
319
  /**
314
- * Whether the caller holds an administrative role.
320
+ * Everything the caller may do, as `resource:action[:target]` scope strings —
321
+ * the data plane, the app's own `auth.scopes`, and whatever their roles (or
322
+ * their API key) hold. Empty for an anonymous request.
315
323
  *
316
- * Delegates to the single definition in `auth/admin-roles.ts` — which is
317
- * `admin` **or** `schema-admin` — rather than comparing against `"admin"`.
318
- * Those two lists disagreed once, and the gap made every public registrant an
319
- * administrator; see that file.
324
+ * Resolved by the framework before the handler runs; `undefined` only when no
325
+ * Rebase auth middleware ran (see {@link identityResolved}).
320
326
  */
321
- function isAdmin(c) {
322
- return hasAdministrativeRole(getRoles(c));
327
+ function getScopes(c) {
328
+ return read(c, "scopes");
329
+ }
330
+ /**
331
+ * Whether the caller holds `scope`, on `target` when one is given.
332
+ *
333
+ * For an app scope declared under `auth.scopes` — `project:deploy` — a
334
+ * signed-in person always holds it, so this narrows only API keys and tokens.
335
+ * Whether the *person* may deploy *this* project is still the handler's to
336
+ * decide.
337
+ */
338
+ function hasScope(c, scope, target) {
339
+ return heldScopesGrant(getScopes(c) ?? [], scope, target);
323
340
  }
324
341
  /** Whether the request carries an identity at all. */
325
342
  function isAuthenticated(c) {
@@ -428,15 +445,14 @@ var requireAuth = async (c, next) => {
428
445
  } }, 401);
429
446
  };
430
447
  /**
431
- * Reject callers without an administrative role with 403.
448
+ * Reject callers without the `admin` role with 403.
432
449
  *
433
450
  * Must come **after** {@link requireAuth}: on its own it answers 401 for an
434
451
  * anonymous caller, which is right, but pairing them keeps the two failures
435
452
  * distinguishable — 401 "who are you", 403 "not you".
436
453
  *
437
- * Administrative means `admin` or `schema-admin`, from the single list in
438
- * `auth/admin-roles.ts`. Do not compare against `"admin"` by hand; that is the
439
- * divergence that list exists to prevent.
454
+ * Prefer {@link requireScope} for anything an app declares a scope for: a
455
+ * scope can be granted to a narrower role and to a key, and `admin` cannot.
440
456
  */
441
457
  var requireAdmin = async (c, next) => {
442
458
  if (!getUser(c)) {
@@ -483,6 +499,44 @@ function requireRole(...roles) {
483
499
  return next();
484
500
  };
485
501
  }
502
+ /**
503
+ * Reject callers who do not hold `scope` with 403.
504
+ *
505
+ * `scope` is a built-in scope or one the app declares under `auth.scopes` on
506
+ * the users collection. `target` narrows it to one resource — a key holding
507
+ * `project:deploy:p1` passes `requireScope("project:deploy", c => c.req.param("project"))`
508
+ * for `p1` only — and may be read from the request.
509
+ *
510
+ * A signed-in person holds every app scope, so for a person this is no
511
+ * authorization at all: it narrows API keys and tokens. Decide whether the
512
+ * person may act in the handler, as you would without it.
513
+ *
514
+ * @example
515
+ * ```ts
516
+ * app.post("/deploy/:project", requireAuth, requireScope("project:deploy", c => c.req.param("project")), handler);
517
+ * ```
518
+ */
519
+ function requireScope(scope, target) {
520
+ return async (c, next) => {
521
+ if (!getUser(c)) {
522
+ if (!identityResolved(c)) return c.json(unresolvedIdentity(), 500);
523
+ return c.json({ error: {
524
+ message: "Authentication required",
525
+ code: "UNAUTHORIZED"
526
+ } }, 401);
527
+ }
528
+ const resolvedTarget = typeof target === "function" ? target(c) : target;
529
+ if (!hasScope(c, scope, resolvedTarget)) {
530
+ const wanted = resolvedTarget !== void 0 ? `${scope}:${resolvedTarget}` : scope;
531
+ return c.json({ error: {
532
+ message: `This credential does not hold the "${wanted}" scope.`,
533
+ code: "SCOPE_MISSING",
534
+ details: { requiredScope: wanted }
535
+ } }, 403);
536
+ }
537
+ return next();
538
+ };
539
+ }
486
540
  //#endregion
487
541
  //#region src/functions/runtime-env.ts
488
542
  /**
@@ -634,7 +688,7 @@ function isProduction() {
634
688
  var configuredLevel;
635
689
  function getMinLevel() {
636
690
  if (configuredLevel) return configuredLevel;
637
- const env = (hostEnv().LOG_LEVEL || "info").toLowerCase();
691
+ const env = (hostEnv().LOG_LEVEL || "info").trim().toLowerCase();
638
692
  if (env in LOG_PRIORITY) return env;
639
693
  return "info";
640
694
  }
@@ -1024,6 +1078,6 @@ var ApiError = class ApiError extends Error {
1024
1078
  }
1025
1079
  };
1026
1080
  //#endregion
1027
- export { ApiError, defineFunction, env, getApiKey, getDriver, getEnv, getRequestId, getRoles, getUser, getUserId, hasRole, identityResolved, isAdmin, isAuthenticated, isNodeRuntime, lazyResource, rebase, requireAdmin, requireAuth, requireDriver, requireEnv, requireRole, runtimeKey, waitUntil };
1081
+ export { ApiError, defineFunction, env, getApiKey, getDriver, getEnv, getRequestId, getRoles, getScopes, getUser, getUserId, hasRole, hasScope, identityResolved, isAdmin, isAuthenticated, isNodeRuntime, lazyResource, rebase, requireAdmin, requireAuth, requireDriver, requireEnv, requireRole, requireScope, runtimeKey, waitUntil };
1028
1082
 
1029
1083
  //# sourceMappingURL=index.js.map