tempmail-sdk 1.0.0 → 1.0.2

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.
Files changed (39) hide show
  1. package/README.md +243 -153
  2. package/demo/poll-emails.ts +172 -187
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +55 -4
  5. package/dist/normalize.d.ts +5 -0
  6. package/dist/normalize.js +87 -0
  7. package/dist/providers/awamail.d.ts +15 -0
  8. package/dist/providers/awamail.js +91 -0
  9. package/dist/providers/chatgpt-org-uk.js +4 -2
  10. package/dist/providers/dropmail.d.ts +13 -0
  11. package/dist/providers/dropmail.js +86 -0
  12. package/dist/providers/linshi-email.js +4 -2
  13. package/dist/providers/mail-tm.d.ts +11 -0
  14. package/dist/providers/mail-tm.js +167 -0
  15. package/dist/providers/temp-mail-io.d.ts +13 -0
  16. package/dist/providers/temp-mail-io.js +69 -0
  17. package/dist/providers/tempmail-la.d.ts +15 -0
  18. package/dist/providers/tempmail-la.js +89 -0
  19. package/dist/providers/tempmail-lol.d.ts +1 -1
  20. package/dist/providers/tempmail-lol.js +5 -3
  21. package/dist/providers/tempmail.js +4 -2
  22. package/dist/types.d.ts +31 -28
  23. package/dist/types.js +1 -1
  24. package/package.json +37 -37
  25. package/src/global.d.ts +5 -5
  26. package/src/index.ts +183 -133
  27. package/src/normalize.ts +80 -0
  28. package/src/providers/awamail.ts +101 -0
  29. package/src/providers/chatgpt-org-uk.ts +59 -57
  30. package/src/providers/dropmail.ts +98 -0
  31. package/src/providers/linshi-email.ts +63 -61
  32. package/src/providers/mail-tm.ts +188 -0
  33. package/src/providers/temp-mail-io.ts +76 -0
  34. package/src/providers/tempmail-la.ts +99 -0
  35. package/src/providers/tempmail-lol.ts +55 -53
  36. package/src/providers/tempmail.ts +61 -59
  37. package/src/types.ts +62 -58
  38. package/test/example.ts +63 -48
  39. package/tsconfig.json +27 -27
package/README.md CHANGED
@@ -1,153 +1,243 @@
1
- # temp-email-sdk
2
-
3
- 临时邮箱 SDK,支持多个邮箱服务提供商。
4
-
5
- ## 许可证
6
-
7
- GPL-3.0
8
-
9
- ## 安装
10
-
11
- ```bash
12
- npm install tempmail-sdk
13
- ```
14
-
15
- ## 支持的渠道
16
-
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 |
23
-
24
- ## 使用方法
25
-
26
- ### 列出所有提供商
27
-
28
- ```typescript
29
- import { listChannels, getChannelInfo } from 'temp-email-sdk';
30
-
31
- // 获取所有支持的渠道
32
- const channels = listChannels();
33
- console.log(channels);
34
- // [
35
- // { channel: 'tempmail', name: 'TempMail', website: 'tempmail.ing' },
36
- // { channel: 'linshi-email', name: '临时邮箱', website: 'linshi-email.com' },
37
- // { channel: 'tempmail-lol', name: 'TempMail LOL', website: 'tempmail.lol' },
38
- // { channel: 'chatgpt-org-uk', name: 'ChatGPT Mail', website: 'mail.chatgpt.org.uk' }
39
- // ]
40
-
41
- // 获取指定渠道信息
42
- const info = getChannelInfo('tempmail');
43
- console.log(info);
44
- // { channel: 'tempmail', name: 'TempMail', website: 'tempmail.ing' }
45
- ```
46
-
47
- ### 获取邮箱
48
-
49
- ```typescript
50
- import { generateEmail } from 'temp-email-sdk';
51
-
52
- // 从随机渠道获取邮箱
53
- const emailInfo = await generateEmail();
54
- console.log(emailInfo);
55
- // { channel: 'tempmail', email: 'xxx@ibymail.com', expiresAt: '...' }
56
-
57
- // 从指定渠道获取邮箱
58
- const emailInfo2 = await generateEmail({ channel: 'linshi-email' });
59
- console.log(emailInfo2);
60
- // { channel: 'linshi-email', email: 'xxx@iwatermail.com', expiresAt: 1768283576295 }
61
- ```
62
-
63
- ### 获取邮件
64
-
65
- ```typescript
66
- import { getEmails } from 'temp-email-sdk';
67
-
68
- // 查询邮件(需要传递渠道和邮箱)
69
- const result = await getEmails({
70
- channel: 'tempmail',
71
- email: 'xxx@ibymail.com'
72
- });
73
- console.log(result);
74
- // { channel: 'tempmail', email: 'xxx@ibymail.com', emails: [...], success: true }
75
-
76
- // tempmail-lol 渠道需要传递 token
77
- const result2 = await getEmails({
78
- channel: 'tempmail-lol',
79
- email: 'xxx@chessgameland.com',
80
- token: 'your-token-here'
81
- });
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
-
96
- // 获取邮件
97
- const result = await client.getEmails();
98
- console.log(`收到 ${result.emails.length} 封邮件`);
99
- ```
100
-
101
- ## API
102
-
103
- ### listChannels()
104
-
105
- 获取所有支持的渠道列表。
106
-
107
- **返回值:** `ChannelInfo[]`
108
- - `channel` - 渠道标识
109
- - `name` - 渠道名称
110
- - `website` - 服务商网站
111
-
112
- ### getChannelInfo(channel)
113
-
114
- 获取指定渠道信息。
115
-
116
- **参数:**
117
- - `channel` - 渠道标识
118
-
119
- **返回值:** `ChannelInfo | undefined`
120
-
121
- ### generateEmail(options?)
122
-
123
- 生成临时邮箱地址。
124
-
125
- **参数:**
126
- - `channel` - 指定渠道(可选,不指定则随机选择)
127
- - `duration` - 邮箱有效期,单位分钟(仅 `tempmail` 渠道支持)
128
- - `domain` - 指定域名(仅 `tempmail-lol` 渠道支持)
129
-
130
- **返回值:** `EmailInfo`
131
- - `channel` - 渠道名称
132
- - `email` - 邮箱地址
133
- - `token` - 访问收件箱的令牌(仅 `tempmail-lol` 渠道返回)
134
- - `expiresAt` - 过期时间
135
-
136
- ### getEmails(options)
137
-
138
- 获取指定邮箱的邮件列表。
139
-
140
- **参数(必填):**
141
- - `channel` - 渠道名称
142
- - `email` - 邮箱地址
143
- - `token` - 令牌(`tempmail-lol` 渠道必填)
144
-
145
- **返回值:** `GetEmailsResult`
146
- - `channel` - 渠道名称
147
- - `email` - 邮箱地址
148
- - `emails` - 邮件数组
149
- - `success` - 是否成功
150
-
151
- ## 环境要求
152
-
153
- - Node.js 18+(需要原生 fetch 支持)
1
+ # tempmail-sdk
2
+
3
+ [![npm version](https://badge.fury.io/js/tempmail-sdk.svg)](https://www.npmjs.com/package/tempmail-sdk)
4
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
5
+
6
+ 临时邮箱 SDK(TypeScript/Node.js),支持 9 个邮箱服务提供商,所有渠道返回**统一标准化格式**。
7
+
8
+ ## 安装
9
+
10
+ ```bash
11
+ npm install tempmail-sdk
12
+ ```
13
+
14
+ ## 支持的渠道
15
+
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} 封邮件`);
48
+
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
+ ```
58
+
59
+ ### 使用函数式 API
60
+
61
+ #### 列出所有渠道
62
+
63
+ ```typescript
64
+ import { listChannels, getChannelInfo } from 'tempmail-sdk';
65
+
66
+ const channels = listChannels();
67
+ console.log(channels);
68
+ // [
69
+ // { channel: 'tempmail', name: 'TempMail', website: 'tempmail.ing' },
70
+ // { channel: 'linshi-email', name: '临时邮箱', website: 'linshi-email.com' },
71
+ // { channel: 'tempmail-lol', name: 'TempMail LOL', website: 'tempmail.lol' },
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' }
78
+ // ]
79
+
80
+ const info = getChannelInfo('tempmail');
81
+ // { channel: 'tempmail', name: 'TempMail', website: 'tempmail.ing' }
82
+ ```
83
+
84
+ #### 获取邮箱
85
+
86
+ ```typescript
87
+ import { generateEmail } from 'tempmail-sdk';
88
+
89
+ // 从随机渠道获取邮箱
90
+ const emailInfo = await generateEmail();
91
+ console.log(emailInfo);
92
+ // { channel: 'tempmail', email: 'xxx@ibymail.com', expiresAt: '...' }
93
+
94
+ // 从指定渠道获取邮箱
95
+ const emailInfo2 = await generateEmail({ channel: 'linshi-email' });
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' });
102
+ ```
103
+
104
+ #### 获取邮件
105
+
106
+ ```typescript
107
+ import { getEmails } from 'tempmail-sdk';
108
+
109
+ // 不需要 Token 的渠道
110
+ const result = await getEmails({
111
+ channel: 'tempmail',
112
+ email: 'xxx@ibymail.com',
113
+ });
114
+ console.log(result.emails); // 标准化邮件数组
115
+
116
+ // 需要 Token 的渠道(token 由 generateEmail 返回)
117
+ const result2 = await getEmails({
118
+ channel: 'mail-tm',
119
+ email: emailInfo.email,
120
+ token: emailInfo.token, // Bearer Token
121
+ });
122
+
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
+ }
135
+ ```
136
+
137
+ ## API 参考
138
+
139
+ ### listChannels()
140
+
141
+ 获取所有支持的渠道列表。
142
+
143
+ **返回值:** `ChannelInfo[]`
144
+
145
+ | 字段 | 类型 | 说明 |
146
+ |------|------|------|
147
+ | `channel` | `Channel` | 渠道标识 |
148
+ | `name` | `string` | 渠道显示名称 |
149
+ | `website` | `string` | 服务商网站 |
150
+
151
+ ### getChannelInfo(channel)
152
+
153
+ 获取指定渠道信息。
154
+
155
+ **返回值:** `ChannelInfo | undefined`
156
+
157
+ ### generateEmail(options?)
158
+
159
+ 生成临时邮箱地址。
160
+
161
+ **参数:**
162
+
163
+ | 字段 | 类型 | 说明 |
164
+ |------|------|------|
165
+ | `channel` | `Channel` | 指定渠道(可选,不指定则随机) |
166
+ | `duration` | `number` | 有效期分钟数(仅 `tempmail` 渠道) |
167
+ | `domain` | `string` | 指定域名(仅 `tempmail-lol` 渠道) |
168
+
169
+ **返回值:** `EmailInfo`
170
+
171
+ | 字段 | 类型 | 说明 |
172
+ |------|------|------|
173
+ | `channel` | `Channel` | 渠道标识 |
174
+ | `email` | `string` | 邮箱地址 |
175
+ | `token` | `string?` | 访问令牌(部分渠道返回) |
176
+ | `expiresAt` | `string \| number?` | 过期时间 |
177
+ | `createdAt` | `string?` | 创建时间 |
178
+
179
+ ### getEmails(options)
180
+
181
+ 获取邮件列表。
182
+
183
+ **参数:**
184
+
185
+ | 字段 | 类型 | 必填 | 说明 |
186
+ |------|------|:----:|------|
187
+ | `channel` | `Channel` | ✅ | 渠道标识 |
188
+ | `email` | `string` | ✅ | 邮箱地址 |
189
+ | `token` | `string` | 部分 | 访问令牌(`tempmail-lol`、`awamail`、`mail-tm`、`dropmail` 必填) |
190
+
191
+ **返回值:** `GetEmailsResult`
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
+ ```
235
+
236
+ ## 环境要求
237
+
238
+ - Node.js 18+(需要原生 `fetch` 支持)
239
+ - TypeScript 5.0+(类型定义)
240
+
241
+ ## 许可证
242
+
243
+ GPL-3.0