@base44-preview/cli 0.0.54-pr.537.b8591fe → 0.0.54-pr.537.eba1e24
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 +5 -5
- 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
|
}
|
|
@@ -244385,6 +244397,7 @@ async function login({
|
|
|
244385
244397
|
|
|
244386
244398
|
// src/cli/utils/command/middleware.ts
|
|
244387
244399
|
async function ensureAuth(ctx) {
|
|
244400
|
+
await seedAuthFromEnv();
|
|
244388
244401
|
const loggedIn = await isLoggedIn();
|
|
244389
244402
|
if (!loggedIn) {
|
|
244390
244403
|
ctx.log.info("You need to login first to continue.");
|
|
@@ -251767,8 +251780,7 @@ function getLogoutCommand() {
|
|
|
251767
251780
|
// src/cli/commands/auth/whoami.ts
|
|
251768
251781
|
async function whoami(_ctx) {
|
|
251769
251782
|
const auth2 = await readAuth();
|
|
251770
|
-
|
|
251771
|
-
return { outroMessage: `Logged in as: ${theme.styles.bold(identity4)}` };
|
|
251783
|
+
return { outroMessage: `Logged in as: ${theme.styles.bold(auth2.email)}` };
|
|
251772
251784
|
}
|
|
251773
251785
|
function getWhoamiCommand() {
|
|
251774
251786
|
return new Base44Command("whoami", { requireAppConfig: false }).description("Display current authenticated user").action(whoami);
|
|
@@ -261661,4 +261673,4 @@ export {
|
|
|
261661
261673
|
CLIExitError
|
|
261662
261674
|
};
|
|
261663
261675
|
|
|
261664
|
-
//# debugId=
|
|
261676
|
+
//# debugId=1EB78D62F7CFAAF364756E2164756E21
|