@base44-preview/cli 0.0.30-pr.223.517d2cd → 0.0.30-pr.225.09b17d9

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
@@ -136896,12 +136896,12 @@ var require_linker = __commonJS((exports) => {
136896
136896
  var require_optionValidator = __commonJS((exports) => {
136897
136897
  Object.defineProperty(exports, "__esModule", { value: true });
136898
136898
  exports.validateOptions = undefined;
136899
- function validateOptions2({ maxItems }) {
136899
+ function validateOptions3({ maxItems }) {
136900
136900
  if (maxItems !== undefined && maxItems < -1) {
136901
136901
  throw RangeError(`Expected options.maxItems to be >= -1, but was given ${maxItems}.`);
136902
136902
  }
136903
136903
  }
136904
- exports.validateOptions = validateOptions2;
136904
+ exports.validateOptions = validateOptions3;
136905
136905
  });
136906
136906
 
136907
136907
  // node_modules/json-schema-to-typescript/dist/src/index.js
@@ -152521,6 +152521,24 @@ class FileReadError extends SystemError {
152521
152521
  });
152522
152522
  }
152523
152523
  }
152524
+
152525
+ class FunctionNotFoundError extends ApiError {
152526
+ constructor(functionName, cause) {
152527
+ super(`Function "${functionName}" was not found in this app`, {
152528
+ statusCode: 404,
152529
+ cause,
152530
+ hints: [
152531
+ {
152532
+ message: "Make sure the function name is correct and has been deployed",
152533
+ command: "base44 functions deploy"
152534
+ },
152535
+ {
152536
+ message: "List project functions by checking the base44/functions/ directory"
152537
+ }
152538
+ ]
152539
+ });
152540
+ }
152541
+ }
152524
152542
  class TypeGenerationError extends SystemError {
152525
152543
  code = "TYPE_GENERATION_ERROR";
152526
152544
  entityName;
@@ -154019,6 +154037,13 @@ var DeployFunctionsResponseSchema = exports_external.object({
154019
154037
  skipped: exports_external.array(exports_external.string()).optional().nullable(),
154020
154038
  errors: exports_external.array(exports_external.object({ name: exports_external.string(), message: exports_external.string() })).nullable()
154021
154039
  });
154040
+ var LogLevelSchema = exports_external.enum(["log", "info", "warn", "error", "debug"]);
154041
+ var FunctionLogEntrySchema = exports_external.object({
154042
+ time: exports_external.string(),
154043
+ level: LogLevelSchema,
154044
+ message: exports_external.string()
154045
+ });
154046
+ var FunctionLogsResponseSchema = exports_external.array(FunctionLogEntrySchema);
154022
154047
 
154023
154048
  // src/core/resources/function/api.ts
154024
154049
  function toDeployPayloadItem(fn) {
@@ -154049,6 +154074,55 @@ async function deployFunctions(functions) {
154049
154074
  }
154050
154075
  return result.data;
154051
154076
  }
154077
+ function buildLogsQueryString(filters) {
154078
+ const params = new URLSearchParams;
154079
+ if (filters.since) {
154080
+ params.set("since", filters.since);
154081
+ }
154082
+ if (filters.until) {
154083
+ params.set("until", filters.until);
154084
+ }
154085
+ if (filters.level) {
154086
+ params.set("level", filters.level);
154087
+ }
154088
+ if (filters.limit !== undefined) {
154089
+ params.set("limit", String(filters.limit));
154090
+ }
154091
+ if (filters.order) {
154092
+ params.set("order", filters.order);
154093
+ }
154094
+ const queryString = params.toString();
154095
+ return queryString ? `?${queryString}` : "";
154096
+ }
154097
+ async function fetchFunctionLogs(functionName, filters = {}) {
154098
+ const appClient = getAppClient();
154099
+ const queryString = buildLogsQueryString(filters);
154100
+ let response;
154101
+ try {
154102
+ response = await appClient.get(`functions-mgmt/${functionName}/logs${queryString}`);
154103
+ } catch (error48) {
154104
+ if (error48 instanceof HTTPError) {
154105
+ if (error48.response.status === 404) {
154106
+ throw new FunctionNotFoundError(functionName, error48);
154107
+ }
154108
+ try {
154109
+ const body = await error48.response.clone().json();
154110
+ if (body.error_type === "KeyError") {
154111
+ throw new FunctionNotFoundError(functionName, error48);
154112
+ }
154113
+ } catch (parseError) {
154114
+ if (parseError instanceof ApiError)
154115
+ throw parseError;
154116
+ }
154117
+ }
154118
+ throw await ApiError.fromHttpError(error48, `fetching function logs: '${functionName}'`);
154119
+ }
154120
+ const result = FunctionLogsResponseSchema.safeParse(await response.json());
154121
+ if (!result.success) {
154122
+ throw new SchemaValidationError("Invalid function logs response from server", result.error);
154123
+ }
154124
+ return result.data;
154125
+ }
154052
154126
  // src/core/resources/function/config.ts
154053
154127
  import { dirname as dirname3, join as join3 } from "node:path";
154054
154128
  async function readFunctionConfig(configPath) {
@@ -168812,14 +168886,18 @@ async function printUpgradeNotificationIfAvailable() {
168812
168886
 
168813
168887
  // src/cli/utils/runCommand.ts
168814
168888
  async function runCommand(commandFn, options, context) {
168815
- console.log();
168816
- if (options?.fullBanner) {
168817
- await printBanner();
168818
- Ie("");
168819
- } else {
168820
- Ie(theme.colors.base44OrangeBackground(" Base 44 "));
168889
+ const skipIntro = options?.skipIntro === true;
168890
+ const skipOutro = options?.skipOutro === true;
168891
+ if (!skipIntro) {
168892
+ console.log();
168893
+ if (options?.fullBanner) {
168894
+ await printBanner();
168895
+ Ie("");
168896
+ } else {
168897
+ Ie(theme.colors.base44OrangeBackground(" Base 44 "));
168898
+ }
168899
+ await printUpgradeNotificationIfAvailable();
168821
168900
  }
168822
- await printUpgradeNotificationIfAvailable();
168823
168901
  try {
168824
168902
  if (options?.requireAuth) {
168825
168903
  const loggedIn = await isLoggedIn();
@@ -168839,7 +168917,9 @@ async function runCommand(commandFn, options, context) {
168839
168917
  context.errorReporter.setContext({ appId: appConfig.id });
168840
168918
  }
168841
168919
  const { outroMessage } = await commandFn();
168842
- Se(outroMessage || "");
168920
+ if (!skipOutro) {
168921
+ Se(outroMessage || "");
168922
+ }
168843
168923
  } catch (error48) {
168844
168924
  const errorMessage = error48 instanceof Error ? error48.message : String(error48);
168845
168925
  M2.error(errorMessage);
@@ -168853,7 +168933,12 @@ async function runCommand(commandFn, options, context) {
168853
168933
  }
168854
168934
  }
168855
168935
  const errorContext = context.errorReporter.getErrorContext();
168856
- Se(theme.format.errorContext(errorContext));
168936
+ if (!skipOutro) {
168937
+ Se(theme.format.errorContext(errorContext));
168938
+ } else {
168939
+ process.stderr.write(`${theme.format.errorContext(errorContext)}
168940
+ `);
168941
+ }
168857
168942
  throw error48;
168858
168943
  }
168859
168944
  }
@@ -169669,6 +169754,152 @@ function getFunctionsDeployCommand(context) {
169669
169754
  }));
169670
169755
  }
169671
169756
 
169757
+ // src/cli/commands/logs/index.ts
169758
+ var VALID_LEVELS = ["log", "info", "warn", "error", "debug"];
169759
+ function parseFunctionFilters(options) {
169760
+ const filters = {};
169761
+ if (options.since) {
169762
+ filters.since = options.since;
169763
+ }
169764
+ if (options.until) {
169765
+ filters.until = options.until;
169766
+ }
169767
+ if (options.level) {
169768
+ filters.level = options.level;
169769
+ }
169770
+ if (options.limit) {
169771
+ filters.limit = Number.parseInt(options.limit, 10);
169772
+ }
169773
+ if (options.order) {
169774
+ filters.order = options.order.toLowerCase();
169775
+ }
169776
+ return filters;
169777
+ }
169778
+ function parseFunctionNames(option) {
169779
+ if (!option)
169780
+ return [];
169781
+ return option.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
169782
+ }
169783
+ function normalizeDatetime(value) {
169784
+ if (/Z$|[+-]\d{2}:\d{2}$/.test(value))
169785
+ return value;
169786
+ return `${value}Z`;
169787
+ }
169788
+ function validateOptions2(options) {
169789
+ if (options.level && !VALID_LEVELS.includes(options.level)) {
169790
+ throw new InvalidInputError(`Invalid level: "${options.level}". Must be one of: ${VALID_LEVELS.join(", ")}.`);
169791
+ }
169792
+ if (options.limit) {
169793
+ const limit = Number.parseInt(options.limit, 10);
169794
+ if (Number.isNaN(limit) || limit < 1 || limit > 1000) {
169795
+ throw new InvalidInputError(`Invalid limit: "${options.limit}". Must be a number between 1 and 1000.`);
169796
+ }
169797
+ }
169798
+ if (options.order) {
169799
+ const order = options.order.toUpperCase();
169800
+ if (order !== "ASC" && order !== "DESC") {
169801
+ throw new InvalidInputError(`Invalid order: "${options.order}". Must be "ASC" or "DESC".`);
169802
+ }
169803
+ }
169804
+ }
169805
+ function formatEntry(entry) {
169806
+ const time3 = entry.time.substring(0, 19).replace("T", " ");
169807
+ const level = entry.level.toUpperCase().padEnd(5);
169808
+ const message = entry.message.trim();
169809
+ return `${time3} ${level} ${message}
169810
+ `;
169811
+ }
169812
+ function displayLogs(entries) {
169813
+ if (entries.length === 0) {
169814
+ process.stdout.write(`No logs found matching the filters.
169815
+ `);
169816
+ return;
169817
+ }
169818
+ process.stdout.write(`Showing ${entries.length} function log entries
169819
+
169820
+ `);
169821
+ for (const entry of entries) {
169822
+ process.stdout.write(formatEntry(entry));
169823
+ }
169824
+ }
169825
+ function normalizeLogEntry(entry, functionName) {
169826
+ return {
169827
+ time: entry.time,
169828
+ level: entry.level,
169829
+ message: `[${functionName}] ${entry.message}`,
169830
+ source: functionName
169831
+ };
169832
+ }
169833
+ async function fetchLogsForFunctions(functionNames, options, availableFunctionNames) {
169834
+ const filters = parseFunctionFilters(options);
169835
+ const allEntries = [];
169836
+ for (const functionName of functionNames) {
169837
+ let logs;
169838
+ try {
169839
+ logs = await fetchFunctionLogs(functionName, filters);
169840
+ } catch (error48) {
169841
+ if (error48 instanceof FunctionNotFoundError && availableFunctionNames.length > 0) {
169842
+ const available = availableFunctionNames.join(", ");
169843
+ throw new InvalidInputError(`Function "${functionName}" was not found in this app`, {
169844
+ hints: [
169845
+ {
169846
+ message: `Available functions in this project: ${available}`
169847
+ },
169848
+ {
169849
+ message: "Make sure the function has been deployed before fetching logs",
169850
+ command: "base44 functions deploy"
169851
+ }
169852
+ ]
169853
+ });
169854
+ }
169855
+ throw error48;
169856
+ }
169857
+ const entries = logs.map((entry) => normalizeLogEntry(entry, functionName));
169858
+ allEntries.push(...entries);
169859
+ }
169860
+ if (functionNames.length > 1) {
169861
+ const order = options.order?.toUpperCase() === "ASC" ? 1 : -1;
169862
+ allEntries.sort((a2, b3) => order * a2.time.localeCompare(b3.time));
169863
+ }
169864
+ return allEntries;
169865
+ }
169866
+ async function getAllFunctionNames() {
169867
+ const { functions } = await readProjectConfig();
169868
+ return functions.map((fn) => fn.name);
169869
+ }
169870
+ async function logsAction(options) {
169871
+ if (options.since)
169872
+ options.since = normalizeDatetime(options.since);
169873
+ if (options.until)
169874
+ options.until = normalizeDatetime(options.until);
169875
+ validateOptions2(options);
169876
+ const specifiedFunctions = parseFunctionNames(options.function);
169877
+ const allProjectFunctions = await getAllFunctionNames();
169878
+ const functionNames = specifiedFunctions.length > 0 ? specifiedFunctions : allProjectFunctions;
169879
+ if (functionNames.length === 0) {
169880
+ process.stdout.write(`No functions found in this project.
169881
+ `);
169882
+ return {};
169883
+ }
169884
+ let entries = await fetchLogsForFunctions(functionNames, options, allProjectFunctions);
169885
+ const limit = options.limit ? Number.parseInt(options.limit, 10) : undefined;
169886
+ if (limit !== undefined && entries.length > limit) {
169887
+ entries = entries.slice(0, limit);
169888
+ }
169889
+ if (options.json) {
169890
+ process.stdout.write(`${JSON.stringify(entries, null, 2)}
169891
+ `);
169892
+ } else {
169893
+ displayLogs(entries);
169894
+ }
169895
+ return {};
169896
+ }
169897
+ function getLogsCommand(context) {
169898
+ return new Command("logs").description("Fetch function logs for this app").option("--function <names>", "Filter by function name(s), comma-separated. If omitted, fetches logs for all project functions").option("--since <datetime>", "Show logs from this time (ISO format)").option("--until <datetime>", "Show logs until this time (ISO format)").option("--level <level>", "Filter by log level: log, info, warn, error, debug").option("-n, --limit <n>", "Results per page (1-1000, default: 50)").option("--order <order>", "Sort order: ASC|DESC (default: DESC)").option("--json", "Output raw JSON").action(async (options) => {
169899
+ await runCommand(() => logsAction(options), { requireAuth: true, skipIntro: true, skipOutro: true }, context);
169900
+ });
169901
+ }
169902
+
169672
169903
  // src/cli/commands/project/create.ts
169673
169904
  import { basename as basename3, join as join9, resolve as resolve2 } from "node:path";
169674
169905
  var import_lodash = __toESM(require_lodash(), 1);
@@ -170251,6 +170482,7 @@ function createProgram(context) {
170251
170482
  program2.addCommand(getFunctionsDeployCommand(context));
170252
170483
  program2.addCommand(getSiteCommand(context));
170253
170484
  program2.addCommand(getTypesCommand(context), { hidden: true });
170485
+ program2.addCommand(getLogsCommand(context));
170254
170486
  return program2;
170255
170487
  }
170256
170488
 
@@ -174517,4 +174749,4 @@ export {
174517
174749
  CLIExitError
174518
174750
  };
174519
174751
 
174520
- //# debugId=CAC914B71B29789364756E2164756E21
174752
+ //# debugId=8FC5567422BA15ED64756E2164756E21