@ecomiq/core 0.1.9 → 1.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.
Files changed (278) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -2
  3. package/dist/_virtual/_rolldown/runtime-C6LprzCP.cjs +22 -0
  4. package/dist/api.cjs +117 -102
  5. package/dist/api.d.cts +33 -37
  6. package/dist/api.d.ts +33 -37
  7. package/dist/api.js +116 -100
  8. package/dist/client.cjs +499 -1676
  9. package/dist/client.d.cts +156 -15
  10. package/dist/client.d.ts +156 -15
  11. package/dist/client.js +500 -1675
  12. package/dist/index.cjs +344 -2092
  13. package/dist/index.d.cts +54 -1127
  14. package/dist/index.d.ts +54 -1127
  15. package/dist/index.js +53 -1895
  16. package/dist/libs/bounded-read-cache-Abmb5VnJ.js +41 -0
  17. package/dist/libs/bounded-read-cache-D4644LJo.cjs +41 -0
  18. package/dist/libs/catalog-link-key-B7l5KZsF.js +9 -0
  19. package/dist/libs/catalog-link-key-CZTHJBGD.cjs +9 -0
  20. package/dist/libs/catalog-link-key.d.cts +2 -0
  21. package/dist/libs/catalog-link-key.d.ts +2 -0
  22. package/dist/libs/graphql-_6Y8lR_Q.js +49 -0
  23. package/dist/libs/graphql-selection-Cj51WkJn.cjs +21 -0
  24. package/dist/libs/graphql-selection-H1RMh6VD.js +21 -0
  25. package/dist/libs/graphql-selection.d.cts +3 -0
  26. package/dist/libs/graphql-selection.d.ts +3 -0
  27. package/dist/libs/graphql-wJH7HaQU.cjs +50 -0
  28. package/dist/libs/graphql.d.cts +24 -0
  29. package/dist/libs/graphql.d.ts +24 -0
  30. package/dist/models/amounts-cKBCecl7.js +5 -0
  31. package/dist/models/amounts-lmg89eJQ.cjs +4 -0
  32. package/dist/models/articles-C-4JvT2Z.js +27 -0
  33. package/dist/models/articles-xHCXLKDK.cjs +30 -0
  34. package/dist/models/articles.d.cts +46 -0
  35. package/dist/models/articles.d.ts +46 -0
  36. package/dist/models/catalog-links-BzJeyBy4.js +80 -0
  37. package/dist/models/catalog-links-c4LADGf_.cjs +88 -0
  38. package/dist/models/catalog-links.d.cts +39 -0
  39. package/dist/models/catalog-links.d.ts +39 -0
  40. package/dist/models/categories-CKkJY8_P.js +42 -0
  41. package/dist/models/categories-DZ5i5kwi.cjs +45 -0
  42. package/dist/models/categories.d.cts +54 -0
  43. package/dist/models/categories.d.ts +54 -0
  44. package/dist/models/collections.cjs +13 -22
  45. package/dist/models/collections.d.cts +23 -56
  46. package/dist/models/collections.d.ts +23 -56
  47. package/dist/models/collections.js +12 -20
  48. package/dist/models/complaint-book-D5INpuI2.cjs +64 -0
  49. package/dist/models/complaint-book-QpQZe7Xl.js +58 -0
  50. package/dist/models/complaint-book.d.cts +71 -0
  51. package/dist/models/complaint-book.d.ts +71 -0
  52. package/dist/models/customer-address.cjs +39 -38
  53. package/dist/models/customer-address.d.cts +59 -158
  54. package/dist/models/customer-address.d.ts +59 -158
  55. package/dist/models/customer-address.js +38 -36
  56. package/dist/models/customer-order.cjs +183 -142
  57. package/dist/models/customer-order.d.cts +474 -857
  58. package/dist/models/customer-order.d.ts +474 -857
  59. package/dist/models/customer-order.js +180 -141
  60. package/dist/models/customer-profile.cjs +121 -118
  61. package/dist/models/customer-profile.d.cts +89 -174
  62. package/dist/models/customer-profile.d.ts +89 -174
  63. package/dist/models/customer-profile.js +121 -116
  64. package/dist/models/customer-registration-C13knqyv.js +28 -0
  65. package/dist/models/customer-registration-EZ0yZgGr.cjs +31 -0
  66. package/dist/models/customer-registration.d.cts +66 -0
  67. package/dist/models/customer-registration.d.ts +66 -0
  68. package/dist/models/customer-session-BiX0TXhO.js +41 -0
  69. package/dist/models/customer-session-JeQiC8Yx.cjs +45 -0
  70. package/dist/models/customer-session.d.cts +61 -0
  71. package/dist/models/customer-session.d.ts +61 -0
  72. package/dist/models/geo.cjs +52 -49
  73. package/dist/models/geo.d.cts +141 -270
  74. package/dist/models/geo.d.ts +141 -270
  75. package/dist/models/geo.js +51 -47
  76. package/dist/models/ids.cjs +8 -11
  77. package/dist/models/ids.d.cts +7 -10
  78. package/dist/models/ids.d.ts +7 -10
  79. package/dist/models/ids.js +7 -9
  80. package/dist/models/order-draft-C-2WRbjl.cjs +41 -0
  81. package/dist/models/order-draft-CSIWRIV0.js +39 -0
  82. package/dist/models/order-draft.d.cts +69 -0
  83. package/dist/models/order-draft.d.ts +69 -0
  84. package/dist/models/order-review--xGlZKtS.cjs +18 -0
  85. package/dist/models/order-review-egGeCaqB.js +17 -0
  86. package/dist/models/order-review.d.cts +22 -0
  87. package/dist/models/order-review.d.ts +22 -0
  88. package/dist/models/order-status-CS_OeSPY.cjs +66 -0
  89. package/dist/models/order-status-CgaLkU0M.js +60 -0
  90. package/dist/models/order-status.d.cts +307 -0
  91. package/dist/models/order-status.d.ts +307 -0
  92. package/dist/models/payment-methods--VUUZpMz.js +17 -0
  93. package/dist/models/payment-methods-CmK08zBM.cjs +19 -0
  94. package/dist/models/payment-methods.d.cts +28 -0
  95. package/dist/models/payment-methods.d.ts +28 -0
  96. package/dist/models/personalization-BPFmkdJ0.js +69 -0
  97. package/dist/models/personalization-CQosKg8O.cjs +77 -0
  98. package/dist/models/personalization.d.cts +83 -0
  99. package/dist/models/personalization.d.ts +83 -0
  100. package/dist/models/products.cjs +218 -194
  101. package/dist/models/products.d.cts +646 -1353
  102. package/dist/models/products.d.ts +646 -1353
  103. package/dist/models/products.js +214 -187
  104. package/dist/models/search.cjs +13 -23
  105. package/dist/models/search.d.cts +21 -51
  106. package/dist/models/search.d.ts +21 -51
  107. package/dist/models/search.js +12 -21
  108. package/dist/models/sellers.cjs +44 -0
  109. package/dist/models/sellers.d.cts +82 -0
  110. package/dist/models/sellers.d.ts +82 -0
  111. package/dist/models/sellers.js +38 -0
  112. package/dist/models/settings.cjs +205 -236
  113. package/dist/models/settings.d.cts +853 -6940
  114. package/dist/models/settings.d.ts +853 -6940
  115. package/dist/models/settings.js +213 -239
  116. package/dist/models/storefront-cart.cjs +152 -118
  117. package/dist/models/storefront-cart.d.cts +277 -706
  118. package/dist/models/storefront-cart.d.ts +277 -706
  119. package/dist/models/storefront-cart.js +148 -117
  120. package/dist/models/storefront-checkout.cjs +212 -297
  121. package/dist/models/storefront-checkout.d.cts +672 -2449
  122. package/dist/models/storefront-checkout.d.ts +672 -2449
  123. package/dist/models/storefront-checkout.js +208 -297
  124. package/dist/models/storefront-reviews.cjs +58 -43
  125. package/dist/models/storefront-reviews.d.cts +71 -139
  126. package/dist/models/storefront-reviews.d.ts +71 -139
  127. package/dist/models/storefront-reviews.js +55 -42
  128. package/dist/models/tracking-CiIAhQW0.js +33 -0
  129. package/dist/models/tracking-wNyzQ6Bp.cjs +36 -0
  130. package/dist/models/tracking.d.cts +26 -0
  131. package/dist/models/tracking.d.ts +26 -0
  132. package/dist/models/urls-B0ZODOwH.cjs +35 -0
  133. package/dist/models/urls-Dt_dTt4Q.js +33 -0
  134. package/dist/models/urls.d.cts +233 -0
  135. package/dist/models/urls.d.ts +233 -0
  136. package/dist/redirects.cjs +113 -0
  137. package/dist/redirects.d.cts +11 -0
  138. package/dist/redirects.d.ts +11 -0
  139. package/dist/redirects.js +108 -0
  140. package/dist/services/article.service-DBsOvflH.js +10 -0
  141. package/dist/services/article.service-zmTkbbPV.cjs +11 -0
  142. package/dist/services/article.service.d.cts +4 -0
  143. package/dist/services/article.service.d.ts +4 -0
  144. package/dist/services/cart.service-B0D8s6jI.cjs +37 -0
  145. package/dist/services/cart.service-yMCz9oQP.js +33 -0
  146. package/dist/services/cart.service.d.cts +572 -0
  147. package/dist/services/cart.service.d.ts +572 -0
  148. package/dist/services/catalog-link.service-BQ2d-EPX.js +8 -0
  149. package/dist/services/catalog-link.service-DiB-OVjn.cjs +8 -0
  150. package/dist/services/category.service-8tieYX2r.js +6 -0
  151. package/dist/services/category.service-BsSJZV2B.cjs +6 -0
  152. package/dist/services/checkout.service-CC-3tm2y.js +60 -0
  153. package/dist/services/checkout.service-CG8KrDNY.cjs +69 -0
  154. package/dist/services/checkout.service.d.cts +475 -0
  155. package/dist/services/checkout.service.d.ts +475 -0
  156. package/dist/services/collection.service-C4QETpuI.js +11 -0
  157. package/dist/services/collection.service-DHGN3rhs.cjs +12 -0
  158. package/dist/services/complaint-book.service-C7TxltQe.cjs +13 -0
  159. package/dist/services/complaint-book.service-DXiVyKdD.js +12 -0
  160. package/dist/services/complaint-book.service.d.cts +4 -0
  161. package/dist/services/complaint-book.service.d.ts +4 -0
  162. package/dist/services/customer-address.service-Ca4qla_R.cjs +51 -0
  163. package/dist/services/customer-address.service-xEThx7cQ.js +47 -0
  164. package/dist/services/customer-address.service.d.cts +19 -0
  165. package/dist/services/customer-address.service.d.ts +19 -0
  166. package/dist/services/customer-order.service-DLGgT0xa.cjs +54 -0
  167. package/dist/services/customer-order.service-qHoRBuyX.js +51 -0
  168. package/dist/services/customer-order.service.d.cts +34 -0
  169. package/dist/services/customer-order.service.d.ts +34 -0
  170. package/dist/services/customer-registration.service-C3BNyCHP.cjs +10 -0
  171. package/dist/services/customer-registration.service-CxcWD2hf.js +9 -0
  172. package/dist/services/customer-registration.service.d.cts +5 -0
  173. package/dist/services/customer-registration.service.d.ts +5 -0
  174. package/dist/services/customer-session.service-4YgfbWRB.js +16 -0
  175. package/dist/services/customer-session.service-Bd8pLC2v.cjs +19 -0
  176. package/dist/services/customer.service-BM0NrOxP.cjs +26 -0
  177. package/dist/services/customer.service-BoU6l2-R.js +25 -0
  178. package/dist/services/customer.service.d.cts +10 -0
  179. package/dist/services/customer.service.d.ts +10 -0
  180. package/dist/services/geo.service-C32R7N8W.js +39 -0
  181. package/dist/services/geo.service-JeTT3Wun.cjs +42 -0
  182. package/dist/services/geo.service.d.cts +10 -0
  183. package/dist/services/geo.service.d.ts +10 -0
  184. package/dist/services/layout.service-BkvLzl1g.cjs +50 -0
  185. package/dist/services/layout.service-DmbeMOkK.js +50 -0
  186. package/dist/services/layout.service.d.cts +9 -0
  187. package/dist/services/layout.service.d.ts +9 -0
  188. package/dist/services/order-draft.service-B0VcmWhn.js +13 -0
  189. package/dist/services/order-draft.service-Dlu6eEkV.cjs +14 -0
  190. package/dist/services/order-draft.service.d.cts +4 -0
  191. package/dist/services/order-draft.service.d.ts +4 -0
  192. package/dist/services/order-review.service-BEr-FB6_.cjs +11 -0
  193. package/dist/services/order-review.service-PdBPUsxE.js +11 -0
  194. package/dist/services/order-review.service.d.cts +7 -0
  195. package/dist/services/order-review.service.d.ts +7 -0
  196. package/dist/services/order-status.service-Cn7dsaJo.cjs +26 -0
  197. package/dist/services/order-status.service-MC9hVpP-.js +23 -0
  198. package/dist/services/order-status.service.d.cts +16 -0
  199. package/dist/services/order-status.service.d.ts +16 -0
  200. package/dist/services/page.service-CWhWCjMQ.js +7 -0
  201. package/dist/services/page.service-DmCSeMiR.cjs +7 -0
  202. package/dist/services/page.service.d.cts +4 -0
  203. package/dist/services/page.service.d.ts +4 -0
  204. package/dist/services/payment-method.service-CEt_nB4R.cjs +7 -0
  205. package/dist/services/payment-method.service-CjKbAsOh.js +7 -0
  206. package/dist/services/payment-method.service.d.cts +4 -0
  207. package/dist/services/payment-method.service.d.ts +4 -0
  208. package/dist/services/product.service-B05Qmbuh.js +35 -0
  209. package/dist/services/product.service-B7OFZWB1.cjs +37 -0
  210. package/dist/services/product.service.d.cts +256 -0
  211. package/dist/services/product.service.d.ts +256 -0
  212. package/dist/services/review.service-CO2icjpu.cjs +46 -0
  213. package/dist/services/review.service-De1YkhFp.js +43 -0
  214. package/dist/services/review.service.d.cts +28 -0
  215. package/dist/services/review.service.d.ts +28 -0
  216. package/dist/services/search.service-Bx1zbTHJ.cjs +10 -0
  217. package/dist/services/search.service-DSBMhaSY.js +10 -0
  218. package/dist/services/search.service.d.cts +9 -0
  219. package/dist/services/search.service.d.ts +9 -0
  220. package/dist/services/seller.service-D11WHhbC.cjs +10 -0
  221. package/dist/services/seller.service-DUptDTv4.js +9 -0
  222. package/dist/services/seller.service.d.cts +42 -0
  223. package/dist/services/seller.service.d.ts +42 -0
  224. package/dist/services/tracking.service-CPK1B69N.js +11 -0
  225. package/dist/services/tracking.service-DqOoi8qr.cjs +11 -0
  226. package/dist/services/tracking.service.d.cts +7 -0
  227. package/dist/services/tracking.service.d.ts +7 -0
  228. package/dist/services/url.service-B-nC14Ue.cjs +19 -0
  229. package/dist/services/url.service-CLW0Tc7S.js +18 -0
  230. package/dist/storefront-cache-revision.cjs +23 -0
  231. package/dist/storefront-cache-revision.d.cts +16 -0
  232. package/dist/storefront-cache-revision.d.ts +16 -0
  233. package/dist/storefront-cache-revision.js +17 -0
  234. package/dist/storefront-routes.cjs +14 -0
  235. package/dist/storefront-routes.d.cts +11 -0
  236. package/dist/storefront-routes.d.ts +11 -0
  237. package/dist/storefront-routes.js +12 -0
  238. package/dist/utils-CDEC5xcY.cjs +139 -0
  239. package/dist/utils-DK7qa54o.js +136 -0
  240. package/dist/utils.d.cts +3 -0
  241. package/dist/utils.d.ts +3 -0
  242. package/dist/video-links-CbRO0m8V.js +47 -0
  243. package/dist/video-links-ClryQjPH.cjs +47 -0
  244. package/dist/video-links.d.cts +7 -0
  245. package/dist/video-links.d.ts +7 -0
  246. package/package.json +28 -11
  247. package/dist/api.cjs.map +0 -1
  248. package/dist/api.js.map +0 -1
  249. package/dist/client-Ba1r_uiO.d.ts +0 -195
  250. package/dist/client-Cqcnv2tC.d.cts +0 -195
  251. package/dist/client.cjs.map +0 -1
  252. package/dist/client.js.map +0 -1
  253. package/dist/index.cjs.map +0 -1
  254. package/dist/index.js.map +0 -1
  255. package/dist/models/collections.cjs.map +0 -1
  256. package/dist/models/collections.js.map +0 -1
  257. package/dist/models/customer-address.cjs.map +0 -1
  258. package/dist/models/customer-address.js.map +0 -1
  259. package/dist/models/customer-order.cjs.map +0 -1
  260. package/dist/models/customer-order.js.map +0 -1
  261. package/dist/models/customer-profile.cjs.map +0 -1
  262. package/dist/models/customer-profile.js.map +0 -1
  263. package/dist/models/geo.cjs.map +0 -1
  264. package/dist/models/geo.js.map +0 -1
  265. package/dist/models/ids.cjs.map +0 -1
  266. package/dist/models/ids.js.map +0 -1
  267. package/dist/models/products.cjs.map +0 -1
  268. package/dist/models/products.js.map +0 -1
  269. package/dist/models/search.cjs.map +0 -1
  270. package/dist/models/search.js.map +0 -1
  271. package/dist/models/settings.cjs.map +0 -1
  272. package/dist/models/settings.js.map +0 -1
  273. package/dist/models/storefront-cart.cjs.map +0 -1
  274. package/dist/models/storefront-cart.js.map +0 -1
  275. package/dist/models/storefront-checkout.cjs.map +0 -1
  276. package/dist/models/storefront-checkout.js.map +0 -1
  277. package/dist/models/storefront-reviews.cjs.map +0 -1
  278. package/dist/models/storefront-reviews.js.map +0 -1
package/dist/client.js CHANGED
@@ -1,1677 +1,502 @@
1
- import { z } from 'zod';
2
-
3
- // src/libs/api.ts
4
- var DEFAULT_API_BASE_URL = "https://storefront.ecomiq.pe";
5
- var DEFAULT_API_VERSION = "v1";
6
- var ApiError = class extends Error {
7
- constructor(message, status, url, body) {
8
- super(message);
9
- this.status = status;
10
- this.url = url;
11
- this.body = body;
12
- this.name = "ApiError";
13
- }
14
- status;
15
- url;
16
- body;
17
- };
18
- function resolveApiBaseUrl(baseUrl = DEFAULT_API_BASE_URL, version = DEFAULT_API_VERSION) {
19
- const root = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
20
- const segment = version.replace(/^\/+|\/+$/g, "");
21
- if (!segment) return root;
22
- return new URL(`${segment}/`, root).toString();
23
- }
24
- function createApi(options = {}) {
25
- const {
26
- baseUrl = DEFAULT_API_BASE_URL,
27
- version = DEFAULT_API_VERSION,
28
- headers: baseHeaders = {},
29
- timeoutMs = 1e4
30
- } = options;
31
- const effectiveBaseUrl = resolveApiBaseUrl(baseUrl, version);
32
- async function request(method, path, schema, opts = {}) {
33
- const url = new URL(path.replace(/^\//, ""), effectiveBaseUrl);
34
- for (const [key, value] of Object.entries(opts.query ?? {})) {
35
- if (value !== void 0) url.searchParams.set(key, String(value));
36
- }
37
- const controller = new AbortController();
38
- const timeout = setTimeout(() => controller.abort(), timeoutMs);
39
- if (opts.signal) opts.signal.addEventListener("abort", () => controller.abort(), { once: true });
40
- const isFormData = typeof FormData !== "undefined" && opts.body instanceof FormData;
41
- let response;
42
- try {
43
- response = await fetch(url.toString(), {
44
- method,
45
- headers: {
46
- accept: "application/json",
47
- ...opts.body !== void 0 && !isFormData ? { "content-type": "application/json" } : {},
48
- ...baseHeaders,
49
- ...opts.headers
50
- },
51
- body: opts.body === void 0 ? void 0 : isFormData ? opts.body : JSON.stringify(opts.body),
52
- signal: controller.signal
53
- });
54
- } catch (err) {
55
- throw new ApiError(
56
- err instanceof DOMException && err.name === "AbortError" ? `Timeout tras ${timeoutMs}ms: ${url}` : `No se pudo conectar con ${url}`,
57
- 0,
58
- url.toString()
59
- );
60
- } finally {
61
- clearTimeout(timeout);
62
- }
63
- if (!response.ok) {
64
- const bodyText2 = await response.text().catch(() => void 0);
65
- let body = bodyText2;
66
- if (bodyText2) {
67
- try {
68
- body = JSON.parse(bodyText2);
69
- } catch {
70
- }
71
- }
72
- throw new ApiError(`${method} ${url} \u2192 ${response.status}`, response.status, url.toString(), body);
73
- }
74
- const bodyText = await response.text();
75
- let json = null;
76
- if (bodyText.trim()) {
77
- try {
78
- json = JSON.parse(bodyText);
79
- } catch {
80
- throw new ApiError(
81
- `Respuesta no JSON de ${url}`,
82
- response.status,
83
- url.toString(),
84
- bodyText
85
- );
86
- }
87
- }
88
- const parsed = schema.safeParse(json);
89
- if (!parsed.success) {
90
- throw new ApiError(
91
- `Respuesta inesperada de ${url}: ${parsed.error.issues[0]?.path.join(".")} ${parsed.error.issues[0]?.message}`,
92
- response.status,
93
- url.toString(),
94
- json
95
- );
96
- }
97
- return parsed.data;
98
- }
99
- return {
100
- request,
101
- get: (path, schema, opts) => request("GET", path, schema, opts),
102
- post: (path, body, schema, opts) => request("POST", path, schema, { ...opts, body }),
103
- postForm: (path, body, schema, opts) => request("POST", path, schema, { ...opts, body })
104
- };
105
- }
106
- var EntityIdSchema = z.string().min(1, "Expected resource id");
107
- var CartTokenSchema = z.string().min(1).max(32).regex(/^[A-Za-z0-9_-]+$/, "Expected cart token");
108
- var NullableEntityIdSchema = EntityIdSchema.nullable();
109
- var OptionalEntityIdSchema = EntityIdSchema.optional();
110
-
111
- // src/models/collections.ts
112
- var CollectionSchema = z.object({
113
- id: EntityIdSchema,
114
- slug: z.string(),
115
- name: z.string(),
116
- description: z.string().nullable().optional(),
117
- imageUrl: z.string().nullable().optional(),
118
- type: z.string(),
119
- productCount: z.number().optional()
120
- });
121
- var CollectionsSchema = z.array(CollectionSchema);
122
- var ProductSummarySchema = z.object({
123
- id: EntityIdSchema,
124
- name: z.string(),
125
- slug: z.string(),
126
- productType: z.string(),
127
- imageUrl: z.string(),
128
- price: z.number().nonnegative(),
129
- compareAtPrice: z.number().nonnegative().nullable(),
130
- variantCount: z.number().int().nonnegative(),
131
- isAvailable: z.boolean(),
132
- totalInventory: z.number().int().nonnegative(),
133
- bundleItemsCount: z.number().int().nonnegative(),
134
- brand: z.string(),
135
- category: z.string(),
136
- status: z.string(),
137
- collections: z.array(z.string()),
138
- tags: z.array(z.string())
139
- });
140
- var ProductSummariesSchema = z.array(ProductSummarySchema);
141
- var FacetItemSchema = z.object({
142
- value: z.string(),
143
- count: z.number().int().nonnegative(),
144
- label: z.string().nullable(),
145
- selected: z.boolean()
146
- });
147
- var SearchFilterSchema = z.object({
148
- id: z.string(),
149
- label: z.string(),
150
- type: z.enum(["list", "price_range"]),
151
- values: z.array(FacetItemSchema),
152
- min: z.number().nonnegative().nullable(),
153
- max: z.number().nonnegative().nullable(),
154
- selectedMin: z.number().nonnegative().nullable(),
155
- selectedMax: z.number().nonnegative().nullable()
156
- });
157
- var ProductsResponseSchema = z.object({
158
- pageIndex: z.number().int().positive(),
159
- pageSize: z.number().int().positive().max(100),
160
- totalCount: z.number().int().nonnegative(),
161
- totalPages: z.number().int().nonnegative(),
162
- products: z.array(ProductSummarySchema),
163
- filters: z.array(SearchFilterSchema)
164
- });
165
- var ProductSortSchema = z.enum([
166
- "price_asc",
167
- "price_desc",
168
- "name_asc",
169
- "name_desc",
170
- "newest"
171
- ]);
172
- var ProductsParamsSchema = z.object({
173
- page: z.number().int().positive().default(1),
174
- pageSize: z.number().int().positive().max(100).default(24),
175
- sort: ProductSortSchema.optional(),
176
- sellerId: OptionalEntityIdSchema,
177
- search: z.string().optional(),
178
- collection: z.string().optional(),
179
- collections: z.array(z.string()).optional(),
180
- collectionId: EntityIdSchema.optional(),
181
- category: z.string().optional(),
182
- categories: z.array(z.string()).optional(),
183
- brand: z.string().optional(),
184
- brands: z.array(z.string()).optional(),
185
- productType: z.string().optional(),
186
- productTypes: z.array(z.string()).optional(),
187
- tag: z.string().optional(),
188
- tags: z.array(z.string()).optional(),
189
- filters: z.array(z.string()).optional(),
190
- locationId: OptionalEntityIdSchema,
191
- inStock: z.boolean().optional(),
192
- minPrice: z.number().nonnegative().optional(),
193
- maxPrice: z.number().nonnegative().optional()
194
- });
195
- var ProductDetailParamsSchema = z.object({
196
- sellerId: OptionalEntityIdSchema
197
- });
198
- var RelatedProductsParamsSchema = z.object({
199
- productId: EntityIdSchema,
200
- limit: z.number().int().positive().max(12).default(8),
201
- sellerId: OptionalEntityIdSchema
202
- });
203
- var SpecItemSchema = z.object({
204
- key: z.string(),
205
- name: z.string(),
206
- value: z.string()
207
- });
208
- var ProductImageSchema = z.object({
209
- url: z.string(),
210
- name: z.string(),
211
- order: z.number().int().nonnegative()
212
- });
213
- var VariantItemSchema = z.object({
214
- id: EntityIdSchema.nullable(),
215
- sku: z.string(),
216
- status: z.string(),
217
- price: z.number().nonnegative(),
218
- compareAtPrice: z.number().nonnegative().nullable(),
219
- quantity: z.number().int().nonnegative(),
220
- options: z.array(SpecItemSchema),
221
- images: z.array(ProductImageSchema)
222
- });
223
- var ProductPriceTierSchema = z.object({
224
- variantId: EntityIdSchema,
225
- minQuantity: z.number().int().positive(),
226
- maxQuantity: z.number().int().positive().nullable(),
227
- unitPrice: z.number().nonnegative()
228
- });
229
- var BundleItemSchema = z.object({
230
- productId: EntityIdSchema,
231
- variantId: EntityIdSchema,
232
- productName: z.string(),
233
- variantName: z.string().nullable(),
234
- sku: z.string().nullable(),
235
- brand: z.string().nullable(),
236
- imageUrl: z.string().nullable(),
237
- quantity: z.number().int().positive(),
238
- available: z.number().int().nonnegative(),
239
- allowBackorders: z.boolean(),
240
- requiresShipping: z.boolean()
241
- });
242
- var SizeGuideMeasurementSchema = z.object({
243
- key: z.string(),
244
- name: z.string(),
245
- min: z.number().nullable(),
246
- max: z.number().nullable(),
247
- value: z.number().nullable(),
248
- description: z.string().nullable()
249
- });
250
- var SizeGuideRowSchema = z.object({
251
- label: z.string(),
252
- sizeKey: z.string(),
253
- order: z.number().int().nonnegative(),
254
- measurements: z.array(SizeGuideMeasurementSchema)
255
- });
256
- var SizeGuideSchema = z.object({
257
- id: EntityIdSchema,
258
- name: z.string(),
259
- slug: z.string(),
260
- description: z.string().nullable(),
261
- imageUrl: z.string().nullable(),
262
- gender: z.string(),
263
- measurementType: z.string(),
264
- unit: z.string(),
265
- notes: z.string().nullable(),
266
- rows: z.array(SizeGuideRowSchema)
267
- });
268
- var ProductDetailSchema = z.object({
269
- id: EntityIdSchema,
270
- name: z.string(),
271
- slug: z.string(),
272
- description: z.string(),
273
- productType: z.string(),
274
- status: z.string(),
275
- imageUrl: z.string(),
276
- price: z.number().nonnegative(),
277
- compareAtPrice: z.number().nonnegative().nullable(),
278
- isAvailable: z.boolean(),
279
- totalInventory: z.number().int().nonnegative(),
280
- brand: z.string(),
281
- category: z.string(),
282
- categoryId: EntityIdSchema.nullable(),
283
- tags: z.array(z.string()),
284
- specifications: z.array(SpecItemSchema),
285
- variants: z.array(VariantItemSchema),
286
- images: z.array(ProductImageSchema),
287
- bundleItems: z.array(BundleItemSchema),
288
- sizeGuide: SizeGuideSchema.nullable(),
289
- priceTiers: z.array(ProductPriceTierSchema),
290
- createdAt: z.string().datetime({ offset: true }).nullable(),
291
- updatedAt: z.string().datetime({ offset: true }).nullable()
292
- });
293
- var JsonElementSchema = z.lazy(
294
- () => z.union([
295
- z.null(),
296
- z.boolean(),
297
- z.number().finite(),
298
- z.string(),
299
- z.array(JsonElementSchema),
300
- z.record(z.string(), JsonElementSchema)
301
- ])
302
- );
303
- var DateTimeOffsetSchema = z.string().datetime({ offset: true });
304
- var NullableDateTimeOffsetSchema = DateTimeOffsetSchema.nullable();
305
- var StoreTypeSchema = z.enum([
306
- "b2C",
307
- "marketplace",
308
- "retail",
309
- "b2B",
310
- "social",
311
- "hub",
312
- "restaurant"
313
- ]);
314
- var StoreVisibilitySchema = z.enum(["public", "private"]);
315
- var StoreThemeSettingsSchema = z.object({
316
- name: z.string().nullable(),
317
- mode: z.string().nullable(),
318
- colors: z.record(z.string(), z.string()),
319
- fonts: z.record(z.string(), z.string()),
320
- assets: z.record(z.string(), z.string())
321
- }).strict();
322
- var StoreFeatureFlagsSchema = z.object({
323
- flags: z.record(z.string(), z.boolean())
324
- }).strict();
325
- var StoreCheckoutGeneralSettingsSchema = z.object({
326
- allowGuestCheckout: z.boolean(),
327
- identityScope: z.enum(["store", "tenant", "global"]),
328
- signInMethods: z.array(z.enum(["password", "emailOtp", "google"])),
329
- useSequentialOrderNumbers: z.boolean(),
330
- automaticallySelectFirstAddress: z.boolean(),
331
- alwaysRequestCustomerAddress: z.boolean(),
332
- requestCustomerDateOfBirth: z.boolean(),
333
- automaticallySelectBestPromotion: z.boolean()
334
- }).strict();
335
- var StoreCheckoutShippingSettingsSchema = z.object({
336
- showDeliveryTime: z.boolean(),
337
- showDeliveryTimeInDays: z.boolean(),
338
- useBusinessDaysForDeliveryTime: z.boolean(),
339
- showEstimatedDeliveryDateInThankYouAndEmails: z.boolean(),
340
- showOriginalShippingPriceWhenFree: z.boolean()
341
- }).strict();
342
- var StoreCheckoutCartPageSettingsSchema = z.object({
343
- showShippingCostCalculation: z.boolean(),
344
- allowProductLinks: z.boolean(),
345
- redirectToCartPage: z.boolean()
346
- }).strict();
347
- var StoreCheckoutOrderBumpSettingsSchema = z.object({
348
- mergeOrderBumpOrders: z.boolean(),
349
- allowOnlyOneAdditionalOffer: z.boolean(),
350
- maxVisibleOffers: z.number().int()
351
- }).strict();
352
- var StoreCheckoutOrdersAndPaymentsSettingsSchema = z.object({
353
- allowPurchasesFrom: z.enum(["any", "individual", "company"]),
354
- creditCardDailyOrderLimitPerIp: z.number().int().nullable(),
355
- maximumItemsPerOrder: z.number().int().nullable(),
356
- deliveryNoteText: z.string().nullable(),
357
- boletoPaymentNoteText: z.string().nullable()
358
- }).strict();
359
- var StoreCheckoutSettingsSchema = z.object({
360
- general: StoreCheckoutGeneralSettingsSchema,
361
- shipping: StoreCheckoutShippingSettingsSchema,
362
- cartPage: StoreCheckoutCartPageSettingsSchema,
363
- orderBumps: StoreCheckoutOrderBumpSettingsSchema,
364
- ordersAndPayments: StoreCheckoutOrdersAndPaymentsSettingsSchema
365
- }).strict();
366
- var StorefrontStoreShape = {
367
- id: EntityIdSchema,
368
- tenantId: EntityIdSchema,
369
- sellerId: NullableEntityIdSchema,
370
- type: StoreTypeSchema,
371
- isActive: z.boolean(),
372
- name: z.string(),
373
- description: z.string(),
374
- logo: z.string().nullable(),
375
- icon: z.string().nullable(),
376
- slug: z.string().nullable(),
377
- domain: z.string().nullable(),
378
- domains: z.array(z.string()),
379
- timeZone: z.string(),
380
- currency: z.string(),
381
- language: z.string(),
382
- visibility: StoreVisibilitySchema,
383
- themeConfig: StoreThemeSettingsSchema,
384
- featuresEnabled: StoreFeatureFlagsSchema,
385
- checkoutSettings: StoreCheckoutSettingsSchema
386
- };
387
- var StoreModelSchema = z.object(StorefrontStoreShape).strict();
388
- var CmsBrandingSettingsDtoSchema = z.object({
389
- logoUrl: z.string().nullable(),
390
- logoDarkUrl: z.string().nullable(),
391
- faviconUrl: z.string().nullable(),
392
- socialImageUrl: z.string().nullable()
393
- }).strict();
394
- var CmsSeoSettingsDtoSchema = z.object({
395
- siteName: z.string().nullable(),
396
- metaTitle: z.string().nullable(),
397
- metaDescription: z.string().nullable(),
398
- titleTemplate: z.string().nullable(),
399
- robotsIndex: z.boolean()
400
- }).strict();
401
- var CmsSocialLinksDtoSchema = z.object({
402
- instagram: z.string().nullable(),
403
- facebook: z.string().nullable(),
404
- tiktok: z.string().nullable(),
405
- youtube: z.string().nullable(),
406
- x: z.string().nullable()
407
- }).strict();
408
- var CmsContactSettingsDtoSchema = z.object({
409
- supportEmail: z.string().nullable(),
410
- phone: z.string().nullable(),
411
- whatsapp: z.string().nullable(),
412
- address: z.string().nullable(),
413
- socialLinks: CmsSocialLinksDtoSchema
414
- }).strict();
415
- var CmsTrackingSettingsDtoSchema = z.object({
416
- googleAnalyticsMeasurementId: z.string().nullable(),
417
- metaPixelId: z.string().nullable(),
418
- googleTagManagerContainerId: z.string().nullable()
419
- }).strict();
420
- var CmsCustomScriptsDtoSchema = z.object({
421
- enabled: z.boolean(),
422
- head: z.string().nullable(),
423
- bodyEnd: z.string().nullable()
424
- }).strict();
425
- var CmsSiteSettingsDtoSchema = z.object({
426
- themeKey: z.string(),
427
- branding: CmsBrandingSettingsDtoSchema,
428
- seo: CmsSeoSettingsDtoSchema,
429
- contact: CmsContactSettingsDtoSchema,
430
- tracking: CmsTrackingSettingsDtoSchema,
431
- customScripts: CmsCustomScriptsDtoSchema,
432
- updatedOn: NullableDateTimeOffsetSchema
433
- }).strict();
434
- var CmsMenuItemSchema = z.lazy(
435
- () => z.object({
436
- label: z.string(),
437
- url: z.string(),
438
- order: z.number().int(),
439
- target: z.string().nullable(),
440
- visible: z.boolean().nullable(),
441
- children: z.array(CmsMenuItemSchema).nullable()
442
- }).strict()
443
- );
444
- var CmsMenuDtoSchema = z.object({
445
- key: z.string(),
446
- name: z.string(),
447
- items: z.array(CmsMenuItemSchema)
448
- }).strict();
449
- var CmsBlockDtoSchema = z.object({
450
- id: EntityIdSchema,
451
- type: z.string(),
452
- order: z.number().int(),
453
- settings: JsonElementSchema
454
- }).strict();
455
- var CmsSectionDtoSchema = z.object({
456
- id: EntityIdSchema,
457
- type: z.string(),
458
- order: z.number().int(),
459
- settings: JsonElementSchema,
460
- blocks: z.array(CmsBlockDtoSchema)
461
- }).strict();
462
- var CmsContentChannelSchema = z.enum(["storefront", "pos"]);
463
- var CmsPageStatusSchema = z.enum(["draft", "published", "archived"]);
464
- var CmsPageDetailsDtoSchema = z.object({
465
- id: EntityIdSchema,
466
- name: z.string(),
467
- slug: z.string(),
468
- channel: CmsContentChannelSchema,
469
- layout: z.string(),
470
- version: z.number().int().nullable(),
471
- settings: JsonElementSchema,
472
- sections: z.array(CmsSectionDtoSchema),
473
- status: CmsPageStatusSchema,
474
- hasPublishedVersion: z.boolean(),
475
- publishedOn: NullableDateTimeOffsetSchema,
476
- publishedBy: NullableEntityIdSchema,
477
- createdOn: DateTimeOffsetSchema,
478
- updatedOn: NullableDateTimeOffsetSchema,
479
- createdBy: NullableEntityIdSchema,
480
- updatedBy: NullableEntityIdSchema,
481
- lastModifiedBy: z.string().nullable()
482
- }).strict();
483
- var CmsSnapshotDtoSchema = z.object({
484
- settings: CmsSiteSettingsDtoSchema,
485
- pages: z.array(CmsPageDetailsDtoSchema),
486
- menus: z.array(CmsMenuDtoSchema)
487
- }).strict();
488
- var StoreSettingsSnapshotV1Schema = z.object({
489
- schemaVersion: z.literal(1),
490
- generatedAt: DateTimeOffsetSchema,
491
- store: z.object(StorefrontStoreShape),
492
- cms: CmsSnapshotDtoSchema
493
- }).strict();
494
- var StoreSettingsSnapshotV2Schema = z.object({
495
- schemaVersion: z.literal(2),
496
- generatedAt: DateTimeOffsetSchema,
497
- store: StoreModelSchema,
498
- cms: CmsSnapshotDtoSchema
499
- }).strict();
500
- var StoreSettingsSnapshotDtoSchema = z.discriminatedUnion(
501
- "schemaVersion",
502
- [StoreSettingsSnapshotV1Schema, StoreSettingsSnapshotV2Schema]
503
- );
504
- var StorefrontSettingsSchema = StoreSettingsSnapshotDtoSchema;
505
-
506
- // src/services/product.service.ts
507
- async function getProducts(api, params = {}) {
508
- const input = ProductsParamsSchema.parse(params);
509
- const query = new URLSearchParams();
510
- query.set("page", String(input.page));
511
- query.set("pageSize", String(input.pageSize));
512
- if (input.sort) query.set("sort", input.sort);
513
- if (input.sellerId) query.set("sellerId", input.sellerId);
514
- if (input.search) query.set("search", input.search);
515
- if (input.collection) query.set("collection", input.collection);
516
- for (const collection of input.collections ?? []) {
517
- query.append("collections", collection);
518
- }
519
- if (input.collectionId) query.set("collectionId", input.collectionId);
520
- if (input.category) query.set("category", input.category);
521
- for (const category of input.categories ?? []) {
522
- query.append("categories", category);
523
- }
524
- if (input.brand) query.set("brand", input.brand);
525
- for (const brand of input.brands ?? []) {
526
- query.append("brands", brand);
527
- }
528
- if (input.productType) query.set("productType", input.productType);
529
- for (const productType of input.productTypes ?? []) {
530
- query.append("productTypes", productType);
531
- }
532
- if (input.tag) query.set("tag", input.tag);
533
- for (const tag of input.tags ?? []) {
534
- query.append("tags", tag);
535
- }
536
- for (const filter of input.filters ?? []) {
537
- query.append("filters", filter);
538
- }
539
- if (input.locationId) query.set("locationId", input.locationId);
540
- if (input.inStock !== void 0) query.set("inStock", String(input.inStock));
541
- if (input.minPrice !== void 0) query.set("minPrice", String(input.minPrice));
542
- if (input.maxPrice !== void 0) query.set("maxPrice", String(input.maxPrice));
543
- return api.get(`products?${query.toString()}`, ProductsResponseSchema);
544
- }
545
- async function getProductBySlug(api, slug, params = {}) {
546
- const input = ProductDetailParamsSchema.parse(params);
547
- const query = new URLSearchParams();
548
- if (input.sellerId) query.set("sellerId", input.sellerId);
549
- const path = `products/${encodeURIComponent(slug)}`;
550
- const search = query.toString();
551
- if (search) {
552
- return api.get(`${path}?${search}`, ProductDetailSchema);
553
- }
554
- return api.get(path, ProductDetailSchema);
555
- }
556
- async function getRelatedProducts(api, params) {
557
- const input = RelatedProductsParamsSchema.parse(params);
558
- return api.get(
559
- `products/${encodeURIComponent(input.productId)}/related`,
560
- ProductSummariesSchema,
561
- {
562
- query: {
563
- limit: input.limit,
564
- sellerId: input.sellerId
565
- }
566
- }
567
- );
568
- }
569
- var ProductAutocompleteParamsSchema = z.object({
570
- search: z.string().min(2).max(80),
571
- limit: z.number().int().positive().max(20).default(8),
572
- sellerId: OptionalEntityIdSchema
573
- });
574
- var ProductSuggestionSchema = z.object({
575
- id: EntityIdSchema,
576
- name: z.string(),
577
- slug: z.string(),
578
- imageUrl: z.string()
579
- });
580
- var ProductSuggestionsSchema = z.array(ProductSuggestionSchema);
581
-
582
- // src/services/search.service.ts
583
- async function autocompleteProducts(api, params) {
584
- const input = ProductAutocompleteParamsSchema.parse(params);
585
- return api.get("search/autocomplete", ProductSuggestionsSchema, {
586
- query: {
587
- search: input.search,
588
- limit: input.limit,
589
- sellerId: input.sellerId
590
- }
591
- });
592
- }
593
- var StorefrontReviewSchema = z.object({
594
- id: EntityIdSchema,
595
- productId: EntityIdSchema,
596
- isVerifiedPurchase: z.boolean(),
597
- rating: z.number().int().min(1).max(5),
598
- title: z.string().nullable(),
599
- content: z.string(),
600
- reviewerName: z.string().nullable(),
601
- createdOn: z.string().datetime({ offset: true })
602
- });
603
- var StorefrontReviewsSchema = z.object({
604
- data: z.array(StorefrontReviewSchema),
605
- hasNextPage: z.boolean(),
606
- nextCursor: z.string().nullable(),
607
- totalCount: z.number().int().nonnegative().nullable()
608
- });
609
- var ListProductReviewsParamsSchema = z.object({
610
- productId: EntityIdSchema,
611
- limit: z.number().int().min(1).max(200).optional(),
612
- cursor: z.string().optional(),
613
- search: z.string().optional(),
614
- sortBy: z.enum(["rating", "createdOn"]).optional(),
615
- sortDirection: z.enum(["asc", "desc"]).optional(),
616
- rating: z.number().int().min(1).max(5).optional()
617
- });
618
- var CreateProductReviewParamsSchema = z.object({
619
- productId: EntityIdSchema,
620
- rating: z.number().int().min(1).max(5),
621
- content: z.string().min(1).max(4e3),
622
- title: z.string().max(200).optional(),
623
- reviewerName: z.string().min(1).max(200),
624
- reviewerEmail: z.string().email().max(320),
625
- orderId: EntityIdSchema.optional()
626
- });
627
-
628
- // src/services/review.service.ts
629
- async function listProductReviews(api, params) {
630
- const input = ListProductReviewsParamsSchema.parse(params);
631
- return api.get(
632
- `products/${encodeURIComponent(input.productId)}/reviews`,
633
- StorefrontReviewsSchema,
634
- {
635
- query: {
636
- limit: input.limit,
637
- cursor: input.cursor,
638
- search: input.search,
639
- sortBy: input.sortBy,
640
- sortDirection: input.sortDirection,
641
- rating: input.rating
642
- }
643
- }
644
- );
645
- }
646
- async function createProductReview(api, params) {
647
- const input = CreateProductReviewParamsSchema.parse(params);
648
- return api.post(
649
- `products/${encodeURIComponent(input.productId)}/reviews`,
650
- {
651
- rating: input.rating,
652
- content: input.content,
653
- title: input.title,
654
- reviewerName: input.reviewerName,
655
- reviewerEmail: input.reviewerEmail,
656
- orderId: input.orderId
657
- },
658
- StorefrontReviewSchema
659
- );
660
- }
661
- var StorefrontAddressSchema = z.object({
662
- name: z.string().nullable(),
663
- address1: z.string(),
664
- city: z.string(),
665
- countryCode: z.string(),
666
- company: z.string().nullable(),
667
- address2: z.string().nullable(),
668
- province: z.string().nullable(),
669
- postalCode: z.string().nullable(),
670
- district: z.string().nullable(),
671
- phone: z.string().nullable(),
672
- latitude: z.number().nullable(),
673
- longitude: z.number().nullable()
674
- });
675
- var StorefrontCartBundleItemSchema = z.object({
676
- productId: EntityIdSchema,
677
- variantId: EntityIdSchema,
678
- productName: z.string(),
679
- variantName: z.string().nullable(),
680
- sku: z.string().nullable(),
681
- brand: z.string().nullable(),
682
- imageUrl: z.string().nullable(),
683
- quantity: z.number().int().positive()
684
- });
685
- var StorefrontCartItemSchema = z.object({
686
- id: EntityIdSchema,
687
- productId: NullableEntityIdSchema,
688
- title: z.string(),
689
- variantLabel: z.string().nullable(),
690
- productHandle: z.string().nullable(),
691
- thumbnail: z.string().nullable(),
692
- quantity: z.number().int().positive(),
693
- variantId: NullableEntityIdSchema,
694
- variantSku: z.string().nullable(),
695
- unitPrice: z.number(),
696
- compareAtUnitPrice: z.number().nullable(),
697
- bundleItems: z.array(StorefrontCartBundleItemSchema)
698
- });
699
- var StorefrontCartShippingMethodSchema = z.object({
700
- id: EntityIdSchema,
701
- shippingMethodId: NullableEntityIdSchema,
702
- rateId: NullableEntityIdSchema,
703
- name: z.string(),
704
- description: z.string().nullable(),
705
- total: z.number(),
706
- locationId: NullableEntityIdSchema,
707
- estimatedDays: z.number().int().nullable(),
708
- pickupPointId: NullableEntityIdSchema,
709
- scheduledDate: z.string().nullable(),
710
- scheduledTime: z.string().nullable(),
711
- serviceCode: z.string().nullable(),
712
- sellerId: NullableEntityIdSchema,
713
- shippingProfileId: NullableEntityIdSchema
714
- });
715
- var StorefrontCartTotalsSchema = z.object({
716
- subtotal: z.number(),
717
- discountTotal: z.number(),
718
- shippingOriginalTotal: z.number(),
719
- shippingTotal: z.number(),
720
- taxTotal: z.number(),
721
- warrantyTotal: z.number(),
722
- total: z.number()
723
- });
724
- var StorefrontCartStatusSchema = z.enum([
725
- "inProgress",
726
- "pending",
727
- "completed",
728
- "abandoned",
729
- "cancelled",
730
- "expired",
731
- "failed"
732
- ]);
733
- var StorefrontCartSchema = z.object({
734
- id: EntityIdSchema,
735
- token: CartTokenSchema,
736
- cartNumber: z.string(),
737
- email: z.string().nullable(),
738
- phone: z.string().nullable(),
739
- firstName: z.string().nullable(),
740
- lastName: z.string().nullable(),
741
- currencyCode: z.string(),
742
- status: StorefrontCartStatusSchema,
743
- completedAt: z.string().datetime({ offset: true }).nullable(),
744
- shippingAddress: StorefrontAddressSchema.nullable(),
745
- billingAddress: StorefrontAddressSchema.nullable(),
746
- promotionCodes: z.array(z.string()),
747
- items: z.array(StorefrontCartItemSchema),
748
- shippingMethods: z.array(StorefrontCartShippingMethodSchema),
749
- totals: StorefrontCartTotalsSchema
750
- });
751
- var CreateCartParamsSchema = z.object({
752
- currencyCode: z.string().length(3),
753
- salesChannelId: z.string().optional(),
754
- email: z.string().email().optional()
755
- });
756
- var GetCartParamsSchema = z.object({
757
- cartToken: CartTokenSchema
758
- });
759
- var CartItemModifierSchema = z.object({
760
- modifierGroupId: EntityIdSchema,
761
- optionIds: z.array(EntityIdSchema).min(1)
762
- });
763
- var AddCartItemParamsSchema = z.object({
764
- cartToken: CartTokenSchema,
765
- variantId: EntityIdSchema,
766
- quantity: z.number().int().positive(),
767
- modifiers: z.array(CartItemModifierSchema).optional()
768
- });
769
- var UpdateCartItemQuantityParamsSchema = z.object({
770
- cartToken: CartTokenSchema,
771
- cartItemId: EntityIdSchema,
772
- quantity: z.number().int().nonnegative()
773
- });
774
- var RemoveCartItemParamsSchema = z.object({
775
- cartToken: CartTokenSchema,
776
- cartItemId: EntityIdSchema
777
- });
778
-
779
- // src/services/cart.service.ts
780
- async function createCart(api, params) {
781
- const input = CreateCartParamsSchema.parse(params);
782
- return api.post(
783
- "carts",
784
- {
785
- currencyCode: input.currencyCode,
786
- salesChannelId: input.salesChannelId,
787
- email: input.email
788
- },
789
- StorefrontCartSchema
790
- );
791
- }
792
- async function getCart(api, params) {
793
- const input = GetCartParamsSchema.parse(params);
794
- return api.get(
795
- `carts/${encodeURIComponent(input.cartToken)}`,
796
- StorefrontCartSchema
797
- );
798
- }
799
- async function addCartItem(api, params) {
800
- const input = AddCartItemParamsSchema.parse(params);
801
- return api.post(
802
- `carts/${encodeURIComponent(input.cartToken)}/items`,
803
- {
804
- variantId: input.variantId,
805
- quantity: input.quantity,
806
- modifiers: input.modifiers
807
- },
808
- StorefrontCartSchema
809
- );
810
- }
811
- async function updateCartItemQuantity(api, params) {
812
- const input = UpdateCartItemQuantityParamsSchema.parse(params);
813
- return api.request(
814
- "PATCH",
815
- `carts/${encodeURIComponent(input.cartToken)}/items/${encodeURIComponent(input.cartItemId)}`,
816
- StorefrontCartSchema,
817
- { body: { quantity: input.quantity } }
818
- );
819
- }
820
- async function removeCartItem(api, params) {
821
- const input = RemoveCartItemParamsSchema.parse(params);
822
- return api.request(
823
- "DELETE",
824
- `carts/${encodeURIComponent(input.cartToken)}/items/${encodeURIComponent(input.cartItemId)}`,
825
- StorefrontCartSchema
826
- );
827
- }
828
-
829
- // src/services/collection.service.ts
830
- async function getCollections(api) {
831
- return api.get("collections", CollectionsSchema);
832
- }
833
- async function getCollectionBySlug(api, collectionSlug) {
834
- return api.get(`collections/${encodeURIComponent(collectionSlug)}`, CollectionSchema);
835
- }
836
-
837
- // src/services/page.service.ts
838
- async function getPageBySlug(api, pageSlug) {
839
- return api.get(`pages/${encodeURIComponent(pageSlug)}`, CmsPageDetailsDtoSchema);
840
- }
841
- var CheckoutMetadataValueSchema = z.lazy(
842
- () => z.union([
843
- z.string(),
844
- z.number(),
845
- z.boolean(),
846
- z.null(),
847
- z.array(CheckoutMetadataValueSchema),
848
- z.record(z.string(), CheckoutMetadataValueSchema)
849
- ])
850
- );
851
- var CartBuyerParamsSchema = z.object({
852
- cartToken: CartTokenSchema,
853
- email: z.string().email(),
854
- firstName: z.string().min(1),
855
- lastName: z.string().min(1),
856
- phone: z.string().min(1)
857
- });
858
- var CartAddressWriteSchema = z.object({
859
- name: z.string().min(1),
860
- address1: z.string().min(1),
861
- city: z.string().min(1),
862
- countryCode: z.string().length(2),
863
- company: z.string().nullable().optional(),
864
- address2: z.string().nullable().optional(),
865
- province: z.string().nullable().optional(),
866
- postalCode: z.string().nullable().optional(),
867
- district: z.string().nullable().optional(),
868
- phone: z.string().nullable().optional(),
869
- latitude: z.number().nullable().optional(),
870
- longitude: z.number().nullable().optional(),
871
- geo: z.object({
872
- departmentCode: z.string().nullable().optional(),
873
- provinceCode: z.string().nullable().optional(),
874
- districtCode: z.string().nullable().optional()
875
- }).nullable().optional()
876
- });
877
- var CartAddressesParamsSchema = z.object({
878
- cartToken: CartTokenSchema,
879
- shippingAddress: CartAddressWriteSchema,
880
- billingAddress: CartAddressWriteSchema
881
- });
882
- var CartPaymentMethodSchema = z.object({
883
- code: z.string(),
884
- name: z.string(),
885
- description: z.string().nullable().optional(),
886
- kind: z.string(),
887
- providerMethodCode: z.string().nullable().optional(),
888
- isActive: z.boolean(),
889
- isDefault: z.boolean(),
890
- isManual: z.boolean(),
891
- sortOrder: z.number(),
892
- phoneNumber: z.string().nullable().optional(),
893
- accountHolder: z.string().nullable().optional(),
894
- qrImageUrl: z.string().nullable().optional()
895
- });
896
- var StorefrontOrderBumpSchema = z.object({
897
- id: EntityIdSchema,
898
- productId: EntityIdSchema,
899
- variantId: EntityIdSchema,
900
- productName: z.string(),
901
- variantName: z.string().nullable().optional(),
902
- imageUrl: z.string().nullable().optional(),
903
- currencyCode: z.string(),
904
- regularPrice: z.number(),
905
- offerPrice: z.number(),
906
- badgeLabel: z.string().nullable().optional(),
907
- callToAction: z.string(),
908
- description: z.string().nullable().optional()
909
- });
910
- var CartCheckoutReadParamsSchema = z.object({
911
- cartToken: CartTokenSchema
912
- });
913
- var CartCheckoutReadResponseSchema = z.object({
914
- cart: StorefrontCartSchema,
915
- paymentMethods: z.object({
916
- methods: z.array(CartPaymentMethodSchema)
917
- }),
918
- orderBumps: z.array(StorefrontOrderBumpSchema).optional().default([])
919
- });
920
- var CartCheckoutPaymentActionSchema = z.object({
921
- publicConfiguration: z.object({
922
- publishableKey: z.string().nullable().optional(),
923
- checkoutMode: z.string().nullable().optional(),
924
- phoneNumber: z.string().nullable().optional(),
925
- accountHolder: z.string().nullable().optional(),
926
- qrImageUrl: z.string().nullable().optional()
927
- }).strip().nullable().optional(),
928
- url: z.string().nullable().optional(),
929
- html: z.string().nullable().optional(),
930
- clientSecret: z.string().nullable().optional(),
931
- qrCode: z.string().nullable().optional(),
932
- expiresAt: z.string().nullable().optional()
933
- }).strip();
934
- var CartCheckoutPaymentSchema = z.object({
935
- transactionId: z.string(),
936
- paymentMethodCode: z.string(),
937
- providerId: z.string().nullable().optional(),
938
- status: z.string(),
939
- amount: z.number(),
940
- reference: z.string(),
941
- actionType: z.string(),
942
- receiptUrl: z.string().nullable().optional(),
943
- action: CartCheckoutPaymentActionSchema.nullable().optional()
944
- }).strip();
945
- var CartCheckoutResponseSchema = z.object({
946
- publicKey: z.string().optional(),
947
- publishableKey: z.string().optional(),
948
- stripePublicKey: z.string().optional(),
949
- clientSecret: z.string().optional(),
950
- intentClientSecret: z.string().optional(),
951
- orderId: EntityIdSchema.optional(),
952
- orderGroup: z.string().optional(),
953
- orderIds: z.array(EntityIdSchema).optional(),
954
- payment: CartCheckoutPaymentSchema.optional(),
955
- cart: StorefrontCartSchema.optional()
956
- }).strip();
957
- var CartCheckoutParamsSchema = z.object({
958
- cartToken: CartTokenSchema,
959
- paymentMethodCode: z.string().min(1),
960
- externalRef: z.string().min(1),
961
- receiptUrl: z.string().min(1).optional()
962
- });
963
- var ShippingRateSchema = z.object({
964
- shippingMethodId: z.string(),
965
- name: z.string(),
966
- displayName: z.string().optional(),
967
- type: z.string().optional(),
968
- price: z.number(),
969
- currency: z.string().optional(),
970
- sortOrder: z.number().optional(),
971
- rateId: z.string(),
972
- description: z.string().nullable().optional(),
973
- deliveryLocationId: z.string().nullable().optional(),
974
- deliveryLocationName: z.string().nullable().optional(),
975
- estimatedDeliveryDays: z.number().nullable().optional(),
976
- serviceCode: z.string().nullable().optional(),
977
- metadata: z.record(z.string(), CheckoutMetadataValueSchema).optional()
978
- }).strip();
979
- var ShippingOptionGroupSchema = z.object({
980
- sellerId: z.string(),
981
- shippingProfileId: z.string().nullable().optional(),
982
- orderAmount: z.number().optional(),
983
- totalWeight: z.number().optional(),
984
- itemIds: z.array(z.string()).optional(),
985
- rates: z.array(ShippingRateSchema)
986
- }).strip();
987
- var ShippingOptionsResponseSchema = z.object({
988
- groups: z.array(ShippingOptionGroupSchema)
989
- });
990
- var GetShippingOptionsParamsSchema = z.object({
991
- cartToken: CartTokenSchema,
992
- postalCode: z.string().min(1)
993
- });
994
- var PutShippingMethodParamsSchema = z.object({
995
- cartToken: CartTokenSchema,
996
- rateId: z.string().min(1),
997
- shippingMethodId: z.string().min(1),
998
- serviceCode: z.string().nullable().optional(),
999
- sellerId: z.string().nullable().optional(),
1000
- shippingProfileId: z.string().nullable().optional(),
1001
- locationId: z.string().nullable().optional(),
1002
- pickupPointId: z.string().nullable().optional(),
1003
- scheduledDate: z.string().nullable().optional(),
1004
- scheduledTime: z.string().nullable().optional()
1005
- });
1006
- var CartPaymentReceiptResponseSchema = z.object({
1007
- id: z.string(),
1008
- url: z.string()
1009
- });
1010
- var CartPromotionCodeParamsSchema = z.object({
1011
- cartToken: CartTokenSchema,
1012
- code: z.string().min(1)
1013
- });
1014
-
1015
- // src/services/checkout.service.ts
1016
- async function getCartCheckout(api, params) {
1017
- const input = CartCheckoutReadParamsSchema.parse(params);
1018
- return api.get(
1019
- `carts/${encodeURIComponent(input.cartToken)}/checkout`,
1020
- CartCheckoutReadResponseSchema
1021
- );
1022
- }
1023
- async function getShippingOptions(api, params) {
1024
- const input = GetShippingOptionsParamsSchema.parse(params);
1025
- return api.get(
1026
- `carts/${encodeURIComponent(input.cartToken)}/shipping-options`,
1027
- ShippingOptionsResponseSchema,
1028
- { query: { postalCode: input.postalCode } }
1029
- );
1030
- }
1031
- async function putCartShippingMethod(api, params) {
1032
- const input = PutShippingMethodParamsSchema.parse(params);
1033
- const { cartToken, ...body } = input;
1034
- return api.request(
1035
- "PUT",
1036
- `carts/${encodeURIComponent(cartToken)}/shipping-method`,
1037
- StorefrontCartSchema,
1038
- { body }
1039
- );
1040
- }
1041
- async function patchCartBuyer(api, params) {
1042
- const input = CartBuyerParamsSchema.parse(params);
1043
- const { cartToken, ...body } = input;
1044
- return api.request(
1045
- "PATCH",
1046
- `carts/${encodeURIComponent(cartToken)}/buyer`,
1047
- StorefrontCartSchema,
1048
- { body }
1049
- );
1050
- }
1051
- async function patchCartAddresses(api, params) {
1052
- const input = CartAddressesParamsSchema.parse(params);
1053
- const { cartToken, shippingAddress, billingAddress } = input;
1054
- return api.request(
1055
- "PATCH",
1056
- `carts/${encodeURIComponent(cartToken)}/addresses`,
1057
- StorefrontCartSchema,
1058
- { body: { shippingAddress, billingAddress } }
1059
- );
1060
- }
1061
- async function checkoutCart(api, params) {
1062
- const input = CartCheckoutParamsSchema.parse(params);
1063
- const { cartToken, ...body } = input;
1064
- return api.post(
1065
- `carts/${encodeURIComponent(cartToken)}/checkout`,
1066
- body,
1067
- CartCheckoutResponseSchema
1068
- );
1069
- }
1070
- async function uploadPaymentReceipt(api, params) {
1071
- const cartToken = CartCheckoutReadParamsSchema.shape.cartToken.parse(params.cartToken);
1072
- if (!(params.file instanceof Blob)) {
1073
- throw new TypeError("uploadPaymentReceipt requiere un archivo (Blob/File)");
1074
- }
1075
- const form = new FormData();
1076
- const name = params.fileName ?? (params.file instanceof File ? params.file.name : "receipt");
1077
- form.append("file", params.file, name);
1078
- return api.postForm(
1079
- `carts/${encodeURIComponent(cartToken)}/payment-receipt`,
1080
- form,
1081
- CartPaymentReceiptResponseSchema
1082
- );
1083
- }
1084
- async function addCartPromotionCode(api, params) {
1085
- const input = CartPromotionCodeParamsSchema.parse(params);
1086
- return api.post(
1087
- `carts/${encodeURIComponent(input.cartToken)}/promotion-codes`,
1088
- { code: input.code },
1089
- StorefrontCartSchema
1090
- );
1091
- }
1092
- async function removeCartPromotionCode(api, params) {
1093
- const input = CartPromotionCodeParamsSchema.parse(params);
1094
- return api.request(
1095
- "DELETE",
1096
- `carts/${encodeURIComponent(input.cartToken)}/promotion-codes/${encodeURIComponent(input.code)}`,
1097
- StorefrontCartSchema
1098
- );
1099
- }
1100
- var CountrySchema = z.object({
1101
- code: z.string().length(2),
1102
- name: z.string().min(1)
1103
- }).strict();
1104
- var CountriesSchema = z.array(CountrySchema);
1105
- var GeoDivisionTypeSchema = z.enum(["level1", "level2", "level3"]);
1106
- var GeoDivisionSchema = z.object({
1107
- id: EntityIdSchema,
1108
- countryCode: z.string().length(2),
1109
- type: GeoDivisionTypeSchema,
1110
- code: z.string().min(1),
1111
- name: z.string().min(1),
1112
- parentId: NullableEntityIdSchema,
1113
- source: z.string().min(1)
1114
- }).strict();
1115
- var DepartmentSchema = GeoDivisionSchema;
1116
- var DepartmentsSchema = z.array(DepartmentSchema);
1117
- var GetDepartmentsParamsSchema = z.object({
1118
- countryCode: z.string().length(2),
1119
- source: z.string().min(1).default("inei"),
1120
- search: z.string().default(""),
1121
- limit: z.number().int().positive().max(500).default(200)
1122
- });
1123
- var ProvinceSchema = GeoDivisionSchema;
1124
- var ProvincesSchema = z.array(ProvinceSchema);
1125
- var GetProvincesParamsSchema = z.object({
1126
- countryCode: z.string().length(2),
1127
- departmentCode: z.string().min(1),
1128
- source: z.string().min(1).default("inei"),
1129
- search: z.string().default(""),
1130
- limit: z.number().int().positive().max(500).default(200)
1131
- });
1132
- var DistrictSchema = GeoDivisionSchema;
1133
- var DistrictsSchema = z.array(DistrictSchema);
1134
- var GetDistrictsParamsSchema = z.object({
1135
- countryCode: z.string().length(2),
1136
- provinceCode: z.string().min(1),
1137
- source: z.string().min(1).default("inei"),
1138
- search: z.string().default(""),
1139
- limit: z.number().int().positive().max(500).default(200)
1140
- });
1141
-
1142
- // src/services/geo.service.ts
1143
- async function getCountries(api) {
1144
- return api.get("geo/countries", CountriesSchema);
1145
- }
1146
- async function getDepartments(api, params) {
1147
- const input = GetDepartmentsParamsSchema.parse(params);
1148
- return api.get("geo/departments", DepartmentsSchema, {
1149
- query: {
1150
- countryCode: input.countryCode,
1151
- source: input.source,
1152
- search: input.search,
1153
- limit: input.limit
1154
- }
1155
- });
1156
- }
1157
- async function getProvinces(api, params) {
1158
- const input = GetProvincesParamsSchema.parse(params);
1159
- return api.get("geo/provinces", ProvincesSchema, {
1160
- query: {
1161
- countryCode: input.countryCode,
1162
- departmentCode: input.departmentCode,
1163
- source: input.source,
1164
- search: input.search,
1165
- limit: input.limit
1166
- }
1167
- });
1168
- }
1169
- async function getDistricts(api, params) {
1170
- const input = GetDistrictsParamsSchema.parse(params);
1171
- return api.get("geo/districts", DistrictsSchema, {
1172
- query: {
1173
- countryCode: input.countryCode,
1174
- provinceCode: input.provinceCode,
1175
- source: input.source,
1176
- search: input.search,
1177
- limit: input.limit
1178
- }
1179
- });
1180
- }
1181
- var CustomerAddressUpsertInputSchema = z.object({
1182
- addressKey: z.string().trim().min(1),
1183
- countryIsoCode: z.string().trim().length(2),
1184
- addressLine: z.string().trim().min(1),
1185
- addressNumber: z.string().trim().min(1),
1186
- department: z.string().trim().min(1),
1187
- province: z.string().trim().min(1),
1188
- district: z.string().trim().min(1),
1189
- phone: z.string().trim(),
1190
- cellPhone: z.string().trim(),
1191
- postalCode: z.string().trim().min(1),
1192
- reference: z.string().trim(),
1193
- latitude: z.number().nullable(),
1194
- longitude: z.number().nullable(),
1195
- isDefault: z.boolean()
1196
- });
1197
- var CustomerAddressSchema = CustomerAddressUpsertInputSchema.extend({
1198
- id: EntityIdSchema.optional()
1199
- });
1200
- var CustomerAddressesSchema = z.array(CustomerAddressSchema);
1201
-
1202
- // src/services/customer-address.service.ts
1203
- var ADDRESSES_PATH = "customer/addresses";
1204
- var CustomerAddressMutationResponseSchema = z.union([
1205
- CustomerAddressSchema,
1206
- z.object({
1207
- id: EntityIdSchema
1208
- }),
1209
- z.null()
1210
- ]);
1211
- async function getCustomerAddresses(api, options = {}) {
1212
- return api.get(ADDRESSES_PATH, CustomerAddressesSchema, {
1213
- headers: options.headers,
1214
- signal: options.signal
1215
- });
1216
- }
1217
- async function createCustomerAddress(api, data, options = {}) {
1218
- const payload = CustomerAddressUpsertInputSchema.parse(data);
1219
- return api.post(ADDRESSES_PATH, payload, CustomerAddressMutationResponseSchema, {
1220
- headers: options.headers,
1221
- signal: options.signal
1222
- });
1223
- }
1224
- async function updateCustomerAddress(api, addressId, data, options = {}) {
1225
- const id = addressId.trim();
1226
- if (!id) throw new Error("addressId requerido");
1227
- const payload = CustomerAddressUpsertInputSchema.parse(data);
1228
- return api.request(
1229
- "PUT",
1230
- `${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
1231
- CustomerAddressMutationResponseSchema,
1232
- {
1233
- body: payload,
1234
- headers: options.headers,
1235
- signal: options.signal
1236
- }
1237
- );
1238
- }
1239
- async function deleteCustomerAddress(api, addressId, options = {}) {
1240
- const id = addressId.trim();
1241
- if (!id) throw new Error("addressId requerido");
1242
- await api.request(
1243
- "DELETE",
1244
- `${ADDRESSES_PATH}/${encodeURIComponent(id)}`,
1245
- z.null(),
1246
- {
1247
- headers: options.headers,
1248
- signal: options.signal
1249
- }
1250
- );
1251
- }
1252
- var DEFAULT_COUNTRY_CODE = "PE";
1253
- z.object({
1254
- email: z.string().email(),
1255
- firstName: z.string().trim().min(1),
1256
- lastName: z.string().trim().min(1),
1257
- countryIsoCode: z.string().trim().length(2),
1258
- password: z.string().min(1),
1259
- phone: z.string().trim().min(1).optional()
1260
- });
1261
- var CustomerProfilePatchSchema = z.object({
1262
- firstName: z.string().trim().min(1),
1263
- lastName: z.string().trim().min(1),
1264
- phone: z.string().trim(),
1265
- identificationNumber: z.string().nullable(),
1266
- identificationType: z.string().nullable(),
1267
- entityName: z.string().nullable(),
1268
- entityIdentificationNumber: z.string().nullable(),
1269
- gender: z.string().nullable(),
1270
- role: z.string().nullable(),
1271
- companyName: z.string().nullable(),
1272
- dateOfBirth: z.string().nullable(),
1273
- consent: z.boolean(),
1274
- countryIsoCode: z.string().trim().length(2)
1275
- });
1276
- z.object({
1277
- firstName: z.string(),
1278
- lastName: z.string(),
1279
- phone: z.string(),
1280
- email: z.string().email(),
1281
- identificationNumber: z.string().nullable(),
1282
- identificationType: z.string().nullable(),
1283
- countryIsoCode: z.string(),
1284
- consent: z.boolean(),
1285
- entityName: z.string().nullable(),
1286
- entityIdentificationNumber: z.string().nullable(),
1287
- gender: z.string().nullable(),
1288
- role: z.string().nullable(),
1289
- companyName: z.string().nullable(),
1290
- dateOfBirth: z.string().nullable()
1291
- });
1292
- var nullableString = z.string().nullable().optional().transform((v) => v ?? null);
1293
- var CustomerMeSchema = z.object({
1294
- id: EntityIdSchema,
1295
- storeId: EntityIdSchema.optional(),
1296
- email: z.string().email(),
1297
- firstName: z.string(),
1298
- lastName: z.string(),
1299
- phone: z.union([z.string(), z.null()]).optional().transform((v) => v ?? ""),
1300
- identificationNumber: nullableString,
1301
- identificationType: nullableString,
1302
- entityName: nullableString,
1303
- entityIdentificationNumber: nullableString,
1304
- gender: nullableString,
1305
- role: nullableString,
1306
- companyName: nullableString,
1307
- dateOfBirth: nullableString,
1308
- countryIsoCode: z.string().optional().transform((v) => v?.trim().length === 2 ? v.trim() : DEFAULT_COUNTRY_CODE),
1309
- consent: z.boolean().optional().transform((v) => v ?? false)
1310
- }).passthrough();
1311
-
1312
- // src/services/customer.service.ts
1313
- var CUSTOMER_PATH = "customer";
1314
- async function getCustomerMe(api, options = {}) {
1315
- return api.get(CUSTOMER_PATH, CustomerMeSchema, {
1316
- headers: options.headers,
1317
- signal: options.signal
1318
- });
1319
- }
1320
- async function patchCustomer(api, data, options = {}) {
1321
- const payload = CustomerProfilePatchSchema.parse(data);
1322
- await api.request("PATCH", CUSTOMER_PATH, z.null(), {
1323
- body: payload,
1324
- headers: options.headers,
1325
- signal: options.signal
1326
- });
1327
- }
1328
- var CustomerOrderShippingAddressSchema = z.object({
1329
- name: z.string().nullable().optional(),
1330
- company: z.string().nullable().optional(),
1331
- address1: z.string(),
1332
- address2: z.string().nullable().optional(),
1333
- city: z.string().nullable().optional(),
1334
- countryCode: z.string().min(2).max(2),
1335
- province: z.string().nullable().optional(),
1336
- postalCode: z.string().nullable().optional(),
1337
- district: z.string().nullable().optional(),
1338
- phone: z.string().nullable().optional(),
1339
- latitude: z.number().nullable().optional(),
1340
- longitude: z.number().nullable().optional(),
1341
- metadata: z.record(z.unknown()).nullable().optional()
1342
- }).passthrough();
1343
- var CustomerOrderLineItemSchema = z.object({
1344
- id: EntityIdSchema,
1345
- orderId: EntityIdSchema,
1346
- productId: EntityIdSchema.nullable(),
1347
- variantId: EntityIdSchema.nullable(),
1348
- title: z.string(),
1349
- subtitle: z.string().nullable().optional(),
1350
- thumbnail: z.string().nullable().optional(),
1351
- variantTitle: z.string().nullable().optional(),
1352
- productHandle: z.string().nullable().optional(),
1353
- quantity: z.number(),
1354
- unitPrice: z.number(),
1355
- total: z.number(),
1356
- status: z.string()
1357
- });
1358
- var CustomerOrderListItemSchema = z.object({
1359
- orderId: EntityIdSchema,
1360
- orderNumber: z.string(),
1361
- orderGroup: z.string(),
1362
- orderIds: z.array(EntityIdSchema),
1363
- status: z.string(),
1364
- total: z.number(),
1365
- totalPaid: z.number(),
1366
- currencyCode: z.string(),
1367
- orderDate: z.string(),
1368
- createdOn: z.string(),
1369
- updatedOn: z.string().nullable().optional(),
1370
- paymentAt: z.string().nullable().optional(),
1371
- shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1372
- shippingAddressSummary: z.string().nullable().optional(),
1373
- items: z.array(CustomerOrderLineItemSchema)
1374
- });
1375
- var CustomerOrderListSchema = z.array(CustomerOrderListItemSchema);
1376
- var CustomerOrderPaymentSchema = z.object({
1377
- id: EntityIdSchema,
1378
- paymentMethod: z.string(),
1379
- paymentCode: z.string(),
1380
- amount: z.number(),
1381
- paymentStatus: z.string(),
1382
- receiptUrl: z.string().nullable().optional(),
1383
- createdOn: z.string()
1384
- });
1385
- var CustomerOrderStatusTimelineSchema = z.object({
1386
- key: z.string(),
1387
- label: z.string(),
1388
- occurredAt: z.string(),
1389
- description: z.string().nullable().optional(),
1390
- status: z.string(),
1391
- source: z.string()
1392
- });
1393
- var CustomerOrderDetailSchema = z.object({
1394
- id: EntityIdSchema,
1395
- orderNumber: z.string(),
1396
- orderGroup: z.string(),
1397
- status: z.string(),
1398
- total: z.number(),
1399
- totalPaid: z.number(),
1400
- currencyCode: z.string(),
1401
- orderDate: z.string(),
1402
- createdOn: z.string(),
1403
- updatedOn: z.string().nullable().optional(),
1404
- paymentAt: z.string().nullable().optional(),
1405
- subTotal: z.number(),
1406
- discount: z.number(),
1407
- shipping: z.number(),
1408
- tax: z.number(),
1409
- email: z.string(),
1410
- phone: z.string(),
1411
- firstName: z.string(),
1412
- lastName: z.string(),
1413
- shippingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1414
- shippingAddressSummary: z.string().nullable().optional(),
1415
- billingAddress: CustomerOrderShippingAddressSchema.nullable().optional(),
1416
- items: z.array(CustomerOrderLineItemSchema),
1417
- payments: z.array(CustomerOrderPaymentSchema),
1418
- statusTimeline: z.array(CustomerOrderStatusTimelineSchema)
1419
- });
1420
-
1421
- // src/services/customer-order.service.ts
1422
- var ORDERS_PATH = "customer/orders";
1423
- async function getCustomerOrders(api, options = {}) {
1424
- return api.get(ORDERS_PATH, CustomerOrderListSchema, {
1425
- headers: options.headers,
1426
- signal: options.signal
1427
- });
1428
- }
1429
- async function getCustomerOrder(api, orderId, options = {}) {
1430
- const id = orderId.trim();
1431
- if (!id) throw new Error("orderId requerido");
1432
- return api.get(
1433
- `${ORDERS_PATH}/${encodeURIComponent(id)}`,
1434
- CustomerOrderDetailSchema,
1435
- {
1436
- headers: options.headers,
1437
- signal: options.signal
1438
- }
1439
- );
1440
- }
1441
-
1
+ import { ApiError, createApi } from "./api.js";
2
+ import { executeGraphQL } from "./libs/graphql-_6Y8lR_Q.js";
3
+ import { catalogLinkKey } from "./libs/catalog-link-key-B7l5KZsF.js";
4
+ import { catalogLinkCandidates, readCatalogLink } from "./models/catalog-links-BzJeyBy4.js";
5
+ import { getLinks } from "./services/catalog-link.service-BQ2d-EPX.js";
6
+ import { getLayout } from "./services/layout.service-DmbeMOkK.js";
7
+ import { ProductsParamsSchema } from "./models/products.js";
8
+ import { BoundedReadCache } from "./libs/bounded-read-cache-Abmb5VnJ.js";
9
+ import { completeCustomerRegistration, getCustomerRegistration } from "./services/customer-registration.service-CxcWD2hf.js";
10
+ import { createCustomerSession, deleteCustomerSession, getCustomerSession, upsertCustomerAuthConfiguration } from "./services/customer-session.service-4YgfbWRB.js";
11
+ import { authenticateOrderPayment, getOrderStatus, startOrderPayment, uploadOrderPaymentReceipt } from "./services/order-status.service-MC9hVpP-.js";
12
+ import { checkoutOrderDraft, getOrderDraft } from "./services/order-draft.service-B0VcmWhn.js";
13
+ import { createComplaintBookEntry, getComplaintBook } from "./services/complaint-book.service-DXiVyKdD.js";
14
+ import { StorefrontSettingsSchema } from "./models/settings.js";
15
+ import { getProductBySlug, getProducts, getRelatedProducts } from "./services/product.service-B05Qmbuh.js";
16
+ import { autocompleteProducts } from "./services/search.service-DSBMhaSY.js";
17
+ import { createCustomerProductReview, createProductReview, listProductReviews, listStoreReviews } from "./services/review.service-De1YkhFp.js";
18
+ import { addCartItem, createCart, getCart, removeCartItem, updateCartItemQuantity } from "./services/cart.service-yMCz9oQP.js";
19
+ import { getCollectionBySlug, getCollections } from "./services/collection.service-C4QETpuI.js";
20
+ import { getPageBySlug } from "./services/page.service-CWhWCjMQ.js";
21
+ import { getCategoryBySlug } from "./services/category.service-8tieYX2r.js";
22
+ import { getSitemap, resolveUrl } from "./services/url.service-CLW0Tc7S.js";
23
+ import { getArticleBySlug, listArticles } from "./services/article.service-DBsOvflH.js";
24
+ import { addCartPromotionCode, checkoutCart, getCartCheckout, getShippingOptions, patchCartAddresses, patchCartBuyer, putCartPaymentMethod, putCartShippingMethod, removeCartPromotionCode, uploadPaymentReceipt } from "./services/checkout.service-CC-3tm2y.js";
25
+ import { getCountries, getDepartments, getDistricts, getProvinces } from "./services/geo.service-C32R7N8W.js";
26
+ import { createCustomerAddress, deleteCustomerAddress, getCustomerAddresses, updateCustomerAddress } from "./services/customer-address.service-xEThx7cQ.js";
27
+ import { getCustomerMe, patchCustomer } from "./services/customer.service-BoU6l2-R.js";
28
+ import { getCustomerOrder, getCustomerOrders, requestCustomerOrderCancellation, requestCustomerOrderReturn } from "./services/customer-order.service-qHoRBuyX.js";
29
+ import { getSellerBySlug, getSellers } from "./services/seller.service-DUptDTv4.js";
30
+ import { getPaymentMethods } from "./services/payment-method.service-CjKbAsOh.js";
1442
31
  // src/client.ts
1443
- var DEFAULT_SETTINGS_CACHE_TTL_MS = 3e4;
32
+ const DEFAULT_SETTINGS_CACHE_TTL_MS = 3e4;
33
+ const PRODUCT_READ_CACHE_TTL_MS = 3e4;
34
+ const COLLECTION_READ_CACHE_TTL_MS = 6e4;
35
+ const CATEGORY_READ_CACHE_TTL_MS = 3e4;
36
+ const URL_READ_CACHE_TTL_MS = 3e4;
37
+ /**
38
+ * Crea el cliente storefront de bajo nivel (requiere domain).
39
+ * En apps Ecomiq usa `createClient()` de `@ecomiq/storefront`, que toma el domain del config.
40
+ *
41
+ * ```ts
42
+ * const api = createClient({ domain: 'marketplace' })
43
+ * const collections = await api.getCollections()
44
+ * ```
45
+ */
1444
46
  function createClient(options) {
1445
- const {
1446
- domain,
1447
- settingsCacheTtlMs = DEFAULT_SETTINGS_CACHE_TTL_MS,
1448
- ...apiOptions
1449
- } = options;
1450
- if (!domain?.trim()) {
1451
- throw new Error("createClient requiere `domain` (config.domain de ecomiq.config.js)");
1452
- }
1453
- if (!Number.isFinite(settingsCacheTtlMs) || settingsCacheTtlMs < 0) {
1454
- throw new Error("settingsCacheTtlMs debe ser un n\xFAmero mayor o igual a 0");
1455
- }
1456
- const api = createApi(apiOptions);
1457
- const apiClient = async () => {
1458
- const storeId = await getStoreId();
1459
- return createApi({
1460
- ...apiOptions,
1461
- headers: {
1462
- ...apiOptions.headers,
1463
- "x-Store-Id": storeId
1464
- }
1465
- });
1466
- };
1467
- let cache = null;
1468
- let inflight = null;
1469
- function clearCache() {
1470
- cache = null;
1471
- inflight = null;
1472
- }
1473
- async function getSettings() {
1474
- const now = Date.now();
1475
- if (cache && cache.expiresAt > now) return cache.data;
1476
- if (inflight) return inflight;
1477
- const previous = cache?.data;
1478
- inflight = api.get("settings", StorefrontSettingsSchema, {
1479
- headers: { "x-Store-Domain": domain }
1480
- }).then((data) => {
1481
- cache = { data, expiresAt: Date.now() + settingsCacheTtlMs };
1482
- return data;
1483
- }).catch((error) => {
1484
- if (previous) return previous;
1485
- throw error;
1486
- }).finally(() => {
1487
- inflight = null;
1488
- });
1489
- return inflight;
1490
- }
1491
- async function getStoreId() {
1492
- const settings = await getSettings();
1493
- return settings.store.id;
1494
- }
1495
- async function getCollections2() {
1496
- const client = await apiClient();
1497
- return getCollections(client);
1498
- }
1499
- async function getCollectionBySlug2(collectionSlug) {
1500
- const client = await apiClient();
1501
- return getCollectionBySlug(client, collectionSlug);
1502
- }
1503
- async function getPageBySlug2(pageSlug) {
1504
- const client = await apiClient();
1505
- return getPageBySlug(client, pageSlug);
1506
- }
1507
- async function getProducts2(params = {}) {
1508
- const client = await apiClient();
1509
- return getProducts(client, params);
1510
- }
1511
- async function getProductBySlug2(productSlug, params = {}) {
1512
- const client = await apiClient();
1513
- return getProductBySlug(client, productSlug, params);
1514
- }
1515
- async function getRelatedProducts2(params) {
1516
- const client = await apiClient();
1517
- return getRelatedProducts(client, params);
1518
- }
1519
- async function autocompleteProducts2(params) {
1520
- const client = await apiClient();
1521
- return autocompleteProducts(client, params);
1522
- }
1523
- async function listProductReviews2(params) {
1524
- const client = await apiClient();
1525
- return listProductReviews(client, params);
1526
- }
1527
- async function createProductReview2(params) {
1528
- const client = await apiClient();
1529
- return createProductReview(client, params);
1530
- }
1531
- async function createCart2(params) {
1532
- const client = await apiClient();
1533
- return createCart(client, params);
1534
- }
1535
- async function getCart2(params) {
1536
- const client = await apiClient();
1537
- return getCart(client, params);
1538
- }
1539
- async function addCartItem2(params) {
1540
- const client = await apiClient();
1541
- return addCartItem(client, params);
1542
- }
1543
- async function updateCartItemQuantity2(params) {
1544
- const client = await apiClient();
1545
- return updateCartItemQuantity(client, params);
1546
- }
1547
- async function removeCartItem2(params) {
1548
- const client = await apiClient();
1549
- return removeCartItem(client, params);
1550
- }
1551
- async function getCartCheckout2(params) {
1552
- const client = await apiClient();
1553
- return getCartCheckout(client, params);
1554
- }
1555
- async function getShippingOptions2(params) {
1556
- const client = await apiClient();
1557
- return getShippingOptions(client, params);
1558
- }
1559
- async function putCartShippingMethod2(params) {
1560
- const client = await apiClient();
1561
- return putCartShippingMethod(client, params);
1562
- }
1563
- async function patchCartBuyer2(params) {
1564
- const client = await apiClient();
1565
- return patchCartBuyer(client, params);
1566
- }
1567
- async function patchCartAddresses2(params) {
1568
- const client = await apiClient();
1569
- return patchCartAddresses(client, params);
1570
- }
1571
- async function checkoutCart2(params) {
1572
- const client = await apiClient();
1573
- return checkoutCart(client, params);
1574
- }
1575
- async function uploadPaymentReceipt2(params) {
1576
- const client = await apiClient();
1577
- return uploadPaymentReceipt(client, params);
1578
- }
1579
- async function addCartPromotionCode2(params) {
1580
- const client = await apiClient();
1581
- return addCartPromotionCode(client, params);
1582
- }
1583
- async function removeCartPromotionCode2(params) {
1584
- const client = await apiClient();
1585
- return removeCartPromotionCode(client, params);
1586
- }
1587
- async function getCountries2() {
1588
- return getCountries(api);
1589
- }
1590
- async function getDepartments2(params) {
1591
- return getDepartments(api, params);
1592
- }
1593
- async function getProvinces2(params) {
1594
- return getProvinces(api, params);
1595
- }
1596
- async function getDistricts2(params) {
1597
- return getDistricts(api, params);
1598
- }
1599
- async function getCustomerAddresses2(options2 = {}) {
1600
- const client = await apiClient();
1601
- return getCustomerAddresses(client, options2);
1602
- }
1603
- async function createCustomerAddress2(data, options2 = {}) {
1604
- const client = await apiClient();
1605
- return createCustomerAddress(client, data, options2);
1606
- }
1607
- async function updateCustomerAddress2(addressId, data, options2 = {}) {
1608
- const client = await apiClient();
1609
- return updateCustomerAddress(client, addressId, data, options2);
1610
- }
1611
- async function deleteCustomerAddress2(addressId, options2 = {}) {
1612
- const client = await apiClient();
1613
- return deleteCustomerAddress(client, addressId, options2);
1614
- }
1615
- async function getCustomerMe2(options2 = {}) {
1616
- const client = await apiClient();
1617
- return getCustomerMe(client, options2);
1618
- }
1619
- async function patchCustomer2(data, options2 = {}) {
1620
- const client = await apiClient();
1621
- return patchCustomer(client, data, options2);
1622
- }
1623
- async function getCustomerOrders2(options2 = {}) {
1624
- const client = await apiClient();
1625
- return getCustomerOrders(client, options2);
1626
- }
1627
- async function getCustomerOrder2(orderId, options2 = {}) {
1628
- const client = await apiClient();
1629
- return getCustomerOrder(client, orderId, options2);
1630
- }
1631
- return {
1632
- ...api,
1633
- getSettings,
1634
- getStoreId,
1635
- getCollections: getCollections2,
1636
- getCollectionBySlug: getCollectionBySlug2,
1637
- getPageBySlug: getPageBySlug2,
1638
- clearCache,
1639
- getProducts: getProducts2,
1640
- getProductBySlug: getProductBySlug2,
1641
- getRelatedProducts: getRelatedProducts2,
1642
- autocompleteProducts: autocompleteProducts2,
1643
- listProductReviews: listProductReviews2,
1644
- createProductReview: createProductReview2,
1645
- createCart: createCart2,
1646
- getCart: getCart2,
1647
- addCartItem: addCartItem2,
1648
- updateCartItemQuantity: updateCartItemQuantity2,
1649
- removeCartItem: removeCartItem2,
1650
- getCartCheckout: getCartCheckout2,
1651
- getShippingOptions: getShippingOptions2,
1652
- putCartShippingMethod: putCartShippingMethod2,
1653
- patchCartBuyer: patchCartBuyer2,
1654
- patchCartAddresses: patchCartAddresses2,
1655
- checkoutCart: checkoutCart2,
1656
- uploadPaymentReceipt: uploadPaymentReceipt2,
1657
- addCartPromotionCode: addCartPromotionCode2,
1658
- removeCartPromotionCode: removeCartPromotionCode2,
1659
- getCountries: getCountries2,
1660
- getDepartments: getDepartments2,
1661
- getProvinces: getProvinces2,
1662
- getDistricts: getDistricts2,
1663
- getCustomerAddresses: getCustomerAddresses2,
1664
- createCustomerAddress: createCustomerAddress2,
1665
- updateCustomerAddress: updateCustomerAddress2,
1666
- deleteCustomerAddress: deleteCustomerAddress2,
1667
- getCustomerMe: getCustomerMe2,
1668
- patchCustomer: patchCustomer2,
1669
- getCustomerOrders: getCustomerOrders2,
1670
- getCustomerOrder: getCustomerOrder2
1671
- };
1672
- }
1673
- var createStorefrontClient = createClient;
1674
-
1675
- export { createClient, createStorefrontClient };
1676
- //# sourceMappingURL=client.js.map
1677
- //# sourceMappingURL=client.js.map
47
+ const { domain, storeId, settingsCacheTtlMs = DEFAULT_SETTINGS_CACHE_TTL_MS, ...apiOptions } = options;
48
+ if (!domain?.trim()) throw new Error("createClient requiere `domain` (config.domain de ecomiq.config.js)");
49
+ if (storeId !== void 0 && !storeId.trim()) throw new Error("storeId debe ser un ID no vacío");
50
+ if (!Number.isFinite(settingsCacheTtlMs) || settingsCacheTtlMs < 0) throw new Error("settingsCacheTtlMs debe ser un número mayor o igual a 0");
51
+ const api = createApi(apiOptions);
52
+ const graphQLApi = createApi({
53
+ ...apiOptions,
54
+ version: ""
55
+ });
56
+ function graphql(document, dataSchema, variables, requestOptions = {}) {
57
+ return executeGraphQL(graphQLApi, domain, document, dataSchema, variables, requestOptions);
58
+ }
59
+ const apiClient = async () => {
60
+ const storeId = await getStoreId();
61
+ return createApi({
62
+ ...apiOptions,
63
+ headers: {
64
+ ...apiOptions.headers,
65
+ "x-Store-Id": storeId
66
+ }
67
+ });
68
+ };
69
+ let cache = null;
70
+ let settingsGeneration = 0;
71
+ let layoutRead = null;
72
+ const productsCache = new BoundedReadCache(32);
73
+ const productCache = new BoundedReadCache(100);
74
+ const collectionsCache = new BoundedReadCache(1);
75
+ const collectionCache = new BoundedReadCache(50);
76
+ const categoryCache = new BoundedReadCache(50);
77
+ const urlCache = new BoundedReadCache(200);
78
+ const linksCache = new BoundedReadCache(32);
79
+ const cacheDomain = domain.trim().toLowerCase();
80
+ function clearCache() {
81
+ settingsGeneration += 1;
82
+ cache = null;
83
+ layoutRead = null;
84
+ productsCache.clear();
85
+ productCache.clear();
86
+ collectionsCache.clear();
87
+ collectionCache.clear();
88
+ categoryCache.clear();
89
+ urlCache.clear();
90
+ linksCache.clear();
91
+ }
92
+ async function getSettings() {
93
+ if (layoutRead && layoutRead.expiresAt > Date.now()) return (await layoutRead.data).settings;
94
+ return loadSettings();
95
+ }
96
+ async function loadSettings({ writeCache = true } = {}) {
97
+ const generation = settingsGeneration;
98
+ const now = Date.now();
99
+ if (cache && cache.expiresAt > now) return cache.data;
100
+ const previous = cache?.data;
101
+ return api.get("settings", StorefrontSettingsSchema, { headers: { "x-Store-Domain": domain } }).catch((error) => {
102
+ if (previous && error instanceof ApiError && (error.status === 0 || error.status === 429 || error.status >= 500)) return previous;
103
+ throw error;
104
+ }).then((data) => {
105
+ if (storeId !== void 0 && data.store.id !== storeId) throw new Error("El ID de tienda del Worker no coincide con el dominio publicado");
106
+ if (writeCache && generation === settingsGeneration) cache = {
107
+ data,
108
+ expiresAt: Date.now() + settingsCacheTtlMs
109
+ };
110
+ return data;
111
+ });
112
+ }
113
+ function getLayout$1(links) {
114
+ const key = JSON.stringify(links);
115
+ if (layoutRead?.key === key && layoutRead.expiresAt > Date.now()) return layoutRead.data;
116
+ const read = getLayout({
117
+ graphql,
118
+ links
119
+ }).catch(async (error) => {
120
+ if (error instanceof ApiError && (error.status === 401 || error.status === 403)) return {
121
+ settings: await loadSettings({ writeCache: false }),
122
+ collections: [],
123
+ links: links.map(readCatalogLink)
124
+ };
125
+ throw error;
126
+ }).then((result) => {
127
+ if (storeId !== void 0 && result.settings.store.id !== storeId) throw new Error("El ID de tienda del Worker no coincide con el dominio publicado");
128
+ if (layoutRead?.data === read) {
129
+ layoutRead.expiresAt = Date.now() + Math.min(URL_READ_CACHE_TTL_MS, settingsCacheTtlMs);
130
+ cache = {
131
+ data: result.settings,
132
+ expiresAt: Date.now() + settingsCacheTtlMs
133
+ };
134
+ }
135
+ return result;
136
+ });
137
+ layoutRead = {
138
+ key,
139
+ expiresAt: Infinity,
140
+ data: read
141
+ };
142
+ read.catch(() => {
143
+ if (layoutRead?.data === read) layoutRead = null;
144
+ });
145
+ return read;
146
+ }
147
+ async function getStoreId() {
148
+ if (storeId !== void 0) return storeId;
149
+ return (await getSettings()).store.id;
150
+ }
151
+ async function getCollections$1() {
152
+ if (layoutRead && layoutRead.expiresAt > Date.now()) return (await layoutRead.data).collections;
153
+ return collectionsCache.read(cacheDomain, COLLECTION_READ_CACHE_TTL_MS, async () => {
154
+ const client = await apiClient();
155
+ return getCollections(client);
156
+ });
157
+ }
158
+ async function getPaymentMethods$1() {
159
+ const client = await apiClient();
160
+ return getPaymentMethods(client);
161
+ }
162
+ async function getCollectionBySlug$1(collectionSlug) {
163
+ return collectionCache.read(`${cacheDomain}\u0000${collectionSlug}`, COLLECTION_READ_CACHE_TTL_MS, async () => {
164
+ const client = await apiClient();
165
+ return getCollectionBySlug(client, collectionSlug);
166
+ });
167
+ }
168
+ async function getPageBySlug$1(pageSlug) {
169
+ const client = await apiClient();
170
+ return getPageBySlug(client, pageSlug);
171
+ }
172
+ async function getCategoryBySlug$1(categorySlug) {
173
+ return categoryCache.read(`${cacheDomain}\u0000${categorySlug}`, CATEGORY_READ_CACHE_TTL_MS, async () => {
174
+ const client = await apiClient();
175
+ return getCategoryBySlug(client, categorySlug);
176
+ });
177
+ }
178
+ async function resolveUrl$1(path, options = {}) {
179
+ if (options.previewKey) {
180
+ const client = await apiClient();
181
+ return resolveUrl(client, path, options);
182
+ }
183
+ return urlCache.read(`${cacheDomain}\u0000${path}`, URL_READ_CACHE_TTL_MS, async () => {
184
+ const client = await apiClient();
185
+ return resolveUrl(client, path);
186
+ });
187
+ }
188
+ async function getSitemap$1(page) {
189
+ const client = await apiClient();
190
+ return getSitemap(client, page);
191
+ }
192
+ async function getLinks$1(links) {
193
+ const input = links.map(readCatalogLink);
194
+ const candidates = catalogLinkCandidates(input);
195
+ if (candidates.length === 0) return input;
196
+ const resolved = /* @__PURE__ */ new Map();
197
+ const batches = [];
198
+ for (let offset = 0; offset < candidates.length; offset += 100) {
199
+ const batch = candidates.slice(offset, offset + 100);
200
+ const key = `${cacheDomain}\u0000${JSON.stringify(batch.map(catalogLinkKey))}`;
201
+ batches.push(linksCache.read(key, URL_READ_CACHE_TTL_MS, async () => {
202
+ const client = await apiClient();
203
+ return getLinks(client, batch);
204
+ }).then((result) => {
205
+ batch.forEach((original, index) => resolved.set(catalogLinkKey(original), result[index] ?? original));
206
+ }));
207
+ }
208
+ await Promise.all(batches);
209
+ return input.map((link) => resolved.get(catalogLinkKey(link)) ?? link);
210
+ }
211
+ async function listArticles$1(params = {}) {
212
+ const client = await apiClient();
213
+ return listArticles(client, params);
214
+ }
215
+ async function getArticleBySlug$1(articleSlug) {
216
+ const client = await apiClient();
217
+ return getArticleBySlug(client, articleSlug);
218
+ }
219
+ async function getSellers$1() {
220
+ const client = await apiClient();
221
+ return getSellers(client);
222
+ }
223
+ async function getSellerBySlug$1(sellerSlug) {
224
+ const client = await apiClient();
225
+ return getSellerBySlug(client, sellerSlug);
226
+ }
227
+ async function getProducts$1(params = {}) {
228
+ const input = ProductsParamsSchema.parse(params);
229
+ return productsCache.read(`${cacheDomain}\u0000${JSON.stringify(input)}`, PRODUCT_READ_CACHE_TTL_MS, async () => {
230
+ const client = await apiClient();
231
+ return getProducts(client, input);
232
+ });
233
+ }
234
+ async function getProductBySlug$1(productSlug, options = {}) {
235
+ if (options.previewKey) {
236
+ const client = await apiClient();
237
+ return getProductBySlug(client, productSlug, options);
238
+ }
239
+ return productCache.read(`${cacheDomain}\u0000${productSlug}`, PRODUCT_READ_CACHE_TTL_MS, async () => {
240
+ const client = await apiClient();
241
+ return getProductBySlug(client, productSlug);
242
+ });
243
+ }
244
+ async function getRelatedProducts$1(params) {
245
+ const client = await apiClient();
246
+ return getRelatedProducts(client, params);
247
+ }
248
+ async function autocompleteProducts$1(params) {
249
+ const client = await apiClient();
250
+ return autocompleteProducts(client, params);
251
+ }
252
+ async function listProductReviews$1(params) {
253
+ const client = await apiClient();
254
+ return listProductReviews(client, params);
255
+ }
256
+ async function listStoreReviews$1(params) {
257
+ const client = await apiClient();
258
+ return listStoreReviews(client, params);
259
+ }
260
+ async function createProductReview$1(params) {
261
+ const client = await apiClient();
262
+ return createProductReview(client, params);
263
+ }
264
+ async function createCustomerProductReview$1(params, options) {
265
+ const client = await apiClient();
266
+ return createCustomerProductReview(client, params, options);
267
+ }
268
+ async function createCart$1(params) {
269
+ const client = await apiClient();
270
+ return createCart(client, params);
271
+ }
272
+ async function getCart$1(params) {
273
+ const client = await apiClient();
274
+ return getCart(client, params);
275
+ }
276
+ async function addCartItem$1(params) {
277
+ const client = await apiClient();
278
+ return addCartItem(client, params);
279
+ }
280
+ async function updateCartItemQuantity$1(params) {
281
+ const client = await apiClient();
282
+ return updateCartItemQuantity(client, params);
283
+ }
284
+ async function removeCartItem$1(params) {
285
+ const client = await apiClient();
286
+ return removeCartItem(client, params);
287
+ }
288
+ async function getCartCheckout$1(params) {
289
+ const client = await apiClient();
290
+ return getCartCheckout(client, params);
291
+ }
292
+ async function getShippingOptions$1(params) {
293
+ const client = await apiClient();
294
+ return getShippingOptions(client, params);
295
+ }
296
+ async function putCartShippingMethod$1(params) {
297
+ const client = await apiClient();
298
+ return putCartShippingMethod(client, params);
299
+ }
300
+ async function putCartPaymentMethod$1(params) {
301
+ const client = await apiClient();
302
+ return putCartPaymentMethod(client, params);
303
+ }
304
+ async function patchCartBuyer$1(params) {
305
+ const client = await apiClient();
306
+ return patchCartBuyer(client, params);
307
+ }
308
+ async function patchCartAddresses$1(params) {
309
+ const client = await apiClient();
310
+ return patchCartAddresses(client, params);
311
+ }
312
+ async function checkoutCart$1(params, options = {}) {
313
+ const client = await apiClient();
314
+ return checkoutCart(client, params, options);
315
+ }
316
+ async function uploadPaymentReceipt$1(params) {
317
+ const client = await apiClient();
318
+ return uploadPaymentReceipt(client, params);
319
+ }
320
+ async function addCartPromotionCode$1(params) {
321
+ const client = await apiClient();
322
+ return addCartPromotionCode(client, params);
323
+ }
324
+ async function removeCartPromotionCode$1(params) {
325
+ const client = await apiClient();
326
+ return removeCartPromotionCode(client, params);
327
+ }
328
+ async function getCountries$1() {
329
+ return getCountries(api);
330
+ }
331
+ async function getDepartments$1(params) {
332
+ return getDepartments(api, params);
333
+ }
334
+ async function getProvinces$1(params) {
335
+ return getProvinces(api, params);
336
+ }
337
+ async function getDistricts$1(params) {
338
+ return getDistricts(api, params);
339
+ }
340
+ async function getCustomerAddresses$1(options = {}) {
341
+ const client = await apiClient();
342
+ return getCustomerAddresses(client, options);
343
+ }
344
+ async function upsertCustomerAuthConfiguration$1(origin) {
345
+ return upsertCustomerAuthConfiguration(await apiClient(), origin);
346
+ }
347
+ async function createCustomerSession$1(input) {
348
+ return createCustomerSession(await apiClient(), input);
349
+ }
350
+ async function getCustomerSession$1(options) {
351
+ return getCustomerSession(await apiClient(), options);
352
+ }
353
+ async function deleteCustomerSession$1(options) {
354
+ return deleteCustomerSession(await apiClient(), options);
355
+ }
356
+ async function createCustomerAddress$1(data, options = {}) {
357
+ const client = await apiClient();
358
+ return createCustomerAddress(client, data, options);
359
+ }
360
+ async function updateCustomerAddress$1(addressId, data, options = {}) {
361
+ const client = await apiClient();
362
+ return updateCustomerAddress(client, addressId, data, options);
363
+ }
364
+ async function deleteCustomerAddress$1(addressId, options = {}) {
365
+ const client = await apiClient();
366
+ return deleteCustomerAddress(client, addressId, options);
367
+ }
368
+ async function getCustomerRegistration$1(options) {
369
+ return getCustomerRegistration(await apiClient(), options);
370
+ }
371
+ async function completeCustomerRegistration$1(input, options) {
372
+ return completeCustomerRegistration(await apiClient(), input, options);
373
+ }
374
+ async function getCustomerMe$1(options = {}) {
375
+ const client = await apiClient();
376
+ return getCustomerMe(client, options);
377
+ }
378
+ async function patchCustomer$1(data, options = {}) {
379
+ const client = await apiClient();
380
+ return patchCustomer(client, data, options);
381
+ }
382
+ async function getCustomerOrders$1(options = {}) {
383
+ const client = await apiClient();
384
+ return getCustomerOrders(client, options);
385
+ }
386
+ async function getCustomerOrder$1(orderId, options = {}) {
387
+ const client = await apiClient();
388
+ return getCustomerOrder(client, orderId, options);
389
+ }
390
+ async function requestCustomerOrderReturn$1(orderId, input, options = {}) {
391
+ const client = await apiClient();
392
+ return requestCustomerOrderReturn(client, orderId, input, options);
393
+ }
394
+ async function requestCustomerOrderCancellation$1(orderId, input, options = {}) {
395
+ const client = await apiClient();
396
+ return requestCustomerOrderCancellation(client, orderId, input, options);
397
+ }
398
+ async function getOrderStatus$1(token) {
399
+ const client = await apiClient();
400
+ return getOrderStatus(client, token);
401
+ }
402
+ async function authenticateOrderPayment$1(token, transactionId, input) {
403
+ const client = await apiClient();
404
+ return authenticateOrderPayment(client, token, transactionId, input);
405
+ }
406
+ async function startOrderPayment$1(token, input) {
407
+ const client = await apiClient();
408
+ return startOrderPayment(client, token, input);
409
+ }
410
+ async function getOrderDraft$1(token) {
411
+ const client = await apiClient();
412
+ return getOrderDraft(client, token);
413
+ }
414
+ async function uploadOrderPaymentReceipt$1(token, input) {
415
+ const client = await apiClient();
416
+ return uploadOrderPaymentReceipt(client, token, input);
417
+ }
418
+ async function checkoutOrderDraft$1(token) {
419
+ const client = await apiClient();
420
+ return checkoutOrderDraft(client, token);
421
+ }
422
+ async function getComplaintBook$1() {
423
+ const client = await apiClient();
424
+ return getComplaintBook(client);
425
+ }
426
+ async function createComplaintBookEntry$1(input, files, captchaToken) {
427
+ const client = await apiClient();
428
+ return createComplaintBookEntry(client, input, files, captchaToken);
429
+ }
430
+ return {
431
+ ...api,
432
+ graphql,
433
+ getSettings,
434
+ getLayout: getLayout$1,
435
+ getStoreId,
436
+ getCollections: getCollections$1,
437
+ getPaymentMethods: getPaymentMethods$1,
438
+ getCollectionBySlug: getCollectionBySlug$1,
439
+ getPageBySlug: getPageBySlug$1,
440
+ getCategoryBySlug: getCategoryBySlug$1,
441
+ resolveUrl: resolveUrl$1,
442
+ getLinks: getLinks$1,
443
+ getSitemap: getSitemap$1,
444
+ listArticles: listArticles$1,
445
+ getArticleBySlug: getArticleBySlug$1,
446
+ clearCache,
447
+ getSellers: getSellers$1,
448
+ getSellerBySlug: getSellerBySlug$1,
449
+ getProducts: getProducts$1,
450
+ getProductBySlug: getProductBySlug$1,
451
+ getRelatedProducts: getRelatedProducts$1,
452
+ autocompleteProducts: autocompleteProducts$1,
453
+ listProductReviews: listProductReviews$1,
454
+ listStoreReviews: listStoreReviews$1,
455
+ createProductReview: createProductReview$1,
456
+ createCustomerProductReview: createCustomerProductReview$1,
457
+ createCart: createCart$1,
458
+ getCart: getCart$1,
459
+ addCartItem: addCartItem$1,
460
+ updateCartItemQuantity: updateCartItemQuantity$1,
461
+ removeCartItem: removeCartItem$1,
462
+ getCartCheckout: getCartCheckout$1,
463
+ getShippingOptions: getShippingOptions$1,
464
+ putCartShippingMethod: putCartShippingMethod$1,
465
+ putCartPaymentMethod: putCartPaymentMethod$1,
466
+ patchCartBuyer: patchCartBuyer$1,
467
+ patchCartAddresses: patchCartAddresses$1,
468
+ checkoutCart: checkoutCart$1,
469
+ uploadPaymentReceipt: uploadPaymentReceipt$1,
470
+ addCartPromotionCode: addCartPromotionCode$1,
471
+ removeCartPromotionCode: removeCartPromotionCode$1,
472
+ getCountries: getCountries$1,
473
+ getDepartments: getDepartments$1,
474
+ getProvinces: getProvinces$1,
475
+ getDistricts: getDistricts$1,
476
+ getCustomerAddresses: getCustomerAddresses$1,
477
+ upsertCustomerAuthConfiguration: upsertCustomerAuthConfiguration$1,
478
+ createCustomerSession: createCustomerSession$1,
479
+ getCustomerSession: getCustomerSession$1,
480
+ getCustomerRegistration: getCustomerRegistration$1,
481
+ completeCustomerRegistration: completeCustomerRegistration$1,
482
+ deleteCustomerSession: deleteCustomerSession$1,
483
+ createCustomerAddress: createCustomerAddress$1,
484
+ updateCustomerAddress: updateCustomerAddress$1,
485
+ deleteCustomerAddress: deleteCustomerAddress$1,
486
+ getCustomerMe: getCustomerMe$1,
487
+ patchCustomer: patchCustomer$1,
488
+ getCustomerOrders: getCustomerOrders$1,
489
+ getCustomerOrder: getCustomerOrder$1,
490
+ requestCustomerOrderReturn: requestCustomerOrderReturn$1,
491
+ requestCustomerOrderCancellation: requestCustomerOrderCancellation$1,
492
+ getOrderStatus: getOrderStatus$1,
493
+ startOrderPayment: startOrderPayment$1,
494
+ authenticateOrderPayment: authenticateOrderPayment$1,
495
+ uploadOrderPaymentReceipt: uploadOrderPaymentReceipt$1,
496
+ getOrderDraft: getOrderDraft$1,
497
+ checkoutOrderDraft: checkoutOrderDraft$1,
498
+ getComplaintBook: getComplaintBook$1,
499
+ createComplaintBookEntry: createComplaintBookEntry$1
500
+ };
501
+ }
502
+ export { createClient };