tempmail-sdk 1.0.1 → 1.0.3
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 +162 -72
- package/demo/poll-emails.ts +25 -40
- package/dist/index.d.ts +96 -2
- package/dist/index.js +186 -21
- package/dist/logger.d.ts +73 -0
- package/dist/logger.js +100 -0
- package/dist/normalize.d.ts +12 -0
- package/dist/normalize.js +132 -0
- package/dist/providers/awamail.d.ts +15 -0
- package/dist/providers/awamail.js +91 -0
- package/dist/providers/chatgpt-org-uk.js +4 -2
- package/dist/providers/dropmail.d.ts +13 -0
- package/dist/providers/dropmail.js +86 -0
- package/dist/providers/linshi-email.js +4 -2
- package/dist/providers/mail-tm.d.ts +11 -0
- package/dist/providers/mail-tm.js +172 -0
- package/dist/providers/temp-mail-io.d.ts +13 -0
- package/dist/providers/temp-mail-io.js +99 -0
- package/dist/providers/tempmail-la.d.ts +15 -0
- package/dist/providers/tempmail-la.js +89 -0
- package/dist/providers/tempmail-lol.d.ts +1 -1
- package/dist/providers/tempmail-lol.js +5 -3
- package/dist/providers/tempmail.js +4 -2
- package/dist/retry.d.ts +38 -0
- package/dist/retry.js +121 -0
- package/dist/types.d.ts +118 -28
- package/dist/types.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +182 -25
- package/src/logger.ts +106 -0
- package/src/normalize.ts +125 -0
- package/src/providers/awamail.ts +101 -0
- package/src/providers/chatgpt-org-uk.ts +3 -1
- package/src/providers/dropmail.ts +98 -0
- package/src/providers/linshi-email.ts +3 -1
- package/src/providers/mail-tm.ts +193 -0
- package/src/providers/temp-mail-io.ts +108 -0
- package/src/providers/tempmail-la.ts +99 -0
- package/src/providers/tempmail-lol.ts +4 -2
- package/src/providers/tempmail.ts +3 -1
- package/src/retry.ts +146 -0
- package/src/types.ts +120 -28
- package/test/example.ts +16 -1
package/README.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# tempmail-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/tempmail-sdk)
|
|
4
|
+
[](https://www.gnu.org/licenses/gpl-3.0)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
GPL-3.0
|
|
6
|
+
临时邮箱 SDK(TypeScript/Node.js),支持 9 个邮箱服务提供商,所有渠道返回**统一标准化格式**。
|
|
8
7
|
|
|
9
8
|
## 安装
|
|
10
9
|
|
|
@@ -14,40 +13,78 @@ npm install tempmail-sdk
|
|
|
14
13
|
|
|
15
14
|
## 支持的渠道
|
|
16
15
|
|
|
17
|
-
| 渠道 | 服务商 |
|
|
18
|
-
|
|
19
|
-
| `tempmail` | tempmail.ing |
|
|
20
|
-
| `linshi-email` | linshi-email.com |
|
|
21
|
-
| `tempmail-lol` | tempmail.lol |
|
|
22
|
-
| `chatgpt-org-uk` | mail.chatgpt.org.uk |
|
|
16
|
+
| 渠道 | 服务商 | 需要 Token | 说明 |
|
|
17
|
+
|------|--------|:----------:|------|
|
|
18
|
+
| `tempmail` | tempmail.ing | - | 支持自定义有效期 |
|
|
19
|
+
| `linshi-email` | linshi-email.com | - | |
|
|
20
|
+
| `tempmail-lol` | tempmail.lol | ✅ | 支持指定域名 |
|
|
21
|
+
| `chatgpt-org-uk` | mail.chatgpt.org.uk | - | |
|
|
22
|
+
| `tempmail-la` | tempmail.la | - | 支持分页 |
|
|
23
|
+
| `temp-mail-io` | temp-mail.io | - | |
|
|
24
|
+
| `awamail` | awamail.com | ✅ | Session Cookie 自动管理 |
|
|
25
|
+
| `mail-tm` | mail.tm | ✅ | 自动注册账号获取 Bearer Token |
|
|
26
|
+
| `dropmail` | dropmail.me | ✅ | GraphQL API |
|
|
27
|
+
|
|
28
|
+
> **提示:** 使用 `TempEmailClient` 类时无需手动处理 Token,SDK 自动管理。
|
|
29
|
+
|
|
30
|
+
## 快速开始
|
|
31
|
+
|
|
32
|
+
### 使用 TempEmailClient(推荐)
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { TempEmailClient } from 'tempmail-sdk';
|
|
36
|
+
|
|
37
|
+
const client = new TempEmailClient();
|
|
38
|
+
|
|
39
|
+
// 获取临时邮箱(可指定渠道,不指定则随机)
|
|
40
|
+
const emailInfo = await client.generate({ channel: 'tempmail' });
|
|
41
|
+
console.log(`渠道: ${emailInfo.channel}`);
|
|
42
|
+
console.log(`邮箱: ${emailInfo.email}`);
|
|
43
|
+
if (emailInfo.expiresAt) console.log(`过期时间: ${emailInfo.expiresAt}`);
|
|
44
|
+
|
|
45
|
+
// 获取邮件(Token 自动传递,无需手动处理)
|
|
46
|
+
const result = await client.getEmails();
|
|
47
|
+
console.log(`收到 ${result.emails.length} 封邮件`);
|
|
23
48
|
|
|
24
|
-
|
|
49
|
+
for (const email of result.emails) {
|
|
50
|
+
console.log(`发件人: ${email.from}`);
|
|
51
|
+
console.log(`主题: ${email.subject}`);
|
|
52
|
+
console.log(`内容: ${email.text}`);
|
|
53
|
+
console.log(`时间: ${email.date}`);
|
|
54
|
+
console.log(`已读: ${email.isRead}`);
|
|
55
|
+
console.log(`附件: ${email.attachments.length} 个`);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
25
58
|
|
|
26
|
-
###
|
|
59
|
+
### 使用函数式 API
|
|
60
|
+
|
|
61
|
+
#### 列出所有渠道
|
|
27
62
|
|
|
28
63
|
```typescript
|
|
29
|
-
import { listChannels, getChannelInfo } from '
|
|
64
|
+
import { listChannels, getChannelInfo } from 'tempmail-sdk';
|
|
30
65
|
|
|
31
|
-
// 获取所有支持的渠道
|
|
32
66
|
const channels = listChannels();
|
|
33
67
|
console.log(channels);
|
|
34
68
|
// [
|
|
35
69
|
// { channel: 'tempmail', name: 'TempMail', website: 'tempmail.ing' },
|
|
36
70
|
// { channel: 'linshi-email', name: '临时邮箱', website: 'linshi-email.com' },
|
|
37
71
|
// { channel: 'tempmail-lol', name: 'TempMail LOL', website: 'tempmail.lol' },
|
|
38
|
-
// { channel: 'chatgpt-org-uk', name: 'ChatGPT Mail', website: 'mail.chatgpt.org.uk' }
|
|
72
|
+
// { channel: 'chatgpt-org-uk', name: 'ChatGPT Mail', website: 'mail.chatgpt.org.uk' },
|
|
73
|
+
// { channel: 'tempmail-la', name: 'TempMail LA', website: 'tempmail.la' },
|
|
74
|
+
// { channel: 'temp-mail-io', name: 'Temp Mail IO', website: 'temp-mail.io' },
|
|
75
|
+
// { channel: 'awamail', name: 'AwaMail', website: 'awamail.com' },
|
|
76
|
+
// { channel: 'mail-tm', name: 'Mail.tm', website: 'mail.tm' },
|
|
77
|
+
// { channel: 'dropmail', name: 'DropMail', website: 'dropmail.me' }
|
|
39
78
|
// ]
|
|
40
79
|
|
|
41
|
-
// 获取指定渠道信息
|
|
42
80
|
const info = getChannelInfo('tempmail');
|
|
43
|
-
console.log(info);
|
|
44
81
|
// { channel: 'tempmail', name: 'TempMail', website: 'tempmail.ing' }
|
|
45
82
|
```
|
|
46
83
|
|
|
47
|
-
|
|
84
|
+
#### 获取邮箱
|
|
48
85
|
|
|
49
86
|
```typescript
|
|
50
|
-
import { generateEmail } from '
|
|
87
|
+
import { generateEmail } from 'tempmail-sdk';
|
|
51
88
|
|
|
52
89
|
// 从随机渠道获取邮箱
|
|
53
90
|
const emailInfo = await generateEmail();
|
|
@@ -56,66 +93,65 @@ console.log(emailInfo);
|
|
|
56
93
|
|
|
57
94
|
// 从指定渠道获取邮箱
|
|
58
95
|
const emailInfo2 = await generateEmail({ channel: 'linshi-email' });
|
|
59
|
-
|
|
60
|
-
//
|
|
96
|
+
|
|
97
|
+
// tempmail 渠道支持自定义有效期(分钟)
|
|
98
|
+
const emailInfo3 = await generateEmail({ channel: 'tempmail', duration: 60 });
|
|
99
|
+
|
|
100
|
+
// tempmail-lol 渠道支持指定域名
|
|
101
|
+
const emailInfo4 = await generateEmail({ channel: 'tempmail-lol', domain: 'example.com' });
|
|
61
102
|
```
|
|
62
103
|
|
|
63
|
-
|
|
104
|
+
#### 获取邮件
|
|
64
105
|
|
|
65
106
|
```typescript
|
|
66
|
-
import { getEmails } from '
|
|
107
|
+
import { getEmails } from 'tempmail-sdk';
|
|
67
108
|
|
|
68
|
-
//
|
|
109
|
+
// 不需要 Token 的渠道
|
|
69
110
|
const result = await getEmails({
|
|
70
111
|
channel: 'tempmail',
|
|
71
|
-
email: 'xxx@ibymail.com'
|
|
112
|
+
email: 'xxx@ibymail.com',
|
|
72
113
|
});
|
|
73
|
-
console.log(result);
|
|
74
|
-
// { channel: 'tempmail', email: 'xxx@ibymail.com', emails: [...], success: true }
|
|
114
|
+
console.log(result.emails); // 标准化邮件数组
|
|
75
115
|
|
|
76
|
-
//
|
|
116
|
+
// 需要 Token 的渠道(token 由 generateEmail 返回)
|
|
77
117
|
const result2 = await getEmails({
|
|
78
|
-
channel: '
|
|
79
|
-
email:
|
|
80
|
-
token:
|
|
118
|
+
channel: 'mail-tm',
|
|
119
|
+
email: emailInfo.email,
|
|
120
|
+
token: emailInfo.token, // Bearer Token
|
|
81
121
|
});
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### 使用 TempEmailClient 类
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
import { TempEmailClient } from 'temp-email-sdk';
|
|
88
|
-
|
|
89
|
-
const client = new TempEmailClient();
|
|
90
|
-
|
|
91
|
-
// 获取邮箱
|
|
92
|
-
const emailInfo = await client.generate({ channel: 'tempmail' });
|
|
93
|
-
console.log(`渠道: ${emailInfo.channel}`);
|
|
94
|
-
console.log(`邮箱: ${emailInfo.email}`);
|
|
95
122
|
|
|
96
|
-
//
|
|
97
|
-
const
|
|
98
|
-
console.log(
|
|
123
|
+
// 所有邮件使用统一格式,无需关心渠道差异
|
|
124
|
+
for (const email of result2.emails) {
|
|
125
|
+
console.log(email.id); // 邮件 ID
|
|
126
|
+
console.log(email.from); // 发件人
|
|
127
|
+
console.log(email.to); // 收件人
|
|
128
|
+
console.log(email.subject); // 主题
|
|
129
|
+
console.log(email.text); // 纯文本
|
|
130
|
+
console.log(email.html); // HTML
|
|
131
|
+
console.log(email.date); // ISO 日期
|
|
132
|
+
console.log(email.isRead); // 是否已读
|
|
133
|
+
console.log(email.attachments); // 附件列表
|
|
134
|
+
}
|
|
99
135
|
```
|
|
100
136
|
|
|
101
|
-
## API
|
|
137
|
+
## API 参考
|
|
102
138
|
|
|
103
139
|
### listChannels()
|
|
104
140
|
|
|
105
141
|
获取所有支持的渠道列表。
|
|
106
142
|
|
|
107
143
|
**返回值:** `ChannelInfo[]`
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
144
|
+
|
|
145
|
+
| 字段 | 类型 | 说明 |
|
|
146
|
+
|------|------|------|
|
|
147
|
+
| `channel` | `Channel` | 渠道标识 |
|
|
148
|
+
| `name` | `string` | 渠道显示名称 |
|
|
149
|
+
| `website` | `string` | 服务商网站 |
|
|
111
150
|
|
|
112
151
|
### getChannelInfo(channel)
|
|
113
152
|
|
|
114
153
|
获取指定渠道信息。
|
|
115
154
|
|
|
116
|
-
**参数:**
|
|
117
|
-
- `channel` - 渠道标识
|
|
118
|
-
|
|
119
155
|
**返回值:** `ChannelInfo | undefined`
|
|
120
156
|
|
|
121
157
|
### generateEmail(options?)
|
|
@@ -123,31 +159,85 @@ console.log(`收到 ${result.emails.length} 封邮件`);
|
|
|
123
159
|
生成临时邮箱地址。
|
|
124
160
|
|
|
125
161
|
**参数:**
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
162
|
+
|
|
163
|
+
| 字段 | 类型 | 说明 |
|
|
164
|
+
|------|------|------|
|
|
165
|
+
| `channel` | `Channel` | 指定渠道(可选,不指定则随机) |
|
|
166
|
+
| `duration` | `number` | 有效期分钟数(仅 `tempmail` 渠道) |
|
|
167
|
+
| `domain` | `string` | 指定域名(仅 `tempmail-lol` 渠道) |
|
|
129
168
|
|
|
130
169
|
**返回值:** `EmailInfo`
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
170
|
+
|
|
171
|
+
| 字段 | 类型 | 说明 |
|
|
172
|
+
|------|------|------|
|
|
173
|
+
| `channel` | `Channel` | 渠道标识 |
|
|
174
|
+
| `email` | `string` | 邮箱地址 |
|
|
175
|
+
| `token` | `string?` | 访问令牌(部分渠道返回) |
|
|
176
|
+
| `expiresAt` | `string \| number?` | 过期时间 |
|
|
177
|
+
| `createdAt` | `string?` | 创建时间 |
|
|
135
178
|
|
|
136
179
|
### getEmails(options)
|
|
137
180
|
|
|
138
|
-
|
|
181
|
+
获取邮件列表。
|
|
139
182
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
183
|
+
**参数:**
|
|
184
|
+
|
|
185
|
+
| 字段 | 类型 | 必填 | 说明 |
|
|
186
|
+
|------|------|:----:|------|
|
|
187
|
+
| `channel` | `Channel` | ✅ | 渠道标识 |
|
|
188
|
+
| `email` | `string` | ✅ | 邮箱地址 |
|
|
189
|
+
| `token` | `string` | 部分 | 访问令牌(`tempmail-lol`、`awamail`、`mail-tm`、`dropmail` 必填) |
|
|
144
190
|
|
|
145
191
|
**返回值:** `GetEmailsResult`
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
192
|
+
|
|
193
|
+
| 字段 | 类型 | 说明 |
|
|
194
|
+
|------|------|------|
|
|
195
|
+
| `channel` | `Channel` | 渠道标识 |
|
|
196
|
+
| `email` | `string` | 邮箱地址 |
|
|
197
|
+
| `emails` | `Email[]` | 标准化邮件数组 |
|
|
198
|
+
| `success` | `boolean` | 是否成功 |
|
|
199
|
+
|
|
200
|
+
### 标准化邮件格式
|
|
201
|
+
|
|
202
|
+
所有渠道返回的邮件均使用统一的 `Email` 格式:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
interface Email {
|
|
206
|
+
id: string; // 邮件唯一标识
|
|
207
|
+
from: string; // 发件人邮箱地址
|
|
208
|
+
to: string; // 收件人邮箱地址
|
|
209
|
+
subject: string; // 邮件主题
|
|
210
|
+
text: string; // 纯文本内容
|
|
211
|
+
html: string; // HTML 内容
|
|
212
|
+
date: string; // ISO 8601 格式日期
|
|
213
|
+
isRead: boolean; // 是否已读
|
|
214
|
+
attachments: EmailAttachment[]; // 附件列表
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface EmailAttachment {
|
|
218
|
+
filename: string; // 文件名
|
|
219
|
+
size?: number; // 文件大小(字节)
|
|
220
|
+
contentType?: string; // MIME 类型
|
|
221
|
+
url?: string; // 下载地址
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### TempEmailClient 类
|
|
226
|
+
|
|
227
|
+
封装了 Token 自动管理的便捷客户端:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
const client = new TempEmailClient();
|
|
231
|
+
await client.generate(options?); // 生成邮箱
|
|
232
|
+
await client.getEmails(); // 获取邮件(自动传递 token)
|
|
233
|
+
client.getEmailInfo(); // 获取当前邮箱信息
|
|
234
|
+
```
|
|
150
235
|
|
|
151
236
|
## 环境要求
|
|
152
237
|
|
|
153
|
-
- Node.js 18+(需要原生 fetch 支持)
|
|
238
|
+
- Node.js 18+(需要原生 `fetch` 支持)
|
|
239
|
+
- TypeScript 5.0+(类型定义)
|
|
240
|
+
|
|
241
|
+
## 许可证
|
|
242
|
+
|
|
243
|
+
GPL-3.0
|
package/demo/poll-emails.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import * as readline from 'readline';
|
|
9
|
-
import { generateEmail, getEmails, listChannels, getChannelInfo, Channel, EmailInfo, ChannelInfo } from '../src';
|
|
9
|
+
import { generateEmail, getEmails, listChannels, getChannelInfo, Channel, EmailInfo, ChannelInfo, Email } from '../src';
|
|
10
10
|
|
|
11
11
|
// 配置
|
|
12
12
|
const POLL_INTERVAL = 5000; // 轮询间隔(毫秒)
|
|
@@ -51,6 +51,29 @@ async function selectChannel(channels: ChannelInfo[]): Promise<Channel> {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
function printEmail(email: Email, index: number): void {
|
|
55
|
+
console.log(`\n邮件 #${index + 1}`);
|
|
56
|
+
console.log('━'.repeat(50));
|
|
57
|
+
console.log(`ID: ${email.id || '无'}`);
|
|
58
|
+
console.log(`发件人: ${email.from || '未知'}`);
|
|
59
|
+
console.log(`收件人: ${email.to || '未知'}`);
|
|
60
|
+
console.log(`主题: ${email.subject || '无主题'}`);
|
|
61
|
+
console.log(`时间: ${email.date || '未知'}`);
|
|
62
|
+
console.log(`已读: ${email.isRead ? '是' : '否'}`);
|
|
63
|
+
if (email.text) {
|
|
64
|
+
const preview = email.text.substring(0, 200);
|
|
65
|
+
console.log(`内容: ${preview}`);
|
|
66
|
+
}
|
|
67
|
+
if (email.html) {
|
|
68
|
+
const htmlPreview = email.html.replace(/<[^>]*>/g, '').substring(0, 100);
|
|
69
|
+
console.log(`HTML: ${htmlPreview}...`);
|
|
70
|
+
}
|
|
71
|
+
if (email.attachments.length > 0) {
|
|
72
|
+
console.log(`附件: ${email.attachments.map(a => a.filename).join(', ')}`);
|
|
73
|
+
}
|
|
74
|
+
console.log('━'.repeat(50));
|
|
75
|
+
}
|
|
76
|
+
|
|
54
77
|
async function pollEmails(emailInfo: EmailInfo): Promise<void> {
|
|
55
78
|
console.log(`\n开始轮询邮件...(每 ${POLL_INTERVAL / 1000} 秒检查一次)`);
|
|
56
79
|
console.log('按 Ctrl+C 停止轮询\n');
|
|
@@ -76,45 +99,7 @@ async function pollEmails(emailInfo: EmailInfo): Promise<void> {
|
|
|
76
99
|
printJson('返回数据 (GetEmailsResult)', result);
|
|
77
100
|
|
|
78
101
|
for (let i = 0; i < result.emails.length; i++) {
|
|
79
|
-
|
|
80
|
-
console.log(`\n邮件 #${i + 1}`);
|
|
81
|
-
console.log('━'.repeat(50));
|
|
82
|
-
console.log(`ID: ${email.id || email.eid || email._id || '无'}`);
|
|
83
|
-
const fromAddr = email.from_address || email.address_from || email.from || '未知';
|
|
84
|
-
const fromName = email.from_name || email.name_from || '';
|
|
85
|
-
const fromDisplay = fromName ? `${fromName} <${fromAddr}>` : fromAddr;
|
|
86
|
-
console.log(`发件人: ${fromDisplay}`);
|
|
87
|
-
console.log(`收件人: ${email.to || email.name_to || email.email_address || result.email}`);
|
|
88
|
-
console.log(`主题: ${email.subject || email.e_subject || '无主题'}`);
|
|
89
|
-
let emailDate: string = '未知';
|
|
90
|
-
if (email.received_at) {
|
|
91
|
-
emailDate = email.received_at;
|
|
92
|
-
} else if (email.created_at) {
|
|
93
|
-
emailDate = email.created_at;
|
|
94
|
-
} else if (email.createdAt) {
|
|
95
|
-
emailDate = email.createdAt;
|
|
96
|
-
} else if (email.timestamp) {
|
|
97
|
-
emailDate = new Date(email.timestamp * 1000).toISOString();
|
|
98
|
-
} else if (email.e_date) {
|
|
99
|
-
emailDate = new Date(email.e_date).toISOString();
|
|
100
|
-
} else if (typeof email.date === 'number') {
|
|
101
|
-
emailDate = new Date(email.date).toISOString();
|
|
102
|
-
} else if (email.date) {
|
|
103
|
-
emailDate = email.date;
|
|
104
|
-
}
|
|
105
|
-
console.log(`时间: ${emailDate}`);
|
|
106
|
-
console.log(`已读: ${email.is_read ? '是' : '否'}`);
|
|
107
|
-
const body = email.text || email.body || email.content || '';
|
|
108
|
-
if (body) {
|
|
109
|
-
const preview = body.replace(/<[^>]*>/g, '').substring(0, 200);
|
|
110
|
-
console.log(`内容: ${preview}`);
|
|
111
|
-
}
|
|
112
|
-
const htmlContent = email.html_content || email.html || '';
|
|
113
|
-
if (htmlContent) {
|
|
114
|
-
const htmlPreview = htmlContent.replace(/<[^>]*>/g, '').substring(0, 100);
|
|
115
|
-
console.log(`HTML: ${htmlPreview}...`);
|
|
116
|
-
}
|
|
117
|
-
console.log('━'.repeat(50));
|
|
102
|
+
printEmail(result.emails[i], i);
|
|
118
103
|
}
|
|
119
104
|
|
|
120
105
|
// 收到邮件后可以选择继续轮询或退出
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,118 @@
|
|
|
1
1
|
import { Channel, EmailInfo, GetEmailsResult, GenerateEmailOptions, GetEmailsOptions } from './types';
|
|
2
|
-
export { Channel, EmailInfo, Email, GetEmailsResult, GenerateEmailOptions, GetEmailsOptions } from './types';
|
|
2
|
+
export { Channel, EmailInfo, Email, EmailAttachment, GetEmailsResult, GenerateEmailOptions, GetEmailsOptions } from './types';
|
|
3
|
+
export { normalizeEmail } from './normalize';
|
|
4
|
+
export { withRetry, fetchWithTimeout, RetryOptions } from './retry';
|
|
5
|
+
export { LogLevel, LogHandler, setLogLevel, getLogLevel, setLogger, logger } from './logger';
|
|
6
|
+
/**
|
|
7
|
+
* 渠道信息,包含渠道标识、显示名称和对应网站
|
|
8
|
+
*/
|
|
3
9
|
export interface ChannelInfo {
|
|
10
|
+
/** 渠道标识 */
|
|
4
11
|
channel: Channel;
|
|
12
|
+
/** 渠道显示名称 */
|
|
5
13
|
name: string;
|
|
14
|
+
/** 对应的临时邮箱服务网站 */
|
|
6
15
|
website: string;
|
|
7
16
|
}
|
|
8
17
|
/**
|
|
9
18
|
* 获取所有支持的渠道列表
|
|
19
|
+
*
|
|
20
|
+
* @returns 所有渠道的信息数组
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const channels = listChannels();
|
|
25
|
+
* channels.forEach(ch => console.log(`${ch.name} (${ch.website})`));
|
|
26
|
+
* ```
|
|
10
27
|
*/
|
|
11
28
|
export declare function listChannels(): ChannelInfo[];
|
|
12
29
|
/**
|
|
13
|
-
*
|
|
30
|
+
* 获取指定渠道的详细信息
|
|
31
|
+
*
|
|
32
|
+
* @param channel - 渠道标识
|
|
33
|
+
* @returns 渠道信息,不存在时返回 undefined
|
|
14
34
|
*/
|
|
15
35
|
export declare function getChannelInfo(channel: Channel): ChannelInfo | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* 创建临时邮箱
|
|
38
|
+
*
|
|
39
|
+
* 错误处理策略:
|
|
40
|
+
* - 网络错误、超时、服务端 5xx 错误 → 自动重试(默认 2 次,指数退避)
|
|
41
|
+
* - 4xx 客户端错误、参数错误 → 直接抛出异常
|
|
42
|
+
*
|
|
43
|
+
* @param options - 创建选项,可指定渠道、有效时长、域名等
|
|
44
|
+
* @returns 邮箱信息,包含地址、令牌等
|
|
45
|
+
* @throws 重试耗尽后仍失败时抛出异常
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const emailInfo = await generateEmail({ channel: 'temp-mail-io' });
|
|
50
|
+
* console.log(emailInfo.email); // 临时邮箱地址
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
16
53
|
export declare function generateEmail(options?: GenerateEmailOptions): Promise<EmailInfo>;
|
|
54
|
+
/**
|
|
55
|
+
* 获取邮件列表
|
|
56
|
+
*
|
|
57
|
+
* 错误处理策略:
|
|
58
|
+
* - 网络错误、超时、服务端 5xx 错误 → 自动重试(默认 2 次)
|
|
59
|
+
* - 重试耗尽后返回 { success: false, emails: [] },不抛异常
|
|
60
|
+
* - 参数校验错误(缺少 channel / token)直接抛出
|
|
61
|
+
*
|
|
62
|
+
* 这种设计让调用方在轮询场景下不会因网络波动而中断整个流程,
|
|
63
|
+
* 只需检查 success 字段即可判断本次请求是否成功。
|
|
64
|
+
*
|
|
65
|
+
* @param options - 获取选项,包含渠道、邮箱地址、令牌
|
|
66
|
+
* @returns 邮件结果,包含 success 标记和邮件列表
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const result = await getEmails({
|
|
71
|
+
* channel: emailInfo.channel,
|
|
72
|
+
* email: emailInfo.email,
|
|
73
|
+
* token: emailInfo.token,
|
|
74
|
+
* });
|
|
75
|
+
* if (result.success && result.emails.length > 0) {
|
|
76
|
+
* console.log('收到邮件:', result.emails[0].subject);
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
17
80
|
export declare function getEmails(options: GetEmailsOptions): Promise<GetEmailsResult>;
|
|
81
|
+
/**
|
|
82
|
+
* 临时邮箱客户端
|
|
83
|
+
* 封装了邮箱创建和邮件获取的完整流程,自动管理邮箱信息和认证令牌
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const client = new TempEmailClient();
|
|
88
|
+
* const emailInfo = await client.generate({ channel: 'mail-tm' });
|
|
89
|
+
* console.log('邮箱:', emailInfo.email);
|
|
90
|
+
*
|
|
91
|
+
* // 轮询获取邮件
|
|
92
|
+
* const result = await client.getEmails();
|
|
93
|
+
* if (result.success) {
|
|
94
|
+
* console.log('邮件数:', result.emails.length);
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
18
98
|
export declare class TempEmailClient {
|
|
19
99
|
private emailInfo;
|
|
100
|
+
/**
|
|
101
|
+
* 创建临时邮箱并缓存邮箱信息
|
|
102
|
+
* 后续调用 getEmails() 时自动使用此邮箱的渠道、地址和令牌
|
|
103
|
+
*/
|
|
20
104
|
generate(options?: GenerateEmailOptions): Promise<EmailInfo>;
|
|
105
|
+
/**
|
|
106
|
+
* 获取当前邮箱的邮件列表
|
|
107
|
+
* 必须先调用 generate() 创建邮箱
|
|
108
|
+
*
|
|
109
|
+
* @throws 未调用 generate() 时抛出异常
|
|
110
|
+
*/
|
|
21
111
|
getEmails(): Promise<GetEmailsResult>;
|
|
112
|
+
/**
|
|
113
|
+
* 获取当前缓存的邮箱信息
|
|
114
|
+
* 未调用 generate() 时返回 null
|
|
115
|
+
*/
|
|
22
116
|
getEmailInfo(): EmailInfo | null;
|
|
23
117
|
}
|
|
24
118
|
declare const _default: {
|