@aglyn/plugins-outreach 1.0.0-beta.173 → 1.0.0-beta.175
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 +13 -13
- package/src/lib/components/sequence-editor.js +10 -10
- package/src/lib/components/sequence-editor.js.map +1 -1
- package/src/lib/model/outreach.types.d.ts +1 -1
- package/src/lib/model/outreach.types.js.map +1 -1
- package/src/lib/routes/enroll-routes.js +8 -7
- package/src/lib/routes/enroll-routes.js.map +1 -1
- package/src/lib/routes/register-routes.js +2 -1
- package/src/lib/routes/register-routes.js.map +1 -1
- package/src/lib/routes/sequence-routes.js +9 -7
- package/src/lib/routes/sequence-routes.js.map +1 -1
- package/src/lib/runtime/campaign-credit.js +1 -0
- package/src/lib/runtime/campaign-credit.js.map +1 -1
- package/src/lib/runtime/platform-runtime-deps.js +2 -1
- package/src/lib/runtime/platform-runtime-deps.js.map +1 -1
- package/src/lib/runtime/runtime-deps.d.ts +6 -0
- package/src/lib/runtime/runtime-deps.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-outreach",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.175",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-data-mdi": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-ui-email-campaigns": "1.0.0-beta.
|
|
31
|
-
"@aglyn/shared-ui-jsx": "1.0.0-beta.
|
|
32
|
-
"@aglyn/shared-ui-next": "1.0.0-beta.
|
|
33
|
-
"@aglyn/shared-ui-snackstack": "1.0.0-beta.
|
|
34
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
35
|
-
"@aglyn/shared-util-timestamp": "1.0.0-beta.
|
|
36
|
-
"@aglyn/shared-util-tools": "1.0.0-beta.
|
|
37
|
-
"@aglyn/tenant-data-admin": "1.0.0-beta.
|
|
38
|
-
"@aglyn/tenant-feature-instance": "1.0.0-beta.
|
|
39
|
-
"@aglyn/tenant-runtime": "1.0.0-beta.
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.175",
|
|
29
|
+
"@aglyn/shared-data-mdi": "1.0.0-beta.175",
|
|
30
|
+
"@aglyn/shared-ui-email-campaigns": "1.0.0-beta.175",
|
|
31
|
+
"@aglyn/shared-ui-jsx": "1.0.0-beta.175",
|
|
32
|
+
"@aglyn/shared-ui-next": "1.0.0-beta.175",
|
|
33
|
+
"@aglyn/shared-ui-snackstack": "1.0.0-beta.175",
|
|
34
|
+
"@aglyn/shared-util-http": "1.0.0-beta.175",
|
|
35
|
+
"@aglyn/shared-util-timestamp": "1.0.0-beta.175",
|
|
36
|
+
"@aglyn/shared-util-tools": "1.0.0-beta.175",
|
|
37
|
+
"@aglyn/tenant-data-admin": "1.0.0-beta.175",
|
|
38
|
+
"@aglyn/tenant-feature-instance": "1.0.0-beta.175",
|
|
39
|
+
"@aglyn/tenant-runtime": "1.0.0-beta.175",
|
|
40
40
|
"@swc/helpers": "0.5.23"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
@@ -22,7 +22,7 @@ import { mdiPlus } from "@aglyn/shared-data-mdi";
|
|
|
22
22
|
import { CardDisplay, MdiIcon } from "@aglyn/shared-ui-jsx";
|
|
23
23
|
import CampaignPicker from "@aglyn/shared-ui-email-campaigns/components/campaign-picker.component";
|
|
24
24
|
import { useSnackbar } from "@aglyn/shared-ui-snackstack";
|
|
25
|
-
import {
|
|
25
|
+
import { useOrgCampaigns, useUser } from "@aglyn/tenant-feature-instance";
|
|
26
26
|
import { Alert, Autocomplete, Box, Button, Chip, FormControlLabel, Grid, Menu, MenuItem, Stack, Switch, TextField, Typography } from "@mui/material";
|
|
27
27
|
import { useEffect, useMemo, useState } from "react";
|
|
28
28
|
import { isInThreadEmailStep, OUTREACH_SEQUENCE_NAME_MAX, validateOutreachSequence } from "../engine/sequence-validation.js";
|
|
@@ -125,12 +125,12 @@ import { useOutreachEmailTemplates } from "./use-outreach-crm.js";
|
|
|
125
125
|
const mailbox = (_props_mailboxes_mailboxes_find = props.mailboxes.mailboxes.find((entry)=>entry.id === draft.mailboxId)) != null ? _props_mailboxes_mailboxes_find : null;
|
|
126
126
|
const archived = (sequence == null ? void 0 : sequence.status) === 'archived';
|
|
127
127
|
/*
|
|
128
|
-
* The
|
|
129
|
-
* is open
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*/ const campaigns =
|
|
133
|
-
enabled:
|
|
128
|
+
* The org's campaigns, for the picker (AGL-3254): read while the editor
|
|
129
|
+
* is open. A sequence is the organization's record and so is a campaign,
|
|
130
|
+
* so the choice is every campaign in the org, whichever site the
|
|
131
|
+
* sequence sends as.
|
|
132
|
+
*/ const campaigns = useOrgCampaigns(orgId, {
|
|
133
|
+
enabled: true
|
|
134
134
|
});
|
|
135
135
|
const issues = useMemo(()=>{
|
|
136
136
|
const judged = [
|
|
@@ -285,7 +285,7 @@ import { useOutreachEmailTemplates } from "./use-outreach-crm.js";
|
|
|
285
285
|
error: issueAt('mailboxId'),
|
|
286
286
|
disabled: archived
|
|
287
287
|
}),
|
|
288
|
-
|
|
288
|
+
/*#__PURE__*/ _jsx(CampaignPicker, {
|
|
289
289
|
options: campaigns.options,
|
|
290
290
|
value: draft.campaignIds,
|
|
291
291
|
onChange: (campaignIds)=>update({
|
|
@@ -295,8 +295,8 @@ import { useOutreachEmailTemplates } from "./use-outreach-crm.js";
|
|
|
295
295
|
helperText: (_issueAt1 = issueAt('campaignIds')) != null ? _issueAt1 : 'The campaigns this sequence is part of. Everyone enrolled joins them, and its sends, replies, meetings and conversions count on their pages.',
|
|
296
296
|
disabled: archived,
|
|
297
297
|
empty: campaigns.ready && !campaigns.options.length,
|
|
298
|
-
emptyText: "
|
|
299
|
-
})
|
|
298
|
+
emptyText: "There are no campaigns yet. Create one from Marketing to file this sequence under it."
|
|
299
|
+
})
|
|
300
300
|
]
|
|
301
301
|
})
|
|
302
302
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/outreach/src/lib/components/sequence-editor.tsx"],"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'use client'\n\nimport { pluginDocsHelp, type ConsolePluginOrgMount } from '@aglyn/aglyn'\nimport { mdiPlus } from '@aglyn/shared-data-mdi'\nimport { CardDisplay, MdiIcon } from '@aglyn/shared-ui-jsx'\nimport CampaignPicker from '@aglyn/shared-ui-email-campaigns/components/campaign-picker.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { useHostCampaigns, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Autocomplete,\n Box,\n Button,\n Chip,\n FormControlLabel,\n Grid,\n Menu,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useEffect, useMemo, useState } from 'react'\nimport {\n isInThreadEmailStep,\n OUTREACH_SEQUENCE_NAME_MAX,\n validateOutreachSequence,\n} from '../engine/sequence-validation'\nimport { outreachCountryLabel } from '../model/compliance-settings'\nimport {\n OUTREACH_MAX_EMAIL_STEPS,\n OUTREACH_MAX_STEPS,\n OUTREACH_TASK_KIND_LABELS,\n OUTREACH_TASK_KINDS,\n type OutreachSequence,\n type OutreachSequenceStep,\n type OutreachTaskKind,\n} from '../model/outreach.types'\nimport {\n emptyOutreachSequenceDraft,\n newOutreachEmailStep,\n newOutreachTaskStep,\n outreachSequenceDraftOf,\n type OutreachSequenceDraft,\n type OutreachSequenceIssue,\n} from '../model/sequence-draft'\nimport { OutreachSendWindowFields } from './send-window-fields'\nimport { OutreachSequenceMailboxPicker } from './sequence-mailbox-picker'\nimport { OutreachSequencePreview } from './sequence-preview'\nimport { OutreachStepCard } from './sequence-step-card'\nimport { OutreachRouteError, useOutreachApi } from './use-outreach-api'\nimport { useOutreachEmailTemplates } from './use-outreach-crm'\nimport type { OutreachMailboxesResult } from './use-outreach-mailboxes'\nimport type { OutreachSettingsLoad } from './use-outreach-settings'\n\nexport interface OutreachSequenceEditorProps {\n orgId: string\n orgMount?: ConsolePluginOrgMount\n /** The stored sequence, or `null` for a new one. */\n sequence: OutreachSequence | null\n /** The organization's compliance settings: its countries, and the preview's footer. */\n settings: OutreachSettingsLoad\n /**\n * The organization's mailboxes, from the Mailboxes section's listener:\n * what the picker offers, and who the preview's emails are from.\n */\n mailboxes: OutreachMailboxesResult\n /** The Mailboxes section, where the picker sends a member to connect one. */\n mailboxesPath: string\n onSaved(sequence: OutreachSequence): void\n onCancel?(): void\n}\n\n/** The step a dotted issue path is about, and the field within it. */\nfunction stepIssueKey(path: string): { index: number; field: string } | null {\n const match = /^steps\\.(\\d+)(?:\\.(.+))?$/.exec(path)\n if (!match) return null\n const field = match[2] ?? 'step'\n return { index: Number(match[1]), field: field === 'id' ? 'step' : field }\n}\n\n/**\n * The sequence editor (AGL-2980): the name, the site and mailbox, the steps,\n * who it sends to and when, beside a live preview of each email.\n *\n * Every issue the engine's validator finds is shown beside its field — the\n * same validator the save route refuses with — errors once a save was\n * attempted, warnings as soon as they appear. What only the server can\n * judge (whose mailbox, which countries the organization allows, what may\n * no longer change once people are enrolled) comes back from the save and\n * is shown in the same places.\n */\nexport function OutreachSequenceEditor(props: OutreachSequenceEditorProps) {\n const { orgId, orgMount, sequence, settings } = props\n const api = useOutreachApi(orgId)\n const { enqueueSnackbar } = useSnackbar()\n const { data: user } = useUser()\n const uid = user?.uid ?? null\n const mountedHosts = orgMount?.hosts\n const hosts = useMemo(() => mountedHosts ?? [], [mountedHosts])\n const orgCountries = settings.settings?.allowedCountries ?? ['US']\n\n const [draft, setDraft] = useState<OutreachSequenceDraft>(() =>\n sequence\n ? outreachSequenceDraftOf(sequence)\n : emptyOutreachSequenceDraft({\n hostId: hosts.length === 1 ? hosts[0].id : '',\n allowedCountries: orgCountries,\n }),\n )\n const [attempted, setAttempted] = useState(false)\n const [serverIssues, setServerIssues] = useState<OutreachSequenceIssue[]>([])\n const [saving, setSaving] = useState(false)\n const [taskAnchor, setTaskAnchor] = useState<HTMLElement | null>(null)\n\n // A stored sequence the listener updated (a save, a status change) is the\n // new starting point.\n useEffect(() => {\n if (sequence) setDraft(outreachSequenceDraftOf(sequence))\n }, [sequence])\n // A new sequence starts on the organization's countries once they are read.\n const settingsCountries = settings.settings?.allowedCountries.join(',')\n useEffect(() => {\n if (!sequence && settingsCountries) {\n setDraft((previous) => ({\n ...previous,\n settings: {\n ...previous.settings,\n allowedCountries: settingsCountries.split(','),\n },\n }))\n }\n }, [sequence, settingsCountries])\n useEffect(() => {\n if (!sequence && !draft.hostId && hosts.length === 1)\n setDraft((previous) => ({ ...previous, hostId: hosts[0].id }))\n }, [sequence, draft.hostId, hosts])\n\n // A new sequence starts on the member's own mailbox when they have exactly\n // one that is sending.\n const ownSending = props.mailboxes.mailboxes.filter(\n (entry) => entry.connectedByUid === uid && entry.status === 'connected',\n )\n const onlyOwnMailbox = ownSending.length === 1 ? ownSending[0].id : ''\n useEffect(() => {\n if (!sequence && !draft.mailboxId && onlyOwnMailbox)\n setDraft((previous) => ({ ...previous, mailboxId: onlyOwnMailbox }))\n }, [sequence, draft.mailboxId, onlyOwnMailbox])\n\n const templates = useOutreachEmailTemplates(orgId, draft.hostId || null, uid)\n const mailbox =\n props.mailboxes.mailboxes.find((entry) => entry.id === draft.mailboxId) ??\n null\n const archived = sequence?.status === 'archived'\n /*\n * The site's campaigns, for the picker (AGL-3254): read while the editor\n * is open, the way the form's page reads them, and re-read when the\n * sequence moves to another site — a campaign belongs to one site, so a\n * draft moved elsewhere has to pick again from that site's.\n */\n const campaigns = useHostCampaigns(draft.hostId || undefined, { enabled: Boolean(draft.hostId) })\n\n const issues = useMemo(() => {\n const judged = [\n ...validateOutreachSequence(draft),\n ...serverIssues,\n ] as OutreachSequenceIssue[]\n return judged.filter(\n (issue) =>\n issue.severity === 'warning' ||\n attempted ||\n serverIssues.includes(issue),\n )\n }, [draft, serverIssues, attempted])\n const issueAt = (path: string) =>\n issues.find((issue) => issue.path === path)?.message\n const stepIssues = (index: number) => {\n const found: Record<string, string> = {}\n for (const issue of issues) {\n const key = stepIssueKey(issue.path)\n if (key?.index === index && !found[key.field])\n found[key.field] = issue.message\n }\n return found\n }\n const listIssue = issueAt('steps')\n const countriesIssue = issues.find((issue) =>\n issue.path.startsWith('settings.allowedCountries'),\n )?.message\n\n const update = (next: Partial<OutreachSequenceDraft>) => {\n setServerIssues([])\n setDraft((previous) => ({ ...previous, ...next }))\n }\n const setStep = (index: number, step: OutreachSequenceStep) =>\n update({\n steps: draft.steps.map((entry, position) =>\n position === index ? step : entry,\n ),\n })\n const moveStep = (index: number, direction: -1 | 1) => {\n const steps = [...draft.steps]\n const [moved] = steps.splice(index, 1)\n steps.splice(index + direction, 0, moved)\n update({ steps })\n }\n const emailCount = draft.steps.filter((step) => step.kind === 'email').length\n const full = draft.steps.length >= OUTREACH_MAX_STEPS\n const threadSubject = (index: number) => {\n for (let position = index - 1; position >= 0; position -= 1) {\n const step = draft.steps[position]\n if (step.kind === 'email' && !isInThreadEmailStep(draft.steps, position))\n return step.subject\n }\n return ''\n }\n\n const save = async () => {\n setAttempted(true)\n if (\n validateOutreachSequence(draft).some(\n (issue) => issue.severity === 'error',\n )\n )\n return\n setSaving(true)\n try {\n const answer = await api.saveSequence(sequence?.id ?? null, draft)\n setServerIssues([])\n setAttempted(false)\n enqueueSnackbar(\n answer.created ? 'Sequence created.' : 'Sequence saved.',\n { variant: 'success' },\n )\n props.onSaved(answer.sequence)\n } catch (error) {\n if (error instanceof OutreachRouteError && error.issues.length) {\n setServerIssues(\n error.issues.filter(\n (issue): issue is OutreachSequenceIssue => 'path' in issue,\n ),\n )\n }\n enqueueSnackbar((error as Error).message, {\n variant: 'error',\n allowDuplicate: true,\n })\n } finally {\n setSaving(false)\n }\n }\n\n const siteName = hosts.find((host) => host.id === draft.hostId)?.name ?? ''\n const countryOptions = [\n ...new Set([...orgCountries, ...draft.settings.allowedCountries]),\n ]\n\n return (\n <Grid container spacing={2}>\n <Grid size={{ xs: 12, md: 7 }}>\n <Stack spacing={2}>\n {archived ? (\n <Alert severity=\"info\">\n This sequence is archived, so it can’t be edited.\n </Alert>\n ) : null}\n <CardDisplay\n header=\"Sequence\"\n help={pluginDocsHelp('sequences', { anchor: '#build-a-sequence' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2}>\n <TextField\n label=\"Name\"\n value={draft.name}\n onChange={(event) => update({ name: event.target.value })}\n disabled={archived}\n error={Boolean(issueAt('name'))}\n helperText={issueAt('name')}\n slotProps={{\n htmlInput: { maxLength: OUTREACH_SEQUENCE_NAME_MAX + 20 },\n }}\n fullWidth\n />\n <TextField\n select\n label=\"Site\"\n value={\n hosts.some((host) => host.id === draft.hostId)\n ? draft.hostId\n : ''\n }\n onChange={(event) => update({ hostId: event.target.value })}\n disabled={archived || !hosts.length}\n error={Boolean(issueAt('hostId'))}\n helperText={\n issueAt('hostId') ??\n 'The site whose contacts this sequence emails.'\n }\n fullWidth\n >\n {hosts.map((host) => (\n <MenuItem key={host.id} value={host.id}>\n {host.name}\n </MenuItem>\n ))}\n </TextField>\n <OutreachSequenceMailboxPicker\n orgId={orgId}\n uid={uid}\n mailboxes={props.mailboxes}\n mailboxesPath={props.mailboxesPath}\n value={draft.mailboxId}\n onChange={(mailboxId) => update({ mailboxId })}\n error={issueAt('mailboxId')}\n disabled={archived}\n />\n {/*\n The campaigns this sequence is part of (AGL-3254), picked the\n way a form's page picks them. Everyone enrolled joins them,\n and what the sequence produces is reported under them; it\n does not change who is enrolled or what is sent.\n */}\n {draft.hostId ? (\n <CampaignPicker\n options={campaigns.options}\n value={draft.campaignIds}\n onChange={(campaignIds) => update({ campaignIds })}\n label=\"Campaigns\"\n helperText={\n issueAt('campaignIds') ??\n 'The campaigns this sequence is part of. Everyone enrolled joins them, and its sends, replies, meetings and conversions count on their pages.'\n }\n disabled={archived}\n empty={campaigns.ready && !campaigns.options.length}\n emptyText=\"This site has no campaigns yet. Create one from Marketing to file this sequence under it.\"\n />\n ) : null}\n </Stack>\n </CardDisplay>\n\n {listIssue ? <Alert severity=\"error\">{listIssue}</Alert> : null}\n {draft.steps.map((step, index) => (\n <OutreachStepCard\n key={step.id || `step-${index}`}\n step={step}\n index={index}\n count={draft.steps.length}\n firstEmail={\n draft.steps.findIndex((entry) => entry.kind === 'email') ===\n index\n }\n inThread={isInThreadEmailStep(draft.steps, index)}\n threadSubject={threadSubject(index)}\n templates={templates.data}\n issues={stepIssues(index)}\n disabled={archived}\n onChange={(next) => setStep(index, next)}\n onMove={(direction) => moveStep(index, direction)}\n onRemove={() =>\n update({\n steps: draft.steps.filter(\n (_entry, position) => position !== index,\n ),\n })\n }\n />\n ))}\n <Stack\n direction=\"row\"\n spacing={1}\n sx={{ flexWrap: 'wrap', rowGap: 1 }}\n >\n <Button\n variant=\"outlined\"\n startIcon={<MdiIcon path={mdiPlus.path} fontSize=\"small\" />}\n disabled={\n archived || full || emailCount >= OUTREACH_MAX_EMAIL_STEPS\n }\n onClick={() =>\n update({\n steps: [...draft.steps, newOutreachEmailStep(draft.steps)],\n })\n }\n >\n Add email\n </Button>\n <Button\n variant=\"outlined\"\n startIcon={<MdiIcon path={mdiPlus.path} fontSize=\"small\" />}\n disabled={archived || full}\n onClick={(event) => setTaskAnchor(event.currentTarget)}\n aria-haspopup=\"menu\"\n >\n Add task\n </Button>\n <Menu\n anchorEl={taskAnchor}\n open={Boolean(taskAnchor)}\n onClose={() => setTaskAnchor(null)}\n >\n {OUTREACH_TASK_KINDS.map((kind: OutreachTaskKind) => (\n <MenuItem\n key={kind}\n onClick={() => {\n setTaskAnchor(null)\n update({\n steps: [\n ...draft.steps,\n newOutreachTaskStep(draft.steps, kind),\n ],\n })\n }}\n >\n {OUTREACH_TASK_KIND_LABELS[kind]}\n </MenuItem>\n ))}\n </Menu>\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Up to ${OUTREACH_MAX_STEPS} steps, ${OUTREACH_MAX_EMAIL_STEPS} of them emails.`}\n </Typography>\n\n <CardDisplay\n header=\"Who it sends to, and when\"\n help={pluginDocsHelp('sequences', {\n anchor: '#build-a-sequence',\n excerpt:\n 'A sequence sends only to the countries both it and your organization allow, and in its mailbox’s sending hours unless it has its own.',\n })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2}>\n <Autocomplete<string, true>\n multiple\n options={countryOptions}\n value={draft.settings.allowedCountries}\n getOptionLabel={outreachCountryLabel}\n onChange={(_event, next) =>\n update({\n settings: { ...draft.settings, allowedCountries: next },\n })\n }\n disabled={archived}\n renderValue={(value, getItemProps) =>\n value.map((code, index) => {\n const { key, ...item } = getItemProps({ index })\n return (\n <Chip\n key={key}\n size=\"small\"\n label={outreachCountryLabel(code)}\n {...item}\n />\n )\n })\n }\n renderInput={(params) => (\n <TextField\n {...params}\n label=\"Countries\"\n error={Boolean(countriesIssue)}\n helperText={\n countriesIssue ??\n 'Among the countries your organization allows. Cold contacts are emailed only in the United States.'\n }\n />\n )}\n />\n <FormControlLabel\n control={\n <Switch\n checked={draft.settings.allowCustomers}\n onChange={(event) =>\n update({\n settings: {\n ...draft.settings,\n allowCustomers: event.target.checked,\n },\n })\n }\n disabled={archived}\n />\n }\n label=\"Include customers\"\n />\n {/*\n * Click tracking (AGL-3239), with its cost stated where it is\n * chosen rather than in a document nobody opens. Off by\n * default: it changes the link a cold recipient sees, and the\n * emails stay plain text either way — there is no open\n * tracking to turn on, because a tracking image needs an HTML\n * email and these are not.\n */}\n <Stack spacing={0}>\n <FormControlLabel\n control={\n <Switch\n checked={draft.settings.trackClicks}\n onChange={(event) =>\n update({\n settings: {\n ...draft.settings,\n trackClicks: event.target.checked,\n },\n })\n }\n disabled={archived}\n />\n }\n label=\"Count link clicks\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n Links in these emails are replaced with links of ours that\n forward to the same page, so clicks can be counted. The\n recipient sees the replacement, not your address. Opens\n aren’t counted either way: these emails are plain text, and\n counting an open needs a tracking image.\n </Typography>\n </Stack>\n <OutreachSendWindowFields\n window={draft.settings.window}\n onChange={(window) =>\n update({ settings: { ...draft.settings, window } })\n }\n daysIssue={issueAt('settings.window.days')}\n hoursIssue={issueAt('settings.window')}\n disabled={archived}\n />\n </Stack>\n </CardDisplay>\n\n {archived ? null : (\n <Stack\n direction={{ xs: 'column', sm: 'row' }}\n spacing={1}\n sx={{ justifyContent: 'flex-end' }}\n >\n {props.onCancel ? (\n <Button\n variant=\"text\"\n onClick={props.onCancel}\n disabled={saving}\n >\n Cancel\n </Button>\n ) : null}\n <Button\n variant=\"contained\"\n onClick={() => void save()}\n disabled={saving}\n >\n {saving ? 'Saving…' : sequence ? 'Save' : 'Create sequence'}\n </Button>\n </Stack>\n )}\n </Stack>\n </Grid>\n <Grid size={{ xs: 12, md: 5 }}>\n <Box sx={{ position: { md: 'sticky' }, top: { md: 16 } }}>\n <OutreachSequencePreview\n steps={draft.steps}\n orgSettings={settings.settings}\n orgSettingsStatus={settings.status}\n templates={templates.data}\n sender={\n mailbox\n ? {\n name: mailbox.displayName,\n email: mailbox.sendAs || mailbox.email,\n }\n : null\n }\n siteName={siteName}\n />\n </Box>\n </Grid>\n </Grid>\n )\n}\nOutreachSequenceEditor.displayName = 'OutreachSequenceEditor'\n\nexport default OutreachSequenceEditor\n"],"names":["pluginDocsHelp","mdiPlus","CardDisplay","MdiIcon","CampaignPicker","useSnackbar","useHostCampaigns","useUser","Alert","Autocomplete","Box","Button","Chip","FormControlLabel","Grid","Menu","MenuItem","Stack","Switch","TextField","Typography","useEffect","useMemo","useState","isInThreadEmailStep","OUTREACH_SEQUENCE_NAME_MAX","validateOutreachSequence","outreachCountryLabel","OUTREACH_MAX_EMAIL_STEPS","OUTREACH_MAX_STEPS","OUTREACH_TASK_KIND_LABELS","OUTREACH_TASK_KINDS","emptyOutreachSequenceDraft","newOutreachEmailStep","newOutreachTaskStep","outreachSequenceDraftOf","OutreachSendWindowFields","OutreachSequenceMailboxPicker","OutreachSequencePreview","OutreachStepCard","OutreachRouteError","useOutreachApi","useOutreachEmailTemplates","stepIssueKey","path","match","exec","field","index","Number","OutreachSequenceEditor","props","issueAt","settings","issues","hosts","orgId","orgMount","sequence","api","enqueueSnackbar","data","user","uid","mountedHosts","orgCountries","allowedCountries","draft","setDraft","hostId","length","id","attempted","setAttempted","serverIssues","setServerIssues","saving","setSaving","taskAnchor","setTaskAnchor","settingsCountries","join","previous","split","ownSending","mailboxes","filter","entry","connectedByUid","status","onlyOwnMailbox","mailboxId","templates","mailbox","find","archived","campaigns","undefined","enabled","Boolean","judged","issue","severity","includes","message","stepIssues","found","key","listIssue","countriesIssue","startsWith","update","next","setStep","step","steps","map","position","moveStep","direction","moved","splice","emailCount","kind","full","threadSubject","subject","save","some","answer","saveSequence","created","variant","onSaved","error","allowDuplicate","siteName","host","name","countryOptions","Set","container","spacing","size","xs","md","header","help","anchor","contentGutterX","contentGutterY","label","value","onChange","event","target","disabled","helperText","slotProps","htmlInput","maxLength","fullWidth","select","mailboxesPath","options","campaignIds","empty","ready","emptyText","count","firstEmail","findIndex","inThread","onMove","onRemove","_entry","sx","flexWrap","rowGap","startIcon","fontSize","onClick","currentTarget","aria-haspopup","anchorEl","open","onClose","color","excerpt","multiple","getOptionLabel","_event","renderValue","getItemProps","code","item","renderInput","params","control","checked","allowCustomers","trackClicks","window","daysIssue","hoursIssue","sm","justifyContent","onCancel","top","orgSettings","orgSettingsStatus","sender","displayName","email","sendAs"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;;AAEA,SAASA,cAAc,QAAoC,eAAc;AACzE,SAASC,OAAO,QAAQ,yBAAwB;AAChD,SAASC,WAAW,EAAEC,OAAO,QAAQ,uBAAsB;AAC3D,OAAOC,oBAAoB,wEAAuE;AAClG,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,gBAAgB,EAAEC,OAAO,QAAQ,iCAAgC;AAC1E,SACEC,KAAK,EACLC,YAAY,EACZC,GAAG,EACHC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,IAAI,EACJC,IAAI,EACJC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACpD,SACEC,mBAAmB,EACnBC,0BAA0B,EAC1BC,wBAAwB,QACnB,mCAA+B;AACtC,SAASC,oBAAoB,QAAQ,kCAA8B;AACnE,SACEC,wBAAwB,EACxBC,kBAAkB,EAClBC,yBAAyB,EACzBC,mBAAmB,QAId,6BAAyB;AAChC,SACEC,0BAA0B,EAC1BC,oBAAoB,EACpBC,mBAAmB,EACnBC,uBAAuB,QAGlB,6BAAyB;AAChC,SAASC,wBAAwB,QAAQ,0BAAsB;AAC/D,SAASC,6BAA6B,QAAQ,+BAA2B;AACzE,SAASC,uBAAuB,QAAQ,wBAAoB;AAC5D,SAASC,gBAAgB,QAAQ,0BAAsB;AACvD,SAASC,kBAAkB,EAAEC,cAAc,QAAQ,wBAAoB;AACvE,SAASC,yBAAyB,QAAQ,wBAAoB;AAsB9D,oEAAoE,GACpE,SAASC,aAAaC,IAAY;QAGlBC;IAFd,MAAMA,QAAQ,4BAA4BC,IAAI,CAACF;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,OAAOxH,QAAQyH,MAAM,IAAIzH,QAAQwH,KAAK;wBACxC,IACA;wBAEN7E,UAAUA;;;;;;AAMtB;AACAtF,uBAAuBkK,WAAW,GAAG;AAErC,eAAelK,uBAAsB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/outreach/src/lib/components/sequence-editor.tsx"],"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'use client'\n\nimport { pluginDocsHelp, type ConsolePluginOrgMount } from '@aglyn/aglyn'\nimport { mdiPlus } from '@aglyn/shared-data-mdi'\nimport { CardDisplay, MdiIcon } from '@aglyn/shared-ui-jsx'\nimport CampaignPicker from '@aglyn/shared-ui-email-campaigns/components/campaign-picker.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { useOrgCampaigns, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Autocomplete,\n Box,\n Button,\n Chip,\n FormControlLabel,\n Grid,\n Menu,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useEffect, useMemo, useState } from 'react'\nimport {\n isInThreadEmailStep,\n OUTREACH_SEQUENCE_NAME_MAX,\n validateOutreachSequence,\n} from '../engine/sequence-validation'\nimport { outreachCountryLabel } from '../model/compliance-settings'\nimport {\n OUTREACH_MAX_EMAIL_STEPS,\n OUTREACH_MAX_STEPS,\n OUTREACH_TASK_KIND_LABELS,\n OUTREACH_TASK_KINDS,\n type OutreachSequence,\n type OutreachSequenceStep,\n type OutreachTaskKind,\n} from '../model/outreach.types'\nimport {\n emptyOutreachSequenceDraft,\n newOutreachEmailStep,\n newOutreachTaskStep,\n outreachSequenceDraftOf,\n type OutreachSequenceDraft,\n type OutreachSequenceIssue,\n} from '../model/sequence-draft'\nimport { OutreachSendWindowFields } from './send-window-fields'\nimport { OutreachSequenceMailboxPicker } from './sequence-mailbox-picker'\nimport { OutreachSequencePreview } from './sequence-preview'\nimport { OutreachStepCard } from './sequence-step-card'\nimport { OutreachRouteError, useOutreachApi } from './use-outreach-api'\nimport { useOutreachEmailTemplates } from './use-outreach-crm'\nimport type { OutreachMailboxesResult } from './use-outreach-mailboxes'\nimport type { OutreachSettingsLoad } from './use-outreach-settings'\n\nexport interface OutreachSequenceEditorProps {\n orgId: string\n orgMount?: ConsolePluginOrgMount\n /** The stored sequence, or `null` for a new one. */\n sequence: OutreachSequence | null\n /** The organization's compliance settings: its countries, and the preview's footer. */\n settings: OutreachSettingsLoad\n /**\n * The organization's mailboxes, from the Mailboxes section's listener:\n * what the picker offers, and who the preview's emails are from.\n */\n mailboxes: OutreachMailboxesResult\n /** The Mailboxes section, where the picker sends a member to connect one. */\n mailboxesPath: string\n onSaved(sequence: OutreachSequence): void\n onCancel?(): void\n}\n\n/** The step a dotted issue path is about, and the field within it. */\nfunction stepIssueKey(path: string): { index: number; field: string } | null {\n const match = /^steps\\.(\\d+)(?:\\.(.+))?$/.exec(path)\n if (!match) return null\n const field = match[2] ?? 'step'\n return { index: Number(match[1]), field: field === 'id' ? 'step' : field }\n}\n\n/**\n * The sequence editor (AGL-2980): the name, the site and mailbox, the steps,\n * who it sends to and when, beside a live preview of each email.\n *\n * Every issue the engine's validator finds is shown beside its field — the\n * same validator the save route refuses with — errors once a save was\n * attempted, warnings as soon as they appear. What only the server can\n * judge (whose mailbox, which countries the organization allows, what may\n * no longer change once people are enrolled) comes back from the save and\n * is shown in the same places.\n */\nexport function OutreachSequenceEditor(props: OutreachSequenceEditorProps) {\n const { orgId, orgMount, sequence, settings } = props\n const api = useOutreachApi(orgId)\n const { enqueueSnackbar } = useSnackbar()\n const { data: user } = useUser()\n const uid = user?.uid ?? null\n const mountedHosts = orgMount?.hosts\n const hosts = useMemo(() => mountedHosts ?? [], [mountedHosts])\n const orgCountries = settings.settings?.allowedCountries ?? ['US']\n\n const [draft, setDraft] = useState<OutreachSequenceDraft>(() =>\n sequence\n ? outreachSequenceDraftOf(sequence)\n : emptyOutreachSequenceDraft({\n hostId: hosts.length === 1 ? hosts[0].id : '',\n allowedCountries: orgCountries,\n }),\n )\n const [attempted, setAttempted] = useState(false)\n const [serverIssues, setServerIssues] = useState<OutreachSequenceIssue[]>([])\n const [saving, setSaving] = useState(false)\n const [taskAnchor, setTaskAnchor] = useState<HTMLElement | null>(null)\n\n // A stored sequence the listener updated (a save, a status change) is the\n // new starting point.\n useEffect(() => {\n if (sequence) setDraft(outreachSequenceDraftOf(sequence))\n }, [sequence])\n // A new sequence starts on the organization's countries once they are read.\n const settingsCountries = settings.settings?.allowedCountries.join(',')\n useEffect(() => {\n if (!sequence && settingsCountries) {\n setDraft((previous) => ({\n ...previous,\n settings: {\n ...previous.settings,\n allowedCountries: settingsCountries.split(','),\n },\n }))\n }\n }, [sequence, settingsCountries])\n useEffect(() => {\n if (!sequence && !draft.hostId && hosts.length === 1)\n setDraft((previous) => ({ ...previous, hostId: hosts[0].id }))\n }, [sequence, draft.hostId, hosts])\n\n // A new sequence starts on the member's own mailbox when they have exactly\n // one that is sending.\n const ownSending = props.mailboxes.mailboxes.filter(\n (entry) => entry.connectedByUid === uid && entry.status === 'connected',\n )\n const onlyOwnMailbox = ownSending.length === 1 ? ownSending[0].id : ''\n useEffect(() => {\n if (!sequence && !draft.mailboxId && onlyOwnMailbox)\n setDraft((previous) => ({ ...previous, mailboxId: onlyOwnMailbox }))\n }, [sequence, draft.mailboxId, onlyOwnMailbox])\n\n const templates = useOutreachEmailTemplates(orgId, draft.hostId || null, uid)\n const mailbox =\n props.mailboxes.mailboxes.find((entry) => entry.id === draft.mailboxId) ??\n null\n const archived = sequence?.status === 'archived'\n /*\n * The org's campaigns, for the picker (AGL-3254): read while the editor\n * is open. A sequence is the organization's record and so is a campaign,\n * so the choice is every campaign in the org, whichever site the\n * sequence sends as.\n */\n const campaigns = useOrgCampaigns(orgId, { enabled: true })\n\n const issues = useMemo(() => {\n const judged = [\n ...validateOutreachSequence(draft),\n ...serverIssues,\n ] as OutreachSequenceIssue[]\n return judged.filter(\n (issue) =>\n issue.severity === 'warning' ||\n attempted ||\n serverIssues.includes(issue),\n )\n }, [draft, serverIssues, attempted])\n const issueAt = (path: string) =>\n issues.find((issue) => issue.path === path)?.message\n const stepIssues = (index: number) => {\n const found: Record<string, string> = {}\n for (const issue of issues) {\n const key = stepIssueKey(issue.path)\n if (key?.index === index && !found[key.field])\n found[key.field] = issue.message\n }\n return found\n }\n const listIssue = issueAt('steps')\n const countriesIssue = issues.find((issue) =>\n issue.path.startsWith('settings.allowedCountries'),\n )?.message\n\n const update = (next: Partial<OutreachSequenceDraft>) => {\n setServerIssues([])\n setDraft((previous) => ({ ...previous, ...next }))\n }\n const setStep = (index: number, step: OutreachSequenceStep) =>\n update({\n steps: draft.steps.map((entry, position) =>\n position === index ? step : entry,\n ),\n })\n const moveStep = (index: number, direction: -1 | 1) => {\n const steps = [...draft.steps]\n const [moved] = steps.splice(index, 1)\n steps.splice(index + direction, 0, moved)\n update({ steps })\n }\n const emailCount = draft.steps.filter((step) => step.kind === 'email').length\n const full = draft.steps.length >= OUTREACH_MAX_STEPS\n const threadSubject = (index: number) => {\n for (let position = index - 1; position >= 0; position -= 1) {\n const step = draft.steps[position]\n if (step.kind === 'email' && !isInThreadEmailStep(draft.steps, position))\n return step.subject\n }\n return ''\n }\n\n const save = async () => {\n setAttempted(true)\n if (\n validateOutreachSequence(draft).some(\n (issue) => issue.severity === 'error',\n )\n )\n return\n setSaving(true)\n try {\n const answer = await api.saveSequence(sequence?.id ?? null, draft)\n setServerIssues([])\n setAttempted(false)\n enqueueSnackbar(\n answer.created ? 'Sequence created.' : 'Sequence saved.',\n { variant: 'success' },\n )\n props.onSaved(answer.sequence)\n } catch (error) {\n if (error instanceof OutreachRouteError && error.issues.length) {\n setServerIssues(\n error.issues.filter(\n (issue): issue is OutreachSequenceIssue => 'path' in issue,\n ),\n )\n }\n enqueueSnackbar((error as Error).message, {\n variant: 'error',\n allowDuplicate: true,\n })\n } finally {\n setSaving(false)\n }\n }\n\n const siteName = hosts.find((host) => host.id === draft.hostId)?.name ?? ''\n const countryOptions = [\n ...new Set([...orgCountries, ...draft.settings.allowedCountries]),\n ]\n\n return (\n <Grid container spacing={2}>\n <Grid size={{ xs: 12, md: 7 }}>\n <Stack spacing={2}>\n {archived ? (\n <Alert severity=\"info\">\n This sequence is archived, so it can’t be edited.\n </Alert>\n ) : null}\n <CardDisplay\n header=\"Sequence\"\n help={pluginDocsHelp('sequences', { anchor: '#build-a-sequence' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2}>\n <TextField\n label=\"Name\"\n value={draft.name}\n onChange={(event) => update({ name: event.target.value })}\n disabled={archived}\n error={Boolean(issueAt('name'))}\n helperText={issueAt('name')}\n slotProps={{\n htmlInput: { maxLength: OUTREACH_SEQUENCE_NAME_MAX + 20 },\n }}\n fullWidth\n />\n <TextField\n select\n label=\"Site\"\n value={\n hosts.some((host) => host.id === draft.hostId)\n ? draft.hostId\n : ''\n }\n onChange={(event) => update({ hostId: event.target.value })}\n disabled={archived || !hosts.length}\n error={Boolean(issueAt('hostId'))}\n helperText={\n issueAt('hostId') ??\n 'The site whose contacts this sequence emails.'\n }\n fullWidth\n >\n {hosts.map((host) => (\n <MenuItem key={host.id} value={host.id}>\n {host.name}\n </MenuItem>\n ))}\n </TextField>\n <OutreachSequenceMailboxPicker\n orgId={orgId}\n uid={uid}\n mailboxes={props.mailboxes}\n mailboxesPath={props.mailboxesPath}\n value={draft.mailboxId}\n onChange={(mailboxId) => update({ mailboxId })}\n error={issueAt('mailboxId')}\n disabled={archived}\n />\n {/*\n The campaigns this sequence is part of (AGL-3254), picked the\n way a form's page picks them. Everyone enrolled joins them,\n and what the sequence produces is reported under them; it\n does not change who is enrolled or what is sent.\n */}\n <CampaignPicker\n options={campaigns.options}\n value={draft.campaignIds}\n onChange={(campaignIds) => update({ campaignIds })}\n label=\"Campaigns\"\n helperText={\n issueAt('campaignIds') ??\n 'The campaigns this sequence is part of. Everyone enrolled joins them, and its sends, replies, meetings and conversions count on their pages.'\n }\n disabled={archived}\n empty={campaigns.ready && !campaigns.options.length}\n emptyText=\"There are no campaigns yet. Create one from Marketing to file this sequence under it.\"\n />\n </Stack>\n </CardDisplay>\n\n {listIssue ? <Alert severity=\"error\">{listIssue}</Alert> : null}\n {draft.steps.map((step, index) => (\n <OutreachStepCard\n key={step.id || `step-${index}`}\n step={step}\n index={index}\n count={draft.steps.length}\n firstEmail={\n draft.steps.findIndex((entry) => entry.kind === 'email') ===\n index\n }\n inThread={isInThreadEmailStep(draft.steps, index)}\n threadSubject={threadSubject(index)}\n templates={templates.data}\n issues={stepIssues(index)}\n disabled={archived}\n onChange={(next) => setStep(index, next)}\n onMove={(direction) => moveStep(index, direction)}\n onRemove={() =>\n update({\n steps: draft.steps.filter(\n (_entry, position) => position !== index,\n ),\n })\n }\n />\n ))}\n <Stack\n direction=\"row\"\n spacing={1}\n sx={{ flexWrap: 'wrap', rowGap: 1 }}\n >\n <Button\n variant=\"outlined\"\n startIcon={<MdiIcon path={mdiPlus.path} fontSize=\"small\" />}\n disabled={\n archived || full || emailCount >= OUTREACH_MAX_EMAIL_STEPS\n }\n onClick={() =>\n update({\n steps: [...draft.steps, newOutreachEmailStep(draft.steps)],\n })\n }\n >\n Add email\n </Button>\n <Button\n variant=\"outlined\"\n startIcon={<MdiIcon path={mdiPlus.path} fontSize=\"small\" />}\n disabled={archived || full}\n onClick={(event) => setTaskAnchor(event.currentTarget)}\n aria-haspopup=\"menu\"\n >\n Add task\n </Button>\n <Menu\n anchorEl={taskAnchor}\n open={Boolean(taskAnchor)}\n onClose={() => setTaskAnchor(null)}\n >\n {OUTREACH_TASK_KINDS.map((kind: OutreachTaskKind) => (\n <MenuItem\n key={kind}\n onClick={() => {\n setTaskAnchor(null)\n update({\n steps: [\n ...draft.steps,\n newOutreachTaskStep(draft.steps, kind),\n ],\n })\n }}\n >\n {OUTREACH_TASK_KIND_LABELS[kind]}\n </MenuItem>\n ))}\n </Menu>\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Up to ${OUTREACH_MAX_STEPS} steps, ${OUTREACH_MAX_EMAIL_STEPS} of them emails.`}\n </Typography>\n\n <CardDisplay\n header=\"Who it sends to, and when\"\n help={pluginDocsHelp('sequences', {\n anchor: '#build-a-sequence',\n excerpt:\n 'A sequence sends only to the countries both it and your organization allow, and in its mailbox’s sending hours unless it has its own.',\n })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2}>\n <Autocomplete<string, true>\n multiple\n options={countryOptions}\n value={draft.settings.allowedCountries}\n getOptionLabel={outreachCountryLabel}\n onChange={(_event, next) =>\n update({\n settings: { ...draft.settings, allowedCountries: next },\n })\n }\n disabled={archived}\n renderValue={(value, getItemProps) =>\n value.map((code, index) => {\n const { key, ...item } = getItemProps({ index })\n return (\n <Chip\n key={key}\n size=\"small\"\n label={outreachCountryLabel(code)}\n {...item}\n />\n )\n })\n }\n renderInput={(params) => (\n <TextField\n {...params}\n label=\"Countries\"\n error={Boolean(countriesIssue)}\n helperText={\n countriesIssue ??\n 'Among the countries your organization allows. Cold contacts are emailed only in the United States.'\n }\n />\n )}\n />\n <FormControlLabel\n control={\n <Switch\n checked={draft.settings.allowCustomers}\n onChange={(event) =>\n update({\n settings: {\n ...draft.settings,\n allowCustomers: event.target.checked,\n },\n })\n }\n disabled={archived}\n />\n }\n label=\"Include customers\"\n />\n {/*\n * Click tracking (AGL-3239), with its cost stated where it is\n * chosen rather than in a document nobody opens. Off by\n * default: it changes the link a cold recipient sees, and the\n * emails stay plain text either way — there is no open\n * tracking to turn on, because a tracking image needs an HTML\n * email and these are not.\n */}\n <Stack spacing={0}>\n <FormControlLabel\n control={\n <Switch\n checked={draft.settings.trackClicks}\n onChange={(event) =>\n update({\n settings: {\n ...draft.settings,\n trackClicks: event.target.checked,\n },\n })\n }\n disabled={archived}\n />\n }\n label=\"Count link clicks\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n Links in these emails are replaced with links of ours that\n forward to the same page, so clicks can be counted. The\n recipient sees the replacement, not your address. Opens\n aren’t counted either way: these emails are plain text, and\n counting an open needs a tracking image.\n </Typography>\n </Stack>\n <OutreachSendWindowFields\n window={draft.settings.window}\n onChange={(window) =>\n update({ settings: { ...draft.settings, window } })\n }\n daysIssue={issueAt('settings.window.days')}\n hoursIssue={issueAt('settings.window')}\n disabled={archived}\n />\n </Stack>\n </CardDisplay>\n\n {archived ? null : (\n <Stack\n direction={{ xs: 'column', sm: 'row' }}\n spacing={1}\n sx={{ justifyContent: 'flex-end' }}\n >\n {props.onCancel ? (\n <Button\n variant=\"text\"\n onClick={props.onCancel}\n disabled={saving}\n >\n Cancel\n </Button>\n ) : null}\n <Button\n variant=\"contained\"\n onClick={() => void save()}\n disabled={saving}\n >\n {saving ? 'Saving…' : sequence ? 'Save' : 'Create sequence'}\n </Button>\n </Stack>\n )}\n </Stack>\n </Grid>\n <Grid size={{ xs: 12, md: 5 }}>\n <Box sx={{ position: { md: 'sticky' }, top: { md: 16 } }}>\n <OutreachSequencePreview\n steps={draft.steps}\n orgSettings={settings.settings}\n orgSettingsStatus={settings.status}\n templates={templates.data}\n sender={\n mailbox\n ? {\n name: mailbox.displayName,\n email: mailbox.sendAs || mailbox.email,\n }\n : null\n }\n siteName={siteName}\n />\n </Box>\n </Grid>\n </Grid>\n )\n}\nOutreachSequenceEditor.displayName = 'OutreachSequenceEditor'\n\nexport default OutreachSequenceEditor\n"],"names":["pluginDocsHelp","mdiPlus","CardDisplay","MdiIcon","CampaignPicker","useSnackbar","useOrgCampaigns","useUser","Alert","Autocomplete","Box","Button","Chip","FormControlLabel","Grid","Menu","MenuItem","Stack","Switch","TextField","Typography","useEffect","useMemo","useState","isInThreadEmailStep","OUTREACH_SEQUENCE_NAME_MAX","validateOutreachSequence","outreachCountryLabel","OUTREACH_MAX_EMAIL_STEPS","OUTREACH_MAX_STEPS","OUTREACH_TASK_KIND_LABELS","OUTREACH_TASK_KINDS","emptyOutreachSequenceDraft","newOutreachEmailStep","newOutreachTaskStep","outreachSequenceDraftOf","OutreachSendWindowFields","OutreachSequenceMailboxPicker","OutreachSequencePreview","OutreachStepCard","OutreachRouteError","useOutreachApi","useOutreachEmailTemplates","stepIssueKey","path","match","exec","field","index","Number","OutreachSequenceEditor","props","issueAt","settings","issues","hosts","orgId","orgMount","sequence","api","enqueueSnackbar","data","user","uid","mountedHosts","orgCountries","allowedCountries","draft","setDraft","hostId","length","id","attempted","setAttempted","serverIssues","setServerIssues","saving","setSaving","taskAnchor","setTaskAnchor","settingsCountries","join","previous","split","ownSending","mailboxes","filter","entry","connectedByUid","status","onlyOwnMailbox","mailboxId","templates","mailbox","find","archived","campaigns","enabled","judged","issue","severity","includes","message","stepIssues","found","key","listIssue","countriesIssue","startsWith","update","next","setStep","step","steps","map","position","moveStep","direction","moved","splice","emailCount","kind","full","threadSubject","subject","save","some","answer","saveSequence","created","variant","onSaved","error","allowDuplicate","siteName","host","name","countryOptions","Set","container","spacing","size","xs","md","header","help","anchor","contentGutterX","contentGutterY","label","value","onChange","event","target","disabled","Boolean","helperText","slotProps","htmlInput","maxLength","fullWidth","select","mailboxesPath","options","campaignIds","empty","ready","emptyText","count","firstEmail","findIndex","inThread","onMove","onRemove","_entry","sx","flexWrap","rowGap","startIcon","fontSize","onClick","currentTarget","aria-haspopup","anchorEl","open","onClose","color","excerpt","multiple","getOptionLabel","_event","renderValue","getItemProps","code","item","renderInput","params","control","checked","allowCustomers","trackClicks","window","daysIssue","hoursIssue","sm","justifyContent","onCancel","top","orgSettings","orgSettingsStatus","sender","displayName","email","sendAs"],"mappings":"AAAA;;;;;;;;;;;;;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|
|
434
434
|
/**
|
|
435
435
|
* The campaigns the sequence is in (AGL-3254): container ids from the
|
|
436
|
-
*
|
|
436
|
+
* org's `emailCampaigns`, under the field every campaign member carries
|
|
437
437
|
* (`CAMPAIGN_MEMBERSHIP_FIELD`). Everyone enrolled gains them on their
|
|
438
438
|
* own record at enroll time, and what the sequence produces is credited
|
|
439
439
|
* to them. Absent on a sequence saved before it could join one.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/outreach/src/lib/model/outreach.types.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * THE OUTREACH DOCUMENT MODEL (AGL-2974).\n *\n * One file both halves import — the console reads these documents, the server\n * routes write them — so a field is spelled once. Client-safe: types and\n * constants only, nothing that reaches Firestore.\n *\n * EVERY DOCUMENT HERE IS SERVER-WRITTEN. The Firestore rules let an\n * org-wide member holding `outreach.use` READ the org collections on a\n * workspace that carries `features.outreach`, and refuse every client write,\n * because these documents are the sending engine's state: a client that\n * could write a mailbox could lift its daily cap, and one that could write\n * an enrollment could send a step twice. The credential collection is closed\n * to clients entirely.\n *\n * Lean on purpose. Each type carries what the mailbox and sequence work is\n * known to need and nothing speculative; a field is added where the code\n * that reads it lands. Times are epoch milliseconds throughout, the unit\n * `nextDueAtMs` has to be compared in.\n */\n\n/**\n * Where Outreach keeps its records.\n *\n * Five collections under the organization, and one at the top level. The\n * org-scoped ones are erased with the org, whose erasure deletes the whole\n * `orgs/{orgId}` tree. The top-level one holds credentials, so it is keyed by\n * an `orgId` FIELD that a path-scoped delete of `orgs/{orgId}` cannot see:\n * the org erasure sweeps it by that field\n * (`libs/tenant/data/admin/src/lib/server/erase.ts` names it as a literal,\n * which the boundary forces, and `outreach.types.spec.ts` holds the two\n * spellings together, along with the rules').\n */\nexport const OUTREACH_COLLECTIONS = {\n /** `orgs/{orgId}/outreachMailboxes/{mailboxId}` — a connected mailbox. */\n mailboxes: 'outreachMailboxes',\n /** `orgs/{orgId}/outreachSequences/{sequenceId}` — the steps to send. */\n sequences: 'outreachSequences',\n /** `orgs/{orgId}/outreachEnrollments/{enrollmentId}` — one person in one sequence. */\n enrollments: 'outreachEnrollments',\n /**\n * `orgs/{orgId}/outreachSettings/{settingsId}` — the organization's own\n * Outreach settings, one document per concern. `compliance` holds who\n * every email says sent it and the countries Outreach may send to.\n */\n settings: 'outreachSettings',\n /**\n * `orgs/{orgId}/outreachDoNotContact/{key}` — the addresses Outreach never\n * emails for this organization, keyed by `outreachDoNotContactKey`.\n */\n doNotContact: 'outreachDoNotContact',\n /**\n * `orgs/{orgId}/outreachDoNotContactDomains/{domain}` — the domains\n * Outreach never emails for this organization (AGL-3244), keyed by the\n * domain itself: a domain names a company, not a person.\n */\n doNotContactDomains: 'outreachDoNotContactDomains',\n /**\n * `outreachMailboxCredentials/{mailboxId}` — the provider grant behind a\n * mailbox. TOP-LEVEL and closed to every client, staff included, so the\n * token material never shares a readable path with the mailbox it serves.\n */\n mailboxCredentials: 'outreachMailboxCredentials',\n} as const\n\n/** The org-scoped collections, by their {@link OUTREACH_COLLECTIONS} key. */\nexport type OutreachOrgCollection = Exclude<\n keyof typeof OUTREACH_COLLECTIONS,\n 'mailboxCredentials'\n>\n\n/** `orgs/{orgId}/<collection>` for one of the org-scoped collections. */\nexport function outreachOrgCollectionPath(\n orgId: string,\n collection: OutreachOrgCollection,\n): string {\n return `orgs/${orgId}/${OUTREACH_COLLECTIONS[collection]}`\n}\n\n/** Stamped by the server on every write. */\nexport interface OutreachTimestamps {\n createdAtMs: number\n updatedAtMs: number\n}\n\n/** The mail providers a mailbox can be connected through. */\nexport const OUTREACH_MAILBOX_PROVIDERS = ['google'] as const\nexport type OutreachMailboxProvider =\n (typeof OUTREACH_MAILBOX_PROVIDERS)[number]\n\n/**\n * Where a mailbox stands.\n *\n * - `connected` — the grant works and the mailbox may send.\n * - `paused` — a member stopped it; enrollments on it wait.\n * - `reconnect_required` — the provider refused the grant (revoked, expired,\n * password changed); nothing sends until the rep connects it again.\n * - `disconnected` — a member removed it; its credential is gone.\n */\nexport const OUTREACH_MAILBOX_STATUSES = [\n 'connected',\n 'paused',\n 'reconnect_required',\n 'disconnected',\n] as const\nexport type OutreachMailboxStatus = (typeof OUTREACH_MAILBOX_STATUSES)[number]\n\n/**\n * The hours a mailbox sends in, in its own {@link OutreachMailbox.timezone}.\n * A step that comes due outside the window waits for the next opening.\n */\nexport interface OutreachSendWindow {\n /** Days of the week it sends on, `0` Sunday through `6` Saturday. */\n days: number[]\n /** Minutes after local midnight the window opens, inclusive. */\n startMinute: number\n /** Minutes after local midnight the window closes, exclusive. */\n endMinute: number\n}\n\n/**\n * One mailbox-local day's sending, as the health panel sums it (AGL-2978).\n */\nexport interface OutreachMailboxDailyHealth {\n sent: number\n bounces: number\n replies: number\n}\n\n/**\n * The counters a mailbox's sending is judged by.\n *\n * `sentToday` is what `dailyCap` refuses against, and it belongs to one\n * mailbox-local day — `sentOnDay` — so a counter from yesterday is read as\n * zero rather than as today's spend.\n */\nexport interface OutreachMailboxHealth {\n sentToday: number\n /** The local day (`YYYY-MM-DD` in the mailbox's timezone) `sentToday` counts. */\n sentOnDay: string | null\n /** Hard bounces on mail this mailbox sent. */\n bounces: number\n /** Replies detected on Outreach threads. */\n replies: number\n lastSentAtMs: number | null\n /** The last provider error, kept until a later send succeeds. */\n lastErrorAtMs: number | null\n lastErrorCode: string | null\n /**\n * Per mailbox-local day (`YYYY-MM-DD`), the sends, bounces and replies\n * counted on it (AGL-2978). The Mailboxes panel shows the last seven days\n * summed; the sending runtime increments the day it counts on and may drop\n * days older than a week. Absent, or empty, until the first send.\n */\n daily?: Record<string, OutreachMailboxDailyHealth>\n /**\n * The mailbox's most recent sends, newest last, at most\n * `OUTREACH_BOUNCE_RATE_WINDOW_SENDS` of them, each marked when a hard\n * bounce came back for it (AGL-2981): the window the bounce-rate pause is\n * judged over. A send is named by a digest of its `Message-ID`, never by\n * its recipient.\n */\n recentSends?: OutreachRecentSend[]\n /** When a reply last called this mailbox's email spam (AGL-2981). */\n lastComplaintAtMs?: number | null\n}\n\n/** One send in {@link OutreachMailboxHealth.recentSends}. */\nexport interface OutreachRecentSend {\n /** A digest of the send's `Message-ID`: what a bounce is matched to. */\n id: string\n atMs: number\n bounced: boolean\n}\n\n/** Why a mailbox paused itself (AGL-2981): the engine's health decision, kept. */\nexport interface OutreachMailboxAutoPause {\n reason: 'bounces_today' | 'bounce_rate' | 'complaint'\n /** The sentence the mailbox's card shows. */\n message: string\n atMs: number\n /** For a complaint, when resuming stops being premature; `null` otherwise. */\n untilMs: number | null\n}\n\n/** Where a mailbox's reply and bounce sync has read to (AGL-2981). */\nexport interface OutreachMailboxSync {\n /** Everything received before this was read by an earlier run, epoch ms. */\n throughMs: number\n /** Gmail ids of messages outside any enrollment's thread already handled. */\n handledMessageIds: string[]\n}\n\n/**\n * An address a connected Google account may send as, which Gmail has\n * verified — its own address, or an alias whose ownership Gmail confirmed\n * (AGL-2978). Only these are offered as a mailbox's `sendAs`.\n */\nexport interface OutreachSendAsAddress {\n email: string\n /** The name Gmail holds for the address, `''` when it holds none. */\n displayName: string\n /** The account's own address. */\n isPrimary: boolean\n /** The address Gmail sends as by default. */\n isDefault: boolean\n}\n\n/**\n * A rep's own mailbox, connected to send Outreach mail\n * (`orgs/{orgId}/outreachMailboxes/{id}`).\n *\n * Its grant lives in {@link OutreachMailboxCredentials} under the same id.\n */\nexport interface OutreachMailbox extends OutreachTimestamps {\n id: string\n provider: OutreachMailboxProvider\n /** The account's own address. */\n email: string\n /** The address mail goes out as: the account's, or an alias it may send as. */\n sendAs: string\n /**\n * The verified addresses `sendAs` may be, as Gmail listed them at the last\n * connect (AGL-2978). A changed alias shows up here on the next reconnect.\n */\n sendAsOptions: OutreachSendAsAddress[]\n /** The From name recipients see. */\n displayName: string\n status: OutreachMailboxStatus\n /** The most mail it sends in one local day, ramp included. */\n dailyCap: number\n window: OutreachSendWindow\n /** IANA zone the window and the day boundary are read in. */\n timezone: string\n /**\n * When the warm-up ramp began, or `null` for a mailbox sending at its full\n * cap. The ramp is measured from here, not from connection, so a paused\n * mailbox can restart it.\n */\n rampStartedAtMs: number | null\n health: OutreachMailboxHealth\n /** The member who connected it, and whose mail it is. */\n connectedByUid: string\n /** When the grant behind it was last connected (AGL-2978). */\n connectedAtMs: number\n /**\n * Set when the mailbox paused ITSELF on its health (AGL-2981), and cleared\n * when a member pauses or resumes it; absent otherwise.\n */\n autoPause?: OutreachMailboxAutoPause | null\n /** The reply and bounce sync's place in the mailbox (AGL-2981). */\n sync?: OutreachMailboxSync | null\n}\n\n/**\n * The provider grant behind one mailbox\n * (`outreachMailboxCredentials/{mailboxId}`).\n *\n * Only the fields every reader relies on are declared here; the token\n * material is added by the code that stores it. `orgId` is REQUIRED, not\n * decorative: the org erasure finds these documents by it, and a credential\n * written without one would outlive its workspace.\n *\n * NAME EVERY SEALED FIELD WITH A SECRET WORD — `refreshToken`,\n * `tokenCiphertext`. The personal-data export discloses these documents with\n * secrets redacted, and its redaction reads field names first: a name\n * carrying `token`, `secret` or `credential` is withheld whatever its value,\n * while a neutral name such as `ciphertext` is judged by the value's shape\n * alone and can be disclosed.\n */\nexport interface OutreachMailboxCredentials extends OutreachTimestamps {\n /** The mailbox id, which is also this document's id. */\n id: string\n orgId: string\n mailboxId: string\n provider: OutreachMailboxProvider\n}\n\n/** A sequence's lifecycle. Only an `active` sequence advances its enrollments. */\nexport const OUTREACH_SEQUENCE_STATUSES = [\n 'draft',\n 'active',\n 'paused',\n 'archived',\n] as const\nexport type OutreachSequenceStatus =\n (typeof OUTREACH_SEQUENCE_STATUSES)[number]\n\n/*==========================================\n * SEQUENCES (AGL-2979).\n *\n * The limits are the outbound playbook's: a person gets at most four emails\n * from one sequence, spaced by business days, and the tasks between them are\n * the rep's own touches — a LinkedIn note, a call. The engine\n * (`../engine/sequence-validation.ts`) holds a stored sequence to them.\n *==========================================*/\n\n/** The most steps one sequence holds, emails and tasks together. */\nexport const OUTREACH_MAX_STEPS = 8\n\n/** The most of those steps that send an email. */\nexport const OUTREACH_MAX_EMAIL_STEPS = 4\n\n/** The longest wait one step may carry, in business days. */\nexport const OUTREACH_MAX_STEP_DELAY_BUSINESS_DAYS = 30\n\n/**\n * The shortest wait before an email that follows an earlier email. The first\n * email may wait `0` — \"the next opening of the window\", or the same day as\n * a task before it — and so may a task, but each later email waits at least\n * this long after the step before it.\n */\nexport const OUTREACH_MIN_EMAIL_FOLLOW_UP_BUSINESS_DAYS = 1\n\n/**\n * One email step.\n *\n * Steps are a union on `kind`, so a later kind joins without reshaping the\n * ones already stored.\n */\nexport interface OutreachEmailStep {\n /** Stable within the sequence, so an edit that reorders steps is traceable. */\n id: string\n kind: 'email'\n /**\n * Business days to wait after the previous step, counted in the mailbox's\n * zone — after enrollment for the first step, where `0` means the next\n * opening of the sending window.\n */\n delayBusinessDays: number\n /**\n * The subject, merge fields allowed. Required on the first email and on\n * any email that starts a new thread; an in-thread email is sent as `Re:`\n * the thread's own subject, so its field is not read.\n */\n subject: string\n /**\n * Whether the email goes out as a reply in the thread the earlier emails\n * started. True by default for every email after the first; the first\n * email always starts the thread, whatever this says.\n */\n replyInThread: boolean\n /** Plain text with merge fields, as its author wrote it; `''` when `templateId` is set. */\n body: string\n /**\n * A CRM email template (`orgs/{orgId}/crmEmailTemplates/{id}`) whose body\n * is sent instead of `body`, or `null`. Only the body is taken from it: the\n * step's own subject is the one that is sent.\n */\n templateId: string | null\n}\n\n/** The rep's own touches a task step asks for. */\nexport const OUTREACH_TASK_KINDS = ['linkedin', 'call', 'todo'] as const\nexport type OutreachTaskKind = (typeof OUTREACH_TASK_KINDS)[number]\n\nexport const OUTREACH_TASK_KIND_LABELS: Record<OutreachTaskKind, string> = {\n linkedin: 'LinkedIn',\n call: 'Call',\n todo: 'To-do',\n}\n\n/** One task step: a CRM task for the rep, created when the step comes due. */\nexport interface OutreachTaskStep {\n id: string\n kind: 'task'\n taskKind: OutreachTaskKind\n /** What the task says, e.g. \"Connect on LinkedIn\". */\n title: string\n /** Business days after the previous step; `0` is the same day. */\n delayBusinessDays: number\n}\n\nexport type OutreachSequenceStep = OutreachEmailStep | OutreachTaskStep\n\n/** The countries a new sequence sends to: the United States alone. */\nexport const OUTREACH_DEFAULT_ALLOWED_COUNTRIES: readonly string[] = ['US']\n\n/** Behavior a sequence applies to every enrollment in it. */\nexport interface OutreachSequenceSettings {\n /**\n * The hours this sequence sends in, replacing its mailbox's own window;\n * `null` sends in the mailbox's. Read in the mailbox's zone either way.\n */\n window: OutreachSendWindow | null\n /**\n * ISO-3166-1 alpha-2 codes a recipient may be in, uppercase. Default\n * {@link OUTREACH_DEFAULT_ALLOWED_COUNTRIES}: Canada, the United Kingdom\n * and most of the EU need a consent basis a cold email does not have.\n */\n allowedCountries: string[]\n /** Whether a contact who is already a customer may be enrolled. Default `false`. */\n allowCustomers: boolean\n /**\n * Whether the links in this sequence's emails are rewritten so clicks are\n * counted (AGL-3239). Default `false`, and `false` on every sequence\n * written before the setting existed: turning it on changes what the\n * recipient sees in the body, which is not a change to make on anyone's\n * behalf.\n *\n * It buys the one engagement number a plain-text sequence can honestly\n * report. It costs a visible link: the destination in the body becomes a\n * signed link on the console that forwards to it. There is no equivalent\n * setting for opens, because a pixel needs an HTML part — see\n * `../engine/click-tracking.ts`.\n */\n trackClicks: boolean\n}\n\n/*==========================================\n * WHAT A SEQUENCE MEASURED (AGL-3239).\n *\n * Counters on the sequence document, incremented by the sending runtime and\n * by the click route. They are NOT derived from the enrollments on read: the\n * console lists enrollments a page at a time, so a rollup taken over what is\n * loaded would report the first page's numbers as the sequence's.\n *\n * Every field is optional and every absence means \"not recorded\", never\n * zero. The distinction is the whole of `campaign-report.ts`'s honesty and\n * it is kept here for the same reason: a sequence that ran before this\n * existed has no counters, and reporting its click rate as 0% would publish\n * a fact about our schema as a fact about its recipients.\n *=========================================*/\n\n/**\n * The per-destination click rollup under one sequence:\n * `orgs/{orgId}/outreachSequences/{id}/reports/links`.\n *\n * One document per sequence, holding a bounded map — the campaign rollup's\n * own shape and its own cap, so \"a link\" means the same thing in a rep's\n * report and a marketer's. Here rather than beside the writer, because the\n * console's listener is a browser module and the writer is not.\n */\nexport const OUTREACH_LINK_ROLLUP_PATH = ['reports', 'links'] as const\n\n/** The counters one sequence is judged by. */\nexport interface OutreachSequenceStats {\n /** Email steps that left. One person getting four emails counts four. */\n sent?: number\n /**\n * Distinct enrollments that have had at least one email — the denominator\n * of every engagement rate, and the thing `sent` is not.\n */\n people?: number\n /**\n * At least one email of this sequence went out with its links rewritten.\n *\n * Absent is NOT false; it is \"never recorded\", which is what every\n * sequence sent before the setting existed reads as. Either way the report\n * withholds the click rate rather than showing 0% — see\n * {@link OutreachSequenceStats} above.\n */\n clickTracked?: boolean\n /** Click EVENTS judged a person's. One reader clicking twice counts two. */\n clicks?: number\n /** Enrollments whose FIRST human click was seen: the rate's numerator. */\n uniqueClicks?: number\n /**\n * Clicks a link scanner or a security gateway made, counted apart and\n * never in the rate (`../engine/click-tracking.ts`). Shown, not hidden:\n * a large number here is the reader's evidence that the small number\n * beside it is the real one.\n */\n machineClicks?: number\n /** When a person last followed a link. */\n lastClickAtMs?: number | null\n}\n\n/** What one enrollment did with the links it was sent (AGL-3239). */\nexport interface OutreachEnrollmentEngagement {\n /** Click events judged this person's, machines excluded. */\n clicks: number\n /** The first, which is what makes them one of the sequence's `uniqueClicks`. */\n firstClickAtMs: number | null\n lastClickAtMs: number | null\n /** The destination they followed last, as `campaignLinkKey` reduces it. */\n lastClickUrl: string | null\n /** Clicks on this person's links that were a machine's. */\n machineClicks: number\n}\n\n/** An ordered set of steps sent from one mailbox (`orgs/{orgId}/outreachSequences/{id}`). */\nexport interface OutreachSequence extends OutreachTimestamps {\n id: string\n name: string\n /** The site whose CRM the enrolled people are records of. */\n hostId: string\n /**\n * The mailbox every email step is sent from. A setting of the sequence,\n * kept beside `settings` rather than inside it because enrollments and a\n * mailbox's own screens select sequences by it.\n */\n mailboxId: string\n steps: OutreachSequenceStep[]\n settings: OutreachSequenceSettings\n status: OutreachSequenceStatus\n /**\n * The campaigns the sequence is in (AGL-3254): container ids from the\n * site's `emailCampaigns`, under the field every campaign member carries\n * (`CAMPAIGN_MEMBERSHIP_FIELD`). Everyone enrolled gains them on their\n * own record at enroll time, and what the sequence produces is credited\n * to them. Absent on a sequence saved before it could join one.\n */\n campaignIds?: string[]\n /**\n * What it measured (AGL-3239). Absent until the first email leaves, and\n * absent forever on a sequence that finished before the counters existed.\n */\n stats?: OutreachSequenceStats\n}\n\n/*==========================================\n * ENROLLMENTS (AGL-2979).\n *==========================================*/\n\n/**\n * Where one person's run through a sequence stands.\n *\n * `active` sends and `paused` waits. The rest end the sending, and each says\n * why: `finished` sent every step, `replied` heard back, `bounced` reached a\n * mailbox that does not exist, `opted_out` was asked to stop, `stopped` was\n * ended by a member or a gate, `failed` could not be sent. The transitions\n * between them are the engine's (`../engine/enrollment-state.ts`).\n */\nexport const OUTREACH_ENROLLMENT_STATUSES = [\n 'active',\n 'paused',\n 'finished',\n 'replied',\n 'bounced',\n 'opted_out',\n 'stopped',\n 'failed',\n] as const\nexport type OutreachEnrollmentStatus =\n (typeof OUTREACH_ENROLLMENT_STATUSES)[number]\n\n/**\n * Why an enrollment is not `active`, recorded beside the status. `finished`\n * needs none; each other status allows the reasons\n * `OUTREACH_STOP_REASONS_BY_STATUS` names.\n */\nexport const OUTREACH_STOP_REASONS = [\n /** A person wrote back in the thread. */\n 'reply',\n /** The recipient's server refused the address for good. */\n 'hard_bounce',\n /** A reply asked not to be emailed again. */\n 'opt_out_reply',\n /** The unsubscribe link or header was used. */\n 'unsubscribe',\n /** The address is on the organization's do-not-contact list. */\n 'do_not_contact',\n /** A gate refused the next send — the person became a customer, say. */\n 'gate',\n /** A member paused or stopped it. */\n 'manual',\n /** The sequence was archived with the person still in it. */\n 'sequence_archived',\n /** The provider refused the send for good, or the email could not be composed. */\n 'send_failed',\n] as const\nexport type OutreachStopReason = (typeof OUTREACH_STOP_REASONS)[number]\n\n/** The statuses a stop reason is recorded with, and the reasons each allows. */\nexport const OUTREACH_STOP_REASONS_BY_STATUS: Readonly<\n Record<\n Exclude<OutreachEnrollmentStatus, 'active' | 'finished'>,\n readonly OutreachStopReason[]\n >\n> = {\n paused: ['manual'],\n replied: ['reply'],\n bounced: ['hard_bounce'],\n opted_out: ['opt_out_reply', 'unsubscribe', 'do_not_contact'],\n stopped: ['manual', 'gate', 'sequence_archived'],\n failed: ['send_failed'],\n}\n\n/**\n * What a rep confirms before a COLD contact is enrolled — one with no\n * inbound capture behind them — each recorded with who confirmed it and\n * when, because each is a fact only the rep can know:\n *\n * - `us_business_address`: the address is a business address in the US;\n * - `published_or_given`: they or their company published it, or they gave\n * it to us — never guessed from a name or bought on a list;\n * - `verified_deliverable`: a verifier said it accepts mail.\n */\nexport const OUTREACH_ATTESTATION_KINDS = [\n 'us_business_address',\n 'published_or_given',\n 'verified_deliverable',\n] as const\nexport type OutreachAttestationKind = (typeof OUTREACH_ATTESTATION_KINDS)[number]\n\n/** The sentence a rep ticks for each attestation. */\nexport const OUTREACH_ATTESTATION_LABELS: Record<OutreachAttestationKind, string> = {\n us_business_address: 'This is a US business address',\n published_or_given:\n 'They or their company published this address, or they gave it to us',\n verified_deliverable: 'This address was verified as deliverable',\n}\n\n/** One confirmation, as stored. */\nexport interface OutreachAttestation {\n /** The member who confirmed it. */\n uid: string\n atMs: number\n}\n\n/** The confirmations an enrollment carries, by kind. */\nexport type OutreachAttestations = Partial<\n Record<OutreachAttestationKind, OutreachAttestation>\n>\n\n/** The longest personal line an enrollment keeps: one sentence, not a letter. */\nexport const OUTREACH_PERSONAL_LINE_MAX = 300\n\n/**\n * Which CRM record an enrollment names (AGL-3234). A person is a LEAD until\n * somebody qualifies them and a CONTACT after, and a sequence works either:\n * an enrollment made on a lead follows the lead to the contact it becomes,\n * so the thread and the steps carry on as one enrollment.\n */\nexport const OUTREACH_ENROLLMENT_TARGETS = ['contact', 'lead'] as const\nexport type OutreachEnrollmentTarget = (typeof OUTREACH_ENROLLMENT_TARGETS)[number]\n\n/** One person in one sequence (`orgs/{orgId}/outreachEnrollments/{id}`). */\nexport interface OutreachEnrollment extends OutreachTimestamps {\n id: string\n sequenceId: string\n /**\n * The record the person is (AGL-3234): `contact` for a CRM contact,\n * `lead` for a lead the sequence's site holds. A stored enrollment with\n * no target is a contact's — every enrollment was, before leads could be\n * sequenced.\n */\n target: OutreachEnrollmentTarget\n /**\n * The CRM contact the person is — `''` while the enrollment targets a\n * lead that has not converted. Filled in, beside `target: 'contact'`, the\n * moment the lead becomes a contact.\n */\n contactId: string\n /**\n * `hosts/{hostId}/leads/{leadId}` — the person key — for an enrollment\n * made on a lead; kept once the lead converts, so the lead's page still\n * lists the sequence. `null` for an enrollment made on a contact.\n */\n leadId: string | null\n /**\n * The person's name as the sending site knew it at enrollment, `''` when\n * it had none — what the enrollments table shows beside the address,\n * without a read of every record on the page (AGL-2980).\n */\n contactName: string\n /** The address the steps go to, normalized, captured at enrollment. */\n email: string\n hostId: string\n mailboxId: string\n /** The index into `steps` of the NEXT step to run. */\n stepIndex: number\n /** When that step comes due, or `null` when nothing is waiting. */\n nextDueAtMs: number | null\n status: OutreachEnrollmentStatus\n /** Why the status is not `active`; `null` while active and once finished. */\n stopReason: OutreachStopReason | null\n /** Plain-language detail: the gate's reason, the bounce's diagnostic. */\n stopDetail: string | null\n stoppedAtMs: number | null\n /** The member who paused or stopped it; `null` when the engine did. */\n stoppedByUid: string | null\n /**\n * The rep's signal sentence — why this person, now — merged into the\n * steps as `{{enrollment.personalLine}}`. Required for a cold contact.\n */\n personalLine: string\n /** Whether the contact was cold (no inbound capture) when enrolled. */\n cold: boolean\n attestations: OutreachAttestations\n /** The member who enrolled the person. */\n enrolledByUid: string\n /** The provider thread the next in-thread email is sent into, once one exists. */\n gmailThreadId: string | null\n /** Every provider thread this enrollment has sent into, oldest first — what reply sync watches. */\n gmailThreadIds: string[]\n /** The subject the current thread was started with, as sent. */\n threadSubject: string | null\n /**\n * The `Message-ID`s of the emails sent into the current thread, oldest\n * first, angle brackets included: the next in-thread email answers the\n * last and names them all in `References`.\n */\n messageIds: string[]\n /** When the last step ran. */\n lastSentAtMs: number | null\n /**\n * A sending run's hold on the step it is running (AGL-2981): taken in a\n * transaction before the step runs, cleared when it is recorded. Absent\n * or `null` while no run holds one.\n */\n sendClaim?: OutreachSendClaim | null\n /** Every step the runtime ran, oldest first (AGL-2981). */\n stepRecords?: OutreachStepRecord[]\n /** Gmail ids of this enrollment's thread messages the sync has handled, the last hundred. */\n syncedMessageIds?: string[]\n /**\n * What this person did with the links they were sent (AGL-3239). Absent\n * until their first click, which is why the table reads an absence as\n * \"no clicks\" only for a sequence that tracks them at all.\n */\n engagement?: OutreachEnrollmentEngagement\n /**\n * The sequence's campaigns as they stood when the person was enrolled\n * (AGL-3254): what every outcome of this enrollment is credited to. A\n * campaign the sequence joins later does not claim the people already\n * in it, and one it leaves keeps what it was credited with.\n */\n campaignIds?: string[]\n}\n\n/** A sending run's claim on one enrollment's step (AGL-2981). */\nexport interface OutreachSendClaim {\n /** The run that holds it. */\n token: string\n atMs: number\n stepIndex: number\n /**\n * The `Message-ID` an email step goes out with, minted before the send, so\n * a claim a run died holding is settled by looking for the message rather\n * than by sending it again. `null` for a task step.\n */\n messageId: string | null\n}\n\n/** One step the runtime ran for an enrollment (AGL-2981). */\nexport interface OutreachStepRecord {\n stepIndex: number\n stepId: string\n kind: 'email' | 'task'\n atMs: number\n /** Gmail's id for the sent message. */\n gmailMessageId?: string\n /** Gmail's thread the message went into. */\n gmailThreadId?: string\n /** The `Message-ID` it went out with, angle brackets included. */\n messageId?: string\n /** The subject as sent. */\n subject?: string\n /** The record system's task for a task step; `null` when none could be filed. */\n taskId?: string | null\n /**\n * The destinations this email's links were rewritten to point at, in the\n * order a click token indexes them (AGL-3239). Absent on a step that\n * carried no links, and on every step sent before tracking existed.\n *\n * Kept so the console can say WHICH link a person followed without the\n * token having to carry the URL back to us, and so a rewritten body can be\n * read afterwards for what it actually offered them.\n */\n links?: string[]\n}\n\n/*==========================================\n * ORGANIZATION SETTINGS (AGL-2979).\n *==========================================*/\n\n/**\n * What every Outreach email's footer says about who sent it — the\n * identification and the postal address CAN-SPAM requires on commercial\n * mail. The composer refuses to write an email without a legal name and a\n * postal address, and a sequence cannot be activated without them.\n */\nexport interface OutreachOrgSettings {\n /** The organization's legal name, as the footer prints it: \"Example Co LLC\". */\n legalName: string\n /**\n * The name the solicitation sentence uses when it is not the legal name:\n * \"This is a sales email from Example Co.\" `''` uses the legal\n * name.\n */\n brandName: string\n /**\n * A valid physical postal address: a street address, a USPS PO box, or a\n * private mailbox registered with the USPS. Line breaks are printed as\n * commas.\n */\n postalAddress: string\n}\n\n/** The id of the compliance document in the `settings` collection. */\nexport const OUTREACH_COMPLIANCE_SETTINGS_ID = 'compliance'\n\n/**\n * The organization's Outreach compliance settings\n * (`orgs/{orgId}/outreachSettings/compliance`): the footer's sender identity,\n * and the countries Outreach may send to at all.\n *\n * `allowedCountries` is a CEILING over every sequence's own list — a\n * sequence sends only to the countries both name — so narrowing it here\n * narrows every sequence at once, without editing any of them. Default\n * {@link OUTREACH_DEFAULT_ALLOWED_COUNTRIES}.\n */\nexport interface OutreachComplianceSettings extends OutreachOrgSettings {\n /** ISO-3166-1 alpha-2 codes, uppercase, in the order they were chosen. */\n allowedCountries: string[]\n}\n\n/** The compliance settings as stored, with who changed them last. */\nexport interface OutreachComplianceSettingsDocument\n extends OutreachComplianceSettings {\n /** `0` until the organization first saves them. */\n updatedAtMs: number\n updatedByUid: string | null\n}\n\n/*==========================================\n * DO NOT CONTACT (AGL-2980).\n *\n * The organization's own list of addresses Outreach never emails, whoever\n * enrolls them and from whichever site. A member adds one by hand; the\n * sending runtime adds one when a reply asks to be left alone, when the\n * unsubscribe link is used, and when an address bounces for good.\n *\n * AN ENTRY CARRIES NO ADDRESS. Its id is `outreachDoNotContactKey(email)` —\n * the same hash the platform's suppression lists key by — and that is all a\n * lookup needs, since every caller holds the address it is about to use.\n * So the list keeps working after a person is erased from the workspace,\n * which is exactly when a promise not to email them must still hold, while\n * holding nothing that identifies them.\n *==========================================*/\n\n/** Why an address is on the list. */\nexport const OUTREACH_DO_NOT_CONTACT_REASONS = [\n /** A member put it there. */\n 'manual',\n /** A reply asked not to be emailed again. */\n 'opt_out_reply',\n /** The unsubscribe link or header was used. */\n 'unsubscribe',\n /** Mail to it bounced for good. */\n 'hard_bounce',\n /**\n * The recipient organization's mail gateway refused the sender outright\n * (AGL-3244) — a Barracuda, Proofpoint or Mimecast policy block — which is\n * a verdict on the whole domain, and is filed against it.\n */\n 'gateway_block',\n] as const\nexport type OutreachDoNotContactReason =\n (typeof OUTREACH_DO_NOT_CONTACT_REASONS)[number]\n\n/** What put an address on the list: a member, or the sending runtime. */\nexport const OUTREACH_DO_NOT_CONTACT_SOURCES = ['member', 'runtime'] as const\nexport type OutreachDoNotContactSource =\n (typeof OUTREACH_DO_NOT_CONTACT_SOURCES)[number]\n\n/** One address on the list (`orgs/{orgId}/outreachDoNotContact/{key}`). */\nexport interface OutreachDoNotContactEntry {\n /** `outreachDoNotContactKey` of the address, which is also the document id. */\n key: string\n reason: OutreachDoNotContactReason\n source: OutreachDoNotContactSource\n /** The member who added it; `null` when the runtime did. */\n addedByUid: string | null\n addedAtMs: number\n /** The enrollment that led here, when one did. */\n enrollmentId: string | null\n /** That enrollment's sequence. */\n sequenceId: string | null\n /** Plain-language detail: why the member added it, the bounce's diagnostic. */\n detail: string | null\n}\n\n/**\n * One domain on the list (`orgs/{orgId}/outreachDoNotContactDomains/{domain}`)\n * (AGL-3244): no address at it is emailed, whoever enrolls them.\n *\n * Unlike an address entry it CARRIES THE DOMAIN, in clear, because the\n * Compliance page lists it and a member takes it off by name; a domain is a\n * company's, not a person's, and a person erasure leaves it alone. A member\n * adds one by hand; the sending runtime adds one when a hard bounce reads\n * as the domain's mail gateway refusing the sender rather than one address\n * being unknown.\n */\nexport interface OutreachDoNotContactDomainEntry {\n /** The domain, lower-cased, which is also the document id. */\n domain: string\n reason: OutreachDoNotContactReason\n source: OutreachDoNotContactSource\n /** The member who added it; `null` when the runtime did. */\n addedByUid: string | null\n addedAtMs: number\n /** The enrollment whose bounce led here, when one did. */\n enrollmentId: string | null\n /** That enrollment's sequence. */\n sequenceId: string | null\n /** Plain-language detail: the member's note, or the bounce's diagnostic. */\n detail: string | null\n}\n"],"names":["OUTREACH_COLLECTIONS","mailboxes","sequences","enrollments","settings","doNotContact","doNotContactDomains","mailboxCredentials","outreachOrgCollectionPath","orgId","collection","OUTREACH_MAILBOX_PROVIDERS","OUTREACH_MAILBOX_STATUSES","OUTREACH_SEQUENCE_STATUSES","OUTREACH_MAX_STEPS","OUTREACH_MAX_EMAIL_STEPS","OUTREACH_MAX_STEP_DELAY_BUSINESS_DAYS","OUTREACH_MIN_EMAIL_FOLLOW_UP_BUSINESS_DAYS","OUTREACH_TASK_KINDS","OUTREACH_TASK_KIND_LABELS","linkedin","call","todo","OUTREACH_DEFAULT_ALLOWED_COUNTRIES","OUTREACH_LINK_ROLLUP_PATH","OUTREACH_ENROLLMENT_STATUSES","OUTREACH_STOP_REASONS","OUTREACH_STOP_REASONS_BY_STATUS","paused","replied","bounced","opted_out","stopped","failed","OUTREACH_ATTESTATION_KINDS","OUTREACH_ATTESTATION_LABELS","us_business_address","published_or_given","verified_deliverable","OUTREACH_PERSONAL_LINE_MAX","OUTREACH_ENROLLMENT_TARGETS","OUTREACH_COMPLIANCE_SETTINGS_ID","OUTREACH_DO_NOT_CONTACT_REASONS","OUTREACH_DO_NOT_CON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/lib/model/outreach.types.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * THE OUTREACH DOCUMENT MODEL (AGL-2974).\n *\n * One file both halves import — the console reads these documents, the server\n * routes write them — so a field is spelled once. Client-safe: types and\n * constants only, nothing that reaches Firestore.\n *\n * EVERY DOCUMENT HERE IS SERVER-WRITTEN. The Firestore rules let an\n * org-wide member holding `outreach.use` READ the org collections on a\n * workspace that carries `features.outreach`, and refuse every client write,\n * because these documents are the sending engine's state: a client that\n * could write a mailbox could lift its daily cap, and one that could write\n * an enrollment could send a step twice. The credential collection is closed\n * to clients entirely.\n *\n * Lean on purpose. Each type carries what the mailbox and sequence work is\n * known to need and nothing speculative; a field is added where the code\n * that reads it lands. Times are epoch milliseconds throughout, the unit\n * `nextDueAtMs` has to be compared in.\n */\n\n/**\n * Where Outreach keeps its records.\n *\n * Five collections under the organization, and one at the top level. The\n * org-scoped ones are erased with the org, whose erasure deletes the whole\n * `orgs/{orgId}` tree. The top-level one holds credentials, so it is keyed by\n * an `orgId` FIELD that a path-scoped delete of `orgs/{orgId}` cannot see:\n * the org erasure sweeps it by that field\n * (`libs/tenant/data/admin/src/lib/server/erase.ts` names it as a literal,\n * which the boundary forces, and `outreach.types.spec.ts` holds the two\n * spellings together, along with the rules').\n */\nexport const OUTREACH_COLLECTIONS = {\n /** `orgs/{orgId}/outreachMailboxes/{mailboxId}` — a connected mailbox. */\n mailboxes: 'outreachMailboxes',\n /** `orgs/{orgId}/outreachSequences/{sequenceId}` — the steps to send. */\n sequences: 'outreachSequences',\n /** `orgs/{orgId}/outreachEnrollments/{enrollmentId}` — one person in one sequence. */\n enrollments: 'outreachEnrollments',\n /**\n * `orgs/{orgId}/outreachSettings/{settingsId}` — the organization's own\n * Outreach settings, one document per concern. `compliance` holds who\n * every email says sent it and the countries Outreach may send to.\n */\n settings: 'outreachSettings',\n /**\n * `orgs/{orgId}/outreachDoNotContact/{key}` — the addresses Outreach never\n * emails for this organization, keyed by `outreachDoNotContactKey`.\n */\n doNotContact: 'outreachDoNotContact',\n /**\n * `orgs/{orgId}/outreachDoNotContactDomains/{domain}` — the domains\n * Outreach never emails for this organization (AGL-3244), keyed by the\n * domain itself: a domain names a company, not a person.\n */\n doNotContactDomains: 'outreachDoNotContactDomains',\n /**\n * `outreachMailboxCredentials/{mailboxId}` — the provider grant behind a\n * mailbox. TOP-LEVEL and closed to every client, staff included, so the\n * token material never shares a readable path with the mailbox it serves.\n */\n mailboxCredentials: 'outreachMailboxCredentials',\n} as const\n\n/** The org-scoped collections, by their {@link OUTREACH_COLLECTIONS} key. */\nexport type OutreachOrgCollection = Exclude<\n keyof typeof OUTREACH_COLLECTIONS,\n 'mailboxCredentials'\n>\n\n/** `orgs/{orgId}/<collection>` for one of the org-scoped collections. */\nexport function outreachOrgCollectionPath(\n orgId: string,\n collection: OutreachOrgCollection,\n): string {\n return `orgs/${orgId}/${OUTREACH_COLLECTIONS[collection]}`\n}\n\n/** Stamped by the server on every write. */\nexport interface OutreachTimestamps {\n createdAtMs: number\n updatedAtMs: number\n}\n\n/** The mail providers a mailbox can be connected through. */\nexport const OUTREACH_MAILBOX_PROVIDERS = ['google'] as const\nexport type OutreachMailboxProvider =\n (typeof OUTREACH_MAILBOX_PROVIDERS)[number]\n\n/**\n * Where a mailbox stands.\n *\n * - `connected` — the grant works and the mailbox may send.\n * - `paused` — a member stopped it; enrollments on it wait.\n * - `reconnect_required` — the provider refused the grant (revoked, expired,\n * password changed); nothing sends until the rep connects it again.\n * - `disconnected` — a member removed it; its credential is gone.\n */\nexport const OUTREACH_MAILBOX_STATUSES = [\n 'connected',\n 'paused',\n 'reconnect_required',\n 'disconnected',\n] as const\nexport type OutreachMailboxStatus = (typeof OUTREACH_MAILBOX_STATUSES)[number]\n\n/**\n * The hours a mailbox sends in, in its own {@link OutreachMailbox.timezone}.\n * A step that comes due outside the window waits for the next opening.\n */\nexport interface OutreachSendWindow {\n /** Days of the week it sends on, `0` Sunday through `6` Saturday. */\n days: number[]\n /** Minutes after local midnight the window opens, inclusive. */\n startMinute: number\n /** Minutes after local midnight the window closes, exclusive. */\n endMinute: number\n}\n\n/**\n * One mailbox-local day's sending, as the health panel sums it (AGL-2978).\n */\nexport interface OutreachMailboxDailyHealth {\n sent: number\n bounces: number\n replies: number\n}\n\n/**\n * The counters a mailbox's sending is judged by.\n *\n * `sentToday` is what `dailyCap` refuses against, and it belongs to one\n * mailbox-local day — `sentOnDay` — so a counter from yesterday is read as\n * zero rather than as today's spend.\n */\nexport interface OutreachMailboxHealth {\n sentToday: number\n /** The local day (`YYYY-MM-DD` in the mailbox's timezone) `sentToday` counts. */\n sentOnDay: string | null\n /** Hard bounces on mail this mailbox sent. */\n bounces: number\n /** Replies detected on Outreach threads. */\n replies: number\n lastSentAtMs: number | null\n /** The last provider error, kept until a later send succeeds. */\n lastErrorAtMs: number | null\n lastErrorCode: string | null\n /**\n * Per mailbox-local day (`YYYY-MM-DD`), the sends, bounces and replies\n * counted on it (AGL-2978). The Mailboxes panel shows the last seven days\n * summed; the sending runtime increments the day it counts on and may drop\n * days older than a week. Absent, or empty, until the first send.\n */\n daily?: Record<string, OutreachMailboxDailyHealth>\n /**\n * The mailbox's most recent sends, newest last, at most\n * `OUTREACH_BOUNCE_RATE_WINDOW_SENDS` of them, each marked when a hard\n * bounce came back for it (AGL-2981): the window the bounce-rate pause is\n * judged over. A send is named by a digest of its `Message-ID`, never by\n * its recipient.\n */\n recentSends?: OutreachRecentSend[]\n /** When a reply last called this mailbox's email spam (AGL-2981). */\n lastComplaintAtMs?: number | null\n}\n\n/** One send in {@link OutreachMailboxHealth.recentSends}. */\nexport interface OutreachRecentSend {\n /** A digest of the send's `Message-ID`: what a bounce is matched to. */\n id: string\n atMs: number\n bounced: boolean\n}\n\n/** Why a mailbox paused itself (AGL-2981): the engine's health decision, kept. */\nexport interface OutreachMailboxAutoPause {\n reason: 'bounces_today' | 'bounce_rate' | 'complaint'\n /** The sentence the mailbox's card shows. */\n message: string\n atMs: number\n /** For a complaint, when resuming stops being premature; `null` otherwise. */\n untilMs: number | null\n}\n\n/** Where a mailbox's reply and bounce sync has read to (AGL-2981). */\nexport interface OutreachMailboxSync {\n /** Everything received before this was read by an earlier run, epoch ms. */\n throughMs: number\n /** Gmail ids of messages outside any enrollment's thread already handled. */\n handledMessageIds: string[]\n}\n\n/**\n * An address a connected Google account may send as, which Gmail has\n * verified — its own address, or an alias whose ownership Gmail confirmed\n * (AGL-2978). Only these are offered as a mailbox's `sendAs`.\n */\nexport interface OutreachSendAsAddress {\n email: string\n /** The name Gmail holds for the address, `''` when it holds none. */\n displayName: string\n /** The account's own address. */\n isPrimary: boolean\n /** The address Gmail sends as by default. */\n isDefault: boolean\n}\n\n/**\n * A rep's own mailbox, connected to send Outreach mail\n * (`orgs/{orgId}/outreachMailboxes/{id}`).\n *\n * Its grant lives in {@link OutreachMailboxCredentials} under the same id.\n */\nexport interface OutreachMailbox extends OutreachTimestamps {\n id: string\n provider: OutreachMailboxProvider\n /** The account's own address. */\n email: string\n /** The address mail goes out as: the account's, or an alias it may send as. */\n sendAs: string\n /**\n * The verified addresses `sendAs` may be, as Gmail listed them at the last\n * connect (AGL-2978). A changed alias shows up here on the next reconnect.\n */\n sendAsOptions: OutreachSendAsAddress[]\n /** The From name recipients see. */\n displayName: string\n status: OutreachMailboxStatus\n /** The most mail it sends in one local day, ramp included. */\n dailyCap: number\n window: OutreachSendWindow\n /** IANA zone the window and the day boundary are read in. */\n timezone: string\n /**\n * When the warm-up ramp began, or `null` for a mailbox sending at its full\n * cap. The ramp is measured from here, not from connection, so a paused\n * mailbox can restart it.\n */\n rampStartedAtMs: number | null\n health: OutreachMailboxHealth\n /** The member who connected it, and whose mail it is. */\n connectedByUid: string\n /** When the grant behind it was last connected (AGL-2978). */\n connectedAtMs: number\n /**\n * Set when the mailbox paused ITSELF on its health (AGL-2981), and cleared\n * when a member pauses or resumes it; absent otherwise.\n */\n autoPause?: OutreachMailboxAutoPause | null\n /** The reply and bounce sync's place in the mailbox (AGL-2981). */\n sync?: OutreachMailboxSync | null\n}\n\n/**\n * The provider grant behind one mailbox\n * (`outreachMailboxCredentials/{mailboxId}`).\n *\n * Only the fields every reader relies on are declared here; the token\n * material is added by the code that stores it. `orgId` is REQUIRED, not\n * decorative: the org erasure finds these documents by it, and a credential\n * written without one would outlive its workspace.\n *\n * NAME EVERY SEALED FIELD WITH A SECRET WORD — `refreshToken`,\n * `tokenCiphertext`. The personal-data export discloses these documents with\n * secrets redacted, and its redaction reads field names first: a name\n * carrying `token`, `secret` or `credential` is withheld whatever its value,\n * while a neutral name such as `ciphertext` is judged by the value's shape\n * alone and can be disclosed.\n */\nexport interface OutreachMailboxCredentials extends OutreachTimestamps {\n /** The mailbox id, which is also this document's id. */\n id: string\n orgId: string\n mailboxId: string\n provider: OutreachMailboxProvider\n}\n\n/** A sequence's lifecycle. Only an `active` sequence advances its enrollments. */\nexport const OUTREACH_SEQUENCE_STATUSES = [\n 'draft',\n 'active',\n 'paused',\n 'archived',\n] as const\nexport type OutreachSequenceStatus =\n (typeof OUTREACH_SEQUENCE_STATUSES)[number]\n\n/*==========================================\n * SEQUENCES (AGL-2979).\n *\n * The limits are the outbound playbook's: a person gets at most four emails\n * from one sequence, spaced by business days, and the tasks between them are\n * the rep's own touches — a LinkedIn note, a call. The engine\n * (`../engine/sequence-validation.ts`) holds a stored sequence to them.\n *==========================================*/\n\n/** The most steps one sequence holds, emails and tasks together. */\nexport const OUTREACH_MAX_STEPS = 8\n\n/** The most of those steps that send an email. */\nexport const OUTREACH_MAX_EMAIL_STEPS = 4\n\n/** The longest wait one step may carry, in business days. */\nexport const OUTREACH_MAX_STEP_DELAY_BUSINESS_DAYS = 30\n\n/**\n * The shortest wait before an email that follows an earlier email. The first\n * email may wait `0` — \"the next opening of the window\", or the same day as\n * a task before it — and so may a task, but each later email waits at least\n * this long after the step before it.\n */\nexport const OUTREACH_MIN_EMAIL_FOLLOW_UP_BUSINESS_DAYS = 1\n\n/**\n * One email step.\n *\n * Steps are a union on `kind`, so a later kind joins without reshaping the\n * ones already stored.\n */\nexport interface OutreachEmailStep {\n /** Stable within the sequence, so an edit that reorders steps is traceable. */\n id: string\n kind: 'email'\n /**\n * Business days to wait after the previous step, counted in the mailbox's\n * zone — after enrollment for the first step, where `0` means the next\n * opening of the sending window.\n */\n delayBusinessDays: number\n /**\n * The subject, merge fields allowed. Required on the first email and on\n * any email that starts a new thread; an in-thread email is sent as `Re:`\n * the thread's own subject, so its field is not read.\n */\n subject: string\n /**\n * Whether the email goes out as a reply in the thread the earlier emails\n * started. True by default for every email after the first; the first\n * email always starts the thread, whatever this says.\n */\n replyInThread: boolean\n /** Plain text with merge fields, as its author wrote it; `''` when `templateId` is set. */\n body: string\n /**\n * A CRM email template (`orgs/{orgId}/crmEmailTemplates/{id}`) whose body\n * is sent instead of `body`, or `null`. Only the body is taken from it: the\n * step's own subject is the one that is sent.\n */\n templateId: string | null\n}\n\n/** The rep's own touches a task step asks for. */\nexport const OUTREACH_TASK_KINDS = ['linkedin', 'call', 'todo'] as const\nexport type OutreachTaskKind = (typeof OUTREACH_TASK_KINDS)[number]\n\nexport const OUTREACH_TASK_KIND_LABELS: Record<OutreachTaskKind, string> = {\n linkedin: 'LinkedIn',\n call: 'Call',\n todo: 'To-do',\n}\n\n/** One task step: a CRM task for the rep, created when the step comes due. */\nexport interface OutreachTaskStep {\n id: string\n kind: 'task'\n taskKind: OutreachTaskKind\n /** What the task says, e.g. \"Connect on LinkedIn\". */\n title: string\n /** Business days after the previous step; `0` is the same day. */\n delayBusinessDays: number\n}\n\nexport type OutreachSequenceStep = OutreachEmailStep | OutreachTaskStep\n\n/** The countries a new sequence sends to: the United States alone. */\nexport const OUTREACH_DEFAULT_ALLOWED_COUNTRIES: readonly string[] = ['US']\n\n/** Behavior a sequence applies to every enrollment in it. */\nexport interface OutreachSequenceSettings {\n /**\n * The hours this sequence sends in, replacing its mailbox's own window;\n * `null` sends in the mailbox's. Read in the mailbox's zone either way.\n */\n window: OutreachSendWindow | null\n /**\n * ISO-3166-1 alpha-2 codes a recipient may be in, uppercase. Default\n * {@link OUTREACH_DEFAULT_ALLOWED_COUNTRIES}: Canada, the United Kingdom\n * and most of the EU need a consent basis a cold email does not have.\n */\n allowedCountries: string[]\n /** Whether a contact who is already a customer may be enrolled. Default `false`. */\n allowCustomers: boolean\n /**\n * Whether the links in this sequence's emails are rewritten so clicks are\n * counted (AGL-3239). Default `false`, and `false` on every sequence\n * written before the setting existed: turning it on changes what the\n * recipient sees in the body, which is not a change to make on anyone's\n * behalf.\n *\n * It buys the one engagement number a plain-text sequence can honestly\n * report. It costs a visible link: the destination in the body becomes a\n * signed link on the console that forwards to it. There is no equivalent\n * setting for opens, because a pixel needs an HTML part — see\n * `../engine/click-tracking.ts`.\n */\n trackClicks: boolean\n}\n\n/*==========================================\n * WHAT A SEQUENCE MEASURED (AGL-3239).\n *\n * Counters on the sequence document, incremented by the sending runtime and\n * by the click route. They are NOT derived from the enrollments on read: the\n * console lists enrollments a page at a time, so a rollup taken over what is\n * loaded would report the first page's numbers as the sequence's.\n *\n * Every field is optional and every absence means \"not recorded\", never\n * zero. The distinction is the whole of `campaign-report.ts`'s honesty and\n * it is kept here for the same reason: a sequence that ran before this\n * existed has no counters, and reporting its click rate as 0% would publish\n * a fact about our schema as a fact about its recipients.\n *=========================================*/\n\n/**\n * The per-destination click rollup under one sequence:\n * `orgs/{orgId}/outreachSequences/{id}/reports/links`.\n *\n * One document per sequence, holding a bounded map — the campaign rollup's\n * own shape and its own cap, so \"a link\" means the same thing in a rep's\n * report and a marketer's. Here rather than beside the writer, because the\n * console's listener is a browser module and the writer is not.\n */\nexport const OUTREACH_LINK_ROLLUP_PATH = ['reports', 'links'] as const\n\n/** The counters one sequence is judged by. */\nexport interface OutreachSequenceStats {\n /** Email steps that left. One person getting four emails counts four. */\n sent?: number\n /**\n * Distinct enrollments that have had at least one email — the denominator\n * of every engagement rate, and the thing `sent` is not.\n */\n people?: number\n /**\n * At least one email of this sequence went out with its links rewritten.\n *\n * Absent is NOT false; it is \"never recorded\", which is what every\n * sequence sent before the setting existed reads as. Either way the report\n * withholds the click rate rather than showing 0% — see\n * {@link OutreachSequenceStats} above.\n */\n clickTracked?: boolean\n /** Click EVENTS judged a person's. One reader clicking twice counts two. */\n clicks?: number\n /** Enrollments whose FIRST human click was seen: the rate's numerator. */\n uniqueClicks?: number\n /**\n * Clicks a link scanner or a security gateway made, counted apart and\n * never in the rate (`../engine/click-tracking.ts`). Shown, not hidden:\n * a large number here is the reader's evidence that the small number\n * beside it is the real one.\n */\n machineClicks?: number\n /** When a person last followed a link. */\n lastClickAtMs?: number | null\n}\n\n/** What one enrollment did with the links it was sent (AGL-3239). */\nexport interface OutreachEnrollmentEngagement {\n /** Click events judged this person's, machines excluded. */\n clicks: number\n /** The first, which is what makes them one of the sequence's `uniqueClicks`. */\n firstClickAtMs: number | null\n lastClickAtMs: number | null\n /** The destination they followed last, as `campaignLinkKey` reduces it. */\n lastClickUrl: string | null\n /** Clicks on this person's links that were a machine's. */\n machineClicks: number\n}\n\n/** An ordered set of steps sent from one mailbox (`orgs/{orgId}/outreachSequences/{id}`). */\nexport interface OutreachSequence extends OutreachTimestamps {\n id: string\n name: string\n /** The site whose CRM the enrolled people are records of. */\n hostId: string\n /**\n * The mailbox every email step is sent from. A setting of the sequence,\n * kept beside `settings` rather than inside it because enrollments and a\n * mailbox's own screens select sequences by it.\n */\n mailboxId: string\n steps: OutreachSequenceStep[]\n settings: OutreachSequenceSettings\n status: OutreachSequenceStatus\n /**\n * The campaigns the sequence is in (AGL-3254): container ids from the\n * org's `emailCampaigns`, under the field every campaign member carries\n * (`CAMPAIGN_MEMBERSHIP_FIELD`). Everyone enrolled gains them on their\n * own record at enroll time, and what the sequence produces is credited\n * to them. Absent on a sequence saved before it could join one.\n */\n campaignIds?: string[]\n /**\n * What it measured (AGL-3239). Absent until the first email leaves, and\n * absent forever on a sequence that finished before the counters existed.\n */\n stats?: OutreachSequenceStats\n}\n\n/*==========================================\n * ENROLLMENTS (AGL-2979).\n *==========================================*/\n\n/**\n * Where one person's run through a sequence stands.\n *\n * `active` sends and `paused` waits. The rest end the sending, and each says\n * why: `finished` sent every step, `replied` heard back, `bounced` reached a\n * mailbox that does not exist, `opted_out` was asked to stop, `stopped` was\n * ended by a member or a gate, `failed` could not be sent. The transitions\n * between them are the engine's (`../engine/enrollment-state.ts`).\n */\nexport const OUTREACH_ENROLLMENT_STATUSES = [\n 'active',\n 'paused',\n 'finished',\n 'replied',\n 'bounced',\n 'opted_out',\n 'stopped',\n 'failed',\n] as const\nexport type OutreachEnrollmentStatus =\n (typeof OUTREACH_ENROLLMENT_STATUSES)[number]\n\n/**\n * Why an enrollment is not `active`, recorded beside the status. `finished`\n * needs none; each other status allows the reasons\n * `OUTREACH_STOP_REASONS_BY_STATUS` names.\n */\nexport const OUTREACH_STOP_REASONS = [\n /** A person wrote back in the thread. */\n 'reply',\n /** The recipient's server refused the address for good. */\n 'hard_bounce',\n /** A reply asked not to be emailed again. */\n 'opt_out_reply',\n /** The unsubscribe link or header was used. */\n 'unsubscribe',\n /** The address is on the organization's do-not-contact list. */\n 'do_not_contact',\n /** A gate refused the next send — the person became a customer, say. */\n 'gate',\n /** A member paused or stopped it. */\n 'manual',\n /** The sequence was archived with the person still in it. */\n 'sequence_archived',\n /** The provider refused the send for good, or the email could not be composed. */\n 'send_failed',\n] as const\nexport type OutreachStopReason = (typeof OUTREACH_STOP_REASONS)[number]\n\n/** The statuses a stop reason is recorded with, and the reasons each allows. */\nexport const OUTREACH_STOP_REASONS_BY_STATUS: Readonly<\n Record<\n Exclude<OutreachEnrollmentStatus, 'active' | 'finished'>,\n readonly OutreachStopReason[]\n >\n> = {\n paused: ['manual'],\n replied: ['reply'],\n bounced: ['hard_bounce'],\n opted_out: ['opt_out_reply', 'unsubscribe', 'do_not_contact'],\n stopped: ['manual', 'gate', 'sequence_archived'],\n failed: ['send_failed'],\n}\n\n/**\n * What a rep confirms before a COLD contact is enrolled — one with no\n * inbound capture behind them — each recorded with who confirmed it and\n * when, because each is a fact only the rep can know:\n *\n * - `us_business_address`: the address is a business address in the US;\n * - `published_or_given`: they or their company published it, or they gave\n * it to us — never guessed from a name or bought on a list;\n * - `verified_deliverable`: a verifier said it accepts mail.\n */\nexport const OUTREACH_ATTESTATION_KINDS = [\n 'us_business_address',\n 'published_or_given',\n 'verified_deliverable',\n] as const\nexport type OutreachAttestationKind = (typeof OUTREACH_ATTESTATION_KINDS)[number]\n\n/** The sentence a rep ticks for each attestation. */\nexport const OUTREACH_ATTESTATION_LABELS: Record<OutreachAttestationKind, string> = {\n us_business_address: 'This is a US business address',\n published_or_given:\n 'They or their company published this address, or they gave it to us',\n verified_deliverable: 'This address was verified as deliverable',\n}\n\n/** One confirmation, as stored. */\nexport interface OutreachAttestation {\n /** The member who confirmed it. */\n uid: string\n atMs: number\n}\n\n/** The confirmations an enrollment carries, by kind. */\nexport type OutreachAttestations = Partial<\n Record<OutreachAttestationKind, OutreachAttestation>\n>\n\n/** The longest personal line an enrollment keeps: one sentence, not a letter. */\nexport const OUTREACH_PERSONAL_LINE_MAX = 300\n\n/**\n * Which CRM record an enrollment names (AGL-3234). A person is a LEAD until\n * somebody qualifies them and a CONTACT after, and a sequence works either:\n * an enrollment made on a lead follows the lead to the contact it becomes,\n * so the thread and the steps carry on as one enrollment.\n */\nexport const OUTREACH_ENROLLMENT_TARGETS = ['contact', 'lead'] as const\nexport type OutreachEnrollmentTarget = (typeof OUTREACH_ENROLLMENT_TARGETS)[number]\n\n/** One person in one sequence (`orgs/{orgId}/outreachEnrollments/{id}`). */\nexport interface OutreachEnrollment extends OutreachTimestamps {\n id: string\n sequenceId: string\n /**\n * The record the person is (AGL-3234): `contact` for a CRM contact,\n * `lead` for a lead the sequence's site holds. A stored enrollment with\n * no target is a contact's — every enrollment was, before leads could be\n * sequenced.\n */\n target: OutreachEnrollmentTarget\n /**\n * The CRM contact the person is — `''` while the enrollment targets a\n * lead that has not converted. Filled in, beside `target: 'contact'`, the\n * moment the lead becomes a contact.\n */\n contactId: string\n /**\n * `hosts/{hostId}/leads/{leadId}` — the person key — for an enrollment\n * made on a lead; kept once the lead converts, so the lead's page still\n * lists the sequence. `null` for an enrollment made on a contact.\n */\n leadId: string | null\n /**\n * The person's name as the sending site knew it at enrollment, `''` when\n * it had none — what the enrollments table shows beside the address,\n * without a read of every record on the page (AGL-2980).\n */\n contactName: string\n /** The address the steps go to, normalized, captured at enrollment. */\n email: string\n hostId: string\n mailboxId: string\n /** The index into `steps` of the NEXT step to run. */\n stepIndex: number\n /** When that step comes due, or `null` when nothing is waiting. */\n nextDueAtMs: number | null\n status: OutreachEnrollmentStatus\n /** Why the status is not `active`; `null` while active and once finished. */\n stopReason: OutreachStopReason | null\n /** Plain-language detail: the gate's reason, the bounce's diagnostic. */\n stopDetail: string | null\n stoppedAtMs: number | null\n /** The member who paused or stopped it; `null` when the engine did. */\n stoppedByUid: string | null\n /**\n * The rep's signal sentence — why this person, now — merged into the\n * steps as `{{enrollment.personalLine}}`. Required for a cold contact.\n */\n personalLine: string\n /** Whether the contact was cold (no inbound capture) when enrolled. */\n cold: boolean\n attestations: OutreachAttestations\n /** The member who enrolled the person. */\n enrolledByUid: string\n /** The provider thread the next in-thread email is sent into, once one exists. */\n gmailThreadId: string | null\n /** Every provider thread this enrollment has sent into, oldest first — what reply sync watches. */\n gmailThreadIds: string[]\n /** The subject the current thread was started with, as sent. */\n threadSubject: string | null\n /**\n * The `Message-ID`s of the emails sent into the current thread, oldest\n * first, angle brackets included: the next in-thread email answers the\n * last and names them all in `References`.\n */\n messageIds: string[]\n /** When the last step ran. */\n lastSentAtMs: number | null\n /**\n * A sending run's hold on the step it is running (AGL-2981): taken in a\n * transaction before the step runs, cleared when it is recorded. Absent\n * or `null` while no run holds one.\n */\n sendClaim?: OutreachSendClaim | null\n /** Every step the runtime ran, oldest first (AGL-2981). */\n stepRecords?: OutreachStepRecord[]\n /** Gmail ids of this enrollment's thread messages the sync has handled, the last hundred. */\n syncedMessageIds?: string[]\n /**\n * What this person did with the links they were sent (AGL-3239). Absent\n * until their first click, which is why the table reads an absence as\n * \"no clicks\" only for a sequence that tracks them at all.\n */\n engagement?: OutreachEnrollmentEngagement\n /**\n * The sequence's campaigns as they stood when the person was enrolled\n * (AGL-3254): what every outcome of this enrollment is credited to. A\n * campaign the sequence joins later does not claim the people already\n * in it, and one it leaves keeps what it was credited with.\n */\n campaignIds?: string[]\n}\n\n/** A sending run's claim on one enrollment's step (AGL-2981). */\nexport interface OutreachSendClaim {\n /** The run that holds it. */\n token: string\n atMs: number\n stepIndex: number\n /**\n * The `Message-ID` an email step goes out with, minted before the send, so\n * a claim a run died holding is settled by looking for the message rather\n * than by sending it again. `null` for a task step.\n */\n messageId: string | null\n}\n\n/** One step the runtime ran for an enrollment (AGL-2981). */\nexport interface OutreachStepRecord {\n stepIndex: number\n stepId: string\n kind: 'email' | 'task'\n atMs: number\n /** Gmail's id for the sent message. */\n gmailMessageId?: string\n /** Gmail's thread the message went into. */\n gmailThreadId?: string\n /** The `Message-ID` it went out with, angle brackets included. */\n messageId?: string\n /** The subject as sent. */\n subject?: string\n /** The record system's task for a task step; `null` when none could be filed. */\n taskId?: string | null\n /**\n * The destinations this email's links were rewritten to point at, in the\n * order a click token indexes them (AGL-3239). Absent on a step that\n * carried no links, and on every step sent before tracking existed.\n *\n * Kept so the console can say WHICH link a person followed without the\n * token having to carry the URL back to us, and so a rewritten body can be\n * read afterwards for what it actually offered them.\n */\n links?: string[]\n}\n\n/*==========================================\n * ORGANIZATION SETTINGS (AGL-2979).\n *==========================================*/\n\n/**\n * What every Outreach email's footer says about who sent it — the\n * identification and the postal address CAN-SPAM requires on commercial\n * mail. The composer refuses to write an email without a legal name and a\n * postal address, and a sequence cannot be activated without them.\n */\nexport interface OutreachOrgSettings {\n /** The organization's legal name, as the footer prints it: \"Example Co LLC\". */\n legalName: string\n /**\n * The name the solicitation sentence uses when it is not the legal name:\n * \"This is a sales email from Example Co.\" `''` uses the legal\n * name.\n */\n brandName: string\n /**\n * A valid physical postal address: a street address, a USPS PO box, or a\n * private mailbox registered with the USPS. Line breaks are printed as\n * commas.\n */\n postalAddress: string\n}\n\n/** The id of the compliance document in the `settings` collection. */\nexport const OUTREACH_COMPLIANCE_SETTINGS_ID = 'compliance'\n\n/**\n * The organization's Outreach compliance settings\n * (`orgs/{orgId}/outreachSettings/compliance`): the footer's sender identity,\n * and the countries Outreach may send to at all.\n *\n * `allowedCountries` is a CEILING over every sequence's own list — a\n * sequence sends only to the countries both name — so narrowing it here\n * narrows every sequence at once, without editing any of them. Default\n * {@link OUTREACH_DEFAULT_ALLOWED_COUNTRIES}.\n */\nexport interface OutreachComplianceSettings extends OutreachOrgSettings {\n /** ISO-3166-1 alpha-2 codes, uppercase, in the order they were chosen. */\n allowedCountries: string[]\n}\n\n/** The compliance settings as stored, with who changed them last. */\nexport interface OutreachComplianceSettingsDocument\n extends OutreachComplianceSettings {\n /** `0` until the organization first saves them. */\n updatedAtMs: number\n updatedByUid: string | null\n}\n\n/*==========================================\n * DO NOT CONTACT (AGL-2980).\n *\n * The organization's own list of addresses Outreach never emails, whoever\n * enrolls them and from whichever site. A member adds one by hand; the\n * sending runtime adds one when a reply asks to be left alone, when the\n * unsubscribe link is used, and when an address bounces for good.\n *\n * AN ENTRY CARRIES NO ADDRESS. Its id is `outreachDoNotContactKey(email)` —\n * the same hash the platform's suppression lists key by — and that is all a\n * lookup needs, since every caller holds the address it is about to use.\n * So the list keeps working after a person is erased from the workspace,\n * which is exactly when a promise not to email them must still hold, while\n * holding nothing that identifies them.\n *==========================================*/\n\n/** Why an address is on the list. */\nexport const OUTREACH_DO_NOT_CONTACT_REASONS = [\n /** A member put it there. */\n 'manual',\n /** A reply asked not to be emailed again. */\n 'opt_out_reply',\n /** The unsubscribe link or header was used. */\n 'unsubscribe',\n /** Mail to it bounced for good. */\n 'hard_bounce',\n /**\n * The recipient organization's mail gateway refused the sender outright\n * (AGL-3244) — a Barracuda, Proofpoint or Mimecast policy block — which is\n * a verdict on the whole domain, and is filed against it.\n */\n 'gateway_block',\n] as const\nexport type OutreachDoNotContactReason =\n (typeof OUTREACH_DO_NOT_CONTACT_REASONS)[number]\n\n/** What put an address on the list: a member, or the sending runtime. */\nexport const OUTREACH_DO_NOT_CONTACT_SOURCES = ['member', 'runtime'] as const\nexport type OutreachDoNotContactSource =\n (typeof OUTREACH_DO_NOT_CONTACT_SOURCES)[number]\n\n/** One address on the list (`orgs/{orgId}/outreachDoNotContact/{key}`). */\nexport interface OutreachDoNotContactEntry {\n /** `outreachDoNotContactKey` of the address, which is also the document id. */\n key: string\n reason: OutreachDoNotContactReason\n source: OutreachDoNotContactSource\n /** The member who added it; `null` when the runtime did. */\n addedByUid: string | null\n addedAtMs: number\n /** The enrollment that led here, when one did. */\n enrollmentId: string | null\n /** That enrollment's sequence. */\n sequenceId: string | null\n /** Plain-language detail: why the member added it, the bounce's diagnostic. */\n detail: string | null\n}\n\n/**\n * One domain on the list (`orgs/{orgId}/outreachDoNotContactDomains/{domain}`)\n * (AGL-3244): no address at it is emailed, whoever enrolls them.\n *\n * Unlike an address entry it CARRIES THE DOMAIN, in clear, because the\n * Compliance page lists it and a member takes it off by name; a domain is a\n * company's, not a person's, and a person erasure leaves it alone. A member\n * adds one by hand; the sending runtime adds one when a hard bounce reads\n * as the domain's mail gateway refusing the sender rather than one address\n * being unknown.\n */\nexport interface OutreachDoNotContactDomainEntry {\n /** The domain, lower-cased, which is also the document id. */\n domain: string\n reason: OutreachDoNotContactReason\n source: OutreachDoNotContactSource\n /** The member who added it; `null` when the runtime did. */\n addedByUid: string | null\n addedAtMs: number\n /** The enrollment whose bounce led here, when one did. */\n enrollmentId: string | null\n /** That enrollment's sequence. */\n sequenceId: string | null\n /** Plain-language detail: the member's note, or the bounce's diagnostic. */\n detail: string | null\n}\n"],"names":["OUTREACH_COLLECTIONS","mailboxes","sequences","enrollments","settings","doNotContact","doNotContactDomains","mailboxCredentials","outreachOrgCollectionPath","orgId","collection","OUTREACH_MAILBOX_PROVIDERS","OUTREACH_MAILBOX_STATUSES","OUTREACH_SEQUENCE_STATUSES","OUTREACH_MAX_STEPS","OUTREACH_MAX_EMAIL_STEPS","OUTREACH_MAX_STEP_DELAY_BUSINESS_DAYS","OUTREACH_MIN_EMAIL_FOLLOW_UP_BUSINESS_DAYS","OUTREACH_TASK_KINDS","OUTREACH_TASK_KIND_LABELS","linkedin","call","todo","OUTREACH_DEFAULT_ALLOWED_COUNTRIES","OUTREACH_LINK_ROLLUP_PATH","OUTREACH_ENROLLMENT_STATUSES","OUTREACH_STOP_REASONS","OUTREACH_STOP_REASONS_BY_STATUS","paused","replied","bounced","opted_out","stopped","failed","OUTREACH_ATTESTATION_KINDS","OUTREACH_ATTESTATION_LABELS","us_business_address","published_or_given","verified_deliverable","OUTREACH_PERSONAL_LINE_MAX","OUTREACH_ENROLLMENT_TARGETS","OUTREACH_COMPLIANCE_SETTINGS_ID","OUTREACH_DO_NOT_CONTACT_REASONS","OUTREACH_DO_NOT_CONTACT_SOURCES"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;CAmBC,GAED;;;;;;;;;;;CAWC,GACD,OAAO,MAAMA,uBAAuB;IAClC,wEAAwE,GACxEC,WAAW;IACX,uEAAuE,GACvEC,WAAW;IACX,oFAAoF,GACpFC,aAAa;IACb;;;;GAIC,GACDC,UAAU;IACV;;;GAGC,GACDC,cAAc;IACd;;;;GAIC,GACDC,qBAAqB;IACrB;;;;GAIC,GACDC,oBAAo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ACA,gFAAgF,GAChF;CACD,CAAS;AAGV,8EAA8E,GAC9E,OAAO,MAAMC,kCAKT;IACFC,QAAQ;QAAC;KAAS;IAClBC,SAAS;QAAC;KAAQ;IAClBC,SAAS;QAAC;KAAc;IACxBC,WAAW;QAAC;QAAiB;QAAe;KAAiB;IAC7DC,SAAS;QAAC;QAAU;QAAQ;KAAoB;IAChDC,QAAQ;QAAC;KAAc;AACzB,EAAC;AAED;;;;;;;;;CASC,GACD,OAAO,MAAMC,6BAA6B;IACxC;IACA;IACA;CACD,CAAS;AAGV,mDAAmD,GACnD,OAAO,MAAMC,8BAAuE;IAClFC,qBAAqB;IACrBC,oBACE;IACFC,sBAAsB;AACxB,EAAC;AAcD,+EAA+E,GAC/E,OAAO,MAAMC,6BAA6B,IAAG;AAE7C;;;;;CAKC,GACD,OAAO,MAAMC,8BAA8B;IAAC;IAAW;CAAO,CAAS;AAsKvE,oEAAoE,GACpE,OAAO,MAAMC,kCAAkC,aAAY;AAyB3D;;;;;;;;;;;;;;4CAc4C,GAE5C,mCAAmC,GACnC,OAAO,MAAMC,kCAAkC;IAC7C,2BAA2B,GAC3B;IACA,2CAA2C,GAC3C;IACA,6CAA6C,GAC7C;IACA,iCAAiC,GACjC;IACA;;;;GAIC,GACD;CACD,CAAS;AAIV,uEAAuE,GACvE,OAAO,MAAMC,kCAAkC;IAAC;IAAU;CAAU,CAAS"}
|
|
@@ -210,6 +210,7 @@ export function createOutreachEnrollRoutes(deps) {
|
|
|
210
210
|
try {
|
|
211
211
|
await deps.creditCampaign({
|
|
212
212
|
hostId: sequence.hostId,
|
|
213
|
+
orgId,
|
|
213
214
|
campaignIds,
|
|
214
215
|
outcome: 'enrolled',
|
|
215
216
|
atMs: nowMs
|
|
@@ -220,14 +221,14 @@ export function createOutreachEnrollRoutes(deps) {
|
|
|
220
221
|
}
|
|
221
222
|
/**
|
|
222
223
|
* The names of the sequence's campaigns as they stand, for the entry the
|
|
223
|
-
* enroll files on the person's record (AGL-3274)
|
|
224
|
-
* not per person; a
|
|
225
|
-
* names the rest.
|
|
226
|
-
*/ async function sequenceCampaignNames(firestore, sequence) {
|
|
224
|
+
* enroll files on the person's record (AGL-3274) — the org's containers,
|
|
225
|
+
* `orgs/{orgId}/emailCampaigns`. Read once per request, not per person; a
|
|
226
|
+
* container that is gone answers nothing and the entry names the rest.
|
|
227
|
+
*/ async function sequenceCampaignNames(firestore, orgId, sequence) {
|
|
227
228
|
const campaignIds = normalizeCampaignIds(sequence.campaignIds);
|
|
228
|
-
if (!campaignIds.length) return [];
|
|
229
|
+
if (!campaignIds.length || !orgId) return [];
|
|
229
230
|
try {
|
|
230
|
-
const containers = firestore.collection('
|
|
231
|
+
const containers = firestore.collection('orgs').doc(orgId).collection('emailCampaigns');
|
|
231
232
|
const found = await firestore.getAll(...campaignIds.map((id)=>containers.doc(id)));
|
|
232
233
|
return found.map((snapshot)=>{
|
|
233
234
|
var _snapshot_get;
|
|
@@ -394,7 +395,7 @@ export function createOutreachEnrollRoutes(deps) {
|
|
|
394
395
|
...requested.values()
|
|
395
396
|
].map((entry)=>entry.ref));
|
|
396
397
|
const enrollments = outreachOrgCollection(firestore, caller.orgId, 'enrollments');
|
|
397
|
-
const campaignNames = await sequenceCampaignNames(firestore, sequence);
|
|
398
|
+
const campaignNames = await sequenceCampaignNames(firestore, caller.orgId, sequence);
|
|
398
399
|
const results = await Promise.all(candidates.map(async (candidate)=>{
|
|
399
400
|
var _requested_get, _lookups_get;
|
|
400
401
|
const named = {
|