@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
|
@@ -0,0 +1,84 @@
|
|
|
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/paas/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: 'form-data-handover',
|
|
42
|
+
description: '自定义表单移交接口(businessType: 0)',
|
|
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
|
+
if (debug) {
|
|
74
|
+
process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
75
|
+
}
|
|
76
|
+
const resp = await fetch(buildApiUrl(baseUrl, API_URL), { method: 'POST', headers, body });
|
|
77
|
+
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
78
|
+
const data = await resp.json();
|
|
79
|
+
const responseBody = JSON.stringify(data);
|
|
80
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
81
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
82
|
+
return [{ resultType: data.result?.resultType || '', resultMsg: data.result?.resultMsg || '', code: data.code ?? '', msg: data.msg || '' }];
|
|
83
|
+
},
|
|
84
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
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 FORM_DATA_LIST_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/paas/list';
|
|
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
|
+
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, apiUrl) {
|
|
32
|
+
const apiPath = new URL(apiUrl).pathname;
|
|
33
|
+
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function buildConditions(kwargs) {
|
|
37
|
+
if (!(kwargs.attr && kwargs.value)) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return [{
|
|
42
|
+
attr: String(kwargs.attr),
|
|
43
|
+
value: [String(kwargs.value)],
|
|
44
|
+
symbol: String(kwargs.symbol || 'equal'),
|
|
45
|
+
}];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function buildPayload(kwargs, corpid, defaultUserId) {
|
|
49
|
+
const payload = {
|
|
50
|
+
corpid,
|
|
51
|
+
formId: Number(kwargs.formId || 0),
|
|
52
|
+
...(String(kwargs.page ?? '') !== '' ? { page: Number(kwargs.page) } : {}),
|
|
53
|
+
...(String(kwargs.pageSize ?? '') !== '' ? { pageSize: Number(kwargs.pageSize) } : {}),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const userId = String(kwargs.userId || defaultUserId || '');
|
|
57
|
+
if (userId) {
|
|
58
|
+
payload.userId = userId;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const viewApproval = String(kwargs.viewApproval ?? '');
|
|
62
|
+
if (viewApproval !== '') {
|
|
63
|
+
payload.viewApproval = viewApproval;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const conditions = buildConditions(kwargs);
|
|
67
|
+
if (conditions.length) {
|
|
68
|
+
payload.conditions = conditions;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return payload;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getValidationError(payload, token) {
|
|
75
|
+
if (!payload.corpid) {
|
|
76
|
+
return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
|
|
77
|
+
}
|
|
78
|
+
if (!payload.formId) {
|
|
79
|
+
return { code: 'NO_FORMID', msg: '缺少 --formId' };
|
|
80
|
+
}
|
|
81
|
+
if (!token) {
|
|
82
|
+
return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function makeErrorRow(code, msg) {
|
|
89
|
+
return [{
|
|
90
|
+
rank: '',
|
|
91
|
+
dataId: '',
|
|
92
|
+
formId: '',
|
|
93
|
+
addTime: '',
|
|
94
|
+
updateTime: '',
|
|
95
|
+
data: '',
|
|
96
|
+
code,
|
|
97
|
+
msg,
|
|
98
|
+
}];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function makeSuccessRows(list) {
|
|
102
|
+
return list.map((item, index) => ({
|
|
103
|
+
rank: index + 1,
|
|
104
|
+
dataId: item.dataId || '',
|
|
105
|
+
formId: item.formId || '',
|
|
106
|
+
addTime: item.addTime || '',
|
|
107
|
+
updateTime: item.updateTime || '',
|
|
108
|
+
data: JSON.stringify(item.data || {}),
|
|
109
|
+
code: '',
|
|
110
|
+
msg: '',
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
cli({
|
|
115
|
+
site: 'xbb',
|
|
116
|
+
name: 'form-data-list',
|
|
117
|
+
description: '自定义表单数据列表接口(businessType: 0;formId必填)',
|
|
118
|
+
strategy: Strategy.PUBLIC,
|
|
119
|
+
access: 'read',
|
|
120
|
+
browser: false,
|
|
121
|
+
domain: 'proapi.xbongbong.com',
|
|
122
|
+
args: [
|
|
123
|
+
{ name: 'formId', type: 'int', help: '表单id(必填)' },
|
|
124
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
125
|
+
{ name: 'viewApproval', type: 'str', default: '', help: '是否查询审批中数据,1是,0否' },
|
|
126
|
+
{ name: 'attr', type: 'str', default: '', help: '筛选字段 attr,例如 text_1' },
|
|
127
|
+
{ name: 'value', type: 'str', default: '', help: '筛选值,和 --attr 配合使用' },
|
|
128
|
+
{ name: 'symbol', type: 'str', default: 'equal', help: '筛选操作符,默认 equal' },
|
|
129
|
+
{ name: 'page', type: 'str', default: '', help: '页码(可选)' },
|
|
130
|
+
{ name: 'pageSize', type: 'str', default: '', help: '每页数量(可选)' },
|
|
131
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
132
|
+
{ name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
|
|
133
|
+
],
|
|
134
|
+
columns: ['rank', 'dataId', 'formId', 'addTime', 'updateTime', 'data', 'code', 'msg'],
|
|
135
|
+
footerExtra: () => (lastPagination ? `totalCount ${lastPagination.totalCount} / totalPage ${lastPagination.totalPage}` : undefined),
|
|
136
|
+
func: async function (kwargs) {
|
|
137
|
+
const debug = Boolean(kwargs.debug);
|
|
138
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
139
|
+
const payload = buildPayload(kwargs, corpid, userId);
|
|
140
|
+
const requestBody = JSON.stringify(payload);
|
|
141
|
+
|
|
142
|
+
const validationError = getValidationError(payload, token);
|
|
143
|
+
if (validationError) {
|
|
144
|
+
return makeErrorRow(validationError.code, validationError.msg);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const apiUrl = buildApiUrl(baseUrl, FORM_DATA_LIST_API_URL);
|
|
148
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
149
|
+
const headers = Object.assign({
|
|
150
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
151
|
+
sign,
|
|
152
|
+
}, userId ? { userId } : {});
|
|
153
|
+
|
|
154
|
+
if (debug) {
|
|
155
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const resp = await fetch(apiUrl, {
|
|
159
|
+
method: 'POST',
|
|
160
|
+
headers,
|
|
161
|
+
body: requestBody,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
if (!resp.ok) {
|
|
165
|
+
const responseText = await resp.text();
|
|
166
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
167
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const data = await resp.json();
|
|
171
|
+
lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
|
|
172
|
+
? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
|
|
173
|
+
: null;
|
|
174
|
+
const responseBody = JSON.stringify(data);
|
|
175
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
176
|
+
if (kwargs.raw) return [{ raw: responseBody }];
|
|
177
|
+
if (data.code !== 1) {
|
|
178
|
+
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const list = Array.isArray(data.result?.list) ? data.result.list : [];
|
|
182
|
+
if (!list.length) {
|
|
183
|
+
return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return makeSuccessRows(list);
|
|
187
|
+
},
|
|
188
|
+
});
|
package/form-get.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
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 FORM_GET_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/form/get';
|
|
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 buildPayload(kwargs, corpid) {
|
|
36
|
+
const payload = {
|
|
37
|
+
formId: Number(kwargs.formId || 0),
|
|
38
|
+
corpid,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if (kwargs.userId) {
|
|
42
|
+
payload.userId = String(kwargs.userId);
|
|
43
|
+
}
|
|
44
|
+
if (String(kwargs.subBusinessType ?? '') !== '') {
|
|
45
|
+
payload.subBusinessType = Number(kwargs.subBusinessType);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return payload;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getValidationError(payload, token) {
|
|
52
|
+
if (!payload.formId) {
|
|
53
|
+
return { code: 'NO_FORMID', msg: '缺少 --formId' };
|
|
54
|
+
}
|
|
55
|
+
if (!payload.corpid) {
|
|
56
|
+
return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
|
|
57
|
+
}
|
|
58
|
+
if (!token) {
|
|
59
|
+
return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function makeErrorRow(code, msg) {
|
|
66
|
+
return [{
|
|
67
|
+
rank: '',
|
|
68
|
+
attr: '',
|
|
69
|
+
attrName: '',
|
|
70
|
+
fieldType: '',
|
|
71
|
+
required: '',
|
|
72
|
+
noRepeat: '',
|
|
73
|
+
showType: '',
|
|
74
|
+
dateType: '',
|
|
75
|
+
items: '',
|
|
76
|
+
code,
|
|
77
|
+
msg,
|
|
78
|
+
}];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function makeSuccessRows(explainList) {
|
|
82
|
+
return explainList.map((item, index) => ({
|
|
83
|
+
rank: index + 1,
|
|
84
|
+
attr: item.attr || '',
|
|
85
|
+
attrName: item.attrName || '',
|
|
86
|
+
fieldType: item.fieldType ?? '',
|
|
87
|
+
required: item.required ?? '',
|
|
88
|
+
noRepeat: item.noRepeat ?? '',
|
|
89
|
+
showType: item.showType ?? '',
|
|
90
|
+
dateType: item.dateType || '',
|
|
91
|
+
items: JSON.stringify(item.items || []),
|
|
92
|
+
code: '',
|
|
93
|
+
msg: '',
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
cli({
|
|
98
|
+
site: 'xbb',
|
|
99
|
+
name: 'form-get',
|
|
100
|
+
description: '表单模板字段解释接口(businessType: -1;formId必填)',
|
|
101
|
+
strategy: Strategy.PUBLIC,
|
|
102
|
+
access: 'read',
|
|
103
|
+
browser: false,
|
|
104
|
+
domain: 'proapi.xbongbong.com',
|
|
105
|
+
args: [
|
|
106
|
+
{ name: 'formId', type: 'int', help: '表单id(必填)' },
|
|
107
|
+
{ name: 'subBusinessType', type: 'str', default: '', help: '表单业务子类型(可选)' },
|
|
108
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
109
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
110
|
+
],
|
|
111
|
+
columns: ['rank', 'attr', 'attrName', 'fieldType', 'required', 'noRepeat', 'showType', 'dateType', 'items', 'code', 'msg'],
|
|
112
|
+
func: async function (kwargs) {
|
|
113
|
+
const debug = Boolean(kwargs.debug);
|
|
114
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
115
|
+
const payload = buildPayload(kwargs, corpid);
|
|
116
|
+
const body = JSON.stringify(payload);
|
|
117
|
+
|
|
118
|
+
const validationError = getValidationError(payload, token);
|
|
119
|
+
if (validationError) {
|
|
120
|
+
return makeErrorRow(validationError.code, validationError.msg);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const sign = crypto.createHash('sha256').update(body + token).digest('hex');
|
|
124
|
+
const headers = Object.assign({
|
|
125
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
126
|
+
sign,
|
|
127
|
+
}, userId ? { userId } : {});
|
|
128
|
+
if (debug) {
|
|
129
|
+
process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, FORM_GET_API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
130
|
+
}
|
|
131
|
+
const resp = await fetch(buildApiUrl(baseUrl, FORM_GET_API_URL), {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
headers,
|
|
134
|
+
body,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (!resp.ok) {
|
|
138
|
+
const responseText = await resp.text();
|
|
139
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
140
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const data = await resp.json();
|
|
144
|
+
const responseBody = JSON.stringify(data);
|
|
145
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
146
|
+
if (data.code !== 1) {
|
|
147
|
+
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const explainList = Array.isArray(data.result?.explainList) ? data.result.explainList : [];
|
|
151
|
+
if (!explainList.length) {
|
|
152
|
+
return makeErrorRow('NO_DATA', '接口成功,但 explainList 为空');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return makeSuccessRows(explainList);
|
|
156
|
+
},
|
|
157
|
+
});
|
package/form-list.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
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 FORM_LIST_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/form/list';
|
|
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
|
+
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, defaultUrl) {
|
|
32
|
+
const apiPath = new URL(defaultUrl).pathname;
|
|
33
|
+
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function hasCliArg(name) {
|
|
37
|
+
const flag = `--${name}`;
|
|
38
|
+
return process.argv.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function buildPayload(kwargs, corpid) {
|
|
42
|
+
const payload = {
|
|
43
|
+
corpid,
|
|
44
|
+
saasMark: Number(kwargs.saasMark || 0),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (kwargs.userId) {
|
|
48
|
+
payload.userId = String(kwargs.userId);
|
|
49
|
+
}
|
|
50
|
+
if (kwargs.name) {
|
|
51
|
+
payload.name = String(kwargs.name);
|
|
52
|
+
}
|
|
53
|
+
if (hasCliArg('businessType')) {
|
|
54
|
+
payload.businessType = Number(kwargs.businessType);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return payload;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getValidationError(payload, token) {
|
|
61
|
+
if (!payload.corpid) {
|
|
62
|
+
return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
|
|
63
|
+
}
|
|
64
|
+
if (!payload.saasMark) {
|
|
65
|
+
return { code: 'NO_SAASMARK', msg: '缺少 --saasMark(1系统表单,2自定义表单)' };
|
|
66
|
+
}
|
|
67
|
+
if (!token) {
|
|
68
|
+
return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function makeErrorRow(code, msg) {
|
|
75
|
+
return [{
|
|
76
|
+
rank: '',
|
|
77
|
+
formId: '',
|
|
78
|
+
appId: '',
|
|
79
|
+
menuId: '',
|
|
80
|
+
businessType: '',
|
|
81
|
+
isProcessForm: '',
|
|
82
|
+
name: '',
|
|
83
|
+
code,
|
|
84
|
+
msg,
|
|
85
|
+
}];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function makeSuccessRows(list) {
|
|
89
|
+
return list.map((item, index) => ({
|
|
90
|
+
rank: index + 1,
|
|
91
|
+
formId: item.formId || '',
|
|
92
|
+
appId: item.appId || '',
|
|
93
|
+
menuId: item.menuId || '',
|
|
94
|
+
businessType: item.businessType || '',
|
|
95
|
+
isProcessForm: item.isProcessForm || '',
|
|
96
|
+
name: item.name || '',
|
|
97
|
+
code: '',
|
|
98
|
+
msg: '',
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
cli({
|
|
103
|
+
site: 'xbb',
|
|
104
|
+
name: 'form-list',
|
|
105
|
+
description: '表单模板列表接口(businessType: -1)',
|
|
106
|
+
strategy: Strategy.PUBLIC,
|
|
107
|
+
access: 'read',
|
|
108
|
+
browser: false,
|
|
109
|
+
domain: 'proapi.xbongbong.com',
|
|
110
|
+
args: [
|
|
111
|
+
{ name: 'saasMark', type: 'int', help: '表单类型(必填):1系统表单,2自定义表单' },
|
|
112
|
+
{ name: 'businessType', type: 'int', default: '', help: '业务类型(可选)' },
|
|
113
|
+
{ name: 'name', type: 'str', default: '', help: '模板名称模糊查询(可选)' },
|
|
114
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
115
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
116
|
+
{ name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
|
|
117
|
+
],
|
|
118
|
+
columns: ['rank', 'formId', 'appId', 'menuId', 'businessType', 'isProcessForm', 'name', 'code', 'msg'],
|
|
119
|
+
footerExtra: () => (lastPagination ? `totalCount ${lastPagination.totalCount} / totalPage ${lastPagination.totalPage}` : undefined),
|
|
120
|
+
func: async function (kwargs) {
|
|
121
|
+
const debug = Boolean(kwargs.debug);
|
|
122
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
123
|
+
const payload = buildPayload(kwargs, corpid);
|
|
124
|
+
const body = JSON.stringify(payload);
|
|
125
|
+
|
|
126
|
+
const validationError = getValidationError(payload, token);
|
|
127
|
+
if (validationError) {
|
|
128
|
+
return makeErrorRow(validationError.code, validationError.msg);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const sign = crypto.createHash('sha256').update(body + token).digest('hex');
|
|
132
|
+
const headers = Object.assign({
|
|
133
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
134
|
+
sign,
|
|
135
|
+
}, userId ? { userId } : {});
|
|
136
|
+
if (debug) {
|
|
137
|
+
process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, FORM_LIST_API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
138
|
+
}
|
|
139
|
+
const resp = await fetch(buildApiUrl(baseUrl, FORM_LIST_API_URL), {
|
|
140
|
+
method: 'POST',
|
|
141
|
+
headers,
|
|
142
|
+
body,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (!resp.ok) {
|
|
146
|
+
const responseText = await resp.text();
|
|
147
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
148
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const data = await resp.json();
|
|
152
|
+
lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
|
|
153
|
+
? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
|
|
154
|
+
: null;
|
|
155
|
+
const responseBody = JSON.stringify(data);
|
|
156
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
157
|
+
if (kwargs.raw) return [{ raw: responseBody }];
|
|
158
|
+
if (data.code !== 1) {
|
|
159
|
+
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const formList = Array.isArray(data.result?.formList) ? data.result.formList : [];
|
|
163
|
+
if (!formList.length) {
|
|
164
|
+
return makeErrorRow('NO_DATA', '接口成功,但 formList 为空');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return makeSuccessRows(formList);
|
|
168
|
+
},
|
|
169
|
+
});
|