@base44-preview/cli 0.0.54-pr.538.31b00c3 → 0.0.54-pr.538.476f05c

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 CHANGED
@@ -235154,10 +235154,38 @@ 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 getEnvAccessToken() {
235158
- return process.env.BASE44_ACCESS_TOKEN || undefined;
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
+ function readEnvAuth() {
235169
+ const accessToken = process.env.BASE44_ACCESS_TOKEN;
235170
+ if (!accessToken) {
235171
+ return null;
235172
+ }
235173
+ const claims = decodeJwtClaims(accessToken);
235174
+ const sub = typeof claims?.sub === "string" ? claims.sub : "";
235175
+ const exp = typeof claims?.exp === "number" ? claims.exp : null;
235176
+ return {
235177
+ accessToken,
235178
+ refreshToken: process.env.BASE44_REFRESH_TOKEN ?? "",
235179
+ expiresAt: exp !== null ? exp * 1000 : Number.POSITIVE_INFINITY,
235180
+ email: sub,
235181
+ name: ""
235182
+ };
235159
235183
  }
235160
235184
  async function readAuth() {
235185
+ const envAuth = readEnvAuth();
235186
+ if (envAuth) {
235187
+ return envAuth;
235188
+ }
235161
235189
  try {
235162
235190
  const authData = await readJsonFile(getAuthFilePath());
235163
235191
  const result = AuthDataSchema.safeParse(authData);
@@ -235194,6 +235222,9 @@ function isTokenExpired(auth) {
235194
235222
  return Date.now() >= auth.expiresAt - TOKEN_REFRESH_BUFFER_MS;
235195
235223
  }
235196
235224
  async function refreshAndSaveTokens() {
235225
+ if (readEnvAuth()) {
235226
+ return null;
235227
+ }
235197
235228
  if (refreshPromise) {
235198
235229
  return refreshPromise;
235199
235230
  }
@@ -235218,9 +235249,6 @@ async function refreshAndSaveTokens() {
235218
235249
  return refreshPromise;
235219
235250
  }
235220
235251
  async function isLoggedIn() {
235221
- if (getEnvAccessToken()) {
235222
- return true;
235223
- }
235224
235252
  try {
235225
235253
  await readAuth();
235226
235254
  return true;
@@ -244171,9 +244199,6 @@ async function handleUnauthorized(request, _options, response) {
244171
244199
  if (retriedRequests.has(request)) {
244172
244200
  return;
244173
244201
  }
244174
- if (getEnvAccessToken()) {
244175
- return;
244176
- }
244177
244202
  const newAccessToken = await refreshAndSaveTokens();
244178
244203
  if (!newAccessToken) {
244179
244204
  return;
@@ -244200,11 +244225,6 @@ var base44Client = distribution_default.create({
244200
244225
  captureRequestBody,
244201
244226
  async (request) => {
244202
244227
  try {
244203
- const envToken = getEnvAccessToken();
244204
- if (envToken) {
244205
- request.headers.set("Authorization", `Bearer ${envToken}`);
244206
- return;
244207
- }
244208
244228
  const auth = await readAuth();
244209
244229
  if (isTokenExpired(auth)) {
244210
244230
  const newAccessToken = await refreshAndSaveTokens();
@@ -251786,7 +251806,8 @@ function getLogoutCommand() {
251786
251806
  // src/cli/commands/auth/whoami.ts
251787
251807
  async function whoami(_ctx) {
251788
251808
  const auth2 = await readAuth();
251789
- return { outroMessage: `Logged in as: ${theme.styles.bold(auth2.email)}` };
251809
+ const identity4 = auth2.email || "environment credentials";
251810
+ return { outroMessage: `Logged in as: ${theme.styles.bold(identity4)}` };
251790
251811
  }
251791
251812
  function getWhoamiCommand() {
251792
251813
  return new Base44Command("whoami", { requireAppConfig: false }).description("Display current authenticated user").action(whoami);
@@ -261803,4 +261824,4 @@ export {
261803
261824
  CLIExitError
261804
261825
  };
261805
261826
 
261806
- //# debugId=3C4BC63D9DD7271A64756E2164756E21
261827
+ //# debugId=408730CE1B96080164756E2164756E21