@aglyn/plugins-email 1.0.0-beta.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +7 -0
  3. package/package.json +58 -0
  4. package/src/index.d.ts +35 -0
  5. package/src/index.js +35 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/components/campaign-design-create-widget.d.ts +21 -0
  8. package/src/lib/components/campaign-design-create-widget.js +61 -0
  9. package/src/lib/components/campaign-design-create-widget.js.map +1 -0
  10. package/src/lib/components/campaign-sender-editor-widget.d.ts +18 -0
  11. package/src/lib/components/campaign-sender-editor-widget.js +39 -0
  12. package/src/lib/components/campaign-sender-editor-widget.js.map +1 -0
  13. package/src/lib/components/campaign-topic-options-widget.d.ts +19 -0
  14. package/src/lib/components/campaign-topic-options-widget.js +48 -0
  15. package/src/lib/components/campaign-topic-options-widget.js.map +1 -0
  16. package/src/lib/components/campaign-topic-select.d.ts +32 -0
  17. package/src/lib/components/campaign-topic-select.js +87 -0
  18. package/src/lib/components/campaign-topic-select.js.map +1 -0
  19. package/src/lib/components/dynamic-list-rule-fields.d.ts +173 -0
  20. package/src/lib/components/dynamic-list-rule-fields.js +1473 -0
  21. package/src/lib/components/dynamic-list-rule-fields.js.map +1 -0
  22. package/src/lib/components/email-blocks.d.ts +111 -0
  23. package/src/lib/components/email-blocks.js +875 -0
  24. package/src/lib/components/email-blocks.js.map +1 -0
  25. package/src/lib/components/email-design-preview.d.ts +62 -0
  26. package/src/lib/components/email-design-preview.js +174 -0
  27. package/src/lib/components/email-design-preview.js.map +1 -0
  28. package/src/lib/components/email-screens-card.d.ts +42 -0
  29. package/src/lib/components/email-screens-card.js +277 -0
  30. package/src/lib/components/email-screens-card.js.map +1 -0
  31. package/src/lib/components/email-template-detail.d.ts +48 -0
  32. package/src/lib/components/email-template-detail.js +681 -0
  33. package/src/lib/components/email-template-detail.js.map +1 -0
  34. package/src/lib/components/email-topic-detail.d.ts +32 -0
  35. package/src/lib/components/email-topic-detail.js +293 -0
  36. package/src/lib/components/email-topic-detail.js.map +1 -0
  37. package/src/lib/components/email-topics-card.d.ts +46 -0
  38. package/src/lib/components/email-topics-card.js +327 -0
  39. package/src/lib/components/email-topics-card.js.map +1 -0
  40. package/src/lib/components/email-zones.d.ts +28 -0
  41. package/src/lib/components/email-zones.js +20 -0
  42. package/src/lib/components/email-zones.js.map +1 -0
  43. package/src/lib/components/emails-console-page.d.ts +32 -0
  44. package/src/lib/components/emails-console-page.js +229 -0
  45. package/src/lib/components/emails-console-page.js.map +1 -0
  46. package/src/lib/components/emails-console-sections.d.ts +36 -0
  47. package/src/lib/components/emails-console-sections.js +108 -0
  48. package/src/lib/components/emails-console-sections.js.map +1 -0
  49. package/src/lib/components/list-detail-card.d.ts +47 -0
  50. package/src/lib/components/list-detail-card.js +273 -0
  51. package/src/lib/components/list-detail-card.js.map +1 -0
  52. package/src/lib/components/list-edit-card.d.ts +11 -0
  53. package/src/lib/components/list-edit-card.js +287 -0
  54. package/src/lib/components/list-edit-card.js.map +1 -0
  55. package/src/lib/components/list-import-drawer.d.ts +22 -0
  56. package/src/lib/components/list-import-drawer.js +662 -0
  57. package/src/lib/components/list-import-drawer.js.map +1 -0
  58. package/src/lib/components/list-members-panel.d.ts +94 -0
  59. package/src/lib/components/list-members-panel.js +686 -0
  60. package/src/lib/components/list-members-panel.js.map +1 -0
  61. package/src/lib/components/lists-card.d.ts +28 -0
  62. package/src/lib/components/lists-card.js +377 -0
  63. package/src/lib/components/lists-card.js.map +1 -0
  64. package/src/lib/components/sending-domain-detail.d.ts +26 -0
  65. package/src/lib/components/sending-domain-detail.js +496 -0
  66. package/src/lib/components/sending-domain-detail.js.map +1 -0
  67. package/src/lib/components/sending-domains-card.d.ts +33 -0
  68. package/src/lib/components/sending-domains-card.js +962 -0
  69. package/src/lib/components/sending-domains-card.js.map +1 -0
  70. package/src/lib/components/sending-sender-drawer.d.ts +94 -0
  71. package/src/lib/components/sending-sender-drawer.js +543 -0
  72. package/src/lib/components/sending-sender-drawer.js.map +1 -0
  73. package/src/lib/components/suppressions-card.d.ts +49 -0
  74. package/src/lib/components/suppressions-card.js +639 -0
  75. package/src/lib/components/suppressions-card.js.map +1 -0
  76. package/src/lib/components/use-org-email-topics.d.ts +79 -0
  77. package/src/lib/components/use-org-email-topics.js +111 -0
  78. package/src/lib/components/use-org-email-topics.js.map +1 -0
  79. package/src/lib/constants/bundle-common.d.ts +18 -0
  80. package/src/lib/constants/bundle-common.js +18 -0
  81. package/src/lib/constants/bundle-common.js.map +1 -0
  82. package/src/lib/hooks/use-org-company-options.d.ts +20 -0
  83. package/src/lib/hooks/use-org-company-options.js +138 -0
  84. package/src/lib/hooks/use-org-company-options.js.map +1 -0
  85. package/src/lib/hooks/use-org-contact-fields.d.ts +40 -0
  86. package/src/lib/hooks/use-org-contact-fields.js +91 -0
  87. package/src/lib/hooks/use-org-contact-fields.js.map +1 -0
  88. package/src/lib/hooks/use-org-contact-segments.d.ts +16 -0
  89. package/src/lib/hooks/use-org-contact-segments.js +55 -0
  90. package/src/lib/hooks/use-org-contact-segments.js.map +1 -0
  91. package/src/lib/hooks/use-org-crm-views.d.ts +8 -0
  92. package/src/lib/hooks/use-org-crm-views.js +74 -0
  93. package/src/lib/hooks/use-org-crm-views.js.map +1 -0
  94. package/src/lib/hooks/use-org-lists.d.ts +8 -0
  95. package/src/lib/hooks/use-org-lists.js +47 -0
  96. package/src/lib/hooks/use-org-lists.js.map +1 -0
  97. package/src/lib/model/email-design-document.d.ts +52 -0
  98. package/src/lib/model/email-design-document.js +62 -0
  99. package/src/lib/model/email-design-document.js.map +1 -0
  100. package/src/lib/model/index.d.ts +64 -0
  101. package/src/lib/model/index.js +71 -0
  102. package/src/lib/model/index.js.map +1 -0
  103. package/src/lib/model/sending-domain-status.d.ts +99 -0
  104. package/src/lib/model/sending-domain-status.js +196 -0
  105. package/src/lib/model/sending-domain-status.js.map +1 -0
  106. package/src/lib/model/template-provenance.d.ts +113 -0
  107. package/src/lib/model/template-provenance.js +107 -0
  108. package/src/lib/model/template-provenance.js.map +1 -0
  109. package/src/lib/model/template-report.d.ts +158 -0
  110. package/src/lib/model/template-report.js +249 -0
  111. package/src/lib/model/template-report.js.map +1 -0
  112. package/src/lib/plugin.d.ts +27 -0
  113. package/src/lib/plugin.js +163 -0
  114. package/src/lib/plugin.js.map +1 -0
  115. package/src/lib/server-console.d.ts +116 -0
  116. package/src/lib/server-console.js +422 -0
  117. package/src/lib/server-console.js.map +1 -0
  118. package/src/lib/server-email-drafts.d.ts +104 -0
  119. package/src/lib/server-email-drafts.js +381 -0
  120. package/src/lib/server-email-drafts.js.map +1 -0
  121. package/src/lib/server-list-gate.d.ts +183 -0
  122. package/src/lib/server-list-gate.js +365 -0
  123. package/src/lib/server-list-gate.js.map +1 -0
  124. package/src/lib/server-list-import.d.ts +199 -0
  125. package/src/lib/server-list-import.js +632 -0
  126. package/src/lib/server-list-import.js.map +1 -0
  127. package/src/lib/server-suppressions.d.ts +135 -0
  128. package/src/lib/server-suppressions.js +295 -0
  129. package/src/lib/server-suppressions.js.map +1 -0
  130. package/src/lib/server.d.ts +19 -0
  131. package/src/lib/server.js +834 -0
  132. package/src/lib/server.js.map +1 -0
  133. package/src/lib/site.d.ts +26 -0
  134. package/src/lib/site.js +81 -0
  135. package/src/lib/site.js.map +1 -0
  136. package/src/lib/unsubscribe-link.d.ts +311 -0
  137. package/src/lib/unsubscribe-link.js +398 -0
  138. package/src/lib/unsubscribe-link.js.map +1 -0
  139. package/src/lib/utils/create-email-screen.d.ts +59 -0
  140. package/src/lib/utils/create-email-screen.js +59 -0
  141. package/src/lib/utils/create-email-screen.js.map +1 -0
  142. package/src/lib/utils/generate-preset-id.d.ts +19 -0
  143. package/src/lib/utils/generate-preset-id.js +25 -0
  144. package/src/lib/utils/generate-preset-id.js.map +1 -0
@@ -0,0 +1,543 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ 'use client';
17
+ import { _ as _extends } from "@swc/helpers/_/_extends";
18
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
19
+ import { hostRoleFor, HOST_ACCESS_ROLES, pluginDocsHelp } from "@aglyn/aglyn";
20
+ import { ICON_VARIANT_CLOSE } from "@aglyn/shared-data-enums";
21
+ import { Container, HelpTip, MdiIcon, SrOnly } from "@aglyn/shared-ui-jsx";
22
+ import { NavigationDrawerComponent } from "@aglyn/shared-ui-jsx/components/navigation-drawer.component";
23
+ import { normalizeLocalPart, validateSendingLocalPart } from "@aglyn/shared-util-email";
24
+ import { useFirestore, useFirestoreCollection } from "@aglyn/tenant-feature-instance";
25
+ import { Alert, Button, Divider, IconButton, InputAdornment, MenuItem, Stack, TextField, Typography } from "@mui/material";
26
+ import { collection, limit, query, where } from "firebase/firestore";
27
+ import { useCallback, useEffect, useMemo, useState } from "react";
28
+ import { useSendingApi } from "@aglyn/tenant-feature-instance/hooks/use-sending-identity-api";
29
+ /**
30
+ * How many people each of the roster reads may return.
31
+ *
32
+ * A ceiling rather than a page, because this control is a shortcut and not a
33
+ * roster: somebody choosing a sender knows who they are looking for, and a
34
+ * site large enough to overflow this has an admin who can type the three
35
+ * fields directly. Bounded because the read happens on a merchant's settings
36
+ * screen, and an unbounded one would grow with the site for no benefit.
37
+ *
38
+ * 250 is the largest per-site collaborator allowance any finite plan grants
39
+ * (`membersPerHost`), so on every plan below Enterprise the whole entitled
40
+ * set fits and nothing is cut. Where it does bite it cuts in document-id
41
+ * order, which is a stable slice and not a ranked one — the queries below are
42
+ * already narrowed to people who can reach this site, so what is dropped is a
43
+ * tail of an entitled roster rather than an arbitrary sample of a workspace.
44
+ */ const SENDER_PICKER_CEILING = 250;
45
+ /**
46
+ * ONE SENDER THIS SITE MAY SEND AS.
47
+ *
48
+ * Three fields, and they are not three of a kind. The MAILBOX is the part of
49
+ * the address in front of the `@`; the domain behind it is whatever this
50
+ * site's verified identity resolves to and is not editable here, because
51
+ * DMARC on the sending apex is published `adkim=s` and the `From:` domain has
52
+ * to be exactly the domain whose DKIM key signed the message. The NAME is
53
+ * what a recipient reads in their inbox list. The REPLY ADDRESS is the only
54
+ * one of the three that may name a mailbox on a domain nobody here has
55
+ * verified — which is what makes "replies reach me personally" possible
56
+ * without pretending the mail came from a personal account.
57
+ *
58
+ * ## Why a site holds a LIST, and why the composer picks from it
59
+ *
60
+ * The composer already carries a from name and a reply-to per campaign, and
61
+ * keeps them: those are per-message facts. The mailbox is not, because it is
62
+ * an address that has to work — a bounce returns to it, and a mail client
63
+ * that ignores `Reply-To:` answers to it. A mailbox that exists in one
64
+ * campaign's headers and nowhere else is an address nobody serves.
65
+ *
66
+ * So a mailbox is configured HERE, once, and a campaign chooses among the
67
+ * senders that were configured. A per-send address field would be the thing
68
+ * that closure removed; a per-send choice between approved senders is not.
69
+ *
70
+ * The gates differ for the same reason. Deciding which addresses this site's
71
+ * mail may leave on is an organization-admin decision and lives here beside
72
+ * the domain it depends on; the composer is admin-or-editor and may pick
73
+ * among them and name the person in front of the address.
74
+ *
75
+ * ## The picker
76
+ *
77
+ * "Send as a person" is mostly one action — take a teammate's name and their
78
+ * mailbox and make the mail read as theirs — so the picker does all three
79
+ * fields at once and then lets any of them be edited. The address it proposes
80
+ * is derived from the part of their email in front of the `@`, which is the
81
+ * name they already answer to, and their real address becomes the reply
82
+ * target rather than the sender: a `From:` on their own mail provider's
83
+ * domain could never align, and would be rejected rather than delivered.
84
+ *
85
+ * Opened to ADD, it fills a new sender and leaves the ones this site already
86
+ * has alone — which is what makes "send as Jamie" an address beside the
87
+ * others rather than a rename of the only one.
88
+ *
89
+ * ## Who is on the list
90
+ *
91
+ * Everybody who can reach this site, from wherever their access comes from:
92
+ * the organization's team, whose members reach a site through an org role or
93
+ * an `allHosts` flag or a per-site grant, and the site's own collaborators,
94
+ * who are on it and nowhere else. Both, because either alone is a picker that
95
+ * is missing people — and a workspace that manages its team entirely at the
96
+ * org level has an empty site roster, so reading only that one offered no
97
+ * teammates at all.
98
+ *
99
+ * Nobody else. An org member scoped to other sites is not a candidate sender
100
+ * for this one: the address would work, and the person would be signing mail
101
+ * for a site they cannot open. `hostRoleFor` draws that line, and it is the
102
+ * same one the rules and every server gate draw.
103
+ *
104
+ * The roster is read only while this drawer is open. It is four collection
105
+ * reads on a settings surface, and ones that happen because somebody asked for
106
+ * them are a different thing from ones that happen because a card mounted.
107
+ */ export function SendingSenderDrawer(props) {
108
+ var _find, _ref, _ref1, _ref2;
109
+ const { open, hostId, view, senderId, onClose, onSaved } = props;
110
+ const call = useSendingApi();
111
+ const firestore = useFirestore();
112
+ const [mailbox, setMailbox] = useState('');
113
+ const [fromName, setFromName] = useState('');
114
+ const [replyTo, setReplyTo] = useState('');
115
+ const [busy, setBusy] = useState(false);
116
+ const [error, setError] = useState('');
117
+ /**
118
+ * The row being edited, or null while adding one.
119
+ *
120
+ * Resolved from the view the card already holds rather than read again here:
121
+ * the list and the editor open from one answer, so they cannot disagree
122
+ * about what a sender currently is.
123
+ */ const editing = senderId ? (_find = ((_ref = view == null ? void 0 : view.senders) != null ? _ref : []).find((sender)=>sender.id === senderId)) != null ? _find : null : null;
124
+ /*
125
+ * The stored values are copied in when the drawer OPENS, not on every
126
+ * render of the card.
127
+ *
128
+ * A settings form seeded from a prop that keeps arriving would discard what
129
+ * somebody was halfway through typing the moment the card re-read the
130
+ * identity behind them — so the dependencies are the row's FIELDS and not
131
+ * the array they came in, which is a new array on every read.
132
+ */ useEffect(()=>{
133
+ var _ref, _ref1, _ref2;
134
+ if (!open) return;
135
+ setMailbox((_ref = editing == null ? void 0 : editing.localPart) != null ? _ref : '');
136
+ setFromName((_ref1 = editing == null ? void 0 : editing.fromName) != null ? _ref1 : '');
137
+ setReplyTo((_ref2 = editing == null ? void 0 : editing.replyTo) != null ? _ref2 : '');
138
+ setError('');
139
+ }, [
140
+ open,
141
+ senderId,
142
+ editing == null ? void 0 : editing.localPart,
143
+ editing == null ? void 0 : editing.fromName,
144
+ editing == null ? void 0 : editing.replyTo
145
+ ]);
146
+ /*
147
+ * The org this site belongs to, as the identity route resolved it.
148
+ *
149
+ * Taken from the view rather than read again here, so the drawer and the
150
+ * card it opens from agree about which workspace they are looking at, and
151
+ * so the org reads below cannot start before the route has answered.
152
+ */ const orgId = String((_ref1 = view == null ? void 0 : view.orgId) != null ? _ref1 : '');
153
+ const reading = open && Boolean(hostId);
154
+ /*
155
+ * THE SITE'S OWN COLLABORATOR ROSTER — `hosts/{hostId}/members`.
156
+ *
157
+ * Not the whole answer, and reading it alone was the defect: this
158
+ * subcollection holds only people added TO ONE SITE by
159
+ * `POST /api/hosts/members`. A workspace whose team reaches every site
160
+ * through their org membership has no rows here at all, so a picker built
161
+ * on it offered whichever one address happened to have been added this way
162
+ * and no teammates whatsoever.
163
+ *
164
+ * It stays because it is the only source for one population: somebody
165
+ * invited to the site by an address with no Aglyn account behind it yet has
166
+ * a roster row and, until they accept, no org member document. They are a
167
+ * real person with a real mailbox who has been granted access, which is all
168
+ * a reply address needs.
169
+ *
170
+ * Ordered by nothing, and capped: see {@link SENDER_PICKER_CEILING}. This
171
+ * subcollection has exactly one writer and it writes `email` on every
172
+ * document, so an `orderBy('email')` would be safe here — it buys nothing,
173
+ * because the merged set below is arranged for display after the fact and a
174
+ * server order over one of four reads cannot survive the merge.
175
+ */ const { data: siteMemberDocs } = useFirestoreCollection(()=>reading ? query(collection(firestore, 'hosts', hostId, 'members'), limit(SENDER_PICKER_CEILING)) : null, [
176
+ firestore,
177
+ hostId,
178
+ reading
179
+ ], {
180
+ idField: '$id'
181
+ });
182
+ /*
183
+ * THE ORG'S TEAM — `orgs/{orgId}/members`, in the three shapes that reach
184
+ * one host.
185
+ *
186
+ * `hostRoleFor` is the predicate the rules, the ~20 server gates and
187
+ * `useHostRole` all resolve a member's access to a site with, and it is a
188
+ * disjunction of exactly three cases: an owner or admin spans every site; an
189
+ * editor or viewer with `allHosts` spans every site at their org role; and
190
+ * anybody may carry an explicit per-site grant in `hostAccess`. Firestore
191
+ * cannot express that as one query, so it is asked as three and merged.
192
+ *
193
+ * ## Three narrow reads rather than one broad one
194
+ *
195
+ * The alternative — read the roster and filter in the browser — reads every
196
+ * member of the workspace to find the few who work on this site, and the cap
197
+ * would then apply BEFORE the filter: in an org of 400 where five people
198
+ * have this site, the picker could contain none of them. Splitting the
199
+ * predicate across the wire means the cap only ever cuts a tail of people
200
+ * who all belong in the list.
201
+ *
202
+ * ## The `orderBy` trap, and why there is no `orderBy` here
203
+ *
204
+ * `orderBy` matches only documents that HAVE the field, so ordering on one
205
+ * some writer omits hides rows instead of arranging them. `email` is NOT
206
+ * safe to order on in this collection: `AglynOrgMember` declares it
207
+ * optional, and two production paths create a member document without it —
208
+ * `PATCH /api/hosts/members` re-grants host access with no identity fields,
209
+ * and `POST /api/orgs/members` omits it entirely when the auth record
210
+ * carries no email. Ordering on it would drop exactly the teammates this
211
+ * change exists to surface, silently.
212
+ *
213
+ * Each `where` below is safe in a way an `orderBy` is not, and for the same
214
+ * reason it looks unsafe: a document missing `role`, missing `allHosts` or
215
+ * missing `hostAccess` is dropped by the filter — and `hostRoleFor` resolves
216
+ * every one of those to "no access" anyway. The predicate and the index
217
+ * agree about what absence means, so the query cannot hide anybody the
218
+ * filter would have kept.
219
+ */ const orgMembers = (constrain)=>()=>reading && orgId ? constrain(collection(firestore, 'orgs', orgId, 'members')) : null;
220
+ const { data: orgAdminDocs } = useFirestoreCollection(orgMembers((base)=>query(base, where('role', 'in', [
221
+ 'owner',
222
+ 'admin'
223
+ ]), limit(SENDER_PICKER_CEILING))), [
224
+ firestore,
225
+ orgId,
226
+ reading
227
+ ], {
228
+ idField: '$id'
229
+ });
230
+ const { data: orgWideDocs } = useFirestoreCollection(orgMembers((base)=>query(base, where('allHosts', '==', true), limit(SENDER_PICKER_CEILING))), [
231
+ firestore,
232
+ orgId,
233
+ reading
234
+ ], {
235
+ idField: '$id'
236
+ });
237
+ /*
238
+ * `HOST_ACCESS_ROLES` rather than a written-out array, for the reason it
239
+ * exists: a role added to `HostAccessRole` and missing from an `in` list is
240
+ * a person who holds access and cannot be seen to, with no error to explain
241
+ * it. The constant is built from a `Record` so a new role fails to compile
242
+ * there instead of quietly shortening this query.
243
+ */ const { data: orgScopedDocs } = useFirestoreCollection(orgMembers((base)=>query(base, where(`hostAccess.${hostId}`, 'in', HOST_ACCESS_ROLES), limit(SENDER_PICKER_CEILING))), [
244
+ firestore,
245
+ orgId,
246
+ hostId,
247
+ reading
248
+ ], {
249
+ idField: '$id'
250
+ });
251
+ const candidates = useMemo(()=>{
252
+ /*
253
+ * ONE ROW PER PERSON, keyed by uid.
254
+ *
255
+ * The same teammate legitimately appears in several of these reads — an
256
+ * org admin who is also an explicit collaborator is in two, and an org
257
+ * member who accepted a site invite has a roster row as well — so the
258
+ * merge is by identity rather than by document. The org member document
259
+ * and the site roster row are keyed by the same uid, which is what makes
260
+ * that possible: `POST /api/hosts/members` names the roster document after
261
+ * the auth uid whenever an account exists, and falls back to a generated
262
+ * id only for an address that has none. Such a row has no org document to
263
+ * collide with, so the fallback cannot merge two people into one.
264
+ *
265
+ * Fields are taken from the first read that has them rather than from a
266
+ * chosen winner. Neither source is complete on its own: the site roster
267
+ * always carries an `email` and never a `displayName`, and an org member
268
+ * document usually carries both but is allowed to omit either.
269
+ */ const byPerson = new Map();
270
+ const fold = (id, entry)=>{
271
+ var _byPerson_get, _ref, _ref1;
272
+ if (!id) return;
273
+ const current = (_byPerson_get = byPerson.get(id)) != null ? _byPerson_get : {
274
+ id,
275
+ email: '',
276
+ displayName: ''
277
+ };
278
+ byPerson.set(id, {
279
+ id,
280
+ email: current.email || String((_ref = entry == null ? void 0 : entry.email) != null ? _ref : '').trim(),
281
+ displayName: current.displayName || String((_ref1 = entry == null ? void 0 : entry.displayName) != null ? _ref1 : '').trim()
282
+ });
283
+ };
284
+ /*
285
+ * THE PREDICATE IS APPLIED AGAIN HERE, over the documents themselves.
286
+ *
287
+ * The three queries are the predicate projected onto an index, and an
288
+ * index answers a coarser question than the function does — `allHosts`
289
+ * reaches every site only for a member who HAS an org role, and a document
290
+ * carrying the flag with no role is a member of nothing. `hostRoleFor` is
291
+ * the one definition of "can this person reach this site", so it decides,
292
+ * and the queries are only what keeps the reads narrow.
293
+ */ for (const entry of [
294
+ ...orgAdminDocs != null ? orgAdminDocs : [],
295
+ ...orgWideDocs != null ? orgWideDocs : [],
296
+ ...orgScopedDocs != null ? orgScopedDocs : []
297
+ ]){
298
+ var _ref;
299
+ if (!hostRoleFor(entry, hostId)) continue;
300
+ fold(String((_ref = entry == null ? void 0 : entry.$id) != null ? _ref : ''), entry);
301
+ }
302
+ /*
303
+ * The site's roster rows carry no role of their own to resolve — being in
304
+ * this subcollection IS access to this site, which is what the Users card
305
+ * on the site's own settings page renders it as. `uid` before `$id` so an
306
+ * accepted collaborator merges onto their org member document rather than
307
+ * arriving as a second row for the same person.
308
+ */ for (const entry of siteMemberDocs != null ? siteMemberDocs : []){
309
+ fold(String((entry == null ? void 0 : entry.uid) || (entry == null ? void 0 : entry.$id) || ''), entry);
310
+ }
311
+ return [
312
+ ...byPerson.values()
313
+ ]/*
314
+ * An address is not optional. It is what the mailbox is derived from
315
+ * and what replies are pointed at, so a person recorded without one
316
+ * has nothing this picker could fill in.
317
+ */ .filter((entry)=>entry.email)/*
318
+ * Sorted here rather than by the server, because this is a COMPLETE
319
+ * set and not a page: four reads have been merged, so no server order
320
+ * survives, and arranging a page in the browser is what makes an
321
+ * arbitrary slice read as a ranked one. By the name a person is
322
+ * looking for, falling back to the address for somebody who has none.
323
+ */ .sort((left, right)=>(left.displayName || left.email).localeCompare(right.displayName || right.email, undefined, {
324
+ sensitivity: 'base'
325
+ }));
326
+ }, [
327
+ orgAdminDocs,
328
+ orgWideDocs,
329
+ orgScopedDocs,
330
+ siteMemberDocs,
331
+ hostId
332
+ ]);
333
+ /*
334
+ * The domain half, shown as a fixed suffix rather than as a field.
335
+ *
336
+ * A person setting a sender is choosing an address, and an address with its
337
+ * domain missing from the screen is one they have to assemble in their head
338
+ * from the alert above. Read from the identity the server resolved, so it
339
+ * is the domain a send would actually use.
340
+ */ const domain = String((_ref2 = view == null ? void 0 : view.selected) != null ? _ref2 : '');
341
+ const pooled = Boolean(view) && !(view == null ? void 0 : view.localPartInUse);
342
+ const handleSave = useCallback(async ()=>{
343
+ var _ref;
344
+ if (busy) return;
345
+ /*
346
+ * A POOLED SITE SENDS NO MAILBOX AT ALL, rather than sending one the
347
+ * route will refuse.
348
+ *
349
+ * The field is disabled above and the alert says why, and this is the
350
+ * half that matters: a merchant on the shared address editing their
351
+ * sender name would otherwise have the whole save rejected over a field
352
+ * they were never offered.
353
+ */ const checked = pooled ? null : validateSendingLocalPart(mailbox);
354
+ if (checked == null ? void 0 : checked.error) return setError(checked.error);
355
+ setError('');
356
+ setBusy(true);
357
+ const { response, payload } = await call({
358
+ path: 'sending-identity',
359
+ method: 'POST',
360
+ /*
361
+ * No `domain` key. Absent means "this is not a decision about the
362
+ * domain" — an empty one would mean "move this site back to the address
363
+ * Aglyn issues it", which would reset a site sending as its own
364
+ * verified name every time somebody edited the sender.
365
+ */ body: _extends({
366
+ hostId,
367
+ action: senderId ? 'updateSender' : 'createSender'
368
+ }, senderId ? {
369
+ senderId
370
+ } : {}, (checked == null ? void 0 : checked.localPart) ? {
371
+ localPart: checked.localPart
372
+ } : {}, {
373
+ fromName: fromName.trim(),
374
+ replyTo: replyTo.trim()
375
+ })
376
+ });
377
+ setBusy(false);
378
+ if (!response.ok) {
379
+ var _ref1;
380
+ return setError((_ref1 = payload == null ? void 0 : payload.error) != null ? _ref1 : 'Could not save who this site sends as');
381
+ }
382
+ onSaved(String((_ref = payload == null ? void 0 : payload.senderId) != null ? _ref : '') || undefined);
383
+ onClose();
384
+ }, [
385
+ busy,
386
+ call,
387
+ hostId,
388
+ senderId,
389
+ mailbox,
390
+ pooled,
391
+ fromName,
392
+ replyTo,
393
+ onSaved,
394
+ onClose
395
+ ]);
396
+ const applyCandidate = useCallback((candidate)=>{
397
+ const at = candidate.email.lastIndexOf('@');
398
+ const proposed = normalizeLocalPart(at > 0 ? candidate.email.slice(0, at) : '');
399
+ if (proposed) setMailbox(proposed);
400
+ if (candidate.displayName) setFromName(candidate.displayName);
401
+ setReplyTo(candidate.email);
402
+ setError('');
403
+ }, []);
404
+ return /*#__PURE__*/ _jsx(NavigationDrawerComponent, {
405
+ open: open,
406
+ anchor: "right",
407
+ variant: "temporary",
408
+ onClose: onClose,
409
+ AppBarProps: {
410
+ color: 'surface'
411
+ },
412
+ appBarLeft: /*#__PURE__*/ _jsxs(_Fragment, {
413
+ children: [
414
+ /*#__PURE__*/ _jsxs(IconButton, {
415
+ color: "inherit",
416
+ edge: "start",
417
+ onClick: onClose,
418
+ sx: {
419
+ mr: 2
420
+ },
421
+ children: [
422
+ /*#__PURE__*/ _jsx(MdiIcon, {
423
+ path: ICON_VARIANT_CLOSE.path
424
+ }),
425
+ /*#__PURE__*/ _jsx(SrOnly, {
426
+ children: "close drawer"
427
+ })
428
+ ]
429
+ }),
430
+ /*#__PURE__*/ _jsx(Typography, {
431
+ variant: "h6",
432
+ component: "div",
433
+ children: senderId ? 'Edit this sender' : 'Add a sender'
434
+ }),
435
+ /*#__PURE__*/ _jsx(HelpTip, _extends({}, pluginDocsHelp('emailCampaigns', {
436
+ anchor: '#senders',
437
+ title: 'Senders',
438
+ excerpt: 'A mailbox this site may send as, with the name and reply ' + 'address that go out in front of it. A campaign picks one of ' + 'them rather than typing an address.'
439
+ })))
440
+ ]
441
+ }),
442
+ children: /*#__PURE__*/ _jsx(Container, {
443
+ gutterY: true,
444
+ children: /*#__PURE__*/ _jsxs(Stack, {
445
+ spacing: 2,
446
+ children: [
447
+ /*#__PURE__*/ _jsx(Typography, {
448
+ variant: "body2",
449
+ color: "text.secondary",
450
+ children: 'An address your email may leave on, and the name in front of ' + 'it. The domain is your site’s verified sending domain and ' + 'cannot be changed here — the part before the @ can. To have ' + 'replies reach a personal or company mailbox, use the reply ' + 'address: sending as an address on somebody else’s mail ' + 'provider is refused by the receiving side, not delivered.'
451
+ }),
452
+ /*#__PURE__*/ _jsx(Typography, {
453
+ variant: "body2",
454
+ color: "text.secondary",
455
+ children: (editing == null ? void 0 : editing.isDefault) ? 'Every email you compose picks a sender. This is the one an ' + 'email that names no other goes out as.' : 'Every email you compose picks a sender, and this will be ' + 'one of the choices.'
456
+ }),
457
+ candidates.length ? /*#__PURE__*/ _jsxs(_Fragment, {
458
+ children: [
459
+ /*#__PURE__*/ _jsx(TextField, {
460
+ select: true,
461
+ label: "Send as a person",
462
+ value: "",
463
+ size: "small",
464
+ onChange: (event)=>{
465
+ const match = candidates.find((entry)=>entry.id === event.target.value);
466
+ if (match) applyCandidate(match);
467
+ },
468
+ helperText: "Fills the three fields below from someone who works on this site",
469
+ children: candidates.map((candidate)=>/*#__PURE__*/ _jsx(MenuItem, {
470
+ value: candidate.id,
471
+ children: /*#__PURE__*/ _jsxs(Stack, {
472
+ spacing: 0,
473
+ children: [
474
+ candidate.displayName ? /*#__PURE__*/ _jsx(Typography, {
475
+ variant: "body2",
476
+ children: candidate.displayName
477
+ }) : null,
478
+ /*#__PURE__*/ _jsx(Typography, {
479
+ variant: candidate.displayName ? 'caption' : 'body2',
480
+ color: candidate.displayName ? 'text.secondary' : undefined,
481
+ children: candidate.email
482
+ })
483
+ ]
484
+ })
485
+ }, candidate.id))
486
+ }),
487
+ /*#__PURE__*/ _jsx(Divider, {})
488
+ ]
489
+ }) : null,
490
+ pooled ? /*#__PURE__*/ _jsx(Alert, {
491
+ severity: "info",
492
+ children: 'This site sends on a shared Aglyn address, whose mailbox is ' + 'fixed and shared with the other sites on it. The name and ' + 'reply address below apply to that mail; the mailbox takes ' + 'effect once this site has a domain of its own.'
493
+ }) : null,
494
+ /*#__PURE__*/ _jsx(TextField, {
495
+ label: "Mailbox",
496
+ value: mailbox,
497
+ onChange: (event)=>setMailbox(event.target.value),
498
+ size: "small",
499
+ disabled: pooled,
500
+ slotProps: {
501
+ input: domain ? {
502
+ endAdornment: /*#__PURE__*/ _jsx(InputAdornment, {
503
+ position: "end",
504
+ children: `@${domain}`
505
+ })
506
+ } : undefined
507
+ },
508
+ helperText: 'The part before the @ — for example hello, sales or jamie'
509
+ }),
510
+ /*#__PURE__*/ _jsx(TextField, {
511
+ label: "Sender name",
512
+ value: fromName,
513
+ onChange: (event)=>setFromName(event.target.value),
514
+ size: "small",
515
+ helperText: "Shown in front of the address. A person’s name, or your brand"
516
+ }),
517
+ /*#__PURE__*/ _jsx(TextField, {
518
+ label: "Reply address",
519
+ value: replyTo,
520
+ onChange: (event)=>setReplyTo(event.target.value),
521
+ size: "small",
522
+ type: "email",
523
+ helperText: "Where replies go. May be any mailbox, including a personal one"
524
+ }),
525
+ error ? /*#__PURE__*/ _jsx(Alert, {
526
+ severity: "error",
527
+ children: error
528
+ }) : null,
529
+ /*#__PURE__*/ _jsx(Button, {
530
+ variant: "contained",
531
+ disabled: busy || !view,
532
+ onClick: ()=>void handleSave(),
533
+ children: busy ? 'Saving…' : senderId ? 'Save sender' : 'Add sender'
534
+ })
535
+ ]
536
+ })
537
+ })
538
+ });
539
+ }
540
+ SendingSenderDrawer.displayName = 'SendingSenderDrawer';
541
+ export default SendingSenderDrawer;
542
+
543
+ //# sourceMappingURL=sending-sender-drawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/email/src/lib/components/sending-sender-drawer.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 { hostRoleFor, HOST_ACCESS_ROLES, pluginDocsHelp } from '@aglyn/aglyn'\nimport { ICON_VARIANT_CLOSE } from '@aglyn/shared-data-enums'\nimport { Container, HelpTip, MdiIcon, SrOnly } from '@aglyn/shared-ui-jsx'\nimport { NavigationDrawerComponent } from '@aglyn/shared-ui-jsx/components/navigation-drawer.component'\nimport {\n normalizeLocalPart,\n validateSendingLocalPart,\n} from '@aglyn/shared-util-email'\nimport {\n useFirestore,\n useFirestoreCollection,\n} from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Button,\n Divider,\n IconButton,\n InputAdornment,\n MenuItem,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { collection, limit, query, where } from 'firebase/firestore'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n useSendingApi,\n type SendingIdentityView,\n} from '@aglyn/tenant-feature-instance/hooks/use-sending-identity-api'\n\n/**\n * How many people each of the roster reads may return.\n *\n * A ceiling rather than a page, because this control is a shortcut and not a\n * roster: somebody choosing a sender knows who they are looking for, and a\n * site large enough to overflow this has an admin who can type the three\n * fields directly. Bounded because the read happens on a merchant's settings\n * screen, and an unbounded one would grow with the site for no benefit.\n *\n * 250 is the largest per-site collaborator allowance any finite plan grants\n * (`membersPerHost`), so on every plan below Enterprise the whole entitled\n * set fits and nothing is cut. Where it does bite it cuts in document-id\n * order, which is a stable slice and not a ranked one — the queries below are\n * already narrowed to people who can reach this site, so what is dropped is a\n * tail of an entitled roster rather than an arbitrary sample of a workspace.\n */\nconst SENDER_PICKER_CEILING = 250\n\nexport interface SendingSenderDrawerProps {\n open: boolean\n hostId: string\n /** The identity as the route reports it. Null while the card is loading. */\n view: SendingIdentityView | null\n /**\n * WHICH SENDER THIS DRAWER IS EDITING, or `null` to add one.\n *\n * The two modes differ in what the fields start as and in nothing else: an\n * edit opens on the row's stored values, and an add opens empty so the\n * picker below fills a NEW sender rather than overwriting the one this site\n * already has.\n */\n senderId?: string | null\n onClose: () => void\n /**\n * Called after a successful save, so the caller can re-read the identity.\n *\n * Carries the id the route answered with, which is what a caller that has to\n * SELECT the new sender needs — the composer opens this drawer from its From\n * picker, and the row it must then choose does not exist in any list it\n * holds until it re-reads. A caller that only refreshes ignores it.\n */\n onSaved: (senderId?: string) => void\n}\n\n/** One row of the picker, reduced to what a sender needs from a person. */\ninterface SenderCandidate {\n id: string\n email: string\n displayName: string\n}\n\n/**\n * ONE SENDER THIS SITE MAY SEND AS.\n *\n * Three fields, and they are not three of a kind. The MAILBOX is the part of\n * the address in front of the `@`; the domain behind it is whatever this\n * site's verified identity resolves to and is not editable here, because\n * DMARC on the sending apex is published `adkim=s` and the `From:` domain has\n * to be exactly the domain whose DKIM key signed the message. The NAME is\n * what a recipient reads in their inbox list. The REPLY ADDRESS is the only\n * one of the three that may name a mailbox on a domain nobody here has\n * verified — which is what makes \"replies reach me personally\" possible\n * without pretending the mail came from a personal account.\n *\n * ## Why a site holds a LIST, and why the composer picks from it\n *\n * The composer already carries a from name and a reply-to per campaign, and\n * keeps them: those are per-message facts. The mailbox is not, because it is\n * an address that has to work — a bounce returns to it, and a mail client\n * that ignores `Reply-To:` answers to it. A mailbox that exists in one\n * campaign's headers and nowhere else is an address nobody serves.\n *\n * So a mailbox is configured HERE, once, and a campaign chooses among the\n * senders that were configured. A per-send address field would be the thing\n * that closure removed; a per-send choice between approved senders is not.\n *\n * The gates differ for the same reason. Deciding which addresses this site's\n * mail may leave on is an organization-admin decision and lives here beside\n * the domain it depends on; the composer is admin-or-editor and may pick\n * among them and name the person in front of the address.\n *\n * ## The picker\n *\n * \"Send as a person\" is mostly one action — take a teammate's name and their\n * mailbox and make the mail read as theirs — so the picker does all three\n * fields at once and then lets any of them be edited. The address it proposes\n * is derived from the part of their email in front of the `@`, which is the\n * name they already answer to, and their real address becomes the reply\n * target rather than the sender: a `From:` on their own mail provider's\n * domain could never align, and would be rejected rather than delivered.\n *\n * Opened to ADD, it fills a new sender and leaves the ones this site already\n * has alone — which is what makes \"send as Jamie\" an address beside the\n * others rather than a rename of the only one.\n *\n * ## Who is on the list\n *\n * Everybody who can reach this site, from wherever their access comes from:\n * the organization's team, whose members reach a site through an org role or\n * an `allHosts` flag or a per-site grant, and the site's own collaborators,\n * who are on it and nowhere else. Both, because either alone is a picker that\n * is missing people — and a workspace that manages its team entirely at the\n * org level has an empty site roster, so reading only that one offered no\n * teammates at all.\n *\n * Nobody else. An org member scoped to other sites is not a candidate sender\n * for this one: the address would work, and the person would be signing mail\n * for a site they cannot open. `hostRoleFor` draws that line, and it is the\n * same one the rules and every server gate draw.\n *\n * The roster is read only while this drawer is open. It is four collection\n * reads on a settings surface, and ones that happen because somebody asked for\n * them are a different thing from ones that happen because a card mounted.\n */\nexport function SendingSenderDrawer(props: SendingSenderDrawerProps) {\n const { open, hostId, view, senderId, onClose, onSaved } = props\n const call = useSendingApi()\n const firestore = useFirestore()\n\n const [mailbox, setMailbox] = useState('')\n const [fromName, setFromName] = useState('')\n const [replyTo, setReplyTo] = useState('')\n const [busy, setBusy] = useState(false)\n const [error, setError] = useState('')\n\n /**\n * The row being edited, or null while adding one.\n *\n * Resolved from the view the card already holds rather than read again here:\n * the list and the editor open from one answer, so they cannot disagree\n * about what a sender currently is.\n */\n const editing = senderId\n ? ((view?.senders ?? []).find((sender) => sender.id === senderId) ?? null)\n : null\n\n /*\n * The stored values are copied in when the drawer OPENS, not on every\n * render of the card.\n *\n * A settings form seeded from a prop that keeps arriving would discard what\n * somebody was halfway through typing the moment the card re-read the\n * identity behind them — so the dependencies are the row's FIELDS and not\n * the array they came in, which is a new array on every read.\n */\n useEffect(() => {\n if (!open) return\n setMailbox(editing?.localPart ?? '')\n setFromName(editing?.fromName ?? '')\n setReplyTo(editing?.replyTo ?? '')\n setError('')\n }, [\n open,\n senderId,\n editing?.localPart,\n editing?.fromName,\n editing?.replyTo,\n ])\n\n /*\n * The org this site belongs to, as the identity route resolved it.\n *\n * Taken from the view rather than read again here, so the drawer and the\n * card it opens from agree about which workspace they are looking at, and\n * so the org reads below cannot start before the route has answered.\n */\n const orgId = String(view?.orgId ?? '')\n const reading = open && Boolean(hostId)\n\n /*\n * THE SITE'S OWN COLLABORATOR ROSTER — `hosts/{hostId}/members`.\n *\n * Not the whole answer, and reading it alone was the defect: this\n * subcollection holds only people added TO ONE SITE by\n * `POST /api/hosts/members`. A workspace whose team reaches every site\n * through their org membership has no rows here at all, so a picker built\n * on it offered whichever one address happened to have been added this way\n * and no teammates whatsoever.\n *\n * It stays because it is the only source for one population: somebody\n * invited to the site by an address with no Aglyn account behind it yet has\n * a roster row and, until they accept, no org member document. They are a\n * real person with a real mailbox who has been granted access, which is all\n * a reply address needs.\n *\n * Ordered by nothing, and capped: see {@link SENDER_PICKER_CEILING}. This\n * subcollection has exactly one writer and it writes `email` on every\n * document, so an `orderBy('email')` would be safe here — it buys nothing,\n * because the merged set below is arranged for display after the fact and a\n * server order over one of four reads cannot survive the merge.\n */\n const { data: siteMemberDocs } = useFirestoreCollection<any>(\n () =>\n reading\n ? query(\n collection(firestore, 'hosts', hostId, 'members'),\n limit(SENDER_PICKER_CEILING),\n )\n : null,\n [firestore, hostId, reading],\n { idField: '$id' },\n )\n\n /*\n * THE ORG'S TEAM — `orgs/{orgId}/members`, in the three shapes that reach\n * one host.\n *\n * `hostRoleFor` is the predicate the rules, the ~20 server gates and\n * `useHostRole` all resolve a member's access to a site with, and it is a\n * disjunction of exactly three cases: an owner or admin spans every site; an\n * editor or viewer with `allHosts` spans every site at their org role; and\n * anybody may carry an explicit per-site grant in `hostAccess`. Firestore\n * cannot express that as one query, so it is asked as three and merged.\n *\n * ## Three narrow reads rather than one broad one\n *\n * The alternative — read the roster and filter in the browser — reads every\n * member of the workspace to find the few who work on this site, and the cap\n * would then apply BEFORE the filter: in an org of 400 where five people\n * have this site, the picker could contain none of them. Splitting the\n * predicate across the wire means the cap only ever cuts a tail of people\n * who all belong in the list.\n *\n * ## The `orderBy` trap, and why there is no `orderBy` here\n *\n * `orderBy` matches only documents that HAVE the field, so ordering on one\n * some writer omits hides rows instead of arranging them. `email` is NOT\n * safe to order on in this collection: `AglynOrgMember` declares it\n * optional, and two production paths create a member document without it —\n * `PATCH /api/hosts/members` re-grants host access with no identity fields,\n * and `POST /api/orgs/members` omits it entirely when the auth record\n * carries no email. Ordering on it would drop exactly the teammates this\n * change exists to surface, silently.\n *\n * Each `where` below is safe in a way an `orderBy` is not, and for the same\n * reason it looks unsafe: a document missing `role`, missing `allHosts` or\n * missing `hostAccess` is dropped by the filter — and `hostRoleFor` resolves\n * every one of those to \"no access\" anyway. The predicate and the index\n * agree about what absence means, so the query cannot hide anybody the\n * filter would have kept.\n */\n const orgMembers = (constrain: (base: any) => any) => () =>\n reading && orgId\n ? constrain(collection(firestore, 'orgs', orgId, 'members'))\n : null\n\n const { data: orgAdminDocs } = useFirestoreCollection<any>(\n orgMembers((base) =>\n query(\n base,\n where('role', 'in', ['owner', 'admin']),\n limit(SENDER_PICKER_CEILING),\n ),\n ),\n [firestore, orgId, reading],\n { idField: '$id' },\n )\n const { data: orgWideDocs } = useFirestoreCollection<any>(\n orgMembers((base) =>\n query(base, where('allHosts', '==', true), limit(SENDER_PICKER_CEILING)),\n ),\n [firestore, orgId, reading],\n { idField: '$id' },\n )\n /*\n * `HOST_ACCESS_ROLES` rather than a written-out array, for the reason it\n * exists: a role added to `HostAccessRole` and missing from an `in` list is\n * a person who holds access and cannot be seen to, with no error to explain\n * it. The constant is built from a `Record` so a new role fails to compile\n * there instead of quietly shortening this query.\n */\n const { data: orgScopedDocs } = useFirestoreCollection<any>(\n orgMembers((base) =>\n query(\n base,\n where(`hostAccess.${hostId}`, 'in', HOST_ACCESS_ROLES),\n limit(SENDER_PICKER_CEILING),\n ),\n ),\n [firestore, orgId, hostId, reading],\n { idField: '$id' },\n )\n\n const candidates = useMemo<SenderCandidate[]>(() => {\n /*\n * ONE ROW PER PERSON, keyed by uid.\n *\n * The same teammate legitimately appears in several of these reads — an\n * org admin who is also an explicit collaborator is in two, and an org\n * member who accepted a site invite has a roster row as well — so the\n * merge is by identity rather than by document. The org member document\n * and the site roster row are keyed by the same uid, which is what makes\n * that possible: `POST /api/hosts/members` names the roster document after\n * the auth uid whenever an account exists, and falls back to a generated\n * id only for an address that has none. Such a row has no org document to\n * collide with, so the fallback cannot merge two people into one.\n *\n * Fields are taken from the first read that has them rather than from a\n * chosen winner. Neither source is complete on its own: the site roster\n * always carries an `email` and never a `displayName`, and an org member\n * document usually carries both but is allowed to omit either.\n */\n const byPerson = new Map<string, SenderCandidate>()\n const fold = (id: string, entry: any) => {\n if (!id) return\n const current = byPerson.get(id) ?? { id, email: '', displayName: '' }\n byPerson.set(id, {\n id,\n email: current.email || String(entry?.email ?? '').trim(),\n displayName:\n current.displayName || String(entry?.displayName ?? '').trim(),\n })\n }\n\n /*\n * THE PREDICATE IS APPLIED AGAIN HERE, over the documents themselves.\n *\n * The three queries are the predicate projected onto an index, and an\n * index answers a coarser question than the function does — `allHosts`\n * reaches every site only for a member who HAS an org role, and a document\n * carrying the flag with no role is a member of nothing. `hostRoleFor` is\n * the one definition of \"can this person reach this site\", so it decides,\n * and the queries are only what keeps the reads narrow.\n */\n for (const entry of [\n ...(orgAdminDocs ?? []),\n ...(orgWideDocs ?? []),\n ...(orgScopedDocs ?? []),\n ]) {\n if (!hostRoleFor(entry, hostId as never)) continue\n fold(String(entry?.$id ?? ''), entry)\n }\n\n /*\n * The site's roster rows carry no role of their own to resolve — being in\n * this subcollection IS access to this site, which is what the Users card\n * on the site's own settings page renders it as. `uid` before `$id` so an\n * accepted collaborator merges onto their org member document rather than\n * arriving as a second row for the same person.\n */\n for (const entry of siteMemberDocs ?? []) {\n fold(String(entry?.uid || entry?.$id || ''), entry)\n }\n\n return (\n [...byPerson.values()]\n /*\n * An address is not optional. It is what the mailbox is derived from\n * and what replies are pointed at, so a person recorded without one\n * has nothing this picker could fill in.\n */\n .filter((entry) => entry.email)\n /*\n * Sorted here rather than by the server, because this is a COMPLETE\n * set and not a page: four reads have been merged, so no server order\n * survives, and arranging a page in the browser is what makes an\n * arbitrary slice read as a ranked one. By the name a person is\n * looking for, falling back to the address for somebody who has none.\n */\n .sort((left, right) =>\n (left.displayName || left.email).localeCompare(\n right.displayName || right.email,\n undefined,\n { sensitivity: 'base' },\n ),\n )\n )\n }, [orgAdminDocs, orgWideDocs, orgScopedDocs, siteMemberDocs, hostId])\n\n /*\n * The domain half, shown as a fixed suffix rather than as a field.\n *\n * A person setting a sender is choosing an address, and an address with its\n * domain missing from the screen is one they have to assemble in their head\n * from the alert above. Read from the identity the server resolved, so it\n * is the domain a send would actually use.\n */\n const domain = String(view?.selected ?? '')\n const pooled = Boolean(view) && !view?.localPartInUse\n\n const handleSave = useCallback(async () => {\n if (busy) return\n /*\n * A POOLED SITE SENDS NO MAILBOX AT ALL, rather than sending one the\n * route will refuse.\n *\n * The field is disabled above and the alert says why, and this is the\n * half that matters: a merchant on the shared address editing their\n * sender name would otherwise have the whole save rejected over a field\n * they were never offered.\n */\n const checked = pooled ? null : validateSendingLocalPart(mailbox)\n if (checked?.error) return setError(checked.error)\n setError('')\n setBusy(true)\n const { response, payload } = await call({\n path: 'sending-identity',\n method: 'POST',\n /*\n * No `domain` key. Absent means \"this is not a decision about the\n * domain\" — an empty one would mean \"move this site back to the address\n * Aglyn issues it\", which would reset a site sending as its own\n * verified name every time somebody edited the sender.\n */\n body: {\n hostId,\n action: senderId ? 'updateSender' : 'createSender',\n ...(senderId ? { senderId } : {}),\n ...(checked?.localPart ? { localPart: checked.localPart } : {}),\n fromName: fromName.trim(),\n replyTo: replyTo.trim(),\n },\n })\n setBusy(false)\n if (!response.ok) {\n return setError(payload?.error ?? 'Could not save who this site sends as')\n }\n onSaved(String(payload?.senderId ?? '') || undefined)\n onClose()\n }, [\n busy,\n call,\n hostId,\n senderId,\n mailbox,\n pooled,\n fromName,\n replyTo,\n onSaved,\n onClose,\n ])\n\n const applyCandidate = useCallback((candidate: SenderCandidate) => {\n const at = candidate.email.lastIndexOf('@')\n const proposed = normalizeLocalPart(\n at > 0 ? candidate.email.slice(0, at) : '',\n )\n if (proposed) setMailbox(proposed)\n if (candidate.displayName) setFromName(candidate.displayName)\n setReplyTo(candidate.email)\n setError('')\n }, [])\n\n return (\n <NavigationDrawerComponent\n open={open}\n anchor=\"right\"\n variant=\"temporary\"\n onClose={onClose}\n AppBarProps={{ color: 'surface' }}\n appBarLeft={\n <>\n <IconButton\n color=\"inherit\"\n edge=\"start\"\n onClick={onClose}\n sx={{ mr: 2 }}\n >\n <MdiIcon path={ICON_VARIANT_CLOSE.path} />\n <SrOnly>close drawer</SrOnly>\n </IconButton>\n <Typography variant=\"h6\" component=\"div\">\n {senderId ? 'Edit this sender' : 'Add a sender'}\n </Typography>\n {/*\n The help affordance every console surface carries, pointed at the\n section that says what a sender is and which of its three fields\n the shared address restricts — which is the question somebody\n standing in this drawer with a disabled Mailbox field has.\n */}\n <HelpTip\n {...pluginDocsHelp('emailCampaigns', {\n anchor: '#senders',\n title: 'Senders',\n excerpt:\n 'A mailbox this site may send as, with the name and reply ' +\n 'address that go out in front of it. A campaign picks one of ' +\n 'them rather than typing an address.',\n })}\n />\n </>\n }\n >\n <Container gutterY>\n <Stack spacing={2}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'An address your email may leave on, and the name in front of ' +\n 'it. The domain is your site’s verified sending domain and ' +\n 'cannot be changed here — the part before the @ can. To have ' +\n 'replies reach a personal or company mailbox, use the reply ' +\n 'address: sending as an address on somebody else’s mail ' +\n 'provider is refused by the receiving side, not delivered.'}\n </Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {editing?.isDefault\n ? 'Every email you compose picks a sender. This is the one an ' +\n 'email that names no other goes out as.'\n : 'Every email you compose picks a sender, and this will be ' +\n 'one of the choices.'}\n </Typography>\n\n {candidates.length ? (\n <>\n <TextField\n select\n label=\"Send as a person\"\n value=\"\"\n size=\"small\"\n onChange={(event) => {\n const match = candidates.find(\n (entry) => entry.id === event.target.value,\n )\n if (match) applyCandidate(match)\n }}\n helperText=\"Fills the three fields below from someone who works on this site\"\n >\n {/*\n THE NAME LEADS, and the address sits under it.\n\n A sender picker is answering \"which of us is this from\",\n which is a question about a person; a list of bare addresses\n makes the reader parse a local part to recognise a colleague.\n The address stays on the row because it is what the mailbox\n is derived from and where replies will land, so it is part of\n the choice rather than a detail behind it — and it is the\n whole row for somebody whose name nothing has recorded, which\n is an ordinary state for an invited teammate who has not\n signed in yet.\n */}\n {candidates.map((candidate) => (\n <MenuItem key={candidate.id} value={candidate.id}>\n <Stack spacing={0}>\n {candidate.displayName ? (\n <Typography variant=\"body2\">\n {candidate.displayName}\n </Typography>\n ) : null}\n <Typography\n variant={candidate.displayName ? 'caption' : 'body2'}\n color={\n candidate.displayName ? 'text.secondary' : undefined\n }\n >\n {candidate.email}\n </Typography>\n </Stack>\n </MenuItem>\n ))}\n </TextField>\n <Divider />\n </>\n ) : null}\n\n {pooled ? (\n <Alert severity=\"info\">\n {'This site sends on a shared Aglyn address, whose mailbox is ' +\n 'fixed and shared with the other sites on it. The name and ' +\n 'reply address below apply to that mail; the mailbox takes ' +\n 'effect once this site has a domain of its own.'}\n </Alert>\n ) : null}\n\n <TextField\n label=\"Mailbox\"\n value={mailbox}\n onChange={(event) => setMailbox(event.target.value)}\n size=\"small\"\n disabled={pooled}\n slotProps={{\n input: domain\n ? {\n endAdornment: (\n <InputAdornment position=\"end\">\n {`@${domain}`}\n </InputAdornment>\n ),\n }\n : undefined,\n }}\n helperText={\n 'The part before the @ — for example hello, sales or jamie'\n }\n />\n <TextField\n label=\"Sender name\"\n value={fromName}\n onChange={(event) => setFromName(event.target.value)}\n size=\"small\"\n helperText=\"Shown in front of the address. A person’s name, or your brand\"\n />\n <TextField\n label=\"Reply address\"\n value={replyTo}\n onChange={(event) => setReplyTo(event.target.value)}\n size=\"small\"\n type=\"email\"\n helperText=\"Where replies go. May be any mailbox, including a personal one\"\n />\n\n {error ? <Alert severity=\"error\">{error}</Alert> : null}\n\n <Button\n variant=\"contained\"\n disabled={busy || !view}\n onClick={() => void handleSave()}\n >\n {busy ? 'Saving…' : senderId ? 'Save sender' : 'Add sender'}\n </Button>\n </Stack>\n </Container>\n </NavigationDrawerComponent>\n )\n}\nSendingSenderDrawer.displayName = 'SendingSenderDrawer'\n\nexport default SendingSenderDrawer\n"],"names":["hostRoleFor","HOST_ACCESS_ROLES","pluginDocsHelp","ICON_VARIANT_CLOSE","Container","HelpTip","MdiIcon","SrOnly","NavigationDrawerComponent","normalizeLocalPart","validateSendingLocalPart","useFirestore","useFirestoreCollection","Alert","Button","Divider","IconButton","InputAdornment","MenuItem","Stack","TextField","Typography","collection","limit","query","where","useCallback","useEffect","useMemo","useState","useSendingApi","SENDER_PICKER_CEILING","SendingSenderDrawer","props","open","hostId","view","senderId","onClose","onSaved","call","firestore","mailbox","setMailbox","fromName","setFromName","replyTo","setReplyTo","busy","setBusy","error","setError","editing","senders","find","sender","id","localPart","orgId","String","reading","Boolean","data","siteMemberDocs","idField","orgMembers","constrain","orgAdminDocs","base","orgWideDocs","orgScopedDocs","candidates","byPerson","Map","fold","entry","current","get","email","displayName","set","trim","$id","uid","values","filter","sort","left","right","localeCompare","undefined","sensitivity","domain","selected","pooled","localPartInUse","handleSave","checked","response","payload","path","method","body","action","ok","applyCandidate","candidate","at","lastIndexOf","proposed","slice","anchor","variant","AppBarProps","color","appBarLeft","edge","onClick","sx","mr","component","title","excerpt","gutterY","spacing","isDefault","length","select","label","value","size","onChange","event","match","target","helperText","map","severity","disabled","slotProps","input","endAdornment","position","type"],"mapp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