eprolo-cli 1.0.55 → 1.0.56
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 +27 -31
- package/package.json +1 -1
package/bin/eprolo-cli.js
CHANGED
|
@@ -91,29 +91,27 @@ async function postJsonWithRetry(url, body, config) {
|
|
|
91
91
|
|
|
92
92
|
let result = await postJson(url, body, headers);
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// }
|
|
116
|
-
// }
|
|
94
|
+
if (result.code === 401) {
|
|
95
|
+
// 刷新 token
|
|
96
|
+
const refreshRes = await postJson(REFRESH_API, {},{
|
|
97
|
+
refreshToken: config.refreshToken
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (refreshRes.code === 0 && refreshRes.data.accessToken) {
|
|
101
|
+
// 更新凭据文件
|
|
102
|
+
config.accessToken = refreshRes.data.accessToken;
|
|
103
|
+
if (refreshRes.data.account) config.account = refreshRes.data.account;
|
|
104
|
+
writeConfig(config);
|
|
105
|
+
|
|
106
|
+
// 用新 token 重试
|
|
107
|
+
headers["accessToken"] = `${config.accessToken}`;
|
|
108
|
+
result = await postJson(url, body, headers);
|
|
109
|
+
} else {
|
|
110
|
+
const err = new Error("Token 刷新失败,请重新登录授权");
|
|
111
|
+
err.response = refreshRes.data;
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
117
115
|
|
|
118
116
|
if (result.code !== 0) {
|
|
119
117
|
const err = new Error(`HTTP ${result.statusCode}`);
|
|
@@ -132,23 +130,21 @@ async function login(argv) {
|
|
|
132
130
|
const userCode = process.env.EPROLO_USER_CODE; // env 通道
|
|
133
131
|
if (!userCode) { console.error("缺少用户密文:请在授权弹窗中填写"); process.exit(2); }
|
|
134
132
|
|
|
135
|
-
const defaultShop = readFlag(argv, "--default-shop"); // arg 通道,可能不存在
|
|
136
|
-
|
|
137
133
|
const res = await postJson(LOGIN_API, { openApiKey: userCode });
|
|
138
134
|
|
|
139
|
-
if (res.
|
|
135
|
+
if (res.code !== 0) {
|
|
140
136
|
console.error(JSON.stringify({
|
|
141
137
|
success: false,
|
|
142
|
-
errorMessage: "
|
|
143
|
-
statusCode: res.
|
|
138
|
+
errorMessage: res.error || "登录失败",
|
|
139
|
+
statusCode: res.code,
|
|
144
140
|
response: res.data
|
|
145
141
|
}));
|
|
146
142
|
process.exit(1);
|
|
147
143
|
}
|
|
148
144
|
|
|
149
|
-
const { account, accessToken, accountId, shopId } = res.data;
|
|
150
|
-
const config = { account, accessToken, defaultShop, accountId, shopId, version: 1 };
|
|
151
|
-
writeConfig(
|
|
145
|
+
// const { account, accessToken, accountId, shopId } = res.data;
|
|
146
|
+
// const config = { account, accessToken, defaultShop, accountId, shopId, version: 1 };
|
|
147
|
+
writeConfig(res.data);
|
|
152
148
|
|
|
153
149
|
console.log("login ok");
|
|
154
150
|
process.exit(0);
|
package/package.json
CHANGED