eprolo-cli 1.0.72 → 1.0.74
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 +20 -11
- 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_list.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,29 +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
206
|
console.log(JSON.stringify(data, null, 2));
|
|
207
207
|
process.exit(0);
|
|
208
208
|
}
|
|
209
209
|
async function queryOrderList() {
|
|
210
210
|
const config = readConfig();
|
|
211
|
-
|
|
212
|
-
|
|
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" }));
|
|
213
219
|
process.exit(1);
|
|
214
220
|
}
|
|
215
|
-
const data = await postJsonWithRetry(
|
|
221
|
+
const data = await postJsonWithRetry(PRODUCT_TYPE_API, {id:productId}, config, "GET");
|
|
216
222
|
console.log(JSON.stringify(data, null, 2));
|
|
217
223
|
process.exit(0);
|
|
218
224
|
}
|
|
219
|
-
|
|
220
225
|
// ---------------------------------------------------------------------------
|
|
221
226
|
// help
|
|
222
227
|
// ---------------------------------------------------------------------------
|
|
@@ -283,7 +288,11 @@ async function main() {
|
|
|
283
288
|
await queryOrderList();
|
|
284
289
|
return;
|
|
285
290
|
}
|
|
286
|
-
|
|
291
|
+
if (argv[0] === "product") {
|
|
292
|
+
await queryProductId(argv[1]);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
287
296
|
printHelp();
|
|
288
297
|
}
|
|
289
298
|
|
package/package.json
CHANGED