shop-client 3.15.0 → 3.16.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 +25 -0
- package/dist/ai/enrich.d.ts +3 -0
- package/dist/ai/enrich.mjs +1 -1
- package/dist/{chunk-ESTBP7AD.mjs → chunk-THCO3JT4.mjs} +45 -5
- package/dist/{chunk-2W623LCW.mjs → chunk-ZX4IG4TY.mjs} +12 -6
- package/dist/index.mjs +2 -2
- package/dist/products.d.ts +10 -0
- package/dist/products.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -409,6 +409,24 @@ const showcasedProducts = await shop.products.showcased();
|
|
|
409
409
|
|
|
410
410
|
**Returns:** `Product[]` - Array of featured products
|
|
411
411
|
|
|
412
|
+
#### `products.infoHtml(productHandle, content?)`
|
|
413
|
+
|
|
414
|
+
Fetches the extracted HTML content from the product page. This is useful for getting the main product description and content directly from the page HTML.
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
// Fetch from store
|
|
418
|
+
const html = await shop.products.infoHtml("product-handle");
|
|
419
|
+
|
|
420
|
+
// Use provided HTML
|
|
421
|
+
const htmlFromContent = await shop.products.infoHtml("product-handle", "<html>...</html>");
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
**Parameters:**
|
|
425
|
+
- `productHandle` (string): The product handle
|
|
426
|
+
- `content` (string, optional): HTML content to extract from. If provided, skips fetching the product page.
|
|
427
|
+
|
|
428
|
+
**Returns:** `Promise<string | null>` - Extracted HTML content or null if not found
|
|
429
|
+
|
|
412
430
|
#### `products.filter()`
|
|
413
431
|
|
|
414
432
|
Creates a map of variant options and their distinct values from all products in the store. This is useful for building filter interfaces, search facets, and product option selectors.
|
|
@@ -739,6 +757,12 @@ const enrichedMarkdown = await shop.products.enriched('some-product-handle', {
|
|
|
739
757
|
});
|
|
740
758
|
// enrichedMarkdown?.enriched_content → markdown
|
|
741
759
|
|
|
760
|
+
// Use provided content instead of fetching product page
|
|
761
|
+
const enrichedFromContent = await shop.products.enriched('some-product-handle', {
|
|
762
|
+
outputFormat: 'markdown',
|
|
763
|
+
content: '<html>...</html>',
|
|
764
|
+
});
|
|
765
|
+
|
|
742
766
|
const enrichedJson = await shop.products.enriched('some-product-handle', {
|
|
743
767
|
outputFormat: 'json',
|
|
744
768
|
});
|
|
@@ -747,6 +771,7 @@ const enrichedJson = await shop.products.enriched('some-product-handle', {
|
|
|
747
771
|
// Build prompts without calling the LLM (useful for debugging)
|
|
748
772
|
const { system, user } = await shop.products.enrichedPrompts('some-product-handle', {
|
|
749
773
|
outputFormat: 'markdown',
|
|
774
|
+
content: '<html>...</html>', // Optional content
|
|
750
775
|
});
|
|
751
776
|
```
|
|
752
777
|
|
package/dist/ai/enrich.d.ts
CHANGED
|
@@ -11,10 +11,12 @@ declare function buildEnrichPromptForProduct(domain: string, handle: string, opt
|
|
|
11
11
|
useGfm?: boolean;
|
|
12
12
|
inputType?: "markdown" | "html";
|
|
13
13
|
outputFormat?: "markdown" | "json";
|
|
14
|
+
htmlContent?: string;
|
|
14
15
|
}): Promise<SystemUserPrompt>;
|
|
15
16
|
declare function buildClassifyPromptForProduct(domain: string, handle: string, options?: {
|
|
16
17
|
useGfm?: boolean;
|
|
17
18
|
inputType?: "markdown" | "html";
|
|
19
|
+
htmlContent?: string;
|
|
18
20
|
}): Promise<SystemUserPrompt>;
|
|
19
21
|
interface EnrichedProductResult {
|
|
20
22
|
bodyHtml: string;
|
|
@@ -63,6 +65,7 @@ declare function enrichProduct(domain: string, handle: string, options?: {
|
|
|
63
65
|
model?: string;
|
|
64
66
|
outputFormat?: "markdown" | "json";
|
|
65
67
|
openRouter?: OpenRouterConfig;
|
|
68
|
+
htmlContent?: string;
|
|
66
69
|
}): Promise<EnrichedProductResult>;
|
|
67
70
|
/**
|
|
68
71
|
* Classify product content into a three-tier hierarchy using LLM.
|
package/dist/ai/enrich.mjs
CHANGED
|
@@ -254,7 +254,8 @@ function createProductOperations(baseUrl, storeDomain, fetchProducts, productsDt
|
|
|
254
254
|
useGfm: options == null ? void 0 : options.useGfm,
|
|
255
255
|
inputType: options == null ? void 0 : options.inputType,
|
|
256
256
|
model: options == null ? void 0 : options.model,
|
|
257
|
-
outputFormat: options == null ? void 0 : options.outputFormat
|
|
257
|
+
outputFormat: options == null ? void 0 : options.outputFormat,
|
|
258
|
+
htmlContent: options == null ? void 0 : options.content
|
|
258
259
|
});
|
|
259
260
|
return {
|
|
260
261
|
...baseProduct,
|
|
@@ -274,7 +275,8 @@ function createProductOperations(baseUrl, storeDomain, fetchProducts, productsDt
|
|
|
274
275
|
return buildEnrichPromptForProduct(storeDomain, handle, {
|
|
275
276
|
useGfm: options == null ? void 0 : options.useGfm,
|
|
276
277
|
inputType: options == null ? void 0 : options.inputType,
|
|
277
|
-
outputFormat: options == null ? void 0 : options.outputFormat
|
|
278
|
+
outputFormat: options == null ? void 0 : options.outputFormat,
|
|
279
|
+
htmlContent: options == null ? void 0 : options.content
|
|
278
280
|
});
|
|
279
281
|
},
|
|
280
282
|
classify: async (productHandle, options) => {
|
|
@@ -285,7 +287,8 @@ function createProductOperations(baseUrl, storeDomain, fetchProducts, productsDt
|
|
|
285
287
|
apiKey: options == null ? void 0 : options.apiKey,
|
|
286
288
|
inputType: "html",
|
|
287
289
|
model: options == null ? void 0 : options.model,
|
|
288
|
-
outputFormat: "json"
|
|
290
|
+
outputFormat: "json",
|
|
291
|
+
content: options == null ? void 0 : options.content
|
|
289
292
|
});
|
|
290
293
|
if (!enrichedProduct || !enrichedProduct.enriched_content) return null;
|
|
291
294
|
let productContent = enrichedProduct.enriched_content;
|
|
@@ -327,7 +330,8 @@ function createProductOperations(baseUrl, storeDomain, fetchProducts, productsDt
|
|
|
327
330
|
const { buildClassifyPromptForProduct } = await import("./ai/enrich.mjs");
|
|
328
331
|
return buildClassifyPromptForProduct(storeDomain, handle, {
|
|
329
332
|
useGfm: options == null ? void 0 : options.useGfm,
|
|
330
|
-
inputType: options == null ? void 0 : options.inputType
|
|
333
|
+
inputType: options == null ? void 0 : options.inputType,
|
|
334
|
+
htmlContent: options == null ? void 0 : options.content
|
|
331
335
|
});
|
|
332
336
|
},
|
|
333
337
|
generateSEOContent: async (productHandle, options) => {
|
|
@@ -343,7 +347,13 @@ function createProductOperations(baseUrl, storeDomain, fetchProducts, productsDt
|
|
|
343
347
|
price: baseProduct.price,
|
|
344
348
|
tags: baseProduct.tags
|
|
345
349
|
};
|
|
346
|
-
const {
|
|
350
|
+
const {
|
|
351
|
+
extractMainSection,
|
|
352
|
+
fetchAjaxProduct,
|
|
353
|
+
fetchProductPage,
|
|
354
|
+
generateSEOContent: generateSEOContentLLM,
|
|
355
|
+
mergeWithLLM
|
|
356
|
+
} = await import("./ai/enrich.mjs");
|
|
347
357
|
const seo = await generateSEOContentLLM(payload, {
|
|
348
358
|
apiKey: options == null ? void 0 : options.apiKey,
|
|
349
359
|
openRouter: ai == null ? void 0 : ai.openRouter,
|
|
@@ -351,6 +361,36 @@ function createProductOperations(baseUrl, storeDomain, fetchProducts, productsDt
|
|
|
351
361
|
});
|
|
352
362
|
return seo;
|
|
353
363
|
},
|
|
364
|
+
/**
|
|
365
|
+
* Fetches the extracted HTML content from the product page.
|
|
366
|
+
* This is useful for getting the main product description and content directly from the page HTML.
|
|
367
|
+
*
|
|
368
|
+
* @param productHandle - The handle of the product
|
|
369
|
+
* @param content - Optional HTML content to extract from. If provided, skips fetching the product page.
|
|
370
|
+
* @returns {Promise<string | null>} The extracted HTML content or null if not found
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```typescript
|
|
374
|
+
* // Fetch from store
|
|
375
|
+
* const html = await shop.products.infoHtml("product-handle");
|
|
376
|
+
*
|
|
377
|
+
* // Use provided HTML
|
|
378
|
+
* const htmlFromContent = await shop.products.infoHtml("product-handle", "<html>...</html>");
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
infoHtml: async (productHandle, content) => {
|
|
382
|
+
if (!productHandle || typeof productHandle !== "string") {
|
|
383
|
+
throw new Error("Product handle is required and must be a string");
|
|
384
|
+
}
|
|
385
|
+
const { extractMainSection, fetchProductPage } = await import("./ai/enrich.mjs");
|
|
386
|
+
if (content) {
|
|
387
|
+
return extractMainSection(content);
|
|
388
|
+
}
|
|
389
|
+
const baseProduct = await operations.find(productHandle);
|
|
390
|
+
if (!baseProduct) return null;
|
|
391
|
+
const pageHtml = await fetchProductPage(storeDomain, baseProduct.handle);
|
|
392
|
+
return extractMainSection(pageHtml);
|
|
393
|
+
},
|
|
354
394
|
/**
|
|
355
395
|
* Fetches products that are showcased/featured on the store's homepage.
|
|
356
396
|
*
|
|
@@ -204,9 +204,11 @@ Return ONLY valid JSON (no markdown, no code fences) with keys:
|
|
|
204
204
|
}
|
|
205
205
|
async function buildEnrichPromptForProduct(domain, handle, options) {
|
|
206
206
|
var _a, _b;
|
|
207
|
+
const ajaxProductPromise = fetchAjaxProduct(domain, handle);
|
|
208
|
+
const pageHtmlPromise = (options == null ? void 0 : options.htmlContent) ? Promise.resolve(options.htmlContent) : fetchProductPage(domain, handle);
|
|
207
209
|
const [ajaxProduct, pageHtml] = await Promise.all([
|
|
208
|
-
|
|
209
|
-
|
|
210
|
+
ajaxProductPromise,
|
|
211
|
+
pageHtmlPromise
|
|
210
212
|
]);
|
|
211
213
|
const bodyHtml = ajaxProduct.description || "";
|
|
212
214
|
const extractedHtml = extractMainSection(pageHtml);
|
|
@@ -220,9 +222,11 @@ async function buildEnrichPromptForProduct(domain, handle, options) {
|
|
|
220
222
|
}
|
|
221
223
|
async function buildClassifyPromptForProduct(domain, handle, options) {
|
|
222
224
|
var _a;
|
|
225
|
+
const ajaxProductPromise = fetchAjaxProduct(domain, handle);
|
|
226
|
+
const pageHtmlPromise = (options == null ? void 0 : options.htmlContent) ? Promise.resolve(options.htmlContent) : fetchProductPage(domain, handle);
|
|
223
227
|
const [ajaxProduct, pageHtml] = await Promise.all([
|
|
224
|
-
|
|
225
|
-
|
|
228
|
+
ajaxProductPromise,
|
|
229
|
+
pageHtmlPromise
|
|
226
230
|
]);
|
|
227
231
|
const bodyHtml = ajaxProduct.description || "";
|
|
228
232
|
const extractedHtml = extractMainSection(pageHtml);
|
|
@@ -499,9 +503,11 @@ function mockOpenRouterResponse(prompt) {
|
|
|
499
503
|
}
|
|
500
504
|
async function enrichProduct(domain, handle, options) {
|
|
501
505
|
var _a;
|
|
506
|
+
const ajaxProductPromise = fetchAjaxProduct(domain, handle);
|
|
507
|
+
const pageHtmlPromise = (options == null ? void 0 : options.htmlContent) ? Promise.resolve(options.htmlContent) : fetchProductPage(domain, handle);
|
|
502
508
|
const [ajaxProduct, pageHtml] = await Promise.all([
|
|
503
|
-
|
|
504
|
-
|
|
509
|
+
ajaxProductPromise,
|
|
510
|
+
pageHtmlPromise
|
|
505
511
|
]);
|
|
506
512
|
const bodyHtml = ajaxProduct.description || "";
|
|
507
513
|
const extractedHtml = extractMainSection(pageHtml);
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-QCB3U4AO.mjs";
|
|
7
7
|
import {
|
|
8
8
|
createProductOperations
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-THCO3JT4.mjs";
|
|
10
10
|
import {
|
|
11
11
|
createShopOperations,
|
|
12
12
|
getInfoForShop
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
classifyProduct,
|
|
16
16
|
determineStoreType,
|
|
17
17
|
generateSEOContent
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-ZX4IG4TY.mjs";
|
|
19
19
|
import {
|
|
20
20
|
configureRateLimit,
|
|
21
21
|
rateLimitedFetch
|
package/dist/products.d.ts
CHANGED
|
@@ -35,11 +35,13 @@ interface ProductOperations {
|
|
|
35
35
|
inputType?: "markdown" | "html";
|
|
36
36
|
model?: string;
|
|
37
37
|
outputFormat?: "markdown" | "json";
|
|
38
|
+
content?: string;
|
|
38
39
|
}): Promise<Product | null>;
|
|
39
40
|
enrichedPrompts(productHandle: string, options?: {
|
|
40
41
|
useGfm?: boolean;
|
|
41
42
|
inputType?: "markdown" | "html";
|
|
42
43
|
outputFormat?: "markdown" | "json";
|
|
44
|
+
content?: string;
|
|
43
45
|
}): Promise<{
|
|
44
46
|
system: string;
|
|
45
47
|
user: string;
|
|
@@ -47,10 +49,12 @@ interface ProductOperations {
|
|
|
47
49
|
classify(productHandle: string, options?: {
|
|
48
50
|
apiKey?: string;
|
|
49
51
|
model?: string;
|
|
52
|
+
content?: string;
|
|
50
53
|
}): Promise<ProductClassification | null>;
|
|
51
54
|
classifyPrompts(productHandle: string, options?: {
|
|
52
55
|
useGfm?: boolean;
|
|
53
56
|
inputType?: "markdown" | "html";
|
|
57
|
+
content?: string;
|
|
54
58
|
}): Promise<{
|
|
55
59
|
system: string;
|
|
56
60
|
user: string;
|
|
@@ -62,6 +66,12 @@ interface ProductOperations {
|
|
|
62
66
|
apiKey?: string;
|
|
63
67
|
model?: string;
|
|
64
68
|
}): Promise<SEOContent | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Fetches the extracted HTML content from the product page.
|
|
71
|
+
* This is useful for getting the main product description and content directly from the page HTML.
|
|
72
|
+
* If content is provided, it is used directly to extract the main section.
|
|
73
|
+
*/
|
|
74
|
+
infoHtml(productHandle: string, content?: string): Promise<string | null>;
|
|
65
75
|
/**
|
|
66
76
|
* Fetches products that are showcased/featured on the store's homepage.
|
|
67
77
|
*/
|
package/dist/products.mjs
CHANGED