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.
- package/README.md +19 -0
- package/dist/commands/app.js +348 -344
- package/dist/commands/app.js.map +7 -0
- package/dist/commands/apps.js +110 -82
- package/dist/commands/apps.js.map +7 -0
- package/dist/commands/cells.js +161 -0
- package/dist/commands/cells.js.map +7 -0
- package/dist/commands/checkout.js +140 -155
- package/dist/commands/checkout.js.map +7 -0
- package/dist/commands/config.js +128 -126
- package/dist/commands/config.js.map +7 -0
- package/dist/commands/dashboards.js +130 -0
- package/dist/commands/dashboards.js.map +7 -0
- package/dist/commands/diff.js +171 -193
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/dimensions.js +222 -119
- package/dist/commands/dimensions.js.map +7 -0
- package/dist/commands/files.js +96 -77
- package/dist/commands/files.js.map +7 -0
- package/dist/commands/formula.js +116 -0
- package/dist/commands/formula.js.map +7 -0
- package/dist/commands/install.js +74 -76
- package/dist/commands/install.js.map +7 -0
- package/dist/commands/list.js +91 -73
- package/dist/commands/list.js.map +7 -0
- package/dist/commands/login.js +137 -98
- package/dist/commands/login.js.map +7 -0
- package/dist/commands/logout.js +59 -41
- package/dist/commands/logout.js.map +7 -0
- package/dist/commands/mcp-server.js +36 -23
- package/dist/commands/mcp-server.js.map +7 -0
- package/dist/commands/model.js +186 -175
- package/dist/commands/model.js.map +7 -0
- package/dist/commands/pull.js +264 -274
- package/dist/commands/pull.js.map +7 -0
- package/dist/commands/push.js +209 -221
- package/dist/commands/push.js.map +7 -0
- package/dist/commands/run.js +276 -321
- package/dist/commands/run.js.map +7 -0
- package/dist/commands/sheets.js +200 -0
- package/dist/commands/sheets.js.map +7 -0
- package/dist/commands/status.js +149 -169
- package/dist/commands/status.js.map +7 -0
- package/dist/commands/variables.js +247 -188
- package/dist/commands/variables.js.map +7 -0
- package/dist/commands/whoami.js +65 -44
- package/dist/commands/whoami.js.map +7 -0
- package/dist/index.js +179 -115
- package/dist/index.js.map +7 -0
- package/dist/mcp/index.js +33 -16
- package/dist/mcp/index.js.map +7 -0
- package/dist/mcp/prompts/workflows.js +191 -145
- package/dist/mcp/prompts/workflows.js.map +7 -0
- package/dist/mcp/resources/documentation.js +158 -148
- package/dist/mcp/resources/documentation.js.map +7 -0
- package/dist/mcp/server.js +56 -33
- package/dist/mcp/server.js.map +7 -0
- package/dist/mcp/tools/appTools.js +309 -277
- package/dist/mcp/tools/appTools.js.map +7 -0
- package/dist/mcp/tools/authTools.js +130 -121
- package/dist/mcp/tools/authTools.js.map +7 -0
- package/dist/mcp/tools/cellTools.js +148 -0
- package/dist/mcp/tools/cellTools.js.map +7 -0
- package/dist/mcp/tools/dashboardTools.js +133 -0
- package/dist/mcp/tools/dashboardTools.js.map +7 -0
- package/dist/mcp/tools/dataTools.js +270 -267
- package/dist/mcp/tools/dataTools.js.map +7 -0
- package/dist/mcp/tools/modelTools.js +575 -229
- package/dist/mcp/tools/modelTools.js.map +7 -0
- package/dist/mcp/tools/runTools.js +201 -203
- package/dist/mcp/tools/runTools.js.map +7 -0
- package/dist/mcp/tools/sheetTools.js +240 -0
- package/dist/mcp/tools/sheetTools.js.map +7 -0
- package/dist/mcp/tools/syncTools.js +335 -314
- package/dist/mcp/tools/syncTools.js.map +7 -0
- package/dist/mcp/utils/helpers.js +117 -123
- package/dist/mcp/utils/helpers.js.map +7 -0
- package/dist/services/appSyncService.js +381 -437
- package/dist/services/appSyncService.js.map +7 -0
- package/dist/services/configService.js +154 -143
- package/dist/services/configService.js.map +7 -0
- package/dist/services/farseerApi.js +422 -399
- package/dist/services/farseerApi.js.map +7 -0
- package/dist/services/farseerFactory.js +208 -273
- package/dist/services/farseerFactory.js.map +7 -0
- package/dist/services/farseerService.js +467 -486
- package/dist/services/farseerService.js.map +7 -0
- package/dist/services/syncService.js +661 -731
- package/dist/services/syncService.js.map +7 -0
- package/dist/utils/constants.js +52 -19
- package/dist/utils/constants.js.map +7 -0
- package/dist/utils/entityResolver.js +78 -0
- package/dist/utils/entityResolver.js.map +7 -0
- package/dist/utils/helpers.js +331 -365
- package/dist/utils/helpers.js.map +7 -0
- package/dist/utils/logger.js +74 -42
- package/dist/utils/logger.js.map +7 -0
- package/package.json +3 -2
|
@@ -1,458 +1,402 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
-
|
|
373
|
-
|
|
374
|
-
|
|
316
|
+
} else {
|
|
317
|
+
result.unchanged.push(local.name);
|
|
318
|
+
}
|
|
375
319
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
-
|
|
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
|
-
|
|
398
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
399
|
+
0 && (module.exports = {
|
|
400
|
+
AppSyncService
|
|
401
|
+
});
|
|
402
|
+
//# sourceMappingURL=appSyncService.js.map
|