@garagem-ai/site-sdk 0.5.3 → 0.6.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
@@ -479,6 +479,353 @@ function isVisitSlotAllowed(schedule, visitDate, visitTime, now = /* @__PURE__ *
479
479
  return slotsForDate(schedule, visitDate, now).includes(time);
480
480
  }
481
481
 
482
+ // src/phone.ts
483
+ import {
484
+ AsYouType,
485
+ isValidPhoneNumber,
486
+ parsePhoneNumber
487
+ } from "libphonenumber-js";
488
+
489
+ // src/phone-countries.ts
490
+ var DEFAULT_PHONE_COUNTRY_CODE = "BR";
491
+ var PHONE_COUNTRIES = [
492
+ { code: "BR", name: "Brasil", dialCode: "55", flag: "\u{1F1E7}\u{1F1F7}" },
493
+ { code: "US", name: "Estados Unidos", dialCode: "1", flag: "\u{1F1FA}\u{1F1F8}" },
494
+ { code: "CA", name: "Canad\xE1", dialCode: "1", flag: "\u{1F1E8}\u{1F1E6}" },
495
+ { code: "MX", name: "M\xE9xico", dialCode: "52", flag: "\u{1F1F2}\u{1F1FD}" },
496
+ { code: "GT", name: "Guatemala", dialCode: "502", flag: "\u{1F1EC}\u{1F1F9}" },
497
+ { code: "BZ", name: "Belize", dialCode: "501", flag: "\u{1F1E7}\u{1F1FF}" },
498
+ { code: "SV", name: "El Salvador", dialCode: "503", flag: "\u{1F1F8}\u{1F1FB}" },
499
+ { code: "HN", name: "Honduras", dialCode: "504", flag: "\u{1F1ED}\u{1F1F3}" },
500
+ { code: "NI", name: "Nicar\xE1gua", dialCode: "505", flag: "\u{1F1F3}\u{1F1EE}" },
501
+ { code: "CR", name: "Costa Rica", dialCode: "506", flag: "\u{1F1E8}\u{1F1F7}" },
502
+ { code: "PA", name: "Panam\xE1", dialCode: "507", flag: "\u{1F1F5}\u{1F1E6}" },
503
+ { code: "CU", name: "Cuba", dialCode: "53", flag: "\u{1F1E8}\u{1F1FA}" },
504
+ { code: "DO", name: "Rep\xFAblica Dominicana", dialCode: "1", flag: "\u{1F1E9}\u{1F1F4}" },
505
+ { code: "HT", name: "Haiti", dialCode: "509", flag: "\u{1F1ED}\u{1F1F9}" },
506
+ { code: "AR", name: "Argentina", dialCode: "54", flag: "\u{1F1E6}\u{1F1F7}" },
507
+ { code: "CL", name: "Chile", dialCode: "56", flag: "\u{1F1E8}\u{1F1F1}" },
508
+ { code: "CO", name: "Col\xF4mbia", dialCode: "57", flag: "\u{1F1E8}\u{1F1F4}" },
509
+ { code: "PE", name: "Peru", dialCode: "51", flag: "\u{1F1F5}\u{1F1EA}" },
510
+ { code: "UY", name: "Uruguai", dialCode: "598", flag: "\u{1F1FA}\u{1F1FE}" },
511
+ { code: "PY", name: "Paraguai", dialCode: "595", flag: "\u{1F1F5}\u{1F1FE}" },
512
+ { code: "BO", name: "Bol\xEDvia", dialCode: "591", flag: "\u{1F1E7}\u{1F1F4}" },
513
+ { code: "EC", name: "Equador", dialCode: "593", flag: "\u{1F1EA}\u{1F1E8}" },
514
+ { code: "VE", name: "Venezuela", dialCode: "58", flag: "\u{1F1FB}\u{1F1EA}" },
515
+ { code: "GY", name: "Guiana", dialCode: "592", flag: "\u{1F1EC}\u{1F1FE}" },
516
+ { code: "SR", name: "Suriname", dialCode: "597", flag: "\u{1F1F8}\u{1F1F7}" },
517
+ { code: "PT", name: "Portugal", dialCode: "351", flag: "\u{1F1F5}\u{1F1F9}" },
518
+ { code: "ES", name: "Espanha", dialCode: "34", flag: "\u{1F1EA}\u{1F1F8}" },
519
+ { code: "FR", name: "Fran\xE7a", dialCode: "33", flag: "\u{1F1EB}\u{1F1F7}" },
520
+ { code: "UK", name: "Reino Unido", dialCode: "44", flag: "\u{1F1EC}\u{1F1E7}" },
521
+ { code: "DE", name: "Alemanha", dialCode: "49", flag: "\u{1F1E9}\u{1F1EA}" },
522
+ { code: "IT", name: "It\xE1lia", dialCode: "39", flag: "\u{1F1EE}\u{1F1F9}" },
523
+ { code: "NL", name: "Holanda", dialCode: "31", flag: "\u{1F1F3}\u{1F1F1}" },
524
+ { code: "BE", name: "B\xE9lgica", dialCode: "32", flag: "\u{1F1E7}\u{1F1EA}" },
525
+ { code: "CH", name: "Su\xED\xE7a", dialCode: "41", flag: "\u{1F1E8}\u{1F1ED}" },
526
+ { code: "AT", name: "\xC1ustria", dialCode: "43", flag: "\u{1F1E6}\u{1F1F9}" },
527
+ { code: "SE", name: "Su\xE9cia", dialCode: "46", flag: "\u{1F1F8}\u{1F1EA}" },
528
+ { code: "NO", name: "Noruega", dialCode: "47", flag: "\u{1F1F3}\u{1F1F4}" },
529
+ { code: "DK", name: "Dinamarca", dialCode: "45", flag: "\u{1F1E9}\u{1F1F0}" },
530
+ { code: "FI", name: "Finl\xE2ndia", dialCode: "358", flag: "\u{1F1EB}\u{1F1EE}" },
531
+ { code: "IE", name: "Irlanda", dialCode: "353", flag: "\u{1F1EE}\u{1F1EA}" },
532
+ { code: "AU", name: "Austr\xE1lia", dialCode: "61", flag: "\u{1F1E6}\u{1F1FA}" },
533
+ { code: "NZ", name: "Nova Zel\xE2ndia", dialCode: "64", flag: "\u{1F1F3}\u{1F1FF}" },
534
+ { code: "JP", name: "Jap\xE3o", dialCode: "81", flag: "\u{1F1EF}\u{1F1F5}" },
535
+ { code: "KR", name: "Coreia do Sul", dialCode: "82", flag: "\u{1F1F0}\u{1F1F7}" },
536
+ { code: "CN", name: "China", dialCode: "86", flag: "\u{1F1E8}\u{1F1F3}" },
537
+ { code: "IN", name: "\xCDndia", dialCode: "91", flag: "\u{1F1EE}\u{1F1F3}" },
538
+ { code: "RU", name: "R\xFAssia", dialCode: "7", flag: "\u{1F1F7}\u{1F1FA}" },
539
+ { code: "UA", name: "Ucr\xE2nia", dialCode: "380", flag: "\u{1F1FA}\u{1F1E6}" },
540
+ { code: "AE", name: "Emirados \xC1rabes", dialCode: "971", flag: "\u{1F1E6}\u{1F1EA}" },
541
+ { code: "SA", name: "Ar\xE1bia Saudita", dialCode: "966", flag: "\u{1F1F8}\u{1F1E6}" },
542
+ { code: "QA", name: "Catar", dialCode: "974", flag: "\u{1F1F6}\u{1F1E6}" },
543
+ { code: "KW", name: "Kuwait", dialCode: "965", flag: "\u{1F1F0}\u{1F1FC}" },
544
+ { code: "BH", name: "Bahrein", dialCode: "973", flag: "\u{1F1E7}\u{1F1ED}" },
545
+ { code: "OM", name: "Om\xE3", dialCode: "968", flag: "\u{1F1F4}\u{1F1F2}" },
546
+ { code: "JO", name: "Jord\xE2nia", dialCode: "962", flag: "\u{1F1EF}\u{1F1F4}" },
547
+ { code: "LB", name: "L\xEDbano", dialCode: "961", flag: "\u{1F1F1}\u{1F1E7}" },
548
+ { code: "IL", name: "Israel", dialCode: "972", flag: "\u{1F1EE}\u{1F1F1}" },
549
+ { code: "TR", name: "Turquia", dialCode: "90", flag: "\u{1F1F9}\u{1F1F7}" },
550
+ { code: "EG", name: "Egito", dialCode: "20", flag: "\u{1F1EA}\u{1F1EC}" },
551
+ { code: "ZA", name: "\xC1frica do Sul", dialCode: "27", flag: "\u{1F1FF}\u{1F1E6}" },
552
+ { code: "AO", name: "Angola", dialCode: "244", flag: "\u{1F1E6}\u{1F1F4}" },
553
+ { code: "MZ", name: "Mo\xE7ambique", dialCode: "258", flag: "\u{1F1F2}\u{1F1FF}" },
554
+ { code: "CV", name: "Cabo Verde", dialCode: "238", flag: "\u{1F1E8}\u{1F1FB}" }
555
+ ];
556
+ function phoneCountrySearchValue(country) {
557
+ return `${country.name} ${country.code} ${country.dialCode} +${country.dialCode}`;
558
+ }
559
+ function findPhoneCountry(code) {
560
+ if (!code) return void 0;
561
+ const normalized = code.trim().toUpperCase();
562
+ return PHONE_COUNTRIES.find((country) => country.code === normalized);
563
+ }
564
+ function defaultPhoneCountry() {
565
+ return findPhoneCountry(DEFAULT_PHONE_COUNTRY_CODE) ?? PHONE_COUNTRIES[0];
566
+ }
567
+
568
+ // src/phone.ts
569
+ var MAX_NATIONAL_PHONE_DIGITS = 15;
570
+ var VALID_BR_DDDS = /* @__PURE__ */ new Set([
571
+ "11",
572
+ "12",
573
+ "13",
574
+ "14",
575
+ "15",
576
+ "16",
577
+ "17",
578
+ "18",
579
+ "19",
580
+ "21",
581
+ "22",
582
+ "24",
583
+ "27",
584
+ "28",
585
+ "31",
586
+ "32",
587
+ "33",
588
+ "34",
589
+ "35",
590
+ "37",
591
+ "38",
592
+ "41",
593
+ "42",
594
+ "43",
595
+ "44",
596
+ "45",
597
+ "46",
598
+ "47",
599
+ "48",
600
+ "49",
601
+ "51",
602
+ "53",
603
+ "54",
604
+ "55",
605
+ "61",
606
+ "62",
607
+ "63",
608
+ "64",
609
+ "65",
610
+ "66",
611
+ "67",
612
+ "68",
613
+ "69",
614
+ "71",
615
+ "73",
616
+ "74",
617
+ "75",
618
+ "77",
619
+ "79",
620
+ "81",
621
+ "82",
622
+ "83",
623
+ "84",
624
+ "85",
625
+ "86",
626
+ "87",
627
+ "88",
628
+ "89",
629
+ "91",
630
+ "92",
631
+ "93",
632
+ "94",
633
+ "95",
634
+ "96",
635
+ "97",
636
+ "98",
637
+ "99"
638
+ ]);
639
+ var PHONE_INPUT_COUNTRY_CODES = new Set(
640
+ PHONE_COUNTRIES.map((country) => country.code)
641
+ );
642
+ var SORTED_PHONE_INPUT_DIAL_CODES = [
643
+ ...new Set(PHONE_COUNTRIES.map((country) => country.dialCode))
644
+ ].sort((a, b) => b.length - a.length);
645
+ function toLibCountryCode(code) {
646
+ if (code === "UK") return "GB";
647
+ return code;
648
+ }
649
+ function fromLibCountryCode(code) {
650
+ if (code === "GB") return "UK";
651
+ return code;
652
+ }
653
+ function nationalPhoneDigits(value) {
654
+ return String(value ?? "").replace(/\D/g, "");
655
+ }
656
+ function truncateNationalPhoneDigits(digits, max = MAX_NATIONAL_PHONE_DIGITS) {
657
+ return digits.slice(0, max);
658
+ }
659
+ function collapseDuplicatedBrazilianMobileNine(digits) {
660
+ if (digits.length === 14 && digits.startsWith("55")) {
661
+ const national = collapseDuplicatedBrazilianMobileNine(digits.slice(2));
662
+ return national === digits.slice(2) ? digits : `55${national}`;
663
+ }
664
+ if (digits.length !== 12) return digits;
665
+ const ddd = digits.slice(0, 2);
666
+ if (!VALID_BR_DDDS.has(ddd)) return digits;
667
+ if (digits.charAt(2) !== "9") return digits;
668
+ const rest = digits.slice(3);
669
+ if (rest.length !== 9 || rest.charAt(0) !== "9") return digits;
670
+ if (ddd === "55") {
671
+ const subscriberFirst = digits.charAt(4);
672
+ if (subscriberFirst >= "0" && subscriberFirst <= "5") {
673
+ return digits;
674
+ }
675
+ }
676
+ return `${ddd}${rest}`;
677
+ }
678
+ var BR_DIAL_CODE = "55";
679
+ function stripAccidentalDialCodePrefix(numbers, country) {
680
+ const dial = country.dialCode;
681
+ if (!numbers.startsWith(dial) || numbers.length <= dial.length) {
682
+ return numbers;
683
+ }
684
+ const withoutDial = numbers.slice(dial.length);
685
+ if (!withoutDial) return numbers;
686
+ try {
687
+ const parsed = parsePhoneNumber(numbers, toLibCountryCode(country.code));
688
+ if (parsed.nationalNumber === numbers) {
689
+ return numbers;
690
+ }
691
+ if (parsed.countryCallingCode === dial && parsed.nationalNumber === withoutDial) {
692
+ return withoutDial;
693
+ }
694
+ } catch {
695
+ }
696
+ return numbers;
697
+ }
698
+ function prepareNationalDigits(value, country) {
699
+ const raw = nationalPhoneDigits(value);
700
+ const stripped = stripAccidentalDialCodePrefix(raw, country);
701
+ const digits = country.dialCode === BR_DIAL_CODE ? collapseDuplicatedBrazilianMobileNine(stripped) : stripped;
702
+ return truncateNationalPhoneDigits(digits);
703
+ }
704
+ function prepareInternationalDigits(value) {
705
+ const digits = nationalPhoneDigits(value);
706
+ const collapsed = collapseDuplicatedBrazilianMobileNine(digits);
707
+ if (collapsed === digits) return digits;
708
+ try {
709
+ const original = parsePhoneNumber(`+${digits}`);
710
+ if (original.isValid() && original.countryCallingCode !== BR_DIAL_CODE) {
711
+ return digits;
712
+ }
713
+ } catch {
714
+ }
715
+ return collapsed;
716
+ }
717
+ function formatNationalDigits(digits, country) {
718
+ if (!digits) return "";
719
+ const libCode = toLibCountryCode(country.code);
720
+ const formatter = new AsYouType(libCode);
721
+ formatter.input(`+${country.dialCode}${digits}`);
722
+ const national = formatter.getNumber()?.formatNational();
723
+ if (national && nationalPhoneDigits(national) === digits) return national;
724
+ const asTyped = new AsYouType(libCode).input(digits);
725
+ if (nationalPhoneDigits(asTyped) === digits) return asTyped;
726
+ return digits;
727
+ }
728
+ function formatPhoneNational(value, countryCode = DEFAULT_PHONE_COUNTRY_CODE) {
729
+ const country = findPhoneCountry(countryCode) ?? defaultPhoneCountry();
730
+ return formatNationalDigits(prepareNationalDigits(value, country), country);
731
+ }
732
+ function parsePhoneInput(input) {
733
+ const cleaned = String(input ?? "").replace(/[\s\-().]/g, "");
734
+ if (!cleaned) {
735
+ return { ddi: null, national: "", countryCode: null };
736
+ }
737
+ const hasPlus = cleaned.startsWith("+");
738
+ if (hasPlus) {
739
+ try {
740
+ const parsed = parsePhoneNumber(cleaned);
741
+ if (parsed.country) {
742
+ const ourCode = fromLibCountryCode(parsed.country);
743
+ if (PHONE_INPUT_COUNTRY_CODES.has(ourCode)) {
744
+ return {
745
+ ddi: parsed.countryCallingCode,
746
+ national: parsed.nationalNumber,
747
+ countryCode: ourCode
748
+ };
749
+ }
750
+ }
751
+ } catch {
752
+ }
753
+ const digits = cleaned.slice(1);
754
+ for (const ddi of SORTED_PHONE_INPUT_DIAL_CODES) {
755
+ if (digits.startsWith(ddi)) {
756
+ const national = digits.slice(ddi.length);
757
+ const match = PHONE_COUNTRIES.find((c) => c.dialCode === ddi);
758
+ return {
759
+ ddi,
760
+ national,
761
+ countryCode: match?.code ?? null
762
+ };
763
+ }
764
+ }
765
+ return {
766
+ ddi: null,
767
+ national: digits,
768
+ countryCode: null
769
+ };
770
+ }
771
+ return {
772
+ ddi: null,
773
+ national: cleaned.replace(/\D/g, ""),
774
+ countryCode: null
775
+ };
776
+ }
777
+ function preferValidE164(candidate) {
778
+ try {
779
+ const number = parsePhoneNumber(candidate);
780
+ if (number.isValid()) return number.number;
781
+ } catch {
782
+ }
783
+ return candidate;
784
+ }
785
+ function toE164(value, countryCode = DEFAULT_PHONE_COUNTRY_CODE) {
786
+ const trimmed = String(value ?? "").trim();
787
+ if (!trimmed) return "";
788
+ const parsed = parsePhoneInput(trimmed);
789
+ if (parsed.ddi && parsed.national) {
790
+ const ddiCountry = parsed.countryCode && findPhoneCountry(parsed.countryCode) || PHONE_COUNTRIES.find((c) => c.dialCode === parsed.ddi) || defaultPhoneCountry();
791
+ return preferValidE164(
792
+ `+${parsed.ddi}${prepareNationalDigits(parsed.national, ddiCountry)}`
793
+ );
794
+ }
795
+ const country = findPhoneCountry(countryCode) ?? defaultPhoneCountry();
796
+ const national = prepareNationalDigits(parsed.national || trimmed, country);
797
+ if (!national) return "";
798
+ return preferValidE164(`+${country.dialCode}${national}`);
799
+ }
800
+ function isValidPhone(value, countryCode) {
801
+ const cleaned = String(value ?? "").trim();
802
+ if (!cleaned) return false;
803
+ if (cleaned.startsWith("+")) {
804
+ const digits2 = prepareInternationalDigits(cleaned);
805
+ return digits2 ? isValidPhoneNumber(`+${digits2}`) : false;
806
+ }
807
+ const country = countryCode ? findPhoneCountry(countryCode) : defaultPhoneCountry();
808
+ if (!country) return false;
809
+ const digits = prepareNationalDigits(cleaned, country);
810
+ if (!digits) return false;
811
+ if (countryCode) {
812
+ return isValidPhoneNumber(digits, toLibCountryCode(countryCode));
813
+ }
814
+ if (isValidPhoneNumber(`+${digits}`)) return true;
815
+ return isValidPhoneNumber(digits, "BR");
816
+ }
817
+ function remaskPhoneForCountry(nationalOrDraft, countryCode) {
818
+ const country = findPhoneCountry(countryCode) ?? defaultPhoneCountry();
819
+ const digits = truncateNationalPhoneDigits(
820
+ nationalPhoneDigits(nationalOrDraft)
821
+ );
822
+ return {
823
+ display: formatNationalDigits(digits, country),
824
+ e164: digits ? `+${country.dialCode}${digits}` : "",
825
+ country
826
+ };
827
+ }
828
+
482
829
  // src/resolve-site-id.ts
483
830
  var PREVIEW_HOST_SUFFIXES = [".vusercontent.net"];
484
831
  function isStudioPreviewHost(host) {
@@ -612,10 +959,15 @@ function normalizeContact(input) {
612
959
  code: "invalid_contact"
613
960
  });
614
961
  }
615
- if (phone && (phone.length < 5 || phone.length > 40)) {
616
- throw new LeadSubmitError("Garagem SDK: phone is invalid.", {
617
- code: "invalid_contact"
618
- });
962
+ let normalizedPhone;
963
+ if (phone) {
964
+ const e164 = toE164(phone);
965
+ if (!e164 || !isValidPhone(e164) || e164.length > 40) {
966
+ throw new LeadSubmitError("Garagem SDK: phone is invalid.", {
967
+ code: "invalid_contact"
968
+ });
969
+ }
970
+ normalizedPhone = e164;
619
971
  }
620
972
  const message = input.message?.trim() || void 0;
621
973
  if (message && message.length > MESSAGE_MAX) {
@@ -626,10 +978,19 @@ function normalizeContact(input) {
626
978
  return {
627
979
  name,
628
980
  ...email ? { email } : {},
629
- ...phone ? { phone } : {},
981
+ ...normalizedPhone ? { phone: normalizedPhone } : {},
630
982
  ...message ? { message } : {}
631
983
  };
632
984
  }
985
+ function normalizeSdkBusinessType(value) {
986
+ if (!value) return void 0;
987
+ const normalized = value.trim().toLowerCase();
988
+ if (normalized === "rent" || normalized === "rental" || normalized === "aluguel") {
989
+ return "rent";
990
+ }
991
+ if (normalized === "sale" || normalized === "venda") return "sale";
992
+ return void 0;
993
+ }
633
994
  async function postSiteLead(input) {
634
995
  const siteId = await resolveLeadSiteId(input);
635
996
  const base = normalizeBaseUrl(input.baseUrl);
@@ -677,13 +1038,16 @@ async function postSiteLead(input) {
677
1038
  }
678
1039
  function leadPostContext(input) {
679
1040
  assertListingId(input.listingId);
1041
+ const businessType = normalizeSdkBusinessType(input.businessType) ?? normalizeSdkBusinessType(input.listingType);
680
1042
  return {
681
1043
  listingId: input.listingId.trim(),
682
1044
  contact: normalizeContact(input),
683
1045
  extras: {
684
1046
  ...input.visitorId ? { visitorId: input.visitorId } : {},
685
1047
  ...input.brokerRef ? { brokerRef: input.brokerRef } : {},
686
- ...input.referrer ? { referrer: input.referrer } : {}
1048
+ ...input.referrer ? { referrer: input.referrer } : {},
1049
+ ...businessType ? { businessType } : {},
1050
+ ...input.listingType ? { listingType: input.listingType } : {}
687
1051
  }
688
1052
  };
689
1053
  }
@@ -1121,7 +1485,7 @@ function toListingCardModel(listing) {
1121
1485
  businessLabel: listingBusinessLabel(listing.businessType),
1122
1486
  priceVisibility: listing.priceVisibility,
1123
1487
  price: listing.price,
1124
- priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price),
1488
+ priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price, "pt-BR", listing.currency ?? "BRL"),
1125
1489
  pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
1126
1490
  locationLabel: listingLocationLabel(listing.location || {}),
1127
1491
  propertyType: listing.property?.type ?? null,
@@ -2045,7 +2409,11 @@ function listingValues(listing) {
2045
2409
  {
2046
2410
  key: "price",
2047
2411
  label: "Pre\xE7o",
2048
- text: listing.priceVisibility === "private" ? "Sob consulta" : formatListingPrice(listing.price)
2412
+ text: listing.priceVisibility === "private" ? "Sob consulta" : formatListingPrice(
2413
+ listing.price,
2414
+ "pt-BR",
2415
+ listing.currency ?? "BRL"
2416
+ )
2049
2417
  }
2050
2418
  ];
2051
2419
  const condoFee = positiveCount(listing.property?.condoFee);
@@ -2280,6 +2648,28 @@ var STUDIO_SDK_CONTRACT = {
2280
2648
  "listingBusinessLabel",
2281
2649
  "formatListingPrice"
2282
2650
  ],
2651
+ /**
2652
+ * Prompt-safe phone helpers on `minNpmVersion`. Empty until a published
2653
+ * tarball exports them and this pin bumps — then move names here from
2654
+ * `unpublishedPhoneExports`.
2655
+ */
2656
+ phoneExports: [],
2657
+ /**
2658
+ * Headless phone mask helpers in git / newer tarballs but not on
2659
+ * `minNpmVersion` (0.4.12). Prompts, completeness, and repair text must
2660
+ * not mention these until the pin bumps — v0 installs the pin and the
2661
+ * ESM loader throws on missing named exports.
2662
+ */
2663
+ unpublishedPhoneExports: [
2664
+ "PHONE_COUNTRIES",
2665
+ "formatPhoneNational",
2666
+ "toE164",
2667
+ "isValidPhone",
2668
+ "parsePhoneInput",
2669
+ "phoneCountrySearchValue",
2670
+ "findPhoneCountry",
2671
+ "remaskPhoneForCountry"
2672
+ ],
2283
2673
  amenityExports: ["listingAmenityGroups"],
2284
2674
  /**
2285
2675
  * Names already on the pinned npm tarball (`minNpmVersion` / 0.4.12) —
@@ -2333,7 +2723,7 @@ ${studioSiteWidthCss()}
2333
2723
  Every page section is two layers: (1) surface \u2014 \`section\` / header / footer \`${STUDIO_SITE_LAYOUT.surfaceClassName}\`, background to the viewport edges, no max-width class and no horizontal padding; (2) wrapper \u2014 one child \`${STUDIO_SITE_LAYOUT.wrapperClassName}\`. Header and footer use that same inner wrapper. Components fill the wrapper (\`w-full\`). Never nest a second max-width container with extra horizontal padding. ${studioSearchLandmarkInstruction()} Do not use \`ml-auto\` on the content wrapper. To make the site narrower or wider, change ONLY \`--site-max-width\` in \`app/globals.css\` (allowed: ${scale}; default ${STUDIO_SITE_LAYOUT.maxWidthRem}). Do not edit wrapper class names or horizontal padding. Full-bleed image surfaces (home hero, listing gallery) stay flush with the header \u2014 do not add vertical padding there.`;
2334
2724
  }
2335
2725
  function studioSearchLandmarkInstruction() {
2336
- return `Search at \`/imoveis\` (hard rule). The page landmark is \`<main className="${STUDIO_SITE_LAYOUT.searchMainClassName}">\` with one child \`${STUDIO_SITE_LAYOUT.wrapperClassName}\`. Wire the catalog with \`usePublicSearch\` from \`${STUDIO_SDK_PACKAGE}/react\` inside \`<Suspense>\` whose fallback is the site listing-card-skeleton module. Do not wrap the search UI in \`<section>\` or a second max-width. The page owns the SEO heading as \`<div data-slot="search-heading">\`: count \`<span data-slot="search-heading-count">\` FIRST, then \`<h1 data-slot="search-heading-title">\` \u2014 never put the count inside the H1 and never put the h1 first. \`pt-4 pb-12\` is the default on that search \`<main>\` \u2014 change those values if the design needs it. Flush search (glued to the header) is allowed only with \`${STUDIO_SITE_LAYOUT.searchFlushMarker}\` on that \`<main>\`. Never add that vertical padding to home heroes or listing galleries.`;
2726
+ return `Search at \`/imoveis\` (hard rule). The page landmark is \`<main className="${STUDIO_SITE_LAYOUT.searchMainClassName}">\` with one child \`${STUDIO_SITE_LAYOUT.wrapperClassName}\`. The server page awaits the catalog and renders it with \`usePublicSearch\` from \`${STUDIO_SDK_PACKAGE}/react\` (\`search\` from the page searchParams, plus \`initial\`). Do not wrap that UI in \`<Suspense>\` and do not add a route \`loading\` file. A suspended page is streamed into a hidden node and stays invisible until JavaScript runs. Do not wrap the search UI in \`<section>\` or a second max-width. The page owns the SEO heading as \`<div data-slot="search-heading">\`: count \`<span data-slot="search-heading-count">\` FIRST, then \`<h1 data-slot="search-heading-title">\` \u2014 never put the count inside the H1 and never put the h1 first. \`pt-4 pb-12\` is the default on that search \`<main>\` \u2014 change those values if the design needs it. Flush search (glued to the header) is allowed only with \`${STUDIO_SITE_LAYOUT.searchFlushMarker}\` on that \`<main>\`. Never add that vertical padding to home heroes or listing galleries.`;
2337
2727
  }
2338
2728
  var REACT_SDK_NAMED_IMPORT_RE = /(?:^|[\n;])\s*import\s+(?!type\b)(?:type\s+)?\{([^}]+)\}\s+from\s+['"]@garagem-ai\/site-sdk\/react['"]/g;
2339
2729
  var SHOWCASE_LEADS_POST_URL_RE = /\/api\/sites\/[^\s"']*\/leads(?!\/ui)/;
@@ -2396,11 +2786,11 @@ function studioSdkPinInstruction() {
2396
2786
  }
2397
2787
  function studioLeadInstruction() {
2398
2788
  const names = STUDIO_SDK_CONTRACT.leadExports.join(", ");
2399
- return `Listing-detail visit/contact leads: import ${names} from \`${STUDIO_SDK_PACKAGE}\` (the main package, not \`/react\`). Call \`submitVisitLead\` / \`submitContactLead\` \u2014 never concatenate a leads webhook URL and never POST the Showcase demo leads route.`;
2789
+ return `Listing-detail visit/contact leads: import ${names} from \`${STUDIO_SDK_PACKAGE}\` (the main package, not \`/react\`). Call \`submitVisitLead\` / \`submitContactLead\` \u2014 never concatenate a leads webhook URL and never POST the Showcase demo leads route. Phone fields use a national mask with a country picker and submit E.164 \u2014 do not invent a second mask and do not import \`@garagem/ui\` PhoneInput.`;
2400
2790
  }
2401
2791
  function studioListingCardInstruction() {
2402
2792
  const names = STUDIO_SDK_CONTRACT.listingCardExports.join(", ");
2403
- return `Listing card (site-wide). WRITE \`components/garagem/listing-card.tsx\` \u2014 one module for home, search results, and similar listings. Do not invent a second card. From \`${STUDIO_SDK_PACKAGE}\` import ${names}. \`const model = toListingCardModel(listing)\`. href is \`model.href\` / \`listingPublicPath(listing)\` \u2014 never \`listing.id\` or \`property.id\`. Skip the card or omit the link when href is empty (no \`href=""\`, no \`href="#"\`). Must show title (\`model.title\`) and price (\`model.priceLabel\` \u2014 \u201CSob consulta\u201D when private; \`model.pricePeriod\` \u201C/m\xEAs\u201D when present, omit when null). Photo: \`model.coverSrc\` as img \`src\`, alt \`model.coverAlt\`; skip the img when cover is missing; an empty-photo block is allowed; never Unsplash, \`/placeholder.svg\`, or invented \`?query=\` images. Show when present, omit the line when missing: \`locationLabel\` (else \`propertyType\`), \`listingBusinessLabel\` / \`model.businessLabel\`, bedrooms, bathrooms, parkingSpaces, area via \`formatAreaM2\`. Never interpolate the listing object as a React child. Design is free (grid vs carousel vs mosaic; radius is site \`--radius\`). WRITE \`components/garagem/listing-card-skeleton.tsx\` for the search \`<Suspense>\` fallback \u2014 it should suggest the card surface, never the text \u201CCarregando im\xF3veis\u2026\u201D. Do not \`if (search.loading) return\` that skeleton inside the search client.`;
2793
+ return `Listing card (site-wide). WRITE \`components/garagem/listing-card.tsx\` \u2014 one module for home, search results, and similar listings. Do not invent a second card. From \`${STUDIO_SDK_PACKAGE}\` import ${names}. \`const model = toListingCardModel(listing)\`. href is \`model.href\` / \`listingPublicPath(listing)\` \u2014 never \`listing.id\` or \`property.id\`. Skip the card or omit the link when href is empty (no \`href=""\`, no \`href="#"\`). Must show title (\`model.title\`) and price (\`model.priceLabel\` \u2014 \u201CSob consulta\u201D when private; \`model.pricePeriod\` \u201C/m\xEAs\u201D when present, omit when null). Photo: \`model.coverSrc\` as img \`src\`, alt \`model.coverAlt\`; skip the img when cover is missing; an empty-photo block is allowed; never Unsplash, \`/placeholder.svg\`, or invented \`?query=\` images. Show when present, omit the line when missing: \`locationLabel\` (else \`propertyType\`), \`listingBusinessLabel\` / \`model.businessLabel\`, bedrooms, bathrooms, parkingSpaces, area via \`formatAreaM2\`. Never interpolate the listing object as a React child. Design is free (grid vs carousel vs mosaic; radius is site \`--radius\`). WRITE \`components/garagem/listing-card-skeleton.tsx\` only for a slot whose content is still unknown \u2014 never as a \`<Suspense>\` fallback that replaces the catalog, and never the text \u201CCarregando im\xF3veis\u2026\u201D. Do not \`if (search.loading) return\` that skeleton inside the search client.`;
2404
2794
  }
2405
2795
  function studioListingDetailInstruction() {
2406
2796
  const names = STUDIO_SDK_CONTRACT.listingDetailExports.join(", ");
@@ -2412,7 +2802,7 @@ function studioAmenityInstruction() {
2412
2802
  function studioSearchInstruction() {
2413
2803
  const reactNames = STUDIO_SDK_CONTRACT.reactExports.join(", ");
2414
2804
  const libNames = STUDIO_SDK_CONTRACT.searchExports.join(", ");
2415
- return `Search: import ${reactNames} from \`${STUDIO_SDK_PACKAGE}/react\`. From \`${STUDIO_SDK_PACKAGE}\` import ${libNames}. Call \`const search = usePublicSearch({ siteId, baseUrl: GARAGEM_API_BASE })\` in a client component inside \`<Suspense>\` (\`useSearchParams\`). Compose the page UI in the app \u2014 do not paste a canonical search TSX. Required chrome (design is free; omit none): query (\`qDraft\` / \`setQDraft\` / form \`preventDefault\` + \`submitQuery\`), heading (count span FIRST then h1 from \`searchResultsHeading(search.pathFilters, search.schema?.dictionary, search.locationNames)\` \u2014 never \`searchResultsHeading({})\`), toolbar (\`toolbarFilterIds\` + \`applyFilter\`; range \u201CAtualizar\u201D on that toolbar item only) vs sheet (\`visibleSearchFilters\` extras, \`stageFilter\`, one footer \`applyStaged\`), sort (\`searchSortOptions\` + \`setSort\`; first option id is \`""\` / \u201CMais relevantes\u201D \u2014 map **only** that empty id to Select sentinel \`"relevancia"\` (\`opt.id || "relevancia"\`), never \`SelectItem value=""\` and never give \u201CMais recentes\u201D (\`id: "recentes"\`, \`?ordenar=recentes\`) that sentinel; on change \`setSort(id === "relevancia" ? "" : id)\` so recentes stays recentes. Closed trigger shows the option \`.label\`, never \`{search.applied.sort}\`), grid (\`listings.map\` + the site listing-card module; listing-card-skeleton is only the Suspense fallback; do not \`throw\` in that chrome), pagination (\`paginationPages\` + \`hrefWithExplicitPage\`). Never interpolate \`schema\`, \`pathFilters\`, or a filter object as a React child. \`queryListings\` key is \`params\`. The URL is the document. Count text is \`{search.total}\` only. Heading is one row; font size lives on the container and the span and h1 use \`font-size: inherit\`. Sort trigger shows the option label (\u201CMais relevantes\u201D when \`ordenar\` is absent), chevron at the end, same height as the toolbar controls. Toolbar ranges open a Popover form (not DropdownMenu \u2014 Menu typeahead swallows digit keys) whose submit calls \`applyFilter\`; the popup clips and the two inputs stay inside (\`min-w-0\`, no \`w-64\`). Reset min/max drafts when the popover opens and when the applied path range changes. The sheet omits toolbar ids (price, bedrooms) so Pre\xE7o is never a heading without inputs. Sheet DialogContent uses \`h-[min(640px,85dvh)]\` (not max-h alone) so the body ScrollArea can move. Tipo de im\xF3vel, caracter\xEDsticas and comodidades each use a nested ScrollArea with \`h-56 overflow-hidden\` (viewport \`h-full\`). Area is two inputs in schema order with no \u201CAplicar\u201D; the footer stages then applyStaged. Never read \`staged[filter.id]\` \u2014 path keys are \`bedrooms\` / \`listingType\` / \`bathrooms\`. Bedrooms Select reads \`pathFilters.bedrooms\` so \`/imoveis/4-quartos\` checks \`"4"\` and shows the same trigger dot as price. Bathrooms and parking pressed state uses \`pathFilterHasOption\`. Limpar keeps location plus toolbar price and bedrooms via \`clearStagedPathFilters\` and \`toolbarFilterIds\`; do not call \`clearStaged\` for that button. It enables only when staged has a path filter other than location and those kept toolbar ids. Each multi-select \`stageFilter\` value is one option id, never a concatenated slug; \`checked\` uses \`pathFilterHasOption\`. Listing type does not pass the clicked id: no path value shows every checkbox checked, unchecking one stages the other option's id, and the last box stays checked. Price inputs use formatGroupedInteger. The closed price and bedrooms triggers keep the filter label plus a dot when set \u2014 never the literal range. Empty price calls applyFilter(id, undefined); never send 0 or 1000000000. Area is a plain integer (not that mask). The results button stageFilter property_area_total with both drafts, then applyStaged. Never send 0 or 100000. Count buttons pass the option id (\`"2"\`), never the label \`"2+"\`. Property type, features, and amenities render in pt-BR label order. Do not set \`[data-slot="search-sort"] { flex-direction: column }\` in a \`<style>\` tag; that selector is row so the chevron sits beside the label. Empty copy: ${JSON.stringify(SEARCH_EMPTY_COPY)}`;
2805
+ return `Search: import ${reactNames} from \`${STUDIO_SDK_PACKAGE}/react\`. From \`${STUDIO_SDK_PACKAGE}\` import ${libNames}. Prefetch \`getSearchUi\` + \`queryListings\` on the server page. \`const search = usePublicSearch({ siteId, baseUrl: GARAGEM_API_BASE, search: searchFromServer, initial })\` where \`searchFromServer\` is \`new URLSearchParams(await searchParams).toString()\` \u2014 never shorthand \`{ search }\` beside \`const search =\` (temporal dead zone). Do not wrap this UI in \`<Suspense>\` and do not add a route \`loading\` file \u2014 heading and cards are ordinary elements in the document, visible with JavaScript off. Compose the page UI in the app \u2014 do not paste a canonical search TSX. Required chrome (design is free; omit none): query (\`qDraft\` / \`setQDraft\` / form \`preventDefault\` + \`submitQuery\`), heading (count span FIRST then h1 from \`searchResultsHeading(search.pathFilters, search.schema?.dictionary, search.locationNames)\` \u2014 never \`searchResultsHeading({})\`), toolbar (\`toolbarFilterIds\` + \`applyFilter\`; range \u201CAtualizar\u201D on that toolbar item only) vs sheet (\`visibleSearchFilters\` extras, \`stageFilter\`, one footer \`applyStaged\`), sort (\`searchSortOptions\` + \`setSort\`; first option id is \`""\` / \u201CMais relevantes\u201D \u2014 map **only** that empty id to Select sentinel \`"relevancia"\` (\`opt.id || "relevancia"\`), never \`SelectItem value=""\` and never give \u201CMais recentes\u201D (\`id: "recentes"\`, \`?ordenar=recentes\`) that sentinel; on change \`setSort(id === "relevancia" ? "" : id)\` so recentes stays recentes. Closed trigger shows the option \`.label\`, never \`{search.applied.sort}\`), grid (\`listings.map\` + the site listing-card module; listing-card-skeleton only for a slot whose content is still unknown, never as a Suspense fallback; do not \`throw\` in that chrome), pagination (\`paginationPages\` + \`hrefWithExplicitPage\`). Never interpolate \`schema\`, \`pathFilters\`, or a filter object as a React child. \`queryListings\` key is \`params\`. The URL is the document. Count text is \`{search.total}\` only. Heading is one row; font size lives on the container and the span and h1 use \`font-size: inherit\`. Sort trigger shows the option label (\u201CMais relevantes\u201D when \`ordenar\` is absent), chevron at the end, same height as the toolbar controls. Toolbar ranges open a Popover form (not DropdownMenu \u2014 Menu typeahead swallows digit keys) whose submit calls \`applyFilter\`; the popup clips and the two inputs stay inside (\`min-w-0\`, no \`w-64\`). Reset min/max drafts when the popover opens and when the applied path range changes. The sheet omits toolbar ids (price, bedrooms) so Pre\xE7o is never a heading without inputs. Sheet DialogContent uses \`h-[min(640px,85dvh)]\` (not max-h alone) so the body ScrollArea can move. Tipo de im\xF3vel, caracter\xEDsticas and comodidades each use a nested ScrollArea with \`h-56 overflow-hidden\` (viewport \`h-full\`). Area is two inputs in schema order with no \u201CAplicar\u201D; the footer stages then applyStaged. Never read \`staged[filter.id]\` \u2014 path keys are \`bedrooms\` / \`listingType\` / \`bathrooms\`. Bedrooms Select reads \`pathFilters.bedrooms\` so \`/imoveis/4-quartos\` checks \`"4"\` and shows the same trigger dot as price. Bathrooms and parking pressed state uses \`pathFilterHasOption\`. Limpar keeps location plus toolbar price and bedrooms via \`clearStagedPathFilters\` and \`toolbarFilterIds\`; do not call \`clearStaged\` for that button. It enables only when staged has a path filter other than location and those kept toolbar ids. Each multi-select \`stageFilter\` value is one option id, never a concatenated slug; \`checked\` uses \`pathFilterHasOption\`. Listing type does not pass the clicked id: no path value shows every checkbox checked, unchecking one stages the other option's id, and the last box stays checked. Price inputs use formatGroupedInteger. The closed price and bedrooms triggers keep the filter label plus a dot when set \u2014 never the literal range. Empty price calls applyFilter(id, undefined); never send 0 or 1000000000. Area is a plain integer (not that mask). The results button stageFilter property_area_total with both drafts, then applyStaged. Never send 0 or 100000. Count buttons pass the option id (\`"2"\`), never the label \`"2+"\`. Property type, features, and amenities render in pt-BR label order. Do not set \`[data-slot="search-sort"] { flex-direction: column }\` in a \`<style>\` tag; that selector is row so the chevron sits beside the label. Empty copy: ${JSON.stringify(SEARCH_EMPTY_COPY)}`;
2416
2806
  }
2417
2807
  function studioChromeInstruction() {
2418
2808
  return `Card, skeleton, and search chrome markup are app-owned. Never \`import "${STUDIO_SDK_CONTRACT.forbiddenImports[0]}"\` \u2014 v0 preview cannot load npm CSS. Do not mount an SDK stylesheet. Theme with site tokens and \`--radius\` in \`app/globals.css\`.`;
@@ -2435,6 +2825,11 @@ function studioCodegenContractViolations(text) {
2435
2825
  violations.push(name);
2436
2826
  }
2437
2827
  }
2828
+ for (const name of STUDIO_SDK_CONTRACT.unpublishedPhoneExports) {
2829
+ if (mentionsExportName(text, name) && !violations.includes(name)) {
2830
+ violations.push(name);
2831
+ }
2832
+ }
2438
2833
  const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
2439
2834
  const available = reactExportsAvailableAt(pin);
2440
2835
  for (const name of parseReactSdkNamedImports(text)) {
@@ -2608,11 +3003,14 @@ function createGaragemClient(options = {}) {
2608
3003
  }
2609
3004
  export {
2610
3005
  AMENITY_FALLBACK_LABELS,
3006
+ DEFAULT_PHONE_COUNTRY_CODE,
2611
3007
  FORBIDDEN_SEARCH_QUERY_KEYS,
2612
3008
  GaragemSdkError,
2613
3009
  LISTING_AMENITY_TITLES,
2614
3010
  LISTING_DESCRIPTION_CLAMP,
2615
3011
  LeadSubmitError,
3012
+ MAX_NATIONAL_PHONE_DIGITS,
3013
+ PHONE_COUNTRIES,
2616
3014
  SEARCH_EMPTY_COPY,
2617
3015
  SEARCH_SORT_RELEVANCE,
2618
3016
  STUDIO_DEFAULT_VISIT_SCHEDULE,
@@ -2626,18 +3024,22 @@ export {
2626
3024
  canonicalizeSearchHref,
2627
3025
  clearStagedPathFilters,
2628
3026
  coerceNpmVersion,
3027
+ collapseDuplicatedBrazilianMobileNine,
2629
3028
  compareSemver,
2630
3029
  composeSearchPublicHref2 as composeSearchPublicHref,
2631
3030
  composeSearchPublicPath2 as composeSearchPublicPath,
2632
3031
  countFacetChoices,
2633
3032
  countOptionLabel,
2634
3033
  createGaragemClient,
3034
+ defaultPhoneCountry,
2635
3035
  displayPathLocation,
2636
3036
  expandVisitSchedule,
2637
3037
  expandVisitTimeSlots,
3038
+ findPhoneCountry,
2638
3039
  formatAreaM2,
2639
3040
  formatGroupedInteger,
2640
3041
  formatListingPrice,
3042
+ formatPhoneNational,
2641
3043
  getCmsCollection,
2642
3044
  getCmsCollections,
2643
3045
  getCmsEntries,
@@ -2654,6 +3056,7 @@ export {
2654
3056
  hrefWithExplicitPage,
2655
3057
  isListingDetailPath,
2656
3058
  isStudioPreviewHost,
3059
+ isValidPhone,
2657
3060
  isVisitSlotAllowed,
2658
3061
  labelAmenities,
2659
3062
  listingAmenityGroups,
@@ -2671,22 +3074,26 @@ export {
2671
3074
  listingPublicPath,
2672
3075
  listingValues,
2673
3076
  mergeAppliedSearchQueryIntoSearch2 as mergeAppliedSearchQueryIntoSearch,
3077
+ nationalPhoneDigits,
2674
3078
  normalizeVisitDate,
2675
3079
  normalizeVisitTime,
2676
3080
  paginationPages,
2677
3081
  parseAppliedSearchQuery2 as parseAppliedSearchQuery,
2678
3082
  parseGroupedInteger,
3083
+ parsePhoneInput,
2679
3084
  parseReactSdkNamedImports,
2680
3085
  parseSearchPublicPath2 as parseSearchPublicPath,
2681
3086
  pathFilterHasOption,
2682
3087
  pathFilterValue,
2683
3088
  pathFiltersToQueryFilters,
2684
3089
  pathLocationToFilterInput,
3090
+ phoneCountrySearchValue,
2685
3091
  publicSearchHref,
2686
3092
  queryListings,
2687
3093
  rangeDraftFromPath,
2688
3094
  readPublicSearch,
2689
3095
  reduceAppliedSearchQuery2 as reduceAppliedSearchQuery,
3096
+ remaskPhoneForCountry,
2690
3097
  resolvePublicSiteId,
2691
3098
  searchChromeModel,
2692
3099
  searchHrefUsesLegacyFilterQuery,
@@ -2709,8 +3116,10 @@ export {
2709
3116
  studioSiteWidthCss,
2710
3117
  submitContactLead,
2711
3118
  submitVisitLead,
3119
+ toE164,
2712
3120
  toListingCardModel,
2713
3121
  toolbarFilterIds,
3122
+ truncateNationalPhoneDigits,
2714
3123
  unavailableReactImports,
2715
3124
  visibleSearchFilters
2716
3125
  };