@aglyn/aglyn 1.0.0-beta.146 → 1.0.0-beta.149

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.
Files changed (37) hide show
  1. package/package.json +10 -10
  2. package/src/lib/app-utils/binding-token-catalog.js +9 -2
  3. package/src/lib/app-utils/binding-token-catalog.js.map +1 -1
  4. package/src/lib/app-utils/collection-entries.d.ts +95 -3
  5. package/src/lib/app-utils/collection-entries.js +146 -10
  6. package/src/lib/app-utils/collection-entries.js.map +1 -1
  7. package/src/lib/app-utils/console-routes.d.ts +2 -0
  8. package/src/lib/app-utils/console-routes.js +14 -0
  9. package/src/lib/app-utils/console-routes.js.map +1 -1
  10. package/src/lib/app-utils/docs-help.generated.d.ts +1 -1
  11. package/src/lib/app-utils/docs-help.generated.js +3 -0
  12. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  13. package/src/lib/app-utils/docs-index.generated.js +2 -2
  14. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  15. package/src/lib/app-utils/notifications.d.ts +136 -2
  16. package/src/lib/app-utils/notifications.js +139 -3
  17. package/src/lib/app-utils/notifications.js.map +1 -1
  18. package/src/lib/foundation/definitions/host-content-collections.d.ts +42 -40
  19. package/src/lib/foundation/definitions/host-content-collections.js +47 -109
  20. package/src/lib/foundation/definitions/host-content-collections.js.map +1 -1
  21. package/src/lib/plugin-manager/feature-plugins.d.ts +70 -0
  22. package/src/lib/plugin-manager/feature-plugins.js +27 -0
  23. package/src/lib/plugin-manager/feature-plugins.js.map +1 -1
  24. package/src/lib/plugin-manager/first-party-plugins.generated.d.ts +13 -0
  25. package/src/lib/plugin-manager/first-party-plugins.generated.js +257 -0
  26. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  27. package/src/lib/plugin-manager/plugin-contact-capture.d.ts +16 -0
  28. package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
  29. package/src/lib/plugin-manager/plugin-host-collections.d.ts +27 -5
  30. package/src/lib/plugin-manager/plugin-host-collections.js +25 -16
  31. package/src/lib/plugin-manager/plugin-host-collections.js.map +1 -1
  32. package/src/lib/plugin-manager/plugin-org-capacity.d.ts +57 -0
  33. package/src/lib/plugin-manager/plugin-org-capacity.js +68 -0
  34. package/src/lib/plugin-manager/plugin-org-capacity.js.map +1 -0
  35. package/src/lib/plugin-manager/record-captured-contact.d.ts +89 -0
  36. package/src/lib/plugin-manager/record-captured-contact.js +128 -0
  37. package/src/lib/plugin-manager/record-captured-contact.js.map +1 -0
@@ -22,7 +22,7 @@ import type { ITimestamp } from '@aglyn/shared-util-timestamp';
22
22
  * their owner. Types follow the common SaaS taxonomy so the console can
23
23
  * icon/group them without a registry.
24
24
  */
25
- export type AglynNotificationType = 'billing.invoice' | 'billing.paymentFailed' | 'billing.subscriptionCanceled' | 'billing.usage' | 'team.invite' | 'team.roleChanged' | 'team.hostAccessGranted' | 'content.formSubmission' | 'content.booking' | 'content.order' | 'content.lowStock' | 'content.taskAssigned' | 'content.taskReminder' | 'content.contactAssigned' | 'content.leadAssigned' | 'content.crmDailyDigest' | 'content.insightsDigest' | 'marketplace.review' | 'support.ticketOpened' | 'support.ticketReply' | 'system.announcement' | 'system.pluginVerifierRegression' | 'system.signInMethodRemoved' | 'system.scopeDrift' | 'system.ssoDomainUnverified' | 'system.formSubmissionsPaused' | 'system.visitorRecordsPaused' | 'system.abuseReportUrgent' | 'system.dmcaCounterNotice' | 'system.bandwidthCeilingTripped' | 'system.bandwidthCapEngaged' | 'system.billingWebhookHalfApplied' | 'system.disputeUnattributed';
25
+ export type AglynNotificationType = 'billing.invoice' | 'billing.paymentFailed' | 'billing.subscriptionCanceled' | 'billing.usage' | 'team.invite' | 'team.roleChanged' | 'team.hostAccessGranted' | 'content.formSubmission' | 'content.booking' | 'content.order' | 'content.lowStock' | 'content.taskAssigned' | 'content.taskReminder' | 'content.contactAssigned' | 'content.leadAssigned' | 'content.crmDailyDigest' | 'content.insightsDigest' | 'marketplace.review' | 'support.ticketOpened' | 'support.ticketReply' | 'system.announcement' | 'system.pluginVerifierRegression' | 'system.signInMethodRemoved' | 'system.scopeDrift' | 'system.ssoDomainUnverified' | 'system.formSubmissionsPaused' | 'system.visitorRecordsPaused' | 'system.abuseReportUrgent' | 'system.dmcaCounterNotice' | 'system.bandwidthCeilingTripped' | 'system.bandwidthCapEngaged' | 'system.billingWebhookHalfApplied' | 'system.disputeUnattributed' | 'staff.userSignedUp' | 'staff.orgCreated';
26
26
  export interface AglynNotification {
27
27
  $id?: string;
28
28
  type: AglynNotificationType;
@@ -38,8 +38,17 @@ export interface AglynNotification {
38
38
  }
39
39
  export declare const NOTIFICATION_TYPE_LABELS: Record<AglynNotificationType, string>;
40
40
  /** Preference buckets (AGL-267): the prefix before the dot. */
41
- export type NotificationCategory = 'billing' | 'team' | 'content' | 'marketplace' | 'support' | 'system';
41
+ export type NotificationCategory = 'billing' | 'team' | 'content' | 'marketplace' | 'support' | 'system' | 'staff';
42
42
  export declare const NOTIFICATION_CATEGORY_LABELS: Record<NotificationCategory, string>;
43
+ /**
44
+ * The categories only staff can receive (AGL-3225).
45
+ *
46
+ * The settings page hides these rows from everybody else, because a switch
47
+ * for mail that can never arrive is a promise the product does not keep. It
48
+ * is presentation only: `notifyStaff` is what decides the audience, and it
49
+ * enumerates the `staff` claim rather than reading this.
50
+ */
51
+ export declare const STAFF_NOTIFICATION_CATEGORIES: ReadonlySet<NotificationCategory>;
43
52
  export declare function notificationCategory(type: AglynNotificationType | string): NotificationCategory;
44
53
  /**
45
54
  * Per-user mute map stored at `users/{uid}.notificationPrefs`
@@ -69,3 +78,128 @@ export declare function crmDailyDigestEnabled(prefs: Record<string, boolean> | n
69
78
  export declare const INSIGHT_DIGESTS_FIELD = "insightDigests";
70
79
  /** Whether a person asked for a workspace's weekly insights. */
71
80
  export declare function insightDigestSubscribed(value: Record<string, boolean> | null | undefined, orgId: string): boolean;
81
+ /**
82
+ * The channels a notification can travel on (AGL-3223).
83
+ *
84
+ * `console` is the feed at `/manage/notifications` and the app-bar dropdown
85
+ * that reads it — the only channel that existed. `email` is the message the
86
+ * fan-out sends beside that doc when the recipient asked for one.
87
+ */
88
+ export type NotificationChannel = 'console' | 'email';
89
+ /**
90
+ * One scope's answer for one category. **Tri-state on purpose**: `true` and
91
+ * `false` decide, and an ABSENT key inherits from the scope above.
92
+ *
93
+ * Inheritance is the whole reason this is a partial rather than a pair of
94
+ * booleans. A person who wants form submissions from one busy site and not
95
+ * from the other five has to be able to say that about the one site without
96
+ * restating their answer for every other category at every other scope — and
97
+ * a two-valued leaf cannot express "I have not said", so every override would
98
+ * have to be written out in full and would then stop tracking the account
99
+ * default it was never meant to detach from.
100
+ */
101
+ export interface NotificationChannelPrefs {
102
+ console?: boolean;
103
+ email?: boolean;
104
+ }
105
+ export type NotificationCategoryPrefs = Partial<Record<NotificationCategory, NotificationChannelPrefs>>;
106
+ /**
107
+ * Per-scope, per-channel notification preferences (AGL-3223), stored at
108
+ * `users/{uid}.notificationSettings`.
109
+ *
110
+ * Three layers, narrowest first when resolving: the SITE a notification
111
+ * concerns, then the WORKSPACE, then the account. Anything none of them
112
+ * answers falls to {@link NOTIFICATION_CHANNEL_DEFAULTS}.
113
+ *
114
+ * ON THE USER DOCUMENT, not on `orgs/{orgId}/members/{uid}`, and that is a
115
+ * cost decision rather than a modelling preference. `notifyUsers` already
116
+ * does exactly one `getAll` over the recipients' user docs to read their
117
+ * category mutes, so every layer living here means per-site preferences are
118
+ * read for free on the fan-out's hot path. The member row would add a read
119
+ * per recipient per notification to answer a question the document already in
120
+ * hand could have answered.
121
+ */
122
+ export interface NotificationSettings {
123
+ account?: NotificationCategoryPrefs;
124
+ /** Keyed by org id. */
125
+ orgs?: Record<string, NotificationCategoryPrefs>;
126
+ /** Keyed by host id — a site's own answer, narrower than its workspace's. */
127
+ hosts?: Record<string, NotificationCategoryPrefs>;
128
+ }
129
+ export declare const NOTIFICATION_SETTINGS_FIELD = "notificationSettings";
130
+ /**
131
+ * What a category does when nobody has said otherwise.
132
+ *
133
+ * Console on, email OFF, everywhere. Email defaults off because the inbox is
134
+ * not ours to fill: the product already sends transactional mail nobody opted
135
+ * into — welcome, verification, invites, dunning, usage alerts — and every one
136
+ * of those leaves on the same domain a customer's password reset depends on.
137
+ * Turning a busy site's form submissions into mail by default would put that
138
+ * domain's reputation behind traffic the recipient never asked for.
139
+ *
140
+ * Exhaustive `Record` deliberately: a new {@link NotificationCategory} is a
141
+ * compile error here until somebody decides what it does by default, which is
142
+ * the one question a new category must not be able to ship without answering.
143
+ */
144
+ export declare const NOTIFICATION_CHANNEL_DEFAULTS: Record<NotificationCategory, Record<NotificationChannel, boolean>>;
145
+ /**
146
+ * The types that send their OWN email and must never be mailed again by the
147
+ * generic channel (AGL-3224).
148
+ *
149
+ * Both digests compose a message the fan-out could not reproduce — a day's
150
+ * owed tasks, a week's figures — and send it from their own route under their
151
+ * own switch (`digestPrefs.crmDaily`, `insightDigests.{orgId}`). A recipient
152
+ * who switches the `content` email channel on would otherwise receive the
153
+ * digest twice: once as the digest, once as a one-line "Daily CRM digest"
154
+ * notification saying that the digest happened.
155
+ */
156
+ export declare const NOTIFICATION_SELF_SENT_EMAIL_TYPES: ReadonlySet<string>;
157
+ /**
158
+ * Whether a channel is on for one notification, at its own scope.
159
+ *
160
+ * Resolution order, first answer wins: the notification's SITE, its
161
+ * WORKSPACE, the account, then {@link NOTIFICATION_CHANNEL_DEFAULTS}. A scope
162
+ * that holds no entry for the category, or an entry with the channel key
163
+ * absent, does not answer — see {@link NotificationChannelPrefs}.
164
+ *
165
+ * `legacyPrefs` is the flat `notificationPrefs` mute map this replaces
166
+ * (AGL-267), and it sits BELOW the account layer rather than beside it.
167
+ * Nothing migrates it: a person who never opens the new settings page keeps
168
+ * being governed by the mutes they set years ago, and the first thing they do
169
+ * set on the account layer overrides the old map for that category without
170
+ * disturbing the rest of it. It answers for `console` only, because the map
171
+ * predates there being a second channel and reading a console mute as an
172
+ * email preference would be inventing an answer its author never gave.
173
+ */
174
+ export declare function notificationChannelEnabled(settings: NotificationSettings | null | undefined, channel: NotificationChannel, type: AglynNotificationType | string, scope?: {
175
+ orgId?: string | null;
176
+ hostId?: string | null;
177
+ }, legacyPrefs?: Record<string, boolean> | null): boolean;
178
+ /**
179
+ * What one scope says, with no inheritance applied — what the settings page
180
+ * renders as Inherit / On / Off, and `undefined` is Inherit.
181
+ *
182
+ * `scope` names the layer directly rather than being derived from a
183
+ * notification, because the page edits a layer whether or not anything has
184
+ * ever arrived from it.
185
+ */
186
+ export declare function notificationScopePref(settings: NotificationSettings | null | undefined, scope: {
187
+ kind: 'account';
188
+ } | {
189
+ kind: 'org' | 'host';
190
+ id: string;
191
+ }, category: NotificationCategory, channel: NotificationChannel): boolean | undefined;
192
+ /**
193
+ * The scopes this person has said something different about — what the
194
+ * settings page lists so an override is never somewhere you have to go
195
+ * looking for.
196
+ *
197
+ * Returns ids, not names: the page holds the org and host rosters and this
198
+ * module holds no lookups. An id with no name is still worth listing, because
199
+ * a preference about a workspace somebody left is exactly the kind of
200
+ * leftover that is invisible until it is listed.
201
+ */
202
+ export declare function notificationOverriddenScopes(settings: NotificationSettings | null | undefined): {
203
+ orgIds: string[];
204
+ hostIds: string[];
205
+ };
@@ -46,7 +46,9 @@
46
46
  'system.bandwidthCeilingTripped': 'Bandwidth ceiling reached',
47
47
  'system.bandwidthCapEngaged': 'Monthly traffic limit reached',
48
48
  'system.billingWebhookHalfApplied': 'Billing webhook half applied',
49
- 'system.disputeUnattributed': 'Card dispute with no owner'
49
+ 'system.disputeUnattributed': 'Card dispute with no owner',
50
+ 'staff.userSignedUp': 'New account',
51
+ 'staff.orgCreated': 'New workspace'
50
52
  };
51
53
  export const NOTIFICATION_CATEGORY_LABELS = {
52
54
  billing: 'Billing',
@@ -54,8 +56,19 @@ export const NOTIFICATION_CATEGORY_LABELS = {
54
56
  content: 'Forms & bookings',
55
57
  marketplace: 'Marketplace',
56
58
  support: 'Support',
57
- system: 'Product & system'
59
+ system: 'Product & system',
60
+ staff: 'Platform growth'
58
61
  };
62
+ /**
63
+ * The categories only staff can receive (AGL-3225).
64
+ *
65
+ * The settings page hides these rows from everybody else, because a switch
66
+ * for mail that can never arrive is a promise the product does not keep. It
67
+ * is presentation only: `notifyStaff` is what decides the audience, and it
68
+ * enumerates the `staff` claim rather than reading this.
69
+ */ export const STAFF_NOTIFICATION_CATEGORIES = new Set([
70
+ 'staff'
71
+ ]);
59
72
  export function notificationCategory(type) {
60
73
  const prefix = String(type).split('.')[0];
61
74
  return [
@@ -64,7 +77,8 @@ export function notificationCategory(type) {
64
77
  'content',
65
78
  'marketplace',
66
79
  'support',
67
- 'system'
80
+ 'system',
81
+ 'staff'
68
82
  ].includes(prefix) ? prefix : 'system';
69
83
  }
70
84
  /**
@@ -97,5 +111,127 @@ export function crmDailyDigestEnabled(prefs) {
97
111
  /** Whether a person asked for a workspace's weekly insights. */ export function insightDigestSubscribed(value, orgId) {
98
112
  return Boolean(orgId) && (value == null ? void 0 : value[orgId]) === true;
99
113
  }
114
+ export const NOTIFICATION_SETTINGS_FIELD = 'notificationSettings';
115
+ /**
116
+ * What a category does when nobody has said otherwise.
117
+ *
118
+ * Console on, email OFF, everywhere. Email defaults off because the inbox is
119
+ * not ours to fill: the product already sends transactional mail nobody opted
120
+ * into — welcome, verification, invites, dunning, usage alerts — and every one
121
+ * of those leaves on the same domain a customer's password reset depends on.
122
+ * Turning a busy site's form submissions into mail by default would put that
123
+ * domain's reputation behind traffic the recipient never asked for.
124
+ *
125
+ * Exhaustive `Record` deliberately: a new {@link NotificationCategory} is a
126
+ * compile error here until somebody decides what it does by default, which is
127
+ * the one question a new category must not be able to ship without answering.
128
+ */ export const NOTIFICATION_CHANNEL_DEFAULTS = {
129
+ billing: {
130
+ console: true,
131
+ email: false
132
+ },
133
+ team: {
134
+ console: true,
135
+ email: false
136
+ },
137
+ content: {
138
+ console: true,
139
+ email: false
140
+ },
141
+ marketplace: {
142
+ console: true,
143
+ email: false
144
+ },
145
+ support: {
146
+ console: true,
147
+ email: false
148
+ },
149
+ system: {
150
+ console: true,
151
+ email: false
152
+ },
153
+ // Console ON, because the complaint this answers is that staff never heard
154
+ // about a sign-up at all; email off, like everything else, because that is
155
+ // what the channel defaults to and a sign-up is not urgent enough to be the
156
+ // exception that starts filling inboxes by default.
157
+ staff: {
158
+ console: true,
159
+ email: false
160
+ }
161
+ };
162
+ /**
163
+ * The types that send their OWN email and must never be mailed again by the
164
+ * generic channel (AGL-3224).
165
+ *
166
+ * Both digests compose a message the fan-out could not reproduce — a day's
167
+ * owed tasks, a week's figures — and send it from their own route under their
168
+ * own switch (`digestPrefs.crmDaily`, `insightDigests.{orgId}`). A recipient
169
+ * who switches the `content` email channel on would otherwise receive the
170
+ * digest twice: once as the digest, once as a one-line "Daily CRM digest"
171
+ * notification saying that the digest happened.
172
+ */ export const NOTIFICATION_SELF_SENT_EMAIL_TYPES = new Set([
173
+ 'content.crmDailyDigest',
174
+ 'content.insightsDigest'
175
+ ]);
176
+ /**
177
+ * Whether a channel is on for one notification, at its own scope.
178
+ *
179
+ * Resolution order, first answer wins: the notification's SITE, its
180
+ * WORKSPACE, the account, then {@link NOTIFICATION_CHANNEL_DEFAULTS}. A scope
181
+ * that holds no entry for the category, or an entry with the channel key
182
+ * absent, does not answer — see {@link NotificationChannelPrefs}.
183
+ *
184
+ * `legacyPrefs` is the flat `notificationPrefs` mute map this replaces
185
+ * (AGL-267), and it sits BELOW the account layer rather than beside it.
186
+ * Nothing migrates it: a person who never opens the new settings page keeps
187
+ * being governed by the mutes they set years ago, and the first thing they do
188
+ * set on the account layer overrides the old map for that category without
189
+ * disturbing the rest of it. It answers for `console` only, because the map
190
+ * predates there being a second channel and reading a console mute as an
191
+ * email preference would be inventing an answer its author never gave.
192
+ */ export function notificationChannelEnabled(settings, channel, type, scope, legacyPrefs) {
193
+ var _settings_hosts, _settings_orgs;
194
+ const category = notificationCategory(type);
195
+ const layers = [
196
+ (scope == null ? void 0 : scope.hostId) ? settings == null ? void 0 : (_settings_hosts = settings.hosts) == null ? void 0 : _settings_hosts[scope.hostId] : undefined,
197
+ (scope == null ? void 0 : scope.orgId) ? settings == null ? void 0 : (_settings_orgs = settings.orgs) == null ? void 0 : _settings_orgs[scope.orgId] : undefined,
198
+ settings == null ? void 0 : settings.account
199
+ ];
200
+ for (const layer of layers){
201
+ var _layer_category;
202
+ const answer = layer == null ? void 0 : (_layer_category = layer[category]) == null ? void 0 : _layer_category[channel];
203
+ if (typeof answer === 'boolean') return answer;
204
+ }
205
+ if (channel === 'console' && notificationMuted(legacyPrefs, type)) return false;
206
+ return NOTIFICATION_CHANNEL_DEFAULTS[category][channel];
207
+ }
208
+ /**
209
+ * What one scope says, with no inheritance applied — what the settings page
210
+ * renders as Inherit / On / Off, and `undefined` is Inherit.
211
+ *
212
+ * `scope` names the layer directly rather than being derived from a
213
+ * notification, because the page edits a layer whether or not anything has
214
+ * ever arrived from it.
215
+ */ export function notificationScopePref(settings, scope, category, channel) {
216
+ var _settings_orgs, _settings_hosts, _layer_category;
217
+ const layer = scope.kind === 'account' ? settings == null ? void 0 : settings.account : scope.kind === 'org' ? settings == null ? void 0 : (_settings_orgs = settings.orgs) == null ? void 0 : _settings_orgs[scope.id] : settings == null ? void 0 : (_settings_hosts = settings.hosts) == null ? void 0 : _settings_hosts[scope.id];
218
+ return layer == null ? void 0 : (_layer_category = layer[category]) == null ? void 0 : _layer_category[channel];
219
+ }
220
+ /**
221
+ * The scopes this person has said something different about — what the
222
+ * settings page lists so an override is never somewhere you have to go
223
+ * looking for.
224
+ *
225
+ * Returns ids, not names: the page holds the org and host rosters and this
226
+ * module holds no lookups. An id with no name is still worth listing, because
227
+ * a preference about a workspace somebody left is exactly the kind of
228
+ * leftover that is invisible until it is listed.
229
+ */ export function notificationOverriddenScopes(settings) {
230
+ const named = (layers)=>Object.entries(layers != null ? layers : {}).filter(([, prefs])=>Object.values(prefs != null ? prefs : {}).some((channels)=>Object.values(channels != null ? channels : {}).some((value)=>typeof value === 'boolean'))).map(([id])=>id).sort();
231
+ return {
232
+ orgIds: named(settings == null ? void 0 : settings.orgs),
233
+ hostIds: named(settings == null ? void 0 : settings.hosts)
234
+ };
235
+ }
100
236
 
101
237
  //# sourceMappingURL=notifications.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/notifications.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ITimestamp } from '@aglyn/shared-util-timestamp'\n\n/**\n * In-app notifications (AGL-259): per-user docs at\n * `users/{uid}/notifications/{id}`, written by the Admin SDK (emitters in\n * the API routes + the `notifyAdmins` automation step) and read/marked by\n * their owner. Types follow the common SaaS taxonomy so the console can\n * icon/group them without a registry.\n */\nexport type AglynNotificationType =\n | 'billing.invoice'\n | 'billing.paymentFailed'\n // Stripe gave up on a failed renewal and CANCELLED the subscription\n // (AGL-1877). Distinct from `paymentFailed`, which announces one failed\n // attempt inside a retry window the customer can still recover from; this\n // one is the window having closed. Measured on the test account with a\n // test clock: five attempts over 21.08 days, then\n // `cancellation_details.reason: 'payment_failed'` — and until this existed\n // the org went silently to Free at that moment, with the `past_due` banner\n // disappearing at exactly the instant the consequence arrived.\n | 'billing.subscriptionCanceled'\n | 'billing.usage'\n | 'team.invite'\n | 'team.roleChanged'\n | 'team.hostAccessGranted'\n | 'content.formSubmission'\n | 'content.booking'\n | 'content.order'\n | 'content.lowStock'\n // A CRM task was assigned to the recipient by somebody else (AGL-2599).\n // `content.` because it is the same kind of message as a form submission\n // or a booking: a thing on the site that now needs this person's hands,\n // not a change to their standing (`team.`) and not a platform notice\n // (`system.`). Someone who has muted the operational stream has said they\n // do not want to be told about work as it arrives, and a task is work.\n | 'content.taskAssigned'\n // A CRM task's reminder came due (AGL-2659): the hourly runner telling\n // the assignee, at the task's own time, that the task is due. `content.`\n // beside `taskAssigned` for the same reason it gives — work on the site,\n // not standing — and so the one mute that stops \"work arriving\" stops\n // \"work falling due\" with it. The mute governs the whole reminder, mail\n // included, unlike the digest's: a reminder is one message about one\n // task, and there is no schedule to keep separately from it.\n | 'content.taskReminder'\n // A contact, or a lead, became the recipient's to work (AGL-2618): a\n // capture the assignment rules or the site's default owner routed to\n // them, a lead somebody converted and handed to them, or an automation's\n // \"assign an owner\" step — every server path that writes `ownerUid`\n // except the recipient assigning themselves. Two types rather than one\n // because the record the person opens differs: a lead is the site's own\n // working record and a contact is the org's, and the link goes to the\n // one they will actually work. `content.`, beside `taskAssigned`, for the\n // same reason: work arriving, not standing changing.\n | 'content.contactAssigned'\n | 'content.leadAssigned'\n // The morning's CRM digest (AGL-2619): what the recipient owes today —\n // overdue and due-today tasks, and the leads nobody has worked. `content.`\n // for the reason `taskAssigned` is: it is about work on the site, and the\n // person who muted the operational stream has asked not to be told about\n // work. The digest EMAIL is governed separately, by\n // `crmDailyDigestEnabled`: the mute is a fact about the console feed and\n // the digest switch is a fact about the digest.\n | 'content.crmDailyDigest'\n // The weekly insights (AGL-2915): what a site's figures showed that week,\n // for a person who asked for them. `content.` beside the CRM digest, for the\n // reason that one gives: it is about the site's work, and the operational\n // mute governs the console notification while the person's own switch for\n // the digest governs the digest.\n | 'content.insightsDigest'\n // Marketplace review verdicts (AGL-432/653).\n | 'marketplace.review'\n // Support desk, staff audience (AGL-850): a subscriber opened or replied to\n // a ticket. Fanned out to staff-claim holders, not org members.\n | 'support.ticketOpened'\n | 'support.ticketReply'\n | 'system.announcement'\n // A live plugin version stopped passing the static verifier (AGL-1086).\n // Staff audience: bytes we told workspaces were checked now fail checks\n // that did not exist when they were approved.\n //\n // Deliberately NOT under `marketplace.` (AGL-1088). Category is the prefix,\n // categories are mutable per user, and Marketplace is the category a staff\n // member mutes to stop routine listing-review chatter — which would drop\n // this alert as collateral. `system` is the bucket nobody mutes to reduce\n // noise. The adminAudit record survives a mute either way; the timeliness\n // does not, and timeliness is the whole point of the alert.\n | 'system.pluginVerifierRegression'\n // A sign-in method was removed from the user's own account because their\n // organization turned on SSO enforcement (AGL-1129). `system.`, not\n // `team.`, for the AGL-1088 reason above: `team` is the category someone\n // mutes to stop routine roster chatter, and \"the way you sign in just\n // changed\" is not chatter — the next sign-in fails without it.\n | 'system.signInMethodRemoved'\n // Documents in a scoped collection carrying no `visibleTo` (AGL-1478).\n // Staff audience: the weekly dry run found resources that are invisible\n // to every site-scoped read, which always means a creation path forgot\n // the field. `system.` for the AGL-1088 reason above, and because the\n // collection it names may be `marketplace`-adjacent or not.\n | 'system.scopeDrift'\n // An SSO domain that WAS DNS-proven has stopped answering with our\n // challenge record, for three consecutive weekly sweeps (AGL-1210).\n // Nothing has been turned off — sign-in for that domain still routes\n // exactly as it did — and that is precisely why this has to be said out\n // loud rather than left in a log.\n //\n // `system.`, not `team.`, for the AGL-1088 reason above and one of its\n // own: the audience is the org's own admins, the subject is whether their\n // people can still sign in, and it must reach them BEFORE anybody decides\n // to revoke the routing. A category somebody mutes to quieten roster\n // chatter is the wrong place for the one warning that precedes a lockout.\n | 'system.ssoDomainUnverified'\n // A site hit the per-month form-submission abuse ceiling and further\n // submissions are being refused (AGL-1655). `system.`, not `content.`, for\n // the AGL-1088 reason above and more sharply than any of them: `content` is\n // literally the category a site owner mutes to stop routine form-submission\n // chatter, and this is the one form notification that says the form has\n // STOPPED accepting. Filing it under the muted bucket would guarantee it\n // reaches nobody on exactly the sites busy enough to trip it.\n | 'system.formSubmissionsPaused'\n // A site reached the flat platform ceiling on member accounts or on lead\n // records, so further ones are being refused (AGL-1529). `system.` for the\n // same reason as `formSubmissionsPaused` directly above, and with the same\n // sharpness: `content.` is the bucket an owner mutes to stop routine\n // sign-up and lead chatter, and this is the one notification saying the\n // sign-ups have STOPPED — muted exactly on the sites busy enough to trip it.\n | 'system.visitorRecordsPaused'\n // An outsider reported one of our sites for phishing, malware or CSAM\n // (AGL-1964). `system` for the AGL-1088 reason and, again, more sharply\n // than most: this notification goes to STAFF, not to a customer, and its\n // subject is somebody else's site. There is no bucket a recipient could\n // mute it into that would be honest — nobody has opted into being told a\n // stranger is being phished through our platform, and nobody should be able\n // to opt out of it either.\n //\n // Only the urgent categories raise one, and only on a first report. See the\n // fan-out in apps/tenant/app/api/report-abuse/route.ts for why: a flood of\n // alerts IS the flood, and the alert it would cost us is the phishing one.\n | 'system.abuseReportUrgent'\n // The §512(g) counter-notice (AGL-1983), and the one place the \"only urgent\n // categories raise a notification\" restraint above is deliberately not\n // applied. Every counter-notice carries a statutory deadline that is\n // ALREADY RUNNING when it arrives — the clock counts from the subscriber's\n // submission, not from our attention — so there is no low-value tail of\n // these to drown out the important ones, and the one that goes unread is a\n // customer locked out of their own work plus an unmet obligation under\n // §512(g)(2)(A). Raised on first submission only, like the one above, so a\n // resubmitting customer cannot re-alert.\n | 'system.dmcaCounterNotice'\n // A site crossed the per-month bandwidth abuse ceiling (AGL-2155). Two\n // audiences share one type: staff, because an uncompensated free site\n // serving six figures of page views is an incident; and the site's own\n // managers, because on free the site is now serving a capped notice and\n // nobody should learn that from a visitor.\n //\n // `system.`, not `billing.`, for the AGL-1088 reason and one specific to\n // this meter: on the free plan there is no bill, so `billing` would be the\n // one category where the message is literally never about money — and it is\n // exactly the free-tier trip that changes what visitors see.\n | 'system.bandwidthCeilingTripped'\n // A free site crossed its PLAN's included bandwidth and is now serving the\n // capped notice (AGL-2413). Distinct from the ceiling above on purpose: that\n // one is an incident at 10x the band and goes to staff first; this one is an\n // ordinary quota at 1x, concerns only the site's own managers, and its\n // remedy is an upgrade rather than an investigation. Sending both under one\n // type would tell an owner their traffic was being treated as suspected\n // abuse when it is simply a successful free site.\n | 'system.bandwidthCapEngaged'\n // A Stripe billing webhook threw AFTER its handlers had begun (AGL-2157),\n // so its side effects may be half applied and its idempotency claim is\n // being HELD — Stripe will not retry it. Staff audience: this is the one\n // failure on that route no automatic retry can make safe, because the\n // handlers behind it are not all idempotent, and a human has to reconcile.\n | 'system.billingWebhookHalfApplied'\n // A card dispute arrived that NOTHING in the platform claimed (AGL-2429):\n // no `platformRevenue` row, no storefront order, no marketplace purchase.\n // Staff audience, and the reason it needs a type of its own is that its\n // absence was the bug — the routine case (a storefront or marketplace\n // chargeback, which the plugins own) and the fault case were the same\n // silence from the route's side, so a dispute nobody handled looked\n // exactly like one somebody did.\n //\n // `system.`, not `billing.`, for the AGL-1088 reason and one specific to\n // this alert: `billing` is the category a recipient is most likely to have\n // muted as routine invoice traffic, and this is the one message on that\n // route where muting it means money moves with nobody looking.\n | 'system.disputeUnattributed'\n\nexport interface AglynNotification {\n $id?: string\n type: AglynNotificationType\n title: string\n body?: string\n /** Console path the notification opens (e.g. a host inbox). */\n link?: string\n orgId?: string\n hostId?: string\n createdAt?: ITimestamp\n /** Set by the owner when read; unread while absent. */\n readAt?: ITimestamp | null\n}\n\nexport const NOTIFICATION_TYPE_LABELS: Record<AglynNotificationType, string> =\n {\n 'billing.invoice': 'Invoice available',\n 'billing.paymentFailed': 'Payment failed',\n 'billing.subscriptionCanceled': 'Subscription canceled',\n 'billing.usage': 'Usage threshold',\n 'team.invite': 'Team invite',\n 'team.roleChanged': 'Role changed',\n 'team.hostAccessGranted': 'Site access granted',\n 'content.formSubmission': 'Form submission',\n 'content.booking': 'New booking',\n 'content.order': 'New order',\n 'content.lowStock': 'Low stock',\n 'content.taskAssigned': 'Task assigned to you',\n 'content.taskReminder': 'Task reminder',\n 'content.contactAssigned': 'Contact assigned to you',\n 'content.leadAssigned': 'Lead assigned to you',\n 'content.crmDailyDigest': 'Daily CRM digest',\n 'content.insightsDigest': 'Weekly insights',\n 'marketplace.review': 'Listing review',\n\n 'support.ticketOpened': 'New support ticket',\n 'support.ticketReply': 'Support ticket reply',\n 'system.announcement': 'Announcement',\n 'system.pluginVerifierRegression': 'Plugin verifier regression',\n 'system.signInMethodRemoved': 'Sign-in method removed',\n 'system.scopeDrift': 'Resources missing a sharing scope',\n 'system.ssoDomainUnverified': 'SSO domain no longer proves ownership',\n 'system.formSubmissionsPaused': 'Form submissions paused',\n 'system.visitorRecordsPaused': 'Sign-ups or leads paused',\n 'system.abuseReportUrgent': 'Urgent abuse report',\n 'system.dmcaCounterNotice': 'DMCA counter-notice',\n 'system.bandwidthCeilingTripped': 'Bandwidth ceiling reached',\n 'system.bandwidthCapEngaged': 'Monthly traffic limit reached',\n 'system.billingWebhookHalfApplied': 'Billing webhook half applied',\n 'system.disputeUnattributed': 'Card dispute with no owner',\n }\n\n/** Preference buckets (AGL-267): the prefix before the dot. */\nexport type NotificationCategory =\n | 'billing'\n | 'team'\n | 'content'\n | 'marketplace'\n | 'support'\n | 'system'\n\nexport const NOTIFICATION_CATEGORY_LABELS: Record<\n NotificationCategory,\n string\n> = {\n billing: 'Billing',\n team: 'Team & access',\n content: 'Forms & bookings',\n marketplace: 'Marketplace',\n support: 'Support',\n system: 'Product & system',\n}\n\nexport function notificationCategory(\n type: AglynNotificationType | string,\n): NotificationCategory {\n const prefix = String(type).split('.')[0]\n return (\n ['billing', 'team', 'content', 'marketplace', 'support', 'system'].includes(\n prefix,\n )\n ? prefix\n : 'system'\n ) as NotificationCategory\n}\n\n/**\n * Per-user mute map stored at `users/{uid}.notificationPrefs`\n * (`{ [category]: false }` mutes); absent categories stay on.\n */\nexport function notificationMuted(\n prefs: Record<string, boolean> | null | undefined,\n type: AglynNotificationType | string,\n): boolean {\n return prefs?.[notificationCategory(type)] === false\n}\n\n/**\n * The field on `users/{uid}` that holds a person's digest switches\n * (AGL-2619): `{ crmDaily: false }` turns the daily CRM digest off, and an\n * absent key leaves it on. Its own map rather than a key in\n * `notificationPrefs`, because that map is keyed by CATEGORY and read by\n * {@link notificationMuted} — a digest is a schedule a person keeps or\n * drops, not a bucket of types, and one switch governs both the console\n * notification and the email it travels with.\n */\nexport const DIGEST_PREFS_FIELD = 'digestPrefs'\n\nexport function crmDailyDigestEnabled(\n prefs: Record<string, boolean> | null | undefined,\n): boolean {\n return prefs?.['crmDaily'] !== false\n}\n\n/**\n * The field on `users/{uid}` naming the workspaces whose weekly insights a\n * person asked for (AGL-2915): `{ [orgId]: true }`. OPT-IN, unlike the CRM\n * digest — an absent key is off — because a weekly insight is generated, and a\n * generation spends the workspace's credits. The person turns it on beside the\n * answers themselves, where the plan, the release and their permission have\n * already been checked, and off again there or in Notifications; the weekly\n * sweep checks all three again before it spends anything.\n */\nexport const INSIGHT_DIGESTS_FIELD = 'insightDigests'\n\n/** Whether a person asked for a workspace's weekly insights. */\nexport function insightDigestSubscribed(\n value: Record<string, boolean> | null | undefined,\n orgId: string,\n): boolean {\n return Boolean(orgId) && value?.[orgId] === true\n}\n"],"names":["NOTIFICATION_TYPE_LABELS","NOTIFICATION_CATEGORY_LABELS","billing","team","content","marketplace","support","system","notificationCategory","type","prefix","String","split","includes","notificationMuted","prefs","DIGEST_PREFS_FIELD","crmDailyDigestEnabled","INSIGHT_DIGESTS_FIELD","insightDigestSubscribed","value","orgId","Boolean"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GA2MD,OAAO,MAAMA,2BACX;IACE,mBAAmB;IACnB,yBAAyB;IACzB,gCAAgC;IAChC,iBAAiB;IACjB,eAAe;IACf,oBAAoB;IACpB,0BAA0B;IAC1B,0BAA0B;IAC1B,mBAAmB;IACnB,iBAAiB;IACjB,oBAAoB;IACpB,wBAAwB;IACxB,wBAAwB;IACxB,2BAA2B;IAC3B,wBAAwB;IACxB,0BAA0B;IAC1B,0BAA0B;IAC1B,sBAAsB;IAEtB,wBAAwB;IACxB,uBAAuB;IACvB,uBAAuB;IACvB,mCAAmC;IACnC,8BAA8B;IAC9B,qBAAqB;IACrB,8BAA8B;IAC9B,gCAAgC;IAChC,+BAA+B;IAC/B,4BAA4B;IAC5B,4BAA4B;IAC5B,kCAAkC;IAClC,8BAA8B;IAC9B,oCAAoC;IACpC,8BAA8B;AAChC,EAAC;AAWH,OAAO,MAAMC,+BAGT;IACFC,SAAS;IACTC,MAAM;IACNC,SAAS;IACTC,aAAa;IACbC,SAAS;IACTC,QAAQ;AACV,EAAC;AAED,OAAO,SAASC,qBACdC,IAAoC;IAEpC,MAAMC,SAASC,OAAOF,MAAMG,KAAK,CAAC,IAAI,CAAC,EAAE;IACzC,OACE;QAAC;QAAW;QAAQ;QAAW;QAAe;QAAW;KAAS,CAACC,QAAQ,CACzEH,UAEEA,SACA;AAER;AAEA;;;CAGC,GACD,OAAO,SAASI,kBACdC,KAAiD,EACjDN,IAAoC;IAEpC,OAAOM,CAAAA,yBAAAA,KAAO,CAACP,qBAAqBC,MAAM,MAAK;AACjD;AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMO,qBAAqB,cAAa;AAE/C,OAAO,SAASC,sBACdF,KAAiD;IAEjD,OAAOA,CAAAA,yBAAAA,KAAO,CAAC,WAAW,MAAK;AACjC;AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMG,wBAAwB,iBAAgB;AAErD,8DAA8D,GAC9D,OAAO,SAASC,wBACdC,KAAiD,EACjDC,KAAa;IAEb,OAAOC,QAAQD,UAAUD,CAAAA,yBAAAA,KAAO,CAACC,MAAM,MAAK;AAC9C"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/notifications.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ITimestamp } from '@aglyn/shared-util-timestamp'\n\n/**\n * In-app notifications (AGL-259): per-user docs at\n * `users/{uid}/notifications/{id}`, written by the Admin SDK (emitters in\n * the API routes + the `notifyAdmins` automation step) and read/marked by\n * their owner. Types follow the common SaaS taxonomy so the console can\n * icon/group them without a registry.\n */\nexport type AglynNotificationType =\n | 'billing.invoice'\n | 'billing.paymentFailed'\n // Stripe gave up on a failed renewal and CANCELLED the subscription\n // (AGL-1877). Distinct from `paymentFailed`, which announces one failed\n // attempt inside a retry window the customer can still recover from; this\n // one is the window having closed. Measured on the test account with a\n // test clock: five attempts over 21.08 days, then\n // `cancellation_details.reason: 'payment_failed'` — and until this existed\n // the org went silently to Free at that moment, with the `past_due` banner\n // disappearing at exactly the instant the consequence arrived.\n | 'billing.subscriptionCanceled'\n | 'billing.usage'\n | 'team.invite'\n | 'team.roleChanged'\n | 'team.hostAccessGranted'\n | 'content.formSubmission'\n | 'content.booking'\n | 'content.order'\n | 'content.lowStock'\n // A CRM task was assigned to the recipient by somebody else (AGL-2599).\n // `content.` because it is the same kind of message as a form submission\n // or a booking: a thing on the site that now needs this person's hands,\n // not a change to their standing (`team.`) and not a platform notice\n // (`system.`). Someone who has muted the operational stream has said they\n // do not want to be told about work as it arrives, and a task is work.\n | 'content.taskAssigned'\n // A CRM task's reminder came due (AGL-2659): the hourly runner telling\n // the assignee, at the task's own time, that the task is due. `content.`\n // beside `taskAssigned` for the same reason it gives — work on the site,\n // not standing — and so the one mute that stops \"work arriving\" stops\n // \"work falling due\" with it. The mute governs the whole reminder, mail\n // included, unlike the digest's: a reminder is one message about one\n // task, and there is no schedule to keep separately from it.\n | 'content.taskReminder'\n // A contact, or a lead, became the recipient's to work (AGL-2618): a\n // capture the assignment rules or the site's default owner routed to\n // them, a lead somebody converted and handed to them, or an automation's\n // \"assign an owner\" step — every server path that writes `ownerUid`\n // except the recipient assigning themselves. Two types rather than one\n // because the record the person opens differs: a lead is the site's own\n // working record and a contact is the org's, and the link goes to the\n // one they will actually work. `content.`, beside `taskAssigned`, for the\n // same reason: work arriving, not standing changing.\n | 'content.contactAssigned'\n | 'content.leadAssigned'\n // The morning's CRM digest (AGL-2619): what the recipient owes today —\n // overdue and due-today tasks, and the leads nobody has worked. `content.`\n // for the reason `taskAssigned` is: it is about work on the site, and the\n // person who muted the operational stream has asked not to be told about\n // work. The digest EMAIL is governed separately, by\n // `crmDailyDigestEnabled`: the mute is a fact about the console feed and\n // the digest switch is a fact about the digest.\n | 'content.crmDailyDigest'\n // The weekly insights (AGL-2915): what a site's figures showed that week,\n // for a person who asked for them. `content.` beside the CRM digest, for the\n // reason that one gives: it is about the site's work, and the operational\n // mute governs the console notification while the person's own switch for\n // the digest governs the digest.\n | 'content.insightsDigest'\n // Marketplace review verdicts (AGL-432/653).\n | 'marketplace.review'\n // Support desk, staff audience (AGL-850): a subscriber opened or replied to\n // a ticket. Fanned out to staff-claim holders, not org members.\n | 'support.ticketOpened'\n | 'support.ticketReply'\n | 'system.announcement'\n // A live plugin version stopped passing the static verifier (AGL-1086).\n // Staff audience: bytes we told workspaces were checked now fail checks\n // that did not exist when they were approved.\n //\n // Deliberately NOT under `marketplace.` (AGL-1088). Category is the prefix,\n // categories are mutable per user, and Marketplace is the category a staff\n // member mutes to stop routine listing-review chatter — which would drop\n // this alert as collateral. `system` is the bucket nobody mutes to reduce\n // noise. The adminAudit record survives a mute either way; the timeliness\n // does not, and timeliness is the whole point of the alert.\n | 'system.pluginVerifierRegression'\n // A sign-in method was removed from the user's own account because their\n // organization turned on SSO enforcement (AGL-1129). `system.`, not\n // `team.`, for the AGL-1088 reason above: `team` is the category someone\n // mutes to stop routine roster chatter, and \"the way you sign in just\n // changed\" is not chatter — the next sign-in fails without it.\n | 'system.signInMethodRemoved'\n // Documents in a scoped collection carrying no `visibleTo` (AGL-1478).\n // Staff audience: the weekly dry run found resources that are invisible\n // to every site-scoped read, which always means a creation path forgot\n // the field. `system.` for the AGL-1088 reason above, and because the\n // collection it names may be `marketplace`-adjacent or not.\n | 'system.scopeDrift'\n // An SSO domain that WAS DNS-proven has stopped answering with our\n // challenge record, for three consecutive weekly sweeps (AGL-1210).\n // Nothing has been turned off — sign-in for that domain still routes\n // exactly as it did — and that is precisely why this has to be said out\n // loud rather than left in a log.\n //\n // `system.`, not `team.`, for the AGL-1088 reason above and one of its\n // own: the audience is the org's own admins, the subject is whether their\n // people can still sign in, and it must reach them BEFORE anybody decides\n // to revoke the routing. A category somebody mutes to quieten roster\n // chatter is the wrong place for the one warning that precedes a lockout.\n | 'system.ssoDomainUnverified'\n // A site hit the per-month form-submission abuse ceiling and further\n // submissions are being refused (AGL-1655). `system.`, not `content.`, for\n // the AGL-1088 reason above and more sharply than any of them: `content` is\n // literally the category a site owner mutes to stop routine form-submission\n // chatter, and this is the one form notification that says the form has\n // STOPPED accepting. Filing it under the muted bucket would guarantee it\n // reaches nobody on exactly the sites busy enough to trip it.\n | 'system.formSubmissionsPaused'\n // A site reached the flat platform ceiling on member accounts or on lead\n // records, so further ones are being refused (AGL-1529). `system.` for the\n // same reason as `formSubmissionsPaused` directly above, and with the same\n // sharpness: `content.` is the bucket an owner mutes to stop routine\n // sign-up and lead chatter, and this is the one notification saying the\n // sign-ups have STOPPED — muted exactly on the sites busy enough to trip it.\n | 'system.visitorRecordsPaused'\n // An outsider reported one of our sites for phishing, malware or CSAM\n // (AGL-1964). `system` for the AGL-1088 reason and, again, more sharply\n // than most: this notification goes to STAFF, not to a customer, and its\n // subject is somebody else's site. There is no bucket a recipient could\n // mute it into that would be honest — nobody has opted into being told a\n // stranger is being phished through our platform, and nobody should be able\n // to opt out of it either.\n //\n // Only the urgent categories raise one, and only on a first report. See the\n // fan-out in apps/tenant/app/api/report-abuse/route.ts for why: a flood of\n // alerts IS the flood, and the alert it would cost us is the phishing one.\n | 'system.abuseReportUrgent'\n // The §512(g) counter-notice (AGL-1983), and the one place the \"only urgent\n // categories raise a notification\" restraint above is deliberately not\n // applied. Every counter-notice carries a statutory deadline that is\n // ALREADY RUNNING when it arrives — the clock counts from the subscriber's\n // submission, not from our attention — so there is no low-value tail of\n // these to drown out the important ones, and the one that goes unread is a\n // customer locked out of their own work plus an unmet obligation under\n // §512(g)(2)(A). Raised on first submission only, like the one above, so a\n // resubmitting customer cannot re-alert.\n | 'system.dmcaCounterNotice'\n // A site crossed the per-month bandwidth abuse ceiling (AGL-2155). Two\n // audiences share one type: staff, because an uncompensated free site\n // serving six figures of page views is an incident; and the site's own\n // managers, because on free the site is now serving a capped notice and\n // nobody should learn that from a visitor.\n //\n // `system.`, not `billing.`, for the AGL-1088 reason and one specific to\n // this meter: on the free plan there is no bill, so `billing` would be the\n // one category where the message is literally never about money — and it is\n // exactly the free-tier trip that changes what visitors see.\n | 'system.bandwidthCeilingTripped'\n // A free site crossed its PLAN's included bandwidth and is now serving the\n // capped notice (AGL-2413). Distinct from the ceiling above on purpose: that\n // one is an incident at 10x the band and goes to staff first; this one is an\n // ordinary quota at 1x, concerns only the site's own managers, and its\n // remedy is an upgrade rather than an investigation. Sending both under one\n // type would tell an owner their traffic was being treated as suspected\n // abuse when it is simply a successful free site.\n | 'system.bandwidthCapEngaged'\n // A Stripe billing webhook threw AFTER its handlers had begun (AGL-2157),\n // so its side effects may be half applied and its idempotency claim is\n // being HELD — Stripe will not retry it. Staff audience: this is the one\n // failure on that route no automatic retry can make safe, because the\n // handlers behind it are not all idempotent, and a human has to reconcile.\n | 'system.billingWebhookHalfApplied'\n // A card dispute arrived that NOTHING in the platform claimed (AGL-2429):\n // no `platformRevenue` row, no storefront order, no marketplace purchase.\n // Staff audience, and the reason it needs a type of its own is that its\n // absence was the bug — the routine case (a storefront or marketplace\n // chargeback, which the plugins own) and the fault case were the same\n // silence from the route's side, so a dispute nobody handled looked\n // exactly like one somebody did.\n //\n // `system.`, not `billing.`, for the AGL-1088 reason and one specific to\n // this alert: `billing` is the category a recipient is most likely to have\n // muted as routine invoice traffic, and this is the one message on that\n // route where muting it means money moves with nobody looking.\n | 'system.disputeUnattributed'\n // Somebody created an account, and somebody created a workspace\n // (AGL-3225). Staff audience, and the only two types in the taxonomy whose\n // subject is the platform's own growth rather than anybody's work.\n //\n // `staff.`, and NOT `system.`, and the AGL-1088 note above is the reason\n // rather than an exception to it: `system` is the bucket nobody mutes to\n // reduce noise, which is exactly what makes it the wrong home for the two\n // routine, high-volume events in the product. A staff member must be able\n // to stop hearing about every sign-up without also dropping the verifier\n // regression and the unattributed dispute that share that bucket — and\n // before this category existed, there was nowhere to put them where that\n // was true.\n //\n // The category also tells the settings page who a row is for: `staff` is\n // rendered only to claim holders, so no customer is shown a switch for\n // notifications they could never receive.\n | 'staff.userSignedUp'\n | 'staff.orgCreated'\n\nexport interface AglynNotification {\n $id?: string\n type: AglynNotificationType\n title: string\n body?: string\n /** Console path the notification opens (e.g. a host inbox). */\n link?: string\n orgId?: string\n hostId?: string\n createdAt?: ITimestamp\n /** Set by the owner when read; unread while absent. */\n readAt?: ITimestamp | null\n}\n\nexport const NOTIFICATION_TYPE_LABELS: Record<AglynNotificationType, string> =\n {\n 'billing.invoice': 'Invoice available',\n 'billing.paymentFailed': 'Payment failed',\n 'billing.subscriptionCanceled': 'Subscription canceled',\n 'billing.usage': 'Usage threshold',\n 'team.invite': 'Team invite',\n 'team.roleChanged': 'Role changed',\n 'team.hostAccessGranted': 'Site access granted',\n 'content.formSubmission': 'Form submission',\n 'content.booking': 'New booking',\n 'content.order': 'New order',\n 'content.lowStock': 'Low stock',\n 'content.taskAssigned': 'Task assigned to you',\n 'content.taskReminder': 'Task reminder',\n 'content.contactAssigned': 'Contact assigned to you',\n 'content.leadAssigned': 'Lead assigned to you',\n 'content.crmDailyDigest': 'Daily CRM digest',\n 'content.insightsDigest': 'Weekly insights',\n 'marketplace.review': 'Listing review',\n\n 'support.ticketOpened': 'New support ticket',\n 'support.ticketReply': 'Support ticket reply',\n 'system.announcement': 'Announcement',\n 'system.pluginVerifierRegression': 'Plugin verifier regression',\n 'system.signInMethodRemoved': 'Sign-in method removed',\n 'system.scopeDrift': 'Resources missing a sharing scope',\n 'system.ssoDomainUnverified': 'SSO domain no longer proves ownership',\n 'system.formSubmissionsPaused': 'Form submissions paused',\n 'system.visitorRecordsPaused': 'Sign-ups or leads paused',\n 'system.abuseReportUrgent': 'Urgent abuse report',\n 'system.dmcaCounterNotice': 'DMCA counter-notice',\n 'system.bandwidthCeilingTripped': 'Bandwidth ceiling reached',\n 'system.bandwidthCapEngaged': 'Monthly traffic limit reached',\n 'system.billingWebhookHalfApplied': 'Billing webhook half applied',\n 'system.disputeUnattributed': 'Card dispute with no owner',\n 'staff.userSignedUp': 'New account',\n 'staff.orgCreated': 'New workspace',\n }\n\n/** Preference buckets (AGL-267): the prefix before the dot. */\nexport type NotificationCategory =\n | 'billing'\n | 'team'\n | 'content'\n | 'marketplace'\n | 'support'\n | 'system'\n // Staff-only, and shown only to staff (AGL-3225) — see\n // {@link STAFF_NOTIFICATION_CATEGORIES}.\n | 'staff'\n\nexport const NOTIFICATION_CATEGORY_LABELS: Record<\n NotificationCategory,\n string\n> = {\n billing: 'Billing',\n team: 'Team & access',\n content: 'Forms & bookings',\n marketplace: 'Marketplace',\n support: 'Support',\n system: 'Product & system',\n staff: 'Platform growth',\n}\n\n/**\n * The categories only staff can receive (AGL-3225).\n *\n * The settings page hides these rows from everybody else, because a switch\n * for mail that can never arrive is a promise the product does not keep. It\n * is presentation only: `notifyStaff` is what decides the audience, and it\n * enumerates the `staff` claim rather than reading this.\n */\nexport const STAFF_NOTIFICATION_CATEGORIES: ReadonlySet<NotificationCategory> =\n new Set<NotificationCategory>(['staff'])\n\nexport function notificationCategory(\n type: AglynNotificationType | string,\n): NotificationCategory {\n const prefix = String(type).split('.')[0]\n return (\n [\n 'billing',\n 'team',\n 'content',\n 'marketplace',\n 'support',\n 'system',\n 'staff',\n ].includes(prefix)\n ? prefix\n : 'system'\n ) as NotificationCategory\n}\n\n/**\n * Per-user mute map stored at `users/{uid}.notificationPrefs`\n * (`{ [category]: false }` mutes); absent categories stay on.\n */\nexport function notificationMuted(\n prefs: Record<string, boolean> | null | undefined,\n type: AglynNotificationType | string,\n): boolean {\n return prefs?.[notificationCategory(type)] === false\n}\n\n/**\n * The field on `users/{uid}` that holds a person's digest switches\n * (AGL-2619): `{ crmDaily: false }` turns the daily CRM digest off, and an\n * absent key leaves it on. Its own map rather than a key in\n * `notificationPrefs`, because that map is keyed by CATEGORY and read by\n * {@link notificationMuted} — a digest is a schedule a person keeps or\n * drops, not a bucket of types, and one switch governs both the console\n * notification and the email it travels with.\n */\nexport const DIGEST_PREFS_FIELD = 'digestPrefs'\n\nexport function crmDailyDigestEnabled(\n prefs: Record<string, boolean> | null | undefined,\n): boolean {\n return prefs?.['crmDaily'] !== false\n}\n\n/**\n * The field on `users/{uid}` naming the workspaces whose weekly insights a\n * person asked for (AGL-2915): `{ [orgId]: true }`. OPT-IN, unlike the CRM\n * digest — an absent key is off — because a weekly insight is generated, and a\n * generation spends the workspace's credits. The person turns it on beside the\n * answers themselves, where the plan, the release and their permission have\n * already been checked, and off again there or in Notifications; the weekly\n * sweep checks all three again before it spends anything.\n */\nexport const INSIGHT_DIGESTS_FIELD = 'insightDigests'\n\n/** Whether a person asked for a workspace's weekly insights. */\nexport function insightDigestSubscribed(\n value: Record<string, boolean> | null | undefined,\n orgId: string,\n): boolean {\n return Boolean(orgId) && value?.[orgId] === true\n}\n\n/**\n * The channels a notification can travel on (AGL-3223).\n *\n * `console` is the feed at `/manage/notifications` and the app-bar dropdown\n * that reads it — the only channel that existed. `email` is the message the\n * fan-out sends beside that doc when the recipient asked for one.\n */\nexport type NotificationChannel = 'console' | 'email'\n\n/**\n * One scope's answer for one category. **Tri-state on purpose**: `true` and\n * `false` decide, and an ABSENT key inherits from the scope above.\n *\n * Inheritance is the whole reason this is a partial rather than a pair of\n * booleans. A person who wants form submissions from one busy site and not\n * from the other five has to be able to say that about the one site without\n * restating their answer for every other category at every other scope — and\n * a two-valued leaf cannot express \"I have not said\", so every override would\n * have to be written out in full and would then stop tracking the account\n * default it was never meant to detach from.\n */\nexport interface NotificationChannelPrefs {\n console?: boolean\n email?: boolean\n}\n\nexport type NotificationCategoryPrefs = Partial<\n Record<NotificationCategory, NotificationChannelPrefs>\n>\n\n/**\n * Per-scope, per-channel notification preferences (AGL-3223), stored at\n * `users/{uid}.notificationSettings`.\n *\n * Three layers, narrowest first when resolving: the SITE a notification\n * concerns, then the WORKSPACE, then the account. Anything none of them\n * answers falls to {@link NOTIFICATION_CHANNEL_DEFAULTS}.\n *\n * ON THE USER DOCUMENT, not on `orgs/{orgId}/members/{uid}`, and that is a\n * cost decision rather than a modelling preference. `notifyUsers` already\n * does exactly one `getAll` over the recipients' user docs to read their\n * category mutes, so every layer living here means per-site preferences are\n * read for free on the fan-out's hot path. The member row would add a read\n * per recipient per notification to answer a question the document already in\n * hand could have answered.\n */\nexport interface NotificationSettings {\n account?: NotificationCategoryPrefs\n /** Keyed by org id. */\n orgs?: Record<string, NotificationCategoryPrefs>\n /** Keyed by host id — a site's own answer, narrower than its workspace's. */\n hosts?: Record<string, NotificationCategoryPrefs>\n}\n\nexport const NOTIFICATION_SETTINGS_FIELD = 'notificationSettings'\n\n/**\n * What a category does when nobody has said otherwise.\n *\n * Console on, email OFF, everywhere. Email defaults off because the inbox is\n * not ours to fill: the product already sends transactional mail nobody opted\n * into — welcome, verification, invites, dunning, usage alerts — and every one\n * of those leaves on the same domain a customer's password reset depends on.\n * Turning a busy site's form submissions into mail by default would put that\n * domain's reputation behind traffic the recipient never asked for.\n *\n * Exhaustive `Record` deliberately: a new {@link NotificationCategory} is a\n * compile error here until somebody decides what it does by default, which is\n * the one question a new category must not be able to ship without answering.\n */\nexport const NOTIFICATION_CHANNEL_DEFAULTS: Record<\n NotificationCategory,\n Record<NotificationChannel, boolean>\n> = {\n billing: { console: true, email: false },\n team: { console: true, email: false },\n content: { console: true, email: false },\n marketplace: { console: true, email: false },\n support: { console: true, email: false },\n system: { console: true, email: false },\n // Console ON, because the complaint this answers is that staff never heard\n // about a sign-up at all; email off, like everything else, because that is\n // what the channel defaults to and a sign-up is not urgent enough to be the\n // exception that starts filling inboxes by default.\n staff: { console: true, email: false },\n}\n\n/**\n * The types that send their OWN email and must never be mailed again by the\n * generic channel (AGL-3224).\n *\n * Both digests compose a message the fan-out could not reproduce — a day's\n * owed tasks, a week's figures — and send it from their own route under their\n * own switch (`digestPrefs.crmDaily`, `insightDigests.{orgId}`). A recipient\n * who switches the `content` email channel on would otherwise receive the\n * digest twice: once as the digest, once as a one-line \"Daily CRM digest\"\n * notification saying that the digest happened.\n */\nexport const NOTIFICATION_SELF_SENT_EMAIL_TYPES: ReadonlySet<string> = new Set<\n AglynNotificationType\n>(['content.crmDailyDigest', 'content.insightsDigest'])\n\n/**\n * Whether a channel is on for one notification, at its own scope.\n *\n * Resolution order, first answer wins: the notification's SITE, its\n * WORKSPACE, the account, then {@link NOTIFICATION_CHANNEL_DEFAULTS}. A scope\n * that holds no entry for the category, or an entry with the channel key\n * absent, does not answer — see {@link NotificationChannelPrefs}.\n *\n * `legacyPrefs` is the flat `notificationPrefs` mute map this replaces\n * (AGL-267), and it sits BELOW the account layer rather than beside it.\n * Nothing migrates it: a person who never opens the new settings page keeps\n * being governed by the mutes they set years ago, and the first thing they do\n * set on the account layer overrides the old map for that category without\n * disturbing the rest of it. It answers for `console` only, because the map\n * predates there being a second channel and reading a console mute as an\n * email preference would be inventing an answer its author never gave.\n */\nexport function notificationChannelEnabled(\n settings: NotificationSettings | null | undefined,\n channel: NotificationChannel,\n type: AglynNotificationType | string,\n scope?: { orgId?: string | null; hostId?: string | null },\n legacyPrefs?: Record<string, boolean> | null,\n): boolean {\n const category = notificationCategory(type)\n const layers: Array<NotificationCategoryPrefs | undefined> = [\n scope?.hostId ? settings?.hosts?.[scope.hostId] : undefined,\n scope?.orgId ? settings?.orgs?.[scope.orgId] : undefined,\n settings?.account,\n ]\n for (const layer of layers) {\n const answer = layer?.[category]?.[channel]\n if (typeof answer === 'boolean') return answer\n }\n if (channel === 'console' && notificationMuted(legacyPrefs, type)) return false\n return NOTIFICATION_CHANNEL_DEFAULTS[category][channel]\n}\n\n/**\n * What one scope says, with no inheritance applied — what the settings page\n * renders as Inherit / On / Off, and `undefined` is Inherit.\n *\n * `scope` names the layer directly rather than being derived from a\n * notification, because the page edits a layer whether or not anything has\n * ever arrived from it.\n */\nexport function notificationScopePref(\n settings: NotificationSettings | null | undefined,\n scope: { kind: 'account' } | { kind: 'org' | 'host'; id: string },\n category: NotificationCategory,\n channel: NotificationChannel,\n): boolean | undefined {\n const layer =\n scope.kind === 'account'\n ? settings?.account\n : scope.kind === 'org'\n ? settings?.orgs?.[scope.id]\n : settings?.hosts?.[scope.id]\n return layer?.[category]?.[channel]\n}\n\n/**\n * The scopes this person has said something different about — what the\n * settings page lists so an override is never somewhere you have to go\n * looking for.\n *\n * Returns ids, not names: the page holds the org and host rosters and this\n * module holds no lookups. An id with no name is still worth listing, because\n * a preference about a workspace somebody left is exactly the kind of\n * leftover that is invisible until it is listed.\n */\nexport function notificationOverriddenScopes(\n settings: NotificationSettings | null | undefined,\n): { orgIds: string[]; hostIds: string[] } {\n const named = (layers: Record<string, NotificationCategoryPrefs> | undefined) =>\n Object.entries(layers ?? {})\n .filter(([, prefs]) =>\n Object.values(prefs ?? {}).some((channels) =>\n Object.values(channels ?? {}).some(\n (value) => typeof value === 'boolean',\n ),\n ),\n )\n .map(([id]) => id)\n .sort()\n return { orgIds: named(settings?.orgs), hostIds: named(settings?.hosts) }\n}\n"],"names":["NOTIFICATION_TYPE_LABELS","NOTIFICATION_CATEGORY_LABELS","billing","team","content","marketplace","support","system","staff","STAFF_NOTIFICATION_CATEGORIES","Set","notificationCategory","type","prefix","String","split","includes","notificationMuted","prefs","DIGEST_PREFS_FIELD","crmDailyDigestEnabled","INSIGHT_DIGESTS_FIELD","insightDigestSubscribed","value","orgId","Boolean","NOTIFICATION_SETTINGS_FIELD","NOTIFICATION_CHANNEL_DEFAULTS","console","email","NOTIFICATION_SELF_SENT_EMAIL_TYPES","notificationChannelEnabled","settings","channel","scope","legacyPrefs","category","layers","hostId","hosts","undefined","orgs","account","layer","answer","notificationScopePref","kind","id","notificationOverriddenScopes","named","Object","entries","filter","values","some","channels","map","sort","orgIds","hostIds"],"mappings":"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"}
@@ -15,7 +15,8 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  /**
18
- * Which host subcollections the media usage scan reads (AGL-1867).
18
+ * The host subcollections CORE owns, and how the media usage scan reads them
19
+ * (AGL-1867, AGL-3080).
19
20
  *
20
21
  * ## Why this exists, and why it is shaped the way it is
21
22
  *
@@ -34,8 +35,8 @@
34
35
  * feared is only necessary if the default is NOT to scan. So the default here
35
36
  * is inverted:
36
37
  *
37
- * **Every host subcollection is scanned unless it is named below with a
38
- * reason it is not.**
38
+ * **Every host subcollection is scanned unless it is named with a reason it is
39
+ * not.**
39
40
  *
40
41
  * That turns the open question from "does this carry media?" — which needs a
41
42
  * judgement about a schema nobody wrote down — into "is scanning this wasteful
@@ -44,15 +45,27 @@
44
45
  * thought about is READ, so a plugin shipping a new media-bearing collection is
45
46
  * covered the day it lands rather than the day somebody remembers it.
46
47
  *
47
- * ## What keeps the list from rotting
48
+ * ## Core holds core's, and asks the plugins for theirs (AGL-3080)
49
+ *
50
+ * This file used to hold every collection in the product: which ones commerce
51
+ * writes, which ones marketing writes, and which console page each deep-links
52
+ * to. That is the platform keeping a map of its plugins' storage, and the map
53
+ * went stale exactly where a stale map is invisible — three of its deep links
54
+ * pointed at a hub that did not hold the document, and nothing could tell.
55
+ *
56
+ * So a plugin declares its own collections in `plugins.config.json` and the
57
+ * readers ask `plugin-manager/plugin-host-collections`. What is left here is
58
+ * core's own storage, which is the only part core is entitled to name.
59
+ *
60
+ * ## What keeps these lists from rotting
48
61
  *
49
62
  * `host-content-media-coverage.spec.ts` sweeps `apps/**` and `libs/**` for host
50
63
  * subcollection names — the same derived sweep
51
64
  * `host-subcollection-write-deny-coverage.spec.ts` uses, for the same reason —
52
- * and asserts {@link PLUGIN_CONTENT_COLLECTIONS} is EXACTLY that sweep minus
53
- * {@link CORE_CONTENT_COLLECTIONS} minus {@link MEDIA_SCAN_EXCLUDED}. A new
54
- * collection fails the build with a one-line decision to make, and the default
55
- * answer — add it to the scanned list — is also the safe one.
65
+ * and asserts the sweep is EXACTLY these three lists plus the plugins'
66
+ * declarations. A new collection fails the build with a one-line decision to
67
+ * make, and the default answer — declare it scanned, on the plugin that writes
68
+ * it — is also the safe one.
56
69
  *
57
70
  * ## The plugin boundary was NOT crossed to do this
58
71
  *
@@ -86,45 +99,31 @@
86
99
  */
87
100
  export declare const CORE_CONTENT_COLLECTIONS: readonly ["screens", "layouts", "components", "emailTemplates", "collections"];
88
101
  /**
89
- * Host subcollections deliberately NOT read by the media scan, and why.
90
- *
91
- * Every entry has to answer one of two questions: what would scanning it cost,
92
- * or what would scanning it get wrong. "It probably has no images in it" is not
93
- * an accepted reason — that is the guess this file is arranged to avoid making.
94
- */
95
- export declare const MEDIA_SCAN_EXCLUDED: Record<string, string>;
96
- /**
97
- * Host subcollections the media scan reads generically.
102
+ * Core's own host subcollections that the scan reads generically.
98
103
  *
99
104
  * Generically: no per-collection field list and no per-collection decoder.
100
105
  * Each document is flattened by `documentHaystack` — which decodes `nodes` and
101
- * `elements` through `decodeStoredNodes` first, so a plugin that adopts the
102
- * compressed storage form is covered without touching this file — and the
103
- * matching field's dotted path is recovered by walking the document. A field
104
- * list here would be the same staleness trap `referencingFieldPath` was written
105
- * to avoid one level down.
106
- *
107
- * MUST equal the repo-wide host subcollection sweep minus
108
- * {@link CORE_CONTENT_COLLECTIONS} minus {@link MEDIA_SCAN_EXCLUDED}. The guard
109
- * spec asserts exactly that, in both directions, so this list can neither miss
110
- * a new collection nor keep naming a deleted one.
106
+ * `elements` through `decodeStoredNodes` first — and the matching field's
107
+ * dotted path is recovered by walking the document. A field list here would be
108
+ * the same staleness trap `referencingFieldPath` was written to avoid one
109
+ * level down.
110
+ *
111
+ * Short because it is only core's: a blog author, the per-plugin settings
112
+ * document the plugin manager owns, and a site template. Everything else that
113
+ * is scanned generically belongs to a plugin and is declared by it.
111
114
  */
112
- export declare const PLUGIN_CONTENT_COLLECTIONS: readonly ["actions", "authors", "campaigns", "coupons", "discounts", "events", "experiments", "forms", "functions", "installs", "locations", "memberPosts", "overlays", "pluginSettings", "productCategories", "products", "redirects", "resources", "reviews", "services", "settings", "siteMembers", "suppliers", "templates", "variables", "webhooks", "workflows"];
113
- export type PluginContentCollection = (typeof PLUGIN_CONTENT_COLLECTIONS)[number];
115
+ export declare const CORE_GENERIC_SCAN_COLLECTIONS: readonly ["authors", "pluginSettings", "templates"];
114
116
  /**
115
- * Console page slug a plugin-content reference row deep-links to.
117
+ * Core's own host subcollections that the media scan deliberately does NOT
118
+ * read, and why.
116
119
  *
117
- * Optional on purpose, and deliberately not required for a collection to be
118
- * scanned. A row with no destination still renders — as text rather than a
119
- * link — and that is strictly better than the row not existing, which is the
120
- * bug this issue is about. Requiring a slug would have made the deep link a
121
- * precondition for coverage and quietly re-created the hole for every
122
- * collection nobody had got round to routing.
123
- *
124
- * Keyed by collection, valued with the `[pluginSlug]` segment of
125
- * `Route.HOST_PLUGIN`.
120
+ * Every entry has to answer one of two questions: what would scanning it cost,
121
+ * or what would scanning it get wrong. "It probably has no images in it" is not
122
+ * an accepted reason — that is the guess this file is arranged to avoid making.
123
+ * A plugin's exclusions carry the same burden and live in its own declaration,
124
+ * where `mediaScanReason` is required with `mediaScan: 'none'`.
126
125
  */
127
- export declare const PLUGIN_CONTENT_ROUTE_SLUG: Partial<Record<PluginContentCollection, string>>;
126
+ export declare const MEDIA_SCAN_EXCLUDED: Record<string, string>;
128
127
  /**
129
128
  * What to call one of these in a reference row.
130
129
  *
@@ -133,5 +132,8 @@ export declare const PLUGIN_CONTENT_ROUTE_SLUG: Partial<Record<PluginContentColl
133
132
  * `productCategories` reads as "Product category". Singularised with the two
134
133
  * rules English spells consistently enough to be worth automating; anything
135
134
  * else keeps its name, which is a cosmetic miss rather than a coverage one.
135
+ *
136
+ * Shared with `pluginHostCollectionLabel`, which prefers a plugin's declared
137
+ * label and falls back to exactly this.
136
138
  */
137
139
  export declare function hostContentCollectionLabel(collection: string): string;