@aglyn/tenant-data-admin 1.0.0-beta.271 → 1.0.0-beta.272
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/src/lib/server/domain-ownership.d.ts +205 -0
- package/src/lib/server/domain-ownership.js +575 -0
- package/src/lib/server/domain-ownership.js.map +1 -0
- package/src/lib/server/erase.d.ts +17 -0
- package/src/lib/server/erase.js +21 -0
- package/src/lib/server/erase.js.map +1 -1
- package/src/lib/server/site-care-emails.d.ts +2 -1
- package/src/lib/server/site-care-emails.js +4 -4
- package/src/lib/server/site-care-emails.js.map +1 -1
- package/src/lib/server/site-care-inbound.d.ts +58 -15
- package/src/lib/server/site-care-inbound.js +67 -41
- package/src/lib/server/site-care-inbound.js.map +1 -1
- package/src/lib/server/sso-provisioning.d.ts +6 -0
- package/src/lib/server/sso-provisioning.js +7 -0
- package/src/lib/server/sso-provisioning.js.map +1 -1
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
* `shared-util-email`), rendered in the WORKSPACE's brand — a white-label
|
|
22
22
|
* agency's client hears from the agency — and sent from the platform's
|
|
23
23
|
* address with a Reply-To that threads the answer onto the same request:
|
|
24
|
-
* `
|
|
24
|
+
* `support+<requestId>@<inbound mail domain>` (AGL-3997), or the support
|
|
25
|
+
* address for an email about no one request. Metered as platform mail, like
|
|
25
26
|
* the success manager's copy: this is the service the owner pays for, not
|
|
26
27
|
* mail the workspace sent.
|
|
27
28
|
*
|
|
@@ -15,7 +15,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/ import { inboundMailDomain } from "@aglyn/aglyn/app-utils/inbound-mail-domain";
|
|
18
|
-
import {
|
|
18
|
+
import { siteCareReplyAddress } from "@aglyn/aglyn/app-utils/site-care";
|
|
19
19
|
import { isEmailConfigured, sendEmail } from "@aglyn/shared-util-email";
|
|
20
20
|
import { meterPlatformEmail } from "./email-metering.js";
|
|
21
21
|
import { renderSystemEmailContent, systemEmailBrand } from "./render-system-email.js";
|
|
@@ -26,7 +26,8 @@ import { renderSystemEmailContent, systemEmailBrand } from "./render-system-emai
|
|
|
26
26
|
* `shared-util-email`), rendered in the WORKSPACE's brand — a white-label
|
|
27
27
|
* agency's client hears from the agency — and sent from the platform's
|
|
28
28
|
* address with a Reply-To that threads the answer onto the same request:
|
|
29
|
-
* `
|
|
29
|
+
* `support+<requestId>@<inbound mail domain>` (AGL-3997), or the support
|
|
30
|
+
* address for an email about no one request. Metered as platform mail, like
|
|
30
31
|
* the success manager's copy: this is the service the owner pays for, not
|
|
31
32
|
* mail the workspace sent.
|
|
32
33
|
*
|
|
@@ -34,8 +35,7 @@ import { renderSystemEmailContent, systemEmailBrand } from "./render-system-emai
|
|
|
34
35
|
* `email.sent` history row, so whether an email went is a fact on the
|
|
35
36
|
* request rather than an assumption.
|
|
36
37
|
*/ /** The address a request's emails reply to, so the answer joins it. */ export function siteCareReplyTo(requestId) {
|
|
37
|
-
|
|
38
|
-
return `${local}@${inboundMailDomain()}`;
|
|
38
|
+
return siteCareReplyAddress(requestId, inboundMailDomain());
|
|
39
39
|
}
|
|
40
40
|
export async function sendSiteCareEmail(input) {
|
|
41
41
|
var _input_to;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/site-care-emails.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { inboundMailDomain } from '@aglyn/aglyn/app-utils/inbound-mail-domain'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/site-care-emails.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { inboundMailDomain } from '@aglyn/aglyn/app-utils/inbound-mail-domain'\nimport { siteCareReplyAddress } from '@aglyn/aglyn/app-utils/site-care'\nimport { isEmailConfigured, sendEmail } from '@aglyn/shared-util-email'\nimport { meterPlatformEmail } from './email-metering'\nimport {\n renderSystemEmailContent,\n systemEmailBrand,\n} from './render-system-email'\n\n/**\n * SENDING THE SITE CARE EMAILS (AGL-3959).\n *\n * Every Site Care email is a catalog key (`site-care-emails.ts` in\n * `shared-util-email`), rendered in the WORKSPACE's brand — a white-label\n * agency's client hears from the agency — and sent from the platform's\n * address with a Reply-To that threads the answer onto the same request:\n * `support+<requestId>@<inbound mail domain>` (AGL-3997), or the support\n * address for an email about no one request. Metered as platform mail, like\n * the success manager's copy: this is the service the owner pays for, not\n * mail the workspace sent.\n *\n * Never throws. The caller records what it returns as the request's\n * `email.sent` history row, so whether an email went is a fact on the\n * request rather than an assumption.\n */\n\n/** The address a request's emails reply to, so the answer joins it. */\nexport function siteCareReplyTo(requestId: string | null): string {\n return siteCareReplyAddress(requestId, inboundMailDomain())\n}\n\nexport interface SiteCareEmailInput {\n key: string\n to: string | null\n /** The workspace whose brand the email is sent in; null is the platform's. */\n org: Readonly<Record<string, unknown>> | null\n requestId: string | null\n merge: Record<string, string>\n fallback: { subject: string; text: string }\n}\n\nexport interface SiteCareEmailResult {\n sent: boolean\n to: string | null\n subject: string\n reason?: string\n}\n\nexport async function sendSiteCareEmail(input: SiteCareEmailInput): Promise<SiteCareEmailResult> {\n const to = String(input.to ?? '').trim()\n if (!to) return { sent: false, to: null, subject: input.fallback.subject, reason: 'no-recipient' }\n if (!isEmailConfigured()) {\n return { sent: false, to, subject: input.fallback.subject, reason: 'unconfigured' }\n }\n try {\n const brand = systemEmailBrand(input.org)\n const content = await renderSystemEmailContent(\n input.key,\n { ...(brand.orgName ? { 'org.name': brand.orgName } : {}), ...input.merge },\n brand,\n input.fallback,\n )\n const result = await sendEmail({\n to,\n subject: content.subject,\n text: content.text,\n ...(content.html ? { html: content.html } : {}),\n ...(brand.fromName ? { fromName: brand.fromName } : {}),\n replyTo: siteCareReplyTo(input.requestId),\n context: input.key,\n })\n if (result.sent) await meterPlatformEmail()\n return result.sent\n ? { sent: true, to, subject: content.subject }\n : {\n sent: false,\n to,\n subject: content.subject,\n reason: String((result as { reason?: unknown }).reason ?? 'not-sent'),\n }\n } catch (error) {\n console.error(`[site-care] ${input.key} email failed`, error)\n return { sent: false, to, subject: input.fallback.subject, reason: 'error' }\n }\n}\n"],"names":["inboundMailDomain","siteCareReplyAddress","isEmailConfigured","sendEmail","meterPlatformEmail","renderSystemEmailContent","systemEmailBrand","siteCareReplyTo","requestId","sendSiteCareEmail","input","to","String","trim","sent","subject","fallback","reason","brand","org","content","key","orgName","merge","result","text","html","fromName","replyTo","context","error","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,QAAQ,6CAA4C;AAC9E,SAASC,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,iBAAiB,EAAEC,SAAS,QAAQ,2BAA0B;AACvE,SAASC,kBAAkB,QAAQ,sBAAkB;AACrD,SACEC,wBAAwB,EACxBC,gBAAgB,QACX,2BAAuB;AAE9B;;;;;;;;;;;;;;;CAeC,GAED,qEAAqE,GACrE,OAAO,SAASC,gBAAgBC,SAAwB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KAAK,CAAC,CAAC,YAAY,EAAEpB,MAAMW,GAAG,CAAC,aAAa,CAAC,EAAES;QACvD,OAAO;YAAEhB,MAAM;YAAOH;YAAII,SAASL,MAAMM,QAAQ,CAACD,OAAO;YAAEE,QAAQ;QAAQ;IAC7E;AACF"}
|
|
@@ -17,25 +17,52 @@
|
|
|
17
17
|
import { type ReceivedEmail } from '@aglyn/shared-util-email';
|
|
18
18
|
import { type SiteCareDeps } from './site-care-requests';
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* SITE CARE MAIL ARRIVES AT THE SUPPORT ADDRESS (AGL-3959, AGL-3997).
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
22
|
+
* Site Care has no address of its own. An owner emails the support address
|
|
23
|
+
* they already know, and the support mailbox delivers a copy of each message
|
|
24
|
+
* to `support@<inbound mail domain>`, where the mail provider announces it.
|
|
25
|
+
* A message to either address from a member of a workspace with Site Care
|
|
26
|
+
* becomes a Site Care request on that workspace, matched by the sender's
|
|
27
|
+
* address against the members of workspaces that have Site Care. A reply to
|
|
28
|
+
* any Site Care email goes to `support+<requestId>@…` and joins that
|
|
29
|
+
* request's thread, when the sender is a member of its workspace.
|
|
30
|
+
*
|
|
31
|
+
* Everything else is acknowledged and left alone: nothing is filed and
|
|
32
|
+
* nothing is sent back, and a message to the support address stays in the
|
|
33
|
+
* support inbox as ordinary support mail. That includes the platform's own
|
|
34
|
+
* mail and anything a machine sent: an out-of-office answering a Site Care
|
|
35
|
+
* email would otherwise join the request, and one answering anything that
|
|
36
|
+
* replies to support would open one.
|
|
29
37
|
*/
|
|
30
|
-
/** What a received message was addressed to,
|
|
38
|
+
/** What a received message was addressed to: a new request, or a reply on one. */
|
|
31
39
|
export type SiteCareInboundTarget = {
|
|
32
40
|
kind: 'new';
|
|
33
41
|
} | {
|
|
34
42
|
kind: 'reply';
|
|
35
43
|
requestId: string;
|
|
36
44
|
};
|
|
45
|
+
/** The addresses the intake reads as the platform's own. */
|
|
46
|
+
export interface SiteCareInboundAddresses {
|
|
47
|
+
/** The inbound mail domain: `support@` and `support+<requestId>@` it. */
|
|
48
|
+
domain: string;
|
|
49
|
+
/** The operator's support address, or null when the deployment publishes none. */
|
|
50
|
+
supportEmail: string | null;
|
|
51
|
+
/** The address the platform sends from, `USAGE_EMAIL_FROM`'s, or null. */
|
|
52
|
+
platformSender: string | null;
|
|
53
|
+
}
|
|
54
|
+
/** This deployment's {@link SiteCareInboundAddresses}, read per call. */
|
|
55
|
+
export declare function siteCareInboundAddresses(): SiteCareInboundAddresses;
|
|
37
56
|
/** The Site Care target among a message's recipients, or null. */
|
|
38
|
-
export declare function siteCareInboundTarget(recipients: readonly string[],
|
|
57
|
+
export declare function siteCareInboundTarget(recipients: readonly string[], addresses: Pick<SiteCareInboundAddresses, 'domain' | 'supportEmail'>): SiteCareInboundTarget | null;
|
|
58
|
+
/** Why a message is ignored without a lookup: the platform wrote it, or a machine did. */
|
|
59
|
+
export type SiteCareMachineMail = 'ours' | 'automatic';
|
|
60
|
+
/**
|
|
61
|
+
* Whether a message is not a person writing in: from the support address,
|
|
62
|
+
* the platform's sender or any address on the inbound mail domain, or one
|
|
63
|
+
* its headers say a machine sent. Null when it may be a person.
|
|
64
|
+
*/
|
|
65
|
+
export declare function siteCareMachineMail(message: Pick<ReceivedEmail, 'from' | 'autoSubmitted'>, addresses: SiteCareInboundAddresses): SiteCareMachineMail | null;
|
|
39
66
|
export interface SiteCareSenderMatch {
|
|
40
67
|
orgId: string;
|
|
41
68
|
org: Record<string, unknown>;
|
|
@@ -49,7 +76,7 @@ export type SiteCareAccountLookup = (email: string) => Promise<{
|
|
|
49
76
|
/**
|
|
50
77
|
* Every pool, not only the project's: an owner who signs in through SSO is a
|
|
51
78
|
* GCIP tenant user the project pool never returns (AGL-1122), and their mail
|
|
52
|
-
* would be
|
|
79
|
+
* would be read as a stranger's.
|
|
53
80
|
*/
|
|
54
81
|
export declare const findSiteCareAccount: SiteCareAccountLookup;
|
|
55
82
|
/**
|
|
@@ -60,6 +87,16 @@ export declare const findSiteCareAccount: SiteCareAccountLookup;
|
|
|
60
87
|
export declare function findSiteCareWorkspaceForSender(firestore: FirebaseFirestore.Firestore, findAccount: SiteCareAccountLookup, sender: string): Promise<SiteCareSenderMatch | null>;
|
|
61
88
|
/** The words of a message, above any quoted history. */
|
|
62
89
|
export declare function siteCareMessageBody(message: Pick<ReceivedEmail, 'text' | 'html'>): string;
|
|
90
|
+
/** Why a message was acknowledged and left alone. */
|
|
91
|
+
export type SiteCareIgnoredReason =
|
|
92
|
+
/** No workspace with Site Care has the sender as a member: ordinary support mail. */
|
|
93
|
+
'not-a-member'
|
|
94
|
+
/** The platform's own address wrote it. */
|
|
95
|
+
| 'ours'
|
|
96
|
+
/** Its headers say a machine sent it. */
|
|
97
|
+
| 'automatic'
|
|
98
|
+
/** A member wrote, but said nothing. */
|
|
99
|
+
| 'empty';
|
|
63
100
|
export type SiteCareInboundOutcome = {
|
|
64
101
|
outcome: 'opened';
|
|
65
102
|
requestId: string;
|
|
@@ -67,14 +104,20 @@ export type SiteCareInboundOutcome = {
|
|
|
67
104
|
outcome: 'replied';
|
|
68
105
|
requestId: string;
|
|
69
106
|
} | {
|
|
70
|
-
outcome: '
|
|
71
|
-
|
|
72
|
-
outcome: 'empty';
|
|
107
|
+
outcome: 'ignored';
|
|
108
|
+
reason: SiteCareIgnoredReason;
|
|
73
109
|
};
|
|
74
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Files one received message addressed to the support address or to a
|
|
112
|
+
* request's reply address. Nothing is ever sent back to a sender it does
|
|
113
|
+
* not file for: a message to the support address is still in the support
|
|
114
|
+
* inbox, answered there like any other.
|
|
115
|
+
*/
|
|
75
116
|
export declare function fileSiteCareInboundEmail(firestore: FirebaseFirestore.Firestore, input: {
|
|
76
117
|
target: SiteCareInboundTarget;
|
|
77
118
|
message: ReceivedEmail;
|
|
119
|
+
/** The platform's own addresses; this deployment's by default. */
|
|
120
|
+
addresses?: SiteCareInboundAddresses;
|
|
78
121
|
/** The seam a spec replaces; every auth pool by default. */
|
|
79
122
|
findAccount?: SiteCareAccountLookup;
|
|
80
123
|
}, deps?: SiteCareDeps): Promise<SiteCareInboundOutcome>;
|
|
@@ -13,26 +13,41 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/ import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
16
|
+
*/ import { inboundMailDomain } from "@aglyn/aglyn/app-utils/inbound-mail-domain";
|
|
17
|
+
import { emailAddressOf, htmlToPlainText, stripQuotedHistory, threadSubject } from "@aglyn/aglyn/app-utils/email-text";
|
|
18
|
+
import { SITE_CARE_INBOUND_LOCAL_PART, siteCareSupportAddress } from "@aglyn/aglyn/app-utils/site-care";
|
|
19
|
+
import { getEmailConfig } from "@aglyn/shared-util-email";
|
|
19
20
|
import { appendSiteCareReply, openSiteCareRequest, orgHasSiteCare, readSiteCareOrg } from "./site-care-requests.js";
|
|
20
21
|
import { findUserByEmailAcrossPools } from "./auth-pools.js";
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
/** This deployment's {@link SiteCareInboundAddresses}, read per call. */ export function siteCareInboundAddresses() {
|
|
23
|
+
return {
|
|
24
|
+
domain: inboundMailDomain(),
|
|
25
|
+
supportEmail: emailAddressOf(siteCareSupportAddress()),
|
|
26
|
+
platformSender: emailAddressOf(getEmailConfig().from)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** The Site Care target among a message's recipients, or null. */ export function siteCareInboundTarget(recipients, addresses) {
|
|
30
|
+
const domain = addresses.domain.toLowerCase();
|
|
31
|
+
const support = emailAddressOf(addresses.supportEmail);
|
|
23
32
|
let found = null;
|
|
24
33
|
for (const value of recipients){
|
|
25
34
|
var _ref;
|
|
26
35
|
var _exec;
|
|
27
|
-
// Validated (and lowercased) for the
|
|
28
|
-
// as written: a request id is a case-sensitive Firestore id, and
|
|
29
|
-
// lowercasing `
|
|
36
|
+
// Validated (and lowercased) for the comparison, but the local part is
|
|
37
|
+
// read as written: a request id is a case-sensitive Firestore id, and
|
|
38
|
+
// lowercasing `support+AbC…` would look up a ticket that does not exist.
|
|
30
39
|
const address = emailAddressOf(value);
|
|
31
40
|
if (!address) continue;
|
|
41
|
+
if (support && address === support) {
|
|
42
|
+
found = found != null ? found : {
|
|
43
|
+
kind: 'new'
|
|
44
|
+
};
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
32
47
|
const raw = String(value != null ? value : '').trim();
|
|
33
48
|
const written = ((_ref = (_exec = /<([^<>]+)>\s*$/.exec(raw)) == null ? void 0 : _exec[1]) != null ? _ref : raw).trim();
|
|
34
49
|
const at = written.lastIndexOf('@');
|
|
35
|
-
if (at <= 0 || address.slice(address.lastIndexOf('@') + 1) !== domain
|
|
50
|
+
if (at <= 0 || address.slice(address.lastIndexOf('@') + 1) !== domain) continue;
|
|
36
51
|
const local = written.slice(0, at);
|
|
37
52
|
if (local.toLowerCase() === SITE_CARE_INBOUND_LOCAL_PART) {
|
|
38
53
|
found = found != null ? found : {
|
|
@@ -53,10 +68,26 @@ import { sendSiteCareEmail } from "./site-care-emails.js";
|
|
|
53
68
|
}
|
|
54
69
|
return found;
|
|
55
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether a message is not a person writing in: from the support address,
|
|
73
|
+
* the platform's sender or any address on the inbound mail domain, or one
|
|
74
|
+
* its headers say a machine sent. Null when it may be a person.
|
|
75
|
+
*/ export function siteCareMachineMail(message, addresses) {
|
|
76
|
+
const sender = emailAddressOf(message.from);
|
|
77
|
+
if (sender) {
|
|
78
|
+
const own = [
|
|
79
|
+
addresses.supportEmail,
|
|
80
|
+
addresses.platformSender
|
|
81
|
+
].map((value)=>emailAddressOf(value));
|
|
82
|
+
if (own.includes(sender)) return 'ours';
|
|
83
|
+
if (sender.slice(sender.lastIndexOf('@') + 1) === addresses.domain.toLowerCase()) return 'ours';
|
|
84
|
+
}
|
|
85
|
+
return message.autoSubmitted ? 'automatic' : null;
|
|
86
|
+
}
|
|
56
87
|
/**
|
|
57
88
|
* Every pool, not only the project's: an owner who signs in through SSO is a
|
|
58
89
|
* GCIP tenant user the project pool never returns (AGL-1122), and their mail
|
|
59
|
-
* would be
|
|
90
|
+
* would be read as a stranger's.
|
|
60
91
|
*/ export const findSiteCareAccount = async (email)=>{
|
|
61
92
|
const found = await findUserByEmailAcrossPools(email).catch(()=>null);
|
|
62
93
|
return found ? {
|
|
@@ -92,21 +123,33 @@ import { sendSiteCareEmail } from "./site-care-emails.js";
|
|
|
92
123
|
const plain = (((_message_text = message.text) == null ? void 0 : _message_text.trim()) ? message.text : htmlToPlainText(message.html)).replace(/\r\n?/g, '\n');
|
|
93
124
|
return stripQuotedHistory(plain).trim();
|
|
94
125
|
}
|
|
95
|
-
/**
|
|
96
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Files one received message addressed to the support address or to a
|
|
128
|
+
* request's reply address. Nothing is ever sent back to a sender it does
|
|
129
|
+
* not file for: a message to the support address is still in the support
|
|
130
|
+
* inbox, answered there like any other.
|
|
131
|
+
*/ export async function fileSiteCareInboundEmail(firestore, input, deps = {}) {
|
|
132
|
+
var _input_addresses, _input_findAccount;
|
|
97
133
|
const { message } = input;
|
|
134
|
+
const machine = siteCareMachineMail(message, (_input_addresses = input.addresses) != null ? _input_addresses : siteCareInboundAddresses());
|
|
135
|
+
if (machine) return {
|
|
136
|
+
outcome: 'ignored',
|
|
137
|
+
reason: machine
|
|
138
|
+
};
|
|
98
139
|
const body = siteCareMessageBody(message);
|
|
99
140
|
const sender = emailAddressOf(message.from);
|
|
100
|
-
|
|
101
|
-
|
|
141
|
+
const findAccount = (_input_findAccount = input.findAccount) != null ? _input_findAccount : findSiteCareAccount;
|
|
142
|
+
const match = sender ? await findSiteCareWorkspaceForSender(firestore, findAccount, sender) : null;
|
|
143
|
+
if (input.target.kind === 'reply' && match) {
|
|
144
|
+
var _ticket_get;
|
|
102
145
|
const ticket = await firestore.collection('supportTickets').doc(input.target.requestId).get();
|
|
103
146
|
const orgId = String((_ticket_get = ticket.get('orgId')) != null ? _ticket_get : '');
|
|
104
|
-
const match = sender ? await findSiteCareWorkspaceForSender(firestore, (_input_findAccount1 = input.findAccount) != null ? _input_findAccount1 : findSiteCareAccount, sender) : null;
|
|
105
147
|
// Only a member of the request's own workspace may add to it.
|
|
106
|
-
const member =
|
|
107
|
-
if (ticket.exists && member
|
|
148
|
+
const member = orgId ? (await firestore.collection('orgs').doc(orgId).collection('members').doc(match.uid).get()).exists : false;
|
|
149
|
+
if (ticket.exists && member) {
|
|
108
150
|
if (!body) return {
|
|
109
|
-
outcome: '
|
|
151
|
+
outcome: 'ignored',
|
|
152
|
+
reason: 'empty'
|
|
110
153
|
};
|
|
111
154
|
await appendSiteCareReply(firestore, {
|
|
112
155
|
ticketId: ticket.id,
|
|
@@ -124,30 +167,13 @@ import { sendSiteCareEmail } from "./site-care-emails.js";
|
|
|
124
167
|
}
|
|
125
168
|
// A reply that cannot join its request is read as a new one below.
|
|
126
169
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
await ((_deps_email = deps.email) != null ? _deps_email : sendSiteCareEmail)({
|
|
132
|
-
key: SITE_CARE_UNKNOWN_SENDER_EMAIL_KEY,
|
|
133
|
-
to: sender,
|
|
134
|
-
org: null,
|
|
135
|
-
requestId: null,
|
|
136
|
-
merge: {
|
|
137
|
-
'sender.email': sender
|
|
138
|
-
},
|
|
139
|
-
fallback: {
|
|
140
|
-
subject: 'We could not match your email to an account',
|
|
141
|
-
text: `We got your message from ${sender}, but no workspace with Site Care has that address as a member. ` + 'Please send it again from the email address you sign in with.'
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
outcome: 'unknown-sender'
|
|
147
|
-
};
|
|
148
|
-
}
|
|
170
|
+
if (!match) return {
|
|
171
|
+
outcome: 'ignored',
|
|
172
|
+
reason: 'not-a-member'
|
|
173
|
+
};
|
|
149
174
|
if (!body && !threadSubject(message.subject)) return {
|
|
150
|
-
outcome: '
|
|
175
|
+
outcome: 'ignored',
|
|
176
|
+
reason: 'empty'
|
|
151
177
|
};
|
|
152
178
|
const opened = await openSiteCareRequest(firestore, {
|
|
153
179
|
orgId: match.orgId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/site-care-inbound.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n emailAddressOf,\n htmlToPlainText,\n stripQuotedHistory,\n threadSubject,\n} from '@aglyn/aglyn/app-utils/email-text'\nimport { SITE_CARE_INBOUND_LOCAL_PART } from '@aglyn/aglyn/app-utils/site-care'\nimport {\n SITE_CARE_UNKNOWN_SENDER_EMAIL_KEY,\n type ReceivedEmail,\n} from '@aglyn/shared-util-email'\nimport {\n appendSiteCareReply,\n openSiteCareRequest,\n orgHasSiteCare,\n readSiteCareOrg,\n type SiteCareDeps,\n} from './site-care-requests'\nimport { findUserByEmailAcrossPools } from './auth-pools'\nimport { sendSiteCareEmail } from './site-care-emails'\n\n/**\n * THE SITE CARE ADDRESS (AGL-3959): `care@<inbound mail domain>`.\n *\n * An owner emails or forwards a change to the address and it becomes a Site\n * Care request on their workspace, matched by the sender's address against\n * the members of workspaces that have Site Care. A reply to any Site Care\n * email goes to `care+<requestId>@…` and joins that request's thread, when\n * the sender is a member of its workspace. A sender who matches nobody gets\n * a reply asking them to write from the address on the account; the message\n * itself is not kept.\n */\n\n/** What a received message was addressed to, of the Site Care address. */\nexport type SiteCareInboundTarget = { kind: 'new' } | { kind: 'reply'; requestId: string }\n\n/** The Site Care target among a message's recipients, or null. */\nexport function siteCareInboundTarget(\n recipients: readonly string[],\n domain: string,\n): SiteCareInboundTarget | null {\n let found: SiteCareInboundTarget | null = null\n for (const value of recipients) {\n // Validated (and lowercased) for the domain, but the local part is read\n // as written: a request id is a case-sensitive Firestore id, and\n // lowercasing `care+AbC…` would look up a ticket that does not exist.\n const address = emailAddressOf(value)\n if (!address) continue\n const raw = String(value ?? '').trim()\n const written = (/<([^<>]+)>\\s*$/.exec(raw)?.[1] ?? raw).trim()\n const at = written.lastIndexOf('@')\n if (at <= 0 || address.slice(address.lastIndexOf('@') + 1) !== domain.toLowerCase()) continue\n const local = written.slice(0, at)\n if (local.toLowerCase() === SITE_CARE_INBOUND_LOCAL_PART) {\n found = found ?? { kind: 'new' }\n continue\n }\n const prefix = `${SITE_CARE_INBOUND_LOCAL_PART}+`\n if (local.toLowerCase().startsWith(prefix)) {\n const requestId = local.slice(prefix.length)\n // Firestore ids: 20 characters of [A-Za-z0-9]; anything else by shape\n // is refused rather than looked up.\n if (/^[A-Za-z0-9]{10,40}$/.test(requestId)) return { kind: 'reply', requestId }\n }\n }\n return found\n}\n\nexport interface SiteCareSenderMatch {\n orgId: string\n org: Record<string, unknown>\n uid: string\n email: string\n}\n\n/** The account an address signs in with: its uid, or null when it has none. */\nexport type SiteCareAccountLookup = (email: string) => Promise<{ uid: string } | null>\n\n/**\n * Every pool, not only the project's: an owner who signs in through SSO is a\n * GCIP tenant user the project pool never returns (AGL-1122), and their mail\n * would be answered as a stranger's.\n */\nexport const findSiteCareAccount: SiteCareAccountLookup = async (email) => {\n const found = await findUserByEmailAcrossPools(email).catch(() => null)\n return found ? { uid: found.record.uid } : null\n}\n\n/**\n * The Site Care workspace a sender belongs to: the account their address\n * signs in with (in any pool), then the workspaces it is a member of, the\n * first with Site Care in force (by id, so the choice is stable).\n */\nexport async function findSiteCareWorkspaceForSender(\n firestore: FirebaseFirestore.Firestore,\n findAccount: SiteCareAccountLookup,\n sender: string,\n): Promise<SiteCareSenderMatch | null> {\n const email = emailAddressOf(sender)\n if (!email) return null\n const user = await findAccount(email).catch(() => null)\n if (!user) return null\n const memberships = await firestore.collection('users').doc(user.uid).collection('orgs').limit(25).get()\n const orgIds = memberships.docs.map((doc) => doc.id).sort()\n for (const orgId of orgIds) {\n const member = await firestore.collection('orgs').doc(orgId).collection('members').doc(user.uid).get()\n if (!member.exists) continue\n const org = await readSiteCareOrg(firestore, orgId)\n if (org && orgHasSiteCare(org)) return { orgId, org, uid: user.uid, email }\n }\n return null\n}\n\n/** The words of a message, above any quoted history. */\nexport function siteCareMessageBody(message: Pick<ReceivedEmail, 'text' | 'html'>): string {\n const plain = (message.text?.trim() ? message.text : htmlToPlainText(message.html)).replace(/\\r\\n?/g, '\\n')\n return stripQuotedHistory(plain).trim()\n}\n\nexport type SiteCareInboundOutcome =\n | { outcome: 'opened'; requestId: string }\n | { outcome: 'replied'; requestId: string }\n | { outcome: 'unknown-sender' }\n | { outcome: 'empty' }\n\n/** Files one received message addressed to the Site Care address. */\nexport async function fileSiteCareInboundEmail(\n firestore: FirebaseFirestore.Firestore,\n input: {\n target: SiteCareInboundTarget\n message: ReceivedEmail\n /** The seam a spec replaces; every auth pool by default. */\n findAccount?: SiteCareAccountLookup\n },\n deps: SiteCareDeps = {},\n): Promise<SiteCareInboundOutcome> {\n const { message } = input\n const body = siteCareMessageBody(message)\n const sender = emailAddressOf(message.from)\n if (input.target.kind === 'reply') {\n const ticket = await firestore.collection('supportTickets').doc(input.target.requestId).get()\n const orgId = String(ticket.get('orgId') ?? '')\n const match = sender ? await findSiteCareWorkspaceForSender(firestore, input.findAccount ?? findSiteCareAccount, sender) : null\n // Only a member of the request's own workspace may add to it.\n const member =\n match && orgId\n ? (await firestore.collection('orgs').doc(orgId).collection('members').doc(match.uid).get()).exists\n : false\n if (ticket.exists && member && match) {\n if (!body) return { outcome: 'empty' }\n await appendSiteCareReply(\n firestore,\n {\n ticketId: ticket.id,\n from: { uid: match.uid, email: match.email },\n body,\n dedupeKey: message.messageId || message.id,\n },\n deps,\n )\n return { outcome: 'replied', requestId: ticket.id }\n }\n // A reply that cannot join its request is read as a new one below.\n }\n const match = sender ? await findSiteCareWorkspaceForSender(firestore, input.findAccount ?? findSiteCareAccount, sender) : null\n if (!match) {\n if (sender) {\n await (deps.email ?? sendSiteCareEmail)({\n key: SITE_CARE_UNKNOWN_SENDER_EMAIL_KEY,\n to: sender,\n org: null,\n requestId: null,\n merge: { 'sender.email': sender },\n fallback: {\n subject: 'We could not match your email to an account',\n text:\n `We got your message from ${sender}, but no workspace with Site Care has that address as a member. ` +\n 'Please send it again from the email address you sign in with.',\n },\n })\n }\n return { outcome: 'unknown-sender' }\n }\n if (!body && !threadSubject(message.subject)) return { outcome: 'empty' }\n const opened = await openSiteCareRequest(\n firestore,\n {\n orgId: match.orgId,\n org: match.org,\n hostId: null,\n subject: threadSubject(message.subject) || body.split('\\n')[0].slice(0, 150) || 'A change by email',\n body: body || threadSubject(message.subject),\n requester: { uid: match.uid, email: match.email },\n source: 'email',\n dedupeKey: message.messageId || message.id,\n },\n deps,\n )\n return { outcome: 'opened', requestId: opened.ticketId }\n}\n"],"names":["emailAddressOf","htmlToPlainText","stripQuotedHistory","threadSubject","SITE_CARE_INBOUND_LOCAL_PART","SITE_CARE_UNKNOWN_SENDER_EMAIL_KEY","appendSiteCareReply","openSiteCareRequest","orgHasSiteCare","readSiteCareOrg","findUserByEmailAcrossPools","sendSiteCareEmail","siteCareInboundTarget","recipients","domain","found","value","address","raw","String","trim","written","exec","at","lastIndexOf","slice","toLowerCase","local","kind","prefix","startsWith","requestId","length","test","findSiteCareAccount","email","catch","uid","record","findSiteCareWorkspaceForSender","firestore","findAccount","sender","user","memberships","collection","doc","limit","get","orgIds","docs","map","id","sort","orgId","member","exists","org","siteCareMessageBody","message","plain","text","html","replace","fileSiteCareInboundEmail","input","deps","body","from","target","ticket","match","outcome","ticketId","dedupeKey","messageId","key","to","merge","fallback","subject","opened","hostId","split","requester","source"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,cAAc,EACdC,eAAe,EACfC,kBAAkB,EAClBC,aAAa,QACR,oCAAmC;AAC1C,SAASC,4BAA4B,QAAQ,mCAAkC;AAC/E,SACEC,kCAAkC,QAE7B,2BAA0B;AACjC,SACEC,mBAAmB,EACnBC,mBAAmB,EACnBC,cAAc,EACdC,eAAe,QAEV,0BAAsB;AAC7B,SAASC,0BAA0B,QAAQ,kBAAc;AACzD,SAASC,iBAAiB,QAAQ,wBAAoB;AAiBtD,gEAAgE,GAChE,OAAO,SAASC,sBACdC,UAA6B,EAC7BC,MAAc;IAEd,IAAIC,QAAsC;IAC1C,KAAK,MAAMC,SAASH,WAAY;;YAOb;QANjB,wEAAwE;QACxE,iEAAiE;QACjE,sEAAsE;QACtE,MAAMI,UAAUjB,eAAegB;QAC/B,IAAI,CAACC,SAAS;QACd,MAAMC,MAAMC,OAAOH,gBAAAA,QAAS,IAAII,IAAI;QACpC,MAAMC,UAAU,UAAC,QAAA,iBAAiBC,IAAI,CAACJ,yBAAtB,KAA4B,CAAC,EAAE,mBAAIA,KAAKE,IAAI;QAC7D,MAAMG,KAAKF,QAAQG,WAAW,CAAC;QAC/B,IAAID,MAAM,KAAKN,QAAQQ,KAAK,CAACR,QAAQO,WAAW,CAAC,OAAO,OAAOV,OAAOY,WAAW,IAAI;QACrF,MAAMC,QAAQN,QAAQI,KAAK,CAAC,GAAGF;QAC/B,IAAII,MAAMD,WAAW,OAAOtB,8BAA8B;YACxDW,QAAQA,gBAAAA,QAAS;gBAAEa,MAAM;YAAM;YAC/B;QACF;QACA,MAA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;QAAC;QAChDkD,QAAQ;QACRX,WAAWf,QAAQgB,SAAS,IAAIhB,QAAQP,EAAE;IAC5C,GACAc;IAEF,OAAO;QAAEM,SAAS;QAAUzC,WAAWkD,OAAOR,QAAQ;IAAC;AACzD"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/site-care-inbound.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { inboundMailDomain } from '@aglyn/aglyn/app-utils/inbound-mail-domain'\nimport {\n emailAddressOf,\n htmlToPlainText,\n stripQuotedHistory,\n threadSubject,\n} from '@aglyn/aglyn/app-utils/email-text'\nimport { SITE_CARE_INBOUND_LOCAL_PART, siteCareSupportAddress } from '@aglyn/aglyn/app-utils/site-care'\nimport { getEmailConfig, type ReceivedEmail } from '@aglyn/shared-util-email'\nimport {\n appendSiteCareReply,\n openSiteCareRequest,\n orgHasSiteCare,\n readSiteCareOrg,\n type SiteCareDeps,\n} from './site-care-requests'\nimport { findUserByEmailAcrossPools } from './auth-pools'\n\n/**\n * SITE CARE MAIL ARRIVES AT THE SUPPORT ADDRESS (AGL-3959, AGL-3997).\n *\n * Site Care has no address of its own. An owner emails the support address\n * they already know, and the support mailbox delivers a copy of each message\n * to `support@<inbound mail domain>`, where the mail provider announces it.\n * A message to either address from a member of a workspace with Site Care\n * becomes a Site Care request on that workspace, matched by the sender's\n * address against the members of workspaces that have Site Care. A reply to\n * any Site Care email goes to `support+<requestId>@…` and joins that\n * request's thread, when the sender is a member of its workspace.\n *\n * Everything else is acknowledged and left alone: nothing is filed and\n * nothing is sent back, and a message to the support address stays in the\n * support inbox as ordinary support mail. That includes the platform's own\n * mail and anything a machine sent: an out-of-office answering a Site Care\n * email would otherwise join the request, and one answering anything that\n * replies to support would open one.\n */\n\n/** What a received message was addressed to: a new request, or a reply on one. */\nexport type SiteCareInboundTarget = { kind: 'new' } | { kind: 'reply'; requestId: string }\n\n/** The addresses the intake reads as the platform's own. */\nexport interface SiteCareInboundAddresses {\n /** The inbound mail domain: `support@` and `support+<requestId>@` it. */\n domain: string\n /** The operator's support address, or null when the deployment publishes none. */\n supportEmail: string | null\n /** The address the platform sends from, `USAGE_EMAIL_FROM`'s, or null. */\n platformSender: string | null\n}\n\n/** This deployment's {@link SiteCareInboundAddresses}, read per call. */\nexport function siteCareInboundAddresses(): SiteCareInboundAddresses {\n return {\n domain: inboundMailDomain(),\n supportEmail: emailAddressOf(siteCareSupportAddress()),\n platformSender: emailAddressOf(getEmailConfig().from),\n }\n}\n\n/** The Site Care target among a message's recipients, or null. */\nexport function siteCareInboundTarget(\n recipients: readonly string[],\n addresses: Pick<SiteCareInboundAddresses, 'domain' | 'supportEmail'>,\n): SiteCareInboundTarget | null {\n const domain = addresses.domain.toLowerCase()\n const support = emailAddressOf(addresses.supportEmail)\n let found: SiteCareInboundTarget | null = null\n for (const value of recipients) {\n // Validated (and lowercased) for the comparison, but the local part is\n // read as written: a request id is a case-sensitive Firestore id, and\n // lowercasing `support+AbC…` would look up a ticket that does not exist.\n const address = emailAddressOf(value)\n if (!address) continue\n if (support && address === support) {\n found = found ?? { kind: 'new' }\n continue\n }\n const raw = String(value ?? '').trim()\n const written = (/<([^<>]+)>\\s*$/.exec(raw)?.[1] ?? raw).trim()\n const at = written.lastIndexOf('@')\n if (at <= 0 || address.slice(address.lastIndexOf('@') + 1) !== domain) continue\n const local = written.slice(0, at)\n if (local.toLowerCase() === SITE_CARE_INBOUND_LOCAL_PART) {\n found = found ?? { kind: 'new' }\n continue\n }\n const prefix = `${SITE_CARE_INBOUND_LOCAL_PART}+`\n if (local.toLowerCase().startsWith(prefix)) {\n const requestId = local.slice(prefix.length)\n // Firestore ids: 20 characters of [A-Za-z0-9]; anything else by shape\n // is refused rather than looked up.\n if (/^[A-Za-z0-9]{10,40}$/.test(requestId)) return { kind: 'reply', requestId }\n }\n }\n return found\n}\n\n/** Why a message is ignored without a lookup: the platform wrote it, or a machine did. */\nexport type SiteCareMachineMail = 'ours' | 'automatic'\n\n/**\n * Whether a message is not a person writing in: from the support address,\n * the platform's sender or any address on the inbound mail domain, or one\n * its headers say a machine sent. Null when it may be a person.\n */\nexport function siteCareMachineMail(\n message: Pick<ReceivedEmail, 'from' | 'autoSubmitted'>,\n addresses: SiteCareInboundAddresses,\n): SiteCareMachineMail | null {\n const sender = emailAddressOf(message.from)\n if (sender) {\n const own = [addresses.supportEmail, addresses.platformSender].map((value) => emailAddressOf(value))\n if (own.includes(sender)) return 'ours'\n if (sender.slice(sender.lastIndexOf('@') + 1) === addresses.domain.toLowerCase()) return 'ours'\n }\n return message.autoSubmitted ? 'automatic' : null\n}\n\nexport interface SiteCareSenderMatch {\n orgId: string\n org: Record<string, unknown>\n uid: string\n email: string\n}\n\n/** The account an address signs in with: its uid, or null when it has none. */\nexport type SiteCareAccountLookup = (email: string) => Promise<{ uid: string } | null>\n\n/**\n * Every pool, not only the project's: an owner who signs in through SSO is a\n * GCIP tenant user the project pool never returns (AGL-1122), and their mail\n * would be read as a stranger's.\n */\nexport const findSiteCareAccount: SiteCareAccountLookup = async (email) => {\n const found = await findUserByEmailAcrossPools(email).catch(() => null)\n return found ? { uid: found.record.uid } : null\n}\n\n/**\n * The Site Care workspace a sender belongs to: the account their address\n * signs in with (in any pool), then the workspaces it is a member of, the\n * first with Site Care in force (by id, so the choice is stable).\n */\nexport async function findSiteCareWorkspaceForSender(\n firestore: FirebaseFirestore.Firestore,\n findAccount: SiteCareAccountLookup,\n sender: string,\n): Promise<SiteCareSenderMatch | null> {\n const email = emailAddressOf(sender)\n if (!email) return null\n const user = await findAccount(email).catch(() => null)\n if (!user) return null\n const memberships = await firestore.collection('users').doc(user.uid).collection('orgs').limit(25).get()\n const orgIds = memberships.docs.map((doc) => doc.id).sort()\n for (const orgId of orgIds) {\n const member = await firestore.collection('orgs').doc(orgId).collection('members').doc(user.uid).get()\n if (!member.exists) continue\n const org = await readSiteCareOrg(firestore, orgId)\n if (org && orgHasSiteCare(org)) return { orgId, org, uid: user.uid, email }\n }\n return null\n}\n\n/** The words of a message, above any quoted history. */\nexport function siteCareMessageBody(message: Pick<ReceivedEmail, 'text' | 'html'>): string {\n const plain = (message.text?.trim() ? message.text : htmlToPlainText(message.html)).replace(/\\r\\n?/g, '\\n')\n return stripQuotedHistory(plain).trim()\n}\n\n/** Why a message was acknowledged and left alone. */\nexport type SiteCareIgnoredReason =\n /** No workspace with Site Care has the sender as a member: ordinary support mail. */\n | 'not-a-member'\n /** The platform's own address wrote it. */\n | 'ours'\n /** Its headers say a machine sent it. */\n | 'automatic'\n /** A member wrote, but said nothing. */\n | 'empty'\n\nexport type SiteCareInboundOutcome =\n | { outcome: 'opened'; requestId: string }\n | { outcome: 'replied'; requestId: string }\n | { outcome: 'ignored'; reason: SiteCareIgnoredReason }\n\n/**\n * Files one received message addressed to the support address or to a\n * request's reply address. Nothing is ever sent back to a sender it does\n * not file for: a message to the support address is still in the support\n * inbox, answered there like any other.\n */\nexport async function fileSiteCareInboundEmail(\n firestore: FirebaseFirestore.Firestore,\n input: {\n target: SiteCareInboundTarget\n message: ReceivedEmail\n /** The platform's own addresses; this deployment's by default. */\n addresses?: SiteCareInboundAddresses\n /** The seam a spec replaces; every auth pool by default. */\n findAccount?: SiteCareAccountLookup\n },\n deps: SiteCareDeps = {},\n): Promise<SiteCareInboundOutcome> {\n const { message } = input\n const machine = siteCareMachineMail(message, input.addresses ?? siteCareInboundAddresses())\n if (machine) return { outcome: 'ignored', reason: machine }\n const body = siteCareMessageBody(message)\n const sender = emailAddressOf(message.from)\n const findAccount = input.findAccount ?? findSiteCareAccount\n const match = sender ? await findSiteCareWorkspaceForSender(firestore, findAccount, sender) : null\n if (input.target.kind === 'reply' && match) {\n const ticket = await firestore.collection('supportTickets').doc(input.target.requestId).get()\n const orgId = String(ticket.get('orgId') ?? '')\n // Only a member of the request's own workspace may add to it.\n const member = orgId\n ? (await firestore.collection('orgs').doc(orgId).collection('members').doc(match.uid).get()).exists\n : false\n if (ticket.exists && member) {\n if (!body) return { outcome: 'ignored', reason: 'empty' }\n await appendSiteCareReply(\n firestore,\n {\n ticketId: ticket.id,\n from: { uid: match.uid, email: match.email },\n body,\n dedupeKey: message.messageId || message.id,\n },\n deps,\n )\n return { outcome: 'replied', requestId: ticket.id }\n }\n // A reply that cannot join its request is read as a new one below.\n }\n if (!match) return { outcome: 'ignored', reason: 'not-a-member' }\n if (!body && !threadSubject(message.subject)) return { outcome: 'ignored', reason: 'empty' }\n const opened = await openSiteCareRequest(\n firestore,\n {\n orgId: match.orgId,\n org: match.org,\n hostId: null,\n subject: threadSubject(message.subject) || body.split('\\n')[0].slice(0, 150) || 'A change by email',\n body: body || threadSubject(message.subject),\n requester: { uid: match.uid, email: match.email },\n source: 'email',\n dedupeKey: message.messageId || message.id,\n },\n deps,\n )\n return { outcome: 'opened', requestId: opened.ticketId }\n}\n"],"names":["inboundMailDomain","emailAddressOf","htmlToPlainText","stripQuotedHistory","threadSubject","SITE_CARE_INBOUND_LOCAL_PART","siteCareSupportAddress","getEmailConfig","appendSiteCareReply","openSiteCareRequest","orgHasSiteCare","readSiteCareOrg","findUserByEmailAcrossPools","siteCareInboundAddresses","domain","supportEmail","platformSender","from","siteCareInboundTarget","recipients","addresses","toLowerCase","support","found","value","address","kind","raw","String","trim","written","exec","at","lastIndexOf","slice","local","prefix","startsWith","requestId","length","test","siteCareMachineMail","message","sender","own","map","includes","autoSubmitted","findSiteCareAccount","email","catch","uid","record","findSiteCareWorkspaceForSender","firestore","findAccount","user","memberships","collection","doc","limit","get","orgIds","docs","id","sort","orgId","member","exists","org","siteCareMessageBody","plain","text","html","replace","fileSiteCareInboundEmail","input","deps","machine","outcome","reason","body","match","target","ticket","ticketId","dedupeKey","messageId","subject","opened","hostId","split","requester","source"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,QAAQ,6CAA4C;AAC9E,SACEC,cAAc,EACdC,eAAe,EACfC,kBAAkB,EAClBC,aAAa,QACR,oCAAmC;AAC1C,SAASC,4BAA4B,EAAEC,sBAAsB,QAAQ,mCAAkC;AACvG,SAASC,cAAc,QAA4B,2BAA0B;AAC7E,SACEC,mBAAmB,EACnBC,mBAAmB,EACnBC,cAAc,EACdC,eAAe,QAEV,0BAAsB;AAC7B,SAASC,0BAA0B,QAAQ,kBAAc;AAmCzD,uEAAuE,GACvE,OAAO,SAASC;IACd,OAAO;QACLC,QAAQd;QACRe,cAAcd,eAAeK;QAC7BU,gBAAgBf,eAAeM,iBAAiBU,IAAI;IACtD;AACF;AAEA,gEAAgE,GAChE,OAAO,SAASC,sBACdC,UAA6B,EAC7BC,SAAoE;IAEpE,MAAMN,SAASM,UAAUN,MAAM,CAACO,WAAW;IAC3C,MAAMC,UAAUrB,eAAemB,UAAUL,YAAY;IACrD,IAAIQ,QAAsC;IAC1C,KAAK,MAAMC,SAASL,WAAY;;YAWb;QAVjB,uEAAuE;QACvE,sEAAsE;QACtE,yEAAyE;QACzE,MAAMM,UAAUxB,eAAeuB;QAC/B,IAAI,CAACC,SAAS;QACd,IAAIH,WAAWG,YAAYH,SAAS;YAClCC,QAAQA,gBAAAA,QAAS;gBAAEG,MAAM;YAAM;YAC/B;QACF;QACA,MAAMC,MAAMC,OAAOJ,gBAAAA,QAAS,IAAIK,IAAI;QACpC,MAAMC,UAAU,UAAC,QAAA,iBAAiBC,IAAI,CAACJ,yBAAtB,KAA4B,CAAC,EAAE,mBAAIA,KAAKE,IAAI;QAC7D,MAAMG,KAAKF,QAAQG,WAAW,CAAC;QAC/B,IAAID,MAAM,KAAKP,QAAQS,K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IAChE,IAAI,CAACC,QAAQ,CAAC7E,cAAcsC,QAAQ8C,OAAO,GAAG,OAAO;QAAET,SAAS;QAAWC,QAAQ;IAAQ;IAC3F,MAAMS,SAAS,MAAMhF,oBACnB6C,WACA;QACEY,OAAOgB,MAAMhB,KAAK;QAClBG,KAAKa,MAAMb,GAAG;QACdqB,QAAQ;QACRF,SAASpF,cAAcsC,QAAQ8C,OAAO,KAAKP,KAAKU,KAAK,CAAC,KAAK,CAAC,EAAE,CAACzD,KAAK,CAAC,GAAG,QAAQ;QAChF+C,MAAMA,QAAQ7E,cAAcsC,QAAQ8C,OAAO;QAC3CI,WAAW;YAAEzC,KAAK+B,MAAM/B,GAAG;YAAEF,OAAOiC,MAAMjC,KAAK;QAAC;QAChD4C,QAAQ;QACRP,WAAW5C,QAAQ6C,SAAS,IAAI7C,QAAQsB,EAAE;IAC5C,GACAa;IAEF,OAAO;QAAEE,SAAS;QAAUzC,WAAWmD,OAAOJ,QAAQ;IAAC;AACzD"}
|
|
@@ -19,6 +19,12 @@ import type { DomainProbe } from './sso-drift-logic';
|
|
|
19
19
|
export declare const SSO_CHALLENGE_PREFIX = "_aglyn-challenge";
|
|
20
20
|
/** Prefix on the TXT value, so an unrelated record cannot pass by accident. */
|
|
21
21
|
export declare const SSO_TXT_PREFIX = "aglyn-domain-verification=";
|
|
22
|
+
/**
|
|
23
|
+
* Whether `domain` is a consumer mailbox provider's, shared by people who
|
|
24
|
+
* have nothing to do with each other. A proof of control means nothing there,
|
|
25
|
+
* so neither SSO nor a domain ownership claim accepts one.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isPublicEmailDomain(domain: string): boolean;
|
|
22
28
|
export declare function normalizeSsoDomain(input: string): string;
|
|
23
29
|
/**
|
|
24
30
|
* `{ value, error }` rather than a discriminated union on purpose: an
|
|
@@ -91,6 +91,13 @@ const DOMAIN_PATTERN = /^(?!-)[a-z0-9-]{1,63}(\.[a-z0-9-]{1,63})+$/;
|
|
|
91
91
|
'163.com',
|
|
92
92
|
'126.com'
|
|
93
93
|
]);
|
|
94
|
+
/**
|
|
95
|
+
* Whether `domain` is a consumer mailbox provider's, shared by people who
|
|
96
|
+
* have nothing to do with each other. A proof of control means nothing there,
|
|
97
|
+
* so neither SSO nor a domain ownership claim accepts one.
|
|
98
|
+
*/ export function isPublicEmailDomain(domain) {
|
|
99
|
+
return PUBLIC_EMAIL_DOMAINS.has(String(domain != null ? domain : '').trim().toLowerCase());
|
|
100
|
+
}
|
|
94
101
|
export function normalizeSsoDomain(input) {
|
|
95
102
|
const raw = String(input != null ? input : '').trim().toLowerCase();
|
|
96
103
|
const at = raw.lastIndexOf('@');
|