@aglyn/aglyn 1.11.0 → 1.13.0
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/app-utils/account-preferences.d.ts +15 -13
- package/src/lib/app-utils/account-preferences.js +20 -20
- package/src/lib/app-utils/account-preferences.js.map +1 -1
- package/src/lib/app-utils/crm.d.ts +3 -1
- package/src/lib/app-utils/crm.js +6 -3
- package/src/lib/app-utils/crm.js.map +1 -1
- package/src/lib/app-utils/docs-help-sections.generated.js +10 -4
- package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
- package/src/lib/app-utils/docs-help.generated.d.ts +2 -2
- package/src/lib/app-utils/docs-help.generated.js +8 -0
- package/src/lib/app-utils/docs-help.generated.js.map +1 -1
- package/src/lib/app-utils/docs-index.generated.js +117 -96
- package/src/lib/app-utils/docs-index.generated.js.map +1 -1
- package/src/lib/app-utils/host-permissions.d.ts +12 -0
- package/src/lib/app-utils/host-permissions.js +26 -1
- package/src/lib/app-utils/host-permissions.js.map +1 -1
- package/src/lib/app-utils/markdown-lite.js +8 -1
- package/src/lib/app-utils/markdown-lite.js.map +1 -1
- package/src/lib/app-utils/media-asset-facts.d.ts +2 -2
- package/src/lib/app-utils/media-asset-facts.js +4 -3
- package/src/lib/app-utils/media-asset-facts.js.map +1 -1
- package/src/lib/app-utils/media-cdn-scope.d.ts +19 -4
- package/src/lib/app-utils/media-cdn-scope.js +19 -5
- package/src/lib/app-utils/media-cdn-scope.js.map +1 -1
- package/src/lib/app-utils/media-ref.d.ts +10 -6
- package/src/lib/app-utils/media-ref.js +34 -8
- package/src/lib/app-utils/media-ref.js.map +1 -1
- package/src/lib/app-utils/org-permissions.d.ts +7 -0
- package/src/lib/app-utils/org-permissions.js +2 -0
- package/src/lib/app-utils/org-permissions.js.map +1 -1
- package/src/lib/app-utils/org-role-grants.d.ts +13 -0
- package/src/lib/app-utils/org-role-grants.js +9 -5
- package/src/lib/app-utils/org-role-grants.js.map +1 -1
- package/src/lib/app-utils/person-erasure.d.ts +8 -0
- package/src/lib/app-utils/person-erasure.js +6 -0
- package/src/lib/app-utils/person-erasure.js.map +1 -1
- package/src/lib/app-utils/scope-tokens.d.ts +132 -3
- package/src/lib/app-utils/scope-tokens.js +276 -3
- package/src/lib/app-utils/scope-tokens.js.map +1 -1
- package/src/lib/app-utils/site-placement.d.ts +56 -0
- package/src/lib/app-utils/site-placement.js +88 -0
- package/src/lib/app-utils/site-placement.js.map +1 -0
- package/src/lib/app-utils/site-preview.d.ts +6 -2
- package/src/lib/app-utils/site-preview.js +5 -3
- package/src/lib/app-utils/site-preview.js.map +1 -1
- package/src/lib/app-utils/site-unavailable.d.ts +4 -7
- package/src/lib/app-utils/site-unavailable.js +4 -8
- package/src/lib/app-utils/site-unavailable.js.map +1 -1
- package/src/lib/app-utils/transfer-launcher-context.d.ts +17 -1
- package/src/lib/app-utils/transfer-launcher-context.js.map +1 -1
- package/src/lib/data-transfer/access.d.ts +10 -18
- package/src/lib/data-transfer/access.js +21 -25
- package/src/lib/data-transfer/access.js.map +1 -1
- package/src/lib/data-transfer/resource.d.ts +13 -14
- package/src/lib/data-transfer/resource.js +9 -10
- package/src/lib/data-transfer/resource.js.map +1 -1
- package/src/lib/foundation/definitions/org-billing.types.js +2 -2
- package/src/lib/foundation/definitions/org-billing.types.js.map +1 -1
- package/src/lib/foundation/definitions/platform.types.d.ts +1 -1
- package/src/lib/foundation/definitions/platform.types.js.map +1 -1
- package/src/lib/foundation/definitions/write-deny-coverage.util.d.ts +1 -1
- package/src/lib/foundation/definitions/write-deny-coverage.util.js +1 -1
- package/src/lib/foundation/definitions/write-deny-coverage.util.js.map +1 -1
- package/src/lib/plugin-manager/first-party-plugins.generated.js +4 -5
- package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
- package/src/lib/plugin-manager/plugin-contact-capture.d.ts +18 -0
- package/src/lib/plugin-manager/plugin-contact-capture.js +26 -0
- package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
- package/src/lib/plugin-manager/plugin-entitlements.d.ts +12 -0
- package/src/lib/plugin-manager/plugin-entitlements.js +3 -1
- package/src/lib/plugin-manager/plugin-entitlements.js.map +1 -1
- package/src/lib/plugin-manager/plugin-person-erasure-notes.d.ts +61 -0
- package/src/lib/plugin-manager/plugin-person-erasure-notes.js +114 -0
- package/src/lib/plugin-manager/plugin-person-erasure-notes.js.map +1 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.d.ts +52 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.generated.d.ts +10 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.generated.js +82 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.generated.js.map +1 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.js +85 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.js.map +1 -0
- package/src/lib/plugin-manager/plugin-site-starters.d.ts +7 -0
- package/src/lib/plugin-manager/plugin-site-starters.js.map +1 -1
- package/src/lib/plugin-manager/plugin-transfer-resources.d.ts +56 -1
- package/src/lib/plugin-manager/plugin-transfer-resources.js +13 -0
- package/src/lib/plugin-manager/plugin-transfer-resources.js.map +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { AglynOrgMember, HostAccessRole } from '../foundation';
|
|
18
|
+
import type { AglynOrgCustomRole } from './org-permissions';
|
|
19
|
+
/** The one site `visibleTo` places a resource on, or `null` for every site, several, or none. */
|
|
20
|
+
export declare function oneSitePlacement(visibleTo: unknown): string | null;
|
|
21
|
+
/**
|
|
22
|
+
* The verdict for a resource placed at `visibleTo`: see above. `site` is asked
|
|
23
|
+
* only when the workspace key did not settle it, so a door pays for reading the
|
|
24
|
+
* site only then.
|
|
25
|
+
*/
|
|
26
|
+
export declare function placementVerdict<T extends boolean | Promise<boolean>>(input: {
|
|
27
|
+
member: Partial<AglynOrgMember> | null | undefined;
|
|
28
|
+
visibleTo: unknown;
|
|
29
|
+
workspace: boolean;
|
|
30
|
+
site: (hostId: string) => T;
|
|
31
|
+
}): boolean | T;
|
|
32
|
+
/**
|
|
33
|
+
* The site key as the site's stamp gives it, read as the rules read it:
|
|
34
|
+
* `memberPermissions[uid][key]`, else, on a site the projection has not reached
|
|
35
|
+
* since the key existed, the site role's preset, unless someone decided against
|
|
36
|
+
* this member in a way the stamp would carry: a custom role, or their own
|
|
37
|
+
* workspace key refused. Those wait for the stamp, so nobody refused regains it
|
|
38
|
+
* from `memberRoles`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function stampedPlacementKey(stamps: {
|
|
41
|
+
memberPermissions?: unknown;
|
|
42
|
+
memberRoles?: unknown;
|
|
43
|
+
} | null | undefined, uid: string, key: string, preset: Readonly<Partial<Record<HostAccessRole, boolean>>>, member: (Partial<AglynOrgMember> & {
|
|
44
|
+
roleId?: unknown;
|
|
45
|
+
permissions?: unknown;
|
|
46
|
+
}) | null | undefined, workspaceKey: string): boolean;
|
|
47
|
+
/** The site key from the membership alone, by the function the site's stamp is written from. */
|
|
48
|
+
export declare function resolvedPlacementKey(member: Partial<AglynOrgMember> | null | undefined, hostId: string, key: string, customRole?: AglynOrgCustomRole | null): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether deleting a resource is out of this member's reach whatever they hold:
|
|
51
|
+
* they do not reach every site, and it is placed on every site or on several. It
|
|
52
|
+
* belongs to the whole workspace.
|
|
53
|
+
*/
|
|
54
|
+
export declare function deleteBeyondReach(member: Partial<AglynOrgMember> | null | undefined, visibleTo: unknown): boolean;
|
|
55
|
+
/** The refusal for it, which names the reach it takes because no permission decides it. */
|
|
56
|
+
export declare function deleteBeyondReachRefusal(label: string): string;
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
*/ import { hostStampedSitePermission, resolveMemberHostPermissions, siteMayNarrow } from "./host-permissions.js";
|
|
17
|
+
import { hostRoleFor, isOrgWideMember } from "./organizations.js";
|
|
18
|
+
/*
|
|
19
|
+
* A RESOURCE PLACED ON ONE SITE ANSWERS TO THAT SITE (AGL-4047).
|
|
20
|
+
*
|
|
21
|
+
* The workspace's shared resources carry `visibleTo`, and one placed on exactly
|
|
22
|
+
* one site belongs to it. Where a plugin decides a resource's writes that way,
|
|
23
|
+
* its keys come in pairs: a workspace key, and a site key that follows it for a
|
|
24
|
+
* member of the whole workspace, which a site can narrow and raise
|
|
25
|
+
* (`narrowsPerSite`, `raisesPerSite`), and which a site collaborator holds by
|
|
26
|
+
* their site role. The verdict:
|
|
27
|
+
*
|
|
28
|
+
* - the workspace key admits, unless a site narrows the member on the one site
|
|
29
|
+
* the resource sits on;
|
|
30
|
+
* - else, on that one site, the site key.
|
|
31
|
+
*
|
|
32
|
+
* Placed on every site or on several, the workspace key alone: no one site can be
|
|
33
|
+
* asked, and a security rule cannot look through a list of them.
|
|
34
|
+
*
|
|
35
|
+
* The rules ask the same thing in their own words, so these are kept in step with
|
|
36
|
+
* them, placement test included.
|
|
37
|
+
*/ /** The one site `visibleTo` places a resource on, or `null` for every site, several, or none. */ export function oneSitePlacement(visibleTo) {
|
|
38
|
+
if (!Array.isArray(visibleTo) || visibleTo.length !== 1) return null;
|
|
39
|
+
const [token] = visibleTo;
|
|
40
|
+
const match = typeof token === 'string' ? /^host:([^:/]+)$/.exec(token) : null;
|
|
41
|
+
return match ? match[1] : null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The verdict for a resource placed at `visibleTo`: see above. `site` is asked
|
|
45
|
+
* only when the workspace key did not settle it, so a door pays for reading the
|
|
46
|
+
* site only then.
|
|
47
|
+
*/ export function placementVerdict(input) {
|
|
48
|
+
const hostId = oneSitePlacement(input.visibleTo);
|
|
49
|
+
if (!hostId) return input.workspace;
|
|
50
|
+
if (input.workspace && !siteMayNarrow(input.member, hostId)) return true;
|
|
51
|
+
return input.site(hostId);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The site key as the site's stamp gives it, read as the rules read it:
|
|
55
|
+
* `memberPermissions[uid][key]`, else, on a site the projection has not reached
|
|
56
|
+
* since the key existed, the site role's preset, unless someone decided against
|
|
57
|
+
* this member in a way the stamp would carry: a custom role, or their own
|
|
58
|
+
* workspace key refused. Those wait for the stamp, so nobody refused regains it
|
|
59
|
+
* from `memberRoles`.
|
|
60
|
+
*/ export function stampedPlacementKey(stamps, uid, key, preset, member, workspaceKey) {
|
|
61
|
+
var _stamps_memberPermissions_uid, _stamps_memberPermissions, _member_permissions;
|
|
62
|
+
const stamp = stamps == null ? void 0 : (_stamps_memberPermissions = stamps.memberPermissions) == null ? void 0 : (_stamps_memberPermissions_uid = _stamps_memberPermissions[uid]) == null ? void 0 : _stamps_memberPermissions_uid[key];
|
|
63
|
+
if (typeof stamp === 'boolean') return stamp;
|
|
64
|
+
if ((member == null ? void 0 : member.roleId) != null || (member == null ? void 0 : (_member_permissions = member.permissions) == null ? void 0 : _member_permissions[workspaceKey]) === false) return false;
|
|
65
|
+
return hostStampedSitePermission({
|
|
66
|
+
memberRoles: stamps == null ? void 0 : stamps.memberRoles
|
|
67
|
+
}, uid, key, preset);
|
|
68
|
+
}
|
|
69
|
+
/** The site key from the membership alone, by the function the site's stamp is written from. */ export function resolvedPlacementKey(member, hostId, key, customRole) {
|
|
70
|
+
if (!member || !hostRoleFor(member, hostId)) return false;
|
|
71
|
+
return resolveMemberHostPermissions({
|
|
72
|
+
member,
|
|
73
|
+
customRole: customRole != null ? customRole : null,
|
|
74
|
+
hostId
|
|
75
|
+
})[key] === true;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether deleting a resource is out of this member's reach whatever they hold:
|
|
79
|
+
* they do not reach every site, and it is placed on every site or on several. It
|
|
80
|
+
* belongs to the whole workspace.
|
|
81
|
+
*/ export function deleteBeyondReach(member, visibleTo) {
|
|
82
|
+
return !isOrgWideMember(member) && oneSitePlacement(visibleTo) === null;
|
|
83
|
+
}
|
|
84
|
+
/** The refusal for it, which names the reach it takes because no permission decides it. */ export function deleteBeyondReachRefusal(label) {
|
|
85
|
+
return `This ${label.toLowerCase()} is shared beyond one site, so deleting it takes access to every site in the workspace.`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=site-placement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-placement.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AglynOrgMember, HostAccessRole } from '../foundation'\nimport { hostStampedSitePermission, resolveMemberHostPermissions, siteMayNarrow } from './host-permissions'\nimport type { AglynOrgCustomRole } from './org-permissions'\nimport { hostRoleFor, isOrgWideMember } from './organizations'\n\n/*\n * A RESOURCE PLACED ON ONE SITE ANSWERS TO THAT SITE (AGL-4047).\n *\n * The workspace's shared resources carry `visibleTo`, and one placed on exactly\n * one site belongs to it. Where a plugin decides a resource's writes that way,\n * its keys come in pairs: a workspace key, and a site key that follows it for a\n * member of the whole workspace, which a site can narrow and raise\n * (`narrowsPerSite`, `raisesPerSite`), and which a site collaborator holds by\n * their site role. The verdict:\n *\n * - the workspace key admits, unless a site narrows the member on the one site\n * the resource sits on;\n * - else, on that one site, the site key.\n *\n * Placed on every site or on several, the workspace key alone: no one site can be\n * asked, and a security rule cannot look through a list of them.\n *\n * The rules ask the same thing in their own words, so these are kept in step with\n * them, placement test included.\n */\n\n/** The one site `visibleTo` places a resource on, or `null` for every site, several, or none. */\nexport function oneSitePlacement(visibleTo: unknown): string | null {\n if (!Array.isArray(visibleTo) || visibleTo.length !== 1) return null\n const [token] = visibleTo as unknown[]\n const match = typeof token === 'string' ? /^host:([^:/]+)$/.exec(token) : null\n return match ? match[1] : null\n}\n\n/**\n * The verdict for a resource placed at `visibleTo`: see above. `site` is asked\n * only when the workspace key did not settle it, so a door pays for reading the\n * site only then.\n */\nexport function placementVerdict<T extends boolean | Promise<boolean>>(input: {\n member: Partial<AglynOrgMember> | null | undefined\n visibleTo: unknown\n workspace: boolean\n site: (hostId: string) => T\n}): boolean | T {\n const hostId = oneSitePlacement(input.visibleTo)\n if (!hostId) return input.workspace\n if (input.workspace && !siteMayNarrow(input.member, hostId)) return true\n return input.site(hostId)\n}\n\n/**\n * The site key as the site's stamp gives it, read as the rules read it:\n * `memberPermissions[uid][key]`, else, on a site the projection has not reached\n * since the key existed, the site role's preset, unless someone decided against\n * this member in a way the stamp would carry: a custom role, or their own\n * workspace key refused. Those wait for the stamp, so nobody refused regains it\n * from `memberRoles`.\n */\nexport function stampedPlacementKey(\n stamps: { memberPermissions?: unknown; memberRoles?: unknown } | null | undefined,\n uid: string,\n key: string,\n preset: Readonly<Partial<Record<HostAccessRole, boolean>>>,\n member: (Partial<AglynOrgMember> & { roleId?: unknown; permissions?: unknown }) | null | undefined,\n workspaceKey: string,\n): boolean {\n const stamp = (stamps?.memberPermissions as Record<string, Record<string, unknown> | undefined> | undefined)?.[uid]?.[key]\n if (typeof stamp === 'boolean') return stamp\n if (member?.roleId != null || (member?.permissions as Record<string, unknown> | undefined)?.[workspaceKey] === false) return false\n return hostStampedSitePermission({ memberRoles: stamps?.memberRoles }, uid, key, preset)\n}\n\n/** The site key from the membership alone, by the function the site's stamp is written from. */\nexport function resolvedPlacementKey(\n member: Partial<AglynOrgMember> | null | undefined,\n hostId: string,\n key: string,\n customRole?: AglynOrgCustomRole | null,\n): boolean {\n if (!member || !hostRoleFor(member, hostId)) return false\n return resolveMemberHostPermissions({ member, customRole: customRole ?? null, hostId })[key] === true\n}\n\n/**\n * Whether deleting a resource is out of this member's reach whatever they hold:\n * they do not reach every site, and it is placed on every site or on several. It\n * belongs to the whole workspace.\n */\nexport function deleteBeyondReach(member: Partial<AglynOrgMember> | null | undefined, visibleTo: unknown): boolean {\n return !isOrgWideMember(member) && oneSitePlacement(visibleTo) === null\n}\n\n/** The refusal for it, which names the reach it takes because no permission decides it. */\nexport function deleteBeyondReachRefusal(label: string): string {\n return `This ${label.toLowerCase()} is shared beyond one site, so deleting it takes access to every site in the workspace.`\n}\n"],"names":["hostStampedSitePermission","resolveMemberHostPermissions","siteMayNarrow","hostRoleFor","isOrgWideMember","oneSitePlacement","visibleTo","Array","isArray","length","token","match","exec","placementVerdict","input","hostId","workspace","member","site","stampedPlacementKey","stamps","uid","key","preset","workspaceKey","stamp","memberPermissions","roleId","permissions","memberRoles","resolvedPlacementKey","customRole","deleteBeyondReach","deleteBeyondReachRefusal","label","toLowerCase"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,yBAAyB,EAAEC,4BAA4B,EAAEC,aAAa,QAAQ,wBAAoB;AAE3G,SAASC,WAAW,EAAEC,eAAe,QAAQ,qBAAiB;AAE9D;;;;;;;;;;;;;;;;;;;CAmBC,GAED,+FAA+F,GAC/F,OAAO,SAASC,iBAAiBC,SAAkB;IACjD,IAAI,CAACC,MAAMC,OAAO,CAACF,cAAcA,UAAUG,MAAM,KAAK,GAAG,OAAO;IAChE,MAAM,CAACC,MAAM,GAAGJ;IAChB,MAAMK,QAAQ,OAAOD,UAAU,WAAW,kBAAkBE,IAAI,CAACF,SAAS;IAC1E,OAAOC,QAAQA,KAAK,CAAC,EAAE,GAAG;AAC5B;AAEA;;;;CAIC,GACD,OAAO,SAASE,iBAAuDC,KAKtE;IACC,MAAMC,SAASV,iBAAiBS,MAAMR,SAAS;IAC/C,IAAI,CAACS,QAAQ,OAAOD,MAAME,SAAS;IACnC,IAAIF,MAAME,SAAS,IAAI,CAACd,cAAcY,MAAMG,MAAM,EAAEF,SAAS,OAAO;IACpE,OAAOD,MAAMI,IAAI,CAACH;AACpB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASI,oBACdC,MAAiF,EACjFC,GAAW,EACXC,GAAW,EACXC,MAA0D,EAC1DN,MAAkG,EAClGO,YAAoB;QAEN,+BAACJ,2BAEgBH;IAF/B,MAAMQ,QAASL,2BAAAA,4BAAAA,OAAQM,iBAAiB,sBAA1B,gCAAA,AAACN,yBAA+F,CAACC,IAAI,qBAArG,6BAAuG,CAACC,IAAI;IAC1H,IAAI,OAAOG,UAAU,WAAW,OAAOA;IACvC,IAAIR,CAAAA,0BAAAA,OAAQU,MAAM,KAAI,QAAQ,CAACV,2BAAAA,sBAAAA,OAAQW,WAAW,qBAApB,AAACX,mBAA6D,CAACO,aAAa,MAAK,OAAO,OAAO;IAC7H,OAAOxB,0BAA0B;QAAE6B,WAAW,EAAET,0BAAAA,OAAQS,WAAW;IAAC,GAAGR,KAAKC,KAAKC;AACnF;AAEA,8FAA8F,GAC9F,OAAO,SAASO,qBACdb,MAAkD,EAClDF,MAAc,EACdO,GAAW,EACXS,UAAsC;IAEtC,IAAI,CAACd,UAAU,CAACd,YAAYc,QAAQF,SAAS,OAAO;IACpD,OAAOd,6BAA6B;QAAEgB;QAAQc,UAAU,EAAEA,qBAAAA,aAAc;QAAMhB;IAAO,EAAE,CAACO,IAAI,KAAK;AACnG;AAEA;;;;CAIC,GACD,OAAO,SAASU,kBAAkBf,MAAkD,EAAEX,SAAkB;IACtG,OAAO,CAACF,gBAAgBa,WAAWZ,iBAAiBC,eAAe;AACrE;AAEA,yFAAyF,GACzF,OAAO,SAAS2B,yBAAyBC,KAAa;IACpD,OAAO,CAAC,KAAK,EAAEA,MAAMC,WAAW,GAAG,uFAAuF,CAAC;AAC7H"}
|
|
@@ -86,11 +86,13 @@ export declare function previewScreenIds(host: Pick<SitePreviewHost, 'previewScr
|
|
|
86
86
|
export declare function sitePreviewPaths(host: Pick<SitePreviewHost, 'previewScreens' | 'screens'> | null | undefined): string[];
|
|
87
87
|
/**
|
|
88
88
|
* Whether a request path is one the team must be routed around the public
|
|
89
|
-
* cache for: every path while the site is in preview
|
|
90
|
-
* page in preview. Trailing slashes are ignored, as Next ignores
|
|
89
|
+
* cache for: every path while the site is in preview or in maintenance, or the
|
|
90
|
+
* address of a page in preview. Trailing slashes are ignored, as Next ignores
|
|
91
|
+
* them.
|
|
91
92
|
*/
|
|
92
93
|
export declare function isSitePreviewRequest(verdict: {
|
|
93
94
|
preview?: boolean;
|
|
95
|
+
maintenance?: boolean;
|
|
94
96
|
previewPaths?: readonly string[];
|
|
95
97
|
} | null | undefined, pathname: string): boolean;
|
|
96
98
|
/**
|
|
@@ -149,5 +151,7 @@ export declare function sitePreviewNotice(siteName: string | null | undefined):
|
|
|
149
151
|
};
|
|
150
152
|
/** The fixed line the team reads on every page of a site in preview. */
|
|
151
153
|
export declare const SITE_PREVIEW_BANNER_TEXT = "Preview \u2014 only your team can see this site. Make it public in Admin \u2192 Error pages.";
|
|
154
|
+
/** The same line for a site in maintenance mode, whatever else it is in. */
|
|
155
|
+
export declare const SITE_MAINTENANCE_BANNER_TEXT = "Maintenance mode \u2014 only your team can see this site. Turn it off in Admin \u2192 Error pages.";
|
|
152
156
|
/** The same line for one page in preview on a public site. */
|
|
153
157
|
export declare const PAGE_PREVIEW_BANNER_TEXT = "Preview \u2014 only your team can see this page. Make it public in its Page Access card.";
|
|
@@ -93,11 +93,12 @@
|
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Whether a request path is one the team must be routed around the public
|
|
96
|
-
* cache for: every path while the site is in preview
|
|
97
|
-
* page in preview. Trailing slashes are ignored, as Next ignores
|
|
96
|
+
* cache for: every path while the site is in preview or in maintenance, or the
|
|
97
|
+
* address of a page in preview. Trailing slashes are ignored, as Next ignores
|
|
98
|
+
* them.
|
|
98
99
|
*/ export function isSitePreviewRequest(verdict, pathname) {
|
|
99
100
|
if (!verdict) return false;
|
|
100
|
-
if (verdict.preview === true) return true;
|
|
101
|
+
if (verdict.preview === true || verdict.maintenance === true) return true;
|
|
101
102
|
const paths = verdict.previewPaths;
|
|
102
103
|
if (!paths || !paths.length) return false;
|
|
103
104
|
const normalized = routingPathToRequestPath(pathname);
|
|
@@ -162,6 +163,7 @@ export function sitePreviewSwitchPlan(host, enabled) {
|
|
|
162
163
|
};
|
|
163
164
|
}
|
|
164
165
|
/** The fixed line the team reads on every page of a site in preview. */ export const SITE_PREVIEW_BANNER_TEXT = 'Preview — only your team can see this site. Make it public in Admin → Error pages.';
|
|
166
|
+
/** The same line for a site in maintenance mode, whatever else it is in. */ export const SITE_MAINTENANCE_BANNER_TEXT = 'Maintenance mode — only your team can see this site. Turn it off in Admin → Error pages.';
|
|
165
167
|
/** The same line for one page in preview on a public site. */ export const PAGE_PREVIEW_BANNER_TEXT = 'Preview — only your team can see this page. Make it public in its Page Access card.';
|
|
166
168
|
|
|
167
169
|
//# sourceMappingURL=site-preview.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-preview.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/**\n * Preview: a site, or one page of it, that only its team can see (AGL-4086).\n *\n * The public gets the site's 503 page, or a \"Coming soon\" notice, at every\n * address of a site in preview, and the site's 404 at a page in preview. The\n * site's team, and Aglyn staff, get the whole site. Flipping the switch makes\n * it public to everyone.\n *\n * DEPENDENCY-FREE ON PURPOSE. The tenant middleware runs on the edge and reads\n * the cookie name and the enter path from here; it deep-imports its helpers so\n * the edge bundle does not drag a barrel, and this module imports nothing, as\n * `entry-preview-link.ts` does not.\n *\n * ## The two fields\n *\n * - `host.preview: true` puts the WHOLE SITE in preview. Absent is public: a\n * missing field must never read as \"hide this site\", or a schema slip would\n * take every customer off the air.\n * - `host.previewScreens: { [screenId]: true }` puts ONE PAGE in preview, on a\n * site that is otherwise public. It lives on the host document rather than\n * on the screen for one reason: the tenant middleware has to know, before\n * any cached HTML answers, which addresses a team member must be routed\n * around the cache for, and the verdict route it asks holds the host\n * document and nothing else.\n *\n * `host.publicSinceMs` records that the site has been public at least once,\n * so the switch that makes it public reports `site_published` only for a site\n * that never was.\n */\n\n/** A host document, as far as preview reads it. */\nexport interface SitePreviewHost {\n preview?: boolean | null\n previewScreens?: Record<string, unknown> | null\n publicSinceMs?: number | null\n /** The routing map: screen id → routing-map path (`about`, `/`). */\n screens?: Record<string, unknown> | null\n}\n\n/**\n * The cookie a console-minted enter link plants on the site's own host. It\n * holds a signed token bound to one site, verified on every request by the\n * tenant; the edge only checks that it is present.\n */\nexport const SITE_PREVIEW_COOKIE = 'aglyn_site_preview'\n\n/**\n * The console sign-in's hint cookie on the tenant apex (`Domain=.aglyn.app`),\n * planted by `/api/edit-hint/set`. Named here as well so the edge reads one\n * dependency-free module; the server side keeps its own constant beside the\n * signer.\n */\nexport const SITE_PREVIEW_EDIT_HINT_COOKIE = 'aglyn_edit_hint'\n\n/** The tenant route a console-minted enter link lands on. */\nexport const SITE_PREVIEW_ENTER_PATH = '/api/site-preview/enter'\n\n/** How long a planted preview cookie lasts: 12 hours. */\nexport const SITE_PREVIEW_COOKIE_TTL_MS = 12 * 60 * 60 * 1000\n\n/**\n * How long an enter link's blob lasts: two minutes. It rides a URL, which is\n * logged and can be shared, so it lives only as long as one click takes.\n */\nexport const SITE_PREVIEW_ENTER_TTL_MS = 2 * 60 * 1000\n\n/** Whether the whole site is in preview. Only an explicit `true` is. */\nexport function isHostInPreview(\n host: Pick<SitePreviewHost, 'preview'> | null | undefined,\n): boolean {\n return host?.preview === true\n}\n\n/** Whether one page of the site is in preview. */\nexport function isScreenInPreview(\n host: Pick<SitePreviewHost, 'previewScreens'> | null | undefined,\n screenId: string | null | undefined,\n): boolean {\n if (!screenId) return false\n const map = host?.previewScreens\n if (!map || typeof map !== 'object') return false\n return (map as Record<string, unknown>)[screenId] === true\n}\n\n/** The ids of the pages in preview, in a stable order. */\nexport function previewScreenIds(\n host: Pick<SitePreviewHost, 'previewScreens'> | null | undefined,\n): string[] {\n const map = host?.previewScreens\n if (!map || typeof map !== 'object') return []\n return Object.keys(map)\n .filter((id) => (map as Record<string, unknown>)[id] === true)\n .sort()\n}\n\n/** A routing-map path (`about`, `services/roofing`, `/`) as a request path. */\nfunction routingPathToRequestPath(path: string): string {\n const trimmed = path.trim().replace(/^\\/+|\\/+$/g, '')\n return trimmed ? `/${trimmed}` : '/'\n}\n\n/**\n * The request paths of the published pages in preview, for the middleware.\n * A page in preview that is not published has no address, so it has none.\n */\nexport function sitePreviewPaths(\n host: Pick<SitePreviewHost, 'previewScreens' | 'screens'> | null | undefined,\n): string[] {\n const routing = host?.screens\n if (!routing || typeof routing !== 'object') return []\n const paths = new Set<string>()\n for (const screenId of previewScreenIds(host)) {\n const path = (routing as Record<string, unknown>)[screenId]\n if (typeof path === 'string') paths.add(routingPathToRequestPath(path))\n }\n return [...paths].sort()\n}\n\n/**\n * Whether a request path is one the team must be routed around the public\n * cache for: every path while the site is in preview, or the address of a\n * page in preview. Trailing slashes are ignored, as Next ignores them.\n */\nexport function isSitePreviewRequest(\n verdict: { preview?: boolean; previewPaths?: readonly string[] } | null | undefined,\n pathname: string,\n): boolean {\n if (!verdict) return false\n if (verdict.preview === true) return true\n const paths = verdict.previewPaths\n if (!paths || !paths.length) return false\n const normalized = routingPathToRequestPath(pathname)\n return paths.includes(normalized)\n}\n\n/**\n * Where a create flow starts by default: in preview for a site brought in\n * from somewhere else, public for everything else. A site that already exists\n * elsewhere should not be public before its owner has looked at it; a new\n * site is the launch its owner asked for.\n */\nexport type SitePreviewStart = 'import' | 'ai' | 'starter' | 'blank'\n\nexport function sitePreviewStartsOn(start: string | null | undefined): boolean {\n return start === 'import'\n}\n\n/**\n * What a create request asks for: an explicit `preview` boolean wins, and\n * without one the start decides ({@link sitePreviewStartsOn}).\n */\nexport function sitePreviewForCreate(body: {\n preview?: unknown\n start?: unknown\n} | null | undefined): boolean {\n if (typeof body?.preview === 'boolean') return body.preview\n return sitePreviewStartsOn(typeof body?.start === 'string' ? body.start : null)\n}\n\n/**\n * What flipping the site's switch writes, and whether it is the site's first\n * time in public.\n *\n * - Turning preview ON for a site that is public now stamps `publicSinceMs`\n * when it is absent: the site WAS public, and the stamp is what keeps a\n * later \"make it public\" from reporting a first publish it is not.\n * - Turning it OFF clears `preview`, and stamps `publicSinceMs` when the site\n * has never been public. That is the moment `site_published` is reported,\n * once, for a site that has pages to show.\n */\nexport interface SitePreviewSwitchPlan {\n /** `preview` after the write: true, or the field removed. */\n preview: boolean\n /** Stamp `publicSinceMs` with the write's time. */\n stampPublicSince: boolean\n /** Report `site_published` (first publish) for this flip. */\n firstPublic: boolean\n /** Nothing would change; the caller writes nothing. */\n unchanged: boolean\n}\n\nexport function sitePreviewSwitchPlan(\n host: SitePreviewHost | null | undefined,\n enabled: boolean,\n): SitePreviewSwitchPlan {\n const inPreview = isHostInPreview(host)\n const everPublic = typeof host?.publicSinceMs === 'number'\n if (enabled) {\n return {\n preview: true,\n stampPublicSince: !inPreview && !everPublic,\n firstPublic: false,\n unchanged: inPreview,\n }\n }\n const hasPages = Object.keys(host?.screens ?? {}).length > 0\n return {\n preview: false,\n stampPublicSince: inPreview && !everPublic,\n firstPublic: inPreview && !everPublic && hasPages,\n unchanged: !inPreview,\n }\n}\n\n/**\n * A return path an enter link may send the browser to: a path on the site's\n * own origin, and nothing else. Anything that could leave the origin — a\n * scheme, `//host`, a backslash the browser would read as a slash, a control\n * character — answers `/`.\n */\nexport function sitePreviewReturnPath(raw: string | null | undefined): string {\n if (typeof raw !== 'string' || !raw) return '/'\n if (raw.length > 2048) return '/'\n if (!raw.startsWith('/')) return '/'\n if (raw.startsWith('//')) return '/'\n // eslint-disable-next-line no-control-regex\n if (/[\\\\\\u0000-\\u001f\\u007f]/.test(raw)) return '/'\n return raw\n}\n\n/**\n * What the public sees at a site in preview when no 503 page is assigned:\n * the holding page's words, because to a visitor the two are the same thing,\n * a site on its way.\n */\nexport function sitePreviewNotice(siteName: string | null | undefined): {\n title: string\n body: string\n} {\n const name = String(siteName ?? '').trim()\n return name\n ? { title: name, body: 'This site is coming soon. Check back shortly.' }\n : { title: 'Coming soon', body: 'This site is on its way. Check back shortly.' }\n}\n\n/** The fixed line the team reads on every page of a site in preview. */\nexport const SITE_PREVIEW_BANNER_TEXT =\n 'Preview — only your team can see this site. Make it public in Admin → Error pages.'\n\n/** The same line for one page in preview on a public site. */\nexport const PAGE_PREVIEW_BANNER_TEXT =\n 'Preview — only your team can see this page. Make it public in its Page Access card.'\n"],"names":["SITE_PREVIEW_COOKIE","SITE_PREVIEW_EDIT_HINT_COOKIE","SITE_PREVIEW_ENTER_PATH","SITE_PREVIEW_COOKIE_TTL_MS","SITE_PREVIEW_ENTER_TTL_MS","isHostInPreview","host","preview","isScreenInPreview","screenId","map","previewScreens","previewScreenIds","Object","keys","filter","id","sort","routingPathToRequestPath","path","trimmed","trim","replace","sitePreviewPaths","routing","screens","paths","Set","add","isSitePreviewRequest","verdict","pathname","previewPaths","length","normalized","includes","sitePreviewStartsOn","start","sitePreviewForCreate","body","sitePreviewSwitchPlan","enabled","inPreview","everPublic","publicSinceMs","stampPublicSince","firstPublic","unchanged","hasPages","sitePreviewReturnPath","raw","startsWith","test","sitePreviewNotice","siteName","name","String","title","SITE_PREVIEW_BANNER_TEXT","PAGE_PREVIEW_BANNER_TEXT"],"mappings":"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"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-preview.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/**\n * Preview: a site, or one page of it, that only its team can see (AGL-4086).\n *\n * The public gets the site's 503 page, or a \"Coming soon\" notice, at every\n * address of a site in preview, and the site's 404 at a page in preview. The\n * site's team, and Aglyn staff, get the whole site. Flipping the switch makes\n * it public to everyone.\n *\n * DEPENDENCY-FREE ON PURPOSE. The tenant middleware runs on the edge and reads\n * the cookie name and the enter path from here; it deep-imports its helpers so\n * the edge bundle does not drag a barrel, and this module imports nothing, as\n * `entry-preview-link.ts` does not.\n *\n * ## The two fields\n *\n * - `host.preview: true` puts the WHOLE SITE in preview. Absent is public: a\n * missing field must never read as \"hide this site\", or a schema slip would\n * take every customer off the air.\n * - `host.previewScreens: { [screenId]: true }` puts ONE PAGE in preview, on a\n * site that is otherwise public. It lives on the host document rather than\n * on the screen for one reason: the tenant middleware has to know, before\n * any cached HTML answers, which addresses a team member must be routed\n * around the cache for, and the verdict route it asks holds the host\n * document and nothing else.\n *\n * `host.publicSinceMs` records that the site has been public at least once,\n * so the switch that makes it public reports `site_published` only for a site\n * that never was.\n */\n\n/** A host document, as far as preview reads it. */\nexport interface SitePreviewHost {\n preview?: boolean | null\n previewScreens?: Record<string, unknown> | null\n publicSinceMs?: number | null\n /** The routing map: screen id → routing-map path (`about`, `/`). */\n screens?: Record<string, unknown> | null\n}\n\n/**\n * The cookie a console-minted enter link plants on the site's own host. It\n * holds a signed token bound to one site, verified on every request by the\n * tenant; the edge only checks that it is present.\n */\nexport const SITE_PREVIEW_COOKIE = 'aglyn_site_preview'\n\n/**\n * The console sign-in's hint cookie on the tenant apex (`Domain=.aglyn.app`),\n * planted by `/api/edit-hint/set`. Named here as well so the edge reads one\n * dependency-free module; the server side keeps its own constant beside the\n * signer.\n */\nexport const SITE_PREVIEW_EDIT_HINT_COOKIE = 'aglyn_edit_hint'\n\n/** The tenant route a console-minted enter link lands on. */\nexport const SITE_PREVIEW_ENTER_PATH = '/api/site-preview/enter'\n\n/** How long a planted preview cookie lasts: 12 hours. */\nexport const SITE_PREVIEW_COOKIE_TTL_MS = 12 * 60 * 60 * 1000\n\n/**\n * How long an enter link's blob lasts: two minutes. It rides a URL, which is\n * logged and can be shared, so it lives only as long as one click takes.\n */\nexport const SITE_PREVIEW_ENTER_TTL_MS = 2 * 60 * 1000\n\n/** Whether the whole site is in preview. Only an explicit `true` is. */\nexport function isHostInPreview(\n host: Pick<SitePreviewHost, 'preview'> | null | undefined,\n): boolean {\n return host?.preview === true\n}\n\n/** Whether one page of the site is in preview. */\nexport function isScreenInPreview(\n host: Pick<SitePreviewHost, 'previewScreens'> | null | undefined,\n screenId: string | null | undefined,\n): boolean {\n if (!screenId) return false\n const map = host?.previewScreens\n if (!map || typeof map !== 'object') return false\n return (map as Record<string, unknown>)[screenId] === true\n}\n\n/** The ids of the pages in preview, in a stable order. */\nexport function previewScreenIds(\n host: Pick<SitePreviewHost, 'previewScreens'> | null | undefined,\n): string[] {\n const map = host?.previewScreens\n if (!map || typeof map !== 'object') return []\n return Object.keys(map)\n .filter((id) => (map as Record<string, unknown>)[id] === true)\n .sort()\n}\n\n/** A routing-map path (`about`, `services/roofing`, `/`) as a request path. */\nfunction routingPathToRequestPath(path: string): string {\n const trimmed = path.trim().replace(/^\\/+|\\/+$/g, '')\n return trimmed ? `/${trimmed}` : '/'\n}\n\n/**\n * The request paths of the published pages in preview, for the middleware.\n * A page in preview that is not published has no address, so it has none.\n */\nexport function sitePreviewPaths(\n host: Pick<SitePreviewHost, 'previewScreens' | 'screens'> | null | undefined,\n): string[] {\n const routing = host?.screens\n if (!routing || typeof routing !== 'object') return []\n const paths = new Set<string>()\n for (const screenId of previewScreenIds(host)) {\n const path = (routing as Record<string, unknown>)[screenId]\n if (typeof path === 'string') paths.add(routingPathToRequestPath(path))\n }\n return [...paths].sort()\n}\n\n/**\n * Whether a request path is one the team must be routed around the public\n * cache for: every path while the site is in preview or in maintenance, or the\n * address of a page in preview. Trailing slashes are ignored, as Next ignores\n * them.\n */\nexport function isSitePreviewRequest(\n verdict:\n | { preview?: boolean; maintenance?: boolean; previewPaths?: readonly string[] }\n | null\n | undefined,\n pathname: string,\n): boolean {\n if (!verdict) return false\n if (verdict.preview === true || verdict.maintenance === true) return true\n const paths = verdict.previewPaths\n if (!paths || !paths.length) return false\n const normalized = routingPathToRequestPath(pathname)\n return paths.includes(normalized)\n}\n\n/**\n * Where a create flow starts by default: in preview for a site brought in\n * from somewhere else, public for everything else. A site that already exists\n * elsewhere should not be public before its owner has looked at it; a new\n * site is the launch its owner asked for.\n */\nexport type SitePreviewStart = 'import' | 'ai' | 'starter' | 'blank'\n\nexport function sitePreviewStartsOn(start: string | null | undefined): boolean {\n return start === 'import'\n}\n\n/**\n * What a create request asks for: an explicit `preview` boolean wins, and\n * without one the start decides ({@link sitePreviewStartsOn}).\n */\nexport function sitePreviewForCreate(body: {\n preview?: unknown\n start?: unknown\n} | null | undefined): boolean {\n if (typeof body?.preview === 'boolean') return body.preview\n return sitePreviewStartsOn(typeof body?.start === 'string' ? body.start : null)\n}\n\n/**\n * What flipping the site's switch writes, and whether it is the site's first\n * time in public.\n *\n * - Turning preview ON for a site that is public now stamps `publicSinceMs`\n * when it is absent: the site WAS public, and the stamp is what keeps a\n * later \"make it public\" from reporting a first publish it is not.\n * - Turning it OFF clears `preview`, and stamps `publicSinceMs` when the site\n * has never been public. That is the moment `site_published` is reported,\n * once, for a site that has pages to show.\n */\nexport interface SitePreviewSwitchPlan {\n /** `preview` after the write: true, or the field removed. */\n preview: boolean\n /** Stamp `publicSinceMs` with the write's time. */\n stampPublicSince: boolean\n /** Report `site_published` (first publish) for this flip. */\n firstPublic: boolean\n /** Nothing would change; the caller writes nothing. */\n unchanged: boolean\n}\n\nexport function sitePreviewSwitchPlan(\n host: SitePreviewHost | null | undefined,\n enabled: boolean,\n): SitePreviewSwitchPlan {\n const inPreview = isHostInPreview(host)\n const everPublic = typeof host?.publicSinceMs === 'number'\n if (enabled) {\n return {\n preview: true,\n stampPublicSince: !inPreview && !everPublic,\n firstPublic: false,\n unchanged: inPreview,\n }\n }\n const hasPages = Object.keys(host?.screens ?? {}).length > 0\n return {\n preview: false,\n stampPublicSince: inPreview && !everPublic,\n firstPublic: inPreview && !everPublic && hasPages,\n unchanged: !inPreview,\n }\n}\n\n/**\n * A return path an enter link may send the browser to: a path on the site's\n * own origin, and nothing else. Anything that could leave the origin — a\n * scheme, `//host`, a backslash the browser would read as a slash, a control\n * character — answers `/`.\n */\nexport function sitePreviewReturnPath(raw: string | null | undefined): string {\n if (typeof raw !== 'string' || !raw) return '/'\n if (raw.length > 2048) return '/'\n if (!raw.startsWith('/')) return '/'\n if (raw.startsWith('//')) return '/'\n // eslint-disable-next-line no-control-regex\n if (/[\\\\\\u0000-\\u001f\\u007f]/.test(raw)) return '/'\n return raw\n}\n\n/**\n * What the public sees at a site in preview when no 503 page is assigned:\n * the holding page's words, because to a visitor the two are the same thing,\n * a site on its way.\n */\nexport function sitePreviewNotice(siteName: string | null | undefined): {\n title: string\n body: string\n} {\n const name = String(siteName ?? '').trim()\n return name\n ? { title: name, body: 'This site is coming soon. Check back shortly.' }\n : { title: 'Coming soon', body: 'This site is on its way. Check back shortly.' }\n}\n\n/** The fixed line the team reads on every page of a site in preview. */\nexport const SITE_PREVIEW_BANNER_TEXT =\n 'Preview — only your team can see this site. Make it public in Admin → Error pages.'\n\n/** The same line for a site in maintenance mode, whatever else it is in. */\nexport const SITE_MAINTENANCE_BANNER_TEXT =\n 'Maintenance mode — only your team can see this site. Turn it off in Admin → Error pages.'\n\n/** The same line for one page in preview on a public site. */\nexport const PAGE_PREVIEW_BANNER_TEXT =\n 'Preview — only your team can see this page. Make it public in its Page Access card.'\n"],"names":["SITE_PREVIEW_COOKIE","SITE_PREVIEW_EDIT_HINT_COOKIE","SITE_PREVIEW_ENTER_PATH","SITE_PREVIEW_COOKIE_TTL_MS","SITE_PREVIEW_ENTER_TTL_MS","isHostInPreview","host","preview","isScreenInPreview","screenId","map","previewScreens","previewScreenIds","Object","keys","filter","id","sort","routingPathToRequestPath","path","trimmed","trim","replace","sitePreviewPaths","routing","screens","paths","Set","add","isSitePreviewRequest","verdict","pathname","maintenance","previewPaths","length","normalized","includes","sitePreviewStartsOn","start","sitePreviewForCreate","body","sitePreviewSwitchPlan","enabled","inPreview","everPublic","publicSinceMs","stampPublicSince","firstPublic","unchanged","hasPages","sitePreviewReturnPath","raw","startsWith","test","sitePreviewNotice","siteName","name","String","title","SITE_PREVIEW_BANNER_TEXT","SITE_MAINTENANCE_BANNER_TEXT","PAGE_PREVIEW_BANNER_TEXT"],"mappings":"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"}
|
|
@@ -75,7 +75,7 @@ export declare function isHostInMaintenance(host: {
|
|
|
75
75
|
} | null | undefined): boolean;
|
|
76
76
|
/** What the middleware knows about a site, from its verdict. */
|
|
77
77
|
export interface SiteUnavailableVerdict {
|
|
78
|
-
/** Maintenance mode is on. */
|
|
78
|
+
/** Maintenance mode is on: the public gets the notice, the team the site. */
|
|
79
79
|
maintenance?: boolean;
|
|
80
80
|
/** The WHOLE site is in preview. One page in preview is not this. */
|
|
81
81
|
preview?: boolean;
|
|
@@ -95,12 +95,9 @@ export interface SiteUnavailableRouting {
|
|
|
95
95
|
/**
|
|
96
96
|
* Does this page request get the site's 503 answer as an HTTP 503?
|
|
97
97
|
*
|
|
98
|
-
* - **Maintenance: yes, for
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* - **A site in preview: yes, for the public**, the requests answered from the
|
|
102
|
-
* shared cache. A request carrying a team cookie goes to the uncached
|
|
103
|
-
* preview route instead, which shows the team the whole site.
|
|
98
|
+
* - **Maintenance or a site in preview: yes, for the public**, the requests
|
|
99
|
+
* answered from the shared cache. A request carrying a team cookie goes to
|
|
100
|
+
* the uncached preview route instead, which shows the team the whole site.
|
|
104
101
|
* - **An entry preview link: no.** When the site is unavailable its route
|
|
105
102
|
* redirects to the plain address, which answers 503 by the rules above; a
|
|
106
103
|
* 503 set here would only argue with that redirect.
|
|
@@ -70,12 +70,9 @@
|
|
|
70
70
|
/**
|
|
71
71
|
* Does this page request get the site's 503 answer as an HTTP 503?
|
|
72
72
|
*
|
|
73
|
-
* - **Maintenance: yes, for
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* - **A site in preview: yes, for the public**, the requests answered from the
|
|
77
|
-
* shared cache. A request carrying a team cookie goes to the uncached
|
|
78
|
-
* preview route instead, which shows the team the whole site.
|
|
73
|
+
* - **Maintenance or a site in preview: yes, for the public**, the requests
|
|
74
|
+
* answered from the shared cache. A request carrying a team cookie goes to
|
|
75
|
+
* the uncached preview route instead, which shows the team the whole site.
|
|
79
76
|
* - **An entry preview link: no.** When the site is unavailable its route
|
|
80
77
|
* redirects to the plain address, which answers 503 by the rules above; a
|
|
81
78
|
* 503 set here would only argue with that redirect.
|
|
@@ -89,8 +86,7 @@
|
|
|
89
86
|
* an answer with a status of its own.
|
|
90
87
|
*/ export function siteUnavailableForRequest(verdict, routing) {
|
|
91
88
|
if (!verdict || routing.entryPreview || routing.noticeRequest) return false;
|
|
92
|
-
|
|
93
|
-
return verdict.preview === true && !routing.teamPreview;
|
|
89
|
+
return (verdict.maintenance === true || verdict.preview === true) && !routing.teamPreview;
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
//# sourceMappingURL=site-unavailable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-unavailable.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/**\n * The site's 503 answer, sent as a 503 (AGL-4110).\n *\n * Maintenance mode (AGL-131) and preview (AGL-4086) answer a visitor who is\n * not let through with the site's designed 503 page, or the built-in notice,\n * at every address. The body was right and the status was not: every address\n * said `200 OK`, which tells a crawler the notice IS the page. A live site\n * that spent a weekend in maintenance could be re-indexed as \"Temporarily\n * unavailable\" and drop out of search. `503` with `Retry-After` is the answer\n * that means \"this site is briefly down, come back\".\n *\n * The body still comes from the ISR-cached catch-all, exactly as before; only\n * the tenant middleware can set the status, because an App Router page has no\n * status lever and the middleware is the one layer that runs ahead of the\n * cache on every request. It asks {@link siteUnavailableForRequest}, reads the\n * page, and sends it as a 503, so a cached page body never decides the status.\n * Why it reads the page rather than putting the status on its rewrite is the\n * note beside that code: on Vercel that rewrite loses the page.\n *\n * DEPENDENCY-FREE ON PURPOSE, like `site-preview.ts`: the middleware runs on\n * the edge and deep-imports this leaf, so it imports nothing.\n */\n\n/**\n * How long a crawler or uptime check is told to wait before asking again, in\n * seconds: an hour.\n *\n * The bandwidth cap's figure (`BANDWIDTH_CAP_RETRY_AFTER_SECONDS`), for the\n * same reason. Both states end the moment the owner flips a switch, and the\n * site is back within about a minute, so no longer value is ever \"correct\".\n * Too long is wrong in the direction that costs the site: a crawler staying\n * away after the site came back. An hour is short enough to be wrong in the\n * recoverable direction, and long enough that a crawler does not spend its\n * visits re-reading \"not yet\".\n */\nexport const SITE_UNAVAILABLE_RETRY_AFTER_SECONDS = 3600\n\n/**\n * Marks the middleware's own read of the notice page, which comes back through\n * the middleware and must take the plain rewrite rather than read it again.\n *\n * Not a secret, and nothing is withheld behind it: a stranger who sends it gets\n * the same notice with a 200.\n */\nexport const SITE_NOTICE_REQUEST_HEADER = 'x-aglyn-site-notice'\n\n/**\n * How long a visitor waits on that read, in milliseconds, before being served\n * the plain rewrite. Generous, as the verdict's deadline is: a cold render\n * answers inside it, and the page still arrives if it does not.\n */\nexport const SITE_NOTICE_DEADLINE_MS = 8_000\n\n/**\n * Is the site in maintenance mode (AGL-131)?\n *\n * The loader's own test, shared with the verdict the middleware reads, so the\n * status and the body are decided by one predicate: a field the loader reads as\n * \"in maintenance\" is a field the middleware reads the same way.\n */\nexport function isHostInMaintenance(\n host: { maintenance?: unknown } | null | undefined,\n): boolean {\n return Boolean(host?.maintenance)\n}\n\n/** What the middleware knows about a site, from its verdict. */\nexport interface SiteUnavailableVerdict {\n /** Maintenance mode is on. */\n maintenance?: boolean\n /** The WHOLE site is in preview. One page in preview is not this. */\n preview?: boolean\n}\n\n/** How the middleware is routing this request. */\nexport interface SiteUnavailableRouting {\n /** An entry preview link (`?aglyn_preview=`) is being opened. */\n entryPreview: boolean\n /**\n * A team cookie sent this request around the cache to the uncached preview\n * route, which shows the team the site.\n */\n teamPreview: boolean\n /** The middleware's own read of the notice page, not a visitor. */\n noticeRequest?: boolean\n}\n\n/**\n * Does this page request get the site's 503 answer as an HTTP 503?\n *\n * - **Maintenance
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-unavailable.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/**\n * The site's 503 answer, sent as a 503 (AGL-4110).\n *\n * Maintenance mode (AGL-131) and preview (AGL-4086) answer a visitor who is\n * not let through with the site's designed 503 page, or the built-in notice,\n * at every address. The body was right and the status was not: every address\n * said `200 OK`, which tells a crawler the notice IS the page. A live site\n * that spent a weekend in maintenance could be re-indexed as \"Temporarily\n * unavailable\" and drop out of search. `503` with `Retry-After` is the answer\n * that means \"this site is briefly down, come back\".\n *\n * The body still comes from the ISR-cached catch-all, exactly as before; only\n * the tenant middleware can set the status, because an App Router page has no\n * status lever and the middleware is the one layer that runs ahead of the\n * cache on every request. It asks {@link siteUnavailableForRequest}, reads the\n * page, and sends it as a 503, so a cached page body never decides the status.\n * Why it reads the page rather than putting the status on its rewrite is the\n * note beside that code: on Vercel that rewrite loses the page.\n *\n * DEPENDENCY-FREE ON PURPOSE, like `site-preview.ts`: the middleware runs on\n * the edge and deep-imports this leaf, so it imports nothing.\n */\n\n/**\n * How long a crawler or uptime check is told to wait before asking again, in\n * seconds: an hour.\n *\n * The bandwidth cap's figure (`BANDWIDTH_CAP_RETRY_AFTER_SECONDS`), for the\n * same reason. Both states end the moment the owner flips a switch, and the\n * site is back within about a minute, so no longer value is ever \"correct\".\n * Too long is wrong in the direction that costs the site: a crawler staying\n * away after the site came back. An hour is short enough to be wrong in the\n * recoverable direction, and long enough that a crawler does not spend its\n * visits re-reading \"not yet\".\n */\nexport const SITE_UNAVAILABLE_RETRY_AFTER_SECONDS = 3600\n\n/**\n * Marks the middleware's own read of the notice page, which comes back through\n * the middleware and must take the plain rewrite rather than read it again.\n *\n * Not a secret, and nothing is withheld behind it: a stranger who sends it gets\n * the same notice with a 200.\n */\nexport const SITE_NOTICE_REQUEST_HEADER = 'x-aglyn-site-notice'\n\n/**\n * How long a visitor waits on that read, in milliseconds, before being served\n * the plain rewrite. Generous, as the verdict's deadline is: a cold render\n * answers inside it, and the page still arrives if it does not.\n */\nexport const SITE_NOTICE_DEADLINE_MS = 8_000\n\n/**\n * Is the site in maintenance mode (AGL-131)?\n *\n * The loader's own test, shared with the verdict the middleware reads, so the\n * status and the body are decided by one predicate: a field the loader reads as\n * \"in maintenance\" is a field the middleware reads the same way.\n */\nexport function isHostInMaintenance(\n host: { maintenance?: unknown } | null | undefined,\n): boolean {\n return Boolean(host?.maintenance)\n}\n\n/** What the middleware knows about a site, from its verdict. */\nexport interface SiteUnavailableVerdict {\n /** Maintenance mode is on: the public gets the notice, the team the site. */\n maintenance?: boolean\n /** The WHOLE site is in preview. One page in preview is not this. */\n preview?: boolean\n}\n\n/** How the middleware is routing this request. */\nexport interface SiteUnavailableRouting {\n /** An entry preview link (`?aglyn_preview=`) is being opened. */\n entryPreview: boolean\n /**\n * A team cookie sent this request around the cache to the uncached preview\n * route, which shows the team the site.\n */\n teamPreview: boolean\n /** The middleware's own read of the notice page, not a visitor. */\n noticeRequest?: boolean\n}\n\n/**\n * Does this page request get the site's 503 answer as an HTTP 503?\n *\n * - **Maintenance or a site in preview: yes, for the public**, the requests\n * answered from the shared cache. A request carrying a team cookie goes to\n * the uncached preview route instead, which shows the team the whole site.\n * - **An entry preview link: no.** When the site is unavailable its route\n * redirects to the plain address, which answers 503 by the rules above; a\n * 503 set here would only argue with that redirect.\n * - **One page in preview: no.** The public gets the site's 404 there, and the\n * render's own 404 decides that status.\n * - **The middleware's own read of the page: no.** That is how the body of the\n * 503 is fetched, and it would otherwise fetch itself.\n *\n * Nothing here is a permission. The body is the loader's decision, and a\n * request this answers `false` for is one whose body is already the site, or\n * an answer with a status of its own.\n */\nexport function siteUnavailableForRequest(\n verdict: SiteUnavailableVerdict | null | undefined,\n routing: SiteUnavailableRouting,\n): boolean {\n if (!verdict || routing.entryPreview || routing.noticeRequest) return false\n return (\n (verdict.maintenance === true || verdict.preview === true) &&\n !routing.teamPreview\n )\n}\n"],"names":["SITE_UNAVAILABLE_RETRY_AFTER_SECONDS","SITE_NOTICE_REQUEST_HEADER","SITE_NOTICE_DEADLINE_MS","isHostInMaintenance","host","Boolean","maintenance","siteUnavailableForRequest","verdict","routing","entryPreview","noticeRequest","preview","teamPreview"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;CAqBC,GAED;;;;;;;;;;;CAWC,GACD,OAAO,MAAMA,uCAAuC,KAAI;AAExD;;;;;;CAMC,GACD,OAAO,MAAMC,6BAA6B,sBAAqB;AAE/D;;;;CAIC,GACD,OAAO,MAAMC,0BAA0B,KAAK;AAE5C;;;;;;CAMC,GACD,OAAO,SAASC,oBACdC,IAAkD;IAElD,OAAOC,QAAQD,wBAAAA,KAAME,WAAW;AAClC;AAuBA;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASC,0BACdC,OAAkD,EAClDC,OAA+B;IAE/B,IAAI,CAACD,WAAWC,QAAQC,YAAY,IAAID,QAAQE,aAAa,EAAE,OAAO;IACtE,OACE,AAACH,CAAAA,QAAQF,WAAW,KAAK,QAAQE,QAAQI,OAAO,KAAK,IAAG,KACxD,CAACH,QAAQI,WAAW;AAExB"}
|
|
@@ -98,6 +98,13 @@ export interface TransferAccessTarget {
|
|
|
98
98
|
scope: TransferLaunchScope;
|
|
99
99
|
/** The site, for a `host` resource or a workspace resource read through one site. */
|
|
100
100
|
hostId?: string | null;
|
|
101
|
+
/**
|
|
102
|
+
* The surface's own verdict on importing into this instance (AGL-4047), for
|
|
103
|
+
* a resource whose server half answers `importAccess`, in place of "Manage
|
|
104
|
+
* data" on the workspace. The plan is still asked. The routes stay the
|
|
105
|
+
* enforcement.
|
|
106
|
+
*/
|
|
107
|
+
importAllowed?: boolean;
|
|
101
108
|
}
|
|
102
109
|
/**
|
|
103
110
|
* An import the person started and left before it wrote anything
|
|
@@ -117,9 +124,18 @@ export interface TransferLauncher {
|
|
|
117
124
|
* permissions have answered. Importing needs "Manage data" (on the named
|
|
118
125
|
* site, for a site's records); exporting needs only access to the
|
|
119
126
|
* records — membership, and reaching the named site — unless the resource
|
|
120
|
-
* declares a `readPermission
|
|
127
|
+
* declares a `readPermission`, or the target carries the resource's own
|
|
128
|
+
* `importAllowed`. The routes stay the enforcement.
|
|
121
129
|
*/
|
|
122
130
|
can(action: TransferAction, target: TransferAccessTarget): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* The permission to name beside a switched-off Import or Export (AGL-4047),
|
|
133
|
+
* once it is known to be a permission that refuses them. `null` when `can`
|
|
134
|
+
* says yes, while its reads are out or failed, and for what no permission
|
|
135
|
+
* decides: the plan, which a surface has its own words for, or a site the
|
|
136
|
+
* person does not reach.
|
|
137
|
+
*/
|
|
138
|
+
refusedPermission?(action: TransferAction, target: TransferAccessTarget): string | null;
|
|
123
139
|
/**
|
|
124
140
|
* The person's own unfinished imports (AGL-3549), newest first: of the
|
|
125
141
|
* target's resource — the exact key, so one dataset's are not another's —
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/transfer-launcher-context.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext, useContext } from 'react'\nimport type { TransferUnfinishedImportSummary } from '../data-transfer/transfer-api'\n\n/**\n * The console shell's import wizard and export dialog, for a plugin to open.\n *\n * The wizard and the dialog are the console's private UI kit, which a\n * published plugin cannot depend on. So the shell hands down a launcher\n * through this context, and a plugin's list or hub opens the wizard for its\n * own resource — the key it declared in `transferResources` — with\n * `useTransferLauncher()?.openImport({ resource, scope })`.\n *\n * Outside the console shell — a spec, a tenant page, a surface mounted by\n * something else — the context holds `null`, and a plugin hides its Import\n * and Export actions: with no shell there is no workspace to move data into.\n *\n * Inside it, `can('import' | 'export', target)` says which of the two this\n * person may use (AGL-3546): a plugin shows Import only when `can('import')`\n * and Export only when `can('export')`. The transfer routes stay the\n * enforcement; `can` answers what they would.\n *\n * Only types and a context: it names no resource, imports nothing from the\n * transfer core, and so costs the barrel nothing past React.\n *\n * A client-only context like the others in `contexts.ts`: it calls\n * `createContext` at module scope, so it is reachable from the full\n * `@aglyn/aglyn` barrel (and this subpath) and never from\n * `@aglyn/aglyn/server` (AGL-405).\n */\n\n/** Where the records live: the workspace, or one of its sites. */\nexport type TransferLaunchScope = 'org' | 'host'\n\n/** Opens the import wizard on one resource. */\nexport interface TransferImportLaunch {\n /**\n * The resource key the plugin declared in `transferResources` — for one\n * declared with `instances`, the key naming the instance\n * (`data.dataset:<datasetId>`).\n */\n resource: string\n scope: TransferLaunchScope\n /** The wizard's title, naming the instance (\"Import into Products\"); \"Import <resource label>\" when absent. */\n title?: string\n /** The site, for a `host` resource. */\n hostId?: string | null\n /** Resume this import instead of starting a new one. */\n jobId?: string | null\n /**\n * What the file is imported as, as the `importMapping` zone's widgets know\n * it (`contacts`); omitted, the mapping step shows no zone.\n */\n mappingZone?: string\n /** Called when the person leaves the wizard from its results with Done. */\n onFinished?(): void\n}\n\n/** Opens the export dialog on one resource. */\nexport interface TransferExportLaunch {\n /** The resource key the plugin declared in `transferResources`, naming the instance for one declared with `instances`. */\n resource: string\n scope: TransferLaunchScope\n /** The dialog's title, naming the instance (\"Export Products\"); \"Export <resource label>\" when absent. */\n title?: string\n /** The site, for a `host` resource. */\n hostId?: string | null\n /** The record ids the person selected in the list, when there is a selection. */\n selection?: readonly string[]\n /** The list's current filter: a name for it, and the value the resource's `readPage` reads. */\n filter?: { label: string; value: unknown }\n /**\n * One of the resource's own presets to open on (`TransferResourcePreset.id`)\n * — a list's \"Export for Pirate Ship\" — instead of the person's last\n * choice. An id the resource does not offer is ignored.\n */\n preset?: string\n}\n\n/** What a person may do with a resource's records. */\nexport type TransferAction = 'import' | 'export'\n\n/** The resource a list asks {@link TransferLauncher.can} about. */\nexport interface TransferAccessTarget {\n /** The resource key, naming the instance for one declared with `instances`. */\n resource: string\n scope: TransferLaunchScope\n /** The site, for a `host` resource or a workspace resource read through one site. */\n hostId?: string | null\n}\n\n/**\n * An import the person started and left before it wrote anything\n * (AGL-3549) — a tab closed mid-wizard — which `openImport({ jobId })`\n * reopens on the step it was left at.\n */\nexport type TransferUnfinishedImport = TransferUnfinishedImportSummary\n\n/** What the shell offers: open the wizard or the dialog, or close whichever is open. */\nexport interface TransferLauncher {\n openImport(launch: TransferImportLaunch): void\n openExport(launch: TransferExportLaunch): void\n close(): void\n /**\n * Whether the person may `action` the target's records (AGL-3546) — the\n * answer the transfer routes give, from the permissions the shell already\n * holds: synchronous, with no request per button, and `false` until those\n * permissions have answered. Importing needs \"Manage data\" (on the named\n * site, for a site's records); exporting needs only access to the\n * records — membership, and reaching the named site — unless the resource\n * declares a `readPermission`. The routes stay the enforcement.\n */\n can(action: TransferAction, target: TransferAccessTarget): boolean\n /**\n * The person's own unfinished imports (AGL-3549), newest first: of the\n * target's resource — the exact key, so one dataset's are not another's —\n * on the target's site when it names one, when a target is given; every\n * one otherwise. Empty\n * until the shell has read them; the first ask starts the read, and the\n * list is read again whenever the wizard closes. Only for a person who may\n * import into the workspace.\n */\n unfinished?(target?: TransferAccessTarget): readonly TransferUnfinishedImport[]\n /**\n * Throws an unfinished import away now — its job, its file and its saved\n * choices — instead of leaving it to expire. Refused for an import that\n * has written anything, which is undone instead.\n */\n discard?(jobId: string): Promise<void>\n}\n\nexport const TransferLauncherContext = createContext<TransferLauncher | null>(null)\nTransferLauncherContext.displayName = 'TransferLauncherContext'\n\n/** The shell's launcher, or `null` outside the console shell. */\nexport function useTransferLauncher(): TransferLauncher | null {\n return useContext(TransferLauncherContext)\n}\n\n"],"names":["createContext","useContext","TransferLauncherContext","displayName","useTransferLauncher"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAO;
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/transfer-launcher-context.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext, useContext } from 'react'\nimport type { TransferUnfinishedImportSummary } from '../data-transfer/transfer-api'\n\n/**\n * The console shell's import wizard and export dialog, for a plugin to open.\n *\n * The wizard and the dialog are the console's private UI kit, which a\n * published plugin cannot depend on. So the shell hands down a launcher\n * through this context, and a plugin's list or hub opens the wizard for its\n * own resource — the key it declared in `transferResources` — with\n * `useTransferLauncher()?.openImport({ resource, scope })`.\n *\n * Outside the console shell — a spec, a tenant page, a surface mounted by\n * something else — the context holds `null`, and a plugin hides its Import\n * and Export actions: with no shell there is no workspace to move data into.\n *\n * Inside it, `can('import' | 'export', target)` says which of the two this\n * person may use (AGL-3546): a plugin shows Import only when `can('import')`\n * and Export only when `can('export')`. The transfer routes stay the\n * enforcement; `can` answers what they would.\n *\n * Only types and a context: it names no resource, imports nothing from the\n * transfer core, and so costs the barrel nothing past React.\n *\n * A client-only context like the others in `contexts.ts`: it calls\n * `createContext` at module scope, so it is reachable from the full\n * `@aglyn/aglyn` barrel (and this subpath) and never from\n * `@aglyn/aglyn/server` (AGL-405).\n */\n\n/** Where the records live: the workspace, or one of its sites. */\nexport type TransferLaunchScope = 'org' | 'host'\n\n/** Opens the import wizard on one resource. */\nexport interface TransferImportLaunch {\n /**\n * The resource key the plugin declared in `transferResources` — for one\n * declared with `instances`, the key naming the instance\n * (`data.dataset:<datasetId>`).\n */\n resource: string\n scope: TransferLaunchScope\n /** The wizard's title, naming the instance (\"Import into Products\"); \"Import <resource label>\" when absent. */\n title?: string\n /** The site, for a `host` resource. */\n hostId?: string | null\n /** Resume this import instead of starting a new one. */\n jobId?: string | null\n /**\n * What the file is imported as, as the `importMapping` zone's widgets know\n * it (`contacts`); omitted, the mapping step shows no zone.\n */\n mappingZone?: string\n /** Called when the person leaves the wizard from its results with Done. */\n onFinished?(): void\n}\n\n/** Opens the export dialog on one resource. */\nexport interface TransferExportLaunch {\n /** The resource key the plugin declared in `transferResources`, naming the instance for one declared with `instances`. */\n resource: string\n scope: TransferLaunchScope\n /** The dialog's title, naming the instance (\"Export Products\"); \"Export <resource label>\" when absent. */\n title?: string\n /** The site, for a `host` resource. */\n hostId?: string | null\n /** The record ids the person selected in the list, when there is a selection. */\n selection?: readonly string[]\n /** The list's current filter: a name for it, and the value the resource's `readPage` reads. */\n filter?: { label: string; value: unknown }\n /**\n * One of the resource's own presets to open on (`TransferResourcePreset.id`)\n * — a list's \"Export for Pirate Ship\" — instead of the person's last\n * choice. An id the resource does not offer is ignored.\n */\n preset?: string\n}\n\n/** What a person may do with a resource's records. */\nexport type TransferAction = 'import' | 'export'\n\n/** The resource a list asks {@link TransferLauncher.can} about. */\nexport interface TransferAccessTarget {\n /** The resource key, naming the instance for one declared with `instances`. */\n resource: string\n scope: TransferLaunchScope\n /** The site, for a `host` resource or a workspace resource read through one site. */\n hostId?: string | null\n /**\n * The surface's own verdict on importing into this instance (AGL-4047), for\n * a resource whose server half answers `importAccess`, in place of \"Manage\n * data\" on the workspace. The plan is still asked. The routes stay the\n * enforcement.\n */\n importAllowed?: boolean\n}\n\n/**\n * An import the person started and left before it wrote anything\n * (AGL-3549) — a tab closed mid-wizard — which `openImport({ jobId })`\n * reopens on the step it was left at.\n */\nexport type TransferUnfinishedImport = TransferUnfinishedImportSummary\n\n/** What the shell offers: open the wizard or the dialog, or close whichever is open. */\nexport interface TransferLauncher {\n openImport(launch: TransferImportLaunch): void\n openExport(launch: TransferExportLaunch): void\n close(): void\n /**\n * Whether the person may `action` the target's records (AGL-3546) — the\n * answer the transfer routes give, from the permissions the shell already\n * holds: synchronous, with no request per button, and `false` until those\n * permissions have answered. Importing needs \"Manage data\" (on the named\n * site, for a site's records); exporting needs only access to the\n * records — membership, and reaching the named site — unless the resource\n * declares a `readPermission`, or the target carries the resource's own\n * `importAllowed`. The routes stay the enforcement.\n */\n can(action: TransferAction, target: TransferAccessTarget): boolean\n /**\n * The permission to name beside a switched-off Import or Export (AGL-4047),\n * once it is known to be a permission that refuses them. `null` when `can`\n * says yes, while its reads are out or failed, and for what no permission\n * decides: the plan, which a surface has its own words for, or a site the\n * person does not reach.\n */\n refusedPermission?(action: TransferAction, target: TransferAccessTarget): string | null\n /**\n * The person's own unfinished imports (AGL-3549), newest first: of the\n * target's resource — the exact key, so one dataset's are not another's —\n * on the target's site when it names one, when a target is given; every\n * one otherwise. Empty\n * until the shell has read them; the first ask starts the read, and the\n * list is read again whenever the wizard closes. Only for a person who may\n * import into the workspace.\n */\n unfinished?(target?: TransferAccessTarget): readonly TransferUnfinishedImport[]\n /**\n * Throws an unfinished import away now — its job, its file and its saved\n * choices — instead of leaving it to expire. Refused for an import that\n * has written anything, which is undone instead.\n */\n discard?(jobId: string): Promise<void>\n}\n\nexport const TransferLauncherContext = createContext<TransferLauncher | null>(null)\nTransferLauncherContext.displayName = 'TransferLauncherContext'\n\n/** The shell's launcher, or `null` outside the console shell. */\nexport function useTransferLauncher(): TransferLauncher | null {\n return useContext(TransferLauncherContext)\n}\n\n"],"names":["createContext","useContext","TransferLauncherContext","displayName","useTransferLauncher"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAO;AAkJjD,OAAO,MAAMC,0BAA0BF,cAAuC,MAAK;AACnFE,wBAAwBC,WAAW,GAAG;AAEtC,+DAA+D,GAC/D,OAAO,SAASC;IACd,OAAOH,WAAWC;AACpB"}
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import type {
|
|
17
|
+
import type { TransferResourceDescriptor } from './resource';
|
|
18
18
|
import { type TransferApiRoute, type TransferPlanRequiredResponse } from './transfer-api';
|
|
19
19
|
/** What a resource declares about who may read and import its records. */
|
|
20
|
-
export type TransferReadDeclaration = Pick<TransferResourceDescriptor, 'readPermission' | 'readableByMembers' | '
|
|
20
|
+
export type TransferReadDeclaration = Pick<TransferResourceDescriptor, 'readPermission' | 'readPermissionOnly' | 'readableByMembers' | 'importPermission'>;
|
|
21
21
|
/** What a resource declares about the plan that moves its records. */
|
|
22
22
|
export type TransferPlanDeclaration = Pick<TransferResourceDescriptor, 'featureFlag' | 'featureFlagExempt'>;
|
|
23
23
|
/** What a member is doing with a resource's records. */
|
|
@@ -40,29 +40,21 @@ export interface TransferMemberAxis {
|
|
|
40
40
|
holds(permission: string): boolean;
|
|
41
41
|
/** Whether the member reaches the named site; `true` when none is named or the member is org-wide. */
|
|
42
42
|
reachesSite: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* The member's role where the records are — on the named site
|
|
45
|
-
* (`hostRoleFor`), or on the workspace (`transferWorkspaceRole`) — for a
|
|
46
|
-
* resource that names `importRoles`; `null` for none.
|
|
47
|
-
*/
|
|
48
|
-
role?: TransferImportRole | null;
|
|
49
43
|
}
|
|
50
44
|
/** Whether a member may `intent` a resource's records: see the block above. */
|
|
51
45
|
export declare function transferAccessAllowed(intent: TransferAccessIntent, descriptor: TransferReadDeclaration | null | undefined, axis: TransferMemberAxis): boolean;
|
|
52
46
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
47
|
+
* The permission to name when a member may not `intent` the records, or `null`
|
|
48
|
+
* when their permissions are not what refuses them: they hold what it takes, or
|
|
49
|
+
* they do not reach the site, which no key decides. Asked in the gate's order.
|
|
56
50
|
*/
|
|
57
|
-
export declare function
|
|
51
|
+
export declare function transferMissingPermission(intent: TransferAccessIntent, descriptor: TransferReadDeclaration | null | undefined, axis: TransferMemberAxis): string | null;
|
|
58
52
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
53
|
+
* The key a member must also hold to `intent` the records, on top of
|
|
54
|
+
* `data.manage` (AGL-4047): the resource's `importPermission` for an import,
|
|
55
|
+
* and nothing for an export or a resource that names none.
|
|
62
56
|
*/
|
|
63
|
-
export declare function
|
|
64
|
-
/** The sentence refusing a member whose role is not among the resource's `importRoles`. */
|
|
65
|
-
export declare function transferImportRoleRefusal(descriptor: Pick<TransferResourceDescriptor, 'importRoles' | 'label' | 'scope'>): string;
|
|
57
|
+
export declare function transferImportPermission(intent: TransferAccessIntent, descriptor: Pick<TransferResourceDescriptor, 'importPermission'> | null | undefined): string | null;
|
|
66
58
|
/**
|
|
67
59
|
* The plan feature a workspace needs to `intent` a resource's records, or
|
|
68
60
|
* `null` when every plan may — no `featureFlag`, or an intent the resource
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
];
|
|
34
34
|
if ((descriptor == null ? void 0 : descriptor.readableByMembers) === true) return [];
|
|
35
35
|
const read = descriptor == null ? void 0 : (_descriptor_readPermission = descriptor.readPermission) == null ? void 0 : _descriptor_readPermission.trim();
|
|
36
|
+
if (read && (descriptor == null ? void 0 : descriptor.readPermissionOnly) === true) return [
|
|
37
|
+
read
|
|
38
|
+
];
|
|
36
39
|
// Whoever may write the records may read them.
|
|
37
40
|
return read && read !== TRANSFER_MANAGE_PERMISSION ? [
|
|
38
41
|
read,
|
|
@@ -42,38 +45,31 @@
|
|
|
42
45
|
];
|
|
43
46
|
}
|
|
44
47
|
/** Whether a member may `intent` a resource's records: see the block above. */ export function transferAccessAllowed(intent, descriptor, axis) {
|
|
45
|
-
var _axis_role;
|
|
46
48
|
if (!axis.reachesSite) return false;
|
|
47
|
-
|
|
49
|
+
const stricter = transferImportPermission(intent, descriptor);
|
|
50
|
+
if (stricter && !axis.holds(stricter)) return false;
|
|
48
51
|
const needed = transferAccessPermissions(intent, descriptor);
|
|
49
52
|
return !needed.length || needed.some((permission)=>axis.holds(permission));
|
|
50
53
|
}
|
|
51
54
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*/ export function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
* The permission to name when a member may not `intent` the records, or `null`
|
|
56
|
+
* when their permissions are not what refuses them: they hold what it takes, or
|
|
57
|
+
* they do not reach the site, which no key decides. Asked in the gate's order.
|
|
58
|
+
*/ export function transferMissingPermission(intent, descriptor, axis) {
|
|
59
|
+
if (!axis.reachesSite) return null;
|
|
60
|
+
const needed = transferAccessPermissions(intent, descriptor);
|
|
61
|
+
if (needed.length && !needed.some((permission)=>axis.holds(permission))) return needed[0];
|
|
62
|
+
const stricter = transferImportPermission(intent, descriptor);
|
|
63
|
+
return stricter && !axis.holds(stricter) ? stricter : null;
|
|
59
64
|
}
|
|
60
65
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*/ export function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/** The sentence refusing a member whose role is not among the resource's `importRoles`. */ export function transferImportRoleRefusal(descriptor) {
|
|
69
|
-
var _descriptor_importRoles;
|
|
70
|
-
const roles = (_descriptor_importRoles = descriptor.importRoles) != null ? _descriptor_importRoles : [];
|
|
71
|
-
const what = /^[A-Z][a-z]/.test(descriptor.label) ? descriptor.label.charAt(0).toLowerCase() + descriptor.label.slice(1) : descriptor.label;
|
|
72
|
-
if (roles.length === 1 && roles[0] === 'admin') {
|
|
73
|
-
return descriptor.scope === 'host' ? `Only the workspace’s owners and admins, and the site’s admins, can import ${what}.` : `Only the workspace’s owners and admins can import ${what}.`;
|
|
74
|
-
}
|
|
75
|
-
const named = roles.map((role)=>role.charAt(0).toUpperCase() + role.slice(1)).join(', ');
|
|
76
|
-
return `Importing ${what} needs one of these roles${descriptor.scope === 'host' ? ' on the site' : ''}: ${named}.`;
|
|
66
|
+
* The key a member must also hold to `intent` the records, on top of
|
|
67
|
+
* `data.manage` (AGL-4047): the resource's `importPermission` for an import,
|
|
68
|
+
* and nothing for an export or a resource that names none.
|
|
69
|
+
*/ export function transferImportPermission(intent, descriptor) {
|
|
70
|
+
var _descriptor_importPermission;
|
|
71
|
+
const key = descriptor == null ? void 0 : (_descriptor_importPermission = descriptor.importPermission) == null ? void 0 : _descriptor_importPermission.trim();
|
|
72
|
+
return intent === 'import' && key ? key : null;
|
|
77
73
|
}
|
|
78
74
|
/**
|
|
79
75
|
* The plan feature a workspace needs to `intent` a resource's records, or
|