@aranova/tracking-react 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -820,9 +820,58 @@ function parseConversionConfig(raw) {
820
820
  };
821
821
  }
822
822
  function parseLeadForms(value) {
823
- if (!value || typeof value !== "object") return null;
824
- const version = value.registry_version;
825
- return typeof version === "number" ? { registry_version: version } : null;
823
+ if (!isRecord(value) || typeof value.registry_version !== "number") return null;
824
+ return {
825
+ registry_version: value.registry_version,
826
+ contracts: records(value.contracts).flatMap(
827
+ (c) => typeof c.form_kind === "string" && typeof c.contract_hash === "string" ? [
828
+ {
829
+ form_kind: c.form_kind,
830
+ requires: records(c.requires).flatMap(
831
+ (r) => typeof r.role === "string" ? [
832
+ {
833
+ role: r.role,
834
+ required_when: parseCondition(r.required_when),
835
+ waived: r.waived === true
836
+ }
837
+ ] : []
838
+ ),
839
+ requires_any: records(c.requires_any).map((g) => ({
840
+ roles: strings(g.roles),
841
+ waived: g.waived === true
842
+ })),
843
+ options: records(c.options).flatMap(
844
+ (o) => typeof o.role === "string" ? [{ role: o.role, options: records(o.options).flatMap(parseContractOption) }] : []
845
+ ),
846
+ contract_hash: c.contract_hash
847
+ }
848
+ ] : []
849
+ )
850
+ };
851
+ }
852
+ function parseCondition(value) {
853
+ if (!isRecord(value) || typeof value.role !== "string") return null;
854
+ return { role: value.role, any_of: strings(value.any_of) };
855
+ }
856
+ function parseContractOption(value) {
857
+ if (typeof value.key !== "string" || typeof value.label !== "string") return [];
858
+ return [
859
+ {
860
+ key: value.key,
861
+ label: value.label,
862
+ is_non_answer: value.is_non_answer === true,
863
+ deprecated: value.deprecated === true
864
+ }
865
+ ];
866
+ }
867
+ function isRecord(value) {
868
+ return !!value && typeof value === "object" && !Array.isArray(value);
869
+ }
870
+ function records(value) {
871
+ return Array.isArray(value) ? value.filter(isRecord) : [];
872
+ }
873
+ function strings(value) {
874
+ return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
826
875
  }
827
876
  var CACHE_PREFIX = "_aranova_cfg_";
828
877
  function cacheKey(url) {