@redotech/redo-hydrogen 1.1.3 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 1.2.1
2
+
3
+ - Fix root types exports
4
+
5
+ ### 1.2.0
6
+
7
+ - If cart is a CartWithActionsDocs, use those cart manipulation functions instead of fetchers
8
+
1
9
  ### 1.1.3
2
10
 
3
11
  - Allow both Cart and CartWithActionsDocs as cart inputs
package/dist/cjs/index.js CHANGED
@@ -7,5 +7,5 @@
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
- */function p(){return l||(l=1,"production"!==process.env.NODE_ENV&&function(){var r=e,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),c=Symbol.for("react.provider"),u=Symbol.for("react.context"),s=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),v=Symbol.for("react.lazy"),y=Symbol.for("react.offscreen"),h=Symbol.iterator;var b=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function m(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=b.ReactDebugCurrentFrame,o=n.getStackAddendum();""!==o&&(r+="%s",t=t.concat([o]));var a=t.map((function(e){return String(e)}));a.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,a)}("error",e,t)}var g;function E(e){return e.displayName||"Context"}function w(e){if(null==e)return null;if("number"==typeof e.tag&&m("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case o:return"Fragment";case n:return"Portal";case i:return"Profiler";case a:return"StrictMode";case l:return"Suspense";case f:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return E(e)+".Consumer";case c:return E(e._context)+".Provider";case s:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case p:var r=e.displayName||null;return null!==r?r:w(e.type)||"Memo";case v:var t=e,d=t._payload,y=t._init;try{return w(y(d))}catch(e){return null}}return null}g=Symbol.for("react.module.reference");var _,S,I,T,k,R,O,j=Object.assign,C=0;function P(){}P.__reactDisabledLog=!0;var x,A=b.ReactCurrentDispatcher;function N(e,r,t){if(void 0===x)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);x=n&&n[1]||""}return"\n"+x+e}var F,$=!1,D="function"==typeof WeakMap?WeakMap:Map;function U(e,r){if(!e||$)return"";var t,n=F.get(e);if(void 0!==n)return n;$=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=A.current,A.current=null,function(){if(0===C){_=console.log,S=console.info,I=console.warn,T=console.error,k=console.group,R=console.groupCollapsed,O=console.groupEnd;var e={configurable:!0,enumerable:!0,value:P,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}C++}();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(i,[])}catch(e){t=e}Reflect.construct(e,[],i)}else{try{i.call()}catch(e){t=e}e.call(i.prototype)}}else{try{throw Error()}catch(e){t=e}e()}}catch(r){if(r&&t&&"string"==typeof r.stack){for(var c=r.stack.split("\n"),u=t.stack.split("\n"),s=c.length-1,l=u.length-1;s>=1&&l>=0&&c[s]!==u[l];)l--;for(;s>=1&&l>=0;s--,l--)if(c[s]!==u[l]){if(1!==s||1!==l)do{if(s--,--l<0||c[s]!==u[l]){var f="\n"+c[s].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&F.set(e,f),f}}while(s>=1&&l>=0);break}}}finally{$=!1,A.current=o,function(){if(0==--C){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:j({},e,{value:_}),info:j({},e,{value:S}),warn:j({},e,{value:I}),error:j({},e,{value:T}),group:j({},e,{value:k}),groupCollapsed:j({},e,{value:R}),groupEnd:j({},e,{value:O})})}C<0&&m("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var d=e?e.displayName||e.name:"",p=d?N(d):"";return"function"==typeof e&&F.set(e,p),p}function L(e,r,t){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return N(e);switch(e){case l:return N("Suspense");case f:return N("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case s:return U(e.render,!1);case p:return L(e.type,r,t);case v:var o=e,a=o._payload,i=o._init;try{return L(i(a),r,t)}catch(e){}}return""}F=new D;var q=Object.prototype.hasOwnProperty,M={},V=b.ReactDebugCurrentFrame;function W(e){if(e){var r=e._owner,t=L(e.type,e._source,r?r.type:null);V.setExtraStackFrame(t)}else V.setExtraStackFrame(null)}var B=Array.isArray;function z(e){return B(e)}function J(e){return""+e}function X(e){if(function(e){try{return J(e),!1}catch(e){return!0}}(e))return m("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),J(e)}var Y,K,H=b.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,r,n,o,a){var i,c={},u=null,s=null;for(i in void 0!==n&&(X(n),u=""+n),function(e){if(q.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(X(r.key),u=""+r.key),function(e){if(q.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(s=r.ref,function(e){"string"==typeof e.ref&&H.current}(r)),r)q.call(r,i)&&!G.hasOwnProperty(i)&&(c[i]=r[i]);if(e&&e.defaultProps){var l=e.defaultProps;for(i in l)void 0===c[i]&&(c[i]=l[i])}if(u||s){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;u&&function(e,r){var t=function(){Y||(Y=!0,m("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(c,f),s&&function(e,r){var t=function(){K||(K=!0,m("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(c,f)}return function(e,r,n,o,a,i,c){var u={$$typeof:t,type:e,key:r,ref:n,props:c,_owner:i,_store:{}};return Object.defineProperty(u._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(u,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(u,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(u.props),Object.freeze(u)),u}(e,u,s,a,o,H.current,c)}var Z,ee=b.ReactCurrentOwner,re=b.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,t=L(e.type,e._source,r?r.type:null);re.setExtraStackFrame(t)}else re.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===t}function oe(){if(ee.current){var e=w(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var ae={};function ie(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=oe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ae[t]){ae[t]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+w(e._owner.type)+"."),te(e),m('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),te(null)}}}function ce(e,r){if("object"==typeof e)if(z(e))for(var t=0;t<e.length;t++){var n=e[t];ne(n)&&ie(n,r)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=h&&e[h]||e["@@iterator"];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,i=o.call(e);!(a=i.next()).done;)ne(a.value)&&ie(a.value,r)}}function ue(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==s&&t.$$typeof!==p)return;r=t.propTypes}if(r){var n=w(t);!function(e,r,t,n,o){var a=Function.call.bind(q);for(var i in e)if(a(e,i)){var c=void 0;try{if("function"!=typeof e[i]){var u=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw u.name="Invariant Violation",u}c=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){c=e}!c||c instanceof Error||(W(o),m("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof c),W(null)),c instanceof Error&&!(c.message in M)&&(M[c.message]=!0,W(o),m("Failed %s type: %s",t,c.message),W(null))}}(r,e.props,"prop",n,e)}else if(void 0!==t.PropTypes&&!Z){Z=!0,m("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",w(t)||"Unknown")}"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||m("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var se={};function le(e,r,n,d,h,b){var E=function(e){return"string"==typeof e||"function"==typeof e||e===o||e===i||e===a||e===l||e===f||e===y||"object"==typeof e&&null!==e&&(e.$$typeof===v||e.$$typeof===p||e.$$typeof===c||e.$$typeof===u||e.$$typeof===s||e.$$typeof===g||void 0!==e.getModuleId)}(e);if(!E){var _="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(_+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var S;_+=oe(),null===e?S="null":z(e)?S="array":void 0!==e&&e.$$typeof===t?(S="<"+(w(e.type)||"Unknown")+" />",_=" Did you accidentally export a JSX literal instead of a component?"):S=typeof e,m("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",S,_)}var I=Q(e,r,n,h,b);if(null==I)return I;if(E){var T=r.children;if(void 0!==T)if(d)if(z(T)){for(var k=0;k<T.length;k++)ce(T[k],e);Object.freeze&&Object.freeze(T)}else m("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ce(T,e)}if(q.call(r,"key")){var R=w(e),O=Object.keys(r).filter((function(e){return"key"!==e})),j=O.length>0?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}";if(!se[R+j])m('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',j,R,O.length>0?"{"+O.join(": ..., ")+": ...}":"{}",R),se[R+j]=!0}return e===o?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){te(e),m("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),te(null);break}}null!==e.ref&&(te(e),m("Invalid attribute `ref` supplied to `React.Fragment`."),te(null))}(I):ue(I),I}var fe=function(e,r,t){return le(e,r,t,!1)},de=function(e,r,t){return le(e,r,t,!0)};d.Fragment=o,d.jsx=fe,d.jsxs=de}()),d}var v,y=(f||(f=1,"production"===process.env.NODE_ENV?u.exports=function(){if(c)return s;c=1;var r=e,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function u(e,r,n){var c,u={},s=null,l=null;for(c in void 0!==n&&(s=""+n),void 0!==r.key&&(s=""+r.key),void 0!==r.ref&&(l=r.ref),r)o.call(r,c)&&!i.hasOwnProperty(c)&&(u[c]=r[c]);if(e&&e.defaultProps)for(c in r=e.defaultProps)void 0===u[c]&&(u[c]=r[c]);return{$$typeof:t,type:e,key:s,ref:l,props:u,_owner:a.current}}return s.Fragment=n,s.jsx=u,s.jsxs=u,s}():u.exports=p()),u.exports);exports.RedoErrorType=void 0,(v=exports.RedoErrorType||(exports.RedoErrorType={})).ApiBadRequest="API_BAD_REQUEST",v.ApiServerError="API_SERVER_ERROR",v.ApiUnknownError="API_UNKNOWN_ERROR";var h="api.getredo.com",b=[h],m=function(e){var r;return function(e){return Array.isArray(e.lines)&&"linesAdd"in e&&"function"==typeof e.linesAdd}(e)?e.lines:null!==(r=e.lines.nodes)&&void 0!==r?r:e.lines.edges.map((function(e){return e.node}))},g=function(e){return o(void 0,[e],void 0,(function(e){var r,t,n=e.cart,o=e.fetcher,i=e.cartInfoToEnable;return a(this,(function(e){switch(e.label){case 0:return n?[3,2]:[4,_({fetcher:o,cartInfoToEnable:i})];case 1:case 3:return[2,e.sent()];case 2:return r=m(n).filter((function(e){return"re:do"===e.merchandise.product.vendor})),t=null==r?void 0:r.filter((function(e){return e.merchandise.id==="gid://shopify/ProductVariant/".concat(i.variantId)})),0!==r.length?[3,4]:[4,_({fetcher:o,cartInfoToEnable:i})];case 4:return 1!==r.length||1!==t.length||1!==t[0].quantity?[3,5]:[2];case 5:return[4,E({fetcher:o,lineIds:r.map((function(e){return e.id}))})];case 6:return e.sent(),[4,_({fetcher:o,cartInfoToEnable:i})];case 7:return e.sent(),[2]}}))}))},E=function(e){return o(void 0,[e],void 0,(function(e){var r,n,o=e.fetcher,i=e.lineIds;return a(this,(function(e){switch(e.label){case 0:return r={action:t.CartForm.ACTIONS.LinesRemove,inputs:{lineIds:i}},[4,o.submit((n={},n[t.CartForm.INPUT_NAME]=JSON.stringify(r),n),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))},w=function(e){return o(void 0,[e],void 0,(function(e){var r,t=e.cart,n=e.fetcher;return e.cartInfoToEnable,a(this,(function(e){switch(e.label){case 0:return t?0===(r=m(t).filter((function(e){return"re:do"===e.merchandise.product.vendor}))).length?[3,2]:[4,E({fetcher:n,lineIds:r.map((function(e){return e.id}))})]:(console.error("No cart"),[2]);case 1:return e.sent(),[3,2];case 2:return[2]}}))}))},_=function(e){return o(void 0,[e],void 0,(function(e){var r,n,o,i=e.fetcher,c=e.cartInfoToEnable;return a(this,(function(e){switch(e.label){case 0:return r={merchandiseId:"gid://shopify/ProductVariant/".concat(c.variantId),quantity:1,selectedVariant:c.selectedVariant},n={action:t.CartForm.ACTIONS.LinesAdd,inputs:{lines:[r]}},[4,i.submit((o={},o[t.CartForm.INPUT_NAME]=JSON.stringify(n),o),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))},S=function(e){return o(void 0,[e],void 0,(function(e){var r,n,o=e.fetcher,i=e.cartInfoToEnable,c=e.enabled;return a(this,(function(e){switch(e.label){case 0:return r={action:t.CartForm.ACTIONS.AttributesUpdateInput,inputs:{attributes:[{key:(null==i?void 0:i.cartAttribute)||"redo_opted_in_from_cart",value:c.toString()}]}},[4,o.submit((n={},n[t.CartForm.INPUT_NAME]=JSON.stringify(r),n),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))};var I=e.createContext({enabled:!1,loading:!0}),T=function(){var t=e.useContext(I),i=function(t){var i=this,c=r.useFetcher(t),u=e.useRef(null),s=e.useRef(null);s.current||(s.current=new Promise((function(e){u.current=e})));var l=e.useCallback((function(){s.current=new Promise((function(e){u.current=e}))}),[s,u]),f=e.useCallback((function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return o(i,void 0,void 0,(function(){return a(this,(function(r){return c.submit.apply(c,e),[2,s.current]}))}))}),[c,s]);return e.useEffect((function(){var e;"idle"===c.state&&(c.data&&(null===(e=u.current)||void 0===e||e.call(u,c.data)),l())}),[c,l]),n(n({},c),{submit:f})}();return e.useEffect((function(){!t.loading&&t.cartInfoToEnable&&w({fetcher:i,cart:t.cart,cartInfoToEnable:t.cartInfoToEnable})}),[t.loading]),{enable:function(){return o(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return t.loading||!t.cartInfoToEnable?[2,!1]:[4,g({fetcher:i,cart:t.cart,cartInfoToEnable:t.cartInfoToEnable})];case 1:return e.sent(),[4,S({fetcher:i,cartInfoToEnable:t.cartInfoToEnable,enabled:!0})];case 2:return e.sent(),[2,!0]}}))}))},disable:function(){return o(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return t.cartInfoToEnable?[4,w({fetcher:i,cart:t.cart,cartInfoToEnable:t.cartInfoToEnable})]:[2,!1];case 1:return e.sent(),[4,S({fetcher:i,cartInfoToEnable:t.cartInfoToEnable,enabled:!1})];case 2:return e.sent(),[2,!0]}}))}))},get loading(){return t.loading},get eligible(){var e;return!(this.loading||!this.price||!this.cartProduct||!(null===(e=this.cart)||void 0===e?void 0:e.cost))},get enabled(){return t.enabled},get price(){var e,r,n,o=null===(n=null===(r=null===(e=t.cartInfoToEnable)||void 0===e?void 0:e.selectedVariant)||void 0===r?void 0:r.price)||void 0===n?void 0:n.amount;if(o&&"NaN"!==Number(o).toString())return Number(o)},get cart(){return t.cart},get cartProduct(){var e;return null===(e=t.cartInfoToEnable)||void 0===e?void 0:e.selectedVariant},get cartAttribute(){var e;return null===(e=t.cartInfoToEnable)||void 0===e?void 0:e.cartAttribute},get storeId(){return t.storeId},get errors(){return t.errors}}},k=function(e){var r=e.redoCoverageClient,t=e.cart,n=e.storeId;return new Promise((function(e,i){fetch("https://".concat(h,"/v2.2/stores/").concat(n,"/checkout-buttons-ui"),{method:"GET",headers:{"Content-Type":"application/json"}}).then((function(n){return o(void 0,void 0,void 0,(function(){var o,c;return a(this,(function(a){switch(a.label){case 0:return[4,n.json()];case 1:return(o=a.sent()).html?(c=R({redoCoverageClient:r,cart:t,ui:o}))?[2,e(c)]:[2,i(null)]:[2,e(null)]}}))}))}))}))},R=function(e){var r=e.redoCoverageClient,t=e.cart,n=e.ui;if(!r.eligible||!r.price||!(null==t?void 0:t.cost))return null;var o=t.cost.totalAmount.currencyCode;"XXX"===o&&(o="USD");var a=!!m(t).some((function(e){var r,t;return"re:do"===(null===(t=null===(r=e.merchandise)||void 0===r?void 0:r.product)||void 0===t?void 0:t.vendor)})),i=new Intl.NumberFormat("en-US",{style:"currency",currency:o}).format(Number(t.cost.totalAmount.amount)+(a?0:r.price));return i&&i.length&&!i.includes("NaN")?(n.html=n.html.replaceAll("%combinedPrice%",i),n):null},O=function(e,r){return null==e?null:r(e)?e:O(e.parentElement,r)};exports.REDO_REQUIRED_HOSTNAMES=b,exports.RedoCheckoutButtons=function(r){var t,n=T(),i=n.cart,c=(null===(t=n.cart)||void 0===t?void 0:t.checkoutUrl)||"/checkout",u=e.useState(null);u[0],u[1];var s=e.useState(null),l=s[0],f=s[1];e.useEffect((function(){o(void 0,void 0,void 0,(function(){var e;return a(this,(function(r){switch(r.label){case 0:return n.eligible&&i&&n.storeId?[4,k({redoCoverageClient:n,cart:i,storeId:n.storeId})]:[2];case 1:return(e=r.sent())&&f(e),[2]}}))}))}),[i,n.eligible,n.price,n.storeId]);return y.jsx("div",{children:l?y.jsxs("div",{onClick:function(e){return o(void 0,void 0,void 0,(function(){var t,o;return a(this,(function(a){switch(a.label){case 0:return(t=e.target).dataset?O(t,(function(e){var r;return"coverage-button"==(null===(r=e.dataset)||void 0===r?void 0:r.target)}))?[4,n.enable()]:[3,4]:[2];case 1:return o=a.sent(),r.onClick?[4,r.onClick(o)]:[3,3];case 2:a.sent(),a.label=3;case 3:return window.location.href=c,[3,8];case 4:return O(t,(function(e){return"non-coverage-button"==e.dataset.target}))?[4,n.disable()]:[3,8];case 5:return a.sent(),r.onClick?[4,r.onClick(!1)]:[3,7];case 6:a.sent(),a.label=7;case 7:window.location.href=c,a.label=8;case 8:return[2]}}))}))},children:[l.css?y.jsx("style",{children:l.css}):"",y.jsx("div",{dangerouslySetInnerHTML:{__html:l.html}})]}):r.children})},exports.RedoProvider=function(r){var t=r.cart,n=r.storeId,c=r.children,u=e.useState();u[0],u[1];var s=e.useState();s[0],s[1];var l=e.useState(),f=l[0],d=l[1],p=e.useState(!0),v=p[0],b=p[1],g=e.useState([]),E=g[0],w=g[1],_=function(e){return E.find((function(r){return r.type===e.type}))||w(i(i([],E,!0),[e],!1)),e};e.useEffect((function(){var e,r,i,c,u,s,l;if(t&&n){var f=m(t);fetch("https://".concat(h,"/v2.2/stores/").concat(n,"/coverage-products"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cart:{lineItems:f.map((function(e){var r,t,n,o,a,i,c,u,s,l,f;return{id:e.id,originalPrice:{amount:null===(t=null===(r=e.merchandise)||void 0===r?void 0:r.price)||void 0===t?void 0:t.amount,currency:null===(o=null===(n=e.merchandise)||void 0===n?void 0:n.price)||void 0===o?void 0:o.currencyCode},priceTotal:{amount:null===(i=null===(a=e.cost)||void 0===a?void 0:a.totalAmount)||void 0===i?void 0:i.amount,currency:null===(u=null===(c=e.cost)||void 0===c?void 0:c.totalAmount)||void 0===u?void 0:u.currencyCode},product:{id:null===(l=null===(s=e.merchandise)||void 0===s?void 0:s.product)||void 0===l?void 0:l.id},variant:{id:null===(f=e.merchandise)||void 0===f?void 0:f.id},quantity:e.quantity}})),priceTotal:{amount:null===(r=null===(e=t.cost)||void 0===e?void 0:e.totalAmount)||void 0===r?void 0:r.amount,currency:null===(c=null===(i=t.cost)||void 0===i?void 0:i.totalAmount)||void 0===c?void 0:c.currencyCode}},customer:{id:(null===(s=null===(u=t.buyerIdentity)||void 0===u?void 0:u.customer)||void 0===s?void 0:s.id)||"",country:null===(l=t.buyerIdentity)||void 0===l?void 0:l.countryCode}})}).then((function(e){return o(void 0,void 0,void 0,(function(){var r,t,n,o,i,c,u,s,l,f,p,v;return a(this,(function(a){switch(a.label){case 0:return 500!==e.status?[3,2]:(r=_,i={type:exports.RedoErrorType.ApiServerError,message:"Internal server error occured when getting available coverage products from Redo API.. Check your inputs are correct and storeId have been configured. Reach out to Redo support if the issue persists."},c={},[4,e.json()]);case 1:return r.apply(void 0,[(i.context=(c.json=a.sent(),c),i)]),[2];case 2:return 400!==e.status?[3,4]:(t=_,u={type:exports.RedoErrorType.ApiBadRequest,message:"Bad request when getting available coverage products from Redo API. Check that the passed in cart is of the correct type Cart/CartReturn and includes all of the correct cart information."},s={},[4,e.json()]);case 3:return t.apply(void 0,[(u.context=(s.json=a.sent(),s),u)]),[2];case 4:return 200===e.status?[3,6]:(n=_,l={type:exports.RedoErrorType.ApiUnknownError,message:"Unkown error occured while getting available coverage products from Redo API."},f={status:e.status},[4,e.json()]);case 5:return n.apply(void 0,[(l.context=(f.json=a.sent(),f),l)]),[2];case 6:return[4,e.json()];case 7:return o=a.sent(),b(!1),(null===(v=null===(p=null==o?void 0:o.coverageProducts)||void 0===p?void 0:p[0])||void 0===v?void 0:v.cartInfoToEnable)?(d(o.coverageProducts[0].cartInfoToEnable),[2]):[2]}}))}))}))}}),[t,n]);var S={enabled:!0,loading:v,storeId:n,cartInfoToEnable:f,cart:t,errors:(null==E?void 0:E.length)&&E.length>0?E:void 0};return y.jsx(I.Provider,{value:S,children:c})},exports.useLoad=function(r,t){var o=e.useState({pending:!1}),a=o[0],i=o[1];return e.useEffect((function(){var e=new AbortController;return i((function(e){return n(n({},e),{pending:!0})})),r(e.signal).then((function(e){return i({pending:!1,value:e})}),(function(e){e.message.includes("Request aborted for RPC method")||"ERR_CANCELED"===e.code||"Another request is in flight"===e.message||i({pending:!1,error:e})})),function(){e.abort(),i((function(e){return n(n({},e),{pending:!1})}))}}),t),a},exports.useRedoCoverageClient=T;
10
+ */function p(){return l||(l=1,"production"!==process.env.NODE_ENV&&function(){var r=e,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),c=Symbol.for("react.provider"),u=Symbol.for("react.context"),s=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),v=Symbol.for("react.lazy"),y=Symbol.for("react.offscreen"),h=Symbol.iterator;var b=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function m(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=b.ReactDebugCurrentFrame,o=n.getStackAddendum();""!==o&&(r+="%s",t=t.concat([o]));var a=t.map((function(e){return String(e)}));a.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,a)}("error",e,t)}var g;function E(e){return e.displayName||"Context"}function w(e){if(null==e)return null;if("number"==typeof e.tag&&m("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case o:return"Fragment";case n:return"Portal";case i:return"Profiler";case a:return"StrictMode";case l:return"Suspense";case f:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return E(e)+".Consumer";case c:return E(e._context)+".Provider";case s:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case p:var r=e.displayName||null;return null!==r?r:w(e.type)||"Memo";case v:var t=e,d=t._payload,y=t._init;try{return w(y(d))}catch(e){return null}}return null}g=Symbol.for("react.module.reference");var _,S,I,T,k,R,O,j=Object.assign,C=0;function P(){}P.__reactDisabledLog=!0;var x,A=b.ReactCurrentDispatcher;function N(e,r,t){if(void 0===x)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);x=n&&n[1]||""}return"\n"+x+e}var F,$=!1,D="function"==typeof WeakMap?WeakMap:Map;function U(e,r){if(!e||$)return"";var t,n=F.get(e);if(void 0!==n)return n;$=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=A.current,A.current=null,function(){if(0===C){_=console.log,S=console.info,I=console.warn,T=console.error,k=console.group,R=console.groupCollapsed,O=console.groupEnd;var e={configurable:!0,enumerable:!0,value:P,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}C++}();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(i,[])}catch(e){t=e}Reflect.construct(e,[],i)}else{try{i.call()}catch(e){t=e}e.call(i.prototype)}}else{try{throw Error()}catch(e){t=e}e()}}catch(r){if(r&&t&&"string"==typeof r.stack){for(var c=r.stack.split("\n"),u=t.stack.split("\n"),s=c.length-1,l=u.length-1;s>=1&&l>=0&&c[s]!==u[l];)l--;for(;s>=1&&l>=0;s--,l--)if(c[s]!==u[l]){if(1!==s||1!==l)do{if(s--,--l<0||c[s]!==u[l]){var f="\n"+c[s].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&F.set(e,f),f}}while(s>=1&&l>=0);break}}}finally{$=!1,A.current=o,function(){if(0==--C){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:j({},e,{value:_}),info:j({},e,{value:S}),warn:j({},e,{value:I}),error:j({},e,{value:T}),group:j({},e,{value:k}),groupCollapsed:j({},e,{value:R}),groupEnd:j({},e,{value:O})})}C<0&&m("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var d=e?e.displayName||e.name:"",p=d?N(d):"";return"function"==typeof e&&F.set(e,p),p}function L(e,r,t){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return N(e);switch(e){case l:return N("Suspense");case f:return N("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case s:return U(e.render,!1);case p:return L(e.type,r,t);case v:var o=e,a=o._payload,i=o._init;try{return L(i(a),r,t)}catch(e){}}return""}F=new D;var q=Object.prototype.hasOwnProperty,M={},V=b.ReactDebugCurrentFrame;function W(e){if(e){var r=e._owner,t=L(e.type,e._source,r?r.type:null);V.setExtraStackFrame(t)}else V.setExtraStackFrame(null)}var B=Array.isArray;function z(e){return B(e)}function J(e){return""+e}function X(e){if(function(e){try{return J(e),!1}catch(e){return!0}}(e))return m("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),J(e)}var Y,K,H=b.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,r,n,o,a){var i,c={},u=null,s=null;for(i in void 0!==n&&(X(n),u=""+n),function(e){if(q.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(X(r.key),u=""+r.key),function(e){if(q.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(s=r.ref,function(e){"string"==typeof e.ref&&H.current}(r)),r)q.call(r,i)&&!G.hasOwnProperty(i)&&(c[i]=r[i]);if(e&&e.defaultProps){var l=e.defaultProps;for(i in l)void 0===c[i]&&(c[i]=l[i])}if(u||s){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;u&&function(e,r){var t=function(){Y||(Y=!0,m("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(c,f),s&&function(e,r){var t=function(){K||(K=!0,m("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(c,f)}return function(e,r,n,o,a,i,c){var u={$$typeof:t,type:e,key:r,ref:n,props:c,_owner:i,_store:{}};return Object.defineProperty(u._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(u,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(u,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(u.props),Object.freeze(u)),u}(e,u,s,a,o,H.current,c)}var Z,ee=b.ReactCurrentOwner,re=b.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,t=L(e.type,e._source,r?r.type:null);re.setExtraStackFrame(t)}else re.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===t}function oe(){if(ee.current){var e=w(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var ae={};function ie(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=oe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ae[t]){ae[t]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+w(e._owner.type)+"."),te(e),m('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),te(null)}}}function ce(e,r){if("object"==typeof e)if(z(e))for(var t=0;t<e.length;t++){var n=e[t];ne(n)&&ie(n,r)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=h&&e[h]||e["@@iterator"];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,i=o.call(e);!(a=i.next()).done;)ne(a.value)&&ie(a.value,r)}}function ue(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==s&&t.$$typeof!==p)return;r=t.propTypes}if(r){var n=w(t);!function(e,r,t,n,o){var a=Function.call.bind(q);for(var i in e)if(a(e,i)){var c=void 0;try{if("function"!=typeof e[i]){var u=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw u.name="Invariant Violation",u}c=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){c=e}!c||c instanceof Error||(W(o),m("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof c),W(null)),c instanceof Error&&!(c.message in M)&&(M[c.message]=!0,W(o),m("Failed %s type: %s",t,c.message),W(null))}}(r,e.props,"prop",n,e)}else if(void 0!==t.PropTypes&&!Z){Z=!0,m("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",w(t)||"Unknown")}"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||m("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var se={};function le(e,r,n,d,h,b){var E=function(e){return"string"==typeof e||"function"==typeof e||e===o||e===i||e===a||e===l||e===f||e===y||"object"==typeof e&&null!==e&&(e.$$typeof===v||e.$$typeof===p||e.$$typeof===c||e.$$typeof===u||e.$$typeof===s||e.$$typeof===g||void 0!==e.getModuleId)}(e);if(!E){var _="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(_+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var S;_+=oe(),null===e?S="null":z(e)?S="array":void 0!==e&&e.$$typeof===t?(S="<"+(w(e.type)||"Unknown")+" />",_=" Did you accidentally export a JSX literal instead of a component?"):S=typeof e,m("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",S,_)}var I=Q(e,r,n,h,b);if(null==I)return I;if(E){var T=r.children;if(void 0!==T)if(d)if(z(T)){for(var k=0;k<T.length;k++)ce(T[k],e);Object.freeze&&Object.freeze(T)}else m("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ce(T,e)}if(q.call(r,"key")){var R=w(e),O=Object.keys(r).filter((function(e){return"key"!==e})),j=O.length>0?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}";if(!se[R+j])m('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',j,R,O.length>0?"{"+O.join(": ..., ")+": ...}":"{}",R),se[R+j]=!0}return e===o?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){te(e),m("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),te(null);break}}null!==e.ref&&(te(e),m("Invalid attribute `ref` supplied to `React.Fragment`."),te(null))}(I):ue(I),I}var fe=function(e,r,t){return le(e,r,t,!1)},de=function(e,r,t){return le(e,r,t,!0)};d.Fragment=o,d.jsx=fe,d.jsxs=de}()),d}var v,y=(f||(f=1,"production"===process.env.NODE_ENV?u.exports=function(){if(c)return s;c=1;var r=e,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function u(e,r,n){var c,u={},s=null,l=null;for(c in void 0!==n&&(s=""+n),void 0!==r.key&&(s=""+r.key),void 0!==r.ref&&(l=r.ref),r)o.call(r,c)&&!i.hasOwnProperty(c)&&(u[c]=r[c]);if(e&&e.defaultProps)for(c in r=e.defaultProps)void 0===u[c]&&(u[c]=r[c]);return{$$typeof:t,type:e,key:s,ref:l,props:u,_owner:a.current}}return s.Fragment=n,s.jsx=u,s.jsxs=u,s}():u.exports=p()),u.exports);exports.RedoErrorType=void 0,(v=exports.RedoErrorType||(exports.RedoErrorType={})).ApiBadRequest="API_BAD_REQUEST",v.ApiServerError="API_SERVER_ERROR",v.ApiUnknownError="API_UNKNOWN_ERROR";var h="api.getredo.com",b=[h],m=function(e){return Array.isArray(e.lines)&&"linesAdd"in e&&"function"==typeof e.linesAdd},g=function(e){var r;return m(e)?e.lines:null!==(r=e.lines.nodes)&&void 0!==r?r:e.lines.edges.map((function(e){return e.node}))},E=function(e){return new Promise((function(r,t){var n=setInterval((function(){if("idle"===e.status)return clearInterval(n),r()}),100)}))},w=function(e){return o(void 0,[e],void 0,(function(e){var r,t,n=e.cart,o=e.fetcher,i=e.cartInfoToEnable;return a(this,(function(e){switch(e.label){case 0:return n?[3,2]:[4,I({cart:n,fetcher:o,cartInfoToEnable:i})];case 1:case 3:return[2,e.sent()];case 2:return r=g(n).filter((function(e){return"re:do"===e.merchandise.product.vendor})),t=null==r?void 0:r.filter((function(e){return e.merchandise.id==="gid://shopify/ProductVariant/".concat(i.variantId)})),0!==r.length?[3,4]:[4,I({cart:n,fetcher:o,cartInfoToEnable:i})];case 4:return 1!==r.length||1!==t.length||1!==t[0].quantity?[3,5]:[2];case 5:return[4,_({cart:n,fetcher:o,lineIds:r.map((function(e){return e.id}))})];case 6:return e.sent(),[4,I({cart:n,fetcher:o,cartInfoToEnable:i})];case 7:return e.sent(),[2]}}))}))},_=function(e){return o(void 0,[e],void 0,(function(e){var r,n,o=e.cart,i=e.fetcher,c=e.lineIds;return a(this,(function(e){switch(e.label){case 0:return r={action:t.CartForm.ACTIONS.LinesRemove,inputs:{lineIds:c}},o&&m(o)?(o.linesRemove(c),[4,E(o)]):[3,2];case 1:return e.sent(),[3,4];case 2:return[4,i.submit((n={},n[t.CartForm.INPUT_NAME]=JSON.stringify(r),n),{method:"POST",action:"/cart"})];case 3:e.sent(),e.label=4;case 4:return[2]}}))}))},S=function(e){return o(void 0,[e],void 0,(function(e){var r,t=e.cart,n=e.fetcher;return e.cartInfoToEnable,a(this,(function(e){switch(e.label){case 0:return t?0===(r=g(t).filter((function(e){return"re:do"===e.merchandise.product.vendor}))).length?[3,2]:[4,_({cart:t,fetcher:n,lineIds:r.map((function(e){return e.id}))})]:(console.error("No cart"),[2]);case 1:return e.sent(),[3,2];case 2:return[2]}}))}))},I=function(e){return o(void 0,[e],void 0,(function(e){var r,n,o,i=e.cart,c=e.fetcher,u=e.cartInfoToEnable;return a(this,(function(e){switch(e.label){case 0:return r={merchandiseId:"gid://shopify/ProductVariant/".concat(u.variantId),quantity:1,selectedVariant:u.selectedVariant},n={action:t.CartForm.ACTIONS.LinesAdd,inputs:{lines:[r]}},i&&m(i)?(i.linesAdd([r]),[4,E(i)]):[3,2];case 1:return e.sent(),[3,4];case 2:return[4,c.submit((o={},o[t.CartForm.INPUT_NAME]=JSON.stringify(n),o),{method:"POST",action:"/cart"})];case 3:e.sent(),e.label=4;case 4:return[2]}}))}))},T=function(e){return o(void 0,[e],void 0,(function(e){var r,n,o,i=e.cart,c=e.fetcher,u=e.cartInfoToEnable,s=e.enabled;return a(this,(function(e){switch(e.label){case 0:return r={key:(null==u?void 0:u.cartAttribute)||"redo_opted_in_from_cart",value:s.toString()},n={action:t.CartForm.ACTIONS.AttributesUpdateInput,inputs:{attributes:[r]}},i&&m(i)?(i.cartAttributesUpdate([r]),[4,E(i)]):[3,2];case 1:return e.sent(),[3,4];case 2:return[4,c.submit((o={},o[t.CartForm.INPUT_NAME]=JSON.stringify(n),o),{method:"POST",action:"/cart"})];case 3:e.sent(),e.label=4;case 4:return[2]}}))}))};var k=e.createContext({enabled:!1,loading:!0}),R=function(){var t=e.useContext(k),i=function(t){var i=this,c=r.useFetcher(t),u=e.useRef(null),s=e.useRef(null);s.current||(s.current=new Promise((function(e){u.current=e})));var l=e.useCallback((function(){s.current=new Promise((function(e){u.current=e}))}),[s,u]),f=e.useCallback((function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return o(i,void 0,void 0,(function(){return a(this,(function(r){return c.submit.apply(c,e),[2,s.current]}))}))}),[c,s]);return e.useEffect((function(){var e;"idle"===c.state&&(c.data&&(null===(e=u.current)||void 0===e||e.call(u,c.data)),l())}),[c,l]),n(n({},c),{submit:f})}();return e.useEffect((function(){!t.loading&&t.cartInfoToEnable&&S({fetcher:i,cart:t.cart,cartInfoToEnable:t.cartInfoToEnable})}),[t.loading]),{enable:function(){return o(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return t.loading||!t.cartInfoToEnable?[2,!1]:[4,w({fetcher:i,cart:t.cart,cartInfoToEnable:t.cartInfoToEnable})];case 1:return e.sent(),[4,T({cart:t.cart,fetcher:i,cartInfoToEnable:t.cartInfoToEnable,enabled:!0})];case 2:return e.sent(),[2,!0]}}))}))},disable:function(){return o(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return t.cartInfoToEnable?[4,S({fetcher:i,cart:t.cart,cartInfoToEnable:t.cartInfoToEnable})]:[2,!1];case 1:return e.sent(),[4,T({cart:t.cart,fetcher:i,cartInfoToEnable:t.cartInfoToEnable,enabled:!1})];case 2:return e.sent(),[2,!0]}}))}))},get loading(){return t.loading},get eligible(){var e;return!(this.loading||!this.price||!this.cartProduct||!(null===(e=this.cart)||void 0===e?void 0:e.cost))},get enabled(){return t.enabled},get price(){var e,r,n,o=null===(n=null===(r=null===(e=t.cartInfoToEnable)||void 0===e?void 0:e.selectedVariant)||void 0===r?void 0:r.price)||void 0===n?void 0:n.amount;if(o&&"NaN"!==Number(o).toString())return Number(o)},get cart(){return t.cart},get cartProduct(){var e;return null===(e=t.cartInfoToEnable)||void 0===e?void 0:e.selectedVariant},get cartAttribute(){var e;return null===(e=t.cartInfoToEnable)||void 0===e?void 0:e.cartAttribute},get storeId(){return t.storeId},get errors(){return t.errors}}},O=function(e){var r=e.redoCoverageClient,t=e.cart,n=e.storeId;return new Promise((function(e,i){fetch("https://".concat(h,"/v2.2/stores/").concat(n,"/checkout-buttons-ui"),{method:"GET",headers:{"Content-Type":"application/json"}}).then((function(n){return o(void 0,void 0,void 0,(function(){var o,c;return a(this,(function(a){switch(a.label){case 0:return[4,n.json()];case 1:return(o=a.sent()).html?(c=j({redoCoverageClient:r,cart:t,ui:o}))?[2,e(c)]:[2,i(null)]:[2,e(null)]}}))}))}))}))},j=function(e){var r=e.redoCoverageClient,t=e.cart,n=e.ui;if(!r.eligible||!r.price||!(null==t?void 0:t.cost))return null;var o=t.cost.totalAmount.currencyCode;"XXX"===o&&(o="USD");var a=!!g(t).some((function(e){var r,t;return"re:do"===(null===(t=null===(r=e.merchandise)||void 0===r?void 0:r.product)||void 0===t?void 0:t.vendor)})),i=new Intl.NumberFormat("en-US",{style:"currency",currency:o}).format(Number(t.cost.totalAmount.amount)+(a?0:r.price));return i&&i.length&&!i.includes("NaN")?(n.html=n.html.replaceAll("%combinedPrice%",i),n):null},C=function(e,r){return null==e?null:r(e)?e:C(e.parentElement,r)};exports.REDO_REQUIRED_HOSTNAMES=b,exports.RedoCheckoutButtons=function(r){var t,n=R(),i=n.cart,c=(null===(t=n.cart)||void 0===t?void 0:t.checkoutUrl)||"/checkout",u=e.useState(null);u[0],u[1];var s=e.useState(null),l=s[0],f=s[1];e.useEffect((function(){o(void 0,void 0,void 0,(function(){var e;return a(this,(function(r){switch(r.label){case 0:return n.eligible&&i&&n.storeId?[4,O({redoCoverageClient:n,cart:i,storeId:n.storeId})]:[2];case 1:return(e=r.sent())&&f(e),[2]}}))}))}),[i,n.eligible,n.price,n.storeId]);return y.jsx("div",{children:l?y.jsxs("div",{onClick:function(e){return o(void 0,void 0,void 0,(function(){var t,o;return a(this,(function(a){switch(a.label){case 0:return(t=e.target).dataset?C(t,(function(e){var r;return"coverage-button"==(null===(r=e.dataset)||void 0===r?void 0:r.target)}))?[4,n.enable()]:[3,4]:[2];case 1:return o=a.sent(),r.onClick?[4,r.onClick(o)]:[3,3];case 2:a.sent(),a.label=3;case 3:return window.location.href=c,[3,8];case 4:return C(t,(function(e){return"non-coverage-button"==e.dataset.target}))?[4,n.disable()]:[3,8];case 5:return a.sent(),r.onClick?[4,r.onClick(!1)]:[3,7];case 6:a.sent(),a.label=7;case 7:window.location.href=c,a.label=8;case 8:return[2]}}))}))},children:[l.css?y.jsx("style",{children:l.css}):"",y.jsx("div",{dangerouslySetInnerHTML:{__html:l.html}})]}):r.children})},exports.RedoProvider=function(r){var t=r.cart,n=r.storeId,c=r.children,u=e.useState();u[0],u[1];var s=e.useState();s[0],s[1];var l=e.useState(),f=l[0],d=l[1],p=e.useState(!0),v=p[0],b=p[1],m=e.useState([]),E=m[0],w=m[1],_=function(e){return E.find((function(r){return r.type===e.type}))||w(i(i([],E,!0),[e],!1)),e};e.useEffect((function(){var e,r,i,c,u,s,l;if(t&&n){var f=g(t);fetch("https://".concat(h,"/v2.2/stores/").concat(n,"/coverage-products"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cart:{lineItems:f.map((function(e){var r,t,n,o,a,i,c,u,s,l,f;return{id:e.id,originalPrice:{amount:null===(t=null===(r=e.merchandise)||void 0===r?void 0:r.price)||void 0===t?void 0:t.amount,currency:null===(o=null===(n=e.merchandise)||void 0===n?void 0:n.price)||void 0===o?void 0:o.currencyCode},priceTotal:{amount:null===(i=null===(a=e.cost)||void 0===a?void 0:a.totalAmount)||void 0===i?void 0:i.amount,currency:null===(u=null===(c=e.cost)||void 0===c?void 0:c.totalAmount)||void 0===u?void 0:u.currencyCode},product:{id:null===(l=null===(s=e.merchandise)||void 0===s?void 0:s.product)||void 0===l?void 0:l.id},variant:{id:null===(f=e.merchandise)||void 0===f?void 0:f.id},quantity:e.quantity}})),priceTotal:{amount:null===(r=null===(e=t.cost)||void 0===e?void 0:e.totalAmount)||void 0===r?void 0:r.amount,currency:null===(c=null===(i=t.cost)||void 0===i?void 0:i.totalAmount)||void 0===c?void 0:c.currencyCode}},customer:{id:(null===(s=null===(u=t.buyerIdentity)||void 0===u?void 0:u.customer)||void 0===s?void 0:s.id)||"",country:null===(l=t.buyerIdentity)||void 0===l?void 0:l.countryCode}})}).then((function(e){return o(void 0,void 0,void 0,(function(){var r,t,n,o,i,c,u,s,l,f,p,v;return a(this,(function(a){switch(a.label){case 0:return 500!==e.status?[3,2]:(r=_,i={type:exports.RedoErrorType.ApiServerError,message:"Internal server error occured when getting available coverage products from Redo API.. Check your inputs are correct and storeId have been configured. Reach out to Redo support if the issue persists."},c={},[4,e.json()]);case 1:return r.apply(void 0,[(i.context=(c.json=a.sent(),c),i)]),[2];case 2:return 400!==e.status?[3,4]:(t=_,u={type:exports.RedoErrorType.ApiBadRequest,message:"Bad request when getting available coverage products from Redo API. Check that the passed in cart is of the correct type Cart/CartReturn and includes all of the correct cart information."},s={},[4,e.json()]);case 3:return t.apply(void 0,[(u.context=(s.json=a.sent(),s),u)]),[2];case 4:return 200===e.status?[3,6]:(n=_,l={type:exports.RedoErrorType.ApiUnknownError,message:"Unkown error occured while getting available coverage products from Redo API."},f={status:e.status},[4,e.json()]);case 5:return n.apply(void 0,[(l.context=(f.json=a.sent(),f),l)]),[2];case 6:return[4,e.json()];case 7:return o=a.sent(),b(!1),(null===(v=null===(p=null==o?void 0:o.coverageProducts)||void 0===p?void 0:p[0])||void 0===v?void 0:v.cartInfoToEnable)?(d(o.coverageProducts[0].cartInfoToEnable),[2]):[2]}}))}))}))}}),[t,n]);var S={enabled:!0,loading:v,storeId:n,cartInfoToEnable:f,cart:t,errors:(null==E?void 0:E.length)&&E.length>0?E:void 0};return y.jsx(k.Provider,{value:S,children:c})},exports.useLoad=function(r,t){var o=e.useState({pending:!1}),a=o[0],i=o[1];return e.useEffect((function(){var e=new AbortController;return i((function(e){return n(n({},e),{pending:!0})})),r(e.signal).then((function(e){return i({pending:!1,value:e})}),(function(e){e.message.includes("Request aborted for RPC method")||"ERR_CANCELED"===e.code||"Another request is in flight"===e.message||i({pending:!1,error:e})})),function(){e.abort(),i((function(e){return n(n({},e),{pending:!1})}))}}),t),a},exports.useRedoCoverageClient=R;
11
11
  //# sourceMappingURL=index.js.map