tempmail-sdk 1.2.0 → 1.2.2-dev

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/src/retry.ts CHANGED
@@ -171,13 +171,48 @@ function getFetchConfig(): { fetchFn: typeof fetch; timeout: number } {
171
171
  return _cachedFetchConfig;
172
172
  }
173
173
 
174
+ /** Node 下跳过 TLS 证书校验(用于 10mail.wangtz.cn 等渠道默认行为) */
175
+ export interface FetchWithTimeoutOptions {
176
+ skipTlsVerify?: boolean;
177
+ }
178
+
179
+ function resolveFetchForTls(
180
+ baseFetch: typeof fetch,
181
+ skipTlsVerify: boolean | undefined,
182
+ ): typeof fetch {
183
+ if (!skipTlsVerify) {
184
+ return baseFetch;
185
+ }
186
+ if (typeof process === 'undefined' || !process.versions?.node) {
187
+ return baseFetch;
188
+ }
189
+ try {
190
+ // Node 18+ 内置 undici,用于 per-request 关闭证书校验(不修改全局 NODE_TLS_REJECT_UNAUTHORIZED)
191
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
192
+ const undici = require('undici') as {
193
+ Agent: new (opts: { connect: { rejectUnauthorized: boolean } }) => unknown;
194
+ fetch: (input: string, init?: Record<string, unknown>) => Promise<Response>;
195
+ };
196
+ const dispatcher = new undici.Agent({ connect: { rejectUnauthorized: false } });
197
+ return ((u: string, i?: RequestInit) =>
198
+ undici.fetch(u, {
199
+ ...(i as Record<string, unknown>),
200
+ dispatcher,
201
+ })) as typeof fetch;
202
+ } catch {
203
+ return baseFetch;
204
+ }
205
+ }
206
+
174
207
  export async function fetchWithTimeout(
175
208
  url: string,
176
209
  init?: RequestInit,
177
210
  timeoutMs?: number,
211
+ opts?: FetchWithTimeoutOptions,
178
212
  ): Promise<Response> {
179
213
  const { fetchFn, timeout: defaultTimeout } = getFetchConfig();
180
214
  const effectiveTimeout = timeoutMs ?? defaultTimeout;
215
+ const fetchImpl = resolveFetchForTls(fetchFn, opts?.skipTlsVerify);
181
216
  const controller = new AbortController();
182
217
  const timeoutId = setTimeout(() => controller.abort(), effectiveTimeout);
183
218
 
@@ -191,7 +226,7 @@ export async function fetchWithTimeout(
191
226
  }
192
227
 
193
228
  try {
194
- const response = await fetchFn(url, {
229
+ const response = await fetchImpl(url, {
195
230
  ...init,
196
231
  signal: controller.signal,
197
232
  });
package/src/types.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * 支持的临时邮箱渠道标识
3
3
  * 每个渠道对应一个第三方临时邮箱服务商
4
4
  */
5
- export type Channel = 'tempmail' | 'tempmail-cn' | 'linshi-email' | 'linshiyou' | 'mffac' | 'tempmail-lol' | 'chatgpt-org-uk' | 'temp-mail-io' | 'awamail' | 'temporary-email-org' | 'mail-tm' | 'mail-cx' | 'dropmail' | 'guerrillamail' | 'maildrop' | 'smail-pw' | 'boomlify' | 'minmail' | 'vip-215' | 'anonbox' | 'fake-legal';
5
+ export type Channel = 'tempmail' | 'tempmail-cn' | 'tmpmails' | 'tempmailg' | 'ta-easy' | '10mail-wangtz' | '10minute-one' | 'linshi-email' | 'linshiyou' | 'mffac' | 'tempmail-lol' | 'chatgpt-org-uk' | 'temp-mail-io' | 'awamail' | 'temporary-email-org' | 'mail-tm' | 'mail-cx' | 'dropmail' | 'guerrillamail' | 'maildrop' | 'smail-pw' | 'boomlify' | 'minmail' | 'vip-215' | 'anonbox' | 'fake-legal' | 'moakt';
6
6
 
7
7
  /**
8
8
  * 创建临时邮箱后返回的邮箱信息