@fabrika/email 0.9.0-dev.5 → 0.9.0-dev.50

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/email",
3
- "version": "0.9.0-dev.5",
3
+ "version": "0.9.0-dev.50",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,6 +36,11 @@
36
36
  "types": "./types/src/ahasend.d.ts",
37
37
  "default": "./src/ahasend.ts"
38
38
  },
39
+ "./brevo": {
40
+ "bun": "./src/brevo.ts",
41
+ "types": "./types/src/brevo.d.ts",
42
+ "default": "./src/brevo.ts"
43
+ },
39
44
  "./cloudflare": {
40
45
  "bun": "./src/cloudflare.ts",
41
46
  "types": "./types/src/cloudflare.d.ts",
@@ -78,7 +83,7 @@
78
83
  }
79
84
  },
80
85
  "scripts": {
81
- "typecheck": "tsc --noEmit",
86
+ "typecheck": "tsrs --build tsconfig.test.json",
82
87
  "test": "bun test src/__tests__"
83
88
  },
84
89
  "dependencies": {
package/src/brevo.ts ADDED
@@ -0,0 +1,158 @@
1
+ // Brevo's transactional email API (https://developers.brevo.com/reference/sendtransacemail), built from its
2
+ // documentation in November 2026 and checked only against a stubbed fetch (backlog 290). A 201 carries the message id.
3
+ // Brevo dedupes a repeated `idempotencyKey` for 30 minutes only, while a relay or an outbox retries for hours, so the
4
+ // adapter sends the key but does not report itself idempotent: an unknown outcome over Brevo waits for a person.
5
+
6
+ import { z } from 'zod'
7
+ import { type EmailProvider, parseProviderVariables } from './config.js'
8
+ import { base64Of } from './content.js'
9
+ import { EmailDeliveryError, type EmailMessage, type EmailSenderCapabilities } from './email.js'
10
+ import { credentialVariable, type HttpEmailRequest, HttpEmailSender, type HttpEmailSenderOptions, isCredential } from './http-sender.js'
11
+ import type { ProviderResponse } from './http.js'
12
+
13
+ const BREVO_SEND_URL = 'https://api.brevo.com/v3/smtp/email'
14
+ const brevoSuccessSchema = z.object({ messageId: z.string() })
15
+ /** A refusal's `code` is one of a documented set; its `message` is free text and is never read. */
16
+ const brevoErrorSchema = z.object({ code: z.string() })
17
+ /** Brevo bounds a sender's or a recipient's display name at 70 characters; the contract allows 128. */
18
+ const BREVO_MAX_NAME_LENGTH = 70
19
+ /**
20
+ * Brevo bounds a transactional message at 20 MB with its attachments base64; 10 MiB of bytes leaves room for the
21
+ * bodies. Its help center also mentions 4 MB per file, which is not enforced here (backlog 290).
22
+ */
23
+ const BREVO_MAX_ATTACHMENT_BYTES = 10 * 1024 * 1024
24
+ /**
25
+ * The extensions Brevo takes an attachment with, from its API reference. It takes no media type: it derives it from the
26
+ * file name, so the adapter refuses any other file before the request instead of losing the message to a 400.
27
+ */
28
+ const BREVO_ATTACHMENT_EXTENSIONS: readonly string[] = (
29
+ 'xlsx xls ods docx docm doc csv pdf txt gif jpg jpeg png tif tiff rtf bmp cgm css shtml html htm zip xml ppt pptx tar ez ics mobi msg pub '
30
+ + 'eps odt mp3 m4a m4v wma ogg flac wav aif aifc aiff mp4 mov avi mkv mpeg mpg wmv pkpass xlsm'
31
+ ).split(' ')
32
+ /**
33
+ * A repeated idempotency key (`duplicate_parameter`), an identical request too soon (`duplicate_request`), or a request
34
+ * the reference's error codes call already processed: each says an earlier request may have sent the message.
35
+ */
36
+ const DUPLICATE_CODES: ReadonlySet<string> = new Set(['duplicate_parameter', 'duplicate_request', 'Request already processed'])
37
+ /** The account has no credits left (402 `not_enough_credits`; the reference also lists `Insufficient credits`). */
38
+ const NO_CREDITS_CODES: ReadonlySet<string> = new Set(['not_enough_credits', 'Insufficient credits'])
39
+ /**
40
+ * The key or the account may not send: a failed authentication, an unknown key, a missing permission, an account still
41
+ * validated. The reference lists `Authentication failed` and `api-key not found` beside the snake_case codes.
42
+ */
43
+ const NOT_ALLOWED_CODES: ReadonlySet<string> = new Set([
44
+ 'unauthorized',
45
+ 'Authentication failed',
46
+ 'api-key not found',
47
+ 'permission_denied',
48
+ 'account_under_validation',
49
+ ])
50
+
51
+ export interface BrevoEmailSenderOptions extends HttpEmailSenderOptions {
52
+ /** An API key (v3) of the account. */
53
+ readonly apiKey: string
54
+ }
55
+
56
+ export class BrevoEmailSender extends HttpEmailSender {
57
+ readonly capabilities: EmailSenderCapabilities = {
58
+ // Brevo keeps a key for 30 minutes, shorter than any retry horizon here, so a late retry could deliver twice.
59
+ idempotent: false,
60
+ confirmation: 'sync',
61
+ maxBatch: 1,
62
+ maxAttachmentBytes: BREVO_MAX_ATTACHMENT_BYTES,
63
+ attachmentExtensions: BREVO_ATTACHMENT_EXTENSIONS,
64
+ // No `listUnsubscribe`, and so no `broadcast`: Brevo takes no standard header in `headers`, so `List-Unsubscribe`
65
+ // is not known to reach the recipient.
66
+ }
67
+ readonly #apiKey: string
68
+
69
+ constructor(options: BrevoEmailSenderOptions) {
70
+ if (!isCredential(options.apiKey)) {
71
+ throw new EmailDeliveryError('Brevo API key is invalid', { code: 'invalid_configuration' })
72
+ }
73
+ if (options.from.name !== undefined && options.from.name.length > BREVO_MAX_NAME_LENGTH) {
74
+ throw new EmailDeliveryError(`Brevo sender name is longer than ${BREVO_MAX_NAME_LENGTH} characters`, { code: 'invalid_configuration' })
75
+ }
76
+ super({ label: 'Brevo', provider: 'brevo' }, options)
77
+ this.#apiKey = options.apiKey
78
+ }
79
+
80
+ protected async request(message: EmailMessage): Promise<HttpEmailRequest> {
81
+ const name = message.fromName ?? this.from.name
82
+ if (name !== undefined && name.length > BREVO_MAX_NAME_LENGTH) {
83
+ throw new EmailDeliveryError(`Brevo sends no sender name longer than ${BREVO_MAX_NAME_LENGTH} characters`, { code: 'invalid_message' })
84
+ }
85
+ const attachments = message.attachments ?? []
86
+ return {
87
+ url: BREVO_SEND_URL,
88
+ headers: { 'api-key': this.#apiKey, Accept: 'application/json' },
89
+ body: {
90
+ sender: { email: this.from.address, ...(name === undefined ? {} : { name }) },
91
+ to: [{ email: message.to }],
92
+ subject: message.subject,
93
+ // Brevo requires an HTML body without a template; a message without one, or with a blank one, gets its text
94
+ // as HTML, so the recipient never sees an empty message.
95
+ htmlContent: message.html === undefined || message.html.trim() === '' ? brevoHtmlOfText(message.text) : message.html,
96
+ textContent: message.text,
97
+ ...(message.replyTo === undefined ? {} : { replyTo: { email: message.replyTo } }),
98
+ headers: { idempotencyKey: await brevoIdempotencyKey(message.idempotencyKey) },
99
+ ...(attachments.length === 0
100
+ ? {}
101
+ : { attachment: attachments.map((attachment) => ({ name: attachment.filename, content: base64Of(attachment.content) })) }),
102
+ },
103
+ }
104
+ }
105
+
106
+ protected messageId(response: ProviderResponse): string | undefined {
107
+ return brevoSuccessSchema.safeParse(response.body).data?.messageId
108
+ }
109
+
110
+ protected override refusal(response: ProviderResponse): EmailDeliveryError | undefined {
111
+ const status = response.status
112
+ const code = brevoErrorSchema.safeParse(response.body).data?.code
113
+ if (status === 402 || (code !== undefined && NO_CREDITS_CODES.has(code))) {
114
+ return new EmailDeliveryError(`Brevo account has no credits left (${status})`, { code: 'quota_exceeded', httpStatus: status })
115
+ }
116
+ // A 429 or a 5xx keeps the meaning of its status whatever its code.
117
+ if (code === undefined || status >= 500 || status === 429) return undefined
118
+ if (DUPLICATE_CODES.has(code)) {
119
+ // Brevo took a request under this key, or an identical one, and does not say whether its content matched.
120
+ return new EmailDeliveryError(`Brevo already took a request under this idempotency key (${status})`, {
121
+ code: 'idempotency_conflict',
122
+ httpStatus: status,
123
+ })
124
+ }
125
+ if (NOT_ALLOWED_CODES.has(code)) {
126
+ return new EmailDeliveryError(`Brevo refused the key or the account (${status})`, { code: 'provider_unauthorized', httpStatus: status })
127
+ }
128
+ return undefined
129
+ }
130
+ }
131
+
132
+ /**
133
+ * The message's key as Brevo takes it, a UUID: the first 16 bytes of its SHA-256 with the version 4 and variant bits
134
+ * set. One key is always one UUID, so a retry sends the same one; Brevo recommends a version 4 UUID.
135
+ */
136
+ async function brevoIdempotencyKey(key: string): Promise<string> {
137
+ const bytes = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(key))).slice(0, 16)
138
+ bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40
139
+ bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80
140
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('')
141
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
142
+ }
143
+
144
+ /** A plain text as the HTML body Brevo requires: every character escaped, each line break a `<br>`. */
145
+ export function brevoHtmlOfText(text: string): string {
146
+ const escaped = text.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#39;')
147
+ return escaped.replace(/\r\n|\r|\n/g, '<br>\n')
148
+ }
149
+
150
+ const brevoVariablesSchema = z.object({ FABRIKA_EMAIL_BREVO_API_KEY: credentialVariable })
151
+
152
+ export const brevoEmailProvider: EmailProvider = {
153
+ variables: [{ name: 'FABRIKA_EMAIL_BREVO_API_KEY', secret: true, required: true }],
154
+ create({ from, env, fetch }) {
155
+ const variables = parseProviderVariables(brevoVariablesSchema, env)
156
+ return new BrevoEmailSender({ apiKey: variables.FABRIKA_EMAIL_BREVO_API_KEY, from, fetch })
157
+ },
158
+ }
@@ -280,6 +280,20 @@ function describeHttpSender(harness: EmailSenderHttpHarness): void {
280
280
  expect(current.requests).toHaveLength(0)
281
281
  })
282
282
 
283
+ test('refuses an attachment of a file type outside the ones it says it sends, without a request', async () => {
284
+ const current = httpCase(async (request) => harness.answers.accepted(request))
285
+ const allowed = current.sender.capabilities.attachmentExtensions
286
+ if (allowed === undefined || current.sender.capabilities.maxAttachmentBytes === undefined) return
287
+ const extension = ['json', 'svg', 'webp', 'bin'].find((candidate) => !allowed.includes(candidate))
288
+ if (extension === undefined) throw new Error('every probe extension is allowed: pick another')
289
+ const message: EmailMessage = {
290
+ ...ATTACHMENT_MESSAGE,
291
+ attachments: [{ filename: `report.${extension}`, contentType: 'application/octet-stream', content: ONE_BYTE }],
292
+ }
293
+ await expectRejection(() => current.sender.send(message, new AbortController().signal), 'invalid_message', () => MESSAGE_MARKERS)
294
+ expect(current.requests).toHaveLength(0)
295
+ })
296
+
283
297
  test('refuses a body shorter than it says it sends, counted in characters once trimmed, without a request', async () => {
284
298
  const current = httpCase(async (request) => harness.answers.accepted(request))
285
299
  const min = current.sender.capabilities.minBodyLength
package/src/email.ts CHANGED
@@ -55,6 +55,8 @@ export interface EmailSenderCapabilities {
55
55
  readonly maxAttachmentBytes?: number
56
56
  /** File extensions it refuses an attachment for, lowercase and without the dot; absent: none. */
57
57
  readonly refusedAttachmentExtensions?: readonly string[]
58
+ /** The only file extensions it sends an attachment with, lowercase and without the dot; absent: any. */
59
+ readonly attachmentExtensions?: readonly string[]
58
60
  /** The fewest characters a text or HTML body has once trimmed; absent: any body that is not blank. */
59
61
  readonly minBodyLength?: number
60
62
  /** Whether it sends a `broadcast` message, on its provider's channel for them where it has one; absent is no. */
package/src/http.ts CHANGED
@@ -1,5 +1,5 @@
1
- // The request half both HTTP adapters share: the caller's signal, the adapter's own timeout, and how a thrown fetch
2
- // is classified. Messages name the provider and nothing the request carried.
1
+ // The request half both HTTP adapters share: the caller's signal, the adapter's own timeout, how a thrown fetch is
2
+ // classified, and a redirect that is never followed. Messages name the provider and nothing the request carried.
3
3
 
4
4
  import { EmailDeliveryError, type EmailFetch } from './email.js'
5
5
 
@@ -21,7 +21,10 @@ export interface ProviderResponse {
21
21
  readonly body: unknown
22
22
  }
23
23
 
24
- /** The answer with its body already read, so an abort or a timeout while the body arrives is classified as one. */
24
+ /**
25
+ * The answer with its body already read, so an abort or a timeout while the body arrives is classified as one. A redirect
26
+ * is never followed: a followed one would send the credential headers and the message to wherever it points.
27
+ */
25
28
  export async function postToProvider(request: ProviderRequest): Promise<ProviderResponse> {
26
29
  if (request.signal.aborted) throw abortedError(request.label)
27
30
  const timeout = AbortSignal.timeout(request.timeoutMs)
@@ -32,16 +35,39 @@ export async function postToProvider(request: ProviderRequest): Promise<Provider
32
35
  headers: { ...request.headers, 'Content-Type': 'application/json' },
33
36
  signal,
34
37
  body: JSON.stringify(request.body),
38
+ redirect: 'manual',
35
39
  })
40
+ if (isRedirect(response)) {
41
+ void response.body?.cancel().catch(() => undefined)
42
+ throw redirectError(request.label, response.status)
43
+ }
36
44
  const text = await untilAborted(response.text(), signal)
37
45
  return { ok: response.ok, status: response.status, body: parseJson(text) }
38
- } catch {
46
+ } catch (error) {
47
+ if (error instanceof EmailDeliveryError) throw error
39
48
  if (request.signal.aborted) throw abortedError(request.label)
40
49
  if (timeout.aborted) throw new EmailDeliveryError(`${request.label} request timed out`, { code: 'request_timeout' })
41
50
  throw new EmailDeliveryError(`${request.label} request failed`, { code: 'network_error' })
42
51
  }
43
52
  }
44
53
 
54
+ /**
55
+ * A 3xx, or the opaque answer a browser-like runtime gives for one under `redirect: 'manual'`. The endpoint answered
56
+ * without taking the message, and the same request gets the same answer, so it is a permanent `provider_rejected`: the
57
+ * configured URL is not the provider's API, and a person fixes it.
58
+ */
59
+ function isRedirect(response: Response): boolean {
60
+ return response.type === 'opaqueredirect' || (response.status >= 300 && response.status < 400)
61
+ }
62
+
63
+ function redirectError(label: string, status: number): EmailDeliveryError {
64
+ const shown = status === 0 ? '' : ` (HTTP ${status})`
65
+ return new EmailDeliveryError(`${label} answered with a redirect${shown}, which is not followed`, {
66
+ code: 'provider_rejected',
67
+ ...(status === 0 ? {} : { httpStatus: status }),
68
+ })
69
+ }
70
+
45
71
  export function parseTimeout(label: string, value: number | undefined): number {
46
72
  const timeoutMs = value ?? 10_000
47
73
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 120_000) {
package/src/platform.ts CHANGED
@@ -7,7 +7,13 @@ import {
7
7
  type EmailSenderCapabilities,
8
8
  } from './email.js'
9
9
  import { parseTimeout, postToProvider } from './http.js'
10
- import { encodePlatformMailRequest, parsePlatformMailAnswer, PLATFORM_MAIL_CAPABILITIES, PLATFORM_MAIL_SEND_PATH } from './platform-wire.js'
10
+ import {
11
+ encodePlatformMailRequest,
12
+ installationMailKey,
13
+ parsePlatformMailAnswer,
14
+ PLATFORM_MAIL_CAPABILITIES,
15
+ PLATFORM_MAIL_SEND_PATH,
16
+ } from './platform-wire.js'
11
17
  import { isVisibleAscii, validateEmailAttachments, validateEmailBroadcast, validateEmailMessage } from './validation.js'
12
18
 
13
19
  export {
@@ -99,8 +105,48 @@ export class PlatformEmailSender implements EmailSender {
99
105
  }
100
106
  }
101
107
 
102
- /** `http(s)://host[:port]` exactly as written: no path, query, fragment or credentials. */
103
- function isHttpOrigin(value: string): boolean {
108
+ export interface InstallationMailSenderOptions {
109
+ /** Control's http(s) origin; the send path is appended to it. */
110
+ readonly url: string
111
+ /** The secret the service shares with Control, which its key derives from (`installationMailKey`). */
112
+ readonly secret: string
113
+ readonly fetch?: EmailFetch
114
+ readonly timeoutMs?: number
115
+ }
116
+
117
+ /**
118
+ * An installation service's sender to Control's relay: a `PlatformEmailSender` under `installationMailKey(secret)`,
119
+ * built at the first send because deriving the key is asynchronous. A send that cannot build it (a URL that is not an
120
+ * origin, a secret that is not usable) throws and keeps nothing, so the next send builds it again.
121
+ */
122
+ export function installationMailSender(options: InstallationMailSenderOptions): EmailSender {
123
+ let sender: Promise<PlatformEmailSender> | undefined
124
+ return {
125
+ capabilities: PLATFORM_MAIL_CAPABILITIES,
126
+ async send(message, signal) {
127
+ const pending = sender ??= installationMailKey(options.secret).then((key) =>
128
+ new PlatformEmailSender({
129
+ url: options.url,
130
+ key,
131
+ ...(options.fetch === undefined ? {} : { fetch: options.fetch }),
132
+ ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
133
+ })
134
+ )
135
+ const ready = await pending.catch((error: unknown) => {
136
+ // Only the build that failed is dropped; a send that started a newer one keeps it.
137
+ if (sender === pending) sender = undefined
138
+ throw error
139
+ })
140
+ return ready.send(message, signal)
141
+ },
142
+ }
143
+ }
144
+
145
+ /**
146
+ * `http(s)://host[:port]` exactly as written: no path, query, fragment or credentials. The one check of a relay's origin,
147
+ * for the sender, IAM's boot and IAM's Cloudflare deploy (which also requires `https:`).
148
+ */
149
+ export function isHttpOrigin(value: string): boolean {
104
150
  try {
105
151
  const url = new URL(value)
106
152
  return (url.protocol === 'http:' || url.protocol === 'https:') && url.origin === value
package/src/providers.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ahaSendEmailProvider } from './ahasend.js'
2
+ import { brevoEmailProvider } from './brevo.js'
2
3
  import { cloudflareEmailProvider } from './cloudflare.js'
3
4
  import type { EmailProviderRegistry, EmailProviderVariable } from './config.js'
4
5
  import { lettermintEmailProvider } from './lettermint.js'
@@ -12,6 +13,7 @@ import { smartEmailingEmailProvider } from './smartemailing.js'
12
13
  */
13
14
  export const builtinEmailProviders = {
14
15
  ahasend: ahaSendEmailProvider,
16
+ brevo: brevoEmailProvider,
15
17
  cloudflare: cloudflareEmailProvider,
16
18
  lettermint: lettermintEmailProvider,
17
19
  postmark: postmarkEmailProvider,
@@ -32,6 +34,7 @@ export const builtinEmailProviderVariables: readonly EmailProviderVariable[] = O
32
34
  */
33
35
  export const builtinEmailProviderSince = {
34
36
  ahasend: '0.8.2',
37
+ brevo: '0.9.0-dev.17',
35
38
  cloudflare: '0.9.0',
36
39
  lettermint: '0.8.2',
37
40
  postmark: '0.8.2',
package/src/validation.ts CHANGED
@@ -75,8 +75,8 @@ export function validateEmailMessage(message: EmailMessage): void {
75
75
 
76
76
  /**
77
77
  * Refuses a message whose attachments `capabilities` does not carry: any attachment where the transport sends none,
78
- * more bytes together than its `maxAttachmentBytes`, or a file whose extension it refuses. `label` names the transport
79
- * in the message.
78
+ * more bytes together than its `maxAttachmentBytes`, or a file whose extension it refuses or does not list in
79
+ * `attachmentExtensions`. `label` names the transport in the message.
80
80
  */
81
81
  export function validateEmailAttachments(message: EmailMessage, capabilities: EmailSenderCapabilities, label: string): void {
82
82
  const attachments = message.attachments ?? []
@@ -86,9 +86,12 @@ export function validateEmailAttachments(message: EmailMessage, capabilities: Em
86
86
  const bytes = attachmentBytes(message)
87
87
  if (bytes > limit) throw invalidMessage(`Email attachments have ${bytes} bytes, more than the ${limit} ${label} sends`)
88
88
  const refused = capabilities.refusedAttachmentExtensions ?? []
89
- if (refused.length > 0 && attachments.some((attachment) => refused.includes(extensionOf(attachment.filename)))) {
90
- throw invalidMessage(`${label} sends no attachment of this file type`)
89
+ const allowed = capabilities.attachmentExtensions
90
+ const refusedType = (filename: string): boolean => {
91
+ const extension = extensionOf(filename)
92
+ return refused.includes(extension) || (allowed !== undefined && !allowed.includes(extension))
91
93
  }
94
+ if (attachments.some((attachment) => refusedType(attachment.filename))) throw invalidMessage(`${label} sends no attachment of this file type`)
92
95
  }
93
96
 
94
97
  /** Refuses a `broadcast` message where the transport sends none. */
@@ -107,7 +110,7 @@ export function validateEmailBodies(message: EmailMessage, capabilities: EmailSe
107
110
  }
108
111
 
109
112
  /** The extension after the last dot, lowercase; empty without one. */
110
- function extensionOf(filename: string): string {
113
+ export function extensionOf(filename: string): string {
111
114
  const dot = filename.lastIndexOf('.')
112
115
  return dot < 0 ? '' : filename.slice(dot + 1).toLowerCase()
113
116
  }
@@ -0,0 +1,19 @@
1
+ import { type EmailProvider } from './config.js';
2
+ import { EmailDeliveryError, type EmailMessage, type EmailSenderCapabilities } from './email.js';
3
+ import { type HttpEmailRequest, HttpEmailSender, type HttpEmailSenderOptions } from './http-sender.js';
4
+ import type { ProviderResponse } from './http.js';
5
+ export interface BrevoEmailSenderOptions extends HttpEmailSenderOptions {
6
+ /** An API key (v3) of the account. */
7
+ readonly apiKey: string;
8
+ }
9
+ export declare class BrevoEmailSender extends HttpEmailSender {
10
+ #private;
11
+ readonly capabilities: EmailSenderCapabilities;
12
+ constructor(options: BrevoEmailSenderOptions);
13
+ protected request(message: EmailMessage): Promise<HttpEmailRequest>;
14
+ protected messageId(response: ProviderResponse): string | undefined;
15
+ protected refusal(response: ProviderResponse): EmailDeliveryError | undefined;
16
+ }
17
+ /** A plain text as the HTML body Brevo requires: every character escaped, each line break a `<br>`. */
18
+ export declare function brevoHtmlOfText(text: string): string;
19
+ export declare const brevoEmailProvider: EmailProvider;
@@ -51,6 +51,8 @@ export interface EmailSenderCapabilities {
51
51
  readonly maxAttachmentBytes?: number;
52
52
  /** File extensions it refuses an attachment for, lowercase and without the dot; absent: none. */
53
53
  readonly refusedAttachmentExtensions?: readonly string[];
54
+ /** The only file extensions it sends an attachment with, lowercase and without the dot; absent: any. */
55
+ readonly attachmentExtensions?: readonly string[];
54
56
  /** The fewest characters a text or HTML body has once trimmed; absent: any body that is not blank. */
55
57
  readonly minBodyLength?: number;
56
58
  /** Whether it sends a `broadcast` message, on its provider's channel for them where it has one; absent is no. */
@@ -15,6 +15,9 @@ export interface ProviderResponse {
15
15
  /** The parsed JSON body, or undefined when it is not JSON. Never put into an error. */
16
16
  readonly body: unknown;
17
17
  }
18
- /** The answer with its body already read, so an abort or a timeout while the body arrives is classified as one. */
18
+ /**
19
+ * The answer with its body already read, so an abort or a timeout while the body arrives is classified as one. A redirect
20
+ * is never followed: a followed one would send the credential headers and the message to wherever it points.
21
+ */
19
22
  export declare function postToProvider(request: ProviderRequest): Promise<ProviderResponse>;
20
23
  export declare function parseTimeout(label: string, value: number | undefined): number;
@@ -17,3 +17,22 @@ export declare class PlatformEmailSender implements EmailSender {
17
17
  constructor(options: PlatformEmailSenderOptions);
18
18
  send(message: EmailMessage, signal: AbortSignal): Promise<EmailDeliveryResult>;
19
19
  }
20
+ export interface InstallationMailSenderOptions {
21
+ /** Control's http(s) origin; the send path is appended to it. */
22
+ readonly url: string;
23
+ /** The secret the service shares with Control, which its key derives from (`installationMailKey`). */
24
+ readonly secret: string;
25
+ readonly fetch?: EmailFetch;
26
+ readonly timeoutMs?: number;
27
+ }
28
+ /**
29
+ * An installation service's sender to Control's relay: a `PlatformEmailSender` under `installationMailKey(secret)`,
30
+ * built at the first send because deriving the key is asynchronous. A send that cannot build it (a URL that is not an
31
+ * origin, a secret that is not usable) throws and keeps nothing, so the next send builds it again.
32
+ */
33
+ export declare function installationMailSender(options: InstallationMailSenderOptions): EmailSender;
34
+ /**
35
+ * `http(s)://host[:port]` exactly as written: no path, query, fragment or credentials. The one check of a relay's origin,
36
+ * for the sender, IAM's boot and IAM's Cloudflare deploy (which also requires `https:`).
37
+ */
38
+ export declare function isHttpOrigin(value: string): boolean;
@@ -5,6 +5,7 @@ import type { EmailProviderVariable } from './config.js';
5
5
  */
6
6
  export declare const builtinEmailProviders: {
7
7
  ahasend: import("./config.js").EmailProvider;
8
+ brevo: import("./config.js").EmailProvider;
8
9
  cloudflare: import("./config.js").EmailProvider;
9
10
  lettermint: import("./config.js").EmailProvider;
10
11
  postmark: import("./config.js").EmailProvider;
@@ -21,6 +22,7 @@ export declare const builtinEmailProviderVariables: readonly EmailProviderVariab
21
22
  */
22
23
  export declare const builtinEmailProviderSince: {
23
24
  readonly ahasend: "0.8.2";
25
+ readonly brevo: "0.9.0-dev.17";
24
26
  readonly cloudflare: "0.9.0";
25
27
  readonly lettermint: "0.8.2";
26
28
  readonly postmark: "0.8.2";
@@ -16,14 +16,16 @@ export declare function isValidEmailSenderIdentity(identity: EmailSenderIdentity
16
16
  export declare function validateEmailMessage(message: EmailMessage): void;
17
17
  /**
18
18
  * Refuses a message whose attachments `capabilities` does not carry: any attachment where the transport sends none,
19
- * more bytes together than its `maxAttachmentBytes`, or a file whose extension it refuses. `label` names the transport
20
- * in the message.
19
+ * more bytes together than its `maxAttachmentBytes`, or a file whose extension it refuses or does not list in
20
+ * `attachmentExtensions`. `label` names the transport in the message.
21
21
  */
22
22
  export declare function validateEmailAttachments(message: EmailMessage, capabilities: EmailSenderCapabilities, label: string): void;
23
23
  /** Refuses a `broadcast` message where the transport sends none. */
24
24
  export declare function validateEmailBroadcast(message: EmailMessage, capabilities: EmailSenderCapabilities, label: string): void;
25
25
  /** Refuses a text or HTML body shorter than the transport's `minBodyLength`, counted in characters once trimmed. */
26
26
  export declare function validateEmailBodies(message: EmailMessage, capabilities: EmailSenderCapabilities, label: string): void;
27
+ /** The extension after the last dot, lowercase; empty without one. */
28
+ export declare function extensionOf(filename: string): string;
27
29
  /** The most files one message carries. */
28
30
  export declare const MAX_EMAIL_ATTACHMENTS = 20;
29
31
  /** 1..255 characters, no control characters, no path separator and no `"`, so every transport can quote it. */