@z_06/relay-temp-mail 2.0.0 → 2.1.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.
- package/README.md +357 -226
- package/README.zh-CN.md +357 -195
- package/dist/index.cjs +190 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -4
- package/dist/index.d.ts +79 -4
- package/dist/index.js +188 -108
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,226 +1,357 @@
|
|
|
1
|
-
# relay-temp-mail
|
|
2
|
-
|
|
3
|
-
[English](README.md) | [中文](README.zh-CN.md)
|
|
4
|
-
|
|
5
|
-
A TypeScript/JavaScript package for managing
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
##
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
1
|
+
# relay-temp-mail
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
A modular TypeScript/JavaScript package for managing email aliases and retrieving temporary emails through pluggable providers.
|
|
6
|
+
|
|
7
|
+
Built on a provider architecture — combine any **alias provider** with any **mail provider** to fit your workflow. Currently ships with Firefox Relay, DuckDuckGo Email Protection, and CloudFlare Temp Mail support.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Provider-based architecture** — mix and match alias + mail providers
|
|
12
|
+
- **Firefox Relay** — create, list, and delete email aliases
|
|
13
|
+
- **DuckDuckGo Email Protection** — create email aliases with local storage
|
|
14
|
+
- **CloudFlare Temp Mail** — retrieve and parse emails via API
|
|
15
|
+
- **TypeScript support** — full type definitions for all APIs, including provider interfaces
|
|
16
|
+
- **ESM + CommonJS support** — works with both module systems
|
|
17
|
+
- **Extensible** — implement `AliasProvider` or `MailProvider` to add new services
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @z_06/relay-temp-mail
|
|
23
|
+
# or
|
|
24
|
+
pnpm add @z_06/relay-temp-mail
|
|
25
|
+
# or
|
|
26
|
+
bun add @z_06/relay-temp-mail
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { TempMailClient } from '@z_06/relay-temp-mail';
|
|
33
|
+
|
|
34
|
+
const client = new TempMailClient({
|
|
35
|
+
aliasProvider: {
|
|
36
|
+
type: 'firefox-relay',
|
|
37
|
+
csrfToken: 'your-csrf-token',
|
|
38
|
+
sessionId: 'your-session-id',
|
|
39
|
+
},
|
|
40
|
+
mailProvider: {
|
|
41
|
+
type: 'cf-temp-mail',
|
|
42
|
+
apiUrl: 'https://your-cf-api.com',
|
|
43
|
+
token: 'your-cf-token',
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Create a new alias
|
|
48
|
+
const alias = await client.createAlias();
|
|
49
|
+
console.log('New alias:', alias.fullAddress);
|
|
50
|
+
|
|
51
|
+
// List all aliases
|
|
52
|
+
const aliases = await client.listAliases();
|
|
53
|
+
|
|
54
|
+
// Get emails for a specific alias
|
|
55
|
+
const emails = await client.getEmails(alias.fullAddress, { limit: 10 });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Providers
|
|
59
|
+
|
|
60
|
+
The library uses two types of providers that can be combined independently:
|
|
61
|
+
|
|
62
|
+
| Provider Type | Interface | Current Implementations |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| **Alias Provider** | `AliasProvider` | `firefox-relay`, `duckduckgo-email` |
|
|
65
|
+
| **Mail Provider** | `MailProvider` | `cf-temp-mail` |
|
|
66
|
+
|
|
67
|
+
### Alias Providers
|
|
68
|
+
|
|
69
|
+
#### `firefox-relay`
|
|
70
|
+
|
|
71
|
+
Manages email aliases through [Firefox Relay](https://relay.firefox.com).
|
|
72
|
+
|
|
73
|
+
**Configuration:**
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
{
|
|
77
|
+
type: 'firefox-relay',
|
|
78
|
+
csrfToken: string; // CSRF token from relay.firefox.com cookies
|
|
79
|
+
sessionId: string; // Session ID from relay.firefox.com cookies
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Getting your tokens:**
|
|
84
|
+
|
|
85
|
+
1. Login to [relay.firefox.com](https://relay.firefox.com)
|
|
86
|
+
2. Open your browser's developer tools (F12)
|
|
87
|
+
3. Go to the Application/Storage tab
|
|
88
|
+
4. Find Cookies for `relay.firefox.com`
|
|
89
|
+
5. Copy the values for `csrftoken` and `sessionid`
|
|
90
|
+
|
|
91
|
+
#### `duckduckgo-email`
|
|
92
|
+
|
|
93
|
+
Manages email aliases through [DuckDuckGo Email Protection](https://duckduckgo.com/email/).
|
|
94
|
+
|
|
95
|
+
Since the DuckDuckGo API does not provide endpoints for listing or deleting aliases, this provider uses a local store. A default in-memory store is included; implement `DuckDuckGoAliasStore` for custom persistence (e.g., file-based, database).
|
|
96
|
+
|
|
97
|
+
**Configuration:**
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
{
|
|
101
|
+
type: 'duckduckgo-email',
|
|
102
|
+
jwtToken: string; // JWT token from DuckDuckGo Email Protection
|
|
103
|
+
store?: DuckDuckGoAliasStore; // Optional custom store (default: in-memory)
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Getting your JWT token:**
|
|
108
|
+
|
|
109
|
+
1. Visit [duckduckgo.com/email](https://duckduckgo.com/email/) and register an account
|
|
110
|
+
2. Open your browser's developer tools (F12)
|
|
111
|
+
3. Click "Generate New Address" in the DuckDuckGo Email UI
|
|
112
|
+
4. In the Network tab, find the request to `quack.duckduckgo.com`
|
|
113
|
+
5. Copy the Bearer token from the `Authorization` header
|
|
114
|
+
|
|
115
|
+
**Custom persistence:**
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import type { DuckDuckGoAliasStore, RelayAlias } from '@z_06/relay-temp-mail';
|
|
119
|
+
|
|
120
|
+
class MyFileStore implements DuckDuckGoAliasStore {
|
|
121
|
+
getAll(): RelayAlias[] { /* read from file */ }
|
|
122
|
+
add(alias: RelayAlias): void { /* append to file */ }
|
|
123
|
+
remove(id: number): void { /* remove from file */ }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const client = new TempMailClient({
|
|
127
|
+
aliasProvider: {
|
|
128
|
+
type: 'duckduckgo-email',
|
|
129
|
+
jwtToken: 'your-jwt-token',
|
|
130
|
+
store: new MyFileStore(),
|
|
131
|
+
},
|
|
132
|
+
mailProvider: { /* ... */ },
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Duplicate detection:** The DuckDuckGo API may occasionally return a previously-generated address with a 201 response. The provider detects this and throws a `RelayTempMailError` with code `DUPLICATE_ALIAS`.
|
|
137
|
+
|
|
138
|
+
### Mail Providers
|
|
139
|
+
|
|
140
|
+
#### `cf-temp-mail`
|
|
141
|
+
|
|
142
|
+
Retrieves emails from a [cloudflare_temp_email](https://github.com/dreamhunter2333/cloudflare_temp_email) instance.
|
|
143
|
+
|
|
144
|
+
**Configuration:**
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
{
|
|
148
|
+
type: 'cf-temp-mail',
|
|
149
|
+
apiUrl: string; // Base URL of your CF temp email API
|
|
150
|
+
token: string; // Bearer token for API authentication
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Deploying the backend:**
|
|
155
|
+
|
|
156
|
+
1. Fork [cloudflare_temp_email](https://github.com/dreamhunter2333/cloudflare_temp_email)
|
|
157
|
+
2. Deploy to Cloudflare Workers (one-click or manual via [docs](https://temp-mail-docs.awsl.uk))
|
|
158
|
+
3. Configure Email Routing and catch-all rules in Cloudflare Dashboard
|
|
159
|
+
4. Generate an API Token from the admin panel or user settings
|
|
160
|
+
|
|
161
|
+
## API Documentation
|
|
162
|
+
|
|
163
|
+
### TempMailClient
|
|
164
|
+
|
|
165
|
+
Main client class. Accepts an `aliasProvider` and `mailProvider` configuration and exposes a unified interface.
|
|
166
|
+
|
|
167
|
+
#### Constructor
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
new TempMailClient(config: TempMailConfig)
|
|
171
|
+
|
|
172
|
+
interface TempMailConfig {
|
|
173
|
+
aliasProvider: AliasProviderConfig; // Alias provider config (discriminated union)
|
|
174
|
+
mailProvider: MailProviderConfig; // Mail provider config (discriminated union)
|
|
175
|
+
timeout?: number; // Request timeout in ms (default: 30000)
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Methods
|
|
180
|
+
|
|
181
|
+
##### `listAliases()`
|
|
182
|
+
|
|
183
|
+
Lists all email aliases from the configured alias provider.
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const aliases = await client.listAliases();
|
|
187
|
+
// Returns: RelayAlias[]
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
##### `createAlias()`
|
|
191
|
+
|
|
192
|
+
Creates a new email alias via the configured alias provider.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
const alias = await client.createAlias();
|
|
196
|
+
// Returns: RelayAlias
|
|
197
|
+
console.log(alias.fullAddress); // e.g., "random123@mozmail.com"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
##### `deleteAlias(id)`
|
|
201
|
+
|
|
202
|
+
Deletes an alias by its ID.
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
await client.deleteAlias(12345);
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
##### `getEmails(aliasAddress?, options?)`
|
|
209
|
+
|
|
210
|
+
Retrieves and parses emails from the configured mail provider. If `aliasAddress` is provided, only emails sent to that address are returned.
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
// Get all emails (up to default limit)
|
|
214
|
+
const allEmails = await client.getEmails();
|
|
215
|
+
|
|
216
|
+
// Get emails for a specific alias
|
|
217
|
+
const emails = await client.getEmails('alias@mozmail.com', { limit: 10 });
|
|
218
|
+
|
|
219
|
+
// With pagination
|
|
220
|
+
const page2 = await client.getEmails('alias@mozmail.com', { limit: 10, offset: 10 });
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Options:
|
|
224
|
+
|
|
225
|
+
- `limit` - Maximum number of emails to return (default: 20)
|
|
226
|
+
- `offset` - Offset for pagination, 0-indexed (default: 0)
|
|
227
|
+
|
|
228
|
+
## Custom Providers
|
|
229
|
+
|
|
230
|
+
Implement the `AliasProvider` or `MailProvider` interface to add support for new services:
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import type { AliasProvider, RelayAlias } from '@z_06/relay-temp-mail';
|
|
234
|
+
|
|
235
|
+
class MyAliasProvider implements AliasProvider {
|
|
236
|
+
async listAliases(): Promise<RelayAlias[]> { /* ... */ }
|
|
237
|
+
async createAlias(): Promise<RelayAlias> { /* ... */ }
|
|
238
|
+
async deleteAlias(id: number): Promise<void> { /* ... */ }
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import type { MailProvider, Email } from '@z_06/relay-temp-mail';
|
|
244
|
+
|
|
245
|
+
class MyMailProvider implements MailProvider {
|
|
246
|
+
async getMails(limit: number, offset: number): Promise<Email[]> { /* ... */ }
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Error Handling
|
|
251
|
+
|
|
252
|
+
The package exports several error classes for handling different failure scenarios:
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import {
|
|
256
|
+
RelayTempMailError,
|
|
257
|
+
NetworkError,
|
|
258
|
+
AuthError,
|
|
259
|
+
NotFoundError,
|
|
260
|
+
ParseError,
|
|
261
|
+
RateLimitError,
|
|
262
|
+
} from '@z_06/relay-temp-mail';
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
const alias = await client.createAlias();
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (error instanceof AuthError) {
|
|
268
|
+
console.error('Authentication failed:', error.message);
|
|
269
|
+
} else if (error instanceof NetworkError) {
|
|
270
|
+
console.error('Network problem:', error.message);
|
|
271
|
+
} else if (error instanceof RateLimitError) {
|
|
272
|
+
console.error('Rate limited. Retry after:', error.response?.retryAfter);
|
|
273
|
+
} else if (error instanceof RelayTempMailError) {
|
|
274
|
+
console.error('Error:', error.code, error.message);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Error Classes
|
|
280
|
+
|
|
281
|
+
| Class | Description | Status Code |
|
|
282
|
+
|-------|-------------|-------------|
|
|
283
|
+
| `RelayTempMailError` | Base error class for all package errors | - |
|
|
284
|
+
| `NetworkError` | Network connectivity issues | - |
|
|
285
|
+
| `AuthError` | Authentication or authorization failures | 401/403 |
|
|
286
|
+
| `NotFoundError` | Requested resource not found | 404 |
|
|
287
|
+
| `ParseError` | Email MIME parsing failures | - |
|
|
288
|
+
| `RateLimitError` | API rate limit exceeded | 429 |
|
|
289
|
+
|
|
290
|
+
All error classes extend `RelayTempMailError` and provide:
|
|
291
|
+
|
|
292
|
+
- `code` - Machine-readable error code
|
|
293
|
+
- `statusCode` - HTTP status code (if applicable)
|
|
294
|
+
- `response` - Raw response data from the API (if available)
|
|
295
|
+
|
|
296
|
+
## TypeScript
|
|
297
|
+
|
|
298
|
+
All types are fully exported, including the provider interfaces:
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
import type {
|
|
302
|
+
AliasProvider,
|
|
303
|
+
MailProvider,
|
|
304
|
+
TempMailConfig,
|
|
305
|
+
FirefoxRelayConfig,
|
|
306
|
+
DuckDuckGoEmailConfig,
|
|
307
|
+
DuckDuckGoAliasStore,
|
|
308
|
+
CFTempMailConfig,
|
|
309
|
+
RelayAlias,
|
|
310
|
+
Email,
|
|
311
|
+
ParsedEmail,
|
|
312
|
+
GetEmailsOptions,
|
|
313
|
+
} from '@z_06/relay-temp-mail';
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Migration from v1
|
|
317
|
+
|
|
318
|
+
<details>
|
|
319
|
+
<summary>v1 → v2 Migration Guide</summary>
|
|
320
|
+
|
|
321
|
+
**`RelayClient` → `TempMailClient`**
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
// v1 (deprecated)
|
|
325
|
+
import { RelayClient } from '@z_06/relay-temp-mail';
|
|
326
|
+
const client = new RelayClient({
|
|
327
|
+
csrfToken: '...',
|
|
328
|
+
sessionId: '...',
|
|
329
|
+
cfApiUrl: 'https://...',
|
|
330
|
+
cfToken: '...',
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// v2
|
|
334
|
+
import { TempMailClient } from '@z_06/relay-temp-mail';
|
|
335
|
+
const client = new TempMailClient({
|
|
336
|
+
aliasProvider: {
|
|
337
|
+
type: 'firefox-relay',
|
|
338
|
+
csrfToken: '...',
|
|
339
|
+
sessionId: '...',
|
|
340
|
+
},
|
|
341
|
+
mailProvider: {
|
|
342
|
+
type: 'cf-temp-mail',
|
|
343
|
+
apiUrl: 'https://...',
|
|
344
|
+
token: '...',
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
**`RelayAPIClient` → `FirefoxRelayProvider`**, **`CFEmailClient` → `CFTempMailProvider`**
|
|
350
|
+
|
|
351
|
+
The old names are still exported as deprecated aliases. The method signatures are unchanged.
|
|
352
|
+
|
|
353
|
+
</details>
|
|
354
|
+
|
|
355
|
+
## License
|
|
356
|
+
|
|
357
|
+
MIT
|