@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 +8 -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/package.json +2 -2
- package/src/providers/redo-coverage-client.tsx +2 -0
- package/src/utils/cart.ts +67 -33
package/dist/esm/index.js
CHANGED
|
@@ -7,5 +7,5 @@ import e,{createContext as r,useState as t,useEffect as n,useContext as o}from"r
|
|
|
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 b(){return v||(v=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"),l=Symbol.for("react.forward_ref"),s=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),v=Symbol.for("react.offscreen"),y=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 w(e){return e.displayName||"Context"}function E(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 f:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return w(e)+".Consumer";case c:return w(e._context)+".Provider";case l: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 d:var r=e.displayName||null;return null!==r?r:E(e.type)||"Memo";case p:var t=e,v=t._payload,y=t._init;try{return E(y(v))}catch(e){return null}}return null}g=Symbol.for("react.module.reference");var _,I,k,S,T,O,R,j=Object.assign,P=0;function C(){}C.__reactDisabledLog=!0;var A,N=b.ReactCurrentDispatcher;function x(e,r,t){if(void 0===A)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);A=n&&n[1]||""}return"\n"+A+e}var $,D=!1,F="function"==typeof WeakMap?WeakMap:Map;function U(e,r){if(!e||D)return"";var t,n=$.get(e);if(void 0!==n)return n;D=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=N.current,N.current=null,function(){if(0===P){_=console.log,I=console.info,k=console.warn,S=console.error,T=console.group,O=console.groupCollapsed,R=console.groupEnd;var e={configurable:!0,enumerable:!0,value:C,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}P++}();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"),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&&$.set(e,f),f}}while(l>=1&&s>=0);break}}}finally{D=!1,N.current=o,function(){if(0==--P){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:j({},e,{value:_}),info:j({},e,{value:I}),warn:j({},e,{value:k}),error:j({},e,{value:S}),group:j({},e,{value:T}),groupCollapsed:j({},e,{value:O}),groupEnd:j({},e,{value:R})})}P<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?x(d):"";return"function"==typeof e&&$.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 x(e);switch(e){case s:return x("Suspense");case f:return x("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case l:return U(e.render,!1);case d:return L(e.type,r,t);case p:var o=e,a=o._payload,i=o._init;try{return L(i(a),r,t)}catch(e){}}return""}$=new F;var q=Object.prototype.hasOwnProperty,V={},W=b.ReactDebugCurrentFrame;function M(e){if(e){var r=e._owner,t=L(e.type,e._source,r?r.type:null);W.setExtraStackFrame(t)}else W.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,G=b.ReactCurrentOwner,H={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,r,n,o,a){var i,c={},u=null,l=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)&&(l=r.ref,function(e){"string"==typeof e.ref&&G.current}(r)),r)q.call(r,i)&&!H.hasOwnProperty(i)&&(c[i]=r[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,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),l&&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,l,a,o,G.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=E(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 "+E(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=y&&e[y]||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!==l&&t.$$typeof!==d)return;r=t.propTypes}if(r){var n=E(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||(M(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),M(null)),c instanceof Error&&!(c.message in V)&&(V[c.message]=!0,M(o),m("Failed %s type: %s",t,c.message),M(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?",E(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 le={};function se(e,r,n,y,h,b){var w=function(e){return"string"==typeof e||"function"==typeof e||e===o||e===i||e===a||e===s||e===f||e===v||"object"==typeof e&&null!==e&&(e.$$typeof===p||e.$$typeof===d||e.$$typeof===c||e.$$typeof===u||e.$$typeof===l||e.$$typeof===g||void 0!==e.getModuleId)}(e);if(!w){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 I;_+=oe(),null===e?I="null":z(e)?I="array":void 0!==e&&e.$$typeof===t?(I="<"+(E(e.type)||"Unknown")+" />",_=" Did you accidentally export a JSX literal instead of a component?"):I=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",I,_)}var k=Q(e,r,n,h,b);if(null==k)return k;if(w){var S=r.children;if(void 0!==S)if(y)if(z(S)){for(var T=0;T<S.length;T++)ce(S[T],e);Object.freeze&&Object.freeze(S)}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(S,e)}if(q.call(r,"key")){var O=E(e),R=Object.keys(r).filter((function(e){return"key"!==e})),j=R.length>0?"{key: someKey, "+R.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,R.length>0?"{"+R.join(": ..., ")+": ...}":"{}",O),le[O+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))}(k):ue(k),k}var fe=function(e,r,t){return se(e,r,t,!1)},de=function(e,r,t){return se(e,r,t,!0)};h.Fragment=o,h.jsx=fe,h.jsxs=de}()),h}var m,g=(y||(y=1,"production"===process.env.NODE_ENV?d.exports=function(){if(f)return p;f=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 c(e,r,n){var c,u={},l=null,s=null;for(c in void 0!==n&&(l=""+n),void 0!==r.key&&(l=""+r.key),void 0!==r.ref&&(s=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:l,ref:s,props:u,_owner:a.current}}return p.Fragment=n,p.jsx=c,p.jsxs=c,p}():d.exports=b()),d.exports);!function(e){e.ApiBadRequest="API_BAD_REQUEST",e.ApiServerError="API_SERVER_ERROR",e.ApiUnknownError="API_UNKNOWN_ERROR"}(m||(m={}));var w="api.getredo.com",E=[w],_=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}))},I=function(e){return u(void 0,[e],void 0,(function(e){var r,t,n=e.cart,o=e.fetcher,a=e.cartInfoToEnable;return l(this,(function(e){switch(e.label){case 0:return n?[3,2]:[4,T({fetcher:o,cartInfoToEnable:a})];case 1:case 3:return[2,e.sent()];case 2:return r=_(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(a.variantId)})),0!==r.length?[3,4]:[4,T({fetcher:o,cartInfoToEnable:a})];case 4:return 1!==r.length||1!==t.length||1!==t[0].quantity?[3,5]:[2];case 5:return[4,k({fetcher:o,lineIds:r.map((function(e){return e.id}))})];case 6:return e.sent(),[4,T({fetcher:o,cartInfoToEnable:a})];case 7:return e.sent(),[2]}}))}))},k=function(e){return u(void 0,[e],void 0,(function(e){var r,t,n=e.fetcher,o=e.lineIds;return l(this,(function(e){switch(e.label){case 0:return r={action:i.ACTIONS.LinesRemove,inputs:{lineIds:o}},[4,n.submit((t={},t[i.INPUT_NAME]=JSON.stringify(r),t),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))},S=function(e){return u(void 0,[e],void 0,(function(e){var r,t=e.cart,n=e.fetcher;return e.cartInfoToEnable,l(this,(function(e){switch(e.label){case 0:return t?0===(r=_(t).filter((function(e){return"re:do"===e.merchandise.product.vendor}))).length?[3,2]:[4,k({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]}}))}))},T=function(e){return u(void 0,[e],void 0,(function(e){var r,t,n,o=e.fetcher,a=e.cartInfoToEnable;return l(this,(function(e){switch(e.label){case 0:return r={merchandiseId:"gid://shopify/ProductVariant/".concat(a.variantId),quantity:1,selectedVariant:a.selectedVariant},t={action:i.ACTIONS.LinesAdd,inputs:{lines:[r]}},[4,o.submit((n={},n[i.INPUT_NAME]=JSON.stringify(t),n),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))},O=function(e){return u(void 0,[e],void 0,(function(e){var r,t,n=e.fetcher,o=e.cartInfoToEnable,a=e.enabled;return l(this,(function(e){switch(e.label){case 0:return r={action:i.ACTIONS.AttributesUpdateInput,inputs:{attributes:[{key:(null==o?void 0:o.cartAttribute)||"redo_opted_in_from_cart",value:a.toString()}]}},[4,n.submit((t={},t[i.INPUT_NAME]=JSON.stringify(r),t),{method:"POST",action:"/cart"})];case 1:return e.sent(),[2]}}))}))};var R=r({enabled:!1,loading:!0}),j=function(e){var r=e.cart,o=e.storeId,a=e.children,i=t();i[0],i[1];var c=t();c[0],c[1];var f=t(),d=f[0],p=f[1],v=t(!0),y=v[0],h=v[1],b=t([]),E=b[0],I=b[1],k=function(e){return E.find((function(r){return r.type===e.type}))||I(s(s([],E,!0),[e],!1)),e};n((function(){var e,t,n,a,i,c,s;if(r&&o){var f=_(r);fetch("https://".concat(w,"/v2.2/stores/").concat(o,"/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,l,s,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===(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===(a=null===(n=r.cost)||void 0===n?void 0:n.totalAmount)||void 0===a?void 0:a.currencyCode}},customer:{id:(null===(c=null===(i=r.buyerIdentity)||void 0===i?void 0:i.customer)||void 0===c?void 0:c.id)||"",country:null===(s=r.buyerIdentity)||void 0===s?void 0:s.countryCode}})}).then((function(e){return u(void 0,void 0,void 0,(function(){var r,t,n,o,a,i,c,u,s,f,d,v;return l(this,(function(l){switch(l.label){case 0:return 500!==e.status?[3,2]:(r=k,a={type:m.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."},i={},[4,e.json()]);case 1:return r.apply(void 0,[(a.context=(i.json=l.sent(),i),a)]),[2];case 2:return 400!==e.status?[3,4]:(t=k,c={type:m.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."},u={},[4,e.json()]);case 3:return t.apply(void 0,[(c.context=(u.json=l.sent(),u),c)]),[2];case 4:return 200===e.status?[3,6]:(n=k,s={type:m.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,[(s.context=(f.json=l.sent(),f),s)]),[2];case 6:return[4,e.json()];case 7:return o=l.sent(),h(!1),(null===(v=null===(d=null==o?void 0:o.coverageProducts)||void 0===d?void 0:d[0])||void 0===v?void 0:v.cartInfoToEnable)?(p(o.coverageProducts[0].cartInfoToEnable),[2]):[2]}}))}))}))}}),[r,o]);var S={enabled:!0,loading:y,storeId:o,cartInfoToEnable:d,cart:r,errors:(null==E?void 0:E.length)&&E.length>0?E:void 0};return g.jsx(R.Provider,{value:S,children:a})},P=function(){var r=o(R),t=function(r){var t=this,n=a(r),o=e.useRef(null),i=e.useRef(null);i.current||(i.current=new Promise((function(e){o.current=e})));var s=e.useCallback((function(){i.current=new Promise((function(e){o.current=e}))}),[i,o]),f=e.useCallback((function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return u(t,void 0,void 0,(function(){return l(this,(function(r){return n.submit.apply(n,e),[2,i.current]}))}))}),[n,i]);return e.useEffect((function(){var e;"idle"===n.state&&(n.data&&(null===(e=o.current)||void 0===e||e.call(o,n.data)),s())}),[n,s]),c(c({},n),{submit:f})}();return n((function(){!r.loading&&r.cartInfoToEnable&&S({fetcher:t,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})}),[r.loading]),{enable:function(){return u(void 0,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return r.loading||!r.cartInfoToEnable?[2,!1]:[4,I({fetcher:t,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})];case 1:return e.sent(),[4,O({fetcher:t,cartInfoToEnable:r.cartInfoToEnable,enabled:!0})];case 2:return e.sent(),[2,!0]}}))}))},disable:function(){return u(void 0,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return r.cartInfoToEnable?[4,S({fetcher:t,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})]:[2,!1];case 1:return e.sent(),[4,O({fetcher:t,cartInfoToEnable:r.cartInfoToEnable,enabled:!1})];case 2:return e.sent(),[2,!0]}}))}))},get loading(){return r.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 r.enabled},get price(){var e,t,n,o=null===(n=null===(t=null===(e=r.cartInfoToEnable)||void 0===e?void 0:e.selectedVariant)||void 0===t?void 0:t.price)||void 0===n?void 0:n.amount;if(o&&"NaN"!==Number(o).toString())return Number(o)},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},get errors(){return r.errors}}},C=function(e){var r=e.redoCoverageClient,t=e.cart,n=e.storeId;return new Promise((function(e,o){fetch("https://".concat(w,"/v2.2/stores/").concat(n,"/checkout-buttons-ui"),{method:"GET",headers:{"Content-Type":"application/json"}}).then((function(n){return u(void 0,void 0,void 0,(function(){var a,i;return l(this,(function(c){switch(c.label){case 0:return[4,n.json()];case 1:return(a=c.sent()).html?(i=A({redoCoverageClient:r,cart:t,ui:a}))?[2,e(i)]:[2,o(null)]:[2,e(null)]}}))}))}))}))},A=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=!!_(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},N=function(e,r){return null==e?null:r(e)?e:N(e.parentElement,r)},x=function(e){var r,o=P(),a=o.cart,i=(null===(r=o.cart)||void 0===r?void 0:r.checkoutUrl)||"/checkout",c=t(null);c[0],c[1];var s=t(null),f=s[0],d=s[1];n((function(){u(void 0,void 0,void 0,(function(){var e;return l(this,(function(r){switch(r.label){case 0:return o.eligible&&a&&o.storeId?[4,C({redoCoverageClient:o,cart:a,storeId:o.storeId})]:[2];case 1:return(e=r.sent())&&d(e),[2]}}))}))}),[a,o.eligible,o.price,o.storeId]);return g.jsx("div",{children:f?g.jsxs("div",{onClick:function(r){return u(void 0,void 0,void 0,(function(){var t,n;return l(this,(function(a){switch(a.label){case 0:return(t=r.target).dataset?N(t,(function(e){var r;return"coverage-button"==(null===(r=e.dataset)||void 0===r?void 0:r.target)}))?[4,o.enable()]:[3,4]:[2];case 1:return n=a.sent(),e.onClick?[4,e.onClick(n)]:[3,3];case 2:a.sent(),a.label=3;case 3:return window.location.href=i,[3,8];case 4:return N(t,(function(e){return"non-coverage-button"==e.dataset.target}))?[4,o.disable()]:[3,8];case 5:return a.sent(),e.onClick?[4,e.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:[f.css?g.jsx("style",{children:f.css}):"",g.jsx("div",{dangerouslySetInnerHTML:{__html:f.html}})]}):e.children})};function $(e,r){var o=t({pending:!1}),a=o[0],i=o[1];return n((function(){var r=new AbortController;return i((function(e){return c(c({},e),{pending:!0})})),e(r.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(){r.abort(),i((function(e){return c(c({},e),{pending:!1})}))}}),r),a}export{E as REDO_REQUIRED_HOSTNAMES,x as RedoCheckoutButtons,m as RedoErrorType,j as RedoProvider,$ as useLoad,P as useRedoCoverageClient};
|
|
10
|
+
*/function b(){return v||(v=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"),l=Symbol.for("react.forward_ref"),s=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),v=Symbol.for("react.offscreen"),y=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 w(e){return e.displayName||"Context"}function E(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 f:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return w(e)+".Consumer";case c:return w(e._context)+".Provider";case l: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 d:var r=e.displayName||null;return null!==r?r:E(e.type)||"Memo";case p:var t=e,v=t._payload,y=t._init;try{return E(y(v))}catch(e){return null}}return null}g=Symbol.for("react.module.reference");var _,I,k,S,T,O,R,j=Object.assign,P=0;function C(){}C.__reactDisabledLog=!0;var A,N=b.ReactCurrentDispatcher;function x(e,r,t){if(void 0===A)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);A=n&&n[1]||""}return"\n"+A+e}var $,D=!1,U="function"==typeof WeakMap?WeakMap:Map;function F(e,r){if(!e||D)return"";var t,n=$.get(e);if(void 0!==n)return n;D=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=N.current,N.current=null,function(){if(0===P){_=console.log,I=console.info,k=console.warn,S=console.error,T=console.group,O=console.groupCollapsed,R=console.groupEnd;var e={configurable:!0,enumerable:!0,value:C,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}P++}();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"),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&&$.set(e,f),f}}while(l>=1&&s>=0);break}}}finally{D=!1,N.current=o,function(){if(0==--P){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:j({},e,{value:_}),info:j({},e,{value:I}),warn:j({},e,{value:k}),error:j({},e,{value:S}),group:j({},e,{value:T}),groupCollapsed:j({},e,{value:O}),groupEnd:j({},e,{value:R})})}P<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?x(d):"";return"function"==typeof e&&$.set(e,p),p}function L(e,r,t){if(null==e)return"";if("function"==typeof e)return F(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return x(e);switch(e){case s:return x("Suspense");case f:return x("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case l:return F(e.render,!1);case d:return L(e.type,r,t);case p:var o=e,a=o._payload,i=o._init;try{return L(i(a),r,t)}catch(e){}}return""}$=new U;var q=Object.prototype.hasOwnProperty,V={},W=b.ReactDebugCurrentFrame;function M(e){if(e){var r=e._owner,t=L(e.type,e._source,r?r.type:null);W.setExtraStackFrame(t)}else W.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,G=b.ReactCurrentOwner,H={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,r,n,o,a){var i,c={},u=null,l=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)&&(l=r.ref,function(e){"string"==typeof e.ref&&G.current}(r)),r)q.call(r,i)&&!H.hasOwnProperty(i)&&(c[i]=r[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,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),l&&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,l,a,o,G.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=E(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 "+E(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=y&&e[y]||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!==l&&t.$$typeof!==d)return;r=t.propTypes}if(r){var n=E(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||(M(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),M(null)),c instanceof Error&&!(c.message in V)&&(V[c.message]=!0,M(o),m("Failed %s type: %s",t,c.message),M(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?",E(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 le={};function se(e,r,n,y,h,b){var w=function(e){return"string"==typeof e||"function"==typeof e||e===o||e===i||e===a||e===s||e===f||e===v||"object"==typeof e&&null!==e&&(e.$$typeof===p||e.$$typeof===d||e.$$typeof===c||e.$$typeof===u||e.$$typeof===l||e.$$typeof===g||void 0!==e.getModuleId)}(e);if(!w){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 I;_+=oe(),null===e?I="null":z(e)?I="array":void 0!==e&&e.$$typeof===t?(I="<"+(E(e.type)||"Unknown")+" />",_=" Did you accidentally export a JSX literal instead of a component?"):I=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",I,_)}var k=Q(e,r,n,h,b);if(null==k)return k;if(w){var S=r.children;if(void 0!==S)if(y)if(z(S)){for(var T=0;T<S.length;T++)ce(S[T],e);Object.freeze&&Object.freeze(S)}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(S,e)}if(q.call(r,"key")){var O=E(e),R=Object.keys(r).filter((function(e){return"key"!==e})),j=R.length>0?"{key: someKey, "+R.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,R.length>0?"{"+R.join(": ..., ")+": ...}":"{}",O),le[O+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))}(k):ue(k),k}var fe=function(e,r,t){return se(e,r,t,!1)},de=function(e,r,t){return se(e,r,t,!0)};h.Fragment=o,h.jsx=fe,h.jsxs=de}()),h}var m,g=(y||(y=1,"production"===process.env.NODE_ENV?d.exports=function(){if(f)return p;f=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 c(e,r,n){var c,u={},l=null,s=null;for(c in void 0!==n&&(l=""+n),void 0!==r.key&&(l=""+r.key),void 0!==r.ref&&(s=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:l,ref:s,props:u,_owner:a.current}}return p.Fragment=n,p.jsx=c,p.jsxs=c,p}():d.exports=b()),d.exports);!function(e){e.ApiBadRequest="API_BAD_REQUEST",e.ApiServerError="API_SERVER_ERROR",e.ApiUnknownError="API_UNKNOWN_ERROR"}(m||(m={}));var w="api.getredo.com",E=[w],_=function(e){return Array.isArray(e.lines)&&"linesAdd"in e&&"function"==typeof e.linesAdd},I=function(e){var r;return _(e)?e.lines:null!==(r=e.lines.nodes)&&void 0!==r?r:e.lines.edges.map((function(e){return e.node}))},k=function(e){return new Promise((function(r,t){var n=setInterval((function(){if("idle"===e.status)return clearInterval(n),r()}),100)}))},S=function(e){return u(void 0,[e],void 0,(function(e){var r,t,n=e.cart,o=e.fetcher,a=e.cartInfoToEnable;return l(this,(function(e){switch(e.label){case 0:return n?[3,2]:[4,R({cart:n,fetcher:o,cartInfoToEnable:a})];case 1:case 3:return[2,e.sent()];case 2:return r=I(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(a.variantId)})),0!==r.length?[3,4]:[4,R({cart:n,fetcher:o,cartInfoToEnable:a})];case 4:return 1!==r.length||1!==t.length||1!==t[0].quantity?[3,5]:[2];case 5:return[4,T({cart:n,fetcher:o,lineIds:r.map((function(e){return e.id}))})];case 6:return e.sent(),[4,R({cart:n,fetcher:o,cartInfoToEnable:a})];case 7:return e.sent(),[2]}}))}))},T=function(e){return u(void 0,[e],void 0,(function(e){var r,t,n=e.cart,o=e.fetcher,a=e.lineIds;return l(this,(function(e){switch(e.label){case 0:return r={action:i.ACTIONS.LinesRemove,inputs:{lineIds:a}},n&&_(n)?(n.linesRemove(a),[4,k(n)]):[3,2];case 1:return e.sent(),[3,4];case 2:return[4,o.submit((t={},t[i.INPUT_NAME]=JSON.stringify(r),t),{method:"POST",action:"/cart"})];case 3:e.sent(),e.label=4;case 4:return[2]}}))}))},O=function(e){return u(void 0,[e],void 0,(function(e){var r,t=e.cart,n=e.fetcher;return e.cartInfoToEnable,l(this,(function(e){switch(e.label){case 0:return t?0===(r=I(t).filter((function(e){return"re:do"===e.merchandise.product.vendor}))).length?[3,2]:[4,T({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]}}))}))},R=function(e){return u(void 0,[e],void 0,(function(e){var r,t,n,o=e.cart,a=e.fetcher,c=e.cartInfoToEnable;return l(this,(function(e){switch(e.label){case 0:return r={merchandiseId:"gid://shopify/ProductVariant/".concat(c.variantId),quantity:1,selectedVariant:c.selectedVariant},t={action:i.ACTIONS.LinesAdd,inputs:{lines:[r]}},o&&_(o)?(o.linesAdd([r]),[4,k(o)]):[3,2];case 1:return e.sent(),[3,4];case 2:return[4,a.submit((n={},n[i.INPUT_NAME]=JSON.stringify(t),n),{method:"POST",action:"/cart"})];case 3:e.sent(),e.label=4;case 4:return[2]}}))}))},j=function(e){return u(void 0,[e],void 0,(function(e){var r,t,n,o=e.cart,a=e.fetcher,c=e.cartInfoToEnable,u=e.enabled;return l(this,(function(e){switch(e.label){case 0:return r={key:(null==c?void 0:c.cartAttribute)||"redo_opted_in_from_cart",value:u.toString()},t={action:i.ACTIONS.AttributesUpdateInput,inputs:{attributes:[r]}},o&&_(o)?(o.cartAttributesUpdate([r]),[4,k(o)]):[3,2];case 1:return e.sent(),[3,4];case 2:return[4,a.submit((n={},n[i.INPUT_NAME]=JSON.stringify(t),n),{method:"POST",action:"/cart"})];case 3:e.sent(),e.label=4;case 4:return[2]}}))}))};var P=r({enabled:!1,loading:!0}),C=function(e){var r=e.cart,o=e.storeId,a=e.children,i=t();i[0],i[1];var c=t();c[0],c[1];var f=t(),d=f[0],p=f[1],v=t(!0),y=v[0],h=v[1],b=t([]),E=b[0],_=b[1],k=function(e){return E.find((function(r){return r.type===e.type}))||_(s(s([],E,!0),[e],!1)),e};n((function(){var e,t,n,a,i,c,s;if(r&&o){var f=I(r);fetch("https://".concat(w,"/v2.2/stores/").concat(o,"/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,l,s,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===(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===(a=null===(n=r.cost)||void 0===n?void 0:n.totalAmount)||void 0===a?void 0:a.currencyCode}},customer:{id:(null===(c=null===(i=r.buyerIdentity)||void 0===i?void 0:i.customer)||void 0===c?void 0:c.id)||"",country:null===(s=r.buyerIdentity)||void 0===s?void 0:s.countryCode}})}).then((function(e){return u(void 0,void 0,void 0,(function(){var r,t,n,o,a,i,c,u,s,f,d,v;return l(this,(function(l){switch(l.label){case 0:return 500!==e.status?[3,2]:(r=k,a={type:m.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."},i={},[4,e.json()]);case 1:return r.apply(void 0,[(a.context=(i.json=l.sent(),i),a)]),[2];case 2:return 400!==e.status?[3,4]:(t=k,c={type:m.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."},u={},[4,e.json()]);case 3:return t.apply(void 0,[(c.context=(u.json=l.sent(),u),c)]),[2];case 4:return 200===e.status?[3,6]:(n=k,s={type:m.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,[(s.context=(f.json=l.sent(),f),s)]),[2];case 6:return[4,e.json()];case 7:return o=l.sent(),h(!1),(null===(v=null===(d=null==o?void 0:o.coverageProducts)||void 0===d?void 0:d[0])||void 0===v?void 0:v.cartInfoToEnable)?(p(o.coverageProducts[0].cartInfoToEnable),[2]):[2]}}))}))}))}}),[r,o]);var S={enabled:!0,loading:y,storeId:o,cartInfoToEnable:d,cart:r,errors:(null==E?void 0:E.length)&&E.length>0?E:void 0};return g.jsx(P.Provider,{value:S,children:a})},A=function(){var r=o(P),t=function(r){var t=this,n=a(r),o=e.useRef(null),i=e.useRef(null);i.current||(i.current=new Promise((function(e){o.current=e})));var s=e.useCallback((function(){i.current=new Promise((function(e){o.current=e}))}),[i,o]),f=e.useCallback((function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return u(t,void 0,void 0,(function(){return l(this,(function(r){return n.submit.apply(n,e),[2,i.current]}))}))}),[n,i]);return e.useEffect((function(){var e;"idle"===n.state&&(n.data&&(null===(e=o.current)||void 0===e||e.call(o,n.data)),s())}),[n,s]),c(c({},n),{submit:f})}();return n((function(){!r.loading&&r.cartInfoToEnable&&O({fetcher:t,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})}),[r.loading]),{enable:function(){return u(void 0,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return r.loading||!r.cartInfoToEnable?[2,!1]:[4,S({fetcher:t,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})];case 1:return e.sent(),[4,j({cart:r.cart,fetcher:t,cartInfoToEnable:r.cartInfoToEnable,enabled:!0})];case 2:return e.sent(),[2,!0]}}))}))},disable:function(){return u(void 0,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return r.cartInfoToEnable?[4,O({fetcher:t,cart:r.cart,cartInfoToEnable:r.cartInfoToEnable})]:[2,!1];case 1:return e.sent(),[4,j({cart:r.cart,fetcher:t,cartInfoToEnable:r.cartInfoToEnable,enabled:!1})];case 2:return e.sent(),[2,!0]}}))}))},get loading(){return r.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 r.enabled},get price(){var e,t,n,o=null===(n=null===(t=null===(e=r.cartInfoToEnable)||void 0===e?void 0:e.selectedVariant)||void 0===t?void 0:t.price)||void 0===n?void 0:n.amount;if(o&&"NaN"!==Number(o).toString())return Number(o)},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},get errors(){return r.errors}}},N=function(e){var r=e.redoCoverageClient,t=e.cart,n=e.storeId;return new Promise((function(e,o){fetch("https://".concat(w,"/v2.2/stores/").concat(n,"/checkout-buttons-ui"),{method:"GET",headers:{"Content-Type":"application/json"}}).then((function(n){return u(void 0,void 0,void 0,(function(){var a,i;return l(this,(function(c){switch(c.label){case 0:return[4,n.json()];case 1:return(a=c.sent()).html?(i=x({redoCoverageClient:r,cart:t,ui:a}))?[2,e(i)]:[2,o(null)]:[2,e(null)]}}))}))}))}))},x=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=!!I(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},$=function(e,r){return null==e?null:r(e)?e:$(e.parentElement,r)},D=function(e){var r,o=A(),a=o.cart,i=(null===(r=o.cart)||void 0===r?void 0:r.checkoutUrl)||"/checkout",c=t(null);c[0],c[1];var s=t(null),f=s[0],d=s[1];n((function(){u(void 0,void 0,void 0,(function(){var e;return l(this,(function(r){switch(r.label){case 0:return o.eligible&&a&&o.storeId?[4,N({redoCoverageClient:o,cart:a,storeId:o.storeId})]:[2];case 1:return(e=r.sent())&&d(e),[2]}}))}))}),[a,o.eligible,o.price,o.storeId]);return g.jsx("div",{children:f?g.jsxs("div",{onClick:function(r){return u(void 0,void 0,void 0,(function(){var t,n;return l(this,(function(a){switch(a.label){case 0:return(t=r.target).dataset?$(t,(function(e){var r;return"coverage-button"==(null===(r=e.dataset)||void 0===r?void 0:r.target)}))?[4,o.enable()]:[3,4]:[2];case 1:return n=a.sent(),e.onClick?[4,e.onClick(n)]:[3,3];case 2:a.sent(),a.label=3;case 3:return window.location.href=i,[3,8];case 4:return $(t,(function(e){return"non-coverage-button"==e.dataset.target}))?[4,o.disable()]:[3,8];case 5:return a.sent(),e.onClick?[4,e.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:[f.css?g.jsx("style",{children:f.css}):"",g.jsx("div",{dangerouslySetInnerHTML:{__html:f.html}})]}):e.children})};function U(e,r){var o=t({pending:!1}),a=o[0],i=o[1];return n((function(){var r=new AbortController;return i((function(e){return c(c({},e),{pending:!0})})),e(r.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(){r.abort(),i((function(e){return c(c({},e),{pending:!1})}))}}),r),a}export{E as REDO_REQUIRED_HOSTNAMES,D as RedoCheckoutButtons,m as RedoErrorType,C as RedoProvider,U as useLoad,A as useRedoCoverageClient};
|
|
11
11
|
//# sourceMappingURL=index.js.map
|