@aglyn/tenant-data-admin 1.0.0-beta.264 → 1.0.0-beta.268
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/organizations.js +8 -1
- package/src/lib/server/organizations.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/rate-limit-store.d.ts +12 -4
- package/src/lib/server/rate-limit-store.js +19 -4
- package/src/lib/server/rate-limit-store.js.map +1 -1
- package/src/lib/server/render-monitor.d.ts +36 -5
- package/src/lib/server/render-monitor.js +81 -22
- package/src/lib/server/render-monitor.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/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
|
@@ -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,MAAM,CACzE;QAEF,MAAMC,OAAO,AAAC,CAAA,MAAMD,0BAAyB,EAAGE,KAAK,CAAC,GAAGjB;QACzD,MAAMkB,YAAY,IAAIC;QACtB,KAAK,MAAMC,OAAOJ,KAAM;;gBAECK;YADvB,MAAMA,SAAS,MAAMP,yBAAyBM,KAAKE,KAAK,CAAC,IAAM;YAC/D,MAAMC,UAAUnB,e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AAI,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,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,IAA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