eprolo-cli 1.0.71 → 1.0.73
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/bin/eprolo-cli.js +31 -8
- package/package.json +1 -1
package/bin/eprolo-cli.js
CHANGED
|
@@ -9,6 +9,7 @@ const https = require("https");
|
|
|
9
9
|
const LOGIN_API = "https://wixtest.eprolo.com/v1/auth/verifyCode.stm";
|
|
10
10
|
const REFRESH_API = "https://wixtest.eprolo.com/v1/auth/refresh-code";
|
|
11
11
|
const ORDERS_API = "https://wixtest.eprolo.com/order_list.html";
|
|
12
|
+
const PRODUCT_TYPE_API = "https://wixtest.eprolo.com/product_type.html";
|
|
12
13
|
const CONFIG_DIR = path.join(os.homedir(), ".eprolo-toolkit");
|
|
13
14
|
const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
14
15
|
|
|
@@ -92,7 +93,10 @@ function postJson(url, body, headers = {},method = "POST") {
|
|
|
92
93
|
async function postJsonWithRetry(url, body, config, method = "POST") {
|
|
93
94
|
let headers = {};
|
|
94
95
|
if (config.apiKey) headers["apiKey"] = `${config.apiKey}`;
|
|
95
|
-
|
|
96
|
+
if(config.timestamp){
|
|
97
|
+
body.timestamp = config.timestamp;
|
|
98
|
+
body.sign = config.accessToken;
|
|
99
|
+
}
|
|
96
100
|
let result = await postJson(url, body, headers, method);
|
|
97
101
|
if (result.data.code == 400) {
|
|
98
102
|
// 刷新 token
|
|
@@ -194,19 +198,30 @@ function authLogout() {
|
|
|
194
198
|
|
|
195
199
|
async function queryOrders(orderId) {
|
|
196
200
|
const config = readConfig();
|
|
197
|
-
if (!config.accessToken) {
|
|
198
|
-
console.error(JSON.stringify({ success: false, errorMessage: "未授权,请先登录" }));
|
|
199
|
-
process.exit(1);
|
|
200
|
-
}
|
|
201
201
|
if (!orderId) {
|
|
202
202
|
console.error(JSON.stringify({ success: false, errorMessage: "缺少订单 ID" }));
|
|
203
203
|
process.exit(1);
|
|
204
204
|
}
|
|
205
|
-
const data = await postJsonWithRetry(ORDERS_API, {
|
|
205
|
+
const data = await postJsonWithRetry(ORDERS_API, {}, config, "GET");
|
|
206
|
+
console.log(JSON.stringify(data, null, 2));
|
|
207
|
+
process.exit(0);
|
|
208
|
+
}
|
|
209
|
+
async function queryOrderList() {
|
|
210
|
+
const config = readConfig();
|
|
211
|
+
const data = await postJsonWithRetry(ORDERS_API, {}, config, "GET");
|
|
212
|
+
console.log(JSON.stringify(data, null, 2));
|
|
213
|
+
process.exit(0);
|
|
214
|
+
}
|
|
215
|
+
async function queryProductId(productId) {
|
|
216
|
+
const config = readConfig();
|
|
217
|
+
if (!productId) {
|
|
218
|
+
console.error(JSON.stringify({ success: false, errorMessage: "缺少产品 ID" }));
|
|
219
|
+
process.exit(1);
|
|
220
|
+
}
|
|
221
|
+
const data = await postJsonWithRetry(PRODUCT_TYPE_API, {id:productId}, config, "GET");
|
|
206
222
|
console.log(JSON.stringify(data, null, 2));
|
|
207
223
|
process.exit(0);
|
|
208
224
|
}
|
|
209
|
-
|
|
210
225
|
// ---------------------------------------------------------------------------
|
|
211
226
|
// help
|
|
212
227
|
// ---------------------------------------------------------------------------
|
|
@@ -269,7 +284,15 @@ async function main() {
|
|
|
269
284
|
await queryOrders(argv[2]);
|
|
270
285
|
return;
|
|
271
286
|
}
|
|
272
|
-
|
|
287
|
+
if (argv[0] === "list") {
|
|
288
|
+
await queryOrderList();
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (argv[0] === "product") {
|
|
292
|
+
await queryProductId(argv[1]);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
273
296
|
printHelp();
|
|
274
297
|
}
|
|
275
298
|
|
package/package.json
CHANGED