@timeax/digital-service-engine 0.3.4 → 0.3.5

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.
@@ -4787,12 +4787,32 @@ function toSelectedOptionKeys(byField) {
4787
4787
  }
4788
4788
  return keys;
4789
4789
  }
4790
- function getSelectedOptionsByFieldId(selection, fieldById) {
4791
- const out = {};
4790
+ function getSelectedOptionsByFieldId(selection, fieldById, mode) {
4791
+ var _a, _b;
4792
+ const collected = {};
4792
4793
  for (const visit of buildSelectedNodeVisitOrder(selection, fieldById)) {
4793
4794
  if (visit.kind !== "option") continue;
4794
- if (!out[visit.fieldId]) out[visit.fieldId] = [];
4795
- out[visit.fieldId].push(visit.optionId);
4795
+ if (!collected[visit.fieldId]) collected[visit.fieldId] = [];
4796
+ collected[visit.fieldId].push(visit.optionId);
4797
+ }
4798
+ const out = {};
4799
+ for (const [fieldId, optionIds] of Object.entries(collected)) {
4800
+ const field = fieldById.get(fieldId);
4801
+ if (!field) continue;
4802
+ const validOptionIds = new Set(
4803
+ ((_a = field.options) != null ? _a : []).map((option) => option.id)
4804
+ );
4805
+ const dedupedValid = [];
4806
+ const seen = /* @__PURE__ */ new Set();
4807
+ for (const optionId of optionIds) {
4808
+ if (!validOptionIds.has(optionId)) continue;
4809
+ if (seen.has(optionId)) continue;
4810
+ seen.add(optionId);
4811
+ dedupedValid.push(optionId);
4812
+ }
4813
+ const isMulti = ((_b = field.meta) == null ? void 0 : _b.multi) === true;
4814
+ const normalized = mode === "prod" && !isMulti ? dedupedValid.length ? [dedupedValid[dedupedValid.length - 1]] : [] : dedupedValid;
4815
+ if (normalized.length) out[fieldId] = normalized;
4796
4816
  }
4797
4817
  return out;
4798
4818
  }
@@ -5282,7 +5302,11 @@ function buildOrderSnapshot(props, builder, selection, services, settings = {})
5282
5302
  const tagById = new Map(((_e = props.filters) != null ? _e : []).map((t) => [t.id, t]));
5283
5303
  const fieldById = new Map(((_f = props.fields) != null ? _f : []).map((f) => [f.id, f]));
5284
5304
  const tagConstraints = (_h = (_g = tagById.get(tagId)) == null ? void 0 : _g.constraints) != null ? _h : void 0;
5285
- const selectedOptionsByFieldId = getSelectedOptionsByFieldId(selection, fieldById);
5305
+ const selectedOptionsByFieldId = getSelectedOptionsByFieldId(
5306
+ selection,
5307
+ fieldById,
5308
+ mode
5309
+ );
5286
5310
  const selectionFields = visibleFieldIds.map((fid) => fieldById.get(fid)).filter((f) => !!f).map((f) => {
5287
5311
  var _a2;
5288
5312
  const optionIds = isOptionBased(f) ? (_a2 = selectedOptionsByFieldId[f.id]) != null ? _a2 : [] : void 0;