@rebasepro/server 0.33.2 → 0.34.1

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 (103) hide show
  1. package/dist/{GCSStorageController-kCv5MH2B.js → GCSStorageController-DKv7oDo7.js} +3 -3
  2. package/dist/{GCSStorageController-kCv5MH2B.js.map → GCSStorageController-DKv7oDo7.js.map} +1 -1
  3. package/dist/{S3StorageController-DqK533Sl.js → S3StorageController-CIQ2_mC5.js} +3 -3
  4. package/dist/{S3StorageController-DqK533Sl.js.map → S3StorageController-CIQ2_mC5.js.map} +1 -1
  5. package/dist/{access-CRQBlEZY.js → access-BdsIXo_L.js} +4 -4
  6. package/dist/{access-CRQBlEZY.js.map → access-BdsIXo_L.js.map} +1 -1
  7. package/dist/api/rest/api-generator.d.ts +11 -1
  8. package/dist/auth/auth-hooks.d.ts +1 -1
  9. package/dist/auth/builtin-auth-adapter.d.ts +2 -0
  10. package/dist/auth/capabilities.d.ts +12 -0
  11. package/dist/auth/platform-signin-routes.d.ts +85 -0
  12. package/dist/auth/platform-token.d.ts +33 -0
  13. package/dist/auth/routes.d.ts +8 -0
  14. package/dist/auth/seed-admin.d.ts +2 -0
  15. package/dist/{auth-BanB_pZj.js → auth-CHOmnYwu.js} +358 -12
  16. package/dist/auth-CHOmnYwu.js.map +1 -0
  17. package/dist/{backup-CVNce2jz.js → backup-M37yPYpz.js} +6 -6
  18. package/dist/{backup-CVNce2jz.js.map → backup-M37yPYpz.js.map} +1 -1
  19. package/dist/boot/bundle.d.ts +12 -0
  20. package/dist/boot/env.d.ts +1 -0
  21. package/dist/{branch-routes-aLDaGOD1.js → branch-routes-Cl-Oa3CL.js} +2 -2
  22. package/dist/{branch-routes-aLDaGOD1.js.map → branch-routes-Cl-Oa3CL.js.map} +1 -1
  23. package/dist/{contract-routes-a4ZbN1h3.js → contract-routes-Dkxl-2B_.js} +3 -3
  24. package/dist/{contract-routes-a4ZbN1h3.js.map → contract-routes-Dkxl-2B_.js.map} +1 -1
  25. package/dist/{cron-loader-CWhyA5eR.js → cron-loader-BWahenzQ.js} +2 -2
  26. package/dist/{cron-loader-CWhyA5eR.js.map → cron-loader-BWahenzQ.js.map} +1 -1
  27. package/dist/{cron-routes-CMGAz1my.js → cron-routes-Cq6O3oPR.js} +4 -4
  28. package/dist/{cron-routes-CMGAz1my.js.map → cron-routes-Cq6O3oPR.js.map} +1 -1
  29. package/dist/{cron-scheduler-DQBdkkfb.js → cron-scheduler-B25NuV7o.js} +2 -2
  30. package/dist/{cron-scheduler-DQBdkkfb.js.map → cron-scheduler-B25NuV7o.js.map} +1 -1
  31. package/dist/{cron-store-CjUydRyp.js → cron-store-B1IStnKM.js} +2 -2
  32. package/dist/{cron-store-CjUydRyp.js.map → cron-store-B1IStnKM.js.map} +1 -1
  33. package/dist/dist-DDppJiwg.js +19354 -0
  34. package/dist/dist-DDppJiwg.js.map +1 -0
  35. package/dist/email/link-base.d.ts +21 -0
  36. package/dist/email/types.d.ts +4 -0
  37. package/dist/{filter-dialect-nsQ2ozPY.js → filter-dialect-DgWkoXt7.js} +2 -2
  38. package/dist/{filter-dialect-nsQ2ozPY.js.map → filter-dialect-DgWkoXt7.js.map} +1 -1
  39. package/dist/{function-loader-Cihj_r86.js → function-loader-C23HVFx8.js} +2 -2
  40. package/dist/{function-loader-Cihj_r86.js.map → function-loader-C23HVFx8.js.map} +1 -1
  41. package/dist/{function-routes-CWaldgEj.js → function-routes-DBKL2azw.js} +2 -2
  42. package/dist/{function-routes-CWaldgEj.js.map → function-routes-DBKL2azw.js.map} +1 -1
  43. package/dist/{history-recorder-B8TJMEfO.js → history-recorder-C5gixsU3.js} +16 -3
  44. package/dist/history-recorder-C5gixsU3.js.map +1 -0
  45. package/dist/history-store-c_cm9R3w.js +459 -0
  46. package/dist/history-store-c_cm9R3w.js.map +1 -0
  47. package/dist/index.d.ts +1 -1
  48. package/dist/index.es.js +273 -236
  49. package/dist/index.es.js.map +1 -1
  50. package/dist/{jobs-IJX3fE3X.js → jobs-uqvEGTfs.js} +2 -2
  51. package/dist/{jobs-IJX3fE3X.js.map → jobs-uqvEGTfs.js.map} +1 -1
  52. package/dist/{jwt-BuEprb39.js → jwt-B_5zx-7y.js} +3 -3
  53. package/dist/{jwt-BuEprb39.js.map → jwt-B_5zx-7y.js.map} +1 -1
  54. package/dist/{keys-C8gpPIOG.js → keys-C0g4vwP5.js} +2 -2
  55. package/dist/{keys-C8gpPIOG.js.map → keys-C0g4vwP5.js.map} +1 -1
  56. package/dist/{load-schema-BvRxAuaD.js → load-schema-aNynBztw.js} +2 -2
  57. package/dist/{load-schema-BvRxAuaD.js.map → load-schema-aNynBztw.js.map} +1 -1
  58. package/dist/{logs-routes-BAq2ZxuY.js → logs-routes-D2NGM5Pa.js} +2 -2
  59. package/dist/{logs-routes-BAq2ZxuY.js.map → logs-routes-D2NGM5Pa.js.map} +1 -1
  60. package/dist/metrics/history-recorder.d.ts +10 -1
  61. package/dist/metrics/history-store.d.ts +122 -7
  62. package/dist/metrics/index.d.ts +24 -2
  63. package/dist/{offline-ET6xI1ZO-CIdB1ilf.js → offline-ET6xI1ZO-Du75S8J1.js} +4 -4
  64. package/dist/{offline-ET6xI1ZO-CIdB1ilf.js.map → offline-ET6xI1ZO-Du75S8J1.js.map} +1 -1
  65. package/dist/{offline-store-DtmBwmKE-CzyvC_Zj.js → offline-store-DtmBwmKE-CEakGPWn.js} +3 -3
  66. package/dist/{offline-store-DtmBwmKE-CzyvC_Zj.js.map → offline-store-DtmBwmKE-CEakGPWn.js.map} +1 -1
  67. package/dist/{openapi-generator-CCLtAJ2s.js → openapi-generator-B7EbCjhN.js} +2 -2
  68. package/dist/{openapi-generator-CCLtAJ2s.js.map → openapi-generator-B7EbCjhN.js.map} +1 -1
  69. package/dist/{project-root-CuCOXvbk.js → project-root-BTQAiPki.js} +2 -2
  70. package/dist/{project-root-CuCOXvbk.js.map → project-root-BTQAiPki.js.map} +1 -1
  71. package/dist/{proxy-DUUXXoQo.js → proxy-0fGXJapt.js} +2 -2
  72. package/dist/{proxy-DUUXXoQo.js.map → proxy-0fGXJapt.js.map} +1 -1
  73. package/dist/{query-parser-C9l1eFov.js → query-parser-DwERE0rm.js} +3 -3
  74. package/dist/{query-parser-C9l1eFov.js.map → query-parser-DwERE0rm.js.map} +1 -1
  75. package/dist/{request-timeout-DOu8ItLQ.js → request-timeout-DdbFS6ef.js} +3 -3
  76. package/dist/{request-timeout-DOu8ItLQ.js.map → request-timeout-DdbFS6ef.js.map} +1 -1
  77. package/dist/{rls-simulator-routes-DIAjffhq.js → rls-simulator-routes-Cjv8yY1V.js} +3 -3
  78. package/dist/{rls-simulator-routes-DIAjffhq.js.map → rls-simulator-routes-Cjv8yY1V.js.map} +1 -1
  79. package/dist/{schema-editor-routes-qWGWBPi0.js → schema-editor-routes-CwdoGYKu.js} +4 -4
  80. package/dist/{schema-editor-routes-qWGWBPi0.js.map → schema-editor-routes-CwdoGYKu.js.map} +1 -1
  81. package/dist/{schema-tables-BneB2KZ7.js → schema-tables-DUThMxen.js} +3 -3
  82. package/dist/{schema-tables-BneB2KZ7.js.map → schema-tables-DUThMxen.js.map} +1 -1
  83. package/dist/{schema-tables-routes-BBZJK8_S.js → schema-tables-routes-Ch52xLqF.js} +4 -4
  84. package/dist/{schema-tables-routes-BBZJK8_S.js.map → schema-tables-routes-Ch52xLqF.js.map} +1 -1
  85. package/dist/{securityRuleToConditions-Cj5ZR7TS.js → securityRuleToConditions-DXPY_Z-x.js} +2 -2
  86. package/dist/{securityRuleToConditions-Cj5ZR7TS.js.map → securityRuleToConditions-DXPY_Z-x.js.map} +1 -1
  87. package/dist/{selection-BB8ejqa2.js → selection-BiTJ-Tiy.js} +2 -2
  88. package/dist/{selection-BB8ejqa2.js.map → selection-BiTJ-Tiy.js.map} +1 -1
  89. package/dist/{sql-export-routes-CPXI3qZ7.js → sql-export-routes-BYt7G2v-.js} +2 -2
  90. package/dist/{sql-export-routes-CPXI3qZ7.js.map → sql-export-routes-BYt7G2v-.js.map} +1 -1
  91. package/dist/{src-BdPKCs9u.js → src--EBfCtYm.js} +2 -2
  92. package/dist/src--EBfCtYm.js.map +1 -0
  93. package/dist/storage/routes.d.ts +6 -0
  94. package/dist/{table-source-editor-D3m_VMwN.js → table-source-editor-P5zp7lOn.js} +3 -3
  95. package/dist/{table-source-editor-D3m_VMwN.js.map → table-source-editor-P5zp7lOn.js.map} +1 -1
  96. package/package.json +5 -5
  97. package/dist/auth-BanB_pZj.js.map +0 -1
  98. package/dist/dist-C1vNURUy.js +0 -19354
  99. package/dist/dist-C1vNURUy.js.map +0 -1
  100. package/dist/history-recorder-B8TJMEfO.js.map +0 -1
  101. package/dist/history-store-DzrJeEKv.js +0 -233
  102. package/dist/history-store-DzrJeEKv.js.map +0 -1
  103. package/dist/src-BdPKCs9u.js.map +0 -1
@@ -1,9 +1,19 @@
1
1
  import { Hono } from "hono";
2
- import { AuthAdapter, DataDriver } from "@rebasepro/types";
2
+ import { AuthAdapter, DataDriver, type TableDescriptor } from "@rebasepro/types";
3
3
  import { QueryOptions, HonoEnv } from "../types.js";
4
4
  import { type ListLimitOptions } from "./query-parser.js";
5
5
  import { type RestTables, type ServedTable, type TableLookup } from "./served-table.js";
6
6
  import type { FieldViewer } from "@rebasepro/common";
7
+ /**
8
+ * Refuse an address with the wrong number of parts for a table's key.
9
+ *
10
+ * A table keyed on `(agency_id, id)` is addressed as `<agency_id>:::<id>`.
11
+ * Given `/proposals/p1`, the parts did not match, the read found nothing, and
12
+ * the answer was the 404 that says the row "may be hidden from this caller by
13
+ * row-level security", which sent the caller to the policies. Exported for
14
+ * the test.
15
+ */
16
+ export declare function assertKeyAddress(table: Pick<TableDescriptor, "slug" | "primaryKey">, id: string): void;
7
17
  /**
8
18
  * The row a single-row write addresses, as its route found it.
9
19
  *
@@ -44,7 +44,7 @@ import type { AuthResponsePayload, TransformAuthResponseContext } from "@rebasep
44
44
  /**
45
45
  * Authentication method identifier for lifecycle hooks.
46
46
  */
47
- export type AuthMethod = "login" | "register" | "oauth" | "refresh" | "password-reset" | "anonymous" | "magic-link" | "otp" | "mfa" | "device";
47
+ export type AuthMethod = "login" | "register" | "oauth" | "refresh" | "password-reset" | "anonymous" | "magic-link" | "otp" | "mfa" | "device" | "platform";
48
48
  /**
49
49
  * Hook specific parts of the built-in Rebase auth implementation.
50
50
  *
@@ -93,6 +93,8 @@ export interface BuiltinAuthAdapterConfig {
93
93
  refreshTokenReuse?: import("./routes.js").RefreshTokenReusePolicy;
94
94
  /** A magic-link or email-code request for an unknown address creates its account, while registration is open. */
95
95
  magicLinkCreatesUsers?: boolean;
96
+ /** The platform's sign-in door; see `AuthModuleConfig.platformSignIn`. */
97
+ platformSignIn?: import("./platform-signin-routes.js").PlatformSignInConfig;
96
98
  }
97
99
  /**
98
100
  * Create the built-in Rebase auth adapter.
@@ -53,3 +53,15 @@ export interface BuiltinAuthCapabilityInputs {
53
53
  * `anonymousLogin` go through the shared predicates for exactly that reason.
54
54
  */
55
55
  export declare function buildBuiltinAuthCapabilities(inputs: BuiltinAuthCapabilityInputs): AuthAdapterCapabilities;
56
+ /**
57
+ * The sign-in methods switched on that cannot work, as `GET /auth/config`
58
+ * reports them (`unavailable`). Spread into the capabilities only when one is
59
+ * missing, so the document stays the same for every backend that is fine.
60
+ */
61
+ export declare function unavailableSignIn(inputs: {
62
+ enableMagicLink?: boolean;
63
+ enableEmailOtp?: boolean;
64
+ emailConfigured: boolean;
65
+ }): {
66
+ unavailable?: NonNullable<AuthAdapterCapabilities["unavailable"]>;
67
+ };
@@ -0,0 +1,85 @@
1
+ /**
2
+ * `POST /auth/platform-signin`: the platform hosting this backend signs a
3
+ * project's owner in to the project's admin panel.
4
+ *
5
+ * ## Why this exists
6
+ *
7
+ * A Rebase Cloud project runs under `NODE_ENV=production`, where the first
8
+ * account to register is not promoted (`registration-policy.ts`), so a fresh
9
+ * project's admin panel is a login form nobody holds credentials for. The way
10
+ * in was `REBASE_ADMIN_EMAIL` and `REBASE_ADMIN_PASSWORD` set before the first
11
+ * deploy, which nobody knew to do — and the person who owns the project is
12
+ * already signed in, to the platform's console.
13
+ *
14
+ * So the console signs a platform token (`platform-token.ts`) carrying
15
+ * {@link PLATFORM_SIGNIN_SCOPES}, for that person, for this project, for a
16
+ * minute or two, and hands it to the admin panel in the URL fragment. This
17
+ * route trades it for an ordinary session.
18
+ *
19
+ * ## Who it signs in, and as what
20
+ *
21
+ * The control plane mints the scope only for an owner or admin of the
22
+ * organization that owns the project (`saas` `functions/admin-signin.ts`):
23
+ * people who can already set this project's environment and redeploy it, which
24
+ * reaches everything an `admin` of the app can. So the session it opens is the
25
+ * `admin` role, on the account whose email the token names — found, or created
26
+ * with no password and the address marked verified, because the platform has
27
+ * verified it.
28
+ *
29
+ * An existing account under that email whose address nobody had proven may
30
+ * have been registered by somebody else, with a password they know. Before
31
+ * that account becomes the owner's admin, `confirmAddressOwnership` removes
32
+ * every way in it did not vouch for and ends its sessions, as clicking a magic
33
+ * link does.
34
+ *
35
+ * ## What it refuses
36
+ *
37
+ * Everything `verifyPlatformToken` refuses (signature, issuer, another
38
+ * project's audience, a token from the future or living past
39
+ * {@link PLATFORM_TOKEN_MAX_LIFETIME_SECONDS}), and on top of that: a token
40
+ * without this scope, without a `jti` or an email, or living longer than
41
+ * {@link PLATFORM_SIGNIN_MAX_LIFETIME_SECONDS}; and the same token twice. A
42
+ * spent `jti` is remembered in the backend's rate-limit store — shared across
43
+ * replicas when the backend has a shared one — until the token would have
44
+ * expired anyway.
45
+ *
46
+ * The second-factor gate in `createSessionAndTokens` applies as on every other
47
+ * door: an account with a verified factor gets `MFA_REQUIRED`, not a session.
48
+ *
49
+ * @module
50
+ */
51
+ import { Hono } from "hono";
52
+ import { z } from "zod";
53
+ import type { AuthResponsePayload, TransformAuthResponseContext } from "@rebasepro/types";
54
+ import type { HonoEnv } from "../api/types.js";
55
+ import type { AuthModuleConfig, CreateSessionAndTokens } from "./routes.js";
56
+ import type { ResolvedAuthHooks } from "./auth-hooks.js";
57
+ import type { RateLimitStore } from "./rate-limit-store.js";
58
+ import { type AuthLimiters } from "./rate-limiter.js";
59
+ import { type PlatformTokenConfig } from "./platform-token.js";
60
+ /** What a backend hands the auth routes to turn the sign-in door on. */
61
+ export interface PlatformSignInConfig {
62
+ /** The platform's public keys and this project's audience. */
63
+ tokens: PlatformTokenConfig;
64
+ /** Where a spent token's `jti` is remembered. */
65
+ usedTokens: RateLimitStore;
66
+ }
67
+ export declare function mountPlatformSignInRoutes(deps: {
68
+ router: Hono<HonoEnv>;
69
+ config: AuthModuleConfig;
70
+ platformSignIn: PlatformSignInConfig;
71
+ limiters: AuthLimiters;
72
+ ops: ResolvedAuthHooks;
73
+ parseBody: <T>(schema: z.ZodSchema<T>, body: unknown) => T;
74
+ buildAuthResponse: (user: {
75
+ id: string;
76
+ email: string;
77
+ displayName?: string | null;
78
+ photoUrl?: string | null;
79
+ emailVerified?: boolean;
80
+ isAnonymous?: boolean;
81
+ metadata?: Record<string, unknown> | null;
82
+ }, roleIds: string[], accessToken: string, refreshToken: string, providerId: string) => unknown;
83
+ createSessionAndTokens: CreateSessionAndTokens;
84
+ applyTransformHook: (response: AuthResponsePayload, method: TransformAuthResponseContext["method"], request: Request, uid: string) => Promise<AuthResponsePayload>;
85
+ }): void;
@@ -71,11 +71,34 @@ export declare const PLATFORM_TOKEN_SCOPES: readonly AdminScope[];
71
71
  * the same review as `cron:write`.
72
72
  */
73
73
  export declare const PLATFORM_MCP_SCOPES: readonly string[];
74
+ /**
75
+ * What a platform token can be granted at the sign-in door, and only there:
76
+ * `POST /auth/platform-signin` (`platform-signin-routes.ts`), which turns it
77
+ * into an ordinary session for the person it names, with the `admin` role.
78
+ *
79
+ * This is the one scope that makes a platform token worth a person of the app,
80
+ * so it is held tighter than the others: the token must name the person's
81
+ * email, carry a `jti`, live at most {@link PLATFORM_SIGNIN_MAX_LIFETIME_SECONDS},
82
+ * and is spent by its first use. The control plane mints it only for an owner
83
+ * or admin of the organization that owns the project — someone who could
84
+ * already set `REBASE_ADMIN_EMAIL` and redeploy, which is the reach this
85
+ * grants, without the password nobody knew to choose. Never on an admin
86
+ * surface or the MCP endpoint: neither lists it.
87
+ */
88
+ export declare const PLATFORM_SIGNIN_SCOPES: readonly string[];
89
+ /** The longest `exp - iat` a sign-in token may declare. */
90
+ export declare const PLATFORM_SIGNIN_MAX_LIFETIME_SECONDS = 120;
74
91
  /** The longest `exp - iat` a platform token may declare. */
75
92
  export declare const PLATFORM_TOKEN_MAX_LIFETIME_SECONDS = 600;
76
93
  /** The environment variables a platform sets to turn platform tokens on. */
77
94
  export declare const PLATFORM_TOKEN_KEY_ENV = "REBASE_PLATFORM_TOKEN_KEY";
78
95
  export declare const PLATFORM_TOKEN_AUDIENCE_ENV = "REBASE_PLATFORM_TOKEN_AUDIENCE";
96
+ /**
97
+ * Where the admin panel's "Continue with Rebase Cloud" goes: the project's page
98
+ * in the platform's console, which mints a sign-in token and comes back. Set by
99
+ * the platform with the other two; optional.
100
+ */
101
+ export declare const PLATFORM_SIGNIN_URL_ENV = "REBASE_PLATFORM_SIGNIN_URL";
79
102
  /** What this server verifies platform tokens against. */
80
103
  export interface PlatformTokenConfig {
81
104
  /**
@@ -85,6 +108,8 @@ export interface PlatformTokenConfig {
85
108
  publicKeys: string[];
86
109
  /** This project, as the platform names it in `aud`. */
87
110
  audience: string;
111
+ /** {@link PLATFORM_SIGNIN_URL_ENV}, when the platform set a valid http(s) URL. */
112
+ signInUrl?: string;
88
113
  }
89
114
  /** A verified platform token, as the request will act. */
90
115
  export interface PlatformCaller {
@@ -94,6 +119,14 @@ export interface PlatformCaller {
94
119
  scopes: string[];
95
120
  /** `jti`, when the platform set one — what an audit line quotes. */
96
121
  tokenId?: string;
122
+ /**
123
+ * The person's email, when the platform set one: the control plane's
124
+ * verified address for `sub`. Only the sign-in door reads it.
125
+ */
126
+ email?: string;
127
+ /** `iat` and `exp`, in seconds. */
128
+ issuedAt: number;
129
+ expiresAt: number;
97
130
  }
98
131
  /** Why a presented platform token does not authenticate. */
99
132
  export interface PlatformTokenRefusal {
@@ -6,6 +6,7 @@ import { EmailService, EmailConfig } from "../email/index.js";
6
6
  import { HonoEnv } from "../api/types.js";
7
7
  import { type AuthLimiters } from "./rate-limiter.js";
8
8
  import { type CaptchaConfig } from "./captcha.js";
9
+ import { type PlatformSignInConfig } from "./platform-signin-routes.js";
9
10
  import { type DeviceLoginRoutesConfig } from "./device-login-routes.js";
10
11
  import { type AccessControl } from "./access.js";
11
12
  import { isDeliverableAddress } from "./deliverable-address.js";
@@ -81,6 +82,13 @@ export interface AuthModuleConfig {
81
82
  * Off when absent. See `device-login-routes.ts`.
82
83
  */
83
84
  deviceLogin?: DeviceLoginRoutesConfig;
85
+ /**
86
+ * The platform's sign-in door, `POST /auth/platform-signin`: a project
87
+ * owner arriving from the platform's console with a short-lived token is
88
+ * signed in as `admin`. Off when absent — every self-hosted backend. See
89
+ * `platform-signin-routes.ts`.
90
+ */
91
+ platformSignIn?: PlatformSignInConfig;
84
92
  /**
85
93
  * Opt-in httpOnly cookie mode for refresh tokens.
86
94
  *
@@ -37,6 +37,8 @@ export interface SeedAdminEnv {
37
37
  REBASE_ADMIN_PASSWORD?: string;
38
38
  /** Decides whether the seed is this deployment's way in at all. */
39
39
  NODE_ENV?: string;
40
+ /** Set by a platform that signs the project's owners in; see `platform-token.ts`. */
41
+ REBASE_PLATFORM_TOKEN_KEY?: string;
40
42
  }
41
43
  export type SeedAdminOutcome =
42
44
  /** Created, with the new user's id. */