@garagem-ai/site-sdk 0.11.1 → 0.12.1

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
@@ -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)$/;
@@ -3043,10 +3085,11 @@ var STUDIO_SDK_CONTRACT = {
3043
3085
  * (`useMapSearch`, `searchListingsInBounds`) shipped in 0.9.0 — 0.7.0
3044
3086
  * does not export them. Property registration shipped in 0.10.0.
3045
3087
  * Weighted map buckets (`map.buckets`, clustered by the hook) shipped
3046
- * in 0.11.0. Search filter helpers (`visibleSearchFilters` /
3088
+ * in 0.11.0. Share links (`getShareLink`, `/p/[token]`) shipped in
3089
+ * 0.12.0. Search filter helpers (`visibleSearchFilters` /
3047
3090
  * `toolbarFilterIds`) shipped in 0.4.12 and remain on this pin.
3048
3091
  */
3049
- minNpmVersion: "0.11.0",
3092
+ minNpmVersion: "0.12.0",
3050
3093
  /** Historical: older tarballs inject card CSS when those components mount. */
3051
3094
  selfInjectSince: "0.4.2",
3052
3095
  chromeStrategy: "app-owned",
@@ -3245,11 +3288,27 @@ var STUDIO_SDK_CONTRACT = {
3245
3288
  "isValidEmail",
3246
3289
  "isValidName"
3247
3290
  ],
3248
- sellerLeadSince: "0.10.0"
3291
+ sellerLeadSince: "0.10.0",
3292
+ /**
3293
+ * Share-link page (`/p/[token]`). Prompt-safe only once `minNpmVersion`
3294
+ * reaches `shareLinkSince`. Below it `studioShareLinkInstruction` prints
3295
+ * nothing and `studioCodegenContractViolations` flags `getShareLink` —
3296
+ * v0 installs the pin and copies any identifier it sees.
3297
+ */
3298
+ shareExports: ["getShareLink"],
3299
+ shareLinkSince: "0.12.0"
3249
3300
  };
3250
3301
  function isSellerLeadOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3251
3302
  return compareSemver(pin, STUDIO_SDK_CONTRACT.sellerLeadSince) >= 0;
3252
3303
  }
3304
+ function isShareLinkOnPin(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3305
+ return compareSemver(pin, STUDIO_SDK_CONTRACT.shareLinkSince) >= 0;
3306
+ }
3307
+ function studioShareLinkInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3308
+ if (!isShareLinkOnPin(pin)) return "";
3309
+ const name = STUDIO_SDK_CONTRACT.shareExports[0];
3310
+ 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.`;
3311
+ }
3253
3312
  function studioSellerLeadSdkInstruction(pin = STUDIO_SDK_CONTRACT.minNpmVersion) {
3254
3313
  if (!isSellerLeadOnPin(pin)) return "";
3255
3314
  const names = STUDIO_SDK_CONTRACT.sellerLeadExports.join(", ");
@@ -3495,6 +3554,13 @@ function studioCodegenContractViolations(text2) {
3495
3554
  }
3496
3555
  }
3497
3556
  }
3557
+ if (!isShareLinkOnPin()) {
3558
+ for (const name of STUDIO_SDK_CONTRACT.shareExports) {
3559
+ if (mentionsExportName(text2, name) && !violations.includes(name)) {
3560
+ violations.push(name);
3561
+ }
3562
+ }
3563
+ }
3498
3564
  const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
3499
3565
  if (!marketExportsAvailableAt(pin)) {
3500
3566
  for (const name of STUDIO_SDK_CONTRACT.marketExports) {
@@ -4906,6 +4972,7 @@ export {
4906
4972
  getListings,
4907
4973
  getNeighborhoodSummary,
4908
4974
  getSearchUi,
4975
+ getShareLink,
4909
4976
  getSimilarByPhoto,
4910
4977
  getSimilarListings,
4911
4978
  getSite,
@@ -4918,6 +4985,7 @@ export {
4918
4985
  isMapPolygon,
4919
4986
  isPhotoSearchOnPin,
4920
4987
  isSellerLeadOnPin,
4988
+ isShareLinkOnPin,
4921
4989
  isStudioPreviewHost,
4922
4990
  isValidEmail,
4923
4991
  isValidName,
@@ -5013,6 +5081,7 @@ export {
5013
5081
  studioSearchInstruction,
5014
5082
  studioSearchLandmarkInstruction,
5015
5083
  studioSellerLeadSdkInstruction,
5084
+ studioShareLinkInstruction,
5016
5085
  studioSiteWidthCss,
5017
5086
  submitContactLead,
5018
5087
  submitSellerLead,