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.
- package/dist/commands/app.js +344 -316
- package/dist/commands/apps.js +83 -103
- package/dist/commands/checkout.js +156 -134
- package/dist/commands/config.js +126 -124
- package/dist/commands/diff.js +194 -169
- package/dist/commands/dimensions.js +122 -137
- package/dist/commands/files.js +77 -88
- package/dist/commands/install.js +77 -74
- package/dist/commands/list.js +74 -89
- package/dist/commands/login.js +101 -126
- package/dist/commands/logout.js +42 -57
- package/dist/commands/mcp-server.js +24 -39
- package/dist/commands/model.js +176 -184
- package/dist/commands/pull.js +276 -248
- package/dist/commands/push.js +222 -200
- package/dist/commands/run.js +322 -274
- package/dist/commands/status.js +170 -147
- package/dist/commands/variables.js +192 -168
- package/dist/commands/whoami.js +45 -61
- package/dist/index.js +115 -117
- package/dist/mcp/index.js +17 -33
- package/dist/mcp/prompts/workflows.js +146 -191
- package/dist/mcp/resources/documentation.js +149 -158
- package/dist/mcp/server.js +34 -50
- package/dist/mcp/tools/appTools.js +278 -307
- package/dist/mcp/tools/authTools.js +123 -130
- package/dist/mcp/tools/dataTools.js +271 -275
- package/dist/mcp/tools/modelTools.js +233 -265
- package/dist/mcp/tools/runTools.js +205 -199
- package/dist/mcp/tools/syncTools.js +315 -341
- package/dist/mcp/utils/helpers.js +124 -117
- package/dist/services/appSyncService.js +438 -379
- package/dist/services/configService.js +144 -154
- package/dist/services/farseerApi.js +401 -401
- package/dist/services/farseerFactory.js +274 -208
- package/dist/services/farseerService.js +488 -455
- package/dist/services/syncService.js +732 -657
- package/dist/utils/constants.js +20 -45
- package/dist/utils/helpers.js +366 -333
- package/dist/utils/logger.js +43 -74
- package/package.json +8 -1
- package/dist/commands/app.js.map +0 -7
- package/dist/commands/apps.js.map +0 -7
- package/dist/commands/checkout.js.map +0 -7
- package/dist/commands/config.js.map +0 -7
- package/dist/commands/diff.js.map +0 -7
- package/dist/commands/dimensions.js.map +0 -7
- package/dist/commands/files.js.map +0 -7
- package/dist/commands/install.js.map +0 -7
- package/dist/commands/list.js.map +0 -7
- package/dist/commands/login.js.map +0 -7
- package/dist/commands/logout.js.map +0 -7
- package/dist/commands/mcp-server.js.map +0 -7
- package/dist/commands/model.js.map +0 -7
- package/dist/commands/pull.js.map +0 -7
- package/dist/commands/push.js.map +0 -7
- package/dist/commands/run.js.map +0 -7
- package/dist/commands/status.js.map +0 -7
- package/dist/commands/variables.js.map +0 -7
- package/dist/commands/whoami.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/mcp/index.js.map +0 -7
- package/dist/mcp/prompts/workflows.js.map +0 -7
- package/dist/mcp/resources/documentation.js.map +0 -7
- package/dist/mcp/server.js.map +0 -7
- package/dist/mcp/tools/appTools.js.map +0 -7
- package/dist/mcp/tools/authTools.js.map +0 -7
- package/dist/mcp/tools/dataTools.js.map +0 -7
- package/dist/mcp/tools/modelTools.js.map +0 -7
- package/dist/mcp/tools/runTools.js.map +0 -7
- package/dist/mcp/tools/syncTools.js.map +0 -7
- package/dist/mcp/utils/helpers.js.map +0 -7
- package/dist/services/appSyncService.js.map +0 -7
- package/dist/services/configService.js.map +0 -7
- package/dist/services/farseerApi.js.map +0 -7
- package/dist/services/farseerFactory.js.map +0 -7
- package/dist/services/farseerService.js.map +0 -7
- package/dist/services/syncService.js.map +0 -7
- package/dist/utils/constants.js.map +0 -7
- package/dist/utils/helpers.js.map +0 -7
- package/dist/utils/logger.js.map +0 -7
package/dist/utils/helpers.js
CHANGED
|
@@ -1,413 +1,446 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
|
|
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
|
-
|
|
74
|
+
return crypto.createHash('md5').update(content).digest('hex');
|
|
71
75
|
}
|
|
72
76
|
function getAppsDir() {
|
|
73
|
-
|
|
77
|
+
return path.join(process.cwd(), 'farseer-apps');
|
|
74
78
|
}
|
|
75
79
|
function getTenantDir(tenant) {
|
|
76
|
-
|
|
80
|
+
return path.join(getAppsDir(), tenant);
|
|
77
81
|
}
|
|
78
82
|
function getTenantFilesDir(tenant) {
|
|
79
|
-
|
|
83
|
+
return path.join(getTenantDir(tenant), 'files');
|
|
80
84
|
}
|
|
85
|
+
// Legacy - for backwards compatibility with run command
|
|
81
86
|
function getTenantSrcDir(tenant) {
|
|
82
|
-
|
|
87
|
+
return path.join(getTenantFilesDir(tenant), 'Scripts');
|
|
83
88
|
}
|
|
84
89
|
function getSyncFilePath(tenant) {
|
|
85
|
-
|
|
90
|
+
return path.join(getTenantDir(tenant), '.farseer-sync.json');
|
|
86
91
|
}
|
|
87
92
|
function getAuditLogPath(tenant) {
|
|
88
|
-
|
|
93
|
+
return path.join(getTenantDir(tenant), '.farseer-audit.log');
|
|
89
94
|
}
|
|
90
95
|
function getTenantAppsDir(tenant) {
|
|
91
|
-
|
|
96
|
+
return path.join(getTenantDir(tenant), 'apps');
|
|
92
97
|
}
|
|
93
98
|
function ensureDirectoryExists(dirPath) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
if (!fs.existsSync(dirPath)) {
|
|
100
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
101
|
+
}
|
|
97
102
|
}
|
|
98
103
|
function getRelativePath(fullPath, basePath) {
|
|
99
|
-
|
|
104
|
+
return path.relative(basePath, fullPath);
|
|
100
105
|
}
|
|
101
106
|
function getAllFiles(dirPath, basePath) {
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
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
|
-
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
137
|
-
|
|
144
|
+
const ext = path.extname(filename).toLowerCase();
|
|
145
|
+
return ['.ts', '.js', '.mjs', '.cjs'].includes(ext);
|
|
138
146
|
}
|
|
139
147
|
function isTextFile(filename) {
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
150
|
-
|
|
159
|
+
const d = typeof date === 'string' ? new Date(date) : date;
|
|
160
|
+
return d.toLocaleString();
|
|
151
161
|
}
|
|
152
162
|
function getCredentialsHint(tenant) {
|
|
153
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
|
168
|
-
}
|
|
169
|
-
return null;
|
|
186
|
+
return null;
|
|
170
187
|
}
|
|
171
188
|
function resolveTenant(tenantArg) {
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
243
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
284
|
-
|
|
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
|
-
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
/const farseerClient = new farseer\.FarseerClient\(\s*\);/g,
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
379
|
+
return INJECTED_CLIENT_PATTERN.test(code);
|
|
320
380
|
}
|
|
321
381
|
function hasEmptyFarseerClient(code) {
|
|
322
|
-
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
results
|
|
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
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
+
}
|