farseer-cli 1.0.8 → 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.
- package/dist/commands/app.js +377 -0
- package/dist/commands/apps.js +91 -0
- package/dist/commands/checkout.js +164 -0
- package/dist/commands/config.js +141 -0
- package/dist/commands/diff.js +210 -0
- package/dist/commands/dimensions.js +130 -0
- package/dist/commands/files.js +88 -0
- package/dist/commands/install.js +82 -0
- package/dist/commands/list.js +77 -0
- package/dist/commands/login.js +109 -0
- package/dist/commands/logout.js +44 -0
- package/dist/commands/mcp-server.js +26 -0
- package/dist/commands/model.js +181 -0
- package/dist/commands/pull.js +286 -0
- package/dist/commands/push.js +235 -0
- package/dist/commands/run.js +336 -0
- package/dist/commands/status.js +178 -0
- package/dist/commands/variables.js +200 -0
- package/dist/commands/whoami.js +47 -0
- package/dist/index.js +163 -0
- package/dist/mcp/index.js +19 -0
- package/dist/mcp/prompts/workflows.js +403 -0
- package/dist/mcp/resources/documentation.js +158 -0
- package/dist/mcp/server.js +36 -0
- package/dist/mcp/tools/appTools.js +348 -0
- package/dist/mcp/tools/authTools.js +152 -0
- package/dist/mcp/tools/dataTools.js +358 -0
- package/dist/mcp/tools/modelTools.js +293 -0
- package/dist/mcp/tools/runTools.js +239 -0
- package/dist/mcp/tools/syncTools.js +383 -0
- package/dist/mcp/utils/helpers.js +142 -0
- package/dist/services/appSyncService.js +458 -0
- package/dist/services/configService.js +186 -0
- package/dist/services/farseerApi.js +426 -0
- package/dist/services/farseerFactory.js +297 -0
- package/dist/services/farseerService.js +647 -0
- package/dist/services/syncService.js +764 -0
- package/dist/utils/constants.js +21 -0
- package/dist/utils/helpers.js +446 -0
- package/dist/utils/logger.js +45 -0
- package/package.json +8 -1
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
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");
|
|
11
|
+
function registerAppCommand(program) {
|
|
12
|
+
const appCmd = program
|
|
13
|
+
.command('app')
|
|
14
|
+
.description('Manage apps on a Farseer instance')
|
|
15
|
+
.addHelpText('after', `
|
|
16
|
+
Commands:
|
|
17
|
+
list [tenant] List all apps
|
|
18
|
+
show [tenant] <name...> Show app details
|
|
19
|
+
create [tenant] <name...> Create a new app
|
|
20
|
+
configure [tenant] <name...> Configure app (entrypoint, scripts, arguments)
|
|
21
|
+
delete [tenant] <name...> Delete an app (requires --force)
|
|
22
|
+
|
|
23
|
+
Note: App names with spaces don't need quotes if tenant is checked out.
|
|
24
|
+
|
|
25
|
+
Examples:
|
|
26
|
+
$ farseer app list mycompany # List all apps
|
|
27
|
+
$ farseer app show mycompany "My App" # Explicit tenant
|
|
28
|
+
$ farseer app show My App # Uses checked-out tenant
|
|
29
|
+
$ farseer app configure "My App" --entrypoint index.ts
|
|
30
|
+
`);
|
|
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;
|
|
52
|
+
}
|
|
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
|
+
}
|
|
87
|
+
}
|
|
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.');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
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');
|
|
151
|
+
}
|
|
152
|
+
console.log();
|
|
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}`);
|
|
251
|
+
process.exit(1);
|
|
252
|
+
}
|
|
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;
|
|
260
|
+
}
|
|
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;
|
|
331
|
+
}
|
|
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;
|
|
336
|
+
}
|
|
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
|
+
}
|
|
364
|
+
}
|
|
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);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
// Helper to collect multiple --add-arg options
|
|
375
|
+
function collectArgs(value, previous) {
|
|
376
|
+
return previous.concat([value]);
|
|
377
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerAppsCommand = registerAppsCommand;
|
|
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");
|
|
11
|
+
function registerAppsCommand(program) {
|
|
12
|
+
program
|
|
13
|
+
.command('apps [tenant]')
|
|
14
|
+
.description('List all apps on a Farseer instance')
|
|
15
|
+
.option('--details', 'Show detailed information for each app')
|
|
16
|
+
.action(async (tenantArg, options) => {
|
|
17
|
+
const { organisation, tenant } = (0, helpers_1.resolveTenantWithOrgMapping)(tenantArg);
|
|
18
|
+
const result = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
19
|
+
if (!result) {
|
|
20
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
const api = result.client;
|
|
24
|
+
const authLabel = result.authType === 'apiKey' ? 'API key' : 'browser login';
|
|
25
|
+
logger_1.logger.info(`Fetching apps from ${tenant} (using ${authLabel})...`);
|
|
26
|
+
try {
|
|
27
|
+
const apps = await api.listApps();
|
|
28
|
+
if (apps.length === 0) {
|
|
29
|
+
logger_1.logger.warning('No apps found.');
|
|
30
|
+
logger_1.logger.dim('Create an app with: farseer app create <app-name>');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
logger_1.logger.header(`Apps on ${tenant}`);
|
|
34
|
+
console.log();
|
|
35
|
+
if (options.details) {
|
|
36
|
+
// Fetch full details for each app
|
|
37
|
+
for (const app of apps) {
|
|
38
|
+
const details = await api.getApp(app.reference);
|
|
39
|
+
if (details) {
|
|
40
|
+
console.log(` 📦 ${chalk_1.default.bold(details.name)}`);
|
|
41
|
+
if (details.description) {
|
|
42
|
+
console.log(` ${chalk_1.default.dim(details.description)}`);
|
|
43
|
+
}
|
|
44
|
+
console.log(` Status: ${details.status === 'AVAILABLE' ? chalk_1.default.green(details.status) : chalk_1.default.yellow(details.status)}`);
|
|
45
|
+
const detailScripts = details.scriptFiles ?? [];
|
|
46
|
+
if (detailScripts.length > 0) {
|
|
47
|
+
const mainScript = detailScripts.find((s) => s.id === details.mainScriptFileId);
|
|
48
|
+
console.log(` Entrypoint: ${mainScript ? chalk_1.default.cyan(mainScript.name) : chalk_1.default.red('Not set')}`);
|
|
49
|
+
console.log(` Scripts:`);
|
|
50
|
+
for (const script of detailScripts) {
|
|
51
|
+
const isMain = script.id === details.mainScriptFileId;
|
|
52
|
+
console.log(` ${isMain ? chalk_1.default.green('▶') : ' '} ${script.name}${isMain ? chalk_1.default.dim(' (entrypoint)') : ''}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
console.log(` Scripts: ${chalk_1.default.dim('None')}`);
|
|
57
|
+
}
|
|
58
|
+
if (details.expectedArguments.length > 0) {
|
|
59
|
+
console.log(` Arguments:`);
|
|
60
|
+
for (const arg of details.expectedArguments) {
|
|
61
|
+
console.log(` - ${arg.name}: ${chalk_1.default.dim(arg.defaultValue)}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
console.log();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Simple list
|
|
70
|
+
for (const app of apps) {
|
|
71
|
+
console.log(` 📦 ${app.name}`);
|
|
72
|
+
}
|
|
73
|
+
console.log();
|
|
74
|
+
logger_1.logger.dim(`Total: ${apps.length} app(s)`);
|
|
75
|
+
logger_1.logger.dim('Use --details to see more information.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if ((0, farseerFactory_1.isAuthError)(error)) {
|
|
80
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
logger_1.logger.error('Failed to list apps.');
|
|
84
|
+
if (error instanceof Error) {
|
|
85
|
+
logger_1.logger.dim(error.message);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.registerCheckoutCommand = registerCheckoutCommand;
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
const logger_1 = require("../utils/logger");
|
|
42
|
+
const configService_1 = require("../services/configService");
|
|
43
|
+
const farseerFactory_1 = require("../services/farseerFactory");
|
|
44
|
+
const syncService_1 = require("../services/syncService");
|
|
45
|
+
const appSyncService_1 = require("../services/appSyncService");
|
|
46
|
+
const helpers_1 = require("../utils/helpers");
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
const path = __importStar(require("path"));
|
|
49
|
+
function registerCheckoutCommand(program) {
|
|
50
|
+
program
|
|
51
|
+
.command('checkout [org] [tenant]')
|
|
52
|
+
.description('Set default tenant for commands (runs auth check and pull)')
|
|
53
|
+
.option('--no-pull', 'Skip automatic pull')
|
|
54
|
+
.option('--clear', 'Clear current checkout')
|
|
55
|
+
.action(async (first, second, options) => {
|
|
56
|
+
// Handle --clear flag
|
|
57
|
+
if (options.clear) {
|
|
58
|
+
(0, configService_1.clearCurrentTenant)();
|
|
59
|
+
logger_1.logger.success('Checkout cleared. You now need to specify tenant for each command.');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
// If no arguments specified, show current checkout status
|
|
63
|
+
if (!first) {
|
|
64
|
+
const current = (0, configService_1.getCurrentCheckout)();
|
|
65
|
+
if (current) {
|
|
66
|
+
if (current.organisation === current.tenant) {
|
|
67
|
+
logger_1.logger.info(`Currently checked out: ${chalk_1.default.bold(current.tenant)}`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
logger_1.logger.info(`Currently checked out: ${chalk_1.default.bold(current.tenant)} (org: ${chalk_1.default.bold(current.organisation)})`);
|
|
71
|
+
}
|
|
72
|
+
logger_1.logger.dim('Run "farseer checkout <tenant>" to switch tenants.');
|
|
73
|
+
logger_1.logger.dim('Run "farseer checkout --clear" to clear checkout.');
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
logger_1.logger.info('No tenant currently checked out.');
|
|
77
|
+
logger_1.logger.dim('Run "farseer checkout <tenant>" to set a default tenant.');
|
|
78
|
+
logger_1.logger.dim('Run "farseer checkout <org> <tenant>" if organisation and tenant differ.');
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Determine organisation and tenant
|
|
83
|
+
// If two arguments: first=organisation, second=tenant
|
|
84
|
+
// If one argument: organisation=tenant=first
|
|
85
|
+
const organisation = second ? first : first;
|
|
86
|
+
const tenant = second || first;
|
|
87
|
+
logger_1.logger.info(`Checking out tenant: ${chalk_1.default.bold(tenant)} (org: ${chalk_1.default.bold(organisation)})...`);
|
|
88
|
+
console.log();
|
|
89
|
+
// Step 1: Verify authentication
|
|
90
|
+
logger_1.logger.info('Verifying authentication...');
|
|
91
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
92
|
+
if (!clientResult) {
|
|
93
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
const authLabel = clientResult.authType === 'apiKey' ? 'API key' : 'browser login';
|
|
97
|
+
logger_1.logger.success(`Authenticated (using ${authLabel})`);
|
|
98
|
+
// Step 2: Set as current checkout and save org-tenant mapping
|
|
99
|
+
(0, configService_1.setCurrentCheckout)(organisation, tenant);
|
|
100
|
+
(0, configService_1.saveTenantOrgMapping)(tenant, organisation);
|
|
101
|
+
// Step 3: Auto-pull (unless --no-pull)
|
|
102
|
+
if (options.pull) {
|
|
103
|
+
console.log();
|
|
104
|
+
logger_1.logger.info('Pulling latest files and apps...');
|
|
105
|
+
const syncService = new syncService_1.SyncService(tenant, clientResult.client);
|
|
106
|
+
const tenantDir = (0, helpers_1.getTenantDir)(tenant);
|
|
107
|
+
(0, helpers_1.ensureDirectoryExists)(tenantDir);
|
|
108
|
+
try {
|
|
109
|
+
// Ensure package.json exists
|
|
110
|
+
const packageJsonPath = path.join(tenantDir, 'package.json');
|
|
111
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
112
|
+
createDefaultPackageJson(tenant, packageJsonPath);
|
|
113
|
+
}
|
|
114
|
+
// Pull files (scripts only by default)
|
|
115
|
+
const result = await syncService.pull({ all: false });
|
|
116
|
+
logger_1.logger.dim(`Files: +${result.downloaded.length} -${result.deleted.length} (${result.unchanged.length} unchanged)`);
|
|
117
|
+
// Pull apps
|
|
118
|
+
const appSyncService = new appSyncService_1.AppSyncService(tenant, clientResult.client);
|
|
119
|
+
const appResult = await appSyncService.pull();
|
|
120
|
+
logger_1.logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);
|
|
121
|
+
logger_1.logger.success('Pull complete!');
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
logger_1.logger.warning('Pull failed, but checkout is complete.');
|
|
125
|
+
if (error instanceof Error) {
|
|
126
|
+
logger_1.logger.dim(error.message);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Final message
|
|
131
|
+
console.log();
|
|
132
|
+
logger_1.logger.success(`Tenant ${chalk_1.default.bold(tenant)} is now checked out.`);
|
|
133
|
+
logger_1.logger.dim('You can now run commands without specifying the tenant:');
|
|
134
|
+
logger_1.logger.dim(' farseer status');
|
|
135
|
+
logger_1.logger.dim(' farseer model --variables');
|
|
136
|
+
logger_1.logger.dim(' farseer apps');
|
|
137
|
+
logger_1.logger.dim(' farseer push');
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function createDefaultPackageJson(tenant, packageJsonPath) {
|
|
141
|
+
const packageJson = {
|
|
142
|
+
name: `farseer-${tenant}`,
|
|
143
|
+
version: '1.0.0',
|
|
144
|
+
description: `Farseer scripts for ${tenant}`,
|
|
145
|
+
type: 'module',
|
|
146
|
+
scripts: {
|
|
147
|
+
build: 'tsc',
|
|
148
|
+
},
|
|
149
|
+
dependencies: {
|
|
150
|
+
'farseer-client': 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client/release-1.4.5.tar',
|
|
151
|
+
arquero: '^7.0.1',
|
|
152
|
+
xlsx: '^0.18.5',
|
|
153
|
+
xmldom: '^0.6.0',
|
|
154
|
+
},
|
|
155
|
+
devDependencies: {
|
|
156
|
+
'@types/node': '^22.5.0',
|
|
157
|
+
'@types/xmldom': '^0.1.34',
|
|
158
|
+
'ts-node': '^10.9.2',
|
|
159
|
+
typescript: '^5.5.4',
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
|
|
163
|
+
logger_1.logger.dim(`Created package.json for ${tenant}`);
|
|
164
|
+
}
|