@aglyn/plugins-redirects 1.0.0-beta.221 → 1.0.0-beta.223
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/components/redirects-console-page.js +60 -30
- package/src/lib/components/redirects-console-page.js.map +1 -1
- package/src/lib/declarations.console-server.d.ts +29 -0
- package/src/lib/declarations.console-server.js +69 -0
- package/src/lib/declarations.console-server.js.map +1 -0
- package/src/lib/model/redirects.d.ts +75 -0
- package/src/lib/model/redirects.js +73 -0
- package/src/lib/model/redirects.js.map +1 -1
- package/src/lib/plugin.js +13 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/server/resolve-redirect.js +16 -6
- package/src/lib/server/resolve-redirect.js.map +1 -1
- package/src/lib/transfer/redirects-transfer-console.d.ts +18 -0
- package/src/lib/transfer/redirects-transfer-console.js +62 -0
- package/src/lib/transfer/redirects-transfer-console.js.map +1 -0
- package/src/lib/transfer/redirects-transfer-fields.d.ts +81 -0
- package/src/lib/transfer/redirects-transfer-fields.js +398 -0
- package/src/lib/transfer/redirects-transfer-fields.js.map +1 -0
- package/src/lib/transfer/redirects-transfer.d.ts +73 -0
- package/src/lib/transfer/redirects-transfer.js +986 -0
- package/src/lib/transfer/redirects-transfer.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-redirects",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.223",
|
|
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.0.0-beta.
|
|
29
|
-
"@aglyn/shared-data-mdi": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-ui-jsx": "1.0.0-beta.
|
|
31
|
-
"@aglyn/shared-ui-snackstack": "1.0.0-beta.
|
|
32
|
-
"@aglyn/shared-util-email": "1.0.0-beta.
|
|
33
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
34
|
-
"@aglyn/shared-util-timestamp": "1.0.0-beta.
|
|
35
|
-
"@aglyn/shared-util-tools": "1.0.0-beta.
|
|
36
|
-
"@aglyn/tenant-data-admin": "1.0.0-beta.
|
|
37
|
-
"@aglyn/tenant-feature-instance": "1.0.0-beta.
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.223",
|
|
29
|
+
"@aglyn/shared-data-mdi": "1.0.0-beta.223",
|
|
30
|
+
"@aglyn/shared-ui-jsx": "1.0.0-beta.223",
|
|
31
|
+
"@aglyn/shared-ui-snackstack": "1.0.0-beta.223",
|
|
32
|
+
"@aglyn/shared-util-email": "1.0.0-beta.223",
|
|
33
|
+
"@aglyn/shared-util-http": "1.0.0-beta.223",
|
|
34
|
+
"@aglyn/shared-util-timestamp": "1.0.0-beta.223",
|
|
35
|
+
"@aglyn/shared-util-tools": "1.0.0-beta.223",
|
|
36
|
+
"@aglyn/tenant-data-admin": "1.0.0-beta.223",
|
|
37
|
+
"@aglyn/tenant-feature-instance": "1.0.0-beta.223",
|
|
38
38
|
"@swc/helpers": "0.5.23"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
*/ 'use client';
|
|
17
17
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
18
18
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
-
import {
|
|
19
|
+
import { TransferResumeImport } from "@aglyn/aglyn/app-utils/transfer-resume-import";
|
|
20
|
+
import { checkQuota, pluginDocsHelp, useTransferLauncher } from "@aglyn/aglyn";
|
|
20
21
|
import { TENANT_APEX } from "@aglyn/aglyn/app-utils/tenant-apex";
|
|
21
|
-
import { isExternalRedirectDestination, isSelfRedirect, matchRedirect, normalizeRedirectDestination, normalizeRedirectSource, REDIRECT_DEFAULT_PRIORITY, validateRedirectRule, REDIRECT_STATUS_CODES } from "../model/index.js";
|
|
22
|
+
import { findDuplicateRedirect, isExternalRedirectDestination, isSelfRedirect, matchRedirect, normalizeRedirectDestination, normalizeRedirectSource, REDIRECT_DEFAULT_PRIORITY, redirectHitKey, redirectSourceIsLivePage, validateRedirectRule, REDIRECT_STATUS_CODES, walkRedirectChain } from "../model/index.js";
|
|
22
23
|
import { CardDisplay, useConfirmationContext } from "@aglyn/shared-ui-jsx";
|
|
24
|
+
import { REDIRECTS_TRANSFER_KEY } from "../transfer/redirects-transfer-fields.js";
|
|
23
25
|
import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
|
|
24
26
|
import QuotaReadoutComponent from "@aglyn/shared-ui-jsx/components/quota-readout.component";
|
|
25
27
|
import { useSnackbar } from "@aglyn/shared-ui-snackstack";
|
|
@@ -222,7 +224,6 @@ import { ceilingedWindow, collectionCeiling, useFirestore, useFirestoreCollectio
|
|
|
222
224
|
firestore,
|
|
223
225
|
hostId
|
|
224
226
|
]);
|
|
225
|
-
const idKey = (value)=>value.replace(/[.$#[\]/]/g, '_');
|
|
226
227
|
const totalHits = Object.values(hits != null ? hits : {}).reduce((sum, count)=>sum + count, 0);
|
|
227
228
|
const handleAdd = useCallback(()=>{
|
|
228
229
|
if (!entitled) {
|
|
@@ -293,7 +294,7 @@ import { ceilingedWindow, collectionCeiling, useFirestore, useFirestoreCollectio
|
|
|
293
294
|
hostId
|
|
294
295
|
]);
|
|
295
296
|
const handleSave = useCallback(async ()=>{
|
|
296
|
-
var _ref
|
|
297
|
+
var _ref;
|
|
297
298
|
if (!draft) return;
|
|
298
299
|
const kind = draft.kind || 'exact';
|
|
299
300
|
// Shared v2 validation (AGL-375): regex patterns must compile; path
|
|
@@ -326,9 +327,10 @@ import { ceilingedWindow, collectionCeiling, useFirestore, useFirestoreCollectio
|
|
|
326
327
|
persist: false
|
|
327
328
|
});
|
|
328
329
|
}
|
|
329
|
-
const duplicate = redirects
|
|
330
|
-
|
|
331
|
-
|
|
330
|
+
const duplicate = findDuplicateRedirect(redirects, {
|
|
331
|
+
$id: draft.id,
|
|
332
|
+
source,
|
|
333
|
+
kind
|
|
332
334
|
});
|
|
333
335
|
if (duplicate) {
|
|
334
336
|
return void enqueueSnackbar(`A rule for ${source} already exists`, {
|
|
@@ -338,27 +340,19 @@ import { ceilingedWindow, collectionCeiling, useFirestore, useFirestoreCollectio
|
|
|
338
340
|
}
|
|
339
341
|
// Chain-loop detection (AGL-156): follow internal destinations through
|
|
340
342
|
// the rule set; a walk that returns to this source can never execute.
|
|
341
|
-
if (
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
variant: 'warning',
|
|
351
|
-
persist: false
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
const next = bySource.get(cursor);
|
|
355
|
-
cursor = next && next.startsWith('/') ? next.toLowerCase() : undefined;
|
|
356
|
-
}
|
|
343
|
+
if (walkRedirectChain(redirects, {
|
|
344
|
+
$id: draft.id,
|
|
345
|
+
source,
|
|
346
|
+
destination
|
|
347
|
+
}).loop) {
|
|
348
|
+
return void enqueueSnackbar('That destination chains back to this rule — a redirect loop', {
|
|
349
|
+
variant: 'warning',
|
|
350
|
+
persist: false
|
|
351
|
+
});
|
|
357
352
|
}
|
|
358
353
|
// Screen-route collision: shadowing a live page may be intentional
|
|
359
354
|
// (moved pages) — warn, don't block (decision per the issue).
|
|
360
|
-
|
|
361
|
-
if (routedPaths.includes(source)) {
|
|
355
|
+
if (redirectSourceIsLivePage(host == null ? void 0 : host.screens, source)) {
|
|
362
356
|
enqueueSnackbar(`${source} is a published page — the redirect takes precedence`, {
|
|
363
357
|
variant: 'info',
|
|
364
358
|
persist: false
|
|
@@ -405,7 +399,7 @@ import { ceilingedWindow, collectionCeiling, useFirestore, useFirestoreCollectio
|
|
|
405
399
|
* stamp behind that a LATER edit back to an external target would inherit
|
|
406
400
|
* — approval carried across a destination nobody approved.
|
|
407
401
|
*/ const approval = isExternalRedirectDestination(destination) ? {
|
|
408
|
-
externalDestinationApprovedBy: (
|
|
402
|
+
externalDestinationApprovedBy: (_ref = currentUser == null ? void 0 : currentUser.uid) != null ? _ref : null
|
|
409
403
|
} : {
|
|
410
404
|
externalDestinationApprovedBy: deleteField()
|
|
411
405
|
};
|
|
@@ -468,9 +462,9 @@ import { ceilingedWindow, collectionCeiling, useFirestore, useFirestoreCollectio
|
|
|
468
462
|
persist: false
|
|
469
463
|
});
|
|
470
464
|
} catch (error) {
|
|
471
|
-
var
|
|
465
|
+
var _ref1;
|
|
472
466
|
console.error(error);
|
|
473
|
-
enqueueSnackbar((
|
|
467
|
+
enqueueSnackbar((_ref1 = error == null ? void 0 : error.message) != null ? _ref1 : 'An error has occurred', {
|
|
474
468
|
variant: 'error',
|
|
475
469
|
allowDuplicate: true
|
|
476
470
|
});
|
|
@@ -551,11 +545,47 @@ import { ceilingedWindow, collectionCeiling, useFirestore, useFirestoreCollectio
|
|
|
551
545
|
reportWriteFailure,
|
|
552
546
|
announceRuleChange
|
|
553
547
|
]);
|
|
548
|
+
/*
|
|
549
|
+
* Import and Export, through the console's transfer launcher (`null`
|
|
550
|
+
* outside the console shell, where there is no workspace to move rules in
|
|
551
|
+
* or out of). The list above is a live listener, so an import's rules show
|
|
552
|
+
* up without a refresh.
|
|
553
|
+
*/ const transfer = useTransferLauncher();
|
|
554
|
+
const transferTarget = {
|
|
555
|
+
resource: REDIRECTS_TRANSFER_KEY,
|
|
556
|
+
scope: 'host',
|
|
557
|
+
hostId
|
|
558
|
+
};
|
|
559
|
+
// Import for those who may write the records, Export for those who may read them.
|
|
560
|
+
const canImport = Boolean(transfer == null ? void 0 : transfer.can('import', transferTarget));
|
|
561
|
+
const canExport = Boolean(transfer == null ? void 0 : transfer.can('export', transferTarget));
|
|
562
|
+
const transferActions = transfer && (canImport || canExport) ? /*#__PURE__*/ _jsxs(Stack, {
|
|
563
|
+
direction: "row",
|
|
564
|
+
spacing: 1,
|
|
565
|
+
children: [
|
|
566
|
+
/*#__PURE__*/ _jsx(TransferResumeImport, {
|
|
567
|
+
target: transferTarget
|
|
568
|
+
}),
|
|
569
|
+
canImport && /*#__PURE__*/ _jsx(Button, {
|
|
570
|
+
size: "small",
|
|
571
|
+
onClick: ()=>transfer.openImport(transferTarget),
|
|
572
|
+
children: 'Import'
|
|
573
|
+
}),
|
|
574
|
+
canExport && /*#__PURE__*/ _jsx(Button, {
|
|
575
|
+
size: "small",
|
|
576
|
+
onClick: ()=>transfer.openExport(transferTarget),
|
|
577
|
+
children: 'Export'
|
|
578
|
+
})
|
|
579
|
+
]
|
|
580
|
+
}) : null;
|
|
554
581
|
return /*#__PURE__*/ _jsxs(CardDisplay, {
|
|
555
582
|
header: 'URL redirects',
|
|
556
583
|
help: pluginDocsHelp('redirects', {
|
|
557
584
|
anchor: '#manage-redirects'
|
|
558
585
|
}),
|
|
586
|
+
HeaderProps: transferActions ? {
|
|
587
|
+
action: transferActions
|
|
588
|
+
} : undefined,
|
|
559
589
|
contentGutterX: true,
|
|
560
590
|
contentGutterY: true,
|
|
561
591
|
children: [
|
|
@@ -573,7 +603,7 @@ import { ceilingedWindow, collectionCeiling, useFirestore, useFirestoreCollectio
|
|
|
573
603
|
children: `${totalHits} redirect hit${totalHits === 1 ? '' : 's'} in ` + 'the last 30 days (sampled — one per cache window with ' + 'traffic).'
|
|
574
604
|
}) : null,
|
|
575
605
|
visibleRedirects.map((redirect)=>{
|
|
576
|
-
var _redirect_statusCode, _redirect_kind,
|
|
606
|
+
var _redirect_statusCode, _redirect_kind, _hits_redirectHitKey;
|
|
577
607
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
578
608
|
direction: "row",
|
|
579
609
|
spacing: 1,
|
|
@@ -617,7 +647,7 @@ import { ceilingedWindow, collectionCeiling, useFirestore, useFirestoreCollectio
|
|
|
617
647
|
variant: "caption",
|
|
618
648
|
color: "text.secondary",
|
|
619
649
|
children: [
|
|
620
|
-
hits ? `${(
|
|
650
|
+
hits ? `${(_hits_redirectHitKey = hits[redirectHitKey(redirect.$id)]) != null ? _hits_redirectHitKey : 0} hits (30d, sampled)` : null,
|
|
621
651
|
redirect.lastHitAt ? `last ${redirect.lastHitAt.toDate().toLocaleString()}` : null
|
|
622
652
|
].filter(Boolean).join(' · ')
|
|
623
653
|
}) : null
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/redirects/src/lib/components/redirects-console-page.tsx"],"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'use client'\n\nimport { checkQuota, pluginDocsHelp } from '@aglyn/aglyn'\nimport { type ConsolePluginPageProps } from '@aglyn/aglyn'\nimport { TENANT_APEX } from '@aglyn/aglyn/app-utils/tenant-apex'\nimport { isExternalRedirectDestination, isSelfRedirect, matchRedirect, normalizeRedirectDestination, normalizeRedirectSource, REDIRECT_DEFAULT_PRIORITY, validateRedirectRule, REDIRECT_STATUS_CODES } from '../model'\nimport { CardDisplay, useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport QuotaReadoutComponent from '@aglyn/shared-ui-jsx/components/quota-readout.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { Timestamp } from '@aglyn/shared-util-timestamp'\nimport {\n Alert,\n Button,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport {\n collection,\n deleteField,\n doc,\n getCountFromServer,\n getDoc,\n setDoc,\n updateDoc,\n} from 'firebase/firestore'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { TABLE_PAGE_SIZE_DEFAULT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport {\n ceilingedWindow,\n collectionCeiling,\n useFirestore,\n useFirestoreCollection,\n useFirestoreDoc,\n useHostResourceApi,\n useUser,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\n\n/**\n * How many redirect documents this page reads.\n *\n * A CEILING, not a page size. Everything the page decides is computed over\n * the WHOLE rule set: the duplicate-source check, the chain-loop walk that\n * follows internal destinations through the rules, and the inline tester that\n * runs the enforcement matcher. A server page would give each of them a\n * tenth of the rules to reason about, and the duplicate check would then\n * create exactly the collision it exists to prevent.\n */\nconst REDIRECT_CEILING = 200\n\ninterface RedirectDraft {\n id: string | null\n source: string\n destination: string\n statusCode: number\n /** Match mode (AGL-375): exact | prefix | regex. */\n kind: string\n /** Lower fires first. */\n priority: number\n /**\n * The rule's on/off state, carried through the editor rather than reset by\n * it (AGL-1372). The save used to hardcode `true`, so changing a **disabled**\n * rule's target turned it back on and rerouted the site without the author\n * asking. A new rule seeds this `true`; an edit seeds it from the stored\n * rule, which is also where the row's switch reads from.\n */\n enabled: boolean\n}\n\n/**\n * Redirect manager (AGL-156): CRUD over `hosts/{hostId}/redirects` with\n * the shared AGL-154 validation (normalized sources, https-or-internal\n * destinations, self-redirect refusal, duplicate-source check). Paid\n * (`redirects` flag + `redirectsPerHost` quota); rules take effect on the\n * site within ~30 seconds (AGL-155 ISR window).\n *\n * The plan gate is the SHELL's, and it runs before this component exists\n * (AGL-2484): the console resolves `redirects` from the org billing doc and\n * renders its own refusal notice in place of the surface, so this card is\n * only ever mounted for an entitled org and states no plan terms of its own.\n * Redirects registers no `upgradeNotice` override because it is a genuine\n * upgrade — free denies it, Starter and above grant it — which makes the\n * shell's plan-derived sentence the accurate one already.\n *\n * `entitled` is still read below, where it is not redundant: it holds back\n * the thirty analytics day-doc reads behind the hit counts, and refuses the\n * add path ahead of the server that enforces it.\n */\nexport function RedirectsConsolePage(props: ConsolePluginPageProps) {\n const { hostId, entitled, org } = props\n const firestore = useFirestore()\n const createHostResource = useHostResourceApi()\n const { data: currentUser } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const { confirm } = useConfirmationContext()\n\n const {\n data: redirectDocs,\n status: redirectsStatus,\n /**\n * The rows this editor is seeded from are unconfirmed by the server\n * (AGL-1358). Editing copies every field the form owns out of the stored\n * rule and writes all of them back, so `merge: true` protects only the\n * fields written elsewhere (`lastHitAt`, `deletedAt`). This is the site\n * where a rollback is hardest to undo: a reverted `destination` on a\n * **301** is cached by every browser that has already followed it, so the\n * stale target outlives the fix in the console. `kind` reverting from\n * exact to prefix silently widens a rule over a whole subtree, and\n * `priority` reorders which rule fires when several match.\n */\n fromCache: redirectsFromCache,\n } = useFirestoreCollection<any>(\n /*\n * ORDERED AND CEILINGED, with a probe (AGL-2501).\n *\n * `limit(200)` alone is answered in DOCUMENT-ID order and the ids are\n * generated, so the window was a pseudo-random two hundred of the site's\n * rules — sorted by `source` in the browser afterwards, which is what\n * made it invisible: the rules on screen run alphabetically and are\n * simply the wrong rules, and the ones missing leave no gap to notice.\n *\n * `orderBy('source')` is the tempting fix and the dangerous one. It\n * matches only documents that HAVE the field, and nothing validates\n * `source` for presence — `/api/hosts/resources` stores an allow-list of\n * fields and checks none of them — so a rule saved without one would\n * vanish from this page while still redirecting live traffic. The\n * document NAME cannot be absent, so the walk is total: every rule is\n * reachable, and the alphabetical order stays where it belongs, in the\n * sort below over a window the page holds whole.\n */\n () =>\n collectionCeiling(\n collection(firestore, 'hosts', hostId, 'redirects'),\n REDIRECT_CEILING,\n ),\n [firestore, hostId],\n { idField: '$id' },\n )\n const { rows: readRedirects, truncated: redirectsTruncated } =\n ceilingedWindow<any>(redirectDocs, REDIRECT_CEILING)\n const redirects = [...readRedirects]\n .filter((redirect: any) => !redirect.deletedAt)\n .sort((a: any, b: any) =>\n String(a.source ?? '').localeCompare(String(b.source ?? '')),\n )\n\n /*\n * The page is a SLICE of the ceiling, which is what the three whole-set\n * consumers above require. The count is the rules this page HOLDS, after\n * soft-deleted ones are dropped — not the quota, which is a server count of\n * every document including the soft-deleted, and is read separately below.\n */\n const [page, setPage] = useState(0)\n const [pageSize, setPageSize] = useState(TABLE_PAGE_SIZE_DEFAULT)\n const visibleRedirects = useMemo(\n () => redirects.slice(page * pageSize, page * pageSize + pageSize),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [redirectDocs, page, pageSize],\n )\n\n /**\n * What the ENFORCING route counts, which is not what this page was counting.\n *\n * `hosts/{id}/redirects` is read here as an unordered `limit(200)` window\n * and then filtered to drop soft-deleted rows, and that filtered length was\n * feeding both `checkQuota('redirectsPerHost')` and the readout beside it.\n * The route in `app/api/hosts/resources` counts the collection plainly —\n * `collectionRef.count()`, every document, soft-deleted ones included — so\n * the two disagreed on both counts at once: a rule deleted in this console\n * still occupies a slot on the server, and a site past 200 rules has rows\n * the window never saw.\n *\n * The visible effect is the worst kind: the page shows room, the author\n * fills in the form, and the save is refused by a server counting something\n * else. Same shape as AGL-1716.\n *\n * An aggregation query, so it costs one read unit per thousand documents\n * rather than reading them. Re-run when the document set changes, which\n * covers an add; a soft delete leaves the document in place and so does not\n * move this number — correctly, because it does not move the server's\n * either.\n *\n * Only the COUNT is corrected here. Whether a soft-deleted rule should go on\n * occupying a slot is the quota RULE, and that lives with the enforcing\n * route.\n */\n const [enforcedCount, setEnforcedCount] = useState<number | null>(null)\n const redirectDocCount = redirectDocs?.length ?? 0\n\n /**\n * `null` when the count cannot be taken, never a number.\n *\n * `try`, not `.catch()`: `getCountFromServer` validates its reference and\n * THROWS synchronously on a bad one, so a rejection handler alone leaves the\n * error to escape the effect and take the page down with it. Unreadable is\n * also not zero — answering zero would tell an author at their cap that the\n * whole allowance is free.\n */\n const countRedirects = useCallback(async (): Promise<number | null> => {\n try {\n const snapshot = await getCountFromServer(\n collection(firestore, 'hosts', hostId, 'redirects'),\n )\n return snapshot.data().count\n } catch {\n return null\n }\n }, [firestore, hostId])\n\n useEffect(() => {\n let active = true\n void countRedirects().then((count) => {\n if (active && count != null) setEnforcedCount(count)\n })\n return () => {\n active = false\n }\n }, [countRedirects, redirectDocCount])\n\n const [draft, setDraft] = useState<RedirectDraft | null>(null)\n const [testPath, setTestPath] = useState('')\n\n // Host routing map for the screen-collision warning (AGL-156 spec).\n const { data: host } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId),\n [firestore, hostId],\n { idField: '$id' },\n )\n\n // Sampled hit counts (AGL-157): summed from the last 30 analytics day\n // docs' `redirects` maps written by enforcement. Counts are sampled —\n // one per ISR revalidation window with traffic, not per request.\n const [hits, setHits] = useState<Record<string, number> | null>(null)\n useEffect(() => {\n if (!entitled) return\n let active = true\n const ids = Array.from({ length: 30 }, (_, index) => {\n const date = new Date()\n date.setDate(date.getDate() - index)\n return date.toISOString().slice(0, 10)\n })\n void Promise.all(\n ids.map((id) =>\n getDoc(doc(firestore, 'hosts', hostId, 'analytics', id))\n .then((snapshot) => (snapshot.get('redirects') ?? {}) as Record<string, number>)\n .catch(() => ({}) as Record<string, number>),\n ),\n ).then((days) => {\n if (!active) return\n const totals: Record<string, number> = {}\n for (const dayMap of days) {\n for (const [redirectId, count] of Object.entries(dayMap)) {\n totals[redirectId] = (totals[redirectId] ?? 0) + Number(count)\n }\n }\n setHits(totals)\n })\n return () => {\n active = false\n }\n }, [entitled, firestore, hostId])\n const idKey = (value: string) => value.replace(/[.$#[\\]/]/g, '_')\n const totalHits = Object.values(hits ?? {}).reduce(\n (sum, count) => sum + count,\n 0,\n )\n\n const handleAdd = useCallback(() => {\n if (!entitled) {\n return void enqueueSnackbar(\n 'URL redirects require a Starter plan — see Billing to upgrade',\n { variant: 'warning', persist: false },\n )\n }\n /*\n * The SERVER's count, not the rows on screen — the whole point of this\n * fix. Read from the polled value rather than re-counted on the click:\n * this gate is a courtesy that spares the author a form they are about to\n * be refused, the route is the actual enforcer, and making the button\n * await an aggregation would delay the dialog on every press to sharpen a\n * number the server re-checks anyway.\n *\n * `null` means the count could not be read, and that lets the add through:\n * refusing on a number we do not have would block an author who may well\n * be inside their cap.\n */\n const quota = checkQuota(org, 'redirectsPerHost', enforcedCount ?? 0)\n if (!quota.allowed) {\n return void enqueueSnackbar(\n `Redirect limit reached (${quota.limit}) — upgrade in Billing`,\n { variant: 'warning', persist: false },\n )\n }\n setDraft({\n id: null,\n source: '',\n destination: '',\n statusCode: 302,\n kind: 'exact',\n priority: REDIRECT_DEFAULT_PRIORITY,\n // A NEW rule is on: the author is adding it to make it fire, and\n // enforcement queries `where('enabled', '==', true)`, so a rule created\n // without the field would never resolve (AGL-1372).\n enabled: true,\n })\n }, [entitled, org, enforcedCount, enqueueSnackbar])\n\n /**\n * Tell the tenant a rule changed (best effort, never awaited into the save\n * outcome). Rule writes are client Firestore writes with no publish step,\n * and the tenant's rules list sits behind the hour-long\n * `tenant-data:{hostId}` backstop — without this call a new rule waits out\n * that TTL while the snackbar above promises ~30 seconds. The route busts\n * the host tag and drops the source path's cached HTML; a regex pattern has\n * no single literal path, so it announces `/` for the tag bust alone and\n * the matching pages catch up on their own ISR window.\n */\n const announceRuleChange = useCallback(\n (source: string | undefined) => {\n const redirectPath =\n typeof source === 'string' && source.startsWith('/') ? source : '/'\n void authorizedFetch(currentUser, '/api/screens/revalidate', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, redirectPath }),\n }).catch(() => undefined)\n },\n [currentUser, hostId],\n )\n\n const handleSave = useCallback(async () => {\n if (!draft) return\n const kind = draft.kind || 'exact'\n // Shared v2 validation (AGL-375): regex patterns must compile; path\n // kinds keep the v1 normalization. A destination that wears another\n // brand is refused (AGL-3447); the site's own hosts never do.\n const problem = validateRedirectRule(\n {\n kind,\n source: draft.source,\n destination: draft.destination,\n },\n {\n ownDomains: [\n typeof host?.cname === 'string' ? host.cname : null,\n typeof host?.subdomain === 'string' && host.subdomain\n ? `${host.subdomain}.${TENANT_APEX}`\n : null,\n ],\n },\n )\n if (problem) {\n return void enqueueSnackbar(problem, {\n variant: 'warning',\n persist: false,\n })\n }\n const source =\n kind === 'regex'\n ? draft.source.trim()\n : (normalizeRedirectSource(draft.source) as string)\n const destination = normalizeRedirectDestination(\n draft.destination,\n ) as string\n if (kind !== 'regex' && isSelfRedirect({ source, destination })) {\n return void enqueueSnackbar('That would redirect the path to itself', {\n variant: 'warning',\n persist: false,\n })\n }\n const duplicate = redirects.find(\n (redirect: any) =>\n redirect.source === source &&\n (redirect.kind ?? 'exact') === kind &&\n redirect.$id !== draft.id,\n )\n if (duplicate) {\n return void enqueueSnackbar(`A rule for ${source} already exists`, {\n variant: 'warning',\n persist: false,\n })\n }\n // Chain-loop detection (AGL-156): follow internal destinations through\n // the rule set; a walk that returns to this source can never execute.\n if (destination.startsWith('/')) {\n const bySource = new Map<string, string>(\n redirects\n .filter((redirect: any) => redirect.$id !== draft.id)\n .map((redirect: any) => [redirect.source, redirect.destination]),\n )\n let cursor: string | undefined = destination.toLowerCase()\n for (let hop = 0; hop < 10 && cursor; hop += 1) {\n if (cursor === source) {\n return void enqueueSnackbar(\n 'That destination chains back to this rule — a redirect loop',\n { variant: 'warning', persist: false },\n )\n }\n const next: string | undefined = bySource.get(cursor)\n cursor = next && next.startsWith('/') ? next.toLowerCase() : undefined\n }\n }\n // Screen-route collision: shadowing a live page may be intentional\n // (moved pages) — warn, don't block (decision per the issue).\n const routedPaths = Object.values(\n (host?.screens ?? {}) as Record<string, string>,\n ).map((path) => (path === '/' ? '/' : `/${path}`))\n if (routedPaths.includes(source)) {\n enqueueSnackbar(\n `${source} is a published page — the redirect takes precedence`,\n { variant: 'info', persist: false },\n )\n }\n const fields = {\n source,\n destination,\n statusCode: (REDIRECT_STATUS_CODES as readonly number[]).includes(\n draft.statusCode,\n )\n ? draft.statusCode\n : 302,\n kind,\n priority: Number.isFinite(Number(draft.priority))\n ? Number(draft.priority)\n : REDIRECT_DEFAULT_PRIORITY,\n /**\n * Whatever the rule already was (AGL-1372). This was `true`, so editing\n * a **disabled** rule's target silently re-enabled it — a deliberate\n * \"off\" (a retired campaign, a rule that broke something) undone by a\n * routine save, changing site routing without the author asking.\n *\n * `!== false` rather than the raw value, because the switch below reads\n * the stored field the same way: absent means on. Enforcement's query is\n * `where('enabled', '==', true)`, so a rule missing the field is not\n * served, and normalising it here makes the console's claim true.\n *\n * The create default lives in `handleAdd` — a new rule seeds the draft\n * `true`, so both defaults hold without either one reading the other.\n */\n enabled: draft.enabled !== false,\n }\n /**\n * The publisher's stamp on an external destination (AGL-1881).\n *\n * `matchRedirect` will not send traffic off the platform without it, and\n * `cloud/firebase-firestore.rules` admits no write to this collection from\n * anyone but `canPublishHostContent` — so reaching this line at all is the\n * approval, and saving is how a rule written before that fix starts firing\n * again.\n *\n * Written on EDIT only. A create rides /api/hosts/resources, which stamps\n * the same field from the id token's verified uid; sending it from here\n * would be the client supplying its own provenance, and that route drops\n * it for exactly that reason.\n *\n * Cleared with `deleteField()` when the destination is internal, rather\n * than left standing. `merge: true` never removes a key, so an edit from\n * `https://elsewhere.example` back to `/pricing` would otherwise leave a\n * stamp behind that a LATER edit back to an external target would inherit\n * — approval carried across a destination nobody approved.\n */\n const approval = isExternalRedirectDestination(destination)\n ? { externalDestinationApprovedBy: currentUser?.uid ?? null }\n : { externalDestinationApprovedBy: deleteField() }\n try {\n if (draft.id) {\n /**\n * Edit stays client-direct (no quota consumed) — and is refused when\n * its seed was never confirmed by the server (AGL-1358); the eight\n * validation refusals above have all already returned by here.\n *\n * `merge: true` is load-bearing, contrary to what this said before\n * (AGL-1372): `fields` is every key the FORM owns, not every key the\n * document holds. `lastHitAt` is written by enforcement\n * (`resolve-redirect`), and `deletedAt` by the delete below — a\n * replacing write would erase both.\n *\n * The guard WRAPS the write. An early return is a shape you can keep\n * while losing the protection; here the write is only reachable\n * through the verdict.\n */\n const verdict = await writeGuardedBySeed(\n {\n subject: 'redirect',\n unreadable: redirectsStatus === 'error',\n fromCache: redirectsFromCache,\n },\n async () => {\n await setDoc(\n doc(firestore, 'hosts', hostId, 'redirects', draft.id),\n { ...fields, ...approval, updatedAt: Timestamp.now() },\n { merge: true },\n )\n },\n )\n // Before `setDraft(null)`, so a refusal keeps the dialog open with\n // what was typed, in the same warning vocabulary as the validation\n // refusals above it.\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, {\n variant: 'warning',\n persist: false,\n })\n }\n } else {\n // New redirect rides the quota-enforcing resources API (AGL-473) —\n // it also re-checks the `redirects` entitlement server-side.\n await createHostResource({ hostId, resource: 'redirect', data: fields })\n }\n // The changed rule, and — when an edit moved the source — the path\n // that just STOPPED redirecting, so its page refreshes too.\n announceRuleChange(source)\n if (draft.id) {\n const previous = (redirects ?? []).find(\n (rule: any) => rule.$id === draft.id,\n )?.source\n if (previous && previous !== source) announceRuleChange(previous)\n }\n setDraft(null)\n enqueueSnackbar('Redirect saved — live within ~30 seconds', {\n variant: 'success',\n persist: false,\n })\n } catch (error: any) {\n console.error(error)\n enqueueSnackbar(error?.message ?? 'An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n }, [\n draft,\n redirects,\n host,\n firestore,\n hostId,\n createHostResource,\n currentUser,\n enqueueSnackbar,\n redirectsStatus,\n redirectsFromCache,\n announceRuleChange,\n ])\n\n /**\n * A refusal has to be visible (AGL-1881).\n *\n * These two writes were bare `await`s. The rules now gate this collection on\n * a publishing role, so an `author` reaching either gets a\n * permission-denied — and an unhandled rejection renders as a control that\n * flips back with no error, which is the worst way to say no. `handleSave`\n * has always ended in a snackbar; these now match it.\n *\n * The card is not role-gated on purpose: it is entitlement-gated, and the\n * rules leave READ to the catch-all so an author can still see the rules\n * that affect the pages they write.\n */\n const reportWriteFailure = useCallback(\n (error: any) => {\n enqueueSnackbar(\n error?.code === 'permission-denied'\n ? 'Changing a redirect needs a publishing role — ask an editor or admin'\n : (error?.message ?? 'An error has occurred'),\n { variant: 'warning', persist: false },\n )\n },\n [enqueueSnackbar],\n )\n\n const handleToggle = useCallback(\n (redirect: any) => async (event: { target: { checked: boolean } }) => {\n try {\n await updateDoc(\n doc(firestore, 'hosts', hostId, 'redirects', redirect.$id),\n { enabled: event.target.checked, updatedAt: Timestamp.now() },\n )\n announceRuleChange(redirect.source)\n } catch (error: any) {\n reportWriteFailure(error)\n }\n },\n [firestore, hostId, reportWriteFailure, announceRuleChange],\n )\n\n const handleDelete = useCallback(\n (redirect: any) => async () => {\n const confirmed = await confirm({\n title: 'Delete this redirect?',\n description: `${redirect.source} stops redirecting.`,\n confirmationText: 'Delete',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n try {\n await updateDoc(\n doc(firestore, 'hosts', hostId, 'redirects', redirect.$id),\n { deletedAt: Timestamp.now(), enabled: false },\n )\n announceRuleChange(redirect.source)\n } catch (error: any) {\n reportWriteFailure(error)\n }\n },\n [confirm, firestore, hostId, reportWriteFailure, announceRuleChange],\n )\n\n return (\n <CardDisplay\n header={'URL redirects'}\n help={pluginDocsHelp('redirects', { anchor: '#manage-redirects' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Exact-path rules; 302 while testing, promote to 301 when ' +\n 'sure (browsers cache 301 aggressively). Changes go live ' +\n 'within ~30 seconds.'}\n </Typography>\n {hits && totalHits > 0 ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${totalHits} redirect hit${totalHits === 1 ? '' : 's'} in ` +\n 'the last 30 days (sampled — one per cache window with ' +\n 'traffic).'}\n </Typography>\n ) : null}\n {visibleRedirects.map((redirect: any) => (\n <Stack\n key={redirect.$id}\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center' }}\n >\n <Switch\n size=\"small\"\n checked={redirect.enabled !== false}\n onChange={handleToggle(redirect)}\n />\n <Chip size=\"small\" label={redirect.statusCode ?? 302} />\n {(redirect.kind ?? 'exact') !== 'exact' ? (\n <Chip\n size=\"small\"\n variant=\"outlined\"\n label={redirect.kind}\n />\n ) : null}\n {/* An external rule with no publisher stamp is not being served\n (AGL-1881) — `matchRedirect` skips it. Say so on the row\n rather than letting it read as live: a rule that silently\n stops firing is the failure mode a fail-closed gate owes an\n explanation for, and pressing Edit → Save is the whole fix.\n Shown for external destinations only, since that is the only\n case the gate applies to. */}\n {isExternalRedirectDestination(redirect.destination) &&\n !redirect.externalDestinationApprovedBy ? (\n <Chip\n size=\"small\"\n color=\"warning\"\n variant=\"outlined\"\n label=\"not serving\"\n title={\n 'This rule sends visitors to another site. Open it and ' +\n 'save to confirm the destination — until then it is ' +\n 'skipped.'\n }\n />\n ) : null}\n <Stack sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {`${redirect.source} → ${redirect.destination}`}\n </Typography>\n {hits || redirect.lastHitAt ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {[\n hits\n ? `${hits[idKey(redirect.$id)] ?? 0} hits (30d, sampled)`\n : null,\n redirect.lastHitAt\n ? `last ${redirect.lastHitAt\n .toDate()\n .toLocaleString()}`\n : null,\n ]\n .filter(Boolean)\n .join(' · ')}\n </Typography>\n ) : null}\n </Stack>\n <Button\n size=\"small\"\n onClick={() =>\n setDraft({\n id: redirect.$id,\n source: redirect.source ?? '',\n destination: redirect.destination ?? '',\n statusCode: redirect.statusCode ?? 302,\n kind: redirect.kind ?? 'exact',\n priority: redirect.priority ?? REDIRECT_DEFAULT_PRIORITY,\n // Read exactly as the switch beside it does (AGL-1372):\n // an edit must not be a way to turn a rule back on.\n enabled: redirect.enabled !== false,\n })\n }\n >\n {'Edit'}\n </Button>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={handleDelete(redirect)}\n >\n {'Delete'}\n </Button>\n </Stack>\n ))}\n {redirects.length === 0 ? null : (\n <ListPagination\n page={page}\n pageSize={pageSize}\n rowCount={visibleRedirects.length}\n // The rules this page HOLDS, after the soft-deleted ones are\n // dropped. Not the quota figure below it: that is a server\n // count over every document, soft-deleted rows included,\n // because a deleted rule still occupies a slot.\n count={redirects.length}\n onPageChange={setPage}\n onPageSizeChange={setPageSize}\n />\n )}\n {redirectsTruncated ? (\n <Alert severity=\"info\">\n {`Showing ${REDIRECT_CEILING} rules, ordered by id. This site ` +\n 'has more — the duplicate check and the tester below only ' +\n 'cover the ones listed here.'}\n </Alert>\n ) : null}\n <Button\n size=\"small\"\n color=\"primary\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={handleAdd}\n >\n {'Add redirect'}\n </Button>\n {/* The cap, standing rather than only on refusal (AGL-2113).\n `enforcedCount` is what the enforcing route counts and what\n `handleAdd` checks against, so the readout, the gate and the\n server cannot disagree. It is deliberately NOT the number of rows\n on screen: a soft-deleted rule still occupies a slot, so showing\n the visible count here would promise room the server refuses. */}\n <QuotaReadoutComponent\n ready={org != null && enforcedCount != null}\n used={enforcedCount ?? 0}\n limit={\n checkQuota(org, 'redirectsPerHost', enforcedCount ?? 0).limit\n }\n noun=\"redirect\"\n />\n {/* Inline tester (AGL-375): same matcher as enforcement. */}\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <TextField\n size=\"small\"\n label=\"Test a path\"\n placeholder=\"/old-page\"\n value={testPath}\n onChange={(event) => setTestPath(event.target.value)}\n sx={{ maxWidth: 260 }}\n />\n {testPath.trim() ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {(() => {\n const normalized =\n normalizeRedirectSource(testPath) ?? testPath.trim()\n const result = matchRedirect(redirects as any, normalized)\n return result\n ? `→ ${result.destination} (${result.statusCode})`\n : 'No rule matches'\n })()}\n </Typography>\n ) : null}\n </Stack>\n </Stack>\n\n <Dialog\n open={Boolean(draft)}\n onClose={() => setDraft(null)}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>{draft?.id ? 'Edit redirect' : 'Add redirect'}</DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 1.5, pt: 1 }}\n >\n <TextField\n select\n label=\"Match mode\"\n value={draft?.kind ?? 'exact'}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, kind: event.target.value } : prev,\n )\n }\n size=\"small\"\n sx={{ mt: 1 }}\n >\n <MenuItem value=\"exact\">{'Exact path'}</MenuItem>\n <MenuItem value=\"prefix\">{'Path prefix'}</MenuItem>\n <MenuItem value=\"regex\">{'Regular expression'}</MenuItem>\n </TextField>\n <TextField\n label={draft?.kind === 'regex' ? 'Pattern' : 'From path'}\n placeholder={\n draft?.kind === 'regex' ? '/product/(\\\\d+)' : '/old-page'\n }\n helperText={\n draft?.kind === 'regex'\n ? 'Anchored to the whole path; use $1, $2 in the destination'\n : draft?.kind === 'prefix'\n ? 'Matches the path and everything under it'\n : undefined\n }\n value={draft?.source ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, source: event.target.value } : prev,\n )\n }\n size=\"small\"\n autoFocus\n />\n <TextField\n label=\"To\"\n placeholder=\"/new-page or https://example.com\"\n value={draft?.destination ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, destination: event.target.value } : prev,\n )\n }\n size=\"small\"\n />\n <TextField\n select\n label=\"Status code\"\n value={draft?.statusCode ?? 302}\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? { ...prev, statusCode: Number(event.target.value) }\n : prev,\n )\n }\n size=\"small\"\n >\n <MenuItem value={302}>{'302 — temporary (default)'}</MenuItem>\n <MenuItem value={301}>{'301 — permanent'}</MenuItem>\n <MenuItem value={307}>{'307 — temporary, keep method'}</MenuItem>\n <MenuItem value={308}>{'308 — permanent, keep method'}</MenuItem>\n </TextField>\n <TextField\n label=\"Priority\"\n type=\"number\"\n helperText=\"Lower fires first when several rules match\"\n value={draft?.priority ?? REDIRECT_DEFAULT_PRIORITY}\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? { ...prev, priority: Number(event.target.value) }\n : prev,\n )\n }\n size=\"small\"\n />\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setDraft(null)}>{'Cancel'}</Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!draft?.source.trim() || !draft?.destination.trim()}\n onClick={handleSave}\n >\n {'Save redirect'}\n </Button>\n </DialogActions>\n </Dialog>\n </CardDisplay>\n )\n}\nRedirectsConsolePage.displayName = 'RedirectsConsolePage'\n\nexport default RedirectsConsolePage\n"],"names":["checkQuota","pluginDocsHelp","TENANT_APEX","isExternalRedirectDestination","isSelfRedirect","matchRedirect","normalizeRedirectDestination","normalizeRedirectSource","REDIRECT_DEFAULT_PRIORITY","validateRedirectRule","REDIRECT_STATUS_CODES","CardDisplay","useConfirmationContext","authorizedFetch","QuotaReadoutComponent","useSnackbar","Timestamp","Alert","Button","Chip","Dialog","DialogActions","DialogContent","DialogTitle","MenuItem","Stack","Switch","TextField","Typography","collection","deleteField","doc","getCountFromServer","getDoc","setDoc","updateDoc","useCallback","useEffect","useMemo","useState","ListPagination","TABLE_PAGE_SIZE_DEFAULT","ceilingedWindow","collectionCeiling","useFirestore","useFirestoreCollection","useFirestoreDoc","useHostResourceApi","useUser","writeGuardedBySeed","REDIRECT_CEILING","RedirectsConsolePage","props","hostId","entitled","org","firestore","createHostResource","data","currentUser","enqueueSnackbar","confirm","redirectDocs","status","redirectsStatus","fromCache","redirectsFromCache","idField","rows","readRedirects","truncated","redirectsTruncated","redirects","filter","redirect","deletedAt","sort","a","b","String","source","localeCompare","page","setPage","pageSize","setPageSize","visibleRedirects","slice","enforcedCount","setEnforcedCount","redirectDocCount","length","countRedirects","snapshot","count","active","then","draft","setDraft","testPath","setTestPath","host","hits","setHits","ids","Array","from","_","index","date","Date","setDate","getDate","toISOString","Promise","all","map","id","get","catch","days","totals","dayMap","redirectId","Object","entries","Number","idKey","value","replace","totalHits","values","reduce","sum","handleAdd","variant","persist","quota","allowed","limit","destination","statusCode","kind","priority","enabled","announceRuleChange","redirectPath","startsWith","method","headers","body","JSON","stringify","undefined","handleSave","problem","ownDomains","cname","subdomain","trim","duplicate","find","$id","bySource","Map","cursor","toLowerCase","hop","next","routedPaths","screens","path","includes","fields","isFinite","approval","externalDestinationApprovedBy","uid","verdict","subject","unreadable","updatedAt","now","merge","ok","message","resource","previous","rule","error","console","allowDuplicate","reportWriteFailure","code","handleToggle","event","target","checked","handleDelete","confirmed","title","description","confirmationText","confirmationButtonProps","color","header","help","anchor","contentGutterX","contentGutterY","spacing","direction","sx","alignItems","size","onChange","label","flex","minWidth","noWrap","lastHitAt","toDate","toLocaleString","Boolean","join","onClick","rowCount","onPageChange","onPageSizeChange","severity","alignSelf","ready","used","noun","placeholder","maxWidth","normalized","result","open","onClose","fullWidth","display","flexDirection","gap","pt","select","prev","mt","helperText","autoFocus","type","disabled","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,UAAU,EAAEC,cAAc,QAAQ,eAAc;AAEzD,SAASC,WAAW,QAAQ,qCAAoC;AAChE,SAASC,6BAA6B,EAAEC,cAAc,EAAEC,aAAa,EAAEC,4BAA4B,EAAEC,uBAAuB,EAAEC,yBAAyB,EAAEC,oBAAoB,EAAEC,qBAAqB,QAAQ,oBAAU;AACtN,SAASC,WAAW,EAAEC,sBAAsB,QAAQ,uBAAsB;AAC1E,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,OAAOC,2BAA2B,0DAAyD;AAC3F,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,SAAS,QAAQ,+BAA8B;AACxD,SACEC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,QAAQ,EACRC,KAAK,EACLC,MAAM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,MAAK;gCACLF,YAAW;gCACXxH,KAAK,WAAE/B,yBAAAA,MAAO8C,QAAQ,oBAAIvI;gCAC1B+M,UAAU,CAACpB,QACTjG,SAAS,CAACoJ,OACRA,OACI,aAAKA;4CAAMvG,UAAUjB,OAAOqE,MAAMC,MAAM,CAACpE,KAAK;6CAC9CsH;gCAGRhC,MAAK;;;;kCAGT,MAACjM;;0CACC,KAACH;gCAAO+M,SAAS,IAAM/H,SAAS;0CAAQ;;0CACxC,KAAChF;gCACCqH,SAAQ;gCACRqE,OAAM;gCACN+C,UAAU,EAAC1J,yBAAAA,MAAOjB,MAAM,CAAC+E,IAAI,OAAM,EAAC9D,yBAAAA,MAAO2C,WAAW,CAACmB,IAAI;gCAC3DkE,SAASvE;0CAER;;;;;;;;AAMb;AACAvG,qBAAqByM,WAAW,GAAG;AAEnC,eAAezM,qBAAoB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/redirects/src/lib/components/redirects-console-page.tsx"],"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'use client'\n\nimport { TransferResumeImport } from '@aglyn/aglyn/app-utils/transfer-resume-import'\nimport { checkQuota, pluginDocsHelp, useTransferLauncher } from '@aglyn/aglyn'\nimport { type ConsolePluginPageProps } from '@aglyn/aglyn'\nimport { TENANT_APEX } from '@aglyn/aglyn/app-utils/tenant-apex'\nimport { findDuplicateRedirect, isExternalRedirectDestination, isSelfRedirect, matchRedirect, normalizeRedirectDestination, normalizeRedirectSource, REDIRECT_DEFAULT_PRIORITY, redirectHitKey, redirectSourceIsLivePage, validateRedirectRule, REDIRECT_STATUS_CODES, walkRedirectChain } from '../model'\nimport { CardDisplay, useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport { REDIRECTS_TRANSFER_KEY } from '../transfer/redirects-transfer-fields'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport QuotaReadoutComponent from '@aglyn/shared-ui-jsx/components/quota-readout.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { Timestamp } from '@aglyn/shared-util-timestamp'\nimport {\n Alert,\n Button,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport {\n collection,\n deleteField,\n doc,\n getCountFromServer,\n getDoc,\n setDoc,\n updateDoc,\n} from 'firebase/firestore'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { TABLE_PAGE_SIZE_DEFAULT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport {\n ceilingedWindow,\n collectionCeiling,\n useFirestore,\n useFirestoreCollection,\n useFirestoreDoc,\n useHostResourceApi,\n useUser,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\n\n/**\n * How many redirect documents this page reads.\n *\n * A CEILING, not a page size. Everything the page decides is computed over\n * the WHOLE rule set: the duplicate-source check, the chain-loop walk that\n * follows internal destinations through the rules, and the inline tester that\n * runs the enforcement matcher. A server page would give each of them a\n * tenth of the rules to reason about, and the duplicate check would then\n * create exactly the collision it exists to prevent.\n */\nconst REDIRECT_CEILING = 200\n\ninterface RedirectDraft {\n id: string | null\n source: string\n destination: string\n statusCode: number\n /** Match mode (AGL-375): exact | prefix | regex. */\n kind: string\n /** Lower fires first. */\n priority: number\n /**\n * The rule's on/off state, carried through the editor rather than reset by\n * it (AGL-1372). The save used to hardcode `true`, so changing a **disabled**\n * rule's target turned it back on and rerouted the site without the author\n * asking. A new rule seeds this `true`; an edit seeds it from the stored\n * rule, which is also where the row's switch reads from.\n */\n enabled: boolean\n}\n\n/**\n * Redirect manager (AGL-156): CRUD over `hosts/{hostId}/redirects` with\n * the shared AGL-154 validation (normalized sources, https-or-internal\n * destinations, self-redirect refusal, duplicate-source check). Paid\n * (`redirects` flag + `redirectsPerHost` quota); rules take effect on the\n * site within ~30 seconds (AGL-155 ISR window).\n *\n * The plan gate is the SHELL's, and it runs before this component exists\n * (AGL-2484): the console resolves `redirects` from the org billing doc and\n * renders its own refusal notice in place of the surface, so this card is\n * only ever mounted for an entitled org and states no plan terms of its own.\n * Redirects registers no `upgradeNotice` override because it is a genuine\n * upgrade — free denies it, Starter and above grant it — which makes the\n * shell's plan-derived sentence the accurate one already.\n *\n * `entitled` is still read below, where it is not redundant: it holds back\n * the thirty analytics day-doc reads behind the hit counts, and refuses the\n * add path ahead of the server that enforces it.\n */\nexport function RedirectsConsolePage(props: ConsolePluginPageProps) {\n const { hostId, entitled, org } = props\n const firestore = useFirestore()\n const createHostResource = useHostResourceApi()\n const { data: currentUser } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const { confirm } = useConfirmationContext()\n\n const {\n data: redirectDocs,\n status: redirectsStatus,\n /**\n * The rows this editor is seeded from are unconfirmed by the server\n * (AGL-1358). Editing copies every field the form owns out of the stored\n * rule and writes all of them back, so `merge: true` protects only the\n * fields written elsewhere (`lastHitAt`, `deletedAt`). This is the site\n * where a rollback is hardest to undo: a reverted `destination` on a\n * **301** is cached by every browser that has already followed it, so the\n * stale target outlives the fix in the console. `kind` reverting from\n * exact to prefix silently widens a rule over a whole subtree, and\n * `priority` reorders which rule fires when several match.\n */\n fromCache: redirectsFromCache,\n } = useFirestoreCollection<any>(\n /*\n * ORDERED AND CEILINGED, with a probe (AGL-2501).\n *\n * `limit(200)` alone is answered in DOCUMENT-ID order and the ids are\n * generated, so the window was a pseudo-random two hundred of the site's\n * rules — sorted by `source` in the browser afterwards, which is what\n * made it invisible: the rules on screen run alphabetically and are\n * simply the wrong rules, and the ones missing leave no gap to notice.\n *\n * `orderBy('source')` is the tempting fix and the dangerous one. It\n * matches only documents that HAVE the field, and nothing validates\n * `source` for presence — `/api/hosts/resources` stores an allow-list of\n * fields and checks none of them — so a rule saved without one would\n * vanish from this page while still redirecting live traffic. The\n * document NAME cannot be absent, so the walk is total: every rule is\n * reachable, and the alphabetical order stays where it belongs, in the\n * sort below over a window the page holds whole.\n */\n () =>\n collectionCeiling(\n collection(firestore, 'hosts', hostId, 'redirects'),\n REDIRECT_CEILING,\n ),\n [firestore, hostId],\n { idField: '$id' },\n )\n const { rows: readRedirects, truncated: redirectsTruncated } =\n ceilingedWindow<any>(redirectDocs, REDIRECT_CEILING)\n const redirects = [...readRedirects]\n .filter((redirect: any) => !redirect.deletedAt)\n .sort((a: any, b: any) =>\n String(a.source ?? '').localeCompare(String(b.source ?? '')),\n )\n\n /*\n * The page is a SLICE of the ceiling, which is what the three whole-set\n * consumers above require. The count is the rules this page HOLDS, after\n * soft-deleted ones are dropped — not the quota, which is a server count of\n * every document including the soft-deleted, and is read separately below.\n */\n const [page, setPage] = useState(0)\n const [pageSize, setPageSize] = useState(TABLE_PAGE_SIZE_DEFAULT)\n const visibleRedirects = useMemo(\n () => redirects.slice(page * pageSize, page * pageSize + pageSize),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [redirectDocs, page, pageSize],\n )\n\n /**\n * What the ENFORCING route counts, which is not what this page was counting.\n *\n * `hosts/{id}/redirects` is read here as an unordered `limit(200)` window\n * and then filtered to drop soft-deleted rows, and that filtered length was\n * feeding both `checkQuota('redirectsPerHost')` and the readout beside it.\n * The route in `app/api/hosts/resources` counts the collection plainly —\n * `collectionRef.count()`, every document, soft-deleted ones included — so\n * the two disagreed on both counts at once: a rule deleted in this console\n * still occupies a slot on the server, and a site past 200 rules has rows\n * the window never saw.\n *\n * The visible effect is the worst kind: the page shows room, the author\n * fills in the form, and the save is refused by a server counting something\n * else. Same shape as AGL-1716.\n *\n * An aggregation query, so it costs one read unit per thousand documents\n * rather than reading them. Re-run when the document set changes, which\n * covers an add; a soft delete leaves the document in place and so does not\n * move this number — correctly, because it does not move the server's\n * either.\n *\n * Only the COUNT is corrected here. Whether a soft-deleted rule should go on\n * occupying a slot is the quota RULE, and that lives with the enforcing\n * route.\n */\n const [enforcedCount, setEnforcedCount] = useState<number | null>(null)\n const redirectDocCount = redirectDocs?.length ?? 0\n\n /**\n * `null` when the count cannot be taken, never a number.\n *\n * `try`, not `.catch()`: `getCountFromServer` validates its reference and\n * THROWS synchronously on a bad one, so a rejection handler alone leaves the\n * error to escape the effect and take the page down with it. Unreadable is\n * also not zero — answering zero would tell an author at their cap that the\n * whole allowance is free.\n */\n const countRedirects = useCallback(async (): Promise<number | null> => {\n try {\n const snapshot = await getCountFromServer(\n collection(firestore, 'hosts', hostId, 'redirects'),\n )\n return snapshot.data().count\n } catch {\n return null\n }\n }, [firestore, hostId])\n\n useEffect(() => {\n let active = true\n void countRedirects().then((count) => {\n if (active && count != null) setEnforcedCount(count)\n })\n return () => {\n active = false\n }\n }, [countRedirects, redirectDocCount])\n\n const [draft, setDraft] = useState<RedirectDraft | null>(null)\n const [testPath, setTestPath] = useState('')\n\n // Host routing map for the screen-collision warning (AGL-156 spec).\n const { data: host } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId),\n [firestore, hostId],\n { idField: '$id' },\n )\n\n // Sampled hit counts (AGL-157): summed from the last 30 analytics day\n // docs' `redirects` maps written by enforcement. Counts are sampled —\n // one per ISR revalidation window with traffic, not per request.\n const [hits, setHits] = useState<Record<string, number> | null>(null)\n useEffect(() => {\n if (!entitled) return\n let active = true\n const ids = Array.from({ length: 30 }, (_, index) => {\n const date = new Date()\n date.setDate(date.getDate() - index)\n return date.toISOString().slice(0, 10)\n })\n void Promise.all(\n ids.map((id) =>\n getDoc(doc(firestore, 'hosts', hostId, 'analytics', id))\n .then((snapshot) => (snapshot.get('redirects') ?? {}) as Record<string, number>)\n .catch(() => ({}) as Record<string, number>),\n ),\n ).then((days) => {\n if (!active) return\n const totals: Record<string, number> = {}\n for (const dayMap of days) {\n for (const [redirectId, count] of Object.entries(dayMap)) {\n totals[redirectId] = (totals[redirectId] ?? 0) + Number(count)\n }\n }\n setHits(totals)\n })\n return () => {\n active = false\n }\n }, [entitled, firestore, hostId])\n const totalHits = Object.values(hits ?? {}).reduce(\n (sum, count) => sum + count,\n 0,\n )\n\n const handleAdd = useCallback(() => {\n if (!entitled) {\n return void enqueueSnackbar(\n 'URL redirects require a Starter plan — see Billing to upgrade',\n { variant: 'warning', persist: false },\n )\n }\n /*\n * The SERVER's count, not the rows on screen — the whole point of this\n * fix. Read from the polled value rather than re-counted on the click:\n * this gate is a courtesy that spares the author a form they are about to\n * be refused, the route is the actual enforcer, and making the button\n * await an aggregation would delay the dialog on every press to sharpen a\n * number the server re-checks anyway.\n *\n * `null` means the count could not be read, and that lets the add through:\n * refusing on a number we do not have would block an author who may well\n * be inside their cap.\n */\n const quota = checkQuota(org, 'redirectsPerHost', enforcedCount ?? 0)\n if (!quota.allowed) {\n return void enqueueSnackbar(\n `Redirect limit reached (${quota.limit}) — upgrade in Billing`,\n { variant: 'warning', persist: false },\n )\n }\n setDraft({\n id: null,\n source: '',\n destination: '',\n statusCode: 302,\n kind: 'exact',\n priority: REDIRECT_DEFAULT_PRIORITY,\n // A NEW rule is on: the author is adding it to make it fire, and\n // enforcement queries `where('enabled', '==', true)`, so a rule created\n // without the field would never resolve (AGL-1372).\n enabled: true,\n })\n }, [entitled, org, enforcedCount, enqueueSnackbar])\n\n /**\n * Tell the tenant a rule changed (best effort, never awaited into the save\n * outcome). Rule writes are client Firestore writes with no publish step,\n * and the tenant's rules list sits behind the hour-long\n * `tenant-data:{hostId}` backstop — without this call a new rule waits out\n * that TTL while the snackbar above promises ~30 seconds. The route busts\n * the host tag and drops the source path's cached HTML; a regex pattern has\n * no single literal path, so it announces `/` for the tag bust alone and\n * the matching pages catch up on their own ISR window.\n */\n const announceRuleChange = useCallback(\n (source: string | undefined) => {\n const redirectPath =\n typeof source === 'string' && source.startsWith('/') ? source : '/'\n void authorizedFetch(currentUser, '/api/screens/revalidate', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, redirectPath }),\n }).catch(() => undefined)\n },\n [currentUser, hostId],\n )\n\n const handleSave = useCallback(async () => {\n if (!draft) return\n const kind = draft.kind || 'exact'\n // Shared v2 validation (AGL-375): regex patterns must compile; path\n // kinds keep the v1 normalization. A destination that wears another\n // brand is refused (AGL-3447); the site's own hosts never do.\n const problem = validateRedirectRule(\n {\n kind,\n source: draft.source,\n destination: draft.destination,\n },\n {\n ownDomains: [\n typeof host?.cname === 'string' ? host.cname : null,\n typeof host?.subdomain === 'string' && host.subdomain\n ? `${host.subdomain}.${TENANT_APEX}`\n : null,\n ],\n },\n )\n if (problem) {\n return void enqueueSnackbar(problem, {\n variant: 'warning',\n persist: false,\n })\n }\n const source =\n kind === 'regex'\n ? draft.source.trim()\n : (normalizeRedirectSource(draft.source) as string)\n const destination = normalizeRedirectDestination(\n draft.destination,\n ) as string\n if (kind !== 'regex' && isSelfRedirect({ source, destination })) {\n return void enqueueSnackbar('That would redirect the path to itself', {\n variant: 'warning',\n persist: false,\n })\n }\n const duplicate = findDuplicateRedirect(redirects, {\n $id: draft.id,\n source,\n kind,\n })\n if (duplicate) {\n return void enqueueSnackbar(`A rule for ${source} already exists`, {\n variant: 'warning',\n persist: false,\n })\n }\n // Chain-loop detection (AGL-156): follow internal destinations through\n // the rule set; a walk that returns to this source can never execute.\n if (walkRedirectChain(redirects, { $id: draft.id, source, destination }).loop) {\n return void enqueueSnackbar(\n 'That destination chains back to this rule — a redirect loop',\n { variant: 'warning', persist: false },\n )\n }\n // Screen-route collision: shadowing a live page may be intentional\n // (moved pages) — warn, don't block (decision per the issue).\n if (redirectSourceIsLivePage(host?.screens, source)) {\n enqueueSnackbar(\n `${source} is a published page — the redirect takes precedence`,\n { variant: 'info', persist: false },\n )\n }\n const fields = {\n source,\n destination,\n statusCode: (REDIRECT_STATUS_CODES as readonly number[]).includes(\n draft.statusCode,\n )\n ? draft.statusCode\n : 302,\n kind,\n priority: Number.isFinite(Number(draft.priority))\n ? Number(draft.priority)\n : REDIRECT_DEFAULT_PRIORITY,\n /**\n * Whatever the rule already was (AGL-1372). This was `true`, so editing\n * a **disabled** rule's target silently re-enabled it — a deliberate\n * \"off\" (a retired campaign, a rule that broke something) undone by a\n * routine save, changing site routing without the author asking.\n *\n * `!== false` rather than the raw value, because the switch below reads\n * the stored field the same way: absent means on. Enforcement's query is\n * `where('enabled', '==', true)`, so a rule missing the field is not\n * served, and normalising it here makes the console's claim true.\n *\n * The create default lives in `handleAdd` — a new rule seeds the draft\n * `true`, so both defaults hold without either one reading the other.\n */\n enabled: draft.enabled !== false,\n }\n /**\n * The publisher's stamp on an external destination (AGL-1881).\n *\n * `matchRedirect` will not send traffic off the platform without it, and\n * `cloud/firebase-firestore.rules` admits no write to this collection from\n * anyone but `canPublishHostContent` — so reaching this line at all is the\n * approval, and saving is how a rule written before that fix starts firing\n * again.\n *\n * Written on EDIT only. A create rides /api/hosts/resources, which stamps\n * the same field from the id token's verified uid; sending it from here\n * would be the client supplying its own provenance, and that route drops\n * it for exactly that reason.\n *\n * Cleared with `deleteField()` when the destination is internal, rather\n * than left standing. `merge: true` never removes a key, so an edit from\n * `https://elsewhere.example` back to `/pricing` would otherwise leave a\n * stamp behind that a LATER edit back to an external target would inherit\n * — approval carried across a destination nobody approved.\n */\n const approval = isExternalRedirectDestination(destination)\n ? { externalDestinationApprovedBy: currentUser?.uid ?? null }\n : { externalDestinationApprovedBy: deleteField() }\n try {\n if (draft.id) {\n /**\n * Edit stays client-direct (no quota consumed) — and is refused when\n * its seed was never confirmed by the server (AGL-1358); the eight\n * validation refusals above have all already returned by here.\n *\n * `merge: true` is load-bearing, contrary to what this said before\n * (AGL-1372): `fields` is every key the FORM owns, not every key the\n * document holds. `lastHitAt` is written by enforcement\n * (`resolve-redirect`), and `deletedAt` by the delete below — a\n * replacing write would erase both.\n *\n * The guard WRAPS the write. An early return is a shape you can keep\n * while losing the protection; here the write is only reachable\n * through the verdict.\n */\n const verdict = await writeGuardedBySeed(\n {\n subject: 'redirect',\n unreadable: redirectsStatus === 'error',\n fromCache: redirectsFromCache,\n },\n async () => {\n await setDoc(\n doc(firestore, 'hosts', hostId, 'redirects', draft.id),\n { ...fields, ...approval, updatedAt: Timestamp.now() },\n { merge: true },\n )\n },\n )\n // Before `setDraft(null)`, so a refusal keeps the dialog open with\n // what was typed, in the same warning vocabulary as the validation\n // refusals above it.\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, {\n variant: 'warning',\n persist: false,\n })\n }\n } else {\n // New redirect rides the quota-enforcing resources API (AGL-473) —\n // it also re-checks the `redirects` entitlement server-side.\n await createHostResource({ hostId, resource: 'redirect', data: fields })\n }\n // The changed rule, and — when an edit moved the source — the path\n // that just STOPPED redirecting, so its page refreshes too.\n announceRuleChange(source)\n if (draft.id) {\n const previous = (redirects ?? []).find(\n (rule: any) => rule.$id === draft.id,\n )?.source\n if (previous && previous !== source) announceRuleChange(previous)\n }\n setDraft(null)\n enqueueSnackbar('Redirect saved — live within ~30 seconds', {\n variant: 'success',\n persist: false,\n })\n } catch (error: any) {\n console.error(error)\n enqueueSnackbar(error?.message ?? 'An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n }, [\n draft,\n redirects,\n host,\n firestore,\n hostId,\n createHostResource,\n currentUser,\n enqueueSnackbar,\n redirectsStatus,\n redirectsFromCache,\n announceRuleChange,\n ])\n\n /**\n * A refusal has to be visible (AGL-1881).\n *\n * These two writes were bare `await`s. The rules now gate this collection on\n * a publishing role, so an `author` reaching either gets a\n * permission-denied — and an unhandled rejection renders as a control that\n * flips back with no error, which is the worst way to say no. `handleSave`\n * has always ended in a snackbar; these now match it.\n *\n * The card is not role-gated on purpose: it is entitlement-gated, and the\n * rules leave READ to the catch-all so an author can still see the rules\n * that affect the pages they write.\n */\n const reportWriteFailure = useCallback(\n (error: any) => {\n enqueueSnackbar(\n error?.code === 'permission-denied'\n ? 'Changing a redirect needs a publishing role — ask an editor or admin'\n : (error?.message ?? 'An error has occurred'),\n { variant: 'warning', persist: false },\n )\n },\n [enqueueSnackbar],\n )\n\n const handleToggle = useCallback(\n (redirect: any) => async (event: { target: { checked: boolean } }) => {\n try {\n await updateDoc(\n doc(firestore, 'hosts', hostId, 'redirects', redirect.$id),\n { enabled: event.target.checked, updatedAt: Timestamp.now() },\n )\n announceRuleChange(redirect.source)\n } catch (error: any) {\n reportWriteFailure(error)\n }\n },\n [firestore, hostId, reportWriteFailure, announceRuleChange],\n )\n\n const handleDelete = useCallback(\n (redirect: any) => async () => {\n const confirmed = await confirm({\n title: 'Delete this redirect?',\n description: `${redirect.source} stops redirecting.`,\n confirmationText: 'Delete',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n try {\n await updateDoc(\n doc(firestore, 'hosts', hostId, 'redirects', redirect.$id),\n { deletedAt: Timestamp.now(), enabled: false },\n )\n announceRuleChange(redirect.source)\n } catch (error: any) {\n reportWriteFailure(error)\n }\n },\n [confirm, firestore, hostId, reportWriteFailure, announceRuleChange],\n )\n\n /*\n * Import and Export, through the console's transfer launcher (`null`\n * outside the console shell, where there is no workspace to move rules in\n * or out of). The list above is a live listener, so an import's rules show\n * up without a refresh.\n */\n const transfer = useTransferLauncher()\n const transferTarget = { resource: REDIRECTS_TRANSFER_KEY, scope: 'host' as const, hostId }\n // Import for those who may write the records, Export for those who may read them.\n const canImport = Boolean(transfer?.can('import', transferTarget))\n const canExport = Boolean(transfer?.can('export', transferTarget))\n const transferActions =\n transfer && (canImport || canExport) ? (\n <Stack direction=\"row\" spacing={1}>\n {/* An import left unfinished, reopened where it stopped (AGL-3549). */}\n <TransferResumeImport target={transferTarget} />\n {canImport && (\n <Button size=\"small\" onClick={() => transfer.openImport(transferTarget)}>\n {'Import'}\n </Button>\n )}\n {canExport && (\n <Button\n size=\"small\"\n onClick={() =>\n transfer.openExport(transferTarget)\n }\n >\n {'Export'}\n </Button>\n )}\n </Stack>\n ) : null\n\n return (\n <CardDisplay\n header={'URL redirects'}\n help={pluginDocsHelp('redirects', { anchor: '#manage-redirects' })}\n HeaderProps={transferActions ? { action: transferActions } : undefined}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Exact-path rules; 302 while testing, promote to 301 when ' +\n 'sure (browsers cache 301 aggressively). Changes go live ' +\n 'within ~30 seconds.'}\n </Typography>\n {hits && totalHits > 0 ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${totalHits} redirect hit${totalHits === 1 ? '' : 's'} in ` +\n 'the last 30 days (sampled — one per cache window with ' +\n 'traffic).'}\n </Typography>\n ) : null}\n {visibleRedirects.map((redirect: any) => (\n <Stack\n key={redirect.$id}\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center' }}\n >\n <Switch\n size=\"small\"\n checked={redirect.enabled !== false}\n onChange={handleToggle(redirect)}\n />\n <Chip size=\"small\" label={redirect.statusCode ?? 302} />\n {(redirect.kind ?? 'exact') !== 'exact' ? (\n <Chip\n size=\"small\"\n variant=\"outlined\"\n label={redirect.kind}\n />\n ) : null}\n {/* An external rule with no publisher stamp is not being served\n (AGL-1881) — `matchRedirect` skips it. Say so on the row\n rather than letting it read as live: a rule that silently\n stops firing is the failure mode a fail-closed gate owes an\n explanation for, and pressing Edit → Save is the whole fix.\n Shown for external destinations only, since that is the only\n case the gate applies to. */}\n {isExternalRedirectDestination(redirect.destination) &&\n !redirect.externalDestinationApprovedBy ? (\n <Chip\n size=\"small\"\n color=\"warning\"\n variant=\"outlined\"\n label=\"not serving\"\n title={\n 'This rule sends visitors to another site. Open it and ' +\n 'save to confirm the destination — until then it is ' +\n 'skipped.'\n }\n />\n ) : null}\n <Stack sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {`${redirect.source} → ${redirect.destination}`}\n </Typography>\n {hits || redirect.lastHitAt ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {[\n hits\n ? `${hits[redirectHitKey(redirect.$id)] ?? 0} hits (30d, sampled)`\n : null,\n redirect.lastHitAt\n ? `last ${redirect.lastHitAt\n .toDate()\n .toLocaleString()}`\n : null,\n ]\n .filter(Boolean)\n .join(' · ')}\n </Typography>\n ) : null}\n </Stack>\n <Button\n size=\"small\"\n onClick={() =>\n setDraft({\n id: redirect.$id,\n source: redirect.source ?? '',\n destination: redirect.destination ?? '',\n statusCode: redirect.statusCode ?? 302,\n kind: redirect.kind ?? 'exact',\n priority: redirect.priority ?? REDIRECT_DEFAULT_PRIORITY,\n // Read exactly as the switch beside it does (AGL-1372):\n // an edit must not be a way to turn a rule back on.\n enabled: redirect.enabled !== false,\n })\n }\n >\n {'Edit'}\n </Button>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={handleDelete(redirect)}\n >\n {'Delete'}\n </Button>\n </Stack>\n ))}\n {redirects.length === 0 ? null : (\n <ListPagination\n page={page}\n pageSize={pageSize}\n rowCount={visibleRedirects.length}\n // The rules this page HOLDS, after the soft-deleted ones are\n // dropped. Not the quota figure below it: that is a server\n // count over every document, soft-deleted rows included,\n // because a deleted rule still occupies a slot.\n count={redirects.length}\n onPageChange={setPage}\n onPageSizeChange={setPageSize}\n />\n )}\n {redirectsTruncated ? (\n <Alert severity=\"info\">\n {`Showing ${REDIRECT_CEILING} rules, ordered by id. This site ` +\n 'has more — the duplicate check and the tester below only ' +\n 'cover the ones listed here.'}\n </Alert>\n ) : null}\n <Button\n size=\"small\"\n color=\"primary\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={handleAdd}\n >\n {'Add redirect'}\n </Button>\n {/* The cap, standing rather than only on refusal (AGL-2113).\n `enforcedCount` is what the enforcing route counts and what\n `handleAdd` checks against, so the readout, the gate and the\n server cannot disagree. It is deliberately NOT the number of rows\n on screen: a soft-deleted rule still occupies a slot, so showing\n the visible count here would promise room the server refuses. */}\n <QuotaReadoutComponent\n ready={org != null && enforcedCount != null}\n used={enforcedCount ?? 0}\n limit={\n checkQuota(org, 'redirectsPerHost', enforcedCount ?? 0).limit\n }\n noun=\"redirect\"\n />\n {/* Inline tester (AGL-375): same matcher as enforcement. */}\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <TextField\n size=\"small\"\n label=\"Test a path\"\n placeholder=\"/old-page\"\n value={testPath}\n onChange={(event) => setTestPath(event.target.value)}\n sx={{ maxWidth: 260 }}\n />\n {testPath.trim() ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {(() => {\n const normalized =\n normalizeRedirectSource(testPath) ?? testPath.trim()\n const result = matchRedirect(redirects as any, normalized)\n return result\n ? `→ ${result.destination} (${result.statusCode})`\n : 'No rule matches'\n })()}\n </Typography>\n ) : null}\n </Stack>\n </Stack>\n\n <Dialog\n open={Boolean(draft)}\n onClose={() => setDraft(null)}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>{draft?.id ? 'Edit redirect' : 'Add redirect'}</DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 1.5, pt: 1 }}\n >\n <TextField\n select\n label=\"Match mode\"\n value={draft?.kind ?? 'exact'}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, kind: event.target.value } : prev,\n )\n }\n size=\"small\"\n sx={{ mt: 1 }}\n >\n <MenuItem value=\"exact\">{'Exact path'}</MenuItem>\n <MenuItem value=\"prefix\">{'Path prefix'}</MenuItem>\n <MenuItem value=\"regex\">{'Regular expression'}</MenuItem>\n </TextField>\n <TextField\n label={draft?.kind === 'regex' ? 'Pattern' : 'From path'}\n placeholder={\n draft?.kind === 'regex' ? '/product/(\\\\d+)' : '/old-page'\n }\n helperText={\n draft?.kind === 'regex'\n ? 'Anchored to the whole path; use $1, $2 in the destination'\n : draft?.kind === 'prefix'\n ? 'Matches the path and everything under it'\n : undefined\n }\n value={draft?.source ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, source: event.target.value } : prev,\n )\n }\n size=\"small\"\n autoFocus\n />\n <TextField\n label=\"To\"\n placeholder=\"/new-page or https://example.com\"\n value={draft?.destination ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, destination: event.target.value } : prev,\n )\n }\n size=\"small\"\n />\n <TextField\n select\n label=\"Status code\"\n value={draft?.statusCode ?? 302}\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? { ...prev, statusCode: Number(event.target.value) }\n : prev,\n )\n }\n size=\"small\"\n >\n <MenuItem value={302}>{'302 — temporary (default)'}</MenuItem>\n <MenuItem value={301}>{'301 — permanent'}</MenuItem>\n <MenuItem value={307}>{'307 — temporary, keep method'}</MenuItem>\n <MenuItem value={308}>{'308 — permanent, keep method'}</MenuItem>\n </TextField>\n <TextField\n label=\"Priority\"\n type=\"number\"\n helperText=\"Lower fires first when several rules match\"\n value={draft?.priority ?? REDIRECT_DEFAULT_PRIORITY}\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? { ...prev, priority: Number(event.target.value) }\n : prev,\n )\n }\n size=\"small\"\n />\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setDraft(null)}>{'Cancel'}</Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!draft?.source.trim() || !draft?.destination.trim()}\n onClick={handleSave}\n >\n {'Save redirect'}\n </Button>\n </DialogActions>\n </Dialog>\n </CardDisplay>\n )\n}\nRedirectsConsolePage.displayName = 'RedirectsConsolePage'\n\nexport default RedirectsConsolePage\n"],"names":["TransferResumeImport","checkQuota","pluginDocsHelp","useTransferLauncher","TENANT_APEX","findDuplicateRedirect","isExternalRedirectDestination","isSelfRedirect","matchRedirect","normalizeRedirectDestination","normalizeRedirectSource","REDIRECT_DEFAULT_PRIORITY","redirectHitKey","redirectSourceIsLivePage","validateRedirectRule","REDIRECT_STATUS_CODES","walkRedirectChain","CardDisplay","useConfirmationContext","REDIRECTS_TRANSFER_KEY","authorizedFetch","QuotaReadoutComponent","useSnackbar","Timestamp","Alert","Button","Chip","Dialog","DialogActions","DialogContent","DialogTitle","MenuItem","Stack","Switch","TextField","Typography","collection","deleteField","doc","getCountFromServer","getDoc","setDoc","updateDoc","useCallback","useEffect","useMemo","useState","ListPagination","TABLE_PAGE_SIZE_DEFAULT","ceilingedWindow","collectionCeiling","useFirestore","useFirestoreCollection","useFirestoreDoc","useHostResourceApi","useUser","writeGuardedBySeed","REDIRECT_CEILING","RedirectsConsolePage","props","hostId","entitled","org","firestore","createHostResource","data","currentUser","enqueueSnackbar","confirm","redirectDocs","status","redirectsStatus","fromCache","redirectsFromCache","idField","rows","readRedirects","truncated","redirectsTruncated","redirects","filter","redirect","deletedAt","sort","a","b","String","source","localeCompare","page","setPage","pageSize","setPageSize","visibleRedirects","slice","enforcedCount","setEnforcedCount","redirectDocCount","length","countRedirects","snapshot","count","active","then","draft","setDraft","testPath","setTestPath","host","hits","setHits","ids","Array","from","_","index","date","Date","setDate","getDate","toISOString","Promise","all","map","id","get","catch","days","totals","dayMap","redirectId","Object","entries","Number","totalHits","values","reduce","sum","handleAdd","variant","persist","quota","allowed","limit","destination","statusCode","kind","priority","enabled","announceRuleChange","redirectPath","startsWith","method","headers","body","JSON","stringify","undefined","handleSave","problem","ownDomains","cname","subdomain","trim","duplicate","$id","loop","screens","fields","includes","isFinite","approval","externalDestinationApprovedBy","uid","verdict","subject","unreadable","updatedAt","now","merge","ok","message","resource","previous","find","rule","error","console","allowDuplicate","reportWriteFailure","code","handleToggle","event","target","checked","handleDelete","confirmed","title","description","confirmationText","confirmationButtonProps","color","transfer","transferTarget","scope","canImport","Boolean","can","canExport","transferActions","direction","spacing","size","onClick","openImport","openExport","header","help","anchor","HeaderProps","action","contentGutterX","contentGutterY","sx","alignItems","onChange","label","flex","minWidth","noWrap","lastHitAt","toDate","toLocaleString","join","rowCount","onPageChange","onPageSizeChange","severity","alignSelf","ready","used","noun","placeholder","value","maxWidth","normalized","result","open","onClose","fullWidth","display","flexDirection","gap","pt","select","prev","mt","helperText","autoFocus","type","disabled","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,oBAAoB,QAAQ,gDAA+C;AACpF,SAASC,UAAU,EAAEC,cAAc,EAAEC,mBAAmB,QAAQ,eAAc;AAE9E,SAASC,WAAW,QAAQ,qCAAoC;AAChE,SAASC,qBAAqB,EAAEC,6BAA6B,EAAEC,cAAc,EAAEC,aAAa,EAAEC,4BAA4B,EAAEC,uBAAuB,EAAEC,yBAAyB,EAAEC,cAAc,EAAEC,wBAAwB,EAAEC,oBAAoB,EAAEC,qBAAqB,EAAEC,iBAAiB,QAAQ,oBAAU;AAC1S,SAASC,WAAW,EAAEC,sBAAsB,QAAQ,uBAAsB;AAC1E,SAASC,sBAAsB,QAAQ,2CAAuC;AAC9E,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,OAAOC,2BAA2B,0DAAyD;AAC3F,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,SAAS,QAAQ,+BAA8B;AACxD,SACEC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SACEC,UAAU,EACVC,WAAW,EACXC,GAAG,EACHC,kBAAkB,EAClBC,MAAM,EACNC,MAAM,EACNC,SAAS,QACJ,qBAAoB;AAC3B,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACjE,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,uBAAuB,QAAQ,8CAA6C;AACrF,SACEC,eAAe,EACfC,iBAAiB,EACjBC,YAAY,EACZC,sBAAsB,EACtBC,eAAe,EACfC,kBAAkB,EAClBC,O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AER;;;;;;;;AAMb;AACApG,qBAAqB2M,WAAW,GAAG;AAEnC,eAAe3M,qBAAoB"}
|
|
@@ -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
|
+
/**
|
|
18
|
+
* The redirects plugin's CONSOLE-ONLY server declarations, named under
|
|
19
|
+
* `consoleServerDeclarations` in `plugins.config.json` and run at the
|
|
20
|
+
* console's boot. The tenant runtime registers none of it.
|
|
21
|
+
*
|
|
22
|
+
* The `redirects` transfer resource: a site's redirect rules, imported and
|
|
23
|
+
* exported through the data-transfer jobs, written through the same checks
|
|
24
|
+
* as the redirects page and the create route (`transfer/redirects-transfer.ts`).
|
|
25
|
+
* The catalog, the match keys, the alias dictionaries, the starting policy
|
|
26
|
+
* and the value comparator are answered from here; every hook that reads or writes loads the Admin SDK with its first
|
|
27
|
+
* call, so boot pays for none of it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function registerRedirectsConsoleServerDeclarations(): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
*/ // The registry's own module, not the `@aglyn/aglyn/server` barrel: boot needs
|
|
17
|
+
// one registry, not the whole server surface.
|
|
18
|
+
import { registerPluginTransferResource } from "@aglyn/aglyn/plugin-manager/plugin-transfer-resources";
|
|
19
|
+
import { BUNDLE_ID } from "./constants/bundle-common.js";
|
|
20
|
+
import { REDIRECTS_ALIAS_DICTIONARIES, REDIRECTS_DEFAULT_POLICY, REDIRECTS_MATCH_KEYS, REDIRECTS_TRANSFER_KEY, redirectValuesEqual, redirectsTransferCatalog } from "./transfer/redirects-transfer-fields.js";
|
|
21
|
+
/** The resource that reads and writes, loaded with the first import or export. */ async function load() {
|
|
22
|
+
return (await import("./transfer/redirects-transfer-console.js")).redirectsTransferResource();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The redirects plugin's CONSOLE-ONLY server declarations, named under
|
|
26
|
+
* `consoleServerDeclarations` in `plugins.config.json` and run at the
|
|
27
|
+
* console's boot. The tenant runtime registers none of it.
|
|
28
|
+
*
|
|
29
|
+
* The `redirects` transfer resource: a site's redirect rules, imported and
|
|
30
|
+
* exported through the data-transfer jobs, written through the same checks
|
|
31
|
+
* as the redirects page and the create route (`transfer/redirects-transfer.ts`).
|
|
32
|
+
* The catalog, the match keys, the alias dictionaries, the starting policy
|
|
33
|
+
* and the value comparator are answered from here; every hook that reads or writes loads the Admin SDK with its first
|
|
34
|
+
* call, so boot pays for none of it.
|
|
35
|
+
*/ export function registerRedirectsConsoleServerDeclarations() {
|
|
36
|
+
const resource = {
|
|
37
|
+
fields: ()=>redirectsTransferCatalog(),
|
|
38
|
+
matchKeys: REDIRECTS_MATCH_KEYS,
|
|
39
|
+
aliases: REDIRECTS_ALIAS_DICTIONARIES,
|
|
40
|
+
// A rule already on the site takes the file's values unless the person
|
|
41
|
+
// chooses otherwise; the review compares values as the page stores them.
|
|
42
|
+
defaultPolicy: REDIRECTS_DEFAULT_POLICY,
|
|
43
|
+
valuesEqual: redirectValuesEqual,
|
|
44
|
+
match: async (ctx, input)=>{
|
|
45
|
+
const hooks = await load();
|
|
46
|
+
if (!hooks.match) throw new Error('The redirects resource has no matching.');
|
|
47
|
+
return hooks.match(ctx, input);
|
|
48
|
+
},
|
|
49
|
+
count: async (ctx, options)=>{
|
|
50
|
+
var _ref;
|
|
51
|
+
var _count, _this;
|
|
52
|
+
return (_ref = (_count = (_this = await load()).count) == null ? void 0 : _count.call(_this, ctx, options)) != null ? _ref : 0;
|
|
53
|
+
},
|
|
54
|
+
readPage: async (ctx, cursor, fieldIds, options)=>(await load()).readPage(ctx, cursor, fieldIds, options),
|
|
55
|
+
lookup: async (ctx, requests)=>(await load()).lookup(ctx, requests),
|
|
56
|
+
plan: async (ctx, input)=>{
|
|
57
|
+
const hooks = await load();
|
|
58
|
+
if (!hooks.plan) throw new Error('The redirects resource has no plan.');
|
|
59
|
+
return hooks.plan(ctx, input);
|
|
60
|
+
},
|
|
61
|
+
apply: async (ctx, chunk, writer)=>(await load()).apply(ctx, chunk, writer),
|
|
62
|
+
revert: async (ctx, snapshot, decisions)=>(await load()).revert(ctx, snapshot, decisions)
|
|
63
|
+
};
|
|
64
|
+
registerPluginTransferResource(REDIRECTS_TRANSFER_KEY, resource, {
|
|
65
|
+
pluginId: BUNDLE_ID
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=declarations.console-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/plugins/redirects/src/lib/declarations.console-server.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 registry's own module, not the `@aglyn/aglyn/server` barrel: boot needs\n// one registry, not the whole server surface.\nimport {\n registerPluginTransferResource,\n type PluginTransferResource,\n type TransferRecordsHooks,\n} from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources'\nimport { BUNDLE_ID } from './constants/bundle-common'\nimport {\n REDIRECTS_ALIAS_DICTIONARIES,\n REDIRECTS_DEFAULT_POLICY,\n REDIRECTS_MATCH_KEYS,\n REDIRECTS_TRANSFER_KEY,\n redirectValuesEqual,\n redirectsTransferCatalog,\n} from './transfer/redirects-transfer-fields'\n\n/** The resource that reads and writes, loaded with the first import or export. */\nasync function load(): Promise<TransferRecordsHooks> {\n return (await import('./transfer/redirects-transfer-console')).redirectsTransferResource() as TransferRecordsHooks\n}\n\n/**\n * The redirects plugin's CONSOLE-ONLY server declarations, named under\n * `consoleServerDeclarations` in `plugins.config.json` and run at the\n * console's boot. The tenant runtime registers none of it.\n *\n * The `redirects` transfer resource: a site's redirect rules, imported and\n * exported through the data-transfer jobs, written through the same checks\n * as the redirects page and the create route (`transfer/redirects-transfer.ts`).\n * The catalog, the match keys, the alias dictionaries, the starting policy\n * and the value comparator are answered from here; every hook that reads or writes loads the Admin SDK with its first\n * call, so boot pays for none of it.\n */\nexport function registerRedirectsConsoleServerDeclarations(): void {\n const resource: PluginTransferResource = {\n fields: () => redirectsTransferCatalog(),\n matchKeys: REDIRECTS_MATCH_KEYS,\n aliases: REDIRECTS_ALIAS_DICTIONARIES,\n // A rule already on the site takes the file's values unless the person\n // chooses otherwise; the review compares values as the page stores them.\n defaultPolicy: REDIRECTS_DEFAULT_POLICY,\n valuesEqual: redirectValuesEqual,\n match: async (ctx, input) => {\n const hooks = await load()\n if (!hooks.match) throw new Error('The redirects resource has no matching.')\n return hooks.match(ctx, input)\n },\n count: async (ctx, options) => (await load()).count?.(ctx, options) ?? 0,\n readPage: async (ctx, cursor, fieldIds, options) => (await load()).readPage(ctx, cursor, fieldIds, options),\n lookup: async (ctx, requests) => (await load()).lookup(ctx, requests),\n plan: async (ctx, input) => {\n const hooks = await load()\n if (!hooks.plan) throw new Error('The redirects resource has no plan.')\n return hooks.plan(ctx, input)\n },\n apply: async (ctx, chunk, writer) => (await load()).apply(ctx, chunk, writer),\n revert: async (ctx, snapshot, decisions) => (await load()).revert(ctx, snapshot, decisions),\n }\n registerPluginTransferResource(REDIRECTS_TRANSFER_KEY, resource, { pluginId: BUNDLE_ID })\n}\n"],"names":["registerPluginTransferResource","BUNDLE_ID","REDIRECTS_ALIAS_DICTIONARIES","REDIRECTS_DEFAULT_POLICY","REDIRECTS_MATCH_KEYS","REDIRECTS_TRANSFER_KEY","redirectValuesEqual","redirectsTransferCatalog","load","redirectsTransferResource","registerRedirectsConsoleServerDeclarations","resource","fields","matchKeys","aliases","defaultPolicy","valuesEqual","match","ctx","input","hooks","Error","count","options","readPage","cursor","fieldIds","lookup","requests","plan","apply","chunk","writer","revert","snapshot","decisions","pluginId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,8EAA8E;AAC9E,8CAA8C;AAC9C,SACEA,8BAA8B,QAGzB,wDAAuD;AAC9D,SAASC,SAAS,QAAQ,+BAA2B;AACrD,SACEC,4BAA4B,EAC5BC,wBAAwB,EACxBC,oBAAoB,EACpBC,sBAAsB,EACtBC,mBAAmB,EACnBC,wBAAwB,QACnB,0CAAsC;AAE7C,gFAAgF,GAChF,eAAeC;IACb,OAAO,AAAC,CAAA,MAAM,MAAM,CAAC,2CAAuC,EAAGC,yBAAy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