ui.shipaid.com 0.3.66 → 0.3.67
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/README.md +200 -200
- package/dist/widget.es.js +2 -2
- package/dist/widget.iife.js +2 -2
- package/dist/widget.umd.js +2 -2
- package/dist-types/common/shopify/index.d.ts +6 -6
- package/dist-types/common/shopify/protection.d.ts +7 -7
- package/dist-types/common/shopify/types/ShopifyCart.d.ts +29 -29
- package/dist-types/common/shopify/types/ShopifyProduct.d.ts +12 -12
- package/dist-types/common/types/ShipAid.d.ts +82 -82
- package/dist-types/widget/src/assets/confirmation-styles.d.ts +2 -2
- package/dist-types/widget/src/assets/icons.d.ts +9 -9
- package/dist-types/widget/src/assets/learn-more-styles.d.ts +2 -2
- package/dist-types/widget/src/assets/styles.d.ts +2 -2
- package/dist-types/widget/src/components/checkout-package-protection.d.ts +13 -13
- package/dist-types/widget/src/components/confirmation-popup.d.ts +9 -9
- package/dist-types/widget/src/components/learn-more-popup.d.ts +8 -8
- package/dist-types/widget/src/components/product-add-confirmation.d.ts +13 -0
- package/dist-types/widget/src/components/shipaid-cart-confirmation.d.ts +15 -15
- package/dist-types/widget/src/shipaid-widget.d.ts +145 -145
- package/dist-types/widget/src/utils/fetch_interceptor.d.ts +3 -3
- package/dist-types/widget/src/utils/fetch_interceptor.test.d.ts +1 -1
- package/dist-types/widget/types/shipaid.d.ts +10 -10
- package/dist-types/widget/types/shopify.d.ts +29 -29
- package/dist-types/widget/types/widget.d.ts +13 -13
- package/package.json +48 -48
- package/dist-types/widget/src/components/checkout-button.d.ts +0 -7
- package/dist-types/widget/src/components/checkoutButton.d.ts +0 -13
- package/dist-types/widget/src/components/content-loader.d.ts +0 -6
package/dist/widget.umd.js
CHANGED
|
@@ -1168,7 +1168,7 @@ function qt(t,e,i){return t?e():null==i?void 0:i()}const jt=u`
|
|
|
1168
1168
|
.shipaid-prompt .prompt-footer .prompt-footer-badge svg {
|
|
1169
1169
|
height:var(--shipaid-footer-badge-logo-height, 9px);
|
|
1170
1170
|
}
|
|
1171
|
-
`;var me=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(me||{});var ge=Object.defineProperty,fe=(t,e,i,o)=>{for(var r,n=void 0,s=t.length-1;s>=0;s--)(r=t[s])&&(n=r(e,i,n)||n);return n&&ge(e,i,n),n};const ve=t=>({items:t.lines.edges.map((({node:t})=>({id:t.id,key:t.id,variant_id:t.merchandise.id,sku:t.merchandise.sku,final_line_price:parseFloat(t.cost.totalAmount.amount),quantity:t.quantity}))),total_price:parseFloat(t.cost.totalAmount.amount),item_count:t.lines.edges.length}),be=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.")}},ye=t=>console.warn(`[ShipAid] ${t}`),_e=t=>console.error(`[ShipAid] ${t}`),we="shipaid-protection",Ce="shipaid-protection-popup-show",xe="shipaid-protection",$e="query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetPollProtection\n widgetShowCart\n excludedProductSkus\n excludedCustomersIdsAutoOptIn\n protectionSettings\n widgetConfigurations\n useCustomApp\n }\n}",ke=Object.assign({"./lang/de.json":()=>Promise.resolve().then((()=>qe)).then((t=>t.default)),"./lang/en.json":()=>Promise.resolve().then((()=>he)).then((t=>t.default)),"./lang/es.json":()=>Promise.resolve().then((()=>Be)).then((t=>t.default)),"./lang/fr.json":()=>Promise.resolve().then((()=>Ke)).then((t=>t.default)),"./lang/it.json":()=>Promise.resolve().then((()=>ii)).then((t=>t.default)),"./lang/nl.json":()=>Promise.resolve().then((()=>pi)).then((t=>t.default)),"./lang/pt.json":()=>Promise.resolve().then((()=>fi)).then((t=>t.default))});var Se;Se={loader:async t=>{if("en"===t)return ce;const e=Reflect.get(ke,`./lang/${t}.json`);return e?await e():ce}},bt=Object.assign(Object.assign({},bt),Se);const Ae=class extends ht{constructor(){var t,e,i;super(...arguments),this.env="prod",this.useCustomStoreFront=!1,this.storeDomain="",this.storeAccessToken="",this.cartId="",this.disablePolling=!1,this.disableActions=!1,this.pollingInterval=2500,this.disableRefresh=!1,this.refreshCart=!1,this.persistPopup=!1,this.defaultToggleButton=!1,this.lang="en",this.currency=void 0,this.customerId=void 0,this.supportSubscriptions=!1,this.dataSelector="",this.useShipAidCheckout=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),this._hasFinishedSetup=!1,this._shouldShowWidget=!1,this._hasProtectionInCart=!1,this.hasLoadedStrings=!1,this.fetchInterceptorCleanup=()=>{},this.intervalId=null,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>be(t),post:(t,e)=>be(t,{method:"POST",headers:{"Content-Type":"application/json","X-ShipAid":"1"},body:JSON.stringify(e)})}}shouldUpdate(t){return this.hasLoadedStrings&&super.shouldUpdate(t)}shouldPersistPopup(){return"true"===localStorage.getItem(`${Ce}`)?"learn-more":null}setPopupKey(){this.persistPopup&&localStorage.setItem(`${Ce}`,"true")}get nhost(){const t=`https://${"prod"===this.env?"gjiyysyzjwuculcymsvb":"staging"===this.env?"xfnjpunvafvudwuzwjlm":"local"}.graphql.us-east-1.nhost.run/v1`;return{request:async(e,i)=>{try{const o=await fetch(t,{method:"post",body:JSON.stringify({query:e,variables:i})});return await o.json()}catch(o){console.log(`Nhost Error: ${o}`)}}}}async runStoreFrontQuery(t,e){try{const i=new Headers;i.append("Content-Type","application/json"),i.append("X-Shopify-Storefront-Access-Token",this.storeAccessToken);const o={method:"POST",headers:i,body:JSON.stringify({query:t,variables:e})},r=await fetch(`https://${this.storeDomain}/api/2021-07/graphql.json`,o);if(!r.ok)throw new Error(`GraphQL request failed: ${r.statusText}`);const n=await r.json();if(n.errors)throw new Error(n.errors[0].message);return n.data}catch(i){throw console.error("GraphQL query error:",i),new Error("Failed to execute GraphQL query")}}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")?(ye("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,o,r,n,s;const a=this.currency||(null==(i=null==(e=window.Shopify)?void 0:e.currency)?void 0:i.active)||(null==(o=this._store)?void 0:o.currency)||"USD";if(null==(s=null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.widget)?void 0:s.currencyFormat){return this._store.widgetConfigurations.widget.currencyFormat.replace("_value_",Number(t)).replace("_currency_",a)}return new Intl.NumberFormat(void 0,{currency:a,style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}_handleRefreshCart(){if(this.refreshCart)return window.location.reload()}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(me.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return i.calculateProtectionTotal(this._store,this._protectionProduct,t)}_findProtectionVariant(t){if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return i.findProtectionVariant(this._store,this._protectionProduct,t)}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}_handleConfirmationPopup(){"confirmation"!==this._popup&&(this._popup="confirmation")}_updateProtection(){var t,e,i;const o=null==(i=null==(e=null==(t=this._store)?void 0:t.widgetConfigurations)?void 0:e.widget)?void 0:i.removeWithConfirmation;if(this._hasProtectionInCart)return o?this._handleConfirmationPopup():this.removeProtection();this.addProtection()}async _fetchShipAidData(){var t,e,i,o,r;let n;if(n=this.storeDomain?this.storeDomain:(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),!n)throw new Error("No shop found in Shopify object.");try{let t,e;if(this.useCustomStoreFront)e=await this.nhost.request($e,{store:n});else{t=new URL(window.location.href),t.pathname=this._apiEndpoint;const i={query:$e,variables:{store:n}};e=await this._fetch.post(t.toString(),i)}if(!e)throw new Error("Missing response for store query.");if(null==(o=e.errors)?void 0:o.length)throw new Error(e.errors[0].message);if(!(null==(r=e.data)?void 0:r.store))throw new Error("Missing store from store query response.");return e.data.store}catch(s){throw console.error(s),new Error(`Could not find a store for ${this._storeDomain}`)}}_findSellingPlanByName(t,e){for(const i of t){const t=i.node;for(const i of t.sellingPlans.edges){const t=i.node;if(e===t.name)return t}}return null}async _fetchSellingPlanFromVariant(t){var e,i,o,r,n,s,a,d,p,l,c,h,u;const m=(null==(e=window.Shopify)?void 0:e.shop)??(null==(o=null==(i=window.Shopify)?void 0:i.Checkout)?void 0:o.apiHost);if(!m)throw new Error("No shop found in Shopify object.");try{const e=new URL(window.location.href);e.pathname=this._apiEndpoint;const i={query:"query SellingPlanFromVariant($store: String!, $variantId: String!){\n sellingPlanFromVariant(input: {store: $store, variantId: $variantId })\n}",variables:{store:m,variantId:`gid://shopify/ProductVariant/${null==(r=this._protectionVariant)?void 0:r.id}`}},o=await this._fetch.post(e.toString(),i);if(!o)throw new Error("Missing response for selling plan query.");if(null==(n=o.errors)?void 0:n.length)throw new Error(o.errors[0].message);if(!(null==(s=o.data)?void 0:s.sellingPlanFromVariant))throw new Error("Missing variant from selling plan query response.");const g=(null==(d=null==(a=o.data.sellingPlanFromVariant)?void 0:a.sellingPlanGroups)?void 0:d.edges)||[],f=(null==(u=null==(h=null==(c=null==(l=null==(p=g[0])?void 0:p.node)?void 0:l.sellingPlans)?void 0:c.edges)?void 0:h[0])?void 0:u.node)||null;return this._findSellingPlanByName(g,t.name)||f}catch(g){console.error("Error during the query ====>",g)}}async _fetchCart(){try{if(this.useCustomStoreFront&&this.cartId){const t=await this.runStoreFrontQuery("query getCart($cartId: ID!){ cart( id: $cartId ) { id createdAt updatedAt lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } }",{cartId:this.cartId});return ve(t.cart)}return await this._fetch.get("/cart.js")}catch(t){throw _e(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){var t,e,i,o,r,n,s,a;try{let d;if(this.useCustomStoreFront){const p=await this.runStoreFrontQuery("query product($handle: String!) { product(handle: $handle) { id title images(first: 1) {edges { node { id url altText } } } handle variants(first: 100) { edges { node { id title price { amount } } } } } }",{handle:xe});if(null==p?void 0:p.product){const l=p.product;d={id:l.id,title:l.title,image:{id:null==(o=null==(i=null==(e=null==(t=null==l?void 0:l.images)?void 0:t.edges)?void 0:e[0])?void 0:i.node)?void 0:o.id,src:null==(a=null==(s=null==(n=null==(r=null==l?void 0:l.images)?void 0:r.edges)?void 0:n[0])?void 0:s.node)?void 0:a.url},variants:l.variants.edges.map((t=>({id:t.node.id,price:t.node.price.amount})))}}}else d=(await this._fetch.get(`/products/${xe}.json`)).product;return d}catch(d){throw _e(d.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 addCartProtectionVariant(){var t,i,o,r;let n,s;if(this.supportSubscriptions){const o=null==(i=null==(t=this._cart)?void 0:t.items)?void 0:i.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));if(o){const t=await this._fetchSellingPlanFromVariant(o.selling_plan_allocation.selling_plan);s=t?e(t.id):null}}if(this.useCustomStoreFront){const t=await this.runStoreFrontQuery("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 } } } } }",{cartId:this.cartId,lines:[{merchandiseId:String(null==(o=this._protectionVariant)?void 0:o.id),quantity:1,sellingPlanId:s}]});n=ve(t.cartLinesAdd.cart)}else{const t={quantity:1,id:String(null==(r=this._protectionVariant)?void 0:r.id),selling_plan:s};n=await this._fetch.post("/cart/add.js",t)}return n}async updateCartProtectionVariant(t,e=null,i=null){var o,r;let n;if(this.useCustomStoreFront){const r=await this.runStoreFrontQuery("mutation RemoveItemToCart($cartId: ID!, $lines: [CartLineUpdateInput!]!) { cartLinesUpdate(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 } } } } }",{cartId:this.cartId,lines:[{id:String(e?e.key:null==(o=this._protectionCartItem)?void 0:o.key),quantity:t,sellingPlanId:i}]});n=ve(r.cartLinesUpdate.cart)}else{const o={quantity:t,id:String(e?e.key:null==(r=this._protectionCartItem)?void 0:r.key),selling_plan:i};n=await this._fetch.post("/cart/change.js",o)}return n}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=await this.addCartProtectionVariant();await this._handleRefresh(i),this._setState("success")}catch(i){_e(i.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}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=await this.updateCartProtectionVariant(0,this._protectionCartItem);await this._handleRefresh(t),this._cart=t,this._setState("success")}catch(t){_e(t.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}async attemptAddProtection(){var t,e,i,o,r,n;if(!(null==(t=this._store)?void 0:t.widgetAutoOptIn)||!this._store.useCustomApp)return;if(!(null==(e=this._cart)?void 0:e.items)||!(null==(i=this._cart)?void 0:i.item_count))return;const s=null==(o=this._cart.items)?void 0:o.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))})),a=null==(r=this._cart)?void 0:r.items[s];if(this._hasProtectionInCart=!!a,1===this._cart.item_count&&a)return;!!sessionStorage.getItem(we)||!this._hasProtectionInCart&&(null==(n=this._cart)?void 0:n.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(we,JSON.stringify({loaded:!0})))}async handleMultipleProtectionVariants(){var t,e,i,o,r;if(!(null==(t=this._cart)?void 0:t.items)||!(null==(e=this._cart)?void 0:e.item_count))return;let n=0;if(null==(i=this._cart.items)||i.forEach((t=>{var e,i;(null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id)))&&n++})),n>1){const t=null==(o=this._cart.items)?void 0:o.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))})),e=null==(r=this._cart)?void 0:r.items[t],i=await this.updateCartProtectionVariant(0,e);return await this._handleRefresh(i)}}learnMorePopupTemplate(){return H`
|
|
1171
|
+
`;var me=(t=>(t.LOADED="shipaid-loaded",t.STATUS_UPDATE="shipaid-protection-status",t))(me||{});var ge=Object.defineProperty,fe=(t,e,i,o)=>{for(var r,n=void 0,s=t.length-1;s>=0;s--)(r=t[s])&&(n=r(e,i,n)||n);return n&&ge(e,i,n),n};const ve=t=>({items:t.lines.edges.map((({node:t})=>({id:t.id,key:t.id,variant_id:t.merchandise.id,sku:t.merchandise.sku,final_line_price:parseFloat(t.cost.totalAmount.amount),quantity:t.quantity}))),total_price:parseFloat(t.cost.totalAmount.amount),item_count:t.lines.edges.length}),be=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.")}},ye=t=>console.warn(`[ShipAid] ${t}`),_e=t=>console.error(`[ShipAid] ${t}`),we="shipaid-protection",Ce="shipaid-protection-popup-show",xe="shipaid-protection",$e="query StoreByDomain ($store: String!) {\n store: storeByDomain (input: {store: $store}) {\n currency\n planActive\n store\n widgetAutoOptIn\n widgetPollProtection\n widgetShowCart\n excludedProductSkus\n excludedCustomersIdsAutoOptIn\n protectionSettings\n widgetConfigurations\n useCustomApp\n }\n}",ke=Object.assign({"./lang/de.json":()=>Promise.resolve().then((()=>qe)).then((t=>t.default)),"./lang/en.json":()=>Promise.resolve().then((()=>he)).then((t=>t.default)),"./lang/es.json":()=>Promise.resolve().then((()=>Be)).then((t=>t.default)),"./lang/fr.json":()=>Promise.resolve().then((()=>Ke)).then((t=>t.default)),"./lang/it.json":()=>Promise.resolve().then((()=>ii)).then((t=>t.default)),"./lang/nl.json":()=>Promise.resolve().then((()=>pi)).then((t=>t.default)),"./lang/pt.json":()=>Promise.resolve().then((()=>fi)).then((t=>t.default))});var Se;Se={loader:async t=>{if("en"===t)return ce;const e=Reflect.get(ke,`./lang/${t}.json`);return e?await e():ce}},bt=Object.assign(Object.assign({},bt),Se);const Ae=class extends ht{constructor(){var t,e,i;super(...arguments),this.env="prod",this.useCustomStoreFront=!1,this.storeDomain="",this.storeAccessToken="",this.cartId="",this.disablePolling=!1,this.disableActions=!1,this.pollingInterval=2500,this.disableRefresh=!1,this.refreshCart=!1,this.persistPopup=!1,this.defaultToggleButton=!1,this.lang="en",this.currency=void 0,this.customerId=void 0,this.supportSubscriptions=!1,this.dataSelector="",this.useShipAidCheckout=!1,this._apiEndpoint="/apps/shipaid",this._storeDomain=(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),this._hasFinishedSetup=!1,this._shouldShowWidget=!1,this._hasProtectionInCart=!1,this.hasLoadedStrings=!1,this.fetchInterceptorCleanup=()=>{},this.intervalId=null,this._state={loading:!1,success:null,error:!1},this._popup=null,this._fetch={get:t=>be(t),post:(t,e)=>be(t,{method:"POST",headers:{"Content-Type":"application/json","X-ShipAid":"1"},body:JSON.stringify(e)})}}shouldUpdate(t){return this.hasLoadedStrings&&super.shouldUpdate(t)}shouldPersistPopup(){return"true"===localStorage.getItem(`${Ce}`)?"learn-more":null}setPopupKey(){this.persistPopup&&localStorage.setItem(`${Ce}`,"true")}get nhost(){const t=`https://${"prod"===this.env?"gjiyysyzjwuculcymsvb":"staging"===this.env?"xfnjpunvafvudwuzwjlm":"local"}.graphql.us-east-1.nhost.run/v1`;return{request:async(e,i)=>{try{const o=await fetch(t,{method:"post",body:JSON.stringify({query:e,variables:i})});return await o.json()}catch(o){console.log(`Nhost Error: ${o}`)}}}}async runStoreFrontQuery(t,e){try{const i=new Headers;i.append("Content-Type","application/json"),i.append("X-Shopify-Storefront-Access-Token",this.storeAccessToken);const o={method:"POST",headers:i,body:JSON.stringify({query:t,variables:e})},r=await fetch(`https://${this.storeDomain}/api/2021-07/graphql.json`,o);if(!r.ok)throw new Error(`GraphQL request failed: ${r.statusText}`);const n=await r.json();if(n.errors)throw new Error(n.errors[0].message);return n.data}catch(i){throw console.error("GraphQL query error:",i),new Error("Failed to execute GraphQL query")}}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")?(ye("Currently in preview mode."),!0):!!(null==(e=this._store)?void 0:e.planActive)}_currencyFormat(t){var e,i,o,r,n,s;const a=this.currency||(null==(i=null==(e=window.Shopify)?void 0:e.currency)?void 0:i.active)||(null==(o=this._store)?void 0:o.currency)||"USD";if(null==(s=null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.widget)?void 0:s.currencyFormat){return this._store.widgetConfigurations.widget.currencyFormat.replace("_value_",Number(t)).replace("_currency_",a)}return new Intl.NumberFormat(void 0,{currency:a,style:"currency"}).format(Number(t))}_dispatchEvent(t,e={}){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e}))}_handleRefreshCart(){if(this.refreshCart)return window.location.reload()}async _handleRefresh(t){const e=Reflect.has(t,"items");if(this.shouldRefreshOnUpdate)return window.location.reload();e||await this.updateCart(),this._dispatchEvent(me.STATUS_UPDATE,{protection:this._hasProtectionInCart,cart:e?t:this._cart,lineItem:e?this._protectionCartItem:t})}async calculateProtectionTotal(t){if(t||(t=await this._fetchCart()),!t)throw new Error("Could not fetch cart.");if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return i.calculateProtectionTotal(this._store,this._protectionProduct,t)}_findProtectionVariant(t){if(!this._store)throw new Error("Missing ShipAid store");if(!this._protectionProduct)throw new Error("Missing Shopify protection product");return i.findProtectionVariant(this._store,this._protectionProduct,t)}_setState(t,e){this._state={loading:"loading"===t,success:"success"===t,error:"error"===t&&(e||!0)}}_handleConfirmationPopup(){"confirmation"!==this._popup&&(this._popup="confirmation")}_updateProtection(){var t,e,i;const o=null==(i=null==(e=null==(t=this._store)?void 0:t.widgetConfigurations)?void 0:e.widget)?void 0:i.removeWithConfirmation;if(this._hasProtectionInCart)return o?this._handleConfirmationPopup():this.removeProtection();this.addProtection()}async _fetchShipAidData(){var t,e,i,o,r;let n;if(n=this.storeDomain?this.storeDomain:(null==(t=window.Shopify)?void 0:t.shop)??(null==(i=null==(e=window.Shopify)?void 0:e.Checkout)?void 0:i.apiHost),!n)throw new Error("No shop found in Shopify object.");try{let t,e;if(this.useCustomStoreFront)e=await this.nhost.request($e,{store:n});else{t=new URL(window.location.href),t.pathname=this._apiEndpoint;const i={query:$e,variables:{store:n}};e=await this._fetch.post(t.toString(),i)}if(!e)throw new Error("Missing response for store query.");if(null==(o=e.errors)?void 0:o.length)throw new Error(e.errors[0].message);if(!(null==(r=e.data)?void 0:r.store))throw new Error("Missing store from store query response.");return e.data.store}catch(s){throw console.error(s),new Error(`Could not find a store for ${this._storeDomain}`)}}_findSellingPlanByName(t,e){for(const i of t){const t=i.node;for(const i of t.sellingPlans.edges){const t=i.node;if(e===t.name)return t}}return null}async _fetchSellingPlanFromVariant(t){var e,i,o,r,n,s,a,d,p,l,c,h,u;const m=(null==(e=window.Shopify)?void 0:e.shop)??(null==(o=null==(i=window.Shopify)?void 0:i.Checkout)?void 0:o.apiHost);if(!m)throw new Error("No shop found in Shopify object.");try{const e=new URL(window.location.href);e.pathname=this._apiEndpoint;const i={query:"query SellingPlanFromVariant($store: String!, $variantId: String!){\n sellingPlanFromVariant(input: {store: $store, variantId: $variantId })\n}",variables:{store:m,variantId:`gid://shopify/ProductVariant/${null==(r=this._protectionVariant)?void 0:r.id}`}},o=await this._fetch.post(e.toString(),i);if(!o)throw new Error("Missing response for selling plan query.");if(null==(n=o.errors)?void 0:n.length)throw new Error(o.errors[0].message);if(!(null==(s=o.data)?void 0:s.sellingPlanFromVariant))throw new Error("Missing variant from selling plan query response.");const g=(null==(d=null==(a=o.data.sellingPlanFromVariant)?void 0:a.sellingPlanGroups)?void 0:d.edges)||[],f=(null==(u=null==(h=null==(c=null==(l=null==(p=g[0])?void 0:p.node)?void 0:l.sellingPlans)?void 0:c.edges)?void 0:h[0])?void 0:u.node)||null;return this._findSellingPlanByName(g,t.name)||f}catch(g){console.error("Error during the query ====>",g)}}async _fetchCart(){try{if(this.useCustomStoreFront&&this.cartId){const t=await this.runStoreFrontQuery("query getCart($cartId: ID!){ cart( id: $cartId ) { id createdAt updatedAt lines(first: 10) { edges { node { id quantity merchandise { ... on ProductVariant { id sku } } cost{ totalAmount{ amount currencyCode } } } } } cost { totalAmount { amount currencyCode } subtotalAmount { amount currencyCode } } } }",{cartId:this.cartId});return ve(t.cart)}return await this._fetch.get("/cart.js")}catch(t){throw _e(t.message),new Error("Could not fetch cart for current domain.")}}async _fetchProduct(){var t,e,i,o,r,n,s,a;try{let d;if(this.useCustomStoreFront){const p=await this.runStoreFrontQuery("query product($handle: String!) { product(handle: $handle) { id title images(first: 1) {edges { node { id url altText } } } handle variants(first: 100) { edges { node { id title price { amount } } } } } }",{handle:xe});if(null==p?void 0:p.product){const l=p.product;d={id:l.id,title:l.title,image:{id:null==(o=null==(i=null==(e=null==(t=null==l?void 0:l.images)?void 0:t.edges)?void 0:e[0])?void 0:i.node)?void 0:o.id,src:null==(a=null==(s=null==(n=null==(r=null==l?void 0:l.images)?void 0:r.edges)?void 0:n[0])?void 0:s.node)?void 0:a.url},variants:l.variants.edges.map((t=>({id:t.node.id,price:t.node.price.amount})))}}}else d=(await this._fetch.get(`/products/${xe}.json`)).product;return d}catch(d){throw _e(d.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 addCartProtectionVariant(){var t,i,o,r;let n,s;if(this.supportSubscriptions){const o=null==(i=null==(t=this._cart)?void 0:t.items)?void 0:i.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));if(o){const t=await this._fetchSellingPlanFromVariant(o.selling_plan_allocation.selling_plan);s=t?e(t.id):null}}if(this.useCustomStoreFront){const t=await this.runStoreFrontQuery("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 } } } } }",{cartId:this.cartId,lines:[{merchandiseId:String(null==(o=this._protectionVariant)?void 0:o.id),quantity:1,sellingPlanId:s}]});n=ve(t.cartLinesAdd.cart)}else{const t={quantity:1,id:String(null==(r=this._protectionVariant)?void 0:r.id),selling_plan:s};n=await this._fetch.post("/cart/add.js",t)}return n}async updateCartProtectionVariant(t,e=null,i=null){var o,r;let n;if(this.useCustomStoreFront){const r=await this.runStoreFrontQuery("mutation RemoveItemToCart($cartId: ID!, $lines: [CartLineUpdateInput!]!) { cartLinesUpdate(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 } } } } }",{cartId:this.cartId,lines:[{id:String(e?e.key:null==(o=this._protectionCartItem)?void 0:o.key),quantity:t,sellingPlanId:i}]});n=ve(r.cartLinesUpdate.cart)}else{const o={quantity:t,id:String(e?e.key:null==(r=this._protectionCartItem)?void 0:r.key),selling_plan:i};n=await this._fetch.post("/cart/change.js",o)}return n}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=await this.addCartProtectionVariant();await this._handleRefresh(i),this._setState("success")}catch(i){_e(i.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}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=await this.updateCartProtectionVariant(0,this._protectionCartItem);await this._handleRefresh(t),this._cart=t,this._setState("success")}catch(t){_e(t.message)}finally{this._cart=await this._fetchCart(),this._setState("success")}}async attemptAddProtection(){var t,e,i,o,r,n;if(!(null==(t=this._store)?void 0:t.widgetAutoOptIn))return;if(!(null==(e=this._cart)?void 0:e.items)||!(null==(i=this._cart)?void 0:i.item_count))return;const s=null==(o=this._cart.items)?void 0:o.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))})),a=null==(r=this._cart)?void 0:r.items[s];if(this._hasProtectionInCart=!!a,1===this._cart.item_count&&a)return;!!sessionStorage.getItem(we)||!this._hasProtectionInCart&&(null==(n=this._cart)?void 0:n.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(we,JSON.stringify({loaded:!0})))}async handleMultipleProtectionVariants(){var t,e,i,o,r;if(!(null==(t=this._cart)?void 0:t.items)||!(null==(e=this._cart)?void 0:e.item_count))return;let n=0;if(null==(i=this._cart.items)||i.forEach((t=>{var e,i;(null==(i=null==(e=this._protectionProduct)?void 0:e.variants)?void 0:i.some((e=>e.id===t.variant_id)))&&n++})),n>1){const t=null==(o=this._cart.items)?void 0:o.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))})),e=null==(r=this._cart)?void 0:r.items[t],i=await this.updateCartProtectionVariant(0,e);return await this._handleRefresh(i)}}learnMorePopupTemplate(){return H`
|
|
1172
1172
|
<shipaid-popup-learn-more
|
|
1173
1173
|
?active=${"learn-more"===this._popup}
|
|
1174
1174
|
@close=${()=>{this.persistPopup&&localStorage.removeItem(`${Ce}`),this._popup=null}}
|
|
@@ -1430,7 +1430,7 @@ function qt(t,e,i){return t?e():null==i?void 0:i()}const jt=u`
|
|
|
1430
1430
|
</a>
|
|
1431
1431
|
</div>
|
|
1432
1432
|
</div>
|
|
1433
|
-
`}async connectedCallback(){super.connectedCallback(),await async function(t,e=bt){const i=await e.loader(t,e);e.translationCache={},yt(t,i,e)}(this.lang),this.hasLoadedStrings=!0,this.fetchInterceptorCleanup=function(t){const e=window.fetch;let i=!0;const o=async(o,r)=>{const n=e(o,r);if(i)try{await t([o,r],n)}catch(s){console.warn(s)}return await n};return window.fetch=o,()=>{window.fetch===o?window.fetch=e:i=!1}}((async(t,e)=>{var i,o,r,n;if(null==(o=null==(i=t[1])?void 0:i.headers)?void 0:o["X-ShipAid"])return;if(!t[0].startsWith("/cart/change")&&!t[0].startsWith("/cart/update"))return;const s=(null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.checkoutButtonSelector)||'button[type="submit"][name="checkout"][form="cart"]',a=document.querySelector(s);if(console.log("q",a),a){a.setAttribute("disabled","true"),console.debug("button","t");try{await e,await this.updateCart(),await this.updateProtection()}finally{a.removeAttribute("disabled"),console.debug("button","f")}}}))}disconnectedCallback(){var t;super.disconnectedCallback(),null==(t=this.fetchInterceptorCleanup)||t.call(this)}async updateProtection(){var t,i,o,r;if(this._cartLastUpdated=new Date,!(null==(t=this._cart)?void 0:t.items))return;const n=null==(i=this._cart.items)?void 0:i.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))})),s=null==(o=this._cart)?void 0:o.items[n];if(this._hasProtectionInCart=!!s,!this._store)return;const a=await this.calculateProtectionTotal(this._cart);if(this._cart.item_count>0&&s&&(this._cart.total_price===(null==s?void 0:s.final_line_price)||!a)){const t=await this.updateCartProtectionVariant(0,s);return sessionStorage.removeItem(we),await this._handleRefresh(t)}const d=this._findProtectionVariant(a);if(a?(this._protectionVariant=d,this._shouldShowWidget=!0):this._protectionVariant={id:0,price:"0"},!(null==d?void 0:d.id))return this._shouldShowWidget=!1,void _e("No matching protection variant found.");if(!(null==(r=this._protectionVariant)?void 0:r.id))return void(this._shouldShowWidget=!1);if(!s)return;if(this.supportSubscriptions){const t=this._cart.items.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));let i=null;if(!t&&(null==s?void 0:s.selling_plan_allocation))i={id:s.key,quantity:1,selling_plan:null};else if(t&&!(null==s?void 0:s.selling_plan_allocation)){const o=await this._fetchSellingPlanFromVariant(t.selling_plan_allocation.selling_plan),r=o?e(o.id):null;i={id:s.key,quantity:1,selling_plan:r}}if(i){const t=await this.updateCartProtectionVariant(i.quantity,s,i.selling_plan);await this._handleRefresh(t)}}if(d.id===s.variant_id){if(this._protectionCartItem={...s,index:n,position:n+1},1===s.quantity)return;const t=await this.updateCartProtectionVariant(1,s);return this._handleRefreshCart(),await this._handleRefresh(t)}const p={updates:{[s.variant_id]:0,[d.id]:1}},l=await this._fetch.post("/cart/update.js",p);await this._handleRefresh(l)}render(){return Tt(this,(async()=>{var t,e,i,o,r,n;const s=document.createElement("link");s.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),s.setAttribute("rel","stylesheet"),document.head.appendChild(s);try{const[t,e,i]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=t,this._cart=e,this._protectionProduct=i}catch(a){return _e(a.message),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._dispatchEvent(me.LOADED,this._store),setTimeout((async()=>{var t,e,i,o;(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&
|
|
1433
|
+
`}async connectedCallback(){super.connectedCallback(),await async function(t,e=bt){const i=await e.loader(t,e);e.translationCache={},yt(t,i,e)}(this.lang),this.hasLoadedStrings=!0,this.fetchInterceptorCleanup=function(t){const e=window.fetch;let i=!0;const o=async(o,r)=>{const n=e(o,r);if(i)try{await t([o,r],n)}catch(s){console.warn(s)}return await n};return window.fetch=o,()=>{window.fetch===o?window.fetch=e:i=!1}}((async(t,e)=>{var i,o,r,n;if(null==(o=null==(i=t[1])?void 0:i.headers)?void 0:o["X-ShipAid"])return;if(!t[0].startsWith("/cart/change")&&!t[0].startsWith("/cart/update"))return;const s=(null==(n=null==(r=this._store)?void 0:r.widgetConfigurations)?void 0:n.checkoutButtonSelector)||'button[type="submit"][name="checkout"][form="cart"]',a=document.querySelector(s);if(console.log("q",a),a){a.setAttribute("disabled","true"),console.debug("button","t");try{await e,await this.updateCart(),await this.updateProtection()}finally{a.removeAttribute("disabled"),console.debug("button","f")}}}))}disconnectedCallback(){var t;super.disconnectedCallback(),null==(t=this.fetchInterceptorCleanup)||t.call(this)}async updateProtection(){var t,i,o,r;if(this._cartLastUpdated=new Date,!(null==(t=this._cart)?void 0:t.items))return;const n=null==(i=this._cart.items)?void 0:i.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))})),s=null==(o=this._cart)?void 0:o.items[n];if(this._hasProtectionInCart=!!s,!this._store)return;const a=await this.calculateProtectionTotal(this._cart);if(this._cart.item_count>0&&s&&(this._cart.total_price===(null==s?void 0:s.final_line_price)||!a)){const t=await this.updateCartProtectionVariant(0,s);return sessionStorage.removeItem(we),await this._handleRefresh(t)}const d=this._findProtectionVariant(a);if(a?(this._protectionVariant=d,this._shouldShowWidget=!0):this._protectionVariant={id:0,price:"0"},!(null==d?void 0:d.id))return this._shouldShowWidget=!1,void _e("No matching protection variant found.");if(!(null==(r=this._protectionVariant)?void 0:r.id))return void(this._shouldShowWidget=!1);if(!s)return;if(this.supportSubscriptions){const t=this._cart.items.find((t=>{var e;return t.id!==(null==(e=this._protectionVariant)?void 0:e.id)&&!!(null==t?void 0:t.selling_plan_allocation)}));let i=null;if(!t&&(null==s?void 0:s.selling_plan_allocation))i={id:s.key,quantity:1,selling_plan:null};else if(t&&!(null==s?void 0:s.selling_plan_allocation)){const o=await this._fetchSellingPlanFromVariant(t.selling_plan_allocation.selling_plan),r=o?e(o.id):null;i={id:s.key,quantity:1,selling_plan:r}}if(i){const t=await this.updateCartProtectionVariant(i.quantity,s,i.selling_plan);await this._handleRefresh(t)}}if(d.id===s.variant_id){if(this._protectionCartItem={...s,index:n,position:n+1},1===s.quantity)return;const t=await this.updateCartProtectionVariant(1,s);return this._handleRefreshCart(),await this._handleRefresh(t)}const p={updates:{[s.variant_id]:0,[d.id]:1}},l=await this._fetch.post("/cart/update.js",p);await this._handleRefresh(l)}render(){return Tt(this,(async()=>{var t,e,i,o,r,n;const s=document.createElement("link");s.setAttribute("href","https://fonts.googleapis.com/css2?family=Lato&display=swap"),s.setAttribute("rel","stylesheet"),document.head.appendChild(s);try{const[t,e,i]=await Promise.all([this._fetchShipAidData(),this._fetchCart(),this._fetchProduct()]);this._store=t,this._cart=e,this._protectionProduct=i}catch(a){return _e(a.message),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._dispatchEvent(me.LOADED,this._store),setTimeout((async()=>{var t,e,i,o;(null==(t=this._store)?void 0:t.widgetAutoOptIn)&&(null==(e=this._cart)?void 0:e.item_count)&&(this.customerId&&this._store.excludedCustomersIdsAutoOptIn&&(null==(i=this._store.excludedCustomersIdsAutoOptIn)?void 0:i.length)&&this._store.excludedCustomersIdsAutoOptIn.includes(`gid://shopify/Customer/${this.customerId}`)||sessionStorage.getItem(we)||!this._hasProtectionInCart&&(null==(o=this._cart)?void 0:o.item_count)&&this._store.widgetShowCart&&(await this.addProtection(),sessionStorage.setItem(we,JSON.stringify({loaded:!0}))))}),500),void(this.disablePolling||(setInterval((async()=>{const t=this._cartLastUpdated;t&&(new Date).getTime()-t.getTime()<this.pollingInterval||await this.updateCart()}),this.pollingInterval),(null==(i=this._store)?void 0:i.widgetPollProtection)&&!this.intervalId&&(this.intervalId=setInterval((async()=>{await this.attemptAddProtection()}),400),localStorage.setItem(`polling-shipaid-protection_${this.intervalId}`,`${this.intervalId}`)),(null==(n=null==(r=null==(o=this._store)?void 0:o.widgetConfigurations)?void 0:r.widget)?void 0:n.pollVariantsCheck)&&setInterval((async()=>{await this.handleMultipleProtectionVariants()}),400)))):(ye("No protection settings product for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(ye("No protection settings for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1)):(ye("No plan is active for this store - skipping setup."),this._hasFinishedSetup=!0,void(this._shouldShowWidget=!1))}),[]),Tt(this,(async()=>{await this.updateProtection()}),[this._store,this._cart]),Tt(this,(async()=>{pt(this.renderPopups(),document.body)}),[this._popup]),H`
|
|
1434
1434
|
<style>
|
|
1435
1435
|
:host {
|
|
1436
1436
|
--shipaid-primary: #002bd6;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { calculateProtectionTotal, findProtectionVariant } from './protection';
|
|
2
|
-
declare const _default: {
|
|
3
|
-
calculateProtectionTotal: typeof calculateProtectionTotal;
|
|
4
|
-
findProtectionVariant: typeof findProtectionVariant;
|
|
5
|
-
};
|
|
6
|
-
export default _default;
|
|
1
|
+
import { calculateProtectionTotal, findProtectionVariant } from './protection';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
calculateProtectionTotal: typeof calculateProtectionTotal;
|
|
4
|
+
findProtectionVariant: typeof findProtectionVariant;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type ShipAidStore } from '../types/ShipAid';
|
|
2
|
-
import { type ShopifyCart } from './types/ShopifyCart';
|
|
3
|
-
import { type ShopifyProduct, type ShopifyProductVariant } from './types/ShopifyProduct';
|
|
4
|
-
/** Given the current cart, it calculates the protection total according to the store protection settings. */
|
|
5
|
-
export declare function calculateProtectionTotal(store: ShipAidStore, protectionProduct: ShopifyProduct, cart: ShopifyCart): number;
|
|
6
|
-
export declare function findProtectionVariant(store: ShipAidStore, protectionProduct: ShopifyProduct, protectionFee: number): ShopifyProductVariant | undefined;
|
|
7
|
-
export declare function getIdFromShopifyGid(gid: string): string | null;
|
|
1
|
+
import { type ShipAidStore } from '../types/ShipAid';
|
|
2
|
+
import { type ShopifyCart } from './types/ShopifyCart';
|
|
3
|
+
import { type ShopifyProduct, type ShopifyProductVariant } from './types/ShopifyProduct';
|
|
4
|
+
/** Given the current cart, it calculates the protection total according to the store protection settings. */
|
|
5
|
+
export declare function calculateProtectionTotal(store: ShipAidStore, protectionProduct: ShopifyProduct, cart: ShopifyCart): number;
|
|
6
|
+
export declare function findProtectionVariant(store: ShipAidStore, protectionProduct: ShopifyProduct, protectionFee: number): ShopifyProductVariant | undefined;
|
|
7
|
+
export declare function getIdFromShopifyGid(gid: string): string | null;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
export interface ShopifyCart {
|
|
2
|
-
/** Should be the lowest common denomination */
|
|
3
|
-
total_price: number;
|
|
4
|
-
item_count: number;
|
|
5
|
-
items?: ShopifyCartItem[];
|
|
6
|
-
}
|
|
7
|
-
export interface ShopifyCartItem {
|
|
8
|
-
id: number;
|
|
9
|
-
index: number;
|
|
10
|
-
position: number;
|
|
11
|
-
quantity: number;
|
|
12
|
-
variant_id: number;
|
|
13
|
-
key: string;
|
|
14
|
-
sku: string;
|
|
15
|
-
/** Should be the lowest common denomination */
|
|
16
|
-
final_line_price: number;
|
|
17
|
-
selling_plan_allocation?: any;
|
|
18
|
-
}
|
|
19
|
-
export interface FeaturedImage {
|
|
20
|
-
aspect_ratio: number;
|
|
21
|
-
alt: string;
|
|
22
|
-
height: number;
|
|
23
|
-
url: string;
|
|
24
|
-
width: number;
|
|
25
|
-
}
|
|
26
|
-
export interface OptionsWithValues {
|
|
27
|
-
name: string;
|
|
28
|
-
value: string;
|
|
29
|
-
}
|
|
1
|
+
export interface ShopifyCart {
|
|
2
|
+
/** Should be the lowest common denomination */
|
|
3
|
+
total_price: number;
|
|
4
|
+
item_count: number;
|
|
5
|
+
items?: ShopifyCartItem[];
|
|
6
|
+
}
|
|
7
|
+
export interface ShopifyCartItem {
|
|
8
|
+
id: number;
|
|
9
|
+
index: number;
|
|
10
|
+
position: number;
|
|
11
|
+
quantity: number;
|
|
12
|
+
variant_id: number;
|
|
13
|
+
key: string;
|
|
14
|
+
sku: string;
|
|
15
|
+
/** Should be the lowest common denomination */
|
|
16
|
+
final_line_price: number;
|
|
17
|
+
selling_plan_allocation?: any;
|
|
18
|
+
}
|
|
19
|
+
export interface FeaturedImage {
|
|
20
|
+
aspect_ratio: number;
|
|
21
|
+
alt: string;
|
|
22
|
+
height: number;
|
|
23
|
+
url: string;
|
|
24
|
+
width: number;
|
|
25
|
+
}
|
|
26
|
+
export interface OptionsWithValues {
|
|
27
|
+
name: string;
|
|
28
|
+
value: string;
|
|
29
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export interface ShopifyProduct {
|
|
2
|
-
id?: string;
|
|
3
|
-
image?: {
|
|
4
|
-
src: string;
|
|
5
|
-
};
|
|
6
|
-
title?: string;
|
|
7
|
-
variants?: ShopifyProductVariant[];
|
|
8
|
-
}
|
|
9
|
-
export interface ShopifyProductVariant {
|
|
10
|
-
id: number;
|
|
11
|
-
price: string;
|
|
12
|
-
}
|
|
1
|
+
export interface ShopifyProduct {
|
|
2
|
+
id?: string;
|
|
3
|
+
image?: {
|
|
4
|
+
src: string;
|
|
5
|
+
};
|
|
6
|
+
title?: string;
|
|
7
|
+
variants?: ShopifyProductVariant[];
|
|
8
|
+
}
|
|
9
|
+
export interface ShopifyProductVariant {
|
|
10
|
+
id: number;
|
|
11
|
+
price: string;
|
|
12
|
+
}
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
export interface ProtectionSettingsProductVariant {
|
|
2
|
-
id?: string;
|
|
3
|
-
sku?: string;
|
|
4
|
-
price?: string;
|
|
5
|
-
title?: string;
|
|
6
|
-
selectedOptions?: Array<{
|
|
7
|
-
name?: string;
|
|
8
|
-
value?: string;
|
|
9
|
-
}>;
|
|
10
|
-
}
|
|
11
|
-
export interface ProtectionSettingsProduct {
|
|
12
|
-
id?: string;
|
|
13
|
-
title?: string;
|
|
14
|
-
options?: Array<{
|
|
15
|
-
name: string;
|
|
16
|
-
value: string;
|
|
17
|
-
}>;
|
|
18
|
-
variants?: {
|
|
19
|
-
edges?: Array<{
|
|
20
|
-
node?: ProtectionSettingsProductVariant;
|
|
21
|
-
}>;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export interface ProtectionSettings {
|
|
25
|
-
product?: ProtectionSettingsProduct;
|
|
26
|
-
}
|
|
27
|
-
export interface ProtectionSettingsPercentage {
|
|
28
|
-
protectionType: 'PERCENTAGE';
|
|
29
|
-
percentage: number;
|
|
30
|
-
minimumFee: number;
|
|
31
|
-
}
|
|
32
|
-
export interface ProtectionSettingsFixed {
|
|
33
|
-
protectionType: 'FIXED';
|
|
34
|
-
defaultFee?: number;
|
|
35
|
-
rules?: Array<{
|
|
36
|
-
fee?: number;
|
|
37
|
-
rangeLower?: number;
|
|
38
|
-
rangeUpper?: number;
|
|
39
|
-
}>;
|
|
40
|
-
}
|
|
41
|
-
declare enum Deadline {
|
|
42
|
-
THIRTY_MIN = "THIRTY_MIN",
|
|
43
|
-
SIXTY_MIN = "SIXTY_MIN",
|
|
44
|
-
NINETY_MIN = "NINETY_MIN",
|
|
45
|
-
TWO_HOURS = "TWO_HOURS",
|
|
46
|
-
THREE_HOURS = "THREE_HOURS",
|
|
47
|
-
SIX_HOURS = "SIX_HOURS",
|
|
48
|
-
TWELVE_HOURS = "TWELVE_HOURS",
|
|
49
|
-
ONE_DAY = "ONE_DAY",
|
|
50
|
-
TWO_DAYS = "TWO_DAYS",
|
|
51
|
-
THREE_DAYS = "THREE_DAYS",
|
|
52
|
-
FIVE_DAYS = "FIVE_DAYS",
|
|
53
|
-
TEN_DAYS = "TEN_DAYS"
|
|
54
|
-
}
|
|
55
|
-
interface OrderSettings {
|
|
56
|
-
deadline: {
|
|
57
|
-
timing: Deadline;
|
|
58
|
-
description: string;
|
|
59
|
-
};
|
|
60
|
-
shipping: {
|
|
61
|
-
allow_customer_to_use_po_boxes: boolean;
|
|
62
|
-
allow_customer_to_edit_shipping: boolean;
|
|
63
|
-
allow_gmaps_to_verify_addresses: boolean;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
export interface ShipAidStore {
|
|
67
|
-
store: string;
|
|
68
|
-
currency: string;
|
|
69
|
-
widgetAutoOptIn?: boolean;
|
|
70
|
-
useCustomApp?: boolean;
|
|
71
|
-
widgetPollProtection?: boolean;
|
|
72
|
-
widgetShowCart?: boolean;
|
|
73
|
-
excludedProductSkus?: string[];
|
|
74
|
-
excludedProductsVariantsId?: string[];
|
|
75
|
-
excludedCustomersIdsAutoOptIn?: string[] | null;
|
|
76
|
-
planActive: boolean;
|
|
77
|
-
protectionSettings: ProtectionSettingsFixed | ProtectionSettingsPercentage;
|
|
78
|
-
widgetConfigurations: any;
|
|
79
|
-
orderSettings: OrderSettings;
|
|
80
|
-
autoOptInProbability: any;
|
|
81
|
-
}
|
|
82
|
-
export {};
|
|
1
|
+
export interface ProtectionSettingsProductVariant {
|
|
2
|
+
id?: string;
|
|
3
|
+
sku?: string;
|
|
4
|
+
price?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
selectedOptions?: Array<{
|
|
7
|
+
name?: string;
|
|
8
|
+
value?: string;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export interface ProtectionSettingsProduct {
|
|
12
|
+
id?: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
options?: Array<{
|
|
15
|
+
name: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}>;
|
|
18
|
+
variants?: {
|
|
19
|
+
edges?: Array<{
|
|
20
|
+
node?: ProtectionSettingsProductVariant;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface ProtectionSettings {
|
|
25
|
+
product?: ProtectionSettingsProduct;
|
|
26
|
+
}
|
|
27
|
+
export interface ProtectionSettingsPercentage {
|
|
28
|
+
protectionType: 'PERCENTAGE';
|
|
29
|
+
percentage: number;
|
|
30
|
+
minimumFee: number;
|
|
31
|
+
}
|
|
32
|
+
export interface ProtectionSettingsFixed {
|
|
33
|
+
protectionType: 'FIXED';
|
|
34
|
+
defaultFee?: number;
|
|
35
|
+
rules?: Array<{
|
|
36
|
+
fee?: number;
|
|
37
|
+
rangeLower?: number;
|
|
38
|
+
rangeUpper?: number;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
declare enum Deadline {
|
|
42
|
+
THIRTY_MIN = "THIRTY_MIN",
|
|
43
|
+
SIXTY_MIN = "SIXTY_MIN",
|
|
44
|
+
NINETY_MIN = "NINETY_MIN",
|
|
45
|
+
TWO_HOURS = "TWO_HOURS",
|
|
46
|
+
THREE_HOURS = "THREE_HOURS",
|
|
47
|
+
SIX_HOURS = "SIX_HOURS",
|
|
48
|
+
TWELVE_HOURS = "TWELVE_HOURS",
|
|
49
|
+
ONE_DAY = "ONE_DAY",
|
|
50
|
+
TWO_DAYS = "TWO_DAYS",
|
|
51
|
+
THREE_DAYS = "THREE_DAYS",
|
|
52
|
+
FIVE_DAYS = "FIVE_DAYS",
|
|
53
|
+
TEN_DAYS = "TEN_DAYS"
|
|
54
|
+
}
|
|
55
|
+
interface OrderSettings {
|
|
56
|
+
deadline: {
|
|
57
|
+
timing: Deadline;
|
|
58
|
+
description: string;
|
|
59
|
+
};
|
|
60
|
+
shipping: {
|
|
61
|
+
allow_customer_to_use_po_boxes: boolean;
|
|
62
|
+
allow_customer_to_edit_shipping: boolean;
|
|
63
|
+
allow_gmaps_to_verify_addresses: boolean;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export interface ShipAidStore {
|
|
67
|
+
store: string;
|
|
68
|
+
currency: string;
|
|
69
|
+
widgetAutoOptIn?: boolean;
|
|
70
|
+
useCustomApp?: boolean;
|
|
71
|
+
widgetPollProtection?: boolean;
|
|
72
|
+
widgetShowCart?: boolean;
|
|
73
|
+
excludedProductSkus?: string[];
|
|
74
|
+
excludedProductsVariantsId?: string[];
|
|
75
|
+
excludedCustomersIdsAutoOptIn?: string[] | null;
|
|
76
|
+
planActive: boolean;
|
|
77
|
+
protectionSettings: ProtectionSettingsFixed | ProtectionSettingsPercentage;
|
|
78
|
+
widgetConfigurations: any;
|
|
79
|
+
orderSettings: OrderSettings;
|
|
80
|
+
autoOptInProbability: any;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const styles: import("lit").CSSResult;
|
|
2
|
-
export default styles;
|
|
1
|
+
declare const styles: import("lit").CSSResult;
|
|
2
|
+
export default styles;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare const CheckmarkIcon: import("lit").TemplateResult<1>;
|
|
2
|
-
export declare const ShipAidLogo: import("lit").TemplateResult<1>;
|
|
3
|
-
export declare const ShipAidReducedLogo: import("lit").TemplateResult<1>;
|
|
4
|
-
export declare const ShipAidLogoText: import("lit").TemplateResult<1>;
|
|
5
|
-
export declare const ShipAidLogoPopUp: import("lit").TemplateResult<1>;
|
|
6
|
-
export declare const CheckmarkRibbon: import("lit").TemplateResult<1>;
|
|
7
|
-
export declare const MapIcon: import("lit").TemplateResult<1>;
|
|
8
|
-
export declare const BoxIcon: import("lit").TemplateResult<1>;
|
|
9
|
-
export declare const BellIcon: import("lit").TemplateResult<1>;
|
|
1
|
+
export declare const CheckmarkIcon: import("lit").TemplateResult<1>;
|
|
2
|
+
export declare const ShipAidLogo: import("lit").TemplateResult<1>;
|
|
3
|
+
export declare const ShipAidReducedLogo: import("lit").TemplateResult<1>;
|
|
4
|
+
export declare const ShipAidLogoText: import("lit").TemplateResult<1>;
|
|
5
|
+
export declare const ShipAidLogoPopUp: import("lit").TemplateResult<1>;
|
|
6
|
+
export declare const CheckmarkRibbon: import("lit").TemplateResult<1>;
|
|
7
|
+
export declare const MapIcon: import("lit").TemplateResult<1>;
|
|
8
|
+
export declare const BoxIcon: import("lit").TemplateResult<1>;
|
|
9
|
+
export declare const BellIcon: import("lit").TemplateResult<1>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const styles: import("lit").CSSResult;
|
|
2
|
-
export default styles;
|
|
1
|
+
declare const styles: import("lit").CSSResult;
|
|
2
|
+
export default styles;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("lit").CSSResult;
|
|
2
|
-
export default _default;
|
|
1
|
+
declare const _default: import("lit").CSSResult;
|
|
2
|
+
export default _default;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
2
|
-
declare class CheckoutPackageProtection extends LitElement {
|
|
3
|
-
createRenderRoot(): this;
|
|
4
|
-
protectionPrice: number;
|
|
5
|
-
checkoutTotal: number;
|
|
6
|
-
logo: string;
|
|
7
|
-
originalClasses: string;
|
|
8
|
-
handleAbout(): void;
|
|
9
|
-
handleCheckoutWithProtection(): void;
|
|
10
|
-
handleCheckoutWithoutProtection(): void;
|
|
11
|
-
render(): import("lit").TemplateResult<1>;
|
|
12
|
-
}
|
|
13
|
-
export default CheckoutPackageProtection;
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
declare class CheckoutPackageProtection extends LitElement {
|
|
3
|
+
createRenderRoot(): this;
|
|
4
|
+
protectionPrice: number;
|
|
5
|
+
checkoutTotal: number;
|
|
6
|
+
logo: string;
|
|
7
|
+
originalClasses: string;
|
|
8
|
+
handleAbout(): void;
|
|
9
|
+
handleCheckoutWithProtection(): void;
|
|
10
|
+
handleCheckoutWithoutProtection(): void;
|
|
11
|
+
render(): import("lit").TemplateResult<1>;
|
|
12
|
+
}
|
|
13
|
+
export default CheckoutPackageProtection;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
2
|
-
declare class ConfirmationPopup extends LitElement {
|
|
3
|
-
static styles: import("lit").CSSResult;
|
|
4
|
-
active: boolean;
|
|
5
|
-
handleClosePopup(): void;
|
|
6
|
-
handleRemoveProtection(): void;
|
|
7
|
-
render(): import("lit").TemplateResult<1>;
|
|
8
|
-
}
|
|
9
|
-
export default ConfirmationPopup;
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
declare class ConfirmationPopup extends LitElement {
|
|
3
|
+
static styles: import("lit").CSSResult;
|
|
4
|
+
active: boolean;
|
|
5
|
+
handleClosePopup(): void;
|
|
6
|
+
handleRemoveProtection(): void;
|
|
7
|
+
render(): import("lit").TemplateResult<1>;
|
|
8
|
+
}
|
|
9
|
+
export default ConfirmationPopup;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
2
|
-
declare class LearnMorePopup extends LitElement {
|
|
3
|
-
static styles: import("lit").CSSResult;
|
|
4
|
-
active: boolean;
|
|
5
|
-
handleClosePopup(): void;
|
|
6
|
-
render(): import("lit").TemplateResult<1>;
|
|
7
|
-
}
|
|
8
|
-
export default LearnMorePopup;
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
declare class LearnMorePopup extends LitElement {
|
|
3
|
+
static styles: import("lit").CSSResult;
|
|
4
|
+
active: boolean;
|
|
5
|
+
handleClosePopup(): void;
|
|
6
|
+
render(): import("lit").TemplateResult<1>;
|
|
7
|
+
}
|
|
8
|
+
export default LearnMorePopup;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LitElement } from 'lit'
|
|
2
|
+
declare class ProductAddConfirmation extends LitElement {
|
|
3
|
+
static styles: import('lit').CSSResult
|
|
4
|
+
open: boolean
|
|
5
|
+
product: null
|
|
6
|
+
imageUrl: null
|
|
7
|
+
priceOfVariant: null
|
|
8
|
+
quantity: number
|
|
9
|
+
handleDismiss(): void
|
|
10
|
+
handleConfirm(): void
|
|
11
|
+
render(): import('lit-html').TemplateResult<1>
|
|
12
|
+
}
|
|
13
|
+
export default ProductAddConfirmation
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
2
|
-
declare class ShipAidCartConfirmation extends LitElement {
|
|
3
|
-
static styles: import("lit").CSSResult;
|
|
4
|
-
open: boolean;
|
|
5
|
-
product: null;
|
|
6
|
-
imageUrl: null;
|
|
7
|
-
priceOfVariant: null;
|
|
8
|
-
quantity: number;
|
|
9
|
-
handleDismiss(): void;
|
|
10
|
-
handleDontShowAgain(ev: any): void;
|
|
11
|
-
handleConfirm(): void;
|
|
12
|
-
dontShowAgain: boolean;
|
|
13
|
-
render(): import("lit").TemplateResult<1>;
|
|
14
|
-
}
|
|
15
|
-
export default ShipAidCartConfirmation;
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
declare class ShipAidCartConfirmation extends LitElement {
|
|
3
|
+
static styles: import("lit").CSSResult;
|
|
4
|
+
open: boolean;
|
|
5
|
+
product: null;
|
|
6
|
+
imageUrl: null;
|
|
7
|
+
priceOfVariant: null;
|
|
8
|
+
quantity: number;
|
|
9
|
+
handleDismiss(): void;
|
|
10
|
+
handleDontShowAgain(ev: any): void;
|
|
11
|
+
handleConfirm(): void;
|
|
12
|
+
dontShowAgain: boolean;
|
|
13
|
+
render(): import("lit").TemplateResult<1>;
|
|
14
|
+
}
|
|
15
|
+
export default ShipAidCartConfirmation;
|