@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/work-task-add.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
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/workTask/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 parseJsonLikeObject(text) {
|
|
36
|
+
let index = 0;
|
|
37
|
+
|
|
38
|
+
function skipWhitespace() {
|
|
39
|
+
while (index < text.length && /\s/.test(text[index])) index += 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function consume(char) {
|
|
43
|
+
skipWhitespace();
|
|
44
|
+
if (text[index] !== char) throw new Error('Invalid input');
|
|
45
|
+
index += 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function parseQuotedString(quote) {
|
|
49
|
+
let value = '';
|
|
50
|
+
index += 1;
|
|
51
|
+
while (index < text.length) {
|
|
52
|
+
const char = text[index];
|
|
53
|
+
if (char === '\\') {
|
|
54
|
+
const next = text[index + 1];
|
|
55
|
+
if (next === undefined) throw new Error('Invalid input');
|
|
56
|
+
value += next === quote || next === '\\' ? next : char + next;
|
|
57
|
+
index += 2;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (char === quote) {
|
|
61
|
+
index += 1;
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
value += char;
|
|
65
|
+
index += 1;
|
|
66
|
+
}
|
|
67
|
+
throw new Error('Invalid input');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parseBareValue(stopChars) {
|
|
71
|
+
const start = index;
|
|
72
|
+
while (index < text.length && !stopChars.includes(text[index])) index += 1;
|
|
73
|
+
const raw = text.slice(start, index).trim();
|
|
74
|
+
if (!raw) throw new Error('Invalid input');
|
|
75
|
+
if (raw === 'true') return true;
|
|
76
|
+
if (raw === 'false') return false;
|
|
77
|
+
if (raw === 'null') return null;
|
|
78
|
+
if (/^-?(?:\d+|\d*\.\d+)(?:[eE][+-]?\d+)?$/.test(raw)) return Number(raw);
|
|
79
|
+
return raw;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function parseValue(stopChars) {
|
|
83
|
+
skipWhitespace();
|
|
84
|
+
const char = text[index];
|
|
85
|
+
if (char === '{') return parseObject();
|
|
86
|
+
if (char === '[') return parseArray();
|
|
87
|
+
if (char === '"' || char === "'") return parseQuotedString(char);
|
|
88
|
+
return parseBareValue(stopChars);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function parseObject() {
|
|
92
|
+
const value = {};
|
|
93
|
+
consume('{');
|
|
94
|
+
skipWhitespace();
|
|
95
|
+
if (text[index] === '}') {
|
|
96
|
+
index += 1;
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
while (index < text.length) {
|
|
100
|
+
skipWhitespace();
|
|
101
|
+
let key;
|
|
102
|
+
if (text[index] === '"' || text[index] === "'") {
|
|
103
|
+
key = parseQuotedString(text[index]);
|
|
104
|
+
} else {
|
|
105
|
+
const keyStart = index;
|
|
106
|
+
while (index < text.length && ![':', ',', '}'].includes(text[index])) index += 1;
|
|
107
|
+
key = text.slice(keyStart, index).trim();
|
|
108
|
+
}
|
|
109
|
+
if (!key) throw new Error('Invalid input');
|
|
110
|
+
consume(':');
|
|
111
|
+
value[key] = parseValue(',}');
|
|
112
|
+
skipWhitespace();
|
|
113
|
+
if (text[index] === ',') {
|
|
114
|
+
index += 1;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
consume('}');
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
throw new Error('Invalid input');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function parseArray() {
|
|
124
|
+
const value = [];
|
|
125
|
+
consume('[');
|
|
126
|
+
skipWhitespace();
|
|
127
|
+
if (text[index] === ']') {
|
|
128
|
+
index += 1;
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
while (index < text.length) {
|
|
132
|
+
value.push(parseValue(',]'));
|
|
133
|
+
skipWhitespace();
|
|
134
|
+
if (text[index] === ',') {
|
|
135
|
+
index += 1;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
consume(']');
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
throw new Error('Invalid input');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const parsed = parseValue('');
|
|
145
|
+
skipWhitespace();
|
|
146
|
+
if (index !== text.length) throw new Error('Invalid input');
|
|
147
|
+
return parsed;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function parseDataList(raw) {
|
|
151
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
152
|
+
return raw;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const text = String(raw || '').trim();
|
|
156
|
+
if (!text) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const candidates = [text];
|
|
161
|
+
if (text.includes('\\"')) candidates.push(text.replaceAll('\\"', '"'));
|
|
162
|
+
for (const candidate of candidates) {
|
|
163
|
+
try {
|
|
164
|
+
const parsed = JSON.parse(candidate);
|
|
165
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
166
|
+
return parsed;
|
|
167
|
+
}
|
|
168
|
+
} catch {
|
|
169
|
+
// Try the repaired JSON and JSON-like fallbacks below.
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
const parsed = parseJsonLikeObject(text);
|
|
175
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : undefined;
|
|
176
|
+
} catch {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function buildPayload(kwargs, parsedDataList, corpid, defaultUserId) {
|
|
182
|
+
const payload = { corpid };
|
|
183
|
+
const userId = String(kwargs.userId || defaultUserId || '').trim();
|
|
184
|
+
if (userId) payload.userId = userId;
|
|
185
|
+
if (parsedDataList) payload.dataList = parsedDataList;
|
|
186
|
+
return payload;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function getValidationError(payload, token, parsedDataList) {
|
|
190
|
+
if (!payload.corpid) return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
|
|
191
|
+
if (!token) return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
|
|
192
|
+
if (parsedDataList === null) return { code: 'NO_DATALIST', msg: '缺少 --dataList' };
|
|
193
|
+
if (parsedDataList === undefined) return { code: 'INVALID_DATALIST', msg: '--dataList 解析失败;需传 JSON 对象字符串。PowerShell 示例:opencli.cmd --% xbb work-task-add --dataList "{\\"text_1\\":\\"name1\\"}"' };
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function makeErrorRow(code, msg) {
|
|
198
|
+
return [{ dataId: '', resultCode: '', resultMsg: '', code, msg }];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function makeSuccessRow(data) {
|
|
202
|
+
const result = data.result || {};
|
|
203
|
+
return [{ dataId: result.dataId || '', resultCode: result.code ?? '', resultMsg: result.msg || '', code: data.code ?? '', msg: data.msg || '' }];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
cli({
|
|
207
|
+
site: 'xbb',
|
|
208
|
+
name: 'work-task-add',
|
|
209
|
+
description: '新增任务接口(businessType: 21500),{ "text_1": "{任务名称}", "ownerId": [ "{执行人userId}" ],"date_1":1788969600 ,"date_2":1789833600 ,"text_3":"{任务描述}"}',
|
|
210
|
+
strategy: Strategy.PUBLIC,
|
|
211
|
+
access: 'write',
|
|
212
|
+
browser: false,
|
|
213
|
+
domain: 'proapi.xbongbong.com',
|
|
214
|
+
args: [
|
|
215
|
+
{ name: 'dataList', type: 'str', help: '任务数据JSON字符串(必填)' },
|
|
216
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
217
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
218
|
+
],
|
|
219
|
+
columns: ['dataId', 'resultCode', 'resultMsg', 'code', 'msg'],
|
|
220
|
+
func: async function (kwargs) {
|
|
221
|
+
const debug = Boolean(kwargs.debug);
|
|
222
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
223
|
+
const parsedDataList = parseDataList(kwargs.dataList);
|
|
224
|
+
const payload = buildPayload(kwargs, parsedDataList, corpid, userId);
|
|
225
|
+
const requestBody = JSON.stringify(payload);
|
|
226
|
+
const validationError = getValidationError(payload, token, parsedDataList);
|
|
227
|
+
if (validationError) return makeErrorRow(validationError.code, validationError.msg);
|
|
228
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
229
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, userId ? { userId } : {});
|
|
230
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
231
|
+
if (debug) {
|
|
232
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
233
|
+
}
|
|
234
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
|
|
235
|
+
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
236
|
+
const data = await resp.json();
|
|
237
|
+
const responseBody = JSON.stringify(data);
|
|
238
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
239
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
240
|
+
return makeSuccessRow(data);
|
|
241
|
+
},
|
|
242
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
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_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
|
|
8
|
+
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workTask/deleteCoUser';
|
|
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, defaultUrl) {
|
|
31
|
+
const apiPath = new URL(defaultUrl).pathname;
|
|
32
|
+
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function makeErrorRow(code, msg) {
|
|
36
|
+
return [{ resultCode: '', resultMsg: '', code, msg }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cli({
|
|
40
|
+
site: 'xbb',
|
|
41
|
+
name: 'work-task-delete-couser',
|
|
42
|
+
description: '工作任务删除协同人接口(businessType: 21500)',
|
|
43
|
+
strategy: Strategy.PUBLIC,
|
|
44
|
+
access: 'write',
|
|
45
|
+
browser: false,
|
|
46
|
+
domain: 'proapi.xbongbong.com',
|
|
47
|
+
args: [
|
|
48
|
+
{ name: 'dataId', type: 'int', help: '任务id(必填)' },
|
|
49
|
+
{ name: 'businessUserIdList', type: 'str', help: '需删除的协同人id列表,JSON数组字符串(必填)' },
|
|
50
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
51
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
52
|
+
],
|
|
53
|
+
columns: ['resultCode', 'resultMsg', 'code', 'msg'],
|
|
54
|
+
func: async (kwargs) => {
|
|
55
|
+
const debug = Boolean(kwargs.debug);
|
|
56
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
57
|
+
const payload = { corpid, dataId: Number(kwargs.dataId || 0) };
|
|
58
|
+
if (kwargs.userId) payload.userId = String(kwargs.userId);
|
|
59
|
+
let userIdList;
|
|
60
|
+
try {
|
|
61
|
+
userIdList = JSON.parse(String(kwargs.businessUserIdList || ''));
|
|
62
|
+
} catch {
|
|
63
|
+
userIdList = null;
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(userIdList)) payload.businessUserIdList = userIdList;
|
|
66
|
+
const body = JSON.stringify(payload);
|
|
67
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
68
|
+
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
69
|
+
if (!Array.isArray(userIdList) || !userIdList.length) return makeErrorRow('NO_USERIDLIST', '缺少 --businessUserIdList 或格式不正确,需为JSON数组');
|
|
70
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
71
|
+
const sign = crypto.createHash('sha256').update(body + token).digest('hex');
|
|
72
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, userId ? { userId } : {});
|
|
73
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
74
|
+
if (debug) {
|
|
75
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
76
|
+
}
|
|
77
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body });
|
|
78
|
+
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
79
|
+
const data = await resp.json();
|
|
80
|
+
const responseBody = JSON.stringify(data);
|
|
81
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
82
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
83
|
+
return [{ resultCode: data.code ?? '', resultMsg: data.msg || '', code: data.code ?? '', msg: data.msg || '' }];
|
|
84
|
+
},
|
|
85
|
+
});
|
|
@@ -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(), '.xbbcli', 'config.env');
|
|
8
|
+
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workTask/detail';
|
|
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 [{ dataId: '', taskName: '', taskStartTime: '', taskEndTime: '', remark: '', code, msg }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function formatTimestampSeconds(value) {
|
|
40
|
+
const timestamp = Number(value);
|
|
41
|
+
if (value === null || value === undefined || value === '' || !Number.isFinite(timestamp) || timestamp <= 0) {
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const parts = new Intl.DateTimeFormat('zh-CN', {
|
|
46
|
+
timeZone: 'Asia/Shanghai',
|
|
47
|
+
year: 'numeric',
|
|
48
|
+
month: '2-digit',
|
|
49
|
+
day: '2-digit',
|
|
50
|
+
hour: '2-digit',
|
|
51
|
+
minute: '2-digit',
|
|
52
|
+
second: '2-digit',
|
|
53
|
+
hour12: false,
|
|
54
|
+
}).formatToParts(new Date(timestamp * 1000)).reduce((acc, part) => {
|
|
55
|
+
if (part.type !== 'literal') acc[part.type] = part.value;
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
|
|
59
|
+
return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}:${parts.second}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
cli({
|
|
63
|
+
site: 'xbb',
|
|
64
|
+
name: 'work-task-detail',
|
|
65
|
+
description: '工作任务详情接口(businessType: 21500)',
|
|
66
|
+
strategy: Strategy.PUBLIC,
|
|
67
|
+
access: 'read',
|
|
68
|
+
browser: false,
|
|
69
|
+
domain: 'proapi.xbongbong.com',
|
|
70
|
+
args: [
|
|
71
|
+
{ name: 'dataId', type: 'int', help: '任务id(必填)' },
|
|
72
|
+
{ name: 'queryFlag', type: 'int', default: 0, help: '查询标记(可选)' },
|
|
73
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
74
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
75
|
+
],
|
|
76
|
+
columns: ['dataId', 'taskName', 'taskStartTime', 'taskEndTime', 'remark', 'code', 'msg'],
|
|
77
|
+
func: async (kwargs) => {
|
|
78
|
+
const debug = Boolean(kwargs.debug);
|
|
79
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
80
|
+
const payload = { corpid, dataId: Number(kwargs.dataId || 0) };
|
|
81
|
+
if (kwargs.userId) payload.userId = String(kwargs.userId);
|
|
82
|
+
if (String(kwargs.queryFlag ?? '') !== '') payload.queryFlag = Number(kwargs.queryFlag);
|
|
83
|
+
const requestBody = JSON.stringify(payload);
|
|
84
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
85
|
+
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
86
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
87
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
88
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, userId ? { userId } : {});
|
|
89
|
+
if (debug) {
|
|
90
|
+
process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
91
|
+
}
|
|
92
|
+
const resp = await fetch(buildApiUrl(baseUrl, API_URL), { method: 'POST', headers, body: requestBody });
|
|
93
|
+
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
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 [{ dataId: result.dataId || '', taskName: result.data?.text_1 || '', taskStartTime: formatTimestampSeconds(result.data?.date_1), taskEndTime: formatTimestampSeconds(result.data?.date_2), remark: result.data?.text_3?.taskMemoText || '', code: data.code ?? '', msg: data.msg || '' }];
|
|
100
|
+
},
|
|
101
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
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/workTask/edit';
|
|
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
|
+
const text = String(raw || '').trim();
|
|
40
|
+
if (!text) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const parsed = JSON.parse(text);
|
|
45
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
} catch {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function buildPayload(kwargs, parsedDataList, corpid, defaultUserId) {
|
|
55
|
+
const payload = { corpid, dataId: Number(kwargs.dataId || 0) };
|
|
56
|
+
const userId = String(kwargs.userId || defaultUserId || '').trim();
|
|
57
|
+
if (userId) payload.userId = userId;
|
|
58
|
+
if (parsedDataList) payload.dataList = parsedDataList;
|
|
59
|
+
return payload;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getValidationError(payload, token, parsedDataList) {
|
|
63
|
+
if (!payload.corpid) return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
|
|
64
|
+
if (!payload.dataId) return { code: 'NO_DATAID', msg: '缺少 --dataId' };
|
|
65
|
+
if (!token) return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
|
|
66
|
+
if (parsedDataList === null) return { code: 'NO_DATALIST', msg: '缺少 --dataList' };
|
|
67
|
+
if (parsedDataList === undefined) return { code: 'INVALID_DATALIST', msg: '--dataList 必须是 JSON 对象字符串' };
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function makeErrorRow(code, msg) {
|
|
72
|
+
return [{ dataId: '', resultCode: '', resultMsg: '', code, msg }];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function makeSuccessRow(data) {
|
|
76
|
+
const result = data.result || {};
|
|
77
|
+
return [{ dataId: result.dataId || '', resultCode: result.code ?? '', resultMsg: result.msg || '', code: data.code ?? '', msg: data.msg || '' }];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
cli({
|
|
81
|
+
site: 'xbb',
|
|
82
|
+
name: 'work-task-edit',
|
|
83
|
+
description: '编辑工作任务接口(businessType: 21500)',
|
|
84
|
+
strategy: Strategy.PUBLIC,
|
|
85
|
+
access: 'write',
|
|
86
|
+
browser: false,
|
|
87
|
+
domain: 'proapi.xbongbong.com',
|
|
88
|
+
args: [
|
|
89
|
+
{ name: 'dataId', type: 'int', help: '任务id(必填)' },
|
|
90
|
+
{ name: 'dataList', type: 'str', help: '任务数据JSON字符串(必填)' },
|
|
91
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
92
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
93
|
+
],
|
|
94
|
+
columns: ['dataId', 'resultCode', 'resultMsg', 'code', 'msg'],
|
|
95
|
+
func: async function (kwargs) {
|
|
96
|
+
const debug = Boolean(kwargs.debug);
|
|
97
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
98
|
+
const parsedDataList = parseDataList(kwargs.dataList);
|
|
99
|
+
const payload = buildPayload(kwargs, parsedDataList, corpid, userId);
|
|
100
|
+
const requestBody = JSON.stringify(payload);
|
|
101
|
+
const validationError = getValidationError(payload, token, parsedDataList);
|
|
102
|
+
if (validationError) return makeErrorRow(validationError.code, validationError.msg);
|
|
103
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
104
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, userId ? { userId } : {});
|
|
105
|
+
if (debug) {
|
|
106
|
+
process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
107
|
+
}
|
|
108
|
+
const resp = await fetch(buildApiUrl(baseUrl, API_URL), { method: 'POST', headers, body: requestBody });
|
|
109
|
+
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
110
|
+
const data = await resp.json();
|
|
111
|
+
const responseBody = JSON.stringify(data);
|
|
112
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
113
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
114
|
+
return makeSuccessRow(data);
|
|
115
|
+
},
|
|
116
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
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_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
|
|
8
|
+
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workTask/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, defaultUrl) {
|
|
31
|
+
const apiPath = new URL(defaultUrl).pathname;
|
|
32
|
+
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function makeErrorRow(code, msg) {
|
|
36
|
+
return [{ resultType: '', resultMsg: '', code, msg }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cli({
|
|
40
|
+
site: 'xbb',
|
|
41
|
+
name: 'work-task-handover',
|
|
42
|
+
description: '工作任务移交接口(businessType: 21500)',
|
|
43
|
+
strategy: Strategy.PUBLIC,
|
|
44
|
+
access: 'write',
|
|
45
|
+
browser: false,
|
|
46
|
+
domain: 'proapi.xbongbong.com',
|
|
47
|
+
args: [
|
|
48
|
+
{ name: 'dataIdList', type: 'str', help: '任务id列表,JSON数组字符串(必填)' },
|
|
49
|
+
{ name: 'businessUserId', type: 'str', help: '移交目标人员id(必填)' },
|
|
50
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
51
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
52
|
+
],
|
|
53
|
+
columns: ['resultType', 'resultMsg', 'code', 'msg'],
|
|
54
|
+
func: async (kwargs) => {
|
|
55
|
+
const debug = Boolean(kwargs.debug);
|
|
56
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
57
|
+
const payload = { corpid, businessUserId: String(kwargs.businessUserId || '') };
|
|
58
|
+
if (kwargs.userId) payload.userId = String(kwargs.userId);
|
|
59
|
+
let dataIdList;
|
|
60
|
+
try {
|
|
61
|
+
dataIdList = JSON.parse(String(kwargs.dataIdList || ''));
|
|
62
|
+
} catch {
|
|
63
|
+
dataIdList = null;
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(dataIdList)) payload.dataIdList = dataIdList;
|
|
66
|
+
const body = JSON.stringify(payload);
|
|
67
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
68
|
+
if (!Array.isArray(dataIdList) || !dataIdList.length) return makeErrorRow('NO_DATAIDLIST', '缺少 --dataIdList 或格式不正确,需为JSON数组');
|
|
69
|
+
if (!payload.businessUserId) return makeErrorRow('NO_BUSINESSUSERID', '缺少 --businessUserId');
|
|
70
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
71
|
+
const sign = crypto.createHash('sha256').update(body + token).digest('hex');
|
|
72
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, userId ? { userId } : {});
|
|
73
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
74
|
+
if (debug) {
|
|
75
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
76
|
+
}
|
|
77
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body });
|
|
78
|
+
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
79
|
+
const data = await resp.json();
|
|
80
|
+
const responseBody = JSON.stringify(data);
|
|
81
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
82
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
83
|
+
return [{ resultType: data.result?.resultType || '', resultMsg: data.result?.resultMsg || '', code: data.code ?? '', msg: data.msg || '' }];
|
|
84
|
+
},
|
|
85
|
+
});
|