shop-client 3.10.0 → 3.11.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.
@@ -12,8 +12,8 @@ import {
12
12
 
13
13
  // src/client/get-info.ts
14
14
  import { unique } from "remeda";
15
- async function getInfoForStore(args) {
16
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
15
+ async function getInfoForStore(args, options) {
16
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
17
17
  const {
18
18
  baseUrl,
19
19
  storeDomain,
@@ -22,7 +22,8 @@ async function getInfoForStore(args) {
22
22
  validateLinksInBatches
23
23
  } = args;
24
24
  const response = await rateLimitedFetch(baseUrl, {
25
- rateLimitClass: "store:info"
25
+ rateLimitClass: "store:info",
26
+ timeoutMs: 7e3
26
27
  });
27
28
  if (!response.ok) {
28
29
  throw new Error(`HTTP error! status: ${response.status}`);
@@ -94,18 +95,22 @@ async function getInfoForStore(args) {
94
95
  )) {
95
96
  contactLinks.contactPage = (match == null ? void 0 : match[1]) || null;
96
97
  }
97
- const extractedProductLinks = ((_g = (_f = html.match(/href=["']([^"']*\/products\/[^"']+)["']/g)) == null ? void 0 : _f.map(
98
- (match) => {
99
- var _a2, _b2;
100
- return (_b2 = (_a2 = match == null ? void 0 : match.split("href=")[1]) == null ? void 0 : _a2.replace(/["']/g, "")) == null ? void 0 : _b2.split("/").at(-1);
101
- }
102
- )) == null ? void 0 : _g.filter(Boolean)) || [];
103
- const extractedCollectionLinks = ((_i = (_h = html.match(/href=["']([^"']*\/collections\/[^"']+)["']/g)) == null ? void 0 : _h.map(
104
- (match) => {
105
- var _a2, _b2;
106
- return (_b2 = (_a2 = match == null ? void 0 : match.split("href=")[1]) == null ? void 0 : _a2.replace(/["']/g, "")) == null ? void 0 : _b2.split("/").at(-1);
107
- }
108
- )) == null ? void 0 : _i.filter(Boolean)) || [];
98
+ const extractedProductLinks = unique(
99
+ ((_g = (_f = html.match(/href=["']([^"']*\/products\/[^"']+)["']/g)) == null ? void 0 : _f.map(
100
+ (match) => {
101
+ var _a2, _b2;
102
+ return (_b2 = (_a2 = match == null ? void 0 : match.split("href=")[1]) == null ? void 0 : _a2.replace(/["']/g, "")) == null ? void 0 : _b2.split("/").at(-1);
103
+ }
104
+ )) == null ? void 0 : _g.filter(Boolean)) || []
105
+ ).slice(0, 8);
106
+ const extractedCollectionLinks = unique(
107
+ ((_i = (_h = html.match(/href=["']([^"']*\/collections\/[^"']+)["']/g)) == null ? void 0 : _h.map(
108
+ (match) => {
109
+ var _a2, _b2;
110
+ return (_b2 = (_a2 = match == null ? void 0 : match.split("href=")[1]) == null ? void 0 : _a2.replace(/["']/g, "")) == null ? void 0 : _b2.split("/").at(-1);
111
+ }
112
+ )) == null ? void 0 : _i.filter(Boolean)) || []
113
+ ).slice(0, 8);
109
114
  const headerLinks = (_k = (_j = html.match(
110
115
  /<(header|nav|div|section)\b[^>]*\b(?:id|class)=["'][^"']*(?=.*shopify-section)(?=.*\b(header|navigation|nav|menu)\b)[^"']*["'][^>]*>[\s\S]*?<\/\1>/gi
111
116
  )) == null ? void 0 : _j.flatMap((header) => {
@@ -129,20 +134,37 @@ async function getInfoForStore(args) {
129
134
  })) != null ? _k : [];
130
135
  const slug = generateStoreSlug(baseUrl);
131
136
  const countryDetection = await detectShopCountry(html);
132
- const [homePageProductLinks, homePageCollectionLinks] = await Promise.all([
133
- validateLinksInBatches(
134
- extractedProductLinks.filter(
135
- (handle) => Boolean(handle)
137
+ const doValidate = (options == null ? void 0 : options.validateShowcase) === true;
138
+ let homePageProductLinks = [];
139
+ let homePageCollectionLinks = [];
140
+ if (doValidate) {
141
+ const batchSize = (_l = options == null ? void 0 : options.validationBatchSize) != null ? _l : 5;
142
+ const validated = await Promise.all([
143
+ validateLinksInBatches(
144
+ extractedProductLinks.filter(
145
+ (handle) => Boolean(handle)
146
+ ),
147
+ (handle) => validateProductExists(handle),
148
+ batchSize
136
149
  ),
137
- (handle) => validateProductExists(handle)
138
- ),
139
- validateLinksInBatches(
140
- extractedCollectionLinks.filter(
141
- (handle) => Boolean(handle)
142
- ),
143
- (handle) => validateCollectionExists(handle)
144
- )
145
- ]);
150
+ validateLinksInBatches(
151
+ extractedCollectionLinks.filter(
152
+ (handle) => Boolean(handle)
153
+ ),
154
+ (handle) => validateCollectionExists(handle),
155
+ batchSize
156
+ )
157
+ ]);
158
+ homePageProductLinks = (_m = validated[0]) != null ? _m : [];
159
+ homePageCollectionLinks = (_n = validated[1]) != null ? _n : [];
160
+ } else {
161
+ homePageProductLinks = extractedProductLinks.filter(
162
+ (handle) => Boolean(handle)
163
+ );
164
+ homePageCollectionLinks = extractedCollectionLinks.filter(
165
+ (handle) => Boolean(handle)
166
+ );
167
+ }
146
168
  const info = {
147
169
  name: name || slug,
148
170
  domain: sanitizeDomain(baseUrl),
@@ -157,14 +179,14 @@ async function getInfoForStore(args) {
157
179
  products: unique(homePageProductLinks != null ? homePageProductLinks : []),
158
180
  collections: unique(homePageCollectionLinks != null ? homePageCollectionLinks : [])
159
181
  },
160
- jsonLdData: ((_m = (_l = html.match(
182
+ jsonLdData: ((_p = (_o = html.match(
161
183
  /<script[^>]*type="application\/ld\+json"[^>]*>([^<]+)<\/script>/g
162
- )) == null ? void 0 : _l.map(
184
+ )) == null ? void 0 : _o.map(
163
185
  (match) => {
164
186
  var _a2;
165
187
  return ((_a2 = match == null ? void 0 : match.split(">")[1]) == null ? void 0 : _a2.replace(/<\/script/g, "")) || null;
166
188
  }
167
- )) == null ? void 0 : _m.map((json) => json ? JSON.parse(json) : null)) || [],
189
+ )) == null ? void 0 : _p.map((json) => json ? JSON.parse(json) : null)) || [],
168
190
  techProvider: {
169
191
  name: "shopify",
170
192
  walletId: shopifyWalletId,
package/dist/index.d.ts CHANGED
@@ -153,6 +153,8 @@ declare class ShopClient {
153
153
  */
154
154
  getInfo(options?: {
155
155
  force?: boolean;
156
+ validateShowcase?: boolean;
157
+ validationBatchSize?: number;
156
158
  }): Promise<StoreInfo>;
157
159
  /**
158
160
  * Manually clear the cached store info.
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  import {
11
11
  createStoreOperations,
12
12
  getInfoForStore
13
- } from "./chunk-MSIVKUGN.mjs";
13
+ } from "./chunk-EUAKMCAX.mjs";
14
14
  import {
15
15
  classifyProduct,
16
16
  determineStoreType,
@@ -568,7 +568,8 @@ var ShopClient = class {
568
568
  const url = `${this.baseUrl}products/${handle}.js`;
569
569
  const response = await rateLimitedFetch(url, {
570
570
  method: "HEAD",
571
- rateLimitClass: "validate:product"
571
+ rateLimitClass: "validate:product",
572
+ timeoutMs: 5e3
572
573
  });
573
574
  const exists = response.ok;
574
575
  this.setCacheValue(cacheKey, exists);
@@ -590,7 +591,8 @@ var ShopClient = class {
590
591
  const url = `${this.baseUrl}collections/${handle}.json`;
591
592
  const response = await rateLimitedFetch(url, {
592
593
  method: "HEAD",
593
- rateLimitClass: "validate:collection"
594
+ rateLimitClass: "validate:collection",
595
+ timeoutMs: 5e3
594
596
  });
595
597
  const exists = response.ok;
596
598
  this.setCacheValue(cacheKey, exists);
@@ -685,13 +687,19 @@ var ShopClient = class {
685
687
  return await this.infoInFlight;
686
688
  }
687
689
  this.infoInFlight = (async () => {
688
- const { info, currencyCode } = await getInfoForStore({
689
- baseUrl: this.baseUrl,
690
- storeDomain: this.storeDomain,
691
- validateProductExists: (handle) => this.validateProductExists(handle),
692
- validateCollectionExists: (handle) => this.validateCollectionExists(handle),
693
- validateLinksInBatches: (items, validator, batchSize) => this.validateLinksInBatches(items, validator, batchSize)
694
- });
690
+ const { info, currencyCode } = await getInfoForStore(
691
+ {
692
+ baseUrl: this.baseUrl,
693
+ storeDomain: this.storeDomain,
694
+ validateProductExists: (handle) => this.validateProductExists(handle),
695
+ validateCollectionExists: (handle) => this.validateCollectionExists(handle),
696
+ validateLinksInBatches: (items, validator, batchSize) => this.validateLinksInBatches(items, validator, batchSize)
697
+ },
698
+ {
699
+ validateShowcase: (options == null ? void 0 : options.validateShowcase) === true,
700
+ validationBatchSize: options == null ? void 0 : options.validationBatchSize
701
+ }
702
+ );
695
703
  if (typeof currencyCode === "string") {
696
704
  this.storeCurrency = currencyCode;
697
705
  }
package/dist/store.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createStoreOperations
3
- } from "./chunk-MSIVKUGN.mjs";
3
+ } from "./chunk-EUAKMCAX.mjs";
4
4
  import "./chunk-D5MTUWFO.mjs";
5
5
  import "./chunk-G7OCMGA6.mjs";
6
6
  import "./chunk-U3RQRBXZ.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shop-client",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",