@layervai/qurl-mcp 0.4.0 → 0.5.0
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/README.md +742 -46
- package/assets/fonts/NotoSansSC-Regular.ttf +0 -0
- package/assets/fonts/OFL.txt +93 -0
- package/assets/fonts/README.md +18 -0
- package/dist/auth/request-context.d.ts +13 -0
- package/dist/auth/request-context.d.ts.map +1 -0
- package/dist/auth/request-context.js +21 -0
- package/dist/auth/request-context.js.map +1 -0
- package/dist/auth/static-bearer.d.ts +12 -0
- package/dist/auth/static-bearer.d.ts.map +1 -0
- package/dist/auth/static-bearer.js +47 -0
- package/dist/auth/static-bearer.js.map +1 -0
- package/dist/client.d.ts +112 -23
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +173 -78
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +98 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +543 -0
- package/dist/config.js.map +1 -0
- package/dist/credential-rate-limit-store.d.ts +38 -0
- package/dist/credential-rate-limit-store.d.ts.map +1 -0
- package/dist/credential-rate-limit-store.js +135 -0
- package/dist/credential-rate-limit-store.js.map +1 -0
- package/dist/email-addresses.d.ts +7 -0
- package/dist/email-addresses.d.ts.map +1 -0
- package/dist/email-addresses.js +36 -0
- package/dist/email-addresses.js.map +1 -0
- package/dist/email-types.d.ts +33 -0
- package/dist/email-types.d.ts.map +1 -0
- package/dist/email-types.js +28 -0
- package/dist/email-types.js.map +1 -0
- package/dist/emf-metrics.d.ts +25 -0
- package/dist/emf-metrics.d.ts.map +1 -0
- package/dist/emf-metrics.js +87 -0
- package/dist/emf-metrics.js.map +1 -0
- package/dist/http-config.d.ts +38 -0
- package/dist/http-config.d.ts.map +1 -0
- package/dist/http-config.js +243 -0
- package/dist/http-config.js.map +1 -0
- package/dist/http-routes.d.ts +5 -0
- package/dist/http-routes.d.ts.map +1 -0
- package/dist/http-routes.js +12 -0
- package/dist/http-routes.js.map +1 -0
- package/dist/http.d.ts +33 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +1116 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -25
- package/dist/index.js.map +1 -1
- package/dist/logging.d.ts +7 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +110 -0
- package/dist/logging.js.map +1 -0
- package/dist/prompts/secure-a-service.d.ts +16 -4
- package/dist/prompts/secure-a-service.d.ts.map +1 -1
- package/dist/prompts/secure-a-service.js +7 -15
- package/dist/prompts/secure-a-service.js.map +1 -1
- package/dist/server.d.ts +18 -6
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +41 -8
- package/dist/server.js.map +1 -1
- package/dist/services/email.d.ts +17 -0
- package/dist/services/email.d.ts.map +1 -0
- package/dist/services/email.js +351 -0
- package/dist/services/email.js.map +1 -0
- package/dist/services/html.d.ts +5 -0
- package/dist/services/html.d.ts.map +1 -0
- package/dist/services/html.js +28 -0
- package/dist/services/html.js.map +1 -0
- package/dist/services/legal-pages.d.ts +12 -0
- package/dist/services/legal-pages.d.ts.map +1 -0
- package/dist/services/legal-pages.js +588 -0
- package/dist/services/legal-pages.js.map +1 -0
- package/dist/services/text-pdf.d.ts +16 -0
- package/dist/services/text-pdf.d.ts.map +1 -0
- package/dist/services/text-pdf.js +141 -0
- package/dist/services/text-pdf.js.map +1 -0
- package/dist/services/video-page.d.ts +4 -0
- package/dist/services/video-page.d.ts.map +1 -0
- package/dist/services/video-page.js +311 -0
- package/dist/services/video-page.js.map +1 -0
- package/dist/text.d.ts +4 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +16 -0
- package/dist/text.js.map +1 -0
- package/dist/tools/_shared.d.ts +13 -3
- package/dist/tools/_shared.d.ts.map +1 -1
- package/dist/tools/_shared.js +31 -7
- package/dist/tools/_shared.js.map +1 -1
- package/dist/tools/batch-create.d.ts +36 -343
- package/dist/tools/batch-create.d.ts.map +1 -1
- package/dist/tools/batch-create.js +7 -4
- package/dist/tools/batch-create.js.map +1 -1
- package/dist/tools/create-qurl.d.ts +79 -237
- package/dist/tools/create-qurl.d.ts.map +1 -1
- package/dist/tools/create-qurl.js +77 -47
- package/dist/tools/create-qurl.js.map +1 -1
- package/dist/tools/delete-qurl.d.ts +5 -22
- package/dist/tools/delete-qurl.d.ts.map +1 -1
- package/dist/tools/delete-qurl.js +19 -13
- package/dist/tools/delete-qurl.js.map +1 -1
- package/dist/tools/email-delivery.d.ts +37 -0
- package/dist/tools/email-delivery.d.ts.map +1 -0
- package/dist/tools/email-delivery.js +115 -0
- package/dist/tools/email-delivery.js.map +1 -0
- package/dist/tools/extend-qurl.d.ts +36 -189
- package/dist/tools/extend-qurl.d.ts.map +1 -1
- package/dist/tools/extend-qurl.js +3 -3
- package/dist/tools/extend-qurl.js.map +1 -1
- package/dist/tools/get-qurl.d.ts +36 -185
- package/dist/tools/get-qurl.d.ts.map +1 -1
- package/dist/tools/get-qurl.js +8 -5
- package/dist/tools/get-qurl.js.map +1 -1
- package/dist/tools/list-qurl-sessions.d.ts +45 -0
- package/dist/tools/list-qurl-sessions.d.ts.map +1 -0
- package/dist/tools/list-qurl-sessions.js +33 -0
- package/dist/tools/list-qurl-sessions.js.map +1 -0
- package/dist/tools/list-qurls.d.ts +38 -319
- package/dist/tools/list-qurls.d.ts.map +1 -1
- package/dist/tools/list-qurls.js +45 -20
- package/dist/tools/list-qurls.js.map +1 -1
- package/dist/tools/mint-link.d.ts +72 -303
- package/dist/tools/mint-link.d.ts.map +1 -1
- package/dist/tools/mint-link.js +35 -21
- package/dist/tools/mint-link.js.map +1 -1
- package/dist/tools/output-schemas.d.ts +326 -1112
- package/dist/tools/output-schemas.d.ts.map +1 -1
- package/dist/tools/output-schemas.js +141 -40
- package/dist/tools/output-schemas.js.map +1 -1
- package/dist/tools/resolve-qurl.d.ts +6 -37
- package/dist/tools/resolve-qurl.d.ts.map +1 -1
- package/dist/tools/resolve-qurl.js +5 -5
- package/dist/tools/resolve-qurl.js.map +1 -1
- package/dist/tools/revoke-qurl-token.d.ts +41 -0
- package/dist/tools/revoke-qurl-token.d.ts.map +1 -0
- package/dist/tools/revoke-qurl-token.js +40 -0
- package/dist/tools/revoke-qurl-token.js.map +1 -0
- package/dist/tools/terminate-qurl-sessions.d.ts +41 -0
- package/dist/tools/terminate-qurl-sessions.d.ts.map +1 -0
- package/dist/tools/terminate-qurl-sessions.js +68 -0
- package/dist/tools/terminate-qurl-sessions.js.map +1 -0
- package/dist/tools/update-qurl-token.d.ts +142 -0
- package/dist/tools/update-qurl-token.d.ts.map +1 -0
- package/dist/tools/update-qurl-token.js +75 -0
- package/dist/tools/update-qurl-token.js.map +1 -0
- package/dist/tools/update-qurl.d.ts +43 -264
- package/dist/tools/update-qurl.d.ts.map +1 -1
- package/dist/tools/update-qurl.js +57 -8
- package/dist/tools/update-qurl.js.map +1 -1
- package/dist/tools/upload-file-data-qurl.d.ts +182 -0
- package/dist/tools/upload-file-data-qurl.d.ts.map +1 -0
- package/dist/tools/upload-file-data-qurl.js +200 -0
- package/dist/tools/upload-file-data-qurl.js.map +1 -0
- package/dist/tools/upload-file-qurl.d.ts +162 -0
- package/dist/tools/upload-file-qurl.d.ts.map +1 -0
- package/dist/tools/upload-file-qurl.js +167 -0
- package/dist/tools/upload-file-qurl.js.map +1 -0
- package/dist/tools/upload-file-shared.d.ts +36 -0
- package/dist/tools/upload-file-shared.d.ts.map +1 -0
- package/dist/tools/upload-file-shared.js +347 -0
- package/dist/tools/upload-file-shared.js.map +1 -0
- package/dist/tools/upload-mint-options.d.ts +22 -0
- package/dist/tools/upload-mint-options.d.ts.map +1 -0
- package/dist/tools/upload-mint-options.js +29 -0
- package/dist/tools/upload-mint-options.js.map +1 -0
- package/dist/tools/upload-text-qurl.d.ts +144 -0
- package/dist/tools/upload-text-qurl.d.ts.map +1 -0
- package/dist/tools/upload-text-qurl.js +102 -0
- package/dist/tools/upload-text-qurl.js.map +1 -0
- package/package.json +27 -8
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type SmtpConfig } from "../config.js";
|
|
2
|
+
import type { EmailDeliveryResult } from "../email-types.js";
|
|
3
|
+
export interface EmailMessageInput {
|
|
4
|
+
to: string[];
|
|
5
|
+
subject: string;
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
export interface EmailMessageOptions {
|
|
9
|
+
allowServerApiKeyFallback?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function isHttpEmailAuthorized(requestApiKey: string | undefined, operatorApiKey: string | undefined): boolean;
|
|
12
|
+
export declare function hasEmailQuotaTrackingCapacity(principalAlreadyTracked: boolean, trackedPrincipalCount: number): boolean;
|
|
13
|
+
export declare const EMAIL_DELIVERY_DEADLINE_MS = 60000;
|
|
14
|
+
export declare function formatSmtpErrorForLog(error: unknown, smtp: SmtpConfig): string;
|
|
15
|
+
export declare function clearEmailQuotaState(): void;
|
|
16
|
+
export declare function sendEmailMessage(input: EmailMessageInput, options?: EmailMessageOptions): Promise<EmailDeliveryResult>;
|
|
17
|
+
//# sourceMappingURL=email.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/services/email.ts"],"names":[],"mappings":"AAIA,OAAO,EAAyC,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAOtF,OAAO,KAAK,EAAgC,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAQ3F,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,mBAAmB;IAClC,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,cAAc,EAAE,MAAM,GAAG,SAAS,GACjC,OAAO,CAKT;AAED,wBAAgB,6BAA6B,CAC3C,uBAAuB,EAAE,OAAO,EAChC,qBAAqB,EAAE,MAAM,GAC5B,OAAO,CAET;AASD,eAAO,MAAM,0BAA0B,QAAS,CAAC;AA8BjD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAgB9E;AAED,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AA2CD,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,iBAAiB,EACxB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,mBAAmB,CAAC,CA6R9B"}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { hkdf, randomBytes, timingSafeEqual } from "node:crypto";
|
|
3
|
+
import nodemailer from "nodemailer";
|
|
4
|
+
import { getRequestQurlApiKey } from "../auth/request-context.js";
|
|
5
|
+
import { loadRuntimeConfig } from "../config.js";
|
|
6
|
+
import { isEmailAddress, normalizeEmailDomain, uniqueRecipients } from "../email-addresses.js";
|
|
7
|
+
import { EmailDeliverySetupError, MAX_EMAIL_SUBJECT_CHARACTERS, MAX_EMAIL_TEXT_CHARACTERS, } from "../email-types.js";
|
|
8
|
+
import { formatErrorForLog } from "../logging.js";
|
|
9
|
+
import { flattenControlCharacters } from "../text.js";
|
|
10
|
+
export function isHttpEmailAuthorized(requestApiKey, operatorApiKey) {
|
|
11
|
+
if (!requestApiKey || !operatorApiKey)
|
|
12
|
+
return false;
|
|
13
|
+
const supplied = Buffer.from(requestApiKey);
|
|
14
|
+
const expected = Buffer.from(operatorApiKey);
|
|
15
|
+
return supplied.length === expected.length && timingSafeEqual(supplied, expected);
|
|
16
|
+
}
|
|
17
|
+
export function hasEmailQuotaTrackingCapacity(principalAlreadyTracked, trackedPrincipalCount) {
|
|
18
|
+
return principalAlreadyTracked || trackedPrincipalCount < 10_000;
|
|
19
|
+
}
|
|
20
|
+
const emailQuotaByPrincipal = new Map();
|
|
21
|
+
// This is intentionally a fixed window. It provides a bounded, retry-proof
|
|
22
|
+
// process-local abuse guard; operators needing a strict sliding aggregate
|
|
23
|
+
// policy should enforce it at the SMTP provider or gateway across replicas.
|
|
24
|
+
const EMAIL_QUOTA_WINDOW_MS = 60 * 60 * 1000;
|
|
25
|
+
const EMAIL_QUOTA_SALT = randomBytes(16);
|
|
26
|
+
export const EMAIL_DELIVERY_DEADLINE_MS = 60_000;
|
|
27
|
+
class EmailDeliveryDeadlineError extends Error {
|
|
28
|
+
constructor() {
|
|
29
|
+
super("Aggregate email delivery deadline exceeded.");
|
|
30
|
+
this.name = "EmailDeliveryDeadlineError";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function settleBeforeDeliveryDeadline(operation, remainingMs) {
|
|
34
|
+
if (remainingMs <= 0)
|
|
35
|
+
throw new EmailDeliveryDeadlineError();
|
|
36
|
+
// Promise.race observes both branches, but keep an explicit rejection
|
|
37
|
+
// observer on the underlying Nodemailer operation as defense in depth when
|
|
38
|
+
// the deadline wins and transporter.close() settles that operation later.
|
|
39
|
+
void operation.catch(() => undefined);
|
|
40
|
+
let timeout;
|
|
41
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
42
|
+
timeout = globalThis.setTimeout(() => reject(new EmailDeliveryDeadlineError()), remainingMs);
|
|
43
|
+
timeout.unref?.();
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
return await Promise.race([operation, deadline]);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
if (timeout !== undefined)
|
|
50
|
+
globalThis.clearTimeout(timeout);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function formatSmtpErrorForLog(error, smtp) {
|
|
54
|
+
if (!(error instanceof Error))
|
|
55
|
+
return formatErrorForLog(error);
|
|
56
|
+
let message = error.message;
|
|
57
|
+
for (const credential of [smtp.username, smtp.password]) {
|
|
58
|
+
if (!credential)
|
|
59
|
+
continue;
|
|
60
|
+
for (const representation of new Set([
|
|
61
|
+
credential,
|
|
62
|
+
encodeURIComponent(credential),
|
|
63
|
+
Buffer.from(credential, "utf8").toString("base64"),
|
|
64
|
+
])) {
|
|
65
|
+
message = message.replaceAll(representation, "[REDACTED]");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const redacted = new Error(message);
|
|
69
|
+
redacted.name = error.name;
|
|
70
|
+
return formatErrorForLog(redacted);
|
|
71
|
+
}
|
|
72
|
+
export function clearEmailQuotaState() {
|
|
73
|
+
emailQuotaByPrincipal.clear();
|
|
74
|
+
}
|
|
75
|
+
function skippedRecipientResults(recipients, error) {
|
|
76
|
+
return recipients.map((email) => ({
|
|
77
|
+
email,
|
|
78
|
+
success: false,
|
|
79
|
+
skipped: true,
|
|
80
|
+
error,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
function blockedRecipientResults(recipients) {
|
|
84
|
+
return skippedRecipientResults(recipients, "Recipient is not allowed by SMTP policy.");
|
|
85
|
+
}
|
|
86
|
+
async function deriveEmailQuotaPrincipal(principalKey) {
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
// qURL API keys are high-entropy credentials, so HKDF is the appropriate
|
|
89
|
+
// low-cost one-way derivation. A password KDF such as scrypt adds latency
|
|
90
|
+
// without improving resistance to guessing attacks here.
|
|
91
|
+
hkdf("sha256", principalKey, EMAIL_QUOTA_SALT, "qurl-mcp-email-quota", 32, (error, key) => {
|
|
92
|
+
if (error) {
|
|
93
|
+
reject(error);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
resolve(Buffer.from(key).toString("hex"));
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function loadEmailRuntimeConfig() {
|
|
101
|
+
try {
|
|
102
|
+
return loadRuntimeConfig();
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
const message = error instanceof Error ? error.message : "SMTP configuration could not be loaded.";
|
|
106
|
+
throw new EmailDeliverySetupError("smtp", message, { cause: error });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export async function sendEmailMessage(input, options = {}) {
|
|
110
|
+
const runtimeConfig = loadEmailRuntimeConfig();
|
|
111
|
+
const smtp = runtimeConfig.smtp;
|
|
112
|
+
const requestApiKey = getRequestQurlApiKey();
|
|
113
|
+
if (options.allowServerApiKeyFallback === false && !requestApiKey) {
|
|
114
|
+
throw new EmailDeliverySetupError("authorization", "Request-scoped qURL credentials are unavailable for email quota tracking.");
|
|
115
|
+
}
|
|
116
|
+
if (options.allowServerApiKeyFallback === false &&
|
|
117
|
+
!isHttpEmailAuthorized(requestApiKey, runtimeConfig.qurlApiKey)) {
|
|
118
|
+
throw new EmailDeliverySetupError("authorization", "SMTP delivery is not authorized for this HTTP credential.");
|
|
119
|
+
}
|
|
120
|
+
const recipients = uniqueRecipients(input.to);
|
|
121
|
+
if (recipients.length === 0) {
|
|
122
|
+
return {
|
|
123
|
+
attempted: false,
|
|
124
|
+
enabled: smtp !== undefined,
|
|
125
|
+
recipients,
|
|
126
|
+
sent: 0,
|
|
127
|
+
failed: 0,
|
|
128
|
+
results: [],
|
|
129
|
+
skipped_reason: "No email recipients were provided.",
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (recipients.some((recipient) => recipient.length > 254 || !isEmailAddress(recipient))) {
|
|
133
|
+
throw new EmailDeliverySetupError("input", "Email recipients must be valid addresses.");
|
|
134
|
+
}
|
|
135
|
+
const subject = input.subject.trim();
|
|
136
|
+
if (!subject ||
|
|
137
|
+
subject.length > MAX_EMAIL_SUBJECT_CHARACTERS ||
|
|
138
|
+
flattenControlCharacters(subject) !== subject) {
|
|
139
|
+
throw new EmailDeliverySetupError("input", "Email subject must be a non-empty single line.");
|
|
140
|
+
}
|
|
141
|
+
// Defense at the exported service boundary; tool assembly also checks this
|
|
142
|
+
// limit so it can return a structured skipped-delivery result.
|
|
143
|
+
// Keep the same UTF-16-unit semantics as the Zod email input schemas.
|
|
144
|
+
if (input.text.length > MAX_EMAIL_TEXT_CHARACTERS) {
|
|
145
|
+
throw new EmailDeliverySetupError("input", "Email text exceeds the 10,000 character limit.");
|
|
146
|
+
}
|
|
147
|
+
if (!smtp) {
|
|
148
|
+
return {
|
|
149
|
+
attempted: false,
|
|
150
|
+
enabled: false,
|
|
151
|
+
recipients,
|
|
152
|
+
sent: 0,
|
|
153
|
+
failed: 0,
|
|
154
|
+
results: [],
|
|
155
|
+
skipped_reason: "SMTP is not configured.",
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// Revalidate sender headers at the delivery boundary as defense in depth in
|
|
159
|
+
// case callers provide a RuntimeConfig through a future non-file source.
|
|
160
|
+
if (/[\r\n]/.test(smtp.fromEmail) ||
|
|
161
|
+
smtp.fromEmail.length > 254 ||
|
|
162
|
+
!isEmailAddress(smtp.fromEmail)) {
|
|
163
|
+
throw new EmailDeliverySetupError("smtp", "SMTP fromEmail must be a valid single-line email address.");
|
|
164
|
+
}
|
|
165
|
+
if (smtp.fromName && (/[\r\n]/.test(smtp.fromName) || smtp.fromName.length > 200)) {
|
|
166
|
+
throw new EmailDeliverySetupError("smtp", "SMTP fromName must be a single line of at most 200 characters.");
|
|
167
|
+
}
|
|
168
|
+
if (recipients.length > smtp.maxRecipientsPerMessage) {
|
|
169
|
+
// Cap the complete requested fan-out before allowlist filtering. This is
|
|
170
|
+
// intentionally stricter than the hourly quota's delivered-recipient
|
|
171
|
+
// count so blocked addresses cannot be used to submit oversized batches.
|
|
172
|
+
return {
|
|
173
|
+
attempted: false,
|
|
174
|
+
enabled: true,
|
|
175
|
+
recipients,
|
|
176
|
+
sent: 0,
|
|
177
|
+
failed: recipients.length,
|
|
178
|
+
results: skippedRecipientResults(recipients, "Recipient count exceeds the configured SMTP policy limit."),
|
|
179
|
+
skipped_reason: `Recipient count exceeds the configured per-message limit of ${smtp.maxRecipientsPerMessage}.`,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const exactAllowlist = new Set(smtp.allowedRecipients ?? []);
|
|
183
|
+
const domainAllowlist = new Set((smtp.allowedRecipientDomains ?? []).map(normalizeEmailDomain));
|
|
184
|
+
const hasRecipientRestrictions = exactAllowlist.size > 0 || domainAllowlist.size > 0;
|
|
185
|
+
if (!hasRecipientRestrictions) {
|
|
186
|
+
const reason = "SMTP delivery requires at least one configured allowed recipient or recipient domain.";
|
|
187
|
+
return {
|
|
188
|
+
attempted: false,
|
|
189
|
+
enabled: true,
|
|
190
|
+
recipients,
|
|
191
|
+
sent: 0,
|
|
192
|
+
failed: recipients.length,
|
|
193
|
+
results: skippedRecipientResults(recipients, reason),
|
|
194
|
+
skipped_reason: reason,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const allowedRecipients = [];
|
|
198
|
+
const blockedRecipients = [];
|
|
199
|
+
for (const recipient of recipients) {
|
|
200
|
+
// Normalize at the enforcement boundary instead of relying on both the
|
|
201
|
+
// delivery and config call paths to preserve a hidden shared invariant.
|
|
202
|
+
// isEmailAddress above deliberately rejects quoted local parts and extra
|
|
203
|
+
// @ signs, so the final delimiter is the unambiguous domain boundary.
|
|
204
|
+
const domain = normalizeEmailDomain(recipient.slice(recipient.lastIndexOf("@") + 1));
|
|
205
|
+
const isAllowed = exactAllowlist.has(recipient) || domainAllowlist.has(domain);
|
|
206
|
+
(isAllowed ? allowedRecipients : blockedRecipients).push(recipient);
|
|
207
|
+
}
|
|
208
|
+
if (allowedRecipients.length === 0) {
|
|
209
|
+
return {
|
|
210
|
+
attempted: false,
|
|
211
|
+
enabled: true,
|
|
212
|
+
recipients,
|
|
213
|
+
sent: 0,
|
|
214
|
+
failed: blockedRecipients.length,
|
|
215
|
+
skipped_reason: "No recipient matched the configured SMTP recipient allowlist.",
|
|
216
|
+
results: blockedRecipientResults(blockedRecipients),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
// Registered tools reject a missing qURL key before reaching delivery. The
|
|
220
|
+
// fallback bucket exists only for direct service embedding/tests, where no
|
|
221
|
+
// credential principal is available and sharing one conservative quota is
|
|
222
|
+
// safer than disabling quota enforcement.
|
|
223
|
+
const principalKey = requestApiKey ?? runtimeConfig.qurlApiKey ?? "unscoped";
|
|
224
|
+
const quotaSkipResult = (skippedReason, allowedMessage) => ({
|
|
225
|
+
attempted: false,
|
|
226
|
+
enabled: true,
|
|
227
|
+
recipients,
|
|
228
|
+
sent: 0,
|
|
229
|
+
failed: recipients.length,
|
|
230
|
+
results: [
|
|
231
|
+
...blockedRecipientResults(blockedRecipients),
|
|
232
|
+
...skippedRecipientResults(allowedRecipients, allowedMessage),
|
|
233
|
+
],
|
|
234
|
+
skipped_reason: skippedReason,
|
|
235
|
+
});
|
|
236
|
+
const principal = await deriveEmailQuotaPrincipal(principalKey);
|
|
237
|
+
// Promise continuations resume one at a time on the JavaScript event loop.
|
|
238
|
+
// From this await through quota increment/map update there are no further
|
|
239
|
+
// await points, so even concurrent first requests for one principal cannot
|
|
240
|
+
// both observe and reserve the same empty quota bucket.
|
|
241
|
+
const now = Date.now();
|
|
242
|
+
for (const [key, quota] of emailQuotaByPrincipal) {
|
|
243
|
+
if (now - quota.windowStartedAt >= EMAIL_QUOTA_WINDOW_MS)
|
|
244
|
+
emailQuotaByPrincipal.delete(key);
|
|
245
|
+
}
|
|
246
|
+
if (!hasEmailQuotaTrackingCapacity(emailQuotaByPrincipal.has(principal), emailQuotaByPrincipal.size)) {
|
|
247
|
+
// Fail closed instead of evicting a live principal. LRU eviction would let
|
|
248
|
+
// an attacker cycle keys until a prior key's quota state disappears, then
|
|
249
|
+
// reuse that key to bypass the hourly recipient limit.
|
|
250
|
+
return quotaSkipResult("Email quota tracking capacity has been reached. Try again later.", "Email delivery was skipped because quota tracking is at capacity.");
|
|
251
|
+
}
|
|
252
|
+
const quota = emailQuotaByPrincipal.get(principal) ?? { recipients: 0, windowStartedAt: now };
|
|
253
|
+
if (quota.recipients + allowedRecipients.length > smtp.maxRecipientsPerHour) {
|
|
254
|
+
return quotaSkipResult(`Recipient quota exceeds the configured per-key hourly limit of ${smtp.maxRecipientsPerHour}.`, "Email delivery was skipped because the hourly quota was reached.");
|
|
255
|
+
}
|
|
256
|
+
let transporter;
|
|
257
|
+
try {
|
|
258
|
+
transporter = nodemailer.createTransport({
|
|
259
|
+
host: smtp.host,
|
|
260
|
+
port: smtp.port,
|
|
261
|
+
secure: smtp.secure,
|
|
262
|
+
// Port 587-style connections must upgrade before credentials or qURL
|
|
263
|
+
// links are sent. Implicit-TLS transports are already encrypted.
|
|
264
|
+
requireTLS: !smtp.secure,
|
|
265
|
+
tls: { minVersion: "TLSv1.2" },
|
|
266
|
+
auth: {
|
|
267
|
+
user: smtp.username,
|
|
268
|
+
pass: smtp.password,
|
|
269
|
+
},
|
|
270
|
+
connectionTimeout: 10_000,
|
|
271
|
+
greetingTimeout: 10_000,
|
|
272
|
+
socketTimeout: 30_000,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
throw new EmailDeliverySetupError("smtp", "SMTP transport could not be created.", {
|
|
277
|
+
cause: error,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
// Count attempted recipients, not only successful sends. Refunding failures
|
|
281
|
+
// would let a failing or adversarial SMTP destination bypass the abuse cap
|
|
282
|
+
// by retrying indefinitely. Construction above is synchronous, so the quota
|
|
283
|
+
// check, transport creation, and reservation still have no interleaving await.
|
|
284
|
+
emailQuotaByPrincipal.set(principal, {
|
|
285
|
+
...quota,
|
|
286
|
+
recipients: quota.recipients + allowedRecipients.length,
|
|
287
|
+
});
|
|
288
|
+
const from = smtp.fromName ? { name: smtp.fromName, address: smtp.fromEmail } : smtp.fromEmail;
|
|
289
|
+
const results = blockedRecipientResults(blockedRecipients);
|
|
290
|
+
const deliveryDeadlineAt = Date.now() + EMAIL_DELIVERY_DEADLINE_MS;
|
|
291
|
+
try {
|
|
292
|
+
// Send sequentially to apply backpressure to the SMTP server and preserve
|
|
293
|
+
// deterministic per-recipient outcomes. maxRecipientsPerMessage bounds
|
|
294
|
+
// the resulting latency; operators needing bulk throughput should use a
|
|
295
|
+
// provider-side queue rather than increasing in-process concurrency.
|
|
296
|
+
for (const [index, recipient] of allowedRecipients.entries()) {
|
|
297
|
+
try {
|
|
298
|
+
const sent = await settleBeforeDeliveryDeadline(transporter.sendMail({
|
|
299
|
+
from,
|
|
300
|
+
to: recipient,
|
|
301
|
+
subject,
|
|
302
|
+
text: input.text,
|
|
303
|
+
}), deliveryDeadlineAt - Date.now());
|
|
304
|
+
results.push({
|
|
305
|
+
email: recipient,
|
|
306
|
+
success: true,
|
|
307
|
+
skipped: false,
|
|
308
|
+
message_id: sent.messageId,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
if (error instanceof EmailDeliveryDeadlineError) {
|
|
313
|
+
results.push({
|
|
314
|
+
email: recipient,
|
|
315
|
+
success: false,
|
|
316
|
+
skipped: false,
|
|
317
|
+
error: "Email delivery exceeded the aggregate deadline.",
|
|
318
|
+
});
|
|
319
|
+
results.push(...skippedRecipientResults(allowedRecipients.slice(index + 1), "Email delivery was skipped after the aggregate deadline."));
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
console.error(`Email delivery to one recipient failed (${formatSmtpErrorForLog(error, smtp)})`);
|
|
323
|
+
results.push({
|
|
324
|
+
email: recipient,
|
|
325
|
+
success: false,
|
|
326
|
+
skipped: false,
|
|
327
|
+
error: "Email delivery failed.",
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
finally {
|
|
333
|
+
try {
|
|
334
|
+
transporter.close();
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
// Transport cleanup must never replace the delivery outcome.
|
|
338
|
+
console.error(`SMTP transport cleanup failed (${formatSmtpErrorForLog(error, smtp)})`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const sentCount = results.filter((result) => result.success).length;
|
|
342
|
+
return {
|
|
343
|
+
attempted: true,
|
|
344
|
+
enabled: true,
|
|
345
|
+
recipients,
|
|
346
|
+
sent: sentCount,
|
|
347
|
+
failed: results.length - sentCount,
|
|
348
|
+
results,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
//# sourceMappingURL=email.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.js","sourceRoot":"","sources":["../../src/services/email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAuC,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC/F,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAgBtD,MAAM,UAAU,qBAAqB,CACnC,aAAiC,EACjC,cAAkC;IAElC,IAAI,CAAC,aAAa,IAAI,CAAC,cAAc;QAAE,OAAO,KAAK,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC7C,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,IAAI,eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACpF,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,uBAAgC,E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,CAAC;gBACF,OAAO,CAAC,IAAI,CAAC;oBACX,KAAK,EAAE,SAAS;oBAChB,OAAO,EAAE,KAAK;oBACd,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,wBAAwB;iBAChC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,WAAW,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,6DAA6D;YAC7D,OAAO,CAAC,KAAK,CAAC,kCAAkC,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACzF,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IACpE,OAAO;QACL,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,IAAI;QACb,UAAU;QACV,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,SAAS;QAClC,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const REFERENCE_SITE_URL = "https://layerv.ai";
|
|
2
|
+
export declare function escapeHtml(value: string): string;
|
|
3
|
+
/** Validate an HTTP(S) URL before escaping it for a quoted HTML attribute. */
|
|
4
|
+
export declare function escapeHttpUrlAttribute(value: string): string;
|
|
5
|
+
//# sourceMappingURL=html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/services/html.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,sBAAsB,CAAC;AAItD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOhD;AAED,8EAA8E;AAC9E,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAe5D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const REFERENCE_SITE_URL = "https://layerv.ai";
|
|
2
|
+
// Safe for HTML text and quoted attribute values only. Do not reuse this for
|
|
3
|
+
// unquoted attributes, URL policy, JavaScript, or CSS contexts.
|
|
4
|
+
export function escapeHtml(value) {
|
|
5
|
+
return value
|
|
6
|
+
.replaceAll("&", "&")
|
|
7
|
+
.replaceAll("<", "<")
|
|
8
|
+
.replaceAll(">", ">")
|
|
9
|
+
.replaceAll('"', """)
|
|
10
|
+
.replaceAll("'", "'");
|
|
11
|
+
}
|
|
12
|
+
/** Validate an HTTP(S) URL before escaping it for a quoted HTML attribute. */
|
|
13
|
+
export function escapeHttpUrlAttribute(value) {
|
|
14
|
+
let url;
|
|
15
|
+
try {
|
|
16
|
+
url = new URL(value);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new Error("HTML URL attributes must contain an absolute HTTP(S) URL.");
|
|
20
|
+
}
|
|
21
|
+
if ((url.protocol !== "http:" && url.protocol !== "https:") ||
|
|
22
|
+
url.username !== "" ||
|
|
23
|
+
url.password !== "") {
|
|
24
|
+
throw new Error("HTML URL attributes must contain an absolute HTTP(S) URL.");
|
|
25
|
+
}
|
|
26
|
+
return escapeHtml(url.toString());
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/services/html.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AAEtD,6EAA6E;AAC7E,gEAAgE;AAChE,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,KAAK;SACT,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;SACxB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC;SACzB,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,sBAAsB,CAAC,KAAa;IAClD,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;IACD,IACE,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;QACvD,GAAG,CAAC,QAAQ,KAAK,EAAE;QACnB,GAAG,CAAC,QAAQ,KAAK,EAAE,EACnB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type LegalDocument = {
|
|
2
|
+
description: string;
|
|
3
|
+
path: string;
|
|
4
|
+
title: string;
|
|
5
|
+
markdown: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function renderMarkdownToHtml(markdown: string): string;
|
|
8
|
+
export declare function getLegalDocuments(): LegalDocument[];
|
|
9
|
+
export declare function findLegalDocument(pathname: string): LegalDocument | undefined;
|
|
10
|
+
export declare function renderLegalDocumentHtml(pathname: string, baseUrl: string): string | undefined;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=legal-pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legal-pages.d.ts","sourceRoot":"","sources":["../../src/services/legal-pages.ts"],"names":[],"mappings":"AAGA,KAAK,aAAa,GAAG;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAsLF,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CA8D7D;AAsVD,wBAAgB,iBAAiB,IAAI,aAAa,EAAE,CAEnD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE7E;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI7F"}
|