clishop 1.3.2 → 1.4.0
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/dist/{chunk-ML7L6BAH.js → chunk-EAXPWOMT.js} +6 -43
- package/dist/index.js +204 -781
- package/dist/mcp.js +63 -6
- package/package.json +1 -1
|
@@ -104,25 +104,6 @@ async function deletePassword(account) {
|
|
|
104
104
|
}
|
|
105
105
|
fileDeletePassword(SERVICE_NAME, account);
|
|
106
106
|
}
|
|
107
|
-
function assertAuthResponse(data) {
|
|
108
|
-
const payload = data;
|
|
109
|
-
if (!payload || typeof payload !== "object") {
|
|
110
|
-
throw new Error("Invalid auth response from server.");
|
|
111
|
-
}
|
|
112
|
-
if (!payload.token || typeof payload.token !== "string") {
|
|
113
|
-
throw new Error("Auth response missing access token.");
|
|
114
|
-
}
|
|
115
|
-
if (payload.refreshToken !== void 0 && typeof payload.refreshToken !== "string") {
|
|
116
|
-
throw new Error("Auth response has an invalid refresh token.");
|
|
117
|
-
}
|
|
118
|
-
if (!payload.user || typeof payload.user !== "object") {
|
|
119
|
-
throw new Error("Auth response missing user profile.");
|
|
120
|
-
}
|
|
121
|
-
if (!payload.user.id || !payload.user.email || !payload.user.name) {
|
|
122
|
-
throw new Error("Auth response user profile is incomplete.");
|
|
123
|
-
}
|
|
124
|
-
return payload;
|
|
125
|
-
}
|
|
126
107
|
async function storeToken(token) {
|
|
127
108
|
await setPassword(ACCOUNT_TOKEN, token);
|
|
128
109
|
}
|
|
@@ -155,27 +136,10 @@ async function clearAuth() {
|
|
|
155
136
|
async function isLoggedIn() {
|
|
156
137
|
return !!await getToken();
|
|
157
138
|
}
|
|
158
|
-
async function
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
await storeToken(token);
|
|
163
|
-
if (refreshToken) await storeRefreshToken(refreshToken);
|
|
164
|
-
await storeUserInfo(user);
|
|
165
|
-
return user;
|
|
166
|
-
}
|
|
167
|
-
async function register(email, password, name, monthlySpendingLimitInCents) {
|
|
168
|
-
const baseUrl = getApiBaseUrl();
|
|
169
|
-
const body = { email, password, name };
|
|
170
|
-
if (monthlySpendingLimitInCents !== void 0) {
|
|
171
|
-
body.monthlySpendingLimitInCents = monthlySpendingLimitInCents;
|
|
172
|
-
}
|
|
173
|
-
const res = await axios.post(`${baseUrl}/auth/register`, body);
|
|
174
|
-
const { token, refreshToken, user } = assertAuthResponse(res.data);
|
|
175
|
-
await storeToken(token);
|
|
176
|
-
if (refreshToken) await storeRefreshToken(refreshToken);
|
|
177
|
-
await storeUserInfo(user);
|
|
178
|
-
return user;
|
|
139
|
+
async function storeAuthFromSetup(data) {
|
|
140
|
+
await storeToken(data.token);
|
|
141
|
+
await storeRefreshToken(data.refreshToken);
|
|
142
|
+
await storeUserInfo(data.user);
|
|
179
143
|
}
|
|
180
144
|
async function logout() {
|
|
181
145
|
const baseUrl = getApiBaseUrl();
|
|
@@ -241,7 +205,7 @@ function getApiClient() {
|
|
|
241
205
|
} catch {
|
|
242
206
|
}
|
|
243
207
|
}
|
|
244
|
-
console.error(chalk.red("\n\u2717 Session expired. Please
|
|
208
|
+
console.error(chalk.red("\n\u2717 Session expired. Please run: clishop setup\n"));
|
|
245
209
|
process.exit(1);
|
|
246
210
|
}
|
|
247
211
|
throw error;
|
|
@@ -297,8 +261,7 @@ export {
|
|
|
297
261
|
getToken,
|
|
298
262
|
getUserInfo,
|
|
299
263
|
isLoggedIn,
|
|
300
|
-
|
|
301
|
-
register,
|
|
264
|
+
storeAuthFromSetup,
|
|
302
265
|
logout,
|
|
303
266
|
getApiClient,
|
|
304
267
|
ensureAgentOnBackend,
|