@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.
Files changed (255) hide show
  1. package/README.md +436 -0
  2. package/ai-call-add-task.js +106 -0
  3. package/ai-word-list.js +81 -0
  4. package/bin/xbbcli.js +120 -0
  5. package/buyer-inquiry-detail.js +112 -0
  6. package/buyer-inquiry-list.js +142 -0
  7. package/clue-add-couser.js +86 -0
  8. package/clue-add.js +102 -0
  9. package/clue-back.js +82 -0
  10. package/clue-del.js +75 -0
  11. package/clue-delete-couser.js +84 -0
  12. package/clue-delete-mainuser.js +84 -0
  13. package/clue-detail.js +78 -0
  14. package/clue-distribution.js +91 -0
  15. package/clue-edit.js +101 -0
  16. package/clue-handover.js +103 -0
  17. package/clue-list.js +224 -0
  18. package/clue-thorough-delete.js +82 -0
  19. package/communicate-add.js +144 -0
  20. package/communicate-del.js +118 -0
  21. package/communicate-detail.js +123 -0
  22. package/communicate-edit.js +146 -0
  23. package/communicate-list.js +194 -0
  24. package/communicate-plan-add.js +102 -0
  25. package/communicate-plan-cancel.js +76 -0
  26. package/communicate-plan-del.js +76 -0
  27. package/communicate-plan-detail.js +79 -0
  28. package/communicate-plan-list.js +129 -0
  29. package/communicate-plan-single-operate.js +86 -0
  30. package/contact-add-couser.js +87 -0
  31. package/contact-add-mainuser.js +87 -0
  32. package/contact-add.js +125 -0
  33. package/contact-del.js +70 -0
  34. package/contact-delete-couser.js +87 -0
  35. package/contact-delete-mainuser.js +87 -0
  36. package/contact-detail.js +72 -0
  37. package/contact-edit.js +103 -0
  38. package/contact-handover.js +84 -0
  39. package/contact-list.js +195 -0
  40. package/contract-add-couser.js +129 -0
  41. package/contract-add-mainuser.js +129 -0
  42. package/contract-add.js +148 -0
  43. package/contract-del.js +117 -0
  44. package/contract-delete-couser.js +128 -0
  45. package/contract-delete-mainuser.js +129 -0
  46. package/contract-detail.js +124 -0
  47. package/contract-edit.js +147 -0
  48. package/contract-handover.js +129 -0
  49. package/contract-list.js +235 -0
  50. package/contract-outstock-add.js +104 -0
  51. package/contract-outstock-del.js +78 -0
  52. package/contract-outstock-detail.js +80 -0
  53. package/contract-outstock-edit.js +106 -0
  54. package/contract-outstock-list.js +121 -0
  55. package/customer-add-couser.js +186 -0
  56. package/customer-add.js +152 -0
  57. package/customer-back.js +125 -0
  58. package/customer-del.js +117 -0
  59. package/customer-delete-couser.js +128 -0
  60. package/customer-delete-mainuser.js +129 -0
  61. package/customer-detail.js +148 -0
  62. package/customer-distribution.js +132 -0
  63. package/customer-edit.js +174 -0
  64. package/customer-handover.js +131 -0
  65. package/customer-invoice-address-add.js +101 -0
  66. package/customer-invoice-address-edit.js +102 -0
  67. package/customer-invoice-address.js +86 -0
  68. package/customer-invoice-info-add.js +101 -0
  69. package/customer-invoice-info-edit.js +102 -0
  70. package/customer-invoice-info.js +88 -0
  71. package/customer-list.js +187 -0
  72. package/department-add.js +77 -0
  73. package/department-del.js +76 -0
  74. package/department-edit.js +77 -0
  75. package/department-list.js +190 -0
  76. package/form-data-add-couser.js +84 -0
  77. package/form-data-add-mainuser.js +84 -0
  78. package/form-data-add.js +171 -0
  79. package/form-data-del.js +135 -0
  80. package/form-data-delete-couser.js +85 -0
  81. package/form-data-delete-mainuser.js +84 -0
  82. package/form-data-detail.js +146 -0
  83. package/form-data-edit.js +171 -0
  84. package/form-data-handover.js +84 -0
  85. package/form-data-list.js +188 -0
  86. package/form-get.js +157 -0
  87. package/form-list.js +169 -0
  88. package/invoice-add.js +98 -0
  89. package/invoice-cancel.js +97 -0
  90. package/invoice-del.js +83 -0
  91. package/invoice-detail.js +85 -0
  92. package/invoice-edit.js +101 -0
  93. package/invoice-get-amount-detail.js +84 -0
  94. package/invoice-list.js +125 -0
  95. package/invoice-red.js +101 -0
  96. package/label-add.js +93 -0
  97. package/label-all-list.js +102 -0
  98. package/label-batch-add.js +111 -0
  99. package/label-batch-remove.js +111 -0
  100. package/label-del-completely.js +88 -0
  101. package/label-del.js +98 -0
  102. package/label-edit.js +96 -0
  103. package/label-group-add.js +89 -0
  104. package/label-group-del.js +83 -0
  105. package/label-group-list.js +87 -0
  106. package/label-group-update.js +92 -0
  107. package/label-list.js +97 -0
  108. package/label-reduction.js +92 -0
  109. package/label-repeat.js +89 -0
  110. package/market-activity-add.js +109 -0
  111. package/market-activity-del.js +83 -0
  112. package/market-activity-detail.js +84 -0
  113. package/market-activity-edit.js +106 -0
  114. package/market-activity-handover.js +88 -0
  115. package/market-activity-list.js +121 -0
  116. package/opportunity-add-couser.js +129 -0
  117. package/opportunity-add-mainuser.js +129 -0
  118. package/opportunity-add.js +147 -0
  119. package/opportunity-del.js +118 -0
  120. package/opportunity-delete-couser.js +129 -0
  121. package/opportunity-delete-mainuser.js +128 -0
  122. package/opportunity-detail.js +125 -0
  123. package/opportunity-edit.js +146 -0
  124. package/opportunity-handover.js +130 -0
  125. package/opportunity-list.js +169 -0
  126. package/package.json +34 -0
  127. package/pay-plan-add-couser.js +88 -0
  128. package/pay-plan-add-mainuser.js +88 -0
  129. package/pay-plan-add.js +104 -0
  130. package/pay-plan-delete-couser.js +87 -0
  131. package/pay-plan-delete-mainuser.js +87 -0
  132. package/pay-plan-handover.js +85 -0
  133. package/pay-sheet-add-bad.js +104 -0
  134. package/pay-sheet-add-couser.js +87 -0
  135. package/pay-sheet-add-mainuser.js +88 -0
  136. package/pay-sheet-add-red.js +104 -0
  137. package/pay-sheet-add-write-off.js +104 -0
  138. package/pay-sheet-del.js +86 -0
  139. package/pay-sheet-delete-couser.js +87 -0
  140. package/pay-sheet-delete-mainuser.js +88 -0
  141. package/pay-sheet-detail.js +85 -0
  142. package/pay-sheet-edit-bad.js +110 -0
  143. package/pay-sheet-edit-red.js +110 -0
  144. package/pay-sheet-edit-write-off.js +106 -0
  145. package/pay-sheet-get-amount-detail.js +83 -0
  146. package/pay-sheet-list.js +123 -0
  147. package/payment-add-couser.js +129 -0
  148. package/payment-add-mainuser.js +129 -0
  149. package/payment-add.js +142 -0
  150. package/payment-del.js +117 -0
  151. package/payment-delete-couser.js +128 -0
  152. package/payment-delete-mainuser.js +128 -0
  153. package/payment-detail.js +123 -0
  154. package/payment-edit.js +146 -0
  155. package/payment-handover.js +130 -0
  156. package/payment-list.js +195 -0
  157. package/payment-sheet-add-bad-debt.js +142 -0
  158. package/payment-sheet-add-pre.js +104 -0
  159. package/payment-sheet-add-red.js +142 -0
  160. package/payment-sheet-add-write-off.js +130 -0
  161. package/payment-sheet-del.js +106 -0
  162. package/payment-sheet-detail.js +113 -0
  163. package/payment-sheet-edit-bad-debt.js +131 -0
  164. package/payment-sheet-edit-red.js +146 -0
  165. package/payment-sheet-edit-write-off.js +146 -0
  166. package/payment-sheet-get-amount-detail.js +84 -0
  167. package/payment-sheet-handover.js +85 -0
  168. package/payment-sheet-list.js +206 -0
  169. package/product-add.js +129 -0
  170. package/product-category-add.js +124 -0
  171. package/product-category-del.js +132 -0
  172. package/product-category-list.js +164 -0
  173. package/product-category-update.js +139 -0
  174. package/product-del.js +106 -0
  175. package/product-detail.js +183 -0
  176. package/product-edit.js +131 -0
  177. package/product-list.js +193 -0
  178. package/product-online.js +91 -0
  179. package/quotation-add-couser.js +106 -0
  180. package/quotation-add-mainuser.js +101 -0
  181. package/quotation-add.js +100 -0
  182. package/quotation-del.js +83 -0
  183. package/quotation-delete-couser.js +101 -0
  184. package/quotation-delete-mainuser.js +101 -0
  185. package/quotation-detail.js +85 -0
  186. package/quotation-edit.js +101 -0
  187. package/quotation-handover.js +84 -0
  188. package/quotation-list.js +123 -0
  189. package/refund-add.js +83 -0
  190. package/refund-del.js +68 -0
  191. package/refund-detail.js +71 -0
  192. package/refund-edit.js +84 -0
  193. package/refund-list.js +193 -0
  194. package/role-list.js +85 -0
  195. package/sign-in-list.js +136 -0
  196. package/stage-get.js +100 -0
  197. package/stage-jump.js +109 -0
  198. package/supplier-add.js +142 -0
  199. package/token-generate.js +109 -0
  200. package/token-set.js +222 -0
  201. package/user-add.js +103 -0
  202. package/user-del.js +90 -0
  203. package/user-edit.js +102 -0
  204. package/user-handover.js +78 -0
  205. package/user-list.js +147 -0
  206. package/version.js +18 -0
  207. package/work-order-add.js +171 -0
  208. package/work-order-asset-add-couser.js +101 -0
  209. package/work-order-asset-add-mainuser.js +104 -0
  210. package/work-order-asset-add.js +98 -0
  211. package/work-order-asset-del-couser.js +101 -0
  212. package/work-order-asset-del-mainuser.js +101 -0
  213. package/work-order-asset-del.js +83 -0
  214. package/work-order-asset-detail.js +85 -0
  215. package/work-order-asset-edit.js +101 -0
  216. package/work-order-asset-handover.js +101 -0
  217. package/work-order-asset-list.js +123 -0
  218. package/work-order-del.js +136 -0
  219. package/work-order-detail.js +186 -0
  220. package/work-order-dynamic-list.js +145 -0
  221. package/work-order-edit.js +170 -0
  222. package/work-order-list.js +243 -0
  223. package/work-order-operate.js +167 -0
  224. package/work-order-template-detail.js +157 -0
  225. package/work-order-template-list.js +145 -0
  226. package/work-report-daily-add.js +97 -0
  227. package/work-report-daily-del.js +75 -0
  228. package/work-report-daily-detail.js +78 -0
  229. package/work-report-daily-edit.js +129 -0
  230. package/work-report-daily-get-work-plan.js +80 -0
  231. package/work-report-daily-list.js +116 -0
  232. package/work-report-monthly-add.js +98 -0
  233. package/work-report-monthly-del.js +79 -0
  234. package/work-report-monthly-detail.js +78 -0
  235. package/work-report-monthly-edit.js +98 -0
  236. package/work-report-monthly-list.js +116 -0
  237. package/work-report-weekly-add.js +98 -0
  238. package/work-report-weekly-del.js +76 -0
  239. package/work-report-weekly-detail.js +79 -0
  240. package/work-report-weekly-edit.js +99 -0
  241. package/work-report-weekly-list.js +116 -0
  242. package/work-task-add-couser.js +88 -0
  243. package/work-task-add.js +242 -0
  244. package/work-task-delete-couser.js +85 -0
  245. package/work-task-detail.js +101 -0
  246. package/work-task-edit.js +116 -0
  247. package/work-task-handover.js +85 -0
  248. package/workorder-add-couser.js +128 -0
  249. package/workorder-delete-couser.js +129 -0
  250. package/workorder-handover.js +137 -0
  251. package/workorderlist.js +194 -0
  252. package/workorderproductlist.js +159 -0
  253. package/worktimerecorddetail.js +157 -0
  254. package/worktimerecordlist.js +199 -0
  255. package/xbb-registry.js +21 -0
@@ -0,0 +1,123 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { cli, Strategy } from './xbb-registry.js';
6
+
7
+ const CONFIG_FILE = path.join(os.homedir(), '.opencli', 'xbb', 'config.env');
8
+ const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workOrderV2/asset/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
+ let lastPagination = null;
35
+
36
+ function buildConditions(kwargs) {
37
+ if (String(kwargs.conditions ?? '').trim()) {
38
+ const parsed = JSON.parse(String(kwargs.conditions));
39
+ if (!Array.isArray(parsed)) {
40
+ throw new Error('INVALID_CONDITIONS:conditions 必须是 JSON 数组');
41
+ }
42
+ return parsed;
43
+ }
44
+ if (!(kwargs.attr && kwargs.value)) {
45
+ return [];
46
+ }
47
+ return [{ attr: String(kwargs.attr), value: [String(kwargs.value)], symbol: String(kwargs.symbol || 'equal') }];
48
+ }
49
+
50
+ function makeErrorRow(code, msg) {
51
+ return [{ rank: '', dataId: '', formId: '', addTime: '', updateTime: '', data: '', code, msg }];
52
+ }
53
+
54
+ cli({
55
+ site: 'xbb',
56
+ name: 'work-order-asset-list',
57
+ description: '资产列表接口(businessType: -1;workOrderV2 资产)',
58
+ strategy: Strategy.PUBLIC,
59
+ access: 'read',
60
+ browser: false,
61
+ domain: 'proapi.xbongbong.com',
62
+ args: [
63
+ { name: 'conditions', type: 'str', default: '', help: '筛选条件 JSON 数组字符串,优先级高于 --attr/--value' },
64
+ { name: 'attr', type: 'str', default: '', help: '筛选字段 attr' },
65
+ { name: 'value', type: 'str', default: '', help: '筛选值,和 --attr 配合使用' },
66
+ { name: 'symbol', type: 'str', default: 'equal', help: '筛选操作符,默认 equal' },
67
+ { name: 'viewApproval', type: 'str', default: '', help: '是否查询审批中数据,1:是,0:否' },
68
+ { name: 'page', type: 'str', default: '', help: '页码(可选)' },
69
+ { name: 'pageSize', type: 'str', default: '', help: '每页数量(可选)' },
70
+ { name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
71
+ { name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
72
+ { name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
73
+ ],
74
+ columns: ['rank', 'dataId', 'formId', 'addTime', 'updateTime', 'data', 'code', 'msg'],
75
+ footerExtra: () => (lastPagination ? `totalCount ${lastPagination.totalCount} / totalPage ${lastPagination.totalPage}` : undefined),
76
+ func: async function (kwargs) {
77
+ const debug = Boolean(kwargs.debug);
78
+ let conditions;
79
+ try {
80
+ conditions = buildConditions(kwargs);
81
+ } catch (error) {
82
+ const message = String(error?.message || error);
83
+ const separatorIndex = message.indexOf(':');
84
+ const code = separatorIndex > 0 ? message.slice(0, separatorIndex) : 'INVALID_CONDITIONS';
85
+ const detail = separatorIndex > 0 ? message.slice(separatorIndex + 1) : message;
86
+ return makeErrorRow(code, detail);
87
+ }
88
+ const { corpid, token, baseUrl, userId } = getRuntimeConfig();
89
+ const runtimeUserId = String(kwargs.userId || userId || '').trim();
90
+ const payload = { corpid };
91
+ if (String(kwargs.page ?? '') !== '') payload.page = Number(kwargs.page);
92
+ if (String(kwargs.pageSize ?? '') !== '') payload.pageSize = Number(kwargs.pageSize);
93
+ if (runtimeUserId) payload.userId = runtimeUserId;
94
+ if (conditions.length) payload.conditions = conditions;
95
+ if (String(kwargs.viewApproval ?? '') !== '') payload.viewApproval = Number(kwargs.viewApproval);
96
+ const requestBody = JSON.stringify(payload);
97
+ if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 opencli xbb token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
98
+ if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
99
+ const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
100
+ const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
101
+ const apiUrl = buildApiUrl(baseUrl, API_URL);
102
+ if (debug) {
103
+ process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
104
+ }
105
+ const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
106
+ if (!resp.ok) {
107
+ const responseText = await resp.text();
108
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
109
+ return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
110
+ }
111
+ const data = await resp.json();
112
+ lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
113
+ ? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
114
+ : null;
115
+ const responseBody = JSON.stringify(data);
116
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
117
+ if (kwargs.raw) return [{ raw: responseBody }];
118
+ if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
119
+ const list = Array.isArray(data.result?.list) ? data.result.list : [];
120
+ if (!list.length) return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
121
+ return list.map((item, index) => ({ rank: index + 1, dataId: item.dataId || '', formId: item.formId || '', addTime: item.addTime || '', updateTime: item.updateTime || '', data: JSON.stringify(item.data || {}), code: '', msg: '' }));
122
+ },
123
+ });
@@ -0,0 +1,136 @@
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_DELETE_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workOrderV2/del';
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
+ return payload;
47
+ }
48
+
49
+ function getValidationError(payload, token) {
50
+ if (!payload.dataId) {
51
+ return { code: 'NO_DATAID', msg: '缺少 --dataId' };
52
+ }
53
+ if (!payload.corpid) {
54
+ return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
55
+ }
56
+ if (!token) {
57
+ return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
58
+ }
59
+
60
+ return null;
61
+ }
62
+
63
+ function makeErrorRow(code, msg) {
64
+ return [{
65
+ dataId: '',
66
+ code,
67
+ msg,
68
+ errorDataMemo: '',
69
+ }];
70
+ }
71
+
72
+ function makeSuccessRow(data) {
73
+ return [{
74
+ dataId: '',
75
+ code: data.code ?? '',
76
+ msg: data.msg || '',
77
+ errorDataMemo: data.result?.errorDataMemo || '',
78
+ }];
79
+ }
80
+
81
+ cli({
82
+ site: 'xbb',
83
+ name: 'work-order-del',
84
+ description: '删除工单接口(businessType: 20300)',
85
+ strategy: Strategy.PUBLIC,
86
+ access: 'write',
87
+ browser: false,
88
+ domain: 'proapi.xbongbong.com',
89
+ args: [
90
+ { name: 'dataId', type: 'int', help: '表单数据id(必填)' },
91
+ { name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
92
+ { name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
93
+ ],
94
+ columns: ['dataId', 'code', 'msg', 'errorDataMemo'],
95
+ func: async function (kwargs) {
96
+ const debug = Boolean(kwargs.debug);
97
+ const { corpid, token, baseUrl, userId } = getRuntimeConfig();
98
+ const payload = buildPayload(kwargs, corpid);
99
+ const requestBody = JSON.stringify(payload);
100
+
101
+ const validationError = getValidationError(payload, token);
102
+ if (validationError) {
103
+ return makeErrorRow(validationError.code, validationError.msg);
104
+ }
105
+
106
+ const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
107
+ const headers = Object.assign({
108
+ 'Content-Type': 'application/json;charset=UTF-8',
109
+ sign,
110
+ }, userId ? { userId } : {});
111
+ const apiUrl = buildApiUrl(baseUrl, WORK_ORDER_DELETE_API_URL);
112
+ if (debug) {
113
+ process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
114
+ }
115
+ const resp = await fetch(apiUrl, {
116
+ method: 'POST',
117
+ headers,
118
+ body: requestBody,
119
+ });
120
+
121
+ if (!resp.ok) {
122
+ const responseText = await resp.text();
123
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
124
+ return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
125
+ }
126
+
127
+ const data = await resp.json();
128
+ const responseBody = JSON.stringify(data);
129
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
130
+ if (data.code !== 1) {
131
+ return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
132
+ }
133
+
134
+ return makeSuccessRow(data);
135
+ },
136
+ });
@@ -0,0 +1,186 @@
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_DETAIL_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workOrderV2/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 parseOptionalInteger(value, code, msg) {
36
+ if (String(value ?? '') === '') {
37
+ return null;
38
+ }
39
+
40
+ const parsed = Number(value);
41
+ if (Number.isNaN(parsed)) {
42
+ throw new Error(`${code}:${msg}`);
43
+ }
44
+
45
+ return parsed;
46
+ }
47
+
48
+ function buildPayload(kwargs, corpid) {
49
+ const payload = {
50
+ dataId: Number(kwargs.dataId || 0),
51
+ corpid,
52
+ };
53
+
54
+ const userId = String(kwargs.userId || '');
55
+ if (userId) {
56
+ payload.userId = userId;
57
+ }
58
+
59
+ const queryFlag = parseOptionalInteger(kwargs.queryFlag, 'INVALID_QUERY_FLAG', 'queryFlag 必须是数字');
60
+ if (queryFlag !== null) {
61
+ payload.queryFlag = queryFlag;
62
+ }
63
+
64
+ return payload;
65
+ }
66
+
67
+ function getValidationError(payload, token) {
68
+ if (!payload.dataId) {
69
+ return { code: 'NO_DATAID', msg: '缺少 --dataId' };
70
+ }
71
+ if (!payload.corpid) {
72
+ return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
73
+ }
74
+ if (!token) {
75
+ return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
76
+ }
77
+
78
+ return null;
79
+ }
80
+
81
+ function makeErrorRow(code, msg) {
82
+ return [{
83
+ dataId: '',
84
+ formId: '',
85
+ serialNo: '',
86
+ creatorId: '',
87
+ ownerId: '',
88
+ coUserId: '',
89
+ addTime: '',
90
+ updateTime: '',
91
+ data: '',
92
+ code,
93
+ msg,
94
+ }];
95
+ }
96
+
97
+ function stringifyValue(value) {
98
+ if (Array.isArray(value) || (value && typeof value === 'object')) {
99
+ return JSON.stringify(value);
100
+ }
101
+ return value ?? '';
102
+ }
103
+
104
+ function makeSuccessRow(data) {
105
+ const result = data.result || {};
106
+ return [{
107
+ dataId: result.dataId || '',
108
+ formId: result.formId || '',
109
+ serialNo: result.data?.serialNo || '',
110
+ creatorId: stringifyValue(result.data?.creatorId),
111
+ ownerId: stringifyValue(result.data?.ownerId),
112
+ coUserId: stringifyValue(result.data?.coUserId),
113
+ addTime: result.addTime || '',
114
+ updateTime: result.updateTime || '',
115
+ data: JSON.stringify(result.data || {}),
116
+ code: data.code ?? '',
117
+ msg: data.msg || '',
118
+ }];
119
+ }
120
+
121
+ cli({
122
+ site: 'xbb',
123
+ name: 'work-order-detail',
124
+ description: '工单详情接口(businessType: 20300)',
125
+ strategy: Strategy.PUBLIC,
126
+ access: 'read',
127
+ browser: false,
128
+ domain: 'proapi.xbongbong.com',
129
+ args: [
130
+ { name: 'dataId', type: 'int', help: '数据id(必填)' },
131
+ { name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
132
+ { name: 'queryFlag', type: 'str', default: '', help: '是否查询审批数据:0非审批数据,1审批数据,2全部' },
133
+ { name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
134
+ ],
135
+ columns: ['dataId', 'formId', 'serialNo', 'creatorId', 'ownerId', 'coUserId', 'addTime', 'updateTime', 'data', 'code', 'msg'],
136
+ func: async function (kwargs) {
137
+ const debug = Boolean(kwargs.debug);
138
+ const { corpid, token, baseUrl, userId } = getRuntimeConfig();
139
+ let payload;
140
+ try {
141
+ payload = buildPayload(kwargs, corpid);
142
+ } catch (error) {
143
+ const message = String(error?.message || error);
144
+ const separatorIndex = message.indexOf(':');
145
+ const code = separatorIndex > 0 ? message.slice(0, separatorIndex) : 'INVALID_PAYLOAD';
146
+ const detail = separatorIndex > 0 ? message.slice(separatorIndex + 1) : message;
147
+ return makeErrorRow(code, detail);
148
+ }
149
+
150
+ const requestBody = JSON.stringify(payload);
151
+
152
+ const validationError = getValidationError(payload, token);
153
+ if (validationError) {
154
+ return makeErrorRow(validationError.code, validationError.msg);
155
+ }
156
+
157
+ const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
158
+ const headers = Object.assign({
159
+ 'Content-Type': 'application/json;charset=UTF-8',
160
+ sign,
161
+ }, userId ? { userId } : {});
162
+ if (debug) {
163
+ process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, WORK_ORDER_DETAIL_API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
164
+ }
165
+ const resp = await fetch(buildApiUrl(baseUrl, WORK_ORDER_DETAIL_API_URL), {
166
+ method: 'POST',
167
+ headers,
168
+ body: requestBody,
169
+ });
170
+
171
+ if (!resp.ok) {
172
+ const responseText = await resp.text();
173
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
174
+ return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
175
+ }
176
+
177
+ const data = await resp.json();
178
+ const responseBody = JSON.stringify(data);
179
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
180
+ if (data.code !== 1) {
181
+ return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
182
+ }
183
+
184
+ return makeSuccessRow(data);
185
+ },
186
+ });
@@ -0,0 +1,145 @@
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_DYNAMIC_LIST_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/workOrderV2/dynamic/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 buildPayload(kwargs, corpid) {
37
+ return {
38
+ corpid,
39
+ dataId: Number(kwargs.dataId || 0),
40
+ page: Number(String(kwargs.page ?? '') === '' ? 1 : kwargs.page),
41
+ pageSize: Number(String(kwargs.pageSize ?? '') === '' ? 20 : kwargs.pageSize),
42
+ };
43
+ }
44
+
45
+ function getValidationError(payload, token) {
46
+ if (!payload.corpid) {
47
+ return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
48
+ }
49
+ if (!payload.dataId) {
50
+ return { code: 'NO_DATA_ID', msg: '缺少 --dataId' };
51
+ }
52
+ if (!token) {
53
+ return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
54
+ }
55
+ return null;
56
+ }
57
+
58
+ function makeErrorRow(code, msg) {
59
+ return [{
60
+ rank: '',
61
+ dataId: '',
62
+ content: '',
63
+ creatorId: '',
64
+ createTime: '',
65
+ data: '',
66
+ code,
67
+ msg,
68
+ }];
69
+ }
70
+
71
+ function makeSuccessRows(list) {
72
+ return list.map((item, index) => ({
73
+ rank: index + 1,
74
+ dataId: item.dataId ?? item.id ?? '',
75
+ content: item.content ?? item.remark ?? item.text ?? '',
76
+ creatorId: item.creatorId ?? item.userId ?? '',
77
+ createTime: item.createTime ?? item.addTime ?? item.updateTime ?? '',
78
+ data: JSON.stringify(item),
79
+ code: '',
80
+ msg: '',
81
+ }));
82
+ }
83
+
84
+ cli({
85
+ site: 'xbb',
86
+ name: 'work-order-dynamic-list',
87
+ description: '工单动态列表接口(businessType: 20300)',
88
+ strategy: Strategy.PUBLIC,
89
+ access: 'read',
90
+ browser: false,
91
+ domain: 'proapi.xbongbong.com',
92
+ args: [
93
+ { name: 'dataId', type: 'int', help: '工单数据id(必填)' },
94
+ { name: 'page', type: 'str', default: '1', help: '页码' },
95
+ { name: 'pageSize', type: 'str', default: '20', help: '每页数量' },
96
+ { name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
97
+ { name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
98
+ ],
99
+ columns: ['rank', 'dataId', 'content', 'creatorId', 'createTime', 'data', 'code', 'msg'],
100
+ footerExtra: () => (lastPagination ? `totalCount ${lastPagination.totalCount} / totalPage ${lastPagination.totalPage}` : undefined),
101
+ func: async function (kwargs) {
102
+ const debug = Boolean(kwargs.debug);
103
+ const { corpid, token, baseUrl, userId } = getRuntimeConfig();
104
+ const payload = buildPayload(kwargs, corpid);
105
+ const body = JSON.stringify(payload);
106
+
107
+ const validationError = getValidationError(payload, token);
108
+ if (validationError) {
109
+ return makeErrorRow(validationError.code, validationError.msg);
110
+ }
111
+
112
+ const sign = crypto.createHash('sha256').update(body + token).digest('hex');
113
+ const headers = Object.assign({
114
+ 'Content-Type': 'application/json;charset=UTF-8',
115
+ sign,
116
+ }, userId ? { userId } : {});
117
+ const apiUrl = buildApiUrl(baseUrl, WORK_ORDER_DYNAMIC_LIST_API_URL);
118
+ if (debug) {
119
+ process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
120
+ }
121
+ const resp = await fetch(apiUrl, { method: 'POST', headers, body });
122
+ if (!resp.ok) {
123
+ const responseText = await resp.text();
124
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
125
+ return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
126
+ }
127
+
128
+ const data = await resp.json();
129
+ lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
130
+ ? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
131
+ : null;
132
+ const responseBody = JSON.stringify(data);
133
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
134
+ if (kwargs.raw) return [{ raw: responseBody }];
135
+ if (data.code !== 1) {
136
+ return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
137
+ }
138
+
139
+ const list = Array.isArray(data.result?.list) ? data.result.list : [];
140
+ if (!list.length) {
141
+ return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
142
+ }
143
+ return makeSuccessRows(list);
144
+ },
145
+ });