@bluecopa/core 0.1.2

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 (47) hide show
  1. package/README.md +312 -0
  2. package/dist/api/client.d.ts +2 -0
  3. package/dist/api/dataset/getData.d.ts +5 -0
  4. package/dist/api/dataset/getSampleData.d.ts +8 -0
  5. package/dist/api/dataset/index.d.ts +2 -0
  6. package/dist/api/definition/index.d.ts +3 -0
  7. package/dist/api/definition/runDefinition.d.ts +9 -0
  8. package/dist/api/definition/runPublishedDefinition.d.ts +11 -0
  9. package/dist/api/definition/runSampleDefinition.d.ts +6 -0
  10. package/dist/api/file/getFileUrlByFileId.d.ts +18 -0
  11. package/dist/api/file/index.d.ts +1 -0
  12. package/dist/api/index.d.ts +8 -0
  13. package/dist/api/inputTable/getData.d.ts +11 -0
  14. package/dist/api/inputTable/getTableById.d.ts +2 -0
  15. package/dist/api/inputTable/index.d.ts +2 -0
  16. package/dist/api/metric/getData.d.ts +10 -0
  17. package/dist/api/metric/index.d.ts +1 -0
  18. package/dist/api/user/getLoggedInUserDetails.d.ts +25 -0
  19. package/dist/api/user/index.d.ts +1 -0
  20. package/dist/api/workbook/getPublishedWorkbookById.d.ts +5 -0
  21. package/dist/api/workbook/index.d.ts +0 -0
  22. package/dist/api/workflow/index.d.ts +2 -0
  23. package/dist/api/workflow/triggerHttpWorkflow.d.ts +20 -0
  24. package/dist/api/workflow/triggerWorkflow.d.ts +23 -0
  25. package/dist/api/worksheet/getWorksheets.d.ts +2 -0
  26. package/dist/api/worksheet/index.d.ts +1 -0
  27. package/dist/config.d.ts +18 -0
  28. package/dist/index.d.ts +4 -0
  29. package/dist/index.es.js +2321 -0
  30. package/dist/index.es.js.map +1 -0
  31. package/dist/tailwind/bluecopa.config.d.ts +164 -0
  32. package/dist/types/workbook.d.ts +13 -0
  33. package/dist/utils/date.d.ts +1 -0
  34. package/dist/utils/file/downloadFile.d.ts +1 -0
  35. package/dist/utils/index.d.ts +3 -0
  36. package/dist/utils/inputTable/index.d.ts +1 -0
  37. package/dist/utils/inputTable/inputTableDefinition.d.ts +35 -0
  38. package/dist/utils/metric/analysisMethods.d.ts +424 -0
  39. package/dist/utils/metric/buildVariable.d.ts +19 -0
  40. package/dist/utils/metric/displayNamesUtil.d.ts +7 -0
  41. package/dist/utils/metric/filterUtils.d.ts +22 -0
  42. package/dist/utils/metric/getMetricDefinition.d.ts +28 -0
  43. package/dist/utils/metric/hydrateWorksheet.d.ts +2 -0
  44. package/dist/utils/metric/inputNameUtil.d.ts +1 -0
  45. package/dist/utils/metric/mergeFilterService.d.ts +34 -0
  46. package/dist/utils/metric/variableUtils.d.ts +5 -0
  47. package/package.json +39 -0
@@ -0,0 +1,2321 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import axios from "axios";
5
+ import _ from "lodash";
6
+ class ConfigSingleton {
7
+ constructor() {
8
+ this.config = {
9
+ apiBaseUrl: "",
10
+ accessToken: "",
11
+ workspaceId: ""
12
+ };
13
+ }
14
+ static getInstance() {
15
+ if (!ConfigSingleton.instance) {
16
+ ConfigSingleton.instance = new ConfigSingleton();
17
+ }
18
+ return ConfigSingleton.instance;
19
+ }
20
+ setConfig(newConfig) {
21
+ this.config = { ...this.config, ...newConfig };
22
+ }
23
+ getConfig() {
24
+ return { ...this.config };
25
+ }
26
+ resetConfig() {
27
+ this.config = {
28
+ apiBaseUrl: "",
29
+ accessToken: "",
30
+ workspaceId: ""
31
+ };
32
+ }
33
+ }
34
+ const configInstance = ConfigSingleton.getInstance();
35
+ function setConfig(newConfig) {
36
+ configInstance.setConfig(newConfig);
37
+ }
38
+ function getConfig() {
39
+ return configInstance.getConfig();
40
+ }
41
+ const createApiClient = () => {
42
+ const client = axios.create({
43
+ timeout: 1e4,
44
+ headers: {
45
+ "Content-Type": "application/json"
46
+ }
47
+ });
48
+ client.interceptors.request.use(
49
+ (config) => {
50
+ const copaConfig = getConfig();
51
+ if (copaConfig.apiBaseUrl) {
52
+ config.baseURL = copaConfig.apiBaseUrl;
53
+ }
54
+ if (copaConfig.accessToken && config.headers) {
55
+ config.headers["X-COPA-TOKEN"] = `Bearer ${copaConfig.accessToken}`;
56
+ }
57
+ if (copaConfig.workspaceId && config.headers) {
58
+ config.headers["X-COPA-WORKSPACE-ID"] = copaConfig.workspaceId;
59
+ }
60
+ console.log("API Request Config:", {
61
+ baseURL: config.baseURL,
62
+ hasToken: !!copaConfig.accessToken,
63
+ hasWorkspaceId: !!copaConfig.workspaceId
64
+ });
65
+ return config;
66
+ },
67
+ (error) => {
68
+ return Promise.reject(error);
69
+ }
70
+ );
71
+ client.interceptors.response.use(
72
+ (response) => {
73
+ return response;
74
+ },
75
+ (error) => {
76
+ var _a;
77
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
78
+ setConfig({ accessToken: "", workspaceId: "" });
79
+ }
80
+ return Promise.reject(error);
81
+ }
82
+ );
83
+ return client;
84
+ };
85
+ const apiClient = createApiClient();
86
+ async function getLoggedInUserDetails() {
87
+ var _a, _b, _c;
88
+ try {
89
+ const response = await apiClient.get("/user/current");
90
+ if (!response.data) {
91
+ throw { message: "Failed to fetch user details", status: 500 };
92
+ }
93
+ return response.data;
94
+ } catch (error) {
95
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while fetching user details";
96
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
97
+ throw { message, status };
98
+ }
99
+ }
100
+ const index$8 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
101
+ __proto__: null,
102
+ getLoggedInUserDetails
103
+ }, Symbol.toStringTag, { value: "Module" }));
104
+ async function triggerHttpWorkflow({
105
+ data,
106
+ triggerId
107
+ }) {
108
+ var _a, _b, _c;
109
+ try {
110
+ const response = await apiClient.post(`/http-trigger/${triggerId}`, data);
111
+ if (!response.data) {
112
+ throw { message: "Failed to trigger HTTP workflow", status: 500 };
113
+ }
114
+ return response.data;
115
+ } catch (error) {
116
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while triggering the HTTP workflow";
117
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
118
+ throw { message, status };
119
+ }
120
+ }
121
+ async function triggerWorkflow({
122
+ parentId,
123
+ triggerBy
124
+ }) {
125
+ var _a, _b, _c;
126
+ try {
127
+ const response = await apiClient.post("/workflow/trigger", { parentId, triggerBy });
128
+ if (!response.data) {
129
+ throw { message: "Failed to trigger workflow", status: 500 };
130
+ }
131
+ return response.data;
132
+ } catch (error) {
133
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while triggering the workflow";
134
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
135
+ throw { message, status };
136
+ }
137
+ }
138
+ const index$7 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
139
+ __proto__: null,
140
+ triggerHttpWorkflow,
141
+ triggerWorkflow
142
+ }, Symbol.toStringTag, { value: "Module" }));
143
+ async function getFileUrlByFileId({
144
+ key,
145
+ contentType,
146
+ method
147
+ }) {
148
+ var _a, _b, _c;
149
+ try {
150
+ const response = await apiClient.post("/file/url", { key, contentType, method });
151
+ if (!response.data) {
152
+ throw { message: "Failed to get file URL", status: 500 };
153
+ }
154
+ return { url: response.data };
155
+ } catch (error) {
156
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while getting file URL";
157
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
158
+ throw { message, status };
159
+ }
160
+ }
161
+ const index$6 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
162
+ __proto__: null,
163
+ getFileUrlByFileId
164
+ }, Symbol.toStringTag, { value: "Module" }));
165
+ const runPublishedDefinition = async (props) => {
166
+ const { sheet, variable, inputs, describe, source } = props;
167
+ if (!sheet) {
168
+ throw new Error(`Definition is null`);
169
+ }
170
+ if (!variable) {
171
+ throw new Error(`Variable is null`);
172
+ }
173
+ return apiClient.post(
174
+ "/definition/run-published",
175
+ {
176
+ sheet,
177
+ variable,
178
+ inputs,
179
+ describe
180
+ },
181
+ { cancelToken: source == null ? void 0 : source.token }
182
+ );
183
+ };
184
+ const runSampleDefinition = async (props) => {
185
+ const { datasetId, dataFilter, duplicateColGroups, datasetType } = props;
186
+ if (!datasetId) {
187
+ throw new Error(`Dataset ID is null`);
188
+ }
189
+ if (!dataFilter) {
190
+ throw new Error(`Data filter is null`);
191
+ }
192
+ return apiClient.post(
193
+ "/definition/run-sample",
194
+ { datasetId, dataFilter, duplicateColGroups, datasetType }
195
+ );
196
+ };
197
+ const runDefinition = async (props) => {
198
+ const { definition, variable, inputs, limit, source } = props;
199
+ if (!definition) {
200
+ throw new Error(`Definition is null`);
201
+ }
202
+ if (!variable) {
203
+ throw new Error(`Variable is null`);
204
+ }
205
+ if (!inputs) {
206
+ throw new Error(`Inputs is null`);
207
+ }
208
+ return apiClient.post(
209
+ "/definition/run-sample",
210
+ { inputs, definition, variable, limit },
211
+ { cancelToken: source == null ? void 0 : source.token }
212
+ );
213
+ };
214
+ const index$5 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
215
+ __proto__: null,
216
+ runDefinition,
217
+ runPublishedDefinition,
218
+ runSampleDefinition
219
+ }, Symbol.toStringTag, { value: "Module" }));
220
+ const getWorksheets = async (worksheetIds) => {
221
+ var _a, _b, _c;
222
+ try {
223
+ const response = await apiClient.post("/worksheet/get-worksheets", {
224
+ ids: worksheetIds
225
+ });
226
+ if (!response.data) {
227
+ throw { message: "Failed to fetch worksheets details", status: 500 };
228
+ }
229
+ return response.data;
230
+ } catch (error) {
231
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while fetching worksheets details";
232
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
233
+ throw { message, status };
234
+ }
235
+ };
236
+ function formatDate(date) {
237
+ return date.toISOString().split("T")[0];
238
+ }
239
+ var ShowAsEnum = /* @__PURE__ */ ((ShowAsEnum2) => {
240
+ ShowAsEnum2["DEFAULT"] = "default";
241
+ ShowAsEnum2["ROW"] = "row";
242
+ ShowAsEnum2["COLUMN"] = "column";
243
+ ShowAsEnum2["GRAND_TOTAL"] = "grandTotal";
244
+ return ShowAsEnum2;
245
+ })(ShowAsEnum || {});
246
+ var CustomCalculationShowAsEnum = /* @__PURE__ */ ((CustomCalculationShowAsEnum2) => {
247
+ CustomCalculationShowAsEnum2["NONE"] = "none";
248
+ CustomCalculationShowAsEnum2["FORMULA"] = "formula";
249
+ CustomCalculationShowAsEnum2["AGGREGATE"] = "aggregate";
250
+ return CustomCalculationShowAsEnum2;
251
+ })(CustomCalculationShowAsEnum || {});
252
+ class ClientEnvironmentVariablesHolder {
253
+ constructor() {
254
+ __publicField(this, "envVariables");
255
+ const envClone = _.clone(process.env);
256
+ this.envVariables = {
257
+ [
258
+ "MAX_PIVOT_CELL_COUNT"
259
+ /* MAX_PIVOT_CELL_COUNT */
260
+ ]: envClone.MAX_PIVOT_CELL_COUNT,
261
+ [
262
+ "ADMIN_EMAIL"
263
+ /* ADMIN_EMAIL */
264
+ ]: envClone.ADMIN_EMAIL,
265
+ [
266
+ "MAX_LINES_FOR_REPORT_CHART"
267
+ /* MAX_LINES_FOR_REPORT_CHART */
268
+ ]: envClone.MAX_LINES_FOR_REPORT_CHART,
269
+ [
270
+ "ROW_LIMIT"
271
+ /* ROW_LIMIT */
272
+ ]: envClone.ROW_LIMIT,
273
+ [
274
+ "ENABLE_STATIC_TEMPLATES"
275
+ /* ENABLE_STATIC_TEMPLATES */
276
+ ]: envClone.ENABLE_STATIC_TEMPLATES,
277
+ [
278
+ "MAX_UNIQUE_VALUES_COUNT"
279
+ /* MAX_UNIQUE_VALUES_COUNT */
280
+ ]: envClone.MAX_UNIQUE_VALUES_COUNT,
281
+ [
282
+ "ENABLE_JUNIOR"
283
+ /* ENABLE_JUNIOR */
284
+ ]: envClone.ENABLE_JUNIOR,
285
+ [
286
+ "SHOULD_SHOW_MODEL"
287
+ /* SHOULD_SHOW_MODEL */
288
+ ]: envClone.SHOULD_SHOW_MODEL,
289
+ [
290
+ "PROD"
291
+ /* PROD */
292
+ ]: envClone.PROD,
293
+ [
294
+ "DD_LOGGING_CLIENT_TOKEN"
295
+ /* DD_LOGGING_CLIENT_TOKEN */
296
+ ]: envClone.DD_LOGGING_CLIENT_TOKEN,
297
+ [
298
+ "APP_NAME"
299
+ /* APP_NAME */
300
+ ]: envClone.APP_NAME,
301
+ [
302
+ "FAVICON_URL"
303
+ /* FAVICON_URL */
304
+ ]: envClone.FAVICON_URL,
305
+ [
306
+ "EXT_BRANDING_LOGO"
307
+ /* EXT_BRANDING_LOGO */
308
+ ]: envClone.EXT_BRANDING_LOGO,
309
+ [
310
+ "AGGRID_LICENSE_KEY"
311
+ /* AGGRID_LICENSE_KEY */
312
+ ]: envClone.AGGRID_LICENSE_KEY,
313
+ [
314
+ "AMCHARTS_LICENSE"
315
+ /* AMCHARTS_LICENSE */
316
+ ]: envClone.AMCHARTS_LICENSE,
317
+ [
318
+ "ONEDRIVE_CLIENT_ID"
319
+ /* ONEDRIVE_CLIENT_ID */
320
+ ]: envClone.ONEDRIVE_CLIENT_ID,
321
+ [
322
+ "DBT_TRANSFORMATIONS_BRANCH"
323
+ /* DBT_TRANSFORMATIONS_BRANCH */
324
+ ]: envClone.DBT_TRANSFORMATIONS_BRANCH,
325
+ [
326
+ "WEBSOCKET_MECHANISM"
327
+ /* WEBSOCKET_MECHANISM */
328
+ ]: envClone.WEBSOCKET_MECHANISM,
329
+ [
330
+ "PUSHER_APP_KEY"
331
+ /* PUSHER_APP_KEY */
332
+ ]: envClone.PUSHER_APP_KEY,
333
+ [
334
+ "PUSHER_APP_CLUSTER"
335
+ /* PUSHER_APP_CLUSTER */
336
+ ]: envClone.PUSHER_APP_CLUSTER,
337
+ [
338
+ "PUSHER_APP_SECRET"
339
+ /* PUSHER_APP_SECRET */
340
+ ]: envClone.PUSHER_APP_SECRET,
341
+ [
342
+ "PUSHER_APP_ID"
343
+ /* PUSHER_APP_ID */
344
+ ]: envClone.PUSHER_APP_ID,
345
+ [
346
+ "CENTRIFUGO_WEBSOCKET_URL"
347
+ /* CENTRIFUGO_WEBSOCKET_URL */
348
+ ]: envClone.CENTRIFUGO_WEBSOCKET_URL,
349
+ [
350
+ "CENTRIFUGO_WEBSOCKET_TOKEN"
351
+ /* CENTRIFUGO_WEBSOCKET_TOKEN */
352
+ ]: envClone.CENTRIFUGO_WEBSOCKET_TOKEN,
353
+ [
354
+ "DEPLOYMENT_PLATFORM"
355
+ /* DEPLOYMENT_PLATFORM */
356
+ ]: envClone.DEPLOYMENT_PLATFORM,
357
+ [
358
+ "DISABLE_UI_LOGGING"
359
+ /* DISABLE_UI_LOGGING */
360
+ ]: envClone.DISABLE_UI_LOGGING
361
+ };
362
+ }
363
+ set variables(values) {
364
+ Object.keys(values).forEach((key) => {
365
+ this.envVariables[key] = values[key];
366
+ });
367
+ }
368
+ get(key) {
369
+ return this.envVariables[key];
370
+ }
371
+ get MAX_PIVOT_CELL_COUNT() {
372
+ return this.get(
373
+ "MAX_PIVOT_CELL_COUNT"
374
+ /* MAX_PIVOT_CELL_COUNT */
375
+ );
376
+ }
377
+ get ADMIN_EMAIL() {
378
+ return this.get(
379
+ "ADMIN_EMAIL"
380
+ /* ADMIN_EMAIL */
381
+ );
382
+ }
383
+ get MAX_LINES_FOR_REPORT_CHART() {
384
+ return this.get(
385
+ "MAX_LINES_FOR_REPORT_CHART"
386
+ /* MAX_LINES_FOR_REPORT_CHART */
387
+ );
388
+ }
389
+ get ROW_LIMIT() {
390
+ return this.get(
391
+ "ROW_LIMIT"
392
+ /* ROW_LIMIT */
393
+ );
394
+ }
395
+ get ENABLE_STATIC_TEMPLATES() {
396
+ return this.get(
397
+ "ENABLE_STATIC_TEMPLATES"
398
+ /* ENABLE_STATIC_TEMPLATES */
399
+ );
400
+ }
401
+ get MAX_UNIQUE_VALUES_COUNT() {
402
+ if (this.get(
403
+ "MAX_UNIQUE_VALUES_COUNT"
404
+ /* MAX_UNIQUE_VALUES_COUNT */
405
+ )) {
406
+ return parseInt(this.get(
407
+ "MAX_UNIQUE_VALUES_COUNT"
408
+ /* MAX_UNIQUE_VALUES_COUNT */
409
+ ));
410
+ }
411
+ return 400;
412
+ }
413
+ get ENABLE_JUNIOR() {
414
+ return this.get(
415
+ "ENABLE_JUNIOR"
416
+ /* ENABLE_JUNIOR */
417
+ );
418
+ }
419
+ get SHOULD_SHOW_MODEL() {
420
+ return this.get(
421
+ "SHOULD_SHOW_MODEL"
422
+ /* SHOULD_SHOW_MODEL */
423
+ );
424
+ }
425
+ get PROD() {
426
+ return this.get(
427
+ "PROD"
428
+ /* PROD */
429
+ );
430
+ }
431
+ get DD_LOGGING_CLIENT_TOKEN() {
432
+ return this.get(
433
+ "DD_LOGGING_CLIENT_TOKEN"
434
+ /* DD_LOGGING_CLIENT_TOKEN */
435
+ );
436
+ }
437
+ get APP_NAME() {
438
+ return this.get(
439
+ "APP_NAME"
440
+ /* APP_NAME */
441
+ ) ?? "Bluecopa";
442
+ }
443
+ get FAVICON_URL() {
444
+ return this.get(
445
+ "FAVICON_URL"
446
+ /* FAVICON_URL */
447
+ );
448
+ }
449
+ get EXT_BRANDING_LOGO() {
450
+ return this.get(
451
+ "EXT_BRANDING_LOGO"
452
+ /* EXT_BRANDING_LOGO */
453
+ );
454
+ }
455
+ get AGGRID_LICENSE_KEY() {
456
+ return this.get(
457
+ "AGGRID_LICENSE_KEY"
458
+ /* AGGRID_LICENSE_KEY */
459
+ );
460
+ }
461
+ get AMCHARTS_LICENSE() {
462
+ return this.get(
463
+ "AMCHARTS_LICENSE"
464
+ /* AMCHARTS_LICENSE */
465
+ );
466
+ }
467
+ get WEBSOCKET_MECHANISM() {
468
+ return this.get(
469
+ "WEBSOCKET_MECHANISM"
470
+ /* WEBSOCKET_MECHANISM */
471
+ );
472
+ }
473
+ get ONEDRIVE_CLIENT_ID() {
474
+ return this.get(
475
+ "ONEDRIVE_CLIENT_ID"
476
+ /* ONEDRIVE_CLIENT_ID */
477
+ );
478
+ }
479
+ get DBT_TRANSFORMATIONS_BRANCH() {
480
+ return this.get(
481
+ "DBT_TRANSFORMATIONS_BRANCH"
482
+ /* DBT_TRANSFORMATIONS_BRANCH */
483
+ );
484
+ }
485
+ get PUSHER_APP_KEY() {
486
+ return this.get(
487
+ "PUSHER_APP_KEY"
488
+ /* PUSHER_APP_KEY */
489
+ );
490
+ }
491
+ get PUSHER_APP_CLUSTER() {
492
+ return this.get(
493
+ "PUSHER_APP_CLUSTER"
494
+ /* PUSHER_APP_CLUSTER */
495
+ );
496
+ }
497
+ get PUSHER_APP_SECRET() {
498
+ return this.get(
499
+ "PUSHER_APP_SECRET"
500
+ /* PUSHER_APP_SECRET */
501
+ );
502
+ }
503
+ get PUSHER_APP_ID() {
504
+ return this.get(
505
+ "PUSHER_APP_ID"
506
+ /* PUSHER_APP_ID */
507
+ );
508
+ }
509
+ get CENTRIFUGO_WEBSOCKET_URL() {
510
+ return this.get(
511
+ "CENTRIFUGO_WEBSOCKET_URL"
512
+ /* CENTRIFUGO_WEBSOCKET_URL */
513
+ );
514
+ }
515
+ get CENTRIFUGO_WEBSOCKET_TOKEN() {
516
+ return this.get(
517
+ "CENTRIFUGO_WEBSOCKET_TOKEN"
518
+ /* CENTRIFUGO_WEBSOCKET_TOKEN */
519
+ );
520
+ }
521
+ get DEPLOYMENT_PLATFORM() {
522
+ return this.get(
523
+ "DEPLOYMENT_PLATFORM"
524
+ /* DEPLOYMENT_PLATFORM */
525
+ );
526
+ }
527
+ get DISABLE_UI_LOGGING() {
528
+ return this.get(
529
+ "DISABLE_UI_LOGGING"
530
+ /* DISABLE_UI_LOGGING */
531
+ );
532
+ }
533
+ }
534
+ const clientEnvironmentVariablesHolder = new ClientEnvironmentVariablesHolder();
535
+ clientEnvironmentVariablesHolder.MAX_UNIQUE_VALUES_COUNT;
536
+ const defaultFilterPanel = {
537
+ is_not: false,
538
+ rule_type: "and_cond",
539
+ rules: []
540
+ };
541
+ const filterToSelectOptionType = (filter, columns) => {
542
+ const rules = (filter == null ? void 0 : filter.rules) || [];
543
+ if (!rules || rules.length === 0) {
544
+ return {
545
+ defaultType: "and_cond",
546
+ rules: []
547
+ };
548
+ }
549
+ const selectOptionsForRules = rules.map(
550
+ (rule) => getSelectionOptionsFromFilter(rule, columns)
551
+ );
552
+ return {
553
+ defaultType: (filter == null ? void 0 : filter.rule_type) || "and_cond",
554
+ rules: selectOptionsForRules
555
+ };
556
+ };
557
+ const getSelectionOptionsFromFilter = (rule, columns) => {
558
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
559
+ if (_.isEmpty(rule == null ? void 0 : rule.rules)) {
560
+ const col2 = columns.find((column) => column.label === rule.col || column.value === rule.col);
561
+ return {
562
+ label: (col2 == null ? void 0 : col2.label) || "",
563
+ value: (col2 == null ? void 0 : col2.value) || "",
564
+ option: {
565
+ aggFun: (_a = col2 == null ? void 0 : col2.option) == null ? void 0 : _a.aggFun,
566
+ uniqueValues: [
567
+ {
568
+ label: (col2 == null ? void 0 : col2.label) || "",
569
+ value: (col2 == null ? void 0 : col2.value) || "",
570
+ option: {
571
+ uniqueValue: rule == null ? void 0 : rule.value,
572
+ operator: rule == null ? void 0 : rule.operator,
573
+ ruleType: (rule == null ? void 0 : rule.rule_type) || "cond",
574
+ isNot: (rule == null ? void 0 : rule.is_not) || false,
575
+ caseSensitive: (rule == null ? void 0 : rule.is_case_sensitive) ?? true
576
+ }
577
+ }
578
+ ],
579
+ uniqueValueCount: (_b = col2 == null ? void 0 : col2.option) == null ? void 0 : _b.uniqueCount,
580
+ type: (_c = col2 == null ? void 0 : col2.option) == null ? void 0 : _c.type,
581
+ ruleType: (rule == null ? void 0 : rule.rule_type) || "cond"
582
+ }
583
+ };
584
+ }
585
+ const col = columns == null ? void 0 : columns.find(
586
+ (column) => {
587
+ var _a2, _b2, _c2, _d2;
588
+ return column.label === ((_b2 = (_a2 = rule == null ? void 0 : rule.rules) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.col) || column.value === ((_d2 = (_c2 = rule == null ? void 0 : rule.rules) == null ? void 0 : _c2[0]) == null ? void 0 : _d2.col);
589
+ }
590
+ );
591
+ const isValueFilter = _.get(rule, "rules.0.operator", null) === "in_op" && _.get(rule, "rules.0.value", null);
592
+ if (isValueFilter) {
593
+ return {
594
+ label: (col == null ? void 0 : col.label) || "",
595
+ value: (col == null ? void 0 : col.value) || "",
596
+ option: {
597
+ aggFun: (_d = col == null ? void 0 : col.option) == null ? void 0 : _d.aggFun,
598
+ uniqueValues: ((_g = (_f = (_e = rule == null ? void 0 : rule.rules) == null ? void 0 : _e[0]) == null ? void 0 : _f.value) == null ? void 0 : _g.map((r) => {
599
+ var _a2;
600
+ return {
601
+ label: (col == null ? void 0 : col.label) || "",
602
+ value: (col == null ? void 0 : col.value) || "",
603
+ option: {
604
+ aggFun: (_a2 = col == null ? void 0 : col.option) == null ? void 0 : _a2.aggFun,
605
+ uniqueValue: r,
606
+ operator: "equal",
607
+ ruleType: "cond",
608
+ isNot: false,
609
+ caseSensitive: true
610
+ }
611
+ };
612
+ })) || [],
613
+ uniqueValueCount: (_h = col == null ? void 0 : col.option) == null ? void 0 : _h.uniqueCount,
614
+ type: (_i = col == null ? void 0 : col.option) == null ? void 0 : _i.type,
615
+ ruleType: (rule == null ? void 0 : rule.rule_type) || "cond"
616
+ }
617
+ };
618
+ }
619
+ return {
620
+ label: (col == null ? void 0 : col.label) || "",
621
+ value: (col == null ? void 0 : col.value) || "",
622
+ option: {
623
+ aggFun: (_j = col == null ? void 0 : col.option) == null ? void 0 : _j.aggFun,
624
+ uniqueValues: ((_k = rule == null ? void 0 : rule.rules) == null ? void 0 : _k.map((r) => {
625
+ var _a2;
626
+ const childCol = columns == null ? void 0 : columns.find((column) => column.value === r.col);
627
+ return {
628
+ label: (childCol == null ? void 0 : childCol.label) || "",
629
+ value: (childCol == null ? void 0 : childCol.value) || "",
630
+ option: {
631
+ aggFun: (_a2 = childCol == null ? void 0 : childCol.option) == null ? void 0 : _a2.aggFun,
632
+ uniqueValue: r == null ? void 0 : r.value,
633
+ operator: r == null ? void 0 : r.operator,
634
+ ruleType: (r == null ? void 0 : r.rule_type) || "cond",
635
+ isNot: (r == null ? void 0 : r.is_not) || false,
636
+ caseSensitive: (r == null ? void 0 : r.is_case_sensitive) ?? true
637
+ }
638
+ };
639
+ })) || [],
640
+ uniqueValueCount: (_l = col == null ? void 0 : col.option) == null ? void 0 : _l.uniqueCount,
641
+ type: (_m = col == null ? void 0 : col.option) == null ? void 0 : _m.type,
642
+ ruleType: (rule == null ? void 0 : rule.rule_type) || "cond"
643
+ }
644
+ };
645
+ };
646
+ const getSelectOptionTypeToFilter = (filter, filterColumnsBy) => {
647
+ const rules = filter == null ? void 0 : filter.rules;
648
+ const defaultRuleType = filter == null ? void 0 : filter.defaultType;
649
+ if (!rules || rules.length === 0) {
650
+ return defaultFilterPanel;
651
+ }
652
+ let filterRules = rules == null ? void 0 : rules.map(
653
+ (rule) => getFilterRuleFromSelectionOptions(rule)
654
+ );
655
+ if (filterRules.length === 1 && filterRules[0].rules && filterRules[0].rules.length < 1) {
656
+ filterRules = [];
657
+ }
658
+ return {
659
+ is_not: false,
660
+ rule_type: defaultRuleType,
661
+ rules: filterRules
662
+ };
663
+ };
664
+ const getFilterRuleFromSelectionOptions = (rule, filterColumnsBy) => {
665
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
666
+ if (((_b = (_a = rule == null ? void 0 : rule.option) == null ? void 0 : _a.uniqueValues) == null ? void 0 : _b.length) > 2) {
667
+ return {
668
+ rule_type: "or_cond",
669
+ rules: [
670
+ {
671
+ col: rule.value,
672
+ value: _.map(((_c = rule == null ? void 0 : rule.option) == null ? void 0 : _c.uniqueValues) || [], (r) => r.option.uniqueValue),
673
+ operator: "in_op",
674
+ rule_type: "cond",
675
+ is_not: false,
676
+ is_case_sensitive: true
677
+ }
678
+ ],
679
+ is_not: false
680
+ };
681
+ }
682
+ if (((_e = (_d = rule == null ? void 0 : rule.option) == null ? void 0 : _d.uniqueValues) == null ? void 0 : _e.length) === 1) {
683
+ const uniqueValue = (_g = (_f = rule == null ? void 0 : rule.option) == null ? void 0 : _f.uniqueValues) == null ? void 0 : _g[0];
684
+ return {
685
+ col: rule.value,
686
+ value: (_h = uniqueValue == null ? void 0 : uniqueValue.option) == null ? void 0 : _h.uniqueValue,
687
+ operator: (_i = uniqueValue == null ? void 0 : uniqueValue.option) == null ? void 0 : _i.operator,
688
+ rule_type: ((_j = uniqueValue == null ? void 0 : uniqueValue.option) == null ? void 0 : _j.ruleType) ?? "cond",
689
+ is_not: ((_k = uniqueValue == null ? void 0 : uniqueValue.option) == null ? void 0 : _k.isNot) ?? false,
690
+ is_case_sensitive: ((_l = uniqueValue == null ? void 0 : uniqueValue.option) == null ? void 0 : _l.caseSensitive) ?? true
691
+ };
692
+ }
693
+ return {
694
+ rule_type: (_m = rule == null ? void 0 : rule.option) == null ? void 0 : _m.ruleType,
695
+ rules: (((_n = rule == null ? void 0 : rule.option) == null ? void 0 : _n.uniqueValues) || []).map((r) => {
696
+ var _a2, _b2, _c2, _d2, _e2;
697
+ return {
698
+ col: r.value,
699
+ value: (_a2 = r.option) == null ? void 0 : _a2.uniqueValue,
700
+ operator: (_b2 = r.option) == null ? void 0 : _b2.operator,
701
+ rule_type: ((_c2 = r.option) == null ? void 0 : _c2.ruleType) ?? "cond",
702
+ is_not: ((_d2 = r.option) == null ? void 0 : _d2.isNot) ?? false,
703
+ is_case_sensitive: ((_e2 = r.option) == null ? void 0 : _e2.caseSensitive) ?? true
704
+ };
705
+ }),
706
+ is_not: false
707
+ };
708
+ };
709
+ const getColumnFilterRuleFromCombinedFilterRule = (combinedFilterRule, valueCols) => {
710
+ const filterRules = (combinedFilterRule == null ? void 0 : combinedFilterRule.rules) ?? [];
711
+ const columnFilterRules = [];
712
+ _.forEach(filterRules, (rule) => {
713
+ const valueCol = valueCols == null ? void 0 : valueCols.find((valueCol2) => (rule == null ? void 0 : rule.col) === (valueCol2 == null ? void 0 : valueCol2.label));
714
+ if (!valueCol) {
715
+ columnFilterRules.push(rule);
716
+ }
717
+ });
718
+ return {
719
+ ...combinedFilterRule,
720
+ rules: columnFilterRules
721
+ };
722
+ };
723
+ var ProjectFractionEnum = /* @__PURE__ */ ((ProjectFractionEnum2) => {
724
+ ProjectFractionEnum2["FRACTION_OF_COL_TOTAL"] = "FRACTION_OF_COL_TOTAL";
725
+ ProjectFractionEnum2["FRACTION_OF_ROW_TOTAL"] = "FRACTION_OF_ROW_TOTAL";
726
+ ProjectFractionEnum2["FRACTION_OF_GRAND_TOTAL"] = "FRACTION_OF_GRAND_TOTAL";
727
+ ProjectFractionEnum2["NONE"] = "null";
728
+ ProjectFractionEnum2["TOTAL_OF_FORMULA"] = "TOTAL_OF_FORMULA";
729
+ ProjectFractionEnum2["TOTAL_OF_AGGREGATE"] = "TOTAL_OF_AGGREGATE";
730
+ return ProjectFractionEnum2;
731
+ })(ProjectFractionEnum || {});
732
+ const getValuesForSpecialOperators = (op) => {
733
+ switch (op) {
734
+ case "not_equal":
735
+ return { operator: "equal", isNot: true };
736
+ case "not_contains":
737
+ return { operator: "contains", isNot: true };
738
+ case "is_empty":
739
+ return { value: "", operator: "equal", isNot: false };
740
+ case "is_not_empty":
741
+ return { value: "", operator: "equal", isNot: true };
742
+ case "is_null":
743
+ return { value: null, operator: "equal", isNot: false };
744
+ case "is_not_null":
745
+ return { value: null, operator: "equal", isNot: true };
746
+ default:
747
+ return {};
748
+ }
749
+ };
750
+ const replaceFilterColumn = (props) => {
751
+ const { fr, column } = props;
752
+ const updatedFr = _.map(fr, (f) => {
753
+ let newFr = { ...f, label: column == null ? void 0 : column.label, value: column == null ? void 0 : column.value };
754
+ if (newFr.option.uniqueValues) {
755
+ _.map(newFr.option.uniqueValues, (u) => {
756
+ u.label = column == null ? void 0 : column.label;
757
+ u.value = column == null ? void 0 : column.value;
758
+ });
759
+ }
760
+ return newFr;
761
+ });
762
+ return updatedFr;
763
+ };
764
+ const getParentTableVariableType = (childId, variables) => {
765
+ const parentTableVariable = _.find(variables, (v) => v.name === childId);
766
+ return parentTableVariable;
767
+ };
768
+ const findParentIsMetricSeries = (childId, variables) => {
769
+ var _a, _b;
770
+ const parentTableVariable = getParentTableVariableType(childId, variables);
771
+ if (((_a = parentTableVariable == null ? void 0 : parentTableVariable.transforms[0]) == null ? void 0 : _a.type) === "MetricSeries") {
772
+ return true;
773
+ } else if (parentTableVariable == null ? void 0 : parentTableVariable.transforms[0]) {
774
+ return findParentIsMetricSeries((_b = parentTableVariable == null ? void 0 : parentTableVariable.transforms[0]) == null ? void 0 : _b.table, variables);
775
+ }
776
+ return false;
777
+ };
778
+ const ShowAsToProjectFractionMapper = {
779
+ [ShowAsEnum.ROW]: ProjectFractionEnum.FRACTION_OF_ROW_TOTAL,
780
+ [ShowAsEnum.COLUMN]: ProjectFractionEnum.FRACTION_OF_COL_TOTAL,
781
+ [ShowAsEnum.GRAND_TOTAL]: ProjectFractionEnum.FRACTION_OF_GRAND_TOTAL,
782
+ [CustomCalculationShowAsEnum.NONE]: ProjectFractionEnum.FRACTION_OF_ROW_TOTAL,
783
+ [CustomCalculationShowAsEnum.FORMULA]: ProjectFractionEnum.TOTAL_OF_FORMULA,
784
+ [CustomCalculationShowAsEnum.AGGREGATE]: ProjectFractionEnum.TOTAL_OF_AGGREGATE
785
+ };
786
+ const getDrilldownFiltersMap = (props) => {
787
+ const { filtersToBeApplied, columnSelectOptions } = props;
788
+ let filterMap = {};
789
+ const filterGroup = _.groupBy(filtersToBeApplied, "field");
790
+ _.forEach(filterGroup, (fg) => {
791
+ let uniqueValues = [];
792
+ const col = columnSelectOptions == null ? void 0 : columnSelectOptions.find(
793
+ (c) => c.value === fg[0].field || c.value === `${fg[0].field}_group` || c.label === fg[0].field
794
+ );
795
+ let ruleType = "cond";
796
+ _.forEach(
797
+ fg,
798
+ (ftba) => {
799
+ var _a, _b;
800
+ if (ftba.operator) {
801
+ let uniqueValuesForNegationOperator, uniqueValuesForOperator;
802
+ if (ftba.operator.includes("not")) {
803
+ uniqueValuesForNegationOperator = getValuesForSpecialOperators(ftba.operator);
804
+ uniqueValuesForOperator = [
805
+ {
806
+ label: col == null ? void 0 : col.label,
807
+ value: col == null ? void 0 : col.value,
808
+ option: {
809
+ uniqueValue: ftba.key,
810
+ ruleType: "cond",
811
+ operator: uniqueValuesForNegationOperator.operator,
812
+ isNot: uniqueValuesForNegationOperator.isNot
813
+ }
814
+ }
815
+ ];
816
+ } else {
817
+ uniqueValuesForOperator = [
818
+ {
819
+ label: col == null ? void 0 : col.label,
820
+ value: col == null ? void 0 : col.value,
821
+ option: {
822
+ uniqueValue: ftba.key,
823
+ ruleType: "cond",
824
+ operator: ftba.operator
825
+ }
826
+ }
827
+ ];
828
+ }
829
+ uniqueValues.push(...uniqueValuesForOperator);
830
+ ruleType = "and_cond";
831
+ } else if (ftba.type === "date") {
832
+ const uniqueValuesForDate = [
833
+ {
834
+ label: col == null ? void 0 : col.label,
835
+ value: (_a = col == null ? void 0 : col.value) == null ? void 0 : _a.replace("_group", ""),
836
+ option: {
837
+ uniqueValue: ftba.startDate,
838
+ ruleType: "cond",
839
+ operator: "greater_equal"
840
+ }
841
+ },
842
+ {
843
+ label: col == null ? void 0 : col.label,
844
+ value: (_b = col == null ? void 0 : col.value) == null ? void 0 : _b.replace("_group", ""),
845
+ option: {
846
+ uniqueValue: ftba.endDate,
847
+ ruleType: "cond",
848
+ operator: "less_equal"
849
+ }
850
+ }
851
+ ];
852
+ uniqueValues.push(...uniqueValuesForDate);
853
+ ruleType = "or_cond";
854
+ } else {
855
+ const uniqueValuesForSelection = [
856
+ {
857
+ label: (col == null ? void 0 : col.label) || "",
858
+ value: col == null ? void 0 : col.value,
859
+ option: { uniqueValue: ftba.key, ruleType: "cond", operator: "equal" }
860
+ }
861
+ ];
862
+ uniqueValues.push(...uniqueValuesForSelection);
863
+ }
864
+ }
865
+ );
866
+ const fiterSelectOption = {
867
+ label: (col == null ? void 0 : col.label) || "",
868
+ value: col == null ? void 0 : col.value,
869
+ option: {
870
+ uniqueValues,
871
+ ruleType,
872
+ uniqueValueCount: col == null ? void 0 : col.option.uniqueCount,
873
+ type: col == null ? void 0 : col.option.type
874
+ }
875
+ };
876
+ filterMap = {
877
+ ...filterMap,
878
+ [col == null ? void 0 : col.value]: fiterSelectOption
879
+ };
880
+ });
881
+ return filterMap;
882
+ };
883
+ const getFiltersToBeAppliedOnDrilldown = (props) => {
884
+ const { rowGroups, groupKeys } = props;
885
+ const filtersToBeApplied = [];
886
+ groupKeys == null ? void 0 : groupKeys.forEach((key, index2) => filtersToBeApplied.push({ field: rowGroups[index2], key }));
887
+ return filtersToBeApplied;
888
+ };
889
+ const getMetricFilterRule = (inputs) => {
890
+ const isInputsArray = Array.isArray(inputs);
891
+ const input = isInputsArray ? inputs[0] : inputs;
892
+ return (input == null ? void 0 : input["rule_pivot"]) ?? defaultFilterRule;
893
+ };
894
+ const getColumnSettingsToSelectOptions = (columnSettings) => {
895
+ return _.chain(columnSettings).filter((c) => !c.field.includes("__bc_") && !c.aggFunc).map((c) => {
896
+ return {
897
+ label: c.headerName,
898
+ value: c.field,
899
+ option: {
900
+ type: c.type,
901
+ uniqueCount: c.unique_count,
902
+ fieldLabel: c.headerName,
903
+ currency: c == null ? void 0 : c.currency,
904
+ precision: c == null ? void 0 : c.precision,
905
+ dateFormat: c == null ? void 0 : c.dateFormat,
906
+ isCurrency: c == null ? void 0 : c.isCurrency
907
+ }
908
+ };
909
+ }).value();
910
+ };
911
+ const defaultFilterRule = {
912
+ is_not: false,
913
+ rule_type: "and_cond",
914
+ rules: []
915
+ };
916
+ const getUpdatedDefinitionCustomModel = (props) => {
917
+ var _a, _b, _c, _d, _e;
918
+ const {
919
+ metricDefinitionModel,
920
+ parentDefinitionModel,
921
+ metricCustomModel,
922
+ parentCustomModel,
923
+ removeSort
924
+ } = props;
925
+ const parentTableVariable = parentCustomModel.variable;
926
+ const metricNewColumns = _.filter(metricDefinitionModel.variables ?? [], (v) => {
927
+ if (!v.transforms || !v.transforms[0]) {
928
+ return false;
929
+ }
930
+ if (removeSort) {
931
+ return findParentIsMetricSeries(
932
+ v.transforms[0].table,
933
+ metricDefinitionModel.variables ?? []
934
+ ) && v.transforms[0].type !== "Sort";
935
+ }
936
+ return findParentIsMetricSeries(
937
+ v.transforms[0].table,
938
+ metricDefinitionModel.variables ?? []
939
+ );
940
+ });
941
+ const definitionVariables = metricDefinitionModel.variables ?? [];
942
+ const analysisVariable = _.find(
943
+ definitionVariables,
944
+ (v) => !!_.find(v.transforms, (t) => t.type === "MetricSeries")
945
+ );
946
+ metricDefinitionModel.imports = _.uniqBy(
947
+ [...parentDefinitionModel.imports ?? [], ...metricDefinitionModel.imports ?? []],
948
+ "to"
949
+ );
950
+ const parentDefinitionAliases = parentDefinitionModel.aliases ?? {};
951
+ const parentTableVariableAlias = parentTableVariable ? parentDefinitionAliases[parentTableVariable] : {};
952
+ const metricDefinitionAliases = {
953
+ ...metricDefinitionModel.aliases,
954
+ ...parentDefinitionAliases
955
+ };
956
+ for (const [tableId] of Object.entries(metricDefinitionAliases)) {
957
+ if (!parentDefinitionAliases[tableId]) {
958
+ const metricTableAlias = metricDefinitionAliases[tableId];
959
+ for (const [columnName, columnId] of Object.entries(metricTableAlias)) {
960
+ const pColName = _.findKey(parentTableVariableAlias, (pColId) => pColId === columnId);
961
+ if (pColName && pColName !== columnName) {
962
+ delete metricTableAlias[columnName];
963
+ metricTableAlias[pColName] = parentTableVariableAlias[pColName];
964
+ }
965
+ }
966
+ }
967
+ }
968
+ metricDefinitionModel.aliases = metricDefinitionAliases;
969
+ const variables = _.cloneDeep(parentDefinitionModel.variables ?? []);
970
+ metricDefinitionModel.variables = definitionVariables.filter(
971
+ (v) => v.name === (analysisVariable == null ? void 0 : analysisVariable.name)
972
+ );
973
+ const previousVariables = metricDefinitionModel.variables;
974
+ metricDefinitionModel.variables = [...variables];
975
+ const variableNames = (_a = metricDefinitionModel.variables) == null ? void 0 : _a.map((v) => v == null ? void 0 : v.name);
976
+ metricDefinitionModel.variables.push(
977
+ ..._.filter(previousVariables, (v) => variableNames == null ? void 0 : variableNames.includes(v.name))
978
+ );
979
+ const filterVariable = _.find(
980
+ definitionVariables,
981
+ (v) => {
982
+ var _a2;
983
+ return (_a2 = v.transforms) == null ? void 0 : _a2.some((t) => t.type === "RuleFilter" && t.rule === "${rule_pivot}");
984
+ }
985
+ );
986
+ if (filterVariable && parentTableVariable) {
987
+ filterVariable.transforms[0].table = parentTableVariable;
988
+ metricDefinitionModel.variables.push(filterVariable);
989
+ }
990
+ if (analysisVariable && parentTableVariable) {
991
+ analysisVariable.transforms[0].table = parentTableVariable;
992
+ analysisVariable.transforms[0].row_group_by = "${rowGroupByInput}";
993
+ analysisVariable.transforms[0].col_group_by = "${columnGroupByInput}";
994
+ const rowGroups = ((_b = metricCustomModel == null ? void 0 : metricCustomModel.gridColumnState) == null ? void 0 : _b.rowGroupCols) ?? [];
995
+ const valueCols = ((_c = metricCustomModel == null ? void 0 : metricCustomModel.gridColumnState) == null ? void 0 : _c.valueCols) ?? [];
996
+ const showAsList = _.chain(valueCols).filter((vc) => !!vc.showAs).map((vc) => vc == null ? void 0 : vc.showAs).value();
997
+ analysisVariable.transforms[0].require_totals = !_.isEmpty(rowGroups) || !_.isEmpty(showAsList) && _.some(showAsList, (showAs) => showAs !== "default");
998
+ if (filterVariable) {
999
+ analysisVariable.transforms[0].table = filterVariable.name;
1000
+ if (metricDefinitionModel.aliases && parentTableVariable) {
1001
+ metricDefinitionModel.aliases[parentTableVariable] = {
1002
+ ...metricDefinitionModel.aliases[parentTableVariable]
1003
+ };
1004
+ }
1005
+ }
1006
+ metricDefinitionModel.variables.push(analysisVariable);
1007
+ metricCustomModel.variable = analysisVariable.name;
1008
+ }
1009
+ metricCustomModel.inputs = { ...parentCustomModel.inputs, ...metricCustomModel.inputs };
1010
+ if (!_.isEmpty(metricNewColumns)) {
1011
+ metricDefinitionModel.variables.push(...metricNewColumns);
1012
+ metricCustomModel.variable = metricNewColumns[metricNewColumns.length - 1].name;
1013
+ }
1014
+ if (metricCustomModel.parentTableColumnSettings && ((_d = parentCustomModel.uiSettings) == null ? void 0 : _d.columnSettings)) {
1015
+ metricCustomModel.parentTableColumnSettings.splice(
1016
+ 0,
1017
+ metricCustomModel.parentTableColumnSettings.length,
1018
+ ...parentCustomModel.uiSettings.columnSettings
1019
+ );
1020
+ }
1021
+ if (((_e = metricCustomModel.inputs) == null ? void 0 : _e["view_worksheet"]) && metricCustomModel.parentTableColumnSettings) {
1022
+ _.forEach(metricCustomModel.parentTableColumnSettings, (c) => {
1023
+ var _a2;
1024
+ if ((_a2 = metricCustomModel.inputs) == null ? void 0 : _a2.view_worksheet) {
1025
+ metricCustomModel.inputs.view_worksheet = _.uniq([
1026
+ ...metricCustomModel.inputs.view_worksheet,
1027
+ c.field
1028
+ ]);
1029
+ }
1030
+ });
1031
+ }
1032
+ if (parentTableVariable) {
1033
+ metricCustomModel.parentTableVariable = parentTableVariable;
1034
+ }
1035
+ return { definitionModel: metricDefinitionModel, customModel: metricCustomModel };
1036
+ };
1037
+ class MergeFilterService {
1038
+ getColumnSettingsForCommonFilters(cf) {
1039
+ return [
1040
+ {
1041
+ label: cf.name,
1042
+ value: cf.column.name,
1043
+ option: {
1044
+ headerName: cf.name,
1045
+ field: cf.column.name,
1046
+ //@ts-ignore
1047
+ type: cf.column.data_type,
1048
+ datasetName: cf.datasetName,
1049
+ datasetId: cf.datasetId
1050
+ }
1051
+ }
1052
+ ];
1053
+ }
1054
+ mergeCommonFilters(props) {
1055
+ const { commonFilters, rule, id, condition } = props;
1056
+ let replacedFr = [];
1057
+ if (_.isEmpty(commonFilters)) return { defaultType: condition, rules: rule };
1058
+ _.forEach(commonFilters, (f) => {
1059
+ const columnSettingsSelectOption = this.getColumnSettingsForCommonFilters(f);
1060
+ const appliedOnLine = _.find(f == null ? void 0 : f.appliedOnBlocks, (l) => l.blockId === id);
1061
+ if (appliedOnLine && appliedOnLine.applied) {
1062
+ const commonRule = f.rule;
1063
+ const fr = filterToSelectOptionType(commonRule, columnSettingsSelectOption);
1064
+ const columnSetting = _.find(
1065
+ appliedOnLine.columnSettings,
1066
+ (c) => c.value === appliedOnLine.column
1067
+ );
1068
+ if (columnSetting) {
1069
+ replacedFr.push(replaceFilterColumn({ fr: fr.rules, column: columnSetting }));
1070
+ }
1071
+ }
1072
+ });
1073
+ const mergedFr = _.unionBy(replacedFr.flat(), rule, "value");
1074
+ return { defaultType: condition, rules: mergedFr };
1075
+ }
1076
+ getApplicablePromotedFilters(props) {
1077
+ const { id, datasetIds, promotedFilters } = props;
1078
+ return _.filter(promotedFilters, (pf) => {
1079
+ const appliedBlock = _.find(pf.appliedOnBlocks, (aob) => aob.blockId === id);
1080
+ const isApplied = (appliedBlock == null ? void 0 : appliedBlock.applied) ?? false;
1081
+ return isApplied && _.includes(datasetIds, pf.datasetId);
1082
+ });
1083
+ }
1084
+ getUnion(promotedFilters, metricFilters, columnSettings) {
1085
+ const pfSelectOptions = _.map(promotedFilters, (pf) => {
1086
+ var _a;
1087
+ return ((_a = filterToSelectOptionType(pf.rule, getColumnSettingsToSelectOptions(pf.blockColumnSettings))) == null ? void 0 : _a.rules) ?? [];
1088
+ }).flat();
1089
+ const mFilterModel = filterToSelectOptionType(
1090
+ metricFilters,
1091
+ getColumnSettingsToSelectOptions(columnSettings)
1092
+ );
1093
+ if (_.isEmpty(mFilterModel)) {
1094
+ return { defaultType: "and_cond", rules: pfSelectOptions };
1095
+ }
1096
+ const ruleType = (mFilterModel == null ? void 0 : mFilterModel.defaultType) ?? "and_cond";
1097
+ const mSelectOptions = (mFilterModel == null ? void 0 : mFilterModel.rules) ?? [];
1098
+ const union = _.unionBy(pfSelectOptions, mSelectOptions, "value");
1099
+ return { defaultType: ruleType, rules: union };
1100
+ }
1101
+ /** merges promoted filter to metric filter */
1102
+ mergePromotedFilters(props) {
1103
+ const { metricFilters, columnSettings, promotedFilters } = props;
1104
+ const applicablePromotedFilters = this.getApplicablePromotedFilters({
1105
+ id: props.id,
1106
+ datasetIds: props.datasetIds,
1107
+ promotedFilters
1108
+ });
1109
+ return this.getUnion(applicablePromotedFilters, metricFilters, columnSettings);
1110
+ }
1111
+ mergeFilters(props) {
1112
+ const { commonFilters } = props;
1113
+ const filtersWithPromoted = this.mergePromotedFilters(props);
1114
+ const filtersWithCommon = this.mergeCommonFilters({
1115
+ commonFilters,
1116
+ rule: filtersWithPromoted.rules,
1117
+ id: props.id,
1118
+ condition: (filtersWithPromoted == null ? void 0 : filtersWithPromoted.defaultType) ?? "and_cond"
1119
+ });
1120
+ return getSelectOptionTypeToFilter(filtersWithCommon);
1121
+ }
1122
+ }
1123
+ const updatePromotedFiltersAndDateRangeToMetadataAndInputs = (props) => {
1124
+ var _a;
1125
+ const { blockId, metadata, promotedFilters, inputs, commonFilters } = props;
1126
+ const updateDateRange = (updateProps) => {
1127
+ var _a2;
1128
+ const { blockId: blockId2, blockDateRange, dateRangeModel } = updateProps;
1129
+ const { dateRange, appliedOnBlocks } = dateRangeModel;
1130
+ const dateRangeApplicableOnBlockIds = (_a2 = appliedOnBlocks == null ? void 0 : appliedOnBlocks.filter((apb) => apb.applied)) == null ? void 0 : _a2.map((apb) => apb.blockId);
1131
+ if (dateRangeApplicableOnBlockIds == null ? void 0 : dateRangeApplicableOnBlockIds.includes(blockId2)) {
1132
+ return dateRange;
1133
+ } else {
1134
+ return blockDateRange;
1135
+ }
1136
+ };
1137
+ const updateCurrencyFilter = (updateProps) => {
1138
+ const { blockId: blockId2, blockCurrencyFilter, currencyModel } = updateProps;
1139
+ const { currency, appliedOnBlocks } = currencyModel;
1140
+ const currencyFilterApplicableOnBlockIds = _.chain(appliedOnBlocks).filter((apb) => apb.applied).map((apb) => apb.blockId).value();
1141
+ if (currencyFilterApplicableOnBlockIds == null ? void 0 : currencyFilterApplicableOnBlockIds.includes(blockId2)) {
1142
+ return currency;
1143
+ } else {
1144
+ return blockCurrencyFilter;
1145
+ }
1146
+ };
1147
+ const metricColumnFilter = getColumnFilterRuleFromCombinedFilterRule(
1148
+ metadata.filterModel,
1149
+ metadata.valueCols || []
1150
+ );
1151
+ const updatedFilterRule = new MergeFilterService().mergeFilters({
1152
+ id: blockId,
1153
+ metricFilters: metricColumnFilter,
1154
+ columnSettings: metadata.columnSettings,
1155
+ promotedFilters,
1156
+ commonFilters: commonFilters || [],
1157
+ datasetIds: [metadata.datasetId || ""]
1158
+ });
1159
+ const updatedDateRange = updateDateRange({
1160
+ blockId,
1161
+ blockDateRange: metadata.dateRange || { time_period: "past_quarter" },
1162
+ dateRangeModel: props.dateRangeModel
1163
+ });
1164
+ const updateCurrencyFilterValue = updateCurrencyFilter({
1165
+ blockId,
1166
+ blockCurrencyFilter: metadata.currency || "",
1167
+ currencyModel: props.currencyModel
1168
+ });
1169
+ const updatedInputs = {
1170
+ ...inputs,
1171
+ ["filterOnAggregates"]: _.get(
1172
+ inputs,
1173
+ "filterOnAggregates",
1174
+ defaultFilterRule
1175
+ ),
1176
+ ["rule_pivot"]: updatedFilterRule,
1177
+ date_range: updatedDateRange,
1178
+ to_currency: updateCurrencyFilterValue,
1179
+ showDimensionMappingValues: metadata.showDimensionMappingValues ?? false,
1180
+ showBinSortOrderValues: ((_a = metadata == null ? void 0 : metadata.inputs) == null ? void 0 : _a.showBinSortOrderValues) ?? false
1181
+ };
1182
+ const updatedMetadata = {
1183
+ ...metadata,
1184
+ filterModel: updatedFilterRule,
1185
+ dateRange: updatedDateRange,
1186
+ inputs: updatedInputs
1187
+ };
1188
+ return { updatedInputs, updatedMetadata };
1189
+ };
1190
+ const getRowsToGroupBy = (props) => {
1191
+ const { pivotColumns, timeBin, rowGroupColumns } = props;
1192
+ const rowsToGroupBy = [];
1193
+ if (!_.isEmpty(pivotColumns)) {
1194
+ if (timeBin) {
1195
+ rowsToGroupBy.push([...rowGroupColumns]);
1196
+ for (let i = 0; i < pivotColumns.length; i++) {
1197
+ const pcols = pivotColumns;
1198
+ rowsToGroupBy.push([...pcols.slice(0, i + 1), ...rowGroupColumns]);
1199
+ }
1200
+ } else {
1201
+ for (let i = 0; i < pivotColumns.length; i++) {
1202
+ const pcols = pivotColumns;
1203
+ rowsToGroupBy.push([...pcols.slice(0, i + 1), ...rowGroupColumns]);
1204
+ }
1205
+ }
1206
+ } else {
1207
+ rowsToGroupBy.push([...pivotColumns, ...rowGroupColumns]);
1208
+ }
1209
+ return rowsToGroupBy;
1210
+ };
1211
+ const getInputsArray = (props) => {
1212
+ const {
1213
+ pivotColumns,
1214
+ timeBin,
1215
+ rowsToGroupBy,
1216
+ inputs,
1217
+ dateColumn,
1218
+ valueCols,
1219
+ hierarchy,
1220
+ rowGroupCols,
1221
+ compareTrends,
1222
+ showDimensionMappingValues = false,
1223
+ showBinSortOrderValues = false
1224
+ } = props;
1225
+ let inputsArray = [];
1226
+ const inputsCompareTrendsIndices = [];
1227
+ const getViewsInput = (index2) => {
1228
+ let viewInputs = inputs == null ? void 0 : inputs.viewInputs;
1229
+ if (!viewInputs) return void 0;
1230
+ const valueColsLabel = _.map(valueCols, (vc) => vc.label);
1231
+ viewInputs = _.filter(
1232
+ viewInputs,
1233
+ (vi) => valueColsLabel.includes(vi) || vi.includes("__bc_")
1234
+ );
1235
+ if (_.isEmpty(rowGroupCols)) {
1236
+ viewInputs = _.filter(viewInputs, (vi) => !vi.includes("__bc_"));
1237
+ }
1238
+ if (timeBin) {
1239
+ viewInputs = _.uniq([...viewInputs, dateColumn, `${dateColumn}_group`]);
1240
+ }
1241
+ if (index2 !== void 0) {
1242
+ viewInputs = _.uniq([...viewInputs, ...rowsToGroupBy[index2]]);
1243
+ } else {
1244
+ if (!_.isEmpty(rowGroupCols)) {
1245
+ let row = rowsToGroupBy[0];
1246
+ if (!_.isEmpty(hierarchy) && hierarchy) {
1247
+ const rowLabelName = _.get(rowsToGroupBy, "0.0.0");
1248
+ row = [
1249
+ rowLabelName,
1250
+ `${rowLabelName}_level_number`,
1251
+ `${rowLabelName}_${hierarchy.parentColId}`,
1252
+ `${rowLabelName}_${hierarchy.nodeColName}`
1253
+ ];
1254
+ }
1255
+ viewInputs = _.uniq([...viewInputs, ...row]);
1256
+ }
1257
+ }
1258
+ return viewInputs;
1259
+ };
1260
+ const projectAsInput = _.reduce(
1261
+ valueCols,
1262
+ (acc, curr) => {
1263
+ if (curr.showAs && curr.showAs !== ShowAsEnum.DEFAULT && curr.label) {
1264
+ acc[curr.label] = ShowAsToProjectFractionMapper[curr.showAs];
1265
+ }
1266
+ return acc;
1267
+ },
1268
+ {}
1269
+ );
1270
+ const sortPivotInputsKey = Object.keys(inputs).find(
1271
+ (key) => key.startsWith("sortPivotInputs")
1272
+ );
1273
+ const sortPivotInputsValue = sortPivotInputsKey ? { ...inputs[sortPivotInputsKey] } : void 0;
1274
+ if (!_.isEmpty(pivotColumns)) {
1275
+ const pc = timeBin ? [dateColumn, ...pivotColumns] : pivotColumns;
1276
+ pc == null ? void 0 : pc.forEach((col, index2) => {
1277
+ const groupByInput = rowsToGroupBy[index2];
1278
+ const columnGroupByInput = _.filter(groupByInput, (r) => pc.includes(r));
1279
+ const rowGroupByInput = _.filter(groupByInput, (r) => !pc.includes(r));
1280
+ if (sortPivotInputsValue) {
1281
+ sortPivotInputsValue.pivotColumns = rowsToGroupBy[index2];
1282
+ }
1283
+ inputsArray.push({
1284
+ ...inputs,
1285
+ groupByInput: rowsToGroupBy[index2],
1286
+ dateColumnInput: dateColumn,
1287
+ binByInput: timeBin,
1288
+ viewInputs: getViewsInput(index2),
1289
+ columnGroupByInput,
1290
+ rowGroupByInput,
1291
+ projectAsInput,
1292
+ showDimensionMappingValues,
1293
+ showBinSortOrderValues,
1294
+ ...sortPivotInputsKey ? { [sortPivotInputsKey]: sortPivotInputsValue } : {}
1295
+ });
1296
+ });
1297
+ } else {
1298
+ if (compareTrends && compareTrends.length > 0) {
1299
+ if (sortPivotInputsValue) {
1300
+ sortPivotInputsValue.pivotColumns = rowsToGroupBy[0];
1301
+ }
1302
+ inputsArray = _.map(compareTrends, (ct, index2) => {
1303
+ inputsCompareTrendsIndices.push({ id: ct.id, index: index2 });
1304
+ return {
1305
+ ...inputs,
1306
+ date_range: { ...ct.dateRange },
1307
+ groupByInput: rowsToGroupBy[0],
1308
+ dateColumnInput: dateColumn,
1309
+ binByInput: timeBin,
1310
+ viewInputs: getViewsInput(),
1311
+ rowGroupByInput: rowsToGroupBy[0],
1312
+ columnGroupByInput: [],
1313
+ projectAsInput,
1314
+ showDimensionMappingValues,
1315
+ showBinSortOrderValues,
1316
+ ...sortPivotInputsKey ? { [sortPivotInputsKey]: sortPivotInputsValue } : {}
1317
+ };
1318
+ });
1319
+ } else {
1320
+ if (sortPivotInputsValue) {
1321
+ sortPivotInputsValue.pivotColumns = rowsToGroupBy[0];
1322
+ }
1323
+ inputsArray = [
1324
+ {
1325
+ ...inputs,
1326
+ groupByInput: rowsToGroupBy[0],
1327
+ dateColumnInput: dateColumn,
1328
+ binByInput: timeBin,
1329
+ viewInputs: getViewsInput(),
1330
+ rowGroupByInput: rowsToGroupBy[0],
1331
+ columnGroupByInput: [],
1332
+ projectAsInput,
1333
+ showDimensionMappingValues,
1334
+ showBinSortOrderValues,
1335
+ ...sortPivotInputsKey ? { [sortPivotInputsKey]: sortPivotInputsValue } : {}
1336
+ }
1337
+ ];
1338
+ }
1339
+ }
1340
+ return { inputs: inputsArray, inputsCompareTrendsIndices };
1341
+ };
1342
+ const mergeDrilldownFiltersToMetricFilters = (props) => {
1343
+ const { metricFilterRule, filtersToBeApplied, columnSettings } = props;
1344
+ const columnSelectOptions = getColumnSettingsToSelectOptions(columnSettings);
1345
+ const metricFilterRuleSelectOptions = filterToSelectOptionType(
1346
+ metricFilterRule,
1347
+ columnSelectOptions
1348
+ );
1349
+ const drilldownFilterMap = getDrilldownFiltersMap({
1350
+ filtersToBeApplied,
1351
+ columnSelectOptions
1352
+ });
1353
+ const mergedRule = _.unionBy(
1354
+ Object.values(drilldownFilterMap),
1355
+ metricFilterRuleSelectOptions.rules,
1356
+ "value"
1357
+ );
1358
+ const filterRule = getSelectOptionTypeToFilter({
1359
+ defaultType: "and_cond",
1360
+ rules: mergedRule
1361
+ });
1362
+ return filterRule;
1363
+ };
1364
+ const getMetricDefinition = (props) => {
1365
+ var _a, _b;
1366
+ const {
1367
+ sheetId,
1368
+ metadata,
1369
+ groupKeys,
1370
+ promotedFiltersStoreValue,
1371
+ promotedFilters,
1372
+ dateRangeModel,
1373
+ currencyModel,
1374
+ commonFilters
1375
+ } = props;
1376
+ const {
1377
+ parentTableVariable,
1378
+ valueCols,
1379
+ rowGroupCols,
1380
+ pivotCols,
1381
+ timeBin,
1382
+ dateColumn,
1383
+ columnSettings
1384
+ } = metadata;
1385
+ let inputs = metadata == null ? void 0 : metadata.inputs;
1386
+ const { updatedInputs } = updatePromotedFiltersAndDateRangeToMetadataAndInputs({
1387
+ blockId: sheetId,
1388
+ metadata,
1389
+ promotedFilters,
1390
+ inputs,
1391
+ dateRangeModel,
1392
+ currencyModel,
1393
+ commonFilters
1394
+ });
1395
+ let rowsToGroupBy = getRowsToGroupBy({
1396
+ pivotColumns: pivotCols || [],
1397
+ rowGroupColumns: (rowGroupCols || []).slice(0, groupKeys.length + 1),
1398
+ timeBin: timeBin || ""
1399
+ });
1400
+ let { inputs: inputsArray } = getInputsArray({
1401
+ inputs: updatedInputs,
1402
+ dateColumn: dateColumn || "",
1403
+ timeBin: timeBin || "",
1404
+ rowsToGroupBy,
1405
+ pivotColumns: pivotCols || [],
1406
+ valueCols: valueCols || [],
1407
+ rowGroupCols,
1408
+ compareTrends: metadata.compareTrends,
1409
+ showDimensionMappingValues: ((_a = metadata == null ? void 0 : metadata.inputs) == null ? void 0 : _a.showDimensionMappingValues) ?? false,
1410
+ showBinSortOrderValues: ((_b = metadata == null ? void 0 : metadata.inputs) == null ? void 0 : _b.showBinSortOrderValues) ?? false
1411
+ });
1412
+ if (!_.isEmpty(groupKeys)) {
1413
+ const mergedFilterRule = mergeDrilldownFiltersToMetricFilters({
1414
+ metricFilterRule: getMetricFilterRule(inputsArray),
1415
+ filtersToBeApplied: getFiltersToBeAppliedOnDrilldown({
1416
+ rowGroups: metadata == null ? void 0 : metadata.rowGroupCols,
1417
+ groupKeys
1418
+ }),
1419
+ columnSettings
1420
+ });
1421
+ inputsArray = inputsArray == null ? void 0 : inputsArray.map((ia) => {
1422
+ return { ...ia, ["rule_pivot"]: mergedFilterRule };
1423
+ });
1424
+ }
1425
+ return {
1426
+ inputs: inputsArray,
1427
+ describe: parentTableVariable
1428
+ };
1429
+ };
1430
+ const getSelectedMetricsParentIds = (selectedItems) => {
1431
+ return _.chain(selectedItems).map((s) => {
1432
+ var _a, _b;
1433
+ return (_b = (_a = s == null ? void 0 : s.sheet) == null ? void 0 : _a.customFields) == null ? void 0 : _b.parentTableId;
1434
+ }).uniq().value();
1435
+ };
1436
+ const defaultDashboardDateRangeModel = {
1437
+ //@ts-ignore
1438
+ dateRange: {},
1439
+ appliedOnBlocks: []
1440
+ };
1441
+ const defaultCurrencyModel = {
1442
+ currency: "USD",
1443
+ appliedOnBlocks: []
1444
+ };
1445
+ const getGroupByDefinition = ({
1446
+ tableId,
1447
+ tableName,
1448
+ groupKeys,
1449
+ rowGroupCols,
1450
+ columnSettings,
1451
+ filterRules,
1452
+ sortValue,
1453
+ metricSeries
1454
+ }) => {
1455
+ let filtersToBeApplied = getFiltersToBeAppliedOnDrilldown({
1456
+ groupKeys,
1457
+ rowGroups: rowGroupCols
1458
+ });
1459
+ const columnSelectOptions = getColumnSettingsToSelectOptions(columnSettings);
1460
+ const metricFilterRuleSelectOptions = filterToSelectOptionType(filterRules, columnSelectOptions);
1461
+ const crossFilterMap = getDrilldownFiltersMap({
1462
+ filtersToBeApplied,
1463
+ columnSelectOptions
1464
+ });
1465
+ const mergedRule = _.unionBy(
1466
+ Object.values(crossFilterMap),
1467
+ metricFilterRuleSelectOptions.rules,
1468
+ "value"
1469
+ );
1470
+ const filterRule = getSelectOptionTypeToFilter({
1471
+ defaultType: "and_cond",
1472
+ rules: mergedRule
1473
+ });
1474
+ return generateDefinitionModel({
1475
+ filters: filterRule,
1476
+ sort: sortValue,
1477
+ metricSeries,
1478
+ tableId,
1479
+ tableName
1480
+ });
1481
+ };
1482
+ const generateDefinitionModel = ({
1483
+ filters,
1484
+ sort,
1485
+ metricSeries,
1486
+ tableId,
1487
+ tableName
1488
+ }) => {
1489
+ const { transformations, targetName } = generateTransformations(
1490
+ tableName,
1491
+ filters,
1492
+ sort,
1493
+ metricSeries
1494
+ );
1495
+ const importConfig = getImportConfig(tableId, tableName);
1496
+ return {
1497
+ targetName,
1498
+ definition: {
1499
+ imports: [importConfig],
1500
+ transformations
1501
+ }
1502
+ };
1503
+ };
1504
+ const sortConfigFromValue = (sortBy) => {
1505
+ const sortValueObj = !_.isNil(sortBy == null ? void 0 : sortBy.sortByField) ? { [sortBy.sortByField.value]: _.get(sortBy, "sortByOrder", "asc").toUpperCase() } : void 0;
1506
+ return sortValueObj;
1507
+ };
1508
+ const getMetricSeries = (props) => {
1509
+ const { pivotCols, rowGroupCols, valueCols } = props;
1510
+ const group_by = [...pivotCols, ...rowGroupCols];
1511
+ const aggregates = _.map(valueCols, (valueCol) => {
1512
+ if (valueCol.type === "formula") {
1513
+ const formula = valueCol.formula;
1514
+ return [valueCol.label, formula];
1515
+ } else if (valueCol.type === "column") {
1516
+ const formula = valueCol.formula;
1517
+ return [valueCol.label, formula];
1518
+ }
1519
+ return [valueCol.label, valueCol.col, valueCol.aggFun];
1520
+ });
1521
+ const metricSeries = {
1522
+ aggregates,
1523
+ group_by,
1524
+ row_group_by: rowGroupCols,
1525
+ col_group_by: pivotCols,
1526
+ type: "TableAggregate",
1527
+ formula_on_aggregates: []
1528
+ };
1529
+ return metricSeries;
1530
+ };
1531
+ const getFilterConfig = (filters, prevName) => ({
1532
+ name: "table_filter",
1533
+ table_name: prevName,
1534
+ filter: filters,
1535
+ type: "CollectionFilter"
1536
+ });
1537
+ const getSortConfig = (sort, prevName) => ({
1538
+ name: "table_sort",
1539
+ table_name: prevName,
1540
+ sort_columns: sort,
1541
+ type: "CollectionSort"
1542
+ });
1543
+ const generateTransformations = (tableName, filters, sort, metricSeries) => {
1544
+ const transformations = [];
1545
+ let prevName = tableName;
1546
+ let targetName = tableName;
1547
+ if (!_.isEmpty(filters)) {
1548
+ const filterConfig = getFilterConfig(filters, prevName);
1549
+ transformations.push(filterConfig);
1550
+ prevName = filterConfig.name;
1551
+ targetName = "table_filter";
1552
+ }
1553
+ if (metricSeries) {
1554
+ const aggregateConfig = {
1555
+ name: "table_aggregate",
1556
+ table_name: prevName,
1557
+ aggregates: metricSeries.aggregates,
1558
+ group_by: metricSeries.group_by,
1559
+ type: "CollectionAggregate"
1560
+ };
1561
+ transformations.push(aggregateConfig);
1562
+ prevName = aggregateConfig.name;
1563
+ targetName = "table_aggregate";
1564
+ }
1565
+ if (metricSeries == null ? void 0 : metricSeries.aggregates) {
1566
+ if (sort !== void 0) {
1567
+ const sortEntries = Object.entries(sort);
1568
+ if (sortEntries.length > 0) {
1569
+ const newSort = {};
1570
+ for (const [sortKey, sortOrder] of sortEntries) {
1571
+ const matchingAggregate = metricSeries.aggregates.find((agg) => agg[1] === sortKey);
1572
+ if (matchingAggregate) {
1573
+ newSort[matchingAggregate[0]] = sortOrder;
1574
+ }
1575
+ }
1576
+ sort = _.isEmpty(newSort) ? {} : newSort;
1577
+ }
1578
+ }
1579
+ }
1580
+ if (!_.isEmpty(sort)) {
1581
+ const sortConfig = getSortConfig(sort, prevName);
1582
+ transformations.push(sortConfig);
1583
+ prevName = sortConfig.name;
1584
+ targetName = "table_sort";
1585
+ }
1586
+ return { transformations, targetName };
1587
+ };
1588
+ const getImportConfig = (id, name) => ({
1589
+ name,
1590
+ table_id: id,
1591
+ type: "TableImport"
1592
+ });
1593
+ const inputTableDefinition = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1594
+ __proto__: null,
1595
+ generateDefinitionModel,
1596
+ getGroupByDefinition,
1597
+ getMetricSeries,
1598
+ sortConfigFromValue
1599
+ }, Symbol.toStringTag, { value: "Module" }));
1600
+ const index$4 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1601
+ __proto__: null,
1602
+ formatDate,
1603
+ getMetricDefinition,
1604
+ inputTableUtils: inputTableDefinition
1605
+ }, Symbol.toStringTag, { value: "Module" }));
1606
+ async function downloadFile(loc, contentType) {
1607
+ if (!loc) return null;
1608
+ const requestData = {
1609
+ key: loc,
1610
+ contentType,
1611
+ method: "GET"
1612
+ // Type assertion to match the expected type
1613
+ };
1614
+ try {
1615
+ const response = await getFileUrlByFileId(requestData);
1616
+ const presignedUrl = response.url;
1617
+ const config = {
1618
+ method: "GET",
1619
+ url: presignedUrl,
1620
+ headers: {
1621
+ "Content-Type": "application/octet-stream"
1622
+ }
1623
+ };
1624
+ const axiosInstance = axios.create();
1625
+ const result = await axiosInstance(config);
1626
+ const fileRead = result.data;
1627
+ return fileRead;
1628
+ } catch (error) {
1629
+ console.error("Error downloading file:", error);
1630
+ throw error;
1631
+ }
1632
+ }
1633
+ const hydrateWorksheet = async (sheet) => {
1634
+ try {
1635
+ if (!sheet) return sheet;
1636
+ const isHydrated = sheet.definitionModel && sheet.customModel;
1637
+ if (isHydrated) {
1638
+ return sheet;
1639
+ }
1640
+ const definitionModelId = sheet.externalDataId;
1641
+ const customModelId = sheet.modelId;
1642
+ let definitionModel = {};
1643
+ let customModel = {};
1644
+ const sheetId = sheet.id;
1645
+ if (definitionModelId && customModelId) {
1646
+ definitionModel = await downloadFile(definitionModelId, "application/json");
1647
+ customModel = await downloadFile(customModelId, "application/json");
1648
+ }
1649
+ if (!definitionModel || !definitionModel[sheetId]) {
1650
+ return sheet;
1651
+ }
1652
+ sheet.definitionModel = definitionModel[sheetId];
1653
+ sheet.customModel = customModel[sheetId];
1654
+ return sheet;
1655
+ } catch (error) {
1656
+ console.error("Error hydrating portal page:", error);
1657
+ throw error;
1658
+ }
1659
+ };
1660
+ const getData$2 = async (metricSheetId, options) => {
1661
+ var _a, _b, _c, _d, _e, _f;
1662
+ const worksheets = await getWorksheets([metricSheetId]);
1663
+ if (_.isEmpty(worksheets)) return {};
1664
+ const selectedWorksheet = worksheets[0];
1665
+ const hydratedSheet = await hydrateWorksheet(selectedWorksheet);
1666
+ if (!hydratedSheet) return {};
1667
+ const selectedMetricsParentIds = getSelectedMetricsParentIds([
1668
+ { sheet: selectedWorksheet }
1669
+ ]);
1670
+ const parentWorksheets = await getWorksheets(selectedMetricsParentIds);
1671
+ const parentSheet = _.find(
1672
+ parentWorksheets,
1673
+ (ps) => ps.id === (hydratedSheet == null ? void 0 : hydratedSheet.customFields.parentTableId)
1674
+ );
1675
+ let definitionModel;
1676
+ let customModel;
1677
+ if (parentSheet) {
1678
+ const hydratedParentSheet = await hydrateWorksheet(parentSheet);
1679
+ if (hydratedParentSheet == null ? void 0 : hydratedParentSheet.definitionModel) {
1680
+ const {
1681
+ definitionModel: parentDefinitionModel,
1682
+ customModel: parentCustomModel
1683
+ } = getUpdatedDefinitionCustomModel({
1684
+ metricDefinitionModel: hydratedSheet.definitionModel,
1685
+ parentDefinitionModel: hydratedParentSheet == null ? void 0 : hydratedParentSheet.definitionModel,
1686
+ parentCustomModel: hydratedParentSheet == null ? void 0 : hydratedParentSheet.customModel,
1687
+ metricCustomModel: hydratedSheet.customModel
1688
+ });
1689
+ definitionModel = parentDefinitionModel;
1690
+ customModel = parentCustomModel;
1691
+ }
1692
+ } else {
1693
+ definitionModel = hydratedSheet.definitionModel;
1694
+ customModel = hydratedSheet.customModel;
1695
+ }
1696
+ const cModel = customModel;
1697
+ const dModel = definitionModel;
1698
+ const gridColumnState = cModel == null ? void 0 : cModel.gridColumnState;
1699
+ const { variable, parentTableVariable, inputs } = cModel;
1700
+ const aliases = (_a = dModel == null ? void 0 : dModel.aliases) == null ? void 0 : _a[parentTableVariable];
1701
+ let timeBin = "";
1702
+ if (options == null ? void 0 : options.isKPI) {
1703
+ timeBin = (options == null ? void 0 : options.plotAsTrend) ? !_.isEmpty(cModel == null ? void 0 : cModel.timeBin) ? cModel == null ? void 0 : cModel.timeBin : "per_month" : "";
1704
+ } else {
1705
+ timeBin = (cModel == null ? void 0 : cModel.timeBin) ?? "";
1706
+ }
1707
+ const valueCols = _.map(gridColumnState == null ? void 0 : gridColumnState.valueCols, (vc) => ({
1708
+ ...vc,
1709
+ hide: false
1710
+ }));
1711
+ const columnSettings = _.map(cModel == null ? void 0 : cModel.parentTableColumnSettings, (cs) => ({
1712
+ ...cs,
1713
+ hide: false
1714
+ }));
1715
+ const metadata = {
1716
+ variable,
1717
+ parentTableVariable,
1718
+ inputs,
1719
+ datasetId: (cModel == null ? void 0 : cModel.datasetId) ?? "",
1720
+ datasetName: (cModel == null ? void 0 : cModel.datasetName) ?? "",
1721
+ columnSettings: columnSettings ?? [],
1722
+ filterColumnsBy: (cModel == null ? void 0 : cModel.filterColumnsBy) ?? {},
1723
+ filterModel: ((_c = (_b = hydratedSheet == null ? void 0 : hydratedSheet.customModel) == null ? void 0 : _b.gridColumnState) == null ? void 0 : _c.filterModel) ?? {},
1724
+ valueCols: valueCols ?? [],
1725
+ rowGroupCols: (gridColumnState == null ? void 0 : gridColumnState.rowGroupCols) ?? [],
1726
+ pivotCols: (gridColumnState == null ? void 0 : gridColumnState.pivotCols) ?? [],
1727
+ dateColumn: cModel == null ? void 0 : cModel.dateColumn,
1728
+ timeBin,
1729
+ dateRange: (_d = cModel == null ? void 0 : cModel.inputs) == null ? void 0 : _d.date_range,
1730
+ aliases,
1731
+ lastModifiedDate: hydratedSheet == null ? void 0 : hydratedSheet.lastModifiedDate,
1732
+ hierarchy: cModel == null ? void 0 : cModel.hierarchy,
1733
+ description: "",
1734
+ isKPI: (options == null ? void 0 : options.isKPI) ?? false,
1735
+ currency: cModel == null ? void 0 : cModel.currency,
1736
+ sortOptions: cModel == null ? void 0 : cModel.sortOptions,
1737
+ limitOptions: cModel == null ? void 0 : cModel.limitOptions,
1738
+ stringValue: (options == null ? void 0 : options.stringValue) ?? false
1739
+ };
1740
+ const { inputs: definitionInputs, describe } = getMetricDefinition({
1741
+ sheetId: hydratedSheet.id,
1742
+ metadata,
1743
+ groupKeys: (options == null ? void 0 : options.groupKeys) ?? [],
1744
+ lastModifiedDate: hydratedSheet.lastModifiedDate,
1745
+ promotedFiltersStoreValue: {},
1746
+ promotedFilters: [],
1747
+ dateRangeModel: ((_e = hydratedSheet == null ? void 0 : hydratedSheet.customModel) == null ? void 0 : _e.dateRangeModel) ?? defaultDashboardDateRangeModel,
1748
+ currencyModel: ((_f = hydratedSheet == null ? void 0 : hydratedSheet.customModel) == null ? void 0 : _f.currencyModel) ?? defaultCurrencyModel,
1749
+ commonFilters: []
1750
+ });
1751
+ let resultData = [];
1752
+ if (!_.isEmpty(valueCols) || !_.isEmpty(metadata.rowGroupCols) || !_.isEmpty(metadata.pivotCols)) {
1753
+ if (!_.isEmpty(definitionInputs)) {
1754
+ let promises = [];
1755
+ definitionInputs.forEach((input) => {
1756
+ promises.push(
1757
+ runPublishedDefinition({
1758
+ inputs: { ...input },
1759
+ sheet: {
1760
+ id: hydratedSheet.id,
1761
+ lastModifiedDate: hydratedSheet.lastModifiedDate
1762
+ },
1763
+ variable,
1764
+ describe: parentTableVariable
1765
+ })
1766
+ );
1767
+ });
1768
+ const data = await Promise.all(promises);
1769
+ resultData = _.map(data, (d) => d.data.data);
1770
+ } else {
1771
+ const result = (await runPublishedDefinition({
1772
+ inputs: { ...inputs },
1773
+ sheet: {
1774
+ id: hydratedSheet.id,
1775
+ lastModifiedDate: hydratedSheet.lastModifiedDate
1776
+ },
1777
+ variable,
1778
+ describe: parentTableVariable
1779
+ })).data;
1780
+ resultData = result.data;
1781
+ }
1782
+ }
1783
+ resultData = _.flatten(resultData);
1784
+ return { data: resultData };
1785
+ };
1786
+ const index$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1787
+ __proto__: null,
1788
+ getData: getData$2
1789
+ }, Symbol.toStringTag, { value: "Module" }));
1790
+ class DefinitionBuilder {
1791
+ constructor(def) {
1792
+ __publicField(this, "definition");
1793
+ this.definition = {
1794
+ inputs: {},
1795
+ aliases: {},
1796
+ imports: [],
1797
+ loads: [],
1798
+ variables: [],
1799
+ permissions: [],
1800
+ exports: [],
1801
+ tables: [],
1802
+ sections: []
1803
+ };
1804
+ if (def) {
1805
+ this.definition = {
1806
+ ...this.definition,
1807
+ ...def
1808
+ };
1809
+ }
1810
+ }
1811
+ static builder(def) {
1812
+ return new DefinitionBuilder(def);
1813
+ }
1814
+ // Input methods
1815
+ withInputs(inputs) {
1816
+ this.definition.inputs = { ...this.definition.inputs, ...inputs };
1817
+ return this;
1818
+ }
1819
+ // Alias methods
1820
+ withAlias(tableName, columnAliases) {
1821
+ if (!this.definition.aliases) {
1822
+ this.definition.aliases = {};
1823
+ }
1824
+ this.definition.aliases[tableName] = columnAliases;
1825
+ return this;
1826
+ }
1827
+ // Import methods
1828
+ addImport(imprt) {
1829
+ var _a;
1830
+ (_a = this.definition.imports) == null ? void 0 : _a.push(imprt);
1831
+ return this;
1832
+ }
1833
+ addDatasetImport(datasetId, options) {
1834
+ const imprt = {
1835
+ loc: datasetId,
1836
+ to: datasetId,
1837
+ import_type: "dataset",
1838
+ ...options
1839
+ };
1840
+ return this.addImport(imprt);
1841
+ }
1842
+ // Load methods
1843
+ addLoad(load) {
1844
+ var _a;
1845
+ (_a = this.definition.loads) == null ? void 0 : _a.push(load);
1846
+ return this;
1847
+ }
1848
+ addFileLoad(from, to, fsOptions = {}) {
1849
+ const load = {
1850
+ loc: from,
1851
+ to,
1852
+ fs_options: fsOptions
1853
+ };
1854
+ return this.addLoad(load);
1855
+ }
1856
+ // Variable methods
1857
+ addVariable(name, transforms) {
1858
+ var _a;
1859
+ const variable = {
1860
+ name,
1861
+ transforms
1862
+ };
1863
+ (_a = this.definition.variables) == null ? void 0 : _a.push(variable);
1864
+ return this;
1865
+ }
1866
+ // Permission methods
1867
+ addPermission(permission) {
1868
+ var _a;
1869
+ (_a = this.definition.permissions) == null ? void 0 : _a.push(permission);
1870
+ return this;
1871
+ }
1872
+ // Export methods
1873
+ addExport(exprt) {
1874
+ var _a;
1875
+ (_a = this.definition.exports) == null ? void 0 : _a.push(exprt);
1876
+ return this;
1877
+ }
1878
+ // Table methods
1879
+ addTable(table) {
1880
+ var _a;
1881
+ (_a = this.definition.tables) == null ? void 0 : _a.push(table);
1882
+ return this;
1883
+ }
1884
+ // Section methods
1885
+ addSection(section) {
1886
+ var _a;
1887
+ (_a = this.definition.sections) == null ? void 0 : _a.push(section);
1888
+ return this;
1889
+ }
1890
+ // Build method with basic validation
1891
+ build() {
1892
+ this.validateDefinition();
1893
+ return this.definition;
1894
+ }
1895
+ validateDefinition() {
1896
+ var _a, _b, _c;
1897
+ const definedTables = /* @__PURE__ */ new Set([
1898
+ ...((_a = this.definition.imports) == null ? void 0 : _a.map((i) => i.to)) || [],
1899
+ ...((_b = this.definition.loads) == null ? void 0 : _b.map((l) => l.to)) || []
1900
+ ]);
1901
+ const aliasedTables = Object.keys(this.definition.aliases || {});
1902
+ for (const table of aliasedTables) {
1903
+ if (!definedTables.has(table)) {
1904
+ throw new Error(
1905
+ `Table "${table}" referenced in aliases but not defined in imports or loads`
1906
+ );
1907
+ }
1908
+ }
1909
+ (_c = this.definition.variables) == null ? void 0 : _c.forEach((variable) => {
1910
+ if (!variable.name) {
1911
+ throw new Error("Variable must have a name");
1912
+ }
1913
+ if (!Array.isArray(variable.transforms) || variable.transforms.length === 0) {
1914
+ throw new Error(`Variable "${variable.name}" must have at least one transform`);
1915
+ }
1916
+ });
1917
+ }
1918
+ }
1919
+ const getData$1 = async (datasetId, options) => {
1920
+ var _a, _b, _c;
1921
+ try {
1922
+ if (!datasetId) {
1923
+ throw new Error("Dataset ID is required");
1924
+ }
1925
+ const definitionModel = DefinitionBuilder.builder().addDatasetImport(datasetId).build();
1926
+ const response = await runDefinition({
1927
+ definition: definitionModel,
1928
+ inputs: definitionModel.inputs,
1929
+ variable: datasetId,
1930
+ limit: (options == null ? void 0 : options.limit) || 1e3
1931
+ });
1932
+ if (!(response == null ? void 0 : response.data)) {
1933
+ throw new Error("No data returned from API");
1934
+ }
1935
+ return { data: response.data };
1936
+ } catch (error) {
1937
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while fetching data for the dataset";
1938
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
1939
+ throw { message, status };
1940
+ }
1941
+ };
1942
+ const getSampleData = async ({
1943
+ datasetId,
1944
+ dataFilter,
1945
+ duplicateColGroups,
1946
+ datasetType
1947
+ }) => {
1948
+ var _a, _b, _c;
1949
+ try {
1950
+ if (!datasetId) {
1951
+ throw new Error("Dataset ID is required");
1952
+ }
1953
+ const response = await runSampleDefinition({
1954
+ datasetId,
1955
+ dataFilter,
1956
+ duplicateColGroups,
1957
+ datasetType
1958
+ });
1959
+ if (!(response == null ? void 0 : response.data)) {
1960
+ throw new Error("No data returned from API");
1961
+ }
1962
+ return { data: response.data };
1963
+ } catch (error) {
1964
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while fetching sample data";
1965
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
1966
+ throw { message, status };
1967
+ }
1968
+ };
1969
+ const index$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1970
+ __proto__: null,
1971
+ getData: getData$1,
1972
+ getSampleData
1973
+ }, Symbol.toStringTag, { value: "Module" }));
1974
+ const getPublishedWorkbookById = async ({
1975
+ type,
1976
+ id
1977
+ }) => {
1978
+ var _a, _b, _c;
1979
+ try {
1980
+ const response = await apiClient.post("/workbook/published", {
1981
+ type,
1982
+ id
1983
+ });
1984
+ if (!response.data) {
1985
+ throw { message: "Failed to fetch workbook details", status: 500 };
1986
+ }
1987
+ return response.data;
1988
+ } catch (error) {
1989
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while fetching workbook details";
1990
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
1991
+ throw { message, status };
1992
+ }
1993
+ };
1994
+ var WorkbookTypeEnum = /* @__PURE__ */ ((WorkbookTypeEnum2) => {
1995
+ WorkbookTypeEnum2["WORKBOOK"] = "WORKBOOK";
1996
+ WorkbookTypeEnum2["TRANSFORMATION"] = "TRANSFORMATION";
1997
+ WorkbookTypeEnum2["STATEMENT"] = "STATEMENT";
1998
+ WorkbookTypeEnum2["DASHBOARD"] = "DASHBOARD";
1999
+ WorkbookTypeEnum2["PORTAL"] = "PORTAL";
2000
+ WorkbookTypeEnum2["PROCESS"] = "PROCESS";
2001
+ WorkbookTypeEnum2["COLLECTION"] = "COLLECTION";
2002
+ WorkbookTypeEnum2["COST_ALLOCATION_GROUP"] = "ALLOCATION_GROUP";
2003
+ WorkbookTypeEnum2["ALLOCATION_BLUEPRINT"] = "ALLOCATION_BLUEPRINT";
2004
+ WorkbookTypeEnum2["FIN_CLOSE"] = "FIN_CLOSE";
2005
+ WorkbookTypeEnum2["PAGE_TEMPLATE"] = "PAGE_TEMPLATE";
2006
+ return WorkbookTypeEnum2;
2007
+ })(WorkbookTypeEnum || {});
2008
+ const getTableById = async (tableId) => {
2009
+ var _a, _b, _c;
2010
+ try {
2011
+ const response = await apiClient.get(
2012
+ `/input-table/get-table/${tableId}`
2013
+ );
2014
+ if (!response.data) {
2015
+ throw { message: "Failed to fetch table details", status: 500 };
2016
+ }
2017
+ return response.data;
2018
+ } catch (error) {
2019
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while fetching table details";
2020
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
2021
+ throw { message, status };
2022
+ }
2023
+ };
2024
+ const getData = async ({
2025
+ inputTableId: inputTableWorkbookId,
2026
+ inputTableViewId,
2027
+ pageParams = {},
2028
+ limitParams,
2029
+ sortParams,
2030
+ offsetParam
2031
+ }) => {
2032
+ var _a, _b, _c, _d;
2033
+ try {
2034
+ if (!inputTableWorkbookId || !inputTableViewId) {
2035
+ return [];
2036
+ }
2037
+ const inputTableWorkbook = await getPublishedWorkbookById({
2038
+ id: inputTableWorkbookId,
2039
+ type: WorkbookTypeEnum.COLLECTION
2040
+ });
2041
+ const inputTableId = _.get(
2042
+ inputTableWorkbook,
2043
+ "customFields.metadata.inputTableId"
2044
+ );
2045
+ const inputTable = await getTableById(inputTableId);
2046
+ if (!inputTable) {
2047
+ throw new Error("Input table not found");
2048
+ }
2049
+ const inputTableView = (_a = inputTableWorkbook == null ? void 0 : inputTableWorkbook.sheets) == null ? void 0 : _a.find(
2050
+ (sheet) => sheet.id === inputTableViewId
2051
+ );
2052
+ if (!inputTableView) {
2053
+ throw new Error("Input table view not found");
2054
+ }
2055
+ const hydratedView = await hydrateWorksheet(inputTableView);
2056
+ if (!hydratedView) {
2057
+ throw new Error("Failed to hydrate input table view");
2058
+ }
2059
+ const filters = _.get(hydratedView, "customModel.filters");
2060
+ const sort = _.get(hydratedView, "customModel.sort");
2061
+ const limit = _.get(hydratedView, "customModel.limit", {});
2062
+ const metadata = _.get(hydratedView, "customModel.metadata");
2063
+ let { targetName, definition } = {
2064
+ targetName: "",
2065
+ definition: {}
2066
+ };
2067
+ if (hydratedView.type === "PIVOT") {
2068
+ const gridColumnState = {
2069
+ valueCols: _.get(metadata, "valueCols", []),
2070
+ rowGroupCols: _.get(metadata, "rowGroupCols", []),
2071
+ filterModel: _.get(metadata, "filterModel", {}),
2072
+ pivotCols: _.get(metadata, "pivotCols", [])
2073
+ };
2074
+ const metricSeries = getMetricSeries({
2075
+ pivotCols: _.get(metadata, "pivotCols", []),
2076
+ rowGroupCols: _.get(metadata, "rowGroupCols", []),
2077
+ valueCols: _.get(metadata, "valueCols", [])
2078
+ });
2079
+ const columnSettings = _.get(
2080
+ hydratedView,
2081
+ "customModel.metadata.columnSettings"
2082
+ );
2083
+ const groupByDefinition = getGroupByDefinition({
2084
+ tableId: inputTable.id,
2085
+ tableName: inputTable.name,
2086
+ groupKeys: [],
2087
+ rowGroupCols: gridColumnState.rowGroupCols,
2088
+ columnSettings,
2089
+ filterRules: filters,
2090
+ sortValue: sort,
2091
+ metricSeries
2092
+ });
2093
+ targetName = groupByDefinition.targetName;
2094
+ definition = groupByDefinition.definition;
2095
+ } else {
2096
+ const definitionModel = generateDefinitionModel({
2097
+ tableId: inputTable.id,
2098
+ tableName: inputTable.name,
2099
+ filters,
2100
+ sort: (sortParams == null ? void 0 : sortParams.sortByOrder) ? sortConfigFromValue(sortParams) : sortConfigFromValue(sort)
2101
+ });
2102
+ targetName = definitionModel.targetName;
2103
+ definition = definitionModel.definition;
2104
+ }
2105
+ let stringifiedDefinition = JSON.stringify(definition);
2106
+ try {
2107
+ const matches = stringifiedDefinition == null ? void 0 : stringifiedDefinition.match(/{{\s*([\w.]+)\s*}}/g);
2108
+ if (matches) {
2109
+ matches.forEach((match) => {
2110
+ const key = match.replace(/{{\s*|\s*}}/g, "");
2111
+ const value = _.get(pageParams, key, "");
2112
+ if (value) {
2113
+ stringifiedDefinition = (stringifiedDefinition == null ? void 0 : stringifiedDefinition.replace(match, value)) || "";
2114
+ }
2115
+ });
2116
+ }
2117
+ } catch (error) {
2118
+ console.warn("Error evaluating input", error);
2119
+ }
2120
+ const inputTableResponse = await apiClient.post(
2121
+ "/input-table/get-table-data",
2122
+ {
2123
+ targetName,
2124
+ definition: JSON.parse(stringifiedDefinition)
2125
+ },
2126
+ {
2127
+ params: {
2128
+ limit: (limitParams == null ? void 0 : limitParams.limit) || limit.limit || 1e3,
2129
+ offset: offsetParam || 0
2130
+ }
2131
+ }
2132
+ );
2133
+ const data = _.get(inputTableResponse, "data.result");
2134
+ return { data };
2135
+ } catch (error) {
2136
+ const message = ((_c = (_b = error.response) == null ? void 0 : _b.data) == null ? void 0 : _c.message) || error.message || "An unexpected error occurred while fetching table details";
2137
+ const status = ((_d = error.response) == null ? void 0 : _d.status) || 500;
2138
+ throw { message, status };
2139
+ }
2140
+ };
2141
+ const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2142
+ __proto__: null,
2143
+ getData,
2144
+ getTableById
2145
+ }, Symbol.toStringTag, { value: "Module" }));
2146
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2147
+ __proto__: null,
2148
+ apiClient,
2149
+ dataset: index$2,
2150
+ definition: index$5,
2151
+ files: index$6,
2152
+ inputTable: index$1,
2153
+ metric: index$3,
2154
+ user: index$8,
2155
+ workflow: index$7
2156
+ }, Symbol.toStringTag, { value: "Module" }));
2157
+ const bluecopaTailwindConfig = {
2158
+ darkMode: "class",
2159
+ important: true,
2160
+ theme: {
2161
+ fontFamily: {
2162
+ para: ["Bogle"],
2163
+ display: ["Bogle"],
2164
+ table: ["Bogle"]
2165
+ },
2166
+ fontWeight: {
2167
+ normal: "300",
2168
+ semibold: "500",
2169
+ bold: "700",
2170
+ black: "800"
2171
+ },
2172
+ keyframes: {
2173
+ "fadeIn-top-to-bottom": {
2174
+ "0%": { transform: "translateY(-3%)", opacity: 0 },
2175
+ "100%": { transform: "translateY(0)", opacity: 1 }
2176
+ }
2177
+ },
2178
+ animation: {
2179
+ "fadeIn-t-b": "fadeIn-top-to-bottom 0.8s ease-out forwards",
2180
+ "fadeOut-b-t": "fadeIn-top-to-bottom 0.8s ease-out backwards"
2181
+ },
2182
+ extend: {
2183
+ boxShadow: {
2184
+ md: "2px 2px 10px 0px rgba(0,0,0,0.3)",
2185
+ lg: "4px 4px 10px 0px rgba(0,0,0,0.3)",
2186
+ xl: "6px 6px 10px 0px rgba(0,0,0,0.3)",
2187
+ DEFAULT: "2px 2px 10px 0px rgba(0,0,0,0.3)"
2188
+ },
2189
+ colors: {
2190
+ primary: {
2191
+ 50: "#ebf4ff",
2192
+ 100: "#dbe9ff",
2193
+ 200: "#bed7ff",
2194
+ 300: "#97bbff",
2195
+ 400: "#6e92ff",
2196
+ 500: "#0071dc",
2197
+ 600: "#3548ff",
2198
+ 700: "#202ee2",
2199
+ 800: "#1d2bb6",
2200
+ 900: "#202d8f",
2201
+ 950: "#131953",
2202
+ DEFAULT: "#0071dc"
2203
+ },
2204
+ secondary: {
2205
+ 50: "#F9FAFB",
2206
+ 100: "#F3F4F6",
2207
+ 200: "#E5E7EB",
2208
+ 300: "#D1D5DB",
2209
+ 400: "#9CA3AF",
2210
+ 500: "#041e42",
2211
+ 600: "#4B5563",
2212
+ 700: "#374151",
2213
+ 800: "#1F2937",
2214
+ 900: "#111827",
2215
+ DEFAULT: "#041e42"
2216
+ },
2217
+ danger: {
2218
+ 50: "#FEF2F2",
2219
+ 100: "#FEE2E2",
2220
+ 200: "#FECACA",
2221
+ 300: "#FCA5A5",
2222
+ 400: "#F87171",
2223
+ 500: "#EF4444",
2224
+ 600: "#DC2626",
2225
+ 700: "#B91C1C",
2226
+ 800: "#991B1B",
2227
+ 900: "#7F1D1D",
2228
+ DEFAULT: "#DE1C24"
2229
+ },
2230
+ success: {
2231
+ 50: "#EEFFDD",
2232
+ 100: "#ddedce",
2233
+ 200: "#bcdb9d",
2234
+ 300: "#9ac96c",
2235
+ 400: "#79b73b",
2236
+ 500: "#89E32F",
2237
+ 600: "#468408",
2238
+ 700: "#346306",
2239
+ 800: "#234204",
2240
+ 900: "#112102",
2241
+ DEFAULT: "#53a10f"
2242
+ },
2243
+ warning: {
2244
+ DEFAULT: "#fff200",
2245
+ 100: "#fef3c7"
2246
+ },
2247
+ menuBtnBg: "#ffffff",
2248
+ menuBtnText: "#041e42",
2249
+ navbarBg: "#041e42",
2250
+ navbarBlue: "#041e42",
2251
+ navbarText: "#fff",
2252
+ headerBg: "#fff",
2253
+ headerText: "#041e42",
2254
+ homeHeaderBg: "#f5f5f4",
2255
+ homeHeaderText: "#041e42",
2256
+ coralRed: "#ef4444",
2257
+ dartMouthGreen: "#059669",
2258
+ chestnut: "#c2410c",
2259
+ softPink: "#fecaca",
2260
+ darkPurple: "#6b21a8",
2261
+ darkPastelGreen: "#4d7c0f",
2262
+ sandyBrown: "#fb923c",
2263
+ cinnabar: "#ef4444",
2264
+ tyrianPurple: "#701a75",
2265
+ ruddyBlue: "#0891b2",
2266
+ viridian: "#0f766e",
2267
+ cobaltBlue: "#1d4ed8",
2268
+ dukeBlue: "#1e3a8a",
2269
+ jasmine: "#fde68a"
2270
+ },
2271
+ spacing: {
2272
+ none: "0rem",
2273
+ sm: "0.3025rem",
2274
+ md: "0.605rem",
2275
+ lg: "0.9075rem",
2276
+ xl: "1.21rem",
2277
+ "2xl": "2.42rem",
2278
+ "3xl": "4.84rem"
2279
+ },
2280
+ borderRadius: {
2281
+ sm: "1.3rem",
2282
+ md: "1.3rem",
2283
+ lg: "1.3rem",
2284
+ DEFAULT: "1.3rem"
2285
+ },
2286
+ fontSize: {
2287
+ "preset-0": ["3.013rem", "4.513rem"],
2288
+ "preset-1": ["2.505rem", "3.763rem"],
2289
+ "preset-2": ["2.093rem", "3.146rem"],
2290
+ "preset-3": ["1.742rem", "2.626rem"],
2291
+ "preset-4": ["1.452rem", "2.190rem"],
2292
+ "preset-5": ["1.21rem", "1.815rem"],
2293
+ "preset-6": ["1.004rem", "1.513rem"],
2294
+ "preset-7": ["0.835rem", "1.258rem"],
2295
+ "preset-8": ["0.702rem", "1.053rem"]
2296
+ },
2297
+ zIndex: {
2298
+ 1: "1",
2299
+ 2: "2",
2300
+ 3: "3",
2301
+ 4: "4",
2302
+ 5: "5",
2303
+ 6: "6",
2304
+ 7: "7",
2305
+ 8: "8",
2306
+ 9: "9",
2307
+ 10: "10",
2308
+ 1001: "1001",
2309
+ 1002: "1002"
2310
+ }
2311
+ }
2312
+ }
2313
+ };
2314
+ export {
2315
+ index as copaApi,
2316
+ getConfig as copaGetConfig,
2317
+ setConfig as copaSetConfig,
2318
+ bluecopaTailwindConfig as copaTailwindConfig,
2319
+ index$4 as copaUtils
2320
+ };
2321
+ //# sourceMappingURL=index.es.js.map