@upyo/lettermint 0.5.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,234 @@
1
+ import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
2
+
3
+ //#region src/config.d.ts
4
+
5
+ /**
6
+ * Per-email Lettermint tracking settings.
7
+ *
8
+ * These settings are sent as provider-specific defaults for every message
9
+ * delivered through a {@link LettermintTransport}.
10
+ *
11
+ * @since 0.5.0
12
+ */
13
+ interface LettermintSettings {
14
+ /**
15
+ * Whether Lettermint should track email opens.
16
+ */
17
+ readonly trackOpens?: boolean;
18
+ /**
19
+ * Whether Lettermint should track link clicks.
20
+ */
21
+ readonly trackClicks?: boolean;
22
+ }
23
+ /**
24
+ * Configuration interface for Lettermint transport connection settings.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const config: LettermintConfig = {
29
+ * apiToken: "your-project-api-token",
30
+ * route: "transactional",
31
+ * tag: "welcome",
32
+ * timeout: 30000,
33
+ * retries: 3,
34
+ * };
35
+ * ```
36
+ *
37
+ * @since 0.5.0
38
+ */
39
+ interface LettermintConfig {
40
+ /**
41
+ * Your project-specific Lettermint sending API token.
42
+ *
43
+ * The token is sent as the `x-lettermint-token` HTTP header.
44
+ */
45
+ readonly apiToken: string;
46
+ /**
47
+ * Base URL for the Lettermint API.
48
+ *
49
+ * @default "https://api.lettermint.co"
50
+ */
51
+ readonly baseUrl?: string;
52
+ /**
53
+ * HTTP request timeout in milliseconds.
54
+ *
55
+ * @default 30000
56
+ */
57
+ readonly timeout?: number;
58
+ /**
59
+ * Number of retry attempts for failed requests.
60
+ *
61
+ * @default 3
62
+ */
63
+ readonly retries?: number;
64
+ /**
65
+ * Additional HTTP headers to include with requests.
66
+ */
67
+ readonly headers?: Record<string, string>;
68
+ /**
69
+ * Lettermint route to apply to sent messages.
70
+ */
71
+ readonly route?: string;
72
+ /**
73
+ * Default Lettermint tag to apply when the Upyo message has no tag.
74
+ */
75
+ readonly tag?: string | null;
76
+ /**
77
+ * Metadata to track with sent messages. This metadata is not added as
78
+ * email headers.
79
+ */
80
+ readonly metadata?: Record<string, string>;
81
+ /**
82
+ * Lettermint tracking settings to apply to sent messages.
83
+ */
84
+ readonly settings?: LettermintSettings;
85
+ }
86
+ /**
87
+ * Resolved Lettermint configuration with defaults applied.
88
+ *
89
+ * @since 0.5.0
90
+ */
91
+ type ResolvedLettermintConfig = Required<Omit<LettermintConfig, "route" | "tag" | "metadata" | "settings">> & {
92
+ readonly route?: string;
93
+ readonly tag?: string | null;
94
+ readonly metadata?: Record<string, string>;
95
+ readonly settings?: LettermintSettings;
96
+ };
97
+ /**
98
+ * Creates a resolved Lettermint configuration by applying default values.
99
+ *
100
+ * @param config The Lettermint configuration with optional fields.
101
+ * @returns A resolved configuration with all defaults applied.
102
+ * @since 0.5.0
103
+ */
104
+ declare function createLettermintConfig(config: LettermintConfig): ResolvedLettermintConfig;
105
+ //#endregion
106
+ //#region src/lettermint-transport.d.ts
107
+ /**
108
+ * Lettermint transport implementation for sending emails via Lettermint API.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * import { createMessage } from "@upyo/core";
113
+ * import { LettermintTransport } from "@upyo/lettermint";
114
+ *
115
+ * const transport = new LettermintTransport({
116
+ * apiToken: "your-project-api-token",
117
+ * });
118
+ *
119
+ * const receipt = await transport.send(createMessage({
120
+ * from: "sender@example.com",
121
+ * to: "recipient@example.com",
122
+ * subject: "Hello from Lettermint",
123
+ * content: { text: "Hello!" },
124
+ * }));
125
+ * ```
126
+ *
127
+ * @since 0.5.0
128
+ */
129
+ declare class LettermintTransport implements Transport {
130
+ /**
131
+ * The resolved Lettermint configuration used by this transport.
132
+ */
133
+ config: ResolvedLettermintConfig;
134
+ private httpClient;
135
+ /**
136
+ * Creates a new Lettermint transport instance.
137
+ *
138
+ * @param config Lettermint configuration including API token and options.
139
+ */
140
+ constructor(config: LettermintConfig);
141
+ /**
142
+ * Sends a single email message via Lettermint API.
143
+ *
144
+ * @param message The email message to send.
145
+ * @param options Optional transport options including `AbortSignal`.
146
+ * @returns A receipt indicating success or failure.
147
+ */
148
+ send(message: Message, options?: TransportOptions): Promise<Receipt>;
149
+ /**
150
+ * Sends multiple email messages via Lettermint batch API.
151
+ *
152
+ * Messages are chunked into Lettermint's maximum batch size of 500 messages.
153
+ *
154
+ * @param messages An iterable or async iterable of messages to send.
155
+ * @param options Optional transport options including `AbortSignal`.
156
+ * @returns An async iterable of receipts, one for each message.
157
+ */
158
+ sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt>;
159
+ private sendBatch;
160
+ }
161
+ //#endregion
162
+ //#region src/http-client.d.ts
163
+ /**
164
+ * Lettermint message status values.
165
+ *
166
+ * @since 0.5.0
167
+ */
168
+ type LettermintStatus = "pending" | "queued" | "suppressed" | "processed" | "delivered" | "opened" | "clicked" | "soft_bounced" | "hard_bounced" | "spam_complaint" | "failed" | "blocked" | "policy_rejected" | "unsubscribed";
169
+ /**
170
+ * Response from Lettermint API for sending a single message.
171
+ *
172
+ * @since 0.5.0
173
+ */
174
+ interface LettermintResponse {
175
+ /** The message ID returned by Lettermint. */
176
+ readonly message_id: string;
177
+ /** Current message status. */
178
+ readonly status: LettermintStatus;
179
+ }
180
+ /**
181
+ * Response from Lettermint API for sending batch messages.
182
+ *
183
+ * @since 0.5.0
184
+ */
185
+ type LettermintBatchResponse = readonly LettermintResponse[];
186
+ /**
187
+ * Error response from Lettermint API.
188
+ *
189
+ * @since 0.5.0
190
+ */
191
+ interface LettermintError {
192
+ /** Error message from Lettermint. */
193
+ readonly message?: string;
194
+ /** Error detail from Lettermint. */
195
+ readonly error?: string;
196
+ /** Validation errors from Lettermint. */
197
+ readonly errors?: readonly unknown[];
198
+ }
199
+ /**
200
+ * Lettermint API error class for API-specific failures.
201
+ *
202
+ * @since 0.5.0
203
+ */
204
+ declare class LettermintApiError extends Error {
205
+ readonly statusCode: number;
206
+ /**
207
+ * Creates a Lettermint API error.
208
+ *
209
+ * @param message Error message.
210
+ * @param statusCode HTTP status code.
211
+ */
212
+ constructor(message: string, statusCode: number);
213
+ }
214
+ /**
215
+ * Lettermint request timeout error.
216
+ *
217
+ * @since 0.5.0
218
+ */
219
+ declare class LettermintTimeoutError extends Error {
220
+ readonly timeout: number;
221
+ /**
222
+ * Creates a Lettermint request timeout error.
223
+ *
224
+ * @param timeout Request timeout in milliseconds.
225
+ */
226
+ constructor(timeout: number);
227
+ }
228
+ /**
229
+ * HTTP client wrapper for Lettermint API requests.
230
+ *
231
+ * @since 0.5.0
232
+ */
233
+ //#endregion
234
+ export { LettermintApiError, LettermintBatchResponse, LettermintConfig, LettermintError, LettermintResponse, LettermintSettings, LettermintStatus, LettermintTimeoutError, LettermintTransport, ResolvedLettermintConfig, createLettermintConfig };
@@ -0,0 +1,234 @@
1
+ import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
2
+
3
+ //#region src/config.d.ts
4
+
5
+ /**
6
+ * Per-email Lettermint tracking settings.
7
+ *
8
+ * These settings are sent as provider-specific defaults for every message
9
+ * delivered through a {@link LettermintTransport}.
10
+ *
11
+ * @since 0.5.0
12
+ */
13
+ interface LettermintSettings {
14
+ /**
15
+ * Whether Lettermint should track email opens.
16
+ */
17
+ readonly trackOpens?: boolean;
18
+ /**
19
+ * Whether Lettermint should track link clicks.
20
+ */
21
+ readonly trackClicks?: boolean;
22
+ }
23
+ /**
24
+ * Configuration interface for Lettermint transport connection settings.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const config: LettermintConfig = {
29
+ * apiToken: "your-project-api-token",
30
+ * route: "transactional",
31
+ * tag: "welcome",
32
+ * timeout: 30000,
33
+ * retries: 3,
34
+ * };
35
+ * ```
36
+ *
37
+ * @since 0.5.0
38
+ */
39
+ interface LettermintConfig {
40
+ /**
41
+ * Your project-specific Lettermint sending API token.
42
+ *
43
+ * The token is sent as the `x-lettermint-token` HTTP header.
44
+ */
45
+ readonly apiToken: string;
46
+ /**
47
+ * Base URL for the Lettermint API.
48
+ *
49
+ * @default "https://api.lettermint.co"
50
+ */
51
+ readonly baseUrl?: string;
52
+ /**
53
+ * HTTP request timeout in milliseconds.
54
+ *
55
+ * @default 30000
56
+ */
57
+ readonly timeout?: number;
58
+ /**
59
+ * Number of retry attempts for failed requests.
60
+ *
61
+ * @default 3
62
+ */
63
+ readonly retries?: number;
64
+ /**
65
+ * Additional HTTP headers to include with requests.
66
+ */
67
+ readonly headers?: Record<string, string>;
68
+ /**
69
+ * Lettermint route to apply to sent messages.
70
+ */
71
+ readonly route?: string;
72
+ /**
73
+ * Default Lettermint tag to apply when the Upyo message has no tag.
74
+ */
75
+ readonly tag?: string | null;
76
+ /**
77
+ * Metadata to track with sent messages. This metadata is not added as
78
+ * email headers.
79
+ */
80
+ readonly metadata?: Record<string, string>;
81
+ /**
82
+ * Lettermint tracking settings to apply to sent messages.
83
+ */
84
+ readonly settings?: LettermintSettings;
85
+ }
86
+ /**
87
+ * Resolved Lettermint configuration with defaults applied.
88
+ *
89
+ * @since 0.5.0
90
+ */
91
+ type ResolvedLettermintConfig = Required<Omit<LettermintConfig, "route" | "tag" | "metadata" | "settings">> & {
92
+ readonly route?: string;
93
+ readonly tag?: string | null;
94
+ readonly metadata?: Record<string, string>;
95
+ readonly settings?: LettermintSettings;
96
+ };
97
+ /**
98
+ * Creates a resolved Lettermint configuration by applying default values.
99
+ *
100
+ * @param config The Lettermint configuration with optional fields.
101
+ * @returns A resolved configuration with all defaults applied.
102
+ * @since 0.5.0
103
+ */
104
+ declare function createLettermintConfig(config: LettermintConfig): ResolvedLettermintConfig;
105
+ //#endregion
106
+ //#region src/lettermint-transport.d.ts
107
+ /**
108
+ * Lettermint transport implementation for sending emails via Lettermint API.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * import { createMessage } from "@upyo/core";
113
+ * import { LettermintTransport } from "@upyo/lettermint";
114
+ *
115
+ * const transport = new LettermintTransport({
116
+ * apiToken: "your-project-api-token",
117
+ * });
118
+ *
119
+ * const receipt = await transport.send(createMessage({
120
+ * from: "sender@example.com",
121
+ * to: "recipient@example.com",
122
+ * subject: "Hello from Lettermint",
123
+ * content: { text: "Hello!" },
124
+ * }));
125
+ * ```
126
+ *
127
+ * @since 0.5.0
128
+ */
129
+ declare class LettermintTransport implements Transport {
130
+ /**
131
+ * The resolved Lettermint configuration used by this transport.
132
+ */
133
+ config: ResolvedLettermintConfig;
134
+ private httpClient;
135
+ /**
136
+ * Creates a new Lettermint transport instance.
137
+ *
138
+ * @param config Lettermint configuration including API token and options.
139
+ */
140
+ constructor(config: LettermintConfig);
141
+ /**
142
+ * Sends a single email message via Lettermint API.
143
+ *
144
+ * @param message The email message to send.
145
+ * @param options Optional transport options including `AbortSignal`.
146
+ * @returns A receipt indicating success or failure.
147
+ */
148
+ send(message: Message, options?: TransportOptions): Promise<Receipt>;
149
+ /**
150
+ * Sends multiple email messages via Lettermint batch API.
151
+ *
152
+ * Messages are chunked into Lettermint's maximum batch size of 500 messages.
153
+ *
154
+ * @param messages An iterable or async iterable of messages to send.
155
+ * @param options Optional transport options including `AbortSignal`.
156
+ * @returns An async iterable of receipts, one for each message.
157
+ */
158
+ sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt>;
159
+ private sendBatch;
160
+ }
161
+ //#endregion
162
+ //#region src/http-client.d.ts
163
+ /**
164
+ * Lettermint message status values.
165
+ *
166
+ * @since 0.5.0
167
+ */
168
+ type LettermintStatus = "pending" | "queued" | "suppressed" | "processed" | "delivered" | "opened" | "clicked" | "soft_bounced" | "hard_bounced" | "spam_complaint" | "failed" | "blocked" | "policy_rejected" | "unsubscribed";
169
+ /**
170
+ * Response from Lettermint API for sending a single message.
171
+ *
172
+ * @since 0.5.0
173
+ */
174
+ interface LettermintResponse {
175
+ /** The message ID returned by Lettermint. */
176
+ readonly message_id: string;
177
+ /** Current message status. */
178
+ readonly status: LettermintStatus;
179
+ }
180
+ /**
181
+ * Response from Lettermint API for sending batch messages.
182
+ *
183
+ * @since 0.5.0
184
+ */
185
+ type LettermintBatchResponse = readonly LettermintResponse[];
186
+ /**
187
+ * Error response from Lettermint API.
188
+ *
189
+ * @since 0.5.0
190
+ */
191
+ interface LettermintError {
192
+ /** Error message from Lettermint. */
193
+ readonly message?: string;
194
+ /** Error detail from Lettermint. */
195
+ readonly error?: string;
196
+ /** Validation errors from Lettermint. */
197
+ readonly errors?: readonly unknown[];
198
+ }
199
+ /**
200
+ * Lettermint API error class for API-specific failures.
201
+ *
202
+ * @since 0.5.0
203
+ */
204
+ declare class LettermintApiError extends Error {
205
+ readonly statusCode: number;
206
+ /**
207
+ * Creates a Lettermint API error.
208
+ *
209
+ * @param message Error message.
210
+ * @param statusCode HTTP status code.
211
+ */
212
+ constructor(message: string, statusCode: number);
213
+ }
214
+ /**
215
+ * Lettermint request timeout error.
216
+ *
217
+ * @since 0.5.0
218
+ */
219
+ declare class LettermintTimeoutError extends Error {
220
+ readonly timeout: number;
221
+ /**
222
+ * Creates a Lettermint request timeout error.
223
+ *
224
+ * @param timeout Request timeout in milliseconds.
225
+ */
226
+ constructor(timeout: number);
227
+ }
228
+ /**
229
+ * HTTP client wrapper for Lettermint API requests.
230
+ *
231
+ * @since 0.5.0
232
+ */
233
+ //#endregion
234
+ export { LettermintApiError, LettermintBatchResponse, LettermintConfig, LettermintError, LettermintResponse, LettermintSettings, LettermintStatus, LettermintTimeoutError, LettermintTransport, ResolvedLettermintConfig, createLettermintConfig };