@z_06/relay-temp-mail 1.0.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,317 @@
1
+ /**
2
+ * TypeScript type definitions for the relay-temp-mail package.
3
+ *
4
+ * These interfaces define the core data structures used throughout the package,
5
+ * ensuring type safety when interacting with the Firefox Relay and CF temp email APIs.
6
+ */
7
+ /**
8
+ * Configuration interface for initializing the RelayClient.
9
+ *
10
+ * This interface contains all required authentication tokens and API URLs
11
+ * needed to communicate with both Firefox Relay and CloudFlare temp email services.
12
+ */
13
+ interface RelayConfig {
14
+ /** CSRF token for Firefox Relay API authentication */
15
+ csrfToken: string;
16
+ /** Session ID for Firefox Relay API authentication */
17
+ sessionId: string;
18
+ /** Base URL for the CloudFlare temp email API */
19
+ cfApiUrl: string;
20
+ /** Bearer token for CloudFlare temp email API authentication */
21
+ cfToken: string;
22
+ /** Optional timeout for HTTP requests in milliseconds */
23
+ timeout?: number;
24
+ }
25
+ /**
26
+ * Represents a Firefox Relay email alias.
27
+ *
28
+ * This interface maps to the JSON structure returned by the Firefox Relay API
29
+ * when listing or creating email aliases.
30
+ *
31
+ * Note: Property names use camelCase even though the API returns snake_case.
32
+ * The package will handle the conversion internally.
33
+ */
34
+ interface RelayAlias {
35
+ /** Unique identifier for the alias */
36
+ id: number;
37
+ /** The alias username (part before @) */
38
+ address: string;
39
+ /** Complete email address including domain */
40
+ fullAddress: string;
41
+ /** Whether the alias is currently enabled for receiving emails */
42
+ enabled: boolean;
43
+ /** ISO timestamp when the alias was created */
44
+ createdAt: string;
45
+ /** Domain identifier (2 for mozmail.com) */
46
+ domain: number;
47
+ /** Type of alias generation (e.g., "random") */
48
+ maskType: string;
49
+ /** Optional description for the alias */
50
+ description?: string;
51
+ /** Number of emails forwarded through this alias */
52
+ numForwarded?: number;
53
+ /** Number of emails blocked by this alias */
54
+ numBlocked?: number;
55
+ /** Optional timestamp when alias was last modified */
56
+ lastModifiedAt?: string;
57
+ /** Optional timestamp when alias was last used */
58
+ lastUsedAt?: string | null;
59
+ /** Number of level one trackers blocked */
60
+ numLevelOneTrackersBlocked?: number;
61
+ /** Number of replies sent from this alias */
62
+ numReplied?: number;
63
+ /** Number of spam emails marked */
64
+ numSpam?: number;
65
+ /** Whether the alias blocks list emails */
66
+ blockListEmails?: boolean;
67
+ /** Service the alias was generated for (optional) */
68
+ generatedFor?: string;
69
+ /** Where the alias is used (optional) */
70
+ usedOn?: string | null;
71
+ }
72
+ /**
73
+ * Email object returned by the CloudFlare temp email API.
74
+ *
75
+ * This interface represents the raw email data as returned from the CF API,
76
+ * including the complete MIME message in the `raw` field.
77
+ */
78
+ interface Email {
79
+ /** Unique identifier for the email */
80
+ id: number;
81
+ /** Original message ID from the email headers */
82
+ messageId: string;
83
+ /** Source email address that sent this email */
84
+ source: string;
85
+ /** Destination email address that received this email */
86
+ address: string;
87
+ /** Raw MIME content of the email */
88
+ raw: string;
89
+ /** Metadata associated with the email (can be any type) */
90
+ metadata: any | null;
91
+ /** ISO timestamp when the email was created/received */
92
+ createdAt: string;
93
+ }
94
+ /**
95
+ * Email object with parsed alias information.
96
+ *
97
+ * This interface extends the base Email interface and adds the parsed
98
+ * Firefox Relay alias information extracted from the MIME content.
99
+ */
100
+ interface ParsedEmail extends Email {
101
+ /**
102
+ * The Firefox Relay alias that this email was sent to.
103
+ * This is extracted from the `raw` MIME content by parsing the `To:` header.
104
+ */
105
+ relayAlias?: string;
106
+ }
107
+ /**
108
+ * Query options for listing Firefox Relay aliases.
109
+ */
110
+ interface ListAliasesOptions {
111
+ /** Maximum number of aliases to return */
112
+ limit?: number;
113
+ /** Offset for pagination (0-indexed) */
114
+ offset?: number;
115
+ }
116
+ /**
117
+ * Query options for retrieving emails from the CF temp email API.
118
+ */
119
+ interface GetEmailsOptions {
120
+ /** Maximum number of emails to return */
121
+ limit?: number;
122
+ /** Offset for pagination (0-indexed) */
123
+ offset?: number;
124
+ }
125
+ /**
126
+ * Response structure from the CloudFlare temp email API for listing emails.
127
+ *
128
+ * This matches the JSON structure returned by the `/api/mails` endpoint.
129
+ */
130
+ interface CFMailsResponse {
131
+ /** Array of email objects */
132
+ results: Email[];
133
+ /** Total number of emails available (for pagination) */
134
+ count: number;
135
+ }
136
+ /**
137
+ * Response type for listing Firefox Relay aliases.
138
+ *
139
+ * The Firefox Relay API returns an array of alias objects directly.
140
+ */
141
+ type RelayAddressesResponse = RelayAlias[];
142
+ /**
143
+ * Response type for creating a new Firefox Relay alias.
144
+ *
145
+ * The Firefox Relay API returns a single alias object when creating a new alias.
146
+ */
147
+ type CreateAliasResponse = RelayAlias;
148
+
149
+ /**
150
+ * Custom error classes for the relay-temp-mail package.
151
+ *
152
+ * These errors provide structured error information including error codes,
153
+ * HTTP status codes, and response data for better error handling.
154
+ */
155
+ /**
156
+ * Base error class for all relay-temp-mail errors.
157
+ *
158
+ * Extends the built-in Error class with additional context about the error,
159
+ * including an error code for programmatic error handling and optional
160
+ * response data from the API.
161
+ */
162
+ declare class RelayTempMailError extends Error {
163
+ /**
164
+ * Machine-readable error code for programmatic error handling.
165
+ * Examples: 'NETWORK_ERROR', 'AUTH_ERROR', 'NOT_FOUND'
166
+ */
167
+ code: string;
168
+ /**
169
+ * HTTP status code associated with this error, if applicable.
170
+ */
171
+ statusCode?: number;
172
+ /**
173
+ * Raw response data from the API, if available.
174
+ */
175
+ response?: any;
176
+ /**
177
+ * Creates a new RelayTempMailError instance.
178
+ *
179
+ * @param message - Human-readable error message describing the error.
180
+ * @param code - Machine-readable error code (e.g., 'UNKNOWN_ERROR').
181
+ * @param statusCode - Optional HTTP status code associated with the error.
182
+ * @param response - Optional raw response data from the API.
183
+ */
184
+ constructor(message: string, code: string, statusCode?: number, response?: any);
185
+ }
186
+ /**
187
+ * Error for network-related failures.
188
+ *
189
+ * Thrown when there is a problem establishing or maintaining a network
190
+ * connection, such as DNS resolution failures, connection timeouts,
191
+ * or network unreachability.
192
+ */
193
+ declare class NetworkError extends RelayTempMailError {
194
+ code: "NETWORK_ERROR";
195
+ constructor(message: string, response?: any);
196
+ }
197
+ /**
198
+ * Error for authentication and authorization failures.
199
+ *
200
+ * Thrown when API requests fail due to invalid or missing credentials
201
+ * (401) or when the authenticated user lacks permission for the
202
+ * requested operation (403).
203
+ */
204
+ declare class AuthError extends RelayTempMailError {
205
+ code: "AUTH_ERROR";
206
+ constructor(message: string, statusCode?: number, response?: any);
207
+ }
208
+ /**
209
+ * Error for resource not found errors.
210
+ *
211
+ * Thrown when the requested resource does not exist (404 response),
212
+ * such as when trying to access a non-existent alias or email.
213
+ */
214
+ declare class NotFoundError extends RelayTempMailError {
215
+ code: "NOT_FOUND";
216
+ constructor(message: string, response?: any);
217
+ }
218
+ /**
219
+ * Error for MIME message parsing failures.
220
+ *
221
+ * Thrown when there is an error parsing email MIME content,
222
+ * such as malformed headers or invalid message structure.
223
+ */
224
+ declare class ParseError extends RelayTempMailError {
225
+ code: "PARSE_ERROR";
226
+ constructor(message: string, response?: any);
227
+ }
228
+ /**
229
+ * Error for rate limiting responses.
230
+ *
231
+ * Thrown when the API rate limit has been exceeded (429 response).
232
+ * The client should wait and retry the request after the indicated
233
+ * cooldown period.
234
+ */
235
+ declare class RateLimitError extends RelayTempMailError {
236
+ code: "RATE_LIMIT_ERROR";
237
+ constructor(message: string, response?: any);
238
+ }
239
+
240
+ /**
241
+ * Main client for the relay-temp-mail package.
242
+ *
243
+ * This module provides the RelayClient class which integrates all components
244
+ * (CF API, Relay API, Parser) into a unified interface.
245
+ */
246
+
247
+ /**
248
+ * Main client for interacting with Firefox Relay and CloudFlare temp email services.
249
+ *
250
+ * RelayClient integrates all components to provide a unified interface for:
251
+ * - Managing Firefox Relay email aliases
252
+ * - Retrieving and parsing emails from CloudFlare temp email API
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * const client = new RelayClient({
257
+ * csrfToken: '...',
258
+ * sessionId: '...',
259
+ * cfApiUrl: 'https://...',
260
+ * cfToken: '...',
261
+ * timeout: 30000
262
+ * });
263
+ *
264
+ * const aliases = await client.listAliases();
265
+ * const emails = await client.getEmails('alias@mozmail.com', { limit: 10 });
266
+ * ```
267
+ */
268
+ declare class RelayClient {
269
+ private readonly relayApi;
270
+ private readonly cfApi;
271
+ private readonly parser;
272
+ /**
273
+ * Creates a new RelayClient instance.
274
+ *
275
+ * @param config - Configuration object containing authentication tokens and API URLs
276
+ */
277
+ constructor(config: RelayConfig);
278
+ /**
279
+ * Lists all Firefox Relay email aliases.
280
+ *
281
+ * @returns Promise resolving to an array of RelayAlias objects
282
+ * @throws AuthError if authentication fails
283
+ * @throws NetworkError if there's a network problem
284
+ */
285
+ listAliases(): Promise<RelayAlias[]>;
286
+ /**
287
+ * Creates a new Firefox Relay email alias.
288
+ *
289
+ * @returns Promise resolving to the newly created RelayAlias
290
+ * @throws AuthError if authentication fails
291
+ * @throws NetworkError if there's a network problem
292
+ */
293
+ createAlias(): Promise<RelayAlias>;
294
+ /**
295
+ * Deletes a Firefox Relay email alias.
296
+ *
297
+ * @param id - The ID of the alias to delete
298
+ * @throws AuthError if authentication fails
299
+ * @throws NotFoundError if the alias doesn't exist
300
+ * @throws NetworkError if there's a network problem
301
+ */
302
+ deleteAlias(id: number): Promise<void>;
303
+ /**
304
+ * Retrieves and parses emails from the CloudFlare temp email API.
305
+ *
306
+ * If aliasAddress is provided, only emails sent to that address are returned.
307
+ *
308
+ * @param aliasAddress - Optional email address to filter by
309
+ * @param options - Query options for pagination
310
+ * @returns Promise resolving to an array of ParsedEmail objects
311
+ * @throws AuthError if authentication fails
312
+ * @throws NetworkError if there's a network problem
313
+ */
314
+ getEmails(aliasAddress?: string, options?: GetEmailsOptions): Promise<ParsedEmail[]>;
315
+ }
316
+
317
+ export { AuthError, type CFMailsResponse, type CreateAliasResponse, type Email, type GetEmailsOptions, type ListAliasesOptions, NetworkError, NotFoundError, ParseError, type ParsedEmail, RateLimitError, type RelayAddressesResponse, type RelayAlias, RelayClient, type RelayConfig, RelayTempMailError };