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.
Files changed (41) hide show
  1. package/dist/commands/app.js +377 -0
  2. package/dist/commands/apps.js +91 -0
  3. package/dist/commands/checkout.js +164 -0
  4. package/dist/commands/config.js +141 -0
  5. package/dist/commands/diff.js +210 -0
  6. package/dist/commands/dimensions.js +130 -0
  7. package/dist/commands/files.js +88 -0
  8. package/dist/commands/install.js +82 -0
  9. package/dist/commands/list.js +77 -0
  10. package/dist/commands/login.js +109 -0
  11. package/dist/commands/logout.js +44 -0
  12. package/dist/commands/mcp-server.js +26 -0
  13. package/dist/commands/model.js +181 -0
  14. package/dist/commands/pull.js +286 -0
  15. package/dist/commands/push.js +235 -0
  16. package/dist/commands/run.js +336 -0
  17. package/dist/commands/status.js +178 -0
  18. package/dist/commands/variables.js +200 -0
  19. package/dist/commands/whoami.js +47 -0
  20. package/dist/index.js +163 -0
  21. package/dist/mcp/index.js +19 -0
  22. package/dist/mcp/prompts/workflows.js +403 -0
  23. package/dist/mcp/resources/documentation.js +158 -0
  24. package/dist/mcp/server.js +36 -0
  25. package/dist/mcp/tools/appTools.js +348 -0
  26. package/dist/mcp/tools/authTools.js +152 -0
  27. package/dist/mcp/tools/dataTools.js +358 -0
  28. package/dist/mcp/tools/modelTools.js +293 -0
  29. package/dist/mcp/tools/runTools.js +239 -0
  30. package/dist/mcp/tools/syncTools.js +383 -0
  31. package/dist/mcp/utils/helpers.js +142 -0
  32. package/dist/services/appSyncService.js +458 -0
  33. package/dist/services/configService.js +186 -0
  34. package/dist/services/farseerApi.js +426 -0
  35. package/dist/services/farseerFactory.js +297 -0
  36. package/dist/services/farseerService.js +647 -0
  37. package/dist/services/syncService.js +764 -0
  38. package/dist/utils/constants.js +21 -0
  39. package/dist/utils/helpers.js +446 -0
  40. package/dist/utils/logger.js +45 -0
  41. package/package.json +8 -1
@@ -0,0 +1,21 @@
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.SCRIPT_EXTENSIONS = exports.SCRIPTS_FOLDER_PATH = exports.KEYCLOAK_CLIENT_ID = exports.KEYCLOAK_TOKEN_URL = exports.FARSEER_CLIENT_AXIOS_URL = exports.FARSEER_CLIENT_URL = exports.CLI_VERSION = void 0;
7
+ // CLI version - read dynamically from package.json
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, '../../package.json'), 'utf-8'));
11
+ exports.CLI_VERSION = packageJson.version;
12
+ // Farseer client package URLs - update these when new versions are released
13
+ exports.FARSEER_CLIENT_URL = 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client/release-1.4.5.tar';
14
+ exports.FARSEER_CLIENT_AXIOS_URL = 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client-axios/6898c0cb-5dca-4b2f-b325-119efc7f099e/v1.0.1.tar';
15
+ // Keycloak auth configuration
16
+ exports.KEYCLOAK_TOKEN_URL = 'https://login.farseer.io/auth/realms/master/protocol/openid-connect/token';
17
+ exports.KEYCLOAK_CLIENT_ID = 'security-admin-console';
18
+ // Default paths
19
+ exports.SCRIPTS_FOLDER_PATH = ['Files', 'Scripts'];
20
+ // Supported script file extensions
21
+ exports.SCRIPT_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs'];
@@ -0,0 +1,446 @@
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.calculateHash = calculateHash;
37
+ exports.getAppsDir = getAppsDir;
38
+ exports.getTenantDir = getTenantDir;
39
+ exports.getTenantFilesDir = getTenantFilesDir;
40
+ exports.getTenantSrcDir = getTenantSrcDir;
41
+ exports.getSyncFilePath = getSyncFilePath;
42
+ exports.getAuditLogPath = getAuditLogPath;
43
+ exports.getTenantAppsDir = getTenantAppsDir;
44
+ exports.ensureDirectoryExists = ensureDirectoryExists;
45
+ exports.getRelativePath = getRelativePath;
46
+ exports.getAllFiles = getAllFiles;
47
+ exports.getAllFilesInDir = getAllFilesInDir;
48
+ exports.isScriptFile = isScriptFile;
49
+ exports.isTextFile = isTextFile;
50
+ exports.formatFileSize = formatFileSize;
51
+ exports.formatDate = formatDate;
52
+ exports.getCredentialsHint = getCredentialsHint;
53
+ exports.resolveOrgAndTenant = resolveOrgAndTenant;
54
+ exports.resolveTenant = resolveTenant;
55
+ exports.resolveTenantOrExit = resolveTenantOrExit;
56
+ exports.resolveTenantWithOrgMapping = resolveTenantWithOrgMapping;
57
+ exports.resolveOrgAndTenantOrExit = resolveOrgAndTenantOrExit;
58
+ exports.isKnownTenant = isKnownTenant;
59
+ exports.parseAppArgs = parseAppArgs;
60
+ exports.injectCredentials = injectCredentials;
61
+ exports.stripCredentials = stripCredentials;
62
+ exports.hasInjectedCredentials = hasInjectedCredentials;
63
+ exports.hasEmptyFarseerClient = hasEmptyFarseerClient;
64
+ exports.injectCredentialsInDir = injectCredentialsInDir;
65
+ exports.stripCredentialsInDir = stripCredentialsInDir;
66
+ exports.fetchWithConcurrency = fetchWithConcurrency;
67
+ exports.appendToAuditLog = appendToAuditLog;
68
+ const crypto = __importStar(require("crypto"));
69
+ const path = __importStar(require("path"));
70
+ const fs = __importStar(require("fs"));
71
+ const configService_1 = require("../services/configService");
72
+ const logger_1 = require("./logger");
73
+ function calculateHash(content) {
74
+ return crypto.createHash('md5').update(content).digest('hex');
75
+ }
76
+ function getAppsDir() {
77
+ return path.join(process.cwd(), 'farseer-apps');
78
+ }
79
+ function getTenantDir(tenant) {
80
+ return path.join(getAppsDir(), tenant);
81
+ }
82
+ function getTenantFilesDir(tenant) {
83
+ return path.join(getTenantDir(tenant), 'files');
84
+ }
85
+ // Legacy - for backwards compatibility with run command
86
+ function getTenantSrcDir(tenant) {
87
+ return path.join(getTenantFilesDir(tenant), 'Scripts');
88
+ }
89
+ function getSyncFilePath(tenant) {
90
+ return path.join(getTenantDir(tenant), '.farseer-sync.json');
91
+ }
92
+ function getAuditLogPath(tenant) {
93
+ return path.join(getTenantDir(tenant), '.farseer-audit.log');
94
+ }
95
+ function getTenantAppsDir(tenant) {
96
+ return path.join(getTenantDir(tenant), 'apps');
97
+ }
98
+ function ensureDirectoryExists(dirPath) {
99
+ if (!fs.existsSync(dirPath)) {
100
+ fs.mkdirSync(dirPath, { recursive: true });
101
+ }
102
+ }
103
+ function getRelativePath(fullPath, basePath) {
104
+ return path.relative(basePath, fullPath);
105
+ }
106
+ function getAllFiles(dirPath, basePath) {
107
+ if (!fs.existsSync(dirPath)) {
108
+ return [];
109
+ }
110
+ const base = basePath || dirPath;
111
+ const files = [];
112
+ const items = fs.readdirSync(dirPath, { withFileTypes: true });
113
+ for (const item of items) {
114
+ const fullPath = path.join(dirPath, item.name);
115
+ if (item.isDirectory()) {
116
+ files.push(...getAllFiles(fullPath, base));
117
+ }
118
+ else if (item.isFile() && isScriptFile(item.name)) {
119
+ files.push(getRelativePath(fullPath, base));
120
+ }
121
+ }
122
+ return files;
123
+ }
124
+ // Get all files in directory (not just scripts)
125
+ function getAllFilesInDir(dirPath, basePath) {
126
+ if (!fs.existsSync(dirPath)) {
127
+ return [];
128
+ }
129
+ const base = basePath || dirPath;
130
+ const files = [];
131
+ const items = fs.readdirSync(dirPath, { withFileTypes: true });
132
+ for (const item of items) {
133
+ const fullPath = path.join(dirPath, item.name);
134
+ if (item.isDirectory()) {
135
+ files.push(...getAllFilesInDir(fullPath, base));
136
+ }
137
+ else if (item.isFile()) {
138
+ files.push(getRelativePath(fullPath, base));
139
+ }
140
+ }
141
+ return files;
142
+ }
143
+ function isScriptFile(filename) {
144
+ const ext = path.extname(filename).toLowerCase();
145
+ return ['.ts', '.js', '.mjs', '.cjs'].includes(ext);
146
+ }
147
+ function isTextFile(filename) {
148
+ const ext = path.extname(filename).toLowerCase().slice(1); // remove leading dot
149
+ return ['ts', 'js', 'mjs', 'cjs', 'json', 'txt', 'md', 'csv', 'xml', 'html', 'css', 'yaml', 'yml'].includes(ext);
150
+ }
151
+ function formatFileSize(bytes) {
152
+ if (bytes < 1024)
153
+ return `${bytes} B`;
154
+ if (bytes < 1024 * 1024)
155
+ return `${(bytes / 1024).toFixed(1)} KB`;
156
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
157
+ }
158
+ function formatDate(date) {
159
+ const d = typeof date === 'string' ? new Date(date) : date;
160
+ return d.toLocaleString();
161
+ }
162
+ function getCredentialsHint(tenant) {
163
+ return `Use: farseer login
164
+ Or: farseer config set ${tenant} --api-key <key> --org <organisation>`;
165
+ }
166
+ /**
167
+ * Resolve organisation and tenant from argument or checkout.
168
+ * When only tenant is provided, assumes organisation = tenant.
169
+ */
170
+ function resolveOrgAndTenant(tenantArg) {
171
+ if (tenantArg) {
172
+ // When tenant is specified as arg, assume org = tenant
173
+ // (User can use checkout for different org/tenant)
174
+ return { organisation: tenantArg, tenant: tenantArg };
175
+ }
176
+ const checkout = (0, configService_1.getCurrentCheckout)();
177
+ if (checkout) {
178
+ if (checkout.organisation === checkout.tenant) {
179
+ logger_1.logger.dim(`Using checked-out tenant: ${checkout.tenant}`);
180
+ }
181
+ else {
182
+ logger_1.logger.dim(`Using checked-out tenant: ${checkout.tenant} (org: ${checkout.organisation})`);
183
+ }
184
+ return checkout;
185
+ }
186
+ return null;
187
+ }
188
+ function resolveTenant(tenantArg) {
189
+ const resolved = resolveOrgAndTenant(tenantArg);
190
+ return resolved?.tenant || null;
191
+ }
192
+ /**
193
+ * Resolve tenant or exit with error if not available.
194
+ */
195
+ function resolveTenantOrExit(tenantArg) {
196
+ const tenant = resolveTenant(tenantArg);
197
+ if (!tenant) {
198
+ logger_1.logger.error('No tenant specified.');
199
+ logger_1.logger.dim('Either specify a tenant: farseer <command> <tenant>');
200
+ logger_1.logger.dim('Or checkout a tenant: farseer checkout <tenant>');
201
+ process.exit(1);
202
+ }
203
+ return tenant;
204
+ }
205
+ /**
206
+ * Resolve organisation and tenant with support for org-tenant mapping.
207
+ *
208
+ * Usage patterns:
209
+ * - <org> <tenant>: Explicit org and tenant, saves mapping for future use
210
+ * - <tenant>: Look up org from saved mapping or use checkout
211
+ * - (no args): Use current checkout
212
+ *
213
+ * @param arg1 - Organisation (if 2 args) or tenant (if 1 arg)
214
+ * @param arg2 - Tenant (if 2 args)
215
+ * @returns ResolvedCheckout or exits with error
216
+ */
217
+ function resolveTenantWithOrgMapping(arg1, arg2) {
218
+ // Case 1: Two arguments - <org> <tenant>
219
+ if (arg1 && arg2) {
220
+ const org = arg1;
221
+ const tenant = arg2;
222
+ // Save mapping for future use
223
+ (0, configService_1.saveTenantOrgMapping)(tenant, org);
224
+ if (org === tenant) {
225
+ logger_1.logger.dim(`Using tenant: ${tenant}`);
226
+ }
227
+ else {
228
+ logger_1.logger.dim(`Using tenant: ${tenant} (org: ${org})`);
229
+ }
230
+ return { organisation: org, tenant };
231
+ }
232
+ // Case 2: One argument - <tenant>
233
+ if (arg1) {
234
+ const tenant = arg1;
235
+ // Try to get org from saved mapping
236
+ const savedOrg = (0, configService_1.getTenantOrg)(tenant);
237
+ if (savedOrg) {
238
+ if (savedOrg === tenant) {
239
+ logger_1.logger.dim(`Using tenant: ${tenant} (from saved mapping)`);
240
+ }
241
+ else {
242
+ logger_1.logger.dim(`Using tenant: ${tenant} (org: ${savedOrg}, from saved mapping)`);
243
+ }
244
+ return { organisation: savedOrg, tenant };
245
+ }
246
+ // No saved mapping - show error with helpful message
247
+ logger_1.logger.error(`Organisation unknown for tenant "${tenant}".`);
248
+ logger_1.logger.dim('Please specify both organisation and tenant:');
249
+ logger_1.logger.dim(` farseer <command> <organisation> <tenant>`);
250
+ logger_1.logger.dim(` Example: farseer pull jgl tt-hotels-hr-dev`);
251
+ logger_1.logger.dim('');
252
+ logger_1.logger.dim('Or checkout the tenant first:');
253
+ logger_1.logger.dim(` farseer checkout <organisation> <tenant>`);
254
+ process.exit(1);
255
+ }
256
+ // Case 3: No arguments - use current checkout
257
+ const checkout = (0, configService_1.getCurrentCheckout)();
258
+ if (checkout) {
259
+ if (checkout.organisation === checkout.tenant) {
260
+ logger_1.logger.dim(`Using checked-out tenant: ${checkout.tenant}`);
261
+ }
262
+ else {
263
+ logger_1.logger.dim(`Using checked-out tenant: ${checkout.tenant} (org: ${checkout.organisation})`);
264
+ }
265
+ return checkout;
266
+ }
267
+ // No checkout either
268
+ logger_1.logger.error('No tenant specified.');
269
+ logger_1.logger.dim('Either specify organisation and tenant: farseer <command> <org> <tenant>');
270
+ logger_1.logger.dim('Or checkout a tenant: farseer checkout <org> <tenant>');
271
+ process.exit(1);
272
+ }
273
+ /**
274
+ * Resolve organisation and tenant or exit with error.
275
+ */
276
+ function resolveOrgAndTenantOrExit(tenantArg) {
277
+ const resolved = resolveOrgAndTenant(tenantArg);
278
+ if (!resolved) {
279
+ logger_1.logger.error('No tenant specified.');
280
+ logger_1.logger.dim('Either specify a tenant: farseer <command> <tenant>');
281
+ logger_1.logger.dim('Or checkout a tenant: farseer checkout <tenant>');
282
+ process.exit(1);
283
+ }
284
+ return resolved;
285
+ }
286
+ /**
287
+ * Check if a string is a known tenant (has credentials configured).
288
+ */
289
+ function isKnownTenant(name) {
290
+ // Import here to avoid circular dependency
291
+ const { getCredential } = require('../services/configService');
292
+ return !!getCredential(name);
293
+ }
294
+ /**
295
+ * Parse variadic arguments to extract tenant and app name.
296
+ * If first arg is a known tenant, use it as tenant and rest as app name.
297
+ * Otherwise, use checked-out tenant and all args as app name.
298
+ *
299
+ * @param args Array of arguments (from variadic command)
300
+ * @returns { organisation: string, tenant: string, appName: string }
301
+ */
302
+ function parseAppArgs(args) {
303
+ if (args.length === 0) {
304
+ logger_1.logger.error('App name is required.');
305
+ process.exit(1);
306
+ }
307
+ // Check if first argument is a known tenant
308
+ if (args.length >= 2 && isKnownTenant(args[0])) {
309
+ // First arg is tenant, rest is app name
310
+ // Assume organisation = tenant when specified via command line
311
+ return {
312
+ organisation: args[0],
313
+ tenant: args[0],
314
+ appName: args.slice(1).join(' '),
315
+ };
316
+ }
317
+ // Use checked-out tenant, all args are app name
318
+ const checkout = (0, configService_1.getCurrentCheckout)();
319
+ if (checkout) {
320
+ if (checkout.organisation === checkout.tenant) {
321
+ logger_1.logger.dim(`Using checked-out tenant: ${checkout.tenant}`);
322
+ }
323
+ else {
324
+ logger_1.logger.dim(`Using checked-out tenant: ${checkout.tenant} (org: ${checkout.organisation})`);
325
+ }
326
+ return {
327
+ organisation: checkout.organisation,
328
+ tenant: checkout.tenant,
329
+ appName: args.join(' '),
330
+ };
331
+ }
332
+ // No checked-out tenant and first arg isn't a known tenant
333
+ // Assume first arg is tenant (will fail later if invalid)
334
+ if (args.length >= 2) {
335
+ return {
336
+ organisation: args[0],
337
+ tenant: args[0],
338
+ appName: args.slice(1).join(' '),
339
+ };
340
+ }
341
+ // Only one arg and no checkout - could be tenant or app name
342
+ logger_1.logger.error('No tenant specified.');
343
+ logger_1.logger.dim('Either specify a tenant: farseer app show <tenant> <app-name>');
344
+ logger_1.logger.dim('Or checkout a tenant: farseer checkout <tenant>');
345
+ process.exit(1);
346
+ }
347
+ // Pattern to match empty FarseerClient() constructor (no /g flag to avoid lastIndex issues)
348
+ const EMPTY_CLIENT_PATTERNS = [
349
+ /const farseerClient = new farseer\.FarseerClient\(\s*\);/,
350
+ /const fClient = new farseer\.FarseerClient\(\s*\);/,
351
+ ];
352
+ // Pattern to match FarseerClient with injected credentials (multiline, no /g flag)
353
+ const INJECTED_CLIENT_PATTERN = /const (farseerClient|fClient) = new farseer\.FarseerClient\(\{[\s\S]*?basePath:[\s\S]*?headers:[\s\S]*?'X-TENANT-ID':[\s\S]*?'X-API-KEY':[\s\S]*?\}\);/;
354
+ function injectCredentials(code, credential) {
355
+ const clientConfig = `{
356
+ basePath: '${credential.basePath}',
357
+ headers: {
358
+ 'X-TENANT-ID': '${credential.tenantId}',
359
+ 'X-API-KEY': '${credential.apiKey}',
360
+ }
361
+ }`;
362
+ let modified = code;
363
+ // Pattern 1: const farseerClient = new farseer.FarseerClient();
364
+ modified = modified.replace(/const farseerClient = new farseer\.FarseerClient\(\s*\);/g, `const farseerClient = new farseer.FarseerClient(${clientConfig});`);
365
+ // Pattern 2: const fClient = new farseer.FarseerClient();
366
+ modified = modified.replace(/const fClient = new farseer\.FarseerClient\(\s*\);/g, `const fClient = new farseer.FarseerClient(${clientConfig});`);
367
+ return modified;
368
+ }
369
+ function stripCredentials(code) {
370
+ // Replace injected credentials back to empty constructor
371
+ let modified = code;
372
+ // Match farseerClient with credentials
373
+ modified = modified.replace(/const farseerClient = new farseer\.FarseerClient\(\{[\s\S]*?basePath:[\s\S]*?headers:[\s\S]*?'X-TENANT-ID':[\s\S]*?'X-API-KEY':[\s\S]*?\}\);/g, 'const farseerClient = new farseer.FarseerClient();');
374
+ // Match fClient with credentials
375
+ modified = modified.replace(/const fClient = new farseer\.FarseerClient\(\{[\s\S]*?basePath:[\s\S]*?headers:[\s\S]*?'X-TENANT-ID':[\s\S]*?'X-API-KEY':[\s\S]*?\}\);/g, 'const fClient = new farseer.FarseerClient();');
376
+ return modified;
377
+ }
378
+ function hasInjectedCredentials(code) {
379
+ return INJECTED_CLIENT_PATTERN.test(code);
380
+ }
381
+ function hasEmptyFarseerClient(code) {
382
+ return EMPTY_CLIENT_PATTERNS.some((pattern) => pattern.test(code));
383
+ }
384
+ // Process all script files in a directory
385
+ function injectCredentialsInDir(srcDir, credential) {
386
+ let count = 0;
387
+ const files = getAllFiles(srcDir);
388
+ for (const file of files) {
389
+ const filePath = path.join(srcDir, file);
390
+ const content = fs.readFileSync(filePath, 'utf-8');
391
+ const modified = injectCredentials(content, credential);
392
+ if (modified !== content) {
393
+ fs.writeFileSync(filePath, modified);
394
+ count++;
395
+ }
396
+ }
397
+ return count;
398
+ }
399
+ function stripCredentialsInDir(srcDir) {
400
+ let count = 0;
401
+ const files = getAllFiles(srcDir);
402
+ for (const file of files) {
403
+ const filePath = path.join(srcDir, file);
404
+ const content = fs.readFileSync(filePath, 'utf-8');
405
+ const modified = stripCredentials(content);
406
+ if (modified !== content) {
407
+ fs.writeFileSync(filePath, modified);
408
+ count++;
409
+ }
410
+ }
411
+ return count;
412
+ }
413
+ /**
414
+ * Execute async operations with limited concurrency.
415
+ * Processes items in chunks to avoid overwhelming the API.
416
+ *
417
+ * @param items Array of items to process
418
+ * @param fetcher Async function to call for each item
419
+ * @param concurrency Maximum number of concurrent requests (default: 15)
420
+ * @returns Array of results in the same order as input items
421
+ */
422
+ async function fetchWithConcurrency(items, fetcher, concurrency = 15) {
423
+ const results = [];
424
+ for (let i = 0; i < items.length; i += concurrency) {
425
+ const chunk = items.slice(i, i + concurrency);
426
+ const chunkResults = await Promise.all(chunk.map((item, chunkIndex) => fetcher(item, i + chunkIndex)));
427
+ results.push(...chunkResults);
428
+ }
429
+ return results;
430
+ }
431
+ function appendToAuditLog(tenant, entries) {
432
+ if (entries.length === 0) {
433
+ return;
434
+ }
435
+ const logPath = getAuditLogPath(tenant);
436
+ const timestamp = new Date().toISOString();
437
+ let logContent = '';
438
+ for (const entry of entries) {
439
+ const uploaderInfo = entry.uploaderName
440
+ ? `${entry.uploaderName} (${entry.uploaderEmail})`
441
+ : entry.uploaderEmail || 'Unknown';
442
+ const uploadedAt = entry.uploadTime ? new Date(entry.uploadTime).toLocaleString() : 'Unknown';
443
+ logContent += `${timestamp} | ${entry.operation} | ${entry.filePath} | Modified by: ${uploaderInfo} | Uploaded: ${uploadedAt}\n`;
444
+ }
445
+ fs.appendFileSync(logPath, logContent, 'utf-8');
446
+ }
@@ -0,0 +1,45 @@
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.logger = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ exports.logger = {
9
+ info: (message) => {
10
+ console.log(chalk_1.default.blue('ℹ'), message);
11
+ },
12
+ success: (message) => {
13
+ console.log(chalk_1.default.green('✓'), message);
14
+ },
15
+ warning: (message) => {
16
+ console.log(chalk_1.default.yellow('⚠'), message);
17
+ },
18
+ error: (message) => {
19
+ console.log(chalk_1.default.red('✗'), message);
20
+ },
21
+ log: (message) => {
22
+ console.log(message);
23
+ },
24
+ dim: (message) => {
25
+ console.log(chalk_1.default.dim(message));
26
+ },
27
+ header: (message) => {
28
+ console.log();
29
+ console.log(chalk_1.default.bold.underline(message));
30
+ console.log();
31
+ },
32
+ list: (items, indent = 2) => {
33
+ const prefix = ' '.repeat(indent);
34
+ items.forEach((item) => {
35
+ console.log(`${prefix}${item}`);
36
+ });
37
+ },
38
+ table: (rows) => {
39
+ const maxLabelLength = Math.max(...rows.map((r) => r.label.length));
40
+ rows.forEach((row) => {
41
+ const paddedLabel = row.label.padEnd(maxLabelLength);
42
+ console.log(` ${chalk_1.default.dim(paddedLabel)} ${row.value}`);
43
+ });
44
+ },
45
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "farseer-cli",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "CLI tool for syncing Farseer App scripts between local folder and Farseer instances",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -16,6 +16,9 @@
16
16
  "build": "node build.js",
17
17
  "typecheck": "tsc --noEmit",
18
18
  "build:tsc": "tsc",
19
+ "lint": "eslint src --ext .ts",
20
+ "format:check": "prettier --check src",
21
+ "format": "prettier --write src",
19
22
  "dev": "ts-node src/index.ts",
20
23
  "start": "node dist/index.js"
21
24
  },
@@ -55,7 +58,11 @@
55
58
  "@types/diff": "^5.0.8",
56
59
  "@types/inquirer": "^9.0.7",
57
60
  "@types/node": "^20.10.0",
61
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
62
+ "@typescript-eslint/parser": "^8.0.0",
58
63
  "esbuild": "^0.27.2",
64
+ "eslint": "^8.57.0",
65
+ "prettier": "^3.3.0",
59
66
  "ts-node": "^10.9.2",
60
67
  "typescript": "^5.3.2"
61
68
  }