farseer-cli 1.3.0 → 1.5.0

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.
Files changed (63) hide show
  1. package/README.md +102 -30
  2. package/dist/commands/checkout.js +3 -8
  3. package/dist/commands/checkout.js.map +2 -2
  4. package/dist/commands/dimensions.js +8 -8
  5. package/dist/commands/dimensions.js.map +2 -2
  6. package/dist/commands/model.js +29 -13
  7. package/dist/commands/model.js.map +2 -2
  8. package/dist/commands/pull.js +159 -46
  9. package/dist/commands/pull.js.map +2 -2
  10. package/dist/commands/push.js +185 -75
  11. package/dist/commands/push.js.map +2 -2
  12. package/dist/commands/run.js +31 -30
  13. package/dist/commands/run.js.map +2 -2
  14. package/dist/commands/status.js +26 -33
  15. package/dist/commands/status.js.map +2 -2
  16. package/dist/commands/variables.js +2 -2
  17. package/dist/commands/variables.js.map +2 -2
  18. package/dist/index.js +5 -3
  19. package/dist/index.js.map +2 -2
  20. package/dist/mcp/tools/appTools.js +6 -20
  21. package/dist/mcp/tools/appTools.js.map +2 -2
  22. package/dist/mcp/tools/authTools.js +2 -1
  23. package/dist/mcp/tools/authTools.js.map +2 -2
  24. package/dist/mcp/tools/cellTools.js +2 -10
  25. package/dist/mcp/tools/cellTools.js.map +2 -2
  26. package/dist/mcp/tools/dashboardTools.js +12 -23
  27. package/dist/mcp/tools/dashboardTools.js.map +2 -2
  28. package/dist/mcp/tools/dataTools.js +5 -16
  29. package/dist/mcp/tools/dataTools.js.map +2 -2
  30. package/dist/mcp/tools/folderTools.js +3 -11
  31. package/dist/mcp/tools/folderTools.js.map +2 -2
  32. package/dist/mcp/tools/modelTools.js +61 -69
  33. package/dist/mcp/tools/modelTools.js.map +2 -2
  34. package/dist/mcp/tools/runTools.js +3 -8
  35. package/dist/mcp/tools/runTools.js.map +2 -2
  36. package/dist/mcp/tools/sheetTools.js +11 -22
  37. package/dist/mcp/tools/sheetTools.js.map +2 -2
  38. package/dist/mcp/tools/syncTools.js +132 -47
  39. package/dist/mcp/tools/syncTools.js.map +2 -2
  40. package/dist/mcp/utils/helpers.js +2 -2
  41. package/dist/mcp/utils/helpers.js.map +2 -2
  42. package/dist/services/appSyncService.js +3 -2
  43. package/dist/services/appSyncService.js.map +2 -2
  44. package/dist/services/farseerApi.js +120 -72
  45. package/dist/services/farseerApi.js.map +2 -2
  46. package/dist/services/farseerFactory.js +1 -1
  47. package/dist/services/farseerFactory.js.map +2 -2
  48. package/dist/services/farseerService.js +87 -47
  49. package/dist/services/farseerService.js.map +2 -2
  50. package/dist/services/syncService.js +322 -182
  51. package/dist/services/syncService.js.map +3 -3
  52. package/dist/utils/cliOptions.js +36 -0
  53. package/dist/utils/cliOptions.js.map +7 -0
  54. package/dist/utils/errorFormatter.js +152 -0
  55. package/dist/utils/errorFormatter.js.map +7 -0
  56. package/dist/utils/fileLogger.js +13 -0
  57. package/dist/utils/fileLogger.js.map +2 -2
  58. package/dist/utils/fileValidation.js +180 -0
  59. package/dist/utils/fileValidation.js.map +7 -0
  60. package/dist/utils/helpers.js +85 -14
  61. package/dist/utils/helpers.js.map +2 -2
  62. package/docs/cli-guide.md +49 -4
  63. package/package.json +1 -1
@@ -37,6 +37,7 @@ var path = __toESM(require("path"));
37
37
  var os = __toESM(require("os"));
38
38
  var import_farseerFactory = require("../../services/farseerFactory");
39
39
  var import_helpers = require("../utils/helpers");
40
+ var import_errorFormatter = require("../../utils/errorFormatter");
40
41
  var farseer = __toESM(require("farseer-client"));
41
42
  var import_farseer_client = require("farseer-client");
42
43
  const ROLLUP_TYPE_MAP = {
@@ -62,15 +63,6 @@ function normalizeRollupType(value) {
62
63
  }
63
64
  return normalized;
64
65
  }
65
- async function extractErrorMessage(error) {
66
- if (error instanceof Error) return error.message;
67
- if (error && typeof error === "object" && "status" in error && "statusText" in error) {
68
- const resp = error;
69
- const body = resp.text ? await resp.text() : "";
70
- return `HTTP ${resp.status} ${resp.statusText}${body ? ": " + body : ""}`;
71
- }
72
- return String(error);
73
- }
74
66
  const evaluateFormulaSchema = {
75
67
  organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
76
68
  tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
@@ -136,7 +128,10 @@ const deleteVariableDataSchema = {
136
128
  };
137
129
  const exportModelSchema = {
138
130
  tenant: import_zod.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
139
- organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.")
131
+ organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
132
+ includeMembers: import_zod.z.boolean().optional().describe(
133
+ "Include dimension member rows. Default false because the unscoped fetch can exceed the response size limit on larger tenants and time out. Use farseer_get_table for member samples of a single table instead."
134
+ )
140
135
  };
141
136
  const listTablesSchema = {
142
137
  tenant: import_zod.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
@@ -184,7 +179,10 @@ If no tenant is specified, uses the currently checked-out tenant.`,
184
179
  return (0, import_helpers.authRequiredResponse)(tenant);
185
180
  }
186
181
  try {
187
- const model = await clientResult.client.exportModel();
182
+ const types = params.includeMembers ? ["DTAB", "DMEM", "VAR"] : ["DTAB", "VAR"];
183
+ const model = await clientResult.client.exportModel({
184
+ types
185
+ });
188
186
  const tables = model.tables.map((t) => ({
189
187
  name: t.name,
190
188
  memberCount: t.rows?.length || 0,
@@ -235,10 +233,14 @@ If no tenant is specified, uses the currently checked-out tenant.`,
235
233
  }
236
234
  return (0, import_helpers.successResponse)(result);
237
235
  } catch (error) {
238
- return (0, import_helpers.errorResponse)(
239
- `Export model failed: ${error instanceof Error ? error.message : "Unknown error"}`,
240
- "NETWORK_ERROR"
241
- );
236
+ const formatted = await (0, import_errorFormatter.formatClientError)(error);
237
+ if (params.includeMembers && /socket hang up|timeout|ECONNRESET/i.test(formatted)) {
238
+ return (0, import_helpers.errorResponse)(
239
+ `Export model with members timed out \u2014 the response is too large for this tenant. Retry with includeMembers: false (default) for the structure, then call farseer_get_table for the specific tables you need members from.`,
240
+ "NETWORK_ERROR"
241
+ );
242
+ }
243
+ return (0, import_helpers.errorResponse)(`Export model failed: ${formatted}`, "NETWORK_ERROR");
242
244
  }
243
245
  }
244
246
  );
@@ -266,10 +268,9 @@ If no tenant is specified, uses the currently checked-out tenant.`,
266
268
  return (0, import_helpers.authRequiredResponse)(tenant);
267
269
  }
268
270
  try {
269
- const model = await clientResult.client.exportModel();
271
+ const model = await clientResult.client.exportModel({ types: ["DTAB"] });
270
272
  const tables = model.tables.map((t) => ({
271
273
  name: t.name,
272
- memberCount: t.rows?.length || 0,
273
274
  foreignKeys: t.columns.filter((c) => c.type === "FOREIGN_KEY").map((c) => c.foreignKeyTableName)
274
275
  }));
275
276
  tables.sort((a, b) => a.name.localeCompare(b.name));
@@ -279,10 +280,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
279
280
  tables
280
281
  });
281
282
  } catch (error) {
282
- return (0, import_helpers.errorResponse)(
283
- `List tables failed: ${error instanceof Error ? error.message : "Unknown error"}`,
284
- "NETWORK_ERROR"
285
- );
283
+ return (0, import_helpers.errorResponse)(`List tables failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
286
284
  }
287
285
  }
288
286
  );
@@ -310,27 +308,32 @@ If no tenant is specified, uses the currently checked-out tenant.`,
310
308
  return (0, import_helpers.authRequiredResponse)(tenant);
311
309
  }
312
310
  try {
313
- const model = await clientResult.client.exportModel();
314
- const gidMap = /* @__PURE__ */ new Map();
315
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
316
- if (nativeClient) {
317
- try {
318
- await nativeClient.initTagMap();
319
- for (const v of model.variables) {
320
- const tag = await nativeClient.getVariable(v.name);
321
- gidMap.set(v.name, tag.id);
322
- }
323
- } catch {
324
- }
325
- }
311
+ const model = await clientResult.client.exportModel({ types: ["VAR"] });
326
312
  const variables = model.variables.map((v) => ({
327
313
  name: v.name,
328
- entityGid: gidMap.get(v.name) || null,
314
+ entityGid: v.gid ?? null,
329
315
  dimensions: v.tables || [],
330
316
  hasFormula: !!v.formula,
331
317
  rollupType: v.rollupType,
332
318
  readonly: v.readonly
333
319
  }));
320
+ if (variables.some((v) => v.entityGid === null)) {
321
+ const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
322
+ if (nativeClient) {
323
+ try {
324
+ await nativeClient.initTagMap();
325
+ for (const v of variables) {
326
+ if (v.entityGid !== null) continue;
327
+ try {
328
+ const tag = await nativeClient.getVariable(v.name);
329
+ v.entityGid = tag.id;
330
+ } catch {
331
+ }
332
+ }
333
+ } catch {
334
+ }
335
+ }
336
+ }
334
337
  variables.sort((a, b) => a.name.localeCompare(b.name));
335
338
  return (0, import_helpers.successResponse)({
336
339
  tenant,
@@ -338,10 +341,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
338
341
  variables
339
342
  });
340
343
  } catch (error) {
341
- return (0, import_helpers.errorResponse)(
342
- `List variables failed: ${error instanceof Error ? error.message : "Unknown error"}`,
343
- "NETWORK_ERROR"
344
- );
344
+ return (0, import_helpers.errorResponse)(`List variables failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
345
345
  }
346
346
  }
347
347
  );
@@ -370,8 +370,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
370
370
  return (0, import_helpers.authRequiredResponse)(tenant);
371
371
  }
372
372
  try {
373
- const model = await clientResult.client.exportModel();
374
- const table = model.tables.find((t) => t.name.toLowerCase() === params.tableName.toLowerCase());
373
+ const table = await clientResult.client.loadDimensionTableWithMembers(params.tableName);
375
374
  if (!table) {
376
375
  return (0, import_helpers.errorResponse)(`Table "${params.tableName}" not found`, "NOT_FOUND");
377
376
  }
@@ -396,10 +395,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
396
395
  }
397
396
  });
398
397
  } catch (error) {
399
- return (0, import_helpers.errorResponse)(
400
- `Get table failed: ${error instanceof Error ? error.message : "Unknown error"}`,
401
- "NETWORK_ERROR"
402
- );
398
+ return (0, import_helpers.errorResponse)(`Get table failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
403
399
  }
404
400
  }
405
401
  );
@@ -429,21 +425,23 @@ If no tenant is specified, uses the currently checked-out tenant.`,
429
425
  return (0, import_helpers.authRequiredResponse)(tenant);
430
426
  }
431
427
  try {
432
- const model = await clientResult.client.exportModel();
428
+ const model = await clientResult.client.exportModel({ types: ["VAR"] });
433
429
  const variable = model.variables.find(
434
430
  (v) => v.name.toLowerCase() === params.variableName.toLowerCase()
435
431
  );
436
432
  if (!variable) {
437
433
  return (0, import_helpers.errorResponse)(`Variable "${params.variableName}" not found`, "NOT_FOUND");
438
434
  }
439
- let entityGid = null;
440
- const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
441
- if (nativeClient) {
442
- try {
443
- await nativeClient.initTagMap();
444
- const tag = await nativeClient.getVariable(variable.name);
445
- entityGid = tag.id;
446
- } catch {
435
+ let entityGid = variable.gid ?? null;
436
+ if (entityGid === null) {
437
+ const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
438
+ if (nativeClient) {
439
+ try {
440
+ await nativeClient.initTagMap();
441
+ const tag = await nativeClient.getVariable(variable.name);
442
+ entityGid = tag.id;
443
+ } catch {
444
+ }
447
445
  }
448
446
  }
449
447
  return (0, import_helpers.successResponse)({
@@ -463,10 +461,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
463
461
  }
464
462
  });
465
463
  } catch (error) {
466
- return (0, import_helpers.errorResponse)(
467
- `Get variable failed: ${error instanceof Error ? error.message : "Unknown error"}`,
468
- "NETWORK_ERROR"
469
- );
464
+ return (0, import_helpers.errorResponse)(`Get variable failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
470
465
  }
471
466
  }
472
467
  );
@@ -516,7 +511,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
516
511
  }))
517
512
  });
518
513
  } catch (error) {
519
- return (0, import_helpers.errorResponse)(`Evaluate formula failed: ${await extractErrorMessage(error)}`, "NETWORK_ERROR");
514
+ return (0, import_helpers.errorResponse)(`Evaluate formula failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
520
515
  }
521
516
  }
522
517
  );
@@ -582,7 +577,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
582
577
  });
583
578
  } catch (error) {
584
579
  return (0, import_helpers.errorResponse)(
585
- `List dimension members failed: ${await extractErrorMessage(error)}`,
580
+ `List dimension members failed: ${await (0, import_errorFormatter.formatClientError)(error)}`,
586
581
  "NETWORK_ERROR"
587
582
  );
588
583
  }
@@ -664,7 +659,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
664
659
  }
665
660
  } catch (error) {
666
661
  return (0, import_helpers.errorResponse)(
667
- `Manage dimension member failed: ${await extractErrorMessage(error)}`,
662
+ `Manage dimension member failed: ${await (0, import_errorFormatter.formatClientError)(error)}`,
668
663
  "NETWORK_ERROR"
669
664
  );
670
665
  }
@@ -736,7 +731,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
736
731
  message: `Dimension table "${params.name}" created`
737
732
  });
738
733
  } catch (error) {
739
- return (0, import_helpers.errorResponse)(`Create table failed: ${await extractErrorMessage(error)}`, "NETWORK_ERROR");
734
+ return (0, import_helpers.errorResponse)(`Create table failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
740
735
  }
741
736
  }
742
737
  );
@@ -832,7 +827,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
832
827
  result
833
828
  });
834
829
  } catch (error) {
835
- return (0, import_helpers.errorResponse)(`Create variable failed: ${await extractErrorMessage(error)}`, "NETWORK_ERROR");
830
+ return (0, import_helpers.errorResponse)(`Create variable failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
836
831
  }
837
832
  }
838
833
  );
@@ -932,7 +927,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
932
927
  result
933
928
  });
934
929
  } catch (error) {
935
- return (0, import_helpers.errorResponse)(`Update variable failed: ${await extractErrorMessage(error)}`, "NETWORK_ERROR");
930
+ return (0, import_helpers.errorResponse)(`Update variable failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
936
931
  }
937
932
  }
938
933
  );
@@ -968,10 +963,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
968
963
  message: `All data deleted for variable "${params.variableName}"`
969
964
  });
970
965
  } catch (error) {
971
- return (0, import_helpers.errorResponse)(
972
- `Delete variable data failed: ${await extractErrorMessage(error)}`,
973
- "NETWORK_ERROR"
974
- );
966
+ return (0, import_helpers.errorResponse)(`Delete variable data failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
975
967
  }
976
968
  }
977
969
  );
@@ -1005,7 +997,7 @@ If no tenant is specified, uses the currently checked-out tenant.`,
1005
997
  message: `Variable "${params.variableName}" deleted`
1006
998
  });
1007
999
  } catch (error) {
1008
- return (0, import_helpers.errorResponse)(`Delete variable failed: ${await extractErrorMessage(error)}`, "NETWORK_ERROR");
1000
+ return (0, import_helpers.errorResponse)(`Delete variable failed: ${await (0, import_errorFormatter.formatClientError)(error)}`, "NETWORK_ERROR");
1009
1001
  }
1010
1002
  }
1011
1003
  );