ui.shipaid.com 0.3.95 → 0.3.96
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/widget.es.js +61 -39
- package/dist/widget.iife.js +83 -79
- package/dist/widget.umd.js +83 -79
- package/dist-types/widget/src/shipaid-widget.d.ts +4 -1
- package/package.json +1 -1
package/dist/widget.es.js
CHANGED
|
@@ -2392,6 +2392,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2392
2392
|
this.fetchInterceptorCleanup = () => {
|
|
2393
2393
|
};
|
|
2394
2394
|
this.intervalId = null;
|
|
2395
|
+
this._sellingPlanId = null;
|
|
2395
2396
|
this._state = {
|
|
2396
2397
|
loading: false,
|
|
2397
2398
|
success: null,
|
|
@@ -2758,28 +2759,17 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2758
2759
|
this._cart = cart;
|
|
2759
2760
|
}
|
|
2760
2761
|
async addCartProtectionVariant() {
|
|
2761
|
-
var _a, _b
|
|
2762
|
+
var _a, _b;
|
|
2762
2763
|
let cart;
|
|
2763
|
-
let sellingPlanId;
|
|
2764
|
-
if (this.supportSubscriptions) {
|
|
2765
|
-
const itemWithSubscription = (_b = (_a = this._cart) == null ? void 0 : _a.items) == null ? void 0 : _b.find((item) => {
|
|
2766
|
-
var _a2;
|
|
2767
|
-
return item.id !== ((_a2 = this._protectionVariant) == null ? void 0 : _a2.id) && !!(item == null ? void 0 : item.selling_plan_allocation);
|
|
2768
|
-
});
|
|
2769
|
-
if (itemWithSubscription) {
|
|
2770
|
-
const protectionSellingPlan = await this._fetchSellingPlanFromVariant(itemWithSubscription.selling_plan_allocation.selling_plan);
|
|
2771
|
-
sellingPlanId = protectionSellingPlan ? getIdFromShopifyGid(protectionSellingPlan.id) : null;
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
2764
|
if (this.useCustomStoreFront) {
|
|
2775
2765
|
const cartItemAdded = await this.runStoreFrontQuery(
|
|
2776
2766
|
"mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) { cartLinesAdd(cartId: $cartId, lines: $lines) { cart { id lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } } }",
|
|
2777
2767
|
{
|
|
2778
2768
|
cartId: this.cartId,
|
|
2779
2769
|
lines: [{
|
|
2780
|
-
merchandiseId: String((
|
|
2770
|
+
merchandiseId: String((_a = this._protectionVariant) == null ? void 0 : _a.id),
|
|
2781
2771
|
quantity: 1,
|
|
2782
|
-
sellingPlanId
|
|
2772
|
+
sellingPlanId: this._sellingPlanId
|
|
2783
2773
|
}]
|
|
2784
2774
|
}
|
|
2785
2775
|
);
|
|
@@ -2787,8 +2777,8 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2787
2777
|
} else {
|
|
2788
2778
|
const payload = {
|
|
2789
2779
|
quantity: 1,
|
|
2790
|
-
id: String((
|
|
2791
|
-
selling_plan:
|
|
2780
|
+
id: String((_b = this._protectionVariant) == null ? void 0 : _b.id),
|
|
2781
|
+
selling_plan: this._sellingPlanId
|
|
2792
2782
|
};
|
|
2793
2783
|
cart = await this._fetch.post(
|
|
2794
2784
|
"/cart/add.js",
|
|
@@ -2797,7 +2787,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2797
2787
|
}
|
|
2798
2788
|
return cart;
|
|
2799
2789
|
}
|
|
2800
|
-
async updateCartProtectionVariant(qty, protectionCartItem = null
|
|
2790
|
+
async updateCartProtectionVariant(qty, protectionCartItem = null) {
|
|
2801
2791
|
var _a, _b;
|
|
2802
2792
|
let cart;
|
|
2803
2793
|
if (this.useCustomStoreFront) {
|
|
@@ -2809,7 +2799,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2809
2799
|
{
|
|
2810
2800
|
id: String(protectionCartItem ? protectionCartItem.key : (_a = this._protectionCartItem) == null ? void 0 : _a.key),
|
|
2811
2801
|
quantity: qty,
|
|
2812
|
-
sellingPlanId
|
|
2802
|
+
sellingPlanId: this._sellingPlanId
|
|
2813
2803
|
}
|
|
2814
2804
|
]
|
|
2815
2805
|
}
|
|
@@ -2819,7 +2809,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
2819
2809
|
const payload = {
|
|
2820
2810
|
quantity: qty,
|
|
2821
2811
|
id: String(protectionCartItem ? protectionCartItem.key : (_b = this._protectionCartItem) == null ? void 0 : _b.key),
|
|
2822
|
-
selling_plan:
|
|
2812
|
+
selling_plan: this._sellingPlanId
|
|
2823
2813
|
};
|
|
2824
2814
|
cart = await this._fetch.post(
|
|
2825
2815
|
"/cart/change.js",
|
|
@@ -3080,8 +3070,28 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
3080
3070
|
createRenderRoot() {
|
|
3081
3071
|
return this.useShipAidCheckout ? this : super.createRenderRoot();
|
|
3082
3072
|
}
|
|
3073
|
+
async getSubscription(_cart) {
|
|
3074
|
+
var _a;
|
|
3075
|
+
if (!(_cart == null ? void 0 : _cart.items) || !(_cart == null ? void 0 : _cart.item_count)) return;
|
|
3076
|
+
const itemWithSubscription = (_a = _cart == null ? void 0 : _cart.items) == null ? void 0 : _a.find((item) => {
|
|
3077
|
+
var _a2;
|
|
3078
|
+
return item.id !== ((_a2 = this._protectionVariant) == null ? void 0 : _a2.id) && !!(item == null ? void 0 : item.selling_plan_allocation);
|
|
3079
|
+
});
|
|
3080
|
+
if (itemWithSubscription) {
|
|
3081
|
+
const protectionSellingPlan = await this._fetchSellingPlanFromVariant(itemWithSubscription.selling_plan_allocation.selling_plan);
|
|
3082
|
+
return protectionSellingPlan ? getIdFromShopifyGid(protectionSellingPlan.id) : null;
|
|
3083
|
+
}
|
|
3084
|
+
return null;
|
|
3085
|
+
}
|
|
3086
|
+
getCheckoutURL() {
|
|
3087
|
+
var _a, _b;
|
|
3088
|
+
if (this._sellingPlanId) {
|
|
3089
|
+
return `/cart/add?id=${(_a = this._protectionVariant) == null ? void 0 : _a.id}&quantity=1&selling_plan=${this._sellingPlanId}&return_to=/checkout`;
|
|
3090
|
+
}
|
|
3091
|
+
return `/checkout?attributes[_shipaid-internal]=1&updates[${(_b = this._protectionVariant) == null ? void 0 : _b.id}]=1`;
|
|
3092
|
+
}
|
|
3083
3093
|
checkoutButtonTemplate() {
|
|
3084
|
-
var _a, _b, _c, _d, _e;
|
|
3094
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3085
3095
|
if (!document.getElementById("shipaid-styles")) {
|
|
3086
3096
|
const style = document.createElement("style");
|
|
3087
3097
|
style.id = "shipaid-styles";
|
|
@@ -3244,19 +3254,25 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
3244
3254
|
</svg>
|
|
3245
3255
|
</div>
|
|
3246
3256
|
</div>
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
var _a2;
|
|
3257
|
+
${this._sellingPlanId ? x`
|
|
3258
|
+
<button id="shipaid-checkout-button" class="${originalClasses}" @click=${async () => {
|
|
3259
|
+
var _a2, _b2;
|
|
3250
3260
|
sessionStorage.setItem("shipaid_variant", JSON.stringify((_a2 = this._protectionVariant) == null ? void 0 : _a2.id));
|
|
3261
|
+
await this.addCartProtectionVariant();
|
|
3262
|
+
window.location.href = `/checkout?attributes[_shipaid-internal]=1&updates[${(_b2 = this._protectionVariant) == null ? void 0 : _b2.id}]=1`;
|
|
3251
3263
|
}}>
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
window.location.href = "/checkout";
|
|
3264
|
+
<slot name="checkout-button-text">CHECKOUT+</slot> ${cartTotal ? this._currencyFormat(cartTotal) : loading2}
|
|
3265
|
+
</button>
|
|
3266
|
+
` : x`
|
|
3267
|
+
<a href="/checkout${((_d = this._protectionVariant) == null ? void 0 : _d.id) ? `?attributes[_shipaid-internal]=1&updates[${(_e = this._protectionVariant) == null ? void 0 : _e.id}]=1` : ""}" id="shipaid-checkout-button" class="${originalClasses}" @click=${() => {
|
|
3268
|
+
var _a2;
|
|
3269
|
+
sessionStorage.setItem("shipaid_variant", JSON.stringify((_a2 = this._protectionVariant) == null ? void 0 : _a2.id));
|
|
3259
3270
|
}}>
|
|
3271
|
+
<span class="shipaid-checkout-text">${translate("checkout-plus.checkout")}+</span>
|
|
3272
|
+
<span class="shipaid-checkout-amount">${cartTotal ? this._currencyFormat(cartTotal) : loading2}</span>
|
|
3273
|
+
</a>
|
|
3274
|
+
`}
|
|
3275
|
+
<a href="/checkout${((_f = this._protectionVariant) == null ? void 0 : _f.id) ? `?attributes[_shipaid-internal]=1&updates[${(_g = this._protectionVariant) == null ? void 0 : _g.id}]=0` : ""}" class="continue-link">
|
|
3260
3276
|
<slot name="link-continue">${translate("checkout-plus.continue")}</slot>
|
|
3261
3277
|
</a>
|
|
3262
3278
|
</div>
|
|
@@ -3440,22 +3456,25 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
3440
3456
|
this._shouldShowWidget = false;
|
|
3441
3457
|
return;
|
|
3442
3458
|
}
|
|
3459
|
+
if (this.useShipAidCheckout && this.supportSubscriptions) {
|
|
3460
|
+
this._sellingPlanId = await this.getSubscription(this._cart);
|
|
3461
|
+
}
|
|
3443
3462
|
if (!protectionCartItem) return;
|
|
3444
|
-
if (this.supportSubscriptions) {
|
|
3463
|
+
if (this.supportSubscriptions && !this.useShipAidCheckout) {
|
|
3445
3464
|
const itemWithSubscription = this._cart.items.find((item) => {
|
|
3446
3465
|
var _a2;
|
|
3447
3466
|
return item.id !== ((_a2 = this._protectionVariant) == null ? void 0 : _a2.id) && !!(item == null ? void 0 : item.selling_plan_allocation);
|
|
3448
3467
|
});
|
|
3449
|
-
let
|
|
3468
|
+
let shouldUpdateSubscription = true;
|
|
3450
3469
|
if (!itemWithSubscription && (protectionCartItem == null ? void 0 : protectionCartItem.selling_plan_allocation)) {
|
|
3451
|
-
|
|
3470
|
+
this._sellingPlanId = null;
|
|
3452
3471
|
} else if (itemWithSubscription && !(protectionCartItem == null ? void 0 : protectionCartItem.selling_plan_allocation)) {
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3472
|
+
this._sellingPlanId = await this.getSubscription(this._cart);
|
|
3473
|
+
} else {
|
|
3474
|
+
shouldUpdateSubscription = false;
|
|
3456
3475
|
}
|
|
3457
|
-
if (
|
|
3458
|
-
const cart2 = await this.updateCartProtectionVariant(
|
|
3476
|
+
if (shouldUpdateSubscription) {
|
|
3477
|
+
const cart2 = await this.updateCartProtectionVariant(1, protectionCartItem);
|
|
3459
3478
|
await this._handleRefresh(cart2);
|
|
3460
3479
|
}
|
|
3461
3480
|
}
|
|
@@ -3579,7 +3598,7 @@ const _ShipAidWidget = class _ShipAidWidget extends s$1 {
|
|
|
3579
3598
|
);
|
|
3580
3599
|
}
|
|
3581
3600
|
}, 500);
|
|
3582
|
-
if (this.disablePolling) return;
|
|
3601
|
+
if (this.disablePolling || this.useShipAidCheckout) return;
|
|
3583
3602
|
setInterval(async () => {
|
|
3584
3603
|
const lastUpdated = this._cartLastUpdated;
|
|
3585
3604
|
if (lastUpdated) {
|
|
@@ -4014,6 +4033,9 @@ __decorateClass([
|
|
|
4014
4033
|
__decorateClass([
|
|
4015
4034
|
t$3()
|
|
4016
4035
|
], ShipAidWidget.prototype, "intervalId");
|
|
4036
|
+
__decorateClass([
|
|
4037
|
+
t$3()
|
|
4038
|
+
], ShipAidWidget.prototype, "_sellingPlanId");
|
|
4017
4039
|
__decorateClass([
|
|
4018
4040
|
t$3()
|
|
4019
4041
|
], ShipAidWidget.prototype, "_state");
|