@liquidcommerce/cloud-sdk 1.2.0 → 1.3.0

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.
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).LiquidCommerce={})}(this,(function(t){"use strict";var LIQUID_COMMERCE_ENV,e,i,r,n,s,a,o,h,c,l,d,u,I,E,w,f,S,p,y;t.LIQUID_COMMERCE_ENV=void 0,(LIQUID_COMMERCE_ENV=t.LIQUID_COMMERCE_ENV||(t.LIQUID_COMMERCE_ENV={})).LOC="loc",LIQUID_COMMERCE_ENV.STAGE="stage",LIQUID_COMMERCE_ENV.PROD="prod",LIQUID_COMMERCE_ENV.DEV="dev",function(t){t.ON_DEMAND="onDemand",t.SHIPPING="shipping"}(e||(e={})),function(t){t.MONDAY="monday",t.TUESDAY="tuesday",t.WEDNESDAY="wednesday",t.THURSDAY="thursday",t.FRIDAY="friday",t.SATURDAY="saturday",t.SUNDAY="sunday"}(i||(i={})),function(t){t.AL="AL",t.AK="AK",t.AR="AR",t.CA="CA",t.CO="CO",t.CT="CT",t.DE="DE",t.DC="DC",t.FL="FL",t.GA="GA",t.HI="HI",t.ID="ID",t.IL="IL",t.IN="IN",t.IA="IA",t.KS="KS",t.KY="KY",t.LA="LA",t.ME="ME",t.MD="MD",t.MA="MA",t.MI="MI",t.MN="MN",t.MS="MS",t.MO="MO",t.MT="MT",t.NE="NE",t.NV="NV",t.NH="NH",t.NJ="NJ",t.NM="NM",t.NY="NY",t.NC="NC",t.ND="ND",t.OH="OH",t.OK="OK",t.OR="OR",t.PA="PA",t.RI="RI",t.SC="SC",t.SD="SD",t.TN="TN",t.TX="TX",t.UT="UT",t.VT="VT",t.VA="VA",t.WA="WA",t.WV="WV",t.WI="WI",t.WY="WY"}(r||(r={})),function(t){t.ALABAMA="AL",t.ALASKA="AK",t.ARKANSAS="AR",t.CALIFORNIA="CA",t.COLORADO="CO",t.CONNECTICUT="CT",t.DELAWARE="DE",t.DISTRICT_OF_COLUMBIA="DC",t.FLORIDA="FL",t.GEORGIA="GA",t.HAWAII="HI",t.IDAHO="ID",t.ILLINOIS="IL",t.INDIANA="IN",t.IOWA="IA",t.KANSAS="KS",t.KENTUCKY="KY",t.LOUISIANA="LA",t.MAINE="ME",t.MARYLAND="MD",t.MASSACHUSETTS="MA",t.MICHIGAN="MI",t.MINNESOTA="MN",t.MISSISSIPPI="MS",t.MISSOURI="MO",t.MONTANA="MT",t.NEBRASKA="NE",t.NEVADA="NV",t.NEW_HAMPSHIRE="NH",t.NEW_JERSEY="NJ",t.NEW_MEXICO="NM",t.NEW_YORK="NY",t.NORTH_CAROLINA="NC",t.NORTH_DAKOTA="ND",t.OHIO="OH",t.OKLAHOMA="OK",t.OREGON="OR",t.PENNSYLVANIA="PA",t.RHODE_ISLAND="RI",t.SOUTH_CAROLINA="SC",t.SOUTH_DAKOTA="SD",t.TENNESSEE="TN",t.TEXAS="TX",t.UTAH="UT",t.VERMONT="VT",t.VIRGINIA="VA",t.WASHINGTON="WA",t.WEST_VIRGINIA="WV",t.WISCONSIN="WI",t.WYOMING="WY"}(n||(n={})),function(t){t.ALE="BEER > ALE",t.LAGER="BEER > LAGER",t.MAIN="BEER",t.NON_ALCOHOLIC="BEER > NON-ALCOHOLIC",t.OTHER_BEER="BEER > OTHER BEER"}(s||(s={})),function(t){t.BASE="FOOD",t.PANTRY_OTHER="FOOD > PANTRY > OTHER"}(a||(a={})),function(t){t.BASE="MERCHANDISE",t.GLASSWARE="MERCHANDISE > GLASSWARE",t.HUMIDOR="MERCHANDISE > HUMIDOR"}(o||(o={})),function(t){t.BASE="MISCELLANEOUS",t.GIFT_CARD="MISCELLANEOUS > GIFT CARDS",t.PROMOTIONAL="MISCELLANEOUS > PROMOTIONAL",t.MEMBERSHIP="MISCELLANEOUS > MEMBERSHIP"}(h||(h={})),function(t){t.BASE="NON ALCOHOLIC",t.BITTERS="NON ALCOHOLIC > BITTERS",t.COCKTAIL_MIX="NON ALCOHOLIC > COCKTAIL MIX",t.COFFEE="NON ALCOHOLIC > COFFEE",t.ENERGY_DRINKS="NON ALCOHOLIC > ENERGY DRINKS",t.JUICE="NON ALCOHOLIC > JUICE",t.SODA="NON ALCOHOLIC > SODA",t.SPECIALTY_ITEM="NON ALCOHOLIC > SPECIALTY ITEM",t.SPIRITS="NON ALCOHOLIC > SPIRITS",t.TEA="NON ALCOHOLIC > TEA",t.WATER="NON ALCOHOLIC > WATER",t.WINE="NON ALCOHOLIC > WINE"}(c||(c={})),function(t){t.BASE="READY TO DRINK",t.HARD_CIDER="READY TO DRINK > HARD CIDER",t.HARD_CIDER_PERRY_PEAR_CIDER="READY TO DRINK > HARD CIDER > PERRY (PEAR CIDER)",t.HARD_TEA="READY TO DRINK > HARD TEA",t.MALT_BASED="READY TO DRINK > MALT BASED",t.SPIRITS_BASED_RTDS="READY TO DRINK > SPIRITS-BASED RTDS",t.SPIRITS_BASED_RTDS_RUM_COCKTAILS="READY TO DRINK > SPIRITS-BASED RTDS > RUM COCKTAILS",t.SPIRITS_BASED_RTDS_TEQUILA_COCKTAILS="READY TO DRINK > SPIRITS-BASED RTDS > TEQUILA COCKTAILS",t.SPIRITS_BASED_RTDS_VODKA_COCKTAILS="READY TO DRINK > SPIRITS-BASED RTDS > VODKA COCKTAILS",t.SPIRITS_BASED_RTDS_WHISKEY_COCKTAILS="READY TO DRINK > SPIRITS-BASED RTDS > WHISKEY COCKTAILS",t.WINE_COCKTAILS="READY TO DRINK > WINE COCKTAILS"}(l||(l={})),function(t){t.BASE="SPIRITS",t.BAIJIU="SPIRITS > BAIJIU",t.BITTERS="SPIRITS > BITTERS",t.BRANDY="SPIRITS > BRANDY",t.CACHACA="SPIRITS > CACHACA",t.GIN="SPIRITS > GIN",t.LAGER="SPIRITS > LAGER",t.LIQUEUR="SPIRITS > LIQUEUR",t.MEZCAL="SPIRITS > MEZCAL",t.OTHER_SPIRITS="SPIRITS > OTHER SPIRITS",t.RUM="SPIRITS > RUM",t.RUM_AGED_RUM="SPIRITS > RUM > AGED RUM",t.RUM_DARK_RUM="SPIRITS > RUM > DARK RUM",t.RUM_FLAVORED_RUM="SPIRITS > RUM > FLAVORED RUM",t.RUM_GOLD_RUM="SPIRITS > RUM > GOLD RUM",t.RUM_OTHER="SPIRITS > RUM > OTHER",t.RUM_SPICED="SPIRITS > RUM > SPICED",t.RUM_WHITE_RUM="SPIRITS > RUM > WHITE RUM",t.SOJU="SPIRITS > SOJU",t.TEQUILA="SPIRITS > TEQUILA",t.VODKA="SPIRITS > VODKA",t.VODKA_FLAVORED_VODKA="SPIRITS > VODKA > FLAVORED VODKA",t.WHISKEY="SPIRITS > WHISKEY",t.WHISKEY_AMERICAN_WHISKEY="SPIRITS > WHISKEY > AMERICAN WHISKEY",t.WHISKEY_BOURBON="SPIRITS > WHISKEY > BOURBON",t.WHISKEY_CANADIAN_WHISKEY="SPIRITS > WHISKEY > CANADIAN WHISKEY",t.WHISKEY_IRISH_WHISKEY="SPIRITS > WHISKEY > IRISH WHISKEY",t.WHISKEY_SCOTCH="SPIRITS > WHISKEY > SCOTCH"}(d||(d={})),function(t){t.BASE="WINE",t.CHAMPAGNE_SPARKLING="WINE > CHAMPAGNE & SPARKLING",t.CHAMPAGNE_SPARKLING_SPARKLING_WINE="WINE > CHAMPAGNE & SPARKLING > SPARKLING WINE",t.COOKING="WINE > COOKING",t.DESSERT_FORTIFIED_WINE="WINE > DESSERT & FORTIFIED WINE",t.DESSERT_FORTIFIED_WINE_SHERRY="WINE > DESSERT & FORTIFIED WINE > SHERRY",t.RED_WINE="WINE > RED WINE",t.ROSE_WINE="WINE > ROSE WINE",t.SAKE="WINE > SAKE",t.WHITE_WINE="WINE > WHITE WINE"}(u||(u={})),function(t){t.BRANDS="brands",t.FLAVOR="flavor",t.REGION="region",t.VARIETY="variety",t.PRICE="price",t.AVAILABILITY="availability",t.CATEGORIES="categories",t.SIZES="sizes",t.COLORS="colors",t.APPELLATION="appellation",t.COUNTRY="country",t.VINTAGE="vintage",t.MATERIALS="materials"}(I||(I={})),function(t){t.ASC="asc",t.DESC="desc"}(E||(E={})),function(t){t.PRICE="price"}(w||(w={})),function(t){t.UNSPECIFIED="AVAILABILITY_UNSPECIFIED",t.IN_STOCK="IN_STOCK",t.OUT_OF_STOCK="OUT_OF_STOCK",t.PREORDER="PREORDER",t.BACKORDER="BACKORDER"}(f||(f={})),function(t){t.INVALID_ITEMS_TYPE="Items must be a non-empty array",t.INVALID_ITEMS_MAX="You can only send up to 25 items at a time!",t.INVALID_PART_NUMBER="The partnerNumber provided is invalid",t.INVALID_FULFILLMENT_ID="The fulfillmentId provided is invalid"}(S||(S={})),function(t){t.OOS="OutOfStock",t.ITEMS_NOT_ADDED="ItemsNotAdded",t.ITEMS_REQUESTED_NOT_ADDED="ItemsRequestedNotAdded",t.ITEM_NOT_ENGRAVED="ItemEngravingError",t.ADDRESS_CHANGE="AddressChange",t.LOCATION_AVAILABILITY="LocationAvailability",t.REMOVED_EXISTING_ITEMS="RemovedExistingCartItems",t.RETAILER_MIN="RetailerMinNotMet",t.NO_ITEMS_IN_CART="NoItemsInCart",t.INVALID_ID="InvalidId",t.NO_ID="NoId",t.CART_CHECKOUT_PROCESSED="CartCheckoutProcessed",t.NEW_CART="NewCart",t.DEFAULT="CartError",t.ITEM_QTY_CHANGE="ItemQuantityChange"}(p||(p={})),function(t){t.SHIPPING="shipping",t.BILLING="billing"}(y||(y={}));const m={[t.LIQUID_COMMERCE_ENV.LOC]:"https://staging.cloud.liquidcommerce.co/api",[t.LIQUID_COMMERCE_ENV.DEV]:"https://staging.cloud.liquidcommerce.co/api",[t.LIQUID_COMMERCE_ENV.STAGE]:"https://staging.cloud.liquidcommerce.co/api",[t.LIQUID_COMMERCE_ENV.PROD]:"https://staging.cloud.liquidcommerce.co/api"};class v{constructor(t){this.accessToken=null,this.tokenExpiration=null,this.isAuthenticating=!1,this.xhrFetch=(t,e)=>new Promise(((i,r)=>{const n=new XMLHttpRequest;n.open(e.method||"GET",t),Object.entries(e.headers).forEach((([t,e])=>{n.setRequestHeader(t,e)})),n.onload=()=>{i({ok:n.status>=200&&n.status<300,status:n.status,statusText:n.statusText,headers:n.getAllResponseHeaders().split("\r\n").reduce(((t,e)=>{const[i,r]=e.split(": ");return i&&(t[i]=r),t}),{}),json:()=>Promise.resolve(JSON.parse(n.responseText)),text:()=>Promise.resolve(n.responseText)})},n.onerror=()=>{r(new TypeError("Network request failed"))},n.send(e.body)})),this.apiKey=t.apiKey,this.baseURL=t.baseURL,this.httpClient=this.getFetchImplementation()}static getInstance(t){return v.instance||(v.instance=new v(t)),v.instance}getFetchImplementation(){return"undefined"!=typeof fetch?this.fetchAdapter(fetch):"undefined"!=typeof global&&global.fetch?this.fetchAdapter(global.fetch):window.fetch?this.fetchAdapter(window.fetch):this.xhrFetch}fetchAdapter(t){return async(e,i)=>{var r;const n=await t(e,i);let s;return"function"==typeof(null===(r=n.headers)||void 0===r?void 0:r.entries)?s=Object.fromEntries(n.headers.entries()):(s={},n.headers.forEach(((t,e)=>{s[e]=t}))),{ok:n.ok,status:n.status,statusText:n.statusText,headers:s,json:()=>n.json(),text:()=>n.text()}}}getUniqueKey(){return`${this.apiKey}_${this.baseURL}`}async authenticate(){var t,e;if(this.isAuthenticating)await new Promise((t=>{const e=()=>{this.isAuthenticating?setTimeout(e,100):t(void 0)};e()}));else{this.isAuthenticating=!0;try{const i=await this.requestWithoutAuth("/authentication",{method:"GET"});this.accessToken=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.token,this.tokenExpiration=Date.now()+1e3*(null===(e=null==i?void 0:i.data)||void 0===e?void 0:e.exp)}catch(t){throw new Error("Failed to authenticate with LiquidCommerce API")}finally{this.isAuthenticating=!1}}}async requestWithoutAuth(t,e){const i=new URL(`api${t}`,this.baseURL),r={"Content-Type":"application/json","X-LIQUID-API-KEY":this.apiKey,...e.headers},n={method:e.method,headers:r,body:e.body?JSON.stringify(e.body):void 0},s=await this.httpClient(i.toString(),n);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s.json()}isTokenExpired(){return!this.tokenExpiration||Date.now()>=this.tokenExpiration}async request(t,e){this.accessToken&&!this.isTokenExpired()||await this.authenticate();const i=new URL(`api${t}`,this.baseURL),r={"Content-Type":"application/json","X-LIQUID-API-KEY":this.apiKey,Authorization:`Bearer ${this.accessToken}`,...e.headers},n={method:e.method,headers:r,body:e.body?JSON.stringify(e.body):void 0},s=await this.httpClient(i.toString(),n);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s.json()}async get(t,e){return this.request(t,{method:"GET",headers:e})}async post(t,e,i){return this.request(t,{method:"POST",body:e,headers:i})}async put(t,e,i){return this.request(t,{method:"PUT",body:e,headers:i})}async delete(t,e){return this.request(t,{method:"DELETE",headers:e})}}v.instance=null;class A{constructor(t){this.locationHelperService=t}validateAndNormalizeParams(t){const e={...t};return e.id=this.validateId(e.id),e.items=this.validateAndNormalizeItems(e.items),this.locationHelperService.validateAndNormalizeLocation(e.loc),e.refresh=Boolean(e.refresh),e}validateId(t){return t&&"string"==typeof t&&0!==t.trim().length?t.trim():""}validateAndNormalizeItems(t){if(!Array.isArray(t)||0===t.length)throw new Error(S.INVALID_ITEMS_TYPE);if(t.length>25)throw new Error(S.INVALID_ITEMS_MAX);return t.map((t=>this.validateAndNormalizeItem(t)))}validateAndNormalizeItem(t){const e={...t};if(!this.validatePartNumber(e.partNumber))throw new Error(S.INVALID_PART_NUMBER);if(!e.fulfillmentId||"string"!=typeof e.fulfillmentId||0===e.fulfillmentId.trim().length)throw new Error(S.INVALID_FULFILLMENT_ID);return e.quantity=Math.max(0,Math.floor(e.quantity)),e.engravingLines&&(e.engravingLines=e.engravingLines.map((t=>t.trim())).filter((t=>t.length>0))),e}validatePartNumber(t){if(!t||"string"!=typeof t)return!1;const e=t.split("_");return 2===e.length&&14===e[0].length&&e[1].length>0}}class R{constructor(t){this.locationServiceHelper=t,this.taxonomyValues=new Set([...Object.values(s),...Object.values(a),...Object.values(o),...Object.values(c),...Object.values(l),...Object.values(d),...Object.values(u)])}validateAndNormalizeParams(t){const e={...t};return this.validateUPCs(e.upcs),this.locationServiceHelper.validateAndNormalizeLocation(e.loc),e}validateAndNormalizeSearchParams(t){const e=[],i={...t};return this.validateOrderBy(i.orderBy,e),this.validateOrderDirection(i.orderDirection,e),this.validateFilters(i.filters,e),this.validatePagination(i.page,i.perPage,e),this.locationServiceHelper.validateAndNormalizeLocation(i.loc),e.length>0?{...i,error:e.join(". ")}:i}validateUPCs(t){if(!Array.isArray(t)||0===t.length)throw new Error("UPCs must be a non-empty array of strings");if(!t.every((t=>"string"==typeof t&&t.trim().length>0)))throw new Error("All UPCs must be non-empty strings")}validateOrderBy(t,e){t&&!Object.values(w).includes(t)&&e.push(`Invalid orderBy value: ${t}`)}validateOrderDirection(t,e){t&&!Object.values(E).includes(t)&&e.push(`Invalid orderDirection value: ${t}`)}validateFilters(t,e){t&&(t.length>10&&e.push("Maximum of 10 filters allowed"),t.forEach((t=>{switch(Object.values(I).includes(t.key)||e.push(`Invalid filter key: ${t.key}`),t.key){case I.AVAILABILITY:this.validateAvailabilityFilter(t.values,e);break;case I.BRANDS:this.validateArrayFilter(t.values,30,"brands",e);break;case I.CATEGORIES:this.validateCategoriesFilter(t.values,e);break;case I.COLORS:this.validateArrayFilter(t.values,75,"colors",e)}})))}validateAvailabilityFilter(t,e){Object.values(f).includes(t)||e.push(`Invalid availability value: ${t}`)}validateArrayFilter(t,e,i,r){Array.isArray(t)?t.length>e&&r.push(`${i} filter can have a maximum of ${e} values`):r.push(`${i} filter must be an array`)}validateCategoriesFilter(t,e){Array.isArray(t)?t.every((t=>this.taxonomyValues.has(t)))||e.push("Invalid category value(s) in categories filter"):e.push("Categories filter must be an array")}validatePagination(t,e,i){void 0!==t&&("number"!=typeof t||t<0)&&i.push("Page must be a non-negative number"),void 0!==e&&("number"!=typeof e||e<=0)&&i.push("PerPage must be a positive number")}}class O{constructor(t){this.locationHelperService=t}validateAndNormalizePrepareParams(t){const e={...t};if(!e.cartId||"string"!=typeof e.cartId)throw new Error("Invalid cartId");return this.validateRecipient(e.recipient),e.billingAddress&&this.validateAddress(e.billingAddress),e.hasSubstitutionPolicy=Boolean(e.hasSubstitutionPolicy),e.isGift=Boolean(e.isGift),e.billingSameAsShipping=Boolean(e.billingSameAsShipping),e.isGift&&this.validateGiftOptions(e.giftOptions),this.validateMarketingPreferences(e.marketingPreferences),e.deliveryTips&&this.validateDeliveryTips(e.deliveryTips),e.refresh=Boolean(e.refresh),e}validateAndNormalizeCompleteParams(t){const e={...t};if(!e.token||"string"!=typeof e.token)throw new Error("Invalid token");if(!e.payment||"string"!=typeof e.payment)throw new Error("Invalid payment token");return void 0!==e.refresh&&(e.refresh=Boolean(e.refresh)),e}validateRecipient(t){if(!t||"object"!=typeof t)throw new Error("Invalid recipient");["firstName","lastName","email","phone","birthDate"].forEach((e=>{if(!t[e]||"string"!=typeof t[e])throw new Error(`Invalid recipient ${e}`)})),t.hasAgeVerify=Boolean(t.hasAgeVerify)}validateAddress(t){if(!t||"object"!=typeof t)throw new Error("Invalid address");["firstName","lastName","email","phone","one","city","state","zip"].forEach((e=>{if(!t[e]||"string"!=typeof t[e])throw new Error(`Invalid address ${e}`)})),this.locationHelperService.validateAndNormalizeLocation({address:t})}validateGiftOptions(t){if(!t||"object"!=typeof t)throw new Error("Invalid giftOptions");if(t.message&&"string"!=typeof t.message)throw new Error("Invalid gift message");if(t.recipient){const{name:e,phone:i,email:r}=t.recipient;if(e&&"string"!=typeof e)throw new Error("Invalid gift recipient name");if(i&&"string"!=typeof i)throw new Error("Invalid gift recipient phone");if(r&&"string"!=typeof r)throw new Error("Invalid gift recipient email")}}validateMarketingPreferences(t){if(!t||"object"!=typeof t)throw new Error("Invalid marketingPreferences");t.canEmail=Boolean(t.canEmail),t.canSms=Boolean(t.canSms)}validateDeliveryTips(t){if(!Array.isArray(t))throw new Error("Invalid deliveryTips");t.forEach((t=>{if(!t.fulfillmentId||"string"!=typeof t.fulfillmentId)throw new Error("Invalid fulfillmentId in deliveryTip");if("number"!=typeof t.tip||t.tip<0)throw new Error("Invalid tip amount in deliveryTip")}))}}class N{validateAndNormalizeLocation(t){if(!t||"object"!=typeof t)throw new Error("Location must be a valid object");if(t.coords)this.validateCoordinates(t.coords);else{if(!t.address)throw new Error("Location must contain either coords or address");this.validateAndNormalizeAddress(t.address)}}validateCoordinates(t){if("number"!=typeof t.lat||"number"!=typeof t.long)throw new Error("Coordinates must be valid numbers");if(t.lat<-90||t.lat>90||t.long<-180||t.long>180)throw new Error("Coordinates are out of valid range")}validateAndNormalizeAddress(t){if(!t.state||"string"!=typeof t.state)throw new Error("State is required and must be a string");if(t.state=this.normalizeState(t.state),!t.city||"string"!=typeof t.city)throw new Error("City is required and must be a string");if(!t.zip||"string"!=typeof t.zip)throw new Error("ZIP code is required and must be a string")}normalizeState(t){const e=t.toUpperCase();if(r[e])return r[e];const i=t.toUpperCase();if(n[i])return n[i];throw new Error(`Invalid state: ${t}`)}}var T,C="https://js.stripe.com/v3",g=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,P=function(t){var e=document.createElement("script");e.src="".concat(C).concat("");var i=document.head||document.body;if(!i)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return i.appendChild(e),e},D=null,b=null,L=null,M=function(){return T||(T=(null!==D?D:(D=new Promise((function(t,e){if("undefined"!=typeof document)if(window.Stripe,window.Stripe)t(window.Stripe);else try{var i=function(){for(var t=document.querySelectorAll('script[src^="'.concat(C,'"]')),e=0;e<t.length;e++){var i=t[e];if(g.test(i.src))return i}return null}();if(i){if(i&&null!==L&&null!==b){var r;i.removeEventListener("load",L),i.removeEventListener("error",b),null===(r=i.parentNode)||void 0===r||r.removeChild(i),i=P()}}else i=P();L=function(t,e){return function(){window.Stripe?t(window.Stripe):e(new Error("Stripe.js not available"))}}(t,e),b=function(t){return function(){t(new Error("Failed to load Stripe.js"))}}(e),i.addEventListener("load",L),i.addEventListener("error",b)}catch(t){return void e(t)}else t(null)}))).catch((function(t){return D=null,Promise.reject(t)}))).catch((function(t){return T=null,Promise.reject(t)})))};Promise.resolve().then((function(){return M()})).catch((function(t){}));class H{constructor(){this.stripe=null,this.elements=null,this.paymentElement=null,this.events=["ready","change","loaderror","loaderstart"],this.eventsErrorMsg="The only Payment Element events allowed (change, ready, loaderstart, loadererror)"}async mount(t){if(!document.getElementById(t.elementId))throw new Error(`Element with id "${t.elementId}" not found`);try{this.stripe=await function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];var r=Date.now();return M().then((function(t){return function(t,e,i){if(null===t)return null;var r=t.apply(void 0,e);return function(t,e){t&&t.t&&t.t({name:"stripe-js",version:"4.3.0",startTime:e})}(r,i),r}(t,e,r)}))}(t.key)}catch(t){throw new Error("Failed to initialize Stripe")}if(!this.stripe)throw new Error("Failed to initialize Stripe");const e={clientSecret:t.clientSecret,appearance:this.mapAppearance(t.appearance),paymentMethodCreation:"manual"};this.elements=this.stripe.elements(e);const i=this.mapElementOptions(t.elementOptions);this.paymentElement=this.elements.create("payment",i),this.paymentElement.mount(`#${t.elementId}`)}async generateToken(){var t,e,i,r,n,s,a,o;if(!this.stripe||!this.elements)return{type:"client_error",message:"Payment form has not been initialized"};const{error:h}=await this.elements.submit();if(h)return{type:"validation_error",message:h.message,code:h.code};const{error:c,paymentMethod:l}=await this.stripe.createPaymentMethod({elements:this.elements});return c?{type:"validation_error"===c.type?"validation_error":"api_error",message:c.message,code:c.code,param:c.param}:l?{id:l.id,type:l.type,card:(null==l?void 0:l.card)?{brand:null!==(e=null===(t=l.card)||void 0===t?void 0:t.brand)&&void 0!==e?e:"",country:null!==(i=l.card.country)&&void 0!==i?i:"",expMonth:null!==(r=l.card.exp_month)&&void 0!==r?r:0,expYear:null!==(n=l.card.exp_year)&&void 0!==n?n:0,last4:null!==(s=l.card.last4)&&void 0!==s?s:"",funding:null!==(a=l.card.funding)&&void 0!==a?a:""}:void 0,created:null!==(o=null==l?void 0:l.created)&&void 0!==o?o:0}:{type:"client_error",message:"Failed to generate payment token"}}subscribe(t,e){if(!this.paymentElement)throw new Error("Payment Element has not been initialized");if(!this.events.includes(t))throw new Error(this.eventsErrorMsg);this.paymentElement.on(t,e)}unsubscribe(t,e){if(!this.paymentElement)throw new Error("Payment Element has not been initialized");if(!this.events.includes(t))throw new Error(this.eventsErrorMsg);this.paymentElement.off(t,e)}mapAppearance(t){if(t)return{theme:"night"===t.theme?"night":"stripe"}}mapElementOptions(t){return{layout:null==t?void 0:t.layout,wallets:{applePay:"auto",googlePay:"auto"}}}}class K{constructor(t){this.client=t}async autocomplete(t,e){try{return await this.client.post("/address/autocomplete",{...t,key:e})}catch(t){throw t}}async details(t,e){try{return await this.client.post("/address/details",{...t,key:e})}catch(t){throw t}}}class U{constructor(t,e){this.client=t,this.cartHelperService=e,this.servicePath="/cart/update"}async get(t,e){try{let i=this.cartHelperService.validateId(t);if(i=""!==i&&i,i){const t={id:i};return"boolean"==typeof e&&(t.refresh=e),await this.client.post(this.servicePath,t)}return await this.client.post(this.servicePath)}catch(t){throw t}}async update(t){try{const e=this.cartHelperService.validateAndNormalizeParams(t);return await this.client.post(this.servicePath,e)}catch(t){throw t}}}class W{constructor(t,e){this.client=t,this.catalogHelperService=e,this.servicePath="/catalog/"}async availability(t){try{const e=this.catalogHelperService.validateAndNormalizeParams(t);return await this.client.post(`${this.servicePath}availability`,e)}catch(t){throw t}}async search(t){try{const e=this.catalogHelperService.validateAndNormalizeSearchParams(t);if(null==e?void 0:e.error)throw new Error(null==e?void 0:e.error);return await this.client.post(`${this.servicePath}search`,e)}catch(t){throw t}}}class Y{constructor(t,e){this.client=t,this.checkoutHelperService=e,this.servicePath="/checkout"}async prepare(t){try{const e=this.checkoutHelperService.validateAndNormalizePrepareParams(t);return await this.client.post(`${this.servicePath}/prepare`,e)}catch(t){throw t}}async complete(t){try{const e=this.checkoutHelperService.validateAndNormalizeCompleteParams(t);return await this.client.post(`${this.servicePath}/complete`,e)}catch(t){throw t}}}class ${constructor(t){this.paymentProvider=t}async mount(t){try{await this.paymentProvider.mount(t)}catch(t){throw t}}async generateToken(){return this.paymentProvider.generateToken()}subscribe(t,e){this.paymentProvider.subscribe(t,e)}unsubscribe(t,e){this.paymentProvider.unsubscribe(t,e)}}class B{constructor(t){this.client=t,this.servicePath="/users"}async createOrUpdateSession(t){try{if(!(null==t?void 0:t.id)&&!(null==t?void 0:t.email))throw new Error("Either id or email must be provided");return await this.client.post(`${this.servicePath}/session`,t)}catch(t){throw t}}async purge(t){try{if(!t)throw new Error("User identifier (ID or email) must be provided");return await this.client.delete(`${this.servicePath}/purge/${t}`)}catch(t){throw t}}async updateAddress(t){try{if(!(t.customerId&&t.one&&t.city&&t.state&&t.zip&&t.type))throw new Error("Missing required parameters for address update");return await this.client.post(`${this.servicePath}/addresses/update`,t)}catch(t){throw t}}async purgeAddress(t){try{if(!t)throw new Error("Address ID must be provided");return await this.client.delete(`${this.servicePath}/addresses/purge/${t}`)}catch(t){throw t}}}class j{constructor(){this.services=new Map,this.liquidCommerceClientConstructor=null}static getInstance(){return j.instance||(j.instance=new j),j.instance}setLiquidCommerceClientConstructor(t){this.liquidCommerceClientConstructor=t}async getLiquidCommerceClient(t,e){const i=`LiquidCommerceClient_${t}_${JSON.stringify(e)}`;if(!this.services.has(i)){if(!this.liquidCommerceClientConstructor)throw new Error("LiquidCommerceClient constructor not set");const r=new this.liquidCommerceClientConstructor(t,e);await r.init(),this.services.set(i,r)}return this.services.get(i)}getOrCreateService(t,e,...i){if(!this.services.has(t)){const r="getInstance"in e?e.getInstance(...i):new e(...i);this.services.set(t,r)}return this.services.get(t)}getAuthenticatedClient(t){return this.getOrCreateService(`AuthenticatedClient_${JSON.stringify(t)}`,v,t)}getLocationHelperService(){return this.getOrCreateService("LocationHelperService",N)}getAddressService(t){return this.getOrCreateService(`AddressService_${t.getUniqueKey()}`,K,t)}getCatalogHelperService(){return this.getOrCreateService("CatalogHelperService",R,this.getLocationHelperService())}getCatalogService(t){return this.getOrCreateService(`CatalogService_${t.getUniqueKey()}`,W,t,this.getCatalogHelperService())}getCartHelperService(){return this.getOrCreateService("CartHelperService",A,this.getLocationHelperService())}getCartService(t){return this.getOrCreateService(`CartService_${t.getUniqueKey()}`,U,t,this.getCartHelperService())}getUserService(t){return this.getOrCreateService(`UserService_${t.getUniqueKey()}`,B,t)}getPaymentProviderService(){return this.getOrCreateService("PaymentProviderService",H)}getPaymentService(){return this.getOrCreateService("PaymentService",$,this.getPaymentProviderService())}getCheckoutHelperService(){return this.getOrCreateService("CheckoutHelperService",O,this.getLocationHelperService())}getCheckoutService(t){return this.getOrCreateService(`CheckoutService_${t.getUniqueKey()}`,Y,t,this.getCheckoutHelperService())}}j.instance=null;class k{constructor(t,e){this.address={autocomplete:async t=>(await this.ensureAuthenticated(),this.addressService.autocomplete(t,this.config.googlePlacesApiKey)),details:async t=>(await this.ensureAuthenticated(),this.addressService.details(t,this.config.googlePlacesApiKey))},this.catalog={availability:async t=>(await this.ensureAuthenticated(),this.catalogService.availability(t)),search:async t=>(await this.ensureAuthenticated(),this.catalogService.search(t))},this.cart={get:async(t,e)=>(await this.ensureAuthenticated(),this.cartService.get(t,e)),update:async t=>(await this.ensureAuthenticated(),this.cartService.update(t))},this.user={session:async t=>(await this.ensureAuthenticated(),this.userService.createOrUpdateSession(t)),purge:async t=>(await this.ensureAuthenticated(),this.userService.purge(t)),updateAddress:async t=>(await this.ensureAuthenticated(),this.userService.updateAddress(t)),purgeAddress:async t=>(await this.ensureAuthenticated(),this.userService.purgeAddress(t))},this.payment={mount:async t=>(await this.ensureAuthenticated(),this.paymentService.mount(t)),generateToken:async()=>(await this.ensureAuthenticated(),this.paymentService.generateToken()),subscribe:(t,e)=>{this.paymentService.subscribe(t,e)},unsubscribe:(t,e)=>{this.paymentService.unsubscribe(t,e)}},this.checkout={prepare:async t=>(await this.ensureAuthenticated(),this.checkoutService.prepare(t)),complete:async t=>(await this.ensureAuthenticated(),this.checkoutService.complete(t))},this.config=e,this.singletonManager=j.getInstance();const i=this.determineBaseURL(e);this.authenticatedClient=this.singletonManager.getAuthenticatedClient({apiKey:t,baseURL:i}),this.addressService=this.singletonManager.getAddressService(this.authenticatedClient),this.catalogService=this.singletonManager.getCatalogService(this.authenticatedClient),this.cartService=this.singletonManager.getCartService(this.authenticatedClient),this.userService=this.singletonManager.getUserService(this.authenticatedClient),this.paymentService=this.singletonManager.getPaymentService(),this.checkoutService=this.singletonManager.getCheckoutService(this.authenticatedClient)}determineBaseURL(e){const i=e.env||t.LIQUID_COMMERCE_ENV.STAGE;return m[i]}async init(){try{await this.authenticatedClient.authenticate()}catch(t){throw new Error("Authentication failed during initialization")}}async ensureAuthenticated(){this.authenticatedClient.isTokenExpired()&&await this.authenticatedClient.authenticate()}}async function LiquidCommerce(t,e){const i=j.getInstance();return i.setLiquidCommerceClientConstructor(k),await i.getLiquidCommerceClient(t,e)}window.LiquidCommerce=LiquidCommerce,window.LIQUID_COMMERCE_ENV=t.LIQUID_COMMERCE_ENV,t.LiquidCommerce=LiquidCommerce}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).LiquidCommerce={})}(this,(function(t){"use strict";var LIQUID_COMMERCE_ENV,e,i,r,n,s,a,o,h,c,l,d,u,I,w,E,y,f,p,m;t.LIQUID_COMMERCE_ENV=void 0,(LIQUID_COMMERCE_ENV=t.LIQUID_COMMERCE_ENV||(t.LIQUID_COMMERCE_ENV={})).LOC="loc",LIQUID_COMMERCE_ENV.STAGE="stage",LIQUID_COMMERCE_ENV.PROD="prod",LIQUID_COMMERCE_ENV.DEV="dev",function(t){t.ON_DEMAND="onDemand",t.SHIPPING="shipping"}(e||(e={})),function(t){t.MONDAY="monday",t.TUESDAY="tuesday",t.WEDNESDAY="wednesday",t.THURSDAY="thursday",t.FRIDAY="friday",t.SATURDAY="saturday",t.SUNDAY="sunday"}(i||(i={})),function(t){t.AL="AL",t.AK="AK",t.AR="AR",t.CA="CA",t.CO="CO",t.CT="CT",t.DE="DE",t.DC="DC",t.FL="FL",t.GA="GA",t.HI="HI",t.ID="ID",t.IL="IL",t.IN="IN",t.IA="IA",t.KS="KS",t.KY="KY",t.LA="LA",t.ME="ME",t.MD="MD",t.MA="MA",t.MI="MI",t.MN="MN",t.MS="MS",t.MO="MO",t.MT="MT",t.NE="NE",t.NV="NV",t.NH="NH",t.NJ="NJ",t.NM="NM",t.NY="NY",t.NC="NC",t.ND="ND",t.OH="OH",t.OK="OK",t.OR="OR",t.PA="PA",t.RI="RI",t.SC="SC",t.SD="SD",t.TN="TN",t.TX="TX",t.UT="UT",t.VT="VT",t.VA="VA",t.WA="WA",t.WV="WV",t.WI="WI",t.WY="WY"}(r||(r={})),function(t){t.ALABAMA="AL",t.ALASKA="AK",t.ARKANSAS="AR",t.CALIFORNIA="CA",t.COLORADO="CO",t.CONNECTICUT="CT",t.DELAWARE="DE",t.DISTRICT_OF_COLUMBIA="DC",t.FLORIDA="FL",t.GEORGIA="GA",t.HAWAII="HI",t.IDAHO="ID",t.ILLINOIS="IL",t.INDIANA="IN",t.IOWA="IA",t.KANSAS="KS",t.KENTUCKY="KY",t.LOUISIANA="LA",t.MAINE="ME",t.MARYLAND="MD",t.MASSACHUSETTS="MA",t.MICHIGAN="MI",t.MINNESOTA="MN",t.MISSISSIPPI="MS",t.MISSOURI="MO",t.MONTANA="MT",t.NEBRASKA="NE",t.NEVADA="NV",t.NEW_HAMPSHIRE="NH",t.NEW_JERSEY="NJ",t.NEW_MEXICO="NM",t.NEW_YORK="NY",t.NORTH_CAROLINA="NC",t.NORTH_DAKOTA="ND",t.OHIO="OH",t.OKLAHOMA="OK",t.OREGON="OR",t.PENNSYLVANIA="PA",t.RHODE_ISLAND="RI",t.SOUTH_CAROLINA="SC",t.SOUTH_DAKOTA="SD",t.TENNESSEE="TN",t.TEXAS="TX",t.UTAH="UT",t.VERMONT="VT",t.VIRGINIA="VA",t.WASHINGTON="WA",t.WEST_VIRGINIA="WV",t.WISCONSIN="WI",t.WYOMING="WY"}(n||(n={})),function(t){t.ALE="BEER > ALE",t.LAGER="BEER > LAGER",t.MAIN="BEER",t.NON_ALCOHOLIC="BEER > NON-ALCOHOLIC",t.OTHER_BEER="BEER > OTHER BEER"}(s||(s={})),function(t){t.BASE="FOOD",t.PANTRY_OTHER="FOOD > PANTRY > OTHER"}(a||(a={})),function(t){t.BASE="MERCHANDISE",t.GLASSWARE="MERCHANDISE > GLASSWARE",t.HUMIDOR="MERCHANDISE > HUMIDOR"}(o||(o={})),function(t){t.BASE="MISCELLANEOUS",t.GIFT_CARD="MISCELLANEOUS > GIFT CARDS",t.PROMOTIONAL="MISCELLANEOUS > PROMOTIONAL",t.MEMBERSHIP="MISCELLANEOUS > MEMBERSHIP"}(h||(h={})),function(t){t.BASE="NON ALCOHOLIC",t.BITTERS="NON ALCOHOLIC > BITTERS",t.COCKTAIL_MIX="NON ALCOHOLIC > COCKTAIL MIX",t.COFFEE="NON ALCOHOLIC > COFFEE",t.ENERGY_DRINKS="NON ALCOHOLIC > ENERGY DRINKS",t.JUICE="NON ALCOHOLIC > JUICE",t.SODA="NON ALCOHOLIC > SODA",t.SPECIALTY_ITEM="NON ALCOHOLIC > SPECIALTY ITEM",t.SPIRITS="NON ALCOHOLIC > SPIRITS",t.TEA="NON ALCOHOLIC > TEA",t.WATER="NON ALCOHOLIC > WATER",t.WINE="NON ALCOHOLIC > WINE"}(c||(c={})),function(t){t.BASE="READY TO DRINK",t.HARD_CIDER="READY TO DRINK > HARD CIDER",t.HARD_CIDER_PERRY_PEAR_CIDER="READY TO DRINK > HARD CIDER > PERRY (PEAR CIDER)",t.HARD_TEA="READY TO DRINK > HARD TEA",t.MALT_BASED="READY TO DRINK > MALT BASED",t.SPIRITS_BASED_RTDS="READY TO DRINK > SPIRITS-BASED RTDS",t.SPIRITS_BASED_RTDS_RUM_COCKTAILS="READY TO DRINK > SPIRITS-BASED RTDS > RUM COCKTAILS",t.SPIRITS_BASED_RTDS_TEQUILA_COCKTAILS="READY TO DRINK > SPIRITS-BASED RTDS > TEQUILA COCKTAILS",t.SPIRITS_BASED_RTDS_VODKA_COCKTAILS="READY TO DRINK > SPIRITS-BASED RTDS > VODKA COCKTAILS",t.SPIRITS_BASED_RTDS_WHISKEY_COCKTAILS="READY TO DRINK > SPIRITS-BASED RTDS > WHISKEY COCKTAILS",t.WINE_COCKTAILS="READY TO DRINK > WINE COCKTAILS"}(l||(l={})),function(t){t.BASE="SPIRITS",t.BAIJIU="SPIRITS > BAIJIU",t.BITTERS="SPIRITS > BITTERS",t.BRANDY="SPIRITS > BRANDY",t.CACHACA="SPIRITS > CACHACA",t.GIN="SPIRITS > GIN",t.LAGER="SPIRITS > LAGER",t.LIQUEUR="SPIRITS > LIQUEUR",t.MEZCAL="SPIRITS > MEZCAL",t.OTHER_SPIRITS="SPIRITS > OTHER SPIRITS",t.RUM="SPIRITS > RUM",t.RUM_AGED_RUM="SPIRITS > RUM > AGED RUM",t.RUM_DARK_RUM="SPIRITS > RUM > DARK RUM",t.RUM_FLAVORED_RUM="SPIRITS > RUM > FLAVORED RUM",t.RUM_GOLD_RUM="SPIRITS > RUM > GOLD RUM",t.RUM_OTHER="SPIRITS > RUM > OTHER",t.RUM_SPICED="SPIRITS > RUM > SPICED",t.RUM_WHITE_RUM="SPIRITS > RUM > WHITE RUM",t.SOJU="SPIRITS > SOJU",t.TEQUILA="SPIRITS > TEQUILA",t.VODKA="SPIRITS > VODKA",t.VODKA_FLAVORED_VODKA="SPIRITS > VODKA > FLAVORED VODKA",t.WHISKEY="SPIRITS > WHISKEY",t.WHISKEY_AMERICAN_WHISKEY="SPIRITS > WHISKEY > AMERICAN WHISKEY",t.WHISKEY_BOURBON="SPIRITS > WHISKEY > BOURBON",t.WHISKEY_CANADIAN_WHISKEY="SPIRITS > WHISKEY > CANADIAN WHISKEY",t.WHISKEY_IRISH_WHISKEY="SPIRITS > WHISKEY > IRISH WHISKEY",t.WHISKEY_SCOTCH="SPIRITS > WHISKEY > SCOTCH"}(d||(d={})),function(t){t.BASE="WINE",t.CHAMPAGNE_SPARKLING="WINE > CHAMPAGNE & SPARKLING",t.CHAMPAGNE_SPARKLING_SPARKLING_WINE="WINE > CHAMPAGNE & SPARKLING > SPARKLING WINE",t.COOKING="WINE > COOKING",t.DESSERT_FORTIFIED_WINE="WINE > DESSERT & FORTIFIED WINE",t.DESSERT_FORTIFIED_WINE_SHERRY="WINE > DESSERT & FORTIFIED WINE > SHERRY",t.RED_WINE="WINE > RED WINE",t.ROSE_WINE="WINE > ROSE WINE",t.SAKE="WINE > SAKE",t.WHITE_WINE="WINE > WHITE WINE"}(u||(u={})),function(t){t.BRANDS="brands",t.FLAVOR="flavor",t.REGION="region",t.VARIETY="variety",t.PRICE="price",t.AVAILABILITY="availability",t.CATEGORIES="categories",t.SIZES="sizes",t.COLORS="colors",t.APPELLATION="appellation",t.COUNTRY="country",t.VINTAGE="vintage",t.MATERIALS="materials"}(I||(I={})),function(t){t.ASC="asc",t.DESC="desc"}(w||(w={})),function(t){t.PRICE="price"}(E||(E={})),function(t){t.UNSPECIFIED="AVAILABILITY_UNSPECIFIED",t.IN_STOCK="IN_STOCK",t.OUT_OF_STOCK="OUT_OF_STOCK",t.PREORDER="PREORDER",t.BACKORDER="BACKORDER"}(y||(y={})),function(t){t.INVALID_ITEMS_TYPE="Items must be a non-empty array",t.INVALID_ITEMS_MAX="You can only send up to 25 items at a time!",t.INVALID_PART_NUMBER="The partnerNumber provided is invalid",t.INVALID_FULFILLMENT_ID="The fulfillmentId provided is invalid"}(f||(f={})),function(t){t.OOS="OutOfStock",t.ITEMS_NOT_ADDED="ItemsNotAdded",t.ITEMS_REQUESTED_NOT_ADDED="ItemsRequestedNotAdded",t.ITEM_NOT_ENGRAVED="ItemEngravingError",t.ADDRESS_CHANGE="AddressChange",t.LOCATION_AVAILABILITY="LocationAvailability",t.REMOVED_EXISTING_ITEMS="RemovedExistingCartItems",t.RETAILER_MIN="RetailerMinNotMet",t.NO_ITEMS_IN_CART="NoItemsInCart",t.INVALID_ID="InvalidId",t.NO_ID="NoId",t.CART_CHECKOUT_PROCESSED="CartCheckoutProcessed",t.NEW_CART="NewCart",t.DEFAULT="CartError",t.ITEM_QTY_CHANGE="ItemQuantityChange"}(p||(p={})),function(t){t.SHIPPING="shipping",t.BILLING="billing"}(m||(m={}));const S={[t.LIQUID_COMMERCE_ENV.LOC]:"https://staging.cloud.liquidcommerce.co/api",[t.LIQUID_COMMERCE_ENV.DEV]:"https://staging.cloud.liquidcommerce.co/api",[t.LIQUID_COMMERCE_ENV.STAGE]:"https://staging.cloud.liquidcommerce.co/api",[t.LIQUID_COMMERCE_ENV.PROD]:"https://staging.cloud.liquidcommerce.co/api"};class v{constructor(t){this.accessToken=null,this.tokenExpiration=null,this.isAuthenticating=!1,this.xhrFetch=(t,e)=>new Promise(((i,r)=>{const n=new XMLHttpRequest;n.open(e.method||"GET",t),Object.entries(e.headers).forEach((([t,e])=>{n.setRequestHeader(t,e)})),n.onload=()=>{i({ok:n.status>=200&&n.status<300,status:n.status,statusText:n.statusText,headers:n.getAllResponseHeaders().split("\r\n").reduce(((t,e)=>{const[i,r]=e.split(": ");return i&&(t[i]=r),t}),{}),json:()=>Promise.resolve(JSON.parse(n.responseText)),text:()=>Promise.resolve(n.responseText)})},n.onerror=()=>{r(new TypeError("Network request failed"))},n.send(e.body)})),this.apiKey=t.apiKey,this.baseURL=t.baseURL,this.httpClient=this.getFetchImplementation()}static getInstance(t){return v.instance||(v.instance=new v(t)),v.instance}getFetchImplementation(){return"undefined"!=typeof fetch?this.fetchAdapter(fetch):"undefined"!=typeof global&&global.fetch?this.fetchAdapter(global.fetch):window.fetch?this.fetchAdapter(window.fetch):this.xhrFetch}fetchAdapter(t){return async(e,i)=>{var r;const n=await t(e,i);let s;return"function"==typeof(null===(r=n.headers)||void 0===r?void 0:r.entries)?s=Object.fromEntries(n.headers.entries()):(s={},n.headers.forEach(((t,e)=>{s[e]=t}))),{ok:n.ok,status:n.status,statusText:n.statusText,headers:s,json:()=>n.json(),text:()=>n.text()}}}getUniqueKey(){return`${this.apiKey}_${this.baseURL}`}async authenticate(){var t,e;if(this.isAuthenticating)await new Promise((t=>{const e=()=>{this.isAuthenticating?setTimeout(e,100):t(void 0)};e()}));else{this.isAuthenticating=!0;try{const i=await this.requestWithoutAuth("/authentication",{method:"GET"});this.accessToken=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.token,this.tokenExpiration=Date.now()+1e3*(null===(e=null==i?void 0:i.data)||void 0===e?void 0:e.exp)}catch(t){throw new Error("Failed to authenticate with LiquidCommerce API")}finally{this.isAuthenticating=!1}}}async requestWithoutAuth(t,e){const i=new URL(`api${t}`,this.baseURL),r={"Content-Type":"application/json","X-LIQUID-API-KEY":this.apiKey,...e.headers},n={method:e.method,headers:r,body:e.body?JSON.stringify(e.body):void 0},s=await this.httpClient(i.toString(),n);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s.json()}isTokenExpired(){return!this.tokenExpiration||Date.now()>=this.tokenExpiration}async request(t,e){this.accessToken&&!this.isTokenExpired()||await this.authenticate();const i=new URL(`api${t}`,this.baseURL),r={"Content-Type":"application/json","X-LIQUID-API-KEY":this.apiKey,Authorization:`Bearer ${this.accessToken}`,...e.headers},n={method:e.method,headers:r,body:e.body?JSON.stringify(e.body):void 0},s=await this.httpClient(i.toString(),n);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return s.json()}async get(t,e){return this.request(t,{method:"GET",headers:e})}async post(t,e,i){return this.request(t,{method:"POST",body:e,headers:i})}async put(t,e,i){return this.request(t,{method:"PUT",body:e,headers:i})}async delete(t,e){return this.request(t,{method:"DELETE",headers:e})}}v.instance=null;class A{constructor(t){this.locationHelperService=t}validateAndNormalizeParams(t){const e={...t};return e.id=this.validateId(e.id),e.items=this.validateAndNormalizeItems(e.items),this.locationHelperService.validateAndNormalizeLocation(e.loc),e.refresh=Boolean(e.refresh),e}validateId(t){return t&&"string"==typeof t&&0!==t.trim().length?t.trim():""}validateAndNormalizeItems(t){if(!Array.isArray(t)||0===t.length)throw new Error(f.INVALID_ITEMS_TYPE);if(t.length>25)throw new Error(f.INVALID_ITEMS_MAX);return t.map((t=>this.validateAndNormalizeItem(t)))}validateAndNormalizeItem(t){const e={...t};if(!this.validatePartNumber(e.partNumber))throw new Error(f.INVALID_PART_NUMBER);if(!e.fulfillmentId||"string"!=typeof e.fulfillmentId||0===e.fulfillmentId.trim().length)throw new Error(f.INVALID_FULFILLMENT_ID);return e.quantity=Math.max(0,Math.floor(e.quantity)),e.engravingLines&&(e.engravingLines=e.engravingLines.map((t=>t.trim())).filter((t=>t.length>0))),e}validatePartNumber(t){if(!t||"string"!=typeof t)return!1;const e=t.split("_");return 2===e.length&&14===e[0].length&&e[1].length>0}}class R{constructor(t){this.locationServiceHelper=t,this.taxonomyValues=new Set([...Object.values(s),...Object.values(a),...Object.values(o),...Object.values(c),...Object.values(l),...Object.values(d),...Object.values(u)])}validateAndNormalizeParams(t){const e={...t};return this.validateUPCs(e.upcs),this.locationServiceHelper.validateAndNormalizeLocation(e.loc),e}validateAndNormalizeSearchParams(t){const e=[],i={...t};return this.validateOrderBy(i.orderBy,e),this.validateOrderDirection(i.orderDirection,e),this.validateFilters(i.filters,e),this.validatePagination(i.page,i.perPage,e),this.locationServiceHelper.validateAndNormalizeLocation(i.loc),e.length>0?{...i,error:e.join(". ")}:i}validateUPCs(t){if(!Array.isArray(t)||0===t.length)throw new Error("UPCs must be a non-empty array of strings");if(!t.every((t=>"string"==typeof t&&t.trim().length>0)))throw new Error("All UPCs must be non-empty strings")}validateOrderBy(t,e){t&&!Object.values(E).includes(t)&&e.push(`Invalid orderBy value: ${t}`)}validateOrderDirection(t,e){t&&!Object.values(w).includes(t)&&e.push(`Invalid orderDirection value: ${t}`)}validateFilters(t,e){t&&(t.length>10&&e.push("Maximum of 10 filters allowed"),t.forEach((t=>{switch(Object.values(I).includes(t.key)||e.push(`Invalid filter key: ${t.key}`),t.key){case I.AVAILABILITY:this.validateAvailabilityFilter(t.values,e);break;case I.BRANDS:this.validateArrayFilter(t.values,30,"brands",e);break;case I.CATEGORIES:this.validateCategoriesFilter(t.values,e);break;case I.COLORS:this.validateArrayFilter(t.values,75,"colors",e)}})))}validateAvailabilityFilter(t,e){Object.values(y).includes(t)||e.push(`Invalid availability value: ${t}`)}validateArrayFilter(t,e,i,r){Array.isArray(t)?t.length>e&&r.push(`${i} filter can have a maximum of ${e} values`):r.push(`${i} filter must be an array`)}validateCategoriesFilter(t,e){Array.isArray(t)?t.every((t=>this.taxonomyValues.has(t)))||e.push("Invalid category value(s) in categories filter"):e.push("Categories filter must be an array")}validatePagination(t,e,i){void 0!==t&&("number"!=typeof t||t<0)&&i.push("Page must be a non-negative number"),void 0!==e&&("number"!=typeof e||e<=0)&&i.push("PerPage must be a positive number")}}class O{constructor(t){this.locationHelperService=t}validateAndNormalizePrepareParams(t){const e={...t};if(!e.cartId||"string"!=typeof e.cartId)throw new Error("Invalid cartId");return this.validateRecipient(e.recipient),e.billingAddress&&this.validateAddress(e.billingAddress),e.hasSubstitutionPolicy=Boolean(e.hasSubstitutionPolicy),e.isGift=Boolean(e.isGift),e.billingSameAsShipping=Boolean(e.billingSameAsShipping),e.isGift&&this.validateGiftOptions(e.giftOptions),this.validateMarketingPreferences(e.marketingPreferences),e.deliveryTips&&this.validateDeliveryTips(e.deliveryTips),e.refresh=Boolean(e.refresh),e}validateAndNormalizeCompleteParams(t){const e={...t};if(!e.token||"string"!=typeof e.token)throw new Error("Invalid token");if(!e.payment||"string"!=typeof e.payment)throw new Error("Invalid payment token");return void 0!==e.refresh&&(e.refresh=Boolean(e.refresh)),e}validateRecipient(t){if(!t||"object"!=typeof t)throw new Error("Invalid recipient");["firstName","lastName","email","phone","birthDate"].forEach((e=>{if(!t[e]||"string"!=typeof t[e])throw new Error(`Invalid recipient ${e}`)})),t.hasAgeVerify=Boolean(t.hasAgeVerify)}validateAddress(t){if(!t||"object"!=typeof t)throw new Error("Invalid address");["firstName","lastName","email","phone","one","city","state","zip"].forEach((e=>{if(!t[e]||"string"!=typeof t[e])throw new Error(`Invalid address ${e}`)})),this.locationHelperService.validateAndNormalizeLocation({address:t})}validateGiftOptions(t){if(!t||"object"!=typeof t)throw new Error("Invalid giftOptions");if(t.message&&"string"!=typeof t.message)throw new Error("Invalid gift message");if(t.recipient){const{name:e,phone:i,email:r}=t.recipient;if(e&&"string"!=typeof e)throw new Error("Invalid gift recipient name");if(i&&"string"!=typeof i)throw new Error("Invalid gift recipient phone");if(r&&"string"!=typeof r)throw new Error("Invalid gift recipient email")}}validateMarketingPreferences(t){if(!t||"object"!=typeof t)throw new Error("Invalid marketingPreferences");t.canEmail=Boolean(t.canEmail),t.canSms=Boolean(t.canSms)}validateDeliveryTips(t){if(!Array.isArray(t))throw new Error("Invalid deliveryTips");t.forEach((t=>{if(!t.fulfillmentId||"string"!=typeof t.fulfillmentId)throw new Error("Invalid fulfillmentId in deliveryTip");if("number"!=typeof t.tip||t.tip<0)throw new Error("Invalid tip amount in deliveryTip")}))}}class T{validateAndNormalizeLocation(t){if(!t||"object"!=typeof t)throw new Error("Location must be a valid object");if(t.coords)this.validateCoordinates(t.coords);else{if(!t.address)throw new Error("Location must contain either coords or address");this.validateAndNormalizeAddress(t.address)}}validateCoordinates(t){if("number"!=typeof t.lat||"number"!=typeof t.long)throw new Error("Coordinates must be valid numbers");if(t.lat<-90||t.lat>90||t.long<-180||t.long>180)throw new Error("Coordinates are out of valid range")}validateAndNormalizeAddress(t){if(!t.state||"string"!=typeof t.state)throw new Error("State is required and must be a string");if(t.state=this.normalizeState(t.state),!t.city||"string"!=typeof t.city)throw new Error("City is required and must be a string");if(!t.zip||"string"!=typeof t.zip)throw new Error("ZIP code is required and must be a string")}normalizeState(t){const e=t.toUpperCase();if(r[e])return r[e];const i=t.toUpperCase();if(n[i])return n[i];throw new Error(`Invalid state: ${t}`)}}var N,C="https://js.stripe.com/v3",g=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,P=function(t){var e=document.createElement("script");e.src="".concat(C).concat("");var i=document.head||document.body;if(!i)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return i.appendChild(e),e},b=null,D=null,L=null,M=function(){return N||(N=(null!==b?b:(b=new Promise((function(t,e){if("undefined"!=typeof document)if(window.Stripe,window.Stripe)t(window.Stripe);else try{var i=function(){for(var t=document.querySelectorAll('script[src^="'.concat(C,'"]')),e=0;e<t.length;e++){var i=t[e];if(g.test(i.src))return i}return null}();if(i){if(i&&null!==L&&null!==D){var r;i.removeEventListener("load",L),i.removeEventListener("error",D),null===(r=i.parentNode)||void 0===r||r.removeChild(i),i=P()}}else i=P();L=function(t,e){return function(){window.Stripe?t(window.Stripe):e(new Error("Stripe.js not available"))}}(t,e),D=function(t){return function(){t(new Error("Failed to load Stripe.js"))}}(e),i.addEventListener("load",L),i.addEventListener("error",D)}catch(t){return void e(t)}else t(null)}))).catch((function(t){return b=null,Promise.reject(t)}))).catch((function(t){return N=null,Promise.reject(t)})))};Promise.resolve().then((function(){return M()})).catch((function(t){}));class H{constructor(){this.stripe=null,this.elements=null,this.paymentElement=null,this.events=["ready","change","loaderror","loaderstart"],this.eventsErrorMsg="The only Payment Element events allowed (change, ready, loaderstart, loadererror)",this.clientSecret=null}async mount(t){if(!document.getElementById(t.elementId))throw new Error(`Element with id "${t.elementId}" not found`);try{this.stripe=await function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];var r=Date.now();return M().then((function(t){return function(t,e,i){if(null===t)return null;var r=t.apply(void 0,e);return function(t,e){t&&t.t&&t.t({name:"stripe-js",version:"4.3.0",startTime:e})}(r,i),r}(t,e,r)}))}(t.key)}catch(t){throw new Error("Failed to initialize Stripe")}if(!this.stripe)throw new Error("Failed to initialize Stripe");this.clientSecret=t.clientSecret;try{const{setupIntent:t}=await this.stripe.retrieveSetupIntent(this.clientSecret);if("succeeded"===(null==t?void 0:t.status))throw new Error(`The client secret (${this.clientSecret}) has already been used previously. Generate a new one through a use session.`)}catch(t){throw t}const e={clientSecret:t.clientSecret,appearance:this.mapAppearance(t.appearance),paymentMethodCreation:"manual"};this.elements=this.stripe.elements(e);const i=this.mapElementOptions(t.elementOptions);this.paymentElement=this.elements.create("payment",i),this.paymentElement.mount(`#${t.elementId}`)}async generateToken(){var t,e,i,r,n,s,a,o,h,c,l,d;if(!this.stripe||!this.elements||!this.clientSecret)return{type:"client_error",message:"Payment form has not been initialized"};const{error:u}=await this.elements.submit();if(u)return{type:"validation_error",message:u.message,code:u.code};const{error:I,paymentMethod:w}=await this.stripe.createPaymentMethod({elements:this.elements}),E=await this.stripe.confirmSetup({elements:this.elements,redirect:"if_required"});return E.error?{type:"confirm_error",message:null!==(e=null===(t=null==E?void 0:E.error)||void 0===t?void 0:t.message)&&void 0!==e?e:"",code:null!==(r=null===(i=null==E?void 0:E.error)||void 0===i?void 0:i.code)&&void 0!==r?r:""}:I?{type:"validation_error"===I.type?"validation_error":"api_error",message:I.message,code:I.code,param:I.param}:w?{id:w.id,type:w.type,card:(null==w?void 0:w.card)?{brand:null!==(s=null===(n=w.card)||void 0===n?void 0:n.brand)&&void 0!==s?s:"",country:null!==(a=w.card.country)&&void 0!==a?a:"",expMonth:null!==(o=w.card.exp_month)&&void 0!==o?o:0,expYear:null!==(h=w.card.exp_year)&&void 0!==h?h:0,last4:null!==(c=w.card.last4)&&void 0!==c?c:"",funding:null!==(l=w.card.funding)&&void 0!==l?l:""}:void 0,created:null!==(d=null==w?void 0:w.created)&&void 0!==d?d:0}:{type:"client_error",message:"Failed to generate payment token"}}subscribe(t,e){if(!this.paymentElement)throw new Error("Payment Element has not been initialized");if(!this.events.includes(t))throw new Error(this.eventsErrorMsg);this.paymentElement.on(t,e)}unsubscribe(t,e){if(!this.paymentElement)throw new Error("Payment Element has not been initialized");if(!this.events.includes(t))throw new Error(this.eventsErrorMsg);this.paymentElement.off(t,e)}mapAppearance(t){if(t)return{theme:"night"===t.theme?"night":"stripe"}}mapElementOptions(t){return{layout:null==t?void 0:t.layout,wallets:{applePay:"auto",googlePay:"auto"}}}unmount(){if(!this.paymentElement)throw new Error("Payment Element has not been initialized");this.paymentElement.unmount()}collapse(){if(!this.paymentElement)throw new Error("Payment Element has not been initialized");this.paymentElement.collapse()}destroy(){if(!this.paymentElement)throw new Error("Payment Element has not been initialized");this.paymentElement.destroy()}}class K{constructor(t){this.client=t}async autocomplete(t,e){try{return await this.client.post("/address/autocomplete",{...t,key:e})}catch(t){throw t}}async details(t,e){try{return await this.client.post("/address/details",{...t,key:e})}catch(t){throw t}}}class U{constructor(t,e){this.client=t,this.cartHelperService=e,this.servicePath="/cart/update"}async get(t,e){try{let i=this.cartHelperService.validateId(t);if(i=""!==i&&i,i){const t={id:i};return"boolean"==typeof e&&(t.refresh=e),await this.client.post(this.servicePath,t)}return await this.client.post(this.servicePath)}catch(t){throw t}}async update(t){try{const e=this.cartHelperService.validateAndNormalizeParams(t);return await this.client.post(this.servicePath,e)}catch(t){throw t}}}class ${constructor(t,e){this.client=t,this.catalogHelperService=e,this.servicePath="/catalog/"}async availability(t){try{const e=this.catalogHelperService.validateAndNormalizeParams(t);return await this.client.post(`${this.servicePath}availability`,e)}catch(t){throw t}}async search(t){try{const e=this.catalogHelperService.validateAndNormalizeSearchParams(t);if(null==e?void 0:e.error)throw new Error(null==e?void 0:e.error);return await this.client.post(`${this.servicePath}search`,e)}catch(t){throw t}}}class W{constructor(t,e){this.client=t,this.checkoutHelperService=e,this.servicePath="/checkout"}async prepare(t){try{const e=this.checkoutHelperService.validateAndNormalizePrepareParams(t);return await this.client.post(`${this.servicePath}/prepare`,e)}catch(t){throw t}}async complete(t){try{const e=this.checkoutHelperService.validateAndNormalizeCompleteParams(t);return await this.client.post(`${this.servicePath}/complete`,e)}catch(t){throw t}}}class Y{constructor(t){this.paymentProvider=t,this.collapse=()=>this.paymentProvider.collapse(),this.unmount=()=>this.paymentProvider.unmount(),this.destroy=()=>this.paymentProvider.destroy()}async mount(t){try{await this.paymentProvider.mount(t)}catch(t){throw t}}async generateToken(){return this.paymentProvider.generateToken()}subscribe(t,e){this.paymentProvider.subscribe(t,e)}unsubscribe(t,e){this.paymentProvider.unsubscribe(t,e)}}class B{constructor(t){this.client=t,this.servicePath="/users"}async createOrUpdateSession(t){try{if(!(null==t?void 0:t.id)&&!(null==t?void 0:t.email))throw new Error("Either id or email must be provided");return await this.client.post(`${this.servicePath}/session`,t)}catch(t){throw t}}async purge(t){try{if(!t)throw new Error("User identifier (ID or email) must be provided");return await this.client.delete(`${this.servicePath}/purge/${t}`)}catch(t){throw t}}async addAddress(t){try{if(!(t.customerId&&t.one&&t.city&&t.state&&t.zip&&t.type))throw new Error("Missing required parameters to add address");return await this.client.post(`${this.servicePath}/addresses/add`,t)}catch(t){throw t}}async updateAddress(t){try{if(!(t.customerId&&t.one&&t.city&&t.state&&t.zip&&t.type))throw new Error("Missing required parameters for address update");return await this.client.post(`${this.servicePath}/addresses/update`,t)}catch(t){throw t}}async purgeAddress(t){try{if(!t)throw new Error("Address ID must be provided");return await this.client.delete(`${this.servicePath}/addresses/purge/${t}`)}catch(t){throw t}}async addPayment(t){try{if(!t.customerId||!t.paymentMethodId)throw new Error("Missing required parameters to add payment");return void 0===(null==t?void 0:t.isDefault)&&(null==t||delete t.isDefault),await this.client.post(`${this.servicePath}/payments/add`,t)}catch(t){throw t}}async updatePayment(t){try{if(!t.customerId||!t.paymentMethodId||void 0===(null==t?void 0:t.isDefault)||"boolean"!=typeof(null==t?void 0:t.isDefault))throw new Error("Missing required parameters to add payment");return await this.client.post(`${this.servicePath}/payments/update`,t)}catch(t){throw t}}async purgePayment(t,e){try{if(!t||!e)throw new Error("Missing required parameters for payment purge");return await this.client.delete(`${this.servicePath}/payments/purge/${t}/${e}`)}catch(t){throw t}}}class j{constructor(){this.services=new Map,this.liquidCommerceClientConstructor=null}static getInstance(){return j.instance||(j.instance=new j),j.instance}setLiquidCommerceClientConstructor(t){this.liquidCommerceClientConstructor=t}async getLiquidCommerceClient(t,e){const i=`LiquidCommerceClient_${t}_${JSON.stringify(e)}`;if(!this.services.has(i)){if(!this.liquidCommerceClientConstructor)throw new Error("LiquidCommerceClient constructor not set");const r=new this.liquidCommerceClientConstructor(t,e);await r.init(),this.services.set(i,r)}return this.services.get(i)}getOrCreateService(t,e,...i){if(!this.services.has(t)){const r="getInstance"in e?e.getInstance(...i):new e(...i);this.services.set(t,r)}return this.services.get(t)}getAuthenticatedClient(t){return this.getOrCreateService(`AuthenticatedClient_${JSON.stringify(t)}`,v,t)}getLocationHelperService(){return this.getOrCreateService("LocationHelperService",T)}getAddressService(t){return this.getOrCreateService(`AddressService_${t.getUniqueKey()}`,K,t)}getCatalogHelperService(){return this.getOrCreateService("CatalogHelperService",R,this.getLocationHelperService())}getCatalogService(t){return this.getOrCreateService(`CatalogService_${t.getUniqueKey()}`,$,t,this.getCatalogHelperService())}getCartHelperService(){return this.getOrCreateService("CartHelperService",A,this.getLocationHelperService())}getCartService(t){return this.getOrCreateService(`CartService_${t.getUniqueKey()}`,U,t,this.getCartHelperService())}getUserService(t){return this.getOrCreateService(`UserService_${t.getUniqueKey()}`,B,t)}getPaymentProviderService(){return this.getOrCreateService("PaymentProviderService",H)}getPaymentService(){return this.getOrCreateService("PaymentService",Y,this.getPaymentProviderService())}getCheckoutHelperService(){return this.getOrCreateService("CheckoutHelperService",O,this.getLocationHelperService())}getCheckoutService(t){return this.getOrCreateService(`CheckoutService_${t.getUniqueKey()}`,W,t,this.getCheckoutHelperService())}}j.instance=null;class k{constructor(t,e){this.address={autocomplete:async t=>(await this.ensureAuthenticated(),this.addressService.autocomplete(t,this.config.googlePlacesApiKey)),details:async t=>(await this.ensureAuthenticated(),this.addressService.details(t,this.config.googlePlacesApiKey))},this.catalog={availability:async t=>(await this.ensureAuthenticated(),this.catalogService.availability(t)),search:async t=>(await this.ensureAuthenticated(),this.catalogService.search(t))},this.cart={get:async(t,e)=>(await this.ensureAuthenticated(),this.cartService.get(t,e)),update:async t=>(await this.ensureAuthenticated(),this.cartService.update(t))},this.user={session:async t=>(await this.ensureAuthenticated(),this.userService.createOrUpdateSession(t)),purge:async t=>(await this.ensureAuthenticated(),this.userService.purge(t)),addAddress:async t=>(await this.ensureAuthenticated(),this.userService.addAddress(t)),updateAddress:async t=>(await this.ensureAuthenticated(),this.userService.updateAddress(t)),purgeAddress:async t=>(await this.ensureAuthenticated(),this.userService.purgeAddress(t)),addPayment:async t=>(await this.ensureAuthenticated(),this.userService.addPayment(t)),updatePayment:async t=>(await this.ensureAuthenticated(),this.userService.updatePayment(t)),purgePayment:async(t,e)=>(await this.ensureAuthenticated(),this.userService.purgePayment(t,e))},this.payment={mount:async t=>(await this.ensureAuthenticated(),this.paymentService.mount(t)),generateToken:async()=>(await this.ensureAuthenticated(),this.paymentService.generateToken()),subscribe:(t,e)=>{this.paymentService.subscribe(t,e)},unsubscribe:(t,e)=>{this.paymentService.unsubscribe(t,e)},collapse:()=>{this.paymentService.collapse()},unmount:()=>{this.paymentService.unmount()},destroy:()=>{this.paymentService.destroy()}},this.checkout={prepare:async t=>(await this.ensureAuthenticated(),this.checkoutService.prepare(t)),complete:async t=>(await this.ensureAuthenticated(),this.checkoutService.complete(t))},this.config=e,this.singletonManager=j.getInstance();const i=this.determineBaseURL(e);this.authenticatedClient=this.singletonManager.getAuthenticatedClient({apiKey:t,baseURL:i}),this.addressService=this.singletonManager.getAddressService(this.authenticatedClient),this.catalogService=this.singletonManager.getCatalogService(this.authenticatedClient),this.cartService=this.singletonManager.getCartService(this.authenticatedClient),this.userService=this.singletonManager.getUserService(this.authenticatedClient),this.paymentService=this.singletonManager.getPaymentService(),this.checkoutService=this.singletonManager.getCheckoutService(this.authenticatedClient)}determineBaseURL(e){const i=e.env||t.LIQUID_COMMERCE_ENV.STAGE;return S[i]}async init(){try{await this.authenticatedClient.authenticate()}catch(t){throw new Error("Authentication failed during initialization")}}async ensureAuthenticated(){this.authenticatedClient.isTokenExpired()&&await this.authenticatedClient.authenticate()}}async function LiquidCommerce(t,e){const i=j.getInstance();return i.setLiquidCommerceClientConstructor(k),await i.getLiquidCommerceClient(t,e)}window.LiquidCommerce=LiquidCommerce,window.LIQUID_COMMERCE_ENV=t.LIQUID_COMMERCE_ENV,t.LiquidCommerce=LiquidCommerce}));