@garagem-ai/site-sdk 0.11.1 → 0.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/README.md +1 -0
- package/dist/index.d.mts +162 -2
- package/dist/index.d.ts +162 -2
- package/dist/index.js +72 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +14 -0
- package/src/share.ts +114 -0
- package/src/studio-contract.ts +34 -0
- package/src/types-share.ts +122 -0
package/dist/index.mjs
CHANGED
|
@@ -437,6 +437,48 @@ async function getCmsEntry(options) {
|
|
|
437
437
|
return data;
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
+
// src/share.ts
|
|
441
|
+
async function getShareLink(options) {
|
|
442
|
+
const { token, password, baseUrl, fetch: fetchImpl, next } = options;
|
|
443
|
+
if (!token || !token.trim()) {
|
|
444
|
+
throw new TypeError("getShareLink: `token` is required");
|
|
445
|
+
}
|
|
446
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
447
|
+
const url = `${base}/api/sites/share/${encodeURIComponent(token)}`;
|
|
448
|
+
const doFetch = fetchImpl ?? fetch;
|
|
449
|
+
const baseInit = password ? {
|
|
450
|
+
method: "POST",
|
|
451
|
+
headers: {
|
|
452
|
+
Accept: "application/json",
|
|
453
|
+
"Content-Type": "application/json"
|
|
454
|
+
},
|
|
455
|
+
body: JSON.stringify({ password }),
|
|
456
|
+
next
|
|
457
|
+
} : { method: "GET", headers: { Accept: "application/json" }, next };
|
|
458
|
+
const init = withPublishableKeyHeader(baseInit, options.publishableKey);
|
|
459
|
+
const response = await doFetch(url, init);
|
|
460
|
+
if (response.ok) {
|
|
461
|
+
return { ok: true, ...await response.json() };
|
|
462
|
+
}
|
|
463
|
+
const EXPECTED_STATUSES = /* @__PURE__ */ new Set([400, 401, 403, 404, 410]);
|
|
464
|
+
if (EXPECTED_STATUSES.has(response.status)) {
|
|
465
|
+
const body = await response.json().catch(() => ({}));
|
|
466
|
+
return {
|
|
467
|
+
ok: false,
|
|
468
|
+
status: response.status,
|
|
469
|
+
reason: body.reason ?? null,
|
|
470
|
+
message: body.error ?? "Share link unavailable",
|
|
471
|
+
...body.listingCode ? { listingCode: body.listingCode } : {},
|
|
472
|
+
...body.site ? { site: body.site } : {}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
const text2 = await response.text().catch(() => "");
|
|
476
|
+
throw new GaragemSdkError(
|
|
477
|
+
`Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${text2 ? ` \u2014 ${text2.slice(0, 200)}` : ""}`,
|
|
478
|
+
{ status: response.status, url }
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
|
|
440
482
|
// src/schedule.ts
|
|
441
483
|
var VISIT_TIME_ZONE = "America/Sao_Paulo";
|
|
442
484
|
var HHMM_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
@@ -3245,11 +3287,27 @@ var STUDIO_SDK_CONTRACT = {
|
|
|
3245
3287
|
"isValidEmail",
|
|
3246
3288
|
"isValidName"
|
|
3247
3289
|
],
|
|
3248
|
-
sellerLeadSince: "0.10.0"
|
|
3290
|
+
sellerLeadSince: "0.10.0",
|
|
3291
|
+
/**
|
|
3292
|
+
* Share-link page (`/p/[token]`). Prompt-safe only once `minNpmVersion`
|
|
3293
|
+
* reaches `shareLinkSince`. Below it `studioShareLinkInstruction` prints
|
|
3294
|
+
* nothing and `studioCodegenContractViolations` flags `getShareLink` —
|
|
3295
|
+
* v0 installs the pin and copies any identifier it sees.
|
|
3296
|
+
*/
|
|
3297
|
+
shareExports: ["getShareLink"],
|
|
3298
|
+
shareLinkSince: "0.12.0"
|
|
3249
3299
|
};
|
|
3250
3300
|
function isSellerLeadOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3251
3301
|
return compareSemver(pin, STUDIO_SDK_CONTRACT.sellerLeadSince) >= 0;
|
|
3252
3302
|
}
|
|
3303
|
+
function isShareLinkOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3304
|
+
return compareSemver(pin, STUDIO_SDK_CONTRACT.shareLinkSince) >= 0;
|
|
3305
|
+
}
|
|
3306
|
+
function studioShareLinkInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3307
|
+
if (!isShareLinkOnPin(pin)) return "";
|
|
3308
|
+
const name = STUDIO_SDK_CONTRACT.shareExports[0];
|
|
3309
|
+
return `Share links (\`/p/[token]\`): add a server page \`app/p/[token]/page.tsx\`. Read \`token\` from the route params and \`const result = await ${name}({ token, baseUrl: GARAGEM_API_BASE })\`. When \`result.ok\` is false and \`result.reason\` is \`password_required\` or \`password_invalid\`, render a password form and submit \`getShareLink({ token, password, baseUrl: GARAGEM_API_BASE })\`. For \`not_found\`, \`inactive\`, or \`expired\`, say the link is no longer available \u2014 do not render a generic framework 404. When \`result.ok\` and \`result.listing\` is set, render that listing with the same listing-detail module \`/imoveis\` already uses (\`listingDetailModel\` and the site gallery). Do not invent a second listing layout and do not proxy the page to another host.`;
|
|
3310
|
+
}
|
|
3253
3311
|
function studioSellerLeadSdkInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
|
|
3254
3312
|
if (!isSellerLeadOnPin(pin)) return "";
|
|
3255
3313
|
const names = STUDIO_SDK_CONTRACT.sellerLeadExports.join(", ");
|
|
@@ -3495,6 +3553,13 @@ function studioCodegenContractViolations(text2) {
|
|
|
3495
3553
|
}
|
|
3496
3554
|
}
|
|
3497
3555
|
}
|
|
3556
|
+
if (!isShareLinkOnPin()) {
|
|
3557
|
+
for (const name of STUDIO_SDK_CONTRACT.shareExports) {
|
|
3558
|
+
if (mentionsExportName(text2, name) && !violations.includes(name)) {
|
|
3559
|
+
violations.push(name);
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3498
3563
|
const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
|
|
3499
3564
|
if (!marketExportsAvailableAt(pin)) {
|
|
3500
3565
|
for (const name of STUDIO_SDK_CONTRACT.marketExports) {
|
|
@@ -4906,6 +4971,7 @@ export {
|
|
|
4906
4971
|
getListings,
|
|
4907
4972
|
getNeighborhoodSummary,
|
|
4908
4973
|
getSearchUi,
|
|
4974
|
+
getShareLink,
|
|
4909
4975
|
getSimilarByPhoto,
|
|
4910
4976
|
getSimilarListings,
|
|
4911
4977
|
getSite,
|
|
@@ -4918,6 +4984,7 @@ export {
|
|
|
4918
4984
|
isMapPolygon,
|
|
4919
4985
|
isPhotoSearchOnPin,
|
|
4920
4986
|
isSellerLeadOnPin,
|
|
4987
|
+
isShareLinkOnPin,
|
|
4921
4988
|
isStudioPreviewHost,
|
|
4922
4989
|
isValidEmail,
|
|
4923
4990
|
isValidName,
|
|
@@ -5013,6 +5080,7 @@ export {
|
|
|
5013
5080
|
studioSearchInstruction,
|
|
5014
5081
|
studioSearchLandmarkInstruction,
|
|
5015
5082
|
studioSellerLeadSdkInstruction,
|
|
5083
|
+
studioShareLinkInstruction,
|
|
5016
5084
|
studioSiteWidthCss,
|
|
5017
5085
|
submitContactLead,
|
|
5018
5086
|
submitSellerLead,
|