@garagem-ai/site-sdk 0.1.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 ADDED
@@ -0,0 +1,204 @@
1
+ // src/internal/url.ts
2
+ var DEFAULT_BASE_URL = "https://app.garagem.ai";
3
+ function normalizeBaseUrl(baseUrl) {
4
+ const url = baseUrl ?? DEFAULT_BASE_URL;
5
+ return url.endsWith("/") ? url.slice(0, -1) : url;
6
+ }
7
+ function buildListingFiltersQuery(filters) {
8
+ const params = new URLSearchParams();
9
+ if (!filters) return params;
10
+ if (filters.limit != null) params.set("limit", String(filters.limit));
11
+ if (filters.offset != null) params.set("offset", String(filters.offset));
12
+ if (filters.businessType) params.set("businessType", filters.businessType);
13
+ if (filters.propertyType) params.set("propertyType", filters.propertyType);
14
+ if (filters.city) params.set("city", filters.city);
15
+ if (filters.neighborhood) params.set("neighborhood", filters.neighborhood);
16
+ if (filters.minPrice != null) params.set("minPrice", String(filters.minPrice));
17
+ if (filters.maxPrice != null) params.set("maxPrice", String(filters.maxPrice));
18
+ return params;
19
+ }
20
+
21
+ // src/fetchers.ts
22
+ async function callJson(url, init, fetchImpl) {
23
+ const response = await fetchImpl(url, init);
24
+ if (!response.ok) {
25
+ const text = await response.text().catch(() => "");
26
+ throw new GaragemSdkError(
27
+ `Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${text ? ` \u2014 ${text.slice(0, 200)}` : ""}`,
28
+ { status: response.status, url }
29
+ );
30
+ }
31
+ return await response.json();
32
+ }
33
+ var GaragemSdkError = class extends Error {
34
+ status;
35
+ url;
36
+ constructor(message, info) {
37
+ super(message);
38
+ this.name = "GaragemSdkError";
39
+ this.status = info.status;
40
+ this.url = info.url;
41
+ }
42
+ };
43
+ async function getListings(options) {
44
+ const { siteId, filters, baseUrl, fetch: fetchImpl, next } = options;
45
+ const base = normalizeBaseUrl(baseUrl);
46
+ const params = buildListingFiltersQuery(filters);
47
+ const qs = params.size > 0 ? `?${params.toString()}` : "";
48
+ const url = `${base}/api/sites/${encodeURIComponent(siteId)}/listings${qs}`;
49
+ const data = await callJson(
50
+ url,
51
+ { method: "GET", headers: { "Content-Type": "application/json" }, next },
52
+ fetchImpl ?? fetch
53
+ );
54
+ return {
55
+ listings: data.listings ?? [],
56
+ total: data.total ?? 0
57
+ };
58
+ }
59
+ async function getListing(options) {
60
+ const { siteId, listingId, baseUrl, fetch: fetchImpl, next } = options;
61
+ const base = normalizeBaseUrl(baseUrl);
62
+ const url = `${base}/api/sites/${encodeURIComponent(siteId)}/listings/${encodeURIComponent(
63
+ listingId
64
+ )}`;
65
+ return callJson(
66
+ url,
67
+ { method: "GET", headers: { "Content-Type": "application/json" }, next },
68
+ fetchImpl ?? fetch
69
+ );
70
+ }
71
+ async function getSite(options) {
72
+ const { siteId, domain, baseUrl, fetch: fetchImpl, next } = options;
73
+ if (!siteId && !domain) {
74
+ throw new TypeError(
75
+ "getSite: provide exactly one of `siteId` or `domain`."
76
+ );
77
+ }
78
+ if (siteId && domain) {
79
+ throw new TypeError(
80
+ "getSite: provide only one of `siteId` or `domain`, not both."
81
+ );
82
+ }
83
+ const base = normalizeBaseUrl(baseUrl);
84
+ const params = new URLSearchParams();
85
+ if (siteId) params.set("siteId", siteId);
86
+ if (domain) params.set("domain", domain);
87
+ const url = `${base}/api/sites/resolve?${params.toString()}`;
88
+ const f = fetchImpl ?? fetch;
89
+ const response = await f(url, {
90
+ method: "GET",
91
+ headers: { "Content-Type": "application/json" },
92
+ next
93
+ });
94
+ if (response.status === 404) return null;
95
+ if (!response.ok) {
96
+ throw new GaragemSdkError(
97
+ `Garagem SDK: getSite failed (${response.status}) for ${url}`,
98
+ { status: response.status, url }
99
+ );
100
+ }
101
+ const data = await response.json();
102
+ return {
103
+ id: data.id,
104
+ name: data.name,
105
+ domain: data.domain,
106
+ tenantId: data.tenantId
107
+ };
108
+ }
109
+ async function searchListings(options) {
110
+ const { siteId, params, baseUrl, fetch: fetchImpl, next } = options;
111
+ if (!params || typeof params.q !== "string") {
112
+ throw new TypeError(
113
+ "Garagem SDK: searchListings requires `params.q` (Typesense query string)."
114
+ );
115
+ }
116
+ const base = normalizeBaseUrl(baseUrl);
117
+ const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search`;
118
+ return callJson(
119
+ url,
120
+ {
121
+ method: "POST",
122
+ headers: { "Content-Type": "application/json" },
123
+ body: JSON.stringify(params),
124
+ next
125
+ },
126
+ fetchImpl ?? fetch
127
+ );
128
+ }
129
+
130
+ // src/client.ts
131
+ function createGaragemClient(options = {}) {
132
+ const resolveSiteId = (override) => {
133
+ const id = override ?? options.siteId;
134
+ if (!id) {
135
+ throw new TypeError(
136
+ "Garagem SDK: siteId is required \u2014 pass it to createGaragemClient or to the call itself."
137
+ );
138
+ }
139
+ return id;
140
+ };
141
+ const mergeNext = (callNext) => {
142
+ if (!options.next && !callNext) return void 0;
143
+ return { ...options.next, ...callNext };
144
+ };
145
+ return {
146
+ options: Object.freeze({ ...options }),
147
+ async getListings({ filters, siteId, next } = {}) {
148
+ const opts = {
149
+ siteId: resolveSiteId(siteId)
150
+ };
151
+ if (filters !== void 0) opts.filters = filters;
152
+ if (options.baseUrl !== void 0) opts.baseUrl = options.baseUrl;
153
+ if (options.fetch !== void 0) opts.fetch = options.fetch;
154
+ const merged = mergeNext(next);
155
+ if (merged !== void 0) opts.next = merged;
156
+ return getListings(opts);
157
+ },
158
+ async getListing({ listingId, siteId, next }) {
159
+ const opts = {
160
+ siteId: resolveSiteId(siteId),
161
+ listingId
162
+ };
163
+ if (options.baseUrl !== void 0) opts.baseUrl = options.baseUrl;
164
+ if (options.fetch !== void 0) opts.fetch = options.fetch;
165
+ const merged = mergeNext(next);
166
+ if (merged !== void 0) opts.next = merged;
167
+ return getListing(opts);
168
+ },
169
+ async getSite({ siteId, domain, next }) {
170
+ const opts = {};
171
+ if (siteId !== void 0) opts.siteId = siteId;
172
+ if (domain !== void 0) opts.domain = domain;
173
+ if (options.baseUrl !== void 0) opts.baseUrl = options.baseUrl;
174
+ if (options.fetch !== void 0) opts.fetch = options.fetch;
175
+ const merged = mergeNext(next);
176
+ if (merged !== void 0) opts.next = merged;
177
+ return getSite(opts);
178
+ },
179
+ async searchListings({
180
+ params,
181
+ siteId,
182
+ next
183
+ }) {
184
+ const opts = {
185
+ siteId: resolveSiteId(siteId),
186
+ params
187
+ };
188
+ if (options.baseUrl !== void 0) opts.baseUrl = options.baseUrl;
189
+ if (options.fetch !== void 0) opts.fetch = options.fetch;
190
+ const merged = mergeNext(next);
191
+ if (merged !== void 0) opts.next = merged;
192
+ return searchListings(opts);
193
+ }
194
+ };
195
+ }
196
+ export {
197
+ GaragemSdkError,
198
+ createGaragemClient,
199
+ getListing,
200
+ getListings,
201
+ getSite,
202
+ searchListings
203
+ };
204
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internal/url.ts","../src/fetchers.ts","../src/client.ts"],"sourcesContent":["import type { ListingFilters } from \"../types\";\n\n/** Default base URL — the public Garagem API. Override via `baseUrl`. */\nexport const DEFAULT_BASE_URL = \"https://app.garagem.ai\";\n\nexport function normalizeBaseUrl(baseUrl: string | undefined): string {\n const url = baseUrl ?? DEFAULT_BASE_URL;\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\n/**\n * Serialize listing filters into URLSearchParams. Skips undefined/null\n * values so the URL stays clean. Kept separate from the fetcher so it's\n * testable in isolation.\n */\nexport function buildListingFiltersQuery(\n filters: ListingFilters | undefined\n): URLSearchParams {\n const params = new URLSearchParams();\n if (!filters) return params;\n\n if (filters.limit != null) params.set(\"limit\", String(filters.limit));\n if (filters.offset != null) params.set(\"offset\", String(filters.offset));\n if (filters.businessType) params.set(\"businessType\", filters.businessType);\n if (filters.propertyType) params.set(\"propertyType\", filters.propertyType);\n if (filters.city) params.set(\"city\", filters.city);\n if (filters.neighborhood) params.set(\"neighborhood\", filters.neighborhood);\n if (filters.minPrice != null) params.set(\"minPrice\", String(filters.minPrice));\n if (filters.maxPrice != null) params.set(\"maxPrice\", String(filters.maxPrice));\n\n return params;\n}\n","import type {\n Listing,\n ListingDetail,\n ListingFilters,\n ListingsResult,\n RequestNextOptions,\n SearchListingsParams,\n SearchListingsResult,\n Site,\n} from \"./types\";\nimport {\n buildListingFiltersQuery,\n normalizeBaseUrl,\n} from \"./internal/url\";\n\n/** Custom fetch implementation. Defaults to the global `fetch`. */\nexport type FetchLike = typeof fetch;\n\ninterface BaseOptions {\n /** Garagem API base URL. Defaults to `https://app.garagem.ai`. */\n baseUrl?: string;\n /** Override the fetch implementation (testing, edge runtimes, retries). */\n fetch?: FetchLike;\n /**\n * Next.js App Router caching hints. Ignored on runtimes that don't\n * understand them.\n */\n next?: RequestNextOptions;\n}\n\nexport interface GetListingsOptions extends BaseOptions {\n siteId: string;\n filters?: ListingFilters;\n}\n\nexport interface GetListingOptions extends BaseOptions {\n siteId: string;\n listingId: string;\n}\n\nexport interface GetSiteOptions extends BaseOptions {\n /** Look up by site ID, or… */\n siteId?: string;\n /** …by domain. Exactly one of `siteId` / `domain` must be provided. */\n domain?: string;\n}\n\nexport interface SearchListingsOptions extends BaseOptions {\n siteId: string;\n params: SearchListingsParams;\n}\n\ninterface FetchInit extends RequestInit {\n /**\n * Next.js attaches this on `fetch` (App Router). Adding it here keeps\n * `RequestInit` typed without forcing consumers to install Next types.\n */\n next?: RequestNextOptions;\n}\n\nasync function callJson<T>(\n url: string,\n init: FetchInit,\n fetchImpl: FetchLike\n): Promise<T> {\n const response = await fetchImpl(url, init);\n if (!response.ok) {\n const text = await response.text().catch(() => \"\");\n throw new GaragemSdkError(\n `Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${\n text ? ` — ${text.slice(0, 200)}` : \"\"\n }`,\n { status: response.status, url }\n );\n }\n return (await response.json()) as T;\n}\n\n/** Error thrown when a fetcher hits a non-2xx response. */\nexport class GaragemSdkError extends Error {\n readonly status: number;\n readonly url: string;\n constructor(message: string, info: { status: number; url: string }) {\n super(message);\n this.name = \"GaragemSdkError\";\n this.status = info.status;\n this.url = info.url;\n }\n}\n\n/**\n * Fetch a paginated list of listings for a given site.\n *\n * @example\n * const { listings } = await getListings({\n * siteId: \"abc\",\n * filters: { city: \"São Paulo\", limit: 24 },\n * next: { revalidate: 300, tags: [`site:abc:listings`] },\n * });\n */\nexport async function getListings(\n options: GetListingsOptions\n): Promise<ListingsResult> {\n const { siteId, filters, baseUrl, fetch: fetchImpl, next } = options;\n const base = normalizeBaseUrl(baseUrl);\n const params = buildListingFiltersQuery(filters);\n const qs = params.size > 0 ? `?${params.toString()}` : \"\";\n const url = `${base}/api/sites/${encodeURIComponent(siteId)}/listings${qs}`;\n\n const data = await callJson<{ listings?: Listing[]; total?: number }>(\n url,\n { method: \"GET\", headers: { \"Content-Type\": \"application/json\" }, next },\n fetchImpl ?? fetch\n );\n return {\n listings: data.listings ?? [],\n total: data.total ?? 0,\n };\n}\n\n/**\n * Fetch a single listing's full detail (amenities, gallery, building).\n */\nexport async function getListing(\n options: GetListingOptions\n): Promise<ListingDetail> {\n const { siteId, listingId, baseUrl, fetch: fetchImpl, next } = options;\n const base = normalizeBaseUrl(baseUrl);\n const url = `${base}/api/sites/${encodeURIComponent(siteId)}/listings/${encodeURIComponent(\n listingId\n )}`;\n\n return callJson<ListingDetail>(\n url,\n { method: \"GET\", headers: { \"Content-Type\": \"application/json\" }, next },\n fetchImpl ?? fetch\n );\n}\n\n/**\n * Resolve a site's public profile by ID or by domain. Returns `null`\n * when the site does not exist or the host is unrecognized.\n *\n * @example\n * const site = await getSite({ domain: \"imobiliariax.com.br\" });\n * if (!site) return notFound();\n */\nexport async function getSite(\n options: GetSiteOptions\n): Promise<Site | null> {\n const { siteId, domain, baseUrl, fetch: fetchImpl, next } = options;\n if (!siteId && !domain) {\n throw new TypeError(\n \"getSite: provide exactly one of `siteId` or `domain`.\"\n );\n }\n if (siteId && domain) {\n throw new TypeError(\n \"getSite: provide only one of `siteId` or `domain`, not both.\"\n );\n }\n\n const base = normalizeBaseUrl(baseUrl);\n const params = new URLSearchParams();\n if (siteId) params.set(\"siteId\", siteId);\n if (domain) params.set(\"domain\", domain);\n const url = `${base}/api/sites/resolve?${params.toString()}`;\n\n const f = fetchImpl ?? fetch;\n const response = await f(url, {\n method: \"GET\",\n headers: { \"Content-Type\": \"application/json\" },\n next,\n } as FetchInit);\n if (response.status === 404) return null;\n if (!response.ok) {\n throw new GaragemSdkError(\n `Garagem SDK: getSite failed (${response.status}) for ${url}`,\n { status: response.status, url }\n );\n }\n const data = (await response.json()) as {\n id: string;\n name: string;\n domain: string | null;\n tenantId: string;\n };\n return {\n id: data.id,\n name: data.name,\n domain: data.domain,\n tenantId: data.tenantId,\n };\n}\n\n/**\n * Advanced search escape hatch.\n *\n * Calls `POST /api/sites/{siteId}/search` directly and returns the raw\n * Typesense response (`{ found, page, hits: [{ document, ... }], ... }`).\n * Use when the friendly `getListings({ filters })` API isn't expressive\n * enough — faceted search, multi-field sort, custom grouping, etc.\n *\n * @example\n * const result = await searchListings({\n * siteId: \"abc\",\n * params: {\n * q: \"frente mar\",\n * query_by: \"title,description,neighborhood\",\n * filter_by: \"businessType:=sale && bedrooms:>=3\",\n * sort_by: \"price:asc\",\n * per_page: 24,\n * page: 1,\n * facet_by: \"neighborhood,propertyType\",\n * },\n * });\n * for (const hit of result.hits) {\n * console.log(hit.document, hit.highlight);\n * }\n */\nexport async function searchListings<\n TDocument = Record<string, unknown>,\n>(\n options: SearchListingsOptions\n): Promise<SearchListingsResult<TDocument>> {\n const { siteId, params, baseUrl, fetch: fetchImpl, next } = options;\n if (!params || typeof params.q !== \"string\") {\n throw new TypeError(\n \"Garagem SDK: searchListings requires `params.q` (Typesense query string).\"\n );\n }\n const base = normalizeBaseUrl(baseUrl);\n const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search`;\n return callJson<SearchListingsResult<TDocument>>(\n url,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(params),\n next,\n },\n fetchImpl ?? fetch\n );\n}\n","import {\n getListing,\n getListings,\n getSite,\n searchListings,\n type FetchLike,\n type GetListingOptions,\n type GetListingsOptions,\n type GetSiteOptions,\n type SearchListingsOptions,\n} from \"./fetchers\";\nimport type {\n ListingDetail,\n ListingFilters,\n ListingsResult,\n RequestNextOptions,\n SearchListingsParams,\n SearchListingsResult,\n Site,\n} from \"./types\";\n\nexport interface CreateGaragemClientOptions {\n /** Garagem API base URL. Defaults to `https://app.garagem.ai`. */\n baseUrl?: string;\n /** Pre-bind a site so each call doesn't repeat it. */\n siteId?: string;\n /** Custom fetch implementation. */\n fetch?: FetchLike;\n /** Default Next.js caching hints applied to every request. */\n next?: RequestNextOptions;\n}\n\nexport interface GaragemClient {\n /** Configuration the client was created with. */\n readonly options: Readonly<CreateGaragemClientOptions>;\n /** List listings for the bound (or explicitly passed) site. */\n getListings(\n args?: { filters?: ListingFilters; siteId?: string; next?: RequestNextOptions }\n ): Promise<ListingsResult>;\n /** Fetch a single listing detail. */\n getListing(\n args: { listingId: string; siteId?: string; next?: RequestNextOptions }\n ): Promise<ListingDetail>;\n /** Resolve a site by ID or domain. */\n getSite(\n args: { siteId?: string; domain?: string; next?: RequestNextOptions }\n ): Promise<Site | null>;\n /**\n * Advanced search — raw Typesense parameters, raw response. Use when\n * the friendly `getListings({ filters })` API isn't expressive enough.\n */\n searchListings<TDocument = Record<string, unknown>>(\n args: {\n params: SearchListingsParams;\n siteId?: string;\n next?: RequestNextOptions;\n }\n ): Promise<SearchListingsResult<TDocument>>;\n}\n\n/**\n * Bind base URL, fetch and site to a single client object. Useful when\n * the same configuration is shared across many calls (RSC pages, API\n * routes, scripts).\n *\n * The bare functions (`getListings`, `getListing`, `getSite`) are also\n * exported for the no-client style.\n */\nexport function createGaragemClient(\n options: CreateGaragemClientOptions = {}\n): GaragemClient {\n const resolveSiteId = (override?: string): string => {\n const id = override ?? options.siteId;\n if (!id) {\n throw new TypeError(\n \"Garagem SDK: siteId is required — pass it to createGaragemClient or to the call itself.\"\n );\n }\n return id;\n };\n const mergeNext = (\n callNext?: RequestNextOptions\n ): RequestNextOptions | undefined => {\n if (!options.next && !callNext) return undefined;\n return { ...options.next, ...callNext };\n };\n\n // All methods are `async` so validation failures (e.g. missing siteId)\n // surface as promise rejections rather than synchronous throws. SDK\n // callers always `await` — this keeps error handling predictable.\n return {\n options: Object.freeze({ ...options }),\n async getListings({ filters, siteId, next } = {}) {\n const opts: GetListingsOptions = {\n siteId: resolveSiteId(siteId),\n };\n if (filters !== undefined) opts.filters = filters;\n if (options.baseUrl !== undefined) opts.baseUrl = options.baseUrl;\n if (options.fetch !== undefined) opts.fetch = options.fetch;\n const merged = mergeNext(next);\n if (merged !== undefined) opts.next = merged;\n return getListings(opts);\n },\n async getListing({ listingId, siteId, next }) {\n const opts: GetListingOptions = {\n siteId: resolveSiteId(siteId),\n listingId,\n };\n if (options.baseUrl !== undefined) opts.baseUrl = options.baseUrl;\n if (options.fetch !== undefined) opts.fetch = options.fetch;\n const merged = mergeNext(next);\n if (merged !== undefined) opts.next = merged;\n return getListing(opts);\n },\n async getSite({ siteId, domain, next }) {\n const opts: GetSiteOptions = {};\n if (siteId !== undefined) opts.siteId = siteId;\n if (domain !== undefined) opts.domain = domain;\n if (options.baseUrl !== undefined) opts.baseUrl = options.baseUrl;\n if (options.fetch !== undefined) opts.fetch = options.fetch;\n const merged = mergeNext(next);\n if (merged !== undefined) opts.next = merged;\n return getSite(opts);\n },\n async searchListings<TDocument = Record<string, unknown>>({\n params,\n siteId,\n next,\n }: {\n params: SearchListingsParams;\n siteId?: string;\n next?: RequestNextOptions;\n }) {\n const opts: SearchListingsOptions = {\n siteId: resolveSiteId(siteId),\n params,\n };\n if (options.baseUrl !== undefined) opts.baseUrl = options.baseUrl;\n if (options.fetch !== undefined) opts.fetch = options.fetch;\n const merged = mergeNext(next);\n if (merged !== undefined) opts.next = merged;\n return searchListings<TDocument>(opts);\n },\n };\n}\n"],"m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AI,WAAW,OAAW,MAAK,SAAS;AACxC,UAAI,QAAQ,YAAY,OAAW,MAAK,UAAU,QAAQ;AAC1D,UAAI,QAAQ,UAAU,OAAW,MAAK,QAAQ,QAAQ;AACtD,YAAM,SAAS,UAAU,IAAI;AAC7B,UAAI,WAAW,OAAW,MAAK,OAAO;AACtC,aAAO,QAAQ,IAAI;AAAA,IACrB;AAAA,IACA,MAAM,eAAoD;AAAA,MACxD;AAAA,MACA;AAAA,MACA;AAAA,IACF,GAIG;AACD,YAAM,OAA8B;AAAA,QAClC,QAAQ,cAAc,MAAM;AAAA,QAC5B;AAAA,MACF;AACA,UAAI,QAAQ,YAAY,OAAW,MAAK,UAAU,QAAQ;AAC1D,UAAI,QAAQ,UAAU,OAAW,MAAK,QAAQ,QAAQ;AACtD,YAAM,SAAS,UAAU,IAAI;AAC7B,UAAI,WAAW,OAAW,MAAK,OAAO;AACtC,aAAO,eAA0B,IAAI;AAAA,IACvC;AAAA,EACF;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@garagem-ai/site-sdk",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "Typed, runtime-agnostic SDK for building custom real estate sites against the Garagem platform. Drop into any Next.js (or other JS) project to fetch listings, sites and CMS data.",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./src/index.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "src",
20
+ "README.md"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "dev": "tsup --watch",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest",
30
+ "typecheck": "tsc --noEmit"
31
+ },
32
+ "devDependencies": {
33
+ "tsup": "^8.0.1",
34
+ "typescript": "^5.3.3",
35
+ "vitest": "^4.0.0"
36
+ },
37
+ "sideEffects": false,
38
+ "keywords": [
39
+ "garagem",
40
+ "real-estate",
41
+ "sdk",
42
+ "nextjs",
43
+ "headless",
44
+ "imoveis"
45
+ ]
46
+ }
package/src/client.ts ADDED
@@ -0,0 +1,145 @@
1
+ import {
2
+ getListing,
3
+ getListings,
4
+ getSite,
5
+ searchListings,
6
+ type FetchLike,
7
+ type GetListingOptions,
8
+ type GetListingsOptions,
9
+ type GetSiteOptions,
10
+ type SearchListingsOptions,
11
+ } from "./fetchers";
12
+ import type {
13
+ ListingDetail,
14
+ ListingFilters,
15
+ ListingsResult,
16
+ RequestNextOptions,
17
+ SearchListingsParams,
18
+ SearchListingsResult,
19
+ Site,
20
+ } from "./types";
21
+
22
+ export interface CreateGaragemClientOptions {
23
+ /** Garagem API base URL. Defaults to `https://app.garagem.ai`. */
24
+ baseUrl?: string;
25
+ /** Pre-bind a site so each call doesn't repeat it. */
26
+ siteId?: string;
27
+ /** Custom fetch implementation. */
28
+ fetch?: FetchLike;
29
+ /** Default Next.js caching hints applied to every request. */
30
+ next?: RequestNextOptions;
31
+ }
32
+
33
+ export interface GaragemClient {
34
+ /** Configuration the client was created with. */
35
+ readonly options: Readonly<CreateGaragemClientOptions>;
36
+ /** List listings for the bound (or explicitly passed) site. */
37
+ getListings(
38
+ args?: { filters?: ListingFilters; siteId?: string; next?: RequestNextOptions }
39
+ ): Promise<ListingsResult>;
40
+ /** Fetch a single listing detail. */
41
+ getListing(
42
+ args: { listingId: string; siteId?: string; next?: RequestNextOptions }
43
+ ): Promise<ListingDetail>;
44
+ /** Resolve a site by ID or domain. */
45
+ getSite(
46
+ args: { siteId?: string; domain?: string; next?: RequestNextOptions }
47
+ ): Promise<Site | null>;
48
+ /**
49
+ * Advanced search — raw Typesense parameters, raw response. Use when
50
+ * the friendly `getListings({ filters })` API isn't expressive enough.
51
+ */
52
+ searchListings<TDocument = Record<string, unknown>>(
53
+ args: {
54
+ params: SearchListingsParams;
55
+ siteId?: string;
56
+ next?: RequestNextOptions;
57
+ }
58
+ ): Promise<SearchListingsResult<TDocument>>;
59
+ }
60
+
61
+ /**
62
+ * Bind base URL, fetch and site to a single client object. Useful when
63
+ * the same configuration is shared across many calls (RSC pages, API
64
+ * routes, scripts).
65
+ *
66
+ * The bare functions (`getListings`, `getListing`, `getSite`) are also
67
+ * exported for the no-client style.
68
+ */
69
+ export function createGaragemClient(
70
+ options: CreateGaragemClientOptions = {}
71
+ ): GaragemClient {
72
+ const resolveSiteId = (override?: string): string => {
73
+ const id = override ?? options.siteId;
74
+ if (!id) {
75
+ throw new TypeError(
76
+ "Garagem SDK: siteId is required — pass it to createGaragemClient or to the call itself."
77
+ );
78
+ }
79
+ return id;
80
+ };
81
+ const mergeNext = (
82
+ callNext?: RequestNextOptions
83
+ ): RequestNextOptions | undefined => {
84
+ if (!options.next && !callNext) return undefined;
85
+ return { ...options.next, ...callNext };
86
+ };
87
+
88
+ // All methods are `async` so validation failures (e.g. missing siteId)
89
+ // surface as promise rejections rather than synchronous throws. SDK
90
+ // callers always `await` — this keeps error handling predictable.
91
+ return {
92
+ options: Object.freeze({ ...options }),
93
+ async getListings({ filters, siteId, next } = {}) {
94
+ const opts: GetListingsOptions = {
95
+ siteId: resolveSiteId(siteId),
96
+ };
97
+ if (filters !== undefined) opts.filters = filters;
98
+ if (options.baseUrl !== undefined) opts.baseUrl = options.baseUrl;
99
+ if (options.fetch !== undefined) opts.fetch = options.fetch;
100
+ const merged = mergeNext(next);
101
+ if (merged !== undefined) opts.next = merged;
102
+ return getListings(opts);
103
+ },
104
+ async getListing({ listingId, siteId, next }) {
105
+ const opts: GetListingOptions = {
106
+ siteId: resolveSiteId(siteId),
107
+ listingId,
108
+ };
109
+ if (options.baseUrl !== undefined) opts.baseUrl = options.baseUrl;
110
+ if (options.fetch !== undefined) opts.fetch = options.fetch;
111
+ const merged = mergeNext(next);
112
+ if (merged !== undefined) opts.next = merged;
113
+ return getListing(opts);
114
+ },
115
+ async getSite({ siteId, domain, next }) {
116
+ const opts: GetSiteOptions = {};
117
+ if (siteId !== undefined) opts.siteId = siteId;
118
+ if (domain !== undefined) opts.domain = domain;
119
+ if (options.baseUrl !== undefined) opts.baseUrl = options.baseUrl;
120
+ if (options.fetch !== undefined) opts.fetch = options.fetch;
121
+ const merged = mergeNext(next);
122
+ if (merged !== undefined) opts.next = merged;
123
+ return getSite(opts);
124
+ },
125
+ async searchListings<TDocument = Record<string, unknown>>({
126
+ params,
127
+ siteId,
128
+ next,
129
+ }: {
130
+ params: SearchListingsParams;
131
+ siteId?: string;
132
+ next?: RequestNextOptions;
133
+ }) {
134
+ const opts: SearchListingsOptions = {
135
+ siteId: resolveSiteId(siteId),
136
+ params,
137
+ };
138
+ if (options.baseUrl !== undefined) opts.baseUrl = options.baseUrl;
139
+ if (options.fetch !== undefined) opts.fetch = options.fetch;
140
+ const merged = mergeNext(next);
141
+ if (merged !== undefined) opts.next = merged;
142
+ return searchListings<TDocument>(opts);
143
+ },
144
+ };
145
+ }
@@ -0,0 +1,244 @@
1
+ import type {
2
+ Listing,
3
+ ListingDetail,
4
+ ListingFilters,
5
+ ListingsResult,
6
+ RequestNextOptions,
7
+ SearchListingsParams,
8
+ SearchListingsResult,
9
+ Site,
10
+ } from "./types";
11
+ import {
12
+ buildListingFiltersQuery,
13
+ normalizeBaseUrl,
14
+ } from "./internal/url";
15
+
16
+ /** Custom fetch implementation. Defaults to the global `fetch`. */
17
+ export type FetchLike = typeof fetch;
18
+
19
+ interface BaseOptions {
20
+ /** Garagem API base URL. Defaults to `https://app.garagem.ai`. */
21
+ baseUrl?: string;
22
+ /** Override the fetch implementation (testing, edge runtimes, retries). */
23
+ fetch?: FetchLike;
24
+ /**
25
+ * Next.js App Router caching hints. Ignored on runtimes that don't
26
+ * understand them.
27
+ */
28
+ next?: RequestNextOptions;
29
+ }
30
+
31
+ export interface GetListingsOptions extends BaseOptions {
32
+ siteId: string;
33
+ filters?: ListingFilters;
34
+ }
35
+
36
+ export interface GetListingOptions extends BaseOptions {
37
+ siteId: string;
38
+ listingId: string;
39
+ }
40
+
41
+ export interface GetSiteOptions extends BaseOptions {
42
+ /** Look up by site ID, or… */
43
+ siteId?: string;
44
+ /** …by domain. Exactly one of `siteId` / `domain` must be provided. */
45
+ domain?: string;
46
+ }
47
+
48
+ export interface SearchListingsOptions extends BaseOptions {
49
+ siteId: string;
50
+ params: SearchListingsParams;
51
+ }
52
+
53
+ interface FetchInit extends RequestInit {
54
+ /**
55
+ * Next.js attaches this on `fetch` (App Router). Adding it here keeps
56
+ * `RequestInit` typed without forcing consumers to install Next types.
57
+ */
58
+ next?: RequestNextOptions;
59
+ }
60
+
61
+ async function callJson<T>(
62
+ url: string,
63
+ init: FetchInit,
64
+ fetchImpl: FetchLike
65
+ ): Promise<T> {
66
+ const response = await fetchImpl(url, init);
67
+ if (!response.ok) {
68
+ const text = await response.text().catch(() => "");
69
+ throw new GaragemSdkError(
70
+ `Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${
71
+ text ? ` — ${text.slice(0, 200)}` : ""
72
+ }`,
73
+ { status: response.status, url }
74
+ );
75
+ }
76
+ return (await response.json()) as T;
77
+ }
78
+
79
+ /** Error thrown when a fetcher hits a non-2xx response. */
80
+ export class GaragemSdkError extends Error {
81
+ readonly status: number;
82
+ readonly url: string;
83
+ constructor(message: string, info: { status: number; url: string }) {
84
+ super(message);
85
+ this.name = "GaragemSdkError";
86
+ this.status = info.status;
87
+ this.url = info.url;
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Fetch a paginated list of listings for a given site.
93
+ *
94
+ * @example
95
+ * const { listings } = await getListings({
96
+ * siteId: "abc",
97
+ * filters: { city: "São Paulo", limit: 24 },
98
+ * next: { revalidate: 300, tags: [`site:abc:listings`] },
99
+ * });
100
+ */
101
+ export async function getListings(
102
+ options: GetListingsOptions
103
+ ): Promise<ListingsResult> {
104
+ const { siteId, filters, baseUrl, fetch: fetchImpl, next } = options;
105
+ const base = normalizeBaseUrl(baseUrl);
106
+ const params = buildListingFiltersQuery(filters);
107
+ const qs = params.size > 0 ? `?${params.toString()}` : "";
108
+ const url = `${base}/api/sites/${encodeURIComponent(siteId)}/listings${qs}`;
109
+
110
+ const data = await callJson<{ listings?: Listing[]; total?: number }>(
111
+ url,
112
+ { method: "GET", headers: { "Content-Type": "application/json" }, next },
113
+ fetchImpl ?? fetch
114
+ );
115
+ return {
116
+ listings: data.listings ?? [],
117
+ total: data.total ?? 0,
118
+ };
119
+ }
120
+
121
+ /**
122
+ * Fetch a single listing's full detail (amenities, gallery, building).
123
+ */
124
+ export async function getListing(
125
+ options: GetListingOptions
126
+ ): Promise<ListingDetail> {
127
+ const { siteId, listingId, baseUrl, fetch: fetchImpl, next } = options;
128
+ const base = normalizeBaseUrl(baseUrl);
129
+ const url = `${base}/api/sites/${encodeURIComponent(siteId)}/listings/${encodeURIComponent(
130
+ listingId
131
+ )}`;
132
+
133
+ return callJson<ListingDetail>(
134
+ url,
135
+ { method: "GET", headers: { "Content-Type": "application/json" }, next },
136
+ fetchImpl ?? fetch
137
+ );
138
+ }
139
+
140
+ /**
141
+ * Resolve a site's public profile by ID or by domain. Returns `null`
142
+ * when the site does not exist or the host is unrecognized.
143
+ *
144
+ * @example
145
+ * const site = await getSite({ domain: "imobiliariax.com.br" });
146
+ * if (!site) return notFound();
147
+ */
148
+ export async function getSite(
149
+ options: GetSiteOptions
150
+ ): Promise<Site | null> {
151
+ const { siteId, domain, baseUrl, fetch: fetchImpl, next } = options;
152
+ if (!siteId && !domain) {
153
+ throw new TypeError(
154
+ "getSite: provide exactly one of `siteId` or `domain`."
155
+ );
156
+ }
157
+ if (siteId && domain) {
158
+ throw new TypeError(
159
+ "getSite: provide only one of `siteId` or `domain`, not both."
160
+ );
161
+ }
162
+
163
+ const base = normalizeBaseUrl(baseUrl);
164
+ const params = new URLSearchParams();
165
+ if (siteId) params.set("siteId", siteId);
166
+ if (domain) params.set("domain", domain);
167
+ const url = `${base}/api/sites/resolve?${params.toString()}`;
168
+
169
+ const f = fetchImpl ?? fetch;
170
+ const response = await f(url, {
171
+ method: "GET",
172
+ headers: { "Content-Type": "application/json" },
173
+ next,
174
+ } as FetchInit);
175
+ if (response.status === 404) return null;
176
+ if (!response.ok) {
177
+ throw new GaragemSdkError(
178
+ `Garagem SDK: getSite failed (${response.status}) for ${url}`,
179
+ { status: response.status, url }
180
+ );
181
+ }
182
+ const data = (await response.json()) as {
183
+ id: string;
184
+ name: string;
185
+ domain: string | null;
186
+ tenantId: string;
187
+ };
188
+ return {
189
+ id: data.id,
190
+ name: data.name,
191
+ domain: data.domain,
192
+ tenantId: data.tenantId,
193
+ };
194
+ }
195
+
196
+ /**
197
+ * Advanced search escape hatch.
198
+ *
199
+ * Calls `POST /api/sites/{siteId}/search` directly and returns the raw
200
+ * Typesense response (`{ found, page, hits: [{ document, ... }], ... }`).
201
+ * Use when the friendly `getListings({ filters })` API isn't expressive
202
+ * enough — faceted search, multi-field sort, custom grouping, etc.
203
+ *
204
+ * @example
205
+ * const result = await searchListings({
206
+ * siteId: "abc",
207
+ * params: {
208
+ * q: "frente mar",
209
+ * query_by: "title,description,neighborhood",
210
+ * filter_by: "businessType:=sale && bedrooms:>=3",
211
+ * sort_by: "price:asc",
212
+ * per_page: 24,
213
+ * page: 1,
214
+ * facet_by: "neighborhood,propertyType",
215
+ * },
216
+ * });
217
+ * for (const hit of result.hits) {
218
+ * console.log(hit.document, hit.highlight);
219
+ * }
220
+ */
221
+ export async function searchListings<
222
+ TDocument = Record<string, unknown>,
223
+ >(
224
+ options: SearchListingsOptions
225
+ ): Promise<SearchListingsResult<TDocument>> {
226
+ const { siteId, params, baseUrl, fetch: fetchImpl, next } = options;
227
+ if (!params || typeof params.q !== "string") {
228
+ throw new TypeError(
229
+ "Garagem SDK: searchListings requires `params.q` (Typesense query string)."
230
+ );
231
+ }
232
+ const base = normalizeBaseUrl(baseUrl);
233
+ const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search`;
234
+ return callJson<SearchListingsResult<TDocument>>(
235
+ url,
236
+ {
237
+ method: "POST",
238
+ headers: { "Content-Type": "application/json" },
239
+ body: JSON.stringify(params),
240
+ next,
241
+ },
242
+ fetchImpl ?? fetch
243
+ );
244
+ }