var _____WB$wombat$assign$function_____ = function(name) {return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; }; if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { this.__WB_source = obj; return this; } } { let window = _____WB$wombat$assign$function_____("window"); let self = _____WB$wombat$assign$function_____("self"); let document = _____WB$wombat$assign$function_____("document"); let location = _____WB$wombat$assign$function_____("location"); let top = _____WB$wombat$assign$function_____("top"); let parent = _____WB$wombat$assign$function_____("parent"); let frames = _____WB$wombat$assign$function_____("frames"); let opener = _____WB$wombat$assign$function_____("opener"); "use strict";(globalThis.webpackChunkcalypso=globalThis.webpackChunkcalypso||[]).push([[21546],{"./my-sites/checkout/cart-manager-client.ts":(t,e,r)=>{r.d(e,{h:()=>z});var o=r("../node_modules/debug/src/browser.js"),n=r.n(o);const a=n()("shopping-cart:cart-functions");let s=100;const i={blog_id:"",create_new_blog:!1,cart_generated_at_timestamp:0,cart_key:"no-site",products:[],total_tax:"0",total_tax_integer:0,total_tax_display:"0",total_tax_breakdown:[],total_cost:0,total_cost_integer:0,total_cost_display:"0",coupon_savings_total_integer:0,coupon_savings_total_display:"0",sub_total_with_taxes_integer:0,sub_total_with_taxes_display:"0",sub_total_integer:0,sub_total_display:"0",currency:"USD",credits_integer:0,credits_display:"0",allowed_payment_methods:[],coupon:"",is_coupon_applied:!1,coupon_discounts_integer:[],locale:"en-us",tax:{location:{},display_taxes:!1},is_signup:!1,next_domain_is_free:!1,next_domain_condition:""};function c(t){const{product_slug:e,meta:r,product_id:o,extra:n,volume:a,quantity:s}=t;return{product_slug:e,meta:r,volume:a,quantity:s,product_id:o,extra:n}}function u(t){return{...t,products:t.products.filter(d)}}function d(t){return"uuid"in t}function p(t,e){return{...t,products:t.products.filter((t=>!d(t)||t.uuid!==e))}}function l(t,e){return{...t,coupon:e,is_coupon_applied:!1}}function _(t,e){return{...t,tax:{...t.tax,location:{country_code:e.countryCode||void 0,postal_code:e.postalCode||void 0,subdivision_code:e.subdivisionCode||void 0}}}}function g(t){if("object"!=typeof t||null===t)return i;let e={};t.tax?.location&&(e=Array.isArray(t.tax.location)?{}:t.tax.location);const r=t.products?.length&&Array.isArray(t.products)?t.products:[];return{...i,...t,tax:{location:e,display_taxes:t.tax?.display_taxes??!1},products:r.filter(E).map((t=>({...t,uuid:t.product_slug+s++})))}}function E(t){return"wordpress-com-credits"!==t.product_slug}function y(t,e){return{...t,products:[...e]}}function h(t,e,r){return{...t,products:t.products.map((t=>d(t)&&t.uuid===e?{...t,...r}:t))}}var C=r("../node_modules/@babel/runtime/helpers/esm/defineProperty.js");class R extends Error{constructor(t,e){super(t),(0,C.Z)(this,"code",void 0),this.code=e}}class m extends R{}class f extends R{}const v=n()("shopping-cart:managers");function T(t){const{cacheStatus:e,queuedActions:r,couponStatus:o,loadingErrorType:n,loadingError:a,lastValidResponseCart:s}=t,i="fresh"===e||"fresh-pending"===e,c=r.length>0||"valid"!==e,u="error"===e?a:null;return v("manager isLoading",i,"isPendingUpdate",c,"loadingError",u),{isLoading:i,loadingError:u,loadingErrorType:n,isPendingUpdate:c,couponStatus:o,responseCart:s}}const S={blog_id:"",create_new_blog:!1,cart_generated_at_timestamp:0,cart_key:"no-site",products:[],total_tax:"0",total_tax_integer:0,total_tax_display:"0",total_tax_breakdown:[],total_cost:0,total_cost_integer:0,total_cost_display:"0",coupon_savings_total_integer:0,coupon_savings_total_display:"0",sub_total_with_taxes_integer:0,sub_total_with_taxes_display:"0",sub_total_integer:0,sub_total_display:"0",currency:"USD",credits_integer:0,credits_display:"0",allowed_payment_methods:[],coupon:"",is_coupon_applied:!1,coupon_discounts_integer:[],locale:"en-us",tax:{location:{},display_taxes:!1},is_signup:!1,next_domain_is_free:!1,next_domain_condition:""},A=()=>Promise.reject("Cart actions cannot be taken without a cart key."),b={isLoading:!0,loadingError:void 0,loadingErrorType:void 0,isPendingUpdate:!0,couponStatus:"fresh",responseCart:S},x={actions:{addProductsToCart:A,removeProductFromCart:A,applyCoupon:A,removeCoupon:A,updateLocation:A,replaceProductInCart:A,replaceProductsInCart:A,reloadFromServer:()=>Promise.resolve(S),clearMessages:()=>Promise.resolve(S)},getState:()=>b,subscribe:()=>()=>null,fetchInitialCart:()=>Promise.resolve(S)};var P=r("../packages/shopping-cart/src/create-request-cart-product.ts");const w=n()("shopping-cart:shopping-cart-reducer"),O={blog_id:"",create_new_blog:!1,cart_generated_at_timestamp:0,cart_key:"no-site",products:[],total_tax:"0",total_tax_integer:0,total_tax_display:"0",total_tax_breakdown:[],total_cost:0,total_cost_integer:0,total_cost_display:"0",coupon_savings_total_integer:0,coupon_savings_total_display:"0",sub_total_with_taxes_integer:0,sub_total_with_taxes_display:"0",sub_total_integer:0,sub_total_display:"0",currency:"USD",credits_integer:0,credits_display:"0",allowed_payment_methods:[],coupon:"",is_coupon_applied:!1,coupon_discounts_integer:[],locale:"en-us",tax:{location:{},display_taxes:!1},is_signup:!1,next_domain_is_free:!1,next_domain_condition:""},I=["RECEIVE_INITIAL_RESPONSE_CART","RECEIVE_UPDATED_RESPONSE_CART","FETCH_INITIAL_RESPONSE_CART","RAISE_ERROR"],D=["fresh","pending","fresh-pending"],L=["invalid","fresh","pending","fresh-pending"];function U(t){return t.queuedActions.length>0||"valid"!==t.cacheStatus}function k(t,e){if(L.includes(t.cacheStatus)&&"CART_RELOAD"===e.type)return w("cart is pending an operation; ignoring reload action"),t;if(function(t,e){return!I.includes(e.type)&&!!D.includes(t)}(t.cacheStatus,e))return w("cart has not yet loaded; queuing requested action",e),{...t,queuedActions:[...t.queuedActions,e]};const r=t;if(function(t){return t.queuedActions.length>0&&"valid"===t.cacheStatus}(t=q(t,e))){w("playing queued actions",t.queuedActions);t=[...t.queuedActions,{type:"CLEAR_QUEUED_ACTIONS"}].reduce(q,t),w("queued actions are dispatched and queue is cleared")}return t===r||U(t)||(t=q(t,{type:"UPDATE_LAST_VALID_CART"})),t}function q(t,e){w("processing requested action",e);const r=t.couponStatus;switch(e.type){case"UPDATE_LAST_VALID_CART":return{...t,lastValidResponseCart:u(t.responseCart)};case"FETCH_INITIAL_RESPONSE_CART":return{...t,cacheStatus:"fresh-pending",loadingError:void 0,loadingErrorType:void 0};case"CART_RELOAD":return w("reloading cart from server"),{...t,cacheStatus:"fresh",loadingError:void 0,loadingErrorType:void 0};case"CLEAR_MESSAGES":return{...t,responseCart:{...t.responseCart,messages:{errors:[],success:[]}}};case"CLEAR_QUEUED_ACTIONS":return{...t,queuedActions:[]};case"REMOVE_CART_ITEM":{const r=e.uuidToRemove;return w("removing item from cart with uuid",r),{...t,responseCart:p(t.responseCart,r),cacheStatus:"invalid",loadingError:void 0,loadingErrorType:void 0}}case"CART_PRODUCTS_ADD":return w("adding items to cart",e.products),{...t,responseCart:(n=t.responseCart,s=e.products,function(t,e){return t.some((t=>function(t,e){const r=e.products.some((t=>"renewal"===t.extra?.purchaseType));return!r&&"renewal"===t.extra?.purchaseType&&"domain_redemption"!==t.product_slug||!(!r||"renewal"===t.extra?.purchaseType)}(t,e)))}(s,n)?(a("items should replace response cart",s),y(n,s)):(a("items should not replace response cart",s),{...n,products:[...n.products,...s]})),cacheStatus:"invalid",loadingError:void 0,loadingErrorType:void 0};case"CART_PRODUCTS_REPLACE_ALL":return w("replacing items in cart with",e.products),{...t,responseCart:y(t.responseCart,e.products),cacheStatus:"invalid",loadingError:void 0,loadingErrorType:void 0};case"CART_PRODUCT_REPLACE":{const r=e.uuidToReplace;return function(t,e){return t.products.some((t=>d(t)&&Object.keys(e).every((r=>{const o=r;return t[o]===e[o]}))))}(t.responseCart,{uuid:r,...e.productPropertiesToChange})?(w("variant is already in cart; not submitting again"),t):(w(`replacing item with uuid ${r} with`,e.productPropertiesToChange),{...t,responseCart:h(t.responseCart,r,e.productPropertiesToChange),cacheStatus:"invalid",loadingError:void 0,loadingErrorType:void 0})}case"REMOVE_COUPON":return"applied"!==r?(w(`coupon status is '${r}'; not removing`),t):(w("removing coupon"),{...t,responseCart:(o=t.responseCart,{...o,coupon:"",is_coupon_applied:!1}),couponStatus:"fresh",cacheStatus:"invalid",loadingError:void 0,loadingErrorType:void 0});case"ADD_COUPON":{const o=e.couponToAdd;return"applied"!==r&&"pending"!==r||o!==t.responseCart.coupon?(w("adding coupon",o),{...t,responseCart:l(t.responseCart,o),couponStatus:"pending",cacheStatus:"invalid",loadingError:void 0,loadingErrorType:void 0}):(w(`coupon status is '${r}'; not submitting again`),t)}case"RECEIVE_INITIAL_RESPONSE_CART":{const o=e.initialResponseCart;return{...t,responseCart:o,couponStatus:N(r,o),cacheStatus:"valid",loadingError:void 0,loadingErrorType:void 0}}case"REQUEST_UPDATED_RESPONSE_CART":return{...t,cacheStatus:"pending",loadingError:void 0,loadingErrorType:void 0};case"RECEIVE_UPDATED_RESPONSE_CART":{const o=e.updatedResponseCart,n=N(r,o),a=o.cart_key,s=o.products.map((t=>t.product_slug));return"no-user"===a&&function(t){let e=null;try{e=JSON.parse(window.localStorage.getItem("shoppingCart")||"[]")}catch(t){return}if(!Array.isArray(e))return;const r=e.filter((e=>t.includes(e.product_slug)));try{window.localStorage.setItem("shoppingCart",JSON.stringify(r))}catch(t){return}}(s),{...t,responseCart:o,couponStatus:n,cacheStatus:"valid",loadingError:void 0,loadingErrorType:void 0}}case"RAISE_ERROR":switch(e.error){case"GET_SERVER_CART_ERROR":return{...t,cacheStatus:"error",loadingError:e.message||"Error while fetching the shopping cart. Please check your network connection and try again.",loadingErrorType:e.error};case"SET_SERVER_CART_ERROR":return{...t,cacheStatus:"error",loadingError:e.message||"Error while updating the shopping cart endpoint. Please check your network connection and try again.",loadingErrorType:e.error};default:return t}case"SET_LOCATION":return function(t,e){const{countryCode:r="",postalCode:o="",subdivisionCode:n=""}=e,{country_code:a="",postal_code:s="",subdivision_code:i=""}=t.tax?.location??{};return void 0!==e.countryCode&&r!==a||void 0!==e.postalCode&&o!==s||void 0!==e.subdivisionCode&&n!==i}(t.responseCart,e.location)?(w("changing location on cart from",t.responseCart.tax.location,"to",e.location),{...t,responseCart:_(t.responseCart,e.location),cacheStatus:"invalid",loadingError:void 0,loadingErrorType:void 0}):(w("cart location is the same; not updating"),t);default:return t}var o,n,s}function N(t,e){return e.is_coupon_applied?"applied":"pending"===t?"rejected":"fresh"}const V=n()("shopping-cart:state-based-actions");function j(t){let e;return(r,o)=>{e&&clearTimeout(e),e=setTimeout((()=>{V("cache status before state-based-actions is",r.cacheStatus),function(t,e,r){const{cacheStatus:o}=t;"fresh"===o&&(V("triggering fetch of initial cart"),e({type:"FETCH_INITIAL_RESPONSE_CART"}),r.fetchInitialCartFromServer(e))}(r,o,t),function(t,e,r){const{queuedActions:o,cacheStatus:n}=t;0===o.length&&"invalid"===n&&(V("triggering sync of cart to server"),e({type:"REQUEST_UPDATED_RESPONSE_CART"}),r.syncPendingCartToServer(t,e))}(r,o,t),V("running state-based-actions complete")}))}}var $=r("../packages/shopping-cart/src/cart-keys.ts");const M=n()("shopping-cart:sync"),F={blog_id:"",create_new_blog:!1,cart_generated_at_timestamp:0,cart_key:"no-site",products:[],total_tax:"0",total_tax_integer:0,total_tax_display:"0",total_tax_breakdown:[],total_cost:0,total_cost_integer:0,total_cost_display:"0",coupon_savings_total_integer:0,coupon_savings_total_display:"0",sub_total_with_taxes_integer:0,sub_total_with_taxes_display:"0",sub_total_integer:0,sub_total_display:"0",currency:"USD",credits_integer:0,credits_display:"0",allowed_payment_methods:[],coupon:"",is_coupon_applied:!1,coupon_discounts_integer:[],locale:"en-us",tax:{location:{},display_taxes:!1},is_signup:!1,next_domain_is_free:!1,next_domain_condition:""};function K(t,e,r){const o=$.e.includes(t),n=()=>o?Promise.resolve(F):e(t);return{syncPendingCartToServer(e,o){const n=function({products:t,coupon:e,tax:r}){let o=null;return(r.location.country_code||r.location.postal_code||r.location.subdivision_code)&&(o={location:{country_code:r.location.country_code,postal_code:r.location.postal_code,subdivision_code:r.location.subdivision_code}}),{products:t.map(c),coupon:e,temporary:!1,tax:o}}(e.responseCart);var a;M("sending edited cart to server",n),(a=n,r(t,a)).then((t=>{M("update cart request complete",n,"; updated cart is",t),o({type:"RECEIVE_UPDATED_RESPONSE_CART",updatedResponseCart:g(t)})})).catch((t=>{M("error while setting cart",t),o({type:"RAISE_ERROR",error:"SET_SERVER_CART_ERROR",message:t.message})}))},fetchInitialCartFromServer(t){M("fetching initial cart from server"),n().then((e=>{M("initialized cart is",e);const r=g(e);t({type:"RECEIVE_INITIAL_RESPONSE_CART",initialResponseCart:r})})).catch((e=>{M("error while initializing cart",e),t({type:"RAISE_ERROR",error:"GET_SERVER_CART_ERROR",message:e.message})}))}}}const G=n()("shopping-cart:shopping-cart-manager");function Q(t){if(t.loadingError)return new m(t.loadingError,t.loadingErrorType);const e=t.responseCart.messages?.errors??[];if(e.length>0){const t=e[0];return new f(t.message,t.code)}}function Z(t,e,r){let o={responseCart:O,lastValidResponseCart:O,cacheStatus:"fresh",couponStatus:"fresh",queuedActions:[]};const n=function(t){let e=[];return{subscribe:r=>(v(`adding subscriber for cartKey ${t}`),e.push(r),()=>{v(`removing subscriber for cartKey ${t}`),e=e.filter((t=>t!==r))}),notifySubscribers:()=>{v(`notifying ${e.length} subscribers for cartKey ${t}`),e.forEach((t=>{try{t()}catch(t){throw console.error("An error ocurred while notifying a subscriber of a ShoppingCartManager change",t.message),t}})),v(`completed notification of subscribers for cartKey ${t}`)}}}(t),a=K(t,e,r),s=function(){let t=[];return{resolve(e){if(t.length>0){v(`resolving ${t.length} action promises`);const r=u(e);t.forEach((t=>t.resolve(r))),t=[]}},reject(e){t.length>0&&(v(`rejecting ${t.length} action promises`),t.forEach((t=>t.reject(e))),t=[])},add(e){t.push(e)}}}(),i=j(a),c=e=>{G(`dispatching action for cartKey ${t}`,e.type);const r=k(o,e),a=r!==o;if(o=r,"error"===o.cacheStatus&&s.reject(new m(o.loadingError,o.loadingErrorType)),!U(o)){const t=Q(o);t?s.reject(t):s.resolve(o.responseCart)}a&&(i(o,c),n.notifySubscribers())},d=function(t,e){return r=>new Promise(((o,n)=>{e.add({resolve:o,reject:n}),t(r)}))}(c,s),p=function(t){return{reloadFromServer:()=>t({type:"CART_RELOAD"}),clearMessages:()=>t({type:"CLEAR_MESSAGES"}),removeCoupon:()=>t({type:"REMOVE_COUPON"}),addProductsToCart:async e=>t({type:"CART_PRODUCTS_ADD",products:(0,P.A)(e)}),removeProductFromCart:e=>t({type:"REMOVE_CART_ITEM",uuidToRemove:e}),replaceProductsInCart:async e=>t({type:"CART_PRODUCTS_REPLACE_ALL",products:(0,P.A)(e)}),replaceProductInCart:(e,r)=>t({type:"CART_PRODUCT_REPLACE",uuidToReplace:e,productPropertiesToChange:r}),updateLocation:e=>t({type:"SET_LOCATION",location:e}),applyCoupon:e=>t({type:"ADD_COUPON",couponToAdd:e})}}(d);let l=T(o),_=o;let g=!1;return{subscribe:n.subscribe,actions:p,getState:()=>(_!==o&&(l=T(o),_=o),l),fetchInitialCart:()=>{if(g){const t=Q(o);return t?Promise.reject(t):Promise.resolve(o.lastValidResponseCart)}return g=!0,i(o,c),new Promise(((t,e)=>{s.add({resolve:t,reject:e})}))}}}var H=r("./lib/wp/browser.js");const z=function({getCart:t,setCart:e}){const r=new Map;return{forCartKey:function(o){if(!o)return x;let n=r.get(o);return void 0===n&&(G(`creating cart manager for "${o}"`),n=Z(o,t,e),r.set(o,n)),n},getCartKeyForSiteSlug:e=>async function(t,e){try{return(await e(t)).cart_key}catch{return"no-site"}}(e,t)}}({getCart:t=>{let e;try{e=window?.location?.pathname}catch{}return H.Z.req.get(`/me/shopping-cart/${t}?source=${e??"unknown"}`)},setCart:(t,e)=>H.Z.req.post(`/me/shopping-cart/${t}`,e)})},"../packages/shopping-cart/src/cart-keys.ts":(t,e,r)=>{r.d(e,{e:()=>o});const o=["no-user"]},"../packages/shopping-cart/src/create-request-cart-product.ts":(t,e,r)=>{function o(t){if(!t.product_slug)throw new Error("product_slug is required for request cart products");const{product_slug:e,product_id:r,meta:o,volume:n,quantity:a,extra:s}=t;return{product_slug:e,product_id:r,meta:o??"",volume:n??1,quantity:a??null,extra:s??{}}}function n(t){return t.map(o)}r.d(e,{Z:()=>o,A:()=>n})}}]); } /* FILE ARCHIVED ON 19:45:01 Jun 07, 2022 AND RETRIEVED FROM THE INTERNET ARCHIVE ON 04:52:19 Nov 19, 2024. JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C. SECTION 108(a)(3)). */ /* playback timings (ms): captures_list: 0.641 exclusion.robots: 0.026 exclusion.robots.policy: 0.015 esindex: 0.011 cdx.remote: 6.27 LoadShardBlock: 150.881 (6) PetaboxLoader3.datanode: 220.128 (7) load_resource: 116.756 PetaboxLoader3.resolve: 38.771 */