farseer-cli 1.0.10 → 1.1.1

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 (98) hide show
  1. package/README.md +19 -0
  2. package/dist/commands/app.js +348 -344
  3. package/dist/commands/app.js.map +7 -0
  4. package/dist/commands/apps.js +110 -82
  5. package/dist/commands/apps.js.map +7 -0
  6. package/dist/commands/cells.js +161 -0
  7. package/dist/commands/cells.js.map +7 -0
  8. package/dist/commands/checkout.js +140 -155
  9. package/dist/commands/checkout.js.map +7 -0
  10. package/dist/commands/config.js +128 -126
  11. package/dist/commands/config.js.map +7 -0
  12. package/dist/commands/dashboards.js +130 -0
  13. package/dist/commands/dashboards.js.map +7 -0
  14. package/dist/commands/diff.js +171 -193
  15. package/dist/commands/diff.js.map +7 -0
  16. package/dist/commands/dimensions.js +222 -119
  17. package/dist/commands/dimensions.js.map +7 -0
  18. package/dist/commands/files.js +96 -77
  19. package/dist/commands/files.js.map +7 -0
  20. package/dist/commands/formula.js +116 -0
  21. package/dist/commands/formula.js.map +7 -0
  22. package/dist/commands/install.js +74 -76
  23. package/dist/commands/install.js.map +7 -0
  24. package/dist/commands/list.js +91 -73
  25. package/dist/commands/list.js.map +7 -0
  26. package/dist/commands/login.js +137 -98
  27. package/dist/commands/login.js.map +7 -0
  28. package/dist/commands/logout.js +59 -41
  29. package/dist/commands/logout.js.map +7 -0
  30. package/dist/commands/mcp-server.js +36 -23
  31. package/dist/commands/mcp-server.js.map +7 -0
  32. package/dist/commands/model.js +186 -175
  33. package/dist/commands/model.js.map +7 -0
  34. package/dist/commands/pull.js +264 -274
  35. package/dist/commands/pull.js.map +7 -0
  36. package/dist/commands/push.js +209 -221
  37. package/dist/commands/push.js.map +7 -0
  38. package/dist/commands/run.js +276 -321
  39. package/dist/commands/run.js.map +7 -0
  40. package/dist/commands/sheets.js +200 -0
  41. package/dist/commands/sheets.js.map +7 -0
  42. package/dist/commands/status.js +149 -169
  43. package/dist/commands/status.js.map +7 -0
  44. package/dist/commands/variables.js +247 -188
  45. package/dist/commands/variables.js.map +7 -0
  46. package/dist/commands/whoami.js +65 -44
  47. package/dist/commands/whoami.js.map +7 -0
  48. package/dist/index.js +179 -115
  49. package/dist/index.js.map +7 -0
  50. package/dist/mcp/index.js +33 -16
  51. package/dist/mcp/index.js.map +7 -0
  52. package/dist/mcp/prompts/workflows.js +191 -145
  53. package/dist/mcp/prompts/workflows.js.map +7 -0
  54. package/dist/mcp/resources/documentation.js +158 -148
  55. package/dist/mcp/resources/documentation.js.map +7 -0
  56. package/dist/mcp/server.js +56 -33
  57. package/dist/mcp/server.js.map +7 -0
  58. package/dist/mcp/tools/appTools.js +309 -277
  59. package/dist/mcp/tools/appTools.js.map +7 -0
  60. package/dist/mcp/tools/authTools.js +130 -121
  61. package/dist/mcp/tools/authTools.js.map +7 -0
  62. package/dist/mcp/tools/cellTools.js +148 -0
  63. package/dist/mcp/tools/cellTools.js.map +7 -0
  64. package/dist/mcp/tools/dashboardTools.js +133 -0
  65. package/dist/mcp/tools/dashboardTools.js.map +7 -0
  66. package/dist/mcp/tools/dataTools.js +270 -267
  67. package/dist/mcp/tools/dataTools.js.map +7 -0
  68. package/dist/mcp/tools/modelTools.js +575 -229
  69. package/dist/mcp/tools/modelTools.js.map +7 -0
  70. package/dist/mcp/tools/runTools.js +201 -203
  71. package/dist/mcp/tools/runTools.js.map +7 -0
  72. package/dist/mcp/tools/sheetTools.js +240 -0
  73. package/dist/mcp/tools/sheetTools.js.map +7 -0
  74. package/dist/mcp/tools/syncTools.js +335 -314
  75. package/dist/mcp/tools/syncTools.js.map +7 -0
  76. package/dist/mcp/utils/helpers.js +117 -123
  77. package/dist/mcp/utils/helpers.js.map +7 -0
  78. package/dist/services/appSyncService.js +381 -437
  79. package/dist/services/appSyncService.js.map +7 -0
  80. package/dist/services/configService.js +154 -143
  81. package/dist/services/configService.js.map +7 -0
  82. package/dist/services/farseerApi.js +422 -399
  83. package/dist/services/farseerApi.js.map +7 -0
  84. package/dist/services/farseerFactory.js +208 -273
  85. package/dist/services/farseerFactory.js.map +7 -0
  86. package/dist/services/farseerService.js +467 -486
  87. package/dist/services/farseerService.js.map +7 -0
  88. package/dist/services/syncService.js +661 -731
  89. package/dist/services/syncService.js.map +7 -0
  90. package/dist/utils/constants.js +52 -19
  91. package/dist/utils/constants.js.map +7 -0
  92. package/dist/utils/entityResolver.js +78 -0
  93. package/dist/utils/entityResolver.js.map +7 -0
  94. package/dist/utils/helpers.js +331 -365
  95. package/dist/utils/helpers.js.map +7 -0
  96. package/dist/utils/logger.js +74 -42
  97. package/dist/utils/logger.js.map +7 -0
  98. package/package.json +3 -2
@@ -1,458 +1,402 @@
1
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;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var appSyncService_exports = {};
30
+ __export(appSyncService_exports, {
31
+ AppSyncService: () => AppSyncService
17
32
  });
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
- */
33
+ module.exports = __toCommonJS(appSyncService_exports);
34
+ var fs = __toESM(require("fs"));
35
+ var path = __toESM(require("path"));
36
+ var import_helpers = require("../utils/helpers");
37
+ var import_logger = require("../utils/logger");
44
38
  function sanitizeDiacritics(text) {
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('');
39
+ const diacriticMap = {
40
+ // Croatian
41
+ \u010D: "c",
42
+ \u010C: "C",
43
+ \u0107: "c",
44
+ \u0106: "C",
45
+ \u0161: "s",
46
+ \u0160: "S",
47
+ \u017E: "z",
48
+ \u017D: "Z",
49
+ \u0111: "d",
50
+ \u0110: "D",
51
+ // German/Other common
52
+ \u00E4: "a",
53
+ \u00C4: "A",
54
+ \u00F6: "o",
55
+ \u00D6: "O",
56
+ \u00FC: "u",
57
+ \u00DC: "U",
58
+ \u00DF: "ss",
59
+ // Polish
60
+ \u0105: "a",
61
+ \u0104: "A",
62
+ \u0119: "e",
63
+ \u0118: "E",
64
+ \u0142: "l",
65
+ \u0141: "L",
66
+ \u0144: "n",
67
+ \u0143: "N",
68
+ \u00F3: "o",
69
+ \u00D3: "O",
70
+ \u015B: "s",
71
+ \u015A: "S",
72
+ \u017A: "z",
73
+ \u0179: "Z",
74
+ \u017C: "z",
75
+ \u017B: "Z",
76
+ // French/Spanish
77
+ \u00E0: "a",
78
+ \u00E1: "a",
79
+ \u00E2: "a",
80
+ \u00E8: "e",
81
+ \u00E9: "e",
82
+ \u00EA: "e",
83
+ \u00EB: "e",
84
+ \u00EC: "i",
85
+ \u00ED: "i",
86
+ \u00EE: "i",
87
+ \u00EF: "i",
88
+ \u00F2: "o",
89
+ \u00F4: "o",
90
+ \u00F9: "u",
91
+ \u00FA: "u",
92
+ \u00FB: "u",
93
+ \u00F1: "n",
94
+ \u00D1: "N",
95
+ \u00E7: "c",
96
+ \u00C7: "C"
97
+ };
98
+ return text.split("").map((char) => diacriticMap[char] || char).join("");
108
99
  }
109
- /**
110
- * Service for syncing app configurations between local JSON files and remote Farseer instance
111
- */
112
100
  class AppSyncService {
113
- constructor(tenant, api) {
114
- this.api = api;
115
- this.appsDir = (0, helpers_1.getTenantAppsDir)(tenant);
101
+ constructor(tenant, api) {
102
+ this.api = api;
103
+ this.appsDir = (0, import_helpers.getTenantAppsDir)(tenant);
104
+ }
105
+ /**
106
+ * Get filename for an app (keep original name, just sanitize for filesystem)
107
+ */
108
+ getAppFilename(name) {
109
+ return sanitizeDiacritics(name).replace(/[<>:"/\\|?*]/g, "").trim() + ".json";
110
+ }
111
+ /**
112
+ * Load all local app configs
113
+ */
114
+ loadLocalApps() {
115
+ const apps = /* @__PURE__ */ new Map();
116
+ if (!fs.existsSync(this.appsDir)) {
117
+ return apps;
116
118
  }
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');
119
+ const files = fs.readdirSync(this.appsDir).filter((f) => f.endsWith(".json"));
120
+ for (const file of files) {
121
+ try {
122
+ const content = fs.readFileSync(path.join(this.appsDir, file), "utf-8");
123
+ const config = JSON.parse(content);
124
+ apps.set(config.name.toLowerCase(), config);
125
+ } catch {
126
+ }
124
127
  }
125
- /**
126
- * Load all local app configs
127
- */
128
- loadLocalApps() {
129
- const apps = new Map();
130
- if (!fs.existsSync(this.appsDir)) {
131
- return apps;
132
- }
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
- }
128
+ return apps;
129
+ }
130
+ /**
131
+ * Save a local app config
132
+ */
133
+ saveLocalApp(config) {
134
+ (0, import_helpers.ensureDirectoryExists)(this.appsDir);
135
+ const filename = this.getAppFilename(config.name);
136
+ const filePath = path.join(this.appsDir, filename);
137
+ fs.writeFileSync(filePath, JSON.stringify(config, null, 2), "utf-8");
138
+ }
139
+ /**
140
+ * Delete a local app config
141
+ */
142
+ deleteLocalApp(name) {
143
+ const filename = this.getAppFilename(name);
144
+ const filePath = path.join(this.appsDir, filename);
145
+ if (fs.existsSync(filePath)) {
146
+ fs.unlinkSync(filePath);
147
+ return true;
148
+ }
149
+ return false;
150
+ }
151
+ /**
152
+ * Convert remote app to local config format
153
+ */
154
+ remoteToLocal(remote, reference) {
155
+ const scriptFiles = remote.scriptFiles ?? [];
156
+ const mainScript = scriptFiles.find((s) => s.id === remote.mainScriptFileId);
157
+ return {
158
+ name: remote.name,
159
+ description: remote.description || "",
160
+ entrypoint: mainScript?.name || null,
161
+ scripts: scriptFiles.map((s) => s.name),
162
+ arguments: remote.expectedArguments.map((a) => ({
163
+ name: a.name,
164
+ defaultValue: a.defaultValue
165
+ })),
166
+ _remote: {
167
+ id: remote.id,
168
+ reference
169
+ }
170
+ };
171
+ }
172
+ /**
173
+ * Check if local and remote app configs are equivalent
174
+ */
175
+ areAppsEqual(local, remote) {
176
+ if (local.name !== remote.name) return false;
177
+ if ((local.description || "") !== (remote.description || "")) return false;
178
+ const remoteScriptFiles = remote.scriptFiles ?? [];
179
+ const remoteEntrypoint = remoteScriptFiles.find((s) => s.id === remote.mainScriptFileId)?.name || null;
180
+ if (local.entrypoint !== remoteEntrypoint) return false;
181
+ const localScripts = [...local.scripts].sort();
182
+ const remoteScripts = [...remoteScriptFiles.map((s) => s.name)].sort();
183
+ if (JSON.stringify(localScripts) !== JSON.stringify(remoteScripts)) return false;
184
+ const localArgs = local.arguments.map((a) => `${a.name}=${a.defaultValue}`).sort();
185
+ const remoteArgs = remote.expectedArguments.map((a) => `${a.name}=${a.defaultValue}`).sort();
186
+ if (JSON.stringify(localArgs) !== JSON.stringify(remoteArgs)) return false;
187
+ return true;
188
+ }
189
+ /**
190
+ * Pull apps from remote and save locally
191
+ */
192
+ async pull() {
193
+ const result = {
194
+ created: [],
195
+ updated: [],
196
+ deleted: [],
197
+ unchanged: []
198
+ };
199
+ const localApps = this.loadLocalApps();
200
+ const remoteAppList = await this.api.listApps();
201
+ const remoteApps = /* @__PURE__ */ new Map();
202
+ import_logger.logger.dim(`Fetching ${remoteAppList.length} apps in parallel...`);
203
+ const appDetails = await (0, import_helpers.fetchWithConcurrency)(
204
+ remoteAppList,
205
+ async (item, index) => {
206
+ const app = await this.api.getApp(item.reference);
207
+ if ((index + 1) % 10 === 0 || index === remoteAppList.length - 1) {
208
+ process.stdout.write(`\r Progress: ${index + 1}/${remoteAppList.length} apps`);
143
209
  }
144
- return apps;
210
+ return { app, reference: item.reference };
211
+ },
212
+ 15
213
+ );
214
+ if (remoteAppList.length > 0) {
215
+ process.stdout.write("\r" + " ".repeat(50) + "\r");
145
216
  }
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');
217
+ for (const { app, reference } of appDetails) {
218
+ if (app) {
219
+ remoteApps.set(app.name.toLowerCase(), { app, reference });
220
+ }
154
221
  }
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;
222
+ for (const [key, { app, reference }] of remoteApps) {
223
+ const localConfig = this.remoteToLocal(app, reference);
224
+ const existingLocal = localApps.get(key);
225
+ if (!existingLocal) {
226
+ this.saveLocalApp(localConfig);
227
+ result.created.push(app.name);
228
+ } else if (!this.areAppsEqual(existingLocal, app)) {
229
+ this.saveLocalApp(localConfig);
230
+ result.updated.push(app.name);
231
+ } else {
232
+ result.unchanged.push(app.name);
233
+ }
166
234
  }
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
- };
235
+ for (const [key, local] of localApps) {
236
+ if (!remoteApps.has(key) && local._remote) {
237
+ this.deleteLocalApp(local.name);
238
+ result.deleted.push(local.name);
239
+ }
187
240
  }
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;
241
+ return result;
242
+ }
243
+ /**
244
+ * Push local apps to remote
245
+ */
246
+ async push() {
247
+ const result = {
248
+ created: [],
249
+ updated: [],
250
+ deleted: [],
251
+ unchanged: []
252
+ };
253
+ const localApps = this.loadLocalApps();
254
+ const remoteAppList = await this.api.listApps();
255
+ const remoteApps = /* @__PURE__ */ new Map();
256
+ const appDetails = await (0, import_helpers.fetchWithConcurrency)(
257
+ remoteAppList,
258
+ async (item) => {
259
+ const app = await this.api.getApp(item.reference);
260
+ return { app, reference: item.reference };
261
+ },
262
+ 15
263
+ );
264
+ for (const { app, reference } of appDetails) {
265
+ if (app) {
266
+ remoteApps.set(app.name.toLowerCase(), { app, reference });
267
+ }
214
268
  }
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');
243
- }
244
- for (const { app, reference } of appDetails) {
245
- if (app) {
246
- remoteApps.set(app.name.toLowerCase(), { app, reference });
247
- }
248
- }
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
- }
266
- }
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;
269
+ const availableScripts = await this.api.getScriptFiles();
270
+ const scriptIdByPath = /* @__PURE__ */ new Map();
271
+ const scriptIdByName = /* @__PURE__ */ new Map();
272
+ for (const s of availableScripts) {
273
+ const pathKey = s.name.toLowerCase();
274
+ const filenameKey = s.name.split("/").pop()?.toLowerCase() || pathKey;
275
+ scriptIdByPath.set(pathKey, s.id);
276
+ if (!scriptIdByName.has(filenameKey)) {
277
+ scriptIdByName.set(filenameKey, s.id);
278
+ }
276
279
  }
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
- }
280
+ const findScriptId = (scriptRef) => {
281
+ const key = scriptRef.toLowerCase();
282
+ const byPath = scriptIdByPath.get(key);
283
+ if (byPath) return byPath;
284
+ const withPrefix = scriptIdByPath.get(`scripts/${key}`);
285
+ if (withPrefix) return withPrefix;
286
+ return scriptIdByName.get(key.split("/").pop() || key);
287
+ };
288
+ for (const [key, local] of localApps) {
289
+ const remote = remoteApps.get(key);
290
+ if (!remote) {
291
+ try {
292
+ const created = await this.api.createApp(local.name);
293
+ const update = this.buildUpdatePayload(local, findScriptId);
294
+ update.name = local.name;
295
+ update.description = local.description;
296
+ await this.api.updateApp(created.id.toString(), update);
297
+ local._remote = {
298
+ id: created.id,
299
+ reference: created.id.toString()
300
+ };
301
+ this.saveLocalApp(local);
302
+ result.created.push(local.name);
303
+ } catch (error) {
304
+ console.error(`Failed to create app ${local.name}:`, error);
316
305
  }
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
- }
306
+ } else if (!this.areAppsEqual(local, remote.app)) {
307
+ try {
308
+ const update = this.buildUpdatePayload(local, findScriptId);
309
+ update.name = local.name;
310
+ update.description = local.description;
311
+ await this.api.updateApp(remote.reference, update);
312
+ result.updated.push(local.name);
313
+ } catch (error) {
314
+ console.error(`Failed to update app ${local.name}:`, error);
371
315
  }
372
- // Note: We don't auto-delete remote apps when deleted locally
373
- // User must use "farseer app delete" explicitly
374
- return result;
316
+ } else {
317
+ result.unchanged.push(local.name);
318
+ }
375
319
  }
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;
320
+ return result;
321
+ }
322
+ /**
323
+ * Build update payload for API
324
+ */
325
+ buildUpdatePayload(local, findScriptId) {
326
+ const update = {};
327
+ if (local.arguments.length > 0) {
328
+ update.expectedArguments = local.arguments.map((a) => ({
329
+ name: a.name,
330
+ type: "variable",
331
+ defaultValue: a.defaultValue
332
+ }));
410
333
  }
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
- }
334
+ if (local.scripts.length > 0) {
335
+ const scriptIds = [];
336
+ for (const scriptRef of local.scripts) {
337
+ const id = findScriptId(scriptRef);
338
+ if (id) {
339
+ scriptIds.push(id);
454
340
  }
455
- return status;
341
+ }
342
+ if (scriptIds.length > 0) {
343
+ update.scriptFileIds = scriptIds;
344
+ }
456
345
  }
346
+ if (local.entrypoint) {
347
+ const entrypointId = findScriptId(local.entrypoint);
348
+ if (entrypointId) {
349
+ update.mainScriptFileId = entrypointId;
350
+ }
351
+ }
352
+ return update;
353
+ }
354
+ /**
355
+ * Get sync status without making changes
356
+ */
357
+ async getStatus() {
358
+ const status = {
359
+ newLocal: [],
360
+ newRemote: [],
361
+ modified: [],
362
+ synced: []
363
+ };
364
+ const localApps = this.loadLocalApps();
365
+ const remoteAppList = await this.api.listApps();
366
+ const remoteApps = /* @__PURE__ */ new Map();
367
+ const appDetails = await (0, import_helpers.fetchWithConcurrency)(
368
+ remoteAppList,
369
+ async (item) => {
370
+ const app = await this.api.getApp(item.reference);
371
+ return { app, reference: item.reference };
372
+ },
373
+ 15
374
+ );
375
+ for (const { app, reference } of appDetails) {
376
+ if (app) {
377
+ remoteApps.set(app.name.toLowerCase(), { app, reference });
378
+ }
379
+ }
380
+ for (const [key, local] of localApps) {
381
+ const remote = remoteApps.get(key);
382
+ if (!remote) {
383
+ status.newLocal.push(local.name);
384
+ } else if (!this.areAppsEqual(local, remote.app)) {
385
+ status.modified.push(local.name);
386
+ } else {
387
+ status.synced.push(local.name);
388
+ }
389
+ }
390
+ for (const [key, { app }] of remoteApps) {
391
+ if (!localApps.has(key)) {
392
+ status.newRemote.push(app.name);
393
+ }
394
+ }
395
+ return status;
396
+ }
457
397
  }
458
- exports.AppSyncService = AppSyncService;
398
+ // Annotate the CommonJS export names for ESM import in node:
399
+ 0 && (module.exports = {
400
+ AppSyncService
401
+ });
402
+ //# sourceMappingURL=appSyncService.js.map