@aranova/tracking-react 1.16.1 → 1.18.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
@@ -717,9 +717,18 @@ function parseBookingRules(value) {
717
717
  special_hours: parseWindowsMap(r.special_hours),
718
718
  vehicle_required: r.vehicle_required === true,
719
719
  vehicle_deferred: r.vehicle_deferred === true,
720
- drop_off_options: isStringList(r.drop_off_options) ? r.drop_off_options : []
720
+ drop_off_options: isStringList(r.drop_off_options) ? r.drop_off_options : [],
721
+ booked_counts: parseCounts(r.booked_counts)
721
722
  };
722
723
  }
724
+ function parseCounts(value) {
725
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
726
+ const counts = {};
727
+ for (const [date, count] of Object.entries(value)) {
728
+ if (typeof count === "number" && Number.isInteger(count) && count >= 0) counts[date] = count;
729
+ }
730
+ return counts;
731
+ }
723
732
  function parseBookingOption(value) {
724
733
  if (!value || typeof value !== "object") return [];
725
734
  const o = value;
@@ -1535,7 +1544,8 @@ function camelRules(rules) {
1535
1544
  specialHours: rules.special_hours,
1536
1545
  vehicleRequired: rules.vehicle_required,
1537
1546
  vehicleDeferred: rules.vehicle_deferred,
1538
- dropOffOptions: rules.drop_off_options
1547
+ dropOffOptions: rules.drop_off_options,
1548
+ bookedCounts: rules.booked_counts ?? {}
1539
1549
  };
1540
1550
  }
1541
1551
  var WEEKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
@@ -1568,7 +1578,8 @@ function bookableSlots(rules, { timeZone, now = /* @__PURE__ */ new Date() }) {
1568
1578
  date,
1569
1579
  weekday,
1570
1580
  morning: [...windows.morning],
1571
- afternoon: [...windows.afternoon]
1581
+ afternoon: [...windows.afternoon],
1582
+ booked: rules.bookedCounts?.[date] ?? 0
1572
1583
  });
1573
1584
  }
1574
1585
  return days;
@@ -1669,6 +1680,13 @@ var EVENT_SEMANTICS = {
1669
1680
  outcomeRole: "engagement",
1670
1681
  clientVisibility: "detailed"
1671
1682
  },
1683
+ // Adds to the submit it names; counting it as a lead would double every lead.
1684
+ form_details: {
1685
+ label: "Form details added",
1686
+ category: "lead",
1687
+ outcomeRole: "engagement",
1688
+ clientVisibility: "detailed"
1689
+ },
1672
1690
  form_submit: {
1673
1691
  label: "Form submitted",
1674
1692
  category: "lead",
@@ -1727,7 +1745,6 @@ var jsonValueSchema = z2.lazy(
1727
1745
  ])
1728
1746
  ).register(z2.globalRegistry, { id: "JsonSerializableValue" });
1729
1747
  var contractNameSchema = z2.string().check(z2.regex(/^[a-z][a-z0-9_]{0,47}(:[a-z0-9_-]{1,48})?$/));
1730
- var contractName = contractNameSchema;
1731
1748
  var violationRole = z2.string().check(
1732
1749
  z2.maxLength(200),
1733
1750
  z2.regex(
@@ -1739,38 +1756,41 @@ var contractViolationSchema = z2.strictObject({
1739
1756
  role: z2.nullable(violationRole),
1740
1757
  rule: z2.string().check(z2.regex(/^[a-z][a-z_]{0,47}$/))
1741
1758
  });
1759
+ var formFieldSchema = z2.strictObject({
1760
+ name: z2.string(),
1761
+ type: z2.string(),
1762
+ label: z2.nullable(z2.string()),
1763
+ value: jsonValueSchema,
1764
+ role: z2.optional(z2.nullable(contractNameSchema))
1765
+ });
1766
+ var formExtraSchema = z2.optional(
1767
+ z2.nullable(
1768
+ z2.array(
1769
+ z2.strictObject({
1770
+ key: z2.string().check(z2.maxLength(64)),
1771
+ label: z2.string().check(z2.maxLength(200)),
1772
+ value: jsonValueSchema
1773
+ })
1774
+ ).check(z2.maxLength(20))
1775
+ )
1776
+ );
1777
+ var contractVersionSchema = z2.optional(z2.nullable(z2.int().check(z2.gte(1))));
1778
+ var contractHashSchema = z2.optional(z2.nullable(z2.string().check(z2.maxLength(64))));
1779
+ var formContractViolationsSchema = z2.optional(
1780
+ z2.nullable(z2.array(contractViolationSchema).check(z2.maxLength(MAX_CONTRACT_VIOLATIONS)))
1781
+ );
1742
1782
  var formSubmitMetadataSchema = z2.strictObject({
1743
1783
  form: z2.strictObject({
1744
1784
  id: z2.string(),
1745
1785
  action: z2.nullable(z2.string()),
1746
- fields: z2.optional(
1747
- z2.array(
1748
- z2.strictObject({
1749
- name: z2.string(),
1750
- type: z2.string(),
1751
- label: z2.nullable(z2.string()),
1752
- value: jsonValueSchema,
1753
- role: z2.optional(z2.nullable(contractName))
1754
- })
1755
- )
1756
- ),
1757
- kind: z2.optional(z2.nullable(contractName)),
1758
- contract_version: z2.optional(z2.nullable(z2.int().check(z2.gte(1)))),
1759
- contract_hash: z2.optional(z2.nullable(z2.string().check(z2.maxLength(64)))),
1760
- extra: z2.optional(
1761
- z2.nullable(
1762
- z2.array(
1763
- z2.strictObject({
1764
- key: z2.string().check(z2.maxLength(64)),
1765
- label: z2.string().check(z2.maxLength(200)),
1766
- value: jsonValueSchema
1767
- })
1768
- ).check(z2.maxLength(20))
1769
- )
1770
- ),
1771
- contract_violations: z2.optional(
1772
- z2.nullable(z2.array(contractViolationSchema).check(z2.maxLength(MAX_CONTRACT_VIOLATIONS)))
1773
- )
1786
+ fields: z2.optional(z2.array(formFieldSchema)),
1787
+ kind: z2.optional(z2.nullable(contractNameSchema)),
1788
+ contract_version: contractVersionSchema,
1789
+ contract_hash: contractHashSchema,
1790
+ extra: formExtraSchema,
1791
+ contract_violations: formContractViolationsSchema,
1792
+ // Minted per submit; a later `form_details` names it to add answers to this lead.
1793
+ submission_id: z2.optional(z2.nullable(z2.uuidv4()))
1774
1794
  }),
1775
1795
  page: z2.strictObject({
1776
1796
  path: z2.string()
@@ -1902,10 +1922,10 @@ var KNOWN_ROLES = new Set(LEAD_FORM_ROLES);
1902
1922
  var ROLE_ORDER = new Map(LEAD_FORM_ROLES.map((role, index) => [role, index]));
1903
1923
  var ADD_ON = /^add_on:[a-z0-9_-]{1,48}$/;
1904
1924
  var CONTRACT_NAME = /^[a-z][a-z0-9_]{0,47}(:[a-z0-9_-]{1,48})?$/;
1905
- function judgeLeadForm(kind, formId, fields, contracts, settings) {
1925
+ function judgeLeadForm(kind, formId, fields, contracts, settings, { partial = false } = {}) {
1906
1926
  const generated = contracts?.contracts[kind];
1907
1927
  const live = liveContract(settings.trackingConfig, kind);
1908
- const violations = check(live === void 0 ? generated : fromLive(live), fields);
1928
+ const violations = check(live === void 0 ? generated : fromLive(live), fields, partial);
1909
1929
  const liveHash = live === void 0 ? void 0 : live?.contract_hash ?? null;
1910
1930
  if (contracts && (liveHash !== void 0 && (generated?.hash ?? null) !== liveHash || contracts.registryVersion !== LEAD_FORM_REGISTRY_VERSION)) {
1911
1931
  violations.push({ role: null, rule: "contract_behind" });
@@ -1937,7 +1957,7 @@ function fromLive(live) {
1937
1957
  options: Object.fromEntries(live.options.map((o) => [o.role, o.options.map((x) => x.key)]))
1938
1958
  };
1939
1959
  }
1940
- function check(contract, fields) {
1960
+ function check(contract, fields, partial) {
1941
1961
  const answered = new Map(fields);
1942
1962
  const violations = [];
1943
1963
  for (const [role, value] of fields) {
@@ -1955,6 +1975,7 @@ function check(contract, fields) {
1955
1975
  violations.push({ role, rule: "unknown_option" });
1956
1976
  }
1957
1977
  }
1978
+ if (partial) return violations;
1958
1979
  for (const { role, requiredWhen } of contract?.requires ?? []) {
1959
1980
  const owing = requiredWhen === null || optionKeys(answered.get(requiredWhen.role)).some((key) => requiredWhen.anyOf.includes(key));
1960
1981
  if (owing && !answered.has(role)) violations.push({ role, rule: "missing_required" });
@@ -2623,12 +2644,15 @@ var zSmsWithheldReason = z4.enum([
2623
2644
  "test_or_bot_session",
2624
2645
  "invalid_phone",
2625
2646
  "recently_texted",
2647
+ "owner_not_alerted",
2648
+ "no_new_details",
2626
2649
  "do_not_contact",
2627
2650
  "do_not_text_tag",
2628
2651
  "missing_value",
2629
2652
  "us_texting_pending",
2630
2653
  "us_texting_rejected",
2631
- "texts_paused"
2654
+ "texts_paused",
2655
+ "outside_nanp"
2632
2656
  ]);
2633
2657
  var zSaleSmsStatusSchema = z4.object({
2634
2658
  can_send_now: z4._default(z4.boolean(), false),