@base44-preview/cli 0.0.54-pr.538.01bc08e → 0.0.54-pr.538.31586c1
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/cli/index.js +30 -18
- package/dist/cli/index.js.map +8 -8
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -235154,24 +235154,39 @@ function getTestOverrides() {
|
|
|
235154
235154
|
// src/core/auth/config.ts
|
|
235155
235155
|
var TOKEN_REFRESH_BUFFER_MS = 60 * 1000;
|
|
235156
235156
|
var refreshPromise = null;
|
|
235157
|
-
function
|
|
235157
|
+
function decodeJwtClaims(token) {
|
|
235158
|
+
const parts = token.split(".");
|
|
235159
|
+
if (parts.length !== 3) {
|
|
235160
|
+
return null;
|
|
235161
|
+
}
|
|
235162
|
+
try {
|
|
235163
|
+
return JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
235164
|
+
} catch {
|
|
235165
|
+
return null;
|
|
235166
|
+
}
|
|
235167
|
+
}
|
|
235168
|
+
async function seedAuthFromEnv() {
|
|
235158
235169
|
const accessToken = process.env.BASE44_ACCESS_TOKEN;
|
|
235159
235170
|
if (!accessToken) {
|
|
235160
|
-
return
|
|
235171
|
+
return false;
|
|
235161
235172
|
}
|
|
235162
|
-
|
|
235173
|
+
const refreshToken = process.env.BASE44_REFRESH_TOKEN;
|
|
235174
|
+
const claims = decodeJwtClaims(accessToken);
|
|
235175
|
+
const sub = typeof claims?.sub === "string" ? claims.sub : undefined;
|
|
235176
|
+
const exp = typeof claims?.exp === "number" ? claims.exp : undefined;
|
|
235177
|
+
if (!refreshToken || !sub || !exp) {
|
|
235178
|
+
return false;
|
|
235179
|
+
}
|
|
235180
|
+
await writeAuth({
|
|
235163
235181
|
accessToken,
|
|
235164
|
-
refreshToken
|
|
235165
|
-
expiresAt:
|
|
235166
|
-
email:
|
|
235167
|
-
name:
|
|
235168
|
-
};
|
|
235182
|
+
refreshToken,
|
|
235183
|
+
expiresAt: exp * 1000,
|
|
235184
|
+
email: sub,
|
|
235185
|
+
name: sub
|
|
235186
|
+
});
|
|
235187
|
+
return true;
|
|
235169
235188
|
}
|
|
235170
235189
|
async function readAuth() {
|
|
235171
|
-
const envAuth = readEnvAuth();
|
|
235172
|
-
if (envAuth) {
|
|
235173
|
-
return envAuth;
|
|
235174
|
-
}
|
|
235175
235190
|
try {
|
|
235176
235191
|
const authData = await readJsonFile(getAuthFilePath());
|
|
235177
235192
|
const result = AuthDataSchema.safeParse(authData);
|
|
@@ -235208,9 +235223,6 @@ function isTokenExpired(auth) {
|
|
|
235208
235223
|
return Date.now() >= auth.expiresAt - TOKEN_REFRESH_BUFFER_MS;
|
|
235209
235224
|
}
|
|
235210
235225
|
async function refreshAndSaveTokens() {
|
|
235211
|
-
if (readEnvAuth()) {
|
|
235212
|
-
return null;
|
|
235213
|
-
}
|
|
235214
235226
|
if (refreshPromise) {
|
|
235215
235227
|
return refreshPromise;
|
|
235216
235228
|
}
|
|
@@ -244410,6 +244422,7 @@ async function login({
|
|
|
244410
244422
|
|
|
244411
244423
|
// src/cli/utils/command/middleware.ts
|
|
244412
244424
|
async function ensureAuth(ctx) {
|
|
244425
|
+
await seedAuthFromEnv();
|
|
244413
244426
|
const loggedIn = await isLoggedIn();
|
|
244414
244427
|
if (!loggedIn) {
|
|
244415
244428
|
ctx.log.info("You need to login first to continue.");
|
|
@@ -251792,8 +251805,7 @@ function getLogoutCommand() {
|
|
|
251792
251805
|
// src/cli/commands/auth/whoami.ts
|
|
251793
251806
|
async function whoami(_ctx) {
|
|
251794
251807
|
const auth2 = await readAuth();
|
|
251795
|
-
|
|
251796
|
-
return { outroMessage: `Logged in as: ${theme.styles.bold(identity4)}` };
|
|
251808
|
+
return { outroMessage: `Logged in as: ${theme.styles.bold(auth2.email)}` };
|
|
251797
251809
|
}
|
|
251798
251810
|
function getWhoamiCommand() {
|
|
251799
251811
|
return new Base44Command("whoami", { requireAppConfig: false }).description("Display current authenticated user").action(whoami);
|
|
@@ -261810,4 +261822,4 @@ export {
|
|
|
261810
261822
|
CLIExitError
|
|
261811
261823
|
};
|
|
261812
261824
|
|
|
261813
|
-
//# debugId=
|
|
261825
|
+
//# debugId=C760C3B8B75787D664756E2164756E21
|