@shoppexio/storefront 1.0.93 → 1.0.94

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/CHANGELOG.md CHANGED
@@ -1,7 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.94
4
+
5
+ - `getProduct(idOrSlug, { variant })` reads a product for a variant's direct link (`?variant=<id>`). A private variant (`is_private: true`) is listed only when it is named this way; it then comes first in `price_variants`, so a buy box that opens on the first sellable option preselects it. Product lists never carry a private variant.
6
+
3
7
  ## 1.0.93
4
8
 
9
+ - `undoSubscriptionCancel(uniqid)` takes back a scheduled cancellation of the signed-in customer's subscription before its period ends (PR #3696).
5
10
  - Select custom fields: `StorefrontCustomField.options` lists the labels of a `type: "select"` field, and `validateStorefrontCustomFieldValue` refuses any other answer with "<name> must be one of the listed options." (the server refuses it with `custom_field_option_invalid`). Draw a select as a dropdown of exactly these labels.
6
11
  - `normalizeStorefrontCustomFields` leaves out fields the merchant collects after payment (`collect_after_payment`). The buyer answers those on the invoice after paying, and the server drops a value the cart sends for them.
7
12
  - `Product.addons_required`: the buyer must pick one of the product's `addons`; the server refuses a cart or invoice line that names none with `errors.checkout.addon_required`. It asks nothing when `addons` is empty. Send the buyer to the product page to choose; never add an add-on for them.
package/dist/index.cjs CHANGED
@@ -1370,7 +1370,8 @@ function priceVariantToProductVariant(variant) {
1370
1370
  cloudflare_image_id: variant.cloudflare_image_id,
1371
1371
  cloudflareImageId: variant.cloudflareImageId,
1372
1372
  image_url: variant.image_url,
1373
- imageUrl: variant.imageUrl
1373
+ imageUrl: variant.imageUrl,
1374
+ is_private: variant.is_private
1374
1375
  };
1375
1376
  }
1376
1377
  function normalizeProduct(product) {
@@ -1454,7 +1455,7 @@ async function getStorefrontProductsPage(options) {
1454
1455
  }
1455
1456
  return forwardFailure(response);
1456
1457
  }
1457
- async function getProduct(idOrSlug) {
1458
+ async function getProduct(idOrSlug, options = {}) {
1458
1459
  let shopId = getShopId();
1459
1460
  if (!shopId) {
1460
1461
  const store = await getStore();
@@ -1463,13 +1464,16 @@ async function getProduct(idOrSlug) {
1463
1464
  }
1464
1465
  shopId = store.data?.id ?? null;
1465
1466
  }
1466
- const queryParams = shopId ? `?slug_shop_id=${encodeURIComponent(shopId)}` : "";
1467
+ const query = new URLSearchParams();
1468
+ if (shopId) query.set("slug_shop_id", shopId);
1469
+ if (options.variant) query.set("variant", options.variant);
1470
+ const queryParams = query.size > 0 ? `?${query.toString()}` : "";
1467
1471
  const response = await get(
1468
1472
  `${buildEndpoint("/v1/storefront/products/unique/:idOrSlug", { idOrSlug })}${queryParams}`,
1469
1473
  {
1470
1474
  buyerCurrency: true,
1471
1475
  cache: {
1472
- key: `product:${idOrSlug}:${shopId ?? "no-shop"}`,
1476
+ key: `product:${idOrSlug}:${shopId ?? "no-shop"}:${options.variant ?? "no-variant"}`,
1473
1477
  ttl: PRODUCTS_CACHE_TTL,
1474
1478
  staleWhileRevalidate: true
1475
1479
  }