@base44-preview/cli 0.1.3-pr.568.67b756c → 0.1.3-pr.568.68320bd

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
@@ -161113,11 +161113,11 @@ var require_json4 = __commonJS((exports, module) => {
161113
161113
  var debug = require_src4()("body-parser:json");
161114
161114
  var read3 = require_read();
161115
161115
  var { normalizeOptions: normalizeOptions5 } = require_utils8();
161116
- module.exports = json3;
161116
+ module.exports = json2;
161117
161117
  var FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*([^\x20\x09\x0a\x0d])/;
161118
161118
  var JSON_SYNTAX_CHAR = "#";
161119
161119
  var JSON_SYNTAX_REGEXP = /#+/g;
161120
- function json3(options8) {
161120
+ function json2(options8) {
161121
161121
  const normalizedOptions = normalizeOptions5(options8, "application/json");
161122
161122
  var reviver = options8?.reviver;
161123
161123
  var strict = options8?.strict !== false;
@@ -168320,7 +168320,7 @@ var require_response = __commonJS((exports, module) => {
168320
168320
  }
168321
168321
  return this;
168322
168322
  };
168323
- res.json = function json3(obj) {
168323
+ res.json = function json2(obj) {
168324
168324
  var app = this.app;
168325
168325
  var escape3 = app.get("json escape");
168326
168326
  var replacer = app.get("json replacer");
@@ -168656,9 +168656,9 @@ var require_response = __commonJS((exports, module) => {
168656
168656
  file2.pipe(res2);
168657
168657
  }
168658
168658
  function stringify(value, replacer, spaces, escape3) {
168659
- var json3 = replacer || spaces ? JSON.stringify(value, replacer, spaces) : JSON.stringify(value);
168660
- if (escape3 && typeof json3 === "string") {
168661
- json3 = json3.replace(/[<>&]/g, function(c8) {
168659
+ var json2 = replacer || spaces ? JSON.stringify(value, replacer, spaces) : JSON.stringify(value);
168660
+ if (escape3 && typeof json2 === "string") {
168661
+ json2 = json2.replace(/[<>&]/g, function(c8) {
168662
168662
  switch (c8.charCodeAt(0)) {
168663
168663
  case 60:
168664
168664
  return "\\u003c";
@@ -168671,7 +168671,7 @@ var require_response = __commonJS((exports, module) => {
168671
168671
  }
168672
168672
  });
168673
168673
  }
168674
- return json3;
168674
+ return json2;
168675
168675
  }
168676
168676
  });
168677
168677
 
@@ -251335,11 +251335,6 @@ class Base44Command extends Command {
251335
251335
  });
251336
251336
  }
251337
251337
  }
251338
- // src/cli/utils/json.ts
251339
- function toJsonStdout(result) {
251340
- return `${JSON.stringify(result, null, 2)}
251341
- `;
251342
- }
251343
251338
  // src/cli/errors.ts
251344
251339
  class CLIExitError extends Error {
251345
251340
  code;
@@ -251549,6 +251544,10 @@ var MoveAppResponseSchema = exports_external.looseObject({
251549
251544
  appId: data.app_id,
251550
251545
  newWorkspaceId: data.new_workspace_id
251551
251546
  }));
251547
+ var APP_EDITOR_ROLES = ["owner", "admin", "editor"];
251548
+ function canCreateAppsInWorkspace(role) {
251549
+ return role !== undefined && APP_EDITOR_ROLES.includes(role.toLowerCase());
251550
+ }
251552
251551
 
251553
251552
  // src/core/workspace/api.ts
251554
251553
  async function listWorkspaces() {
@@ -253456,13 +253455,62 @@ function fetchWorkspaces(ctx) {
253456
253455
  errorMessage: "Failed to fetch workspaces"
253457
253456
  });
253458
253457
  }
253458
+ function workspaceHints(workspaces) {
253459
+ return [
253460
+ { message: "Run 'base44 workspace list' to see available workspaces" },
253461
+ ...workspaces.filter((w) => canCreateAppsInWorkspace(w.userRole)).map((w) => ({ message: `${w.name} — ${w.id}` }))
253462
+ ];
253463
+ }
253459
253464
  function workspaceLabel(workspace2) {
253460
253465
  const suffix = workspace2.isPersonal ? "personal" : workspace2.userRole ?? "member";
253461
253466
  return `${workspace2.name} (${suffix})`;
253462
253467
  }
253463
- async function resolveWorkspaceId(ctx, flagWorkspaceId, isInteractive, options = {}) {
253468
+ async function resolveWorkspaceId(ctx, flagWorkspaceId, isInteractive) {
253464
253469
  if (flagWorkspaceId) {
253465
- return flagWorkspaceId;
253470
+ const workspaces2 = await fetchWorkspaces(ctx);
253471
+ const match = workspaces2.find((w) => w.id === flagWorkspaceId);
253472
+ if (!match) {
253473
+ throw new InvalidInputError(`Workspace "${flagWorkspaceId}" not found, or you are not a member of it.`, { hints: workspaceHints(workspaces2) });
253474
+ }
253475
+ if (!canCreateAppsInWorkspace(match.userRole)) {
253476
+ throw new InvalidInputError(`You don't have permission to create apps in workspace "${match.name}" (your role: ${match.userRole ?? "unknown"}).`);
253477
+ }
253478
+ return match.id;
253479
+ }
253480
+ if (!isInteractive) {
253481
+ return;
253482
+ }
253483
+ const workspaces = await fetchWorkspaces(ctx);
253484
+ const eligible = workspaces.filter((w) => canCreateAppsInWorkspace(w.userRole));
253485
+ if (eligible.length <= 1) {
253486
+ return;
253487
+ }
253488
+ const options = eligible.map((w) => ({
253489
+ value: w.id,
253490
+ label: workspaceLabel(w)
253491
+ }));
253492
+ const selected = await Je({
253493
+ message: "Which workspace should this app belong to?",
253494
+ options,
253495
+ initialValue: eligible[0].id
253496
+ });
253497
+ if (Ct(selected)) {
253498
+ onPromptCancel();
253499
+ }
253500
+ return selected;
253501
+ }
253502
+ async function resolveListingWorkspaceId(ctx, flagWorkspaceId, isInteractive) {
253503
+ if (flagWorkspaceId) {
253504
+ const workspaces2 = await fetchWorkspaces(ctx);
253505
+ const match = workspaces2.find((w) => w.id === flagWorkspaceId);
253506
+ if (!match) {
253507
+ throw new InvalidInputError(`Workspace "${flagWorkspaceId}" not found, or you are not a member of it.`, {
253508
+ hints: [
253509
+ { message: "Run 'base44 workspace list' to see your workspaces" }
253510
+ ]
253511
+ });
253512
+ }
253513
+ return match.id;
253466
253514
  }
253467
253515
  if (!isInteractive) {
253468
253516
  return;
@@ -253471,13 +253519,13 @@ async function resolveWorkspaceId(ctx, flagWorkspaceId, isInteractive, options =
253471
253519
  if (workspaces.length <= 1) {
253472
253520
  return;
253473
253521
  }
253474
- const promptOptions = workspaces.map((w) => ({
253522
+ const options = workspaces.map((w) => ({
253475
253523
  value: w.id,
253476
253524
  label: workspaceLabel(w)
253477
253525
  }));
253478
253526
  const selected = await Je({
253479
- message: options.promptMessage ?? "Which workspace should this app belong to?",
253480
- options: promptOptions,
253527
+ message: "Which workspace is the app in?",
253528
+ options,
253481
253529
  initialValue: workspaces[0].id
253482
253530
  });
253483
253531
  if (Ct(selected)) {
@@ -253832,7 +253880,7 @@ async function resolveExplicitAppId(ctx, appId) {
253832
253880
  return appId;
253833
253881
  }
253834
253882
  async function chooseProjectInteractively(ctx, options) {
253835
- const workspaceId = await resolveWorkspaceId(ctx, options.workspace ?? options.org, !ctx.isNonInteractive, { promptMessage: "Which workspace is the app in?" });
253883
+ const workspaceId = await resolveListingWorkspaceId(ctx, options.workspace ?? options.org, !ctx.isNonInteractive);
253836
253884
  const projects = await ctx.runTask("Fetching projects...", () => listProjects({ workspaceId }), {
253837
253885
  successMessage: "Projects fetched",
253838
253886
  errorMessage: "Failed to fetch projects"
@@ -254327,6 +254375,10 @@ async function resolveFlagOrStdin(flagValue, flagName) {
254327
254375
  }
254328
254376
  return readStdin(flagName, { trim: false });
254329
254377
  }
254378
+ function toJsonStdout(result) {
254379
+ return `${JSON.stringify(result, null, 2)}
254380
+ `;
254381
+ }
254330
254382
  function parsePositiveInt(value, flagName) {
254331
254383
  if (value === undefined) {
254332
254384
  return;
@@ -254764,6 +254816,10 @@ function getTypesCommand() {
254764
254816
  }
254765
254817
 
254766
254818
  // src/cli/commands/workspace/shared.ts
254819
+ function toJsonStdout2(result) {
254820
+ return `${JSON.stringify(result, null, 2)}
254821
+ `;
254822
+ }
254767
254823
  function workspaceTag(workspace2) {
254768
254824
  const role = workspace2.userRole ?? "member";
254769
254825
  return workspace2.isPersonal ? `personal, ${role}` : role;
@@ -254782,7 +254838,7 @@ async function getWorkspaceAction({ runTask: runTask2, log, jsonMode }, workspac
254782
254838
  if (jsonMode) {
254783
254839
  return {
254784
254840
  outroMessage: workspace2.name,
254785
- stdout: toJsonStdout(workspace2)
254841
+ stdout: toJsonStdout2(workspace2)
254786
254842
  };
254787
254843
  }
254788
254844
  log.message(` ${theme.styles.bold(workspace2.name)} ${theme.styles.dim(`[${workspaceTag(workspace2)}]`)}
@@ -254800,6 +254856,9 @@ function pluralize2(n5) {
254800
254856
  }
254801
254857
  async function listWorkspacesAction({ log, runTask: runTask2, jsonMode }, options8) {
254802
254858
  let workspaces = await runTask2("Fetching workspaces...", () => listWorkspaces(), { errorMessage: "Failed to fetch workspaces" });
254859
+ if (options8.canCreate) {
254860
+ workspaces = workspaces.filter((w8) => canCreateAppsInWorkspace(w8.userRole));
254861
+ }
254803
254862
  if (options8.role) {
254804
254863
  const role = options8.role.toLowerCase();
254805
254864
  workspaces = workspaces.filter((w8) => w8.userRole?.toLowerCase() === role);
@@ -254807,7 +254866,7 @@ async function listWorkspacesAction({ log, runTask: runTask2, jsonMode }, option
254807
254866
  if (jsonMode) {
254808
254867
  return {
254809
254868
  outroMessage: pluralize2(workspaces.length),
254810
- stdout: toJsonStdout(workspaces)
254869
+ stdout: toJsonStdout2(workspaces)
254811
254870
  };
254812
254871
  }
254813
254872
  for (const workspace2 of workspaces) {
@@ -254817,23 +254876,46 @@ async function listWorkspacesAction({ log, runTask: runTask2, jsonMode }, option
254817
254876
  return { outroMessage: pluralize2(workspaces.length) };
254818
254877
  }
254819
254878
  function getWorkspaceListCommand() {
254820
- return new Base44Command("list", { requireAppContext: false }).description("List the workspaces you belong to").option("--role <role>", "Only workspaces where your role matches (owner, admin, editor, viewer)").action(listWorkspacesAction);
254879
+ return new Base44Command("list", { requireAppContext: false }).description("List the workspaces you belong to").option("--can-create", "Only workspaces you can create or move apps into (owner/admin/editor)").option("--role <role>", "Only workspaces where your role matches (owner, admin, editor, viewer)").action(listWorkspacesAction);
254821
254880
  }
254822
254881
 
254823
254882
  // src/cli/commands/workspace/move.ts
254824
- async function promptForTargetWorkspace(ctx, appId) {
254825
- const { workspaces, currentWorkspaceId } = await ctx.runTask("Fetching workspaces...", async () => {
254826
- const [workspaces2, app] = await Promise.all([
254827
- listWorkspaces(),
254828
- getApp(appId)
254829
- ]);
254830
- return { workspaces: workspaces2, currentWorkspaceId: app.organizationId };
254831
- }, { errorMessage: "Failed to fetch workspaces" });
254832
- const destinations = workspaces.filter((w8) => w8.id !== currentWorkspaceId);
254833
- if (destinations.length === 0) {
254883
+ function workspaceName(workspaces, id2) {
254884
+ if (!id2)
254885
+ return "unknown workspace";
254886
+ return workspaces.find((w8) => w8.id === id2)?.name ?? id2;
254887
+ }
254888
+ async function resolveTargetWorkspace(target, workspaces, currentWorkspaceId, isInteractive) {
254889
+ const eligible = workspaces.filter((w8) => canCreateAppsInWorkspace(w8.userRole) && w8.id !== currentWorkspaceId);
254890
+ if (target) {
254891
+ const match = workspaces.find((w8) => w8.id === target);
254892
+ if (!match) {
254893
+ throw new InvalidInputError(`Workspace "${target}" not found, or you are not a member of it.`, {
254894
+ hints: [
254895
+ { message: "Run 'base44 workspace list' to see your workspaces" }
254896
+ ]
254897
+ });
254898
+ }
254899
+ if (target === currentWorkspaceId) {
254900
+ throw new InvalidInputError("The app is already in that workspace.");
254901
+ }
254902
+ if (!canCreateAppsInWorkspace(match.userRole)) {
254903
+ throw new InvalidInputError(`You don't have permission to move apps into workspace "${match.name}" (your role: ${match.userRole ?? "unknown"}).`);
254904
+ }
254905
+ return match.id;
254906
+ }
254907
+ if (!isInteractive) {
254908
+ throw new InvalidInputError("A target workspace ID is required in non-interactive mode.", {
254909
+ hints: [
254910
+ { message: "Usage: base44 workspace move <workspace-id>" },
254911
+ { message: "Run 'base44 workspace list' to see your workspaces" }
254912
+ ]
254913
+ });
254914
+ }
254915
+ if (eligible.length === 0) {
254834
254916
  throw new InvalidInputError("No other workspaces available to move this app into.");
254835
254917
  }
254836
- const options8 = destinations.map((w8) => ({
254918
+ const options8 = eligible.map((w8) => ({
254837
254919
  value: w8.id,
254838
254920
  label: `${w8.name} (${w8.userRole ?? "member"})`
254839
254921
  }));
@@ -254844,64 +254926,42 @@ async function promptForTargetWorkspace(ctx, appId) {
254844
254926
  if (Ct(selected)) {
254845
254927
  onPromptCancel();
254846
254928
  }
254847
- const targetWorkspaceId = selected;
254848
- const nameOf = (id2) => workspaces.find((w8) => w8.id === id2)?.name ?? id2 ?? "unknown workspace";
254849
- return {
254850
- targetWorkspaceId,
254851
- fromName: nameOf(currentWorkspaceId),
254852
- toName: nameOf(targetWorkspaceId)
254853
- };
254929
+ return selected;
254854
254930
  }
254855
254931
  async function moveAction(ctx, target, options8) {
254856
254932
  const { runTask: runTask2, isNonInteractive, jsonMode } = ctx;
254857
254933
  const isInteractive = !isNonInteractive && !jsonMode;
254858
254934
  const { id: appId } = getAppContext();
254859
- let targetWorkspaceId;
254860
- let toLabel;
254861
- if (target) {
254862
- targetWorkspaceId = target;
254863
- toLabel = target;
254864
- if (isInteractive && !options8.yes) {
254865
- const proceed = await Re({
254866
- message: `Move this app to workspace ${theme.styles.bold(target)}?`
254867
- });
254868
- if (Ct(proceed)) {
254869
- onPromptCancel();
254870
- }
254871
- if (!proceed) {
254872
- return { outroMessage: "Move cancelled" };
254873
- }
254935
+ const { workspaces, currentWorkspaceId } = await runTask2("Fetching workspaces...", async () => {
254936
+ const [workspaces2, app] = await Promise.all([
254937
+ listWorkspaces(),
254938
+ getApp(appId)
254939
+ ]);
254940
+ return { workspaces: workspaces2, currentWorkspaceId: app.organizationId };
254941
+ }, { errorMessage: "Failed to fetch workspaces" });
254942
+ const targetWorkspaceId = await resolveTargetWorkspace(target, workspaces, currentWorkspaceId, isInteractive);
254943
+ if (isInteractive && !options8.yes) {
254944
+ const proceed = await Re({
254945
+ message: `Move this app from ${theme.styles.bold(workspaceName(workspaces, currentWorkspaceId))} to ${theme.styles.bold(workspaceName(workspaces, targetWorkspaceId))}?`
254946
+ });
254947
+ if (Ct(proceed)) {
254948
+ onPromptCancel();
254874
254949
  }
254875
- } else if (isInteractive) {
254876
- const picked = await promptForTargetWorkspace(ctx, appId);
254877
- targetWorkspaceId = picked.targetWorkspaceId;
254878
- toLabel = picked.toName;
254879
- if (!options8.yes) {
254880
- const proceed = await Re({
254881
- message: `Move this app from ${theme.styles.bold(picked.fromName)} to ${theme.styles.bold(picked.toName)}?`
254882
- });
254883
- if (Ct(proceed)) {
254884
- onPromptCancel();
254885
- }
254886
- if (!proceed) {
254887
- return { outroMessage: "Move cancelled" };
254888
- }
254950
+ if (!proceed) {
254951
+ return { outroMessage: "Move cancelled" };
254889
254952
  }
254890
- } else {
254891
- throw new InvalidInputError("A target workspace ID is required in non-interactive mode.", {
254892
- hints: [
254893
- { message: "Usage: base44 workspace move <workspace-id>" },
254894
- { message: "Run 'base44 workspace list' to see your workspaces" }
254895
- ]
254896
- });
254897
254953
  }
254898
254954
  const result = await runTask2("Moving app to workspace...", () => moveAppToWorkspace(appId, targetWorkspaceId, {
254899
254955
  disconnectIntegrations: options8.disconnectIntegrations
254900
254956
  }), { errorMessage: "Failed to move app" });
254957
+ const targetName = workspaceName(workspaces, targetWorkspaceId);
254901
254958
  if (jsonMode) {
254902
- return { outroMessage: "App moved", stdout: toJsonStdout(result) };
254959
+ return {
254960
+ outroMessage: `App moved to ${targetName}`,
254961
+ stdout: toJsonStdout2(result)
254962
+ };
254903
254963
  }
254904
- return { outroMessage: `App moved to ${theme.styles.bold(toLabel)}` };
254964
+ return { outroMessage: `App moved to ${theme.styles.bold(targetName)}` };
254905
254965
  }
254906
254966
  function getWorkspaceMoveCommand() {
254907
254967
  return new Base44Command("move").description("Move the current app to another workspace").argument("[workspace-id]", "Target workspace (organization) ID").option("--disconnect-integrations", "Disconnect the app's OAuth integrations as part of the move").option("-y, --yes", "Skip the confirmation prompt").addHelpText("after", `
@@ -262945,4 +263005,4 @@ export {
262945
263005
  CLIExitError
262946
263006
  };
262947
263007
 
262948
- //# debugId=BE50FE58EDC1DC8A64756E2164756E21
263008
+ //# debugId=F3935F096F24A1DE64756E2164756E21