@xbongbong/xbbcli 2.0.0
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 +436 -0
- package/ai-call-add-task.js +106 -0
- package/ai-word-list.js +81 -0
- package/bin/xbbcli.js +120 -0
- package/buyer-inquiry-detail.js +112 -0
- package/buyer-inquiry-list.js +142 -0
- package/clue-add-couser.js +86 -0
- package/clue-add.js +102 -0
- package/clue-back.js +82 -0
- package/clue-del.js +75 -0
- package/clue-delete-couser.js +84 -0
- package/clue-delete-mainuser.js +84 -0
- package/clue-detail.js +78 -0
- package/clue-distribution.js +91 -0
- package/clue-edit.js +101 -0
- package/clue-handover.js +103 -0
- package/clue-list.js +224 -0
- package/clue-thorough-delete.js +82 -0
- package/communicate-add.js +144 -0
- package/communicate-del.js +118 -0
- package/communicate-detail.js +123 -0
- package/communicate-edit.js +146 -0
- package/communicate-list.js +194 -0
- package/communicate-plan-add.js +102 -0
- package/communicate-plan-cancel.js +76 -0
- package/communicate-plan-del.js +76 -0
- package/communicate-plan-detail.js +79 -0
- package/communicate-plan-list.js +129 -0
- package/communicate-plan-single-operate.js +86 -0
- package/contact-add-couser.js +87 -0
- package/contact-add-mainuser.js +87 -0
- package/contact-add.js +125 -0
- package/contact-del.js +70 -0
- package/contact-delete-couser.js +87 -0
- package/contact-delete-mainuser.js +87 -0
- package/contact-detail.js +72 -0
- package/contact-edit.js +103 -0
- package/contact-handover.js +84 -0
- package/contact-list.js +195 -0
- package/contract-add-couser.js +129 -0
- package/contract-add-mainuser.js +129 -0
- package/contract-add.js +148 -0
- package/contract-del.js +117 -0
- package/contract-delete-couser.js +128 -0
- package/contract-delete-mainuser.js +129 -0
- package/contract-detail.js +124 -0
- package/contract-edit.js +147 -0
- package/contract-handover.js +129 -0
- package/contract-list.js +235 -0
- package/contract-outstock-add.js +104 -0
- package/contract-outstock-del.js +78 -0
- package/contract-outstock-detail.js +80 -0
- package/contract-outstock-edit.js +106 -0
- package/contract-outstock-list.js +121 -0
- package/customer-add-couser.js +186 -0
- package/customer-add.js +152 -0
- package/customer-back.js +125 -0
- package/customer-del.js +117 -0
- package/customer-delete-couser.js +128 -0
- package/customer-delete-mainuser.js +129 -0
- package/customer-detail.js +148 -0
- package/customer-distribution.js +132 -0
- package/customer-edit.js +174 -0
- package/customer-handover.js +131 -0
- package/customer-invoice-address-add.js +101 -0
- package/customer-invoice-address-edit.js +102 -0
- package/customer-invoice-address.js +86 -0
- package/customer-invoice-info-add.js +101 -0
- package/customer-invoice-info-edit.js +102 -0
- package/customer-invoice-info.js +88 -0
- package/customer-list.js +187 -0
- package/department-add.js +77 -0
- package/department-del.js +76 -0
- package/department-edit.js +77 -0
- package/department-list.js +190 -0
- package/form-data-add-couser.js +84 -0
- package/form-data-add-mainuser.js +84 -0
- package/form-data-add.js +171 -0
- package/form-data-del.js +135 -0
- package/form-data-delete-couser.js +85 -0
- package/form-data-delete-mainuser.js +84 -0
- package/form-data-detail.js +146 -0
- package/form-data-edit.js +171 -0
- package/form-data-handover.js +84 -0
- package/form-data-list.js +188 -0
- package/form-get.js +157 -0
- package/form-list.js +169 -0
- package/invoice-add.js +98 -0
- package/invoice-cancel.js +97 -0
- package/invoice-del.js +83 -0
- package/invoice-detail.js +85 -0
- package/invoice-edit.js +101 -0
- package/invoice-get-amount-detail.js +84 -0
- package/invoice-list.js +125 -0
- package/invoice-red.js +101 -0
- package/label-add.js +93 -0
- package/label-all-list.js +102 -0
- package/label-batch-add.js +111 -0
- package/label-batch-remove.js +111 -0
- package/label-del-completely.js +88 -0
- package/label-del.js +98 -0
- package/label-edit.js +96 -0
- package/label-group-add.js +89 -0
- package/label-group-del.js +83 -0
- package/label-group-list.js +87 -0
- package/label-group-update.js +92 -0
- package/label-list.js +97 -0
- package/label-reduction.js +92 -0
- package/label-repeat.js +89 -0
- package/market-activity-add.js +109 -0
- package/market-activity-del.js +83 -0
- package/market-activity-detail.js +84 -0
- package/market-activity-edit.js +106 -0
- package/market-activity-handover.js +88 -0
- package/market-activity-list.js +121 -0
- package/opportunity-add-couser.js +129 -0
- package/opportunity-add-mainuser.js +129 -0
- package/opportunity-add.js +147 -0
- package/opportunity-del.js +118 -0
- package/opportunity-delete-couser.js +129 -0
- package/opportunity-delete-mainuser.js +128 -0
- package/opportunity-detail.js +125 -0
- package/opportunity-edit.js +146 -0
- package/opportunity-handover.js +130 -0
- package/opportunity-list.js +169 -0
- package/package.json +34 -0
- package/pay-plan-add-couser.js +88 -0
- package/pay-plan-add-mainuser.js +88 -0
- package/pay-plan-add.js +104 -0
- package/pay-plan-delete-couser.js +87 -0
- package/pay-plan-delete-mainuser.js +87 -0
- package/pay-plan-handover.js +85 -0
- package/pay-sheet-add-bad.js +104 -0
- package/pay-sheet-add-couser.js +87 -0
- package/pay-sheet-add-mainuser.js +88 -0
- package/pay-sheet-add-red.js +104 -0
- package/pay-sheet-add-write-off.js +104 -0
- package/pay-sheet-del.js +86 -0
- package/pay-sheet-delete-couser.js +87 -0
- package/pay-sheet-delete-mainuser.js +88 -0
- package/pay-sheet-detail.js +85 -0
- package/pay-sheet-edit-bad.js +110 -0
- package/pay-sheet-edit-red.js +110 -0
- package/pay-sheet-edit-write-off.js +106 -0
- package/pay-sheet-get-amount-detail.js +83 -0
- package/pay-sheet-list.js +123 -0
- package/payment-add-couser.js +129 -0
- package/payment-add-mainuser.js +129 -0
- package/payment-add.js +142 -0
- package/payment-del.js +117 -0
- package/payment-delete-couser.js +128 -0
- package/payment-delete-mainuser.js +128 -0
- package/payment-detail.js +123 -0
- package/payment-edit.js +146 -0
- package/payment-handover.js +130 -0
- package/payment-list.js +195 -0
- package/payment-sheet-add-bad-debt.js +142 -0
- package/payment-sheet-add-pre.js +104 -0
- package/payment-sheet-add-red.js +142 -0
- package/payment-sheet-add-write-off.js +130 -0
- package/payment-sheet-del.js +106 -0
- package/payment-sheet-detail.js +113 -0
- package/payment-sheet-edit-bad-debt.js +131 -0
- package/payment-sheet-edit-red.js +146 -0
- package/payment-sheet-edit-write-off.js +146 -0
- package/payment-sheet-get-amount-detail.js +84 -0
- package/payment-sheet-handover.js +85 -0
- package/payment-sheet-list.js +206 -0
- package/product-add.js +129 -0
- package/product-category-add.js +124 -0
- package/product-category-del.js +132 -0
- package/product-category-list.js +164 -0
- package/product-category-update.js +139 -0
- package/product-del.js +106 -0
- package/product-detail.js +183 -0
- package/product-edit.js +131 -0
- package/product-list.js +193 -0
- package/product-online.js +91 -0
- package/quotation-add-couser.js +106 -0
- package/quotation-add-mainuser.js +101 -0
- package/quotation-add.js +100 -0
- package/quotation-del.js +83 -0
- package/quotation-delete-couser.js +101 -0
- package/quotation-delete-mainuser.js +101 -0
- package/quotation-detail.js +85 -0
- package/quotation-edit.js +101 -0
- package/quotation-handover.js +84 -0
- package/quotation-list.js +123 -0
- package/refund-add.js +83 -0
- package/refund-del.js +68 -0
- package/refund-detail.js +71 -0
- package/refund-edit.js +84 -0
- package/refund-list.js +193 -0
- package/role-list.js +85 -0
- package/sign-in-list.js +136 -0
- package/stage-get.js +100 -0
- package/stage-jump.js +109 -0
- package/supplier-add.js +142 -0
- package/token-generate.js +109 -0
- package/token-set.js +222 -0
- package/user-add.js +103 -0
- package/user-del.js +90 -0
- package/user-edit.js +102 -0
- package/user-handover.js +78 -0
- package/user-list.js +147 -0
- package/version.js +18 -0
- package/work-order-add.js +171 -0
- package/work-order-asset-add-couser.js +101 -0
- package/work-order-asset-add-mainuser.js +104 -0
- package/work-order-asset-add.js +98 -0
- package/work-order-asset-del-couser.js +101 -0
- package/work-order-asset-del-mainuser.js +101 -0
- package/work-order-asset-del.js +83 -0
- package/work-order-asset-detail.js +85 -0
- package/work-order-asset-edit.js +101 -0
- package/work-order-asset-handover.js +101 -0
- package/work-order-asset-list.js +123 -0
- package/work-order-del.js +136 -0
- package/work-order-detail.js +186 -0
- package/work-order-dynamic-list.js +145 -0
- package/work-order-edit.js +170 -0
- package/work-order-list.js +243 -0
- package/work-order-operate.js +167 -0
- package/work-order-template-detail.js +157 -0
- package/work-order-template-list.js +145 -0
- package/work-report-daily-add.js +97 -0
- package/work-report-daily-del.js +75 -0
- package/work-report-daily-detail.js +78 -0
- package/work-report-daily-edit.js +129 -0
- package/work-report-daily-get-work-plan.js +80 -0
- package/work-report-daily-list.js +116 -0
- package/work-report-monthly-add.js +98 -0
- package/work-report-monthly-del.js +79 -0
- package/work-report-monthly-detail.js +78 -0
- package/work-report-monthly-edit.js +98 -0
- package/work-report-monthly-list.js +116 -0
- package/work-report-weekly-add.js +98 -0
- package/work-report-weekly-del.js +76 -0
- package/work-report-weekly-detail.js +79 -0
- package/work-report-weekly-edit.js +99 -0
- package/work-report-weekly-list.js +116 -0
- package/work-task-add-couser.js +88 -0
- package/work-task-add.js +242 -0
- package/work-task-delete-couser.js +85 -0
- package/work-task-detail.js +101 -0
- package/work-task-edit.js +116 -0
- package/work-task-handover.js +85 -0
- package/workorder-add-couser.js +128 -0
- package/workorder-delete-couser.js +129 -0
- package/workorder-handover.js +137 -0
- package/workorderlist.js +194 -0
- package/workorderproductlist.js +159 -0
- package/worktimerecorddetail.js +157 -0
- package/worktimerecordlist.js +199 -0
- package/xbb-registry.js +21 -0
package/user-handover.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { cli, Strategy } from './xbb-registry.js';
|
|
6
|
+
|
|
7
|
+
const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
|
|
8
|
+
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/user/handover';
|
|
9
|
+
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
10
|
+
const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
|
|
11
|
+
|
|
12
|
+
function readConfig() {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
15
|
+
} catch {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getRuntimeConfig() {
|
|
21
|
+
const config = readConfig();
|
|
22
|
+
return {
|
|
23
|
+
corpid: String(config.corpid || '').trim(),
|
|
24
|
+
token: String(config.token || '').trim(),
|
|
25
|
+
baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
|
|
26
|
+
userId: String(config.userId || '').trim(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function buildApiUrl(baseUrl, apiUrl) {
|
|
31
|
+
const apiPath = new URL(apiUrl).pathname;
|
|
32
|
+
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function makeErrorRow(code, msg) {
|
|
36
|
+
return [{ code, msg }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cli({
|
|
40
|
+
site: 'xbb',
|
|
41
|
+
name: 'user-handover',
|
|
42
|
+
description: '用户交接接口(businessType: -1)',
|
|
43
|
+
strategy: Strategy.PUBLIC,
|
|
44
|
+
access: 'write',
|
|
45
|
+
browser: false,
|
|
46
|
+
domain: 'proapi.xbongbong.com',
|
|
47
|
+
args: [
|
|
48
|
+
{ name: 'fromUserId', type: 'str', help: '需要交接工作的员工userId(必填)' },
|
|
49
|
+
{ name: 'toUserId', type: 'str', help: '交接目标员工userId(必填)' },
|
|
50
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
51
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
52
|
+
],
|
|
53
|
+
columns: ['code', 'msg'],
|
|
54
|
+
func: async function (kwargs) {
|
|
55
|
+
const debug = Boolean(kwargs.debug);
|
|
56
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
57
|
+
const payload = { fromUserId: String(kwargs.fromUserId || ''), toUserId: String(kwargs.toUserId || ''), corpid };
|
|
58
|
+
if (kwargs.userId) payload.userId = String(kwargs.userId);
|
|
59
|
+
const requestBody = JSON.stringify(payload);
|
|
60
|
+
if (!payload.fromUserId) return makeErrorRow('NO_FROMUSERID', '缺少 --fromUserId');
|
|
61
|
+
if (!payload.toUserId) return makeErrorRow('NO_TOUSERID', '缺少 --toUserId');
|
|
62
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
63
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
64
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
65
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, userId ? { userId } : {});
|
|
66
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
67
|
+
if (debug) {
|
|
68
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
69
|
+
}
|
|
70
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
|
|
71
|
+
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
72
|
+
const data = await resp.json();
|
|
73
|
+
const responseBody = JSON.stringify(data);
|
|
74
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
75
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
76
|
+
return [{ code: data.code ?? '', msg: data.msg || '' }];
|
|
77
|
+
},
|
|
78
|
+
});
|
package/user-list.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import { cli, Strategy } from './xbb-registry.js';
|
|
6
|
+
|
|
7
|
+
const CONFIG_DIR = path.join(os.homedir(), '.xbbcli');
|
|
8
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.env');
|
|
9
|
+
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
10
|
+
const USER_LIST_API_PATH = '/pro/v2/api/user/list';
|
|
11
|
+
let lastPagination = null;
|
|
12
|
+
|
|
13
|
+
function readConfig() {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
16
|
+
} catch {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getRuntimeConfig() {
|
|
22
|
+
const config = readConfig();
|
|
23
|
+
return {
|
|
24
|
+
corpid: String(config.corpid || '').trim(),
|
|
25
|
+
token: String(config.token || '').trim(),
|
|
26
|
+
baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
|
|
27
|
+
userId: String(config.userId || '').trim(),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function buildApiUrl(baseUrl) {
|
|
32
|
+
return `${baseUrl.replace(/\/+$/, '')}${USER_LIST_API_PATH}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function buildPayload(kwargs, corpid) {
|
|
36
|
+
const payload = {
|
|
37
|
+
corpid,
|
|
38
|
+
...(String(kwargs.page ?? '') !== '' ? { page: Number(kwargs.page) } : {}),
|
|
39
|
+
...(String(kwargs.pageSize ?? '') !== '' ? { pageSize: Number(kwargs.pageSize) } : {}),
|
|
40
|
+
};
|
|
41
|
+
if (kwargs.userId) payload.userId = String(kwargs.userId);
|
|
42
|
+
if (kwargs.name) payload.name = String(kwargs.name);
|
|
43
|
+
if (kwargs.nameLike) payload.nameLike = String(kwargs.nameLike);
|
|
44
|
+
if (Number(kwargs.departmentId || 0)) payload.departmentId = Number(kwargs.departmentId);
|
|
45
|
+
if (Number(kwargs.delIgnore || 0)) payload.delIgnore = Number(kwargs.delIgnore);
|
|
46
|
+
return payload;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function makeErrorRow(code, msg) {
|
|
50
|
+
return [{
|
|
51
|
+
rank: '',
|
|
52
|
+
userId: '',
|
|
53
|
+
name: '',
|
|
54
|
+
position: '',
|
|
55
|
+
jobnumber: '',
|
|
56
|
+
avatar: '',
|
|
57
|
+
code,
|
|
58
|
+
msg,
|
|
59
|
+
}];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
cli({
|
|
63
|
+
site: 'xbb',
|
|
64
|
+
name: 'user-list',
|
|
65
|
+
description: '用户列表接口(businessType: -1)',
|
|
66
|
+
strategy: Strategy.PUBLIC,
|
|
67
|
+
access: 'read',
|
|
68
|
+
browser: false,
|
|
69
|
+
domain: 'proapi.xbongbong.com',
|
|
70
|
+
args: [
|
|
71
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
72
|
+
{ name: 'name', type: 'str', default: '', help: '员工姓名完全匹配(可选)' },
|
|
73
|
+
{ name: 'nameLike', type: 'str', default: '', help: '员工姓名模糊查询(可选)' },
|
|
74
|
+
{ name: 'departmentId', type: 'int', default: 0, help: '部门id筛选(可选)' },
|
|
75
|
+
{ name: 'delIgnore', type: 'int', default: 0, help: '是否查询已离职员工,0不查/1查询' },
|
|
76
|
+
{ name: 'page', type: 'str', default: '', help: '页码(可选)' },
|
|
77
|
+
{ name: 'pageSize', type: 'str', default: '', help: '每页数量(可选)' },
|
|
78
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
79
|
+
{ name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
|
|
80
|
+
],
|
|
81
|
+
columns: ['rank', 'userId', 'name', 'position', 'jobnumber', 'avatar', 'code', 'msg'],
|
|
82
|
+
footerExtra: () => (lastPagination ? `totalCount ${lastPagination.totalCount} / totalPage ${lastPagination.totalPage}` : undefined),
|
|
83
|
+
func: async (kwargs) => {
|
|
84
|
+
const debug = Boolean(kwargs.debug);
|
|
85
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
86
|
+
const payload = buildPayload(kwargs, corpid);
|
|
87
|
+
const body = JSON.stringify(payload);
|
|
88
|
+
|
|
89
|
+
if (!payload.corpid) {
|
|
90
|
+
return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
91
|
+
}
|
|
92
|
+
if (!token) {
|
|
93
|
+
return makeErrorRow('NO_TOKEN', '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const sign = crypto.createHash('sha256').update(body + token).digest('hex');
|
|
97
|
+
const headers = {
|
|
98
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
99
|
+
sign,
|
|
100
|
+
};
|
|
101
|
+
if (userId) headers.userId = userId;
|
|
102
|
+
const apiUrl = buildApiUrl(baseUrl);
|
|
103
|
+
|
|
104
|
+
if (debug) {
|
|
105
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const resp = await fetch(apiUrl, {
|
|
109
|
+
method: 'POST',
|
|
110
|
+
headers,
|
|
111
|
+
body,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (!resp.ok) {
|
|
115
|
+
const responseText = await resp.text();
|
|
116
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
117
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const data = await resp.json();
|
|
121
|
+
lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
|
|
122
|
+
? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
|
|
123
|
+
: null;
|
|
124
|
+
const responseBody = JSON.stringify(data);
|
|
125
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
126
|
+
if (kwargs.raw) return [{ raw: responseBody }];
|
|
127
|
+
if (data.code !== 1) {
|
|
128
|
+
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const list = Array.isArray(data.result?.userList) ? data.result.userList : [];
|
|
132
|
+
if (!list.length) {
|
|
133
|
+
return makeErrorRow('NO_DATA', '接口成功,但 userList 为空');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return list.map((item, index) => ({
|
|
137
|
+
rank: index + 1,
|
|
138
|
+
userId: item.userId || '',
|
|
139
|
+
name: item.name || '',
|
|
140
|
+
position: item.position || '',
|
|
141
|
+
jobnumber: item.jobnumber || '',
|
|
142
|
+
avatar: item.avatar || '',
|
|
143
|
+
code: '',
|
|
144
|
+
msg: '',
|
|
145
|
+
}));
|
|
146
|
+
},
|
|
147
|
+
});
|
package/version.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cli, Strategy } from './xbb-registry.js';
|
|
2
|
+
|
|
3
|
+
const VERSION = 'v1.6';
|
|
4
|
+
|
|
5
|
+
cli({
|
|
6
|
+
site: 'xbb',
|
|
7
|
+
name: 'version',
|
|
8
|
+
description: '查看销帮帮插件版本号',
|
|
9
|
+
strategy: Strategy.PUBLIC,
|
|
10
|
+
access: 'read',
|
|
11
|
+
browser: false,
|
|
12
|
+
domain: 'proapi.xbongbong.com',
|
|
13
|
+
args: [],
|
|
14
|
+
columns: ['version'],
|
|
15
|
+
func: async function () {
|
|
16
|
+
return [{ version: VERSION }];
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { cli, Strategy } from './xbb-registry.js';
|
|
6
|
+
|
|
7
|
+
const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
|
|
8
|
+
const WORK_ORDER_ADD_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workOrderV2/add';
|
|
9
|
+
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
10
|
+
const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
|
|
11
|
+
|
|
12
|
+
function readConfig() {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
15
|
+
} catch {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getRuntimeConfig() {
|
|
21
|
+
const config = readConfig();
|
|
22
|
+
return {
|
|
23
|
+
corpid: String(config.corpid || '').trim(),
|
|
24
|
+
token: String(config.token || '').trim(),
|
|
25
|
+
baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
|
|
26
|
+
userId: String(config.userId || '').trim(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function buildApiUrl(baseUrl, apiUrl) {
|
|
31
|
+
const apiPath = new URL(apiUrl).pathname;
|
|
32
|
+
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseDataList(raw) {
|
|
36
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
37
|
+
return raw;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const text = String(raw || '').trim();
|
|
41
|
+
if (!text) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const parsed = JSON.parse(text);
|
|
47
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
48
|
+
return parsed;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
} catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function buildPayload(kwargs, parsedDataList, corpid, defaultUserId) {
|
|
57
|
+
const payload = {
|
|
58
|
+
corpid,
|
|
59
|
+
formId: Number(kwargs.formId || 0),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const userId = String(kwargs.userId || defaultUserId || '').trim();
|
|
63
|
+
if (userId) {
|
|
64
|
+
payload.userId = userId;
|
|
65
|
+
}
|
|
66
|
+
if (parsedDataList) {
|
|
67
|
+
payload.dataList = parsedDataList;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return payload;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getValidationError(payload, token, parsedDataList) {
|
|
74
|
+
if (!payload.corpid) {
|
|
75
|
+
return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
|
|
76
|
+
}
|
|
77
|
+
if (!payload.formId) {
|
|
78
|
+
return { code: 'NO_FORMID', msg: '缺少 --formId' };
|
|
79
|
+
}
|
|
80
|
+
if (!token) {
|
|
81
|
+
return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
|
|
82
|
+
}
|
|
83
|
+
if (parsedDataList === null) {
|
|
84
|
+
return { code: 'NO_DATALIST', msg: '缺少 --dataList' };
|
|
85
|
+
}
|
|
86
|
+
if (parsedDataList === undefined) {
|
|
87
|
+
return { code: 'INVALID_DATALIST', msg: '--dataList 必须是 JSON 对象字符串' };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function makeErrorRow(code, msg) {
|
|
94
|
+
return [{
|
|
95
|
+
dataId: '',
|
|
96
|
+
resultCode: '',
|
|
97
|
+
resultMsg: '',
|
|
98
|
+
code,
|
|
99
|
+
msg,
|
|
100
|
+
}];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function makeSuccessRow(data) {
|
|
104
|
+
const result = data.result || {};
|
|
105
|
+
return [{
|
|
106
|
+
dataId: result.dataId || '',
|
|
107
|
+
resultCode: result.code ?? '',
|
|
108
|
+
resultMsg: result.msg || '',
|
|
109
|
+
code: data.code ?? '',
|
|
110
|
+
msg: data.msg || '',
|
|
111
|
+
}];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
cli({
|
|
115
|
+
site: 'xbb',
|
|
116
|
+
name: 'work-order-add',
|
|
117
|
+
description: '新增工单接口(businessType: 20300;formId必填)',
|
|
118
|
+
strategy: Strategy.PUBLIC,
|
|
119
|
+
access: 'write',
|
|
120
|
+
browser: false,
|
|
121
|
+
domain: 'proapi.xbongbong.com',
|
|
122
|
+
args: [
|
|
123
|
+
{ name: 'formId', type: 'int', help: '表单模板id(必填)' },
|
|
124
|
+
{ name: 'dataList', type: 'str', help: '表单数据JSON字符串(必填)' },
|
|
125
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
126
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
127
|
+
],
|
|
128
|
+
columns: ['dataId', 'resultCode', 'resultMsg', 'code', 'msg'],
|
|
129
|
+
func: async function (kwargs) {
|
|
130
|
+
const debug = Boolean(kwargs.debug);
|
|
131
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
132
|
+
const parsedDataList = parseDataList(kwargs.dataList);
|
|
133
|
+
const payload = buildPayload(kwargs, parsedDataList, corpid, userId);
|
|
134
|
+
const requestBody = JSON.stringify(payload);
|
|
135
|
+
|
|
136
|
+
const validationError = getValidationError(payload, token, parsedDataList);
|
|
137
|
+
if (validationError) {
|
|
138
|
+
return makeErrorRow(validationError.code, validationError.msg);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
142
|
+
const headers = Object.assign({
|
|
143
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
144
|
+
sign,
|
|
145
|
+
}, payload.userId ? { userId: payload.userId } : {});
|
|
146
|
+
const apiUrl = buildApiUrl(baseUrl, WORK_ORDER_ADD_API_URL);
|
|
147
|
+
if (debug) {
|
|
148
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
149
|
+
}
|
|
150
|
+
const resp = await fetch(apiUrl, {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
headers,
|
|
153
|
+
body: requestBody,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
if (!resp.ok) {
|
|
157
|
+
const responseText = await resp.text();
|
|
158
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
159
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const data = await resp.json();
|
|
163
|
+
const responseBody = JSON.stringify(data);
|
|
164
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
165
|
+
if (data.code !== 1) {
|
|
166
|
+
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return makeSuccessRow(data);
|
|
170
|
+
},
|
|
171
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { cli, Strategy } from './xbb-registry.js';
|
|
6
|
+
|
|
7
|
+
const CONFIG_FILE = path.join(os.homedir(), '.opencli', 'xbb', 'config.env');
|
|
8
|
+
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workOrderV2/asset/addCoUser';
|
|
9
|
+
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
10
|
+
const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
|
|
11
|
+
|
|
12
|
+
function readConfig() {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
15
|
+
} catch {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getRuntimeConfig() {
|
|
21
|
+
const config = readConfig();
|
|
22
|
+
return {
|
|
23
|
+
corpid: String(config.corpid || '').trim(),
|
|
24
|
+
token: String(config.token || '').trim(),
|
|
25
|
+
baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
|
|
26
|
+
userId: String(config.userId || '').trim(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function buildApiUrl(baseUrl, apiUrl) {
|
|
31
|
+
const apiPath = new URL(apiUrl).pathname;
|
|
32
|
+
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseJsonArray(raw) {
|
|
36
|
+
const text = String(raw || '').trim();
|
|
37
|
+
if (!text) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const parsed = JSON.parse(text);
|
|
42
|
+
return Array.isArray(parsed) ? parsed : undefined;
|
|
43
|
+
} catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function makeErrorRow(code, msg) {
|
|
49
|
+
return [{ resultCode: '', resultMsg: '', messageList: '', code, msg }];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
cli({
|
|
53
|
+
site: 'xbb',
|
|
54
|
+
name: 'work-order-asset-add-couser',
|
|
55
|
+
description: '资产添加协同人接口(businessType: -1;workOrderV2 资产)',
|
|
56
|
+
strategy: Strategy.PUBLIC,
|
|
57
|
+
access: 'write',
|
|
58
|
+
browser: false,
|
|
59
|
+
domain: 'proapi.xbongbong.com',
|
|
60
|
+
args: [
|
|
61
|
+
{ name: 'dataId', type: 'int', help: '资产id(必填)' },
|
|
62
|
+
{ name: 'businessUserIdList', type: 'str', help: '需添加的协同人id列表,JSON数组字符串(必填)' },
|
|
63
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
64
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
65
|
+
],
|
|
66
|
+
columns: ['resultCode', 'resultMsg', 'messageList', 'code', 'msg'],
|
|
67
|
+
func: async function (kwargs) {
|
|
68
|
+
const debug = Boolean(kwargs.debug);
|
|
69
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
70
|
+
const runtimeUserId = String(kwargs.userId || userId || '').trim();
|
|
71
|
+
const payload = { corpid };
|
|
72
|
+
payload.dataId = Number(kwargs.dataId || 0);
|
|
73
|
+
const parsedBusinessUserIdList = parseJsonArray(kwargs.businessUserIdList);
|
|
74
|
+
if (Array.isArray(parsedBusinessUserIdList)) payload.businessUserIdList = parsedBusinessUserIdList;
|
|
75
|
+
if (runtimeUserId) payload.userId = runtimeUserId;
|
|
76
|
+
const requestBody = JSON.stringify(payload);
|
|
77
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
78
|
+
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
79
|
+
if (parsedBusinessUserIdList === null) return makeErrorRow('NO_BUSINESSUSERIDLIST', '缺少 --businessUserIdList');
|
|
80
|
+
if (parsedBusinessUserIdList === undefined) return makeErrorRow('INVALID_BUSINESSUSERIDLIST', '--businessUserIdList 必须是 JSON 数组字符串');
|
|
81
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
82
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
83
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
|
|
84
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
85
|
+
if (debug) {
|
|
86
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
87
|
+
}
|
|
88
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
|
|
89
|
+
if (!resp.ok) {
|
|
90
|
+
const responseText = await resp.text();
|
|
91
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
92
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
93
|
+
}
|
|
94
|
+
const data = await resp.json();
|
|
95
|
+
const responseBody = JSON.stringify(data);
|
|
96
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
97
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
98
|
+
const result = data.result || {};
|
|
99
|
+
return [{ resultCode: data.code ?? '', resultMsg: data.msg || '', messageList: JSON.stringify(result.messageList || []), code: data.code ?? '', msg: data.msg || '' }];
|
|
100
|
+
},
|
|
101
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { cli, Strategy } from './xbb-registry.js';
|
|
6
|
+
|
|
7
|
+
const CONFIG_FILE = path.join(os.homedir(), '.opencli', 'xbb', 'config.env');
|
|
8
|
+
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workOrderV2/asset/addMinUser';
|
|
9
|
+
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
10
|
+
const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
|
|
11
|
+
|
|
12
|
+
function readConfig() {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
15
|
+
} catch {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getRuntimeConfig() {
|
|
21
|
+
const config = readConfig();
|
|
22
|
+
return {
|
|
23
|
+
corpid: String(config.corpid || '').trim(),
|
|
24
|
+
token: String(config.token || '').trim(),
|
|
25
|
+
baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
|
|
26
|
+
userId: String(config.userId || '').trim(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function buildApiUrl(baseUrl, apiUrl) {
|
|
31
|
+
const apiPath = new URL(apiUrl).pathname;
|
|
32
|
+
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseJsonArray(raw) {
|
|
36
|
+
const text = String(raw || '').trim();
|
|
37
|
+
if (!text) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const parsed = JSON.parse(text);
|
|
42
|
+
return Array.isArray(parsed) ? parsed : undefined;
|
|
43
|
+
} catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function makeErrorRow(code, msg) {
|
|
49
|
+
return [{ resultCode: '', resultMsg: '', messageList: '', code, msg }];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
cli({
|
|
53
|
+
site: 'xbb',
|
|
54
|
+
name: 'work-order-asset-add-mainuser',
|
|
55
|
+
description: '资产添加负责人接口(businessType: -1;workOrderV2 资产)',
|
|
56
|
+
strategy: Strategy.PUBLIC,
|
|
57
|
+
access: 'write',
|
|
58
|
+
browser: false,
|
|
59
|
+
domain: 'proapi.xbongbong.com',
|
|
60
|
+
args: [
|
|
61
|
+
{ name: 'formId', type: 'int', help: '表单id(必填)' },
|
|
62
|
+
{ name: 'dataId', type: 'int', help: '资产id(必填)' },
|
|
63
|
+
{ name: 'businessUserIdList', type: 'str', help: '负责人id列表,JSON数组字符串(必填)' },
|
|
64
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
65
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
66
|
+
],
|
|
67
|
+
columns: ['resultCode', 'resultMsg', 'messageList', 'code', 'msg'],
|
|
68
|
+
func: async function (kwargs) {
|
|
69
|
+
const debug = Boolean(kwargs.debug);
|
|
70
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
71
|
+
const runtimeUserId = String(kwargs.userId || userId || '').trim();
|
|
72
|
+
const payload = { corpid };
|
|
73
|
+
payload.formId = Number(kwargs.formId || 0);
|
|
74
|
+
payload.dataId = Number(kwargs.dataId || 0);
|
|
75
|
+
const parsedBusinessUserIdList = parseJsonArray(kwargs.businessUserIdList);
|
|
76
|
+
if (Array.isArray(parsedBusinessUserIdList)) payload.businessUserIdList = parsedBusinessUserIdList;
|
|
77
|
+
if (runtimeUserId) payload.userId = runtimeUserId;
|
|
78
|
+
const requestBody = JSON.stringify(payload);
|
|
79
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
80
|
+
if (!payload.formId) return makeErrorRow('NO_FORMID', '缺少 --formId');
|
|
81
|
+
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
82
|
+
if (parsedBusinessUserIdList === null) return makeErrorRow('NO_BUSINESSUSERIDLIST', '缺少 --businessUserIdList');
|
|
83
|
+
if (parsedBusinessUserIdList === undefined) return makeErrorRow('INVALID_BUSINESSUSERIDLIST', '--businessUserIdList 必须是 JSON 数组字符串');
|
|
84
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
85
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
86
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
|
|
87
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
88
|
+
if (debug) {
|
|
89
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
90
|
+
}
|
|
91
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
|
|
92
|
+
if (!resp.ok) {
|
|
93
|
+
const responseText = await resp.text();
|
|
94
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
95
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
96
|
+
}
|
|
97
|
+
const data = await resp.json();
|
|
98
|
+
const responseBody = JSON.stringify(data);
|
|
99
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
100
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
101
|
+
const result = data.result || {};
|
|
102
|
+
return [{ resultCode: data.code ?? '', resultMsg: data.msg || '', messageList: JSON.stringify(result.messageList || []), code: data.code ?? '', msg: data.msg || '' }];
|
|
103
|
+
},
|
|
104
|
+
});
|