@aglyn/tenant-runtime 1.0.0-beta.220 → 1.0.0-beta.222
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/README.md +6 -3
- package/package.json +5 -3
- package/src/index.d.ts +0 -3
- package/src/index.js +1 -4
- package/src/index.js.map +1 -1
- package/src/lib/apply-publish-schedule.js +41 -17
- package/src/lib/apply-publish-schedule.js.map +1 -1
- package/src/lib/compose-screen-nodes.d.ts +9 -0
- package/src/lib/compose-screen-nodes.js +13 -4
- package/src/lib/compose-screen-nodes.js.map +1 -1
- package/src/lib/enrich-gated-page.js +17 -2
- package/src/lib/enrich-gated-page.js.map +1 -1
- package/src/lib/get-site-icon-facts.d.ts +43 -0
- package/src/lib/get-site-icon-facts.js +105 -0
- package/src/lib/get-site-icon-facts.js.map +1 -0
- package/src/lib/self-hosted-fonts.d.ts +44 -0
- package/src/lib/self-hosted-fonts.js +149 -0
- package/src/lib/self-hosted-fonts.js.map +1 -0
- package/src/lib/assign-contact-owner.d.ts +0 -162
- package/src/lib/assign-contact-owner.js +0 -340
- package/src/lib/assign-contact-owner.js.map +0 -1
- package/src/lib/associate-company-by-domain.d.ts +0 -70
- package/src/lib/associate-company-by-domain.js +0 -153
- package/src/lib/associate-company-by-domain.js.map +0 -1
- package/src/lib/capture-host-contact.d.ts +0 -104
- package/src/lib/capture-host-contact.js +0 -151
- package/src/lib/capture-host-contact.js.map +0 -1
- package/src/lib/repeat-record-pages.d.ts +0 -48
- package/src/lib/repeat-record-pages.js +0 -64
- package/src/lib/repeat-record-pages.js.map +0 -1
- package/src/lib/resolve-dataset.d.ts +0 -40
- package/src/lib/resolve-dataset.js +0 -64
- package/src/lib/resolve-dataset.js.map +0 -1
package/README.md
CHANGED
|
@@ -36,9 +36,12 @@ single plugin owns, and runs none of what an event triggers:
|
|
|
36
36
|
- `listHostEventListeners` and `runHostEventListeners` for diagnostics and
|
|
37
37
|
direct use.
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
(
|
|
41
|
-
|
|
39
|
+
Contact capture and owner assignment are the CRM's
|
|
40
|
+
(`@aglyn/plugins-crm/server/capture-host-contact`,
|
|
41
|
+
`@aglyn/plugins-crm/server/assign-contact-owner`): another plugin reports a
|
|
42
|
+
person through the platform's capture contract (`plugin-contact-capture`).
|
|
43
|
+
Finding a dataset by its id or name is the data plugin's
|
|
44
|
+
(`@aglyn/plugins-data/server/resolve-dataset`).
|
|
42
45
|
|
|
43
46
|
By subpath, the screen-composition pipeline. This is the render read-path
|
|
44
47
|
shared by the tenant app's server rendering and any plugin that needs to
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/tenant-runtime",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.222",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,8 +25,10 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.0.0-beta.
|
|
29
|
-
"@aglyn/
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.222",
|
|
29
|
+
"@aglyn/shared-data-types": "1.0.0-beta.222",
|
|
30
|
+
"@aglyn/shared-ui-theme": "1.0.0-beta.222",
|
|
31
|
+
"@aglyn/tenant-data-admin": "1.0.0-beta.222",
|
|
30
32
|
"@swc/helpers": "0.5.23"
|
|
31
33
|
},
|
|
32
34
|
"peerDependencies": {
|
package/src/index.d.ts
CHANGED
|
@@ -14,8 +14,5 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
export * from './lib/assign-contact-owner';
|
|
18
|
-
export * from './lib/capture-host-contact';
|
|
19
17
|
export * from './lib/emit-host-event';
|
|
20
18
|
export * from './lib/host-event-listeners';
|
|
21
|
-
export * from './lib/resolve-dataset';
|
package/src/index.js
CHANGED
|
@@ -13,10 +13,7 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/ export * from "./lib/
|
|
17
|
-
export * from "./lib/capture-host-contact.js";
|
|
18
|
-
export * from "./lib/emit-host-event.js";
|
|
16
|
+
*/ export * from "./lib/emit-host-event.js";
|
|
19
17
|
export * from "./lib/host-event-listeners.js";
|
|
20
|
-
export * from "./lib/resolve-dataset.js";
|
|
21
18
|
|
|
22
19
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../libs/tenant/runtime/src/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './lib/
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/tenant/runtime/src/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './lib/emit-host-event'\nexport * from './lib/host-event-listeners'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,2BAAuB;AACrC,cAAc,gCAA4B"}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
17
|
-
import { blockingRouteOwner, checkEntitlement, composeScreenRoutePath, SCREEN_KIND_EMAIL, SCREEN_ROOT_PATH } from "@aglyn/aglyn/server";
|
|
17
|
+
import { blockingRouteOwner, checkEntitlement, composeScreenRoutePath, SCREEN_KIND_EMAIL, SCREEN_KIND_GROUP, SCREEN_ROOT_PATH, toScreenRouteNode } from "@aglyn/aglyn/server";
|
|
18
18
|
// Deep import, like the Measurement Protocol sender's: `analytics-events.ts`
|
|
19
19
|
// is deliberately DOM-free so both sides of the publish path can share the
|
|
20
20
|
// one definition of `first_publish` (AGL-1588).
|
|
@@ -35,11 +35,12 @@ import { FieldValue, Timestamp } from "firebase-admin/firestore";
|
|
|
35
35
|
* The three refusals are all "this cannot become an address", and all three
|
|
36
36
|
* are silent no-ops if left unrecorded, which is the bug this issue is about:
|
|
37
37
|
*
|
|
38
|
-
* - `not-a-page` — an email document (AGL-1383)
|
|
39
|
-
* path refuses to render
|
|
40
|
-
* against `screensPerHost` without making it
|
|
41
|
-
* is deliberately NOT refused: a collection
|
|
42
|
-
* purpose, which is how the compose pipeline
|
|
38
|
+
* - `not-a-page` — an email document (AGL-1383) or a page group (AGL-3463).
|
|
39
|
+
* Neither has a URL, the serve path refuses to render either, and a routing
|
|
40
|
+
* entry would make it BILLABLE against `screensPerHost` without making it
|
|
41
|
+
* reachable. `kind: 'template'` is deliberately NOT refused: a collection
|
|
42
|
+
* entry template is routed on purpose, which is how the compose pipeline
|
|
43
|
+
* picks it up (AGL-1400).
|
|
43
44
|
* - `no-path` — the screen or an ancestor has no slug, so there is no address
|
|
44
45
|
* to publish at.
|
|
45
46
|
* - `path-taken` — another screen already holds the address. The interactive
|
|
@@ -57,16 +58,19 @@ import { FieldValue, Timestamp } from "firebase-admin/firestore";
|
|
|
57
58
|
const snapshot = await screens.doc(currentId).get();
|
|
58
59
|
if (!snapshot.exists) break;
|
|
59
60
|
if (currentId === screenId) {
|
|
60
|
-
if (snapshot.get('deletedAt') != null || snapshot.get('kind') === SCREEN_KIND_EMAIL) {
|
|
61
|
+
if (snapshot.get('deletedAt') != null || snapshot.get('kind') === SCREEN_KIND_EMAIL || snapshot.get('kind') === SCREEN_KIND_GROUP) {
|
|
61
62
|
return {
|
|
62
63
|
refused: 'not-a-page'
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
// The kind rides along so a GROUP ancestor composes as nothing rather
|
|
68
|
+
// than as a slugless page that refuses the path (AGL-3463).
|
|
69
|
+
screensById[currentId] = toScreenRouteNode({
|
|
67
70
|
slug: snapshot.get('slug'),
|
|
68
|
-
parentId: snapshot.get('parentId')
|
|
69
|
-
|
|
71
|
+
parentId: snapshot.get('parentId'),
|
|
72
|
+
kind: snapshot.get('kind')
|
|
73
|
+
});
|
|
70
74
|
currentId = snapshot.get('parentId');
|
|
71
75
|
}
|
|
72
76
|
const path = composeScreenRoutePath(screenId, screensById);
|
|
@@ -137,6 +141,11 @@ import { FieldValue, Timestamp } from "firebase-admin/firestore";
|
|
|
137
141
|
// Scheduled unpublish (AGL-113, screens only): drop the routing-map entry
|
|
138
142
|
// so the path 404s on the next revalidate. This render still serves the
|
|
139
143
|
// current version — the map is matched before this runs.
|
|
144
|
+
//
|
|
145
|
+
// THIS screen's entry only (AGL-3463). A scheduled unpublish of a parent
|
|
146
|
+
// leaves every page nested under it serving at its own address, exactly as
|
|
147
|
+
// the console's unpublish does; a page below only goes when it is
|
|
148
|
+
// unpublished itself.
|
|
140
149
|
if (schedule.action === 'unpublish') {
|
|
141
150
|
if (collectionName === 'screens') {
|
|
142
151
|
try {
|
|
@@ -178,6 +187,10 @@ import { FieldValue, Timestamp } from "firebase-admin/firestore";
|
|
|
178
187
|
// Screens only. A layout has no address of its own, exactly as the
|
|
179
188
|
// unpublish branch above is screens-only.
|
|
180
189
|
//
|
|
190
|
+
// Only THIS screen's entry is written, never a descendant's (AGL-3463): a
|
|
191
|
+
// scheduled publish of a parent neither puts the drafts beneath it live
|
|
192
|
+
// nor moves a page below that kept its own address.
|
|
193
|
+
//
|
|
181
194
|
// In practice the CRON BEAT is the only caller that reaches a first publish:
|
|
182
195
|
// the lazy ISR path resolves a request path through the routing map before
|
|
183
196
|
// it ever loads a screen, so an unrouted screen 404s without its schedule
|
|
@@ -194,19 +207,28 @@ import { FieldValue, Timestamp } from "firebase-admin/firestore";
|
|
|
194
207
|
// The placeholder home page this publish takes `/` from, if it does
|
|
195
208
|
// (AGL-3408) — its entry leaves the map in the same commit.
|
|
196
209
|
let releasedPlaceholder;
|
|
210
|
+
// This IS the placeholder home page, published by its owner (AGL-3478): a
|
|
211
|
+
// schedule is somebody's deliberate act, and the platform never writes one.
|
|
212
|
+
// From here it is their home page, so the marker goes in the same commit —
|
|
213
|
+
// a starter must not unpublish it — and the publish is an activation.
|
|
214
|
+
let publishesPlaceholder = false;
|
|
197
215
|
if (collectionName === 'screens') {
|
|
198
216
|
try {
|
|
199
217
|
var _host_get;
|
|
200
218
|
const host = await hostRef.get();
|
|
201
219
|
const routing = (_host_get = host.get('screens')) != null ? _host_get : {};
|
|
220
|
+
const defaultHomeScreenId = host.get('defaultHomeScreenId');
|
|
221
|
+
publishesPlaceholder = Boolean(defaultHomeScreenId) && defaultHomeScreenId === docId;
|
|
202
222
|
// An existing entry is the republish case: the route is already live,
|
|
203
223
|
// this only swaps which version it serves, and there is nothing to
|
|
204
|
-
// register and no activation to report
|
|
205
|
-
|
|
224
|
+
// register and no activation to report — except on the placeholder,
|
|
225
|
+
// whose live route the platform registered rather than its owner.
|
|
226
|
+
if (!routing[docId] || publishesPlaceholder) {
|
|
206
227
|
// The same predicate the console's three publish surfaces use, so a
|
|
207
228
|
// `first_publish` breakdown means one thing across all four senders.
|
|
208
|
-
firstPublish = isFirstPublishedRoute(routing,
|
|
209
|
-
|
|
229
|
+
firstPublish = isFirstPublishedRoute(routing, defaultHomeScreenId);
|
|
230
|
+
}
|
|
231
|
+
if (!routing[docId]) {
|
|
210
232
|
const resolved = await resolveScheduledRoutePath({
|
|
211
233
|
hostRef,
|
|
212
234
|
screenId: docId,
|
|
@@ -247,18 +269,20 @@ import { FieldValue, Timestamp } from "firebase-admin/firestore";
|
|
|
247
269
|
versionId: schedule.versionId,
|
|
248
270
|
'publishSchedule.status': 'applied'
|
|
249
271
|
};
|
|
250
|
-
if (routePath) {
|
|
272
|
+
if (routePath || publishesPlaceholder) {
|
|
251
273
|
// ONE atomic commit, and the order matters more than the write count:
|
|
252
274
|
// a status of `applied` with no routing entry is permanent (nothing
|
|
253
275
|
// retries a terminal status), so the entry and the status must land
|
|
254
276
|
// together or not at all. A failed commit leaves the schedule pending
|
|
255
277
|
// and the next beat runs it again.
|
|
256
278
|
const batch = firestore.batch();
|
|
257
|
-
batch.update(hostRef, _extends({
|
|
279
|
+
batch.update(hostRef, _extends({}, routePath ? {
|
|
258
280
|
[`screens.${docId}`]: routePath
|
|
259
|
-
}, releasedPlaceholder ? {
|
|
281
|
+
} : {}, releasedPlaceholder ? {
|
|
260
282
|
[`screens.${releasedPlaceholder}`]: FieldValue.delete(),
|
|
261
283
|
defaultHomeScreenId: FieldValue.delete()
|
|
284
|
+
} : {}, publishesPlaceholder ? {
|
|
285
|
+
defaultHomeScreenId: FieldValue.delete()
|
|
262
286
|
} : {}));
|
|
263
287
|
if (releasedPlaceholder) {
|
|
264
288
|
batch.set(hostRef.collection('screens').doc(releasedPlaceholder), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/tenant/runtime/src/lib/apply-publish-schedule.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as Aglyn from '@aglyn/aglyn/server'\nimport {\n blockingRouteOwner,\n checkEntitlement,\n composeScreenRoutePath,\n SCREEN_KIND_EMAIL,\n SCREEN_ROOT_PATH,\n} from '@aglyn/aglyn/server'\n// Deep import, like the Measurement Protocol sender's: `analytics-events.ts`\n// is deliberately DOM-free so both sides of the publish path can share the\n// one definition of `first_publish` (AGL-1588).\nimport { isFirstPublishedRoute } from '@aglyn/aglyn/app-utils/analytics-events'\nimport {\n firebaseAdmin,\n getOrgForHost,\n sendGa4SitePublished,\n} from '@aglyn/tenant-data-admin'\nimport { FieldValue, Timestamp } from 'firebase-admin/firestore'\n\n/** Parent chains deeper than `composeScreenRoutePath` accepts are invalid. */\nconst MAX_ANCESTOR_READS = 32\n\n/**\n * Why a due publish declined to make the screen reachable. Recorded on the\n * schedule as `skipped-unroutable` — see {@link resolveScheduledRoutePath}.\n */\ntype RouteRefusal = 'not-a-page' | 'no-path' | 'path-taken'\n\n/**\n * The routing-map path a due publish should register for a screen that has\n * no entry yet, or the reason it must not get one (AGL-1589).\n *\n * Reads the screen and walks its ancestor chain (one doc per level, bounded)\n * because the composed path is `parent segments + own slug` and the executor\n * is handed only the version pointer and the schedule. Runs at most once per\n * schedule that actually comes due, and never for the common case — a screen\n * whose route is already live is answered from the host document alone.\n *\n * The three refusals are all \"this cannot become an address\", and all three\n * are silent no-ops if left unrecorded, which is the bug this issue is about:\n *\n * - `not-a-page` — an email document (AGL-1383). It has no URL, the serve\n * path refuses to render it, and a routing entry would make it BILLABLE\n * against `screensPerHost` without making it reachable. `kind: 'template'`\n * is deliberately NOT refused: a collection entry template is routed on\n * purpose, which is how the compose pipeline picks it up (AGL-1400).\n * - `no-path` — the screen or an ancestor has no slug, so there is no address\n * to publish at.\n * - `path-taken` — another screen already holds the address. The interactive\n * path refuses this with a message (\"Another screen is already published at\n * …\"); registering it anyway would put two screens at one path and could\n * take a LIVE page off the site, which is a worse bug than the one being\n * fixed here.\n */\nasync function resolveScheduledRoutePath(options: {\n hostRef: FirebaseFirestore.DocumentReference\n screenId: string\n routing: Record<string, string>\n /** The placeholder home page, which does not block `/` (AGL-3408). */\n defaultHomeScreenId?: string\n}): Promise<{ path: string } | { refused: RouteRefusal }> {\n const { hostRef, screenId, routing, defaultHomeScreenId } = options\n const screens = hostRef.collection('screens')\n const screensById: Record<string, Aglyn.ScreenRouteNode | undefined> = {}\n\n let currentId: string | undefined = screenId\n for (let depth = 0; currentId && depth < MAX_ANCESTOR_READS; depth += 1) {\n if (screensById[currentId]) break // cycle — composeScreenRoutePath refuses\n const snapshot = await screens.doc(currentId).get()\n if (!snapshot.exists) break\n if (currentId === screenId) {\n if (\n snapshot.get('deletedAt') != null ||\n snapshot.get('kind') === SCREEN_KIND_EMAIL\n ) {\n return { refused: 'not-a-page' }\n }\n }\n screensById[currentId] = {\n slug: snapshot.get('slug'),\n parentId: snapshot.get('parentId'),\n }\n currentId = snapshot.get('parentId')\n }\n\n const path = composeScreenRoutePath(screenId, screensById)\n if (!path) return { refused: 'no-path' }\n const owner = blockingRouteOwner(routing, path, defaultHomeScreenId)\n if (owner && owner !== screenId) return { refused: 'path-taken' }\n return { path }\n}\n\n/**\n * Lazy scheduled-publishing executor (AGL-61): if the doc carries a pending\n * `publishSchedule` whose time has passed, flip the `versionId` pointer,\n * register the screen's routing entry when the route is not live yet\n * (AGL-1589), and mark the schedule applied. Runs during ISR revalidation,\n * so a schedule\n * takes effect on the first regeneration after its time (within the\n * revalidate window) — no dedicated cron needed. Returns the effective\n * versionId; fail-open on write errors (the pointer flips next revalidate).\n */\nexport async function applyDuePublishSchedule(options: {\n hostId: Aglyn.HostUid\n collectionName: 'screens' | 'layouts'\n docId: string\n parent: Pick<Aglyn.AglynScreen, 'versionId' | 'publishSchedule'>\n}): Promise<Aglyn.VersionUid | undefined> {\n const { hostId, collectionName, docId, parent } = options\n const schedule = parent.publishSchedule\n const publishAtMs = (schedule?.publishAt?.seconds ?? 0) * 1000\n if (schedule?.status !== 'pending' || publishAtMs > Date.now()) {\n return parent.versionId\n }\n\n // Plan gate (AGL-471): the console gates *writing* a schedule on the\n // scheduledPublishing entitlement, but this executor is the authority —\n // a schedule written directly to Firestore must not auto-publish on an\n // unentitled plan.\n const org = (await getOrgForHost(hostId))?.org ?? {}\n if (!checkEntitlement(org, 'scheduledPublishing')) {\n // Record the refusal instead of leaving it pending (AGL-1185).\n //\n // The refusal itself is correct and unchanged. What was wrong is that it\n // left no trace: the schedule stayed `pending` and permanently due, so the\n // moment the org upgraded to Business the next beat — every minute since\n // AGL-1159 — published it. Content scheduled on a plan that could not\n // honour it, and forgotten, would surface during an upgrade, which is\n // exactly when nobody is looking for it.\n //\n // Safe to write here because the dueness check above has already passed, so\n // this can only ever mark a schedule that came due and was declined. A\n // future-dated schedule is returned long before this point and is untouched.\n //\n // Terminal on purpose: upgrading does not resurrect it. A schedule whose\n // time passed while unentitled is stale by the time the plan changes, and\n // re-running it is the surprise this removes. Rescheduling is a deliberate\n // act, and the console can now say why the original never ran.\n //\n // Fail-open like every other write here — a failure leaves it pending,\n // which is today's behaviour, and the next beat retries.\n try {\n await firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(hostId)\n .collection(collectionName)\n .doc(docId)\n .update({ 'publishSchedule.status': 'skipped-unentitled' })\n } catch (error) {\n console.error(error)\n }\n return parent.versionId\n }\n\n // Scheduled unpublish (AGL-113, screens only): drop the routing-map entry\n // so the path 404s on the next revalidate. This render still serves the\n // current version — the map is matched before this runs.\n if (schedule.action === 'unpublish') {\n if (collectionName === 'screens') {\n try {\n const firestore = firebaseAdmin.app().firestore()\n const hostRef = firestore.collection('hosts').doc(hostId)\n await Promise.all([\n hostRef.update({\n [`screens.${docId}`]: FieldValue.delete(),\n }),\n hostRef.collection(collectionName).doc(docId).update({\n 'publishSchedule.status': 'applied',\n // Route no longer live — drop the published date to match the\n // interactive unpublish path (constants/screen-publishing.ts).\n publishedAt: FieldValue.delete(),\n }),\n ])\n } catch (error) {\n console.error(error)\n }\n }\n return parent.versionId\n }\n\n if (!schedule.versionId) return parent.versionId\n\n // Register the routing entry, not just the version pointer (AGL-1589).\n //\n // Until this, a due publish wrote `versionId` + `status: 'applied'` and\n // nothing else — never `hosts/{hostId}.screens.{screenId}`, the map the\n // tenant matches request paths against. A REPUBLISH was therefore correct\n // (the entry already existed, and only the version needed swapping) and a\n // FIRST publish silently was not: the schedule reported success, the\n // activity log said published, and the URL kept 404ing. Scheduled\n // publishing is a Business feature, so that was a paying customer's page.\n //\n // Mirrors `publishScreenRoute` (constants/screen-publishing.ts): the\n // composed path into the host's map, `publishedAt` stamped on the screen.\n // The stored `slug` is not rewritten — the path was composed FROM it, so\n // there is nothing to change.\n //\n // Screens only. A layout has no address of its own, exactly as the\n // unpublish branch above is screens-only.\n //\n // In practice the CRON BEAT is the only caller that reaches a first publish:\n // the lazy ISR path resolves a request path through the routing map before\n // it ever loads a screen, so an unrouted screen 404s without its schedule\n // being read. That is the same map this now writes — which is why the bug\n // could not heal itself on the next visit.\n const firestore = firebaseAdmin.app().firestore()\n const hostRef = firestore.collection('hosts').doc(hostId)\n const docRef = hostRef.collection(collectionName).doc(docId)\n\n let routePath: string | undefined\n // Decided from the routing map as read below — BEFORE the batch registers\n // this entry (AGL-1588). Left undefined outside the screens branch, where\n // no route is going live and no `site_published` is sent at all.\n let firstPublish: boolean | undefined\n // The placeholder home page this publish takes `/` from, if it does\n // (AGL-3408) — its entry leaves the map in the same commit.\n let releasedPlaceholder: string | undefined\n if (collectionName === 'screens') {\n try {\n const host = await hostRef.get()\n const routing = (host.get('screens') ?? {}) as Record<string, string>\n // An existing entry is the republish case: the route is already live,\n // this only swaps which version it serves, and there is nothing to\n // register and no activation to report.\n if (!routing[docId]) {\n // The same predicate the console's three publish surfaces use, so a\n // `first_publish` breakdown means one thing across all four senders.\n firstPublish = isFirstPublishedRoute(\n routing,\n host.get('defaultHomeScreenId'),\n )\n const defaultHomeScreenId = host.get('defaultHomeScreenId')\n const resolved = await resolveScheduledRoutePath({\n hostRef,\n screenId: docId,\n routing,\n defaultHomeScreenId,\n })\n if ('refused' in resolved) {\n // Record the refusal rather than publishing a pointer at a page\n // nobody can reach — the AGL-1185 posture, for the same reason: an\n // unrecorded decline is indistinguishable from success, and leaving\n // it `pending` would re-attempt it on every beat forever. Terminal:\n // fixing the address is a deliberate act in the console, and\n // rescheduling is part of it.\n try {\n await docRef.update({\n 'publishSchedule.status': 'skipped-unroutable',\n })\n } catch (error) {\n console.error(error)\n }\n return parent.versionId\n }\n routePath = resolved.path\n if (\n routePath === SCREEN_ROOT_PATH &&\n defaultHomeScreenId &&\n defaultHomeScreenId !== docId &&\n routing[defaultHomeScreenId] === SCREEN_ROOT_PATH\n ) {\n releasedPlaceholder = defaultHomeScreenId\n }\n }\n } catch (error) {\n // Fail-open like every other write here: leave the schedule pending and\n // let the next beat (or revalidate) retry. Publishing the pointer while\n // the routing question is unanswered is the failure being fixed.\n console.error(error)\n return parent.versionId\n }\n }\n\n try {\n const applied = {\n versionId: schedule.versionId,\n 'publishSchedule.status': 'applied',\n }\n if (routePath) {\n // ONE atomic commit, and the order matters more than the write count:\n // a status of `applied` with no routing entry is permanent (nothing\n // retries a terminal status), so the entry and the status must land\n // together or not at all. A failed commit leaves the schedule pending\n // and the next beat runs it again.\n const batch = firestore.batch()\n batch.update(hostRef, {\n [`screens.${docId}`]: routePath,\n // The first real home page replaces the placeholder (AGL-3408), in\n // the same commit, so `/` is never answered by two screens.\n ...(releasedPlaceholder\n ? {\n [`screens.${releasedPlaceholder}`]: FieldValue.delete(),\n defaultHomeScreenId: FieldValue.delete(),\n }\n : {}),\n })\n if (releasedPlaceholder) {\n batch.set(\n hostRef.collection('screens').doc(releasedPlaceholder),\n { publishedAt: FieldValue.delete() },\n { merge: true },\n )\n }\n batch.update(docRef, { ...applied, publishedAt: Timestamp.now() })\n await batch.commit()\n\n // A route just went live with no browser anywhere near it, which is\n // precisely what the client-side `site_published` in\n // `publishScreenRoute` cannot see (AGL-1562, AGL-1589). Awaited, not\n // floated: this render/beat is the only thing keeping the process\n // alive. It never throws, and it returns immediately when the\n // Measurement Protocol is not configured — the normal state on a\n // self-hosted deployment and in development.\n //\n // ⚠️ NOT the state of our own tenant app any more. This comment used to\n // say GA4_MEASUREMENT_ID / GA4_API_SECRET were unset on the\n // aglyn-tenant Vercel project; both landed on 2026-08-17 12:15 UTC and\n // the sender is LIVE on this path. The stale version of this note is\n // part of what made a 2026-08-19 smoke pass conclude every server-side\n // event was dead (AGL-2327). See docs/ANALYTICS.md.\n await sendGa4SitePublished({ hostId, firstPublish })\n } else {\n await docRef.update(applied)\n }\n } catch (error) {\n console.error(error)\n }\n // Serve the scheduled version for this render either way — the schedule\n // is due, and the write (or its retry next revalidate) makes it durable.\n return schedule.versionId\n}\n\nexport default applyDuePublishSchedule\n"],"names":["blockingRouteOwner","checkEntitlement","composeScreenRoutePath","SCREEN_KIND_EMAIL","SCREEN_ROOT_PATH","isFirstPublishedRoute","firebaseAdmin","getOrgForHost","sendGa4SitePublished","FieldValue","Timestamp","MAX_ANCESTOR_READS","resolveScheduledRoutePath","options","hostRef","screenId","routing","defaultHomeScreenId","screens","collection","screensById","currentId","depth","snapshot","doc","get","exists","refused","slug","parentId","path","owner","applyDuePublishSchedule","schedule","hostId","collectionName","docId","parent","publishSchedule","publishAtMs","publishAt","seconds","status","Date","now","versionId","org","app","firestore","update","error","console","action","Promise","all","delete","publishedAt","docRef","routePath","firstPublish","releasedPlaceholder","host","resolved","applied","batch","set","merge","commit"],"mappings":"AAAA;;;;;;;;;;;;;;;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AAoE;YACpE,sEAAsE;YACtE,mCAAmC;YACnC,MAAMM,QAAQhB,UAAUgB,KAAK;YAC7BA,MAAMf,MAAM,CAACnC,SAAS;gBACpB,CAAC,CAAC,QAAQ,EAAEsB,OAAO,CAAC,EAAEsB;eAGlBE,sBACA;gBACE,CAAC,CAAC,QAAQ,EAAEA,qBAAqB,CAAC,EAAEnD,WAAW8C,MAAM;gBACrDtC,qBAAqBR,WAAW8C,MAAM;YACxC,IACA,CAAC;YAEP,IAAIK,qBAAqB;gBACvBI,MAAMC,GAAG,CACPnD,QAAQK,UAAU,CAAC,WAAWK,GAAG,CAACoC,sBAClC;oBAAEJ,aAAa/C,WAAW8C,MAAM;gBAAG,GACnC;oBAAEW,OAAO;gBAAK;YAElB;YACAF,MAAMf,MAAM,CAACQ,QAAQ,aAAKM;gBAASP,aAAa9C,UAAUkC,GAAG;;YAC7D,MAAMoB,MAAMG,MAAM;YAElB,oEAAoE;YACpE,qDAAqD;YACrD,qEAAqE;YACrE,kEAAkE;YAClE,8DAA8D;YAC9D,iEAAiE;YACjE,6CAA6C;YAC7C,EAAE;YACF,wEAAwE;YACxE,4DAA4D;YAC5D,uEAAuE;YACvE,qEAAqE;YACrE,uEAAuE;YACvE,oDAAoD;YACpD,MAAM3D,qBAAqB;gBAAE0B;gBAAQyB;YAAa;QACpD,OAAO;YACL,MAAMF,OAAOR,MAAM,CAACc;QACtB;IACF,EAAE,OAAOb,OAAO;QACdC,QAAQD,KAAK,CAACA;IAChB;IACA,wEAAwE;IACxE,yEAAyE;IACzE,OAAOjB,SAASY,SAAS;AAC3B;AAEA,eAAeb,wBAAuB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/tenant/runtime/src/lib/apply-publish-schedule.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as Aglyn from '@aglyn/aglyn/server'\nimport {\n blockingRouteOwner,\n checkEntitlement,\n composeScreenRoutePath,\n SCREEN_KIND_EMAIL,\n SCREEN_KIND_GROUP,\n SCREEN_ROOT_PATH,\n toScreenRouteNode,\n} from '@aglyn/aglyn/server'\n// Deep import, like the Measurement Protocol sender's: `analytics-events.ts`\n// is deliberately DOM-free so both sides of the publish path can share the\n// one definition of `first_publish` (AGL-1588).\nimport { isFirstPublishedRoute } from '@aglyn/aglyn/app-utils/analytics-events'\nimport {\n firebaseAdmin,\n getOrgForHost,\n sendGa4SitePublished,\n} from '@aglyn/tenant-data-admin'\nimport { FieldValue, Timestamp } from 'firebase-admin/firestore'\n\n/** Parent chains deeper than `composeScreenRoutePath` accepts are invalid. */\nconst MAX_ANCESTOR_READS = 32\n\n/**\n * Why a due publish declined to make the screen reachable. Recorded on the\n * schedule as `skipped-unroutable` — see {@link resolveScheduledRoutePath}.\n */\ntype RouteRefusal = 'not-a-page' | 'no-path' | 'path-taken'\n\n/**\n * The routing-map path a due publish should register for a screen that has\n * no entry yet, or the reason it must not get one (AGL-1589).\n *\n * Reads the screen and walks its ancestor chain (one doc per level, bounded)\n * because the composed path is `parent segments + own slug` and the executor\n * is handed only the version pointer and the schedule. Runs at most once per\n * schedule that actually comes due, and never for the common case — a screen\n * whose route is already live is answered from the host document alone.\n *\n * The three refusals are all \"this cannot become an address\", and all three\n * are silent no-ops if left unrecorded, which is the bug this issue is about:\n *\n * - `not-a-page` — an email document (AGL-1383) or a page group (AGL-3463).\n * Neither has a URL, the serve path refuses to render either, and a routing\n * entry would make it BILLABLE against `screensPerHost` without making it\n * reachable. `kind: 'template'` is deliberately NOT refused: a collection\n * entry template is routed on purpose, which is how the compose pipeline\n * picks it up (AGL-1400).\n * - `no-path` — the screen or an ancestor has no slug, so there is no address\n * to publish at.\n * - `path-taken` — another screen already holds the address. The interactive\n * path refuses this with a message (\"Another screen is already published at\n * …\"); registering it anyway would put two screens at one path and could\n * take a LIVE page off the site, which is a worse bug than the one being\n * fixed here.\n */\nasync function resolveScheduledRoutePath(options: {\n hostRef: FirebaseFirestore.DocumentReference\n screenId: string\n routing: Record<string, string>\n /** The placeholder home page, which does not block `/` (AGL-3408). */\n defaultHomeScreenId?: string\n}): Promise<{ path: string } | { refused: RouteRefusal }> {\n const { hostRef, screenId, routing, defaultHomeScreenId } = options\n const screens = hostRef.collection('screens')\n const screensById: Record<string, Aglyn.ScreenRouteNode | undefined> = {}\n\n let currentId: string | undefined = screenId\n for (let depth = 0; currentId && depth < MAX_ANCESTOR_READS; depth += 1) {\n if (screensById[currentId]) break // cycle — composeScreenRoutePath refuses\n const snapshot = await screens.doc(currentId).get()\n if (!snapshot.exists) break\n if (currentId === screenId) {\n if (\n snapshot.get('deletedAt') != null ||\n snapshot.get('kind') === SCREEN_KIND_EMAIL ||\n snapshot.get('kind') === SCREEN_KIND_GROUP\n ) {\n return { refused: 'not-a-page' }\n }\n }\n // The kind rides along so a GROUP ancestor composes as nothing rather\n // than as a slugless page that refuses the path (AGL-3463).\n screensById[currentId] = toScreenRouteNode({\n slug: snapshot.get('slug'),\n parentId: snapshot.get('parentId'),\n kind: snapshot.get('kind'),\n })\n currentId = snapshot.get('parentId')\n }\n\n const path = composeScreenRoutePath(screenId, screensById)\n if (!path) return { refused: 'no-path' }\n const owner = blockingRouteOwner(routing, path, defaultHomeScreenId)\n if (owner && owner !== screenId) return { refused: 'path-taken' }\n return { path }\n}\n\n/**\n * Lazy scheduled-publishing executor (AGL-61): if the doc carries a pending\n * `publishSchedule` whose time has passed, flip the `versionId` pointer,\n * register the screen's routing entry when the route is not live yet\n * (AGL-1589), and mark the schedule applied. Runs during ISR revalidation,\n * so a schedule\n * takes effect on the first regeneration after its time (within the\n * revalidate window) — no dedicated cron needed. Returns the effective\n * versionId; fail-open on write errors (the pointer flips next revalidate).\n */\nexport async function applyDuePublishSchedule(options: {\n hostId: Aglyn.HostUid\n collectionName: 'screens' | 'layouts'\n docId: string\n parent: Pick<Aglyn.AglynScreen, 'versionId' | 'publishSchedule'>\n}): Promise<Aglyn.VersionUid | undefined> {\n const { hostId, collectionName, docId, parent } = options\n const schedule = parent.publishSchedule\n const publishAtMs = (schedule?.publishAt?.seconds ?? 0) * 1000\n if (schedule?.status !== 'pending' || publishAtMs > Date.now()) {\n return parent.versionId\n }\n\n // Plan gate (AGL-471): the console gates *writing* a schedule on the\n // scheduledPublishing entitlement, but this executor is the authority —\n // a schedule written directly to Firestore must not auto-publish on an\n // unentitled plan.\n const org = (await getOrgForHost(hostId))?.org ?? {}\n if (!checkEntitlement(org, 'scheduledPublishing')) {\n // Record the refusal instead of leaving it pending (AGL-1185).\n //\n // The refusal itself is correct and unchanged. What was wrong is that it\n // left no trace: the schedule stayed `pending` and permanently due, so the\n // moment the org upgraded to Business the next beat — every minute since\n // AGL-1159 — published it. Content scheduled on a plan that could not\n // honour it, and forgotten, would surface during an upgrade, which is\n // exactly when nobody is looking for it.\n //\n // Safe to write here because the dueness check above has already passed, so\n // this can only ever mark a schedule that came due and was declined. A\n // future-dated schedule is returned long before this point and is untouched.\n //\n // Terminal on purpose: upgrading does not resurrect it. A schedule whose\n // time passed while unentitled is stale by the time the plan changes, and\n // re-running it is the surprise this removes. Rescheduling is a deliberate\n // act, and the console can now say why the original never ran.\n //\n // Fail-open like every other write here — a failure leaves it pending,\n // which is today's behaviour, and the next beat retries.\n try {\n await firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(hostId)\n .collection(collectionName)\n .doc(docId)\n .update({ 'publishSchedule.status': 'skipped-unentitled' })\n } catch (error) {\n console.error(error)\n }\n return parent.versionId\n }\n\n // Scheduled unpublish (AGL-113, screens only): drop the routing-map entry\n // so the path 404s on the next revalidate. This render still serves the\n // current version — the map is matched before this runs.\n //\n // THIS screen's entry only (AGL-3463). A scheduled unpublish of a parent\n // leaves every page nested under it serving at its own address, exactly as\n // the console's unpublish does; a page below only goes when it is\n // unpublished itself.\n if (schedule.action === 'unpublish') {\n if (collectionName === 'screens') {\n try {\n const firestore = firebaseAdmin.app().firestore()\n const hostRef = firestore.collection('hosts').doc(hostId)\n await Promise.all([\n hostRef.update({\n [`screens.${docId}`]: FieldValue.delete(),\n }),\n hostRef.collection(collectionName).doc(docId).update({\n 'publishSchedule.status': 'applied',\n // Route no longer live — drop the published date to match the\n // interactive unpublish path (constants/screen-publishing.ts).\n publishedAt: FieldValue.delete(),\n }),\n ])\n } catch (error) {\n console.error(error)\n }\n }\n return parent.versionId\n }\n\n if (!schedule.versionId) return parent.versionId\n\n // Register the routing entry, not just the version pointer (AGL-1589).\n //\n // Until this, a due publish wrote `versionId` + `status: 'applied'` and\n // nothing else — never `hosts/{hostId}.screens.{screenId}`, the map the\n // tenant matches request paths against. A REPUBLISH was therefore correct\n // (the entry already existed, and only the version needed swapping) and a\n // FIRST publish silently was not: the schedule reported success, the\n // activity log said published, and the URL kept 404ing. Scheduled\n // publishing is a Business feature, so that was a paying customer's page.\n //\n // Mirrors `publishScreenRoute` (constants/screen-publishing.ts): the\n // composed path into the host's map, `publishedAt` stamped on the screen.\n // The stored `slug` is not rewritten — the path was composed FROM it, so\n // there is nothing to change.\n //\n // Screens only. A layout has no address of its own, exactly as the\n // unpublish branch above is screens-only.\n //\n // Only THIS screen's entry is written, never a descendant's (AGL-3463): a\n // scheduled publish of a parent neither puts the drafts beneath it live\n // nor moves a page below that kept its own address.\n //\n // In practice the CRON BEAT is the only caller that reaches a first publish:\n // the lazy ISR path resolves a request path through the routing map before\n // it ever loads a screen, so an unrouted screen 404s without its schedule\n // being read. That is the same map this now writes — which is why the bug\n // could not heal itself on the next visit.\n const firestore = firebaseAdmin.app().firestore()\n const hostRef = firestore.collection('hosts').doc(hostId)\n const docRef = hostRef.collection(collectionName).doc(docId)\n\n let routePath: string | undefined\n // Decided from the routing map as read below — BEFORE the batch registers\n // this entry (AGL-1588). Left undefined outside the screens branch, where\n // no route is going live and no `site_published` is sent at all.\n let firstPublish: boolean | undefined\n // The placeholder home page this publish takes `/` from, if it does\n // (AGL-3408) — its entry leaves the map in the same commit.\n let releasedPlaceholder: string | undefined\n // This IS the placeholder home page, published by its owner (AGL-3478): a\n // schedule is somebody's deliberate act, and the platform never writes one.\n // From here it is their home page, so the marker goes in the same commit —\n // a starter must not unpublish it — and the publish is an activation.\n let publishesPlaceholder = false\n if (collectionName === 'screens') {\n try {\n const host = await hostRef.get()\n const routing = (host.get('screens') ?? {}) as Record<string, string>\n const defaultHomeScreenId = host.get('defaultHomeScreenId')\n publishesPlaceholder =\n Boolean(defaultHomeScreenId) && defaultHomeScreenId === docId\n // An existing entry is the republish case: the route is already live,\n // this only swaps which version it serves, and there is nothing to\n // register and no activation to report — except on the placeholder,\n // whose live route the platform registered rather than its owner.\n if (!routing[docId] || publishesPlaceholder) {\n // The same predicate the console's three publish surfaces use, so a\n // `first_publish` breakdown means one thing across all four senders.\n firstPublish = isFirstPublishedRoute(routing, defaultHomeScreenId)\n }\n if (!routing[docId]) {\n const resolved = await resolveScheduledRoutePath({\n hostRef,\n screenId: docId,\n routing,\n defaultHomeScreenId,\n })\n if ('refused' in resolved) {\n // Record the refusal rather than publishing a pointer at a page\n // nobody can reach — the AGL-1185 posture, for the same reason: an\n // unrecorded decline is indistinguishable from success, and leaving\n // it `pending` would re-attempt it on every beat forever. Terminal:\n // fixing the address is a deliberate act in the console, and\n // rescheduling is part of it.\n try {\n await docRef.update({\n 'publishSchedule.status': 'skipped-unroutable',\n })\n } catch (error) {\n console.error(error)\n }\n return parent.versionId\n }\n routePath = resolved.path\n if (\n routePath === SCREEN_ROOT_PATH &&\n defaultHomeScreenId &&\n defaultHomeScreenId !== docId &&\n routing[defaultHomeScreenId] === SCREEN_ROOT_PATH\n ) {\n releasedPlaceholder = defaultHomeScreenId\n }\n }\n } catch (error) {\n // Fail-open like every other write here: leave the schedule pending and\n // let the next beat (or revalidate) retry. Publishing the pointer while\n // the routing question is unanswered is the failure being fixed.\n console.error(error)\n return parent.versionId\n }\n }\n\n try {\n const applied = {\n versionId: schedule.versionId,\n 'publishSchedule.status': 'applied',\n }\n if (routePath || publishesPlaceholder) {\n // ONE atomic commit, and the order matters more than the write count:\n // a status of `applied` with no routing entry is permanent (nothing\n // retries a terminal status), so the entry and the status must land\n // together or not at all. A failed commit leaves the schedule pending\n // and the next beat runs it again.\n const batch = firestore.batch()\n batch.update(hostRef, {\n ...(routePath ? { [`screens.${docId}`]: routePath } : {}),\n // The first real home page replaces the placeholder (AGL-3408), in\n // the same commit, so `/` is never answered by two screens.\n ...(releasedPlaceholder\n ? {\n [`screens.${releasedPlaceholder}`]: FieldValue.delete(),\n defaultHomeScreenId: FieldValue.delete(),\n }\n : {}),\n ...(publishesPlaceholder\n ? { defaultHomeScreenId: FieldValue.delete() }\n : {}),\n })\n if (releasedPlaceholder) {\n batch.set(\n hostRef.collection('screens').doc(releasedPlaceholder),\n { publishedAt: FieldValue.delete() },\n { merge: true },\n )\n }\n batch.update(docRef, { ...applied, publishedAt: Timestamp.now() })\n await batch.commit()\n\n // A route just went live with no browser anywhere near it, which is\n // precisely what the client-side `site_published` in\n // `publishScreenRoute` cannot see (AGL-1562, AGL-1589). Awaited, not\n // floated: this render/beat is the only thing keeping the process\n // alive. It never throws, and it returns immediately when the\n // Measurement Protocol is not configured — the normal state on a\n // self-hosted deployment and in development.\n //\n // ⚠️ NOT the state of our own tenant app any more. This comment used to\n // say GA4_MEASUREMENT_ID / GA4_API_SECRET were unset on the\n // aglyn-tenant Vercel project; both landed on 2026-08-17 12:15 UTC and\n // the sender is LIVE on this path. The stale version of this note is\n // part of what made a 2026-08-19 smoke pass conclude every server-side\n // event was dead (AGL-2327). See docs/ANALYTICS.md.\n await sendGa4SitePublished({ hostId, firstPublish })\n } else {\n await docRef.update(applied)\n }\n } catch (error) {\n console.error(error)\n }\n // Serve the scheduled version for this render either way — the schedule\n // is due, and the write (or its retry next revalidate) makes it durable.\n return schedule.versionId\n}\n\nexport default applyDuePublishSchedule\n"],"names":["blockingRouteOwner","checkEntitlement","composeScreenRoutePath","SCREEN_KIND_EMAIL","SCREEN_KIND_GROUP","SCREEN_ROOT_PATH","toScreenRouteNode","isFirstPublishedRoute","firebaseAdmin","getOrgForHost","sendGa4SitePublished","FieldValue","Timestamp","MAX_ANCESTOR_READS","resolveScheduledRoutePath","options","hostRef","screenId","routing","defaultHomeScreenId","screens","collection","screensById","currentId","depth","snapshot","doc","get","exists","refused","slug","parentId","kind","path","owner","applyDuePublishSchedule","schedule","hostId","collectionName","docId","parent","publishSchedule","publishAtMs","publishAt","seconds","status","Date","now","versionId","org","app","firestore","update","error","console","action","Promise","all","delete","publishedAt","docRef","routePath","firstPublish","releasedPlaceholder","publishesPlaceholder","host","Boolean","resolved","applied","batch","set","merge","commit"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SACEA,kBAAkB,EAClBC,gBAAgB,EAChBC,sBAAsB,EACtBC,iBAAiB,EACjBC,iBAAiB,EACjBC,gBAAgB,EAChBC,iBAAiB,QACZ,sBAAqB;AAC5B,6EAA6E;AAC7E,2EAA2E;AAC3E,gDAAgD;AAChD,SAASC,qBAAqB,QAAQ,0CAAyC;AAC/E,SACEC,aAAa,EACbC,aAAa,EACbC,oBAAoB,QACf,2BAA0B;AACjC,SAASC,UAAU,EAAEC,SAAS,QAAQ,2BAA0B;AAEhE,4EAA4E,GAC5E,MAAMC,qBAAqB;AAQ3B;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,eAAeC,0BAA0BC,OAMxC;IACC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,mBAAmB,EAAE,GAAGJ;IAC5D,MAAMK,UAAUJ,QAAQK,UAAU,CAAC;IACnC,MAAMC,cAAiE,CAAC;IAExE,IAAIC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CAAC,CAAC,QAAQ,EAAEtB,OAAO,CAAC,EAAEsB;YAAU,IAAI,CAAC,GAGnDE,sBACA;gBACE,CAAC,CAAC,QAAQ,EAAEA,qBAAqB,CAAC,EAAEpD,WAAW+C,MAAM;gBACrDvC,qBAAqBR,WAAW+C,MAAM;YACxC,IACA,CAAC,GACDM,uBACA;gBAAE7C,qBAAqBR,WAAW+C,MAAM;YAAG,IAC3C,CAAC;YAEP,IAAIK,qBAAqB;gBACvBM,MAAMC,GAAG,CACPtD,QAAQK,UAAU,CAAC,WAAWK,GAAG,CAACqC,sBAClC;oBAAEJ,aAAahD,WAAW+C,MAAM;gBAAG,GACnC;oBAAEa,OAAO;gBAAK;YAElB;YACAF,MAAMjB,MAAM,CAACQ,QAAQ,aAAKQ;gBAAST,aAAa/C,UAAUmC,GAAG;;YAC7D,MAAMsB,MAAMG,MAAM;YAElB,oEAAoE;YACpE,qDAAqD;YACrD,qEAAqE;YACrE,kEAAkE;YAClE,8DAA8D;YAC9D,iEAAiE;YACjE,6CAA6C;YAC7C,EAAE;YACF,wEAAwE;YACxE,4DAA4D;YAC5D,uEAAuE;YACvE,qEAAqE;YACrE,uEAAuE;YACvE,oDAAoD;YACpD,MAAM9D,qBAAqB;gBAAE2B;gBAAQyB;YAAa;QACpD,OAAO;YACL,MAAMF,OAAOR,MAAM,CAACgB;QACtB;IACF,EAAE,OAAOf,OAAO;QACdC,QAAQD,KAAK,CAACA;IAChB;IACA,wEAAwE;IACxE,yEAAyE;IACzE,OAAOjB,SAASY,SAAS;AAC3B;AAEA,eAAeb,wBAAuB"}
|
|
@@ -127,6 +127,13 @@ export declare function composeNodesWithChrome(options: {
|
|
|
127
127
|
screenNodes: Record<string, any> | Promise<Record<string, any>>;
|
|
128
128
|
/** Entry-template tokens (AGL-105) substituted before denormalize. */
|
|
129
129
|
tokens?: Record<string, string>;
|
|
130
|
+
/**
|
|
131
|
+
* The one record this page renders (AGL-3475) — a record template's routed
|
|
132
|
+
* record. Its `{{item.*}}` tokens are put into the page after the repeats
|
|
133
|
+
* expand, and into each repeat's filter before, exactly as a repeat puts
|
|
134
|
+
* its rows into its copies.
|
|
135
|
+
*/
|
|
136
|
+
record?: Aglyn.PageRecordScope | null;
|
|
130
137
|
/** Routed content collection (AGL-551) for Collection entries blocks. */
|
|
131
138
|
collection?: ComposeCollectionContext;
|
|
132
139
|
/**
|
|
@@ -184,6 +191,8 @@ export declare function composeScreenNodes(options: {
|
|
|
184
191
|
screen: Aglyn.AglynScreen;
|
|
185
192
|
/** Entry-template tokens (AGL-105) substituted before denormalize. */
|
|
186
193
|
tokens?: Record<string, string>;
|
|
194
|
+
/** The one record a record template renders (AGL-3475). */
|
|
195
|
+
record?: Aglyn.PageRecordScope | null;
|
|
187
196
|
/** Routed content collection (AGL-551) for Collection entries blocks. */
|
|
188
197
|
collection?: ComposeCollectionContext;
|
|
189
198
|
/**
|
|
@@ -416,21 +416,27 @@ export async function composeNodesWithChrome(options) {
|
|
|
416
416
|
// asked is the composed one — after grafting — because that is the map the
|
|
417
417
|
// expansion reads: a repeatable living in a layout or a reusable component
|
|
418
418
|
// is invisible in `screenNodes`, and reading only the screen's keys would
|
|
419
|
-
// silently render
|
|
419
|
+
// silently render an empty list where the author put rows. The
|
|
420
420
|
// screen's own keys were issued beside the chrome reads above; a key only a
|
|
421
421
|
// layout or a component adds is read here, for that key alone.
|
|
422
422
|
//
|
|
423
423
|
// The rows come from the plugin that keeps them, through the repeat-rows
|
|
424
424
|
// contract; this composition names no collection. A declared source whose
|
|
425
425
|
// reader is missing THROWS rather than answering "no rows", so a broken boot
|
|
426
|
-
// keeps the last good render instead of
|
|
426
|
+
// keeps the last good render instead of emptying every list. A repeat its
|
|
427
|
+
// rows answer nothing for renders zero copies, never its raw template
|
|
428
|
+
// (AGL-3496).
|
|
427
429
|
const composedRepeatKeys = Aglyn.repeatKeys(grafted);
|
|
428
430
|
const unreadRepeatKeys = composedRepeatKeys.filter((key)=>!screenRepeatKeys.includes(key));
|
|
429
431
|
const repeatRows = unreadRepeatKeys.length ? _extends({}, screenRepeatRows, await readRepeatRows({
|
|
430
432
|
hostId,
|
|
431
433
|
keys: unreadRepeatKeys
|
|
432
434
|
})) : screenRepeatRows;
|
|
433
|
-
|
|
435
|
+
// A record template's routed record (AGL-3475): its values reach each
|
|
436
|
+
// repeat's filter before the expansion, and every token the expansion left
|
|
437
|
+
// — the page's own `{{item.*}}`, never a copy's — right after it.
|
|
438
|
+
const filtered = Aglyn.substituteRepeatFilterRecordTokens(grafted, options.record);
|
|
439
|
+
const repeated = Aglyn.substituteNodesRecordTokens(Aglyn.expandRepeatables(filtered, repeatRows), options.record);
|
|
434
440
|
// Collection entries blocks (AGL-551) expand alongside repeatables:
|
|
435
441
|
// per-entry {{entry.*}} tokens substitute inside the clones here, while
|
|
436
442
|
// page-level tokens wait for resolveNamedTokens below.
|
|
@@ -649,7 +655,10 @@ export async function composeNodesWithChrome(options) {
|
|
|
649
655
|
var _res_version;
|
|
650
656
|
return (_ref = (_res_version = res.version) == null ? void 0 : _res_version.nodes) != null ? _ref : {};
|
|
651
657
|
}, ()=>({})),
|
|
652
|
-
tokens: options.tokens
|
|
658
|
+
tokens: options.tokens
|
|
659
|
+
}, options.record ? {
|
|
660
|
+
record: options.record
|
|
661
|
+
} : {}, {
|
|
653
662
|
collection: options.collection,
|
|
654
663
|
host: options.host,
|
|
655
664
|
socialImages: options.socialImages
|