farseer-cli 1.0.10 → 1.1.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.
- package/README.md +19 -0
- package/dist/commands/app.js +348 -344
- package/dist/commands/app.js.map +7 -0
- package/dist/commands/apps.js +110 -82
- package/dist/commands/apps.js.map +7 -0
- package/dist/commands/cells.js +161 -0
- package/dist/commands/cells.js.map +7 -0
- package/dist/commands/checkout.js +140 -155
- package/dist/commands/checkout.js.map +7 -0
- package/dist/commands/config.js +128 -126
- package/dist/commands/config.js.map +7 -0
- package/dist/commands/dashboards.js +130 -0
- package/dist/commands/dashboards.js.map +7 -0
- package/dist/commands/diff.js +171 -193
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/dimensions.js +222 -119
- package/dist/commands/dimensions.js.map +7 -0
- package/dist/commands/files.js +96 -77
- package/dist/commands/files.js.map +7 -0
- package/dist/commands/formula.js +116 -0
- package/dist/commands/formula.js.map +7 -0
- package/dist/commands/install.js +74 -76
- package/dist/commands/install.js.map +7 -0
- package/dist/commands/list.js +91 -73
- package/dist/commands/list.js.map +7 -0
- package/dist/commands/login.js +137 -98
- package/dist/commands/login.js.map +7 -0
- package/dist/commands/logout.js +59 -41
- package/dist/commands/logout.js.map +7 -0
- package/dist/commands/mcp-server.js +36 -23
- package/dist/commands/mcp-server.js.map +7 -0
- package/dist/commands/model.js +186 -175
- package/dist/commands/model.js.map +7 -0
- package/dist/commands/pull.js +264 -274
- package/dist/commands/pull.js.map +7 -0
- package/dist/commands/push.js +209 -221
- package/dist/commands/push.js.map +7 -0
- package/dist/commands/run.js +276 -321
- package/dist/commands/run.js.map +7 -0
- package/dist/commands/sheets.js +200 -0
- package/dist/commands/sheets.js.map +7 -0
- package/dist/commands/status.js +149 -169
- package/dist/commands/status.js.map +7 -0
- package/dist/commands/variables.js +247 -188
- package/dist/commands/variables.js.map +7 -0
- package/dist/commands/whoami.js +65 -44
- package/dist/commands/whoami.js.map +7 -0
- package/dist/index.js +179 -115
- package/dist/index.js.map +7 -0
- package/dist/mcp/index.js +33 -16
- package/dist/mcp/index.js.map +7 -0
- package/dist/mcp/prompts/workflows.js +191 -145
- package/dist/mcp/prompts/workflows.js.map +7 -0
- package/dist/mcp/resources/documentation.js +158 -148
- package/dist/mcp/resources/documentation.js.map +7 -0
- package/dist/mcp/server.js +56 -33
- package/dist/mcp/server.js.map +7 -0
- package/dist/mcp/tools/appTools.js +309 -277
- package/dist/mcp/tools/appTools.js.map +7 -0
- package/dist/mcp/tools/authTools.js +130 -121
- package/dist/mcp/tools/authTools.js.map +7 -0
- package/dist/mcp/tools/cellTools.js +148 -0
- package/dist/mcp/tools/cellTools.js.map +7 -0
- package/dist/mcp/tools/dashboardTools.js +133 -0
- package/dist/mcp/tools/dashboardTools.js.map +7 -0
- package/dist/mcp/tools/dataTools.js +270 -267
- package/dist/mcp/tools/dataTools.js.map +7 -0
- package/dist/mcp/tools/modelTools.js +575 -229
- package/dist/mcp/tools/modelTools.js.map +7 -0
- package/dist/mcp/tools/runTools.js +201 -203
- package/dist/mcp/tools/runTools.js.map +7 -0
- package/dist/mcp/tools/sheetTools.js +240 -0
- package/dist/mcp/tools/sheetTools.js.map +7 -0
- package/dist/mcp/tools/syncTools.js +335 -314
- package/dist/mcp/tools/syncTools.js.map +7 -0
- package/dist/mcp/utils/helpers.js +117 -123
- package/dist/mcp/utils/helpers.js.map +7 -0
- package/dist/services/appSyncService.js +381 -437
- package/dist/services/appSyncService.js.map +7 -0
- package/dist/services/configService.js +154 -143
- package/dist/services/configService.js.map +7 -0
- package/dist/services/farseerApi.js +405 -400
- package/dist/services/farseerApi.js.map +7 -0
- package/dist/services/farseerFactory.js +208 -273
- package/dist/services/farseerFactory.js.map +7 -0
- package/dist/services/farseerService.js +453 -487
- package/dist/services/farseerService.js.map +7 -0
- package/dist/services/syncService.js +661 -731
- package/dist/services/syncService.js.map +7 -0
- package/dist/utils/constants.js +52 -19
- package/dist/utils/constants.js.map +7 -0
- package/dist/utils/entityResolver.js +78 -0
- package/dist/utils/entityResolver.js.map +7 -0
- package/dist/utils/helpers.js +331 -365
- package/dist/utils/helpers.js.map +7 -0
- package/dist/utils/logger.js +74 -42
- package/dist/utils/logger.js.map +7 -0
- package/package.json +3 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/commands/status.ts"],
|
|
4
|
+
"sourcesContent": ["import { Command } from 'commander';\nimport chalk from 'chalk';\nimport { logger } from '../utils/logger';\nimport { getFarseerClientWithFallback, showLoginPrompt } from '../services/farseerFactory';\nimport { SyncService } from '../services/syncService';\nimport { AppSyncService } from '../services/appSyncService';\nimport { getTenantFilesDir, resolveTenantWithOrgMapping } from '../utils/helpers';\nimport * as fs from 'fs';\n\nexport function registerStatusCommand(program: Command): void {\n program\n .command('status [org] [tenant]')\n .description(\n 'Show sync status between local and remote\\n\\nUsage: status <org> <tenant> OR status <tenant> (if org is known)',\n )\n .option('--all', 'Show status for all files (default: only scripts .ts, .js)')\n .action(async (arg1, arg2, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping(arg1, arg2);\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n\n if (!clientResult) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n const filesDir = getTenantFilesDir(tenant);\n\n if (!fs.existsSync(filesDir)) {\n logger.warning(`Local folder not found: apps/${tenant}/files/`);\n logger.dim('Run \"farseer pull <tenant>\" to download files from the instance.');\n return;\n }\n\n logger.info(`Comparing local (apps/${tenant}/files/) with remote (Files/)...`);\n console.log();\n\n const syncService = new SyncService(tenant, clientResult.client);\n\n try {\n const status = await syncService.getStatus({ all: options.all });\n\n const hasChanges =\n status.modifiedLocally.length > 0 ||\n status.modifiedRemotely.length > 0 ||\n status.onlyLocal.length > 0 ||\n status.onlyRemote.length > 0 ||\n (status.conflicts && status.conflicts.length > 0);\n\n if (!hasChanges) {\n logger.success('Everything is in sync!');\n logger.dim(`${status.inSync.length} file(s) synchronized.`);\n return;\n }\n\n // Modified locally\n if (status.modifiedLocally.length > 0) {\n console.log(chalk.yellow('Modified locally:'));\n for (const file of status.modifiedLocally) {\n console.log(chalk.yellow(` M ${file}`));\n }\n console.log();\n }\n\n // Modified remotely\n if (status.modifiedRemotely.length > 0) {\n console.log(chalk.cyan('Modified on remote:'));\n const syncState = syncService.loadSyncState();\n\n for (const file of status.modifiedRemotely) {\n const metadata = syncState.files[file]?.metadata;\n const uploaderInfo = metadata?.uploaderName\n ? ` (by ${metadata.uploaderName})`\n : metadata?.uploaderEmail\n ? ` (by ${metadata.uploaderEmail})`\n : '';\n\n console.log(chalk.cyan(` M ${file}`) + chalk.dim(uploaderInfo));\n }\n console.log();\n }\n\n // Only local (new files)\n if (status.onlyLocal.length > 0) {\n console.log(chalk.green('Only local (new):'));\n for (const file of status.onlyLocal) {\n console.log(chalk.green(` + ${file}`));\n }\n console.log();\n }\n\n // Only remote (not downloaded)\n if (status.onlyRemote.length > 0) {\n console.log(chalk.red('Only on remote:'));\n for (const file of status.onlyRemote) {\n console.log(chalk.red(` - ${file}`));\n }\n console.log();\n }\n\n // Conflicts\n if (status.conflicts && status.conflicts.length > 0) {\n console.log(chalk.red.bold('CONFLICTS:'));\n for (const conflict of status.conflicts) {\n console.log(chalk.red(` ! ${conflict.filePath}`));\n console.log(chalk.dim(` ${conflict.description}`));\n }\n console.log();\n logger.dim(`Resolve conflicts during pull: farseer pull ${tenant}`);\n console.log();\n }\n\n // Apps status (works with both JWT and API key)\n const appSyncService = new AppSyncService(tenant, clientResult.client);\n const appStatus = await appSyncService.getStatus();\n\n const hasAppChanges =\n appStatus.newLocal.length > 0 || appStatus.newRemote.length > 0 || appStatus.modified.length > 0;\n\n if (hasAppChanges) {\n console.log(chalk.bold('Apps:'));\n console.log();\n\n if (appStatus.newLocal.length > 0) {\n console.log(chalk.green('New local apps (to be created on remote):'));\n for (const app of appStatus.newLocal) {\n console.log(chalk.green(` + ${app}`));\n }\n console.log();\n }\n\n if (appStatus.newRemote.length > 0) {\n console.log(chalk.cyan('New remote apps (to be downloaded):'));\n for (const app of appStatus.newRemote) {\n console.log(chalk.cyan(` + ${app}`));\n }\n console.log();\n }\n\n if (appStatus.modified.length > 0) {\n console.log(chalk.yellow('Modified apps:'));\n for (const app of appStatus.modified) {\n console.log(chalk.yellow(` ~ ${app}`));\n }\n console.log();\n }\n\n if (appStatus.synced.length > 0) {\n logger.dim(`${appStatus.synced.length} app(s) in sync.`);\n }\n } else if (appStatus.synced.length > 0) {\n logger.dim(`${appStatus.synced.length} app(s) in sync.`);\n }\n\n // Summary\n console.log();\n logger.dim('Use \"farseer push <tenant>\" to upload local changes.');\n logger.dim('Use \"farseer pull <tenant>\" to download remote changes.');\n } catch (error) {\n logger.error('Failed to check status.');\n if (error instanceof Error) {\n logger.dim(error.message);\n }\n process.exit(1);\n }\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAuB;AACvB,4BAA8D;AAC9D,yBAA4B;AAC5B,4BAA+B;AAC/B,qBAA+D;AAC/D,SAAoB;AAEb,SAAS,sBAAsB,SAAwB;AAC1D,UACK,QAAQ,uBAAuB,EAC/B;AAAA,IACG;AAAA,EACJ,EACC,OAAO,SAAS,4DAA4D,EAC5E,OAAO,OAAO,MAAM,MAAM,YAAY;AACnC,UAAM,EAAE,cAAc,OAAO,QAAI,4CAA4B,MAAM,IAAI;AACvE,UAAM,eAAe,UAAM,oDAA6B,cAAc,MAAM;AAE5E,QAAI,CAAC,cAAc;AACf,iDAAgB,MAAM;AACtB,cAAQ,KAAK,CAAC;AAAA,IAClB;AAEA,UAAM,eAAW,kCAAkB,MAAM;AAEzC,QAAI,CAAC,GAAG,WAAW,QAAQ,GAAG;AAC1B,2BAAO,QAAQ,gCAAgC,MAAM,SAAS;AAC9D,2BAAO,IAAI,kEAAkE;AA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|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
37
19
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var variables_exports = {};
|
|
30
|
+
__export(variables_exports, {
|
|
31
|
+
registerVariablesCommand: () => registerVariablesCommand
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(variables_exports);
|
|
34
|
+
var fs = __toESM(require("fs"));
|
|
35
|
+
var import_chalk = __toESM(require("chalk"));
|
|
36
|
+
var import_logger = require("../utils/logger");
|
|
37
|
+
var import_farseerFactory = require("../services/farseerFactory");
|
|
38
|
+
var import_helpers = require("../utils/helpers");
|
|
45
39
|
function registerVariablesCommand(program) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
console.log(` ${chalk_1.default.bold(variable.name)}${flagStr}`);
|
|
75
|
-
console.log(` Dimensions: ${variable.tables.join(', ')}`);
|
|
76
|
-
console.log(` Rollup: ${variable.rollupType} | Type: ${variable.dataType}`);
|
|
77
|
-
if (variable.formula) {
|
|
78
|
-
console.log(` Formula: ${chalk_1.default.dim(variable.formula.substring(0, 80))}${variable.formula.length > 80 ? '...' : ''}`);
|
|
79
|
-
}
|
|
80
|
-
console.log();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
handleModelError(error, tenant);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
// farseer variable details / export (singular)
|
|
88
|
-
const variableCmd = program.command('variable').description('Variable details and export');
|
|
89
|
-
variableCmd
|
|
90
|
-
.command('details <name>')
|
|
91
|
-
.description('Show variable details (dimensions, formula, rollup, etc.)')
|
|
92
|
-
.option('--json', 'Output raw JSON')
|
|
93
|
-
.action(async (name, options) => {
|
|
94
|
-
const { organisation, tenant } = (0, helpers_1.resolveTenantWithOrgMapping)();
|
|
95
|
-
const result = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
96
|
-
if (!result) {
|
|
97
|
-
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
98
|
-
process.exit(1);
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
const model = await result.client.exportModel();
|
|
102
|
-
const variable = model.variables.find((v) => v.name.toLowerCase() === name.toLowerCase());
|
|
103
|
-
if (!variable) {
|
|
104
|
-
logger_1.logger.error(`Variable "${name}" not found.`);
|
|
105
|
-
logger_1.logger.dim('Available variables:');
|
|
106
|
-
model.variables.slice(0, 10).forEach((v) => logger_1.logger.dim(` - ${v.name}`));
|
|
107
|
-
if (model.variables.length > 10) {
|
|
108
|
-
logger_1.logger.dim(` ... and ${model.variables.length - 10} more`);
|
|
109
|
-
}
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
if (options.json) {
|
|
113
|
-
console.log(JSON.stringify(variable, null, 2));
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
logger_1.logger.header(`Variable: ${variable.name}`);
|
|
117
|
-
console.log();
|
|
118
|
-
if (variable.description) {
|
|
119
|
-
console.log(` Description: ${variable.description}`);
|
|
120
|
-
}
|
|
121
|
-
if (variable.formula) {
|
|
122
|
-
console.log(` Formula: ${variable.formula}`);
|
|
123
|
-
}
|
|
124
|
-
console.log(` Dimensions: ${variable.tables.join(', ')}`);
|
|
125
|
-
if (variable.members.length > 0) {
|
|
126
|
-
console.log(` Specific members: ${variable.members.join(', ')}`);
|
|
127
|
-
}
|
|
128
|
-
console.log(` Roll-up type: ${variable.rollupType}`);
|
|
129
|
-
console.log(` Data type: ${variable.dataType}`);
|
|
130
|
-
if (variable.numberFormat) {
|
|
131
|
-
console.log(` Format: ${variable.numberFormat.type}${variable.numberFormat.formatString ? ` (${variable.numberFormat.formatString})` : ''}`);
|
|
132
|
-
}
|
|
133
|
-
console.log(` Readonly: ${variable.readonly}`);
|
|
134
|
-
console.log(` Calculate on demand: ${variable.calculateOnDemand}`);
|
|
135
|
-
if (variable.folderPath) {
|
|
136
|
-
console.log(` Folder: ${variable.folderPath.join(' / ')}`);
|
|
137
|
-
}
|
|
138
|
-
if (variable.cells && variable.cells.length > 0) {
|
|
139
|
-
console.log(` Cells with data: ${variable.cells.length}`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
handleModelError(error, tenant);
|
|
40
|
+
const variablesCmd = program.command("variables").description("List and manage variables");
|
|
41
|
+
variablesCmd.command("list [org] [tenant]").description("List all variables").option("--json", "Output raw JSON").action(async (first, second, options) => {
|
|
42
|
+
const { organisation, tenant } = (0, import_helpers.resolveTenantWithOrgMapping)(first, second);
|
|
43
|
+
const result = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
|
|
44
|
+
if (!result) {
|
|
45
|
+
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const model = await result.client.exportModel();
|
|
50
|
+
if (options.json) {
|
|
51
|
+
console.log(JSON.stringify(model.variables, null, 2));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
import_logger.logger.header(`Variables (${model.variables.length})`);
|
|
55
|
+
console.log();
|
|
56
|
+
for (const variable of model.variables) {
|
|
57
|
+
const flags = [];
|
|
58
|
+
if (variable.readonly) flags.push("readonly");
|
|
59
|
+
if (variable.calculateOnDemand) flags.push("on-demand");
|
|
60
|
+
const flagStr = flags.length > 0 ? import_chalk.default.dim(` [${flags.join(", ")}]`) : "";
|
|
61
|
+
console.log(` ${import_chalk.default.bold(variable.name)}${flagStr}`);
|
|
62
|
+
console.log(` Dimensions: ${variable.tables.join(", ")}`);
|
|
63
|
+
console.log(` Rollup: ${variable.rollupType} | Type: ${variable.dataType}`);
|
|
64
|
+
if (variable.formula) {
|
|
65
|
+
console.log(
|
|
66
|
+
` Formula: ${import_chalk.default.dim(variable.formula.substring(0, 80))}${variable.formula.length > 80 ? "..." : ""}`
|
|
67
|
+
);
|
|
144
68
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
69
|
+
console.log();
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
handleModelError(error, tenant);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const variableCmd = program.command("variable").description("Variable details and export");
|
|
76
|
+
variableCmd.command("details <name>").description("Show variable details (dimensions, formula, rollup, etc.)").option("--json", "Output raw JSON").action(async (name, options) => {
|
|
77
|
+
const { organisation, tenant } = (0, import_helpers.resolveTenantWithOrgMapping)();
|
|
78
|
+
const result = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
|
|
79
|
+
if (!result) {
|
|
80
|
+
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const model = await result.client.exportModel();
|
|
85
|
+
const variable = model.variables.find((v) => v.name.toLowerCase() === name.toLowerCase());
|
|
86
|
+
if (!variable) {
|
|
87
|
+
import_logger.logger.error(`Variable "${name}" not found.`);
|
|
88
|
+
import_logger.logger.dim("Available variables:");
|
|
89
|
+
model.variables.slice(0, 10).forEach((v) => import_logger.logger.dim(` - ${v.name}`));
|
|
90
|
+
if (model.variables.length > 10) {
|
|
91
|
+
import_logger.logger.dim(` ... and ${model.variables.length - 10} more`);
|
|
158
92
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
if (options.json) {
|
|
96
|
+
console.log(JSON.stringify(variable, null, 2));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
import_logger.logger.header(`Variable: ${variable.name}`);
|
|
100
|
+
console.log();
|
|
101
|
+
if (variable.description) {
|
|
102
|
+
console.log(` Description: ${variable.description}`);
|
|
103
|
+
}
|
|
104
|
+
if (variable.formula) {
|
|
105
|
+
console.log(` Formula: ${variable.formula}`);
|
|
106
|
+
}
|
|
107
|
+
console.log(` Dimensions: ${variable.tables.join(", ")}`);
|
|
108
|
+
if (variable.members.length > 0) {
|
|
109
|
+
console.log(` Specific members: ${variable.members.join(", ")}`);
|
|
110
|
+
}
|
|
111
|
+
console.log(` Roll-up type: ${variable.rollupType}`);
|
|
112
|
+
console.log(` Data type: ${variable.dataType}`);
|
|
113
|
+
if (variable.numberFormat) {
|
|
114
|
+
console.log(
|
|
115
|
+
` Format: ${variable.numberFormat.type}${variable.numberFormat.formatString ? ` (${variable.numberFormat.formatString})` : ""}`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
console.log(` Readonly: ${variable.readonly}`);
|
|
119
|
+
console.log(` Calculate on demand: ${variable.calculateOnDemand}`);
|
|
120
|
+
if (variable.folderPath) {
|
|
121
|
+
console.log(` Folder: ${variable.folderPath.join(" / ")}`);
|
|
122
|
+
}
|
|
123
|
+
if (variable.cells && variable.cells.length > 0) {
|
|
124
|
+
console.log(` Cells with data: ${variable.cells.length}`);
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
handleModelError(error, tenant);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
variablesCmd.command("create [org] [tenant]").description("Create a new variable").requiredOption("--name <name>", "Variable name").option("--dimensions <csv>", "Comma-separated dimension table names").option("--formula <expr>", "Formula expression").option("--rollup <type>", "Rollup type (Sum, Average, Min, Max, Last, First, Count)").option("--data-type <type>", "Data type (Decimal, Integer, Text)", "Decimal").option("--description <text>", "Variable description").option("--readonly", "Set variable as read-only").action(async (first, second, options) => {
|
|
131
|
+
const { organisation, tenant } = (0, import_helpers.resolveTenantWithOrgMapping)(first, second);
|
|
132
|
+
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
133
|
+
if (!nativeClient) {
|
|
134
|
+
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
await nativeClient.initTagMap();
|
|
139
|
+
const tableGids = [];
|
|
140
|
+
if (options.dimensions) {
|
|
141
|
+
const tableNames = options.dimensions.split(",").map((s) => s.trim());
|
|
142
|
+
for (const tableName of tableNames) {
|
|
143
|
+
const table = await nativeClient.getDimensionTable(tableName);
|
|
144
|
+
tableGids.push(table.id);
|
|
175
145
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
146
|
+
}
|
|
147
|
+
const createEntity = {
|
|
148
|
+
type: "VAR",
|
|
149
|
+
meta: {
|
|
150
|
+
name: options.name,
|
|
151
|
+
description: options.description || null
|
|
152
|
+
},
|
|
153
|
+
variable: {
|
|
154
|
+
tableGids,
|
|
155
|
+
rollupType: options.rollup || "Sum",
|
|
156
|
+
dataType: options.dataType || "Decimal",
|
|
157
|
+
readonly: options.readonly || false
|
|
181
158
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
159
|
+
};
|
|
160
|
+
if (options.formula) {
|
|
161
|
+
createEntity.calculation = { formula: options.formula };
|
|
162
|
+
}
|
|
163
|
+
const result = await nativeClient.entities.mutate({ created: [createEntity] });
|
|
164
|
+
import_logger.logger.success(`Created variable "${options.name}".`);
|
|
165
|
+
if (result.created?.length > 0) {
|
|
166
|
+
import_logger.logger.dim(` ID: ${result.created[0].id}`);
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
170
|
+
import_logger.logger.error(`Failed to create variable "${options.name}".`);
|
|
171
|
+
import_logger.logger.dim(errorMessage);
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
variablesCmd.command("update [org] [tenant]").description("Update an existing variable").requiredOption("--name <name>", "Variable name").option("--formula <expr>", "New formula expression").option("--rollup <type>", "New rollup type").option("--description <text>", "New description").option("--readonly", "Set as read-only").option("--no-readonly", "Set as editable").action(async (first, second, options) => {
|
|
176
|
+
const { organisation, tenant } = (0, import_helpers.resolveTenantWithOrgMapping)(first, second);
|
|
177
|
+
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
178
|
+
if (!nativeClient) {
|
|
179
|
+
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
180
|
+
process.exit(1);
|
|
188
181
|
}
|
|
189
|
-
|
|
190
|
-
|
|
182
|
+
try {
|
|
183
|
+
await nativeClient.initTagMap();
|
|
184
|
+
const variable = await nativeClient.getVariable(options.name);
|
|
185
|
+
const updateEntity = {
|
|
186
|
+
id: variable.id,
|
|
187
|
+
type: "VAR"
|
|
188
|
+
};
|
|
189
|
+
if (options.description !== void 0) {
|
|
190
|
+
updateEntity.meta = { name: variable.name, description: options.description };
|
|
191
|
+
}
|
|
192
|
+
const variableUpdate = {};
|
|
193
|
+
if (options.rollup) variableUpdate.rollupType = options.rollup;
|
|
194
|
+
if (options.readonly !== void 0) variableUpdate.readonly = options.readonly;
|
|
195
|
+
if (Object.keys(variableUpdate).length > 0) {
|
|
196
|
+
updateEntity.variable = variableUpdate;
|
|
197
|
+
}
|
|
198
|
+
if (options.formula !== void 0) {
|
|
199
|
+
updateEntity.calculation = { formula: options.formula };
|
|
200
|
+
}
|
|
201
|
+
await nativeClient.entities.mutate({ updated: [updateEntity] });
|
|
202
|
+
import_logger.logger.success(`Updated variable "${options.name}".`);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
205
|
+
import_logger.logger.error(`Failed to update variable "${options.name}".`);
|
|
206
|
+
import_logger.logger.dim(errorMessage);
|
|
207
|
+
process.exit(1);
|
|
191
208
|
}
|
|
192
|
-
|
|
193
|
-
|
|
209
|
+
});
|
|
210
|
+
variableCmd.command("export <name>").description("Export variable data to CSV file").option("--output <file>", "Output file path").option("--format <format>", "Output format: csv, json, xlsx", "csv").option("--limit <n>", "Limit number of rows", parseInt).action(async (name, options) => {
|
|
211
|
+
const { organisation, tenant } = (0, import_helpers.resolveTenantWithOrgMapping)();
|
|
212
|
+
const nativeClient = await (0, import_farseerFactory.getNativeFarseerClient)(organisation, tenant);
|
|
213
|
+
if (!nativeClient) {
|
|
214
|
+
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
215
|
+
process.exit(1);
|
|
194
216
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
217
|
+
try {
|
|
218
|
+
import_logger.logger.info(`Exporting variable "${name}" from ${tenant}...`);
|
|
219
|
+
const exportRequest = {
|
|
220
|
+
formula: name,
|
|
221
|
+
format: options.format || "csv"
|
|
222
|
+
};
|
|
223
|
+
if (options.limit) {
|
|
224
|
+
exportRequest.limit = options.limit;
|
|
225
|
+
}
|
|
226
|
+
const blob = await nativeClient.export.exportFormula(exportRequest);
|
|
227
|
+
const content = await blob.text();
|
|
228
|
+
const outputFile = options.output || `${name.replace(/[^a-zA-Z0-9_-]/g, "_")}.${options.format || "csv"}`;
|
|
229
|
+
fs.writeFileSync(outputFile, content, "utf-8");
|
|
230
|
+
import_logger.logger.success(`Exported to ${outputFile}`);
|
|
231
|
+
const lines = content.split("\n").filter((l) => l.trim()).length;
|
|
232
|
+
import_logger.logger.dim(`${lines - 1} data rows`);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
235
|
+
import_logger.logger.error(`Failed to export variable "${name}".`);
|
|
236
|
+
import_logger.logger.dim(errorMessage);
|
|
237
|
+
process.exit(1);
|
|
198
238
|
}
|
|
199
|
-
|
|
239
|
+
});
|
|
200
240
|
}
|
|
241
|
+
function handleModelError(error, tenant) {
|
|
242
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
243
|
+
if ((0, import_farseerFactory.isAuthError)(error)) {
|
|
244
|
+
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
245
|
+
} else if (errorMessage.includes("404")) {
|
|
246
|
+
import_logger.logger.error(`Tenant "${tenant}" not found or not accessible.`);
|
|
247
|
+
} else if (errorMessage.includes("ENOTFOUND") || errorMessage.includes("ECONNREFUSED")) {
|
|
248
|
+
import_logger.logger.error("Failed to connect to Farseer.");
|
|
249
|
+
} else {
|
|
250
|
+
import_logger.logger.error("Failed to fetch model.");
|
|
251
|
+
import_logger.logger.dim(errorMessage);
|
|
252
|
+
}
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
255
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
256
|
+
0 && (module.exports = {
|
|
257
|
+
registerVariablesCommand
|
|
258
|
+
});
|
|
259
|
+
//# sourceMappingURL=variables.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/commands/variables.ts"],
|
|
4
|
+
"sourcesContent": ["import { Command } from 'commander';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport chalk from 'chalk';\nimport { logger } from '../utils/logger';\nimport {\n getFarseerClientWithFallback,\n getNativeFarseerClient,\n showLoginPrompt,\n isAuthError,\n} from '../services/farseerFactory';\nimport { resolveTenantWithOrgMapping } from '../utils/helpers';\n\nexport function registerVariablesCommand(program: Command): void {\n // farseer variables list\n const variablesCmd = program.command('variables').description('List and manage variables');\n\n variablesCmd\n .command('list [org] [tenant]')\n .description('List all variables')\n .option('--json', 'Output raw JSON')\n .action(async (first, second, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping(first, second);\n const result = await getFarseerClientWithFallback(organisation, tenant);\n\n if (!result) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n try {\n const model = await result.client.exportModel();\n\n if (options.json) {\n console.log(JSON.stringify(model.variables, null, 2));\n return;\n }\n\n logger.header(`Variables (${model.variables.length})`);\n console.log();\n for (const variable of model.variables) {\n const flags = [];\n if (variable.readonly) flags.push('readonly');\n if (variable.calculateOnDemand) flags.push('on-demand');\n const flagStr = flags.length > 0 ? chalk.dim(` [${flags.join(', ')}]`) : '';\n\n console.log(` ${chalk.bold(variable.name)}${flagStr}`);\n console.log(` Dimensions: ${variable.tables.join(', ')}`);\n console.log(` Rollup: ${variable.rollupType} | Type: ${variable.dataType}`);\n if (variable.formula) {\n console.log(\n ` Formula: ${chalk.dim(variable.formula.substring(0, 80))}${variable.formula.length > 80 ? '...' : ''}`,\n );\n }\n console.log();\n }\n } catch (error) {\n handleModelError(error, tenant);\n }\n });\n\n // farseer variable details / export (singular)\n const variableCmd = program.command('variable').description('Variable details and export');\n\n variableCmd\n .command('details <name>')\n .description('Show variable details (dimensions, formula, rollup, etc.)')\n .option('--json', 'Output raw JSON')\n .action(async (name, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping();\n const result = await getFarseerClientWithFallback(organisation, tenant);\n\n if (!result) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n try {\n const model = await result.client.exportModel();\n const variable = model.variables.find((v) => v.name.toLowerCase() === name.toLowerCase());\n\n if (!variable) {\n logger.error(`Variable \"${name}\" not found.`);\n logger.dim('Available variables:');\n model.variables.slice(0, 10).forEach((v) => logger.dim(` - ${v.name}`));\n if (model.variables.length > 10) {\n logger.dim(` ... and ${model.variables.length - 10} more`);\n }\n process.exit(1);\n }\n\n if (options.json) {\n console.log(JSON.stringify(variable, null, 2));\n return;\n }\n\n logger.header(`Variable: ${variable.name}`);\n console.log();\n if (variable.description) {\n console.log(` Description: ${variable.description}`);\n }\n if (variable.formula) {\n console.log(` Formula: ${variable.formula}`);\n }\n console.log(` Dimensions: ${variable.tables.join(', ')}`);\n if (variable.members.length > 0) {\n console.log(` Specific members: ${variable.members.join(', ')}`);\n }\n console.log(` Roll-up type: ${variable.rollupType}`);\n console.log(` Data type: ${variable.dataType}`);\n if (variable.numberFormat) {\n console.log(\n ` Format: ${variable.numberFormat.type}${variable.numberFormat.formatString ? ` (${variable.numberFormat.formatString})` : ''}`,\n );\n }\n console.log(` Readonly: ${variable.readonly}`);\n console.log(` Calculate on demand: ${variable.calculateOnDemand}`);\n if (variable.folderPath) {\n console.log(` Folder: ${variable.folderPath.join(' / ')}`);\n }\n if (variable.cells && variable.cells.length > 0) {\n console.log(` Cells with data: ${variable.cells.length}`);\n }\n } catch (error) {\n handleModelError(error, tenant);\n }\n });\n\n // farseer variables create [org] [tenant]\n variablesCmd\n .command('create [org] [tenant]')\n .description('Create a new variable')\n .requiredOption('--name <name>', 'Variable name')\n .option('--dimensions <csv>', 'Comma-separated dimension table names')\n .option('--formula <expr>', 'Formula expression')\n .option('--rollup <type>', 'Rollup type (Sum, Average, Min, Max, Last, First, Count)')\n .option('--data-type <type>', 'Data type (Decimal, Integer, Text)', 'Decimal')\n .option('--description <text>', 'Variable description')\n .option('--readonly', 'Set variable as read-only')\n .action(async (first, second, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping(first, second);\n const nativeClient = await getNativeFarseerClient(organisation, tenant);\n\n if (!nativeClient) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n try {\n await nativeClient.initTagMap();\n\n // Resolve dimension table names to IDs\n const tableGids: number[] = [];\n if (options.dimensions) {\n const tableNames = options.dimensions.split(',').map((s: string) => s.trim());\n for (const tableName of tableNames) {\n const table = await nativeClient.getDimensionTable(tableName);\n tableGids.push(table.id);\n }\n }\n\n const createEntity: any = {\n type: 'VAR',\n meta: {\n name: options.name,\n description: options.description || null,\n },\n variable: {\n tableGids,\n rollupType: options.rollup || 'Sum',\n dataType: options.dataType || 'Decimal',\n readonly: options.readonly || false,\n },\n };\n\n if (options.formula) {\n createEntity.calculation = { formula: options.formula };\n }\n\n const result = await nativeClient.entities.mutate({ created: [createEntity] });\n logger.success(`Created variable \"${options.name}\".`);\n if ((result as any).created?.length > 0) {\n logger.dim(` ID: ${(result as any).created[0].id}`);\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.error(`Failed to create variable \"${options.name}\".`);\n logger.dim(errorMessage);\n process.exit(1);\n }\n });\n\n // farseer variables update [org] [tenant]\n variablesCmd\n .command('update [org] [tenant]')\n .description('Update an existing variable')\n .requiredOption('--name <name>', 'Variable name')\n .option('--formula <expr>', 'New formula expression')\n .option('--rollup <type>', 'New rollup type')\n .option('--description <text>', 'New description')\n .option('--readonly', 'Set as read-only')\n .option('--no-readonly', 'Set as editable')\n .action(async (first, second, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping(first, second);\n const nativeClient = await getNativeFarseerClient(organisation, tenant);\n\n if (!nativeClient) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n try {\n await nativeClient.initTagMap();\n const variable = await nativeClient.getVariable(options.name);\n\n const updateEntity: any = {\n id: variable.id,\n type: 'VAR',\n };\n\n if (options.description !== undefined) {\n updateEntity.meta = { name: variable.name, description: options.description };\n }\n\n const variableUpdate: any = {};\n if (options.rollup) variableUpdate.rollupType = options.rollup;\n if (options.readonly !== undefined) variableUpdate.readonly = options.readonly;\n if (Object.keys(variableUpdate).length > 0) {\n updateEntity.variable = variableUpdate;\n }\n\n if (options.formula !== undefined) {\n updateEntity.calculation = { formula: options.formula };\n }\n\n await nativeClient.entities.mutate({ updated: [updateEntity] });\n logger.success(`Updated variable \"${options.name}\".`);\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.error(`Failed to update variable \"${options.name}\".`);\n logger.dim(errorMessage);\n process.exit(1);\n }\n });\n\n variableCmd\n .command('export <name>')\n .description('Export variable data to CSV file')\n .option('--output <file>', 'Output file path')\n .option('--format <format>', 'Output format: csv, json, xlsx', 'csv')\n .option('--limit <n>', 'Limit number of rows', parseInt)\n .action(async (name, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping();\n const nativeClient = await getNativeFarseerClient(organisation, tenant);\n\n if (!nativeClient) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n try {\n logger.info(`Exporting variable \"${name}\" from ${tenant}...`);\n\n const exportRequest: any = {\n formula: name,\n format: options.format || 'csv',\n };\n if (options.limit) {\n exportRequest.limit = options.limit;\n }\n\n const blob = await nativeClient.export.exportFormula(exportRequest);\n const content = await blob.text();\n\n const outputFile =\n options.output || `${name.replace(/[^a-zA-Z0-9_-]/g, '_')}.${options.format || 'csv'}`;\n fs.writeFileSync(outputFile, content, 'utf-8');\n\n logger.success(`Exported to ${outputFile}`);\n const lines = content.split('\\n').filter((l) => l.trim()).length;\n logger.dim(`${lines - 1} data rows`);\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.error(`Failed to export variable \"${name}\".`);\n logger.dim(errorMessage);\n process.exit(1);\n }\n });\n}\n\nfunction handleModelError(error: unknown, tenant: string): void {\n const errorMessage = error instanceof Error ? error.message : String(error);\n\n if (isAuthError(error)) {\n showLoginPrompt(tenant);\n } else if (errorMessage.includes('404')) {\n logger.error(`Tenant \"${tenant}\" not found or not accessible.`);\n } else if (errorMessage.includes('ENOTFOUND') || errorMessage.includes('ECONNREFUSED')) {\n logger.error('Failed to connect to Farseer.');\n } else {\n logger.error('Failed to fetch model.');\n logger.dim(errorMessage);\n }\n process.exit(1);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,SAAoB;AAEpB,mBAAkB;AAClB,oBAAuB;AACvB,4BAKO;AACP,qBAA4C;AAErC,SAAS,yBAAyB,SAAwB;AAE7D,QAAM,eAAe,QAAQ,QAAQ,WAAW,EAAE,YAAY,2BAA2B;AAEzF,eACK,QAAQ,qBAAqB,EAC7B,YAAY,oBAAoB,EAChC,OAAO,UAAU,iBAAiB,EAClC,OAAO,OAAO,OAAO,QAAQ,YAAY;AACtC,UAAM,EAAE,cAAc,OAAO,QAAI,4CAA4B,OAAO,MAAM;AAC1E,UAAM,SAAS,UAAM,oDAA6B,cAAc,MAAM;AAEtE,QAAI,CAAC,QAAQ;AACT,iDAAgB,MAAM;AACtB,cAAQ,KAAK,CAAC;AAAA,IAClB;AAEA,QAAI;AACA,YAAM,QAAQ,MAAM,OAAO,OAAO,YAAY;AAE9C,UAAI,QAAQ,MAAM;AACd,gBAAQ,IAAI,KAAK,UAAU,MAAM,WAAW,MAAM,CAAC,CAAC;AACpD;AAAA,MACJ;AAEA,2BAAO,OAAO,cAAc,MAAM,UAAU,MAAM,GAAG;AACrD,cAAQ,IAAI;AACZ,iBAAW,YAAY,MAAM,WAAW;AACpC,cAAM,QAAQ,CAAC;AACf,YAAI,SAAS,SAAU,OAAM,KAAK,UAAU;AAC5C,YAAI,SAAS,kBAAmB,OAAM,KA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