farseer-cli 1.0.8 → 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 (41) hide show
  1. package/dist/commands/app.js +377 -0
  2. package/dist/commands/apps.js +91 -0
  3. package/dist/commands/checkout.js +164 -0
  4. package/dist/commands/config.js +141 -0
  5. package/dist/commands/diff.js +210 -0
  6. package/dist/commands/dimensions.js +130 -0
  7. package/dist/commands/files.js +88 -0
  8. package/dist/commands/install.js +82 -0
  9. package/dist/commands/list.js +77 -0
  10. package/dist/commands/login.js +109 -0
  11. package/dist/commands/logout.js +44 -0
  12. package/dist/commands/mcp-server.js +26 -0
  13. package/dist/commands/model.js +181 -0
  14. package/dist/commands/pull.js +286 -0
  15. package/dist/commands/push.js +235 -0
  16. package/dist/commands/run.js +336 -0
  17. package/dist/commands/status.js +178 -0
  18. package/dist/commands/variables.js +200 -0
  19. package/dist/commands/whoami.js +47 -0
  20. package/dist/index.js +163 -0
  21. package/dist/mcp/index.js +19 -0
  22. package/dist/mcp/prompts/workflows.js +403 -0
  23. package/dist/mcp/resources/documentation.js +158 -0
  24. package/dist/mcp/server.js +36 -0
  25. package/dist/mcp/tools/appTools.js +348 -0
  26. package/dist/mcp/tools/authTools.js +152 -0
  27. package/dist/mcp/tools/dataTools.js +358 -0
  28. package/dist/mcp/tools/modelTools.js +293 -0
  29. package/dist/mcp/tools/runTools.js +239 -0
  30. package/dist/mcp/tools/syncTools.js +383 -0
  31. package/dist/mcp/utils/helpers.js +142 -0
  32. package/dist/services/appSyncService.js +458 -0
  33. package/dist/services/configService.js +186 -0
  34. package/dist/services/farseerApi.js +426 -0
  35. package/dist/services/farseerFactory.js +297 -0
  36. package/dist/services/farseerService.js +647 -0
  37. package/dist/services/syncService.js +764 -0
  38. package/dist/utils/constants.js +21 -0
  39. package/dist/utils/helpers.js +446 -0
  40. package/dist/utils/logger.js +45 -0
  41. package/package.json +8 -1
@@ -0,0 +1,647 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.FarseerService = void 0;
37
+ exports.loginWithPassword = loginWithPassword;
38
+ exports.loginWithBrowser = loginWithBrowser;
39
+ exports.refreshAccessToken = refreshAccessToken;
40
+ const farseer = __importStar(require("farseer-client"));
41
+ const configService_1 = require("./configService");
42
+ class FarseerService {
43
+ constructor(credential) {
44
+ this.credential = credential;
45
+ this.client = new farseer.FarseerClient({
46
+ basePath: credential.basePath,
47
+ headers: {
48
+ 'X-TENANT-ID': credential.tenantId,
49
+ 'X-API-KEY': credential.apiKey,
50
+ },
51
+ });
52
+ }
53
+ static fromUserAuth(tenant, basePath) {
54
+ const auth = (0, configService_1.getUserAuth)();
55
+ if (!auth)
56
+ return null;
57
+ const service = new FarseerService({
58
+ type: 'apiKey',
59
+ tenantId: tenant,
60
+ apiKey: '',
61
+ basePath: basePath,
62
+ });
63
+ // Override with access token
64
+ service.client = new farseer.FarseerClient({
65
+ basePath: basePath,
66
+ headers: {
67
+ 'X-TENANT-ID': tenant,
68
+ },
69
+ accessToken: auth.accessToken,
70
+ });
71
+ return service;
72
+ }
73
+ async testConnection() {
74
+ try {
75
+ // Try to get the Files folder to test connection
76
+ await this.client.getItemByPath(['Files']);
77
+ return true;
78
+ }
79
+ catch {
80
+ return false;
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);
144
+ }
145
+ async ensureFolderPath(folderPath) {
146
+ const currentPath = [];
147
+ for (const segment of folderPath) {
148
+ currentPath.push(segment);
149
+ try {
150
+ await this.client.getItemByPath(currentPath);
151
+ }
152
+ catch {
153
+ // Folder doesn't exist, create it
154
+ if (currentPath.length > 1) {
155
+ const parentPath = currentPath.slice(0, -1);
156
+ const parent = await this.client.getItemByPath(parentPath);
157
+ await this.client.folders.create({
158
+ parentId: parent.id,
159
+ name: segment,
160
+ allowedTypes: [],
161
+ });
162
+ }
163
+ }
164
+ }
165
+ }
166
+ async getFileByPath(filePath) {
167
+ const pathParts = ['Files', ...filePath.split('/')];
168
+ const fileName = pathParts.pop();
169
+ const folderPath = pathParts;
170
+ try {
171
+ const folder = await this.client.getItemByPath(folderPath);
172
+ const folderContent = await this.client.folders.listItemsBatch([{ id: folder.id }]);
173
+ for (const item of folderContent[0]?.items || []) {
174
+ if (item.name === fileName && item.type === farseer.FolderItemType.FarseerFile && 'reference' in item) {
175
+ return {
176
+ name: item.name,
177
+ path: filePath,
178
+ reference: item.reference,
179
+ };
180
+ }
181
+ }
182
+ }
183
+ catch {
184
+ return null;
185
+ }
186
+ return null;
187
+ }
188
+ async getFileMetadata(reference) {
189
+ try {
190
+ const metadata = await this.client.farseerFiles.getMetadata(reference);
191
+ return {
192
+ uploadTime: metadata.uploadTime?.toISOString(),
193
+ uploader: metadata.uploader
194
+ ? {
195
+ id: metadata.uploader.id,
196
+ email: metadata.uploader.email || '',
197
+ firstName: metadata.uploader.firstName || '',
198
+ lastName: metadata.uploader.lastName || '',
199
+ }
200
+ : undefined,
201
+ size: metadata.size,
202
+ };
203
+ }
204
+ catch (error) {
205
+ // Metadata fetch failed - non-critical, continue without it
206
+ return null;
207
+ }
208
+ }
209
+ async getFileContentAsBuffer(reference) {
210
+ const blob = await this.client.farseerFiles.get(reference);
211
+ const arrayBuffer = await blob.arrayBuffer();
212
+ return Buffer.from(arrayBuffer);
213
+ }
214
+ isTextFile(filename) {
215
+ const ext = filename.toLowerCase().split('.').pop() || '';
216
+ return ['ts', 'js', 'mjs', 'cjs', 'json', 'txt', 'md', 'csv', 'xml', 'html', 'css', 'yaml', 'yml'].includes(ext);
217
+ }
218
+ isBinaryFile(filename) {
219
+ return !this.isTextFile(filename);
220
+ }
221
+ // ==================== Apps (Remote Jobs) API ====================
222
+ /**
223
+ * List all apps (Remote Jobs) on the tenant
224
+ */
225
+ async listApps() {
226
+ const response = await this.apiRequest('/remoteJobs', 'GET');
227
+ return response.map((app) => ({
228
+ id: app.id,
229
+ name: app.name,
230
+ type: 'REMOTE_JOB',
231
+ reference: String(app.id),
232
+ }));
233
+ }
234
+ /**
235
+ * Get app details by reference ID
236
+ */
237
+ async getApp(referenceId) {
238
+ try {
239
+ return await this.apiRequest(`/remoteJobs/${referenceId}`, 'GET');
240
+ }
241
+ catch {
242
+ return null;
243
+ }
244
+ }
245
+ /**
246
+ * Get app by name
247
+ */
248
+ async getAppByName(name) {
249
+ const apps = await this.listApps();
250
+ const app = apps.find((a) => a.name.toLowerCase() === name.toLowerCase());
251
+ if (!app) {
252
+ return null;
253
+ }
254
+ return this.getApp(app.reference);
255
+ }
256
+ /**
257
+ * Create a new app
258
+ */
259
+ async createApp(name) {
260
+ // Get Apps folder ID first
261
+ const appsFolderId = await this.getAppsFolderId();
262
+ if (!appsFolderId) {
263
+ throw new Error('Apps folder not found');
264
+ }
265
+ return await this.apiRequest('/remoteJobs', 'POST', {
266
+ folderId: appsFolderId,
267
+ name,
268
+ });
269
+ }
270
+ /**
271
+ * Update an app
272
+ */
273
+ async updateApp(referenceId, update) {
274
+ await this.apiRequest(`/remoteJobs/${referenceId}`, 'PUT', {
275
+ ...update,
276
+ schedule: null,
277
+ runnerName: null,
278
+ predefinedActions: [],
279
+ });
280
+ // API returns 204 No Content, so fetch the updated app
281
+ const app = await this.getApp(referenceId);
282
+ if (!app) {
283
+ throw new Error('Failed to fetch updated app');
284
+ }
285
+ return app;
286
+ }
287
+ /**
288
+ * Delete an app
289
+ */
290
+ async deleteApp(referenceId) {
291
+ await this.apiRequest(`/remoteJobs/${referenceId}`, 'DELETE');
292
+ }
293
+ /**
294
+ * Get script files available for apps
295
+ */
296
+ async getScriptFiles() {
297
+ const allFiles = await this.listFiles(['Files']);
298
+ return allFiles
299
+ .filter((f) => f.name.endsWith('.ts') || f.name.endsWith('.js'))
300
+ .map((f) => ({
301
+ id: f.reference,
302
+ name: f.name,
303
+ }));
304
+ }
305
+ /**
306
+ * Export the entire model structure
307
+ */
308
+ async exportModel() {
309
+ return this.apiRequest('/model/export', 'POST');
310
+ }
311
+ /**
312
+ * Get the Apps folder ID
313
+ */
314
+ async getAppsFolderId() {
315
+ try {
316
+ const item = await this.client.getItemByPath(['Apps']);
317
+ return item.id;
318
+ }
319
+ catch {
320
+ return null;
321
+ }
322
+ }
323
+ /**
324
+ * Make a direct API request (for endpoints not in farseer-client)
325
+ */
326
+ async apiRequest(endpoint, method, body) {
327
+ const url = `${this.credential.basePath}${endpoint}`;
328
+ const headers = {
329
+ 'Content-Type': 'application/json',
330
+ 'X-TENANT-ID': this.credential.tenantId,
331
+ 'X-API-KEY': this.credential.apiKey,
332
+ 'x-api-version': '3.3.0',
333
+ };
334
+ const response = await fetch(url, {
335
+ method,
336
+ headers,
337
+ body: body ? JSON.stringify(body) : undefined,
338
+ });
339
+ if (!response.ok) {
340
+ throw new Error(`HTTP ${response.status}: ${await response.text()}`);
341
+ }
342
+ if (response.status === 204) {
343
+ return undefined;
344
+ }
345
+ return response.json();
346
+ }
347
+ }
348
+ exports.FarseerService = FarseerService;
349
+ async function loginWithPassword(email, password) {
350
+ const tokenUrl = 'https://login.farseer.io/auth/realms/master/protocol/openid-connect/token';
351
+ try {
352
+ const response = await fetch(tokenUrl, {
353
+ method: 'POST',
354
+ headers: {
355
+ 'Content-Type': 'application/x-www-form-urlencoded',
356
+ },
357
+ body: new URLSearchParams({
358
+ grant_type: 'password',
359
+ client_id: 'security-admin-console',
360
+ username: email,
361
+ password: password,
362
+ }),
363
+ });
364
+ if (!response.ok) {
365
+ return null;
366
+ }
367
+ const data = (await response.json());
368
+ return {
369
+ accessToken: data.access_token,
370
+ refreshToken: data.refresh_token,
371
+ expiresIn: data.expires_in,
372
+ };
373
+ }
374
+ catch {
375
+ return null;
376
+ }
377
+ }
378
+ function getErrorPage(title, message) {
379
+ return `
380
+ <html>
381
+ <head>
382
+ <title>Farseer CLI - Error</title>
383
+ <style>
384
+ * { margin: 0; padding: 0; box-sizing: border-box; }
385
+ body {
386
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
387
+ background: #fafafa;
388
+ min-height: 100vh;
389
+ display: flex;
390
+ align-items: center;
391
+ justify-content: center;
392
+ }
393
+ .container {
394
+ text-align: center;
395
+ padding: 48px;
396
+ }
397
+ .error-icon {
398
+ width: 80px;
399
+ height: 80px;
400
+ border-radius: 50%;
401
+ background: #ef4444;
402
+ display: flex;
403
+ align-items: center;
404
+ justify-content: center;
405
+ margin: 0 auto 24px;
406
+ }
407
+ .error-icon svg {
408
+ width: 40px;
409
+ height: 40px;
410
+ stroke: white;
411
+ stroke-width: 3;
412
+ fill: none;
413
+ }
414
+ h1 {
415
+ color: #18181b;
416
+ font-size: 24px;
417
+ font-weight: 600;
418
+ margin-bottom: 8px;
419
+ }
420
+ p {
421
+ color: #71717a;
422
+ font-size: 15px;
423
+ }
424
+ </style>
425
+ </head>
426
+ <body>
427
+ <div class="container">
428
+ <div class="error-icon">
429
+ <svg viewBox="0 0 24 24">
430
+ <line x1="18" y1="6" x2="6" y2="18"></line>
431
+ <line x1="6" y1="6" x2="18" y2="18"></line>
432
+ </svg>
433
+ </div>
434
+ <h1>${title}</h1>
435
+ <p>${message}</p>
436
+ <p style="margin-top: 16px;">You can close this window.</p>
437
+ </div>
438
+ </body>
439
+ </html>
440
+ `;
441
+ }
442
+ // Browser-based OAuth login with PKCE
443
+ async function loginWithBrowser(realm = 'master') {
444
+ const http = await Promise.resolve().then(() => __importStar(require('http')));
445
+ const crypto = await Promise.resolve().then(() => __importStar(require('crypto')));
446
+ const { exec } = await Promise.resolve().then(() => __importStar(require('child_process')));
447
+ const { promisify } = await Promise.resolve().then(() => __importStar(require('util')));
448
+ const execAsync = promisify(exec);
449
+ const KEYCLOAK_BASE = `https://login.farseer.io/auth/realms/${realm}/protocol/openid-connect`;
450
+ const CLIENT_ID = 'auth'; // Use auth client with full scope access
451
+ const REDIRECT_PORT = 8787;
452
+ const REDIRECT_URI = `http://localhost:${REDIRECT_PORT}/callback`;
453
+ // Generate PKCE code verifier and challenge
454
+ const codeVerifier = crypto.randomBytes(32).toString('base64url');
455
+ const codeChallenge = crypto.createHash('sha256').update(codeVerifier).digest('base64url');
456
+ // Generate state for CSRF protection
457
+ const state = crypto.randomBytes(16).toString('hex');
458
+ return new Promise((resolve) => {
459
+ const server = http.createServer(async (req, res) => {
460
+ const url = new URL(req.url || '', `http://localhost:${REDIRECT_PORT}`);
461
+ if (url.pathname === '/callback') {
462
+ const code = url.searchParams.get('code');
463
+ const returnedState = url.searchParams.get('state');
464
+ const error = url.searchParams.get('error');
465
+ if (error) {
466
+ res.writeHead(200, { 'Content-Type': 'text/html' });
467
+ res.end(getErrorPage('Login Failed', `Error: ${error}`));
468
+ server.close();
469
+ resolve(null);
470
+ return;
471
+ }
472
+ if (!code || returnedState !== state) {
473
+ res.writeHead(400, { 'Content-Type': 'text/html' });
474
+ res.end(getErrorPage('Invalid Response', 'Missing code or state mismatch.'));
475
+ server.close();
476
+ resolve(null);
477
+ return;
478
+ }
479
+ // Exchange code for tokens
480
+ try {
481
+ const tokenResponse = await fetch(`${KEYCLOAK_BASE}/token`, {
482
+ method: 'POST',
483
+ headers: {
484
+ 'Content-Type': 'application/x-www-form-urlencoded',
485
+ },
486
+ body: new URLSearchParams({
487
+ grant_type: 'authorization_code',
488
+ client_id: CLIENT_ID,
489
+ code: code,
490
+ redirect_uri: REDIRECT_URI,
491
+ code_verifier: codeVerifier,
492
+ }),
493
+ });
494
+ if (!tokenResponse.ok) {
495
+ throw new Error('Token exchange failed');
496
+ }
497
+ const data = (await tokenResponse.json());
498
+ res.writeHead(200, { 'Content-Type': 'text/html' });
499
+ res.end(`
500
+ <html>
501
+ <head>
502
+ <title>Farseer CLI - Login</title>
503
+ <style>
504
+ * { margin: 0; padding: 0; box-sizing: border-box; }
505
+ body {
506
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
507
+ background: #fafafa;
508
+ min-height: 100vh;
509
+ display: flex;
510
+ align-items: center;
511
+ justify-content: center;
512
+ }
513
+ .container {
514
+ text-align: center;
515
+ padding: 48px;
516
+ }
517
+ .checkmark {
518
+ width: 80px;
519
+ height: 80px;
520
+ border-radius: 50%;
521
+ background: #22c55e;
522
+ display: flex;
523
+ align-items: center;
524
+ justify-content: center;
525
+ margin: 0 auto 24px;
526
+ animation: scale-in 0.3s ease-out;
527
+ }
528
+ .checkmark svg {
529
+ width: 40px;
530
+ height: 40px;
531
+ stroke: white;
532
+ stroke-width: 3;
533
+ fill: none;
534
+ animation: draw 0.4s ease-out 0.2s forwards;
535
+ stroke-dasharray: 50;
536
+ stroke-dashoffset: 50;
537
+ }
538
+ @keyframes scale-in {
539
+ from { transform: scale(0); }
540
+ to { transform: scale(1); }
541
+ }
542
+ @keyframes draw {
543
+ to { stroke-dashoffset: 0; }
544
+ }
545
+ h1 {
546
+ color: #18181b;
547
+ font-size: 24px;
548
+ font-weight: 600;
549
+ margin-bottom: 8px;
550
+ }
551
+ p {
552
+ color: #71717a;
553
+ font-size: 15px;
554
+ }
555
+ </style>
556
+ </head>
557
+ <body>
558
+ <div class="container">
559
+ <div class="checkmark">
560
+ <svg viewBox="0 0 24 24">
561
+ <polyline points="20 6 9 17 4 12"></polyline>
562
+ </svg>
563
+ </div>
564
+ <h1>Login Successful</h1>
565
+ <p>You can close this window and return to the terminal.</p>
566
+ </div>
567
+ </body>
568
+ </html>
569
+ `);
570
+ server.close();
571
+ resolve({
572
+ accessToken: data.access_token,
573
+ refreshToken: data.refresh_token,
574
+ expiresIn: data.expires_in,
575
+ });
576
+ }
577
+ catch {
578
+ res.writeHead(500, { 'Content-Type': 'text/html' });
579
+ res.end(getErrorPage('Token Exchange Failed', 'Could not complete login.'));
580
+ server.close();
581
+ resolve(null);
582
+ }
583
+ }
584
+ });
585
+ server.listen(REDIRECT_PORT, async () => {
586
+ // Build authorization URL
587
+ const authUrl = new URL(`${KEYCLOAK_BASE}/auth`);
588
+ authUrl.searchParams.set('client_id', CLIENT_ID);
589
+ authUrl.searchParams.set('redirect_uri', REDIRECT_URI);
590
+ authUrl.searchParams.set('response_type', 'code');
591
+ authUrl.searchParams.set('scope', 'openid offline_access');
592
+ authUrl.searchParams.set('state', state);
593
+ authUrl.searchParams.set('code_challenge', codeChallenge);
594
+ authUrl.searchParams.set('code_challenge_method', 'S256');
595
+ // Open browser
596
+ const url = authUrl.toString();
597
+ try {
598
+ if (process.platform === 'darwin') {
599
+ await execAsync(`open "${url}"`);
600
+ }
601
+ else if (process.platform === 'win32') {
602
+ await execAsync(`start "${url}"`);
603
+ }
604
+ else {
605
+ await execAsync(`xdg-open "${url}"`);
606
+ }
607
+ }
608
+ catch {
609
+ // If we can't open browser, show URL to user
610
+ console.log(`\nOpen this URL in your browser:\n${url}\n`);
611
+ }
612
+ });
613
+ // Timeout after 5 minutes
614
+ setTimeout(() => {
615
+ server.close();
616
+ resolve(null);
617
+ }, 5 * 60 * 1000);
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 {
639
+ accessToken: data.access_token,
640
+ refreshToken: data.refresh_token,
641
+ expiresIn: data.expires_in,
642
+ };
643
+ }
644
+ catch {
645
+ return null;
646
+ }
647
+ }