@xbongbong/xbbcli 2.4.5 → 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.
- package/README.md +15 -4
- package/business-info-detail.js +126 -0
- package/business-info-search.js +95 -0
- package/buyer-inquiry-detail.js +16 -47
- package/buyer-inquiry-list.js +18 -56
- package/clue-add-couser.js +14 -39
- package/clue-add.js +15 -41
- package/clue-back.js +14 -39
- package/clue-del.js +14 -39
- package/clue-delete-couser.js +14 -39
- package/clue-delete-mainuser.js +14 -39
- package/clue-detail.js +15 -40
- package/clue-distribution.js +14 -43
- package/clue-edit.js +15 -41
- package/clue-handover.js +15 -45
- package/clue-list.js +18 -61
- package/clue-thorough-delete.js +14 -39
- package/communicate-add.js +15 -56
- package/communicate-del.js +17 -59
- package/communicate-detail.js +15 -56
- package/communicate-edit.js +15 -56
- package/communicate-list.js +17 -62
- package/communicate-plan-add.js +16 -42
- package/communicate-plan-cancel.js +14 -40
- package/communicate-plan-del.js +14 -40
- package/communicate-plan-detail.js +15 -41
- package/communicate-plan-list.js +18 -46
- package/communicate-plan-single-operate.js +14 -39
- package/contact-add-couser.js +14 -39
- package/contact-add-mainuser.js +14 -39
- package/contact-add.js +15 -51
- package/contact-del.js +15 -38
- package/contact-delete-couser.js +14 -39
- package/contact-delete-mainuser.js +14 -39
- package/contact-detail.js +15 -38
- package/contact-edit.js +14 -47
- package/contact-handover.js +14 -39
- package/contact-list.js +37 -61
- package/contract-add-couser.js +16 -58
- package/contract-add-mainuser.js +16 -58
- package/contract-add.js +15 -57
- package/contract-del.js +17 -58
- package/contract-delete-couser.js +16 -57
- package/contract-delete-mainuser.js +16 -58
- package/contract-detail.js +15 -57
- package/contract-edit.js +15 -57
- package/contract-handover.js +15 -56
- package/contract-list.js +18 -61
- package/contract-outstock-add.js +15 -46
- package/contract-outstock-del.js +15 -41
- package/contract-outstock-detail.js +15 -41
- package/contract-outstock-edit.js +15 -46
- package/contract-outstock-list.js +18 -46
- package/customer-add-couser.js +13 -54
- package/customer-add.js +15 -58
- package/customer-back.js +15 -57
- package/customer-del.js +17 -58
- package/customer-delete-couser.js +16 -57
- package/customer-delete-mainuser.js +16 -58
- package/customer-detail.js +13 -54
- package/customer-distribution.js +15 -57
- package/customer-edit.js +13 -53
- package/customer-handover.js +15 -56
- package/customer-invoice-address-add.js +15 -41
- package/customer-invoice-address-edit.js +15 -40
- package/customer-invoice-address.js +17 -42
- package/customer-invoice-info-add.js +15 -41
- package/customer-invoice-info-edit.js +15 -40
- package/customer-invoice-info.js +17 -42
- package/customer-list.js +18 -61
- package/department-add.js +14 -39
- package/department-del.js +14 -40
- package/department-edit.js +14 -39
- package/department-list.js +17 -59
- package/form-data-add-couser.js +14 -39
- package/form-data-add-mainuser.js +14 -39
- package/form-data-add.js +13 -54
- package/form-data-del.js +13 -53
- package/form-data-delete-couser.js +14 -40
- package/form-data-delete-mainuser.js +14 -39
- package/form-data-detail.js +13 -54
- package/form-data-edit.js +13 -54
- package/form-data-handover.js +14 -39
- package/form-data-list.js +37 -63
- package/form-get.js +13 -53
- package/form-list.js +19 -66
- package/hkh-call-add-task.js +14 -44
- package/hkh-word-list.js +16 -44
- package/invoice-add.js +15 -45
- package/invoice-cancel.js +14 -44
- package/invoice-del.js +15 -45
- package/invoice-detail.js +15 -45
- package/invoice-edit.js +15 -45
- package/invoice-get-amount-detail.js +14 -44
- package/invoice-list.js +18 -50
- package/invoice-red.js +15 -45
- package/label-add.js +14 -44
- package/label-all-list.js +16 -44
- package/label-batch-add.js +14 -44
- package/label-batch-remove.js +14 -44
- package/label-del-completely.js +14 -44
- package/label-del.js +15 -45
- package/label-edit.js +14 -44
- package/label-group-add.js +15 -45
- package/label-group-del.js +15 -45
- package/label-group-list.js +16 -44
- package/label-group-update.js +15 -45
- package/label-list.js +16 -44
- package/label-reduction.js +15 -45
- package/label-repeat.js +15 -45
- package/market-activity-add.js +14 -49
- package/market-activity-del.js +15 -46
- package/market-activity-detail.js +15 -45
- package/market-activity-edit.js +15 -46
- package/market-activity-handover.js +14 -40
- package/market-activity-list.js +18 -46
- package/opportunity-add-couser.js +16 -58
- package/opportunity-add-mainuser.js +16 -58
- package/opportunity-add.js +15 -56
- package/opportunity-del.js +17 -59
- package/opportunity-delete-couser.js +16 -58
- package/opportunity-delete-mainuser.js +16 -57
- package/opportunity-detail.js +15 -58
- package/opportunity-edit.js +15 -56
- package/opportunity-handover.js +15 -57
- package/opportunity-list.js +40 -65
- package/orginal-text-list.js +16 -61
- package/package.json +8 -1
- package/pay-plan-add-couser.js +14 -41
- package/pay-plan-add-mainuser.js +14 -41
- package/pay-plan-add.js +15 -46
- package/pay-plan-delete-couser.js +14 -40
- package/pay-plan-delete-mainuser.js +14 -40
- package/pay-plan-handover.js +14 -40
- package/pay-sheet-add-bad.js +15 -46
- package/pay-sheet-add-couser.js +14 -40
- package/pay-sheet-add-mainuser.js +14 -41
- package/pay-sheet-add-red.js +15 -46
- package/pay-sheet-add-write-off.js +15 -46
- package/pay-sheet-del.js +14 -48
- package/pay-sheet-delete-couser.js +14 -40
- package/pay-sheet-delete-mainuser.js +14 -41
- package/pay-sheet-detail.js +15 -46
- package/pay-sheet-edit-bad.js +14 -49
- package/pay-sheet-edit-red.js +14 -49
- package/pay-sheet-edit-write-off.js +15 -46
- package/pay-sheet-get-amount-detail.js +14 -44
- package/pay-sheet-list.js +18 -46
- package/payment-add-couser.js +16 -58
- package/payment-add-mainuser.js +16 -58
- package/payment-add.js +15 -56
- package/payment-del.js +17 -58
- package/payment-delete-couser.js +16 -57
- package/payment-delete-mainuser.js +16 -57
- package/payment-detail.js +15 -56
- package/payment-edit.js +15 -56
- package/payment-handover.js +15 -57
- package/payment-list.js +37 -61
- package/payment-sheet-add-bad-debt.js +15 -57
- package/payment-sheet-add-pre.js +15 -46
- package/payment-sheet-add-red.js +15 -57
- package/payment-sheet-add-write-off.js +15 -52
- package/payment-sheet-del.js +17 -53
- package/payment-sheet-detail.js +15 -52
- package/payment-sheet-edit-bad-debt.js +15 -51
- package/payment-sheet-edit-red.js +15 -56
- package/payment-sheet-edit-write-off.js +15 -56
- package/payment-sheet-get-amount-detail.js +14 -45
- package/payment-sheet-handover.js +14 -40
- package/payment-sheet-list.js +37 -60
- package/product-add.js +15 -51
- package/product-category-add.js +13 -48
- package/product-category-del.js +13 -53
- package/product-category-list.js +17 -60
- package/product-category-update.js +13 -54
- package/product-del.js +17 -53
- package/product-detail.js +13 -54
- package/product-edit.js +15 -51
- package/product-list.js +37 -63
- package/product-online.js +14 -44
- package/quotation-add-couser.js +15 -45
- package/quotation-add-mainuser.js +15 -45
- package/quotation-add.js +15 -45
- package/quotation-del.js +15 -45
- package/quotation-delete-couser.js +15 -45
- package/quotation-delete-mainuser.js +15 -45
- package/quotation-detail.js +15 -45
- package/quotation-edit.js +15 -45
- package/quotation-handover.js +14 -39
- package/quotation-list.js +18 -50
- package/refund-add.js +15 -39
- package/refund-del.js +15 -38
- package/refund-detail.js +15 -39
- package/refund-edit.js +15 -39
- package/refund-list.js +37 -61
- package/role-list.js +18 -46
- package/sign-in-list.js +21 -49
- package/stage-get.js +16 -42
- package/stage-jump.js +15 -49
- package/supplier-add.js +15 -57
- package/token-del.js +1 -1
- package/token-list.js +20 -1
- package/token-set.js +1 -1
- package/token-use.js +2 -35
- package/user-add.js +14 -39
- package/user-del.js +14 -40
- package/user-edit.js +14 -40
- package/user-handover.js +14 -40
- package/user-list.js +16 -62
- package/work-order-add.js +13 -54
- package/work-order-asset-add-couser.js +15 -45
- package/work-order-asset-add-mainuser.js +15 -45
- package/work-order-asset-add.js +15 -45
- package/work-order-asset-del-couser.js +15 -45
- package/work-order-asset-del-mainuser.js +15 -45
- package/work-order-asset-del.js +15 -45
- package/work-order-asset-detail.js +15 -45
- package/work-order-asset-edit.js +15 -45
- package/work-order-asset-handover.js +15 -45
- package/work-order-asset-list.js +18 -50
- package/work-order-del.js +13 -54
- package/work-order-detail.js +13 -53
- package/work-order-dynamic-list.js +18 -56
- package/work-order-edit.js +13 -54
- package/work-order-list.js +17 -59
- package/work-order-operate.js +13 -54
- package/work-order-template-detail.js +13 -54
- package/work-order-template-list.js +17 -60
- package/work-report-daily-add.js +14 -39
- package/work-report-daily-del.js +14 -39
- package/work-report-daily-detail.js +15 -40
- package/work-report-daily-edit.js +17 -52
- package/work-report-daily-get-work-plan.js +14 -40
- package/work-report-daily-list.js +18 -45
- package/work-report-monthly-add.js +14 -40
- package/work-report-monthly-del.js +14 -43
- package/work-report-monthly-detail.js +15 -40
- package/work-report-monthly-edit.js +15 -40
- package/work-report-monthly-list.js +18 -45
- package/work-report-weekly-add.js +14 -40
- package/work-report-weekly-del.js +14 -40
- package/work-report-weekly-detail.js +15 -41
- package/work-report-weekly-edit.js +15 -41
- package/work-report-weekly-list.js +18 -45
- package/work-task-add-couser.js +14 -43
- package/work-task-add.js +15 -41
- package/work-task-delete-couser.js +14 -40
- package/work-task-detail.js +15 -40
- package/work-task-edit.js +14 -39
- package/work-task-handover.js +14 -40
- package/workorder-add-couser.js +16 -57
- package/workorder-delete-couser.js +16 -58
- package/workorder-handover.js +17 -58
- package/workorderlist.js +38 -60
- package/workorderproductlist.js +18 -59
- package/worktimerecorddetail.js +13 -54
- package/worktimerecordlist.js +18 -59
- package/xbb-http.js +71 -0
|
@@ -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 {
|
|
2
|
+
import { getRuntimeConfig, requestGateway } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/paas/deleteMainUser';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const API_PATH = '/pro/v2/api/paas/deleteMainUser';
|
|
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 [{ resultCode: '', resultMsg: '', messageList: '', code, msg }];
|
|
34
9
|
}
|
|
@@ -60,22 +35,22 @@ cli({
|
|
|
60
35
|
businessUserIdList = null;
|
|
61
36
|
}
|
|
62
37
|
if (Array.isArray(businessUserIdList)) payload.businessUserIdList = businessUserIdList;
|
|
63
|
-
const body = JSON.stringify(payload);
|
|
64
38
|
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
65
39
|
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
66
40
|
if (!Array.isArray(businessUserIdList) || !businessUserIdList.length) return makeErrorRow('NO_USERIDLIST', '缺少 --businessUserIdList 或格式不正确,需为JSON数组');
|
|
67
41
|
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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 ?? '未知错误');
|
|
72
53
|
}
|
|
73
|
-
|
|
74
|
-
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
75
|
-
const data = await resp.json();
|
|
76
|
-
const responseBody = JSON.stringify(data);
|
|
77
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
78
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
79
|
-
return [{ resultCode: data.code ?? '', resultMsg: data.msg || '', messageList: JSON.stringify(data.result?.messageList || []), code: data.code ?? '', msg: data.msg || '' }];
|
|
54
|
+
return [{ resultCode: gateway.data.code ?? '', resultMsg: gateway.data.msg || '', messageList: JSON.stringify(gateway.data.result?.messageList || []), code: gateway.data.code ?? '', msg: gateway.data.msg || '' }];
|
|
80
55
|
},
|
|
81
56
|
});
|
package/form-data-detail.js
CHANGED
|
@@ -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 {
|
|
2
|
+
import { getRuntimeConfig, requestGateway } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const FORM_DATA_DETAIL_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/paas/detail';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const FORM_DATA_DETAIL_API_PATH = '/pro/v2/api/paas/detail';
|
|
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, apiUrl) {
|
|
28
|
-
const apiPath = new URL(apiUrl).pathname;
|
|
29
|
-
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
7
|
function buildPayload(kwargs, corpid) {
|
|
33
8
|
const payload = {
|
|
34
9
|
dataId: Number(kwargs.dataId || 0),
|
|
@@ -103,41 +78,25 @@ cli({
|
|
|
103
78
|
const debug = Boolean(kwargs.debug);
|
|
104
79
|
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
105
80
|
const payload = buildPayload(kwargs, corpid);
|
|
106
|
-
const requestBody = JSON.stringify(payload);
|
|
107
81
|
|
|
108
82
|
const validationError = getValidationError(payload, token);
|
|
109
83
|
if (validationError) {
|
|
110
84
|
return makeErrorRow(validationError.code, validationError.msg);
|
|
111
85
|
}
|
|
112
86
|
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
121
|
-
}
|
|
122
|
-
const resp = await fetch(apiUrl, {
|
|
123
|
-
method: 'POST',
|
|
124
|
-
headers,
|
|
125
|
-
body: requestBody,
|
|
87
|
+
const gateway = await requestGateway({
|
|
88
|
+
baseUrl,
|
|
89
|
+
apiPath: FORM_DATA_DETAIL_API_PATH,
|
|
90
|
+
payload,
|
|
91
|
+
token,
|
|
92
|
+
userId,
|
|
93
|
+
debug,
|
|
126
94
|
});
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
131
|
-
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const data = await resp.json();
|
|
135
|
-
const responseBody = JSON.stringify(data);
|
|
136
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
137
|
-
if (data.code !== 1) {
|
|
138
|
-
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
95
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
96
|
+
if (gateway.data.code !== 1) {
|
|
97
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
139
98
|
}
|
|
140
99
|
|
|
141
|
-
return makeSuccessRow(data);
|
|
100
|
+
return makeSuccessRow(gateway.data);
|
|
142
101
|
},
|
|
143
102
|
});
|
package/form-data-edit.js
CHANGED
|
@@ -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 {
|
|
2
|
+
import { getRuntimeConfig, requestGateway } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const FORM_DATA_EDIT_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/paas/edit';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const FORM_DATA_EDIT_API_PATH = '/pro/v2/api/paas/edit';
|
|
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, apiUrl) {
|
|
28
|
-
const apiPath = new URL(apiUrl).pathname;
|
|
29
|
-
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
7
|
function parseDataList(raw) {
|
|
33
8
|
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
34
9
|
return raw;
|
|
@@ -128,41 +103,25 @@ cli({
|
|
|
128
103
|
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
129
104
|
const parsedDataList = parseDataList(kwargs.dataList);
|
|
130
105
|
const payload = buildPayload(kwargs, parsedDataList, corpid, userId);
|
|
131
|
-
const requestBody = JSON.stringify(payload);
|
|
132
106
|
|
|
133
107
|
const validationError = getValidationError(payload, token, parsedDataList);
|
|
134
108
|
if (validationError) {
|
|
135
109
|
return makeErrorRow(validationError.code, validationError.msg);
|
|
136
110
|
}
|
|
137
111
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
146
|
-
}
|
|
147
|
-
const resp = await fetch(apiUrl, {
|
|
148
|
-
method: 'POST',
|
|
149
|
-
headers,
|
|
150
|
-
body: requestBody,
|
|
112
|
+
const gateway = await requestGateway({
|
|
113
|
+
baseUrl,
|
|
114
|
+
apiPath: FORM_DATA_EDIT_API_PATH,
|
|
115
|
+
payload,
|
|
116
|
+
token,
|
|
117
|
+
userId,
|
|
118
|
+
debug,
|
|
151
119
|
});
|
|
152
|
-
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
156
|
-
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const data = await resp.json();
|
|
160
|
-
const responseBody = JSON.stringify(data);
|
|
161
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
162
|
-
if (data.code !== 1) {
|
|
163
|
-
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
120
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
121
|
+
if (gateway.data.code !== 1) {
|
|
122
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
164
123
|
}
|
|
165
124
|
|
|
166
|
-
return makeSuccessRow(data);
|
|
125
|
+
return makeSuccessRow(gateway.data);
|
|
167
126
|
},
|
|
168
127
|
});
|
package/form-data-handover.js
CHANGED
|
@@ -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 {
|
|
2
|
+
import { getRuntimeConfig, requestGateway } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/paas/handover';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const API_PATH = '/pro/v2/api/paas/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,22 +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
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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 ?? '未知错误');
|
|
72
53
|
}
|
|
73
|
-
|
|
74
|
-
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
75
|
-
const data = await resp.json();
|
|
76
|
-
const responseBody = JSON.stringify(data);
|
|
77
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
78
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
79
|
-
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 || '' }];
|
|
80
55
|
},
|
|
81
56
|
});
|
package/form-data-list.js
CHANGED
|
@@ -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 {
|
|
2
|
+
import { getRuntimeConfig, requestGateway, createPagination } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const FORM_DATA_LIST_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/paas/list';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const FORM_DATA_LIST_API_PATH = '/pro/v2/api/paas/list';
|
|
11
5
|
const MISSING_TOKEN_MESSAGE = '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>';
|
|
12
|
-
|
|
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, apiUrl) {
|
|
29
|
-
const apiPath = new URL(apiUrl).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
|
}
|
|
@@ -120,6 +104,7 @@ cli({
|
|
|
120
104
|
{ name: 'formId', type: 'int', help: '表单id(必填)' },
|
|
121
105
|
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
122
106
|
{ name: 'viewApproval', type: 'str', default: '', help: '是否查询审批中数据,1是,0否' },
|
|
107
|
+
{ name: 'conditions', type: 'str', default: '', help: '条件集合 JSON 数组字符串,优先级高于 --attr/--value' },
|
|
123
108
|
{ name: 'attr', type: 'str', default: '', help: '筛选字段 attr,例如 text_1' },
|
|
124
109
|
{ name: 'value', type: 'str', default: '', help: '筛选值,和 --attr 配合使用' },
|
|
125
110
|
{ name: 'symbol', type: 'str', default: 'equal', help: '筛选操作符,默认 equal' },
|
|
@@ -129,53 +114,42 @@ cli({
|
|
|
129
114
|
{ name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
|
|
130
115
|
],
|
|
131
116
|
columns: ['rank', 'dataId', 'formId', 'addTime', 'updateTime', 'data', 'code', 'msg'],
|
|
132
|
-
footerExtra:
|
|
117
|
+
footerExtra: pagination.footerExtra,
|
|
133
118
|
func: async function (kwargs) {
|
|
134
119
|
const debug = Boolean(kwargs.debug);
|
|
135
120
|
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
136
|
-
|
|
137
|
-
|
|
121
|
+
let payload;
|
|
122
|
+
try {
|
|
123
|
+
payload = buildPayload(kwargs, corpid, userId);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
const message = String(error?.message || error);
|
|
126
|
+
const separatorIndex = message.indexOf(':');
|
|
127
|
+
const code = separatorIndex > 0 ? message.slice(0, separatorIndex) : 'INVALID_PAYLOAD';
|
|
128
|
+
const detail = separatorIndex > 0 ? message.slice(separatorIndex + 1) : message;
|
|
129
|
+
return makeErrorRow(code, detail);
|
|
130
|
+
}
|
|
138
131
|
|
|
139
132
|
const validationError = getValidationError(payload, token);
|
|
140
133
|
if (validationError) {
|
|
141
134
|
return makeErrorRow(validationError.code, validationError.msg);
|
|
142
135
|
}
|
|
143
136
|
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (debug) {
|
|
152
|
-
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${requestBody}\n`);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const resp = await fetch(apiUrl, {
|
|
156
|
-
method: 'POST',
|
|
157
|
-
headers,
|
|
158
|
-
body: requestBody,
|
|
137
|
+
const gateway = await requestGateway({
|
|
138
|
+
baseUrl,
|
|
139
|
+
apiPath: FORM_DATA_LIST_API_PATH,
|
|
140
|
+
payload,
|
|
141
|
+
token,
|
|
142
|
+
userId,
|
|
143
|
+
debug,
|
|
159
144
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return makeErrorRow(
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const data = await resp.json();
|
|
168
|
-
lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
|
|
169
|
-
? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
|
|
170
|
-
: null;
|
|
171
|
-
const responseBody = JSON.stringify(data);
|
|
172
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
173
|
-
if (kwargs.raw) return [{ raw: responseBody }];
|
|
174
|
-
if (data.code !== 1) {
|
|
175
|
-
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
145
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
146
|
+
pagination.update(gateway.data);
|
|
147
|
+
if (kwargs.raw) return [{ raw: gateway.responseBody }];
|
|
148
|
+
if (gateway.data.code !== 1) {
|
|
149
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
176
150
|
}
|
|
177
151
|
|
|
178
|
-
const list = Array.isArray(data.result?.list) ? data.result.list : [];
|
|
152
|
+
const list = Array.isArray(gateway.data.result?.list) ? gateway.data.result.list : [];
|
|
179
153
|
if (!list.length) {
|
|
180
154
|
return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
|
|
181
155
|
}
|
package/form-get.js
CHANGED
|
@@ -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 {
|
|
2
|
+
import { getRuntimeConfig, requestGateway } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const FORM_GET_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/form/get';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const FORM_GET_API_PATH = '/pro/v2/api/form/get';
|
|
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
|
formId: Number(kwargs.formId || 0),
|
|
@@ -110,41 +85,26 @@ cli({
|
|
|
110
85
|
const debug = Boolean(kwargs.debug);
|
|
111
86
|
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
112
87
|
const payload = buildPayload(kwargs, corpid);
|
|
113
|
-
const body = JSON.stringify(payload);
|
|
114
88
|
|
|
115
89
|
const validationError = getValidationError(payload, token);
|
|
116
90
|
if (validationError) {
|
|
117
91
|
return makeErrorRow(validationError.code, validationError.msg);
|
|
118
92
|
}
|
|
119
93
|
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
const resp = await fetch(buildApiUrl(baseUrl, FORM_GET_API_URL), {
|
|
129
|
-
method: 'POST',
|
|
130
|
-
headers,
|
|
131
|
-
body,
|
|
94
|
+
const gateway = await requestGateway({
|
|
95
|
+
baseUrl,
|
|
96
|
+
apiPath: FORM_GET_API_PATH,
|
|
97
|
+
payload,
|
|
98
|
+
token,
|
|
99
|
+
userId,
|
|
100
|
+
debug,
|
|
132
101
|
});
|
|
133
|
-
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
137
|
-
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const data = await resp.json();
|
|
141
|
-
const responseBody = JSON.stringify(data);
|
|
142
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
143
|
-
if (data.code !== 1) {
|
|
144
|
-
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
102
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
103
|
+
if (gateway.data.code !== 1) {
|
|
104
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
145
105
|
}
|
|
146
106
|
|
|
147
|
-
const explainList = Array.isArray(data.result?.explainList) ? data.result.explainList : [];
|
|
107
|
+
const explainList = Array.isArray(gateway.data.result?.explainList) ? gateway.data.result.explainList : [];
|
|
148
108
|
if (!explainList.length) {
|
|
149
109
|
return makeErrorRow('NO_DATA', '接口成功,但 explainList 为空');
|
|
150
110
|
}
|