shop-client 3.8.2 → 3.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +158 -1
  3. package/dist/ai/enrich.d.ts +93 -0
  4. package/dist/ai/enrich.js +25 -0
  5. package/dist/checkout.js +5 -114
  6. package/dist/{chunk-2KBOKOAD.mjs → chunk-2MF53V33.js} +32 -13
  7. package/dist/{chunk-BWKBRM2Z.mjs → chunk-CN7L3BHG.js} +12 -1
  8. package/dist/chunk-CXUCPK6X.js +460 -0
  9. package/dist/{chunk-QCTICSBE.mjs → chunk-MOBWPEY4.js} +29 -7
  10. package/dist/chunk-ROH545KI.js +274 -0
  11. package/dist/{chunk-QL5OUZGP.mjs → chunk-RR6YTQWP.js} +0 -1
  12. package/dist/{chunk-O4BPIIQ6.mjs → chunk-V52MFQZE.js} +11 -281
  13. package/dist/{chunk-WTK5HUFI.mjs → chunk-VPPCOJC3.js} +13 -435
  14. package/dist/collections.d.ts +2 -1
  15. package/dist/collections.js +7 -539
  16. package/dist/index.d.ts +28 -87
  17. package/dist/index.js +109 -2597
  18. package/dist/products.d.ts +2 -1
  19. package/dist/products.js +7 -1205
  20. package/dist/store.d.ts +53 -1
  21. package/dist/store.js +8 -697
  22. package/dist/{store-CJVUz2Yb.d.ts → types-luPg5O08.d.ts} +1 -208
  23. package/dist/utils/detect-country.d.ts +32 -0
  24. package/dist/utils/detect-country.js +6 -0
  25. package/dist/utils/func.d.ts +61 -0
  26. package/dist/utils/func.js +24 -0
  27. package/dist/utils/rate-limit.d.ts +5 -0
  28. package/dist/utils/rate-limit.js +7 -200
  29. package/package.json +21 -10
  30. package/dist/checkout.d.mts +0 -31
  31. package/dist/checkout.js.map +0 -1
  32. package/dist/checkout.mjs +0 -7
  33. package/dist/checkout.mjs.map +0 -1
  34. package/dist/chunk-2KBOKOAD.mjs.map +0 -1
  35. package/dist/chunk-BWKBRM2Z.mjs.map +0 -1
  36. package/dist/chunk-O4BPIIQ6.mjs.map +0 -1
  37. package/dist/chunk-QCTICSBE.mjs.map +0 -1
  38. package/dist/chunk-QL5OUZGP.mjs.map +0 -1
  39. package/dist/chunk-WTK5HUFI.mjs.map +0 -1
  40. package/dist/collections.d.mts +0 -64
  41. package/dist/collections.js.map +0 -1
  42. package/dist/collections.mjs +0 -9
  43. package/dist/collections.mjs.map +0 -1
  44. package/dist/index.d.mts +0 -233
  45. package/dist/index.js.map +0 -1
  46. package/dist/index.mjs +0 -702
  47. package/dist/index.mjs.map +0 -1
  48. package/dist/products.d.mts +0 -63
  49. package/dist/products.js.map +0 -1
  50. package/dist/products.mjs +0 -9
  51. package/dist/products.mjs.map +0 -1
  52. package/dist/store-CJVUz2Yb.d.mts +0 -608
  53. package/dist/store.d.mts +0 -1
  54. package/dist/store.js.map +0 -1
  55. package/dist/store.mjs +0 -9
  56. package/dist/store.mjs.map +0 -1
  57. package/dist/utils/rate-limit.d.mts +0 -25
  58. package/dist/utils/rate-limit.js.map +0 -1
  59. package/dist/utils/rate-limit.mjs +0 -11
  60. package/dist/utils/rate-limit.mjs.map +0 -1
@@ -0,0 +1,460 @@
1
+ import {
2
+ rateLimitedFetch
3
+ } from "./chunk-2MF53V33.js";
4
+ import {
5
+ formatPrice
6
+ } from "./chunk-CN7L3BHG.js";
7
+
8
+ // src/products.ts
9
+ import { filter, isNonNullish } from "remeda";
10
+ function createProductOperations(baseUrl, storeDomain, fetchProducts, productsDto, productDto, getStoreInfo, findProduct) {
11
+ const cacheExpiryMs = 5 * 60 * 1e3;
12
+ const findCache = /* @__PURE__ */ new Map();
13
+ const getCached = (key) => {
14
+ const entry = findCache.get(key);
15
+ if (!entry) return void 0;
16
+ if (Date.now() - entry.ts < cacheExpiryMs) return entry.value;
17
+ findCache.delete(key);
18
+ return void 0;
19
+ };
20
+ const setCached = (key, value) => {
21
+ findCache.set(key, { ts: Date.now(), value });
22
+ };
23
+ function applyCurrencyOverride(product, currency) {
24
+ var _a, _b, _c, _d, _e, _f;
25
+ const priceMin = (_b = (_a = product.priceMin) != null ? _a : product.price) != null ? _b : 0;
26
+ const priceMax = (_d = (_c = product.priceMax) != null ? _c : product.price) != null ? _d : 0;
27
+ const compareAtMin = (_f = (_e = product.compareAtPriceMin) != null ? _e : product.compareAtPrice) != null ? _f : 0;
28
+ return {
29
+ ...product,
30
+ currency,
31
+ localizedPricing: {
32
+ currency,
33
+ priceFormatted: formatPrice(priceMin, currency),
34
+ priceMinFormatted: formatPrice(priceMin, currency),
35
+ priceMaxFormatted: formatPrice(priceMax, currency),
36
+ compareAtPriceFormatted: formatPrice(compareAtMin, currency)
37
+ }
38
+ };
39
+ }
40
+ function maybeOverrideProductsCurrency(products, currency) {
41
+ if (!products || !currency) return products;
42
+ return products.map((p) => applyCurrencyOverride(p, currency));
43
+ }
44
+ const operations = {
45
+ /**
46
+ * Fetches all products from the store across all pages.
47
+ *
48
+ * @returns {Promise<Product[] | null>} Array of all products or null if error occurs
49
+ *
50
+ * @throws {Error} When there's a network error or API failure
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const shop = new ShopClient('https://exampleshop.com');
55
+ * const allProducts = await shop.products.all();
56
+ *
57
+ * console.log(`Found ${allProducts?.length} products`);
58
+ * allProducts?.forEach(product => {
59
+ * console.log(product.title, product.price);
60
+ * });
61
+ * ```
62
+ */
63
+ all: async (options) => {
64
+ const limit = 250;
65
+ const allProducts = [];
66
+ async function fetchAll() {
67
+ let currentPage = 1;
68
+ while (true) {
69
+ const products = await fetchProducts(currentPage, limit);
70
+ if (!products || products.length === 0 || products.length < limit) {
71
+ if (products && products.length > 0) {
72
+ allProducts.push(...products);
73
+ }
74
+ break;
75
+ }
76
+ allProducts.push(...products);
77
+ currentPage++;
78
+ }
79
+ return allProducts;
80
+ }
81
+ try {
82
+ const products = await fetchAll();
83
+ return maybeOverrideProductsCurrency(products, options == null ? void 0 : options.currency);
84
+ } catch (error) {
85
+ console.error("Failed to fetch all products:", storeDomain, error);
86
+ throw error;
87
+ }
88
+ },
89
+ /**
90
+ * Fetches products with pagination support.
91
+ *
92
+ * @param options - Pagination options
93
+ * @param options.page - Page number (default: 1)
94
+ * @param options.limit - Number of products per page (default: 250, max: 250)
95
+ *
96
+ * @returns {Promise<Product[] | null>} Array of products for the specified page or null if error occurs
97
+ *
98
+ * @throws {Error} When there's a network error or API failure
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const shop = new ShopClient('https://example.myshopify.com');
103
+ *
104
+ * // Get first page with default limit (250)
105
+ * const firstPage = await shop.products.paginated();
106
+ *
107
+ * // Get second page with custom limit
108
+ * const secondPage = await shop.products.paginated({ page: 2, limit: 50 });
109
+ * ```
110
+ */
111
+ paginated: async (options) => {
112
+ var _a, _b;
113
+ const page = (_a = options == null ? void 0 : options.page) != null ? _a : 1;
114
+ const limit = Math.min((_b = options == null ? void 0 : options.limit) != null ? _b : 250, 250);
115
+ const url = `${baseUrl}products.json?limit=${limit}&page=${page}`;
116
+ try {
117
+ const response = await rateLimitedFetch(url, {
118
+ rateLimitClass: "products:paginated"
119
+ });
120
+ if (!response.ok) {
121
+ console.error(
122
+ `HTTP error! status: ${response.status} for ${storeDomain} page ${page}`
123
+ );
124
+ throw new Error(`HTTP error! status: ${response.status}`);
125
+ }
126
+ const data = await response.json();
127
+ if (data.products.length === 0) {
128
+ return [];
129
+ }
130
+ const normalized = productsDto(data.products);
131
+ return maybeOverrideProductsCurrency(normalized, options == null ? void 0 : options.currency);
132
+ } catch (error) {
133
+ console.error(
134
+ `Error fetching products for ${storeDomain} page ${page} with limit ${limit}:`,
135
+ error
136
+ );
137
+ return null;
138
+ }
139
+ },
140
+ /**
141
+ * Finds a specific product by its handle.
142
+ *
143
+ * @param productHandle - The product handle (URL slug) to search for
144
+ *
145
+ * @returns {Promise<Product | null>} The product if found, null if not found
146
+ *
147
+ * @throws {Error} When the handle is invalid or there's a network error
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const shop = new ShopClient('https://exampleshop.com');
152
+ *
153
+ * // Find product by handle
154
+ * const product = await shop.products.find('awesome-t-shirt');
155
+ *
156
+ * if (product) {
157
+ * console.log(product.title, product.price);
158
+ * console.log('Available variants:', product.variants.length);
159
+ * }
160
+ *
161
+ * // Handle with query string
162
+ * const productWithVariant = await shop.products.find('t-shirt?variant=123');
163
+ * ```
164
+ */
165
+ find: async (productHandle, options) => {
166
+ var _a, _b;
167
+ if (!productHandle || typeof productHandle !== "string") {
168
+ throw new Error("Product handle is required and must be a string");
169
+ }
170
+ try {
171
+ let qs = null;
172
+ if (productHandle.includes("?")) {
173
+ const parts = productHandle.split("?");
174
+ const handlePart = (_a = parts[0]) != null ? _a : productHandle;
175
+ const qsPart = (_b = parts[1]) != null ? _b : null;
176
+ productHandle = handlePart;
177
+ qs = qsPart;
178
+ }
179
+ const sanitizedHandle = productHandle.trim().replace(/[^a-zA-Z0-9\-_]/g, "");
180
+ if (!sanitizedHandle) {
181
+ throw new Error("Invalid product handle format");
182
+ }
183
+ if (sanitizedHandle.length > 255) {
184
+ throw new Error("Product handle is too long");
185
+ }
186
+ const cached = getCached(sanitizedHandle);
187
+ if (typeof cached !== "undefined") {
188
+ return (options == null ? void 0 : options.currency) ? cached ? applyCurrencyOverride(cached, options.currency) : null : cached;
189
+ }
190
+ let finalHandle = sanitizedHandle;
191
+ try {
192
+ const htmlResp = await rateLimitedFetch(
193
+ `${baseUrl}products/${encodeURIComponent(sanitizedHandle)}`,
194
+ { rateLimitClass: "products:resolve" }
195
+ );
196
+ if (htmlResp.ok) {
197
+ const finalUrl = htmlResp.url;
198
+ if (finalUrl) {
199
+ const pathname = new URL(finalUrl).pathname.replace(/\/$/, "");
200
+ const parts = pathname.split("/").filter(Boolean);
201
+ const idx = parts.indexOf("products");
202
+ const maybeHandle = idx >= 0 ? parts[idx + 1] : void 0;
203
+ if (typeof maybeHandle === "string" && maybeHandle.length) {
204
+ finalHandle = maybeHandle;
205
+ }
206
+ }
207
+ }
208
+ } catch {
209
+ }
210
+ const url = `${baseUrl}products/${encodeURIComponent(finalHandle)}.js${qs ? `?${qs}` : ""}`;
211
+ const response = await rateLimitedFetch(url, {
212
+ rateLimitClass: "products:single"
213
+ });
214
+ if (!response.ok) {
215
+ if (response.status === 404) {
216
+ return null;
217
+ }
218
+ throw new Error(`HTTP error! status: ${response.status}`);
219
+ }
220
+ const product = await response.json();
221
+ const productData = productDto(product);
222
+ setCached(sanitizedHandle, productData);
223
+ if (finalHandle !== sanitizedHandle)
224
+ setCached(finalHandle, productData);
225
+ return (options == null ? void 0 : options.currency) ? applyCurrencyOverride(productData, options.currency) : productData;
226
+ } catch (error) {
227
+ if (error instanceof Error) {
228
+ console.error(
229
+ `Error fetching product ${productHandle}:`,
230
+ baseUrl,
231
+ error.message
232
+ );
233
+ }
234
+ throw error;
235
+ }
236
+ },
237
+ /**
238
+ * Enrich a product by generating merged markdown from body_html and product page.
239
+ * Adds `enriched_content` to the returned product.
240
+ */
241
+ enriched: async (productHandle, options) => {
242
+ if (!productHandle || typeof productHandle !== "string") {
243
+ throw new Error("Product handle is required and must be a string");
244
+ }
245
+ const apiKey = (options == null ? void 0 : options.apiKey) || process.env.OPENROUTER_API_KEY;
246
+ if (!apiKey) {
247
+ throw new Error(
248
+ "Missing OpenRouter API key. Pass options.apiKey or set OPENROUTER_API_KEY."
249
+ );
250
+ }
251
+ const baseProduct = await operations.find(productHandle);
252
+ if (!baseProduct) {
253
+ return null;
254
+ }
255
+ const handle = baseProduct.handle;
256
+ const { enrichProduct } = await import("./ai/enrich.js");
257
+ const enriched = await enrichProduct(storeDomain, handle, {
258
+ apiKey,
259
+ useGfm: options == null ? void 0 : options.useGfm,
260
+ inputType: options == null ? void 0 : options.inputType,
261
+ model: options == null ? void 0 : options.model,
262
+ outputFormat: options == null ? void 0 : options.outputFormat
263
+ });
264
+ return {
265
+ ...baseProduct,
266
+ enriched_content: enriched.mergedMarkdown
267
+ };
268
+ },
269
+ classify: async (productHandle, options) => {
270
+ if (!productHandle || typeof productHandle !== "string") {
271
+ throw new Error("Product handle is required and must be a string");
272
+ }
273
+ const apiKey = (options == null ? void 0 : options.apiKey) || process.env.OPENROUTER_API_KEY;
274
+ if (!apiKey) {
275
+ throw new Error(
276
+ "Missing OpenRouter API key. Pass options.apiKey or set OPENROUTER_API_KEY."
277
+ );
278
+ }
279
+ const enrichedProduct = await operations.enriched(productHandle, {
280
+ apiKey,
281
+ inputType: "html",
282
+ model: options == null ? void 0 : options.model,
283
+ outputFormat: "json"
284
+ });
285
+ if (!enrichedProduct || !enrichedProduct.enriched_content) return null;
286
+ let productContent = enrichedProduct.enriched_content;
287
+ try {
288
+ const obj = JSON.parse(enrichedProduct.enriched_content);
289
+ const lines = [];
290
+ if (obj.title && typeof obj.title === "string")
291
+ lines.push(`Title: ${obj.title}`);
292
+ if (obj.description && typeof obj.description === "string")
293
+ lines.push(`Description: ${obj.description}`);
294
+ if (Array.isArray(obj.materials) && obj.materials.length)
295
+ lines.push(`Materials: ${obj.materials.join(", ")}`);
296
+ if (Array.isArray(obj.care) && obj.care.length)
297
+ lines.push(`Care: ${obj.care.join(", ")}`);
298
+ if (obj.fit && typeof obj.fit === "string")
299
+ lines.push(`Fit: ${obj.fit}`);
300
+ if (obj.returnPolicy && typeof obj.returnPolicy === "string")
301
+ lines.push(`ReturnPolicy: ${obj.returnPolicy}`);
302
+ productContent = lines.join("\n");
303
+ } catch {
304
+ }
305
+ const { classifyProduct } = await import("./ai/enrich.js");
306
+ const classification = await classifyProduct(productContent, {
307
+ apiKey,
308
+ model: options == null ? void 0 : options.model
309
+ });
310
+ return classification;
311
+ },
312
+ generateSEOContent: async (productHandle, options) => {
313
+ if (!productHandle || typeof productHandle !== "string") {
314
+ throw new Error("Product handle is required and must be a string");
315
+ }
316
+ const apiKey = (options == null ? void 0 : options.apiKey) || process.env.OPENROUTER_API_KEY;
317
+ if (!apiKey) {
318
+ throw new Error(
319
+ "Missing OpenRouter API key. Pass options.apiKey or set OPENROUTER_API_KEY."
320
+ );
321
+ }
322
+ const baseProduct = await operations.find(productHandle);
323
+ if (!baseProduct) return null;
324
+ const payload = {
325
+ title: baseProduct.title,
326
+ description: baseProduct.bodyHtml || void 0,
327
+ vendor: baseProduct.vendor,
328
+ price: baseProduct.price,
329
+ tags: baseProduct.tags
330
+ };
331
+ const { generateSEOContent: generateSEOContentLLM } = await import("./ai/enrich.js");
332
+ const seo = await generateSEOContentLLM(payload, {
333
+ apiKey,
334
+ model: options == null ? void 0 : options.model
335
+ });
336
+ return seo;
337
+ },
338
+ /**
339
+ * Fetches products that are showcased/featured on the store's homepage.
340
+ *
341
+ * @returns {Promise<Product[]>} Array of showcased products found on the homepage
342
+ *
343
+ * @throws {Error} When there's a network error or API failure
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * const shop = new ShopClient('https://exampleshop.com');
348
+ * const showcasedProducts = await shop.products.showcased();
349
+ *
350
+ * console.log(`Found ${showcasedProducts.length} showcased products`);
351
+ * showcasedProducts.forEach(product => {
352
+ * console.log(`Featured: ${product.title} - ${product.price}`);
353
+ * });
354
+ * ```
355
+ */
356
+ showcased: async () => {
357
+ const storeInfo = await getStoreInfo();
358
+ const products = await Promise.all(
359
+ storeInfo.showcase.products.map(
360
+ (productHandle) => findProduct(productHandle)
361
+ )
362
+ );
363
+ return filter(products, isNonNullish);
364
+ },
365
+ /**
366
+ * Creates a filter map of variant options and their distinct values from all products.
367
+ *
368
+ * @returns {Promise<Record<string, string[]> | null>} Map of option names to their distinct values or null if error occurs
369
+ *
370
+ * @throws {Error} When there's a network error or API failure
371
+ *
372
+ * @example
373
+ * ```typescript
374
+ * const shop = new ShopClient('https://exampleshop.com');
375
+ * const filters = await shop.products.filter();
376
+ *
377
+ * console.log('Available filters:', filters);
378
+ * // Output: { "Size": ["S", "M", "L", "XL"], "Color": ["Red", "Blue", "Green"] }
379
+ *
380
+ * // Use filters for UI components
381
+ * Object.entries(filters || {}).forEach(([optionName, values]) => {
382
+ * console.log(`${optionName}: ${values.join(', ')}`);
383
+ * });
384
+ * ```
385
+ */
386
+ filter: async () => {
387
+ try {
388
+ const products = await operations.all();
389
+ if (!products || products.length === 0) {
390
+ return {};
391
+ }
392
+ const filterMap = {};
393
+ products.forEach((product) => {
394
+ if (product.variants && product.variants.length > 0) {
395
+ if (product.options && product.options.length > 0) {
396
+ product.options.forEach((option) => {
397
+ const lowercaseOptionName = option.name.toLowerCase();
398
+ if (!filterMap[lowercaseOptionName]) {
399
+ filterMap[lowercaseOptionName] = /* @__PURE__ */ new Set();
400
+ }
401
+ option.values.forEach((value) => {
402
+ const trimmed = value == null ? void 0 : value.trim();
403
+ if (trimmed) {
404
+ let set = filterMap[lowercaseOptionName];
405
+ if (!set) {
406
+ set = /* @__PURE__ */ new Set();
407
+ filterMap[lowercaseOptionName] = set;
408
+ }
409
+ set.add(trimmed.toLowerCase());
410
+ }
411
+ });
412
+ });
413
+ }
414
+ product.variants.forEach((variant) => {
415
+ var _a, _b, _c, _d, _e, _f;
416
+ if (variant.option1) {
417
+ const optionName = (((_b = (_a = product.options) == null ? void 0 : _a[0]) == null ? void 0 : _b.name) || "Option 1").toLowerCase();
418
+ let set1 = filterMap[optionName];
419
+ if (!set1) {
420
+ set1 = /* @__PURE__ */ new Set();
421
+ filterMap[optionName] = set1;
422
+ }
423
+ set1.add(variant.option1.trim().toLowerCase());
424
+ }
425
+ if (variant.option2) {
426
+ const optionName = (((_d = (_c = product.options) == null ? void 0 : _c[1]) == null ? void 0 : _d.name) || "Option 2").toLowerCase();
427
+ let set2 = filterMap[optionName];
428
+ if (!set2) {
429
+ set2 = /* @__PURE__ */ new Set();
430
+ filterMap[optionName] = set2;
431
+ }
432
+ set2.add(variant.option2.trim().toLowerCase());
433
+ }
434
+ if (variant.option3) {
435
+ const optionName = (((_f = (_e = product.options) == null ? void 0 : _e[2]) == null ? void 0 : _f.name) || "Option 3").toLowerCase();
436
+ if (!filterMap[optionName]) {
437
+ filterMap[optionName] = /* @__PURE__ */ new Set();
438
+ }
439
+ filterMap[optionName].add(variant.option3.trim().toLowerCase());
440
+ }
441
+ });
442
+ }
443
+ });
444
+ const result = {};
445
+ Object.entries(filterMap).forEach(([optionName, valueSet]) => {
446
+ result[optionName] = Array.from(valueSet).sort();
447
+ });
448
+ return result;
449
+ } catch (error) {
450
+ console.error("Failed to create product filters:", storeDomain, error);
451
+ throw error;
452
+ }
453
+ }
454
+ };
455
+ return operations;
456
+ }
457
+
458
+ export {
459
+ createProductOperations
460
+ };
@@ -1,13 +1,25 @@
1
- import {
2
- formatPrice
3
- } from "./chunk-BWKBRM2Z.mjs";
4
1
  import {
5
2
  rateLimitedFetch
6
- } from "./chunk-2KBOKOAD.mjs";
3
+ } from "./chunk-2MF53V33.js";
4
+ import {
5
+ formatPrice
6
+ } from "./chunk-CN7L3BHG.js";
7
7
 
8
8
  // src/collections.ts
9
9
  import { filter, isNonNullish } from "remeda";
10
10
  function createCollectionOperations(baseUrl, storeDomain, fetchCollections, collectionsDto, fetchPaginatedProductsFromCollection, getStoreInfo, findCollection) {
11
+ const cacheExpiryMs = 5 * 60 * 1e3;
12
+ const findCache = /* @__PURE__ */ new Map();
13
+ const getCached = (key) => {
14
+ const entry = findCache.get(key);
15
+ if (!entry) return void 0;
16
+ if (Date.now() - entry.ts < cacheExpiryMs) return entry.value;
17
+ findCache.delete(key);
18
+ return void 0;
19
+ };
20
+ const setCached = (key, value) => {
21
+ findCache.set(key, { ts: Date.now(), value });
22
+ };
11
23
  function applyCurrencyOverride(product, currency) {
12
24
  var _a, _b, _c, _d, _e, _f;
13
25
  const priceMin = (_b = (_a = product.priceMin) != null ? _a : product.price) != null ? _b : 0;
@@ -140,9 +152,15 @@ function createCollectionOperations(baseUrl, storeDomain, fetchCollections, coll
140
152
  if (sanitizedHandle.length > 255) {
141
153
  throw new Error("Collection handle is too long");
142
154
  }
155
+ const cached = getCached(sanitizedHandle);
156
+ if (typeof cached !== "undefined") {
157
+ return cached;
158
+ }
143
159
  try {
144
160
  const url = `${baseUrl}collections/${encodeURIComponent(sanitizedHandle)}.json`;
145
- const response = await rateLimitedFetch(url);
161
+ const response = await rateLimitedFetch(url, {
162
+ rateLimitClass: "collections:single"
163
+ });
146
164
  if (!response.ok) {
147
165
  if (response.status === 404) {
148
166
  return null;
@@ -175,7 +193,12 @@ function createCollectionOperations(baseUrl, storeDomain, fetchCollections, coll
175
193
  image: collectionImage
176
194
  }
177
195
  ]);
178
- return collectionData[0] || null;
196
+ const coll = collectionData[0] || null;
197
+ setCached(sanitizedHandle, coll);
198
+ if ((coll == null ? void 0 : coll.handle) && coll.handle !== sanitizedHandle) {
199
+ setCached(coll.handle, coll);
200
+ }
201
+ return coll;
179
202
  } catch (error) {
180
203
  if (error instanceof Error) {
181
204
  console.error(
@@ -395,4 +418,3 @@ function createCollectionOperations(baseUrl, storeDomain, fetchCollections, coll
395
418
  export {
396
419
  createCollectionOperations
397
420
  };
398
- //# sourceMappingURL=chunk-QCTICSBE.mjs.map