@swell/apps-sdk 1.0.144 → 1.0.145
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.cjs +29 -11
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +29 -11
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +29 -11
- package/dist/index.mjs.map +3 -3
- package/dist/src/resources/product_helpers.d.ts +3 -0
- package/dist/src/resources/swell_types.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7386,9 +7386,25 @@ var SwellPage = class extends SwellStorefrontRecord {
|
|
|
7386
7386
|
};
|
|
7387
7387
|
|
|
7388
7388
|
// src/resources/product_helpers.ts
|
|
7389
|
+
function isGiftcard(product) {
|
|
7390
|
+
return product.type === "giftcard";
|
|
7391
|
+
}
|
|
7392
|
+
function isOptionAvailable(product, option) {
|
|
7393
|
+
if (isGiftcard(product)) {
|
|
7394
|
+
return true;
|
|
7395
|
+
}
|
|
7396
|
+
return Boolean(option.active && option.name);
|
|
7397
|
+
}
|
|
7398
|
+
function isProductAvailable(product, variant) {
|
|
7399
|
+
if (product.stock_purchasable) {
|
|
7400
|
+
return true;
|
|
7401
|
+
}
|
|
7402
|
+
const stockStatus = (variant || product).stock_status;
|
|
7403
|
+
return !stockStatus || stockStatus === "in_stock";
|
|
7404
|
+
}
|
|
7389
7405
|
function getAvailableVariants(product) {
|
|
7390
7406
|
return (product.variants?.results?.slice()?.reverse() || []).filter(
|
|
7391
|
-
(variant) =>
|
|
7407
|
+
(variant) => isProductAvailable(product, variant)
|
|
7392
7408
|
);
|
|
7393
7409
|
}
|
|
7394
7410
|
function isOptionValueAvailable(option, value, product, availableVariants) {
|
|
@@ -7455,7 +7471,7 @@ function getSelectedVariantOptionValues(product, queryParams, variant) {
|
|
|
7455
7471
|
return acc;
|
|
7456
7472
|
}
|
|
7457
7473
|
const hasOptionValues = option.values.length > 0;
|
|
7458
|
-
if (!option
|
|
7474
|
+
if (!isOptionAvailable(product, option) || !hasOptionValues) {
|
|
7459
7475
|
return acc;
|
|
7460
7476
|
}
|
|
7461
7477
|
const value = option.values.find(
|
|
@@ -14273,8 +14289,8 @@ function ShopifyVariant(instance, variant, productIn, depth = 0) {
|
|
|
14273
14289
|
return new ShopifyResource({
|
|
14274
14290
|
...swellVariant,
|
|
14275
14291
|
available: deferWith(
|
|
14276
|
-
variant,
|
|
14277
|
-
(variant2) =>
|
|
14292
|
+
[product, variant],
|
|
14293
|
+
(product2, variant2) => isProductAvailable(product2, variant2)
|
|
14278
14294
|
),
|
|
14279
14295
|
barcode: void 0,
|
|
14280
14296
|
compare_at_price: defer(() => variant.orig_price),
|
|
@@ -14363,7 +14379,7 @@ function ShopifyVariant(instance, variant, productIn, depth = 0) {
|
|
|
14363
14379
|
requires_selling_plan: false,
|
|
14364
14380
|
requires_shipping: deferWith(
|
|
14365
14381
|
product,
|
|
14366
|
-
(product2) => Boolean(product2.delivery?.
|
|
14382
|
+
(product2) => Boolean(product2.delivery?.includes("shipment"))
|
|
14367
14383
|
),
|
|
14368
14384
|
selected: false,
|
|
14369
14385
|
selected_selling_plan_allocation: void 0,
|
|
@@ -14432,7 +14448,7 @@ function ShopifyProduct(instance, product, depth = 0) {
|
|
|
14432
14448
|
return new ShopifyResource({
|
|
14433
14449
|
available: deferWith(
|
|
14434
14450
|
product,
|
|
14435
|
-
(product2) => product2
|
|
14451
|
+
(product2) => isProductAvailable(product2)
|
|
14436
14452
|
),
|
|
14437
14453
|
collections: [],
|
|
14438
14454
|
// TODO: need to support this in the resource class somehow
|
|
@@ -14457,7 +14473,7 @@ function ShopifyProduct(instance, product, depth = 0) {
|
|
|
14457
14473
|
const variant = getSelectedVariant(product2, {});
|
|
14458
14474
|
return variant ? ShopifyVariant(instance, variant, product2, depth + 1) : void 0;
|
|
14459
14475
|
}),
|
|
14460
|
-
"gift_card?": deferWith(product,
|
|
14476
|
+
"gift_card?": deferWith(product, isGiftcard),
|
|
14461
14477
|
handle: defer(() => product.slug),
|
|
14462
14478
|
// indicates that product has any options
|
|
14463
14479
|
has_only_default_variant: deferWith(
|
|
@@ -14489,7 +14505,9 @@ function ShopifyProduct(instance, product, depth = 0) {
|
|
|
14489
14505
|
if (!Array.isArray(product2.options)) {
|
|
14490
14506
|
return [];
|
|
14491
14507
|
}
|
|
14492
|
-
return product2.options.filter(
|
|
14508
|
+
return product2.options.filter(
|
|
14509
|
+
(option) => isOptionAvailable(product2, option)
|
|
14510
|
+
).map((option) => option.name);
|
|
14493
14511
|
}),
|
|
14494
14512
|
options_by_name: deferWith(product, (product2) => {
|
|
14495
14513
|
if (!Array.isArray(product2.options)) {
|
|
@@ -14500,7 +14518,7 @@ function ShopifyProduct(instance, product, depth = 0) {
|
|
|
14500
14518
|
const variant = getSelectedVariant(product2, queryParams);
|
|
14501
14519
|
return product2.options.reduce(
|
|
14502
14520
|
(acc, option, index) => {
|
|
14503
|
-
if (!
|
|
14521
|
+
if (!isOptionAvailable(product2, option)) {
|
|
14504
14522
|
return acc;
|
|
14505
14523
|
}
|
|
14506
14524
|
acc[option.name.toLowerCase()] = getOption(
|
|
@@ -14526,7 +14544,7 @@ function ShopifyProduct(instance, product, depth = 0) {
|
|
|
14526
14544
|
const { queryParams } = instance.swell;
|
|
14527
14545
|
const variants = getAvailableVariants(product2);
|
|
14528
14546
|
const variant = getSelectedVariant(product2, queryParams);
|
|
14529
|
-
return product2.options.filter((option) =>
|
|
14547
|
+
return product2.options.filter((option) => isOptionAvailable(product2, option)).map(
|
|
14530
14548
|
(option, index) => getOption(
|
|
14531
14549
|
option,
|
|
14532
14550
|
index,
|
|
@@ -14699,7 +14717,7 @@ function ShopifyLineItem(instance, item, cart, options = {}) {
|
|
|
14699
14717
|
: undefined, */
|
|
14700
14718
|
fulfillment_service: "manual",
|
|
14701
14719
|
// TODO
|
|
14702
|
-
gift_card: item.
|
|
14720
|
+
gift_card: isGiftcard(item.product),
|
|
14703
14721
|
grams: item.shipment_weight,
|
|
14704
14722
|
id: item.id,
|
|
14705
14723
|
image: deferWith(
|