@aglyn/plugins-redirects 1.29.0 → 1.29.2
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 +11 -11
- package/src/lib/model/redirect-draft-content.d.ts +12 -1
- package/src/lib/model/redirect-draft-content.js +19 -4
- package/src/lib/model/redirect-draft-content.js.map +1 -1
- package/src/lib/plugin.js +6 -1
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/server/redirect-ai-writer.d.ts +11 -0
- package/src/lib/server/redirect-ai-writer.js +117 -11
- package/src/lib/server/redirect-ai-writer.js.map +1 -1
- package/src/lib/transfer/redirects-transfer-fields.js +20 -0
- package/src/lib/transfer/redirects-transfer-fields.js.map +1 -1
- package/src/lib/transfer/squarespace-url-mapping-headers.d.ts +25 -0
- package/src/lib/transfer/squarespace-url-mapping-headers.js +29 -0
- package/src/lib/transfer/squarespace-url-mapping-headers.js.map +1 -0
- package/src/lib/transfer/squarespace-url-mappings.d.ts +56 -0
- package/src/lib/transfer/squarespace-url-mappings.js +192 -0
- package/src/lib/transfer/squarespace-url-mappings.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-redirects",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.29.
|
|
29
|
-
"@aglyn/shared-data-mdi": "1.29.
|
|
30
|
-
"@aglyn/shared-ui-jsx": "1.29.
|
|
31
|
-
"@aglyn/shared-ui-snackstack": "1.29.
|
|
32
|
-
"@aglyn/shared-util-email": "1.29.
|
|
33
|
-
"@aglyn/shared-util-http": "1.29.
|
|
34
|
-
"@aglyn/shared-util-timestamp": "1.29.
|
|
35
|
-
"@aglyn/shared-util-tools": "1.29.
|
|
36
|
-
"@aglyn/tenant-data-admin": "1.29.
|
|
37
|
-
"@aglyn/tenant-feature-instance": "1.29.
|
|
28
|
+
"@aglyn/aglyn": "1.29.2",
|
|
29
|
+
"@aglyn/shared-data-mdi": "1.29.2",
|
|
30
|
+
"@aglyn/shared-ui-jsx": "1.29.2",
|
|
31
|
+
"@aglyn/shared-ui-snackstack": "1.29.2",
|
|
32
|
+
"@aglyn/shared-util-email": "1.29.2",
|
|
33
|
+
"@aglyn/shared-util-http": "1.29.2",
|
|
34
|
+
"@aglyn/shared-util-timestamp": "1.29.2",
|
|
35
|
+
"@aglyn/shared-util-tools": "1.29.2",
|
|
36
|
+
"@aglyn/tenant-data-admin": "1.29.2",
|
|
37
|
+
"@aglyn/tenant-feature-instance": "1.29.2",
|
|
38
38
|
"@swc/helpers": "0.5.24"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
@@ -33,7 +33,11 @@ import { REDIRECT_KINDS, REDIRECT_STATUS_CODES } from './redirects';
|
|
|
33
33
|
*
|
|
34
34
|
* Only the rule's own fields (`HostRedirect`) are read, plus
|
|
35
35
|
* `replacesLivePage`: a from-path the site publishes a page at is refused
|
|
36
|
-
* unless the person asked for that page to be redirected
|
|
36
|
+
* unless the person asked for that page to be redirected; and, on a create,
|
|
37
|
+
* `followChain` (AGL-4245): a destination the site's rules already redirect
|
|
38
|
+
* is replaced by where they lead, so the new rule never starts a chain. A
|
|
39
|
+
* build's arguments never carry it (its schema does not name it); a site
|
|
40
|
+
* import's redirects do. The provenance
|
|
37
41
|
* stamp on an off-site destination is never content: the writer stamps the
|
|
38
42
|
* member the change is made for.
|
|
39
43
|
*/
|
|
@@ -56,6 +60,8 @@ export interface RedirectDraftContent {
|
|
|
56
60
|
priority?: number;
|
|
57
61
|
enabled?: boolean;
|
|
58
62
|
replacesLivePage?: boolean;
|
|
63
|
+
/** Create only: send visitors straight to where an already-redirected destination leads (AGL-4245). */
|
|
64
|
+
followChain?: boolean;
|
|
59
65
|
}
|
|
60
66
|
export type RedirectDraftContentRead = {
|
|
61
67
|
ok: true;
|
|
@@ -69,6 +75,11 @@ export declare function readRedirectDraftContent(content: Readonly<Record<string
|
|
|
69
75
|
/**
|
|
70
76
|
* The seam's `check`: whether the content is a change the writer would try,
|
|
71
77
|
* with what it says about it. Pure. A change is live once written.
|
|
78
|
+
*
|
|
79
|
+
* `storedSource` is the from-path as the rule would store it, normalized
|
|
80
|
+
* the redirects page's way (lowercase, no trailing slash, no query; a
|
|
81
|
+
* pattern trimmed), so a caller compares addresses as the plugin does
|
|
82
|
+
* without restating its rules (AGL-4245).
|
|
72
83
|
*/
|
|
73
84
|
export declare function checkRedirectDraftContent(content: Readonly<Record<string, unknown>>): {
|
|
74
85
|
ok: true;
|
|
@@ -33,7 +33,11 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
33
33
|
*
|
|
34
34
|
* Only the rule's own fields (`HostRedirect`) are read, plus
|
|
35
35
|
* `replacesLivePage`: a from-path the site publishes a page at is refused
|
|
36
|
-
* unless the person asked for that page to be redirected
|
|
36
|
+
* unless the person asked for that page to be redirected; and, on a create,
|
|
37
|
+
* `followChain` (AGL-4245): a destination the site's rules already redirect
|
|
38
|
+
* is replaced by where they lead, so the new rule never starts a chain. A
|
|
39
|
+
* build's arguments never carry it (its schema does not name it); a site
|
|
40
|
+
* import's redirects do. The provenance
|
|
37
41
|
* stamp on an off-site destination is never content: the writer stamps the
|
|
38
42
|
* member the change is made for.
|
|
39
43
|
*/ /** The resource the writer is registered under: the create route's kind. */ export const REDIRECT_DRAFT_RESOURCE = 'redirect';
|
|
@@ -53,7 +57,8 @@ const KEYS = new Set([
|
|
|
53
57
|
'statusCode',
|
|
54
58
|
'priority',
|
|
55
59
|
'enabled',
|
|
56
|
-
'replacesLivePage'
|
|
60
|
+
'replacesLivePage',
|
|
61
|
+
'followChain'
|
|
57
62
|
]);
|
|
58
63
|
/** The fields an update may change, and a remove may not carry. */ const CHANGES = [
|
|
59
64
|
'newSource',
|
|
@@ -110,7 +115,8 @@ function given(value) {
|
|
|
110
115
|
}
|
|
111
116
|
for (const key of [
|
|
112
117
|
'enabled',
|
|
113
|
-
'replacesLivePage'
|
|
118
|
+
'replacesLivePage',
|
|
119
|
+
'followChain'
|
|
114
120
|
]){
|
|
115
121
|
if (content[key] === undefined || content[key] === null) continue;
|
|
116
122
|
if (typeof content[key] === 'boolean') value[key] = content[key];
|
|
@@ -128,6 +134,9 @@ function given(value) {
|
|
|
128
134
|
problems.push('Removing a redirect names only its from-path and, where needed, its match mode');
|
|
129
135
|
}
|
|
130
136
|
}
|
|
137
|
+
if (value.action !== 'create' && value.followChain !== undefined) {
|
|
138
|
+
problems.push('Only a new redirect follows a chain');
|
|
139
|
+
}
|
|
131
140
|
// The page's own rules on what the content gives: a path or pattern the
|
|
132
141
|
// matcher can use, and a destination it can serve that wears no other
|
|
133
142
|
// company's address. The site's own domains are the writer's to add.
|
|
@@ -166,6 +175,11 @@ function given(value) {
|
|
|
166
175
|
/**
|
|
167
176
|
* The seam's `check`: whether the content is a change the writer would try,
|
|
168
177
|
* with what it says about it. Pure. A change is live once written.
|
|
178
|
+
*
|
|
179
|
+
* `storedSource` is the from-path as the rule would store it, normalized
|
|
180
|
+
* the redirects page's way (lowercase, no trailing slash, no query; a
|
|
181
|
+
* pattern trimmed), so a caller compares addresses as the plugin does
|
|
182
|
+
* without restating its rules (AGL-4245).
|
|
169
183
|
*/ export function checkRedirectDraftContent(content) {
|
|
170
184
|
const read = readRedirectDraftContent(content);
|
|
171
185
|
if (read.ok === false) return read;
|
|
@@ -174,7 +188,8 @@ function given(value) {
|
|
|
174
188
|
ok: true,
|
|
175
189
|
facts: _extends({
|
|
176
190
|
action,
|
|
177
|
-
source
|
|
191
|
+
source,
|
|
192
|
+
storedSource: (kind != null ? kind : 'exact') === 'regex' ? source : normalizeRedirectSource(source)
|
|
178
193
|
}, destination ? {
|
|
179
194
|
destination
|
|
180
195
|
} : {}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/redirects/src/lib/model/redirect-draft-content.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 {\n REDIRECT_KINDS,\n REDIRECT_STATUS_CODES,\n normalizeRedirectDestination,\n normalizeRedirectSource,\n validateRedirectRule,\n} from './redirects'\n\n/**\n * A REDIRECT RULE CHANGE ANOTHER PLUGIN ASKS FOR (AGL-3745): the content the\n * `redirect` writer takes on the core's resource-drafts seam, and its pure\n * check. Pure and light, so the console's boot answers `check` without the\n * Admin SDK; the writer (`server/redirect-ai-writer.ts`) reads it again and\n * makes every check that needs the site.\n *\n * One change per item, named by `action`:\n *\n * - `create` a rule from `source` to `destination`, with the page's\n * defaults where a field is not given: exact, 302, priority 100, on;\n * - `update` the live rule at `source` (of `kind`, when the site has rules\n * of two modes at that path): any of `newSource`, `destination`,\n * `statusCode`, `priority`, `enabled`;\n * - `remove` the live rule at `source`, as the page's Delete does.\n *\n * Only the rule's own fields (`HostRedirect`) are read, plus\n * `replacesLivePage`: a from-path the site publishes a page at is refused\n * unless the person asked for that page to be redirected. The provenance\n * stamp on an off-site destination is never content: the writer stamps the\n * member the change is made for.\n */\n\n/** The resource the writer is registered under: the create route's kind. */\nexport const REDIRECT_DRAFT_RESOURCE = 'redirect'\n\nexport const REDIRECT_DRAFT_ACTIONS = ['create', 'update', 'remove'] as const\nexport type RedirectDraftAction = (typeof REDIRECT_DRAFT_ACTIONS)[number]\n\n/** The longest from-path the source normalizer keeps. */\nexport const REDIRECT_DRAFT_SOURCE_MAX = 500\n/** The longest destination the destination normalizer keeps. */\nexport const REDIRECT_DRAFT_DESTINATION_MAX = 1000\n\n/** The content, read. Fields the item did not give are absent. */\nexport interface RedirectDraftContent {\n action: RedirectDraftAction\n source: string\n kind?: (typeof REDIRECT_KINDS)[number]\n destination?: string\n newSource?: string\n statusCode?: (typeof REDIRECT_STATUS_CODES)[number]\n priority?: number\n enabled?: boolean\n replacesLivePage?: boolean\n}\n\nexport type RedirectDraftContentRead =\n | { ok: true; value: RedirectDraftContent }\n | { ok: false; problems: string[] }\n\nconst KEYS = new Set([\n 'action',\n 'source',\n 'kind',\n 'destination',\n 'newSource',\n 'statusCode',\n 'priority',\n 'enabled',\n 'replacesLivePage',\n])\n\n/** The fields an update may change, and a remove may not carry. */\nconst CHANGES = ['newSource', 'destination', 'statusCode', 'priority', 'enabled'] as const\n\nfunction given(value: unknown): boolean {\n return value !== undefined && value !== null && value !== ''\n}\n\n/** A status code as a number: a build's arguments carry it as text. */\nfunction statusCodeOf(value: unknown): number | null {\n const code = typeof value === 'string' && /^\\d{3}$/.test(value.trim()) ? Number(value) : value\n return (REDIRECT_STATUS_CODES as readonly unknown[]).includes(code) ? (code as number) : null\n}\n\n/** The content as the writer reads it, or every problem that stops it. Pure. */\nexport function readRedirectDraftContent(\n content: Readonly<Record<string, unknown>>,\n): RedirectDraftContentRead {\n const problems: string[] = []\n for (const key of Object.keys(content)) {\n if (!KEYS.has(key)) problems.push(`\"${key}\" is not a redirect field`)\n }\n const action = content['action']\n if (!(REDIRECT_DRAFT_ACTIONS as readonly unknown[]).includes(action)) {\n problems.push('Say whether the redirect is created, updated or removed')\n }\n const source = typeof content['source'] === 'string' ? content['source'].trim() : ''\n if (!source) problems.push('Enter a site path like /old-page')\n const value: RedirectDraftContent = { action: action as RedirectDraftAction, source }\n\n if (given(content['kind'])) {\n if ((REDIRECT_KINDS as readonly unknown[]).includes(content['kind'])) {\n value.kind = content['kind'] as RedirectDraftContent['kind']\n } else problems.push('Unknown match mode')\n }\n for (const key of ['destination', 'newSource'] as const) {\n if (!given(content[key])) continue\n if (typeof content[key] === 'string') value[key] = (content[key] as string).trim()\n else problems.push(`\"${key}\" is text`)\n }\n if (given(content['statusCode'])) {\n const code = statusCodeOf(content['statusCode'])\n if (code === null) problems.push('Status codes are 301, 302, 307 or 308')\n else value.statusCode = code as RedirectDraftContent['statusCode']\n }\n if (given(content['priority'])) {\n const priority = content['priority']\n if (typeof priority === 'number' && Number.isInteger(priority)) value.priority = priority\n else problems.push('The priority is a whole number')\n }\n for (const key of ['enabled', 'replacesLivePage'] as const) {\n if (content[key] === undefined || content[key] === null) continue\n if (typeof content[key] === 'boolean') value[key] = content[key] as boolean\n else problems.push(`\"${key}\" is true or false`)\n }\n\n if (value.action === 'create') {\n if (!value.destination) problems.push('Destinations are internal paths or https:// URLs')\n if (value.newSource !== undefined) problems.push('A new redirect has no \"newSource\": its from-path is \"source\"')\n } else if (value.action === 'update') {\n if (!CHANGES.some((key) => value[key] !== undefined)) {\n problems.push('Say what changes: the from-path, the destination, the status code, the priority or whether it is on')\n }\n } else if (value.action === 'remove') {\n if (CHANGES.some((key) => value[key] !== undefined)) {\n problems.push('Removing a redirect names only its from-path and, where needed, its match mode')\n }\n }\n\n // The page's own rules on what the content gives: a path or pattern the\n // matcher can use, and a destination it can serve that wears no other\n // company's address. The site's own domains are the writer's to add.\n const kind = value.kind ?? 'exact'\n if (source && kind !== 'regex' && !normalizeRedirectSource(source)) {\n problems.push('Enter a site path like /old-page')\n }\n const written = value.action === 'create' ? source : value.newSource\n if (written) {\n const problem = validateRedirectRule({ kind, source: written, destination: '/' })\n if (problem) problems.push(problem)\n }\n if (value.destination) {\n const problem = normalizeRedirectDestination(value.destination)\n ? validateRedirectRule({ kind: 'exact', source: '/', destination: value.destination })\n : 'Destinations are internal paths or https:// URLs'\n if (problem) problems.push(problem)\n }\n if (problems.length) return { ok: false, problems: [...new Set(problems)] }\n return { ok: true, value }\n}\n\n/**\n * The seam's `check`: whether the content is a change the writer would try,\n * with what it says about it. Pure. A change is live once written.\n */\nexport function checkRedirectDraftContent(\n content: Readonly<Record<string, unknown>>,\n): { ok: true; facts: Readonly<Record<string, unknown>> } | { ok: false; problems: string[] } {\n const read = readRedirectDraftContent(content)\n if (read.ok === false) return read\n const { action, source, destination, kind } = read.value\n return {\n ok: true,\n facts: { action, source, ...(destination ? { destination } : {}), kind: kind ?? 'exact', live: true },\n }\n}\n"],"names":["REDIRECT_KINDS","REDIRECT_STATUS_CODES","normalizeRedirectDestination","normalizeRedirectSource","validateRedirectRule","REDIRECT_DRAFT_RESOURCE","REDIRECT_DRAFT_ACTIONS","REDIRECT_DRAFT_SOURCE_MAX","REDIRECT_DRAFT_DESTINATION_MAX","KEYS","Set","CHANGES","given","value","undefined","statusCodeOf","code","test","trim","Number","includes","readRedirectDraftContent","content","problems","key","Object","keys","has","push","action","source","kind","statusCode","priority","isInteger","destination","newSource","some","written","problem","length","ok","checkRedirectDraftContent","read","facts","live"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,cAAc,EACdC,qBAAqB,EACrBC,4BAA4B,EAC5BC,uBAAuB,EACvBC,oBAAoB,QACf,iBAAa;AAEpB;;;;;;;;;;;;;;;;;;;;;CAqBC,GAED,0EAA0E,GAC1E,OAAO,MAAMC,0BAA0B,WAAU;AAEjD,OAAO,MAAMC,yBAAyB;IAAC;IAAU;IAAU;CAAS,CAAS;AAG7E,uDAAuD,GACvD,OAAO,MAAMC,4BAA4B,IAAG;AAC5C,8DAA8D,GAC9D,OAAO,MAAMC,iCAAiC,KAAI;AAmBlD,MAAMC,OAAO,IAAIC,IAAI;IACnB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,iEAAiE,GACjE,MAAMC,UAAU;IAAC;IAAa;IAAe;IAAc;IAAY;CAAU;AAEjF,SAASC,MAAMC,KA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AAwE;IACxE,sEAAsE;IACtE,qEAAqE;IACrE,MAAMG,QAAOlB,cAAAA,MAAMkB,IAAI,YAAVlB,cAAc;IAC3B,IAAIiB,UAAUC,SAAS,WAAW,CAAC5B,wBAAwB2B,SAAS;QAClEP,SAASK,IAAI,CAAC;IAChB;IACA,MAAMU,UAAUzB,MAAMgB,MAAM,KAAK,WAAWC,SAASjB,MAAMuB,SAAS;IACpE,IAAIE,SAAS;QACX,MAAMC,UAAUnC,qBAAqB;YAAE2B;YAAMD,QAAQQ;YAASH,aAAa;QAAI;QAC/E,IAAII,SAAShB,SAASK,IAAI,CAACW;IAC7B;IACA,IAAI1B,MAAMsB,WAAW,EAAE;QACrB,MAAMI,UAAUrC,6BAA6BW,MAAMsB,WAAW,IAC1D/B,qBAAqB;YAAE2B,MAAM;YAASD,QAAQ;YAAKK,aAAatB,MAAMsB,WAAW;QAAC,KAClF;QACJ,IAAII,SAAShB,SAASK,IAAI,CAACW;IAC7B;IACA,IAAIhB,SAASiB,MAAM,EAAE,OAAO;QAAEC,IAAI;QAAOlB,UAAU;eAAI,IAAIb,IAAIa;SAAU;IAAC;IAC1E,OAAO;QAAEkB,IAAI;QAAM5B;IAAM;AAC3B;AAEA;;;CAGC,GACD,OAAO,SAAS6B,0BACdpB,OAA0C;IAE1C,MAAMqB,OAAOtB,yBAAyBC;IACtC,IAAIqB,KAAKF,EAAE,KAAK,OAAO,OAAOE;IAC9B,MAAM,EAAEd,MAAM,EAAEC,MAAM,EAAEK,WAAW,EAAEJ,IAAI,EAAE,GAAGY,KAAK9B,KAAK;IACxD,OAAO;QACL4B,IAAI;QACJG,OAAO;YAAEf;YAAQC;WAAYK,cAAc;YAAEA;QAAY,IAAI,CAAC;YAAIJ,IAAI,EAAEA,eAAAA,OAAQ;YAASc,MAAM;;IACjG;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/redirects/src/lib/model/redirect-draft-content.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 {\n REDIRECT_KINDS,\n REDIRECT_STATUS_CODES,\n normalizeRedirectDestination,\n normalizeRedirectSource,\n validateRedirectRule,\n} from './redirects'\n\n/**\n * A REDIRECT RULE CHANGE ANOTHER PLUGIN ASKS FOR (AGL-3745): the content the\n * `redirect` writer takes on the core's resource-drafts seam, and its pure\n * check. Pure and light, so the console's boot answers `check` without the\n * Admin SDK; the writer (`server/redirect-ai-writer.ts`) reads it again and\n * makes every check that needs the site.\n *\n * One change per item, named by `action`:\n *\n * - `create` a rule from `source` to `destination`, with the page's\n * defaults where a field is not given: exact, 302, priority 100, on;\n * - `update` the live rule at `source` (of `kind`, when the site has rules\n * of two modes at that path): any of `newSource`, `destination`,\n * `statusCode`, `priority`, `enabled`;\n * - `remove` the live rule at `source`, as the page's Delete does.\n *\n * Only the rule's own fields (`HostRedirect`) are read, plus\n * `replacesLivePage`: a from-path the site publishes a page at is refused\n * unless the person asked for that page to be redirected; and, on a create,\n * `followChain` (AGL-4245): a destination the site's rules already redirect\n * is replaced by where they lead, so the new rule never starts a chain. A\n * build's arguments never carry it (its schema does not name it); a site\n * import's redirects do. The provenance\n * stamp on an off-site destination is never content: the writer stamps the\n * member the change is made for.\n */\n\n/** The resource the writer is registered under: the create route's kind. */\nexport const REDIRECT_DRAFT_RESOURCE = 'redirect'\n\nexport const REDIRECT_DRAFT_ACTIONS = ['create', 'update', 'remove'] as const\nexport type RedirectDraftAction = (typeof REDIRECT_DRAFT_ACTIONS)[number]\n\n/** The longest from-path the source normalizer keeps. */\nexport const REDIRECT_DRAFT_SOURCE_MAX = 500\n/** The longest destination the destination normalizer keeps. */\nexport const REDIRECT_DRAFT_DESTINATION_MAX = 1000\n\n/** The content, read. Fields the item did not give are absent. */\nexport interface RedirectDraftContent {\n action: RedirectDraftAction\n source: string\n kind?: (typeof REDIRECT_KINDS)[number]\n destination?: string\n newSource?: string\n statusCode?: (typeof REDIRECT_STATUS_CODES)[number]\n priority?: number\n enabled?: boolean\n replacesLivePage?: boolean\n /** Create only: send visitors straight to where an already-redirected destination leads (AGL-4245). */\n followChain?: boolean\n}\n\nexport type RedirectDraftContentRead =\n | { ok: true; value: RedirectDraftContent }\n | { ok: false; problems: string[] }\n\nconst KEYS = new Set([\n 'action',\n 'source',\n 'kind',\n 'destination',\n 'newSource',\n 'statusCode',\n 'priority',\n 'enabled',\n 'replacesLivePage',\n 'followChain',\n])\n\n/** The fields an update may change, and a remove may not carry. */\nconst CHANGES = ['newSource', 'destination', 'statusCode', 'priority', 'enabled'] as const\n\nfunction given(value: unknown): boolean {\n return value !== undefined && value !== null && value !== ''\n}\n\n/** A status code as a number: a build's arguments carry it as text. */\nfunction statusCodeOf(value: unknown): number | null {\n const code = typeof value === 'string' && /^\\d{3}$/.test(value.trim()) ? Number(value) : value\n return (REDIRECT_STATUS_CODES as readonly unknown[]).includes(code) ? (code as number) : null\n}\n\n/** The content as the writer reads it, or every problem that stops it. Pure. */\nexport function readRedirectDraftContent(\n content: Readonly<Record<string, unknown>>,\n): RedirectDraftContentRead {\n const problems: string[] = []\n for (const key of Object.keys(content)) {\n if (!KEYS.has(key)) problems.push(`\"${key}\" is not a redirect field`)\n }\n const action = content['action']\n if (!(REDIRECT_DRAFT_ACTIONS as readonly unknown[]).includes(action)) {\n problems.push('Say whether the redirect is created, updated or removed')\n }\n const source = typeof content['source'] === 'string' ? content['source'].trim() : ''\n if (!source) problems.push('Enter a site path like /old-page')\n const value: RedirectDraftContent = { action: action as RedirectDraftAction, source }\n\n if (given(content['kind'])) {\n if ((REDIRECT_KINDS as readonly unknown[]).includes(content['kind'])) {\n value.kind = content['kind'] as RedirectDraftContent['kind']\n } else problems.push('Unknown match mode')\n }\n for (const key of ['destination', 'newSource'] as const) {\n if (!given(content[key])) continue\n if (typeof content[key] === 'string') value[key] = (content[key] as string).trim()\n else problems.push(`\"${key}\" is text`)\n }\n if (given(content['statusCode'])) {\n const code = statusCodeOf(content['statusCode'])\n if (code === null) problems.push('Status codes are 301, 302, 307 or 308')\n else value.statusCode = code as RedirectDraftContent['statusCode']\n }\n if (given(content['priority'])) {\n const priority = content['priority']\n if (typeof priority === 'number' && Number.isInteger(priority)) value.priority = priority\n else problems.push('The priority is a whole number')\n }\n for (const key of ['enabled', 'replacesLivePage', 'followChain'] as const) {\n if (content[key] === undefined || content[key] === null) continue\n if (typeof content[key] === 'boolean') value[key] = content[key] as boolean\n else problems.push(`\"${key}\" is true or false`)\n }\n\n if (value.action === 'create') {\n if (!value.destination) problems.push('Destinations are internal paths or https:// URLs')\n if (value.newSource !== undefined) problems.push('A new redirect has no \"newSource\": its from-path is \"source\"')\n } else if (value.action === 'update') {\n if (!CHANGES.some((key) => value[key] !== undefined)) {\n problems.push('Say what changes: the from-path, the destination, the status code, the priority or whether it is on')\n }\n } else if (value.action === 'remove') {\n if (CHANGES.some((key) => value[key] !== undefined)) {\n problems.push('Removing a redirect names only its from-path and, where needed, its match mode')\n }\n }\n if (value.action !== 'create' && value.followChain !== undefined) {\n problems.push('Only a new redirect follows a chain')\n }\n\n // The page's own rules on what the content gives: a path or pattern the\n // matcher can use, and a destination it can serve that wears no other\n // company's address. The site's own domains are the writer's to add.\n const kind = value.kind ?? 'exact'\n if (source && kind !== 'regex' && !normalizeRedirectSource(source)) {\n problems.push('Enter a site path like /old-page')\n }\n const written = value.action === 'create' ? source : value.newSource\n if (written) {\n const problem = validateRedirectRule({ kind, source: written, destination: '/' })\n if (problem) problems.push(problem)\n }\n if (value.destination) {\n const problem = normalizeRedirectDestination(value.destination)\n ? validateRedirectRule({ kind: 'exact', source: '/', destination: value.destination })\n : 'Destinations are internal paths or https:// URLs'\n if (problem) problems.push(problem)\n }\n if (problems.length) return { ok: false, problems: [...new Set(problems)] }\n return { ok: true, value }\n}\n\n/**\n * The seam's `check`: whether the content is a change the writer would try,\n * with what it says about it. Pure. A change is live once written.\n *\n * `storedSource` is the from-path as the rule would store it, normalized\n * the redirects page's way (lowercase, no trailing slash, no query; a\n * pattern trimmed), so a caller compares addresses as the plugin does\n * without restating its rules (AGL-4245).\n */\nexport function checkRedirectDraftContent(\n content: Readonly<Record<string, unknown>>,\n): { ok: true; facts: Readonly<Record<string, unknown>> } | { ok: false; problems: string[] } {\n const read = readRedirectDraftContent(content)\n if (read.ok === false) return read\n const { action, source, destination, kind } = read.value\n return {\n ok: true,\n facts: {\n action,\n source,\n storedSource: (kind ?? 'exact') === 'regex' ? source : normalizeRedirectSource(source),\n ...(destination ? { destination } : {}),\n kind: kind ?? 'exact',\n live: true,\n },\n }\n}\n"],"names":["REDIRECT_KINDS","REDIRECT_STATUS_CODES","normalizeRedirectDestination","normalizeRedirectSource","validateRedirectRule","REDIRECT_DRAFT_RESOURCE","REDIRECT_DRAFT_ACTIONS","REDIRECT_DRAFT_SOURCE_MAX","REDIRECT_DRAFT_DESTINATION_MAX","KEYS","Set","CHANGES","given","value","undefined","statusCodeOf","code","test","trim","Number","includes","readRedirectDraftContent","content","problems","key","Object","keys","has","push","action","source","kind","statusCode","priority","isInteger","destination","newSource","some","followChain","written","problem","length","ok","checkRedirectDraftContent","read","facts","storedSource","live"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,cAAc,EACdC,qBAAqB,EACrBC,4BAA4B,EAC5BC,uBAAuB,EACvBC,oBAAoB,QACf,iBAAa;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GAED,0EAA0E,GAC1E,OAAO,MAAMC,0BAA0B,WAAU;AAEjD,OAAO,MAAMC,yBAAyB;IAAC;IAAU;IAAU;CAAS,CAAS;AAG7E,uDAAuD,GAC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E,KAAK,OAAO,OAAOE;IAC9B,MAAM,EAAEf,MAAM,EAAEC,MAAM,EAAEK,WAAW,EAAEJ,IAAI,EAAE,GAAGa,KAAK/B,KAAK;IACxD,OAAO;QACL6B,IAAI;QACJG,OAAO;YACLhB;YACAC;YACAgB,cAAc,CAACf,eAAAA,OAAQ,aAAa,UAAUD,SAAS3B,wBAAwB2B;WAC3EK,cAAc;YAAEA;QAAY,IAAI,CAAC;YACrCJ,IAAI,EAAEA,eAAAA,OAAQ;YACdgB,MAAM;;IAEV;AACF"}
|
package/src/lib/plugin.js
CHANGED
|
@@ -61,11 +61,16 @@ import { REDIRECTS_TRANSFER_KEY } from "./transfer/redirects-transfer-fields.js"
|
|
|
61
61
|
// The client half of the `redirects` transfer resource: how the import
|
|
62
62
|
// wizard and the export dialog name it. The server half is registered from
|
|
63
63
|
// `declarations.console-server.ts`.
|
|
64
|
+
// Squarespace has no redirect export (AGL-4245): the text of its URL
|
|
65
|
+
// Mappings box, pasted or as a .txt file, is read into the import's CSV.
|
|
64
66
|
registerPluginTransferResourceUi(REDIRECTS_TRANSFER_KEY, {
|
|
65
67
|
label: 'Redirects',
|
|
66
68
|
icon: {
|
|
67
69
|
path: mdiSignDirection.path
|
|
68
|
-
}
|
|
70
|
+
},
|
|
71
|
+
readText: async (text)=>// The Squarespace parser loads only when a file is read, not with
|
|
72
|
+
// the plugin on every console screen (check:plugin-budgets).
|
|
73
|
+
(await import("./transfer/squarespace-url-mappings.js")).squarespaceUrlMappingsCsv(text)
|
|
69
74
|
}, {
|
|
70
75
|
pluginId: BUNDLE_ID
|
|
71
76
|
});
|
package/src/lib/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/plugins/redirects/src/lib/plugin.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 * as Aglyn from '@aglyn/aglyn'\nimport { registerPluginTransferResourceUi } from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources'\nimport { mdiSignDirection } from '@aglyn/shared-data-mdi'\nimport { lazy } from 'react'\nimport { BUNDLE_ID } from './constants/bundle-common'\nimport { registerRedirectsRecordRoutes } from './model/redirects-record-routes'\nimport { REDIRECTS_SEARCH_SOURCES } from './model/redirects-search-sources'\nimport { REDIRECTS_TRANSFER_KEY } from './transfer/redirects-transfer-fields'\n\n/** Code-split: the Redirects console page only loads when opened. */\nconst RedirectsConsolePage = lazy(\n () => import('./components/redirects-console-page'),\n)\n\n/**\n * Redirects feature plugin (AGL-395). Console-only — redirects render on\n * published sites through server enforcement (ISR), not a canvas component,\n * so there is no UI bundle to register in the tenant/besigner. The console\n * half declares the Redirects nav + page through the ConsoleExtension\n * registry, gated by the `redirects` entitlement.\n */\nexport function registerRedirectsConsole(): void {\n Aglyn.registerConsoleExtension({\n pluginId: BUNDLE_ID,\n displayName: 'Redirects',\n featureFlag: 'redirects',\n searchSources: REDIRECTS_SEARCH_SOURCES,\n navItems: [\n {\n label: 'Redirects',\n href: '/redirects',\n // Reuse the existing release-flag nav-tab so staff-preview gating is\n // unchanged now that the tab comes from the plugin (AGL-395).\n navTabId: 'nav-tab-redirects',\n icon: { path: mdiSignDirection.path },\n header: {\n title: 'Redirects',\n icon: { path: mdiSignDirection.path },\n docsTopic: 'redirects',\n },\n Component: RedirectsConsolePage,\n },\n ],\n })\n // Where a rule opens, for a surface that names one — the AI plugin's job\n // drawer opening a rule a build changed (AGL-3745).\n registerRedirectsRecordRoutes()\n // The client half of the `redirects` transfer resource: how the import\n // wizard and the export dialog name it. The server half is registered from\n // `declarations.console-server.ts`.\n registerPluginTransferResourceUi(\n REDIRECTS_TRANSFER_KEY,\n { label: 'Redirects', icon: { path: mdiSignDirection.path } },\n { pluginId: BUNDLE_ID },\n )\n}\n"],"names":["Aglyn","registerPluginTransferResourceUi","mdiSignDirection","lazy","BUNDLE_ID","registerRedirectsRecordRoutes","REDIRECTS_SEARCH_SOURCES","REDIRECTS_TRANSFER_KEY","RedirectsConsolePage","registerRedirectsConsole","registerConsoleExtension","pluginId","displayName","featureFlag","searchSources","navItems","label","href","navTabId","icon","path","header","title","docsTopic","Component"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,gCAAgC,QAAQ,wDAAuD;AACxG,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,IAAI,QAAQ,QAAO;AAC5B,SAASC,SAAS,QAAQ,+BAA2B;AACrD,SAASC,6BAA6B,QAAQ,qCAAiC;AAC/E,SAASC,wBAAwB,QAAQ,sCAAkC;AAC3E,SAASC,sBAAsB,QAAQ,0CAAsC;AAE7E,mEAAmE,GACnE,MAAMC,uBAAuBL,KAC3B,IAAM,MAAM,CAAC;AAGf;;;;;;CAMC,GACD,OAAO,SAASM;IACdT,MAAMU,wBAAwB,CAAC;QAC7BC,UAAUP;QACVQ,aAAa;QACbC,aAAa;QACbC,eAAeR;QACfS,UAAU;YACR;gBACEC,OAAO;gBACPC,MAAM;gBACN,qEAAqE;gBACrE,8DAA8D;gBAC9DC,UAAU;gBACVC,MAAM;oBAAEC,MAAMlB,iBAAiBkB,IAAI;gBAAC;gBACpCC,QAAQ;oBACNC,OAAO;oBACPH,MAAM;wBAAEC,MAAMlB,iBAAiBkB,IAAI;oBAAC;oBACpCG,WAAW;gBACb;gBACAC,WAAWhB;YACb;SACD;IACH;IACA,yEAAyE;IACzE,oDAAoD;IACpDH;IACA,uEAAuE;IACvE,2EAA2E;IAC3E,oCAAoC;
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/plugins/redirects/src/lib/plugin.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 * as Aglyn from '@aglyn/aglyn'\nimport { registerPluginTransferResourceUi } from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources'\nimport { mdiSignDirection } from '@aglyn/shared-data-mdi'\nimport { lazy } from 'react'\nimport { BUNDLE_ID } from './constants/bundle-common'\nimport { registerRedirectsRecordRoutes } from './model/redirects-record-routes'\nimport { REDIRECTS_SEARCH_SOURCES } from './model/redirects-search-sources'\nimport { REDIRECTS_TRANSFER_KEY } from './transfer/redirects-transfer-fields'\n\n/** Code-split: the Redirects console page only loads when opened. */\nconst RedirectsConsolePage = lazy(\n () => import('./components/redirects-console-page'),\n)\n\n/**\n * Redirects feature plugin (AGL-395). Console-only — redirects render on\n * published sites through server enforcement (ISR), not a canvas component,\n * so there is no UI bundle to register in the tenant/besigner. The console\n * half declares the Redirects nav + page through the ConsoleExtension\n * registry, gated by the `redirects` entitlement.\n */\nexport function registerRedirectsConsole(): void {\n Aglyn.registerConsoleExtension({\n pluginId: BUNDLE_ID,\n displayName: 'Redirects',\n featureFlag: 'redirects',\n searchSources: REDIRECTS_SEARCH_SOURCES,\n navItems: [\n {\n label: 'Redirects',\n href: '/redirects',\n // Reuse the existing release-flag nav-tab so staff-preview gating is\n // unchanged now that the tab comes from the plugin (AGL-395).\n navTabId: 'nav-tab-redirects',\n icon: { path: mdiSignDirection.path },\n header: {\n title: 'Redirects',\n icon: { path: mdiSignDirection.path },\n docsTopic: 'redirects',\n },\n Component: RedirectsConsolePage,\n },\n ],\n })\n // Where a rule opens, for a surface that names one — the AI plugin's job\n // drawer opening a rule a build changed (AGL-3745).\n registerRedirectsRecordRoutes()\n // The client half of the `redirects` transfer resource: how the import\n // wizard and the export dialog name it. The server half is registered from\n // `declarations.console-server.ts`.\n // Squarespace has no redirect export (AGL-4245): the text of its URL\n // Mappings box, pasted or as a .txt file, is read into the import's CSV.\n registerPluginTransferResourceUi(\n REDIRECTS_TRANSFER_KEY,\n { label: 'Redirects', icon: { path: mdiSignDirection.path }, readText: async (text: string) =>\n // The Squarespace parser loads only when a file is read, not with\n // the plugin on every console screen (check:plugin-budgets).\n (await import('./transfer/squarespace-url-mappings')).squarespaceUrlMappingsCsv(text) },\n { pluginId: BUNDLE_ID },\n )\n}\n"],"names":["Aglyn","registerPluginTransferResourceUi","mdiSignDirection","lazy","BUNDLE_ID","registerRedirectsRecordRoutes","REDIRECTS_SEARCH_SOURCES","REDIRECTS_TRANSFER_KEY","RedirectsConsolePage","registerRedirectsConsole","registerConsoleExtension","pluginId","displayName","featureFlag","searchSources","navItems","label","href","navTabId","icon","path","header","title","docsTopic","Component","readText","text","squarespaceUrlMappingsCsv"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,eAAc;AACrC,SAASC,gCAAgC,QAAQ,wDAAuD;AACxG,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,IAAI,QAAQ,QAAO;AAC5B,SAASC,SAAS,QAAQ,+BAA2B;AACrD,SAASC,6BAA6B,QAAQ,qCAAiC;AAC/E,SAASC,wBAAwB,QAAQ,sCAAkC;AAC3E,SAASC,sBAAsB,QAAQ,0CAAsC;AAE7E,mEAAmE,GACnE,MAAMC,uBAAuBL,KAC3B,IAAM,MAAM,CAAC;AAGf;;;;;;CAMC,GACD,OAAO,SAASM;IACdT,MAAMU,wBAAwB,CAAC;QAC7BC,UAAUP;QACVQ,aAAa;QACbC,aAAa;QACbC,eAAeR;QACfS,UAAU;YACR;gBACEC,OAAO;gBACPC,MAAM;gBACN,qEAAqE;gBACrE,8DAA8D;gBAC9DC,UAAU;gBACVC,MAAM;oBAAEC,MAAMlB,iBAAiBkB,IAAI;gBAAC;gBACpCC,QAAQ;oBACNC,OAAO;oBACPH,MAAM;wBAAEC,MAAMlB,iBAAiBkB,IAAI;oBAAC;oBACpCG,WAAW;gBACb;gBACAC,WAAWhB;YACb;SACD;IACH;IACA,yEAAyE;IACzE,oDAAoD;IACpDH;IACA,uEAAuE;IACvE,2EAA2E;IAC3E,oCAAoC;IACpC,qEAAqE;IACrE,yEAAyE;IACzEJ,iCACEM,wBACA;QAAES,OAAO;QAAaG,MAAM;YAAEC,MAAMlB,iBAAiBkB,IAAI;QAAC;QAAGK,UAAU,OAAOC,OAG1E,AAFA,kEAAkE;YAClE,6DAA6D;YAC5D,CAAA,MAAM,MAAM,CAAC,yCAAqC,EAAGC,yBAAyB,CAACD;IAAM,GAC1F;QAAEf,UAAUP;IAAU;AAE1B"}
|
|
@@ -16,6 +16,17 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import type { ResolvedPluginHostResource } from '@aglyn/aglyn/plugin-manager/plugin-host-resources';
|
|
18
18
|
import type { PluginDraftContext, PluginResourceDraftWriter } from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts';
|
|
19
|
+
/**
|
|
20
|
+
* The `code` on a create's refusal (AGL-4245): a rule already redirects that
|
|
21
|
+
* from-path; a published page answers at it; the destination leads back or
|
|
22
|
+
* into a loop; the plan has no room for another rule.
|
|
23
|
+
*/
|
|
24
|
+
export declare const REDIRECT_AI_REFUSAL_CODES: {
|
|
25
|
+
readonly duplicate: "duplicate";
|
|
26
|
+
readonly livePage: "live-page";
|
|
27
|
+
readonly loop: "loop";
|
|
28
|
+
readonly planLimit: "plan-limit";
|
|
29
|
+
};
|
|
19
30
|
type Firestore = FirebaseFirestore.Firestore;
|
|
20
31
|
type StoredRule = Record<string, unknown>;
|
|
21
32
|
/** The page's refusal for a member without the publishing role. */
|
|
@@ -19,9 +19,65 @@ import { holdsSiteKey, siteKeyRefusal } from "@aglyn/aglyn/app-utils/host-permis
|
|
|
19
19
|
import { countLiveDocuments } from "@aglyn/aglyn/app-utils/live-document-count";
|
|
20
20
|
import { FieldValue, Timestamp } from "firebase-admin/firestore";
|
|
21
21
|
import { checkRedirectDraftContent, readRedirectDraftContent } from "../model/redirect-draft-content.js";
|
|
22
|
-
import { REDIRECT_DEFAULT_PRIORITY, findDuplicateRedirect, isExternalRedirectDestination, normalizeRedirectSource, redirectSourceIsLivePage, walkRedirectChain } from "../model/redirects.js";
|
|
22
|
+
import { REDIRECT_DEFAULT_PRIORITY, findDuplicateRedirect, isExternalRedirectDestination, normalizeRedirectDestination, normalizeRedirectSource, redirectSourceIsLivePage, walkRedirectChain } from "../model/redirects.js";
|
|
23
23
|
import { announcedPath, redirectDeclaration, redirectRuleValues, ruleProblem, storedFields, withDefaults } from "../transfer/redirects-transfer.js";
|
|
24
24
|
import { REDIRECT_FIELD } from "../transfer/redirects-transfer-fields.js";
|
|
25
|
+
/*==========================================
|
|
26
|
+
* A REDIRECT RULE AN AI BUILD CHANGES (AGL-3745)
|
|
27
|
+
*
|
|
28
|
+
* The writer the redirects plugin registers for the `redirect` resource on the
|
|
29
|
+
* core's resource-drafts seam, which the `redirect` build operation
|
|
30
|
+
* (`redirect-ai-capability.ts`) executes. Every rule is this plugin's, made
|
|
31
|
+
* with the functions the redirects page's save and the importer already use:
|
|
32
|
+
*
|
|
33
|
+
* - who: the publishing role on the site (`hostRoleCanPublish`, the axis the
|
|
34
|
+
* Firestore rules gate the collection on), the plan's `redirects` feature,
|
|
35
|
+
* and no lockdown refusing a write to the site, its workspace or the member;
|
|
36
|
+
* - what: the page's normalization and defaults (exact, 302, priority 100,
|
|
37
|
+
* on), the create route's allow-list of fields, and `validateRedirectRule`
|
|
38
|
+
* with the site's own domains, so a lookalike destination, a pattern the
|
|
39
|
+
* matcher cannot run and a path redirected to itself are refused;
|
|
40
|
+
* - against what: the page's duplicate check and chain walk over the site's
|
|
41
|
+
* live rules. A walk that comes back to the rule is the page's loop and is
|
|
42
|
+
* refused; one that leads into a circle other rules make is refused too,
|
|
43
|
+
* which the page only warns about — an AI change never sends visitors into
|
|
44
|
+
* a loop. A from-path the site publishes a page at is refused unless the
|
|
45
|
+
* item says the person asked for it (`replacesLivePage`): the page warns,
|
|
46
|
+
* because replacing a moved page is what a redirect is for, but a build
|
|
47
|
+
* must not take a live page away on its own reading of a request;
|
|
48
|
+
* - how many: a create is counted and written in one transaction against
|
|
49
|
+
* `redirectsPerHost`, as the create route does. An update or a remove
|
|
50
|
+
* takes no slot, so the allowance never refuses one;
|
|
51
|
+
* - provenance: an off-site destination carries the member's uid, the stamp
|
|
52
|
+
* the serve path requires and the page writes; an on-site one has it
|
|
53
|
+
* removed;
|
|
54
|
+
* - afterwards: a created rule gets `createdAt`, `updatedAt`, `createdBy` and
|
|
55
|
+
* the "Created redirect" activity line; every path a change touches is
|
|
56
|
+
* announced to the site cache, as the page announces a save.
|
|
57
|
+
*
|
|
58
|
+
* A redirect has no draft state: the console writes a rule live, and so does
|
|
59
|
+
* this. The build's plan card is where the person agrees to it, and the job
|
|
60
|
+
* reports the change as live (the capability's `live`). A remove is the page's
|
|
61
|
+
* Delete: the rule is marked deleted and off.
|
|
62
|
+
*
|
|
63
|
+
* Asked again for the same change, it answers with what it already did: a
|
|
64
|
+
* create finds the rule written under the request's id, an update whose values
|
|
65
|
+
* already hold changes nothing, and a remove of a rule already deleted is done.
|
|
66
|
+
*
|
|
67
|
+
* A create may ask to `followChain` (AGL-4245, a site import's redirects): a
|
|
68
|
+
* destination the site's rules already send elsewhere is replaced by the
|
|
69
|
+
* on-site address the chain ends at, so the new rule is one hop. A refusal
|
|
70
|
+
* a caller may act on carries its `code` (`REDIRECT_AI_REFUSAL_CODES`).
|
|
71
|
+
*=========================================*/ /**
|
|
72
|
+
* The `code` on a create's refusal (AGL-4245): a rule already redirects that
|
|
73
|
+
* from-path; a published page answers at it; the destination leads back or
|
|
74
|
+
* into a loop; the plan has no room for another rule.
|
|
75
|
+
*/ export const REDIRECT_AI_REFUSAL_CODES = {
|
|
76
|
+
duplicate: 'duplicate',
|
|
77
|
+
livePage: 'live-page',
|
|
78
|
+
loop: 'loop',
|
|
79
|
+
planLimit: 'plan-limit'
|
|
80
|
+
};
|
|
25
81
|
/** The page's refusal for a member without the publishing role. */ /** Names "Publish site content" (`site.publish`, AGL-4047), never a role. */ export const REDIRECT_AI_ROLE_REFUSAL = siteKeyRefusal('site.publish');
|
|
26
82
|
/** The page's refusal for a plan without redirects. */ export const REDIRECT_AI_PLAN_REFUSAL = 'URL redirects require a Starter plan — see Billing to upgrade';
|
|
27
83
|
/** What a member is told while a lockdown refuses writes to the site. */ export const REDIRECT_AI_LOCKED_REFUSAL = 'This site is not accepting changes right now.';
|
|
@@ -110,12 +166,38 @@ export function createRedirectAiWriter(deps) {
|
|
|
110
166
|
});
|
|
111
167
|
}
|
|
112
168
|
/** Why the rule a change leaves cannot be saved among the site's live rules, or `null`. */ function setProblem(rows, rule) {
|
|
113
|
-
if (findDuplicateRedirect(rows, rule))
|
|
169
|
+
if (findDuplicateRedirect(rows, rule)) {
|
|
170
|
+
return {
|
|
171
|
+
error: `A rule for ${rule.source} already exists`,
|
|
172
|
+
code: REDIRECT_AI_REFUSAL_CODES.duplicate
|
|
173
|
+
};
|
|
174
|
+
}
|
|
114
175
|
const walk = walkRedirectChain(rows, rule);
|
|
115
|
-
if (walk.loop)
|
|
116
|
-
|
|
176
|
+
if (walk.loop) {
|
|
177
|
+
return {
|
|
178
|
+
error: 'That destination chains back to this rule — a redirect loop',
|
|
179
|
+
code: REDIRECT_AI_REFUSAL_CODES.loop
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (walk.cycle) {
|
|
183
|
+
return {
|
|
184
|
+
error: 'That destination leads into a redirect loop other rules already make',
|
|
185
|
+
code: REDIRECT_AI_REFUSAL_CODES.loop
|
|
186
|
+
};
|
|
187
|
+
}
|
|
117
188
|
return null;
|
|
118
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Where a chain from `destination` ends on the site (AGL-4245): the last
|
|
192
|
+
* on-site address the rules pass it through, or `destination` itself when
|
|
193
|
+
* no rule redirects it. An off-site hop ends the walk before it.
|
|
194
|
+
*/ function chainEnd(rows, rule) {
|
|
195
|
+
var _onSite_;
|
|
196
|
+
const walk = walkRedirectChain(rows, rule);
|
|
197
|
+
if (walk.loop || walk.cycle) return rule.destination;
|
|
198
|
+
const onSite = walk.hops.filter((hop)=>hop.startsWith('/') && !hop.startsWith('//'));
|
|
199
|
+
return (_onSite_ = onSite[onSite.length - 1]) != null ? _onSite_ : rule.destination;
|
|
200
|
+
}
|
|
119
201
|
function livePageProblem(host, source, kind, asked) {
|
|
120
202
|
if (asked || kind === 'regex' || !redirectSourceIsLivePage(host['screens'], source)) {
|
|
121
203
|
return null;
|
|
@@ -128,11 +210,13 @@ export function createRedirectAiWriter(deps) {
|
|
|
128
210
|
];
|
|
129
211
|
if (unique.length && deps.announcePaths) await deps.announcePaths(hostId, unique).catch(()=>undefined);
|
|
130
212
|
}
|
|
131
|
-
const refuse = (status, error)=>({
|
|
213
|
+
const refuse = (status, error, code)=>_extends({
|
|
132
214
|
ok: false,
|
|
133
215
|
status,
|
|
134
216
|
error
|
|
135
|
-
}
|
|
217
|
+
}, code ? {
|
|
218
|
+
code
|
|
219
|
+
} : {});
|
|
136
220
|
return {
|
|
137
221
|
refusal: async (context)=>refusalFor(await hostRef(context.hostId).get(), context),
|
|
138
222
|
check: (content)=>checkRedirectDraftContent(content),
|
|
@@ -189,14 +273,36 @@ export function createRedirectAiWriter(deps) {
|
|
|
189
273
|
const source = String(fields['source']);
|
|
190
274
|
const kind = String((_fields_kind1 = fields['kind']) != null ? _fields_kind1 : 'exact');
|
|
191
275
|
const shadow = livePageProblem(host, source, kind, change.replacesLivePage);
|
|
192
|
-
if (shadow) return refuse(409, shadow);
|
|
276
|
+
if (shadow) return refuse(409, shadow, REDIRECT_AI_REFUSAL_CODES.livePage);
|
|
277
|
+
if (findDuplicateRedirect(rows, {
|
|
278
|
+
$id: request.id,
|
|
279
|
+
source,
|
|
280
|
+
kind
|
|
281
|
+
})) {
|
|
282
|
+
return refuse(409, `A rule for ${source} already exists`, REDIRECT_AI_REFUSAL_CODES.duplicate);
|
|
283
|
+
}
|
|
284
|
+
if (change.followChain) {
|
|
285
|
+
const end = chainEnd(rows, {
|
|
286
|
+
$id: request.id,
|
|
287
|
+
source,
|
|
288
|
+
destination: String(fields['destination'])
|
|
289
|
+
});
|
|
290
|
+
if (end !== fields['destination']) {
|
|
291
|
+
var _normalizeRedirectDestination;
|
|
292
|
+
// The chain's end, held to the page's rules again as the new destination.
|
|
293
|
+
const followed = ruleProblem(_extends({}, rule, {
|
|
294
|
+
destination: end
|
|
295
|
+
}), host);
|
|
296
|
+
if (!followed) fields['destination'] = (_normalizeRedirectDestination = normalizeRedirectDestination(end)) != null ? _normalizeRedirectDestination : end;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
193
299
|
const clash = setProblem(rows, {
|
|
194
300
|
$id: request.id,
|
|
195
301
|
source,
|
|
196
302
|
destination: String(fields['destination']),
|
|
197
303
|
kind
|
|
198
304
|
});
|
|
199
|
-
if (clash) return refuse(409, clash);
|
|
305
|
+
if (clash) return refuse(409, clash.error, clash.code);
|
|
200
306
|
const stamp = stampFor(fields['destination']);
|
|
201
307
|
const written = _extends({}, fields, stamp ? {
|
|
202
308
|
[approvalField]: stamp
|
|
@@ -224,7 +330,7 @@ export function createRedirectAiWriter(deps) {
|
|
|
224
330
|
}));
|
|
225
331
|
return {};
|
|
226
332
|
});
|
|
227
|
-
if (outcome.refusal) return refuse(403, outcome.refusal);
|
|
333
|
+
if (outcome.refusal) return refuse(403, outcome.refusal, REDIRECT_AI_REFUSAL_CODES.planLimit);
|
|
228
334
|
if (outcome.existed) return _extends({
|
|
229
335
|
ok: true,
|
|
230
336
|
replayed: true
|
|
@@ -292,7 +398,7 @@ export function createRedirectAiWriter(deps) {
|
|
|
292
398
|
const kind = String((_fields_kind = fields['kind']) != null ? _fields_kind : 'exact');
|
|
293
399
|
if (source !== current['source']) {
|
|
294
400
|
const shadow = livePageProblem(host, source, kind, change.replacesLivePage);
|
|
295
|
-
if (shadow) return refuse(409, shadow);
|
|
401
|
+
if (shadow) return refuse(409, shadow, REDIRECT_AI_REFUSAL_CODES.livePage);
|
|
296
402
|
}
|
|
297
403
|
const clash = setProblem(rows, {
|
|
298
404
|
$id: target.id,
|
|
@@ -300,7 +406,7 @@ export function createRedirectAiWriter(deps) {
|
|
|
300
406
|
destination: String(fields['destination']),
|
|
301
407
|
kind
|
|
302
408
|
});
|
|
303
|
-
if (clash) return refuse(409, clash);
|
|
409
|
+
if (clash) return refuse(409, clash.error, clash.code);
|
|
304
410
|
const stamp = stampFor(fields['destination']);
|
|
305
411
|
const unchanged = Object.entries(fields).every(([key, value])=>current[key] === value) && ((_current_approvalField = current[approvalField]) != null ? _current_approvalField : null) === stamp;
|
|
306
412
|
const after = _extends({}, target.data, fields, stamp ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/redirects/src/lib/server/redirect-ai-writer.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 { checkEntitlement, checkQuota } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { holdsSiteKey, siteKeyRefusal } from '@aglyn/aglyn/app-utils/host-permissions'\nimport { countLiveDocuments } from '@aglyn/aglyn/app-utils/live-document-count'\nimport type { ResolvedPluginHostResource } from '@aglyn/aglyn/plugin-manager/plugin-host-resources'\nimport type {\n PluginDraftContext,\n PluginDraftRecord,\n PluginDraftRefusal,\n PluginDraftWrite,\n PluginResourceDraftWriter,\n} from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts'\nimport { FieldValue, Timestamp } from 'firebase-admin/firestore'\nimport {\n checkRedirectDraftContent,\n readRedirectDraftContent,\n type RedirectDraftContent,\n} from '../model/redirect-draft-content'\nimport {\n REDIRECT_DEFAULT_PRIORITY,\n findDuplicateRedirect,\n isExternalRedirectDestination,\n normalizeRedirectSource,\n redirectSourceIsLivePage,\n walkRedirectChain,\n type RedirectRuleRow,\n} from '../model/redirects'\nimport {\n announcedPath,\n redirectDeclaration,\n redirectRuleValues,\n ruleProblem,\n storedFields,\n withDefaults,\n} from '../transfer/redirects-transfer'\nimport { REDIRECT_FIELD } from '../transfer/redirects-transfer-fields'\n\n/*==========================================\n * A REDIRECT RULE AN AI BUILD CHANGES (AGL-3745)\n *\n * The writer the redirects plugin registers for the `redirect` resource on the\n * core's resource-drafts seam, which the `redirect` build operation\n * (`redirect-ai-capability.ts`) executes. Every rule is this plugin's, made\n * with the functions the redirects page's save and the importer already use:\n *\n * - who: the publishing role on the site (`hostRoleCanPublish`, the axis the\n * Firestore rules gate the collection on), the plan's `redirects` feature,\n * and no lockdown refusing a write to the site, its workspace or the member;\n * - what: the page's normalization and defaults (exact, 302, priority 100,\n * on), the create route's allow-list of fields, and `validateRedirectRule`\n * with the site's own domains, so a lookalike destination, a pattern the\n * matcher cannot run and a path redirected to itself are refused;\n * - against what: the page's duplicate check and chain walk over the site's\n * live rules. A walk that comes back to the rule is the page's loop and is\n * refused; one that leads into a circle other rules make is refused too,\n * which the page only warns about — an AI change never sends visitors into\n * a loop. A from-path the site publishes a page at is refused unless the\n * item says the person asked for it (`replacesLivePage`): the page warns,\n * because replacing a moved page is what a redirect is for, but a build\n * must not take a live page away on its own reading of a request;\n * - how many: a create is counted and written in one transaction against\n * `redirectsPerHost`, as the create route does. An update or a remove\n * takes no slot, so the allowance never refuses one;\n * - provenance: an off-site destination carries the member's uid, the stamp\n * the serve path requires and the page writes; an on-site one has it\n * removed;\n * - afterwards: a created rule gets `createdAt`, `updatedAt`, `createdBy` and\n * the \"Created redirect\" activity line; every path a change touches is\n * announced to the site cache, as the page announces a save.\n *\n * A redirect has no draft state: the console writes a rule live, and so does\n * this. The build's plan card is where the person agrees to it, and the job\n * reports the change as live (the capability's `live`). A remove is the page's\n * Delete: the rule is marked deleted and off.\n *\n * Asked again for the same change, it answers with what it already did: a\n * create finds the rule written under the request's id, an update whose values\n * already hold changes nothing, and a remove of a rule already deleted is done.\n *=========================================*/\n\ntype Firestore = FirebaseFirestore.Firestore\ntype StoredRule = Record<string, unknown>\n\n/** The page's refusal for a member without the publishing role. */\n/** Names \"Publish site content\" (`site.publish`, AGL-4047), never a role. */\nexport const REDIRECT_AI_ROLE_REFUSAL = siteKeyRefusal('site.publish')\n/** The page's refusal for a plan without redirects. */\nexport const REDIRECT_AI_PLAN_REFUSAL = 'URL redirects require a Starter plan — see Billing to upgrade'\n/** What a member is told while a lockdown refuses writes to the site. */\nexport const REDIRECT_AI_LOCKED_REFUSAL = 'This site is not accepting changes right now.'\n\n/** The create route's refusal at the plan's allowance. */\nexport function redirectAiLimitRefusal(limit: number): string {\n return `Your plan includes ${limit} redirects — upgrade in Billing for more`\n}\n\n/** Whether a lockdown refuses this member's write to this site; `true` refuses. */\nexport type RedirectAiLockdownCheck = (input: {\n uid: string\n org: PluginDraftContext['org']\n host: StoredRule\n}) => Promise<boolean>\n\nexport interface RedirectAiWriterDeps {\n firestore: () => Firestore\n lockdown: RedirectAiLockdownCheck\n /** The `redirect` kind's declaration; the create route's otherwise. */\n declaration?: () => ResolvedPluginHostResource\n /** Drops the site's cached pages at these paths, best effort. */\n announcePaths?(hostId: string, paths: readonly string[]): Promise<void>\n /** Writes the site activity line for a created rule, best effort. */\n logCreated?(hostId: string, actorUid: string, ruleId: string, declared: ResolvedPluginHostResource): Promise<void>\n}\n\n/** What a caller is told about a rule: what it is, and that it is live. */\nfunction factsOf(action: RedirectDraftContent['action'], data: StoredRule): Record<string, unknown> {\n const values = redirectRuleValues('', data)\n return {\n action,\n source: values['source'],\n destination: values['destination'],\n kind: values['kind'],\n statusCode: values['statusCode'],\n priority: values['priority'],\n enabled: action === 'remove' ? false : values['enabled'],\n removed: action === 'remove',\n live: true,\n }\n}\n\nfunction recordOf(id: string, action: RedirectDraftContent['action'], data: StoredRule): PluginDraftRecord {\n return {\n id,\n name: `${String(data['source'] ?? '')} → ${String(data['destination'] ?? '')}`,\n versionId: null,\n facts: factsOf(action, data),\n }\n}\n\nfunction isLive(data: StoredRule | undefined): data is StoredRule {\n return Boolean(data) && !data?.['deletedAt']\n}\n\n/** A from-path as a rule of `kind` stores it: a pattern trimmed, a path normalized. */\nfunction storedSourceOf(kind: string, source: string): string | null {\n return kind === 'regex' ? source.trim() || null : normalizeRedirectSource(source)\n}\n\nexport function createRedirectAiWriter(deps: RedirectAiWriterDeps): PluginResourceDraftWriter {\n const declaration = deps.declaration ?? redirectDeclaration\n const hostRef = (hostId: string) => deps.firestore().collection('hosts').doc(hostId)\n const rulesOf = (hostId: string) => hostRef(hostId).collection('redirects')\n\n async function refusalFor(\n host: FirebaseFirestore.DocumentSnapshot,\n context: Pick<PluginDraftContext, 'uid' | 'org'>,\n ): Promise<PluginDraftRefusal | null> {\n if (!host.exists) return { status: 404, error: 'Unknown site' }\n const data = (host.data() ?? {}) as StoredRule\n if (!holdsSiteKey(data, context.uid, 'site.publish')) return { status: 403, error: REDIRECT_AI_ROLE_REFUSAL }\n const declared = declaration()\n if (declared.entitlement && !checkEntitlement((context.org ?? {}) as never, declared.entitlement)) {\n return { status: 403, error: REDIRECT_AI_PLAN_REFUSAL }\n }\n if (await deps.lockdown({ uid: context.uid, org: context.org, host: data })) {\n return { status: 403, error: REDIRECT_AI_LOCKED_REFUSAL }\n }\n return null\n }\n\n /** Every rule document of the site, soft-deleted ones included. */\n async function readAllRules(hostId: string): Promise<Array<{ id: string; data: StoredRule }>> {\n const snapshot = await rulesOf(hostId).get()\n return snapshot.docs.map((doc) => ({ id: doc.id, data: (doc.data() ?? {}) as StoredRule }))\n }\n\n /** The live rules at a from-path, of `kind` when it is given. */\n function rulesAt(\n all: ReadonlyArray<{ id: string; data: StoredRule }>,\n source: string,\n kind: string | undefined,\n ): Array<{ id: string; data: StoredRule }> {\n return all.filter(({ data }) => {\n const ruleKind = typeof data['kind'] === 'string' && data['kind'] ? (data['kind'] as string) : 'exact'\n if (kind && ruleKind !== kind) return false\n return data['source'] === storedSourceOf(ruleKind, source)\n })\n }\n\n /** Why the rule a change leaves cannot be saved among the site's live rules, or `null`. */\n function setProblem(\n rows: readonly RedirectRuleRow[],\n rule: { $id: string; source: string; destination: string; kind: string },\n ): string | null {\n if (findDuplicateRedirect(rows, rule)) return `A rule for ${rule.source} already exists`\n const walk = walkRedirectChain(rows, rule)\n if (walk.loop) return 'That destination chains back to this rule — a redirect loop'\n if (walk.cycle) return 'That destination leads into a redirect loop other rules already make'\n return null\n }\n\n function livePageProblem(host: StoredRule, source: string, kind: string, asked: boolean | undefined): string | null {\n if (asked || kind === 'regex' || !redirectSourceIsLivePage(host['screens'] as Record<string, unknown>, source)) {\n return null\n }\n return `${source} is a published page, and a redirect there would take its place. Redirect it only when the person asks for that page to send visitors elsewhere.`\n }\n\n async function announce(hostId: string, paths: Array<string | null>): Promise<void> {\n const unique = [...new Set(paths.filter((path): path is string => Boolean(path)))]\n if (unique.length && deps.announcePaths) await deps.announcePaths(hostId, unique).catch(() => undefined)\n }\n\n const refuse = (status: PluginDraftRefusal['status'], error: string): PluginDraftWrite => ({ ok: false, status, error })\n\n return {\n refusal: async (context) => refusalFor(await hostRef(context.hostId).get(), context),\n\n check: (content) => checkRedirectDraftContent(content),\n\n read: async ({ hostId, id }) => {\n const snapshot = await rulesOf(hostId).doc(id).get()\n if (!snapshot.exists) return null\n const data = (snapshot.data() ?? {}) as StoredRule\n return recordOf(id, isLive(data) ? 'create' : 'remove', data)\n },\n\n write: async (request): Promise<PluginDraftWrite> => {\n const read = readRedirectDraftContent(request.content)\n if (read.ok === false) return refuse(400, read.problems[0] as string)\n const change = read.value\n const hostSnapshot = await hostRef(request.hostId).get()\n const refusal = await refusalFor(hostSnapshot, request)\n if (refusal) return { ok: false, ...refusal }\n const host = (hostSnapshot.data() ?? {}) as StoredRule\n const declared = declaration()\n const approvalField = declared.externalDestination?.approvedByField ?? REDIRECT_FIELD.approvedBy\n const stampFor = (destination: unknown): string | null =>\n declared.externalDestination && isExternalRedirectDestination(String(destination ?? '')) ? request.uid : null\n const at = Timestamp.fromDate(request.now)\n const all = await readAllRules(request.hostId)\n const live = all.filter(({ data }) => isLive(data))\n const rows: RedirectRuleRow[] = live.map(({ id, data }) => ({\n $id: id,\n source: data['source'] as string,\n destination: data['destination'] as string,\n kind: data['kind'] as string,\n }))\n\n if (change.action === 'create') {\n const ref = rulesOf(request.hostId).doc(request.id)\n const before = all.find((one) => one.id === request.id)\n if (before) return { ok: true, replayed: true, ...recordOf(request.id, 'create', before.data) }\n const rule = withDefaults({\n source: change.source,\n destination: change.destination,\n kind: change.kind ?? 'exact',\n statusCode: change.statusCode ?? 302,\n priority: change.priority ?? REDIRECT_DEFAULT_PRIORITY,\n enabled: change.enabled ?? true,\n })\n const problem = ruleProblem(rule, host)\n if (problem) return refuse(400, problem.detail)\n const fields = storedFields(rule, declared.fields)\n const source = String(fields['source'])\n const kind = String(fields['kind'] ?? 'exact')\n const shadow = livePageProblem(host, source, kind, change.replacesLivePage)\n if (shadow) return refuse(409, shadow)\n const clash = setProblem(rows, { $id: request.id, source, destination: String(fields['destination']), kind })\n if (clash) return refuse(409, clash)\n const stamp = stampFor(fields['destination'])\n const written = { ...fields, ...(stamp ? { [approvalField]: stamp } : {}) }\n const db = deps.firestore()\n const outcome = await db.runTransaction(async (tx): Promise<{ refusal?: string; existed?: StoredRule }> => {\n const existing = await tx.get(ref)\n if (existing.exists) return { existed: (existing.data() ?? {}) as StoredRule }\n if (declared.quotaKey) {\n // Live rules only, as the create route counts: a deleted rule frees its slot (AGL-3918).\n const used = await countLiveDocuments(rulesOf(request.hostId), (aggregate) => tx.get(aggregate))\n const quota = checkQuota((request.org ?? {}) as never, declared.quotaKey as never, Number(used) || 0)\n if (!quota.allowed) return { refusal: redirectAiLimitRefusal(quota.limit) }\n }\n tx.create(ref, { ...written, createdAt: at, updatedAt: at, createdBy: request.uid })\n return {}\n })\n if (outcome.refusal) return refuse(403, outcome.refusal)\n if (outcome.existed) return { ok: true, replayed: true, ...recordOf(request.id, 'create', outcome.existed) }\n if (deps.logCreated) {\n await deps.logCreated(request.hostId, request.uid, ref.id, declared).catch(() => undefined)\n }\n await announce(request.hostId, [announcedPath(fields)])\n return { ok: true, replayed: false, ...recordOf(ref.id, 'create', written) }\n }\n\n // An update or a remove names a rule the site has.\n const found = rulesAt(live, change.source, change.kind)\n if (found.length > 1) {\n return refuse(\n 409,\n `The site has more than one redirect at ${change.source}; say which match mode (exact, prefix or regex) to change`,\n )\n }\n const target = found[0]\n if (!target) {\n if (change.action === 'remove') {\n const gone = rulesAt(all, change.source, change.kind)[0]\n if (gone) return { ok: true, replayed: true, ...recordOf(gone.id, 'remove', gone.data) }\n }\n return refuse(404, `The site has no redirect from ${change.source}`)\n }\n const ref = rulesOf(request.hostId).doc(target.id)\n\n if (change.action === 'remove') {\n // The page's Delete: marked deleted and off, so the serve path drops it.\n await ref.set({ deletedAt: at, enabled: false }, { merge: true })\n await announce(request.hostId, [announcedPath(target.data as { kind?: string; source?: string })])\n return { ok: true, replayed: false, ...recordOf(target.id, 'remove', target.data) }\n }\n\n const current = redirectRuleValues(target.id, target.data)\n const rule = withDefaults({\n ...current,\n ...(change.newSource !== undefined ? { source: change.newSource } : {}),\n ...(change.destination !== undefined ? { destination: change.destination } : {}),\n ...(change.statusCode !== undefined ? { statusCode: change.statusCode } : {}),\n ...(change.priority !== undefined ? { priority: change.priority } : {}),\n ...(change.enabled !== undefined ? { enabled: change.enabled } : {}),\n })\n const problem = ruleProblem(rule, host)\n if (problem) return refuse(400, problem.detail)\n const fields = storedFields(rule, declared.fields)\n const source = String(fields['source'])\n const kind = String(fields['kind'] ?? 'exact')\n if (source !== current['source']) {\n const shadow = livePageProblem(host, source, kind, change.replacesLivePage)\n if (shadow) return refuse(409, shadow)\n }\n const clash = setProblem(rows, { $id: target.id, source, destination: String(fields['destination']), kind })\n if (clash) return refuse(409, clash)\n const stamp = stampFor(fields['destination'])\n const unchanged =\n Object.entries(fields).every(([key, value]) => current[key] === value) &&\n (current[approvalField] ?? null) === stamp\n const after = { ...target.data, ...fields, ...(stamp ? { [approvalField]: stamp } : {}) }\n if (unchanged) return { ok: true, replayed: true, ...recordOf(target.id, 'update', after) }\n // The page's edit: every field the form owns, the stamp set or removed,\n // `updatedAt`, merged so `lastHitAt` stays.\n await ref.set({ ...fields, [approvalField]: stamp ?? FieldValue.delete(), updatedAt: at }, { merge: true })\n await announce(request.hostId, [announcedPath(fields), announcedPath(target.data as { kind?: string; source?: string })])\n return { ok: true, replayed: false, ...recordOf(target.id, 'update', after) }\n },\n }\n}\n"],"names":["checkEntitlement","checkQuota","holdsSiteKey","siteKeyRefusal","countLiveDocuments","FieldValue","Timestamp","checkRedirectDraftContent","readRedirectDraftContent","REDIRECT_DEFAULT_PRIORITY","findDuplicateRedirect","isExternalRedirectDestination","normalizeRedirectSource","redirectSourceIsLivePage","walkRedirectChain","announcedPath","redirectDeclaration","redirectRuleValues","ruleProblem","storedFields","withDefaults","REDIRECT_FIELD","REDIRECT_AI_ROLE_REFUSAL","REDIRECT_AI_PLAN_REFUSAL","REDIRECT_AI_LOCKED_REFUSAL","redirectAiLimitRefusal","limit","factsOf","action","data","values","source","destination","kind","statusCode","priority","enabled","removed","live","recordOf","id","name","String","versionId","facts","isLive","Boolean","storedSourceOf","trim","createRedirectAiWriter","deps","declaration","hostRef","hostId","firestore","collection","doc","rulesOf","refusalFor","host","context","exists","status","error","uid","declared","entitlement","org","lockdown","readAllRules","snapshot","get","docs","map","rulesAt","all","filter","ruleKind","setProblem","rows","rule","walk","loop","cycle","livePageProblem","asked","announce","paths","unique","Set","path","length","announcePaths","catch","undefined","refuse","ok","refusal","check","content","read","write","request","hostSnapshot","fields","current","problems","change","value","approvalField","externalDestination","approvedByField","approvedBy","stampFor","at","fromDate","now","$id","ref","before","find","one","replayed","problem","detail","shadow","replacesLivePage","clash","stamp","written","db","outcome","runTransaction","tx","existing","existed","quotaKey","used","aggregate","quota","Number","allowed","create","createdAt","updatedAt","createdBy","logCreated","found","target","gone","set","deletedAt","merge","newSource","unchanged","Object","entries","every","key","after","delete"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,2CAA0C;AACvF,SAASC,YAAY,EAAEC,cAAc,QAAQ,0CAAyC;AACtF,SAASC,kBAAkB,QAAQ,6CAA4C;AAS/E,SAASC,UAAU,EAAEC,SAAS,QAAQ,2BAA0B;AAChE,SACEC,yBAAyB,EACzBC,wBAAwB,QAEnB,qCAAiC;AACxC,SACEC,yBAAyB,EACzBC,qBAAqB,EACrBC,6BAA6B,EAC7BC,uBAAuB,EACvBC,wBAAwB,EACxBC,iBAAiB,QAEZ,wBAAoB;AAC3B,SACEC,aAAa,EACbC,mBAAmB,EACnBC,kBAAkB,EAClBC,WAAW,EACXC,YAAY,EACZC,YAAY,QACP,oCAAgC;AACvC,SAASC,cAAc,QAAQ,2CAAuC;AAgDtE,iEAAiE,GACjE,2EAA2E,GAC3E,OAAO,MAAMC,2BAA2BnB,eAAe,gBAAe;AACtE,qDAAqD,GACrD,OAAO,MAAMoB,2BAA2B,gEAA+D;AACvG,uEAAuE,GACvE,OAAO,MAAMC,6BAA6B,gDAA+C;AAEzF,wDAAwD,GACxD,OAAO,SAASC,uBAAuBC,KAAa;IAClD,OAAO,CAAC,mBAAmB,EAAEA,MA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MAAM,CAAC,cAAc;gBAAGvE;YAAK;YAC1G,IAAI8F,OAAO,OAAOhC,OAAO,KAAKgC;YAC9B,MAAMC,QAAQf,SAAST,MAAM,CAAC,cAAc;YAC5C,MAAMkD,YACJC,OAAOC,OAAO,CAACpD,QAAQqD,KAAK,CAAC,CAAC,CAACC,KAAKlD,MAAM,GAAKH,OAAO,CAACqD,IAAI,KAAKlD,UAChE,EAACH,yBAAAA,OAAO,CAACI,cAAc,YAAtBJ,yBAA0B,UAAUuB;YACvC,MAAM+B,QAAQ,aAAKX,OAAOvH,IAAI,EAAK2E,QAAYwB,QAAQ;gBAAE,CAACnB,cAAc,EAAEmB;YAAM,IAAI,CAAC;YACrF,IAAI0B,WAAW,OAAO;gBAAE1D,IAAI;gBAAM0B,UAAU;eAASnF,SAAS6G,OAAO5G,EAAE,EAAE,UAAUuH;YACnF,wEAAwE;YACxE,4CAA4C;YAC5C,MAAMzC,IAAIgC,GAAG,CAAC,aAAK9C;gBAAQ,CAACK,cAAc,EAAEmB,gBAAAA,QAAS3H,WAAW2J,MAAM;gBAAIhB,WAAW9B;gBAAM;gBAAEsC,OAAO;YAAK;YACzG,MAAMlE,SAASgB,QAAQjD,MAAM,EAAE;gBAACtC,cAAcyF;gBAASzF,cAAcqI,OAAOvH,IAAI;aAAwC;YACxH,OAAO;gBAAEmE,IAAI;gBAAM0B,UAAU;eAAUnF,SAAS6G,OAAO5G,EAAE,EAAE,UAAUuH;QACvE;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/redirects/src/lib/server/redirect-ai-writer.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 { checkEntitlement, checkQuota } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { holdsSiteKey, siteKeyRefusal } from '@aglyn/aglyn/app-utils/host-permissions'\nimport { countLiveDocuments } from '@aglyn/aglyn/app-utils/live-document-count'\nimport type { ResolvedPluginHostResource } from '@aglyn/aglyn/plugin-manager/plugin-host-resources'\nimport type {\n PluginDraftContext,\n PluginDraftRecord,\n PluginDraftRefusal,\n PluginDraftWrite,\n PluginResourceDraftWriter,\n} from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts'\nimport { FieldValue, Timestamp } from 'firebase-admin/firestore'\nimport {\n checkRedirectDraftContent,\n readRedirectDraftContent,\n type RedirectDraftContent,\n} from '../model/redirect-draft-content'\nimport {\n REDIRECT_DEFAULT_PRIORITY,\n findDuplicateRedirect,\n isExternalRedirectDestination,\n normalizeRedirectDestination,\n normalizeRedirectSource,\n redirectSourceIsLivePage,\n walkRedirectChain,\n type RedirectRuleRow,\n} from '../model/redirects'\nimport {\n announcedPath,\n redirectDeclaration,\n redirectRuleValues,\n ruleProblem,\n storedFields,\n withDefaults,\n} from '../transfer/redirects-transfer'\nimport { REDIRECT_FIELD } from '../transfer/redirects-transfer-fields'\n\n/*==========================================\n * A REDIRECT RULE AN AI BUILD CHANGES (AGL-3745)\n *\n * The writer the redirects plugin registers for the `redirect` resource on the\n * core's resource-drafts seam, which the `redirect` build operation\n * (`redirect-ai-capability.ts`) executes. Every rule is this plugin's, made\n * with the functions the redirects page's save and the importer already use:\n *\n * - who: the publishing role on the site (`hostRoleCanPublish`, the axis the\n * Firestore rules gate the collection on), the plan's `redirects` feature,\n * and no lockdown refusing a write to the site, its workspace or the member;\n * - what: the page's normalization and defaults (exact, 302, priority 100,\n * on), the create route's allow-list of fields, and `validateRedirectRule`\n * with the site's own domains, so a lookalike destination, a pattern the\n * matcher cannot run and a path redirected to itself are refused;\n * - against what: the page's duplicate check and chain walk over the site's\n * live rules. A walk that comes back to the rule is the page's loop and is\n * refused; one that leads into a circle other rules make is refused too,\n * which the page only warns about — an AI change never sends visitors into\n * a loop. A from-path the site publishes a page at is refused unless the\n * item says the person asked for it (`replacesLivePage`): the page warns,\n * because replacing a moved page is what a redirect is for, but a build\n * must not take a live page away on its own reading of a request;\n * - how many: a create is counted and written in one transaction against\n * `redirectsPerHost`, as the create route does. An update or a remove\n * takes no slot, so the allowance never refuses one;\n * - provenance: an off-site destination carries the member's uid, the stamp\n * the serve path requires and the page writes; an on-site one has it\n * removed;\n * - afterwards: a created rule gets `createdAt`, `updatedAt`, `createdBy` and\n * the \"Created redirect\" activity line; every path a change touches is\n * announced to the site cache, as the page announces a save.\n *\n * A redirect has no draft state: the console writes a rule live, and so does\n * this. The build's plan card is where the person agrees to it, and the job\n * reports the change as live (the capability's `live`). A remove is the page's\n * Delete: the rule is marked deleted and off.\n *\n * Asked again for the same change, it answers with what it already did: a\n * create finds the rule written under the request's id, an update whose values\n * already hold changes nothing, and a remove of a rule already deleted is done.\n *\n * A create may ask to `followChain` (AGL-4245, a site import's redirects): a\n * destination the site's rules already send elsewhere is replaced by the\n * on-site address the chain ends at, so the new rule is one hop. A refusal\n * a caller may act on carries its `code` (`REDIRECT_AI_REFUSAL_CODES`).\n *=========================================*/\n\n/**\n * The `code` on a create's refusal (AGL-4245): a rule already redirects that\n * from-path; a published page answers at it; the destination leads back or\n * into a loop; the plan has no room for another rule.\n */\nexport const REDIRECT_AI_REFUSAL_CODES = {\n duplicate: 'duplicate',\n livePage: 'live-page',\n loop: 'loop',\n planLimit: 'plan-limit',\n} as const\n\ntype Firestore = FirebaseFirestore.Firestore\ntype StoredRule = Record<string, unknown>\n\n/** The page's refusal for a member without the publishing role. */\n/** Names \"Publish site content\" (`site.publish`, AGL-4047), never a role. */\nexport const REDIRECT_AI_ROLE_REFUSAL = siteKeyRefusal('site.publish')\n/** The page's refusal for a plan without redirects. */\nexport const REDIRECT_AI_PLAN_REFUSAL = 'URL redirects require a Starter plan — see Billing to upgrade'\n/** What a member is told while a lockdown refuses writes to the site. */\nexport const REDIRECT_AI_LOCKED_REFUSAL = 'This site is not accepting changes right now.'\n\n/** The create route's refusal at the plan's allowance. */\nexport function redirectAiLimitRefusal(limit: number): string {\n return `Your plan includes ${limit} redirects — upgrade in Billing for more`\n}\n\n/** Whether a lockdown refuses this member's write to this site; `true` refuses. */\nexport type RedirectAiLockdownCheck = (input: {\n uid: string\n org: PluginDraftContext['org']\n host: StoredRule\n}) => Promise<boolean>\n\nexport interface RedirectAiWriterDeps {\n firestore: () => Firestore\n lockdown: RedirectAiLockdownCheck\n /** The `redirect` kind's declaration; the create route's otherwise. */\n declaration?: () => ResolvedPluginHostResource\n /** Drops the site's cached pages at these paths, best effort. */\n announcePaths?(hostId: string, paths: readonly string[]): Promise<void>\n /** Writes the site activity line for a created rule, best effort. */\n logCreated?(hostId: string, actorUid: string, ruleId: string, declared: ResolvedPluginHostResource): Promise<void>\n}\n\n/** What a caller is told about a rule: what it is, and that it is live. */\nfunction factsOf(action: RedirectDraftContent['action'], data: StoredRule): Record<string, unknown> {\n const values = redirectRuleValues('', data)\n return {\n action,\n source: values['source'],\n destination: values['destination'],\n kind: values['kind'],\n statusCode: values['statusCode'],\n priority: values['priority'],\n enabled: action === 'remove' ? false : values['enabled'],\n removed: action === 'remove',\n live: true,\n }\n}\n\nfunction recordOf(id: string, action: RedirectDraftContent['action'], data: StoredRule): PluginDraftRecord {\n return {\n id,\n name: `${String(data['source'] ?? '')} → ${String(data['destination'] ?? '')}`,\n versionId: null,\n facts: factsOf(action, data),\n }\n}\n\nfunction isLive(data: StoredRule | undefined): data is StoredRule {\n return Boolean(data) && !data?.['deletedAt']\n}\n\n/** A from-path as a rule of `kind` stores it: a pattern trimmed, a path normalized. */\nfunction storedSourceOf(kind: string, source: string): string | null {\n return kind === 'regex' ? source.trim() || null : normalizeRedirectSource(source)\n}\n\nexport function createRedirectAiWriter(deps: RedirectAiWriterDeps): PluginResourceDraftWriter {\n const declaration = deps.declaration ?? redirectDeclaration\n const hostRef = (hostId: string) => deps.firestore().collection('hosts').doc(hostId)\n const rulesOf = (hostId: string) => hostRef(hostId).collection('redirects')\n\n async function refusalFor(\n host: FirebaseFirestore.DocumentSnapshot,\n context: Pick<PluginDraftContext, 'uid' | 'org'>,\n ): Promise<PluginDraftRefusal | null> {\n if (!host.exists) return { status: 404, error: 'Unknown site' }\n const data = (host.data() ?? {}) as StoredRule\n if (!holdsSiteKey(data, context.uid, 'site.publish')) return { status: 403, error: REDIRECT_AI_ROLE_REFUSAL }\n const declared = declaration()\n if (declared.entitlement && !checkEntitlement((context.org ?? {}) as never, declared.entitlement)) {\n return { status: 403, error: REDIRECT_AI_PLAN_REFUSAL }\n }\n if (await deps.lockdown({ uid: context.uid, org: context.org, host: data })) {\n return { status: 403, error: REDIRECT_AI_LOCKED_REFUSAL }\n }\n return null\n }\n\n /** Every rule document of the site, soft-deleted ones included. */\n async function readAllRules(hostId: string): Promise<Array<{ id: string; data: StoredRule }>> {\n const snapshot = await rulesOf(hostId).get()\n return snapshot.docs.map((doc) => ({ id: doc.id, data: (doc.data() ?? {}) as StoredRule }))\n }\n\n /** The live rules at a from-path, of `kind` when it is given. */\n function rulesAt(\n all: ReadonlyArray<{ id: string; data: StoredRule }>,\n source: string,\n kind: string | undefined,\n ): Array<{ id: string; data: StoredRule }> {\n return all.filter(({ data }) => {\n const ruleKind = typeof data['kind'] === 'string' && data['kind'] ? (data['kind'] as string) : 'exact'\n if (kind && ruleKind !== kind) return false\n return data['source'] === storedSourceOf(ruleKind, source)\n })\n }\n\n /** Why the rule a change leaves cannot be saved among the site's live rules, or `null`. */\n function setProblem(\n rows: readonly RedirectRuleRow[],\n rule: { $id: string; source: string; destination: string; kind: string },\n ): { error: string; code: string } | null {\n if (findDuplicateRedirect(rows, rule)) {\n return { error: `A rule for ${rule.source} already exists`, code: REDIRECT_AI_REFUSAL_CODES.duplicate }\n }\n const walk = walkRedirectChain(rows, rule)\n if (walk.loop) {\n return { error: 'That destination chains back to this rule — a redirect loop', code: REDIRECT_AI_REFUSAL_CODES.loop }\n }\n if (walk.cycle) {\n return { error: 'That destination leads into a redirect loop other rules already make', code: REDIRECT_AI_REFUSAL_CODES.loop }\n }\n return null\n }\n\n /**\n * Where a chain from `destination` ends on the site (AGL-4245): the last\n * on-site address the rules pass it through, or `destination` itself when\n * no rule redirects it. An off-site hop ends the walk before it.\n */\n function chainEnd(rows: readonly RedirectRuleRow[], rule: { $id: string; source: string; destination: string }): string {\n const walk = walkRedirectChain(rows, rule)\n if (walk.loop || walk.cycle) return rule.destination\n const onSite = walk.hops.filter((hop) => hop.startsWith('/') && !hop.startsWith('//'))\n return onSite[onSite.length - 1] ?? rule.destination\n }\n\n function livePageProblem(host: StoredRule, source: string, kind: string, asked: boolean | undefined): string | null {\n if (asked || kind === 'regex' || !redirectSourceIsLivePage(host['screens'] as Record<string, unknown>, source)) {\n return null\n }\n return `${source} is a published page, and a redirect there would take its place. Redirect it only when the person asks for that page to send visitors elsewhere.`\n }\n\n async function announce(hostId: string, paths: Array<string | null>): Promise<void> {\n const unique = [...new Set(paths.filter((path): path is string => Boolean(path)))]\n if (unique.length && deps.announcePaths) await deps.announcePaths(hostId, unique).catch(() => undefined)\n }\n\n const refuse = (status: PluginDraftRefusal['status'], error: string, code?: string): PluginDraftWrite => ({\n ok: false,\n status,\n error,\n ...(code ? { code } : {}),\n })\n\n return {\n refusal: async (context) => refusalFor(await hostRef(context.hostId).get(), context),\n\n check: (content) => checkRedirectDraftContent(content),\n\n read: async ({ hostId, id }) => {\n const snapshot = await rulesOf(hostId).doc(id).get()\n if (!snapshot.exists) return null\n const data = (snapshot.data() ?? {}) as StoredRule\n return recordOf(id, isLive(data) ? 'create' : 'remove', data)\n },\n\n write: async (request): Promise<PluginDraftWrite> => {\n const read = readRedirectDraftContent(request.content)\n if (read.ok === false) return refuse(400, read.problems[0] as string)\n const change = read.value\n const hostSnapshot = await hostRef(request.hostId).get()\n const refusal = await refusalFor(hostSnapshot, request)\n if (refusal) return { ok: false, ...refusal }\n const host = (hostSnapshot.data() ?? {}) as StoredRule\n const declared = declaration()\n const approvalField = declared.externalDestination?.approvedByField ?? REDIRECT_FIELD.approvedBy\n const stampFor = (destination: unknown): string | null =>\n declared.externalDestination && isExternalRedirectDestination(String(destination ?? '')) ? request.uid : null\n const at = Timestamp.fromDate(request.now)\n const all = await readAllRules(request.hostId)\n const live = all.filter(({ data }) => isLive(data))\n const rows: RedirectRuleRow[] = live.map(({ id, data }) => ({\n $id: id,\n source: data['source'] as string,\n destination: data['destination'] as string,\n kind: data['kind'] as string,\n }))\n\n if (change.action === 'create') {\n const ref = rulesOf(request.hostId).doc(request.id)\n const before = all.find((one) => one.id === request.id)\n if (before) return { ok: true, replayed: true, ...recordOf(request.id, 'create', before.data) }\n const rule = withDefaults({\n source: change.source,\n destination: change.destination,\n kind: change.kind ?? 'exact',\n statusCode: change.statusCode ?? 302,\n priority: change.priority ?? REDIRECT_DEFAULT_PRIORITY,\n enabled: change.enabled ?? true,\n })\n const problem = ruleProblem(rule, host)\n if (problem) return refuse(400, problem.detail)\n const fields = storedFields(rule, declared.fields)\n const source = String(fields['source'])\n const kind = String(fields['kind'] ?? 'exact')\n const shadow = livePageProblem(host, source, kind, change.replacesLivePage)\n if (shadow) return refuse(409, shadow, REDIRECT_AI_REFUSAL_CODES.livePage)\n if (findDuplicateRedirect(rows, { $id: request.id, source, kind })) {\n return refuse(409, `A rule for ${source} already exists`, REDIRECT_AI_REFUSAL_CODES.duplicate)\n }\n if (change.followChain) {\n const end = chainEnd(rows, { $id: request.id, source, destination: String(fields['destination']) })\n if (end !== fields['destination']) {\n // The chain's end, held to the page's rules again as the new destination.\n const followed = ruleProblem({ ...rule, destination: end }, host)\n if (!followed) fields['destination'] = normalizeRedirectDestination(end) ?? end\n }\n }\n const clash = setProblem(rows, { $id: request.id, source, destination: String(fields['destination']), kind })\n if (clash) return refuse(409, clash.error, clash.code)\n const stamp = stampFor(fields['destination'])\n const written = { ...fields, ...(stamp ? { [approvalField]: stamp } : {}) }\n const db = deps.firestore()\n const outcome = await db.runTransaction(async (tx): Promise<{ refusal?: string; existed?: StoredRule }> => {\n const existing = await tx.get(ref)\n if (existing.exists) return { existed: (existing.data() ?? {}) as StoredRule }\n if (declared.quotaKey) {\n // Live rules only, as the create route counts: a deleted rule frees its slot (AGL-3918).\n const used = await countLiveDocuments(rulesOf(request.hostId), (aggregate) => tx.get(aggregate))\n const quota = checkQuota((request.org ?? {}) as never, declared.quotaKey as never, Number(used) || 0)\n if (!quota.allowed) return { refusal: redirectAiLimitRefusal(quota.limit) }\n }\n tx.create(ref, { ...written, createdAt: at, updatedAt: at, createdBy: request.uid })\n return {}\n })\n if (outcome.refusal) return refuse(403, outcome.refusal, REDIRECT_AI_REFUSAL_CODES.planLimit)\n if (outcome.existed) return { ok: true, replayed: true, ...recordOf(request.id, 'create', outcome.existed) }\n if (deps.logCreated) {\n await deps.logCreated(request.hostId, request.uid, ref.id, declared).catch(() => undefined)\n }\n await announce(request.hostId, [announcedPath(fields)])\n return { ok: true, replayed: false, ...recordOf(ref.id, 'create', written) }\n }\n\n // An update or a remove names a rule the site has.\n const found = rulesAt(live, change.source, change.kind)\n if (found.length > 1) {\n return refuse(\n 409,\n `The site has more than one redirect at ${change.source}; say which match mode (exact, prefix or regex) to change`,\n )\n }\n const target = found[0]\n if (!target) {\n if (change.action === 'remove') {\n const gone = rulesAt(all, change.source, change.kind)[0]\n if (gone) return { ok: true, replayed: true, ...recordOf(gone.id, 'remove', gone.data) }\n }\n return refuse(404, `The site has no redirect from ${change.source}`)\n }\n const ref = rulesOf(request.hostId).doc(target.id)\n\n if (change.action === 'remove') {\n // The page's Delete: marked deleted and off, so the serve path drops it.\n await ref.set({ deletedAt: at, enabled: false }, { merge: true })\n await announce(request.hostId, [announcedPath(target.data as { kind?: string; source?: string })])\n return { ok: true, replayed: false, ...recordOf(target.id, 'remove', target.data) }\n }\n\n const current = redirectRuleValues(target.id, target.data)\n const rule = withDefaults({\n ...current,\n ...(change.newSource !== undefined ? { source: change.newSource } : {}),\n ...(change.destination !== undefined ? { destination: change.destination } : {}),\n ...(change.statusCode !== undefined ? { statusCode: change.statusCode } : {}),\n ...(change.priority !== undefined ? { priority: change.priority } : {}),\n ...(change.enabled !== undefined ? { enabled: change.enabled } : {}),\n })\n const problem = ruleProblem(rule, host)\n if (problem) return refuse(400, problem.detail)\n const fields = storedFields(rule, declared.fields)\n const source = String(fields['source'])\n const kind = String(fields['kind'] ?? 'exact')\n if (source !== current['source']) {\n const shadow = livePageProblem(host, source, kind, change.replacesLivePage)\n if (shadow) return refuse(409, shadow, REDIRECT_AI_REFUSAL_CODES.livePage)\n }\n const clash = setProblem(rows, { $id: target.id, source, destination: String(fields['destination']), kind })\n if (clash) return refuse(409, clash.error, clash.code)\n const stamp = stampFor(fields['destination'])\n const unchanged =\n Object.entries(fields).every(([key, value]) => current[key] === value) &&\n (current[approvalField] ?? null) === stamp\n const after = { ...target.data, ...fields, ...(stamp ? { [approvalField]: stamp } : {}) }\n if (unchanged) return { ok: true, replayed: true, ...recordOf(target.id, 'update', after) }\n // The page's edit: every field the form owns, the stamp set or removed,\n // `updatedAt`, merged so `lastHitAt` stays.\n await ref.set({ ...fields, [approvalField]: stamp ?? FieldValue.delete(), updatedAt: at }, { merge: true })\n await announce(request.hostId, [announcedPath(fields), announcedPath(target.data as { kind?: string; source?: string })])\n return { ok: true, replayed: false, ...recordOf(target.id, 'update', after) }\n },\n }\n}\n"],"names":["checkEntitlement","checkQuota","holdsSiteKey","siteKeyRefusal","countLiveDocuments","FieldValue","Timestamp","checkRedirectDraftContent","readRedirectDraftContent","REDIRECT_DEFAULT_PRIORITY","findDuplicateRedirect","isExternalRedirectDestination","normalizeRedirectDestination","normalizeRedirectSource","redirectSourceIsLivePage","walkRedirectChain","announcedPath","redirectDeclaration","redirectRuleValues","ruleProblem","storedFields","withDefaults","REDIRECT_FIELD","REDIRECT_AI_REFUSAL_CODES","duplicate","livePage","loop","planLimit","REDIRECT_AI_ROLE_REFUSAL","REDIRECT_AI_PLAN_REFUSAL","REDIRECT_AI_LOCKED_REFUSAL","redirectAiLimitRefusal","limit","factsOf","action","data","values","source","destination","kind","statusCode","priority","enabled","removed","live","recordOf","id","name","String","versionId","facts","isLive","Boolean","storedSourceOf","trim","createRedirectAiWriter","deps","declaration","hostRef","hostId","firestore","collection","doc","rulesOf","refusalFor","host","context","exists","status","error","uid","declared","entitlement","org","lockdown","readAllRules","snapshot","get","docs","map","rulesAt","all","filter","ruleKind","setProblem","rows","rule","code","walk","cycle","chainEnd","onSite","hops","hop","startsWith","length","livePageProblem","asked","announce","paths","unique","Set","path","announcePaths","catch","undefined","refuse","ok","refusal","check","content","read","write","request","hostSnapshot","fields","current","problems","change","value","approvalField","externalDestination","approvedByField","approvedBy","stampFor","at","fromDate","now","$id","ref","before","find","one","replayed","problem","detail","shadow","replacesLivePage","followChain","end","followed","clash","stamp","written","db","outcome","runTransaction","tx","existing","existed","quotaKey","used","aggregate","quota","Number","allowed","create","createdAt","updatedAt","createdBy","logCreated","found","target","gone","set","deletedAt","merge","newSource","unchanged","Object","entries","every","key","after","delete"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,2CAA0C;AACvF,SAASC,YAAY,EAAEC,cAAc,QAAQ,0CAAyC;AACtF,SAASC,kBAAkB,QAAQ,6CAA4C;AAS/E,SAASC,UAAU,EAAEC,SAAS,QAAQ,2BAA0B;AAChE,SACEC,yBAAyB,EACzBC,wBAAwB,QAEnB,qCAAiC;AACxC,SACEC,yBAAyB,EACzBC,qBAAqB,EACrBC,6BAA6B,EAC7BC,4BAA4B,EAC5BC,uBAAuB,EACvBC,wBAAwB,EACxBC,iBAAiB,QAEZ,wBAAoB;AAC3B,SACEC,aAAa,EACbC,mBAAmB,EACnBC,kBAAkB,EAClBC,WAAW,EACXC,YAAY,EACZ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BAAQ,CAACK,cAAc,EAAEsB,gBAAAA,QAASzI,WAAWyK,MAAM;gBAAIhB,WAAWjC;gBAAM;gBAAEyC,OAAO;YAAK;YACzG,MAAMpE,SAASe,QAAQtD,MAAM,EAAE;gBAAC3C,cAAcmG;gBAASnG,cAAckJ,OAAO/H,IAAI;aAAwC;YACxH,OAAO;gBAAEwE,IAAI;gBAAM0B,UAAU;eAAUxF,SAASqH,OAAOpH,EAAE,EAAE,UAAU+H;QACvE;IACF;AACF"}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/ import { normalizeRedirectDestination, normalizeRedirectSource } from "../model/redirects.js";
|
|
17
|
+
import { SQUARESPACE_URL_MAPPINGS_SOURCE, SQUARESPACE_URL_MAPPING_HEADERS } from "./squarespace-url-mapping-headers.js";
|
|
17
18
|
/**
|
|
18
19
|
* What the redirects resource is made of, without reading anything: its key,
|
|
19
20
|
* its fields, the keys a row finds its rule by and other products' header
|
|
@@ -284,6 +285,25 @@ const GROUPS = [
|
|
|
284
285
|
]
|
|
285
286
|
}
|
|
286
287
|
},
|
|
288
|
+
{
|
|
289
|
+
// No export: the text of Settings → URL Mappings, which the upload step
|
|
290
|
+
// reads into these columns (`squarespace-url-mappings.ts`).
|
|
291
|
+
source: SQUARESPACE_URL_MAPPINGS_SOURCE,
|
|
292
|
+
aliases: {
|
|
293
|
+
[REDIRECT_FIELD.source]: [
|
|
294
|
+
SQUARESPACE_URL_MAPPING_HEADERS.source
|
|
295
|
+
],
|
|
296
|
+
[REDIRECT_FIELD.destination]: [
|
|
297
|
+
SQUARESPACE_URL_MAPPING_HEADERS.destination
|
|
298
|
+
],
|
|
299
|
+
[REDIRECT_FIELD.statusCode]: [
|
|
300
|
+
SQUARESPACE_URL_MAPPING_HEADERS.statusCode
|
|
301
|
+
],
|
|
302
|
+
[REDIRECT_FIELD.kind]: [
|
|
303
|
+
SQUARESPACE_URL_MAPPING_HEADERS.kind
|
|
304
|
+
]
|
|
305
|
+
}
|
|
306
|
+
},
|
|
287
307
|
{
|
|
288
308
|
source: 'Spreadsheet',
|
|
289
309
|
aliases: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/redirects/src/lib/transfer/redirects-transfer-fields.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n MatchKeySpec,\n TransferAliasDictionary,\n TransferCatalogInput,\n TransferField,\n TransferPolicyDefaults,\n} from '@aglyn/aglyn/data-transfer'\nimport { REDIRECT_KINDS, normalizeRedirectDestination, normalizeRedirectSource } from '../model/redirects'\n\n/**\n * What the redirects resource is made of, without reading anything: its key,\n * its fields, the keys a row finds its rule by and other products' header\n * spellings. Light on purpose — the console's boot registers the resource\n * with these, and only an import or an export loads the module that reads\n * and writes (`redirects-transfer.ts`).\n */\n\n/** The resource key declared in `plugins.config.json` (`transferResources`). */\nexport const REDIRECTS_TRANSFER_KEY = 'redirects'\n\n/** The kind `/api/hosts/resources` creates a rule as, and whose declaration holds its allow-list. */\nexport const REDIRECT_HOST_RESOURCE_KIND = 'redirect'\n\n/** The rule's match mode, as stored. */\nexport type RedirectKind = (typeof REDIRECT_KINDS)[number]\n\n/** Field ids, as the catalog, the plan and the export name them. */\nexport const REDIRECT_FIELD = {\n source: 'source',\n kind: 'kind',\n destination: 'destination',\n statusCode: 'statusCode',\n priority: 'priority',\n enabled: 'enabled',\n approvedBy: 'externalDestinationApprovedBy',\n createdAt: 'createdAt',\n updatedAt: 'updatedAt',\n createdBy: 'createdBy',\n lastHitAt: 'lastHitAt',\n hits: 'hits30d',\n} as const\n\n/** The fields a file may write: the rule's own six, the create route's allow-list. */\nexport const REDIRECT_WRITABLE_FIELDS = [\n REDIRECT_FIELD.source,\n REDIRECT_FIELD.destination,\n REDIRECT_FIELD.statusCode,\n REDIRECT_FIELD.kind,\n REDIRECT_FIELD.priority,\n REDIRECT_FIELD.enabled,\n] as const\n\n/**\n * The keys a row finds its rule by: the Aglyn ID, then the path it redirects\n * from. The core folds the from-path only by trimming it; the lookup and the\n * plan read it the way the redirects page stores it (lowercase, no trailing\n * slash, no query) and within its match mode, so `/Old-Page/` finds the exact\n * rule for `/old-page` and not the prefix rule beside it.\n */\nexport const REDIRECTS_MATCH_KEYS: readonly MatchKeySpec[] = [\n { fieldId: 'id', normalizer: 'aglynId' },\n { fieldId: REDIRECT_FIELD.source, normalizer: 'trim' },\n]\n\nconst GROUPS = [\n { id: 'rule', label: 'Rule' },\n { id: 'usage', label: 'Usage' },\n]\n\n/** The field catalog: the rule, its usage, and what the platform stamps on it. */\nexport function redirectsTransferCatalog(): TransferCatalogInput {\n return {\n groups: GROUPS,\n standard: [\n {\n id: REDIRECT_FIELD.source,\n label: 'From path',\n group: 'rule',\n type: 'text',\n required: true,\n matchKey: true,\n description:\n 'The path visitors arrive at, like /old-page; for a regex rule, the pattern.',\n aliases: ['from', 'source', 'source path', 'from url', 'old path', 'old url', 'redirect from', 'origin', 'pattern'],\n },\n {\n id: REDIRECT_FIELD.kind,\n label: 'Kind',\n group: 'rule',\n type: 'text',\n description: 'exact, prefix or regex; exact when blank.',\n aliases: ['match', 'match mode', 'match type', 'kind', 'mode', 'regex'],\n },\n {\n id: REDIRECT_FIELD.destination,\n label: 'To',\n group: 'rule',\n type: 'text',\n required: true,\n description: 'A path on this site, like /new-page, or an https:// address.',\n aliases: ['to', 'destination', 'target', 'to url', 'new path', 'new url', 'redirect to', 'redirect url'],\n },\n {\n id: REDIRECT_FIELD.statusCode,\n label: 'Status code',\n group: 'rule',\n type: 'integer',\n description: '301, 302, 307 or 308; 302 when blank.',\n aliases: ['status', 'status code', 'code', 'http code', 'http status', 'type', 'redirect type'],\n },\n {\n id: REDIRECT_FIELD.priority,\n label: 'Priority',\n group: 'rule',\n type: 'integer',\n description: 'Lower fires first when several rules match; 100 when blank.',\n aliases: ['order', 'position'],\n },\n {\n id: REDIRECT_FIELD.enabled,\n label: 'Enabled',\n group: 'rule',\n type: 'boolean',\n description: 'Whether the rule is on; on when blank.',\n aliases: ['active', 'on', 'enabled'],\n },\n ],\n derived: [\n {\n id: REDIRECT_FIELD.hits,\n label: 'Hits in the last 30 days',\n group: 'usage',\n type: 'integer',\n readOnly: true,\n description: 'Sampled: one per cache window with traffic.',\n },\n ],\n system: [\n {\n id: REDIRECT_FIELD.approvedBy,\n label: 'Off-site destination approved by',\n type: 'text',\n readOnly: true,\n description:\n 'Who confirmed an off-site destination. Importing one approves it in your name; it is never read from a file.',\n },\n { id: REDIRECT_FIELD.lastHitAt, label: 'Last hit', group: 'usage', type: 'datetime', readOnly: true },\n { id: REDIRECT_FIELD.createdAt, label: 'Created', type: 'datetime', readOnly: true },\n { id: REDIRECT_FIELD.updatedAt, label: 'Updated', type: 'datetime', readOnly: true },\n { id: REDIRECT_FIELD.createdBy, label: 'Created by', type: 'text', readOnly: true },\n ],\n }\n}\n\n/**\n * Other products' redirect exports, by their own header spellings, so their\n * files map without a person matching columns by hand.\n */\nexport const REDIRECTS_ALIAS_DICTIONARIES: readonly TransferAliasDictionary[] = [\n {\n source: 'Shopify URL redirects',\n aliases: {\n [REDIRECT_FIELD.source]: ['Redirect from'],\n [REDIRECT_FIELD.destination]: ['Redirect to'],\n },\n },\n {\n source: 'WordPress Redirection',\n aliases: {\n [REDIRECT_FIELD.source]: ['source'],\n [REDIRECT_FIELD.destination]: ['target'],\n [REDIRECT_FIELD.statusCode]: ['code'],\n [REDIRECT_FIELD.kind]: ['regex'],\n },\n },\n {\n source: 'Yoast SEO redirects',\n aliases: {\n [REDIRECT_FIELD.source]: ['Origin'],\n [REDIRECT_FIELD.destination]: ['Target'],\n [REDIRECT_FIELD.statusCode]: ['Type'],\n [REDIRECT_FIELD.kind]: ['Format'],\n },\n },\n {\n source: 'Wix URL redirects',\n aliases: {\n [REDIRECT_FIELD.source]: ['Old URL'],\n [REDIRECT_FIELD.destination]: ['New URL'],\n },\n },\n {\n source: 'Webflow 301 redirects',\n aliases: {\n [REDIRECT_FIELD.source]: ['Old path'],\n [REDIRECT_FIELD.destination]: ['Redirect to path'],\n },\n },\n {\n source: 'Spreadsheet',\n aliases: {\n [REDIRECT_FIELD.source]: ['Source', 'From', 'Old'],\n [REDIRECT_FIELD.destination]: ['Destination', 'Target', 'To', 'New'],\n [REDIRECT_FIELD.statusCode]: ['Status', 'Type', 'HTTP status code'],\n },\n },\n]\n\n/**\n * The spellings a file's Kind cell may take, read to the stored mode. Covers\n * the console's own labels (\"Path prefix\"), the words other products use,\n * and a yes/no \"regex\" column (the WordPress Redirection export's).\n * Yoast's Format column says `plain` or `regex`.\n */\nconst KIND_SPELLINGS: Readonly<Record<string, RedirectKind>> = {\n exact: 'exact',\n 'exact path': 'exact',\n 'exact match': 'exact',\n plain: 'exact',\n path: 'exact',\n page: 'exact',\n '0': 'exact',\n no: 'exact',\n false: 'exact',\n prefix: 'prefix',\n 'path prefix': 'prefix',\n 'starts with': 'prefix',\n folder: 'prefix',\n directory: 'prefix',\n regex: 'regex',\n regexp: 'regex',\n 'regular expression': 'regex',\n pattern: 'regex',\n '1': 'regex',\n yes: 'regex',\n true: 'regex',\n}\n\n/** A Kind cell as the stored mode, or `null` when it names none. */\nexport function canonicalRedirectKind(value: unknown): RedirectKind | null {\n if (typeof value === 'boolean') return value ? 'regex' : 'exact'\n const text = String(value ?? '')\n .trim()\n .toLowerCase()\n .replace(/\\s+/g, ' ')\n return KIND_SPELLINGS[text] ?? null\n}\n\n/**\n * Where an import of redirects starts: a rule already on the site takes the\n * file's values. A redirect file is the statement of where each path goes —\n * re-importing one with a new destination means \"point it there\" — so the\n * core's fill blanks would keep every old destination and change nothing. A\n * blank cell still leaves the rule's value alone.\n */\nexport const REDIRECTS_DEFAULT_POLICY: TransferPolicyDefaults = {\n fieldDefault: { mode: 'overwrite', blank: 'leave' },\n note:\n 'A redirect file says where each path goes, so a rule already on the site takes the ' +\n 'file’s destination, status, priority and on/off. Choose Fill blanks to keep what the site has.',\n}\n\nconst textOf = (value: unknown): string => (typeof value === 'string' ? value : '')\nconst isBlankCell = (value: unknown): boolean =>\n value === null || value === undefined || (typeof value === 'string' && !value.trim())\n\n/** Characters only a pattern holds; a path compared with one is compared as typed. */\nconst PATTERN_CHARACTERS = /[\\^$*+?()[\\]{}|\\\\]/\n\n/**\n * Whether a file's value and a rule's are the same as the page stores them\n * (the review's Conflicts step and the dry run agree): a from-path by its\n * stored form (`/Old-Page/` is `/old-page`) unless either side is a pattern,\n * which is compared as typed; a destination by its stored form; a mode by\n * its canonical name; a status code and a priority as numbers.\n */\nexport function redirectValuesEqual(field: TransferField, a: unknown, b: unknown): boolean | undefined {\n if (isBlankCell(a) || isBlankCell(b)) return undefined\n switch (field.id) {\n case REDIRECT_FIELD.source: {\n const left = textOf(a).trim()\n const right = textOf(b).trim()\n if (PATTERN_CHARACTERS.test(left) || PATTERN_CHARACTERS.test(right)) return left === right\n const stored = normalizeRedirectSource(left)\n return stored !== null && stored === normalizeRedirectSource(right) ? true : left === right\n }\n case REDIRECT_FIELD.destination: {\n const stored = normalizeRedirectDestination(textOf(a))\n return stored !== null && stored === normalizeRedirectDestination(textOf(b)) ? true : textOf(a).trim() === textOf(b).trim()\n }\n case REDIRECT_FIELD.kind: {\n const kind = canonicalRedirectKind(a)\n return kind !== null && kind === canonicalRedirectKind(b) ? true : undefined\n }\n case REDIRECT_FIELD.statusCode:\n case REDIRECT_FIELD.priority: {\n const left = Number(a)\n const right = Number(b)\n return Number.isFinite(left) && Number.isFinite(right) ? left === right : undefined\n }\n default:\n return undefined\n }\n}\n"],"names":["normalizeRedirectDestination","normalizeRedirectSource","REDIRECTS_TRANSFER_KEY","REDIRECT_HOST_RESOURCE_KIND","REDIRECT_FIELD","source","kind","destination","statusCode","priority","enabled","approvedBy","createdAt","updatedAt","createdBy","lastHitAt","hits","REDIRECT_WRITABLE_FIELDS","REDIRECTS_MATCH_KEYS","fieldId","normalizer","GROUPS","id","label","redirectsTransferCatalog","groups","standard","group","type","required","matchKey","description","aliases","derived","readOnly","system","REDIRECTS_ALIAS_DICTIONARIES","KIND_SPELLINGS","exact","plain","path","page","no","false","prefix","folder","directory","regex","regexp","pattern","yes","true","canonicalRedirectKind","value","text","String","trim","toLowerCase","replace","REDIRECTS_DEFAULT_POLICY","fieldDefault","mode","blank","note","textOf","isBlankCell","undefined","PATTERN_CHARACTERS","redirectValuesEqual","field","a","b","left","right","test","stored","Number","isFinite"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GASD,SAAyBA,4BAA4B,EAAEC,uBAAuB,QAAQ,wBAAoB;AAE1G;;;;;;CAMC,GAED,8EAA8E,GAC9E,OAAO,MAAMC,yBAAyB,YAAW;AAEjD,mGAAmG,GACnG,OAAO,MAAMC,8BAA8B,WAAU;AAKrD,kEAAkE,GAClE,OAAO,MAAMC,iBAAiB;IAC5BC,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,YAAY;IACZC,UAAU;IACVC,SAAS;IACTC,YAAY;IACZC,WAAW;IACXC,WAAW;IACXC,WAAW;IACXC,WAAW;IACXC,MAAM;AACR,EAAU;AAEV,oFAAoF,GACpF,OAAO,MAAMC,2BAA2B;IACtCb,eAAeC,MAAM;IACrBD,eAAeG,WAAW;IAC1BH,eAAeI,UAAU;IACzBJ,eAAeE,IAAI;IACnBF,eAAeK,QAAQ;IACvBL,eAAeM,OAAO;CACvB,CAAS;AAEV;;;;;;CAMC,GACD,OAAO,MAAMQ,uBAAgD;IAC3D;QAAEC,SAAS;QAAMC,YAAY;IAAU;IACvC;QAAED,SAAS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SAASD,SAASC,QAAQP;YAC5E;QACA;YACE,OAAOA;IACX;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/redirects/src/lib/transfer/redirects-transfer-fields.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n MatchKeySpec,\n TransferAliasDictionary,\n TransferCatalogInput,\n TransferField,\n TransferPolicyDefaults,\n} from '@aglyn/aglyn/data-transfer'\nimport { REDIRECT_KINDS, normalizeRedirectDestination, normalizeRedirectSource } from '../model/redirects'\nimport { SQUARESPACE_URL_MAPPINGS_SOURCE, SQUARESPACE_URL_MAPPING_HEADERS } from './squarespace-url-mapping-headers'\n\n/**\n * What the redirects resource is made of, without reading anything: its key,\n * its fields, the keys a row finds its rule by and other products' header\n * spellings. Light on purpose — the console's boot registers the resource\n * with these, and only an import or an export loads the module that reads\n * and writes (`redirects-transfer.ts`).\n */\n\n/** The resource key declared in `plugins.config.json` (`transferResources`). */\nexport const REDIRECTS_TRANSFER_KEY = 'redirects'\n\n/** The kind `/api/hosts/resources` creates a rule as, and whose declaration holds its allow-list. */\nexport const REDIRECT_HOST_RESOURCE_KIND = 'redirect'\n\n/** The rule's match mode, as stored. */\nexport type RedirectKind = (typeof REDIRECT_KINDS)[number]\n\n/** Field ids, as the catalog, the plan and the export name them. */\nexport const REDIRECT_FIELD = {\n source: 'source',\n kind: 'kind',\n destination: 'destination',\n statusCode: 'statusCode',\n priority: 'priority',\n enabled: 'enabled',\n approvedBy: 'externalDestinationApprovedBy',\n createdAt: 'createdAt',\n updatedAt: 'updatedAt',\n createdBy: 'createdBy',\n lastHitAt: 'lastHitAt',\n hits: 'hits30d',\n} as const\n\n/** The fields a file may write: the rule's own six, the create route's allow-list. */\nexport const REDIRECT_WRITABLE_FIELDS = [\n REDIRECT_FIELD.source,\n REDIRECT_FIELD.destination,\n REDIRECT_FIELD.statusCode,\n REDIRECT_FIELD.kind,\n REDIRECT_FIELD.priority,\n REDIRECT_FIELD.enabled,\n] as const\n\n/**\n * The keys a row finds its rule by: the Aglyn ID, then the path it redirects\n * from. The core folds the from-path only by trimming it; the lookup and the\n * plan read it the way the redirects page stores it (lowercase, no trailing\n * slash, no query) and within its match mode, so `/Old-Page/` finds the exact\n * rule for `/old-page` and not the prefix rule beside it.\n */\nexport const REDIRECTS_MATCH_KEYS: readonly MatchKeySpec[] = [\n { fieldId: 'id', normalizer: 'aglynId' },\n { fieldId: REDIRECT_FIELD.source, normalizer: 'trim' },\n]\n\nconst GROUPS = [\n { id: 'rule', label: 'Rule' },\n { id: 'usage', label: 'Usage' },\n]\n\n/** The field catalog: the rule, its usage, and what the platform stamps on it. */\nexport function redirectsTransferCatalog(): TransferCatalogInput {\n return {\n groups: GROUPS,\n standard: [\n {\n id: REDIRECT_FIELD.source,\n label: 'From path',\n group: 'rule',\n type: 'text',\n required: true,\n matchKey: true,\n description:\n 'The path visitors arrive at, like /old-page; for a regex rule, the pattern.',\n aliases: ['from', 'source', 'source path', 'from url', 'old path', 'old url', 'redirect from', 'origin', 'pattern'],\n },\n {\n id: REDIRECT_FIELD.kind,\n label: 'Kind',\n group: 'rule',\n type: 'text',\n description: 'exact, prefix or regex; exact when blank.',\n aliases: ['match', 'match mode', 'match type', 'kind', 'mode', 'regex'],\n },\n {\n id: REDIRECT_FIELD.destination,\n label: 'To',\n group: 'rule',\n type: 'text',\n required: true,\n description: 'A path on this site, like /new-page, or an https:// address.',\n aliases: ['to', 'destination', 'target', 'to url', 'new path', 'new url', 'redirect to', 'redirect url'],\n },\n {\n id: REDIRECT_FIELD.statusCode,\n label: 'Status code',\n group: 'rule',\n type: 'integer',\n description: '301, 302, 307 or 308; 302 when blank.',\n aliases: ['status', 'status code', 'code', 'http code', 'http status', 'type', 'redirect type'],\n },\n {\n id: REDIRECT_FIELD.priority,\n label: 'Priority',\n group: 'rule',\n type: 'integer',\n description: 'Lower fires first when several rules match; 100 when blank.',\n aliases: ['order', 'position'],\n },\n {\n id: REDIRECT_FIELD.enabled,\n label: 'Enabled',\n group: 'rule',\n type: 'boolean',\n description: 'Whether the rule is on; on when blank.',\n aliases: ['active', 'on', 'enabled'],\n },\n ],\n derived: [\n {\n id: REDIRECT_FIELD.hits,\n label: 'Hits in the last 30 days',\n group: 'usage',\n type: 'integer',\n readOnly: true,\n description: 'Sampled: one per cache window with traffic.',\n },\n ],\n system: [\n {\n id: REDIRECT_FIELD.approvedBy,\n label: 'Off-site destination approved by',\n type: 'text',\n readOnly: true,\n description:\n 'Who confirmed an off-site destination. Importing one approves it in your name; it is never read from a file.',\n },\n { id: REDIRECT_FIELD.lastHitAt, label: 'Last hit', group: 'usage', type: 'datetime', readOnly: true },\n { id: REDIRECT_FIELD.createdAt, label: 'Created', type: 'datetime', readOnly: true },\n { id: REDIRECT_FIELD.updatedAt, label: 'Updated', type: 'datetime', readOnly: true },\n { id: REDIRECT_FIELD.createdBy, label: 'Created by', type: 'text', readOnly: true },\n ],\n }\n}\n\n/**\n * Other products' redirect exports, by their own header spellings, so their\n * files map without a person matching columns by hand.\n */\nexport const REDIRECTS_ALIAS_DICTIONARIES: readonly TransferAliasDictionary[] = [\n {\n source: 'Shopify URL redirects',\n aliases: {\n [REDIRECT_FIELD.source]: ['Redirect from'],\n [REDIRECT_FIELD.destination]: ['Redirect to'],\n },\n },\n {\n source: 'WordPress Redirection',\n aliases: {\n [REDIRECT_FIELD.source]: ['source'],\n [REDIRECT_FIELD.destination]: ['target'],\n [REDIRECT_FIELD.statusCode]: ['code'],\n [REDIRECT_FIELD.kind]: ['regex'],\n },\n },\n {\n source: 'Yoast SEO redirects',\n aliases: {\n [REDIRECT_FIELD.source]: ['Origin'],\n [REDIRECT_FIELD.destination]: ['Target'],\n [REDIRECT_FIELD.statusCode]: ['Type'],\n [REDIRECT_FIELD.kind]: ['Format'],\n },\n },\n {\n source: 'Wix URL redirects',\n aliases: {\n [REDIRECT_FIELD.source]: ['Old URL'],\n [REDIRECT_FIELD.destination]: ['New URL'],\n },\n },\n {\n source: 'Webflow 301 redirects',\n aliases: {\n [REDIRECT_FIELD.source]: ['Old path'],\n [REDIRECT_FIELD.destination]: ['Redirect to path'],\n },\n },\n {\n // No export: the text of Settings → URL Mappings, which the upload step\n // reads into these columns (`squarespace-url-mappings.ts`).\n source: SQUARESPACE_URL_MAPPINGS_SOURCE,\n aliases: {\n [REDIRECT_FIELD.source]: [SQUARESPACE_URL_MAPPING_HEADERS.source],\n [REDIRECT_FIELD.destination]: [SQUARESPACE_URL_MAPPING_HEADERS.destination],\n [REDIRECT_FIELD.statusCode]: [SQUARESPACE_URL_MAPPING_HEADERS.statusCode],\n [REDIRECT_FIELD.kind]: [SQUARESPACE_URL_MAPPING_HEADERS.kind],\n },\n },\n {\n source: 'Spreadsheet',\n aliases: {\n [REDIRECT_FIELD.source]: ['Source', 'From', 'Old'],\n [REDIRECT_FIELD.destination]: ['Destination', 'Target', 'To', 'New'],\n [REDIRECT_FIELD.statusCode]: ['Status', 'Type', 'HTTP status code'],\n },\n },\n]\n\n/**\n * The spellings a file's Kind cell may take, read to the stored mode. Covers\n * the console's own labels (\"Path prefix\"), the words other products use,\n * and a yes/no \"regex\" column (the WordPress Redirection export's).\n * Yoast's Format column says `plain` or `regex`.\n */\nconst KIND_SPELLINGS: Readonly<Record<string, RedirectKind>> = {\n exact: 'exact',\n 'exact path': 'exact',\n 'exact match': 'exact',\n plain: 'exact',\n path: 'exact',\n page: 'exact',\n '0': 'exact',\n no: 'exact',\n false: 'exact',\n prefix: 'prefix',\n 'path prefix': 'prefix',\n 'starts with': 'prefix',\n folder: 'prefix',\n directory: 'prefix',\n regex: 'regex',\n regexp: 'regex',\n 'regular expression': 'regex',\n pattern: 'regex',\n '1': 'regex',\n yes: 'regex',\n true: 'regex',\n}\n\n/** A Kind cell as the stored mode, or `null` when it names none. */\nexport function canonicalRedirectKind(value: unknown): RedirectKind | null {\n if (typeof value === 'boolean') return value ? 'regex' : 'exact'\n const text = String(value ?? '')\n .trim()\n .toLowerCase()\n .replace(/\\s+/g, ' ')\n return KIND_SPELLINGS[text] ?? null\n}\n\n/**\n * Where an import of redirects starts: a rule already on the site takes the\n * file's values. A redirect file is the statement of where each path goes —\n * re-importing one with a new destination means \"point it there\" — so the\n * core's fill blanks would keep every old destination and change nothing. A\n * blank cell still leaves the rule's value alone.\n */\nexport const REDIRECTS_DEFAULT_POLICY: TransferPolicyDefaults = {\n fieldDefault: { mode: 'overwrite', blank: 'leave' },\n note:\n 'A redirect file says where each path goes, so a rule already on the site takes the ' +\n 'file’s destination, status, priority and on/off. Choose Fill blanks to keep what the site has.',\n}\n\nconst textOf = (value: unknown): string => (typeof value === 'string' ? value : '')\nconst isBlankCell = (value: unknown): boolean =>\n value === null || value === undefined || (typeof value === 'string' && !value.trim())\n\n/** Characters only a pattern holds; a path compared with one is compared as typed. */\nconst PATTERN_CHARACTERS = /[\\^$*+?()[\\]{}|\\\\]/\n\n/**\n * Whether a file's value and a rule's are the same as the page stores them\n * (the review's Conflicts step and the dry run agree): a from-path by its\n * stored form (`/Old-Page/` is `/old-page`) unless either side is a pattern,\n * which is compared as typed; a destination by its stored form; a mode by\n * its canonical name; a status code and a priority as numbers.\n */\nexport function redirectValuesEqual(field: TransferField, a: unknown, b: unknown): boolean | undefined {\n if (isBlankCell(a) || isBlankCell(b)) return undefined\n switch (field.id) {\n case REDIRECT_FIELD.source: {\n const left = textOf(a).trim()\n const right = textOf(b).trim()\n if (PATTERN_CHARACTERS.test(left) || PATTERN_CHARACTERS.test(right)) return left === right\n const stored = normalizeRedirectSource(left)\n return stored !== null && stored === normalizeRedirectSource(right) ? true : left === right\n }\n case REDIRECT_FIELD.destination: {\n const stored = normalizeRedirectDestination(textOf(a))\n return stored !== null && stored === normalizeRedirectDestination(textOf(b)) ? true : textOf(a).trim() === textOf(b).trim()\n }\n case REDIRECT_FIELD.kind: {\n const kind = canonicalRedirectKind(a)\n return kind !== null && kind === canonicalRedirectKind(b) ? true : undefined\n }\n case REDIRECT_FIELD.statusCode:\n case REDIRECT_FIELD.priority: {\n const left = Number(a)\n const right = Number(b)\n return Number.isFinite(left) && Number.isFinite(right) ? left === right : undefined\n }\n default:\n return undefined\n }\n}\n"],"names":["normalizeRedirectDestination","normalizeRedirectSource","SQUARESPACE_URL_MAPPINGS_SOURCE","SQUARESPACE_URL_MAPPING_HEADERS","REDIRECTS_TRANSFER_KEY","REDIRECT_HOST_RESOURCE_KIND","REDIRECT_FIELD","source","kind","destination","statusCode","priority","enabled","approvedBy","createdAt","updatedAt","createdBy","lastHitAt","hits","REDIRECT_WRITABLE_FIELDS","REDIRECTS_MATCH_KEYS","fieldId","normalizer","GROUPS","id","label","redirectsTransferCatalog","groups","standard","group","type","required","matchKey","description","aliases","derived","readOnly","system","REDIRECTS_ALIAS_DICTIONARIES","KIND_SPELLINGS","exact","plain","path","page","no","false","prefix","folder","directory","regex","regexp","pattern","yes","true","canonicalRedirectKind","value","text","String","trim","toLowerCase","replace","REDIRECTS_DEFAULT_POLICY","fieldDefault","mode","blank","note","textOf","isBlankCell","undefined","PATTERN_CHARACTERS","redirectValuesEqual","field","a","b","left","right","test","stored","Number","isFinite"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GASD,SAAyBA,4BAA4B,EAAEC,uBAAuB,QAAQ,wBAAoB;AAC1G,SAASC,+BAA+B,EAAEC,+BAA+B,QAAQ,uCAAmC;AAEpH;;;;;;CAMC,GAED,8EAA8E,GAC9E,OAAO,MAAMC,yBAAyB,YAAW;AAEjD,mGAAmG,GACnG,OAAO,MAAMC,8BAA8B,WAAU;AAKrD,kEAAkE,GAClE,OAAO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E;gBAC1B,MAAMmE,OAAOR,OAAOM,GAAGd,IAAI;gBAC3B,MAAMiB,QAAQT,OAAOO,GAAGf,IAAI;gBAC5B,IAAIW,mBAAmBO,IAAI,CAACF,SAASL,mBAAmBO,IAAI,CAACD,QAAQ,OAAOD,SAASC;gBACrF,MAAME,SAAS5E,wBAAwByE;gBACvC,OAAOG,WAAW,QAAQA,WAAW5E,wBAAwB0E,SAAS,OAAOD,SAASC;YACxF;QACA,KAAKrE,eAAeG,WAAW;YAAE;gBAC/B,MAAMoE,SAAS7E,6BAA6BkE,OAAOM;gBACnD,OAAOK,WAAW,QAAQA,WAAW7E,6BAA6BkE,OAAOO,MAAM,OAAOP,OAAOM,GAAGd,IAAI,OAAOQ,OAAOO,GAAGf,IAAI;YAC3H;QACA,KAAKpD,eAAeE,IAAI;YAAE;gBACxB,MAAMA,OAAO8C,sBAAsBkB;gBACnC,OAAOhE,SAAS,QAAQA,SAAS8C,sBAAsBmB,KAAK,OAAOL;YACrE;QACA,KAAK9D,eAAeI,UAAU;QAC9B,KAAKJ,eAAeK,QAAQ;YAAE;gBAC5B,MAAM+D,OAAOI,OAAON;gBACpB,MAAMG,QAAQG,OAAOL;gBACrB,OAAOK,OAAOC,QAAQ,CAACL,SAASI,OAAOC,QAAQ,CAACJ,SAASD,SAASC,QAAQP;YAC5E;QACA;YACE,OAAOA;IACX;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/** The headers the read CSV carries; the alias dictionary maps each. */
|
|
18
|
+
export declare const SQUARESPACE_URL_MAPPING_HEADERS: {
|
|
19
|
+
readonly source: "URL mapping from";
|
|
20
|
+
readonly destination: "URL mapping to";
|
|
21
|
+
readonly statusCode: "URL mapping type";
|
|
22
|
+
readonly kind: "URL mapping match";
|
|
23
|
+
};
|
|
24
|
+
/** The dictionary's name, as the mapping step shows it. */
|
|
25
|
+
export declare const SQUARESPACE_URL_MAPPINGS_SOURCE = "Squarespace URL mappings";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ /*==========================================
|
|
17
|
+
* The Squarespace URL mappings read's column names (AGL-4245), apart from
|
|
18
|
+
* the parser: the transfer fields load with the plugin on every console
|
|
19
|
+
* screen, and the parser loads only when a file is read
|
|
20
|
+
* (`squarespace-url-mappings.ts`, check:plugin-budgets).
|
|
21
|
+
*=========================================*/ /** The headers the read CSV carries; the alias dictionary maps each. */ export const SQUARESPACE_URL_MAPPING_HEADERS = {
|
|
22
|
+
source: 'URL mapping from',
|
|
23
|
+
destination: 'URL mapping to',
|
|
24
|
+
statusCode: 'URL mapping type',
|
|
25
|
+
kind: 'URL mapping match'
|
|
26
|
+
};
|
|
27
|
+
/** The dictionary's name, as the mapping step shows it. */ export const SQUARESPACE_URL_MAPPINGS_SOURCE = 'Squarespace URL mappings';
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=squarespace-url-mapping-headers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/redirects/src/lib/transfer/squarespace-url-mapping-headers.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/*==========================================\n * The Squarespace URL mappings read's column names (AGL-4245), apart from\n * the parser: the transfer fields load with the plugin on every console\n * screen, and the parser loads only when a file is read\n * (`squarespace-url-mappings.ts`, check:plugin-budgets).\n *=========================================*/\n\n/** The headers the read CSV carries; the alias dictionary maps each. */\nexport const SQUARESPACE_URL_MAPPING_HEADERS = {\n source: 'URL mapping from',\n destination: 'URL mapping to',\n statusCode: 'URL mapping type',\n kind: 'URL mapping match',\n} as const\n\n/** The dictionary's name, as the mapping step shows it. */\nexport const SQUARESPACE_URL_MAPPINGS_SOURCE = 'Squarespace URL mappings'\n"],"names":["SQUARESPACE_URL_MAPPING_HEADERS","source","destination","statusCode","kind","SQUARESPACE_URL_MAPPINGS_SOURCE"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;;;2CAK2C,GAE3C,sEAAsE,GACtE,OAAO,MAAMA,kCAAkC;IAC7CC,QAAQ;IACRC,aAAa;IACbC,YAAY;IACZC,MAAM;AACR,EAAU;AAEV,yDAAyD,GACzD,OAAO,MAAMC,kCAAkC,2BAA0B"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { SQUARESPACE_URL_MAPPING_HEADERS, SQUARESPACE_URL_MAPPINGS_SOURCE } from './squarespace-url-mapping-headers';
|
|
18
|
+
export { SQUARESPACE_URL_MAPPING_HEADERS, SQUARESPACE_URL_MAPPINGS_SOURCE };
|
|
19
|
+
/** One rule as read. */
|
|
20
|
+
export interface SquarespaceUrlMapping {
|
|
21
|
+
/** The 1-based line in the text. */
|
|
22
|
+
line: number;
|
|
23
|
+
source: string;
|
|
24
|
+
destination: string;
|
|
25
|
+
/** 301 or 302; absent when the line gives no code. */
|
|
26
|
+
statusCode?: 301 | 302;
|
|
27
|
+
kind: 'exact' | 'regex';
|
|
28
|
+
}
|
|
29
|
+
/** A line that is not imported, and why, in words a person reads. */
|
|
30
|
+
export interface SquarespaceUrlMappingSkip {
|
|
31
|
+
line: number;
|
|
32
|
+
text: string;
|
|
33
|
+
reason: string;
|
|
34
|
+
}
|
|
35
|
+
export interface SquarespaceUrlMappingsRead {
|
|
36
|
+
rules: SquarespaceUrlMapping[];
|
|
37
|
+
skipped: SquarespaceUrlMappingSkip[];
|
|
38
|
+
}
|
|
39
|
+
/** Whether a text reads as Squarespace's URL mappings: every rule line has an arrow, and one reads as a rule. */
|
|
40
|
+
export declare function looksLikeSquarespaceUrlMappings(text: string): boolean;
|
|
41
|
+
/** Squarespace's URL mappings as rules, and the lines that are not imported. Pure. */
|
|
42
|
+
export declare function readSquarespaceUrlMappings(text: string): SquarespaceUrlMappingsRead;
|
|
43
|
+
/** What the upload step is handed for a text that is Squarespace's URL mappings. */
|
|
44
|
+
export interface SquarespaceUrlMappingsCsv {
|
|
45
|
+
/** The CSV the import reads: a header and one row per rule. */
|
|
46
|
+
text: string;
|
|
47
|
+
/** The format the text was read as. */
|
|
48
|
+
source: string;
|
|
49
|
+
/** Sentences the step shows above the preview: what was read, and each line not imported. */
|
|
50
|
+
notes: string[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The text as the CSV the import reads, or `null` when it is not Squarespace's
|
|
54
|
+
* URL mappings (the step then reads it as it always did).
|
|
55
|
+
*/
|
|
56
|
+
export declare function squarespaceUrlMappingsCsv(text: string): SquarespaceUrlMappingsCsv | null;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { escapeCsvCell } from "@aglyn/aglyn/app-utils/csv";
|
|
18
|
+
import { compileRedirectRegex } from "../model/redirects.js";
|
|
19
|
+
/*==========================================
|
|
20
|
+
* SQUARESPACE URL MAPPINGS (AGL-4245): the text a site owner copies out of
|
|
21
|
+
* Squarespace's Settings → URL Mappings, read into the CSV the redirects
|
|
22
|
+
* import already takes.
|
|
23
|
+
*
|
|
24
|
+
* Squarespace has no redirect export: its rules are one text box, one rule
|
|
25
|
+
* per line, `/old-path -> /new-path 301` (or `302`). Blank lines and lines
|
|
26
|
+
* that start with `#` are comments, and a line may carry extra spaces. A
|
|
27
|
+
* rule may name a part of the path with a variable, `[name]`, and use it on
|
|
28
|
+
* the right: `/blog/[name] -> /news/[name] 301`.
|
|
29
|
+
*
|
|
30
|
+
* Read in the browser, before the upload step shows the file, so every
|
|
31
|
+
* later step (mapping, review, dry run, apply, undo) is the import's own and
|
|
32
|
+
* nothing in it is Squarespace's. The columns written here are named in the
|
|
33
|
+
* `Squarespace URL mappings` alias dictionary, so they map on their own.
|
|
34
|
+
*
|
|
35
|
+
* A variable is one path segment, so a rule with one becomes a regex rule
|
|
36
|
+
* (the redirects page's own pattern mode): each variable is `([^/]+)` and the
|
|
37
|
+
* destination names it `$1`, `$2`, … in the order the left side gives them.
|
|
38
|
+
* A pattern that cannot be one (a destination naming a variable the left
|
|
39
|
+
* side lacks, more than nine variables, a pattern the matcher cannot run) is
|
|
40
|
+
* not imported, and the read lists it with why.
|
|
41
|
+
*=========================================*/ import { SQUARESPACE_URL_MAPPING_HEADERS, SQUARESPACE_URL_MAPPINGS_SOURCE } from "./squarespace-url-mapping-headers.js";
|
|
42
|
+
export { SQUARESPACE_URL_MAPPING_HEADERS, SQUARESPACE_URL_MAPPINGS_SOURCE };
|
|
43
|
+
/** One rule line, its spaces folded: a from, an arrow, a to, and an optional status code. */ const RULE_LINE = /^(\S+) ?-> ?(\S+)(?: (\d{3}))?$/;
|
|
44
|
+
/** A variable, `[name]`. */ const VARIABLE = /\[([^\]\s/]+)\]/g;
|
|
45
|
+
/** Whether a path names a variable. */ const hasVariable = (path)=>/\[[^\]\s/]+\]/.test(path);
|
|
46
|
+
/** The most capture groups a destination may name (`$1` … `$9`). */ const MAX_VARIABLES = 9;
|
|
47
|
+
/** The text's lines that are rules or attempts at one: comments and blank lines dropped, spaces folded. */ function ruleLines(text) {
|
|
48
|
+
return String(text != null ? text : '').replace(/^\uFEFF/, '').split(/\r\n|\r|\n/).map((raw, index)=>({
|
|
49
|
+
line: index + 1,
|
|
50
|
+
text: raw.trim().replace(/\s+/g, ' ')
|
|
51
|
+
})).filter((entry)=>entry.text && !entry.text.startsWith('#'));
|
|
52
|
+
}
|
|
53
|
+
/** Whether a text reads as Squarespace's URL mappings: every rule line has an arrow, and one reads as a rule. */ export function looksLikeSquarespaceUrlMappings(text) {
|
|
54
|
+
const lines = ruleLines(text);
|
|
55
|
+
if (!lines.length) return false;
|
|
56
|
+
if (!lines.every((entry)=>entry.text.includes('->'))) return false;
|
|
57
|
+
return lines.some((entry)=>RULE_LINE.test(entry.text));
|
|
58
|
+
}
|
|
59
|
+
const escapeRegex = (literal)=>literal.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
|
|
60
|
+
/**
|
|
61
|
+
* A pattern line as a regex rule's source and destination, or why it cannot
|
|
62
|
+
* be one. The literal parts are lowercased and a trailing slash dropped, as
|
|
63
|
+
* the serve path reads the address it matches.
|
|
64
|
+
*/ function patternRule(source, destination) {
|
|
65
|
+
const names = [];
|
|
66
|
+
let pattern = '';
|
|
67
|
+
let at = 0;
|
|
68
|
+
for (const found of source.matchAll(VARIABLE)){
|
|
69
|
+
var _found_index;
|
|
70
|
+
const index = (_found_index = found.index) != null ? _found_index : 0;
|
|
71
|
+
pattern += escapeRegex(source.slice(at, index).toLowerCase());
|
|
72
|
+
names.push(String(found[1]).toLowerCase());
|
|
73
|
+
pattern += '([^/]+)';
|
|
74
|
+
at = index + found[0].length;
|
|
75
|
+
}
|
|
76
|
+
pattern += escapeRegex(source.slice(at).toLowerCase().replace(/\/+$/, ''));
|
|
77
|
+
if (names.length > MAX_VARIABLES) {
|
|
78
|
+
return {
|
|
79
|
+
reason: `it has more than ${MAX_VARIABLES} [variables], which a redirect pattern cannot carry`
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (new Set(names).size !== names.length) {
|
|
83
|
+
return {
|
|
84
|
+
reason: 'it uses the same [variable] twice in the old address'
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
let missing = null;
|
|
88
|
+
const target = destination.replace(VARIABLE, (_token, name)=>{
|
|
89
|
+
const index = names.indexOf(name.toLowerCase());
|
|
90
|
+
if (index < 0) missing != null ? missing : missing = name;
|
|
91
|
+
return `$${index + 1}`;
|
|
92
|
+
});
|
|
93
|
+
if (missing) return {
|
|
94
|
+
reason: `it sends visitors to [${missing}], which the old address does not have`
|
|
95
|
+
};
|
|
96
|
+
const anchored = `^${pattern}$`;
|
|
97
|
+
if (!compileRedirectRegex(anchored)) return {
|
|
98
|
+
reason: 'its pattern cannot be used as a redirect'
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
source: anchored,
|
|
102
|
+
destination: target
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Squarespace's URL mappings as rules, and the lines that are not imported. Pure. */ export function readSquarespaceUrlMappings(text) {
|
|
106
|
+
const rules = [];
|
|
107
|
+
const skipped = [];
|
|
108
|
+
for (const entry of ruleLines(text)){
|
|
109
|
+
const matched = RULE_LINE.exec(entry.text);
|
|
110
|
+
if (!matched) {
|
|
111
|
+
skipped.push(_extends({}, entry, {
|
|
112
|
+
reason: 'it is not in the form /old-page -> /new-page 301'
|
|
113
|
+
}));
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const from = String(matched[1]);
|
|
117
|
+
const to = String(matched[2]);
|
|
118
|
+
const code = matched[3];
|
|
119
|
+
if (code && code !== '301' && code !== '302') {
|
|
120
|
+
skipped.push(_extends({}, entry, {
|
|
121
|
+
reason: `${code} is not a redirect type Squarespace uses; use 301 or 302`
|
|
122
|
+
}));
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const statusCode = code ? Number(code) : undefined;
|
|
126
|
+
if (!hasVariable(from) && !hasVariable(to)) {
|
|
127
|
+
rules.push(_extends({
|
|
128
|
+
line: entry.line,
|
|
129
|
+
source: from,
|
|
130
|
+
destination: to
|
|
131
|
+
}, statusCode ? {
|
|
132
|
+
statusCode
|
|
133
|
+
} : {}, {
|
|
134
|
+
kind: 'exact'
|
|
135
|
+
}));
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const rule = patternRule(from, to);
|
|
139
|
+
if ('reason' in rule) {
|
|
140
|
+
skipped.push(_extends({}, entry, {
|
|
141
|
+
reason: rule.reason
|
|
142
|
+
}));
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
rules.push(_extends({
|
|
146
|
+
line: entry.line
|
|
147
|
+
}, rule, statusCode ? {
|
|
148
|
+
statusCode
|
|
149
|
+
} : {}, {
|
|
150
|
+
kind: 'regex'
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
rules,
|
|
155
|
+
skipped
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The text as the CSV the import reads, or `null` when it is not Squarespace's
|
|
160
|
+
* URL mappings (the step then reads it as it always did).
|
|
161
|
+
*/ export function squarespaceUrlMappingsCsv(text) {
|
|
162
|
+
if (!looksLikeSquarespaceUrlMappings(text)) return null;
|
|
163
|
+
const read = readSquarespaceUrlMappings(text);
|
|
164
|
+
const header = [
|
|
165
|
+
SQUARESPACE_URL_MAPPING_HEADERS.source,
|
|
166
|
+
SQUARESPACE_URL_MAPPING_HEADERS.destination,
|
|
167
|
+
SQUARESPACE_URL_MAPPING_HEADERS.statusCode,
|
|
168
|
+
SQUARESPACE_URL_MAPPING_HEADERS.kind
|
|
169
|
+
];
|
|
170
|
+
const rows = read.rules.map((rule)=>[
|
|
171
|
+
rule.source,
|
|
172
|
+
rule.destination,
|
|
173
|
+
rule.statusCode ? String(rule.statusCode) : '',
|
|
174
|
+
rule.kind
|
|
175
|
+
]);
|
|
176
|
+
const patterns = read.rules.filter((rule)=>rule.kind === 'regex').length;
|
|
177
|
+
const count = `${read.rules.length} ${read.rules.length === 1 ? 'redirect' : 'redirects'}`;
|
|
178
|
+
const notes = [
|
|
179
|
+
`Read as ${SQUARESPACE_URL_MAPPINGS_SOURCE}: ${count}${patterns ? `, ${patterns} with [variables] brought in as patterns` : ''}.`,
|
|
180
|
+
...read.skipped.map((skip)=>`Line ${skip.line} is not imported: ${skip.reason}. (${skip.text})`)
|
|
181
|
+
];
|
|
182
|
+
return {
|
|
183
|
+
text: [
|
|
184
|
+
header,
|
|
185
|
+
...rows
|
|
186
|
+
].map((cells)=>cells.map((cell)=>escapeCsvCell(cell)).join(',')).join('\n') + '\n',
|
|
187
|
+
source: SQUARESPACE_URL_MAPPINGS_SOURCE,
|
|
188
|
+
notes
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=squarespace-url-mappings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/redirects/src/lib/transfer/squarespace-url-mappings.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 { escapeCsvCell } from '@aglyn/aglyn/app-utils/csv'\nimport { compileRedirectRegex } from '../model/redirects'\n\n/*==========================================\n * SQUARESPACE URL MAPPINGS (AGL-4245): the text a site owner copies out of\n * Squarespace's Settings → URL Mappings, read into the CSV the redirects\n * import already takes.\n *\n * Squarespace has no redirect export: its rules are one text box, one rule\n * per line, `/old-path -> /new-path 301` (or `302`). Blank lines and lines\n * that start with `#` are comments, and a line may carry extra spaces. A\n * rule may name a part of the path with a variable, `[name]`, and use it on\n * the right: `/blog/[name] -> /news/[name] 301`.\n *\n * Read in the browser, before the upload step shows the file, so every\n * later step (mapping, review, dry run, apply, undo) is the import's own and\n * nothing in it is Squarespace's. The columns written here are named in the\n * `Squarespace URL mappings` alias dictionary, so they map on their own.\n *\n * A variable is one path segment, so a rule with one becomes a regex rule\n * (the redirects page's own pattern mode): each variable is `([^/]+)` and the\n * destination names it `$1`, `$2`, … in the order the left side gives them.\n * A pattern that cannot be one (a destination naming a variable the left\n * side lacks, more than nine variables, a pattern the matcher cannot run) is\n * not imported, and the read lists it with why.\n *=========================================*/\n\nimport {\n SQUARESPACE_URL_MAPPING_HEADERS,\n SQUARESPACE_URL_MAPPINGS_SOURCE,\n} from './squarespace-url-mapping-headers'\n\nexport { SQUARESPACE_URL_MAPPING_HEADERS, SQUARESPACE_URL_MAPPINGS_SOURCE }\n\n/** One rule line, its spaces folded: a from, an arrow, a to, and an optional status code. */\nconst RULE_LINE = /^(\\S+) ?-> ?(\\S+)(?: (\\d{3}))?$/\n\n/** A variable, `[name]`. */\nconst VARIABLE = /\\[([^\\]\\s/]+)\\]/g\n\n/** Whether a path names a variable. */\nconst hasVariable = (path: string): boolean => /\\[[^\\]\\s/]+\\]/.test(path)\n\n/** The most capture groups a destination may name (`$1` … `$9`). */\nconst MAX_VARIABLES = 9\n\n/** One rule as read. */\nexport interface SquarespaceUrlMapping {\n /** The 1-based line in the text. */\n line: number\n source: string\n destination: string\n /** 301 or 302; absent when the line gives no code. */\n statusCode?: 301 | 302\n kind: 'exact' | 'regex'\n}\n\n/** A line that is not imported, and why, in words a person reads. */\nexport interface SquarespaceUrlMappingSkip {\n line: number\n text: string\n reason: string\n}\n\nexport interface SquarespaceUrlMappingsRead {\n rules: SquarespaceUrlMapping[]\n skipped: SquarespaceUrlMappingSkip[]\n}\n\n/** The text's lines that are rules or attempts at one: comments and blank lines dropped, spaces folded. */\nfunction ruleLines(text: string): Array<{ line: number; text: string }> {\n return String(text ?? '')\n .replace(/^\\uFEFF/, '')\n .split(/\\r\\n|\\r|\\n/)\n .map((raw, index) => ({ line: index + 1, text: raw.trim().replace(/\\s+/g, ' ') }))\n .filter((entry) => entry.text && !entry.text.startsWith('#'))\n}\n\n/** Whether a text reads as Squarespace's URL mappings: every rule line has an arrow, and one reads as a rule. */\nexport function looksLikeSquarespaceUrlMappings(text: string): boolean {\n const lines = ruleLines(text)\n if (!lines.length) return false\n if (!lines.every((entry) => entry.text.includes('->'))) return false\n return lines.some((entry) => RULE_LINE.test(entry.text))\n}\n\nconst escapeRegex = (literal: string): string => literal.replace(/[\\\\^$.*+?()[\\]{}|]/g, '\\\\$&')\n\n/**\n * A pattern line as a regex rule's source and destination, or why it cannot\n * be one. The literal parts are lowercased and a trailing slash dropped, as\n * the serve path reads the address it matches.\n */\nfunction patternRule(source: string, destination: string): { source: string; destination: string } | { reason: string } {\n const names: string[] = []\n let pattern = ''\n let at = 0\n for (const found of source.matchAll(VARIABLE)) {\n const index = found.index ?? 0\n pattern += escapeRegex(source.slice(at, index).toLowerCase())\n names.push(String(found[1]).toLowerCase())\n pattern += '([^/]+)'\n at = index + found[0].length\n }\n pattern += escapeRegex(source.slice(at).toLowerCase().replace(/\\/+$/, ''))\n if (names.length > MAX_VARIABLES) {\n return { reason: `it has more than ${MAX_VARIABLES} [variables], which a redirect pattern cannot carry` }\n }\n if (new Set(names).size !== names.length) {\n return { reason: 'it uses the same [variable] twice in the old address' }\n }\n let missing: string | null = null\n const target = destination.replace(VARIABLE, (_token, name: string) => {\n const index = names.indexOf(name.toLowerCase())\n if (index < 0) missing ??= name\n return `$${index + 1}`\n })\n if (missing) return { reason: `it sends visitors to [${missing}], which the old address does not have` }\n const anchored = `^${pattern}$`\n if (!compileRedirectRegex(anchored)) return { reason: 'its pattern cannot be used as a redirect' }\n return { source: anchored, destination: target }\n}\n\n/** Squarespace's URL mappings as rules, and the lines that are not imported. Pure. */\nexport function readSquarespaceUrlMappings(text: string): SquarespaceUrlMappingsRead {\n const rules: SquarespaceUrlMapping[] = []\n const skipped: SquarespaceUrlMappingSkip[] = []\n for (const entry of ruleLines(text)) {\n const matched = RULE_LINE.exec(entry.text)\n if (!matched) {\n skipped.push({ ...entry, reason: 'it is not in the form /old-page -> /new-page 301' })\n continue\n }\n const from = String(matched[1])\n const to = String(matched[2])\n const code = matched[3]\n if (code && code !== '301' && code !== '302') {\n skipped.push({ ...entry, reason: `${code} is not a redirect type Squarespace uses; use 301 or 302` })\n continue\n }\n const statusCode = code ? (Number(code) as 301 | 302) : undefined\n if (!hasVariable(from) && !hasVariable(to)) {\n rules.push({ line: entry.line, source: from, destination: to, ...(statusCode ? { statusCode } : {}), kind: 'exact' })\n continue\n }\n const rule = patternRule(from, to)\n if ('reason' in rule) {\n skipped.push({ ...entry, reason: rule.reason })\n continue\n }\n rules.push({ line: entry.line, ...rule, ...(statusCode ? { statusCode } : {}), kind: 'regex' })\n }\n return { rules, skipped }\n}\n\n/** What the upload step is handed for a text that is Squarespace's URL mappings. */\nexport interface SquarespaceUrlMappingsCsv {\n /** The CSV the import reads: a header and one row per rule. */\n text: string\n /** The format the text was read as. */\n source: string\n /** Sentences the step shows above the preview: what was read, and each line not imported. */\n notes: string[]\n}\n\n/**\n * The text as the CSV the import reads, or `null` when it is not Squarespace's\n * URL mappings (the step then reads it as it always did).\n */\nexport function squarespaceUrlMappingsCsv(text: string): SquarespaceUrlMappingsCsv | null {\n if (!looksLikeSquarespaceUrlMappings(text)) return null\n const read = readSquarespaceUrlMappings(text)\n const header = [\n SQUARESPACE_URL_MAPPING_HEADERS.source,\n SQUARESPACE_URL_MAPPING_HEADERS.destination,\n SQUARESPACE_URL_MAPPING_HEADERS.statusCode,\n SQUARESPACE_URL_MAPPING_HEADERS.kind,\n ]\n const rows = read.rules.map((rule) => [rule.source, rule.destination, rule.statusCode ? String(rule.statusCode) : '', rule.kind])\n const patterns = read.rules.filter((rule) => rule.kind === 'regex').length\n const count = `${read.rules.length} ${read.rules.length === 1 ? 'redirect' : 'redirects'}`\n const notes = [\n `Read as ${SQUARESPACE_URL_MAPPINGS_SOURCE}: ${count}${patterns ? `, ${patterns} with [variables] brought in as patterns` : ''}.`,\n ...read.skipped.map((skip) => `Line ${skip.line} is not imported: ${skip.reason}. (${skip.text})`),\n ]\n return {\n text: [header, ...rows].map((cells) => cells.map((cell) => escapeCsvCell(cell)).join(',')).join('\\n') + '\\n',\n source: SQUARESPACE_URL_MAPPINGS_SOURCE,\n notes,\n }\n}\n"],"names":["escapeCsvCell","compileRedirectRegex","SQUARESPACE_URL_MAPPING_HEADERS","SQUARESPACE_URL_MAPPINGS_SOURCE","RULE_LINE","VARIABLE","hasVariable","path","test","MAX_VARIABLES","ruleLines","text","String","replace","split","map","raw","index","line","trim","filter","entry","startsWith","looksLikeSquarespaceUrlMappings","lines","length","every","includes","some","escapeRegex","literal","patternRule","source","destination","names","pattern","at","found","matchAll","slice","toLowerCase","push","reason","Set","size","missing","target","_token","name","indexOf","anchored","readSquarespaceUrlMappings","rules","skipped","matched","exec","from","to","code","statusCode","Number","undefined","kind","rule","squarespaceUrlMappingsCsv","read","header","rows","patterns","count","notes","skip","cells","cell","join"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,aAAa,QAAQ,6BAA4B;AAC1D,SAASC,oBAAoB,QAAQ,wBAAoB;AAEzD;;;;;;;;;;;;;;;;;;;;;;2CAsB2C,GAE3C,SACEC,+BAA+B,EAC/BC,+BAA+B,QAC1B,uCAAmC;AAE1C,SAASD,+BAA+B,EAAEC,+BAA+B,GAAE;AAE3E,2FAA2F,GAC3F,MAAMC,YAAY;AAElB,0BAA0B,GAC1B,MAAMC,WAAW;AAEjB,qCA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