@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
package/bin/xbbcli.js ADDED
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath, pathToFileURL } from 'node:url';
6
+ import { getRegistry } from '../xbb-registry.js';
7
+
8
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
9
+
10
+ process.stdout.on('error', (error) => {
11
+ if (error.code === 'EPIPE') process.exit(0);
12
+ throw error;
13
+ });
14
+
15
+ async function loadCommands() {
16
+ const files = fs.readdirSync(root)
17
+ .filter((name) => name.endsWith('.js') && name !== 'xbb-registry.js')
18
+ .sort();
19
+ for (const file of files) {
20
+ await import(`${pathToFileURL(path.join(root, file)).href}?xbbCli`);
21
+ }
22
+ }
23
+
24
+ function printHelp() {
25
+ const commands = [...getRegistry().values()].sort((a, b) => a.name.localeCompare(b.name));
26
+ process.stdout.write('Usage: xbbcli <command> [options]\n\nCommands:\n');
27
+ for (const command of commands) {
28
+ process.stdout.write(` ${command.name.padEnd(34)} ${command.description || ''}\n`);
29
+ }
30
+ }
31
+
32
+ function printCommandHelp(command) {
33
+ process.stdout.write(`Usage: xbbcli ${command.name} [options]\n\n${command.description || ''}\n\nOptions:\n`);
34
+ for (const arg of command.args || []) {
35
+ const suffix = arg.default !== undefined ? ` (default: ${arg.default})` : '';
36
+ process.stdout.write(` --${arg.name}${arg.type === 'bool' ? '' : ' <value>'}${suffix}\n ${arg.help || ''}\n`);
37
+ }
38
+ process.stdout.write(' -f, --format <format> output format: json, table, csv\n --help show this help\n');
39
+ }
40
+
41
+ function parseArgs(command, argv) {
42
+ const kwargs = {};
43
+ for (const arg of command.args || []) {
44
+ if (arg.default !== undefined) kwargs[arg.name] = arg.default;
45
+ }
46
+ let format = 'table';
47
+ for (let index = 0; index < argv.length; index += 1) {
48
+ const token = argv[index];
49
+ if (token === '--help' || token === '-h') return { help: true, kwargs, format };
50
+ if (token === '-f' || token === '--format') {
51
+ format = argv[++index] || format;
52
+ continue;
53
+ }
54
+ if (!token.startsWith('--')) throw new Error(`未知参数:${token}`);
55
+ const equalIndex = token.indexOf('=');
56
+ const name = token.slice(2, equalIndex === -1 ? undefined : equalIndex);
57
+ const definition = (command.args || []).find((item) => item.name === name);
58
+ if (!definition) throw new Error(`未知参数:--${name}`);
59
+ let value = equalIndex === -1 ? undefined : token.slice(equalIndex + 1);
60
+ if (definition.type === 'bool') {
61
+ kwargs[name] = value === undefined ? true : !['false', '0', 'no'].includes(value.toLowerCase());
62
+ continue;
63
+ }
64
+ if (value === undefined) value = argv[++index];
65
+ if (value === undefined) throw new Error(`参数 --${name} 缺少值`);
66
+ if (definition.type === 'int') {
67
+ if (value === '') value = '';
68
+ else if (!Number.isFinite(Number(value))) throw new Error(`参数 --${name} 必须是数字`);
69
+ else value = Number(value);
70
+ }
71
+ kwargs[name] = value;
72
+ }
73
+ return { kwargs, format };
74
+ }
75
+
76
+ function csvCell(value) {
77
+ const text = String(value ?? '');
78
+ return /[",\n\r]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
79
+ }
80
+
81
+ function outputRows(rows, command, format) {
82
+ if (format === 'json') {
83
+ process.stdout.write(`${JSON.stringify(rows, null, 2)}\n`);
84
+ return;
85
+ }
86
+ const columns = command.columns || (rows[0] ? Object.keys(rows[0]) : []);
87
+ if (format === 'csv') {
88
+ process.stdout.write(`${columns.map(csvCell).join(',')}\n`);
89
+ for (const row of rows) process.stdout.write(`${columns.map((column) => csvCell(row[column])).join(',')}\n`);
90
+ return;
91
+ }
92
+ process.stdout.write(`${columns.join('\t')}\n`);
93
+ for (const row of rows) process.stdout.write(`${columns.map((column) => String(row[column] ?? '')).join('\t')}\n`);
94
+ }
95
+
96
+ await loadCommands();
97
+ const [commandName, ...argv] = process.argv.slice(2);
98
+ if (!commandName || commandName === '--help' || commandName === '-h') {
99
+ printHelp();
100
+ process.exitCode = 0;
101
+ } else {
102
+ const command = getRegistry().get(`xbb/${commandName}`);
103
+ if (!command) {
104
+ process.stderr.write(`未知命令:${commandName}\n\n`);
105
+ printHelp();
106
+ process.exitCode = 2;
107
+ } else {
108
+ try {
109
+ const parsed = parseArgs(command, argv);
110
+ if (parsed.help) printCommandHelp(command);
111
+ else {
112
+ const rows = await command.func(parsed.kwargs);
113
+ outputRows(rows, command, parsed.format);
114
+ }
115
+ } catch (error) {
116
+ process.stderr.write(`${error.message || error}\n`);
117
+ process.exitCode = 1;
118
+ }
119
+ }
120
+ }
@@ -0,0 +1,112 @@
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 BUYER_INQUIRY_DETAIL_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/buyerInquiry/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, defaultUrl) {
31
+ const apiPath = new URL(defaultUrl).pathname;
32
+ return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
33
+ }
34
+
35
+ function buildPayload(kwargs, corpid) {
36
+ const payload = { corpid, dataId: Number(kwargs.dataId || 0) };
37
+ if (kwargs.userId) payload.userId = String(kwargs.userId);
38
+ if (String(kwargs.queryFlag ?? '') !== '') payload.queryFlag = Number(kwargs.queryFlag);
39
+ return payload;
40
+ }
41
+
42
+ function getValidationError(payload, token) {
43
+ if (!payload.corpid) {
44
+ return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
45
+ }
46
+ if (!payload.dataId) {
47
+ return { code: 'NO_DATAID', msg: '缺少 --dataId' };
48
+ }
49
+ if (!token) {
50
+ return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
51
+ }
52
+ return null;
53
+ }
54
+
55
+ function makeErrorRow(code, msg) {
56
+ return [{ dataId: '', formId: '', addTime: '', updateTime: '', data: '', code, msg }];
57
+ }
58
+
59
+ cli({
60
+ site: 'xbb',
61
+ name: 'buyer-inquiry-detail',
62
+ description: '采购询价详情接口(businessType: 5900)',
63
+ strategy: Strategy.PUBLIC,
64
+ access: 'read',
65
+ browser: false,
66
+ domain: 'proapi.xbongbong.com',
67
+ args: [
68
+ { name: 'dataId', type: 'int', help: '采购询价 id(必填)' },
69
+ { name: 'userId', type: 'str', default: '', help: '操作人 id(可选)' },
70
+ { name: 'queryFlag', type: 'str', default: '', help: '查询标记(可选)' },
71
+ { name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
72
+ ],
73
+ columns: ['dataId', 'formId', 'addTime', 'updateTime', 'data', 'code', 'msg'],
74
+ func: async function (kwargs) {
75
+ const debug = Boolean(kwargs.debug);
76
+ const { corpid, token, baseUrl, userId } = getRuntimeConfig();
77
+ const payload = buildPayload(kwargs, corpid);
78
+ const body = JSON.stringify(payload);
79
+
80
+ const validationError = getValidationError(payload, token);
81
+ if (validationError) return makeErrorRow(validationError.code, validationError.msg);
82
+
83
+ const sign = crypto.createHash('sha256').update(body + token).digest('hex');
84
+ const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, userId ? { userId } : {});
85
+ const apiUrl = buildApiUrl(baseUrl, BUYER_INQUIRY_DETAIL_API_URL);
86
+ if (debug) {
87
+ process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
88
+ }
89
+ const resp = await fetch(apiUrl, { method: 'POST', headers, body });
90
+ if (!resp.ok) {
91
+ const responseText = await resp.text();
92
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
93
+ return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
94
+ }
95
+
96
+ const data = await resp.json();
97
+ const responseBody = JSON.stringify(data);
98
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
99
+ if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
100
+
101
+ const result = data.result || {};
102
+ return [{
103
+ dataId: result.dataId ?? result.id ?? payload.dataId,
104
+ formId: result.formId ?? '',
105
+ addTime: result.addTime ?? result.createTime ?? '',
106
+ updateTime: result.updateTime ?? '',
107
+ data: JSON.stringify(result.data ?? result),
108
+ code: data.code ?? '',
109
+ msg: data.msg ?? '',
110
+ }];
111
+ },
112
+ });
@@ -0,0 +1,142 @@
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 BUYER_INQUIRY_LIST_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/buyerInquiry/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
+ page: Number(String(kwargs.page ?? '') === '' ? 1 : kwargs.page),
40
+ pageSize: Number(String(kwargs.pageSize ?? '') === '' ? 20 : kwargs.pageSize),
41
+ };
42
+ }
43
+
44
+ function getValidationError(payload, token) {
45
+ if (!payload.corpid) {
46
+ return { code: 'NO_CORPID', msg: '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>' };
47
+ }
48
+ if (!token) {
49
+ return { code: 'NO_TOKEN', msg: MISSING_TOKEN_MESSAGE };
50
+ }
51
+ return null;
52
+ }
53
+
54
+ function makeErrorRow(code, msg) {
55
+ return [{
56
+ rank: '',
57
+ inquiryId: '',
58
+ inquiryNo: '',
59
+ buyerName: '',
60
+ status: '',
61
+ createTime: '',
62
+ data: '',
63
+ code,
64
+ msg,
65
+ }];
66
+ }
67
+
68
+ function makeSuccessRows(list) {
69
+ return list.map((item, index) => ({
70
+ rank: index + 1,
71
+ inquiryId: item.inquiryId ?? item.dataId ?? item.id ?? '',
72
+ inquiryNo: item.inquiryNo ?? item.no ?? item.serialNo ?? '',
73
+ buyerName: item.buyerName ?? item.customerName ?? item.name ?? '',
74
+ status: item.status ?? item.state ?? '',
75
+ createTime: item.createTime ?? item.addTime ?? item.updateTime ?? '',
76
+ data: JSON.stringify(item),
77
+ code: '',
78
+ msg: '',
79
+ }));
80
+ }
81
+
82
+ cli({
83
+ site: 'xbb',
84
+ name: 'buyer-inquiry-list',
85
+ description: '采购询价列表接口(businessType: 5900)',
86
+ strategy: Strategy.PUBLIC,
87
+ access: 'read',
88
+ browser: false,
89
+ domain: 'proapi.xbongbong.com',
90
+ args: [
91
+ { name: 'page', type: 'str', default: '1', help: '页码' },
92
+ { name: 'pageSize', type: 'str', default: '20', help: '每页数量' },
93
+ { name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
94
+ { name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
95
+ ],
96
+ columns: ['rank', 'inquiryId', 'inquiryNo', 'buyerName', 'status', 'createTime', 'data', 'code', 'msg'],
97
+ footerExtra: () => (lastPagination ? `totalCount ${lastPagination.totalCount} / totalPage ${lastPagination.totalPage}` : undefined),
98
+ func: async function (kwargs) {
99
+ const debug = Boolean(kwargs.debug);
100
+ const { corpid, token, baseUrl, userId } = getRuntimeConfig();
101
+ const payload = buildPayload(kwargs, corpid);
102
+ const body = JSON.stringify(payload);
103
+
104
+ const validationError = getValidationError(payload, token);
105
+ if (validationError) {
106
+ return makeErrorRow(validationError.code, validationError.msg);
107
+ }
108
+
109
+ const sign = crypto.createHash('sha256').update(body + token).digest('hex');
110
+ const headers = Object.assign({
111
+ 'Content-Type': 'application/json;charset=UTF-8',
112
+ sign,
113
+ }, userId ? { userId } : {});
114
+ const apiUrl = buildApiUrl(baseUrl, BUYER_INQUIRY_LIST_API_URL);
115
+ if (debug) {
116
+ process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
117
+ }
118
+ const resp = await fetch(apiUrl, { method: 'POST', headers, body });
119
+ if (!resp.ok) {
120
+ const responseText = await resp.text();
121
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
122
+ return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
123
+ }
124
+
125
+ const data = await resp.json();
126
+ lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
127
+ ? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
128
+ : null;
129
+ const responseBody = JSON.stringify(data);
130
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
131
+ if (kwargs.raw) return [{ raw: responseBody }];
132
+ if (data.code !== 1) {
133
+ return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
134
+ }
135
+
136
+ const list = Array.isArray(data.result?.list) ? data.result.list : [];
137
+ if (!list.length) {
138
+ return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
139
+ }
140
+ return makeSuccessRows(list);
141
+ },
142
+ });
@@ -0,0 +1,86 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import crypto from 'node:crypto';
5
+ import { cli, Strategy } from './xbb-registry.js';
6
+
7
+ const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
8
+ const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/clue/addCoUser';
9
+ const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
10
+ const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
11
+
12
+ function readConfig() {
13
+ try {
14
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
15
+ } catch {
16
+ return {};
17
+ }
18
+ }
19
+
20
+ function getRuntimeConfig() {
21
+ const config = readConfig();
22
+ return {
23
+ corpid: String(config.corpid || '').trim(),
24
+ token: String(config.token || '').trim(),
25
+ baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
26
+ userId: String(config.userId || '').trim(),
27
+ };
28
+ }
29
+
30
+ function buildApiUrl(baseUrl, apiUrl) {
31
+ const apiPath = new URL(apiUrl).pathname;
32
+ return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
33
+ }
34
+
35
+ function makeErrorRow(code, msg) {
36
+ return [{ resultCode: '', resultMsg: '', messageList: '', code, msg }];
37
+ }
38
+
39
+ cli({
40
+ site: 'xbb',
41
+ name: 'clue-add-couser',
42
+ description: '线索添加协同人接口(businessType: 8000)',
43
+ strategy: Strategy.PUBLIC,
44
+ access: 'write',
45
+ browser: false,
46
+ domain: 'proapi.xbongbong.com',
47
+ args: [
48
+ { name: 'dataId', type: 'int', help: '线索id(必填)' },
49
+ { name: 'businessUserIdList', type: 'str', help: '需添加的协同人id列表,JSON数组字符串(必填)' },
50
+ { name: 'mainUserId', type: 'str', default: '', help: '团队负责人id(可选)' },
51
+ { name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
52
+ { name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
53
+ ],
54
+ columns: ['resultCode', 'resultMsg', 'messageList', 'code', 'msg'],
55
+ func: async (kwargs) => {
56
+ const debug = Boolean(kwargs.debug);
57
+ const { corpid, token, baseUrl, userId } = getRuntimeConfig();
58
+ const payload = { dataId: Number(kwargs.dataId || 0), corpid };
59
+ if (kwargs.userId) payload.userId = String(kwargs.userId);
60
+ if (String(kwargs.mainUserId || '').trim()) payload.mainUserId = String(kwargs.mainUserId);
61
+ let businessUserIdList;
62
+ try {
63
+ businessUserIdList = JSON.parse(String(kwargs.businessUserIdList || ''));
64
+ } catch {
65
+ businessUserIdList = null;
66
+ }
67
+ if (Array.isArray(businessUserIdList)) payload.businessUserIdList = businessUserIdList;
68
+ const requestBody = JSON.stringify(payload);
69
+ if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
70
+ if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
71
+ if (!Array.isArray(businessUserIdList) || !businessUserIdList.length) return makeErrorRow('NO_USERIDLIST', '缺少 --businessUserIdList 或格式不正确,需为JSON数组');
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 }, userId ? { userId } : {});
75
+ if (debug) {
76
+ process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
77
+ }
78
+ const resp = await fetch(buildApiUrl(baseUrl, API_URL), { method: 'POST', headers, body: requestBody });
79
+ if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
80
+ const data = await resp.json();
81
+ const responseBody = JSON.stringify(data);
82
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
83
+ if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
84
+ return [{ resultCode: data.code ?? '', resultMsg: data.msg || '', messageList: JSON.stringify(data.result?.messageList || []), code: data.code ?? '', msg: data.msg || '' }];
85
+ },
86
+ });
package/clue-add.js ADDED
@@ -0,0 +1,102 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { cli, Strategy } from './xbb-registry.js';
6
+
7
+ const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
8
+ const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/clue/add';
9
+ const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
10
+ const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
11
+
12
+ function readConfig() {
13
+ try {
14
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
15
+ } catch {
16
+ return {};
17
+ }
18
+ }
19
+
20
+ function getRuntimeConfig() {
21
+ const config = readConfig();
22
+ return {
23
+ corpid: String(config.corpid || '').trim(),
24
+ token: String(config.token || '').trim(),
25
+ baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
26
+ userId: String(config.userId || '').trim(),
27
+ };
28
+ }
29
+
30
+ function buildApiUrl(baseUrl, apiUrl) {
31
+ const apiPath = new URL(apiUrl).pathname;
32
+ return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
33
+ }
34
+
35
+ function parseDataList(raw) {
36
+ if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
37
+ return raw;
38
+ }
39
+ const text = String(raw || '').trim();
40
+ if (!text) {
41
+ return null;
42
+ }
43
+ try {
44
+ const parsed = JSON.parse(text);
45
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
46
+ return parsed;
47
+ }
48
+ return undefined;
49
+ } catch {
50
+ return undefined;
51
+ }
52
+ }
53
+
54
+ function makeErrorRow(code, msg) {
55
+ return [{ dataId: '', resultCode: '', resultMsg: '', code, msg }];
56
+ }
57
+
58
+ cli({
59
+ site: 'xbb',
60
+ name: 'clue-add',
61
+ description: '新建线索接口(businessType: 8000;formId必填)',
62
+ strategy: Strategy.PUBLIC,
63
+ access: 'write',
64
+ browser: false,
65
+ domain: 'proapi.xbongbong.com',
66
+ args: [
67
+ { name: 'formId', type: 'int', help: '表单模板id(必填)' },
68
+ { name: 'dataList', type: 'str', help: '线索数据JSON字符串(必填)' },
69
+ { name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
70
+ { name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
71
+ ],
72
+ columns: ['dataId', 'resultCode', 'resultMsg', 'code', 'msg'],
73
+ func: async function (kwargs) {
74
+ const debug = Boolean(kwargs.debug);
75
+ const { corpid, token, baseUrl, userId } = getRuntimeConfig();
76
+ const parsedDataList = parseDataList(kwargs.dataList);
77
+ const payload = { corpid, formId: Number(kwargs.formId || 0) };
78
+ const runtimeUserId = String(kwargs.userId || userId || '').trim();
79
+ if (runtimeUserId) payload.userId = runtimeUserId;
80
+ if (parsedDataList) payload.dataList = parsedDataList;
81
+ const requestBody = JSON.stringify(payload);
82
+ if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
83
+ if (!payload.formId) return makeErrorRow('NO_FORMID', '缺少 --formId');
84
+ if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
85
+ if (parsedDataList === null) return makeErrorRow('NO_DATALIST', '缺少 --dataList');
86
+ if (parsedDataList === undefined) return makeErrorRow('INVALID_DATALIST', '--dataList 必须是 JSON 对象字符串');
87
+ const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
88
+ const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
89
+ const apiUrl = buildApiUrl(baseUrl, API_URL);
90
+ if (debug) {
91
+ process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
92
+ }
93
+ const resp = await fetch(apiUrl, { method: 'POST', headers, body: requestBody });
94
+ if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
95
+ const data = await resp.json();
96
+ const responseBody = JSON.stringify(data);
97
+ if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
98
+ if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
99
+ const result = data.result || {};
100
+ return [{ dataId: result.dataId || '', resultCode: result.code ?? '', resultMsg: result.msg || '', code: data.code ?? '', msg: data.msg || '' }];
101
+ },
102
+ });
package/clue-back.js ADDED
@@ -0,0 +1,82 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import crypto from 'node:crypto';
5
+ import { cli, Strategy } from './xbb-registry.js';
6
+
7
+ const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
8
+ const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/clue/back';
9
+ const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
10
+ const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
11
+
12
+ function readConfig() {
13
+ try {
14
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
15
+ } catch {
16
+ return {};
17
+ }
18
+ }
19
+
20
+ function getRuntimeConfig() {
21
+ const config = readConfig();
22
+ return {
23
+ corpid: String(config.corpid || '').trim(),
24
+ token: String(config.token || '').trim(),
25
+ baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
26
+ userId: String(config.userId || '').trim(),
27
+ };
28
+ }
29
+
30
+ function buildApiUrl(baseUrl, apiUrl) {
31
+ const apiPath = new URL(apiUrl).pathname;
32
+ return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
33
+ }
34
+
35
+ function makeErrorRow(code, msg) {
36
+ return [{ resultType: '', resultMsg: '', code, msg }];
37
+ }
38
+
39
+ cli({
40
+ site: 'xbb',
41
+ name: 'clue-back',
42
+ description: '线索退回公海接口(businessType: 8000)',
43
+ strategy: Strategy.PUBLIC,
44
+ access: 'write',
45
+ browser: false,
46
+ domain: 'proapi.xbongbong.com',
47
+ args: [
48
+ { name: 'dataIdList', type: 'str', help: '线索id列表,JSON数组字符串(必填)' },
49
+ { name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
50
+ { name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
51
+ ],
52
+ columns: ['resultType', 'resultMsg', 'code', 'msg'],
53
+ func: async (kwargs) => {
54
+ const debug = Boolean(kwargs.debug);
55
+ const { corpid, token, baseUrl, userId } = getRuntimeConfig();
56
+ const payload = { corpid };
57
+ if (kwargs.userId) payload.userId = String(kwargs.userId);
58
+ let dataIdList;
59
+ try {
60
+ dataIdList = JSON.parse(String(kwargs.dataIdList || ''));
61
+ } catch {
62
+ dataIdList = null;
63
+ }
64
+ if (Array.isArray(dataIdList)) payload.dataIdList = dataIdList;
65
+ const requestBody = JSON.stringify(payload);
66
+ if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
67
+ if (!Array.isArray(dataIdList) || !dataIdList.length) return makeErrorRow('NO_DATAIDLIST', '缺少 --dataIdList 或格式不正确,需为JSON数组');
68
+ if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
69
+ const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
70
+ const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, userId ? { userId } : {});
71
+ if (debug) {
72
+ process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
73
+ }
74
+ const resp = await fetch(buildApiUrl(baseUrl, API_URL), { method: 'POST', headers, body: requestBody });
75
+ if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
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
+ return [{ resultType: data.result?.resultType || '', resultMsg: data.result?.resultMsg || '', code: data.code ?? '', msg: data.msg || '' }];
81
+ },
82
+ });