@aglyn/aglyn 1.10.0 → 1.12.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 +3 -3
- 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 +2 -0
- package/src/lib/app-utils/docs-help.generated.js.map +1 -1
- package/src/lib/app-utils/docs-index.generated.js +76 -69
- package/src/lib/app-utils/docs-index.generated.js.map +1 -1
- package/src/lib/app-utils/full-use-cost.d.ts +28 -11
- package/src/lib/app-utils/full-use-cost.js +31 -15
- package/src/lib/app-utils/full-use-cost.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/org-role-grants.d.ts +6 -0
- package/src/lib/app-utils/org-role-grants.js +3 -1
- 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/plan-entitlements.d.ts +27 -1
- package/src/lib/app-utils/plan-entitlements.js +44 -3
- package/src/lib/app-utils/plan-entitlements.js.map +1 -1
- 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/upgrade-proposal.d.ts +17 -3
- package/src/lib/app-utils/upgrade-proposal.js +28 -6
- package/src/lib/app-utils/upgrade-proposal.js.map +1 -1
- package/src/lib/foundation/definitions/org-billing.types.d.ts +22 -0
- 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 +1 -1
- 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-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-site-starters.d.ts +7 -0
- package/src/lib/plugin-manager/plugin-site-starters.js.map +1 -1
|
@@ -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":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC,GAED,iDAAiD,GASjD;;;;CAIC,GACD,OAAO,MAAMA,sBAAsB,qBAAoB;AAEvD;;;;;CAKC,GACD,OAAO,MAAMC,gCAAgC,kBAAiB;AAE9D,2DAA2D,GAC3D,OAAO,MAAMC,0BAA0B,0BAAyB;AAEhE,uDAAuD,GACvD,OAAO,MAAMC,6BAA6B,KAAK,KAAK,KAAK,KAAI;AAE7D;;;CAGC,GACD,OAAO,MAAMC,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4CAA4C;IAC5C,IAAI,0BAA0BC,IAAI,CAACF,MAAM,OAAO;IAChD,OAAOA;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASG,kBAAkBC,QAAmC;IAInE,MAAMC,OAAOC,OAAOF,mBAAAA,WAAY,IAAIjC,IAAI;IACxC,OAAOkC,OACH;QAAEE,OAAOF;QAAMhB,MAAM;IAAgD,IACrE;QAAEkB,OAAO;QAAelB,MAAM;IAA+C;AACnF;AAEA,sEAAsE,GACtE,OAAO,MAAMmB,2BACX,qFAAoF;AAEtF,4DAA4D,GAC5D,OAAO,MAAMC,2BACX,sFAAqF"}
|
|
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":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC,GAED,iDAAiD,GASjD;;;;CAIC,GACD,OAAO,MAAMA,sBAAsB,qBAAoB;AAEvD;;;;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SAASO,sBAAsBC,GAA8B;IAClE,IAAI,OAAOA,QAAQ,YAAY,CAACA,KAAK,OAAO;IAC5C,IAAIA,IAAIjB,MAAM,GAAG,MAAM,OAAO;IAC9B,IAAI,CAACiB,IAAIC,UAAU,CAAC,MAAM,OAAO;IACjC,IAAID,IAAIC,UAAU,CAAC,OAAO,OAAO;IACjC,4CAA4C;IAC5C,IAAI,0BAA0BC,IAAI,CAACF,MAAM,OAAO;IAChD,OAAOA;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASG,kBAAkBC,QAAmC;IAInE,MAAMC,OAAOC,OAAOF,mBAAAA,WAAY,IAAIlC,IAAI;IACxC,OAAOmC,OACH;QAAEE,OAAOF;QAAMhB,MAAM;IAAgD,IACrE;QAAEkB,OAAO;QAAelB,MAAM;IAA+C;AACnF;AAEA,sEAAsE,GACtE,OAAO,MAAMmB,2BACX,qFAAoF;AAEtF,0EAA0E,GAC1E,OAAO,MAAMC,+BACX,2FAA0F;AAE5F,4DAA4D,GAC5D,OAAO,MAAMC,2BACX,sFAAqF"}
|
|
@@ -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"}
|
|
@@ -44,6 +44,16 @@ export declare function normalizeUpgradeProposalNote(note: unknown): string | un
|
|
|
44
44
|
* button opens a checkout for an unknown tier is worse than no card.
|
|
45
45
|
*/
|
|
46
46
|
export declare function readUpgradeProposal(org: Partial<AglynOrgBilling> | null | undefined): OrgUpgradeProposal | null;
|
|
47
|
+
/**
|
|
48
|
+
* Whether a subscription on `current.plan`, billed `current.interval`, is
|
|
49
|
+
* what the proposal asks for (AGL-4160): the same plan, and the proposed
|
|
50
|
+
* cadence when one was proposed. A cadence that is not known does not answer
|
|
51
|
+
* a proposal that names one.
|
|
52
|
+
*/
|
|
53
|
+
export declare function upgradeProposalAnsweredBy(proposal: Pick<OrgUpgradeProposal, 'plan' | 'interval'>, current: {
|
|
54
|
+
plan?: unknown;
|
|
55
|
+
interval?: unknown;
|
|
56
|
+
}): boolean;
|
|
47
57
|
/**
|
|
48
58
|
* The bundle half of a proposal (AGL-3956) as it is stored: add-ons through
|
|
49
59
|
* the shared parser and fitted to the plan, an interval only when one was
|
|
@@ -60,13 +70,17 @@ export declare function normalizeUpgradeProposalBundle(plan: OrgPlan, input: {
|
|
|
60
70
|
} | null | undefined): Pick<OrgUpgradeProposal, 'addons' | 'interval' | 'coupon'>;
|
|
61
71
|
/**
|
|
62
72
|
* The proposal the workspace should be shown: the stored one, while no
|
|
63
|
-
* subscription is live
|
|
73
|
+
* subscription is live — or, for one proposed to a workspace that already
|
|
74
|
+
* subscribes (AGL-4160), while the subscription is not yet on the proposed
|
|
75
|
+
* plan and cadence.
|
|
64
76
|
*
|
|
65
77
|
* `billingStatus` is the org document's mirror of the subscription status,
|
|
66
78
|
* readable by every member, so this answers from the document the console
|
|
67
79
|
* already holds. A live subscription means the workspace has bought a plan,
|
|
68
|
-
* which settles the question
|
|
69
|
-
* clears the field then, and this hides it in the
|
|
80
|
+
* which settles the question a proposal made before it asked;
|
|
81
|
+
* `writeOrgBilling`'s caller clears the field then, and this hides it in the
|
|
82
|
+
* meantime. A proposal made to a subscriber asks a different question, a
|
|
83
|
+
* change of plan, which only the change answers.
|
|
70
84
|
*/
|
|
71
85
|
export declare function standingUpgradeProposal(org: Partial<AglynOrgBilling> | null | undefined): OrgUpgradeProposal | null;
|
|
72
86
|
type ProposalBundle = Pick<OrgUpgradeProposal, 'plan'> & Partial<Pick<OrgUpgradeProposal, 'addons' | 'interval' | 'coupon'>>;
|
|
@@ -59,7 +59,18 @@ export function isUpgradeProposalPlan(plan) {
|
|
|
59
59
|
proposedAt: Number.isFinite(raw.proposedAt) ? Number(raw.proposedAt) : 0
|
|
60
60
|
}, note ? {
|
|
61
61
|
note
|
|
62
|
-
} : {}, bundle
|
|
62
|
+
} : {}, bundle, raw.forSubscriber === true ? {
|
|
63
|
+
forSubscriber: true
|
|
64
|
+
} : {});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether a subscription on `current.plan`, billed `current.interval`, is
|
|
68
|
+
* what the proposal asks for (AGL-4160): the same plan, and the proposed
|
|
69
|
+
* cadence when one was proposed. A cadence that is not known does not answer
|
|
70
|
+
* a proposal that names one.
|
|
71
|
+
*/ export function upgradeProposalAnsweredBy(proposal, current) {
|
|
72
|
+
if (proposal.plan !== current.plan) return false;
|
|
73
|
+
return !proposal.interval || proposal.interval === current.interval;
|
|
63
74
|
}
|
|
64
75
|
/**
|
|
65
76
|
* The bundle half of a proposal (AGL-3956) as it is stored: add-ons through
|
|
@@ -84,16 +95,27 @@ export function isUpgradeProposalPlan(plan) {
|
|
|
84
95
|
}
|
|
85
96
|
/**
|
|
86
97
|
* The proposal the workspace should be shown: the stored one, while no
|
|
87
|
-
* subscription is live
|
|
98
|
+
* subscription is live — or, for one proposed to a workspace that already
|
|
99
|
+
* subscribes (AGL-4160), while the subscription is not yet on the proposed
|
|
100
|
+
* plan and cadence.
|
|
88
101
|
*
|
|
89
102
|
* `billingStatus` is the org document's mirror of the subscription status,
|
|
90
103
|
* readable by every member, so this answers from the document the console
|
|
91
104
|
* already holds. A live subscription means the workspace has bought a plan,
|
|
92
|
-
* which settles the question
|
|
93
|
-
* clears the field then, and this hides it in the
|
|
105
|
+
* which settles the question a proposal made before it asked;
|
|
106
|
+
* `writeOrgBilling`'s caller clears the field then, and this hides it in the
|
|
107
|
+
* meantime. A proposal made to a subscriber asks a different question, a
|
|
108
|
+
* change of plan, which only the change answers.
|
|
94
109
|
*/ export function standingUpgradeProposal(org) {
|
|
95
|
-
|
|
96
|
-
|
|
110
|
+
var _org_subscription;
|
|
111
|
+
const proposal = readUpgradeProposal(org);
|
|
112
|
+
if (!isLiveSubscriptionStatus(org == null ? void 0 : org.billingStatus)) return proposal;
|
|
113
|
+
if (!(proposal == null ? void 0 : proposal.forSubscriber)) return null;
|
|
114
|
+
const current = {
|
|
115
|
+
plan: org == null ? void 0 : org.plan,
|
|
116
|
+
interval: org == null ? void 0 : (_org_subscription = org.subscription) == null ? void 0 : _org_subscription.interval
|
|
117
|
+
};
|
|
118
|
+
return upgradeProposalAnsweredBy(proposal, current) ? null : proposal;
|
|
97
119
|
}
|
|
98
120
|
/**
|
|
99
121
|
* The intent a proposal carries into Billing: the plan, and the add-ons,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/upgrade-proposal.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 platform team's request that a workspace move to a paid plan\n * (AGL-3466), read in one place.\n *\n * A workspace staff build for a client is handed over first and sold second:\n * the client joins, looks around on whatever the workspace already has, and\n * only then is asked to upgrade. Staff record that ask as\n * `orgs/{orgId}.upgradeProposal`; this module decides whether it still\n * stands, what it may name, and where the button under it goes.\n */\n\nimport type {\n AglynOrgBilling,\n OrgPlan,\n OrgUpgradeProposal,\n} from '../foundation/definitions/org-billing.types'\nimport {\n describeBundle,\n fitBundleAddonsToPlan,\n hasBundleAddons,\n normalizeBundleCoupon,\n parseBundleAddons,\n type BundleAddons,\n} from './bundle-intent'\nimport {\n onboardingDestination,\n type OnboardingPlanIntent,\n} from './onboarding-deep-link'\nimport { isLiveSubscriptionStatus } from './org-billing-doc'\nimport { PLAN_LABELS, SELF_SERVE_PLANS } from './plan-entitlements'\n\n/** The longest staff note a proposal carries. */\nexport const UPGRADE_PROPOSAL_NOTE_MAX = 500\n\n/**\n * The plans staff may propose: every tier a customer can buy themselves,\n * less Free, which is not a purchase. Enterprise is quoted per deal, so it\n * is never proposed through a checkout link.\n */\nexport const UPGRADE_PROPOSAL_PLANS: readonly OrgPlan[] = SELF_SERVE_PLANS.filter(\n (plan) => plan !== 'free',\n)\n\nexport function isUpgradeProposalPlan(plan: unknown): plan is OrgPlan {\n return (\n typeof plan === 'string' &&\n (UPGRADE_PROPOSAL_PLANS as readonly string[]).includes(plan)\n )\n}\n\n/** A staff note as it is stored: trimmed, bounded, and absent when blank. */\nexport function normalizeUpgradeProposalNote(note: unknown): string | undefined {\n if (typeof note !== 'string') return undefined\n const trimmed = note.trim().slice(0, UPGRADE_PROPOSAL_NOTE_MAX)\n return trimmed || undefined\n}\n\n/**\n * The stored proposal, narrowed, or null when there is none worth showing.\n *\n * A proposal naming a plan this build cannot sell reads as none: a card whose\n * button opens a checkout for an unknown tier is worse than no card.\n */\nexport function readUpgradeProposal(\n org: Partial<AglynOrgBilling> | null | undefined,\n): OrgUpgradeProposal | null {\n const raw = org?.upgradeProposal as Partial<OrgUpgradeProposal> | null | undefined\n if (!raw || typeof raw !== 'object' || !isUpgradeProposalPlan(raw.plan)) {\n return null\n }\n const note = normalizeUpgradeProposalNote(raw.note)\n const bundle = normalizeUpgradeProposalBundle(raw.plan, raw)\n return {\n plan: raw.plan,\n proposedBy: typeof raw.proposedBy === 'string' ? raw.proposedBy : '',\n proposedAt: Number.isFinite(raw.proposedAt) ? Number(raw.proposedAt) : 0,\n ...(note ? { note } : {}),\n ...bundle,\n }\n}\n\n/**\n * The bundle half of a proposal (AGL-3956) as it is stored: add-ons through\n * the shared parser and fitted to the plan, an interval only when one was\n * chosen, and a coupon only when it reads as a code. Aglyn AI is a number of\n * credit blocks like any quantity add-on (AGL-4144); a retired tier name is\n * dropped by the parser, never stored. Whatever cannot be honored is left out\n * rather than stored, so Billing is never asked to preselect something the\n * checkout would refuse.\n */\nexport function normalizeUpgradeProposalBundle(\n plan: OrgPlan,\n input:\n | { addons?: unknown; interval?: unknown; coupon?: unknown }\n | null\n | undefined,\n): Pick<OrgUpgradeProposal, 'addons' | 'interval' | 'coupon'> {\n const parsed = parseBundleAddons(input?.addons)\n const addons: BundleAddons = fitBundleAddonsToPlan(parsed.addons, plan).addons\n const interval =\n input?.interval === 'year' || input?.interval === 'month' ? input.interval : undefined\n const coupon = normalizeBundleCoupon(input?.coupon)\n return {\n ...(hasBundleAddons(addons) ? { addons } : {}),\n ...(interval ? { interval } : {}),\n ...(coupon ? { coupon } : {}),\n }\n}\n\n/**\n * The proposal the workspace should be shown: the stored one, while no\n * subscription is live.\n *\n * `billingStatus` is the org document's mirror of the subscription status,\n * readable by every member, so this answers from the document the console\n * already holds. A live subscription means the workspace has bought a plan,\n * which settles the question the proposal asked; `writeOrgBilling`'s caller\n * clears the field then, and this hides it in the meantime.\n */\nexport function standingUpgradeProposal(\n org: Partial<AglynOrgBilling> | null | undefined,\n): OrgUpgradeProposal | null {\n if (isLiveSubscriptionStatus(org?.billingStatus)) return null\n return readUpgradeProposal(org)\n}\n\ntype ProposalBundle = Pick<OrgUpgradeProposal, 'plan'> &\n Partial<Pick<OrgUpgradeProposal, 'addons' | 'interval' | 'coupon'>>\n\n/**\n * The intent a proposal carries into Billing: the plan, and the add-ons,\n * cadence and coupon staff proposed with it (AGL-3956) — the same fields the\n * bundle checkout link carries (AGL-3955), so the proposal card and the link\n * land on the same preselected page.\n */\nexport function upgradeProposalIntent(proposal: ProposalBundle): OnboardingPlanIntent {\n const addons = fitBundleAddonsToPlan(proposal.addons, proposal.plan).addons\n const coupon = normalizeBundleCoupon(proposal.coupon)\n const interval = proposal.interval === 'year' || proposal.interval === 'month'\n ? proposal.interval\n : null\n return {\n plan: proposal.plan,\n interval: interval ?? 'month',\n // A proposal with no cadence names a plan, not a cadence, so the page\n // keeps whatever its toggle says rather than being told \"monthly\".\n intervalStated: interval !== null,\n contactSales: false,\n ...(addons.aiAddon ? { ai: true as const } : {}),\n ...(hasBundleAddons(addons) ? { addons } : {}),\n ...(coupon ? { coupon } : {}),\n }\n}\n\n/**\n * The bundle Billing prices (AGL-4154): the link's, else the standing\n * proposal's.\n *\n * A link says what the visitor came to buy, so it wins. Without one, an owner\n * who opened Billing from the menu still meets the plan, cadence, add-ons and\n * code staff proposed, and the code is tried on the first quote as the link\n * would try it, so a coupon on a hand-off never has to be typed.\n */\nexport function billingPlanIntent(\n linkIntent: OnboardingPlanIntent | null,\n proposal: ProposalBundle | null | undefined,\n): OnboardingPlanIntent | null {\n if (linkIntent) return linkIntent\n return proposal ? upgradeProposalIntent(proposal) : null\n}\n\n/** Where the proposal's button goes: Billing, with the bundle preselected. */\nexport function upgradeProposalDestination(\n orgSlug: string,\n proposal: ProposalBundle,\n): string {\n return onboardingDestination(orgSlug, upgradeProposalIntent(proposal))\n}\n\n/** \"Starter with Site Care, billed yearly, code BOOTH25\". */\nexport function upgradeProposalSummary(\n proposal: ProposalBundle,\n options: { brand?: string } = {},\n): string {\n return describeBundle(\n {\n plan: proposal.plan,\n addons: proposal.addons ?? null,\n interval: proposal.interval ?? null,\n coupon: proposal.coupon ?? null,\n },\n options,\n )\n}\n\n/** \"Acme's Aglyn team proposed the Starter plan\". */\nexport function upgradeProposalHeadline(\n proposal: Pick<OrgUpgradeProposal, 'plan'>,\n options: { orgName?: string | null; productName: string },\n): string {\n const workspace = options.orgName?.trim()\n const team = workspace\n ? `${workspace}'s ${options.productName} team`\n : `Your ${options.productName} team`\n return `${team} proposed the ${PLAN_LABELS[proposal.plan]} plan`\n}\n"],"names":["describeBundle","fitBundleAddonsToPlan","hasBundleAddons","normalizeBundleCoupon","parseBundleAddons","onboardingDestination","isLiveSubscriptionStatus","PLAN_LABELS","SELF_SERVE_PLANS","UPGRADE_PROPOSAL_NOTE_MAX","UPGRADE_PROPOSAL_PLANS","filter","plan","isUpgradeProposalPlan","includes","normalizeUpgradeProposalNote","note","undefined","trimmed","trim","slice","readUpgradeProposal","org","raw","upgradeProposal","bundle","normalizeUpgradeProposalBundle","proposedBy","proposedAt","Number","isFinite","input","parsed","addons","interval","coupon","standingUpgradeProposal","billingStatus","upgradeProposalIntent","proposal","intervalStated","contactSales","aiAddon","ai","billingPlanIntent","linkIntent","upgradeProposalDestination","orgSlug","upgradeProposalSummary","options","upgradePro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;;;;;;;;CAQC,GACD,OAAO,SAASS,kBACdC,UAAuC,EACvCN,QAA2C;IAE3C,IAAIM,YAAY,OAAOA;IACvB,OAAON,WAAWD,sBAAsBC,YAAY;AACtD;AAEA,4EAA4E,GAC5E,OAAO,SAASO,2BACdC,OAAe,EACfR,QAAwB;IAExB,OAAOlC,sBAAsB0C,SAAST,sBAAsBC;AAC9D;AAEA,2DAA2D,GAC3D,OAAO,SAASS,uBACdT,QAAwB,EACxBU,UAA8B,CAAC,CAAC;QAKpBV,kBACEA,oBACFA;IALZ,OAAOvC,eACL;QACEY,MAAM2B,SAAS3B,IAAI;QACnBqB,MAAM,GAAEM,mBAAAA,SAASN,MAAM,YAAfM,mBAAmB;QAC3BL,QAAQ,GAAEK,qBAAAA,SAASL,QAAQ,YAAjBK,qBAAqB;QAC/BJ,MAAM,GAAEI,mBAAAA,SAASJ,MAAM,YAAfI,mBAAmB;IAC7B,GACAU;AAEJ;AAEA,mDAAmD,GACnD,OAAO,SAASC,wBACdX,QAA0C,EAC1CU,OAAyD;QAEvCA;IAAlB,MAAME,aAAYF,mBAAAA,QAAQG,OAAO,qBAAfH,iBAAiB9B,IAAI;IACvC,MAAMkC,OAAOF,YACT,GAAGA,UAAU,GAAG,EAAEF,QAAQK,WAAW,CAAC,KAAK,CAAC,GAC5C,CAAC,KAAK,EAAEL,QAAQK,WAAW,CAAC,KAAK,CAAC;IACtC,OAAO,GAAGD,KAAK,cAAc,EAAE9C,WAAW,CAACgC,SAAS3B,IAAI,CAAC,CAAC,KAAK,CAAC;AAClE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/upgrade-proposal.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 platform team's request that a workspace move to a paid plan\n * (AGL-3466), read in one place.\n *\n * A workspace staff build for a client is handed over first and sold second:\n * the client joins, looks around on whatever the workspace already has, and\n * only then is asked to upgrade. Staff record that ask as\n * `orgs/{orgId}.upgradeProposal`; this module decides whether it still\n * stands, what it may name, and where the button under it goes.\n */\n\nimport type {\n AglynOrgBilling,\n OrgPlan,\n OrgUpgradeProposal,\n} from '../foundation/definitions/org-billing.types'\nimport {\n describeBundle,\n fitBundleAddonsToPlan,\n hasBundleAddons,\n normalizeBundleCoupon,\n parseBundleAddons,\n type BundleAddons,\n} from './bundle-intent'\nimport {\n onboardingDestination,\n type OnboardingPlanIntent,\n} from './onboarding-deep-link'\nimport { isLiveSubscriptionStatus } from './org-billing-doc'\nimport { PLAN_LABELS, SELF_SERVE_PLANS } from './plan-entitlements'\n\n/** The longest staff note a proposal carries. */\nexport const UPGRADE_PROPOSAL_NOTE_MAX = 500\n\n/**\n * The plans staff may propose: every tier a customer can buy themselves,\n * less Free, which is not a purchase. Enterprise is quoted per deal, so it\n * is never proposed through a checkout link.\n */\nexport const UPGRADE_PROPOSAL_PLANS: readonly OrgPlan[] = SELF_SERVE_PLANS.filter(\n (plan) => plan !== 'free',\n)\n\nexport function isUpgradeProposalPlan(plan: unknown): plan is OrgPlan {\n return (\n typeof plan === 'string' &&\n (UPGRADE_PROPOSAL_PLANS as readonly string[]).includes(plan)\n )\n}\n\n/** A staff note as it is stored: trimmed, bounded, and absent when blank. */\nexport function normalizeUpgradeProposalNote(note: unknown): string | undefined {\n if (typeof note !== 'string') return undefined\n const trimmed = note.trim().slice(0, UPGRADE_PROPOSAL_NOTE_MAX)\n return trimmed || undefined\n}\n\n/**\n * The stored proposal, narrowed, or null when there is none worth showing.\n *\n * A proposal naming a plan this build cannot sell reads as none: a card whose\n * button opens a checkout for an unknown tier is worse than no card.\n */\nexport function readUpgradeProposal(\n org: Partial<AglynOrgBilling> | null | undefined,\n): OrgUpgradeProposal | null {\n const raw = org?.upgradeProposal as Partial<OrgUpgradeProposal> | null | undefined\n if (!raw || typeof raw !== 'object' || !isUpgradeProposalPlan(raw.plan)) {\n return null\n }\n const note = normalizeUpgradeProposalNote(raw.note)\n const bundle = normalizeUpgradeProposalBundle(raw.plan, raw)\n return {\n plan: raw.plan,\n proposedBy: typeof raw.proposedBy === 'string' ? raw.proposedBy : '',\n proposedAt: Number.isFinite(raw.proposedAt) ? Number(raw.proposedAt) : 0,\n ...(note ? { note } : {}),\n ...bundle,\n ...(raw.forSubscriber === true ? { forSubscriber: true } : {}),\n }\n}\n\n/**\n * Whether a subscription on `current.plan`, billed `current.interval`, is\n * what the proposal asks for (AGL-4160): the same plan, and the proposed\n * cadence when one was proposed. A cadence that is not known does not answer\n * a proposal that names one.\n */\nexport function upgradeProposalAnsweredBy(\n proposal: Pick<OrgUpgradeProposal, 'plan' | 'interval'>,\n current: { plan?: unknown; interval?: unknown },\n): boolean {\n if (proposal.plan !== current.plan) return false\n return !proposal.interval || proposal.interval === current.interval\n}\n\n/**\n * The bundle half of a proposal (AGL-3956) as it is stored: add-ons through\n * the shared parser and fitted to the plan, an interval only when one was\n * chosen, and a coupon only when it reads as a code. Aglyn AI is a number of\n * credit blocks like any quantity add-on (AGL-4144); a retired tier name is\n * dropped by the parser, never stored. Whatever cannot be honored is left out\n * rather than stored, so Billing is never asked to preselect something the\n * checkout would refuse.\n */\nexport function normalizeUpgradeProposalBundle(\n plan: OrgPlan,\n input:\n | { addons?: unknown; interval?: unknown; coupon?: unknown }\n | null\n | undefined,\n): Pick<OrgUpgradeProposal, 'addons' | 'interval' | 'coupon'> {\n const parsed = parseBundleAddons(input?.addons)\n const addons: BundleAddons = fitBundleAddonsToPlan(parsed.addons, plan).addons\n const interval =\n input?.interval === 'year' || input?.interval === 'month' ? input.interval : undefined\n const coupon = normalizeBundleCoupon(input?.coupon)\n return {\n ...(hasBundleAddons(addons) ? { addons } : {}),\n ...(interval ? { interval } : {}),\n ...(coupon ? { coupon } : {}),\n }\n}\n\n/**\n * The proposal the workspace should be shown: the stored one, while no\n * subscription is live — or, for one proposed to a workspace that already\n * subscribes (AGL-4160), while the subscription is not yet on the proposed\n * plan and cadence.\n *\n * `billingStatus` is the org document's mirror of the subscription status,\n * readable by every member, so this answers from the document the console\n * already holds. A live subscription means the workspace has bought a plan,\n * which settles the question a proposal made before it asked;\n * `writeOrgBilling`'s caller clears the field then, and this hides it in the\n * meantime. A proposal made to a subscriber asks a different question, a\n * change of plan, which only the change answers.\n */\nexport function standingUpgradeProposal(\n org: Partial<AglynOrgBilling> | null | undefined,\n): OrgUpgradeProposal | null {\n const proposal = readUpgradeProposal(org)\n if (!isLiveSubscriptionStatus(org?.billingStatus)) return proposal\n if (!proposal?.forSubscriber) return null\n const current = {\n plan: org?.plan,\n interval: (org?.subscription as { interval?: unknown } | undefined)?.interval,\n }\n return upgradeProposalAnsweredBy(proposal, current) ? null : proposal\n}\n\ntype ProposalBundle = Pick<OrgUpgradeProposal, 'plan'> &\n Partial<Pick<OrgUpgradeProposal, 'addons' | 'interval' | 'coupon'>>\n\n/**\n * The intent a proposal carries into Billing: the plan, and the add-ons,\n * cadence and coupon staff proposed with it (AGL-3956) — the same fields the\n * bundle checkout link carries (AGL-3955), so the proposal card and the link\n * land on the same preselected page.\n */\nexport function upgradeProposalIntent(proposal: ProposalBundle): OnboardingPlanIntent {\n const addons = fitBundleAddonsToPlan(proposal.addons, proposal.plan).addons\n const coupon = normalizeBundleCoupon(proposal.coupon)\n const interval = proposal.interval === 'year' || proposal.interval === 'month'\n ? proposal.interval\n : null\n return {\n plan: proposal.plan,\n interval: interval ?? 'month',\n // A proposal with no cadence names a plan, not a cadence, so the page\n // keeps whatever its toggle says rather than being told \"monthly\".\n intervalStated: interval !== null,\n contactSales: false,\n ...(addons.aiAddon ? { ai: true as const } : {}),\n ...(hasBundleAddons(addons) ? { addons } : {}),\n ...(coupon ? { coupon } : {}),\n }\n}\n\n/**\n * The bundle Billing prices (AGL-4154): the link's, else the standing\n * proposal's.\n *\n * A link says what the visitor came to buy, so it wins. Without one, an owner\n * who opened Billing from the menu still meets the plan, cadence, add-ons and\n * code staff proposed, and the code is tried on the first quote as the link\n * would try it, so a coupon on a hand-off never has to be typed.\n */\nexport function billingPlanIntent(\n linkIntent: OnboardingPlanIntent | null,\n proposal: ProposalBundle | null | undefined,\n): OnboardingPlanIntent | null {\n if (linkIntent) return linkIntent\n return proposal ? upgradeProposalIntent(proposal) : null\n}\n\n/** Where the proposal's button goes: Billing, with the bundle preselected. */\nexport function upgradeProposalDestination(\n orgSlug: string,\n proposal: ProposalBundle,\n): string {\n return onboardingDestination(orgSlug, upgradeProposalIntent(proposal))\n}\n\n/** \"Starter with Site Care, billed yearly, code BOOTH25\". */\nexport function upgradeProposalSummary(\n proposal: ProposalBundle,\n options: { brand?: string } = {},\n): string {\n return describeBundle(\n {\n plan: proposal.plan,\n addons: proposal.addons ?? null,\n interval: proposal.interval ?? null,\n coupon: proposal.coupon ?? null,\n },\n options,\n )\n}\n\n/** \"Acme's Aglyn team proposed the Starter plan\". */\nexport function upgradeProposalHeadline(\n proposal: Pick<OrgUpgradeProposal, 'plan'>,\n options: { orgName?: string | null; productName: string },\n): string {\n const workspace = options.orgName?.trim()\n const team = workspace\n ? `${workspace}'s ${options.productName} team`\n : `Your ${options.productName} team`\n return `${team} proposed the ${PLAN_LABELS[proposal.plan]} plan`\n}\n"],"names":["describeBundle","fitBundleAddonsToPlan","hasBundleAddons","normalizeBundleCoupon","parseBundleAddons","onboardingDestination","isLiveSubscriptionStatus","PLAN_LABELS","SELF_SERVE_PLANS","UPGRADE_PROPOSAL_NOTE_MAX","UPGRADE_PROPOSAL_PLANS","filter","plan","isUpgradeProposalPlan","includes","normalizeUpgradeProposalNote","note","undefined","trimmed","trim","slice","readUpgradeProposal","org","raw","upgradeProposal","bundle","normalizeUpgradeProposalBundle","proposedBy","proposedAt","Number","isFinite","forSubscriber","upgradeProposalAnsweredBy","proposal","current","interval","input","parsed","addons","coupon","standingUpgradeProposal","billingStatus","subscription","upgradeProposalIntent","intervalStated","contactSales","aiAddon","ai","billingPlanIntent","linkIntent","upgradeProposalDestination","orgSlug","upgradeProposalSummary","options","upgradeProposalHeadline","workspace","orgName","team","productName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;CASC;AAOD,SACEA,cAAc,EACdC,qBAAqB,EACrBC,eAAe,EACfC,qBAAqB,EACrBC,iBAAiB,QAEZ,qBAAiB;AACxB,SACEC,qBAAqB,QAEhB,4BAAwB;AAC/B,SAASC,wBAAwB,QAAQ,uBAAmB;AAC5D,SAASC,WAAW,EAAEC,gBAAgB,QAAQ,yBAAqB;AAEnE,+CAA+C,GAC/C,OAAO,MAAMC,4BAA4B,IAAG;AAE5C;;;;CAIC,GACD,OAAO,MAAMC,yBAA6CF,iBAAiBG,MAAM,CAC/E,CAACC,OAASA,SAAS,QACpB;AAED,OAAO,SAASC,sBAAsBD,IAAa;IACjD,OACE,OAAOA,SAAS,YAChB,AAACF,uBAA6CI,QAAQ,CAACF;AAE3D;AAEA,2EAA2E,GAC3E,OAAO,SAASG,6BAA6BC,IAAa;IACxD,IAAI,OAAOA,SAAS,UAAU,OAAOC;IACrC,MAAMC,UAAUF,KAAKG,IAAI,GAAGC,KAAK,CAAC,GAAGX;IACrC,OAAOS,WAAWD;AACpB;AAEA;;;;;CAKC,GACD,OAAO,SAASI,oBACdC,GAAgD;IAEhD,MAAMC,MAAMD,uBAAAA,IAAKE,eAAe;IAChC,IAAI,CAACD,OAAO,OAAOA,QAAQ,YAAY,CAACV,sBAAsBU,IAAIX,IAAI,GAAG;QACvE,OAAO;IACT;IACA,MAAMI,OAAOD,6BAA6BQ,IAAIP,IAAI;IAClD,MAAMS,SAASC,+BAA+BH,IAAIX,IAAI,EAAEW;IACxD,OAAO;QACLX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,GAAEF,qBAAAA,SAASE,QAAQ,YAAjBF,qBAAqB;QAC/BM,MAAM,GAAEN,mBAAAA,SAASM,MAAM,YAAfN,mBAAmB;IAC7B,GACAoB;AAEJ;AAEA,mDAAmD,GACnD,OAAO,SAASC,wBACdrB,QAA0C,EAC1CoB,OAAyD;QAEvCA;IAAlB,MAAME,aAAYF,mBAAAA,QAAQG,OAAO,qBAAfH,iBAAiBlC,IAAI;IACvC,MAAMsC,OAAOF,YACT,GAAGA,UAAU,GAAG,EAAEF,QAAQK,WAAW,CAAC,KAAK,CAAC,GAC5C,CAAC,KAAK,EAAEL,QAAQK,WAAW,CAAC,KAAK,CAAC;IACtC,OAAO,GAAGD,KAAK,cAAc,EAAElD,WAAW,CAAC0B,SAASrB,IAAI,CAAC,CAAC,KAAK,CAAC;AAClE"}
|
|
@@ -912,6 +912,20 @@ export interface OrgDiscount {
|
|
|
912
912
|
/** Free-text why (the enterprise deal, the promotion) — staff-only. */
|
|
913
913
|
reason?: string;
|
|
914
914
|
appliedAt: ITimestamp;
|
|
915
|
+
/**
|
|
916
|
+
* The coupon takes its discount off the plan's BASE PRICE only (AGL-4161):
|
|
917
|
+
* Stripe `applies_to.products` names plan products (AGL-4159), so add-ons
|
|
918
|
+
* and usage past the plan's limits bill in full. Absent or false is a
|
|
919
|
+
* whole-subscription discount — every mirror written before this field
|
|
920
|
+
* reads that way, which is what those coupons were.
|
|
921
|
+
*/
|
|
922
|
+
basePriceOnly?: boolean;
|
|
923
|
+
/**
|
|
924
|
+
* The plans whose base price a `basePriceOnly` coupon reaches, read from
|
|
925
|
+
* the deployment's plan prices when the mirror was written. Absent when
|
|
926
|
+
* they could not be read; empty when the coupon names no plan sold now.
|
|
927
|
+
*/
|
|
928
|
+
appliesToPlans?: OrgPlan[];
|
|
915
929
|
}
|
|
916
930
|
export interface OrgSubscription {
|
|
917
931
|
status?: 'active' | 'trialing' | 'past_due' | 'canceled' | 'incomplete' | 'unpaid';
|
|
@@ -1264,6 +1278,14 @@ export interface OrgUpgradeProposal {
|
|
|
1264
1278
|
interval?: 'month' | 'year';
|
|
1265
1279
|
/** A promotion code minted on the staff Coupons page, applied at checkout. */
|
|
1266
1280
|
coupon?: string;
|
|
1281
|
+
/**
|
|
1282
|
+
* Proposed to a workspace that already subscribes (AGL-4160): a change of
|
|
1283
|
+
* plan or billing cadence, with its code applied to the switch. It stands
|
|
1284
|
+
* until the subscription moves to the proposed plan and cadence, rather
|
|
1285
|
+
* than being settled by a subscription being live, which is what settles
|
|
1286
|
+
* a proposal made before the workspace bought anything.
|
|
1287
|
+
*/
|
|
1288
|
+
forSubscriber?: boolean;
|
|
1267
1289
|
}
|
|
1268
1290
|
/**
|
|
1269
1291
|
* What the CRM lets an organization decide for every site at once
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
* reason is mandatory and is the whole value of the map: it records that
|
|
59
59
|
* someone decided, rather than that someone forgot.
|
|
60
60
|
*/ export const ORG_CLIENT_WRITABLE_FIELDS = {
|
|
61
|
-
name: 'The workspace name. Deliberately writable by
|
|
61
|
+
name: 'The workspace name. Deliberately writable by a member holding ' + '"Organization settings" (`org.settings`, owners and admins by default) — ' + 'the rules admit the rename branch and `firestore-rules.test.mjs` asserts it still ' + 'succeeds. Cosmetic: no entitlement, price or routing decision reads it. ' + '(The console renames through /api/orgs/settings anyway, because the name ' + 'is denormalized onto every membership row and the fan-out is a server ' + 'job — but the client write is allowed and must stay allowed.)',
|
|
62
62
|
description: 'Free-text workspace blurb. Nothing resolves, gates or bills on it, and ' + 'no server route owns it.',
|
|
63
63
|
createdAt: 'Creation stamp seeded by `createOrganization`. Nothing gates on it; the ' + 'staff org list only displays it. Denying it would buy nothing and would ' + 'break the merge-writes below, which stamp the pair together.',
|
|
64
64
|
updatedAt: 'Last-write stamp. Every client write that IS allowed sets it in the same ' + '`setDoc(..., { merge: true })` — the staff suspension, erasure-request ' + 'and plan-override cards all do — so denying it would deny those writes.',
|
|
65
|
-
crm: 'The CRM settings map (AGL-2613): `autoCreateCompanies`, the per-site ' + 'default owner, the assignment rules and the round-robin pool ' + '(AGL-2618), and whatever the CRM → Settings section adds beside them. ' + 'Deliberately writable by
|
|
65
|
+
crm: 'The CRM settings map (AGL-2613): `autoCreateCompanies`, the per-site ' + 'default owner, the assignment rules and the round-robin pool ' + '(AGL-2618), and whatever the CRM → Settings section adds beside them. ' + 'Deliberately writable by a member holding "Change CRM settings" ' + '(`crm.settings`, owners and admins by default, AGL-4047) — the section writes it ' + 'client-direct by dotted path. No entitlement, price, routing decision ' + 'or staff judgement reads it; its readers are the contact capture door ' + 'deciding whether to mint a company record from an email domain and ' + 'whom to hand a new record to, which are choices about the org\'s own ' + "data that the org's managers are the right people to make. The pool's " + 'pointer (`crm.roundRobin.lastAssignedUid`) is advanced by the server ' + 'inside the assigning transaction; a client that moved it would only ' + 'change who is next, never what anybody may see.'
|
|
66
66
|
};
|
|
67
67
|
/**
|
|
68
68
|
* Fields declared on `AglynOrgBilling` that are NOT stored on the document,
|