@layervai/qurl-mcp 0.4.1 → 0.6.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.
Files changed (183) hide show
  1. package/README.md +798 -50
  2. package/assets/fonts/NotoSansSC-Regular.ttf +0 -0
  3. package/assets/fonts/OFL.txt +93 -0
  4. package/assets/fonts/README.md +18 -0
  5. package/dist/auth/request-context.d.ts +13 -0
  6. package/dist/auth/request-context.d.ts.map +1 -0
  7. package/dist/auth/request-context.js +21 -0
  8. package/dist/auth/request-context.js.map +1 -0
  9. package/dist/auth/static-bearer.d.ts +12 -0
  10. package/dist/auth/static-bearer.d.ts.map +1 -0
  11. package/dist/auth/static-bearer.js +47 -0
  12. package/dist/auth/static-bearer.js.map +1 -0
  13. package/dist/client.d.ts +66 -11
  14. package/dist/client.d.ts.map +1 -1
  15. package/dist/client.js +116 -7
  16. package/dist/client.js.map +1 -1
  17. package/dist/config.d.ts +98 -0
  18. package/dist/config.d.ts.map +1 -0
  19. package/dist/config.js +543 -0
  20. package/dist/config.js.map +1 -0
  21. package/dist/credential-rate-limit-store.d.ts +38 -0
  22. package/dist/credential-rate-limit-store.d.ts.map +1 -0
  23. package/dist/credential-rate-limit-store.js +135 -0
  24. package/dist/credential-rate-limit-store.js.map +1 -0
  25. package/dist/email-addresses.d.ts +7 -0
  26. package/dist/email-addresses.d.ts.map +1 -0
  27. package/dist/email-addresses.js +36 -0
  28. package/dist/email-addresses.js.map +1 -0
  29. package/dist/email-types.d.ts +33 -0
  30. package/dist/email-types.d.ts.map +1 -0
  31. package/dist/email-types.js +28 -0
  32. package/dist/email-types.js.map +1 -0
  33. package/dist/emf-metrics.d.ts +25 -0
  34. package/dist/emf-metrics.d.ts.map +1 -0
  35. package/dist/emf-metrics.js +87 -0
  36. package/dist/emf-metrics.js.map +1 -0
  37. package/dist/http-config.d.ts +38 -0
  38. package/dist/http-config.d.ts.map +1 -0
  39. package/dist/http-config.js +243 -0
  40. package/dist/http-config.js.map +1 -0
  41. package/dist/http-routes.d.ts +5 -0
  42. package/dist/http-routes.d.ts.map +1 -0
  43. package/dist/http-routes.js +12 -0
  44. package/dist/http-routes.js.map +1 -0
  45. package/dist/http.d.ts +33 -0
  46. package/dist/http.d.ts.map +1 -0
  47. package/dist/http.js +1116 -0
  48. package/dist/http.js.map +1 -0
  49. package/dist/index.d.ts +1 -1
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +42 -26
  52. package/dist/index.js.map +1 -1
  53. package/dist/logging.d.ts +7 -0
  54. package/dist/logging.d.ts.map +1 -0
  55. package/dist/logging.js +110 -0
  56. package/dist/logging.js.map +1 -0
  57. package/dist/prompts/audit-links.js +1 -1
  58. package/dist/prompts/audit-links.js.map +1 -1
  59. package/dist/server.d.ts +14 -4
  60. package/dist/server.d.ts.map +1 -1
  61. package/dist/server.js +38 -8
  62. package/dist/server.js.map +1 -1
  63. package/dist/services/email.d.ts +17 -0
  64. package/dist/services/email.d.ts.map +1 -0
  65. package/dist/services/email.js +351 -0
  66. package/dist/services/email.js.map +1 -0
  67. package/dist/services/html.d.ts +5 -0
  68. package/dist/services/html.d.ts.map +1 -0
  69. package/dist/services/html.js +28 -0
  70. package/dist/services/html.js.map +1 -0
  71. package/dist/services/legal-pages.d.ts +12 -0
  72. package/dist/services/legal-pages.d.ts.map +1 -0
  73. package/dist/services/legal-pages.js +588 -0
  74. package/dist/services/legal-pages.js.map +1 -0
  75. package/dist/services/text-pdf.d.ts +16 -0
  76. package/dist/services/text-pdf.d.ts.map +1 -0
  77. package/dist/services/text-pdf.js +141 -0
  78. package/dist/services/text-pdf.js.map +1 -0
  79. package/dist/services/video-page.d.ts +4 -0
  80. package/dist/services/video-page.d.ts.map +1 -0
  81. package/dist/services/video-page.js +311 -0
  82. package/dist/services/video-page.js.map +1 -0
  83. package/dist/text.d.ts +4 -0
  84. package/dist/text.d.ts.map +1 -0
  85. package/dist/text.js +16 -0
  86. package/dist/text.js.map +1 -0
  87. package/dist/tools/_shared.d.ts +10 -1
  88. package/dist/tools/_shared.d.ts.map +1 -1
  89. package/dist/tools/_shared.js +25 -8
  90. package/dist/tools/_shared.js.map +1 -1
  91. package/dist/tools/batch-create.d.ts +12 -11
  92. package/dist/tools/batch-create.d.ts.map +1 -1
  93. package/dist/tools/batch-create.js +6 -4
  94. package/dist/tools/batch-create.js.map +1 -1
  95. package/dist/tools/consumer-access.d.ts +235 -0
  96. package/dist/tools/consumer-access.d.ts.map +1 -0
  97. package/dist/tools/consumer-access.js +231 -0
  98. package/dist/tools/consumer-access.js.map +1 -0
  99. package/dist/tools/create-qurl.d.ts +43 -4
  100. package/dist/tools/create-qurl.d.ts.map +1 -1
  101. package/dist/tools/create-qurl.js +69 -32
  102. package/dist/tools/create-qurl.js.map +1 -1
  103. package/dist/tools/delete-qurl.d.ts +3 -2
  104. package/dist/tools/delete-qurl.d.ts.map +1 -1
  105. package/dist/tools/delete-qurl.js +9 -13
  106. package/dist/tools/delete-qurl.js.map +1 -1
  107. package/dist/tools/duration.d.ts +13 -0
  108. package/dist/tools/duration.d.ts.map +1 -0
  109. package/dist/tools/duration.js +71 -0
  110. package/dist/tools/duration.js.map +1 -0
  111. package/dist/tools/email-delivery.d.ts +36 -0
  112. package/dist/tools/email-delivery.d.ts.map +1 -0
  113. package/dist/tools/email-delivery.js +114 -0
  114. package/dist/tools/email-delivery.js.map +1 -0
  115. package/dist/tools/extend-qurl.d.ts +20 -6
  116. package/dist/tools/extend-qurl.d.ts.map +1 -1
  117. package/dist/tools/extend-qurl.js +180 -19
  118. package/dist/tools/extend-qurl.js.map +1 -1
  119. package/dist/tools/get-qurl.d.ts +13 -5
  120. package/dist/tools/get-qurl.d.ts.map +1 -1
  121. package/dist/tools/get-qurl.js +5 -3
  122. package/dist/tools/get-qurl.js.map +1 -1
  123. package/dist/tools/list-qurl-sessions.d.ts +5 -4
  124. package/dist/tools/list-qurl-sessions.d.ts.map +1 -1
  125. package/dist/tools/list-qurl-sessions.js +2 -2
  126. package/dist/tools/list-qurl-sessions.js.map +1 -1
  127. package/dist/tools/list-qurls.d.ts +15 -7
  128. package/dist/tools/list-qurls.d.ts.map +1 -1
  129. package/dist/tools/list-qurls.js +9 -7
  130. package/dist/tools/list-qurls.js.map +1 -1
  131. package/dist/tools/mint-link.d.ts +39 -3
  132. package/dist/tools/mint-link.d.ts.map +1 -1
  133. package/dist/tools/mint-link.js +26 -14
  134. package/dist/tools/mint-link.js.map +1 -1
  135. package/dist/tools/output-schemas.d.ts +154 -45
  136. package/dist/tools/output-schemas.d.ts.map +1 -1
  137. package/dist/tools/output-schemas.js +106 -30
  138. package/dist/tools/output-schemas.js.map +1 -1
  139. package/dist/tools/resolve-qurl.d.ts +4 -3
  140. package/dist/tools/resolve-qurl.d.ts.map +1 -1
  141. package/dist/tools/resolve-qurl.js +3 -3
  142. package/dist/tools/resolve-qurl.js.map +1 -1
  143. package/dist/tools/revoke-qurl-token.d.ts +3 -2
  144. package/dist/tools/revoke-qurl-token.d.ts.map +1 -1
  145. package/dist/tools/revoke-qurl-token.js +2 -2
  146. package/dist/tools/revoke-qurl-token.js.map +1 -1
  147. package/dist/tools/share-by-crid.d.ts +50 -0
  148. package/dist/tools/share-by-crid.d.ts.map +1 -0
  149. package/dist/tools/share-by-crid.js +114 -0
  150. package/dist/tools/share-by-crid.js.map +1 -0
  151. package/dist/tools/terminate-qurl-sessions.d.ts +3 -2
  152. package/dist/tools/terminate-qurl-sessions.d.ts.map +1 -1
  153. package/dist/tools/terminate-qurl-sessions.js +7 -3
  154. package/dist/tools/terminate-qurl-sessions.js.map +1 -1
  155. package/dist/tools/update-qurl-token.d.ts +5 -4
  156. package/dist/tools/update-qurl-token.d.ts.map +1 -1
  157. package/dist/tools/update-qurl-token.js +8 -9
  158. package/dist/tools/update-qurl-token.js.map +1 -1
  159. package/dist/tools/update-qurl.d.ts +13 -5
  160. package/dist/tools/update-qurl.d.ts.map +1 -1
  161. package/dist/tools/update-qurl.js +10 -11
  162. package/dist/tools/update-qurl.js.map +1 -1
  163. package/dist/tools/upload-file-data-qurl.d.ts +138 -0
  164. package/dist/tools/upload-file-data-qurl.d.ts.map +1 -0
  165. package/dist/tools/upload-file-data-qurl.js +207 -0
  166. package/dist/tools/upload-file-data-qurl.js.map +1 -0
  167. package/dist/tools/upload-file-qurl.d.ts +134 -0
  168. package/dist/tools/upload-file-qurl.d.ts.map +1 -0
  169. package/dist/tools/upload-file-qurl.js +174 -0
  170. package/dist/tools/upload-file-qurl.js.map +1 -0
  171. package/dist/tools/upload-file-shared.d.ts +53 -0
  172. package/dist/tools/upload-file-shared.d.ts.map +1 -0
  173. package/dist/tools/upload-file-shared.js +617 -0
  174. package/dist/tools/upload-file-shared.js.map +1 -0
  175. package/dist/tools/upload-mint-options.d.ts +22 -0
  176. package/dist/tools/upload-mint-options.d.ts.map +1 -0
  177. package/dist/tools/upload-mint-options.js +47 -0
  178. package/dist/tools/upload-mint-options.js.map +1 -0
  179. package/dist/tools/upload-text-qurl.d.ts +112 -0
  180. package/dist/tools/upload-text-qurl.d.ts.map +1 -0
  181. package/dist/tools/upload-text-qurl.js +106 -0
  182. package/dist/tools/upload-text-qurl.js.map +1 -0
  183. package/package.json +26 -8
@@ -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,GAA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AAE,iDAAiD;qBACzD,CAAC,CAAC;oBACH,OAAO,CAAC,IAAI,CACV,GAAG,uBAAuB,CACxB,iBAAiB,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAClC,0DAA0D,CAC3D,CACF,CAAC;oBACF,MAAM;gBACR,CAAC;gBACD,OAAO,CAAC,KAAK,CACX,2CAA2C,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CACjF,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("&", "&amp;")
7
+ .replaceAll("<", "&lt;")
8
+ .replaceAll(">", "&gt;")
9
+ .replaceAll('"', "&quot;")
10
+ .replaceAll("'", "&#39;");
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"}