@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,88 @@
|
|
|
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/label/del/completely';
|
|
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 makeErrorRow(code, msg) {
|
|
36
|
+
return [{ code, msg }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cli({
|
|
40
|
+
site: 'xbb',
|
|
41
|
+
name: 'label-del-completely',
|
|
42
|
+
description: '彻底删除标签接口(businessType: -1;label 模块)',
|
|
43
|
+
strategy: Strategy.PUBLIC,
|
|
44
|
+
access: 'write',
|
|
45
|
+
browser: false,
|
|
46
|
+
domain: 'proapi.xbongbong.com',
|
|
47
|
+
args: [
|
|
48
|
+
{ name: 'businessType', type: 'int', help: '业务类型(必填)' },
|
|
49
|
+
{ name: 'formId', type: 'int', help: '表单id(必填)' },
|
|
50
|
+
{ name: 'dataId', type: 'int', help: '标签id,只支持单个删除(必填)' },
|
|
51
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
52
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
53
|
+
],
|
|
54
|
+
columns: ['code', 'msg'],
|
|
55
|
+
func: async function (kwargs) {
|
|
56
|
+
const debug = Boolean(kwargs.debug);
|
|
57
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
58
|
+
const runtimeUserId = String(kwargs.userId || userId || '').trim();
|
|
59
|
+
const payload = { corpid };
|
|
60
|
+
payload.businessType = Number(kwargs.businessType || 0);
|
|
61
|
+
payload.formId = Number(kwargs.formId || 0);
|
|
62
|
+
payload.dataId = Number(kwargs.dataId || 0);
|
|
63
|
+
if (runtimeUserId) payload.userId = runtimeUserId;
|
|
64
|
+
const requestBody = JSON.stringify(payload);
|
|
65
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
66
|
+
if (!payload.businessType) return makeErrorRow('NO_BUSINESSTYPE', '缺少 --businessType');
|
|
67
|
+
if (!payload.formId) return makeErrorRow('NO_FORMID', '缺少 --formId');
|
|
68
|
+
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
69
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
70
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
71
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
|
|
72
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
73
|
+
if (debug) {
|
|
74
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
75
|
+
}
|
|
76
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
|
|
77
|
+
if (!resp.ok) {
|
|
78
|
+
const responseText = await resp.text();
|
|
79
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
80
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
81
|
+
}
|
|
82
|
+
const data = await resp.json();
|
|
83
|
+
const responseBody = JSON.stringify(data);
|
|
84
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
85
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
86
|
+
return [{ code: data.code ?? '', msg: data.msg || '' }];
|
|
87
|
+
},
|
|
88
|
+
});
|
package/label-del.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
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/label/del';
|
|
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 [{ dataIdList: '', code, msg }];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
cli({
|
|
53
|
+
site: 'xbb',
|
|
54
|
+
name: 'label-del',
|
|
55
|
+
description: '删除标签接口(businessType: -1;移入回收站,label 模块)',
|
|
56
|
+
strategy: Strategy.PUBLIC,
|
|
57
|
+
access: 'write',
|
|
58
|
+
browser: false,
|
|
59
|
+
domain: 'proapi.xbongbong.com',
|
|
60
|
+
args: [
|
|
61
|
+
{ name: 'dataIdList', type: 'str', help: '标签id列表,JSON数组字符串(必填)' },
|
|
62
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
63
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
64
|
+
],
|
|
65
|
+
columns: ['dataIdList', 'code', 'msg'],
|
|
66
|
+
func: async function (kwargs) {
|
|
67
|
+
const debug = Boolean(kwargs.debug);
|
|
68
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
69
|
+
const runtimeUserId = String(kwargs.userId || userId || '').trim();
|
|
70
|
+
const payload = { corpid };
|
|
71
|
+
const parsedDataIdList = parseJsonArray(kwargs.dataIdList);
|
|
72
|
+
if (Array.isArray(parsedDataIdList)) payload.dataIdList = parsedDataIdList;
|
|
73
|
+
if (runtimeUserId) payload.userId = runtimeUserId;
|
|
74
|
+
const requestBody = JSON.stringify(payload);
|
|
75
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
76
|
+
if (parsedDataIdList === null) return makeErrorRow('NO_DATAIDLIST', '缺少 --dataIdList');
|
|
77
|
+
if (parsedDataIdList === undefined) return makeErrorRow('INVALID_DATAIDLIST', '--dataIdList 必须是 JSON 数组字符串');
|
|
78
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
79
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
80
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
|
|
81
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
82
|
+
if (debug) {
|
|
83
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
84
|
+
}
|
|
85
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
|
|
86
|
+
if (!resp.ok) {
|
|
87
|
+
const responseText = await resp.text();
|
|
88
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
89
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
90
|
+
}
|
|
91
|
+
const data = await resp.json();
|
|
92
|
+
const responseBody = JSON.stringify(data);
|
|
93
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
94
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
95
|
+
const result = data.result || {};
|
|
96
|
+
return [{ dataIdList: JSON.stringify(result.dataIdList || []), code: data.code ?? '', msg: data.msg || '' }];
|
|
97
|
+
},
|
|
98
|
+
});
|
package/label-edit.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
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/label/edit';
|
|
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 makeErrorRow(code, msg) {
|
|
36
|
+
return [{ code, msg }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cli({
|
|
40
|
+
site: 'xbb',
|
|
41
|
+
name: 'label-edit',
|
|
42
|
+
description: '编辑标签接口(businessType: -1;label 模块)',
|
|
43
|
+
strategy: Strategy.PUBLIC,
|
|
44
|
+
access: 'write',
|
|
45
|
+
browser: false,
|
|
46
|
+
domain: 'proapi.xbongbong.com',
|
|
47
|
+
args: [
|
|
48
|
+
{ name: 'businessType', type: 'int', help: '业务类型(必填)' },
|
|
49
|
+
{ name: 'formId', type: 'int', help: '表单id(必填)' },
|
|
50
|
+
{ name: 'groupId', type: 'int', help: '分组id(必填)' },
|
|
51
|
+
{ name: 'dataId', type: 'int', help: '标签id(必填)' },
|
|
52
|
+
{ name: 'color', type: 'str', help: '标签颜色(必填)' },
|
|
53
|
+
{ name: 'name', type: 'str', default: '', help: '标签名(可选)' },
|
|
54
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
55
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
56
|
+
],
|
|
57
|
+
columns: ['code', 'msg'],
|
|
58
|
+
func: async function (kwargs) {
|
|
59
|
+
const debug = Boolean(kwargs.debug);
|
|
60
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
61
|
+
const runtimeUserId = String(kwargs.userId || userId || '').trim();
|
|
62
|
+
const payload = { corpid };
|
|
63
|
+
payload.businessType = Number(kwargs.businessType || 0);
|
|
64
|
+
payload.formId = Number(kwargs.formId || 0);
|
|
65
|
+
payload.groupId = Number(kwargs.groupId || 0);
|
|
66
|
+
payload.dataId = Number(kwargs.dataId || 0);
|
|
67
|
+
payload.color = String(kwargs.color || '').trim();
|
|
68
|
+
if (String(kwargs.name || '').trim()) payload.name = String(kwargs.name).trim();
|
|
69
|
+
if (runtimeUserId) payload.userId = runtimeUserId;
|
|
70
|
+
const requestBody = JSON.stringify(payload);
|
|
71
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
72
|
+
if (!payload.businessType) return makeErrorRow('NO_BUSINESSTYPE', '缺少 --businessType');
|
|
73
|
+
if (!payload.formId) return makeErrorRow('NO_FORMID', '缺少 --formId');
|
|
74
|
+
if (!payload.groupId) return makeErrorRow('NO_GROUPID', '缺少 --groupId');
|
|
75
|
+
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
76
|
+
if (!payload.color) return makeErrorRow('NO_COLOR', '缺少 --color');
|
|
77
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
78
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
79
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
|
|
80
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
81
|
+
if (debug) {
|
|
82
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
83
|
+
}
|
|
84
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
|
|
85
|
+
if (!resp.ok) {
|
|
86
|
+
const responseText = await resp.text();
|
|
87
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
88
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
89
|
+
}
|
|
90
|
+
const data = await resp.json();
|
|
91
|
+
const responseBody = JSON.stringify(data);
|
|
92
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
93
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
94
|
+
return [{ code: data.code ?? '', msg: data.msg || '' }];
|
|
95
|
+
},
|
|
96
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
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/label/group/add';
|
|
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 makeErrorRow(code, msg) {
|
|
36
|
+
return [{ dataId: '', code, msg }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cli({
|
|
40
|
+
site: 'xbb',
|
|
41
|
+
name: 'label-group-add',
|
|
42
|
+
description: '新建标签分组接口(businessType: -1;label 模块)',
|
|
43
|
+
strategy: Strategy.PUBLIC,
|
|
44
|
+
access: 'write',
|
|
45
|
+
browser: false,
|
|
46
|
+
domain: 'proapi.xbongbong.com',
|
|
47
|
+
args: [
|
|
48
|
+
{ name: 'formId', type: 'int', help: '表单模板id(必填)' },
|
|
49
|
+
{ name: 'businessType', type: 'int', help: '业务类型(必填)' },
|
|
50
|
+
{ name: 'name', type: 'str', help: '分组名(必填)' },
|
|
51
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
52
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
53
|
+
],
|
|
54
|
+
columns: ['dataId', 'code', 'msg'],
|
|
55
|
+
func: async function (kwargs) {
|
|
56
|
+
const debug = Boolean(kwargs.debug);
|
|
57
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
58
|
+
const runtimeUserId = String(kwargs.userId || userId || '').trim();
|
|
59
|
+
const payload = { corpid };
|
|
60
|
+
payload.formId = Number(kwargs.formId || 0);
|
|
61
|
+
payload.businessType = Number(kwargs.businessType || 0);
|
|
62
|
+
payload.name = String(kwargs.name || '').trim();
|
|
63
|
+
if (runtimeUserId) payload.userId = runtimeUserId;
|
|
64
|
+
const requestBody = JSON.stringify(payload);
|
|
65
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
66
|
+
if (!payload.formId) return makeErrorRow('NO_FORMID', '缺少 --formId');
|
|
67
|
+
if (!payload.businessType) return makeErrorRow('NO_BUSINESSTYPE', '缺少 --businessType');
|
|
68
|
+
if (!payload.name) return makeErrorRow('NO_NAME', '缺少 --name');
|
|
69
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
70
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
71
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
|
|
72
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
73
|
+
if (debug) {
|
|
74
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
75
|
+
}
|
|
76
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
|
|
77
|
+
if (!resp.ok) {
|
|
78
|
+
const responseText = await resp.text();
|
|
79
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
80
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
81
|
+
}
|
|
82
|
+
const data = await resp.json();
|
|
83
|
+
const responseBody = JSON.stringify(data);
|
|
84
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
85
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
86
|
+
const result = data.result || {};
|
|
87
|
+
return [{ dataId: result.dataId || result.id || '', code: data.code ?? '', msg: data.msg || '' }];
|
|
88
|
+
},
|
|
89
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
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/label/group/del';
|
|
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 makeErrorRow(code, msg) {
|
|
36
|
+
return [{ groupId: '', code, msg }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cli({
|
|
40
|
+
site: 'xbb',
|
|
41
|
+
name: 'label-group-del',
|
|
42
|
+
description: '删除标签分组接口(businessType: -1;label 模块)',
|
|
43
|
+
strategy: Strategy.PUBLIC,
|
|
44
|
+
access: 'write',
|
|
45
|
+
browser: false,
|
|
46
|
+
domain: 'proapi.xbongbong.com',
|
|
47
|
+
args: [
|
|
48
|
+
{ name: 'groupId', type: 'int', help: '分组id(必填)' },
|
|
49
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
50
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
51
|
+
],
|
|
52
|
+
columns: ['groupId', 'code', 'msg'],
|
|
53
|
+
func: async function (kwargs) {
|
|
54
|
+
const debug = Boolean(kwargs.debug);
|
|
55
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
56
|
+
const runtimeUserId = String(kwargs.userId || userId || '').trim();
|
|
57
|
+
const payload = { corpid };
|
|
58
|
+
payload.groupId = Number(kwargs.groupId || 0);
|
|
59
|
+
if (runtimeUserId) payload.userId = runtimeUserId;
|
|
60
|
+
const requestBody = JSON.stringify(payload);
|
|
61
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
62
|
+
if (!payload.groupId) return makeErrorRow('NO_GROUPID', '缺少 --groupId');
|
|
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 }, runtimeUserId ? { userId: runtimeUserId } : {});
|
|
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) {
|
|
72
|
+
const responseText = await resp.text();
|
|
73
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
74
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
75
|
+
}
|
|
76
|
+
const data = await resp.json();
|
|
77
|
+
const responseBody = JSON.stringify(data);
|
|
78
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
79
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
80
|
+
const result = data.result || {};
|
|
81
|
+
return [{ groupId: result.groupId || result.id || '', code: data.code ?? '', msg: data.msg || '' }];
|
|
82
|
+
},
|
|
83
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
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/label/group/list';
|
|
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 makeErrorRow(code, msg) {
|
|
36
|
+
return [{ rank: '', groupId: '', name: '', sort: '', code, msg }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cli({
|
|
40
|
+
site: 'xbb',
|
|
41
|
+
name: 'label-group-list',
|
|
42
|
+
description: '标签分组列表接口(businessType: -1;label 模块)',
|
|
43
|
+
strategy: Strategy.PUBLIC,
|
|
44
|
+
access: 'read',
|
|
45
|
+
browser: false,
|
|
46
|
+
domain: 'proapi.xbongbong.com',
|
|
47
|
+
args: [
|
|
48
|
+
{ name: 'formId', type: 'int', help: '表单id(必填)' },
|
|
49
|
+
{ name: 'businessType', type: 'int', help: '业务类型(必填)' },
|
|
50
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
51
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
52
|
+
],
|
|
53
|
+
columns: ['rank', 'groupId', 'name', 'sort', 'code', 'msg'],
|
|
54
|
+
func: async function (kwargs) {
|
|
55
|
+
const debug = Boolean(kwargs.debug);
|
|
56
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
57
|
+
const runtimeUserId = String(kwargs.userId || userId || '').trim();
|
|
58
|
+
const payload = { corpid };
|
|
59
|
+
payload.formId = Number(kwargs.formId || 0);
|
|
60
|
+
payload.businessType = Number(kwargs.businessType || 0);
|
|
61
|
+
if (runtimeUserId) payload.userId = runtimeUserId;
|
|
62
|
+
const requestBody = JSON.stringify(payload);
|
|
63
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
64
|
+
if (!payload.formId) return makeErrorRow('NO_FORMID', '缺少 --formId');
|
|
65
|
+
if (!payload.businessType) return makeErrorRow('NO_BUSINESSTYPE', '缺少 --businessType');
|
|
66
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
67
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
68
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
|
|
69
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
70
|
+
if (debug) {
|
|
71
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
72
|
+
}
|
|
73
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
|
|
74
|
+
if (!resp.ok) {
|
|
75
|
+
const responseText = await resp.text();
|
|
76
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
77
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
78
|
+
}
|
|
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
|
+
const list = Array.isArray(data.result?.labelGroupList) ? data.result.labelGroupList : [];
|
|
84
|
+
if (!list.length) return makeErrorRow('NO_DATA', '接口成功,但 labelGroupList 为空');
|
|
85
|
+
return list.map((item, index) => ({ rank: index + 1, groupId: item.groupId || '', name: item.name || '', sort: item.sort ?? '', code: '', msg: '' }));
|
|
86
|
+
},
|
|
87
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
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/label/group/update';
|
|
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 makeErrorRow(code, msg) {
|
|
36
|
+
return [{ groupId: '', code, msg }];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cli({
|
|
40
|
+
site: 'xbb',
|
|
41
|
+
name: 'label-group-update',
|
|
42
|
+
description: '编辑标签分组接口(businessType: -1;label 模块)',
|
|
43
|
+
strategy: Strategy.PUBLIC,
|
|
44
|
+
access: 'write',
|
|
45
|
+
browser: false,
|
|
46
|
+
domain: 'proapi.xbongbong.com',
|
|
47
|
+
args: [
|
|
48
|
+
{ name: 'formId', type: 'int', help: '表单id(必填)' },
|
|
49
|
+
{ name: 'name', type: 'str', help: '分组名(必填)' },
|
|
50
|
+
{ name: 'groupId', type: 'int', help: '分组id(必填)' },
|
|
51
|
+
{ name: 'businessType', type: 'int', help: '业务类型(必填)' },
|
|
52
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
53
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
54
|
+
],
|
|
55
|
+
columns: ['groupId', 'code', 'msg'],
|
|
56
|
+
func: async function (kwargs) {
|
|
57
|
+
const debug = Boolean(kwargs.debug);
|
|
58
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
59
|
+
const runtimeUserId = String(kwargs.userId || userId || '').trim();
|
|
60
|
+
const payload = { corpid };
|
|
61
|
+
payload.formId = Number(kwargs.formId || 0);
|
|
62
|
+
payload.name = String(kwargs.name || '').trim();
|
|
63
|
+
payload.groupId = Number(kwargs.groupId || 0);
|
|
64
|
+
payload.businessType = Number(kwargs.businessType || 0);
|
|
65
|
+
if (runtimeUserId) payload.userId = runtimeUserId;
|
|
66
|
+
const requestBody = JSON.stringify(payload);
|
|
67
|
+
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
68
|
+
if (!payload.formId) return makeErrorRow('NO_FORMID', '缺少 --formId');
|
|
69
|
+
if (!payload.name) return makeErrorRow('NO_NAME', '缺少 --name');
|
|
70
|
+
if (!payload.groupId) return makeErrorRow('NO_GROUPID', '缺少 --groupId');
|
|
71
|
+
if (!payload.businessType) return makeErrorRow('NO_BUSINESSTYPE', '缺少 --businessType');
|
|
72
|
+
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
73
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
74
|
+
const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
|
|
75
|
+
const apiUrl = buildApiUrl(baseUrl, API_URL);
|
|
76
|
+
if (debug) {
|
|
77
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
78
|
+
}
|
|
79
|
+
const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
|
|
80
|
+
if (!resp.ok) {
|
|
81
|
+
const responseText = await resp.text();
|
|
82
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
83
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
84
|
+
}
|
|
85
|
+
const data = await resp.json();
|
|
86
|
+
const responseBody = JSON.stringify(data);
|
|
87
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
88
|
+
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
89
|
+
const result = data.result || {};
|
|
90
|
+
return [{ groupId: result.groupId || result.id || '', code: data.code ?? '', msg: data.msg || '' }];
|
|
91
|
+
},
|
|
92
|
+
});
|