wjx-api-sdk 0.1.1
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 +21 -0
- package/README.md +300 -0
- package/dist/core/api-client.d.ts +13 -0
- package/dist/core/api-client.js +141 -0
- package/dist/core/api-client.js.map +1 -0
- package/dist/core/constants.d.ts +61 -0
- package/dist/core/constants.js +82 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/types.d.ts +26 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/analytics/compute.d.ts +14 -0
- package/dist/modules/analytics/compute.js +205 -0
- package/dist/modules/analytics/compute.js.map +1 -0
- package/dist/modules/analytics/push-decode.d.ts +12 -0
- package/dist/modules/analytics/push-decode.js +46 -0
- package/dist/modules/analytics/push-decode.js.map +1 -0
- package/dist/modules/analytics/types.d.ts +61 -0
- package/dist/modules/analytics/types.js +3 -0
- package/dist/modules/analytics/types.js.map +1 -0
- package/dist/modules/contacts/client.d.ts +16 -0
- package/dist/modules/contacts/client.js +129 -0
- package/dist/modules/contacts/client.js.map +1 -0
- package/dist/modules/contacts/types.d.ts +62 -0
- package/dist/modules/contacts/types.js +2 -0
- package/dist/modules/contacts/types.js.map +1 -0
- package/dist/modules/multi-user/client.d.ts +7 -0
- package/dist/modules/multi-user/client.js +70 -0
- package/dist/modules/multi-user/client.js.map +1 -0
- package/dist/modules/multi-user/types.d.ts +31 -0
- package/dist/modules/multi-user/types.js +2 -0
- package/dist/modules/multi-user/types.js.map +1 -0
- package/dist/modules/response/client.d.ts +12 -0
- package/dist/modules/response/client.js +169 -0
- package/dist/modules/response/client.js.map +1 -0
- package/dist/modules/response/types.d.ts +83 -0
- package/dist/modules/response/types.js +2 -0
- package/dist/modules/response/types.js.map +1 -0
- package/dist/modules/sso/client.d.ts +22 -0
- package/dist/modules/sso/client.js +101 -0
- package/dist/modules/sso/client.js.map +1 -0
- package/dist/modules/sso/types.d.ts +75 -0
- package/dist/modules/sso/types.js +2 -0
- package/dist/modules/sso/types.js.map +1 -0
- package/dist/modules/survey/client.d.ts +13 -0
- package/dist/modules/survey/client.js +140 -0
- package/dist/modules/survey/client.js.map +1 -0
- package/dist/modules/survey/survey-to-text.d.ts +17 -0
- package/dist/modules/survey/survey-to-text.js +237 -0
- package/dist/modules/survey/survey-to-text.js.map +1 -0
- package/dist/modules/survey/text-to-survey.d.ts +9 -0
- package/dist/modules/survey/text-to-survey.js +175 -0
- package/dist/modules/survey/text-to-survey.js.map +1 -0
- package/dist/modules/survey/types.d.ts +170 -0
- package/dist/modules/survey/types.js +2 -0
- package/dist/modules/survey/types.js.map +1 -0
- package/dist/modules/user-system/client.d.ts +8 -0
- package/dist/modules/user-system/client.js +76 -0
- package/dist/modules/user-system/client.js.map +1 -0
- package/dist/modules/user-system/types.d.ts +41 -0
- package/dist/modules/user-system/types.js +2 -0
- package/dist/modules/user-system/types.js.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wjx-ai-kit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
# wjx-api-sdk
|
|
2
|
+
|
|
3
|
+
> 问卷星 OpenAPI TypeScript SDK — 零依赖、类型安全、ESM-only。
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 特性
|
|
11
|
+
|
|
12
|
+
- **零运行时依赖** — 仅使用 Node.js 内置 `fetch`,无需安装任何第三方包
|
|
13
|
+
- **完整类型定义** — 所有输入/输出均有 TypeScript 类型,IDE 自动补全
|
|
14
|
+
- **8 大模块、50+ 函数** — 覆盖问卷星 OpenAPI 全部功能
|
|
15
|
+
- **ESM-only** — 原生 ES Module,`import` 直接使用
|
|
16
|
+
- **可测试设计** — 所有函数支持注入 `credentials` 和 `fetchImpl`
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 安装
|
|
21
|
+
|
|
22
|
+
作为 `wjx-ai-kit` monorepo 的一部分:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
git clone <your-repo-url>
|
|
26
|
+
cd wjx-ai-kit
|
|
27
|
+
npm install
|
|
28
|
+
npm run build --workspace=wjx-api-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 快速开始
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { listSurveys, getSurvey, createSurvey } from "wjx-api-sdk";
|
|
37
|
+
|
|
38
|
+
const creds = { token: process.env.WJX_TOKEN! };
|
|
39
|
+
|
|
40
|
+
// 列出问卷
|
|
41
|
+
const list = await listSurveys({ page_index: 1, page_size: 10 }, creds);
|
|
42
|
+
console.log(list);
|
|
43
|
+
|
|
44
|
+
// 获取问卷详情
|
|
45
|
+
const detail = await getSurvey({ vid: 12345 }, creds);
|
|
46
|
+
|
|
47
|
+
// 创建问卷
|
|
48
|
+
const created = await createSurvey({
|
|
49
|
+
title: "客户满意度调查",
|
|
50
|
+
type: 0,
|
|
51
|
+
description: "2026年Q1客户满意度",
|
|
52
|
+
questions: "[]",
|
|
53
|
+
}, creds);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 认证
|
|
59
|
+
|
|
60
|
+
### 方式一:直接传入(推荐)
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const creds = { token: "your_token" };
|
|
64
|
+
const result = await listSurveys({ page_index: 1 }, creds);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 方式二:环境变量
|
|
68
|
+
|
|
69
|
+
设置 `WJX_TOKEN` 环境变量后,可省略 `credentials` 参数:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
export WJX_TOKEN=your_token
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
// 自动从 WJX_TOKEN 读取
|
|
77
|
+
const result = await listSurveys({ page_index: 1 });
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 方式三:自定义 Provider
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { setCredentialProvider } from "wjx-api-sdk";
|
|
84
|
+
|
|
85
|
+
setCredentialProvider(() => ({
|
|
86
|
+
token: getTokenFromVault(),
|
|
87
|
+
}));
|
|
88
|
+
|
|
89
|
+
// 后续调用自动使用 provider
|
|
90
|
+
const result = await listSurveys({ page_index: 1 });
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## API 参考
|
|
96
|
+
|
|
97
|
+
### 统一函数签名
|
|
98
|
+
|
|
99
|
+
所有 SDK 函数遵循统一的 3 参数模式:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
async function sdkFunction(
|
|
103
|
+
input: InputType, // 请求参数
|
|
104
|
+
credentials: WjxCredentials = getWjxCredentials(), // 认证凭据
|
|
105
|
+
fetchImpl: FetchLike = fetch, // 可选:注入 fetch 实现
|
|
106
|
+
): Promise<WjxApiResponse<T>>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Core — 核心
|
|
110
|
+
|
|
111
|
+
| 函数 | 说明 |
|
|
112
|
+
|------|------|
|
|
113
|
+
| `callWjxApi(action, params, creds, opts?)` | 底层 API 调用(签名、重试、超时) |
|
|
114
|
+
| `callWjxUserSystemApi(...)` | 用户体系 API 调用 |
|
|
115
|
+
| `callWjxSubuserApi(...)` | 子账号 API 调用 |
|
|
116
|
+
| `callWjxContactsApi(...)` | 通讯录 API 调用 |
|
|
117
|
+
| `setCredentialProvider(fn)` | 设置全局凭据 Provider |
|
|
118
|
+
| `getWjxCredentials()` | 获取当前凭据 |
|
|
119
|
+
| `validateQuestionsJson(json)` | 验证题目 JSON 格式 |
|
|
120
|
+
| `getCorpId(creds)` | 获取企业 ID |
|
|
121
|
+
|
|
122
|
+
### Survey — 问卷管理(11 函数)
|
|
123
|
+
|
|
124
|
+
| 函数 | 说明 |
|
|
125
|
+
|------|------|
|
|
126
|
+
| `listSurveys(input)` | 列出问卷列表 |
|
|
127
|
+
| `getSurvey(input)` | 获取问卷详情 |
|
|
128
|
+
| `createSurvey(input)` | 创建问卷 |
|
|
129
|
+
| `updateSurveyStatus(input)` | 更新问卷状态(发布/暂停/删除) |
|
|
130
|
+
| `getSurveySettings(input)` | 获取问卷设置 |
|
|
131
|
+
| `updateSurveySettings(input)` | 更新问卷设置 |
|
|
132
|
+
| `deleteSurvey(input)` | 删除问卷 |
|
|
133
|
+
| `getQuestionTags(input)` | 获取题目标签 |
|
|
134
|
+
| `getTagDetails(input)` | 获取标签详情 |
|
|
135
|
+
| `clearRecycleBin(input)` | 清空回收站 |
|
|
136
|
+
| `uploadFile(input)` | 上传文件 |
|
|
137
|
+
|
|
138
|
+
### Survey — DSL 转换器
|
|
139
|
+
|
|
140
|
+
| 函数 | 说明 |
|
|
141
|
+
|------|------|
|
|
142
|
+
| `surveyToText(survey)` | 将问卷结构转为纯文本 DSL |
|
|
143
|
+
| `textToSurvey(text)` | 将纯文本 DSL 解析为 `ParsedSurvey` |
|
|
144
|
+
| `typeToLabel(type)` | 题型代码转可读标签 |
|
|
145
|
+
| `stripHtml(html)` | 去除 HTML 标签 |
|
|
146
|
+
|
|
147
|
+
### Response — 答卷数据(10 函数)
|
|
148
|
+
|
|
149
|
+
| 函数 | 说明 |
|
|
150
|
+
|------|------|
|
|
151
|
+
| `queryResponses(input)` | 查询答卷(分页) |
|
|
152
|
+
| `queryResponsesRealtime(input)` | 实时查询答卷 |
|
|
153
|
+
| `downloadResponses(input)` | 下载答卷数据 |
|
|
154
|
+
| `getReport(input)` | 获取统计报告 |
|
|
155
|
+
| `submitResponse(input)` | 代填提交答卷 |
|
|
156
|
+
| `getFileLinks(input)` | 获取文件链接 |
|
|
157
|
+
| `getWinners(input)` | 获取中奖者 |
|
|
158
|
+
| `modifyResponse(input)` | 修改答卷分数 |
|
|
159
|
+
| `get360Report(input)` | 获取 360 报告 |
|
|
160
|
+
| `clearResponses(input)` | 清空答卷 |
|
|
161
|
+
|
|
162
|
+
### Contacts — 通讯录(14 函数)
|
|
163
|
+
|
|
164
|
+
| 函数 | 说明 |
|
|
165
|
+
|------|------|
|
|
166
|
+
| `queryContacts(input)` | 查询联系人 |
|
|
167
|
+
| `addContacts(input)` | 添加联系人 |
|
|
168
|
+
| `deleteContacts(input)` | 删除联系人 |
|
|
169
|
+
| `addAdmin(input)` | 添加管理员 |
|
|
170
|
+
| `deleteAdmin(input)` | 删除管理员 |
|
|
171
|
+
| `restoreAdmin(input)` | 恢复管理员 |
|
|
172
|
+
| `listDepartments(input)` | 列出部门 |
|
|
173
|
+
| `addDepartment(input)` | 添加部门 |
|
|
174
|
+
| `modifyDepartment(input)` | 修改部门 |
|
|
175
|
+
| `deleteDepartment(input)` | 删除部门 |
|
|
176
|
+
| `listTags(input)` | 列出标签 |
|
|
177
|
+
| `addTag(input)` | 添加标签 |
|
|
178
|
+
| `modifyTag(input)` | 修改标签 |
|
|
179
|
+
| `deleteTag(input)` | 删除标签 |
|
|
180
|
+
|
|
181
|
+
### User System — 用户体系(6 函数)
|
|
182
|
+
|
|
183
|
+
| 函数 | 说明 |
|
|
184
|
+
|------|------|
|
|
185
|
+
| `addParticipants(input)` | 添加参与者 |
|
|
186
|
+
| `modifyParticipants(input)` | 修改参与者 |
|
|
187
|
+
| `deleteParticipants(input)` | 删除参与者 |
|
|
188
|
+
| `bindActivity(input)` | 绑定活动 |
|
|
189
|
+
| `querySurveyBinding(input)` | 查询问卷绑定 |
|
|
190
|
+
| `queryUserSurveys(input)` | 查询用户问卷 |
|
|
191
|
+
|
|
192
|
+
### Multi-User — 多用户管理(5 函数)
|
|
193
|
+
|
|
194
|
+
| 函数 | 说明 |
|
|
195
|
+
|------|------|
|
|
196
|
+
| `addSubAccount(input)` | 添加子账号 |
|
|
197
|
+
| `modifySubAccount(input)` | 修改子账号 |
|
|
198
|
+
| `deleteSubAccount(input)` | 删除子账号 |
|
|
199
|
+
| `restoreSubAccount(input)` | 恢复子账号 |
|
|
200
|
+
| `querySubAccounts(input)` | 查询子账号列表 |
|
|
201
|
+
|
|
202
|
+
### SSO — 免登录(5 函数)
|
|
203
|
+
|
|
204
|
+
| 函数 | 说明 |
|
|
205
|
+
|------|------|
|
|
206
|
+
| `buildSsoSubaccountUrl(input)` | 生成子账号 SSO 链接 |
|
|
207
|
+
| `buildSsoUserSystemUrl(input)` | 生成用户体系 SSO 链接 |
|
|
208
|
+
| `buildSsoPartnerUrl(input)` | 生成合作伙伴 SSO 链接 |
|
|
209
|
+
| `buildSurveyUrl(input)` | 生成问卷创建/编辑 URL |
|
|
210
|
+
| `buildPreviewUrl(input)` | 生成问卷预览 URL |
|
|
211
|
+
|
|
212
|
+
### Analytics — 本地分析(6 函数)
|
|
213
|
+
|
|
214
|
+
| 函数 | 说明 |
|
|
215
|
+
|------|------|
|
|
216
|
+
| `decodeResponses(responses, questions)` | 解码答卷原始数据为可读结构 |
|
|
217
|
+
| `calculateNps(responses)` | 计算 NPS 净推荐值 |
|
|
218
|
+
| `calculateCsat(responses)` | 计算 CSAT 客户满意度 |
|
|
219
|
+
| `detectAnomalies(responses)` | 检测异常答卷 |
|
|
220
|
+
| `compareMetrics(baseline, current)` | 指标对比分析 |
|
|
221
|
+
| `decodePushPayload(payload)` | 解码推送回调数据 |
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## DSL 文本格式
|
|
226
|
+
|
|
227
|
+
SDK 提供问卷与纯文本之间的双向转换,方便 AI Agent 和脚本操作。
|
|
228
|
+
|
|
229
|
+
### surveyToText — 问卷转文本
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { getSurvey, surveyToText } from "wjx-api-sdk";
|
|
233
|
+
|
|
234
|
+
const detail = await getSurvey({ vid: 12345 }, creds);
|
|
235
|
+
const text = surveyToText(detail.data);
|
|
236
|
+
console.log(text);
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
输出格式:
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
问卷标题: 客户满意度调查
|
|
243
|
+
===
|
|
244
|
+
|
|
245
|
+
Q1 [单选题] 您对我们的服务满意吗?
|
|
246
|
+
1. 非常满意
|
|
247
|
+
2. 满意
|
|
248
|
+
3. 一般
|
|
249
|
+
4. 不满意
|
|
250
|
+
|
|
251
|
+
Q2 [填空题] 请输入您的建议
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### textToSurvey — 文本转问卷
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { textToSurvey } from "wjx-api-sdk";
|
|
258
|
+
|
|
259
|
+
const parsed = textToSurvey(`
|
|
260
|
+
问卷标题: 员工满意度调查
|
|
261
|
+
===
|
|
262
|
+
|
|
263
|
+
Q1 [单选题] 您对工作环境满意吗?
|
|
264
|
+
1. 非常满意
|
|
265
|
+
2. 满意
|
|
266
|
+
3. 一般
|
|
267
|
+
`);
|
|
268
|
+
|
|
269
|
+
console.log(parsed.title); // "员工满意度调查"
|
|
270
|
+
console.log(parsed.questions); // ParsedQuestion[]
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## 环境变量
|
|
276
|
+
|
|
277
|
+
| 变量 | 必填 | 说明 |
|
|
278
|
+
|------|:----:|------|
|
|
279
|
+
| `WJX_TOKEN` | 是 | 问卷星 OpenAPI Bearer Token |
|
|
280
|
+
| `WJX_BASE_URL` | 否 | 自定义 API 基础域名(默认 `https://www.wjx.cn`) |
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## 开发
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
cd wjx-ai-kit/wjx-api-sdk
|
|
288
|
+
|
|
289
|
+
npm run build # tsc 编译
|
|
290
|
+
npm test # 运行全部测试(598 tests)
|
|
291
|
+
npm run clean # 清理 dist/
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
测试使用 Node.js 内置测试运行器(`node:test`)。
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## 许可证
|
|
299
|
+
|
|
300
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { WjxCredentials, WjxApiResponse, RequestOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Register a credential provider that will be called before falling back to env vars.
|
|
4
|
+
* Used by MCP Server to inject AsyncLocalStorage-based per-request credentials.
|
|
5
|
+
*/
|
|
6
|
+
export declare function setCredentialProvider(fn: (() => WjxCredentials | undefined) | undefined): void;
|
|
7
|
+
export declare function getWjxCredentials(env?: NodeJS.ProcessEnv): WjxCredentials;
|
|
8
|
+
export declare function validateQuestionsJson(questions: string): void;
|
|
9
|
+
export declare function callWjxApi<T = unknown>(params: Record<string, unknown>, opts?: RequestOptions): Promise<WjxApiResponse<T>>;
|
|
10
|
+
export declare function callWjxUserSystemApi<T = unknown>(params: Record<string, unknown>, opts?: RequestOptions): Promise<WjxApiResponse<T>>;
|
|
11
|
+
export declare function callWjxSubuserApi<T = unknown>(params: Record<string, unknown>, opts?: RequestOptions): Promise<WjxApiResponse<T>>;
|
|
12
|
+
export declare function callWjxContactsApi<T = unknown>(params: Record<string, unknown>, opts?: RequestOptions): Promise<WjxApiResponse<T>>;
|
|
13
|
+
export declare function getCorpId(env?: NodeJS.ProcessEnv): string | undefined;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { getWjxApiUrl, getWjxUserSystemApiUrl, getWjxSubuserApiUrl, getWjxContactsApiUrl, DEFAULT_TIMEOUT_MS, DEFAULT_MAX_RETRIES, RETRY_DELAY_MS, } from "./constants.js";
|
|
3
|
+
/** Pluggable credential provider for per-request credentials (e.g. multi-tenant). */
|
|
4
|
+
let _credentialProvider;
|
|
5
|
+
/**
|
|
6
|
+
* Register a credential provider that will be called before falling back to env vars.
|
|
7
|
+
* Used by MCP Server to inject AsyncLocalStorage-based per-request credentials.
|
|
8
|
+
*/
|
|
9
|
+
export function setCredentialProvider(fn) {
|
|
10
|
+
_credentialProvider = fn;
|
|
11
|
+
}
|
|
12
|
+
function generateTraceId() {
|
|
13
|
+
return randomUUID().replace(/-/g, "");
|
|
14
|
+
}
|
|
15
|
+
export function getWjxCredentials(env = process.env) {
|
|
16
|
+
// 1. Per-request credentials from registered provider (e.g. AsyncLocalStorage)
|
|
17
|
+
const providerCreds = _credentialProvider?.();
|
|
18
|
+
if (providerCreds)
|
|
19
|
+
return providerCreds;
|
|
20
|
+
// 2. Fallback: environment variables (single-tenant / stdio / CLI mode)
|
|
21
|
+
const token = env.WJX_TOKEN;
|
|
22
|
+
if (!token) {
|
|
23
|
+
throw new Error("WJX_TOKEN must be set (via env var or credential provider).");
|
|
24
|
+
}
|
|
25
|
+
return { token };
|
|
26
|
+
}
|
|
27
|
+
export function validateQuestionsJson(questions) {
|
|
28
|
+
let parsed;
|
|
29
|
+
try {
|
|
30
|
+
parsed = JSON.parse(questions);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
34
|
+
throw new Error(`questions must be valid JSON: ${message}`);
|
|
35
|
+
}
|
|
36
|
+
if (!Array.isArray(parsed)) {
|
|
37
|
+
throw new Error("questions must be a JSON array");
|
|
38
|
+
}
|
|
39
|
+
for (const [i, q] of parsed.entries()) {
|
|
40
|
+
if (typeof q.q_index !== "number") {
|
|
41
|
+
throw new Error(`questions[${i}] missing required field "q_index" (number)`);
|
|
42
|
+
}
|
|
43
|
+
if (typeof q.q_type !== "number") {
|
|
44
|
+
throw new Error(`questions[${i}] missing required field "q_type" (number)`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function isRetryable(status) {
|
|
49
|
+
return status === 429 || status >= 500;
|
|
50
|
+
}
|
|
51
|
+
function sleep(ms) {
|
|
52
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
53
|
+
}
|
|
54
|
+
async function _callApi(baseUrl, params, opts = {}) {
|
|
55
|
+
const credentials = opts.credentials ?? getWjxCredentials();
|
|
56
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
57
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
58
|
+
const maxRetries = opts.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
59
|
+
const logger = opts.logger;
|
|
60
|
+
const traceId = generateTraceId();
|
|
61
|
+
const action = String(params.action ?? "unknown");
|
|
62
|
+
const url = `${baseUrl}?traceid=${traceId}&action=${encodeURIComponent(action)}`;
|
|
63
|
+
let lastError;
|
|
64
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
65
|
+
if (attempt > 0) {
|
|
66
|
+
const delay = RETRY_DELAY_MS * Math.pow(2, attempt - 1) * (0.5 + Math.random() * 0.5);
|
|
67
|
+
logger?.warn(`[wjx] retry ${attempt}/${maxRetries} for action=${action} traceid=${traceId} after ${delay}ms`);
|
|
68
|
+
await sleep(delay);
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
73
|
+
let response;
|
|
74
|
+
try {
|
|
75
|
+
response = await fetchImpl(url, {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: {
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
"Authorization": `Bearer ${credentials.token}`,
|
|
80
|
+
},
|
|
81
|
+
body: JSON.stringify(params),
|
|
82
|
+
signal: controller.signal,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
}
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
if (isRetryable(response.status) && attempt < maxRetries) {
|
|
90
|
+
lastError = new Error(`WJX API request failed with ${response.status} ${response.statusText}`);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`WJX API request failed with ${response.status} ${response.statusText}`);
|
|
94
|
+
}
|
|
95
|
+
let result;
|
|
96
|
+
try {
|
|
97
|
+
result = (await response.json());
|
|
98
|
+
}
|
|
99
|
+
catch (parseError) {
|
|
100
|
+
throw new Error(`WJX API returned unparseable response for action=${action} traceid=${traceId}: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
101
|
+
}
|
|
102
|
+
if (result.result === false) {
|
|
103
|
+
logger?.error(`[wjx] api error action=${action} traceid=${traceId}: ${result.errormsg}`);
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
109
|
+
lastError = new Error(`WJX API request timed out after ${timeoutMs}ms (action=${action}, traceid=${traceId})`);
|
|
110
|
+
if (attempt < maxRetries)
|
|
111
|
+
continue;
|
|
112
|
+
throw lastError;
|
|
113
|
+
}
|
|
114
|
+
const isNetworkError = error instanceof TypeError &&
|
|
115
|
+
typeof error.message === "string" &&
|
|
116
|
+
/fetch|network|connect|ECONNR|ETIMEDOUT|EAI_AGAIN/i.test(error.message);
|
|
117
|
+
if (isNetworkError && attempt < maxRetries) {
|
|
118
|
+
lastError = error;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
throw lastError ?? new Error("Exhausted retries");
|
|
125
|
+
}
|
|
126
|
+
export async function callWjxApi(params, opts = {}) {
|
|
127
|
+
return _callApi(getWjxApiUrl(), params, opts);
|
|
128
|
+
}
|
|
129
|
+
export async function callWjxUserSystemApi(params, opts = {}) {
|
|
130
|
+
return _callApi(getWjxUserSystemApiUrl(), params, opts);
|
|
131
|
+
}
|
|
132
|
+
export async function callWjxSubuserApi(params, opts = {}) {
|
|
133
|
+
return _callApi(getWjxSubuserApiUrl(), params, opts);
|
|
134
|
+
}
|
|
135
|
+
export async function callWjxContactsApi(params, opts = {}) {
|
|
136
|
+
return _callApi(getWjxContactsApiUrl(), params, opts);
|
|
137
|
+
}
|
|
138
|
+
export function getCorpId(env = process.env) {
|
|
139
|
+
return env.WJX_CORP_ID || undefined;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["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DAAmD,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC1E,IAAI,cAAc,IAAI,OAAO,GAAG,UAAU,EAAE,CAAC;gBAC3C,SAAS,GAAG,KAAc,CAAC;gBAC3B,SAAS;YACX,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,MAAM,SAAS,IAAI,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAA+B,EAC/B,OAAuB,EAAE;IAEzB,OAAO,QAAQ,CAAI,YAAY,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAA+B,EAC/B,OAAuB,EAAE;IAEzB,OAAO,QAAQ,CAAI,sBAAsB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAA+B,EAC/B,OAAuB,EAAE;IAEzB,OAAO,QAAQ,CAAI,mBAAmB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAA+B,EAC/B,OAAuB,EAAE;IAEzB,OAAO,QAAQ,CAAI,oBAAoB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC5D,OAAO,GAAG,CAAC,WAAW,IAAI,SAAS,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export declare function getWjxBaseUrl(): string;
|
|
2
|
+
export declare function getWjxApiUrl(): string;
|
|
3
|
+
export declare function getWjxUserSystemApiUrl(): string;
|
|
4
|
+
export declare function getWjxSubuserApiUrl(): string;
|
|
5
|
+
export declare function getWjxContactsApiUrl(): string;
|
|
6
|
+
export declare function getWjxSsoSubaccountUrl(): string;
|
|
7
|
+
export declare function getWjxSsoUserSystemUrl(): string;
|
|
8
|
+
export declare function getWjxSsoPartnerUrl(): string;
|
|
9
|
+
export declare function getWjxSurveyCreateUrl(): string;
|
|
10
|
+
export declare function getWjxSurveyEditUrl(): string;
|
|
11
|
+
export declare const Action: {
|
|
12
|
+
readonly GET_SURVEY: "1000001";
|
|
13
|
+
readonly LIST_SURVEYS: "1000002";
|
|
14
|
+
readonly GET_SETTINGS: "1000003";
|
|
15
|
+
readonly GET_TAGS: "1000004";
|
|
16
|
+
readonly GET_TAG_DETAILS: "1000005";
|
|
17
|
+
readonly CREATE_SURVEY: "1000101";
|
|
18
|
+
readonly UPDATE_STATUS: "1000102";
|
|
19
|
+
readonly UPDATE_SETTINGS: "1000103";
|
|
20
|
+
readonly UPLOAD_FILE: "1000104";
|
|
21
|
+
readonly DELETE_SURVEY: "1000301";
|
|
22
|
+
readonly CLEAR_RECYCLE_BIN: "1000302";
|
|
23
|
+
readonly SUBMIT_RESPONSE: "1001001";
|
|
24
|
+
readonly QUERY_RESPONSES: "1001002";
|
|
25
|
+
readonly QUERY_RESPONSES_REALTIME: "1001003";
|
|
26
|
+
readonly DOWNLOAD_RESPONSES: "1001004";
|
|
27
|
+
readonly GET_FILE_LINKS: "1001005";
|
|
28
|
+
readonly GET_WINNERS: "1001006";
|
|
29
|
+
readonly MODIFY_RESPONSE: "1001007";
|
|
30
|
+
readonly GET_REPORT: "1001101";
|
|
31
|
+
readonly GET_360_REPORT: "1001102";
|
|
32
|
+
readonly CLEAR_RESPONSES: "1001201";
|
|
33
|
+
readonly ADD_PARTICIPANTS: "1002001";
|
|
34
|
+
readonly MODIFY_PARTICIPANTS: "1002002";
|
|
35
|
+
readonly DELETE_PARTICIPANTS: "1002003";
|
|
36
|
+
readonly BIND_ACTIVITY: "1002004";
|
|
37
|
+
readonly QUERY_SURVEY_BINDING: "1002005";
|
|
38
|
+
readonly QUERY_USER_SURVEYS: "1002006";
|
|
39
|
+
readonly ADD_SUB_ACCOUNT: "1003001";
|
|
40
|
+
readonly MODIFY_SUB_ACCOUNT: "1003002";
|
|
41
|
+
readonly DELETE_SUB_ACCOUNT: "1003003";
|
|
42
|
+
readonly RESTORE_SUB_ACCOUNT: "1003004";
|
|
43
|
+
readonly QUERY_SUB_ACCOUNTS: "1003005";
|
|
44
|
+
readonly QUERY_CONTACTS: "1005001";
|
|
45
|
+
readonly ADD_CONTACTS: "1005002";
|
|
46
|
+
readonly MANAGE_CONTACTS: "1005003";
|
|
47
|
+
readonly ADD_ADMIN: "1005004";
|
|
48
|
+
readonly DELETE_ADMIN: "1005005";
|
|
49
|
+
readonly RESTORE_ADMIN: "1005006";
|
|
50
|
+
readonly LIST_DEPARTMENTS: "1005101";
|
|
51
|
+
readonly ADD_DEPARTMENT: "1005102";
|
|
52
|
+
readonly MODIFY_DEPARTMENT: "1005103";
|
|
53
|
+
readonly DELETE_DEPARTMENT: "1005104";
|
|
54
|
+
readonly LIST_TAGS: "1005201";
|
|
55
|
+
readonly ADD_TAG: "1005202";
|
|
56
|
+
readonly MODIFY_TAG: "1005203";
|
|
57
|
+
readonly DELETE_TAG: "1005204";
|
|
58
|
+
};
|
|
59
|
+
export declare const DEFAULT_TIMEOUT_MS = 15000;
|
|
60
|
+
export declare const DEFAULT_MAX_RETRIES = 2;
|
|
61
|
+
export declare const RETRY_DELAY_MS = 1000;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export function getWjxBaseUrl() {
|
|
2
|
+
return (process.env.WJX_BASE_URL ?? "https://www.wjx.cn").replace(/\/+$/, "");
|
|
3
|
+
}
|
|
4
|
+
export function getWjxApiUrl() {
|
|
5
|
+
return process.env.WJX_API_URL ?? `${getWjxBaseUrl()}/openapi/default.aspx`;
|
|
6
|
+
}
|
|
7
|
+
export function getWjxUserSystemApiUrl() {
|
|
8
|
+
return process.env.WJX_USER_SYSTEM_API_URL ?? `${getWjxBaseUrl()}/openapi/usersystem.aspx`;
|
|
9
|
+
}
|
|
10
|
+
export function getWjxSubuserApiUrl() {
|
|
11
|
+
return process.env.WJX_SUBUSER_API_URL ?? `${getWjxBaseUrl()}/openapi/subuser.aspx`;
|
|
12
|
+
}
|
|
13
|
+
export function getWjxContactsApiUrl() {
|
|
14
|
+
return process.env.WJX_CONTACTS_API_URL ?? `${getWjxBaseUrl()}/openapi/contacts.aspx`;
|
|
15
|
+
}
|
|
16
|
+
export function getWjxSsoSubaccountUrl() {
|
|
17
|
+
return process.env.WJX_SSO_SUBACCOUNT_URL ?? `${getWjxBaseUrl()}/zunxiang/login.aspx`;
|
|
18
|
+
}
|
|
19
|
+
export function getWjxSsoUserSystemUrl() {
|
|
20
|
+
return process.env.WJX_SSO_USER_SYSTEM_URL ?? `${getWjxBaseUrl()}/user/loginform.aspx`;
|
|
21
|
+
}
|
|
22
|
+
export function getWjxSsoPartnerUrl() {
|
|
23
|
+
return process.env.WJX_SSO_PARTNER_URL ?? `${getWjxBaseUrl()}/partner/login.aspx`;
|
|
24
|
+
}
|
|
25
|
+
export function getWjxSurveyCreateUrl() {
|
|
26
|
+
return process.env.WJX_SURVEY_CREATE_URL ?? `${getWjxBaseUrl()}/newwjx/mysojump/createblankNew.aspx`;
|
|
27
|
+
}
|
|
28
|
+
export function getWjxSurveyEditUrl() {
|
|
29
|
+
return process.env.WJX_SURVEY_EDIT_URL ?? `${getWjxBaseUrl()}/newwjx/design/editquestionnaire.aspx`;
|
|
30
|
+
}
|
|
31
|
+
export const Action = {
|
|
32
|
+
GET_SURVEY: "1000001",
|
|
33
|
+
LIST_SURVEYS: "1000002",
|
|
34
|
+
GET_SETTINGS: "1000003",
|
|
35
|
+
GET_TAGS: "1000004",
|
|
36
|
+
GET_TAG_DETAILS: "1000005",
|
|
37
|
+
CREATE_SURVEY: "1000101",
|
|
38
|
+
UPDATE_STATUS: "1000102",
|
|
39
|
+
UPDATE_SETTINGS: "1000103",
|
|
40
|
+
UPLOAD_FILE: "1000104",
|
|
41
|
+
DELETE_SURVEY: "1000301",
|
|
42
|
+
CLEAR_RECYCLE_BIN: "1000302",
|
|
43
|
+
SUBMIT_RESPONSE: "1001001",
|
|
44
|
+
QUERY_RESPONSES: "1001002",
|
|
45
|
+
QUERY_RESPONSES_REALTIME: "1001003",
|
|
46
|
+
DOWNLOAD_RESPONSES: "1001004",
|
|
47
|
+
GET_FILE_LINKS: "1001005",
|
|
48
|
+
GET_WINNERS: "1001006",
|
|
49
|
+
MODIFY_RESPONSE: "1001007",
|
|
50
|
+
GET_REPORT: "1001101",
|
|
51
|
+
GET_360_REPORT: "1001102",
|
|
52
|
+
CLEAR_RESPONSES: "1001201",
|
|
53
|
+
ADD_PARTICIPANTS: "1002001",
|
|
54
|
+
MODIFY_PARTICIPANTS: "1002002",
|
|
55
|
+
DELETE_PARTICIPANTS: "1002003",
|
|
56
|
+
BIND_ACTIVITY: "1002004",
|
|
57
|
+
QUERY_SURVEY_BINDING: "1002005",
|
|
58
|
+
QUERY_USER_SURVEYS: "1002006",
|
|
59
|
+
ADD_SUB_ACCOUNT: "1003001",
|
|
60
|
+
MODIFY_SUB_ACCOUNT: "1003002",
|
|
61
|
+
DELETE_SUB_ACCOUNT: "1003003",
|
|
62
|
+
RESTORE_SUB_ACCOUNT: "1003004",
|
|
63
|
+
QUERY_SUB_ACCOUNTS: "1003005",
|
|
64
|
+
QUERY_CONTACTS: "1005001",
|
|
65
|
+
ADD_CONTACTS: "1005002",
|
|
66
|
+
MANAGE_CONTACTS: "1005003",
|
|
67
|
+
ADD_ADMIN: "1005004",
|
|
68
|
+
DELETE_ADMIN: "1005005",
|
|
69
|
+
RESTORE_ADMIN: "1005006",
|
|
70
|
+
LIST_DEPARTMENTS: "1005101",
|
|
71
|
+
ADD_DEPARTMENT: "1005102",
|
|
72
|
+
MODIFY_DEPARTMENT: "1005103",
|
|
73
|
+
DELETE_DEPARTMENT: "1005104",
|
|
74
|
+
LIST_TAGS: "1005201",
|
|
75
|
+
ADD_TAG: "1005202",
|
|
76
|
+
MODIFY_TAG: "1005203",
|
|
77
|
+
DELETE_TAG: "1005204",
|
|
78
|
+
};
|
|
79
|
+
export const DEFAULT_TIMEOUT_MS = 15_000;
|
|
80
|
+
export const DEFAULT_MAX_RETRIES = 2;
|
|
81
|
+
export const RETRY_DELAY_MS = 1000;
|
|
82
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,oBAAoB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,GAAG,aAAa,EAAE,uBAAuB,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,GAAG,aAAa,EAAE,0BAA0B,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,OAAO,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,GAAG,aAAa,EAAE,uBAAuB,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,GAAG,aAAa,EAAE,wBAAwB,CAAC;AACxF,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,GAAG,aAAa,EAAE,sBAAsB,CAAC;AACxF,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,GAAG,aAAa,EAAE,sBAAsB,CAAC;AACzF,CAAC;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AE,SAAS;IACzB,YAAY,EAAE,SAAS;IACvB,eAAe,EAAE,SAAS;IAC1B,SAAS,EAAE,SAAS;IACpB,YAAY,EAAE,SAAS;IACvB,aAAa,EAAE,SAAS;IACxB,gBAAgB,EAAE,SAAS;IAC3B,cAAc,EAAE,SAAS;IACzB,iBAAiB,EAAE,SAAS;IAC5B,iBAAiB,EAAE,SAAS;IAC5B,SAAS,EAAE,SAAS;IACpB,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE,SAAS;CACb,CAAC;AAEX,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface WjxCredentials {
|
|
2
|
+
token: string;
|
|
3
|
+
}
|
|
4
|
+
export interface WjxApiSuccess<T = unknown> {
|
|
5
|
+
result: true;
|
|
6
|
+
data: T;
|
|
7
|
+
}
|
|
8
|
+
export interface WjxApiFailure {
|
|
9
|
+
result: false;
|
|
10
|
+
errormsg: string;
|
|
11
|
+
errorcode?: number;
|
|
12
|
+
data?: unknown;
|
|
13
|
+
}
|
|
14
|
+
export type WjxApiResponse<T = unknown> = WjxApiSuccess<T> | WjxApiFailure;
|
|
15
|
+
export type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
16
|
+
export interface Logger {
|
|
17
|
+
warn(msg: string): void;
|
|
18
|
+
error(msg: string): void;
|
|
19
|
+
}
|
|
20
|
+
export interface RequestOptions {
|
|
21
|
+
credentials?: WjxCredentials;
|
|
22
|
+
fetchImpl?: FetchLike;
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
logger?: Logger;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":""}
|