@lockerverse/sdk 0.2.41 → 0.2.42
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/README.md +87 -39
- package/dist/checkout.d.ts +2 -2
- package/dist/checkout.d.ts.map +1 -1
- package/dist/checkout.js +1 -1
- package/dist/checkout.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/signup.d.ts +1 -1
- package/dist/signup.js +1 -1
- package/dist/transport.js +1 -1
- package/dist/transport.js.map +1 -1
- package/dist/types.d.ts +67 -63
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# Lockerverse SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
complete payment form.
|
|
3
|
+
Stateless browser client for Lockerverse checkout and signup APIs. It validates
|
|
4
|
+
public inputs and backend responses, returns immutable snapshots, and never
|
|
5
|
+
renders UI or owns host application state.
|
|
7
6
|
|
|
8
7
|
## Checkout
|
|
9
8
|
|
|
@@ -13,45 +12,70 @@ import { createLockerverseCheckoutClient } from "@lockerverse/sdk/checkout";
|
|
|
13
12
|
const client = createLockerverseCheckoutClient({
|
|
14
13
|
communitySlug: "auburn",
|
|
15
14
|
widgetSlug: "auburn-tailgate-party",
|
|
15
|
+
onError(error) {
|
|
16
|
+
console.error(error.code, error.operation);
|
|
17
|
+
},
|
|
16
18
|
});
|
|
17
19
|
|
|
18
|
-
const
|
|
19
|
-
email: "customer@example.com",
|
|
20
|
-
items: [{ productSlug: "adult", quantity: 2 }],
|
|
21
|
-
requestKey: crypto.randomUUID(),
|
|
22
|
-
returnUrl: "https://example.com/payment-complete",
|
|
23
|
-
tipCents: 500,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const catalog = session.catalog;
|
|
27
|
-
|
|
28
|
-
await client.updateSessionDiscount({
|
|
29
|
-
paymentReference: session.paymentReference,
|
|
30
|
-
promoCode: "FREE",
|
|
31
|
-
});
|
|
20
|
+
const catalog = await client.load();
|
|
32
21
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
// The host owns Product selection. Use IDs from the current catalog.
|
|
23
|
+
const items = [
|
|
24
|
+
{ productId: catalog.products[0].id, quantity: 2 },
|
|
25
|
+
];
|
|
26
|
+
const pricing = {
|
|
27
|
+
email: "customer@example.com",
|
|
28
|
+
includeServiceFee: true,
|
|
36
29
|
tipCents: 500,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Lockerverse resolves current prices, availability, discounts, fees, and the
|
|
33
|
+
// connected Stripe account authoritatively.
|
|
34
|
+
const checkout = await client.calculateTotal({ ...pricing, items });
|
|
35
|
+
|
|
36
|
+
// Render Stripe Elements with checkout.payment.publishableKey,
|
|
37
|
+
// checkout.payment.connectedAccountId, and checkout.totalCents. The prepared
|
|
38
|
+
// checkout also binds the normalized items and pricing used for this total.
|
|
39
|
+
const payment = await client.submitPayment({
|
|
40
|
+
checkout,
|
|
41
|
+
submission: {
|
|
42
|
+
confirmationToken: "ctoken_...",
|
|
43
|
+
customFieldAnswers: [
|
|
44
|
+
{ fieldId: "guest-name", value: "Ada Lovelace" },
|
|
45
|
+
{ fieldId: "interests", value: ["meetups", "merch"] },
|
|
46
|
+
],
|
|
47
|
+
email: "customer@example.com",
|
|
48
|
+
metadata: { source: "community-site" },
|
|
49
|
+
},
|
|
37
50
|
});
|
|
38
51
|
|
|
39
|
-
|
|
52
|
+
// Safe after a refresh or an interrupted confirmation response.
|
|
53
|
+
const recovered = await client.getPaymentStatus(checkout.paymentReference);
|
|
40
54
|
```
|
|
41
55
|
|
|
42
|
-
|
|
43
|
-
`
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
`createLockerverseCheckoutClient()` exposes only `load`, `calculateTotal`,
|
|
57
|
+
`submitPayment`, and `getPaymentStatus`. It has no selection store, lifecycle
|
|
58
|
+
state, subscriptions, or Stripe state. React applications can use
|
|
59
|
+
`@lockerverse/react` for the complete payment UI and orchestration.
|
|
60
|
+
|
|
61
|
+
Fixed prices in the catalog are display data. `calculateTotal()` sends Product
|
|
62
|
+
IDs and selections to Lockerverse, which resolves the payable amount. The host
|
|
63
|
+
returns them together as one immutable prepared checkout. Pass that prepared
|
|
64
|
+
checkout to `submitPayment()` so a host cannot accidentally submit different
|
|
65
|
+
inputs from the ones Lockerverse quoted. It owns one stable payment reference
|
|
66
|
+
so Lockerverse can prevent duplicate checkout creation and recover ambiguous
|
|
67
|
+
outcomes.
|
|
47
68
|
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
If `submitPayment()` throws an error with `recoveryRecommended: true`, the
|
|
70
|
+
request may still have reached Lockerverse. Query `getPaymentStatus()` with the
|
|
71
|
+
prepared checkout's payment reference before allowing another payment. Other
|
|
72
|
+
failures are definitive and do not require recovery.
|
|
50
73
|
|
|
51
|
-
##
|
|
74
|
+
## Runtime configuration
|
|
52
75
|
|
|
53
|
-
Production is the default. A custom endpoint must
|
|
54
|
-
environment
|
|
76
|
+
Production is the default endpoint and environment. A custom endpoint must name
|
|
77
|
+
its environment so a development host cannot silently select live Stripe
|
|
78
|
+
configuration:
|
|
55
79
|
|
|
56
80
|
```ts
|
|
57
81
|
const client = createLockerverseCheckoutClient({
|
|
@@ -62,6 +86,11 @@ const client = createLockerverseCheckoutClient({
|
|
|
62
86
|
});
|
|
63
87
|
```
|
|
64
88
|
|
|
89
|
+
Custom endpoints must be HTTP(S) URLs without credentials, query strings, or
|
|
90
|
+
fragments. HTTPS is required except for literal `localhost`, `127.0.0.1`, and
|
|
91
|
+
`[::1]` endpoints in development. Requests have a 20-second deadline by
|
|
92
|
+
default; override it with a positive `requestTimeoutMs` value.
|
|
93
|
+
|
|
65
94
|
## Signup
|
|
66
95
|
|
|
67
96
|
```ts
|
|
@@ -74,24 +103,43 @@ const signup = createLockerverseSignup({
|
|
|
74
103
|
|
|
75
104
|
const definition = await signup.load();
|
|
76
105
|
const submission = await signup.submit({
|
|
77
|
-
answers: [{ fieldId:
|
|
106
|
+
answers: [{ fieldId: "guest-type", value: "student" }],
|
|
78
107
|
email: "customer@example.com",
|
|
79
108
|
name: "Ada Lovelace",
|
|
80
109
|
participantCount: 2,
|
|
81
110
|
});
|
|
82
111
|
```
|
|
83
112
|
|
|
113
|
+
Signup currently retains its small workflow facade. Its immutable states are
|
|
114
|
+
`idle`, `loading`, `ready`, `submitting`, `submitted`, and `error`. When a
|
|
115
|
+
submission times out, reuse `recoverableSubmissionReference` with the same
|
|
116
|
+
values so Lockerverse can return the original submission.
|
|
117
|
+
|
|
84
118
|
## Security and observability
|
|
85
119
|
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
-
|
|
120
|
+
- No Stripe or Lockerverse secret is accepted by the public API.
|
|
121
|
+
- Successful catalog, quote, confirmation, and status responses are validated
|
|
122
|
+
before being returned.
|
|
123
|
+
- Public workflow inputs are validated with private Valibot schemas.
|
|
124
|
+
- Backend response bodies and validation internals never escape in SDK errors.
|
|
125
|
+
- Expected input errors are `reportable: false`; unexpected network and server
|
|
126
|
+
failures are `reportable: true`.
|
|
127
|
+
- Reportable failures are sent directly to Lockerverse Sentry with allowlisted
|
|
128
|
+
workflow context. `sentryDsn: null` disables loading and sending telemetry.
|
|
129
|
+
- The Sentry runtime is an isolated failure-only chunk and does not replace or
|
|
130
|
+
mutate the host application's Sentry client.
|
|
131
|
+
- Stripe's shared publishable key is selected by environment. The authoritative
|
|
132
|
+
quote supplies the community's connected account.
|
|
133
|
+
- Analytics and auctions are intentionally out of scope.
|
|
91
134
|
|
|
92
135
|
## Commands
|
|
93
136
|
|
|
137
|
+
Run these from the repository root:
|
|
138
|
+
|
|
94
139
|
```sh
|
|
95
140
|
pnpm dev:react
|
|
96
|
-
pnpm
|
|
141
|
+
pnpm typecheck
|
|
142
|
+
pnpm test
|
|
143
|
+
pnpm build
|
|
144
|
+
pnpm --filter @lockerverse/sdk pack:check
|
|
97
145
|
```
|
package/dist/checkout.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as LockerverseSdkOperation, C as LockerversePaymentResult, D as LockerverseProduct, E as LockerversePreparedCheckout, F as LockerverseWidgetFields, M as LockerverseSubmitPaymentInput, N as LockerverseTextCustomField, O as LockerverseSdkError, P as LockerverseWidgetConfiguration, S as LockerversePaymentOption, T as LockerversePaymentSubmission, _ as LockerverseCustomFieldAnswerValue, a as LockerverseCatalog, b as LockerverseMultiOptionCustomField, c as LockerverseCheckoutItem, d as LockerverseCheckoutPricingInput, f as LockerverseCheckoutPricingPolicy, g as LockerverseCustomFieldAnswer, h as LockerverseCustomField, i as LockerverseCalculateTotalInput, j as LockerverseSingleOptionCustomField, k as LockerverseSdkErrorCode, l as LockerverseCheckoutLineItem, m as LockerverseCommunityBranding, n as LOCKERVERSE_SDK_VERSION, o as LockerverseCheckoutAmounts, p as LockerverseCheckoutQuote, r as LockerverseAppliedDiscount, s as LockerverseCheckoutClient, t as CreateLockerverseWidgetOptions, u as LockerverseCheckoutPaymentConfiguration, v as LockerverseCustomFieldOption, w as LockerversePaymentStatus, x as LockerversePaymentConfiguration, y as LockerverseEnvironment } from "./types.js";
|
|
2
2
|
//#region src/checkout-client.d.ts
|
|
3
3
|
declare function createLockerverseCheckoutClient(options: CreateLockerverseWidgetOptions): LockerverseCheckoutClient;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { CreateLockerverseWidgetOptions, LOCKERVERSE_SDK_VERSION, LockerverseCatalog, LockerverseCheckoutClient, LockerverseCheckoutItem,
|
|
5
|
+
export { CreateLockerverseWidgetOptions, LOCKERVERSE_SDK_VERSION, LockerverseAppliedDiscount, LockerverseCalculateTotalInput, LockerverseCatalog, LockerverseCheckoutAmounts, LockerverseCheckoutClient, LockerverseCheckoutItem, LockerverseCheckoutLineItem, LockerverseCheckoutPaymentConfiguration, LockerverseCheckoutPricingInput, LockerverseCheckoutPricingPolicy, LockerverseCheckoutQuote, LockerverseCommunityBranding, LockerverseCustomField, LockerverseCustomFieldAnswer, LockerverseCustomFieldAnswerValue, LockerverseCustomFieldOption, LockerverseEnvironment, LockerverseMultiOptionCustomField, LockerversePaymentConfiguration, LockerversePaymentOption, LockerversePaymentResult, LockerversePaymentStatus, LockerversePaymentSubmission, LockerversePreparedCheckout, LockerverseProduct, LockerverseSdkError, LockerverseSdkErrorCode, LockerverseSdkOperation, LockerverseSingleOptionCustomField, LockerverseSubmitPaymentInput, LockerverseTextCustomField, LockerverseWidgetConfiguration, LockerverseWidgetFields, createLockerverseCheckoutClient };
|
|
6
6
|
//# sourceMappingURL=checkout.d.ts.map
|
package/dist/checkout.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.d.ts","names":[],"sources":["../src/checkout-client.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","names":[],"sources":["../src/checkout-client.ts"],"mappings":";;iBA0CgB,gCACd,SAAS,iCACR"}
|
package/dist/checkout.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{C as e,D as t,E as n,O as r,S as i,T as a,_ as o,a as s,b as c,c as l,d as u,f as d,g as f,h as p,k as m,l as h,n as g,o as _,p as v,r as y,s as b,t as x,v as S,w as C,x as w,y as T}from"./transport.js";import{n as E,t as D}from"./types.js";const O={development:`pk_test_51O7FkjDHAhgRuLtFHdkXdIe8T5i7rOVaG9PCtDetK3UUVKojVUEKHmQacGzigf9mOX1wz3zSOKoYwFjRcTfML9PU00OjJko2lk`,production:`pk_live_51O7FkjDHAhgRuLtFlzLdxJrwo7F09WCKTlzT9lnBePjOGizWnuijkH9oCkoAddkmBT8ngIuqAPkDiHlPEAH4KXbz00Tm0DaPT4`};function k(e){let t=h(e,`widgetSlug`);return{...t,stripePublishableKey:O[t.environment],widgetSlug:t.resourceSlug,widgetSlugValue:t.resourceSlugValue}}const A=r([a({amountCents:l(1),productSlug:_}),a({productSlug:_,quantity:l(1)})]),j=e(C(e(n(),o(1),f(40)),e(n(),f(500))),v(e=>Object.keys(e).length<=50)),M=w(a({email:c(n()),includeServiceFee:c(d()),items:e(u(A),o(1)),metadata:c(j),requestKey:_,returnUrl:_,tipCents:c(l(0))})),N=w(a({paymentReference:_,promoCode:c(n())})),P=w(a({includeServiceFee:d(),paymentReference:_,tipCents:l(0)})),F=w(a({customFieldAnswers:c(u(a({fieldId:_,value:c(S(r([n(),u(n())])))}))),email:_,memberId:c(n()),merchSize:c(i([`XS`,`S`,`M`,`L`,`XL`,`XXL`,`XXXL`])),paymentReference:_,phone:c(n())})),I=i([`one-time`,`monthly`,`annually`]),L=S(l(0)),R={description:b,id:_,inventoryQuantity:L,maxQuantity:L,minimumAmountCents:L,minQuantity:L,name:_,paymentOption:I},z=e(m(`pricingMode`,[T({...R,amountCents:l(0),pricingMode:p(`fixed`)}),T({...R,amountCents:L,pricingMode:p(`custom`)})]),v(({maxQuantity:e,minQuantity:t})=>e===null||t===null||t<=e)),B=T({acceptsDiscounts:c(d(),!1),id:_,product:z,productId:_,slug:_}),V=c(T({memberId:c(d(),!1),merchSize:c(d(),!1),phone:c(d(),!1),promoCode:c(d(),!1),serviceFee:c(d(),!1),shipping:c(d(),!1),tipping:c(d(),!1)}),{}),H=T({color:b,name:_,thumbnail:b}),U=e(T({community:c(H),config:c(T({customFields:s,fields:V})),description:b,id:c(n(),``),name:c(n(),`Lockerverse widget`),pricingPolicy:c(T({currency:c(p(`usd`),`usd`),serviceFeeRateBasisPoints:c(l(0),0)})),products:c(u(B),[]),showCommunityBranding:c(d(),!0),title:b}),t(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}}))),W=T({checkoutId:_,checkoutStatus:i([`action_required`,`failed`,`pending`,`success`]),clientSecret:S(n()),paymentReference:_,requiresAction:d(),status:S(n())}),G=T({catalog:U,checkoutId:_,clientSecret:_,connectedAccountId:S(_),paymentReference:_,pricing:T({discountCents:l(0),includeServiceFee:d(),serviceFeeCents:l(0),subtotalCents:l(0),tipCents:l(0),totalCents:l(0)}),sessionId:_}),K=T({discountCents:l(0),paymentReference:_,totalCents:l(0)}),q=T({paymentReference:_,totalCents:l(0)}),J=T({includeServiceFee:d(),paymentReference:_,serviceFeeCents:l(0),tipCents:l(0),totalCents:l(0)}),Y=w(G),X=w(K),Z=w(q),Q=w(J),$=w(W);function ee(e){let{product:t}=e;return{acceptsDiscounts:e.acceptsDiscounts??!1,amountCents:t.amountCents,description:t.description??null,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 te(e,t){let n=e.config?.fields??{};return{community:e.community?{accentColor:e.community.color??null,imageUrl:e.community.thumbnail??null,name:e.community.name}:null,payment:{currency:`usd`,publishableKey:t},pricingPolicy:{currency:`usd`,serviceFeeRateBasisPoints:e.pricingPolicy?.serviceFeeRateBasisPoints??0},products:(e.products??[]).map(ee),widget:{customFields:e.config?.customFields??[],description:e.description??null,fields:{memberId:n.memberId??!1,merchSize:n.merchSize??!1,phone:n.phone??!1,promoCode:n.promoCode??!1,serviceFee:n.serviceFee??!1,shipping:n.shipping??!1,tipping:n.tipping??!1},id:e.id??``,name:e.name??`Lockerverse widget`,showCommunityBranding:e.showCommunityBranding??!0,title:e.title??null}}}function ne(e){return re(e)}function re(e){return y(structuredClone(e))}function ie(e){let{apiBaseUrl:t,communitySlug:n,communitySlugValue:r,environment:i,fetchImplementation:a,onError:o,requestTimeoutMs:s,sentryDsn:c,stripePublishableKey:l,widgetSlug:u,widgetSlugValue:d}=k(e),f=g({communitySlug:r,environment:i,getContext:()=>({widgetSlug:d}),onError:o,resourceContextName:`lockerverse_widget`,sentryDsn:c}),{requestJson:p}=x(a,f,s),m=`${t}/v2/community/${n}/payment-widgets/${u}`,h=`${m}/checkout/session`;function _(e,t){throw f(new E({code:`invalid_selection`,message:e,operation:t,reportable:!1}))}function v(e,t){throw f(e instanceof E?e:new E({...t,reportable:!0}))}function b(e){try{let t=M(e),n=new URL(t.returnUrl);if(n.protocol!==`http:`&&n.protocol!==`https:`)throw TypeError(`Invalid return URL.`);let r=t.email?.trim().toLowerCase();return{...r?{email:r}:{},...t.includeServiceFee===void 0?{}:{includeServiceFee:t.includeServiceFee},items:t.items,...t.metadata?{metadata:t.metadata}:{},requestKey:t.requestKey.trim(),returnUrl:n.toString(),...t.tipCents===void 0?{}:{tipCents:t.tipCents}}}catch{_(`Checkout Session input is invalid.`,`create_session`)}}return{async createSession(e){let t=b(e),n={code:`session_create_failed`,message:`Lockerverse returned an invalid Checkout Session.`,operation:`create_session`};try{let e=await p(h,{body:JSON.stringify(t),headers:{"Content-Type":`application/json`},method:`POST`},Y,{...n,message:`Unable to create the Lockerverse Checkout Session because the request failed.`,report:!1},{...n,report:!1});if(!e.ok)throw new E({...n,message:`Unable to create the Lockerverse Checkout Session (${e.response.status}).`,reportable:e.response.status>=500,status:e.response.status});let{catalog:r,...i}=e.value;return y({...i,catalog:te(r,l)})}catch(e){v(e,n)}},async getPaymentStatus(e){(typeof e!=`string`||!e.trim())&&_(`Provide a payment reference to recover its status.`,`get_payment_status`);let t=e.trim(),n={code:`payment_status_failed`,message:`Lockerverse returned an invalid payment status.`,operation:`get_payment_status`};try{let e=await p(`${m}/checkout/${encodeURIComponent(t)}/status`,void 0,$,{...n,message:`Unable to recover the Lockerverse payment status because the request failed.`,report:!1},{...n,report:!1});if(!e.ok)throw new E({...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 E({...n,reportable:!0});return ne(e.value)}catch(e){v(e,n)}},stripePublishableKey:l,async updateSessionDetails(e){let t;try{t=F(e)}catch{_(`Checkout Session details are invalid.`,`update_session_details`)}let n=t.paymentReference.trim(),r={code:`session_update_failed`,message:`Lockerverse returned invalid Checkout Session details.`,operation:`update_session_details`};try{let e={...t.customFieldAnswers?{customFieldAnswers:t.customFieldAnswers}:{},email:t.email.trim().toLowerCase(),...t.memberId?.trim()?{memberId:t.memberId.trim()}:{},...t.merchSize?{merchSize:t.merchSize}:{},...t.phone?.trim()?{phone:t.phone.trim()}:{}},i=await p(`${h}/${encodeURIComponent(n)}/details`,{body:JSON.stringify(e),headers:{"Content-Type":`application/json`},method:`PATCH`},Z,{...r,report:!1},{...r,report:!1});if(!i.ok)throw new E({...r,message:`Unable to save the Lockerverse Checkout Session details (${i.response.status}).`,reportable:i.response.status>=500,status:i.response.status});if(i.value.paymentReference!==n)throw new E({...r,reportable:!0});return y({...i.value})}catch(e){v(e,r)}},async updateSessionDiscount(e){let t;try{t=N(e)}catch{_(`Checkout Session discount input is invalid.`,`update_session_discount`)}let n=t.paymentReference.trim(),r=t.promoCode?.trim(),i={code:`session_update_failed`,message:`Lockerverse returned an invalid Checkout Session update.`,operation:`update_session_discount`};try{let e=await p(`${h}/${encodeURIComponent(n)}/discount`,{body:JSON.stringify(r?{promoCode:r}:{}),headers:{"Content-Type":`application/json`},method:`PATCH`},X,{...i,message:`Unable to update the Lockerverse Checkout Session because the request failed.`,report:!1},{...i,report:!1});if(!e.ok)throw new E({...i,message:`Unable to update the Lockerverse Checkout Session (${e.response.status}).`,reportable:e.response.status>=500,status:e.response.status});if(e.value.paymentReference!==n)throw new E({...i,reportable:!0});return y({...e.value})}catch(e){v(e,i)}},async updateSessionPricing(e){let t;try{t=P(e)}catch{_(`Checkout Session pricing input is invalid.`,`update_session_pricing`)}let n=t.paymentReference.trim(),r={code:`session_update_failed`,message:`Lockerverse returned invalid Checkout Session pricing.`,operation:`update_session_pricing`};try{let e=await p(`${h}/${encodeURIComponent(n)}/pricing`,{body:JSON.stringify({includeServiceFee:t.includeServiceFee,tipCents:t.tipCents}),headers:{"Content-Type":`application/json`},method:`PATCH`},Q,{...r,report:!1},{...r,report:!1});if(!e.ok)throw new E({...r,message:`Unable to update Lockerverse Checkout Session pricing (${e.response.status}).`,reportable:e.response.status>=500,status:e.response.status});if(e.value.paymentReference!==n)throw new E({...r,reportable:!0});return y({...e.value})}catch(e){v(e,r)}}}}export{D as LOCKERVERSE_SDK_VERSION,E as LockerverseSdkError,ie as createLockerverseCheckoutClient};
|
|
1
|
+
import{A as e,C as t,D as n,E as r,M as i,O as a,S as o,T as s,_ as c,a as l,b as u,c as d,d as f,f as p,g as m,i as h,j as g,k as _,l as v,m as y,n as b,o as x,p as S,r as C,s as w,t as T,v as ee,w as E,x as D,y as O}from"./transport.js";import{n as k,t as A}from"./types.js";const j={development:`pk_test_51O7FkjDHAhgRuLtFHdkXdIe8T5i7rOVaG9PCtDetK3UUVKojVUEKHmQacGzigf9mOX1wz3zSOKoYwFjRcTfML9PU00OjJko2lk`,production:`pk_live_51O7FkjDHAhgRuLtFlzLdxJrwo7F09WCKTlzT9lnBePjOGizWnuijkH9oCkoAddkmBT8ngIuqAPkDiHlPEAH4KXbz00Tm0DaPT4`};function M(e){let t=v(e,`widgetSlug`);return{...t,stripePublishableKey:j[t.environment],widgetSlug:t.resourceSlug,widgetSlugValue:t.resourceSlugValue}}const N=E(t(a({email:t(_()),includeServiceFee:t(p()),promoCode:t(_()),tipCents:t(d(0))}),{})),P=E(a({confirmationToken:x,customFieldAnswers:t(f(h)),email:_(),memberId:t(_()),merchSize:t(s([`XS`,`S`,`M`,`L`,`XL`,`XXL`,`XXXL`])),metadata:t(n(_(),_())),phone:t(_())})),F=g([a({amountCents:d(1),productId:x}),a({productId:x,quantity:d(1)})]),I=E(r(f(F),ee(1))),L=s([`one-time`,`monthly`,`annually`]),R=u(d(0)),z={description:w,id:x,inventoryQuantity:R,maxQuantity:R,minimumAmountCents:R,minQuantity:R,name:x,paymentOption:L},B=r(i(`pricingMode`,[o({...z,amountCents:d(0),pricingMode:m(`fixed`)}),o({...z,amountCents:R,pricingMode:m(`custom`)})]),S(({maxQuantity:e,minQuantity:t})=>e===null||t===null||t<=e)),V=o({acceptsDiscounts:t(p(),!1),id:x,product:B,productId:x,slug:x}),H=t(o({memberId:t(p(),!1),merchSize:t(p(),!1),phone:t(p(),!1),promoCode:t(p(),!1),serviceFee:t(p(),!1),shipping:t(p(),!1),tipping:t(p(),!1)}),{}),U=r(o({community:t(o({color:_(),name:x,thumbnail:_()})),config:t(o({customFields:l,fields:H})),description:w,id:t(_(),``),name:t(_(),`Lockerverse widget`),pricingPolicy:t(o({currency:t(m(`usd`),`usd`),serviceFeeRateBasisPoints:t(d(0),0)})),products:t(f(V),[]),showCommunityBranding:t(p(),!0),title:w}),e(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}}))),W=u(o({percentageOff:r(D(),y(),O(0),c(100)),source:s([`email_list`,`promo_code`])})),G=o({acceptsDiscounts:p(),listingId:x,listingSlug:x,paymentOption:L,pricingMode:s([`fixed`,`custom`]),productId:x,productName:x,quantity:d(1),subtotalCents:d(0),unitAmountCents:d(0)}),K=o({amountCents:d(0),appliedDiscount:W,connectedAccountId:u(x),discountableSubtotalCents:d(0),discountCents:d(0),lineItems:f(G),paymentOption:L,serviceFeeCents:d(0),subtotalCents:d(0),tipCents:d(0),totalCents:d(0)}),q=o({checkoutId:x,checkoutStatus:s([`action_required`,`failed`,`pending`,`success`]),clientSecret:u(_()),paymentReference:x,requiresAction:p(),status:u(_())}),J=E(K),Y=E(q),X=E(U);function Z(e){let{product:t}=e;return{acceptsDiscounts:e.acceptsDiscounts??!1,amountCents:t.amountCents,description:t.description??null,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 te(e,t){let n=e.config?.fields??{};return{community:e.community?{accentColor:e.community.color,imageUrl:e.community.thumbnail,name:e.community.name}:null,payment:{currency:`usd`,publishableKey:t},pricingPolicy:{currency:`usd`,serviceFeeRateBasisPoints:e.pricingPolicy?.serviceFeeRateBasisPoints??0},products:(e.products??[]).map(Z),widget:{customFields:e.config?.customFields??[],description:e.description??null,fields:{memberId:n.memberId??!1,merchSize:n.merchSize??!1,phone:n.phone??!1,promoCode:n.promoCode??!1,serviceFee:n.serviceFee??!1,shipping:n.shipping??!1,tipping:n.tipping??!1},id:e.id??``,name:e.name??`Lockerverse widget`,showCommunityBranding:e.showCommunityBranding??!0,title:e.title??null}}}function ne(e){return $(e)}function re(e){return $(e)}function Q(e){return $(e)}function $(e){return C(structuredClone(e))}function ie(e){let{apiBaseUrl:t,communitySlug:n,communitySlugValue:r,environment:i,fetchImplementation:a,onError:o,requestTimeoutMs:s,sentryDsn:c,stripePublishableKey:l,widgetSlug:u,widgetSlugValue:d}=M(e),f=b({communitySlug:r,environment:i,getContext:()=>({widgetSlug:d}),onError:o,resourceContextName:`lockerverse_widget`,sentryDsn:c}),{requestJson:p}=T(a,f,s),m=`${t}/v2/community/${n}/payment-widgets/${u}/checkout`;function h(e,t,n=`invalid_selection`){throw f(new k({code:n,message:e,operation:t,reportable:!1}))}function g(e,t){return e instanceof k?e:new k({...t,reportable:!0})}function _(e,t,n=!1){let r=g(e,t),i=n&&(r.status===void 0||r.status>=500);throw f(i?new k({code:r.code,message:r.message,operation:r.operation,recoveryRecommended:!0,reportable:r.reportable,...r.status===void 0?{}:{status:r.status}}):r)}function v(e,t){let n;try{n=N(e)}catch{h(`Checkout pricing input is invalid.`,t)}let r=n.email?.trim().toLowerCase(),i=n.promoCode?.trim();return{...r?{email:r}:{},...n.includeServiceFee===void 0?{}:{includeServiceFee:n.includeServiceFee},...i?{promoCode:i}:{},...n.tipCents===void 0?{}:{tipCents:n.tipCents}}}function y(e){(!(e&&typeof e==`object`)||Array.isArray(e))&&h(`Checkout selection is invalid.`,`calculate_total`);let{items:t,...n}=e;try{return{items:I(t),pricing:v(n,`calculate_total`)}}catch(e){if(e instanceof k)throw e;h(`Checkout selection is invalid.`,`calculate_total`)}}function x(e){try{if(!(e&&typeof e==`object`)||Array.isArray(e))throw TypeError(`Invalid quote.`);let t=e;if(t.authoritative!==!0||t.paymentOption!==`one-time`||typeof t.paymentReference!=`string`||t.paymentReference.length===0||t.payment.currency!==`usd`||t.payment.publishableKey!==l)throw TypeError(`Invalid quote.`);let n=J({...t,connectedAccountId:t.payment.connectedAccountId});if(n.paymentOption!==`one-time`)throw TypeError(`Unsupported checkout cadence.`);let{connectedAccountId:r,paymentOption:i,...a}=n;return C({...a,authoritative:!0,payment:{connectedAccountId:r,currency:`usd`,publishableKey:l},paymentOption:`one-time`,paymentReference:t.paymentReference})}catch{h(`Lockerverse payment submission is invalid.`,`submit_payment`,`payment_submit_failed`)}}function S(e){try{if(!(e&&typeof e==`object`)||Array.isArray(e))throw TypeError(`Invalid payment input.`);let{checkout:t,submission:n}=e;if(!(t&&typeof t==`object`)||Array.isArray(t))throw TypeError(`Invalid prepared checkout.`);let r=t,i=I(r.items),a=v(r.pricing,`submit_payment`),o=x(r),s=P(n),c=s.email.trim().toLowerCase();return(!c||c!==a.email)&&h(`Payment email must match the current checkout quote.`,`submit_payment`),{items:i,pricing:a,quote:o,submission:{...s,email:c}}}catch(e){if(e instanceof k)throw e;h(`Lockerverse payment submission is invalid.`,`submit_payment`,`payment_submit_failed`)}}return{async calculateTotal(e){let{items:t,pricing:n}=y(e),r={code:`total_calculation_failed`,message:`Lockerverse returned an invalid checkout total.`,operation:`calculate_total`};try{let e=await p(`${m}/quote`,{body:JSON.stringify({...n,items:t}),headers:{"Content-Type":`application/json`},method:`POST`},J,{...r,message:`Unable to calculate the Lockerverse checkout total because the request failed.`,report:!1},{...r,report:!1});if(!e.ok)throw new k({...r,message:`Unable to calculate the Lockerverse checkout total (${e.response.status}).`,reportable:e.response.status>=500,status:e.response.status});if(e.value.paymentOption!==`one-time`)throw new k({...r,message:`Lockerverse returned an unsupported checkout cadence.`,reportable:!0});let{connectedAccountId:i,paymentOption:a,...o}=e.value;return re(C({...o,authoritative:!0,items:t,payment:{connectedAccountId:i,currency:`usd`,publishableKey:l},paymentOption:`one-time`,paymentReference:globalThis.crypto.randomUUID(),pricing:n}))}catch(e){_(e,r)}},async getPaymentStatus(e){(typeof e!=`string`||!e.trim())&&h(`Provide a payment reference to recover its status.`,`get_payment_status`);let t=e.trim(),n={code:`payment_status_failed`,message:`Lockerverse returned an invalid payment status.`,operation:`get_payment_status`};try{let e=await p(`${m}/${encodeURIComponent(t)}/status`,void 0,Y,{...n,message:`Unable to recover the Lockerverse payment status because the request failed.`,report:!1},{...n,report:!1});if(!e.ok)throw new k({...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 k({...n,reportable:!0});return Q(e.value)}catch(e){_(e,n)}},async load(){let e={code:`widget_load_failed`,message:`Lockerverse returned an invalid widget catalog.`,operation:`load_widget`};try{let r=await p(`${t}/v2/community/${n}/payment-widgets/${u}`,void 0,X,{...e,message:`Unable to load Lockerverse widget because the request failed.`,report:!1},{...e,report:!1});if(!r.ok)throw new k({...e,message:`Unable to load Lockerverse widget (${r.response.status}).`,reportable:r.response.status>=500,status:r.response.status});return ne(C(te(r.value,l)))}catch(t){_(t,e)}},async submitPayment(e){let{items:t,pricing:n,quote:r,submission:i}=S(e),a={code:`payment_submit_failed`,message:`Lockerverse returned an invalid payment confirmation.`,operation:`submit_payment`};try{let e=await p(`${m}/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}),headers:{"Content-Type":`application/json`},method:`POST`},Y,{...a,message:`Unable to submit the Lockerverse payment because the request failed.`,report:!1},{...a,report:!1});if(!e.ok)throw new k({...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 k({...a,reportable:!0});return Q(e.value)}catch(e){_(e,a,!0)}}}}export{A as LOCKERVERSE_SDK_VERSION,k as LockerverseSdkError,ie as createLockerverseCheckoutClient};
|
|
2
2
|
//# sourceMappingURL=checkout.js.map
|
package/dist/checkout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.js","names":[],"sources":["../src/checkout-environment.ts","../src/checkout-input-schemas.ts","../src/checkout-schemas.ts","../src/snapshots.ts","../src/checkout-client.ts"],"sourcesContent":["import { resolveResourceEnvironment } from \"./environment.ts\";\nimport type {\n CreateLockerverseWidgetOptions,\n LockerverseEnvironment,\n} from \"./types.ts\";\n\nconst STRIPE_PUBLISHABLE_KEYS: Record<LockerverseEnvironment, string> = {\n development:\n \"pk_test_51O7FkjDHAhgRuLtFHdkXdIe8T5i7rOVaG9PCtDetK3UUVKojVUEKHmQacGzigf9mOX1wz3zSOKoYwFjRcTfML9PU00OjJko2lk\",\n production:\n \"pk_live_51O7FkjDHAhgRuLtFlzLdxJrwo7F09WCKTlzT9lnBePjOGizWnuijkH9oCkoAddkmBT8ngIuqAPkDiHlPEAH4KXbz00Tm0DaPT4\",\n};\n\nexport function resolveWidgetEnvironment(\n options: CreateLockerverseWidgetOptions\n) {\n const runtime = resolveResourceEnvironment(options, \"widgetSlug\");\n return {\n ...runtime,\n stripePublishableKey: STRIPE_PUBLISHABLE_KEYS[runtime.environment],\n widgetSlug: runtime.resourceSlug,\n widgetSlugValue: runtime.resourceSlugValue,\n };\n}\n","import {\n array,\n boolean,\n check,\n maxLength,\n minLength,\n nullable,\n optional,\n parser,\n picklist,\n pipe,\n record,\n strictObject,\n string,\n union,\n} from \"valibot\";\n\nimport { nonEmptyStringSchema, safeIntegerSchema } from \"./schema-helpers.ts\";\n\nconst checkoutItemSchema = union([\n strictObject({\n amountCents: safeIntegerSchema(1),\n productSlug: nonEmptyStringSchema,\n }),\n strictObject({\n productSlug: nonEmptyStringSchema,\n quantity: safeIntegerSchema(1),\n }),\n]);\n\nconst metadataSchema = pipe(\n record(\n pipe(string(), minLength(1), maxLength(40)),\n pipe(string(), maxLength(500))\n ),\n check((metadata) => Object.keys(metadata).length <= 50)\n);\n\nexport const parseCreateCheckoutSessionInput = parser(\n strictObject({\n email: optional(string()),\n includeServiceFee: optional(boolean()),\n items: pipe(array(checkoutItemSchema), minLength(1)),\n metadata: optional(metadataSchema),\n requestKey: nonEmptyStringSchema,\n returnUrl: nonEmptyStringSchema,\n tipCents: optional(safeIntegerSchema(0)),\n })\n);\n\nexport const parseCheckoutSessionDiscountInput = parser(\n strictObject({\n paymentReference: nonEmptyStringSchema,\n promoCode: optional(string()),\n })\n);\n\nexport const parseCheckoutSessionPricingInput = parser(\n strictObject({\n includeServiceFee: boolean(),\n paymentReference: nonEmptyStringSchema,\n tipCents: safeIntegerSchema(0),\n })\n);\n\nexport const parseCheckoutSessionDetailsInput = parser(\n strictObject({\n customFieldAnswers: optional(\n array(\n strictObject({\n fieldId: nonEmptyStringSchema,\n value: optional(nullable(union([string(), array(string())]))),\n })\n )\n ),\n email: nonEmptyStringSchema,\n memberId: optional(string()),\n merchSize: optional(picklist([\"XS\", \"S\", \"M\", \"L\", \"XL\", \"XXL\", \"XXXL\"])),\n paymentReference: nonEmptyStringSchema,\n phone: optional(string()),\n })\n);\n","import {\n array,\n boolean,\n check,\n type InferOutput,\n literal,\n nullable,\n object,\n optional,\n parser,\n picklist,\n pipe,\n string,\n transform,\n variant,\n} from \"valibot\";\n\nimport {\n customFieldsSchema,\n nonEmptyStringSchema,\n optionalNullableStringSchema,\n safeIntegerSchema,\n} from \"./schema-helpers.ts\";\n\nconst paymentOptionSchema = picklist([\"one-time\", \"monthly\", \"annually\"]);\nconst nullableNonNegativeIntegerSchema = nullable(safeIntegerSchema(0));\n\nconst productBaseEntries = {\n description: optionalNullableStringSchema,\n id: nonEmptyStringSchema,\n inventoryQuantity: nullableNonNegativeIntegerSchema,\n maxQuantity: nullableNonNegativeIntegerSchema,\n minimumAmountCents: nullableNonNegativeIntegerSchema,\n minQuantity: nullableNonNegativeIntegerSchema,\n name: nonEmptyStringSchema,\n paymentOption: paymentOptionSchema,\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\nconst communitySchema = object({\n color: optionalNullableStringSchema,\n name: nonEmptyStringSchema,\n thumbnail: optionalNullableStringSchema,\n});\n\nexport const publicWidgetSchema = pipe(\n object({\n community: optional(communitySchema),\n config: optional(\n object({\n customFields: customFieldsSchema,\n fields: widgetFieldsSchema,\n })\n ),\n description: optionalNullableStringSchema,\n id: optional(string(), \"\"),\n name: optional(string(), \"Lockerverse widget\"),\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\nexport const paymentResultSchema = object({\n checkoutId: nonEmptyStringSchema,\n checkoutStatus: picklist([\"action_required\", \"failed\", \"pending\", \"success\"]),\n clientSecret: nullable(string()),\n paymentReference: nonEmptyStringSchema,\n requiresAction: boolean(),\n status: nullable(string()),\n});\n\nexport const checkoutSessionSchema = object({\n catalog: publicWidgetSchema,\n checkoutId: nonEmptyStringSchema,\n clientSecret: nonEmptyStringSchema,\n connectedAccountId: nullable(nonEmptyStringSchema),\n paymentReference: nonEmptyStringSchema,\n pricing: object({\n discountCents: safeIntegerSchema(0),\n includeServiceFee: boolean(),\n serviceFeeCents: safeIntegerSchema(0),\n subtotalCents: safeIntegerSchema(0),\n tipCents: safeIntegerSchema(0),\n totalCents: safeIntegerSchema(0),\n }),\n sessionId: nonEmptyStringSchema,\n});\n\nexport const checkoutSessionDiscountSchema = object({\n discountCents: safeIntegerSchema(0),\n paymentReference: nonEmptyStringSchema,\n totalCents: safeIntegerSchema(0),\n});\n\nexport const checkoutSessionDetailsSchema = object({\n paymentReference: nonEmptyStringSchema,\n totalCents: safeIntegerSchema(0),\n});\n\nexport const checkoutSessionPricingSchema = object({\n includeServiceFee: boolean(),\n paymentReference: nonEmptyStringSchema,\n serviceFeeCents: safeIntegerSchema(0),\n tipCents: safeIntegerSchema(0),\n totalCents: safeIntegerSchema(0),\n});\n\nexport type PublicProductListing = InferOutput<typeof productListingSchema>;\nexport type PublicWidget = InferOutput<typeof publicWidgetSchema>;\n\nexport const parseCheckoutSession = parser(checkoutSessionSchema);\nexport const parseCheckoutSessionDiscount = parser(\n checkoutSessionDiscountSchema\n);\nexport const parseCheckoutSessionDetails = parser(checkoutSessionDetailsSchema);\nexport const parseCheckoutSessionPricing = parser(checkoutSessionPricingSchema);\nexport const parsePaymentResult = parser(paymentResultSchema);\n","import type { PublicProductListing, PublicWidget } from \"./checkout-schemas.ts\";\nimport { deepFreeze } from \"./deep-freeze.ts\";\nimport type {\n LockerverseCatalog,\n LockerversePaymentResult,\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 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(\n widget: PublicWidget,\n publishableKey: string\n): LockerverseCatalog {\n const fields = widget.config?.fields ?? {};\n\n return {\n community: widget.community\n ? {\n accentColor: widget.community.color ?? null,\n imageUrl: widget.community.thumbnail ?? null,\n name: widget.community.name,\n }\n : null,\n payment: {\n currency: \"usd\",\n 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 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 { resolveWidgetEnvironment } from \"./checkout-environment.ts\";\nimport {\n parseCheckoutSessionDetailsInput,\n parseCheckoutSessionDiscountInput,\n parseCheckoutSessionPricingInput,\n parseCreateCheckoutSessionInput,\n} from \"./checkout-input-schemas.ts\";\nimport {\n parseCheckoutSession,\n parseCheckoutSessionDetails,\n parseCheckoutSessionDiscount,\n parseCheckoutSessionPricing,\n parsePaymentResult,\n} from \"./checkout-schemas.ts\";\nimport { deepFreeze } from \"./deep-freeze.ts\";\nimport { createSdkErrorReporter } from \"./error-reporting.ts\";\nimport { clonePaymentResult, createCatalog } from \"./snapshots.ts\";\nimport { createTransport } from \"./transport.ts\";\nimport {\n type CreateLockerverseWidgetOptions,\n type LockerverseCheckoutClient,\n LockerverseSdkError,\n type LockerverseSdkOperation,\n} from \"./types.ts\";\n\ntype OperationErrorContext = {\n code:\n | \"payment_status_failed\"\n | \"session_create_failed\"\n | \"session_update_failed\";\n message: string;\n operation:\n | \"create_session\"\n | \"get_payment_status\"\n | \"update_session_details\"\n | \"update_session_discount\"\n | \"update_session_pricing\";\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 stripePublishableKey,\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 widgetUrl = `${apiBaseUrl}/v2/community/${communitySlug}/payment-widgets/${widgetSlug}`;\n const sessionUrl = `${widgetUrl}/checkout/session`;\n\n function invalidInput(\n message: string,\n operation: LockerverseSdkOperation\n ): never {\n throw reportError(\n new LockerverseSdkError({\n code: \"invalid_selection\",\n message,\n operation,\n reportable: false,\n })\n );\n }\n\n function failOperation(\n error: unknown,\n context: OperationErrorContext\n ): never {\n throw reportError(\n error instanceof LockerverseSdkError\n ? error\n : new LockerverseSdkError({ ...context, reportable: true })\n );\n }\n\n function normalizeCreateSessionInput(input: unknown) {\n try {\n const parsed = parseCreateCheckoutSessionInput(input);\n const returnUrl = new URL(parsed.returnUrl);\n if (\n !(returnUrl.protocol === \"http:\" || returnUrl.protocol === \"https:\")\n ) {\n throw new TypeError(\"Invalid return URL.\");\n }\n const email = parsed.email?.trim().toLowerCase();\n return {\n ...(email ? { email } : {}),\n ...(parsed.includeServiceFee === undefined\n ? {}\n : { includeServiceFee: parsed.includeServiceFee }),\n items: parsed.items,\n ...(parsed.metadata ? { metadata: parsed.metadata } : {}),\n requestKey: parsed.requestKey.trim(),\n returnUrl: returnUrl.toString(),\n ...(parsed.tipCents === undefined ? {} : { tipCents: parsed.tipCents }),\n };\n } catch {\n invalidInput(\"Checkout Session input is invalid.\", \"create_session\");\n }\n }\n\n return {\n async createSession(input) {\n const normalized = normalizeCreateSessionInput(input);\n const context = {\n code: \"session_create_failed\" as const,\n message: \"Lockerverse returned an invalid Checkout Session.\",\n operation: \"create_session\" as const,\n };\n try {\n const response = await requestJson(\n sessionUrl,\n {\n body: JSON.stringify(normalized),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"POST\",\n },\n parseCheckoutSession,\n {\n ...context,\n message:\n \"Unable to create the Lockerverse Checkout Session 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 create the Lockerverse Checkout Session (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n const { catalog, ...session } = response.value;\n return deepFreeze({\n ...session,\n catalog: createCatalog(catalog, stripePublishableKey),\n });\n } catch (error) {\n failOperation(error, context);\n }\n },\n async getPaymentStatus(paymentReference) {\n if (typeof paymentReference !== \"string\" || !paymentReference.trim()) {\n invalidInput(\n \"Provide a payment reference to recover its status.\",\n \"get_payment_status\"\n );\n }\n const normalizedReference = paymentReference.trim();\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 `${widgetUrl}/checkout/${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 stripePublishableKey,\n async updateSessionDetails(input) {\n let parsed: ReturnType<typeof parseCheckoutSessionDetailsInput>;\n try {\n parsed = parseCheckoutSessionDetailsInput(input);\n } catch {\n invalidInput(\n \"Checkout Session details are invalid.\",\n \"update_session_details\"\n );\n }\n const paymentReference = parsed.paymentReference.trim();\n const context = {\n code: \"session_update_failed\" as const,\n message: \"Lockerverse returned invalid Checkout Session details.\",\n operation: \"update_session_details\" as const,\n };\n try {\n const body = {\n ...(parsed.customFieldAnswers\n ? { customFieldAnswers: parsed.customFieldAnswers }\n : {}),\n email: parsed.email.trim().toLowerCase(),\n ...(parsed.memberId?.trim()\n ? { memberId: parsed.memberId.trim() }\n : {}),\n ...(parsed.merchSize ? { merchSize: parsed.merchSize } : {}),\n ...(parsed.phone?.trim() ? { phone: parsed.phone.trim() } : {}),\n };\n const response = await requestJson(\n `${sessionUrl}/${encodeURIComponent(paymentReference)}/details`,\n {\n body: JSON.stringify(body),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"PATCH\",\n },\n parseCheckoutSessionDetails,\n { ...context, report: false },\n { ...context, report: false }\n );\n if (!response.ok) {\n throw new LockerverseSdkError({\n ...context,\n message: `Unable to save the Lockerverse Checkout Session details (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n if (response.value.paymentReference !== paymentReference) {\n throw new LockerverseSdkError({ ...context, reportable: true });\n }\n return deepFreeze({ ...response.value });\n } catch (error) {\n failOperation(error, context);\n }\n },\n async updateSessionDiscount(input) {\n let parsed: ReturnType<typeof parseCheckoutSessionDiscountInput>;\n try {\n parsed = parseCheckoutSessionDiscountInput(input);\n } catch {\n invalidInput(\n \"Checkout Session discount input is invalid.\",\n \"update_session_discount\"\n );\n }\n const paymentReference = parsed.paymentReference.trim();\n const promoCode = parsed.promoCode?.trim();\n const context = {\n code: \"session_update_failed\" as const,\n message: \"Lockerverse returned an invalid Checkout Session update.\",\n operation: \"update_session_discount\" as const,\n };\n try {\n const response = await requestJson(\n `${sessionUrl}/${encodeURIComponent(paymentReference)}/discount`,\n {\n body: JSON.stringify(promoCode ? { promoCode } : {}),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"PATCH\",\n },\n parseCheckoutSessionDiscount,\n {\n ...context,\n message:\n \"Unable to update the Lockerverse Checkout Session 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 update the Lockerverse Checkout Session (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n if (response.value.paymentReference !== paymentReference) {\n throw new LockerverseSdkError({ ...context, reportable: true });\n }\n return deepFreeze({ ...response.value });\n } catch (error) {\n failOperation(error, context);\n }\n },\n async updateSessionPricing(input) {\n let parsed: ReturnType<typeof parseCheckoutSessionPricingInput>;\n try {\n parsed = parseCheckoutSessionPricingInput(input);\n } catch {\n invalidInput(\n \"Checkout Session pricing input is invalid.\",\n \"update_session_pricing\"\n );\n }\n const paymentReference = parsed.paymentReference.trim();\n const context = {\n code: \"session_update_failed\" as const,\n message: \"Lockerverse returned invalid Checkout Session pricing.\",\n operation: \"update_session_pricing\" as const,\n };\n try {\n const response = await requestJson(\n `${sessionUrl}/${encodeURIComponent(paymentReference)}/pricing`,\n {\n body: JSON.stringify({\n includeServiceFee: parsed.includeServiceFee,\n tipCents: parsed.tipCents,\n }),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"PATCH\",\n },\n parseCheckoutSessionPricing,\n { ...context, report: false },\n { ...context, report: false }\n );\n if (!response.ok) {\n throw new LockerverseSdkError({\n ...context,\n message: `Unable to update Lockerverse Checkout Session pricing (${response.response.status}).`,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n if (response.value.paymentReference !== paymentReference) {\n throw new LockerverseSdkError({ ...context, reportable: true });\n }\n return deepFreeze({ ...response.value });\n } catch (error) {\n failOperation(error, context);\n }\n },\n };\n}\n"],"mappings":"wPAMA,MAAM,EAAkE,CACtE,YACE,8GACF,WACE,6GACJ,EAEA,SAAgB,EACd,EACA,CACA,IAAM,EAAU,EAA2B,EAAS,YAAY,EAChE,MAAO,CACL,GAAG,EACH,qBAAsB,EAAwB,EAAQ,aACtD,WAAY,EAAQ,aACpB,gBAAiB,EAAQ,iBAC3B,CACF,CCJA,MAAM,EAAqB,EAAM,CAC/B,EAAa,CACX,YAAa,EAAkB,CAAC,EAChC,YAAa,CACf,CAAC,EACD,EAAa,CACX,YAAa,EACb,SAAU,EAAkB,CAAC,CAC/B,CAAC,CACH,CAAC,EAEK,EAAiB,EACrB,EACE,EAAK,EAAO,EAAG,EAAU,CAAC,EAAG,EAAU,EAAE,CAAC,EAC1C,EAAK,EAAO,EAAG,EAAU,GAAG,CAAC,CAC/B,EACA,EAAO,GAAa,OAAO,KAAK,CAAQ,CAAC,CAAC,QAAU,EAAE,CACxD,EAEa,EAAkC,EAC7C,EAAa,CACX,MAAO,EAAS,EAAO,CAAC,EACxB,kBAAmB,EAAS,EAAQ,CAAC,EACrC,MAAO,EAAK,EAAM,CAAkB,EAAG,EAAU,CAAC,CAAC,EACnD,SAAU,EAAS,CAAc,EACjC,WAAY,EACZ,UAAW,EACX,SAAU,EAAS,EAAkB,CAAC,CAAC,CACzC,CAAC,CACH,EAEa,EAAoC,EAC/C,EAAa,CACX,iBAAkB,EAClB,UAAW,EAAS,EAAO,CAAC,CAC9B,CAAC,CACH,EAEa,EAAmC,EAC9C,EAAa,CACX,kBAAmB,EAAQ,EAC3B,iBAAkB,EAClB,SAAU,EAAkB,CAAC,CAC/B,CAAC,CACH,EAEa,EAAmC,EAC9C,EAAa,CACX,mBAAoB,EAClB,EACE,EAAa,CACX,QAAS,EACT,MAAO,EAAS,EAAS,EAAM,CAAC,EAAO,EA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":["../src/checkout-environment.ts","../src/checkout-input-schemas.ts","../src/checkout-schemas.ts","../src/snapshots.ts","../src/checkout-client.ts"],"sourcesContent":["import { resolveResourceEnvironment } from \"./environment.ts\";\nimport type {\n CreateLockerverseWidgetOptions,\n LockerverseEnvironment,\n} from \"./types.ts\";\n\nconst STRIPE_PUBLISHABLE_KEYS: Record<LockerverseEnvironment, string> = {\n development:\n \"pk_test_51O7FkjDHAhgRuLtFHdkXdIe8T5i7rOVaG9PCtDetK3UUVKojVUEKHmQacGzigf9mOX1wz3zSOKoYwFjRcTfML9PU00OjJko2lk\",\n production:\n \"pk_live_51O7FkjDHAhgRuLtFlzLdxJrwo7F09WCKTlzT9lnBePjOGizWnuijkH9oCkoAddkmBT8ngIuqAPkDiHlPEAH4KXbz00Tm0DaPT4\",\n};\n\nexport function resolveWidgetEnvironment(\n options: CreateLockerverseWidgetOptions\n) {\n const runtime = resolveResourceEnvironment(options, \"widgetSlug\");\n return {\n ...runtime,\n stripePublishableKey: STRIPE_PUBLISHABLE_KEYS[runtime.environment],\n widgetSlug: runtime.resourceSlug,\n widgetSlugValue: runtime.resourceSlugValue,\n };\n}\n","import {\n array,\n boolean,\n minLength,\n optional,\n parser,\n picklist,\n pipe,\n record,\n strictObject,\n string,\n union,\n} from \"valibot\";\n\nimport {\n customFieldAnswerSchema,\n nonEmptyStringSchema,\n safeIntegerSchema,\n} from \"./schema-helpers.ts\";\n\nexport const parseCheckoutPricingInput = parser(\n optional(\n strictObject({\n email: optional(string()),\n includeServiceFee: optional(boolean()),\n promoCode: optional(string()),\n tipCents: optional(safeIntegerSchema(0)),\n }),\n {}\n )\n);\n\nexport const parsePaymentSubmission = parser(\n strictObject({\n confirmationToken: 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 })\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]);\n\nexport const parseCheckoutItems = parser(\n pipe(array(checkoutItemSchema), minLength(1))\n);\n","import {\n array,\n boolean,\n check,\n finite,\n type InferOutput,\n literal,\n maxValue,\n minValue,\n nullable,\n number,\n object,\n optional,\n parser,\n picklist,\n pipe,\n string,\n transform,\n variant,\n} from \"valibot\";\n\nimport {\n customFieldsSchema,\n nonEmptyStringSchema,\n optionalNullableStringSchema,\n safeIntegerSchema,\n} from \"./schema-helpers.ts\";\n\nconst paymentOptionSchema = picklist([\"one-time\", \"monthly\", \"annually\"]);\nconst nullableNonNegativeIntegerSchema = nullable(safeIntegerSchema(0));\n\nconst productBaseEntries = {\n description: optionalNullableStringSchema,\n id: nonEmptyStringSchema,\n inventoryQuantity: nullableNonNegativeIntegerSchema,\n maxQuantity: nullableNonNegativeIntegerSchema,\n minimumAmountCents: nullableNonNegativeIntegerSchema,\n minQuantity: nullableNonNegativeIntegerSchema,\n name: nonEmptyStringSchema,\n paymentOption: paymentOptionSchema,\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 community: optional(\n object({\n color: string(),\n name: nonEmptyStringSchema,\n thumbnail: string(),\n })\n ),\n config: optional(\n object({\n customFields: customFieldsSchema,\n fields: widgetFieldsSchema,\n })\n ),\n description: optionalNullableStringSchema,\n id: optional(string(), \"\"),\n name: optional(string(), \"Lockerverse widget\"),\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 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 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 = 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\nexport const paymentResultSchema = object({\n checkoutId: nonEmptyStringSchema,\n checkoutStatus: picklist([\"action_required\", \"failed\", \"pending\", \"success\"]),\n clientSecret: nullable(string()),\n paymentReference: nonEmptyStringSchema,\n requiresAction: boolean(),\n status: nullable(string()),\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 parsePaymentResult = parser(paymentResultSchema);\nexport const parsePublicWidget = parser(publicWidgetSchema);\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 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(\n widget: PublicWidget,\n publishableKey: string\n): LockerverseCatalog {\n const fields = widget.config?.fields ?? {};\n\n return {\n community: widget.community\n ? {\n accentColor: widget.community.color,\n imageUrl: widget.community.thumbnail,\n name: widget.community.name,\n }\n : null,\n payment: {\n currency: \"usd\",\n 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 { resolveWidgetEnvironment } from \"./checkout-environment.ts\";\nimport {\n parseCheckoutItems,\n parseCheckoutPricingInput,\n parsePaymentSubmission,\n} from \"./checkout-input-schemas.ts\";\nimport {\n parseCheckoutQuote,\n parsePaymentResult,\n parsePublicWidget,\n} from \"./checkout-schemas.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 LockerverseCheckoutClient,\n type LockerverseCheckoutQuote,\n LockerverseSdkError,\n type LockerverseSdkOperation,\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\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 stripePublishableKey,\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\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(\n error: unknown,\n context: OperationErrorContext\n ) {\n return error instanceof LockerverseSdkError\n ? error\n : new LockerverseSdkError({ ...context, reportable: true });\n }\n\n function failOperation(\n error: unknown,\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 throw reportError(\n recoveryRecommended\n ? new LockerverseSdkError({\n code: normalized.code,\n message: normalized.message,\n operation: normalized.operation,\n recoveryRecommended: true,\n reportable: normalized.reportable,\n ...(normalized.status === undefined\n ? {}\n : { status: normalized.status }),\n })\n : normalized\n );\n }\n\n function normalizePricingInput(\n input: unknown,\n operation: \"calculate_total\" | \"submit_payment\"\n ) {\n let parsed: ReturnType<typeof parseCheckoutPricingInput>;\n try {\n parsed = parseCheckoutPricingInput(input);\n } catch {\n invalidInput(\"Checkout pricing input is invalid.\", operation);\n }\n const email = parsed.email?.trim().toLowerCase();\n const promoCode = parsed.promoCode?.trim();\n return {\n ...(email ? { email } : {}),\n ...(parsed.includeServiceFee === undefined\n ? {}\n : { includeServiceFee: parsed.includeServiceFee }),\n ...(promoCode ? { promoCode } : {}),\n ...(parsed.tipCents === undefined ? {} : { tipCents: parsed.tipCents }),\n };\n }\n\n function normalizeCalculateTotalInput(input: unknown) {\n if (!(input && typeof input === \"object\") || Array.isArray(input)) {\n invalidInput(\"Checkout selection is invalid.\", \"calculate_total\");\n }\n const { items, ...pricingInput } = input as Record<string, unknown>;\n try {\n return {\n items: parseCheckoutItems(items),\n pricing: normalizePricingInput(pricingInput, \"calculate_total\"),\n };\n } catch (error) {\n if (error instanceof LockerverseSdkError) {\n throw error;\n }\n invalidInput(\"Checkout selection is invalid.\", \"calculate_total\");\n }\n }\n\n function normalizeQuote(input: unknown) {\n try {\n if (!(input && typeof input === \"object\") || Array.isArray(input)) {\n throw new TypeError(\"Invalid quote.\");\n }\n const quoteInput = input as LockerverseCheckoutQuote;\n if (\n quoteInput.authoritative !== true ||\n quoteInput.paymentOption !== \"one-time\" ||\n typeof quoteInput.paymentReference !== \"string\" ||\n quoteInput.paymentReference.length === 0 ||\n quoteInput.payment.currency !== \"usd\" ||\n quoteInput.payment.publishableKey !== stripePublishableKey\n ) {\n throw new TypeError(\"Invalid quote.\");\n }\n const parsed = parseCheckoutQuote({\n ...quoteInput,\n connectedAccountId: quoteInput.payment.connectedAccountId,\n });\n if (parsed.paymentOption !== \"one-time\") {\n throw new TypeError(\"Unsupported checkout cadence.\");\n }\n const {\n connectedAccountId,\n paymentOption: _paymentOption,\n ...quote\n } = parsed;\n return deepFreeze({\n ...quote,\n authoritative: true as const,\n payment: {\n connectedAccountId,\n currency: \"usd\" as const,\n publishableKey: stripePublishableKey,\n },\n paymentOption: \"one-time\" as const,\n paymentReference: quoteInput.paymentReference,\n });\n } catch {\n invalidInput(\n \"Lockerverse payment submission is invalid.\",\n \"submit_payment\",\n \"payment_submit_failed\"\n );\n }\n }\n\n function normalizeSubmitPaymentInput(input: unknown) {\n try {\n if (!(input && typeof input === \"object\") || Array.isArray(input)) {\n throw new TypeError(\"Invalid payment input.\");\n }\n const { checkout, submission: submissionInput } = input as Record<\n string,\n unknown\n >;\n if (\n !(checkout && typeof checkout === \"object\") ||\n Array.isArray(checkout)\n ) {\n throw new TypeError(\"Invalid prepared checkout.\");\n }\n const checkoutInput = checkout as Record<string, unknown>;\n const items = parseCheckoutItems(checkoutInput.items);\n const pricing = normalizePricingInput(\n checkoutInput.pricing,\n \"submit_payment\"\n );\n const quote = normalizeQuote(checkoutInput);\n const submission = parsePaymentSubmission(submissionInput);\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 async calculateTotal(input) {\n const { 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 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 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 if (response.value.paymentOption !== \"one-time\") {\n throw new LockerverseSdkError({\n ...context,\n message: \"Lockerverse returned an unsupported checkout cadence.\",\n reportable: true,\n });\n }\n const {\n connectedAccountId,\n paymentOption: _paymentOption,\n ...quote\n } = response.value;\n return clonePreparedCheckout(\n deepFreeze({\n ...quote,\n authoritative: true as const,\n items,\n payment: {\n connectedAccountId,\n currency: \"usd\" as const,\n publishableKey: stripePublishableKey,\n },\n paymentOption: \"one-time\" as const,\n paymentReference: globalThis.crypto.randomUUID(),\n pricing,\n })\n );\n } catch (error) {\n failOperation(error, context);\n }\n },\n async getPaymentStatus(paymentReference) {\n if (typeof paymentReference !== \"string\" || !paymentReference.trim()) {\n invalidInput(\n \"Provide a payment reference to recover its status.\",\n \"get_payment_status\"\n );\n }\n const normalizedReference = paymentReference.trim();\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 async load() {\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 const response = await requestJson(\n `${apiBaseUrl}/v2/community/${communitySlug}/payment-widgets/${widgetSlug}`,\n undefined,\n parsePublicWidget,\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 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 return cloneCatalog(\n deepFreeze(createCatalog(response.value, stripePublishableKey))\n );\n } catch (error) {\n failOperation(error, context);\n }\n },\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 }),\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 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"],"mappings":"qRAMA,MAAM,EAAkE,CACtE,YACE,8GACF,WACE,6GACJ,EAEA,SAAgB,EACd,EACA,CACA,IAAM,EAAU,EAA2B,EAAS,YAAY,EAChE,MAAO,CACL,GAAG,EACH,qBAAsB,EAAwB,EAAQ,aACtD,WAAY,EAAQ,aACpB,gBAAiB,EAAQ,iBAC3B,CACF,CCHA,MAAa,EAA4B,EACvC,EACE,EAAa,CACX,MAAO,EAAS,EAAO,CAAC,EACxB,kBAAmB,EAAS,EAAQ,CAAC,EACrC,UAAW,EAAS,EAAO,CAAC,EAC5B,SAAU,EAAS,EAAkB,CAAC,CAAC,CACzC,CAAC,EACD,CAAC,CACH,CACF,EAEa,EAAyB,EACpC,EAAa,CACX,kBAAmB,EACnB,mBAAoB,EAAS,EAAM,CAAuB,CAAC,EAC3D,MAAO,EAAO,EACd,SAAU,EAAS,EAAO,CAAC,EAC3B,UAAW,EAAS,EAAS,CAAC,KAAM,IAAK,IAAK,IAAK,KAAM,MAAO,MAAM,CAAC,CAAC,EACxE,SAAU,EAAS,EAAO,EAAO,EAAG,EAAO,CAAC,CAAC,EAC7C,MAAO,EAAS,EAAO,CAAC,CAC1B,CAAC,CACH,EAEM,EAAqB,EAAM,CAC/B,EAAa,CACX,YAAa,EAAkB,CAAC,EAChC,UAAW,CACb,CAAC,EACD,EAAa,CACX,UAAW,EACX,SAAU,EAAkB,CAAC,CAC/B,CAAC,CACH,CAAC,EAEY,EAAqB,EAChC,EAAK,EAAM,CAAkB,EAAG,GAAU,CAAC,CAAC,CAC9C,EC7BM,EAAsB,EAAS,CAAC,WAAY,UAAW,UAAU,CAAC,EAClE,EAAmC,EAAS,EAAkB,CAAC,CAAC,EAEhE,EAAqB,CACzB,YAAa,EACb,GAAI,EACJ,kBAAm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OAAQ,MACV,EACA,EACA,CACE,GAAG,EACH,QACE,uEACF,OAAQ,EACV,EACA,CAAE,GAAG,EAAS,OAAQ,EAAM,CAC9B,EACA,GAAI,CAAC,EAAS,GACZ,MAAM,IAAI,EAAoB,CAC5B,GAAG,EACH,QAAS,6CAA6C,EAAS,SAAS,OAAO,IAC/E,WAAY,EAAS,SAAS,QAAU,IACxC,OAAQ,EAAS,SAAS,MAC5B,CAAC,EAEH,GAAI,EAAS,MAAM,mBAAqB,EAAM,iBAC5C,MAAM,IAAI,EAAoB,CAAE,GAAG,EAAS,WAAY,EAAK,CAAC,EAEhE,OAAO,EAAmB,EAAS,KAAK,CAC1C,OAAS,EAAO,CACd,EAAc,EAAO,EAAS,EAAI,CACpC,CACF,CACF,CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as LockerverseSdkOperation, O as LockerverseSdkError, k as LockerverseSdkErrorCode, n as LOCKERVERSE_SDK_VERSION, y as LockerverseEnvironment } from "./types.js";
|
|
2
2
|
export { LOCKERVERSE_SDK_VERSION, type LockerverseEnvironment, LockerverseSdkError, type LockerverseSdkErrorCode, type LockerverseSdkOperation };
|
package/dist/signup.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { O as LockerverseSdkError, _ as LockerverseCustomFieldAnswerValue, g as LockerverseCustomFieldAnswer, h as LockerverseCustomField, v as LockerverseCustomFieldOption, y as LockerverseEnvironment } from "./types.js";
|
|
2
2
|
//#region src/signup-types.d.ts
|
|
3
3
|
type LockerverseSignupField = {
|
|
4
4
|
enabled: boolean;
|
package/dist/signup.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{A as e,C as t,E as n,O as r,S as i,a,b as o,c as s,d as c,f as l,h as u,i as d,k as f,n as p,o as m,r as h,s as g,t as _,u as v,w as y}from"./transport.js";import{n as b}from"./types.js";const x=r({city:f(),country:f(),line1:f(),line2:t(o(f())),postalCode:f(),state:f()}),S=y(r({address:t(o(x)),answers:t(c(d)),email:t(o(f())),honeypot:t(f()),name:m,participantCount:t(o(s(0))),phone:t(o(f()))})),C=i({enabled:l(),required:l()}),w=n(i({config:i({builtInFields:i({address:C,email:C,name:C,participantCount:C,phone:C}),customFields:a}),coverImageUrl:g,description:g,id:m,isActive:l(),name:m,slug:m,title:g}),e(({config:e,...t})=>({...t,customFields:e.customFields,fields:e.builtInFields}))),T=i({id:m,submittedAt:n(f(),u())}),E=y(w),D=y(T);function O(e){let t=h(e),n=new Set;return{commit(e){t=h(e);for(let e of[...n])try{e(t)}catch{}},getState(){return t},subscribe(e){n.add(e);try{e(t)}catch{}return()=>{n.delete(e)}}}}function k(e){let t=v(e),n=O({phase:`idle`}),r=null,i=!1,a=!1,o=p({communitySlug:t.communitySlugValue,environment:t.environment,getContext:()=>({signupSlug:t.signupSlugValue}),onError:t.onError,resourceContextName:`lockerverse_signup`,sentryDsn:t.sentryDsn}),{requestJson:s}=_(t.fetchImplementation,o,t.requestTimeoutMs);return{getState:n.getState,async load(){let e={code:`signup_load_failed`,message:`Unable to load Lockerverse signup.`,operation:`load_signup`};if(i||a)throw o(new b({...e,reportable:!1}));i=!0,r=null,n.commit({phase:`loading`});try{let i;try{i=await s(`${t.apiBaseUrl}/community/${t.communitySlug}/sign-up-widgets/${t.signupSlug}`,void 0,E,e,e)}catch(e){throw e instanceof b&&n.commit({error:e,phase:`error`,recoverableSubmissionReference:null,signup:null}),e}if(!i.ok){let t=o(new b({...e,reportable:i.response.status>=500,status:i.response.status}));throw n.commit({error:t,phase:`error`,recoverableSubmissionReference:null,signup:null}),t}let a=h(i.value);return r=a,n.commit({phase:`ready`,signup:a}),a}finally{i=!1}},async submit(e,i){let c=r,l=i?.submissionReference??globalThis.crypto.randomUUID(),u={code:`signup_submit_failed`,message:`Unable to submit Lockerverse signup.`,operation:`submit_signup`};if(!c?.isActive||a)throw o(new b({...u,reportable:!1}));let d;try{d=S(e)}catch{let e=o(new b({...u,message:`Lockerverse signup input is invalid.`,reportable:!1}));throw n.commit({error:e,phase:`error`,recoverableSubmissionReference:l,signup:c}),e}a=!0,n.commit({phase:`submitting`,signup:c,submissionReference:l});try{let e=await s(`${t.apiBaseUrl}/community/${t.communitySlug}/sign-up-widgets/${t.signupSlug}/submissions`,{body:JSON.stringify({...d,submissionReference:l}),headers:{"content-type":`application/json`},method:`POST`},D,u,u);if(!e.ok)throw o(new b({...u,reportable:e.response.status>=500,status:e.response.status}));let r=h(e.value);if(r.id!==l)throw o(new b({...u,reportable:!0}));return n.commit({phase:`submitted`,signup:c,submission:r}),r}catch(e){let t=e instanceof b?e:o(new b({...u,reportable:!1}));throw n.commit({error:t,phase:`error`,recoverableSubmissionReference:l,signup:c}),t}finally{a=!1}},subscribe:n.subscribe}}export{k as createLockerverseSignup};
|
|
2
2
|
//# sourceMappingURL=signup.js.map
|
package/dist/transport.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e}from"./types.js";const t={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function n(e){return e?{lang:e?.lang??void 0,message:e?.message,abortEarly:e?.abortEarly??void 0,abortPipeEarly:e?.abortPipeEarly??void 0}:t}function r(e){let t=typeof e;return t===`string`?`"${e}"`:t===`number`||t===`bigint`||t===`boolean`?`${e}`:t===`object`||t===`function`?(e&&Object.getPrototypeOf(e)?.constructor?.name)??`null`:t}function i(e,t,n,i,a){let o=a&&`input`in a?a.input:n.value,s=a?.expected??e.expects??null,c=a?.received??r(o),l={kind:e.kind,type:e.type,input:o,expected:s,received:c,message:`Invalid ${t}: ${s?`Expected ${s} but r`:`R`}eceived ${c}`,requirement:e.requirement,path:a?.path,issues:a?.issues,lang:i.lang,abortEarly:i.abortEarly,abortPipeEarly:i.abortPipeEarly},u=e.kind===`schema`,d=a?.message??e.message??(e.reference,l.lang,void 0)??(u?(l.lang,void 0):null)??i.message??(l.lang,void 0);d!==void 0&&(l.message=typeof d==`function`?d(l):d),u&&(n.typed=!1),n.issues?n.issues.push(l):n.issues=[l]}const a=new WeakMap;function o(e){let t=a.get(e);return t||(t={version:1,vendor:`valibot`,validate(t){return e[`~run`]({value:t},n())}},a.set(e,t)),t}function s(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!==`__proto__`&&t!==`prototype`&&t!==`constructor`}function c(e,t){let n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??`never`}var l=class extends Error{constructor(e){super(e[0].message),this.name=`ValiError`,this.issues=e}};const u=/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])[T ](?:0\d|1\d|2[0-3])(?::[0-5]\d){2}(?:\.\d{1,9})?(?:Z| ?[+-](?:0\d|1\d|2[0-3])(?::?[0-5]\d)?)$/u;function d(e,t){return{kind:`validation`,type:`check`,reference:d,async:!1,expects:null,requirement:e,message:t,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&i(this,`input`,e,t),e}}}function f(e){return{kind:`validation`,type:`iso_timestamp`,reference:f,async:!1,expects:null,requirement:u,message:e,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&i(this,`timestamp`,e,t),e}}}function p(e,t){return{kind:`validation`,type:`max_length`,reference:p,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(e,t){return e.typed&&e.value.length>this.requirement&&i(this,`length`,e,t,{received:`${e.value.length}`}),e}}}function m(e,t){return{kind:`validation`,type:`max_value`,reference:m,async:!1,expects:`<=${e instanceof Date?e.toJSON():r(e)}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!(e.value<=this.requirement)&&i(this,`value`,e,t,{received:e.value instanceof Date?e.value.toJSON():r(e.value)}),e}}}function h(e,t){return{kind:`validation`,type:`min_length`,reference:h,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(e,t){return e.typed&&e.value.length<this.requirement&&i(this,`length`,e,t,{received:`${e.value.length}`}),e}}}function g(e,t){return{kind:`validation`,type:`min_value`,reference:g,async:!1,expects:`>=${e instanceof Date?e.toJSON():r(e)}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!(e.value>=this.requirement)&&i(this,`value`,e,t,{received:e.value instanceof Date?e.value.toJSON():r(e.value)}),e}}}function _(e){return{kind:`validation`,type:`non_empty`,reference:_,async:!1,expects:`!0`,message:e,"~run"(e,t){return e.typed&&e.value.length===0&&i(this,`length`,e,t,{received:`0`}),e}}}function v(e){return{kind:`validation`,type:`safe_integer`,reference:v,async:!1,expects:null,requirement:Number.isSafeInteger,message:e,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&i(this,`safe integer`,e,t),e}}}function y(e){return{kind:`transformation`,type:`transform`,reference:y,async:!1,operation:e,"~run"(e){return e.value=this.operation(e.value),e}}}const ee={abortEarly:!0};function b(e,t,n){return typeof e.fallback==`function`?e.fallback(t,n):e.fallback}function x(e,t,n){return typeof e.default==`function`?e.default(t,n):e.default}function S(e,t){return{kind:`schema`,type:`array`,reference:S,expects:`Array`,async:!1,item:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(Array.isArray(n)){e.typed=!0,e.value=[];for(let r=0;r<n.length;r++){let i=n[r],a=this.item[`~run`]({value:i},t);if(a.issues){let o={type:`array`,origin:`value`,input:n,key:r,value:i};for(let t of a.issues)t.path?t.path.unshift(o):t.path=[o],e.issues?.push(t);if(e.issues||=a.issues,t.abortEarly){e.typed=!1;break}}a.typed||(e.typed=!1),e.value.push(a.value)}}else i(this,`type`,e,t);return e}}}function C(e){return{kind:`schema`,type:`boolean`,reference:C,expects:`boolean`,async:!1,message:e,get"~standard"(){return o(this)},"~run"(e,t){return typeof e.value==`boolean`?e.typed=!0:i(this,`type`,e,t),e}}}function w(e,t){return{kind:`schema`,type:`custom`,reference:w,expects:`unknown`,async:!1,check:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){return this.check(e.value)?e.typed=!0:i(this,`type`,e,t),e}}}function T(e,t){return{kind:`schema`,type:`literal`,reference:T,expects:r(e),async:!1,literal:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){return e.value===this.literal?e.typed=!0:i(this,`type`,e,t),e}}}function E(e,t){return{kind:`schema`,type:`loose_object`,reference:E,expects:`Object`,async:!1,entries:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in this.entries){let a=this.entries[r];if(r in n||(a.type===`exact_optional`||a.type===`optional`||a.type===`nullish`)&&a.default!==void 0){let i=r in n?n[r]:x(a),o=a[`~run`]({value:i},t);if(o.issues){let a={type:`object`,origin:`value`,input:n,key:r,value:i};for(let t of o.issues)t.path?t.path.unshift(a):t.path=[a],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value[r]=o.value}else if(a.fallback!==void 0)e.value[r]=b(a);else if(a.type!==`exact_optional`&&a.type!==`optional`&&a.type!==`nullish`&&(i(this,`key`,e,t,{input:void 0,expected:`"${r}"`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]}),t.abortEarly))break}if(!e.issues||!t.abortEarly)for(let t in n)s(n,t)&&!(t in this.entries)&&(e.value[t]=n[t])}else i(this,`type`,e,t);return e}}}function D(e,t){return{kind:`schema`,type:`nullable`,reference:D,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,get"~standard"(){return o(this)},"~run"(e,t){return e.value===null&&(this.default!==void 0&&(e.value=x(this,e,t)),e.value===null)?(e.typed=!0,e):this.wrapped[`~run`](e,t)}}}function O(e){return{kind:`schema`,type:`number`,reference:O,expects:`number`,async:!1,message:e,get"~standard"(){return o(this)},"~run"(e,t){return typeof e.value==`number`&&!isNaN(e.value)?e.typed=!0:i(this,`type`,e,t),e}}}function k(e,t){return{kind:`schema`,type:`object`,reference:k,expects:`Object`,async:!1,entries:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in this.entries){let a=this.entries[r];if(r in n||(a.type===`exact_optional`||a.type===`optional`||a.type===`nullish`)&&a.default!==void 0){let i=r in n?n[r]:x(a),o=a[`~run`]({value:i},t);if(o.issues){let a={type:`object`,origin:`value`,input:n,key:r,value:i};for(let t of o.issues)t.path?t.path.unshift(a):t.path=[a],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value[r]=o.value}else if(a.fallback!==void 0)e.value[r]=b(a);else if(a.type!==`exact_optional`&&a.type!==`optional`&&a.type!==`nullish`&&(i(this,`key`,e,t,{input:void 0,expected:`"${r}"`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]}),t.abortEarly))break}}else i(this,`type`,e,t);return e}}}function A(e,t){return{kind:`schema`,type:`optional`,reference:A,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return o(this)},"~run"(e,t){return e.value===void 0&&(this.default!==void 0&&(e.value=x(this,e,t)),e.value===void 0)?(e.typed=!0,e):this.wrapped[`~run`](e,t)}}}function j(e,t){return{kind:`schema`,type:`picklist`,reference:j,expects:c(e.map(r),`|`),async:!1,options:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){return this.options.includes(e.value)?e.typed=!0:i(this,`type`,e,t),e}}}function M(e,t,n){return{kind:`schema`,type:`record`,reference:M,expects:`Object`,async:!1,key:e,value:t,message:n,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in n)if(s(n,r)){let i=n[r],a=this.key[`~run`]({value:r},t);if(a.issues){let o={type:`object`,origin:`key`,input:n,key:r,value:i};for(let t of a.issues)t.path=[o],e.issues?.push(t);if(e.issues||=a.issues,t.abortEarly){e.typed=!1;break}}let o=this.value[`~run`]({value:i},t);if(o.issues){let a={type:`object`,origin:`value`,input:n,key:r,value:i};for(let t of o.issues)t.path?t.path.unshift(a):t.path=[a],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}(!a.typed||!o.typed)&&(e.typed=!1),a.typed&&(e.value[a.value]=o.value)}}else i(this,`type`,e,t);return e}}}function N(e,t){return{kind:`schema`,type:`strict_object`,reference:N,expects:`Object`,async:!1,entries:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in this.entries){let a=this.entries[r];if(r in n||(a.type===`exact_optional`||a.type===`optional`||a.type===`nullish`)&&a.default!==void 0){let i=r in n?n[r]:x(a),o=a[`~run`]({value:i},t);if(o.issues){let a={type:`object`,origin:`value`,input:n,key:r,value:i};for(let t of o.issues)t.path?t.path.unshift(a):t.path=[a],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value[r]=o.value}else if(a.fallback!==void 0)e.value[r]=b(a);else if(a.type!==`exact_optional`&&a.type!==`optional`&&a.type!==`nullish`&&(i(this,`key`,e,t,{input:void 0,expected:`"${r}"`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]}),t.abortEarly))break}if(!e.issues||!t.abortEarly){for(let r in n)if(!(r in this.entries)){i(this,`key`,e,t,{input:r,expected:`never`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]});break}}}else i(this,`type`,e,t);return e}}}function P(e){return{kind:`schema`,type:`string`,reference:P,expects:`string`,async:!1,message:e,get"~standard"(){return o(this)},"~run"(e,t){return typeof e.value==`string`?e.typed=!0:i(this,`type`,e,t),e}}}function F(e){let t;if(e)for(let n of e)if(t)for(let e of n.issues)t.push(e);else t=n.issues;return t}function I(e,t){return{kind:`schema`,type:`union`,reference:I,expects:c(e.map(e=>e.expects),`|`),async:!1,options:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){let n,r,a;for(let i of this.options){let o=i[`~run`]({value:e.value},t);if(o.typed)if(o.issues)r?r.push(o):r=[o];else{n=o;break}else a?a.push(o):a=[o]}if(n)return n;if(r){if(r.length===1)return r[0];i(this,`type`,e,t,{issues:F(r)}),e.typed=!0}else if(a?.length===1)return a[0];else i(this,`type`,e,t,{issues:F(a)});return e}}}function L(){return{kind:`schema`,type:`unknown`,reference:L,expects:`unknown`,async:!1,get"~standard"(){return o(this)},"~run"(e){return e.typed=!0,e}}}function R(e,t,n){return{kind:`schema`,type:`variant`,reference:R,expects:`Object`,async:!1,key:e,options:t,message:n,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){let r,a=0,o=this.key,s=[],l=(e,i)=>{for(let c of e.options){if(c.type===`variant`)l(c,new Set(i).add(c.key));else{let e=!0,l=0;for(let t of i){let r=c.entries[t];if(t in n?r[`~run`]({typed:!1,value:n[t]},ee).issues:r.type!==`exact_optional`&&r.type!==`optional`&&r.type!==`nullish`){e=!1,o!==t&&(a<l||a===l&&t in n&&!(o in n))&&(a=l,o=t,s=[]),o===t&&s.push(c.entries[t].expects);break}l++}if(e){let e=c[`~run`]({value:n},t);(!r||!r.typed&&e.typed)&&(r=e)}}if(r&&!r.issues)break}};if(l(this,new Set([this.key])),r)return r;i(this,`type`,e,t,{input:n[o],expected:c(s,`|`),path:[{type:`object`,origin:`value`,input:n,key:o,value:n[o]}]})}else i(this,`type`,e,t);return e}}}function z(e,t,r){let i=e[`~run`]({value:t},n(r));if(i.issues)throw new l(i.issues);return i.value}function B(e,t){let n=n=>z(e,n,t);return n.schema=e,n.config=t,n}function V(...e){return{...e[0],pipe:e,get"~standard"(){return o(this)},"~run"(t,n){for(let r of e)if(r.kind!==`metadata`){if(t.issues&&(r.kind===`schema`||r.kind===`transformation`)){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=r[`~run`](t,n))}return t}}}const H=/\/+$/,U=new Set([`localhost`,`127.0.0.1`,`[::1]`]),W={development:{sentryDsn:`https://1977371f7bc44480935a7bc9726ca296@o1338376.ingest.sentry.io/6631829`},production:{sentryDsn:`https://c87cbc682ff0422eab5a4714acb95fd1@o1338376.ingest.sentry.io/6662564`}};function G(e,t){let n;try{n=new URL(e)}catch{throw TypeError(`apiBaseUrl must be a valid HTTP or HTTPS URL.`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw TypeError(`apiBaseUrl must be a valid HTTP or HTTPS URL.`);if(n.username||n.password)throw TypeError(`apiBaseUrl must not include credentials.`);if(n.search||n.hash)throw TypeError(`apiBaseUrl must not include a query or fragment.`);if(n.protocol!==`https:`&&!(t===`development`&&U.has(n.hostname)))throw TypeError(`apiBaseUrl must use HTTPS except for development loopback endpoints.`);return n.pathname=n.pathname.replace(H,``),n.toString().replace(H,``)}function K(e,t){let n=`requestTimeoutMs must be a positive integer no greater than 2147483647.`,r=e=>V(P(`${e} must be a non-empty string.`),d(e=>e.trim().length>0,`${e} must be a non-empty string.`));try{let i=z(E({apiBaseUrl:A(P(`apiBaseUrl must be a valid HTTP or HTTPS URL.`)),communitySlug:r(`communitySlug`),environment:A(j([`development`,`production`],`environment must be either development or production.`)),fetch:A(w(e=>typeof e==`function`,`fetch must be a function when provided.`)),onError:A(w(e=>typeof e==`function`,`onError must be a function when provided.`)),requestTimeoutMs:A(V(O(n),v(n),g(1,n),m(2147483647,n))),sentryDsn:A(D(P(`sentryDsn must be a string or null when provided.`)))},`Expected an object.`),e);return{apiBaseUrl:i.apiBaseUrl,communitySlug:i.communitySlug,environment:i.environment,fetch:i.fetch,onError:i.onError,requestTimeoutMs:i.requestTimeoutMs,resourceSlugValue:z(r(t),i[t]),sentryDsn:i.sentryDsn}}catch(e){let t=e instanceof l?e.issues[0]?.message??`Invalid SDK options.`:`Invalid SDK options.`;throw TypeError(t)}}function q(e,t){let n=K(e,t),r=n.environment;if(n.apiBaseUrl!==void 0&&r===void 0)throw TypeError(`environment is required when apiBaseUrl is provided.`);if(n.apiBaseUrl===void 0&&r===`development`)throw TypeError(`apiBaseUrl is required when environment is development.`);let i=r===void 0?`production`:r,{communitySlug:a,resourceSlugValue:o}=n,s=n.fetch??globalThis.fetch,c=n.apiBaseUrl===void 0?`https://portal.lockerverse.com/api`:G(n.apiBaseUrl,i),l=W[i],u=n.sentryDsn,d=u===null?null:u??l.sentryDsn;return{apiBaseUrl:c,communitySlug:encodeURIComponent(a),communitySlugValue:a,environment:i,fetchImplementation:s,onError:n.onError,requestTimeoutMs:n.requestTimeoutMs??2e4,resourceSlug:encodeURIComponent(o),resourceSlugValue:o,sentryDsn:d}}function J(e){let t=q(e,`signupSlug`);return{...t,signupSlug:t.resourceSlug,signupSlugValue:t.resourceSlugValue}}const Y=V(P(),_(),d(e=>e.trim().length>0)),te=A(D(P()),null);function ne(e){return V(O(),v(),g(e))}const X=V(S(L()),y(e=>e.filter(e=>{let{archivedAt:t}=z(E({archivedAt:A(D(Y))}),e);return!t}))),Z=V(X,S(k({id:Y,label:Y})),h(2),d(e=>new Set(e.map(({id:e})=>e)).size===e.length,`Expected unique custom field option IDs.`)),Q={id:Y,label:Y,required:C()},re=R(`type`,[k({...Q,type:j([`text`,`textarea`])}),k({...Q,options:Z,type:j([`radio`,`select`])}),k({...Q,options:Z,type:j([`checkboxes`,`multi_select`])})]),ie=V(A(X,[]),S(re),d(e=>new Set(e.map(({id:e})=>e)).size===e.length,`Expected unique custom field IDs.`)),ae=k({fieldId:Y,value:I([P(),S(P())])});function $(e){if(typeof e!=`object`||!e||Object.isFrozen(e))return e;for(let t of Object.values(e))$(t);return Object.freeze(e)}function oe({communitySlug:e,environment:t,getContext:n,onError:r,resourceContextName:i,sentryDsn:a}){let o=null;return function(s){try{r?.(s)}catch{}if(s.reportable&&a&&typeof window<`u`){let r=o??import(`./telemetry.js`);o=r;let c={communitySlug:e,...n()};s.status!==void 0&&(c.status=s.status),r.then(({captureSdkError:e})=>e({context:c,contextName:i,dsn:a,environment:t,error:s})).catch(()=>{o===r&&(o=null)})}return s}}function se(t,n,r){function i(t){let r=new e({code:t.code,message:t.message,operation:t.operation,reportable:!0});return t.report===!1?r:n(r)}async function a(e,n,a,o,s){let c=new AbortController,l=n?.signal??void 0,u=()=>c.abort(l?.reason);l?.aborted?u():l?.addEventListener(`abort`,u,{once:!0});let d,f=new Promise((e,t)=>{d=()=>t(c.signal.reason??new DOMException(`The request was aborted.`,`AbortError`)),c.signal.aborted?d():c.signal.addEventListener(`abort`,d,{once:!0})}),p=setTimeout(()=>{c.abort(new DOMException(`The request timed out.`,`TimeoutError`))},r);try{let r;try{r=await Promise.race([t(e,{...n,signal:c.signal}),f])}catch{throw i(o)}if(!r.ok)return{ok:!1,response:r};try{let e=await Promise.race([r.json(),f]);return{ok:!0,response:r,value:a(e)}}catch{throw i(s)}}finally{clearTimeout(p),l?.removeEventListener(`abort`,u),d&&c.signal.removeEventListener(`abort`,d)}}return{requestJson:a}}export{V as C,y as D,P as E,I as O,j as S,N as T,h as _,ie as a,A as b,ne as c,S as d,C as f,p as g,T as h,ae as i,R as k,q as l,f as m,oe as n,Y as o,d as p,$ as r,te as s,se as t,J as u,D as v,M as w,B as x,k as y};
|
|
1
|
+
import{n as e}from"./types.js";const t={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function n(e){return e?{lang:e?.lang??void 0,message:e?.message,abortEarly:e?.abortEarly??void 0,abortPipeEarly:e?.abortPipeEarly??void 0}:t}function r(e){let t=typeof e;return t===`string`?`"${e}"`:t===`number`||t===`bigint`||t===`boolean`?`${e}`:t===`object`||t===`function`?(e&&Object.getPrototypeOf(e)?.constructor?.name)??`null`:t}function i(e,t,n,i,a){let o=a&&`input`in a?a.input:n.value,s=a?.expected??e.expects??null,c=a?.received??r(o),l={kind:e.kind,type:e.type,input:o,expected:s,received:c,message:`Invalid ${t}: ${s?`Expected ${s} but r`:`R`}eceived ${c}`,requirement:e.requirement,path:a?.path,issues:a?.issues,lang:i.lang,abortEarly:i.abortEarly,abortPipeEarly:i.abortPipeEarly},u=e.kind===`schema`,d=a?.message??e.message??(e.reference,l.lang,void 0)??(u?(l.lang,void 0):null)??i.message??(l.lang,void 0);d!==void 0&&(l.message=typeof d==`function`?d(l):d),u&&(n.typed=!1),n.issues?n.issues.push(l):n.issues=[l]}const a=new WeakMap;function o(e){let t=a.get(e);return t||(t={version:1,vendor:`valibot`,validate(t){return e[`~run`]({value:t},n())}},a.set(e,t)),t}function s(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!==`__proto__`&&t!==`prototype`&&t!==`constructor`}function c(e,t){let n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??`never`}var l=class extends Error{constructor(e){super(e[0].message),this.name=`ValiError`,this.issues=e}};const u=/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])[T ](?:0\d|1\d|2[0-3])(?::[0-5]\d){2}(?:\.\d{1,9})?(?:Z| ?[+-](?:0\d|1\d|2[0-3])(?::?[0-5]\d)?)$/u;function d(e,t){return{kind:`validation`,type:`check`,reference:d,async:!1,expects:null,requirement:e,message:t,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&i(this,`input`,e,t),e}}}function f(e){return{kind:`validation`,type:`finite`,reference:f,async:!1,expects:null,requirement:Number.isFinite,message:e,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&i(this,`finite`,e,t),e}}}function p(e){return{kind:`validation`,type:`iso_timestamp`,reference:p,async:!1,expects:null,requirement:u,message:e,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&i(this,`timestamp`,e,t),e}}}function m(e,t){return{kind:`validation`,type:`max_value`,reference:m,async:!1,expects:`<=${e instanceof Date?e.toJSON():r(e)}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!(e.value<=this.requirement)&&i(this,`value`,e,t,{received:e.value instanceof Date?e.value.toJSON():r(e.value)}),e}}}function h(e,t){return{kind:`validation`,type:`min_length`,reference:h,async:!1,expects:`>=${e}`,requirement:e,message:t,"~run"(e,t){return e.typed&&e.value.length<this.requirement&&i(this,`length`,e,t,{received:`${e.value.length}`}),e}}}function g(e,t){return{kind:`validation`,type:`min_value`,reference:g,async:!1,expects:`>=${e instanceof Date?e.toJSON():r(e)}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!(e.value>=this.requirement)&&i(this,`value`,e,t,{received:e.value instanceof Date?e.value.toJSON():r(e.value)}),e}}}function _(e){return{kind:`validation`,type:`non_empty`,reference:_,async:!1,expects:`!0`,message:e,"~run"(e,t){return e.typed&&e.value.length===0&&i(this,`length`,e,t,{received:`0`}),e}}}function v(e){return{kind:`validation`,type:`safe_integer`,reference:v,async:!1,expects:null,requirement:Number.isSafeInteger,message:e,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&i(this,`safe integer`,e,t),e}}}function y(e){return{kind:`transformation`,type:`transform`,reference:y,async:!1,operation:e,"~run"(e){return e.value=this.operation(e.value),e}}}const ee={abortEarly:!0};function b(e,t,n){return typeof e.fallback==`function`?e.fallback(t,n):e.fallback}function x(e,t,n){return typeof e.default==`function`?e.default(t,n):e.default}function S(e,t){return{kind:`schema`,type:`array`,reference:S,expects:`Array`,async:!1,item:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(Array.isArray(n)){e.typed=!0,e.value=[];for(let r=0;r<n.length;r++){let i=n[r],a=this.item[`~run`]({value:i},t);if(a.issues){let o={type:`array`,origin:`value`,input:n,key:r,value:i};for(let t of a.issues)t.path?t.path.unshift(o):t.path=[o],e.issues?.push(t);if(e.issues||=a.issues,t.abortEarly){e.typed=!1;break}}a.typed||(e.typed=!1),e.value.push(a.value)}}else i(this,`type`,e,t);return e}}}function C(e){return{kind:`schema`,type:`boolean`,reference:C,expects:`boolean`,async:!1,message:e,get"~standard"(){return o(this)},"~run"(e,t){return typeof e.value==`boolean`?e.typed=!0:i(this,`type`,e,t),e}}}function w(e,t){return{kind:`schema`,type:`custom`,reference:w,expects:`unknown`,async:!1,check:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){return this.check(e.value)?e.typed=!0:i(this,`type`,e,t),e}}}function T(e,t){return{kind:`schema`,type:`literal`,reference:T,expects:r(e),async:!1,literal:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){return e.value===this.literal?e.typed=!0:i(this,`type`,e,t),e}}}function E(e,t){return{kind:`schema`,type:`loose_object`,reference:E,expects:`Object`,async:!1,entries:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in this.entries){let a=this.entries[r];if(r in n||(a.type===`exact_optional`||a.type===`optional`||a.type===`nullish`)&&a.default!==void 0){let i=r in n?n[r]:x(a),o=a[`~run`]({value:i},t);if(o.issues){let a={type:`object`,origin:`value`,input:n,key:r,value:i};for(let t of o.issues)t.path?t.path.unshift(a):t.path=[a],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value[r]=o.value}else if(a.fallback!==void 0)e.value[r]=b(a);else if(a.type!==`exact_optional`&&a.type!==`optional`&&a.type!==`nullish`&&(i(this,`key`,e,t,{input:void 0,expected:`"${r}"`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]}),t.abortEarly))break}if(!e.issues||!t.abortEarly)for(let t in n)s(n,t)&&!(t in this.entries)&&(e.value[t]=n[t])}else i(this,`type`,e,t);return e}}}function D(e,t){return{kind:`schema`,type:`nullable`,reference:D,expects:`(${e.expects} | null)`,async:!1,wrapped:e,default:t,get"~standard"(){return o(this)},"~run"(e,t){return e.value===null&&(this.default!==void 0&&(e.value=x(this,e,t)),e.value===null)?(e.typed=!0,e):this.wrapped[`~run`](e,t)}}}function O(e){return{kind:`schema`,type:`number`,reference:O,expects:`number`,async:!1,message:e,get"~standard"(){return o(this)},"~run"(e,t){return typeof e.value==`number`&&!isNaN(e.value)?e.typed=!0:i(this,`type`,e,t),e}}}function k(e,t){return{kind:`schema`,type:`object`,reference:k,expects:`Object`,async:!1,entries:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in this.entries){let a=this.entries[r];if(r in n||(a.type===`exact_optional`||a.type===`optional`||a.type===`nullish`)&&a.default!==void 0){let i=r in n?n[r]:x(a),o=a[`~run`]({value:i},t);if(o.issues){let a={type:`object`,origin:`value`,input:n,key:r,value:i};for(let t of o.issues)t.path?t.path.unshift(a):t.path=[a],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value[r]=o.value}else if(a.fallback!==void 0)e.value[r]=b(a);else if(a.type!==`exact_optional`&&a.type!==`optional`&&a.type!==`nullish`&&(i(this,`key`,e,t,{input:void 0,expected:`"${r}"`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]}),t.abortEarly))break}}else i(this,`type`,e,t);return e}}}function A(e,t){return{kind:`schema`,type:`optional`,reference:A,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return o(this)},"~run"(e,t){return e.value===void 0&&(this.default!==void 0&&(e.value=x(this,e,t)),e.value===void 0)?(e.typed=!0,e):this.wrapped[`~run`](e,t)}}}function j(e,t){return{kind:`schema`,type:`picklist`,reference:j,expects:c(e.map(r),`|`),async:!1,options:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){return this.options.includes(e.value)?e.typed=!0:i(this,`type`,e,t),e}}}function M(e,t,n){return{kind:`schema`,type:`record`,reference:M,expects:`Object`,async:!1,key:e,value:t,message:n,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in n)if(s(n,r)){let i=n[r],a=this.key[`~run`]({value:r},t);if(a.issues){let o={type:`object`,origin:`key`,input:n,key:r,value:i};for(let t of a.issues)t.path=[o],e.issues?.push(t);if(e.issues||=a.issues,t.abortEarly){e.typed=!1;break}}let o=this.value[`~run`]({value:i},t);if(o.issues){let a={type:`object`,origin:`value`,input:n,key:r,value:i};for(let t of o.issues)t.path?t.path.unshift(a):t.path=[a],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}(!a.typed||!o.typed)&&(e.typed=!1),a.typed&&(e.value[a.value]=o.value)}}else i(this,`type`,e,t);return e}}}function N(e,t){return{kind:`schema`,type:`strict_object`,reference:N,expects:`Object`,async:!1,entries:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in this.entries){let a=this.entries[r];if(r in n||(a.type===`exact_optional`||a.type===`optional`||a.type===`nullish`)&&a.default!==void 0){let i=r in n?n[r]:x(a),o=a[`~run`]({value:i},t);if(o.issues){let a={type:`object`,origin:`value`,input:n,key:r,value:i};for(let t of o.issues)t.path?t.path.unshift(a):t.path=[a],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value[r]=o.value}else if(a.fallback!==void 0)e.value[r]=b(a);else if(a.type!==`exact_optional`&&a.type!==`optional`&&a.type!==`nullish`&&(i(this,`key`,e,t,{input:void 0,expected:`"${r}"`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]}),t.abortEarly))break}if(!e.issues||!t.abortEarly){for(let r in n)if(!(r in this.entries)){i(this,`key`,e,t,{input:r,expected:`never`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]});break}}}else i(this,`type`,e,t);return e}}}function P(e){return{kind:`schema`,type:`string`,reference:P,expects:`string`,async:!1,message:e,get"~standard"(){return o(this)},"~run"(e,t){return typeof e.value==`string`?e.typed=!0:i(this,`type`,e,t),e}}}function F(e){let t;if(e)for(let n of e)if(t)for(let e of n.issues)t.push(e);else t=n.issues;return t}function I(e,t){return{kind:`schema`,type:`union`,reference:I,expects:c(e.map(e=>e.expects),`|`),async:!1,options:e,message:t,get"~standard"(){return o(this)},"~run"(e,t){let n,r,a;for(let i of this.options){let o=i[`~run`]({value:e.value},t);if(o.typed)if(o.issues)r?r.push(o):r=[o];else{n=o;break}else a?a.push(o):a=[o]}if(n)return n;if(r){if(r.length===1)return r[0];i(this,`type`,e,t,{issues:F(r)}),e.typed=!0}else if(a?.length===1)return a[0];else i(this,`type`,e,t,{issues:F(a)});return e}}}function L(){return{kind:`schema`,type:`unknown`,reference:L,expects:`unknown`,async:!1,get"~standard"(){return o(this)},"~run"(e){return e.typed=!0,e}}}function R(e,t,n){return{kind:`schema`,type:`variant`,reference:R,expects:`Object`,async:!1,key:e,options:t,message:n,get"~standard"(){return o(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){let r,a=0,o=this.key,s=[],l=(e,i)=>{for(let c of e.options){if(c.type===`variant`)l(c,new Set(i).add(c.key));else{let e=!0,l=0;for(let t of i){let r=c.entries[t];if(t in n?r[`~run`]({typed:!1,value:n[t]},ee).issues:r.type!==`exact_optional`&&r.type!==`optional`&&r.type!==`nullish`){e=!1,o!==t&&(a<l||a===l&&t in n&&!(o in n))&&(a=l,o=t,s=[]),o===t&&s.push(c.entries[t].expects);break}l++}if(e){let e=c[`~run`]({value:n},t);(!r||!r.typed&&e.typed)&&(r=e)}}if(r&&!r.issues)break}};if(l(this,new Set([this.key])),r)return r;i(this,`type`,e,t,{input:n[o],expected:c(s,`|`),path:[{type:`object`,origin:`value`,input:n,key:o,value:n[o]}]})}else i(this,`type`,e,t);return e}}}function z(e,t,r){let i=e[`~run`]({value:t},n(r));if(i.issues)throw new l(i.issues);return i.value}function B(e,t){let n=n=>z(e,n,t);return n.schema=e,n.config=t,n}function V(...e){return{...e[0],pipe:e,get"~standard"(){return o(this)},"~run"(t,n){for(let r of e)if(r.kind!==`metadata`){if(t.issues&&(r.kind===`schema`||r.kind===`transformation`)){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=r[`~run`](t,n))}return t}}}const H=/\/+$/,U=new Set([`localhost`,`127.0.0.1`,`[::1]`]),W={development:{sentryDsn:`https://1977371f7bc44480935a7bc9726ca296@o1338376.ingest.sentry.io/6631829`},production:{sentryDsn:`https://c87cbc682ff0422eab5a4714acb95fd1@o1338376.ingest.sentry.io/6662564`}};function G(e,t){let n;try{n=new URL(e)}catch{throw TypeError(`apiBaseUrl must be a valid HTTP or HTTPS URL.`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw TypeError(`apiBaseUrl must be a valid HTTP or HTTPS URL.`);if(n.username||n.password)throw TypeError(`apiBaseUrl must not include credentials.`);if(n.search||n.hash)throw TypeError(`apiBaseUrl must not include a query or fragment.`);if(n.protocol!==`https:`&&!(t===`development`&&U.has(n.hostname)))throw TypeError(`apiBaseUrl must use HTTPS except for development loopback endpoints.`);return n.pathname=n.pathname.replace(H,``),n.toString().replace(H,``)}function K(e,t){let n=`requestTimeoutMs must be a positive integer no greater than 2147483647.`,r=e=>V(P(`${e} must be a non-empty string.`),d(e=>e.trim().length>0,`${e} must be a non-empty string.`));try{let i=z(E({apiBaseUrl:A(P(`apiBaseUrl must be a valid HTTP or HTTPS URL.`)),communitySlug:r(`communitySlug`),environment:A(j([`development`,`production`],`environment must be either development or production.`)),fetch:A(w(e=>typeof e==`function`,`fetch must be a function when provided.`)),onError:A(w(e=>typeof e==`function`,`onError must be a function when provided.`)),requestTimeoutMs:A(V(O(n),v(n),g(1,n),m(2147483647,n))),sentryDsn:A(D(P(`sentryDsn must be a string or null when provided.`)))},`Expected an object.`),e);return{apiBaseUrl:i.apiBaseUrl,communitySlug:i.communitySlug,environment:i.environment,fetch:i.fetch,onError:i.onError,requestTimeoutMs:i.requestTimeoutMs,resourceSlugValue:z(r(t),i[t]),sentryDsn:i.sentryDsn}}catch(e){let t=e instanceof l?e.issues[0]?.message??`Invalid SDK options.`:`Invalid SDK options.`;throw TypeError(t)}}function q(e,t){let n=K(e,t),r=n.environment;if(n.apiBaseUrl!==void 0&&r===void 0)throw TypeError(`environment is required when apiBaseUrl is provided.`);if(n.apiBaseUrl===void 0&&r===`development`)throw TypeError(`apiBaseUrl is required when environment is development.`);let i=r===void 0?`production`:r,{communitySlug:a,resourceSlugValue:o}=n,s=n.fetch??globalThis.fetch,c=n.apiBaseUrl===void 0?`https://portal.lockerverse.com/api`:G(n.apiBaseUrl,i),l=W[i],u=n.sentryDsn,d=u===null?null:u??l.sentryDsn;return{apiBaseUrl:c,communitySlug:encodeURIComponent(a),communitySlugValue:a,environment:i,fetchImplementation:s,onError:n.onError,requestTimeoutMs:n.requestTimeoutMs??2e4,resourceSlug:encodeURIComponent(o),resourceSlugValue:o,sentryDsn:d}}function J(e){let t=q(e,`signupSlug`);return{...t,signupSlug:t.resourceSlug,signupSlugValue:t.resourceSlugValue}}const Y=V(P(),_(),d(e=>e.trim().length>0)),te=A(D(P()),null);function ne(e){return V(O(),v(),g(e))}const X=V(S(L()),y(e=>e.filter(e=>{let{archivedAt:t}=z(E({archivedAt:A(D(Y))}),e);return!t}))),Z=V(X,S(k({id:Y,label:Y})),h(2),d(e=>new Set(e.map(({id:e})=>e)).size===e.length,`Expected unique custom field option IDs.`)),Q={id:Y,label:Y,required:C()},re=R(`type`,[k({...Q,type:j([`text`,`textarea`])}),k({...Q,options:Z,type:j([`radio`,`select`])}),k({...Q,options:Z,type:j([`checkboxes`,`multi_select`])})]),ie=V(A(X,[]),S(re),d(e=>new Set(e.map(({id:e})=>e)).size===e.length,`Expected unique custom field IDs.`)),ae=k({fieldId:Y,value:I([P(),S(P())])});function $(e){if(typeof e!=`object`||!e||Object.isFrozen(e))return e;for(let t of Object.values(e))$(t);return Object.freeze(e)}function oe({communitySlug:e,environment:t,getContext:n,onError:r,resourceContextName:i,sentryDsn:a}){let o=null;return function(s){try{r?.(s)}catch{}if(s.reportable&&a&&typeof window<`u`){let r=o??import(`./telemetry.js`);o=r;let c={communitySlug:e,...n()};s.status!==void 0&&(c.status=s.status),r.then(({captureSdkError:e})=>e({context:c,contextName:i,dsn:a,environment:t,error:s})).catch(()=>{o===r&&(o=null)})}return s}}function se(t,n,r){function i(t){let r=new e({code:t.code,message:t.message,operation:t.operation,reportable:!0});return t.report===!1?r:n(r)}async function a(e,n,a,o,s){let c=new AbortController,l=n?.signal??void 0,u=()=>c.abort(l?.reason);l?.aborted?u():l?.addEventListener(`abort`,u,{once:!0});let d,f=new Promise((e,t)=>{d=()=>t(c.signal.reason??new DOMException(`The request was aborted.`,`AbortError`)),c.signal.aborted?d():c.signal.addEventListener(`abort`,d,{once:!0})}),p=setTimeout(()=>{c.abort(new DOMException(`The request timed out.`,`TimeoutError`))},r);try{let r;try{r=await Promise.race([t(e,{...n,signal:c.signal}),f])}catch{throw i(o)}if(!r.ok)return{ok:!1,response:r};try{let e=await Promise.race([r.json(),f]);return{ok:!0,response:r,value:a(e)}}catch{throw i(s)}}finally{clearTimeout(p),l?.removeEventListener(`abort`,u),d&&c.signal.removeEventListener(`abort`,d)}}return{requestJson:a}}export{y as A,A as C,M as D,V as E,R as M,N as O,k as S,j as T,m as _,ie as a,D as b,ne as c,S as d,C as f,T as g,p as h,ae as i,I as j,P as k,q as l,f as m,oe as n,Y as o,d as p,$ as r,te as s,se as t,J as u,h as v,B as w,O as x,g as y};
|
|
2
2
|
//# sourceMappingURL=transport.js.map
|