@plolink/sdk 0.0.5 → 0.0.6
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 +40 -26
- package/dist/{chunk-4H4RACSE.js → chunk-LHNCGCWW.js} +137 -3
- package/dist/chunk-LHNCGCWW.js.map +1 -0
- package/dist/{chunk-NS3DJP2O.cjs → chunk-WFBN23AH.cjs} +141 -2
- package/dist/chunk-WFBN23AH.cjs.map +1 -0
- package/dist/client-BuUQTr8R.d.cts +766 -0
- package/dist/client-D2HlV7GT.d.ts +766 -0
- package/dist/common/index.cjs +18 -14
- package/dist/common/index.d.cts +126 -1
- package/dist/common/index.d.ts +126 -1
- package/dist/common/index.js +1 -1
- package/dist/index.cjs +647 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +410 -3
- package/dist/index.d.ts +410 -3
- package/dist/index.js +631 -3
- package/dist/index.js.map +1 -1
- package/dist/modules/billing/index.cjs +1 -1
- package/dist/modules/billing/index.d.cts +1 -1
- package/dist/modules/billing/index.d.ts +1 -1
- package/dist/modules/billing/index.js +1 -1
- package/dist/modules/rbac/index.d.cts +1 -1
- package/dist/modules/rbac/index.d.ts +1 -1
- package/dist/modules/team/index.d.cts +1 -1
- package/dist/modules/team/index.d.ts +1 -1
- package/dist/modules/video-psych-analysis/index.cjs +123 -4
- package/dist/modules/video-psych-analysis/index.cjs.map +1 -1
- package/dist/modules/video-psych-analysis/index.d.cts +231 -93
- package/dist/modules/video-psych-analysis/index.d.ts +231 -93
- package/dist/modules/video-psych-analysis/index.js +123 -4
- package/dist/modules/video-psych-analysis/index.js.map +1 -1
- package/dist/modules/virtual-account/index.d.cts +1 -1
- package/dist/modules/virtual-account/index.d.ts +1 -1
- package/package.json +1 -16
- package/dist/chunk-4H4RACSE.js.map +0 -1
- package/dist/chunk-NS3DJP2O.cjs.map +0 -1
- package/dist/client-CAjIQKPm.d.cts +0 -193
- package/dist/client-CwNikk7i.d.ts +0 -193
- package/dist/modules/agent/index.cjs +0 -21
- package/dist/modules/agent/index.cjs.map +0 -1
- package/dist/modules/agent/index.d.cts +0 -71
- package/dist/modules/agent/index.d.ts +0 -71
- package/dist/modules/agent/index.js +0 -19
- package/dist/modules/agent/index.js.map +0 -1
- package/dist/modules/chat/index.cjs +0 -20
- package/dist/modules/chat/index.cjs.map +0 -1
- package/dist/modules/chat/index.d.cts +0 -68
- package/dist/modules/chat/index.d.ts +0 -68
- package/dist/modules/chat/index.js +0 -18
- package/dist/modules/chat/index.js.map +0 -1
- package/dist/modules/psych/index.cjs +0 -20
- package/dist/modules/psych/index.cjs.map +0 -1
- package/dist/modules/psych/index.d.cts +0 -69
- package/dist/modules/psych/index.d.ts +0 -69
- package/dist/modules/psych/index.js +0 -18
- package/dist/modules/psych/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { EventEmitter, TypedEventEmitter, environmentInfo, getEnvironment, isBrowser, isNode, isWebWorker } from './chunk-4H4RACSE.js';
|
|
2
|
-
export { Poller } from './chunk-IHAAKFEJ.js';
|
|
3
1
|
import { PlolinkError } from './chunk-MD4O7FWT.js';
|
|
4
2
|
export { PlolinkError } from './chunk-MD4O7FWT.js';
|
|
3
|
+
export { EventEmitter, InfoSyncSignature, TypedEventEmitter, environmentInfo, getEnvironment, isBrowser, isNode, isWebWorker } from './chunk-LHNCGCWW.js';
|
|
4
|
+
export { Poller } from './chunk-IHAAKFEJ.js';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
|
|
7
7
|
// src/core/logger.ts
|
|
@@ -187,6 +187,370 @@ function createAxiosInstance(config, logger) {
|
|
|
187
187
|
return instance;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
// src/modules/psychology-test/index.ts
|
|
191
|
+
var PsychologyTest = class {
|
|
192
|
+
constructor(client) {
|
|
193
|
+
this.client = client;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 发起心理评测
|
|
197
|
+
*
|
|
198
|
+
* @description
|
|
199
|
+
* 根据题组代码列表发起心理评测会话,系统会自动生成打乱后的题目列表并返回。
|
|
200
|
+
*
|
|
201
|
+
* @param params - 发起评测参数
|
|
202
|
+
* @returns 评测会话信息,包含会话ID和题目列表
|
|
203
|
+
* @throws {PlolinkError} 当参数验证失败或发起失败时抛出
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const result = await client.psychologyTest.initiate({
|
|
208
|
+
* groupCodes: ['family_parenting', 'disc'],
|
|
209
|
+
* businessModule: 'talent_assessment',
|
|
210
|
+
* businessCode: 'job_match',
|
|
211
|
+
* businessId: 'clxxxx123456',
|
|
212
|
+
* needAnalysis: true,
|
|
213
|
+
* analysisPrompt: '请结合家庭养育方式和DISC行为模式,分析候选人的性格特点。'
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* console.log(`评测会话ID: ${result.sessionId}`);
|
|
217
|
+
* console.log(`共 ${result.totalCount} 道题目`);
|
|
218
|
+
* console.log('题组摘要:', result.groupSummary);
|
|
219
|
+
*
|
|
220
|
+
* // 展示题目
|
|
221
|
+
* result.questions.forEach((q, index) => {
|
|
222
|
+
* console.log(`题目 ${index + 1}: ${q.content}`);
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
async initiate(params) {
|
|
227
|
+
this.client.logger.info("Initiating psychology test", {
|
|
228
|
+
groupCodes: params.groupCodes,
|
|
229
|
+
businessModule: params.businessModule,
|
|
230
|
+
businessCode: params.businessCode,
|
|
231
|
+
needAnalysis: params.needAnalysis
|
|
232
|
+
});
|
|
233
|
+
if (!params.groupCodes || params.groupCodes.length === 0) {
|
|
234
|
+
throw new PlolinkError(
|
|
235
|
+
"groupCodes is required and cannot be empty",
|
|
236
|
+
"VALIDATION_ERROR"
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if (!params.businessModule || !params.businessCode || !params.businessId) {
|
|
240
|
+
throw new PlolinkError(
|
|
241
|
+
"businessModule, businessCode, and businessId are required",
|
|
242
|
+
"VALIDATION_ERROR"
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (params.needAnalysis && !params.analysisPrompt) {
|
|
246
|
+
throw new PlolinkError(
|
|
247
|
+
"analysisPrompt is required when needAnalysis is true",
|
|
248
|
+
"VALIDATION_ERROR"
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
const response = await this.client.axiosInstance.post(
|
|
253
|
+
"/api/v1/psychology/test-sessions/initiate",
|
|
254
|
+
params
|
|
255
|
+
);
|
|
256
|
+
this.client.logger.info("Psychology test initiated successfully", {
|
|
257
|
+
sessionId: response.sessionId,
|
|
258
|
+
totalCount: response.totalCount
|
|
259
|
+
});
|
|
260
|
+
return response;
|
|
261
|
+
} catch (error) {
|
|
262
|
+
this.client.logger.error("Failed to initiate psychology test", { error });
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 提交心理评测
|
|
268
|
+
*
|
|
269
|
+
* @description
|
|
270
|
+
* 提交心理评测答题数据,系统会自动计算得分并生成 Markdown 描述。
|
|
271
|
+
* 如需 AI 分析则会加入异步队列,分析完成后会通过 Webhook 通知。
|
|
272
|
+
*
|
|
273
|
+
* @param params - 提交评测参数
|
|
274
|
+
* @returns 提交结果,包含计算结果和得分描述
|
|
275
|
+
* @throws {PlolinkError} 当参数验证失败或提交失败时抛出
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const result = await client.psychologyTest.submit({
|
|
280
|
+
* sessionId: 'clxxxx789012',
|
|
281
|
+
* answers: [
|
|
282
|
+
* {
|
|
283
|
+
* groupCode: 'family_parenting',
|
|
284
|
+
* bankId: 'bank_123',
|
|
285
|
+
* questionId: 'q_001',
|
|
286
|
+
* questionCode: 'FP001A',
|
|
287
|
+
* answer: '1',
|
|
288
|
+
* timeSpent: 3500
|
|
289
|
+
* },
|
|
290
|
+
* // ... 更多答题记录
|
|
291
|
+
* ],
|
|
292
|
+
* duration: 480000
|
|
293
|
+
* });
|
|
294
|
+
*
|
|
295
|
+
* console.log('得分描述:', result.scoreDescription);
|
|
296
|
+
* console.log('计算结果:', result.calculationResults);
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
async submit(params) {
|
|
300
|
+
this.client.logger.info("Submitting psychology test", {
|
|
301
|
+
sessionId: params.sessionId,
|
|
302
|
+
answersCount: params.answers.length
|
|
303
|
+
});
|
|
304
|
+
if (!params.sessionId) {
|
|
305
|
+
throw new PlolinkError(
|
|
306
|
+
"sessionId is required",
|
|
307
|
+
"VALIDATION_ERROR"
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
if (!params.answers || params.answers.length === 0) {
|
|
311
|
+
throw new PlolinkError(
|
|
312
|
+
"answers is required and cannot be empty",
|
|
313
|
+
"VALIDATION_ERROR"
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
try {
|
|
317
|
+
const response = await this.client.axiosInstance.post(
|
|
318
|
+
"/api/v1/psychology/test-sessions/submit",
|
|
319
|
+
params
|
|
320
|
+
);
|
|
321
|
+
this.client.logger.info("Psychology test submitted successfully", {
|
|
322
|
+
sessionId: response.sessionId
|
|
323
|
+
});
|
|
324
|
+
return response;
|
|
325
|
+
} catch (error) {
|
|
326
|
+
this.client.logger.error("Failed to submit psychology test", { error });
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* 获取心理评测详情
|
|
332
|
+
*
|
|
333
|
+
* @description
|
|
334
|
+
* 获取心理评测会话的完整信息,包括基本信息、计算结果、得分描述、AI分析结果等。
|
|
335
|
+
*
|
|
336
|
+
* @param sessionId - 评测会话ID
|
|
337
|
+
* @returns 评测会话详情
|
|
338
|
+
* @throws {PlolinkError} 当会话不存在或查询失败时抛出
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* const detail = await client.psychologyTest.getDetail('clxxxx789012');
|
|
343
|
+
*
|
|
344
|
+
* console.log('评测状态:', detail.status);
|
|
345
|
+
* console.log('得分描述:', detail.scoreDescription);
|
|
346
|
+
*
|
|
347
|
+
* // 检查分析状态
|
|
348
|
+
* if (detail.analysisStatus === 'COMPLETED') {
|
|
349
|
+
* console.log('AI分析结果:', detail.analysisResult);
|
|
350
|
+
* } else if (detail.analysisStatus === 'ANALYZING') {
|
|
351
|
+
* console.log('AI分析进行中,请稍后查询');
|
|
352
|
+
* } else if (detail.analysisStatus === 'FAILED') {
|
|
353
|
+
* console.error('分析失败:', detail.analysisError);
|
|
354
|
+
* }
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
async getDetail(sessionId) {
|
|
358
|
+
this.client.logger.info("Getting psychology test detail", { sessionId });
|
|
359
|
+
if (!sessionId) {
|
|
360
|
+
throw new PlolinkError(
|
|
361
|
+
"sessionId is required",
|
|
362
|
+
"VALIDATION_ERROR"
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
try {
|
|
366
|
+
const response = await this.client.axiosInstance.get(
|
|
367
|
+
`/api/v1/psychology/test-sessions/${sessionId}`
|
|
368
|
+
);
|
|
369
|
+
this.client.logger.info("Psychology test detail retrieved successfully", {
|
|
370
|
+
sessionId,
|
|
371
|
+
status: response.status,
|
|
372
|
+
analysisStatus: response.analysisStatus
|
|
373
|
+
});
|
|
374
|
+
return response;
|
|
375
|
+
} catch (error) {
|
|
376
|
+
this.client.logger.error("Failed to get psychology test detail", { error });
|
|
377
|
+
throw error;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* 获取心理评测答题记录
|
|
382
|
+
*
|
|
383
|
+
* @description
|
|
384
|
+
* 获取心理评测会话的所有答题记录。
|
|
385
|
+
*
|
|
386
|
+
* @param sessionId - 评测会话ID
|
|
387
|
+
* @returns 答题记录列表
|
|
388
|
+
* @throws {PlolinkError} 当会话不存在或查询失败时抛出
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```typescript
|
|
392
|
+
* const answers = await client.psychologyTest.getAnswers('clxxxx789012');
|
|
393
|
+
*
|
|
394
|
+
* console.log(`共 ${answers.length} 条答题记录`);
|
|
395
|
+
* answers.forEach(answer => {
|
|
396
|
+
* console.log(`题目 ${answer.questionCode}: ${answer.answer}`);
|
|
397
|
+
* });
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
async getAnswers(sessionId) {
|
|
401
|
+
this.client.logger.info("Getting psychology test answers", { sessionId });
|
|
402
|
+
if (!sessionId) {
|
|
403
|
+
throw new PlolinkError(
|
|
404
|
+
"sessionId is required",
|
|
405
|
+
"VALIDATION_ERROR"
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
try {
|
|
409
|
+
const response = await this.client.axiosInstance.get(
|
|
410
|
+
`/api/v1/psychology/test-sessions/${sessionId}/answers`
|
|
411
|
+
);
|
|
412
|
+
this.client.logger.info("Psychology test answers retrieved successfully", {
|
|
413
|
+
sessionId,
|
|
414
|
+
count: response.length
|
|
415
|
+
});
|
|
416
|
+
return response;
|
|
417
|
+
} catch (error) {
|
|
418
|
+
this.client.logger.error("Failed to get psychology test answers", { error });
|
|
419
|
+
throw error;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* 列表查询心理评测会话
|
|
424
|
+
*
|
|
425
|
+
* @description
|
|
426
|
+
* 查询心理评测会话列表,支持分页和多条件筛选。
|
|
427
|
+
* 此接口通常用于管理后台或业务系统查询评测记录。
|
|
428
|
+
*
|
|
429
|
+
* @param params - 查询参数
|
|
430
|
+
* @returns 会话列表和分页信息
|
|
431
|
+
* @throws {PlolinkError} 当查询失败时抛出
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```typescript
|
|
435
|
+
* // 查询所有评测会话
|
|
436
|
+
* const result = await client.psychologyTest.listTestSessions({
|
|
437
|
+
* page: 1,
|
|
438
|
+
* size: 20
|
|
439
|
+
* });
|
|
440
|
+
*
|
|
441
|
+
* console.log(`共 ${result.total} 条记录`);
|
|
442
|
+
* result.list.forEach(session => {
|
|
443
|
+
* console.log(`会话ID: ${session.id}, 状态: ${session.status}`);
|
|
444
|
+
* });
|
|
445
|
+
*
|
|
446
|
+
* // 按条件筛选
|
|
447
|
+
* const filtered = await client.psychologyTest.listTestSessions({
|
|
448
|
+
* page: 1,
|
|
449
|
+
* size: 20,
|
|
450
|
+
* businessModule: 'talent_assessment',
|
|
451
|
+
* status: 'COMPLETED',
|
|
452
|
+
* analysisStatus: 'COMPLETED'
|
|
453
|
+
* });
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
async listTestSessions(params = {}) {
|
|
457
|
+
this.client.logger.info("Listing psychology test sessions", { params });
|
|
458
|
+
try {
|
|
459
|
+
const queryParams = new URLSearchParams();
|
|
460
|
+
if (params.page !== void 0) queryParams.append("page", String(params.page));
|
|
461
|
+
if (params.size !== void 0) queryParams.append("size", String(params.size));
|
|
462
|
+
if (params.businessModule) queryParams.append("businessModule", params.businessModule);
|
|
463
|
+
if (params.businessCode) queryParams.append("businessCode", params.businessCode);
|
|
464
|
+
if (params.status) queryParams.append("status", params.status);
|
|
465
|
+
if (params.analysisStatus) queryParams.append("analysisStatus", params.analysisStatus);
|
|
466
|
+
if (params.startDate) queryParams.append("startDate", params.startDate);
|
|
467
|
+
if (params.endDate) queryParams.append("endDate", params.endDate);
|
|
468
|
+
if (params.teamId) queryParams.append("teamId", params.teamId);
|
|
469
|
+
const url = `/api/admin/psychology/test-sessions${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
|
|
470
|
+
const response = await this.client.axiosInstance.get(url);
|
|
471
|
+
this.client.logger.info("Psychology test sessions listed successfully", {
|
|
472
|
+
total: response.total,
|
|
473
|
+
count: response.list.length
|
|
474
|
+
});
|
|
475
|
+
return response;
|
|
476
|
+
} catch (error) {
|
|
477
|
+
this.client.logger.error("Failed to list psychology test sessions", { error });
|
|
478
|
+
throw error;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* 删除心理评测会话
|
|
483
|
+
*
|
|
484
|
+
* @description
|
|
485
|
+
* 软删除心理评测会话记录。删除后数据不会真正从数据库移除,
|
|
486
|
+
* 但在正常查询中不会显示。此接口通常用于管理后台。
|
|
487
|
+
*
|
|
488
|
+
* @param sessionId - 评测会话ID
|
|
489
|
+
* @returns void
|
|
490
|
+
* @throws {PlolinkError} 当会话不存在或删除失败时抛出
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```typescript
|
|
494
|
+
* // 删除评测会话
|
|
495
|
+
* await client.psychologyTest.deleteTestSession('clxxxx789012');
|
|
496
|
+
* console.log('评测会话已删除');
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
async deleteTestSession(sessionId) {
|
|
500
|
+
this.client.logger.info("Deleting psychology test session", { sessionId });
|
|
501
|
+
if (!sessionId) {
|
|
502
|
+
throw new PlolinkError(
|
|
503
|
+
"sessionId is required",
|
|
504
|
+
"VALIDATION_ERROR"
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
try {
|
|
508
|
+
await this.client.axiosInstance.delete(
|
|
509
|
+
`/api/admin/psychology/test-sessions/${sessionId}`
|
|
510
|
+
);
|
|
511
|
+
this.client.logger.info("Psychology test session deleted successfully", {
|
|
512
|
+
sessionId
|
|
513
|
+
});
|
|
514
|
+
} catch (error) {
|
|
515
|
+
this.client.logger.error("Failed to delete psychology test session", { error });
|
|
516
|
+
throw error;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* 获取题库组列表
|
|
521
|
+
*
|
|
522
|
+
* @description
|
|
523
|
+
* 获取所有启用状态的题库组列表,返回基本信息用于选择。
|
|
524
|
+
* 此接口不需要管理员权限,普通用户即可调用。
|
|
525
|
+
*
|
|
526
|
+
* @returns 题库组列表
|
|
527
|
+
* @throws {PlolinkError} 当查询失败时抛出
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* const groups = await client.psychologyTest.listBankGroups();
|
|
532
|
+
* groups.forEach(g => {
|
|
533
|
+
* console.log(`${g.name} (${g.code}): ${g.testObjective}`);
|
|
534
|
+
* });
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
async listBankGroups() {
|
|
538
|
+
this.client.logger.info("Listing psychology bank groups");
|
|
539
|
+
try {
|
|
540
|
+
const response = await this.client.axiosInstance.get(
|
|
541
|
+
"/api/v1/psychology/bank-groups"
|
|
542
|
+
);
|
|
543
|
+
this.client.logger.info("Psychology bank groups listed successfully", {
|
|
544
|
+
count: response.length
|
|
545
|
+
});
|
|
546
|
+
return response;
|
|
547
|
+
} catch (error) {
|
|
548
|
+
this.client.logger.error("Failed to list psychology bank groups", { error });
|
|
549
|
+
throw error;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
|
|
190
554
|
// src/core/client.ts
|
|
191
555
|
var PlolinkClient = class {
|
|
192
556
|
/**
|
|
@@ -221,6 +585,7 @@ var PlolinkClient = class {
|
|
|
221
585
|
this.config,
|
|
222
586
|
this.logger
|
|
223
587
|
);
|
|
588
|
+
this.psychologyTest = new PsychologyTest(this);
|
|
224
589
|
}
|
|
225
590
|
/**
|
|
226
591
|
* 验证 SDK 配置
|
|
@@ -291,6 +656,269 @@ var PlolinkClient = class {
|
|
|
291
656
|
}
|
|
292
657
|
};
|
|
293
658
|
|
|
659
|
+
// src/modules/info-sync/index.ts
|
|
660
|
+
var InfoSync = class {
|
|
661
|
+
constructor(client) {
|
|
662
|
+
this.client = client;
|
|
663
|
+
}
|
|
664
|
+
// ==================== Webhook 配置管理 ====================
|
|
665
|
+
/**
|
|
666
|
+
* 创建 Webhook 配置
|
|
667
|
+
*
|
|
668
|
+
* @description
|
|
669
|
+
* 为当前团队创建一个新的 Webhook 配置。
|
|
670
|
+
* 返回的 secretKey 仅在创建时返回一次,请立即保存。
|
|
671
|
+
*
|
|
672
|
+
* 每个团队最多可以创建 10 个 Webhook 配置。
|
|
673
|
+
*
|
|
674
|
+
* ⚠️ 重要: secretKey 仅在创建时返回,后续无法再次获取,请妥善保存
|
|
675
|
+
*
|
|
676
|
+
* @param params - 创建参数
|
|
677
|
+
* @returns 创建结果,包含配置 ID 和密钥
|
|
678
|
+
* @throws {PlolinkError} 当参数无效、配置数量超限或权限不足时抛出
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* ```typescript
|
|
682
|
+
* const result = await infoSync.createWebhookConfig({
|
|
683
|
+
* name: 'Production Webhook',
|
|
684
|
+
* url: 'https://example.com/webhook/plolink',
|
|
685
|
+
* modules: ['report-writer', 'video-psych-analysis']
|
|
686
|
+
* });
|
|
687
|
+
*
|
|
688
|
+
* console.log(`配置 ID: ${result.id}`);
|
|
689
|
+
* console.log(`SecretKey: ${result.secretKey}`);
|
|
690
|
+
* // 请立即保存 secretKey,后续无法再次获取
|
|
691
|
+
* ```
|
|
692
|
+
*/
|
|
693
|
+
async createWebhookConfig(params) {
|
|
694
|
+
if (!params.name || params.name.trim().length === 0) {
|
|
695
|
+
throw new PlolinkError("name is required and cannot be empty", "INVALID_PARAMS");
|
|
696
|
+
}
|
|
697
|
+
if (!params.url || params.url.trim().length === 0) {
|
|
698
|
+
throw new PlolinkError("url is required and cannot be empty", "INVALID_PARAMS");
|
|
699
|
+
}
|
|
700
|
+
if (!params.url.startsWith("http://") && !params.url.startsWith("https://")) {
|
|
701
|
+
throw new PlolinkError("url must start with http:// or https://", "INVALID_PARAMS");
|
|
702
|
+
}
|
|
703
|
+
if (!Array.isArray(params.modules)) {
|
|
704
|
+
throw new PlolinkError("modules must be an array", "INVALID_PARAMS");
|
|
705
|
+
}
|
|
706
|
+
return this.client.axiosInstance.post("/api/v1/info-sync/webhook-configs", params);
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* 获取 Webhook 配置列表
|
|
710
|
+
*
|
|
711
|
+
* @description
|
|
712
|
+
* 获取当前团队的所有 Webhook 配置。
|
|
713
|
+
* 注意:列表中不包含 secretKey。
|
|
714
|
+
*
|
|
715
|
+
* @returns Webhook 配置列表
|
|
716
|
+
* @throws {PlolinkError} 当权限不足时抛出
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* ```typescript
|
|
720
|
+
* const configs = await infoSync.listWebhookConfigs();
|
|
721
|
+
* configs.forEach(config => {
|
|
722
|
+
* console.log(`${config.name}: ${config.url}`);
|
|
723
|
+
* console.log(`订阅模块: ${config.modules.join(', ')}`);
|
|
724
|
+
* console.log(`状态: ${config.enabled ? '启用' : '禁用'}`);
|
|
725
|
+
* });
|
|
726
|
+
* ```
|
|
727
|
+
*/
|
|
728
|
+
async listWebhookConfigs() {
|
|
729
|
+
return this.client.axiosInstance.get("/api/v1/info-sync/webhook-configs");
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* 获取 Webhook 配置详情
|
|
733
|
+
*
|
|
734
|
+
* @description
|
|
735
|
+
* 获取指定 Webhook 配置的详细信息。
|
|
736
|
+
* 注意:不包含 secretKey。
|
|
737
|
+
*
|
|
738
|
+
* @param id - 配置 ID
|
|
739
|
+
* @returns Webhook 配置详情
|
|
740
|
+
* @throws {PlolinkError} 当配置不存在或权限不足时抛出
|
|
741
|
+
*
|
|
742
|
+
* @example
|
|
743
|
+
* ```typescript
|
|
744
|
+
* const config = await infoSync.getWebhookConfig('config-123');
|
|
745
|
+
* console.log(`名称: ${config.name}`);
|
|
746
|
+
* console.log(`URL: ${config.url}`);
|
|
747
|
+
* console.log(`订阅模块: ${config.modules.join(', ')}`);
|
|
748
|
+
* ```
|
|
749
|
+
*/
|
|
750
|
+
async getWebhookConfig(id) {
|
|
751
|
+
if (!id) {
|
|
752
|
+
throw new PlolinkError("id is required", "INVALID_PARAMS");
|
|
753
|
+
}
|
|
754
|
+
return this.client.axiosInstance.get(`/api/v1/info-sync/webhook-configs/${id}`);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* 更新 Webhook 配置
|
|
758
|
+
*
|
|
759
|
+
* @description
|
|
760
|
+
* 更新指定 Webhook 配置的信息。
|
|
761
|
+
* 注意:不能更新 secretKey,如需更换密钥请删除后重新创建。
|
|
762
|
+
*
|
|
763
|
+
* @param id - 配置 ID
|
|
764
|
+
* @param params - 更新参数
|
|
765
|
+
* @throws {PlolinkError} 当参数无效、配置不存在或权限不足时抛出
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```typescript
|
|
769
|
+
* // 禁用配置
|
|
770
|
+
* await infoSync.updateWebhookConfig('config-123', {
|
|
771
|
+
* enabled: false
|
|
772
|
+
* });
|
|
773
|
+
*
|
|
774
|
+
* // 更新订阅模块
|
|
775
|
+
* await infoSync.updateWebhookConfig('config-123', {
|
|
776
|
+
* modules: ['report-writer']
|
|
777
|
+
* });
|
|
778
|
+
*
|
|
779
|
+
* // 更新 URL
|
|
780
|
+
* await infoSync.updateWebhookConfig('config-123', {
|
|
781
|
+
* url: 'https://new-url.example.com/webhook'
|
|
782
|
+
* });
|
|
783
|
+
* ```
|
|
784
|
+
*/
|
|
785
|
+
async updateWebhookConfig(id, params) {
|
|
786
|
+
if (!id) {
|
|
787
|
+
throw new PlolinkError("id is required", "INVALID_PARAMS");
|
|
788
|
+
}
|
|
789
|
+
if (params.url && (!params.url.startsWith("http://") && !params.url.startsWith("https://"))) {
|
|
790
|
+
throw new PlolinkError("url must start with http:// or https://", "INVALID_PARAMS");
|
|
791
|
+
}
|
|
792
|
+
if (params.modules !== void 0 && !Array.isArray(params.modules)) {
|
|
793
|
+
throw new PlolinkError("modules must be an array", "INVALID_PARAMS");
|
|
794
|
+
}
|
|
795
|
+
await this.client.axiosInstance.put(`/api/v1/info-sync/webhook-configs/${id}`, params);
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* 删除 Webhook 配置
|
|
799
|
+
*
|
|
800
|
+
* @description
|
|
801
|
+
* 永久删除指定的 Webhook 配置(软删除)。
|
|
802
|
+
* 删除后该配置将不再接收 Webhook 通知。
|
|
803
|
+
*
|
|
804
|
+
* ⚠️ 警告: 此操作不可逆,请确认后再执行
|
|
805
|
+
*
|
|
806
|
+
* @param id - 配置 ID
|
|
807
|
+
* @throws {PlolinkError} 当配置不存在或权限不足时抛出
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
810
|
+
* ```typescript
|
|
811
|
+
* await infoSync.deleteWebhookConfig('config-123');
|
|
812
|
+
* console.log('Webhook 配置已删除');
|
|
813
|
+
* ```
|
|
814
|
+
*/
|
|
815
|
+
async deleteWebhookConfig(id) {
|
|
816
|
+
if (!id) {
|
|
817
|
+
throw new PlolinkError("id is required", "INVALID_PARAMS");
|
|
818
|
+
}
|
|
819
|
+
await this.client.axiosInstance.delete(`/api/v1/info-sync/webhook-configs/${id}`);
|
|
820
|
+
}
|
|
821
|
+
// ==================== 同步记录查询 ====================
|
|
822
|
+
/**
|
|
823
|
+
* 查询同步记录列表
|
|
824
|
+
*
|
|
825
|
+
* @description
|
|
826
|
+
* 查询当前团队的同步记录,支持多种过滤条件和分页。
|
|
827
|
+
*
|
|
828
|
+
* @param params - 查询参数
|
|
829
|
+
* @returns 分页的同步记录列表
|
|
830
|
+
* @throws {PlolinkError} 当参数无效或权限不足时抛出
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
* ```typescript
|
|
834
|
+
* // 查询所有记录
|
|
835
|
+
* const result = await infoSync.listSyncRecords();
|
|
836
|
+
* console.log(`共 ${result.total} 条记录`);
|
|
837
|
+
*
|
|
838
|
+
* // 查询失败的 Webhook 同步记录
|
|
839
|
+
* const failed = await infoSync.listSyncRecords({
|
|
840
|
+
* type: 'WEBHOOK',
|
|
841
|
+
* status: 'FAILED'
|
|
842
|
+
* });
|
|
843
|
+
* console.log(`${failed.total} 条 Webhook 同步失败`);
|
|
844
|
+
*
|
|
845
|
+
* // 查询报告写作模块的记录
|
|
846
|
+
* const reports = await infoSync.listSyncRecords({
|
|
847
|
+
* businessModule: 'report-writer',
|
|
848
|
+
* page: 1,
|
|
849
|
+
* pageSize: 20
|
|
850
|
+
* });
|
|
851
|
+
* ```
|
|
852
|
+
*/
|
|
853
|
+
async listSyncRecords(params) {
|
|
854
|
+
return this.client.axiosInstance.get("/api/v1/info-sync/sync-records", {
|
|
855
|
+
params: params || {}
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* 获取同步记录详情
|
|
860
|
+
*
|
|
861
|
+
* @description
|
|
862
|
+
* 获取指定同步记录的详细信息,包括完整的历史记录。
|
|
863
|
+
*
|
|
864
|
+
* @param id - 记录 ID
|
|
865
|
+
* @returns 同步记录详情
|
|
866
|
+
* @throws {PlolinkError} 当记录不存在或权限不足时抛出
|
|
867
|
+
*
|
|
868
|
+
* @example
|
|
869
|
+
* ```typescript
|
|
870
|
+
* const record = await infoSync.getSyncRecord('record-123');
|
|
871
|
+
* console.log(`业务模块: ${record.businessModule}`);
|
|
872
|
+
* console.log(`业务代码: ${record.businessCode}`);
|
|
873
|
+
* console.log(`状态: ${record.status}`);
|
|
874
|
+
* console.log(`历史记录:`);
|
|
875
|
+
* record.history.forEach(item => {
|
|
876
|
+
* console.log(` ${new Date(item.time).toLocaleString()}: ${item.status} - ${item.message || ''}`);
|
|
877
|
+
* });
|
|
878
|
+
* ```
|
|
879
|
+
*/
|
|
880
|
+
async getSyncRecord(id) {
|
|
881
|
+
if (!id) {
|
|
882
|
+
throw new PlolinkError("id is required", "INVALID_PARAMS");
|
|
883
|
+
}
|
|
884
|
+
return this.client.axiosInstance.get(`/api/v1/info-sync/sync-records/${id}`);
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* 手动重试同步任务
|
|
888
|
+
*
|
|
889
|
+
* @description
|
|
890
|
+
* 手动重试失败的同步任务。
|
|
891
|
+
* 只能重试状态为 FAILED 的记录。
|
|
892
|
+
*
|
|
893
|
+
* 重试后记录状态将变为 PENDING,并重新提交到队列处理。
|
|
894
|
+
*
|
|
895
|
+
* @param id - 记录 ID
|
|
896
|
+
* @throws {PlolinkError} 当记录不存在、状态不是 FAILED 或权限不足时抛出
|
|
897
|
+
*
|
|
898
|
+
* @example
|
|
899
|
+
* ```typescript
|
|
900
|
+
* // 查询失败记录
|
|
901
|
+
* const failed = await infoSync.listSyncRecords({ status: 'FAILED' });
|
|
902
|
+
*
|
|
903
|
+
* // 重试所有失败记录
|
|
904
|
+
* for (const record of failed.list) {
|
|
905
|
+
* try {
|
|
906
|
+
* await infoSync.retrySyncRecord(record.id);
|
|
907
|
+
* console.log(`已重试: ${record.id}`);
|
|
908
|
+
* } catch (error) {
|
|
909
|
+
* console.error(`重试失败: ${record.id}`, error);
|
|
910
|
+
* }
|
|
911
|
+
* }
|
|
912
|
+
* ```
|
|
913
|
+
*/
|
|
914
|
+
async retrySyncRecord(id) {
|
|
915
|
+
if (!id) {
|
|
916
|
+
throw new PlolinkError("id is required", "INVALID_PARAMS");
|
|
917
|
+
}
|
|
918
|
+
await this.client.axiosInstance.post(`/api/v1/info-sync/sync-records/${id}/retry`);
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
|
|
294
922
|
// src/index.ts
|
|
295
923
|
var VERSION = "1.0.0";
|
|
296
924
|
var DEFAULT_CONFIG = {
|
|
@@ -301,6 +929,6 @@ var DEFAULT_CONFIG = {
|
|
|
301
929
|
backoffFactor: 1.5
|
|
302
930
|
};
|
|
303
931
|
|
|
304
|
-
export { DEFAULT_CONFIG, InternalLogger, PlolinkClient, VERSION };
|
|
932
|
+
export { DEFAULT_CONFIG, InfoSync, InternalLogger, PlolinkClient, PsychologyTest, VERSION };
|
|
305
933
|
//# sourceMappingURL=index.js.map
|
|
306
934
|
//# sourceMappingURL=index.js.map
|