@lockerverse/sdk 0.2.97 → 0.2.99

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/dist/checkout.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as e,c as t,d as n,i as r,l as i,m as a,n as o,o as s,r as c,s as l,t as u,u as d}from"./transport.js";import{n as f,t as p}from"./types.js";import{array as m,boolean as h,check as g,finite as _,literal as v,looseObject as y,maxValue as ee,minLength as b,minValue as x,nullable as S,number as C,object as w,optional as T,parser as E,picklist as D,pipe as O,record as k,regex as A,safeParse as j,strictObject as M,string as N,transform as te,union as P,unknown as F,variant as ne}from"valibot";function re(e){let t=a(e,`widgetSlug`);return{...t,widgetSlug:t.resourceSlug,widgetSlugValue:t.resourceSlugValue}}const I=D([`one-time`,`monthly`,`annually`]),L=D([`none`,`event_admission`]),R=S(t(0)),ie=D([`available`,`sold_out`]),ae=T(w({listings:m(w({listingId:s,maxPurchasableQuantity:R,remainingQuantity:R,status:ie})),sharedLimits:m(w({id:s,listingIds:m(s),remainingQuantity:t(0),status:ie}))}),{listings:[],sharedLimits:[]}),oe=O(N(),A(/^pk_(?:test|live)_\S+$/,`Invalid publishable key.`)),z={description:l,fulfillmentType:L,id:s,inventoryQuantity:R,maxQuantity:R,minimumAmountCents:R,minQuantity:R,name:s,paymentOption:I},B=w({description:S(N()),endAt:s,id:s,location:S(N()),name:s,startAt:s,status:D([`draft`,`active`,`finished`,`cancelled`])}),se=O(ne(`pricingMode`,[w({...z,amountCents:t(0),pricingMode:v(`fixed`)}),w({...z,amountCents:R,pricingMode:v(`custom`)})]),g(({maxQuantity:e,minQuantity:t})=>e===null||t===null||t<=e)),ce=w({acceptsDiscounts:T(h(),!1),id:s,product:se,productId:s,slug:s}),V=T(w({memberId:T(h(),!1),merchSize:T(h(),!1),phone:T(h(),!1),promoCode:T(h(),!1),serviceFee:T(h(),!1),shipping:T(h(),!1),tipping:T(h(),!1)}),{}),le=O(w({availability:ae,community:T(w({color:N(),name:s,thumbnail:S(N())})),config:T(w({customFields:e,fields:V})),description:l,event:S(B),id:T(N(),``),name:T(N(),`Lockerverse widget`),payment:w({connectedAccountId:T(S(s),null),currency:v(`usd`),publishableKey:oe}),pricingPolicy:T(w({currency:T(v(`usd`),`usd`),serviceFeeRateBasisPoints:T(t(0),0)})),products:T(m(ce),[]),showCommunityBranding:T(h(),!0),title:l}),te(e=>({...e,config:{customFields:e.config?.customFields??[],fields:{memberId:e.config?.fields?.memberId??!1,merchSize:e.config?.fields?.merchSize??!1,phone:e.config?.fields?.phone??!1,promoCode:e.config?.fields?.promoCode??!1,serviceFee:e.config?.fields?.serviceFee??!1,shipping:e.config?.fields?.shipping??!1,tipping:e.config?.fields?.tipping??!1}},pricingPolicy:e.pricingPolicy??{currency:`usd`,serviceFeeRateBasisPoints:0}}))),ue=w({acceptsDiscounts:h(),amountCents:S(t(0)),description:S(N()),fulfillmentType:L,id:s,inventoryQuantity:R,listingId:s,maximumQuantity:R,minimumAmountCents:R,minimumQuantity:R,name:s,paymentOption:I,pricingMode:D([`fixed`,`custom`]),slug:s}),de=w({availability:ae,community:S(w({accentColor:N(),imageUrl:S(N()),name:s})),event:S(B),payment:w({connectedAccountId:T(S(s),null),currency:v(`usd`),publishableKey:oe}),pricingPolicy:w({currency:v(`usd`),serviceFeeRateBasisPoints:t(0)}),products:m(ue),widget:w({customFields:e,description:S(N()),fields:V,id:N(),name:s,showCommunityBranding:h(),title:S(N())})}),fe=S(w({percentageOff:O(C(),_(),x(0),ee(100)),source:D([`email_list`,`promo_code`])})),pe=w({acceptsDiscounts:h(),eventId:S(s),fulfillmentType:L,listingId:s,listingSlug:s,paymentOption:I,pricingMode:D([`fixed`,`custom`]),productId:s,productName:s,quantity:t(1),subtotalCents:t(0),unitAmountCents:t(0)}),me=O(d,w({amountCents:t(0),appliedDiscount:fe,connectedAccountId:S(s),discountableSubtotalCents:t(0),discountCents:t(0),lineItems:m(pe),paymentOption:I,serviceFeeCents:t(0),subtotalCents:t(0),tipCents:t(0),totalCents:t(0)}),g(({lineItems:e,paymentOption:t})=>e.length===0||e.some(e=>e.paymentOption!==t)?!1:t===`one-time`||e.length===1&&e[0]?.pricingMode===`fixed`&&e[0].quantity===1,`Invalid checkout cadence composition.`)),he=O(i,g(e=>e.checkoutId.trim()&&e.paymentReference.trim()?e.checkoutStatus===`action_required`?e.requiresAction&&e.paymentRequired&&!!e.clientSecret?.trim():!e.requiresAction&&e.clientSecret===null:!1,`Invalid payment result state.`)),H=E(me),ge=E(de),U=E(he),_e=E(n),ve=E(le);function ye(e){return _e(e),ve(e)}function be(e){let t=j(y({quote:T(F())}),e),n=ye(e),r=t.success?t.output.quote:void 0;return r===void 0?{widget:n}:{quote:H(r),widget:n}}const xe={email:T(N()),includeServiceFee:T(h()),promoCode:T(N()),tipCents:T(t(0))},W=M(xe),G=E(T(W,{})),Se=M({confirmationToken:T(s),customFieldAnswers:T(m(r)),email:N(),memberId:T(N()),merchSize:T(D([`XS`,`S`,`M`,`L`,`XL`,`XXL`,`XXXL`])),metadata:T(k(N(),N())),phone:T(N()),shipping:T(M({address:M({city:N(),country:N(),line1:N(),line2:T(N()),postal_code:N(),state:N()}),name:N()}))}),Ce=P([M({amountCents:t(1),productId:s}),M({productId:s,quantity:t(1)}),M({productId:s})]),we=P([M({amountCents:t(1),productSlug:s}),M({productSlug:s,quantity:t(1)}),M({productSlug:s})]),K=O(m(Ce),b(1)),q=O(m(we),b(1)),Te=w({selection:q}),Ee=y({catalog:T(F()),email:T(F()),includeServiceFee:T(F()),items:T(K),promoCode:T(F()),selection:T(q),tipCents:T(F())}),J=O(y({authoritative:v(!0),items:K,payment:w({connectedAccountId:S(s),currency:v(`usd`),publishableKey:O(N(),b(1))}),paymentReference:O(N(),b(1)),pricing:W}),te(e=>{let{items:t,payment:n,paymentReference:r,pricing:i,...a}=e,o=H({...a,connectedAccountId:n.connectedAccountId}),{connectedAccountId:s,...c}=o;return{items:t,pricing:i,quote:{...c,authoritative:!0,payment:{connectedAccountId:s,currency:`usd`,publishableKey:n.publishableKey},paymentOption:o.paymentOption,paymentReference:r}}})),De=y({checkout:J,submission:Se}),Oe=s,ke=E(y({})),Ae=E(Ee);function je(e){let{catalog:t,items:n,selection:r,...i}=Ae(e),a;try{a=ke(t)}catch(e){throw TypeError(`A catalog is required to calculate a checkout.`,{cause:e})}try{return{catalog:a,items:n,pricing:G(i),selection:r}}catch(e){throw TypeError(`Checkout pricing input is invalid.`,{cause:e})}}const Me=E(Te),Ne=E(Oe);E(J);const Pe=E(De),Fe=E(q);function Y(e){return Math.max(100,e.minimumAmountCents??0)}function Ie(e,t){let n=new Map(e.products.map(({id:e,listingId:t})=>[e,t])),r=t.reduce((e,t)=>{let r=n.get(t.productId);return r&&e.set(r,(e.get(r)??0)+(`quantity`in t?t.quantity??1:1)),e},new Map),i=e.availability.listings.some(({listingId:e,maxPurchasableQuantity:t,status:n})=>r.has(e)&&(n===`sold_out`||t!==null&&(r.get(e)??0)>t)),a=e.availability.sharedLimits.some(({listingIds:e,remainingQuantity:t,status:n})=>{let i=e.reduce((e,t)=>e+(r.get(t)??0),0);return i>0&&(n===`sold_out`||i>t)});if(i||a)throw new f({code:`total_calculation_failed`,message:`This option is sold out.`,operation:`calculate_total`,reportable:!1,serverCode:`PAYMENT_WIDGET_SALES_LIMIT_REACHED`})}function Le(e,t){if(e.pricingMode!==`custom`||e.paymentOption!==`one-time`||t<Y(e))throw TypeError(`Selected Product amount is invalid.`);return{checkoutItem:{amountCents:t,productId:e.id},quantity:1,unitAmountCents:t}}function Re(e,t){if(e.pricingMode!==`fixed`||e.amountCents===null)throw TypeError(`Selected Product quantity is invalid.`);if(e.paymentOption!==`one-time`&&t!==1)throw TypeError(`Selected recurring Product is invalid.`);if(e.minimumQuantity!==null&&t<e.minimumQuantity||e.maximumQuantity!==null&&t>e.maximumQuantity||e.inventoryQuantity!==null&&t>e.inventoryQuantity)throw TypeError(`Selected Product quantity is invalid.`);return{checkoutItem:e.paymentOption===`one-time`?{productId:e.id,quantity:t}:{productId:e.id},quantity:t,unitAmountCents:e.amountCents}}function ze(e,t,n){let r=`quantity`in n?n.quantity:1,{checkoutItem:i,quantity:a,unitAmountCents:o}=`amountCents`in n?Le(t,n.amountCents):Re(t,r);return{checkoutItem:i,lineItem:{acceptsDiscounts:t.acceptsDiscounts,eventId:t.fulfillmentType===`event_admission`&&e.event?e.event.id:null,fulfillmentType:t.fulfillmentType,listingId:t.listingId,listingSlug:t.slug,paymentOption:t.paymentOption,pricingMode:t.pricingMode,productId:t.id,productName:t.name,quantity:a,subtotalCents:o*a,unitAmountCents:o}}}function X(e,t){let n=Fe(t),r=new Set,i=n.map(t=>{let n=e.products.find(e=>e.slug===t.productSlug);if(!n)throw TypeError(`Selected Product is unavailable.`);if(r.has(n.id))throw TypeError(`Each Product can appear only once per checkout.`);return r.add(n.id),ze(e,n,t)}),a=i[0]?.lineItem.paymentOption;if(!a)throw TypeError(`Select at least one Product.`);if(i.length>1&&(a!==`one-time`||i.some(({lineItem:e})=>e.paymentOption!==a)))throw TypeError(`Recurring Products must be purchased separately.`);let o=i.map(({checkoutItem:e})=>e);return Ie(e,o),{items:o,lineItems:i.map(({lineItem:e})=>e),paymentOption:a}}function Be(e){let{product:t}=e;return{acceptsDiscounts:e.acceptsDiscounts??!1,amountCents:t.amountCents,description:t.description??null,fulfillmentType:t.fulfillmentType,id:t.id,inventoryQuantity:t.inventoryQuantity,listingId:e.id,maximumQuantity:t.maxQuantity,minimumAmountCents:t.minimumAmountCents,minimumQuantity:t.minQuantity,name:t.name,paymentOption:t.paymentOption,pricingMode:t.pricingMode,slug:e.slug}}function Ve(e){let t=e.config?.fields??{};return{availability:e.availability,community:e.community?{accentColor:e.community.color,imageUrl:e.community.thumbnail||null,name:e.community.name}:null,event:e.event?{description:e.event.description,endAt:e.event.endAt,id:e.event.id,location:e.event.location,name:e.event.name,startAt:e.event.startAt,status:e.event.status}:null,payment:{connectedAccountId:e.payment.connectedAccountId,currency:e.payment.currency,publishableKey:e.payment.publishableKey},pricingPolicy:{currency:`usd`,serviceFeeRateBasisPoints:e.pricingPolicy?.serviceFeeRateBasisPoints??0},products:(e.products??[]).map(Be),widget:{customFields:e.config?.customFields??[],description:e.description??null,fields:{memberId:t.memberId??!1,merchSize:t.merchSize??!1,phone:t.phone??!1,promoCode:t.promoCode??!1,serviceFee:t.serviceFee??!1,shipping:t.shipping??!1,tipping:t.tipping??!1},id:e.id??``,name:e.name??`Lockerverse widget`,showCommunityBranding:e.showCommunityBranding??!0,title:e.title??null}}}function Z(e){return Q(e)}function He(e){return Q(e)}function Ue(e){return Q(e)}function Q(e){return c(structuredClone(e))}const We=w({code:D([`PAYMENT_WIDGET_PHONE_INVALID`,`PAYMENT_WIDGET_PHONE_REQUIRED`,`PAYMENT_WIDGET_SALES_LIMIT_REACHED`])});async function $(e){if(e.status===400||e.status===409)try{let t=j(We,await e.json());return t.success?t.output.code:void 0}catch{}}function Ge({catalog:e,items:t,selection:n}){if(t!==void 0&&n!==void 0)throw TypeError(`Use items or selection, not both.`);let r=Z(ge(e)),i=n===void 0?Ke(t):X(r,n).items;return Ie(r,i),{catalog:r,items:i}}function Ke(e){if(e===void 0)throw TypeError(`Checkout selection is invalid.`);return e}function qe(e){let{apiBaseUrl:t,communitySlug:n,communitySlugValue:r,environment:i,fetchImplementation:a,onError:s,requestTimeoutMs:l,sentryDsn:d,widgetSlug:p,widgetSlugValue:m}=re(e),h=o({communitySlug:r,environment:i,getContext:()=>({widgetSlug:m}),onError:s,resourceContextName:`lockerverse_widget`,sentryDsn:d}),{requestJson:g}=u(a,h,l),_=`${t}/v2/community/${n}/payment-widgets/${p}/checkout`,v=`${t}/v2/community/${n}/payment-widgets/${p}`;function y(e,t,n=`invalid_selection`){throw h(new f({code:n,message:e,operation:t,reportable:!1}))}function ee(e,t){return e instanceof f?e:new f({...t,reportable:!0})}function b(e,t,n=!1){let r=ee(e,t);if(!(n&&(r.status===void 0||r.status>=500)))throw h(r);let i=r.status===void 0?new f({code:r.code,message:r.message,operation:r.operation,recoveryRecommended:!0,reportable:r.reportable}):new f({code:r.code,message:r.message,operation:r.operation,recoveryRecommended:!0,reportable:r.reportable,status:r.status});throw h(i)}function x(e){let t=e.email?.trim().toLowerCase(),n=e.promoCode?.trim(),r={};return t&&(r.email=t),e.includeServiceFee!==void 0&&(r.includeServiceFee=e.includeServiceFee),n&&(r.promoCode=n),e.tipCents!==void 0&&(r.tipCents=e.tipCents),r}function S(e){try{return Me(e).selection}catch{y(`Checkout selection is invalid.`,`load_widget`)}}function C(e,t,n,r){let{connectedAccountId:i,...a}=e;return He(c({...a,authoritative:!0,items:t,payment:{connectedAccountId:i,currency:`usd`,publishableKey:r.publishableKey},paymentOption:e.paymentOption,paymentReference:globalThis.crypto.randomUUID(),pricing:n}))}function w(e,t,n){try{return X(e,t).items}catch(e){throw e instanceof TypeError&&y(e.message,n),e}}function T(e,t,n,r){if(!n)throw new f({...r,message:`Lockerverse did not return the requested initial quote.`,reportable:!0});let i=w(e,t,r.operation);return c({catalog:Z(e),checkout:C(n,i,{includeServiceFee:e.widget.fields.serviceFee},e.payment)})}async function E(e){let t={code:`widget_load_failed`,message:`Lockerverse returned an invalid widget catalog.`,operation:`load_widget`},n=e?`${v}?selection=${encodeURIComponent(JSON.stringify(e))}`:v,r=await g(n,e?{cache:`no-store`}:void 0,be,{...t,message:`Unable to load Lockerverse widget because the request failed.`,report:!1},{...t,report:!1});if(!r.ok){let e=await $(r.response);throw e===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`?new f({...t,message:`This option is sold out.`,reportable:!1,serverCode:e,status:r.response.status}):new f({...t,message:`Unable to load Lockerverse widget (${r.response.status}).`,reportable:r.response.status>=500,status:r.response.status})}let i=c(Ve(r.value.widget));return e?T(i,e,r.value.quote,t):Z(i)}async function D(e,t){let n=await E(),r={includeServiceFee:n.widget.fields.serviceFee},i=w(n,e,t.operation);return c({catalog:n,checkout:await A(i,r,n.payment,t)})}async function O(e){let t={code:`widget_load_failed`,message:`Lockerverse returned an invalid widget catalog.`,operation:`load_widget`};try{return e&&`${v}?selection=${encodeURIComponent(JSON.stringify(e))}`.length>4e3?await D(e,t):e?await E(e):await E()}catch(e){b(e,t)}}function k(e){return e===void 0?O():O(S(e))}async function A(e,t,n,r){let i=await g(`${_}/quote`,{body:JSON.stringify({...t,items:e}),headers:{"Content-Type":`application/json`},method:`POST`},H,{...r,message:`Unable to calculate the Lockerverse checkout total because the request failed.`,report:!1},{...r,report:!1});if(!i.ok){let e=await $(i.response);throw e===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`?new f({...r,message:`This option is sold out.`,reportable:!1,serverCode:e,status:i.response.status}):new f({...r,message:`Unable to calculate the Lockerverse checkout total (${i.response.status}).`,reportable:i.response.status>=500,status:i.response.status})}return C(i.value,e,t,n)}async function j(e){let{catalog:t,items:n,pricing:r}=M(e),i={code:`total_calculation_failed`,message:`Lockerverse returned an invalid checkout total.`,operation:`calculate_total`};try{return await A(n,r,t.payment,i)}catch(e){b(e,i)}}function M(e){try{let t=je(e),n=Ge(t),r=x(t.pricing);return{catalog:n.catalog,items:n.items,pricing:r.includeServiceFee===void 0?{...r,includeServiceFee:n.catalog.widget.fields.serviceFee}:r}}catch(e){if(e instanceof f)throw e;y(e instanceof TypeError?e.message:`Checkout selection is invalid.`,`calculate_total`)}}function N(e){try{let t=Pe(e),{items:n,pricing:r,quote:i}=t.checkout,a=x(r),o=c(i),{submission:s}=t;o.totalCents>0&&!s.confirmationToken&&y(`Stripe confirmation is required for a paid checkout.`,`submit_payment`,`payment_submit_failed`);let l=s.email.trim().toLowerCase();return(!l||l!==a.email)&&y(`Payment email must match the current checkout quote.`,`submit_payment`),{items:n,pricing:a,quote:o,submission:{...s,email:l}}}catch(e){if(e instanceof f)throw e;y(`Lockerverse payment submission is invalid.`,`submit_payment`,`payment_submit_failed`)}}return{calculateTotal:j,async getPaymentStatus(e){let t;try{t=Ne(e).trim()}catch{y(`Provide a payment reference to recover its status.`,`get_payment_status`)}let n={code:`payment_status_failed`,message:`Lockerverse returned an invalid payment status.`,operation:`get_payment_status`};try{let e=await g(`${_}/${encodeURIComponent(t)}/status`,void 0,U,{...n,message:`Unable to recover the Lockerverse payment status because the request failed.`,report:!1},{...n,report:!1});if(!e.ok)throw new f({...n,message:`Unable to recover the Lockerverse payment status (${e.response.status}).`,reportable:e.response.status>=500,status:e.response.status});if(e.value.paymentReference!==t)throw new f({...n,reportable:!0});return Ue(e.value)}catch(e){b(e,n)}},load:k,async submitPayment(e){let{items:t,pricing:n,quote:r,submission:i}=N(e),a={code:`payment_submit_failed`,message:`Lockerverse returned an invalid payment confirmation.`,operation:`submit_payment`};try{let e=await g(`${_}/confirm`,{body:JSON.stringify({confirmationToken:i.confirmationToken,customFieldAnswers:i.customFieldAnswers,email:i.email,expectedAmountCents:r.amountCents,expectedAppliedDiscount:r.appliedDiscount,expectedConnectedAccountId:r.payment.connectedAccountId,expectedDiscountableSubtotalCents:r.discountableSubtotalCents,expectedDiscountCents:r.discountCents,expectedServiceFeeCents:r.serviceFeeCents,expectedSubtotalCents:r.subtotalCents,expectedTipCents:r.tipCents,expectedTotalCents:r.totalCents,...n,items:t,memberId:i.memberId,merchSize:i.merchSize,metadata:i.metadata,paymentReference:r.paymentReference,phone:i.phone,quoteContractVersion:1,shipping:i.shipping}),headers:{"Content-Type":`application/json`},method:`POST`},U,{...a,message:`Unable to submit the Lockerverse payment because the request failed.`,report:!1},{...a,report:!1});if(!e.ok){let t=await $(e.response);throw t?new f({...a,message:t===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`?`This option is sold out.`:`Unable to submit the Lockerverse payment (${e.response.status}).`,reportable:!1,serverCode:t,status:e.response.status}):new f({...a,message:`Unable to submit the Lockerverse payment (${e.response.status}).`,reportable:e.response.status>=500,status:e.response.status})}if(e.value.paymentReference!==r.paymentReference)throw new f({...a,reportable:!0});return Ue(e.value)}catch(e){b(e,a,!0)}}}}function Je(e,t){let{selection:n,...r}=t,i;try{i=G(r)}catch(e){throw TypeError(`Checkout pricing is invalid.`,{cause:e})}let a=i.includeServiceFee??e.widget.fields.serviceFee,{tipCents:o=0}=i,{items:s,lineItems:l,paymentOption:u}=X(e,n),d=l.reduce((e,t)=>e+t.subtotalCents,0);if(!Number.isSafeInteger(d)||d<=0||d>2147483647)throw TypeError(`Checkout total is invalid.`);let f=l.reduce((e,t)=>e+(t.acceptsDiscounts?t.subtotalCents:0),0),p=a?Math.round(d*e.pricingPolicy.serviceFeeRateBasisPoints/1e4):0,m=d+p,h=m+o;if(!Number.isSafeInteger(h)||h>2147483647)throw TypeError(`Checkout total is invalid.`);return c({amountCents:m,appliedDiscount:null,authoritative:!1,discountableSubtotalCents:f,discountCents:0,items:s,lineItems:l,paymentOption:u,serviceFeeCents:p,subtotalCents:d,tipCents:o,totalCents:h})}export{p as LOCKERVERSE_SDK_VERSION,f as LockerverseSdkError,qe as createLockerverseCheckoutClient,Je as estimateLockerverseCheckout,Y as getLockerverseMinimumCustomAmountCents};
1
+ import{a as e,c as t,d as n,i as r,l as i,m as a,n as o,o as s,r as c,s as l,t as u,u as d}from"./transport.js";import{n as f,t as p}from"./types.js";import{array as m,boolean as h,check as g,finite as _,literal as v,looseObject as y,maxValue as ee,minLength as b,minValue as x,nullable as S,number as C,object as w,optional as T,parser as E,picklist as D,pipe as O,record as k,regex as A,safeParse as j,strictObject as M,string as N,transform as te,union as P,unknown as F,variant as ne}from"valibot";function re(e){let t=a(e,`widgetSlug`);return{...t,widgetSlug:t.resourceSlug,widgetSlugValue:t.resourceSlugValue}}const I=D([`one-time`,`monthly`,`annually`]),L=D([`none`,`event_admission`]),R=S(t(0)),ie=D([`available`,`sold_out`]),ae=T(w({listings:m(w({listingId:s,maxPurchasableQuantity:R,remainingQuantity:R,status:ie})),sharedLimits:m(w({id:s,listingIds:m(s),remainingQuantity:t(0),status:ie}))}),{listings:[],sharedLimits:[]}),oe=O(N(),A(/^pk_(?:test|live)_\S+$/,`Invalid publishable key.`)),z={description:l,fulfillmentType:L,id:s,inventoryQuantity:R,maxQuantity:R,minimumAmountCents:R,minQuantity:R,name:s,paymentOption:I},B=w({description:S(N()),endAt:s,id:s,location:S(N()),name:s,startAt:s,status:D([`draft`,`active`,`finished`,`cancelled`])}),se=O(ne(`pricingMode`,[w({...z,amountCents:t(0),pricingMode:v(`fixed`)}),w({...z,amountCents:R,pricingMode:v(`custom`)})]),g(({maxQuantity:e,minQuantity:t})=>e===null||t===null||t<=e)),ce=w({acceptsDiscounts:T(h(),!1),id:s,product:se,productId:s,slug:s}),V=T(w({memberId:T(h(),!1),merchSize:T(h(),!1),phone:T(h(),!1),promoCode:T(h(),!1),serviceFee:T(h(),!1),shipping:T(h(),!1),tipping:T(h(),!1)}),{}),le=O(w({availability:ae,community:T(w({color:N(),memberIdLabel:T(S(N())),name:s,thumbnail:S(N())})),config:T(w({customFields:e,fields:V})),description:l,event:S(B),id:T(N(),``),name:T(N(),`Lockerverse widget`),payment:w({connectedAccountId:T(S(s),null),currency:v(`usd`),publishableKey:oe}),pricingPolicy:T(w({currency:T(v(`usd`),`usd`),serviceFeeRateBasisPoints:T(t(0),0)})),products:T(m(ce),[]),showCommunityBranding:T(h(),!0),title:l}),te(e=>({...e,config:{customFields:e.config?.customFields??[],fields:{memberId:e.config?.fields?.memberId??!1,merchSize:e.config?.fields?.merchSize??!1,phone:e.config?.fields?.phone??!1,promoCode:e.config?.fields?.promoCode??!1,serviceFee:e.config?.fields?.serviceFee??!1,shipping:e.config?.fields?.shipping??!1,tipping:e.config?.fields?.tipping??!1}},pricingPolicy:e.pricingPolicy??{currency:`usd`,serviceFeeRateBasisPoints:0}}))),ue=w({acceptsDiscounts:h(),amountCents:S(t(0)),description:S(N()),fulfillmentType:L,id:s,inventoryQuantity:R,listingId:s,maximumQuantity:R,minimumAmountCents:R,minimumQuantity:R,name:s,paymentOption:I,pricingMode:D([`fixed`,`custom`]),slug:s}),de=w({availability:ae,community:S(w({accentColor:N(),imageUrl:S(N()),memberIdLabel:T(S(N())),name:s})),event:S(B),payment:w({connectedAccountId:T(S(s),null),currency:v(`usd`),publishableKey:oe}),pricingPolicy:w({currency:v(`usd`),serviceFeeRateBasisPoints:t(0)}),products:m(ue),widget:w({customFields:e,description:S(N()),fields:V,id:N(),name:s,showCommunityBranding:h(),title:S(N())})}),fe=S(w({percentageOff:O(C(),_(),x(0),ee(100)),source:D([`email_list`,`promo_code`])})),pe=w({acceptsDiscounts:h(),eventId:S(s),fulfillmentType:L,listingId:s,listingSlug:s,paymentOption:I,pricingMode:D([`fixed`,`custom`]),productId:s,productName:s,quantity:t(1),subtotalCents:t(0),unitAmountCents:t(0)}),me=O(d,w({amountCents:t(0),appliedDiscount:fe,connectedAccountId:S(s),discountableSubtotalCents:t(0),discountCents:t(0),lineItems:m(pe),paymentOption:I,serviceFeeCents:t(0),subtotalCents:t(0),tipCents:t(0),totalCents:t(0)}),g(({lineItems:e,paymentOption:t})=>e.length===0||e.some(e=>e.paymentOption!==t)?!1:t===`one-time`||e.length===1&&e[0]?.pricingMode===`fixed`&&e[0].quantity===1,`Invalid checkout cadence composition.`)),he=O(i,g(e=>e.checkoutId.trim()&&e.paymentReference.trim()?e.checkoutStatus===`action_required`?e.requiresAction&&e.paymentRequired&&!!e.clientSecret?.trim():!e.requiresAction&&e.clientSecret===null:!1,`Invalid payment result state.`)),H=E(me),ge=E(de),U=E(he),_e=E(n),ve=E(le);function ye(e){return _e(e),ve(e)}function be(e){let t=j(y({quote:T(F())}),e),n=ye(e),r=t.success?t.output.quote:void 0;return r===void 0?{widget:n}:{quote:H(r),widget:n}}const xe={email:T(N()),includeServiceFee:T(h()),promoCode:T(N()),tipCents:T(t(0))},W=M(xe),G=E(T(W,{})),Se=M({confirmationToken:T(s),customFieldAnswers:T(m(r)),email:N(),memberId:T(N()),merchSize:T(D([`XS`,`S`,`M`,`L`,`XL`,`XXL`,`XXXL`])),metadata:T(k(N(),N())),phone:T(N()),shipping:T(M({address:M({city:N(),country:N(),line1:N(),line2:T(N()),postal_code:N(),state:N()}),name:N()}))}),Ce=P([M({amountCents:t(1),productId:s}),M({productId:s,quantity:t(1)}),M({productId:s})]),we=P([M({amountCents:t(1),productSlug:s}),M({productSlug:s,quantity:t(1)}),M({productSlug:s})]),K=O(m(Ce),b(1)),q=O(m(we),b(1)),Te=w({selection:q}),Ee=y({catalog:T(F()),email:T(F()),includeServiceFee:T(F()),items:T(K),promoCode:T(F()),selection:T(q),tipCents:T(F())}),J=O(y({authoritative:v(!0),items:K,payment:w({connectedAccountId:S(s),currency:v(`usd`),publishableKey:O(N(),b(1))}),paymentReference:O(N(),b(1)),pricing:W}),te(e=>{let{items:t,payment:n,paymentReference:r,pricing:i,...a}=e,o=H({...a,connectedAccountId:n.connectedAccountId}),{connectedAccountId:s,...c}=o;return{items:t,pricing:i,quote:{...c,authoritative:!0,payment:{connectedAccountId:s,currency:`usd`,publishableKey:n.publishableKey},paymentOption:o.paymentOption,paymentReference:r}}})),De=y({checkout:J,submission:Se}),Oe=s,ke=E(y({})),Ae=E(Ee);function je(e){let{catalog:t,items:n,selection:r,...i}=Ae(e),a;try{a=ke(t)}catch(e){throw TypeError(`A catalog is required to calculate a checkout.`,{cause:e})}try{return{catalog:a,items:n,pricing:G(i),selection:r}}catch(e){throw TypeError(`Checkout pricing input is invalid.`,{cause:e})}}const Me=E(Te),Ne=E(Oe);E(J);const Pe=E(De),Fe=E(q);function Y(e){return Math.max(100,e.minimumAmountCents??0)}function Ie(e,t){let n=new Map(e.products.map(({id:e,listingId:t})=>[e,t])),r=t.reduce((e,t)=>{let r=n.get(t.productId);return r&&e.set(r,(e.get(r)??0)+(`quantity`in t?t.quantity??1:1)),e},new Map),i=e.availability.listings.some(({listingId:e,maxPurchasableQuantity:t,status:n})=>r.has(e)&&(n===`sold_out`||t!==null&&(r.get(e)??0)>t)),a=e.availability.sharedLimits.some(({listingIds:e,remainingQuantity:t,status:n})=>{let i=e.reduce((e,t)=>e+(r.get(t)??0),0);return i>0&&(n===`sold_out`||i>t)});if(i||a)throw new f({code:`total_calculation_failed`,message:`This option is sold out.`,operation:`calculate_total`,reportable:!1,serverCode:`PAYMENT_WIDGET_SALES_LIMIT_REACHED`})}function Le(e,t){if(e.pricingMode!==`custom`||e.paymentOption!==`one-time`||t<Y(e))throw TypeError(`Selected Product amount is invalid.`);return{checkoutItem:{amountCents:t,productId:e.id},quantity:1,unitAmountCents:t}}function Re(e,t){if(e.pricingMode!==`fixed`||e.amountCents===null)throw TypeError(`Selected Product quantity is invalid.`);if(e.paymentOption!==`one-time`&&t!==1)throw TypeError(`Selected recurring Product is invalid.`);if(e.minimumQuantity!==null&&t<e.minimumQuantity||e.maximumQuantity!==null&&t>e.maximumQuantity||e.inventoryQuantity!==null&&t>e.inventoryQuantity)throw TypeError(`Selected Product quantity is invalid.`);return{checkoutItem:e.paymentOption===`one-time`?{productId:e.id,quantity:t}:{productId:e.id},quantity:t,unitAmountCents:e.amountCents}}function ze(e,t,n){let r=`quantity`in n?n.quantity:1,{checkoutItem:i,quantity:a,unitAmountCents:o}=`amountCents`in n?Le(t,n.amountCents):Re(t,r);return{checkoutItem:i,lineItem:{acceptsDiscounts:t.acceptsDiscounts,eventId:t.fulfillmentType===`event_admission`&&e.event?e.event.id:null,fulfillmentType:t.fulfillmentType,listingId:t.listingId,listingSlug:t.slug,paymentOption:t.paymentOption,pricingMode:t.pricingMode,productId:t.id,productName:t.name,quantity:a,subtotalCents:o*a,unitAmountCents:o}}}function X(e,t){let n=Fe(t),r=new Set,i=n.map(t=>{let n=e.products.find(e=>e.slug===t.productSlug);if(!n)throw TypeError(`Selected Product is unavailable.`);if(r.has(n.id))throw TypeError(`Each Product can appear only once per checkout.`);return r.add(n.id),ze(e,n,t)}),a=i[0]?.lineItem.paymentOption;if(!a)throw TypeError(`Select at least one Product.`);if(i.length>1&&(a!==`one-time`||i.some(({lineItem:e})=>e.paymentOption!==a)))throw TypeError(`Recurring Products must be purchased separately.`);let o=i.map(({checkoutItem:e})=>e);return Ie(e,o),{items:o,lineItems:i.map(({lineItem:e})=>e),paymentOption:a}}function Be(e){let{product:t}=e;return{acceptsDiscounts:e.acceptsDiscounts??!1,amountCents:t.amountCents,description:t.description??null,fulfillmentType:t.fulfillmentType,id:t.id,inventoryQuantity:t.inventoryQuantity,listingId:e.id,maximumQuantity:t.maxQuantity,minimumAmountCents:t.minimumAmountCents,minimumQuantity:t.minQuantity,name:t.name,paymentOption:t.paymentOption,pricingMode:t.pricingMode,slug:e.slug}}function Ve(e){if(!e)return null;let t={accentColor:e.color,imageUrl:e.thumbnail||null,name:e.name};return e.memberIdLabel!==void 0&&(t.memberIdLabel=e.memberIdLabel),t}function He(e){let t=e.config?.fields??{};return{availability:e.availability,community:Ve(e.community),event:e.event?{description:e.event.description,endAt:e.event.endAt,id:e.event.id,location:e.event.location,name:e.event.name,startAt:e.event.startAt,status:e.event.status}:null,payment:{connectedAccountId:e.payment.connectedAccountId,currency:e.payment.currency,publishableKey:e.payment.publishableKey},pricingPolicy:{currency:`usd`,serviceFeeRateBasisPoints:e.pricingPolicy?.serviceFeeRateBasisPoints??0},products:(e.products??[]).map(Be),widget:{customFields:e.config?.customFields??[],description:e.description??null,fields:{memberId:t.memberId??!1,merchSize:t.merchSize??!1,phone:t.phone??!1,promoCode:t.promoCode??!1,serviceFee:t.serviceFee??!1,shipping:t.shipping??!1,tipping:t.tipping??!1},id:e.id??``,name:e.name??`Lockerverse widget`,showCommunityBranding:e.showCommunityBranding??!0,title:e.title??null}}}function Z(e){return Q(e)}function Ue(e){return Q(e)}function We(e){return Q(e)}function Q(e){return c(structuredClone(e))}const Ge=w({code:D([`PAYMENT_WIDGET_PHONE_INVALID`,`PAYMENT_WIDGET_PHONE_REQUIRED`,`PAYMENT_WIDGET_SALES_LIMIT_REACHED`])});async function $(e){if(e.status===400||e.status===409)try{let t=j(Ge,await e.json());return t.success?t.output.code:void 0}catch{}}function Ke({catalog:e,items:t,selection:n}){if(t!==void 0&&n!==void 0)throw TypeError(`Use items or selection, not both.`);let r=Z(ge(e)),i=n===void 0?qe(t):X(r,n).items;return Ie(r,i),{catalog:r,items:i}}function qe(e){if(e===void 0)throw TypeError(`Checkout selection is invalid.`);return e}function Je(e){let{apiBaseUrl:t,communitySlug:n,communitySlugValue:r,environment:i,fetchImplementation:a,onError:s,requestTimeoutMs:l,sentryDsn:d,widgetSlug:p,widgetSlugValue:m}=re(e),h=o({communitySlug:r,environment:i,getContext:()=>({widgetSlug:m}),onError:s,resourceContextName:`lockerverse_widget`,sentryDsn:d}),{requestJson:g}=u(a,h,l),_=`${t}/v2/community/${n}/payment-widgets/${p}/checkout`,v=`${t}/v2/community/${n}/payment-widgets/${p}`;function y(e,t,n=`invalid_selection`){throw h(new f({code:n,message:e,operation:t,reportable:!1}))}function ee(e,t){return e instanceof f?e:new f({...t,reportable:!0})}function b(e,t,n=!1){let r=ee(e,t);if(!(n&&(r.status===void 0||r.status>=500)))throw h(r);let i=r.status===void 0?new f({code:r.code,message:r.message,operation:r.operation,recoveryRecommended:!0,reportable:r.reportable}):new f({code:r.code,message:r.message,operation:r.operation,recoveryRecommended:!0,reportable:r.reportable,status:r.status});throw h(i)}function x(e){let t=e.email?.trim().toLowerCase(),n=e.promoCode?.trim(),r={};return t&&(r.email=t),e.includeServiceFee!==void 0&&(r.includeServiceFee=e.includeServiceFee),n&&(r.promoCode=n),e.tipCents!==void 0&&(r.tipCents=e.tipCents),r}function S(e){try{return Me(e).selection}catch{y(`Checkout selection is invalid.`,`load_widget`)}}function C(e,t,n,r){let{connectedAccountId:i,...a}=e;return Ue(c({...a,authoritative:!0,items:t,payment:{connectedAccountId:i,currency:`usd`,publishableKey:r.publishableKey},paymentOption:e.paymentOption,paymentReference:globalThis.crypto.randomUUID(),pricing:n}))}function w(e,t,n){try{return X(e,t).items}catch(e){throw e instanceof TypeError&&y(e.message,n),e}}function T(e,t,n,r){if(!n)throw new f({...r,message:`Lockerverse did not return the requested initial quote.`,reportable:!0});let i=w(e,t,r.operation);return c({catalog:Z(e),checkout:C(n,i,{includeServiceFee:e.widget.fields.serviceFee},e.payment)})}async function E(e){let t={code:`widget_load_failed`,message:`Lockerverse returned an invalid widget catalog.`,operation:`load_widget`},n=e?`${v}?selection=${encodeURIComponent(JSON.stringify(e))}`:v,r=await g(n,e?{cache:`no-store`}:void 0,be,{...t,message:`Unable to load Lockerverse widget because the request failed.`,report:!1},{...t,report:!1});if(!r.ok){let e=await $(r.response);throw e===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`?new f({...t,message:`This option is sold out.`,reportable:!1,serverCode:e,status:r.response.status}):new f({...t,message:`Unable to load Lockerverse widget (${r.response.status}).`,reportable:r.response.status>=500,status:r.response.status})}let i=c(He(r.value.widget));return e?T(i,e,r.value.quote,t):Z(i)}async function D(e,t){let n=await E(),r={includeServiceFee:n.widget.fields.serviceFee},i=w(n,e,t.operation);return c({catalog:n,checkout:await A(i,r,n.payment,t)})}async function O(e){let t={code:`widget_load_failed`,message:`Lockerverse returned an invalid widget catalog.`,operation:`load_widget`};try{return e&&`${v}?selection=${encodeURIComponent(JSON.stringify(e))}`.length>4e3?await D(e,t):e?await E(e):await E()}catch(e){b(e,t)}}function k(e){return e===void 0?O():O(S(e))}async function A(e,t,n,r){let i=await g(`${_}/quote`,{body:JSON.stringify({...t,items:e}),headers:{"Content-Type":`application/json`},method:`POST`},H,{...r,message:`Unable to calculate the Lockerverse checkout total because the request failed.`,report:!1},{...r,report:!1});if(!i.ok){let e=await $(i.response);throw e===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`?new f({...r,message:`This option is sold out.`,reportable:!1,serverCode:e,status:i.response.status}):new f({...r,message:`Unable to calculate the Lockerverse checkout total (${i.response.status}).`,reportable:i.response.status>=500,status:i.response.status})}return C(i.value,e,t,n)}async function j(e){let{catalog:t,items:n,pricing:r}=M(e),i={code:`total_calculation_failed`,message:`Lockerverse returned an invalid checkout total.`,operation:`calculate_total`};try{return await A(n,r,t.payment,i)}catch(e){b(e,i)}}function M(e){try{let t=je(e),n=Ke(t),r=x(t.pricing);return{catalog:n.catalog,items:n.items,pricing:r.includeServiceFee===void 0?{...r,includeServiceFee:n.catalog.widget.fields.serviceFee}:r}}catch(e){if(e instanceof f)throw e;y(e instanceof TypeError?e.message:`Checkout selection is invalid.`,`calculate_total`)}}function N(e){try{let t=Pe(e),{items:n,pricing:r,quote:i}=t.checkout,a=x(r),o=c(i),{submission:s}=t;o.totalCents>0&&!s.confirmationToken&&y(`Stripe confirmation is required for a paid checkout.`,`submit_payment`,`payment_submit_failed`);let l=s.email.trim().toLowerCase();return(!l||l!==a.email)&&y(`Payment email must match the current checkout quote.`,`submit_payment`),{items:n,pricing:a,quote:o,submission:{...s,email:l}}}catch(e){if(e instanceof f)throw e;y(`Lockerverse payment submission is invalid.`,`submit_payment`,`payment_submit_failed`)}}return{calculateTotal:j,async getPaymentStatus(e){let t;try{t=Ne(e).trim()}catch{y(`Provide a payment reference to recover its status.`,`get_payment_status`)}let n={code:`payment_status_failed`,message:`Lockerverse returned an invalid payment status.`,operation:`get_payment_status`};try{let e=await g(`${_}/${encodeURIComponent(t)}/status`,void 0,U,{...n,message:`Unable to recover the Lockerverse payment status because the request failed.`,report:!1},{...n,report:!1});if(!e.ok)throw new f({...n,message:`Unable to recover the Lockerverse payment status (${e.response.status}).`,reportable:e.response.status>=500,status:e.response.status});if(e.value.paymentReference!==t)throw new f({...n,reportable:!0});return We(e.value)}catch(e){b(e,n)}},load:k,async submitPayment(e){let{items:t,pricing:n,quote:r,submission:i}=N(e),a={code:`payment_submit_failed`,message:`Lockerverse returned an invalid payment confirmation.`,operation:`submit_payment`};try{let e=await g(`${_}/confirm`,{body:JSON.stringify({confirmationToken:i.confirmationToken,customFieldAnswers:i.customFieldAnswers,email:i.email,expectedAmountCents:r.amountCents,expectedAppliedDiscount:r.appliedDiscount,expectedConnectedAccountId:r.payment.connectedAccountId,expectedDiscountableSubtotalCents:r.discountableSubtotalCents,expectedDiscountCents:r.discountCents,expectedServiceFeeCents:r.serviceFeeCents,expectedSubtotalCents:r.subtotalCents,expectedTipCents:r.tipCents,expectedTotalCents:r.totalCents,...n,items:t,memberId:i.memberId,merchSize:i.merchSize,metadata:i.metadata,paymentReference:r.paymentReference,phone:i.phone,quoteContractVersion:1,shipping:i.shipping}),headers:{"Content-Type":`application/json`},method:`POST`},U,{...a,message:`Unable to submit the Lockerverse payment because the request failed.`,report:!1},{...a,report:!1});if(!e.ok){let t=await $(e.response);throw t?new f({...a,message:t===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`?`This option is sold out.`:`Unable to submit the Lockerverse payment (${e.response.status}).`,reportable:!1,serverCode:t,status:e.response.status}):new f({...a,message:`Unable to submit the Lockerverse payment (${e.response.status}).`,reportable:e.response.status>=500,status:e.response.status})}if(e.value.paymentReference!==r.paymentReference)throw new f({...a,reportable:!0});return We(e.value)}catch(e){b(e,a,!0)}}}}function Ye(e,t){let{selection:n,...r}=t,i;try{i=G(r)}catch(e){throw TypeError(`Checkout pricing is invalid.`,{cause:e})}let a=i.includeServiceFee??e.widget.fields.serviceFee,{tipCents:o=0}=i,{items:s,lineItems:l,paymentOption:u}=X(e,n),d=l.reduce((e,t)=>e+t.subtotalCents,0);if(!Number.isSafeInteger(d)||d<=0||d>2147483647)throw TypeError(`Checkout total is invalid.`);let f=l.reduce((e,t)=>e+(t.acceptsDiscounts?t.subtotalCents:0),0),p=a?Math.round(d*e.pricingPolicy.serviceFeeRateBasisPoints/1e4):0,m=d+p,h=m+o;if(!Number.isSafeInteger(h)||h>2147483647)throw TypeError(`Checkout total is invalid.`);return c({amountCents:m,appliedDiscount:null,authoritative:!1,discountableSubtotalCents:f,discountCents:0,items:s,lineItems:l,paymentOption:u,serviceFeeCents:p,subtotalCents:d,tipCents:o,totalCents:h})}export{p as LOCKERVERSE_SDK_VERSION,f as LockerverseSdkError,Je as createLockerverseCheckoutClient,Ye as estimateLockerverseCheckout,Y as getLockerverseMinimumCustomAmountCents};
2
2
  //# sourceMappingURL=checkout.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkout.js","names":[],"sources":["../src/checkout-environment.ts","../src/checkout-schemas.ts","../src/checkout-input-schemas.ts","../src/custom-amount.ts","../src/checkout-selection.ts","../src/snapshots.ts","../src/checkout-client.ts","../src/checkout-estimate.ts"],"sourcesContent":["import { resolveResourceEnvironment } from \"./environment.ts\";\nimport type { CreateLockerverseWidgetOptions } from \"./types.ts\";\n\nexport function resolveWidgetEnvironment(\n options: CreateLockerverseWidgetOptions\n) {\n const runtime = resolveResourceEnvironment(options, \"widgetSlug\");\n return {\n ...runtime,\n widgetSlug: runtime.resourceSlug,\n widgetSlugValue: runtime.resourceSlugValue,\n };\n}\n","import {\n array,\n boolean,\n check,\n finite,\n type InferOutput,\n literal,\n looseObject,\n maxValue,\n minValue,\n nullable,\n number,\n object,\n optional,\n parser,\n picklist,\n pipe,\n regex,\n safeParse,\n string,\n transform,\n unknown,\n variant,\n} from \"valibot\";\n\nimport {\n vPaymentWidgetPaymentResultResponseDto,\n vPaymentWidgetQuoteResponseDto,\n vPublicPaymentWidgetResponseDto,\n} from \"./generated/public-api/valibot.gen.ts\";\nimport {\n customFieldsSchema,\n nonEmptyStringSchema,\n optionalNullableStringSchema,\n safeIntegerSchema,\n} from \"./schema-helpers.ts\";\n\nconst paymentOptionSchema = picklist([\"one-time\", \"monthly\", \"annually\"]);\nconst fulfillmentTypeSchema = picklist([\"none\", \"event_admission\"]);\nconst nullableNonNegativeIntegerSchema = nullable(safeIntegerSchema(0));\nconst availabilityStatusSchema = picklist([\"available\", \"sold_out\"]);\nconst availabilitySchema = optional(\n object({\n listings: array(\n object({\n listingId: nonEmptyStringSchema,\n maxPurchasableQuantity: nullableNonNegativeIntegerSchema,\n remainingQuantity: nullableNonNegativeIntegerSchema,\n status: availabilityStatusSchema,\n })\n ),\n sharedLimits: array(\n object({\n id: nonEmptyStringSchema,\n listingIds: array(nonEmptyStringSchema),\n remainingQuantity: safeIntegerSchema(0),\n status: availabilityStatusSchema,\n })\n ),\n }),\n { listings: [], sharedLimits: [] }\n);\nconst publishableKeySchema = pipe(\n string(),\n regex(/^pk_(?:test|live)_\\S+$/, \"Invalid publishable key.\")\n);\n\nconst productBaseEntries = {\n description: optionalNullableStringSchema,\n fulfillmentType: fulfillmentTypeSchema,\n id: nonEmptyStringSchema,\n inventoryQuantity: nullableNonNegativeIntegerSchema,\n maxQuantity: nullableNonNegativeIntegerSchema,\n minimumAmountCents: nullableNonNegativeIntegerSchema,\n minQuantity: nullableNonNegativeIntegerSchema,\n name: nonEmptyStringSchema,\n paymentOption: paymentOptionSchema,\n};\n\nconst eventSchema = object({\n description: nullable(string()),\n endAt: nonEmptyStringSchema,\n id: nonEmptyStringSchema,\n location: nullable(string()),\n name: nonEmptyStringSchema,\n startAt: nonEmptyStringSchema,\n status: picklist([\"draft\", \"active\", \"finished\", \"cancelled\"]),\n});\n\nconst publicProductSchema = pipe(\n variant(\"pricingMode\", [\n object({\n ...productBaseEntries,\n amountCents: safeIntegerSchema(0),\n pricingMode: literal(\"fixed\"),\n }),\n object({\n ...productBaseEntries,\n amountCents: nullableNonNegativeIntegerSchema,\n pricingMode: literal(\"custom\"),\n }),\n ]),\n check(\n ({ maxQuantity, minQuantity }) =>\n maxQuantity === null || minQuantity === null || minQuantity <= maxQuantity\n )\n);\n\nconst productListingSchema = object({\n acceptsDiscounts: optional(boolean(), false),\n id: nonEmptyStringSchema,\n product: publicProductSchema,\n productId: nonEmptyStringSchema,\n slug: nonEmptyStringSchema,\n});\n\nconst widgetFieldsSchema = optional(\n object({\n memberId: optional(boolean(), false),\n merchSize: optional(boolean(), false),\n phone: optional(boolean(), false),\n promoCode: optional(boolean(), false),\n serviceFee: optional(boolean(), false),\n shipping: optional(boolean(), false),\n tipping: optional(boolean(), false),\n }),\n {}\n);\n\nexport const publicWidgetSchema = pipe(\n object({\n availability: availabilitySchema,\n community: optional(\n object({\n color: string(),\n name: nonEmptyStringSchema,\n thumbnail: nullable(string()),\n })\n ),\n config: optional(\n object({\n customFields: customFieldsSchema,\n fields: widgetFieldsSchema,\n })\n ),\n description: optionalNullableStringSchema,\n event: nullable(eventSchema),\n id: optional(string(), \"\"),\n name: optional(string(), \"Lockerverse widget\"),\n payment: object({\n connectedAccountId: optional(nullable(nonEmptyStringSchema), null),\n currency: literal(\"usd\"),\n publishableKey: publishableKeySchema,\n }),\n pricingPolicy: optional(\n object({\n currency: optional(literal(\"usd\"), \"usd\"),\n serviceFeeRateBasisPoints: optional(safeIntegerSchema(0), 0),\n })\n ),\n products: optional(array(productListingSchema), []),\n showCommunityBranding: optional(boolean(), true),\n title: optionalNullableStringSchema,\n }),\n transform((widget) => ({\n ...widget,\n config: {\n customFields: widget.config?.customFields ?? [],\n fields: {\n memberId: widget.config?.fields?.memberId ?? false,\n merchSize: widget.config?.fields?.merchSize ?? false,\n phone: widget.config?.fields?.phone ?? false,\n promoCode: widget.config?.fields?.promoCode ?? false,\n serviceFee: widget.config?.fields?.serviceFee ?? false,\n shipping: widget.config?.fields?.shipping ?? false,\n tipping: widget.config?.fields?.tipping ?? false,\n },\n },\n pricingPolicy: widget.pricingPolicy ?? {\n currency: \"usd\" as const,\n serviceFeeRateBasisPoints: 0,\n },\n }))\n);\n\nconst catalogProductSchema = object({\n acceptsDiscounts: boolean(),\n amountCents: nullable(safeIntegerSchema(0)),\n description: nullable(string()),\n fulfillmentType: fulfillmentTypeSchema,\n id: nonEmptyStringSchema,\n inventoryQuantity: nullableNonNegativeIntegerSchema,\n listingId: nonEmptyStringSchema,\n maximumQuantity: nullableNonNegativeIntegerSchema,\n minimumAmountCents: nullableNonNegativeIntegerSchema,\n minimumQuantity: nullableNonNegativeIntegerSchema,\n name: nonEmptyStringSchema,\n paymentOption: paymentOptionSchema,\n pricingMode: picklist([\"fixed\", \"custom\"]),\n slug: nonEmptyStringSchema,\n});\n\nconst catalogSchema = object({\n availability: availabilitySchema,\n community: nullable(\n object({\n accentColor: string(),\n imageUrl: nullable(string()),\n name: nonEmptyStringSchema,\n })\n ),\n event: nullable(eventSchema),\n payment: object({\n connectedAccountId: optional(nullable(nonEmptyStringSchema), null),\n currency: literal(\"usd\"),\n publishableKey: publishableKeySchema,\n }),\n pricingPolicy: object({\n currency: literal(\"usd\"),\n serviceFeeRateBasisPoints: safeIntegerSchema(0),\n }),\n products: array(catalogProductSchema),\n widget: object({\n customFields: customFieldsSchema,\n description: nullable(string()),\n fields: widgetFieldsSchema,\n id: string(),\n name: nonEmptyStringSchema,\n showCommunityBranding: boolean(),\n title: nullable(string()),\n }),\n});\n\nconst appliedDiscountSchema = nullable(\n object({\n percentageOff: pipe(number(), finite(), minValue(0), maxValue(100)),\n source: picklist([\"email_list\", \"promo_code\"]),\n })\n);\n\nconst checkoutLineItemSchema = object({\n acceptsDiscounts: boolean(),\n eventId: nullable(nonEmptyStringSchema),\n fulfillmentType: fulfillmentTypeSchema,\n listingId: nonEmptyStringSchema,\n listingSlug: nonEmptyStringSchema,\n paymentOption: paymentOptionSchema,\n pricingMode: picklist([\"fixed\", \"custom\"]),\n productId: nonEmptyStringSchema,\n productName: nonEmptyStringSchema,\n quantity: safeIntegerSchema(1),\n subtotalCents: safeIntegerSchema(0),\n unitAmountCents: safeIntegerSchema(0),\n});\n\nexport const checkoutQuoteSchema = pipe(\n vPaymentWidgetQuoteResponseDto,\n object({\n amountCents: safeIntegerSchema(0),\n appliedDiscount: appliedDiscountSchema,\n connectedAccountId: nullable(nonEmptyStringSchema),\n discountableSubtotalCents: safeIntegerSchema(0),\n discountCents: safeIntegerSchema(0),\n lineItems: array(checkoutLineItemSchema),\n paymentOption: paymentOptionSchema,\n serviceFeeCents: safeIntegerSchema(0),\n subtotalCents: safeIntegerSchema(0),\n tipCents: safeIntegerSchema(0),\n totalCents: safeIntegerSchema(0),\n }),\n check(({ lineItems, paymentOption }) => {\n if (\n lineItems.length === 0 ||\n lineItems.some((item) => item.paymentOption !== paymentOption)\n ) {\n return false;\n }\n return (\n paymentOption === \"one-time\" ||\n (lineItems.length === 1 &&\n lineItems[0]?.pricingMode === \"fixed\" &&\n lineItems[0].quantity === 1)\n );\n }, \"Invalid checkout cadence composition.\")\n);\n\nexport const paymentResultSchema = pipe(\n vPaymentWidgetPaymentResultResponseDto,\n check((payment) => {\n if (!(payment.checkoutId.trim() && payment.paymentReference.trim())) {\n return false;\n }\n if (payment.checkoutStatus === \"action_required\") {\n return (\n payment.requiresAction &&\n payment.paymentRequired &&\n Boolean(payment.clientSecret?.trim())\n );\n }\n return !payment.requiresAction && payment.clientSecret === null;\n }, \"Invalid payment result state.\")\n);\n\nexport type PublicCheckoutQuote = InferOutput<typeof checkoutQuoteSchema>;\nexport type PublicProductListing = InferOutput<typeof productListingSchema>;\nexport type PublicWidget = InferOutput<typeof publicWidgetSchema>;\n\nexport const parseCheckoutQuote = parser(checkoutQuoteSchema);\nexport const parseCatalog = parser(catalogSchema);\nexport const parsePaymentResult = parser(paymentResultSchema);\nconst parsePublicWidgetContract = parser(vPublicPaymentWidgetResponseDto);\nconst parseSdkPublicWidget = parser(publicWidgetSchema);\n\nexport function parsePublicWidget<Input>(input: Input) {\n parsePublicWidgetContract(input);\n return parseSdkPublicWidget(input);\n}\n\nexport function parsePublicWidgetLoad<Input>(input: Input) {\n const response = safeParse(\n looseObject({ quote: optional(unknown()) }),\n input\n );\n const widget = parsePublicWidget(input);\n const quote = response.success ? response.output.quote : undefined;\n return quote === undefined\n ? { widget }\n : { quote: parseCheckoutQuote(quote), widget };\n}\n","import {\n array,\n boolean,\n type InferOutput,\n literal,\n looseObject,\n minLength,\n nullable,\n object,\n optional,\n parser,\n picklist,\n pipe,\n record,\n strictObject,\n string,\n transform,\n union,\n unknown,\n} from \"valibot\";\n\nimport { parseCheckoutQuote } from \"./checkout-schemas.ts\";\nimport {\n customFieldAnswerSchema,\n nonEmptyStringSchema,\n safeIntegerSchema,\n} from \"./schema-helpers.ts\";\n\nconst checkoutPricingEntries = {\n email: optional(string()),\n includeServiceFee: optional(boolean()),\n promoCode: optional(string()),\n tipCents: optional(safeIntegerSchema(0)),\n};\n\nconst checkoutPricingInputSchema = strictObject(checkoutPricingEntries);\n\nexport const parseCheckoutPricingInput = parser(\n optional(checkoutPricingInputSchema, {})\n);\n\nconst paymentSubmissionSchema = strictObject({\n confirmationToken: optional(nonEmptyStringSchema),\n customFieldAnswers: optional(array(customFieldAnswerSchema)),\n email: string(),\n memberId: optional(string()),\n merchSize: optional(picklist([\"XS\", \"S\", \"M\", \"L\", \"XL\", \"XXL\", \"XXXL\"])),\n metadata: optional(record(string(), string())),\n phone: optional(string()),\n shipping: optional(\n strictObject({\n address: strictObject({\n city: string(),\n country: string(),\n line1: string(),\n line2: optional(string()),\n postal_code: string(),\n state: string(),\n }),\n name: string(),\n })\n ),\n});\n\nconst checkoutItemSchema = union([\n strictObject({\n amountCents: safeIntegerSchema(1),\n productId: nonEmptyStringSchema,\n }),\n strictObject({\n productId: nonEmptyStringSchema,\n quantity: safeIntegerSchema(1),\n }),\n strictObject({\n productId: nonEmptyStringSchema,\n }),\n]);\n\nconst checkoutSelectionItemSchema = union([\n strictObject({\n amountCents: safeIntegerSchema(1),\n productSlug: nonEmptyStringSchema,\n }),\n strictObject({\n productSlug: nonEmptyStringSchema,\n quantity: safeIntegerSchema(1),\n }),\n strictObject({\n productSlug: nonEmptyStringSchema,\n }),\n]);\n\nconst checkoutItemsSchema = pipe(array(checkoutItemSchema), minLength(1));\nconst checkoutSelectionItemsSchema = pipe(\n array(checkoutSelectionItemSchema),\n minLength(1)\n);\n\nconst loadCheckoutInputSchema = object({\n selection: checkoutSelectionItemsSchema,\n});\n\nconst calculateTotalInputSchema = looseObject({\n catalog: optional(unknown()),\n email: optional(unknown()),\n includeServiceFee: optional(unknown()),\n items: optional(checkoutItemsSchema),\n promoCode: optional(unknown()),\n selection: optional(checkoutSelectionItemsSchema),\n tipCents: optional(unknown()),\n});\n\nconst preparedCheckoutInputSchema = pipe(\n looseObject({\n authoritative: literal(true),\n items: checkoutItemsSchema,\n payment: object({\n connectedAccountId: nullable(nonEmptyStringSchema),\n currency: literal(\"usd\"),\n publishableKey: pipe(string(), minLength(1)),\n }),\n paymentReference: pipe(string(), minLength(1)),\n pricing: checkoutPricingInputSchema,\n }),\n transform((checkout) => {\n const { items, payment, paymentReference, pricing, ...quoteInput } =\n checkout;\n const parsedQuote = parseCheckoutQuote({\n ...quoteInput,\n connectedAccountId: payment.connectedAccountId,\n });\n const { connectedAccountId, ...quote } = parsedQuote;\n return {\n items,\n pricing,\n quote: {\n ...quote,\n authoritative: true as const,\n payment: {\n connectedAccountId,\n currency: \"usd\" as const,\n publishableKey: payment.publishableKey,\n },\n paymentOption: parsedQuote.paymentOption,\n paymentReference,\n },\n };\n })\n);\n\nconst submitPaymentInputSchema = looseObject({\n checkout: preparedCheckoutInputSchema,\n submission: paymentSubmissionSchema,\n});\n\nconst paymentReferenceInputSchema = nonEmptyStringSchema;\nconst parseCatalogInputFields = parser(looseObject({}));\n\nexport type ParsedPreparedCheckoutInput = InferOutput<\n typeof preparedCheckoutInputSchema\n>;\nexport type ParsedLoadCheckoutInput = InferOutput<\n typeof loadCheckoutInputSchema\n>;\nexport type ParsedPaymentReferenceInput = InferOutput<\n typeof paymentReferenceInputSchema\n>;\nexport type ParsedSubmitPaymentInput = InferOutput<\n typeof submitPaymentInputSchema\n>;\n\nconst parseCalculateTotalInputFields = parser(calculateTotalInputSchema);\n\nexport function parseCalculateTotalInput<Input>(input: Input) {\n const { catalog, items, selection, ...pricingInput } =\n parseCalculateTotalInputFields(input);\n let parsedCatalog: ReturnType<typeof parseCatalogInputFields>;\n try {\n parsedCatalog = parseCatalogInputFields(catalog);\n } catch (error) {\n throw new TypeError(\"A catalog is required to calculate a checkout.\", {\n cause: error,\n });\n }\n try {\n return {\n catalog: parsedCatalog,\n items,\n pricing: parseCheckoutPricingInput(pricingInput),\n selection,\n };\n } catch (error) {\n throw new TypeError(\"Checkout pricing input is invalid.\", { cause: error });\n }\n}\n\nexport type ParsedCalculateTotalInput = ReturnType<\n typeof parseCalculateTotalInput\n>;\nexport type ParsedCheckoutPricingInput = InferOutput<\n typeof checkoutPricingInputSchema\n>;\n\nexport const parseLoadCheckoutInput = parser(loadCheckoutInputSchema);\nexport const parsePaymentReferenceInput = parser(paymentReferenceInputSchema);\nexport const parsePreparedCheckoutInput = parser(preparedCheckoutInputSchema);\nexport const parseSubmitPaymentInput = parser(submitPaymentInputSchema);\n\nexport const parseCheckoutSelectionItems = parser(checkoutSelectionItemsSchema);\n","import type { LockerverseProduct } from \"./types.ts\";\n\nconst minimumCustomAmountCents = 100;\n\nexport function getLockerverseMinimumCustomAmountCents(\n product: Pick<LockerverseProduct, \"minimumAmountCents\">\n) {\n return Math.max(minimumCustomAmountCents, product.minimumAmountCents ?? 0);\n}\n","import { parseCheckoutSelectionItems } from \"./checkout-input-schemas.ts\";\nimport { getLockerverseMinimumCustomAmountCents } from \"./custom-amount.ts\";\nimport type {\n LockerverseCatalog,\n LockerverseCheckoutItem,\n LockerverseCheckoutLineItem,\n LockerverseCheckoutSelectionItem,\n LockerverseProduct,\n} from \"./types.ts\";\nimport { LockerverseSdkError } from \"./types.ts\";\n\ntype ResolvedSelectionItem = {\n checkoutItem: LockerverseCheckoutItem;\n quantity: number;\n unitAmountCents: number;\n};\n\nexport function assertCheckoutItemsAreAvailable(\n catalog: LockerverseCatalog,\n items: LockerverseCheckoutItem[]\n) {\n const listingIdByProductId = new Map(\n catalog.products.map(({ id, listingId }) => [id, listingId])\n );\n const requestedByListingId = items.reduce((requested, item) => {\n const listingId = listingIdByProductId.get(item.productId);\n if (listingId) {\n requested.set(\n listingId,\n (requested.get(listingId) ?? 0) +\n (\"quantity\" in item ? (item.quantity ?? 1) : 1)\n );\n }\n return requested;\n }, new Map<string, number>());\n const listingIsSoldOut = catalog.availability.listings.some(\n ({ listingId, maxPurchasableQuantity, status }) =>\n requestedByListingId.has(listingId) &&\n (status === \"sold_out\" ||\n (maxPurchasableQuantity !== null &&\n (requestedByListingId.get(listingId) ?? 0) > maxPurchasableQuantity))\n );\n const sharedLimitIsSoldOut = catalog.availability.sharedLimits.some(\n ({ listingIds, remainingQuantity, status }) => {\n const requestedQuantity = listingIds.reduce(\n (total, listingId) =>\n total + (requestedByListingId.get(listingId) ?? 0),\n 0\n );\n return (\n requestedQuantity > 0 &&\n (status === \"sold_out\" || requestedQuantity > remainingQuantity)\n );\n }\n );\n if (listingIsSoldOut || sharedLimitIsSoldOut) {\n throw new LockerverseSdkError({\n code: \"total_calculation_failed\",\n message: \"This option is sold out.\",\n operation: \"calculate_total\",\n reportable: false,\n serverCode: \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\",\n });\n }\n}\n\nfunction resolveAmountItem(\n product: LockerverseProduct,\n amountCents: number\n): ResolvedSelectionItem {\n if (\n product.pricingMode !== \"custom\" ||\n product.paymentOption !== \"one-time\" ||\n amountCents < getLockerverseMinimumCustomAmountCents(product)\n ) {\n throw new TypeError(\"Selected Product amount is invalid.\");\n }\n return {\n checkoutItem: { amountCents, productId: product.id },\n quantity: 1,\n unitAmountCents: amountCents,\n };\n}\n\nfunction resolveFixedItem(\n product: LockerverseProduct,\n quantity: number\n): ResolvedSelectionItem {\n if (product.pricingMode !== \"fixed\" || product.amountCents === null) {\n throw new TypeError(\"Selected Product quantity is invalid.\");\n }\n if (product.paymentOption !== \"one-time\" && quantity !== 1) {\n throw new TypeError(\"Selected recurring Product is invalid.\");\n }\n if (\n (product.minimumQuantity !== null && quantity < product.minimumQuantity) ||\n (product.maximumQuantity !== null && quantity > product.maximumQuantity) ||\n (product.inventoryQuantity !== null && quantity > product.inventoryQuantity)\n ) {\n throw new TypeError(\"Selected Product quantity is invalid.\");\n }\n return {\n checkoutItem:\n product.paymentOption === \"one-time\"\n ? { productId: product.id, quantity }\n : { productId: product.id },\n quantity,\n unitAmountCents: product.amountCents,\n };\n}\n\nfunction resolveSelectionItem(\n catalog: LockerverseCatalog,\n product: LockerverseProduct,\n selection: LockerverseCheckoutSelectionItem\n) {\n const selectedQuantity = \"quantity\" in selection ? selection.quantity : 1;\n const resolved =\n \"amountCents\" in selection\n ? resolveAmountItem(product, selection.amountCents)\n : resolveFixedItem(product, selectedQuantity);\n const { checkoutItem, quantity, unitAmountCents } = resolved;\n\n return {\n checkoutItem,\n lineItem: {\n acceptsDiscounts: product.acceptsDiscounts,\n eventId:\n product.fulfillmentType === \"event_admission\" && catalog.event\n ? catalog.event.id\n : null,\n fulfillmentType: product.fulfillmentType,\n listingId: product.listingId,\n listingSlug: product.slug,\n paymentOption: product.paymentOption,\n pricingMode: product.pricingMode,\n productId: product.id,\n productName: product.name,\n quantity,\n subtotalCents: unitAmountCents * quantity,\n unitAmountCents,\n } satisfies LockerverseCheckoutLineItem,\n };\n}\n\nexport function resolveCheckoutSelection(\n catalog: LockerverseCatalog,\n input: LockerverseCheckoutSelectionItem[]\n) {\n const selection = parseCheckoutSelectionItems(input);\n const selectedProducts = new Set<string>();\n const resolved = selection.map((item) => {\n const product = catalog.products.find(\n (candidate) => candidate.slug === item.productSlug\n );\n if (!product) {\n throw new TypeError(\"Selected Product is unavailable.\");\n }\n if (selectedProducts.has(product.id)) {\n throw new TypeError(\"Each Product can appear only once per checkout.\");\n }\n selectedProducts.add(product.id);\n return resolveSelectionItem(catalog, product, item);\n });\n const paymentOption = resolved[0]?.lineItem.paymentOption;\n if (!paymentOption) {\n throw new TypeError(\"Select at least one Product.\");\n }\n if (\n resolved.length > 1 &&\n (paymentOption !== \"one-time\" ||\n resolved.some(({ lineItem }) => lineItem.paymentOption !== paymentOption))\n ) {\n throw new TypeError(\"Recurring Products must be purchased separately.\");\n }\n const items = resolved.map(({ checkoutItem }) => checkoutItem);\n assertCheckoutItemsAreAvailable(catalog, items);\n return {\n items,\n lineItems: resolved.map(({ lineItem }) => lineItem),\n paymentOption,\n };\n}\n","import type { PublicProductListing, PublicWidget } from \"./checkout-schemas.ts\";\nimport { deepFreeze } from \"./deep-freeze.ts\";\nimport type {\n LockerverseCatalog,\n LockerversePaymentResult,\n LockerversePreparedCheckout,\n LockerverseProduct,\n} from \"./types.ts\";\n\nfunction mapProduct(listing: PublicProductListing): LockerverseProduct {\n const { product } = listing;\n\n return {\n acceptsDiscounts: listing.acceptsDiscounts ?? false,\n amountCents: product.amountCents,\n description: product.description ?? null,\n fulfillmentType: product.fulfillmentType,\n id: product.id,\n inventoryQuantity: product.inventoryQuantity,\n listingId: listing.id,\n maximumQuantity: product.maxQuantity,\n minimumAmountCents: product.minimumAmountCents,\n minimumQuantity: product.minQuantity,\n name: product.name,\n paymentOption: product.paymentOption,\n pricingMode: product.pricingMode,\n slug: listing.slug,\n };\n}\n\nexport function createCatalog(widget: PublicWidget): LockerverseCatalog {\n const fields = widget.config?.fields ?? {};\n\n return {\n availability: widget.availability,\n community: widget.community\n ? {\n accentColor: widget.community.color,\n imageUrl: widget.community.thumbnail || null,\n name: widget.community.name,\n }\n : null,\n event: widget.event\n ? {\n description: widget.event.description,\n endAt: widget.event.endAt,\n id: widget.event.id,\n location: widget.event.location,\n name: widget.event.name,\n startAt: widget.event.startAt,\n status: widget.event.status,\n }\n : null,\n payment: {\n connectedAccountId: widget.payment.connectedAccountId,\n currency: widget.payment.currency,\n publishableKey: widget.payment.publishableKey,\n },\n pricingPolicy: {\n currency: \"usd\",\n serviceFeeRateBasisPoints:\n widget.pricingPolicy?.serviceFeeRateBasisPoints ?? 0,\n },\n products: (widget.products ?? []).map(mapProduct),\n widget: {\n customFields: widget.config?.customFields ?? [],\n description: widget.description ?? null,\n fields: {\n memberId: fields.memberId ?? false,\n merchSize: fields.merchSize ?? false,\n phone: fields.phone ?? false,\n promoCode: fields.promoCode ?? false,\n serviceFee: fields.serviceFee ?? false,\n shipping: fields.shipping ?? false,\n tipping: fields.tipping ?? false,\n },\n id: widget.id ?? \"\",\n name: widget.name ?? \"Lockerverse widget\",\n showCommunityBranding: widget.showCommunityBranding ?? true,\n title: widget.title ?? null,\n },\n };\n}\n\nexport function cloneCatalog(catalog: LockerverseCatalog): LockerverseCatalog {\n return cloneSnapshot(catalog);\n}\n\nexport function clonePreparedCheckout(\n checkout: LockerversePreparedCheckout\n): LockerversePreparedCheckout {\n return cloneSnapshot(checkout);\n}\n\nexport function clonePaymentResult(\n paymentResult: LockerversePaymentResult\n): LockerversePaymentResult {\n return cloneSnapshot(paymentResult);\n}\n\nfunction cloneSnapshot<T>(value: T): T {\n return deepFreeze(structuredClone(value));\n}\n","import { object, picklist, safeParse } from \"valibot\";\nimport { resolveWidgetEnvironment } from \"./checkout-environment.ts\";\nimport {\n type ParsedCalculateTotalInput,\n type ParsedCheckoutPricingInput,\n parseCalculateTotalInput,\n parseLoadCheckoutInput,\n parsePaymentReferenceInput,\n parseSubmitPaymentInput,\n} from \"./checkout-input-schemas.ts\";\nimport {\n parseCatalog,\n parseCheckoutQuote,\n parsePaymentResult,\n parsePublicWidgetLoad,\n} from \"./checkout-schemas.ts\";\nimport {\n assertCheckoutItemsAreAvailable,\n resolveCheckoutSelection,\n} from \"./checkout-selection.ts\";\nimport { deepFreeze } from \"./deep-freeze.ts\";\nimport { createSdkErrorReporter } from \"./error-reporting.ts\";\nimport {\n cloneCatalog,\n clonePaymentResult,\n clonePreparedCheckout,\n createCatalog,\n} from \"./snapshots.ts\";\nimport { createTransport } from \"./transport.ts\";\nimport {\n type CreateLockerverseWidgetOptions,\n type LockerverseCalculateTotalInput,\n type LockerverseCatalog,\n type LockerverseCheckoutClient,\n type LockerverseCheckoutItem,\n type LockerverseCheckoutPricingInput,\n type LockerverseCheckoutSelectionItem,\n type LockerverseLoadCheckoutInput,\n type LockerverseLoadedCheckout,\n type LockerversePreparedCheckout,\n LockerverseSdkError,\n type LockerverseSdkOperation,\n type LockerverseSdkServerCode,\n type LockerverseSubmitPaymentInput,\n} from \"./types.ts\";\n\ntype OperationErrorContext = {\n code:\n | \"payment_status_failed\"\n | \"payment_submit_failed\"\n | \"total_calculation_failed\"\n | \"widget_load_failed\";\n message: string;\n operation:\n | \"calculate_total\"\n | \"get_payment_status\"\n | \"load_widget\"\n | \"submit_payment\";\n};\n\nconst MAX_SELECTED_WIDGET_URL_LENGTH = 4000;\nconst paymentServerErrorSchema = object({\n code: picklist([\n \"PAYMENT_WIDGET_PHONE_INVALID\",\n \"PAYMENT_WIDGET_PHONE_REQUIRED\",\n \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\",\n ]),\n});\n\nasync function readPaymentServerCode(\n response: Response\n): Promise<LockerverseSdkServerCode | undefined> {\n if (response.status !== 400 && response.status !== 409) {\n return;\n }\n try {\n const result = safeParse(paymentServerErrorSchema, await response.json());\n return result.success ? result.output.code : undefined;\n } catch {\n // Non-JSON error bodies do not contain a safe server code.\n }\n}\n\nfunction resolveCalculateTotalItems({\n catalog,\n items,\n selection,\n}: ParsedCalculateTotalInput) {\n if (items !== undefined && selection !== undefined) {\n throw new TypeError(\"Use items or selection, not both.\");\n }\n const selectionCatalog = cloneCatalog(parseCatalog(catalog));\n const checkoutItems =\n selection === undefined\n ? requireCheckoutItems(items)\n : resolveCheckoutSelection(selectionCatalog, selection).items;\n assertCheckoutItemsAreAvailable(selectionCatalog, checkoutItems);\n return {\n catalog: selectionCatalog,\n items: checkoutItems,\n };\n}\n\nfunction requireCheckoutItems(\n items: ParsedCalculateTotalInput[\"items\"]\n): LockerverseCheckoutItem[] {\n if (items === undefined) {\n throw new TypeError(\"Checkout selection is invalid.\");\n }\n return items;\n}\n\nexport function createLockerverseCheckoutClient(\n options: CreateLockerverseWidgetOptions\n): LockerverseCheckoutClient {\n const {\n apiBaseUrl,\n communitySlug,\n communitySlugValue,\n environment,\n fetchImplementation,\n onError,\n requestTimeoutMs,\n sentryDsn,\n widgetSlug,\n widgetSlugValue,\n } = resolveWidgetEnvironment(options);\n const reportError = createSdkErrorReporter({\n communitySlug: communitySlugValue,\n environment,\n getContext: () => ({ widgetSlug: widgetSlugValue }),\n onError,\n resourceContextName: \"lockerverse_widget\",\n sentryDsn,\n });\n const { requestJson } = createTransport(\n fetchImplementation,\n reportError,\n requestTimeoutMs\n );\n const checkoutBaseUrl = `${apiBaseUrl}/v2/community/${communitySlug}/payment-widgets/${widgetSlug}/checkout`;\n const widgetUrl = `${apiBaseUrl}/v2/community/${communitySlug}/payment-widgets/${widgetSlug}`;\n\n function invalidInput(\n message: string,\n operation: LockerverseSdkOperation,\n code: \"invalid_selection\" | \"payment_submit_failed\" = \"invalid_selection\"\n ): never {\n throw reportError(\n new LockerverseSdkError({\n code,\n message,\n operation,\n reportable: false,\n })\n );\n }\n\n function normalizeOperationError<ErrorValue>(\n error: ErrorValue,\n context: OperationErrorContext\n ) {\n return error instanceof LockerverseSdkError\n ? error\n : new LockerverseSdkError({ ...context, reportable: true });\n }\n\n function failOperation<ErrorValue>(\n error: ErrorValue,\n context: OperationErrorContext,\n recoveryMayBeRequired = false\n ): never {\n const normalized = normalizeOperationError(error, context);\n const recoveryRecommended =\n recoveryMayBeRequired &&\n (normalized.status === undefined || normalized.status >= 500);\n if (!recoveryRecommended) {\n throw reportError(normalized);\n }\n const recoveryError =\n normalized.status === undefined\n ? new LockerverseSdkError({\n code: normalized.code,\n message: normalized.message,\n operation: normalized.operation,\n recoveryRecommended: true,\n reportable: normalized.reportable,\n })\n : new LockerverseSdkError({\n code: normalized.code,\n message: normalized.message,\n operation: normalized.operation,\n recoveryRecommended: true,\n reportable: normalized.reportable,\n status: normalized.status,\n });\n throw reportError(recoveryError);\n }\n\n function normalizePricingInput(input: ParsedCheckoutPricingInput) {\n const email = input.email?.trim().toLowerCase();\n const promoCode = input.promoCode?.trim();\n const pricing: LockerverseCheckoutPricingInput = {};\n if (email) {\n pricing.email = email;\n }\n if (input.includeServiceFee !== undefined) {\n pricing.includeServiceFee = input.includeServiceFee;\n }\n if (promoCode) {\n pricing.promoCode = promoCode;\n }\n if (input.tipCents !== undefined) {\n pricing.tipCents = input.tipCents;\n }\n return pricing;\n }\n\n function normalizeLoadSelection(input: LockerverseLoadCheckoutInput) {\n try {\n return parseLoadCheckoutInput(input).selection;\n } catch {\n invalidInput(\"Checkout selection is invalid.\", \"load_widget\");\n }\n }\n\n function createPreparedCheckout(\n quote: ReturnType<typeof parseCheckoutQuote>,\n items: LockerverseCheckoutItem[],\n pricing: LockerverseCheckoutPricingInput,\n payment: LockerverseCatalog[\"payment\"]\n ): LockerversePreparedCheckout {\n const { connectedAccountId, ...checkoutQuote } = quote;\n return clonePreparedCheckout(\n deepFreeze({\n ...checkoutQuote,\n authoritative: true as const,\n items,\n payment: {\n connectedAccountId,\n currency: \"usd\" as const,\n publishableKey: payment.publishableKey,\n },\n paymentOption: quote.paymentOption,\n paymentReference: globalThis.crypto.randomUUID(),\n pricing,\n })\n );\n }\n\n function resolveSelectedCheckoutItems(\n catalog: LockerverseCatalog,\n selection: LockerverseCheckoutSelectionItem[],\n operation: LockerverseSdkOperation\n ) {\n try {\n return resolveCheckoutSelection(catalog, selection).items;\n } catch (error) {\n if (error instanceof TypeError) {\n invalidInput(error.message, operation);\n }\n throw error;\n }\n }\n\n function createSelectedCheckout(\n catalog: LockerverseCatalog,\n selection: LockerverseCheckoutSelectionItem[],\n quote: ReturnType<typeof parseCheckoutQuote> | undefined,\n context: OperationErrorContext\n ) {\n if (!quote) {\n throw new LockerverseSdkError({\n ...context,\n message: \"Lockerverse did not return the requested initial quote.\",\n reportable: true,\n });\n }\n const checkoutItems = resolveSelectedCheckoutItems(\n catalog,\n selection,\n context.operation\n );\n return deepFreeze({\n catalog: cloneCatalog(catalog),\n checkout: createPreparedCheckout(\n quote,\n checkoutItems,\n { includeServiceFee: catalog.widget.fields.serviceFee },\n catalog.payment\n ),\n });\n }\n\n function requestWidgetResource(): Promise<LockerverseCatalog>;\n function requestWidgetResource(\n selection: LockerverseCheckoutSelectionItem[]\n ): Promise<LockerverseLoadedCheckout>;\n async function requestWidgetResource(\n selection?: LockerverseCheckoutSelectionItem[]\n ): Promise<LockerverseCatalog | LockerverseLoadedCheckout> {\n const context = {\n code: \"widget_load_failed\" as const,\n message: \"Lockerverse returned an invalid widget catalog.\",\n operation: \"load_widget\" as const,\n };\n const requestUrl = selection\n ? `${widgetUrl}?selection=${encodeURIComponent(JSON.stringify(selection))}`\n : widgetUrl;\n const response = await requestJson(\n requestUrl,\n selection ? { cache: \"no-store\" } : undefined,\n parsePublicWidgetLoad,\n {\n ...context,\n message:\n \"Unable to load Lockerverse widget because the request failed.\",\n report: false,\n },\n { ...context, report: false }\n );\n if (!response.ok) {\n const serverCode = await readPaymentServerCode(response.response);\n if (serverCode === \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\") {\n throw new LockerverseSdkError({\n ...context,\n message: \"This option is sold out.\",\n reportable: false,\n serverCode,\n status: response.response.status,\n });\n }\n throw new LockerverseSdkError({\n ...context,\n message: `Unable to load Lockerverse widget (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n const catalog = deepFreeze(createCatalog(response.value.widget));\n if (!selection) {\n return cloneCatalog(catalog);\n }\n return createSelectedCheckout(\n catalog,\n selection,\n response.value.quote,\n context\n );\n }\n\n async function loadLargeSelection(\n selection: LockerverseCheckoutSelectionItem[],\n context: OperationErrorContext\n ): Promise<LockerverseLoadedCheckout> {\n const loaded = await requestWidgetResource();\n const pricing = {\n includeServiceFee: loaded.widget.fields.serviceFee,\n };\n const items = resolveSelectedCheckoutItems(\n loaded,\n selection,\n context.operation\n );\n return deepFreeze({\n catalog: loaded,\n checkout: await requestCheckoutQuote(\n items,\n pricing,\n loaded.payment,\n context\n ),\n });\n }\n\n async function loadWidget(\n selection?: LockerverseCheckoutSelectionItem[]\n ): Promise<LockerverseCatalog | LockerverseLoadedCheckout> {\n const context = {\n code: \"widget_load_failed\" as const,\n message: \"Lockerverse returned an invalid widget catalog.\",\n operation: \"load_widget\" as const,\n };\n try {\n if (\n selection &&\n `${widgetUrl}?selection=${encodeURIComponent(JSON.stringify(selection))}`\n .length > MAX_SELECTED_WIDGET_URL_LENGTH\n ) {\n return await loadLargeSelection(selection, context);\n }\n return selection\n ? await requestWidgetResource(selection)\n : await requestWidgetResource();\n } catch (error) {\n failOperation(error, context);\n }\n }\n\n function load(): Promise<LockerverseCatalog>;\n function load(\n input: LockerverseLoadCheckoutInput\n ): Promise<LockerverseLoadedCheckout>;\n function load(input?: LockerverseLoadCheckoutInput) {\n return input === undefined\n ? loadWidget()\n : loadWidget(normalizeLoadSelection(input));\n }\n\n async function requestCheckoutQuote(\n items: LockerverseCheckoutItem[],\n pricing: LockerverseCheckoutPricingInput,\n payment: LockerverseCatalog[\"payment\"],\n context: OperationErrorContext\n ) {\n const response = await requestJson(\n `${checkoutBaseUrl}/quote`,\n {\n body: JSON.stringify({ ...pricing, items }),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"POST\",\n },\n parseCheckoutQuote,\n {\n ...context,\n message:\n \"Unable to calculate the Lockerverse checkout total because the request failed.\",\n report: false,\n },\n { ...context, report: false }\n );\n if (!response.ok) {\n const serverCode = await readPaymentServerCode(response.response);\n if (serverCode === \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\") {\n throw new LockerverseSdkError({\n ...context,\n message: \"This option is sold out.\",\n reportable: false,\n serverCode,\n status: response.response.status,\n });\n }\n throw new LockerverseSdkError({\n ...context,\n message: `Unable to calculate the Lockerverse checkout total (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n return createPreparedCheckout(response.value, items, pricing, payment);\n }\n\n async function calculateTotal(input: LockerverseCalculateTotalInput) {\n const { catalog, items, pricing } = normalizeCalculateTotalInput(input);\n const context = {\n code: \"total_calculation_failed\" as const,\n message: \"Lockerverse returned an invalid checkout total.\",\n operation: \"calculate_total\" as const,\n };\n try {\n return await requestCheckoutQuote(\n items,\n pricing,\n catalog.payment,\n context\n );\n } catch (error) {\n failOperation(error, context);\n }\n }\n\n function normalizeCalculateTotalInput(input: LockerverseCalculateTotalInput) {\n try {\n const parsed = parseCalculateTotalInput(input);\n const resolved = resolveCalculateTotalItems(parsed);\n const pricing = normalizePricingInput(parsed.pricing);\n return {\n catalog: resolved.catalog,\n items: resolved.items,\n pricing:\n pricing.includeServiceFee === undefined\n ? {\n ...pricing,\n includeServiceFee: resolved.catalog.widget.fields.serviceFee,\n }\n : pricing,\n };\n } catch (error) {\n if (error instanceof LockerverseSdkError) {\n throw error;\n }\n invalidInput(\n error instanceof TypeError\n ? error.message\n : \"Checkout selection is invalid.\",\n \"calculate_total\"\n );\n }\n }\n\n function normalizeSubmitPaymentInput(input: LockerverseSubmitPaymentInput) {\n try {\n const parsed = parseSubmitPaymentInput(input);\n const {\n items,\n pricing: pricingInput,\n quote: quoteInput,\n } = parsed.checkout;\n const pricing = normalizePricingInput(pricingInput);\n const quote = deepFreeze(quoteInput);\n const { submission } = parsed;\n if (quote.totalCents > 0 && !submission.confirmationToken) {\n invalidInput(\n \"Stripe confirmation is required for a paid checkout.\",\n \"submit_payment\",\n \"payment_submit_failed\"\n );\n }\n const email = submission.email.trim().toLowerCase();\n if (!email || email !== pricing.email) {\n invalidInput(\n \"Payment email must match the current checkout quote.\",\n \"submit_payment\"\n );\n }\n return {\n items,\n pricing,\n quote,\n submission: { ...submission, email },\n };\n } catch (error) {\n if (error instanceof LockerverseSdkError) {\n throw error;\n }\n invalidInput(\n \"Lockerverse payment submission is invalid.\",\n \"submit_payment\",\n \"payment_submit_failed\"\n );\n }\n }\n\n return {\n calculateTotal,\n async getPaymentStatus(paymentReference) {\n let normalizedReference: string;\n try {\n normalizedReference =\n parsePaymentReferenceInput(paymentReference).trim();\n } catch {\n invalidInput(\n \"Provide a payment reference to recover its status.\",\n \"get_payment_status\"\n );\n }\n const context = {\n code: \"payment_status_failed\" as const,\n message: \"Lockerverse returned an invalid payment status.\",\n operation: \"get_payment_status\" as const,\n };\n try {\n const response = await requestJson(\n `${checkoutBaseUrl}/${encodeURIComponent(normalizedReference)}/status`,\n undefined,\n parsePaymentResult,\n {\n ...context,\n message:\n \"Unable to recover the Lockerverse payment status because the request failed.\",\n report: false,\n },\n { ...context, report: false }\n );\n if (!response.ok) {\n throw new LockerverseSdkError({\n ...context,\n message: `Unable to recover the Lockerverse payment status (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n if (response.value.paymentReference !== normalizedReference) {\n throw new LockerverseSdkError({ ...context, reportable: true });\n }\n return clonePaymentResult(response.value);\n } catch (error) {\n failOperation(error, context);\n }\n },\n load,\n async submitPayment(input) {\n const { items, pricing, quote, submission } =\n normalizeSubmitPaymentInput(input);\n const context = {\n code: \"payment_submit_failed\" as const,\n message: \"Lockerverse returned an invalid payment confirmation.\",\n operation: \"submit_payment\" as const,\n };\n try {\n const response = await requestJson(\n `${checkoutBaseUrl}/confirm`,\n {\n body: JSON.stringify({\n confirmationToken: submission.confirmationToken,\n customFieldAnswers: submission.customFieldAnswers,\n email: submission.email,\n expectedAmountCents: quote.amountCents,\n expectedAppliedDiscount: quote.appliedDiscount,\n expectedConnectedAccountId: quote.payment.connectedAccountId,\n expectedDiscountableSubtotalCents:\n quote.discountableSubtotalCents,\n expectedDiscountCents: quote.discountCents,\n expectedServiceFeeCents: quote.serviceFeeCents,\n expectedSubtotalCents: quote.subtotalCents,\n expectedTipCents: quote.tipCents,\n expectedTotalCents: quote.totalCents,\n ...pricing,\n items,\n memberId: submission.memberId,\n merchSize: submission.merchSize,\n metadata: submission.metadata,\n paymentReference: quote.paymentReference,\n phone: submission.phone,\n quoteContractVersion: 1,\n shipping: submission.shipping,\n }),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"POST\",\n },\n parsePaymentResult,\n {\n ...context,\n message:\n \"Unable to submit the Lockerverse payment because the request failed.\",\n report: false,\n },\n { ...context, report: false }\n );\n if (!response.ok) {\n const serverCode = await readPaymentServerCode(response.response);\n if (serverCode) {\n throw new LockerverseSdkError({\n ...context,\n message:\n serverCode === \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\"\n ? \"This option is sold out.\"\n : `Unable to submit the Lockerverse payment (${response.response.status}).`,\n reportable: false,\n serverCode,\n status: response.response.status,\n });\n }\n throw new LockerverseSdkError({\n ...context,\n message: `Unable to submit the Lockerverse payment (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n if (response.value.paymentReference !== quote.paymentReference) {\n throw new LockerverseSdkError({ ...context, reportable: true });\n }\n return clonePaymentResult(response.value);\n } catch (error) {\n failOperation(error, context, true);\n }\n },\n };\n}\n","import { parseCheckoutPricingInput } from \"./checkout-input-schemas.ts\";\nimport { resolveCheckoutSelection } from \"./checkout-selection.ts\";\nimport { deepFreeze } from \"./deep-freeze.ts\";\nimport type {\n LockerverseCatalog,\n LockerverseCheckoutEstimate,\n LockerverseEstimateCheckoutInput,\n} from \"./types.ts\";\n\nexport function estimateLockerverseCheckout(\n catalog: LockerverseCatalog,\n input: LockerverseEstimateCheckoutInput\n): LockerverseCheckoutEstimate {\n const { selection, ...pricingInput } = input;\n let pricing: ReturnType<typeof parseCheckoutPricingInput>;\n try {\n pricing = parseCheckoutPricingInput(pricingInput);\n } catch (error) {\n throw new TypeError(\"Checkout pricing is invalid.\", { cause: error });\n }\n const includeServiceFee =\n pricing.includeServiceFee ?? catalog.widget.fields.serviceFee;\n const { tipCents = 0 } = pricing;\n const { items, lineItems, paymentOption } = resolveCheckoutSelection(\n catalog,\n selection\n );\n const subtotalCents = lineItems.reduce(\n (total, lineItem) => total + lineItem.subtotalCents,\n 0\n );\n if (\n !Number.isSafeInteger(subtotalCents) ||\n subtotalCents <= 0 ||\n subtotalCents > 2_147_483_647\n ) {\n throw new TypeError(\"Checkout total is invalid.\");\n }\n const discountableSubtotalCents = lineItems.reduce(\n (total, lineItem) =>\n total + (lineItem.acceptsDiscounts ? lineItem.subtotalCents : 0),\n 0\n );\n const serviceFeeCents = includeServiceFee\n ? Math.round(\n (subtotalCents * catalog.pricingPolicy.serviceFeeRateBasisPoints) /\n 10_000\n )\n : 0;\n const amountCents = subtotalCents + serviceFeeCents;\n const totalCents = amountCents + tipCents;\n if (!Number.isSafeInteger(totalCents) || totalCents > 2_147_483_647) {\n throw new TypeError(\"Checkout total is invalid.\");\n }\n\n return deepFreeze({\n amountCents,\n appliedDiscount: null,\n authoritative: false,\n discountableSubtotalCents,\n discountCents: 0,\n items,\n lineItems,\n paymentOption,\n serviceFeeCents,\n subtotalCents,\n tipCents,\n totalCents,\n });\n}\n"],"mappings":"sfAGA,SAAgB,GACd,EACA,CACA,IAAM,EAAU,EAA2B,EAAS,YAAY,EAChE,MAAO,CACL,GAAG,EACH,WAAY,EAAQ,aACpB,gBAAiB,EAAQ,iBAC3B,CACF,CCyBA,MAAM,EAAsB,EAAS,CAAC,WAAY,UAAW,UAAU,CAAC,EAClE,EAAwB,EAAS,CAAC,OAAQ,iBAAiB,CAAC,EAC5D,EAAmC,EAAS,EAAkB,CAAC,CAAC,EAChE,GAA2B,EAAS,CAAC,YAAa,UAAU,CAAC,EAC7D,GAAqB,EACzB,EAAO,CACL,SAAU,EACR,EAAO,CACL,UAAW,EACX,uBAAwB,EACxB,kBAAmB,EACnB,OAAQ,EACV,CAAC,CACH,EACA,aAAc,EACZ,EAAO,CACL,GAAI,EACJ,WAAY,EAAM,CAAoB,EACtC,kBAAmB,EAAkB,CAAC,EACtC,OAAQ,EACV,CAAC,CACH,CACF,CAAC,EACD,CAAE,SAAU,CAAC,EAAG,aAAc,CAAC,CAAE,CACnC,EACM,GAAuB,EAC3B,EAAO,EACP,EAAM,yBAA0B,0BAA0B,CAC5D,EAEM,EAAqB,CACzB,YAAa,EACb,gBAAiB,EACjB,GAAI,EACJ,kBAAmB,EACnB,YAAa,EACb,mBAAoB,EACpB,YAAa,EACb,KAAM,EACN,cAAe,CACjB,EAEM,EAAc,EAAO,CACzB,YAAa,EAAS,EAAO,CAAC,EAC9B,MAAO,EACP,GAAI,EACJ,SAAU,EAAS,EAAO,CAAC,EAC3B,KAAM,EACN,QAAS,EACT,OAAQ,EAAS,CAAC,QAAS,SAAU,WAAY,WAAW,CAAC,CAC/D,CAAC,EAEK,GAAsB,EAC1B,GAAQ,cAAe,CACrB,EAAO,CACL,GAAG,EACH,YAAa,EAAkB,CAAC,EACh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AW,GAAG,GAAiB,EACnC,EACJ,GAAI,CACF,EAAU,EAA0B,CAAY,CAClD,OAAS,EAAO,CACd,MAAU,UAAU,+BAAgC,CAAE,MAAO,CAAM,CAAC,CACtE,CACA,IAAM,EACJ,EAAQ,mBAAqB,EAAQ,OAAO,OAAO,WAC/C,CAAE,WAAW,GAAM,EACnB,CAAE,QAAO,YAAW,iBAAkB,EAC1C,EACA,CACF,EACM,EAAgB,EAAU,QAC7B,EAAO,IAAa,EAAQ,EAAS,cACtC,CACF,EACA,GACE,CAAC,OAAO,cAAc,CAAa,GACnC,GAAiB,GACjB,EAAgB,WAEhB,MAAU,UAAU,4BAA4B,EAElD,IAAM,EAA4B,EAAU,QACzC,EAAO,IACN,GAAS,EAAS,iBAAmB,EAAS,cAAgB,GAChE,CACF,EACM,EAAkB,EACpB,KAAK,MACF,EAAgB,EAAQ,cAAc,0BACrC,GACJ,EACA,EACE,EAAc,EAAgB,EAC9B,EAAa,EAAc,EACjC,GAAI,CAAC,OAAO,cAAc,CAAU,GAAK,EAAa,WACpD,MAAU,UAAU,4BAA4B,EAGlD,OAAO,EAAW,CAChB,cACA,gBAAiB,KACjB,cAAe,GACf,4BACA,cAAe,EACf,QACA,YACA,gBACA,kBACA,gBACA,WACA,YACF,CAAC,CACH"}
1
+ {"version":3,"file":"checkout.js","names":[],"sources":["../src/checkout-environment.ts","../src/checkout-schemas.ts","../src/checkout-input-schemas.ts","../src/custom-amount.ts","../src/checkout-selection.ts","../src/snapshots.ts","../src/checkout-client.ts","../src/checkout-estimate.ts"],"sourcesContent":["import { resolveResourceEnvironment } from \"./environment.ts\";\nimport type { CreateLockerverseWidgetOptions } from \"./types.ts\";\n\nexport function resolveWidgetEnvironment(\n options: CreateLockerverseWidgetOptions\n) {\n const runtime = resolveResourceEnvironment(options, \"widgetSlug\");\n return {\n ...runtime,\n widgetSlug: runtime.resourceSlug,\n widgetSlugValue: runtime.resourceSlugValue,\n };\n}\n","import {\n array,\n boolean,\n check,\n finite,\n type InferOutput,\n literal,\n looseObject,\n maxValue,\n minValue,\n nullable,\n number,\n object,\n optional,\n parser,\n picklist,\n pipe,\n regex,\n safeParse,\n string,\n transform,\n unknown,\n variant,\n} from \"valibot\";\n\nimport {\n vPaymentWidgetPaymentResultResponseDto,\n vPaymentWidgetQuoteResponseDto,\n vPublicPaymentWidgetResponseDto,\n} from \"./generated/public-api/valibot.gen.ts\";\nimport {\n customFieldsSchema,\n nonEmptyStringSchema,\n optionalNullableStringSchema,\n safeIntegerSchema,\n} from \"./schema-helpers.ts\";\n\nconst paymentOptionSchema = picklist([\"one-time\", \"monthly\", \"annually\"]);\nconst fulfillmentTypeSchema = picklist([\"none\", \"event_admission\"]);\nconst nullableNonNegativeIntegerSchema = nullable(safeIntegerSchema(0));\nconst availabilityStatusSchema = picklist([\"available\", \"sold_out\"]);\nconst availabilitySchema = optional(\n object({\n listings: array(\n object({\n listingId: nonEmptyStringSchema,\n maxPurchasableQuantity: nullableNonNegativeIntegerSchema,\n remainingQuantity: nullableNonNegativeIntegerSchema,\n status: availabilityStatusSchema,\n })\n ),\n sharedLimits: array(\n object({\n id: nonEmptyStringSchema,\n listingIds: array(nonEmptyStringSchema),\n remainingQuantity: safeIntegerSchema(0),\n status: availabilityStatusSchema,\n })\n ),\n }),\n { listings: [], sharedLimits: [] }\n);\nconst publishableKeySchema = pipe(\n string(),\n regex(/^pk_(?:test|live)_\\S+$/, \"Invalid publishable key.\")\n);\n\nconst productBaseEntries = {\n description: optionalNullableStringSchema,\n fulfillmentType: fulfillmentTypeSchema,\n id: nonEmptyStringSchema,\n inventoryQuantity: nullableNonNegativeIntegerSchema,\n maxQuantity: nullableNonNegativeIntegerSchema,\n minimumAmountCents: nullableNonNegativeIntegerSchema,\n minQuantity: nullableNonNegativeIntegerSchema,\n name: nonEmptyStringSchema,\n paymentOption: paymentOptionSchema,\n};\n\nconst eventSchema = object({\n description: nullable(string()),\n endAt: nonEmptyStringSchema,\n id: nonEmptyStringSchema,\n location: nullable(string()),\n name: nonEmptyStringSchema,\n startAt: nonEmptyStringSchema,\n status: picklist([\"draft\", \"active\", \"finished\", \"cancelled\"]),\n});\n\nconst publicProductSchema = pipe(\n variant(\"pricingMode\", [\n object({\n ...productBaseEntries,\n amountCents: safeIntegerSchema(0),\n pricingMode: literal(\"fixed\"),\n }),\n object({\n ...productBaseEntries,\n amountCents: nullableNonNegativeIntegerSchema,\n pricingMode: literal(\"custom\"),\n }),\n ]),\n check(\n ({ maxQuantity, minQuantity }) =>\n maxQuantity === null || minQuantity === null || minQuantity <= maxQuantity\n )\n);\n\nconst productListingSchema = object({\n acceptsDiscounts: optional(boolean(), false),\n id: nonEmptyStringSchema,\n product: publicProductSchema,\n productId: nonEmptyStringSchema,\n slug: nonEmptyStringSchema,\n});\n\nconst widgetFieldsSchema = optional(\n object({\n memberId: optional(boolean(), false),\n merchSize: optional(boolean(), false),\n phone: optional(boolean(), false),\n promoCode: optional(boolean(), false),\n serviceFee: optional(boolean(), false),\n shipping: optional(boolean(), false),\n tipping: optional(boolean(), false),\n }),\n {}\n);\n\nexport const publicWidgetSchema = pipe(\n object({\n availability: availabilitySchema,\n community: optional(\n object({\n color: string(),\n memberIdLabel: optional(nullable(string())),\n name: nonEmptyStringSchema,\n thumbnail: nullable(string()),\n })\n ),\n config: optional(\n object({\n customFields: customFieldsSchema,\n fields: widgetFieldsSchema,\n })\n ),\n description: optionalNullableStringSchema,\n event: nullable(eventSchema),\n id: optional(string(), \"\"),\n name: optional(string(), \"Lockerverse widget\"),\n payment: object({\n connectedAccountId: optional(nullable(nonEmptyStringSchema), null),\n currency: literal(\"usd\"),\n publishableKey: publishableKeySchema,\n }),\n pricingPolicy: optional(\n object({\n currency: optional(literal(\"usd\"), \"usd\"),\n serviceFeeRateBasisPoints: optional(safeIntegerSchema(0), 0),\n })\n ),\n products: optional(array(productListingSchema), []),\n showCommunityBranding: optional(boolean(), true),\n title: optionalNullableStringSchema,\n }),\n transform((widget) => ({\n ...widget,\n config: {\n customFields: widget.config?.customFields ?? [],\n fields: {\n memberId: widget.config?.fields?.memberId ?? false,\n merchSize: widget.config?.fields?.merchSize ?? false,\n phone: widget.config?.fields?.phone ?? false,\n promoCode: widget.config?.fields?.promoCode ?? false,\n serviceFee: widget.config?.fields?.serviceFee ?? false,\n shipping: widget.config?.fields?.shipping ?? false,\n tipping: widget.config?.fields?.tipping ?? false,\n },\n },\n pricingPolicy: widget.pricingPolicy ?? {\n currency: \"usd\" as const,\n serviceFeeRateBasisPoints: 0,\n },\n }))\n);\n\nconst catalogProductSchema = object({\n acceptsDiscounts: boolean(),\n amountCents: nullable(safeIntegerSchema(0)),\n description: nullable(string()),\n fulfillmentType: fulfillmentTypeSchema,\n id: nonEmptyStringSchema,\n inventoryQuantity: nullableNonNegativeIntegerSchema,\n listingId: nonEmptyStringSchema,\n maximumQuantity: nullableNonNegativeIntegerSchema,\n minimumAmountCents: nullableNonNegativeIntegerSchema,\n minimumQuantity: nullableNonNegativeIntegerSchema,\n name: nonEmptyStringSchema,\n paymentOption: paymentOptionSchema,\n pricingMode: picklist([\"fixed\", \"custom\"]),\n slug: nonEmptyStringSchema,\n});\n\nconst catalogSchema = object({\n availability: availabilitySchema,\n community: nullable(\n object({\n accentColor: string(),\n imageUrl: nullable(string()),\n memberIdLabel: optional(nullable(string())),\n name: nonEmptyStringSchema,\n })\n ),\n event: nullable(eventSchema),\n payment: object({\n connectedAccountId: optional(nullable(nonEmptyStringSchema), null),\n currency: literal(\"usd\"),\n publishableKey: publishableKeySchema,\n }),\n pricingPolicy: object({\n currency: literal(\"usd\"),\n serviceFeeRateBasisPoints: safeIntegerSchema(0),\n }),\n products: array(catalogProductSchema),\n widget: object({\n customFields: customFieldsSchema,\n description: nullable(string()),\n fields: widgetFieldsSchema,\n id: string(),\n name: nonEmptyStringSchema,\n showCommunityBranding: boolean(),\n title: nullable(string()),\n }),\n});\n\nconst appliedDiscountSchema = nullable(\n object({\n percentageOff: pipe(number(), finite(), minValue(0), maxValue(100)),\n source: picklist([\"email_list\", \"promo_code\"]),\n })\n);\n\nconst checkoutLineItemSchema = object({\n acceptsDiscounts: boolean(),\n eventId: nullable(nonEmptyStringSchema),\n fulfillmentType: fulfillmentTypeSchema,\n listingId: nonEmptyStringSchema,\n listingSlug: nonEmptyStringSchema,\n paymentOption: paymentOptionSchema,\n pricingMode: picklist([\"fixed\", \"custom\"]),\n productId: nonEmptyStringSchema,\n productName: nonEmptyStringSchema,\n quantity: safeIntegerSchema(1),\n subtotalCents: safeIntegerSchema(0),\n unitAmountCents: safeIntegerSchema(0),\n});\n\nexport const checkoutQuoteSchema = pipe(\n vPaymentWidgetQuoteResponseDto,\n object({\n amountCents: safeIntegerSchema(0),\n appliedDiscount: appliedDiscountSchema,\n connectedAccountId: nullable(nonEmptyStringSchema),\n discountableSubtotalCents: safeIntegerSchema(0),\n discountCents: safeIntegerSchema(0),\n lineItems: array(checkoutLineItemSchema),\n paymentOption: paymentOptionSchema,\n serviceFeeCents: safeIntegerSchema(0),\n subtotalCents: safeIntegerSchema(0),\n tipCents: safeIntegerSchema(0),\n totalCents: safeIntegerSchema(0),\n }),\n check(({ lineItems, paymentOption }) => {\n if (\n lineItems.length === 0 ||\n lineItems.some((item) => item.paymentOption !== paymentOption)\n ) {\n return false;\n }\n return (\n paymentOption === \"one-time\" ||\n (lineItems.length === 1 &&\n lineItems[0]?.pricingMode === \"fixed\" &&\n lineItems[0].quantity === 1)\n );\n }, \"Invalid checkout cadence composition.\")\n);\n\nexport const paymentResultSchema = pipe(\n vPaymentWidgetPaymentResultResponseDto,\n check((payment) => {\n if (!(payment.checkoutId.trim() && payment.paymentReference.trim())) {\n return false;\n }\n if (payment.checkoutStatus === \"action_required\") {\n return (\n payment.requiresAction &&\n payment.paymentRequired &&\n Boolean(payment.clientSecret?.trim())\n );\n }\n return !payment.requiresAction && payment.clientSecret === null;\n }, \"Invalid payment result state.\")\n);\n\nexport type PublicCheckoutQuote = InferOutput<typeof checkoutQuoteSchema>;\nexport type PublicProductListing = InferOutput<typeof productListingSchema>;\nexport type PublicWidget = InferOutput<typeof publicWidgetSchema>;\n\nexport const parseCheckoutQuote = parser(checkoutQuoteSchema);\nexport const parseCatalog = parser(catalogSchema);\nexport const parsePaymentResult = parser(paymentResultSchema);\nconst parsePublicWidgetContract = parser(vPublicPaymentWidgetResponseDto);\nconst parseSdkPublicWidget = parser(publicWidgetSchema);\n\nexport function parsePublicWidget<Input>(input: Input) {\n parsePublicWidgetContract(input);\n return parseSdkPublicWidget(input);\n}\n\nexport function parsePublicWidgetLoad<Input>(input: Input) {\n const response = safeParse(\n looseObject({ quote: optional(unknown()) }),\n input\n );\n const widget = parsePublicWidget(input);\n const quote = response.success ? response.output.quote : undefined;\n return quote === undefined\n ? { widget }\n : { quote: parseCheckoutQuote(quote), widget };\n}\n","import {\n array,\n boolean,\n type InferOutput,\n literal,\n looseObject,\n minLength,\n nullable,\n object,\n optional,\n parser,\n picklist,\n pipe,\n record,\n strictObject,\n string,\n transform,\n union,\n unknown,\n} from \"valibot\";\n\nimport { parseCheckoutQuote } from \"./checkout-schemas.ts\";\nimport {\n customFieldAnswerSchema,\n nonEmptyStringSchema,\n safeIntegerSchema,\n} from \"./schema-helpers.ts\";\n\nconst checkoutPricingEntries = {\n email: optional(string()),\n includeServiceFee: optional(boolean()),\n promoCode: optional(string()),\n tipCents: optional(safeIntegerSchema(0)),\n};\n\nconst checkoutPricingInputSchema = strictObject(checkoutPricingEntries);\n\nexport const parseCheckoutPricingInput = parser(\n optional(checkoutPricingInputSchema, {})\n);\n\nconst paymentSubmissionSchema = strictObject({\n confirmationToken: optional(nonEmptyStringSchema),\n customFieldAnswers: optional(array(customFieldAnswerSchema)),\n email: string(),\n memberId: optional(string()),\n merchSize: optional(picklist([\"XS\", \"S\", \"M\", \"L\", \"XL\", \"XXL\", \"XXXL\"])),\n metadata: optional(record(string(), string())),\n phone: optional(string()),\n shipping: optional(\n strictObject({\n address: strictObject({\n city: string(),\n country: string(),\n line1: string(),\n line2: optional(string()),\n postal_code: string(),\n state: string(),\n }),\n name: string(),\n })\n ),\n});\n\nconst checkoutItemSchema = union([\n strictObject({\n amountCents: safeIntegerSchema(1),\n productId: nonEmptyStringSchema,\n }),\n strictObject({\n productId: nonEmptyStringSchema,\n quantity: safeIntegerSchema(1),\n }),\n strictObject({\n productId: nonEmptyStringSchema,\n }),\n]);\n\nconst checkoutSelectionItemSchema = union([\n strictObject({\n amountCents: safeIntegerSchema(1),\n productSlug: nonEmptyStringSchema,\n }),\n strictObject({\n productSlug: nonEmptyStringSchema,\n quantity: safeIntegerSchema(1),\n }),\n strictObject({\n productSlug: nonEmptyStringSchema,\n }),\n]);\n\nconst checkoutItemsSchema = pipe(array(checkoutItemSchema), minLength(1));\nconst checkoutSelectionItemsSchema = pipe(\n array(checkoutSelectionItemSchema),\n minLength(1)\n);\n\nconst loadCheckoutInputSchema = object({\n selection: checkoutSelectionItemsSchema,\n});\n\nconst calculateTotalInputSchema = looseObject({\n catalog: optional(unknown()),\n email: optional(unknown()),\n includeServiceFee: optional(unknown()),\n items: optional(checkoutItemsSchema),\n promoCode: optional(unknown()),\n selection: optional(checkoutSelectionItemsSchema),\n tipCents: optional(unknown()),\n});\n\nconst preparedCheckoutInputSchema = pipe(\n looseObject({\n authoritative: literal(true),\n items: checkoutItemsSchema,\n payment: object({\n connectedAccountId: nullable(nonEmptyStringSchema),\n currency: literal(\"usd\"),\n publishableKey: pipe(string(), minLength(1)),\n }),\n paymentReference: pipe(string(), minLength(1)),\n pricing: checkoutPricingInputSchema,\n }),\n transform((checkout) => {\n const { items, payment, paymentReference, pricing, ...quoteInput } =\n checkout;\n const parsedQuote = parseCheckoutQuote({\n ...quoteInput,\n connectedAccountId: payment.connectedAccountId,\n });\n const { connectedAccountId, ...quote } = parsedQuote;\n return {\n items,\n pricing,\n quote: {\n ...quote,\n authoritative: true as const,\n payment: {\n connectedAccountId,\n currency: \"usd\" as const,\n publishableKey: payment.publishableKey,\n },\n paymentOption: parsedQuote.paymentOption,\n paymentReference,\n },\n };\n })\n);\n\nconst submitPaymentInputSchema = looseObject({\n checkout: preparedCheckoutInputSchema,\n submission: paymentSubmissionSchema,\n});\n\nconst paymentReferenceInputSchema = nonEmptyStringSchema;\nconst parseCatalogInputFields = parser(looseObject({}));\n\nexport type ParsedPreparedCheckoutInput = InferOutput<\n typeof preparedCheckoutInputSchema\n>;\nexport type ParsedLoadCheckoutInput = InferOutput<\n typeof loadCheckoutInputSchema\n>;\nexport type ParsedPaymentReferenceInput = InferOutput<\n typeof paymentReferenceInputSchema\n>;\nexport type ParsedSubmitPaymentInput = InferOutput<\n typeof submitPaymentInputSchema\n>;\n\nconst parseCalculateTotalInputFields = parser(calculateTotalInputSchema);\n\nexport function parseCalculateTotalInput<Input>(input: Input) {\n const { catalog, items, selection, ...pricingInput } =\n parseCalculateTotalInputFields(input);\n let parsedCatalog: ReturnType<typeof parseCatalogInputFields>;\n try {\n parsedCatalog = parseCatalogInputFields(catalog);\n } catch (error) {\n throw new TypeError(\"A catalog is required to calculate a checkout.\", {\n cause: error,\n });\n }\n try {\n return {\n catalog: parsedCatalog,\n items,\n pricing: parseCheckoutPricingInput(pricingInput),\n selection,\n };\n } catch (error) {\n throw new TypeError(\"Checkout pricing input is invalid.\", { cause: error });\n }\n}\n\nexport type ParsedCalculateTotalInput = ReturnType<\n typeof parseCalculateTotalInput\n>;\nexport type ParsedCheckoutPricingInput = InferOutput<\n typeof checkoutPricingInputSchema\n>;\n\nexport const parseLoadCheckoutInput = parser(loadCheckoutInputSchema);\nexport const parsePaymentReferenceInput = parser(paymentReferenceInputSchema);\nexport const parsePreparedCheckoutInput = parser(preparedCheckoutInputSchema);\nexport const parseSubmitPaymentInput = parser(submitPaymentInputSchema);\n\nexport const parseCheckoutSelectionItems = parser(checkoutSelectionItemsSchema);\n","import type { LockerverseProduct } from \"./types.ts\";\n\nconst minimumCustomAmountCents = 100;\n\nexport function getLockerverseMinimumCustomAmountCents(\n product: Pick<LockerverseProduct, \"minimumAmountCents\">\n) {\n return Math.max(minimumCustomAmountCents, product.minimumAmountCents ?? 0);\n}\n","import { parseCheckoutSelectionItems } from \"./checkout-input-schemas.ts\";\nimport { getLockerverseMinimumCustomAmountCents } from \"./custom-amount.ts\";\nimport type {\n LockerverseCatalog,\n LockerverseCheckoutItem,\n LockerverseCheckoutLineItem,\n LockerverseCheckoutSelectionItem,\n LockerverseProduct,\n} from \"./types.ts\";\nimport { LockerverseSdkError } from \"./types.ts\";\n\ntype ResolvedSelectionItem = {\n checkoutItem: LockerverseCheckoutItem;\n quantity: number;\n unitAmountCents: number;\n};\n\nexport function assertCheckoutItemsAreAvailable(\n catalog: LockerverseCatalog,\n items: LockerverseCheckoutItem[]\n) {\n const listingIdByProductId = new Map(\n catalog.products.map(({ id, listingId }) => [id, listingId])\n );\n const requestedByListingId = items.reduce((requested, item) => {\n const listingId = listingIdByProductId.get(item.productId);\n if (listingId) {\n requested.set(\n listingId,\n (requested.get(listingId) ?? 0) +\n (\"quantity\" in item ? (item.quantity ?? 1) : 1)\n );\n }\n return requested;\n }, new Map<string, number>());\n const listingIsSoldOut = catalog.availability.listings.some(\n ({ listingId, maxPurchasableQuantity, status }) =>\n requestedByListingId.has(listingId) &&\n (status === \"sold_out\" ||\n (maxPurchasableQuantity !== null &&\n (requestedByListingId.get(listingId) ?? 0) > maxPurchasableQuantity))\n );\n const sharedLimitIsSoldOut = catalog.availability.sharedLimits.some(\n ({ listingIds, remainingQuantity, status }) => {\n const requestedQuantity = listingIds.reduce(\n (total, listingId) =>\n total + (requestedByListingId.get(listingId) ?? 0),\n 0\n );\n return (\n requestedQuantity > 0 &&\n (status === \"sold_out\" || requestedQuantity > remainingQuantity)\n );\n }\n );\n if (listingIsSoldOut || sharedLimitIsSoldOut) {\n throw new LockerverseSdkError({\n code: \"total_calculation_failed\",\n message: \"This option is sold out.\",\n operation: \"calculate_total\",\n reportable: false,\n serverCode: \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\",\n });\n }\n}\n\nfunction resolveAmountItem(\n product: LockerverseProduct,\n amountCents: number\n): ResolvedSelectionItem {\n if (\n product.pricingMode !== \"custom\" ||\n product.paymentOption !== \"one-time\" ||\n amountCents < getLockerverseMinimumCustomAmountCents(product)\n ) {\n throw new TypeError(\"Selected Product amount is invalid.\");\n }\n return {\n checkoutItem: { amountCents, productId: product.id },\n quantity: 1,\n unitAmountCents: amountCents,\n };\n}\n\nfunction resolveFixedItem(\n product: LockerverseProduct,\n quantity: number\n): ResolvedSelectionItem {\n if (product.pricingMode !== \"fixed\" || product.amountCents === null) {\n throw new TypeError(\"Selected Product quantity is invalid.\");\n }\n if (product.paymentOption !== \"one-time\" && quantity !== 1) {\n throw new TypeError(\"Selected recurring Product is invalid.\");\n }\n if (\n (product.minimumQuantity !== null && quantity < product.minimumQuantity) ||\n (product.maximumQuantity !== null && quantity > product.maximumQuantity) ||\n (product.inventoryQuantity !== null && quantity > product.inventoryQuantity)\n ) {\n throw new TypeError(\"Selected Product quantity is invalid.\");\n }\n return {\n checkoutItem:\n product.paymentOption === \"one-time\"\n ? { productId: product.id, quantity }\n : { productId: product.id },\n quantity,\n unitAmountCents: product.amountCents,\n };\n}\n\nfunction resolveSelectionItem(\n catalog: LockerverseCatalog,\n product: LockerverseProduct,\n selection: LockerverseCheckoutSelectionItem\n) {\n const selectedQuantity = \"quantity\" in selection ? selection.quantity : 1;\n const resolved =\n \"amountCents\" in selection\n ? resolveAmountItem(product, selection.amountCents)\n : resolveFixedItem(product, selectedQuantity);\n const { checkoutItem, quantity, unitAmountCents } = resolved;\n\n return {\n checkoutItem,\n lineItem: {\n acceptsDiscounts: product.acceptsDiscounts,\n eventId:\n product.fulfillmentType === \"event_admission\" && catalog.event\n ? catalog.event.id\n : null,\n fulfillmentType: product.fulfillmentType,\n listingId: product.listingId,\n listingSlug: product.slug,\n paymentOption: product.paymentOption,\n pricingMode: product.pricingMode,\n productId: product.id,\n productName: product.name,\n quantity,\n subtotalCents: unitAmountCents * quantity,\n unitAmountCents,\n } satisfies LockerverseCheckoutLineItem,\n };\n}\n\nexport function resolveCheckoutSelection(\n catalog: LockerverseCatalog,\n input: LockerverseCheckoutSelectionItem[]\n) {\n const selection = parseCheckoutSelectionItems(input);\n const selectedProducts = new Set<string>();\n const resolved = selection.map((item) => {\n const product = catalog.products.find(\n (candidate) => candidate.slug === item.productSlug\n );\n if (!product) {\n throw new TypeError(\"Selected Product is unavailable.\");\n }\n if (selectedProducts.has(product.id)) {\n throw new TypeError(\"Each Product can appear only once per checkout.\");\n }\n selectedProducts.add(product.id);\n return resolveSelectionItem(catalog, product, item);\n });\n const paymentOption = resolved[0]?.lineItem.paymentOption;\n if (!paymentOption) {\n throw new TypeError(\"Select at least one Product.\");\n }\n if (\n resolved.length > 1 &&\n (paymentOption !== \"one-time\" ||\n resolved.some(({ lineItem }) => lineItem.paymentOption !== paymentOption))\n ) {\n throw new TypeError(\"Recurring Products must be purchased separately.\");\n }\n const items = resolved.map(({ checkoutItem }) => checkoutItem);\n assertCheckoutItemsAreAvailable(catalog, items);\n return {\n items,\n lineItems: resolved.map(({ lineItem }) => lineItem),\n paymentOption,\n };\n}\n","import type { PublicProductListing, PublicWidget } from \"./checkout-schemas.ts\";\nimport { deepFreeze } from \"./deep-freeze.ts\";\nimport type {\n LockerverseCatalog,\n LockerverseCommunityBranding,\n LockerversePaymentResult,\n LockerversePreparedCheckout,\n LockerverseProduct,\n} from \"./types.ts\";\n\nfunction mapProduct(listing: PublicProductListing): LockerverseProduct {\n const { product } = listing;\n\n return {\n acceptsDiscounts: listing.acceptsDiscounts ?? false,\n amountCents: product.amountCents,\n description: product.description ?? null,\n fulfillmentType: product.fulfillmentType,\n id: product.id,\n inventoryQuantity: product.inventoryQuantity,\n listingId: listing.id,\n maximumQuantity: product.maxQuantity,\n minimumAmountCents: product.minimumAmountCents,\n minimumQuantity: product.minQuantity,\n name: product.name,\n paymentOption: product.paymentOption,\n pricingMode: product.pricingMode,\n slug: listing.slug,\n };\n}\n\nfunction mapCommunity(\n community: PublicWidget[\"community\"]\n): LockerverseCommunityBranding | null {\n if (!community) {\n return null;\n }\n const branding: LockerverseCommunityBranding = {\n accentColor: community.color,\n imageUrl: community.thumbnail || null,\n name: community.name,\n };\n if (community.memberIdLabel !== undefined) {\n branding.memberIdLabel = community.memberIdLabel;\n }\n return branding;\n}\n\nexport function createCatalog(widget: PublicWidget): LockerverseCatalog {\n const fields = widget.config?.fields ?? {};\n\n return {\n availability: widget.availability,\n community: mapCommunity(widget.community),\n event: widget.event\n ? {\n description: widget.event.description,\n endAt: widget.event.endAt,\n id: widget.event.id,\n location: widget.event.location,\n name: widget.event.name,\n startAt: widget.event.startAt,\n status: widget.event.status,\n }\n : null,\n payment: {\n connectedAccountId: widget.payment.connectedAccountId,\n currency: widget.payment.currency,\n publishableKey: widget.payment.publishableKey,\n },\n pricingPolicy: {\n currency: \"usd\",\n serviceFeeRateBasisPoints:\n widget.pricingPolicy?.serviceFeeRateBasisPoints ?? 0,\n },\n products: (widget.products ?? []).map(mapProduct),\n widget: {\n customFields: widget.config?.customFields ?? [],\n description: widget.description ?? null,\n fields: {\n memberId: fields.memberId ?? false,\n merchSize: fields.merchSize ?? false,\n phone: fields.phone ?? false,\n promoCode: fields.promoCode ?? false,\n serviceFee: fields.serviceFee ?? false,\n shipping: fields.shipping ?? false,\n tipping: fields.tipping ?? false,\n },\n id: widget.id ?? \"\",\n name: widget.name ?? \"Lockerverse widget\",\n showCommunityBranding: widget.showCommunityBranding ?? true,\n title: widget.title ?? null,\n },\n };\n}\n\nexport function cloneCatalog(catalog: LockerverseCatalog): LockerverseCatalog {\n return cloneSnapshot(catalog);\n}\n\nexport function clonePreparedCheckout(\n checkout: LockerversePreparedCheckout\n): LockerversePreparedCheckout {\n return cloneSnapshot(checkout);\n}\n\nexport function clonePaymentResult(\n paymentResult: LockerversePaymentResult\n): LockerversePaymentResult {\n return cloneSnapshot(paymentResult);\n}\n\nfunction cloneSnapshot<T>(value: T): T {\n return deepFreeze(structuredClone(value));\n}\n","import { object, picklist, safeParse } from \"valibot\";\nimport { resolveWidgetEnvironment } from \"./checkout-environment.ts\";\nimport {\n type ParsedCalculateTotalInput,\n type ParsedCheckoutPricingInput,\n parseCalculateTotalInput,\n parseLoadCheckoutInput,\n parsePaymentReferenceInput,\n parseSubmitPaymentInput,\n} from \"./checkout-input-schemas.ts\";\nimport {\n parseCatalog,\n parseCheckoutQuote,\n parsePaymentResult,\n parsePublicWidgetLoad,\n} from \"./checkout-schemas.ts\";\nimport {\n assertCheckoutItemsAreAvailable,\n resolveCheckoutSelection,\n} from \"./checkout-selection.ts\";\nimport { deepFreeze } from \"./deep-freeze.ts\";\nimport { createSdkErrorReporter } from \"./error-reporting.ts\";\nimport {\n cloneCatalog,\n clonePaymentResult,\n clonePreparedCheckout,\n createCatalog,\n} from \"./snapshots.ts\";\nimport { createTransport } from \"./transport.ts\";\nimport {\n type CreateLockerverseWidgetOptions,\n type LockerverseCalculateTotalInput,\n type LockerverseCatalog,\n type LockerverseCheckoutClient,\n type LockerverseCheckoutItem,\n type LockerverseCheckoutPricingInput,\n type LockerverseCheckoutSelectionItem,\n type LockerverseLoadCheckoutInput,\n type LockerverseLoadedCheckout,\n type LockerversePreparedCheckout,\n LockerverseSdkError,\n type LockerverseSdkOperation,\n type LockerverseSdkServerCode,\n type LockerverseSubmitPaymentInput,\n} from \"./types.ts\";\n\ntype OperationErrorContext = {\n code:\n | \"payment_status_failed\"\n | \"payment_submit_failed\"\n | \"total_calculation_failed\"\n | \"widget_load_failed\";\n message: string;\n operation:\n | \"calculate_total\"\n | \"get_payment_status\"\n | \"load_widget\"\n | \"submit_payment\";\n};\n\nconst MAX_SELECTED_WIDGET_URL_LENGTH = 4000;\nconst paymentServerErrorSchema = object({\n code: picklist([\n \"PAYMENT_WIDGET_PHONE_INVALID\",\n \"PAYMENT_WIDGET_PHONE_REQUIRED\",\n \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\",\n ]),\n});\n\nasync function readPaymentServerCode(\n response: Response\n): Promise<LockerverseSdkServerCode | undefined> {\n if (response.status !== 400 && response.status !== 409) {\n return;\n }\n try {\n const result = safeParse(paymentServerErrorSchema, await response.json());\n return result.success ? result.output.code : undefined;\n } catch {\n // Non-JSON error bodies do not contain a safe server code.\n }\n}\n\nfunction resolveCalculateTotalItems({\n catalog,\n items,\n selection,\n}: ParsedCalculateTotalInput) {\n if (items !== undefined && selection !== undefined) {\n throw new TypeError(\"Use items or selection, not both.\");\n }\n const selectionCatalog = cloneCatalog(parseCatalog(catalog));\n const checkoutItems =\n selection === undefined\n ? requireCheckoutItems(items)\n : resolveCheckoutSelection(selectionCatalog, selection).items;\n assertCheckoutItemsAreAvailable(selectionCatalog, checkoutItems);\n return {\n catalog: selectionCatalog,\n items: checkoutItems,\n };\n}\n\nfunction requireCheckoutItems(\n items: ParsedCalculateTotalInput[\"items\"]\n): LockerverseCheckoutItem[] {\n if (items === undefined) {\n throw new TypeError(\"Checkout selection is invalid.\");\n }\n return items;\n}\n\nexport function createLockerverseCheckoutClient(\n options: CreateLockerverseWidgetOptions\n): LockerverseCheckoutClient {\n const {\n apiBaseUrl,\n communitySlug,\n communitySlugValue,\n environment,\n fetchImplementation,\n onError,\n requestTimeoutMs,\n sentryDsn,\n widgetSlug,\n widgetSlugValue,\n } = resolveWidgetEnvironment(options);\n const reportError = createSdkErrorReporter({\n communitySlug: communitySlugValue,\n environment,\n getContext: () => ({ widgetSlug: widgetSlugValue }),\n onError,\n resourceContextName: \"lockerverse_widget\",\n sentryDsn,\n });\n const { requestJson } = createTransport(\n fetchImplementation,\n reportError,\n requestTimeoutMs\n );\n const checkoutBaseUrl = `${apiBaseUrl}/v2/community/${communitySlug}/payment-widgets/${widgetSlug}/checkout`;\n const widgetUrl = `${apiBaseUrl}/v2/community/${communitySlug}/payment-widgets/${widgetSlug}`;\n\n function invalidInput(\n message: string,\n operation: LockerverseSdkOperation,\n code: \"invalid_selection\" | \"payment_submit_failed\" = \"invalid_selection\"\n ): never {\n throw reportError(\n new LockerverseSdkError({\n code,\n message,\n operation,\n reportable: false,\n })\n );\n }\n\n function normalizeOperationError<ErrorValue>(\n error: ErrorValue,\n context: OperationErrorContext\n ) {\n return error instanceof LockerverseSdkError\n ? error\n : new LockerverseSdkError({ ...context, reportable: true });\n }\n\n function failOperation<ErrorValue>(\n error: ErrorValue,\n context: OperationErrorContext,\n recoveryMayBeRequired = false\n ): never {\n const normalized = normalizeOperationError(error, context);\n const recoveryRecommended =\n recoveryMayBeRequired &&\n (normalized.status === undefined || normalized.status >= 500);\n if (!recoveryRecommended) {\n throw reportError(normalized);\n }\n const recoveryError =\n normalized.status === undefined\n ? new LockerverseSdkError({\n code: normalized.code,\n message: normalized.message,\n operation: normalized.operation,\n recoveryRecommended: true,\n reportable: normalized.reportable,\n })\n : new LockerverseSdkError({\n code: normalized.code,\n message: normalized.message,\n operation: normalized.operation,\n recoveryRecommended: true,\n reportable: normalized.reportable,\n status: normalized.status,\n });\n throw reportError(recoveryError);\n }\n\n function normalizePricingInput(input: ParsedCheckoutPricingInput) {\n const email = input.email?.trim().toLowerCase();\n const promoCode = input.promoCode?.trim();\n const pricing: LockerverseCheckoutPricingInput = {};\n if (email) {\n pricing.email = email;\n }\n if (input.includeServiceFee !== undefined) {\n pricing.includeServiceFee = input.includeServiceFee;\n }\n if (promoCode) {\n pricing.promoCode = promoCode;\n }\n if (input.tipCents !== undefined) {\n pricing.tipCents = input.tipCents;\n }\n return pricing;\n }\n\n function normalizeLoadSelection(input: LockerverseLoadCheckoutInput) {\n try {\n return parseLoadCheckoutInput(input).selection;\n } catch {\n invalidInput(\"Checkout selection is invalid.\", \"load_widget\");\n }\n }\n\n function createPreparedCheckout(\n quote: ReturnType<typeof parseCheckoutQuote>,\n items: LockerverseCheckoutItem[],\n pricing: LockerverseCheckoutPricingInput,\n payment: LockerverseCatalog[\"payment\"]\n ): LockerversePreparedCheckout {\n const { connectedAccountId, ...checkoutQuote } = quote;\n return clonePreparedCheckout(\n deepFreeze({\n ...checkoutQuote,\n authoritative: true as const,\n items,\n payment: {\n connectedAccountId,\n currency: \"usd\" as const,\n publishableKey: payment.publishableKey,\n },\n paymentOption: quote.paymentOption,\n paymentReference: globalThis.crypto.randomUUID(),\n pricing,\n })\n );\n }\n\n function resolveSelectedCheckoutItems(\n catalog: LockerverseCatalog,\n selection: LockerverseCheckoutSelectionItem[],\n operation: LockerverseSdkOperation\n ) {\n try {\n return resolveCheckoutSelection(catalog, selection).items;\n } catch (error) {\n if (error instanceof TypeError) {\n invalidInput(error.message, operation);\n }\n throw error;\n }\n }\n\n function createSelectedCheckout(\n catalog: LockerverseCatalog,\n selection: LockerverseCheckoutSelectionItem[],\n quote: ReturnType<typeof parseCheckoutQuote> | undefined,\n context: OperationErrorContext\n ) {\n if (!quote) {\n throw new LockerverseSdkError({\n ...context,\n message: \"Lockerverse did not return the requested initial quote.\",\n reportable: true,\n });\n }\n const checkoutItems = resolveSelectedCheckoutItems(\n catalog,\n selection,\n context.operation\n );\n return deepFreeze({\n catalog: cloneCatalog(catalog),\n checkout: createPreparedCheckout(\n quote,\n checkoutItems,\n { includeServiceFee: catalog.widget.fields.serviceFee },\n catalog.payment\n ),\n });\n }\n\n function requestWidgetResource(): Promise<LockerverseCatalog>;\n function requestWidgetResource(\n selection: LockerverseCheckoutSelectionItem[]\n ): Promise<LockerverseLoadedCheckout>;\n async function requestWidgetResource(\n selection?: LockerverseCheckoutSelectionItem[]\n ): Promise<LockerverseCatalog | LockerverseLoadedCheckout> {\n const context = {\n code: \"widget_load_failed\" as const,\n message: \"Lockerverse returned an invalid widget catalog.\",\n operation: \"load_widget\" as const,\n };\n const requestUrl = selection\n ? `${widgetUrl}?selection=${encodeURIComponent(JSON.stringify(selection))}`\n : widgetUrl;\n const response = await requestJson(\n requestUrl,\n selection ? { cache: \"no-store\" } : undefined,\n parsePublicWidgetLoad,\n {\n ...context,\n message:\n \"Unable to load Lockerverse widget because the request failed.\",\n report: false,\n },\n { ...context, report: false }\n );\n if (!response.ok) {\n const serverCode = await readPaymentServerCode(response.response);\n if (serverCode === \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\") {\n throw new LockerverseSdkError({\n ...context,\n message: \"This option is sold out.\",\n reportable: false,\n serverCode,\n status: response.response.status,\n });\n }\n throw new LockerverseSdkError({\n ...context,\n message: `Unable to load Lockerverse widget (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n const catalog = deepFreeze(createCatalog(response.value.widget));\n if (!selection) {\n return cloneCatalog(catalog);\n }\n return createSelectedCheckout(\n catalog,\n selection,\n response.value.quote,\n context\n );\n }\n\n async function loadLargeSelection(\n selection: LockerverseCheckoutSelectionItem[],\n context: OperationErrorContext\n ): Promise<LockerverseLoadedCheckout> {\n const loaded = await requestWidgetResource();\n const pricing = {\n includeServiceFee: loaded.widget.fields.serviceFee,\n };\n const items = resolveSelectedCheckoutItems(\n loaded,\n selection,\n context.operation\n );\n return deepFreeze({\n catalog: loaded,\n checkout: await requestCheckoutQuote(\n items,\n pricing,\n loaded.payment,\n context\n ),\n });\n }\n\n async function loadWidget(\n selection?: LockerverseCheckoutSelectionItem[]\n ): Promise<LockerverseCatalog | LockerverseLoadedCheckout> {\n const context = {\n code: \"widget_load_failed\" as const,\n message: \"Lockerverse returned an invalid widget catalog.\",\n operation: \"load_widget\" as const,\n };\n try {\n if (\n selection &&\n `${widgetUrl}?selection=${encodeURIComponent(JSON.stringify(selection))}`\n .length > MAX_SELECTED_WIDGET_URL_LENGTH\n ) {\n return await loadLargeSelection(selection, context);\n }\n return selection\n ? await requestWidgetResource(selection)\n : await requestWidgetResource();\n } catch (error) {\n failOperation(error, context);\n }\n }\n\n function load(): Promise<LockerverseCatalog>;\n function load(\n input: LockerverseLoadCheckoutInput\n ): Promise<LockerverseLoadedCheckout>;\n function load(input?: LockerverseLoadCheckoutInput) {\n return input === undefined\n ? loadWidget()\n : loadWidget(normalizeLoadSelection(input));\n }\n\n async function requestCheckoutQuote(\n items: LockerverseCheckoutItem[],\n pricing: LockerverseCheckoutPricingInput,\n payment: LockerverseCatalog[\"payment\"],\n context: OperationErrorContext\n ) {\n const response = await requestJson(\n `${checkoutBaseUrl}/quote`,\n {\n body: JSON.stringify({ ...pricing, items }),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"POST\",\n },\n parseCheckoutQuote,\n {\n ...context,\n message:\n \"Unable to calculate the Lockerverse checkout total because the request failed.\",\n report: false,\n },\n { ...context, report: false }\n );\n if (!response.ok) {\n const serverCode = await readPaymentServerCode(response.response);\n if (serverCode === \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\") {\n throw new LockerverseSdkError({\n ...context,\n message: \"This option is sold out.\",\n reportable: false,\n serverCode,\n status: response.response.status,\n });\n }\n throw new LockerverseSdkError({\n ...context,\n message: `Unable to calculate the Lockerverse checkout total (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n return createPreparedCheckout(response.value, items, pricing, payment);\n }\n\n async function calculateTotal(input: LockerverseCalculateTotalInput) {\n const { catalog, items, pricing } = normalizeCalculateTotalInput(input);\n const context = {\n code: \"total_calculation_failed\" as const,\n message: \"Lockerverse returned an invalid checkout total.\",\n operation: \"calculate_total\" as const,\n };\n try {\n return await requestCheckoutQuote(\n items,\n pricing,\n catalog.payment,\n context\n );\n } catch (error) {\n failOperation(error, context);\n }\n }\n\n function normalizeCalculateTotalInput(input: LockerverseCalculateTotalInput) {\n try {\n const parsed = parseCalculateTotalInput(input);\n const resolved = resolveCalculateTotalItems(parsed);\n const pricing = normalizePricingInput(parsed.pricing);\n return {\n catalog: resolved.catalog,\n items: resolved.items,\n pricing:\n pricing.includeServiceFee === undefined\n ? {\n ...pricing,\n includeServiceFee: resolved.catalog.widget.fields.serviceFee,\n }\n : pricing,\n };\n } catch (error) {\n if (error instanceof LockerverseSdkError) {\n throw error;\n }\n invalidInput(\n error instanceof TypeError\n ? error.message\n : \"Checkout selection is invalid.\",\n \"calculate_total\"\n );\n }\n }\n\n function normalizeSubmitPaymentInput(input: LockerverseSubmitPaymentInput) {\n try {\n const parsed = parseSubmitPaymentInput(input);\n const {\n items,\n pricing: pricingInput,\n quote: quoteInput,\n } = parsed.checkout;\n const pricing = normalizePricingInput(pricingInput);\n const quote = deepFreeze(quoteInput);\n const { submission } = parsed;\n if (quote.totalCents > 0 && !submission.confirmationToken) {\n invalidInput(\n \"Stripe confirmation is required for a paid checkout.\",\n \"submit_payment\",\n \"payment_submit_failed\"\n );\n }\n const email = submission.email.trim().toLowerCase();\n if (!email || email !== pricing.email) {\n invalidInput(\n \"Payment email must match the current checkout quote.\",\n \"submit_payment\"\n );\n }\n return {\n items,\n pricing,\n quote,\n submission: { ...submission, email },\n };\n } catch (error) {\n if (error instanceof LockerverseSdkError) {\n throw error;\n }\n invalidInput(\n \"Lockerverse payment submission is invalid.\",\n \"submit_payment\",\n \"payment_submit_failed\"\n );\n }\n }\n\n return {\n calculateTotal,\n async getPaymentStatus(paymentReference) {\n let normalizedReference: string;\n try {\n normalizedReference =\n parsePaymentReferenceInput(paymentReference).trim();\n } catch {\n invalidInput(\n \"Provide a payment reference to recover its status.\",\n \"get_payment_status\"\n );\n }\n const context = {\n code: \"payment_status_failed\" as const,\n message: \"Lockerverse returned an invalid payment status.\",\n operation: \"get_payment_status\" as const,\n };\n try {\n const response = await requestJson(\n `${checkoutBaseUrl}/${encodeURIComponent(normalizedReference)}/status`,\n undefined,\n parsePaymentResult,\n {\n ...context,\n message:\n \"Unable to recover the Lockerverse payment status because the request failed.\",\n report: false,\n },\n { ...context, report: false }\n );\n if (!response.ok) {\n throw new LockerverseSdkError({\n ...context,\n message: `Unable to recover the Lockerverse payment status (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n if (response.value.paymentReference !== normalizedReference) {\n throw new LockerverseSdkError({ ...context, reportable: true });\n }\n return clonePaymentResult(response.value);\n } catch (error) {\n failOperation(error, context);\n }\n },\n load,\n async submitPayment(input) {\n const { items, pricing, quote, submission } =\n normalizeSubmitPaymentInput(input);\n const context = {\n code: \"payment_submit_failed\" as const,\n message: \"Lockerverse returned an invalid payment confirmation.\",\n operation: \"submit_payment\" as const,\n };\n try {\n const response = await requestJson(\n `${checkoutBaseUrl}/confirm`,\n {\n body: JSON.stringify({\n confirmationToken: submission.confirmationToken,\n customFieldAnswers: submission.customFieldAnswers,\n email: submission.email,\n expectedAmountCents: quote.amountCents,\n expectedAppliedDiscount: quote.appliedDiscount,\n expectedConnectedAccountId: quote.payment.connectedAccountId,\n expectedDiscountableSubtotalCents:\n quote.discountableSubtotalCents,\n expectedDiscountCents: quote.discountCents,\n expectedServiceFeeCents: quote.serviceFeeCents,\n expectedSubtotalCents: quote.subtotalCents,\n expectedTipCents: quote.tipCents,\n expectedTotalCents: quote.totalCents,\n ...pricing,\n items,\n memberId: submission.memberId,\n merchSize: submission.merchSize,\n metadata: submission.metadata,\n paymentReference: quote.paymentReference,\n phone: submission.phone,\n quoteContractVersion: 1,\n shipping: submission.shipping,\n }),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"POST\",\n },\n parsePaymentResult,\n {\n ...context,\n message:\n \"Unable to submit the Lockerverse payment because the request failed.\",\n report: false,\n },\n { ...context, report: false }\n );\n if (!response.ok) {\n const serverCode = await readPaymentServerCode(response.response);\n if (serverCode) {\n throw new LockerverseSdkError({\n ...context,\n message:\n serverCode === \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\"\n ? \"This option is sold out.\"\n : `Unable to submit the Lockerverse payment (${response.response.status}).`,\n reportable: false,\n serverCode,\n status: response.response.status,\n });\n }\n throw new LockerverseSdkError({\n ...context,\n message: `Unable to submit the Lockerverse payment (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n if (response.value.paymentReference !== quote.paymentReference) {\n throw new LockerverseSdkError({ ...context, reportable: true });\n }\n return clonePaymentResult(response.value);\n } catch (error) {\n failOperation(error, context, true);\n }\n },\n };\n}\n","import { parseCheckoutPricingInput } from \"./checkout-input-schemas.ts\";\nimport { resolveCheckoutSelection } from \"./checkout-selection.ts\";\nimport { deepFreeze } from \"./deep-freeze.ts\";\nimport type {\n LockerverseCatalog,\n LockerverseCheckoutEstimate,\n LockerverseEstimateCheckoutInput,\n} from \"./types.ts\";\n\nexport function estimateLockerverseCheckout(\n catalog: LockerverseCatalog,\n input: LockerverseEstimateCheckoutInput\n): LockerverseCheckoutEstimate {\n const { selection, ...pricingInput } = input;\n let pricing: ReturnType<typeof parseCheckoutPricingInput>;\n try {\n pricing = parseCheckoutPricingInput(pricingInput);\n } catch (error) {\n throw new TypeError(\"Checkout pricing is invalid.\", { cause: error });\n }\n const includeServiceFee =\n pricing.includeServiceFee ?? catalog.widget.fields.serviceFee;\n const { tipCents = 0 } = pricing;\n const { items, lineItems, paymentOption } = resolveCheckoutSelection(\n catalog,\n selection\n );\n const subtotalCents = lineItems.reduce(\n (total, lineItem) => total + lineItem.subtotalCents,\n 0\n );\n if (\n !Number.isSafeInteger(subtotalCents) ||\n subtotalCents <= 0 ||\n subtotalCents > 2_147_483_647\n ) {\n throw new TypeError(\"Checkout total is invalid.\");\n }\n const discountableSubtotalCents = lineItems.reduce(\n (total, lineItem) =>\n total + (lineItem.acceptsDiscounts ? lineItem.subtotalCents : 0),\n 0\n );\n const serviceFeeCents = includeServiceFee\n ? Math.round(\n (subtotalCents * catalog.pricingPolicy.serviceFeeRateBasisPoints) /\n 10_000\n )\n : 0;\n const amountCents = subtotalCents + serviceFeeCents;\n const totalCents = amountCents + tipCents;\n if (!Number.isSafeInteger(totalCents) || totalCents > 2_147_483_647) {\n throw new TypeError(\"Checkout total is invalid.\");\n }\n\n return deepFreeze({\n amountCents,\n appliedDiscount: null,\n authoritative: false,\n discountableSubtotalCents,\n discountCents: 0,\n items,\n lineItems,\n paymentOption,\n serviceFeeCents,\n subtotalCents,\n tipCents,\n totalCents,\n });\n}\n"],"mappings":"sfAGA,SAAgB,GACd,EACA,CACA,IAAM,EAAU,EAA2B,EAAS,YAAY,EAChE,M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W,GAAG,GAAiB,EACnC,EACJ,GAAI,CACF,EAAU,EAA0B,CAAY,CAClD,OAAS,EAAO,CACd,MAAU,UAAU,+BAAgC,CAAE,MAAO,CAAM,CAAC,CACtE,CACA,IAAM,EACJ,EAAQ,mBAAqB,EAAQ,OAAO,OAAO,WAC/C,CAAE,WAAW,GAAM,EACnB,CAAE,QAAO,YAAW,iBAAkB,EAC1C,EACA,CACF,EACM,EAAgB,EAAU,QAC7B,EAAO,IAAa,EAAQ,EAAS,cACtC,CACF,EACA,GACE,CAAC,OAAO,cAAc,CAAa,GACnC,GAAiB,GACjB,EAAgB,WAEhB,MAAU,UAAU,4BAA4B,EAElD,IAAM,EAA4B,EAAU,QACzC,EAAO,IACN,GAAS,EAAS,iBAAmB,EAAS,cAAgB,GAChE,CACF,EACM,EAAkB,EACpB,KAAK,MACF,EAAgB,EAAQ,cAAc,0BACrC,GACJ,EACA,EACE,EAAc,EAAgB,EAC9B,EAAa,EAAc,EACjC,GAAI,CAAC,OAAO,cAAc,CAAU,GAAK,EAAa,WACpD,MAAU,UAAU,4BAA4B,EAGlD,OAAO,EAAW,CAChB,cACA,gBAAiB,KACjB,cAAe,GACf,4BACA,cAAe,EACf,QACA,YACA,gBACA,kBACA,gBACA,WACA,YACF,CAAC,CACH"}
package/dist/types.d.ts CHANGED
@@ -55,6 +55,7 @@ type LockerverseEvent = {
55
55
  type LockerverseCommunityBranding = {
56
56
  accentColor: string;
57
57
  imageUrl: string | null;
58
+ memberIdLabel?: string | null | undefined;
58
59
  name: string;
59
60
  };
60
61
  type LockerverseCheckoutPricingPolicy = {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";KAGY;KACA;KACA;cAEC;KAED;EACV;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA,eAAe;EACf;EACA;EACA;EACA;EACA;EACA;;KAGU;KAEA;EACV,UAAU;IACR;IACA;IACA;IACA,QAAQ;;EAEV,cAAc;IACZ;IACA;IACA;IACA,QAAQ;;;KAIA;EACV,cAAc;EACd,WAAW;EACX,OAAO;EACP,SAAS;EACT,eAAe;EACf,UAAU;EACV,QAAQ;;KAGE;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU;EACV;EACA;EACA;;KAGU;EACV;EACA;;KAGU;EACV;EACA;EACA;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU;EAAiC;EAAY;;KAEpD;EACH;EACA;EACA;;KAGU,6BAA6B;EACvC;;KAGU,gCAAgC;EAC1C;;KAGU,qCAAqC;EAC/C,SAAS;EACT;;KAGU,oCAAoC;EAC9C,SAAS;EACT;;KAGU,yBACR,gCACA,6BACA,qCACA;KAEQ,kCACV,cAAc,0BACZ,cAAc,0CAEd,cAAc;KAIN,6BACV,cAAc,yBAAyB,0BACrC,cAAc;EACZ,SAAS;EAAa,OAAO,kCAAkC;;KAGzD;EACV,cAAc;EACd;EACA,QAAQ;EACR;EACA;EACA;EACA;;KAGU;KASA;KAQA;cAOC,4BAA4B;WAC9B,MAAM;WACN,WAAW;WACX;WACA;WACA;WACA,YAAY;WACZ;EAEG,cACV,MACA,SACA,WACA,YACA,qBACA,YACA;IAEA,MAAM;IACN;IACA,WAAW;IACX;IACA;IACA,aAAa;IACb;;;KAcQ;EACV;EACA;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA,eAAe;EACf;EACA;EACA;;KAGU;EACV;EACA;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU,2BAA2B;EACrC,iBAAiB;EACjB;EACA;EACA,SAAS;EACT,eAAe;EACf,WAAW;;KAGD,8BAA8B;EACxC;EACA;EACA,gBAAgB;EAChB,oBAAoB;EACpB,eAAe;;KAGL;EACV;EACA;EACA;EACA;;KAGU;KAMA;EACV;EACA;EACA,gBAAgB;EAChB;EACA;EACA;EACA;;KAGU,+BAA+B;EACzC;EACA,oBAAoB;;KAYV;EACV;IACE;IACA;IACA;IACA;IACA;IACA;;EAEF;;KAGU;EACV;EACA,qBAAqB;EACrB;EACA;EACA;EACA,WAAW;EACX;EACA,WAAW;;KAGD;EACN;EAAmB;;EACnB;EAAmB;;EACnB;;KAEM;EACN;EAAqB;;EACrB;EAAqB;;EACrB;;KAEM,mCACV;EACE,WAAW;;KAGH;EACV,WAAW;;KAGD,iCAAiC;EAC3C,SAAS;;EAGH,OAAO;EACP;;EAGA;EACA,WAAW;;KAIP,8BAA8B,SACxC;EACE,gBAAgB;EAChB,SAAS,SAAS;;KAIV,4BAA4B;EACtC,SAAS;EACT,UAAU;;KAGA;EACV,UAAU;EACV,YAAY;;KAGT;EACH;EACA,eAAe,WAAW;EAC1B,WAAW,OAAO;EAClB;EACA;EACA;;KAGU;EAEN;EACA,aAAa;;EAGb;EACA;;KAGM,iCACV,qCAAqC;KAE3B;EACV,iBACE,OAAO,mCACJ,QAAQ;EACb,mBACE,6BACG,QAAQ;EACb;QACM,QAAQ;KACX,OAAO,+BAA+B,QAAQ;;EAEjD,gBACE,OAAO,kCACJ,QAAQ"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";KAGY;KACA;KACA;cAEC;KAED;EACV;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA,eAAe;EACf;EACA;EACA;EACA;EACA;EACA;;KAGU;KAEA;EACV,UAAU;IACR;IACA;IACA;IACA,QAAQ;;EAEV,cAAc;IACZ;IACA;IACA;IACA,QAAQ;;;KAIA;EACV,cAAc;EACd,WAAW;EACX,OAAO;EACP,SAAS;EACT,eAAe;EACf,UAAU;EACV,QAAQ;;KAGE;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU;EACV;EACA;EACA;EACA;;KAGU;EACV;EACA;;KAGU;EACV;EACA;EACA;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU;EAAiC;EAAY;;KAEpD;EACH;EACA;EACA;;KAGU,6BAA6B;EACvC;;KAGU,gCAAgC;EAC1C;;KAGU,qCAAqC;EAC/C,SAAS;EACT;;KAGU,oCAAoC;EAC9C,SAAS;EACT;;KAGU,yBACR,gCACA,6BACA,qCACA;KAEQ,kCACV,cAAc,0BACZ,cAAc,0CAEd,cAAc;KAIN,6BACV,cAAc,yBAAyB,0BACrC,cAAc;EACZ,SAAS;EAAa,OAAO,kCAAkC;;KAGzD;EACV,cAAc;EACd;EACA,QAAQ;EACR;EACA;EACA;EACA;;KAGU;KASA;KAQA;cAOC,4BAA4B;WAC9B,MAAM;WACN,WAAW;WACX;WACA;WACA;WACA,YAAY;WACZ;EAEG,cACV,MACA,SACA,WACA,YACA,qBACA,YACA;IAEA,MAAM;IACN;IACA,WAAW;IACX;IACA;IACA,aAAa;IACb;;;KAcQ;EACV;EACA;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA,eAAe;EACf;EACA;EACA;;KAGU;EACV;EACA;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU,2BAA2B;EACrC,iBAAiB;EACjB;EACA;EACA,SAAS;EACT,eAAe;EACf,WAAW;;KAGD,8BAA8B;EACxC;EACA;EACA,gBAAgB;EAChB,oBAAoB;EACpB,eAAe;;KAGL;EACV;EACA;EACA;EACA;;KAGU;KAMA;EACV;EACA;EACA,gBAAgB;EAChB;EACA;EACA;EACA;;KAGU,+BAA+B;EACzC;EACA,oBAAoB;;KAYV;EACV;IACE;IACA;IACA;IACA;IACA;IACA;;EAEF;;KAGU;EACV;EACA,qBAAqB;EACrB;EACA;EACA;EACA,WAAW;EACX;EACA,WAAW;;KAGD;EACN;EAAmB;;EACnB;EAAmB;;EACnB;;KAEM;EACN;EAAqB;;EACrB;EAAqB;;EACrB;;KAEM,mCACV;EACE,WAAW;;KAGH;EACV,WAAW;;KAGD,iCAAiC;EAC3C,SAAS;;EAGH,OAAO;EACP;;EAGA;EACA,WAAW;;KAIP,8BAA8B,SACxC;EACE,gBAAgB;EAChB,SAAS,SAAS;;KAIV,4BAA4B;EACtC,SAAS;EACT,UAAU;;KAGA;EACV,UAAU;EACV,YAAY;;KAGT;EACH;EACA,eAAe,WAAW;EAC1B,WAAW,OAAO;EAClB;EACA;EACA;;KAGU;EAEN;EACA,aAAa;;EAGb;EACA;;KAGM,iCACV,qCAAqC;KAE3B;EACV,iBACE,OAAO,mCACJ,QAAQ;EACb,mBACE,6BACG,QAAQ;EACb;QACM,QAAQ;KACX,OAAO,+BAA+B,QAAQ;;EAEjD,gBACE,OAAO,kCACJ,QAAQ"}
package/dist/types.js CHANGED
@@ -1,2 +1,2 @@
1
- const e=`0.2.97`;var t=class extends Error{code;operation;reportable;recoveryRecommended;sdkVersion;serverCode;status;constructor({code:t,message:n,operation:r,reportable:i,recoveryRecommended:a=!1,serverCode:o,status:s}){super(n),this.name=`LockerverseSdkError`,this.code=t,this.operation=r,this.reportable=i,this.recoveryRecommended=a,this.sdkVersion=e,this.serverCode=o,this.status=s}};export{t as n,e as t};
1
+ const e=`0.2.99`;var t=class extends Error{code;operation;reportable;recoveryRecommended;sdkVersion;serverCode;status;constructor({code:t,message:n,operation:r,reportable:i,recoveryRecommended:a=!1,serverCode:o,status:s}){super(n),this.name=`LockerverseSdkError`,this.code=t,this.operation=r,this.reportable=i,this.recoveryRecommended=a,this.sdkVersion=e,this.serverCode=o,this.status=s}};export{t as n,e as t};
2
2
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":["packageMetadata.version"],"sources":["../package.json","../src/types.ts"],"sourcesContent":["","import packageMetadata from \"../package.json\" with { type: \"json\" };\nimport type { GeneratedPaymentResult } from \"./generated/public-contract-types.ts\";\n\nexport type LockerversePaymentOption = \"one-time\" | \"monthly\" | \"annually\";\nexport type LockerverseEnvironment = \"development\" | \"production\";\nexport type LockerverseFulfillmentType = \"none\" | \"event_admission\";\n\nexport const LOCKERVERSE_SDK_VERSION = packageMetadata.version;\n\nexport type LockerverseProduct = {\n id: string;\n listingId: string;\n slug: string;\n name: string;\n description: string | null;\n fulfillmentType: LockerverseFulfillmentType;\n pricingMode: \"fixed\" | \"custom\";\n paymentOption: LockerversePaymentOption;\n amountCents: number | null;\n minimumAmountCents: number | null;\n minimumQuantity: number | null;\n maximumQuantity: number | null;\n inventoryQuantity: number | null;\n acceptsDiscounts: boolean;\n};\n\nexport type LockerverseAvailabilityStatus = \"available\" | \"sold_out\";\n\nexport type LockerverseCatalogAvailability = {\n listings: Array<{\n listingId: string;\n maxPurchasableQuantity: number | null;\n remainingQuantity: number | null;\n status: LockerverseAvailabilityStatus;\n }>;\n sharedLimits: Array<{\n id: string;\n listingIds: string[];\n remainingQuantity: number;\n status: LockerverseAvailabilityStatus;\n }>;\n};\n\nexport type LockerverseCatalog = {\n availability: LockerverseCatalogAvailability;\n community: LockerverseCommunityBranding | null;\n event: LockerverseEvent | null;\n payment: LockerversePaymentConfiguration;\n pricingPolicy: LockerverseCheckoutPricingPolicy;\n products: LockerverseProduct[];\n widget: LockerverseWidgetConfiguration;\n};\n\nexport type LockerverseEvent = {\n description: string | null;\n endAt: string;\n id: string;\n location: string | null;\n name: string;\n startAt: string;\n status: \"draft\" | \"active\" | \"finished\" | \"cancelled\";\n};\n\nexport type LockerverseCommunityBranding = {\n accentColor: string;\n imageUrl: string | null;\n name: string;\n};\n\nexport type LockerverseCheckoutPricingPolicy = {\n currency: \"usd\";\n serviceFeeRateBasisPoints: number;\n};\n\nexport type LockerversePaymentConfiguration = {\n connectedAccountId: string | null;\n currency: \"usd\";\n publishableKey: string;\n};\n\nexport type LockerverseWidgetFields = {\n memberId: boolean;\n merchSize: boolean;\n phone: boolean;\n promoCode: boolean;\n serviceFee: boolean;\n shipping: boolean;\n tipping: boolean;\n};\n\nexport type LockerverseCustomFieldOption = { id: string; label: string };\n\ntype LockerverseCustomFieldBase = {\n id: string;\n label: string;\n required: boolean;\n};\n\nexport type LockerverseTextCustomField = LockerverseCustomFieldBase & {\n type: \"text\" | \"textarea\";\n};\n\nexport type LockerverseBooleanCustomField = LockerverseCustomFieldBase & {\n type: \"checkbox\";\n};\n\nexport type LockerverseSingleOptionCustomField = LockerverseCustomFieldBase & {\n options: LockerverseCustomFieldOption[];\n type: \"radio\" | \"select\";\n};\n\nexport type LockerverseMultiOptionCustomField = LockerverseCustomFieldBase & {\n options: LockerverseCustomFieldOption[];\n type: \"checkboxes\" | \"multi_select\";\n};\n\nexport type LockerverseCustomField =\n | LockerverseBooleanCustomField\n | LockerverseTextCustomField\n | LockerverseSingleOptionCustomField\n | LockerverseMultiOptionCustomField;\n\nexport type LockerverseCustomFieldAnswerValue<\n Field extends LockerverseCustomField,\n> = Field extends LockerverseBooleanCustomField\n ? boolean\n : Field extends LockerverseMultiOptionCustomField\n ? string[]\n : string;\n\nexport type LockerverseCustomFieldAnswer<\n Field extends LockerverseCustomField = LockerverseCustomField,\n> = Field extends LockerverseCustomField\n ? { fieldId: Field[\"id\"]; value: LockerverseCustomFieldAnswerValue<Field> }\n : never;\n\nexport type LockerverseWidgetConfiguration = {\n customFields: LockerverseCustomField[];\n description: string | null;\n fields: LockerverseWidgetFields;\n id: string;\n name: string;\n showCommunityBranding: boolean;\n title: string | null;\n};\n\nexport type LockerverseSdkErrorCode =\n | \"widget_load_failed\"\n | \"signup_load_failed\"\n | \"signup_submit_failed\"\n | \"total_calculation_failed\"\n | \"payment_submit_failed\"\n | \"payment_status_failed\"\n | \"invalid_selection\";\n\nexport type LockerverseSdkOperation =\n | \"load_widget\"\n | \"load_signup\"\n | \"submit_signup\"\n | \"calculate_total\"\n | \"submit_payment\"\n | \"get_payment_status\";\n\nexport type LockerverseSdkServerCode =\n | \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\"\n | \"PAYMENT_WIDGET_PHONE_INVALID\"\n | \"PAYMENT_WIDGET_PHONE_REQUIRED\"\n | \"SIGN_UP_WIDGET_PHONE_INVALID\"\n | \"SIGN_UP_WIDGET_PHONE_REQUIRED\";\n\nexport class LockerverseSdkError extends Error {\n readonly code: LockerverseSdkErrorCode;\n readonly operation: LockerverseSdkOperation;\n readonly reportable: boolean;\n readonly recoveryRecommended: boolean;\n readonly sdkVersion: string;\n readonly serverCode: LockerverseSdkServerCode | undefined;\n readonly status: number | undefined;\n\n constructor({\n code,\n message,\n operation,\n reportable,\n recoveryRecommended = false,\n serverCode,\n status,\n }: {\n code: LockerverseSdkErrorCode;\n message: string;\n operation: LockerverseSdkOperation;\n reportable: boolean;\n recoveryRecommended?: boolean;\n serverCode?: LockerverseSdkServerCode;\n status?: number;\n }) {\n super(message);\n this.name = \"LockerverseSdkError\";\n this.code = code;\n this.operation = operation;\n this.reportable = reportable;\n this.recoveryRecommended = recoveryRecommended;\n this.sdkVersion = LOCKERVERSE_SDK_VERSION;\n this.serverCode = serverCode;\n this.status = status;\n }\n}\n\nexport type LockerverseCheckoutLineItem = {\n productId: string;\n productName: string;\n listingId: string;\n listingSlug: string;\n acceptsDiscounts: boolean;\n eventId: string | null;\n fulfillmentType: LockerverseFulfillmentType;\n pricingMode: \"fixed\" | \"custom\";\n paymentOption: LockerversePaymentOption;\n quantity: number;\n unitAmountCents: number;\n subtotalCents: number;\n};\n\nexport type LockerverseAppliedDiscount = {\n percentageOff: number;\n source: \"email_list\" | \"promo_code\";\n};\n\nexport type LockerverseCheckoutAmounts = {\n amountCents: number;\n discountableSubtotalCents: number;\n discountCents: number;\n serviceFeeCents: number;\n subtotalCents: number;\n tipCents: number;\n totalCents: number;\n};\n\nexport type LockerverseCheckoutQuote = LockerverseCheckoutAmounts & {\n appliedDiscount: LockerverseAppliedDiscount | null;\n authoritative: true;\n paymentReference: string;\n payment: LockerversePaymentConfiguration;\n paymentOption: LockerversePaymentOption;\n lineItems: LockerverseCheckoutLineItem[];\n};\n\nexport type LockerverseCheckoutEstimate = LockerverseCheckoutAmounts & {\n appliedDiscount: null;\n authoritative: false;\n items: readonly LockerverseCheckoutItem[];\n lineItems: readonly LockerverseCheckoutLineItem[];\n paymentOption: LockerversePaymentOption;\n};\n\nexport type LockerverseCheckoutPricingInput = {\n email?: string;\n includeServiceFee?: boolean;\n promoCode?: string;\n tipCents?: number;\n};\n\nexport type LockerversePaymentStatus =\n | \"action_required\"\n | \"failed\"\n | \"pending\"\n | \"success\";\n\nexport type LockerversePaymentResult = {\n checkoutId: string;\n paymentReference: string;\n checkoutStatus: LockerversePaymentStatus;\n clientSecret: string | null;\n paymentRequired: boolean;\n requiresAction: boolean;\n status: string | null;\n};\n\nexport type LockerversePaymentCompletion = LockerversePaymentResult & {\n email: string | null;\n lineItems: readonly LockerverseCheckoutLineItem[] | null;\n};\n\ntype AssertPaymentContract<T extends true> = T;\ntype _PaymentResultMatchesGenerated = AssertPaymentContract<\n LockerversePaymentResult extends GeneratedPaymentResult\n ? GeneratedPaymentResult extends LockerversePaymentResult\n ? true\n : false\n : false\n>;\n\nexport type LockerverseShipping = {\n address: {\n city: string;\n country: string;\n line1: string;\n line2?: string;\n postal_code: string;\n state: string;\n };\n name: string;\n};\n\nexport type LockerversePaymentSubmission = {\n confirmationToken?: string;\n customFieldAnswers?: LockerverseCustomFieldAnswer[];\n email: string;\n memberId?: string;\n merchSize?: \"XS\" | \"S\" | \"M\" | \"L\" | \"XL\" | \"XXL\" | \"XXXL\";\n metadata?: Record<string, string>;\n phone?: string;\n shipping?: LockerverseShipping;\n};\n\nexport type LockerverseCheckoutItem =\n | { productId: string; quantity: number }\n | { productId: string; amountCents: number }\n | { productId: string };\n\nexport type LockerverseCheckoutSelectionItem =\n | { productSlug: string; quantity: number }\n | { productSlug: string; amountCents: number }\n | { productSlug: string };\n\nexport type LockerverseEstimateCheckoutInput =\n LockerverseCheckoutPricingInput & {\n selection: LockerverseCheckoutSelectionItem[];\n };\n\nexport type LockerverseLoadCheckoutInput = {\n selection: LockerverseCheckoutSelectionItem[];\n};\n\nexport type LockerverseCalculateTotalInput = LockerverseCheckoutPricingInput & {\n catalog: LockerverseCatalog;\n} & (\n | {\n items: LockerverseCheckoutItem[];\n selection?: never;\n }\n | {\n items?: never;\n selection: LockerverseCheckoutSelectionItem[];\n }\n );\n\nexport type LockerversePreparedCheckout = Readonly<\n LockerverseCheckoutQuote & {\n items: readonly LockerverseCheckoutItem[];\n pricing: Readonly<LockerverseCheckoutPricingInput>;\n }\n>;\n\nexport type LockerverseLoadedCheckout = Readonly<{\n catalog: LockerverseCatalog;\n checkout: LockerversePreparedCheckout;\n}>;\n\nexport type LockerverseSubmitPaymentInput = {\n checkout: LockerversePreparedCheckout;\n submission: LockerversePaymentSubmission;\n};\n\ntype CreateLockerverseWidgetBaseOptions = {\n communitySlug: string;\n fetch?: typeof globalThis.fetch;\n onError?: (error: LockerverseSdkError) => void;\n requestTimeoutMs?: number;\n sentryDsn?: string | null;\n widgetSlug: string;\n};\n\nexport type LockerverseResourceEnvironmentOptions =\n | {\n apiBaseUrl: string;\n environment: LockerverseEnvironment;\n }\n | {\n apiBaseUrl?: undefined;\n environment?: \"production\";\n };\n\nexport type CreateLockerverseWidgetOptions =\n CreateLockerverseWidgetBaseOptions & LockerverseResourceEnvironmentOptions;\n\nexport type LockerverseCheckoutClient = {\n calculateTotal: (\n input: LockerverseCalculateTotalInput\n ) => Promise<LockerversePreparedCheckout>;\n getPaymentStatus: (\n paymentReference: string\n ) => Promise<LockerversePaymentResult>;\n load: {\n (): Promise<LockerverseCatalog>;\n (input: LockerverseLoadCheckoutInput): Promise<LockerverseLoadedCheckout>;\n };\n submitPayment: (\n input: LockerverseSubmitPaymentInput\n ) => Promise<LockerversePaymentResult>;\n};\n"],"mappings":"ACOA,MAAa,EAA0BA,SAmKvC,IAAa,EAAb,cAAyC,KAAM,CAC7C,KACA,UACA,WACA,oBACA,WACA,WACA,OAEA,YAAY,CACV,OACA,UACA,YACA,aACA,sBAAsB,GACtB,aACA,UASC,CACD,MAAM,CAAO,EACb,KAAK,KAAO,sBACZ,KAAK,KAAO,EACZ,KAAK,UAAY,EACjB,KAAK,WAAa,EAClB,KAAK,oBAAsB,EAC3B,KAAK,WAAa,EAClB,KAAK,WAAa,EAClB,KAAK,OAAS,CAChB,CACF"}
1
+ {"version":3,"file":"types.js","names":["packageMetadata.version"],"sources":["../package.json","../src/types.ts"],"sourcesContent":["","import packageMetadata from \"../package.json\" with { type: \"json\" };\nimport type { GeneratedPaymentResult } from \"./generated/public-contract-types.ts\";\n\nexport type LockerversePaymentOption = \"one-time\" | \"monthly\" | \"annually\";\nexport type LockerverseEnvironment = \"development\" | \"production\";\nexport type LockerverseFulfillmentType = \"none\" | \"event_admission\";\n\nexport const LOCKERVERSE_SDK_VERSION = packageMetadata.version;\n\nexport type LockerverseProduct = {\n id: string;\n listingId: string;\n slug: string;\n name: string;\n description: string | null;\n fulfillmentType: LockerverseFulfillmentType;\n pricingMode: \"fixed\" | \"custom\";\n paymentOption: LockerversePaymentOption;\n amountCents: number | null;\n minimumAmountCents: number | null;\n minimumQuantity: number | null;\n maximumQuantity: number | null;\n inventoryQuantity: number | null;\n acceptsDiscounts: boolean;\n};\n\nexport type LockerverseAvailabilityStatus = \"available\" | \"sold_out\";\n\nexport type LockerverseCatalogAvailability = {\n listings: Array<{\n listingId: string;\n maxPurchasableQuantity: number | null;\n remainingQuantity: number | null;\n status: LockerverseAvailabilityStatus;\n }>;\n sharedLimits: Array<{\n id: string;\n listingIds: string[];\n remainingQuantity: number;\n status: LockerverseAvailabilityStatus;\n }>;\n};\n\nexport type LockerverseCatalog = {\n availability: LockerverseCatalogAvailability;\n community: LockerverseCommunityBranding | null;\n event: LockerverseEvent | null;\n payment: LockerversePaymentConfiguration;\n pricingPolicy: LockerverseCheckoutPricingPolicy;\n products: LockerverseProduct[];\n widget: LockerverseWidgetConfiguration;\n};\n\nexport type LockerverseEvent = {\n description: string | null;\n endAt: string;\n id: string;\n location: string | null;\n name: string;\n startAt: string;\n status: \"draft\" | \"active\" | \"finished\" | \"cancelled\";\n};\n\nexport type LockerverseCommunityBranding = {\n accentColor: string;\n imageUrl: string | null;\n memberIdLabel?: string | null | undefined;\n name: string;\n};\n\nexport type LockerverseCheckoutPricingPolicy = {\n currency: \"usd\";\n serviceFeeRateBasisPoints: number;\n};\n\nexport type LockerversePaymentConfiguration = {\n connectedAccountId: string | null;\n currency: \"usd\";\n publishableKey: string;\n};\n\nexport type LockerverseWidgetFields = {\n memberId: boolean;\n merchSize: boolean;\n phone: boolean;\n promoCode: boolean;\n serviceFee: boolean;\n shipping: boolean;\n tipping: boolean;\n};\n\nexport type LockerverseCustomFieldOption = { id: string; label: string };\n\ntype LockerverseCustomFieldBase = {\n id: string;\n label: string;\n required: boolean;\n};\n\nexport type LockerverseTextCustomField = LockerverseCustomFieldBase & {\n type: \"text\" | \"textarea\";\n};\n\nexport type LockerverseBooleanCustomField = LockerverseCustomFieldBase & {\n type: \"checkbox\";\n};\n\nexport type LockerverseSingleOptionCustomField = LockerverseCustomFieldBase & {\n options: LockerverseCustomFieldOption[];\n type: \"radio\" | \"select\";\n};\n\nexport type LockerverseMultiOptionCustomField = LockerverseCustomFieldBase & {\n options: LockerverseCustomFieldOption[];\n type: \"checkboxes\" | \"multi_select\";\n};\n\nexport type LockerverseCustomField =\n | LockerverseBooleanCustomField\n | LockerverseTextCustomField\n | LockerverseSingleOptionCustomField\n | LockerverseMultiOptionCustomField;\n\nexport type LockerverseCustomFieldAnswerValue<\n Field extends LockerverseCustomField,\n> = Field extends LockerverseBooleanCustomField\n ? boolean\n : Field extends LockerverseMultiOptionCustomField\n ? string[]\n : string;\n\nexport type LockerverseCustomFieldAnswer<\n Field extends LockerverseCustomField = LockerverseCustomField,\n> = Field extends LockerverseCustomField\n ? { fieldId: Field[\"id\"]; value: LockerverseCustomFieldAnswerValue<Field> }\n : never;\n\nexport type LockerverseWidgetConfiguration = {\n customFields: LockerverseCustomField[];\n description: string | null;\n fields: LockerverseWidgetFields;\n id: string;\n name: string;\n showCommunityBranding: boolean;\n title: string | null;\n};\n\nexport type LockerverseSdkErrorCode =\n | \"widget_load_failed\"\n | \"signup_load_failed\"\n | \"signup_submit_failed\"\n | \"total_calculation_failed\"\n | \"payment_submit_failed\"\n | \"payment_status_failed\"\n | \"invalid_selection\";\n\nexport type LockerverseSdkOperation =\n | \"load_widget\"\n | \"load_signup\"\n | \"submit_signup\"\n | \"calculate_total\"\n | \"submit_payment\"\n | \"get_payment_status\";\n\nexport type LockerverseSdkServerCode =\n | \"PAYMENT_WIDGET_SALES_LIMIT_REACHED\"\n | \"PAYMENT_WIDGET_PHONE_INVALID\"\n | \"PAYMENT_WIDGET_PHONE_REQUIRED\"\n | \"SIGN_UP_WIDGET_PHONE_INVALID\"\n | \"SIGN_UP_WIDGET_PHONE_REQUIRED\";\n\nexport class LockerverseSdkError extends Error {\n readonly code: LockerverseSdkErrorCode;\n readonly operation: LockerverseSdkOperation;\n readonly reportable: boolean;\n readonly recoveryRecommended: boolean;\n readonly sdkVersion: string;\n readonly serverCode: LockerverseSdkServerCode | undefined;\n readonly status: number | undefined;\n\n constructor({\n code,\n message,\n operation,\n reportable,\n recoveryRecommended = false,\n serverCode,\n status,\n }: {\n code: LockerverseSdkErrorCode;\n message: string;\n operation: LockerverseSdkOperation;\n reportable: boolean;\n recoveryRecommended?: boolean;\n serverCode?: LockerverseSdkServerCode;\n status?: number;\n }) {\n super(message);\n this.name = \"LockerverseSdkError\";\n this.code = code;\n this.operation = operation;\n this.reportable = reportable;\n this.recoveryRecommended = recoveryRecommended;\n this.sdkVersion = LOCKERVERSE_SDK_VERSION;\n this.serverCode = serverCode;\n this.status = status;\n }\n}\n\nexport type LockerverseCheckoutLineItem = {\n productId: string;\n productName: string;\n listingId: string;\n listingSlug: string;\n acceptsDiscounts: boolean;\n eventId: string | null;\n fulfillmentType: LockerverseFulfillmentType;\n pricingMode: \"fixed\" | \"custom\";\n paymentOption: LockerversePaymentOption;\n quantity: number;\n unitAmountCents: number;\n subtotalCents: number;\n};\n\nexport type LockerverseAppliedDiscount = {\n percentageOff: number;\n source: \"email_list\" | \"promo_code\";\n};\n\nexport type LockerverseCheckoutAmounts = {\n amountCents: number;\n discountableSubtotalCents: number;\n discountCents: number;\n serviceFeeCents: number;\n subtotalCents: number;\n tipCents: number;\n totalCents: number;\n};\n\nexport type LockerverseCheckoutQuote = LockerverseCheckoutAmounts & {\n appliedDiscount: LockerverseAppliedDiscount | null;\n authoritative: true;\n paymentReference: string;\n payment: LockerversePaymentConfiguration;\n paymentOption: LockerversePaymentOption;\n lineItems: LockerverseCheckoutLineItem[];\n};\n\nexport type LockerverseCheckoutEstimate = LockerverseCheckoutAmounts & {\n appliedDiscount: null;\n authoritative: false;\n items: readonly LockerverseCheckoutItem[];\n lineItems: readonly LockerverseCheckoutLineItem[];\n paymentOption: LockerversePaymentOption;\n};\n\nexport type LockerverseCheckoutPricingInput = {\n email?: string;\n includeServiceFee?: boolean;\n promoCode?: string;\n tipCents?: number;\n};\n\nexport type LockerversePaymentStatus =\n | \"action_required\"\n | \"failed\"\n | \"pending\"\n | \"success\";\n\nexport type LockerversePaymentResult = {\n checkoutId: string;\n paymentReference: string;\n checkoutStatus: LockerversePaymentStatus;\n clientSecret: string | null;\n paymentRequired: boolean;\n requiresAction: boolean;\n status: string | null;\n};\n\nexport type LockerversePaymentCompletion = LockerversePaymentResult & {\n email: string | null;\n lineItems: readonly LockerverseCheckoutLineItem[] | null;\n};\n\ntype AssertPaymentContract<T extends true> = T;\ntype _PaymentResultMatchesGenerated = AssertPaymentContract<\n LockerversePaymentResult extends GeneratedPaymentResult\n ? GeneratedPaymentResult extends LockerversePaymentResult\n ? true\n : false\n : false\n>;\n\nexport type LockerverseShipping = {\n address: {\n city: string;\n country: string;\n line1: string;\n line2?: string;\n postal_code: string;\n state: string;\n };\n name: string;\n};\n\nexport type LockerversePaymentSubmission = {\n confirmationToken?: string;\n customFieldAnswers?: LockerverseCustomFieldAnswer[];\n email: string;\n memberId?: string;\n merchSize?: \"XS\" | \"S\" | \"M\" | \"L\" | \"XL\" | \"XXL\" | \"XXXL\";\n metadata?: Record<string, string>;\n phone?: string;\n shipping?: LockerverseShipping;\n};\n\nexport type LockerverseCheckoutItem =\n | { productId: string; quantity: number }\n | { productId: string; amountCents: number }\n | { productId: string };\n\nexport type LockerverseCheckoutSelectionItem =\n | { productSlug: string; quantity: number }\n | { productSlug: string; amountCents: number }\n | { productSlug: string };\n\nexport type LockerverseEstimateCheckoutInput =\n LockerverseCheckoutPricingInput & {\n selection: LockerverseCheckoutSelectionItem[];\n };\n\nexport type LockerverseLoadCheckoutInput = {\n selection: LockerverseCheckoutSelectionItem[];\n};\n\nexport type LockerverseCalculateTotalInput = LockerverseCheckoutPricingInput & {\n catalog: LockerverseCatalog;\n} & (\n | {\n items: LockerverseCheckoutItem[];\n selection?: never;\n }\n | {\n items?: never;\n selection: LockerverseCheckoutSelectionItem[];\n }\n );\n\nexport type LockerversePreparedCheckout = Readonly<\n LockerverseCheckoutQuote & {\n items: readonly LockerverseCheckoutItem[];\n pricing: Readonly<LockerverseCheckoutPricingInput>;\n }\n>;\n\nexport type LockerverseLoadedCheckout = Readonly<{\n catalog: LockerverseCatalog;\n checkout: LockerversePreparedCheckout;\n}>;\n\nexport type LockerverseSubmitPaymentInput = {\n checkout: LockerversePreparedCheckout;\n submission: LockerversePaymentSubmission;\n};\n\ntype CreateLockerverseWidgetBaseOptions = {\n communitySlug: string;\n fetch?: typeof globalThis.fetch;\n onError?: (error: LockerverseSdkError) => void;\n requestTimeoutMs?: number;\n sentryDsn?: string | null;\n widgetSlug: string;\n};\n\nexport type LockerverseResourceEnvironmentOptions =\n | {\n apiBaseUrl: string;\n environment: LockerverseEnvironment;\n }\n | {\n apiBaseUrl?: undefined;\n environment?: \"production\";\n };\n\nexport type CreateLockerverseWidgetOptions =\n CreateLockerverseWidgetBaseOptions & LockerverseResourceEnvironmentOptions;\n\nexport type LockerverseCheckoutClient = {\n calculateTotal: (\n input: LockerverseCalculateTotalInput\n ) => Promise<LockerversePreparedCheckout>;\n getPaymentStatus: (\n paymentReference: string\n ) => Promise<LockerversePaymentResult>;\n load: {\n (): Promise<LockerverseCatalog>;\n (input: LockerverseLoadCheckoutInput): Promise<LockerverseLoadedCheckout>;\n };\n submitPayment: (\n input: LockerverseSubmitPaymentInput\n ) => Promise<LockerversePaymentResult>;\n};\n"],"mappings":"ACOA,MAAa,EAA0BA,SAoKvC,IAAa,EAAb,cAAyC,KAAM,CAC7C,KACA,UACA,WACA,oBACA,WACA,WACA,OAEA,YAAY,CACV,OACA,UACA,YACA,aACA,sBAAsB,GACtB,aACA,UASC,CACD,MAAM,CAAO,EACb,KAAK,KAAO,sBACZ,KAAK,KAAO,EACZ,KAAK,UAAY,EACjB,KAAK,WAAa,EAClB,KAAK,oBAAsB,EAC3B,KAAK,WAAa,EAClB,KAAK,WAAa,EAClB,KAAK,OAAS,CAChB,CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lockerverse/sdk",
3
- "version": "0.2.97",
3
+ "version": "0.2.99",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Lockerverse/lockerverse-sdk.git",