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
package/dist/index.d.ts CHANGED
@@ -1,97 +1,20 @@
1
1
  import { CheckoutOperations } from './checkout.js';
2
2
  import { CollectionOperations } from './collections.js';
3
3
  import { ProductOperations } from './products.js';
4
- import { P as ProductClassification, S as SEOContent, C as CountryDetectionResult, a as StoreOperations, b as ShopifyProduct, c as Product, d as ShopifySingleProduct, e as ShopifyCollection, f as Collection, g as StoreInfo, h as StoreTypeBreakdown } from './store-CJVUz2Yb.js';
5
- export { H as Address, F as CatalogCategory, I as ContactUrls, K as CountryScore, N as CountryScores, J as Coupon, y as CurrencyCode, G as Demographics, Q as JsonLdEntry, L as LocalizedPricing, M as MetaTag, D as ProductImage, z as ProductOption, x as ProductPricing, B as ProductVariant, A as ProductVariantImage, E as ShopifyApiProduct, u as ShopifyBaseProduct, r as ShopifyBaseVariant, k as ShopifyBasicInfo, o as ShopifyFeaturedMedia, O as ShopifyFeaturesData, m as ShopifyImage, l as ShopifyImageDimensions, p as ShopifyMedia, q as ShopifyOption, w as ShopifyPredictiveProductSearch, v as ShopifyProductAndStore, s as ShopifyProductVariant, t as ShopifySingleProductVariant, j as ShopifyTimestamps, n as ShopifyVariantImage, i as StoreCatalog, R as StoreTypeResult, V as ValidStoreCatalog } from './store-CJVUz2Yb.js';
4
+ import { StoreOperations, StoreInfo } from './store.js';
5
+ import { S as ShopifyProduct, P as Product, a as ShopifySingleProduct, b as ShopifyCollection, C as Collection, c as StoreTypeBreakdown } from './types-luPg5O08.js';
6
+ export { d as CountryDetectionResult, e as CountryScores, f as CurrencyCode, L as LocalizedPricing, M as MetaTag, g as ProductImage, h as ProductOption, i as ProductVariant, j as ProductVariantImage } from './types-luPg5O08.js';
7
+ export { classifyProduct, generateSEOContent } from './ai/enrich.js';
8
+ export { detectShopCountry } from './utils/detect-country.js';
9
+ export { calculateDiscount, extractDomainWithoutSuffix, genProductSlug, generateStoreSlug, safeParseDate, sanitizeDomain } from './utils/func.js';
6
10
  export { configureRateLimit } from './utils/rate-limit.js';
7
11
 
8
- /**
9
- * Classify product content into a three-tier hierarchy using LLM.
10
- * Returns strictly validated JSON with audience, vertical, and optional category/subCategory.
11
- */
12
- declare function classifyProduct(productContent: string, options?: {
13
- apiKey?: string;
14
- model?: string;
15
- }): Promise<ProductClassification>;
16
- /**
17
- * Generate SEO and marketing content for a product. Returns strictly validated JSON.
18
- */
19
- declare function generateSEOContent(product: {
20
- title: string;
21
- description?: string;
22
- vendor?: string;
23
- price?: number;
24
- tags?: string[];
25
- }, options?: {
26
- apiKey?: string;
27
- model?: string;
28
- }): Promise<SEOContent>;
29
-
30
- /**
31
- * Detects the country of a Shopify store by analyzing various signals in the HTML content.
32
- *
33
- * This function examines multiple data sources within the HTML to determine the store's country:
34
- * - Shopify features JSON data (country, locale, money format)
35
- * - Phone number prefixes in contact information
36
- * - JSON-LD structured data with address information
37
- * - Footer mentions of country names
38
- * - Currency symbols in money formatting
39
- *
40
- * @param html - The HTML content of the Shopify store's homepage
41
- * @returns Promise resolving to country detection results containing:
42
- * - `country` - The detected country ISO 3166-1 alpha-2 code (e.g., "US", "GB") or "Unknown" if no reliable detection
43
- * - `confidence` - Confidence score between 0 and 1 (higher = more confident)
44
- * - `signals` - Array of detection signals that contributed to the result
45
- *
46
- * @example
47
- * ```typescript
48
- * const response = await fetch('https://exampleshop.com');
49
- * const html = await response.text();
50
- * const result = await detectShopifyCountry(html);
51
- *
52
- * console.log(result.country); // "US" (ISO code for United States)
53
- * console.log(result.confidence); // 0.85
54
- * console.log(result.signals); // ["shopify-features.country", "phone prefix +1"]
55
- * ```
56
- */
57
- declare function detectShopifyCountry(html: string): Promise<CountryDetectionResult>;
58
-
59
- declare function extractDomainWithoutSuffix(domain: string): string | null;
60
- declare function generateStoreSlug(domain: string): string;
61
- declare const genProductSlug: ({ handle, storeDomain, }: {
62
- handle: string;
63
- storeDomain: string;
64
- }) => string;
65
- declare const calculateDiscount: (price: number, compareAtPrice?: number) => number;
66
- /**
67
- * Normalize and sanitize a domain string.
68
- *
69
- * Accepts inputs like full URLs, protocol-relative URLs, bare hostnames,
70
- * or strings with paths/query/fragment, and returns a normalized domain.
71
- *
72
- * Examples:
73
- * - "https://WWW.Example.com/path" -> "example.com"
74
- * - "//sub.example.co.uk" -> "example.co.uk"
75
- * - "www.example.com:8080" -> "example.com"
76
- * - "example" -> "example"
77
- */
78
- declare function sanitizeDomain(input: string, opts?: {
79
- stripWWW?: boolean;
80
- }): string;
81
- /**
82
- * Safely parse a date string into a Date object.
83
- *
84
- * Returns `undefined` when input is falsy or cannot be parsed into a valid date.
85
- * Use `|| null` at call sites that expect `null` instead of `undefined`.
86
- */
87
- declare function safeParseDate(input?: string | null): Date | undefined;
88
-
89
12
  /**
90
13
  * A comprehensive Shopify store client for fetching products, collections, and store information.
91
14
  *
92
15
  * @example
93
16
  * ```typescript
94
- * import { ShopClient } from 'shop-search';
17
+ * import { ShopClient } from 'shop-client';
95
18
  *
96
19
  * const shop = new ShopClient('https://exampleshop.com');
97
20
  *
@@ -102,6 +25,9 @@ declare function safeParseDate(input?: string | null): Date | undefined;
102
25
  * const storeInfo = await shop.getInfo();
103
26
  * ```
104
27
  */
28
+ type ShopClientOptions = {
29
+ cacheTTL?: number;
30
+ };
105
31
  declare class ShopClient {
106
32
  private storeDomain;
107
33
  private baseUrl;
@@ -111,6 +37,9 @@ declare class ShopClient {
111
37
  private cacheTimestamps;
112
38
  private normalizeImageUrlCache;
113
39
  private storeCurrency?;
40
+ private infoCacheValue?;
41
+ private infoCacheTimestamp?;
42
+ private infoInFlight?;
114
43
  products: ProductOperations;
115
44
  collections: CollectionOperations;
116
45
  checkout: CheckoutOperations;
@@ -135,7 +64,7 @@ declare class ShopClient {
135
64
  * const shop2 = new ShopClient('https://boutique.fashion');
136
65
  * ```
137
66
  */
138
- constructor(urlPath: string);
67
+ constructor(urlPath: string, options?: ShopClientOptions);
139
68
  /**
140
69
  * Optimized image URL normalization with caching
141
70
  */
@@ -217,7 +146,19 @@ declare class ShopClient {
217
146
  * console.log(storeInfo.country); // "US"
218
147
  * ```
219
148
  */
220
- getInfo(): Promise<StoreInfo>;
149
+ /**
150
+ * Optionally bypass cache and force a fresh fetch.
151
+ *
152
+ * @param options - `{ force?: boolean }` when `true`, ignores cached value and TTL.
153
+ */
154
+ getInfo(options?: {
155
+ force?: boolean;
156
+ }): Promise<StoreInfo>;
157
+ /**
158
+ * Manually clear the cached store info.
159
+ * The next call to `getInfo()` will fetch fresh data regardless of TTL.
160
+ */
161
+ clearInfoCache(): void;
221
162
  /**
222
163
  * Determine the store's primary vertical and target audience.
223
164
  * Uses `getInfo()` internally; no input required.
@@ -230,4 +171,4 @@ declare class ShopClient {
230
171
  }): Promise<StoreTypeBreakdown>;
231
172
  }
232
173
 
233
- export { CheckoutOperations, Collection, CollectionOperations, CountryDetectionResult, Product, ProductClassification, ProductOperations, SEOContent, ShopClient, ShopifyCollection, ShopifyProduct, ShopifySingleProduct, StoreInfo, StoreOperations, StoreTypeBreakdown, calculateDiscount, classifyProduct, detectShopifyCountry, extractDomainWithoutSuffix, genProductSlug, generateSEOContent, generateStoreSlug, safeParseDate, sanitizeDomain };
174
+ export { CheckoutOperations, Collection, CollectionOperations, Product, ProductOperations, ShopClient, type ShopClientOptions, StoreInfo, StoreOperations, StoreTypeBreakdown };