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,413 +1,446 @@
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 });
10
- };
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 helpers_exports = {};
29
- __export(helpers_exports, {
30
- appendToAuditLog: () => appendToAuditLog,
31
- calculateHash: () => calculateHash,
32
- ensureDirectoryExists: () => ensureDirectoryExists,
33
- fetchWithConcurrency: () => fetchWithConcurrency,
34
- formatDate: () => formatDate,
35
- formatFileSize: () => formatFileSize,
36
- getAllFiles: () => getAllFiles,
37
- getAllFilesInDir: () => getAllFilesInDir,
38
- getAppsDir: () => getAppsDir,
39
- getAuditLogPath: () => getAuditLogPath,
40
- getCredentialsHint: () => getCredentialsHint,
41
- getRelativePath: () => getRelativePath,
42
- getSyncFilePath: () => getSyncFilePath,
43
- getTenantAppsDir: () => getTenantAppsDir,
44
- getTenantDir: () => getTenantDir,
45
- getTenantFilesDir: () => getTenantFilesDir,
46
- getTenantSrcDir: () => getTenantSrcDir,
47
- hasEmptyFarseerClient: () => hasEmptyFarseerClient,
48
- hasInjectedCredentials: () => hasInjectedCredentials,
49
- injectCredentials: () => injectCredentials,
50
- injectCredentialsInDir: () => injectCredentialsInDir,
51
- isKnownTenant: () => isKnownTenant,
52
- isScriptFile: () => isScriptFile,
53
- isTextFile: () => isTextFile,
54
- parseAppArgs: () => parseAppArgs,
55
- resolveOrgAndTenant: () => resolveOrgAndTenant,
56
- resolveOrgAndTenantOrExit: () => resolveOrgAndTenantOrExit,
57
- resolveTenant: () => resolveTenant,
58
- resolveTenantOrExit: () => resolveTenantOrExit,
59
- resolveTenantWithOrgMapping: () => resolveTenantWithOrgMapping,
60
- stripCredentials: () => stripCredentials,
61
- stripCredentialsInDir: () => stripCredentialsInDir
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;
62
17
  });
63
- module.exports = __toCommonJS(helpers_exports);
64
- var crypto = __toESM(require("crypto"));
65
- var path = __toESM(require("path"));
66
- var fs = __toESM(require("fs"));
67
- var import_configService = require("../services/configService");
68
- var import_logger = require("./logger");
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");
69
73
  function calculateHash(content) {
70
- return crypto.createHash("md5").update(content).digest("hex");
74
+ return crypto.createHash('md5').update(content).digest('hex');
71
75
  }
72
76
  function getAppsDir() {
73
- return path.join(process.cwd(), "farseer-apps");
77
+ return path.join(process.cwd(), 'farseer-apps');
74
78
  }
75
79
  function getTenantDir(tenant) {
76
- return path.join(getAppsDir(), tenant);
80
+ return path.join(getAppsDir(), tenant);
77
81
  }
78
82
  function getTenantFilesDir(tenant) {
79
- return path.join(getTenantDir(tenant), "files");
83
+ return path.join(getTenantDir(tenant), 'files');
80
84
  }
85
+ // Legacy - for backwards compatibility with run command
81
86
  function getTenantSrcDir(tenant) {
82
- return path.join(getTenantFilesDir(tenant), "Scripts");
87
+ return path.join(getTenantFilesDir(tenant), 'Scripts');
83
88
  }
84
89
  function getSyncFilePath(tenant) {
85
- return path.join(getTenantDir(tenant), ".farseer-sync.json");
90
+ return path.join(getTenantDir(tenant), '.farseer-sync.json');
86
91
  }
87
92
  function getAuditLogPath(tenant) {
88
- return path.join(getTenantDir(tenant), ".farseer-audit.log");
93
+ return path.join(getTenantDir(tenant), '.farseer-audit.log');
89
94
  }
90
95
  function getTenantAppsDir(tenant) {
91
- return path.join(getTenantDir(tenant), "apps");
96
+ return path.join(getTenantDir(tenant), 'apps');
92
97
  }
93
98
  function ensureDirectoryExists(dirPath) {
94
- if (!fs.existsSync(dirPath)) {
95
- fs.mkdirSync(dirPath, { recursive: true });
96
- }
99
+ if (!fs.existsSync(dirPath)) {
100
+ fs.mkdirSync(dirPath, { recursive: true });
101
+ }
97
102
  }
98
103
  function getRelativePath(fullPath, basePath) {
99
- return path.relative(basePath, fullPath);
104
+ return path.relative(basePath, fullPath);
100
105
  }
101
106
  function getAllFiles(dirPath, basePath) {
102
- if (!fs.existsSync(dirPath)) {
103
- return [];
104
- }
105
- const base = basePath || dirPath;
106
- const files = [];
107
- const items = fs.readdirSync(dirPath, { withFileTypes: true });
108
- for (const item of items) {
109
- const fullPath = path.join(dirPath, item.name);
110
- if (item.isDirectory()) {
111
- files.push(...getAllFiles(fullPath, base));
112
- } else if (item.isFile() && isScriptFile(item.name)) {
113
- files.push(getRelativePath(fullPath, base));
107
+ if (!fs.existsSync(dirPath)) {
108
+ return [];
114
109
  }
115
- }
116
- return files;
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;
117
123
  }
124
+ // Get all files in directory (not just scripts)
118
125
  function getAllFilesInDir(dirPath, basePath) {
119
- if (!fs.existsSync(dirPath)) {
120
- return [];
121
- }
122
- const base = basePath || dirPath;
123
- const files = [];
124
- const items = fs.readdirSync(dirPath, { withFileTypes: true });
125
- for (const item of items) {
126
- const fullPath = path.join(dirPath, item.name);
127
- if (item.isDirectory()) {
128
- files.push(...getAllFilesInDir(fullPath, base));
129
- } else if (item.isFile()) {
130
- files.push(getRelativePath(fullPath, base));
126
+ if (!fs.existsSync(dirPath)) {
127
+ return [];
131
128
  }
132
- }
133
- return files;
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;
134
142
  }
135
143
  function isScriptFile(filename) {
136
- const ext = path.extname(filename).toLowerCase();
137
- return [".ts", ".js", ".mjs", ".cjs"].includes(ext);
144
+ const ext = path.extname(filename).toLowerCase();
145
+ return ['.ts', '.js', '.mjs', '.cjs'].includes(ext);
138
146
  }
139
147
  function isTextFile(filename) {
140
- const ext = path.extname(filename).toLowerCase().slice(1);
141
- return ["ts", "js", "mjs", "cjs", "json", "txt", "md", "csv", "xml", "html", "css", "yaml", "yml"].includes(ext);
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);
142
150
  }
143
151
  function formatFileSize(bytes) {
144
- if (bytes < 1024) return `${bytes} B`;
145
- if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
146
- return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
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`;
147
157
  }
148
158
  function formatDate(date) {
149
- const d = typeof date === "string" ? new Date(date) : date;
150
- return d.toLocaleString();
159
+ const d = typeof date === 'string' ? new Date(date) : date;
160
+ return d.toLocaleString();
151
161
  }
152
162
  function getCredentialsHint(tenant) {
153
- return `Use: farseer login
163
+ return `Use: farseer login
154
164
  Or: farseer config set ${tenant} --api-key <key> --org <organisation>`;
155
165
  }
166
+ /**
167
+ * Resolve organisation and tenant from argument or checkout.
168
+ * When only tenant is provided, assumes organisation = tenant.
169
+ */
156
170
  function resolveOrgAndTenant(tenantArg) {
157
- if (tenantArg) {
158
- return { organisation: tenantArg, tenant: tenantArg };
159
- }
160
- const checkout = (0, import_configService.getCurrentCheckout)();
161
- if (checkout) {
162
- if (checkout.organisation === checkout.tenant) {
163
- import_logger.logger.dim(`Using checked-out tenant: ${checkout.tenant}`);
164
- } else {
165
- import_logger.logger.dim(`Using checked-out tenant: ${checkout.tenant} (org: ${checkout.organisation})`);
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;
166
185
  }
167
- return checkout;
168
- }
169
- return null;
186
+ return null;
170
187
  }
171
188
  function resolveTenant(tenantArg) {
172
- const resolved = resolveOrgAndTenant(tenantArg);
173
- return resolved?.tenant || null;
189
+ const resolved = resolveOrgAndTenant(tenantArg);
190
+ return resolved?.tenant || null;
174
191
  }
192
+ /**
193
+ * Resolve tenant or exit with error if not available.
194
+ */
175
195
  function resolveTenantOrExit(tenantArg) {
176
- const tenant = resolveTenant(tenantArg);
177
- if (!tenant) {
178
- import_logger.logger.error("No tenant specified.");
179
- import_logger.logger.dim("Either specify a tenant: farseer <command> <tenant>");
180
- import_logger.logger.dim("Or checkout a tenant: farseer checkout <tenant>");
181
- process.exit(1);
182
- }
183
- return tenant;
184
- }
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
+ */
185
217
  function resolveTenantWithOrgMapping(arg1, arg2) {
186
- if (arg1 && arg2) {
187
- const org = arg1;
188
- const tenant = arg2;
189
- (0, import_configService.saveTenantOrgMapping)(tenant, org);
190
- if (org === tenant) {
191
- import_logger.logger.dim(`Using tenant: ${tenant}`);
192
- } else {
193
- import_logger.logger.dim(`Using tenant: ${tenant} (org: ${org})`);
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 };
194
231
  }
195
- return { organisation: org, tenant };
196
- }
197
- if (arg1) {
198
- const tenant = arg1;
199
- const savedOrg = (0, import_configService.getTenantOrg)(tenant);
200
- if (savedOrg) {
201
- if (savedOrg === tenant) {
202
- import_logger.logger.dim(`Using tenant: ${tenant} (from saved mapping)`);
203
- } else {
204
- import_logger.logger.dim(`Using tenant: ${tenant} (org: ${savedOrg}, from saved mapping)`);
205
- }
206
- return { organisation: savedOrg, tenant };
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);
207
255
  }
208
- import_logger.logger.error(`Organisation unknown for tenant "${tenant}".`);
209
- import_logger.logger.dim("Please specify both organisation and tenant:");
210
- import_logger.logger.dim(` farseer <command> <organisation> <tenant>`);
211
- import_logger.logger.dim(` Example: farseer pull jgl tt-hotels-hr-dev`);
212
- import_logger.logger.dim("");
213
- import_logger.logger.dim("Or checkout the tenant first:");
214
- import_logger.logger.dim(` farseer checkout <organisation> <tenant>`);
215
- process.exit(1);
216
- }
217
- const checkout = (0, import_configService.getCurrentCheckout)();
218
- if (checkout) {
219
- if (checkout.organisation === checkout.tenant) {
220
- import_logger.logger.dim(`Using checked-out tenant: ${checkout.tenant}`);
221
- } else {
222
- import_logger.logger.dim(`Using checked-out tenant: ${checkout.tenant} (org: ${checkout.organisation})`);
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;
223
266
  }
224
- return checkout;
225
- }
226
- import_logger.logger.error("No tenant specified.");
227
- import_logger.logger.dim("Either specify organisation and tenant: farseer <command> <org> <tenant>");
228
- import_logger.logger.dim("Or checkout a tenant: farseer checkout <org> <tenant>");
229
- process.exit(1);
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);
230
272
  }
273
+ /**
274
+ * Resolve organisation and tenant or exit with error.
275
+ */
231
276
  function resolveOrgAndTenantOrExit(tenantArg) {
232
- const resolved = resolveOrgAndTenant(tenantArg);
233
- if (!resolved) {
234
- import_logger.logger.error("No tenant specified.");
235
- import_logger.logger.dim("Either specify a tenant: farseer <command> <tenant>");
236
- import_logger.logger.dim("Or checkout a tenant: farseer checkout <tenant>");
237
- process.exit(1);
238
- }
239
- return resolved;
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;
240
285
  }
286
+ /**
287
+ * Check if a string is a known tenant (has credentials configured).
288
+ */
241
289
  function isKnownTenant(name) {
242
- const { getCredential } = require("../services/configService");
243
- return !!getCredential(name);
244
- }
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
+ */
245
302
  function parseAppArgs(args) {
246
- if (args.length === 0) {
247
- import_logger.logger.error("App name is required.");
248
- process.exit(1);
249
- }
250
- if (args.length >= 2 && isKnownTenant(args[0])) {
251
- return {
252
- organisation: args[0],
253
- tenant: args[0],
254
- appName: args.slice(1).join(" ")
255
- };
256
- }
257
- const checkout = (0, import_configService.getCurrentCheckout)();
258
- if (checkout) {
259
- if (checkout.organisation === checkout.tenant) {
260
- import_logger.logger.dim(`Using checked-out tenant: ${checkout.tenant}`);
261
- } else {
262
- import_logger.logger.dim(`Using checked-out tenant: ${checkout.tenant} (org: ${checkout.organisation})`);
303
+ if (args.length === 0) {
304
+ logger_1.logger.error('App name is required.');
305
+ process.exit(1);
263
306
  }
264
- return {
265
- organisation: checkout.organisation,
266
- tenant: checkout.tenant,
267
- appName: args.join(" ")
268
- };
269
- }
270
- if (args.length >= 2) {
271
- return {
272
- organisation: args[0],
273
- tenant: args[0],
274
- appName: args.slice(1).join(" ")
275
- };
276
- }
277
- import_logger.logger.error("No tenant specified.");
278
- import_logger.logger.dim("Either specify a tenant: farseer app show <tenant> <app-name>");
279
- import_logger.logger.dim("Or checkout a tenant: farseer checkout <tenant>");
280
- process.exit(1);
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);
281
346
  }
347
+ // Pattern to match empty FarseerClient() constructor (no /g flag to avoid lastIndex issues)
282
348
  const EMPTY_CLIENT_PATTERNS = [
283
- /const farseerClient = new farseer\.FarseerClient\(\s*\);/,
284
- /const fClient = new farseer\.FarseerClient\(\s*\);/
349
+ /const farseerClient = new farseer\.FarseerClient\(\s*\);/,
350
+ /const fClient = new farseer\.FarseerClient\(\s*\);/,
285
351
  ];
352
+ // Pattern to match FarseerClient with injected credentials (multiline, no /g flag)
286
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]*?\}\);/;
287
354
  function injectCredentials(code, credential) {
288
- const clientConfig = `{
355
+ const clientConfig = `{
289
356
  basePath: '${credential.basePath}',
290
357
  headers: {
291
358
  'X-TENANT-ID': '${credential.tenantId}',
292
359
  'X-API-KEY': '${credential.apiKey}',
293
360
  }
294
361
  }`;
295
- let modified = code;
296
- modified = modified.replace(
297
- /const farseerClient = new farseer\.FarseerClient\(\s*\);/g,
298
- `const farseerClient = new farseer.FarseerClient(${clientConfig});`
299
- );
300
- modified = modified.replace(
301
- /const fClient = new farseer\.FarseerClient\(\s*\);/g,
302
- `const fClient = new farseer.FarseerClient(${clientConfig});`
303
- );
304
- return modified;
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;
305
368
  }
306
369
  function stripCredentials(code) {
307
- let modified = code;
308
- modified = modified.replace(
309
- /const farseerClient = new farseer\.FarseerClient\(\{[\s\S]*?basePath:[\s\S]*?headers:[\s\S]*?'X-TENANT-ID':[\s\S]*?'X-API-KEY':[\s\S]*?\}\);/g,
310
- "const farseerClient = new farseer.FarseerClient();"
311
- );
312
- modified = modified.replace(
313
- /const fClient = new farseer\.FarseerClient\(\{[\s\S]*?basePath:[\s\S]*?headers:[\s\S]*?'X-TENANT-ID':[\s\S]*?'X-API-KEY':[\s\S]*?\}\);/g,
314
- "const fClient = new farseer.FarseerClient();"
315
- );
316
- return modified;
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;
317
377
  }
318
378
  function hasInjectedCredentials(code) {
319
- return INJECTED_CLIENT_PATTERN.test(code);
379
+ return INJECTED_CLIENT_PATTERN.test(code);
320
380
  }
321
381
  function hasEmptyFarseerClient(code) {
322
- return EMPTY_CLIENT_PATTERNS.some((pattern) => pattern.test(code));
382
+ return EMPTY_CLIENT_PATTERNS.some((pattern) => pattern.test(code));
323
383
  }
384
+ // Process all script files in a directory
324
385
  function injectCredentialsInDir(srcDir, credential) {
325
- let count = 0;
326
- const files = getAllFiles(srcDir);
327
- for (const file of files) {
328
- const filePath = path.join(srcDir, file);
329
- const content = fs.readFileSync(filePath, "utf-8");
330
- const modified = injectCredentials(content, credential);
331
- if (modified !== content) {
332
- fs.writeFileSync(filePath, modified);
333
- count++;
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
+ }
334
396
  }
335
- }
336
- return count;
397
+ return count;
337
398
  }
338
399
  function stripCredentialsInDir(srcDir) {
339
- let count = 0;
340
- const files = getAllFiles(srcDir);
341
- for (const file of files) {
342
- const filePath = path.join(srcDir, file);
343
- const content = fs.readFileSync(filePath, "utf-8");
344
- const modified = stripCredentials(content);
345
- if (modified !== content) {
346
- fs.writeFileSync(filePath, modified);
347
- count++;
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
+ }
348
410
  }
349
- }
350
- return count;
351
- }
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
+ */
352
422
  async function fetchWithConcurrency(items, fetcher, concurrency = 15) {
353
- const results = [];
354
- for (let i = 0; i < items.length; i += concurrency) {
355
- const chunk = items.slice(i, i + concurrency);
356
- const chunkResults = await Promise.all(
357
- chunk.map((item, chunkIndex) => fetcher(item, i + chunkIndex))
358
- );
359
- results.push(...chunkResults);
360
- }
361
- return results;
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;
362
430
  }
363
431
  function appendToAuditLog(tenant, entries) {
364
- if (entries.length === 0) {
365
- return;
366
- }
367
- const logPath = getAuditLogPath(tenant);
368
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
369
- let logContent = "";
370
- for (const entry of entries) {
371
- const uploaderInfo = entry.uploaderName ? `${entry.uploaderName} (${entry.uploaderEmail})` : entry.uploaderEmail || "Unknown";
372
- const uploadedAt = entry.uploadTime ? new Date(entry.uploadTime).toLocaleString() : "Unknown";
373
- logContent += `${timestamp} | ${entry.operation} | ${entry.filePath} | Modified by: ${uploaderInfo} | Uploaded: ${uploadedAt}
374
- `;
375
- }
376
- fs.appendFileSync(logPath, logContent, "utf-8");
377
- }
378
- // Annotate the CommonJS export names for ESM import in node:
379
- 0 && (module.exports = {
380
- appendToAuditLog,
381
- calculateHash,
382
- ensureDirectoryExists,
383
- fetchWithConcurrency,
384
- formatDate,
385
- formatFileSize,
386
- getAllFiles,
387
- getAllFilesInDir,
388
- getAppsDir,
389
- getAuditLogPath,
390
- getCredentialsHint,
391
- getRelativePath,
392
- getSyncFilePath,
393
- getTenantAppsDir,
394
- getTenantDir,
395
- getTenantFilesDir,
396
- getTenantSrcDir,
397
- hasEmptyFarseerClient,
398
- hasInjectedCredentials,
399
- injectCredentials,
400
- injectCredentialsInDir,
401
- isKnownTenant,
402
- isScriptFile,
403
- isTextFile,
404
- parseAppArgs,
405
- resolveOrgAndTenant,
406
- resolveOrgAndTenantOrExit,
407
- resolveTenant,
408
- resolveTenantOrExit,
409
- resolveTenantWithOrgMapping,
410
- stripCredentials,
411
- stripCredentialsInDir
412
- });
413
- //# sourceMappingURL=helpers.js.map
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
+ }