@bluecopa/core 0.1.74 → 0.1.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -337,23 +337,35 @@ const index$n = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
337
337
  getFileUrlByFileId
338
338
  }, Symbol.toStringTag, { value: "Module" }));
339
339
  const runPublishedDefinition = async (props) => {
340
+ var _a, _b;
340
341
  const { sheet, variable, inputs, describe, source } = props;
341
342
  if (!sheet) {
342
- throw new Error(`Definition is null`);
343
+ throw { message: "Definition is null", status: 400 };
343
344
  }
344
345
  if (!variable) {
345
- throw new Error(`Variable is null`);
346
+ throw { message: "Variable is null", status: 400 };
347
+ }
348
+ try {
349
+ return await apiClient.post(
350
+ "/definition/run-published",
351
+ {
352
+ sheet,
353
+ variable,
354
+ inputs,
355
+ describe
356
+ },
357
+ { cancelToken: source == null ? void 0 : source.token }
358
+ );
359
+ } catch (error) {
360
+ const data = ((_a = error.response) == null ? void 0 : _a.data) ?? {};
361
+ const errorsList = Array.isArray(data.errors) ? data.errors.filter((e) => typeof e === "string") : void 0;
362
+ const message = (errorsList && errorsList.length > 0 ? errorsList.join("\n") : null) ?? data.message ?? data.error ?? error.message ?? "Failed to run published definition";
363
+ throw {
364
+ message,
365
+ status: ((_b = error.response) == null ? void 0 : _b.status) || 500,
366
+ data
367
+ };
346
368
  }
347
- return apiClient.post(
348
- "/definition/run-published",
349
- {
350
- sheet,
351
- variable,
352
- inputs,
353
- describe
354
- },
355
- { cancelToken: source == null ? void 0 : source.token }
356
- );
357
369
  };
358
370
  const runSampleDefinition = async (props) => {
359
371
  const { datasetId, dataFilter, duplicateColGroups, datasetType } = props;
@@ -371,7 +383,7 @@ const runSampleDefinition = async (props) => {
371
383
  });
372
384
  };
373
385
  const runDefinition = async (props) => {
374
- var _a, _b, _c, _d;
386
+ var _a, _b;
375
387
  const { definition, variable, inputs, limit, source } = props;
376
388
  if (!definition) {
377
389
  throw {
@@ -399,10 +411,13 @@ const runDefinition = async (props) => {
399
411
  );
400
412
  return response.data;
401
413
  } catch (error) {
414
+ const data = ((_a = error.response) == null ? void 0 : _a.data) ?? {};
415
+ const errorsList = Array.isArray(data.errors) ? data.errors.filter((e) => typeof e === "string") : void 0;
416
+ const message = (errorsList && errorsList.length > 0 ? errorsList.join("\n") : null) ?? data.message ?? data.error ?? error.message ?? "Failed to run definition";
402
417
  throw {
403
- message: ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || "Failed to run definition",
404
- status: ((_c = error.response) == null ? void 0 : _c.status) || 500,
405
- data: (_d = error.response) == null ? void 0 : _d.data
418
+ message,
419
+ status: ((_b = error.response) == null ? void 0 : _b.status) || 500,
420
+ data
406
421
  };
407
422
  }
408
423
  };
@@ -5158,7 +5173,7 @@ var pusher = { exports: {} };
5158
5173
  * Copyright 2020, Pusher
5159
5174
  * Released under the MIT licence.
5160
5175
  */
5161
- (function(module, exports$1) {
5176
+ (function(module, exports) {
5162
5177
  (function webpackUniversalModuleDefinition(root, factory) {
5163
5178
  module.exports = factory();
5164
5179
  })(self, () => {
@@ -5167,7 +5182,7 @@ var pusher = { exports: {} };
5167
5182
  (() => {
5168
5183
  var __webpack_modules__ = {
5169
5184
  /***/
5170
- 594(__unused_webpack_module, exports$12) {
5185
+ 594(__unused_webpack_module, exports2) {
5171
5186
  var __extends2 = this && this.__extends || /* @__PURE__ */ function() {
5172
5187
  var extendStatics2 = function(d, b) {
5173
5188
  extendStatics2 = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
@@ -5185,7 +5200,7 @@ var pusher = { exports: {} };
5185
5200
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5186
5201
  };
5187
5202
  }();
5188
- Object.defineProperty(exports$12, "__esModule", { value: true });
5203
+ Object.defineProperty(exports2, "__esModule", { value: true });
5189
5204
  var INVALID_BYTE = 256;
5190
5205
  var Coder = (
5191
5206
  /** @class */
@@ -5317,16 +5332,16 @@ var pusher = { exports: {} };
5317
5332
  return Coder2;
5318
5333
  }()
5319
5334
  );
5320
- exports$12.Coder = Coder;
5335
+ exports2.Coder = Coder;
5321
5336
  var stdCoder = new Coder();
5322
5337
  function encode(data) {
5323
5338
  return stdCoder.encode(data);
5324
5339
  }
5325
- exports$12.encode = encode;
5340
+ exports2.encode = encode;
5326
5341
  function decode(s) {
5327
5342
  return stdCoder.decode(s);
5328
5343
  }
5329
- exports$12.decode = decode;
5344
+ exports2.decode = decode;
5330
5345
  var URLSafeCoder = (
5331
5346
  /** @class */
5332
5347
  function(_super) {
@@ -5355,28 +5370,28 @@ var pusher = { exports: {} };
5355
5370
  return URLSafeCoder2;
5356
5371
  }(Coder)
5357
5372
  );
5358
- exports$12.URLSafeCoder = URLSafeCoder;
5373
+ exports2.URLSafeCoder = URLSafeCoder;
5359
5374
  var urlSafeCoder = new URLSafeCoder();
5360
5375
  function encodeURLSafe(data) {
5361
5376
  return urlSafeCoder.encode(data);
5362
5377
  }
5363
- exports$12.encodeURLSafe = encodeURLSafe;
5378
+ exports2.encodeURLSafe = encodeURLSafe;
5364
5379
  function decodeURLSafe(s) {
5365
5380
  return urlSafeCoder.decode(s);
5366
5381
  }
5367
- exports$12.decodeURLSafe = decodeURLSafe;
5368
- exports$12.encodedLength = function(length) {
5382
+ exports2.decodeURLSafe = decodeURLSafe;
5383
+ exports2.encodedLength = function(length) {
5369
5384
  return stdCoder.encodedLength(length);
5370
5385
  };
5371
- exports$12.maxDecodedLength = function(length) {
5386
+ exports2.maxDecodedLength = function(length) {
5372
5387
  return stdCoder.maxDecodedLength(length);
5373
5388
  };
5374
- exports$12.decodedLength = function(s) {
5389
+ exports2.decodedLength = function(s) {
5375
5390
  return stdCoder.decodedLength(s);
5376
5391
  };
5377
5392
  },
5378
5393
  /***/
5379
- 978(__unused_webpack_module, exports$12) {
5394
+ 978(__unused_webpack_module, exports2) {
5380
5395
  var INVALID_UTF8 = "utf8: invalid source encoding";
5381
5396
  function decode(arr) {
5382
5397
  var chars = [];
@@ -5436,7 +5451,7 @@ var pusher = { exports: {} };
5436
5451
  }
5437
5452
  return chars.join("");
5438
5453
  }
5439
- exports$12.D4 = decode;
5454
+ exports2.D4 = decode;
5440
5455
  },
5441
5456
  /***/
5442
5457
  721(module2, __unused_webpack_exports, __webpack_require__2) {
@@ -9055,10 +9070,10 @@ var pusher = { exports: {} };
9055
9070
  return module2.exports;
9056
9071
  }
9057
9072
  (() => {
9058
- __webpack_require__.d = (exports$12, definition) => {
9073
+ __webpack_require__.d = (exports2, definition) => {
9059
9074
  for (var key in definition) {
9060
- if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports$12, key)) {
9061
- Object.defineProperty(exports$12, key, { enumerable: true, get: definition[key] });
9075
+ if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports2, key)) {
9076
+ Object.defineProperty(exports2, key, { enumerable: true, get: definition[key] });
9062
9077
  }
9063
9078
  }
9064
9079
  };
@@ -9814,6 +9829,209 @@ const index$k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
9814
9829
  statementFilterUtils: filterUtils,
9815
9830
  websocketUtils: websocketProviderFactory
9816
9831
  }, Symbol.toStringTag, { value: "Module" }));
9832
+ function resolveBinding(bindingKey, bindings) {
9833
+ if (!bindings[bindingKey]) return null;
9834
+ const bindingValue = bindings[bindingKey];
9835
+ return _.isObject(bindingValue) && "id" in bindingValue ? bindingValue.id : bindingValue;
9836
+ }
9837
+ function applyNodeBindings(node, bindings) {
9838
+ var _a, _b, _c, _d, _e;
9839
+ if (!node) return node;
9840
+ const updatedNode = { ...node };
9841
+ const nodeType = node.type || ((_a = node.data) == null ? void 0 : _a.type);
9842
+ if (nodeType === "mapping-source") {
9843
+ if ((_b = node.data) == null ? void 0 : _b.sheetId) {
9844
+ const bindingKey = node.data.sheetId;
9845
+ const resolved = resolveBinding(bindingKey, bindings);
9846
+ if (resolved) {
9847
+ updatedNode.data = { ...updatedNode.data, sheetId: resolved };
9848
+ }
9849
+ }
9850
+ if ((_c = node.data) == null ? void 0 : _c.blueprint) {
9851
+ const bindingKey = node.data.blueprint;
9852
+ const resolved = resolveBinding(bindingKey, bindings);
9853
+ if (resolved) {
9854
+ updatedNode.data = { ...updatedNode.data, blueprint: resolved };
9855
+ }
9856
+ }
9857
+ }
9858
+ if (nodeType === "blueprint") {
9859
+ if ((_d = node.data) == null ? void 0 : _d.blueprint) {
9860
+ const bindingKey = node.data.blueprint;
9861
+ const resolved = resolveBinding(bindingKey, bindings);
9862
+ if (resolved) {
9863
+ updatedNode.data = { ...updatedNode.data, blueprint: resolved };
9864
+ }
9865
+ }
9866
+ if (node.blueprintSheetId) {
9867
+ const bindingKey = node.blueprintSheetId;
9868
+ const resolved = resolveBinding(bindingKey, bindings);
9869
+ if (resolved) {
9870
+ updatedNode.blueprintSheetId = resolved;
9871
+ }
9872
+ }
9873
+ }
9874
+ if (nodeType === "source" && ((_e = node.data) == null ? void 0 : _e.input)) {
9875
+ const bindingKey = node.data.input;
9876
+ const resolved = resolveBinding(bindingKey, bindings);
9877
+ if (resolved) {
9878
+ updatedNode.data = { ...updatedNode.data, input: resolved };
9879
+ }
9880
+ }
9881
+ return updatedNode;
9882
+ }
9883
+ function applyTaskBindings(task, bindings) {
9884
+ if (!task) return task;
9885
+ return applyBindingsRecursively(task, bindings);
9886
+ }
9887
+ function applyTaskGroupBindings(taskGroup, bindings) {
9888
+ if (!taskGroup) return taskGroup;
9889
+ const updatedGroup = { ...taskGroup };
9890
+ if (Array.isArray(taskGroup.tasks)) {
9891
+ updatedGroup.tasks = taskGroup.tasks.map((task) => applyTaskBindings(task, bindings));
9892
+ }
9893
+ if (Array.isArray(taskGroup.taskGroups)) {
9894
+ updatedGroup.taskGroups = taskGroup.taskGroups.map(
9895
+ (group) => applyTaskGroupBindings(group, bindings)
9896
+ );
9897
+ }
9898
+ return updatedGroup;
9899
+ }
9900
+ function applyBindingsRecursively(obj, bindings) {
9901
+ if (obj === null || obj === void 0) {
9902
+ return obj;
9903
+ }
9904
+ if (typeof obj === "string") {
9905
+ const resolved = resolveBinding(obj, bindings);
9906
+ return resolved || obj;
9907
+ }
9908
+ if (Array.isArray(obj)) {
9909
+ return obj.map((item) => applyBindingsRecursively(item, bindings));
9910
+ }
9911
+ if (typeof obj === "object") {
9912
+ const result = {};
9913
+ for (const key in obj) {
9914
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
9915
+ result[key] = applyBindingsRecursively(obj[key], bindings);
9916
+ }
9917
+ }
9918
+ return result;
9919
+ }
9920
+ return obj;
9921
+ }
9922
+ function applyUITaskBindings(uiTask, bindings) {
9923
+ if (!uiTask || uiTask.type !== "task") return uiTask;
9924
+ return applyBindingsRecursively(uiTask, bindings);
9925
+ }
9926
+ function applyUIGroupBindings(uiGroup, bindings) {
9927
+ if (!uiGroup || uiGroup.type !== "group") return uiGroup;
9928
+ const updatedGroup = { ...uiGroup };
9929
+ if (Array.isArray(uiGroup.children)) {
9930
+ updatedGroup.children = uiGroup.children.map((child) => {
9931
+ if (child.type === "task") {
9932
+ return applyUITaskBindings(child, bindings);
9933
+ } else if (child.type === "group") {
9934
+ return applyUIGroupBindings(child, bindings);
9935
+ }
9936
+ return child;
9937
+ });
9938
+ }
9939
+ return updatedGroup;
9940
+ }
9941
+ function applyPipelineBindings(fileRead, bindings) {
9942
+ const result = { ...fileRead };
9943
+ if (Array.isArray(result.nodes)) {
9944
+ result.nodes = result.nodes.map((node) => applyNodeBindings(node, bindings));
9945
+ }
9946
+ return result;
9947
+ }
9948
+ function applyScheduleBindings(fileRead, bindings) {
9949
+ const result = { ...fileRead };
9950
+ if (Array.isArray(result.taskGroups)) {
9951
+ result.taskGroups = result.taskGroups.map(
9952
+ (group) => applyTaskGroupBindings(group, bindings)
9953
+ );
9954
+ }
9955
+ if (result.uiModel && Array.isArray(result.uiModel.groups)) {
9956
+ result.uiModel = {
9957
+ ...result.uiModel,
9958
+ groups: result.uiModel.groups.map((group) => applyUIGroupBindings(group, bindings))
9959
+ };
9960
+ }
9961
+ return result;
9962
+ }
9963
+ function applyWorkbookBindings(fileRead, bindings) {
9964
+ const bindingKeys = new Set(Object.keys(bindings));
9965
+ const hasMatchingKeys = Object.keys(fileRead).some((key) => bindingKeys.has(key));
9966
+ if (!hasMatchingKeys) return fileRead;
9967
+ const remapped = {};
9968
+ for (const [key, value] of Object.entries(fileRead)) {
9969
+ const resolvedKey = resolveBinding(key, bindings) ?? key;
9970
+ const resolvedValue = bindingKeys.has(key) ? applyBindingsRecursively(value, bindings) : value;
9971
+ remapped[resolvedKey] = resolvedValue;
9972
+ if (resolvedKey !== key) {
9973
+ remapped[key] = resolvedValue;
9974
+ }
9975
+ }
9976
+ return remapped;
9977
+ }
9978
+ function applyReconBindings(fileRead, bindings) {
9979
+ if (!fileRead || !Array.isArray(fileRead.imports)) return fileRead;
9980
+ return {
9981
+ ...fileRead,
9982
+ imports: fileRead.imports.map((imp) => {
9983
+ if (!(imp == null ? void 0 : imp.loc)) return imp;
9984
+ const resolved = resolveBinding(imp.loc, bindings);
9985
+ return resolved ? { ...imp, loc: resolved } : imp;
9986
+ })
9987
+ };
9988
+ }
9989
+ function applyDefinitionBindings(fileRead, bindings, definitionType) {
9990
+ if (!fileRead || !bindings || !Object.keys(bindings).length) return fileRead;
9991
+ switch (definitionType) {
9992
+ case "PIPELINE":
9993
+ return applyPipelineBindings(fileRead, bindings);
9994
+ case "SCHEDULE":
9995
+ return applyScheduleBindings(fileRead, bindings);
9996
+ case "WORKBOOK":
9997
+ return applyWorkbookBindings(fileRead, bindings);
9998
+ case "RECON":
9999
+ return applyReconBindings(fileRead, bindings);
10000
+ default:
10001
+ return fileRead;
10002
+ }
10003
+ }
10004
+ function applyTargetedBindings(fileRead, bindings) {
10005
+ if (!fileRead || !bindings || !Object.keys(bindings).length) return fileRead;
10006
+ let result = { ...fileRead };
10007
+ result = applyPipelineBindings(result, bindings);
10008
+ result = applyScheduleBindings(result, bindings);
10009
+ result = applyWorkbookBindings(result, bindings);
10010
+ return result;
10011
+ }
10012
+ async function fetchSolutionBindings() {
10013
+ try {
10014
+ const res = await apiClient.get("/solution/bindings");
10015
+ const payload = res == null ? void 0 : res.data;
10016
+ const extracted = payload && typeof payload === "object" && !Array.isArray(payload) && "bindings" in payload ? payload.bindings : payload;
10017
+ if (extracted && typeof extracted === "object" && !Array.isArray(extracted)) {
10018
+ return extracted;
10019
+ }
10020
+ return {};
10021
+ } catch (err) {
10022
+ const msg = err instanceof Error ? err.message : "unknown";
10023
+ console.error(`Error fetching solution bindings: ${msg}`);
10024
+ return {};
10025
+ }
10026
+ }
10027
+ function applyBindings(fileRead, bindings, definitionType) {
10028
+ if (!fileRead || !Object.keys(bindings).length) return fileRead;
10029
+ return definitionType ? applyDefinitionBindings(
10030
+ fileRead,
10031
+ bindings,
10032
+ definitionType
10033
+ ) : applyTargetedBindings(fileRead, bindings);
10034
+ }
9817
10035
  const hydrateWorksheet = async (sheet) => {
9818
10036
  try {
9819
10037
  if (!sheet) return sheet;
@@ -9839,8 +10057,15 @@ const hydrateWorksheet = async (sheet) => {
9839
10057
  if (!definitionModel || !definitionModel[sheetId]) {
9840
10058
  return sheet;
9841
10059
  }
9842
- sheet.definitionModel = definitionModel[sheetId];
9843
- sheet.customModel = customModel[sheetId];
10060
+ const bindings = await fetchSolutionBindings();
10061
+ sheet.definitionModel = applyBindings(
10062
+ definitionModel[sheetId],
10063
+ bindings
10064
+ );
10065
+ sheet.customModel = applyBindings(
10066
+ customModel[sheetId],
10067
+ bindings
10068
+ );
9844
10069
  return sheet;
9845
10070
  } catch (error) {
9846
10071
  console.error("Error hydrating portal page:", error);