@rebasepro/cli 0.10.1-canary.d8d45b2 → 0.10.1-canary.ed78a2c

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.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Ambient declarations for the asset imports a frontend component makes.
3
+ *
4
+ * A collection that points at a custom `Field` or `Preview` with a lazy `import()`
5
+ * thunk gets that reference type-checked — which means TypeScript resolves the
6
+ * component's *own* imports too, including `import icon from "./icon.png"`. That
7
+ * import is Vite's doing and means nothing to `tsc`: the frontend gets away with it
8
+ * through `vite/client` types, but those belong to the frontend's program, not this
9
+ * one, and Vite is not a dependency here (nothing in `config/` runs in a browser).
10
+ *
11
+ * Without these three lines, adding your first custom component fails the config and
12
+ * backend builds with `Cannot find module './icon.png'` — pointing at a frontend file
13
+ * from a build that has no obvious business compiling it.
14
+ */
15
+ declare module "*.png" { const src: string; export default src; }
16
+ declare module "*.svg" { const src: string; export default src; }
17
+ declare module "*.jpg" { const src: string; export default src; }
@@ -4,3 +4,9 @@
4
4
  */
5
5
 
6
6
  export { collections } from "./collections/index.js";
7
+
8
+ // Who may read, write, delete and list files in storage. Exported from here
9
+ // because that is where the runtime and `rebase cloud deploy` look for it — the
10
+ // bundle manifest records whether this export exists, so a managed deploy can be
11
+ // refused with a readable message instead of turning into a boot crash-loop.
12
+ export { storageAuthorize } from "./storage.js";
@@ -1,28 +1,29 @@
1
1
  {
2
- "name": "{{PROJECT_NAME}}-config",
3
- "version": "1.0.0",
4
- "description": "Shared collections for frontend and backend",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "type": "module",
8
- "private": true,
9
- "scripts": {
10
- "build": "tsc",
11
- "dev": "tsc --watch",
12
- "clean": "rm -rf dist"
2
+ "name": "{{PROJECT_NAME}}-config",
3
+ "version": "1.0.0",
4
+ "description": "Shared collections for frontend and backend",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "private": true,
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "dev": "tsc --watch",
12
+ "clean": "rm -rf dist"
13
+ },
14
+ "dependencies": {
15
+ "@rebasepro/admin-types": "workspace:*",
16
+ "@rebasepro/types": "workspace:*"
17
+ },
18
+ "devDependencies": {
19
+ "typescript": "^5.9.2"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
13
26
  },
14
- "dependencies": {
15
- "@rebasepro/types": "workspace:*"
16
- },
17
- "devDependencies": {
18
- "typescript": "^5.9.2"
19
- },
20
- "exports": {
21
- ".": {
22
- "import": "./dist/index.js",
23
- "types": "./dist/index.d.ts",
24
- "default": "./dist/index.js"
25
- },
26
- "./package.json": "./package.json"
27
- }
27
+ "./package.json": "./package.json"
28
+ }
28
29
  }
@@ -0,0 +1,88 @@
1
+ import { isPublicStoragePath, type StorageAuthorize } from "@rebasepro/types";
2
+
3
+ /**
4
+ * Who may do what to files in storage.
5
+ *
6
+ * Storage is **not** under row-level security. Collections are: a request runs as
7
+ * `rebase_user` and Postgres decides row by row. Object storage has no equivalent,
8
+ * so keys share one flat namespace and this hook is the whole authorization model.
9
+ * Without it the server refuses to boot in production, because "authenticated"
10
+ * would be the only thing standing between a signed-in visitor and every file in
11
+ * the bucket — they could `GET /storage/list?prefix=` to enumerate every key, then
12
+ * read, overwrite or delete any of them.
13
+ *
14
+ * ## The model this starter ships
15
+ *
16
+ * A CMS's files are **shared content**, not private per-user documents: hero
17
+ * images, author pictures, product photos. The collections in this template upload
18
+ * to `author_pictures/`, `posts/hero/`, `product_images/` — paths named after the
19
+ * content, not after a user. So the boundary that matters here is not *whose file
20
+ * is this* but *who is allowed to change the library*:
21
+ *
22
+ * | operation | who |
23
+ * | --- | --- |
24
+ * | `read` of `public/…` | anyone, signed in or not |
25
+ * | `read` | any signed-in user — it is content, and the admin panel renders it |
26
+ * | `write`, `delete`, `list` | `admin` or `editor` only |
27
+ *
28
+ * Gating `list` is the important half. Enumeration is what turns "keys are hard to
29
+ * guess" into "keys are trivially known", and it is the first step of the attack
30
+ * the boot guard exists to prevent.
31
+ *
32
+ * ## If your app is multi-tenant, replace this
33
+ *
34
+ * Per-user or per-tenant files need an **ownership** check, and ownership lives in
35
+ * a row rather than in a key — so `ctx.data` hands you trusted, RLS-bypassing read
36
+ * access to answer it:
37
+ *
38
+ * ```ts
39
+ * export const storageAuthorize: StorageAuthorize = async ({ key, user, operation, data }) => {
40
+ * if (operation === "read" && isPublicStoragePath(key)) return true;
41
+ * if (!user) return false;
42
+ *
43
+ * // Writes land under the caller's own prefix.
44
+ * if (operation === "write") return key.startsWith(`users/${user.uid}/`);
45
+ * if (operation === "list") return key.startsWith(`users/${user.uid}/`);
46
+ *
47
+ * // Reads and deletes check the row that owns the object.
48
+ * const attachment = (await data?.collection("attachments").find({
49
+ * where: { storage_key: ["==", key] }, limit: 1
50
+ * }))?.data?.[0];
51
+ * return attachment?.owner_id === user.uid;
52
+ * };
53
+ * ```
54
+ *
55
+ * Note that a prefix rule alone is not an access-control model for reads — it only
56
+ * works because a write *puts* the object there. Anything already in the bucket
57
+ * needs the row consulted.
58
+ *
59
+ * The two escape hatches, if you would rather not write a hook at all:
60
+ * `storagePublicRead: true` when the bucket genuinely is a public read-only CDN,
61
+ * or `storageInsecureAllowAnyAuthenticated: true` for a single-tenant app where
62
+ * every signed-in user is trusted with every file. Both are set on
63
+ * `initializeRebaseBackend` in `backend/src/index.ts`.
64
+ */
65
+ export const storageAuthorize: StorageAuthorize = ({ key, user, operation }) => {
66
+ // The `public/` prefix is the framework's convention for world-readable
67
+ // objects, and it is what signed download URLs for public assets rely on.
68
+ if (operation === "read" && isPublicStoragePath(key)) {
69
+ return true;
70
+ }
71
+
72
+ // Everything else needs a caller. `user` is null on routes that allow
73
+ // unauthenticated access, so this is the anonymous denial.
74
+ if (!user) {
75
+ return false;
76
+ }
77
+
78
+ // Content is shared: any signed-in user may read it. A `viewer` has to be able
79
+ // to see the images the admin panel shows them.
80
+ if (operation === "read") {
81
+ return true;
82
+ }
83
+
84
+ // Changing or enumerating the library is an editor's job. Matches the roles in
85
+ // `collections/users.ts` — widen this if you add your own.
86
+ const roles = user.roles ?? [];
87
+ return roles.includes("admin") || roles.includes("editor");
88
+ };