@lockerverse/sdk 0.2.185 → 0.2.190-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/MIGRATIONS.md CHANGED
@@ -36,6 +36,19 @@ If it cannot be found, report that limit and use the baseline review below. Do n
36
36
  claim that every historical migration was applied. Read this file even if the
37
37
  version already matches: a previous upgrade may have missed host adoption steps.
38
38
 
39
+ ## 0.2.190-dev.1 — widget load recovery and Sentry releases
40
+
41
+ - **Affected:** Core widget loading and SDK failure reporting.
42
+ - **Automatic:** a widget GET retries once after a network failure or request
43
+ timeout, with a full timeout for each attempt. Invalid responses, cancellation,
44
+ HTTP errors, and payment submissions do not retry. Only the final failure is
45
+ reported. Errors expose the safe optional `failureKind` field; Sentry receives
46
+ `sdk.failure_kind` and a valid `lockerverse-sdk@<version>` release name.
47
+ - **Required host changes:** upgrade Core and React together and deploy the host.
48
+ No integration code changes are required.
49
+ - **Check:** interrupt the first widget request and confirm that the second loads
50
+ the widget. Check the final failure classification and Sentry release association.
51
+
39
52
  ## 0.2.185 — shipping for additional items
40
53
 
41
54
  - **Affected:** Core checkout estimates and the React donation launcher.
@@ -50,6 +63,7 @@ version already matches: a previous upgrade may have missed host adoption steps.
50
63
  - **Check:** select one, two, and the maximum allowed trigger quantity. Confirm the
51
64
  local summary and server quote agree; removing all trigger items removes shipping.
52
65
 
66
+
53
67
  ## 0.2.184 — single focus boundary for form fields
54
68
 
55
69
  - **Affected:** React form controls and the shared phone field in payment and signup.
@@ -69,7 +83,7 @@ Widgets can now use a private contact list for email eligibility, a fixed amount
69
83
  Required shipping appears in `catalog.widget.requiredShipping`. Do not offer this product as a separate shopper choice. The SDK adds its quantity once when a trigger product is selected; the server also enforces this rule. Render authoritative quote line items and totals, including shipping. The built-in launcher and payment summary handle this automatically.
70
84
 
71
85
 
72
- ## 0.2.177 — Secure checkout loading recovery
86
+ ## 0.2.176-dev.1 — Secure checkout loading recovery
73
87
 
74
88
  - **Affected:** React payment widget Stripe fields.
75
89
  - **Automatic:** failed field or script loads show a reload action. Fields that
@@ -81,9 +95,23 @@ Required shipping appears in `catalog.widget.requiredShipping`. Do not offer thi
81
95
  - Reload is an explicit customer action and can clear unsaved form entries.
82
96
  Saved payment recovery remains in session storage.
83
97
 
84
-
85
98
  ## 0.2.175 — Match Stripe Elements payment method configuration
86
99
 
100
+ - **Affected:** Core checkout submission and React payment widgets.
101
+ - **Automatic:** React configures explicit card, Link, and community-enabled bank
102
+ methods in Stripe Elements and marks the confirmation request with
103
+ `paymentMethodConfiguration: "explicit"`. This matches the backend's Stripe
104
+ PaymentIntent configuration.
105
+ - **Required:** deploy the backend that supports this optional marker before
106
+ upgrading React. Keep Core and React matched. Existing Core-only callers omit
107
+ the marker and retain automatic payment methods. Custom Elements integrations
108
+ must send the marker only when they use the explicit method list.
109
+ - **Check:** submit card and bank payments through Stripe Elements in test mode,
110
+ including recurring checkout. Confirm pending recovery and settlement.
111
+
112
+
113
+ ## 0.2.174-dev.1 — Match Stripe Elements payment method configuration
114
+
87
115
  - **Affected:** Core checkout submission and React payment widgets.
88
116
  - **Automatic:** React configures explicit card, Link, and community-enabled bank
89
117
  methods in Stripe Elements and marks the confirmation request with
@@ -157,7 +185,39 @@ Required shipping appears in `catalog.widget.requiredShipping`. Do not offer thi
157
185
  verify a changed selection cannot discard it. Check both paid and free order
158
186
  confirmation panels. Do not submit a live transaction for this check.
159
187
 
160
- ## 0.2.170 — six-month payment widgets
188
+ ## 0.2.172-dev.1 — Check pending payment status
189
+
190
+ - **Affected:** React payment widgets with unresolved payments.
191
+ - **Automatic behavior:** the existing pending-payment screen now offers Check
192
+ payment status. It checks the saved payment reference and cannot submit a new
193
+ payment. The control is disabled while the check runs.
194
+ - **Required host changes:** none. Update Core and React together.
195
+ - **Verification:** complete a test bank payment, return to its pending checkout,
196
+ and check its status. Confirm completion clears recovery storage.
197
+
198
+ ## 0.2.171-dev.1 — SDK payment recovery and completion UI
199
+
200
+ - **Affected:** React payment widgets and custom hosts that persist payment recovery.
201
+ - **Optional adoption:** pass `recoveryStorageKey` to `LockerversePayment` to let
202
+ the SDK save and restore the pending payment in session storage. Use a stable
203
+ key scoped to the API environment, community, and widget. Remove the host's
204
+ storage code and recovery-driven component key. Do not combine automatic
205
+ persistence with a second host persistence writer.
206
+ - **Compatibility:** the SDK reads the hosted Next app's existing version 1
207
+ records when the same key is used. It writes version 2 records with widget
208
+ identity. It checks widget and selection identity before recovery and keeps
209
+ an unresolved record if those details differ. Recovery uses the saved connected
210
+ account even if current payment routing has changed. Storage is read after hydration,
211
+ before the payable form mounts. No contact details or payment tokens are saved.
212
+ - **Optional UI adoption:** use `completionView="summary"` for the SDK confirmation
213
+ panel and remove the host's duplicate success panel. Completion callbacks still
214
+ run. The default inline message and explicit `resumePayment` integrations remain
215
+ supported. Auctions and legacy custom checkout forms are unchanged.
216
+ - **Check:** reload a pending checkout and confirm the existing payment is checked;
217
+ verify a changed selection cannot discard it. Check both paid and free order
218
+ confirmation panels. Do not submit a live transaction for this check.
219
+
220
+ ## 0.2.169-dev.1 — six-month payment widgets
161
221
 
162
222
  Affected: @lockerverse/sdk checkout and @lockerverse/react payment widgets.
163
223
 
@@ -173,6 +233,31 @@ Affected: @lockerverse/sdk checkout and @lockerverse/react payment widgets.
173
233
  submission. Do not submit a live payment for an integration check.
174
234
 
175
235
 
236
+ ## 0.2.168-dev.1 — bank authorization terms
237
+
238
+ - **Affected:** React payment widgets with ACH enabled.
239
+ - **Automatic:** Stripe displays its bank authorization terms before payment confirmation.
240
+ - **Adoption:** update the matching SDK/React development pair. No prop changes are required.
241
+ - **Check:** confirm that the bank authorization text is visible when a bank account is selected.
242
+
243
+ ## 0.2.167-dev.1 — widget ACH and subscription payment recovery
244
+
245
+ - **Affected:** Core checkout data and React payment widgets.
246
+ - **Automatic:** bank payment availability follows the organization default and
247
+ community override returned by the backend. Missing policy remains disabled.
248
+ Pending payments keep their existing payment reference. A failed subscription
249
+ invoice can return `action_required` with `requiresAction: false` and `retryUrl`;
250
+ React shows a link to pay the same invoice instead of creating a second subscription.
251
+ - **Required for custom payment UI:** preserve the reference for pending and
252
+ action-required results. Handle `retryUrl` by opening that invoice, and recover
253
+ status before permitting a new checkout. Do not treat submission as settlement.
254
+ - **Adoption:** deploy the matching backend policy and recovery contract before
255
+ enabling ACH. Existing React hosts need no component prop changes. Keep Core and
256
+ React versions matched when upgrading. Auction payment methods are unchanged.
257
+ - **Check:** verify disabled/inherited/enabled bank visibility and pending, bank
258
+ verification, invoice retry, success, and terminal failure in Stripe test mode.
259
+ Do not create a live transaction for this check.
260
+
176
261
  ## 0.2.166 — single dropdown arrow
177
262
 
178
263
  - **Affected:** native single-select custom fields in React signup and payment forms.
@@ -1,4 +1,4 @@
1
- import { B as LockerverseSdkErrorCode, C as LockerverseEnvironment, H as LockerverseSdkServerCode, R as LockerverseResourceEnvironmentOptions, V as LockerverseSdkOperation, j as LockerversePaymentConfiguration, z as LockerverseSdkError } from "./types.js";
1
+ import { B as LockerverseSdkErrorCode, C as LockerverseEnvironment, H as LockerverseSdkOperation, R as LockerverseResourceEnvironmentOptions, U as LockerverseSdkServerCode, j as LockerversePaymentConfiguration, z as LockerverseSdkError } from "./types.js";
2
2
  //#region src/auction-types.d.ts
3
3
  type LockerverseAuctionStatus = "draft" | "active" | "finished";
4
4
  type LockerverseAuctionSaleMode = "auction" | "buy_now" | "hybrid";
@@ -1,4 +1,4 @@
1
- import { A as LockerversePaymentCompletion, B as LockerverseSdkErrorCode, C as LockerverseEnvironment, D as LockerverseLoadCheckoutInput, E as LockerverseFulfillmentType, F as LockerversePaymentSubmission, G as LockerverseSubmitPaymentInput, H as LockerverseSdkServerCode, I as LockerversePreparedCheckout, J as LockerverseWidgetFields, K as LockerverseTextCustomField, L as LockerverseProduct, M as LockerversePaymentOption, N as LockerversePaymentResult, O as LockerverseLoadedCheckout, P as LockerversePaymentStatus, R as LockerverseResourceEnvironmentOptions, S as LockerverseCustomFieldOption, T as LockerverseEvent, U as LockerverseShipping, V as LockerverseSdkOperation, W as LockerverseSingleOptionCustomField, _ as LockerverseCheckoutSelectionItem, a as LockerverseBooleanCustomField, b as LockerverseCustomFieldAnswer, c as LockerverseCatalogAvailability, d as LockerverseCheckoutEstimate, f as LockerverseCheckoutItem, g as LockerverseCheckoutQuote, h as LockerverseCheckoutPricingPolicy, i as LockerverseAvailabilityStatus, j as LockerversePaymentConfiguration, k as LockerverseMultiOptionCustomField, l as LockerverseCheckoutAmounts, m as LockerverseCheckoutPricingInput, n as LOCKERVERSE_SDK_VERSION, o as LockerverseCalculateTotalInput, p as LockerverseCheckoutLineItem, q as LockerverseWidgetConfiguration, r as LockerverseAppliedDiscount, s as LockerverseCatalog, t as CreateLockerverseWidgetOptions, u as LockerverseCheckoutClient, v as LockerverseCommunityBranding, w as LockerverseEstimateCheckoutInput, x as LockerverseCustomFieldAnswerValue, y as LockerverseCustomField, z as LockerverseSdkError } from "./types.js";
1
+ import { A as LockerversePaymentCompletion, B as LockerverseSdkErrorCode, C as LockerverseEnvironment, D as LockerverseLoadCheckoutInput, E as LockerverseFulfillmentType, F as LockerversePaymentSubmission, G as LockerverseSingleOptionCustomField, H as LockerverseSdkOperation, I as LockerversePreparedCheckout, J as LockerverseWidgetConfiguration, K as LockerverseSubmitPaymentInput, L as LockerverseProduct, M as LockerversePaymentOption, N as LockerversePaymentResult, O as LockerverseLoadedCheckout, P as LockerversePaymentStatus, R as LockerverseResourceEnvironmentOptions, S as LockerverseCustomFieldOption, T as LockerverseEvent, U as LockerverseSdkServerCode, V as LockerverseSdkFailureKind, W as LockerverseShipping, Y as LockerverseWidgetFields, _ as LockerverseCheckoutSelectionItem, a as LockerverseBooleanCustomField, b as LockerverseCustomFieldAnswer, c as LockerverseCatalogAvailability, d as LockerverseCheckoutEstimate, f as LockerverseCheckoutItem, g as LockerverseCheckoutQuote, h as LockerverseCheckoutPricingPolicy, i as LockerverseAvailabilityStatus, j as LockerversePaymentConfiguration, k as LockerverseMultiOptionCustomField, l as LockerverseCheckoutAmounts, m as LockerverseCheckoutPricingInput, n as LOCKERVERSE_SDK_VERSION, o as LockerverseCalculateTotalInput, p as LockerverseCheckoutLineItem, q as LockerverseTextCustomField, r as LockerverseAppliedDiscount, s as LockerverseCatalog, t as CreateLockerverseWidgetOptions, u as LockerverseCheckoutClient, v as LockerverseCommunityBranding, w as LockerverseEstimateCheckoutInput, x as LockerverseCustomFieldAnswerValue, y as LockerverseCustomField, z as LockerverseSdkError } from "./types.js";
2
2
  //#region src/checkout-client.d.ts
3
3
  declare function createLockerverseCheckoutClient(options: CreateLockerverseWidgetOptions): LockerverseCheckoutClient;
4
4
  //#endregion
@@ -8,5 +8,5 @@ declare function estimateLockerverseCheckout(catalog: LockerverseCatalog, input:
8
8
  //#region src/custom-amount.d.ts
9
9
  declare function getLockerverseMinimumCustomAmountCents(product: Pick<LockerverseProduct, "minimumAmountCents">): number;
10
10
  //#endregion
11
- export { CreateLockerverseWidgetOptions, LOCKERVERSE_SDK_VERSION, LockerverseAppliedDiscount, LockerverseAvailabilityStatus, LockerverseBooleanCustomField, LockerverseCalculateTotalInput, LockerverseCatalog, LockerverseCatalogAvailability, LockerverseCheckoutAmounts, LockerverseCheckoutClient, LockerverseCheckoutEstimate, LockerverseCheckoutItem, LockerverseCheckoutLineItem, LockerverseCheckoutPricingInput, LockerverseCheckoutPricingPolicy, LockerverseCheckoutQuote, LockerverseCheckoutSelectionItem, LockerverseCommunityBranding, LockerverseCustomField, LockerverseCustomFieldAnswer, LockerverseCustomFieldAnswerValue, LockerverseCustomFieldOption, LockerverseEnvironment, LockerverseEstimateCheckoutInput, LockerverseEvent, LockerverseFulfillmentType, LockerverseLoadCheckoutInput, LockerverseLoadedCheckout, LockerverseMultiOptionCustomField, LockerversePaymentCompletion, LockerversePaymentConfiguration, LockerversePaymentOption, LockerversePaymentResult, LockerversePaymentStatus, LockerversePaymentSubmission, LockerversePreparedCheckout, LockerverseProduct, LockerverseResourceEnvironmentOptions, LockerverseSdkError, LockerverseSdkErrorCode, LockerverseSdkOperation, LockerverseSdkServerCode, LockerverseShipping, LockerverseSingleOptionCustomField, LockerverseSubmitPaymentInput, LockerverseTextCustomField, LockerverseWidgetConfiguration, LockerverseWidgetFields, createLockerverseCheckoutClient, estimateLockerverseCheckout, getLockerverseMinimumCustomAmountCents };
11
+ export { CreateLockerverseWidgetOptions, LOCKERVERSE_SDK_VERSION, LockerverseAppliedDiscount, LockerverseAvailabilityStatus, LockerverseBooleanCustomField, LockerverseCalculateTotalInput, LockerverseCatalog, LockerverseCatalogAvailability, LockerverseCheckoutAmounts, LockerverseCheckoutClient, LockerverseCheckoutEstimate, LockerverseCheckoutItem, LockerverseCheckoutLineItem, LockerverseCheckoutPricingInput, LockerverseCheckoutPricingPolicy, LockerverseCheckoutQuote, LockerverseCheckoutSelectionItem, LockerverseCommunityBranding, LockerverseCustomField, LockerverseCustomFieldAnswer, LockerverseCustomFieldAnswerValue, LockerverseCustomFieldOption, LockerverseEnvironment, LockerverseEstimateCheckoutInput, LockerverseEvent, LockerverseFulfillmentType, LockerverseLoadCheckoutInput, LockerverseLoadedCheckout, LockerverseMultiOptionCustomField, LockerversePaymentCompletion, LockerversePaymentConfiguration, LockerversePaymentOption, LockerversePaymentResult, LockerversePaymentStatus, LockerversePaymentSubmission, LockerversePreparedCheckout, LockerverseProduct, LockerverseResourceEnvironmentOptions, LockerverseSdkError, LockerverseSdkErrorCode, LockerverseSdkFailureKind, LockerverseSdkOperation, LockerverseSdkServerCode, LockerverseShipping, LockerverseSingleOptionCustomField, LockerverseSubmitPaymentInput, LockerverseTextCustomField, LockerverseWidgetConfiguration, LockerverseWidgetFields, createLockerverseCheckoutClient, estimateLockerverseCheckout, getLockerverseMinimumCustomAmountCents };
12
12
  //# sourceMappingURL=checkout.d.ts.map
package/dist/checkout.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as e,i as t,n,r,t as i}from"./schema-helpers.js";import{i as a,n as o,o as s,t as c}from"./transport.js";import{n as l,t as u}from"./types.js";import{n as d,r as f,t as p}from"./valibot.gen.js";import{array as m,boolean as h,check as g,finite as _,literal as v,looseObject as y,maxValue as b,minLength as x,minValue as S,nullable as C,number as w,object as T,optional as E,parser as D,picklist as O,pipe as k,record as ee,regex as A,safeParse as j,strictObject as M,string as N,transform as P,union as F,unknown as I,variant as te}from"valibot";function ne(e){let t=a(e,`widgetSlug`);return{...t,widgetSlug:t.resourceSlug,widgetSlugValue:t.resourceSlugValue}}const L=O([`one-time`,`monthly`,`annually`,`every-six-months`]),R=O([`none`,`event_admission`]),z=C(e(0)),re=O([`available`,`sold_out`]),ie=E(T({listings:m(T({listingId:r,maxPurchasableQuantity:z,remainingQuantity:z,status:re})),sharedLimits:m(T({id:r,listingIds:m(r),remainingQuantity:e(0),status:re}))}),{listings:[],sharedLimits:[]}),ae=k(N(),A(/^pk_(?:test|live)_\S+$/,`Invalid publishable key.`)),B={description:t,fulfillmentType:R,id:r,inventoryQuantity:z,maxQuantity:z,minimumAmountCents:z,minQuantity:z,name:r,paymentOption:L},V=T({description:C(N()),endAt:r,id:r,location:C(N()),name:r,startAt:r,status:O([`draft`,`active`,`finished`,`cancelled`])}),oe=te(`pricingMode`,[T({...B,amountCents:e(0),pricingMode:v(`fixed`)}),T({...B,amountCents:z,pricingMode:v(`custom`)})]),se=T({acceptsDiscounts:E(h(),!1),id:r,maxQuantityPerOrder:E(z,null),product:oe,productId:r,slug:r}),H=E(T({memberId:E(h(),!1),merchSize:E(h(),!1),phone:E(h(),!1),promoCode:E(h(),!1),serviceFee:E(h(),!1),shipping:E(h(),!1),tipping:E(h(),!1)}),{}),U=E(T({additionalUnitAmountCents:E(k(e(0),b(2147483647))),productId:r,triggerProductIds:m(r)})),ce=k(T({availability:ie,community:E(T({color:N(),memberIdLabel:E(C(N())),name:r,thumbnail:C(N()),widgetAchEnabled:E(h())})),config:E(T({customFields:n,fields:H,requiredShipping:U})),description:t,event:C(V),id:E(N(),``),name:E(N(),`Lockerverse widget`),payment:T({connectedAccountId:E(C(r),null),currency:v(`usd`),publishableKey:ae}),pricingPolicy:E(T({currency:E(v(`usd`),`usd`),serviceFeeRateBasisPoints:E(e(0),0)})),products:E(m(se),[]),showCommunityBranding:E(h(),!0),title:t}),P(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},requiredShipping:e.config?.requiredShipping},pricingPolicy:e.pricingPolicy??{currency:`usd`,serviceFeeRateBasisPoints:0}}))),le=T({acceptsDiscounts:h(),amountCents:C(e(0)),description:C(N()),fulfillmentType:R,id:r,inventoryQuantity:z,listingId:r,maximumQuantity:z,minimumAmountCents:z,minimumQuantity:z,name:r,paymentOption:L,pricingMode:O([`fixed`,`custom`]),slug:r}),ue=T({availability:ie,community:C(T({accentColor:N(),imageUrl:C(N()),memberIdLabel:E(C(N())),name:r,widgetAchEnabled:E(h())})),event:C(V),payment:T({connectedAccountId:E(C(r),null),currency:v(`usd`),publishableKey:ae}),pricingPolicy:T({currency:v(`usd`),serviceFeeRateBasisPoints:e(0)}),products:m(le),widget:T({customFields:n,description:C(N()),fields:H,id:N(),name:r,requiredShipping:U,showCommunityBranding:h(),title:C(N())})}),de=C(T({amountOffCents:E(e(0)),message:E(N()),percentageOff:E(k(w(),_(),S(0),b(100))),source:O([`email_list`,`promo_code`])})),fe=T({acceptsDiscounts:h(),eventId:C(r),fulfillmentType:R,listingId:r,listingSlug:r,paymentOption:L,pricingMode:O([`fixed`,`custom`]),productId:r,productName:r,quantity:e(1),subtotalCents:e(0),unitAmountCents:e(0)}),pe=k(d,T({amountCents:e(0),appliedDiscount:de,connectedAccountId:C(r),discountableSubtotalCents:e(0),discountCents:e(0),lineItems:m(fe),paymentOption:L,serviceFeeCents:e(0),subtotalCents:e(0),tipCents:e(0),totalCents:e(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.`)),me=k(T({...p.entries,retryUrl:E(k(r,A(/^https:\/\//)))}),g(e=>e.checkoutId.trim()&&e.paymentReference.trim()?e.checkoutStatus===`action_required`?e.paymentRequired&&(e.requiresAction&&!!e.clientSecret?.trim()||!e.requiresAction&&e.clientSecret===null&&!!e.retryUrl):!e.requiresAction&&e.clientSecret===null:!1,`Invalid payment result state.`)),W=D(pe),he=D(ue),G=D(me),ge=D(f),_e=D(ce);function ve(e){return ge(e),_e(e)}function ye(e){let t=j(y({quote:E(I())}),e),n=ve(e),r=t.success?t.output.quote:void 0;return r===void 0?{widget:n}:{quote:W(r),widget:n}}const be={email:E(N()),includeServiceFee:E(h()),promoCode:E(N()),tipCents:E(e(0))},K=M(be),q=D(E(K,{})),xe=M({confirmationToken:E(r),customFieldAnswers:E(m(i)),email:N(),memberId:E(N()),merchSize:E(O([`XS`,`S`,`M`,`L`,`XL`,`XXL`,`XXXL`])),metadata:E(ee(N(),N())),paymentMethodConfiguration:E(v(`explicit`)),phone:E(N()),shipping:E(M({address:M({city:N(),country:N(),line1:N(),line2:E(N()),postal_code:N(),state:N()}),name:N()}))}),Se=F([M({amountCents:e(1),productId:r}),M({productId:r,quantity:e(1)}),M({productId:r})]),Ce=F([M({amountCents:e(1),productSlug:r}),M({productSlug:r,quantity:e(1)}),M({productSlug:r})]),J=k(m(Se),x(1)),Y=k(m(Ce),x(1)),we=T({selection:Y}),Te=y({catalog:E(I()),email:E(I()),includeServiceFee:E(I()),items:E(J),promoCode:E(I()),selection:E(Y),tipCents:E(I())}),Ee=k(y({authoritative:v(!0),items:J,payment:T({connectedAccountId:C(r),currency:v(`usd`),publishableKey:k(N(),x(1))}),paymentReference:k(N(),x(1)),pricing:K}),P(e=>{let{items:t,payment:n,paymentReference:r,pricing:i,...a}=e,o=W({...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:Ee,submission:xe}),Oe=r,ke=D(y({})),Ae=D(Te);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:q(i),selection:r}}catch(e){throw TypeError(`Checkout pricing input is invalid.`,{cause:e})}}const Me=D(we),Ne=D(Oe);D(Ee);const Pe=D(De),Fe=D(Y);function Ie(e){return Math.max(100,e.minimumAmountCents??0)}function Le(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 l({code:`total_calculation_failed`,message:`This option is sold out.`,operation:`calculate_total`,reportable:!1,serverCode:`PAYMENT_WIDGET_SALES_LIMIT_REACHED`})}function Re(e,t){if(e.pricingMode!==`custom`||e.paymentOption!==`one-time`||t<Ie(e))throw TypeError(`Selected Product amount is invalid.`);return{checkoutItem:{amountCents:t,productId:e.id},quantity:1,unitAmountCents:t}}function ze(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 Be(e,t,n){let r=`quantity`in n?n.quantity:1,{checkoutItem:i,quantity:a,unitAmountCents:o}=`amountCents`in n?Re(t,n.amountCents):ze(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=e.widget.requiredShipping;if(r){let t=e.products.find(({id:e})=>e===r.productId),i=n.some(t=>e.products.some(e=>e.slug===t.productSlug&&r.triggerProductIds.includes(e.id)));if(n=n.filter(e=>e.productSlug!==t?.slug),i){if(!t)throw TypeError(`Required shipping Product is unavailable.`);n.push({productSlug:t.slug,quantity:1})}}let i=new Set,a=n.map(t=>{let n=e.products.find(e=>e.slug===t.productSlug);if(!n)throw TypeError(`Selected Product is unavailable.`);if(i.has(n.id))throw TypeError(`Each Product can appear only once per checkout.`);return i.add(n.id),Be(e,n,t)});if(r?.additionalUnitAmountCents){let e=a.reduce((e,{lineItem:t})=>e+(r.triggerProductIds.includes(t.productId)?t.quantity:0),0),t=a.find(({lineItem:e})=>e.productId===r.productId)?.lineItem;if(t){let n=t.unitAmountCents+Math.max(0,e-1)*r.additionalUnitAmountCents;if(!Number.isSafeInteger(n)||n>2147483647)throw TypeError(`Required shipping amount is invalid.`);t.unitAmountCents=n,t.subtotalCents=n}}let o=a[0]?.lineItem.paymentOption;if(!o)throw TypeError(`Select at least one Product.`);if(a.length>1&&(o!==`one-time`||a.some(({lineItem:e})=>e.paymentOption!==o)))throw TypeError(`Recurring Products must be purchased separately.`);let s=a.map(({checkoutItem:e})=>e);return Le(e,s),{items:s,lineItems:a.map(({lineItem:e})=>e),paymentOption:o}}function Ve(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:e.maxQuantityPerOrder,minimumAmountCents:t.minimumAmountCents,minimumQuantity:t.minQuantity,name:t.name,paymentOption:t.paymentOption,pricingMode:t.pricingMode,slug:e.slug}}function He(e){if(!e)return null;let t={accentColor:e.color,imageUrl:e.thumbnail||null,name:e.name};return e.widgetAchEnabled!==void 0&&(t.widgetAchEnabled=e.widgetAchEnabled),e.memberIdLabel!==void 0&&(t.memberIdLabel=e.memberIdLabel),t}function Ue(e){let t=e.config?.fields??{};return{availability:e.availability,community:He(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(Ve),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`,requiredShipping:e.config?.requiredShipping,showCommunityBranding:e.showCommunityBranding??!0,title:e.title??null}}}function Z(e){return Q(e)}function We(e){return Q(e)}function Ge(e){return Q(e)}function Q(e){return s(structuredClone(e))}const Ke=T({code:O([`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(Ke,await e.json());return t.success?t.output.code:void 0}catch{}}function qe({catalog:e,items:t,selection:n}){if(t!==void 0&&n!==void 0)throw TypeError(`Use items or selection, not both.`);let r=Z(he(e)),i=n===void 0?Je(t):X(r,n).items;return Le(r,i),{catalog:r,items:i}}function Je(e){if(e===void 0)throw TypeError(`Checkout selection is invalid.`);return e}function Ye(e){let{apiBaseUrl:t,communitySlug:n,communitySlugValue:r,environment:i,fetchImplementation:a,onError:u,requestTimeoutMs:d,sentryDsn:f,widgetSlug:p,widgetSlugValue:m}=ne(e),h=o({communitySlug:r,environment:i,getContext:()=>({widgetSlug:m}),onError:u,resourceContextName:`lockerverse_widget`,sentryDsn:f}),{requestJson:g}=c(a,h,d),_=`${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 l({code:n,message:e,operation:t,reportable:!1}))}function b(e,t){return e instanceof l?e:new l({...t,reportable:!0})}function x(e,t,n=!1){let r=b(e,t);if(!(n&&(r.status===void 0||r.status>=500)))throw h(r);let i=r.status===void 0?new l({code:r.code,message:r.message,operation:r.operation,recoveryRecommended:!0,reportable:r.reportable}):new l({code:r.code,message:r.message,operation:r.operation,recoveryRecommended:!0,reportable:r.reportable,status:r.status});throw h(i)}function S(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 C(e){try{return Me(e).selection}catch{y(`Checkout selection is invalid.`,`load_widget`)}}function w(e,t,n,r){let{connectedAccountId:i,...a}=e;return We(s({...a,authoritative:!0,items:t,payment:{connectedAccountId:i,currency:`usd`,publishableKey:r.publishableKey},paymentOption:e.paymentOption,paymentReference:globalThis.crypto.randomUUID(),pricing:n}))}function T(e,t,n){try{return X(e,t).items}catch(e){throw e instanceof TypeError&&y(e.message,n),e}}function E(e,t,n,r){if(!n)throw new l({...r,message:`Lockerverse did not return the requested initial quote.`,reportable:!0});let i=T(e,t,r.operation);return s({catalog:Z(e),checkout:w(n,i,{includeServiceFee:e.widget.fields.serviceFee},e.payment)})}async function D(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,ye,{...t,message:`Unable to load Lockerverse widget because the request failed.`,report:!1},{...t,report:!1},$);if(!r.ok){let e=r.errorValue;throw e===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`?new l({...t,message:`This option is sold out.`,reportable:!1,serverCode:e,status:r.response.status}):new l({...t,message:`Unable to load Lockerverse widget (${r.response.status}).`,reportable:r.response.status>=500,status:r.response.status})}let i=s(Ue(r.value.widget));return e?E(i,e,r.value.quote,t):Z(i)}async function O(e,t){let n=await D(),r={includeServiceFee:n.widget.fields.serviceFee},i=T(n,e,t.operation);return s({catalog:n,checkout:await A(i,r,n.payment,t)})}async function k(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 O(e,t):e?await D(e):await D()}catch(e){x(e,t)}}function ee(e){return e===void 0?k():k(C(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`},W,{...r,message:`Unable to calculate the Lockerverse checkout total because the request failed.`,report:!1},{...r,report:!1},$);if(!i.ok){let e=i.errorValue;throw e===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`?new l({...r,message:`This option is sold out.`,reportable:!1,serverCode:e,status:i.response.status}):new l({...r,message:`Unable to calculate the Lockerverse checkout total (${i.response.status}).`,reportable:i.response.status>=500,status:i.response.status})}return w(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){x(e,i)}}function M(e){try{let t=je(e),n=qe(t),r=S(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 l)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=S(r),o=s(i),{submission:c}=t;o.totalCents>0&&!c.confirmationToken&&y(`Stripe confirmation is required for a paid checkout.`,`submit_payment`,`payment_submit_failed`);let l=c.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:{...c,email:l}}}catch(e){if(e instanceof l)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,G,{...n,message:`Unable to recover the Lockerverse payment status because the request failed.`,report:!1},{...n,report:!1});if(!e.ok)throw new l({...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 l({...n,reportable:!0});return Ge(e.value)}catch(e){x(e,n)}},load:ee,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,paymentMethodConfiguration:i.paymentMethodConfiguration,paymentReference:r.paymentReference,phone:i.phone,quoteContractVersion:1,shipping:i.shipping}),headers:{"Content-Type":`application/json`},method:`POST`},G,{...a,message:`Unable to submit the Lockerverse payment because the request failed.`,report:!1},{...a,report:!1},$);if(!e.ok){let t=e.errorValue;throw t?new l({...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 l({...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 l({...a,reportable:!0});return Ge(e.value)}catch(e){x(e,a,!0)}}}}function Xe(e,t){let{selection:n,...r}=t,i;try{i=q(r)}catch(e){throw TypeError(`Checkout pricing is invalid.`,{cause:e})}let a=i.includeServiceFee??e.widget.fields.serviceFee,{tipCents:o=0}=i,{items:c,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 s({amountCents:m,appliedDiscount:null,authoritative:!1,discountableSubtotalCents:f,discountCents:0,items:c,lineItems:l,paymentOption:u,serviceFeeCents:p,subtotalCents:d,tipCents:o,totalCents:h})}export{u as LOCKERVERSE_SDK_VERSION,l as LockerverseSdkError,Ye as createLockerverseCheckoutClient,Xe as estimateLockerverseCheckout,Ie as getLockerverseMinimumCustomAmountCents};
1
+ import{a as e,i as t,n,r,t as i}from"./schema-helpers.js";import{i as a,n as o,o as s,t as c}from"./transport.js";import{n as l,t as u}from"./types.js";import{n as d,r as f,t as p}from"./valibot.gen.js";import{array as m,boolean as h,check as g,finite as _,literal as v,looseObject as y,maxValue as b,minLength as x,minValue as S,nullable as C,number as w,object as T,optional as E,parser as D,picklist as O,pipe as k,record as ee,regex as A,safeParse as j,strictObject as M,string as N,transform as P,union as F,unknown as I,variant as te}from"valibot";function ne(e){let t=a(e,`widgetSlug`);return{...t,widgetSlug:t.resourceSlug,widgetSlugValue:t.resourceSlugValue}}const L=O([`one-time`,`monthly`,`annually`,`every-six-months`]),R=O([`none`,`event_admission`]),z=C(e(0)),re=O([`available`,`sold_out`]),ie=E(T({listings:m(T({listingId:r,maxPurchasableQuantity:z,remainingQuantity:z,status:re})),sharedLimits:m(T({id:r,listingIds:m(r),remainingQuantity:e(0),status:re}))}),{listings:[],sharedLimits:[]}),ae=k(N(),A(/^pk_(?:test|live)_\S+$/,`Invalid publishable key.`)),B={description:t,fulfillmentType:R,id:r,inventoryQuantity:z,maxQuantity:z,minimumAmountCents:z,minQuantity:z,name:r,paymentOption:L},V=T({description:C(N()),endAt:r,id:r,location:C(N()),name:r,startAt:r,status:O([`draft`,`active`,`finished`,`cancelled`])}),oe=te(`pricingMode`,[T({...B,amountCents:e(0),pricingMode:v(`fixed`)}),T({...B,amountCents:z,pricingMode:v(`custom`)})]),se=T({acceptsDiscounts:E(h(),!1),id:r,maxQuantityPerOrder:E(z,null),product:oe,productId:r,slug:r}),H=E(T({memberId:E(h(),!1),merchSize:E(h(),!1),phone:E(h(),!1),promoCode:E(h(),!1),serviceFee:E(h(),!1),shipping:E(h(),!1),tipping:E(h(),!1)}),{}),U=E(T({additionalUnitAmountCents:E(k(e(0),b(2147483647))),productId:r,triggerProductIds:m(r)})),ce=k(T({availability:ie,community:E(T({color:N(),memberIdLabel:E(C(N())),name:r,thumbnail:C(N()),widgetAchEnabled:E(h())})),config:E(T({customFields:n,fields:H,requiredShipping:U})),description:t,event:C(V),id:E(N(),``),name:E(N(),`Lockerverse widget`),payment:T({connectedAccountId:E(C(r),null),currency:v(`usd`),publishableKey:ae}),pricingPolicy:E(T({currency:E(v(`usd`),`usd`),serviceFeeRateBasisPoints:E(e(0),0)})),products:E(m(se),[]),showCommunityBranding:E(h(),!0),title:t}),P(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},requiredShipping:e.config?.requiredShipping},pricingPolicy:e.pricingPolicy??{currency:`usd`,serviceFeeRateBasisPoints:0}}))),le=T({acceptsDiscounts:h(),amountCents:C(e(0)),description:C(N()),fulfillmentType:R,id:r,inventoryQuantity:z,listingId:r,maximumQuantity:z,minimumAmountCents:z,minimumQuantity:z,name:r,paymentOption:L,pricingMode:O([`fixed`,`custom`]),slug:r}),ue=T({availability:ie,community:C(T({accentColor:N(),imageUrl:C(N()),memberIdLabel:E(C(N())),name:r,widgetAchEnabled:E(h())})),event:C(V),payment:T({connectedAccountId:E(C(r),null),currency:v(`usd`),publishableKey:ae}),pricingPolicy:T({currency:v(`usd`),serviceFeeRateBasisPoints:e(0)}),products:m(le),widget:T({customFields:n,description:C(N()),fields:H,id:N(),name:r,requiredShipping:U,showCommunityBranding:h(),title:C(N())})}),de=C(T({amountOffCents:E(e(0)),message:E(N()),percentageOff:E(k(w(),_(),S(0),b(100))),source:O([`email_list`,`promo_code`])})),fe=T({acceptsDiscounts:h(),eventId:C(r),fulfillmentType:R,listingId:r,listingSlug:r,paymentOption:L,pricingMode:O([`fixed`,`custom`]),productId:r,productName:r,quantity:e(1),subtotalCents:e(0),unitAmountCents:e(0)}),pe=k(d,T({amountCents:e(0),appliedDiscount:de,connectedAccountId:C(r),discountableSubtotalCents:e(0),discountCents:e(0),lineItems:m(fe),paymentOption:L,serviceFeeCents:e(0),subtotalCents:e(0),tipCents:e(0),totalCents:e(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.`)),me=k(T({...p.entries,retryUrl:E(k(r,A(/^https:\/\//)))}),g(e=>e.checkoutId.trim()&&e.paymentReference.trim()?e.checkoutStatus===`action_required`?e.paymentRequired&&(e.requiresAction&&!!e.clientSecret?.trim()||!e.requiresAction&&e.clientSecret===null&&!!e.retryUrl):!e.requiresAction&&e.clientSecret===null:!1,`Invalid payment result state.`)),W=D(pe),he=D(ue),G=D(me),ge=D(f),_e=D(ce);function ve(e){return ge(e),_e(e)}function ye(e){let t=j(y({quote:E(I())}),e),n=ve(e),r=t.success?t.output.quote:void 0;return r===void 0?{widget:n}:{quote:W(r),widget:n}}const be={email:E(N()),includeServiceFee:E(h()),promoCode:E(N()),tipCents:E(e(0))},K=M(be),q=D(E(K,{})),xe=M({confirmationToken:E(r),customFieldAnswers:E(m(i)),email:N(),memberId:E(N()),merchSize:E(O([`XS`,`S`,`M`,`L`,`XL`,`XXL`,`XXXL`])),metadata:E(ee(N(),N())),paymentMethodConfiguration:E(v(`explicit`)),phone:E(N()),shipping:E(M({address:M({city:N(),country:N(),line1:N(),line2:E(N()),postal_code:N(),state:N()}),name:N()}))}),Se=F([M({amountCents:e(1),productId:r}),M({productId:r,quantity:e(1)}),M({productId:r})]),Ce=F([M({amountCents:e(1),productSlug:r}),M({productSlug:r,quantity:e(1)}),M({productSlug:r})]),J=k(m(Se),x(1)),Y=k(m(Ce),x(1)),we=T({selection:Y}),Te=y({catalog:E(I()),email:E(I()),includeServiceFee:E(I()),items:E(J),promoCode:E(I()),selection:E(Y),tipCents:E(I())}),Ee=k(y({authoritative:v(!0),items:J,payment:T({connectedAccountId:C(r),currency:v(`usd`),publishableKey:k(N(),x(1))}),paymentReference:k(N(),x(1)),pricing:K}),P(e=>{let{items:t,payment:n,paymentReference:r,pricing:i,...a}=e,o=W({...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:Ee,submission:xe}),Oe=r,ke=D(y({})),Ae=D(Te);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:q(i),selection:r}}catch(e){throw TypeError(`Checkout pricing input is invalid.`,{cause:e})}}const Me=D(we),Ne=D(Oe);D(Ee);const Pe=D(De),Fe=D(Y);function Ie(e){return Math.max(100,e.minimumAmountCents??0)}function Le(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 l({code:`total_calculation_failed`,message:`This option is sold out.`,operation:`calculate_total`,reportable:!1,serverCode:`PAYMENT_WIDGET_SALES_LIMIT_REACHED`})}function Re(e,t){if(e.pricingMode!==`custom`||e.paymentOption!==`one-time`||t<Ie(e))throw TypeError(`Selected Product amount is invalid.`);return{checkoutItem:{amountCents:t,productId:e.id},quantity:1,unitAmountCents:t}}function ze(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 Be(e,t,n){let r=`quantity`in n?n.quantity:1,{checkoutItem:i,quantity:a,unitAmountCents:o}=`amountCents`in n?Re(t,n.amountCents):ze(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=e.widget.requiredShipping;if(r){let t=e.products.find(({id:e})=>e===r.productId),i=n.some(t=>e.products.some(e=>e.slug===t.productSlug&&r.triggerProductIds.includes(e.id)));if(n=n.filter(e=>e.productSlug!==t?.slug),i){if(!t)throw TypeError(`Required shipping Product is unavailable.`);n.push({productSlug:t.slug,quantity:1})}}let i=new Set,a=n.map(t=>{let n=e.products.find(e=>e.slug===t.productSlug);if(!n)throw TypeError(`Selected Product is unavailable.`);if(i.has(n.id))throw TypeError(`Each Product can appear only once per checkout.`);return i.add(n.id),Be(e,n,t)});if(r?.additionalUnitAmountCents){let e=a.reduce((e,{lineItem:t})=>e+(r.triggerProductIds.includes(t.productId)?t.quantity:0),0),t=a.find(({lineItem:e})=>e.productId===r.productId)?.lineItem;if(t){let n=t.unitAmountCents+Math.max(0,e-1)*r.additionalUnitAmountCents;if(!Number.isSafeInteger(n)||n>2147483647)throw TypeError(`Required shipping amount is invalid.`);t.unitAmountCents=n,t.subtotalCents=n}}let o=a[0]?.lineItem.paymentOption;if(!o)throw TypeError(`Select at least one Product.`);if(a.length>1&&(o!==`one-time`||a.some(({lineItem:e})=>e.paymentOption!==o)))throw TypeError(`Recurring Products must be purchased separately.`);let s=a.map(({checkoutItem:e})=>e);return Le(e,s),{items:s,lineItems:a.map(({lineItem:e})=>e),paymentOption:o}}function Ve(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:e.maxQuantityPerOrder,minimumAmountCents:t.minimumAmountCents,minimumQuantity:t.minQuantity,name:t.name,paymentOption:t.paymentOption,pricingMode:t.pricingMode,slug:e.slug}}function He(e){if(!e)return null;let t={accentColor:e.color,imageUrl:e.thumbnail||null,name:e.name};return e.widgetAchEnabled!==void 0&&(t.widgetAchEnabled=e.widgetAchEnabled),e.memberIdLabel!==void 0&&(t.memberIdLabel=e.memberIdLabel),t}function Ue(e){let t=e.config?.fields??{};return{availability:e.availability,community:He(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(Ve),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`,requiredShipping:e.config?.requiredShipping,showCommunityBranding:e.showCommunityBranding??!0,title:e.title??null}}}function Z(e){return Q(e)}function We(e){return Q(e)}function Ge(e){return Q(e)}function Q(e){return s(structuredClone(e))}const Ke=T({code:O([`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(Ke,await e.json());return t.success?t.output.code:void 0}catch{}}function qe({catalog:e,items:t,selection:n}){if(t!==void 0&&n!==void 0)throw TypeError(`Use items or selection, not both.`);let r=Z(he(e)),i=n===void 0?Je(t):X(r,n).items;return Le(r,i),{catalog:r,items:i}}function Je(e){if(e===void 0)throw TypeError(`Checkout selection is invalid.`);return e}function Ye(e){let{apiBaseUrl:t,communitySlug:n,communitySlugValue:r,environment:i,fetchImplementation:a,onError:u,requestTimeoutMs:d,sentryDsn:f,widgetSlug:p,widgetSlugValue:m}=ne(e),h=o({communitySlug:r,environment:i,getContext:()=>({widgetSlug:m}),onError:u,resourceContextName:`lockerverse_widget`,sentryDsn:f}),{requestJson:g}=c(a,h,d),_=`${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 l({code:n,message:e,operation:t,reportable:!1}))}function b(e,t){return e instanceof l?e:new l({...t,reportable:!0})}function x(e,t,n=!1){let r=b(e,t);if(!(n&&(r.status===void 0||r.status>=500)))throw h(r);let i=new l({code:r.code,failureKind:r.failureKind,message:r.message,operation:r.operation,recoveryRecommended:!0,reportable:r.reportable,status:r.status});throw h(i)}function S(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 C(e){try{return Me(e).selection}catch{y(`Checkout selection is invalid.`,`load_widget`)}}function w(e,t,n,r){let{connectedAccountId:i,...a}=e;return We(s({...a,authoritative:!0,items:t,payment:{connectedAccountId:i,currency:`usd`,publishableKey:r.publishableKey},paymentOption:e.paymentOption,paymentReference:globalThis.crypto.randomUUID(),pricing:n}))}function T(e,t,n){try{return X(e,t).items}catch(e){throw e instanceof TypeError&&y(e.message,n),e}}function E(e,t,n,r){if(!n)throw new l({...r,message:`Lockerverse did not return the requested initial quote.`,reportable:!0});let i=T(e,t,r.operation);return s({catalog:Z(e),checkout:w(n,i,{includeServiceFee:e.widget.fields.serviceFee},e.payment)})}async function D(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=()=>g(n,e?{cache:`no-store`}:void 0,ye,{...t,message:`Unable to load Lockerverse widget because the request failed.`,report:!1},{...t,report:!1},$);async function i(){try{return await r()}catch(e){if(!(e instanceof l)||e.failureKind!==`network`&&e.failureKind!==`timeout`)throw e}return r()}let a=await i();if(!a.ok){let e=a.errorValue;throw e===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`?new l({...t,message:`This option is sold out.`,reportable:!1,serverCode:e,status:a.response.status}):new l({...t,message:`Unable to load Lockerverse widget (${a.response.status}).`,reportable:a.response.status>=500,status:a.response.status})}let o=s(Ue(a.value.widget));return e?E(o,e,a.value.quote,t):Z(o)}async function O(e,t){let n=await D(),r={includeServiceFee:n.widget.fields.serviceFee},i=T(n,e,t.operation);return s({catalog:n,checkout:await A(i,r,n.payment,t)})}async function k(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 O(e,t):e?await D(e):await D()}catch(e){x(e,t)}}function ee(e){return e===void 0?k():k(C(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`},W,{...r,message:`Unable to calculate the Lockerverse checkout total because the request failed.`,report:!1},{...r,report:!1},$);if(!i.ok){let e=i.errorValue;throw e===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`?new l({...r,message:`This option is sold out.`,reportable:!1,serverCode:e,status:i.response.status}):new l({...r,message:`Unable to calculate the Lockerverse checkout total (${i.response.status}).`,reportable:i.response.status>=500,status:i.response.status})}return w(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){x(e,i)}}function M(e){try{let t=je(e),n=qe(t),r=S(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 l)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=S(r),o=s(i),{submission:c}=t;o.totalCents>0&&!c.confirmationToken&&y(`Stripe confirmation is required for a paid checkout.`,`submit_payment`,`payment_submit_failed`);let l=c.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:{...c,email:l}}}catch(e){if(e instanceof l)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,G,{...n,message:`Unable to recover the Lockerverse payment status because the request failed.`,report:!1},{...n,report:!1});if(!e.ok)throw new l({...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 l({...n,reportable:!0});return Ge(e.value)}catch(e){x(e,n)}},load:ee,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,paymentMethodConfiguration:i.paymentMethodConfiguration,paymentReference:r.paymentReference,phone:i.phone,quoteContractVersion:1,shipping:i.shipping}),headers:{"Content-Type":`application/json`},method:`POST`},G,{...a,message:`Unable to submit the Lockerverse payment because the request failed.`,report:!1},{...a,report:!1},$);if(!e.ok){let t=e.errorValue;throw t?new l({...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 l({...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 l({...a,reportable:!0});return Ge(e.value)}catch(e){x(e,a,!0)}}}}function Xe(e,t){let{selection:n,...r}=t,i;try{i=q(r)}catch(e){throw TypeError(`Checkout pricing is invalid.`,{cause:e})}let a=i.includeServiceFee??e.widget.fields.serviceFee,{tipCents:o=0}=i,{items:c,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 s({amountCents:m,appliedDiscount:null,authoritative:!1,discountableSubtotalCents:f,discountCents:0,items:c,lineItems:l,paymentOption:u,serviceFeeCents:p,subtotalCents:d,tipCents:o,totalCents:h})}export{u as LOCKERVERSE_SDK_VERSION,l as LockerverseSdkError,Ye as createLockerverseCheckoutClient,Xe as estimateLockerverseCheckout,Ie as getLockerverseMinimumCustomAmountCents};
2
2
  //# sourceMappingURL=checkout.js.map