@aranova/tracking-react 1.5.0 → 1.7.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/sales.mjs CHANGED
@@ -416,7 +416,7 @@ function outcomeOf(body) {
416
416
  if (body.status === "pending") return { status: "pending", id: body.id, mode };
417
417
  return { status: "failed", id: body.id, fallbackUrl: body.fallback_url, mode };
418
418
  }
419
- function formSubmitPayload(input, formId, labels) {
419
+ function formSubmitPayload(input, formSubmit, labels) {
420
420
  const vehicle = input.vehicle ? `${input.vehicle.year} ${input.vehicle.make} ${input.vehicle.model}` : "";
421
421
  const field = (name, type, label, value) => ({
422
422
  name,
@@ -424,32 +424,31 @@ function formSubmitPayload(input, formId, labels) {
424
424
  label,
425
425
  value
426
426
  });
427
+ const fields = [
428
+ field("first_name", "text", "First name", input.firstName),
429
+ field("last_name", "text", "Last name", input.lastName),
430
+ // E.164 on the wire: it keys the customer and enhanced-conversion matching.
431
+ field("phone", "tel", "Phone", toE164(input.phone) ?? input.phone),
432
+ field("email", "email", "Email", input.email ?? ""),
433
+ field(
434
+ "service",
435
+ "select",
436
+ "Service",
437
+ input.services.map((key) => labels.get(key) ?? key).join(", ")
438
+ ),
439
+ field("vehicle", "text", "Vehicle", vehicle),
440
+ field(
441
+ "start",
442
+ "text",
443
+ "Requested time",
444
+ `${input.startDate} ${String(input.startHour).padStart(2, "0")}:00`
445
+ ),
446
+ field("note", "textarea", "Notes", input.notes ?? "")
447
+ ];
448
+ const reported = new Set(fields.map((item) => item.name));
449
+ const extra = (formSubmit.extraFields ?? []).filter((item) => !reported.has(item.name));
427
450
  return {
428
- form: {
429
- id: formId,
430
- action: "/tracking/bookings",
431
- fields: [
432
- field("first_name", "text", "First name", input.firstName),
433
- field("last_name", "text", "Last name", input.lastName),
434
- // E.164 on the wire: it keys the customer and enhanced-conversion matching.
435
- field("phone", "tel", "Phone", toE164(input.phone) ?? input.phone),
436
- field("email", "email", "Email", input.email ?? ""),
437
- field(
438
- "service",
439
- "select",
440
- "Service",
441
- input.services.map((key) => labels.get(key) ?? key).join(", ")
442
- ),
443
- field("vehicle", "text", "Vehicle", vehicle),
444
- field(
445
- "start",
446
- "text",
447
- "Requested time",
448
- `${input.startDate} ${String(input.startHour).padStart(2, "0")}:00`
449
- ),
450
- field("note", "textarea", "Notes", input.notes ?? "")
451
- ]
452
- },
451
+ form: { id: formSubmit.formId, action: "/tracking/bookings", fields: [...fields, ...extra] },
453
452
  page: { path: typeof window === "undefined" ? "/" : window.location.pathname }
454
453
  };
455
454
  }
@@ -537,7 +536,7 @@ function createSalesBookingsClient(config, firing) {
537
536
  return failedBeforeSend(input);
538
537
  }
539
538
  return {
540
- async submit(input, { attemptKey, formSubmit, simulate }) {
539
+ async submit(input, { attemptKey, formSubmit, simulate, onPending }) {
541
540
  registerCapability("booking_integration");
542
541
  const runtime = runtimeOf(firing);
543
542
  warnOnSetupMismatch(runtime);
@@ -548,10 +547,7 @@ function createSalesBookingsClient(config, firing) {
548
547
  if (formSubmit && !submittedForms.has(attemptKey)) {
549
548
  submittedForms.add(attemptKey);
550
549
  const labels = new Map(booking.options.map((option) => [option.key, option.label]));
551
- formSubmit.tracking.trackEvent(
552
- "form_submit",
553
- formSubmitPayload(input, formSubmit.formId, labels)
554
- );
550
+ formSubmit.tracking.trackEvent("form_submit", formSubmitPayload(input, formSubmit, labels));
555
551
  }
556
552
  const body = {
557
553
  idempotency_key: attemptKey,
@@ -585,10 +581,9 @@ function createSalesBookingsClient(config, firing) {
585
581
  return rejected(error, input, attemptKey, runtime);
586
582
  }
587
583
  const outcome = outcomeOf(response);
588
- return withHandoff(
589
- outcome.status === "pending" ? await poll(outcome.id, outcome.mode) : outcome,
590
- input
591
- );
584
+ if (outcome.status !== "pending") return withHandoff(outcome, input);
585
+ onPending?.(outcome);
586
+ return withHandoff(await poll(outcome.id, outcome.mode), input);
592
587
  },
593
588
  async status(id) {
594
589
  return outcomeOf(
@@ -897,7 +892,14 @@ var zSmsWithheldReason = z.enum([
897
892
  "a2p_registration_required",
898
893
  "alert_recipient_cannot_receive_sms",
899
894
  "line_type_unresolved",
900
- "sale_source_sends_own_messages"
895
+ "sale_source_sends_own_messages",
896
+ "form_lead_disabled",
897
+ "source_not_enabled",
898
+ "confirmed_by_integration",
899
+ "test_or_bot_session",
900
+ "invalid_phone",
901
+ "quiet_hours",
902
+ "recently_texted"
901
903
  ]);
902
904
  var zSaleSmsStatusSchema = z.object({
903
905
  can_send_now: z._default(z.boolean(), false),