@commercengine/storefront-sdk 0.13.2 → 0.13.4
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/index.d.mts +160 -67
- package/dist/index.iife.js +64 -17
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +64 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1121,7 +1121,7 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1121
1121
|
/**
|
|
1122
1122
|
* Get details for a specific product
|
|
1123
1123
|
*
|
|
1124
|
-
* @param pathParams - The path parameters
|
|
1124
|
+
* @param pathParams - The path parameters. Accepts product ID or product slug.
|
|
1125
1125
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1126
1126
|
* @returns Promise with product details
|
|
1127
1127
|
*
|
|
@@ -1129,7 +1129,7 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1129
1129
|
* ```typescript
|
|
1130
1130
|
* // Get product by ID
|
|
1131
1131
|
* const { data, error } = await sdk.catalog.getProductDetail(
|
|
1132
|
-
* {
|
|
1132
|
+
* { product_id: "prod_123" }
|
|
1133
1133
|
* );
|
|
1134
1134
|
*
|
|
1135
1135
|
* if (error) {
|
|
@@ -1141,14 +1141,15 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1141
1141
|
* console.log("Price:", data.product.pricing?.selling_price);
|
|
1142
1142
|
* console.log("Description:", data.product.short_description);
|
|
1143
1143
|
*
|
|
1144
|
-
* // Get product by slug
|
|
1144
|
+
* // Get product by slug (also accepted in place of product_id)
|
|
1145
1145
|
* const { data: slugData, error: slugError } = await sdk.catalog.getProductDetail({
|
|
1146
|
-
*
|
|
1146
|
+
* product_id: "detox-candy"
|
|
1147
1147
|
* });
|
|
1148
1148
|
*
|
|
1149
1149
|
* // Override customer group ID for this specific request
|
|
1150
1150
|
* const { data: overrideData, error: overrideError } = await sdk.catalog.getProductDetail(
|
|
1151
|
-
* {
|
|
1151
|
+
* { product_id: "detox-candy" },
|
|
1152
|
+
* undefined,
|
|
1152
1153
|
* {
|
|
1153
1154
|
* "x-customer-group-id": "premium_customers" // Override default SDK config
|
|
1154
1155
|
* }
|
|
@@ -1164,7 +1165,7 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1164
1165
|
*/
|
|
1165
1166
|
async getProductDetail(pathParams, options, headers) {
|
|
1166
1167
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
1167
|
-
return this.executeRequest(() => this.client.GET("/catalog/products/{
|
|
1168
|
+
return this.executeRequest(() => this.client.GET("/catalog/products/{product_id}", { params: {
|
|
1168
1169
|
path: pathParams,
|
|
1169
1170
|
query: options,
|
|
1170
1171
|
header: mergedHeaders
|
|
@@ -1173,12 +1174,13 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1173
1174
|
/**
|
|
1174
1175
|
* List all variants for a specific product
|
|
1175
1176
|
*
|
|
1176
|
-
* @param pathParams - The path parameters
|
|
1177
|
+
* @param pathParams - The path parameters. Accepts product ID or product slug.
|
|
1177
1178
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1178
1179
|
* @returns Promise with product variants and pagination info
|
|
1179
1180
|
*
|
|
1180
1181
|
* @example
|
|
1181
1182
|
* ```typescript
|
|
1183
|
+
* // By product ID
|
|
1182
1184
|
* const { data, error } = await sdk.catalog.listProductVariants(
|
|
1183
1185
|
* { product_id: "prod_123" }
|
|
1184
1186
|
* );
|
|
@@ -1194,9 +1196,15 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1194
1196
|
* console.log(`Variant: ${variant.name} - SKU: ${variant.sku} - Price: ${variant.pricing?.selling_price}`);
|
|
1195
1197
|
* });
|
|
1196
1198
|
*
|
|
1199
|
+
* // By product slug (also accepted in place of product_id)
|
|
1200
|
+
* const { data: slugData, error: slugError } = await sdk.catalog.listProductVariants(
|
|
1201
|
+
* { product_id: "detox-candy" }
|
|
1202
|
+
* );
|
|
1203
|
+
*
|
|
1197
1204
|
* // Override customer group ID for this specific request
|
|
1198
1205
|
* const { data: overrideData, error: overrideError } = await sdk.catalog.listProductVariants(
|
|
1199
1206
|
* { product_id: "prod_123" },
|
|
1207
|
+
* undefined,
|
|
1200
1208
|
* {
|
|
1201
1209
|
* "x-customer-group-id": "wholesale_customers" // Override default SDK config
|
|
1202
1210
|
* }
|
|
@@ -1214,12 +1222,13 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1214
1222
|
/**
|
|
1215
1223
|
* Get details for a specific product variant
|
|
1216
1224
|
*
|
|
1217
|
-
* @param pathParams - The path parameters
|
|
1225
|
+
* @param pathParams - The path parameters. Accepts product ID or slug for product_id, and variant ID or slug for variant_id.
|
|
1218
1226
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1219
1227
|
* @returns Promise with variant details
|
|
1220
1228
|
*
|
|
1221
1229
|
* @example
|
|
1222
1230
|
* ```typescript
|
|
1231
|
+
* // By product ID and variant ID
|
|
1223
1232
|
* const { data, error } = await sdk.catalog.getVariantDetail(
|
|
1224
1233
|
* {
|
|
1225
1234
|
* product_id: "prod_123",
|
|
@@ -1236,6 +1245,14 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1236
1245
|
* console.log("SKU:", data.variant.sku);
|
|
1237
1246
|
* console.log("Price:", data.variant.pricing?.selling_price);
|
|
1238
1247
|
* console.log("Stock available:", data.variant.stock_available);
|
|
1248
|
+
*
|
|
1249
|
+
* // By product slug and variant slug (also accepted in place of IDs)
|
|
1250
|
+
* const { data: slugData, error: slugError } = await sdk.catalog.getVariantDetail(
|
|
1251
|
+
* {
|
|
1252
|
+
* product_id: "detox-candy",
|
|
1253
|
+
* variant_id: "detox-candy-100g"
|
|
1254
|
+
* }
|
|
1255
|
+
* );
|
|
1239
1256
|
* ```
|
|
1240
1257
|
*/
|
|
1241
1258
|
async getVariantDetail(pathParams, options, headers) {
|
|
@@ -1365,19 +1382,15 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1365
1382
|
/**
|
|
1366
1383
|
* Search for products
|
|
1367
1384
|
*
|
|
1368
|
-
* @param searchData - The search query and
|
|
1385
|
+
* @param searchData - The search query, filters, sort, and pagination options
|
|
1369
1386
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1370
|
-
* @returns Promise with search results including
|
|
1387
|
+
* @returns Promise with search results including SKUs, facet distribution, facet stats, and pagination
|
|
1371
1388
|
*
|
|
1372
1389
|
* @example
|
|
1373
1390
|
* ```typescript
|
|
1391
|
+
* // Basic search
|
|
1374
1392
|
* const { data, error } = await sdk.catalog.searchProducts({
|
|
1375
1393
|
* query: "smartphone",
|
|
1376
|
-
* filters: {
|
|
1377
|
-
* category: ["electronics", "mobile"],
|
|
1378
|
-
* price_range: { min: 100, max: 1000 },
|
|
1379
|
-
* brand: ["Apple", "Samsung"] // facet names depend on product configuration
|
|
1380
|
-
* },
|
|
1381
1394
|
* page: 1,
|
|
1382
1395
|
* limit: 20
|
|
1383
1396
|
* });
|
|
@@ -1389,17 +1402,51 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1389
1402
|
*
|
|
1390
1403
|
* console.log("Search results:", data.skus?.length || 0, "products found");
|
|
1391
1404
|
* console.log("Facet distribution:", data.facet_distribution);
|
|
1392
|
-
* console.log("
|
|
1405
|
+
* console.log("Facet stats:", data.facet_stats);
|
|
1406
|
+
* console.log("Pagination:", data.pagination);
|
|
1393
1407
|
*
|
|
1394
1408
|
* data.skus?.forEach(sku => {
|
|
1395
1409
|
* console.log(`Found: ${sku.product_name} - ${sku.pricing?.selling_price}`);
|
|
1396
1410
|
* });
|
|
1397
1411
|
*
|
|
1412
|
+
* // With filter (string expression — Meilisearch syntax)
|
|
1413
|
+
* const { data: filtered, error: filteredError } = await sdk.catalog.searchProducts({
|
|
1414
|
+
* query: "laptop",
|
|
1415
|
+
* filter: "pricing.selling_price 500 TO 2000 AND product_type = physical",
|
|
1416
|
+
* sort: ["pricing.selling_price:asc"],
|
|
1417
|
+
* facets: ["product_type", "categories.name", "tags"],
|
|
1418
|
+
* page: 1,
|
|
1419
|
+
* limit: 10
|
|
1420
|
+
* });
|
|
1421
|
+
*
|
|
1422
|
+
* // With filter (array of conditions — combined with AND)
|
|
1423
|
+
* const { data: arrayFiltered, error: arrayError } = await sdk.catalog.searchProducts({
|
|
1424
|
+
* query: "shoes",
|
|
1425
|
+
* filter: ["product_type = physical", "rating >= 4", "stock_available > 0"],
|
|
1426
|
+
* sort: ["rating:desc"],
|
|
1427
|
+
* facets: ["*"],
|
|
1428
|
+
* page: 1,
|
|
1429
|
+
* limit: 25
|
|
1430
|
+
* });
|
|
1431
|
+
*
|
|
1432
|
+
* // With filter (nested arrays — inner arrays use OR, outer uses AND)
|
|
1433
|
+
* const { data: nestedFiltered, error: nestedError } = await sdk.catalog.searchProducts({
|
|
1434
|
+
* query: "headphones",
|
|
1435
|
+
* filter: [
|
|
1436
|
+
* "pricing.selling_price 50 TO 300",
|
|
1437
|
+
* ["product_type = physical", "product_type = bundle"]
|
|
1438
|
+
* ],
|
|
1439
|
+
* page: 1,
|
|
1440
|
+
* limit: 25
|
|
1441
|
+
* });
|
|
1442
|
+
*
|
|
1398
1443
|
* // Override customer group ID for this specific request
|
|
1399
1444
|
* const { data: overrideData, error: overrideError } = await sdk.catalog.searchProducts(
|
|
1400
1445
|
* {
|
|
1401
1446
|
* query: "laptop",
|
|
1402
|
-
*
|
|
1447
|
+
* filter: "categories.name = computers",
|
|
1448
|
+
* page: 1,
|
|
1449
|
+
* limit: 20
|
|
1403
1450
|
* },
|
|
1404
1451
|
* {
|
|
1405
1452
|
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|