@redotech/redo-hydrogen 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/package.json +1 -1
- package/src/components/redo-checkout-buttons.tsx +8 -7
- package/src/providers/redo-coverage-client.tsx +15 -1
- package/src/types.ts +2 -0
- package/src/utils/cart.ts +0 -1
package/CHANGELOG.md
ADDED
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 d(){return l||(l=1,"production"!==process.env.NODE_ENV&&function(){var t=e,r=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"),l=Symbol.for("react.forward_ref"),s=Symbol.for("react.suspense"),d=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=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function m(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];!function(e,t,r){var n=b.ReactDebugCurrentFrame,o=n.getStackAddendum();""!==o&&(t+="%s",r=r.concat([o]));var a=r.map((function(e){return String(e)}));a.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,a)}("error",e,r)}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 s:return"Suspense";case d:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return E(e)+".Consumer";case c:return E(e._context)+".Provider";case l:return function(e,t,r){var n=e.displayName;if(n)return n;var o=t.displayName||t.name||"";return""!==o?r+"("+o+")":r}(e,e.render,"ForwardRef");case p:var t=e.displayName||null;return null!==t?t:w(e.type)||"Memo";case v:var r=e,f=r._payload,y=r._init;try{return w(y(f))}catch(e){return null}}return null}g=Symbol.for("react.module.reference");var _,S,k,T,I,O,C,j=Object.assign,R=0;function P(){}P.__reactDisabledLog=!0;var x,N=b.ReactCurrentDispatcher;function A(e,t,r){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,t){if(!e||$)return"";var r,n=F.get(e);if(void 0!==n)return n;$=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=N.current,N.current=null,function(){if(0===R){_=console.log,S=console.info,k=console.warn,T=console.error,I=console.group,O=console.groupCollapsed,C=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})}R++}();try{if(t){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){r=e}Reflect.construct(e,[],i)}else{try{i.call()}catch(e){r=e}e.call(i.prototype)}}else{try{throw Error()}catch(e){r=e}e()}}catch(t){if(t&&r&&"string"==typeof t.stack){for(var c=t.stack.split("\n"),u=r.stack.split("\n"),l=c.length-1,s=u.length-1;l>=1&&s>=0&&c[l]!==u[s];)s--;for(;l>=1&&s>=0;l--,s--)if(c[l]!==u[s]){if(1!==l||1!==s)do{if(l--,--s<0||c[l]!==u[s]){var f="\n"+c[l].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(l>=1&&s>=0);break}}}finally{$=!1,N.current=o,function(){if(0==--R){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:j({},e,{value:_}),info:j({},e,{value:S}),warn:j({},e,{value:k}),error:j({},e,{value:T}),group:j({},e,{value:I}),groupCollapsed:j({},e,{value:O}),groupEnd:j({},e,{value:C})})}R<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?A(d):"";return"function"==typeof e&&F.set(e,p),p}function L(e,t,r){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return A(e);switch(e){case s:return A("Suspense");case d:return A("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case l:return U(e.render,!1);case p:return L(e.type,t,r);case v:var o=e,a=o._payload,i=o._init;try{return L(i(a),t,r)}catch(e){}}return""}F=new D;var q=Object.prototype.hasOwnProperty,M={},V=b.ReactDebugCurrentFrame;function W(e){if(e){var t=e._owner,r=L(e.type,e._source,t?t.type:null);V.setExtraStackFrame(r)}else V.setExtraStackFrame(null)}var z=Array.isArray;function J(e){return z(e)}function Y(e){return""+e}function B(e){if(function(e){try{return Y(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)),Y(e)}var H,K,X=b.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,n,o,a){var i,c={},u=null,l=null;for(i in void 0!==n&&(B(n),u=""+n),function(e){if(q.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(B(t.key),u=""+t.key),function(e){if(q.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(l=t.ref,function(e){"string"==typeof e.ref&&X.current}(t)),t)q.call(t,i)&&!G.hasOwnProperty(i)&&(c[i]=t[i]);if(e&&e.defaultProps){var s=e.defaultProps;for(i in s)void 0===c[i]&&(c[i]=s[i])}if(u||l){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;u&&function(e,t){var r=function(){H||(H=!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)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(c,f),l&&function(e,t){var r=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)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}(c,f)}return function(e,t,n,o,a,i,c){var u={$$typeof:r,type:e,key:t,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,l,a,o,X.current,c)}var Z,ee=b.ReactCurrentOwner,te=b.ReactDebugCurrentFrame;function re(e){if(e){var t=e._owner,r=L(e.type,e._source,t?t.type:null);te.setExtraStackFrame(r)}else te.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===r}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,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var r=function(e){var t=oe();if(!t){var r="string"==typeof e?e:e.displayName||e.name;r&&(t="\n\nCheck the top-level render call using <"+r+">.")}return t}(t);if(!ae[r]){ae[r]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+w(e._owner.type)+"."),re(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.',r,n),re(null)}}}function ce(e,t){if("object"==typeof e)if(J(e))for(var r=0;r<e.length;r++){var n=e[r];ne(n)&&ie(n,t)}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 t=h&&e[h]||e["@@iterator"];return"function"==typeof t?t: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,t)}}function ue(e){var t,r=e.type;if(null!=r&&"string"!=typeof r){if("function"==typeof r)t=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==l&&r.$$typeof!==p)return;t=r.propTypes}if(t){var n=w(r);!function(e,t,r,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")+": "+r+" 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](t,i,n,r,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",r,i,typeof c),W(null)),c instanceof Error&&!(c.message in M)&&(M[c.message]=!0,W(o),m("Failed %s type: %s",r,c.message),W(null))}}(t,e.props,"prop",n,e)}else if(void 0!==r.PropTypes&&!Z){Z=!0,m("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",w(r)||"Unknown")}"function"!=typeof r.getDefaultProps||r.getDefaultProps.isReactClassApproved||m("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var le={};function se(e,t,n,f,h,b){var E=function(e){return"string"==typeof e||"function"==typeof e||e===o||e===i||e===a||e===s||e===d||e===y||"object"==typeof e&&null!==e&&(e.$$typeof===v||e.$$typeof===p||e.$$typeof===c||e.$$typeof===u||e.$$typeof===l||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":J(e)?S="array":void 0!==e&&e.$$typeof===r?(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 k=Q(e,t,n,h,b);if(null==k)return k;if(E){var T=t.children;if(void 0!==T)if(f)if(J(T)){for(var I=0;I<T.length;I++)ce(T[I],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(t,"key")){var O=w(e),C=Object.keys(t).filter((function(e){return"key"!==e})),j=C.length>0?"{key: someKey, "+C.join(": ..., ")+": ...}":"{key: someKey}";if(!le[O+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,O,C.length>0?"{"+C.join(": ..., ")+": ...}":"{}",O),le[O+j]=!0}return e===o?function(e){for(var t=Object.keys(e.props),r=0;r<t.length;r++){var n=t[r];if("children"!==n&&"key"!==n){re(e),m("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),re(null);break}}null!==e.ref&&(re(e),m("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}(k):ue(k),k}var fe=function(e,t,r){return se(e,t,r,!1)},de=function(e,t,r){return se(e,t,r,!0)};f.Fragment=o,f.jsx=fe,f.jsxs=de}()),f}var p=(s||(s=1,"production"===process.env.NODE_ENV?c.exports=function(){if(i)return u;i=1;var t=e,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function l(e,t,n){var i,u={},l=null,s=null;for(i in void 0!==n&&(l=""+n),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(s=t.ref),t)o.call(t,i)&&!c.hasOwnProperty(i)&&(u[i]=t[i]);if(e&&e.defaultProps)for(i in t=e.defaultProps)void 0===u[i]&&(u[i]=t[i]);return{$$typeof:r,type:e,key:l,ref:s,props:u,_owner:a.current}}return u.Fragment=n,u.jsx=l,u.jsxs=l,u}():c.exports=d()),c.exports),v="api.getredo.com",y=[v],h=function(e){return o(void 0,[e],void 0,(function(e){var t,r,n=e.cart,o=e.fetcher,i=e.cartInfoToEnable;return a(this,(function(e){switch(e.label){case 0:return n?[3,2]:[4,g({fetcher:o,cartInfoToEnable:i})];case 1:case 3:return[2,e.sent()];case 2:return t=n.lines.nodes.filter((function(e){return"re:do"===e.merchandise.product.vendor})),r=null==t?void 0:t.filter((function(e){return e.merchandise.id==="gid://shopify/ProductVariant/".concat(i.variantId)})),0!==t.length?[3,4]:[4,g({fetcher:o,cartInfoToEnable:i})];case 4:return 1!==t.length||1!==r.length||1!==r[0].quantity?[3,5]:[2];case 5:return[4,b({fetcher:o,lineIds:t.map((function(e){return e.id}))})];case 6:return e.sent(),[4,g({fetcher:o,cartInfoToEnable:i})];case 7:return e.sent(),[2]}}))}))},b=function(e){return o(void 0,[e],void 0,(function(e){var t,n,o=e.fetcher,i=e.lineIds;return a(this,(function(e){switch(e.label){case 0:return t={action:r.CartForm.ACTIONS.LinesRemove,inputs:{lineIds:i}},[4,o.submit((n={},n[r.CartForm.INPUT_NAME]=JSON.stringify(t),n),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))},m=function(e){return o(void 0,[e],void 0,(function(e){var t,r=e.cart,n=e.fetcher;return e.cartInfoToEnable,a(this,(function(e){switch(e.label){case 0:return r?0===(t=r.lines.nodes.filter((function(e){return"re:do"===e.merchandise.product.vendor}))).length?[3,2]:[4,b({fetcher:n,lineIds:t.map((function(e){return e.id}))})]:(console.error("No cart"),[2]);case 1:return e.sent(),[3,2];case 2:return[2]}}))}))},g=function(e){return o(void 0,[e],void 0,(function(e){var t,n,o,i=e.fetcher,c=e.cartInfoToEnable;return a(this,(function(e){switch(e.label){case 0:return t={merchandiseId:"gid://shopify/ProductVariant/".concat(c.variantId),quantity:1,selectedVariant:c.selectedVariant},n={action:r.CartForm.ACTIONS.LinesAdd,inputs:{lines:[t]}},[4,i.submit((o={},o[r.CartForm.INPUT_NAME]=JSON.stringify(n),o),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))},E=function(e){return o(void 0,[e],void 0,(function(e){var t,n,o=e.fetcher,i=e.cartInfoToEnable,c=e.enabled;return a(this,(function(e){switch(e.label){case 0:return t={action:r.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[r.CartForm.INPUT_NAME]=JSON.stringify(t),n),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))};var w=e.createContext({enabled:!1,loading:!0}),_=function(){var r=e.useContext(w),i=function(r){var i=this,c=t.useFetcher(r),u=e.useRef(null),l=e.useRef(null);l.current||(l.current=new Promise((function(e){u.current=e})));var s=e.useCallback((function(){l.current=new Promise((function(e){u.current=e}))}),[l,u]),f=e.useCallback((function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return o(i,void 0,void 0,(function(){return a(this,(function(t){return c.submit.apply(c,e),[2,l.current]}))}))}),[c,l]);return e.useEffect((function(){var e;"idle"===c.state&&(c.data&&(null===(e=u.current)||void 0===e||e.call(u,c.data)),s())}),[c,s]),n(n({},c),{submit:f})}();return e.useEffect((function(){!r.loading&&r.cartInfoToEnable&&m({fetcher:i,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})}),[r.loading]),{enable:function(){return o(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return r.loading||!r.cartInfoToEnable?[2,!1]:[4,h({fetcher:i,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})];case 1:return e.sent(),[4,E({fetcher:i,cartInfoToEnable:r.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 r.cartInfoToEnable?[4,m({fetcher:i,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})]:[2,!1];case 1:return e.sent(),[4,E({fetcher:i,cartInfoToEnable:r.cartInfoToEnable,enabled:!1})];case 2:return e.sent(),[2,!0]}}))}))},get loading(){return r.loading},get enabled(){return r.enabled},get price(){var e;return Number(null===(e=r.cartInfoToEnable)||void 0===e?void 0:e.selectedVariant.price.amount)},get cartProduct(){var e;return null===(e=r.cartInfoToEnable)||void 0===e?void 0:e.selectedVariant},get cartAttribute(){var e;return null===(e=r.cartInfoToEnable)||void 0===e?void 0:e.cartAttribute}}},S=function(e){var t=e.redoCoverageClient,r=e.cart,n=e.storeId;return new Promise((function(e,i){fetch("https://".concat(v,"/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,i;return a(this,(function(a){switch(a.label){case 0:return[4,n.json()];case 1:return(o=a.sent()).html?(i=k({redoCoverageClient:t,cart:r,ui:o}),[2,e(i)]):[2,e(null)]}}))}))}))}))},k=function(e){var t=e.redoCoverageClient,r=e.cart,n=e.ui,o=!!r.lines.nodes.some((function(e){var t,r;return"re:do"===(null===(r=null===(t=e.merchandise)||void 0===t?void 0:t.product)||void 0===r?void 0:r.vendor)})),a=new Intl.NumberFormat("en-US",{style:"currency",currency:r.cost.totalAmount.currencyCode}).format(Number(r.cost.totalAmount.amount)+(o?0:t.price));return a&&a.length&&!a.includes("NaN")?(n.html=n.html.replaceAll("%combinedPrice%",a),n):null},T=function(e,t){return null==e?null:t(e)?e:T(e.parentElement,t)};exports.REDO_REQUIRED_HOSTNAMES=y,exports.RedoCheckoutButtons=function(t){var r=_(),n=t.cart,i=n.checkoutUrl,c=e.useState(null);c[0],c[1];var u=e.useState(null),l=u[0],s=u[1];e.useEffect((function(){o(void 0,void 0,void 0,(function(){var e;return a(this,(function(o){switch(o.label){case 0:return[4,S({redoCoverageClient:r,cart:n,storeId:t.storeId})];case 1:return(e=o.sent())&&s(e),[2]}}))}))}),[n,r.price]);return p.jsx("div",{children:l?p.jsxs("div",{onClick:function(e){return o(void 0,void 0,void 0,(function(){var n,o;return a(this,(function(a){switch(a.label){case 0:return(n=e.target).dataset?T(n,(function(e){var t;return"coverage-button"==(null===(t=e.dataset)||void 0===t?void 0:t.target)}))?[4,r.enable()]:[3,4]:[2];case 1:return o=a.sent(),t.onClick?[4,t.onClick(o)]:[3,3];case 2:a.sent(),a.label=3;case 3:return window.location.href=i,[3,8];case 4:return T(n,(function(e){return"non-coverage-button"==e.dataset.target}))?[4,r.disable()]:[3,8];case 5:return a.sent(),t.onClick?[4,t.onClick(!1)]:[3,7];case 6:a.sent(),a.label=7;case 7:window.location.href=i,a.label=8;case 8:return[2]}}))}))},children:[l.css?p.jsx("style",{children:l.css}):"",p.jsx("div",{dangerouslySetInnerHTML:{__html:l.html}})]}):t.children})},exports.RedoProvider=function(t){var r=t.cart,n=t.storeId,i=t.children,c=e.useState();c[0],c[1];var u=e.useState();u[0],u[1];var l=e.useState(),s=l[0],f=l[1],d=e.useState(!0),y=d[0],h=d[1];e.useEffect((function(){var e,t,i,c,u,l,s;fetch("https://".concat(v,"/v2.2/stores/").concat(n,"/coverage-products"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cart:{lineItems:r.lines.nodes.map((function(e){var t,r,n,o,a,i,c,u,l,s,f;return{id:e.id,originalPrice:{amount:null===(r=null===(t=e.merchandise)||void 0===t?void 0:t.price)||void 0===r?void 0:r.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===(s=null===(l=e.merchandise)||void 0===l?void 0:l.product)||void 0===s?void 0:s.id},variant:{id:null===(f=e.merchandise)||void 0===f?void 0:f.id},quantity:e.quantity}})),priceTotal:{amount:null===(t=null===(e=r.cost)||void 0===e?void 0:e.totalAmount)||void 0===t?void 0:t.amount,currency:null===(c=null===(i=r.cost)||void 0===i?void 0:i.totalAmount)||void 0===c?void 0:c.currencyCode}},customer:{id:(null===(l=null===(u=r.buyerIdentity)||void 0===u?void 0:u.customer)||void 0===l?void 0:l.id)||"",country:null===(s=r.buyerIdentity)||void 0===s?void 0:s.countryCode}})}).then((function(e){return o(void 0,void 0,void 0,(function(){var t;return a(this,(function(r){switch(r.label){case 0:return[4,e.json()];case 1:return t=r.sent(),h(!1),f(t.coverageProducts[0].cartInfoToEnable),[2]}}))}))}))}),[r]);var b={enabled:!0,loading:y,storeId:n,cartInfoToEnable:s,cart:r};return p.jsx(w.Provider,{value:b,children:i})},exports.useLoad=function(t,r){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})})),t(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})}))}}),r),a},exports.useRedoCoverageClient=_;
|
|
10
|
+
*/function d(){return l||(l=1,"production"!==process.env.NODE_ENV&&function(){var t=e,r=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"),l=Symbol.for("react.forward_ref"),s=Symbol.for("react.suspense"),d=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=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function m(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];!function(e,t,r){var n=b.ReactDebugCurrentFrame,o=n.getStackAddendum();""!==o&&(t+="%s",r=r.concat([o]));var a=r.map((function(e){return String(e)}));a.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,a)}("error",e,r)}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 s:return"Suspense";case d:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return E(e)+".Consumer";case c:return E(e._context)+".Provider";case l:return function(e,t,r){var n=e.displayName;if(n)return n;var o=t.displayName||t.name||"";return""!==o?r+"("+o+")":r}(e,e.render,"ForwardRef");case p:var t=e.displayName||null;return null!==t?t:w(e.type)||"Memo";case v:var r=e,f=r._payload,y=r._init;try{return w(y(f))}catch(e){return null}}return null}g=Symbol.for("react.module.reference");var _,S,k,T,I,O,C,j=Object.assign,R=0;function P(){}P.__reactDisabledLog=!0;var x,N=b.ReactCurrentDispatcher;function A(e,t,r){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,t){if(!e||$)return"";var r,n=F.get(e);if(void 0!==n)return n;$=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=N.current,N.current=null,function(){if(0===R){_=console.log,S=console.info,k=console.warn,T=console.error,I=console.group,O=console.groupCollapsed,C=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})}R++}();try{if(t){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){r=e}Reflect.construct(e,[],i)}else{try{i.call()}catch(e){r=e}e.call(i.prototype)}}else{try{throw Error()}catch(e){r=e}e()}}catch(t){if(t&&r&&"string"==typeof t.stack){for(var c=t.stack.split("\n"),u=r.stack.split("\n"),l=c.length-1,s=u.length-1;l>=1&&s>=0&&c[l]!==u[s];)s--;for(;l>=1&&s>=0;l--,s--)if(c[l]!==u[s]){if(1!==l||1!==s)do{if(l--,--s<0||c[l]!==u[s]){var f="\n"+c[l].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(l>=1&&s>=0);break}}}finally{$=!1,N.current=o,function(){if(0==--R){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:j({},e,{value:_}),info:j({},e,{value:S}),warn:j({},e,{value:k}),error:j({},e,{value:T}),group:j({},e,{value:I}),groupCollapsed:j({},e,{value:O}),groupEnd:j({},e,{value:C})})}R<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?A(d):"";return"function"==typeof e&&F.set(e,p),p}function L(e,t,r){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return A(e);switch(e){case s:return A("Suspense");case d:return A("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case l:return U(e.render,!1);case p:return L(e.type,t,r);case v:var o=e,a=o._payload,i=o._init;try{return L(i(a),t,r)}catch(e){}}return""}F=new D;var q=Object.prototype.hasOwnProperty,M={},V=b.ReactDebugCurrentFrame;function W(e){if(e){var t=e._owner,r=L(e.type,e._source,t?t.type:null);V.setExtraStackFrame(r)}else V.setExtraStackFrame(null)}var z=Array.isArray;function J(e){return z(e)}function Y(e){return""+e}function B(e){if(function(e){try{return Y(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)),Y(e)}var H,K,X=b.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,n,o,a){var i,c={},u=null,l=null;for(i in void 0!==n&&(B(n),u=""+n),function(e){if(q.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(B(t.key),u=""+t.key),function(e){if(q.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(l=t.ref,function(e){"string"==typeof e.ref&&X.current}(t)),t)q.call(t,i)&&!G.hasOwnProperty(i)&&(c[i]=t[i]);if(e&&e.defaultProps){var s=e.defaultProps;for(i in s)void 0===c[i]&&(c[i]=s[i])}if(u||l){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;u&&function(e,t){var r=function(){H||(H=!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)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(c,f),l&&function(e,t){var r=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)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}(c,f)}return function(e,t,n,o,a,i,c){var u={$$typeof:r,type:e,key:t,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,l,a,o,X.current,c)}var Z,ee=b.ReactCurrentOwner,te=b.ReactDebugCurrentFrame;function re(e){if(e){var t=e._owner,r=L(e.type,e._source,t?t.type:null);te.setExtraStackFrame(r)}else te.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===r}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,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var r=function(e){var t=oe();if(!t){var r="string"==typeof e?e:e.displayName||e.name;r&&(t="\n\nCheck the top-level render call using <"+r+">.")}return t}(t);if(!ae[r]){ae[r]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+w(e._owner.type)+"."),re(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.',r,n),re(null)}}}function ce(e,t){if("object"==typeof e)if(J(e))for(var r=0;r<e.length;r++){var n=e[r];ne(n)&&ie(n,t)}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 t=h&&e[h]||e["@@iterator"];return"function"==typeof t?t: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,t)}}function ue(e){var t,r=e.type;if(null!=r&&"string"!=typeof r){if("function"==typeof r)t=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==l&&r.$$typeof!==p)return;t=r.propTypes}if(t){var n=w(r);!function(e,t,r,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")+": "+r+" 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](t,i,n,r,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",r,i,typeof c),W(null)),c instanceof Error&&!(c.message in M)&&(M[c.message]=!0,W(o),m("Failed %s type: %s",r,c.message),W(null))}}(t,e.props,"prop",n,e)}else if(void 0!==r.PropTypes&&!Z){Z=!0,m("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",w(r)||"Unknown")}"function"!=typeof r.getDefaultProps||r.getDefaultProps.isReactClassApproved||m("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var le={};function se(e,t,n,f,h,b){var E=function(e){return"string"==typeof e||"function"==typeof e||e===o||e===i||e===a||e===s||e===d||e===y||"object"==typeof e&&null!==e&&(e.$$typeof===v||e.$$typeof===p||e.$$typeof===c||e.$$typeof===u||e.$$typeof===l||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":J(e)?S="array":void 0!==e&&e.$$typeof===r?(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 k=Q(e,t,n,h,b);if(null==k)return k;if(E){var T=t.children;if(void 0!==T)if(f)if(J(T)){for(var I=0;I<T.length;I++)ce(T[I],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(t,"key")){var O=w(e),C=Object.keys(t).filter((function(e){return"key"!==e})),j=C.length>0?"{key: someKey, "+C.join(": ..., ")+": ...}":"{key: someKey}";if(!le[O+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,O,C.length>0?"{"+C.join(": ..., ")+": ...}":"{}",O),le[O+j]=!0}return e===o?function(e){for(var t=Object.keys(e.props),r=0;r<t.length;r++){var n=t[r];if("children"!==n&&"key"!==n){re(e),m("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),re(null);break}}null!==e.ref&&(re(e),m("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}(k):ue(k),k}var fe=function(e,t,r){return se(e,t,r,!1)},de=function(e,t,r){return se(e,t,r,!0)};f.Fragment=o,f.jsx=fe,f.jsxs=de}()),f}var p=(s||(s=1,"production"===process.env.NODE_ENV?c.exports=function(){if(i)return u;i=1;var t=e,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function l(e,t,n){var i,u={},l=null,s=null;for(i in void 0!==n&&(l=""+n),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(s=t.ref),t)o.call(t,i)&&!c.hasOwnProperty(i)&&(u[i]=t[i]);if(e&&e.defaultProps)for(i in t=e.defaultProps)void 0===u[i]&&(u[i]=t[i]);return{$$typeof:r,type:e,key:l,ref:s,props:u,_owner:a.current}}return u.Fragment=n,u.jsx=l,u.jsxs=l,u}():c.exports=d()),c.exports),v="api.getredo.com",y=[v],h=function(e){return o(void 0,[e],void 0,(function(e){var t,r,n=e.cart,o=e.fetcher,i=e.cartInfoToEnable;return a(this,(function(e){switch(e.label){case 0:return n?[3,2]:[4,g({fetcher:o,cartInfoToEnable:i})];case 1:case 3:return[2,e.sent()];case 2:return t=n.lines.nodes.filter((function(e){return"re:do"===e.merchandise.product.vendor})),r=null==t?void 0:t.filter((function(e){return e.merchandise.id==="gid://shopify/ProductVariant/".concat(i.variantId)})),0!==t.length?[3,4]:[4,g({fetcher:o,cartInfoToEnable:i})];case 4:return 1!==t.length||1!==r.length||1!==r[0].quantity?[3,5]:[2];case 5:return[4,b({fetcher:o,lineIds:t.map((function(e){return e.id}))})];case 6:return e.sent(),[4,g({fetcher:o,cartInfoToEnable:i})];case 7:return e.sent(),[2]}}))}))},b=function(e){return o(void 0,[e],void 0,(function(e){var t,n,o=e.fetcher,i=e.lineIds;return a(this,(function(e){switch(e.label){case 0:return t={action:r.CartForm.ACTIONS.LinesRemove,inputs:{lineIds:i}},[4,o.submit((n={},n[r.CartForm.INPUT_NAME]=JSON.stringify(t),n),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))},m=function(e){return o(void 0,[e],void 0,(function(e){var t,r=e.cart,n=e.fetcher;return e.cartInfoToEnable,a(this,(function(e){switch(e.label){case 0:return r?0===(t=r.lines.nodes.filter((function(e){return"re:do"===e.merchandise.product.vendor}))).length?[3,2]:[4,b({fetcher:n,lineIds:t.map((function(e){return e.id}))})]:(console.error("No cart"),[2]);case 1:return e.sent(),[3,2];case 2:return[2]}}))}))},g=function(e){return o(void 0,[e],void 0,(function(e){var t,n,o,i=e.fetcher,c=e.cartInfoToEnable;return a(this,(function(e){switch(e.label){case 0:return t={merchandiseId:"gid://shopify/ProductVariant/".concat(c.variantId),quantity:1,selectedVariant:c.selectedVariant},n={action:r.CartForm.ACTIONS.LinesAdd,inputs:{lines:[t]}},[4,i.submit((o={},o[r.CartForm.INPUT_NAME]=JSON.stringify(n),o),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))},E=function(e){return o(void 0,[e],void 0,(function(e){var t,n,o=e.fetcher,i=e.cartInfoToEnable,c=e.enabled;return a(this,(function(e){switch(e.label){case 0:return t={action:r.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[r.CartForm.INPUT_NAME]=JSON.stringify(t),n),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))};var w=e.createContext({enabled:!1,loading:!0}),_=function(){var r=e.useContext(w),i=function(r){var i=this,c=t.useFetcher(r),u=e.useRef(null),l=e.useRef(null);l.current||(l.current=new Promise((function(e){u.current=e})));var s=e.useCallback((function(){l.current=new Promise((function(e){u.current=e}))}),[l,u]),f=e.useCallback((function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return o(i,void 0,void 0,(function(){return a(this,(function(t){return c.submit.apply(c,e),[2,l.current]}))}))}),[c,l]);return e.useEffect((function(){var e;"idle"===c.state&&(c.data&&(null===(e=u.current)||void 0===e||e.call(u,c.data)),s())}),[c,s]),n(n({},c),{submit:f})}();return e.useEffect((function(){!r.loading&&r.cartInfoToEnable&&m({fetcher:i,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})}),[r.loading]),{enable:function(){return o(void 0,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return r.loading||!r.cartInfoToEnable?[2,!1]:[4,h({fetcher:i,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})];case 1:return e.sent(),[4,E({fetcher:i,cartInfoToEnable:r.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 r.cartInfoToEnable?[4,m({fetcher:i,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})]:[2,!1];case 1:return e.sent(),[4,E({fetcher:i,cartInfoToEnable:r.cartInfoToEnable,enabled:!1})];case 2:return e.sent(),[2,!0]}}))}))},get loading(){return r.loading},get enabled(){return r.enabled},get price(){var e;return Number(null===(e=r.cartInfoToEnable)||void 0===e?void 0:e.selectedVariant.price.amount)},get cart(){return r.cart},get cartProduct(){var e;return null===(e=r.cartInfoToEnable)||void 0===e?void 0:e.selectedVariant},get cartAttribute(){var e;return null===(e=r.cartInfoToEnable)||void 0===e?void 0:e.cartAttribute},get storeId(){return r.storeId}}},S=function(e){var t=e.redoCoverageClient,r=e.cart,n=e.storeId;return new Promise((function(e,i){fetch("https://".concat(v,"/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,i;return a(this,(function(a){switch(a.label){case 0:return[4,n.json()];case 1:return(o=a.sent()).html?(i=k({redoCoverageClient:t,cart:r,ui:o}),[2,e(i)]):[2,e(null)]}}))}))}))}))},k=function(e){var t=e.redoCoverageClient,r=e.cart,n=e.ui,o=!!r.lines.nodes.some((function(e){var t,r;return"re:do"===(null===(r=null===(t=e.merchandise)||void 0===t?void 0:t.product)||void 0===r?void 0:r.vendor)})),a=new Intl.NumberFormat("en-US",{style:"currency",currency:r.cost.totalAmount.currencyCode}).format(Number(r.cost.totalAmount.amount)+(o?0:t.price));return a&&a.length&&!a.includes("NaN")?(n.html=n.html.replaceAll("%combinedPrice%",a),n):null},T=function(e,t){return null==e?null:t(e)?e:T(e.parentElement,t)};exports.REDO_REQUIRED_HOSTNAMES=y,exports.RedoCheckoutButtons=function(t){var r,n=_(),i=n.cart,c=(null===(r=n.cart)||void 0===r?void 0:r.checkoutUrl)||"/checkout",u=e.useState(null);u[0],u[1];var l=e.useState(null),s=l[0],f=l[1];e.useEffect((function(){o(void 0,void 0,void 0,(function(){var e;return a(this,(function(t){switch(t.label){case 0:return n.storeId&&i?[4,S({redoCoverageClient:n,cart:i,storeId:n.storeId})]:[2];case 1:return(e=t.sent())&&f(e),[2]}}))}))}),[i,n.price,n.storeId]);return p.jsx("div",{children:s?p.jsxs("div",{onClick:function(e){return o(void 0,void 0,void 0,(function(){var r,o;return a(this,(function(a){switch(a.label){case 0:return(r=e.target).dataset?T(r,(function(e){var t;return"coverage-button"==(null===(t=e.dataset)||void 0===t?void 0:t.target)}))?[4,n.enable()]:[3,4]:[2];case 1:return o=a.sent(),t.onClick?[4,t.onClick(o)]:[3,3];case 2:a.sent(),a.label=3;case 3:return window.location.href=c,[3,8];case 4:return T(r,(function(e){return"non-coverage-button"==e.dataset.target}))?[4,n.disable()]:[3,8];case 5:return a.sent(),t.onClick?[4,t.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:[s.css?p.jsx("style",{children:s.css}):"",p.jsx("div",{dangerouslySetInnerHTML:{__html:s.html}})]}):t.children})},exports.RedoProvider=function(t){var r=t.cart,n=t.storeId,i=t.children,c=e.useState();c[0],c[1];var u=e.useState();u[0],u[1];var l=e.useState(),s=l[0],f=l[1],d=e.useState(!0),y=d[0],h=d[1];e.useEffect((function(){var e,t,i,c,u,l,s;fetch("https://".concat(v,"/v2.2/stores/").concat(n,"/coverage-products"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cart:{lineItems:r.lines.nodes.map((function(e){var t,r,n,o,a,i,c,u,l,s,f;return{id:e.id,originalPrice:{amount:null===(r=null===(t=e.merchandise)||void 0===t?void 0:t.price)||void 0===r?void 0:r.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===(s=null===(l=e.merchandise)||void 0===l?void 0:l.product)||void 0===s?void 0:s.id},variant:{id:null===(f=e.merchandise)||void 0===f?void 0:f.id},quantity:e.quantity}})),priceTotal:{amount:null===(t=null===(e=r.cost)||void 0===e?void 0:e.totalAmount)||void 0===t?void 0:t.amount,currency:null===(c=null===(i=r.cost)||void 0===i?void 0:i.totalAmount)||void 0===c?void 0:c.currencyCode}},customer:{id:(null===(l=null===(u=r.buyerIdentity)||void 0===u?void 0:u.customer)||void 0===l?void 0:l.id)||"",country:null===(s=r.buyerIdentity)||void 0===s?void 0:s.countryCode}})}).then((function(e){return o(void 0,void 0,void 0,(function(){var t;return a(this,(function(r){switch(r.label){case 0:return[4,e.json()];case 1:return t=r.sent(),h(!1),f(t.coverageProducts[0].cartInfoToEnable),[2]}}))}))}))}),[r]);var b={enabled:!0,loading:y,storeId:n,cartInfoToEnable:s,cart:r};return p.jsx(w.Provider,{value:b,children:i})},exports.useLoad=function(t,r){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})})),t(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})}))}}),r),a},exports.useRedoCoverageClient=_;
|
|
11
11
|
//# sourceMappingURL=index.js.map
|