@upyo/maileroo 0.6.0-dev.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.
@@ -0,0 +1,267 @@
1
+ import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
2
+
3
+ //#region src/config.d.ts
4
+
5
+ /**
6
+ * Configuration interface for Maileroo transport connection settings.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const config: MailerooConfig = {
11
+ * apiKey: "your-sending-key",
12
+ * timeout: 30000,
13
+ * retries: 3,
14
+ * };
15
+ * ```
16
+ *
17
+ * @since 0.6.0
18
+ */
19
+ interface MailerooConfig {
20
+ /**
21
+ * Your Maileroo sending key.
22
+ *
23
+ * The key is sent as an `X-API-Key` HTTP header.
24
+ */
25
+ readonly apiKey: string;
26
+ /**
27
+ * Base URL for the Maileroo Email API.
28
+ *
29
+ * @default "https://smtp.maileroo.com/api/v2"
30
+ */
31
+ readonly baseUrl?: string;
32
+ /**
33
+ * HTTP request timeout in milliseconds.
34
+ *
35
+ * @default 30000
36
+ */
37
+ readonly timeout?: number;
38
+ /**
39
+ * Number of retry attempts for failed requests.
40
+ *
41
+ * @default 3
42
+ */
43
+ readonly retries?: number;
44
+ /**
45
+ * Additional HTTP headers to include with requests.
46
+ */
47
+ readonly headers?: Record<string, string>;
48
+ /**
49
+ * Whether Maileroo should track opens and clicks for sent messages.
50
+ *
51
+ * When omitted, Maileroo applies the account default.
52
+ */
53
+ readonly tracking?: boolean;
54
+ /**
55
+ * Default Maileroo tags to apply to sent messages.
56
+ */
57
+ readonly tags?: Record<string, string>;
58
+ }
59
+ /**
60
+ * Resolved Maileroo configuration with defaults applied.
61
+ *
62
+ * @since 0.6.0
63
+ */
64
+ type ResolvedMailerooConfig = Required<Omit<MailerooConfig, "tracking" | "tags">> & {
65
+ readonly tracking?: boolean;
66
+ readonly tags?: Record<string, string>;
67
+ };
68
+ /**
69
+ * Creates a resolved Maileroo configuration by applying default values.
70
+ *
71
+ * @param config The Maileroo configuration with optional fields.
72
+ * @returns A resolved configuration with all defaults applied.
73
+ * @since 0.6.0
74
+ */
75
+ declare function createMailerooConfig(config: MailerooConfig): ResolvedMailerooConfig;
76
+ //#endregion
77
+ //#region src/maileroo-transport.d.ts
78
+ /**
79
+ * Maileroo transport implementation for sending emails via Maileroo API.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * import { createMessage } from "@upyo/core";
84
+ * import { MailerooTransport } from "@upyo/maileroo";
85
+ *
86
+ * const transport = new MailerooTransport({
87
+ * apiKey: "your-sending-key",
88
+ * });
89
+ *
90
+ * const receipt = await transport.send(createMessage({
91
+ * from: "sender@example.com",
92
+ * to: "recipient@example.com",
93
+ * subject: "Hello from Maileroo",
94
+ * content: { text: "Hello!" },
95
+ * }));
96
+ * ```
97
+ *
98
+ * @since 0.6.0
99
+ */
100
+ declare class MailerooTransport implements Transport<"maileroo"> {
101
+ readonly id = "maileroo";
102
+ /**
103
+ * The resolved Maileroo configuration used by this transport.
104
+ */
105
+ config: ResolvedMailerooConfig;
106
+ private httpClient;
107
+ /**
108
+ * Creates a new Maileroo transport instance.
109
+ *
110
+ * @param config Maileroo configuration including API key and options.
111
+ */
112
+ constructor(config: MailerooConfig);
113
+ /**
114
+ * Sends a single email message via Maileroo API.
115
+ *
116
+ * @param message The email message to send.
117
+ * @param options Optional transport options including `AbortSignal`.
118
+ * @returns A receipt indicating success or failure.
119
+ */
120
+ send(message: Message, options?: TransportOptions): Promise<Receipt<"maileroo">>;
121
+ /**
122
+ * Sends multiple email messages sequentially via Maileroo API.
123
+ *
124
+ * @param messages An iterable or async iterable of messages to send.
125
+ * @param options Optional transport options including `AbortSignal`.
126
+ * @returns An async iterable of receipts, one for each message.
127
+ */
128
+ sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt<"maileroo">>;
129
+ }
130
+ //#endregion
131
+ //#region src/message-converter.d.ts
132
+ /**
133
+ * Maileroo email address object.
134
+ *
135
+ * @since 0.6.0
136
+ */
137
+ interface MailerooEmailAddress {
138
+ /** Email address. */
139
+ readonly address: string;
140
+ /** Optional display name. */
141
+ readonly display_name?: string;
142
+ }
143
+ /**
144
+ * Maileroo attachment object.
145
+ *
146
+ * @since 0.6.0
147
+ */
148
+ interface MailerooAttachment {
149
+ /** Attachment filename. */
150
+ readonly file_name: string;
151
+ /** Attachment MIME type. */
152
+ readonly content_type?: string;
153
+ /** Base64-encoded attachment content. */
154
+ readonly content: string;
155
+ /** Whether this attachment is treated as inline content. */
156
+ readonly inline?: boolean;
157
+ }
158
+ /**
159
+ * Maileroo email object structure for API requests.
160
+ *
161
+ * @since 0.6.0
162
+ */
163
+ interface MailerooEmail {
164
+ readonly from: MailerooEmailAddress;
165
+ readonly to: MailerooEmailAddress | readonly MailerooEmailAddress[];
166
+ readonly cc?: MailerooEmailAddress | readonly MailerooEmailAddress[];
167
+ readonly bcc?: MailerooEmailAddress | readonly MailerooEmailAddress[];
168
+ readonly reply_to?: MailerooEmailAddress | readonly MailerooEmailAddress[];
169
+ readonly subject: string;
170
+ readonly html?: string;
171
+ readonly plain?: string;
172
+ readonly tracking?: boolean;
173
+ readonly tags?: Record<string, string>;
174
+ readonly headers?: Record<string, string>;
175
+ readonly attachments?: readonly MailerooAttachment[];
176
+ }
177
+ /**
178
+ * Converts an Upyo message to Maileroo API JSON format.
179
+ *
180
+ * @param message The Upyo message to convert.
181
+ * @param config The resolved Maileroo configuration.
182
+ * @returns JSON object ready for Maileroo API submission.
183
+ * @since 0.6.0
184
+ */
185
+ //#endregion
186
+ //#region src/http-client.d.ts
187
+ /**
188
+ * Response from Maileroo API for sending a single message.
189
+ *
190
+ * @since 0.6.0
191
+ */
192
+ interface MailerooResponse {
193
+ /** Whether Maileroo accepted the request. */
194
+ readonly success: boolean;
195
+ /** Human-readable response message. */
196
+ readonly message?: string;
197
+ /** Response payload from Maileroo. */
198
+ readonly data?: {
199
+ /** Maileroo reference ID for tracking the message. */
200
+ readonly reference_id?: string;
201
+ };
202
+ }
203
+ /**
204
+ * Error response from Maileroo API.
205
+ *
206
+ * @since 0.6.0
207
+ */
208
+ interface MailerooError {
209
+ /** Error message from Maileroo. */
210
+ readonly message?: string;
211
+ /** Error detail from Maileroo. */
212
+ readonly error?: string;
213
+ /** Validation errors from Maileroo. */
214
+ readonly errors?: readonly unknown[];
215
+ }
216
+ /**
217
+ * Maileroo API error class for API-specific failures.
218
+ *
219
+ * @since 0.6.0
220
+ */
221
+ declare class MailerooApiError extends Error {
222
+ readonly statusCode: number;
223
+ readonly retryAfterMilliseconds?: number;
224
+ readonly attempts?: number;
225
+ /**
226
+ * Creates a Maileroo API error.
227
+ *
228
+ * @param message Error message.
229
+ * @param statusCode HTTP status code.
230
+ * @param retryAfterMilliseconds Retry delay from the response.
231
+ * @param attempts Number of attempts made before this error.
232
+ */
233
+ constructor(message: string, statusCode: number, retryAfterMilliseconds?: number, attempts?: number);
234
+ }
235
+ /**
236
+ * Maileroo request timeout error.
237
+ *
238
+ * @since 0.6.0
239
+ */
240
+ declare class MailerooTimeoutError extends Error {
241
+ /**
242
+ * Request timeout in milliseconds.
243
+ *
244
+ * @since 0.6.0
245
+ */
246
+ readonly timeout: number;
247
+ /**
248
+ * Number of attempts made before this error was produced.
249
+ *
250
+ * @since 0.6.0
251
+ */
252
+ readonly attempts?: number;
253
+ /**
254
+ * Creates a Maileroo request timeout error.
255
+ *
256
+ * @param timeout Request timeout in milliseconds.
257
+ * @param attempts Number of attempts made before this error.
258
+ */
259
+ constructor(timeout: number, attempts?: number);
260
+ }
261
+ /**
262
+ * HTTP client wrapper for Maileroo API requests.
263
+ *
264
+ * @since 0.6.0
265
+ */
266
+ //#endregion
267
+ export { MailerooApiError, MailerooAttachment, MailerooConfig, MailerooEmail, MailerooEmailAddress, MailerooError, MailerooResponse, MailerooTimeoutError, MailerooTransport, ResolvedMailerooConfig, createMailerooConfig };
@@ -0,0 +1,267 @@
1
+ import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
2
+
3
+ //#region src/config.d.ts
4
+
5
+ /**
6
+ * Configuration interface for Maileroo transport connection settings.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const config: MailerooConfig = {
11
+ * apiKey: "your-sending-key",
12
+ * timeout: 30000,
13
+ * retries: 3,
14
+ * };
15
+ * ```
16
+ *
17
+ * @since 0.6.0
18
+ */
19
+ interface MailerooConfig {
20
+ /**
21
+ * Your Maileroo sending key.
22
+ *
23
+ * The key is sent as an `X-API-Key` HTTP header.
24
+ */
25
+ readonly apiKey: string;
26
+ /**
27
+ * Base URL for the Maileroo Email API.
28
+ *
29
+ * @default "https://smtp.maileroo.com/api/v2"
30
+ */
31
+ readonly baseUrl?: string;
32
+ /**
33
+ * HTTP request timeout in milliseconds.
34
+ *
35
+ * @default 30000
36
+ */
37
+ readonly timeout?: number;
38
+ /**
39
+ * Number of retry attempts for failed requests.
40
+ *
41
+ * @default 3
42
+ */
43
+ readonly retries?: number;
44
+ /**
45
+ * Additional HTTP headers to include with requests.
46
+ */
47
+ readonly headers?: Record<string, string>;
48
+ /**
49
+ * Whether Maileroo should track opens and clicks for sent messages.
50
+ *
51
+ * When omitted, Maileroo applies the account default.
52
+ */
53
+ readonly tracking?: boolean;
54
+ /**
55
+ * Default Maileroo tags to apply to sent messages.
56
+ */
57
+ readonly tags?: Record<string, string>;
58
+ }
59
+ /**
60
+ * Resolved Maileroo configuration with defaults applied.
61
+ *
62
+ * @since 0.6.0
63
+ */
64
+ type ResolvedMailerooConfig = Required<Omit<MailerooConfig, "tracking" | "tags">> & {
65
+ readonly tracking?: boolean;
66
+ readonly tags?: Record<string, string>;
67
+ };
68
+ /**
69
+ * Creates a resolved Maileroo configuration by applying default values.
70
+ *
71
+ * @param config The Maileroo configuration with optional fields.
72
+ * @returns A resolved configuration with all defaults applied.
73
+ * @since 0.6.0
74
+ */
75
+ declare function createMailerooConfig(config: MailerooConfig): ResolvedMailerooConfig;
76
+ //#endregion
77
+ //#region src/maileroo-transport.d.ts
78
+ /**
79
+ * Maileroo transport implementation for sending emails via Maileroo API.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * import { createMessage } from "@upyo/core";
84
+ * import { MailerooTransport } from "@upyo/maileroo";
85
+ *
86
+ * const transport = new MailerooTransport({
87
+ * apiKey: "your-sending-key",
88
+ * });
89
+ *
90
+ * const receipt = await transport.send(createMessage({
91
+ * from: "sender@example.com",
92
+ * to: "recipient@example.com",
93
+ * subject: "Hello from Maileroo",
94
+ * content: { text: "Hello!" },
95
+ * }));
96
+ * ```
97
+ *
98
+ * @since 0.6.0
99
+ */
100
+ declare class MailerooTransport implements Transport<"maileroo"> {
101
+ readonly id = "maileroo";
102
+ /**
103
+ * The resolved Maileroo configuration used by this transport.
104
+ */
105
+ config: ResolvedMailerooConfig;
106
+ private httpClient;
107
+ /**
108
+ * Creates a new Maileroo transport instance.
109
+ *
110
+ * @param config Maileroo configuration including API key and options.
111
+ */
112
+ constructor(config: MailerooConfig);
113
+ /**
114
+ * Sends a single email message via Maileroo API.
115
+ *
116
+ * @param message The email message to send.
117
+ * @param options Optional transport options including `AbortSignal`.
118
+ * @returns A receipt indicating success or failure.
119
+ */
120
+ send(message: Message, options?: TransportOptions): Promise<Receipt<"maileroo">>;
121
+ /**
122
+ * Sends multiple email messages sequentially via Maileroo API.
123
+ *
124
+ * @param messages An iterable or async iterable of messages to send.
125
+ * @param options Optional transport options including `AbortSignal`.
126
+ * @returns An async iterable of receipts, one for each message.
127
+ */
128
+ sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt<"maileroo">>;
129
+ }
130
+ //#endregion
131
+ //#region src/message-converter.d.ts
132
+ /**
133
+ * Maileroo email address object.
134
+ *
135
+ * @since 0.6.0
136
+ */
137
+ interface MailerooEmailAddress {
138
+ /** Email address. */
139
+ readonly address: string;
140
+ /** Optional display name. */
141
+ readonly display_name?: string;
142
+ }
143
+ /**
144
+ * Maileroo attachment object.
145
+ *
146
+ * @since 0.6.0
147
+ */
148
+ interface MailerooAttachment {
149
+ /** Attachment filename. */
150
+ readonly file_name: string;
151
+ /** Attachment MIME type. */
152
+ readonly content_type?: string;
153
+ /** Base64-encoded attachment content. */
154
+ readonly content: string;
155
+ /** Whether this attachment is treated as inline content. */
156
+ readonly inline?: boolean;
157
+ }
158
+ /**
159
+ * Maileroo email object structure for API requests.
160
+ *
161
+ * @since 0.6.0
162
+ */
163
+ interface MailerooEmail {
164
+ readonly from: MailerooEmailAddress;
165
+ readonly to: MailerooEmailAddress | readonly MailerooEmailAddress[];
166
+ readonly cc?: MailerooEmailAddress | readonly MailerooEmailAddress[];
167
+ readonly bcc?: MailerooEmailAddress | readonly MailerooEmailAddress[];
168
+ readonly reply_to?: MailerooEmailAddress | readonly MailerooEmailAddress[];
169
+ readonly subject: string;
170
+ readonly html?: string;
171
+ readonly plain?: string;
172
+ readonly tracking?: boolean;
173
+ readonly tags?: Record<string, string>;
174
+ readonly headers?: Record<string, string>;
175
+ readonly attachments?: readonly MailerooAttachment[];
176
+ }
177
+ /**
178
+ * Converts an Upyo message to Maileroo API JSON format.
179
+ *
180
+ * @param message The Upyo message to convert.
181
+ * @param config The resolved Maileroo configuration.
182
+ * @returns JSON object ready for Maileroo API submission.
183
+ * @since 0.6.0
184
+ */
185
+ //#endregion
186
+ //#region src/http-client.d.ts
187
+ /**
188
+ * Response from Maileroo API for sending a single message.
189
+ *
190
+ * @since 0.6.0
191
+ */
192
+ interface MailerooResponse {
193
+ /** Whether Maileroo accepted the request. */
194
+ readonly success: boolean;
195
+ /** Human-readable response message. */
196
+ readonly message?: string;
197
+ /** Response payload from Maileroo. */
198
+ readonly data?: {
199
+ /** Maileroo reference ID for tracking the message. */
200
+ readonly reference_id?: string;
201
+ };
202
+ }
203
+ /**
204
+ * Error response from Maileroo API.
205
+ *
206
+ * @since 0.6.0
207
+ */
208
+ interface MailerooError {
209
+ /** Error message from Maileroo. */
210
+ readonly message?: string;
211
+ /** Error detail from Maileroo. */
212
+ readonly error?: string;
213
+ /** Validation errors from Maileroo. */
214
+ readonly errors?: readonly unknown[];
215
+ }
216
+ /**
217
+ * Maileroo API error class for API-specific failures.
218
+ *
219
+ * @since 0.6.0
220
+ */
221
+ declare class MailerooApiError extends Error {
222
+ readonly statusCode: number;
223
+ readonly retryAfterMilliseconds?: number;
224
+ readonly attempts?: number;
225
+ /**
226
+ * Creates a Maileroo API error.
227
+ *
228
+ * @param message Error message.
229
+ * @param statusCode HTTP status code.
230
+ * @param retryAfterMilliseconds Retry delay from the response.
231
+ * @param attempts Number of attempts made before this error.
232
+ */
233
+ constructor(message: string, statusCode: number, retryAfterMilliseconds?: number, attempts?: number);
234
+ }
235
+ /**
236
+ * Maileroo request timeout error.
237
+ *
238
+ * @since 0.6.0
239
+ */
240
+ declare class MailerooTimeoutError extends Error {
241
+ /**
242
+ * Request timeout in milliseconds.
243
+ *
244
+ * @since 0.6.0
245
+ */
246
+ readonly timeout: number;
247
+ /**
248
+ * Number of attempts made before this error was produced.
249
+ *
250
+ * @since 0.6.0
251
+ */
252
+ readonly attempts?: number;
253
+ /**
254
+ * Creates a Maileroo request timeout error.
255
+ *
256
+ * @param timeout Request timeout in milliseconds.
257
+ * @param attempts Number of attempts made before this error.
258
+ */
259
+ constructor(timeout: number, attempts?: number);
260
+ }
261
+ /**
262
+ * HTTP client wrapper for Maileroo API requests.
263
+ *
264
+ * @since 0.6.0
265
+ */
266
+ //#endregion
267
+ export { MailerooApiError, MailerooAttachment, MailerooConfig, MailerooEmail, MailerooEmailAddress, MailerooError, MailerooResponse, MailerooTimeoutError, MailerooTransport, ResolvedMailerooConfig, createMailerooConfig };