@base44-preview/cli 0.1.4-pr.567.1d0df8b → 0.1.4-pr.567.2681dfe

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 = json2;
161116
+ module.exports = json3;
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 json2(options8) {
161120
+ function json3(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 json2(obj) {
168323
+ res.json = function json3(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 json2 = replacer || spaces ? JSON.stringify(value, replacer, spaces) : JSON.stringify(value);
168660
- if (escape3 && typeof json2 === "string") {
168661
- json2 = json2.replace(/[<>&]/g, function(c8) {
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) {
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 json2;
168674
+ return json3;
168675
168675
  }
168676
168676
  });
168677
168677
 
@@ -251341,6 +251341,11 @@ class Base44Command extends Command {
251341
251341
  });
251342
251342
  }
251343
251343
  }
251344
+ // src/cli/utils/json.ts
251345
+ function toJsonStdout(result) {
251346
+ return `${JSON.stringify(result, null, 2)}
251347
+ `;
251348
+ }
251344
251349
  // src/cli/errors.ts
251345
251350
  class CLIExitError extends Error {
251346
251351
  code;
@@ -251550,10 +251555,6 @@ var MoveAppResponseSchema = exports_external.looseObject({
251550
251555
  appId: data.app_id,
251551
251556
  newWorkspaceId: data.new_workspace_id
251552
251557
  }));
251553
- var APP_EDITOR_ROLES = ["owner", "admin", "editor"];
251554
- function canCreateAppsInWorkspace(role) {
251555
- return role !== undefined && APP_EDITOR_ROLES.includes(role.toLowerCase());
251556
- }
251557
251558
 
251558
251559
  // src/core/workspace/api.ts
251559
251560
  async function listWorkspaces() {
@@ -251572,6 +251573,10 @@ async function listWorkspaces() {
251572
251573
  isPersonal: index === 0
251573
251574
  }));
251574
251575
  }
251576
+ async function getWorkspace(id) {
251577
+ const workspaces = await listWorkspaces();
251578
+ return workspaces.find((w) => w.id === id);
251579
+ }
251575
251580
  async function moveAppToWorkspace(appId, targetWorkspaceId, options = {}) {
251576
251581
  let response;
251577
251582
  try {
@@ -253457,44 +253462,29 @@ function fetchWorkspaces(ctx) {
253457
253462
  errorMessage: "Failed to fetch workspaces"
253458
253463
  });
253459
253464
  }
253460
- function workspaceHints(workspaces) {
253461
- return [
253462
- { message: "Run 'base44 workspace list' to see available workspaces" },
253463
- ...workspaces.filter((w) => canCreateAppsInWorkspace(w.userRole)).map((w) => ({ message: `${w.name} — ${w.id}` }))
253464
- ];
253465
- }
253466
253465
  function workspaceLabel(workspace2) {
253467
253466
  const suffix = workspace2.isPersonal ? "personal" : workspace2.userRole ?? "member";
253468
253467
  return `${workspace2.name} (${suffix})`;
253469
253468
  }
253470
253469
  async function resolveWorkspaceId(ctx, flagWorkspaceId, isInteractive) {
253471
253470
  if (flagWorkspaceId) {
253472
- const workspaces2 = await fetchWorkspaces(ctx);
253473
- const match = workspaces2.find((w) => w.id === flagWorkspaceId);
253474
- if (!match) {
253475
- throw new InvalidInputError(`Workspace "${flagWorkspaceId}" not found, or you are not a member of it.`, { hints: workspaceHints(workspaces2) });
253476
- }
253477
- if (!canCreateAppsInWorkspace(match.userRole)) {
253478
- throw new InvalidInputError(`You don't have permission to create apps in workspace "${match.name}" (your role: ${match.userRole ?? "unknown"}).`);
253479
- }
253480
- return match.id;
253471
+ return flagWorkspaceId;
253481
253472
  }
253482
253473
  if (!isInteractive) {
253483
253474
  return;
253484
253475
  }
253485
253476
  const workspaces = await fetchWorkspaces(ctx);
253486
- const eligible = workspaces.filter((w) => canCreateAppsInWorkspace(w.userRole));
253487
- if (eligible.length <= 1) {
253477
+ if (workspaces.length <= 1) {
253488
253478
  return;
253489
253479
  }
253490
- const options = eligible.map((w) => ({
253480
+ const options = workspaces.map((w) => ({
253491
253481
  value: w.id,
253492
253482
  label: workspaceLabel(w)
253493
253483
  }));
253494
253484
  const selected = await Je({
253495
253485
  message: "Which workspace should this app belong to?",
253496
253486
  options,
253497
- initialValue: eligible[0].id
253487
+ initialValue: workspaces[0].id
253498
253488
  });
253499
253489
  if (Ct(selected)) {
253500
253490
  onPromptCancel();
@@ -254331,10 +254321,6 @@ async function resolveFlagOrStdin(flagValue, flagName) {
254331
254321
  }
254332
254322
  return readStdin(flagName, { trim: false });
254333
254323
  }
254334
- function toJsonStdout(result) {
254335
- return `${JSON.stringify(result, null, 2)}
254336
- `;
254337
- }
254338
254324
  function parsePositiveInt(value, flagName) {
254339
254325
  if (value === undefined) {
254340
254326
  return;
@@ -254772,77 +254758,76 @@ function getTypesCommand() {
254772
254758
  }
254773
254759
 
254774
254760
  // src/cli/commands/workspace/shared.ts
254775
- function toJsonStdout2(result) {
254776
- return `${JSON.stringify(result, null, 2)}
254777
- `;
254778
- }
254779
254761
  function workspaceTag(workspace2) {
254780
254762
  const role = workspace2.userRole ?? "member";
254781
254763
  return workspace2.isPersonal ? `personal, ${role}` : role;
254782
254764
  }
254783
254765
 
254766
+ // src/cli/commands/workspace/get.ts
254767
+ async function getWorkspaceAction({ runTask: runTask2, log, jsonMode }, workspaceId) {
254768
+ const workspace2 = await runTask2("Fetching workspace...", () => getWorkspace(workspaceId), { errorMessage: "Failed to fetch workspace" });
254769
+ if (!workspace2) {
254770
+ throw new InvalidInputError(`Workspace "${workspaceId}" not found, or you are not a member of it.`, {
254771
+ hints: [
254772
+ { message: "Run 'base44 workspace list' to see your workspaces" }
254773
+ ]
254774
+ });
254775
+ }
254776
+ if (jsonMode) {
254777
+ return {
254778
+ outroMessage: workspace2.name,
254779
+ stdout: toJsonStdout(workspace2)
254780
+ };
254781
+ }
254782
+ log.message(` ${theme.styles.bold(workspace2.name)} ${theme.styles.dim(`[${workspaceTag(workspace2)}]`)}
254783
+ ${theme.styles.dim(workspace2.id)}${workspace2.subscriptionTier ? theme.styles.dim(`
254784
+ tier: ${workspace2.subscriptionTier}`) : ""}`);
254785
+ return { outroMessage: workspace2.name };
254786
+ }
254787
+ function getWorkspaceGetCommand() {
254788
+ return new Base44Command("get", { requireAppContext: false }).description("Show details for a single workspace by ID").argument("<workspace-id>", "Workspace (organization) ID").action(getWorkspaceAction);
254789
+ }
254790
+
254784
254791
  // src/cli/commands/workspace/list.ts
254785
- async function listWorkspacesAction({
254786
- log,
254787
- runTask: runTask2,
254788
- jsonMode
254789
- }) {
254790
- const workspaces = await runTask2("Fetching workspaces...", () => listWorkspaces(), { errorMessage: "Failed to fetch workspaces" });
254792
+ function pluralize2(n5) {
254793
+ return `${n5} workspace${n5 !== 1 ? "s" : ""}`;
254794
+ }
254795
+ async function listWorkspacesAction({ log, runTask: runTask2, jsonMode }, options8) {
254796
+ let workspaces = await runTask2("Fetching workspaces...", () => listWorkspaces(), { errorMessage: "Failed to fetch workspaces" });
254797
+ if (options8.role) {
254798
+ const role = options8.role.toLowerCase();
254799
+ workspaces = workspaces.filter((w8) => w8.userRole?.toLowerCase() === role);
254800
+ }
254791
254801
  if (jsonMode) {
254792
254802
  return {
254793
- outroMessage: `${workspaces.length} workspace${workspaces.length !== 1 ? "s" : ""}`,
254794
- stdout: toJsonStdout2(workspaces)
254803
+ outroMessage: pluralize2(workspaces.length),
254804
+ stdout: toJsonStdout(workspaces)
254795
254805
  };
254796
254806
  }
254797
254807
  for (const workspace2 of workspaces) {
254798
254808
  log.message(` ${theme.styles.bold(workspace2.name)} ${theme.styles.dim(`[${workspaceTag(workspace2)}]`)}
254799
254809
  ${theme.styles.dim(workspace2.id)}`);
254800
254810
  }
254801
- return {
254802
- outroMessage: `${workspaces.length} workspace${workspaces.length !== 1 ? "s" : ""}`
254803
- };
254811
+ return { outroMessage: pluralize2(workspaces.length) };
254804
254812
  }
254805
254813
  function getWorkspaceListCommand() {
254806
- return new Base44Command("list", { requireAppContext: false }).description("List the workspaces you belong to").action(listWorkspacesAction);
254814
+ 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);
254807
254815
  }
254808
254816
 
254809
254817
  // src/cli/commands/workspace/move.ts
254810
- function workspaceName(workspaces, id2) {
254811
- if (!id2)
254812
- return "unknown workspace";
254813
- return workspaces.find((w8) => w8.id === id2)?.name ?? id2;
254814
- }
254815
- async function resolveTargetWorkspace(target, workspaces, currentWorkspaceId, isInteractive) {
254816
- const eligible = workspaces.filter((w8) => canCreateAppsInWorkspace(w8.userRole) && w8.id !== currentWorkspaceId);
254817
- if (target) {
254818
- const match = workspaces.find((w8) => w8.id === target);
254819
- if (!match) {
254820
- throw new InvalidInputError(`Workspace "${target}" not found, or you are not a member of it.`, {
254821
- hints: [
254822
- { message: "Run 'base44 workspace list' to see your workspaces" }
254823
- ]
254824
- });
254825
- }
254826
- if (target === currentWorkspaceId) {
254827
- throw new InvalidInputError("The app is already in that workspace.");
254828
- }
254829
- if (!canCreateAppsInWorkspace(match.userRole)) {
254830
- throw new InvalidInputError(`You don't have permission to move apps into workspace "${match.name}" (your role: ${match.userRole ?? "unknown"}).`);
254831
- }
254832
- return match.id;
254833
- }
254834
- if (!isInteractive) {
254835
- throw new InvalidInputError("A target workspace ID is required in non-interactive mode.", {
254836
- hints: [
254837
- { message: "Usage: base44 workspace move <workspace-id>" },
254838
- { message: "Run 'base44 workspace list' to see your workspaces" }
254839
- ]
254840
- });
254841
- }
254842
- if (eligible.length === 0) {
254818
+ async function promptForTargetWorkspace(ctx, appId) {
254819
+ const { workspaces, currentWorkspaceId } = await ctx.runTask("Fetching workspaces...", async () => {
254820
+ const [workspaces2, app] = await Promise.all([
254821
+ listWorkspaces(),
254822
+ getApp(appId)
254823
+ ]);
254824
+ return { workspaces: workspaces2, currentWorkspaceId: app.organizationId };
254825
+ }, { errorMessage: "Failed to fetch workspaces" });
254826
+ const destinations = workspaces.filter((w8) => w8.id !== currentWorkspaceId);
254827
+ if (destinations.length === 0) {
254843
254828
  throw new InvalidInputError("No other workspaces available to move this app into.");
254844
254829
  }
254845
- const options8 = eligible.map((w8) => ({
254830
+ const options8 = destinations.map((w8) => ({
254846
254831
  value: w8.id,
254847
254832
  label: `${w8.name} (${w8.userRole ?? "member"})`
254848
254833
  }));
@@ -254853,42 +254838,64 @@ async function resolveTargetWorkspace(target, workspaces, currentWorkspaceId, is
254853
254838
  if (Ct(selected)) {
254854
254839
  onPromptCancel();
254855
254840
  }
254856
- return selected;
254841
+ const targetWorkspaceId = selected;
254842
+ const nameOf = (id2) => workspaces.find((w8) => w8.id === id2)?.name ?? id2 ?? "unknown workspace";
254843
+ return {
254844
+ targetWorkspaceId,
254845
+ fromName: nameOf(currentWorkspaceId),
254846
+ toName: nameOf(targetWorkspaceId)
254847
+ };
254857
254848
  }
254858
254849
  async function moveAction(ctx, target, options8) {
254859
254850
  const { runTask: runTask2, isNonInteractive, jsonMode } = ctx;
254860
254851
  const isInteractive = !isNonInteractive && !jsonMode;
254861
254852
  const { id: appId } = getAppContext();
254862
- const { workspaces, currentWorkspaceId } = await runTask2("Fetching workspaces...", async () => {
254863
- const [workspaces2, app] = await Promise.all([
254864
- listWorkspaces(),
254865
- getApp(appId)
254866
- ]);
254867
- return { workspaces: workspaces2, currentWorkspaceId: app.organizationId };
254868
- }, { errorMessage: "Failed to fetch workspaces" });
254869
- const targetWorkspaceId = await resolveTargetWorkspace(target, workspaces, currentWorkspaceId, isInteractive);
254870
- if (isInteractive && !options8.yes) {
254871
- const proceed = await Re({
254872
- message: `Move this app from ${theme.styles.bold(workspaceName(workspaces, currentWorkspaceId))} to ${theme.styles.bold(workspaceName(workspaces, targetWorkspaceId))}?`
254873
- });
254874
- if (Ct(proceed)) {
254875
- onPromptCancel();
254853
+ let targetWorkspaceId;
254854
+ let toLabel;
254855
+ if (target) {
254856
+ targetWorkspaceId = target;
254857
+ toLabel = target;
254858
+ if (isInteractive && !options8.yes) {
254859
+ const proceed = await Re({
254860
+ message: `Move this app to workspace ${theme.styles.bold(target)}?`
254861
+ });
254862
+ if (Ct(proceed)) {
254863
+ onPromptCancel();
254864
+ }
254865
+ if (!proceed) {
254866
+ return { outroMessage: "Move cancelled" };
254867
+ }
254876
254868
  }
254877
- if (!proceed) {
254878
- return { outroMessage: "Move cancelled" };
254869
+ } else if (isInteractive) {
254870
+ const picked = await promptForTargetWorkspace(ctx, appId);
254871
+ targetWorkspaceId = picked.targetWorkspaceId;
254872
+ toLabel = picked.toName;
254873
+ if (!options8.yes) {
254874
+ const proceed = await Re({
254875
+ message: `Move this app from ${theme.styles.bold(picked.fromName)} to ${theme.styles.bold(picked.toName)}?`
254876
+ });
254877
+ if (Ct(proceed)) {
254878
+ onPromptCancel();
254879
+ }
254880
+ if (!proceed) {
254881
+ return { outroMessage: "Move cancelled" };
254882
+ }
254879
254883
  }
254884
+ } else {
254885
+ throw new InvalidInputError("A target workspace ID is required in non-interactive mode.", {
254886
+ hints: [
254887
+ { message: "Usage: base44 workspace move <workspace-id>" },
254888
+ { message: "Run 'base44 workspace list' to see your workspaces" }
254889
+ ]
254890
+ });
254880
254891
  }
254881
254892
  const result = await runTask2("Moving app to workspace...", () => moveAppToWorkspace(appId, targetWorkspaceId, {
254882
254893
  disconnectIntegrations: options8.disconnectIntegrations
254883
254894
  }), { errorMessage: "Failed to move app" });
254884
- const targetName = workspaceName(workspaces, targetWorkspaceId);
254885
254895
  if (jsonMode) {
254886
- return {
254887
- outroMessage: `App moved to ${targetName}`,
254888
- stdout: toJsonStdout2(result)
254889
- };
254896
+ return { outroMessage: "App moved", stdout: toJsonStdout(result) };
254890
254897
  }
254891
- return { outroMessage: `App moved to ${theme.styles.bold(targetName)}` };
254898
+ return { outroMessage: `App moved to ${theme.styles.bold(toLabel)}` };
254892
254899
  }
254893
254900
  function getWorkspaceMoveCommand() {
254894
254901
  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", `
@@ -254899,7 +254906,7 @@ Examples:
254899
254906
 
254900
254907
  // src/cli/commands/workspace/index.ts
254901
254908
  function getWorkspaceCommand() {
254902
- return new Command("workspace").description("List workspaces and move apps between them").addCommand(getWorkspaceListCommand()).addCommand(getWorkspaceMoveCommand());
254909
+ return new Command("workspace").description("List workspaces, inspect one, and move apps between them").addCommand(getWorkspaceListCommand()).addCommand(getWorkspaceGetCommand()).addCommand(getWorkspaceMoveCommand());
254903
254910
  }
254904
254911
 
254905
254912
  // src/cli/dev/dev-server/main.ts
@@ -262932,4 +262939,4 @@ export {
262932
262939
  CLIExitError
262933
262940
  };
262934
262941
 
262935
- //# debugId=411CA34C835D36D464756E2164756E21
262942
+ //# debugId=286FD2180C08CE2564756E2164756E21