@mulmoclaude/core 3.13.0 → 3.15.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.
- package/dist/collection/registry/server/index.cjs +23 -6
- package/dist/collection/registry/server/index.cjs.map +1 -1
- package/dist/collection/registry/server/index.js +24 -7
- package/dist/collection/registry/server/index.js.map +1 -1
- package/dist/collection/server/appViews.d.ts +136 -0
- package/dist/collection/server/index.cjs +14 -1
- package/dist/collection/server/index.d.ts +2 -1
- package/dist/collection/server/index.js +2 -2
- package/dist/collection/server/publishManifest.d.ts +11 -1
- package/dist/collection/server/publishProject.d.ts +61 -0
- package/dist/collection-watchers/index.cjs +1 -1
- package/dist/collection-watchers/index.js +1 -1
- package/dist/feeds/server/index.cjs +1 -1
- package/dist/feeds/server/index.js +1 -1
- package/dist/{server-_g1rW-Uc.cjs → server-DLzQ4jFu.cjs} +500 -22
- package/dist/server-DLzQ4jFu.cjs.map +1 -0
- package/dist/{server-DGjmK9vU.js → server-jm7aGA3g.js} +423 -23
- package/dist/server-jm7aGA3g.js.map +1 -0
- package/package.json +1 -1
- package/dist/server-DGjmK9vU.js.map +0 -1
- package/dist/server-_g1rW-Uc.cjs.map +0 -1
|
@@ -11,6 +11,250 @@ import path from "node:path";
|
|
|
11
11
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
12
12
|
import { cp, lstat, mkdir, open, readFile, readdir, rm, rmdir, stat, unlink, writeFile } from "node:fs/promises";
|
|
13
13
|
import { z } from "zod";
|
|
14
|
+
//#region src/collection/server/appViews.ts
|
|
15
|
+
/** The audiences a view may be written for. A CLOSED set: each one names a
|
|
16
|
+
* tier with a rule behind it, so an unknown value has nowhere to be
|
|
17
|
+
* published to and is refused before it gets there. */
|
|
18
|
+
var VIEW_AUDIENCES = [
|
|
19
|
+
"public",
|
|
20
|
+
"member",
|
|
21
|
+
"participant"
|
|
22
|
+
];
|
|
23
|
+
/** Where each audience's documents live under `apps/{aid}`. `public` is not
|
|
24
|
+
* here: it keeps `config/public` + `config/view`, which are already published
|
|
25
|
+
* and already read by a deployed runtime. */
|
|
26
|
+
var VIEW_TIER = {
|
|
27
|
+
member: "member",
|
|
28
|
+
participant: "roster"
|
|
29
|
+
};
|
|
30
|
+
/** The id `public.view` normalizes to. Fixed rather than derived, so two
|
|
31
|
+
* implementations of the same normalization cannot pick different ones. */
|
|
32
|
+
var PUBLIC_VIEW_ID = "public";
|
|
33
|
+
/** `config` is the projection's own document in every tier (`live:config`),
|
|
34
|
+
* so a view may not be called that — the two would be the same document. */
|
|
35
|
+
var RESERVED_VIEW_IDS = ["config"];
|
|
36
|
+
/** What an id may be.
|
|
37
|
+
*
|
|
38
|
+
* Narrow on purpose: this value is written by the author, and it becomes a
|
|
39
|
+
* Firestore document id under a `live:` / `staged:` prefix. Excluding `:`
|
|
40
|
+
* keeps the prefix and the id from running together; excluding `/`, `.` and
|
|
41
|
+
* `__…__` keeps it a legal document id that addresses the path it says. */
|
|
42
|
+
var VIEW_ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
43
|
+
var VIEW_ID_SHAPE = "must be lowercase letters, digits and hyphens, start with a letter or digit, and be at most 64 characters (e.g. front-desk)";
|
|
44
|
+
/** Both declarations of the same thing, in one file.
|
|
45
|
+
*
|
|
46
|
+
* Refused rather than merged or preferred: whichever way it were resolved,
|
|
47
|
+
* the author would have written two answers and been shown neither. */
|
|
48
|
+
var BOTH_FORMS = "app.json declares both `views` and `public.view`. These are the same thing — `public.view` is the older spelling — and publishing would have to choose one silently. Move the `public.view` entry into `views` as { id: \"public\", audience: \"public\", … } and delete it.";
|
|
49
|
+
/** The two declarations, as one list, or the refusal that they are both there.
|
|
50
|
+
*
|
|
51
|
+
* `public.view` becomes an entry under the reserved id, so everything
|
|
52
|
+
* downstream reads one shape and "which spelling was used" is decided once. */
|
|
53
|
+
function declaredViews(app) {
|
|
54
|
+
const legacy = app.public?.view;
|
|
55
|
+
const authored = app.views;
|
|
56
|
+
if (legacy !== void 0 && authored !== void 0) return {
|
|
57
|
+
ok: false,
|
|
58
|
+
problems: [BOTH_FORMS]
|
|
59
|
+
};
|
|
60
|
+
const views = (authored ?? []).map((view, index) => ({
|
|
61
|
+
id: view.id,
|
|
62
|
+
audience: view.audience,
|
|
63
|
+
path: view.path,
|
|
64
|
+
collections: view.collections,
|
|
65
|
+
where: `views[${index}]`
|
|
66
|
+
}));
|
|
67
|
+
if (legacy === void 0) return {
|
|
68
|
+
ok: true,
|
|
69
|
+
views
|
|
70
|
+
};
|
|
71
|
+
if (views.some((view) => view.id === "public")) return {
|
|
72
|
+
ok: false,
|
|
73
|
+
problems: [`views declares id '${PUBLIC_VIEW_ID}', which is reserved for the older \`public.view\` spelling. ${BOTH_FORMS}`]
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
ok: true,
|
|
77
|
+
views: [...views, {
|
|
78
|
+
id: PUBLIC_VIEW_ID,
|
|
79
|
+
audience: "public",
|
|
80
|
+
path: legacy.path,
|
|
81
|
+
collections: legacy.collections,
|
|
82
|
+
where: "public.view"
|
|
83
|
+
}]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** Whether one id may be used, and what to say when it may not. */
|
|
87
|
+
function viewIdProblems(view) {
|
|
88
|
+
if (RESERVED_VIEW_IDS.includes(view.id)) return [`${view.where}.id is '${view.id}', which is reserved: each audience's own declaration is published at that document id.`];
|
|
89
|
+
if (!VIEW_ID_PATTERN.test(view.id)) return [`${view.where}.id is '${view.id}': a view id ${VIEW_ID_SHAPE}. It becomes the document id this view is published at.`];
|
|
90
|
+
if (view.id === "public" && view.audience !== "public") return [`${view.where}.id is '${PUBLIC_VIEW_ID}' with audience '${view.audience}': that id belongs to the public page.`];
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
/** ONE public page per app, and the reason is the wire rather than taste.
|
|
94
|
+
*
|
|
95
|
+
* The public runtime reads a single `config/view` document and a single
|
|
96
|
+
* `config/public.view` declaration beside it. A second `audience: "public"`
|
|
97
|
+
* entry would pass every other check and then be published nowhere — and
|
|
98
|
+
* which of the two became the live page would depend on declaration order,
|
|
99
|
+
* silently. The member tiers have no such limit: `id` is their address, and
|
|
100
|
+
* each one gets its own document.
|
|
101
|
+
*
|
|
102
|
+
* The refusal is here rather than "one day we will support it" precisely
|
|
103
|
+
* because the failure is invisible: nothing errors, and the author sees a
|
|
104
|
+
* successful publish of a page nobody is served. */
|
|
105
|
+
function singlePublicProblems(views) {
|
|
106
|
+
const [first, ...rest] = views.filter((view) => view.audience === "public");
|
|
107
|
+
if (first === void 0) return [];
|
|
108
|
+
return rest.map((view) => `${view.where} is a second audience "public" view, after ${first.where}. The public page is published at ONE document (config/view), so only one of them could ever be served — and which, would depend on the order they were written in. Give the others audience "member" or "participant", which are addressed by id and may have as many as the app needs.`);
|
|
109
|
+
}
|
|
110
|
+
/** The one shape everything downstream reads.
|
|
111
|
+
*
|
|
112
|
+
* Every caller — the publish gate, the projection, the host that writes the
|
|
113
|
+
* documents — goes through this, so "which declaration was used" is decided
|
|
114
|
+
* exactly once. */
|
|
115
|
+
function normalizeViews(app) {
|
|
116
|
+
const declared = declaredViews(app);
|
|
117
|
+
if (!declared.ok) return declared;
|
|
118
|
+
const problems = [...singlePublicProblems(declared.views)];
|
|
119
|
+
const seen = /* @__PURE__ */ new Map();
|
|
120
|
+
for (const view of declared.views) {
|
|
121
|
+
problems.push(...viewIdProblems(view));
|
|
122
|
+
const first = seen.get(view.id);
|
|
123
|
+
if (first === void 0) {
|
|
124
|
+
seen.set(view.id, view.where);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
problems.push(`${view.where}.id is '${view.id}', which ${first} already uses. The id is the document a view is published at, so two of them are one page — whichever was written second would silently replace the first, in staging and again at publish.`);
|
|
128
|
+
}
|
|
129
|
+
return problems.length > 0 ? {
|
|
130
|
+
ok: false,
|
|
131
|
+
problems
|
|
132
|
+
} : {
|
|
133
|
+
ok: true,
|
|
134
|
+
views: declared.views
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** How a participant reaches `cid`, or null if they cannot.
|
|
138
|
+
*
|
|
139
|
+
* Mirrors the rules' read branches for someone holding no role:
|
|
140
|
+
* `partRead` (the whole collection) and `ownRow` (their own record, found
|
|
141
|
+
* by the submit declaration's `emailField` or by a uid-derived id).
|
|
142
|
+
*
|
|
143
|
+
* `participantRead` is a PARAMETER rather than read off the manifest, and
|
|
144
|
+
* that is the whole point of the signature. Publish does not promote the
|
|
145
|
+
* manifest's value: `projectPublish` overwrites `participantRead` with what
|
|
146
|
+
* the STAGED schemas carry, so a cid added since the last deploy is in the
|
|
147
|
+
* manifest and not in the rules. Deriving the scope from the manifest would
|
|
148
|
+
* publish `scope: "all"` for a collection the promoted rules then deny —
|
|
149
|
+
* and removing one gives the mirror-image false refusal. The caller passes
|
|
150
|
+
* the set that will actually be in force. */
|
|
151
|
+
function participantScope(app, cid, participantRead) {
|
|
152
|
+
if (participantRead.includes(cid)) return {
|
|
153
|
+
cid,
|
|
154
|
+
scope: "all"
|
|
155
|
+
};
|
|
156
|
+
const submit = app.public?.submit?.[cid];
|
|
157
|
+
if (submit?.emailField !== void 0) return {
|
|
158
|
+
cid,
|
|
159
|
+
scope: "own",
|
|
160
|
+
emailField: submit.emailField
|
|
161
|
+
};
|
|
162
|
+
if (submit?.idFrom === "auth.uid") return {
|
|
163
|
+
cid,
|
|
164
|
+
scope: "own",
|
|
165
|
+
ownDocId: "auth.uid"
|
|
166
|
+
};
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
/** The document ids one tier uses. `live:` and `staged:` are the only two
|
|
170
|
+
* prefixes, so a single `match` covers the projection and every view. */
|
|
171
|
+
var viewDocId = (stage, viewId) => `${stage}:${viewId}`;
|
|
172
|
+
var VIEW_CONFIG_ID = "config";
|
|
173
|
+
/** The role a member holds on one collection, by the rules' own resolution:
|
|
174
|
+
* the per-collection entry, else the `*` fallback, else none. */
|
|
175
|
+
function roleOn(app, address, cid) {
|
|
176
|
+
const held = app.members[address];
|
|
177
|
+
if (held === void 0) return void 0;
|
|
178
|
+
return held[cid] ?? held["*"];
|
|
179
|
+
}
|
|
180
|
+
/** The addresses holding one of `roles` on `cid`.
|
|
181
|
+
*
|
|
182
|
+
* Sorted, for the same reason `memberEmails` is: a second publish of an
|
|
183
|
+
* unchanged declaration must produce an unchanged document. */
|
|
184
|
+
function holdersOf(app, cid, roles) {
|
|
185
|
+
return Object.keys(app.members).filter((address) => roles.includes(roleOn(app, address, cid) ?? "")).sort();
|
|
186
|
+
}
|
|
187
|
+
/** Who may write every row of `cid`, and who may write only their own.
|
|
188
|
+
*
|
|
189
|
+
* WHY ADDRESSES ARE PUBLISHED AT ALL. One `member/config` document is read by
|
|
190
|
+
* everyone the tier admits, and the tier only establishes that somebody holds
|
|
191
|
+
* SOME role SOMEWHERE — so a `viewer`, or a stylist scoped to another
|
|
192
|
+
* collection, reads the same entry as the front desk. Without these lists the
|
|
193
|
+
* page would draw approve and reassign for all of them and the rules would
|
|
194
|
+
* refuse when pressed, which is the declaration/enforcement mismatch this
|
|
195
|
+
* whole mechanism exists to prevent.
|
|
196
|
+
*
|
|
197
|
+
* It cannot be answered per principal instead: the document is written once
|
|
198
|
+
* at publish and read by many, and the reader cannot look their own role up —
|
|
199
|
+
* `apps/{aid}` is `readerOf(a, '*')`, and a stylist carrying only
|
|
200
|
+
* `{bookings: "editor"}` holds no `*` role. So the ROSTER'S ANSWER travels
|
|
201
|
+
* with the declaration and the page compares its own address to it.
|
|
202
|
+
*
|
|
203
|
+
* The cost is that staff addresses are visible to staff. That is already true
|
|
204
|
+
* of the approval mail they send each other, and participants read the
|
|
205
|
+
* `roster` tier, which never carries these.
|
|
206
|
+
*
|
|
207
|
+
* A SNAPSHOT, like everything else published: a member added since the last
|
|
208
|
+
* publish is absent until the next one. The rules are the authority either
|
|
209
|
+
* way — this only decides which buttons are drawn. */
|
|
210
|
+
function writersOf(app, cid) {
|
|
211
|
+
return holdersOf(app, cid, ["owner", "editor"]);
|
|
212
|
+
}
|
|
213
|
+
/** The transition half: which table applies, and the field it moves.
|
|
214
|
+
*
|
|
215
|
+
* Both halves or neither. A status field with no table would offer every
|
|
216
|
+
* value; a table with no field has nothing to write it to. */
|
|
217
|
+
function transitionPart(app, audience, cid) {
|
|
218
|
+
const config = app.collections?.[cid];
|
|
219
|
+
const transitions = audience === "member" ? config?.transitions : app.public?.submit?.[cid]?.selfTransitions;
|
|
220
|
+
if (config?.statusField === void 0 || transitions === void 0) return {};
|
|
221
|
+
const part = {
|
|
222
|
+
statusField: config.statusField,
|
|
223
|
+
transitions
|
|
224
|
+
};
|
|
225
|
+
if (audience === "member" && config.mail !== void 0) part.mail = config.mail;
|
|
226
|
+
return part;
|
|
227
|
+
}
|
|
228
|
+
/** The assignment half. `member` only — see {@link writersOf}.
|
|
229
|
+
*
|
|
230
|
+
* `rowWriters` rides here rather than beside `writers`, because the
|
|
231
|
+
* `assignee` role grants nothing at all without a field to compare against
|
|
232
|
+
* (`isAssigned` in the rules requires one, and publish refuses the pair). */
|
|
233
|
+
function assignPart(app, audience, cid) {
|
|
234
|
+
const assigneeField = app.collections?.[cid]?.assigneeField;
|
|
235
|
+
if (audience !== "member" || assigneeField === void 0) return {};
|
|
236
|
+
return {
|
|
237
|
+
assigneeField,
|
|
238
|
+
rowWriters: holdersOf(app, cid, ["assignee"])
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** What `audience` may change about `cid`, or null when the answer is nothing.
|
|
242
|
+
*
|
|
243
|
+
* The two audiences differ in WHICH transition table applies, in whether
|
|
244
|
+
* assignment exists at all, and in whether the roster's answer travels with
|
|
245
|
+
* it; they agree that the status field is the collection's, since the rules
|
|
246
|
+
* read one field either way. */
|
|
247
|
+
function writeFor(app, audience, cid) {
|
|
248
|
+
const write = {
|
|
249
|
+
cid,
|
|
250
|
+
...transitionPart(app, audience, cid),
|
|
251
|
+
...assignPart(app, audience, cid)
|
|
252
|
+
};
|
|
253
|
+
if (Object.keys(write).length === 1) return null;
|
|
254
|
+
if (audience === "member") write.writers = writersOf(app, cid);
|
|
255
|
+
return write;
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
14
258
|
//#region src/collection/server/publishManifest.ts
|
|
15
259
|
/** A collection id / app id, held to the one name rule (`SAFE_SLUG_PATTERN`)
|
|
16
260
|
* that `sharedCollectionKey` applies. Stated once so a path built later
|
|
@@ -264,6 +508,28 @@ var PublicZ = z.object({
|
|
|
264
508
|
}).strict().optional(),
|
|
265
509
|
submit: z.record(NameZ, SubmitZ).optional()
|
|
266
510
|
}).strict();
|
|
511
|
+
/** One page the app shows, and who it is for.
|
|
512
|
+
*
|
|
513
|
+
* Generalised from `public.view` (which is still accepted, and normalizes
|
|
514
|
+
* into this — see `appViews.ts`). The audience is what decides which document
|
|
515
|
+
* the HTML is published to, and therefore who may read it: a rule cannot hide
|
|
516
|
+
* a field, so "the front desk sees this" is a place, not a filter.
|
|
517
|
+
*
|
|
518
|
+
* `id` is not decoration. It becomes the document id the page is published
|
|
519
|
+
* at, which is what lets one audience have more than one page — the front
|
|
520
|
+
* desk and the stock room — and what lets a withdrawn view be found and
|
|
521
|
+
* deleted. Its grammar is enforced at the gate, not here, so the refusal can
|
|
522
|
+
* say what the value is used for.
|
|
523
|
+
*
|
|
524
|
+
* `collections` is declared rather than inferred, for the reason `public.view`
|
|
525
|
+
* gives: an inferred list renders a perfect page with no data in it, and
|
|
526
|
+
* nothing anywhere says why. */
|
|
527
|
+
var ViewZ = z.object({
|
|
528
|
+
id: z.string().trim().min(1),
|
|
529
|
+
audience: z.enum(VIEW_AUDIENCES),
|
|
530
|
+
path: z.string().trim().min(1),
|
|
531
|
+
collections: z.array(NameZ).min(1)
|
|
532
|
+
}).strict();
|
|
267
533
|
/** The URL name an app is handed out under: `https://<host>/{slug}`.
|
|
268
534
|
*
|
|
269
535
|
* A SEPARATE name from the `aid`, and that separation is the point (design
|
|
@@ -312,7 +578,10 @@ var AuthoredAppZ = z.object({
|
|
|
312
578
|
members: MembersZ,
|
|
313
579
|
collections: z.record(NameZ, CollectionConfigZ).optional(),
|
|
314
580
|
participantRead: z.array(NameZ).optional(),
|
|
315
|
-
public: PublicZ.optional()
|
|
581
|
+
public: PublicZ.optional(),
|
|
582
|
+
/** The app's pages, per audience. See {@link ViewZ}; `public.view` is the
|
|
583
|
+
* older spelling of the `public` one and normalizes into this list. */
|
|
584
|
+
views: z.array(ViewZ).optional()
|
|
316
585
|
}).strict();
|
|
317
586
|
/** Parse the authored declaration out of `app.json`'s text.
|
|
318
587
|
*
|
|
@@ -441,11 +710,14 @@ function projectApp(authored, schemas, stamp, existing) {
|
|
|
441
710
|
publishedDirty: stamp.dirty === true ? true : void 0,
|
|
442
711
|
previousPublished: previousOf(existing)
|
|
443
712
|
});
|
|
713
|
+
const normalized = normalizeViews(authored);
|
|
714
|
+
if (!normalized.ok) throw new Error(`publish: views declaration is not publishable (${normalized.problems.join(" ")})`);
|
|
715
|
+
const publicView = normalized.views.find((view) => view.audience === "public");
|
|
444
716
|
const config = {
|
|
445
717
|
enabled: authored.public?.enabled === true,
|
|
446
718
|
read: authored.public?.read ?? [],
|
|
447
719
|
submit,
|
|
448
|
-
...
|
|
720
|
+
...publicView === void 0 ? {} : { view: { collections: publicView.collections } },
|
|
449
721
|
publishedAt: stamp.publishedAt
|
|
450
722
|
};
|
|
451
723
|
if (authored.name !== void 0) config.name = authored.name;
|
|
@@ -596,6 +868,86 @@ var appSlugDoc = (aid, published) => ({
|
|
|
596
868
|
var appStagingPath = (aid) => `apps/${aid}/staging`;
|
|
597
869
|
/** The public-config documents' parent path. */
|
|
598
870
|
var appConfigPath = (aid) => `apps/${aid}/config`;
|
|
871
|
+
/** Where one audience's pages live. `member` is read by anyone holding a role;
|
|
872
|
+
* `roster` by anyone on the roster, participants included. */
|
|
873
|
+
var appViewTierPath = (aid, tier) => `apps/${aid}/${tier}`;
|
|
874
|
+
/** What one audience may see of one collection.
|
|
875
|
+
*
|
|
876
|
+
* For `member` this is always the whole collection: every read branch a role
|
|
877
|
+
* opens (`readerOf`) is unscoped. Whether THIS member holds the role is not
|
|
878
|
+
* knowable here — one projection is read by every member of the tier — and is
|
|
879
|
+
* settled where it can be, by the entrance trying the read.
|
|
880
|
+
*
|
|
881
|
+
* For `participant` it is the rules' own answer, which is why it can be null:
|
|
882
|
+
* a participant with neither `participantRead` nor an own-row submit path
|
|
883
|
+
* cannot read the collection at all, and a page handed it would fail rather
|
|
884
|
+
* than render less. */
|
|
885
|
+
function scopeFor(authored, audience, cid, participantRead) {
|
|
886
|
+
return audience === "member" ? {
|
|
887
|
+
cid,
|
|
888
|
+
scope: "all"
|
|
889
|
+
} : participantScope(authored, cid, participantRead);
|
|
890
|
+
}
|
|
891
|
+
/** What this audience may CHANGE, per collection it draws.
|
|
892
|
+
*
|
|
893
|
+
* The `collections` config is the PROMOTED one where there is one: at publish
|
|
894
|
+
* the rules run against what deploy staged, so projecting the manifest's
|
|
895
|
+
* would advertise transitions the live rules deny. */
|
|
896
|
+
function tierWrites(authored, audience, cids, promoted) {
|
|
897
|
+
const effective = promoted.collections === void 0 ? authored : {
|
|
898
|
+
...authored,
|
|
899
|
+
collections: promoted.collections
|
|
900
|
+
};
|
|
901
|
+
return cids.map((cid) => writeFor(effective, audience, cid)).filter((entry) => entry !== null);
|
|
902
|
+
}
|
|
903
|
+
/** What this audience may READ, and how to query for it.
|
|
904
|
+
*
|
|
905
|
+
* A collection with no scope is dropped rather than published as unreachable:
|
|
906
|
+
* the gate has already refused the declaration, so reaching here with one is
|
|
907
|
+
* a programming error, and a page that queries it is denied. */
|
|
908
|
+
function tierViews(authored, audience, views, participantRead) {
|
|
909
|
+
return views.map((view) => ({
|
|
910
|
+
id: view.id,
|
|
911
|
+
collections: view.collections.map((cid) => scopeFor(authored, audience, cid, participantRead)).filter((scope) => scope !== null)
|
|
912
|
+
}));
|
|
913
|
+
}
|
|
914
|
+
/** One tier's projection: what this audience may read, and what it may change. */
|
|
915
|
+
function tierConfig(authored, audience, views, stamp, promoted) {
|
|
916
|
+
const cids = [...new Set(views.flatMap((view) => view.collections))];
|
|
917
|
+
const config = {
|
|
918
|
+
write: tierWrites(authored, audience, cids, promoted),
|
|
919
|
+
views: tierViews(authored, audience, views, promoted.participantRead ?? authored.participantRead ?? []),
|
|
920
|
+
submit: tierSubmit(authored, cids),
|
|
921
|
+
publishedAt: stamp.publishedAt
|
|
922
|
+
};
|
|
923
|
+
if (authored.name !== void 0) config.name = authored.name;
|
|
924
|
+
return config;
|
|
925
|
+
}
|
|
926
|
+
/** The submit declarations for the collections these views draw, so a page can
|
|
927
|
+
* show what may be sent rather than discovering it from a denial. */
|
|
928
|
+
function tierSubmit(authored, cids) {
|
|
929
|
+
const declared = authored.public?.submit ?? {};
|
|
930
|
+
return Object.fromEntries(cids.flatMap((cid) => {
|
|
931
|
+
const spec = declared[cid];
|
|
932
|
+
return spec === void 0 ? [] : [[cid, projectSubmit(spec)]];
|
|
933
|
+
}));
|
|
934
|
+
}
|
|
935
|
+
function projectAppViews(authored, stamp, promoted = {}) {
|
|
936
|
+
const normalized = normalizeViews(authored);
|
|
937
|
+
if (!normalized.ok) throw new Error(`publish: views declaration is not publishable (${normalized.problems.join(" ")})`);
|
|
938
|
+
return ["member", "participant"].map((audience) => {
|
|
939
|
+
const views = normalized.views.filter((view) => view.audience === audience);
|
|
940
|
+
return {
|
|
941
|
+
tier: VIEW_TIER[audience],
|
|
942
|
+
audience,
|
|
943
|
+
config: tierConfig(authored, audience, views, stamp, promoted),
|
|
944
|
+
views
|
|
945
|
+
};
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
/** The document a tier's projection is published at. Beside the views
|
|
949
|
+
* themselves, under one `match` — see `firestore.rules`. */
|
|
950
|
+
var viewConfigDocId = (stage) => viewDocId(stage, VIEW_CONFIG_ID);
|
|
599
951
|
//#endregion
|
|
600
952
|
//#region src/collection/server/publishChecks.ts
|
|
601
953
|
/** Does this submit declaration bind a record to the submitter's identity?
|
|
@@ -871,7 +1223,7 @@ function publishProblems(app, collections, publisherEmail) {
|
|
|
871
1223
|
...windowRefProblems(app, collections),
|
|
872
1224
|
...idTargetProblems(app, collections),
|
|
873
1225
|
...mirrorProblems(app, collections),
|
|
874
|
-
...
|
|
1226
|
+
...viewProblems(app, collections)
|
|
875
1227
|
];
|
|
876
1228
|
}
|
|
877
1229
|
/** A public submission must NOT be allowed to name its own primary key.
|
|
@@ -1002,24 +1354,56 @@ function mirrorOfProblems(app, cid, collection, known, names) {
|
|
|
1002
1354
|
if (app.public?.submit?.[authority]?.mirror !== cid) return [`collections.${cid}.mirrorOf names '${authority}', but public.submit.${authority} does not declare mirror: "${cid}". Only the pair keeps the projection honest: without the other half a record can be created without moving this one, and the public page goes on offering something that is already taken.`];
|
|
1003
1355
|
return [];
|
|
1004
1356
|
}
|
|
1005
|
-
/** What
|
|
1006
|
-
*
|
|
1007
|
-
*
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1357
|
+
/** What each view is handed, and whether its audience can actually read it.
|
|
1358
|
+
*
|
|
1359
|
+
* Declared, never inferred — a view whose datasets were guessed from
|
|
1360
|
+
* `public.read` renders perfectly and draws an empty grid, with nothing in
|
|
1361
|
+
* the page, the rules or the log to say why.
|
|
1362
|
+
*
|
|
1363
|
+
* The reachability check below is that same failure, once per audience. A
|
|
1364
|
+
* `public` view naming a collection outside `public.read` draws nothing; a
|
|
1365
|
+
* `participant` view naming one the participant reaches by neither
|
|
1366
|
+
* `participantRead` nor their own row is worse, because an unscoped list on
|
|
1367
|
+
* an own-row collection is DENIED rather than narrowed — the page does not
|
|
1368
|
+
* render less, it fails.
|
|
1369
|
+
*
|
|
1370
|
+
* There is deliberately no such check for `member`. Every read a role opens
|
|
1371
|
+
* is unscoped, and WHICH role a given member holds is not a property of the
|
|
1372
|
+
* declaration: a stylist scoped to `bookings` and an owner read the same
|
|
1373
|
+
* projection. That one is settled at the entrance, by trying the read. */
|
|
1374
|
+
/** The path, for one view. The SAME validator the host's own custom views use,
|
|
1375
|
+
* rather than a second opinion about what a safe view path is.
|
|
1376
|
+
*
|
|
1377
|
+
* Two ad-hoc attempts were wrong here in the same afternoon: a prefix-and-
|
|
1378
|
+
* suffix test let `views/../../secrets.html` through, and `views/[^/]+\.html`
|
|
1379
|
+
* still let `views/..\..\secrets.html` through, because a backslash is not a
|
|
1380
|
+
* slash on this side of the check and IS a separator on Windows. This one
|
|
1381
|
+
* rejects `..`, backslashes, leading slashes and anything outside
|
|
1382
|
+
* `[A-Za-z0-9._-]` per segment.
|
|
1383
|
+
*
|
|
1384
|
+
* It matters more here than for a host view: the host reads this path to
|
|
1385
|
+
* decide which file to copy onto a document other people read — for a public
|
|
1386
|
+
* view, a document whose rule is `allow read: if true`, so the blast radius of
|
|
1387
|
+
* a bad path is the world rather than the author's own iframe. Nested paths
|
|
1388
|
+
* ARE allowed by the shared validator; the extra `views/<one name>.html` shape
|
|
1389
|
+
* is this publisher's own narrowing, kept because there is no reason for a
|
|
1390
|
+
* published view to live in a subdirectory. */
|
|
1391
|
+
function viewPathProblems(view) {
|
|
1392
|
+
if (isSafeCustomViewPath(view.path) && view.path.split("/").length === 2) return [];
|
|
1393
|
+
return [`${view.where}.path is '${view.path}': a published view is exactly one HTML file directly inside the collection's own views/ directory (e.g. views/booking.html) — no sub-directories, and no segments that climb out of it. The host reads this as a file to publish.`];
|
|
1394
|
+
}
|
|
1395
|
+
/** One dataset, for one view: does it exist here, and can the audience it is
|
|
1396
|
+
* handed to actually read it? */
|
|
1397
|
+
function viewCollectionProblems(app, view, cid, known) {
|
|
1398
|
+
if (!known.has(cid)) return [`${view.where}.collections names '${cid}', which is not a shared collection in this repository. Shared collections here: ${known.size > 0 ? [...known].sort().join(", ") : "(none)"}.`];
|
|
1399
|
+
if (view.audience === "public" && !(app.public?.read ?? []).includes(cid)) return [`${view.where}.collections names '${cid}', which is not in public.read: the page reads these with the VISITOR's permissions, so the rules refuse the read and the view draws an empty page. Nothing errors — this is the failure that looks like a working view with no data.`];
|
|
1400
|
+
return [];
|
|
1401
|
+
}
|
|
1402
|
+
function viewProblems(app, collections) {
|
|
1403
|
+
const normalized = normalizeViews(app);
|
|
1404
|
+
if (!normalized.ok) return normalized.problems;
|
|
1011
1405
|
const known = new Set(collections.map((collection) => collection.cid));
|
|
1012
|
-
|
|
1013
|
-
const problems = [];
|
|
1014
|
-
if (!isSafeCustomViewPath(view.path) || view.path.split("/").length !== 2) problems.push(`public.view.path is '${view.path}': a published view is exactly one HTML file directly inside the collection's own views/ directory (e.g. views/booking.html) — no sub-directories, and no segments that climb out of it. The host reads this as a file to publish, and what it publishes is world-readable.`);
|
|
1015
|
-
for (const cid of view.collections) {
|
|
1016
|
-
if (!known.has(cid)) {
|
|
1017
|
-
problems.push(`public.view.collections names '${cid}', which is not a shared collection in this repository. Shared collections here: ${known.size > 0 ? [...known].sort().join(", ") : "(none)"}.`);
|
|
1018
|
-
continue;
|
|
1019
|
-
}
|
|
1020
|
-
if (!readable.has(cid)) problems.push(`public.view.collections names '${cid}', which is not in public.read: the page reads these with the VISITOR's permissions, so the rules refuse the read and the view draws an empty page. Nothing errors — this is the failure that looks like a working view with no data.`);
|
|
1021
|
-
}
|
|
1022
|
-
return problems;
|
|
1406
|
+
return normalized.views.flatMap((view) => [...viewPathProblems(view), ...view.collections.flatMap((cid) => viewCollectionProblems(app, view, cid, known))]);
|
|
1023
1407
|
}
|
|
1024
1408
|
/** What publish will actually promote, checked as the PAIR it becomes.
|
|
1025
1409
|
*
|
|
@@ -1051,9 +1435,25 @@ function promotedRoleProblems(app, staged) {
|
|
|
1051
1435
|
return [
|
|
1052
1436
|
...promotedAssigneeProblems(app, promoted, stagedCids),
|
|
1053
1437
|
...promotedMirrorProblems(app, promoted, stagedCids),
|
|
1054
|
-
...promotedRefFieldProblems(app, staged)
|
|
1438
|
+
...promotedRefFieldProblems(app, staged),
|
|
1439
|
+
...promotedParticipantViewProblems(app, staged)
|
|
1055
1440
|
];
|
|
1056
1441
|
}
|
|
1442
|
+
/** A participant's page, checked against the `participantRead` publish will
|
|
1443
|
+
* actually PROMOTE.
|
|
1444
|
+
*
|
|
1445
|
+
* Not against the manifest's. `projectPublish` overwrites `participantRead`
|
|
1446
|
+
* with what the staged schemas carry, so a cid added to the manifest since the
|
|
1447
|
+
* last deploy is not in the rules — and a page written for it would be
|
|
1448
|
+
* published, offered, and then refused the read. The manifest half of this
|
|
1449
|
+
* file cannot see that; the promoted half can, which is why the check lives
|
|
1450
|
+
* here rather than beside the other view checks. */
|
|
1451
|
+
function promotedParticipantViewProblems(app, staged) {
|
|
1452
|
+
const normalized = normalizeViews(app);
|
|
1453
|
+
if (!normalized.ok) return [];
|
|
1454
|
+
const participantRead = stagedRuleConfig(staged).participantRead ?? [];
|
|
1455
|
+
return normalized.views.filter((view) => view.audience === "participant").flatMap((view) => view.collections.filter((cid) => participantScope(app, cid, participantRead) === null).map((cid) => `${view.where}.collections names '${cid}', which a participant cannot read once this publishes: it is not in the participantRead that DEPLOY staged, and public.submit.${cid} declares neither an emailField nor idFrom "auth.uid", so there is no row the rules would call theirs. The page would be refused the read, not handed fewer records. (Adding it to participantRead in app.json is not enough — deploy first.)`));
|
|
1456
|
+
}
|
|
1057
1457
|
/** The FIELDS a rule reads off another record — `idIn.where.field` and the two
|
|
1058
1458
|
* window bounds — checked against the schema publish is about to promote.
|
|
1059
1459
|
*
|
|
@@ -3258,6 +3658,6 @@ function makeManageCollectionTool(deps = {}) {
|
|
|
3258
3658
|
};
|
|
3259
3659
|
}
|
|
3260
3660
|
//#endregion
|
|
3261
|
-
export {
|
|
3661
|
+
export { stagedRuleConfig as $, runQueryOverRows as A, APPS_COLLECTION as B, STORE_UNREADABLE as C, recordFieldProblem as D, compileRecordZ as E, readCustomViewI18n as F, appSlugDoc as G, PUBLIC_CONFIG_DOC as H, readSkillTemplate as I, projectApp as J, appStagingPath as K, bindsSubmitterIdentity as L, buildCollectionActionSeedPrompt as M, promptPathsFor as N, runCollectionQuery as O, readCustomViewHtml as P, promoteSchema as Q, promotedRoleProblems as R, MAX_RECORD_ISSUES as S, validateRecordObject as T, appConfigPath as U, APP_SLUGS_COLLECTION as V, appSchemasPath as W, projectDeploy as X, projectAppViews as Y, projectPublish as Z, computeCollectionIcon as _, deleteCollection as a, RESERVED_VIEW_IDS as at, applyMutateAction as b, computeSuccessor as c, VIEW_ID_PATTERN as ct, isTriggerDue as d, participantScope as dt, viewConfigDocId as et, maybeSpawnSuccessor as f, viewDocId as ft, ONE_SECOND_MS as g, successorId as h, deleteCustomView as i, PUBLIC_VIEW_ID as it, buildActionSeedPrompt as j, enrichItems as k, daysInMonth as l, VIEW_TIER as lt, resolveEvery as m, MAX_UNSELECTIVE_ITEMS as n, AuthoredAppZ as nt, deleteCollectionRefusalMessage as o, VIEW_AUDIENCES as ot, parseCivil as p, writeFor as pt, appViewTierPath as q, makeManageCollectionTool as r, parseAuthoredApp as rt, advanceTriggerDate as s, VIEW_CONFIG_ID as st, MAX_SCHEMA_ISSUES as t, APP_ROLES as tt, formatCivil as u, normalizeViews as ut, buildWorkspaceOntology as v, validateCollectionRecords as w, firstMutateParamProblem as x, schemaRelations as y, publishProblems as z };
|
|
3262
3662
|
|
|
3263
|
-
//# sourceMappingURL=server-
|
|
3663
|
+
//# sourceMappingURL=server-jm7aGA3g.js.map
|