@rebasepro/cli 0.31.0-canary.g902a0ce → 0.32.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 (193) hide show
  1. package/dist/{agent-setup-DqAcoDcn.js → agent-setup-Cg_zBWoW.js} +3 -3
  2. package/dist/{agent-setup-DqAcoDcn.js.map → agent-setup-Cg_zBWoW.js.map} +1 -1
  3. package/dist/api-TbmW33D7.js +275 -0
  4. package/dist/api-TbmW33D7.js.map +1 -0
  5. package/dist/{api-keys-eIUjMqWn.js → api-keys-fPQ55DCm.js} +151 -158
  6. package/dist/api-keys-fPQ55DCm.js.map +1 -0
  7. package/dist/{apps-DExO4PEl.js → apps-DBTRoOeP.js} +18 -13
  8. package/dist/apps-DBTRoOeP.js.map +1 -0
  9. package/dist/{args-CaCcrYE1.js → args-DHyrshtI.js} +3 -132
  10. package/dist/args-DHyrshtI.js.map +1 -0
  11. package/dist/{atlas-dev-database-DOCKk6ht.js → atlas-dev-database-D6h65f2x.js} +3 -3
  12. package/dist/{atlas-dev-database-DOCKk6ht.js.map → atlas-dev-database-D6h65f2x.js.map} +1 -1
  13. package/dist/{auth-CyADghFQ.js → auth-BpyYLEFY.js} +93 -12
  14. package/dist/auth-BpyYLEFY.js.map +1 -0
  15. package/dist/auth-session-B6aT0Dyj.js +371 -0
  16. package/dist/auth-session-B6aT0Dyj.js.map +1 -0
  17. package/dist/{backend-guard-C0mVkXBw.js → backend-guard-Cf8eMK_f.js} +2 -2
  18. package/dist/{backend-guard-C0mVkXBw.js.map → backend-guard-Cf8eMK_f.js.map} +1 -1
  19. package/dist/{branch-pointer-DMPyvZoK.js → branch-pointer-BJOF2Ubv.js} +1 -1
  20. package/dist/{build-CA5R07tw.js → build-BfdT-AUR.js} +12 -10
  21. package/dist/{build-CA5R07tw.js.map → build-BfdT-AUR.js.map} +1 -1
  22. package/dist/{bundle-DgILeA5b.js → bundle-CIiKGrte.js} +78 -12
  23. package/dist/bundle-CIiKGrte.js.map +1 -0
  24. package/dist/bundle.d.ts +31 -1
  25. package/dist/{cloud-CYMk92iG.js → cloud-MqnyPnmX.js} +1540 -1531
  26. package/dist/cloud-MqnyPnmX.js.map +1 -0
  27. package/dist/{cms-directories-BK3vcswg.js → cms-directories-BaV-Is9a.js} +2 -2
  28. package/dist/{cms-directories-BK3vcswg.js.map → cms-directories-BaV-Is9a.js.map} +1 -1
  29. package/dist/codemod/collections-to-tables/backend.d.ts +0 -2
  30. package/dist/codemod/collections-to-tables/customization.d.ts +2 -1
  31. package/dist/codemod/collections-to-tables/modules.d.ts +32 -0
  32. package/dist/codemod/collections-to-tables/plan-context.d.ts +7 -1
  33. package/dist/{command-D5lhW_-B.js → command-D9g46gg9.js} +68 -42
  34. package/dist/command-D9g46gg9.js.map +1 -0
  35. package/dist/commands/api-keys.d.ts +89 -52
  36. package/dist/commands/api.d.ts +114 -0
  37. package/dist/commands/auth-session.d.ts +94 -0
  38. package/dist/commands/auth.d.ts +1 -1
  39. package/dist/commands/cloud/alerts.d.ts +29 -0
  40. package/dist/commands/cloud/context.d.ts +8 -0
  41. package/dist/commands/cloud/debug.d.ts +16 -1
  42. package/dist/commands/cloud/deploy-hooks.d.ts +19 -0
  43. package/dist/commands/cloud/deploy.d.ts +25 -0
  44. package/dist/commands/cloud/env.d.ts +1 -0
  45. package/dist/commands/cloud/index.d.ts +5 -0
  46. package/dist/commands/cloud/maintenance.d.ts +26 -1
  47. package/dist/commands/cloud/not-served.d.ts +27 -0
  48. package/dist/commands/cloud/orgs.d.ts +5 -0
  49. package/dist/commands/cloud/resources.d.ts +82 -2
  50. package/dist/commands/cloud/runtime-logs.d.ts +57 -0
  51. package/dist/commands/cloud/settings.d.ts +3 -0
  52. package/dist/commands/cron.d.ts +68 -0
  53. package/dist/commands/data.d.ts +197 -0
  54. package/dist/commands/functions.d.ts +38 -0
  55. package/dist/commands/logs.d.ts +22 -0
  56. package/dist/commands/rls.d.ts +31 -0
  57. package/dist/commands/schema-reconcile.d.ts +2 -1
  58. package/dist/commands/schema-show.d.ts +38 -0
  59. package/dist/commands/storage-objects.d.ts +88 -0
  60. package/dist/commands/storage.d.ts +18 -2
  61. package/dist/commands/users.d.ts +147 -0
  62. package/dist/{consent-BXLIrMl8.js → consent-UV6ObCME.js} +2 -2
  63. package/dist/{consent-BXLIrMl8.js.map → consent-UV6ObCME.js.map} +1 -1
  64. package/dist/{console-CMjhgMUE.js → console-BVoYOLAO.js} +6 -6
  65. package/dist/{console-CMjhgMUE.js.map → console-BVoYOLAO.js.map} +1 -1
  66. package/dist/{context--JwaHaZp.js → context-BOMEoKxn.js} +80 -9
  67. package/dist/{context--JwaHaZp.js.map → context-BOMEoKxn.js.map} +1 -1
  68. package/dist/cron-CpUsQ739.js +298 -0
  69. package/dist/cron-CpUsQ739.js.map +1 -0
  70. package/dist/cron-ZRXsla0v.js +259 -0
  71. package/dist/cron-ZRXsla0v.js.map +1 -0
  72. package/dist/{daemon-w30PsdwV.js → daemon-D5gdG7gx.js} +3 -3
  73. package/dist/{daemon-w30PsdwV.js.map → daemon-D5gdG7gx.js.map} +1 -1
  74. package/dist/{daemon-entry-zOC1revO.js → daemon-entry--ummUJnk.js} +2 -2
  75. package/dist/{daemon-entry-zOC1revO.js.map → daemon-entry--ummUJnk.js.map} +1 -1
  76. package/dist/data-BJ9AZFUC.js +947 -0
  77. package/dist/data-BJ9AZFUC.js.map +1 -0
  78. package/dist/{db-A7XDCIIO.js → db-D_iF4E-v.js} +60 -36
  79. package/dist/db-D_iF4E-v.js.map +1 -0
  80. package/dist/debug-nNbbxAeo.js +1114 -0
  81. package/dist/debug-nNbbxAeo.js.map +1 -0
  82. package/dist/{derive-C3ezmY-p.js → derive-Mky_u59_.js} +3 -3
  83. package/dist/{derive-C3ezmY-p.js.map → derive-Mky_u59_.js.map} +1 -1
  84. package/dist/{dev-tWwPyWkQ.js → dev-bj6dEeSQ.js} +13 -13
  85. package/dist/{dev-tWwPyWkQ.js.map → dev-bj6dEeSQ.js.map} +1 -1
  86. package/dist/dev-db/__fixtures__/unanswering-postgres.d.ts +11 -0
  87. package/dist/dev-db/attver.d.ts +38 -6
  88. package/dist/dev-db/local-timeouts.d.ts +25 -0
  89. package/dist/dev-db/pull.d.ts +49 -9
  90. package/dist/{dev-preflight-DjvcV6SK.js → dev-preflight-BMOf2N6r.js} +2 -2
  91. package/dist/{dev-preflight-DjvcV6SK.js.map → dev-preflight-BMOf2N6r.js.map} +1 -1
  92. package/dist/{dev-server-BLxCbQEP.js → dev-server-2XHSHM_q.js} +2 -2
  93. package/dist/{dev-server-BLxCbQEP.js.map → dev-server-2XHSHM_q.js.map} +1 -1
  94. package/dist/{doctor-BBM0dWvZ.js → doctor-2Jlau0Rm.js} +9 -8
  95. package/dist/{doctor-BBM0dWvZ.js.map → doctor-2Jlau0Rm.js.map} +1 -1
  96. package/dist/{eject-Bhzd6hgb.js → eject-DK_M9kor.js} +4 -4
  97. package/dist/{eject-Bhzd6hgb.js.map → eject-DK_M9kor.js.map} +1 -1
  98. package/dist/{fold-static-CKewnAPX.js → fold-static-2t3UUX4z.js} +10 -6
  99. package/dist/fold-static-2t3UUX4z.js.map +1 -0
  100. package/dist/fold-static.d.ts +7 -0
  101. package/dist/functions-B4JR6EZL.js +120 -0
  102. package/dist/functions-B4JR6EZL.js.map +1 -0
  103. package/dist/{generate-view-CTOluXvH.js → generate-view-BMaLQm8H.js} +5 -5
  104. package/dist/{generate-view-CTOluXvH.js.map → generate-view-BMaLQm8H.js.map} +1 -1
  105. package/dist/{generate_sdk-De-aLC1L.js → generate_sdk-ByD-gTsK.js} +7 -7
  106. package/dist/{generate_sdk-De-aLC1L.js.map → generate_sdk-ByD-gTsK.js.map} +1 -1
  107. package/dist/index.es.js +123 -47
  108. package/dist/index.es.js.map +1 -1
  109. package/dist/{init-Dtl-IcXf.js → init-DHCe5mJ5.js} +59 -11
  110. package/dist/init-DHCe5mJ5.js.map +1 -0
  111. package/dist/{invoked-command-CG_rIa_o.js → invoked-command-FBeIBS8o.js} +2 -2
  112. package/dist/{invoked-command-CG_rIa_o.js.map → invoked-command-FBeIBS8o.js.map} +1 -1
  113. package/dist/last-dev-database-CBVkEUEl.js +2 -0
  114. package/dist/local-timeouts-B1Kwligw.js +30 -0
  115. package/dist/local-timeouts-B1Kwligw.js.map +1 -0
  116. package/dist/logs-CIgfLBsu.js +192 -0
  117. package/dist/logs-CIgfLBsu.js.map +1 -0
  118. package/dist/{manifest-C3uLDrrJ.js → manifest-RjqxfCpb.js} +114 -5
  119. package/dist/manifest-RjqxfCpb.js.map +1 -0
  120. package/dist/{migrate-VrKoi3nB.js → migrate-Cx8-Y4TG.js} +5 -4
  121. package/dist/{migrate-VrKoi3nB.js.map → migrate-Cx8-Y4TG.js.map} +1 -1
  122. package/dist/{normalize-imports-DwxqEMYq.js → normalize-imports-P86NVfpo.js} +3 -3
  123. package/dist/{normalize-imports-DwxqEMYq.js.map → normalize-imports-P86NVfpo.js.map} +1 -1
  124. package/dist/{path-flags-7O5uPBcQ.js → path-flags-ekLdkbra.js} +3 -3
  125. package/dist/{path-flags-7O5uPBcQ.js.map → path-flags-ekLdkbra.js.map} +1 -1
  126. package/dist/{prepare-Ccxspoj-.js → prepare-BaJe0Zik.js} +4 -4
  127. package/dist/{prepare-Ccxspoj-.js.map → prepare-BaJe0Zik.js.map} +1 -1
  128. package/dist/{project-CLcF5i8c.js → project-DALmhb5R.js} +2 -2
  129. package/dist/{project-CLcF5i8c.js.map → project-DALmhb5R.js.map} +1 -1
  130. package/dist/project-command-Cl9EZzjr.js +662 -0
  131. package/dist/project-command-Cl9EZzjr.js.map +1 -0
  132. package/dist/{project-schema-CsSOG2gE.js → project-schema-Dm6Jk0Y_.js} +4 -2
  133. package/dist/{project-schema-CsSOG2gE.js.map → project-schema-Dm6Jk0Y_.js.map} +1 -1
  134. package/dist/{pull-D9WvpDYY.js → pull-CTIsST6T.js} +336 -55
  135. package/dist/pull-CTIsST6T.js.map +1 -0
  136. package/dist/resolve-C36px9tR.js +2 -0
  137. package/dist/{resources-Dpfs2y8P.js → resources-Db3USuPO.js} +5 -5
  138. package/dist/{resources-Dpfs2y8P.js.map → resources-Db3USuPO.js.map} +1 -1
  139. package/dist/rls-BxrQ0P50.js +133 -0
  140. package/dist/rls-BxrQ0P50.js.map +1 -0
  141. package/dist/{schema-DwFDI1iU.js → schema-_FzZEoB8.js} +54 -40
  142. package/dist/schema-_FzZEoB8.js.map +1 -0
  143. package/dist/{schema-dir-Cd1kvYbf.js → schema-dir-ChcYfWjP.js} +2 -2
  144. package/dist/{schema-dir-Cd1kvYbf.js.map → schema-dir-ChcYfWjP.js.map} +1 -1
  145. package/dist/schema-reconcile-DV14XY4o.js +2 -0
  146. package/dist/schema-show-h72UJ9zH.js +127 -0
  147. package/dist/schema-show-h72UJ9zH.js.map +1 -0
  148. package/dist/{skills-CXjA9TWw.js → skills-DQ2bZGkj.js} +6 -5
  149. package/dist/{skills-CXjA9TWw.js.map → skills-DQ2bZGkj.js.map} +1 -1
  150. package/dist/star-nudge.d.ts +28 -0
  151. package/dist/{start-Bwbtt2W5.js → start-Cjx4W0bJ.js} +7 -7
  152. package/dist/{start-Bwbtt2W5.js.map → start-Cjx4W0bJ.js.map} +1 -1
  153. package/dist/{status-DQ_PPz4C.js → status-CDBk25VO.js} +9 -9
  154. package/dist/{status-DQ_PPz4C.js.map → status-CDBk25VO.js.map} +1 -1
  155. package/dist/{storage-iTqj5-Av.js → storage-Clc8dLG8.js} +79 -36
  156. package/dist/storage-Clc8dLG8.js.map +1 -0
  157. package/dist/storage-objects-CfRKlTDe.js +279 -0
  158. package/dist/storage-objects-CfRKlTDe.js.map +1 -0
  159. package/dist/{telemetry-BP_1Cl9r.js → telemetry-DZU2-NCm.js} +5 -4
  160. package/dist/{telemetry-BP_1Cl9r.js.map → telemetry-DZU2-NCm.js.map} +1 -1
  161. package/dist/{telemetry-M3HjlyhZ.js → telemetry-EVtASbKb.js} +2 -2
  162. package/dist/{telemetry-M3HjlyhZ.js.map → telemetry-EVtASbKb.js.map} +1 -1
  163. package/dist/unknown-command-DnZ2uhGs.js +139 -0
  164. package/dist/unknown-command-DnZ2uhGs.js.map +1 -0
  165. package/dist/{upgrade-oZzJ13jM.js → upgrade-DhpUFb6p.js} +5 -5
  166. package/dist/{upgrade-oZzJ13jM.js.map → upgrade-DhpUFb6p.js.map} +1 -1
  167. package/dist/users-5PkqBY6R.js +561 -0
  168. package/dist/users-5PkqBY6R.js.map +1 -0
  169. package/dist/utils/project-command.d.ts +38 -0
  170. package/dist/utils/project-target.d.ts +193 -0
  171. package/dist/{verify-DkJqhYPI.js → verify-BdeqNb-V.js} +138 -12
  172. package/dist/verify-BdeqNb-V.js.map +1 -0
  173. package/dist/{version-Buyyo1ut.js → version-ONIeo7jl.js} +7 -2
  174. package/dist/{version-Buyyo1ut.js.map → version-ONIeo7jl.js.map} +1 -1
  175. package/package.json +10 -10
  176. package/dist/api-keys-eIUjMqWn.js.map +0 -1
  177. package/dist/apps-DExO4PEl.js.map +0 -1
  178. package/dist/args-CaCcrYE1.js.map +0 -1
  179. package/dist/auth-CyADghFQ.js.map +0 -1
  180. package/dist/bundle-DgILeA5b.js.map +0 -1
  181. package/dist/cloud-CYMk92iG.js.map +0 -1
  182. package/dist/command-D5lhW_-B.js.map +0 -1
  183. package/dist/db-A7XDCIIO.js.map +0 -1
  184. package/dist/fold-static-CKewnAPX.js.map +0 -1
  185. package/dist/init-Dtl-IcXf.js.map +0 -1
  186. package/dist/last-dev-database-Dc8cP01o.js +0 -2
  187. package/dist/manifest-C3uLDrrJ.js.map +0 -1
  188. package/dist/pull-D9WvpDYY.js.map +0 -1
  189. package/dist/resolve-BY7bSFRT.js +0 -2
  190. package/dist/schema-DwFDI1iU.js.map +0 -1
  191. package/dist/schema-reconcile-Tto54Qbv.js +0 -2
  192. package/dist/storage-iTqj5-Av.js.map +0 -1
  193. package/dist/verify-DkJqhYPI.js.map +0 -1
@@ -0,0 +1,38 @@
1
+ /**
2
+ * What every project command shares besides its target: the output mode, the
3
+ * help page, the parse refusal and the way a failed request is reported.
4
+ *
5
+ * The output contract is the cloud family's (`commands/cloud/context.ts`),
6
+ * reused rather than copied: one JSON value on stdout when `--json` is given,
7
+ * `REBASE_JSON=1` is set or stdout is not a terminal; everything else on
8
+ * stderr; a refusal is `{ "error": { message, code, hint } }` and exit 1; a
9
+ * destructive action refuses rather than prompts when nobody can answer.
10
+ *
11
+ * Help is the one difference: a project command's `--help` is the page a
12
+ * person reads even when piped (`rebase data --help | less`), and JSON only
13
+ * when `--json` asks for it.
14
+ */
15
+ import { emit, fail, isJsonMode, type GroupHelp, type HelpAction } from "../commands/cloud/context.js";
16
+ import { type ProjectTarget, type ProjectTargetOptions, type RequestOptions } from "./project-target.js";
17
+ export { emit, fail, isJsonMode, type HelpAction };
18
+ /** Latch the output mode for this run. Call first, before anything prints. */
19
+ export declare function startProjectCommand(rawArgs: string[]): void;
20
+ /** A project group's help page, with the target flags as its global options. */
21
+ export declare function printProjectHelp(page: Omit<GroupHelp, "globalFlags">): void;
22
+ /**
23
+ * Run a parse, and report its refusal through {@link fail} — one JSON value
24
+ * when piped — rather than as a throw, which `bin/rebase.js` prints as text.
25
+ */
26
+ export declare function parsedLine<T>(parse: () => T): T;
27
+ /** Report a {@link TargetError} through {@link fail}; rethrow anything else. */
28
+ export declare function reportTargetError(e: unknown, target?: ProjectTarget): never;
29
+ /** Resolve the target, or end the command with why not. */
30
+ export declare function projectTarget(flags: Readonly<Record<string, unknown>>, options: ProjectTargetOptions): Promise<ProjectTarget>;
31
+ /** Send one request and read its JSON answer, or end the command with the app's own refusal. */
32
+ export declare function requestJson(target: ProjectTarget, path: string, action: string, options?: RequestOptions): Promise<unknown>;
33
+ /** Narrowing helpers for the answers commands read. */
34
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
35
+ export declare function recordsOf(value: unknown): Record<string, unknown>[];
36
+ export declare function stringOf(value: unknown): string | undefined;
37
+ /** A cell's text for a table: strings as they are, everything else as compact JSON. */
38
+ export declare function cellText(value: unknown): string;
@@ -0,0 +1,193 @@
1
+ /**
2
+ * The flags every project command accepts, merged into its own spec.
3
+ *
4
+ * `--json` and `--yes` are here because the output mode and the confirmation
5
+ * prompt are shared too (`commands/cloud/context.ts`): one JSON value on
6
+ * stdout when piped or asked for, and a refusal rather than a prompt when
7
+ * there is nobody to answer one.
8
+ */
9
+ export declare const PROJECT_TARGET_FLAGS: {
10
+ readonly "--project": StringConstructor;
11
+ readonly "-p": "--project";
12
+ readonly "--cloud": BooleanConstructor;
13
+ readonly "--url": StringConstructor;
14
+ readonly "--token": StringConstructor;
15
+ readonly "--session": BooleanConstructor;
16
+ readonly "--anon": BooleanConstructor;
17
+ readonly "--json": BooleanConstructor;
18
+ readonly "--yes": BooleanConstructor;
19
+ readonly "-y": "--yes";
20
+ };
21
+ /** The same flags, as every project command's help page lists them. */
22
+ export declare const PROJECT_TARGET_HELP: Array<[string, string]>;
23
+ /** The values {@link PROJECT_TARGET_FLAGS} resolves to, as a command's parsed flags hold them. */
24
+ export type ProjectTargetFlags = {
25
+ "--project"?: string;
26
+ "--cloud"?: boolean;
27
+ "--url"?: string;
28
+ "--token"?: string;
29
+ "--session"?: boolean;
30
+ "--anon"?: boolean;
31
+ };
32
+ /**
33
+ * Where this project's backend is — or why the CLI will not say.
34
+ *
35
+ * `configured` is an address the developer named; `running` is the one this
36
+ * project's backend recorded when it bound, and is still serving on. There is
37
+ * no third, guessed, answer.
38
+ */
39
+ export type BackendAddress = {
40
+ url: string;
41
+ source: "configured" | "running";
42
+ /**
43
+ * Set when the address came from `.env` and is the cloud project this
44
+ * directory is linked to — which `rebase cloud init --claim` writes
45
+ * there for the app and the SDK, not as a choice of where local
46
+ * commands go. The command still goes there; {@link cloudTargetNote}
47
+ * says so.
48
+ */
49
+ cloudProject?: string;
50
+ } | {
51
+ url: null;
52
+ reason: string;
53
+ };
54
+ /**
55
+ * The address the service key may be sent to, from the project alone.
56
+ *
57
+ * In order: `REBASE_BASE_URL` in the shell or in `.env`, then the
58
+ * `.rebase/state.json` this project's backend writes when it binds — and only
59
+ * while the pid it names is alive, because a backend that was killed leaves
60
+ * the file behind. `.env`'s `PORT` was once the fallback, and every scaffold
61
+ * writes `PORT=3001`: with `rebase dev` stopped, the key went to whatever
62
+ * listened on 3001.
63
+ */
64
+ export declare function resolveBackendAddress(env: Record<string, string>, projectRoot: string): BackendAddress;
65
+ /**
66
+ * What to say before sending a request to the address of a cloud project
67
+ * `.env` names: it goes there, and that project does not take this
68
+ * project's local service key.
69
+ */
70
+ export declare function cloudTargetNote(address: BackendAddress): string | undefined;
71
+ /** One person's session on one server, as `rebase auth login` stores it. */
72
+ export interface StoredSession {
73
+ accessToken: string;
74
+ refreshToken?: string;
75
+ /** Epoch milliseconds. */
76
+ expiresAt: number;
77
+ email?: string;
78
+ uid?: string;
79
+ }
80
+ /**
81
+ * `~/.rebase/sessions.json`: the person sessions `rebase auth login` keeps,
82
+ * keyed by server origin. Never the project directory — a token there is one
83
+ * `git add .` from a repository — and never the cloud credentials file, which
84
+ * holds control-plane sessions a different command family manages.
85
+ * `REBASE_SESSIONS_FILE` moves it, for tests.
86
+ */
87
+ export declare function sessionsPath(): string;
88
+ /** The origin a session is filed under: scheme, host and port, no path. */
89
+ export declare function sessionKey(baseUrl: string): string;
90
+ export declare function storedSession(baseUrl: string): StoredSession | undefined;
91
+ export declare function saveSession(baseUrl: string, session: StoredSession): void;
92
+ /** Forget a server's session. Returns whether there was one. */
93
+ export declare function forgetSession(baseUrl: string): boolean;
94
+ /**
95
+ * The token pair out of an auth response — `{ tokens: { accessToken,
96
+ * refreshToken, accessTokenExpiresAt } }`, the shape login, refresh and the
97
+ * device grant all answer.
98
+ */
99
+ export declare function sessionTokensOf(body: unknown): Pick<StoredSession, "accessToken" | "refreshToken" | "expiresAt"> | undefined;
100
+ /**
101
+ * A refusal while resolving or reaching a target: what happened, what to do
102
+ * about it, and a stable code. Commands report it through the shared `fail`,
103
+ * so it is one JSON value when piped.
104
+ */
105
+ export declare class TargetError extends Error {
106
+ readonly hint?: string | undefined;
107
+ readonly code: string;
108
+ constructor(message: string, hint?: string | undefined, code?: string);
109
+ }
110
+ /** How a request reaches the app, and as whom — for messages and `--json` output. */
111
+ export type TargetCredential = "service-key" | "token" | "session" | "none" | "studio-proxy" | "platform-token";
112
+ export interface RequestOptions {
113
+ method?: string;
114
+ /** Query parameters. Repeated values (`string[]`) become repeated keys. */
115
+ query?: Record<string, string | number | boolean | readonly string[] | undefined>;
116
+ /** A JSON body, stringified here. */
117
+ json?: unknown;
118
+ /** A raw body, sent as it is. */
119
+ body?: BodyInit;
120
+ headers?: Record<string, string>;
121
+ /** Abort after this many milliseconds; unset means no limit (a stream, an upload). */
122
+ timeoutMs?: number;
123
+ }
124
+ export interface ProjectTarget {
125
+ kind: "server" | "cloud";
126
+ /** Where requests go, for messages: `http://localhost:3001 (rebase dev)`, `cloud project acme`. */
127
+ label: string;
128
+ credential: TargetCredential;
129
+ /** The app's own origin when it is reached directly; for the Studio proxy, the proxy's base. */
130
+ baseUrl: string;
131
+ /** The cloud project id, on a cloud target. */
132
+ projectId?: string;
133
+ /** Send a request to `path` on the app (`/api/admin/users`), with the credential. */
134
+ request(path: string, options?: RequestOptions): Promise<Response>;
135
+ /**
136
+ * The bearer a request carries, for the clients that open their own
137
+ * connection (the SDK's realtime socket). On the Studio proxy this is the
138
+ * control-plane session, which only the proxy accepts.
139
+ */
140
+ bearer(): Promise<string | undefined>;
141
+ }
142
+ export interface ProjectTargetOptions {
143
+ /** Names the command in messages: `data query`. */
144
+ command: string;
145
+ /**
146
+ * On a cloud target, ask the control plane for a platform token holding
147
+ * these scopes and call the app directly, instead of the Studio proxy.
148
+ * Only scopes the control plane issues (`cron:read`, `cron:write`), and
149
+ * only when no credential flag was given.
150
+ */
151
+ platformScopes?: readonly string[];
152
+ /**
153
+ * The credential the command needs when the line names none. `person`:
154
+ * the session `rebase auth login` stored (the RLS simulator and personal
155
+ * keys refuse machines). Default: the service key on a server target.
156
+ */
157
+ defaultCredential?: "service-key" | "person";
158
+ }
159
+ /** One line of query string out of {@link RequestOptions.query}. */
160
+ export declare function queryString(query: RequestOptions["query"]): string;
161
+ /**
162
+ * The service key this project's `.env` holds, and the variable it came from.
163
+ * The shell's `REBASE_SERVICE_KEY` wins over the file.
164
+ */
165
+ export declare function projectServiceKey(projectRoot: string | null): {
166
+ key: string;
167
+ variable: string;
168
+ } | undefined;
169
+ /**
170
+ * Resolve a project command's target from its parsed flags.
171
+ *
172
+ * @throws TargetError with a hint and a code; the caller reports it.
173
+ */
174
+ export declare function resolveProjectTarget(flags: ProjectTargetFlags, options: ProjectTargetOptions): Promise<ProjectTarget>;
175
+ /** `https://x.example/` and `x.example` both become `https://x.example`; a path is kept. */
176
+ export declare function normalizeOrigin(raw: string): string;
177
+ /** The app's error envelope: `{ error: { code, message, details } }`. */
178
+ export interface ApiErrorBody {
179
+ code?: string;
180
+ message?: string;
181
+ details?: unknown;
182
+ }
183
+ export declare function apiErrorOf(body: unknown): ApiErrorBody | undefined;
184
+ /**
185
+ * Read a JSON answer, or throw a {@link TargetError} carrying the app's own
186
+ * code and message — and, on a 401, which credential was refused, since that
187
+ * is the question the next command will be about.
188
+ */
189
+ export declare function readJson(res: Response, target: ProjectTarget, action: string): Promise<unknown>;
190
+ /** The refusal a non-2xx answer becomes. Exported for commands that read streams. */
191
+ export declare function failureOf(status: number, body: unknown, target: ProjectTarget, action: string): TargetError;
192
+ /** Lines that say why a server could not be reached — `rebase dev` not running, and where it would be. */
193
+ export declare function unreachableHint(target: ProjectTarget): string | undefined;
@@ -1,14 +1,14 @@
1
- import { a as wantsHelp, n as parseCommandArgs } from "./args-CaCcrYE1.js";
2
- import { a as findBackendDir, d as readEnvFile, i as failAsJson, l as getActiveBackendPlugin, p as requireProjectRoot } from "./project-CLcF5i8c.js";
3
- import { n as resolveSchemaDir } from "./schema-dir-Cd1kvYbf.js";
4
- import { a as refuseRemovedCollectionsFlag, n as SCHEMA_DIR_FLAG_HELP, r as missingSchemaDir } from "./path-flags-7O5uPBcQ.js";
5
- import { t as cmsDirectories } from "./cms-directories-BK3vcswg.js";
6
- import { t as loadProjectSchema } from "./project-schema-CsSOG2gE.js";
7
- import { a as backendGuardMissingMessage, n as BACKEND_GUARD_FIX, o as backendGuardStates } from "./backend-guard-C0mVkXBw.js";
1
+ import { a as wantsHelp, n as parseCommandArgs } from "./args-DHyrshtI.js";
2
+ import { a as findBackendDir, d as readEnvFile, i as failAsJson, l as getActiveBackendPlugin, p as requireProjectRoot } from "./project-DALmhb5R.js";
3
+ import { n as resolveSchemaDir } from "./schema-dir-ChcYfWjP.js";
4
+ import { a as refuseRemovedCollectionsFlag, n as SCHEMA_DIR_FLAG_HELP, r as missingSchemaDir } from "./path-flags-ekLdkbra.js";
5
+ import { t as cmsDirectories } from "./cms-directories-BaV-Is9a.js";
6
+ import { t as loadProjectSchema } from "./project-schema-Dm6Jk0Y_.js";
7
+ import { a as backendGuardMissingMessage, n as BACKEND_GUARD_FIX, o as backendGuardStates } from "./backend-guard-Cf8eMK_f.js";
8
8
  import chalk from "chalk";
9
9
  import fs from "fs";
10
10
  import path from "path";
11
- import { parseEnvBoolean } from "@rebasepro/types";
11
+ import { REBASE_ADMIN_REQUEST_ROLE, REBASE_ADMIN_ROLE, adminRequestRoleFor, parseEnvBoolean } from "@rebasepro/types";
12
12
  import { isSchemaDefinitionError } from "@rebasepro/common";
13
13
  //#region src/commands/verify-cms.ts
14
14
  /**
@@ -506,6 +506,9 @@ async function backendGuardFindings(projectRoot) {
506
506
  * `organization_id` / `tenant_id` column whose rules (its own, or the
507
507
  * `defaultRls` it inherits) let a role read every row regardless of it.
508
508
  * `rls` itself is mandatory, so "no rules at all" is a step-1 error now.
509
+ * And every compiled policy Postgres would refuse to expand (42P17): a
510
+ * rule that reads its own table in a sub-select, or tables whose rules
511
+ * read each other — `checkPolicyRecursion`.
509
512
  * 3. **CMS customizations** — every `customizeTable(...)` under
510
513
  * `frontend/src/cms`, read statically (`verify-cms.ts`): a slug no table
511
514
  * declares, a field that is not a column or relation of its table, a
@@ -706,6 +709,127 @@ function checkRls(verified) {
706
709
  }
707
710
  return findings;
708
711
  }
712
+ /** How the statements a policy of this command guards read in a finding. */
713
+ function statementsOf(command, table) {
714
+ switch (command) {
715
+ case "INSERT": return `every insert into ${table}`;
716
+ case "UPDATE": return `every update of ${table}`;
717
+ case "DELETE": return `every delete from ${table}`;
718
+ case "SELECT": return `every read of ${table}`;
719
+ default: return `every read and write of ${table}`;
720
+ }
721
+ }
722
+ var qualifiedName = (at) => `${at.schema}.${at.table}`;
723
+ /**
724
+ * Where the rule a policy compiles from is written: `rls[i]` of its table, the
725
+ * `defaultRls` rule it inherits, or — for a policy Rebase derives (a junction's,
726
+ * the admin baseline) — the table alone.
727
+ */
728
+ function ruleLocation(descriptor, planned, recursion) {
729
+ if (!descriptor) return {
730
+ path: recursion.table,
731
+ label: `policy "${recursion.policy}" of the junction table`
732
+ };
733
+ const slug = descriptor.slug;
734
+ const fallback = {
735
+ path: `${slug}.rls`,
736
+ label: `policy "${recursion.policy}"`
737
+ };
738
+ if (!planned || planned.injected || descriptor.rls.posture !== "rules") return fallback;
739
+ const rules = descriptor.rls.rules;
740
+ const index = planned.ruleKey.startsWith("#") ? Number(planned.ruleKey.slice(1)) : rules.findIndex((rule) => rule.name === planned.ruleKey);
741
+ if (!Number.isInteger(index) || index < 0 || index >= rules.length) return fallback;
742
+ return descriptor.rls.inherited ? {
743
+ path: `${slug}.rls`,
744
+ label: `the rule it inherits from \`defaultRls\` (defaultRls[${index}])`
745
+ } : {
746
+ path: `${slug}.rls[${index}]`,
747
+ label: `rls[${index}]`
748
+ };
749
+ }
750
+ /** One loop, in words: what the policy reads, and how that leads back to its table. */
751
+ function describeLoop(recursion) {
752
+ const home = qualifiedName(recursion);
753
+ if (recursion.path.length === 1) return `its own table, ${home}, in a sub-select`;
754
+ const through = recursion.path.slice(1).map((step, i, steps) => {
755
+ const next = i + 1 < steps.length ? qualifiedName(steps[i + 1]) : home;
756
+ return `whose read policy "${step.policy}" reads ${next}`;
757
+ });
758
+ return `${qualifiedName(recursion.reads)} in a sub-select, ${through.join(", ")} back`;
759
+ }
760
+ /**
761
+ * The tables' policies, compiled as the boot writes them, read for a loop
762
+ * Postgres refuses to expand: a rule that reads its own table in a
763
+ * sub-select, or two tables whose rules read each other. Since 0.25 every
764
+ * `rebase.uid()` is compiled to `(SELECT rebase.uid())` and the admin policies
765
+ * are sub-selects as well, so such a rule fails on every statement it guards,
766
+ * with 42P17 — for users, the service key and `dataAsAdmin` alike — where it
767
+ * worked on 0.21. The analysis is `findPolicyRecursion` from
768
+ * `@rebasepro/rls-check`, over the compiled SQL rather than the rules, so a
769
+ * structured `existsIn` and a junction's derived policy are read as well as
770
+ * raw SQL.
771
+ */
772
+ async function checkPolicyRecursion(verified) {
773
+ const { planPolicyDefinitions, REBASE_USER_ROLE } = await import("@rebasepro/server-postgres");
774
+ const { findPolicyRecursion } = await import("@rebasepro/rls-check");
775
+ let policies;
776
+ try {
777
+ policies = planPolicyDefinitions(verified.schema.compiled.tables, { adminRequestRoleAvailable: true });
778
+ } catch (error) {
779
+ return [{
780
+ step: "rls",
781
+ check: "rls-policy-plan",
782
+ severity: "error",
783
+ message: `The rules do not compile to policies: ${error instanceof Error ? error.message : String(error)}`,
784
+ fix: "Change the rules as the message says. The boot and `rebase db push` compile the same policies, and refuse them the same way."
785
+ }];
786
+ }
787
+ const adminRequestRole = adminRequestRoleFor(REBASE_USER_ROLE);
788
+ const recursions = findPolicyRecursion(policies, {
789
+ contexts: [{
790
+ name: REBASE_USER_ROLE,
791
+ roles: [REBASE_USER_ROLE]
792
+ }, {
793
+ name: adminRequestRole,
794
+ roles: [
795
+ adminRequestRole,
796
+ REBASE_USER_ROLE,
797
+ REBASE_ADMIN_ROLE,
798
+ REBASE_ADMIN_REQUEST_ROLE
799
+ ]
800
+ }],
801
+ searchPath: ["public"]
802
+ });
803
+ const order = (at) => policies.findIndex((p) => p.schema === at.schema && p.table === at.table && p.name === at.policy);
804
+ const byPolicy = /* @__PURE__ */ new Map();
805
+ for (const recursion of recursions) {
806
+ const at = order(recursion);
807
+ byPolicy.set(at, [...byPolicy.get(at) ?? [], recursion]);
808
+ }
809
+ return [...byPolicy.entries()].sort(([a], [b]) => a - b).map(([at, loops]) => {
810
+ const [first] = loops;
811
+ const descriptor = verified.descriptors.find((d) => d.kind === "table" && d.schema === first.schema && d.table === first.table);
812
+ const planned = policies[at];
813
+ const { path: rulePath, label } = ruleLocation(descriptor, planned, first);
814
+ const slug = descriptor?.slug ?? first.table;
815
+ const file = descriptor ? verified.files.get(slug) : void 0;
816
+ const home = qualifiedName(first);
817
+ const certain = loops.some((loop) => loop.confidence === "certain");
818
+ const who = loops.some((loop) => loop.contexts.includes(REBASE_USER_ROLE)) ? "" : " for admin requests (the service key, `dataAsAdmin` and admin users)";
819
+ const caveats = certain ? [] : [...new Set(loops.flatMap((loop) => loop.caveats))];
820
+ const readTables = [...new Set(loops.map((loop) => qualifiedName(loop.reads)))];
821
+ return {
822
+ step: "rls",
823
+ check: "rls-policy-recursion",
824
+ severity: certain ? "error" : "warning",
825
+ table: slug,
826
+ ...file && { file },
827
+ path: rulePath,
828
+ message: `"${slug}" ${label} (${first.command.toLowerCase()}) reads ${loops.map(describeLoop).join("; it also reads ")}, so Postgres refuses ${statementsOf(first.command, home)}${who} with 42P17 (infinite recursion detected in policy for relation "${first.table}"). Before 0.25 such a rule could pass: since then the compiler writes \`rebase.uid()\` as \`(SELECT rebase.uid())\` and the admin policies as sub-selects, so a table's own policies contain a sub-select even where its rules have none.` + (caveats.length > 0 ? ` Not certain: ${caveats.join(" ")}` : ""),
829
+ fix: `Move the read of ${readTables.join(" and ")} into a \`SECURITY DEFINER\` function, which Postgres does not expand while it applies policies, and call that function from the rule — e.g. \`CREATE FUNCTION public.can_access(…) RETURNS boolean LANGUAGE sql STABLE SECURITY DEFINER SET search_path = '' AS $$ SELECT EXISTS (SELECT 1 FROM ${readTables[0]} …) $$\`, then \`using: "public.can_access(…)"\`. Leave the policies Rebase generates as they are.`
830
+ };
831
+ });
832
+ }
709
833
  var POSTGRES_PLUGIN = "@rebasepro/server-postgres";
710
834
  /** Atlas's baseline bit in `atlas_schema_revisions.type`. */
711
835
  var REVISION_TYPE_BASELINE = 1;
@@ -953,6 +1077,7 @@ async function runVerify(options) {
953
1077
  schemaStep.detail = `${tables} table${tables === 1 ? "" : "s"}, compiled as the backend boots them`;
954
1078
  rlsStep.detail = `${tables} table${tables === 1 ? "" : "s"}`;
955
1079
  findings.push(...checkRls(verified));
1080
+ findings.push(...await checkPolicyRecursion(verified));
956
1081
  const cms = await checkCmsCustomizations(options.projectRoot, verified.descriptors);
957
1082
  if (cms.directories.length === 0) {
958
1083
  cmsStep.status = "skipped";
@@ -1064,7 +1189,8 @@ ${Object.entries(VERIFY_FLAG_HELP).map(([flag, help]) => ` ${chalk.blue(flag.pa
1064
1189
 
1065
1190
  ${chalk.green.bold("Steps")}
1066
1191
  1. Table definitions backend/schema loads and compiles as the backend boots it
1067
- 2. RLS coverage owner and tenant columns are filtered on by the rules that read them
1192
+ 2. RLS coverage owner and tenant columns are filtered on by the rules that read them,
1193
+ and no rule reads its own table back through a sub-select (42P17)
1068
1194
  3. CMS customizations frontend/src/cms: each customizeTable names a table, its fields, and a form that can create
1069
1195
  4. Migration freshness drizzle/migrations builds every declared table and column
1070
1196
  5. Live RLS audit with --live: the rls-check catalogue against the project's database
@@ -1097,9 +1223,9 @@ function authRequiredFrom(environment, envFile) {
1097
1223
  */
1098
1224
  async function resolveLiveDatabase(projectRoot, rawArgs, options) {
1099
1225
  try {
1100
- const { ensureDockerDatabase, databaseUrlOf } = await import("./db-A7XDCIIO.js");
1226
+ const { ensureDockerDatabase, databaseUrlOf } = await import("./db-D_iF4E-v.js");
1101
1227
  await ensureDockerDatabase(projectRoot, rawArgs);
1102
- const { prepareDatabaseEnv } = await import("./prepare-Ccxspoj-.js");
1228
+ const { prepareDatabaseEnv } = await import("./prepare-BaJe0Zik.js");
1103
1229
  return { databaseUrl: databaseUrlOf(await prepareDatabaseEnv(projectRoot, {
1104
1230
  flagUrl: options.flagUrl,
1105
1231
  flagDocker: options.flagDocker,
@@ -1157,4 +1283,4 @@ async function verifyCommand(rawArgs) {
1157
1283
  //#endregion
1158
1284
  export { verifyCommand };
1159
1285
 
1160
- //# sourceMappingURL=verify-DkJqhYPI.js.map
1286
+ //# sourceMappingURL=verify-BdeqNb-V.js.map