@xbongbong/xbbcli 2.4.4 → 2.4.6

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 (258) hide show
  1. package/README.md +15 -4
  2. package/business-info-detail.js +126 -0
  3. package/business-info-search.js +95 -0
  4. package/buyer-inquiry-detail.js +16 -47
  5. package/buyer-inquiry-list.js +18 -56
  6. package/clue-add-couser.js +14 -39
  7. package/clue-add.js +15 -41
  8. package/clue-back.js +14 -39
  9. package/clue-del.js +14 -39
  10. package/clue-delete-couser.js +14 -39
  11. package/clue-delete-mainuser.js +14 -39
  12. package/clue-detail.js +15 -40
  13. package/clue-distribution.js +14 -43
  14. package/clue-edit.js +15 -41
  15. package/clue-handover.js +15 -45
  16. package/clue-list.js +18 -61
  17. package/clue-thorough-delete.js +14 -39
  18. package/communicate-add.js +15 -56
  19. package/communicate-del.js +17 -59
  20. package/communicate-detail.js +15 -56
  21. package/communicate-edit.js +15 -56
  22. package/communicate-list.js +18 -63
  23. package/communicate-plan-add.js +16 -42
  24. package/communicate-plan-cancel.js +14 -40
  25. package/communicate-plan-del.js +14 -40
  26. package/communicate-plan-detail.js +15 -41
  27. package/communicate-plan-list.js +18 -46
  28. package/communicate-plan-single-operate.js +14 -39
  29. package/contact-add-couser.js +14 -39
  30. package/contact-add-mainuser.js +14 -39
  31. package/contact-add.js +15 -51
  32. package/contact-del.js +15 -38
  33. package/contact-delete-couser.js +14 -39
  34. package/contact-delete-mainuser.js +14 -39
  35. package/contact-detail.js +15 -38
  36. package/contact-edit.js +14 -47
  37. package/contact-handover.js +14 -39
  38. package/contact-list.js +37 -61
  39. package/contract-add-couser.js +16 -58
  40. package/contract-add-mainuser.js +16 -58
  41. package/contract-add.js +15 -57
  42. package/contract-del.js +17 -58
  43. package/contract-delete-couser.js +16 -57
  44. package/contract-delete-mainuser.js +16 -58
  45. package/contract-detail.js +15 -57
  46. package/contract-edit.js +15 -57
  47. package/contract-handover.js +15 -56
  48. package/contract-list.js +18 -61
  49. package/contract-outstock-add.js +15 -46
  50. package/contract-outstock-del.js +15 -41
  51. package/contract-outstock-detail.js +15 -41
  52. package/contract-outstock-edit.js +15 -46
  53. package/contract-outstock-list.js +18 -46
  54. package/customer-add-couser.js +13 -54
  55. package/customer-add.js +15 -58
  56. package/customer-back.js +15 -57
  57. package/customer-del.js +17 -58
  58. package/customer-delete-couser.js +16 -57
  59. package/customer-delete-mainuser.js +16 -58
  60. package/customer-detail.js +13 -54
  61. package/customer-distribution.js +15 -57
  62. package/customer-edit.js +13 -53
  63. package/customer-handover.js +15 -56
  64. package/customer-invoice-address-add.js +15 -41
  65. package/customer-invoice-address-edit.js +15 -40
  66. package/customer-invoice-address.js +17 -42
  67. package/customer-invoice-info-add.js +15 -41
  68. package/customer-invoice-info-edit.js +15 -40
  69. package/customer-invoice-info.js +17 -42
  70. package/customer-list.js +18 -61
  71. package/department-add.js +14 -39
  72. package/department-del.js +14 -40
  73. package/department-edit.js +14 -39
  74. package/department-list.js +17 -59
  75. package/form-data-add-couser.js +14 -39
  76. package/form-data-add-mainuser.js +14 -39
  77. package/form-data-add.js +13 -54
  78. package/form-data-del.js +13 -53
  79. package/form-data-delete-couser.js +14 -40
  80. package/form-data-delete-mainuser.js +14 -39
  81. package/form-data-detail.js +13 -54
  82. package/form-data-edit.js +13 -54
  83. package/form-data-handover.js +14 -39
  84. package/form-data-list.js +37 -63
  85. package/form-get.js +13 -53
  86. package/form-list.js +19 -66
  87. package/hkh-call-add-task.js +14 -44
  88. package/hkh-word-list.js +16 -44
  89. package/invoice-add.js +15 -45
  90. package/invoice-cancel.js +14 -44
  91. package/invoice-del.js +15 -45
  92. package/invoice-detail.js +15 -45
  93. package/invoice-edit.js +15 -45
  94. package/invoice-get-amount-detail.js +14 -44
  95. package/invoice-list.js +18 -50
  96. package/invoice-red.js +15 -45
  97. package/label-add.js +14 -44
  98. package/label-all-list.js +16 -44
  99. package/label-batch-add.js +14 -44
  100. package/label-batch-remove.js +14 -44
  101. package/label-del-completely.js +14 -44
  102. package/label-del.js +15 -45
  103. package/label-edit.js +14 -44
  104. package/label-group-add.js +15 -45
  105. package/label-group-del.js +15 -45
  106. package/label-group-list.js +16 -44
  107. package/label-group-update.js +15 -45
  108. package/label-list.js +16 -44
  109. package/label-reduction.js +15 -45
  110. package/label-repeat.js +15 -45
  111. package/market-activity-add.js +14 -49
  112. package/market-activity-del.js +15 -46
  113. package/market-activity-detail.js +15 -45
  114. package/market-activity-edit.js +15 -46
  115. package/market-activity-handover.js +14 -40
  116. package/market-activity-list.js +18 -46
  117. package/opportunity-add-couser.js +16 -58
  118. package/opportunity-add-mainuser.js +16 -58
  119. package/opportunity-add.js +15 -56
  120. package/opportunity-del.js +17 -59
  121. package/opportunity-delete-couser.js +16 -58
  122. package/opportunity-delete-mainuser.js +16 -57
  123. package/opportunity-detail.js +15 -58
  124. package/opportunity-edit.js +15 -56
  125. package/opportunity-handover.js +15 -57
  126. package/opportunity-list.js +40 -65
  127. package/orginal-text-list.js +16 -61
  128. package/package.json +8 -1
  129. package/pay-plan-add-couser.js +14 -41
  130. package/pay-plan-add-mainuser.js +14 -41
  131. package/pay-plan-add.js +15 -46
  132. package/pay-plan-delete-couser.js +14 -40
  133. package/pay-plan-delete-mainuser.js +14 -40
  134. package/pay-plan-handover.js +14 -40
  135. package/pay-sheet-add-bad.js +15 -46
  136. package/pay-sheet-add-couser.js +14 -40
  137. package/pay-sheet-add-mainuser.js +14 -41
  138. package/pay-sheet-add-red.js +15 -46
  139. package/pay-sheet-add-write-off.js +15 -46
  140. package/pay-sheet-del.js +14 -48
  141. package/pay-sheet-delete-couser.js +14 -40
  142. package/pay-sheet-delete-mainuser.js +14 -41
  143. package/pay-sheet-detail.js +15 -46
  144. package/pay-sheet-edit-bad.js +14 -49
  145. package/pay-sheet-edit-red.js +14 -49
  146. package/pay-sheet-edit-write-off.js +15 -46
  147. package/pay-sheet-get-amount-detail.js +14 -44
  148. package/pay-sheet-list.js +18 -46
  149. package/payment-add-couser.js +16 -58
  150. package/payment-add-mainuser.js +16 -58
  151. package/payment-add.js +15 -56
  152. package/payment-del.js +17 -58
  153. package/payment-delete-couser.js +16 -57
  154. package/payment-delete-mainuser.js +16 -57
  155. package/payment-detail.js +15 -56
  156. package/payment-edit.js +15 -56
  157. package/payment-handover.js +15 -57
  158. package/payment-list.js +37 -61
  159. package/payment-sheet-add-bad-debt.js +15 -57
  160. package/payment-sheet-add-pre.js +15 -46
  161. package/payment-sheet-add-red.js +15 -57
  162. package/payment-sheet-add-write-off.js +15 -52
  163. package/payment-sheet-del.js +17 -53
  164. package/payment-sheet-detail.js +15 -52
  165. package/payment-sheet-edit-bad-debt.js +15 -51
  166. package/payment-sheet-edit-red.js +15 -56
  167. package/payment-sheet-edit-write-off.js +15 -56
  168. package/payment-sheet-get-amount-detail.js +14 -45
  169. package/payment-sheet-handover.js +14 -40
  170. package/payment-sheet-list.js +37 -60
  171. package/product-add.js +15 -51
  172. package/product-category-add.js +13 -48
  173. package/product-category-del.js +13 -53
  174. package/product-category-list.js +17 -60
  175. package/product-category-update.js +13 -54
  176. package/product-del.js +17 -53
  177. package/product-detail.js +13 -54
  178. package/product-edit.js +15 -51
  179. package/product-list.js +37 -63
  180. package/product-online.js +14 -44
  181. package/quotation-add-couser.js +15 -45
  182. package/quotation-add-mainuser.js +15 -45
  183. package/quotation-add.js +15 -45
  184. package/quotation-del.js +15 -45
  185. package/quotation-delete-couser.js +15 -45
  186. package/quotation-delete-mainuser.js +15 -45
  187. package/quotation-detail.js +15 -45
  188. package/quotation-edit.js +15 -45
  189. package/quotation-handover.js +14 -39
  190. package/quotation-list.js +18 -50
  191. package/refund-add.js +15 -39
  192. package/refund-del.js +15 -38
  193. package/refund-detail.js +15 -39
  194. package/refund-edit.js +15 -39
  195. package/refund-list.js +37 -61
  196. package/role-list.js +18 -46
  197. package/sign-in-list.js +21 -49
  198. package/stage-get.js +16 -42
  199. package/stage-jump.js +15 -49
  200. package/supplier-add.js +15 -57
  201. package/token-del.js +1 -1
  202. package/token-list.js +20 -1
  203. package/token-set.js +1 -1
  204. package/token-use.js +2 -35
  205. package/user-add.js +14 -39
  206. package/user-del.js +14 -40
  207. package/user-edit.js +14 -40
  208. package/user-handover.js +14 -40
  209. package/user-list.js +16 -62
  210. package/work-order-add.js +13 -54
  211. package/work-order-asset-add-couser.js +15 -45
  212. package/work-order-asset-add-mainuser.js +15 -45
  213. package/work-order-asset-add.js +15 -45
  214. package/work-order-asset-del-couser.js +15 -45
  215. package/work-order-asset-del-mainuser.js +15 -45
  216. package/work-order-asset-del.js +15 -45
  217. package/work-order-asset-detail.js +15 -45
  218. package/work-order-asset-edit.js +15 -45
  219. package/work-order-asset-handover.js +15 -45
  220. package/work-order-asset-list.js +18 -50
  221. package/work-order-del.js +13 -54
  222. package/work-order-detail.js +13 -53
  223. package/work-order-dynamic-list.js +18 -56
  224. package/work-order-edit.js +13 -54
  225. package/work-order-list.js +17 -59
  226. package/work-order-operate.js +13 -54
  227. package/work-order-template-detail.js +13 -54
  228. package/work-order-template-list.js +17 -60
  229. package/work-report-daily-add.js +14 -39
  230. package/work-report-daily-del.js +14 -39
  231. package/work-report-daily-detail.js +15 -40
  232. package/work-report-daily-edit.js +17 -52
  233. package/work-report-daily-get-work-plan.js +14 -40
  234. package/work-report-daily-list.js +18 -45
  235. package/work-report-monthly-add.js +14 -40
  236. package/work-report-monthly-del.js +14 -43
  237. package/work-report-monthly-detail.js +15 -40
  238. package/work-report-monthly-edit.js +15 -40
  239. package/work-report-monthly-list.js +18 -45
  240. package/work-report-weekly-add.js +14 -40
  241. package/work-report-weekly-del.js +14 -40
  242. package/work-report-weekly-detail.js +15 -41
  243. package/work-report-weekly-edit.js +15 -41
  244. package/work-report-weekly-list.js +18 -45
  245. package/work-task-add-couser.js +14 -43
  246. package/work-task-add.js +15 -41
  247. package/work-task-delete-couser.js +14 -40
  248. package/work-task-detail.js +15 -40
  249. package/work-task-edit.js +14 -39
  250. package/work-task-handover.js +14 -40
  251. package/workorder-add-couser.js +16 -57
  252. package/workorder-delete-couser.js +16 -58
  253. package/workorder-handover.js +17 -58
  254. package/workorderlist.js +38 -60
  255. package/workorderproductlist.js +18 -59
  256. package/worktimerecorddetail.js +13 -54
  257. package/worktimerecordlist.js +18 -59
  258. package/xbb-http.js +71 -0
@@ -1,33 +1,7 @@
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
1
  import { cli, Strategy } from './xbb-registry.js';
6
- import { readActiveConfig } from './xbb-config.js';
2
+ import { getRuntimeConfig, requestGateway } from './xbb-http.js';
7
3
 
8
- const CONFIG_DIR = path.join(os.homedir(), '.xbbcli');
9
- const CONFIG_FILE = path.join(CONFIG_DIR, 'config.env');
10
- const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/paymentSheet/editWriteOff';
11
- const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
12
-
13
- function readConfig() {
14
- return readActiveConfig();
15
- }
16
-
17
- function getRuntimeConfig() {
18
- const config = readConfig();
19
- return {
20
- corpid: String(config.corpid || '').trim(),
21
- token: String(config.token || '').trim(),
22
- baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
23
- userId: String(config.userId || '').trim(),
24
- };
25
- }
26
-
27
- function buildApiUrl(baseUrl, defaultUrl) {
28
- const apiPath = new URL(defaultUrl).pathname;
29
- return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
30
- }
4
+ const API_PATH = '/pro/v2/api/paymentSheet/editWriteOff';
31
5
 
32
6
  function makeErrorRow(code, msg) {
33
7
  return [{
@@ -86,7 +60,6 @@ cli({
86
60
  payload.dataList = parsedDataList;
87
61
  }
88
62
 
89
- const body = JSON.stringify(payload);
90
63
 
91
64
  if (!payload.corpid) {
92
65
  return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
@@ -104,40 +77,26 @@ cli({
104
77
  return makeErrorRow('INVALID_DATALIST', '--dataList 必须是 JSON 对象字符串');
105
78
  }
106
79
 
107
- const sign = crypto.createHash('sha256').update(body + token).digest('hex');
108
- const headers = Object.assign({
109
- 'Content-Type': 'application/json;charset=UTF-8',
110
- sign,
111
- }, userId ? { userId } : {});
112
- if (debug) {
113
- process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
114
- }
115
- const resp = await fetch(buildApiUrl(baseUrl, API_URL), {
116
- method: 'POST',
117
- headers,
118
- body,
80
+ const gateway = await requestGateway({
81
+ baseUrl,
82
+ apiPath: API_PATH,
83
+ payload,
84
+ token,
85
+ userId,
86
+ debug,
119
87
  });
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 ?? '未知错误');
88
+ if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
89
+ if (gateway.data.code !== 1) {
90
+ return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
132
91
  }
133
92
 
134
- const result = data.result || {};
93
+ const result = gateway.data.result || {};
135
94
  return [{
136
95
  dataId: result.dataId || '',
137
96
  resultCode: result.code ?? '',
138
97
  resultMsg: result.msg || '',
139
- code: data.code ?? '',
140
- msg: data.msg || '',
98
+ code: gateway.data.code ?? '',
99
+ msg: gateway.data.msg || '',
141
100
  }];
142
101
  },
143
102
  });
@@ -1,33 +1,7 @@
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
1
  import { cli, Strategy } from './xbb-registry.js';
6
- import { readActiveConfig } from './xbb-config.js';
2
+ import { getRuntimeConfig, requestGateway } from './xbb-http.js';
7
3
 
8
- const CONFIG_DIR = path.join(os.homedir(), '.xbbcli');
9
- const CONFIG_FILE = path.join(CONFIG_DIR, 'config.env');
10
- const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/paymentSheet/getAmountDetail';
11
- const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
12
-
13
- function readConfig() {
14
- return readActiveConfig();
15
- }
16
-
17
- function getRuntimeConfig() {
18
- const config = readConfig();
19
- return {
20
- corpid: String(config.corpid || '').trim(),
21
- token: String(config.token || '').trim(),
22
- baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
23
- userId: String(config.userId || '').trim(),
24
- };
25
- }
26
-
27
- function buildApiUrl(baseUrl, defaultUrl) {
28
- const apiPath = new URL(defaultUrl).pathname;
29
- return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
30
- }
4
+ const API_PATH = '/pro/v2/api/paymentSheet/getAmountDetail';
31
5
 
32
6
  function makeErrorRow(code, msg) {
33
7
  return [{ rank: '', amountDetail: '', code, msg }];
@@ -53,28 +27,23 @@ cli({
53
27
  const payload = { corpid, dataId: Number(kwargs.dataId || 0) };
54
28
  if (kwargs.userId) payload.userId = String(kwargs.userId);
55
29
 
56
- const body = JSON.stringify(payload);
57
30
  if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
58
31
  if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
59
32
  if (!token) return makeErrorRow('NO_TOKEN', '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
60
33
 
61
- const sign = crypto.createHash('sha256').update(body + token).digest('hex');
62
- const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, userId ? { userId } : {});
63
- const apiUrl = buildApiUrl(baseUrl, API_URL);
64
- if (debug) {
65
- process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
66
- }
67
- const resp = await fetch(apiUrl, {
68
- method: 'POST',
69
- headers,
70
- body,
34
+ const gateway = await requestGateway({
35
+ baseUrl,
36
+ apiPath: API_PATH,
37
+ payload,
38
+ token,
39
+ userId,
40
+ debug,
71
41
  });
72
- if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
73
- const data = await resp.json();
74
- const responseBody = JSON.stringify(data);
75
- if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
76
- if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
77
- const amountDetail = Array.isArray(data.result?.amountDetail) ? data.result.amountDetail : [];
42
+ if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
43
+ if (gateway.data.code !== 1) {
44
+ return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
45
+ }
46
+ const amountDetail = Array.isArray(gateway.data.result?.amountDetail) ? gateway.data.result.amountDetail : [];
78
47
  if (!amountDetail.length) return makeErrorRow('NO_DATA', '接口成功,但 amountDetail 为空');
79
48
  return amountDetail.map((item, index) => ({ rank: index + 1, amountDetail: JSON.stringify(item || {}), code: '', msg: '' }));
80
49
  },
@@ -1,34 +1,9 @@
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
1
  import { cli, Strategy } from './xbb-registry.js';
6
- import { readActiveConfig } from './xbb-config.js';
2
+ import { getRuntimeConfig, requestGateway } from './xbb-http.js';
7
3
 
8
- const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
9
- const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/paymentSheet/handover';
10
- const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
4
+ const API_PATH = '/pro/v2/api/paymentSheet/handover';
11
5
  const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
12
6
 
13
- function readConfig() {
14
- return readActiveConfig();
15
- }
16
-
17
- function getRuntimeConfig() {
18
- const config = readConfig();
19
- return {
20
- corpid: String(config.corpid || '').trim(),
21
- token: String(config.token || '').trim(),
22
- baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
23
- userId: String(config.userId || '').trim(),
24
- };
25
- }
26
-
27
- function buildApiUrl(baseUrl, defaultUrl) {
28
- const apiPath = new URL(defaultUrl).pathname;
29
- return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
30
- }
31
-
32
7
  function makeErrorRow(code, msg) {
33
8
  return [{ resultType: '', resultMsg: '', code, msg }];
34
9
  }
@@ -60,23 +35,22 @@ cli({
60
35
  dataIdList = null;
61
36
  }
62
37
  if (Array.isArray(dataIdList)) payload.dataIdList = dataIdList;
63
- const body = JSON.stringify(payload);
64
38
  if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
65
39
  if (!Array.isArray(dataIdList) || !dataIdList.length) return makeErrorRow('NO_DATAIDLIST', '缺少 --dataIdList 或格式不正确,需为JSON数组');
66
40
  if (!payload.businessUserId) return makeErrorRow('NO_BUSINESSUSERID', '缺少 --businessUserId');
67
41
  if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
68
- const sign = crypto.createHash('sha256').update(body + token).digest('hex');
69
- const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, userId ? { userId } : {});
70
- const apiUrl = buildApiUrl(baseUrl, API_URL);
71
- if (debug) {
72
- process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
42
+ const gateway = await requestGateway({
43
+ baseUrl,
44
+ apiPath: API_PATH,
45
+ payload,
46
+ token,
47
+ userId,
48
+ debug,
49
+ });
50
+ if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
51
+ if (gateway.data.code !== 1) {
52
+ return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
73
53
  }
74
- const resp = await fetch(apiUrl, { method: 'POST', headers, body });
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 || '' }];
54
+ return [{ resultType: gateway.data.result?.resultType || '', resultMsg: gateway.data.result?.resultMsg || '', code: gateway.data.code ?? '', msg: gateway.data.msg || '' }];
81
55
  },
82
56
  });
@@ -1,36 +1,20 @@
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
1
  import { cli, Strategy } from './xbb-registry.js';
6
- import { readActiveConfig } from './xbb-config.js';
2
+ import { getRuntimeConfig, requestGateway, createPagination } from './xbb-http.js';
7
3
 
8
- const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
9
- const PAYMENT_SHEET_LIST_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/paymentSheet/list';
10
- const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
4
+ const PAYMENT_SHEET_LIST_API_PATH = '/pro/v2/api/paymentSheet/list';
11
5
  const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
12
- let lastPagination = null;
13
-
14
- function readConfig() {
15
- return readActiveConfig();
16
- }
17
-
18
- function getRuntimeConfig() {
19
- const config = readConfig();
20
- return {
21
- corpid: String(config.corpid || '').trim(),
22
- token: String(config.token || '').trim(),
23
- baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
24
- userId: String(config.userId || '').trim(),
25
- };
26
- }
27
-
28
- function buildApiUrl(baseUrl, defaultUrl) {
29
- const apiPath = new URL(defaultUrl).pathname;
30
- return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
31
- }
6
+ const pagination = createPagination();
32
7
 
33
8
  function buildConditions(kwargs) {
9
+ const conditions = kwargs.conditions;
10
+ if (typeof conditions === 'string' && conditions.trim()) {
11
+ const parsed = JSON.parse(conditions);
12
+ if (!Array.isArray(parsed)) {
13
+ throw new Error('INVALID_CONDITIONS:conditions 必须是 JSON 数组');
14
+ }
15
+ return parsed;
16
+ }
17
+
34
18
  if (!(kwargs.attr && kwargs.value)) {
35
19
  return [];
36
20
  }
@@ -141,6 +125,7 @@ cli({
141
125
  { name: 'listGroupId', type: 'str', default: '', help: '分组类型(可选),如 110 红冲退款,111 坏账回款' },
142
126
  { name: 'subBusinessType', type: 'str', default: '', help: '业务子类型(可选),如 702 父回款单' },
143
127
  { name: 'viewApproval', type: 'str', default: '', help: '是否查询审批中数据,1是,0否' },
128
+ { name: 'conditions', type: 'str', default: '', help: '条件集合 JSON 数组字符串,优先级高于 --attr/--value' },
144
129
  { name: 'attr', type: 'str', default: '', help: '筛选字段 attr,例如 serialNo' },
145
130
  { name: 'value', type: 'str', default: '', help: '筛选值,和 --attr 配合使用' },
146
131
  { name: 'symbol', type: 'str', default: 'equal', help: '筛选操作符,默认 equal' },
@@ -150,50 +135,42 @@ cli({
150
135
  { name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
151
136
  ],
152
137
  columns: ['rank', 'dataId', 'formId', 'serialNo', 'customerIds', 'contractIds', 'receivableIds', 'receivedAmount', 'ownerId', 'creatorId', 'addTime', 'updateTime', 'data', 'code', 'msg'],
153
- footerExtra: () => (lastPagination ? `totalCount ${lastPagination.totalCount} / totalPage ${lastPagination.totalPage}` : undefined),
138
+ footerExtra: pagination.footerExtra,
154
139
  func: async function (kwargs) {
155
140
  const debug = Boolean(kwargs.debug);
156
141
  const { corpid, token, baseUrl, userId } = getRuntimeConfig();
157
- const payload = buildPayload(kwargs, corpid);
158
- const body = JSON.stringify(payload);
142
+ let payload;
143
+ try {
144
+ payload = buildPayload(kwargs, corpid);
145
+ } catch (error) {
146
+ const message = String(error?.message || error);
147
+ const separatorIndex = message.indexOf(':');
148
+ const code = separatorIndex > 0 ? message.slice(0, separatorIndex) : 'INVALID_PAYLOAD';
149
+ const detail = separatorIndex > 0 ? message.slice(separatorIndex + 1) : message;
150
+ return makeErrorRow(code, detail);
151
+ }
159
152
 
160
153
  const validationError = getValidationError(payload, token);
161
154
  if (validationError) {
162
155
  return makeErrorRow(validationError.code, validationError.msg);
163
156
  }
164
157
 
165
- const sign = crypto.createHash('sha256').update(body + token).digest('hex');
166
- const headers = Object.assign({
167
- 'Content-Type': 'application/json;charset=UTF-8',
168
- sign,
169
- }, userId ? { userId } : {});
170
- if (debug) {
171
- process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, PAYMENT_SHEET_LIST_API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
172
- }
173
- const resp = await fetch(buildApiUrl(baseUrl, PAYMENT_SHEET_LIST_API_URL), {
174
- method: 'POST',
175
- headers,
176
- body,
158
+ const gateway = await requestGateway({
159
+ baseUrl,
160
+ apiPath: PAYMENT_SHEET_LIST_API_PATH,
161
+ payload,
162
+ token,
163
+ userId,
164
+ debug,
177
165
  });
178
-
179
- if (!resp.ok) {
180
- const responseText = await resp.text();
181
- if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
182
- return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
183
- }
184
-
185
- const data = await resp.json();
186
- lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
187
- ? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
188
- : null;
189
- const responseBody = JSON.stringify(data);
190
- if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
191
- if (kwargs.raw) return [{ raw: responseBody }];
192
- if (data.code !== 1) {
193
- return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
166
+ if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
167
+ pagination.update(gateway.data);
168
+ if (kwargs.raw) return [{ raw: gateway.responseBody }];
169
+ if (gateway.data.code !== 1) {
170
+ return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
194
171
  }
195
172
 
196
- const list = Array.isArray(data.result?.list) ? data.result.list : [];
173
+ const list = Array.isArray(gateway.data.result?.list) ? gateway.data.result.list : [];
197
174
  if (!list.length) {
198
175
  return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
199
176
  }
package/product-add.js CHANGED
@@ -1,33 +1,7 @@
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
1
  import { cli, Strategy } from './xbb-registry.js';
6
- import { readActiveConfig } from './xbb-config.js';
2
+ import { getRuntimeConfig, requestGateway } from './xbb-http.js';
7
3
 
8
- const CONFIG_DIR = path.join(os.homedir(), '.xbbcli');
9
- const CONFIG_FILE = path.join(CONFIG_DIR, 'config.env');
10
- const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/product/add';
11
- const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
12
-
13
- function readConfig() {
14
- return readActiveConfig();
15
- }
16
-
17
- function getRuntimeConfig() {
18
- const config = readConfig();
19
- return {
20
- corpid: String(config.corpid || '').trim(),
21
- token: String(config.token || '').trim(),
22
- baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
23
- userId: String(config.userId || '').trim(),
24
- };
25
- }
26
-
27
- function buildApiUrl(baseUrl, defaultUrl) {
28
- const apiPath = new URL(defaultUrl).pathname;
29
- return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
30
- }
4
+ const API_PATH = '/pro/v2/api/product/add';
31
5
 
32
6
  function makeErrorRow(code, msg) {
33
7
  return [{
@@ -85,42 +59,32 @@ cli({
85
59
  payload.dataList = parsedDataList;
86
60
  }
87
61
 
88
- const body = JSON.stringify(payload);
89
62
 
90
63
  if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
91
64
  if (!token) return makeErrorRow('NO_TOKEN', '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
92
65
  if (parsedDataList === null) return makeErrorRow('NO_DATALIST', '缺少 --dataList');
93
66
  if (parsedDataList === undefined) return makeErrorRow('INVALID_DATALIST', '--dataList 必须是 JSON 对象字符串');
94
67
 
95
- const sign = crypto.createHash('sha256').update(body + token).digest('hex');
96
- const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
97
- if (debug) {
98
- process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
99
- }
100
- const resp = await fetch(buildApiUrl(baseUrl, API_URL), {
101
- method: 'POST',
102
- headers,
103
- body,
68
+ const gateway = await requestGateway({
69
+ baseUrl,
70
+ apiPath: API_PATH,
71
+ payload,
72
+ token,
73
+ userId: runtimeUserId,
74
+ debug,
104
75
  });
105
-
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}`);
76
+ if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
77
+ if (gateway.data.code !== 1) {
78
+ return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
110
79
  }
111
80
 
112
- const data = await resp.json();
113
- const responseBody = JSON.stringify(data);
114
- if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
115
- if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
116
-
117
- const result = data.result || {};
81
+ const result = gateway.data.result || {};
118
82
  return [{
119
83
  dataId: result.dataId || '',
120
84
  resultCode: result.code ?? '',
121
85
  resultMsg: result.msg || '',
122
- code: data.code ?? '',
123
- msg: data.msg || '',
86
+ code: gateway.data.code ?? '',
87
+ msg: gateway.data.msg || '',
124
88
  }];
125
89
  },
126
90
  });
@@ -1,34 +1,9 @@
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
1
  import { cli, Strategy } from './xbb-registry.js';
6
- import { readActiveConfig } from './xbb-config.js';
2
+ import { getRuntimeConfig, requestGateway } from './xbb-http.js';
7
3
 
8
- const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
9
- const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/product/categoryAdd';
10
- const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
4
+ const API_PATH = '/pro/v2/api/product/categoryAdd';
11
5
  const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
12
6
 
13
- function readConfig() {
14
- return readActiveConfig();
15
- }
16
-
17
- function getRuntimeConfig() {
18
- const config = readConfig();
19
- return {
20
- corpid: String(config.corpid || '').trim(),
21
- token: String(config.token || '').trim(),
22
- baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
23
- userId: String(config.userId || '').trim(),
24
- };
25
- }
26
-
27
- function buildApiUrl(baseUrl, defaultUrl) {
28
- const apiPath = new URL(defaultUrl).pathname;
29
- return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
30
- }
31
-
32
7
  function buildPayload(kwargs, corpid, runtimeUserId) {
33
8
  const payload = {
34
9
  corpid,
@@ -89,33 +64,23 @@ cli({
89
64
  const { corpid, token, baseUrl, userId } = getRuntimeConfig();
90
65
  const runtimeUserId = String(kwargs.userId || userId || '').trim();
91
66
  const payload = buildPayload(kwargs, corpid, runtimeUserId);
92
- const requestBody = JSON.stringify(payload);
93
67
 
94
68
  const validationError = getValidationError(payload, token);
95
69
  if (validationError) return makeErrorRow(validationError.code, validationError.msg);
96
70
 
97
- const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
98
- const headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', sign }, runtimeUserId ? { userId: runtimeUserId } : {});
99
- if (debug) {
100
- process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
101
- }
102
- const resp = await fetch(buildApiUrl(baseUrl, API_URL), {
103
- method: 'POST',
104
- headers,
105
- body: requestBody,
71
+ const gateway = await requestGateway({
72
+ baseUrl,
73
+ apiPath: API_PATH,
74
+ payload,
75
+ token,
76
+ userId: runtimeUserId,
77
+ debug,
106
78
  });
107
-
108
- if (!resp.ok) {
109
- const responseText = await resp.text();
110
- if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
111
- return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
79
+ if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
80
+ if (gateway.data.code !== 1) {
81
+ return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
112
82
  }
113
83
 
114
- const data = await resp.json();
115
- const responseBody = JSON.stringify(data);
116
- if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
117
- if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
118
-
119
- return makeSuccessRow(data);
84
+ return makeSuccessRow(gateway.data);
120
85
  },
121
86
  });
@@ -1,34 +1,9 @@
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
1
  import { cli, Strategy } from './xbb-registry.js';
6
- import { readActiveConfig } from './xbb-config.js';
2
+ import { getRuntimeConfig, requestGateway } from './xbb-http.js';
7
3
 
8
- const CONFIG_FILE = path.join(os.homedir(), '.xbbcli', 'config.env');
9
- const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/product/categoryDel';
10
- const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
4
+ const API_PATH = '/pro/v2/api/product/categoryDel';
11
5
  const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
12
6
 
13
- function readConfig() {
14
- return readActiveConfig();
15
- }
16
-
17
- function getRuntimeConfig() {
18
- const config = readConfig();
19
- return {
20
- corpid: String(config.corpid || '').trim(),
21
- token: String(config.token || '').trim(),
22
- baseUrl: String(config.baseurl || DEFAULT_BASE_URL).trim(),
23
- userId: String(config.userId || '').trim(),
24
- };
25
- }
26
-
27
- function buildApiUrl(baseUrl, defaultUrl) {
28
- const apiPath = new URL(defaultUrl).pathname;
29
- return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
30
- }
31
-
32
7
  function buildPayload(kwargs, corpid) {
33
8
  const payload = {
34
9
  corpid,
@@ -90,40 +65,25 @@ cli({
90
65
  const debug = Boolean(kwargs.debug);
91
66
  const { corpid, token, baseUrl, userId } = getRuntimeConfig();
92
67
  const payload = buildPayload(kwargs, corpid);
93
- const requestBody = JSON.stringify(payload);
94
68
 
95
69
  const validationError = getValidationError(payload, token);
96
70
  if (validationError) {
97
71
  return makeErrorRow(validationError.code, validationError.msg);
98
72
  }
99
73
 
100
- const sign = crypto.createHash('sha256').update(requestBody + token).digest('hex');
101
- const headers = Object.assign({
102
- 'Content-Type': 'application/json;charset=UTF-8',
103
- sign,
104
- }, userId ? { userId } : {});
105
- if (debug) {
106
- process.stderr.write(`[debug] URL: ${buildApiUrl(baseUrl, API_URL)}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
107
- }
108
- const resp = await fetch(buildApiUrl(baseUrl, API_URL), {
109
- method: 'POST',
110
- headers,
111
- body: requestBody,
74
+ const gateway = await requestGateway({
75
+ baseUrl,
76
+ apiPath: API_PATH,
77
+ payload,
78
+ token,
79
+ userId,
80
+ debug,
112
81
  });
113
-
114
- if (!resp.ok) {
115
- const responseText = await resp.text();
116
- if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
117
- return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
118
- }
119
-
120
- const data = await resp.json();
121
- const responseBody = JSON.stringify(data);
122
- if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
123
- if (data.code !== 1) {
124
- return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
82
+ if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
83
+ if (gateway.data.code !== 1) {
84
+ return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
125
85
  }
126
86
 
127
- return makeSuccessRow(payload, data);
87
+ return makeSuccessRow(payload, gateway.data);
128
88
  },
129
89
  });