shop-client 3.12.0 → 3.14.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/README.md +42 -11
- package/dist/{chunk-VK5666EK.mjs → chunk-RLVH7LEG.mjs} +11 -4
- package/dist/index.mjs +1 -1
- package/dist/store.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Shop
|
|
1
|
+
# Shop Client
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/shop-client)
|
|
4
4
|
[](https://www.typescriptlang.org/)
|
|
@@ -31,8 +31,9 @@
|
|
|
31
31
|
|
|
32
32
|
## 🧠 Store Info Caching & Concurrency
|
|
33
33
|
|
|
34
|
-
`getInfo()` uses time-based caching and in-flight request deduping to avoid redundant network calls:
|
|
34
|
+
`getInfo()` validates the store URL and uses time-based caching and in-flight request deduping to avoid redundant network calls:
|
|
35
35
|
|
|
36
|
+
- Validation: Ensures the URL points to a valid Shopify store (checks for specific meta tags and scripts). Throws an error if invalid.
|
|
36
37
|
- Cache window: `5 minutes` (`cacheExpiry`). Fresh cached results return immediately.
|
|
37
38
|
- You can configure this TTL via the `ShopClient` constructor option `cacheTTL` (milliseconds).
|
|
38
39
|
- Cached fields: `infoCacheValue` (last `StoreInfo`) and `infoCacheTimestamp` (last fetch time).
|
|
@@ -205,17 +206,8 @@ Notes:
|
|
|
205
206
|
|
|
206
207
|
### Migration: Barrel → Subpath Imports
|
|
207
208
|
|
|
208
|
-
#### Package Rename: `shop-search` → `shop-client` (v3.8.2)
|
|
209
|
-
- Install: `npm i shop-client` (replaces `shop-search`)
|
|
210
|
-
- Update imports to `shop-client` (API unchanged)
|
|
211
|
-
|
|
212
209
|
TypeScript:
|
|
213
210
|
```ts
|
|
214
|
-
// Before (pre-rename: shop-search)
|
|
215
|
-
import { Store } from 'shop-search';
|
|
216
|
-
const store = new Store("your-store.myshopify.com");
|
|
217
|
-
|
|
218
|
-
// After (post-rename: shop-client v3.8.2+)
|
|
219
211
|
import { ShopClient } from 'shop-client';
|
|
220
212
|
const client = new ShopClient("your-store.myshopify.com");
|
|
221
213
|
```
|
|
@@ -354,6 +346,8 @@ const storeInfo = await shop.getInfo();
|
|
|
354
346
|
- `headerLinks`: Navigation menu links
|
|
355
347
|
- `showcase`: Featured products and collections
|
|
356
348
|
- `jsonLdData`: Structured data from the store
|
|
349
|
+
- `country`: ISO 3166-1 alpha-2 code (e.g., `US`, `GB`)
|
|
350
|
+
- `currency`: ISO 4217 currency code (e.g., `USD`, `EUR`)
|
|
357
351
|
|
|
358
352
|
### Products
|
|
359
353
|
|
|
@@ -444,6 +438,43 @@ Object.entries(filters || {}).forEach(([optionName, values]) => {
|
|
|
444
438
|
- Handles products with multiple variant options
|
|
445
439
|
- Returns empty object `{}` if no products have variants
|
|
446
440
|
|
|
441
|
+
### Predictive Search
|
|
442
|
+
|
|
443
|
+
#### `products.predictiveSearch(query, options?)`
|
|
444
|
+
|
|
445
|
+
Locale-aware Shopify Ajax predictive search for products.
|
|
446
|
+
|
|
447
|
+
```typescript
|
|
448
|
+
const results = await shop.products.predictiveSearch("dress", {
|
|
449
|
+
limit: 10, // clamps 1–10
|
|
450
|
+
locale: "en", // defaults to "en"
|
|
451
|
+
// unavailableProducts defaults to "hide"
|
|
452
|
+
currency: "USD", // optional override
|
|
453
|
+
});
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
- Hides unavailable items by default
|
|
457
|
+
- Extracts handles from Ajax results, fetches full products via `find`
|
|
458
|
+
- Falls back to non-locale path when locale returns 404/417
|
|
459
|
+
|
|
460
|
+
### Recommendations
|
|
461
|
+
|
|
462
|
+
#### `products.recommendations(productId, options?)`
|
|
463
|
+
|
|
464
|
+
Shopify Ajax product recommendations for a given product.
|
|
465
|
+
|
|
466
|
+
```typescript
|
|
467
|
+
const recos = await shop.products.recommendations(1234567890, {
|
|
468
|
+
limit: 6, // clamps 1–10 (default 10)
|
|
469
|
+
intent: "related", // or "complementary" (default: related)
|
|
470
|
+
locale: "en", // defaults to "en"
|
|
471
|
+
currency: "USD", // optional override
|
|
472
|
+
});
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
- Returns normalized `Product[]`
|
|
476
|
+
- Locale-aware endpoint `/{locale}/recommendations/products.json`
|
|
477
|
+
|
|
447
478
|
### Collections
|
|
448
479
|
|
|
449
480
|
#### `collections.all()`
|
|
@@ -36,6 +36,13 @@ async function getInfoForStore(args, options) {
|
|
|
36
36
|
const match = html.match(regex);
|
|
37
37
|
return match ? match[1] : null;
|
|
38
38
|
};
|
|
39
|
+
const shopifyWalletId = (_a = getMetaTag("shopify-digital-wallet")) == null ? void 0 : _a.split("/")[1];
|
|
40
|
+
const isShopifyStore = html.includes("cdn.shopify.com") || html.includes("myshopify.com") || html.includes("shopify-digital-wallet") || html.includes("Shopify.shop") || html.includes("Shopify.currency") || html.includes("shopify-section");
|
|
41
|
+
if (!isShopifyStore || !shopifyWalletId) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
"The provided URL does not appear to be a valid Shopify store."
|
|
44
|
+
);
|
|
45
|
+
}
|
|
39
46
|
const getPropertyMetaTag = (property) => {
|
|
40
47
|
const regex = new RegExp(
|
|
41
48
|
`<meta[^>]*property=["']${property}["'][^>]*content=["'](.*?)["']`
|
|
@@ -43,10 +50,9 @@ async function getInfoForStore(args, options) {
|
|
|
43
50
|
const match = html.match(regex);
|
|
44
51
|
return match ? match[1] : null;
|
|
45
52
|
};
|
|
46
|
-
const name = (
|
|
47
|
-
const title = (
|
|
53
|
+
const name = (_b = getMetaTag("og:site_name")) != null ? _b : extractDomainWithoutSuffix(baseUrl);
|
|
54
|
+
const title = (_c = getMetaTag("og:title")) != null ? _c : getMetaTag("twitter:title");
|
|
48
55
|
const description = getMetaTag("description") || getPropertyMetaTag("og:description");
|
|
49
|
-
const shopifyWalletId = (_c = getMetaTag("shopify-digital-wallet")) == null ? void 0 : _c.split("/")[1];
|
|
50
56
|
const myShopifySubdomainMatch = html.match(/['"](.*?\.myshopify\.com)['"]/);
|
|
51
57
|
const myShopifySubdomain = myShopifySubdomainMatch ? myShopifySubdomainMatch[1] : null;
|
|
52
58
|
let logoUrl = getPropertyMetaTag("og:image") || getPropertyMetaTag("og:image:secure_url");
|
|
@@ -188,7 +194,7 @@ async function getInfoForStore(args, options) {
|
|
|
188
194
|
}
|
|
189
195
|
)) == null ? void 0 : _p.map((json) => json ? JSON.parse(json) : null)) || [],
|
|
190
196
|
techProvider: {
|
|
191
|
-
name: "shopify",
|
|
197
|
+
name: shopifyWalletId ? "shopify" : "",
|
|
192
198
|
walletId: shopifyWalletId,
|
|
193
199
|
subDomain: myShopifySubdomain != null ? myShopifySubdomain : null
|
|
194
200
|
},
|
|
@@ -219,6 +225,7 @@ function createStoreOperations(context) {
|
|
|
219
225
|
* - `jsonLdData` - Structured data from JSON-LD scripts
|
|
220
226
|
* - `techProvider` - Shopify-specific information (walletId, subDomain)
|
|
221
227
|
* - `country` - Country detection results with ISO 3166-1 alpha-2 codes (e.g., "US", "GB")
|
|
228
|
+
* - `currency` - ISO 4217 currency code inferred from store (e.g., "USD")
|
|
222
229
|
*
|
|
223
230
|
* @throws {Error} When the store URL is unreachable or returns an error
|
|
224
231
|
*
|
package/dist/index.mjs
CHANGED
package/dist/store.mjs
CHANGED