@proxima-io/storefront-core 0.3.0 → 0.8.2

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.
Files changed (178) hide show
  1. package/README.md +68 -17
  2. package/dist/addresses/address-book.d.ts +36 -0
  3. package/dist/addresses/address-book.d.ts.map +1 -0
  4. package/dist/addresses/address-book.js +62 -0
  5. package/dist/addresses/address-book.js.map +1 -0
  6. package/dist/analytics/analytics.d.ts +28 -0
  7. package/dist/analytics/analytics.d.ts.map +1 -0
  8. package/dist/analytics/analytics.js +124 -0
  9. package/dist/analytics/analytics.js.map +1 -0
  10. package/dist/analytics/attribution.d.ts +28 -0
  11. package/dist/analytics/attribution.d.ts.map +1 -0
  12. package/dist/analytics/attribution.js +116 -0
  13. package/dist/analytics/attribution.js.map +1 -0
  14. package/dist/analytics/session.d.ts +12 -0
  15. package/dist/analytics/session.d.ts.map +1 -0
  16. package/dist/analytics/session.js +62 -0
  17. package/dist/analytics/session.js.map +1 -0
  18. package/dist/analytics/trackers.d.ts +29 -0
  19. package/dist/analytics/trackers.d.ts.map +1 -0
  20. package/dist/analytics/trackers.js +30 -0
  21. package/dist/analytics/trackers.js.map +1 -0
  22. package/dist/api/endpoints.d.ts +70 -0
  23. package/dist/api/endpoints.d.ts.map +1 -0
  24. package/dist/api/endpoints.js +70 -0
  25. package/dist/api/endpoints.js.map +1 -0
  26. package/dist/api/index.d.ts +3 -0
  27. package/dist/api/index.d.ts.map +1 -0
  28. package/dist/api/index.js +3 -0
  29. package/dist/api/index.js.map +1 -0
  30. package/dist/api/storefront-client.d.ts +50 -0
  31. package/dist/api/storefront-client.d.ts.map +1 -0
  32. package/dist/api/storefront-client.js +123 -0
  33. package/dist/api/storefront-client.js.map +1 -0
  34. package/dist/buyer/auth.d.ts +105 -0
  35. package/dist/buyer/auth.d.ts.map +1 -0
  36. package/dist/buyer/auth.js +215 -0
  37. package/dist/buyer/auth.js.map +1 -0
  38. package/dist/cache/cache.d.ts +31 -0
  39. package/dist/cache/cache.d.ts.map +1 -0
  40. package/dist/cache/cache.js +71 -0
  41. package/dist/cache/cache.js.map +1 -0
  42. package/dist/campaign/countdown.d.ts +40 -0
  43. package/dist/campaign/countdown.d.ts.map +1 -0
  44. package/dist/campaign/countdown.js +71 -0
  45. package/dist/campaign/countdown.js.map +1 -0
  46. package/dist/cart/cart.d.ts +57 -0
  47. package/dist/cart/cart.d.ts.map +1 -0
  48. package/dist/cart/cart.js +64 -0
  49. package/dist/cart/cart.js.map +1 -0
  50. package/dist/catalog/listings.d.ts +87 -0
  51. package/dist/catalog/listings.d.ts.map +1 -0
  52. package/dist/catalog/listings.js +140 -0
  53. package/dist/catalog/listings.js.map +1 -0
  54. package/dist/cms/payment-methods.d.ts +13 -0
  55. package/dist/cms/payment-methods.d.ts.map +1 -0
  56. package/dist/cms/payment-methods.js +41 -0
  57. package/dist/cms/payment-methods.js.map +1 -0
  58. package/dist/cms/website.d.ts +76 -0
  59. package/dist/cms/website.d.ts.map +1 -0
  60. package/dist/cms/website.js +146 -0
  61. package/dist/cms/website.js.map +1 -0
  62. package/dist/cookie-consent/consent.d.ts +22 -0
  63. package/dist/cookie-consent/consent.d.ts.map +1 -0
  64. package/dist/cookie-consent/consent.js +93 -0
  65. package/dist/cookie-consent/consent.js.map +1 -0
  66. package/dist/index.d.ts +45 -1310
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +42 -1576
  69. package/dist/index.js.map +1 -1
  70. package/dist/internal/http.d.ts +5 -0
  71. package/dist/internal/http.d.ts.map +1 -0
  72. package/dist/internal/http.js +27 -0
  73. package/dist/internal/http.js.map +1 -0
  74. package/dist/orders/guest.d.ts +9 -0
  75. package/dist/orders/guest.d.ts.map +1 -0
  76. package/dist/orders/guest.js +30 -0
  77. package/dist/orders/guest.js.map +1 -0
  78. package/dist/orders/orders.d.ts +23 -0
  79. package/dist/orders/orders.d.ts.map +1 -0
  80. package/dist/orders/orders.js +33 -0
  81. package/dist/orders/orders.js.map +1 -0
  82. package/dist/seo/engine-url.d.ts +26 -0
  83. package/dist/seo/engine-url.d.ts.map +1 -0
  84. package/dist/seo/engine-url.js +111 -0
  85. package/dist/seo/engine-url.js.map +1 -0
  86. package/dist/seo/hreflang.d.ts +19 -0
  87. package/dist/seo/hreflang.d.ts.map +1 -0
  88. package/dist/seo/hreflang.js +52 -0
  89. package/dist/seo/hreflang.js.map +1 -0
  90. package/dist/seo/indexnow.d.ts +24 -0
  91. package/dist/seo/indexnow.d.ts.map +1 -0
  92. package/dist/seo/indexnow.js +50 -0
  93. package/dist/seo/indexnow.js.map +1 -0
  94. package/dist/seo/json-ld.d.ts +57 -0
  95. package/dist/seo/json-ld.d.ts.map +1 -0
  96. package/dist/seo/json-ld.js +180 -0
  97. package/dist/seo/json-ld.js.map +1 -0
  98. package/dist/seo/page-seo.d.ts +21 -0
  99. package/dist/seo/page-seo.d.ts.map +1 -0
  100. package/dist/seo/page-seo.js +68 -0
  101. package/dist/seo/page-seo.js.map +1 -0
  102. package/dist/seo/robots.d.ts +23 -0
  103. package/dist/seo/robots.d.ts.map +1 -0
  104. package/dist/seo/robots.js +35 -0
  105. package/dist/seo/robots.js.map +1 -0
  106. package/dist/seo/sitemap.d.ts +35 -0
  107. package/dist/seo/sitemap.d.ts.map +1 -0
  108. package/dist/seo/sitemap.js +186 -0
  109. package/dist/seo/sitemap.js.map +1 -0
  110. package/dist/server/process.d.ts +136 -0
  111. package/dist/server/process.d.ts.map +1 -0
  112. package/dist/server/process.js +143 -0
  113. package/dist/server/process.js.map +1 -0
  114. package/dist/types/address.d.ts +40 -0
  115. package/dist/types/address.d.ts.map +1 -0
  116. package/dist/types/address.js +2 -0
  117. package/dist/types/address.js.map +1 -0
  118. package/dist/types/analytics.d.ts +79 -0
  119. package/dist/types/analytics.d.ts.map +1 -0
  120. package/dist/types/analytics.js +2 -0
  121. package/dist/types/analytics.js.map +1 -0
  122. package/dist/types/business.d.ts +95 -0
  123. package/dist/types/business.d.ts.map +1 -0
  124. package/dist/types/business.js +2 -0
  125. package/dist/types/business.js.map +1 -0
  126. package/dist/types/buyer.d.ts +144 -0
  127. package/dist/types/buyer.d.ts.map +1 -0
  128. package/dist/types/buyer.js +45 -0
  129. package/dist/types/buyer.js.map +1 -0
  130. package/dist/types/campaign.d.ts +51 -0
  131. package/dist/types/campaign.d.ts.map +1 -0
  132. package/dist/types/campaign.js +2 -0
  133. package/dist/types/campaign.js.map +1 -0
  134. package/dist/types/cart.d.ts +40 -0
  135. package/dist/types/cart.d.ts.map +1 -0
  136. package/dist/types/cart.js +2 -0
  137. package/dist/types/cart.js.map +1 -0
  138. package/dist/types/catalog.d.ts +164 -0
  139. package/dist/types/catalog.d.ts.map +1 -0
  140. package/dist/types/catalog.js +2 -0
  141. package/dist/types/catalog.js.map +1 -0
  142. package/dist/types/cms.d.ts +200 -0
  143. package/dist/types/cms.d.ts.map +1 -0
  144. package/dist/types/cms.js +2 -0
  145. package/dist/types/cms.js.map +1 -0
  146. package/dist/types/cookie-consent.d.ts +18 -0
  147. package/dist/types/cookie-consent.d.ts.map +1 -0
  148. package/dist/types/cookie-consent.js +7 -0
  149. package/dist/types/cookie-consent.js.map +1 -0
  150. package/dist/types/guest-order.d.ts +16 -0
  151. package/dist/types/guest-order.d.ts.map +1 -0
  152. package/dist/types/guest-order.js +9 -0
  153. package/dist/types/guest-order.js.map +1 -0
  154. package/dist/types/listing.d.ts +14 -0
  155. package/dist/types/listing.d.ts.map +1 -0
  156. package/dist/types/listing.js +2 -0
  157. package/dist/types/listing.js.map +1 -0
  158. package/dist/types/order.d.ts +40 -0
  159. package/dist/types/order.d.ts.map +1 -0
  160. package/dist/types/order.js +2 -0
  161. package/dist/types/order.js.map +1 -0
  162. package/dist/types/seo.d.ts +96 -0
  163. package/dist/types/seo.d.ts.map +1 -0
  164. package/dist/types/seo.js +2 -0
  165. package/dist/types/seo.js.map +1 -0
  166. package/dist/types/server-env.d.ts +19 -0
  167. package/dist/types/server-env.d.ts.map +1 -0
  168. package/dist/types/server-env.js +10 -0
  169. package/dist/types/server-env.js.map +1 -0
  170. package/dist/types/wishlist.d.ts +10 -0
  171. package/dist/types/wishlist.d.ts.map +1 -0
  172. package/dist/types/wishlist.js +2 -0
  173. package/dist/types/wishlist.js.map +1 -0
  174. package/dist/wishlist/wishlist.d.ts +28 -0
  175. package/dist/wishlist/wishlist.d.ts.map +1 -0
  176. package/dist/wishlist/wishlist.js +42 -0
  177. package/dist/wishlist/wishlist.js.map +1 -0
  178. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,1311 +1,46 @@
1
- export interface ProximaApiConfig {
2
- baseUrl: string;
3
- domain: string;
4
- path: string;
5
- websiteId?: string;
6
- businessId?: string;
7
- serviceKey?: string;
8
- /** UUID of a content variant — when set, composition returns the variant snapshot instead of live content. */
9
- variantId?: string;
10
- /** Preview token obtained from the rotate endpoint. Required when variantId is set. */
11
- previewToken?: string;
12
- }
13
- export interface ProximaPageSummary {
14
- name: string;
15
- path: string;
16
- resolver_kind: string;
17
- is_active: boolean;
18
- }
19
- export interface ProximaWebsiteResponse {
20
- id: string;
21
- business_id: string;
22
- name: string;
23
- domain: string;
24
- subdomain_slug?: string | null;
25
- custom_domain?: string | null;
26
- publication_status?: string;
27
- published_at?: string | null;
28
- delivery_mode: string;
29
- data_mode?: string | null;
30
- website_kind: string;
31
- template_key?: string | null;
32
- code_profile?: string | null;
33
- locale: string;
34
- currency: string;
35
- og_image_url?: string | null;
36
- logo_url?: string | null;
37
- favicon_url?: string | null;
38
- twitter_handle?: string | null;
39
- capabilities: Record<string, any>;
40
- theme_tokens: Record<string, any>;
41
- animation_config: Record<string, any>;
42
- pages: ProximaPageSummary[];
43
- shell_sections?: Record<string, {
44
- section_id: number;
45
- section_type: string;
46
- section_name: string;
47
- attributes: Record<string, any>;
48
- }>;
49
- }
50
- export interface ProximaCompositionResponse {
51
- page_id: number;
52
- website_id: string;
53
- path: string;
54
- path_template: string;
55
- name: string;
56
- entity_type?: string | null;
57
- resolver_kind?: string | null;
58
- route_params: Record<string, string>;
59
- resolved_data?: Record<string, any> | null;
60
- sections: Array<{
61
- id: number;
62
- name: string;
63
- type: string;
64
- order: number;
65
- attributes: Record<string, any>;
66
- attributes_meta?: Record<string, any>;
67
- }>;
68
- seo?: Record<string, any> | null;
69
- }
70
- export interface ProximaProductListResponse {
71
- items: any[];
72
- total: number;
73
- page: number;
74
- size: number;
75
- }
76
- /**
77
- * Fully resolved SEO metadata for a single page.
78
- * Produced by `buildPageSeo()` — pass directly to `SiteLayout.astro`.
79
- */
80
- export interface PageSeoMeta {
81
- /** `<title>` tag content */
82
- title: string;
83
- /** `meta[name="description"]` */
84
- description: string;
85
- /** og:title */
86
- ogTitle: string;
87
- /** og:description */
88
- ogDescription: string;
89
- /** og:image and twitter:image — null when no image is available */
90
- ogImage: string | null;
91
- /** og:type — "website" | "product" */
92
- ogType: string;
93
- /** og:site_name */
94
- ogSiteName: string;
95
- /** og:url and link[rel="canonical"] */
96
- canonicalUrl: string;
97
- /** meta[name="robots"] — "index, follow" | "noindex, nofollow" */
98
- robots: string;
99
- /** twitter:card */
100
- twitterCard: string;
101
- /** twitter:site — "@handle" or null */
102
- twitterSite: string | null;
103
- /** twitter:image — mirrors ogImage */
104
- twitterImage: string | null;
105
- /** link[rel="icon"] — null when not set */
106
- faviconUrl: string | null;
107
- }
108
- /**
109
- * Minimal website surface required by `buildPageSeo()`.
110
- * Both `ProximaWebsiteResponse` and the storefront's `ResolvedWebsite` satisfy this.
111
- */
112
- export interface PageSeoWebsiteMeta {
113
- name: string;
114
- og_image_url?: string | null;
115
- favicon_url?: string | null;
116
- twitter_handle?: string | null;
117
- }
118
- /**
119
- * Build fully resolved SEO metadata for a page.
120
- *
121
- * Data priority:
122
- * 1. Admin-set `PageSEO` fields in `composition.seo` (explicit overrides)
123
- * 2. Entity-derived data in `composition.seo.entity_name` / `entity_image` (auto-populated by API)
124
- * 3. Website-level defaults (`website.og_image_url`, etc.)
125
- * 4. Hard fallbacks (empty strings)
126
- *
127
- * @param seoData The `seo` object from `ProximaCompositionResponse` (may be null)
128
- * @param website Website-level SEO fields
129
- * @param locale Locale code for resolving localized strings (e.g. "es")
130
- * @param currentUrl Absolute URL of the current page — used as canonical fallback
131
- *
132
- * @example
133
- * const seo = buildPageSeo(composition.seo, website, website.locale, canonicalUrl);
134
- * // → pass to <SiteLayout seo={seo} />
135
- */
136
- export declare function buildPageSeo(seoData: Record<string, any> | null | undefined, website: PageSeoWebsiteMeta, locale: string, currentUrl: string): PageSeoMeta;
137
- /**
138
- * Minimal website surface required by the JSON-LD builders.
139
- * Both `ProximaWebsiteResponse` and the storefront's `ResolvedWebsite` satisfy this.
140
- */
141
- export interface JsonLdWebsiteMeta {
142
- name: string;
143
- domain: string;
144
- logo_url?: string | null;
145
- twitter_handle?: string | null;
146
- }
147
- /**
148
- * Minimal product surface required by `buildProductJsonLd()`.
149
- */
150
- export interface JsonLdProductMeta {
151
- name: string;
152
- slug: string;
153
- description?: string | null;
154
- image?: string | null;
155
- images?: (string | null | undefined)[] | null;
156
- sku?: string | null;
157
- brand?: string | null;
158
- productId?: number | string | null;
159
- priceRaw: number;
160
- compareAtPrice?: number | null;
161
- inStock?: boolean | null;
162
- }
163
- /**
164
- * A single breadcrumb item.
165
- */
166
- export interface BreadcrumbItem {
167
- label: string;
168
- /** Relative or absolute href — omit for the last (current) item */
169
- href?: string;
170
- }
171
- /**
172
- * Build a `WebSite` JSON-LD object.
173
- * Enables Google's Search Action box in SERPs.
174
- *
175
- * @example
176
- * <script type="application/ld+json" set:html={JSON.stringify(buildWebSiteJsonLd(website))} />
177
- */
178
- export declare function buildWebSiteJsonLd(website: JsonLdWebsiteMeta): Record<string, any>;
179
- /**
180
- * Build an `Organization` JSON-LD object.
181
- * Returns `null` when `website.logo_url` is absent (Google ignores logo-less org markup).
182
- *
183
- * @example
184
- * {orgJsonLd && <script type="application/ld+json" set:html={JSON.stringify(orgJsonLd)} />}
185
- */
186
- export declare function buildOrganizationJsonLd(website: JsonLdWebsiteMeta): Record<string, any> | null;
187
- /**
188
- * Build a `Product` JSON-LD object for a product detail page.
189
- * Includes `Offer` with pricing, currency, and availability.
190
- *
191
- * @example
192
- * <script type="application/ld+json" set:html={JSON.stringify(buildProductJsonLd(product, website))} />
193
- */
194
- export declare function buildProductJsonLd(product: JsonLdProductMeta, website: {
195
- domain: string;
196
- currency: string;
197
- }): Record<string, any>;
198
- /**
199
- * Build a `BreadcrumbList` JSON-LD object.
200
- *
201
- * @param items Array of breadcrumb steps. The last item typically has no `href`.
202
- * @param siteUrl Absolute site URL, e.g. `https://example.com`
203
- *
204
- * @example
205
- * const crumbs = buildBreadcrumbJsonLd(
206
- * [{ label: "Inicio", href: "/" }, { label: "Zapatos", href: "/categoria/zapatos" }, { label: "Nike Air Max" }],
207
- * `https://${website.domain}`
208
- * );
209
- * <script type="application/ld+json" set:html={JSON.stringify(crumbs)} />
210
- */
211
- export declare function buildBreadcrumbJsonLd(items: BreadcrumbItem[], siteUrl: string): Record<string, any>;
212
- /**
213
- * Minimal surface for a LocalBusiness JSON-LD block (typically emitted by the Footer).
214
- * All fields are optional — only the ones present will appear in the output.
215
- */
216
- export interface JsonLdLocalBusinessMeta {
217
- name: string;
218
- url: string;
219
- image?: string | null;
220
- telephone?: string | null;
221
- street_address?: string | null;
222
- address_locality?: string | null;
223
- address_region?: string | null;
224
- postal_code?: string | null;
225
- address_country?: string | null;
226
- latitude?: number | null;
227
- longitude?: number | null;
228
- opening_hours?: string[] | null;
229
- opens?: string | null;
230
- closes?: string | null;
231
- social_links?: string[] | null;
232
- }
233
- /**
234
- * Build a `LocalBusiness` JSON-LD object for brick-and-mortar stores.
235
- * Returns `null` when `seo` is falsy so callers can gate rendering easily.
236
- *
237
- * @example
238
- * const schema = buildLocalBusinessJsonLd(seo);
239
- * {schema && <script type="application/ld+json" set:html={JSON.stringify(schema)} />}
240
- */
241
- export declare function buildLocalBusinessJsonLd(seo: JsonLdLocalBusinessMeta | null | undefined): Record<string, unknown> | null;
242
- /** Minimal website surface needed by the sitemap / robots generators */
243
- export interface SitemapWebsiteMeta {
244
- domain: string;
245
- pages?: Array<{
246
- resolver_kind: string;
247
- path?: string | null;
248
- }> | null;
249
- }
250
- /**
251
- * Generate a complete `sitemap.xml` for a storefront.
252
- *
253
- * Includes:
254
- * 1. Content pages from the website manifest (priority 1.0 for home, 0.8 for others)
255
- * 2. Category pages from the recursive nav tree (priority 0.8)
256
- * 3. Brand pages from the brands directory (priority 0.7)
257
- * 4. Product pages — paginated up to `maxProducts` (priority 0.9)
258
- *
259
- * All entries use today's date as `lastmod`.
260
- *
261
- * @param website Resolved website object (domain + pages array)
262
- * @param apiUrl Base URL of the Proxima API (e.g. `http://localhost:8000`)
263
- * @param options Optional overrides: pageSize (default 60), maxProducts (default 3000)
264
- *
265
- * @example
266
- * // apps/{slug}/src/pages/sitemap.xml.ts
267
- * import type { APIRoute } from "astro";
268
- * import { resolveWebsiteOnly } from "@/lib/resolver";
269
- * import { generateSitemapXml } from "@proxima-io/storefront-core";
270
- *
271
- * export const GET: APIRoute = async () => {
272
- * const website = await resolveWebsiteOnly();
273
- * const xml = await generateSitemapXml(website, import.meta.env.PROXIMA_API_URL ?? "http://localhost:8000");
274
- * return new Response(xml, {
275
- * headers: { "Content-Type": "application/xml; charset=utf-8", "Cache-Control": "public, s-maxage=3600, stale-while-revalidate=86400" },
276
- * });
277
- * };
278
- */
279
- export declare function generateSitemapXml(website: SitemapWebsiteMeta, apiUrl: string, options?: {
280
- pageSize?: number;
281
- maxProducts?: number;
282
- }): Promise<string>;
283
- /**
284
- * Generate a `robots.txt` for a storefront.
285
- *
286
- * Blocks all private buyer routes and API paths.
287
- * Adds a `Sitemap:` directive pointing to `{siteUrl}/sitemap.xml`.
288
- *
289
- * @example
290
- * // apps/{slug}/src/pages/robots.txt.ts
291
- * import type { APIRoute } from "astro";
292
- * import { resolveWebsiteOnly } from "@/lib/resolver";
293
- * import { generateRobotsTxt } from "@proxima-io/storefront-core";
294
- *
295
- * export const GET: APIRoute = async () => {
296
- * const website = await resolveWebsiteOnly();
297
- * return new Response(generateRobotsTxt(website), {
298
- * headers: { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "public, max-age=86400" },
299
- * });
300
- * };
301
- */
302
- export declare function generateRobotsTxt(website: {
303
- domain: string;
304
- }): string;
305
- /**
306
- * Submit a list of changed URLs to the IndexNow API.
307
- *
308
- * IndexNow notifies Bing, Yandex, and (increasingly) Google about new or
309
- * updated pages so they are re-crawled within seconds instead of waiting for
310
- * the next sitemap crawl.
311
- *
312
- * **Setup (one-time per storefront):**
313
- * 1. Generate or reuse the key from `PROXIMA_INDEXNOW_KEY` env var.
314
- * 2. Serve `GET /{key}.txt` returning the key as plain text — see the scaffold
315
- * template at `src/pages/[indexnow_key].txt.ts`.
316
- * 3. That's it — IndexNow verifies the key automatically on first submission.
317
- *
318
- * @param apiKey Your IndexNow key (platform-level; served at `/{apiKey}.txt`)
319
- * @param siteUrl Absolute origin of the site, e.g. `https://example.com`
320
- * @param urls Absolute URLs that changed (max 10 000 per call)
321
- *
322
- * @example
323
- * await notifyIndexNow("my-secret-key", "https://214store.com", [
324
- * "https://214store.com/producto/laptop-gamer",
325
- * ]);
326
- */
327
- export declare function notifyIndexNow(apiKey: string, siteUrl: string, urls: string[]): Promise<void>;
328
- /** List all websites for a service-key authenticated caller. Useful for build-time scripts. */
329
- export declare function fetchProximaWebsiteList(config: Pick<ProximaApiConfig, "baseUrl" | "serviceKey">): Promise<ProximaWebsiteResponse[]>;
330
- /**
331
- * Resolve a website by domain/host. Call this once per request and cache the result.
332
- * Pass `host` if the incoming request host differs from `config.domain` (e.g. in middleware).
333
- *
334
- * @example
335
- * const website = await fetchProximaWebsite({ baseUrl: env.apiUrl, domain: Astro.url.hostname });
336
- */
337
- export declare function fetchProximaWebsite(config: Pick<ProximaApiConfig, "baseUrl" | "domain" | "serviceKey"> & {
338
- host?: string;
339
- }): Promise<ProximaWebsiteResponse>;
340
- /**
341
- * Build a synthetic `ProximaWebsiteResponse` for the visual builder preview.
342
- * Use this when the builder passes `websiteId` and `businessId` via query params
343
- * instead of resolving by domain.
344
- */
345
- export declare function makeBuilderPreviewWebsite(config: Pick<ProximaApiConfig, "websiteId" | "businessId" | "domain">): ProximaWebsiteResponse;
346
- /**
347
- * Fetch the fully resolved page composition for the given path.
348
- * This is the main data-fetching call for every SSR page render.
349
- * The response embeds all section data (via smart collections) and, for detail pages,
350
- * the primary entity in `resolved_data` (product, category, brand, blog post).
351
- * No additional catalog API calls are needed for the initial render.
352
- *
353
- * @example
354
- * // src/pages/[...path].astro
355
- * const composition = await fetchProximaComposition(
356
- * { ...config, path: Astro.url.pathname },
357
- * website
358
- * );
359
- */
360
- export declare function fetchProximaComposition(config: ProximaApiConfig, website: ProximaWebsiteResponse): Promise<ProximaCompositionResponse>;
361
- /**
362
- * @deprecated Use `fetchStorefrontProducts` instead. This function calls the raw
363
- * catalog endpoint (`/api/v1/products`) which is not enriched for storefront use
364
- * (no price_formatted, no badge, no default_variant_id). It will be removed in a future version.
365
- */
366
- export declare function fetchProximaProducts(config: Pick<ProximaApiConfig, "baseUrl" | "serviceKey">, website: ProximaWebsiteResponse): Promise<ProximaProductListResponse>;
367
- /** Well-known error detail strings returned by the API. Use these for comparison
368
- * instead of hardcoding strings in your storefront.
369
- *
370
- * @example
371
- * try { await resetPassword(...) } catch (e: any) {
372
- * if (e.data?.detail === BUYER_AUTH_ERRORS.RESET_TOKEN_INVALID) { ... }
373
- * }
374
- */
375
- export declare const BUYER_AUTH_ERRORS: {
376
- readonly RESET_TOKEN_INVALID: "RESET_TOKEN_INVALID";
377
- readonly VERIFY_TOKEN_INVALID: "VERIFY_TOKEN_INVALID";
378
- readonly EMAIL_ALREADY_VERIFIED: "EMAIL_ALREADY_VERIFIED";
379
- readonly EMAIL_TAKEN: "Email already registered in this store";
380
- readonly MISSING_REQUIRED_FIELDS: "MISSING_REQUIRED_FIELDS";
381
- };
382
- /** Token pair returned by /store/auth/register, /store/auth/login, /store/auth/refresh */
383
- export interface BuyerSession {
384
- access_token: string;
385
- refresh_token: string | null;
386
- token_type: string;
387
- }
388
- /** Full customer profile from GET /store/me */
389
- export interface BuyerProfile {
390
- id: number;
391
- email: string;
392
- business_id: string;
393
- full_name: string | null;
394
- phone: string | null;
395
- doc_type: number | null;
396
- doc_number: string | null;
397
- birth_date: string | null;
398
- newsletter_subscribed: boolean;
399
- avatar_url: string | null;
400
- metadata: Record<string, any>;
401
- registration_source: string;
402
- last_login_at: string | null;
403
- is_active: boolean;
404
- created_at: string;
405
- updated_at: string;
406
- }
407
- /** A single resolved field in the storefront registration form. */
408
- export interface RegistrationFormField {
409
- name: string;
410
- label: string;
411
- /** "text" | "password" | "phone" | "date" | "select" | "boolean" | "image" | "address" | "custom" */
412
- type: string;
413
- /** "text_input" | "phone_input" | "date_picker" | "select" | "checkbox" | "toggle"
414
- * | "image_upload" | "ubigeo_selector" | "google_maps_picker" | "manual" */
415
- widget: string;
416
- widget_config: Record<string, any>;
417
- required: boolean;
418
- order: number;
419
- options: string[] | null;
420
- }
421
- /** A single step in the form (always at least one). */
422
- export interface RegistrationFormStep {
423
- id: string;
424
- label: string;
425
- order: number;
426
- skippable: boolean;
427
- fields: RegistrationFormField[];
428
- }
429
- /** Full resolved form schema from GET /store/auth/registration-form.
430
- * `email` and `password` are always present in steps[0].fields — no need to add them. */
431
- export interface RegistrationForm {
432
- mode: "single_step" | "multi_step";
433
- steps: RegistrationFormStep[];
434
- }
435
- /** Address submitted during customer registration. */
436
- export interface AddressInRegistration {
437
- line1: string;
438
- line2?: string | null;
439
- reference?: string | null;
440
- /** 6-digit Peruvian ubigeo code, e.g. "150101" */
441
- ubigeo_code?: string | null;
442
- latitude?: number | null;
443
- longitude?: number | null;
444
- /** "google_maps" | "ubigeo_centroid" | "manual" */
445
- geocoding_source?: string | null;
446
- }
447
- /** All accepted fields for POST /store/auth/register.
448
- * Which fields are required depends on the merchant's registration form configuration.
449
- * Use fetchRegistrationForm() to know which fields to show and which are required. */
450
- export interface BuyerRegisterParams {
451
- email: string;
452
- password: string;
453
- fullName?: string | null;
454
- phone?: string | null;
455
- /** 1=DNI 2=CE 3=Pasaporte 6=RUC */
456
- docType?: number | null;
457
- docNumber?: string | null;
458
- /** ISO date "YYYY-MM-DD" */
459
- birthDate?: string | null;
460
- newsletterSubscribed?: boolean;
461
- /** Default "organic". */
462
- registrationSource?: string;
463
- /** Custom fields configured by the merchant — keyed by field name. */
464
- metadata?: Record<string, any>;
465
- address?: AddressInRegistration | null;
466
- /** Cloudflare Turnstile token from the widget — required when API has TURNSTILE_ENABLED=true */
467
- captchaToken?: string | null;
468
- }
469
- /** A single field that was missing in the registration request. */
470
- export interface MissingField {
471
- field: string;
472
- msg: string;
473
- }
474
- /**
475
- * Thrown when the API returns 422 MISSING_REQUIRED_FIELDS.
476
- * Use `error.missingFields` to mark exactly which fields are invalid in the UI.
477
- *
478
- * @example
479
- * try {
480
- * await registerBuyer(config, website, params);
481
- * } catch (e) {
482
- * if (e instanceof MissingFieldsError) {
483
- * for (const { field } of e.missingFields) markFieldError(field);
484
- * }
485
- * }
486
- */
487
- export declare class MissingFieldsError extends Error {
488
- status: 422;
489
- missingFields: MissingField[];
490
- constructor(missingFields: MissingField[]);
491
- }
492
- /** Fields the customer can update via PATCH /store/me/profile. All optional. */
493
- export interface BuyerProfileUpdateParams {
494
- fullName?: string | null;
495
- phone?: string | null;
496
- /** 1=DNI 2=CE 3=Pasaporte 6=RUC */
497
- docType?: number | null;
498
- docNumber?: string | null;
499
- /** ISO date "YYYY-MM-DD" */
500
- birthDate?: string | null;
501
- newsletterSubscribed?: boolean;
502
- avatarUrl?: string | null;
503
- /** If provided, changes the customer's password. */
504
- password?: string;
505
- }
506
- /** Lightweight product representation used in listings, search results, and smart collections. */
507
- export interface StorefrontProductSummary {
508
- id: number;
509
- name: string;
510
- slug: string;
511
- price: number;
512
- price_formatted?: string | null;
513
- image_url: string;
514
- brand_name?: string | null;
515
- category_name?: string | null;
516
- /** Promotional badge text, e.g. "OFERTA", "NUEVO" */
517
- badge?: string | null;
518
- rating: number;
519
- currency?: string | null;
520
- /** First variant id — use this when calling addToCart from a listing card */
521
- default_variant_id?: number | null;
522
- }
523
- /** Pagination metadata returned by listing endpoints. */
524
- export interface StorefrontPagination {
525
- page: number;
526
- page_size: number;
527
- total: number;
528
- total_pages: number;
529
- }
530
- export interface StorefrontSortOption {
531
- value: string;
532
- label: string;
533
- }
534
- export interface StorefrontFacetOption {
535
- value: string;
536
- label: string;
537
- count: number;
538
- }
539
- /** Response from GET /storefront/search */
540
- export interface StorefrontSearchResponse {
541
- query: string;
542
- hits: StorefrontProductSummary[];
543
- total: number;
544
- }
545
- /** Response from GET /storefront/products (all-products listing with facets) */
546
- export interface StorefrontProductListingResponse {
547
- items: StorefrontProductSummary[];
548
- pagination: StorefrontPagination;
549
- sort_current: string;
550
- sort_options: StorefrontSortOption[];
551
- brand_facets: StorefrontFacetOption[];
552
- category_facets: StorefrontFacetOption[];
553
- }
554
- export interface StorefrontCategorySummary {
555
- id: number;
556
- name: string;
557
- slug: string;
558
- image_url?: string | null;
559
- }
560
- export interface StorefrontBrandSummary {
561
- id: number;
562
- name: string;
563
- slug: string;
564
- logo_url?: string | null;
565
- }
566
- /** Response from GET /storefront/categories/{slug}/products */
567
- export interface StorefrontCategoryListingResponse {
568
- category: StorefrontCategorySummary;
569
- items: StorefrontProductSummary[];
570
- pagination: StorefrontPagination;
571
- sort_current: string;
572
- sort_options: StorefrontSortOption[];
573
- brand_facets: StorefrontFacetOption[];
574
- }
575
- /** Response from GET /storefront/brands/{slug}/products */
576
- export interface StorefrontBrandListingResponse {
577
- brand: StorefrontBrandSummary;
578
- items: StorefrontProductSummary[];
579
- pagination: StorefrontPagination;
580
- sort_current: string;
581
- sort_options: StorefrontSortOption[];
582
- category_facets: StorefrontFacetOption[];
583
- }
584
- export interface StorefrontCategoryDirectoryItem {
585
- id: number;
586
- name: string;
587
- slug: string;
588
- href: string;
589
- image_url?: string | null;
590
- description?: string | null;
591
- product_count: number;
592
- }
593
- export interface StorefrontBrandDirectoryItem {
594
- id: number;
595
- name: string;
596
- slug: string;
597
- href: string;
598
- logo_url?: string | null;
599
- product_count: number;
600
- }
601
- export interface StorefrontCategoryDirectoryResponse {
602
- items: StorefrontCategoryDirectoryItem[];
603
- total: number;
604
- }
605
- export interface StorefrontBrandDirectoryResponse {
606
- items: StorefrontBrandDirectoryItem[];
607
- total: number;
608
- }
609
- /** Shared params for product listing endpoints — sort, pagination, filters. */
610
- export interface StorefrontListingParams {
611
- /** Page number, starting at 1 */
612
- page?: number;
613
- /** Items per page (1–60). Default: 24 */
614
- pageSize?: number;
615
- /** "newest" | "price_asc" | "price_desc" | "popular". Default: "newest" */
616
- sort?: string;
617
- /** Locale for translated names, e.g. "es", "en" */
618
- locale?: string;
619
- /** ISO currency code, e.g. "PEN", "USD" */
620
- currency?: string;
621
- }
622
- /** Coupon validation result from GET /commerce/coupons/validate */
623
- export interface CouponValidationResult {
624
- valid: boolean;
625
- code?: string;
626
- /** Amount to deduct from the order total */
627
- discount_amount?: number;
628
- /** "percentage" | "fixed" */
629
- discount_type?: string;
630
- discount_value?: number;
631
- /** Error message when valid=false */
632
- error?: string;
633
- }
634
- /** A line item inside a Cart. */
635
- export interface CartItem {
636
- id: number;
637
- product_variant_id: number;
638
- quantity: number;
639
- metadata?: {
640
- name?: string | null;
641
- slug?: string | null;
642
- brand?: string | null;
643
- image?: string | null;
644
- unit_price?: number | null;
645
- unit_price_string?: string | null;
646
- } | null;
647
- }
648
- export interface CartTotals {
649
- subtotal: number;
650
- formatted_subtotal: string;
651
- currency: string;
652
- }
653
- /** Shopping cart for a guest session or authenticated customer. */
654
- export interface Cart {
655
- id: string;
656
- session_id?: string | null;
657
- customer_id?: number | null;
658
- items: CartItem[];
659
- totals: CartTotals;
660
- }
661
- /** Customer and shipping details submitted at checkout. */
662
- export interface CheckoutRequest {
663
- customer_name: string;
664
- customer_phone: string;
665
- customer_email?: string | null;
666
- shipping_address?: string | null;
667
- notes?: string | null;
668
- coupon_code?: string | null;
669
- customer_doc_type?: number | null;
670
- customer_doc_number?: string | null;
671
- address_id?: number | null;
672
- }
673
- export interface UbigeoResult {
674
- code: string;
675
- department: string;
676
- province: string;
677
- district: string;
678
- full_name: string;
679
- }
680
- export interface CustomerAddress {
681
- id: number;
682
- customer_id: number;
683
- business_id: string;
684
- label?: string | null;
685
- recipient_name?: string | null;
686
- phone?: string | null;
687
- line1: string;
688
- line2?: string | null;
689
- ubigeo_code?: string | null;
690
- ubigeo?: UbigeoResult | null;
691
- reference?: string | null;
692
- latitude?: number | null;
693
- longitude?: number | null;
694
- geocoding_source?: string | null;
695
- is_default: boolean;
696
- created_at: string;
697
- updated_at: string;
698
- }
699
- export interface AddressInput {
700
- label?: string | null;
701
- recipient_name?: string | null;
702
- phone?: string | null;
703
- line1: string;
704
- line2?: string | null;
705
- ubigeo_code?: string | null;
706
- reference?: string | null;
707
- latitude?: number | null;
708
- longitude?: number | null;
709
- geocoding_source?: string | null;
710
- is_default?: boolean;
711
- }
712
- export interface OrderItem {
713
- id: number;
714
- product_variant_id?: number | null;
715
- product_id?: number | null;
716
- product_slug?: string | null;
717
- product_image?: string | null;
718
- product_name?: string | null;
719
- brand_name?: string | null;
720
- category_name?: string | null;
721
- sku?: string | null;
722
- quantity: number;
723
- price_at_purchase?: number | null;
724
- /** @deprecated use price_at_purchase */
725
- unit_price?: number | null;
726
- /** @deprecated use product_name */
727
- name?: string | null;
728
- }
729
- /** An order placed by a customer. */
730
- export interface Order {
731
- id: string;
732
- order_number?: string | null;
733
- status: string;
734
- total_amount?: number | null;
735
- currency?: string | null;
736
- customer_name?: string | null;
737
- customer_phone?: string | null;
738
- customer_email?: string | null;
739
- shipping_address?: string | null;
740
- created_at: string;
741
- items?: OrderItem[];
742
- /** @deprecated use total_amount */
743
- total?: number;
744
- }
745
- export interface OrderListResponse {
746
- items: Order[];
747
- total: number;
748
- page: number;
749
- size: number;
750
- }
751
- /** A single item in the customer's wishlist. */
752
- export interface WishlistItem {
753
- id: number;
754
- customer_id: number;
755
- business_id: string;
756
- product_id: string;
757
- variant_id: string | null;
758
- notes: string | null;
759
- added_at: string;
760
- }
761
- /**
762
- * Environment variables needed by server-side `process*` helpers.
763
- * Typically populated from `import.meta.env` in an Astro API route.
764
- */
765
- export interface BuyerServerEnv {
766
- apiUrl: string;
767
- domain: string;
768
- serviceKey?: string;
769
- }
770
- /** Recommended options for the buyer session cookie. Apply to both `buyer_token` and `buyer_refresh_token`. */
771
- export declare const BUYER_COOKIE_OPTIONS: {
772
- readonly path: "/";
773
- readonly httpOnly: true;
774
- readonly sameSite: "lax";
775
- readonly maxAge: number;
776
- };
777
- export declare const BUYER_COOKIE_NAME = "buyer_token";
778
- export declare const BUYER_REFRESH_COOKIE_NAME = "buyer_refresh_token";
779
- /**
780
- * Fetch the merchant-configured registration form schema.
781
- * Call this server-side in your /register page to know which fields to render
782
- * and which are required. `email` and `password` are always prepended by the API.
783
- *
784
- * @example
785
- * // src/pages/register.astro
786
- * const form = await fetchRegistrationForm({ baseUrl: env.apiUrl }, website);
787
- * // Pass `form` as a prop to a client component that renders the dynamic form
788
- */
789
- export declare function fetchRegistrationForm(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">): Promise<RegistrationForm>;
790
- /**
791
- * Register a new customer. The merchant decides which fields are required —
792
- * call fetchRegistrationForm() first to know what to collect.
793
- *
794
- * Throws MissingFieldsError when the merchant marked fields as required but
795
- * they were omitted, so you can mark exactly which inputs are invalid.
796
- *
797
- * @example
798
- * try {
799
- * const session = await registerBuyer(config, website, { email, password, fullName });
800
- * } catch (e) {
801
- * if (e instanceof MissingFieldsError) {
802
- * e.missingFields.forEach(({ field }) => markError(field));
803
- * }
804
- * }
805
- */
806
- export declare function registerBuyer(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: BuyerRegisterParams): Promise<BuyerSession>;
807
- /**
808
- * Authenticate a customer with email and password.
809
- * Returns a BuyerSession with access_token and refresh_token.
810
- * Throws { status: 401 } on wrong credentials.
811
- */
812
- export declare function loginBuyer(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
813
- email: string;
814
- password: string;
815
- captchaToken?: string | null;
816
- }): Promise<BuyerSession>;
817
- /** Invalidate the current session server-side. Best-effort — always clear the cookie too. */
818
- export declare function logoutBuyer(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
819
- token: string;
820
- }): Promise<void>;
821
- /**
822
- * Exchange a refresh token for a new access token.
823
- * Call this when you get a 401 on any authenticated request.
824
- * Throws { status: 401 } if the refresh token is expired or revoked.
825
- *
826
- * @example
827
- * // In Astro middleware:
828
- * try {
829
- * const session = await refreshBuyerToken(config, website, { refreshToken });
830
- * // Set new access_token cookie
831
- * } catch {
832
- * // Clear both cookies, redirect to login
833
- * }
834
- */
835
- export declare function refreshBuyerToken(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
836
- refreshToken: string;
837
- }): Promise<BuyerSession>;
838
- /** Fetch the authenticated customer's full profile. */
839
- export declare function fetchBuyerProfile(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
840
- token: string;
841
- }): Promise<BuyerProfile>;
842
- /**
843
- * Update the authenticated customer's profile. Only the fields you include
844
- * in `params` are changed — it's a partial update.
845
- */
846
- export declare function updateBuyerProfile(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
847
- token: string;
848
- } & BuyerProfileUpdateParams): Promise<BuyerProfile>;
849
- /**
850
- * Send a password reset email. Always resolves — even if the email doesn't exist.
851
- * Always show: "Si el email existe, recibirás un enlace para restablecer tu contraseña."
852
- */
853
- export declare function forgotPassword(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
854
- email: string;
855
- captchaToken?: string | null;
856
- }): Promise<void>;
857
- /**
858
- * Reset the customer's password using the token from the reset email link.
859
- * The token is the `?token=` query param in the reset URL.
860
- * On success, all active sessions are revoked — redirect to login.
861
- * Throws { status: 400, data.detail: BUYER_AUTH_ERRORS.RESET_TOKEN_INVALID } on bad token.
862
- */
863
- export declare function resetPassword(config: Pick<ProximaApiConfig, "baseUrl">, params: {
864
- token: string;
865
- newPassword: string;
866
- }): Promise<void>;
867
- /**
868
- * Verify the customer's email using the token from the verification email link.
869
- * Throws { status: 400, data.detail: BUYER_AUTH_ERRORS.VERIFY_TOKEN_INVALID } on bad token.
870
- */
871
- export declare function verifyEmail(config: Pick<ProximaApiConfig, "baseUrl">, params: {
872
- token: string;
873
- }): Promise<void>;
874
- /**
875
- * Re-send the email verification link. Requires the customer to be authenticated.
876
- * Throws { status: 400, data.detail: BUYER_AUTH_ERRORS.EMAIL_ALREADY_VERIFIED } if already verified.
877
- */
878
- export declare function resendVerification(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
879
- token: string;
880
- }): Promise<void>;
881
- /**
882
- * Search products by query string. Use this for the search bar, autocomplete,
883
- * and search results pages — `resolved_data` for a `search` page is intentionally
884
- * null; query results must be fetched directly.
885
- *
886
- * @example
887
- * const results = await searchStorefront(config, website, { q: 'zapatillas', limit: 10 });
888
- */
889
- export declare function searchStorefront(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id" | "locale" | "currency">, params: {
890
- q: string;
891
- limit?: number;
892
- locale?: string;
893
- currency?: string;
894
- }): Promise<StorefrontSearchResponse>;
895
- /**
896
- * Fetch the general product listing with optional filters and pagination.
897
- * Use this for client-side filter/sort/paginate interactions on the all-products page.
898
- * The initial page render is handled by the composition — call this for subsequent
899
- * filter changes and page turns.
900
- */
901
- export declare function fetchStorefrontProducts(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id" | "locale" | "currency">, params?: StorefrontListingParams & {
902
- brand?: string;
903
- category?: string;
904
- q?: string;
905
- }): Promise<StorefrontProductListingResponse>;
906
- /**
907
- * Fetch paginated + filtered products for a category page (CLP).
908
- * Use this for client-side filter/sort/paginate after the initial SSR render
909
- * (which arrives in `resolved_data` from `fetchProximaComposition`).
910
- */
911
- export declare function fetchCategoryProducts(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id" | "locale" | "currency">, params: StorefrontListingParams & {
912
- /** Category slug, from the URL path */
913
- slug: string;
914
- brand?: string;
915
- q?: string;
916
- }): Promise<StorefrontCategoryListingResponse>;
917
- /**
918
- * Fetch paginated + filtered products for a brand page (BLP).
919
- * Use this for client-side filter/sort/paginate after the initial SSR render
920
- * (which arrives in `resolved_data` from `fetchProximaComposition`).
921
- */
922
- export declare function fetchBrandProducts(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id" | "locale" | "currency">, params: StorefrontListingParams & {
923
- /** Brand slug, from the URL path */
924
- slug: string;
925
- category?: string;
926
- q?: string;
927
- }): Promise<StorefrontBrandListingResponse>;
928
- /**
929
- * Fetch the full category directory (all categories with product counts).
930
- * Useful for navigation menus and sitemap generation.
931
- * For section-level category carousels, use smart collections via composition instead.
932
- */
933
- export declare function fetchCategoriesDirectory(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id" | "locale">, params?: {
934
- locale?: string;
935
- }): Promise<StorefrontCategoryDirectoryResponse>;
936
- /**
937
- * A single node in the category navigation tree.
938
- * `children` contains nodes at the next depth level (up to `max_depth`).
939
- */
940
- export interface CategoryNavNode {
941
- id: number;
942
- slug: string;
943
- name: string;
944
- /** Storefront href — always `/categoria/{slug}` */
945
- href: string;
946
- image_url?: string | null;
947
- product_count: number;
948
- children: CategoryNavNode[];
949
- }
950
- export interface CategoryNavTreeResponse {
951
- nodes: CategoryNavNode[];
952
- total: number;
953
- }
954
- /**
955
- * Fetch the full category hierarchy as a recursive tree.
956
- * Use this for data-driven mega menus — it returns nested `children[]`
957
- * with `/categoria/{slug}` hrefs ready to render.
958
- *
959
- * @param maxDepth - Maximum tree depth (1–5, default 3)
960
- */
961
- export declare function fetchCategoryNavTree(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id" | "locale">, params?: {
962
- maxDepth?: number;
963
- locale?: string;
964
- }): Promise<CategoryNavTreeResponse>;
965
- /**
966
- * Fetch the full brand directory (all brands with product counts).
967
- * Useful for navigation menus and sitemap generation.
968
- */
969
- export declare function fetchBrandsDirectory(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id" | "locale">, params?: {
970
- locale?: string;
971
- }): Promise<StorefrontBrandDirectoryResponse>;
972
- /** Fetch the current cart. Works for both guest sessions and authenticated customers. */
973
- export declare function fetchCart(config: Pick<ProximaApiConfig, "baseUrl">, website: ProximaWebsiteResponse, params: {
974
- token?: string | null;
975
- sessionId?: string | null;
976
- }): Promise<Cart>;
977
- /**
978
- * Add a product variant to the cart. Use `StorefrontProductSummary.default_variant_id`
979
- * as `variantId` when adding from a listing card.
980
- */
981
- export declare function addToCart(config: Pick<ProximaApiConfig, "baseUrl">, website: ProximaWebsiteResponse, params: {
982
- token?: string | null;
983
- sessionId?: string | null;
984
- variantId: number;
985
- quantity: number;
986
- }): Promise<Cart>;
987
- /** Update the quantity of an existing cart item. Set `quantity` to 0 to remove it. */
988
- export declare function updateCartItem(config: Pick<ProximaApiConfig, "baseUrl">, website: ProximaWebsiteResponse, params: {
989
- token?: string | null;
990
- sessionId?: string | null;
991
- variantId: number;
992
- quantity: number;
993
- }): Promise<Cart>;
994
- /** Remove a product variant from the cart entirely. */
995
- export declare function removeCartItem(config: Pick<ProximaApiConfig, "baseUrl">, website: ProximaWebsiteResponse, params: {
996
- token?: string | null;
997
- sessionId?: string | null;
998
- variantId: number;
999
- }): Promise<Cart>;
1000
- /**
1001
- * Merge a guest cart (identified by session ID) into the authenticated customer's cart.
1002
- * Call this immediately after a successful login if there is an active guest session.
1003
- *
1004
- * @example
1005
- * const sessionId = localStorage.getItem('proxima_session_id');
1006
- * if (sessionId) await mergeGuestCart(config, website, { token, sessionId });
1007
- */
1008
- export declare function mergeGuestCart(config: Pick<ProximaApiConfig, "baseUrl">, website: ProximaWebsiteResponse, params: {
1009
- token: string;
1010
- sessionId: string;
1011
- }): Promise<Cart>;
1012
- /**
1013
- * Validate a coupon code before checkout. Always resolves — check `result.valid`.
1014
- * Use the `discount_amount` from the result to preview the discount in the UI.
1015
- *
1016
- * @example
1017
- * const result = await validateCoupon(config, website, { code: 'PROMO10', amount: 150.00 });
1018
- * if (result.valid) showDiscount(result.discount_amount);
1019
- * else showError(result.error);
1020
- */
1021
- export declare function validateCoupon(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
1022
- code: string;
1023
- amount: number;
1024
- }): Promise<CouponValidationResult>;
1025
- /**
1026
- * Submit the current cart as an order (checkout). The cart must be non-empty.
1027
- * On success the cart is cleared. Throws 400 on validation errors (e.g. out of stock).
1028
- */
1029
- export declare function createOrder(config: Pick<ProximaApiConfig, "baseUrl">, website: ProximaWebsiteResponse, params: {
1030
- token: string;
1031
- checkout: CheckoutRequest;
1032
- }): Promise<Order>;
1033
- /** Fetch the authenticated customer's order history, paginated. */
1034
- export declare function fetchOrders(config: Pick<ProximaApiConfig, "baseUrl">, website: ProximaWebsiteResponse, params: {
1035
- token: string;
1036
- page?: number;
1037
- size?: number;
1038
- }): Promise<OrderListResponse>;
1039
- /** Fetch a single order by ID. Works for authenticated customers and guests with the receipt token. */
1040
- export declare function fetchOrder(config: Pick<ProximaApiConfig, "baseUrl">, website: ProximaWebsiteResponse, params: {
1041
- token: string;
1042
- orderId: string;
1043
- }): Promise<Order>;
1044
- /** Fetch all saved addresses for the authenticated customer. */
1045
- export declare function fetchCustomerAddresses(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
1046
- token: string;
1047
- }): Promise<CustomerAddress[]>;
1048
- /** Save a new address to the customer's address book. */
1049
- export declare function createCustomerAddress(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
1050
- token: string;
1051
- address: AddressInput;
1052
- }): Promise<CustomerAddress>;
1053
- /** Partially update a saved address. Only the fields included in `address` are changed. */
1054
- export declare function updateCustomerAddress(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
1055
- token: string;
1056
- addressId: number;
1057
- address: Partial<AddressInput>;
1058
- }): Promise<CustomerAddress>;
1059
- /** Delete a saved address. Throws if the address does not exist. */
1060
- export declare function deleteCustomerAddress(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
1061
- token: string;
1062
- addressId: number;
1063
- }): Promise<void>;
1064
- /** Mark an address as the customer's default. The previous default is unset automatically. */
1065
- export declare function setDefaultAddress(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
1066
- token: string;
1067
- addressId: number;
1068
- }): Promise<CustomerAddress>;
1069
- /**
1070
- * Search Peruvian ubigeo codes (department/province/district) by name.
1071
- * Use this to power the address form's location selector.
1072
- * Returns an empty array on error instead of throwing.
1073
- */
1074
- export declare function searchUbigeo(config: Pick<ProximaApiConfig, "baseUrl">, params: {
1075
- q: string;
1076
- }): Promise<UbigeoResult[]>;
1077
- /**
1078
- * Fetch all wishlist items for the authenticated customer.
1079
- * Returns an empty array if the wishlist is empty.
1080
- */
1081
- export declare function fetchWishlist(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
1082
- token: string;
1083
- }): Promise<WishlistItem[]>;
1084
- /**
1085
- * Add a product to the wishlist. Idempotent — if the product is already
1086
- * in the wishlist, returns the existing item without creating a duplicate.
1087
- */
1088
- export declare function addToWishlist(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
1089
- token: string;
1090
- productId: string;
1091
- variantId?: string | null;
1092
- notes?: string | null;
1093
- }): Promise<WishlistItem>;
1094
- /**
1095
- * Remove a product from the wishlist.
1096
- * Throws { status: 404 } if the product was not in the wishlist.
1097
- */
1098
- export declare function removeFromWishlist(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, params: {
1099
- token: string;
1100
- productId: string;
1101
- }): Promise<void>;
1102
- /**
1103
- * Resolve the website then call loginBuyer.
1104
- * Returns { access_token, refresh_token, next } on success, throws on failure.
1105
- */
1106
- export declare function processBuyerLogin(env: BuyerServerEnv, params: {
1107
- email: string;
1108
- password: string;
1109
- next?: string;
1110
- captchaToken?: string | null;
1111
- }): Promise<{
1112
- access_token: string;
1113
- refresh_token: string | null;
1114
- next: string;
1115
- }>;
1116
- /**
1117
- * Resolve the website then call registerBuyer.
1118
- * Returns { access_token, refresh_token, next } on success, throws on failure.
1119
- * Propagates MissingFieldsError so the API route can return structured 422 errors.
1120
- */
1121
- export declare function processBuyerRegister(env: BuyerServerEnv, params: BuyerRegisterParams & {
1122
- next?: string;
1123
- }): Promise<{
1124
- access_token: string;
1125
- refresh_token: string | null;
1126
- next: string;
1127
- }>;
1128
- /**
1129
- * Call logoutBuyer (best-effort — never throws).
1130
- * Always clear the session cookie regardless of the result.
1131
- */
1132
- export declare function processBuyerLogout(env: BuyerServerEnv, params: {
1133
- token: string;
1134
- }): Promise<void>;
1135
- /**
1136
- * Resolve the website then exchange a refresh token for a new access token.
1137
- * Use this in Astro middleware to silently refresh expired sessions.
1138
- * Throws { status: 401 } if the refresh token is expired — clear cookies and redirect to login.
1139
- */
1140
- export declare function processRefreshToken(env: BuyerServerEnv, params: {
1141
- refreshToken: string;
1142
- }): Promise<{
1143
- access_token: string;
1144
- refresh_token: string | null;
1145
- }>;
1146
- /**
1147
- * Resolve the website then send a password reset email.
1148
- * Never throws — always show a generic confirmation message.
1149
- */
1150
- export declare function processForgotPassword(env: BuyerServerEnv, params: {
1151
- email: string;
1152
- captchaToken?: string | null;
1153
- }): Promise<void>;
1154
- /**
1155
- * Reset the customer's password with the token from the email link.
1156
- * Throws { status: 400, data.detail: BUYER_AUTH_ERRORS.RESET_TOKEN_INVALID } on bad token.
1157
- */
1158
- export declare function processResetPassword(env: BuyerServerEnv, params: {
1159
- token: string;
1160
- newPassword: string;
1161
- }): Promise<void>;
1162
- /**
1163
- * Verify the customer's email with the token from the email link.
1164
- * Throws { status: 400, data.detail: BUYER_AUTH_ERRORS.VERIFY_TOKEN_INVALID } on bad token.
1165
- */
1166
- export declare function processVerifyEmail(env: BuyerServerEnv, params: {
1167
- token: string;
1168
- }): Promise<void>;
1169
- /**
1170
- * Resolve the website then add a variant to the cart.
1171
- * Token is optional (guest cart supported).
1172
- */
1173
- export declare function processAddToCart(env: BuyerServerEnv, params: {
1174
- token?: string | null;
1175
- sessionId?: string | null;
1176
- variantId: number;
1177
- quantity: number;
1178
- }): Promise<Cart>;
1179
- /**
1180
- * Resolve the website then remove a variant from the cart.
1181
- * Token is optional (guest cart supported).
1182
- */
1183
- export declare function processRemoveCartItem(env: BuyerServerEnv, params: {
1184
- token?: string | null;
1185
- sessionId?: string | null;
1186
- variantId: number;
1187
- }): Promise<Cart>;
1188
- /**
1189
- * Resolve the website then update the quantity of a variant in the cart.
1190
- * Token is optional (guest cart supported).
1191
- */
1192
- export declare function processUpdateCartItem(env: BuyerServerEnv, params: {
1193
- token?: string | null;
1194
- sessionId?: string | null;
1195
- variantId: number;
1196
- quantity: number;
1197
- }): Promise<Cart>;
1198
- /**
1199
- * Resolve the website then fetch the current cart.
1200
- * Token is optional (guest cart supported).
1201
- */
1202
- export declare function processGetCart(env: BuyerServerEnv, params: {
1203
- token?: string | null;
1204
- sessionId?: string | null;
1205
- }): Promise<Cart>;
1206
- /**
1207
- * Resolve the website then call POST /checkout.
1208
- * Returns { orderId } on success, throws on failure.
1209
- */
1210
- export declare function processBuyerCheckout(env: BuyerServerEnv, params: {
1211
- token: string;
1212
- checkout: CheckoutRequest;
1213
- }): Promise<{
1214
- orderId: string;
1215
- }>;
1216
- /** Resolve website then set the customer's default address. */
1217
- export declare function processSetDefaultAddress(env: BuyerServerEnv, params: {
1218
- token: string;
1219
- addressId: number;
1220
- }): Promise<CustomerAddress>;
1221
- /** Resolve website then delete a saved address. */
1222
- export declare function processDeleteAddress(env: BuyerServerEnv, params: {
1223
- token: string;
1224
- addressId: number;
1225
- }): Promise<void>;
1226
- export interface ProductListingFilters {
1227
- brand?: string | null;
1228
- category?: string | null;
1229
- price_min?: number | null;
1230
- price_max?: number | null;
1231
- in_stock?: boolean | null;
1232
- }
1233
- export type ProductListingSortOption = "newest" | "price_asc" | "price_desc" | "name_asc";
1234
- /** @deprecated Use StorefrontFacetOption from the main listing types */
1235
- export type ProductFacet = StorefrontFacetOption;
1236
- /** @deprecated Use StorefrontProductListingResponse */
1237
- export type ProductListingResult = StorefrontProductListingResponse;
1238
- /**
1239
- * Fetch a filtered, sorted, paginated product listing.
1240
- * Extends fetchStorefrontProducts with price range and stock filters.
1241
- */
1242
- export declare function fetchProductListing(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id" | "locale" | "currency">, params?: {
1243
- filters?: ProductListingFilters;
1244
- sort?: ProductListingSortOption;
1245
- page?: number;
1246
- page_size?: number;
1247
- }): Promise<StorefrontProductListingResponse>;
1248
- export interface GuestOrderPayload {
1249
- session_id: string;
1250
- customer_name: string;
1251
- customer_phone: string;
1252
- customer_email: string;
1253
- shipping_address?: string | null;
1254
- notes?: string | null;
1255
- }
1256
- export interface GuestOrderResult {
1257
- orderId: string;
1258
- }
1259
- export declare class GuestOrderError extends Error {
1260
- readonly code: "CART_NOT_FOUND" | "OUT_OF_STOCK" | "SERVER_ERROR";
1261
- constructor(code: "CART_NOT_FOUND" | "OUT_OF_STOCK" | "SERVER_ERROR", message: string);
1262
- }
1263
- /**
1264
- * Create an order without buyer authentication.
1265
- * The cart is identified by `session_id` (from the storefront session cookie).
1266
- * Throws `GuestOrderError` for typed error cases.
1267
- */
1268
- export declare function initiateGuestOrder(config: Pick<ProximaApiConfig, "baseUrl">, website: Pick<ProximaWebsiteResponse, "business_id">, payload: GuestOrderPayload): Promise<GuestOrderResult>;
1269
- /**
1270
- * Resolve website then call initiateGuestOrder.
1271
- * Server-side helper for Astro API routes.
1272
- */
1273
- export declare function processGuestCheckout(env: BuyerServerEnv, payload: GuestOrderPayload): Promise<GuestOrderResult>;
1274
- export type StorefrontEventType = 'page_view' | 'product_view' | 'add_to_cart' | 'order_completed' | 'search';
1275
- export interface StorefrontEventPayload {
1276
- product_slug?: string;
1277
- product_id?: string;
1278
- product_name?: string;
1279
- variant_id?: number;
1280
- quantity?: number;
1281
- price?: number;
1282
- order_id?: string;
1283
- order_total?: number;
1284
- query?: string;
1285
- results_count?: number;
1286
- [key: string]: unknown;
1287
- }
1288
- export interface StorefrontAnalyticsConfig {
1289
- apiUrl: string;
1290
- websiteId: string;
1291
- businessId: string;
1292
- locale?: string;
1293
- flushInterval?: number;
1294
- debug?: boolean;
1295
- }
1296
- declare class ProximaAnalytics {
1297
- private config;
1298
- private queue;
1299
- private preInitQueue;
1300
- private timer;
1301
- private initialized;
1302
- init(config: StorefrontAnalyticsConfig): void;
1303
- track(type: StorefrontEventType, payload?: StorefrontEventPayload): void;
1304
- flush(beacon?: boolean): void;
1305
- destroy(): void;
1306
- }
1307
- /** Singleton analytics client. Call `analytics.init()` once from SiteLayout. */
1308
- export declare const analytics: ProximaAnalytics;
1309
- export { createFixtureBundle, createStorefrontDataSource, validateFixtureBundle, resolveStorefrontDataSourceForRequest, FixtureGuestOrderError, } from "./fixtures-commerce.js";
1310
- export type { FixtureBundle, FixtureBundleInput, FixtureBrandListingParams, FixtureCartMutationParams, FixtureCatalogItem, FixtureListingParams, FixtureProductListingParams, FixtureSearchParams, ResolveStorefrontDataSourceOptions, StorefrontCartParams, StorefrontDataMode, StorefrontDataSource, StorefrontDataSourceConfig, ValidateFixtureBundleOptions, } from "./fixtures-commerce.js";
1
+ export * from './types/cms.js';
2
+ export * from './types/seo.js';
3
+ export * from './types/business.js';
4
+ export * from './types/buyer.js';
5
+ export * from './types/catalog.js';
6
+ export * from './types/cart.js';
7
+ export * from './types/order.js';
8
+ export * from './types/address.js';
9
+ export * from './types/wishlist.js';
10
+ export * from './types/server-env.js';
11
+ export * from './types/listing.js';
12
+ export * from './types/guest-order.js';
13
+ export * from './types/campaign.js';
14
+ export * from './types/analytics.js';
15
+ export * from './types/cookie-consent.js';
16
+ export * from './api/index.js';
17
+ export * from './seo/hreflang.js';
18
+ export * from './seo/engine-url.js';
19
+ export * from './seo/page-seo.js';
20
+ export * from './seo/json-ld.js';
21
+ export * from './seo/sitemap.js';
22
+ export * from './seo/robots.js';
23
+ export * from './seo/indexnow.js';
24
+ export * from './cms/website.js';
25
+ export * from './cms/payment-methods.js';
26
+ export * from './buyer/auth.js';
27
+ export * from './catalog/listings.js';
28
+ export * from './cart/cart.js';
29
+ export * from './orders/orders.js';
30
+ export * from './orders/guest.js';
31
+ export * from './addresses/address-book.js';
32
+ export * from './wishlist/wishlist.js';
33
+ export * from './server/process.js';
34
+ export * from './campaign/countdown.js';
35
+ export { analytics } from './analytics/analytics.js';
36
+ export type { StorefrontAnalyticsInitOptions } from './analytics/analytics.js';
37
+ export { resolveAnalyticsSessionId, ANALYTICS_SESSION_STORAGE_KEY } from './analytics/session.js';
38
+ export { captureSessionAttribution, getSessionAttribution, clearSessionAttribution, inferAttributionFromReferrer, ATTRIBUTION_STORAGE_KEY, } from './analytics/attribution.js';
39
+ export type { SessionAttribution } from './analytics/attribution.js';
40
+ export { createStorefrontAnalyticsTrackers } from './analytics/trackers.js';
41
+ export type { StorefrontAnalyticsTrackers } from './analytics/trackers.js';
42
+ export * from './cookie-consent/consent.js';
43
+ export * from './cache/cache.js';
44
+ export { createFixtureBundle, createStorefrontDataSource, validateFixtureBundle, resolveStorefrontDataSourceForRequest, FixtureGuestOrderError, } from './fixtures-commerce.js';
45
+ export type { FixtureBundle, FixtureBundleInput, FixtureBrandListingParams, FixtureCartMutationParams, FixtureCatalogItem, FixtureListingParams, FixtureProductListingParams, FixtureSearchParams, ResolveStorefrontDataSourceOptions, StorefrontCartParams, StorefrontDataMode, StorefrontDataSource, StorefrontDataSourceConfig, ValidateFixtureBundleOptions, } from './fixtures-commerce.js';
1311
46
  //# sourceMappingURL=index.d.ts.map