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,399 +1,458 @@
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 });
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 appSyncService_exports = {};
29
- __export(appSyncService_exports, {
30
- AppSyncService: () => AppSyncService
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;
31
17
  });
32
- module.exports = __toCommonJS(appSyncService_exports);
33
- var fs = __toESM(require("fs"));
34
- var path = __toESM(require("path"));
35
- var import_helpers = require("../utils/helpers");
36
- var import_logger = require("../utils/logger");
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.AppSyncService = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const helpers_1 = require("../utils/helpers");
40
+ const logger_1 = require("../utils/logger");
41
+ /**
42
+ * Sanitize Croatian diacritics and other special characters to ASCII equivalents
43
+ */
37
44
  function sanitizeDiacritics(text) {
38
- const diacriticMap = {
39
- // Croatian
40
- "\u010D": "c",
41
- "\u010C": "C",
42
- "\u0107": "c",
43
- "\u0106": "C",
44
- "\u0161": "s",
45
- "\u0160": "S",
46
- "\u017E": "z",
47
- "\u017D": "Z",
48
- "\u0111": "d",
49
- "\u0110": "D",
50
- // German/Other common
51
- "\xE4": "a",
52
- "\xC4": "A",
53
- "\xF6": "o",
54
- "\xD6": "O",
55
- "\xFC": "u",
56
- "\xDC": "U",
57
- "\xDF": "ss",
58
- // Polish
59
- "\u0105": "a",
60
- "\u0104": "A",
61
- "\u0119": "e",
62
- "\u0118": "E",
63
- "\u0142": "l",
64
- "\u0141": "L",
65
- "\u0144": "n",
66
- "\u0143": "N",
67
- "\xF3": "o",
68
- "\xD3": "O",
69
- "\u015B": "s",
70
- "\u015A": "S",
71
- "\u017A": "z",
72
- "\u0179": "Z",
73
- "\u017C": "z",
74
- "\u017B": "Z",
75
- // French/Spanish
76
- "\xE0": "a",
77
- "\xE1": "a",
78
- "\xE2": "a",
79
- "\xE8": "e",
80
- "\xE9": "e",
81
- "\xEA": "e",
82
- "\xEB": "e",
83
- "\xEC": "i",
84
- "\xED": "i",
85
- "\xEE": "i",
86
- "\xEF": "i",
87
- "\xF2": "o",
88
- "\xF4": "o",
89
- "\xF9": "u",
90
- "\xFA": "u",
91
- "\xFB": "u",
92
- "\xF1": "n",
93
- "\xD1": "N",
94
- "\xE7": "c",
95
- "\xC7": "C"
96
- };
97
- return text.split("").map((char) => diacriticMap[char] || char).join("");
45
+ const diacriticMap = {
46
+ // Croatian
47
+ č: 'c',
48
+ Č: 'C',
49
+ ć: 'c',
50
+ Ć: 'C',
51
+ š: 's',
52
+ Š: 'S',
53
+ ž: 'z',
54
+ Ž: 'Z',
55
+ đ: 'd',
56
+ Đ: 'D',
57
+ // German/Other common
58
+ ä: 'a',
59
+ Ä: 'A',
60
+ ö: 'o',
61
+ Ö: 'O',
62
+ ü: 'u',
63
+ Ü: 'U',
64
+ ß: 'ss',
65
+ // Polish
66
+ ą: 'a',
67
+ Ą: 'A',
68
+ ę: 'e',
69
+ Ę: 'E',
70
+ ł: 'l',
71
+ Ł: 'L',
72
+ ń: 'n',
73
+ Ń: 'N',
74
+ ó: 'o',
75
+ Ó: 'O',
76
+ ś: 's',
77
+ Ś: 'S',
78
+ ź: 'z',
79
+ Ź: 'Z',
80
+ ż: 'z',
81
+ Ż: 'Z',
82
+ // French/Spanish
83
+ à: 'a',
84
+ á: 'a',
85
+ â: 'a',
86
+ è: 'e',
87
+ é: 'e',
88
+ ê: 'e',
89
+ ë: 'e',
90
+ ì: 'i',
91
+ í: 'i',
92
+ î: 'i',
93
+ ï: 'i',
94
+ ò: 'o',
95
+ ô: 'o',
96
+ ù: 'u',
97
+ ú: 'u',
98
+ û: 'u',
99
+ ñ: 'n',
100
+ Ñ: 'N',
101
+ ç: 'c',
102
+ Ç: 'C',
103
+ };
104
+ return text
105
+ .split('')
106
+ .map((char) => diacriticMap[char] || char)
107
+ .join('');
98
108
  }
109
+ /**
110
+ * Service for syncing app configurations between local JSON files and remote Farseer instance
111
+ */
99
112
  class AppSyncService {
100
- constructor(tenant, api) {
101
- this.api = api;
102
- this.appsDir = (0, import_helpers.getTenantAppsDir)(tenant);
103
- }
104
- /**
105
- * Get filename for an app (keep original name, just sanitize for filesystem)
106
- */
107
- getAppFilename(name) {
108
- return sanitizeDiacritics(name).replace(/[<>:"/\\|?*]/g, "").trim() + ".json";
109
- }
110
- /**
111
- * Load all local app configs
112
- */
113
- loadLocalApps() {
114
- const apps = /* @__PURE__ */ new Map();
115
- if (!fs.existsSync(this.appsDir)) {
116
- return apps;
113
+ constructor(tenant, api) {
114
+ this.api = api;
115
+ this.appsDir = (0, helpers_1.getTenantAppsDir)(tenant);
117
116
  }
118
- const files = fs.readdirSync(this.appsDir).filter((f) => f.endsWith(".json"));
119
- for (const file of files) {
120
- try {
121
- const content = fs.readFileSync(path.join(this.appsDir, file), "utf-8");
122
- const config = JSON.parse(content);
123
- apps.set(config.name.toLowerCase(), config);
124
- } catch {
125
- }
117
+ /**
118
+ * Get filename for an app (keep original name, just sanitize for filesystem)
119
+ */
120
+ getAppFilename(name) {
121
+ return (sanitizeDiacritics(name)
122
+ .replace(/[<>:"/\\|?*]/g, '') // Remove invalid filename characters
123
+ .trim() + '.json');
126
124
  }
127
- return apps;
128
- }
129
- /**
130
- * Save a local app config
131
- */
132
- saveLocalApp(config) {
133
- (0, import_helpers.ensureDirectoryExists)(this.appsDir);
134
- const filename = this.getAppFilename(config.name);
135
- const filePath = path.join(this.appsDir, filename);
136
- fs.writeFileSync(filePath, JSON.stringify(config, null, 2), "utf-8");
137
- }
138
- /**
139
- * Delete a local app config
140
- */
141
- deleteLocalApp(name) {
142
- const filename = this.getAppFilename(name);
143
- const filePath = path.join(this.appsDir, filename);
144
- if (fs.existsSync(filePath)) {
145
- fs.unlinkSync(filePath);
146
- return true;
147
- }
148
- return false;
149
- }
150
- /**
151
- * Convert remote app to local config format
152
- */
153
- remoteToLocal(remote, reference) {
154
- const mainScript = remote.scriptFiles.find((s) => s.id === remote.mainScriptFileId);
155
- return {
156
- name: remote.name,
157
- description: remote.description || "",
158
- entrypoint: mainScript?.name || null,
159
- scripts: remote.scriptFiles.map((s) => s.name),
160
- arguments: remote.expectedArguments.map((a) => ({
161
- name: a.name,
162
- defaultValue: a.defaultValue
163
- })),
164
- _remote: {
165
- id: remote.id,
166
- reference
167
- }
168
- };
169
- }
170
- /**
171
- * Check if local and remote app configs are equivalent
172
- */
173
- areAppsEqual(local, remote) {
174
- if (local.name !== remote.name) return false;
175
- if ((local.description || "") !== (remote.description || "")) return false;
176
- const remoteEntrypoint = remote.scriptFiles.find((s) => s.id === remote.mainScriptFileId)?.name || null;
177
- if (local.entrypoint !== remoteEntrypoint) return false;
178
- const localScripts = [...local.scripts].sort();
179
- const remoteScripts = [...remote.scriptFiles.map((s) => s.name)].sort();
180
- if (JSON.stringify(localScripts) !== JSON.stringify(remoteScripts)) return false;
181
- const localArgs = local.arguments.map((a) => `${a.name}=${a.defaultValue}`).sort();
182
- const remoteArgs = remote.expectedArguments.map((a) => `${a.name}=${a.defaultValue}`).sort();
183
- if (JSON.stringify(localArgs) !== JSON.stringify(remoteArgs)) return false;
184
- return true;
185
- }
186
- /**
187
- * Pull apps from remote and save locally
188
- */
189
- async pull() {
190
- const result = {
191
- created: [],
192
- updated: [],
193
- deleted: [],
194
- unchanged: []
195
- };
196
- const localApps = this.loadLocalApps();
197
- const remoteAppList = await this.api.listApps();
198
- const remoteApps = /* @__PURE__ */ new Map();
199
- import_logger.logger.dim(`Fetching ${remoteAppList.length} apps in parallel...`);
200
- const appDetails = await (0, import_helpers.fetchWithConcurrency)(
201
- remoteAppList,
202
- async (item, index) => {
203
- const app = await this.api.getApp(item.reference);
204
- if ((index + 1) % 10 === 0 || index === remoteAppList.length - 1) {
205
- process.stdout.write(`\r Progress: ${index + 1}/${remoteAppList.length} apps`);
125
+ /**
126
+ * Load all local app configs
127
+ */
128
+ loadLocalApps() {
129
+ const apps = new Map();
130
+ if (!fs.existsSync(this.appsDir)) {
131
+ return apps;
206
132
  }
207
- return { app, reference: item.reference };
208
- },
209
- 15
210
- );
211
- if (remoteAppList.length > 0) {
212
- process.stdout.write("\r" + " ".repeat(50) + "\r");
213
- }
214
- for (const { app, reference } of appDetails) {
215
- if (app) {
216
- remoteApps.set(app.name.toLowerCase(), { app, reference });
217
- }
133
+ const files = fs.readdirSync(this.appsDir).filter((f) => f.endsWith('.json'));
134
+ for (const file of files) {
135
+ try {
136
+ const content = fs.readFileSync(path.join(this.appsDir, file), 'utf-8');
137
+ const config = JSON.parse(content);
138
+ apps.set(config.name.toLowerCase(), config);
139
+ }
140
+ catch {
141
+ // Skip invalid files
142
+ }
143
+ }
144
+ return apps;
218
145
  }
219
- for (const [key, { app, reference }] of remoteApps) {
220
- const localConfig = this.remoteToLocal(app, reference);
221
- const existingLocal = localApps.get(key);
222
- if (!existingLocal) {
223
- this.saveLocalApp(localConfig);
224
- result.created.push(app.name);
225
- } else if (!this.areAppsEqual(existingLocal, app)) {
226
- this.saveLocalApp(localConfig);
227
- result.updated.push(app.name);
228
- } else {
229
- result.unchanged.push(app.name);
230
- }
146
+ /**
147
+ * Save a local app config
148
+ */
149
+ saveLocalApp(config) {
150
+ (0, helpers_1.ensureDirectoryExists)(this.appsDir);
151
+ const filename = this.getAppFilename(config.name);
152
+ const filePath = path.join(this.appsDir, filename);
153
+ fs.writeFileSync(filePath, JSON.stringify(config, null, 2), 'utf-8');
231
154
  }
232
- for (const [key, local] of localApps) {
233
- if (!remoteApps.has(key) && local._remote) {
234
- this.deleteLocalApp(local.name);
235
- result.deleted.push(local.name);
236
- }
155
+ /**
156
+ * Delete a local app config
157
+ */
158
+ deleteLocalApp(name) {
159
+ const filename = this.getAppFilename(name);
160
+ const filePath = path.join(this.appsDir, filename);
161
+ if (fs.existsSync(filePath)) {
162
+ fs.unlinkSync(filePath);
163
+ return true;
164
+ }
165
+ return false;
237
166
  }
238
- return result;
239
- }
240
- /**
241
- * Push local apps to remote
242
- */
243
- async push() {
244
- const result = {
245
- created: [],
246
- updated: [],
247
- deleted: [],
248
- unchanged: []
249
- };
250
- const localApps = this.loadLocalApps();
251
- const remoteAppList = await this.api.listApps();
252
- const remoteApps = /* @__PURE__ */ new Map();
253
- const appDetails = await (0, import_helpers.fetchWithConcurrency)(
254
- remoteAppList,
255
- async (item) => {
256
- const app = await this.api.getApp(item.reference);
257
- return { app, reference: item.reference };
258
- },
259
- 15
260
- );
261
- for (const { app, reference } of appDetails) {
262
- if (app) {
263
- remoteApps.set(app.name.toLowerCase(), { app, reference });
264
- }
167
+ /**
168
+ * Convert remote app to local config format
169
+ */
170
+ remoteToLocal(remote, reference) {
171
+ const scriptFiles = remote.scriptFiles ?? [];
172
+ const mainScript = scriptFiles.find((s) => s.id === remote.mainScriptFileId);
173
+ return {
174
+ name: remote.name,
175
+ description: remote.description || '',
176
+ entrypoint: mainScript?.name || null,
177
+ scripts: scriptFiles.map((s) => s.name),
178
+ arguments: remote.expectedArguments.map((a) => ({
179
+ name: a.name,
180
+ defaultValue: a.defaultValue,
181
+ })),
182
+ _remote: {
183
+ id: remote.id,
184
+ reference: reference,
185
+ },
186
+ };
265
187
  }
266
- const availableScripts = await this.api.getScriptFiles();
267
- const scriptIdByPath = /* @__PURE__ */ new Map();
268
- const scriptIdByName = /* @__PURE__ */ new Map();
269
- for (const s of availableScripts) {
270
- const pathKey = s.name.toLowerCase();
271
- const filenameKey = s.name.split("/").pop()?.toLowerCase() || pathKey;
272
- scriptIdByPath.set(pathKey, s.id);
273
- if (!scriptIdByName.has(filenameKey)) {
274
- scriptIdByName.set(filenameKey, s.id);
275
- }
188
+ /**
189
+ * Check if local and remote app configs are equivalent
190
+ */
191
+ areAppsEqual(local, remote) {
192
+ // Compare name
193
+ if (local.name !== remote.name)
194
+ return false;
195
+ // Compare description
196
+ if ((local.description || '') !== (remote.description || ''))
197
+ return false;
198
+ // Compare entrypoint
199
+ const remoteScriptFiles = remote.scriptFiles ?? [];
200
+ const remoteEntrypoint = remoteScriptFiles.find((s) => s.id === remote.mainScriptFileId)?.name || null;
201
+ if (local.entrypoint !== remoteEntrypoint)
202
+ return false;
203
+ // Compare scripts
204
+ const localScripts = [...local.scripts].sort();
205
+ const remoteScripts = [...remoteScriptFiles.map((s) => s.name)].sort();
206
+ if (JSON.stringify(localScripts) !== JSON.stringify(remoteScripts))
207
+ return false;
208
+ // Compare arguments
209
+ const localArgs = local.arguments.map((a) => `${a.name}=${a.defaultValue}`).sort();
210
+ const remoteArgs = remote.expectedArguments.map((a) => `${a.name}=${a.defaultValue}`).sort();
211
+ if (JSON.stringify(localArgs) !== JSON.stringify(remoteArgs))
212
+ return false;
213
+ return true;
276
214
  }
277
- const findScriptId = (scriptRef) => {
278
- const key = scriptRef.toLowerCase();
279
- const byPath = scriptIdByPath.get(key);
280
- if (byPath) return byPath;
281
- const withPrefix = scriptIdByPath.get(`scripts/${key}`);
282
- if (withPrefix) return withPrefix;
283
- return scriptIdByName.get(key.split("/").pop() || key);
284
- };
285
- for (const [key, local] of localApps) {
286
- const remote = remoteApps.get(key);
287
- if (!remote) {
288
- try {
289
- const created = await this.api.createApp(local.name);
290
- const update = this.buildUpdatePayload(local, findScriptId);
291
- update.name = local.name;
292
- update.description = local.description;
293
- await this.api.updateApp(created.id.toString(), update);
294
- local._remote = {
295
- id: created.id,
296
- reference: created.id.toString()
297
- };
298
- this.saveLocalApp(local);
299
- result.created.push(local.name);
300
- } catch (error) {
301
- console.error(`Failed to create app ${local.name}:`, error);
215
+ /**
216
+ * Pull apps from remote and save locally
217
+ */
218
+ async pull() {
219
+ const result = {
220
+ created: [],
221
+ updated: [],
222
+ deleted: [],
223
+ unchanged: [],
224
+ };
225
+ // Load local apps
226
+ const localApps = this.loadLocalApps();
227
+ // Fetch remote apps
228
+ const remoteAppList = await this.api.listApps();
229
+ const remoteApps = new Map();
230
+ // Fetch app details in parallel with concurrency limit
231
+ logger_1.logger.dim(`Fetching ${remoteAppList.length} apps in parallel...`);
232
+ const appDetails = await (0, helpers_1.fetchWithConcurrency)(remoteAppList, async (item, index) => {
233
+ const app = await this.api.getApp(item.reference);
234
+ // Show progress every 10 apps
235
+ if ((index + 1) % 10 === 0 || index === remoteAppList.length - 1) {
236
+ process.stdout.write(`\r Progress: ${index + 1}/${remoteAppList.length} apps`);
237
+ }
238
+ return { app, reference: item.reference };
239
+ }, 15);
240
+ // Clear progress line
241
+ if (remoteAppList.length > 0) {
242
+ process.stdout.write('\r' + ' '.repeat(50) + '\r');
302
243
  }
303
- } else if (!this.areAppsEqual(local, remote.app)) {
304
- try {
305
- const update = this.buildUpdatePayload(local, findScriptId);
306
- update.name = local.name;
307
- update.description = local.description;
308
- await this.api.updateApp(remote.reference, update);
309
- result.updated.push(local.name);
310
- } catch (error) {
311
- console.error(`Failed to update app ${local.name}:`, error);
244
+ for (const { app, reference } of appDetails) {
245
+ if (app) {
246
+ remoteApps.set(app.name.toLowerCase(), { app, reference });
247
+ }
312
248
  }
313
- } else {
314
- result.unchanged.push(local.name);
315
- }
316
- }
317
- return result;
318
- }
319
- /**
320
- * Build update payload for API
321
- */
322
- buildUpdatePayload(local, findScriptId) {
323
- const update = {};
324
- if (local.arguments.length > 0) {
325
- update.expectedArguments = local.arguments.map((a) => ({
326
- name: a.name,
327
- type: "variable",
328
- defaultValue: a.defaultValue
329
- }));
330
- }
331
- if (local.scripts.length > 0) {
332
- const scriptIds = [];
333
- for (const scriptRef of local.scripts) {
334
- const id = findScriptId(scriptRef);
335
- if (id) {
336
- scriptIds.push(id);
249
+ // Process remote apps
250
+ for (const [key, { app, reference }] of remoteApps) {
251
+ const localConfig = this.remoteToLocal(app, reference);
252
+ const existingLocal = localApps.get(key);
253
+ if (!existingLocal) {
254
+ // New app from remote
255
+ this.saveLocalApp(localConfig);
256
+ result.created.push(app.name);
257
+ }
258
+ else if (!this.areAppsEqual(existingLocal, app)) {
259
+ // App changed on remote - update local
260
+ this.saveLocalApp(localConfig);
261
+ result.updated.push(app.name);
262
+ }
263
+ else {
264
+ result.unchanged.push(app.name);
265
+ }
337
266
  }
338
- }
339
- if (scriptIds.length > 0) {
340
- update.scriptFileIds = scriptIds;
341
- }
342
- }
343
- if (local.entrypoint) {
344
- const entrypointId = findScriptId(local.entrypoint);
345
- if (entrypointId) {
346
- update.mainScriptFileId = entrypointId;
347
- }
267
+ // Check for apps deleted on remote
268
+ for (const [key, local] of localApps) {
269
+ if (!remoteApps.has(key) && local._remote) {
270
+ // App was synced before but now deleted on remote
271
+ this.deleteLocalApp(local.name);
272
+ result.deleted.push(local.name);
273
+ }
274
+ }
275
+ return result;
348
276
  }
349
- return update;
350
- }
351
- /**
352
- * Get sync status without making changes
353
- */
354
- async getStatus() {
355
- const status = {
356
- newLocal: [],
357
- newRemote: [],
358
- modified: [],
359
- synced: []
360
- };
361
- const localApps = this.loadLocalApps();
362
- const remoteAppList = await this.api.listApps();
363
- const remoteApps = /* @__PURE__ */ new Map();
364
- const appDetails = await (0, import_helpers.fetchWithConcurrency)(
365
- remoteAppList,
366
- async (item) => {
367
- const app = await this.api.getApp(item.reference);
368
- return { app, reference: item.reference };
369
- },
370
- 15
371
- );
372
- for (const { app, reference } of appDetails) {
373
- if (app) {
374
- remoteApps.set(app.name.toLowerCase(), { app, reference });
375
- }
277
+ /**
278
+ * Push local apps to remote
279
+ */
280
+ async push() {
281
+ const result = {
282
+ created: [],
283
+ updated: [],
284
+ deleted: [],
285
+ unchanged: [],
286
+ };
287
+ // Load local apps
288
+ const localApps = this.loadLocalApps();
289
+ // Fetch remote apps
290
+ const remoteAppList = await this.api.listApps();
291
+ const remoteApps = new Map();
292
+ // Fetch app details in parallel with concurrency limit
293
+ const appDetails = await (0, helpers_1.fetchWithConcurrency)(remoteAppList, async (item) => {
294
+ const app = await this.api.getApp(item.reference);
295
+ return { app, reference: item.reference };
296
+ }, 15);
297
+ for (const { app, reference } of appDetails) {
298
+ if (app) {
299
+ remoteApps.set(app.name.toLowerCase(), { app, reference });
300
+ }
301
+ }
302
+ // Get available scripts for ID lookup
303
+ // Build maps for both path-based and filename-based lookup (backward compatibility)
304
+ const availableScripts = await this.api.getScriptFiles();
305
+ const scriptIdByPath = new Map();
306
+ const scriptIdByName = new Map();
307
+ for (const s of availableScripts) {
308
+ // s.name now contains full path (e.g., "Scripts/test.ts")
309
+ const pathKey = s.name.toLowerCase();
310
+ const filenameKey = s.name.split('/').pop()?.toLowerCase() || pathKey;
311
+ scriptIdByPath.set(pathKey, s.id);
312
+ // For filename lookup, only set if not already set (first match wins for ambiguous names)
313
+ if (!scriptIdByName.has(filenameKey)) {
314
+ scriptIdByName.set(filenameKey, s.id);
315
+ }
316
+ }
317
+ // Helper to find script ID by path or filename
318
+ const findScriptId = (scriptRef) => {
319
+ const key = scriptRef.toLowerCase();
320
+ // Try exact path match first
321
+ const byPath = scriptIdByPath.get(key);
322
+ if (byPath)
323
+ return byPath;
324
+ // Try with Scripts/ prefix
325
+ const withPrefix = scriptIdByPath.get(`scripts/${key}`);
326
+ if (withPrefix)
327
+ return withPrefix;
328
+ // Fall back to filename match
329
+ return scriptIdByName.get(key.split('/').pop() || key);
330
+ };
331
+ // Process local apps
332
+ for (const [key, local] of localApps) {
333
+ const remote = remoteApps.get(key);
334
+ if (!remote) {
335
+ // New local app - create on remote
336
+ try {
337
+ const created = await this.api.createApp(local.name);
338
+ // Update with config (API requires name and description)
339
+ const update = this.buildUpdatePayload(local, findScriptId);
340
+ update.name = local.name;
341
+ update.description = local.description;
342
+ await this.api.updateApp(created.id.toString(), update);
343
+ // Update local with remote ID
344
+ local._remote = {
345
+ id: created.id,
346
+ reference: created.id.toString(),
347
+ };
348
+ this.saveLocalApp(local);
349
+ result.created.push(local.name);
350
+ }
351
+ catch (error) {
352
+ console.error(`Failed to create app ${local.name}:`, error);
353
+ }
354
+ }
355
+ else if (!this.areAppsEqual(local, remote.app)) {
356
+ // App differs - update remote
357
+ try {
358
+ const update = this.buildUpdatePayload(local, findScriptId);
359
+ update.name = local.name;
360
+ update.description = local.description;
361
+ await this.api.updateApp(remote.reference, update);
362
+ result.updated.push(local.name);
363
+ }
364
+ catch (error) {
365
+ console.error(`Failed to update app ${local.name}:`, error);
366
+ }
367
+ }
368
+ else {
369
+ result.unchanged.push(local.name);
370
+ }
371
+ }
372
+ // Note: We don't auto-delete remote apps when deleted locally
373
+ // User must use "farseer app delete" explicitly
374
+ return result;
376
375
  }
377
- for (const [key, local] of localApps) {
378
- const remote = remoteApps.get(key);
379
- if (!remote) {
380
- status.newLocal.push(local.name);
381
- } else if (!this.areAppsEqual(local, remote.app)) {
382
- status.modified.push(local.name);
383
- } else {
384
- status.synced.push(local.name);
385
- }
376
+ /**
377
+ * Build update payload for API
378
+ */
379
+ buildUpdatePayload(local, findScriptId) {
380
+ const update = {};
381
+ // Arguments
382
+ if (local.arguments.length > 0) {
383
+ update.expectedArguments = local.arguments.map((a) => ({
384
+ name: a.name,
385
+ type: 'variable',
386
+ defaultValue: a.defaultValue,
387
+ }));
388
+ }
389
+ // Scripts - lookup by path or filename
390
+ if (local.scripts.length > 0) {
391
+ const scriptIds = [];
392
+ for (const scriptRef of local.scripts) {
393
+ const id = findScriptId(scriptRef);
394
+ if (id) {
395
+ scriptIds.push(id);
396
+ }
397
+ }
398
+ if (scriptIds.length > 0) {
399
+ update.scriptFileIds = scriptIds;
400
+ }
401
+ }
402
+ // Entrypoint - lookup by path or filename
403
+ if (local.entrypoint) {
404
+ const entrypointId = findScriptId(local.entrypoint);
405
+ if (entrypointId) {
406
+ update.mainScriptFileId = entrypointId;
407
+ }
408
+ }
409
+ return update;
386
410
  }
387
- for (const [key, { app }] of remoteApps) {
388
- if (!localApps.has(key)) {
389
- status.newRemote.push(app.name);
390
- }
411
+ /**
412
+ * Get sync status without making changes
413
+ */
414
+ async getStatus() {
415
+ const status = {
416
+ newLocal: [],
417
+ newRemote: [],
418
+ modified: [],
419
+ synced: [],
420
+ };
421
+ // Load local apps
422
+ const localApps = this.loadLocalApps();
423
+ // Fetch remote apps
424
+ const remoteAppList = await this.api.listApps();
425
+ const remoteApps = new Map();
426
+ // Fetch app details in parallel with concurrency limit
427
+ const appDetails = await (0, helpers_1.fetchWithConcurrency)(remoteAppList, async (item) => {
428
+ const app = await this.api.getApp(item.reference);
429
+ return { app, reference: item.reference };
430
+ }, 15);
431
+ for (const { app, reference } of appDetails) {
432
+ if (app) {
433
+ remoteApps.set(app.name.toLowerCase(), { app, reference });
434
+ }
435
+ }
436
+ // Check local apps
437
+ for (const [key, local] of localApps) {
438
+ const remote = remoteApps.get(key);
439
+ if (!remote) {
440
+ status.newLocal.push(local.name);
441
+ }
442
+ else if (!this.areAppsEqual(local, remote.app)) {
443
+ status.modified.push(local.name);
444
+ }
445
+ else {
446
+ status.synced.push(local.name);
447
+ }
448
+ }
449
+ // Check for new remote apps
450
+ for (const [key, { app }] of remoteApps) {
451
+ if (!localApps.has(key)) {
452
+ status.newRemote.push(app.name);
453
+ }
454
+ }
455
+ return status;
391
456
  }
392
- return status;
393
- }
394
457
  }
395
- // Annotate the CommonJS export names for ESM import in node:
396
- 0 && (module.exports = {
397
- AppSyncService
398
- });
399
- //# sourceMappingURL=appSyncService.js.map
458
+ exports.AppSyncService = AppSyncService;