@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.
- package/README.md +226 -0
- package/README.zh-CN.md +195 -0
- package/dist/index.cjs +613 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +317 -0
- package/dist/index.d.ts +317 -0
- package/dist/index.js +580 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# relay-temp-mail
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
A TypeScript/JavaScript package for managing Firefox Relay email aliases and retrieving temporary emails via a CloudFlare temp email API.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Create Firefox Relay aliases** - Generate new email aliases on demand
|
|
10
|
+
- **List existing aliases** - View all your configured email aliases
|
|
11
|
+
- **Get emails for specific aliases** - Fetch and parse emails sent to specific addresses
|
|
12
|
+
- **Delete aliases** - Clean up unused aliases programmatically
|
|
13
|
+
- **TypeScript support** - Full type definitions for all APIs
|
|
14
|
+
- **ESM + CommonJS support** - Works with both module systems
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @z_06/relay-temp-mail
|
|
20
|
+
# or
|
|
21
|
+
pnpm add @z_06/relay-temp-mail
|
|
22
|
+
# or
|
|
23
|
+
bun add @z_06/relay-temp-mail
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { RelayClient } from '@z_06/relay-temp-mail';
|
|
30
|
+
|
|
31
|
+
const client = new RelayClient({
|
|
32
|
+
csrfToken: 'your-csrf-token',
|
|
33
|
+
sessionId: 'your-session-id',
|
|
34
|
+
cfApiUrl: 'https://your-cf-api.com',
|
|
35
|
+
cfToken: 'your-cf-token',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Create a new alias
|
|
39
|
+
const alias = await client.createAlias();
|
|
40
|
+
console.log('New alias:', alias.fullAddress);
|
|
41
|
+
|
|
42
|
+
// List all aliases
|
|
43
|
+
const aliases = await client.listAliases();
|
|
44
|
+
|
|
45
|
+
// Get emails for a specific alias
|
|
46
|
+
const emails = await client.getEmails(alias.fullAddress, { limit: 10 });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Configuration
|
|
50
|
+
|
|
51
|
+
### Firefox Relay Tokens
|
|
52
|
+
|
|
53
|
+
To get your `csrfToken` and `sessionId`:
|
|
54
|
+
|
|
55
|
+
1. Login to [relay.firefox.com](https://relay.firefox.com)
|
|
56
|
+
2. Open your browser's developer tools (F12)
|
|
57
|
+
3. Go to the Application/Storage tab
|
|
58
|
+
4. Find Cookies for `relay.firefox.com`
|
|
59
|
+
5. Copy the values for `csrftoken` and `sessionid`
|
|
60
|
+
|
|
61
|
+
### CF Temp Email
|
|
62
|
+
|
|
63
|
+
本项目使�?[cloudflare_temp_email](https://github.com/dreamhunter2333/cloudflare_temp_email) 作为临时邮箱后端,你需要先部署该服务才能使用�?
|
|
64
|
+
#### 快速部署步�?
|
|
65
|
+
1. **Fork 仓库**
|
|
66
|
+
- 访问 [cloudflare_temp_email](https://github.com/dreamhunter2333/cloudflare_temp_email)
|
|
67
|
+
- 点击右上�?"Fork" 按钮,将仓库复制到你�?GitHub 账户
|
|
68
|
+
|
|
69
|
+
2. **一键部署到 Cloudflare**
|
|
70
|
+
- 点击仓库 README 中的 "Deploy to Cloudflare Workers" 按钮
|
|
71
|
+
- 或参�?[部署文档](https://temp-mail-docs.awsl.uk) 进行手动部署
|
|
72
|
+
|
|
73
|
+
3. **配置域名和邮件路�?*
|
|
74
|
+
- �?Cloudflare Dashboard 中添加你的域�? - 配置 Email Routing(邮件路由)
|
|
75
|
+
- 创建 catch-all 规则将所有邮件转发到 Worker
|
|
76
|
+
|
|
77
|
+
4. **获取 API 地址�?Token**
|
|
78
|
+
- 部署完成后,你的 API 地址格式为:`https://<你的worker名称>.<你的子域>.workers.dev`
|
|
79
|
+
- 登录前端界面(部署后会有 Pages 地址�? - 在用户设置或 Admin 后台生成 API Token
|
|
80
|
+
- �?API 地址�?Token 填入 `RelayClient` 配置
|
|
81
|
+
|
|
82
|
+
#### 获取 `cfApiUrl` �?`cfToken`
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const client = new RelayClient({
|
|
86
|
+
csrfToken: 'your-csrf-token',
|
|
87
|
+
sessionId: 'your-session-id',
|
|
88
|
+
cfApiUrl: 'https://your-worker-name.your-subdomain.workers.dev', // CF Worker API 地址
|
|
89
|
+
cfToken: 'your-api-token', // �?Admin 后台或用户设置中生成
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
更多详细配置请参�?[cloudflare_temp_email 官方文档](https://temp-mail-docs.awsl.uk)�?
|
|
94
|
+
## API Documentation
|
|
95
|
+
|
|
96
|
+
### RelayClient
|
|
97
|
+
|
|
98
|
+
The main class for interacting with both Firefox Relay and CloudFlare temp email services.
|
|
99
|
+
|
|
100
|
+
#### Constructor Options
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
interface RelayConfig {
|
|
104
|
+
csrfToken: string; // Firefox Relay CSRF token
|
|
105
|
+
sessionId: string; // Firefox Relay session ID
|
|
106
|
+
cfApiUrl: string; // CloudFlare temp email API URL
|
|
107
|
+
cfToken: string; // CloudFlare API token
|
|
108
|
+
timeout?: number; // Request timeout in ms (default: 30000)
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Methods
|
|
113
|
+
|
|
114
|
+
##### `listAliases()`
|
|
115
|
+
|
|
116
|
+
Lists all Firefox Relay email aliases.
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const aliases = await client.listAliases();
|
|
120
|
+
// Returns: RelayAlias[]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
##### `createAlias()`
|
|
124
|
+
|
|
125
|
+
Creates a new random Firefox Relay email alias.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
const alias = await client.createAlias();
|
|
129
|
+
// Returns: RelayAlias
|
|
130
|
+
console.log(alias.fullAddress); // e.g., "random123@mozmail.com"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
##### `deleteAlias(id)`
|
|
134
|
+
|
|
135
|
+
Deletes an alias by its ID.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
await client.deleteAlias(12345);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
##### `getEmails(aliasAddress?, options?)`
|
|
142
|
+
|
|
143
|
+
Retrieves and parses emails from the CloudFlare temp email API. If `aliasAddress` is provided, only emails sent to that address are returned.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// Get all emails (up to default limit)
|
|
147
|
+
const allEmails = await client.getEmails();
|
|
148
|
+
|
|
149
|
+
// Get emails for a specific alias
|
|
150
|
+
const emails = await client.getEmails('alias@mozmail.com', { limit: 10 });
|
|
151
|
+
|
|
152
|
+
// With pagination
|
|
153
|
+
const page2 = await client.getEmails('alias@mozmail.com', { limit: 10, offset: 10 });
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Options:
|
|
157
|
+
|
|
158
|
+
- `limit` - Maximum number of emails to return (default: 20)
|
|
159
|
+
- `offset` - Offset for pagination, 0-indexed (default: 0)
|
|
160
|
+
|
|
161
|
+
## Error Handling
|
|
162
|
+
|
|
163
|
+
The package exports several error classes for handling different failure scenarios:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import {
|
|
167
|
+
RelayTempMailError,
|
|
168
|
+
NetworkError,
|
|
169
|
+
AuthError,
|
|
170
|
+
NotFoundError,
|
|
171
|
+
ParseError,
|
|
172
|
+
RateLimitError,
|
|
173
|
+
} from '@z_06/relay-temp-mail';
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
const alias = await client.createAlias();
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (error instanceof AuthError) {
|
|
179
|
+
console.error('Authentication failed:', error.message);
|
|
180
|
+
} else if (error instanceof NetworkError) {
|
|
181
|
+
console.error('Network problem:', error.message);
|
|
182
|
+
} else if (error instanceof RateLimitError) {
|
|
183
|
+
console.error('Rate limited. Retry after:', error.response?.retryAfter);
|
|
184
|
+
} else if (error instanceof RelayTempMailError) {
|
|
185
|
+
console.error('Relay error:', error.code, error.message);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Error Classes
|
|
191
|
+
|
|
192
|
+
| Class | Description | Status Code |
|
|
193
|
+
|-------|-------------|-------------|
|
|
194
|
+
| `RelayTempMailError` | Base error class for all package errors | - |
|
|
195
|
+
| `NetworkError` | Network connectivity issues | - |
|
|
196
|
+
| `AuthError` | Authentication or authorization failures | 401/403 |
|
|
197
|
+
| `NotFoundError` | Requested resource not found | 404 |
|
|
198
|
+
| `ParseError` | Email MIME parsing failures | - |
|
|
199
|
+
| `RateLimitError` | API rate limit exceeded | 429 |
|
|
200
|
+
|
|
201
|
+
All error classes extend `RelayTempMailError` and provide:
|
|
202
|
+
|
|
203
|
+
- `code` - Machine-readable error code
|
|
204
|
+
- `statusCode` - HTTP status code (if applicable)
|
|
205
|
+
- `response` - Raw response data from the API (if available)
|
|
206
|
+
|
|
207
|
+
## TypeScript
|
|
208
|
+
|
|
209
|
+
All types are fully exported for use in your TypeScript projects:
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import type {
|
|
213
|
+
RelayConfig,
|
|
214
|
+
RelayAlias,
|
|
215
|
+
Email,
|
|
216
|
+
ParsedEmail,
|
|
217
|
+
ListAliasesOptions,
|
|
218
|
+
GetEmailsOptions,
|
|
219
|
+
} from '@z_06/relay-temp-mail';
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
The package is built with strict TypeScript settings and provides comprehensive type definitions for all APIs.
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
MIT
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# relay-temp-mail
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
一个用于管�?Firefox Relay 邮箱别名和通过 Cloudflare 临时邮箱 API 接收邮件�?TypeScript/JavaScript 包�?
|
|
6
|
+
## 功能特�?
|
|
7
|
+
- **创建 Firefox Relay 别名** - 按需生成新的邮箱别名
|
|
8
|
+
- **列出已有别名** - 查看所有已配置的邮箱别�?- **获取指定别名的邮�?* - 获取并解析发送到特定地址的邮�?- **删除别名** - 以编程方式清理未使用的别�?- **TypeScript 支持** - 所�?API 都有完整的类型定�?- **支持 ESM + CommonJS** - 兼容两种模块系统
|
|
9
|
+
|
|
10
|
+
## 安装
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @z_06/relay-temp-mail
|
|
14
|
+
# �?pnpm add @z_06/relay-temp-mail
|
|
15
|
+
# �?bun add @z_06/relay-temp-mail
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 快速开�?
|
|
19
|
+
```typescript
|
|
20
|
+
import { RelayClient } from '@z_06/relay-temp-mail';
|
|
21
|
+
|
|
22
|
+
const client = new RelayClient({
|
|
23
|
+
csrfToken: 'your-csrf-token',
|
|
24
|
+
sessionId: 'your-session-id',
|
|
25
|
+
cfApiUrl: 'https://your-cf-api.com',
|
|
26
|
+
cfToken: 'your-cf-token',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// 创建新别�?const alias = await client.createAlias();
|
|
30
|
+
console.log('新别�?', alias.fullAddress);
|
|
31
|
+
|
|
32
|
+
// 列出所有别�?const aliases = await client.listAliases();
|
|
33
|
+
|
|
34
|
+
// 获取指定别名的邮�?const emails = await client.getEmails(alias.fullAddress, { limit: 10 });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 配置
|
|
38
|
+
|
|
39
|
+
### Firefox Relay Token
|
|
40
|
+
|
|
41
|
+
获取 `csrfToken` �?`sessionId` 的方法:
|
|
42
|
+
|
|
43
|
+
1. 登录 [relay.firefox.com](https://relay.firefox.com)
|
|
44
|
+
2. 打开浏览器开发者工�?(F12)
|
|
45
|
+
3. 切换�?Application/Storage 标签�?4. 找到 `relay.firefox.com` �?Cookies
|
|
46
|
+
5. 复制 `csrftoken` �?`sessionid` 的�?
|
|
47
|
+
### CF 临时邮箱
|
|
48
|
+
|
|
49
|
+
本项目使�?[cloudflare_temp_email](https://github.com/dreamhunter2333/cloudflare_temp_email) 作为临时邮箱后端,你需要先部署该服务才能使用�?
|
|
50
|
+
#### 快速部署步�?
|
|
51
|
+
1. **Fork 仓库**
|
|
52
|
+
- 访问 [cloudflare_temp_email](https://github.com/dreamhunter2333/cloudflare_temp_email)
|
|
53
|
+
- 点击右上�?"Fork" 按钮,将仓库复制到你�?GitHub 账户
|
|
54
|
+
|
|
55
|
+
2. **一键部署到 Cloudflare**
|
|
56
|
+
- 点击仓库 README 中的 "Deploy to Cloudflare Workers" 按钮
|
|
57
|
+
- 或参�?[部署文档](https://temp-mail-docs.awsl.uk) 进行手动部署
|
|
58
|
+
|
|
59
|
+
3. **配置域名和邮件路�?*
|
|
60
|
+
- �?Cloudflare Dashboard 中添加你的域�? - 配置 Email Routing(邮件路由)
|
|
61
|
+
- 创建 catch-all 规则将所有邮件转发到 Worker
|
|
62
|
+
|
|
63
|
+
4. **获取 API 地址�?Token**
|
|
64
|
+
- 部署完成后,你的 API 地址格式为:`https://<你的worker名称>.<你的子域>.workers.dev`
|
|
65
|
+
- 登录前端界面(部署后会有 Pages 地址�? - 在用户设置或 Admin 后台生成 API Token
|
|
66
|
+
- �?API 地址�?Token 填入 `RelayClient` 配置
|
|
67
|
+
|
|
68
|
+
#### 获取 `cfApiUrl` �?`cfToken`
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
const client = new RelayClient({
|
|
72
|
+
csrfToken: 'your-csrf-token',
|
|
73
|
+
sessionId: 'your-session-id',
|
|
74
|
+
cfApiUrl: 'https://your-worker-name.your-subdomain.workers.dev', // CF Worker API 地址
|
|
75
|
+
cfToken: 'your-api-token', // �?Admin 后台或用户设置中生成
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
更多详细配置请参�?[cloudflare_temp_email 官方文档](https://temp-mail-docs.awsl.uk)�?
|
|
80
|
+
## API 文档
|
|
81
|
+
|
|
82
|
+
### RelayClient
|
|
83
|
+
|
|
84
|
+
用于�?Firefox Relay �?Cloudflare 临时邮箱服务交互的主类�?
|
|
85
|
+
#### 构造函数选项
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
interface RelayConfig {
|
|
89
|
+
csrfToken: string; // Firefox Relay CSRF token
|
|
90
|
+
sessionId: string; // Firefox Relay session ID
|
|
91
|
+
cfApiUrl: string; // Cloudflare 临时邮箱 API 地址
|
|
92
|
+
cfToken: string; // Cloudflare API token
|
|
93
|
+
timeout?: number; // 请求超时时间,毫秒(默认: 30000�?}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### 方法
|
|
97
|
+
|
|
98
|
+
##### `listAliases()`
|
|
99
|
+
|
|
100
|
+
列出所�?Firefox Relay 邮箱别名�?
|
|
101
|
+
```typescript
|
|
102
|
+
const aliases = await client.listAliases();
|
|
103
|
+
// 返回: RelayAlias[]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
##### `createAlias()`
|
|
107
|
+
|
|
108
|
+
创建一个新的随�?Firefox Relay 邮箱别名�?
|
|
109
|
+
```typescript
|
|
110
|
+
const alias = await client.createAlias();
|
|
111
|
+
// 返回: RelayAlias
|
|
112
|
+
console.log(alias.fullAddress); // 例如: "random123@mozmail.com"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
##### `deleteAlias(id)`
|
|
116
|
+
|
|
117
|
+
根据 ID 删除别名�?
|
|
118
|
+
```typescript
|
|
119
|
+
await client.deleteAlias(12345);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
##### `getEmails(aliasAddress?, options?)`
|
|
123
|
+
|
|
124
|
+
�?Cloudflare 临时邮箱 API 检索和解析邮件。如果提供了 `aliasAddress`,则只返回发送到该地址的邮件�?
|
|
125
|
+
```typescript
|
|
126
|
+
// 获取所有邮件(默认数量限制�?const allEmails = await client.getEmails();
|
|
127
|
+
|
|
128
|
+
// 获取指定别名的邮�?const emails = await client.getEmails('alias@mozmail.com', { limit: 10 });
|
|
129
|
+
|
|
130
|
+
// 分页获取
|
|
131
|
+
const page2 = await client.getEmails('alias@mozmail.com', { limit: 10, offset: 10 });
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
选项�?
|
|
135
|
+
- `limit` - 返回的最大邮件数量(默认: 20�?- `offset` - 分页偏移量,�?0 开始(默认: 0�?
|
|
136
|
+
## 错误处理
|
|
137
|
+
|
|
138
|
+
本包导出了多个错误类,用于处理不同的失败场景�?
|
|
139
|
+
```typescript
|
|
140
|
+
import {
|
|
141
|
+
RelayTempMailError,
|
|
142
|
+
NetworkError,
|
|
143
|
+
AuthError,
|
|
144
|
+
NotFoundError,
|
|
145
|
+
ParseError,
|
|
146
|
+
RateLimitError,
|
|
147
|
+
} from '@z_06/relay-temp-mail';
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const alias = await client.createAlias();
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (error instanceof AuthError) {
|
|
153
|
+
console.error('认证失败:', error.message);
|
|
154
|
+
} else if (error instanceof NetworkError) {
|
|
155
|
+
console.error('网络问题:', error.message);
|
|
156
|
+
} else if (error instanceof RateLimitError) {
|
|
157
|
+
console.error('请求过于频繁,请稍后重试:', error.response?.retryAfter);
|
|
158
|
+
} else if (error instanceof RelayTempMailError) {
|
|
159
|
+
console.error('Relay 错误:', error.code, error.message);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 错误�?
|
|
165
|
+
| 类名 | 描述 | 状态码 |
|
|
166
|
+
|------|------|--------|
|
|
167
|
+
| `RelayTempMailError` | 所有包错误的基�?| - |
|
|
168
|
+
| `NetworkError` | 网络连接问题 | - |
|
|
169
|
+
| `AuthError` | 认证或授权失�?| 401/403 |
|
|
170
|
+
| `NotFoundError` | 请求的资源不存在 | 404 |
|
|
171
|
+
| `ParseError` | 邮件 MIME 解析失败 | - |
|
|
172
|
+
| `RateLimitError` | API 请求频率限制 exceeded | 429 |
|
|
173
|
+
|
|
174
|
+
所有错误类都继承自 `RelayTempMailError`,并提供以下属性:
|
|
175
|
+
|
|
176
|
+
- `code` - 机器可读的错误代�?- `statusCode` - HTTP 状态码(如适用�?- `response` - API 返回的原始响应数据(如可用)
|
|
177
|
+
|
|
178
|
+
## TypeScript
|
|
179
|
+
|
|
180
|
+
所有类型都已导出,可在 TypeScript 项目中使用:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import type {
|
|
184
|
+
RelayConfig,
|
|
185
|
+
RelayAlias,
|
|
186
|
+
Email,
|
|
187
|
+
ParsedEmail,
|
|
188
|
+
ListAliasesOptions,
|
|
189
|
+
GetEmailsOptions,
|
|
190
|
+
} from 'relay-temp-mail';
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
本包使用严格�?TypeScript 设置构建,为所�?API 提供全面的类型定义�?
|
|
194
|
+
## 许可�?
|
|
195
|
+
MIT
|