eprolo-cli 1.0.68 → 1.0.70
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 +22 -10
- package/package.json +1 -1
package/bin/eprolo-cli.js
CHANGED
|
@@ -6,9 +6,9 @@ const os = require("os");
|
|
|
6
6
|
const path = require("path");
|
|
7
7
|
const https = require("https");
|
|
8
8
|
|
|
9
|
-
const LOGIN_API = "https://wixtest.eprolo.com/v1/auth/
|
|
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
|
-
const ORDERS_API = "https://wixtest.eprolo.com/
|
|
11
|
+
const ORDERS_API = "https://wixtest.eprolo.com/order_list.html";
|
|
12
12
|
const CONFIG_DIR = path.join(os.homedir(), ".eprolo-toolkit");
|
|
13
13
|
const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
14
14
|
|
|
@@ -44,7 +44,7 @@ function readFlag(argv, flag) {
|
|
|
44
44
|
// HTTPS POST 请求
|
|
45
45
|
// ---------------------------------------------------------------------------
|
|
46
46
|
|
|
47
|
-
function postJson(url, body, headers = {}) {
|
|
47
|
+
function postJson(url, body, headers = {},method = "POST") {
|
|
48
48
|
return new Promise((resolve, reject) => {
|
|
49
49
|
const target = new URL(url);
|
|
50
50
|
const payload = JSON.stringify(body);
|
|
@@ -52,7 +52,7 @@ function postJson(url, body, headers = {}) {
|
|
|
52
52
|
hostname: target.hostname,
|
|
53
53
|
port: target.port || 443,
|
|
54
54
|
path: `${target.pathname}${target.search}`,
|
|
55
|
-
method:
|
|
55
|
+
method: method,
|
|
56
56
|
headers: {
|
|
57
57
|
"content-type": "application/json",
|
|
58
58
|
"content-length": Buffer.byteLength(payload),
|
|
@@ -85,11 +85,11 @@ function postJson(url, body, headers = {}) {
|
|
|
85
85
|
// 3. 仍然 401 → 抛错
|
|
86
86
|
// ---------------------------------------------------------------------------
|
|
87
87
|
|
|
88
|
-
async function postJsonWithRetry(url, body, config) {
|
|
88
|
+
async function postJsonWithRetry(url, body, config, method = "POST") {
|
|
89
89
|
let headers = {};
|
|
90
|
-
if (config.
|
|
90
|
+
if (config.apiKey) headers["apiKey"] = `${config.apiKey}`;
|
|
91
91
|
|
|
92
|
-
let result = await postJson(url, body, headers);
|
|
92
|
+
let result = await postJson(url, body, headers, method);
|
|
93
93
|
if (result.data.code == 400) {
|
|
94
94
|
// 刷新 token
|
|
95
95
|
const refreshRes = await postJson(REFRESH_API, {},{
|
|
@@ -105,7 +105,19 @@ async function postJsonWithRetry(url, body, config) {
|
|
|
105
105
|
// 用新 token 重试
|
|
106
106
|
headers["accessToken"] = `${config.accessToken}`;
|
|
107
107
|
result = await postJson(url, body, headers);
|
|
108
|
-
}
|
|
108
|
+
}else if (refreshRes.data.code == 400) {
|
|
109
|
+
const res = await postJson(LOGIN_API, { openApiKey: config.openApiKey });
|
|
110
|
+
if (res.data.code != 0) {
|
|
111
|
+
const err = new Error(`HTTP ${res.statusCode}`);
|
|
112
|
+
err.response = res.data.data.msg;
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
115
|
+
res.data.data.openApiKey = config.openApiKey;
|
|
116
|
+
writeConfig(res.data.data);
|
|
117
|
+
headers["accessToken"] = `${res.data.data.accessToken}`;
|
|
118
|
+
result = await postJson(url, body, headers);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
109
121
|
const err = new Error("Token 刷新失败,请重新登录授权");
|
|
110
122
|
err.response = refreshRes.data;
|
|
111
123
|
throw err;
|
|
@@ -138,7 +150,7 @@ async function login(argv) {
|
|
|
138
150
|
}));
|
|
139
151
|
process.exit(1);
|
|
140
152
|
}
|
|
141
|
-
|
|
153
|
+
// res.data.data.openApiKey = userCode;
|
|
142
154
|
// const { account, accessToken, accountId, shopId } = res.data;
|
|
143
155
|
// const config = { account, accessToken, defaultShop, accountId, shopId, version: 1 };
|
|
144
156
|
writeConfig(res.data.data);
|
|
@@ -186,7 +198,7 @@ async function queryOrders(orderId) {
|
|
|
186
198
|
console.error(JSON.stringify({ success: false, errorMessage: "缺少订单 ID" }));
|
|
187
199
|
process.exit(1);
|
|
188
200
|
}
|
|
189
|
-
const data = await postJsonWithRetry(ORDERS_API, {id:orderId}, config);
|
|
201
|
+
const data = await postJsonWithRetry(ORDERS_API, {id:orderId}, config, "GET");
|
|
190
202
|
console.log(JSON.stringify(data, null, 2));
|
|
191
203
|
process.exit(0);
|
|
192
204
|
}
|
package/package.json
CHANGED