UNPKG

@shopgate/pwa-webcheckout-shopify

Version:

Webcheckout Shopify library for the Shopgate Connect PWA.

23 lines 1.85 kB
import appConfig from'@shopgate/pwa-common/helpers/config';/** * Checks if Shopify checkout is available. * @returns {boolean} */export var hasShopifyCheckout=function hasShopifyCheckout(){return appConfig.webCheckoutShopify!==null;};/** * Returns the Shopify checkout configuration. * @returns {Object|null} */export var getShopifyCheckout=function getShopifyCheckout(){return appConfig.webCheckoutShopify;};/** * Returns the Shopify URL based on the given domain or alias. * @returns {string} */export var getShopifyUrl=function getShopifyUrl(){// Prioritize the "domain" property over alias, if it exists. var url=typeof getShopifyCheckout().domain==='string'?getShopifyCheckout().domain.replace(/\/+$/g,''):"https://".concat(getShopifyCheckout().alias,".myshopify.com");// Add https protocol if none is set, yet. if(!url.match(/^https:\/\/.*/g)&&!url.match(/^http:\/\/.*/g)){// Cut out "://" or "//" from the beginning. E.g.: "//www.myshop.com" or "://www.myshop.com" url="https://".concat(url.replace(/^[:/]*/g,''));}return url;};/** * Checks if a configuration for Shopify is available * @return {boolean} */export var isShopify=function isShopify(){var _ref=getShopifyCheckout()||{},alias=_ref.alias;return!!alias;};/** * Returns the logout url for the logout action * @return {string} */export var getLogoutUrl=function getLogoutUrl(){var result;if(isShopify()){result="".concat(getShopifyUrl(),"/account/logout");}else{result=getShopifyCheckout().logoutUrl;}return result;};/** * Returns the logout success url for the logout action. It's used to determine, if the logout * process worked as expected. * @return {string} */export var getLogoutSuccessUrl=function getLogoutSuccessUrl(){var result;if(isShopify()){result="".concat(getShopifyUrl(),"/");}else{result=getShopifyCheckout().logoutSuccessUrl;}return result;};