@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.js
CHANGED
|
@@ -7279,9 +7279,25 @@
|
|
|
7279
7279
|
};
|
|
7280
7280
|
|
|
7281
7281
|
// src/resources/product_helpers.ts
|
|
7282
|
+
function isGiftcard(product) {
|
|
7283
|
+
return product.type === "giftcard";
|
|
7284
|
+
}
|
|
7285
|
+
function isOptionAvailable(product, option) {
|
|
7286
|
+
if (isGiftcard(product)) {
|
|
7287
|
+
return true;
|
|
7288
|
+
}
|
|
7289
|
+
return Boolean(option.active && option.name);
|
|
7290
|
+
}
|
|
7291
|
+
function isProductAvailable(product, variant) {
|
|
7292
|
+
if (product.stock_purchasable) {
|
|
7293
|
+
return true;
|
|
7294
|
+
}
|
|
7295
|
+
const stockStatus = (variant || product).stock_status;
|
|
7296
|
+
return !stockStatus || stockStatus === "in_stock";
|
|
7297
|
+
}
|
|
7282
7298
|
function getAvailableVariants(product) {
|
|
7283
7299
|
return (product.variants?.results?.slice()?.reverse() || []).filter(
|
|
7284
|
-
(variant) =>
|
|
7300
|
+
(variant) => isProductAvailable(product, variant)
|
|
7285
7301
|
);
|
|
7286
7302
|
}
|
|
7287
7303
|
function isOptionValueAvailable(option, value, product, availableVariants) {
|
|
@@ -7348,7 +7364,7 @@
|
|
|
7348
7364
|
return acc;
|
|
7349
7365
|
}
|
|
7350
7366
|
const hasOptionValues = option.values.length > 0;
|
|
7351
|
-
if (!option
|
|
7367
|
+
if (!isOptionAvailable(product, option) || !hasOptionValues) {
|
|
7352
7368
|
return acc;
|
|
7353
7369
|
}
|
|
7354
7370
|
const value = option.values.find(
|
|
@@ -14166,8 +14182,8 @@ ${formattedMessage}`;
|
|
|
14166
14182
|
return new ShopifyResource({
|
|
14167
14183
|
...swellVariant,
|
|
14168
14184
|
available: deferWith(
|
|
14169
|
-
variant,
|
|
14170
|
-
(variant2) =>
|
|
14185
|
+
[product, variant],
|
|
14186
|
+
(product2, variant2) => isProductAvailable(product2, variant2)
|
|
14171
14187
|
),
|
|
14172
14188
|
barcode: void 0,
|
|
14173
14189
|
compare_at_price: defer(() => variant.orig_price),
|
|
@@ -14256,7 +14272,7 @@ ${formattedMessage}`;
|
|
|
14256
14272
|
requires_selling_plan: false,
|
|
14257
14273
|
requires_shipping: deferWith(
|
|
14258
14274
|
product,
|
|
14259
|
-
(product2) => Boolean(product2.delivery?.
|
|
14275
|
+
(product2) => Boolean(product2.delivery?.includes("shipment"))
|
|
14260
14276
|
),
|
|
14261
14277
|
selected: false,
|
|
14262
14278
|
selected_selling_plan_allocation: void 0,
|
|
@@ -14325,7 +14341,7 @@ ${formattedMessage}`;
|
|
|
14325
14341
|
return new ShopifyResource({
|
|
14326
14342
|
available: deferWith(
|
|
14327
14343
|
product,
|
|
14328
|
-
(product2) => product2
|
|
14344
|
+
(product2) => isProductAvailable(product2)
|
|
14329
14345
|
),
|
|
14330
14346
|
collections: [],
|
|
14331
14347
|
// TODO: need to support this in the resource class somehow
|
|
@@ -14350,7 +14366,7 @@ ${formattedMessage}`;
|
|
|
14350
14366
|
const variant = getSelectedVariant(product2, {});
|
|
14351
14367
|
return variant ? ShopifyVariant(instance, variant, product2, depth + 1) : void 0;
|
|
14352
14368
|
}),
|
|
14353
|
-
"gift_card?": deferWith(product,
|
|
14369
|
+
"gift_card?": deferWith(product, isGiftcard),
|
|
14354
14370
|
handle: defer(() => product.slug),
|
|
14355
14371
|
// indicates that product has any options
|
|
14356
14372
|
has_only_default_variant: deferWith(
|
|
@@ -14382,7 +14398,9 @@ ${formattedMessage}`;
|
|
|
14382
14398
|
if (!Array.isArray(product2.options)) {
|
|
14383
14399
|
return [];
|
|
14384
14400
|
}
|
|
14385
|
-
return product2.options.filter(
|
|
14401
|
+
return product2.options.filter(
|
|
14402
|
+
(option) => isOptionAvailable(product2, option)
|
|
14403
|
+
).map((option) => option.name);
|
|
14386
14404
|
}),
|
|
14387
14405
|
options_by_name: deferWith(product, (product2) => {
|
|
14388
14406
|
if (!Array.isArray(product2.options)) {
|
|
@@ -14393,7 +14411,7 @@ ${formattedMessage}`;
|
|
|
14393
14411
|
const variant = getSelectedVariant(product2, queryParams);
|
|
14394
14412
|
return product2.options.reduce(
|
|
14395
14413
|
(acc, option, index) => {
|
|
14396
|
-
if (!
|
|
14414
|
+
if (!isOptionAvailable(product2, option)) {
|
|
14397
14415
|
return acc;
|
|
14398
14416
|
}
|
|
14399
14417
|
acc[option.name.toLowerCase()] = getOption(
|
|
@@ -14419,7 +14437,7 @@ ${formattedMessage}`;
|
|
|
14419
14437
|
const { queryParams } = instance.swell;
|
|
14420
14438
|
const variants = getAvailableVariants(product2);
|
|
14421
14439
|
const variant = getSelectedVariant(product2, queryParams);
|
|
14422
|
-
return product2.options.filter((option) =>
|
|
14440
|
+
return product2.options.filter((option) => isOptionAvailable(product2, option)).map(
|
|
14423
14441
|
(option, index) => getOption(
|
|
14424
14442
|
option,
|
|
14425
14443
|
index,
|
|
@@ -14592,7 +14610,7 @@ ${formattedMessage}`;
|
|
|
14592
14610
|
: undefined, */
|
|
14593
14611
|
fulfillment_service: "manual",
|
|
14594
14612
|
// TODO
|
|
14595
|
-
gift_card: item.
|
|
14613
|
+
gift_card: isGiftcard(item.product),
|
|
14596
14614
|
grams: item.shipment_weight,
|
|
14597
14615
|
id: item.id,
|
|
14598
14616
|
image: deferWith(
|