@h-ai/reach 0.1.0-alpha5
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/LICENSE +202 -0
- package/README.md +161 -0
- package/dist/index.d.ts +468 -0
- package/dist/index.js +1324 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as _h_ai_core from '@h-ai/core';
|
|
3
|
+
import { HaiResult } from '@h-ai/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @h-ai/reach — 配置 Schema
|
|
7
|
+
*
|
|
8
|
+
* 本文件定义触达模块的错误码、Zod Schema 和配置类型。
|
|
9
|
+
* @module reach-config
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Console Provider 配置(开发/测试用,将消息输出到日志)
|
|
14
|
+
*/
|
|
15
|
+
declare const ConsoleProviderConfigSchema: z.ZodObject<{
|
|
16
|
+
name: z.ZodString;
|
|
17
|
+
type: z.ZodLiteral<"console">;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/**
|
|
20
|
+
* SMTP 邮件 Provider 配置
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* {
|
|
25
|
+
* name: 'email',
|
|
26
|
+
* type: 'smtp',
|
|
27
|
+
* host: 'smtp.example.com',
|
|
28
|
+
* port: 465,
|
|
29
|
+
* secure: true,
|
|
30
|
+
* user: 'noreply@example.com',
|
|
31
|
+
* pass: 'password',
|
|
32
|
+
* from: 'noreply@example.com'
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare const SmtpProviderConfigSchema: z.ZodObject<{
|
|
37
|
+
name: z.ZodString;
|
|
38
|
+
type: z.ZodLiteral<"smtp">;
|
|
39
|
+
host: z.ZodString;
|
|
40
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
41
|
+
secure: z.ZodDefault<z.ZodBoolean>;
|
|
42
|
+
user: z.ZodOptional<z.ZodString>;
|
|
43
|
+
pass: z.ZodOptional<z.ZodString>;
|
|
44
|
+
from: z.ZodString;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
/**
|
|
47
|
+
* 阿里云短信 Provider 配置(通过 HTTP API 调用,无需 SDK)
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* {
|
|
52
|
+
* name: 'sms',
|
|
53
|
+
* type: 'aliyun-sms',
|
|
54
|
+
* accessKeyId: 'LTAI...',
|
|
55
|
+
* accessKeySecret: '...',
|
|
56
|
+
* signName: '某某科技',
|
|
57
|
+
* endpoint: 'dysmsapi.aliyuncs.com'
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
declare const AliyunSmsProviderConfigSchema: z.ZodObject<{
|
|
62
|
+
name: z.ZodString;
|
|
63
|
+
type: z.ZodLiteral<"aliyun-sms">;
|
|
64
|
+
accessKeyId: z.ZodString;
|
|
65
|
+
accessKeySecret: z.ZodString;
|
|
66
|
+
signName: z.ZodString;
|
|
67
|
+
endpoint: z.ZodDefault<z.ZodString>;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
/**
|
|
70
|
+
* API 回调 Provider 配置(通用 HTTP 回调)
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* {
|
|
75
|
+
* name: 'webhook',
|
|
76
|
+
* type: 'api',
|
|
77
|
+
* url: 'https://api.example.com/notify',
|
|
78
|
+
* method: 'POST',
|
|
79
|
+
* headers: { 'Authorization': 'Bearer xxx' }
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare const ApiProviderConfigSchema: z.ZodObject<{
|
|
84
|
+
name: z.ZodString;
|
|
85
|
+
type: z.ZodLiteral<"api">;
|
|
86
|
+
url: z.ZodString;
|
|
87
|
+
method: z.ZodDefault<z.ZodEnum<{
|
|
88
|
+
POST: "POST";
|
|
89
|
+
PUT: "PUT";
|
|
90
|
+
}>>;
|
|
91
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
92
|
+
timeout: z.ZodDefault<z.ZodNumber>;
|
|
93
|
+
}, z.core.$strip>;
|
|
94
|
+
/**
|
|
95
|
+
* 单个 Provider 配置 Schema(判别联合体)
|
|
96
|
+
*/
|
|
97
|
+
declare const ProviderConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
98
|
+
name: z.ZodString;
|
|
99
|
+
type: z.ZodLiteral<"console">;
|
|
100
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
101
|
+
name: z.ZodString;
|
|
102
|
+
type: z.ZodLiteral<"smtp">;
|
|
103
|
+
host: z.ZodString;
|
|
104
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
105
|
+
secure: z.ZodDefault<z.ZodBoolean>;
|
|
106
|
+
user: z.ZodOptional<z.ZodString>;
|
|
107
|
+
pass: z.ZodOptional<z.ZodString>;
|
|
108
|
+
from: z.ZodString;
|
|
109
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
110
|
+
name: z.ZodString;
|
|
111
|
+
type: z.ZodLiteral<"aliyun-sms">;
|
|
112
|
+
accessKeyId: z.ZodString;
|
|
113
|
+
accessKeySecret: z.ZodString;
|
|
114
|
+
signName: z.ZodString;
|
|
115
|
+
endpoint: z.ZodDefault<z.ZodString>;
|
|
116
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
117
|
+
name: z.ZodString;
|
|
118
|
+
type: z.ZodLiteral<"api">;
|
|
119
|
+
url: z.ZodString;
|
|
120
|
+
method: z.ZodDefault<z.ZodEnum<{
|
|
121
|
+
POST: "POST";
|
|
122
|
+
PUT: "PUT";
|
|
123
|
+
}>>;
|
|
124
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
125
|
+
timeout: z.ZodDefault<z.ZodNumber>;
|
|
126
|
+
}, z.core.$strip>], "type">;
|
|
127
|
+
/** 单个 Provider 配置类型(parse 后) */
|
|
128
|
+
type ProviderConfig = z.infer<typeof ProviderConfigSchema>;
|
|
129
|
+
/** Console 配置类型 */
|
|
130
|
+
type ConsoleProviderConfig = z.infer<typeof ConsoleProviderConfigSchema>;
|
|
131
|
+
/** SMTP 配置类型 */
|
|
132
|
+
type SmtpProviderConfig = z.infer<typeof SmtpProviderConfigSchema>;
|
|
133
|
+
/** 阿里云短信配置类型 */
|
|
134
|
+
type AliyunSmsProviderConfig = z.infer<typeof AliyunSmsProviderConfigSchema>;
|
|
135
|
+
/** API 回调配置类型 */
|
|
136
|
+
type ApiProviderConfig = z.infer<typeof ApiProviderConfigSchema>;
|
|
137
|
+
/**
|
|
138
|
+
* 免打扰时间段配置
|
|
139
|
+
*
|
|
140
|
+
* 在指定的时间段内,根据策略处理消息:
|
|
141
|
+
* - `discard`:直接丢弃,返回 DND_BLOCKED 错误
|
|
142
|
+
* - `delay`:暂存到数据库(状态为 pending),DND 结束后由定时任务集中发送
|
|
143
|
+
*
|
|
144
|
+
* 时间使用 HH:mm 格式(24 小时制),支持跨午夜(如 22:00-08:00)。
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* {
|
|
149
|
+
* enabled: true,
|
|
150
|
+
* strategy: 'delay',
|
|
151
|
+
* start: '22:00',
|
|
152
|
+
* end: '08:00'
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare const DndConfigSchema: z.ZodObject<{
|
|
157
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
158
|
+
strategy: z.ZodDefault<z.ZodEnum<{
|
|
159
|
+
discard: "discard";
|
|
160
|
+
delay: "delay";
|
|
161
|
+
}>>;
|
|
162
|
+
start: z.ZodDefault<z.ZodString>;
|
|
163
|
+
end: z.ZodDefault<z.ZodString>;
|
|
164
|
+
}, z.core.$strip>;
|
|
165
|
+
/** DND 配置类型 */
|
|
166
|
+
type DndConfig = z.infer<typeof DndConfigSchema>;
|
|
167
|
+
/**
|
|
168
|
+
* 模板配置 Schema(通过配置文件定义模板)
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```yaml
|
|
172
|
+
* templates:
|
|
173
|
+
* - name: verification_code
|
|
174
|
+
* provider: email
|
|
175
|
+
* subject: "验证码: {code}"
|
|
176
|
+
* body: "您的验证码是 {code},有效期 {minutes} 分钟。"
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
declare const TemplateConfigSchema: z.ZodObject<{
|
|
180
|
+
name: z.ZodString;
|
|
181
|
+
provider: z.ZodString;
|
|
182
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
183
|
+
body: z.ZodString;
|
|
184
|
+
}, z.core.$strip>;
|
|
185
|
+
/** 模板配置类型 */
|
|
186
|
+
type TemplateConfig = z.infer<typeof TemplateConfigSchema>;
|
|
187
|
+
/**
|
|
188
|
+
* 触达模块配置 Schema
|
|
189
|
+
*
|
|
190
|
+
* 接受一个 Provider 配置数组,支持同时注册多个 Provider。
|
|
191
|
+
* 支持通过配置文件定义模板和免打扰时间段。
|
|
192
|
+
*/
|
|
193
|
+
declare const ReachConfigSchema: z.ZodObject<{
|
|
194
|
+
providers: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
195
|
+
name: z.ZodString;
|
|
196
|
+
type: z.ZodLiteral<"console">;
|
|
197
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
198
|
+
name: z.ZodString;
|
|
199
|
+
type: z.ZodLiteral<"smtp">;
|
|
200
|
+
host: z.ZodString;
|
|
201
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
202
|
+
secure: z.ZodDefault<z.ZodBoolean>;
|
|
203
|
+
user: z.ZodOptional<z.ZodString>;
|
|
204
|
+
pass: z.ZodOptional<z.ZodString>;
|
|
205
|
+
from: z.ZodString;
|
|
206
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
207
|
+
name: z.ZodString;
|
|
208
|
+
type: z.ZodLiteral<"aliyun-sms">;
|
|
209
|
+
accessKeyId: z.ZodString;
|
|
210
|
+
accessKeySecret: z.ZodString;
|
|
211
|
+
signName: z.ZodString;
|
|
212
|
+
endpoint: z.ZodDefault<z.ZodString>;
|
|
213
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
214
|
+
name: z.ZodString;
|
|
215
|
+
type: z.ZodLiteral<"api">;
|
|
216
|
+
url: z.ZodString;
|
|
217
|
+
method: z.ZodDefault<z.ZodEnum<{
|
|
218
|
+
POST: "POST";
|
|
219
|
+
PUT: "PUT";
|
|
220
|
+
}>>;
|
|
221
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
222
|
+
timeout: z.ZodDefault<z.ZodNumber>;
|
|
223
|
+
}, z.core.$strip>], "type">>;
|
|
224
|
+
templates: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
225
|
+
name: z.ZodString;
|
|
226
|
+
provider: z.ZodString;
|
|
227
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
228
|
+
body: z.ZodString;
|
|
229
|
+
}, z.core.$strip>>>;
|
|
230
|
+
dnd: z.ZodOptional<z.ZodObject<{
|
|
231
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
232
|
+
strategy: z.ZodDefault<z.ZodEnum<{
|
|
233
|
+
discard: "discard";
|
|
234
|
+
delay: "delay";
|
|
235
|
+
}>>;
|
|
236
|
+
start: z.ZodDefault<z.ZodString>;
|
|
237
|
+
end: z.ZodDefault<z.ZodString>;
|
|
238
|
+
}, z.core.$strip>>;
|
|
239
|
+
}, z.core.$strip>;
|
|
240
|
+
/** 触达模块配置类型(parse 后) */
|
|
241
|
+
type ReachConfig = z.infer<typeof ReachConfigSchema>;
|
|
242
|
+
/**
|
|
243
|
+
* 触达模块配置输入类型
|
|
244
|
+
*/
|
|
245
|
+
type ReachConfigInput = z.input<typeof ReachConfigSchema>;
|
|
246
|
+
|
|
247
|
+
declare const HaiReachError: {
|
|
248
|
+
readonly SEND_FAILED: _h_ai_core.HaiErrorDef;
|
|
249
|
+
readonly TEMPLATE_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
250
|
+
readonly TEMPLATE_RENDER_FAILED: _h_ai_core.HaiErrorDef;
|
|
251
|
+
readonly INVALID_RECIPIENT: _h_ai_core.HaiErrorDef;
|
|
252
|
+
readonly PROVIDER_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
253
|
+
readonly DND_BLOCKED: _h_ai_core.HaiErrorDef;
|
|
254
|
+
readonly DND_DEFERRED: _h_ai_core.HaiErrorDef;
|
|
255
|
+
readonly NOT_INITIALIZED: _h_ai_core.HaiErrorDef;
|
|
256
|
+
readonly UNSUPPORTED_TYPE: _h_ai_core.HaiErrorDef;
|
|
257
|
+
readonly CONFIG_ERROR: _h_ai_core.HaiErrorDef;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* 触达渠道类型
|
|
261
|
+
*
|
|
262
|
+
* - `email` — 邮件
|
|
263
|
+
* - `sms` — 短信
|
|
264
|
+
* - `api` — API 回调
|
|
265
|
+
*/
|
|
266
|
+
type ReachChannel = 'email' | 'sms' | 'api';
|
|
267
|
+
/**
|
|
268
|
+
* 触达消息(发送请求)
|
|
269
|
+
*
|
|
270
|
+
* 通过 `provider` 字段指定目标 Provider,通过 `template` 字段指定模板。
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* // 使用模板发送邮件
|
|
275
|
+
* const msg: ReachMessage = {
|
|
276
|
+
* provider: 'email',
|
|
277
|
+
* to: 'user@example.com',
|
|
278
|
+
* template: 'welcome',
|
|
279
|
+
* vars: { userName: '张三' },
|
|
280
|
+
* }
|
|
281
|
+
*
|
|
282
|
+
* // 使用模板发送短信
|
|
283
|
+
* const msg: ReachMessage = {
|
|
284
|
+
* provider: 'sms',
|
|
285
|
+
* to: '13800138000',
|
|
286
|
+
* template: 'verification_code',
|
|
287
|
+
* vars: { code: '123456' },
|
|
288
|
+
* }
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
interface ReachMessage {
|
|
292
|
+
/** 目标 Provider 名称(对应 Provider 配置中的 name) */
|
|
293
|
+
provider: string;
|
|
294
|
+
/** 接收方(邮箱地址或手机号) */
|
|
295
|
+
to: string;
|
|
296
|
+
/** 邮件主题(直接发送时使用) */
|
|
297
|
+
subject?: string;
|
|
298
|
+
/** 消息正文(直接发送时使用) */
|
|
299
|
+
body?: string;
|
|
300
|
+
/** 模板名称(使用模板发送时指定) */
|
|
301
|
+
template?: string;
|
|
302
|
+
/** 模板变量(使用模板发送时传入) */
|
|
303
|
+
vars?: Record<string, string>;
|
|
304
|
+
/** Provider 扩展参数(如短信 Provider 的模板编码、签名等) */
|
|
305
|
+
extra?: Record<string, unknown>;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* 发送结果
|
|
309
|
+
*/
|
|
310
|
+
interface SendResult {
|
|
311
|
+
/** 是否发送成功 */
|
|
312
|
+
success: boolean;
|
|
313
|
+
/** Provider 返回的消息 ID(如有) */
|
|
314
|
+
messageId?: string;
|
|
315
|
+
/** 是否被延时(DND delay 策略暂存,待 DND 结束后发送) */
|
|
316
|
+
deferred?: boolean;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* 触达模板定义
|
|
320
|
+
*
|
|
321
|
+
* 每个模板绑定到一个 Provider,发送时按模板中的 `provider` 路由。
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```ts
|
|
325
|
+
* const template: ReachTemplate = {
|
|
326
|
+
* name: 'verification_code',
|
|
327
|
+
* provider: 'email',
|
|
328
|
+
* subject: '验证码: {code}',
|
|
329
|
+
* body: '您的验证码是 {code},有效期 {minutes} 分钟。',
|
|
330
|
+
* }
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
interface ReachTemplate {
|
|
334
|
+
/** 模板名称(唯一标识) */
|
|
335
|
+
name: string;
|
|
336
|
+
/** 绑定的 Provider 名称 */
|
|
337
|
+
provider: string;
|
|
338
|
+
/** 邮件主题模板(支持 `{var}` 占位符,仅 email) */
|
|
339
|
+
subject?: string;
|
|
340
|
+
/** 消息正文模板(支持 `{var}` 占位符) */
|
|
341
|
+
body: string;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* 渲染后的模板
|
|
345
|
+
*/
|
|
346
|
+
interface RenderedTemplate {
|
|
347
|
+
/** 渲染后的主题 */
|
|
348
|
+
subject?: string;
|
|
349
|
+
/** 渲染后的正文 */
|
|
350
|
+
body: string;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* 发送操作接口
|
|
354
|
+
*/
|
|
355
|
+
interface SendOperations {
|
|
356
|
+
/**
|
|
357
|
+
* 发送触达消息
|
|
358
|
+
*
|
|
359
|
+
* @param message - 触达消息
|
|
360
|
+
* @returns 发送结果
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```ts
|
|
364
|
+
* const result = await reach.send({
|
|
365
|
+
* provider: 'email',
|
|
366
|
+
* to: 'user@example.com',
|
|
367
|
+
* template: 'welcome',
|
|
368
|
+
* vars: { userName: '张三' },
|
|
369
|
+
* })
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
send: (message: ReachMessage) => Promise<HaiResult<SendResult>>;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* 模板注册表接口
|
|
376
|
+
*
|
|
377
|
+
* 所有模板通过数据库持久化存储,避免节点间状态不一致。
|
|
378
|
+
* 配置文件中的模板在 init 时写入数据库。
|
|
379
|
+
*/
|
|
380
|
+
interface ReachTemplateRegistry {
|
|
381
|
+
/** 按名称解析模板 */
|
|
382
|
+
resolve: (name: string) => Promise<HaiResult<ReachTemplate>>;
|
|
383
|
+
/** 保存模板到数据库(upsert) */
|
|
384
|
+
save: (template: ReachTemplate) => Promise<HaiResult<void>>;
|
|
385
|
+
/** 批量保存模板到数据库 */
|
|
386
|
+
saveBatch: (templates: ReachTemplate[]) => Promise<HaiResult<void>>;
|
|
387
|
+
/** 从数据库删除模板 */
|
|
388
|
+
remove: (name: string) => Promise<HaiResult<void>>;
|
|
389
|
+
/** 列出所有模板 */
|
|
390
|
+
list: () => Promise<HaiResult<ReachTemplate[]>>;
|
|
391
|
+
/** 渲染模板(从数据库解析后渲染) */
|
|
392
|
+
render: (name: string, vars: Record<string, string>) => Promise<HaiResult<RenderedTemplate>>;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* 触达模块函数接口
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```ts
|
|
399
|
+
* import { reach } from '@h-ai/reach'
|
|
400
|
+
*
|
|
401
|
+
* // 初始化(同时注册多个 Provider)
|
|
402
|
+
* await reach.init({
|
|
403
|
+
* providers: [
|
|
404
|
+
* { name: 'email', type: 'smtp', host: 'smtp.example.com', from: 'no-reply@example.com' },
|
|
405
|
+
* { name: 'sms', type: 'aliyun-sms', accessKeyId: '...', accessKeySecret: '...', signName: '...' },
|
|
406
|
+
* ],
|
|
407
|
+
* })
|
|
408
|
+
*
|
|
409
|
+
* // 保存模板(绑定到 Provider)
|
|
410
|
+
* await reach.template.save({
|
|
411
|
+
* name: 'welcome',
|
|
412
|
+
* provider: 'email',
|
|
413
|
+
* subject: '欢迎 {userName}',
|
|
414
|
+
* body: '亲爱的 {userName},欢迎使用我们的服务!',
|
|
415
|
+
* })
|
|
416
|
+
*
|
|
417
|
+
* // 发送(指定 Provider)
|
|
418
|
+
* await reach.send({ provider: 'email', to: 'user@example.com', template: 'welcome', vars: { userName: '张三' } })
|
|
419
|
+
*
|
|
420
|
+
* // 关闭
|
|
421
|
+
* await reach.close()
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
interface ReachFunctions extends SendOperations {
|
|
425
|
+
/** 初始化触达模块(注册多个 Provider) */
|
|
426
|
+
init: (config: ReachConfigInput) => Promise<HaiResult<void>>;
|
|
427
|
+
/** 当前配置(未初始化时为 null) */
|
|
428
|
+
readonly config: ReachConfig | null;
|
|
429
|
+
/** 是否已初始化 */
|
|
430
|
+
readonly isInitialized: boolean;
|
|
431
|
+
/** 模板注册表 */
|
|
432
|
+
readonly template: ReachTemplateRegistry;
|
|
433
|
+
/** 关闭连接并释放资源 */
|
|
434
|
+
close: () => Promise<void>;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* 触达 Provider 接口
|
|
438
|
+
*
|
|
439
|
+
* 由具体实现(console / smtp / aliyun-sms / api)提供。
|
|
440
|
+
*/
|
|
441
|
+
interface ReachProvider {
|
|
442
|
+
/** Provider 名称 */
|
|
443
|
+
readonly name: string;
|
|
444
|
+
/** 连接/初始化 Provider */
|
|
445
|
+
connect: (config: ProviderConfig) => Promise<HaiResult<void>>;
|
|
446
|
+
/** 发送消息 */
|
|
447
|
+
send: (message: ReachMessage) => Promise<HaiResult<SendResult>>;
|
|
448
|
+
/** 关闭连接 */
|
|
449
|
+
close: () => Promise<void>;
|
|
450
|
+
/** 是否已连接 */
|
|
451
|
+
isConnected: () => boolean;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* @h-ai/reach — 触达服务主入口
|
|
456
|
+
*
|
|
457
|
+
* 本文件提供统一的 `reach` 对象,聚合模块生命周期管理。
|
|
458
|
+
* @module reach-main
|
|
459
|
+
*/
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* 触达服务对象
|
|
463
|
+
*
|
|
464
|
+
* 统一的用户触达入口,支持同时使用邮件、短信、API 回调等多种 Provider。
|
|
465
|
+
*/
|
|
466
|
+
declare const reach: ReachFunctions;
|
|
467
|
+
|
|
468
|
+
export { type AliyunSmsProviderConfig, AliyunSmsProviderConfigSchema, type ApiProviderConfig, ApiProviderConfigSchema, type ConsoleProviderConfig, ConsoleProviderConfigSchema, type DndConfig, DndConfigSchema, HaiReachError, type ProviderConfig, ProviderConfigSchema, type ReachChannel, type ReachConfig, type ReachConfigInput, ReachConfigSchema, type ReachFunctions, type ReachMessage, type ReachProvider, type ReachTemplate, type ReachTemplateRegistry, type RenderedTemplate, type SendOperations, type SendResult, type SmtpProviderConfig, SmtpProviderConfigSchema, type TemplateConfig, TemplateConfigSchema, reach };
|