@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
|
@@ -320,3 +320,21 @@ export declare function pluginContactSource(source: string): ResolvedPluginConta
|
|
|
320
320
|
* the console's browser and on both servers before a page renders.
|
|
321
321
|
*/
|
|
322
322
|
export declare function labelContactSource(source: unknown, fallback?: string): string;
|
|
323
|
+
/**
|
|
324
|
+
* Whether a word is a source this process can name: one of the core's, or a
|
|
325
|
+
* door a plugin declared. What keeps a saved filter from carrying a word
|
|
326
|
+
* nothing answers to, without closing the list against a plugin's door.
|
|
327
|
+
*/
|
|
328
|
+
export declare function isKnownContactSource(source: unknown): boolean;
|
|
329
|
+
/** One source a filter offers: the stored word, and how it reads. */
|
|
330
|
+
export interface PluginContactSourceOption {
|
|
331
|
+
value: string;
|
|
332
|
+
label: string;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Every source a filter can offer: the core's, then each door a plugin
|
|
336
|
+
* declared, each reading as {@link labelContactSource} reads it, so a filter's
|
|
337
|
+
* choice and a row's chip cannot disagree. A plugin that declares a core word
|
|
338
|
+
* adds no second entry and does not change its label.
|
|
339
|
+
*/
|
|
340
|
+
export declare function listContactSourceOptions(): PluginContactSourceOption[];
|
|
@@ -108,5 +108,31 @@ export const PLUGIN_CONTACT_SOURCES = definePluginServiceContract('core.contact-
|
|
|
108
108
|
}
|
|
109
109
|
return ((_pluginContactSource = pluginContactSource(word)) == null ? void 0 : _pluginContactSource.label) || (fallback != null ? fallback : word);
|
|
110
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Whether a word is a source this process can name: one of the core's, or a
|
|
113
|
+
* door a plugin declared. What keeps a saved filter from carrying a word
|
|
114
|
+
* nothing answers to, without closing the list against a plugin's door.
|
|
115
|
+
*/ export function isKnownContactSource(source) {
|
|
116
|
+
const word = typeof source === 'string' ? source.trim() : '';
|
|
117
|
+
if (!word) return false;
|
|
118
|
+
return Object.hasOwn(CONTACT_SOURCE_LABELS, word) || pluginContactSource(word) !== null;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Every source a filter can offer: the core's, then each door a plugin
|
|
122
|
+
* declared, each reading as {@link labelContactSource} reads it, so a filter's
|
|
123
|
+
* choice and a row's chip cannot disagree. A plugin that declares a core word
|
|
124
|
+
* adds no second entry and does not change its label.
|
|
125
|
+
*/ export function listContactSourceOptions() {
|
|
126
|
+
const words = new Set([
|
|
127
|
+
...Object.keys(CONTACT_SOURCE_LABELS),
|
|
128
|
+
...listPluginContactSources().map((door)=>door.source)
|
|
129
|
+
]);
|
|
130
|
+
return [
|
|
131
|
+
...words
|
|
132
|
+
].map((value)=>({
|
|
133
|
+
value,
|
|
134
|
+
label: labelContactSource(value)
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
111
137
|
|
|
112
138
|
//# sourceMappingURL=plugin-contact-capture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-contact-capture.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 { CONTACT_SOURCE_LABELS } from '../app-utils/contacts'\nimport { getRegisteringPluginId } from '../app-utils/registering-plugin'\nimport {\n definePluginServiceContract,\n registerPluginService,\n resolvePluginServices,\n} from './plugin-services'\n\n/**\n * A person met on a site, handed to whichever plugin keeps people (AGL-3124).\n *\n * Four silos capture the same thing and none of them is the record system: a\n * form submission, a site member signing up, an order, a booking. Each holds\n * an address, a name and the fact that something happened, and each wants the\n * workspace's person record to know. Today each one imports the writer, which\n * makes the highest-fan-in edge in the repo — thirty files in one plugin alone\n * — and makes the record system's plugin something a storefront cannot take a\n * payment without.\n *\n * So the silo stops importing and starts DECLARING: it registers the capture\n * door it owns, and hands a capture to this seam. The plugin that keeps people\n * registers the writer and does every part of the work that is a record\n * system's to do:\n *\n * - normalizing and keying the address, and deciding whether this is a new\n * person or a visit from one the workspace already holds;\n * - the audience band, the erasure rows, and every other refusal — answered,\n * never thrown, so a capture that is refused never costs the silo the order\n * or the submission it was recording;\n * - what a stage, an owner, a company and a tag mean, and what the arrival\n * of a new person sets off.\n *\n * The silo decides none of that. It reports what it saw.\n *\n * ## Why the profile is opaque\n *\n * `profile` is the owner's own field names with scalar values, not a core\n * type. A person's record shape belongs to the plugin that models it, and a\n * typed core shape would be that model spelled in the platform again — which\n * is the defect this seam exists to retire, not a smaller version of it. A key\n * the owner does not document is the owner's to ignore.\n *\n * `source` is the silo's own word for its door, and it is declared rather than\n * enumerated here for the same reason: core listing `form`, `member`, `order`\n * and `booking` would be core holding the plugin set again. A silo registers\n * its source with {@link registerPluginContactSource}, which is what lets a\n * timeline label an entry and a link point back at the thing that captured the\n * person, without the platform knowing what any of them are.\n *\n * ## One writer; many silos\n *\n * A workspace keeps one set of people, so the writer is a slot: a second\n * plugin's writer is refused naming both, and the incumbent keeps serving. A\n * SOURCE is per silo and there are many, but one source word has one owner —\n * two plugins claiming `order` would make the label and the link ambiguous at\n * the point they are read.\n *\n * ## The caller proves who is asking\n *\n * Like `plugin-record-timeline`, the registry authenticates nobody. A silo has\n * already decided, in its own terms and before it asks, that the capture is\n * the workspace's to record — that the submission was accepted, that the order\n * was paid.\n *\n * Server-side: reached by its own subpath, never through\n * `plugin-manager/index.ts`.\n */\n\n/** The person, as the capturing silo saw them. */\nexport interface PluginContactIdentity {\n /**\n * The address they gave. Raw: the owner normalizes and keys on it, and a\n * silo that normalized first would be keeping a second copy of that rule.\n */\n email: unknown\n name?: string | null\n}\n\n/** What happened, in the capturing silo's own words. */\nexport interface PluginContactInteraction {\n /** The silo's declared source word — see {@link registerPluginContactSource}. */\n source: string\n /** When it happened, epoch ms; the owner uses now when absent. */\n atMs?: number\n /**\n * The document it happened on, in the silo's terms\n * (`formSubmissions/{id}`, `orders/{id}`), so a timeline entry can point\n * back at it. Absent where the door leaves nothing to open.\n */\n refId?: string | null\n /** One line a person reads on the timeline. */\n summary?: string | null\n}\n\nexport interface PluginContactCaptureRequest {\n /**\n * Who caused the capture, when it was not the person captured (AGL-3376) —\n * a member adding someone by hand, an integration's key. A door where the\n * visitor acts for themselves (a form, a purchase) may leave it out.\n */\n actor?: {\n kind: 'member' | 'visitor' | 'apiKey' | 'platform'\n uid?: string | null\n email?: string | null\n apiKeyName?: string | null\n }\n orgId: string\n /** The site the person was met on: the brand whose form or checkout it was. */\n hostId: string\n identity: PluginContactIdentity\n interaction: PluginContactInteraction\n /**\n * An explicit marketing opt-in the capture surface carried, recorded against\n * `hostId`: consent to the MARKETING send purpose (`marketing-consent.ts`),\n * whichever plugin's mail later asks for it. Absent is not consent, and\n * filing a capture under a container is not consent either.\n */\n marketingConsent?: boolean\n /**\n * The disclosure key the capture surface rendered beside that opt-in\n * (`consentGroupDisclosureKey`, AGL-3320), passed through as the surface\n * sent it. The owner records the opt-in for the site's whole consent group\n * only when this is the group's current key, and for `hostId` alone\n * otherwise — so a silo whose surface shows no disclosure sends none.\n */\n disclosedConsentGroup?: string\n /** Tags the silo puts on this capture; the owner adds, never replaces. */\n tags?: readonly string[]\n /**\n * What the capture SURFACE is filed under — the merchant's own act — by\n * container kind (`plugin-containers.ts`): `{ [kind]: ids }`. The owner\n * files the person under the kinds it keeps. Filing is not consent.\n */\n containers?: Readonly<Record<string, readonly string[]>>\n /** Money the capture was worth, in cents, where the silo took some. */\n purchaseCents?: number\n /** The currency {@link purchaseCents} is in, lowercase, when the silo knows. */\n purchaseCurrency?: string\n /**\n * The earliest stage this capture describes, in the OWNER's words. A floor\n * and not a value: the owner fills an empty stage and advances an earlier\n * one, and never moves anybody back, so a repeat customer filling in a\n * contact form is still a customer.\n */\n lifecycleFloor?: string\n /**\n * What kind of door this is, which decides WHICH RECORD the person lands\n * on (AGL-3232) — the owner's rule is Salesforce's: one person is one\n * record, a lead until they are qualified and a contact after.\n *\n * - `lead`: a lead surface — a form whose author routes it to leads, a\n * booking request. The person is filed as a LEAD and nothing else,\n * unless the workspace already holds them as a contact, in which case\n * the capture lands on the contact and no lead is filed.\n * - `relationship`: an act that makes the person a known relationship —\n * a member account, a purchase. The person is filed as a CONTACT, and\n * an open lead the site held for them is stamped converted onto it.\n * - `touch`, the default: everything else — a form without lead routing,\n * a newsletter opt-in. The capture lands on the open lead when the site\n * holds one for the address, and on the contact otherwise.\n */\n surface?: 'lead' | 'relationship' | 'touch'\n /**\n * Profile fields the silo knows, keyed by the owner's own field names.\n * Only the keys given are written, so a silo that knows the phone number\n * does not blank a title somebody typed.\n */\n profile?: Readonly<Record<string, unknown>>\n /**\n * Profile fields written only where the record the person lands on holds\n * none (AGL-3493), keyed as {@link profile} is. For what a door learned\n * in passing — the phone a booking form asked for — and must not put over\n * a value somebody typed on the record or gave the business before.\n * A key also present in `profile` is `profile`'s to write.\n */\n profileFill?: Readonly<Record<string, unknown>>\n /**\n * Facts about THIS CAPTURE that the owner models and the platform does not\n * (AGL-3080) — which form was filled in, which page it was on, where the\n * visitor arrived from.\n *\n * Opaque for the reason {@link profile} is: every one of these is a concept\n * belonging to the plugin that keeps people or to the silo that saw it, and\n * a typed core field for each would be those models spelled out in the\n * platform again. `profile` describes the PERSON and outlives the visit;\n * this describes the visit and does not.\n *\n * A key the owner does not recognize is the owner's to ignore, and a silo\n * that sends nothing here loses nothing: every field is an enrichment of a\n * capture that is already complete without it.\n */\n detail?: Readonly<Record<string, unknown>>\n}\n\n/**\n * The owner's answer. `created: false` is a visit by somebody the workspace\n * already held, which is an interaction and not a new person.\n *\n * A refusal is RETURNED. Every one of these silos has already done the thing\n * it was recording, so a throw here would cost an accepted submission or a\n * paid order for a record it could not keep.\n */\nexport type PluginContactCaptured =\n /** The capture landed on a contact — the record every capture used to make. */\n | { ok: true; record: 'contact'; contactId: string; created: boolean }\n /**\n * The capture landed on a LEAD (AGL-3232): a lead surface met somebody the\n * workspace does not hold as a contact, or a touch reached an open lead.\n * `leadId` is the person key the lead is filed under on `hostId`.\n */\n | {\n ok: true\n record: 'lead'\n leadId: string\n created: boolean\n /**\n * Whether this capture's surface was new on the lead — a new person,\n * or one first met through another door. A form counts its leads by\n * it (AGL-3330): the people it filed, not the times they came back.\n * Absent from a writer that does not say, which a caller reads as\n * `created`.\n */\n sourceAdded?: boolean\n }\n | {\n ok: false\n /**\n * `invalid-email`: nothing usable to key a person on. `band`: the\n * workspace is at the audience it may hold. `erased`: the workspace\n * erased this person and a capture must not quietly rebuild them.\n * `error`: the owner failed, and said so rather than silently.\n */\n reason: 'invalid-email' | 'band' | 'erased' | 'error'\n /** Customer-safe: a caller may show or log it as it stands. */\n error: string\n }\n\nexport interface PluginContactCaptureWriter {\n /** Records one capture; a refusal is returned, never thrown. */\n capture(\n request: PluginContactCaptureRequest,\n ): Promise<PluginContactCaptured>\n}\n\n/** A capture door a silo owns. */\nexport interface PluginContactSourceDeclaration {\n /** The silo's word for the door, as its captures carry it. */\n source: string\n /** What a timeline entry from this door says: `Form submission`. */\n label: string\n /**\n * What a link from that entry says when there is something to open —\n * `Open submission`. Absent where the door leaves nothing to open, which\n * is the honest answer for an import or a by-hand add.\n */\n openLabel?: string\n /**\n * The record kind the silo's own document is, for\n * `plugin-record-routes` to address it with. Absent where the door has no\n * record of its own to open.\n */\n recordKind?: string\n}\n\n/** A source declaration with the silo that made it. */\nexport type ResolvedPluginContactSource = PluginContactSourceDeclaration & {\n pluginId: string\n}\n\nexport const PLUGIN_CONTACT_CAPTURE =\n definePluginServiceContract<PluginContactCaptureWriter>(\n 'core.contact-capture',\n { multiple: false },\n )\n\nexport const PLUGIN_CONTACT_SOURCES =\n definePluginServiceContract<PluginContactSourceDeclaration>(\n 'core.contact-capture-sources',\n { multiple: true },\n )\n\n/**\n * Registers the plugin that keeps people. The owner is the loader's marker\n * when a register fn is running, else `options.pluginId`; with neither the\n * registration throws, and a second plugin's writer is refused naming both —\n * the incumbent keeps serving.\n */\nexport function registerPluginContactCaptureWriter(\n writer: PluginContactCaptureWriter,\n options?: { pluginId?: string },\n): void {\n registerPluginService(PLUGIN_CONTACT_CAPTURE, writer, {\n ...(options?.pluginId ? { pluginId: options.pluginId } : {}),\n })\n}\n\n/** Declares a capture door. One source word has one owner. */\nexport function registerPluginContactSource(\n declaration: PluginContactSourceDeclaration,\n options?: { pluginId?: string },\n): void {\n const key = declaration.source?.trim() ?? ''\n if (!key) throw new Error('a contact capture source needs a source word')\n if (!declaration.label?.trim()) {\n throw new Error(`contact capture source \"${key}\" needs a label`)\n }\n const pluginId = (getRegisteringPluginId() ?? options?.pluginId ?? '').trim()\n const incumbent = resolvePluginServices(PLUGIN_CONTACT_SOURCES).find(\n (entry) => entry.key === key,\n )\n if (incumbent && pluginId && incumbent.pluginId !== pluginId) {\n throw new Error(\n `contact capture source \"${key}\" is already declared by ` +\n `\"${incumbent.pluginId}\"; refused \"${pluginId}\"`,\n )\n }\n registerPluginService(\n PLUGIN_CONTACT_SOURCES,\n { ...declaration, source: key },\n {\n ...(options?.pluginId ? { pluginId: options.pluginId } : {}),\n key,\n },\n )\n}\n\nexport interface ResolvedPluginContactCaptureWriter {\n /** The plugin that keeps people. */\n pluginId: string\n writer: PluginContactCaptureWriter\n}\n\n/** The writer with its owner, or `null` when no plugin keeps people here. */\nexport function pluginContactCaptureWriter(): ResolvedPluginContactCaptureWriter | null {\n const entry = resolvePluginServices(PLUGIN_CONTACT_CAPTURE)[0]\n return entry ? { pluginId: entry.pluginId, writer: entry.impl } : null\n}\n\n/**\n * Hands one capture to the plugin that keeps people, or answers `null` when\n * no plugin does.\n *\n * `null` and a refusal are different answers and a silo treats them\n * differently: `null` is a workspace with no record system, where there is\n * nothing to record and nothing has gone wrong; a refusal is a record system\n * that considered this person and declined.\n */\nexport async function capturePluginContact(\n request: PluginContactCaptureRequest,\n): Promise<PluginContactCaptured | null> {\n const found = pluginContactCaptureWriter()\n if (!found) return null\n return found.writer.capture(request)\n}\n\n/** Every declared capture door, with its silo, in registration order. */\nexport function listPluginContactSources(): ResolvedPluginContactSource[] {\n return resolvePluginServices(PLUGIN_CONTACT_SOURCES).map((entry) => ({\n ...entry.impl,\n pluginId: entry.pluginId,\n }))\n}\n\n/** One declared capture door by its source word, or `null`. */\nexport function pluginContactSource(\n source: string,\n): ResolvedPluginContactSource | null {\n const key = source.trim()\n const entry = resolvePluginServices(PLUGIN_CONTACT_SOURCES).find(\n (one) => one.key === key,\n )\n return entry ? { ...entry.impl, pluginId: entry.pluginId } : null\n}\n\n/**\n * How a contact's source word reads on screen, wherever it came from: the\n * core's own words from {@link CONTACT_SOURCE_LABELS}, then the label a\n * plugin declared for its door with {@link registerPluginContactSource},\n * then `fallback` when one is given, else the word itself.\n *\n * The core's map is a closed `Record<ContactSource, string>`, and a plugin's\n * door is an open string by design, so a list, a chip or a report that read\n * the map alone showed a plugin's raw word (`waiver` rather than its label).\n * This is the one place both are asked, in that order, so a plugin cannot\n * relabel a core source. It answers from what is registered in THIS process:\n * a plugin that declares its door from its `declarations` entry is known in\n * the console's browser and on both servers before a page renders.\n */\nexport function labelContactSource(source: unknown, fallback?: string): string {\n const word = typeof source === 'string' ? source.trim() : ''\n if (!word) return fallback ?? ''\n if (Object.hasOwn(CONTACT_SOURCE_LABELS, word)) {\n return CONTACT_SOURCE_LABELS[word as keyof typeof CONTACT_SOURCE_LABELS]\n }\n return pluginContactSource(word)?.label || (fallback ?? word)\n}\n"],"names":["CONTACT_SOURCE_LABELS","getRegisteringPluginId","definePluginServiceContract","registerPluginService","resolvePluginServices","PLUGIN_CONTACT_CAPTURE","multiple","PLUGIN_CONTACT_SOURCES","registerPluginContactCaptureWriter","writer","options","pluginId","registerPluginContactSource","declaration","key","source","trim","Error","label","incumbent","find","entry","pluginContactCaptureWriter","impl","capturePluginContact","request","found","capture","listPluginContactSources","map","pluginContactSource","one","labelContactSource","fallback","word","Object","hasOwn"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,qBAAqB,QAAQ,2BAAuB;AAC7D,SAASC,sBAAsB,QAAQ,qCAAiC;AACxE,SACEC,2BAA2B,EAC3BC,qBAAqB,EACrBC,qBAAqB,QAChB,uBAAmB;AAuQ1B,OAAO,MAAMC,yBACXH,4BACE,wBACA;IAAEI,UAAU;AAAM,GACnB;AAEH,OAAO,MAAMC,yBACXL,4BACE,gCACA;IAAEI,UAAU;AAAK,GAClB;AAEH;;;;;CAKC,GACD,OAAO,SAASE,mCACdC,MAAkC,EAClCC,OAA+B;IAE/BP,sBAAsBE,wBAAwBI,QAAQ,aAChDC,CAAAA,2BAAAA,QAASC,QAAQ,IAAG;QAAEA,UAAUD,QA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OAAO;IACnB,OAAOA,MAAMjB,MAAM,CAACkB,OAAO,CAACF;AAC9B;AAEA,uEAAuE,GACvE,OAAO,SAASG;IACd,OAAOxB,sBAAsBG,wBAAwBsB,GAAG,CAAC,CAACR,QAAW,aAChEA,MAAME,IAAI;YACbZ,UAAUU,MAAMV,QAAQ;;AAE5B;AAEA,6DAA6D,GAC7D,OAAO,SAASmB,oBACdf,MAAc;IAEd,MAAMD,MAAMC,OAAOC,IAAI;IACvB,MAAMK,QAAQjB,sBAAsBG,wBAAwBa,IAAI,CAC9D,CAACW,MAAQA,IAAIjB,GAAG,KAAKA;IAEvB,OAAOO,QAAQ,aAAKA,MAAME,IAAI;QAAEZ,UAAUU,MAAMV,QAAQ;SAAK;AAC/D;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASqB,mBAAmBjB,MAAe,EAAEkB,QAAiB;QAM5DH;IALP,MAAMI,OAAO,OAAOnB,WAAW,WAAWA,OAAOC,IAAI,KAAK;IAC1D,IAAI,CAACkB,MAAM,OAAOD,mBAAAA,WAAY;IAC9B,IAAIE,OAAOC,MAAM,CAACpC,uBAAuBkC,OAAO;QAC9C,OAAOlC,qBAAqB,CAACkC,KAA2C;IAC1E;IACA,OAAOJ,EAAAA,uBAAAA,oBAAoBI,0BAApBJ,qBAA2BZ,KAAK,MAAKe,mBAAAA,WAAYC;AAC1D"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-contact-capture.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 { CONTACT_SOURCE_LABELS } from '../app-utils/contacts'\nimport { getRegisteringPluginId } from '../app-utils/registering-plugin'\nimport {\n definePluginServiceContract,\n registerPluginService,\n resolvePluginServices,\n} from './plugin-services'\n\n/**\n * A person met on a site, handed to whichever plugin keeps people (AGL-3124).\n *\n * Four silos capture the same thing and none of them is the record system: a\n * form submission, a site member signing up, an order, a booking. Each holds\n * an address, a name and the fact that something happened, and each wants the\n * workspace's person record to know. Today each one imports the writer, which\n * makes the highest-fan-in edge in the repo — thirty files in one plugin alone\n * — and makes the record system's plugin something a storefront cannot take a\n * payment without.\n *\n * So the silo stops importing and starts DECLARING: it registers the capture\n * door it owns, and hands a capture to this seam. The plugin that keeps people\n * registers the writer and does every part of the work that is a record\n * system's to do:\n *\n * - normalizing and keying the address, and deciding whether this is a new\n * person or a visit from one the workspace already holds;\n * - the audience band, the erasure rows, and every other refusal — answered,\n * never thrown, so a capture that is refused never costs the silo the order\n * or the submission it was recording;\n * - what a stage, an owner, a company and a tag mean, and what the arrival\n * of a new person sets off.\n *\n * The silo decides none of that. It reports what it saw.\n *\n * ## Why the profile is opaque\n *\n * `profile` is the owner's own field names with scalar values, not a core\n * type. A person's record shape belongs to the plugin that models it, and a\n * typed core shape would be that model spelled in the platform again — which\n * is the defect this seam exists to retire, not a smaller version of it. A key\n * the owner does not document is the owner's to ignore.\n *\n * `source` is the silo's own word for its door, and it is declared rather than\n * enumerated here for the same reason: core listing `form`, `member`, `order`\n * and `booking` would be core holding the plugin set again. A silo registers\n * its source with {@link registerPluginContactSource}, which is what lets a\n * timeline label an entry and a link point back at the thing that captured the\n * person, without the platform knowing what any of them are.\n *\n * ## One writer; many silos\n *\n * A workspace keeps one set of people, so the writer is a slot: a second\n * plugin's writer is refused naming both, and the incumbent keeps serving. A\n * SOURCE is per silo and there are many, but one source word has one owner —\n * two plugins claiming `order` would make the label and the link ambiguous at\n * the point they are read.\n *\n * ## The caller proves who is asking\n *\n * Like `plugin-record-timeline`, the registry authenticates nobody. A silo has\n * already decided, in its own terms and before it asks, that the capture is\n * the workspace's to record — that the submission was accepted, that the order\n * was paid.\n *\n * Server-side: reached by its own subpath, never through\n * `plugin-manager/index.ts`.\n */\n\n/** The person, as the capturing silo saw them. */\nexport interface PluginContactIdentity {\n /**\n * The address they gave. Raw: the owner normalizes and keys on it, and a\n * silo that normalized first would be keeping a second copy of that rule.\n */\n email: unknown\n name?: string | null\n}\n\n/** What happened, in the capturing silo's own words. */\nexport interface PluginContactInteraction {\n /** The silo's declared source word — see {@link registerPluginContactSource}. */\n source: string\n /** When it happened, epoch ms; the owner uses now when absent. */\n atMs?: number\n /**\n * The document it happened on, in the silo's terms\n * (`formSubmissions/{id}`, `orders/{id}`), so a timeline entry can point\n * back at it. Absent where the door leaves nothing to open.\n */\n refId?: string | null\n /** One line a person reads on the timeline. */\n summary?: string | null\n}\n\nexport interface PluginContactCaptureRequest {\n /**\n * Who caused the capture, when it was not the person captured (AGL-3376) —\n * a member adding someone by hand, an integration's key. A door where the\n * visitor acts for themselves (a form, a purchase) may leave it out.\n */\n actor?: {\n kind: 'member' | 'visitor' | 'apiKey' | 'platform'\n uid?: string | null\n email?: string | null\n apiKeyName?: string | null\n }\n orgId: string\n /** The site the person was met on: the brand whose form or checkout it was. */\n hostId: string\n identity: PluginContactIdentity\n interaction: PluginContactInteraction\n /**\n * An explicit marketing opt-in the capture surface carried, recorded against\n * `hostId`: consent to the MARKETING send purpose (`marketing-consent.ts`),\n * whichever plugin's mail later asks for it. Absent is not consent, and\n * filing a capture under a container is not consent either.\n */\n marketingConsent?: boolean\n /**\n * The disclosure key the capture surface rendered beside that opt-in\n * (`consentGroupDisclosureKey`, AGL-3320), passed through as the surface\n * sent it. The owner records the opt-in for the site's whole consent group\n * only when this is the group's current key, and for `hostId` alone\n * otherwise — so a silo whose surface shows no disclosure sends none.\n */\n disclosedConsentGroup?: string\n /** Tags the silo puts on this capture; the owner adds, never replaces. */\n tags?: readonly string[]\n /**\n * What the capture SURFACE is filed under — the merchant's own act — by\n * container kind (`plugin-containers.ts`): `{ [kind]: ids }`. The owner\n * files the person under the kinds it keeps. Filing is not consent.\n */\n containers?: Readonly<Record<string, readonly string[]>>\n /** Money the capture was worth, in cents, where the silo took some. */\n purchaseCents?: number\n /** The currency {@link purchaseCents} is in, lowercase, when the silo knows. */\n purchaseCurrency?: string\n /**\n * The earliest stage this capture describes, in the OWNER's words. A floor\n * and not a value: the owner fills an empty stage and advances an earlier\n * one, and never moves anybody back, so a repeat customer filling in a\n * contact form is still a customer.\n */\n lifecycleFloor?: string\n /**\n * What kind of door this is, which decides WHICH RECORD the person lands\n * on (AGL-3232) — the owner's rule is Salesforce's: one person is one\n * record, a lead until they are qualified and a contact after.\n *\n * - `lead`: a lead surface — a form whose author routes it to leads, a\n * booking request. The person is filed as a LEAD and nothing else,\n * unless the workspace already holds them as a contact, in which case\n * the capture lands on the contact and no lead is filed.\n * - `relationship`: an act that makes the person a known relationship —\n * a member account, a purchase. The person is filed as a CONTACT, and\n * an open lead the site held for them is stamped converted onto it.\n * - `touch`, the default: everything else — a form without lead routing,\n * a newsletter opt-in. The capture lands on the open lead when the site\n * holds one for the address, and on the contact otherwise.\n */\n surface?: 'lead' | 'relationship' | 'touch'\n /**\n * Profile fields the silo knows, keyed by the owner's own field names.\n * Only the keys given are written, so a silo that knows the phone number\n * does not blank a title somebody typed.\n */\n profile?: Readonly<Record<string, unknown>>\n /**\n * Profile fields written only where the record the person lands on holds\n * none (AGL-3493), keyed as {@link profile} is. For what a door learned\n * in passing — the phone a booking form asked for — and must not put over\n * a value somebody typed on the record or gave the business before.\n * A key also present in `profile` is `profile`'s to write.\n */\n profileFill?: Readonly<Record<string, unknown>>\n /**\n * Facts about THIS CAPTURE that the owner models and the platform does not\n * (AGL-3080) — which form was filled in, which page it was on, where the\n * visitor arrived from.\n *\n * Opaque for the reason {@link profile} is: every one of these is a concept\n * belonging to the plugin that keeps people or to the silo that saw it, and\n * a typed core field for each would be those models spelled out in the\n * platform again. `profile` describes the PERSON and outlives the visit;\n * this describes the visit and does not.\n *\n * A key the owner does not recognize is the owner's to ignore, and a silo\n * that sends nothing here loses nothing: every field is an enrichment of a\n * capture that is already complete without it.\n */\n detail?: Readonly<Record<string, unknown>>\n}\n\n/**\n * The owner's answer. `created: false` is a visit by somebody the workspace\n * already held, which is an interaction and not a new person.\n *\n * A refusal is RETURNED. Every one of these silos has already done the thing\n * it was recording, so a throw here would cost an accepted submission or a\n * paid order for a record it could not keep.\n */\nexport type PluginContactCaptured =\n /** The capture landed on a contact — the record every capture used to make. */\n | { ok: true; record: 'contact'; contactId: string; created: boolean }\n /**\n * The capture landed on a LEAD (AGL-3232): a lead surface met somebody the\n * workspace does not hold as a contact, or a touch reached an open lead.\n * `leadId` is the person key the lead is filed under on `hostId`.\n */\n | {\n ok: true\n record: 'lead'\n leadId: string\n created: boolean\n /**\n * Whether this capture's surface was new on the lead — a new person,\n * or one first met through another door. A form counts its leads by\n * it (AGL-3330): the people it filed, not the times they came back.\n * Absent from a writer that does not say, which a caller reads as\n * `created`.\n */\n sourceAdded?: boolean\n }\n | {\n ok: false\n /**\n * `invalid-email`: nothing usable to key a person on. `band`: the\n * workspace is at the audience it may hold. `erased`: the workspace\n * erased this person and a capture must not quietly rebuild them.\n * `error`: the owner failed, and said so rather than silently.\n */\n reason: 'invalid-email' | 'band' | 'erased' | 'error'\n /** Customer-safe: a caller may show or log it as it stands. */\n error: string\n }\n\nexport interface PluginContactCaptureWriter {\n /** Records one capture; a refusal is returned, never thrown. */\n capture(\n request: PluginContactCaptureRequest,\n ): Promise<PluginContactCaptured>\n}\n\n/** A capture door a silo owns. */\nexport interface PluginContactSourceDeclaration {\n /** The silo's word for the door, as its captures carry it. */\n source: string\n /** What a timeline entry from this door says: `Form submission`. */\n label: string\n /**\n * What a link from that entry says when there is something to open —\n * `Open submission`. Absent where the door leaves nothing to open, which\n * is the honest answer for an import or a by-hand add.\n */\n openLabel?: string\n /**\n * The record kind the silo's own document is, for\n * `plugin-record-routes` to address it with. Absent where the door has no\n * record of its own to open.\n */\n recordKind?: string\n}\n\n/** A source declaration with the silo that made it. */\nexport type ResolvedPluginContactSource = PluginContactSourceDeclaration & {\n pluginId: string\n}\n\nexport const PLUGIN_CONTACT_CAPTURE =\n definePluginServiceContract<PluginContactCaptureWriter>(\n 'core.contact-capture',\n { multiple: false },\n )\n\nexport const PLUGIN_CONTACT_SOURCES =\n definePluginServiceContract<PluginContactSourceDeclaration>(\n 'core.contact-capture-sources',\n { multiple: true },\n )\n\n/**\n * Registers the plugin that keeps people. The owner is the loader's marker\n * when a register fn is running, else `options.pluginId`; with neither the\n * registration throws, and a second plugin's writer is refused naming both —\n * the incumbent keeps serving.\n */\nexport function registerPluginContactCaptureWriter(\n writer: PluginContactCaptureWriter,\n options?: { pluginId?: string },\n): void {\n registerPluginService(PLUGIN_CONTACT_CAPTURE, writer, {\n ...(options?.pluginId ? { pluginId: options.pluginId } : {}),\n })\n}\n\n/** Declares a capture door. One source word has one owner. */\nexport function registerPluginContactSource(\n declaration: PluginContactSourceDeclaration,\n options?: { pluginId?: string },\n): void {\n const key = declaration.source?.trim() ?? ''\n if (!key) throw new Error('a contact capture source needs a source word')\n if (!declaration.label?.trim()) {\n throw new Error(`contact capture source \"${key}\" needs a label`)\n }\n const pluginId = (getRegisteringPluginId() ?? options?.pluginId ?? '').trim()\n const incumbent = resolvePluginServices(PLUGIN_CONTACT_SOURCES).find(\n (entry) => entry.key === key,\n )\n if (incumbent && pluginId && incumbent.pluginId !== pluginId) {\n throw new Error(\n `contact capture source \"${key}\" is already declared by ` +\n `\"${incumbent.pluginId}\"; refused \"${pluginId}\"`,\n )\n }\n registerPluginService(\n PLUGIN_CONTACT_SOURCES,\n { ...declaration, source: key },\n {\n ...(options?.pluginId ? { pluginId: options.pluginId } : {}),\n key,\n },\n )\n}\n\nexport interface ResolvedPluginContactCaptureWriter {\n /** The plugin that keeps people. */\n pluginId: string\n writer: PluginContactCaptureWriter\n}\n\n/** The writer with its owner, or `null` when no plugin keeps people here. */\nexport function pluginContactCaptureWriter(): ResolvedPluginContactCaptureWriter | null {\n const entry = resolvePluginServices(PLUGIN_CONTACT_CAPTURE)[0]\n return entry ? { pluginId: entry.pluginId, writer: entry.impl } : null\n}\n\n/**\n * Hands one capture to the plugin that keeps people, or answers `null` when\n * no plugin does.\n *\n * `null` and a refusal are different answers and a silo treats them\n * differently: `null` is a workspace with no record system, where there is\n * nothing to record and nothing has gone wrong; a refusal is a record system\n * that considered this person and declined.\n */\nexport async function capturePluginContact(\n request: PluginContactCaptureRequest,\n): Promise<PluginContactCaptured | null> {\n const found = pluginContactCaptureWriter()\n if (!found) return null\n return found.writer.capture(request)\n}\n\n/** Every declared capture door, with its silo, in registration order. */\nexport function listPluginContactSources(): ResolvedPluginContactSource[] {\n return resolvePluginServices(PLUGIN_CONTACT_SOURCES).map((entry) => ({\n ...entry.impl,\n pluginId: entry.pluginId,\n }))\n}\n\n/** One declared capture door by its source word, or `null`. */\nexport function pluginContactSource(\n source: string,\n): ResolvedPluginContactSource | null {\n const key = source.trim()\n const entry = resolvePluginServices(PLUGIN_CONTACT_SOURCES).find(\n (one) => one.key === key,\n )\n return entry ? { ...entry.impl, pluginId: entry.pluginId } : null\n}\n\n/**\n * How a contact's source word reads on screen, wherever it came from: the\n * core's own words from {@link CONTACT_SOURCE_LABELS}, then the label a\n * plugin declared for its door with {@link registerPluginContactSource},\n * then `fallback` when one is given, else the word itself.\n *\n * The core's map is a closed `Record<ContactSource, string>`, and a plugin's\n * door is an open string by design, so a list, a chip or a report that read\n * the map alone showed a plugin's raw word (`waiver` rather than its label).\n * This is the one place both are asked, in that order, so a plugin cannot\n * relabel a core source. It answers from what is registered in THIS process:\n * a plugin that declares its door from its `declarations` entry is known in\n * the console's browser and on both servers before a page renders.\n */\nexport function labelContactSource(source: unknown, fallback?: string): string {\n const word = typeof source === 'string' ? source.trim() : ''\n if (!word) return fallback ?? ''\n if (Object.hasOwn(CONTACT_SOURCE_LABELS, word)) {\n return CONTACT_SOURCE_LABELS[word as keyof typeof CONTACT_SOURCE_LABELS]\n }\n return pluginContactSource(word)?.label || (fallback ?? word)\n}\n\n/**\n * Whether a word is a source this process can name: one of the core's, or a\n * door a plugin declared. What keeps a saved filter from carrying a word\n * nothing answers to, without closing the list against a plugin's door.\n */\nexport function isKnownContactSource(source: unknown): boolean {\n const word = typeof source === 'string' ? source.trim() : ''\n if (!word) return false\n return Object.hasOwn(CONTACT_SOURCE_LABELS, word) || pluginContactSource(word) !== null\n}\n\n/** One source a filter offers: the stored word, and how it reads. */\nexport interface PluginContactSourceOption {\n value: string\n label: string\n}\n\n/**\n * Every source a filter can offer: the core's, then each door a plugin\n * declared, each reading as {@link labelContactSource} reads it, so a filter's\n * choice and a row's chip cannot disagree. A plugin that declares a core word\n * adds no second entry and does not change its label.\n */\nexport function listContactSourceOptions(): PluginContactSourceOption[] {\n const words = new Set([\n ...Object.keys(CONTACT_SOURCE_LABELS),\n ...listPluginContactSources().map((door) => door.source),\n ])\n return [...words].map((value) => ({ value, label: labelContactSource(value) }))\n}\n"],"names":["CONTACT_SOURCE_LABELS","getRegisteringPluginId","definePluginServiceContract","registerPluginService","resolvePluginServices","PLUGIN_CONTACT_CAPTURE","multiple","PLUGIN_CONTACT_SOURCES","registerPluginContactCaptureWriter","writer","options","pluginId","registerPluginContactSource","declaration","key","source","trim","Error","label","incumbent","find","entry","pluginContactCaptureWriter","impl","capturePluginContact","request","found","capture","listPluginContactSources","map","pluginContactSource","one","labelContactSource","fallback","word","Object","hasOwn","isKnownContactSource","listContactSourceOptions","words","Set","keys","door","value"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,qBAAqB,QAAQ,2BAAuB;AAC7D,SAASC,sBAAsB,QAAQ,qCAAiC;AACxE,SACEC,2BAA2B,EAC3BC,qBAAqB,EACrBC,qBAAqB,QAChB,uBAAmB;AAuQ1B,OAAO,MAAMC,yBACXH,4BACE,wBACA;IAAEI,UAAU;AAAM,GACnB;AA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M,CAACpC,uBAAuBkC,SAASJ,oBAAoBI,UAAU;AACrF;AAQA;;;;;CAKC,GACD,OAAO,SAASI;IACd,MAAMC,QAAQ,IAAIC,IAAI;WACjBL,OAAOM,IAAI,CAACzC;WACZ4B,2BAA2BC,GAAG,CAAC,CAACa,OAASA,KAAK3B,MAAM;KACxD;IACD,OAAO;WAAIwB;KAAM,CAACV,GAAG,CAAC,CAACc,QAAW,CAAA;YAAEA;YAAOzB,OAAOc,mBAAmBW;QAAO,CAAA;AAC9E"}
|
|
@@ -186,6 +186,16 @@ export interface PluginOrgPermissionDeclaration {
|
|
|
186
186
|
* key whose preset is the site role (`presetFromSiteRole`).
|
|
187
187
|
*/
|
|
188
188
|
narrowsPerSite?: boolean | Partial<Record<OrgRole, boolean>>;
|
|
189
|
+
/**
|
|
190
|
+
* A site can also RAISE this key (AGL-4047). Where a member of the whole
|
|
191
|
+
* workspace has wider access to one site than their workspace role, the key
|
|
192
|
+
* reads `hostRoleDefaults` for that access there, unless a custom role or
|
|
193
|
+
* their own permissions decide it or the key it `follows`. For a key that
|
|
194
|
+
* narrows and raises with the site, which `presetFromSiteRole` cannot be:
|
|
195
|
+
* that gives up the workspace's verdict, and with it `narrowsPerSite`'s
|
|
196
|
+
* "Keep this permission". Needs `hostRoleDefaults`.
|
|
197
|
+
*/
|
|
198
|
+
raisesPerSite?: boolean;
|
|
189
199
|
/**
|
|
190
200
|
* The key's preset is the member's role ON THE SITE, for every member
|
|
191
201
|
* (AGL-4047), not only for a site collaborator: the owner and admins are
|
|
@@ -242,6 +252,8 @@ export interface PluginCatalogPermission {
|
|
|
242
252
|
* default for whether it does, normalized from the declaration.
|
|
243
253
|
*/
|
|
244
254
|
narrowsPerSite?: Readonly<Record<OrgRole, boolean>>;
|
|
255
|
+
/** A site can raise the key (AGL-4047); see the declaration's. */
|
|
256
|
+
raisesPerSite?: true;
|
|
245
257
|
/** The key's preset is the member's role on the site (AGL-4047); see the declaration's. */
|
|
246
258
|
presetFromSiteRole?: true;
|
|
247
259
|
/** That preset holds for members of the whole workspace only (AGL-4047); see the declaration's. */
|
|
@@ -243,7 +243,9 @@ const reportedCatalogRefusals = new Set();
|
|
|
243
243
|
presetFromSiteRole: true
|
|
244
244
|
}, permission.workspaceMembersOnly ? {
|
|
245
245
|
workspaceMembersOnly: true
|
|
246
|
-
} : {}) : narrowingDefaultsOf(permission.narrowsPerSite)
|
|
246
|
+
} : {}) : narrowingDefaultsOf(permission.narrowsPerSite), permission.raisesPerSite && permission.hostRoleDefaults && !permission.presetFromSiteRole ? {
|
|
247
|
+
raisesPerSite: true
|
|
248
|
+
} : {}));
|
|
247
249
|
}
|
|
248
250
|
for (const permission of listPluginPermissions()){
|
|
249
251
|
var _permission_description, _permission_group1, _permission_groupLabel1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-entitlements.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 * Plugin-declared billing and access keys (AGL-2940).\n *\n * A plugin that sells something, gates something, or can be switched off in\n * an incident declares the KEYS here — a seat add-on, a feature flag, a\n * lockdown lever, a permission — and the core catalogs that used to be\n * edited for each one read the declarations instead:\n *\n * - `plan-entitlements` folds every registered seat add-on into\n * `resolveOrgEntitlements` (a quota raised per unit, features switched on)\n * and answers a registered feature's plan defaults;\n * - `lockdown` lists a registered lever on the staff page, carries its label,\n * its staff-bypass rule and its visitor notice, and maps the API paths it\n * names onto it for the plugin dispatcher;\n * - `plugin-permissions` receives the permissions with the owner filled in;\n * - `org-permissions` folds every declared catalog key into the org\n * permission catalog — the role editor, custom roles, per-member overrides\n * and the rules stamp — and `host-permissions` decides the keys that\n * declare host-role defaults for a site collaborator, per site.\n *\n * The NUMBERS stay where they are checked. A seat add-on's price is a row in\n * `PLAN_PRICING`, read by the Stripe wiring and reconciled by\n * `check-pricing-drift`; a declaration names the quota it widens and by how\n * much per plan, and nothing here restates a price.\n *\n * Registration order is deterministic: the catalog order of\n * `FIRST_PARTY_PLUGINS`, then any other id alphabetically. Plugin modules\n * load in parallel, so the order they REGISTER in is whatever the network\n * gave, and a list that followed it would put the staff lockdown checklist\n * in a different order per session.\n */\n\nimport type { AglynOrgBilling, HostAccessRole, OrgPlan, OrgRole } from '../foundation'\nimport { declarationRoleDefaults } from '../app-utils/org-role-grants'\nimport { FIRST_PARTY_PLUGINS } from './enabled-plugins'\nimport {\n listPluginPermissions,\n registerPluginPermissions,\n type PluginPermission,\n} from './plugin-permissions'\n\nexport interface PluginSeatAddonDeclaration {\n /** The `org.seatAddons` key the purchase is stored under (`aiAddon`). */\n key: string\n label: string\n /**\n * How many purchased units count. `1` for an org-wide add-on that is\n * bought once, where a doubled webhook item or a hand edit above one is\n * still one purchase; absent to count the stored quantity.\n */\n maxUnits?: number\n /**\n * The quota each unit widens: the resolved entitlement named by `key`\n * gains `perUnit(org, plan) × units` when the figure depends on WHAT was\n * bought (the Aglyn AI tier, AGL-3965), else `perUnitByPlan[plan] × units`.\n * A plan the add-on is not sold on answers 0.\n */\n quota?: {\n key: string\n perUnitByPlan?: Readonly<Record<OrgPlan, number>>\n /**\n * The per-unit figure read off the org itself. `org` is the billing\n * document as `resolveOrgEntitlements` received it and `plan` its\n * effective plan.\n */\n perUnit?: (org: Readonly<Partial<AglynOrgBilling>>, plan: OrgPlan) => number\n }\n /** Feature flags a purchased unit switches on. */\n features?: readonly string[]\n /**\n * Whether a plan sells the add-on, when `perUnitByPlan` cannot say so\n * (a `perUnit` quota, AGL-3965). Absent: sold where `perUnitByPlan` names\n * a figure above zero, or everywhere for an add-on with no quota.\n */\n soldOn?: (plan: OrgPlan) => boolean\n}\n\n/**\n * Whether a plan sells a declared seat add-on: its own `soldOn`, else a\n * `perUnitByPlan` figure above zero for the plan, else (no quota) yes.\n */\nexport function pluginSeatAddonSoldOn(\n addon: PluginSeatAddonDeclaration,\n plan: OrgPlan,\n): boolean {\n if (addon.soldOn) return addon.soldOn(plan)\n if (!addon.quota) return true\n return (addon.quota.perUnitByPlan?.[plan] ?? 0) > 0\n}\n\nexport interface PluginFeatureDeclaration {\n /** The `OrgFeatureFlags` key. */\n key: string\n label: string\n /**\n * The plan defaults, when the key is not one the plan tables already\n * carry. Absent means the plan tables decide, which is the case for every\n * key that predates this registry.\n */\n defaultByPlan?: Readonly<Partial<Record<OrgPlan, boolean>>>\n}\n\nexport interface PluginLockdownFeatureDeclaration {\n /** The lever's wire identity (`ai-generate`). */\n key: string\n /** The staff checklist's label. */\n label: string\n /**\n * What the lever is called in the customer's mail when staff pull it for\n * their workspace (`media uploads`, `AI generation`). A noun phrase that\n * reads right mid-sentence (\"our team paused media uploads\") and after a\n * colon, so lowercase unless it starts with a name or an acronym. The\n * staff `label` never reaches a customer.\n */\n customerName: string\n /**\n * Whether a verified staff claim passes the lock. Granted where a staff\n * action aids incident response — one real call proves a provider is back\n * — and withheld where the staff action would BE the incident.\n */\n staffBypass: boolean\n /**\n * What a visitor reads while the lever is pulled: what is paused AND what\n * still works. The expected-back window is appended by the notice builder.\n */\n notice: { title: string; body: string }\n /**\n * Plugin API paths the lever gates at the dispatcher: exact paths, and\n * prefixes matched on a segment boundary (`ai/generate` also gates\n * `ai/generate/section`, never `ai/generated-report`).\n */\n apiPaths?: { exact?: readonly string[]; prefixes?: readonly string[] }\n}\n\n/**\n * A key a plugin adds to the org permission CATALOG (AGL-2984): the granular\n * map custom roles and per-member overrides are stored in, that\n * `resolveOrgPermissions` layers and the rules stamp carries, and that the\n * role editor lists. A declared key is stored, layered and resolved exactly\n * like a core key; the declaration supplies what a core key's catalog entry\n * and role table supply.\n */\nexport interface PluginOrgPermissionDeclaration {\n /** The dotted key a custom role and a per-member override store (`reviews.reply`). */\n key: string\n /** The role editor's line for the key, and the word a refusal names. */\n label: string\n /** What the key opens, under the label in the role editor. */\n description: string\n /** Each org role's verdict when no custom role or per-member override sets the key. */\n roleDefaults: Readonly<Record<OrgRole, boolean>>\n /**\n * Each HOST role's verdict, for a key a site collaborator holds per site.\n *\n * A collaborator's membership carries no org standing to refine — it\n * exists only to carry access to named sites — so a key with this field is\n * decided for them on the site a request names: the host role they hold\n * there, refined by the per-site toggle on their member document. A key\n * without it is never held by a collaborator.\n */\n hostRoleDefaults?: Readonly<Record<HostAccessRole, boolean>>\n /**\n * The role editor's group for the key (AGL-4047): a core group id\n * (`CORE_ORG_PERMISSION_GROUPS`) or, absent, a group of the plugin's own.\n */\n group?: string\n /** The heading of a group of the plugin's own; absent: the plugin's catalog label. */\n groupLabel?: string\n /**\n * A broader key this one is a finer part of (AGL-4047): never granted\n * without it, and following it where nothing sets this key. See\n * `PluginPermission.refines`.\n */\n refines?: string\n /**\n * A key this one takes its verdict from where nothing sets it, without\n * needing it (AGL-4047). See `PluginPermission.follows`.\n */\n follows?: string\n /**\n * A site can narrow this key, and the built-in roles' default for whether\n * it does (AGL-4047). See `PluginPermission.narrowsPerSite`. Ignored on a\n * key whose preset is the site role (`presetFromSiteRole`).\n */\n narrowsPerSite?: boolean | Partial<Record<OrgRole, boolean>>\n /**\n * The key's preset is the member's role ON THE SITE, for every member\n * (AGL-4047), not only for a site collaborator: the owner and admins are\n * admins of every site, a workspace-wide editor or viewer holds their\n * workspace role on a site unless the site gives them other access there\n * (narrower or wider), and a collaborator holds their site role. So the\n * key reads `hostRoleDefaults` for whatever access the member has on the\n * site a request names, exactly as a gate on that host role did, and a\n * custom role, the member's own permissions and that site's toggle then\n * grant or refuse it like any other key. Needs `hostRoleDefaults`, and\n * `roleDefaults` that match them tier for tier (the owner and admins on\n * Admin, editors on Editor, viewers on Viewer), which is the answer with\n * no site named.\n *\n * For a key that replaces a gate on the site role (who may edit a site's\n * stays, say), so the built-in roles keep exactly the access they had\n * while the key becomes grantable and deniable like every other.\n */\n presetFromSiteRole?: boolean\n /**\n * With `presetFromSiteRole`: the site role is the preset only for a member\n * of the WHOLE workspace (AGL-4047). Someone added to one site only holds\n * the key there when the site's toggle grants it, whatever their site role,\n * and `hostRoleDefaults` is not their default. For a key that replaces a\n * gate asking for an admin of the whole workspace who is also this site's\n * admin (refunds, say): a site's Members card can make a contractor the\n * admin of one site, and that never carried those acts.\n */\n workspaceMembersOnly?: boolean\n}\n\n/**\n * One key of the ONE permission catalog that a plugin contributes (AGL-4047),\n * whichever of the two declaration APIs it came through:\n * `registerPluginEntitlements({ orgPermissions })` (`source: 'catalog'`) or\n * `registerPluginPermissions` (`source: 'tier'`, its per-tier defaults read\n * as org-role defaults, the owner on the admin tier).\n */\nexport interface PluginCatalogPermission {\n key: string\n label: string\n description: string\n pluginId: string\n roleDefaults: Readonly<Record<OrgRole, boolean>>\n hostRoleDefaults?: Readonly<Record<HostAccessRole, boolean>>\n group: string\n groupLabel: string\n source: 'catalog' | 'tier'\n /** The broader key this one refines, when it does. */\n refines?: string\n /** The key this one follows without needing it, when it does. */\n follows?: string\n /**\n * Present when a site can narrow the key (AGL-4047): each built-in role's\n * default for whether it does, normalized from the declaration.\n */\n narrowsPerSite?: Readonly<Record<OrgRole, boolean>>\n /** The key's preset is the member's role on the site (AGL-4047); see the declaration's. */\n presetFromSiteRole?: true\n /** That preset holds for members of the whole workspace only (AGL-4047); see the declaration's. */\n workspaceMembersOnly?: true\n}\n\nexport interface PluginEntitlementRegistration {\n pluginId: string\n seatAddons?: readonly PluginSeatAddonDeclaration[]\n features?: readonly PluginFeatureDeclaration[]\n lockdownFeatures?: readonly PluginLockdownFeatureDeclaration[]\n /** Per-tier keys a plugin's own pages read (`registerPluginPermissions`). */\n permissions?: readonly Omit<PluginPermission, 'pluginId'>[]\n /** Keys added to the org permission catalog — see {@link PluginOrgPermissionDeclaration}. */\n orgPermissions?: readonly PluginOrgPermissionDeclaration[]\n}\n\n/**\n * The registrations and their listeners, held on `globalThis` rather than in\n * module `const`s (AGL-3596), as the custom field registry and the\n * declarations repair hook are (AGL-3412).\n *\n * An app registers the plugins' declarations from `instrumentation.ts`, which\n * Next compiles into a different module graph from the routes. A module-scoped\n * map was filled in the instrumentation's copy and read empty in a route's, so\n * a core route that never loaded a plugin knew none of its keys: the site\n * create door asked for `ai.generate`, read `undefined` from a catalog that\n * had never heard of it, and every guided AI start was born with the starter.\n * One map per process, under a `Symbol.for` key, is the same map in every\n * copy.\n */\nconst REGISTRY_KEY = Symbol.for('@aglyn/aglyn:plugin-entitlements')\n\ninterface PluginEntitlementsRegistry {\n registrations: Map<string, PluginEntitlementRegistration>\n /**\n * Readers of the registrations that keep a derived view in step with them —\n * every copy of the org permission catalog rebuilds itself on every\n * registration and reset, because a plugin's declarations can register\n * after a module that imported the catalog was evaluated, and in another\n * module graph's copy of this file.\n */\n listeners: Set<() => void>\n}\n\nconst globalScope = globalThis as typeof globalThis & {\n [REGISTRY_KEY]?: PluginEntitlementsRegistry\n}\n\nconst registry: PluginEntitlementsRegistry = (globalScope[REGISTRY_KEY] ??= {\n registrations: new Map(),\n listeners: new Set(),\n})\n\nconst registrations = registry.registrations\nconst listeners = registry.listeners\n\n/** Calls `listener` after every registration and reset; answers the unsubscribe. */\nexport function subscribePluginEntitlements(listener: () => void): () => void {\n listeners.add(listener)\n return () => {\n listeners.delete(listener)\n }\n}\n\nfunction notifyListeners(): void {\n for (const listener of [...listeners]) listener()\n}\n\nconst CATALOG_ORDER = new Map(\n FIRST_PARTY_PLUGINS.map((plugin, index) => [plugin.id, index]),\n)\n\nfunction catalogRank(pluginId: string): number {\n return CATALOG_ORDER.get(pluginId) ?? Number.MAX_SAFE_INTEGER\n}\n\nfunction orderedRegistrations(): PluginEntitlementRegistration[] {\n return [...registrations.values()].sort(\n (a, b) =>\n catalogRank(a.pluginId) - catalogRank(b.pluginId) ||\n a.pluginId.localeCompare(b.pluginId),\n )\n}\n\nfunction refuseStolenKeys(\n pluginId: string,\n kind: 'seat add-on' | 'lockdown feature' | 'org permission',\n keys: readonly string[],\n ownerOf: (key: string) => string | undefined,\n): void {\n for (const key of keys) {\n const owner = ownerOf(key)\n if (owner && owner !== pluginId) {\n throw new Error(\n `${kind} \"${key}\" is already declared by \"${owner}\"; refused \"${pluginId}\"`,\n )\n }\n }\n}\n\n/**\n * Idempotent per plugin — re-registration replaces that plugin's\n * declarations. A seat add-on, lockdown or catalog permission key another\n * plugin already owns refuses the whole registration: one key, one owner,\n * or the two declarations disagree about what the key means.\n */\nexport function registerPluginEntitlements(\n registration: PluginEntitlementRegistration,\n): void {\n const pluginId = registration.pluginId.trim()\n if (!pluginId) throw new Error('plugin entitlements need a pluginId')\n refuseStolenKeys(\n pluginId,\n 'seat add-on',\n (registration.seatAddons ?? []).map((entry) => entry.key),\n (key) => pluginSeatAddonOwner(key),\n )\n refuseStolenKeys(\n pluginId,\n 'lockdown feature',\n (registration.lockdownFeatures ?? []).map((entry) => entry.key),\n (key) => pluginLockdownFeatureOwner(key),\n )\n refuseStolenKeys(\n pluginId,\n 'org permission',\n (registration.orgPermissions ?? []).map((entry) => entry.key),\n (key) => pluginOrgPermissionOwner(key) ?? pluginTierPermissionOwner(key),\n )\n registrations.set(pluginId, { ...registration, pluginId })\n if (registration.permissions?.length) {\n registerPluginPermissions(\n registration.permissions.map((permission) => ({ ...permission, pluginId })),\n )\n }\n notifyListeners()\n}\n\nfunction pluginSeatAddonOwner(key: string): string | undefined {\n for (const entry of registrations.values()) {\n if (entry.seatAddons?.some((addon) => addon.key === key)) return entry.pluginId\n }\n return undefined\n}\n\nfunction pluginLockdownFeatureOwner(key: string): string | undefined {\n for (const entry of registrations.values()) {\n if (entry.lockdownFeatures?.some((feature) => feature.key === key)) {\n return entry.pluginId\n }\n }\n return undefined\n}\n\nfunction pluginOrgPermissionOwner(key: string): string | undefined {\n for (const entry of registrations.values()) {\n if (entry.orgPermissions?.some((permission) => permission.key === key)) {\n return entry.pluginId\n }\n }\n return undefined\n}\n\nfunction pluginTierPermissionOwner(key: string): string | undefined {\n return listPluginPermissions().find((permission) => permission.key === key)?.pluginId\n}\n\n/** Refusals already logged by `listPluginCatalogPermissions`, so each is reported once. */\n// boot-registry: per copy — it only de-duplicates a warning; a second compiled copy logging the same refusal once more is harmless, and nothing reads it to decide anything.\nconst reportedCatalogRefusals = new Set<string>()\n\n/** A plugin's catalog label, the heading its own permission group carries. */\nfunction pluginLabel(pluginId: string): string {\n return FIRST_PARTY_PLUGINS.find((plugin) => plugin.id === pluginId)?.label ?? pluginId\n}\n\n/**\n * A declaration's `narrowsPerSite`, normalized to each built-in role's\n * default (AGL-4047): `true` or `false` names every role, a map names each,\n * a role it leaves out keeps. Absent: the key is not one a site can narrow.\n */\nfunction narrowingDefaultsOf(\n declared: boolean | Partial<Record<OrgRole, boolean>> | undefined,\n): { narrowsPerSite?: Readonly<Record<OrgRole, boolean>> } {\n if (declared === undefined || declared === null) return {}\n const every = typeof declared === 'boolean' ? declared : undefined\n const map = typeof declared === 'object' ? declared : {}\n return {\n narrowsPerSite: {\n owner: every ?? map.owner === true,\n admin: every ?? map.admin === true,\n editor: every ?? map.editor === true,\n viewer: every ?? map.viewer === true,\n },\n }\n}\n\n/**\n * Every key plugins contribute to the permission catalog, through EITHER\n * declaration API, in catalog order (AGL-4047): per plugin, its\n * `orgPermissions` declarations and then its `registerPluginPermissions`\n * keys. A key both APIs carry for the same plugin is the catalog\n * declaration's; one a DIFFERENT plugin already declared is refused and\n * logged once, the first declaration keeping its meaning and defaults.\n *\n * Read live: both registries fill at plugin module scope, which can be after\n * any reader of this was evaluated.\n */\nexport function listPluginCatalogPermissions(): PluginCatalogPermission[] {\n const byPlugin = new Map<string, PluginCatalogPermission[]>()\n const owner = new Map<string, string>()\n const add = (entry: PluginCatalogPermission): void => {\n const incumbent = owner.get(entry.key)\n if (incumbent !== undefined) {\n if (incumbent !== entry.pluginId) {\n const refusal = `${entry.pluginId}\\x00${entry.key}`\n if (!reportedCatalogRefusals.has(refusal)) {\n reportedCatalogRefusals.add(refusal)\n console.error(\n `[plugins] refused permission key \"${entry.key}\" to \"${entry.pluginId}\": ` +\n `already declared by \"${incumbent}\"`,\n )\n }\n }\n return\n }\n owner.set(entry.key, entry.pluginId)\n const list = byPlugin.get(entry.pluginId) ?? []\n list.push(entry)\n byPlugin.set(entry.pluginId, list)\n }\n for (const permission of listPluginOrgPermissions()) {\n add({\n key: permission.key,\n label: permission.label,\n description: permission.description,\n pluginId: permission.pluginId,\n roleDefaults: declarationRoleDefaults(permission),\n ...(permission.hostRoleDefaults ? { hostRoleDefaults: permission.hostRoleDefaults } : {}),\n group: permission.group ?? permission.pluginId,\n groupLabel: permission.groupLabel ?? pluginLabel(permission.pluginId),\n source: 'catalog',\n ...(permission.refines ? { refines: permission.refines } : {}),\n ...(permission.follows ? { follows: permission.follows } : {}),\n // A key whose preset is the site role follows every site's access\n // already, so it offers no narrowing control (AGL-4047).\n ...(permission.presetFromSiteRole && permission.hostRoleDefaults\n ? {\n presetFromSiteRole: true as const,\n ...(permission.workspaceMembersOnly ? { workspaceMembersOnly: true as const } : {}),\n }\n : narrowingDefaultsOf(permission.narrowsPerSite)),\n })\n }\n for (const permission of listPluginPermissions()) {\n add({\n key: permission.key,\n label: permission.label,\n description: permission.description ?? '',\n pluginId: permission.pluginId,\n roleDefaults: declarationRoleDefaults(permission),\n group: permission.group ?? permission.pluginId,\n groupLabel: permission.groupLabel ?? pluginLabel(permission.pluginId),\n source: 'tier',\n ...(permission.refines ? { refines: permission.refines } : {}),\n ...(permission.follows ? { follows: permission.follows } : {}),\n ...narrowingDefaultsOf(permission.narrowsPerSite),\n })\n }\n return [...byPlugin.keys()]\n .sort((a, b) => catalogRank(a) - catalogRank(b) || a.localeCompare(b))\n .flatMap((pluginId) => byPlugin.get(pluginId) ?? [])\n}\n\n/** Every declared catalog permission, in catalog order, with the plugin that declared it. */\nexport function listPluginOrgPermissions(): Array<\n PluginOrgPermissionDeclaration & { pluginId: string }\n> {\n return orderedRegistrations().flatMap((entry) =>\n (entry.orgPermissions ?? []).map((permission) => ({\n ...permission,\n pluginId: entry.pluginId,\n })),\n )\n}\n\n/** Every declared seat add-on, in catalog order. */\nexport function listPluginSeatAddons(): PluginSeatAddonDeclaration[] {\n return orderedRegistrations().flatMap((entry) => [...(entry.seatAddons ?? [])])\n}\n\n/** One declared seat add-on by its `seatAddons` key. */\nexport function pluginSeatAddon(key: string): PluginSeatAddonDeclaration | undefined {\n return listPluginSeatAddons().find((entry) => entry.key === key)\n}\n\n/** Every declared feature, in catalog order. */\nexport function listPluginFeatures(): PluginFeatureDeclaration[] {\n return orderedRegistrations().flatMap((entry) => [...(entry.features ?? [])])\n}\n\n/** Every declared lockdown lever, in catalog order. */\nexport function listPluginLockdownFeatures(): PluginLockdownFeatureDeclaration[] {\n return orderedRegistrations().flatMap((entry) => [\n ...(entry.lockdownFeatures ?? []),\n ])\n}\n\n/** One declared lockdown lever by key. */\nexport function pluginLockdownFeature(\n key: string,\n): PluginLockdownFeatureDeclaration | undefined {\n return listPluginLockdownFeatures().find((entry) => entry.key === key)\n}\n\n/** The plugin that declared a lockdown lever, for attribution. */\nexport function pluginIdForLockdownFeature(key: string): string | undefined {\n return pluginLockdownFeatureOwner(key)\n}\n\n/** Every registration, in catalog order. */\nexport function listPluginEntitlementRegistrations(): PluginEntitlementRegistration[] {\n return orderedRegistrations()\n}\n\n/**\n * Test seam: forget every registration. The per-tier permissions stay\n * registered; the catalog permissions go with their registrations.\n */\nexport function resetPluginEntitlementsForTests(): void {\n registrations.clear()\n notifyListeners()\n}\n"],"names":["globalScope","REGISTRY_KEY","declarationRoleDefaults","FIRST_PARTY_PLUGINS","listPluginPermissions","registerPluginPermissions","pluginSeatAddonSoldOn","addon","plan","soldOn","quota","perUnitByPlan","Symbol","for","globalThis","registry","registrations","Map","listeners","Set","subscribePluginEntitlements","listener","add","delete","notifyListeners","CATALOG_ORDER","map","plugin","index","id","catalogRank","pluginId","get","Number","MAX_SAFE_INTEGER","orderedRegistrations","values","sort","a","b","localeCompare","refuseStolenKeys","kind","keys","ownerOf","key","owner","Error","registerPluginEntitlements","registration","trim","seatAddons","entry","pluginSeatAddonOwner","lockdownFeatures","pluginLockdownFeatureOwner","orgPermissions","pluginOrgPermissionOwner","pluginTierPermissionOwner","set","permissions","length","permission","some","undefined","feature","find","reportedCatalogRefusals","pluginLabel","label","narrowingDefaultsOf","declared","every","narrowsPerSite","admin","editor","viewer","listPluginCatalogPermissions","byPlugin","incumbent","refusal","has","console","error","list","push","listPluginOrgPermissions","description","roleDefaults","hostRoleDefaults","group","groupLabel","source","refines","follows","presetFromSiteRole","workspaceMembersOnly","flatMap","listPluginSeatAddons","pluginSeatAddon","listPluginFeatures","features","listPluginLockdownFeatures","pluginLockdownFeature","pluginIdForLockdownFeature","listPluginEntitlementRegistrations","resetPluginEntitlementsForTests","clear"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC;IAqQ6CA,cAAYC,eAAZD;AAlQ9C,SAASE,uBAAuB,QAAQ,kCAA8B;AACtE,SAASC,mBAAmB,QAAQ,uBAAmB;AACvD,SACEC,qBAAqB,EACrBC,yBAAyB,QAEpB,0BAAsB;AAsC7B;;;CAGC,GACD,OAAO,SAASC,sBACdC,KAAiC,EACjCC,IAAa;;QAILD;IAFR,IAAIA,MAAME,MAAM,EAAE,OAAOF,MAAME,MAAM,CAACD;IACtC,IAAI,CAACD,MAAMG,KAAK,EAAE,OAAO;IACzB,OAAO,UAACH,6BAAAA,MAAMG,KAAK,CAACC,aAAa,qBAAzBJ,0BAA2B,CAACC,KAAK,mBAAI,KAAK;AACpD;AA2KA;;;;;;;;;;;;;CAaC,GACD,MAAMP,eAAeW,OAAOC,GAAG,CAAC;AAchC,MAAMb,cAAcc;AAIpB,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":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-entitlements.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 * Plugin-declared billing and access keys (AGL-2940).\n *\n * A plugin that sells something, gates something, or can be switched off in\n * an incident declares the KEYS here — a seat add-on, a feature flag, a\n * lockdown lever, a permission — and the core catalogs that used to be\n * edited for each one read the declarations instead:\n *\n * - `plan-entitlements` folds every registered seat add-on into\n * `resolveOrgEntitlements` (a quota raised per unit, features switched on)\n * and answers a registered feature's plan defaults;\n * - `lockdown` lists a registered lever on the staff page, carries its label,\n * its staff-bypass rule and its visitor notice, and maps the API paths it\n * names onto it for the plugin dispatcher;\n * - `plugin-permissions` receives the permissions with the owner filled in;\n * - `org-permissions` folds every declared catalog key into the org\n * permission catalog — the role editor, custom roles, per-member overrides\n * and the rules stamp — and `host-permissions` decides the keys that\n * declare host-role defaults for a site collaborator, per site.\n *\n * The NUMBERS stay where they are checked. A seat add-on's price is a row in\n * `PLAN_PRICING`, read by the Stripe wiring and reconciled by\n * `check-pricing-drift`; a declaration names the quota it widens and by how\n * much per plan, and nothing here restates a price.\n *\n * Registration order is deterministic: the catalog order of\n * `FIRST_PARTY_PLUGINS`, then any other id alphabetically. Plugin modules\n * load in parallel, so the order they REGISTER in is whatever the network\n * gave, and a list that followed it would put the staff lockdown checklist\n * in a different order per session.\n */\n\nimport type { AglynOrgBilling, HostAccessRole, OrgPlan, OrgRole } from '../foundation'\nimport { declarationRoleDefaults } from '../app-utils/org-role-grants'\nimport { FIRST_PARTY_PLUGINS } from './enabled-plugins'\nimport {\n listPluginPermissions,\n registerPluginPermissions,\n type PluginPermission,\n} from './plugin-permissions'\n\nexport interface PluginSeatAddonDeclaration {\n /** The `org.seatAddons` key the purchase is stored under (`aiAddon`). */\n key: string\n label: string\n /**\n * How many purchased units count. `1` for an org-wide add-on that is\n * bought once, where a doubled webhook item or a hand edit above one is\n * still one purchase; absent to count the stored quantity.\n */\n maxUnits?: number\n /**\n * The quota each unit widens: the resolved entitlement named by `key`\n * gains `perUnit(org, plan) × units` when the figure depends on WHAT was\n * bought (the Aglyn AI tier, AGL-3965), else `perUnitByPlan[plan] × units`.\n * A plan the add-on is not sold on answers 0.\n */\n quota?: {\n key: string\n perUnitByPlan?: Readonly<Record<OrgPlan, number>>\n /**\n * The per-unit figure read off the org itself. `org` is the billing\n * document as `resolveOrgEntitlements` received it and `plan` its\n * effective plan.\n */\n perUnit?: (org: Readonly<Partial<AglynOrgBilling>>, plan: OrgPlan) => number\n }\n /** Feature flags a purchased unit switches on. */\n features?: readonly string[]\n /**\n * Whether a plan sells the add-on, when `perUnitByPlan` cannot say so\n * (a `perUnit` quota, AGL-3965). Absent: sold where `perUnitByPlan` names\n * a figure above zero, or everywhere for an add-on with no quota.\n */\n soldOn?: (plan: OrgPlan) => boolean\n}\n\n/**\n * Whether a plan sells a declared seat add-on: its own `soldOn`, else a\n * `perUnitByPlan` figure above zero for the plan, else (no quota) yes.\n */\nexport function pluginSeatAddonSoldOn(\n addon: PluginSeatAddonDeclaration,\n plan: OrgPlan,\n): boolean {\n if (addon.soldOn) return addon.soldOn(plan)\n if (!addon.quota) return true\n return (addon.quota.perUnitByPlan?.[plan] ?? 0) > 0\n}\n\nexport interface PluginFeatureDeclaration {\n /** The `OrgFeatureFlags` key. */\n key: string\n label: string\n /**\n * The plan defaults, when the key is not one the plan tables already\n * carry. Absent means the plan tables decide, which is the case for every\n * key that predates this registry.\n */\n defaultByPlan?: Readonly<Partial<Record<OrgPlan, boolean>>>\n}\n\nexport interface PluginLockdownFeatureDeclaration {\n /** The lever's wire identity (`ai-generate`). */\n key: string\n /** The staff checklist's label. */\n label: string\n /**\n * What the lever is called in the customer's mail when staff pull it for\n * their workspace (`media uploads`, `AI generation`). A noun phrase that\n * reads right mid-sentence (\"our team paused media uploads\") and after a\n * colon, so lowercase unless it starts with a name or an acronym. The\n * staff `label` never reaches a customer.\n */\n customerName: string\n /**\n * Whether a verified staff claim passes the lock. Granted where a staff\n * action aids incident response — one real call proves a provider is back\n * — and withheld where the staff action would BE the incident.\n */\n staffBypass: boolean\n /**\n * What a visitor reads while the lever is pulled: what is paused AND what\n * still works. The expected-back window is appended by the notice builder.\n */\n notice: { title: string; body: string }\n /**\n * Plugin API paths the lever gates at the dispatcher: exact paths, and\n * prefixes matched on a segment boundary (`ai/generate` also gates\n * `ai/generate/section`, never `ai/generated-report`).\n */\n apiPaths?: { exact?: readonly string[]; prefixes?: readonly string[] }\n}\n\n/**\n * A key a plugin adds to the org permission CATALOG (AGL-2984): the granular\n * map custom roles and per-member overrides are stored in, that\n * `resolveOrgPermissions` layers and the rules stamp carries, and that the\n * role editor lists. A declared key is stored, layered and resolved exactly\n * like a core key; the declaration supplies what a core key's catalog entry\n * and role table supply.\n */\nexport interface PluginOrgPermissionDeclaration {\n /** The dotted key a custom role and a per-member override store (`reviews.reply`). */\n key: string\n /** The role editor's line for the key, and the word a refusal names. */\n label: string\n /** What the key opens, under the label in the role editor. */\n description: string\n /** Each org role's verdict when no custom role or per-member override sets the key. */\n roleDefaults: Readonly<Record<OrgRole, boolean>>\n /**\n * Each HOST role's verdict, for a key a site collaborator holds per site.\n *\n * A collaborator's membership carries no org standing to refine — it\n * exists only to carry access to named sites — so a key with this field is\n * decided for them on the site a request names: the host role they hold\n * there, refined by the per-site toggle on their member document. A key\n * without it is never held by a collaborator.\n */\n hostRoleDefaults?: Readonly<Record<HostAccessRole, boolean>>\n /**\n * The role editor's group for the key (AGL-4047): a core group id\n * (`CORE_ORG_PERMISSION_GROUPS`) or, absent, a group of the plugin's own.\n */\n group?: string\n /** The heading of a group of the plugin's own; absent: the plugin's catalog label. */\n groupLabel?: string\n /**\n * A broader key this one is a finer part of (AGL-4047): never granted\n * without it, and following it where nothing sets this key. See\n * `PluginPermission.refines`.\n */\n refines?: string\n /**\n * A key this one takes its verdict from where nothing sets it, without\n * needing it (AGL-4047). See `PluginPermission.follows`.\n */\n follows?: string\n /**\n * A site can narrow this key, and the built-in roles' default for whether\n * it does (AGL-4047). See `PluginPermission.narrowsPerSite`. Ignored on a\n * key whose preset is the site role (`presetFromSiteRole`).\n */\n narrowsPerSite?: boolean | Partial<Record<OrgRole, boolean>>\n /**\n * A site can also RAISE this key (AGL-4047). Where a member of the whole\n * workspace has wider access to one site than their workspace role, the key\n * reads `hostRoleDefaults` for that access there, unless a custom role or\n * their own permissions decide it or the key it `follows`. For a key that\n * narrows and raises with the site, which `presetFromSiteRole` cannot be:\n * that gives up the workspace's verdict, and with it `narrowsPerSite`'s\n * \"Keep this permission\". Needs `hostRoleDefaults`.\n */\n raisesPerSite?: boolean\n /**\n * The key's preset is the member's role ON THE SITE, for every member\n * (AGL-4047), not only for a site collaborator: the owner and admins are\n * admins of every site, a workspace-wide editor or viewer holds their\n * workspace role on a site unless the site gives them other access there\n * (narrower or wider), and a collaborator holds their site role. So the\n * key reads `hostRoleDefaults` for whatever access the member has on the\n * site a request names, exactly as a gate on that host role did, and a\n * custom role, the member's own permissions and that site's toggle then\n * grant or refuse it like any other key. Needs `hostRoleDefaults`, and\n * `roleDefaults` that match them tier for tier (the owner and admins on\n * Admin, editors on Editor, viewers on Viewer), which is the answer with\n * no site named.\n *\n * For a key that replaces a gate on the site role (who may edit a site's\n * stays, say), so the built-in roles keep exactly the access they had\n * while the key becomes grantable and deniable like every other.\n */\n presetFromSiteRole?: boolean\n /**\n * With `presetFromSiteRole`: the site role is the preset only for a member\n * of the WHOLE workspace (AGL-4047). Someone added to one site only holds\n * the key there when the site's toggle grants it, whatever their site role,\n * and `hostRoleDefaults` is not their default. For a key that replaces a\n * gate asking for an admin of the whole workspace who is also this site's\n * admin (refunds, say): a site's Members card can make a contractor the\n * admin of one site, and that never carried those acts.\n */\n workspaceMembersOnly?: boolean\n}\n\n/**\n * One key of the ONE permission catalog that a plugin contributes (AGL-4047),\n * whichever of the two declaration APIs it came through:\n * `registerPluginEntitlements({ orgPermissions })` (`source: 'catalog'`) or\n * `registerPluginPermissions` (`source: 'tier'`, its per-tier defaults read\n * as org-role defaults, the owner on the admin tier).\n */\nexport interface PluginCatalogPermission {\n key: string\n label: string\n description: string\n pluginId: string\n roleDefaults: Readonly<Record<OrgRole, boolean>>\n hostRoleDefaults?: Readonly<Record<HostAccessRole, boolean>>\n group: string\n groupLabel: string\n source: 'catalog' | 'tier'\n /** The broader key this one refines, when it does. */\n refines?: string\n /** The key this one follows without needing it, when it does. */\n follows?: string\n /**\n * Present when a site can narrow the key (AGL-4047): each built-in role's\n * default for whether it does, normalized from the declaration.\n */\n narrowsPerSite?: Readonly<Record<OrgRole, boolean>>\n /** A site can raise the key (AGL-4047); see the declaration's. */\n raisesPerSite?: true\n /** The key's preset is the member's role on the site (AGL-4047); see the declaration's. */\n presetFromSiteRole?: true\n /** That preset holds for members of the whole workspace only (AGL-4047); see the declaration's. */\n workspaceMembersOnly?: true\n}\n\nexport interface PluginEntitlementRegistration {\n pluginId: string\n seatAddons?: readonly PluginSeatAddonDeclaration[]\n features?: readonly PluginFeatureDeclaration[]\n lockdownFeatures?: readonly PluginLockdownFeatureDeclaration[]\n /** Per-tier keys a plugin's own pages read (`registerPluginPermissions`). */\n permissions?: readonly Omit<PluginPermission, 'pluginId'>[]\n /** Keys added to the org permission catalog — see {@link PluginOrgPermissionDeclaration}. */\n orgPermissions?: readonly PluginOrgPermissionDeclaration[]\n}\n\n/**\n * The registrations and their listeners, held on `globalThis` rather than in\n * module `const`s (AGL-3596), as the custom field registry and the\n * declarations repair hook are (AGL-3412).\n *\n * An app registers the plugins' declarations from `instrumentation.ts`, which\n * Next compiles into a different module graph from the routes. A module-scoped\n * map was filled in the instrumentation's copy and read empty in a route's, so\n * a core route that never loaded a plugin knew none of its keys: the site\n * create door asked for `ai.generate`, read `undefined` from a catalog that\n * had never heard of it, and every guided AI start was born with the starter.\n * One map per process, under a `Symbol.for` key, is the same map in every\n * copy.\n */\nconst REGISTRY_KEY = Symbol.for('@aglyn/aglyn:plugin-entitlements')\n\ninterface PluginEntitlementsRegistry {\n registrations: Map<string, PluginEntitlementRegistration>\n /**\n * Readers of the registrations that keep a derived view in step with them —\n * every copy of the org permission catalog rebuilds itself on every\n * registration and reset, because a plugin's declarations can register\n * after a module that imported the catalog was evaluated, and in another\n * module graph's copy of this file.\n */\n listeners: Set<() => void>\n}\n\nconst globalScope = globalThis as typeof globalThis & {\n [REGISTRY_KEY]?: PluginEntitlementsRegistry\n}\n\nconst registry: PluginEntitlementsRegistry = (globalScope[REGISTRY_KEY] ??= {\n registrations: new Map(),\n listeners: new Set(),\n})\n\nconst registrations = registry.registrations\nconst listeners = registry.listeners\n\n/** Calls `listener` after every registration and reset; answers the unsubscribe. */\nexport function subscribePluginEntitlements(listener: () => void): () => void {\n listeners.add(listener)\n return () => {\n listeners.delete(listener)\n }\n}\n\nfunction notifyListeners(): void {\n for (const listener of [...listeners]) listener()\n}\n\nconst CATALOG_ORDER = new Map(\n FIRST_PARTY_PLUGINS.map((plugin, index) => [plugin.id, index]),\n)\n\nfunction catalogRank(pluginId: string): number {\n return CATALOG_ORDER.get(pluginId) ?? Number.MAX_SAFE_INTEGER\n}\n\nfunction orderedRegistrations(): PluginEntitlementRegistration[] {\n return [...registrations.values()].sort(\n (a, b) =>\n catalogRank(a.pluginId) - catalogRank(b.pluginId) ||\n a.pluginId.localeCompare(b.pluginId),\n )\n}\n\nfunction refuseStolenKeys(\n pluginId: string,\n kind: 'seat add-on' | 'lockdown feature' | 'org permission',\n keys: readonly string[],\n ownerOf: (key: string) => string | undefined,\n): void {\n for (const key of keys) {\n const owner = ownerOf(key)\n if (owner && owner !== pluginId) {\n throw new Error(\n `${kind} \"${key}\" is already declared by \"${owner}\"; refused \"${pluginId}\"`,\n )\n }\n }\n}\n\n/**\n * Idempotent per plugin — re-registration replaces that plugin's\n * declarations. A seat add-on, lockdown or catalog permission key another\n * plugin already owns refuses the whole registration: one key, one owner,\n * or the two declarations disagree about what the key means.\n */\nexport function registerPluginEntitlements(\n registration: PluginEntitlementRegistration,\n): void {\n const pluginId = registration.pluginId.trim()\n if (!pluginId) throw new Error('plugin entitlements need a pluginId')\n refuseStolenKeys(\n pluginId,\n 'seat add-on',\n (registration.seatAddons ?? []).map((entry) => entry.key),\n (key) => pluginSeatAddonOwner(key),\n )\n refuseStolenKeys(\n pluginId,\n 'lockdown feature',\n (registration.lockdownFeatures ?? []).map((entry) => entry.key),\n (key) => pluginLockdownFeatureOwner(key),\n )\n refuseStolenKeys(\n pluginId,\n 'org permission',\n (registration.orgPermissions ?? []).map((entry) => entry.key),\n (key) => pluginOrgPermissionOwner(key) ?? pluginTierPermissionOwner(key),\n )\n registrations.set(pluginId, { ...registration, pluginId })\n if (registration.permissions?.length) {\n registerPluginPermissions(\n registration.permissions.map((permission) => ({ ...permission, pluginId })),\n )\n }\n notifyListeners()\n}\n\nfunction pluginSeatAddonOwner(key: string): string | undefined {\n for (const entry of registrations.values()) {\n if (entry.seatAddons?.some((addon) => addon.key === key)) return entry.pluginId\n }\n return undefined\n}\n\nfunction pluginLockdownFeatureOwner(key: string): string | undefined {\n for (const entry of registrations.values()) {\n if (entry.lockdownFeatures?.some((feature) => feature.key === key)) {\n return entry.pluginId\n }\n }\n return undefined\n}\n\nfunction pluginOrgPermissionOwner(key: string): string | undefined {\n for (const entry of registrations.values()) {\n if (entry.orgPermissions?.some((permission) => permission.key === key)) {\n return entry.pluginId\n }\n }\n return undefined\n}\n\nfunction pluginTierPermissionOwner(key: string): string | undefined {\n return listPluginPermissions().find((permission) => permission.key === key)?.pluginId\n}\n\n/** Refusals already logged by `listPluginCatalogPermissions`, so each is reported once. */\n// boot-registry: per copy — it only de-duplicates a warning; a second compiled copy logging the same refusal once more is harmless, and nothing reads it to decide anything.\nconst reportedCatalogRefusals = new Set<string>()\n\n/** A plugin's catalog label, the heading its own permission group carries. */\nfunction pluginLabel(pluginId: string): string {\n return FIRST_PARTY_PLUGINS.find((plugin) => plugin.id === pluginId)?.label ?? pluginId\n}\n\n/**\n * A declaration's `narrowsPerSite`, normalized to each built-in role's\n * default (AGL-4047): `true` or `false` names every role, a map names each,\n * a role it leaves out keeps. Absent: the key is not one a site can narrow.\n */\nfunction narrowingDefaultsOf(\n declared: boolean | Partial<Record<OrgRole, boolean>> | undefined,\n): { narrowsPerSite?: Readonly<Record<OrgRole, boolean>> } {\n if (declared === undefined || declared === null) return {}\n const every = typeof declared === 'boolean' ? declared : undefined\n const map = typeof declared === 'object' ? declared : {}\n return {\n narrowsPerSite: {\n owner: every ?? map.owner === true,\n admin: every ?? map.admin === true,\n editor: every ?? map.editor === true,\n viewer: every ?? map.viewer === true,\n },\n }\n}\n\n/**\n * Every key plugins contribute to the permission catalog, through EITHER\n * declaration API, in catalog order (AGL-4047): per plugin, its\n * `orgPermissions` declarations and then its `registerPluginPermissions`\n * keys. A key both APIs carry for the same plugin is the catalog\n * declaration's; one a DIFFERENT plugin already declared is refused and\n * logged once, the first declaration keeping its meaning and defaults.\n *\n * Read live: both registries fill at plugin module scope, which can be after\n * any reader of this was evaluated.\n */\nexport function listPluginCatalogPermissions(): PluginCatalogPermission[] {\n const byPlugin = new Map<string, PluginCatalogPermission[]>()\n const owner = new Map<string, string>()\n const add = (entry: PluginCatalogPermission): void => {\n const incumbent = owner.get(entry.key)\n if (incumbent !== undefined) {\n if (incumbent !== entry.pluginId) {\n const refusal = `${entry.pluginId}\\x00${entry.key}`\n if (!reportedCatalogRefusals.has(refusal)) {\n reportedCatalogRefusals.add(refusal)\n console.error(\n `[plugins] refused permission key \"${entry.key}\" to \"${entry.pluginId}\": ` +\n `already declared by \"${incumbent}\"`,\n )\n }\n }\n return\n }\n owner.set(entry.key, entry.pluginId)\n const list = byPlugin.get(entry.pluginId) ?? []\n list.push(entry)\n byPlugin.set(entry.pluginId, list)\n }\n for (const permission of listPluginOrgPermissions()) {\n add({\n key: permission.key,\n label: permission.label,\n description: permission.description,\n pluginId: permission.pluginId,\n roleDefaults: declarationRoleDefaults(permission),\n ...(permission.hostRoleDefaults ? { hostRoleDefaults: permission.hostRoleDefaults } : {}),\n group: permission.group ?? permission.pluginId,\n groupLabel: permission.groupLabel ?? pluginLabel(permission.pluginId),\n source: 'catalog',\n ...(permission.refines ? { refines: permission.refines } : {}),\n ...(permission.follows ? { follows: permission.follows } : {}),\n // A key whose preset is the site role follows every site's access\n // already, so it offers no narrowing control (AGL-4047).\n ...(permission.presetFromSiteRole && permission.hostRoleDefaults\n ? {\n presetFromSiteRole: true as const,\n ...(permission.workspaceMembersOnly ? { workspaceMembersOnly: true as const } : {}),\n }\n : narrowingDefaultsOf(permission.narrowsPerSite)),\n ...(permission.raisesPerSite && permission.hostRoleDefaults && !permission.presetFromSiteRole\n ? { raisesPerSite: true as const }\n : {}),\n })\n }\n for (const permission of listPluginPermissions()) {\n add({\n key: permission.key,\n label: permission.label,\n description: permission.description ?? '',\n pluginId: permission.pluginId,\n roleDefaults: declarationRoleDefaults(permission),\n group: permission.group ?? permission.pluginId,\n groupLabel: permission.groupLabel ?? pluginLabel(permission.pluginId),\n source: 'tier',\n ...(permission.refines ? { refines: permission.refines } : {}),\n ...(permission.follows ? { follows: permission.follows } : {}),\n ...narrowingDefaultsOf(permission.narrowsPerSite),\n })\n }\n return [...byPlugin.keys()]\n .sort((a, b) => catalogRank(a) - catalogRank(b) || a.localeCompare(b))\n .flatMap((pluginId) => byPlugin.get(pluginId) ?? [])\n}\n\n/** Every declared catalog permission, in catalog order, with the plugin that declared it. */\nexport function listPluginOrgPermissions(): Array<\n PluginOrgPermissionDeclaration & { pluginId: string }\n> {\n return orderedRegistrations().flatMap((entry) =>\n (entry.orgPermissions ?? []).map((permission) => ({\n ...permission,\n pluginId: entry.pluginId,\n })),\n )\n}\n\n/** Every declared seat add-on, in catalog order. */\nexport function listPluginSeatAddons(): PluginSeatAddonDeclaration[] {\n return orderedRegistrations().flatMap((entry) => [...(entry.seatAddons ?? [])])\n}\n\n/** One declared seat add-on by its `seatAddons` key. */\nexport function pluginSeatAddon(key: string): PluginSeatAddonDeclaration | undefined {\n return listPluginSeatAddons().find((entry) => entry.key === key)\n}\n\n/** Every declared feature, in catalog order. */\nexport function listPluginFeatures(): PluginFeatureDeclaration[] {\n return orderedRegistrations().flatMap((entry) => [...(entry.features ?? [])])\n}\n\n/** Every declared lockdown lever, in catalog order. */\nexport function listPluginLockdownFeatures(): PluginLockdownFeatureDeclaration[] {\n return orderedRegistrations().flatMap((entry) => [\n ...(entry.lockdownFeatures ?? []),\n ])\n}\n\n/** One declared lockdown lever by key. */\nexport function pluginLockdownFeature(\n key: string,\n): PluginLockdownFeatureDeclaration | undefined {\n return listPluginLockdownFeatures().find((entry) => entry.key === key)\n}\n\n/** The plugin that declared a lockdown lever, for attribution. */\nexport function pluginIdForLockdownFeature(key: string): string | undefined {\n return pluginLockdownFeatureOwner(key)\n}\n\n/** Every registration, in catalog order. */\nexport function listPluginEntitlementRegistrations(): PluginEntitlementRegistration[] {\n return orderedRegistrations()\n}\n\n/**\n * Test seam: forget every registration. The per-tier permissions stay\n * registered; the catalog permissions go with their registrations.\n */\nexport function resetPluginEntitlementsForTests(): void {\n registrations.clear()\n notifyListeners()\n}\n"],"names":["globalScope","REGISTRY_KEY","declarationRoleDefaults","FIRST_PARTY_PLUGINS","listPluginPermissions","registerPluginPermissions","pluginSeatAddonSoldOn","addon","plan","soldOn","quota","perUnitByPlan","Symbol","for","globalThis","registry","registrations","Map","listeners","Set","subscribePluginEntitlements","listener","add","delete","notifyListeners","CATALOG_ORDER","map","plugin","index","id","catalogRank","pluginId","get","Number","MAX_SAFE_INTEGER","orderedRegistrations","values","sort","a","b","localeCompare","refuseStolenKeys","kind","keys","ownerOf","key","owner","Error","registerPluginEntitlements","registration","trim","seatAddons","entry","pluginSeatAddonOwner","lockdownFeatures","pluginLockdownFeatureOwner","orgPermissions","pluginOrgPermissionOwner","pluginTierPermissionOwner","set","permissions","length","permission","some","undefined","feature","find","reportedCatalogRefusals","pluginLabel","label","narrowingDefaultsOf","declared","every","narrowsPerSite","admin","editor","viewer","listPluginCatalogPermissions","byPlugin","incumbent","refusal","has","console","error","list","push","listPluginOrgPermissions","description","roleDefaults","hostRoleDefaults","group","groupLabel","source","refines","follows","presetFromSiteRole","workspaceMembersOnly","raisesPerSite","flatMap","listPluginSeatAddons","pluginSeatAddon","listPluginFeatures","features","listPluginLockdownFeatures","pluginLockdownFeature","pluginIdForLockdownFeature","listPluginEntitlementRegistrations","resetPluginEntitlementsForTests","clear"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC;IAiR6CA,cAAYC,eAAZD;AA9Q9C,SAASE,uBAAuB,QAAQ,kCAA8B;AACtE,SAASC,mBAAmB,QAAQ,uBAAmB;AACvD,SACEC,qBAAqB,EACrBC,yBAAyB,QAEpB,0BAAsB;AAsC7B;;;CAGC,GACD,OAAO,SAASC,sBACdC,KAAiC,EACjCC,IAAa;;QAILD;IAFR,IAAIA,MAAME,MAAM,EAAE,OAAOF,MAAME,MAAM,CAACD;IACtC,IAAI,CAACD,MAAMG,KAAK,EAAE,OAAO;IACzB,OAAO,UAACH,6BAAAA,MAAMG,KAAK,CAACC,aAAa,qBAAzBJ,0BAA2B,CAACC,KAAK,mBAAI,KAAK;AACpD;AAuLA;;;;;;;;;;;;;CAaC,GACD,MAAMP,eAAeW,OAAOC,GAAG,CAAC;AAchC,MAAMb,cAAcc;AAIpB,MAAMC,YAAwCf,IAAAA,CAAAA,eAAAA,YAAW,CAACC,gBAAAA,aAAa,YAAzBD,IAAAA,YAAW,CAACC,cAAa,GAAK;IAC1Ee,eAAe,IAAIC;IACnB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/**
|
|
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
|
+
/** What a source is asked about. */
|
|
18
|
+
export interface PersonErasureNotesRequest {
|
|
19
|
+
/** The workspace the card is open on. */
|
|
20
|
+
orgId: string;
|
|
21
|
+
}
|
|
22
|
+
/** One thing a plugin says it keeps. */
|
|
23
|
+
export interface PersonErasureNote {
|
|
24
|
+
/** Stable, and unique for the plugin. */
|
|
25
|
+
id: string;
|
|
26
|
+
/** One plain sentence: what is kept, how, and for how long. */
|
|
27
|
+
text: string;
|
|
28
|
+
}
|
|
29
|
+
/** A note as the reader answers it, with the plugin that said it. */
|
|
30
|
+
export type PersonErasureNoteAnswer = PersonErasureNote & {
|
|
31
|
+
pluginId: string;
|
|
32
|
+
};
|
|
33
|
+
export interface PersonErasureNoteSource {
|
|
34
|
+
/** The notes for one workspace; none when it holds nothing the plugin keeps. May throw. */
|
|
35
|
+
notes(request: PersonErasureNotesRequest): Promise<readonly PersonErasureNote[]>;
|
|
36
|
+
}
|
|
37
|
+
/** Every plugin may answer; one source per plugin. */
|
|
38
|
+
export declare const PERSON_ERASURE_NOTE_SOURCES: import("./plugin-services").PluginServiceContract<PersonErasureNoteSource>;
|
|
39
|
+
/**
|
|
40
|
+
* Installs a plugin's note source. Owner = the loader's marker inside a
|
|
41
|
+
* register fn, else `options.pluginId`. Registering again replaces the
|
|
42
|
+
* plugin's earlier source.
|
|
43
|
+
*/
|
|
44
|
+
export declare function registerPersonErasureNoteSource(source: PersonErasureNoteSource, options?: {
|
|
45
|
+
pluginId?: string;
|
|
46
|
+
}): void;
|
|
47
|
+
/** Whether a note can be printed: an id and words. */
|
|
48
|
+
export declare function isPrintablePersonErasureNote(note: unknown): note is PersonErasureNote;
|
|
49
|
+
/** What every source answered for one workspace. */
|
|
50
|
+
export interface PersonErasureNotesRead {
|
|
51
|
+
notes: PersonErasureNoteAnswer[];
|
|
52
|
+
/** Plugins whose answer could not be read: the card says details are missing. */
|
|
53
|
+
unavailable: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Asks every source about one workspace. NEVER THROWS: a source that threw or
|
|
57
|
+
* answered something unprintable is listed in `unavailable`, and the rest are
|
|
58
|
+
* answered. With no source registered, runs the app's boot step once and asks
|
|
59
|
+
* again.
|
|
60
|
+
*/
|
|
61
|
+
export declare function readPersonErasureNotes(request: PersonErasureNotesRequest): Promise<PersonErasureNotesRead>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ /**
|
|
18
|
+
* WHAT A PLUGIN KEEPS THROUGH A PERSON ERASURE, said before it is filed
|
|
19
|
+
* (AGL-4042).
|
|
20
|
+
*
|
|
21
|
+
* Its sibling `plugin-person-erasure` does the erasing, and each plugin decides
|
|
22
|
+
* there what it deletes and what it keeps. The console's Erase a person card
|
|
23
|
+
* lists the platform's own removed and kept records; a plugin that keeps a
|
|
24
|
+
* record with the person still on it registers a NOTE SOURCE here, and the card
|
|
25
|
+
* prints what it answers, so the person filing hears it first.
|
|
26
|
+
*
|
|
27
|
+
* The platform owns the question and the card. What a plugin keeps, and the
|
|
28
|
+
* sentence the person reads, are the plugin's. A note is information, never a
|
|
29
|
+
* gate: nothing it answers holds an erasure back.
|
|
30
|
+
*
|
|
31
|
+
* A source answers for the workspace, not for one person, because the card is
|
|
32
|
+
* opened before an address is typed. It answers nothing when the workspace
|
|
33
|
+
* holds nothing of the kind, and otherwise words the sentence so it is true of
|
|
34
|
+
* someone with no such record.
|
|
35
|
+
*
|
|
36
|
+
* ## Not answered is said, not hidden
|
|
37
|
+
*
|
|
38
|
+
* A source that throws, or answers something that cannot be printed, is listed
|
|
39
|
+
* in `unavailable` by plugin id, and the card says some details could not be
|
|
40
|
+
* checked, so a missing note never reads as "nothing is kept". A process where
|
|
41
|
+
* no source is registered at all runs the app's boot step once more first
|
|
42
|
+
* (`plugin-declarations-repair`), as the erasures do.
|
|
43
|
+
*
|
|
44
|
+
* Logic only: the contract, the registry and the reader. The card is the
|
|
45
|
+
* console's.
|
|
46
|
+
*/ import { runPluginDeclarationsRepair } from "./plugin-declarations-repair.js";
|
|
47
|
+
import { definePluginServiceContract, registerPluginService, resolvePluginServices } from "./plugin-services.js";
|
|
48
|
+
/** Every plugin may answer; one source per plugin. */ export const PERSON_ERASURE_NOTE_SOURCES = definePluginServiceContract('core.person-erasure-notes', {
|
|
49
|
+
multiple: true
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* Installs a plugin's note source. Owner = the loader's marker inside a
|
|
53
|
+
* register fn, else `options.pluginId`. Registering again replaces the
|
|
54
|
+
* plugin's earlier source.
|
|
55
|
+
*/ export function registerPersonErasureNoteSource(source, options) {
|
|
56
|
+
if (typeof (source == null ? void 0 : source.notes) !== 'function') {
|
|
57
|
+
throw new Error('a person erasure note source needs a notes function');
|
|
58
|
+
}
|
|
59
|
+
registerPluginService(PERSON_ERASURE_NOTE_SOURCES, source, _extends({}, (options == null ? void 0 : options.pluginId) ? {
|
|
60
|
+
pluginId: options.pluginId
|
|
61
|
+
} : {}));
|
|
62
|
+
}
|
|
63
|
+
const isText = (value)=>typeof value === 'string' && value.trim().length > 0;
|
|
64
|
+
/** Whether a note can be printed: an id and words. */ export function isPrintablePersonErasureNote(note) {
|
|
65
|
+
const candidate = note;
|
|
66
|
+
return Boolean(candidate) && typeof candidate === 'object' && isText(candidate == null ? void 0 : candidate.id) && isText(candidate == null ? void 0 : candidate.text);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Asks every source about one workspace. NEVER THROWS: a source that threw or
|
|
70
|
+
* answered something unprintable is listed in `unavailable`, and the rest are
|
|
71
|
+
* answered. With no source registered, runs the app's boot step once and asks
|
|
72
|
+
* again.
|
|
73
|
+
*/ export async function readPersonErasureNotes(request) {
|
|
74
|
+
let registered = resolvePluginServices(PERSON_ERASURE_NOTE_SOURCES);
|
|
75
|
+
if (!registered.length) {
|
|
76
|
+
const repaired = await runPluginDeclarationsRepair().catch(()=>false);
|
|
77
|
+
if (repaired) registered = resolvePluginServices(PERSON_ERASURE_NOTE_SOURCES);
|
|
78
|
+
}
|
|
79
|
+
const answers = await Promise.all(registered.map(async ({ pluginId, impl })=>{
|
|
80
|
+
try {
|
|
81
|
+
const notes = await impl.notes(request);
|
|
82
|
+
if (!Array.isArray(notes) || !notes.every(isPrintablePersonErasureNote)) {
|
|
83
|
+
console.error(`[person-erasure-notes] "${pluginId}" answered a note that cannot be printed`);
|
|
84
|
+
return {
|
|
85
|
+
pluginId,
|
|
86
|
+
notes: null
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
pluginId,
|
|
91
|
+
notes: notes.map((note)=>({
|
|
92
|
+
id: note.id,
|
|
93
|
+
text: note.text,
|
|
94
|
+
pluginId
|
|
95
|
+
}))
|
|
96
|
+
};
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error(`[person-erasure-notes] "${pluginId}" could not answer`, error);
|
|
99
|
+
return {
|
|
100
|
+
pluginId,
|
|
101
|
+
notes: null
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}));
|
|
105
|
+
return {
|
|
106
|
+
notes: answers.flatMap((answer)=>{
|
|
107
|
+
var _answer_notes;
|
|
108
|
+
return (_answer_notes = answer.notes) != null ? _answer_notes : [];
|
|
109
|
+
}),
|
|
110
|
+
unavailable: answers.filter((answer)=>answer.notes === null).map((answer)=>answer.pluginId)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=plugin-person-erasure-notes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-person-erasure-notes.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 * WHAT A PLUGIN KEEPS THROUGH A PERSON ERASURE, said before it is filed\n * (AGL-4042).\n *\n * Its sibling `plugin-person-erasure` does the erasing, and each plugin decides\n * there what it deletes and what it keeps. The console's Erase a person card\n * lists the platform's own removed and kept records; a plugin that keeps a\n * record with the person still on it registers a NOTE SOURCE here, and the card\n * prints what it answers, so the person filing hears it first.\n *\n * The platform owns the question and the card. What a plugin keeps, and the\n * sentence the person reads, are the plugin's. A note is information, never a\n * gate: nothing it answers holds an erasure back.\n *\n * A source answers for the workspace, not for one person, because the card is\n * opened before an address is typed. It answers nothing when the workspace\n * holds nothing of the kind, and otherwise words the sentence so it is true of\n * someone with no such record.\n *\n * ## Not answered is said, not hidden\n *\n * A source that throws, or answers something that cannot be printed, is listed\n * in `unavailable` by plugin id, and the card says some details could not be\n * checked, so a missing note never reads as \"nothing is kept\". A process where\n * no source is registered at all runs the app's boot step once more first\n * (`plugin-declarations-repair`), as the erasures do.\n *\n * Logic only: the contract, the registry and the reader. The card is the\n * console's.\n */\n\nimport { runPluginDeclarationsRepair } from './plugin-declarations-repair'\nimport {\n definePluginServiceContract,\n registerPluginService,\n resolvePluginServices,\n} from './plugin-services'\n\n/** What a source is asked about. */\nexport interface PersonErasureNotesRequest {\n /** The workspace the card is open on. */\n orgId: string\n}\n\n/** One thing a plugin says it keeps. */\nexport interface PersonErasureNote {\n /** Stable, and unique for the plugin. */\n id: string\n /** One plain sentence: what is kept, how, and for how long. */\n text: string\n}\n\n/** A note as the reader answers it, with the plugin that said it. */\nexport type PersonErasureNoteAnswer = PersonErasureNote & { pluginId: string }\n\nexport interface PersonErasureNoteSource {\n /** The notes for one workspace; none when it holds nothing the plugin keeps. May throw. */\n notes(request: PersonErasureNotesRequest): Promise<readonly PersonErasureNote[]>\n}\n\n/** Every plugin may answer; one source per plugin. */\nexport const PERSON_ERASURE_NOTE_SOURCES = definePluginServiceContract<PersonErasureNoteSource>(\n 'core.person-erasure-notes',\n { multiple: true },\n)\n\n/**\n * Installs a plugin's note source. Owner = the loader's marker inside a\n * register fn, else `options.pluginId`. Registering again replaces the\n * plugin's earlier source.\n */\nexport function registerPersonErasureNoteSource(\n source: PersonErasureNoteSource,\n options?: { pluginId?: string },\n): void {\n if (typeof source?.notes !== 'function') {\n throw new Error('a person erasure note source needs a notes function')\n }\n registerPluginService(PERSON_ERASURE_NOTE_SOURCES, source, {\n ...(options?.pluginId ? { pluginId: options.pluginId } : {}),\n })\n}\n\nconst isText = (value: unknown): value is string => typeof value === 'string' && value.trim().length > 0\n\n/** Whether a note can be printed: an id and words. */\nexport function isPrintablePersonErasureNote(note: unknown): note is PersonErasureNote {\n const candidate = note as PersonErasureNote | null | undefined\n return Boolean(candidate) && typeof candidate === 'object' && isText(candidate?.id) && isText(candidate?.text)\n}\n\n/** What every source answered for one workspace. */\nexport interface PersonErasureNotesRead {\n notes: PersonErasureNoteAnswer[]\n /** Plugins whose answer could not be read: the card says details are missing. */\n unavailable: string[]\n}\n\n/**\n * Asks every source about one workspace. NEVER THROWS: a source that threw or\n * answered something unprintable is listed in `unavailable`, and the rest are\n * answered. With no source registered, runs the app's boot step once and asks\n * again.\n */\nexport async function readPersonErasureNotes(\n request: PersonErasureNotesRequest,\n): Promise<PersonErasureNotesRead> {\n let registered = resolvePluginServices(PERSON_ERASURE_NOTE_SOURCES)\n if (!registered.length) {\n const repaired = await runPluginDeclarationsRepair().catch(() => false)\n if (repaired) registered = resolvePluginServices(PERSON_ERASURE_NOTE_SOURCES)\n }\n const answers = await Promise.all(\n registered.map(async ({ pluginId, impl }) => {\n try {\n const notes = await impl.notes(request)\n if (!Array.isArray(notes) || !notes.every(isPrintablePersonErasureNote)) {\n console.error(`[person-erasure-notes] \"${pluginId}\" answered a note that cannot be printed`)\n return { pluginId, notes: null }\n }\n return { pluginId, notes: notes.map((note) => ({ id: note.id, text: note.text, pluginId })) }\n } catch (error) {\n console.error(`[person-erasure-notes] \"${pluginId}\" could not answer`, error)\n return { pluginId, notes: null }\n }\n }),\n )\n return {\n notes: answers.flatMap((answer) => answer.notes ?? []),\n unavailable: answers.filter((answer) => answer.notes === null).map((answer) => answer.pluginId),\n }\n}\n"],"names":["runPluginDeclarationsRepair","definePluginServiceContract","registerPluginService","resolvePluginServices","PERSON_ERASURE_NOTE_SOURCES","multiple","registerPersonErasureNoteSource","source","options","notes","Error","pluginId","isText","value","trim","length","isPrintablePersonErasureNote","note","candidate","Boolean","id","text","readPersonErasureNotes","request","registered","repaired","catch","answers","Promise","all","map","impl","Array","isArray","every","console","error","flatMap","answer","unavailable","filter"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GAED,SAASA,2BAA2B,QAAQ,kCAA8B;AAC1E,SACEC,2BAA2B,EAC3BC,qBAAqB,EACrBC,qBAAqB,QAChB,uBAAmB;AAwB1B,oDAAoD,GACpD,OAAO,MAAMC,8BAA8BH,4BACzC,6BACA;IAAEI,UAAU;AAAK,GAClB;AAED;;;;CAIC,GACD,OAAO,SAASC,gCACdC,MAA+B,EAC/BC,OAA+B;IAE/B,IAAI,QAAOD,0BAAAA,OAAQE,KAAK,MAAK,YAAY;QACvC,MAAM,IAAIC,MAAM;IAClB;IACAR,sBAAsBE,6BAA6BG,QAAQ,aACrDC,CAAAA,2BAAAA,QAASG,QAAQ,IAAG;QAAEA,UAAUH,QAAQG,QAAQ;IAAC,IAAI,CAAC;AAE9D;AAEA,MAAMC,SAAS,CAACC,QAAoC,OAAOA,UAAU,YAAYA,MAAMC,IAAI,GAAGC,MAAM,GAAG;AAEvG,oDAAoD,GACpD,OAAO,SAASC,6BAA6BC,IAAa;IACxD,MAAMC,YAAYD;IAClB,OAAOE,QAAQD,cAAc,OAAOA,cAAc,YAAYN,OAAOM,6BAAAA,UAAWE,EAAE,KAAKR,OAAOM,6BAAAA,UAAWG,IAAI;AAC/G;AASA;;;;;CAKC,GACD,OAAO,eAAeC,uBACpBC,OAAkC;IAElC,IAAIC,aAAarB,sBAAsBC;IACvC,IAAI,CAACoB,WAAWT,MAAM,EAAE;QACtB,MAAMU,WAAW,MAAMzB,8BAA8B0B,KAAK,CAAC,IAAM;QACjE,IAAID,UAAUD,aAAarB,sBAAsBC;IACnD;IACA,MAAMuB,UAAU,MAAMC,QAAQC,GAAG,CAC/BL,WAAWM,GAAG,CAAC,OAAO,EAAEnB,QAAQ,EAAEoB,IAAI,EAAE;QACtC,IAAI;YACF,MAAMtB,QAAQ,MAAMsB,KAAKtB,KAAK,CAACc;YAC/B,IAAI,CAACS,MAAMC,OAAO,CAACxB,UAAU,CAACA,MAAMyB,KAAK,CAAClB,+BAA+B;gBACvEmB,QAAQC,KAAK,CAAC,CAAC,wBAAwB,EAAEzB,SAAS,wCAAwC,CAAC;gBAC3F,OAAO;oBAAEA;oBAAUF,OAAO;gBAAK;YACjC;YACA,OAAO;gBAAEE;gBAAUF,OAAOA,MAAMqB,GAAG,CAAC,CAACb,OAAU,CAAA;wBAAEG,IAAIH,KAAKG,EAAE;wBAAEC,MAAMJ,KAAKI,IAAI;wBAAEV;oBAAS,CAAA;YAAI;QAC9F,EAAE,OAAOyB,OAAO;YACdD,QAAQC,KAAK,CAAC,CAAC,wBAAwB,EAAEzB,SAAS,kBAAkB,CAAC,EAAEyB;YACvE,OAAO;gBAAEzB;gBAAUF,OAAO;YAAK;QACjC;IACF;IAEF,OAAO;QACLA,OAAOkB,QAAQU,OAAO,CAAC,CAACC;gBAAWA;oBAAAA,gBAAAA,OAAO7B,KAAK,YAAZ6B,gBAAgB,EAAE;;QACrDC,aAAaZ,QAAQa,MAAM,CAAC,CAACF,SAAWA,OAAO7B,KAAK,KAAK,MAAMqB,GAAG,CAAC,CAACQ,SAAWA,OAAO3B,QAAQ;IAChG;AACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
/** One collection under `orgs/{orgId}` whose documents can be all-except. */
|
|
18
|
+
export interface ScopeSharingCollection {
|
|
19
|
+
/** The subcollection, spelled as Firestore holds it. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Stored fields follow `visibleTo`: a patch function is registered. */
|
|
22
|
+
patch?: boolean;
|
|
23
|
+
/** The most sites one document may reach; past it the list stops widening. */
|
|
24
|
+
maxIncluded?: number;
|
|
25
|
+
/** Fields naming sites that stay included though they are excluded. */
|
|
26
|
+
keepSiteFields?: string[];
|
|
27
|
+
}
|
|
28
|
+
/** A declaration with its owner; `core` for what the platform holds itself. */
|
|
29
|
+
export type ResolvedScopeSharingCollection = ScopeSharingCollection & {
|
|
30
|
+
pluginId: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Every collection the sweep walks, in a stable order: a sweep's cursor names
|
|
34
|
+
* a position in this list, and resuming relies on the ones before it being done.
|
|
35
|
+
*/
|
|
36
|
+
export declare function listScopeSharingCollections(): ResolvedScopeSharingCollection[];
|
|
37
|
+
/**
|
|
38
|
+
* Recomputes the fields a document derives from its scope: `next` is the whole
|
|
39
|
+
* document as it will be stored, and the answer is merged into the write.
|
|
40
|
+
*/
|
|
41
|
+
export type ScopeSharingPatch = (collection: string, next: Record<string, unknown>) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Registers the patch for collections a plugin declared with `patch: true`.
|
|
44
|
+
* Refuses a collection another plugin declared, or one declared without it.
|
|
45
|
+
*/
|
|
46
|
+
export declare function registerPluginScopeSharingPatch(collections: readonly string[], patch: ScopeSharingPatch, options?: {
|
|
47
|
+
pluginId?: string;
|
|
48
|
+
}): void;
|
|
49
|
+
/** The patch registered for a collection, or `null`. */
|
|
50
|
+
export declare function scopeSharingPatchFor(collection: string): ScopeSharingPatch | null;
|
|
51
|
+
/** Test seam: forget every patch. */
|
|
52
|
+
export declare function resetScopeSharingPatchesForTests(): void;
|