farseer-cli 1.10.2 → 1.10.3

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.
@@ -35,7 +35,7 @@ var import_zod = require("zod");
35
35
  var fs = __toESM(require("fs"));
36
36
  var path = __toESM(require("path"));
37
37
  var os = __toESM(require("os"));
38
- var import_farseerFactory = require("../../services/farseerFactory");
38
+ var import_session = require("../utils/session");
39
39
  var import_helpers = require("../utils/helpers");
40
40
  var import_errorFormatter = require("../../utils/errorFormatter");
41
41
  var farseer = __toESM(require("farseer-client"));
@@ -141,18 +141,12 @@ and only a summary is returned. Use the Read tool to inspect the file if needed.
141
141
  For a quick overview without the full export, use farseer_list_tables or farseer_list_variables.`,
142
142
  exportModelSchema,
143
143
  async (params) => {
144
- const resolved = (0, import_helpers.getSessionTenant)();
145
- if (!resolved) {
146
- return (0, import_helpers.tenantRequiredResponse)();
147
- }
148
- const { organisation, tenant } = resolved;
149
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
150
- if (!clientResult) {
151
- return (0, import_helpers.authRequiredResponse)(tenant);
152
- }
144
+ const gate = await (0, import_session.requireSession)();
145
+ if (!gate.ok) return gate.response;
146
+ const { tenant, client } = gate.session;
153
147
  try {
154
148
  const types = params.includeMembers ? ["DTAB", "DMEM", "VAR"] : ["DTAB", "VAR"];
155
- const model = await clientResult.client.exportModel({
149
+ const model = await client.exportModel({
156
150
  types
157
151
  });
158
152
  const tables = model.tables.map((t) => ({
@@ -228,17 +222,11 @@ Dimension tables define the structure of data:
228
222
  Returns table names, member counts, and foreign key relationships.`,
229
223
  listTablesSchema,
230
224
  async () => {
231
- const resolved = (0, import_helpers.getSessionTenant)();
232
- if (!resolved) {
233
- return (0, import_helpers.tenantRequiredResponse)();
234
- }
235
- const { organisation, tenant } = resolved;
236
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
237
- if (!clientResult) {
238
- return (0, import_helpers.authRequiredResponse)(tenant);
239
- }
225
+ const gate = await (0, import_session.requireSession)();
226
+ if (!gate.ok) return gate.response;
227
+ const { tenant, client } = gate.session;
240
228
  try {
241
- const model = await clientResult.client.exportModel({ types: ["DTAB"] });
229
+ const model = await client.exportModel({ types: ["DTAB"] });
242
230
  const tables = model.tables.map((t) => ({
243
231
  name: t.name,
244
232
  foreignKeys: t.columns.filter((c) => c.type === "FOREIGN_KEY").map((c) => c.foreignKeyTableName)
@@ -266,17 +254,11 @@ Each variable has:
266
254
  - Roll-up type (how values aggregate up hierarchies)`,
267
255
  listVariablesSchema,
268
256
  async () => {
269
- const resolved = (0, import_helpers.getSessionTenant)();
270
- if (!resolved) {
271
- return (0, import_helpers.tenantRequiredResponse)();
272
- }
273
- const { organisation, tenant } = resolved;
274
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
275
- if (!clientResult) {
276
- return (0, import_helpers.authRequiredResponse)(tenant);
277
- }
257
+ const gate = await (0, import_session.requireSession)();
258
+ if (!gate.ok) return gate.response;
259
+ const { tenant, client, native: nativeClient } = gate.session;
278
260
  try {
279
- const model = await clientResult.client.exportModel({ types: ["VAR"] });
261
+ const model = await client.exportModel({ types: ["VAR"] });
280
262
  const variables = model.variables.map((v) => ({
281
263
  name: v.name,
282
264
  entityGid: v.gid ?? null,
@@ -286,20 +268,17 @@ Each variable has:
286
268
  readonly: v.readonly
287
269
  }));
288
270
  if (variables.some((v) => v.entityGid === null)) {
289
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
290
- if (nativeClient) {
291
- try {
292
- await nativeClient.initTagMap();
293
- for (const v of variables) {
294
- if (v.entityGid !== null) continue;
295
- try {
296
- const tag = await nativeClient.getVariable(v.name);
297
- v.entityGid = tag.id;
298
- } catch {
299
- }
271
+ try {
272
+ await nativeClient.initTagMap();
273
+ for (const v of variables) {
274
+ if (v.entityGid !== null) continue;
275
+ try {
276
+ const tag = await nativeClient.getVariable(v.name);
277
+ v.entityGid = tag.id;
278
+ } catch {
300
279
  }
301
- } catch {
302
280
  }
281
+ } catch {
303
282
  }
304
283
  }
305
284
  variables.sort((a, b) => a.name.localeCompare(b.name));
@@ -326,17 +305,11 @@ Returns:
326
305
  This helps understand the structure needed for import scripts.`,
327
306
  getTableSchema,
328
307
  async (params) => {
329
- const resolved = (0, import_helpers.getSessionTenant)();
330
- if (!resolved) {
331
- return (0, import_helpers.tenantRequiredResponse)();
332
- }
333
- const { organisation, tenant } = resolved;
334
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
335
- if (!clientResult) {
336
- return (0, import_helpers.authRequiredResponse)(tenant);
337
- }
308
+ const gate = await (0, import_session.requireSession)();
309
+ if (!gate.ok) return gate.response;
310
+ const { tenant, client } = gate.session;
338
311
  try {
339
- const table = await clientResult.client.loadDimensionTableWithMembers(params.tableName);
312
+ const table = await client.loadDimensionTableWithMembers(params.tableName);
340
313
  if (!table) {
341
314
  return (0, import_helpers.errorResponse)(`Table "${params.tableName}" not found`, "NOT_FOUND");
342
315
  }
@@ -379,17 +352,11 @@ Returns:
379
352
  This is essential for understanding what dimensions and values are needed for imports.`,
380
353
  getVariableSchema,
381
354
  async (params) => {
382
- const resolved = (0, import_helpers.getSessionTenant)();
383
- if (!resolved) {
384
- return (0, import_helpers.tenantRequiredResponse)();
385
- }
386
- const { organisation, tenant } = resolved;
387
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
388
- if (!clientResult) {
389
- return (0, import_helpers.authRequiredResponse)(tenant);
390
- }
355
+ const gate = await (0, import_session.requireSession)();
356
+ if (!gate.ok) return gate.response;
357
+ const { tenant, client, native: nativeClient } = gate.session;
391
358
  try {
392
- const model = await clientResult.client.exportModel({ types: ["VAR"] });
359
+ const model = await client.exportModel({ types: ["VAR"] });
393
360
  const variable = model.variables.find(
394
361
  (v) => v.name.toLowerCase() === params.variableName.toLowerCase()
395
362
  );
@@ -398,14 +365,11 @@ This is essential for understanding what dimensions and values are needed for im
398
365
  }
399
366
  let entityGid = variable.gid ?? null;
400
367
  if (entityGid === null) {
401
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
402
- if (nativeClient) {
403
- try {
404
- await nativeClient.initTagMap();
405
- const tag = await nativeClient.getVariable(variable.name);
406
- entityGid = tag.id;
407
- } catch {
408
- }
368
+ try {
369
+ await nativeClient.initTagMap();
370
+ const tag = await nativeClient.getVariable(variable.name);
371
+ entityGid = tag.id;
372
+ } catch {
409
373
  }
410
374
  }
411
375
  return (0, import_helpers.successResponse)({
@@ -444,11 +408,9 @@ Returns the computed value along with cell metadata (readonly, calculated, froze
444
408
  evaluateFormulaSchema,
445
409
  // @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
446
410
  async (params) => {
447
- const resolved = (0, import_helpers.getSessionTenant)();
448
- if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
449
- const { organisation, tenant } = resolved;
450
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
451
- if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
411
+ const gate = await (0, import_session.requireSession)();
412
+ if (!gate.ok) return gate.response;
413
+ const { tenant, native: nativeClient } = gate.session;
452
414
  try {
453
415
  let formula = params.formula;
454
416
  const isSimpleIdentifier = !formula.startsWith('"') && !/[+\-*/()>,<!=]/.test(formula);
@@ -488,11 +450,9 @@ For large tables (500+ members), automatically exports to a CSV file and returns
488
450
  instead of inline data, to avoid overwhelming the context window.`,
489
451
  listDimensionMembersSchema,
490
452
  async (params) => {
491
- const resolved = (0, import_helpers.getSessionTenant)();
492
- if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
493
- const { organisation, tenant } = resolved;
494
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
495
- if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
453
+ const gate = await (0, import_session.requireSession)();
454
+ if (!gate.ok) return gate.response;
455
+ const { tenant, native: nativeClient } = gate.session;
496
456
  try {
497
457
  await nativeClient.initTagMap();
498
458
  const members = await nativeClient.getDimensionMembersForTable(params.tableName);
@@ -557,11 +517,9 @@ Actions:
557
517
  WARNING: Delete is destructive and may affect data. Use with caution.`,
558
518
  manageDimensionMembersSchema,
559
519
  async (params) => {
560
- const resolved = (0, import_helpers.getSessionTenant)();
561
- if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
562
- const { organisation, tenant } = resolved;
563
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
564
- if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
520
+ const gate = await (0, import_session.requireSession)();
521
+ if (!gate.ok) return gate.response;
522
+ const { tenant, native: nativeClient } = gate.session;
565
523
  try {
566
524
  await nativeClient.initTagMap();
567
525
  if (params.action === "create") {
@@ -635,11 +593,9 @@ Creates an empty table that you can then add members to with farseer_manage_dime
635
593
  },
636
594
  // @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
637
595
  async (params) => {
638
- const resolved = (0, import_helpers.getSessionTenant)();
639
- if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
640
- const { organisation, tenant } = resolved;
641
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
642
- if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
596
+ const gate = await (0, import_session.requireSession)();
597
+ if (!gate.ok) return gate.response;
598
+ const { tenant, native: nativeClient } = gate.session;
643
599
  try {
644
600
  await nativeClient.initTagMap();
645
601
  const createEntity = {
@@ -707,11 +663,9 @@ Example:
707
663
  createVariableSchema,
708
664
  // @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
709
665
  async (params) => {
710
- const resolved = (0, import_helpers.getSessionTenant)();
711
- if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
712
- const { organisation, tenant } = resolved;
713
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
714
- if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
666
+ const gate = await (0, import_session.requireSession)();
667
+ if (!gate.ok) return gate.response;
668
+ const { tenant, native: nativeClient } = gate.session;
715
669
  try {
716
670
  await nativeClient.initTagMap();
717
671
  const tableGids = [];
@@ -802,11 +756,9 @@ Updatable fields:
802
756
  updateVariableSchema,
803
757
  // @ts-expect-error TS2589 - MCP SDK deep type inference with zod schemas
804
758
  async (params) => {
805
- const resolved = (0, import_helpers.getSessionTenant)();
806
- if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
807
- const { organisation, tenant } = resolved;
808
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
809
- if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
759
+ const gate = await (0, import_session.requireSession)();
760
+ if (!gate.ok) return gate.response;
761
+ const { tenant, native: nativeClient } = gate.session;
810
762
  try {
811
763
  await nativeClient.initTagMap();
812
764
  const variable = await nativeClient.getVariable(params.name);
@@ -891,11 +843,9 @@ for the specified variable across all dimensions and time periods.
891
843
  Use this to clear old template data or reset a variable before re-importing.`,
892
844
  deleteVariableDataSchema,
893
845
  async (params) => {
894
- const resolved = (0, import_helpers.getSessionTenant)();
895
- if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
896
- const { organisation, tenant } = resolved;
897
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
898
- if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
846
+ const gate = await (0, import_session.requireSession)();
847
+ if (!gate.ok) return gate.response;
848
+ const { tenant, native: nativeClient } = gate.session;
899
849
  try {
900
850
  await nativeClient.initTagMap();
901
851
  const variable = await nativeClient.getVariable(params.variableName);
@@ -924,11 +874,9 @@ Resolves the variable by name and permanently deletes it along with all its data
924
874
  WARNING: This is destructive and cannot be undone.`,
925
875
  deleteVariableSchema,
926
876
  async (params) => {
927
- const resolved = (0, import_helpers.getSessionTenant)();
928
- if (!resolved) return (0, import_helpers.tenantRequiredResponse)();
929
- const { organisation, tenant } = resolved;
930
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
931
- if (!nativeClient) return (0, import_helpers.authRequiredResponse)(tenant);
877
+ const gate = await (0, import_session.requireSession)();
878
+ if (!gate.ok) return gate.response;
879
+ const { tenant, native: nativeClient } = gate.session;
932
880
  try {
933
881
  await nativeClient.initTagMap();
934
882
  const variable = await nativeClient.getVariable(params.variableName);