@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
package/communicate-list.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, createPagination } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const COMMUNICATE_LIST_API_URL = 'https://proapi.xbongbong.com/pro/v2/api/communicate/list';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const COMMUNICATE_LIST_API_PATH = '/pro/v2/api/communicate/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, 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) {
|
|
34
9
|
const conditions = kwargs.conditions;
|
|
@@ -145,7 +120,7 @@ cli({
|
|
|
145
120
|
{ name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
|
|
146
121
|
],
|
|
147
122
|
columns: ['rank', 'dataId', 'formId', 'relatedDataId', 'communicateType', 'communicateMethod', 'content', 'creatorId', 'addTime', 'updateTime', 'data', 'code', 'msg'],
|
|
148
|
-
footerExtra:
|
|
123
|
+
footerExtra: pagination.footerExtra,
|
|
149
124
|
func: async function (kwargs) {
|
|
150
125
|
const debug = Boolean(kwargs.debug);
|
|
151
126
|
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
@@ -159,48 +134,28 @@ cli({
|
|
|
159
134
|
const detail = separatorIndex > 0 ? message.slice(separatorIndex + 1) : message;
|
|
160
135
|
return makeErrorRow(code, detail);
|
|
161
136
|
}
|
|
162
|
-
const body = JSON.stringify(payload);
|
|
163
137
|
|
|
164
138
|
const validationError = getValidationError(payload, token);
|
|
165
139
|
if (validationError) {
|
|
166
140
|
return makeErrorRow(validationError.code, validationError.msg);
|
|
167
141
|
}
|
|
168
142
|
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
process.stderr.write(`[debug] URL: ${apiUrl}\n[debug] Headers: ${JSON.stringify(headers)}\n[debug] RequestBody: ${body}\n`);
|
|
177
|
-
}
|
|
178
|
-
const resp = await fetch(apiUrl, {
|
|
179
|
-
method: 'POST',
|
|
180
|
-
headers,
|
|
181
|
-
body,
|
|
143
|
+
const gateway = await requestGateway({
|
|
144
|
+
baseUrl,
|
|
145
|
+
apiPath: COMMUNICATE_LIST_API_PATH,
|
|
146
|
+
payload,
|
|
147
|
+
token,
|
|
148
|
+
userId,
|
|
149
|
+
debug,
|
|
182
150
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return makeErrorRow(
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const data = await resp.json();
|
|
191
|
-
lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
|
|
192
|
-
? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
|
|
193
|
-
: null;
|
|
194
|
-
const responseBody = JSON.stringify(data);
|
|
195
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
196
|
-
if (kwargs.raw) {
|
|
197
|
-
return [{ raw: responseBody }];
|
|
198
|
-
}
|
|
199
|
-
if (data.code !== 1) {
|
|
200
|
-
return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
151
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
152
|
+
pagination.update(gateway.data);
|
|
153
|
+
if (kwargs.raw) return [{ raw: gateway.responseBody }];
|
|
154
|
+
if (gateway.data.code !== 1) {
|
|
155
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
201
156
|
}
|
|
202
157
|
|
|
203
|
-
const list = Array.isArray(data.result?.list) ? data.result.list : [];
|
|
158
|
+
const list = Array.isArray(gateway.data.result?.list) ? gateway.data.result.list : [];
|
|
204
159
|
if (!list.length) {
|
|
205
160
|
return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
|
|
206
161
|
}
|
package/communicate-plan-add.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 API_URL = 'https://proapi.xbongbong.com/pro/v2/api/communicatePlan/add';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const API_PATH = '/pro/v2/api/communicatePlan/add';
|
|
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;
|
|
@@ -62,7 +37,7 @@ cli({
|
|
|
62
37
|
domain: 'proapi.xbongbong.com',
|
|
63
38
|
args: [
|
|
64
39
|
{ name: 'dataList', type: 'str', help: '访客计划数据JSON字符串(必填)' },
|
|
65
|
-
{ name: 'formId', type: '
|
|
40
|
+
{ name: 'formId', type: 'str', default: '', help: '表单模板id(可选)' },
|
|
66
41
|
{ name: 'userId', type: 'str', default: '', help: '操作人id(可选)' },
|
|
67
42
|
{ name: 'debug', type: 'bool', default: false, help: '输出请求体和返回体调试信息' },
|
|
68
43
|
],
|
|
@@ -76,24 +51,23 @@ cli({
|
|
|
76
51
|
if (runtimeUserId) payload.userId = runtimeUserId;
|
|
77
52
|
if (String(kwargs.formId ?? '') !== '') payload.formId = Number(kwargs.formId);
|
|
78
53
|
if (parsedDataList) payload.dataList = parsedDataList;
|
|
79
|
-
const requestBody = JSON.stringify(payload);
|
|
80
54
|
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
81
55
|
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
82
56
|
if (parsedDataList === null) return makeErrorRow('NO_DATALIST', '缺少 --dataList');
|
|
83
57
|
if (parsedDataList === undefined) return makeErrorRow('INVALID_DATALIST', '--dataList 必须是 JSON 对象字符串');
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
58
|
+
const gateway = await requestGateway({
|
|
59
|
+
baseUrl,
|
|
60
|
+
apiPath: API_PATH,
|
|
61
|
+
payload,
|
|
62
|
+
token,
|
|
63
|
+
userId: runtimeUserId,
|
|
64
|
+
debug,
|
|
65
|
+
});
|
|
66
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
67
|
+
if (gateway.data.code !== 1) {
|
|
68
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
89
69
|
}
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
const data = await resp.json();
|
|
93
|
-
const responseBody = JSON.stringify(data);
|
|
94
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
95
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
96
|
-
const result = data.result || {};
|
|
97
|
-
return [{ dataId: result.dataId || '', resultCode: result.code ?? '', resultMsg: result.msg || '', code: data.code ?? '', msg: data.msg || '' }];
|
|
70
|
+
const result = gateway.data.result || {};
|
|
71
|
+
return [{ dataId: result.dataId || '', resultCode: result.code ?? '', resultMsg: result.msg || '', code: gateway.data.code ?? '', msg: gateway.data.msg || '' }];
|
|
98
72
|
},
|
|
99
73
|
});
|
|
@@ -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 API_URL = 'https://proapi.xbongbong.com/pro/v2/api/communicatePlan/cancel';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const API_PATH = '/pro/v2/api/communicatePlan/cancel';
|
|
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 makeErrorRow(code, msg) {
|
|
33
8
|
return [{ code, msg }];
|
|
34
9
|
}
|
|
@@ -52,22 +27,21 @@ cli({
|
|
|
52
27
|
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
53
28
|
const payload = { corpid, dataId: Number(kwargs.dataId || 0) };
|
|
54
29
|
if (kwargs.userId) payload.userId = String(kwargs.userId);
|
|
55
|
-
const requestBody = JSON.stringify(payload);
|
|
56
30
|
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
57
31
|
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
58
32
|
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
33
|
+
const gateway = await requestGateway({
|
|
34
|
+
baseUrl,
|
|
35
|
+
apiPath: API_PATH,
|
|
36
|
+
payload,
|
|
37
|
+
token,
|
|
38
|
+
userId,
|
|
39
|
+
debug,
|
|
40
|
+
});
|
|
41
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
42
|
+
if (gateway.data.code !== 1) {
|
|
43
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
64
44
|
}
|
|
65
|
-
|
|
66
|
-
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
67
|
-
const data = await resp.json();
|
|
68
|
-
const responseBody = JSON.stringify(data);
|
|
69
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
70
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
71
|
-
return [{ code: data.code ?? '', msg: data.msg || '' }];
|
|
45
|
+
return [{ code: gateway.data.code ?? '', msg: gateway.data.msg || '' }];
|
|
72
46
|
},
|
|
73
47
|
});
|
package/communicate-plan-del.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 API_URL = 'https://proapi.xbongbong.com/pro/v2/api/communicatePlan/del';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const API_PATH = '/pro/v2/api/communicatePlan/del';
|
|
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 makeErrorRow(code, msg) {
|
|
33
8
|
return [{ code, msg }];
|
|
34
9
|
}
|
|
@@ -52,22 +27,21 @@ cli({
|
|
|
52
27
|
const { corpid, token, baseUrl, userId } = getRuntimeConfig();
|
|
53
28
|
const payload = { corpid, dataId: Number(kwargs.dataId || 0) };
|
|
54
29
|
if (kwargs.userId) payload.userId = String(kwargs.userId);
|
|
55
|
-
const requestBody = JSON.stringify(payload);
|
|
56
30
|
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
57
31
|
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
58
32
|
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
33
|
+
const gateway = await requestGateway({
|
|
34
|
+
baseUrl,
|
|
35
|
+
apiPath: API_PATH,
|
|
36
|
+
payload,
|
|
37
|
+
token,
|
|
38
|
+
userId,
|
|
39
|
+
debug,
|
|
40
|
+
});
|
|
41
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
42
|
+
if (gateway.data.code !== 1) {
|
|
43
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
64
44
|
}
|
|
65
|
-
|
|
66
|
-
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
67
|
-
const data = await resp.json();
|
|
68
|
-
const responseBody = JSON.stringify(data);
|
|
69
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
70
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
71
|
-
return [{ code: data.code ?? '', msg: data.msg || '' }];
|
|
45
|
+
return [{ code: gateway.data.code ?? '', msg: gateway.data.msg || '' }];
|
|
72
46
|
},
|
|
73
47
|
});
|
|
@@ -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 API_URL = 'https://proapi.xbongbong.com/pro/v2/api/communicatePlan/detail';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const API_PATH = '/pro/v2/api/communicatePlan/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, defaultUrl) {
|
|
28
|
-
const apiPath = new URL(defaultUrl).pathname;
|
|
29
|
-
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
7
|
function makeErrorRow(code, msg) {
|
|
33
8
|
return [{ dataId: '', formId: '', addTime: '', updateTime: '', data: '', code, msg }];
|
|
34
9
|
}
|
|
@@ -54,23 +29,22 @@ cli({
|
|
|
54
29
|
const payload = { dataId: Number(kwargs.dataId || 0), corpid };
|
|
55
30
|
if (kwargs.userId) payload.userId = String(kwargs.userId);
|
|
56
31
|
if (String(kwargs.queryFlag ?? '') !== '') payload.queryFlag = Number(kwargs.queryFlag);
|
|
57
|
-
const body = JSON.stringify(payload);
|
|
58
32
|
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
59
33
|
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
60
34
|
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
35
|
+
const gateway = await requestGateway({
|
|
36
|
+
baseUrl,
|
|
37
|
+
apiPath: API_PATH,
|
|
38
|
+
payload,
|
|
39
|
+
token,
|
|
40
|
+
userId,
|
|
41
|
+
debug,
|
|
42
|
+
});
|
|
43
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
44
|
+
if (gateway.data.code !== 1) {
|
|
45
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
66
46
|
}
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
const data = await resp.json();
|
|
70
|
-
const responseBody = JSON.stringify(data);
|
|
71
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
72
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
73
|
-
const result = data.result || {};
|
|
74
|
-
return [{ dataId: result.dataId || '', formId: result.formId || '', addTime: result.addTime || '', updateTime: result.updateTime || '', data: JSON.stringify(result.data || {}), code: data.code ?? '', msg: data.msg || '' }];
|
|
47
|
+
const result = gateway.data.result || {};
|
|
48
|
+
return [{ dataId: result.dataId || '', formId: result.formId || '', addTime: result.addTime || '', updateTime: result.updateTime || '', data: JSON.stringify(result.data || {}), code: gateway.data.code ?? '', msg: gateway.data.msg || '' }];
|
|
75
49
|
},
|
|
76
50
|
});
|
package/communicate-plan-list.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, createPagination } from './xbb-http.js';
|
|
7
3
|
|
|
8
|
-
const
|
|
9
|
-
const API_URL = 'https://proapi.xbongbong.com/pro/v2/api/communicatePlan/list';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const API_PATH = '/pro/v2/api/communicatePlan/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, defaultUrl) {
|
|
29
|
-
const apiPath = new URL(defaultUrl).pathname;
|
|
30
|
-
return `${baseUrl.replace(/\/+$/, '')}${apiPath}`;
|
|
31
|
-
}
|
|
6
|
+
const pagination = createPagination();
|
|
32
7
|
|
|
33
8
|
function normalizeConditionValue(value) {
|
|
34
9
|
const stringValue = String(value);
|
|
@@ -79,7 +54,7 @@ cli({
|
|
|
79
54
|
{ name: 'raw', type: 'bool', default: false, help: '输出接口返回的原文' },
|
|
80
55
|
],
|
|
81
56
|
columns: ['rank', 'dataId', 'formId', 'name', 'customer', 'remindType', 'visitType', 'visitTime', 'addTime', 'updateTime', 'data', 'code', 'msg'],
|
|
82
|
-
footerExtra:
|
|
57
|
+
footerExtra: pagination.footerExtra,
|
|
83
58
|
func: async (kwargs) => {
|
|
84
59
|
const debug = Boolean(kwargs.debug);
|
|
85
60
|
let conditions;
|
|
@@ -99,27 +74,24 @@ cli({
|
|
|
99
74
|
if (String(kwargs.pageSize ?? '') !== '') payload.pageSize = Number(kwargs.pageSize);
|
|
100
75
|
if (payloadUserId) payload.userId = payloadUserId;
|
|
101
76
|
if (conditions.length) payload.conditions = conditions;
|
|
102
|
-
const body = JSON.stringify(payload);
|
|
103
77
|
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
104
78
|
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
105
79
|
if (!conditions.length) return makeErrorRow('NO_CONDITIONS', '缺少筛选条件,请传 --conditions 或 --attr/--value');
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
80
|
+
const gateway = await requestGateway({
|
|
81
|
+
baseUrl,
|
|
82
|
+
apiPath: API_PATH,
|
|
83
|
+
payload,
|
|
84
|
+
token,
|
|
85
|
+
userId,
|
|
86
|
+
debug,
|
|
87
|
+
});
|
|
88
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
89
|
+
pagination.update(gateway.data);
|
|
90
|
+
if (kwargs.raw) return [{ raw: gateway.responseBody }];
|
|
91
|
+
if (gateway.data.code !== 1) {
|
|
92
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
111
93
|
}
|
|
112
|
-
const
|
|
113
|
-
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
114
|
-
const data = await resp.json();
|
|
115
|
-
lastPagination = data?.code === 1 && data?.result?.totalCount != null && data?.result?.totalPage != null
|
|
116
|
-
? { totalCount: data.result.totalCount, totalPage: data.result.totalPage }
|
|
117
|
-
: null;
|
|
118
|
-
const responseBody = JSON.stringify(data);
|
|
119
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
120
|
-
if (kwargs.raw) return [{ raw: responseBody }];
|
|
121
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
122
|
-
const list = Array.isArray(data.result?.list) ? data.result.list : [];
|
|
94
|
+
const list = Array.isArray(gateway.data.result?.list) ? gateway.data.result.list : [];
|
|
123
95
|
if (!list.length) return makeErrorRow('NO_DATA', '接口成功,但 list 为空');
|
|
124
96
|
return list.map((item, index) => ({ rank: index + 1, dataId: item.dataId || '', formId: item.formId || '', name: item.data?.text_1 || '', customer: item.data?.text_2 || '', remindType: item.data?.text_5 || '', visitType: item.data?.text_4 || '', visitTime: item.data?.date_1 || '', addTime: item.addTime || '', updateTime: item.updateTime || '', data: JSON.stringify(item.data || {}), code: '', msg: '' }));
|
|
125
97
|
},
|
|
@@ -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 API_URL = 'https://proapi.xbongbong.com/pro/v2/api/communicatePlan/singleOperate';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const API_PATH = '/pro/v2/api/communicatePlan/singleOperate';
|
|
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 makeErrorRow(code, msg) {
|
|
33
8
|
return [{ code, msg }];
|
|
34
9
|
}
|
|
@@ -61,23 +36,23 @@ cli({
|
|
|
61
36
|
};
|
|
62
37
|
if (kwargs.userId) payload.userId = String(kwargs.userId);
|
|
63
38
|
if (String(kwargs.delayMemo ?? '') !== '') payload.delayMemo = String(kwargs.delayMemo);
|
|
64
|
-
const requestBody = JSON.stringify(payload);
|
|
65
39
|
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
66
40
|
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
67
41
|
if (!payload.delayCause) return makeErrorRow('NO_DELAYCAUSE', '缺少 --delayCause');
|
|
68
42
|
if (!payload.delayTime) return makeErrorRow('NO_DELAYTIME', '缺少 --delayTime');
|
|
69
43
|
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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 ?? '未知错误');
|
|
74
55
|
}
|
|
75
|
-
|
|
76
|
-
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
77
|
-
const data = await resp.json();
|
|
78
|
-
const responseBody = JSON.stringify(data);
|
|
79
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
80
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
81
|
-
return [{ code: data.code ?? '', msg: data.msg || '' }];
|
|
56
|
+
return [{ code: gateway.data.code ?? '', msg: gateway.data.msg || '' }];
|
|
82
57
|
},
|
|
83
58
|
});
|
package/contact-add-couser.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/contact/addCoUser';
|
|
10
|
-
const DEFAULT_BASE_URL = 'https://proapi.xbongbong.com';
|
|
4
|
+
const API_PATH = '/pro/v2/api/contact/addCoUser';
|
|
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 makeErrorRow(code, msg) {
|
|
33
8
|
return [{ resultCode: '', resultMsg: '', messageList: '', code, msg }];
|
|
34
9
|
}
|
|
@@ -62,23 +37,23 @@ cli({
|
|
|
62
37
|
}
|
|
63
38
|
if (Array.isArray(businessUserIdList)) payload.businessUserIdList = businessUserIdList;
|
|
64
39
|
|
|
65
|
-
const requestBody = JSON.stringify(payload);
|
|
66
40
|
if (!payload.dataId) return makeErrorRow('NO_DATAID', '缺少 --dataId');
|
|
67
41
|
if (!payload.corpid) return makeErrorRow('NO_CORPID', '缺少本地 corpid;请先执行 xbbcli token-set --corpid <CORPID> --token <TOKEN> --userId <USERID>');
|
|
68
42
|
if (!Array.isArray(businessUserIdList) || !businessUserIdList.length) return makeErrorRow('NO_USERIDLIST', '缺少 --businessUserIdList 或格式不正确,需为JSON数组');
|
|
69
43
|
if (!token) return makeErrorRow('NO_TOKEN', MISSING_TOKEN_MESSAGE);
|
|
70
44
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
45
|
+
const gateway = await requestGateway({
|
|
46
|
+
baseUrl,
|
|
47
|
+
apiPath: API_PATH,
|
|
48
|
+
payload,
|
|
49
|
+
token,
|
|
50
|
+
userId,
|
|
51
|
+
debug,
|
|
52
|
+
});
|
|
53
|
+
if (!gateway.ok) return makeErrorRow(gateway.code, gateway.msg);
|
|
54
|
+
if (gateway.data.code !== 1) {
|
|
55
|
+
return makeErrorRow(gateway.data.code ?? '', gateway.data.msg ?? '未知错误');
|
|
75
56
|
}
|
|
76
|
-
|
|
77
|
-
if (!resp.ok) return makeErrorRow(resp.status, `HTTP ${resp.status} ${resp.statusText}`);
|
|
78
|
-
const data = await resp.json();
|
|
79
|
-
const responseBody = JSON.stringify(data);
|
|
80
|
-
if (debug) process.stderr.write(`[debug] ResponseBody: ${responseBody}\n`);
|
|
81
|
-
if (data.code !== 1) return makeErrorRow(data.code ?? '', data.msg ?? '未知错误');
|
|
82
|
-
return [{ resultCode: data.code ?? '', resultMsg: data.msg || '', messageList: JSON.stringify(data.result?.messageList || []), code: data.code ?? '', msg: data.msg || '' }];
|
|
57
|
+
return [{ resultCode: gateway.data.code ?? '', resultMsg: gateway.data.msg || '', messageList: JSON.stringify(gateway.data.result?.messageList || []), code: gateway.data.code ?? '', msg: gateway.data.msg || '' }];
|
|
83
58
|
},
|
|
84
59
|
});
|