@aglyn/tenant-data-admin 1.0.0-beta.263 → 1.0.0-beta.266
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 +7 -7
- package/src/lib/server/host-console-link.d.ts +25 -0
- package/src/lib/server/host-console-link.js +47 -0
- package/src/lib/server/host-console-link.js.map +1 -0
- package/src/lib/server/host-email-tokens.js +25 -2
- package/src/lib/server/host-email-tokens.js.map +1 -1
- package/src/lib/server/mobile-push-switch.d.ts +2 -0
- package/src/lib/server/mobile-push-switch.js.map +1 -1
- package/src/lib/server/notifications.d.ts +10 -4
- package/src/lib/server/notifications.js +34 -9
- package/src/lib/server/notifications.js.map +1 -1
- package/src/lib/server/operator-alerts.d.ts +11 -0
- package/src/lib/server/operator-alerts.js +29 -7
- package/src/lib/server/operator-alerts.js.map +1 -1
- package/src/lib/server/org-member-notice.d.ts +10 -0
- package/src/lib/server/org-member-notice.js +6 -1
- package/src/lib/server/org-member-notice.js.map +1 -1
- package/src/lib/server/push-apns.d.ts +7 -2
- package/src/lib/server/push-apns.js +8 -4
- package/src/lib/server/push-apns.js.map +1 -1
- package/src/lib/server/push-delivery.d.ts +5 -0
- package/src/lib/server/push-delivery.js +9 -4
- package/src/lib/server/push-delivery.js.map +1 -1
- package/src/lib/server/push-fcm.d.ts +8 -1
- package/src/lib/server/push-fcm.js +11 -3
- package/src/lib/server/push-fcm.js.map +1 -1
- package/src/lib/server/render-system-email.js +7 -1
- package/src/lib/server/render-system-email.js.map +1 -1
- package/src/lib/server/risk-notice.js +23 -1
- package/src/lib/server/risk-notice.js.map +1 -1
- package/src/lib/server/sso-domain-policy.d.ts +12 -3
- package/src/lib/server/sso-domain-policy.js +39 -6
- package/src/lib/server/sso-domain-policy.js.map +1 -1
- package/src/lib/server/staff-alert-email.d.ts +10 -0
- package/src/lib/server/staff-alert-email.js +10 -3
- package/src/lib/server/staff-alert-email.js.map +1 -1
|
@@ -122,23 +122,56 @@ export const SSO_REQUIRED_DOMAINS_ENV = 'AGLYN_SSO_REQUIRED_DOMAINS';
|
|
|
122
122
|
*
|
|
123
123
|
* For accounts that cannot use the IdP at all because someone outside the
|
|
124
124
|
* company has to sign in with them: the demo login an app store reviewer is
|
|
125
|
-
* given, for example
|
|
126
|
-
* exception is named and can be
|
|
125
|
+
* given, for example, or an automated sign-up check that creates a new
|
|
126
|
+
* plus-addressed account on every run. Every exception is named and can be
|
|
127
|
+
* read back from configuration:
|
|
127
128
|
*
|
|
128
129
|
* ```
|
|
129
|
-
* AGLYN_SSO_EXEMPT_EMAILS="reviewer@example.com"
|
|
130
|
+
* AGLYN_SSO_EXEMPT_EMAILS="reviewer@example.com ops+signup-canary*@example.com"
|
|
130
131
|
* ```
|
|
131
132
|
*
|
|
133
|
+
* An entry is an exact address, or one mailbox's plus tag followed by `*`,
|
|
134
|
+
* which also admits every address that extends that tag on the same domain.
|
|
135
|
+
* The `*` is accepted only as the last character of the local part and only
|
|
136
|
+
* after a `+`, so no entry can exempt a whole mailbox or a whole domain; any
|
|
137
|
+
* other entry with a `*` is dropped.
|
|
138
|
+
*
|
|
132
139
|
* Comma or whitespace separated, compared lower-cased. Empty by default.
|
|
133
140
|
*/ export const SSO_EXEMPT_EMAILS_ENV = 'AGLYN_SSO_EXEMPT_EMAILS';
|
|
134
141
|
export function parseSsoExemptEmails(raw) {
|
|
135
142
|
const emails = new Set();
|
|
136
143
|
for (const entry of String(raw != null ? raw : '').split(/[,\s]+/)){
|
|
137
144
|
const email = entry.trim().toLowerCase();
|
|
138
|
-
|
|
145
|
+
const at = email.lastIndexOf('@');
|
|
146
|
+
if (at <= 0 || at === email.length - 1) continue;
|
|
147
|
+
if (email.slice(at + 1).includes('*')) continue;
|
|
148
|
+
const local = email.slice(0, at);
|
|
149
|
+
const star = local.indexOf('*');
|
|
150
|
+
if (star !== -1) {
|
|
151
|
+
const plus = local.indexOf('+');
|
|
152
|
+
// One trailing `*`, after a non-empty plus tag: `name+tag*`.
|
|
153
|
+
if (star !== local.length - 1 || plus <= 0 || plus >= star - 1) continue;
|
|
154
|
+
}
|
|
155
|
+
emails.add(email);
|
|
139
156
|
}
|
|
140
157
|
return emails;
|
|
141
158
|
}
|
|
159
|
+
/** Whether an address is named by one of the parsed exemption entries. */ export function isSsoExemptEmail(email, exempt) {
|
|
160
|
+
const address = String(email != null ? email : '').trim().toLowerCase();
|
|
161
|
+
if (!address) return false;
|
|
162
|
+
if (exempt.has(address)) return true;
|
|
163
|
+
const at = address.lastIndexOf('@');
|
|
164
|
+
if (at <= 0) return false;
|
|
165
|
+
const local = address.slice(0, at);
|
|
166
|
+
const domain = address.slice(at + 1);
|
|
167
|
+
for (const entry of exempt){
|
|
168
|
+
if (!entry.endsWith(`*@${domain}`)) continue;
|
|
169
|
+
if (local.startsWith(entry.slice(0, entry.length - domain.length - 2))) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
142
175
|
export function ssoExemptEmails(env = process.env) {
|
|
143
176
|
return parseSsoExemptEmails(env[SSO_EXEMPT_EMAILS_ENV]);
|
|
144
177
|
}
|
|
@@ -153,7 +186,7 @@ export function ssoExemptEmails(env = process.env) {
|
|
|
153
186
|
* so a spec can drive every combination directly, and so the audit view and
|
|
154
187
|
* the enforcement path can never disagree about what the policy says.
|
|
155
188
|
*/ export function evaluateSsoDomainPolicy(identity, domains = ssoRequiredDomains(), exempt = ssoExemptEmails()) {
|
|
156
|
-
var _identity_tenantId
|
|
189
|
+
var _identity_tenantId;
|
|
157
190
|
const domain = domainOf(identity.email);
|
|
158
191
|
const tenantId = (_identity_tenantId = identity.tenantId) != null ? _identity_tenantId : null;
|
|
159
192
|
// Exact-match lookup, never a suffix test: `notaglyn.com` ends with
|
|
@@ -195,7 +228,7 @@ export function ssoExemptEmails(env = process.env) {
|
|
|
195
228
|
reviewable: true
|
|
196
229
|
};
|
|
197
230
|
}
|
|
198
|
-
if (
|
|
231
|
+
if (isSsoExemptEmail(identity.email, exempt)) {
|
|
199
232
|
return {
|
|
200
233
|
verdict: 'allow-exempt',
|
|
201
234
|
refused: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/sso-domain-policy.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 * Workspace-domain SSO policy (AGL-1993).\n *\n * **The rule is about a DOMAIN, not about staff.** An `@aglyn.com` address is a\n * Google Workspace identity, and Workspace is what enforces MFA, disables an\n * account at offboarding, and lets an admin revoke a session. An `@aglyn.com`\n * address that signs in through a project-pool password or a consumer Google\n * account has none of that: it looks like a company identity and is governed\n * like a personal one. That gap is the whole reason this module exists.\n *\n * ## Staff is a SEPARATE axis and this module never reads it\n *\n * Staff may be granted to anybody — SSO or not, `@aglyn.com` or not, project\n * pool or any GCIP tenant including a *customer's*. Nothing here consults the\n * `staff` claim, and `sso-domain-policy.spec.ts` pins that by evaluating every\n * staff permutation and asserting the verdict does not move. The two axes are\n * independent; conflating them would turn a narrow domain control into an\n * accidental SSO mandate for staff, which is explicitly not the policy.\n *\n * These all remain valid, and each has a test:\n *\n * | identity | staff | verdict |\n * | ------------------------------------------ | ----- | ------------------------- |\n * | `@aglyn.com` in the designated tenant | yes | allowed |\n * | personal address, project pool (break-glass)| yes | allowed — permanent design|\n * | personal address, project pool | no | allowed |\n * | SSO identity in a CUSTOMER org's tenant | yes | allowed |\n * | `@aglyn.com` in the PROJECT pool | any | **refused** when enforced |\n *\n * Only the last row is what the switch exists for.\n *\n * ## How this differs from `sso-enforcement.ts`\n *\n * {@link enforceSsoSignInMethods} (AGL-1128/1129) strips non-IdP providers from\n * accounts that are ALREADY INSIDE a tenant. It cannot see an identity that\n * never joined the tenant at all — a project-pool `@aglyn.com` account is\n * invisible to every tenant sweep, by construction. Measured on aglyn-main on\n * 2026-08-18: two such accounts existed, one of them holding a live\n * `google.com` provider. This module covers that outside-the-tenant half.\n *\n * ## Shape note: deliberately NOT a discriminated union\n *\n * `strictNullChecks` is off repo-wide, which defeats boolean-discriminant\n * narrowing — a spec can read the wrong arm of a union and pass silently. So\n * the decision is ONE flat interface with a string `verdict`, and specs assert\n * the literal. There is no arm to read by mistake.\n */\n\n/**\n * ## Self-hosting: this policy is CONFIGURATION, never a compiled-in constant\n *\n * Aglyn ships in two shapes — the Aglyn-operated SaaS, and self-hosted installs\n * on the operator's own Firebase project. `aglyn.com` is *our* Workspace\n * domain; a self-hoster has their own domain, their own IdP, or none at all.\n * Baking our domain in would make the rule dead weight for them at best and a\n * lockout at worst, so the governed set is read from configuration and is\n * **empty by default**.\n *\n * Empty means the rule does nothing. That is simultaneously the correct\n * behaviour for a fresh self-host install and the correct OFF state for us —\n * one default serving both, rather than a special case for either.\n *\n * Format — `domain=tenantId`, comma or whitespace separated:\n *\n * ```\n * AGLYN_SSO_REQUIRED_DOMAINS=\"aglyn.com=aglyn-org-y5v14\"\n * ```\n *\n * A map rather than a bare list because \"must use SSO\" is meaningless without\n * naming WHOSE SSO: the point is IdP lifecycle control, which only the tenant\n * wired to that domain's SAML provider delivers.\n */\nimport { PLATFORM_BRAND_NAME } from '@aglyn/aglyn/app-utils/platform-brand'\n\n/**\n * The block below runs in two places: here, at the session mint, and in the\n * `cloud/functions` account-creation blocking function, which refuses the\n * account before it exists. `cloud/functions` is a plain npm package that can\n * import only firebase-admin and firebase-functions, so it holds a verbatim\n * copy (`cloud/functions/src/sso-domain-policy.ts`), and\n * `apps/console/specs/sso-domain-creation-wiring.spec.ts` fails if the two\n * differ by a single character. Change it here, then copy the region across.\n */\n// #region sso-domain-policy\nexport const SSO_REQUIRED_DOMAINS_ENV = 'AGLYN_SSO_REQUIRED_DOMAINS'\n\nexport type SsoRequiredDomains = Readonly<Record<string, string>>\n\n/**\n * Parse the configured domain→tenant map. Total: anything unparseable is\n * dropped rather than throwing, because this sits on the authentication path\n * and a malformed env var must not take sign-in down. A dropped entry fails\n * OPEN (the domain is simply ungoverned), which is the safe direction for a\n * rule whose only power is to refuse.\n */\nexport function parseSsoRequiredDomains(\n raw: string | null | undefined,\n): SsoRequiredDomains {\n const map: Record<string, string> = {}\n for (const pair of String(raw ?? '').split(/[,\\s]+/)) {\n if (!pair) continue\n const eq = pair.indexOf('=')\n if (eq <= 0) continue\n const domain = pair.slice(0, eq).trim().toLowerCase()\n const tenantId = pair.slice(eq + 1).trim()\n if (!domain || !tenantId) continue\n map[domain] = tenantId\n }\n return map\n}\n\n/**\n * The operator's SSO-required domains. Empty unless configured — see above.\n */\nexport function ssoRequiredDomains(\n env: Record<string, string | undefined> = process.env,\n): SsoRequiredDomains {\n return parseSsoRequiredDomains(env[SSO_REQUIRED_DOMAINS_ENV])\n}\n\n/**\n * Addresses on a governed domain that may still sign in OUTSIDE its tenant.\n *\n * For accounts that cannot use the IdP at all because someone outside the\n * company has to sign in with them: the demo login an app store reviewer is\n * given, for example. Exact addresses only, never a pattern, so every\n * exception is named and can be read back from configuration:\n *\n * ```\n * AGLYN_SSO_EXEMPT_EMAILS=\"reviewer@example.com\"\n * ```\n *\n * Comma or whitespace separated, compared lower-cased. Empty by default.\n */\nexport const SSO_EXEMPT_EMAILS_ENV = 'AGLYN_SSO_EXEMPT_EMAILS'\n\nexport function parseSsoExemptEmails(\n raw: string | null | undefined,\n): ReadonlySet<string> {\n const emails = new Set<string>()\n for (const entry of String(raw ?? '').split(/[,\\s]+/)) {\n const email = entry.trim().toLowerCase()\n if (email.includes('@')) emails.add(email)\n }\n return emails\n}\n\nexport function ssoExemptEmails(\n env: Record<string, string | undefined> = process.env,\n): ReadonlySet<string> {\n return parseSsoExemptEmails(env[SSO_EXEMPT_EMAILS_ENV])\n}\n\nexport type SsoDomainVerdict =\n /** Domain is not governed. Any pool is fine — this is most of the world. */\n | 'allow-ungoverned'\n /** Governed domain, signed in through the tenant we designated for it. */\n | 'allow-designated-tenant'\n /**\n * Governed domain, signed in through SOME tenant, but not the designated\n * one. Allowed — they did use SSO, and refusing would invent a restriction\n * nobody asked for — but surfaced so a staff-access review can see it.\n */\n | 'allow-foreign-tenant'\n /**\n * Governed domain, no tenant, but the address is named in\n * {@link SSO_EXEMPT_EMAILS_ENV}. Allowed and reviewable.\n */\n | 'allow-exempt'\n /**\n * Governed domain with NO tenant at all: a project-pool password or consumer\n * Google sign-in. The only refusal this policy ever produces.\n */\n | 'refuse-sso-required'\n\nexport interface SsoDomainDecision {\n verdict: SsoDomainVerdict\n /**\n * Whether enforcement WOULD refuse this identity. Independent of whether\n * enforcement is currently switched on — {@link ssoDomainEnforcementEnabled}\n * decides that — so the same evaluation can drive both an audit in\n * report-only mode and the refusal once the switch is flipped.\n */\n refused: boolean\n /** Lower-cased domain, or null when the identity has no email address. */\n domain: string | null\n /** Tenant this domain is required to use, or null when ungoverned. */\n requiredTenantId: string | null\n /** Tenant the identity actually signed in through; null = project pool. */\n tenantId: string | null\n /** Worth a human look even though it is allowed (foreign-tenant case). */\n reviewable: boolean\n}\n\nexport interface SsoDomainIdentity {\n /** The identity's email address. Absent/empty is treated as ungoverned. */\n email?: string | null\n /**\n * GCIP tenant the identity signed in through — `decoded.firebase?.tenant`,\n * or a `PooledUserRecord.tenantId`. Null/undefined means the project pool.\n *\n * Never inferred and never defaulted to a hard-coded tenant: a uid is only\n * unique WITHIN a pool, and assuming one is how a lookup silently lands on\n * the wrong record.\n */\n tenantId?: string | null\n}\n\n/** The domain part of an address, lower-cased. Null when there isn't one. */\nexport function domainOf(email: string | null | undefined): string | null {\n const address = String(email ?? '').trim().toLowerCase()\n const at = address.lastIndexOf('@')\n if (at < 0 || at === address.length - 1) return null\n return address.slice(at + 1)\n}\n\n/**\n * Decide the policy for one identity. Pure and total — no Firebase, no env —\n * so a spec can drive every combination directly, and so the audit view and\n * the enforcement path can never disagree about what the policy says.\n */\nexport function evaluateSsoDomainPolicy(\n identity: SsoDomainIdentity,\n domains: SsoRequiredDomains = ssoRequiredDomains(),\n exempt: ReadonlySet<string> = ssoExemptEmails(),\n): SsoDomainDecision {\n const domain = domainOf(identity.email)\n const tenantId = identity.tenantId ?? null\n // Exact-match lookup, never a suffix test: `notaglyn.com` ends with\n // `aglyn.com`, and a suffix test would refuse an unrelated company's staff.\n const requiredTenantId = domain\n ? (Object.prototype.hasOwnProperty.call(domains, domain)\n ? domains[domain]\n : null)\n : null\n\n if (!requiredTenantId) {\n // Ungoverned: a personal address, a customer's address, anything not on\n // the list. Includes the permanent break-glass account by construction\n // rather than by special case — see the staff-access doc.\n return {\n verdict: 'allow-ungoverned',\n refused: false,\n domain,\n requiredTenantId: null,\n tenantId,\n reviewable: false,\n }\n }\n\n if (tenantId === requiredTenantId) {\n return {\n verdict: 'allow-designated-tenant',\n refused: false,\n domain,\n requiredTenantId,\n tenantId,\n reviewable: false,\n }\n }\n\n if (tenantId) {\n // A governed address inside somebody else's tenant. They authenticated\n // through an IdP, so the hole this policy closes is not open here — but\n // the IdP is not one Aglyn controls, so it is flagged for review.\n return {\n verdict: 'allow-foreign-tenant',\n refused: false,\n domain,\n requiredTenantId,\n tenantId,\n reviewable: true,\n }\n }\n\n if (exempt.has(String(identity.email ?? '').trim().toLowerCase())) {\n return {\n verdict: 'allow-exempt',\n refused: false,\n domain,\n requiredTenantId,\n tenantId: null,\n reviewable: true,\n }\n }\n\n return {\n verdict: 'refuse-sso-required',\n refused: true,\n domain,\n requiredTenantId,\n tenantId: null,\n reviewable: true,\n }\n}\n\n/**\n * THE ENFORCEMENT SWITCH — ships OFF.\n *\n * Off means `evaluateSsoDomainPolicy` still computes `refused`, and callers\n * still record it, but nobody is turned away. That is deliberate: the audit\n * trail accumulates under the real rule before the rule bites, so flipping the\n * switch holds no surprises.\n *\n * Opt-in by exact string. Anything else — unset, empty, `false`, `0`, a typo —\n * is OFF. A security control that switches itself on through a misspelling is\n * a control that can lock people out through a misspelling.\n *\n * Note both halves must be set for anything to happen: this switch AND a\n * non-empty {@link SSO_REQUIRED_DOMAINS_ENV}. A self-host install that sets\n * only this switch still governs nothing.\n *\n * **Precondition for flipping it — written down so it is not re-litigated:**\n * 1. SSO staff access verified working through a REAL sign-in (not a token\n * inspection): a staff account reaches `/admin/*` via the SAML tenant.\n * 2. Every identity on a governed domain has been migrated into its tenant,\n * retired, or named in {@link SSO_EXEMPT_EMAILS_ENV}. An automation or\n * reviewer account is the one that bites without warning: nobody is\n * watching a sign-in page when it fails.\n *\n * A second staff identity is NOT a precondition: the permanent break-glass\n * account is on an ungoverned domain, so this rule can never refuse it.\n */\nexport const SSO_DOMAIN_ENFORCEMENT_ENV = 'AGLYN_SSO_DOMAIN_ENFORCEMENT'\n\nexport function ssoDomainEnforcementEnabled(\n env: Record<string, string | undefined> = process.env,\n): boolean {\n return env[SSO_DOMAIN_ENFORCEMENT_ENV] === 'on'\n}\n\n/**\n * Whether an account about to be CREATED must be refused. Same switch, same\n * domains, same exemptions as the session mint, so an address the mint would\n * turn away is never created in the first place, and an address it admits\n * is never refused here.\n */\nexport function ssoDomainCreationRefused(\n identity: SsoDomainIdentity,\n env: Record<string, string | undefined> = process.env,\n): boolean {\n if (!ssoDomainEnforcementEnabled(env)) return false\n return evaluateSsoDomainPolicy(\n identity,\n ssoRequiredDomains(env),\n ssoExemptEmails(env),\n ).refused\n}\n// #endregion sso-domain-policy\n\n/**\n * What the refused person is told. Names the fix, not the mechanism.\n *\n * `PLATFORM_BRAND_NAME`, not a literal (AGL-2214). Everything else in this\n * module is careful that the RULE is configuration rather than a compiled-in\n * assumption about Aglyn — and then the one string a refused person actually\n * reads named us anyway. A self-hoster who governs their own domain would\n * have turned their own staff away in our name.\n *\n * Byte-identical for a deployment that has not renamed itself.\n */\nexport const SSO_DOMAIN_REFUSAL_MESSAGE =\n `Sign in with your ${PLATFORM_BRAND_NAME} Workspace account ` +\n '(Single sign-on). Accounts on this domain cannot use a password or ' +\n 'personal Google sign-in.'\n\n/**\n * The refusal a caller should return, or null to carry on.\n *\n * Returns null whenever the switch is off, so wiring this into an\n * authentication path is inert until the account owner flips it — the call site is live,\n * the consequence is not.\n */\nexport function ssoDomainRefusal(\n identity: SsoDomainIdentity,\n env: Record<string, string | undefined> = process.env,\n): { decision: SsoDomainDecision; response: Response } | null {\n const decision = evaluateSsoDomainPolicy(\n identity,\n ssoRequiredDomains(env),\n ssoExemptEmails(env),\n )\n if (!decision.refused) return null\n if (!ssoDomainEnforcementEnabled(env)) return null\n return {\n decision,\n response: Response.json(\n {\n error: SSO_DOMAIN_REFUSAL_MESSAGE,\n reason: 'sso-domain-required',\n domain: decision.domain,\n },\n { status: 403 },\n ),\n }\n}\n\nexport default evaluateSsoDomainPolicy\n"],"names":["PLATFORM_BRAND_NAME","SSO_REQUIRED_DOMAINS_ENV","parseSsoRequiredDomains","raw","map","pair","String","split","eq","indexOf","domain","slice","trim","toLowerCase","tenantId","ssoRequiredDomains","env","process","SSO_EXEMPT_EMAILS_ENV","parseSsoExemptEmails","emails","Set","entry","email","includes","add","ssoExemptEmails","domainOf","address","at","lastIndexOf","length","evaluateSsoDomainPolicy","identity","domains","exempt","requiredTenantId","Object","prototype","hasOwnProperty","call","verdict","refused","reviewable","has","SSO_DOMAIN_ENFORCEMENT_ENV","ssoDomainEnforcementEnabled","ssoDomainCreationRefused","SSO_DOMAIN_REFUSAL_MESSAGE","ssoDomainRefusal","decision","response","Response","json","error","reason","status"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CC,GAED;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,SAASA,mBAAmB,QAAQ,w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GACD,OAAO,MAAME,6BAA6B,+BAA8B;AAExE,OAAO,SAASC,4BACd9B,MAA0CC,QAAQD,GAAG;IAErD,OAAOA,GAAG,CAAC6B,2BAA2B,KAAK;AAC7C;AAEA;;;;;CAKC,GACD,OAAO,SAASE,yBACdd,QAA2B,EAC3BjB,MAA0CC,QAAQD,GAAG;IAErD,IAAI,CAAC8B,4BAA4B9B,MAAM,OAAO;IAC9C,OAAOgB,wBACLC,UACAlB,mBAAmBC,MACnBU,gBAAgBV,MAChB0B,OAAO;AACX;AACA,+BAA+B;AAE/B;;;;;;;;;;CAUC,GACD,OAAO,MAAMM,6BACX,CAAC,kBAAkB,EAAEhD,oBAAoB,mBAAmB,CAAC,GAC7D,wEACA,2BAA0B;AAE5B;;;;;;CAMC,GACD,OAAO,SAASiD,iBACdhB,QAA2B,EAC3BjB,MAA0CC,QAAQD,GAAG;IAErD,MAAMkC,WAAWlB,wBACfC,UACAlB,mBAAmBC,MACnBU,gBAAgBV;IAElB,IAAI,CAACkC,SAASR,OAAO,EAAE,OAAO;IAC9B,IAAI,CAACI,4BAA4B9B,MAAM,OAAO;IAC9C,OAAO;QACLkC;QACAC,UAAUC,SAASC,IAAI,CACrB;YACEC,OAAON;YACPO,QAAQ;YACR7C,QAAQwC,SAASxC,MAAM;QACzB,GACA;YAAE8C,QAAQ;QAAI;IAElB;AACF;AAEA,eAAexB,wBAAuB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/sso-domain-policy.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 * Workspace-domain SSO policy (AGL-1993).\n *\n * **The rule is about a DOMAIN, not about staff.** An `@aglyn.com` address is a\n * Google Workspace identity, and Workspace is what enforces MFA, disables an\n * account at offboarding, and lets an admin revoke a session. An `@aglyn.com`\n * address that signs in through a project-pool password or a consumer Google\n * account has none of that: it looks like a company identity and is governed\n * like a personal one. That gap is the whole reason this module exists.\n *\n * ## Staff is a SEPARATE axis and this module never reads it\n *\n * Staff may be granted to anybody — SSO or not, `@aglyn.com` or not, project\n * pool or any GCIP tenant including a *customer's*. Nothing here consults the\n * `staff` claim, and `sso-domain-policy.spec.ts` pins that by evaluating every\n * staff permutation and asserting the verdict does not move. The two axes are\n * independent; conflating them would turn a narrow domain control into an\n * accidental SSO mandate for staff, which is explicitly not the policy.\n *\n * These all remain valid, and each has a test:\n *\n * | identity | staff | verdict |\n * | ------------------------------------------ | ----- | ------------------------- |\n * | `@aglyn.com` in the designated tenant | yes | allowed |\n * | personal address, project pool (break-glass)| yes | allowed — permanent design|\n * | personal address, project pool | no | allowed |\n * | SSO identity in a CUSTOMER org's tenant | yes | allowed |\n * | `@aglyn.com` in the PROJECT pool | any | **refused** when enforced |\n *\n * Only the last row is what the switch exists for.\n *\n * ## How this differs from `sso-enforcement.ts`\n *\n * {@link enforceSsoSignInMethods} (AGL-1128/1129) strips non-IdP providers from\n * accounts that are ALREADY INSIDE a tenant. It cannot see an identity that\n * never joined the tenant at all — a project-pool `@aglyn.com` account is\n * invisible to every tenant sweep, by construction. Measured on aglyn-main on\n * 2026-08-18: two such accounts existed, one of them holding a live\n * `google.com` provider. This module covers that outside-the-tenant half.\n *\n * ## Shape note: deliberately NOT a discriminated union\n *\n * `strictNullChecks` is off repo-wide, which defeats boolean-discriminant\n * narrowing — a spec can read the wrong arm of a union and pass silently. So\n * the decision is ONE flat interface with a string `verdict`, and specs assert\n * the literal. There is no arm to read by mistake.\n */\n\n/**\n * ## Self-hosting: this policy is CONFIGURATION, never a compiled-in constant\n *\n * Aglyn ships in two shapes — the Aglyn-operated SaaS, and self-hosted installs\n * on the operator's own Firebase project. `aglyn.com` is *our* Workspace\n * domain; a self-hoster has their own domain, their own IdP, or none at all.\n * Baking our domain in would make the rule dead weight for them at best and a\n * lockout at worst, so the governed set is read from configuration and is\n * **empty by default**.\n *\n * Empty means the rule does nothing. That is simultaneously the correct\n * behaviour for a fresh self-host install and the correct OFF state for us —\n * one default serving both, rather than a special case for either.\n *\n * Format — `domain=tenantId`, comma or whitespace separated:\n *\n * ```\n * AGLYN_SSO_REQUIRED_DOMAINS=\"aglyn.com=aglyn-org-y5v14\"\n * ```\n *\n * A map rather than a bare list because \"must use SSO\" is meaningless without\n * naming WHOSE SSO: the point is IdP lifecycle control, which only the tenant\n * wired to that domain's SAML provider delivers.\n */\nimport { PLATFORM_BRAND_NAME } from '@aglyn/aglyn/app-utils/platform-brand'\n\n/**\n * The block below runs in two places: here, at the session mint, and in the\n * `cloud/functions` account-creation blocking function, which refuses the\n * account before it exists. `cloud/functions` is a plain npm package that can\n * import only firebase-admin and firebase-functions, so it holds a verbatim\n * copy (`cloud/functions/src/sso-domain-policy.ts`), and\n * `apps/console/specs/sso-domain-creation-wiring.spec.ts` fails if the two\n * differ by a single character. Change it here, then copy the region across.\n */\n// #region sso-domain-policy\nexport const SSO_REQUIRED_DOMAINS_ENV = 'AGLYN_SSO_REQUIRED_DOMAINS'\n\nexport type SsoRequiredDomains = Readonly<Record<string, string>>\n\n/**\n * Parse the configured domain→tenant map. Total: anything unparseable is\n * dropped rather than throwing, because this sits on the authentication path\n * and a malformed env var must not take sign-in down. A dropped entry fails\n * OPEN (the domain is simply ungoverned), which is the safe direction for a\n * rule whose only power is to refuse.\n */\nexport function parseSsoRequiredDomains(\n raw: string | null | undefined,\n): SsoRequiredDomains {\n const map: Record<string, string> = {}\n for (const pair of String(raw ?? '').split(/[,\\s]+/)) {\n if (!pair) continue\n const eq = pair.indexOf('=')\n if (eq <= 0) continue\n const domain = pair.slice(0, eq).trim().toLowerCase()\n const tenantId = pair.slice(eq + 1).trim()\n if (!domain || !tenantId) continue\n map[domain] = tenantId\n }\n return map\n}\n\n/**\n * The operator's SSO-required domains. Empty unless configured — see above.\n */\nexport function ssoRequiredDomains(\n env: Record<string, string | undefined> = process.env,\n): SsoRequiredDomains {\n return parseSsoRequiredDomains(env[SSO_REQUIRED_DOMAINS_ENV])\n}\n\n/**\n * Addresses on a governed domain that may still sign in OUTSIDE its tenant.\n *\n * For accounts that cannot use the IdP at all because someone outside the\n * company has to sign in with them: the demo login an app store reviewer is\n * given, for example, or an automated sign-up check that creates a new\n * plus-addressed account on every run. Every exception is named and can be\n * read back from configuration:\n *\n * ```\n * AGLYN_SSO_EXEMPT_EMAILS=\"reviewer@example.com ops+signup-canary*@example.com\"\n * ```\n *\n * An entry is an exact address, or one mailbox's plus tag followed by `*`,\n * which also admits every address that extends that tag on the same domain.\n * The `*` is accepted only as the last character of the local part and only\n * after a `+`, so no entry can exempt a whole mailbox or a whole domain; any\n * other entry with a `*` is dropped.\n *\n * Comma or whitespace separated, compared lower-cased. Empty by default.\n */\nexport const SSO_EXEMPT_EMAILS_ENV = 'AGLYN_SSO_EXEMPT_EMAILS'\n\nexport function parseSsoExemptEmails(\n raw: string | null | undefined,\n): ReadonlySet<string> {\n const emails = new Set<string>()\n for (const entry of String(raw ?? '').split(/[,\\s]+/)) {\n const email = entry.trim().toLowerCase()\n const at = email.lastIndexOf('@')\n if (at <= 0 || at === email.length - 1) continue\n if (email.slice(at + 1).includes('*')) continue\n const local = email.slice(0, at)\n const star = local.indexOf('*')\n if (star !== -1) {\n const plus = local.indexOf('+')\n // One trailing `*`, after a non-empty plus tag: `name+tag*`.\n if (star !== local.length - 1 || plus <= 0 || plus >= star - 1) continue\n }\n emails.add(email)\n }\n return emails\n}\n\n/** Whether an address is named by one of the parsed exemption entries. */\nexport function isSsoExemptEmail(\n email: string | null | undefined,\n exempt: ReadonlySet<string>,\n): boolean {\n const address = String(email ?? '').trim().toLowerCase()\n if (!address) return false\n if (exempt.has(address)) return true\n const at = address.lastIndexOf('@')\n if (at <= 0) return false\n const local = address.slice(0, at)\n const domain = address.slice(at + 1)\n for (const entry of exempt) {\n if (!entry.endsWith(`*@${domain}`)) continue\n if (local.startsWith(entry.slice(0, entry.length - domain.length - 2))) {\n return true\n }\n }\n return false\n}\n\nexport function ssoExemptEmails(\n env: Record<string, string | undefined> = process.env,\n): ReadonlySet<string> {\n return parseSsoExemptEmails(env[SSO_EXEMPT_EMAILS_ENV])\n}\n\nexport type SsoDomainVerdict =\n /** Domain is not governed. Any pool is fine — this is most of the world. */\n | 'allow-ungoverned'\n /** Governed domain, signed in through the tenant we designated for it. */\n | 'allow-designated-tenant'\n /**\n * Governed domain, signed in through SOME tenant, but not the designated\n * one. Allowed — they did use SSO, and refusing would invent a restriction\n * nobody asked for — but surfaced so a staff-access review can see it.\n */\n | 'allow-foreign-tenant'\n /**\n * Governed domain, no tenant, but the address is named in\n * {@link SSO_EXEMPT_EMAILS_ENV}. Allowed and reviewable.\n */\n | 'allow-exempt'\n /**\n * Governed domain with NO tenant at all: a project-pool password or consumer\n * Google sign-in. The only refusal this policy ever produces.\n */\n | 'refuse-sso-required'\n\nexport interface SsoDomainDecision {\n verdict: SsoDomainVerdict\n /**\n * Whether enforcement WOULD refuse this identity. Independent of whether\n * enforcement is currently switched on — {@link ssoDomainEnforcementEnabled}\n * decides that — so the same evaluation can drive both an audit in\n * report-only mode and the refusal once the switch is flipped.\n */\n refused: boolean\n /** Lower-cased domain, or null when the identity has no email address. */\n domain: string | null\n /** Tenant this domain is required to use, or null when ungoverned. */\n requiredTenantId: string | null\n /** Tenant the identity actually signed in through; null = project pool. */\n tenantId: string | null\n /** Worth a human look even though it is allowed (foreign-tenant case). */\n reviewable: boolean\n}\n\nexport interface SsoDomainIdentity {\n /** The identity's email address. Absent/empty is treated as ungoverned. */\n email?: string | null\n /**\n * GCIP tenant the identity signed in through — `decoded.firebase?.tenant`,\n * or a `PooledUserRecord.tenantId`. Null/undefined means the project pool.\n *\n * Never inferred and never defaulted to a hard-coded tenant: a uid is only\n * unique WITHIN a pool, and assuming one is how a lookup silently lands on\n * the wrong record.\n */\n tenantId?: string | null\n}\n\n/** The domain part of an address, lower-cased. Null when there isn't one. */\nexport function domainOf(email: string | null | undefined): string | null {\n const address = String(email ?? '').trim().toLowerCase()\n const at = address.lastIndexOf('@')\n if (at < 0 || at === address.length - 1) return null\n return address.slice(at + 1)\n}\n\n/**\n * Decide the policy for one identity. Pure and total — no Firebase, no env —\n * so a spec can drive every combination directly, and so the audit view and\n * the enforcement path can never disagree about what the policy says.\n */\nexport function evaluateSsoDomainPolicy(\n identity: SsoDomainIdentity,\n domains: SsoRequiredDomains = ssoRequiredDomains(),\n exempt: ReadonlySet<string> = ssoExemptEmails(),\n): SsoDomainDecision {\n const domain = domainOf(identity.email)\n const tenantId = identity.tenantId ?? null\n // Exact-match lookup, never a suffix test: `notaglyn.com` ends with\n // `aglyn.com`, and a suffix test would refuse an unrelated company's staff.\n const requiredTenantId = domain\n ? (Object.prototype.hasOwnProperty.call(domains, domain)\n ? domains[domain]\n : null)\n : null\n\n if (!requiredTenantId) {\n // Ungoverned: a personal address, a customer's address, anything not on\n // the list. Includes the permanent break-glass account by construction\n // rather than by special case — see the staff-access doc.\n return {\n verdict: 'allow-ungoverned',\n refused: false,\n domain,\n requiredTenantId: null,\n tenantId,\n reviewable: false,\n }\n }\n\n if (tenantId === requiredTenantId) {\n return {\n verdict: 'allow-designated-tenant',\n refused: false,\n domain,\n requiredTenantId,\n tenantId,\n reviewable: false,\n }\n }\n\n if (tenantId) {\n // A governed address inside somebody else's tenant. They authenticated\n // through an IdP, so the hole this policy closes is not open here — but\n // the IdP is not one Aglyn controls, so it is flagged for review.\n return {\n verdict: 'allow-foreign-tenant',\n refused: false,\n domain,\n requiredTenantId,\n tenantId,\n reviewable: true,\n }\n }\n\n if (isSsoExemptEmail(identity.email, exempt)) {\n return {\n verdict: 'allow-exempt',\n refused: false,\n domain,\n requiredTenantId,\n tenantId: null,\n reviewable: true,\n }\n }\n\n return {\n verdict: 'refuse-sso-required',\n refused: true,\n domain,\n requiredTenantId,\n tenantId: null,\n reviewable: true,\n }\n}\n\n/**\n * THE ENFORCEMENT SWITCH — ships OFF.\n *\n * Off means `evaluateSsoDomainPolicy` still computes `refused`, and callers\n * still record it, but nobody is turned away. That is deliberate: the audit\n * trail accumulates under the real rule before the rule bites, so flipping the\n * switch holds no surprises.\n *\n * Opt-in by exact string. Anything else — unset, empty, `false`, `0`, a typo —\n * is OFF. A security control that switches itself on through a misspelling is\n * a control that can lock people out through a misspelling.\n *\n * Note both halves must be set for anything to happen: this switch AND a\n * non-empty {@link SSO_REQUIRED_DOMAINS_ENV}. A self-host install that sets\n * only this switch still governs nothing.\n *\n * **Precondition for flipping it — written down so it is not re-litigated:**\n * 1. SSO staff access verified working through a REAL sign-in (not a token\n * inspection): a staff account reaches `/admin/*` via the SAML tenant.\n * 2. Every identity on a governed domain has been migrated into its tenant,\n * retired, or named in {@link SSO_EXEMPT_EMAILS_ENV}. An automation or\n * reviewer account is the one that bites without warning: nobody is\n * watching a sign-in page when it fails.\n *\n * A second staff identity is NOT a precondition: the permanent break-glass\n * account is on an ungoverned domain, so this rule can never refuse it.\n */\nexport const SSO_DOMAIN_ENFORCEMENT_ENV = 'AGLYN_SSO_DOMAIN_ENFORCEMENT'\n\nexport function ssoDomainEnforcementEnabled(\n env: Record<string, string | undefined> = process.env,\n): boolean {\n return env[SSO_DOMAIN_ENFORCEMENT_ENV] === 'on'\n}\n\n/**\n * Whether an account about to be CREATED must be refused. Same switch, same\n * domains, same exemptions as the session mint, so an address the mint would\n * turn away is never created in the first place, and an address it admits\n * is never refused here.\n */\nexport function ssoDomainCreationRefused(\n identity: SsoDomainIdentity,\n env: Record<string, string | undefined> = process.env,\n): boolean {\n if (!ssoDomainEnforcementEnabled(env)) return false\n return evaluateSsoDomainPolicy(\n identity,\n ssoRequiredDomains(env),\n ssoExemptEmails(env),\n ).refused\n}\n// #endregion sso-domain-policy\n\n/**\n * What the refused person is told. Names the fix, not the mechanism.\n *\n * `PLATFORM_BRAND_NAME`, not a literal (AGL-2214). Everything else in this\n * module is careful that the RULE is configuration rather than a compiled-in\n * assumption about Aglyn — and then the one string a refused person actually\n * reads named us anyway. A self-hoster who governs their own domain would\n * have turned their own staff away in our name.\n *\n * Byte-identical for a deployment that has not renamed itself.\n */\nexport const SSO_DOMAIN_REFUSAL_MESSAGE =\n `Sign in with your ${PLATFORM_BRAND_NAME} Workspace account ` +\n '(Single sign-on). Accounts on this domain cannot use a password or ' +\n 'personal Google sign-in.'\n\n/**\n * The refusal a caller should return, or null to carry on.\n *\n * Returns null whenever the switch is off, so wiring this into an\n * authentication path is inert until the account owner flips it — the call site is live,\n * the consequence is not.\n */\nexport function ssoDomainRefusal(\n identity: SsoDomainIdentity,\n env: Record<string, string | undefined> = process.env,\n): { decision: SsoDomainDecision; response: Response } | null {\n const decision = evaluateSsoDomainPolicy(\n identity,\n ssoRequiredDomains(env),\n ssoExemptEmails(env),\n )\n if (!decision.refused) return null\n if (!ssoDomainEnforcementEnabled(env)) return null\n return {\n decision,\n response: Response.json(\n {\n error: SSO_DOMAIN_REFUSAL_MESSAGE,\n reason: 'sso-domain-required',\n domain: decision.domain,\n },\n { status: 403 },\n ),\n }\n}\n\nexport default evaluateSsoDomainPolicy\n"],"names":["PLATFORM_BRAND_NAME","SSO_REQUIRED_DOMAINS_ENV","parseSsoRequiredDomains","raw","map","pair","String","split","eq","indexOf","domain","slice","trim","toLowerCase","tenantId","ssoRequiredDomains","env","process","SSO_EXEMPT_EMAILS_ENV","parseSsoExemptEmails","emails","Set","entry","email","at","lastIndexOf","length","includes","local","star","plus","add","isSsoExemptEmail","exempt","address","has","endsWith","startsWith","ssoExemptEmails","domainOf","evaluateSsoDomainPolicy","identity","domains","requiredTenantId","Object","prototype","hasOwnProperty","call","verdict","refused","reviewable","SSO_DOMAIN_ENFORCEMENT_ENV","ssoDomainEnforcementEnabled","ssoDomainCreationRefused","SSO_DOMAIN_REFUSAL_MESSAGE","ssoDomainRefusal","decision","response","Response","json","error","reason","status"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CC,GAED;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,SAASA,mBAAmB,QAAQ,wCAAuC;AAE3E;;;;;;;;CAQC,GACD,4BAA4B;AAC5B,OAAO,MAAMC,2BAA2B,6BAA4B;AAIpE;;;;;;CAMC,GACD,OAAO,SAASC,wBACdC,GAA8B;IAE9B,MAAMC,MAA8B,CAAC;IACrC,KAAK,MAAMC,QAAQC,OAAOH,cAAAA,MAAO,IAAII,KAAK,CAAC,UAAW;QACpD,IAAI,CAACF,MAAM;QACX,MAAMG,KAAKH,KAAKI,OAAO,CAAC;QACxB,IAAID,MAAM,GAAG;QACb,MAAME,SAASL,KAAKM,KAAK,CAAC,GAAGH,IAAII,IAAI,GAAGC,WAAW;QACnD,MAAMC,WAAWT,KAAKM,KAAK,CAACH,KAAK,GAAGI,IAAI;QACxC,IAAI,CAACF,UAAU,CAACI,UAAU;QAC1BV,GAAG,CAACM,OAAO,GAAGI;IAChB;IACA,OAAOV;AACT;AAEA;;CAEC,GACD,OAAO,SAASW,mBACdC,MAA0CC,QAAQD,GAAG;IAErD,OAAOd,wBAAwBc,GAAG,CAACf,yBAAyB;AAC9D;AAEA;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,MAAMiB,wBAAwB,0BAAyB;AAE9D,OAAO,SAASC,qBACdhB,GAA8B;IAE9B,MAAMiB,SAAS,IAAIC;IACnB,KAAK,MAAMC,SAAShB,OAAOH,cAAAA,MAAO,IAAII,KAAK,CAAC,UAAW;QACrD,MAAMgB,QAAQD,MAAMV,IAAI,GAAGC,WAAW;QACtC,MAAMW,KAAKD,MAAME,WAAW,CAAC;QAC7B,IAAID,MAAM,KAAKA,OAAOD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,OAAO,MAAMC,6BAA6B,+BAA8B;AAExE,OAAO,SAASC,4BACdpC,MAA0CC,QAAQD,GAAG;IAErD,OAAOA,GAAG,CAACmC,2BAA2B,KAAK;AAC7C;AAEA;;;;;CAKC,GACD,OAAO,SAASE,yBACdZ,QAA2B,EAC3BzB,MAA0CC,QAAQD,GAAG;IAErD,IAAI,CAACoC,4BAA4BpC,MAAM,OAAO;IAC9C,OAAOwB,wBACLC,UACA1B,mBAAmBC,MACnBsB,gBAAgBtB,MAChBiC,OAAO;AACX;AACA,+BAA+B;AAE/B;;;;;;;;;;CAUC,GACD,OAAO,MAAMK,6BACX,CAAC,kBAAkB,EAAEtD,oBAAoB,mBAAmB,CAAC,GAC7D,wEACA,2BAA0B;AAE5B;;;;;;CAMC,GACD,OAAO,SAASuD,iBACdd,QAA2B,EAC3BzB,MAA0CC,QAAQD,GAAG;IAErD,MAAMwC,WAAWhB,wBACfC,UACA1B,mBAAmBC,MACnBsB,gBAAgBtB;IAElB,IAAI,CAACwC,SAASP,OAAO,EAAE,OAAO;IAC9B,IAAI,CAACG,4BAA4BpC,MAAM,OAAO;IAC9C,OAAO;QACLwC;QACAC,UAAUC,SAASC,IAAI,CACrB;YACEC,OAAON;YACPO,QAAQ;YACRnD,QAAQ8C,SAAS9C,MAAM;QACzB,GACA;YAAEoD,QAAQ;QAAI;IAElB;AACF;AAEA,eAAetB,wBAAuB"}
|
|
@@ -39,6 +39,10 @@ export declare function sendStaffAlertEmail(input: {
|
|
|
39
39
|
text: string;
|
|
40
40
|
/** Resend tag / log label. */
|
|
41
41
|
context: string;
|
|
42
|
+
/** Absolute link to where it is handled; the staff console when absent. */
|
|
43
|
+
url?: string | null;
|
|
44
|
+
/** The button's words for {@link url}. */
|
|
45
|
+
urlLabel?: string | null;
|
|
42
46
|
}): Promise<SendEmailResult>;
|
|
43
47
|
/**
|
|
44
48
|
* One operator alert (AGL-3375, AGL-3377), as the `operator-alert` system
|
|
@@ -51,6 +55,12 @@ export declare function sendOperatorAlertEmail(input: {
|
|
|
51
55
|
body?: string | null;
|
|
52
56
|
/** Absolute link to the item, when there is one. */
|
|
53
57
|
url?: string | null;
|
|
58
|
+
/** Its level and area, as "Must know · Payments". */
|
|
59
|
+
eyebrow?: string | null;
|
|
60
|
+
/** "Label: value" lines: which alert, which workspace or site, when. */
|
|
61
|
+
details?: string | null;
|
|
62
|
+
/** Absolute link to Staff → Operator alerts. */
|
|
63
|
+
settingsUrl?: string | null;
|
|
54
64
|
context: string;
|
|
55
65
|
}): Promise<SendEmailResult>;
|
|
56
66
|
/**
|
|
@@ -15,6 +15,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/ import { sendEmail } from "@aglyn/shared-util-email";
|
|
18
|
+
import { platformConsoleOrigin } from "@aglyn/aglyn/app-utils/platform-brand";
|
|
18
19
|
/**
|
|
19
20
|
* Staff alerts by email, from LIBRARY code (AGL-2925).
|
|
20
21
|
*
|
|
@@ -121,12 +122,15 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
121
122
|
}
|
|
122
123
|
export async function sendStaffAlertEmail(input) {
|
|
123
124
|
try {
|
|
125
|
+
var _input_url, _input_urlLabel;
|
|
124
126
|
// In the platform's header and footer, as the `staff-alert` system email
|
|
125
127
|
// (AGL-3367). Loaded lazily for the reason the meter is.
|
|
126
128
|
const { renderSystemEmailContent, systemEmailBrand } = await import("./render-system-email.js");
|
|
127
129
|
const content = await renderSystemEmailContent('staff-alert', {
|
|
128
130
|
'alert.subject': input.subject,
|
|
129
|
-
'alert.body': input.text
|
|
131
|
+
'alert.body': input.text,
|
|
132
|
+
'alert.url': String((_input_url = input.url) != null ? _input_url : '').trim() || `${platformConsoleOrigin()}/admin/overview`,
|
|
133
|
+
'alert.urlLabel': String((_input_urlLabel = input.urlLabel) != null ? _input_urlLabel : '').trim() || 'Open the staff console'
|
|
130
134
|
}, systemEmailBrand(null), // The last resort reads as the built-in copy does: subject, then body.
|
|
131
135
|
{
|
|
132
136
|
subject: input.subject,
|
|
@@ -148,14 +152,17 @@ export async function sendStaffAlertEmail(input) {
|
|
|
148
152
|
* nothing else should call it. Never throws.
|
|
149
153
|
*/ export async function sendOperatorAlertEmail(input) {
|
|
150
154
|
try {
|
|
151
|
-
var _input_body, _input_url;
|
|
155
|
+
var _input_body, _input_url, _input_eyebrow, _input_details, _input_settingsUrl;
|
|
152
156
|
const { renderSystemEmailContent, systemEmailBrand } = await import("./render-system-email.js");
|
|
153
157
|
const body = String((_input_body = input.body) != null ? _input_body : '').trim();
|
|
154
158
|
const url = String((_input_url = input.url) != null ? _input_url : '').trim();
|
|
155
159
|
const content = await renderSystemEmailContent('operator-alert', {
|
|
156
160
|
'alert.title': input.title,
|
|
157
161
|
'alert.body': body,
|
|
158
|
-
'alert.url': url
|
|
162
|
+
'alert.url': url,
|
|
163
|
+
'alert.eyebrow': String((_input_eyebrow = input.eyebrow) != null ? _input_eyebrow : '').trim() || 'Operator alert',
|
|
164
|
+
'alert.details': String((_input_details = input.details) != null ? _input_details : '').trim(),
|
|
165
|
+
settingsUrl: String((_input_settingsUrl = input.settingsUrl) != null ? _input_settingsUrl : '').trim() || `${platformConsoleOrigin()}/admin/operator-alerts`
|
|
159
166
|
}, systemEmailBrand(null), {
|
|
160
167
|
subject: input.title,
|
|
161
168
|
text: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/staff-alert-email.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 { sendEmail, type SendEmailResult } from '@aglyn/shared-util-email'\n\n/**\n * Staff alerts by email, from LIBRARY code (AGL-2925).\n *\n * One destination for every subsystem's alarm — the console's\n * `emailStaffAlert` in `apps/console/app/api/_lib/usage-alert-email.ts` sends\n * through here too — resolved by {@link resolveStaffAlertRecipients}\n * (AGL-3375). Nothing here throws, because the mail is a courtesy and the\n * refusal it announces is the control; with no address anywhere the answer\n * is `unconfigured`.\n *\n * Platform email metering is loaded lazily and only after a send, so that\n * importing this module — which every unit test of the meter does — never\n * pulls the Firestore-backed meter, and with it the admin app, into a test\n * that only wanted to count credits. The system-email renderer and the staff\n * roster, which read through the same admin app, are loaded the same way.\n */\n\n/** At most this many staff accounts are mailed when no inbox is configured. */\nconst STAFF_FALLBACK_MAX = 10\n\n/**\n * Where a staff alarm goes (AGL-3375), first answer wins:\n *\n * 1. `STAFF_ALERT_EMAIL`, the operator's one alerts inbox.\n * 2. The operator's published support address,\n * `NEXT_PUBLIC_OPERATOR_SUPPORT_EMAIL`, which every self-hosted install is\n * asked for and most set.\n * 3. Every staff account's own address, up to {@link STAFF_FALLBACK_MAX}.\n *\n * Only the first applies on a preview or development deployment.\n *\n * The chain exists because the alarms that matter most are the ones an\n * install nobody tuned would otherwise send to no one: card testing on its\n * checkout, a stolen card on its first subscription, a phishing campaign\n * held on its sending domain. An unset variable used to mean silence.\n *\n * Empty only when none of the three yields an address.\n */\nexport async function resolveStaffAlertRecipients(): Promise<string[]> {\n const configured = String(process.env.STAFF_ALERT_EMAIL ?? '').trim().toLowerCase()\n if (configured.includes('@')) return [configured]\n // A preview or development deployment says what it is; only a production\n // one, or a self-hosted install that sets no such thing, falls back. A\n // preview's alarms reaching the operator's real inbox would be noise.\n const deployment = String(process.env.VERCEL_ENV ?? '').trim()\n if (deployment && deployment !== 'production') return []\n const operator = String(process.env.NEXT_PUBLIC_OPERATOR_SUPPORT_EMAIL ?? '')\n .trim()\n .toLowerCase()\n if (operator.includes('@')) return [operator]\n try {\n const { findUserByUidAcrossPools, listStaffUidsAcrossPools } = await import(\n './auth-pools'\n )\n const uids = (await listStaffUidsAcrossPools()).slice(0, STAFF_FALLBACK_MAX)\n const addresses = new Set<string>()\n for (const uid of uids) {\n const pooled = await findUserByUidAcrossPools(uid).catch(() => null)\n const address = String(pooled?.record?.email ?? '').trim().toLowerCase()\n if (address.includes('@')) addresses.add(address)\n }\n return [...addresses]\n } catch (error) {\n console.error('[staff-alert-email] staff roster unavailable', error)\n return []\n }\n}\n\n/**\n * Sends one rendered alert to each operator recipient, one message each so\n * no staff member is shown another's address. Metered to the platform: our\n * own alarm is our own cost (AGL-1438). Never throws.\n */\nasync function sendToOperators(\n content: { subject: string; text: string; html?: string },\n context: string,\n): Promise<SendEmailResult> {\n const recipients = await resolveStaffAlertRecipients()\n if (!recipients.length) return { sent: false, reason: 'unconfigured' }\n let delivered: SendEmailResult | null = null\n let failure: SendEmailResult = { sent: false, reason: 'unconfigured' }\n let sent = 0\n for (const to of recipients) {\n const result = await sendEmail({ to, ...content, context })\n if (result.sent) {\n sent += 1\n delivered ??= result\n } else {\n failure = result\n }\n }\n if (sent) {\n const { meterPlatformEmail } = await import('./email-metering')\n await meterPlatformEmail(sent).catch(() => undefined)\n }\n // Delivered to anyone is delivered: one dead staff mailbox does not make\n // the alert a failure for the caller.\n return delivered ?? failure\n}\n\nexport async function sendStaffAlertEmail(input: {\n subject: string\n text: string\n /** Resend tag / log label. */\n context: string\n}): Promise<SendEmailResult> {\n try {\n // In the platform's header and footer, as the `staff-alert` system email\n // (AGL-3367). Loaded lazily for the reason the meter is.\n const { renderSystemEmailContent, systemEmailBrand } = await import(\n './render-system-email'\n )\n const content = await renderSystemEmailContent(\n 'staff-alert',\n { 'alert.subject': input.subject, 'alert.body': input.text },\n systemEmailBrand(null),\n // The last resort reads as the built-in copy does: subject, then body.\n { subject: input.subject, text: `${input.subject}\\n\\n${input.text}` },\n )\n return await sendToOperators(content, input.context)\n } catch (error) {\n console.error('[staff-alert-email] send failed', error)\n return { sent: false, reason: 'network' }\n }\n}\n\n/**\n * One operator alert (AGL-3375, AGL-3377), as the `operator-alert` system\n * email: the alert, a button to the item it is about, in the operator's own\n * brand. Sent by `raiseOperatorAlert` for every alert delivered immediately;\n * nothing else should call it. Never throws.\n */\nexport async function sendOperatorAlertEmail(input: {\n title: string\n body?: string | null\n /** Absolute link to the item, when there is one. */\n url?: string | null\n context: string\n}): Promise<SendEmailResult> {\n try {\n const { renderSystemEmailContent, systemEmailBrand } = await import(\n './render-system-email'\n )\n const body = String(input.body ?? '').trim()\n const url = String(input.url ?? '').trim()\n const content = await renderSystemEmailContent(\n 'operator-alert',\n { 'alert.title': input.title, 'alert.body': body, 'alert.url': url },\n systemEmailBrand(null),\n { subject: input.title, text: [input.title, body, url].filter(Boolean).join('\\n\\n') },\n )\n return await sendToOperators(content, input.context)\n } catch (error) {\n console.error('[staff-alert-email] operator alert failed', error)\n return { sent: false, reason: 'network' }\n }\n}\n\n/**\n * The day's batched operator alerts (AGL-3377), as the\n * `operator-alert-digest` system email. Sent by `sendOperatorAlertDigest`.\n * Never throws.\n */\nexport async function sendOperatorAlertDigestEmail(input: {\n /** The UTC day, `YYYY-MM-DD`. */\n date: string\n count: number\n /** The alerts, composed as one block of text. */\n body: string\n /** Absolute link to the staff console, when there is one. */\n url?: string | null\n}): Promise<SendEmailResult> {\n try {\n const { renderSystemEmailContent, systemEmailBrand } = await import(\n './render-system-email'\n )\n const subject = `${input.count} operator alert${input.count === 1 ? '' : 's'} on ${input.date}`\n const url = String(input.url ?? '').trim()\n const content = await renderSystemEmailContent(\n 'operator-alert-digest',\n {\n 'digest.title': subject,\n 'digest.date': input.date,\n 'digest.count': String(input.count),\n 'digest.body': input.body,\n 'digest.url': url,\n },\n systemEmailBrand(null),\n { subject, text: [subject, input.body, url].filter(Boolean).join('\\n\\n') },\n )\n return await sendToOperators(content, 'operator-alert-digest')\n } catch (error) {\n console.error('[staff-alert-email] operator digest failed', error)\n return { sent: false, reason: 'network' }\n }\n}\n"],"names":["sendEmail","STAFF_FALLBACK_MAX","resolveStaffAlertRecipients","process","configured","String","env","STAFF_ALERT_EMAIL","trim","toLowerCase","includes","deployment","VERCEL_ENV","operator","NEXT_PUBLIC_OPERATOR_SUPPORT_EMAIL","findUserByUidAcrossPools","listStaffUidsAcrossPools","uids","slice","addresses","Set","uid","pooled","catch","address","record","email","add","error","console","sendToOperators","content","context","recipients","length","sent","reason","delivered","failure","to","result","meterPlatformEmail","undefined","sendStaffAlertEmail","input","renderSystemEmailContent","systemEmailBrand","subject","text","sendOperatorAlertEmail","body","url","title","filter","Boolean","join","sendOperatorAlertDigestEmail","count","date"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,SAAS,QAA8B,2BAA0B;AAE1E;;;;;;;;;;;;;;;CAeC,GAED,6EAA6E,GAC7E,MAAMC,qBAAqB;AAE3B;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,eAAeC;QACMC,gCAKAA,yBAEFA;IAPxB,MAAMC,aAAaC,QAAOF,iCAAAA,QAAQG,GAAG,CAACC,iBAAiB,YAA7BJ,iCAAiC,IAAIK,IAAI,GAAGC,WAAW;IACjF,IAAIL,WAAWM,QAAQ,CAAC,MAAM,OAAO;QAACN;KAAW;IACjD,yEAAyE;IACzE,uEAAuE;IACvE,sEAAsE;IACtE,MAAMO,aAAaN,QAAOF,0BAAAA,QAAQG,GAAG,CAACM,UAAU,YAAtBT,0BAA0B,IAAIK,IAAI;IAC5D,IAAIG,cAAcA,eAAe,cAAc,OAAO,EAAE;IACxD,MAAME,WAAWR,QAAOF,kDAAAA,QAAQG,GAAG,CAACQ,kCAAkC,YAA9CX,kDAAkD,IACvEK,IAAI,GACJC,WAAW;IACd,IAAII,SAASH,QAAQ,CAAC,MAAM,OAAO;QAACG;KAAS;IAC7C,IAAI;QACF,MAAM,EAAEE,wBAAwB,EAAEC,wBAAwB,EAAE,GAAG,MAAM,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ACF;AAEA;;;;CAIC,GACD,OAAO,eAAeoB,6BAA6BZ,KAQlD;IACC,IAAI;YAKiBA;QAJnB,MAAM,EAAEC,wBAAwB,EAAEC,gBAAgB,EAAE,GAAG,MAAM,MAAM,CACjE;QAEF,MAAMC,UAAU,GAAGH,MAAMa,KAAK,CAAC,eAAe,EAAEb,MAAMa,KAAK,KAAK,IAAI,KAAK,IAAI,IAAI,EAAEb,MAAMc,IAAI,EAAE;QAC/F,MAAMP,MAAM9C,QAAOuC,aAAAA,MAAMO,GAAG,YAATP,aAAa,IAAIpC,IAAI;QACxC,MAAMuB,UAAU,MAAMc,yBACpB,yBACA;YACE,gBAAgBE;YAChB,eAAeH,MAAMc,IAAI;YACzB,gBAAgBrD,OAAOuC,MAAMa,KAAK;YAClC,eAAeb,MAAMM,IAAI;YACzB,cAAcC;QAChB,GACAL,iBAAiB,OACjB;YAAEC;YAASC,MAAM;gBAACD;gBAASH,MAAMM,IAAI;gBAAEC;aAAI,CAACE,MAAM,CAACC,SAASC,IAAI,CAAC;QAAQ;QAE3E,OAAO,MAAMzB,gBAAgBC,SAAS;IACxC,EAAE,OAAOH,OAAO;QACdC,QAAQD,KAAK,CAAC,8CAA8CA;QAC5D,OAAO;YAAEO,MAAM;YAAOC,QAAQ;QAAU;IAC1C;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/staff-alert-email.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 { sendEmail, type SendEmailResult } from '@aglyn/shared-util-email'\nimport { platformConsoleOrigin } from '@aglyn/aglyn/app-utils/platform-brand'\n\n/**\n * Staff alerts by email, from LIBRARY code (AGL-2925).\n *\n * One destination for every subsystem's alarm — the console's\n * `emailStaffAlert` in `apps/console/app/api/_lib/usage-alert-email.ts` sends\n * through here too — resolved by {@link resolveStaffAlertRecipients}\n * (AGL-3375). Nothing here throws, because the mail is a courtesy and the\n * refusal it announces is the control; with no address anywhere the answer\n * is `unconfigured`.\n *\n * Platform email metering is loaded lazily and only after a send, so that\n * importing this module — which every unit test of the meter does — never\n * pulls the Firestore-backed meter, and with it the admin app, into a test\n * that only wanted to count credits. The system-email renderer and the staff\n * roster, which read through the same admin app, are loaded the same way.\n */\n\n/** At most this many staff accounts are mailed when no inbox is configured. */\nconst STAFF_FALLBACK_MAX = 10\n\n/**\n * Where a staff alarm goes (AGL-3375), first answer wins:\n *\n * 1. `STAFF_ALERT_EMAIL`, the operator's one alerts inbox.\n * 2. The operator's published support address,\n * `NEXT_PUBLIC_OPERATOR_SUPPORT_EMAIL`, which every self-hosted install is\n * asked for and most set.\n * 3. Every staff account's own address, up to {@link STAFF_FALLBACK_MAX}.\n *\n * Only the first applies on a preview or development deployment.\n *\n * The chain exists because the alarms that matter most are the ones an\n * install nobody tuned would otherwise send to no one: card testing on its\n * checkout, a stolen card on its first subscription, a phishing campaign\n * held on its sending domain. An unset variable used to mean silence.\n *\n * Empty only when none of the three yields an address.\n */\nexport async function resolveStaffAlertRecipients(): Promise<string[]> {\n const configured = String(process.env.STAFF_ALERT_EMAIL ?? '').trim().toLowerCase()\n if (configured.includes('@')) return [configured]\n // A preview or development deployment says what it is; only a production\n // one, or a self-hosted install that sets no such thing, falls back. A\n // preview's alarms reaching the operator's real inbox would be noise.\n const deployment = String(process.env.VERCEL_ENV ?? '').trim()\n if (deployment && deployment !== 'production') return []\n const operator = String(process.env.NEXT_PUBLIC_OPERATOR_SUPPORT_EMAIL ?? '')\n .trim()\n .toLowerCase()\n if (operator.includes('@')) return [operator]\n try {\n const { findUserByUidAcrossPools, listStaffUidsAcrossPools } = await import(\n './auth-pools'\n )\n const uids = (await listStaffUidsAcrossPools()).slice(0, STAFF_FALLBACK_MAX)\n const addresses = new Set<string>()\n for (const uid of uids) {\n const pooled = await findUserByUidAcrossPools(uid).catch(() => null)\n const address = String(pooled?.record?.email ?? '').trim().toLowerCase()\n if (address.includes('@')) addresses.add(address)\n }\n return [...addresses]\n } catch (error) {\n console.error('[staff-alert-email] staff roster unavailable', error)\n return []\n }\n}\n\n/**\n * Sends one rendered alert to each operator recipient, one message each so\n * no staff member is shown another's address. Metered to the platform: our\n * own alarm is our own cost (AGL-1438). Never throws.\n */\nasync function sendToOperators(\n content: { subject: string; text: string; html?: string },\n context: string,\n): Promise<SendEmailResult> {\n const recipients = await resolveStaffAlertRecipients()\n if (!recipients.length) return { sent: false, reason: 'unconfigured' }\n let delivered: SendEmailResult | null = null\n let failure: SendEmailResult = { sent: false, reason: 'unconfigured' }\n let sent = 0\n for (const to of recipients) {\n const result = await sendEmail({ to, ...content, context })\n if (result.sent) {\n sent += 1\n delivered ??= result\n } else {\n failure = result\n }\n }\n if (sent) {\n const { meterPlatformEmail } = await import('./email-metering')\n await meterPlatformEmail(sent).catch(() => undefined)\n }\n // Delivered to anyone is delivered: one dead staff mailbox does not make\n // the alert a failure for the caller.\n return delivered ?? failure\n}\n\nexport async function sendStaffAlertEmail(input: {\n subject: string\n text: string\n /** Resend tag / log label. */\n context: string\n /** Absolute link to where it is handled; the staff console when absent. */\n url?: string | null\n /** The button's words for {@link url}. */\n urlLabel?: string | null\n}): Promise<SendEmailResult> {\n try {\n // In the platform's header and footer, as the `staff-alert` system email\n // (AGL-3367). Loaded lazily for the reason the meter is.\n const { renderSystemEmailContent, systemEmailBrand } = await import(\n './render-system-email'\n )\n const content = await renderSystemEmailContent(\n 'staff-alert',\n {\n 'alert.subject': input.subject,\n 'alert.body': input.text,\n 'alert.url':\n String(input.url ?? '').trim() || `${platformConsoleOrigin()}/admin/overview`,\n 'alert.urlLabel': String(input.urlLabel ?? '').trim() || 'Open the staff console',\n },\n systemEmailBrand(null),\n // The last resort reads as the built-in copy does: subject, then body.\n { subject: input.subject, text: `${input.subject}\\n\\n${input.text}` },\n )\n return await sendToOperators(content, input.context)\n } catch (error) {\n console.error('[staff-alert-email] send failed', error)\n return { sent: false, reason: 'network' }\n }\n}\n\n/**\n * One operator alert (AGL-3375, AGL-3377), as the `operator-alert` system\n * email: the alert, a button to the item it is about, in the operator's own\n * brand. Sent by `raiseOperatorAlert` for every alert delivered immediately;\n * nothing else should call it. Never throws.\n */\nexport async function sendOperatorAlertEmail(input: {\n title: string\n body?: string | null\n /** Absolute link to the item, when there is one. */\n url?: string | null\n /** Its level and area, as \"Must know · Payments\". */\n eyebrow?: string | null\n /** \"Label: value\" lines: which alert, which workspace or site, when. */\n details?: string | null\n /** Absolute link to Staff → Operator alerts. */\n settingsUrl?: string | null\n context: string\n}): Promise<SendEmailResult> {\n try {\n const { renderSystemEmailContent, systemEmailBrand } = await import(\n './render-system-email'\n )\n const body = String(input.body ?? '').trim()\n const url = String(input.url ?? '').trim()\n const content = await renderSystemEmailContent(\n 'operator-alert',\n {\n 'alert.title': input.title,\n 'alert.body': body,\n 'alert.url': url,\n 'alert.eyebrow': String(input.eyebrow ?? '').trim() || 'Operator alert',\n 'alert.details': String(input.details ?? '').trim(),\n settingsUrl:\n String(input.settingsUrl ?? '').trim() ||\n `${platformConsoleOrigin()}/admin/operator-alerts`,\n },\n systemEmailBrand(null),\n { subject: input.title, text: [input.title, body, url].filter(Boolean).join('\\n\\n') },\n )\n return await sendToOperators(content, input.context)\n } catch (error) {\n console.error('[staff-alert-email] operator alert failed', error)\n return { sent: false, reason: 'network' }\n }\n}\n\n/**\n * The day's batched operator alerts (AGL-3377), as the\n * `operator-alert-digest` system email. Sent by `sendOperatorAlertDigest`.\n * Never throws.\n */\nexport async function sendOperatorAlertDigestEmail(input: {\n /** The UTC day, `YYYY-MM-DD`. */\n date: string\n count: number\n /** The alerts, composed as one block of text. */\n body: string\n /** Absolute link to the staff console, when there is one. */\n url?: string | null\n}): Promise<SendEmailResult> {\n try {\n const { renderSystemEmailContent, systemEmailBrand } = await import(\n './render-system-email'\n )\n const subject = `${input.count} operator alert${input.count === 1 ? '' : 's'} on ${input.date}`\n const url = String(input.url ?? '').trim()\n const content = await renderSystemEmailContent(\n 'operator-alert-digest',\n {\n 'digest.title': subject,\n 'digest.date': input.date,\n 'digest.count': String(input.count),\n 'digest.body': input.body,\n 'digest.url': url,\n },\n systemEmailBrand(null),\n { subject, text: [subject, input.body, url].filter(Boolean).join('\\n\\n') },\n )\n return await sendToOperators(content, 'operator-alert-digest')\n } catch (error) {\n console.error('[staff-alert-email] operator digest failed', error)\n return { sent: false, reason: 'network' }\n }\n}\n"],"names":["sendEmail","platformConsoleOrigin","STAFF_FALLBACK_MAX","resolveStaffAlertRecipients","process","configured","String","env","STAFF_ALERT_EMAIL","trim","toLowerCase","includes","deployment","VERCEL_ENV","operator","NEXT_PUBLIC_OPERATOR_SUPPORT_EMAIL","findUserByUidAcrossPools","listStaffUidsAcrossPools","uids","slice","addresses","Set","uid","pooled","catch","address","record","email","add","error","console","sendToOperators","content","context","recipients","length","sent","reason","delivered","failure","to","result","meterPlatformEmail","undefined","sendStaffAlertEmail","input","renderSystemEmailContent","systemEmailBrand","subject","text","url","urlLabel","sendOperatorAlertEmail","body","title","eyebrow","details","settingsUrl","filter","Boolean","join","sendOperatorAlertDigestEmail","count","date"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,SAAS,QAA8B,2BAA0B;AAC1E,SAASC,qBAAqB,QAAQ,wCAAuC;AAE7E;;;;;;;;;;;;;;;CAeC,GAED,6EAA6E,GAC7E,MAAMC,qBAAqB;AAE3B;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,eAAeC;QACMC,gCAKAA,yBAEFA;IAPxB,MAAMC,aAAaC,QAAOF,iCAAAA,QAAQG,GAAG,CAACC,iBAAiB,YAA7B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