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.
- package/README.md +19 -0
- package/dist/commands/app.js +348 -344
- package/dist/commands/app.js.map +7 -0
- package/dist/commands/apps.js +110 -82
- package/dist/commands/apps.js.map +7 -0
- package/dist/commands/cells.js +161 -0
- package/dist/commands/cells.js.map +7 -0
- package/dist/commands/checkout.js +140 -155
- package/dist/commands/checkout.js.map +7 -0
- package/dist/commands/config.js +128 -126
- package/dist/commands/config.js.map +7 -0
- package/dist/commands/dashboards.js +130 -0
- package/dist/commands/dashboards.js.map +7 -0
- package/dist/commands/diff.js +171 -193
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/dimensions.js +222 -119
- package/dist/commands/dimensions.js.map +7 -0
- package/dist/commands/files.js +96 -77
- package/dist/commands/files.js.map +7 -0
- package/dist/commands/formula.js +116 -0
- package/dist/commands/formula.js.map +7 -0
- package/dist/commands/install.js +74 -76
- package/dist/commands/install.js.map +7 -0
- package/dist/commands/list.js +91 -73
- package/dist/commands/list.js.map +7 -0
- package/dist/commands/login.js +137 -98
- package/dist/commands/login.js.map +7 -0
- package/dist/commands/logout.js +59 -41
- package/dist/commands/logout.js.map +7 -0
- package/dist/commands/mcp-server.js +36 -23
- package/dist/commands/mcp-server.js.map +7 -0
- package/dist/commands/model.js +186 -175
- package/dist/commands/model.js.map +7 -0
- package/dist/commands/pull.js +264 -274
- package/dist/commands/pull.js.map +7 -0
- package/dist/commands/push.js +209 -221
- package/dist/commands/push.js.map +7 -0
- package/dist/commands/run.js +276 -321
- package/dist/commands/run.js.map +7 -0
- package/dist/commands/sheets.js +200 -0
- package/dist/commands/sheets.js.map +7 -0
- package/dist/commands/status.js +149 -169
- package/dist/commands/status.js.map +7 -0
- package/dist/commands/variables.js +247 -188
- package/dist/commands/variables.js.map +7 -0
- package/dist/commands/whoami.js +65 -44
- package/dist/commands/whoami.js.map +7 -0
- package/dist/index.js +179 -115
- package/dist/index.js.map +7 -0
- package/dist/mcp/index.js +33 -16
- package/dist/mcp/index.js.map +7 -0
- package/dist/mcp/prompts/workflows.js +191 -145
- package/dist/mcp/prompts/workflows.js.map +7 -0
- package/dist/mcp/resources/documentation.js +158 -148
- package/dist/mcp/resources/documentation.js.map +7 -0
- package/dist/mcp/server.js +56 -33
- package/dist/mcp/server.js.map +7 -0
- package/dist/mcp/tools/appTools.js +309 -277
- package/dist/mcp/tools/appTools.js.map +7 -0
- package/dist/mcp/tools/authTools.js +130 -121
- package/dist/mcp/tools/authTools.js.map +7 -0
- package/dist/mcp/tools/cellTools.js +148 -0
- package/dist/mcp/tools/cellTools.js.map +7 -0
- package/dist/mcp/tools/dashboardTools.js +133 -0
- package/dist/mcp/tools/dashboardTools.js.map +7 -0
- package/dist/mcp/tools/dataTools.js +270 -267
- package/dist/mcp/tools/dataTools.js.map +7 -0
- package/dist/mcp/tools/modelTools.js +575 -229
- package/dist/mcp/tools/modelTools.js.map +7 -0
- package/dist/mcp/tools/runTools.js +201 -203
- package/dist/mcp/tools/runTools.js.map +7 -0
- package/dist/mcp/tools/sheetTools.js +240 -0
- package/dist/mcp/tools/sheetTools.js.map +7 -0
- package/dist/mcp/tools/syncTools.js +335 -314
- package/dist/mcp/tools/syncTools.js.map +7 -0
- package/dist/mcp/utils/helpers.js +117 -123
- package/dist/mcp/utils/helpers.js.map +7 -0
- package/dist/services/appSyncService.js +381 -437
- package/dist/services/appSyncService.js.map +7 -0
- package/dist/services/configService.js +154 -143
- package/dist/services/configService.js.map +7 -0
- package/dist/services/farseerApi.js +405 -400
- package/dist/services/farseerApi.js.map +7 -0
- package/dist/services/farseerFactory.js +208 -273
- package/dist/services/farseerFactory.js.map +7 -0
- package/dist/services/farseerService.js +453 -487
- package/dist/services/farseerService.js.map +7 -0
- package/dist/services/syncService.js +661 -731
- package/dist/services/syncService.js.map +7 -0
- package/dist/utils/constants.js +52 -19
- package/dist/utils/constants.js.map +7 -0
- package/dist/utils/entityResolver.js +78 -0
- package/dist/utils/entityResolver.js.map +7 -0
- package/dist/utils/helpers.js +331 -365
- package/dist/utils/helpers.js.map +7 -0
- package/dist/utils/logger.js +74 -42
- package/dist/utils/logger.js.map +7 -0
- package/package.json +3 -2
package/dist/utils/helpers.js
CHANGED
|
@@ -1,446 +1,412 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
71
|
+
return crypto.createHash("md5").update(content).digest("hex");
|
|
75
72
|
}
|
|
76
73
|
function getAppsDir() {
|
|
77
|
-
|
|
74
|
+
return path.join(process.cwd(), "farseer-apps");
|
|
78
75
|
}
|
|
79
76
|
function getTenantDir(tenant) {
|
|
80
|
-
|
|
77
|
+
return path.join(getAppsDir(), tenant);
|
|
81
78
|
}
|
|
82
79
|
function getTenantFilesDir(tenant) {
|
|
83
|
-
|
|
80
|
+
return path.join(getTenantDir(tenant), "files");
|
|
84
81
|
}
|
|
85
|
-
// Legacy - for backwards compatibility with run command
|
|
86
82
|
function getTenantSrcDir(tenant) {
|
|
87
|
-
|
|
83
|
+
return path.join(getTenantFilesDir(tenant), "Scripts");
|
|
88
84
|
}
|
|
89
85
|
function getSyncFilePath(tenant) {
|
|
90
|
-
|
|
86
|
+
return path.join(getTenantDir(tenant), ".farseer-sync.json");
|
|
91
87
|
}
|
|
92
88
|
function getAuditLogPath(tenant) {
|
|
93
|
-
|
|
89
|
+
return path.join(getTenantDir(tenant), ".farseer-audit.log");
|
|
94
90
|
}
|
|
95
91
|
function getTenantAppsDir(tenant) {
|
|
96
|
-
|
|
92
|
+
return path.join(getTenantDir(tenant), "apps");
|
|
97
93
|
}
|
|
98
94
|
function ensureDirectoryExists(dirPath) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
if (!fs.existsSync(dirPath)) {
|
|
96
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
97
|
+
}
|
|
102
98
|
}
|
|
103
99
|
function getRelativePath(fullPath, basePath) {
|
|
104
|
-
|
|
100
|
+
return path.relative(basePath, fullPath);
|
|
105
101
|
}
|
|
106
102
|
function getAllFiles(dirPath, basePath) {
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
111
|
-
|
|
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
|
-
|
|
127
|
-
|
|
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
|
-
|
|
130
|
-
|
|
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
|
-
|
|
145
|
-
|
|
137
|
+
const ext = path.extname(filename).toLowerCase();
|
|
138
|
+
return [".ts", ".js", ".mjs", ".cjs"].includes(ext);
|
|
146
139
|
}
|
|
147
140
|
function isTextFile(filename) {
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
160
|
-
|
|
150
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
151
|
+
return d.toLocaleString();
|
|
161
152
|
}
|
|
162
153
|
function getCredentialsHint(tenant) {
|
|
163
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
|
168
|
+
return checkout;
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
187
171
|
}
|
|
188
172
|
function resolveTenant(tenantArg) {
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
-
|
|
304
|
-
|
|
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
|
-
|
|
350
|
-
|
|
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
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
-
|
|
320
|
+
return INJECTED_CLIENT_PATTERN.test(code);
|
|
380
321
|
}
|
|
381
322
|
function hasEmptyFarseerClient(code) {
|
|
382
|
-
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
-
|
|
336
|
+
}
|
|
337
|
+
return count;
|
|
398
338
|
}
|
|
399
339
|
function stripCredentialsInDir(srcDir) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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
|
-
|
|
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
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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
|