@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,159 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { cli, Strategy } from './xbb-registry.js';
|
|
6
|
+
|
|
7
|
+
const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
|
|
8
|
+
const WORK_ORDER_PRODUCT_LIST_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workOrder/productList';
|
|
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 buildPayload(kwargs, corpid) {
|
|
37
|
+
const payload = {
|
|
38
|
+
dataId: Number(kwargs.dataId || 0),
|
|
39
|
+
corpid,
|
|
40
|
+
page: Number(kwargs.page || 1),
|
|
41
|
+
pageSize: Number(kwargs.pageSize || 20),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (kwargs.userId) {
|
|
45
|
+
payload.userId = String(kwargs.userId);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return payload;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getValidationError(payload, token) {
|
|
52
|
+
if (!payload.dataId) {
|
|
53
|
+
return { code: 'NO_DATAID', msg: '缺少 --dataId' };
|
|
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
|
+
text_1: '',
|
|
69
|
+
text_3: '',
|
|
70
|
+
num_1: '',
|
|
71
|
+
num_3: '',
|
|
72
|
+
businessProductId: '',
|
|
73
|
+
text_8: '',
|
|
74
|
+
code,
|
|
75
|
+
msg,
|
|
76
|
+
}];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function makeSuccessRows(list) {
|
|
80
|
+
return list.map((item, index) => ({
|
|
81
|
+
rank: index + 1,
|
|
82
|
+
text_1: item.text_1 || '',
|
|
83
|
+
text_3: item.text_3 || '',
|
|
84
|
+
num_1: item.num_1 || '',
|
|
85
|
+
num_3: item.num_3 || '',
|
|
86
|
+
businessProductId: item.businessProductId || '',
|
|
87
|
+
text_8: item.text_8 || '',
|
|
88
|
+
code: '',
|
|
89
|
+
msg: '',
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
cli({
|
|
94
|
+
site: 'xbb',
|
|
95
|
+
name: 'workorderproductlist',
|
|
96
|
+
description: '工单配件接口(businessType: 2301)',
|
|
97
|
+
strategy: Strategy.PUBLIC,
|
|
98
|
+
access: 'read',
|
|
99
|
+
browser: false,
|
|
100
|
+
domain: 'proapi.xbongbong.com',
|
|
101
|
+
args: [
|
|
102
|
+
{ name: 'dataId', type: 'int', help: '工单id(必填)' },
|
|
103
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
104
|
+
{ name: 'page', type: 'int', default: 1, help: '页码' },
|
|
105
|
+
{ name: 'pageSize', type: 'int', default: 20, help: '每页数量' },
|
|
106
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
107
|
+
],
|
|
108
|
+
columns: ['rank', 'text_1', 'text_3', 'num_1', 'num_3', 'businessProductId', 'text_8', 'code', 'msg'],
|
|
109
|
+
footerExtra: () => (lastPagination ? `totalCount ${lastPagination.totalCount} / totalPage ${lastPagination.totalPage}` : undefined),
|
|
110
|
+
func: async function (kwargs) {
|
|
111
|
+
const debug = Boolean(kwargs.debug);
|
|
112
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
113
|
+
const payload = buildPayload(kwargs, corpid);
|
|
114
|
+
const body = JSON.stringify(payload);
|
|
115
|
+
|
|
116
|
+
const validationError = getValidationError(payload, token);
|
|
117
|
+
if (validationError) {
|
|
118
|
+
return makeErrorRow(validationError.code, validationError.msg);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const sign = crypto.createHash('sha256').update(body + token).digest('hex');
|
|
122
|
+
const apiUrl = buildApiUrl(baseUrl, WORK_ORDER_PRODUCT_LIST_API_URL);
|
|
123
|
+
const headers = Object.assign({
|
|
124
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
125
|
+
sign,
|
|
126
|
+
}, userId ? { userId } : {});
|
|
127
|
+
if (debug) {
|
|
128
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
129
|
+
}
|
|
130
|
+
const resp = await fetch(apiUrl, {
|
|
131
|
+
method: 'POST',
|
|
132
|
+
headers,
|
|
133
|
+
body,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (!resp.ok) {
|
|
137
|
+
const responseText = await resp.text();
|
|
138
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
139
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const data = await resp.json();
|
|
143
|
+
lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
|
|
144
|
+
? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
|
|
145
|
+
: null;
|
|
146
|
+
const responseBody = JSON.stringify(data);
|
|
147
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
148
|
+
if (data.code !== 1) {
|
|
149
|
+
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const list = Array.isArray(data.result?.list) ? data.result.list : [];
|
|
153
|
+
if (!list.length) {
|
|
154
|
+
return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return makeSuccessRows(list);
|
|
158
|
+
},
|
|
159
|
+
});
|
|
@@ -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 WORK_TIME_RECORD_DETAIL_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workTimeRecord/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 buildPayload(kwargs, corpid) {
|
|
36
|
+
const payload = {
|
|
37
|
+
dataId: Number(kwargs.dataId || 0),
|
|
38
|
+
corpid,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const userId = String(kwargs.userId || '');
|
|
42
|
+
if (userId) {
|
|
43
|
+
payload.userId = userId;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const queryFlag = String(kwargs.queryFlag ?? '');
|
|
47
|
+
if (queryFlag !== '') {
|
|
48
|
+
payload.queryFlag = Number(queryFlag);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return payload;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getValidationError(payload, token) {
|
|
55
|
+
if (!payload.dataId) {
|
|
56
|
+
return { code: 'NO_DATAID', msg: '缺少 --dataId' };
|
|
57
|
+
}
|
|
58
|
+
if (!payload.corpid) {
|
|
59
|
+
return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
|
|
60
|
+
}
|
|
61
|
+
if (!token) {
|
|
62
|
+
return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function makeErrorRow(code, msg) {
|
|
69
|
+
return [{
|
|
70
|
+
dataId: '',
|
|
71
|
+
formId: '',
|
|
72
|
+
serialNo: '',
|
|
73
|
+
creatorId: '',
|
|
74
|
+
ownerId: '',
|
|
75
|
+
coUserId: '',
|
|
76
|
+
addTime: '',
|
|
77
|
+
updateTime: '',
|
|
78
|
+
data: '',
|
|
79
|
+
code,
|
|
80
|
+
msg,
|
|
81
|
+
}];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function makeSuccessRow(data) {
|
|
85
|
+
const result = data.result || {};
|
|
86
|
+
return [{
|
|
87
|
+
dataId: result.dataId || '',
|
|
88
|
+
formId: result.formId || '',
|
|
89
|
+
serialNo: result.data?.serialNo || '',
|
|
90
|
+
creatorId: result.data?.creatorId ? JSON.stringify(result.data.creatorId) : '',
|
|
91
|
+
ownerId: Array.isArray(result.data?.ownerId) ? JSON.stringify(result.data.ownerId) : (result.data?.ownerId || ''),
|
|
92
|
+
coUserId: Array.isArray(result.data?.coUserId) ? JSON.stringify(result.data.coUserId) : (result.data?.coUserId || ''),
|
|
93
|
+
addTime: result.addTime || '',
|
|
94
|
+
updateTime: result.updateTime || '',
|
|
95
|
+
data: JSON.stringify(result.data || {}),
|
|
96
|
+
code: data.code ?? '',
|
|
97
|
+
msg: data.msg || '',
|
|
98
|
+
}];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
cli({
|
|
102
|
+
site: 'xbb',
|
|
103
|
+
name: 'worktimerecorddetail',
|
|
104
|
+
description: '工时记录详情接口(businessType: 2301)',
|
|
105
|
+
strategy: Strategy.PUBLIC,
|
|
106
|
+
access: 'read',
|
|
107
|
+
browser: false,
|
|
108
|
+
domain: 'proapi.xbongbong.com',
|
|
109
|
+
args: [
|
|
110
|
+
{ name: 'dataId', type: 'int', help: '数据id(必填)' },
|
|
111
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
112
|
+
{ name: 'queryFlag', type: 'str', default: '', help: '是否查询审批数据:0非审批,1审批中,2全部' },
|
|
113
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
114
|
+
],
|
|
115
|
+
columns: ['dataId', 'formId', 'serialNo', 'creatorId', 'ownerId', 'coUserId', 'addTime', 'updateTime', 'data', 'code', 'msg'],
|
|
116
|
+
func: async function (kwargs) {
|
|
117
|
+
const debug = Boolean(kwargs.debug);
|
|
118
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
119
|
+
const payload = buildPayload(kwargs, corpid);
|
|
120
|
+
const requestBody = JSON.stringify(payload);
|
|
121
|
+
|
|
122
|
+
const validationError = getValidationError(payload, token);
|
|
123
|
+
if (validationError) {
|
|
124
|
+
return makeErrorRow(validationError.code, validationError.msg);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
128
|
+
const apiUrl = buildApiUrl(baseUrl, WORK_TIME_RECORD_DETAIL_API_URL);
|
|
129
|
+
const headers = Object.assign({
|
|
130
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
131
|
+
sign,
|
|
132
|
+
}, userId ? { userId } : {});
|
|
133
|
+
if (debug) {
|
|
134
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
135
|
+
}
|
|
136
|
+
const resp = await fetch(apiUrl, {
|
|
137
|
+
method: 'POST',
|
|
138
|
+
headers,
|
|
139
|
+
body: requestBody,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
if (!resp.ok) {
|
|
143
|
+
const responseText = await resp.text();
|
|
144
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
145
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const data = await resp.json();
|
|
149
|
+
const responseBody = JSON.stringify(data);
|
|
150
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
151
|
+
if (data.code !== 1) {
|
|
152
|
+
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return makeSuccessRow(data);
|
|
156
|
+
},
|
|
157
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { cli, Strategy } from './xbb-registry.js';
|
|
6
|
+
|
|
7
|
+
const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
|
|
8
|
+
const WORK_TIME_RECORD_LIST_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workTimeRecord/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
|
+
const conditions = kwargs.conditions;
|
|
38
|
+
if (typeof conditions === 'string' && conditions.trim()) {
|
|
39
|
+
return JSON.parse(conditions);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!(kwargs.attr && kwargs.value)) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return [{
|
|
47
|
+
attr: String(kwargs.attr),
|
|
48
|
+
value: [String(kwargs.value)],
|
|
49
|
+
symbol: String(kwargs.symbol || 'equal'),
|
|
50
|
+
}];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function buildPayload(kwargs, corpid) {
|
|
54
|
+
const payload = {
|
|
55
|
+
corpid,
|
|
56
|
+
page: Number(kwargs.page || 1),
|
|
57
|
+
pageSize: Number(kwargs.pageSize || 20),
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const userId = String(kwargs.userId || '');
|
|
61
|
+
if (userId) {
|
|
62
|
+
payload.userId = userId;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const viewApproval = String(kwargs.viewApproval ?? '');
|
|
66
|
+
if (viewApproval !== '') {
|
|
67
|
+
payload.viewApproval = Number(viewApproval);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const conditions = buildConditions(kwargs);
|
|
71
|
+
if (conditions.length) {
|
|
72
|
+
payload.conditions = conditions;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return payload;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getValidationError(payload, token) {
|
|
79
|
+
if (!payload.corpid) {
|
|
80
|
+
return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
|
|
81
|
+
}
|
|
82
|
+
if (!token) {
|
|
83
|
+
return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function makeErrorRow(code, msg) {
|
|
90
|
+
return [{
|
|
91
|
+
rank: '',
|
|
92
|
+
dataId: '',
|
|
93
|
+
formId: '',
|
|
94
|
+
serialNo: '',
|
|
95
|
+
creatorId: '',
|
|
96
|
+
ownerId: '',
|
|
97
|
+
coUserId: '',
|
|
98
|
+
addTime: '',
|
|
99
|
+
updateTime: '',
|
|
100
|
+
data: '',
|
|
101
|
+
code,
|
|
102
|
+
msg,
|
|
103
|
+
}];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function makeSuccessRows(list, kwargs) {
|
|
107
|
+
return list.map((item, index) => ({
|
|
108
|
+
rank: index + 1,
|
|
109
|
+
dataId: item.dataId || '',
|
|
110
|
+
formId: item.formId || '',
|
|
111
|
+
serialNo: item.data?.serialNo || '',
|
|
112
|
+
creatorId: item.data?.creatorId || '',
|
|
113
|
+
ownerId: Array.isArray(item.data?.ownerId) ? JSON.stringify(item.data.ownerId) : (item.data?.ownerId || ''),
|
|
114
|
+
coUserId: Array.isArray(item.data?.coUserId) ? JSON.stringify(item.data.coUserId) : (item.data?.coUserId || ''),
|
|
115
|
+
addTime: item.addTime || '',
|
|
116
|
+
updateTime: item.updateTime || '',
|
|
117
|
+
data: JSON.stringify(item.data || {}),
|
|
118
|
+
code: '',
|
|
119
|
+
msg: '',
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
cli({
|
|
124
|
+
site: 'xbb',
|
|
125
|
+
name: 'worktimerecordlist',
|
|
126
|
+
description: '工时记录列表接口(businessType: 2301)',
|
|
127
|
+
strategy: Strategy.PUBLIC,
|
|
128
|
+
access: 'read',
|
|
129
|
+
browser: false,
|
|
130
|
+
domain: 'proapi.xbongbong.com',
|
|
131
|
+
args: [
|
|
132
|
+
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
133
|
+
{ name: 'viewApproval', type: 'str', default: '', help: '是否查询审批中数据,1是,0否' },
|
|
134
|
+
{ name: 'conditions', type: 'str', default: '', help: '条件集合 JSON 字符串' },
|
|
135
|
+
{ name: 'attr', type: 'str', default: '', help: '筛选字段 attr,例如 text_1' },
|
|
136
|
+
{ name: 'value', type: 'str', default: '', help: '筛选值,和 --attr 配合使用' },
|
|
137
|
+
{ name: 'symbol', type: 'str', default: 'equal', help: '筛选操作符,默认 equal' },
|
|
138
|
+
{ name: 'page', type: 'int', default: 1, help: '页码' },
|
|
139
|
+
{ name: 'pageSize', type: 'int', default: 20, help: '每页数量(最大100)' },
|
|
140
|
+
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
141
|
+
],
|
|
142
|
+
columns: ['rank', 'dataId', 'formId', 'serialNo', 'creatorId', 'ownerId', 'coUserId', 'addTime', 'updateTime', 'data', 'code', 'msg'],
|
|
143
|
+
footerExtra: () => (lastPagination ? `totalCount ${lastPagination.totalCount} / totalPage ${lastPagination.totalPage}` : undefined),
|
|
144
|
+
func: async function (kwargs) {
|
|
145
|
+
const debug = Boolean(kwargs.debug);
|
|
146
|
+
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
147
|
+
let payload;
|
|
148
|
+
try {
|
|
149
|
+
payload = buildPayload(kwargs, corpid);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
return makeErrorRow('INVALID_CONDITIONS', 'conditions 不是合法 JSON');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const requestBody = JSON.stringify(payload);
|
|
155
|
+
|
|
156
|
+
const validationError = getValidationError(payload, token);
|
|
157
|
+
if (validationError) {
|
|
158
|
+
return makeErrorRow(validationError.code, validationError.msg);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
|
|
162
|
+
const apiUrl = buildApiUrl(baseUrl, WORK_TIME_RECORD_LIST_API_URL);
|
|
163
|
+
const headers = Object.assign({
|
|
164
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
165
|
+
sign,
|
|
166
|
+
}, userId ? { userId } : {});
|
|
167
|
+
if (debug) {
|
|
168
|
+
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
169
|
+
}
|
|
170
|
+
const resp = await fetch(apiUrl, {
|
|
171
|
+
method: 'POST',
|
|
172
|
+
headers,
|
|
173
|
+
body: requestBody,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
if (!resp.ok) {
|
|
177
|
+
const responseText = await resp.text();
|
|
178
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
179
|
+
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const data = await resp.json();
|
|
183
|
+
lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
|
|
184
|
+
? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
|
|
185
|
+
: null;
|
|
186
|
+
const responseBody = JSON.stringify(data);
|
|
187
|
+
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
188
|
+
if (data.code !== 1) {
|
|
189
|
+
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const list = Array.isArray(data.result?.list) ? data.result.list : [];
|
|
193
|
+
if (!list.length) {
|
|
194
|
+
return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return makeSuccessRows(list, kwargs);
|
|
198
|
+
},
|
|
199
|
+
});
|
package/xbb-registry.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const registry = new Map();
|
|
2
|
+
|
|
3
|
+
export const Strategy = Object.freeze({ PUBLIC: 'public', PRIVATE: 'private' });
|
|
4
|
+
|
|
5
|
+
export function fullName(site, name) {
|
|
6
|
+
return `${site}/${name}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function cli(definition) {
|
|
10
|
+
const key = fullName(definition.site, definition.name);
|
|
11
|
+
registry.set(key, definition);
|
|
12
|
+
return definition;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function registerCommand(definition) {
|
|
16
|
+
return cli(definition);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getRegistry() {
|
|
20
|
+
return registry;
|
|
21
|
+
}
|