@garagem-ai/site-sdk 0.9.1 → 0.10.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.d.mts +114 -2
- package/dist/index.d.ts +114 -2
- package/dist/index.js +410 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +398 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +23 -0
- package/src/leads.ts +47 -3
- package/src/seller-lead.ts +428 -0
- package/src/studio-contract.ts +42 -0
package/dist/index.mjs
CHANGED
|
@@ -58,13 +58,13 @@ function finiteNonNegative(value) {
|
|
|
58
58
|
}
|
|
59
59
|
return null;
|
|
60
60
|
}
|
|
61
|
-
function parseSdkErrorBody(
|
|
62
|
-
const raw =
|
|
63
|
-
if (!
|
|
61
|
+
function parseSdkErrorBody(text2) {
|
|
62
|
+
const raw = text2 ? text2.slice(0, 200) : "";
|
|
63
|
+
if (!text2) {
|
|
64
64
|
return { reason: null, retryAfterSeconds: null, summary: "" };
|
|
65
65
|
}
|
|
66
66
|
try {
|
|
67
|
-
const body = JSON.parse(
|
|
67
|
+
const body = JSON.parse(text2);
|
|
68
68
|
if (!body || typeof body !== "object") {
|
|
69
69
|
return { reason: null, retryAfterSeconds: null, summary: raw };
|
|
70
70
|
}
|
|
@@ -160,8 +160,8 @@ var GaragemSdkError = class extends Error {
|
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
162
|
async function readGaragemSdkError(response, url) {
|
|
163
|
-
const
|
|
164
|
-
const parsed = parseSdkErrorBody(
|
|
163
|
+
const text2 = await response.text().catch(() => "");
|
|
164
|
+
const parsed = parseSdkErrorBody(text2);
|
|
165
165
|
const retryAfter = response.status === 429 ? retryAfterFromResponse(response, parsed.retryAfterSeconds) : parsed.retryAfterSeconds;
|
|
166
166
|
const detail = parsed.summary;
|
|
167
167
|
return new GaragemSdkError(
|
|
@@ -1018,7 +1018,15 @@ var LeadSubmitError = class extends Error {
|
|
|
1018
1018
|
};
|
|
1019
1019
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1020
1020
|
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
1021
|
+
var NAME_RE = /^[^\d\s]{2,}.*$/;
|
|
1021
1022
|
var MESSAGE_MAX = 2e3;
|
|
1023
|
+
function isValidEmail(value) {
|
|
1024
|
+
return EMAIL_RE.test(value.trim());
|
|
1025
|
+
}
|
|
1026
|
+
function isValidName(value) {
|
|
1027
|
+
const name = value.trim();
|
|
1028
|
+
return name.length <= 200 && NAME_RE.test(name);
|
|
1029
|
+
}
|
|
1022
1030
|
var CONTACT_FIELDS = [
|
|
1023
1031
|
{ id: "name", required: true },
|
|
1024
1032
|
{ id: "email", required: false },
|
|
@@ -1118,6 +1126,27 @@ function normalizeSdkBusinessType(value) {
|
|
|
1118
1126
|
if (normalized === "sale" || normalized === "venda") return "sale";
|
|
1119
1127
|
return void 0;
|
|
1120
1128
|
}
|
|
1129
|
+
var ADDRESS_REJECTIONS = /* @__PURE__ */ new Set([
|
|
1130
|
+
"missing_postal_code",
|
|
1131
|
+
"ungeocoded_address"
|
|
1132
|
+
]);
|
|
1133
|
+
async function rejectedLeadError(response) {
|
|
1134
|
+
if (response.status !== 400 && response.status !== 409) return null;
|
|
1135
|
+
const parsed = parseSdkErrorBody(await response.text().catch(() => ""));
|
|
1136
|
+
if (response.status === 409 || parsed.reason === "duplicate_property") {
|
|
1137
|
+
return new LeadSubmitError(
|
|
1138
|
+
parsed.summary || "Garagem SDK: property already registered.",
|
|
1139
|
+
{ code: "duplicate_property", status: response.status }
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
if (parsed.reason && ADDRESS_REJECTIONS.has(parsed.reason)) {
|
|
1143
|
+
return new LeadSubmitError(`Garagem SDK: ${parsed.reason}.`, {
|
|
1144
|
+
code: "invalid_address",
|
|
1145
|
+
status: 400
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
return null;
|
|
1149
|
+
}
|
|
1121
1150
|
async function postSiteLead(input) {
|
|
1122
1151
|
const siteId = await resolveLeadSiteId(input);
|
|
1123
1152
|
const base = normalizeBaseUrl(input.baseUrl);
|
|
@@ -1152,8 +1181,8 @@ async function postSiteLead(input) {
|
|
|
1152
1181
|
});
|
|
1153
1182
|
}
|
|
1154
1183
|
if (response.status === 429) {
|
|
1155
|
-
const
|
|
1156
|
-
const parsed = parseSdkErrorBody(
|
|
1184
|
+
const text2 = await response.text().catch(() => "");
|
|
1185
|
+
const parsed = parseSdkErrorBody(text2);
|
|
1157
1186
|
const retryAfter = retryAfterFromResponse(
|
|
1158
1187
|
response,
|
|
1159
1188
|
parsed.retryAfterSeconds
|
|
@@ -1170,6 +1199,8 @@ async function postSiteLead(input) {
|
|
|
1170
1199
|
status: 404
|
|
1171
1200
|
});
|
|
1172
1201
|
}
|
|
1202
|
+
const rejected = await rejectedLeadError(response);
|
|
1203
|
+
if (rejected) throw rejected;
|
|
1173
1204
|
throw new LeadSubmitError(
|
|
1174
1205
|
`Garagem SDK: lead submit failed (${response.status}).`,
|
|
1175
1206
|
{ code: "http", status: response.status }
|
|
@@ -1236,6 +1267,278 @@ async function submitContactLead(input) {
|
|
|
1236
1267
|
});
|
|
1237
1268
|
}
|
|
1238
1269
|
|
|
1270
|
+
// src/seller-lead.ts
|
|
1271
|
+
function text(value) {
|
|
1272
|
+
return typeof value === "string" ? value.trim() : "";
|
|
1273
|
+
}
|
|
1274
|
+
function inRange(value, min, max) {
|
|
1275
|
+
return typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
|
|
1276
|
+
}
|
|
1277
|
+
function sellerAddressErrors(address) {
|
|
1278
|
+
const errors = {};
|
|
1279
|
+
if (!address || !text(address.fullAddress)) {
|
|
1280
|
+
errors.fullAddress = "Informe o endere\xE7o do im\xF3vel.";
|
|
1281
|
+
} else if (!inRange(address.latitude, -90, 90) || !inRange(address.longitude, -180, 180) || !text(address.street) || !text(address.city) || !text(address.neighborhood) || !/^[A-Za-z]{2}$/.test(text(address.state))) {
|
|
1282
|
+
errors.fullAddress = "Selecione o endere\xE7o em uma das sugest\xF5es.";
|
|
1283
|
+
}
|
|
1284
|
+
if (!address?.noNumber && !text(address?.number)) {
|
|
1285
|
+
errors.number = "Informe o n\xFAmero ou marque sem n\xFAmero.";
|
|
1286
|
+
}
|
|
1287
|
+
if (!address?.noBlocoTorre && !text(address?.blocoTorre)) {
|
|
1288
|
+
errors.blocoTorre = "Informe o bloco/torre ou marque que n\xE3o tem.";
|
|
1289
|
+
}
|
|
1290
|
+
if (!address?.noUnidade && !text(address?.unidade)) {
|
|
1291
|
+
errors.unidade = "Informe a unidade ou marque que n\xE3o tem.";
|
|
1292
|
+
}
|
|
1293
|
+
if (text(address?.postalCode).replace(/\D/g, "").length !== 8) {
|
|
1294
|
+
errors.postalCode = "Informe um CEP com 8 d\xEDgitos.";
|
|
1295
|
+
}
|
|
1296
|
+
return errors;
|
|
1297
|
+
}
|
|
1298
|
+
var SELLER_LEAD_PHOTO_MAX_BYTES = 10 * 1024 * 1024;
|
|
1299
|
+
var SELLER_LEAD_PHOTO_MAX_COUNT = 30;
|
|
1300
|
+
var SELLER_LEAD_PHOTO_TYPES = [
|
|
1301
|
+
"image/jpeg",
|
|
1302
|
+
"image/png",
|
|
1303
|
+
"image/webp"
|
|
1304
|
+
];
|
|
1305
|
+
async function uploadSellerLeadPhoto(input) {
|
|
1306
|
+
const { file } = input;
|
|
1307
|
+
if (!SELLER_LEAD_PHOTO_TYPES.includes(file.type)) {
|
|
1308
|
+
throw new LeadSubmitError("Garagem SDK: photo must be JPG, PNG or WEBP.", {
|
|
1309
|
+
code: "invalid_photo"
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
if (file.size <= 0) {
|
|
1313
|
+
throw new LeadSubmitError("Garagem SDK: photo is empty.", {
|
|
1314
|
+
code: "invalid_photo"
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
if (file.size > SELLER_LEAD_PHOTO_MAX_BYTES) {
|
|
1318
|
+
throw new LeadSubmitError("Garagem SDK: photo is larger than 10MB.", {
|
|
1319
|
+
code: "invalid_photo"
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
const siteId = await resolveLeadSiteId(input);
|
|
1323
|
+
const url = `${normalizeBaseUrl(input.baseUrl)}/api/webhooks/sites/${encodeURIComponent(siteId)}/photos`;
|
|
1324
|
+
const form = new FormData();
|
|
1325
|
+
form.append("file", file);
|
|
1326
|
+
if (file.name) form.append("fileName", file.name);
|
|
1327
|
+
let response;
|
|
1328
|
+
try {
|
|
1329
|
+
response = await (input.fetch ?? fetch)(url, {
|
|
1330
|
+
method: "POST",
|
|
1331
|
+
body: form
|
|
1332
|
+
});
|
|
1333
|
+
} catch (error) {
|
|
1334
|
+
throw new LeadSubmitError(
|
|
1335
|
+
error instanceof Error ? error.message : "Garagem SDK: network error.",
|
|
1336
|
+
{ code: "network" }
|
|
1337
|
+
);
|
|
1338
|
+
}
|
|
1339
|
+
if (response.status === 404) {
|
|
1340
|
+
throw new LeadSubmitError("Garagem SDK: site not found.", {
|
|
1341
|
+
code: "not_found",
|
|
1342
|
+
status: 404
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
const data = await response.json().catch(() => ({}));
|
|
1346
|
+
if (!response.ok || typeof data.url !== "string" || !data.url) {
|
|
1347
|
+
throw new LeadSubmitError(
|
|
1348
|
+
`Garagem SDK: photo upload failed (${response.status}).`,
|
|
1349
|
+
{
|
|
1350
|
+
code: response.status === 400 ? "invalid_photo" : "http",
|
|
1351
|
+
status: response.status
|
|
1352
|
+
}
|
|
1353
|
+
);
|
|
1354
|
+
}
|
|
1355
|
+
return data.url;
|
|
1356
|
+
}
|
|
1357
|
+
var STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG = {
|
|
1358
|
+
disabledDays: [0, 6],
|
|
1359
|
+
weekdayTimeSlots: [
|
|
1360
|
+
"09:00",
|
|
1361
|
+
"10:00",
|
|
1362
|
+
"11:00",
|
|
1363
|
+
"14:00",
|
|
1364
|
+
"15:00",
|
|
1365
|
+
"16:00",
|
|
1366
|
+
"17:00"
|
|
1367
|
+
],
|
|
1368
|
+
weekendTimeSlots: ["10:00", "11:00", "14:00", "15:00", "16:00"]
|
|
1369
|
+
};
|
|
1370
|
+
function sellerPhotoSchedule(config = STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG) {
|
|
1371
|
+
const weekdayTimeSlots = [...config.weekdayTimeSlots].sort();
|
|
1372
|
+
const weekendTimeSlots = [...config.weekendTimeSlots].sort();
|
|
1373
|
+
const hours = (slots) => slots.length > 0 ? { start: slots[0], end: slots[slots.length - 1] } : null;
|
|
1374
|
+
return {
|
|
1375
|
+
timeZone: VISIT_TIME_ZONE,
|
|
1376
|
+
saturday: !config.disabledDays.includes(6),
|
|
1377
|
+
sunday: !config.disabledDays.includes(0),
|
|
1378
|
+
weekday: hours(weekdayTimeSlots) ?? { start: "09:00", end: "09:00" },
|
|
1379
|
+
weekend: hours(weekendTimeSlots),
|
|
1380
|
+
minHoursAhead: 2,
|
|
1381
|
+
disabledDays: [...config.disabledDays],
|
|
1382
|
+
weekdayTimeSlots,
|
|
1383
|
+
weekendTimeSlots,
|
|
1384
|
+
timeSlots: Array.from(
|
|
1385
|
+
/* @__PURE__ */ new Set([...weekdayTimeSlots, ...weekendTimeSlots])
|
|
1386
|
+
).sort()
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
function contactError(message) {
|
|
1390
|
+
return new LeadSubmitError(`Garagem SDK: ${message}`, {
|
|
1391
|
+
code: "invalid_contact"
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
function normalizeOwner(owner) {
|
|
1395
|
+
const name = text(owner?.name);
|
|
1396
|
+
const email = text(owner?.email);
|
|
1397
|
+
if (!isValidName(name)) throw contactError("owner name is invalid.");
|
|
1398
|
+
if (!isValidEmail(email)) throw contactError("owner email is invalid.");
|
|
1399
|
+
const phone = toE164(text(owner?.phone));
|
|
1400
|
+
if (!phone || !isValidPhone(phone) || phone.length > 40) {
|
|
1401
|
+
throw contactError("owner phone is invalid.");
|
|
1402
|
+
}
|
|
1403
|
+
return { name, email, phone };
|
|
1404
|
+
}
|
|
1405
|
+
function normalizeAddress(address) {
|
|
1406
|
+
const errors = sellerAddressErrors(address);
|
|
1407
|
+
const first = Object.values(errors)[0];
|
|
1408
|
+
if (first) {
|
|
1409
|
+
throw new LeadSubmitError(`Garagem SDK: ${first}`, {
|
|
1410
|
+
code: "invalid_address"
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
const optional = (value) => text(value) ? { value: text(value) } : null;
|
|
1414
|
+
const number = address.noNumber ? null : optional(address.number);
|
|
1415
|
+
const bloco = address.noBlocoTorre ? null : optional(address.blocoTorre);
|
|
1416
|
+
const unidade = address.noUnidade ? null : optional(address.unidade);
|
|
1417
|
+
return {
|
|
1418
|
+
fullAddress: text(address.fullAddress),
|
|
1419
|
+
street: text(address.street),
|
|
1420
|
+
...number ? { number: number.value } : {},
|
|
1421
|
+
neighborhood: text(address.neighborhood),
|
|
1422
|
+
city: text(address.city),
|
|
1423
|
+
state: text(address.state),
|
|
1424
|
+
postalCode: text(address.postalCode).replace(/\D/g, ""),
|
|
1425
|
+
country: text(address.country) || "BR",
|
|
1426
|
+
latitude: address.latitude,
|
|
1427
|
+
longitude: address.longitude,
|
|
1428
|
+
...bloco ? { blocoTorre: bloco.value } : {},
|
|
1429
|
+
...unidade ? { unidade: unidade.value } : {},
|
|
1430
|
+
noNumber: address.noNumber === true,
|
|
1431
|
+
noBlocoTorre: address.noBlocoTorre === true,
|
|
1432
|
+
noUnidade: address.noUnidade === true
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
var COUNT_FIELDS = [
|
|
1436
|
+
"bedrooms",
|
|
1437
|
+
"bathrooms",
|
|
1438
|
+
"suites",
|
|
1439
|
+
"parkingSpaces"
|
|
1440
|
+
];
|
|
1441
|
+
var AMOUNT_FIELDS = [
|
|
1442
|
+
"saleValue",
|
|
1443
|
+
"rentValue",
|
|
1444
|
+
"condoFee",
|
|
1445
|
+
"totalArea"
|
|
1446
|
+
];
|
|
1447
|
+
function propertyError(message) {
|
|
1448
|
+
return new LeadSubmitError(`Garagem SDK: ${message}`, {
|
|
1449
|
+
code: "invalid_property"
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
function normalizeProperty(property) {
|
|
1453
|
+
if (!["sale", "rent", "both"].includes(property?.businessType)) {
|
|
1454
|
+
throw propertyError("businessType must be sale, rent or both.");
|
|
1455
|
+
}
|
|
1456
|
+
for (const field of COUNT_FIELDS) {
|
|
1457
|
+
const value = property[field];
|
|
1458
|
+
if (value != null && (!Number.isInteger(value) || value < 0 || value > 999)) {
|
|
1459
|
+
throw propertyError(`${field} must be a whole number.`);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
for (const field of AMOUNT_FIELDS) {
|
|
1463
|
+
const value = property[field];
|
|
1464
|
+
if (value != null && (!Number.isFinite(value) || value < 0 || value > 1e12)) {
|
|
1465
|
+
throw propertyError(`${field} must be a non-negative number.`);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
const sale = property.businessType === "rent" ? void 0 : property.saleValue;
|
|
1469
|
+
const rent = property.businessType === "sale" ? void 0 : property.rentValue;
|
|
1470
|
+
const price = property.businessType === "rent" ? rent : sale;
|
|
1471
|
+
const counts = Object.fromEntries(
|
|
1472
|
+
COUNT_FIELDS.filter((field) => property[field] != null).map((field) => [
|
|
1473
|
+
field,
|
|
1474
|
+
property[field]
|
|
1475
|
+
])
|
|
1476
|
+
);
|
|
1477
|
+
return {
|
|
1478
|
+
businessType: property.businessType,
|
|
1479
|
+
...price != null ? { price } : {},
|
|
1480
|
+
...property.businessType === "both" && rent != null ? { rentPrice: rent } : {},
|
|
1481
|
+
...property.condoFee != null ? { condominiumFee: property.condoFee } : {},
|
|
1482
|
+
...property.totalArea != null ? { totalArea: property.totalArea } : {},
|
|
1483
|
+
...counts
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
function normalizePhotos(photos) {
|
|
1487
|
+
if (!photos?.length) return void 0;
|
|
1488
|
+
if (photos.length > SELLER_LEAD_PHOTO_MAX_COUNT) {
|
|
1489
|
+
throw new LeadSubmitError("Garagem SDK: too many photos (max 30).", {
|
|
1490
|
+
code: "invalid_photo"
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
return photos.map((url) => {
|
|
1494
|
+
const trimmed = url.trim();
|
|
1495
|
+
if (!trimmed.startsWith("https://")) {
|
|
1496
|
+
throw new LeadSubmitError("Garagem SDK: photo URL must be https.", {
|
|
1497
|
+
code: "invalid_photo"
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1500
|
+
return trimmed;
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
function normalizePhotoSession(input) {
|
|
1504
|
+
if (!input.photoSession) return void 0;
|
|
1505
|
+
const schedule = input.photoSchedule ?? sellerPhotoSchedule();
|
|
1506
|
+
const date = normalizeVisitDate(input.photoSession.date, schedule.timeZone);
|
|
1507
|
+
const time = normalizeVisitTime(input.photoSession.time);
|
|
1508
|
+
if (!date || !time || !isVisitSlotAllowed(schedule, date, time)) {
|
|
1509
|
+
throw new LeadSubmitError(
|
|
1510
|
+
"Garagem SDK: photo session slot is outside the schedule.",
|
|
1511
|
+
{ code: "invalid_slot" }
|
|
1512
|
+
);
|
|
1513
|
+
}
|
|
1514
|
+
return { date, time };
|
|
1515
|
+
}
|
|
1516
|
+
async function submitSellerLead(input) {
|
|
1517
|
+
const owner = normalizeOwner(input.owner);
|
|
1518
|
+
const address = normalizeAddress(input.address);
|
|
1519
|
+
const property = normalizeProperty(input.property);
|
|
1520
|
+
const photos = normalizePhotos(input.photos);
|
|
1521
|
+
const photoScheduling = normalizePhotoSession(input);
|
|
1522
|
+
return postSiteLead({
|
|
1523
|
+
siteId: input.siteId,
|
|
1524
|
+
baseUrl: input.baseUrl,
|
|
1525
|
+
fetch: input.fetch,
|
|
1526
|
+
publishableKey: input.publishableKey,
|
|
1527
|
+
body: {
|
|
1528
|
+
source: "site-sdk",
|
|
1529
|
+
leadType: "seller_lead",
|
|
1530
|
+
...owner,
|
|
1531
|
+
address,
|
|
1532
|
+
...property,
|
|
1533
|
+
...photos ? { photos } : {},
|
|
1534
|
+
...photoScheduling ? { photoScheduling } : {},
|
|
1535
|
+
...input.visitorId ? { visitorId: input.visitorId } : {},
|
|
1536
|
+
...input.brokerRef ? { brokerRef: input.brokerRef } : {},
|
|
1537
|
+
...input.referrer ? { referrer: input.referrer } : {}
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1239
1542
|
// src/amenity-labels.ts
|
|
1240
1543
|
var LISTING_AMENITY_TITLES = {
|
|
1241
1544
|
unit: "Comodidades",
|
|
@@ -1656,9 +1959,9 @@ var SORT_URL_TOKENS = [
|
|
|
1656
1959
|
];
|
|
1657
1960
|
|
|
1658
1961
|
// ../search-url/slugify.ts
|
|
1659
|
-
function slugifyForUrl(
|
|
1660
|
-
if (!
|
|
1661
|
-
const withDashes =
|
|
1962
|
+
function slugifyForUrl(text2) {
|
|
1963
|
+
if (!text2) return "";
|
|
1964
|
+
const withDashes = text2.replace(/([a-z])([A-Z])/g, "$1-$2");
|
|
1662
1965
|
return withDashes.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").trim();
|
|
1663
1966
|
}
|
|
1664
1967
|
|
|
@@ -1935,8 +2238,8 @@ function serializeAppliedSearchQuery(query) {
|
|
|
1935
2238
|
if (normalized.sort && isSortToken(normalized.sort)) {
|
|
1936
2239
|
params.set("ordenar", normalized.sort);
|
|
1937
2240
|
}
|
|
1938
|
-
const
|
|
1939
|
-
if (
|
|
2241
|
+
const text2 = normalized.query?.trim();
|
|
2242
|
+
if (text2) params.set("q", text2);
|
|
1940
2243
|
for (const value of (normalized.loc ?? []).slice(0, MAX_LOC_GROUPS)) {
|
|
1941
2244
|
const trimmed = value.trim();
|
|
1942
2245
|
if (trimmed) params.append("loc", trimmed);
|
|
@@ -2353,11 +2656,11 @@ function countFacetChoices(options) {
|
|
|
2353
2656
|
}
|
|
2354
2657
|
var FEMININE_HEADING = /(casa|cobertura|kitnet|loja|sala|fazenda|chácara|chacara)s?$/i;
|
|
2355
2658
|
function pluralizePt(label) {
|
|
2356
|
-
const
|
|
2357
|
-
if (!
|
|
2358
|
-
if (/il$/i.test(
|
|
2359
|
-
if (/m$/i.test(
|
|
2360
|
-
return `${
|
|
2659
|
+
const text2 = label.trim();
|
|
2660
|
+
if (!text2 || /s$/i.test(text2)) return text2;
|
|
2661
|
+
if (/il$/i.test(text2)) return `${text2.slice(0, -1)}is`;
|
|
2662
|
+
if (/m$/i.test(text2)) return `${text2.slice(0, -1)}ns`;
|
|
2663
|
+
return `${text2}s`;
|
|
2361
2664
|
}
|
|
2362
2665
|
function headingLocationSuffix(location) {
|
|
2363
2666
|
if (!location) return "";
|
|
@@ -2650,16 +2953,16 @@ function listingBreadcrumb(listing) {
|
|
|
2650
2953
|
return crumbs;
|
|
2651
2954
|
}
|
|
2652
2955
|
function listingDescriptionPreview(description, expanded = false) {
|
|
2653
|
-
const
|
|
2654
|
-
if (!
|
|
2655
|
-
if (
|
|
2656
|
-
return { text, truncated: false, toggleLabel: null };
|
|
2956
|
+
const text2 = description?.trim() ?? "";
|
|
2957
|
+
if (!text2) return null;
|
|
2958
|
+
if (text2.length <= LISTING_DESCRIPTION_CLAMP) {
|
|
2959
|
+
return { text: text2, truncated: false, toggleLabel: null };
|
|
2657
2960
|
}
|
|
2658
2961
|
if (expanded) {
|
|
2659
|
-
return { text, truncated: true, toggleLabel: "Ler menos" };
|
|
2962
|
+
return { text: text2, truncated: true, toggleLabel: "Ler menos" };
|
|
2660
2963
|
}
|
|
2661
2964
|
return {
|
|
2662
|
-
text: `${
|
|
2965
|
+
text: `${text2.slice(0, LISTING_DESCRIPTION_CLAMP).trimEnd()}\u2026`,
|
|
2663
2966
|
truncated: true,
|
|
2664
2967
|
toggleLabel: "Ler mais"
|
|
2665
2968
|
};
|
|
@@ -2684,8 +2987,8 @@ function listingMediaOverlays(listing) {
|
|
|
2684
2987
|
return overlays;
|
|
2685
2988
|
}
|
|
2686
2989
|
function listingDetailModel(listing, options) {
|
|
2687
|
-
const
|
|
2688
|
-
const description =
|
|
2990
|
+
const text2 = listing.description?.trim() ?? "";
|
|
2991
|
+
const description = text2 || null;
|
|
2689
2992
|
const truncated = description != null && description.length > LISTING_DESCRIPTION_CLAMP;
|
|
2690
2993
|
const expanded = options?.descriptionExpanded === true;
|
|
2691
2994
|
return {
|
|
@@ -2710,8 +3013,8 @@ function visibleText(value) {
|
|
|
2710
3013
|
function visibleRows(rows) {
|
|
2711
3014
|
return rows.filter((row) => {
|
|
2712
3015
|
const label = visibleText(row.label);
|
|
2713
|
-
const
|
|
2714
|
-
return label != null &&
|
|
3016
|
+
const text2 = visibleText(row.text);
|
|
3017
|
+
return label != null && text2 != null;
|
|
2715
3018
|
});
|
|
2716
3019
|
}
|
|
2717
3020
|
function listingDetailFieldsModel(listing, dictionary) {
|
|
@@ -2917,8 +3220,31 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
2917
3220
|
"searchListingPhotos",
|
|
2918
3221
|
"applyMatchedPhotoCover"
|
|
2919
3222
|
],
|
|
2920
|
-
photoSearchSince: "0.7.0"
|
|
3223
|
+
photoSearchSince: "0.7.0",
|
|
3224
|
+
/**
|
|
3225
|
+
* Seller lead (property registration on `/anunciar-imovel`). Prompt-safe
|
|
3226
|
+
* only once `minNpmVersion` reaches `sellerLeadSince`; below it
|
|
3227
|
+
* `studioSellerLeadSdkInstruction` prints nothing and
|
|
3228
|
+
* `studioCodegenContractViolations` flags the names.
|
|
3229
|
+
*/
|
|
3230
|
+
sellerLeadExports: [
|
|
3231
|
+
"submitSellerLead",
|
|
3232
|
+
"uploadSellerLeadPhoto",
|
|
3233
|
+
"sellerAddressErrors",
|
|
3234
|
+
"sellerPhotoSchedule",
|
|
3235
|
+
"isValidEmail",
|
|
3236
|
+
"isValidName"
|
|
3237
|
+
],
|
|
3238
|
+
sellerLeadSince: "0.10.0"
|
|
2921
3239
|
};
|
|
3240
|
+
function isSellerLeadOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3241
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.sellerLeadSince) >= 0;
|
|
3242
|
+
}
|
|
3243
|
+
function studioSellerLeadSdkInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3244
|
+
if (!isSellerLeadOnPin(pin)) return "";
|
|
3245
|
+
const names = STUDIO_SDK_CONTRACT.sellerLeadExports.join(", ");
|
|
3246
|
+
return `Property registration (\`/anunciar-imovel\`, client component): import ${names}, isValidPhone, toE164 from \`${STUDIO_SDK_PACKAGE}\`. Address: load Maps JS only through \`<script src="https://maps.fndn.ai/sdk.js?callback=initPlaces" async defer />\` (Places is included; never a Google key, never \`maps.googleapis.com\`), then \`google.maps.places.Autocomplete\` with \`componentRestrictions: { country: "br" }\` and pt-BR. Picking a suggestion fills fullAddress, street, number, neighborhood, city, state (the 2-letter code), postalCode, latitude and longitude from the place; a typed address without a suggestion is not enough. The visitor confirms number or "Sem n\xFAmero", bloco/torre or "N\xE3o tem", unidade or "N\xE3o tem" (noNumber, noBlocoTorre, noUnidade). Block the next group while \`sellerAddressErrors(address)\` has keys and show each message on its field. Owner: name, email and phone are all required \u2014 \`isValidName\`, \`isValidEmail\`, the phone mask with \`isValidPhone(toE164(phone))\`. Photos: \`await uploadSellerLeadPhoto({ siteId, baseUrl: GARAGEM_API_BASE, file, publishableKey })\` per file (JPG/PNG/WEBP, 10MB, up to 30), keep the returned URLs. Photo session: \`const schedule = sellerPhotoSchedule(config)\` and \`slotsForDate(schedule, day)\` for the hours. Submit once with \`await submitSellerLead({ siteId, baseUrl: GARAGEM_API_BASE, publishableKey, owner: { name, email, phone }, address, property: { businessType, saleValue, rentValue, condoFee, totalArea, bedrooms, bathrooms, suites, parkingSpaces }, photos, photoSession: { date, time }, photoSchedule: schedule })\` (omit what the visitor did not fill). Errors are \`LeadSubmitError\`: \`duplicate_property\` \u2192 "Este im\xF3vel j\xE1 est\xE1 cadastrado. Nossa equipe entrar\xE1 em contato."; \`invalid_address\` \u2192 ask to pick the address again; anything else \u2192 a retry message. Disable the submit while pending and show a success state after it resolves. Never POST the leads webhook by hand.`;
|
|
3247
|
+
}
|
|
2922
3248
|
function isPhotoSearchOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
2923
3249
|
return compareSemver(pin, STUDIO_SDK_CONTRACT.photoSearchSince) >= 0;
|
|
2924
3250
|
}
|
|
@@ -2953,8 +3279,8 @@ function studioSearchLandmarkInstruction() {
|
|
|
2953
3279
|
}
|
|
2954
3280
|
var REACT_SDK_NAMED_IMPORT_RE = /(?:^|[\n;])\s*import\s+(?!type\b)(?:type\s+)?\{([^}]+)\}\s+from\s+['"]@garagem-ai\/site-sdk\/react['"]/g;
|
|
2955
3281
|
var SHOWCASE_LEADS_POST_URL_RE = /\/api\/sites\/[^\s"']*\/leads(?!\/ui)/;
|
|
2956
|
-
function hasShowcaseLeadsPostUrl(
|
|
2957
|
-
return SHOWCASE_LEADS_POST_URL_RE.test(
|
|
3282
|
+
function hasShowcaseLeadsPostUrl(text2) {
|
|
3283
|
+
return SHOWCASE_LEADS_POST_URL_RE.test(text2);
|
|
2958
3284
|
}
|
|
2959
3285
|
function coerceNpmVersion(raw) {
|
|
2960
3286
|
if (typeof raw !== "string") return null;
|
|
@@ -3095,47 +3421,54 @@ function studioPhotoSearchInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
|
3095
3421
|
function studioChromeInstruction() {
|
|
3096
3422
|
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\`.`;
|
|
3097
3423
|
}
|
|
3098
|
-
function mentionsExportName(
|
|
3099
|
-
return new RegExp(`\\b${name}\\b`).test(
|
|
3424
|
+
function mentionsExportName(text2, name) {
|
|
3425
|
+
return new RegExp(`\\b${name}\\b`).test(text2);
|
|
3100
3426
|
}
|
|
3101
|
-
function studioCodegenContractViolations(
|
|
3427
|
+
function studioCodegenContractViolations(text2) {
|
|
3102
3428
|
const violations = [];
|
|
3103
3429
|
for (const [name, since] of Object.entries(
|
|
3104
3430
|
STUDIO_SDK_CONTRACT.optionalReactExports
|
|
3105
3431
|
)) {
|
|
3106
3432
|
if (compareSemver(STUDIO_SDK_CONTRACT.minNpmVersion, since) >= 0) continue;
|
|
3107
|
-
if (mentionsExportName(
|
|
3433
|
+
if (mentionsExportName(text2, name)) violations.push(name);
|
|
3108
3434
|
}
|
|
3109
3435
|
for (const name of STUDIO_SDK_CONTRACT.retiredReactExports) {
|
|
3110
|
-
if (mentionsExportName(
|
|
3436
|
+
if (mentionsExportName(text2, name) && !violations.includes(name)) {
|
|
3111
3437
|
violations.push(name);
|
|
3112
3438
|
}
|
|
3113
3439
|
}
|
|
3114
3440
|
for (const name of STUDIO_SDK_CONTRACT.unpublishedSearchExports) {
|
|
3115
|
-
if (mentionsExportName(
|
|
3441
|
+
if (mentionsExportName(text2, name) && !violations.includes(name)) {
|
|
3116
3442
|
violations.push(name);
|
|
3117
3443
|
}
|
|
3118
3444
|
}
|
|
3119
3445
|
for (const name of STUDIO_SDK_CONTRACT.unpublishedPhoneExports) {
|
|
3120
|
-
if (mentionsExportName(
|
|
3446
|
+
if (mentionsExportName(text2, name) && !violations.includes(name)) {
|
|
3121
3447
|
violations.push(name);
|
|
3122
3448
|
}
|
|
3123
3449
|
}
|
|
3124
3450
|
if (!mapsExportsPublished()) {
|
|
3125
3451
|
for (const name of STUDIO_SDK_CONTRACT.mapsExports) {
|
|
3126
|
-
if (mentionsExportName(
|
|
3452
|
+
if (mentionsExportName(text2, name) && !violations.includes(name)) {
|
|
3127
3453
|
violations.push(name);
|
|
3128
3454
|
}
|
|
3129
3455
|
}
|
|
3130
3456
|
}
|
|
3131
3457
|
for (const name of STUDIO_SDK_CONTRACT.unpublishedPhotoExports) {
|
|
3132
|
-
if (mentionsExportName(
|
|
3458
|
+
if (mentionsExportName(text2, name) && !violations.includes(name)) {
|
|
3133
3459
|
violations.push(name);
|
|
3134
3460
|
}
|
|
3135
3461
|
}
|
|
3136
3462
|
if (!isPhotoSearchOnPin()) {
|
|
3137
3463
|
for (const name of STUDIO_SDK_CONTRACT.photoSearchExports) {
|
|
3138
|
-
if (mentionsExportName(
|
|
3464
|
+
if (mentionsExportName(text2, name) && !violations.includes(name)) {
|
|
3465
|
+
violations.push(name);
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
if (!isSellerLeadOnPin()) {
|
|
3470
|
+
for (const name of STUDIO_SDK_CONTRACT.sellerLeadExports) {
|
|
3471
|
+
if (mentionsExportName(text2, name) && !violations.includes(name)) {
|
|
3139
3472
|
violations.push(name);
|
|
3140
3473
|
}
|
|
3141
3474
|
}
|
|
@@ -3143,21 +3476,21 @@ function studioCodegenContractViolations(text) {
|
|
|
3143
3476
|
const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
3144
3477
|
if (!marketExportsAvailableAt(pin)) {
|
|
3145
3478
|
for (const name of STUDIO_SDK_CONTRACT.marketExports) {
|
|
3146
|
-
if (mentionsExportName(
|
|
3479
|
+
if (mentionsExportName(text2, name) && !violations.includes(name)) {
|
|
3147
3480
|
violations.push(name);
|
|
3148
3481
|
}
|
|
3149
3482
|
}
|
|
3150
3483
|
}
|
|
3151
3484
|
const available = reactExportsAvailableAt(pin);
|
|
3152
|
-
for (const name of parseReactSdkNamedImports(
|
|
3485
|
+
for (const name of parseReactSdkNamedImports(text2)) {
|
|
3153
3486
|
if (!available.has(name) && !violations.includes(name)) {
|
|
3154
3487
|
violations.push(name);
|
|
3155
3488
|
}
|
|
3156
3489
|
}
|
|
3157
|
-
if (hasShowcaseLeadsPostUrl(
|
|
3490
|
+
if (hasShowcaseLeadsPostUrl(text2)) {
|
|
3158
3491
|
violations.push("showcase-leads-url");
|
|
3159
3492
|
}
|
|
3160
|
-
if (/\btype\s*=\s*["']date["']/.test(
|
|
3493
|
+
if (/\btype\s*=\s*["']date["']/.test(text2)) {
|
|
3161
3494
|
violations.push("native-date-input");
|
|
3162
3495
|
}
|
|
3163
3496
|
return violations;
|
|
@@ -3350,14 +3683,14 @@ function listingCoordinates(listing) {
|
|
|
3350
3683
|
}
|
|
3351
3684
|
function coordinateDecimals(value) {
|
|
3352
3685
|
if (!Number.isFinite(value)) return 0;
|
|
3353
|
-
const
|
|
3354
|
-
if (
|
|
3686
|
+
const text2 = Math.abs(value).toString();
|
|
3687
|
+
if (text2.includes("e")) {
|
|
3355
3688
|
const fixed = Math.abs(value).toFixed(12).replace(/0+$/, "");
|
|
3356
3689
|
const dot2 = fixed.indexOf(".");
|
|
3357
3690
|
return dot2 === -1 ? 0 : fixed.length - dot2 - 1;
|
|
3358
3691
|
}
|
|
3359
|
-
const dot =
|
|
3360
|
-
return dot === -1 ? 0 :
|
|
3692
|
+
const dot = text2.indexOf(".");
|
|
3693
|
+
return dot === -1 ? 0 : text2.length - dot - 1;
|
|
3361
3694
|
}
|
|
3362
3695
|
function roundTo(value, decimals) {
|
|
3363
3696
|
const factor = 10 ** decimals;
|
|
@@ -4221,15 +4554,15 @@ function listingVisualHighlights(listing, options) {
|
|
|
4221
4554
|
if (!isPhoto(item) || !Array.isArray(item.features)) continue;
|
|
4222
4555
|
for (const feature of item.features) {
|
|
4223
4556
|
if (typeof feature !== "string") continue;
|
|
4224
|
-
const
|
|
4225
|
-
if (!
|
|
4226
|
-
const key = normalizeRoomLabel(
|
|
4557
|
+
const text2 = feature.trim();
|
|
4558
|
+
if (!text2) continue;
|
|
4559
|
+
const key = normalizeRoomLabel(text2);
|
|
4227
4560
|
if (!key) continue;
|
|
4228
4561
|
const entry = counts.get(key);
|
|
4229
4562
|
if (entry) {
|
|
4230
4563
|
entry.count += 1;
|
|
4231
4564
|
} else {
|
|
4232
|
-
counts.set(key, { text, count: 1, seen: seen++ });
|
|
4565
|
+
counts.set(key, { text: text2, count: 1, seen: seen++ });
|
|
4233
4566
|
}
|
|
4234
4567
|
}
|
|
4235
4568
|
}
|
|
@@ -4493,6 +4826,10 @@ export {
|
|
|
4493
4826
|
PHOTO_SEARCH_MIN_QUERY_LENGTH,
|
|
4494
4827
|
SEARCH_EMPTY_COPY,
|
|
4495
4828
|
SEARCH_SORT_RELEVANCE,
|
|
4829
|
+
SELLER_LEAD_PHOTO_MAX_BYTES,
|
|
4830
|
+
SELLER_LEAD_PHOTO_MAX_COUNT,
|
|
4831
|
+
SELLER_LEAD_PHOTO_TYPES,
|
|
4832
|
+
STUDIO_DEFAULT_PHOTO_SCHEDULE_CONFIG,
|
|
4496
4833
|
STUDIO_DEFAULT_VISIT_SCHEDULE,
|
|
4497
4834
|
STUDIO_SDK_CONTRACT,
|
|
4498
4835
|
STUDIO_SDK_PACKAGE,
|
|
@@ -4554,7 +4891,10 @@ export {
|
|
|
4554
4891
|
isMapBounds,
|
|
4555
4892
|
isMapPolygon,
|
|
4556
4893
|
isPhotoSearchOnPin,
|
|
4894
|
+
isSellerLeadOnPin,
|
|
4557
4895
|
isStudioPreviewHost,
|
|
4896
|
+
isValidEmail,
|
|
4897
|
+
isValidName,
|
|
4558
4898
|
isValidPhone,
|
|
4559
4899
|
isVisitSlotAllowed,
|
|
4560
4900
|
labelAmenities,
|
|
@@ -4624,6 +4964,8 @@ export {
|
|
|
4624
4964
|
searchListingsInPolygon,
|
|
4625
4965
|
searchResultsHeading,
|
|
4626
4966
|
searchSortOptions,
|
|
4967
|
+
sellerAddressErrors,
|
|
4968
|
+
sellerPhotoSchedule,
|
|
4627
4969
|
serializeAppliedSearchQuery2 as serializeAppliedSearchQuery,
|
|
4628
4970
|
slotsForDate,
|
|
4629
4971
|
studioAmenityInstruction,
|
|
@@ -4644,8 +4986,10 @@ export {
|
|
|
4644
4986
|
studioSdkPinInstruction,
|
|
4645
4987
|
studioSearchInstruction,
|
|
4646
4988
|
studioSearchLandmarkInstruction,
|
|
4989
|
+
studioSellerLeadSdkInstruction,
|
|
4647
4990
|
studioSiteWidthCss,
|
|
4648
4991
|
submitContactLead,
|
|
4992
|
+
submitSellerLead,
|
|
4649
4993
|
submitVisitLead,
|
|
4650
4994
|
toE164,
|
|
4651
4995
|
toListingCardModel,
|
|
@@ -4655,6 +4999,7 @@ export {
|
|
|
4655
4999
|
travelTimesFromListing,
|
|
4656
5000
|
truncateNationalPhoneDigits,
|
|
4657
5001
|
unavailableReactImports,
|
|
5002
|
+
uploadSellerLeadPhoto,
|
|
4658
5003
|
visibleSearchFilters
|
|
4659
5004
|
};
|
|
4660
5005
|
//# sourceMappingURL=index.mjs.map
|