ui.shipaid.com 0.2.16 → 0.2.17
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
CHANGED
|
@@ -672,7 +672,8 @@ const styles$1 = i$1`
|
|
|
672
672
|
--shipaid-font-heavy: 700;
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
-
p,
|
|
675
|
+
p,
|
|
676
|
+
a {
|
|
676
677
|
font-family: var(--shipaid-font);
|
|
677
678
|
font-weight: var(--shipaid-font-regular);
|
|
678
679
|
font-size: var(--shipaid-font-base);
|
|
@@ -690,7 +691,7 @@ const styles$1 = i$1`
|
|
|
690
691
|
max-height: 80vh;
|
|
691
692
|
height: fit-content;
|
|
692
693
|
border: var(--shipaid-popup-border, var(--shipaid-light-grey)) 1px solid;
|
|
693
|
-
background-color:var(--shipaid-popup-background, #fff);
|
|
694
|
+
background-color: var(--shipaid-popup-background, #fff);
|
|
694
695
|
z-index: 1000000000;
|
|
695
696
|
overflow: auto;
|
|
696
697
|
visibility: hidden;
|
|
@@ -710,9 +711,11 @@ const styles$1 = i$1`
|
|
|
710
711
|
|
|
711
712
|
@media (max-width: 600px) {
|
|
712
713
|
.shipaid-popup {
|
|
713
|
-
width:
|
|
714
|
+
width: auto;
|
|
714
715
|
height: 100vh;
|
|
715
716
|
padding: 3rem;
|
|
717
|
+
margin-left: 20px;
|
|
718
|
+
margin-right: 20px;
|
|
716
719
|
}
|
|
717
720
|
}
|
|
718
721
|
|
|
@@ -1432,7 +1435,6 @@ let ShipAidWidget = class extends s {
|
|
|
1432
1435
|
payload
|
|
1433
1436
|
);
|
|
1434
1437
|
await this._handleRefresh(cartItem);
|
|
1435
|
-
this._lastAction = "added";
|
|
1436
1438
|
this._setState("success");
|
|
1437
1439
|
} catch (err) {
|
|
1438
1440
|
const error = err;
|
|
@@ -1460,7 +1462,6 @@ let ShipAidWidget = class extends s {
|
|
|
1460
1462
|
payload
|
|
1461
1463
|
);
|
|
1462
1464
|
await this._handleRefresh(cart);
|
|
1463
|
-
this._lastAction = "removed";
|
|
1464
1465
|
this._cart = cart;
|
|
1465
1466
|
this._setState("success");
|
|
1466
1467
|
} catch (err) {
|
|
@@ -1548,14 +1549,6 @@ let ShipAidWidget = class extends s {
|
|
|
1548
1549
|
);
|
|
1549
1550
|
linkEl.setAttribute("rel", "stylesheet");
|
|
1550
1551
|
document.head.appendChild(linkEl);
|
|
1551
|
-
try {
|
|
1552
|
-
const payload = sessionStorage.getItem(LOCAL_STORAGE_KEY);
|
|
1553
|
-
const { lastAction } = payload ? JSON.parse(payload) : {};
|
|
1554
|
-
if (lastAction)
|
|
1555
|
-
this._lastAction = lastAction;
|
|
1556
|
-
} catch (error) {
|
|
1557
|
-
logger.warn("Failed to parse local storage.");
|
|
1558
|
-
}
|
|
1559
1552
|
try {
|
|
1560
1553
|
const [storeData, cartData, productData] = await Promise.all([
|
|
1561
1554
|
this._fetchShipAidData(),
|
|
@@ -1592,10 +1585,16 @@ let ShipAidWidget = class extends s {
|
|
|
1592
1585
|
this._shouldShowWidget = true;
|
|
1593
1586
|
this._dispatchEvent(Events.LOADED, this._store);
|
|
1594
1587
|
setTimeout(async () => {
|
|
1595
|
-
var _a2, _b2;
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
if (
|
|
1588
|
+
var _a2, _b2, _c;
|
|
1589
|
+
if (!((_a2 = this._store) == null ? void 0 : _a2.widgetAutoOptIn))
|
|
1590
|
+
return;
|
|
1591
|
+
if (!((_b2 = this._cart) == null ? void 0 : _b2.item_count))
|
|
1592
|
+
return;
|
|
1593
|
+
const hasSessionPayload = !!sessionStorage.getItem(LOCAL_STORAGE_KEY);
|
|
1594
|
+
if (hasSessionPayload)
|
|
1595
|
+
return;
|
|
1596
|
+
sessionStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify({ loaded: true }));
|
|
1597
|
+
if (!this._hasProtectionInCart && ((_c = this._cart) == null ? void 0 : _c.item_count) && this._store.widgetShowCart) {
|
|
1599
1598
|
await this.addProtection();
|
|
1600
1599
|
}
|
|
1601
1600
|
}, 500);
|
|
@@ -1612,17 +1611,6 @@ let ShipAidWidget = class extends s {
|
|
|
1612
1611
|
await this.updateCart();
|
|
1613
1612
|
}, this.pollingInterval);
|
|
1614
1613
|
});
|
|
1615
|
-
useEffect(
|
|
1616
|
-
this,
|
|
1617
|
-
() => {
|
|
1618
|
-
const payload = {
|
|
1619
|
-
hasProtection: this._hasProtectionInCart,
|
|
1620
|
-
lastAction: this._lastAction
|
|
1621
|
-
};
|
|
1622
|
-
sessionStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(payload));
|
|
1623
|
-
},
|
|
1624
|
-
[this._lastAction]
|
|
1625
|
-
);
|
|
1626
1614
|
useEffect(
|
|
1627
1615
|
this,
|
|
1628
1616
|
async () => {
|
|
@@ -1637,15 +1625,15 @@ let ShipAidWidget = class extends s {
|
|
|
1637
1625
|
const protectionCartItem = (_c = this._cart) == null ? void 0 : _c.items[protectionCartItemIndex];
|
|
1638
1626
|
this._hasProtectionInCart = !!protectionCartItem;
|
|
1639
1627
|
if (this._cart.item_count === 1 && !!protectionCartItem) {
|
|
1640
|
-
const
|
|
1628
|
+
const removePayload = {
|
|
1641
1629
|
id: protectionCartItem.key,
|
|
1642
1630
|
quantity: 0
|
|
1643
1631
|
};
|
|
1644
|
-
const
|
|
1632
|
+
const cart2 = await this._fetch.post(
|
|
1645
1633
|
"/cart/change.js",
|
|
1646
|
-
|
|
1634
|
+
removePayload
|
|
1647
1635
|
);
|
|
1648
|
-
return await this._handleRefresh(
|
|
1636
|
+
return await this._handleRefresh(cart2);
|
|
1649
1637
|
}
|
|
1650
1638
|
const protectionFee = await this.calculateProtectionTotal(this._cart);
|
|
1651
1639
|
const protectionVariant = this._findProtectionVariant(protectionFee);
|
|
@@ -1665,27 +1653,21 @@ let ShipAidWidget = class extends s {
|
|
|
1665
1653
|
};
|
|
1666
1654
|
if (protectionCartItem.quantity === 1)
|
|
1667
1655
|
return;
|
|
1668
|
-
const
|
|
1656
|
+
const updatePayload2 = {
|
|
1669
1657
|
id: protectionCartItem.key,
|
|
1670
1658
|
quantity: 1
|
|
1671
1659
|
};
|
|
1672
|
-
const
|
|
1673
|
-
return await this._handleRefresh(
|
|
1660
|
+
const cart2 = await this._fetch.post("/cart/change.js", updatePayload2);
|
|
1661
|
+
return await this._handleRefresh(cart2);
|
|
1674
1662
|
}
|
|
1675
|
-
const
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
const addPayload = {
|
|
1681
|
-
quantity: 1,
|
|
1682
|
-
id: protectionVariant.id
|
|
1663
|
+
const updatePayload = {
|
|
1664
|
+
updates: {
|
|
1665
|
+
[protectionCartItem.variant_id]: 0,
|
|
1666
|
+
[protectionVariant.id]: 1
|
|
1667
|
+
}
|
|
1683
1668
|
};
|
|
1684
|
-
const
|
|
1685
|
-
|
|
1686
|
-
addPayload
|
|
1687
|
-
);
|
|
1688
|
-
await this._handleRefresh(cartItem);
|
|
1669
|
+
const cart = await this._fetch.post("/cart/update.js", updatePayload);
|
|
1670
|
+
await this._handleRefresh(cart);
|
|
1689
1671
|
},
|
|
1690
1672
|
[this._store, this._cart]
|
|
1691
1673
|
);
|
|
@@ -1742,9 +1724,6 @@ __decorateClass([
|
|
|
1742
1724
|
__decorateClass([
|
|
1743
1725
|
t$2()
|
|
1744
1726
|
], ShipAidWidget.prototype, "_hasProtectionInCart", 2);
|
|
1745
|
-
__decorateClass([
|
|
1746
|
-
t$2()
|
|
1747
|
-
], ShipAidWidget.prototype, "_lastAction", 2);
|
|
1748
1727
|
__decorateClass([
|
|
1749
1728
|
t$2()
|
|
1750
1729
|
], ShipAidWidget.prototype, "_protectionCartItem", 2);
|
package/dist/widget.iife.js
CHANGED
|
@@ -3,17 +3,17 @@ var ShipAidWidget=function(t){"use strict";
|
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2017 Google LLC
|
|
5
5
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
6
|
-
*/const e=t=>e=>{return"function"==typeof e?(i=t,
|
|
6
|
+
*/const e=t=>e=>{return"function"==typeof e?(i=t,r=e,customElements.define(i,r),r):((t,e)=>{const{kind:i,elements:r}=e;return{kind:i,elements:r,finisher(e){customElements.define(t,e)}}})(t,e);
|
|
7
7
|
/**
|
|
8
8
|
* @license
|
|
9
9
|
* Copyright 2017 Google LLC
|
|
10
10
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
11
|
-
*/var i,
|
|
11
|
+
*/var i,r},i=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(i){i.createProperty(e.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(i){i.createProperty(e.key,t)}};function r(t){return(e,r)=>{return void 0!==r?(o=t,s=r,void e.constructor.createProperty(s,o)):i(t,e);var o,s}}
|
|
12
12
|
/**
|
|
13
13
|
* @license
|
|
14
14
|
* Copyright 2017 Google LLC
|
|
15
15
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
16
|
-
*/function
|
|
16
|
+
*/function o(t){return r({...t,state:!0})}
|
|
17
17
|
/**
|
|
18
18
|
* @license
|
|
19
19
|
* Copyright 2021 Google LLC
|
|
@@ -24,23 +24,23 @@ var ShipAidWidget=function(t){"use strict";
|
|
|
24
24
|
* Copyright 2019 Google LLC
|
|
25
25
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
26
26
|
*/
|
|
27
|
-
const n=window,a=n.ShadowRoot&&(void 0===n.ShadyCSS||n.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,p=Symbol(),l=new WeakMap;class d{constructor(t,e,i){if(this._$cssResult$=!0,i!==p)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(a&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=l.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&l.set(e,t))}return t}toString(){return this.cssText}}const h=(t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,
|
|
27
|
+
const n=window,a=n.ShadowRoot&&(void 0===n.ShadyCSS||n.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,p=Symbol(),l=new WeakMap;class d{constructor(t,e,i){if(this._$cssResult$=!0,i!==p)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(a&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=l.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&l.set(e,t))}return t}toString(){return this.cssText}}const h=(t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,r)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[r+1]),t[0]);return new d(i,t,p)},c=a?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return(t=>new d("string"==typeof t?t:t+"",void 0,p))(e)})(t):t
|
|
28
28
|
/**
|
|
29
29
|
* @license
|
|
30
30
|
* Copyright 2017 Google LLC
|
|
31
31
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
32
|
-
*/;var u;const f=window,v=f.trustedTypes,m=v?v.emptyScript:"",g=f.reactiveElementPolyfillSupport,_={toAttribute(t,e){switch(e){case Boolean:t=t?m:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(
|
|
32
|
+
*/;var u;const f=window,v=f.trustedTypes,m=v?v.emptyScript:"",g=f.reactiveElementPolyfillSupport,_={toAttribute(t,e){switch(e){case Boolean:t=t?m:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(r){i=null}}return i}},C=(t,e)=>e!==t&&(e==e||t==t),y={attribute:!0,type:String,converter:_,reflect:!1,hasChanged:C};class w extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u()}static addInitializer(t){var e;null!==(e=this.h)&&void 0!==e||(this.h=[]),this.h.push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const r=this._$Ep(i,e);void 0!==r&&(this._$Ev.set(r,i),t.push(r))})),t}static createProperty(t,e=y){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,r=this.getPropertyDescriptor(t,i,e);void 0!==r&&Object.defineProperty(this.prototype,t,r)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(r){const o=this[t];this[e]=r,this.requestUpdate(t,o,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||y}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(c(t))}else void 0!==t&&e.push(c(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}u(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,e)=>{a?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),r=n.litNonce;void 0!==r&&i.setAttribute("nonce",r),i.textContent=e.cssText,t.appendChild(i)}))})(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=y){var r;const o=this.constructor._$Ep(t,i);if(void 0!==o&&!0===i.reflect){const s=(void 0!==(null===(r=i.converter)||void 0===r?void 0:r.toAttribute)?i.converter:_).toAttribute(e,i.type);this._$El=t,null==s?this.removeAttribute(o):this.setAttribute(o,s),this._$El=null}}_$AK(t,e){var i;const r=this.constructor,o=r._$Ev.get(t);if(void 0!==o&&this._$El!==o){const t=r.getPropertyOptions(o),s="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:_;this._$El=o,this[o]=s.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let r=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||C)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):r=!1),!this.isUpdatePending&&r&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(r){throw e=!1,this._$Ek(),r}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}}
|
|
33
33
|
/**
|
|
34
34
|
* @license
|
|
35
35
|
* Copyright 2017 Google LLC
|
|
36
36
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
37
37
|
*/
|
|
38
|
-
var $;w.finalized=!0,w.elementProperties=new Map,w.elementStyles=[],w.shadowRootOptions={mode:"open"},null==g||g({ReactiveElement:w}),(null!==(u=f.reactiveElementVersions)&&void 0!==u?u:f.reactiveElementVersions=[]).push("1.4.1");const b=window,L=b.trustedTypes,A=L?L.createPolicy("lit-html",{createHTML:t=>t}):void 0,S=`lit$${(Math.random()+"").slice(9)}$`,x="?"+S,E=`<${x}>`,P=document,k=(t="")=>P.createComment(t),M=t=>null===t||"object"!=typeof t&&"function"!=typeof t,T=Array.isArray,U=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,O=/-->/g,z=/>/g,N=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),R=/'/g,I=/"/g,W=/^(?:script|style|textarea|title)$/i,j=(Z=1,(t,...e)=>({_$litType$:Z,strings:t,values:e})),H=Symbol.for("lit-noChange"),D=Symbol.for("lit-nothing"),B=new WeakMap,F=P.createTreeWalker(P,129,null,!1);var Z;class q{constructor({strings:t,_$litType$:e},i){let
|
|
38
|
+
var $;w.finalized=!0,w.elementProperties=new Map,w.elementStyles=[],w.shadowRootOptions={mode:"open"},null==g||g({ReactiveElement:w}),(null!==(u=f.reactiveElementVersions)&&void 0!==u?u:f.reactiveElementVersions=[]).push("1.4.1");const b=window,L=b.trustedTypes,A=L?L.createPolicy("lit-html",{createHTML:t=>t}):void 0,S=`lit$${(Math.random()+"").slice(9)}$`,x="?"+S,E=`<${x}>`,P=document,k=(t="")=>P.createComment(t),M=t=>null===t||"object"!=typeof t&&"function"!=typeof t,T=Array.isArray,U=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,O=/-->/g,z=/>/g,N=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),R=/'/g,I=/"/g,W=/^(?:script|style|textarea|title)$/i,j=(Z=1,(t,...e)=>({_$litType$:Z,strings:t,values:e})),H=Symbol.for("lit-noChange"),D=Symbol.for("lit-nothing"),B=new WeakMap,F=P.createTreeWalker(P,129,null,!1);var Z;class q{constructor({strings:t,_$litType$:e},i){let r;this.parts=[];let o=0,s=0;const n=t.length-1,a=this.parts,[p,l]=((t,e)=>{const i=t.length-1,r=[];let o,s=2===e?"<svg>":"",n=U;for(let p=0;p<i;p++){const e=t[p];let i,a,l=-1,d=0;for(;d<e.length&&(n.lastIndex=d,a=n.exec(e),null!==a);)d=n.lastIndex,n===U?"!--"===a[1]?n=O:void 0!==a[1]?n=z:void 0!==a[2]?(W.test(a[2])&&(o=RegExp("</"+a[2],"g")),n=N):void 0!==a[3]&&(n=N):n===N?">"===a[0]?(n=null!=o?o:U,l=-1):void 0===a[1]?l=-2:(l=n.lastIndex-a[2].length,i=a[1],n=void 0===a[3]?N:'"'===a[3]?I:R):n===I||n===R?n=N:n===O||n===z?n=U:(n=N,o=void 0);const h=n===N&&t[p+1].startsWith("/>")?" ":"";s+=n===U?e+E:l>=0?(r.push(i),e.slice(0,l)+"$lit$"+e.slice(l)+S+h):e+S+(-2===l?(r.push(void 0),p):h)}const a=s+(t[i]||"<?>")+(2===e?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==A?A.createHTML(a):a,r]})(t,e);if(this.el=q.createElement(p,i),F.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(r=F.nextNode())&&a.length<n;){if(1===r.nodeType){if(r.hasAttributes()){const t=[];for(const e of r.getAttributeNames())if(e.endsWith("$lit$")||e.startsWith(S)){const i=l[s++];if(t.push(e),void 0!==i){const t=r.getAttribute(i.toLowerCase()+"$lit$").split(S),e=/([.?@])?(.*)/.exec(i);a.push({type:1,index:o,name:e[2],strings:t,ctor:"."===e[1]?Y:"?"===e[1]?Q:"@"===e[1]?tt:K})}else a.push({type:6,index:o})}for(const e of t)r.removeAttribute(e)}if(W.test(r.tagName)){const t=r.textContent.split(S),e=t.length-1;if(e>0){r.textContent=L?L.emptyScript:"";for(let i=0;i<e;i++)r.append(t[i],k()),F.nextNode(),a.push({type:2,index:++o});r.append(t[e],k())}}}else if(8===r.nodeType)if(r.data===x)a.push({type:2,index:o});else{let t=-1;for(;-1!==(t=r.data.indexOf(S,t+1));)a.push({type:7,index:o}),t+=S.length-1}o++}}static createElement(t,e){const i=P.createElement("template");return i.innerHTML=t,i}}function V(t,e,i=t,r){var o,s,n,a;if(e===H)return e;let p=void 0!==r?null===(o=i._$Co)||void 0===o?void 0:o[r]:i._$Cl;const l=M(e)?void 0:e._$litDirective$;return(null==p?void 0:p.constructor)!==l&&(null===(s=null==p?void 0:p._$AO)||void 0===s||s.call(p,!1),void 0===l?p=void 0:(p=new l(t),p._$AT(t,i,r)),void 0!==r?(null!==(n=(a=i)._$Co)&&void 0!==n?n:a._$Co=[])[r]=p:i._$Cl=p),void 0!==p&&(e=V(t,p._$AS(t,e.values),p,r)),e}class J{constructor(t,e){this.u=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}v(t){var e;const{el:{content:i},parts:r}=this._$AD,o=(null!==(e=null==t?void 0:t.creationScope)&&void 0!==e?e:P).importNode(i,!0);F.currentNode=o;let s=F.nextNode(),n=0,a=0,p=r[0];for(;void 0!==p;){if(n===p.index){let e;2===p.type?e=new G(s,s.nextSibling,this,t):1===p.type?e=new p.ctor(s,p.name,p.strings,this,t):6===p.type&&(e=new et(s,this,t)),this.u.push(e),p=r[++a]}n!==(null==p?void 0:p.index)&&(s=F.nextNode(),n++)}return o}p(t){let e=0;for(const i of this.u)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class G{constructor(t,e,i,r){var o;this.type=2,this._$AH=D,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=r,this._$Cm=null===(o=null==r?void 0:r.isConnected)||void 0===o||o}get _$AU(){var t,e;return null!==(e=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==e?e:this._$Cm}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=V(this,t,e),M(t)?t===D||null==t||""===t?(this._$AH!==D&&this._$AR(),this._$AH=D):t!==this._$AH&&t!==H&&this.g(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):(t=>T(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]))(t)?this.k(t):this.g(t)}O(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}g(t){this._$AH!==D&&M(this._$AH)?this._$AA.nextSibling.data=t:this.T(P.createTextNode(t)),this._$AH=t}$(t){var e;const{values:i,_$litType$:r}=t,o="number"==typeof r?this._$AC(t):(void 0===r.el&&(r.el=q.createElement(r.h,this.options)),r);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===o)this._$AH.p(i);else{const t=new J(o,this),e=t.v(this.options);t.p(i),this.T(e),this._$AH=t}}_$AC(t){let e=B.get(t.strings);return void 0===e&&B.set(t.strings,e=new q(t)),e}k(t){T(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,r=0;for(const o of t)r===e.length?e.push(i=new G(this.O(k()),this.O(k()),this,this.options)):i=e[r],i._$AI(o),r++;r<e.length&&(this._$AR(i&&i._$AB.nextSibling,r),e.length=r)}_$AR(t=this._$AA.nextSibling,e){var i;for(null===(i=this._$AP)||void 0===i||i.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$Cm=t,null===(e=this._$AP)||void 0===e||e.call(this,t))}}class K{constructor(t,e,i,r,o){this.type=1,this._$AH=D,this._$AN=void 0,this.element=t,this.name=e,this._$AM=r,this.options=o,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=D}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,r){const o=this.strings;let s=!1;if(void 0===o)t=V(this,t,e,0),s=!M(t)||t!==this._$AH&&t!==H,s&&(this._$AH=t);else{const r=t;let n,a;for(t=o[0],n=0;n<o.length-1;n++)a=V(this,r[i+n],e,n),a===H&&(a=this._$AH[n]),s||(s=!M(a)||a!==this._$AH[n]),a===D?t=D:t!==D&&(t+=(null!=a?a:"")+o[n+1]),this._$AH[n]=a}s&&!r&&this.j(t)}j(t){t===D?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class Y extends K{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===D?void 0:t}}const X=L?L.emptyScript:"";class Q extends K{constructor(){super(...arguments),this.type=4}j(t){t&&t!==D?this.element.setAttribute(this.name,X):this.element.removeAttribute(this.name)}}class tt extends K{constructor(t,e,i,r,o){super(t,e,i,r,o),this.type=5}_$AI(t,e=this){var i;if((t=null!==(i=V(this,t,e,0))&&void 0!==i?i:D)===H)return;const r=this._$AH,o=t===D&&r!==D||t.capture!==r.capture||t.once!==r.once||t.passive!==r.passive,s=t!==D&&(r===D||o);o&&this.element.removeEventListener(this.name,this,r),s&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;"function"==typeof this._$AH?this._$AH.call(null!==(i=null===(e=this.options)||void 0===e?void 0:e.host)&&void 0!==i?i:this.element,t):this._$AH.handleEvent(t)}}class et{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){V(this,t)}}const it=b.litHtmlPolyfillSupport;null==it||it(q,G),(null!==($=b.litHtmlVersions)&&void 0!==$?$:b.litHtmlVersions=[]).push("2.4.0");const rt=(t,e,i)=>{var r,o;const s=null!==(r=null==i?void 0:i.renderBefore)&&void 0!==r?r:e;let n=s._$litPart$;if(void 0===n){const t=null!==(o=null==i?void 0:i.renderBefore)&&void 0!==o?o:null;s._$litPart$=n=new G(e.insertBefore(k(),t),t,void 0,null!=i?i:{})}return n._$AI(t),n};
|
|
39
39
|
/**
|
|
40
40
|
* @license
|
|
41
41
|
* Copyright 2017 Google LLC
|
|
42
42
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
43
|
-
*/var
|
|
43
|
+
*/var ot,st;class nt extends w{constructor(){super(...arguments),this.renderOptions={host:this},this._$Dt=void 0}createRenderRoot(){var t,e;const i=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=i.firstChild),i}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Dt=rt(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!1)}render(){return H}}nt.finalized=!0,nt._$litElement$=!0,null===(ot=globalThis.litElementHydrateSupport)||void 0===ot||ot.call(globalThis,{LitElement:nt});const at=globalThis.litElementPolyfillSupport;null==at||at({LitElement:nt}),(null!==(st=globalThis.litElementVersions)&&void 0!==st?st:globalThis.litElementVersions=[]).push("3.2.0");const pt="__registered_effects";function lt(t){const e=t;if(e[pt])return e;const i=function(t){if(!t.dispatchEvent||!t.requestUpdate)throw new Error("Element missing required functions (dispatchEvent/requestUpdate)");return t}(t),r=i.updated;return e[pt]={index:0,count:0,effects:[]},i.updated=t=>(e[pt].index=0,r(t)),e}function dt(t,e,i){const r=function(t,e){const i=lt(t),{index:r,count:o}=i[pt];return r===o?(i[pt].index++,i[pt].count++,i[pt].effects.push(e),e):(i[pt].index++,i[pt].effects[r])}(t,{on:e,observe:["__initial__dirty"]});r.observe.some(((t,e)=>i[e]!==t))&&r.on(),r.observe=i}
|
|
44
44
|
/**
|
|
45
45
|
* @license
|
|
46
46
|
* Copyright 2021 Google LLC
|
|
@@ -64,7 +64,8 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
64
64
|
--shipaid-font-heavy: 700;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
p,
|
|
67
|
+
p,
|
|
68
|
+
a {
|
|
68
69
|
font-family: var(--shipaid-font);
|
|
69
70
|
font-weight: var(--shipaid-font-regular);
|
|
70
71
|
font-size: var(--shipaid-font-base);
|
|
@@ -82,7 +83,7 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
82
83
|
max-height: 80vh;
|
|
83
84
|
height: fit-content;
|
|
84
85
|
border: var(--shipaid-popup-border, var(--shipaid-light-grey)) 1px solid;
|
|
85
|
-
background-color:var(--shipaid-popup-background, #fff);
|
|
86
|
+
background-color: var(--shipaid-popup-background, #fff);
|
|
86
87
|
z-index: 1000000000;
|
|
87
88
|
overflow: auto;
|
|
88
89
|
visibility: hidden;
|
|
@@ -102,9 +103,11 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
102
103
|
|
|
103
104
|
@media (max-width: 600px) {
|
|
104
105
|
.shipaid-popup {
|
|
105
|
-
width:
|
|
106
|
+
width: auto;
|
|
106
107
|
height: 100vh;
|
|
107
108
|
padding: 3rem;
|
|
109
|
+
margin-left: 20px;
|
|
110
|
+
margin-right: 20px;
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
113
|
|
|
@@ -174,7 +177,7 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
174
177
|
font-size: var(--shipaid-font-sm);
|
|
175
178
|
color: var(--shipaid-text);
|
|
176
179
|
}
|
|
177
|
-
`;var ut=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,vt=(t,e,i,
|
|
180
|
+
`;var ut=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,vt=(t,e,i,r)=>{for(var o,s=r>1?void 0:r?ft(e,i):e,n=t.length-1;n>=0;n--)(o=t[n])&&(s=(r?o(e,i,s):o(s))||s);return r&&s&&ut(e,i,s),s};let mt=class extends nt{constructor(){super(...arguments),this.active=!1}handleClosePopup(){const t=new Event("close");this.dispatchEvent(t)}render(){return j`
|
|
178
181
|
<div class=${`shipaid-popup ${this.active&&"active"}`}>
|
|
179
182
|
<button
|
|
180
183
|
type="button"
|
|
@@ -238,7 +241,7 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
238
241
|
</div>
|
|
239
242
|
</div>
|
|
240
243
|
</div>
|
|
241
|
-
`}};mt.styles=ct,vt([
|
|
244
|
+
`}};mt.styles=ct,vt([r({type:Boolean,attribute:!0})],mt.prototype,"active",2),mt=vt([e("shipaid-popup-learn-more")],mt);const gt=h`
|
|
242
245
|
:host {
|
|
243
246
|
--shipaid-primary: #002bd6;
|
|
244
247
|
--shipaid-secondary: #0076ff;
|
|
@@ -515,7 +518,7 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
515
518
|
/>
|
|
516
519
|
</g>
|
|
517
520
|
</svg>
|
|
518
|
-
`;var wt=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(wt||{}),$t=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,Lt=(t,e,i,
|
|
521
|
+
`;var wt=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(wt||{}),$t=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,Lt=(t,e,i,r)=>{for(var o,s=r>1?void 0:r?bt(e,i):e,n=t.length-1;n>=0;n--)(o=t[n])&&(s=(r?o(e,i,s):o(s))||s);return r&&s&&$t(e,i,s),s};const At=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},St=t=>console.warn(`[ShipAid] ${t}`),xt=t=>console.error(`[ShipAid] ${t}`),Et="shipaid-protection";return t.ShipAidWidget=class extends nt{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this.disableRefresh=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>At(t),post:(t,e)=>At(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}get shouldRefreshOnUpdate(){return!this.disablePolling&&!this.disableRefresh}get planActive(){var t,e;const{searchParams:i}=new URL(window.location.href);return(null==(t=window.Shopify)?void 0:t.designMode)||i.has("shipaid-test")?(St("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,r,o,s;return new Intl.NumberFormat(null!=(i=null==(e=window.Shopify)?void 0:e.locale)?i:void 0,{currency:(null==(r=this._store)?void 0:r.currency)||(null==(s=null==(o=window.Shopify)?void 0:o.currency)?void 0:s.active)||"USD",style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(wt.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){var e,i,r,o,s;if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const n=null==(e=this._store)?void 0:e.protectionSettings;if(!n||!this._protectionProduct)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const a=((null==(i=this._store)?void 0:i.excludedProductSkus)&&t.items?t.items.reduce(((t,e)=>{if(!e.sku)return t;return this._store.excludedProductSkus.find((t=>t===e.sku))?t-e.final_price:t}),t.total_price):t.total_price)-(null!=(o=null==(r=t.items)?void 0:r.filter((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})))?o:[]).reduce(((t,e)=>t+=e.final_line_price),0);if("FIXED"===n.protectionType){if("number"!=typeof n.defaultFee)throw new Error("Missing default fee amount.");if(!(null==(s=n.rules)?void 0:s.length))return n.defaultFee;const t=a/100,e=n.rules.sort(((t,e)=>t.rangeLower&&e.rangeLower?t.rangeLower-e.rangeLower:0)).find((e=>{const i=Boolean(e.rangeLower&&e.rangeLower<t);return e.rangeUpper?i&&e.rangeUpper>=t:i}));return"number"==typeof(null==e?void 0:e.fee)?e.fee:n.defaultFee}if("PERCENTAGE"===n.protectionType){const t=a*n.percentage/100;return t>=n.minimumFee?t:n.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(t){var e,i,r,o;if(!(null==(e=this._store)?void 0:e.protectionSettings)||!(null==(r=null==(i=this._protectionProduct)?void 0:i.variants)?void 0:r.length))throw new Error("Missing product and variants from protection settings.");const s=null==(o=this._protectionProduct)?void 0:o.variants.flatMap((t=>{if(!t||!t.price)return[];const e=Number(t.price);return[{...t,formattedPrice:e}]})).sort(((t,e)=>t.formattedPrice-e.formattedPrice)),n=s.find((e=>e.formattedPrice>=t));return n||s[s.length-1]}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){var t,e,i;const r=null==(t=window.Shopify)?void 0:t.shop;if(!r)throw new Error("No shop found in Shopify object.");try{const t=new URL(window.location.href);t.pathname=this._apiEndpoint;const o={query:"query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetShowCart\n excludedProductSkus\n protectionSettings\n }\n}",variables:{store:r}},s=await this._fetch.post(t.toString(),o);if(!s)throw new Error("Missing response for store query.");if(null==(e=s.errors)?void 0:e.length)throw new Error(s.errors[0].message);if(!(null==(i=s.data)?void 0:i.store))throw new Error("Missing store from store query response.");return s.data.store}catch(o){throw console.error(o),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(t){throw xt(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){try{const{product:t}=await this._fetch.get("/products/shipaid-protection.json");return t}catch(t){throw xt(t.message),new Error("Could not fetch protection product for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addProtection(){var t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!(null==(t=this._cart)?void 0:t.items))throw new Error("Cart has not been loaded.");if(!(null==(e=this._protectionVariant)?void 0:e.id))throw new Error("No protection variant found.");this._setState("loading");const i={quantity:1,id:this._protectionVariant.id},r=await this._fetch.post("/cart/add.js",i);await this._handleRefresh(r),this._setState("success")}catch(i){xt(i.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const t={quantity:0,id:this._protectionCartItem.key},e=await this._fetch.post("/cart/change.js",t);await this._handleRefresh(e),this._cart=e,this._setState("success")}catch(t){xt(t.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}learnMorePopupTemplate(){return j`
|
|
519
522
|
<shipaid-popup-learn-more ?active=${"learn-more"===this._popup} @close=${()=>{this._popup=null}}></shipaid-popup-learn-more>
|
|
520
523
|
`}promptTemplate(){var t;return j`
|
|
521
524
|
<div class="shipaid-prompt">
|
|
@@ -561,8 +564,8 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
561
564
|
</button>
|
|
562
565
|
</div>
|
|
563
566
|
</div>
|
|
564
|
-
`}render(){return dt(this,(async()=>{var t,e;const i=document.createElement("link");i.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),i.setAttribute("rel","stylesheet"),document.head.appendChild(i);try{const
|
|
567
|
+
`}render(){return dt(this,(async()=>{var t,e;const i=document.createElement("link");i.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),i.setAttribute("rel","stylesheet"),document.head.appendChild(i);try{const[t,e,i]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=t,this._cart=e,this._protectionProduct=i}catch(r){return this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return this.planActive?(null==(e=null==(t=this._store)?void 0:t.protectionSettings)?void 0:e.protectionType)?this._protectionProduct?(this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(wt.LOADED,this._store),setTimeout((async()=>{var t,e,i;(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&(null==(e=this._cart)?void 0:e.item_count)&&(sessionStorage.getItem(Et)||(sessionStorage.setItem(Et,JSON.stringify({loaded:!0})),!this._hasProtectionInCart&&(null==(i=this._cart)?void 0:i.item_count)&&this._store.widgetShowCart&&await this.addProtection()))}),500),void(this.disablePolling||setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval))):(St("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(St("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(St("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))}),[]),dt(this,(async()=>{var t,e,i;if(this._cartLastUpdated=new Date,!(null==(t=this._cart)?void 0:t.items))return;const r=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),o=null==(i=this._cart)?void 0:i.items[r];if(this._hasProtectionInCart=!!o,1===this._cart.item_count&&o){const t={id:o.key,quantity:0},e=await this._fetch.post("/cart/change.js",t);return await this._handleRefresh(e)}const s=await this.calculateProtectionTotal(this._cart),n=this._findProtectionVariant(s);if(this._protectionVariant=n,!(null==n?void 0:n.id))return this._shouldShowWidget=!1,void xt("No matching protection variant found.");if(!o)return;if(n.id===o.id){if(this._protectionCartItem={...o,index:r,position:r+1},1===o.quantity)return;const t={id:o.key,quantity:1},e=await this._fetch.post("/cart/change.js",t);return await this._handleRefresh(e)}const a={updates:{[o.variant_id]:0,[n.id]:1}},p=await this._fetch.post("/cart/update.js",a);await this._handleRefresh(p)}),[this._store,this._cart]),rt(this.learnMorePopupTemplate(),document.body),j`
|
|
565
568
|
<div class="shipaid">
|
|
566
569
|
${ht(this._hasFinishedSetup,(()=>{var t;return ht(this._shouldShowWidget&&this.planActive&&(null==(t=this._store)?void 0:t.widgetShowCart),(()=>this.promptTemplate()),(()=>D))}),(()=>j`<p><slot name="loading" default>Loading ShipAid Widget...</slot></p>`))}
|
|
567
570
|
</div>
|
|
568
|
-
`}},t.ShipAidWidget.styles=gt,Lt([
|
|
571
|
+
`}},t.ShipAidWidget.styles=gt,Lt([r({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disablePolling",2),Lt([r({type:Number,attribute:!0})],t.ShipAidWidget.prototype,"pollingInterval",2),Lt([r({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disableRefresh",2),Lt([o()],t.ShipAidWidget.prototype,"_storeDomain",2),Lt([o()],t.ShipAidWidget.prototype,"_store",2),Lt([o()],t.ShipAidWidget.prototype,"_cart",2),Lt([o()],t.ShipAidWidget.prototype,"_protectionProduct",2),Lt([o()],t.ShipAidWidget.prototype,"_cartLastUpdated",2),Lt([o()],t.ShipAidWidget.prototype,"_hasFinishedSetup",2),Lt([o()],t.ShipAidWidget.prototype,"_shouldShowWidget",2),Lt([o()],t.ShipAidWidget.prototype,"_hasProtectionInCart",2),Lt([o()],t.ShipAidWidget.prototype,"_protectionCartItem",2),Lt([o()],t.ShipAidWidget.prototype,"_protectionVariant",2),Lt([o()],t.ShipAidWidget.prototype,"_state",2),Lt([o()],t.ShipAidWidget.prototype,"_popup",2),t.ShipAidWidget=Lt([e("shipaid-widget")],t.ShipAidWidget),Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),t}({});
|
package/dist/widget.umd.js
CHANGED
|
@@ -29,7 +29,7 @@ const n=window,a=n.ShadowRoot&&(void 0===n.ShadyCSS||n.ShadyCSS.nativeShadow)&&"
|
|
|
29
29
|
* @license
|
|
30
30
|
* Copyright 2017 Google LLC
|
|
31
31
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
32
|
-
*/;var u;const f=window,v=f.trustedTypes,m=v?v.emptyScript:"",g=f.reactiveElementPolyfillSupport,_={toAttribute(t,e){switch(e){case Boolean:t=t?m:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(o){i=null}}return i}},
|
|
32
|
+
*/;var u;const f=window,v=f.trustedTypes,m=v?v.emptyScript:"",g=f.reactiveElementPolyfillSupport,_={toAttribute(t,e){switch(e){case Boolean:t=t?m:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(o){i=null}}return i}},C=(t,e)=>e!==t&&(e==e||t==t),y={attribute:!0,type:String,converter:_,reflect:!1,hasChanged:C};class w extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u()}static addInitializer(t){var e;null!==(e=this.h)&&void 0!==e||(this.h=[]),this.h.push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const o=this._$Ep(i,e);void 0!==o&&(this._$Ev.set(o,i),t.push(o))})),t}static createProperty(t,e=y){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,o=this.getPropertyDescriptor(t,i,e);void 0!==o&&Object.defineProperty(this.prototype,t,o)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(o){const r=this[t];this[e]=o,this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||y}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(c(t))}else void 0!==t&&e.push(c(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}u(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,e)=>{a?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),o=n.litNonce;void 0!==o&&i.setAttribute("nonce",o),i.textContent=e.cssText,t.appendChild(i)}))})(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=y){var o;const r=this.constructor._$Ep(t,i);if(void 0!==r&&!0===i.reflect){const s=(void 0!==(null===(o=i.converter)||void 0===o?void 0:o.toAttribute)?i.converter:_).toAttribute(e,i.type);this._$El=t,null==s?this.removeAttribute(r):this.setAttribute(r,s),this._$El=null}}_$AK(t,e){var i;const o=this.constructor,r=o._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=o.getPropertyOptions(r),s="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:_;this._$El=r,this[r]=s.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let o=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||C)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):o=!1),!this.isUpdatePending&&o&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(o){throw e=!1,this._$Ek(),o}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}}
|
|
33
33
|
/**
|
|
34
34
|
* @license
|
|
35
35
|
* Copyright 2017 Google LLC
|
|
@@ -64,7 +64,8 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
64
64
|
--shipaid-font-heavy: 700;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
p,
|
|
67
|
+
p,
|
|
68
|
+
a {
|
|
68
69
|
font-family: var(--shipaid-font);
|
|
69
70
|
font-weight: var(--shipaid-font-regular);
|
|
70
71
|
font-size: var(--shipaid-font-base);
|
|
@@ -82,7 +83,7 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
82
83
|
max-height: 80vh;
|
|
83
84
|
height: fit-content;
|
|
84
85
|
border: var(--shipaid-popup-border, var(--shipaid-light-grey)) 1px solid;
|
|
85
|
-
background-color:var(--shipaid-popup-background, #fff);
|
|
86
|
+
background-color: var(--shipaid-popup-background, #fff);
|
|
86
87
|
z-index: 1000000000;
|
|
87
88
|
overflow: auto;
|
|
88
89
|
visibility: hidden;
|
|
@@ -102,9 +103,11 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
102
103
|
|
|
103
104
|
@media (max-width: 600px) {
|
|
104
105
|
.shipaid-popup {
|
|
105
|
-
width:
|
|
106
|
+
width: auto;
|
|
106
107
|
height: 100vh;
|
|
107
108
|
padding: 3rem;
|
|
109
|
+
margin-left: 20px;
|
|
110
|
+
margin-right: 20px;
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
113
|
|
|
@@ -391,7 +394,7 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
391
394
|
<path d="M256.01,120.969C286.193,120.969 314.057,130.87 336.536,147.604L309.406,174.656C294.073,164.573 275.729,158.708 256.01,158.708C229.141,158.708 204.823,169.604 187.214,187.198C169.615,204.797 158.719,229.125 158.719,255.995C158.719,282.865 169.615,307.182 187.214,324.792C204.813,342.406 229.141,353.286 256.01,353.286C282.88,353.286 307.208,342.406 324.807,324.792C342.406,307.193 353.297,282.865 353.297,255.995C353.297,251.818 353.036,247.719 352.526,243.688L383.859,212.458C388.51,226.115 391.036,240.766 391.036,255.995C391.036,293.286 375.927,327.047 351.49,351.479C327.057,375.911 293.302,391.021 256.01,391.021C218.729,391.021 184.964,375.911 160.526,351.479C136.094,327.047 120.984,293.286 120.984,255.995C120.984,218.719 136.094,184.948 160.526,160.516C184.964,136.083 218.719,120.969 256.01,120.969ZM218.141,220.906L253.615,259.729L354.844,158.813L381.375,185.484L252.396,314.068L190.422,246.255L218.13,220.906L218.141,220.906Z" style="fill:white;fill-rule:nonzero;"/>
|
|
392
395
|
</g>
|
|
393
396
|
</svg>
|
|
394
|
-
`,
|
|
397
|
+
`,Ct=j`
|
|
395
398
|
<svg
|
|
396
399
|
viewBox="0 0 384 383.999986"
|
|
397
400
|
preserveAspectRatio="xMidYMid meet"
|
|
@@ -433,7 +436,7 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
433
436
|
/>
|
|
434
437
|
</g>
|
|
435
438
|
</svg>
|
|
436
|
-
`,
|
|
439
|
+
`,yt=j`
|
|
437
440
|
<svg
|
|
438
441
|
viewBox="0 0 423 62"
|
|
439
442
|
version="1.1"
|
|
@@ -515,13 +518,13 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
515
518
|
/>
|
|
516
519
|
</g>
|
|
517
520
|
</svg>
|
|
518
|
-
`;var wt=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(wt||{}),$t=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,Lt=(t,e,i,o)=>{for(var r,s=o>1?void 0:o?bt(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(s=(o?r(e,i,s):r(s))||s);return o&&s&&$t(e,i,s),s};const At=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},St=t=>console.warn(`[ShipAid] ${t}`),xt=t=>console.error(`[ShipAid] ${t}`),Et="shipaid-protection";t.ShipAidWidget=class extends nt{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this.disableRefresh=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>At(t),post:(t,e)=>At(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}get shouldRefreshOnUpdate(){return!this.disablePolling&&!this.disableRefresh}get planActive(){var t,e;const{searchParams:i}=new URL(window.location.href);return(null==(t=window.Shopify)?void 0:t.designMode)||i.has("shipaid-test")?(St("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,o,r,s;return new Intl.NumberFormat(null!=(i=null==(e=window.Shopify)?void 0:e.locale)?i:void 0,{currency:(null==(o=this._store)?void 0:o.currency)||(null==(s=null==(r=window.Shopify)?void 0:r.currency)?void 0:s.active)||"USD",style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(wt.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){var e,i,o,r,s;if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const n=null==(e=this._store)?void 0:e.protectionSettings;if(!n||!this._protectionProduct)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const a=((null==(i=this._store)?void 0:i.excludedProductSkus)&&t.items?t.items.reduce(((t,e)=>{if(!e.sku)return t;return this._store.excludedProductSkus.find((t=>t===e.sku))?t-e.final_price:t}),t.total_price):t.total_price)-(null!=(r=null==(o=t.items)?void 0:o.filter((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})))?r:[]).reduce(((t,e)=>t+=e.final_line_price),0);if("FIXED"===n.protectionType){if("number"!=typeof n.defaultFee)throw new Error("Missing default fee amount.");if(!(null==(s=n.rules)?void 0:s.length))return n.defaultFee;const t=a/100,e=n.rules.sort(((t,e)=>t.rangeLower&&e.rangeLower?t.rangeLower-e.rangeLower:0)).find((e=>{const i=Boolean(e.rangeLower&&e.rangeLower<t);return e.rangeUpper?i&&e.rangeUpper>=t:i}));return"number"==typeof(null==e?void 0:e.fee)?e.fee:n.defaultFee}if("PERCENTAGE"===n.protectionType){const t=a*n.percentage/100;return t>=n.minimumFee?t:n.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(t){var e,i,o,r;if(!(null==(e=this._store)?void 0:e.protectionSettings)||!(null==(o=null==(i=this._protectionProduct)?void 0:i.variants)?void 0:o.length))throw new Error("Missing product and variants from protection settings.");const s=null==(r=this._protectionProduct)?void 0:r.variants.flatMap((t=>{if(!t||!t.price)return[];const e=Number(t.price);return[{...t,formattedPrice:e}]})).sort(((t,e)=>t.formattedPrice-e.formattedPrice)),n=s.find((e=>e.formattedPrice>=t));return n||s[s.length-1]}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){var t,e,i;const o=null==(t=window.Shopify)?void 0:t.shop;if(!o)throw new Error("No shop found in Shopify object.");try{const t=new URL(window.location.href);t.pathname=this._apiEndpoint;const r={query:"query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetShowCart\n excludedProductSkus\n protectionSettings\n }\n}",variables:{store:o}},s=await this._fetch.post(t.toString(),r);if(!s)throw new Error("Missing response for store query.");if(null==(e=s.errors)?void 0:e.length)throw new Error(s.errors[0].message);if(!(null==(i=s.data)?void 0:i.store))throw new Error("Missing store from store query response.");return s.data.store}catch(r){throw console.error(r),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(t){throw xt(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){try{const{product:t}=await this._fetch.get("/products/shipaid-protection.json");return t}catch(t){throw xt(t.message),new Error("Could not fetch protection product for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addProtection(){var t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!(null==(t=this._cart)?void 0:t.items))throw new Error("Cart has not been loaded.");if(!(null==(e=this._protectionVariant)?void 0:e.id))throw new Error("No protection variant found.");this._setState("loading");const i={quantity:1,id:this._protectionVariant.id},o=await this._fetch.post("/cart/add.js",i);await this._handleRefresh(o),this.
|
|
521
|
+
`;var wt=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(wt||{}),$t=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,Lt=(t,e,i,o)=>{for(var r,s=o>1?void 0:o?bt(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(s=(o?r(e,i,s):r(s))||s);return o&&s&&$t(e,i,s),s};const At=async(t,e)=>{try{const i=await fetch(t,e);if(!i.ok)throw new Error(await i.text());return await i.json()}catch(i){throw console.error(i),new Error("Failed to complete fetch request.")}},St=t=>console.warn(`[ShipAid] ${t}`),xt=t=>console.error(`[ShipAid] ${t}`),Et="shipaid-protection";t.ShipAidWidget=class extends nt{constructor(){var t;super(...arguments),this.disablePolling=!1,this.pollingInterval=2500,this.disableRefresh=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=null==(t=window.Shopify)?void 0:t.shop,this._hasFinishedSetup=!1,this._shouldShowWidget=!0,this._hasProtectionInCart=!1,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>At(t),post:(t,e)=>At(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}get shouldRefreshOnUpdate(){return!this.disablePolling&&!this.disableRefresh}get planActive(){var t,e;const{searchParams:i}=new URL(window.location.href);return(null==(t=window.Shopify)?void 0:t.designMode)||i.has("shipaid-test")?(St("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,o,r,s;return new Intl.NumberFormat(null!=(i=null==(e=window.Shopify)?void 0:e.locale)?i:void 0,{currency:(null==(o=this._store)?void 0:o.currency)||(null==(s=null==(r=window.Shopify)?void 0:r.currency)?void 0:s.active)||"USD",style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(wt.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){var e,i,o,r,s;if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing store settings.");const n=null==(e=this._store)?void 0:e.protectionSettings;if(!n||!this._protectionProduct)throw new Error("Tried to find protection variant, but protection settings for this store are missing.");const a=((null==(i=this._store)?void 0:i.excludedProductSkus)&&t.items?t.items.reduce(((t,e)=>{if(!e.sku)return t;return this._store.excludedProductSkus.find((t=>t===e.sku))?t-e.final_price:t}),t.total_price):t.total_price)-(null!=(r=null==(o=t.items)?void 0:o.filter((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})))?r:[]).reduce(((t,e)=>t+=e.final_line_price),0);if("FIXED"===n.protectionType){if("number"!=typeof n.defaultFee)throw new Error("Missing default fee amount.");if(!(null==(s=n.rules)?void 0:s.length))return n.defaultFee;const t=a/100,e=n.rules.sort(((t,e)=>t.rangeLower&&e.rangeLower?t.rangeLower-e.rangeLower:0)).find((e=>{const i=Boolean(e.rangeLower&&e.rangeLower<t);return e.rangeUpper?i&&e.rangeUpper>=t:i}));return"number"==typeof(null==e?void 0:e.fee)?e.fee:n.defaultFee}if("PERCENTAGE"===n.protectionType){const t=a*n.percentage/100;return t>=n.minimumFee?t:n.minimumFee}throw new Error("No protection type handler found for this store.")}_findProtectionVariant(t){var e,i,o,r;if(!(null==(e=this._store)?void 0:e.protectionSettings)||!(null==(o=null==(i=this._protectionProduct)?void 0:i.variants)?void 0:o.length))throw new Error("Missing product and variants from protection settings.");const s=null==(r=this._protectionProduct)?void 0:r.variants.flatMap((t=>{if(!t||!t.price)return[];const e=Number(t.price);return[{...t,formattedPrice:e}]})).sort(((t,e)=>t.formattedPrice-e.formattedPrice)),n=s.find((e=>e.formattedPrice>=t));return n||s[s.length-1]}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}async _updateProtection(){return this._hasProtectionInCart?this.removeProtection():this.addProtection()}async _fetchShipAidData(){var t,e,i;const o=null==(t=window.Shopify)?void 0:t.shop;if(!o)throw new Error("No shop found in Shopify object.");try{const t=new URL(window.location.href);t.pathname=this._apiEndpoint;const r={query:"query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetShowCart\n excludedProductSkus\n protectionSettings\n }\n}",variables:{store:o}},s=await this._fetch.post(t.toString(),r);if(!s)throw new Error("Missing response for store query.");if(null==(e=s.errors)?void 0:e.length)throw new Error(s.errors[0].message);if(!(null==(i=s.data)?void 0:i.store))throw new Error("Missing store from store query response.");return s.data.store}catch(r){throw console.error(r),new Error(`Could not find a store for ${this._storeDomain}`)}}async _fetchCart(){try{return await this._fetch.get("/cart.js")}catch(t){throw xt(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){try{const{product:t}=await this._fetch.get("/products/shipaid-protection.json");return t}catch(t){throw xt(t.message),new Error("Could not fetch protection product for current domain.")}}hasProtection(){return this._hasProtectionInCart}async updateCart(t){t||(t=await this._fetchCart()),this._cart=t}async addProtection(){var t,e;try{if(!this._store)throw new Error("Store has not been loaded.");if(!(null==(t=this._cart)?void 0:t.items))throw new Error("Cart has not been loaded.");if(!(null==(e=this._protectionVariant)?void 0:e.id))throw new Error("No protection variant found.");this._setState("loading");const i={quantity:1,id:this._protectionVariant.id},o=await this._fetch.post("/cart/add.js",i);await this._handleRefresh(o),this._setState("success")}catch(i){xt(i.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}async removeProtection(){try{if(!this._store)throw new Error("Store has not been loaded.");if(!this._protectionCartItem)throw new Error("Protection product not found.");this._setState("loading");const t={quantity:0,id:this._protectionCartItem.key},e=await this._fetch.post("/cart/change.js",t);await this._handleRefresh(e),this._cart=e,this._setState("success")}catch(t){xt(t.message),this._setState("error","Failed to add protection to cart - please try again, or contact us for help.")}}learnMorePopupTemplate(){return j`
|
|
519
522
|
<shipaid-popup-learn-more ?active=${"learn-more"===this._popup} @close=${()=>{this._popup=null}}></shipaid-popup-learn-more>
|
|
520
523
|
`}promptTemplate(){var t;return j`
|
|
521
524
|
<div class="shipaid-prompt">
|
|
522
525
|
<div class="prompt-product">
|
|
523
526
|
<div class="prompt-product-image">
|
|
524
|
-
${ht(this._hasProtectionInCart,(()=>_t),(()=>
|
|
527
|
+
${ht(this._hasProtectionInCart,(()=>_t),(()=>Ct))}
|
|
525
528
|
</div>
|
|
526
529
|
<div class="prompt-product-details">
|
|
527
530
|
<p class="prompt-product-details-title">
|
|
@@ -551,7 +554,7 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
551
554
|
@click=${()=>{this._popup="learn-more"}}
|
|
552
555
|
>
|
|
553
556
|
<span>Powered by</span>
|
|
554
|
-
${
|
|
557
|
+
${yt}
|
|
555
558
|
</a>
|
|
556
559
|
<button
|
|
557
560
|
class="prompt-footer-about"
|
|
@@ -561,8 +564,8 @@ function ht(t,e,i){return t?e():null==i?void 0:i()}const ct=h`
|
|
|
561
564
|
</button>
|
|
562
565
|
</div>
|
|
563
566
|
</div>
|
|
564
|
-
`}render(){return dt(this,(async()=>{var t,e;const i=document.createElement("link");i.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),i.setAttribute("rel","stylesheet"),document.head.appendChild(i);try{const
|
|
567
|
+
`}render(){return dt(this,(async()=>{var t,e;const i=document.createElement("link");i.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),i.setAttribute("rel","stylesheet"),document.head.appendChild(i);try{const[t,e,i]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=t,this._cart=e,this._protectionProduct=i}catch(o){return this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)}return this.planActive?(null==(e=null==(t=this._store)?void 0:t.protectionSettings)?void 0:e.protectionType)?this._protectionProduct?(this._hasFinishedSetup=!0,this._shouldShowWidget=!0,this._dispatchEvent(wt.LOADED,this._store),setTimeout((async()=>{var t,e,i;(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&(null==(e=this._cart)?void 0:e.item_count)&&(sessionStorage.getItem(Et)||(sessionStorage.setItem(Et,JSON.stringify({loaded:!0})),!this._hasProtectionInCart&&(null==(i=this._cart)?void 0:i.item_count)&&this._store.widgetShowCart&&await this.addProtection()))}),500),void(this.disablePolling||setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval))):(St("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(St("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(St("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))}),[]),dt(this,(async()=>{var t,e,i;if(this._cartLastUpdated=new Date,!(null==(t=this._cart)?void 0:t.items))return;const o=null==(e=this._cart.items)?void 0:e.findIndex((t=>{var e,i;return null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id))})),r=null==(i=this._cart)?void 0:i.items[o];if(this._hasProtectionInCart=!!r,1===this._cart.item_count&&r){const t={id:r.key,quantity:0},e=await this._fetch.post("/cart/change.js",t);return await this._handleRefresh(e)}const s=await this.calculateProtectionTotal(this._cart),n=this._findProtectionVariant(s);if(this._protectionVariant=n,!(null==n?void 0:n.id))return this._shouldShowWidget=!1,void xt("No matching protection variant found.");if(!r)return;if(n.id===r.id){if(this._protectionCartItem={...r,index:o,position:o+1},1===r.quantity)return;const t={id:r.key,quantity:1},e=await this._fetch.post("/cart/change.js",t);return await this._handleRefresh(e)}const a={updates:{[r.variant_id]:0,[n.id]:1}},p=await this._fetch.post("/cart/update.js",a);await this._handleRefresh(p)}),[this._store,this._cart]),ot(this.learnMorePopupTemplate(),document.body),j`
|
|
565
568
|
<div class="shipaid">
|
|
566
569
|
${ht(this._hasFinishedSetup,(()=>{var t;return ht(this._shouldShowWidget&&this.planActive&&(null==(t=this._store)?void 0:t.widgetShowCart),(()=>this.promptTemplate()),(()=>D))}),(()=>j`<p><slot name="loading" default>Loading ShipAid Widget...</slot></p>`))}
|
|
567
570
|
</div>
|
|
568
|
-
`}},t.ShipAidWidget.styles=gt,Lt([o({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disablePolling",2),Lt([o({type:Number,attribute:!0})],t.ShipAidWidget.prototype,"pollingInterval",2),Lt([o({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disableRefresh",2),Lt([r()],t.ShipAidWidget.prototype,"_storeDomain",2),Lt([r()],t.ShipAidWidget.prototype,"_store",2),Lt([r()],t.ShipAidWidget.prototype,"_cart",2),Lt([r()],t.ShipAidWidget.prototype,"_protectionProduct",2),Lt([r()],t.ShipAidWidget.prototype,"_cartLastUpdated",2),Lt([r()],t.ShipAidWidget.prototype,"_hasFinishedSetup",2),Lt([r()],t.ShipAidWidget.prototype,"_shouldShowWidget",2),Lt([r()],t.ShipAidWidget.prototype,"_hasProtectionInCart",2),Lt([r()],t.ShipAidWidget.prototype,"
|
|
571
|
+
`}},t.ShipAidWidget.styles=gt,Lt([o({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disablePolling",2),Lt([o({type:Number,attribute:!0})],t.ShipAidWidget.prototype,"pollingInterval",2),Lt([o({type:Boolean,attribute:!0})],t.ShipAidWidget.prototype,"disableRefresh",2),Lt([r()],t.ShipAidWidget.prototype,"_storeDomain",2),Lt([r()],t.ShipAidWidget.prototype,"_store",2),Lt([r()],t.ShipAidWidget.prototype,"_cart",2),Lt([r()],t.ShipAidWidget.prototype,"_protectionProduct",2),Lt([r()],t.ShipAidWidget.prototype,"_cartLastUpdated",2),Lt([r()],t.ShipAidWidget.prototype,"_hasFinishedSetup",2),Lt([r()],t.ShipAidWidget.prototype,"_shouldShowWidget",2),Lt([r()],t.ShipAidWidget.prototype,"_hasProtectionInCart",2),Lt([r()],t.ShipAidWidget.prototype,"_protectionCartItem",2),Lt([r()],t.ShipAidWidget.prototype,"_protectionVariant",2),Lt([r()],t.ShipAidWidget.prototype,"_state",2),Lt([r()],t.ShipAidWidget.prototype,"_popup",2),t.ShipAidWidget=Lt([e("shipaid-widget")],t.ShipAidWidget),Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const styles: import(
|
|
2
|
-
export default styles
|
|
1
|
+
declare const styles: import('lit').CSSResult
|
|
2
|
+
export default styles
|
|
@@ -31,8 +31,6 @@ export declare class ShipAidWidget extends LitElement {
|
|
|
31
31
|
private _shouldShowWidget;
|
|
32
32
|
/** Whether the ShipAid protection product is currently added to the cart */
|
|
33
33
|
private _hasProtectionInCart;
|
|
34
|
-
/** The last action a user took */
|
|
35
|
-
private _lastAction;
|
|
36
34
|
/** The protection item from the Shopify cart */
|
|
37
35
|
private _protectionCartItem;
|
|
38
36
|
/** The protection variant that will be used */
|
|
@@ -81,6 +81,9 @@ export interface ShopifyCartAddPayload {
|
|
|
81
81
|
id: number | string;
|
|
82
82
|
quantity?: number;
|
|
83
83
|
}
|
|
84
|
+
export interface ShopifyCartUpdatePayload {
|
|
85
|
+
updates: Record<string | number, number>;
|
|
86
|
+
}
|
|
84
87
|
export interface ShopifyProductResponse {
|
|
85
88
|
product: ShopifyProduct;
|
|
86
89
|
}
|