farseer-cli 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/app.js +344 -316
- package/dist/commands/apps.js +83 -103
- package/dist/commands/checkout.js +156 -134
- package/dist/commands/config.js +126 -124
- package/dist/commands/diff.js +194 -169
- package/dist/commands/dimensions.js +122 -137
- package/dist/commands/files.js +77 -88
- package/dist/commands/install.js +77 -74
- package/dist/commands/list.js +74 -89
- package/dist/commands/login.js +101 -126
- package/dist/commands/logout.js +42 -57
- package/dist/commands/mcp-server.js +24 -39
- package/dist/commands/model.js +176 -184
- package/dist/commands/pull.js +276 -248
- package/dist/commands/push.js +222 -200
- package/dist/commands/run.js +322 -274
- package/dist/commands/status.js +170 -147
- package/dist/commands/variables.js +192 -168
- package/dist/commands/whoami.js +45 -61
- package/dist/index.js +115 -117
- package/dist/mcp/index.js +17 -33
- package/dist/mcp/prompts/workflows.js +146 -191
- package/dist/mcp/resources/documentation.js +149 -158
- package/dist/mcp/server.js +34 -50
- package/dist/mcp/tools/appTools.js +278 -307
- package/dist/mcp/tools/authTools.js +123 -130
- package/dist/mcp/tools/dataTools.js +271 -275
- package/dist/mcp/tools/modelTools.js +233 -265
- package/dist/mcp/tools/runTools.js +205 -199
- package/dist/mcp/tools/syncTools.js +315 -341
- package/dist/mcp/utils/helpers.js +124 -117
- package/dist/services/appSyncService.js +438 -379
- package/dist/services/configService.js +144 -154
- package/dist/services/farseerApi.js +401 -401
- package/dist/services/farseerFactory.js +274 -208
- package/dist/services/farseerService.js +488 -455
- package/dist/services/syncService.js +732 -657
- package/dist/utils/constants.js +20 -45
- package/dist/utils/helpers.js +366 -333
- package/dist/utils/logger.js +43 -74
- package/package.json +8 -1
- package/dist/commands/app.js.map +0 -7
- package/dist/commands/apps.js.map +0 -7
- package/dist/commands/checkout.js.map +0 -7
- package/dist/commands/config.js.map +0 -7
- package/dist/commands/diff.js.map +0 -7
- package/dist/commands/dimensions.js.map +0 -7
- package/dist/commands/files.js.map +0 -7
- package/dist/commands/install.js.map +0 -7
- package/dist/commands/list.js.map +0 -7
- package/dist/commands/login.js.map +0 -7
- package/dist/commands/logout.js.map +0 -7
- package/dist/commands/mcp-server.js.map +0 -7
- package/dist/commands/model.js.map +0 -7
- package/dist/commands/pull.js.map +0 -7
- package/dist/commands/push.js.map +0 -7
- package/dist/commands/run.js.map +0 -7
- package/dist/commands/status.js.map +0 -7
- package/dist/commands/variables.js.map +0 -7
- package/dist/commands/whoami.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/mcp/index.js.map +0 -7
- package/dist/mcp/prompts/workflows.js.map +0 -7
- package/dist/mcp/resources/documentation.js.map +0 -7
- package/dist/mcp/server.js.map +0 -7
- package/dist/mcp/tools/appTools.js.map +0 -7
- package/dist/mcp/tools/authTools.js.map +0 -7
- package/dist/mcp/tools/dataTools.js.map +0 -7
- package/dist/mcp/tools/modelTools.js.map +0 -7
- package/dist/mcp/tools/runTools.js.map +0 -7
- package/dist/mcp/tools/syncTools.js.map +0 -7
- package/dist/mcp/utils/helpers.js.map +0 -7
- package/dist/services/appSyncService.js.map +0 -7
- package/dist/services/configService.js.map +0 -7
- package/dist/services/farseerApi.js.map +0 -7
- package/dist/services/farseerFactory.js.map +0 -7
- package/dist/services/farseerService.js.map +0 -7
- package/dist/services/syncService.js.map +0 -7
- package/dist/utils/constants.js.map +0 -7
- package/dist/utils/helpers.js.map +0 -7
- package/dist/utils/logger.js.map +0 -7
|
@@ -1,399 +1,458 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var 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
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
var
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
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
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
-
|
|
396
|
-
0 && (module.exports = {
|
|
397
|
-
AppSyncService
|
|
398
|
-
});
|
|
399
|
-
//# sourceMappingURL=appSyncService.js.map
|
|
458
|
+
exports.AppSyncService = AppSyncService;
|