@aglyn/tenant-data-admin 1.0.0-beta.223 → 1.0.0-beta.224

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/tenant-data-admin",
3
- "version": "1.0.0-beta.223",
3
+ "version": "1.0.0-beta.224",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,12 +25,12 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.0.0-beta.223",
29
- "@aglyn/shared-util-email": "1.0.0-beta.223",
30
- "@aglyn/shared-util-fbserver": "1.0.0-beta.223",
31
- "@aglyn/shared-util-first-touch": "1.0.0-beta.223",
32
- "@aglyn/shared-util-http": "1.0.0-beta.223",
33
- "@aglyn/shared-util-tools": "1.0.0-beta.223",
28
+ "@aglyn/aglyn": "1.0.0-beta.224",
29
+ "@aglyn/shared-util-email": "1.0.0-beta.224",
30
+ "@aglyn/shared-util-fbserver": "1.0.0-beta.224",
31
+ "@aglyn/shared-util-first-touch": "1.0.0-beta.224",
32
+ "@aglyn/shared-util-http": "1.0.0-beta.224",
33
+ "@aglyn/shared-util-tools": "1.0.0-beta.224",
34
34
  "@msgpack/msgpack": "^3.1.3",
35
35
  "@swc/helpers": "0.5.23",
36
36
  "sharp": "^0.35.5",
@@ -33,7 +33,7 @@ export declare const RENDER_MONITOR_DEFAULT_THRESHOLD = 2;
33
33
  * screen slug would, not a reserved or rewritten route.
34
34
  */
35
35
  export declare const RENDER_PROBE_ISR_PREFIX = "/aglyn-render-probe-";
36
- export type RenderProbeKind = 'dynamic' | 'isr';
36
+ export type RenderProbeKind = 'dynamic' | 'isr' | 'page';
37
37
  export interface RenderProbeSpec {
38
38
  kind: RenderProbeKind;
39
39
  /** The path to request, given a fresh nonce. */
@@ -67,6 +67,68 @@ export interface RenderProbeVerdict {
67
67
  * document finished streaming, `/_next/static/` that our build produced it.
68
68
  */
69
69
  export declare function gradeRenderProbe(response: RenderProbeResponse, expectStatus: number): RenderProbeVerdict;
70
+ /**
71
+ * The pages Aglyn's own console renders fresh when `RENDER_MONITOR_PAGES` is
72
+ * unset: the canary's real client pages (`tools/scripts/lib/prod-canary.mjs`
73
+ * `DEFAULT_TENANT_HOSTS`), images, reusable components, repeats and a form
74
+ * between them. Applied ONLY on that console deployment (`VERCEL_PROJECT_ID`),
75
+ * so no other install ever requests them.
76
+ */
77
+ export declare const PLATFORM_RENDER_PAGES: string;
78
+ /** Aglyn's console project on Vercel, the one deployment the list above is for. */
79
+ export declare const PLATFORM_CONSOLE_VERCEL_PROJECT_ID = "prj_gEzxEXc0Lhs81rmaXIg2a1GbsDfl";
80
+ /**
81
+ * The tenant's production project domain on Vercel: follows every promote and
82
+ * rollback, honors `?tenantHost=`, and is reachable only with the bypass.
83
+ */
84
+ export declare const PLATFORM_RENDER_ORIGIN = "https://aglyn-tenant-aglyn.vercel.app";
85
+ /**
86
+ * Spelling number `n` of one site: a `?tenantHost=` value that resolves to
87
+ * that site and is a `[host]` route segment no other number produces, so the
88
+ * page it asks for has no cache entry to come from.
89
+ *
90
+ * - `{sub}.{apex}` → the full name, letters upper-cased by the bits of `n`,
91
+ * then one trailing dot per exhausted round of cases.
92
+ * - any other name → `cname--{name}`, recased the same way and cycling after
93
+ * `2 ** letters` (that form keeps trailing dots), with the prefix left
94
+ * lower-case because the canonical-domain redirect tests the raw segment.
95
+ *
96
+ * MUST stay identical to `freshHostSpelling` in
97
+ * `tools/scripts/lib/prod-canary.mjs`; `apps/tenant/specs/probe-host-spelling.spec.ts`
98
+ * pins both against `normalizeHostAlias`.
99
+ */
100
+ export declare function freshHostSpelling(host: string, n: number, apex?: string): string;
101
+ /**
102
+ * The spelling number for a run at `nowMs`: minutes since 2026-10-01, so it
103
+ * never repeats on one deployment — a `{sub}.aglyn.app` name of 18 letters
104
+ * gains its first trailing dot after half a year.
105
+ */
106
+ export declare function renderSpellingNumber(nowMs: number): number;
107
+ /** One watched site's real pages. */
108
+ export interface RenderMonitorPages {
109
+ /** The site's public origin, which keys its state document. */
110
+ origin: string;
111
+ host: string;
112
+ paths: string[];
113
+ }
114
+ /**
115
+ * `"a.example.app b.example.app/services, https://b.example.app/contact"` →
116
+ * one entry per host, paths merged, `/` when an entry names none. Entries that
117
+ * are not a hostname are dropped, as `RENDER_MONITOR_ORIGINS` drops them.
118
+ */
119
+ export declare function parseRenderMonitorPages(text: string | undefined | null): RenderMonitorPages[];
120
+ /**
121
+ * Which real pages the monitor renders, and through which origin.
122
+ *
123
+ * `RENDER_MONITOR_PAGES` (same grammar as the canary's `CANARY_TENANT_HOSTS`)
124
+ * and `RENDER_MONITOR_RENDER_ORIGIN`, else — on Aglyn's own console only —
125
+ * `PLATFORM_RENDER_PAGES` through `PLATFORM_RENDER_ORIGIN`. `off` (here or in
126
+ * `RENDER_MONITOR_ORIGINS`) renders none. No render origin, no pages.
127
+ */
128
+ export declare function resolveRenderMonitorPages(env: Readonly<Record<string, string | undefined>>): {
129
+ renderOrigin: string;
130
+ pages: RenderMonitorPages[];
131
+ };
70
132
  /** A configured value as an origin, or '' when it is not one. */
71
133
  export declare function originOf(value: string | undefined | null): string;
72
134
  /**
@@ -145,6 +207,11 @@ type RaiseAlert = (type: string, options: {
145
207
  dedupeKey?: string;
146
208
  context?: Record<string, string | number>;
147
209
  }) => Promise<unknown>;
210
+ /**
211
+ * The `page` probe's URL for one run: this run's page of the site's list
212
+ * (rotating every five-minute slot), under this run's spelling of the site.
213
+ */
214
+ export declare function pageProbeUrl(renderOrigin: string, site: RenderMonitorPages, slot: number, spelling: number): string;
148
215
  /**
149
216
  * One run: render every target, record each site's state, raise the edge.
150
217
  *
@@ -50,9 +50,29 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
50
50
  * `operatorHealthState/render-monitor--<host>`, beside every other health
51
51
  * check, so Staff → Operator alerts lists it with its status and since when.
52
52
  *
53
- * Nothing here names an Aglyn host: the default target is the install's own
54
- * demonstration site label under its own tenant apex, the convention the
55
- * middleware and the render canaries already follow.
53
+ * Nothing here names an Aglyn host for anyone else: the default target is the
54
+ * install's own demonstration site label under its own tenant apex, the
55
+ * convention the middleware and the render canaries already follow. The one
56
+ * exception is `PLATFORM_RENDER_PAGES` below, which applies on Aglyn's own
57
+ * console deployment and nowhere else.
58
+ *
59
+ * ## Real pages, rendered fresh (AGL-3571)
60
+ *
61
+ * The two probes above draw the layout. They do not draw a page BODY, and
62
+ * beta.223 hung only on page bodies with an image in them (an ancestor walk
63
+ * looped on the page root, AGL-3565): `demo` has no images and the not-found
64
+ * page has no body, so this monitor read green through it. So a third probe,
65
+ * `page`, renders a real published page through the full ISR path — through
66
+ * the tenant's `*.vercel.app` production domain (`RENDER_MONITOR_RENDER_ORIGIN`),
67
+ * which honors `?tenantHost=` and sits behind Deployment Protection, naming
68
+ * the site with a spelling no cache holds (`freshHostSpelling`). The cache key
69
+ * includes the `[host]` segment, and `normalizeHostAlias` resolves every
70
+ * spelling to the same site. Without the automation bypass the render origin
71
+ * answers its sign-in redirect, so no `page` probe is made at all.
72
+ *
73
+ * One page per site per run, rotating through that site's list: a platform
74
+ * break fails every page with an image, so every run, and alerts as fast as
75
+ * before; a break on one page alone is seen on its turn.
56
76
  */ /** The state documents' collection: the health checks' own. */ const RENDER_MONITOR_COLLECTION = 'operatorHealthState';
57
77
  /** Every render monitor document id starts with this. */ export const RENDER_MONITOR_CHECK_PREFIX = 'render-monitor--';
58
78
  /** The beat id `/api/health/crons` reads for the scheduled run. */ export const RENDER_MONITOR_JOB_ID = 'render-monitor';
@@ -162,6 +182,121 @@ export const RENDER_PROBES = [
162
182
  detail: 'rendered'
163
183
  };
164
184
  }
185
+ /**
186
+ * The pages Aglyn's own console renders fresh when `RENDER_MONITOR_PAGES` is
187
+ * unset: the canary's real client pages (`tools/scripts/lib/prod-canary.mjs`
188
+ * `DEFAULT_TENANT_HOSTS`), images, reusable components, repeats and a form
189
+ * between them. Applied ONLY on that console deployment (`VERCEL_PROJECT_ID`),
190
+ * so no other install ever requests them.
191
+ */ export const PLATFORM_RENDER_PAGES = [
192
+ 'ready-to-roll.aglyn.app/',
193
+ 'edr-construction.aglyn.app/',
194
+ 'edr-construction.aglyn.app/services',
195
+ 'edr-construction.aglyn.app/contact'
196
+ ].join(' ');
197
+ /** Aglyn's console project on Vercel, the one deployment the list above is for. */ export const PLATFORM_CONSOLE_VERCEL_PROJECT_ID = 'prj_gEzxEXc0Lhs81rmaXIg2a1GbsDfl';
198
+ /**
199
+ * The tenant's production project domain on Vercel: follows every promote and
200
+ * rollback, honors `?tenantHost=`, and is reachable only with the bypass.
201
+ */ export const PLATFORM_RENDER_ORIGIN = 'https://aglyn-tenant-aglyn.vercel.app';
202
+ /** The middleware's custom-domain sentinel (`apps/tenant/utils/get-host.ts`). */ const CNAME_HOST_PREFIX = 'cname--';
203
+ /** Letters past this are never recased, so the bit arithmetic stays in 32 bits. */ const MAX_SPELLING_BITS = 30;
204
+ function spellingLetters(host) {
205
+ return [
206
+ ...host.toLowerCase()
207
+ ].map((char, index)=>/[a-z]/.test(char) ? index : -1).filter((index)=>index >= 0).slice(0, MAX_SPELLING_BITS);
208
+ }
209
+ /**
210
+ * Spelling number `n` of one site: a `?tenantHost=` value that resolves to
211
+ * that site and is a `[host]` route segment no other number produces, so the
212
+ * page it asks for has no cache entry to come from.
213
+ *
214
+ * - `{sub}.{apex}` → the full name, letters upper-cased by the bits of `n`,
215
+ * then one trailing dot per exhausted round of cases.
216
+ * - any other name → `cname--{name}`, recased the same way and cycling after
217
+ * `2 ** letters` (that form keeps trailing dots), with the prefix left
218
+ * lower-case because the canonical-domain redirect tests the raw segment.
219
+ *
220
+ * MUST stay identical to `freshHostSpelling` in
221
+ * `tools/scripts/lib/prod-canary.mjs`; `apps/tenant/specs/probe-host-spelling.spec.ts`
222
+ * pins both against `normalizeHostAlias`.
223
+ */ export function freshHostSpelling(host, n, apex = TENANT_APEX) {
224
+ const subdomain = host.endsWith(`.${apex}`);
225
+ const prefix = subdomain ? '' : CNAME_HOST_PREFIX;
226
+ const chars = [
227
+ ...host.toLowerCase()
228
+ ];
229
+ const letters = spellingLetters(host);
230
+ const capacity = 2 ** letters.length;
231
+ const value = Math.max(0, Math.floor(Number(n) || 0));
232
+ const bits = value % capacity;
233
+ letters.forEach((index, bit)=>{
234
+ if (Math.floor(bits / 2 ** bit) % 2 === 1) chars[index] = chars[index].toUpperCase();
235
+ });
236
+ const dots = subdomain ? '.'.repeat(Math.floor(value / capacity)) : '';
237
+ return `${prefix}${chars.join('')}${dots}`;
238
+ }
239
+ /**
240
+ * The spelling number for a run at `nowMs`: minutes since 2026-10-01, so it
241
+ * never repeats on one deployment — a `{sub}.aglyn.app` name of 18 letters
242
+ * gains its first trailing dot after half a year.
243
+ */ export function renderSpellingNumber(nowMs) {
244
+ return Math.max(1, Math.floor((nowMs - Date.UTC(2026, 9, 1)) / 60000));
245
+ }
246
+ /**
247
+ * `"a.example.app b.example.app/services, https://b.example.app/contact"` →
248
+ * one entry per host, paths merged, `/` when an entry names none. Entries that
249
+ * are not a hostname are dropped, as `RENDER_MONITOR_ORIGINS` drops them.
250
+ */ export function parseRenderMonitorPages(text) {
251
+ const byHost = new Map();
252
+ for (const raw of String(text != null ? text : '').split(/[\s,]+/)){
253
+ var _byHost_get;
254
+ const entry = raw.trim().replace(/^https?:\/\//i, '');
255
+ if (!entry) continue;
256
+ const slash = entry.indexOf('/');
257
+ const host = (slash === -1 ? entry : entry.slice(0, slash)).toLowerCase();
258
+ if (!/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(host)) continue;
259
+ const path = slash === -1 ? '/' : entry.slice(slash).replace(/\/+$/, '') || '/';
260
+ const paths = (_byHost_get = byHost.get(host)) != null ? _byHost_get : [];
261
+ if (!paths.includes(path)) paths.push(path);
262
+ byHost.set(host, paths);
263
+ }
264
+ return [
265
+ ...byHost
266
+ ].map(([host, paths])=>({
267
+ origin: `https://${host}`,
268
+ host,
269
+ paths
270
+ }));
271
+ }
272
+ /**
273
+ * Which real pages the monitor renders, and through which origin.
274
+ *
275
+ * `RENDER_MONITOR_PAGES` (same grammar as the canary's `CANARY_TENANT_HOSTS`)
276
+ * and `RENDER_MONITOR_RENDER_ORIGIN`, else — on Aglyn's own console only —
277
+ * `PLATFORM_RENDER_PAGES` through `PLATFORM_RENDER_ORIGIN`. `off` (here or in
278
+ * `RENDER_MONITOR_ORIGINS`) renders none. No render origin, no pages.
279
+ */ export function resolveRenderMonitorPages(env) {
280
+ var _env_RENDER_MONITOR_PAGES, _env_RENDER_MONITOR_ORIGINS;
281
+ const off = /^(off|none|false|0)$/i;
282
+ const raw = String((_env_RENDER_MONITOR_PAGES = env['RENDER_MONITOR_PAGES']) != null ? _env_RENDER_MONITOR_PAGES : '').trim();
283
+ if (off.test(raw) || off.test(String((_env_RENDER_MONITOR_ORIGINS = env['RENDER_MONITOR_ORIGINS']) != null ? _env_RENDER_MONITOR_ORIGINS : '').trim())) {
284
+ return {
285
+ renderOrigin: '',
286
+ pages: []
287
+ };
288
+ }
289
+ const platform = env['VERCEL_PROJECT_ID'] === PLATFORM_CONSOLE_VERCEL_PROJECT_ID;
290
+ const renderOrigin = originOf(env['RENDER_MONITOR_RENDER_ORIGIN']) || (platform ? PLATFORM_RENDER_ORIGIN : '');
291
+ const pages = parseRenderMonitorPages(raw || (platform ? PLATFORM_RENDER_PAGES : ''));
292
+ return renderOrigin ? {
293
+ renderOrigin,
294
+ pages
295
+ } : {
296
+ renderOrigin: '',
297
+ pages: []
298
+ };
299
+ }
165
300
  /** A configured value as an origin, or '' when it is not one. */ export function originOf(value) {
166
301
  const trimmed = String(value != null ? value : '').trim().replace(/\/+$/, '');
167
302
  return /^https?:\/\/[^/\s?#]+$/i.test(trimmed) ? trimmed.toLowerCase() : '';
@@ -184,10 +319,13 @@ export const RENDER_PROBES = [
184
319
  const label = String((_env_AGLYN_TENANT_DEMO = env['AGLYN_TENANT_DEMO']) != null ? _env_AGLYN_TENANT_DEMO : '').trim() || 'demo';
185
320
  const demo = originOf(env['OPERATOR_HEALTH_TENANT_ORIGIN']) || originOf(`https://${label}.${apex}`);
186
321
  const listed = raw.split(/[\s,]+/).map((value)=>originOf(value)).filter(Boolean);
322
+ // A site whose pages are rendered is watched whole: its layout probes too.
323
+ const paged = resolveRenderMonitorPages(env).pages.map((page)=>page.origin);
187
324
  return [
188
325
  ...new Set([
189
326
  demo,
190
- ...listed
327
+ ...listed,
328
+ ...paged
191
329
  ].filter(Boolean))
192
330
  ];
193
331
  }
@@ -269,11 +407,20 @@ function describeDuration(ms) {
269
407
  const rest = minutes % 60;
270
408
  return rest ? `${hours} h ${rest} min` : `${hours} h`;
271
409
  }
410
+ /**
411
+ * The `page` probe's URL for one run: this run's page of the site's list
412
+ * (rotating every five-minute slot), under this run's spelling of the site.
413
+ */ export function pageProbeUrl(renderOrigin, site, slot, spelling) {
414
+ var _site_paths_;
415
+ const path = (_site_paths_ = site.paths[Math.abs(slot) % site.paths.length]) != null ? _site_paths_ : '/';
416
+ const url = new URL(path, renderOrigin);
417
+ url.searchParams.set('tenantHost', freshHostSpelling(site.host, spelling));
418
+ return url.toString();
419
+ }
272
420
  function probeLine(row) {
273
421
  return `${row.kind} ${new URL(row.url).pathname}: ${row.detail} (${row.ms} ms)`;
274
422
  }
275
- /** Fetch and grade one probe. Never throws. */ async function runProbe(origin, spec, options) {
276
- const url = `${origin}${spec.path(options.nonce)}`;
423
+ /** Fetch and grade one probe. Never throws. */ async function runProbe(url, spec, options) {
277
424
  const startedAt = options.clock();
278
425
  try {
279
426
  var _response_headers_get;
@@ -323,7 +470,7 @@ function probeLine(row) {
323
470
  * A dry run fetches and grades and writes nothing, so a person can ask
324
471
  * "what would the monitor see right now" without moving its state.
325
472
  */ export async function runRenderMonitor(options = {}) {
326
- var _options_env, _options_now, _options_store, _options_raise, _env_RENDER_MONITOR_FAILURE_THRESHOLD, _options_nonce;
473
+ var _options_env, _options_now, _options_store, _options_raise, _env_RENDER_MONITOR_FAILURE_THRESHOLD, _options_nonce, _options_fetcher, _options_headers, _options_timeoutMs;
327
474
  const env = (_options_env = options.env) != null ? _options_env : process.env;
328
475
  const clock = (_options_now = options.now) != null ? _options_now : Date.now;
329
476
  const store = (_options_store = options.store) != null ? _options_store : firestoreStore;
@@ -332,24 +479,38 @@ function probeLine(row) {
332
479
  const parsedThreshold = Number.parseInt(String((_env_RENDER_MONITOR_FAILURE_THRESHOLD = env['RENDER_MONITOR_FAILURE_THRESHOLD']) != null ? _env_RENDER_MONITOR_FAILURE_THRESHOLD : ''), 10);
333
480
  const threshold = Number.isFinite(parsedThreshold) && parsedThreshold >= 1 ? parsedThreshold : RENDER_MONITOR_DEFAULT_THRESHOLD;
334
481
  const nonce = (_options_nonce = options.nonce) != null ? _options_nonce : ()=>`${clock().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
482
+ const probeOptions = {
483
+ fetcher: (_options_fetcher = options.fetcher) != null ? _options_fetcher : fetch,
484
+ headers: (_options_headers = options.headers) != null ? _options_headers : {},
485
+ timeoutMs: (_options_timeoutMs = options.timeoutMs) != null ? _options_timeoutMs : RENDER_MONITOR_TIMEOUT_MS,
486
+ clock
487
+ };
488
+ // Real pages need the render origin AND the bypass that gets past its
489
+ // Deployment Protection; without both a `page` probe could only fail.
490
+ const { renderOrigin, pages } = resolveRenderMonitorPages(env);
491
+ const canRenderPages = Boolean(renderOrigin && probeOptions.headers['x-vercel-protection-bypass']);
492
+ const runAt = clock();
493
+ const slot = Math.floor(runAt / 300000);
335
494
  const sites = await Promise.all(resolveRenderMonitorTargets(env).map(async (origin)=>{
336
- const probes = await Promise.all(RENDER_PROBES.map((spec)=>{
337
- var _options_fetcher, _options_headers, _options_timeoutMs;
338
- return runProbe(origin, spec, {
339
- fetcher: (_options_fetcher = options.fetcher) != null ? _options_fetcher : fetch,
340
- headers: (_options_headers = options.headers) != null ? _options_headers : {},
341
- nonce: nonce(),
342
- timeoutMs: (_options_timeoutMs = options.timeoutMs) != null ? _options_timeoutMs : RENDER_MONITOR_TIMEOUT_MS,
343
- clock
344
- });
345
- }));
495
+ const layoutProbes = RENDER_PROBES.map((spec)=>runProbe(`${origin}${spec.path(nonce())}`, spec, probeOptions));
496
+ const site = canRenderPages ? pages.find((page)=>page.origin === origin) : undefined;
497
+ const pageProbe = site ? [
498
+ runProbe(pageProbeUrl(renderOrigin, site, slot, renderSpellingNumber(runAt)), {
499
+ kind: 'page',
500
+ expectStatus: 200
501
+ }, probeOptions)
502
+ ] : [];
503
+ const probes = await Promise.all([
504
+ ...layoutProbes,
505
+ ...pageProbe
506
+ ]);
346
507
  const ok = probes.every((probe)=>probe.ok);
347
- const site = {
508
+ const result = {
348
509
  origin,
349
510
  ok,
350
511
  probes
351
512
  };
352
- if (dryRun) return site;
513
+ if (dryRun) return result;
353
514
  const host = new URL(origin).host;
354
515
  const failing = probes.filter((probe)=>!probe.ok);
355
516
  const detail = ok ? 'Fresh renders pass.' : failing.map(probeLine).join('; ');
@@ -374,9 +535,9 @@ function probeLine(row) {
374
535
  })
375
536
  };
376
537
  });
377
- site.status = next.status;
378
- site.consecutiveFailures = next.consecutiveFailures;
379
- site.transition = transition;
538
+ result.status = next.status;
539
+ result.consecutiveFailures = next.consecutiveFailures;
540
+ result.transition = transition;
380
541
  if (transition === 'failing') {
381
542
  await raise('system.siteRenderFailing', {
382
543
  dedupeKey: host,
@@ -397,10 +558,10 @@ function probeLine(row) {
397
558
  });
398
559
  }
399
560
  } catch (error) {
400
- site.error = error instanceof Error ? error.message : String(error);
561
+ result.error = error instanceof Error ? error.message : String(error);
401
562
  console.error(`[render-monitor] ${host} could not be recorded`, error);
402
563
  }
403
- return site;
564
+ return result;
404
565
  }));
405
566
  return {
406
567
  dryRun,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/render-monitor.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 { TENANT_APEX } from '@aglyn/aglyn/app-utils/tenant-apex'\nimport type { OperatorHealthStateDoc } from './operator-health'\n\n/**\n * THE RENDER MONITOR (AGL-3568): does a published site still render a page\n * that was not already in a cache?\n *\n * On 2026-10-05 every uncached page render on the published-site runtime\n * hung to the platform's 60 s limit for 28 minutes, and nothing alerted. The\n * three monitors that existed each missed it for its own reason:\n *\n * - the GitHub uptime probe is scheduled every 15 minutes and GitHub ran it\n * four times that day, none of them during the outage;\n * - its page rows fetch `/`, which the ISR cache answers, so a visitor's\n * page that was cached still loaded and the row stayed green;\n * - `/api/health/render/site` runs the page LOADER in-process and never the\n * site layout, which is where the request was stuck.\n *\n * So this fetches pages over HTTP, from the console (a different deployment\n * from the one it watches), on Cloud Scheduler every five minutes, and asks\n * for two pages no cache can answer:\n *\n * - `dynamic` — `/search`, a route every site has that renders on every\n * request (`force-dynamic`) inside the full site layout. A 200 that is a\n * complete document proves the layout and head ran just now.\n * - `isr` — a path nobody has ever requested, under the catch-all page.\n * A never-seen path is the one request the ISR cache cannot answer, so it\n * renders in the same static context every published page renders in,\n * which is the context the 2026-09-09 outage only appeared in. It is a\n * 404 by construction, and the site's own not-found page is drawn inside\n * the same layout, so a complete 404 document is a pass.\n *\n * A site that fails `threshold` runs in a row raises\n * `system.siteRenderFailing` once; the first passing run after that raises\n * `system.siteRenderRecovered` once. The state lives in\n * `operatorHealthState/render-monitor--<host>`, beside every other health\n * check, so Staff → Operator alerts lists it with its status and since when.\n *\n * Nothing here names an Aglyn host: the default target is the install's own\n * demonstration site label under its own tenant apex, the convention the\n * middleware and the render canaries already follow.\n */\n\n/** The state documents' collection: the health checks' own. */\nconst RENDER_MONITOR_COLLECTION = 'operatorHealthState'\n\n/** Every render monitor document id starts with this. */\nexport const RENDER_MONITOR_CHECK_PREFIX = 'render-monitor--'\n\n/** The beat id `/api/health/crons` reads for the scheduled run. */\nexport const RENDER_MONITOR_JOB_ID = 'render-monitor'\n\n/**\n * How long one page fetch may take. Well under the 60 s a platform function\n * may run, so a hung render is graded here as a timeout rather than waiting\n * for the platform's 504, and well under the route's own `maxDuration`.\n */\nexport const RENDER_MONITOR_TIMEOUT_MS = 25_000\n\n/** Failing runs in a row before the alert goes out. */\nexport const RENDER_MONITOR_DEFAULT_THRESHOLD = 2\n\n/**\n * The prefix of the never-requested path the `isr` probe asks for. A\n * lowercase slug on purpose: it must reach the catch-all page like any\n * screen slug would, not a reserved or rewritten route.\n */\nexport const RENDER_PROBE_ISR_PREFIX = '/aglyn-render-probe-'\n\nexport type RenderProbeKind = 'dynamic' | 'isr'\n\nexport interface RenderProbeSpec {\n kind: RenderProbeKind\n /** The path to request, given a fresh nonce. */\n path: (nonce: string) => string\n /** The status a healthy render answers with. */\n expectStatus: number\n}\n\nexport const RENDER_PROBES: readonly RenderProbeSpec[] = [\n { kind: 'dynamic', path: () => '/search', expectStatus: 200 },\n {\n kind: 'isr',\n path: (nonce) => `${RENDER_PROBE_ISR_PREFIX}${nonce}`,\n expectStatus: 404,\n },\n]\n\n/** One fetched response, reduced to what grading reads. */\nexport interface RenderProbeResponse {\n status: number\n contentType?: string | null\n body?: string\n location?: string | null\n /** `x-vercel-cache` on Vercel, `x-nextjs-cache` on a plain `next start`. */\n cacheState?: string | null\n}\n\nexport interface RenderProbeVerdict {\n ok: boolean\n /** Bot protection answered instead of the site. */\n challenged: boolean\n /** A stable code; `ok` on a pass. */\n code: string\n detail: string\n}\n\n/** Vercel's challenge interstitial, matched on the body like the front doors. */\nconst CHECKPOINT_MARKER = /Vercel Security Checkpoint/i\n\n/**\n * Cache states that mean the bytes came out of a store. A probe meant to\n * prove a render cannot pass on one of these, whatever the status.\n */\nconst CACHED_STATES = new Set(['HIT', 'STALE', 'PRERENDER'])\n\n/**\n * Grade one probe response. Pure.\n *\n * The page markers are the front doors' (`tools/scripts/lib/front-door.mjs`)\n * and for their reason: structural, never site copy. `</html>` proves the\n * document finished streaming, `/_next/static/` that our build produced it.\n */\nexport function gradeRenderProbe(\n response: RenderProbeResponse,\n expectStatus: number,\n): RenderProbeVerdict {\n const body = response.body ?? ''\n if (CHECKPOINT_MARKER.test(body)) {\n return {\n ok: false,\n challenged: true,\n code: 'challenged',\n detail: `bot protection answered (HTTP ${response.status}) instead of the site; check AGLYN_PROBE_TOKEN on the console`,\n }\n }\n if (response.status >= 300 && response.status < 400) {\n return {\n ok: false,\n challenged: false,\n code: 'redirected',\n detail: `redirected to ${response.location ?? '?'}, so no page was rendered`,\n }\n }\n if (response.status !== expectStatus) {\n return {\n ok: false,\n challenged: false,\n code: `http-${response.status}`,\n detail: `HTTP ${response.status}`,\n }\n }\n if (!/text\\/html/i.test(response.contentType ?? '')) {\n return {\n ok: false,\n challenged: false,\n code: 'not-html',\n detail: `not HTML (${response.contentType || 'no content-type'})`,\n }\n }\n if (!body.includes('</html>')) {\n return {\n ok: false,\n challenged: false,\n code: 'incomplete',\n detail: 'the document never finished (no </html>)',\n }\n }\n if (!body.includes('/_next/static/')) {\n return {\n ok: false,\n challenged: false,\n code: 'not-our-render',\n detail: 'no Next asset references, so the app did not render it',\n }\n }\n const cache = String(response.cacheState ?? '').trim().toUpperCase()\n if (CACHED_STATES.has(cache)) {\n return {\n ok: false,\n challenged: false,\n code: 'served-from-cache',\n detail: `served from cache (${cache}), so it proves no render`,\n }\n }\n return { ok: true, challenged: false, code: 'ok', detail: 'rendered' }\n}\n\n/** A configured value as an origin, or '' when it is not one. */\nexport function originOf(value: string | undefined | null): string {\n const trimmed = String(value ?? '').trim().replace(/\\/+$/, '')\n return /^https?:\\/\\/[^/\\s?#]+$/i.test(trimmed) ? trimmed.toLowerCase() : ''\n}\n\n/**\n * Which sites the monitor renders, from the console's environment.\n *\n * 1. The install's demonstration site: `OPERATOR_HEALTH_TENANT_ORIGIN` when\n * set (the one published site the operator alerts tick already watches),\n * else `https://<AGLYN_TENANT_DEMO or demo>.<tenant apex>`.\n * 2. Plus every origin in `RENDER_MONITOR_ORIGINS`, comma separated.\n *\n * `RENDER_MONITOR_ORIGINS=off` watches nothing, for an install with no\n * published site to watch. Values that are not origins are dropped.\n */\nexport function resolveRenderMonitorTargets(\n env: Readonly<Record<string, string | undefined>>,\n): string[] {\n const raw = String(env['RENDER_MONITOR_ORIGINS'] ?? '').trim()\n if (/^(off|none|false|0)$/i.test(raw)) return []\n const apex =\n String(env['NEXT_PUBLIC_TENANT_DOMAIN'] ?? '').trim() || TENANT_APEX\n const label = String(env['AGLYN_TENANT_DEMO'] ?? '').trim() || 'demo'\n const demo =\n originOf(env['OPERATOR_HEALTH_TENANT_ORIGIN']) ||\n originOf(`https://${label}.${apex}`)\n const listed = raw\n .split(/[\\s,]+/)\n .map((value) => originOf(value))\n .filter(Boolean)\n return [...new Set([demo, ...listed].filter(Boolean))]\n}\n\n/** The state document id for one origin. */\nexport function renderMonitorCheckId(origin: string): string {\n return `${RENDER_MONITOR_CHECK_PREFIX}${new URL(origin).host}`\n}\n\n/** One render monitor state document. */\nexport interface RenderMonitorStateDoc extends OperatorHealthStateDoc {\n origin: string\n /** Failing runs in a row, reset by any passing run. */\n consecutiveFailures: number\n /** When the current run of failures began; null while passing. */\n failingSinceMs: number | null\n lastOkAtMs: number | null\n}\n\nexport type RenderMonitorTransition = 'failing' | 'recovered' | null\n\n/**\n * The next state for one site, given what this run saw. Pure.\n *\n * The status turns `degraded` only once `threshold` runs in a row have\n * failed, so one slow cold start or one dropped connection says nothing. It\n * turns back on the first passing run, because a render that works is\n * proof, and a recovery held back is a recovery nobody hears about.\n */\nexport function nextRenderMonitorState(\n prior: Partial<RenderMonitorStateDoc> | null,\n observation: { ok: boolean; detail: string },\n context: { origin: string; label: string; threshold: number; now: number },\n): { next: RenderMonitorStateDoc; transition: RenderMonitorTransition } {\n const { origin, label, threshold, now } = context\n const checkId = renderMonitorCheckId(origin)\n const detail = String(observation.detail ?? '').slice(0, 1_000)\n const wasDegraded = prior?.status === 'degraded'\n if (observation.ok) {\n return {\n next: {\n checkId,\n label,\n origin,\n status: 'ok',\n sinceMs: !wasDegraded && prior?.sinceMs ? prior.sinceMs : now,\n detail,\n updatedAtMs: now,\n consecutiveFailures: 0,\n failingSinceMs: null,\n lastOkAtMs: now,\n },\n transition: wasDegraded ? 'recovered' : null,\n }\n }\n const failures = (prior?.consecutiveFailures ?? 0) + 1\n const failingSinceMs = prior?.failingSinceMs ?? now\n const degraded = wasDegraded || failures >= Math.max(1, threshold)\n return {\n next: {\n checkId,\n label,\n origin,\n status: degraded ? 'degraded' : 'ok',\n sinceMs: degraded\n ? wasDegraded && prior?.sinceMs\n ? prior.sinceMs\n : failingSinceMs\n : (prior?.sinceMs ?? now),\n detail,\n updatedAtMs: now,\n consecutiveFailures: failures,\n failingSinceMs,\n lastOkAtMs: prior?.lastOkAtMs ?? null,\n },\n transition: degraded && !wasDegraded ? 'failing' : null,\n }\n}\n\n/** One probe as the report shows it. */\nexport interface RenderProbeRow extends RenderProbeVerdict {\n kind: RenderProbeKind\n url: string\n ms: number\n httpStatus: number | null\n}\n\n/** One site's result for a run. */\nexport interface RenderMonitorSiteResult {\n origin: string\n ok: boolean\n probes: RenderProbeRow[]\n /** The state written; absent on a dry run or a failed write. */\n status?: 'ok' | 'degraded'\n consecutiveFailures?: number\n transition?: RenderMonitorTransition\n error?: string\n}\n\nexport interface RenderMonitorReport {\n dryRun: boolean\n threshold: number\n sites: RenderMonitorSiteResult[]\n}\n\n/** The read-modify-write of one site's state, as one transaction. */\nexport type RenderMonitorStore = <T>(\n checkId: string,\n work: (prior: Partial<RenderMonitorStateDoc> | null) => {\n next: RenderMonitorStateDoc\n result: T\n },\n) => Promise<T>\n\n/**\n * The default store: one Firestore transaction on the site's document, so\n * two overlapping runs cannot both decide they saw the edge.\n */\nconst firestoreStore: RenderMonitorStore = async (checkId, work) => {\n const { default: firebaseAdmin } = await import('./firebase-admin')\n const db = firebaseAdmin.app().firestore()\n const ref = db.collection(RENDER_MONITOR_COLLECTION).doc(checkId)\n return db.runTransaction(async (transaction: any) => {\n const snapshot = await transaction.get(ref)\n const prior = snapshot.exists\n ? (snapshot.data() as Partial<RenderMonitorStateDoc>)\n : null\n const { next, result } = work(prior)\n transaction.set(ref, next)\n return result\n })\n}\n\ntype RaiseAlert = (\n type: string,\n options: { dedupeKey?: string; context?: Record<string, string | number> },\n) => Promise<unknown>\n\nconst defaultRaise: RaiseAlert = async (type, options) => {\n const { raiseOperatorAlert } = await import('./operator-alerts')\n return raiseOperatorAlert(type, options)\n}\n\nfunction describeDuration(ms: number): string {\n const minutes = Math.max(1, Math.round(ms / 60_000))\n if (minutes < 60) return `${minutes} min`\n const hours = Math.floor(minutes / 60)\n const rest = minutes % 60\n return rest ? `${hours} h ${rest} min` : `${hours} h`\n}\n\nfunction probeLine(row: RenderProbeRow): string {\n return `${row.kind} ${new URL(row.url).pathname}: ${row.detail} (${row.ms} ms)`\n}\n\n/** Fetch and grade one probe. Never throws. */\nasync function runProbe(\n origin: string,\n spec: RenderProbeSpec,\n options: {\n fetcher: typeof fetch\n headers: Record<string, string>\n nonce: string\n timeoutMs: number\n clock: () => number\n },\n): Promise<RenderProbeRow> {\n const url = `${origin}${spec.path(options.nonce)}`\n const startedAt = options.clock()\n try {\n const response = await options.fetcher(url, {\n redirect: 'manual',\n cache: 'no-store',\n headers: {\n 'user-agent': 'aglyn-render-monitor',\n accept: 'text/html,application/xhtml+xml',\n ...options.headers,\n },\n signal: AbortSignal.timeout(options.timeoutMs),\n })\n const body = await response.text()\n const verdict = gradeRenderProbe(\n {\n status: response.status,\n contentType: response.headers.get('content-type'),\n body,\n location: response.headers.get('location'),\n cacheState:\n response.headers.get('x-vercel-cache') ??\n response.headers.get('x-nextjs-cache'),\n },\n spec.expectStatus,\n )\n return {\n kind: spec.kind,\n url,\n ms: options.clock() - startedAt,\n httpStatus: response.status,\n ...verdict,\n }\n } catch (error) {\n const name = (error as { name?: string } | null)?.name\n const timedOut = name === 'TimeoutError' || name === 'AbortError'\n return {\n kind: spec.kind,\n url,\n ms: options.clock() - startedAt,\n httpStatus: null,\n ok: false,\n challenged: false,\n code: timedOut ? 'timeout' : 'unreachable',\n detail: timedOut\n ? `no complete page in ${Math.round(options.timeoutMs / 1_000)} s`\n : `unreachable (${(error as { cause?: { code?: string } } | null)?.cause?.code ?? name ?? 'error'})`,\n }\n }\n}\n\n/**\n * One run: render every target, record each site's state, raise the edge.\n *\n * A dry run fetches and grades and writes nothing, so a person can ask\n * \"what would the monitor see right now\" without moving its state.\n */\nexport async function runRenderMonitor(\n options: {\n dryRun?: boolean\n env?: Readonly<Record<string, string | undefined>>\n fetcher?: typeof fetch\n /** Our own edge's bypass headers, from the caller's environment. */\n headers?: Record<string, string>\n now?: () => number\n nonce?: () => string\n timeoutMs?: number\n store?: RenderMonitorStore\n raise?: RaiseAlert\n } = {},\n): Promise<RenderMonitorReport> {\n const env = options.env ?? process.env\n const clock = options.now ?? Date.now\n const store = options.store ?? firestoreStore\n const raise = options.raise ?? defaultRaise\n const dryRun = Boolean(options.dryRun)\n const parsedThreshold = Number.parseInt(\n String(env['RENDER_MONITOR_FAILURE_THRESHOLD'] ?? ''),\n 10,\n )\n const threshold =\n Number.isFinite(parsedThreshold) && parsedThreshold >= 1\n ? parsedThreshold\n : RENDER_MONITOR_DEFAULT_THRESHOLD\n const nonce =\n options.nonce ??\n (() => `${clock().toString(36)}${Math.random().toString(36).slice(2, 8)}`)\n\n const sites = await Promise.all(\n resolveRenderMonitorTargets(env).map(\n async (origin): Promise<RenderMonitorSiteResult> => {\n const probes = await Promise.all(\n RENDER_PROBES.map((spec) =>\n runProbe(origin, spec, {\n fetcher: options.fetcher ?? fetch,\n headers: options.headers ?? {},\n nonce: nonce(),\n timeoutMs: options.timeoutMs ?? RENDER_MONITOR_TIMEOUT_MS,\n clock,\n }),\n ),\n )\n const ok = probes.every((probe) => probe.ok)\n const site: RenderMonitorSiteResult = { origin, ok, probes }\n if (dryRun) return site\n const host = new URL(origin).host\n const failing = probes.filter((probe) => !probe.ok)\n const detail = ok\n ? 'Fresh renders pass.'\n : failing.map(probeLine).join('; ')\n try {\n const now = clock()\n const { next, transition, failingSinceMs } = await store(\n renderMonitorCheckId(origin),\n (prior) => {\n const decided = nextRenderMonitorState(\n prior,\n { ok, detail },\n {\n origin,\n label: `Page rendering on ${host}`,\n threshold,\n now,\n },\n )\n return {\n next: decided.next,\n result: {\n ...decided,\n // When the failures a recovery ends began.\n failingSinceMs: prior?.failingSinceMs ?? prior?.sinceMs ?? now,\n },\n }\n },\n )\n site.status = next.status\n site.consecutiveFailures = next.consecutiveFailures\n site.transition = transition\n if (transition === 'failing') {\n await raise('system.siteRenderFailing', {\n dedupeKey: host,\n context: {\n site: host,\n failures: next.consecutiveFailures,\n since: describeDuration(now - next.sinceMs),\n detail,\n },\n })\n } else if (transition === 'recovered') {\n await raise('system.siteRenderRecovered', {\n dedupeKey: host,\n context: {\n site: host,\n duration: describeDuration(now - failingSinceMs),\n },\n })\n }\n } catch (error) {\n site.error = error instanceof Error ? error.message : String(error)\n console.error(`[render-monitor] ${host} could not be recorded`, error)\n }\n return site\n },\n ),\n )\n return { dryRun, threshold, sites }\n}\n"],"names":["TENANT_APEX","RENDER_MONITOR_COLLECTION","RENDER_MONITOR_CHECK_PREFIX","RENDER_MONITOR_JOB_ID","RENDER_MONITOR_TIMEOUT_MS","RENDER_MONITOR_DEFAULT_THRESHOLD","RENDER_PROBE_ISR_PREFIX","RENDER_PROBES","kind","path","expectStatus","nonce","CHECKPOINT_MARKER","CACHED_STATES","Set","gradeRenderProbe","response","body","test","ok","challenged","code","detail","status","location","contentType","includes","cache","String","cacheState","trim","toUpperCase","has","originOf","value","trimmed","replace","toLowerCase","resolveRenderMonitorTargets","env","raw","apex","label","demo","listed","split","map","filter","Boolean","renderMonitorCheckId","origin","URL","host","nextRenderMonitorState","prior","observation","context","threshold","now","checkId","slice","wasDegraded","next","sinceMs","updatedAtMs","consecutiveFailures","failingSinceMs","lastOkAtMs","transition","failures","degraded","Math","max","firestoreStore","work","default","firebaseAdmin","db","app","firestore","ref","collection","doc","runTransaction","transaction","snapshot","get","exists","data","result","set","defaultRaise","type","options","raiseOperatorAlert","describeDuration","ms","minutes","round","hours","floor","rest","probeLine","row","url","pathname","runProbe","spec","startedAt","clock","fetcher","redirect","headers","accept","signal","AbortSignal","timeout","timeoutMs","text","verdict","httpStatus","error","name","timedOut","cause","runRenderMonitor","process","Date","store","raise","dryRun","parsedThreshold","Number","parseInt","isFinite","toString","random","sites","Promise","all","probes","fetch","every","probe","site","failing","join","decided","dedupeKey","since","duration","Error","message","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,WAAW,QAAQ,qCAAoC;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCC,GAED,6DAA6D,GAC7D,MAAMC,4BAA4B;AAElC,uDAAuD,GACvD,OAAO,MAAMC,8BAA8B,mBAAkB;AAE7D,iEAAiE,GACjE,OAAO,MAAMC,wBAAwB,iBAAgB;AAErD;;;;CAIC,GACD,OAAO,MAAMC,4BAA4B,MAAM;AAE/C,qDAAqD,GACrD,OAAO,MAAMC,mCAAmC,EAAC;AAEjD;;;;CAIC,GACD,OAAO,MAAMC,0BAA0B,uBAAsB;AAY7D,OAAO,MAAMC,gBAA4C;IACvD;QAAEC,MAAM;QAAWC,MAAM,IAAM;QAAWC,cAAc;IAAI;IAC5D;QACEF,MAAM;QACNC,MAAM,CAACE,QAAU,GAAGL,0BAA0BK,OAAO;QACrDD,cAAc;IAChB;CACD,CAAA;AAqBD,+EAA+E,GAC/E,MAAME,oBAAoB;AAE1B;;;CAGC,GACD,MAAMC,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mBAAmB;wBAClCoF,OAAOtD,iBAAiBrC,MAAMI,KAAKC,OAAO;wBAC1CzC;oBACF;gBACF;YACF,OAAO,IAAI8C,eAAe,aAAa;gBACrC,MAAM6D,MAAM,8BAA8B;oBACxCmB,WAAWhG;oBACXI,SAAS;wBACPwF,MAAM5F;wBACNkG,UAAUvD,iBAAiBrC,MAAMQ;oBACnC;gBACF;YACF;QACF,EAAE,OAAOuD,OAAO;YACduB,KAAKvB,KAAK,GAAGA,iBAAiB8B,QAAQ9B,MAAM+B,OAAO,GAAG5H,OAAO6F;YAC7DgC,QAAQhC,KAAK,CAAC,CAAC,iBAAiB,EAAErE,KAAK,sBAAsB,CAAC,EAAEqE;QAClE;QACA,OAAOuB;IACT;IAGJ,OAAO;QAAEd;QAAQzE;QAAWgF;IAAM;AACpC"}
1
+ {"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/render-monitor.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 { TENANT_APEX } from '@aglyn/aglyn/app-utils/tenant-apex'\nimport type { OperatorHealthStateDoc } from './operator-health'\n\n/**\n * THE RENDER MONITOR (AGL-3568): does a published site still render a page\n * that was not already in a cache?\n *\n * On 2026-10-05 every uncached page render on the published-site runtime\n * hung to the platform's 60 s limit for 28 minutes, and nothing alerted. The\n * three monitors that existed each missed it for its own reason:\n *\n * - the GitHub uptime probe is scheduled every 15 minutes and GitHub ran it\n * four times that day, none of them during the outage;\n * - its page rows fetch `/`, which the ISR cache answers, so a visitor's\n * page that was cached still loaded and the row stayed green;\n * - `/api/health/render/site` runs the page LOADER in-process and never the\n * site layout, which is where the request was stuck.\n *\n * So this fetches pages over HTTP, from the console (a different deployment\n * from the one it watches), on Cloud Scheduler every five minutes, and asks\n * for two pages no cache can answer:\n *\n * - `dynamic` — `/search`, a route every site has that renders on every\n * request (`force-dynamic`) inside the full site layout. A 200 that is a\n * complete document proves the layout and head ran just now.\n * - `isr` — a path nobody has ever requested, under the catch-all page.\n * A never-seen path is the one request the ISR cache cannot answer, so it\n * renders in the same static context every published page renders in,\n * which is the context the 2026-09-09 outage only appeared in. It is a\n * 404 by construction, and the site's own not-found page is drawn inside\n * the same layout, so a complete 404 document is a pass.\n *\n * A site that fails `threshold` runs in a row raises\n * `system.siteRenderFailing` once; the first passing run after that raises\n * `system.siteRenderRecovered` once. The state lives in\n * `operatorHealthState/render-monitor--<host>`, beside every other health\n * check, so Staff → Operator alerts lists it with its status and since when.\n *\n * Nothing here names an Aglyn host for anyone else: the default target is the\n * install's own demonstration site label under its own tenant apex, the\n * convention the middleware and the render canaries already follow. The one\n * exception is `PLATFORM_RENDER_PAGES` below, which applies on Aglyn's own\n * console deployment and nowhere else.\n *\n * ## Real pages, rendered fresh (AGL-3571)\n *\n * The two probes above draw the layout. They do not draw a page BODY, and\n * beta.223 hung only on page bodies with an image in them (an ancestor walk\n * looped on the page root, AGL-3565): `demo` has no images and the not-found\n * page has no body, so this monitor read green through it. So a third probe,\n * `page`, renders a real published page through the full ISR path — through\n * the tenant's `*.vercel.app` production domain (`RENDER_MONITOR_RENDER_ORIGIN`),\n * which honors `?tenantHost=` and sits behind Deployment Protection, naming\n * the site with a spelling no cache holds (`freshHostSpelling`). The cache key\n * includes the `[host]` segment, and `normalizeHostAlias` resolves every\n * spelling to the same site. Without the automation bypass the render origin\n * answers its sign-in redirect, so no `page` probe is made at all.\n *\n * One page per site per run, rotating through that site's list: a platform\n * break fails every page with an image, so every run, and alerts as fast as\n * before; a break on one page alone is seen on its turn.\n */\n\n/** The state documents' collection: the health checks' own. */\nconst RENDER_MONITOR_COLLECTION = 'operatorHealthState'\n\n/** Every render monitor document id starts with this. */\nexport const RENDER_MONITOR_CHECK_PREFIX = 'render-monitor--'\n\n/** The beat id `/api/health/crons` reads for the scheduled run. */\nexport const RENDER_MONITOR_JOB_ID = 'render-monitor'\n\n/**\n * How long one page fetch may take. Well under the 60 s a platform function\n * may run, so a hung render is graded here as a timeout rather than waiting\n * for the platform's 504, and well under the route's own `maxDuration`.\n */\nexport const RENDER_MONITOR_TIMEOUT_MS = 25_000\n\n/** Failing runs in a row before the alert goes out. */\nexport const RENDER_MONITOR_DEFAULT_THRESHOLD = 2\n\n/**\n * The prefix of the never-requested path the `isr` probe asks for. A\n * lowercase slug on purpose: it must reach the catch-all page like any\n * screen slug would, not a reserved or rewritten route.\n */\nexport const RENDER_PROBE_ISR_PREFIX = '/aglyn-render-probe-'\n\nexport type RenderProbeKind = 'dynamic' | 'isr' | 'page'\n\nexport interface RenderProbeSpec {\n kind: RenderProbeKind\n /** The path to request, given a fresh nonce. */\n path: (nonce: string) => string\n /** The status a healthy render answers with. */\n expectStatus: number\n}\n\nexport const RENDER_PROBES: readonly RenderProbeSpec[] = [\n { kind: 'dynamic', path: () => '/search', expectStatus: 200 },\n {\n kind: 'isr',\n path: (nonce) => `${RENDER_PROBE_ISR_PREFIX}${nonce}`,\n expectStatus: 404,\n },\n]\n\n/** One fetched response, reduced to what grading reads. */\nexport interface RenderProbeResponse {\n status: number\n contentType?: string | null\n body?: string\n location?: string | null\n /** `x-vercel-cache` on Vercel, `x-nextjs-cache` on a plain `next start`. */\n cacheState?: string | null\n}\n\nexport interface RenderProbeVerdict {\n ok: boolean\n /** Bot protection answered instead of the site. */\n challenged: boolean\n /** A stable code; `ok` on a pass. */\n code: string\n detail: string\n}\n\n/** Vercel's challenge interstitial, matched on the body like the front doors. */\nconst CHECKPOINT_MARKER = /Vercel Security Checkpoint/i\n\n/**\n * Cache states that mean the bytes came out of a store. A probe meant to\n * prove a render cannot pass on one of these, whatever the status.\n */\nconst CACHED_STATES = new Set(['HIT', 'STALE', 'PRERENDER'])\n\n/**\n * Grade one probe response. Pure.\n *\n * The page markers are the front doors' (`tools/scripts/lib/front-door.mjs`)\n * and for their reason: structural, never site copy. `</html>` proves the\n * document finished streaming, `/_next/static/` that our build produced it.\n */\nexport function gradeRenderProbe(\n response: RenderProbeResponse,\n expectStatus: number,\n): RenderProbeVerdict {\n const body = response.body ?? ''\n if (CHECKPOINT_MARKER.test(body)) {\n return {\n ok: false,\n challenged: true,\n code: 'challenged',\n detail: `bot protection answered (HTTP ${response.status}) instead of the site; check AGLYN_PROBE_TOKEN on the console`,\n }\n }\n if (response.status >= 300 && response.status < 400) {\n return {\n ok: false,\n challenged: false,\n code: 'redirected',\n detail: `redirected to ${response.location ?? '?'}, so no page was rendered`,\n }\n }\n if (response.status !== expectStatus) {\n return {\n ok: false,\n challenged: false,\n code: `http-${response.status}`,\n detail: `HTTP ${response.status}`,\n }\n }\n if (!/text\\/html/i.test(response.contentType ?? '')) {\n return {\n ok: false,\n challenged: false,\n code: 'not-html',\n detail: `not HTML (${response.contentType || 'no content-type'})`,\n }\n }\n if (!body.includes('</html>')) {\n return {\n ok: false,\n challenged: false,\n code: 'incomplete',\n detail: 'the document never finished (no </html>)',\n }\n }\n if (!body.includes('/_next/static/')) {\n return {\n ok: false,\n challenged: false,\n code: 'not-our-render',\n detail: 'no Next asset references, so the app did not render it',\n }\n }\n const cache = String(response.cacheState ?? '').trim().toUpperCase()\n if (CACHED_STATES.has(cache)) {\n return {\n ok: false,\n challenged: false,\n code: 'served-from-cache',\n detail: `served from cache (${cache}), so it proves no render`,\n }\n }\n return { ok: true, challenged: false, code: 'ok', detail: 'rendered' }\n}\n\n/**\n * The pages Aglyn's own console renders fresh when `RENDER_MONITOR_PAGES` is\n * unset: the canary's real client pages (`tools/scripts/lib/prod-canary.mjs`\n * `DEFAULT_TENANT_HOSTS`), images, reusable components, repeats and a form\n * between them. Applied ONLY on that console deployment (`VERCEL_PROJECT_ID`),\n * so no other install ever requests them.\n */\nexport const PLATFORM_RENDER_PAGES = [\n 'ready-to-roll.aglyn.app/',\n 'edr-construction.aglyn.app/',\n 'edr-construction.aglyn.app/services',\n 'edr-construction.aglyn.app/contact',\n].join(' ')\n\n/** Aglyn's console project on Vercel, the one deployment the list above is for. */\nexport const PLATFORM_CONSOLE_VERCEL_PROJECT_ID = 'prj_gEzxEXc0Lhs81rmaXIg2a1GbsDfl'\n\n/**\n * The tenant's production project domain on Vercel: follows every promote and\n * rollback, honors `?tenantHost=`, and is reachable only with the bypass.\n */\nexport const PLATFORM_RENDER_ORIGIN = 'https://aglyn-tenant-aglyn.vercel.app'\n\n/** The middleware's custom-domain sentinel (`apps/tenant/utils/get-host.ts`). */\nconst CNAME_HOST_PREFIX = 'cname--'\n\n/** Letters past this are never recased, so the bit arithmetic stays in 32 bits. */\nconst MAX_SPELLING_BITS = 30\n\nfunction spellingLetters(host: string): number[] {\n return [...host.toLowerCase()]\n .map((char, index) => (/[a-z]/.test(char) ? index : -1))\n .filter((index) => index >= 0)\n .slice(0, MAX_SPELLING_BITS)\n}\n\n/**\n * Spelling number `n` of one site: a `?tenantHost=` value that resolves to\n * that site and is a `[host]` route segment no other number produces, so the\n * page it asks for has no cache entry to come from.\n *\n * - `{sub}.{apex}` → the full name, letters upper-cased by the bits of `n`,\n * then one trailing dot per exhausted round of cases.\n * - any other name → `cname--{name}`, recased the same way and cycling after\n * `2 ** letters` (that form keeps trailing dots), with the prefix left\n * lower-case because the canonical-domain redirect tests the raw segment.\n *\n * MUST stay identical to `freshHostSpelling` in\n * `tools/scripts/lib/prod-canary.mjs`; `apps/tenant/specs/probe-host-spelling.spec.ts`\n * pins both against `normalizeHostAlias`.\n */\nexport function freshHostSpelling(host: string, n: number, apex: string = TENANT_APEX): string {\n const subdomain = host.endsWith(`.${apex}`)\n const prefix = subdomain ? '' : CNAME_HOST_PREFIX\n const chars = [...host.toLowerCase()]\n const letters = spellingLetters(host)\n const capacity = 2 ** letters.length\n const value = Math.max(0, Math.floor(Number(n) || 0))\n const bits = value % capacity\n letters.forEach((index, bit) => {\n if (Math.floor(bits / 2 ** bit) % 2 === 1) chars[index] = chars[index].toUpperCase()\n })\n const dots = subdomain ? '.'.repeat(Math.floor(value / capacity)) : ''\n return `${prefix}${chars.join('')}${dots}`\n}\n\n/**\n * The spelling number for a run at `nowMs`: minutes since 2026-10-01, so it\n * never repeats on one deployment — a `{sub}.aglyn.app` name of 18 letters\n * gains its first trailing dot after half a year.\n */\nexport function renderSpellingNumber(nowMs: number): number {\n return Math.max(1, Math.floor((nowMs - Date.UTC(2026, 9, 1)) / 60_000))\n}\n\n/** One watched site's real pages. */\nexport interface RenderMonitorPages {\n /** The site's public origin, which keys its state document. */\n origin: string\n host: string\n paths: string[]\n}\n\n/**\n * `\"a.example.app b.example.app/services, https://b.example.app/contact\"` →\n * one entry per host, paths merged, `/` when an entry names none. Entries that\n * are not a hostname are dropped, as `RENDER_MONITOR_ORIGINS` drops them.\n */\nexport function parseRenderMonitorPages(text: string | undefined | null): RenderMonitorPages[] {\n const byHost = new Map<string, string[]>()\n for (const raw of String(text ?? '').split(/[\\s,]+/)) {\n const entry = raw.trim().replace(/^https?:\\/\\//i, '')\n if (!entry) continue\n const slash = entry.indexOf('/')\n const host = (slash === -1 ? entry : entry.slice(0, slash)).toLowerCase()\n if (!/^[a-z0-9-]+(\\.[a-z0-9-]+)+$/.test(host)) continue\n const path = slash === -1 ? '/' : entry.slice(slash).replace(/\\/+$/, '') || '/'\n const paths = byHost.get(host) ?? []\n if (!paths.includes(path)) paths.push(path)\n byHost.set(host, paths)\n }\n return [...byHost].map(([host, paths]) => ({ origin: `https://${host}`, host, paths }))\n}\n\n/**\n * Which real pages the monitor renders, and through which origin.\n *\n * `RENDER_MONITOR_PAGES` (same grammar as the canary's `CANARY_TENANT_HOSTS`)\n * and `RENDER_MONITOR_RENDER_ORIGIN`, else — on Aglyn's own console only —\n * `PLATFORM_RENDER_PAGES` through `PLATFORM_RENDER_ORIGIN`. `off` (here or in\n * `RENDER_MONITOR_ORIGINS`) renders none. No render origin, no pages.\n */\nexport function resolveRenderMonitorPages(\n env: Readonly<Record<string, string | undefined>>,\n): { renderOrigin: string; pages: RenderMonitorPages[] } {\n const off = /^(off|none|false|0)$/i\n const raw = String(env['RENDER_MONITOR_PAGES'] ?? '').trim()\n if (off.test(raw) || off.test(String(env['RENDER_MONITOR_ORIGINS'] ?? '').trim())) {\n return { renderOrigin: '', pages: [] }\n }\n const platform = env['VERCEL_PROJECT_ID'] === PLATFORM_CONSOLE_VERCEL_PROJECT_ID\n const renderOrigin =\n originOf(env['RENDER_MONITOR_RENDER_ORIGIN']) || (platform ? PLATFORM_RENDER_ORIGIN : '')\n const pages = parseRenderMonitorPages(raw || (platform ? PLATFORM_RENDER_PAGES : ''))\n return renderOrigin ? { renderOrigin, pages } : { renderOrigin: '', pages: [] }\n}\n\n/** A configured value as an origin, or '' when it is not one. */\nexport function originOf(value: string | undefined | null): string {\n const trimmed = String(value ?? '').trim().replace(/\\/+$/, '')\n return /^https?:\\/\\/[^/\\s?#]+$/i.test(trimmed) ? trimmed.toLowerCase() : ''\n}\n\n/**\n * Which sites the monitor renders, from the console's environment.\n *\n * 1. The install's demonstration site: `OPERATOR_HEALTH_TENANT_ORIGIN` when\n * set (the one published site the operator alerts tick already watches),\n * else `https://<AGLYN_TENANT_DEMO or demo>.<tenant apex>`.\n * 2. Plus every origin in `RENDER_MONITOR_ORIGINS`, comma separated.\n *\n * `RENDER_MONITOR_ORIGINS=off` watches nothing, for an install with no\n * published site to watch. Values that are not origins are dropped.\n */\nexport function resolveRenderMonitorTargets(\n env: Readonly<Record<string, string | undefined>>,\n): string[] {\n const raw = String(env['RENDER_MONITOR_ORIGINS'] ?? '').trim()\n if (/^(off|none|false|0)$/i.test(raw)) return []\n const apex =\n String(env['NEXT_PUBLIC_TENANT_DOMAIN'] ?? '').trim() || TENANT_APEX\n const label = String(env['AGLYN_TENANT_DEMO'] ?? '').trim() || 'demo'\n const demo =\n originOf(env['OPERATOR_HEALTH_TENANT_ORIGIN']) ||\n originOf(`https://${label}.${apex}`)\n const listed = raw\n .split(/[\\s,]+/)\n .map((value) => originOf(value))\n .filter(Boolean)\n // A site whose pages are rendered is watched whole: its layout probes too.\n const paged = resolveRenderMonitorPages(env).pages.map((page) => page.origin)\n return [...new Set([demo, ...listed, ...paged].filter(Boolean))]\n}\n\n/** The state document id for one origin. */\nexport function renderMonitorCheckId(origin: string): string {\n return `${RENDER_MONITOR_CHECK_PREFIX}${new URL(origin).host}`\n}\n\n/** One render monitor state document. */\nexport interface RenderMonitorStateDoc extends OperatorHealthStateDoc {\n origin: string\n /** Failing runs in a row, reset by any passing run. */\n consecutiveFailures: number\n /** When the current run of failures began; null while passing. */\n failingSinceMs: number | null\n lastOkAtMs: number | null\n}\n\nexport type RenderMonitorTransition = 'failing' | 'recovered' | null\n\n/**\n * The next state for one site, given what this run saw. Pure.\n *\n * The status turns `degraded` only once `threshold` runs in a row have\n * failed, so one slow cold start or one dropped connection says nothing. It\n * turns back on the first passing run, because a render that works is\n * proof, and a recovery held back is a recovery nobody hears about.\n */\nexport function nextRenderMonitorState(\n prior: Partial<RenderMonitorStateDoc> | null,\n observation: { ok: boolean; detail: string },\n context: { origin: string; label: string; threshold: number; now: number },\n): { next: RenderMonitorStateDoc; transition: RenderMonitorTransition } {\n const { origin, label, threshold, now } = context\n const checkId = renderMonitorCheckId(origin)\n const detail = String(observation.detail ?? '').slice(0, 1_000)\n const wasDegraded = prior?.status === 'degraded'\n if (observation.ok) {\n return {\n next: {\n checkId,\n label,\n origin,\n status: 'ok',\n sinceMs: !wasDegraded && prior?.sinceMs ? prior.sinceMs : now,\n detail,\n updatedAtMs: now,\n consecutiveFailures: 0,\n failingSinceMs: null,\n lastOkAtMs: now,\n },\n transition: wasDegraded ? 'recovered' : null,\n }\n }\n const failures = (prior?.consecutiveFailures ?? 0) + 1\n const failingSinceMs = prior?.failingSinceMs ?? now\n const degraded = wasDegraded || failures >= Math.max(1, threshold)\n return {\n next: {\n checkId,\n label,\n origin,\n status: degraded ? 'degraded' : 'ok',\n sinceMs: degraded\n ? wasDegraded && prior?.sinceMs\n ? prior.sinceMs\n : failingSinceMs\n : (prior?.sinceMs ?? now),\n detail,\n updatedAtMs: now,\n consecutiveFailures: failures,\n failingSinceMs,\n lastOkAtMs: prior?.lastOkAtMs ?? null,\n },\n transition: degraded && !wasDegraded ? 'failing' : null,\n }\n}\n\n/** One probe as the report shows it. */\nexport interface RenderProbeRow extends RenderProbeVerdict {\n kind: RenderProbeKind\n url: string\n ms: number\n httpStatus: number | null\n}\n\n/** One site's result for a run. */\nexport interface RenderMonitorSiteResult {\n origin: string\n ok: boolean\n probes: RenderProbeRow[]\n /** The state written; absent on a dry run or a failed write. */\n status?: 'ok' | 'degraded'\n consecutiveFailures?: number\n transition?: RenderMonitorTransition\n error?: string\n}\n\nexport interface RenderMonitorReport {\n dryRun: boolean\n threshold: number\n sites: RenderMonitorSiteResult[]\n}\n\n/** The read-modify-write of one site's state, as one transaction. */\nexport type RenderMonitorStore = <T>(\n checkId: string,\n work: (prior: Partial<RenderMonitorStateDoc> | null) => {\n next: RenderMonitorStateDoc\n result: T\n },\n) => Promise<T>\n\n/**\n * The default store: one Firestore transaction on the site's document, so\n * two overlapping runs cannot both decide they saw the edge.\n */\nconst firestoreStore: RenderMonitorStore = async (checkId, work) => {\n const { default: firebaseAdmin } = await import('./firebase-admin')\n const db = firebaseAdmin.app().firestore()\n const ref = db.collection(RENDER_MONITOR_COLLECTION).doc(checkId)\n return db.runTransaction(async (transaction: any) => {\n const snapshot = await transaction.get(ref)\n const prior = snapshot.exists\n ? (snapshot.data() as Partial<RenderMonitorStateDoc>)\n : null\n const { next, result } = work(prior)\n transaction.set(ref, next)\n return result\n })\n}\n\ntype RaiseAlert = (\n type: string,\n options: { dedupeKey?: string; context?: Record<string, string | number> },\n) => Promise<unknown>\n\nconst defaultRaise: RaiseAlert = async (type, options) => {\n const { raiseOperatorAlert } = await import('./operator-alerts')\n return raiseOperatorAlert(type, options)\n}\n\nfunction describeDuration(ms: number): string {\n const minutes = Math.max(1, Math.round(ms / 60_000))\n if (minutes < 60) return `${minutes} min`\n const hours = Math.floor(minutes / 60)\n const rest = minutes % 60\n return rest ? `${hours} h ${rest} min` : `${hours} h`\n}\n\n/**\n * The `page` probe's URL for one run: this run's page of the site's list\n * (rotating every five-minute slot), under this run's spelling of the site.\n */\nexport function pageProbeUrl(\n renderOrigin: string,\n site: RenderMonitorPages,\n slot: number,\n spelling: number,\n): string {\n const path = site.paths[Math.abs(slot) % site.paths.length] ?? '/'\n const url = new URL(path, renderOrigin)\n url.searchParams.set('tenantHost', freshHostSpelling(site.host, spelling))\n return url.toString()\n}\n\nfunction probeLine(row: RenderProbeRow): string {\n return `${row.kind} ${new URL(row.url).pathname}: ${row.detail} (${row.ms} ms)`\n}\n\n/** Fetch and grade one probe. Never throws. */\nasync function runProbe(\n url: string,\n spec: { kind: RenderProbeKind; expectStatus: number },\n options: {\n fetcher: typeof fetch\n headers: Record<string, string>\n timeoutMs: number\n clock: () => number\n },\n): Promise<RenderProbeRow> {\n const startedAt = options.clock()\n try {\n const response = await options.fetcher(url, {\n redirect: 'manual',\n cache: 'no-store',\n headers: {\n 'user-agent': 'aglyn-render-monitor',\n accept: 'text/html,application/xhtml+xml',\n ...options.headers,\n },\n signal: AbortSignal.timeout(options.timeoutMs),\n })\n const body = await response.text()\n const verdict = gradeRenderProbe(\n {\n status: response.status,\n contentType: response.headers.get('content-type'),\n body,\n location: response.headers.get('location'),\n cacheState:\n response.headers.get('x-vercel-cache') ??\n response.headers.get('x-nextjs-cache'),\n },\n spec.expectStatus,\n )\n return {\n kind: spec.kind,\n url,\n ms: options.clock() - startedAt,\n httpStatus: response.status,\n ...verdict,\n }\n } catch (error) {\n const name = (error as { name?: string } | null)?.name\n const timedOut = name === 'TimeoutError' || name === 'AbortError'\n return {\n kind: spec.kind,\n url,\n ms: options.clock() - startedAt,\n httpStatus: null,\n ok: false,\n challenged: false,\n code: timedOut ? 'timeout' : 'unreachable',\n detail: timedOut\n ? `no complete page in ${Math.round(options.timeoutMs / 1_000)} s`\n : `unreachable (${(error as { cause?: { code?: string } } | null)?.cause?.code ?? name ?? 'error'})`,\n }\n }\n}\n\n/**\n * One run: render every target, record each site's state, raise the edge.\n *\n * A dry run fetches and grades and writes nothing, so a person can ask\n * \"what would the monitor see right now\" without moving its state.\n */\nexport async function runRenderMonitor(\n options: {\n dryRun?: boolean\n env?: Readonly<Record<string, string | undefined>>\n fetcher?: typeof fetch\n /** Our own edge's bypass headers, from the caller's environment. */\n headers?: Record<string, string>\n now?: () => number\n nonce?: () => string\n timeoutMs?: number\n store?: RenderMonitorStore\n raise?: RaiseAlert\n } = {},\n): Promise<RenderMonitorReport> {\n const env = options.env ?? process.env\n const clock = options.now ?? Date.now\n const store = options.store ?? firestoreStore\n const raise = options.raise ?? defaultRaise\n const dryRun = Boolean(options.dryRun)\n const parsedThreshold = Number.parseInt(\n String(env['RENDER_MONITOR_FAILURE_THRESHOLD'] ?? ''),\n 10,\n )\n const threshold =\n Number.isFinite(parsedThreshold) && parsedThreshold >= 1\n ? parsedThreshold\n : RENDER_MONITOR_DEFAULT_THRESHOLD\n const nonce =\n options.nonce ??\n (() => `${clock().toString(36)}${Math.random().toString(36).slice(2, 8)}`)\n\n const probeOptions = {\n fetcher: options.fetcher ?? fetch,\n headers: options.headers ?? {},\n timeoutMs: options.timeoutMs ?? RENDER_MONITOR_TIMEOUT_MS,\n clock,\n }\n // Real pages need the render origin AND the bypass that gets past its\n // Deployment Protection; without both a `page` probe could only fail.\n const { renderOrigin, pages } = resolveRenderMonitorPages(env)\n const canRenderPages = Boolean(\n renderOrigin && probeOptions.headers['x-vercel-protection-bypass'],\n )\n const runAt = clock()\n const slot = Math.floor(runAt / 300_000)\n\n const sites = await Promise.all(\n resolveRenderMonitorTargets(env).map(\n async (origin): Promise<RenderMonitorSiteResult> => {\n const layoutProbes = RENDER_PROBES.map((spec) =>\n runProbe(`${origin}${spec.path(nonce())}`, spec, probeOptions),\n )\n const site = canRenderPages ? pages.find((page) => page.origin === origin) : undefined\n const pageProbe = site\n ? [\n runProbe(\n pageProbeUrl(renderOrigin, site, slot, renderSpellingNumber(runAt)),\n { kind: 'page', expectStatus: 200 },\n probeOptions,\n ),\n ]\n : []\n const probes = await Promise.all([...layoutProbes, ...pageProbe])\n const ok = probes.every((probe) => probe.ok)\n const result: RenderMonitorSiteResult = { origin, ok, probes }\n if (dryRun) return result\n const host = new URL(origin).host\n const failing = probes.filter((probe) => !probe.ok)\n const detail = ok\n ? 'Fresh renders pass.'\n : failing.map(probeLine).join('; ')\n try {\n const now = clock()\n const { next, transition, failingSinceMs } = await store(\n renderMonitorCheckId(origin),\n (prior) => {\n const decided = nextRenderMonitorState(\n prior,\n { ok, detail },\n {\n origin,\n label: `Page rendering on ${host}`,\n threshold,\n now,\n },\n )\n return {\n next: decided.next,\n result: {\n ...decided,\n // When the failures a recovery ends began.\n failingSinceMs: prior?.failingSinceMs ?? prior?.sinceMs ?? now,\n },\n }\n },\n )\n result.status = next.status\n result.consecutiveFailures = next.consecutiveFailures\n result.transition = transition\n if (transition === 'failing') {\n await raise('system.siteRenderFailing', {\n dedupeKey: host,\n context: {\n site: host,\n failures: next.consecutiveFailures,\n since: describeDuration(now - next.sinceMs),\n detail,\n },\n })\n } else if (transition === 'recovered') {\n await raise('system.siteRenderRecovered', {\n dedupeKey: host,\n context: {\n site: host,\n duration: describeDuration(now - failingSinceMs),\n },\n })\n }\n } catch (error) {\n result.error = error instanceof Error ? error.message : String(error)\n console.error(`[render-monitor] ${host} could not be recorded`, error)\n }\n return result\n },\n ),\n )\n return { dryRun, threshold, sites }\n}\n"],"names":["TENANT_APEX","RENDER_MONITOR_COLLECTION","RENDER_MONITOR_CHECK_PREFIX","RENDER_MONITOR_JOB_ID","RENDER_MONITOR_TIMEOUT_MS","RENDER_MONITOR_DEFAULT_THRESHOLD","RENDER_PROBE_ISR_PREFIX","RENDER_PROBES","kind","path","expectStatus","nonce","CHECKPOINT_MARKER","CACHED_STATES","Set","gradeRenderProbe","response","body","test","ok","challenged","code","detail","status","location","contentType","includes","cache","String","cacheState","trim","toUpperCase","has","PLATFORM_RENDER_PAGES","join","PLATFORM_CONSOLE_VERCEL_PROJECT_ID","PLATFORM_RENDER_ORIGIN","CNAME_HOST_PREFIX","MAX_SPELLING_BITS","spellingLetters","host","toLowerCase","map","char","index","filter","slice","freshHostSpelling","n","apex","subdomain","endsWith","prefix","chars","letters","capacity","length","value","Math","max","floor","Number","bits","forEach","bit","dots","repeat","renderSpellingNumber","nowMs","Date","UTC","parseRenderMonitorPages","text","byHost","Map","raw","split","entry","replace","slash","indexOf","paths","get","push","set","origin","resolveRenderMonitorPages","env","off","renderOrigin","pages","platform","originOf","trimmed","resolveRenderMonitorTargets","label","demo","listed","Boolean","paged","page","renderMonitorCheckId","URL","nextRenderMonitorState","prior","observation","context","threshold","now","checkId","wasDegraded","next","sinceMs","updatedAtMs","consecutiveFailures","failingSinceMs","lastOkAtMs","transition","failures","degraded","firestoreStore","work","default","firebaseAdmin","db","app","firestore","ref","collection","doc","runTransaction","transaction","snapshot","exists","data","result","defaultRaise","type","options","raiseOperatorAlert","describeDuration","ms","minutes","round","hours","rest","pageProbeUrl","site","slot","spelling","abs","url","searchParams","toString","probeLine","row","pathname","runProbe","spec","startedAt","clock","fetcher","redirect","headers","accept","signal","AbortSignal","timeout","timeoutMs","verdict","httpStatus","error","name","timedOut","cause","runRenderMonitor","process","store","raise","dryRun","parsedThreshold","parseInt","isFinite","random","probeOptions","fetch","canRenderPages","runAt","sites","Promise","all","layoutProbes","find","undefined","pageProbe","probes","every","probe","failing","decided","dedupeKey","since","duration","Error","message","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,WAAW,QAAQ,qCAAoC;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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