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.
Files changed (81) hide show
  1. package/dist/commands/app.js +344 -316
  2. package/dist/commands/apps.js +83 -103
  3. package/dist/commands/checkout.js +156 -134
  4. package/dist/commands/config.js +126 -124
  5. package/dist/commands/diff.js +194 -169
  6. package/dist/commands/dimensions.js +122 -137
  7. package/dist/commands/files.js +77 -88
  8. package/dist/commands/install.js +77 -74
  9. package/dist/commands/list.js +74 -89
  10. package/dist/commands/login.js +101 -126
  11. package/dist/commands/logout.js +42 -57
  12. package/dist/commands/mcp-server.js +24 -39
  13. package/dist/commands/model.js +176 -184
  14. package/dist/commands/pull.js +276 -248
  15. package/dist/commands/push.js +222 -200
  16. package/dist/commands/run.js +322 -274
  17. package/dist/commands/status.js +170 -147
  18. package/dist/commands/variables.js +192 -168
  19. package/dist/commands/whoami.js +45 -61
  20. package/dist/index.js +115 -117
  21. package/dist/mcp/index.js +17 -33
  22. package/dist/mcp/prompts/workflows.js +146 -191
  23. package/dist/mcp/resources/documentation.js +149 -158
  24. package/dist/mcp/server.js +34 -50
  25. package/dist/mcp/tools/appTools.js +278 -307
  26. package/dist/mcp/tools/authTools.js +123 -130
  27. package/dist/mcp/tools/dataTools.js +271 -275
  28. package/dist/mcp/tools/modelTools.js +233 -265
  29. package/dist/mcp/tools/runTools.js +205 -199
  30. package/dist/mcp/tools/syncTools.js +315 -341
  31. package/dist/mcp/utils/helpers.js +124 -117
  32. package/dist/services/appSyncService.js +438 -379
  33. package/dist/services/configService.js +144 -154
  34. package/dist/services/farseerApi.js +401 -401
  35. package/dist/services/farseerFactory.js +274 -208
  36. package/dist/services/farseerService.js +488 -455
  37. package/dist/services/syncService.js +732 -657
  38. package/dist/utils/constants.js +20 -45
  39. package/dist/utils/helpers.js +366 -333
  40. package/dist/utils/logger.js +43 -74
  41. package/package.json +8 -1
  42. package/dist/commands/app.js.map +0 -7
  43. package/dist/commands/apps.js.map +0 -7
  44. package/dist/commands/checkout.js.map +0 -7
  45. package/dist/commands/config.js.map +0 -7
  46. package/dist/commands/diff.js.map +0 -7
  47. package/dist/commands/dimensions.js.map +0 -7
  48. package/dist/commands/files.js.map +0 -7
  49. package/dist/commands/install.js.map +0 -7
  50. package/dist/commands/list.js.map +0 -7
  51. package/dist/commands/login.js.map +0 -7
  52. package/dist/commands/logout.js.map +0 -7
  53. package/dist/commands/mcp-server.js.map +0 -7
  54. package/dist/commands/model.js.map +0 -7
  55. package/dist/commands/pull.js.map +0 -7
  56. package/dist/commands/push.js.map +0 -7
  57. package/dist/commands/run.js.map +0 -7
  58. package/dist/commands/status.js.map +0 -7
  59. package/dist/commands/variables.js.map +0 -7
  60. package/dist/commands/whoami.js.map +0 -7
  61. package/dist/index.js.map +0 -7
  62. package/dist/mcp/index.js.map +0 -7
  63. package/dist/mcp/prompts/workflows.js.map +0 -7
  64. package/dist/mcp/resources/documentation.js.map +0 -7
  65. package/dist/mcp/server.js.map +0 -7
  66. package/dist/mcp/tools/appTools.js.map +0 -7
  67. package/dist/mcp/tools/authTools.js.map +0 -7
  68. package/dist/mcp/tools/dataTools.js.map +0 -7
  69. package/dist/mcp/tools/modelTools.js.map +0 -7
  70. package/dist/mcp/tools/runTools.js.map +0 -7
  71. package/dist/mcp/tools/syncTools.js.map +0 -7
  72. package/dist/mcp/utils/helpers.js.map +0 -7
  73. package/dist/services/appSyncService.js.map +0 -7
  74. package/dist/services/configService.js.map +0 -7
  75. package/dist/services/farseerApi.js.map +0 -7
  76. package/dist/services/farseerFactory.js.map +0 -7
  77. package/dist/services/farseerService.js.map +0 -7
  78. package/dist/services/syncService.js.map +0 -7
  79. package/dist/utils/constants.js.map +0 -7
  80. package/dist/utils/helpers.js.map +0 -7
  81. package/dist/utils/logger.js.map +0 -7
@@ -1,426 +1,426 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
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
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
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
- constructor(accessToken, tenant, tenantId) {
38
- this.isRefreshing = false;
39
- this.refreshSubscribers = [];
40
- this.tenant = tenant;
41
- this.tenantId = tenantId || tenant;
42
- const credential = (0, import_configService.getCredential)(tenant);
43
- const basePath = credential?.basePath || `https://${tenant}.farseer.io/api/v3`;
44
- this.client = import_axios.default.create({
45
- baseURL: basePath,
46
- headers: {
47
- "Authorization": `Bearer ${accessToken}`,
48
- "Content-Type": "application/json",
49
- "x-api-version": "3.3.0",
50
- "X-TENANT-ID": this.tenantId
51
- }
52
- });
53
- this.client.interceptors.response.use(
54
- (response) => response,
55
- async (error) => {
56
- const originalRequest = error.config;
57
- if (error.response?.status === 401 && !originalRequest._retry) {
58
- originalRequest._retry = true;
59
- if (this.isRefreshing) {
60
- return new Promise((resolve) => {
61
- this.refreshSubscribers.push((token) => {
62
- originalRequest.headers["Authorization"] = `Bearer ${token}`;
63
- resolve(this.client(originalRequest));
64
- });
65
- });
66
- }
67
- this.isRefreshing = true;
68
- try {
69
- const auth = (0, import_configService.getUserAuth)();
70
- if (!auth?.refreshToken) {
71
- throw new Error("No refresh token available");
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
- const refreshed = await (0, import_farseerService.refreshAccessToken)(auth.refreshToken, auth.realm || "master");
74
- if (!refreshed) {
75
- throw new Error("Token refresh failed");
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
- return Promise.reject(error);
96
- }
97
- );
98
- }
99
- /**
100
- * Update the access token (used when token is refreshed)
101
- */
102
- updateAccessToken(newToken) {
103
- this.client.defaults.headers["Authorization"] = `Bearer ${newToken}`;
104
- }
105
- async testConnection() {
106
- try {
107
- await this.getItemByPath(["Files"]);
108
- return true;
109
- } catch {
110
- return false;
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
- async getFilesFolder() {
114
- try {
115
- const item = await this.getItemByPath(["Files"]);
116
- return {
117
- id: item.id,
118
- name: item.name,
119
- type: item.type
120
- };
121
- } catch {
122
- return null;
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
- async listFolderItems(folderId) {
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
- if (currentId === null) {
146
- throw new Error("Path is empty");
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
- return { id: currentId, name: path[path.length - 1], type: "folder" };
149
- }
150
- async listFiles(folderPath = ["Files"]) {
151
- const files = [];
152
- try {
153
- const folder = await this.getItemByPath(folderPath);
154
- const folderContent = await this.listFolderItems(folder.id);
155
- for (const item of folderContent.items || []) {
156
- const itemPath = [...folderPath.slice(1), item.name].join("/");
157
- const itemType = item.type.toLowerCase();
158
- if (itemType === "folder") {
159
- const subFiles = await this.listFiles([...folderPath, item.name]);
160
- files.push(...subFiles);
161
- } else if ((itemType === "farseer-file" || itemType === "farseer_file") && item.reference) {
162
- files.push({
163
- name: item.name,
164
- path: itemPath,
165
- reference: item.reference
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
- } catch (error) {
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
- return files;
184
- }
185
- async getFileContent(reference) {
186
- const response = await this.client.get(`/farseerFiles/${reference}`, {
187
- responseType: "text"
188
- });
189
- return response.data;
190
- }
191
- async getFileContentAsBuffer(reference) {
192
- const response = await this.client.get(`/farseerFiles/${reference}`, {
193
- responseType: "arraybuffer"
194
- });
195
- return Buffer.from(response.data);
196
- }
197
- async createFile(content, fileName, folderPath = ["Files"]) {
198
- await this.ensureFolderPath(folderPath);
199
- const folder = await this.getItemByPath(folderPath);
200
- const formData = new FormData();
201
- const blob = content instanceof Buffer ? new Blob([content]) : new Blob([content]);
202
- formData.append("file", blob, fileName);
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
- async getFileByPath(filePath) {
244
- const pathParts = ["Files", ...filePath.split("/")];
245
- const fileName = pathParts.pop();
246
- const folderPath = pathParts;
247
- try {
248
- const folder = await this.getItemByPath(folderPath);
249
- const folderContent = await this.listFolderItems(folder.id);
250
- for (const item of folderContent.items || []) {
251
- const itemType = item.type.toLowerCase();
252
- if (item.name === fileName && (itemType === "farseer-file" || itemType === "farseer_file") && item.reference) {
253
- return {
254
- name: item.name,
255
- path: filePath,
256
- reference: item.reference
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
- return null;
264
- }
265
- async getFileMetadata(reference) {
266
- try {
267
- const response = await this.axios.get(`/farseerFiles/${reference}/metadata`);
268
- const data = response.data;
269
- return {
270
- uploadTime: data.uploadTime,
271
- uploader: data.uploader ? {
272
- id: data.uploader.id,
273
- email: data.uploader.email || "",
274
- firstName: data.uploader.firstName || "",
275
- lastName: data.uploader.lastName || ""
276
- } : void 0,
277
- size: data.size
278
- };
279
- } catch (error) {
280
- return null;
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
- isTextFile(filename) {
284
- const ext = filename.toLowerCase().split(".").pop() || "";
285
- return ["ts", "js", "mjs", "cjs", "json", "txt", "md", "csv", "xml", "html", "css", "yaml", "yml"].includes(ext);
286
- }
287
- isBinaryFile(filename) {
288
- return !this.isTextFile(filename);
289
- }
290
- // ==================== Apps (Remote Jobs) API ====================
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
- return this.listAppsRecursive(appsFolderId);
310
- }
311
- /**
312
- * Recursively list all apps in a folder and its subfolders
313
- */
314
- async listAppsRecursive(folderId) {
315
- const apps = [];
316
- const content = await this.listFolderItems(folderId);
317
- for (const item of content.items || []) {
318
- const itemType = item.type.toLowerCase();
319
- if (itemType === "remote_job") {
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
- } else if (itemType === "folder") {
327
- const subApps = await this.listAppsRecursive(item.id);
328
- apps.push(...subApps);
329
- }
368
+ return response.data;
330
369
  }
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
- } catch {
341
- return null;
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
- * Get app by name
346
- */
347
- async getAppByName(name) {
348
- const apps = await this.listApps();
349
- const app = apps.find((a) => a.name.toLowerCase() === name.toLowerCase());
350
- if (!app) {
351
- return null;
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
- return this.getApp(app.reference);
354
- }
355
- /**
356
- * Create a new app
357
- */
358
- async createApp(name) {
359
- const appsFolderId = await this.getAppsFolderId();
360
- if (!appsFolderId) {
361
- throw new Error("Apps folder not found");
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
- const response = await this.client.post("/remoteJobs", {
364
- folderId: appsFolderId,
365
- name
366
- });
367
- return response.data;
368
- }
369
- /**
370
- * Update an app
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
- // Annotate the CommonJS export names for ESM import in node:
423
- 0 && (module.exports = {
424
- FarseerApi
425
- });
426
- //# sourceMappingURL=farseerApi.js.map
426
+ exports.FarseerApi = FarseerApi;