@plasmicpkgs/commerce-saleor 0.0.36 → 0.0.37

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,2 +1,2 @@
1
- "use strict";function n(n){return n&&"object"==typeof n&&"default"in n?n.default:n}Object.defineProperty(exports,"__esModule",{value:!0});var e=n(require("@plasmicapp/host/registerGlobalContext")),t=require("react"),r=n(t),o=require("@plasmicpkgs/commerce"),u=n(require("js-cookie")),i=n(require("debounce"));function a(n,e,t,r,o,u,i){try{var a=n[u](i),c=a.value}catch(n){return void t(n)}a.done?e(c):Promise.resolve(c).then(r,o)}function c(n){return function(){var e=this,t=arguments;return new Promise((function(r,o){var u=n.apply(e,t);function i(n){a(u,r,o,i,c,"next",n)}function c(n){a(u,r,o,i,c,"throw",n)}i(void 0)}))}}function s(){return(s=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n}).apply(this,arguments)}function l(n,e){if(null==n)return{};var t,r,o={},u=Object.keys(n);for(r=0;r<u.length;r++)e.indexOf(t=u[r])>=0||(o[t]=n[t]);return o}function d(n,e){return n(e={exports:{}},e.exports),e.exports}var p=d((function(n){var e=function(n){var e=Object.prototype,t=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",u=r.asyncIterator||"@@asyncIterator",i=r.toStringTag||"@@toStringTag";function a(n,e,t){return Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),n[e]}try{a({},"")}catch(n){a=function(n,e,t){return n[e]=t}}function c(n,e,t,r){var o=Object.create((e&&e.prototype instanceof d?e:d).prototype),u=new I(r||[]);return o._invoke=function(n,e,t){var r="suspendedStart";return function(o,u){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw u;return{value:void 0,done:!0}}for(t.method=o,t.arg=u;;){var i=t.delegate;if(i){var a=b(i,t);if(a){if(a===l)continue;return a}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===r)throw r="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);r="executing";var c=s(n,e,t);if("normal"===c.type){if(r=t.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:t.done}}"throw"===c.type&&(r="completed",t.method="throw",t.arg=c.arg)}}}(n,t,u),o}function s(n,e,t){try{return{type:"normal",arg:n.call(e,t)}}catch(n){return{type:"throw",arg:n}}}n.wrap=c;var l={};function d(){}function p(){}function f(){}var h={};a(h,o,(function(){return this}));var m=Object.getPrototypeOf,v=m&&m(m(C([])));v&&v!==e&&t.call(v,o)&&(h=v);var g=f.prototype=d.prototype=Object.create(h);function y(n){["next","throw","return"].forEach((function(e){a(n,e,(function(n){return this._invoke(e,n)}))}))}function k(n,e){var r;this._invoke=function(o,u){function i(){return new e((function(r,i){!function r(o,u,i,a){var c=s(n[o],n,u);if("throw"!==c.type){var l=c.arg,d=l.value;return d&&"object"==typeof d&&t.call(d,"__await")?e.resolve(d.__await).then((function(n){r("next",n,i,a)}),(function(n){r("throw",n,i,a)})):e.resolve(d).then((function(n){l.value=n,i(l)}),(function(n){return r("throw",n,i,a)}))}a(c.arg)}(o,u,r,i)}))}return r=r?r.then(i,i):i()}}function b(n,e){var t=n.iterator[e.method];if(void 0===t){if(e.delegate=null,"throw"===e.method){if(n.iterator.return&&(e.method="return",e.arg=void 0,b(n,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var r=s(t,n.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,l;var o=r.arg;return o?o.done?(e[n.resultName]=o.value,e.next=n.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function w(n){var e={tryLoc:n[0]};1 in n&&(e.catchLoc=n[1]),2 in n&&(e.finallyLoc=n[2],e.afterLoc=n[3]),this.tryEntries.push(e)}function x(n){var e=n.completion||{};e.type="normal",delete e.arg,n.completion=e}function I(n){this.tryEntries=[{tryLoc:"root"}],n.forEach(w,this),this.reset(!0)}function C(n){if(n){var e=n[o];if(e)return e.call(n);if("function"==typeof n.next)return n;if(!isNaN(n.length)){var r=-1,u=function e(){for(;++r<n.length;)if(t.call(n,r))return e.value=n[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return u.next=u}}return{next:P}}function P(){return{value:void 0,done:!0}}return p.prototype=f,a(g,"constructor",f),a(f,"constructor",p),p.displayName=a(f,i,"GeneratorFunction"),n.isGeneratorFunction=function(n){var e="function"==typeof n&&n.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},n.mark=function(n){return Object.setPrototypeOf?Object.setPrototypeOf(n,f):(n.__proto__=f,a(n,i,"GeneratorFunction")),n.prototype=Object.create(g),n},n.awrap=function(n){return{__await:n}},y(k.prototype),a(k.prototype,u,(function(){return this})),n.AsyncIterator=k,n.async=function(e,t,r,o,u){void 0===u&&(u=Promise);var i=new k(c(e,t,r,o),u);return n.isGeneratorFunction(t)?i:i.next().then((function(n){return n.done?n.value:i.next()}))},y(g),a(g,i,"Generator"),a(g,o,(function(){return this})),a(g,"toString",(function(){return"[object Generator]"})),n.keys=function(n){var e=[];for(var t in n)e.push(t);return e.reverse(),function t(){for(;e.length;){var r=e.pop();if(r in n)return t.value=r,t.done=!1,t}return t.done=!0,t}},n.values=C,I.prototype={constructor:I,reset:function(n){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!n)for(var e in this)"t"===e.charAt(0)&&t.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var n=this.tryEntries[0].completion;if("throw"===n.type)throw n.arg;return this.rval},dispatchException:function(n){if(this.done)throw n;var e=this;function r(t,r){return i.type="throw",i.arg=n,e.next=t,r&&(e.method="next",e.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var u=this.tryEntries[o],i=u.completion;if("root"===u.tryLoc)return r("end");if(u.tryLoc<=this.prev){var a=t.call(u,"catchLoc"),c=t.call(u,"finallyLoc");if(a&&c){if(this.prev<u.catchLoc)return r(u.catchLoc,!0);if(this.prev<u.finallyLoc)return r(u.finallyLoc)}else if(a){if(this.prev<u.catchLoc)return r(u.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return r(u.finallyLoc)}}}},abrupt:function(n,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&t.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var u=o;break}}u&&("break"===n||"continue"===n)&&u.tryLoc<=e&&e<=u.finallyLoc&&(u=null);var i=u?u.completion:{};return i.type=n,i.arg=e,u?(this.method="next",this.next=u.finallyLoc,l):this.complete(i)},complete:function(n,e){if("throw"===n.type)throw n.arg;return"break"===n.type||"continue"===n.type?this.next=n.arg:"return"===n.type?(this.rval=this.arg=n.arg,this.method="return",this.next="end"):"normal"===n.type&&e&&(this.next=e),l},finish:function(n){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.finallyLoc===n)return this.complete(t.completion,t.afterLoc),x(t),l}},catch:function(n){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.tryLoc===n){var r=t.completion;if("throw"===r.type){var o=r.arg;x(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(n,e,t){return this.delegate={iterator:C(n),resultName:e,nextLoc:t},"next"===this.method&&(this.arg=void 0),l}},n}(n.exports);try{regeneratorRuntime=e}catch(n){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}));function f(n,e){var t;return n=null!=(t=n)?t:[{message:"Failed to fetch Saleor API"}],new o.FetcherError({errors:n,status:e})}function h(n){return m.apply(this,arguments)}function m(){return(m=c(p.mark((function n(e){return p.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,e.json();case 2:return n.abrupt("return",f(n.sent.errors,e.status));case 4:case"end":return n.stop()}}),n)})))).apply(this,arguments)}var v=function(){var n=c(p.mark((function n(e){var t,r,o;return p.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!e.ok){n.next=9;break}return n.next=3,e.json();case 3:if(r=(t=n.sent).data,!(o=t.errors)||!o.length){n.next=8;break}throw f(o,e.status);case 8:return n.abrupt("return",r);case 9:return n.next=11,h(e);case 11:throw n.sent;case 12:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),g=function(n){var e=n.count;return{categoryId:n.categoryId,filter:{search:n.search},sortBy:s({field:"NAME",direction:"ASC"},function(n,e){var t={};switch(n){case"price-asc":t={field:"PRICE",direction:"ASC"};break;case"price-desc":t={field:"PRICE",direction:"DESC"};break;case"trending-desc":t={};break;case"latest-desc":t={field:"DATE",direction:"DESC"}}return t}(n.sort),{channel:"default-channel"}),first:e}},y=function(n){var e,t=(null==(e=u.get("saleor.CheckoutID"))?void 0:e.split(":"))||[];return{checkoutId:t[0],checkoutToken:t[1]}},k=function(){var n=c(p.mark((function n(e){var t,r,o,i;return p.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,e({query:'\n mutation CheckoutCreate {\n checkoutCreate(input: { email: "customer@example.com", lines: [], channel: "default-channel" }) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n \n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n\n'});case 2:return r=null==(t=n.sent.checkoutCreate)?void 0:t.checkout,i=(o=null==r?void 0:r.id)+":"+(null==r?void 0:r.token),o&&u.set("saleor.CheckoutID",i,{expires:2592e3,sameSite:"none",secure:!0}),n.abrupt("return",r);case 9:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),b=["id","name","media","variants","description","slug","pricing"],w=function(n){return{value:+n.amount,currencyCode:n.currency||"USD"}},x=function(n){return null==n?void 0:n.map((function(n){return null==n?void 0:n.attributes})).flat(1).reduce((function(n,e){return n.find((function(n){return n.displayName===e.attribute.name}))?n.map((function(n){return n.displayName===e.attribute.name?s({},n,{values:[].concat(n.values,e.values.map((function(n){return{label:null==n?void 0:n.name}})))}):n})):n.concat({__typename:"MultipleChoiceOption",displayName:e.attribute.name,variant:"size",values:e.values.map((function(n){return{label:null==n?void 0:n.name}}))})}),[])},I=function(n){return null==n?void 0:n.map((function(n){var e,t,r=n.id,o=n.sku,u=n.name,i=n.pricing,a=(null==i||null==(e=i.price)?void 0:e.net)&&(null==(t=w(i.price.net))?void 0:t.value);return{id:r,name:u,sku:null!=o?o:r,price:a,listPrice:a,requiresShipping:!0,options:x([n])}}))};function C(n){var e,t,r,o,u=n.id,i=n.name,a=n.media,c=void 0===a?[]:a,d=n.variants,p=n.description,f=n.slug,h=n.pricing,m=l(n,b);return s({id:u,name:i,vendor:"",description:p?null==(e=JSON.parse(p))||null==(t=e.blocks[0])?void 0:t.data.text:"",path:"/"+f,slug:null==f?void 0:f.replace(/^\/+|\/+$/g,""),price:(null==h||null==(r=h.priceRange)||null==(o=r.start)?void 0:o.net)&&w(h.priceRange.start.net)||{value:0,currencyCode:"USD"},images:null!=c&&c.length?c:[{url:"/product-img-placeholder.svg"}],variants:d&&d.length>0?I(d):[],options:d&&d.length>0?x(d):[]},m)}function P(n){var e,t,r,o,u=n.variant,i=n.quantity;return{id:n.id,variantId:String(null==u?void 0:u.id),productId:String(null==u?void 0:u.id),name:""+u.product.name,quantity:i,variant:{id:String(null==u?void 0:u.id),sku:null!=(e=null==u?void 0:u.sku)?e:"",name:null==u?void 0:u.name,image:{url:null!=u&&u.media[0]?null==u?void 0:u.media[0].url:"/product-img-placeholder.svg"},requiresShipping:!1,price:null==u||null==(t=u.pricing)||null==(r=t.price)?void 0:r.gross.amount,listPrice:0},path:String(null==u||null==(o=u.product)?void 0:o.slug),discounts:[],options:[]}}var O=function(n){var e=n.slug;return{id:n.id,name:n.name,slug:e,path:"/"+e}},q=function(n){var e;if(!n)throw new o.CommerceError({message:"Missing checkout payload from response"});var t=null==n?void 0:n.checkout;if(1!==(null==n||null==(e=n.errors)?void 0:e.length)||"PRODUCT_UNAVAILABLE_FOR_PURCHASE"!==n.errors[0].code){if(null!=n&&n.errors&&function(n){if(n&&n.length)throw new o.ValidationError({errors:n.map((function(n){var e=n.code;return{code:null!=e?e:"validation_error",message:n.message||""}}))})}(null==n?void 0:n.errors),!t)throw new o.CommerceError({message:"Missing checkout object from response"});return function(n){var e,t,r,o,u,i,a=n.lines,c=a.length>0?null==a?void 0:a.map(P):[];return{id:n.id,customerId:"",email:"",createdAt:n.created,currency:{code:null==(e=n.totalPrice)?void 0:e.currency},taxesIncluded:!1,lineItems:c,lineItemsSubtotalPrice:null==(t=n.subtotalPrice)||null==(r=t.gross)?void 0:r.amount,subtotalPrice:null==(o=n.subtotalPrice)||null==(u=o.gross)?void 0:u.amount,totalPrice:null==(i=n.totalPrice)?void 0:i.gross.amount,discounts:[]}}(t)}console.error(n.errors[0])},$='\n query CollectionMany( $channel: String = "default-channel") {\n collections(first:100, channel: $channel) {\n edges {\n node {\n id\n name\n slug\n }\n }\n }\n }\n',E='\n query getProductsFromCollection($categoryId: ID!, $first: Int = 100, $channel: String = "default-channel") {\n collection(id: $categoryId, channel: $channel) {\n id\n name\n slug\n products(first: $first) {\n ...ProductConnection\n }\n }\n }\n \n fragment ProductConnection on ProductCountableConnection {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n id\n name\n description\n slug\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n media {\n url\n alt\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n }\n }\n }\n\n',L={fetchOptions:{query:"\n query CheckoutOne($checkoutId: UUID!) {\n checkout(token: $checkoutId) {\n ... on Checkout {\n ...CheckoutDetails\n }\n }\n }\n \n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n\n"},fetcher:function(n){return c(p.mark((function e(){var t,r,o,u,i,a;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=n.options,u=n.fetch,!(r=n.input.cartId)){e.next=7;break}return a=y().checkoutToken,e.next=5,u(s({},o,{variables:{checkoutId:a}}));case 5:i=e.sent;case 7:if((null==(t=i)||!t.completedAt)&&r){e.next=11;break}return e.next=10,k(u);case 10:i=e.sent;case 11:return e.abrupt("return",q(i));case 12:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.useData;return function(n){var r=e({swrOptions:s({revalidateOnFocus:!1},null==n?void 0:n.swrOptions)});return t.useMemo((function(){return Object.create(r,{isEmpty:{get:function(){var n,e;return(null!=(n=null==(e=r.data)?void 0:e.lineItems.length)?n:0)<=0},enumerable:!0}})}),[r])}}},S={fetchOptions:{query:"\n mutation CheckoutLineAdd($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) {\n checkoutLinesAdd(checkoutId: $checkoutId, lines: $lineItems) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n \n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n\n"},fetcher:function(n){return c(p.mark((function e(){var t,r,u,i;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u=n.options,i=n.fetch,!(r=n.input).quantity||Number.isInteger(r.quantity)&&!(r.quantity<1)){e.next=3;break}throw new o.CommerceError({message:"The item quantity has to be a valid integer greater than 0"});case 3:return e.next=5,i(s({},u,{variables:{checkoutId:y().checkoutId,lineItems:[{variantId:r.variantId,quantity:null!=(t=r.quantity)?t:1}]}}));case 5:return e.abrupt("return",q(e.sent.checkoutLinesAdd));case 8:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.fetch;return function(){var n=o.useCart().mutate;return t.useCallback(function(){var t=c(p.mark((function t(r){var o;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e({input:r});case 2:if(!(o=t.sent)){t.next=8;break}return t.next=6,n(o,!1);case 6:t.next=10;break;case 8:return t.next=10,n();case 10:return t.abrupt("return",o);case 11:case"end":return t.stop()}}),t)})));return function(n){return t.apply(this,arguments)}}(),[e,n])}}},D={fetchOptions:{query:"\n mutation CheckoutLineDelete($checkoutId: ID!, $lineId: ID!) {\n checkoutLineDelete(checkoutId: $checkoutId, lineId: $lineId) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n \n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n\n"},fetcher:function(n){return c(p.mark((function e(){var t,r,o;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.input.itemId,r=n.options,o=n.fetch,e.next=3,o(s({},r,{variables:{checkoutId:y().checkoutId,lineId:t}}));case 3:return e.abrupt("return",q(e.sent.checkoutLineDelete));case 5:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.fetch;return function(){var n=o.useCart().mutate;return t.useCallback(function(){var t=c(p.mark((function t(r){var o;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e({input:{itemId:r.id}});case 2:return o=t.sent,t.next=5,n(o,!1);case 5:return t.abrupt("return",o);case 6:case"end":return t.stop()}}),t)})));return function(n){return t.apply(this,arguments)}}(),[e,n])}}},j={fetchOptions:{query:"\n mutation CheckoutLineUpdate($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) {\n checkoutLinesUpdate(checkoutId: $checkoutId, lines: $lineItems) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n \n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n\n"},fetcher:function(n){return c(p.mark((function e(){var t,r,u,i,a,c;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=(t=n.input).itemId,u=t.item,i=n.options,a=n.fetch,!Number.isInteger(u.quantity)){e.next=6;break}if(!(u.quantity<1)){e.next=4;break}return e.abrupt("return",D.fetcher({options:D.fetchOptions,input:{itemId:r},fetch:a}));case 4:e.next=8;break;case 6:if(!u.quantity){e.next=8;break}throw new o.ValidationError({message:"The item quantity has to be a valid integer"});case 8:return c=y().checkoutId,e.next=11,a(s({},i,{variables:{checkoutId:c,lineItems:[{variantId:u.variantId,quantity:u.quantity}]}}));case 11:return e.abrupt("return",q(e.sent.checkoutLinesUpdate));case 14:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.fetch;return function(n){var r;void 0===n&&(n={});var u=n.item,a=o.useCart().mutate;return t.useCallback(i(function(){var n=c(p.mark((function n(t){var r,i,c,s,l,d,f;return p.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(s=null!=(r=t.id)?r:null==u?void 0:u.id,l=null!=(i=t.productId)?i:null==u?void 0:u.productId,d=null!=(c=t.productId)?c:null==u?void 0:u.variantId,s&&l&&d){n.next=5;break}throw new o.ValidationError({message:"Invalid input used for this operation"});case 5:return n.next=7,e({input:{item:{productId:l,variantId:d,quantity:t.quantity},itemId:s}});case 7:return f=n.sent,n.next=10,a(f,!1);case 10:return n.abrupt("return",f);case 11:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),null!=(r=n.wait)?r:500),[e,a])}}},_={fetchOptions:{query:$},fetcher:function(n){return c(p.mark((function e(){var t,r,o,u,i,a;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=n.fetch,r=n.input.categoryId){e.next=9;break}return e.next=5,t({query:$,variables:{first:250}});case 5:return e.abrupt("return",null!=(o=null==(u=e.sent.collections)||null==(i=u.edges)?void 0:i.map((function(n){return O(n.node)})))?o:[]);case 9:return e.next=11,t({query:E,variables:{categoryId:r}});case 11:return e.abrupt("return",null!=(a=e.sent)&&a.collection?[O(null==a?void 0:a.collection)]:[]);case 13:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.useData;return function(n){var r=e({input:[["categoryId",null==n?void 0:n.categoryId]],swrOptions:s({revalidateOnFocus:!1},null==n?void 0:n.swrOptions)});return t.useMemo((function(){return Object.create(r,{isEmpty:{get:function(){var n,e;return(null!=(n=null==(e=r.data)?void 0:e.length)?n:0)<=0},enumerable:!0}})}),[r])}}},A={fetchOptions:{query:'\n query getAllProductVendors($cursor: String, $channel: String = "default-channel") {\n products(first:100,channel: $channel, after: $cursor) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n slug\n }\n cursor\n }\n }\n }\n'},fetcher:function(n){return c(p.mark((function n(){return p.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",[]);case 2:case"end":return n.stop()}}),n)})))()},useHook:function(n){var e=n.useData;return function(n){var r=e({swrOptions:s({revalidateOnFocus:!1},null==n?void 0:n.swrOptions)});return t.useMemo((function(){return Object.create(r,{isEmpty:{get:function(){var n,e;return(null!=(n=null==(e=r.data)?void 0:e.length)?n:0)<=0},enumerable:!0}})}),[r])}}},N={fetchOptions:{query:'\n query ProductMany(\n $first: Int = 100\n $filter: ProductFilterInput\n $sortBy: ProductOrder\n $channel: String = "default-channel"\n ) {\n products(first: $first, channel: $channel, filter: $filter, sortBy: $sortBy) {\n ...ProductConnection\n }\n }\n \n fragment ProductConnection on ProductCountableConnection {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n id\n name\n description\n slug\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n media {\n url\n alt\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n }\n }\n }\n\n'},fetcher:function(n){return c(p.mark((function e(){var t,r,o,u,i,a,c,s,l,d,f;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.options,o=n.fetch,u=(t=n.input).categoryId,e.next=4,o({query:u?E:r.query,method:null==r?void 0:r.method,variables:g(t)});case 4:return i=e.sent,a=u?null!=(c=null==(s=i.collection)||null==(l=s.products)?void 0:l.edges)?c:[]:null!=(d=null==(f=i.products)?void 0:f.edges)?d:[],e.abrupt("return",{products:a.map((function(n){return C(n.node)})),found:!!a.length});case 7:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.useData;return function(n){return void 0===n&&(n={}),e({input:[["search",n.search],["categoryId",n.categoryId],["brandId",n.brandId],["sort",n.sort],["count",n.count]],swrOptions:s({revalidateOnFocus:!1},n.swrOptions)})}}},T='\n query ProductOneById($id: ID!, $channel: String = "default-channel") {\n product(id: $id, channel: $channel) {\n\n slug\n name\n description\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n media {\n url\n alt\n }\n }\n }',F={fetchOptions:{query:T},fetcher:function(n){return c(p.mark((function e(){var t,r,o,u;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=n.fetch,r=n.input.id){e.next=4;break}return e.abrupt("return",null);case 4:return e.next=6,t({query:T,variables:{id:r}});case 6:if((o=e.sent).product){e.next=12;break}return e.next=10,t({query:'\n query ProductOneBySlug($slug: String!, $channel: String = "default-channel") {\n product(slug: $slug, channel: $channel) {\n id\n slug\n name\n description\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n media {\n url\n alt\n }\n }\n }\n',variables:{slug:r}});case 10:return e.abrupt("return",(u=e.sent).product?C(u.product):null);case 12:return e.abrupt("return",o.product?C(o.product):null);case 13:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.useData;return function(n){return void 0===n&&(n={}),e({input:[["id",n.id]],swrOptions:s({revalidateOnFocus:!1},n.swrOptions)})}}},R=["locale"],U=function(n){return function(){var e=c(p.mark((function e(t){var r,o,i,a,c,s,d,f;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=void 0===(r=t.url)?n:r,a=void 0===(i=t.method)?"POST":i,c=t.query,d=l(null!=(s=t.variables)?s:{},R),f=u.get("saleor.Token"),e.t0=v,e.next=6,fetch(o,{method:a,body:JSON.stringify({query:c,variables:d}),headers:{Authorization:"JWT "+f,"Content-Type":"application/json"}});case 6:return e.t1=e.sent,e.abrupt("return",(0,e.t0)(e.t1));case 8:case"end":return e.stop()}}),e)})));return function(n){return e.apply(this,arguments)}}()},M=function(n){return o.getCommerceProvider(function(n){return{locale:"en-us",cartCookie:"saleor.CheckoutID",fetcher:U(n),cart:{useCart:L,useAddItem:S,useUpdateItem:j,useRemoveItem:D},products:{useSearch:N,useProduct:F},site:{useCategories:_,useBrands:A}}}(n))},G={name:"plasmic-commerce-saleor-provider",displayName:"Saleor Provider",props:{saleorApiUrl:{type:"string",defaultValue:"https://vercel.saleor.cloud/graphql/"}},importPath:"@plasmicpkgs/commerce-saleor",importName:"CommerceProviderComponent"};function H(n){var e=n.saleorApiUrl,t=n.children,o=r.useMemo((function(){return M(e)}),[e]);return r.createElement(o,null,t)}function B(n,t){!function(){n?n.registerGlobalContext.apply(n,arguments):e.apply(void 0,arguments)}(H,null!=t?t:G)}exports.getCommerceProvider=M,exports.registerAll=function(n){B(n)},exports.registerCommerceProvider=B,exports.useCommerce=function(){return o.useCommerce()};
1
+ "use strict";function n(n){return n&&"object"==typeof n&&"default"in n?n.default:n}Object.defineProperty(exports,"__esModule",{value:!0});var e=n(require("@plasmicapp/host/registerGlobalContext")),t=require("react"),r=n(t),o=require("@plasmicpkgs/commerce"),i=n(require("js-cookie")),u=n(require("debounce"));function a(n,e,t,r,o,i,u){try{var a=n[i](u),c=a.value}catch(n){return void t(n)}a.done?e(c):Promise.resolve(c).then(r,o)}function c(n){return function(){var e=this,t=arguments;return new Promise((function(r,o){var i=n.apply(e,t);function u(n){a(i,r,o,u,c,"next",n)}function c(n){a(i,r,o,u,c,"throw",n)}u(void 0)}))}}function s(){return(s=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n}).apply(this,arguments)}function l(n,e){if(null==n)return{};var t,r,o={},i=Object.keys(n);for(r=0;r<i.length;r++)e.indexOf(t=i[r])>=0||(o[t]=n[t]);return o}function d(n,e){return n(e={exports:{}},e.exports),e.exports}var p=d((function(n){var e=function(n){var e=Object.prototype,t=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",i=r.asyncIterator||"@@asyncIterator",u=r.toStringTag||"@@toStringTag";function a(n,e,t){return Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),n[e]}try{a({},"")}catch(n){a=function(n,e,t){return n[e]=t}}function c(n,e,t,r){var o=Object.create((e&&e.prototype instanceof d?e:d).prototype),i=new I(r||[]);return o._invoke=function(n,e,t){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return{value:void 0,done:!0}}for(t.method=o,t.arg=i;;){var u=t.delegate;if(u){var a=b(u,t);if(a){if(a===l)continue;return a}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===r)throw r="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);r="executing";var c=s(n,e,t);if("normal"===c.type){if(r=t.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:t.done}}"throw"===c.type&&(r="completed",t.method="throw",t.arg=c.arg)}}}(n,t,i),o}function s(n,e,t){try{return{type:"normal",arg:n.call(e,t)}}catch(n){return{type:"throw",arg:n}}}n.wrap=c;var l={};function d(){}function p(){}function f(){}var h={};a(h,o,(function(){return this}));var m=Object.getPrototypeOf,v=m&&m(m(C([])));v&&v!==e&&t.call(v,o)&&(h=v);var g=f.prototype=d.prototype=Object.create(h);function y(n){["next","throw","return"].forEach((function(e){a(n,e,(function(n){return this._invoke(e,n)}))}))}function k(n,e){var r;this._invoke=function(o,i){function u(){return new e((function(r,u){!function r(o,i,u,a){var c=s(n[o],n,i);if("throw"!==c.type){var l=c.arg,d=l.value;return d&&"object"==typeof d&&t.call(d,"__await")?e.resolve(d.__await).then((function(n){r("next",n,u,a)}),(function(n){r("throw",n,u,a)})):e.resolve(d).then((function(n){l.value=n,u(l)}),(function(n){return r("throw",n,u,a)}))}a(c.arg)}(o,i,r,u)}))}return r=r?r.then(u,u):u()}}function b(n,e){var t=n.iterator[e.method];if(void 0===t){if(e.delegate=null,"throw"===e.method){if(n.iterator.return&&(e.method="return",e.arg=void 0,b(n,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var r=s(t,n.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,l;var o=r.arg;return o?o.done?(e[n.resultName]=o.value,e.next=n.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function w(n){var e={tryLoc:n[0]};1 in n&&(e.catchLoc=n[1]),2 in n&&(e.finallyLoc=n[2],e.afterLoc=n[3]),this.tryEntries.push(e)}function x(n){var e=n.completion||{};e.type="normal",delete e.arg,n.completion=e}function I(n){this.tryEntries=[{tryLoc:"root"}],n.forEach(w,this),this.reset(!0)}function C(n){if(n){var e=n[o];if(e)return e.call(n);if("function"==typeof n.next)return n;if(!isNaN(n.length)){var r=-1,i=function e(){for(;++r<n.length;)if(t.call(n,r))return e.value=n[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:P}}function P(){return{value:void 0,done:!0}}return p.prototype=f,a(g,"constructor",f),a(f,"constructor",p),p.displayName=a(f,u,"GeneratorFunction"),n.isGeneratorFunction=function(n){var e="function"==typeof n&&n.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},n.mark=function(n){return Object.setPrototypeOf?Object.setPrototypeOf(n,f):(n.__proto__=f,a(n,u,"GeneratorFunction")),n.prototype=Object.create(g),n},n.awrap=function(n){return{__await:n}},y(k.prototype),a(k.prototype,i,(function(){return this})),n.AsyncIterator=k,n.async=function(e,t,r,o,i){void 0===i&&(i=Promise);var u=new k(c(e,t,r,o),i);return n.isGeneratorFunction(t)?u:u.next().then((function(n){return n.done?n.value:u.next()}))},y(g),a(g,u,"Generator"),a(g,o,(function(){return this})),a(g,"toString",(function(){return"[object Generator]"})),n.keys=function(n){var e=[];for(var t in n)e.push(t);return e.reverse(),function t(){for(;e.length;){var r=e.pop();if(r in n)return t.value=r,t.done=!1,t}return t.done=!0,t}},n.values=C,I.prototype={constructor:I,reset:function(n){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!n)for(var e in this)"t"===e.charAt(0)&&t.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var n=this.tryEntries[0].completion;if("throw"===n.type)throw n.arg;return this.rval},dispatchException:function(n){if(this.done)throw n;var e=this;function r(t,r){return u.type="throw",u.arg=n,e.next=t,r&&(e.method="next",e.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var a=t.call(i,"catchLoc"),c=t.call(i,"finallyLoc");if(a&&c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(n,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&t.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===n||"continue"===n)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var u=i?i.completion:{};return u.type=n,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(u)},complete:function(n,e){if("throw"===n.type)throw n.arg;return"break"===n.type||"continue"===n.type?this.next=n.arg:"return"===n.type?(this.rval=this.arg=n.arg,this.method="return",this.next="end"):"normal"===n.type&&e&&(this.next=e),l},finish:function(n){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.finallyLoc===n)return this.complete(t.completion,t.afterLoc),x(t),l}},catch:function(n){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.tryLoc===n){var r=t.completion;if("throw"===r.type){var o=r.arg;x(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(n,e,t){return this.delegate={iterator:C(n),resultName:e,nextLoc:t},"next"===this.method&&(this.arg=void 0),l}},n}(n.exports);try{regeneratorRuntime=e}catch(n){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}));function f(n,e){var t;return n=null!=(t=n)?t:[{message:"Failed to fetch Saleor API"}],new o.FetcherError({errors:n,status:e})}function h(n){return m.apply(this,arguments)}function m(){return(m=c(p.mark((function n(e){return p.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,e.json();case 2:return n.abrupt("return",f(n.sent.errors,e.status));case 4:case"end":return n.stop()}}),n)})))).apply(this,arguments)}var v=function(){var n=c(p.mark((function n(e){var t,r,o;return p.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!e.ok){n.next=9;break}return n.next=3,e.json();case 3:if(r=(t=n.sent).data,!(o=t.errors)||!o.length){n.next=8;break}throw f(o,e.status);case 8:return n.abrupt("return",r);case 9:return n.next=11,h(e);case 11:throw n.sent;case 12:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),g=function(n){var e=n.count;return{categoryId:n.categoryId,filter:{search:n.search},sortBy:s({field:"NAME",direction:"ASC"},function(n,e){var t={};switch(n){case"price-asc":t={field:"PRICE",direction:"ASC"};break;case"price-desc":t={field:"PRICE",direction:"DESC"};break;case"trending-desc":t={};break;case"latest-desc":t={field:"DATE",direction:"DESC"}}return t}(n.sort),{channel:"default-channel"}),first:e}},y=function(n){var e,t=(null==(e=i.get("saleor.CheckoutID"))?void 0:e.split(":"))||[];return{checkoutId:t[0],checkoutToken:t[1]}},k=function(){var n=c(p.mark((function n(e){var t,r,o,u;return p.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,e({query:'\n mutation CheckoutCreate {\n checkoutCreate(input: { email: "customer@example.com", lines: [], channel: "default-channel" }) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n \n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n\n'});case 2:return r=null==(t=n.sent.checkoutCreate)?void 0:t.checkout,u=(o=null==r?void 0:r.id)+":"+(null==r?void 0:r.token),o&&i.set("saleor.CheckoutID",u,{expires:2592e3,sameSite:"none",secure:!0}),n.abrupt("return",r);case 9:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),b=["id","name","media","variants","description","slug","pricing"],w=function(n){return{value:+n.amount,currencyCode:n.currency||"USD"}},x=function(n){return null==n?void 0:n.map((function(n){return null==n?void 0:n.attributes})).flat(1).reduce((function(n,e){return n.find((function(n){return n.displayName===e.attribute.name}))?n.map((function(n){return n.displayName===e.attribute.name?s({},n,{values:[].concat(n.values,e.values.map((function(n){return{label:null==n?void 0:n.name}})))}):n})):n.concat({__typename:"MultipleChoiceOption",displayName:e.attribute.name,variant:"size",values:e.values.map((function(n){return{label:null==n?void 0:n.name}}))})}),[])},I=function(n){return null==n?void 0:n.map((function(n){var e,t,r=n.id,o=n.sku,i=n.name,u=n.pricing,a=(null==u||null==(e=u.price)?void 0:e.net)&&(null==(t=w(u.price.net))?void 0:t.value);return{id:r,name:i,sku:null!=o?o:r,price:a,listPrice:a,requiresShipping:!0,options:x([n])}}))};function C(n){var e,t,r,o,i=n.id,u=n.name,a=n.media,c=void 0===a?[]:a,d=n.variants,p=n.description,f=n.slug,h=n.pricing,m=l(n,b);return s({id:i,name:u,vendor:"",description:p?null==(e=JSON.parse(p))||null==(t=e.blocks[0])?void 0:t.data.text:"",path:"/"+f,slug:null==f?void 0:f.replace(/^\/+|\/+$/g,""),price:(null==h||null==(r=h.priceRange)||null==(o=r.start)?void 0:o.net)&&w(h.priceRange.start.net)||{value:0,currencyCode:"USD"},images:null!=c&&c.length?c:[{url:"/product-img-placeholder.svg"}],variants:d&&d.length>0?I(d):[],options:d&&d.length>0?x(d):[]},m)}function P(n){var e,t,r,o,i=n.variant,u=n.quantity;return{id:n.id,variantId:String(null==i?void 0:i.id),productId:String(null==i?void 0:i.id),name:""+i.product.name,quantity:u,variant:{id:String(null==i?void 0:i.id),sku:null!=(e=null==i?void 0:i.sku)?e:"",name:null==i?void 0:i.name,image:{url:null!=i&&i.media[0]?null==i?void 0:i.media[0].url:"/product-img-placeholder.svg"},requiresShipping:!1,price:null==i||null==(t=i.pricing)||null==(r=t.price)?void 0:r.gross.amount,listPrice:0},path:String(null==i||null==(o=i.product)?void 0:o.slug),discounts:[],options:[]}}var O=function(n){var e=n.slug;return{id:n.id,name:n.name,slug:e,path:"/"+e}},q=function(n){var e;if(!n)throw new o.CommerceError({message:"Missing checkout payload from response"});var t=null==n?void 0:n.checkout;if(1!==(null==n||null==(e=n.errors)?void 0:e.length)||"PRODUCT_UNAVAILABLE_FOR_PURCHASE"!==n.errors[0].code){if(null!=n&&n.errors&&function(n){if(n&&n.length)throw new o.ValidationError({errors:n.map((function(n){var e=n.code;return{code:null!=e?e:"validation_error",message:n.message||""}}))})}(null==n?void 0:n.errors),!t)throw new o.CommerceError({message:"Missing checkout object from response"});return function(n){var e,t,r,o,i,u,a=n.lines,c=a.length>0?null==a?void 0:a.map(P):[];return{id:n.id,customerId:"",email:"",createdAt:n.created,currency:{code:null==(e=n.totalPrice)?void 0:e.currency},taxesIncluded:!1,lineItems:c,lineItemsSubtotalPrice:null==(t=n.subtotalPrice)||null==(r=t.gross)?void 0:r.amount,subtotalPrice:null==(o=n.subtotalPrice)||null==(i=o.gross)?void 0:i.amount,totalPrice:null==(u=n.totalPrice)?void 0:u.gross.amount,discounts:[]}}(t)}console.error(n.errors[0])},$='\n query CollectionMany( $channel: String = "default-channel") {\n collections(first:100, channel: $channel) {\n edges {\n node {\n id\n name\n slug\n }\n }\n }\n }\n',E='\n query getProductsFromCollection($categoryId: ID!, $first: Int = 100, $channel: String = "default-channel") {\n collection(id: $categoryId, channel: $channel) {\n id\n name\n slug\n products(first: $first) {\n ...ProductConnection\n }\n }\n }\n \n fragment ProductConnection on ProductCountableConnection {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n id\n name\n description\n slug\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n media {\n url\n alt\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n }\n }\n }\n\n',L={fetchOptions:{query:"\n query CheckoutOne($checkoutId: UUID!) {\n checkout(token: $checkoutId) {\n ... on Checkout {\n ...CheckoutDetails\n }\n }\n }\n \n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n\n"},fetcher:function(n){return c(p.mark((function e(){var t,r,o,i,u,a;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=n.options,i=n.fetch,!(r=n.input.cartId)){e.next=7;break}return a=y().checkoutToken,e.next=5,i(s({},o,{variables:{checkoutId:a}}));case 5:u=e.sent;case 7:if((null==(t=u)||!t.completedAt)&&r){e.next=11;break}return e.next=10,k(i);case 10:u=e.sent;case 11:return e.abrupt("return",q(u));case 12:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.useData;return function(n){var r=e({swrOptions:s({revalidateOnFocus:!1},null==n?void 0:n.swrOptions)});return t.useMemo((function(){return Object.create(r,{isEmpty:{get:function(){var n,e;return(null!=(n=null==(e=r.data)?void 0:e.lineItems.length)?n:0)<=0},enumerable:!0}})}),[r])}}},S={fetchOptions:{query:"\n mutation CheckoutLineAdd($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) {\n checkoutLinesAdd(checkoutId: $checkoutId, lines: $lineItems) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n \n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n\n"},fetcher:function(n){return c(p.mark((function e(){var t,r,i,u;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=n.options,u=n.fetch,!(r=n.input).quantity||Number.isInteger(r.quantity)&&!(r.quantity<1)){e.next=3;break}throw new o.CommerceError({message:"The item quantity has to be a valid integer greater than 0"});case 3:return e.next=5,u(s({},i,{variables:{checkoutId:y().checkoutId,lineItems:[{variantId:r.variantId,quantity:null!=(t=r.quantity)?t:1}]}}));case 5:return e.abrupt("return",q(e.sent.checkoutLinesAdd));case 8:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.fetch;return function(){var n=o.useCart().mutate;return t.useCallback(function(){var t=c(p.mark((function t(r){var o;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e({input:r});case 2:if(!(o=t.sent)){t.next=8;break}return t.next=6,n(o,!1);case 6:t.next=10;break;case 8:return t.next=10,n();case 10:return t.abrupt("return",o);case 11:case"end":return t.stop()}}),t)})));return function(n){return t.apply(this,arguments)}}(),[e,n])}}},D={fetchOptions:{query:"\n mutation CheckoutLineDelete($checkoutId: ID!, $lineId: ID!) {\n checkoutLineDelete(checkoutId: $checkoutId, lineId: $lineId) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n \n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n\n"},fetcher:function(n){return c(p.mark((function e(){var t,r,o;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.input.itemId,r=n.options,o=n.fetch,e.next=3,o(s({},r,{variables:{checkoutId:y().checkoutId,lineId:t}}));case 3:return e.abrupt("return",q(e.sent.checkoutLineDelete));case 5:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.fetch;return function(){var n=o.useCart().mutate;return t.useCallback(function(){var t=c(p.mark((function t(r){var o;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e({input:{itemId:r.id}});case 2:return o=t.sent,t.next=5,n(o,!1);case 5:return t.abrupt("return",o);case 6:case"end":return t.stop()}}),t)})));return function(n){return t.apply(this,arguments)}}(),[e,n])}}},j={fetchOptions:{query:"\n mutation CheckoutLineUpdate($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) {\n checkoutLinesUpdate(checkoutId: $checkoutId, lines: $lineItems) {\n errors {\n code\n field\n message\n }\n checkout {\n ...CheckoutDetails\n }\n }\n }\n \n fragment CheckoutDetails on Checkout {\n id\n token\n created\n totalPrice {\n currency\n gross {\n amount\n }\n }\n subtotalPrice {\n currency\n gross {\n amount\n }\n }\n\n lines {\n id\n variant {\n id\n name\n sku\n product {\n name\n slug\n }\n media {\n url\n }\n pricing {\n price {\n gross {\n amount\n }\n }\n }\n }\n quantity\n totalPrice {\n currency\n gross {\n amount\n }\n }\n }\n }\n\n"},fetcher:function(n){return c(p.mark((function e(){var t,r,i,u,a,c;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=(t=n.input).itemId,i=t.item,u=n.options,a=n.fetch,!Number.isInteger(i.quantity)){e.next=6;break}if(!(i.quantity<1)){e.next=4;break}return e.abrupt("return",D.fetcher({options:D.fetchOptions,input:{itemId:r},fetch:a}));case 4:e.next=8;break;case 6:if(!i.quantity){e.next=8;break}throw new o.ValidationError({message:"The item quantity has to be a valid integer"});case 8:return c=y().checkoutId,e.next=11,a(s({},u,{variables:{checkoutId:c,lineItems:[{variantId:i.variantId,quantity:i.quantity}]}}));case 11:return e.abrupt("return",q(e.sent.checkoutLinesUpdate));case 14:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.fetch;return function(n){var r;void 0===n&&(n={});var i=n.item,a=o.useCart().mutate;return t.useCallback(u(function(){var n=c(p.mark((function n(t){var r,u,c,s,l,d,f;return p.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(s=null!=(r=t.id)?r:null==i?void 0:i.id,l=null!=(u=t.productId)?u:null==i?void 0:i.productId,d=null!=(c=t.productId)?c:null==i?void 0:i.variantId,s&&l&&d){n.next=5;break}throw new o.ValidationError({message:"Invalid input used for this operation"});case 5:return n.next=7,e({input:{item:{productId:l,variantId:d,quantity:t.quantity},itemId:s}});case 7:return f=n.sent,n.next=10,a(f,!1);case 10:return n.abrupt("return",f);case 11:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),null!=(r=n.wait)?r:500),[e,a])}}},_={fetchOptions:{query:$},fetcher:function(n){return c(p.mark((function e(){var t,r,o,i,u,a;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=n.fetch,r=n.input.categoryId){e.next=9;break}return e.next=5,t({query:$,variables:{first:250}});case 5:return e.abrupt("return",null!=(o=null==(i=e.sent.collections)||null==(u=i.edges)?void 0:u.map((function(n){return O(n.node)})))?o:[]);case 9:return e.next=11,t({query:E,variables:{categoryId:r}});case 11:return e.abrupt("return",null!=(a=e.sent)&&a.collection?[O(null==a?void 0:a.collection)]:[]);case 13:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.useData;return function(n){var r=e({input:[["categoryId",null==n?void 0:n.categoryId]],swrOptions:s({revalidateOnFocus:!1},null==n?void 0:n.swrOptions)});return t.useMemo((function(){return Object.create(r,{isEmpty:{get:function(){var n,e;return(null!=(n=null==(e=r.data)?void 0:e.length)?n:0)<=0},enumerable:!0}})}),[r])}}},A={fetchOptions:{query:'\n query getAllProductVendors($cursor: String, $channel: String = "default-channel") {\n products(first:100,channel: $channel, after: $cursor) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n slug\n }\n cursor\n }\n }\n }\n'},fetcher:function(n){return c(p.mark((function n(){return p.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",[]);case 2:case"end":return n.stop()}}),n)})))()},useHook:function(n){var e=n.useData;return function(n){var r=e({swrOptions:s({revalidateOnFocus:!1},null==n?void 0:n.swrOptions)});return t.useMemo((function(){return Object.create(r,{isEmpty:{get:function(){var n,e;return(null!=(n=null==(e=r.data)?void 0:e.length)?n:0)<=0},enumerable:!0}})}),[r])}}},N={fetchOptions:{query:'\n query ProductMany(\n $first: Int = 100\n $filter: ProductFilterInput\n $sortBy: ProductOrder\n $channel: String = "default-channel"\n ) {\n products(first: $first, channel: $channel, filter: $filter, sortBy: $sortBy) {\n ...ProductConnection\n }\n }\n \n fragment ProductConnection on ProductCountableConnection {\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n edges {\n node {\n id\n name\n description\n slug\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n media {\n url\n alt\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n }\n }\n }\n\n'},fetcher:function(n){return c(p.mark((function e(){var t,r,o,i,u,a,c,s,l,d,f;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.options,o=n.fetch,i=(t=n.input).categoryId,e.next=4,o({query:i?E:r.query,method:null==r?void 0:r.method,variables:g(t)});case 4:return u=e.sent,a=i?null!=(c=null==(s=u.collection)||null==(l=s.products)?void 0:l.edges)?c:[]:null!=(d=null==(f=u.products)?void 0:f.edges)?d:[],e.abrupt("return",{products:a.map((function(n){return C(n.node)})),found:!!a.length});case 7:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.useData;return function(n){return void 0===n&&(n={}),e({input:[["search",n.search],["categoryId",n.categoryId],["brandId",n.brandId],["sort",n.sort],["count",n.count]],swrOptions:s({revalidateOnFocus:!1},n.swrOptions)})}}},T='\n query ProductOneById($id: ID!, $channel: String = "default-channel") {\n product(id: $id, channel: $channel) {\n\n slug\n name\n description\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n media {\n url\n alt\n }\n }\n }',F={fetchOptions:{query:T},fetcher:function(n){return c(p.mark((function e(){var t,r,o,i;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=n.fetch,r=n.input.id){e.next=4;break}return e.abrupt("return",null);case 4:return e.next=6,t({query:T,variables:{id:r}});case 6:if((o=e.sent).product){e.next=12;break}return e.next=10,t({query:'\n query ProductOneBySlug($slug: String!, $channel: String = "default-channel") {\n product(slug: $slug, channel: $channel) {\n id\n slug\n name\n description\n pricing {\n priceRange {\n start {\n net {\n amount\n }\n }\n }\n }\n variants {\n id\n name\n attributes {\n attribute {\n name\n }\n values {\n name\n }\n }\n pricing {\n price {\n net {\n amount\n currency\n }\n }\n }\n }\n media {\n url\n alt\n }\n }\n }\n',variables:{slug:r}});case 10:return e.abrupt("return",(i=e.sent).product?C(i.product):null);case 12:return e.abrupt("return",o.product?C(o.product):null);case 13:case"end":return e.stop()}}),e)})))()},useHook:function(n){var e=n.useData;return function(n){return void 0===n&&(n={}),e({input:[["id",n.id]],swrOptions:s({revalidateOnFocus:!1},n.swrOptions)})}}},R=["locale"],U=function(n){return function(){var e=c(p.mark((function e(t){var r,o,u,a,c,s,d,f;return p.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=void 0===(r=t.url)?n:r,a=void 0===(u=t.method)?"POST":u,c=t.query,d=l(null!=(s=t.variables)?s:{},R),f=i.get("saleor.Token"),e.t0=v,e.next=6,fetch(o,{method:a,body:JSON.stringify({query:c,variables:d}),headers:{Authorization:"JWT "+f,"Content-Type":"application/json"}});case 6:return e.t1=e.sent,e.abrupt("return",(0,e.t0)(e.t1));case 8:case"end":return e.stop()}}),e)})));return function(n){return e.apply(this,arguments)}}()},M=function(n){return o.getCommerceProvider(function(n){return{locale:"en-us",cartCookie:"saleor.CheckoutID",fetcher:U(n),cart:{useCart:L,useAddItem:S,useUpdateItem:j,useRemoveItem:D},products:{useSearch:N,useProduct:F},site:{useCategories:_,useBrands:A}}}(n))},G={name:"plasmic-commerce-saleor-provider",displayName:"Saleor Provider",props:{saleorApiUrl:{type:"string",defaultValue:"https://vercel.saleor.cloud/graphql/"}},importPath:"@plasmicpkgs/commerce-saleor",importName:"CommerceProviderComponent"};function H(n){var e=n.saleorApiUrl,t=n.children,o=r.useMemo((function(){return M(e)}),[e]);return r.createElement(o,null,t)}function B(n,t){!function(){n?n.registerGlobalContext.apply(n,arguments):e.apply(void 0,arguments)}(H,null!=t?t:G)}exports.CommerceProviderComponent=H,exports.getCommerceProvider=M,exports.registerAll=function(n){B(n)},exports.registerCommerceProvider=B,exports.useCommerce=function(){return o.useCommerce()};
2
2
  //# sourceMappingURL=commerce-saleor.cjs.production.min.js.map