farseer-cli 1.0.10 → 1.1.0

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