farseer-cli 1.0.9 → 1.0.10

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.
Files changed (81) hide show
  1. package/dist/commands/app.js +344 -316
  2. package/dist/commands/apps.js +83 -103
  3. package/dist/commands/checkout.js +156 -134
  4. package/dist/commands/config.js +126 -124
  5. package/dist/commands/diff.js +194 -169
  6. package/dist/commands/dimensions.js +122 -137
  7. package/dist/commands/files.js +77 -88
  8. package/dist/commands/install.js +77 -74
  9. package/dist/commands/list.js +74 -89
  10. package/dist/commands/login.js +101 -126
  11. package/dist/commands/logout.js +42 -57
  12. package/dist/commands/mcp-server.js +24 -39
  13. package/dist/commands/model.js +176 -184
  14. package/dist/commands/pull.js +276 -248
  15. package/dist/commands/push.js +222 -200
  16. package/dist/commands/run.js +322 -274
  17. package/dist/commands/status.js +170 -147
  18. package/dist/commands/variables.js +192 -168
  19. package/dist/commands/whoami.js +45 -61
  20. package/dist/index.js +115 -117
  21. package/dist/mcp/index.js +17 -33
  22. package/dist/mcp/prompts/workflows.js +146 -191
  23. package/dist/mcp/resources/documentation.js +149 -158
  24. package/dist/mcp/server.js +34 -50
  25. package/dist/mcp/tools/appTools.js +278 -307
  26. package/dist/mcp/tools/authTools.js +123 -130
  27. package/dist/mcp/tools/dataTools.js +271 -275
  28. package/dist/mcp/tools/modelTools.js +233 -265
  29. package/dist/mcp/tools/runTools.js +205 -199
  30. package/dist/mcp/tools/syncTools.js +315 -341
  31. package/dist/mcp/utils/helpers.js +124 -117
  32. package/dist/services/appSyncService.js +438 -379
  33. package/dist/services/configService.js +144 -154
  34. package/dist/services/farseerApi.js +401 -401
  35. package/dist/services/farseerFactory.js +274 -208
  36. package/dist/services/farseerService.js +488 -455
  37. package/dist/services/syncService.js +732 -657
  38. package/dist/utils/constants.js +20 -45
  39. package/dist/utils/helpers.js +366 -333
  40. package/dist/utils/logger.js +43 -74
  41. package/package.json +8 -1
  42. package/dist/commands/app.js.map +0 -7
  43. package/dist/commands/apps.js.map +0 -7
  44. package/dist/commands/checkout.js.map +0 -7
  45. package/dist/commands/config.js.map +0 -7
  46. package/dist/commands/diff.js.map +0 -7
  47. package/dist/commands/dimensions.js.map +0 -7
  48. package/dist/commands/files.js.map +0 -7
  49. package/dist/commands/install.js.map +0 -7
  50. package/dist/commands/list.js.map +0 -7
  51. package/dist/commands/login.js.map +0 -7
  52. package/dist/commands/logout.js.map +0 -7
  53. package/dist/commands/mcp-server.js.map +0 -7
  54. package/dist/commands/model.js.map +0 -7
  55. package/dist/commands/pull.js.map +0 -7
  56. package/dist/commands/push.js.map +0 -7
  57. package/dist/commands/run.js.map +0 -7
  58. package/dist/commands/status.js.map +0 -7
  59. package/dist/commands/variables.js.map +0 -7
  60. package/dist/commands/whoami.js.map +0 -7
  61. package/dist/index.js.map +0 -7
  62. package/dist/mcp/index.js.map +0 -7
  63. package/dist/mcp/prompts/workflows.js.map +0 -7
  64. package/dist/mcp/resources/documentation.js.map +0 -7
  65. package/dist/mcp/server.js.map +0 -7
  66. package/dist/mcp/tools/appTools.js.map +0 -7
  67. package/dist/mcp/tools/authTools.js.map +0 -7
  68. package/dist/mcp/tools/dataTools.js.map +0 -7
  69. package/dist/mcp/tools/modelTools.js.map +0 -7
  70. package/dist/mcp/tools/runTools.js.map +0 -7
  71. package/dist/mcp/tools/syncTools.js.map +0 -7
  72. package/dist/mcp/utils/helpers.js.map +0 -7
  73. package/dist/services/appSyncService.js.map +0 -7
  74. package/dist/services/configService.js.map +0 -7
  75. package/dist/services/farseerApi.js.map +0 -7
  76. package/dist/services/farseerFactory.js.map +0 -7
  77. package/dist/services/farseerService.js.map +0 -7
  78. package/dist/services/syncService.js.map +0 -7
  79. package/dist/utils/constants.js.map +0 -7
  80. package/dist/utils/helpers.js.map +0 -7
  81. package/dist/utils/logger.js.map +0 -7
@@ -1,41 +1,18 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var app_exports = {};
29
- __export(app_exports, {
30
- registerAppCommand: () => registerAppCommand
31
- });
32
- module.exports = __toCommonJS(app_exports);
33
- var import_chalk = __toESM(require("chalk"));
34
- var import_logger = require("../utils/logger");
35
- var import_farseerFactory = require("../services/farseerFactory");
36
- var import_helpers = require("../utils/helpers");
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.registerAppCommand = registerAppCommand;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const logger_1 = require("../utils/logger");
9
+ const farseerFactory_1 = require("../services/farseerFactory");
10
+ const helpers_1 = require("../utils/helpers");
37
11
  function registerAppCommand(program) {
38
- const appCmd = program.command("app").description("Manage apps on a Farseer instance").addHelpText("after", `
12
+ const appCmd = program
13
+ .command('app')
14
+ .description('Manage apps on a Farseer instance')
15
+ .addHelpText('after', `
39
16
  Commands:
40
17
  list [tenant] List all apps
41
18
  show [tenant] <name...> Show app details
@@ -51,299 +28,350 @@ Examples:
51
28
  $ farseer app show My App # Uses checked-out tenant
52
29
  $ farseer app configure "My App" --entrypoint index.ts
53
30
  `);
54
- appCmd.command("list [tenant]").description("List all apps on a Farseer instance").option("--details", "Show detailed information for each app").action(async (tenantArg, options) => {
55
- const { organisation, tenant } = (0, import_helpers.resolveTenantWithOrgMapping)(tenantArg);
56
- const result = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
57
- if (!result) {
58
- (0, import_farseerFactory.showLoginPrompt)(tenant);
59
- process.exit(1);
60
- }
61
- const api = result.client;
62
- const authLabel = result.authType === "apiKey" ? "API key" : "browser login";
63
- import_logger.logger.info(`Fetching apps from ${tenant} (using ${authLabel})...`);
64
- try {
65
- const apps = await api.listApps();
66
- if (apps.length === 0) {
67
- import_logger.logger.warning("No apps found.");
68
- import_logger.logger.dim("Create an app with: farseer app create <name>");
69
- return;
70
- }
71
- import_logger.logger.header(`Apps on ${tenant}`);
72
- console.log();
73
- if (options.details) {
74
- for (const app of apps) {
75
- const details = await api.getApp(app.reference);
76
- if (details) {
77
- console.log(` \u{1F4E6} ${import_chalk.default.bold(details.name)}`);
78
- if (details.description) {
79
- console.log(` ${import_chalk.default.dim(details.description)}`);
31
+ // List apps
32
+ appCmd
33
+ .command('list [tenant]')
34
+ .description('List all apps on a Farseer instance')
35
+ .option('--details', 'Show detailed information for each app')
36
+ .action(async (tenantArg, options) => {
37
+ const { organisation, tenant } = (0, helpers_1.resolveTenantWithOrgMapping)(tenantArg);
38
+ const result = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
39
+ if (!result) {
40
+ (0, farseerFactory_1.showLoginPrompt)(tenant);
41
+ process.exit(1);
42
+ }
43
+ const api = result.client;
44
+ const authLabel = result.authType === 'apiKey' ? 'API key' : 'browser login';
45
+ logger_1.logger.info(`Fetching apps from ${tenant} (using ${authLabel})...`);
46
+ try {
47
+ const apps = await api.listApps();
48
+ if (apps.length === 0) {
49
+ logger_1.logger.warning('No apps found.');
50
+ logger_1.logger.dim('Create an app with: farseer app create <name>');
51
+ return;
80
52
  }
81
- console.log(` Status: ${details.status === "AVAILABLE" ? import_chalk.default.green(details.status) : import_chalk.default.yellow(details.status)}`);
82
- if (details.scriptFiles.length > 0) {
83
- const mainScript = details.scriptFiles.find((s) => s.id === details.mainScriptFileId);
84
- console.log(` Entrypoint: ${mainScript ? import_chalk.default.cyan(mainScript.name) : import_chalk.default.red("Not set")}`);
85
- console.log(` Scripts:`);
86
- for (const script of details.scriptFiles) {
87
- const isMain = script.id === details.mainScriptFileId;
88
- console.log(` ${isMain ? import_chalk.default.green("\u25B6") : " "} ${script.name}${isMain ? import_chalk.default.dim(" (entrypoint)") : ""}`);
89
- }
90
- } else {
91
- console.log(` Scripts: ${import_chalk.default.dim("None")}`);
53
+ logger_1.logger.header(`Apps on ${tenant}`);
54
+ console.log();
55
+ if (options.details) {
56
+ // Fetch full details for each app
57
+ for (const app of apps) {
58
+ const details = await api.getApp(app.reference);
59
+ if (details) {
60
+ console.log(` 📦 ${chalk_1.default.bold(details.name)}`);
61
+ if (details.description) {
62
+ console.log(` ${chalk_1.default.dim(details.description)}`);
63
+ }
64
+ console.log(` Status: ${details.status === 'AVAILABLE' ? chalk_1.default.green(details.status) : chalk_1.default.yellow(details.status)}`);
65
+ const detailScripts = details.scriptFiles ?? [];
66
+ if (detailScripts.length > 0) {
67
+ const mainScript = detailScripts.find((s) => s.id === details.mainScriptFileId);
68
+ console.log(` Entrypoint: ${mainScript ? chalk_1.default.cyan(mainScript.name) : chalk_1.default.red('Not set')}`);
69
+ console.log(` Scripts:`);
70
+ for (const script of detailScripts) {
71
+ const isMain = script.id === details.mainScriptFileId;
72
+ console.log(` ${isMain ? chalk_1.default.green('▶') : ' '} ${script.name}${isMain ? chalk_1.default.dim(' (entrypoint)') : ''}`);
73
+ }
74
+ }
75
+ else {
76
+ console.log(` Scripts: ${chalk_1.default.dim('None')}`);
77
+ }
78
+ if (details.expectedArguments.length > 0) {
79
+ console.log(` Arguments:`);
80
+ for (const arg of details.expectedArguments) {
81
+ console.log(` - ${arg.name}: ${chalk_1.default.dim(arg.defaultValue)}`);
82
+ }
83
+ }
84
+ console.log();
85
+ }
86
+ }
92
87
  }
93
- if (details.expectedArguments.length > 0) {
94
- console.log(` Arguments:`);
95
- for (const arg of details.expectedArguments) {
96
- console.log(` - ${arg.name}: ${import_chalk.default.dim(arg.defaultValue)}`);
97
- }
88
+ else {
89
+ // Simple list
90
+ for (const app of apps) {
91
+ console.log(` 📦 ${app.name}`);
92
+ }
93
+ console.log();
94
+ logger_1.logger.dim(`Total: ${apps.length} app(s)`);
95
+ logger_1.logger.dim('Use --details to see more information.');
98
96
  }
99
- console.log();
100
- }
101
97
  }
102
- } else {
103
- for (const app of apps) {
104
- console.log(` \u{1F4E6} ${app.name}`);
98
+ catch (error) {
99
+ logger_1.logger.error('Failed to list apps.');
100
+ if (error?.message) {
101
+ logger_1.logger.dim(error.message);
102
+ }
103
+ process.exit(1);
104
+ }
105
+ });
106
+ // Show app details
107
+ appCmd
108
+ .command('show <args...>')
109
+ .description('Show details of an app')
110
+ .action(async (args) => {
111
+ const { organisation, tenant, appName } = (0, helpers_1.parseAppArgs)(args);
112
+ const result = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
113
+ if (!result) {
114
+ (0, farseerFactory_1.showLoginPrompt)(tenant);
115
+ process.exit(1);
116
+ }
117
+ const api = result.client;
118
+ const app = await api.getAppByName(appName);
119
+ if (!app) {
120
+ logger_1.logger.error(`App not found: ${appName}`);
121
+ process.exit(1);
122
+ }
123
+ logger_1.logger.header(`App: ${app.name}`);
124
+ console.log();
125
+ console.log(` ID: ${app.id}`);
126
+ console.log(` Status: ${app.status}`);
127
+ if (app.description) {
128
+ console.log(` Description: ${app.description}`);
129
+ }
130
+ console.log();
131
+ const appScripts = app.scriptFiles ?? [];
132
+ if (appScripts.length > 0) {
133
+ console.log(' Scripts:');
134
+ for (const script of appScripts) {
135
+ const isMain = script.id === app.mainScriptFileId;
136
+ console.log(` ${isMain ? chalk_1.default.green('▶') : ' '} ${script.name}${isMain ? chalk_1.default.dim(' (entrypoint)') : ''}`);
137
+ }
138
+ }
139
+ else {
140
+ console.log(' Scripts: None');
141
+ }
142
+ console.log();
143
+ if (app.expectedArguments.length > 0) {
144
+ console.log(' Arguments:');
145
+ for (const arg of app.expectedArguments) {
146
+ console.log(` - ${arg.name}: ${chalk_1.default.dim(arg.defaultValue)}`);
147
+ }
148
+ }
149
+ else {
150
+ console.log(' Arguments: None');
105
151
  }
106
152
  console.log();
107
- import_logger.logger.dim(`Total: ${apps.length} app(s)`);
108
- import_logger.logger.dim("Use --details to see more information.");
109
- }
110
- } catch (error) {
111
- import_logger.logger.error("Failed to list apps.");
112
- if (error?.message) {
113
- import_logger.logger.dim(error.message);
114
- }
115
- process.exit(1);
116
- }
117
- });
118
- appCmd.command("show <args...>").description("Show details of an app").action(async (args) => {
119
- const { organisation, tenant, appName } = (0, import_helpers.parseAppArgs)(args);
120
- const result = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
121
- if (!result) {
122
- (0, import_farseerFactory.showLoginPrompt)(tenant);
123
- process.exit(1);
124
- }
125
- const api = result.client;
126
- const app = await api.getAppByName(appName);
127
- if (!app) {
128
- import_logger.logger.error(`App not found: ${appName}`);
129
- process.exit(1);
130
- }
131
- import_logger.logger.header(`App: ${app.name}`);
132
- console.log();
133
- console.log(` ID: ${app.id}`);
134
- console.log(` Status: ${app.status}`);
135
- if (app.description) {
136
- console.log(` Description: ${app.description}`);
137
- }
138
- console.log();
139
- if (app.scriptFiles.length > 0) {
140
- console.log(" Scripts:");
141
- for (const script of app.scriptFiles) {
142
- const isMain = script.id === app.mainScriptFileId;
143
- console.log(` ${isMain ? import_chalk.default.green("\u25B6") : " "} ${script.name}${isMain ? import_chalk.default.dim(" (entrypoint)") : ""}`);
144
- }
145
- } else {
146
- console.log(" Scripts: None");
147
- }
148
- console.log();
149
- if (app.expectedArguments.length > 0) {
150
- console.log(" Arguments:");
151
- for (const arg of app.expectedArguments) {
152
- console.log(` - ${arg.name}: ${import_chalk.default.dim(arg.defaultValue)}`);
153
- }
154
- } else {
155
- console.log(" Arguments: None");
156
- }
157
- console.log();
158
- });
159
- appCmd.command("create <args...>").description("Create a new app").action(async (args) => {
160
- const { organisation, tenant, appName } = (0, import_helpers.parseAppArgs)(args);
161
- const result = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
162
- if (!result) {
163
- (0, import_farseerFactory.showLoginPrompt)(tenant);
164
- process.exit(1);
165
- }
166
- const api = result.client;
167
- const existing = await api.getAppByName(appName);
168
- if (existing) {
169
- import_logger.logger.error(`App already exists: ${appName}`);
170
- process.exit(1);
171
- }
172
- import_logger.logger.info(`Creating app: ${appName}...`);
173
- try {
174
- const app = await api.createApp(appName);
175
- import_logger.logger.success(`App created: ${app.name} (ID: ${app.id})`);
176
- import_logger.logger.dim('Configure it with: farseer app configure "' + appName + '"');
177
- } catch (error) {
178
- import_logger.logger.error("Failed to create app.");
179
- if (error instanceof Error) {
180
- import_logger.logger.dim(error.message);
181
- }
182
- process.exit(1);
183
- }
184
- });
185
- appCmd.command("delete <args...>").description("Delete an app").option("--force", "Skip confirmation").action(async (args, options) => {
186
- const { organisation, tenant, appName } = (0, import_helpers.parseAppArgs)(args);
187
- const result = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
188
- if (!result) {
189
- (0, import_farseerFactory.showLoginPrompt)(tenant);
190
- process.exit(1);
191
- }
192
- const api = result.client;
193
- const apps = await api.listApps();
194
- const app = apps.find((a) => a.name.toLowerCase() === appName.toLowerCase());
195
- if (!app) {
196
- import_logger.logger.error(`App not found: ${appName}`);
197
- process.exit(1);
198
- }
199
- if (!options.force) {
200
- import_logger.logger.warning(`This will permanently delete app: ${app.name}`);
201
- import_logger.logger.dim("Use --force to skip this confirmation.");
202
- process.exit(1);
203
- }
204
- import_logger.logger.info(`Deleting app: ${app.name}...`);
205
- try {
206
- await api.deleteApp(app.reference);
207
- import_logger.logger.success(`App deleted: ${app.name}`);
208
- } catch (error) {
209
- import_logger.logger.error("Failed to delete app.");
210
- if (error instanceof Error) {
211
- import_logger.logger.dim(error.message);
212
- }
213
- process.exit(1);
214
- }
215
- });
216
- appCmd.command("configure <args...>").description("Configure an app (set entrypoint, scripts, arguments)").option("--entrypoint <script>", 'Set the entrypoint script (e.g., "index.ts")').option("--scripts <scripts>", "Comma-separated list of scripts to include").option("--add-arg <arg>", 'Add argument in format "Name=DefaultValue" (can be used multiple times)', collectArgs, []).option("--description <desc>", "Set app description").option("--name <name>", "Rename the app").action(async (args, options) => {
217
- const { organisation, tenant, appName } = (0, import_helpers.parseAppArgs)(args);
218
- const result = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
219
- if (!result) {
220
- (0, import_farseerFactory.showLoginPrompt)(tenant);
221
- process.exit(1);
222
- }
223
- const api = result.client;
224
- const apps = await api.listApps();
225
- const appListItem = apps.find((a) => a.name.toLowerCase() === appName.toLowerCase());
226
- if (!appListItem) {
227
- import_logger.logger.error(`App not found: ${appName}`);
228
- process.exit(1);
229
- }
230
- const app = await api.getApp(appListItem.reference);
231
- if (!app) {
232
- import_logger.logger.error(`Failed to load app details: ${appName}`);
233
- process.exit(1);
234
- }
235
- const update = {};
236
- if (options.name) {
237
- update.name = options.name;
238
- }
239
- if (options.description !== void 0) {
240
- update.description = options.description;
241
- }
242
- if (options.scripts || options.entrypoint) {
243
- const availableScripts = await api.getScriptFiles();
244
- let autoSetEntrypoint = false;
245
- let autoEntrypointName = "";
246
- if (options.scripts) {
247
- const scriptNames = options.scripts.split(",").map((s) => s.trim());
248
- const scriptIds = [];
249
- const resolvedScripts = [];
250
- for (const name of scriptNames) {
251
- const script = availableScripts.find((s) => s.name.toLowerCase() === name.toLowerCase());
252
- if (!script) {
253
- import_logger.logger.error(`Script not found: ${name}`);
254
- import_logger.logger.dim("Available scripts: " + availableScripts.map((s) => s.name).join(", "));
153
+ });
154
+ // Create app
155
+ appCmd
156
+ .command('create <args...>')
157
+ .description('Create a new app')
158
+ .action(async (args) => {
159
+ const { organisation, tenant, appName } = (0, helpers_1.parseAppArgs)(args);
160
+ const result = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
161
+ if (!result) {
162
+ (0, farseerFactory_1.showLoginPrompt)(tenant);
163
+ process.exit(1);
164
+ }
165
+ const api = result.client;
166
+ // Check if app already exists
167
+ const existing = await api.getAppByName(appName);
168
+ if (existing) {
169
+ logger_1.logger.error(`App already exists: ${appName}`);
170
+ process.exit(1);
171
+ }
172
+ logger_1.logger.info(`Creating app: ${appName}...`);
173
+ try {
174
+ const app = await api.createApp(appName);
175
+ logger_1.logger.success(`App created: ${app.name} (ID: ${app.id})`);
176
+ logger_1.logger.dim('Configure it with: farseer app configure "' + appName + '"');
177
+ }
178
+ catch (error) {
179
+ logger_1.logger.error('Failed to create app.');
180
+ if (error instanceof Error) {
181
+ logger_1.logger.dim(error.message);
182
+ }
183
+ process.exit(1);
184
+ }
185
+ });
186
+ // Delete app
187
+ appCmd
188
+ .command('delete <args...>')
189
+ .description('Delete an app')
190
+ .option('--force', 'Skip confirmation')
191
+ .action(async (args, options) => {
192
+ const { organisation, tenant, appName } = (0, helpers_1.parseAppArgs)(args);
193
+ const result = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
194
+ if (!result) {
195
+ (0, farseerFactory_1.showLoginPrompt)(tenant);
196
+ process.exit(1);
197
+ }
198
+ const api = result.client;
199
+ // Find app
200
+ const apps = await api.listApps();
201
+ const app = apps.find((a) => a.name.toLowerCase() === appName.toLowerCase());
202
+ if (!app) {
203
+ logger_1.logger.error(`App not found: ${appName}`);
204
+ process.exit(1);
205
+ }
206
+ if (!options.force) {
207
+ logger_1.logger.warning(`This will permanently delete app: ${app.name}`);
208
+ logger_1.logger.dim('Use --force to skip this confirmation.');
209
+ process.exit(1);
210
+ }
211
+ logger_1.logger.info(`Deleting app: ${app.name}...`);
212
+ try {
213
+ await api.deleteApp(app.reference);
214
+ logger_1.logger.success(`App deleted: ${app.name}`);
215
+ }
216
+ catch (error) {
217
+ logger_1.logger.error('Failed to delete app.');
218
+ if (error instanceof Error) {
219
+ logger_1.logger.dim(error.message);
220
+ }
221
+ process.exit(1);
222
+ }
223
+ });
224
+ // Configure app
225
+ appCmd
226
+ .command('configure <args...>')
227
+ .description('Configure an app (set entrypoint, scripts, arguments)')
228
+ .option('--entrypoint <script>', 'Set the entrypoint script (e.g., "index.ts")')
229
+ .option('--scripts <scripts>', 'Comma-separated list of scripts to include')
230
+ .option('--add-arg <arg>', 'Add argument in format "Name=DefaultValue" (can be used multiple times)', collectArgs, [])
231
+ .option('--description <desc>', 'Set app description')
232
+ .option('--name <name>', 'Rename the app')
233
+ .action(async (args, options) => {
234
+ const { organisation, tenant, appName } = (0, helpers_1.parseAppArgs)(args);
235
+ const result = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
236
+ if (!result) {
237
+ (0, farseerFactory_1.showLoginPrompt)(tenant);
238
+ process.exit(1);
239
+ }
240
+ const api = result.client;
241
+ // Find app
242
+ const apps = await api.listApps();
243
+ const appListItem = apps.find((a) => a.name.toLowerCase() === appName.toLowerCase());
244
+ if (!appListItem) {
245
+ logger_1.logger.error(`App not found: ${appName}`);
246
+ process.exit(1);
247
+ }
248
+ const app = await api.getApp(appListItem.reference);
249
+ if (!app) {
250
+ logger_1.logger.error(`Failed to load app details: ${appName}`);
255
251
  process.exit(1);
256
- }
257
- scriptIds.push(script.id);
258
- resolvedScripts.push({ id: script.id, name: script.name });
259
252
  }
260
- update.scriptFileIds = scriptIds;
261
- if (!options.entrypoint && !app.mainScriptFileId && resolvedScripts.length > 0) {
262
- update.mainScriptFileId = resolvedScripts[0].id;
263
- autoSetEntrypoint = true;
264
- autoEntrypointName = resolvedScripts[0].name;
253
+ // Build update object
254
+ const update = {};
255
+ if (options.name) {
256
+ update.name = options.name;
257
+ }
258
+ if (options.description !== undefined) {
259
+ update.description = options.description;
265
260
  }
266
- }
267
- if (options.entrypoint) {
268
- const entryScript = availableScripts.find(
269
- (s) => s.name.toLowerCase() === options.entrypoint.toLowerCase()
270
- );
271
- if (!entryScript) {
272
- import_logger.logger.error(`Entrypoint script not found: ${options.entrypoint}`);
273
- import_logger.logger.dim("Available scripts: " + availableScripts.map((s) => s.name).join(", "));
274
- process.exit(1);
261
+ // Handle scripts and entrypoint
262
+ if (options.scripts || options.entrypoint) {
263
+ const availableScripts = await api.getScriptFiles();
264
+ let autoSetEntrypoint = false;
265
+ let autoEntrypointName = '';
266
+ if (options.scripts) {
267
+ const scriptNames = options.scripts.split(',').map((s) => s.trim());
268
+ const scriptIds = [];
269
+ const resolvedScripts = [];
270
+ for (const name of scriptNames) {
271
+ const script = availableScripts.find((s) => s.name.toLowerCase() === name.toLowerCase());
272
+ if (!script) {
273
+ logger_1.logger.error(`Script not found: ${name}`);
274
+ logger_1.logger.dim('Available scripts: ' +
275
+ availableScripts.map((s) => s.name).join(', '));
276
+ process.exit(1);
277
+ }
278
+ scriptIds.push(script.id);
279
+ resolvedScripts.push({ id: script.id, name: script.name });
280
+ }
281
+ update.scriptFileIds = scriptIds;
282
+ // Auto-set first script as entrypoint if no entrypoint specified and app has none
283
+ if (!options.entrypoint && !app.mainScriptFileId && resolvedScripts.length > 0) {
284
+ update.mainScriptFileId = resolvedScripts[0].id;
285
+ autoSetEntrypoint = true;
286
+ autoEntrypointName = resolvedScripts[0].name;
287
+ }
288
+ }
289
+ if (options.entrypoint) {
290
+ const entryScript = availableScripts.find((s) => s.name.toLowerCase() === options.entrypoint.toLowerCase());
291
+ if (!entryScript) {
292
+ logger_1.logger.error(`Entrypoint script not found: ${options.entrypoint}`);
293
+ logger_1.logger.dim('Available scripts: ' + availableScripts.map((s) => s.name).join(', '));
294
+ process.exit(1);
295
+ }
296
+ update.mainScriptFileId = entryScript.id;
297
+ // If setting entrypoint but no scripts specified, include the entrypoint in scripts
298
+ if (!update.scriptFileIds) {
299
+ update.scriptFileIds = [entryScript.id];
300
+ }
301
+ else if (!update.scriptFileIds.includes(entryScript.id)) {
302
+ update.scriptFileIds.push(entryScript.id);
303
+ }
304
+ }
305
+ // Notify user about auto-set entrypoint
306
+ if (autoSetEntrypoint) {
307
+ logger_1.logger.info(`Auto-set "${autoEntrypointName}" as entrypoint (first script).`);
308
+ logger_1.logger.dim(`Change with: farseer app configure "${appName}" --entrypoint <script>`);
309
+ }
310
+ }
311
+ // Handle arguments
312
+ if (options.addArg && options.addArg.length > 0) {
313
+ const newArgs = [...app.expectedArguments];
314
+ for (const arg of options.addArg) {
315
+ const [name, defaultValue] = arg.split('=');
316
+ if (!name || defaultValue === undefined) {
317
+ logger_1.logger.error(`Invalid argument format: ${arg}`);
318
+ logger_1.logger.dim('Use format: --add-arg "Name=DefaultValue"');
319
+ process.exit(1);
320
+ }
321
+ // Check if arg already exists
322
+ const existingIdx = newArgs.findIndex((a) => a.name.toLowerCase() === name.toLowerCase());
323
+ if (existingIdx >= 0) {
324
+ newArgs[existingIdx] = { name, type: 'variable', defaultValue };
325
+ }
326
+ else {
327
+ newArgs.push({ name, type: 'variable', defaultValue });
328
+ }
329
+ }
330
+ update.expectedArguments = newArgs;
275
331
  }
276
- update.mainScriptFileId = entryScript.id;
277
- if (!update.scriptFileIds) {
278
- update.scriptFileIds = [entryScript.id];
279
- } else if (!update.scriptFileIds.includes(entryScript.id)) {
280
- update.scriptFileIds.push(entryScript.id);
332
+ if (Object.keys(update).length === 0) {
333
+ logger_1.logger.warning('No changes specified.');
334
+ logger_1.logger.dim('Use --entrypoint, --scripts, --add-arg, --description, or --name to configure the app.');
335
+ return;
281
336
  }
282
- }
283
- if (autoSetEntrypoint) {
284
- import_logger.logger.info(`Auto-set "${autoEntrypointName}" as entrypoint (first script).`);
285
- import_logger.logger.dim(`Change with: farseer app configure "${appName}" --entrypoint <script>`);
286
- }
287
- }
288
- if (options.addArg && options.addArg.length > 0) {
289
- const newArgs = [...app.expectedArguments];
290
- for (const arg of options.addArg) {
291
- const [name, defaultValue] = arg.split("=");
292
- if (!name || defaultValue === void 0) {
293
- import_logger.logger.error(`Invalid argument format: ${arg}`);
294
- import_logger.logger.dim('Use format: --add-arg "Name=DefaultValue"');
295
- process.exit(1);
337
+ logger_1.logger.info(`Updating app: ${app.name}...`);
338
+ try {
339
+ // API requires name field to be present
340
+ if (!update.name) {
341
+ update.name = app.name;
342
+ }
343
+ if (update.description === undefined) {
344
+ update.description = app.description || '';
345
+ }
346
+ const updated = await api.updateApp(appListItem.reference, update);
347
+ logger_1.logger.success(`App updated: ${updated.name}`);
348
+ // Show summary of changes
349
+ if (update.name)
350
+ console.log(` Name: ${updated.name}`);
351
+ if (update.description !== undefined)
352
+ console.log(` Description: ${updated.description || '(empty)'}`);
353
+ if (update.mainScriptFileId) {
354
+ const updatedScripts = updated.scriptFiles ?? [];
355
+ const mainScript = updatedScripts.find((s) => s.id === updated.mainScriptFileId);
356
+ console.log(` Entrypoint: ${mainScript?.name}`);
357
+ }
358
+ if (update.scriptFileIds) {
359
+ console.log(` Scripts: ${(updated.scriptFiles ?? []).map((s) => s.name).join(', ')}`);
360
+ }
361
+ if (update.expectedArguments) {
362
+ console.log(` Arguments: ${updated.expectedArguments.map((a) => `${a.name}=${a.defaultValue}`).join(', ')}`);
363
+ }
296
364
  }
297
- const existingIdx = newArgs.findIndex((a) => a.name.toLowerCase() === name.toLowerCase());
298
- if (existingIdx >= 0) {
299
- newArgs[existingIdx] = { name, type: "variable", defaultValue };
300
- } else {
301
- newArgs.push({ name, type: "variable", defaultValue });
365
+ catch (error) {
366
+ logger_1.logger.error('Failed to update app.');
367
+ if (error instanceof Error) {
368
+ logger_1.logger.dim(error.message);
369
+ }
370
+ process.exit(1);
302
371
  }
303
- }
304
- update.expectedArguments = newArgs;
305
- }
306
- if (Object.keys(update).length === 0) {
307
- import_logger.logger.warning("No changes specified.");
308
- import_logger.logger.dim("Use --entrypoint, --scripts, --add-arg, --description, or --name to configure the app.");
309
- return;
310
- }
311
- import_logger.logger.info(`Updating app: ${app.name}...`);
312
- try {
313
- if (!update.name) {
314
- update.name = app.name;
315
- }
316
- if (update.description === void 0) {
317
- update.description = app.description || "";
318
- }
319
- const updated = await api.updateApp(appListItem.reference, update);
320
- import_logger.logger.success(`App updated: ${updated.name}`);
321
- if (update.name) console.log(` Name: ${updated.name}`);
322
- if (update.description !== void 0) console.log(` Description: ${updated.description || "(empty)"}`);
323
- if (update.mainScriptFileId) {
324
- const mainScript = updated.scriptFiles.find((s) => s.id === updated.mainScriptFileId);
325
- console.log(` Entrypoint: ${mainScript?.name}`);
326
- }
327
- if (update.scriptFileIds) {
328
- console.log(` Scripts: ${updated.scriptFiles.map((s) => s.name).join(", ")}`);
329
- }
330
- if (update.expectedArguments) {
331
- console.log(` Arguments: ${updated.expectedArguments.map((a) => `${a.name}=${a.defaultValue}`).join(", ")}`);
332
- }
333
- } catch (error) {
334
- import_logger.logger.error("Failed to update app.");
335
- if (error instanceof Error) {
336
- import_logger.logger.dim(error.message);
337
- }
338
- process.exit(1);
339
- }
340
- });
372
+ });
341
373
  }
374
+ // Helper to collect multiple --add-arg options
342
375
  function collectArgs(value, previous) {
343
- return previous.concat([value]);
376
+ return previous.concat([value]);
344
377
  }
345
- // Annotate the CommonJS export names for ESM import in node:
346
- 0 && (module.exports = {
347
- registerAppCommand
348
- });
349
- //# sourceMappingURL=app.js.map