@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.
- 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 +18 -63
- 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
package/opportunity-edit.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 {
|
|
2
|
+
import { getRuntimeConfig, requestGateway } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.env');
|
|
10
|
-
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/opportunity/edit';
|
|
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/opportunity/edit';
|
|
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
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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 (
|
|
122
|
-
|
|
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
|
});
|
package/opportunity-handover.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 {
|
|
2
|
+
import { getRuntimeConfig, requestGateway } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.env');
|
|
10
|
-
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/opportunity/handover';
|
|
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/opportunity/handover';
|
|
31
5
|
|
|
32
6
|
function makeErrorRow(code, msg) {
|
|
33
7
|
return [{
|
|
@@ -73,7 +47,6 @@ cli({
|
|
|
73
47
|
payload.dataIdList = dataIdList;
|
|
74
48
|
}
|
|
75
49
|
|
|
76
|
-
const body = JSON.stringify(payload);
|
|
77
50
|
|
|
78
51
|
if (!payload.corpid) {
|
|
79
52
|
return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
@@ -88,40 +61,25 @@ cli({
|
|
|
88
61
|
return makeErrorRow('NO_TOKEN', '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
89
62
|
}
|
|
90
63
|
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
99
|
-
}
|
|
100
|
-
const resp = await fetch(apiUrl, {
|
|
101
|
-
method: 'POST',
|
|
102
|
-
headers,
|
|
103
|
-
body,
|
|
64
|
+
const gateway = await requestGateway({
|
|
65
|
+
baseUrl,
|
|
66
|
+
apiPath: API_PATH,
|
|
67
|
+
payload,
|
|
68
|
+
token,
|
|
69
|
+
userId,
|
|
70
|
+
debug,
|
|
104
71
|
});
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseText}\n`);
|
|
109
|
-
return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
110
|
-
}
|
|
111
|
-
|
|
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) {
|
|
116
|
-
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
72
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
73
|
+
if (gateway.data.code !== 1) {
|
|
74
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
117
75
|
}
|
|
118
76
|
|
|
119
|
-
const result = data.result || {};
|
|
77
|
+
const result = gateway.data.result || {};
|
|
120
78
|
return [{
|
|
121
79
|
resultMsg: result.resultMsg || '',
|
|
122
80
|
resultType: result.resultType || '',
|
|
123
|
-
code: data.code ?? '',
|
|
124
|
-
msg: data.msg || '',
|
|
81
|
+
code: gateway.data.code ?? '',
|
|
82
|
+
msg: gateway.data.msg || '',
|
|
125
83
|
}];
|
|
126
84
|
},
|
|
127
85
|
});
|
package/opportunity-list.js
CHANGED
|
@@ -1,45 +1,28 @@
|
|
|
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, createPagination } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const OPPORTUNITY_LIST_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/opportunity/list';
|
|
11
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
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
|
-
}
|
|
4
|
+
const OPPORTUNITY_LIST_API_PATH = '/pro/v2/api/opportunity/list';
|
|
5
|
+
const pagination = createPagination();
|
|
32
6
|
|
|
33
7
|
function buildConditions(kwargs) {
|
|
34
|
-
const conditions =
|
|
8
|
+
const conditions = kwargs.conditions;
|
|
9
|
+
if (typeof conditions === 'string' && conditions.trim()) {
|
|
10
|
+
const parsed = JSON.parse(conditions);
|
|
11
|
+
if (!Array.isArray(parsed)) {
|
|
12
|
+
throw new Error('INVALID_CONDITIONS:conditions 必须是 JSON 数组');
|
|
13
|
+
}
|
|
14
|
+
return parsed;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const result = [];
|
|
35
18
|
if (kwargs.attr && kwargs.value) {
|
|
36
|
-
|
|
19
|
+
result.push({
|
|
37
20
|
attr: String(kwargs.attr),
|
|
38
21
|
value: [String(kwargs.value)],
|
|
39
22
|
symbol: String(kwargs.symbol || 'equal'),
|
|
40
23
|
});
|
|
41
24
|
}
|
|
42
|
-
return
|
|
25
|
+
return result;
|
|
43
26
|
}
|
|
44
27
|
|
|
45
28
|
function buildPayload(kwargs, corpid) {
|
|
@@ -85,6 +68,7 @@ cli({
|
|
|
85
68
|
{ name: 'formId', type: 'int', help: '表单id(必填)' },
|
|
86
69
|
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
87
70
|
{ name: 'viewApproval', type: 'str', default: '', help: '是否查询审批中数据,1是,0否' },
|
|
71
|
+
{ name: 'conditions', type: 'str', default: '', help: '条件集合 JSON 数组字符串,优先级高于 --attr/--value' },
|
|
88
72
|
{ name: 'attr', type: 'str', default: '', help: '筛选字段 attr,例如 serialNo' },
|
|
89
73
|
{ name: 'value', type: 'str', default: '', help: '筛选值,和 --attr 配合使用' },
|
|
90
74
|
{ name: 'symbol', type: 'str', default: 'equal', help: '筛选操作符,默认 equal' },
|
|
@@ -94,12 +78,20 @@ cli({
|
|
|
94
78
|
{ name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
|
|
95
79
|
],
|
|
96
80
|
columns: ['rank', 'dataId', 'formId', 'name', 'serialNo', 'customerId', 'opportunityAmount', 'ownerId', 'addTime', 'updateTime', 'code', 'msg'],
|
|
97
|
-
footerExtra:
|
|
81
|
+
footerExtra: pagination.footerExtra,
|
|
98
82
|
func: async (kwargs) => {
|
|
99
83
|
const debug = Boolean(kwargs.debug);
|
|
100
84
|
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
let payload;
|
|
86
|
+
try {
|
|
87
|
+
payload = buildPayload(kwargs, corpid);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
const message = String(error?.message || error);
|
|
90
|
+
const separatorIndex = message.indexOf(':');
|
|
91
|
+
const code = separatorIndex > 0 ? message.slice(0, separatorIndex) : 'INVALID_PAYLOAD';
|
|
92
|
+
const detail = separatorIndex > 0 ? message.slice(separatorIndex + 1) : message;
|
|
93
|
+
return makeErrorRow(code, detail);
|
|
94
|
+
}
|
|
103
95
|
|
|
104
96
|
if (!payload.corpid) {
|
|
105
97
|
return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
@@ -111,39 +103,22 @@ cli({
|
|
|
111
103
|
return makeErrorRow('NO_TOKEN', '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
112
104
|
}
|
|
113
105
|
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
122
|
-
}
|
|
123
|
-
const resp = await fetch(apiUrl, {
|
|
124
|
-
method: 'POST',
|
|
125
|
-
headers,
|
|
126
|
-
body,
|
|
106
|
+
const gateway = await requestGateway({
|
|
107
|
+
baseUrl,
|
|
108
|
+
apiPath: OPPORTUNITY_LIST_API_PATH,
|
|
109
|
+
payload,
|
|
110
|
+
token,
|
|
111
|
+
userId,
|
|
112
|
+
debug,
|
|
127
113
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return makeErrorRow(
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const data = await resp.json();
|
|
136
|
-
lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
|
|
137
|
-
? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
|
|
138
|
-
: null;
|
|
139
|
-
const responseBody = JSON.stringify(data);
|
|
140
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
141
|
-
if (kwargs.raw) return [{ raw: responseBody }];
|
|
142
|
-
if (data.code !== 1) {
|
|
143
|
-
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
114
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
115
|
+
pagination.update(gateway.data);
|
|
116
|
+
if (kwargs.raw) return [{ raw: gateway.responseBody }];
|
|
117
|
+
if (gateway.data.code !== 1) {
|
|
118
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
144
119
|
}
|
|
145
120
|
|
|
146
|
-
const list = Array.isArray(data.result?.list) ? data.result.list : [];
|
|
121
|
+
const list = Array.isArray(gateway.data.result?.list) ? gateway.data.result.list : [];
|
|
147
122
|
if (!list.length) {
|
|
148
123
|
return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
|
|
149
124
|
}
|
package/orginal-text-list.js
CHANGED
|
@@ -1,32 +1,8 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import crypto from 'node:crypto';
|
|
4
1
|
import { cli, Strategy } from './xbb-registry.js';
|
|
5
|
-
import {
|
|
2
|
+
import { getRuntimeConfig, requestGateway, createPagination } from './xbb-http.js';
|
|
6
3
|
|
|
7
|
-
const CONFIG_DIR = path.join(os.homedir(), '.xbbcli');
|
|
8
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.env');
|
|
9
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
10
4
|
const ORIGINAL_TEXT_LIST_API_PATH = '/pro/v2/api/aiAgent/getAiOriginalText';
|
|
11
|
-
|
|
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) {
|
|
28
|
-
return `${baseUrl.replace(/\/+$/, '')}${ORIGINAL_TEXT_LIST_API_PATH}`;
|
|
29
|
-
}
|
|
5
|
+
const pagination = createPagination({ countOnly: true });
|
|
30
6
|
|
|
31
7
|
function buildPayload(kwargs, corpid) {
|
|
32
8
|
const payload = {
|
|
@@ -67,12 +43,11 @@ cli({
|
|
|
67
43
|
{ name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
|
|
68
44
|
],
|
|
69
45
|
columns: ['rank', 'originalUrl', 'code', 'msg'],
|
|
70
|
-
footerExtra:
|
|
46
|
+
footerExtra: pagination.footerExtra,
|
|
71
47
|
func: async (kwargs) => {
|
|
72
48
|
const debug = Boolean(kwargs.debug);
|
|
73
49
|
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
74
50
|
const payload = buildPayload(kwargs, corpid);
|
|
75
|
-
const body = JSON.stringify(payload);
|
|
76
51
|
|
|
77
52
|
if (!payload.corpid) {
|
|
78
53
|
return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
@@ -81,42 +56,22 @@ cli({
|
|
|
81
56
|
return makeErrorRow('NO_TOKEN', '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
82
57
|
}
|
|
83
58
|
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (debug) {
|
|
93
|
-
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const resp = await fetch(apiUrl, {
|
|
97
|
-
method: 'POST',
|
|
98
|
-
headers,
|
|
99
|
-
body,
|
|
59
|
+
const gateway = await requestGateway({
|
|
60
|
+
baseUrl,
|
|
61
|
+
apiPath: ORIGINAL_TEXT_LIST_API_PATH,
|
|
62
|
+
payload,
|
|
63
|
+
token,
|
|
64
|
+
userId,
|
|
65
|
+
debug,
|
|
100
66
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return makeErrorRow(
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const data = await resp.json();
|
|
109
|
-
lastPagination = data?.code === 1 && data?.totalCount != null
|
|
110
|
-
? { totalCount: data.totalCount }
|
|
111
|
-
: null;
|
|
112
|
-
const responseBody = JSON.stringify(data);
|
|
113
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
114
|
-
if (kwargs.raw) return [{ raw: responseBody }];
|
|
115
|
-
if (data.code !== 1) {
|
|
116
|
-
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
67
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
68
|
+
pagination.update(gateway.data);
|
|
69
|
+
if (kwargs.raw) return [{ raw: gateway.responseBody }];
|
|
70
|
+
if (gateway.data.code !== 1) {
|
|
71
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
117
72
|
}
|
|
118
73
|
|
|
119
|
-
const list = Array.isArray(data.result?.list) ? data.result.list : [];
|
|
74
|
+
const list = Array.isArray(gateway.data.result?.list) ? gateway.data.result.list : [];
|
|
120
75
|
if (!list.length) {
|
|
121
76
|
return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
|
|
122
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xbongbong/xbbcli",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.6",
|
|
4
4
|
"description": "销帮帮 CRM 的独立命令行工具",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,6 +28,13 @@
|
|
|
28
28
|
"engines": {
|
|
29
29
|
"node": ">=18"
|
|
30
30
|
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test": "node test/commands-smoke-test.mjs",
|
|
33
|
+
"test:args": "node test/optional-numeric-args-test.mjs",
|
|
34
|
+
"check": "node test/check-syntax.mjs",
|
|
35
|
+
"test:real": "node test/real-api-test.mjs",
|
|
36
|
+
"test:real:sync-details": "node test/real-api-test.mjs --sync-details"
|
|
37
|
+
},
|
|
31
38
|
"publishConfig": {
|
|
32
39
|
"access": "public"
|
|
33
40
|
}
|
package/pay-plan-add-couser.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 {
|
|
2
|
+
import { getRuntimeConfig, requestGateway } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.env');
|
|
10
|
-
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/payPlan/addCoUser';
|
|
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/payPlan/addCoUser';
|
|
31
5
|
|
|
32
6
|
function makeErrorRow(code, msg) {
|
|
33
7
|
return [{ resultCode: '', resultMsg: '', messageList: '', code, msg }];
|
|
@@ -62,24 +36,23 @@ cli({
|
|
|
62
36
|
}
|
|
63
37
|
if (Array.isArray(businessUserIdList)) payload.businessUserIdList = businessUserIdList;
|
|
64
38
|
|
|
65
|
-
const requestBody = JSON.stringify(payload);
|
|
66
39
|
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
67
40
|
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
68
41
|
if (!Array.isArray(businessUserIdList) || !businessUserIdList.length) return makeErrorRow('NO_USERIDLIST', '缺少 --businessUserIdList 或格式不正确,需为JSON数组');
|
|
69
42
|
if (!token) return makeErrorRow('NO_TOKEN', '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
70
43
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
44
|
+
const gateway = await requestGateway({
|
|
45
|
+
baseUrl,
|
|
46
|
+
apiPath: API_PATH,
|
|
47
|
+
payload,
|
|
48
|
+
token,
|
|
49
|
+
userId,
|
|
50
|
+
debug,
|
|
51
|
+
});
|
|
52
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
53
|
+
if (gateway.data.code !== 1) {
|
|
54
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
76
55
|
}
|
|
77
|
-
|
|
78
|
-
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
79
|
-
const data = await resp.json();
|
|
80
|
-
const responseBody = JSON.stringify(data);
|
|
81
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
82
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
83
|
-
return [{ resultCode: data.code ?? '', resultMsg: data.msg || '', messageList: JSON.stringify(data.result?.messageList || []), code: data.code ?? '', msg: data.msg || '' }];
|
|
56
|
+
return [{ resultCode: gateway.data.code ?? '', resultMsg: gateway.data.msg || '', messageList: JSON.stringify(gateway.data.result?.messageList || []), code: gateway.data.code ?? '', msg: gateway.data.msg || '' }];
|
|
84
57
|
},
|
|
85
58
|
});
|
package/pay-plan-add-mainuser.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 {
|
|
2
|
+
import { getRuntimeConfig, requestGateway } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.env');
|
|
10
|
-
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/payPlan/addMainUser';
|
|
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/payPlan/addMainUser';
|
|
31
5
|
|
|
32
6
|
function makeErrorRow(code, msg) {
|
|
33
7
|
return [{ resultCode: '', resultMsg: '', messageList: '', code, msg }];
|
|
@@ -62,24 +36,23 @@ cli({
|
|
|
62
36
|
}
|
|
63
37
|
if (Array.isArray(businessUserIdList)) payload.businessUserIdList = businessUserIdList;
|
|
64
38
|
|
|
65
|
-
const requestBody = JSON.stringify(payload);
|
|
66
39
|
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
67
40
|
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
68
41
|
if (!Array.isArray(businessUserIdList) || !businessUserIdList.length) return makeErrorRow('NO_USERIDLIST', '缺少 --businessUserIdList 或格式不正确,需为JSON数组');
|
|
69
42
|
if (!token) return makeErrorRow('NO_TOKEN', '缺少 token;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
70
43
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
44
|
+
const gateway = await requestGateway({
|
|
45
|
+
baseUrl,
|
|
46
|
+
apiPath: API_PATH,
|
|
47
|
+
payload,
|
|
48
|
+
token,
|
|
49
|
+
userId,
|
|
50
|
+
debug,
|
|
51
|
+
});
|
|
52
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
53
|
+
if (gateway.data.code !== 1) {
|
|
54
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
76
55
|
}
|
|
77
|
-
|
|
78
|
-
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
79
|
-
const data = await resp.json();
|
|
80
|
-
const responseBody = JSON.stringify(data);
|
|
81
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
82
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
83
|
-
return [{ resultCode: data.code ?? '', resultMsg: data.msg || '', messageList: JSON.stringify(data.result?.messageList || []), code: data.code ?? '', msg: data.msg || '' }];
|
|
56
|
+
return [{ resultCode: gateway.data.code ?? '', resultMsg: gateway.data.msg || '', messageList: JSON.stringify(gateway.data.result?.messageList || []), code: gateway.data.code ?? '', msg: gateway.data.msg || '' }];
|
|
84
57
|
},
|
|
85
58
|
});
|