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,82 +1,104 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 dataTools_exports = {};
|
|
19
|
-
__export(dataTools_exports, {
|
|
20
|
-
registerDataTools: () => registerDataTools
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(dataTools_exports);
|
|
23
|
-
var import_zod = require("zod");
|
|
24
|
-
var import_farseerFactory = require("../../services/farseerFactory");
|
|
25
|
-
var import_helpers = require("../utils/helpers");
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Data Operation Tools
|
|
4
|
+
*
|
|
5
|
+
* MCP tools for data export, import jobs, and file management on Farseer instances.
|
|
6
|
+
* These use the native farseer-client for full API access.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.registerDataTools = registerDataTools;
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
const farseerFactory_1 = require("../../services/farseerFactory");
|
|
12
|
+
const helpers_1 = require("../utils/helpers");
|
|
26
13
|
async function extractErrorMessage(error) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
if (error instanceof Error)
|
|
15
|
+
return error.message;
|
|
16
|
+
if (error && typeof error === 'object' && 'status' in error && 'statusText' in error) {
|
|
17
|
+
const resp = error;
|
|
18
|
+
const body = resp.text ? await resp.text() : '';
|
|
19
|
+
return `HTTP ${resp.status} ${resp.statusText}${body ? ': ' + body : ''}`;
|
|
20
|
+
}
|
|
21
|
+
return String(error);
|
|
34
22
|
}
|
|
23
|
+
// Define schemas outside of tool registration to avoid deep type instantiation
|
|
35
24
|
const exportVariableDataSchema = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
organisation: zod_1.z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
|
|
29
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
|
|
30
|
+
variableName: zod_1.z.string().describe('Name of the variable to export'),
|
|
31
|
+
format: zod_1.z.enum(['csv', 'json']).optional().describe('Output format (default: csv)'),
|
|
32
|
+
limit: zod_1.z.number().optional().describe('Maximum number of rows to return'),
|
|
41
33
|
};
|
|
42
34
|
const loadVariableDataSchema = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
organisation: zod_1.z
|
|
36
|
+
.string()
|
|
37
|
+
.optional()
|
|
38
|
+
.describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
|
|
39
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
|
|
40
|
+
variableName: zod_1.z.string().describe('Name of the variable to load'),
|
|
41
|
+
dimensions: zod_1.z.array(zod_1.z.string()).optional().describe('Dimension table names to include as columns in the export'),
|
|
47
42
|
};
|
|
48
43
|
const createImportJobSchema = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
44
|
+
organisation: zod_1.z
|
|
45
|
+
.string()
|
|
46
|
+
.optional()
|
|
47
|
+
.describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
|
|
48
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
|
|
49
|
+
title: zod_1.z.string().describe('Import job title (shown in import history)'),
|
|
50
|
+
columns: zod_1.z
|
|
51
|
+
.array(zod_1.z.object({
|
|
52
|
+
type: zod_1.z.enum(['DIMENSION_TABLE', 'VARIABLE', 'DATE', 'DESCRIPTION']).describe('Column type'),
|
|
53
|
+
dimensionTableName: zod_1.z.string().optional().describe('For DIMENSION_TABLE: name of the dimension table'),
|
|
54
|
+
variableName: zod_1.z.string().optional().describe('For VARIABLE: name of the variable'),
|
|
55
|
+
columnName: zod_1.z.string().optional().describe('Column header name'),
|
|
56
|
+
dateFormat: zod_1.z.string().optional().describe('For DATE: date format string'),
|
|
57
|
+
dimensionsNames: zod_1.z
|
|
58
|
+
.array(zod_1.z.object({
|
|
59
|
+
tableName: zod_1.z.string(),
|
|
60
|
+
memberName: zod_1.z.string(),
|
|
61
|
+
}))
|
|
62
|
+
.optional()
|
|
63
|
+
.describe('For VARIABLE: fixed dimension members (filters) for this variable column'),
|
|
64
|
+
}))
|
|
65
|
+
.describe('Column definitions matching the data structure'),
|
|
66
|
+
rows: zod_1.z
|
|
67
|
+
.array(zod_1.z.array(zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.null()])))
|
|
68
|
+
.describe('Data rows - each row is an array of values matching column order'),
|
|
69
|
+
labels: zod_1.z
|
|
70
|
+
.array(zod_1.z.string())
|
|
71
|
+
.optional()
|
|
72
|
+
.describe('Labels for grouping import jobs (used by undoPrevious to revert jobs with same labels)'),
|
|
73
|
+
undoPrevious: zod_1.z
|
|
74
|
+
.boolean()
|
|
75
|
+
.optional()
|
|
76
|
+
.describe('Revert previous import jobs with the same labels before committing (default: false)'),
|
|
77
|
+
importDimensions: zod_1.z
|
|
78
|
+
.boolean()
|
|
79
|
+
.optional()
|
|
80
|
+
.describe('Auto-create any missing dimension members before committing (default: false)'),
|
|
81
|
+
overwriteCells: zod_1.z
|
|
82
|
+
.boolean()
|
|
83
|
+
.optional()
|
|
84
|
+
.describe('Overwrite existing cell values (default: false - adds to existing values)'),
|
|
68
85
|
};
|
|
69
86
|
const createFileSchema = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
organisation: zod_1.z
|
|
88
|
+
.string()
|
|
89
|
+
.optional()
|
|
90
|
+
.describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
|
|
91
|
+
tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
|
|
92
|
+
fileName: zod_1.z.string().describe('Name of the file to create or update'),
|
|
93
|
+
folderPath: zod_1.z
|
|
94
|
+
.array(zod_1.z.string())
|
|
95
|
+
.optional()
|
|
96
|
+
.describe('Folder path as array (e.g., ["Files", "Reports"]). Default: ["Files"]'),
|
|
97
|
+
content: zod_1.z.string().describe('File content as text string'),
|
|
75
98
|
};
|
|
76
99
|
function registerDataTools(server) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
`Export data from a Farseer variable as CSV or JSON.
|
|
100
|
+
// farseer_export_variable_data - Export variable data
|
|
101
|
+
server.tool('farseer_export_variable_data', `Export data from a Farseer variable as CSV or JSON.
|
|
80
102
|
|
|
81
103
|
Uses the ExportApi.exportFormula() method to export variable data.
|
|
82
104
|
The variable name is passed as the formula, and the result contains
|
|
@@ -86,47 +108,43 @@ Returns the raw CSV/JSON text inline so you can analyze it directly.
|
|
|
86
108
|
|
|
87
109
|
Use the 'limit' parameter to restrict row count for large variables.
|
|
88
110
|
|
|
89
|
-
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
90
|
-
|
|
111
|
+
If no tenant is specified, uses the currently checked-out tenant.`, exportVariableDataSchema,
|
|
112
|
+
// @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
|
|
91
113
|
async (params) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
const { organisation, tenant } = resolved;
|
|
97
|
-
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
98
|
-
if (!nativeClient) {
|
|
99
|
-
return (0, import_helpers.authRequiredResponse)(tenant);
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
const exportRequest = {
|
|
103
|
-
formula: params.variableName,
|
|
104
|
-
format: params.format || "csv"
|
|
105
|
-
};
|
|
106
|
-
if (params.limit) {
|
|
107
|
-
exportRequest.limit = params.limit;
|
|
114
|
+
const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
|
|
115
|
+
if (!resolved) {
|
|
116
|
+
return (0, helpers_1.tenantRequiredResponse)();
|
|
108
117
|
}
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
const { organisation, tenant } = resolved;
|
|
119
|
+
const nativeClient = await (0, farseerFactory_1.getNativeFarseerClient)(organisation, tenant);
|
|
120
|
+
if (!nativeClient) {
|
|
121
|
+
return (0, helpers_1.authRequiredResponse)(tenant);
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const exportRequest = {
|
|
125
|
+
formula: params.variableName,
|
|
126
|
+
format: params.format || 'csv',
|
|
127
|
+
};
|
|
128
|
+
if (params.limit) {
|
|
129
|
+
exportRequest.limit = params.limit;
|
|
130
|
+
}
|
|
131
|
+
const blob = await nativeClient.export.exportFormula(exportRequest);
|
|
132
|
+
const text = await blob.text();
|
|
133
|
+
const lines = text.split('\n').filter((l) => l.trim()).length;
|
|
134
|
+
return (0, helpers_1.successResponse)({
|
|
135
|
+
tenant,
|
|
136
|
+
variable: params.variableName,
|
|
137
|
+
format: params.format || 'csv',
|
|
138
|
+
rowCount: Math.max(0, lines - 1),
|
|
139
|
+
data: text,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
return (0, helpers_1.errorResponse)(`Export variable data failed: ${await extractErrorMessage(error)}`, 'NETWORK_ERROR');
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
// farseer_load_variable_data - Load variable data with specific dimensions
|
|
147
|
+
server.tool('farseer_load_variable_data', `Load data from a Farseer variable into a structured CSV format.
|
|
130
148
|
|
|
131
149
|
Uses the ExportApi.exportFormula() method to export variable data as CSV.
|
|
132
150
|
Returns all data cells for the variable across all its dimensions.
|
|
@@ -138,44 +156,40 @@ Example usage:
|
|
|
138
156
|
- Load "Revenue" data
|
|
139
157
|
- Load "Revenue" with dimensions ["Product", "Years", "Months"]
|
|
140
158
|
|
|
141
|
-
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
142
|
-
|
|
159
|
+
If no tenant is specified, uses the currently checked-out tenant.`, loadVariableDataSchema,
|
|
160
|
+
// @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
|
|
143
161
|
async (params) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
);
|
|
176
|
-
server.tool(
|
|
177
|
-
"farseer_create_import_job",
|
|
178
|
-
`Create and execute a complete data import job on a Farseer instance.
|
|
162
|
+
const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
|
|
163
|
+
if (!resolved) {
|
|
164
|
+
return (0, helpers_1.tenantRequiredResponse)();
|
|
165
|
+
}
|
|
166
|
+
const { organisation, tenant } = resolved;
|
|
167
|
+
const nativeClient = await (0, farseerFactory_1.getNativeFarseerClient)(organisation, tenant);
|
|
168
|
+
if (!nativeClient) {
|
|
169
|
+
return (0, helpers_1.authRequiredResponse)(tenant);
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
const blob = await nativeClient.export.exportFormula({
|
|
173
|
+
formula: params.variableName,
|
|
174
|
+
format: 'csv',
|
|
175
|
+
});
|
|
176
|
+
const text = await blob.text();
|
|
177
|
+
const lines = text.split('\n').filter((l) => l.trim()).length;
|
|
178
|
+
const rowCount = Math.max(0, lines - 1);
|
|
179
|
+
return (0, helpers_1.successResponse)({
|
|
180
|
+
tenant,
|
|
181
|
+
variable: params.variableName,
|
|
182
|
+
dimensions: params.dimensions || 'all',
|
|
183
|
+
rowCount,
|
|
184
|
+
data: text,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
return (0, helpers_1.errorResponse)(`Load variable data failed: ${await extractErrorMessage(error)}`, 'NETWORK_ERROR');
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
// farseer_create_import_job - Create and execute import job
|
|
192
|
+
server.tool('farseer_create_import_job', `Create and execute a complete data import job on a Farseer instance.
|
|
179
193
|
|
|
180
194
|
This tool handles the full import workflow in a single call:
|
|
181
195
|
1. Builds import metadata from column definitions
|
|
@@ -212,101 +226,96 @@ Example columns for importing revenue data:
|
|
|
212
226
|
}
|
|
213
227
|
]
|
|
214
228
|
|
|
215
|
-
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
216
|
-
|
|
229
|
+
If no tenant is specified, uses the currently checked-out tenant.`, createImportJobSchema,
|
|
230
|
+
// @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
|
|
217
231
|
async (params) => {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
const { organisation, tenant } = resolved;
|
|
223
|
-
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
224
|
-
if (!nativeClient) {
|
|
225
|
-
return (0, import_helpers.authRequiredResponse)(tenant);
|
|
226
|
-
}
|
|
227
|
-
try {
|
|
228
|
-
await nativeClient.initTagMap();
|
|
229
|
-
const {
|
|
230
|
-
title,
|
|
231
|
-
columns,
|
|
232
|
-
rows,
|
|
233
|
-
labels,
|
|
234
|
-
undoPrevious = false,
|
|
235
|
-
importDimensions = false,
|
|
236
|
-
overwriteCells = false
|
|
237
|
-
} = params;
|
|
238
|
-
const metadataColumns = columns.map((col) => {
|
|
239
|
-
switch (col.type) {
|
|
240
|
-
case "DIMENSION_TABLE":
|
|
241
|
-
return {
|
|
242
|
-
type: "DIMENSION_TABLE",
|
|
243
|
-
dimensionTableName: col.dimensionTableName,
|
|
244
|
-
columnName: col.columnName
|
|
245
|
-
};
|
|
246
|
-
case "VARIABLE":
|
|
247
|
-
return {
|
|
248
|
-
type: "VARIABLE",
|
|
249
|
-
variableName: col.variableName,
|
|
250
|
-
columnName: col.columnName || col.variableName,
|
|
251
|
-
dimensionsNames: col.dimensionsNames
|
|
252
|
-
};
|
|
253
|
-
case "DATE":
|
|
254
|
-
return {
|
|
255
|
-
type: "DATE",
|
|
256
|
-
dateFormat: col.dateFormat,
|
|
257
|
-
columnName: col.columnName
|
|
258
|
-
};
|
|
259
|
-
case "DESCRIPTION":
|
|
260
|
-
return {
|
|
261
|
-
type: "DESCRIPTION",
|
|
262
|
-
columnName: col.columnName
|
|
263
|
-
};
|
|
264
|
-
default:
|
|
265
|
-
return {
|
|
266
|
-
type: "NONE",
|
|
267
|
-
columnName: col.columnName
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
const metadata = await nativeClient.buildImportJobMetadata(metadataColumns);
|
|
272
|
-
if (overwriteCells) {
|
|
273
|
-
metadata.overwriteCells = true;
|
|
232
|
+
const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
|
|
233
|
+
if (!resolved) {
|
|
234
|
+
return (0, helpers_1.tenantRequiredResponse)();
|
|
274
235
|
}
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
});
|
|
280
|
-
await importActions.addRows(rows);
|
|
281
|
-
await importActions.flushRows();
|
|
282
|
-
if (importDimensions) {
|
|
283
|
-
await importActions.importDimensions();
|
|
236
|
+
const { organisation, tenant } = resolved;
|
|
237
|
+
const nativeClient = await (0, farseerFactory_1.getNativeFarseerClient)(organisation, tenant);
|
|
238
|
+
if (!nativeClient) {
|
|
239
|
+
return (0, helpers_1.authRequiredResponse)(tenant);
|
|
284
240
|
}
|
|
285
|
-
|
|
286
|
-
|
|
241
|
+
try {
|
|
242
|
+
await nativeClient.initTagMap();
|
|
243
|
+
const { title, columns, rows, labels, undoPrevious = false, importDimensions = false, overwriteCells = false, } = params;
|
|
244
|
+
// Build metadata columns
|
|
245
|
+
const metadataColumns = columns.map((col) => {
|
|
246
|
+
switch (col.type) {
|
|
247
|
+
case 'DIMENSION_TABLE':
|
|
248
|
+
return {
|
|
249
|
+
type: 'DIMENSION_TABLE',
|
|
250
|
+
dimensionTableName: col.dimensionTableName,
|
|
251
|
+
columnName: col.columnName,
|
|
252
|
+
};
|
|
253
|
+
case 'VARIABLE':
|
|
254
|
+
return {
|
|
255
|
+
type: 'VARIABLE',
|
|
256
|
+
variableName: col.variableName,
|
|
257
|
+
columnName: col.columnName || col.variableName,
|
|
258
|
+
dimensionsNames: col.dimensionsNames,
|
|
259
|
+
};
|
|
260
|
+
case 'DATE':
|
|
261
|
+
return {
|
|
262
|
+
type: 'DATE',
|
|
263
|
+
dateFormat: col.dateFormat,
|
|
264
|
+
columnName: col.columnName,
|
|
265
|
+
};
|
|
266
|
+
case 'DESCRIPTION':
|
|
267
|
+
return {
|
|
268
|
+
type: 'DESCRIPTION',
|
|
269
|
+
columnName: col.columnName,
|
|
270
|
+
};
|
|
271
|
+
default:
|
|
272
|
+
return {
|
|
273
|
+
type: 'NONE',
|
|
274
|
+
columnName: col.columnName,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
// Build metadata
|
|
279
|
+
const metadata = await nativeClient.buildImportJobMetadata(metadataColumns);
|
|
280
|
+
if (overwriteCells) {
|
|
281
|
+
metadata.overwriteCells = true;
|
|
282
|
+
}
|
|
283
|
+
// Create import job
|
|
284
|
+
const importActions = await nativeClient.createImportJob({
|
|
285
|
+
title,
|
|
286
|
+
metadata,
|
|
287
|
+
labels,
|
|
288
|
+
});
|
|
289
|
+
// Add rows
|
|
290
|
+
await importActions.addRows(rows);
|
|
291
|
+
await importActions.flushRows();
|
|
292
|
+
// Import dimensions if needed
|
|
293
|
+
if (importDimensions) {
|
|
294
|
+
await importActions.importDimensions();
|
|
295
|
+
}
|
|
296
|
+
// Undo previous if needed
|
|
297
|
+
if (undoPrevious) {
|
|
298
|
+
await importActions.undoPrevious();
|
|
299
|
+
}
|
|
300
|
+
// Commit
|
|
301
|
+
const report = await importActions.commit();
|
|
302
|
+
return (0, helpers_1.successResponse)({
|
|
303
|
+
tenant,
|
|
304
|
+
title,
|
|
305
|
+
rowCount: rows.length,
|
|
306
|
+
labels: labels || [],
|
|
307
|
+
undoPrevious,
|
|
308
|
+
importDimensions,
|
|
309
|
+
overwriteCells,
|
|
310
|
+
commitReport: report,
|
|
311
|
+
});
|
|
287
312
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
undoPrevious,
|
|
295
|
-
importDimensions,
|
|
296
|
-
overwriteCells,
|
|
297
|
-
commitReport: report
|
|
298
|
-
});
|
|
299
|
-
} catch (error) {
|
|
300
|
-
return (0, import_helpers.errorResponse)(
|
|
301
|
-
`Import job failed: ${await extractErrorMessage(error)}`,
|
|
302
|
-
"NETWORK_ERROR"
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
);
|
|
307
|
-
server.tool(
|
|
308
|
-
"farseer_create_file",
|
|
309
|
-
`Create or update a file on a Farseer instance.
|
|
313
|
+
catch (error) {
|
|
314
|
+
return (0, helpers_1.errorResponse)(`Import job failed: ${await extractErrorMessage(error)}`, 'NETWORK_ERROR');
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
// farseer_create_file - Create or update file on instance
|
|
318
|
+
server.tool('farseer_create_file', `Create or update a file on a Farseer instance.
|
|
310
319
|
|
|
311
320
|
This creates a file in the specified folder on the Farseer file system.
|
|
312
321
|
If a file with the same name already exists in that folder, it will be updated.
|
|
@@ -319,44 +328,31 @@ Common use cases:
|
|
|
319
328
|
- Uploading configuration files
|
|
320
329
|
- Saving processed data outputs
|
|
321
330
|
|
|
322
|
-
If no tenant is specified, uses the currently checked-out tenant.`,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
} catch (error) {
|
|
350
|
-
return (0, import_helpers.errorResponse)(
|
|
351
|
-
`Create file failed: ${await extractErrorMessage(error)}`,
|
|
352
|
-
"NETWORK_ERROR"
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
);
|
|
331
|
+
If no tenant is specified, uses the currently checked-out tenant.`, createFileSchema, async (params) => {
|
|
332
|
+
const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
|
|
333
|
+
if (!resolved) {
|
|
334
|
+
return (0, helpers_1.tenantRequiredResponse)();
|
|
335
|
+
}
|
|
336
|
+
const { organisation, tenant } = resolved;
|
|
337
|
+
const nativeClient = await (0, farseerFactory_1.getNativeFarseerClient)(organisation, tenant);
|
|
338
|
+
if (!nativeClient) {
|
|
339
|
+
return (0, helpers_1.authRequiredResponse)(tenant);
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
const folderPath = params.folderPath || ['Files'];
|
|
343
|
+
const folder = await nativeClient.getItemByPath(folderPath);
|
|
344
|
+
const buffer = Buffer.from(params.content, 'utf-8');
|
|
345
|
+
await nativeClient.createOrUpdateFarseerFile({ name: params.fileName, folderId: folder.id }, buffer);
|
|
346
|
+
return (0, helpers_1.successResponse)({
|
|
347
|
+
tenant,
|
|
348
|
+
fileName: params.fileName,
|
|
349
|
+
folderPath,
|
|
350
|
+
size: buffer.length,
|
|
351
|
+
message: `File "${params.fileName}" created/updated in ${folderPath.join('/')}`,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
return (0, helpers_1.errorResponse)(`Create file failed: ${await extractErrorMessage(error)}`, 'NETWORK_ERROR');
|
|
356
|
+
}
|
|
357
|
+
});
|
|
357
358
|
}
|
|
358
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
359
|
-
0 && (module.exports = {
|
|
360
|
-
registerDataTools
|
|
361
|
-
});
|
|
362
|
-
//# sourceMappingURL=dataTools.js.map
|