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.
- package/dist/{chunk-MSIVKUGN.mjs → chunk-EUAKMCAX.mjs} +53 -31
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +18 -10
- package/dist/store.mjs +1 -1
- package/package.json +1 -1
|
@@ -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 = (
|
|
98
|
-
(match)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
(handle) =>
|
|
142
|
-
|
|
143
|
-
|
|
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: ((
|
|
182
|
+
jsonLdData: ((_p = (_o = html.match(
|
|
161
183
|
/<script[^>]*type="application\/ld\+json"[^>]*>([^<]+)<\/script>/g
|
|
162
|
-
)) == null ? void 0 :
|
|
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 :
|
|
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
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
createStoreOperations,
|
|
12
12
|
getInfoForStore
|
|
13
|
-
} from "./chunk-
|
|
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
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
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