farseer-cli 1.0.5 → 1.0.8
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/docs/api-reference.md +372 -0
- package/docs/arquero-patterns.md +158 -0
- package/docs/cli-guide.md +160 -0
- package/docs/how-farseer-works.md +113 -0
- package/docs/import-workflows.md +306 -0
- package/docs/model-export.md +95 -0
- package/docs/new-app-template.md +240 -0
- package/docs/query-formulas.md +97 -0
- package/docs/troubleshooting.md +140 -0
- package/package.json +3 -3
- package/dist/commands/app.js +0 -349
- package/dist/commands/app.js.map +0 -7
- package/dist/commands/apps.js +0 -111
- package/dist/commands/apps.js.map +0 -7
- package/dist/commands/checkout.js +0 -166
- package/dist/commands/checkout.js.map +0 -7
- package/dist/commands/config.js +0 -139
- package/dist/commands/config.js.map +0 -7
- package/dist/commands/diff.js +0 -183
- package/dist/commands/diff.js.map +0 -7
- package/dist/commands/dimensions.js +0 -145
- package/dist/commands/dimensions.js.map +0 -7
- package/dist/commands/files.js +0 -99
- package/dist/commands/files.js.map +0 -7
- package/dist/commands/install.js +0 -79
- package/dist/commands/install.js.map +0 -7
- package/dist/commands/list.js +0 -92
- package/dist/commands/list.js.map +0 -7
- package/dist/commands/login.js +0 -134
- package/dist/commands/login.js.map +0 -7
- package/dist/commands/logout.js +0 -59
- package/dist/commands/logout.js.map +0 -7
- package/dist/commands/mcp-server.js +0 -41
- package/dist/commands/mcp-server.js.map +0 -7
- package/dist/commands/model.js +0 -189
- package/dist/commands/model.js.map +0 -7
- package/dist/commands/pull.js +0 -287
- package/dist/commands/pull.js.map +0 -7
- package/dist/commands/push.js +0 -251
- package/dist/commands/push.js.map +0 -7
- package/dist/commands/run.js +0 -288
- package/dist/commands/run.js.map +0 -7
- package/dist/commands/status.js +0 -145
- package/dist/commands/status.js.map +0 -7
- package/dist/commands/variables.js +0 -176
- package/dist/commands/variables.js.map +0 -7
- package/dist/commands/whoami.js +0 -63
- package/dist/commands/whoami.js.map +0 -7
- package/dist/index.js +0 -153
- package/dist/index.js.map +0 -7
- package/dist/mcp/index.js +0 -35
- package/dist/mcp/index.js.map +0 -7
- package/dist/mcp/prompts/workflows.js +0 -437
- package/dist/mcp/prompts/workflows.js.map +0 -7
- package/dist/mcp/resources/documentation.js +0 -167
- package/dist/mcp/resources/documentation.js.map +0 -7
- package/dist/mcp/server.js +0 -52
- package/dist/mcp/server.js.map +0 -7
- package/dist/mcp/tools/appTools.js +0 -377
- package/dist/mcp/tools/appTools.js.map +0 -7
- package/dist/mcp/tools/authTools.js +0 -158
- package/dist/mcp/tools/authTools.js.map +0 -7
- package/dist/mcp/tools/dataTools.js +0 -366
- package/dist/mcp/tools/dataTools.js.map +0 -7
- package/dist/mcp/tools/modelTools.js +0 -331
- package/dist/mcp/tools/modelTools.js.map +0 -7
- package/dist/mcp/tools/runTools.js +0 -231
- package/dist/mcp/tools/runTools.js.map +0 -7
- package/dist/mcp/tools/syncTools.js +0 -382
- package/dist/mcp/tools/syncTools.js.map +0 -7
- package/dist/mcp/utils/helpers.js +0 -113
- package/dist/mcp/utils/helpers.js.map +0 -7
- package/dist/services/appSyncService.js +0 -399
- package/dist/services/appSyncService.js.map +0 -7
- package/dist/services/configService.js +0 -196
- package/dist/services/configService.js.map +0 -7
- package/dist/services/farseerApi.js +0 -426
- package/dist/services/farseerApi.js.map +0 -7
- package/dist/services/farseerFactory.js +0 -231
- package/dist/services/farseerFactory.js.map +0 -7
- package/dist/services/farseerService.js +0 -614
- package/dist/services/farseerService.js.map +0 -7
- package/dist/services/gitService.js +0 -134
- package/dist/services/gitService.js.map +0 -7
- package/dist/services/syncService.js +0 -415
- package/dist/services/syncService.js.map +0 -7
- package/dist/utils/constants.js +0 -49
- package/dist/utils/constants.js.map +0 -7
- package/dist/utils/helpers.js +0 -433
- package/dist/utils/helpers.js.map +0 -7
- package/dist/utils/logger.js +0 -76
- package/dist/utils/logger.js.map +0 -7
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var syncTools_exports = {};
|
|
19
|
-
__export(syncTools_exports, {
|
|
20
|
-
registerSyncTools: () => registerSyncTools
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(syncTools_exports);
|
|
23
|
-
var import_zod = require("zod");
|
|
24
|
-
var import_diff = require("diff");
|
|
25
|
-
var import_syncService = require("../../services/syncService");
|
|
26
|
-
var import_appSyncService = require("../../services/appSyncService");
|
|
27
|
-
var import_farseerFactory = require("../../services/farseerFactory");
|
|
28
|
-
var import_configService = require("../../services/configService");
|
|
29
|
-
var import_helpers = require("../utils/helpers");
|
|
30
|
-
const pullSchema = {
|
|
31
|
-
tenant: import_zod.z.string().optional().describe("Tenant name. Uses checked-out tenant if omitted."),
|
|
32
|
-
tenantId: import_zod.z.string().optional().describe("Override X-TENANT-ID header if different from tenant name"),
|
|
33
|
-
all: import_zod.z.boolean().optional().describe("Download all files, not just scripts (.ts, .js)")
|
|
34
|
-
};
|
|
35
|
-
const pushSchema = {
|
|
36
|
-
tenant: import_zod.z.string().optional().describe("Tenant name. Uses checked-out tenant if omitted."),
|
|
37
|
-
tenantId: import_zod.z.string().optional().describe("Override X-TENANT-ID header if different from tenant name"),
|
|
38
|
-
force: import_zod.z.boolean().optional().describe("Skip remote changes check (may overwrite remote changes)")
|
|
39
|
-
};
|
|
40
|
-
const statusSchema = {
|
|
41
|
-
tenant: import_zod.z.string().optional().describe("Tenant name. Uses checked-out tenant if omitted."),
|
|
42
|
-
tenantId: import_zod.z.string().optional().describe("Override X-TENANT-ID header"),
|
|
43
|
-
all: import_zod.z.boolean().optional().describe("Show all files, not just scripts")
|
|
44
|
-
};
|
|
45
|
-
const diffSchema = {
|
|
46
|
-
tenant: import_zod.z.string().optional().describe("Tenant name"),
|
|
47
|
-
file: import_zod.z.string().optional().describe("Specific file path to diff. If omitted, shows all differences."),
|
|
48
|
-
showRemote: import_zod.z.boolean().optional().describe("Show only the remote content instead of diff")
|
|
49
|
-
};
|
|
50
|
-
const listFilesSchema = {
|
|
51
|
-
tenant: import_zod.z.string().optional().describe("Tenant name"),
|
|
52
|
-
all: import_zod.z.boolean().optional().describe("Show all files, not just scripts")
|
|
53
|
-
};
|
|
54
|
-
function registerSyncTools(server) {
|
|
55
|
-
server.tool(
|
|
56
|
-
"farseer_pull",
|
|
57
|
-
`Pull (download) files and app configurations from a Farseer instance to the local repository.
|
|
58
|
-
|
|
59
|
-
What gets pulled:
|
|
60
|
-
- TypeScript/JavaScript scripts from Files/ folder (searched recursively)
|
|
61
|
-
- App configurations (saved as JSON in apps/ folder)
|
|
62
|
-
|
|
63
|
-
Files are saved to: apps/<tenant>/files/
|
|
64
|
-
Apps are saved to: apps/<tenant>/apps/
|
|
65
|
-
|
|
66
|
-
By default only script files (.ts, .js, .mjs, .cjs) are pulled.
|
|
67
|
-
Use all=true to pull all files including images, data files, etc.
|
|
68
|
-
|
|
69
|
-
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
70
|
-
pullSchema,
|
|
71
|
-
async (params) => {
|
|
72
|
-
const { tenant: tenantArg, tenantId, all } = params;
|
|
73
|
-
const checkout = (0, import_configService.getCurrentCheckout)();
|
|
74
|
-
const tenant = tenantArg || checkout?.tenant;
|
|
75
|
-
const organisation = tenantArg || checkout?.organisation;
|
|
76
|
-
if (!tenant || !organisation) {
|
|
77
|
-
return (0, import_helpers.tenantRequiredResponse)();
|
|
78
|
-
}
|
|
79
|
-
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenantId || tenant);
|
|
80
|
-
if (!clientResult) {
|
|
81
|
-
return (0, import_helpers.authRequiredResponse)(tenant);
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
const syncService = new import_syncService.SyncService(organisation, clientResult.client);
|
|
85
|
-
const fileResult = await syncService.pull({ all });
|
|
86
|
-
let appResult = null;
|
|
87
|
-
if (clientResult.authType === "jwt") {
|
|
88
|
-
const appSyncService = new import_appSyncService.AppSyncService(organisation, clientResult.client);
|
|
89
|
-
appResult = await appSyncService.pull();
|
|
90
|
-
}
|
|
91
|
-
return (0, import_helpers.successResponse)({
|
|
92
|
-
tenant,
|
|
93
|
-
files: {
|
|
94
|
-
downloaded: fileResult.downloaded,
|
|
95
|
-
deleted: fileResult.deleted,
|
|
96
|
-
unchanged: fileResult.unchanged.length
|
|
97
|
-
},
|
|
98
|
-
apps: appResult ? {
|
|
99
|
-
created: appResult.created,
|
|
100
|
-
updated: appResult.updated,
|
|
101
|
-
deleted: appResult.deleted,
|
|
102
|
-
unchanged: appResult.unchanged.length
|
|
103
|
-
} : { note: "App sync requires browser login (JWT)" },
|
|
104
|
-
message: `Pulled ${fileResult.downloaded.length} files${appResult ? ` and ${appResult.created.length + appResult.updated.length} apps` : ""}`
|
|
105
|
-
});
|
|
106
|
-
} catch (error) {
|
|
107
|
-
return (0, import_helpers.errorResponse)(
|
|
108
|
-
`Pull failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
109
|
-
"NETWORK_ERROR"
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
);
|
|
114
|
-
server.tool(
|
|
115
|
-
"farseer_push",
|
|
116
|
-
`Push (upload) local file and app changes to a Farseer instance.
|
|
117
|
-
|
|
118
|
-
What gets pushed:
|
|
119
|
-
- New/modified scripts from apps/<tenant>/files/
|
|
120
|
-
- New/modified app configurations from apps/<tenant>/apps/
|
|
121
|
-
- Deleted files (if they were previously synced)
|
|
122
|
-
|
|
123
|
-
Important:
|
|
124
|
-
- Checks for unpulled remote changes first to prevent conflicts
|
|
125
|
-
- Use force=true to skip this check (may overwrite remote changes)
|
|
126
|
-
|
|
127
|
-
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
128
|
-
pushSchema,
|
|
129
|
-
async (params) => {
|
|
130
|
-
const { tenant: tenantArg, tenantId, force } = params;
|
|
131
|
-
const checkout = (0, import_configService.getCurrentCheckout)();
|
|
132
|
-
const tenant = tenantArg || checkout?.tenant;
|
|
133
|
-
const organisation = tenantArg || checkout?.organisation;
|
|
134
|
-
if (!tenant || !organisation) {
|
|
135
|
-
return (0, import_helpers.tenantRequiredResponse)();
|
|
136
|
-
}
|
|
137
|
-
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenantId || tenant);
|
|
138
|
-
if (!clientResult) {
|
|
139
|
-
return (0, import_helpers.authRequiredResponse)(tenant);
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
const syncService = new import_syncService.SyncService(organisation, clientResult.client);
|
|
143
|
-
if (!force) {
|
|
144
|
-
const hasRemoteChanges = await syncService.checkRemoteChanges();
|
|
145
|
-
if (hasRemoteChanges) {
|
|
146
|
-
return (0, import_helpers.errorResponse)(
|
|
147
|
-
"Remote has unpulled changes. Pull first or use force=true to overwrite.",
|
|
148
|
-
"VALIDATION_ERROR"
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const fileResult = await syncService.push();
|
|
153
|
-
let appResult = null;
|
|
154
|
-
if (clientResult.authType === "jwt") {
|
|
155
|
-
const appSyncService = new import_appSyncService.AppSyncService(organisation, clientResult.client);
|
|
156
|
-
appResult = await appSyncService.push();
|
|
157
|
-
}
|
|
158
|
-
return (0, import_helpers.successResponse)({
|
|
159
|
-
tenant,
|
|
160
|
-
files: {
|
|
161
|
-
uploaded: fileResult.uploaded,
|
|
162
|
-
updated: fileResult.updated,
|
|
163
|
-
deleted: fileResult.deleted,
|
|
164
|
-
unchanged: fileResult.unchanged.length
|
|
165
|
-
},
|
|
166
|
-
apps: appResult ? {
|
|
167
|
-
created: appResult.created,
|
|
168
|
-
updated: appResult.updated,
|
|
169
|
-
unchanged: appResult.unchanged.length
|
|
170
|
-
} : { note: "App sync requires browser login (JWT)" },
|
|
171
|
-
summary: `Pushed ${fileResult.uploaded.length + fileResult.updated.length} files${appResult ? ` and ${appResult.created.length + appResult.updated.length} apps` : ""}`
|
|
172
|
-
});
|
|
173
|
-
} catch (error) {
|
|
174
|
-
return (0, import_helpers.errorResponse)(
|
|
175
|
-
`Push failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
176
|
-
"NETWORK_ERROR"
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
);
|
|
181
|
-
server.tool(
|
|
182
|
-
"farseer_status",
|
|
183
|
-
`Check the synchronization status between local files and the remote Farseer instance.
|
|
184
|
-
|
|
185
|
-
Shows which files are:
|
|
186
|
-
- Modified locally (changed since last sync)
|
|
187
|
-
- Modified remotely (changed on server since last sync)
|
|
188
|
-
- Only local (new files not yet pushed)
|
|
189
|
-
- Only remote (files not yet pulled)
|
|
190
|
-
- In sync (no changes)
|
|
191
|
-
|
|
192
|
-
Also shows app sync status if using JWT authentication.
|
|
193
|
-
|
|
194
|
-
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
195
|
-
statusSchema,
|
|
196
|
-
async (params) => {
|
|
197
|
-
const { tenant: tenantArg, tenantId, all } = params;
|
|
198
|
-
const checkout = (0, import_configService.getCurrentCheckout)();
|
|
199
|
-
const tenant = tenantArg || checkout?.tenant;
|
|
200
|
-
const organisation = tenantArg || checkout?.organisation;
|
|
201
|
-
if (!tenant || !organisation) {
|
|
202
|
-
return (0, import_helpers.tenantRequiredResponse)();
|
|
203
|
-
}
|
|
204
|
-
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenantId || tenant);
|
|
205
|
-
if (!clientResult) {
|
|
206
|
-
return (0, import_helpers.authRequiredResponse)(tenant);
|
|
207
|
-
}
|
|
208
|
-
try {
|
|
209
|
-
const syncService = new import_syncService.SyncService(organisation, clientResult.client);
|
|
210
|
-
const fileStatus = await syncService.getStatus({ all });
|
|
211
|
-
let appStatus = null;
|
|
212
|
-
if (clientResult.authType === "jwt") {
|
|
213
|
-
const appSyncService = new import_appSyncService.AppSyncService(organisation, clientResult.client);
|
|
214
|
-
appStatus = await appSyncService.getStatus();
|
|
215
|
-
}
|
|
216
|
-
const hasChanges = fileStatus.modifiedLocally.length > 0 || fileStatus.modifiedRemotely.length > 0 || fileStatus.onlyLocal.length > 0 || fileStatus.onlyRemote.length > 0;
|
|
217
|
-
return (0, import_helpers.successResponse)({
|
|
218
|
-
tenant,
|
|
219
|
-
files: {
|
|
220
|
-
modifiedLocally: fileStatus.modifiedLocally,
|
|
221
|
-
modifiedRemotely: fileStatus.modifiedRemotely,
|
|
222
|
-
onlyLocal: fileStatus.onlyLocal,
|
|
223
|
-
onlyRemote: fileStatus.onlyRemote,
|
|
224
|
-
inSync: fileStatus.inSync.length
|
|
225
|
-
},
|
|
226
|
-
apps: appStatus ? {
|
|
227
|
-
newLocal: appStatus.newLocal,
|
|
228
|
-
newRemote: appStatus.newRemote,
|
|
229
|
-
modified: appStatus.modified,
|
|
230
|
-
synced: appStatus.synced.length
|
|
231
|
-
} : { note: "App sync requires browser login (JWT)" },
|
|
232
|
-
summary: hasChanges ? "Changes detected" : "Everything is in sync"
|
|
233
|
-
});
|
|
234
|
-
} catch (error) {
|
|
235
|
-
return (0, import_helpers.errorResponse)(
|
|
236
|
-
`Status check failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
237
|
-
"NETWORK_ERROR"
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
);
|
|
242
|
-
server.tool(
|
|
243
|
-
"farseer_diff",
|
|
244
|
-
`Show the differences between local and remote versions of files.
|
|
245
|
-
|
|
246
|
-
Can show:
|
|
247
|
-
- Unified diff format (default)
|
|
248
|
-
- Just the remote content (showRemote=true)
|
|
249
|
-
|
|
250
|
-
Useful for reviewing changes before pull or push.
|
|
251
|
-
|
|
252
|
-
If no file is specified, shows diffs for all changed files.`,
|
|
253
|
-
diffSchema,
|
|
254
|
-
async (params) => {
|
|
255
|
-
const { tenant: tenantArg, file, showRemote } = params;
|
|
256
|
-
const checkout = (0, import_configService.getCurrentCheckout)();
|
|
257
|
-
const tenant = tenantArg || checkout?.tenant;
|
|
258
|
-
const organisation = tenantArg || checkout?.organisation;
|
|
259
|
-
if (!tenant || !organisation) {
|
|
260
|
-
return (0, import_helpers.tenantRequiredResponse)();
|
|
261
|
-
}
|
|
262
|
-
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
|
|
263
|
-
if (!clientResult) {
|
|
264
|
-
return (0, import_helpers.authRequiredResponse)(tenant);
|
|
265
|
-
}
|
|
266
|
-
try {
|
|
267
|
-
const syncService = new import_syncService.SyncService(organisation, clientResult.client);
|
|
268
|
-
if (file) {
|
|
269
|
-
const { localContent, remoteContent } = await syncService.getFileDiff(file);
|
|
270
|
-
if (showRemote) {
|
|
271
|
-
return (0, import_helpers.successResponse)({
|
|
272
|
-
file,
|
|
273
|
-
remoteContent: remoteContent || "(file does not exist on remote)"
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
const diff = (0, import_diff.createPatch)(
|
|
277
|
-
file,
|
|
278
|
-
remoteContent || "",
|
|
279
|
-
localContent || "",
|
|
280
|
-
"remote",
|
|
281
|
-
"local"
|
|
282
|
-
);
|
|
283
|
-
return (0, import_helpers.successResponse)({
|
|
284
|
-
file,
|
|
285
|
-
localExists: localContent !== null,
|
|
286
|
-
remoteExists: remoteContent !== null,
|
|
287
|
-
diff
|
|
288
|
-
});
|
|
289
|
-
} else {
|
|
290
|
-
const status = await syncService.getStatus();
|
|
291
|
-
const changedFiles = [
|
|
292
|
-
...status.modifiedLocally,
|
|
293
|
-
...status.modifiedRemotely,
|
|
294
|
-
...status.onlyLocal,
|
|
295
|
-
...status.onlyRemote
|
|
296
|
-
];
|
|
297
|
-
const diffs = [];
|
|
298
|
-
for (const f of changedFiles.slice(0, 10)) {
|
|
299
|
-
const { localContent, remoteContent } = await syncService.getFileDiff(f);
|
|
300
|
-
const diff = (0, import_diff.createPatch)(f, remoteContent || "", localContent || "", "remote", "local");
|
|
301
|
-
diffs.push({
|
|
302
|
-
file: f,
|
|
303
|
-
localExists: localContent !== null,
|
|
304
|
-
remoteExists: remoteContent !== null,
|
|
305
|
-
diff
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
return (0, import_helpers.successResponse)({
|
|
309
|
-
totalChangedFiles: changedFiles.length,
|
|
310
|
-
diffs,
|
|
311
|
-
note: changedFiles.length > 10 ? `Showing first 10 of ${changedFiles.length} changed files` : void 0
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
} catch (error) {
|
|
315
|
-
return (0, import_helpers.errorResponse)(
|
|
316
|
-
`Diff failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
317
|
-
"NETWORK_ERROR"
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
);
|
|
322
|
-
server.tool(
|
|
323
|
-
"farseer_list_files",
|
|
324
|
-
`List all files stored on the remote Farseer instance in the Files/ folder.
|
|
325
|
-
|
|
326
|
-
By default shows only script files (.ts, .js, .mjs, .cjs).
|
|
327
|
-
Use all=true to show all files including images, data files, etc.
|
|
328
|
-
|
|
329
|
-
Returns file paths relative to the Files/ folder.`,
|
|
330
|
-
listFilesSchema,
|
|
331
|
-
async (params) => {
|
|
332
|
-
const { tenant: tenantArg, all } = params;
|
|
333
|
-
const checkout = (0, import_configService.getCurrentCheckout)();
|
|
334
|
-
const tenant = tenantArg || checkout?.tenant;
|
|
335
|
-
const organisation = tenantArg || checkout?.organisation;
|
|
336
|
-
if (!tenant || !organisation) {
|
|
337
|
-
return (0, import_helpers.tenantRequiredResponse)();
|
|
338
|
-
}
|
|
339
|
-
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
|
|
340
|
-
if (!clientResult) {
|
|
341
|
-
return (0, import_helpers.authRequiredResponse)(tenant);
|
|
342
|
-
}
|
|
343
|
-
try {
|
|
344
|
-
let files = await clientResult.client.listFiles();
|
|
345
|
-
if (!all) {
|
|
346
|
-
const scriptExtensions = [".ts", ".js", ".mjs", ".cjs"];
|
|
347
|
-
files = files.filter(
|
|
348
|
-
(f) => scriptExtensions.some((ext) => f.name.toLowerCase().endsWith(ext))
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
const byDirectory = {};
|
|
352
|
-
for (const file of files) {
|
|
353
|
-
const dir = file.path.includes("/") ? file.path.split("/").slice(0, -1).join("/") : ".";
|
|
354
|
-
if (!byDirectory[dir]) {
|
|
355
|
-
byDirectory[dir] = [];
|
|
356
|
-
}
|
|
357
|
-
byDirectory[dir].push(file.name);
|
|
358
|
-
}
|
|
359
|
-
return (0, import_helpers.successResponse)({
|
|
360
|
-
tenant,
|
|
361
|
-
totalFiles: files.length,
|
|
362
|
-
files: files.map((f) => ({
|
|
363
|
-
name: f.name,
|
|
364
|
-
path: f.path,
|
|
365
|
-
reference: f.reference
|
|
366
|
-
})),
|
|
367
|
-
byDirectory
|
|
368
|
-
});
|
|
369
|
-
} catch (error) {
|
|
370
|
-
return (0, import_helpers.errorResponse)(
|
|
371
|
-
`List files failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
372
|
-
"NETWORK_ERROR"
|
|
373
|
-
);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
379
|
-
0 && (module.exports = {
|
|
380
|
-
registerSyncTools
|
|
381
|
-
});
|
|
382
|
-
//# sourceMappingURL=syncTools.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/mcp/tools/syncTools.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * File Synchronization Tools\n *\n * Tools for syncing files between local repository and Farseer instance.\n */\n\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport { createPatch } from 'diff';\nimport { SyncService } from '../../services/syncService';\nimport { AppSyncService } from '../../services/appSyncService';\nimport { getFarseerClientWithFallback } from '../../services/farseerFactory';\nimport { getCurrentCheckout } from '../../services/configService';\nimport {\n successResponse,\n errorResponse,\n authRequiredResponse,\n tenantRequiredResponse,\n} from '../utils/helpers';\n\n// Define schemas outside of tool registration to avoid deep type instantiation\nconst pullSchema = {\n tenant: z.string().optional().describe('Tenant name. Uses checked-out tenant if omitted.'),\n tenantId: z\n .string()\n .optional()\n .describe('Override X-TENANT-ID header if different from tenant name'),\n all: z.boolean().optional().describe('Download all files, not just scripts (.ts, .js)'),\n};\n\nconst pushSchema = {\n tenant: z.string().optional().describe('Tenant name. Uses checked-out tenant if omitted.'),\n tenantId: z\n .string()\n .optional()\n .describe('Override X-TENANT-ID header if different from tenant name'),\n force: z.boolean().optional().describe('Skip remote changes check (may overwrite remote changes)'),\n};\n\nconst statusSchema = {\n tenant: z.string().optional().describe('Tenant name. Uses checked-out tenant if omitted.'),\n tenantId: z.string().optional().describe('Override X-TENANT-ID header'),\n all: z.boolean().optional().describe('Show all files, not just scripts'),\n};\n\nconst diffSchema = {\n tenant: z.string().optional().describe('Tenant name'),\n file: z.string().optional().describe('Specific file path to diff. If omitted, shows all differences.'),\n showRemote: z.boolean().optional().describe('Show only the remote content instead of diff'),\n};\n\nconst listFilesSchema = {\n tenant: z.string().optional().describe('Tenant name'),\n all: z.boolean().optional().describe('Show all files, not just scripts'),\n};\n\nexport function registerSyncTools(server: McpServer): void {\n // farseer_pull - Download files from remote\n server.tool(\n 'farseer_pull',\n `Pull (download) files and app configurations from a Farseer instance to the local repository.\n\nWhat gets pulled:\n- TypeScript/JavaScript scripts from Files/ folder (searched recursively)\n- App configurations (saved as JSON in apps/ folder)\n\nFiles are saved to: apps/<tenant>/files/\nApps are saved to: apps/<tenant>/apps/\n\nBy default only script files (.ts, .js, .mjs, .cjs) are pulled.\nUse all=true to pull all files including images, data files, etc.\n\nIf no tenant is specified, uses the currently checked-out tenant.`,\n pullSchema,\n async (params: { tenant?: string; tenantId?: string; all?: boolean }) => {\n const { tenant: tenantArg, tenantId, all } = params;\n const checkout = getCurrentCheckout();\n const tenant = tenantArg || checkout?.tenant;\n const organisation = tenantArg || checkout?.organisation;\n\n if (!tenant || !organisation) {\n return tenantRequiredResponse();\n }\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenantId || tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n // Pull files\n const syncService = new SyncService(organisation, clientResult.client);\n const fileResult = await syncService.pull({ all });\n\n // Pull apps (only with JWT auth)\n let appResult = null;\n if (clientResult.authType === 'jwt') {\n const appSyncService = new AppSyncService(organisation, clientResult.client);\n appResult = await appSyncService.pull();\n }\n\n return successResponse({\n tenant,\n files: {\n downloaded: fileResult.downloaded,\n deleted: fileResult.deleted,\n unchanged: fileResult.unchanged.length,\n },\n apps: appResult\n ? {\n created: appResult.created,\n updated: appResult.updated,\n deleted: appResult.deleted,\n unchanged: appResult.unchanged.length,\n }\n : { note: 'App sync requires browser login (JWT)' },\n message: `Pulled ${fileResult.downloaded.length} files${appResult ? ` and ${appResult.created.length + appResult.updated.length} apps` : ''}`,\n });\n } catch (error) {\n return errorResponse(\n `Pull failed: ${error instanceof Error ? error.message : 'Unknown error'}`,\n 'NETWORK_ERROR'\n );\n }\n }\n );\n\n // farseer_push - Upload files to remote\n server.tool(\n 'farseer_push',\n `Push (upload) local file and app changes to a Farseer instance.\n\nWhat gets pushed:\n- New/modified scripts from apps/<tenant>/files/\n- New/modified app configurations from apps/<tenant>/apps/\n- Deleted files (if they were previously synced)\n\nImportant:\n- Checks for unpulled remote changes first to prevent conflicts\n- Use force=true to skip this check (may overwrite remote changes)\n\nIf no tenant is specified, uses the currently checked-out tenant.`,\n pushSchema,\n async (params: { tenant?: string; tenantId?: string; force?: boolean }) => {\n const { tenant: tenantArg, tenantId, force } = params;\n const checkout = getCurrentCheckout();\n const tenant = tenantArg || checkout?.tenant;\n const organisation = tenantArg || checkout?.organisation;\n\n if (!tenant || !organisation) {\n return tenantRequiredResponse();\n }\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenantId || tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n const syncService = new SyncService(organisation, clientResult.client);\n\n // Check for remote changes unless force is true\n if (!force) {\n const hasRemoteChanges = await syncService.checkRemoteChanges();\n if (hasRemoteChanges) {\n return errorResponse(\n 'Remote has unpulled changes. Pull first or use force=true to overwrite.',\n 'VALIDATION_ERROR'\n );\n }\n }\n\n // Push files\n const fileResult = await syncService.push();\n\n // Push apps (only with JWT auth)\n let appResult = null;\n if (clientResult.authType === 'jwt') {\n const appSyncService = new AppSyncService(organisation, clientResult.client);\n appResult = await appSyncService.push();\n }\n\n return successResponse({\n tenant,\n files: {\n uploaded: fileResult.uploaded,\n updated: fileResult.updated,\n deleted: fileResult.deleted,\n unchanged: fileResult.unchanged.length,\n },\n apps: appResult\n ? {\n created: appResult.created,\n updated: appResult.updated,\n unchanged: appResult.unchanged.length,\n }\n : { note: 'App sync requires browser login (JWT)' },\n summary: `Pushed ${fileResult.uploaded.length + fileResult.updated.length} files${appResult ? ` and ${appResult.created.length + appResult.updated.length} apps` : ''}`,\n });\n } catch (error) {\n return errorResponse(\n `Push failed: ${error instanceof Error ? error.message : 'Unknown error'}`,\n 'NETWORK_ERROR'\n );\n }\n }\n );\n\n // farseer_status - Check sync status\n server.tool(\n 'farseer_status',\n `Check the synchronization status between local files and the remote Farseer instance.\n\nShows which files are:\n- Modified locally (changed since last sync)\n- Modified remotely (changed on server since last sync)\n- Only local (new files not yet pushed)\n- Only remote (files not yet pulled)\n- In sync (no changes)\n\nAlso shows app sync status if using JWT authentication.\n\nIf no tenant is specified, uses the currently checked-out tenant.`,\n statusSchema,\n async (params: { tenant?: string; tenantId?: string; all?: boolean }) => {\n const { tenant: tenantArg, tenantId, all } = params;\n const checkout = getCurrentCheckout();\n const tenant = tenantArg || checkout?.tenant;\n const organisation = tenantArg || checkout?.organisation;\n\n if (!tenant || !organisation) {\n return tenantRequiredResponse();\n }\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenantId || tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n const syncService = new SyncService(organisation, clientResult.client);\n const fileStatus = await syncService.getStatus({ all });\n\n // Get app status (only with JWT auth)\n let appStatus = null;\n if (clientResult.authType === 'jwt') {\n const appSyncService = new AppSyncService(organisation, clientResult.client);\n appStatus = await appSyncService.getStatus();\n }\n\n const hasChanges =\n fileStatus.modifiedLocally.length > 0 ||\n fileStatus.modifiedRemotely.length > 0 ||\n fileStatus.onlyLocal.length > 0 ||\n fileStatus.onlyRemote.length > 0;\n\n return successResponse({\n tenant,\n files: {\n modifiedLocally: fileStatus.modifiedLocally,\n modifiedRemotely: fileStatus.modifiedRemotely,\n onlyLocal: fileStatus.onlyLocal,\n onlyRemote: fileStatus.onlyRemote,\n inSync: fileStatus.inSync.length,\n },\n apps: appStatus\n ? {\n newLocal: appStatus.newLocal,\n newRemote: appStatus.newRemote,\n modified: appStatus.modified,\n synced: appStatus.synced.length,\n }\n : { note: 'App sync requires browser login (JWT)' },\n summary: hasChanges ? 'Changes detected' : 'Everything is in sync',\n });\n } catch (error) {\n return errorResponse(\n `Status check failed: ${error instanceof Error ? error.message : 'Unknown error'}`,\n 'NETWORK_ERROR'\n );\n }\n }\n );\n\n // farseer_diff - Show file differences\n server.tool(\n 'farseer_diff',\n `Show the differences between local and remote versions of files.\n\nCan show:\n- Unified diff format (default)\n- Just the remote content (showRemote=true)\n\nUseful for reviewing changes before pull or push.\n\nIf no file is specified, shows diffs for all changed files.`,\n diffSchema,\n async (params: { tenant?: string; file?: string; showRemote?: boolean }) => {\n const { tenant: tenantArg, file, showRemote } = params;\n const checkout = getCurrentCheckout();\n const tenant = tenantArg || checkout?.tenant;\n const organisation = tenantArg || checkout?.organisation;\n\n if (!tenant || !organisation) {\n return tenantRequiredResponse();\n }\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n const syncService = new SyncService(organisation, clientResult.client);\n\n if (file) {\n // Single file diff\n const { localContent, remoteContent } = await syncService.getFileDiff(file);\n\n if (showRemote) {\n return successResponse({\n file,\n remoteContent: remoteContent || '(file does not exist on remote)',\n });\n }\n\n const diff = createPatch(\n file,\n remoteContent || '',\n localContent || '',\n 'remote',\n 'local'\n );\n\n return successResponse({\n file,\n localExists: localContent !== null,\n remoteExists: remoteContent !== null,\n diff,\n });\n } else {\n // All changed files\n const status = await syncService.getStatus();\n const changedFiles = [\n ...status.modifiedLocally,\n ...status.modifiedRemotely,\n ...status.onlyLocal,\n ...status.onlyRemote,\n ];\n\n const diffs: Array<{\n file: string;\n localExists: boolean;\n remoteExists: boolean;\n diff: string;\n }> = [];\n\n for (const f of changedFiles.slice(0, 10)) {\n // Limit to 10 files\n const { localContent, remoteContent } = await syncService.getFileDiff(f);\n const diff = createPatch(f, remoteContent || '', localContent || '', 'remote', 'local');\n diffs.push({\n file: f,\n localExists: localContent !== null,\n remoteExists: remoteContent !== null,\n diff,\n });\n }\n\n return successResponse({\n totalChangedFiles: changedFiles.length,\n diffs,\n note:\n changedFiles.length > 10\n ? `Showing first 10 of ${changedFiles.length} changed files`\n : undefined,\n });\n }\n } catch (error) {\n return errorResponse(\n `Diff failed: ${error instanceof Error ? error.message : 'Unknown error'}`,\n 'NETWORK_ERROR'\n );\n }\n }\n );\n\n // farseer_list_files - List remote files\n server.tool(\n 'farseer_list_files',\n `List all files stored on the remote Farseer instance in the Files/ folder.\n\nBy default shows only script files (.ts, .js, .mjs, .cjs).\nUse all=true to show all files including images, data files, etc.\n\nReturns file paths relative to the Files/ folder.`,\n listFilesSchema,\n async (params: { tenant?: string; all?: boolean }) => {\n const { tenant: tenantArg, all } = params;\n const checkout = getCurrentCheckout();\n const tenant = tenantArg || checkout?.tenant;\n const organisation = tenantArg || checkout?.organisation;\n\n if (!tenant || !organisation) {\n return tenantRequiredResponse();\n }\n\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n if (!clientResult) {\n return authRequiredResponse(tenant);\n }\n\n try {\n let files = await clientResult.client.listFiles();\n\n // Filter to scripts unless --all\n if (!all) {\n const scriptExtensions = ['.ts', '.js', '.mjs', '.cjs'];\n files = files.filter((f) =>\n scriptExtensions.some((ext) => f.name.toLowerCase().endsWith(ext))\n );\n }\n\n // Group by directory\n const byDirectory: Record<string, string[]> = {};\n for (const file of files) {\n const dir = file.path.includes('/') ? file.path.split('/').slice(0, -1).join('/') : '.';\n if (!byDirectory[dir]) {\n byDirectory[dir] = [];\n }\n byDirectory[dir].push(file.name);\n }\n\n return successResponse({\n tenant,\n totalFiles: files.length,\n files: files.map((f) => ({\n name: f.name,\n path: f.path,\n reference: f.reference,\n })),\n byDirectory,\n });\n } catch (error) {\n return errorResponse(\n `List files failed: ${error instanceof Error ? error.message : 'Unknown error'}`,\n 'NETWORK_ERROR'\n );\n }\n }\n );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iBAAkB;AAClB,kBAA4B;AAC5B,yBAA4B;AAC5B,4BAA+B;AAC/B,4BAA6C;A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OAAO,UAAU;AAGhD,YAAI,CAAC,KAAK;AACN,gBAAM,mBAAmB,CAAC,OAAO,OAAO,QAAQ,MAAM;AACtD,kBAAQ,MAAM;AAAA,YAAO,CAAC,MAClB,iBAAiB,KAAK,CAAC,QAAQ,EAAE,KAAK,YAAY,EAAE,SAAS,GAAG,CAAC;AAAA,UACrE;AAAA,QACJ;AAGA,cAAM,cAAwC,CAAC;AAC/C,mBAAW,QAAQ,OAAO;AACtB,gBAAM,MAAM,KAAK,KAAK,SAAS,GAAG,IAAI,KAAK,KAAK,MAAM,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,KAAK,GAAG,IAAI;AACpF,cAAI,CAAC,YAAY,GAAG,GAAG;AACnB,wBAAY,GAAG,IAAI,CAAC;AAAA,UACxB;AACA,sBAAY,GAAG,EAAE,KAAK,KAAK,IAAI;AAAA,QACnC;AAEA,mBAAO,gCAAgB;AAAA,UACnB;AAAA,UACA,YAAY,MAAM;AAAA,UAClB,OAAO,MAAM,IAAI,CAAC,OAAO;AAAA,YACrB,MAAM,EAAE;AAAA,YACR,MAAM,EAAE;AAAA,YACR,WAAW,EAAE;AAAA,UACjB,EAAE;AAAA,UACF;AAAA,QACJ,CAAC;AAAA,MACL,SAAS,OAAO;AACZ,mBAAO;AAAA,UACH,sBAAsB,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,UAC9E;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var helpers_exports = {};
|
|
19
|
-
__export(helpers_exports, {
|
|
20
|
-
authRequiredResponse: () => authRequiredResponse,
|
|
21
|
-
errorResponse: () => errorResponse,
|
|
22
|
-
getAuthStatus: () => getAuthStatus,
|
|
23
|
-
getClient: () => getClient,
|
|
24
|
-
resolveOrganisation: () => resolveOrganisation,
|
|
25
|
-
resolveTenant: () => resolveTenant,
|
|
26
|
-
successResponse: () => successResponse,
|
|
27
|
-
tenantRequiredResponse: () => tenantRequiredResponse
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(helpers_exports);
|
|
30
|
-
var import_configService = require("../../services/configService");
|
|
31
|
-
var import_farseerFactory = require("../../services/farseerFactory");
|
|
32
|
-
function resolveTenant(tenantArg) {
|
|
33
|
-
if (tenantArg) {
|
|
34
|
-
return tenantArg;
|
|
35
|
-
}
|
|
36
|
-
return (0, import_configService.getCurrentTenant)() || null;
|
|
37
|
-
}
|
|
38
|
-
function resolveOrganisation(orgArg, tenantArg) {
|
|
39
|
-
if (orgArg) {
|
|
40
|
-
return orgArg;
|
|
41
|
-
}
|
|
42
|
-
if (tenantArg) {
|
|
43
|
-
return tenantArg;
|
|
44
|
-
}
|
|
45
|
-
const checkout = (0, import_configService.getCurrentCheckout)();
|
|
46
|
-
return checkout?.organisation || null;
|
|
47
|
-
}
|
|
48
|
-
async function getClient(tenant, tenantId) {
|
|
49
|
-
const result = await (0, import_farseerFactory.getFarseerClientWithFallback)(tenant, tenantId);
|
|
50
|
-
return result?.client || null;
|
|
51
|
-
}
|
|
52
|
-
function successResponse(data) {
|
|
53
|
-
return {
|
|
54
|
-
content: [
|
|
55
|
-
{
|
|
56
|
-
type: "text",
|
|
57
|
-
text: JSON.stringify({ success: true, ...data }, null, 2)
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function errorResponse(message, errorCode) {
|
|
63
|
-
return {
|
|
64
|
-
content: [
|
|
65
|
-
{
|
|
66
|
-
type: "text",
|
|
67
|
-
text: JSON.stringify(
|
|
68
|
-
{
|
|
69
|
-
success: false,
|
|
70
|
-
error: message,
|
|
71
|
-
errorCode: errorCode || "UNKNOWN"
|
|
72
|
-
},
|
|
73
|
-
null,
|
|
74
|
-
2
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
],
|
|
78
|
-
isError: true
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function authRequiredResponse(tenant) {
|
|
82
|
-
const message = tenant ? `Authentication required for tenant "${tenant}". Run "farseer login" to authenticate.` : 'Authentication required. Run "farseer login" to authenticate.';
|
|
83
|
-
return errorResponse(message, "AUTH_REQUIRED");
|
|
84
|
-
}
|
|
85
|
-
function tenantRequiredResponse() {
|
|
86
|
-
return errorResponse(
|
|
87
|
-
'No tenant specified. Either provide tenant parameter or run "farseer checkout <tenant>" first.',
|
|
88
|
-
"VALIDATION_ERROR"
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
function getAuthStatus() {
|
|
92
|
-
const auth = (0, import_configService.getUserAuth)();
|
|
93
|
-
const checkout = (0, import_configService.getCurrentCheckout)();
|
|
94
|
-
const credentials = (0, import_configService.listCredentials)();
|
|
95
|
-
return {
|
|
96
|
-
jwtValid: (0, import_configService.isUserAuthValid)(),
|
|
97
|
-
jwtExpiresAt: auth?.expiresAt,
|
|
98
|
-
currentCheckout: checkout,
|
|
99
|
-
configuredTenants: Object.keys(credentials)
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
-
0 && (module.exports = {
|
|
104
|
-
authRequiredResponse,
|
|
105
|
-
errorResponse,
|
|
106
|
-
getAuthStatus,
|
|
107
|
-
getClient,
|
|
108
|
-
resolveOrganisation,
|
|
109
|
-
resolveTenant,
|
|
110
|
-
successResponse,
|
|
111
|
-
tenantRequiredResponse
|
|
112
|
-
});
|
|
113
|
-
//# sourceMappingURL=helpers.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/mcp/utils/helpers.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * MCP Utility Functions\n *\n * Helper functions for MCP tools including tenant resolution and response formatting.\n */\n\nimport {\n getCurrentCheckout,\n getCurrentTenant,\n getUserAuth,\n isUserAuthValid,\n listCredentials,\n} from '../../services/configService';\nimport { getFarseerClientWithFallback, IFarseerClient } from '../../services/farseerFactory';\n\n/**\n * Resolve tenant from argument or checkout state\n */\nexport function resolveTenant(tenantArg?: string): string | null {\n if (tenantArg) {\n return tenantArg;\n }\n return getCurrentTenant() || null;\n}\n\n/**\n * Resolve organisation from argument or checkout state\n */\nexport function resolveOrganisation(orgArg?: string, tenantArg?: string): string | null {\n if (orgArg) {\n return orgArg;\n }\n if (tenantArg) {\n // If tenant specified but not org, assume org = tenant\n return tenantArg;\n }\n const checkout = getCurrentCheckout();\n return checkout?.organisation || null;\n}\n\n/**\n * Get authenticated Farseer client\n */\nexport async function getClient(tenant: string, tenantId?: string): Promise<IFarseerClient | null> {\n const result = await getFarseerClientWithFallback(tenant, tenantId);\n return result?.client || null;\n}\n\n/**\n * Create a success response\n */\nexport function successResponse(data: Record<string, unknown>): { content: Array<{ type: 'text'; text: string }> } {\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify({ success: true, ...data }, null, 2),\n },\n ],\n };\n}\n\n/**\n * Create an error response\n */\nexport function errorResponse(\n message: string,\n errorCode?: 'AUTH_REQUIRED' | 'NOT_FOUND' | 'NETWORK_ERROR' | 'VALIDATION_ERROR' | 'UNKNOWN'\n): { content: Array<{ type: 'text'; text: string }>; isError: true } {\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(\n {\n success: false,\n error: message,\n errorCode: errorCode || 'UNKNOWN',\n },\n null,\n 2\n ),\n },\n ],\n isError: true,\n };\n}\n\n/**\n * Create auth required error response\n */\nexport function authRequiredResponse(tenant?: string): {\n content: Array<{ type: 'text'; text: string }>;\n isError: true;\n} {\n const message = tenant\n ? `Authentication required for tenant \"${tenant}\". Run \"farseer login\" to authenticate.`\n : 'Authentication required. Run \"farseer login\" to authenticate.';\n\n return errorResponse(message, 'AUTH_REQUIRED');\n}\n\n/**\n * Create tenant required error response\n */\nexport function tenantRequiredResponse(): { content: Array<{ type: 'text'; text: string }>; isError: true } {\n return errorResponse(\n 'No tenant specified. Either provide tenant parameter or run \"farseer checkout <tenant>\" first.',\n 'VALIDATION_ERROR'\n );\n}\n\n/**\n * Get auth status info\n */\nexport function getAuthStatus(): {\n jwtValid: boolean;\n jwtExpiresAt?: string;\n currentCheckout?: { organisation: string; tenant: string };\n configuredTenants: string[];\n} {\n const auth = getUserAuth();\n const checkout = getCurrentCheckout();\n const credentials = listCredentials();\n\n return {\n jwtValid: isUserAuthValid(),\n jwtExpiresAt: auth?.expiresAt,\n currentCheckout: checkout,\n configuredTenants: Object.keys(credentials),\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,2BAMO;AACP,4BAA6D;AAKtD,SAAS,cAAc,WAAmC;AAC7D,MAAI,WAAW;AACX,WAAO;AAAA,EACX;AACA,aAAO,uCAAiB,KAAK;AACjC;AAKO,SAAS,oBAAoB,QAAiB,WAAmC;AACpF,MAAI,QAAQ;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