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