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,426 +1,426 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* FarseerApi - Direct HTTP API client using JWT Bearer token authentication
|
|
4
|
+
*
|
|
5
|
+
* This is an alternative to FarseerService that doesn't use farseer-client library.
|
|
6
|
+
* Use this when authenticating via browser login (Keycloak JWT token) instead of API key.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
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 farseerApi_exports = {};
|
|
29
|
-
__export(farseerApi_exports, {
|
|
30
|
-
FarseerApi: () => FarseerApi
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(farseerApi_exports);
|
|
33
|
-
var import_axios = __toESM(require("axios"));
|
|
34
|
-
var import_configService = require("./configService");
|
|
35
|
-
var import_farseerService = require("./farseerService");
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FarseerApi = void 0;
|
|
13
|
+
const axios_1 = __importDefault(require("axios"));
|
|
14
|
+
const configService_1 = require("./configService");
|
|
15
|
+
const farseerService_1 = require("./farseerService");
|
|
36
16
|
class FarseerApi {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
17
|
+
constructor(accessToken, tenant, tenantId) {
|
|
18
|
+
this.isRefreshing = false;
|
|
19
|
+
this.refreshSubscribers = [];
|
|
20
|
+
this.tenant = tenant;
|
|
21
|
+
this.tenantId = tenantId || tenant;
|
|
22
|
+
// Try to get basePath from existing config, or generate from tenant name
|
|
23
|
+
const credential = (0, configService_1.getCredential)(tenant);
|
|
24
|
+
const basePath = credential?.basePath || `https://${tenant}.farseer.io/api/v3`;
|
|
25
|
+
this.client = axios_1.default.create({
|
|
26
|
+
baseURL: basePath,
|
|
27
|
+
headers: {
|
|
28
|
+
Authorization: `Bearer ${accessToken}`,
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
'x-api-version': '3.3.0',
|
|
31
|
+
'X-TENANT-ID': this.tenantId,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
// Add response interceptor for automatic token refresh on 401
|
|
35
|
+
this.client.interceptors.response.use((response) => response, async (error) => {
|
|
36
|
+
const originalRequest = error.config;
|
|
37
|
+
// Only handle 401 errors and avoid infinite loops
|
|
38
|
+
if (error.response?.status === 401 && !originalRequest._retry) {
|
|
39
|
+
originalRequest._retry = true;
|
|
40
|
+
// If already refreshing, wait for the new token
|
|
41
|
+
if (this.isRefreshing) {
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
this.refreshSubscribers.push((token) => {
|
|
44
|
+
originalRequest.headers['Authorization'] = `Bearer ${token}`;
|
|
45
|
+
resolve(this.client(originalRequest));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
this.isRefreshing = true;
|
|
50
|
+
try {
|
|
51
|
+
const auth = (0, configService_1.getUserAuth)();
|
|
52
|
+
if (!auth?.refreshToken) {
|
|
53
|
+
throw new Error('No refresh token available');
|
|
54
|
+
}
|
|
55
|
+
const refreshed = await (0, farseerService_1.refreshAccessToken)(auth.refreshToken, auth.realm || 'master');
|
|
56
|
+
if (!refreshed) {
|
|
57
|
+
throw new Error('Token refresh failed');
|
|
58
|
+
}
|
|
59
|
+
// Save the new token
|
|
60
|
+
(0, configService_1.setUserAuth)({
|
|
61
|
+
accessToken: refreshed.accessToken,
|
|
62
|
+
refreshToken: refreshed.refreshToken,
|
|
63
|
+
expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),
|
|
64
|
+
realm: auth.realm,
|
|
65
|
+
});
|
|
66
|
+
// Update this client's token
|
|
67
|
+
this.updateAccessToken(refreshed.accessToken);
|
|
68
|
+
// Notify all waiting requests
|
|
69
|
+
this.refreshSubscribers.forEach((callback) => callback(refreshed.accessToken));
|
|
70
|
+
this.refreshSubscribers = [];
|
|
71
|
+
// Retry the original request
|
|
72
|
+
originalRequest.headers['Authorization'] = `Bearer ${refreshed.accessToken}`;
|
|
73
|
+
return this.client(originalRequest);
|
|
74
|
+
}
|
|
75
|
+
catch (refreshError) {
|
|
76
|
+
// Token refresh failed - let the error propagate
|
|
77
|
+
this.refreshSubscribers = [];
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
this.isRefreshing = false;
|
|
82
|
+
}
|
|
72
83
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
return Promise.reject(error);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Update the access token (used when token is refreshed)
|
|
89
|
+
*/
|
|
90
|
+
updateAccessToken(newToken) {
|
|
91
|
+
this.client.defaults.headers['Authorization'] = `Bearer ${newToken}`;
|
|
92
|
+
}
|
|
93
|
+
async testConnection() {
|
|
94
|
+
try {
|
|
95
|
+
await this.getItemByPath(['Files']);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async getFilesFolder() {
|
|
103
|
+
try {
|
|
104
|
+
const item = await this.getItemByPath(['Files']);
|
|
105
|
+
return {
|
|
106
|
+
id: item.id,
|
|
107
|
+
name: item.name,
|
|
108
|
+
type: item.type,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async listFolderItems(folderId) {
|
|
116
|
+
// Body is array: [{ id: null }] for root, [{ id: folderId }] for specific folder
|
|
117
|
+
const response = await this.client.post('/folders/items', [{ id: folderId }]);
|
|
118
|
+
return response.data[0] || { items: [] };
|
|
119
|
+
}
|
|
120
|
+
async findFolderByName(parentId, name) {
|
|
121
|
+
const content = await this.listFolderItems(parentId);
|
|
122
|
+
const folder = content.items?.find((item) => item.name.toLowerCase() === name.toLowerCase() && item.type.toLowerCase() === 'folder');
|
|
123
|
+
return folder || null;
|
|
124
|
+
}
|
|
125
|
+
async getItemByPath(path) {
|
|
126
|
+
let currentId = null;
|
|
127
|
+
for (const segment of path) {
|
|
128
|
+
const folder = await this.findFolderByName(currentId, segment);
|
|
129
|
+
if (!folder) {
|
|
130
|
+
throw new Error(`Folder not found: ${segment}`);
|
|
131
|
+
}
|
|
132
|
+
currentId = folder.id;
|
|
133
|
+
}
|
|
134
|
+
if (currentId === null) {
|
|
135
|
+
throw new Error('Path is empty');
|
|
136
|
+
}
|
|
137
|
+
// Return a minimal FolderItem with the found id
|
|
138
|
+
return { id: currentId, name: path[path.length - 1], type: 'folder' };
|
|
139
|
+
}
|
|
140
|
+
async listFiles(folderPath = ['Files']) {
|
|
141
|
+
const files = [];
|
|
142
|
+
try {
|
|
143
|
+
const folder = await this.getItemByPath(folderPath);
|
|
144
|
+
const folderContent = await this.listFolderItems(folder.id);
|
|
145
|
+
for (const item of folderContent.items || []) {
|
|
146
|
+
const itemPath = [...folderPath.slice(1), item.name].join('/');
|
|
147
|
+
const itemType = item.type.toLowerCase();
|
|
148
|
+
if (itemType === 'folder') {
|
|
149
|
+
const subFiles = await this.listFiles([...folderPath, item.name]);
|
|
150
|
+
files.push(...subFiles);
|
|
151
|
+
}
|
|
152
|
+
else if ((itemType === 'farseer-file' || itemType === 'farseer_file') && item.reference) {
|
|
153
|
+
files.push({
|
|
154
|
+
name: item.name,
|
|
155
|
+
path: itemPath,
|
|
156
|
+
reference: item.reference,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
76
159
|
}
|
|
77
|
-
(0, import_configService.setUserAuth)({
|
|
78
|
-
accessToken: refreshed.accessToken,
|
|
79
|
-
refreshToken: refreshed.refreshToken,
|
|
80
|
-
expiresAt: new Date(Date.now() + refreshed.expiresIn * 1e3).toISOString(),
|
|
81
|
-
realm: auth.realm
|
|
82
|
-
});
|
|
83
|
-
this.updateAccessToken(refreshed.accessToken);
|
|
84
|
-
this.refreshSubscribers.forEach((callback) => callback(refreshed.accessToken));
|
|
85
|
-
this.refreshSubscribers = [];
|
|
86
|
-
originalRequest.headers["Authorization"] = `Bearer ${refreshed.accessToken}`;
|
|
87
|
-
return this.client(originalRequest);
|
|
88
|
-
} catch (refreshError) {
|
|
89
|
-
this.refreshSubscribers = [];
|
|
90
|
-
throw error;
|
|
91
|
-
} finally {
|
|
92
|
-
this.isRefreshing = false;
|
|
93
|
-
}
|
|
94
160
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
161
|
+
catch (error) {
|
|
162
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
163
|
+
const status = error.response?.status;
|
|
164
|
+
const data = error.response?.data;
|
|
165
|
+
const message = typeof data === 'string' ? data : data?.message || JSON.stringify(data);
|
|
166
|
+
console.error(`API Error: ${status} "${message}" (path: ${folderPath.join('/')})`);
|
|
167
|
+
if (data?.code === 'Forbidden') {
|
|
168
|
+
const errorMessage = data?.message || 'Access denied';
|
|
169
|
+
throw new Error(`Access denied: ${errorMessage}\nYou may need to use --tenant-id to specify a different tenant ID.`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
return files;
|
|
175
|
+
}
|
|
176
|
+
async getFileContent(reference) {
|
|
177
|
+
const response = await this.client.get(`/farseerFiles/${reference}`, {
|
|
178
|
+
responseType: 'text',
|
|
179
|
+
});
|
|
180
|
+
return response.data;
|
|
181
|
+
}
|
|
182
|
+
async getFileContentAsBuffer(reference) {
|
|
183
|
+
const response = await this.client.get(`/farseerFiles/${reference}`, {
|
|
184
|
+
responseType: 'arraybuffer',
|
|
185
|
+
});
|
|
186
|
+
return Buffer.from(response.data);
|
|
111
187
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
188
|
+
async createFile(content, fileName, folderPath = ['Files']) {
|
|
189
|
+
await this.ensureFolderPath(folderPath);
|
|
190
|
+
const folder = await this.getItemByPath(folderPath);
|
|
191
|
+
const formData = new FormData();
|
|
192
|
+
const blob = content instanceof Buffer ? new Blob([content]) : new Blob([content]);
|
|
193
|
+
formData.append('file', blob, fileName);
|
|
194
|
+
formData.append('category', 'GENERAL');
|
|
195
|
+
formData.append('folderId', folder.id.toString());
|
|
196
|
+
await this.client.post('/farseerFiles', formData, {
|
|
197
|
+
headers: {
|
|
198
|
+
'Content-Type': 'multipart/form-data',
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
async updateFile(reference, content, fileName) {
|
|
203
|
+
const formData = new FormData();
|
|
204
|
+
const blob = content instanceof Buffer ? new Blob([content]) : new Blob([content]);
|
|
205
|
+
formData.append('file', blob, fileName);
|
|
206
|
+
await this.client.put(`/farseerFiles/${reference}`, formData, {
|
|
207
|
+
headers: {
|
|
208
|
+
'Content-Type': 'multipart/form-data',
|
|
209
|
+
},
|
|
210
|
+
});
|
|
123
211
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const response = await this.client.post("/folders/items", [{ id: folderId }]);
|
|
127
|
-
return response.data[0] || { items: [] };
|
|
128
|
-
}
|
|
129
|
-
async findFolderByName(parentId, name) {
|
|
130
|
-
const content = await this.listFolderItems(parentId);
|
|
131
|
-
const folder = content.items?.find(
|
|
132
|
-
(item) => item.name.toLowerCase() === name.toLowerCase() && item.type.toLowerCase() === "folder"
|
|
133
|
-
);
|
|
134
|
-
return folder || null;
|
|
135
|
-
}
|
|
136
|
-
async getItemByPath(path) {
|
|
137
|
-
let currentId = null;
|
|
138
|
-
for (const segment of path) {
|
|
139
|
-
const folder = await this.findFolderByName(currentId, segment);
|
|
140
|
-
if (!folder) {
|
|
141
|
-
throw new Error(`Folder not found: ${segment}`);
|
|
142
|
-
}
|
|
143
|
-
currentId = folder.id;
|
|
212
|
+
async deleteFile(reference) {
|
|
213
|
+
await this.client.delete(`/farseerFiles/${reference}`);
|
|
144
214
|
}
|
|
145
|
-
|
|
146
|
-
|
|
215
|
+
async ensureFolderPath(folderPath) {
|
|
216
|
+
const currentPath = [];
|
|
217
|
+
for (const segment of folderPath) {
|
|
218
|
+
currentPath.push(segment);
|
|
219
|
+
try {
|
|
220
|
+
await this.getItemByPath(currentPath);
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
if (currentPath.length > 1) {
|
|
224
|
+
const parentPath = currentPath.slice(0, -1);
|
|
225
|
+
const parent = await this.getItemByPath(parentPath);
|
|
226
|
+
await this.client.post('/folders', {
|
|
227
|
+
parentId: parent.id,
|
|
228
|
+
name: segment,
|
|
229
|
+
allowedTypes: [],
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
147
234
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
235
|
+
async getFileByPath(filePath) {
|
|
236
|
+
const pathParts = ['Files', ...filePath.split('/')];
|
|
237
|
+
const fileName = pathParts.pop();
|
|
238
|
+
const folderPath = pathParts;
|
|
239
|
+
try {
|
|
240
|
+
const folder = await this.getItemByPath(folderPath);
|
|
241
|
+
const folderContent = await this.listFolderItems(folder.id);
|
|
242
|
+
for (const item of folderContent.items || []) {
|
|
243
|
+
const itemType = item.type.toLowerCase();
|
|
244
|
+
if (item.name === fileName &&
|
|
245
|
+
(itemType === 'farseer-file' || itemType === 'farseer_file') &&
|
|
246
|
+
item.reference) {
|
|
247
|
+
return {
|
|
248
|
+
name: item.name,
|
|
249
|
+
path: filePath,
|
|
250
|
+
reference: item.reference,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
167
254
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (import_axios.default.isAxiosError(error)) {
|
|
171
|
-
const status = error.response?.status;
|
|
172
|
-
const data = error.response?.data;
|
|
173
|
-
const message = typeof data === "string" ? data : data?.message || JSON.stringify(data);
|
|
174
|
-
console.error(`API Error: ${status} "${message}" (path: ${folderPath.join("/")})`);
|
|
175
|
-
if (data?.code === "Forbidden") {
|
|
176
|
-
const errorMessage = data?.message || "Access denied";
|
|
177
|
-
throw new Error(`Access denied: ${errorMessage}
|
|
178
|
-
You may need to use --tenant-id to specify a different tenant ID.`);
|
|
255
|
+
catch {
|
|
256
|
+
return null;
|
|
179
257
|
}
|
|
180
|
-
|
|
181
|
-
return [];
|
|
258
|
+
return null;
|
|
182
259
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
formData.append("category", "GENERAL");
|
|
204
|
-
formData.append("folderId", folder.id.toString());
|
|
205
|
-
await this.client.post("/farseerFiles", formData, {
|
|
206
|
-
headers: {
|
|
207
|
-
"Content-Type": "multipart/form-data"
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
async updateFile(reference, content, fileName) {
|
|
212
|
-
const formData = new FormData();
|
|
213
|
-
const blob = content instanceof Buffer ? new Blob([content]) : new Blob([content]);
|
|
214
|
-
formData.append("file", blob, fileName);
|
|
215
|
-
await this.client.put(`/farseerFiles/${reference}`, formData, {
|
|
216
|
-
headers: {
|
|
217
|
-
"Content-Type": "multipart/form-data"
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
async deleteFile(reference) {
|
|
222
|
-
await this.client.delete(`/farseerFiles/${reference}`);
|
|
223
|
-
}
|
|
224
|
-
async ensureFolderPath(folderPath) {
|
|
225
|
-
let currentPath = [];
|
|
226
|
-
for (const segment of folderPath) {
|
|
227
|
-
currentPath.push(segment);
|
|
228
|
-
try {
|
|
229
|
-
await this.getItemByPath(currentPath);
|
|
230
|
-
} catch {
|
|
231
|
-
if (currentPath.length > 1) {
|
|
232
|
-
const parentPath = currentPath.slice(0, -1);
|
|
233
|
-
const parent = await this.getItemByPath(parentPath);
|
|
234
|
-
await this.client.post("/folders", {
|
|
235
|
-
parentId: parent.id,
|
|
236
|
-
name: segment,
|
|
237
|
-
allowedTypes: []
|
|
238
|
-
});
|
|
260
|
+
async getFileMetadata(reference) {
|
|
261
|
+
try {
|
|
262
|
+
const response = await this.client.get(`/farseerFiles/${reference}/metadata`);
|
|
263
|
+
const data = response.data;
|
|
264
|
+
return {
|
|
265
|
+
uploadTime: data.uploadTime,
|
|
266
|
+
uploader: data.uploader
|
|
267
|
+
? {
|
|
268
|
+
id: data.uploader.id,
|
|
269
|
+
email: data.uploader.email || '',
|
|
270
|
+
firstName: data.uploader.firstName || '',
|
|
271
|
+
lastName: data.uploader.lastName || '',
|
|
272
|
+
}
|
|
273
|
+
: undefined,
|
|
274
|
+
size: data.size,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
// Metadata fetch failed - non-critical, continue without it
|
|
279
|
+
return null;
|
|
239
280
|
}
|
|
240
|
-
}
|
|
241
281
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
282
|
+
isTextFile(filename) {
|
|
283
|
+
const ext = filename.toLowerCase().split('.').pop() || '';
|
|
284
|
+
return ['ts', 'js', 'mjs', 'cjs', 'json', 'txt', 'md', 'csv', 'xml', 'html', 'css', 'yaml', 'yml'].includes(ext);
|
|
285
|
+
}
|
|
286
|
+
isBinaryFile(filename) {
|
|
287
|
+
return !this.isTextFile(filename);
|
|
288
|
+
}
|
|
289
|
+
// ==================== Apps (Remote Jobs) API ====================
|
|
290
|
+
/**
|
|
291
|
+
* Get the Apps folder ID
|
|
292
|
+
*/
|
|
293
|
+
async getAppsFolderId() {
|
|
294
|
+
const content = await this.listFolderItems(null);
|
|
295
|
+
const appsFolder = content.items?.find((item) => item.name.toLowerCase() === 'apps' && item.type.toLowerCase() === 'folder');
|
|
296
|
+
return appsFolder?.id || null;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* List all apps (Remote Jobs) on the tenant, including those in subfolders
|
|
300
|
+
*/
|
|
301
|
+
async listApps() {
|
|
302
|
+
const appsFolderId = await this.getAppsFolderId();
|
|
303
|
+
if (!appsFolderId) {
|
|
304
|
+
return [];
|
|
258
305
|
}
|
|
259
|
-
|
|
260
|
-
} catch {
|
|
261
|
-
return null;
|
|
306
|
+
return this.listAppsRecursive(appsFolderId);
|
|
262
307
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
308
|
+
/**
|
|
309
|
+
* Recursively list all apps in a folder and its subfolders
|
|
310
|
+
*/
|
|
311
|
+
async listAppsRecursive(folderId) {
|
|
312
|
+
const apps = [];
|
|
313
|
+
const content = await this.listFolderItems(folderId);
|
|
314
|
+
for (const item of content.items || []) {
|
|
315
|
+
const itemType = item.type.toLowerCase();
|
|
316
|
+
if (itemType === 'remote_job') {
|
|
317
|
+
// Found an app
|
|
318
|
+
apps.push({
|
|
319
|
+
id: item.id,
|
|
320
|
+
name: item.name,
|
|
321
|
+
type: item.type,
|
|
322
|
+
reference: item.reference || '',
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
else if (itemType === 'folder') {
|
|
326
|
+
// Recurse into subfolder
|
|
327
|
+
const subApps = await this.listAppsRecursive(item.id);
|
|
328
|
+
apps.push(...subApps);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return apps;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Get app details by reference ID
|
|
335
|
+
*/
|
|
336
|
+
async getApp(referenceId) {
|
|
337
|
+
try {
|
|
338
|
+
const response = await this.client.get(`/remoteJobs/${referenceId}`);
|
|
339
|
+
return response.data;
|
|
340
|
+
}
|
|
341
|
+
catch {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
281
344
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
* Get the Apps folder ID
|
|
293
|
-
*/
|
|
294
|
-
async getAppsFolderId() {
|
|
295
|
-
const content = await this.listFolderItems(null);
|
|
296
|
-
const appsFolder = content.items?.find(
|
|
297
|
-
(item) => item.name.toLowerCase() === "apps" && item.type.toLowerCase() === "folder"
|
|
298
|
-
);
|
|
299
|
-
return appsFolder?.id || null;
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* List all apps (Remote Jobs) on the tenant, including those in subfolders
|
|
303
|
-
*/
|
|
304
|
-
async listApps() {
|
|
305
|
-
const appsFolderId = await this.getAppsFolderId();
|
|
306
|
-
if (!appsFolderId) {
|
|
307
|
-
return [];
|
|
345
|
+
/**
|
|
346
|
+
* Get app by name
|
|
347
|
+
*/
|
|
348
|
+
async getAppByName(name) {
|
|
349
|
+
const apps = await this.listApps();
|
|
350
|
+
const app = apps.find((a) => a.name.toLowerCase() === name.toLowerCase());
|
|
351
|
+
if (!app) {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
return this.getApp(app.reference);
|
|
308
355
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
apps.push({
|
|
321
|
-
id: item.id,
|
|
322
|
-
name: item.name,
|
|
323
|
-
type: item.type,
|
|
324
|
-
reference: item.reference || ""
|
|
356
|
+
/**
|
|
357
|
+
* Create a new app
|
|
358
|
+
*/
|
|
359
|
+
async createApp(name) {
|
|
360
|
+
const appsFolderId = await this.getAppsFolderId();
|
|
361
|
+
if (!appsFolderId) {
|
|
362
|
+
throw new Error('Apps folder not found');
|
|
363
|
+
}
|
|
364
|
+
const response = await this.client.post('/remoteJobs', {
|
|
365
|
+
folderId: appsFolderId,
|
|
366
|
+
name,
|
|
325
367
|
});
|
|
326
|
-
|
|
327
|
-
const subApps = await this.listAppsRecursive(item.id);
|
|
328
|
-
apps.push(...subApps);
|
|
329
|
-
}
|
|
368
|
+
return response.data;
|
|
330
369
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
370
|
+
/**
|
|
371
|
+
* Update an app
|
|
372
|
+
*/
|
|
373
|
+
async updateApp(referenceId, update) {
|
|
374
|
+
await this.client.put(`/remoteJobs/${referenceId}`, {
|
|
375
|
+
...update,
|
|
376
|
+
schedule: null,
|
|
377
|
+
runnerName: null,
|
|
378
|
+
predefinedActions: [],
|
|
379
|
+
});
|
|
380
|
+
// API returns 204 No Content, so fetch the updated app
|
|
381
|
+
const app = await this.getApp(referenceId);
|
|
382
|
+
if (!app) {
|
|
383
|
+
throw new Error('Failed to fetch updated app');
|
|
384
|
+
}
|
|
385
|
+
return app;
|
|
342
386
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Delete an app
|
|
389
|
+
*/
|
|
390
|
+
async deleteApp(referenceId) {
|
|
391
|
+
await this.client.delete(`/remoteJobs/${referenceId}`);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Run an app with arguments
|
|
395
|
+
*/
|
|
396
|
+
async runApp(referenceId, args = {}) {
|
|
397
|
+
const response = await this.client.post(`/remoteJobs/${referenceId}/run`, {
|
|
398
|
+
arguments: args,
|
|
399
|
+
});
|
|
400
|
+
return response.data;
|
|
352
401
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
402
|
+
/**
|
|
403
|
+
* Get script files available for apps (searches all .ts/.js files in Files folder)
|
|
404
|
+
* Returns full path relative to Files/ folder (e.g., "Scripts/test.ts", "Scripts/subfolder/helper.ts")
|
|
405
|
+
*/
|
|
406
|
+
async getScriptFiles() {
|
|
407
|
+
// listFiles already searches recursively, so just filter for .ts/.js files
|
|
408
|
+
const allFiles = await this.listFiles(['Files']);
|
|
409
|
+
return allFiles
|
|
410
|
+
.filter((f) => f.name.endsWith('.ts') || f.name.endsWith('.js'))
|
|
411
|
+
.map((f) => ({
|
|
412
|
+
id: f.reference,
|
|
413
|
+
name: f.path, // Use full path to support scripts in subfolders
|
|
414
|
+
}));
|
|
362
415
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
*/
|
|
372
|
-
async updateApp(referenceId, update) {
|
|
373
|
-
await this.client.put(`/remoteJobs/${referenceId}`, {
|
|
374
|
-
...update,
|
|
375
|
-
schedule: null,
|
|
376
|
-
runnerName: null,
|
|
377
|
-
predefinedActions: []
|
|
378
|
-
});
|
|
379
|
-
const app = await this.getApp(referenceId);
|
|
380
|
-
if (!app) {
|
|
381
|
-
throw new Error("Failed to fetch updated app");
|
|
416
|
+
// ==================== Model Export API ====================
|
|
417
|
+
/**
|
|
418
|
+
* Export the entire model structure - all dimension tables, variables, and configurations.
|
|
419
|
+
* Essential for understanding a tenant's data model.
|
|
420
|
+
*/
|
|
421
|
+
async exportModel() {
|
|
422
|
+
const response = await this.client.post('/model/export');
|
|
423
|
+
return response.data;
|
|
382
424
|
}
|
|
383
|
-
return app;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Delete an app
|
|
387
|
-
*/
|
|
388
|
-
async deleteApp(referenceId) {
|
|
389
|
-
await this.client.delete(`/remoteJobs/${referenceId}`);
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Run an app with arguments
|
|
393
|
-
*/
|
|
394
|
-
async runApp(referenceId, args = {}) {
|
|
395
|
-
const response = await this.client.post(`/remoteJobs/${referenceId}/run`, {
|
|
396
|
-
arguments: args
|
|
397
|
-
});
|
|
398
|
-
return response.data;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Get script files available for apps (searches all .ts/.js files in Files folder)
|
|
402
|
-
* Returns full path relative to Files/ folder (e.g., "Scripts/test.ts", "Scripts/subfolder/helper.ts")
|
|
403
|
-
*/
|
|
404
|
-
async getScriptFiles() {
|
|
405
|
-
const allFiles = await this.listFiles(["Files"]);
|
|
406
|
-
return allFiles.filter((f) => f.name.endsWith(".ts") || f.name.endsWith(".js")).map((f) => ({
|
|
407
|
-
id: f.reference,
|
|
408
|
-
name: f.path
|
|
409
|
-
// Use full path to support scripts in subfolders
|
|
410
|
-
}));
|
|
411
|
-
}
|
|
412
|
-
// ==================== Model Export API ====================
|
|
413
|
-
/**
|
|
414
|
-
* Export the entire model structure - all dimension tables, variables, and configurations.
|
|
415
|
-
* Essential for understanding a tenant's data model.
|
|
416
|
-
*/
|
|
417
|
-
async exportModel() {
|
|
418
|
-
const response = await this.client.post("/model/export");
|
|
419
|
-
return response.data;
|
|
420
|
-
}
|
|
421
425
|
}
|
|
422
|
-
|
|
423
|
-
0 && (module.exports = {
|
|
424
|
-
FarseerApi
|
|
425
|
-
});
|
|
426
|
-
//# sourceMappingURL=farseerApi.js.map
|
|
426
|
+
exports.FarseerApi = FarseerApi;
|