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
|
@@ -1,351 +1,382 @@
|
|
|
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 farseerService_exports = {};
|
|
29
|
-
__export(farseerService_exports, {
|
|
30
|
-
FarseerService: () => FarseerService,
|
|
31
|
-
loginWithBrowser: () => loginWithBrowser,
|
|
32
|
-
loginWithPassword: () => loginWithPassword,
|
|
33
|
-
refreshAccessToken: () => refreshAccessToken
|
|
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;
|
|
34
17
|
});
|
|
35
|
-
|
|
36
|
-
var
|
|
37
|
-
|
|
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.FarseerService = void 0;
|
|
37
|
+
exports.loginWithPassword = loginWithPassword;
|
|
38
|
+
exports.loginWithBrowser = loginWithBrowser;
|
|
39
|
+
exports.refreshAccessToken = refreshAccessToken;
|
|
40
|
+
const farseer = __importStar(require("farseer-client"));
|
|
41
|
+
const configService_1 = require("./configService");
|
|
38
42
|
class FarseerService {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
static fromUserAuth(tenant, basePath) {
|
|
50
|
-
const auth = (0, import_configService.getUserAuth)();
|
|
51
|
-
if (!auth) return null;
|
|
52
|
-
const service = new FarseerService({
|
|
53
|
-
type: "apiKey",
|
|
54
|
-
tenantId: tenant,
|
|
55
|
-
apiKey: "",
|
|
56
|
-
basePath
|
|
57
|
-
});
|
|
58
|
-
service.client = new farseer.FarseerClient({
|
|
59
|
-
basePath,
|
|
60
|
-
headers: {
|
|
61
|
-
"X-TENANT-ID": tenant
|
|
62
|
-
},
|
|
63
|
-
accessToken: auth.accessToken
|
|
64
|
-
});
|
|
65
|
-
return service;
|
|
66
|
-
}
|
|
67
|
-
async testConnection() {
|
|
68
|
-
try {
|
|
69
|
-
await this.client.getItemByPath(["Files"]);
|
|
70
|
-
return true;
|
|
71
|
-
} catch {
|
|
72
|
-
return false;
|
|
43
|
+
constructor(credential) {
|
|
44
|
+
this.credential = credential;
|
|
45
|
+
this.client = new farseer.FarseerClient({
|
|
46
|
+
basePath: credential.basePath,
|
|
47
|
+
headers: {
|
|
48
|
+
'X-TENANT-ID': credential.tenantId,
|
|
49
|
+
'X-API-KEY': credential.apiKey,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
73
52
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
53
|
+
static fromUserAuth(tenant, basePath) {
|
|
54
|
+
const auth = (0, configService_1.getUserAuth)();
|
|
55
|
+
if (!auth)
|
|
56
|
+
return null;
|
|
57
|
+
const service = new FarseerService({
|
|
58
|
+
type: 'apiKey',
|
|
59
|
+
tenantId: tenant,
|
|
60
|
+
apiKey: '',
|
|
61
|
+
basePath: basePath,
|
|
62
|
+
});
|
|
63
|
+
// Override with access token
|
|
64
|
+
service.client = new farseer.FarseerClient({
|
|
65
|
+
basePath: basePath,
|
|
66
|
+
headers: {
|
|
67
|
+
'X-TENANT-ID': tenant,
|
|
68
|
+
},
|
|
69
|
+
accessToken: auth.accessToken,
|
|
70
|
+
});
|
|
71
|
+
return service;
|
|
85
72
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (item.type === farseer.FolderItemType.Folder) {
|
|
95
|
-
const subFiles = await this.listFiles([...folderPath, item.name]);
|
|
96
|
-
files.push(...subFiles);
|
|
97
|
-
} else if (item.type === farseer.FolderItemType.FarseerFile && "reference" in item) {
|
|
98
|
-
files.push({
|
|
99
|
-
name: item.name,
|
|
100
|
-
path: itemPath,
|
|
101
|
-
reference: item.reference
|
|
102
|
-
});
|
|
73
|
+
async testConnection() {
|
|
74
|
+
try {
|
|
75
|
+
// Try to get the Files folder to test connection
|
|
76
|
+
await this.client.getItemByPath(['Files']);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return false;
|
|
103
81
|
}
|
|
104
|
-
}
|
|
105
|
-
} catch (error) {
|
|
106
|
-
return [];
|
|
107
82
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
await this.client.farseerFiles.create(file, "GENERAL", folder.id.toString());
|
|
120
|
-
}
|
|
121
|
-
async updateFile(reference, content, fileName) {
|
|
122
|
-
const blob = content instanceof Buffer ? new Blob([content]) : new Blob([content]);
|
|
123
|
-
const file = new farseer.WebFile([blob], fileName);
|
|
124
|
-
await this.client.farseerFiles.update(reference, file);
|
|
125
|
-
}
|
|
126
|
-
async deleteFile(reference) {
|
|
127
|
-
await this.client.farseerFiles.remove(reference);
|
|
128
|
-
}
|
|
129
|
-
async ensureFolderPath(folderPath) {
|
|
130
|
-
let currentPath = [];
|
|
131
|
-
for (const segment of folderPath) {
|
|
132
|
-
currentPath.push(segment);
|
|
133
|
-
try {
|
|
134
|
-
await this.client.getItemByPath(currentPath);
|
|
135
|
-
} catch {
|
|
136
|
-
if (currentPath.length > 1) {
|
|
137
|
-
const parentPath = currentPath.slice(0, -1);
|
|
138
|
-
const parent = await this.client.getItemByPath(parentPath);
|
|
139
|
-
await this.client.folders.create({
|
|
140
|
-
parentId: parent.id,
|
|
141
|
-
name: segment,
|
|
142
|
-
allowedTypes: []
|
|
143
|
-
});
|
|
83
|
+
async getFilesFolder() {
|
|
84
|
+
try {
|
|
85
|
+
const item = await this.client.getItemByPath(['Files']);
|
|
86
|
+
return {
|
|
87
|
+
id: item.id,
|
|
88
|
+
name: item.name,
|
|
89
|
+
type: item.type,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return null;
|
|
144
94
|
}
|
|
145
|
-
}
|
|
146
95
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
96
|
+
async listFiles(folderPath = ['Files']) {
|
|
97
|
+
const files = [];
|
|
98
|
+
try {
|
|
99
|
+
const folder = await this.client.getItemByPath(folderPath);
|
|
100
|
+
const folderContent = await this.client.folders.listItemsBatch([{ id: folder.id }]);
|
|
101
|
+
for (const item of folderContent[0]?.items || []) {
|
|
102
|
+
// Build path relative to Files folder
|
|
103
|
+
const itemPath = [...folderPath.slice(1), item.name].join('/');
|
|
104
|
+
if (item.type === farseer.FolderItemType.Folder) {
|
|
105
|
+
// Recursively get files from subfolders
|
|
106
|
+
const subFiles = await this.listFiles([...folderPath, item.name]);
|
|
107
|
+
files.push(...subFiles);
|
|
108
|
+
}
|
|
109
|
+
else if (item.type === farseer.FolderItemType.FarseerFile && 'reference' in item) {
|
|
110
|
+
// Accept all file types
|
|
111
|
+
files.push({
|
|
112
|
+
name: item.name,
|
|
113
|
+
path: itemPath,
|
|
114
|
+
reference: item.reference,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
// Folder might not exist
|
|
121
|
+
return [];
|
|
162
122
|
}
|
|
163
|
-
|
|
164
|
-
} catch {
|
|
165
|
-
return null;
|
|
123
|
+
return files;
|
|
166
124
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
try {
|
|
171
|
-
const metadata = await this.client.farseerFiles.getMetadata(reference);
|
|
172
|
-
return {
|
|
173
|
-
uploadTime: metadata.uploadTime?.toISOString(),
|
|
174
|
-
uploader: metadata.uploader ? {
|
|
175
|
-
id: metadata.uploader.id,
|
|
176
|
-
email: metadata.uploader.email || "",
|
|
177
|
-
firstName: metadata.uploader.firstName || "",
|
|
178
|
-
lastName: metadata.uploader.lastName || ""
|
|
179
|
-
} : void 0,
|
|
180
|
-
size: metadata.size
|
|
181
|
-
};
|
|
182
|
-
} catch (error) {
|
|
183
|
-
return null;
|
|
125
|
+
async getFileContent(reference) {
|
|
126
|
+
const blob = await this.client.farseerFiles.get(reference);
|
|
127
|
+
return await blob.text();
|
|
184
128
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const ext = filename.toLowerCase().split(".").pop() || "";
|
|
193
|
-
return ["ts", "js", "mjs", "cjs", "json", "txt", "md", "csv", "xml", "html", "css", "yaml", "yml"].includes(ext);
|
|
194
|
-
}
|
|
195
|
-
isBinaryFile(filename) {
|
|
196
|
-
return !this.isTextFile(filename);
|
|
197
|
-
}
|
|
198
|
-
// ==================== Apps (Remote Jobs) API ====================
|
|
199
|
-
/**
|
|
200
|
-
* List all apps (Remote Jobs) on the tenant
|
|
201
|
-
*/
|
|
202
|
-
async listApps() {
|
|
203
|
-
const response = await this.apiRequest("/remoteJobs", "GET");
|
|
204
|
-
return response.map((app) => ({
|
|
205
|
-
id: app.id,
|
|
206
|
-
name: app.name,
|
|
207
|
-
type: "REMOTE_JOB",
|
|
208
|
-
reference: String(app.id)
|
|
209
|
-
}));
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Get app details by reference ID
|
|
213
|
-
*/
|
|
214
|
-
async getApp(referenceId) {
|
|
215
|
-
try {
|
|
216
|
-
return await this.apiRequest(`/remoteJobs/${referenceId}`, "GET");
|
|
217
|
-
} catch {
|
|
218
|
-
return null;
|
|
129
|
+
async createFile(content, fileName, folderPath = ['Files']) {
|
|
130
|
+
// Ensure folder structure exists
|
|
131
|
+
await this.ensureFolderPath(folderPath);
|
|
132
|
+
const folder = await this.client.getItemByPath(folderPath);
|
|
133
|
+
const blob = content instanceof Buffer ? new Blob([content]) : new Blob([content]);
|
|
134
|
+
const file = new farseer.WebFile([blob], fileName);
|
|
135
|
+
await this.client.farseerFiles.create(file, 'GENERAL', folder.id.toString());
|
|
219
136
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
async getAppByName(name) {
|
|
225
|
-
const apps = await this.listApps();
|
|
226
|
-
const app = apps.find((a) => a.name.toLowerCase() === name.toLowerCase());
|
|
227
|
-
if (!app) {
|
|
228
|
-
return null;
|
|
137
|
+
async updateFile(reference, content, fileName) {
|
|
138
|
+
const blob = content instanceof Buffer ? new Blob([content]) : new Blob([content]);
|
|
139
|
+
const file = new farseer.WebFile([blob], fileName);
|
|
140
|
+
await this.client.farseerFiles.update(reference, file);
|
|
229
141
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Create a new app
|
|
234
|
-
*/
|
|
235
|
-
async createApp(name) {
|
|
236
|
-
const appsFolderId = await this.getAppsFolderId();
|
|
237
|
-
if (!appsFolderId) {
|
|
238
|
-
throw new Error("Apps folder not found");
|
|
142
|
+
async deleteFile(reference) {
|
|
143
|
+
await this.client.farseerFiles.remove(reference);
|
|
239
144
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
145
|
+
async ensureFolderPath(folderPath) {
|
|
146
|
+
const currentPath = [];
|
|
147
|
+
for (const segment of folderPath) {
|
|
148
|
+
currentPath.push(segment);
|
|
149
|
+
try {
|
|
150
|
+
await this.client.getItemByPath(currentPath);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// Folder doesn't exist, create it
|
|
154
|
+
if (currentPath.length > 1) {
|
|
155
|
+
const parentPath = currentPath.slice(0, -1);
|
|
156
|
+
const parent = await this.client.getItemByPath(parentPath);
|
|
157
|
+
await this.client.folders.create({
|
|
158
|
+
parentId: parent.id,
|
|
159
|
+
name: segment,
|
|
160
|
+
allowedTypes: [],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
258
165
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
async exportModel() {
|
|
281
|
-
return this.apiRequest("/model/export", "POST");
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Get the Apps folder ID
|
|
285
|
-
*/
|
|
286
|
-
async getAppsFolderId() {
|
|
287
|
-
try {
|
|
288
|
-
const item = await this.client.getItemByPath(["Apps"]);
|
|
289
|
-
return item.id;
|
|
290
|
-
} catch {
|
|
291
|
-
return null;
|
|
166
|
+
async getFileByPath(filePath) {
|
|
167
|
+
const pathParts = ['Files', ...filePath.split('/')];
|
|
168
|
+
const fileName = pathParts.pop();
|
|
169
|
+
const folderPath = pathParts;
|
|
170
|
+
try {
|
|
171
|
+
const folder = await this.client.getItemByPath(folderPath);
|
|
172
|
+
const folderContent = await this.client.folders.listItemsBatch([{ id: folder.id }]);
|
|
173
|
+
for (const item of folderContent[0]?.items || []) {
|
|
174
|
+
if (item.name === fileName && item.type === farseer.FolderItemType.FarseerFile && 'reference' in item) {
|
|
175
|
+
return {
|
|
176
|
+
name: item.name,
|
|
177
|
+
path: filePath,
|
|
178
|
+
reference: item.reference,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
292
187
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
188
|
+
async getFileMetadata(reference) {
|
|
189
|
+
try {
|
|
190
|
+
const metadata = await this.client.farseerFiles.getMetadata(reference);
|
|
191
|
+
return {
|
|
192
|
+
uploadTime: metadata.uploadTime?.toISOString(),
|
|
193
|
+
uploader: metadata.uploader
|
|
194
|
+
? {
|
|
195
|
+
id: metadata.uploader.id,
|
|
196
|
+
email: metadata.uploader.email || '',
|
|
197
|
+
firstName: metadata.uploader.firstName || '',
|
|
198
|
+
lastName: metadata.uploader.lastName || '',
|
|
199
|
+
}
|
|
200
|
+
: undefined,
|
|
201
|
+
size: metadata.size,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
// Metadata fetch failed - non-critical, continue without it
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
312
208
|
}
|
|
313
|
-
|
|
314
|
-
|
|
209
|
+
async getFileContentAsBuffer(reference) {
|
|
210
|
+
const blob = await this.client.farseerFiles.get(reference);
|
|
211
|
+
const arrayBuffer = await blob.arrayBuffer();
|
|
212
|
+
return Buffer.from(arrayBuffer);
|
|
213
|
+
}
|
|
214
|
+
isTextFile(filename) {
|
|
215
|
+
const ext = filename.toLowerCase().split('.').pop() || '';
|
|
216
|
+
return ['ts', 'js', 'mjs', 'cjs', 'json', 'txt', 'md', 'csv', 'xml', 'html', 'css', 'yaml', 'yml'].includes(ext);
|
|
217
|
+
}
|
|
218
|
+
isBinaryFile(filename) {
|
|
219
|
+
return !this.isTextFile(filename);
|
|
220
|
+
}
|
|
221
|
+
// ==================== Apps (Remote Jobs) API ====================
|
|
222
|
+
/**
|
|
223
|
+
* List all apps (Remote Jobs) on the tenant
|
|
224
|
+
*/
|
|
225
|
+
async listApps() {
|
|
226
|
+
const response = await this.apiRequest('/remoteJobs', 'GET');
|
|
227
|
+
return response.map((app) => ({
|
|
228
|
+
id: app.id,
|
|
229
|
+
name: app.name,
|
|
230
|
+
type: 'REMOTE_JOB',
|
|
231
|
+
reference: String(app.id),
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Get app details by reference ID
|
|
236
|
+
*/
|
|
237
|
+
async getApp(referenceId) {
|
|
238
|
+
try {
|
|
239
|
+
return await this.apiRequest(`/remoteJobs/${referenceId}`, 'GET');
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get app by name
|
|
247
|
+
*/
|
|
248
|
+
async getAppByName(name) {
|
|
249
|
+
const apps = await this.listApps();
|
|
250
|
+
const app = apps.find((a) => a.name.toLowerCase() === name.toLowerCase());
|
|
251
|
+
if (!app) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
return this.getApp(app.reference);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Create a new app
|
|
258
|
+
*/
|
|
259
|
+
async createApp(name) {
|
|
260
|
+
// Get Apps folder ID first
|
|
261
|
+
const appsFolderId = await this.getAppsFolderId();
|
|
262
|
+
if (!appsFolderId) {
|
|
263
|
+
throw new Error('Apps folder not found');
|
|
264
|
+
}
|
|
265
|
+
return await this.apiRequest('/remoteJobs', 'POST', {
|
|
266
|
+
folderId: appsFolderId,
|
|
267
|
+
name,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Update an app
|
|
272
|
+
*/
|
|
273
|
+
async updateApp(referenceId, update) {
|
|
274
|
+
await this.apiRequest(`/remoteJobs/${referenceId}`, 'PUT', {
|
|
275
|
+
...update,
|
|
276
|
+
schedule: null,
|
|
277
|
+
runnerName: null,
|
|
278
|
+
predefinedActions: [],
|
|
279
|
+
});
|
|
280
|
+
// API returns 204 No Content, so fetch the updated app
|
|
281
|
+
const app = await this.getApp(referenceId);
|
|
282
|
+
if (!app) {
|
|
283
|
+
throw new Error('Failed to fetch updated app');
|
|
284
|
+
}
|
|
285
|
+
return app;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Delete an app
|
|
289
|
+
*/
|
|
290
|
+
async deleteApp(referenceId) {
|
|
291
|
+
await this.apiRequest(`/remoteJobs/${referenceId}`, 'DELETE');
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Get script files available for apps
|
|
295
|
+
*/
|
|
296
|
+
async getScriptFiles() {
|
|
297
|
+
const allFiles = await this.listFiles(['Files']);
|
|
298
|
+
return allFiles
|
|
299
|
+
.filter((f) => f.name.endsWith('.ts') || f.name.endsWith('.js'))
|
|
300
|
+
.map((f) => ({
|
|
301
|
+
id: f.reference,
|
|
302
|
+
name: f.name,
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Export the entire model structure
|
|
307
|
+
*/
|
|
308
|
+
async exportModel() {
|
|
309
|
+
return this.apiRequest('/model/export', 'POST');
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Get the Apps folder ID
|
|
313
|
+
*/
|
|
314
|
+
async getAppsFolderId() {
|
|
315
|
+
try {
|
|
316
|
+
const item = await this.client.getItemByPath(['Apps']);
|
|
317
|
+
return item.id;
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Make a direct API request (for endpoints not in farseer-client)
|
|
325
|
+
*/
|
|
326
|
+
async apiRequest(endpoint, method, body) {
|
|
327
|
+
const url = `${this.credential.basePath}${endpoint}`;
|
|
328
|
+
const headers = {
|
|
329
|
+
'Content-Type': 'application/json',
|
|
330
|
+
'X-TENANT-ID': this.credential.tenantId,
|
|
331
|
+
'X-API-KEY': this.credential.apiKey,
|
|
332
|
+
'x-api-version': '3.3.0',
|
|
333
|
+
};
|
|
334
|
+
const response = await fetch(url, {
|
|
335
|
+
method,
|
|
336
|
+
headers,
|
|
337
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
338
|
+
});
|
|
339
|
+
if (!response.ok) {
|
|
340
|
+
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
|
|
341
|
+
}
|
|
342
|
+
if (response.status === 204) {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
return response.json();
|
|
315
346
|
}
|
|
316
|
-
return response.json();
|
|
317
|
-
}
|
|
318
347
|
}
|
|
348
|
+
exports.FarseerService = FarseerService;
|
|
319
349
|
async function loginWithPassword(email, password) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
350
|
+
const tokenUrl = 'https://login.farseer.io/auth/realms/master/protocol/openid-connect/token';
|
|
351
|
+
try {
|
|
352
|
+
const response = await fetch(tokenUrl, {
|
|
353
|
+
method: 'POST',
|
|
354
|
+
headers: {
|
|
355
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
356
|
+
},
|
|
357
|
+
body: new URLSearchParams({
|
|
358
|
+
grant_type: 'password',
|
|
359
|
+
client_id: 'security-admin-console',
|
|
360
|
+
username: email,
|
|
361
|
+
password: password,
|
|
362
|
+
}),
|
|
363
|
+
});
|
|
364
|
+
if (!response.ok) {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
const data = (await response.json());
|
|
368
|
+
return {
|
|
369
|
+
accessToken: data.access_token,
|
|
370
|
+
refreshToken: data.refresh_token,
|
|
371
|
+
expiresIn: data.expires_in,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
return null;
|
|
336
376
|
}
|
|
337
|
-
const data = await response.json();
|
|
338
|
-
return {
|
|
339
|
-
accessToken: data.access_token,
|
|
340
|
-
refreshToken: data.refresh_token,
|
|
341
|
-
expiresIn: data.expires_in
|
|
342
|
-
};
|
|
343
|
-
} catch {
|
|
344
|
-
return null;
|
|
345
|
-
}
|
|
346
377
|
}
|
|
347
378
|
function getErrorPage(title, message) {
|
|
348
|
-
|
|
379
|
+
return `
|
|
349
380
|
<html>
|
|
350
381
|
<head>
|
|
351
382
|
<title>Farseer CLI - Error</title>
|
|
@@ -408,60 +439,64 @@ function getErrorPage(title, message) {
|
|
|
408
439
|
</html>
|
|
409
440
|
`;
|
|
410
441
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
442
|
+
// Browser-based OAuth login with PKCE
|
|
443
|
+
async function loginWithBrowser(realm = 'master') {
|
|
444
|
+
const http = await Promise.resolve().then(() => __importStar(require('http')));
|
|
445
|
+
const crypto = await Promise.resolve().then(() => __importStar(require('crypto')));
|
|
446
|
+
const { exec } = await Promise.resolve().then(() => __importStar(require('child_process')));
|
|
447
|
+
const { promisify } = await Promise.resolve().then(() => __importStar(require('util')));
|
|
448
|
+
const execAsync = promisify(exec);
|
|
449
|
+
const KEYCLOAK_BASE = `https://login.farseer.io/auth/realms/${realm}/protocol/openid-connect`;
|
|
450
|
+
const CLIENT_ID = 'auth'; // Use auth client with full scope access
|
|
451
|
+
const REDIRECT_PORT = 8787;
|
|
452
|
+
const REDIRECT_URI = `http://localhost:${REDIRECT_PORT}/callback`;
|
|
453
|
+
// Generate PKCE code verifier and challenge
|
|
454
|
+
const codeVerifier = crypto.randomBytes(32).toString('base64url');
|
|
455
|
+
const codeChallenge = crypto.createHash('sha256').update(codeVerifier).digest('base64url');
|
|
456
|
+
// Generate state for CSRF protection
|
|
457
|
+
const state = crypto.randomBytes(16).toString('hex');
|
|
458
|
+
return new Promise((resolve) => {
|
|
459
|
+
const server = http.createServer(async (req, res) => {
|
|
460
|
+
const url = new URL(req.url || '', `http://localhost:${REDIRECT_PORT}`);
|
|
461
|
+
if (url.pathname === '/callback') {
|
|
462
|
+
const code = url.searchParams.get('code');
|
|
463
|
+
const returnedState = url.searchParams.get('state');
|
|
464
|
+
const error = url.searchParams.get('error');
|
|
465
|
+
if (error) {
|
|
466
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
467
|
+
res.end(getErrorPage('Login Failed', `Error: ${error}`));
|
|
468
|
+
server.close();
|
|
469
|
+
resolve(null);
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (!code || returnedState !== state) {
|
|
473
|
+
res.writeHead(400, { 'Content-Type': 'text/html' });
|
|
474
|
+
res.end(getErrorPage('Invalid Response', 'Missing code or state mismatch.'));
|
|
475
|
+
server.close();
|
|
476
|
+
resolve(null);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
// Exchange code for tokens
|
|
480
|
+
try {
|
|
481
|
+
const tokenResponse = await fetch(`${KEYCLOAK_BASE}/token`, {
|
|
482
|
+
method: 'POST',
|
|
483
|
+
headers: {
|
|
484
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
485
|
+
},
|
|
486
|
+
body: new URLSearchParams({
|
|
487
|
+
grant_type: 'authorization_code',
|
|
488
|
+
client_id: CLIENT_ID,
|
|
489
|
+
code: code,
|
|
490
|
+
redirect_uri: REDIRECT_URI,
|
|
491
|
+
code_verifier: codeVerifier,
|
|
492
|
+
}),
|
|
493
|
+
});
|
|
494
|
+
if (!tokenResponse.ok) {
|
|
495
|
+
throw new Error('Token exchange failed');
|
|
496
|
+
}
|
|
497
|
+
const data = (await tokenResponse.json());
|
|
498
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
499
|
+
res.end(`
|
|
465
500
|
<html>
|
|
466
501
|
<head>
|
|
467
502
|
<title>Farseer CLI - Login</title>
|
|
@@ -532,83 +567,81 @@ async function loginWithBrowser(realm = "master") {
|
|
|
532
567
|
</body>
|
|
533
568
|
</html>
|
|
534
569
|
`);
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
${url}
|
|
571
|
-
|
|
572
|
-
|
|
570
|
+
server.close();
|
|
571
|
+
resolve({
|
|
572
|
+
accessToken: data.access_token,
|
|
573
|
+
refreshToken: data.refresh_token,
|
|
574
|
+
expiresIn: data.expires_in,
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
catch {
|
|
578
|
+
res.writeHead(500, { 'Content-Type': 'text/html' });
|
|
579
|
+
res.end(getErrorPage('Token Exchange Failed', 'Could not complete login.'));
|
|
580
|
+
server.close();
|
|
581
|
+
resolve(null);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
server.listen(REDIRECT_PORT, async () => {
|
|
586
|
+
// Build authorization URL
|
|
587
|
+
const authUrl = new URL(`${KEYCLOAK_BASE}/auth`);
|
|
588
|
+
authUrl.searchParams.set('client_id', CLIENT_ID);
|
|
589
|
+
authUrl.searchParams.set('redirect_uri', REDIRECT_URI);
|
|
590
|
+
authUrl.searchParams.set('response_type', 'code');
|
|
591
|
+
authUrl.searchParams.set('scope', 'openid offline_access');
|
|
592
|
+
authUrl.searchParams.set('state', state);
|
|
593
|
+
authUrl.searchParams.set('code_challenge', codeChallenge);
|
|
594
|
+
authUrl.searchParams.set('code_challenge_method', 'S256');
|
|
595
|
+
// Open browser
|
|
596
|
+
const url = authUrl.toString();
|
|
597
|
+
try {
|
|
598
|
+
if (process.platform === 'darwin') {
|
|
599
|
+
await execAsync(`open "${url}"`);
|
|
600
|
+
}
|
|
601
|
+
else if (process.platform === 'win32') {
|
|
602
|
+
await execAsync(`start "${url}"`);
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
await execAsync(`xdg-open "${url}"`);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
catch {
|
|
609
|
+
// If we can't open browser, show URL to user
|
|
610
|
+
console.log(`\nOpen this URL in your browser:\n${url}\n`);
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
// Timeout after 5 minutes
|
|
614
|
+
setTimeout(() => {
|
|
615
|
+
server.close();
|
|
616
|
+
resolve(null);
|
|
617
|
+
}, 5 * 60 * 1000);
|
|
573
618
|
});
|
|
574
|
-
setTimeout(() => {
|
|
575
|
-
server.close();
|
|
576
|
-
resolve(null);
|
|
577
|
-
}, 5 * 60 * 1e3);
|
|
578
|
-
});
|
|
579
619
|
}
|
|
580
|
-
async function refreshAccessToken(refreshToken, realm =
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
620
|
+
async function refreshAccessToken(refreshToken, realm = 'master') {
|
|
621
|
+
const tokenUrl = `https://login.farseer.io/auth/realms/${realm}/protocol/openid-connect/token`;
|
|
622
|
+
try {
|
|
623
|
+
const response = await fetch(tokenUrl, {
|
|
624
|
+
method: 'POST',
|
|
625
|
+
headers: {
|
|
626
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
627
|
+
},
|
|
628
|
+
body: new URLSearchParams({
|
|
629
|
+
grant_type: 'refresh_token',
|
|
630
|
+
client_id: 'auth',
|
|
631
|
+
refresh_token: refreshToken,
|
|
632
|
+
}),
|
|
633
|
+
});
|
|
634
|
+
if (!response.ok) {
|
|
635
|
+
return null;
|
|
636
|
+
}
|
|
637
|
+
const data = (await response.json());
|
|
638
|
+
return {
|
|
639
|
+
accessToken: data.access_token,
|
|
640
|
+
refreshToken: data.refresh_token,
|
|
641
|
+
expiresIn: data.expires_in,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
catch {
|
|
645
|
+
return null;
|
|
596
646
|
}
|
|
597
|
-
const data = await response.json();
|
|
598
|
-
return {
|
|
599
|
-
accessToken: data.access_token,
|
|
600
|
-
refreshToken: data.refresh_token,
|
|
601
|
-
expiresIn: data.expires_in
|
|
602
|
-
};
|
|
603
|
-
} catch {
|
|
604
|
-
return null;
|
|
605
|
-
}
|
|
606
647
|
}
|
|
607
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
608
|
-
0 && (module.exports = {
|
|
609
|
-
FarseerService,
|
|
610
|
-
loginWithBrowser,
|
|
611
|
-
loginWithPassword,
|
|
612
|
-
refreshAccessToken
|
|
613
|
-
});
|
|
614
|
-
//# sourceMappingURL=farseerService.js.map
|