@caelo-cms/shared 0.12.3 → 0.12.5-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-tools.d.ts +21 -0
- package/dist/ai-tools.d.ts.map +1 -1
- package/dist/ai-tools.js +11 -0
- package/dist/ai-tools.js.map +1 -1
- package/dist/change-journal.d.ts +1 -1
- package/dist/change-journal.d.ts.map +1 -1
- package/dist/change-journal.js +9 -0
- package/dist/change-journal.js.map +1 -1
- package/dist/document-language.d.ts +11 -0
- package/dist/document-language.d.ts.map +1 -1
- package/dist/document-language.js +27 -1
- package/dist/document-language.js.map +1 -1
- package/dist/gateway-refresh.d.ts +52 -0
- package/dist/gateway-refresh.d.ts.map +1 -0
- package/dist/gateway-refresh.js +55 -0
- package/dist/gateway-refresh.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/live-events.d.ts.map +1 -1
- package/dist/live-events.js +10 -3
- package/dist/live-events.js.map +1 -1
- package/dist/redirect-plan.d.ts +45 -5
- package/dist/redirect-plan.d.ts.map +1 -1
- package/dist/redirect-plan.js +97 -13
- package/dist/redirect-plan.js.map +1 -1
- package/dist/redirect-release.d.ts +105 -0
- package/dist/redirect-release.d.ts.map +1 -0
- package/dist/redirect-release.js +104 -0
- package/dist/redirect-release.js.map +1 -0
- package/dist/snapshots.d.ts +1 -0
- package/dist/snapshots.d.ts.map +1 -1
- package/dist/snapshots.js +2 -0
- package/dist/snapshots.js.map +1 -1
- package/dist/untrusted-tool-result.d.ts +13 -0
- package/dist/untrusted-tool-result.d.ts.map +1 -1
- package/dist/untrusted-tool-result.js +15 -0
- package/dist/untrusted-tool-result.js.map +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/src/ai-tools.ts +12 -0
- package/src/change-journal.ts +14 -0
- package/src/document-language.test.ts +35 -0
- package/src/document-language.ts +31 -2
- package/src/gateway-refresh.ts +64 -0
- package/src/index.ts +2 -0
- package/src/live-events.ts +10 -3
- package/src/redirect-plan.test.ts +62 -0
- package/src/redirect-plan.ts +98 -12
- package/src/redirect-release.test.ts +167 -0
- package/src/redirect-release.ts +162 -0
- package/src/snapshots.ts +2 -0
- package/src/untrusted-tool-result.ts +17 -0
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"untrusted-tool-result.d.ts","sourceRoot":"","sources":["../src/untrusted-tool-result.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,uCAAuC;AACvC,eAAO,MAAM,yBAAyB,0BAA0B,CAAC;AAEjE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAU1D;AAED,mEAAmE;AACnE,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAUjE"}
|
|
1
|
+
{"version":3,"file":"untrusted-tool-result.d.ts","sourceRoot":"","sources":["../src/untrusted-tool-result.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,uCAAuC;AACvC,eAAO,MAAM,yBAAyB,0BAA0B,CAAC;AAEjE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAU1D;AAED,mEAAmE;AACnE,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAUjE;AAED,2EAA2E;AAC3E,eAAO,MAAM,aAAa,cAAc,CAAC;AAEzC;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|
|
@@ -46,4 +46,19 @@ export function untrustedToolResultValue(content) {
|
|
|
46
46
|
}
|
|
47
47
|
return JSON.parse(lines[2]);
|
|
48
48
|
}
|
|
49
|
+
/** The element that marks content crawled from another website (#1360). */
|
|
50
|
+
export const SITE_DATA_TAG = "site-data";
|
|
51
|
+
/**
|
|
52
|
+
* Mark `text` as crawled from another website, for the admin AI (#1360): a
|
|
53
|
+
* site import's pages, titles, URLs and what its crawl reported about them
|
|
54
|
+
* come from a job that read third-party pages, so any of it may be an
|
|
55
|
+
* attempt to instruct the AI. Inline, so the tool's own guidance around it
|
|
56
|
+
* stays Caelo's; the static system prompt says what the element means. A
|
|
57
|
+
* closing tag inside the text is escaped, so crawled text cannot end the
|
|
58
|
+
* element early and go on as if it were outside it; everything else stays
|
|
59
|
+
* as it is, so the HTML and Markdown the AI rebuilds from stay readable.
|
|
60
|
+
*/
|
|
61
|
+
export function siteData(text) {
|
|
62
|
+
return `<${SITE_DATA_TAG}>${text.replace(/<\/(site-data)/gi, "<\\/$1")}</${SITE_DATA_TAG}>`;
|
|
63
|
+
}
|
|
49
64
|
//# sourceMappingURL=untrusted-tool-result.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"untrusted-tool-result.js","sourceRoot":"","sources":["../src/untrusted-tool-result.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC;;;;;;;;GAQG;AAEH,uCAAuC;AACvC,MAAM,CAAC,MAAM,yBAAyB,GAAG,uBAAuB,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC;SAC3C,UAAU,CAAC,GAAG,EAAE,SAAS,CAAC;SAC1B,UAAU,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC9B,OAAO;QACL,IAAI,yBAAyB,GAAG;QAChC,6NAA6N;QAC7N,IAAI;QACJ,KAAK,yBAAyB,GAAG;KAClC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,yBAAyB,KAAK,CAAC,CAAC;AAChE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAe;IACtD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,IACE,KAAK,CAAC,MAAM,KAAK,CAAC;QAClB,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,yBAAyB,GAAG;QAC7C,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,yBAAyB,GAAG,EAC9C,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAW,CAAC,CAAC;AACxC,CAAC"}
|
|
1
|
+
{"version":3,"file":"untrusted-tool-result.js","sourceRoot":"","sources":["../src/untrusted-tool-result.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC;;;;;;;;GAQG;AAEH,uCAAuC;AACvC,MAAM,CAAC,MAAM,yBAAyB,GAAG,uBAAuB,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC;SAC3C,UAAU,CAAC,GAAG,EAAE,SAAS,CAAC;SAC1B,UAAU,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC9B,OAAO;QACL,IAAI,yBAAyB,GAAG;QAChC,6NAA6N;QAC7N,IAAI;QACJ,KAAK,yBAAyB,GAAG;KAClC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,yBAAyB,KAAK,CAAC,CAAC;AAChE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAe;IACtD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,IACE,KAAK,CAAC,MAAM,KAAK,CAAC;QAClB,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,yBAAyB,GAAG;QAC7C,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,yBAAyB,GAAG,EAC9C,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAW,CAAC,CAAC;AACxC,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AAEzC;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,OAAO,IAAI,aAAa,IAAI,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,QAAQ,CAAC,KAAK,aAAa,GAAG,CAAC;AAC9F,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* Format: SemVer 2.0.0. Pre-1.0 minor bumps are breaking; post-1.0
|
|
20
20
|
* follow standard SemVer.
|
|
21
21
|
*/
|
|
22
|
-
export declare const CAELO_VERSION = "0.12.
|
|
22
|
+
export declare const CAELO_VERSION = "0.12.5-rc.1";
|
|
23
23
|
/**
|
|
24
24
|
* Deprecated alias for back-compat — early P17 work spelled this
|
|
25
25
|
* `CALEO_VERSION` (typo of "Caelo"). New code should import
|
|
@@ -31,7 +31,7 @@ export declare const CAELO_VERSION = "0.12.3";
|
|
|
31
31
|
*
|
|
32
32
|
* @deprecated use CAELO_VERSION
|
|
33
33
|
*/
|
|
34
|
-
export declare const CALEO_VERSION = "0.12.
|
|
34
|
+
export declare const CALEO_VERSION = "0.12.5-rc.1";
|
|
35
35
|
/**
|
|
36
36
|
* Parsed shape — major/minor/patch + optional pre-release tag.
|
|
37
37
|
* Stable interface for callers that need to feature-gate (rare —
|
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,YAAY,CAAC,GAAG,GAAE,MAAsB,GAAG,YAAY,CAYtE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAkBvE"}
|
package/dist/version.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* Format: SemVer 2.0.0. Pre-1.0 minor bumps are breaking; post-1.0
|
|
21
21
|
* follow standard SemVer.
|
|
22
22
|
*/
|
|
23
|
-
export const CAELO_VERSION = "0.12.
|
|
23
|
+
export const CAELO_VERSION = "0.12.5-rc.1";
|
|
24
24
|
/**
|
|
25
25
|
* Deprecated alias for back-compat — early P17 work spelled this
|
|
26
26
|
* `CALEO_VERSION` (typo of "Caelo"). New code should import
|
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;AAgB3C,MAAM,UAAU,YAAY,CAAC,MAAc,aAAa;IACtD,MAAM,CAAC,GAAG,iCAAiC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtD,IAAI,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAC;IACnD,CAAC;IACD,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;QACvC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;QACvC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;QACvC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI;QACxB,GAAG;KACJ,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,OAAe;IAC5D,MAAM,KAAK,GAAG,CAAC,CAAS,EAAuB,EAAE;QAC/C,IAAI,CAAC;YACH,OAAO,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;QAC3C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC;IACF,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;IACzB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3B,KAAK,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAU,EAAE,CAAC;QACrD,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC/C,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU;QAAE,OAAO,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;IACrE,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caelo-cms/shared",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.5-rc.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"description": "Shared Zod schemas + types + the two-pass HTML composer used by every Caelo CMS workspace package. Stable enough for plugin authors and embedders to depend on directly.",
|
package/src/ai-tools.ts
CHANGED
|
@@ -891,6 +891,14 @@ export type AutofillPageSeoToolInput = z.infer<typeof autofillPageSeoToolInput>;
|
|
|
891
891
|
* in a single turn. The handlers run inside one transaction so the
|
|
892
892
|
* batch is all-or-nothing.
|
|
893
893
|
*/
|
|
894
|
+
/**
|
|
895
|
+
* #1550 — when a redirect the AI saves goes live: `next_publish` (Staged:
|
|
896
|
+
* staging serves it at once, the live site with the next Publish live),
|
|
897
|
+
* `later` (a Draft, served nowhere), `now` (Staged, plus a Go live now
|
|
898
|
+
* proposal the operator approves on its card; live once approved).
|
|
899
|
+
*/
|
|
900
|
+
export const redirectGoLiveToolSchema = z.enum(["next_publish", "later", "now"]);
|
|
901
|
+
|
|
894
902
|
export const findRedirectsToolInput = z
|
|
895
903
|
.object({
|
|
896
904
|
query: z.string().max(500).optional(),
|
|
@@ -925,6 +933,8 @@ export const bulkCreateRedirectsToolInput = z
|
|
|
925
933
|
.min(1)
|
|
926
934
|
.max(500),
|
|
927
935
|
upsert: z.boolean().default(false),
|
|
936
|
+
/** #1550 — when the saved rules go live (see {@link redirectGoLiveToolSchema}). */
|
|
937
|
+
goLive: redirectGoLiveToolSchema.default("next_publish"),
|
|
928
938
|
})
|
|
929
939
|
.strict();
|
|
930
940
|
export type BulkCreateRedirectsToolInput = z.infer<typeof bulkCreateRedirectsToolInput>;
|
|
@@ -950,6 +960,8 @@ export const bulkDeleteRedirectsToolInput = z
|
|
|
950
960
|
redirectIds: z.array(z.string().uuid()).max(500).optional(),
|
|
951
961
|
fromPaths: z.array(z.string().min(1).max(500)).max(500).optional(),
|
|
952
962
|
matches: z.string().min(1).max(500).optional(),
|
|
963
|
+
/** #1550 — when the removals go live (see {@link redirectGoLiveToolSchema}). */
|
|
964
|
+
goLive: redirectGoLiveToolSchema.default("next_publish"),
|
|
953
965
|
})
|
|
954
966
|
.strict();
|
|
955
967
|
export type BulkDeleteRedirectsToolInput = z.infer<typeof bulkDeleteRedirectsToolInput>;
|
package/src/change-journal.ts
CHANGED
|
@@ -43,6 +43,7 @@ export const JOURNAL_KINDS = [
|
|
|
43
43
|
"media_crop",
|
|
44
44
|
"font",
|
|
45
45
|
"redirect",
|
|
46
|
+
"pending_redirect",
|
|
46
47
|
"static_file",
|
|
47
48
|
"domain",
|
|
48
49
|
"site_defaults",
|
|
@@ -143,6 +144,7 @@ export const JOURNALED_TABLES: Readonly<Record<string, JournaledTable>> = {
|
|
|
143
144
|
media_crops: row("media_crop", "id", ["id"], { parent: "asset_id" }),
|
|
144
145
|
font_assets: row("font", "id", ["id"]),
|
|
145
146
|
redirects: row("redirect", "id", ["id"]),
|
|
147
|
+
pending_redirects: row("pending_redirect", "id", ["id"], { branch: "chat_branch_id" }),
|
|
146
148
|
static_files: row("static_file", "id", ["id"]),
|
|
147
149
|
domains: row("domain", "id", ["id"]),
|
|
148
150
|
site_defaults: row("site_defaults", "id", ["id"]),
|
|
@@ -227,6 +229,8 @@ export const JOURNAL_EXEMPT_TABLES: Readonly<Record<string, string>> = {
|
|
|
227
229
|
platform_update_events: LOG,
|
|
228
230
|
plugin_errors: LOG,
|
|
229
231
|
redirect_syncs: LOG,
|
|
232
|
+
redirect_release_log:
|
|
233
|
+
"#1550: every write of the live redirects, per address (release, take-over, Go live now, rollback); a rollback reads it, nothing is derived from it",
|
|
230
234
|
operator_access_sync_runs: LOG,
|
|
231
235
|
link_migration_runs: LOG,
|
|
232
236
|
comment_archive:
|
|
@@ -283,6 +287,7 @@ export const JOURNAL_EXEMPT_TABLES: Readonly<Record<string, string>> = {
|
|
|
283
287
|
deploy_targets: "deploy target configuration; read by the deploy ops",
|
|
284
288
|
deploy_runs: "deploy runs; reach editors as the op-classified `deploys` topic",
|
|
285
289
|
redirect_sync_state: RUNTIME,
|
|
290
|
+
gateway_refresh_state: RUNTIME,
|
|
286
291
|
redirect_changes:
|
|
287
292
|
"which transactions changed redirects, folded by the redirect sync; the journaled redirects table is the source",
|
|
288
293
|
static_bakes: "derived build output of plugin-baked regions",
|
|
@@ -300,6 +305,10 @@ export const JOURNAL_EXEMPT_TABLES: Readonly<Record<string, string>> = {
|
|
|
300
305
|
"derived (synchronous, #1391): the ids and media slugs each list snapshot state's items reference, maintained by triggers on the journaled list_snapshots; rebuilt by content_instances.rebuild_refs",
|
|
301
306
|
module_snapshot_refs:
|
|
302
307
|
"derived (synchronous, #1391): the ids and media slugs each module snapshot state's fields reference, maintained by triggers on the journaled module_snapshots; rebuilt by content_instances.rebuild_refs",
|
|
308
|
+
content_value_hashes:
|
|
309
|
+
"derived (synchronous, #1062/#1269): the md5 of each content instance's field values of 20+ characters, maintained by triggers on the journaled content_instances; rebuilt by content_instances.rebuild_value_hashes",
|
|
310
|
+
draft_pending_content_value_hashes:
|
|
311
|
+
"derived (synchronous, #1062/#1269): the same hashes of each pending content-instance state of the draft head, maintained by triggers on draft_pending_entities; rebuilt by content_instances.rebuild_value_hashes",
|
|
303
312
|
page_search_words:
|
|
304
313
|
"derived (synchronous, #1269): the search words of each page's title, short title and slug, maintained by triggers on the journaled pages; rebuilt by pages.rebuild_search_words",
|
|
305
314
|
draft_pending_page_words:
|
|
@@ -324,6 +333,11 @@ export const JOURNAL_EXEMPT_TABLES: Readonly<Record<string, string>> = {
|
|
|
324
333
|
platform_update_requests: "update requests, run by the upgrader job",
|
|
325
334
|
platform_update_scheduler: RUNTIME,
|
|
326
335
|
scheduled_tasks: RUNTIME,
|
|
336
|
+
reporting_jobs: LEASE,
|
|
337
|
+
reporting_job_uploads:
|
|
338
|
+
"#1359: the parts of a job's report too large for one request, read by the action that names them",
|
|
339
|
+
build_orders:
|
|
340
|
+
"#1574: what a build carrier's request builds and how it ended, read by the request that waits for it; the deploy run is the build's record",
|
|
327
341
|
|
|
328
342
|
import_runs: "site-import runs; reach editors as the op-classified `crawl` topic",
|
|
329
343
|
import_pages: "crawled pages of a site import, before they become pages",
|
|
@@ -4,6 +4,7 @@ import { describe, expect, it } from "bun:test";
|
|
|
4
4
|
import {
|
|
5
5
|
applyDocumentLanguage,
|
|
6
6
|
languageTagSchema,
|
|
7
|
+
readDocumentLanguage,
|
|
7
8
|
resolveDocumentLanguage,
|
|
8
9
|
} from "./document-language.js";
|
|
9
10
|
|
|
@@ -116,3 +117,37 @@ describe("languageTagSchema", () => {
|
|
|
116
117
|
}
|
|
117
118
|
});
|
|
118
119
|
});
|
|
120
|
+
|
|
121
|
+
describe("readDocumentLanguage", () => {
|
|
122
|
+
it("reads what applyDocumentLanguage wrote, whatever the layout carried", () => {
|
|
123
|
+
for (const layout of [
|
|
124
|
+
"<!doctype html><html><head></head></html>",
|
|
125
|
+
'<!doctype html><html class="x" lang="fr"><head></head></html>',
|
|
126
|
+
"<head></head><body></body>",
|
|
127
|
+
]) {
|
|
128
|
+
expect(readDocumentLanguage(applyDocumentLanguage(layout, "de-AT"))).toBe("de-AT");
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("reads quoted, single-quoted and unquoted values, the first one winning", () => {
|
|
133
|
+
expect(readDocumentLanguage("<html lang='pt-BR'>")).toBe("pt-BR");
|
|
134
|
+
expect(readDocumentLanguage('<html data-x="a>b" lang=en>')).toBe("en");
|
|
135
|
+
expect(readDocumentLanguage('<html lang="de" lang="en">')).toBe("de");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("is null without a language, never a guess", () => {
|
|
139
|
+
for (const html of [
|
|
140
|
+
"<p>no document</p>",
|
|
141
|
+
"<html><head></head></html>",
|
|
142
|
+
"<html lang>",
|
|
143
|
+
'<html lang="">',
|
|
144
|
+
'<html lang="en" ',
|
|
145
|
+
'<html data-lang="en">',
|
|
146
|
+
'<html xml:lang="en">',
|
|
147
|
+
'<html lang="en" onload="x">',
|
|
148
|
+
'<html-widget lang="en">',
|
|
149
|
+
]) {
|
|
150
|
+
expect(readDocumentLanguage(html)).toBeNull();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
package/src/document-language.ts
CHANGED
|
@@ -76,15 +76,21 @@ const HTML_WS = new Set(["\t", "\n", "\f", "\r", " "]);
|
|
|
76
76
|
function stripLangAttributes(
|
|
77
77
|
html: string,
|
|
78
78
|
from: number,
|
|
79
|
-
): {
|
|
79
|
+
): {
|
|
80
|
+
readonly attrs: string;
|
|
81
|
+
readonly end: number;
|
|
82
|
+
/** The first `lang` attribute's value (unquoted, entities left as written), if any. */
|
|
83
|
+
readonly lang: string | null;
|
|
84
|
+
} | null {
|
|
80
85
|
const n = html.length;
|
|
81
86
|
let i = from;
|
|
82
87
|
let attrs = "";
|
|
88
|
+
let lang: string | null = null;
|
|
83
89
|
while (i < n) {
|
|
84
90
|
const segmentStart = i;
|
|
85
91
|
while (i < n && HTML_WS.has(html[i] as string)) i++;
|
|
86
92
|
if (i >= n) return null;
|
|
87
|
-
if (html[i] === ">") return { attrs: attrs + html.slice(segmentStart, i), end: i + 1 };
|
|
93
|
+
if (html[i] === ">") return { attrs: attrs + html.slice(segmentStart, i), end: i + 1, lang };
|
|
88
94
|
const nameStart = i;
|
|
89
95
|
// An attribute name runs to whitespace, `=`, `>` or `/`; a stray `=`
|
|
90
96
|
// or `/` is consumed as a one-character name so the scan always moves.
|
|
@@ -93,6 +99,7 @@ function stripLangAttributes(
|
|
|
93
99
|
const name = html.slice(nameStart, i).toLowerCase();
|
|
94
100
|
const afterName = i;
|
|
95
101
|
while (i < n && HTML_WS.has(html[i] as string)) i++;
|
|
102
|
+
let value: string | null = null;
|
|
96
103
|
if (html[i] === "=") {
|
|
97
104
|
i++;
|
|
98
105
|
while (i < n && HTML_WS.has(html[i] as string)) i++;
|
|
@@ -100,19 +107,41 @@ function stripLangAttributes(
|
|
|
100
107
|
if (quote === '"' || quote === "'") {
|
|
101
108
|
const close = html.indexOf(quote, i + 1);
|
|
102
109
|
if (close === -1) return null;
|
|
110
|
+
value = html.slice(i + 1, close);
|
|
103
111
|
i = close + 1;
|
|
104
112
|
} else {
|
|
113
|
+
const valueStart = i;
|
|
105
114
|
while (i < n && !HTML_WS.has(html[i] as string) && html[i] !== ">") i++;
|
|
115
|
+
value = html.slice(valueStart, i);
|
|
106
116
|
}
|
|
107
117
|
} else {
|
|
108
118
|
// No value: the whitespace belongs to the next attribute.
|
|
109
119
|
i = afterName;
|
|
110
120
|
}
|
|
111
121
|
if (name !== "lang") attrs += html.slice(segmentStart, i);
|
|
122
|
+
else if (lang === null) lang = value ?? "";
|
|
112
123
|
}
|
|
113
124
|
return null;
|
|
114
125
|
}
|
|
115
126
|
|
|
127
|
+
/**
|
|
128
|
+
* The language a rendered document carries: the `lang` of its `<html>`
|
|
129
|
+
* start tag, as {@link applyDocumentLanguage} wrote it. Plugin output
|
|
130
|
+
* spliced into a finished page (`staticRender`) reads the page's language
|
|
131
|
+
* here, so a static build and a plugin-data build — which only has the
|
|
132
|
+
* published file — hand the plugin the same value.
|
|
133
|
+
*
|
|
134
|
+
* @returns the tag, or `null` when the document has no `<html>` start tag,
|
|
135
|
+
* no `lang`, or one that is not a language tag ({@link languageTagSchema}).
|
|
136
|
+
*/
|
|
137
|
+
export function readDocumentLanguage(html: string): string | null {
|
|
138
|
+
const open = HTML_TAG_OPENER_RE.exec(html);
|
|
139
|
+
if (!open) return null;
|
|
140
|
+
const tag = stripLangAttributes(html, open.index + "<html".length);
|
|
141
|
+
if (!tag || tag.lang === null) return null;
|
|
142
|
+
return languageTagSchema.safeParse(tag.lang).success ? tag.lang : null;
|
|
143
|
+
}
|
|
144
|
+
|
|
116
145
|
function escapeAttr(s: string): string {
|
|
117
146
|
return s
|
|
118
147
|
.replaceAll("&", "&")
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The admin's refresh ping to a public API gateway: what both sides agree on.
|
|
5
|
+
*
|
|
6
|
+
* The gateways run on request-billed CPU (Cloud Run): between requests an
|
|
7
|
+
* instance has no CPU, so the NOTIFY the admin's projection publisher sends
|
|
8
|
+
* waits in the gateway's socket. A gateway whose feature is off (epic #763
|
|
9
|
+
* E14 a: no visitor plugin active, no staging host set) answers every visitor
|
|
10
|
+
* the fixed 404 from memory and never asks the database because of visitor
|
|
11
|
+
* traffic, so nothing in that traffic tells it that the feature was switched
|
|
12
|
+
* on meanwhile. After a publish that wrote a gateway's public database, the
|
|
13
|
+
* admin therefore sends that gateway one request: `POST`
|
|
14
|
+
* {@link GATEWAY_REFRESH_PATH} with a Google-signed ID token of the admin's
|
|
15
|
+
* own service account in {@link GATEWAY_REFRESH_TOKEN_HEADER}, for the
|
|
16
|
+
* audience {@link gatewayRefreshAudience}. The gateway checks the token
|
|
17
|
+
* against Google's public keys, without the database, and on a valid one
|
|
18
|
+
* reads its published state again. Anything else on that path is the fixed
|
|
19
|
+
* 404 of an unknown path (docs/dev/gateway-hardening.md).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** The path of the ping, the same on the live and the staging gateway. */
|
|
23
|
+
export const GATEWAY_REFRESH_PATH = "/api/_caelo/refresh";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The request header carrying the admin's ID token. Not `Authorization`:
|
|
27
|
+
* Cloud Run and Firebase Hosting each give that header meanings of their own.
|
|
28
|
+
*/
|
|
29
|
+
export const GATEWAY_REFRESH_TOKEN_HEADER = "x-caelo-refresh-token";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The gateway env var naming the one service account whose pings it takes:
|
|
33
|
+
* the admin's runtime service account. Required on the Google Cloud
|
|
34
|
+
* providers; the gateways of the other providers take no pings.
|
|
35
|
+
*/
|
|
36
|
+
export const GATEWAY_REFRESH_ACCOUNT_ENV = "CAELO_GATEWAY_REFRESH_ACCOUNT";
|
|
37
|
+
|
|
38
|
+
/** Which gateway a ping is for: the live site's or the staging site's. */
|
|
39
|
+
export type GatewayRefreshTarget = "live" | "staging";
|
|
40
|
+
|
|
41
|
+
/** Both gateways, in the order the admin pings and shows them. */
|
|
42
|
+
export const GATEWAY_REFRESH_TARGETS: readonly GatewayRefreshTarget[] = ["live", "staging"];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The `aud` of a ping's ID token. Fixed per install environment and gateway,
|
|
46
|
+
* so a token minted for one gateway cannot ping the other, nor any other
|
|
47
|
+
* service that takes Google ID tokens. URL-shaped (some token minters accept
|
|
48
|
+
* only URLs) on the reserved `.invalid` domain: nothing is ever served there.
|
|
49
|
+
*
|
|
50
|
+
* @param env - the install environment (`CAELO_ENV`, e.g. `production`)
|
|
51
|
+
*/
|
|
52
|
+
export function gatewayRefreshAudience(env: string, target: GatewayRefreshTarget): string {
|
|
53
|
+
return `https://gateway-refresh.caelo.invalid/${encodeURIComponent(env)}/${target}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether a provider's gateways run on request-billed CPU and so need the
|
|
58
|
+
* ping. Self-hosted gateways have CPU between requests and handle every
|
|
59
|
+
* notification as it arrives; AWS and Azure have no gateway service yet
|
|
60
|
+
* (#749, #750).
|
|
61
|
+
*/
|
|
62
|
+
export function gatewayRefreshPingsOn(provider: string | undefined): boolean {
|
|
63
|
+
return provider === "gcp" || provider === "gcp-firebase";
|
|
64
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ export * from "./font-assets.js";
|
|
|
29
29
|
export * from "./font-axis-policy.js";
|
|
30
30
|
export * from "./font-usage.js";
|
|
31
31
|
export * from "./fonts.js";
|
|
32
|
+
export * from "./gateway-refresh.js";
|
|
32
33
|
export * from "./genesis.js";
|
|
33
34
|
export * from "./genesis-inventory.js";
|
|
34
35
|
export * from "./google-models.js";
|
|
@@ -74,6 +75,7 @@ export * from "./redirect-emit-cloudfront.js";
|
|
|
74
75
|
export * from "./redirect-emit-front-door.js";
|
|
75
76
|
export * from "./redirect-emit-gcp.js";
|
|
76
77
|
export * from "./redirect-plan.js";
|
|
78
|
+
export * from "./redirect-release.js";
|
|
77
79
|
export * from "./redirect-target.js";
|
|
78
80
|
export * from "./release-manifest.js";
|
|
79
81
|
export * from "./responsive-images.js";
|
package/src/live-events.ts
CHANGED
|
@@ -69,9 +69,10 @@ export function parseLiveTopics(
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
// Write ops per topic. Heartbeats (`chat.heartbeat_agent_run`,
|
|
72
|
-
// `chat.renew_turn_lease
|
|
73
|
-
//
|
|
74
|
-
//
|
|
72
|
+
// `chat.renew_turn_lease`, a reporting job's `reporting_jobs.authorize`) and
|
|
73
|
+
// the tick's `quality_audits.sweep_unstarted` / `imports.sweep_unstarted_crawls`
|
|
74
|
+
// are left out on purpose: they commit on a clock, and a hint on a clock is
|
|
75
|
+
// the very polling this replaces.
|
|
75
76
|
const EXACT: Readonly<Record<string, readonly LiveTopic[]>> = {
|
|
76
77
|
"chat.register_agent_run": ["agents"],
|
|
77
78
|
"chat.finish_agent_run": ["agents"],
|
|
@@ -109,6 +110,8 @@ const EXACT: Readonly<Record<string, readonly LiveTopic[]>> = {
|
|
|
109
110
|
"chat.finalize_draft_stage": ["quality", "deploys"],
|
|
110
111
|
"chat.publish": ["quality", "deploys"],
|
|
111
112
|
"quality_audits.enqueue": ["quality"],
|
|
113
|
+
// #1359 — the audit's job took the run: queued → running.
|
|
114
|
+
"quality_audits.claim": ["quality"],
|
|
112
115
|
"quality_audits.record_result": ["quality"],
|
|
113
116
|
"quality_audits.retry": ["quality"],
|
|
114
117
|
"quality_audits.claim_chat_notification": ["quality"],
|
|
@@ -121,6 +124,10 @@ const EXACT: Readonly<Record<string, readonly LiveTopic[]>> = {
|
|
|
121
124
|
"imports.create_run": ["crawl"],
|
|
122
125
|
"imports.update_run_status": ["crawl"],
|
|
123
126
|
"imports.write_extracted_pages": ["crawl"],
|
|
127
|
+
// #1360 — the crawl's job took the run, and ended it either way.
|
|
128
|
+
"imports.claim_crawl": ["crawl"],
|
|
129
|
+
"imports.finish_crawl": ["crawl"],
|
|
130
|
+
"imports.fail_crawl": ["crawl"],
|
|
124
131
|
"deploy.trigger": ["deploys", "quality"],
|
|
125
132
|
// #1211 — the Stage's steps: its run appears, ends failed, ends recorded.
|
|
126
133
|
"deploy.start_trigger": ["deploys"],
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { describe, expect, it } from "bun:test";
|
|
9
9
|
import {
|
|
10
10
|
buildRedirectPlan,
|
|
11
|
+
findRedirectLoops,
|
|
11
12
|
formatRedirectsFile,
|
|
12
13
|
parseRedirectsFile,
|
|
13
14
|
type RedirectTableRow,
|
|
@@ -144,6 +145,42 @@ describe("buildRedirectPlan", () => {
|
|
|
144
145
|
});
|
|
145
146
|
});
|
|
146
147
|
|
|
148
|
+
describe("findRedirectLoops (#1550)", () => {
|
|
149
|
+
it("names each loop once, in chain order, whatever leads into it", () => {
|
|
150
|
+
expect(
|
|
151
|
+
findRedirectLoops(
|
|
152
|
+
[
|
|
153
|
+
row("/in", "/a"),
|
|
154
|
+
row("/a", "/b"),
|
|
155
|
+
row("/b", "/c/"),
|
|
156
|
+
row("/c", "/a"),
|
|
157
|
+
row("/self", "/self/"),
|
|
158
|
+
],
|
|
159
|
+
NO_FILES,
|
|
160
|
+
),
|
|
161
|
+
).toEqual([["/a", "/b", "/c"], ["/self"]]);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("finds what buildRedirectPlan refuses, and nothing it serves", () => {
|
|
165
|
+
const loop = [row("/a", "/b"), row("/b", "/a")];
|
|
166
|
+
expect(() => plan(loop)).toThrow(/loop/);
|
|
167
|
+
expect(findRedirectLoops(loop, NO_FILES)).toEqual([["/a", "/b"]]);
|
|
168
|
+
// A page at /b wins over its rule, so the build serves no loop.
|
|
169
|
+
expect(() => plan(loop, new Set(["b/index.html"]))).not.toThrow();
|
|
170
|
+
expect(findRedirectLoops(loop, new Set(["b/index.html"]))).toEqual([]);
|
|
171
|
+
// A chain ends at a gone row, a target with a query and an external one.
|
|
172
|
+
const ends = [
|
|
173
|
+
row("/g", "/gone"),
|
|
174
|
+
row("/gone", "/g", 410),
|
|
175
|
+
row("/q", "/r?x=1"),
|
|
176
|
+
row("/r", "/q"),
|
|
177
|
+
row("/x", "https://example.org/x"),
|
|
178
|
+
];
|
|
179
|
+
expect(() => plan(ends)).not.toThrow();
|
|
180
|
+
expect(findRedirectLoops(ends, NO_FILES)).toEqual([]);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
147
184
|
describe("redirectsToUnservedPaths (#1157)", () => {
|
|
148
185
|
const served = new Set(["index.html", "live/index.html", "doc.pdf"]);
|
|
149
186
|
it("reports redirects whose target the build does not serve, nothing else", () => {
|
|
@@ -166,6 +203,31 @@ describe("redirectsToUnservedPaths (#1157)", () => {
|
|
|
166
203
|
const p = plan([row("/x", "/y"), row("/y", "/live")], served);
|
|
167
204
|
expect(redirectsToUnservedPaths(p, served)).toEqual([]);
|
|
168
205
|
});
|
|
206
|
+
|
|
207
|
+
it("follows a target with a query through the rule on its path (#1550)", () => {
|
|
208
|
+
// The plan stops collapsing at `/alias?utm=x`, but `/alias`'s rule answers it.
|
|
209
|
+
const p = plan(
|
|
210
|
+
[
|
|
211
|
+
row("/old", "/alias?utm_source=campaign"),
|
|
212
|
+
row("/alias", "/live"),
|
|
213
|
+
row("/lost", "/nowhere?x=1"),
|
|
214
|
+
row("/gone-ref", "/gone?x=1"),
|
|
215
|
+
row("/gone", "/gone", 410),
|
|
216
|
+
row("/ring-a", "/ring-b?x=1"),
|
|
217
|
+
row("/ring-b", "/ring-a?y=1"),
|
|
218
|
+
],
|
|
219
|
+
served,
|
|
220
|
+
);
|
|
221
|
+
expect(p.redirects.find((r) => r.fromPath === "/old")?.location).toBe(
|
|
222
|
+
"/alias?utm_source=campaign",
|
|
223
|
+
);
|
|
224
|
+
expect(redirectsToUnservedPaths(p, served).map((r) => r.fromPath)).toEqual([
|
|
225
|
+
"/lost",
|
|
226
|
+
"/gone-ref",
|
|
227
|
+
"/ring-a",
|
|
228
|
+
"/ring-b",
|
|
229
|
+
]);
|
|
230
|
+
});
|
|
169
231
|
});
|
|
170
232
|
|
|
171
233
|
describe("redirectFromPathSpellings", () => {
|
package/src/redirect-plan.ts
CHANGED
|
@@ -183,13 +183,75 @@ export function buildRedirectPlan(args: BuildRedirectPlanArgs): RedirectPlan {
|
|
|
183
183
|
return { redirects, gone, shadowedByBuild };
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
+
/**
|
|
187
|
+
* #1550 — the loops among `rows`, each as the bare from paths of its cycle
|
|
188
|
+
* in chain order: what {@link buildRedirectPlan} refuses as a loop, found
|
|
189
|
+
* without refusing. A caller that combines rules from several sources (a
|
|
190
|
+
* rollback restores some addresses and keeps others live) holds back the
|
|
191
|
+
* rules that close a loop instead of committing a table no host can serve.
|
|
192
|
+
* Chains follow the plan's rules: a row the build serves a page for is left
|
|
193
|
+
* out, and a chain ends at a 410, an external target, a target with a query
|
|
194
|
+
* or fragment, or a path no row answers. Rows are not validated here
|
|
195
|
+
* (`buildRedirectPlan` does that); of two spellings of one address the
|
|
196
|
+
* first counts.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* findRedirectLoops(
|
|
200
|
+
* [
|
|
201
|
+
* { fromPath: "/a", toPath: "/b", statusCode: 301 },
|
|
202
|
+
* { fromPath: "/b", toPath: "/a/", statusCode: 301 },
|
|
203
|
+
* ],
|
|
204
|
+
* new Set(),
|
|
205
|
+
* )
|
|
206
|
+
* // → [["/a", "/b"]]
|
|
207
|
+
*/
|
|
208
|
+
export function findRedirectLoops(
|
|
209
|
+
rows: readonly RedirectTableRow[],
|
|
210
|
+
servedFiles: ReadonlySet<string>,
|
|
211
|
+
): string[][] {
|
|
212
|
+
const live = new Map<string, NormalisedRow>();
|
|
213
|
+
for (const row of rows) {
|
|
214
|
+
const bare = stripTrailingSlash(row.fromPath);
|
|
215
|
+
if (live.has(bare) || servedByBuild(bare, servedFiles)) continue;
|
|
216
|
+
live.set(bare, { bare, toPath: row.toPath, statusCode: row.statusCode });
|
|
217
|
+
}
|
|
218
|
+
const loops: string[][] = [];
|
|
219
|
+
// A path whose chain was walked once: its loop, if any, is recorded, so
|
|
220
|
+
// every path is walked once and every loop found once.
|
|
221
|
+
const settled = new Set<string>();
|
|
222
|
+
for (const start of live.values()) {
|
|
223
|
+
const chain: string[] = [];
|
|
224
|
+
const onChain = new Map<string, number>();
|
|
225
|
+
let row: NormalisedRow | undefined = start;
|
|
226
|
+
while (row && row.statusCode !== GONE_STATUS && !settled.has(row.bare)) {
|
|
227
|
+
const at = onChain.get(row.bare);
|
|
228
|
+
if (at !== undefined) {
|
|
229
|
+
loops.push(chain.slice(at));
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
onChain.set(row.bare, chain.length);
|
|
233
|
+
chain.push(row.bare);
|
|
234
|
+
if (/[?#]/.test(row.toPath) || isExternalRedirectTarget(row.toPath)) break;
|
|
235
|
+
row = live.get(stripTrailingSlash(row.toPath));
|
|
236
|
+
}
|
|
237
|
+
for (const bare of chain) settled.add(bare);
|
|
238
|
+
}
|
|
239
|
+
return loops;
|
|
240
|
+
}
|
|
241
|
+
|
|
186
242
|
/**
|
|
187
243
|
* The planned redirects whose Location is a same-site path the build does
|
|
188
|
-
* not serve (#1157; an external address is the destination's business)
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* build, and are never reported.
|
|
244
|
+
* not serve (#1157; an external address is the destination's business), so
|
|
245
|
+
* a redirect to a page that is still a draft answers 404 at its target
|
|
246
|
+
* until that page is published. Callers report these, and a release keeps
|
|
247
|
+
* such a change waiting (#1550). Paths under `/api/` are answered by the
|
|
248
|
+
* gateway, not the build, and are never reported.
|
|
249
|
+
*
|
|
250
|
+
* #1550 — a Location with a query or fragment ends the plan's chain
|
|
251
|
+
* collapse (it is another URL than the path a rule matches), but every
|
|
252
|
+
* serving layer matches a rule by the path alone: `/alias?utm=x` follows
|
|
253
|
+
* the rule on `/alias`. So a path another planned rule answers is served
|
|
254
|
+
* when that rule's own Location is (a gone rule's is not).
|
|
193
255
|
*
|
|
194
256
|
* @example
|
|
195
257
|
* redirectsToUnservedPaths(plan, new Set(["index.html"]))
|
|
@@ -199,13 +261,37 @@ export function redirectsToUnservedPaths(
|
|
|
199
261
|
plan: RedirectPlan,
|
|
200
262
|
servedFiles: ReadonlySet<string>,
|
|
201
263
|
): PlannedRedirect[] {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
|
|
264
|
+
const byFromPath = new Map(plan.redirects.map((r) => [r.fromPath, r]));
|
|
265
|
+
const reachable = (location: string, seen: Set<string>): boolean => {
|
|
266
|
+
if (isExternalRedirectTarget(location)) return true;
|
|
267
|
+
const path = pathBeforeQuery(location);
|
|
268
|
+
if (path === "/api" || path.startsWith("/api/")) return true;
|
|
269
|
+
const bare = stripTrailingSlash(path);
|
|
270
|
+
if (looksLikeFile(path) ? servedFiles.has(path.slice(1)) : servedByBuild(bare, servedFiles)) {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
// A rule answers the path: served when its own Location is. `seen`
|
|
274
|
+
// ends a loop, which serves nothing.
|
|
275
|
+
const next = byFromPath.get(bare);
|
|
276
|
+
if (next === undefined || seen.has(bare)) return false;
|
|
277
|
+
seen.add(bare);
|
|
278
|
+
return reachable(next.location, seen);
|
|
279
|
+
};
|
|
280
|
+
return plan.redirects.filter((r) => !reachable(r.location, new Set([r.fromPath])));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* #1550 — whether a file of the build answers `path` (a same-site path, its
|
|
285
|
+
* query and fragment ignored): the page's directory index, the bare-slug
|
|
286
|
+
* page, or the file itself. The same test the plan uses to let a page win
|
|
287
|
+
* over a rule.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* redirectPathServed("/about/", new Set(["about/index.html"])) // → true
|
|
291
|
+
* redirectPathServed("/gone", new Set(["index.html"])) // → false
|
|
292
|
+
*/
|
|
293
|
+
export function redirectPathServed(path: string, servedFiles: ReadonlySet<string>): boolean {
|
|
294
|
+
return servedByBuild(stripTrailingSlash(pathBeforeQuery(path)), servedFiles);
|
|
209
295
|
}
|
|
210
296
|
|
|
211
297
|
/**
|