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,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerConfigCommand = registerConfigCommand;
|
|
4
|
+
const logger_1 = require("../utils/logger");
|
|
5
|
+
const configService_1 = require("../services/configService");
|
|
6
|
+
const farseerService_1 = require("../services/farseerService");
|
|
7
|
+
const helpers_1 = require("../utils/helpers");
|
|
8
|
+
function registerConfigCommand(program) {
|
|
9
|
+
const configCmd = program
|
|
10
|
+
.command('config')
|
|
11
|
+
.description('Manage Farseer CLI configuration')
|
|
12
|
+
.addHelpText('after', `
|
|
13
|
+
Commands:
|
|
14
|
+
set <tenant> Set API key for a tenant
|
|
15
|
+
remove <tenant> Remove credentials for a tenant
|
|
16
|
+
list List all configured tenants
|
|
17
|
+
show <tenant> Show full credentials (including API key)
|
|
18
|
+
test <tenant> Test connection to a tenant
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
$ farseer config set mycompany --api-key xxx
|
|
22
|
+
$ farseer config set mycompany --api-key xxx --org myorg
|
|
23
|
+
$ farseer config list
|
|
24
|
+
$ farseer config test mycompany
|
|
25
|
+
`);
|
|
26
|
+
configCmd
|
|
27
|
+
.command('set <tenant>')
|
|
28
|
+
.description('Set credentials for a tenant (use --org if org differs from tenant)')
|
|
29
|
+
.requiredOption('--api-key <key>', 'API key for the tenant')
|
|
30
|
+
.option('--org <organisation>', 'Organisation name if different from tenant (e.g., --org mycompany)')
|
|
31
|
+
.option('--base-path <url>', 'Custom base path (overrides organisation)')
|
|
32
|
+
.option('--no-test', 'Skip connection test')
|
|
33
|
+
.action(async (tenant, options) => {
|
|
34
|
+
const organisation = options.org || tenant;
|
|
35
|
+
const basePath = options.basePath || (0, configService_1.generateBasePath)(organisation);
|
|
36
|
+
const apiKey = options.apiKey;
|
|
37
|
+
const credential = {
|
|
38
|
+
type: 'apiKey',
|
|
39
|
+
tenantId: tenant,
|
|
40
|
+
apiKey: apiKey,
|
|
41
|
+
basePath: basePath,
|
|
42
|
+
};
|
|
43
|
+
if (options.test !== false) {
|
|
44
|
+
logger_1.logger.info('Testing connection...');
|
|
45
|
+
const service = new farseerService_1.FarseerService(credential);
|
|
46
|
+
const isConnected = await service.testConnection();
|
|
47
|
+
if (!isConnected) {
|
|
48
|
+
logger_1.logger.error('Connection failed. Please check your credentials.');
|
|
49
|
+
logger_1.logger.dim(`Tried to connect to: ${basePath}`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
(0, configService_1.setCredential)(tenant, credential);
|
|
54
|
+
logger_1.logger.success(`Credentials saved for tenant: ${tenant}`);
|
|
55
|
+
logger_1.logger.table([
|
|
56
|
+
{ label: 'Tenant ID', value: tenant },
|
|
57
|
+
{ label: 'Base Path', value: basePath },
|
|
58
|
+
{ label: 'API Key', value: apiKey.substring(0, 8) + '...' },
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
configCmd
|
|
62
|
+
.command('remove <tenant>')
|
|
63
|
+
.description('Remove credentials for a tenant')
|
|
64
|
+
.action((tenant) => {
|
|
65
|
+
const removed = (0, configService_1.removeCredential)(tenant);
|
|
66
|
+
if (removed) {
|
|
67
|
+
logger_1.logger.success(`Removed credentials for tenant: ${tenant}`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
logger_1.logger.warning(`No credentials found for tenant: ${tenant}`);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
configCmd
|
|
74
|
+
.command('list')
|
|
75
|
+
.description('List all configured tenants')
|
|
76
|
+
.action(() => {
|
|
77
|
+
const credentials = (0, configService_1.listCredentials)();
|
|
78
|
+
const tenants = Object.keys(credentials);
|
|
79
|
+
if (tenants.length === 0) {
|
|
80
|
+
logger_1.logger.info('No tenants configured.');
|
|
81
|
+
logger_1.logger.dim('Use "farseer config set <tenant> --api-key <key>" to add one.');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
logger_1.logger.header('Configured Tenants');
|
|
85
|
+
for (const tenant of tenants) {
|
|
86
|
+
const cred = credentials[tenant];
|
|
87
|
+
console.log(` ${tenant}`);
|
|
88
|
+
logger_1.logger.dim(` Base: ${cred.basePath}`);
|
|
89
|
+
logger_1.logger.dim(` Key: ${cred.apiKey.substring(0, 8)}...`);
|
|
90
|
+
console.log();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
configCmd
|
|
94
|
+
.command('show <tenant>')
|
|
95
|
+
.description('Show full credentials for a tenant (including API key)')
|
|
96
|
+
.action((tenant) => {
|
|
97
|
+
const credentials = (0, configService_1.listCredentials)();
|
|
98
|
+
const cred = credentials[tenant];
|
|
99
|
+
if (!cred) {
|
|
100
|
+
logger_1.logger.error(`No credentials found for tenant: ${tenant}`);
|
|
101
|
+
logger_1.logger.dim((0, helpers_1.getCredentialsHint)(tenant));
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
logger_1.logger.header(`Credentials for ${tenant}`);
|
|
105
|
+
logger_1.logger.table([
|
|
106
|
+
{ label: 'Tenant ID', value: tenant },
|
|
107
|
+
{ label: 'Base Path', value: cred.basePath },
|
|
108
|
+
{ label: 'API Key', value: cred.apiKey },
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
configCmd
|
|
112
|
+
.command('test <tenant>')
|
|
113
|
+
.description('Test connection to a tenant')
|
|
114
|
+
.action(async (tenant) => {
|
|
115
|
+
const credentials = (0, configService_1.listCredentials)();
|
|
116
|
+
const cred = credentials[tenant];
|
|
117
|
+
if (!cred) {
|
|
118
|
+
logger_1.logger.error(`No credentials found for tenant: ${tenant}`);
|
|
119
|
+
logger_1.logger.dim((0, helpers_1.getCredentialsHint)(tenant));
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
logger_1.logger.info(`Testing connection to ${tenant}...`);
|
|
123
|
+
const service = new farseerService_1.FarseerService(cred);
|
|
124
|
+
const isConnected = await service.testConnection();
|
|
125
|
+
if (isConnected) {
|
|
126
|
+
logger_1.logger.success(`Connection successful!`);
|
|
127
|
+
// Try to get files folder
|
|
128
|
+
const filesFolder = await service.getFilesFolder();
|
|
129
|
+
if (filesFolder) {
|
|
130
|
+
logger_1.logger.dim('Files folder found.');
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
logger_1.logger.warning('Files folder not found. It will be created on first push.');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
logger_1.logger.error('Connection failed.');
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
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.registerDiffCommand = registerDiffCommand;
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
const Diff = __importStar(require("diff"));
|
|
42
|
+
const logger_1 = require("../utils/logger");
|
|
43
|
+
const farseerFactory_1 = require("../services/farseerFactory");
|
|
44
|
+
const syncService_1 = require("../services/syncService");
|
|
45
|
+
const helpers_1 = require("../utils/helpers");
|
|
46
|
+
const fs = __importStar(require("fs"));
|
|
47
|
+
function registerDiffCommand(program) {
|
|
48
|
+
program
|
|
49
|
+
.command('diff [arg1] [arg2] [file]')
|
|
50
|
+
.description('Show differences between local and remote files\n\nUsage: diff <org> <tenant> [file] OR diff <tenant> [file] (if org is known)')
|
|
51
|
+
.option('--remote', 'Show remote version of file(s)')
|
|
52
|
+
.action(async (arg1, arg2, file, options) => {
|
|
53
|
+
// Resolve org/tenant based on number of args
|
|
54
|
+
let organisation;
|
|
55
|
+
let tenant;
|
|
56
|
+
let actualFile;
|
|
57
|
+
// If arg2 looks like a file path (has extension or slash), treat as: diff <tenant> <file>
|
|
58
|
+
if (arg2 && (arg2.includes('/') || arg2.includes('.'))) {
|
|
59
|
+
const resolved = (0, helpers_1.resolveTenantWithOrgMapping)(arg1, undefined);
|
|
60
|
+
organisation = resolved.organisation;
|
|
61
|
+
tenant = resolved.tenant;
|
|
62
|
+
actualFile = arg2;
|
|
63
|
+
}
|
|
64
|
+
else if (arg2) {
|
|
65
|
+
// Two non-file args: diff <org> <tenant> [file]
|
|
66
|
+
const resolved = (0, helpers_1.resolveTenantWithOrgMapping)(arg1, arg2);
|
|
67
|
+
organisation = resolved.organisation;
|
|
68
|
+
tenant = resolved.tenant;
|
|
69
|
+
actualFile = file;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// One arg: diff <tenant> [file] or diff [file] (if checked out)
|
|
73
|
+
const resolved = (0, helpers_1.resolveTenantWithOrgMapping)(arg1, undefined);
|
|
74
|
+
organisation = resolved.organisation;
|
|
75
|
+
tenant = resolved.tenant;
|
|
76
|
+
actualFile = undefined;
|
|
77
|
+
}
|
|
78
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
79
|
+
if (!clientResult) {
|
|
80
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
const filesDir = (0, helpers_1.getTenantFilesDir)(tenant);
|
|
84
|
+
const syncService = new syncService_1.SyncService(tenant, clientResult.client);
|
|
85
|
+
if (actualFile) {
|
|
86
|
+
// Show diff for specific file
|
|
87
|
+
await showFileDiff(syncService, actualFile, options.remote);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// Show diff for all changed files
|
|
91
|
+
await showAllDiffs(syncService, filesDir);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async function showFileDiff(syncService, filePath, showRemote) {
|
|
96
|
+
logger_1.logger.info(`Fetching diff for: ${filePath}`);
|
|
97
|
+
console.log();
|
|
98
|
+
try {
|
|
99
|
+
const { localContent, remoteContent } = await syncService.getFileDiff(filePath);
|
|
100
|
+
if (showRemote) {
|
|
101
|
+
if (remoteContent) {
|
|
102
|
+
console.log(remoteContent);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
logger_1.logger.warning('File does not exist on remote.');
|
|
106
|
+
}
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!localContent && !remoteContent) {
|
|
110
|
+
logger_1.logger.warning('File does not exist locally or remotely.');
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!localContent) {
|
|
114
|
+
logger_1.logger.info('File only exists on remote (not downloaded).');
|
|
115
|
+
console.log();
|
|
116
|
+
console.log(chalk_1.default.green('--- Remote content ---'));
|
|
117
|
+
console.log(remoteContent);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!remoteContent) {
|
|
121
|
+
logger_1.logger.info('File only exists locally (new file).');
|
|
122
|
+
console.log();
|
|
123
|
+
console.log(chalk_1.default.yellow('--- Local content ---'));
|
|
124
|
+
console.log(localContent);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (localContent === remoteContent) {
|
|
128
|
+
logger_1.logger.success('Files are identical.');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
printDiff(filePath, remoteContent, localContent);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
logger_1.logger.error('Failed to get diff.');
|
|
135
|
+
if (error instanceof Error) {
|
|
136
|
+
logger_1.logger.dim(error.message);
|
|
137
|
+
}
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function showAllDiffs(syncService, filesDir) {
|
|
142
|
+
if (!fs.existsSync(filesDir)) {
|
|
143
|
+
logger_1.logger.warning('Local folder not found. Run "farseer pull" first.');
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
logger_1.logger.info('Fetching status...');
|
|
147
|
+
try {
|
|
148
|
+
const status = await syncService.getStatus();
|
|
149
|
+
const conflictFiles = (status.conflicts || []).map((c) => c.filePath);
|
|
150
|
+
const changedFiles = [
|
|
151
|
+
...status.modifiedLocally,
|
|
152
|
+
...status.modifiedRemotely.filter((f) => !status.modifiedLocally.includes(f)),
|
|
153
|
+
...conflictFiles.filter((f) => !status.modifiedLocally.includes(f) && !status.modifiedRemotely.includes(f)),
|
|
154
|
+
];
|
|
155
|
+
if (changedFiles.length === 0) {
|
|
156
|
+
logger_1.logger.success('No differences found.');
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
for (const file of changedFiles) {
|
|
160
|
+
console.log();
|
|
161
|
+
console.log(chalk_1.default.bold(`=== ${file} ===`));
|
|
162
|
+
console.log();
|
|
163
|
+
const { localContent, remoteContent } = await syncService.getFileDiff(file);
|
|
164
|
+
if (!localContent && remoteContent) {
|
|
165
|
+
console.log(chalk_1.default.red('File only exists on remote (deleted locally or new on remote).'));
|
|
166
|
+
}
|
|
167
|
+
else if (localContent && !remoteContent) {
|
|
168
|
+
console.log(chalk_1.default.green('File only exists locally (new file or deleted on remote).'));
|
|
169
|
+
}
|
|
170
|
+
else if (localContent && remoteContent) {
|
|
171
|
+
if (localContent === remoteContent) {
|
|
172
|
+
console.log(chalk_1.default.green('Files are identical.'));
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
printDiff(file, remoteContent, localContent);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
console.log();
|
|
180
|
+
logger_1.logger.dim(`${changedFiles.length} file(s) with differences.`);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
logger_1.logger.error('Failed to get diffs.');
|
|
184
|
+
if (error instanceof Error) {
|
|
185
|
+
logger_1.logger.dim(error.message);
|
|
186
|
+
}
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function printDiff(fileName, oldContent, newContent) {
|
|
191
|
+
const diff = Diff.createPatch(fileName, oldContent, newContent, 'remote', 'local');
|
|
192
|
+
const lines = diff.split('\n');
|
|
193
|
+
for (const line of lines) {
|
|
194
|
+
if (line.startsWith('+++') || line.startsWith('---')) {
|
|
195
|
+
console.log(chalk_1.default.bold(line));
|
|
196
|
+
}
|
|
197
|
+
else if (line.startsWith('+')) {
|
|
198
|
+
console.log(chalk_1.default.green(line));
|
|
199
|
+
}
|
|
200
|
+
else if (line.startsWith('-')) {
|
|
201
|
+
console.log(chalk_1.default.red(line));
|
|
202
|
+
}
|
|
203
|
+
else if (line.startsWith('@@')) {
|
|
204
|
+
console.log(chalk_1.default.cyan(line));
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
console.log(line);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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.registerDimensionsCommand = registerDimensionsCommand;
|
|
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 registerDimensionsCommand(program) {
|
|
12
|
+
// farseer dimensions list
|
|
13
|
+
const dimensionsCmd = program.command('dimensions').description('List and manage dimension tables');
|
|
14
|
+
dimensionsCmd
|
|
15
|
+
.command('list [org] [tenant]')
|
|
16
|
+
.description('List all dimension tables')
|
|
17
|
+
.option('--json', 'Output raw JSON')
|
|
18
|
+
.action(async (first, second, options) => {
|
|
19
|
+
const { organisation, tenant } = (0, helpers_1.resolveTenantWithOrgMapping)(first, second);
|
|
20
|
+
const result = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
21
|
+
if (!result) {
|
|
22
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const model = await result.client.exportModel();
|
|
27
|
+
if (options.json) {
|
|
28
|
+
const tablesInfo = model.tables.map((t) => ({
|
|
29
|
+
name: t.name,
|
|
30
|
+
memberCount: t.rows.length,
|
|
31
|
+
columns: t.columns,
|
|
32
|
+
folderPath: t.folderPath,
|
|
33
|
+
}));
|
|
34
|
+
console.log(JSON.stringify(tablesInfo, null, 2));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
logger_1.logger.header(`Dimension Tables (${model.tables.length})`);
|
|
38
|
+
console.log();
|
|
39
|
+
for (const table of model.tables) {
|
|
40
|
+
const fkColumns = table.columns.filter((c) => c.type === 'FOREIGN_KEY');
|
|
41
|
+
let info = ` ${chalk_1.default.bold(table.name)} ${chalk_1.default.dim(`(${table.rows.length} members)`)}`;
|
|
42
|
+
if (fkColumns.length > 0) {
|
|
43
|
+
info += chalk_1.default.cyan(` -> ${fkColumns.map((c) => c.foreignKeyTableName).join(', ')}`);
|
|
44
|
+
}
|
|
45
|
+
console.log(info);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
handleModelError(error, tenant);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
// farseer dimension details (singular)
|
|
53
|
+
const dimensionCmd = program.command('dimension').description('Dimension table details');
|
|
54
|
+
dimensionCmd
|
|
55
|
+
.command('details <name>')
|
|
56
|
+
.description('Show dimension table details (columns, members)')
|
|
57
|
+
.option('--json', 'Output raw JSON')
|
|
58
|
+
.option('--members <n>', 'Number of sample members to show', '10')
|
|
59
|
+
.action(async (name, options) => {
|
|
60
|
+
const { organisation, tenant } = (0, helpers_1.resolveTenantWithOrgMapping)();
|
|
61
|
+
const result = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
62
|
+
if (!result) {
|
|
63
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const model = await result.client.exportModel();
|
|
68
|
+
const table = model.tables.find((t) => t.name.toLowerCase() === name.toLowerCase());
|
|
69
|
+
if (!table) {
|
|
70
|
+
logger_1.logger.error(`Table "${name}" not found.`);
|
|
71
|
+
logger_1.logger.dim('Available tables:');
|
|
72
|
+
model.tables.slice(0, 10).forEach((t) => logger_1.logger.dim(` - ${t.name}`));
|
|
73
|
+
if (model.tables.length > 10) {
|
|
74
|
+
logger_1.logger.dim(` ... and ${model.tables.length - 10} more`);
|
|
75
|
+
}
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
if (options.json) {
|
|
79
|
+
console.log(JSON.stringify(table, null, 2));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const memberLimit = parseInt(options.members) || 10;
|
|
83
|
+
logger_1.logger.header(`Dimension Table: ${table.name}`);
|
|
84
|
+
console.log();
|
|
85
|
+
console.log(` Columns:`);
|
|
86
|
+
table.columns.forEach((col, i) => {
|
|
87
|
+
let colInfo = ` ${i + 1}. ${chalk_1.default.bold(col.type)}`;
|
|
88
|
+
if (col.name)
|
|
89
|
+
colInfo += ` (${col.name})`;
|
|
90
|
+
if (col.foreignKeyTableName)
|
|
91
|
+
colInfo += chalk_1.default.cyan(` -> ${col.foreignKeyTableName}`);
|
|
92
|
+
console.log(colInfo);
|
|
93
|
+
});
|
|
94
|
+
console.log(` Members: ${table.rows.length}`);
|
|
95
|
+
if (table.folderPath) {
|
|
96
|
+
console.log(` Folder: ${table.folderPath.join(' / ')}`);
|
|
97
|
+
}
|
|
98
|
+
if (table.rows.length > 0) {
|
|
99
|
+
console.log();
|
|
100
|
+
console.log(` Sample members (first ${Math.min(memberLimit, table.rows.length)}):`);
|
|
101
|
+
table.rows.slice(0, memberLimit).forEach((row) => {
|
|
102
|
+
console.log(` - ${row[0]}`);
|
|
103
|
+
});
|
|
104
|
+
if (table.rows.length > memberLimit) {
|
|
105
|
+
logger_1.logger.dim(` ... and ${table.rows.length - memberLimit} more`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
handleModelError(error, tenant);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function handleModelError(error, tenant) {
|
|
115
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
116
|
+
if ((0, farseerFactory_1.isAuthError)(error)) {
|
|
117
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
118
|
+
}
|
|
119
|
+
else if (errorMessage.includes('404')) {
|
|
120
|
+
logger_1.logger.error(`Tenant "${tenant}" not found or not accessible.`);
|
|
121
|
+
}
|
|
122
|
+
else if (errorMessage.includes('ENOTFOUND') || errorMessage.includes('ECONNREFUSED')) {
|
|
123
|
+
logger_1.logger.error('Failed to connect to Farseer.');
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
logger_1.logger.error('Failed to fetch model.');
|
|
127
|
+
logger_1.logger.dim(errorMessage);
|
|
128
|
+
}
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerFilesCommand = registerFilesCommand;
|
|
4
|
+
const logger_1 = require("../utils/logger");
|
|
5
|
+
const farseerFactory_1 = require("../services/farseerFactory");
|
|
6
|
+
const helpers_1 = require("../utils/helpers");
|
|
7
|
+
function registerFilesCommand(program) {
|
|
8
|
+
const filesCmd = program
|
|
9
|
+
.command('files')
|
|
10
|
+
.description('Manage files on a Farseer instance')
|
|
11
|
+
.addHelpText('after', `
|
|
12
|
+
Commands:
|
|
13
|
+
list [tenant] List all files on remote
|
|
14
|
+
|
|
15
|
+
Examples:
|
|
16
|
+
$ farseer files list # List script files
|
|
17
|
+
$ farseer files list --all # List all files
|
|
18
|
+
$ farseer files list mycompany # List files on specific tenant
|
|
19
|
+
`);
|
|
20
|
+
// List files
|
|
21
|
+
filesCmd
|
|
22
|
+
.command('list [org] [tenant]')
|
|
23
|
+
.description('List all files on a Farseer instance\n\nUsage: list <org> <tenant> OR list <tenant> (if org is known)')
|
|
24
|
+
.option('--all', 'List all files (default: only scripts .ts, .js)')
|
|
25
|
+
.action(async (arg1, arg2, options) => {
|
|
26
|
+
const { organisation, tenant } = (0, helpers_1.resolveTenantWithOrgMapping)(arg1, arg2);
|
|
27
|
+
const result = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
28
|
+
if (!result) {
|
|
29
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
const authLabel = result.authType === 'apiKey' ? 'API key' : 'browser login';
|
|
33
|
+
logger_1.logger.info(`Fetching files from ${tenant} (using ${authLabel})...`);
|
|
34
|
+
let files;
|
|
35
|
+
try {
|
|
36
|
+
files = await result.client.listFiles();
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if ((0, farseerFactory_1.isAuthError)(error)) {
|
|
40
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
logger_1.logger.error('Failed to list files.');
|
|
44
|
+
if (error instanceof Error) {
|
|
45
|
+
logger_1.logger.dim(error.message);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
// Filter to scripts only unless --all is specified
|
|
51
|
+
if (!options.all) {
|
|
52
|
+
files = files.filter((f) => farseerFactory_1.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.name.toLowerCase().endsWith(ext)));
|
|
53
|
+
}
|
|
54
|
+
if (files.length === 0) {
|
|
55
|
+
logger_1.logger.warning('No files found in Files/');
|
|
56
|
+
logger_1.logger.dim(options.all
|
|
57
|
+
? 'The folder might be empty or does not exist.'
|
|
58
|
+
: 'No script files (.ts, .js) found. Use --all to see all files.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
logger_1.logger.header(`Files on ${tenant} (Files/)`);
|
|
62
|
+
// Group by directory
|
|
63
|
+
const grouped = {};
|
|
64
|
+
for (const file of files) {
|
|
65
|
+
const parts = file.path.split('/');
|
|
66
|
+
const fileName = parts.pop();
|
|
67
|
+
const dir = parts.length > 0 ? parts.join('/') + '/' : '';
|
|
68
|
+
if (!grouped[dir]) {
|
|
69
|
+
grouped[dir] = [];
|
|
70
|
+
}
|
|
71
|
+
grouped[dir].push(fileName);
|
|
72
|
+
}
|
|
73
|
+
// Sort directories
|
|
74
|
+
const dirs = Object.keys(grouped).sort();
|
|
75
|
+
for (const dir of dirs) {
|
|
76
|
+
if (dir) {
|
|
77
|
+
console.log(` ${dir}`);
|
|
78
|
+
}
|
|
79
|
+
const dirFiles = grouped[dir].sort();
|
|
80
|
+
for (const file of dirFiles) {
|
|
81
|
+
const prefix = dir ? ' ' : ' ';
|
|
82
|
+
console.log(`${prefix}${file}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
console.log();
|
|
86
|
+
logger_1.logger.dim(`Total: ${files.length} file(s)`);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.registerInstallCommand = registerInstallCommand;
|
|
37
|
+
const logger_1 = require("../utils/logger");
|
|
38
|
+
const helpers_1 = require("../utils/helpers");
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const child_process_1 = require("child_process");
|
|
41
|
+
function registerInstallCommand(program) {
|
|
42
|
+
program
|
|
43
|
+
.command('install [tenant]')
|
|
44
|
+
.description('Install npm dependencies for a tenant (runs npm install)')
|
|
45
|
+
.action(async (tenantArg) => {
|
|
46
|
+
const tenant = (0, helpers_1.resolveTenantOrExit)(tenantArg);
|
|
47
|
+
const tenantDir = (0, helpers_1.getTenantDir)(tenant);
|
|
48
|
+
if (!fs.existsSync(tenantDir)) {
|
|
49
|
+
logger_1.logger.error(`Tenant folder not found: farseer-apps/${tenant}/`);
|
|
50
|
+
logger_1.logger.dim('Run "farseer pull <tenant>" first to initialize the folder.');
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
const packageJsonPath = `${tenantDir}/package.json`;
|
|
54
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
55
|
+
logger_1.logger.error(`No package.json found in farseer-apps/${tenant}/`);
|
|
56
|
+
logger_1.logger.dim('Create a package.json first or run "npm init" in that folder.');
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
logger_1.logger.info(`Installing dependencies for ${tenant}...`);
|
|
60
|
+
logger_1.logger.dim(`Running: npm install in farseer-apps/${tenant}/`);
|
|
61
|
+
console.log();
|
|
62
|
+
const child = (0, child_process_1.spawn)('npm', ['install'], {
|
|
63
|
+
stdio: 'inherit',
|
|
64
|
+
cwd: tenantDir,
|
|
65
|
+
shell: true,
|
|
66
|
+
});
|
|
67
|
+
child.on('close', (code) => {
|
|
68
|
+
if (code === 0) {
|
|
69
|
+
console.log();
|
|
70
|
+
logger_1.logger.success('Dependencies installed successfully!');
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
logger_1.logger.error(`npm install exited with code ${code}`);
|
|
74
|
+
process.exit(code || 1);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
child.on('error', (err) => {
|
|
78
|
+
logger_1.logger.error(`Failed to run npm install: ${err.message}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|