@lockerverse/sdk 0.2.257 → 0.2.258
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATIONS.md +17 -1
- package/dist/bookings.d.ts +2 -0
- package/dist/bookings.d.ts.map +1 -1
- package/dist/bookings.js +1 -1
- package/dist/bookings.js.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
package/MIGRATIONS.md
CHANGED
|
@@ -4,7 +4,23 @@ This file ships in both @lockerverse/sdk and @lockerverse/react. Use the copy in
|
|
|
4
4
|
the target installed release. This is an agent-run procedure, not an install
|
|
5
5
|
script. Installing a package does not edit host code or guarantee these steps ran.
|
|
6
6
|
|
|
7
|
-
## Unreleased —
|
|
7
|
+
## Unreleased — booking and auction analytics
|
|
8
|
+
|
|
9
|
+
- **Affected:** `useLockerverseBookings`, `useLockerverseAuction`,
|
|
10
|
+
`useLockerverseAuctions`, and `LockerverseAuctionItem` checkout (React and the
|
|
11
|
+
browser embed). They send the same anonymous product analytics as the payment
|
|
12
|
+
widget: Widget Viewed, Auction Viewed, Auction Item Viewed, Checkout Started,
|
|
13
|
+
Payment Info Entered, Payment Failed, Order Confirmation Viewed. No contact
|
|
14
|
+
data, bid amounts or free text are sent. Bids are reported by the backend.
|
|
15
|
+
- **Automatic:** on after the update. No host code change.
|
|
16
|
+
- **Host adoption:** pass `analytics: false` in the hook options to opt out.
|
|
17
|
+
Booking hosts that use a development client also pass `environment:
|
|
18
|
+
"development"` to `useLockerverseBookings`. Global Privacy Control and Do Not
|
|
19
|
+
Track are honored without code.
|
|
20
|
+
- **Check:** open an auction item page; the network panel shows a POST to
|
|
21
|
+
`/api/v1/s/batch`. Do not place a live bid or payment for this check.
|
|
22
|
+
|
|
23
|
+
## 0.2.257 — product analytics
|
|
8
24
|
|
|
9
25
|
- **Affected:** `@lockerverse/react` payment, donate launcher and signup widgets.
|
|
10
26
|
The widgets send anonymous analytics events (Page Viewed, Widget Viewed,
|
package/dist/bookings.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ type LockerverseBookingPrice = {
|
|
|
33
33
|
};
|
|
34
34
|
type LockerverseBookingBusiness = {
|
|
35
35
|
key: string;
|
|
36
|
+
/** The community of the business (for analytics); absent from older APIs. */
|
|
37
|
+
communityId?: string | undefined;
|
|
36
38
|
name: string;
|
|
37
39
|
/** The Square mode, independent of the SDK API environment. */
|
|
38
40
|
environment?: "sandbox" | "production" | undefined;
|
package/dist/bookings.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bookings.d.ts","names":[],"sources":["../src/booking-types.ts","../src/booking-client.ts"],"mappings":";;KAKY;EACV;EACA;EACA;EACA;;KAGU,mCAAmC;EAC7C;;;;;EAKA,cAAc;;KAGJ;;EAEV;EACA;;;KAIU;EACV;;EAEA;EACA;EACA;;EAEA;IAAe;;;KAGL;EACV;EACA;;EAEA;EACA;EACA,SAAS;;EAET,WAAW;;KAGD;EACV,UAAU;EACV;EACA;EACA;EACA;EACA;EACA;;;;;;EAMA,UAAU;;KAGA;EACV;EACA;;KAGU;KAYA;EACV;EACA,QAAQ;EACR;EACA;EACA;;EAEA;EACA;EACA;;EAEA;;EAEA;;EAEA;EACA;EACA;EACA;;EAEA;;EAEA;;KAGU;EACV;EACA;;KAGU;EACV;EACA;EACA;;;KAIU;EACV;EACA;;KAGU;EACV;EACA;EACA;;EAEA,WAAW;;KAGD,mCACV;EACE;;EAEA,sCAAsC;EACtC,eAAe,WAAW;EAC1B,WAAW,OAAO;EAClB;EACA;;KAGQ;WACD;;EAET,gBACE,iCACG,QAAQ;EACb,qBAAqB,QAAQ;EAC7B,eACE,cACA,gCACG,QAAQ;EACb,aACE,WAAW,gCACR,QAAQ;EACb,UAAU,8BAA8B,QAAQ;EAChD,eAAe,QAAQ;;;;;EAKvB,QACE,4BACA,kBACG,QAAQ;;;;;
|
|
1
|
+
{"version":3,"file":"bookings.d.ts","names":[],"sources":["../src/booking-types.ts","../src/booking-client.ts"],"mappings":";;KAKY;EACV;EACA;EACA;EACA;;KAGU,mCAAmC;EAC7C;;;;;EAKA,cAAc;;KAGJ;;EAEV;EACA;;;KAIU;EACV;;EAEA;EACA;EACA;;EAEA;IAAe;;;KAGL;EACV;;EAEA;EACA;;EAEA;EACA;EACA,SAAS;;EAET,WAAW;;KAGD;EACV,UAAU;EACV;EACA;EACA;EACA;EACA;EACA;;;;;;EAMA,UAAU;;KAGA;EACV;EACA;;KAGU;KAYA;EACV;EACA,QAAQ;EACR;EACA;EACA;;EAEA;EACA;EACA;;EAEA;;EAEA;;EAEA;EACA;EACA;EACA;;EAEA;;EAEA;;KAGU;EACV;EACA;;KAGU;EACV;EACA;EACA;;;KAIU;EACV;EACA;;KAGU;EACV;EACA;EACA;;EAEA,WAAW;;KAGD,mCACV;EACE;;EAEA,sCAAsC;EACtC,eAAe,WAAW;EAC1B,WAAW,OAAO;EAClB;EACA;;KAGQ;WACD;;EAET,gBACE,iCACG,QAAQ;EACb,qBAAqB,QAAQ;EAC7B,eACE,cACA,gCACG,QAAQ;EACb,aACE,WAAW,gCACR,QAAQ;EACb,UAAU,8BAA8B,QAAQ;EAChD,eAAe,QAAQ;;;;;EAKvB,QACE,4BACA,kBACG,QAAQ;;;;;iBC9IC,gCACd,SAAS,mCACR"}
|
package/dist/bookings.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as e,n as t,o as n,t as r}from"./transport.js";import{n as i}from"./types.js";import{array as a,boolean as o,email as s,isoTimestamp as c,literal as l,maxLength as u,minLength as d,minValue as f,nullable as p,number as m,object as h,optional as g,parse as _,picklist as v,pipe as y,regex as b,safeInteger as x,safeParse as S,string as C,trim as w}from"valibot";const T=y(m(),x(),f(0)),E=h({email:y(C(),w(),s(),u(254)),name:y(C(),w(),d(1),u(120)),phone:y(C(),b(/^\+[1-9]\d{7,14}$/))}),D={amountCents:T,currency:l(`USD`),durationMinutes:y(m(),x(),f(1)),name:C()},O=h({environment:g(v([`sandbox`,`production`])),key:C(),name:C(),service:h(D),services:g(a(h({...D,memberPrice:g(h({amountCents:T,label:C()})),serviceVariationId:y(C(),d(1))}))),timeZone:C()}),k=h({business:O,diagnosticCode:g(C()),lockerverse:o(),message:C(),payment:g(h({publishableKey:y(C(),b(/^pk_(?:test|live)_/)),stripeAccountId:p(y(C(),b(/^acct_[A-Za-z0-9]+$/)))})),ready:o(),reviewer:o(),square:o()}),A=y(C(),c()),j=h({amountCents:g(T),bookingId:g(C()),bookingStatus:g(C()),clientSecret:g(C()),currency:g(l(`USD`)),id:C(),message:C(),priceLabel:g(C()),publishableKey:C(),regularAmountCents:g(T),serviceName:g(C()),squarePaymentId:g(C()),start:A,status:v([`review`,`payment_pending`,`payment_action_required`,`payment_failed`,`paid`,`booking_pending`,`booking_created`,`external_payment_pending`,`complete`,`manual_refund_required`]),stripeAccountId:g(p(C())),timeZone:g(C())}),M=h({accessToken:y(C(),b(/^[A-Za-z0-9_-]{43}$/)),expiresAt:A}),N=h({amountCents:T,currency:l(`USD`),memberPrice:p(h({label:C()})),regularAmountCents:T,serviceVariationId:y(C(),d(1))}),P=e=>_(N,e),F=e=>_(k,e),I=e=>_(h({message:C(),slots:a(A)}),e),L=e=>_(j,e),R=e=>_(p(j),e);function z(e){let t=S(E,e);return t.success?t.output:null}const B=e=>_(M,e),V=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,H=/^[A-Za-z0-9_-]{43}$/,U=/^\d{4}-\d{2}-\d{2}$/,W=/^ctoken_[A-Za-z0-9]+$/;function G(a){if(!V.test(a.businessKey)||a.businessKey.length>80)throw TypeError(`businessKey must be a valid booking business key.`);let o=e({...a,communitySlug:a.businessKey,requestTimeoutMs:a.requestTimeoutMs??6e4},`businessKey`),s=t({communitySlug:``,environment:o.environment,getContext:()=>({businessKey:a.businessKey}),onError:o.onError,resourceContextName:`lockerverse_bookings`,sentryDsn:o.sentryDsn}),{requestJson:c}=r(o.fetchImplementation,s,o.requestTimeoutMs),l=`${o.apiBaseUrl}/v2/booking-businesses/${o.resourceSlug}`;async function u(e,t){let n=t===void 0?await a.getAccessToken():t;if(t!==null&&(n===null||!H.test(n)))throw new i({code:`booking_request_failed`,message:`Booking access is not ready. Check your saved booking before trying again.`,operation:e,reportable:!1,status:401});let r=new Headers;return n!==null&&r.set(`Authorization`,`Bearer ${n}`),r}async function d(e,t,r,a,o){let d={code:`booking_request_failed`,message:`Unable to complete the booking request. Check the saved state before trying payment again.`,operation:t,report:!1};try{let s=await u(t,o),f={cache:`no-store`,credentials:`omit`,headers:s,method:a===void 0?`GET`:`POST`,redirect:`error`};a!==void 0&&(f.body=JSON.stringify(a),s.set(`Content-Type`,`application/json`));let p=await c(`${l}${e}`,f,r,d,d);if(!p.ok)throw new i({...d,message:[401,403].includes(p.response.status)?`Booking access has expired or is not valid. Your saved attempt is retained.`:d.message,recoveryRecommended:!0,reportable:p.response.status>=500,status:p.response.status});return n(p.value)}catch(e){throw s(e instanceof i?e:new i({...d,recoveryRecommended:!0,reportable:!1}))}}return{availability(e,t){if(!U.test(e))throw TypeError(`date must use YYYY-MM-DD in the business time zone.`);let n=new URLSearchParams({date:e});return t!==void 0&&n.set(`serviceVariationId`,t),d(`/slots?${n}`,`find_booking_availability`,I)},businessKey:a.businessKey,async configuration(){let e=await d(`/config`,`load_booking_configuration`,F);if(e.business.key!==a.businessKey)throw s(new i({code:`booking_request_failed`,message:`The booking response does not match this business.`,operation:`load_booking_configuration`,reportable:!0}));return e},confirm(e){if(!W.test(e)||e.length>512)throw TypeError(`A valid payment confirmation token is required.`);return d(`/confirm`,`confirm_booking`,L,{confirmationToken:e})},createSession(e){if(e!==void 0&&!H.test(e))throw TypeError(`A valid existing booking session is required.`);return d(`/session`,`create_booking_session`,B,{},e??null)},initialize(e){if(!(U.test(e.date)&&Number.isFinite(Date.parse(e.start))))throw TypeError(`Select an available booking date and time.`);let t=e.customer===void 0?void 0:z(e.customer);if(t===null)throw TypeError(`Enter your name, email and international phone number.`);let n={date:e.date,start:e.start};return e.serviceVariationId!==void 0&&(n.serviceVariationId=e.serviceVariationId),t!==void 0&&(n.customer=t),d(`/attempt`,`initialize_booking`,L,n)},price(e,t){let n=t.trim();if(!(e&&n.includes(`@`))||n.length>254)throw TypeError(`Choose a service and enter a valid email.`);return d(`/price`,`quote_booking_price`,P,{email:n,serviceVariationId:e})},recover:()=>d(`/recover`,`recover_booking`,R,{})}}export{i as LockerverseSdkError,G as createLockerverseBookingsClient};
|
|
1
|
+
import{i as e,n as t,o as n,t as r}from"./transport.js";import{n as i}from"./types.js";import{array as a,boolean as o,email as s,isoTimestamp as c,literal as l,maxLength as u,minLength as d,minValue as f,nullable as p,number as m,object as h,optional as g,parse as _,picklist as v,pipe as y,regex as b,safeInteger as x,safeParse as S,string as C,trim as w}from"valibot";const T=y(m(),x(),f(0)),E=h({email:y(C(),w(),s(),u(254)),name:y(C(),w(),d(1),u(120)),phone:y(C(),b(/^\+[1-9]\d{7,14}$/))}),D={amountCents:T,currency:l(`USD`),durationMinutes:y(m(),x(),f(1)),name:C()},O=h({communityId:g(C()),environment:g(v([`sandbox`,`production`])),key:C(),name:C(),service:h(D),services:g(a(h({...D,memberPrice:g(h({amountCents:T,label:C()})),serviceVariationId:y(C(),d(1))}))),timeZone:C()}),k=h({business:O,diagnosticCode:g(C()),lockerverse:o(),message:C(),payment:g(h({publishableKey:y(C(),b(/^pk_(?:test|live)_/)),stripeAccountId:p(y(C(),b(/^acct_[A-Za-z0-9]+$/)))})),ready:o(),reviewer:o(),square:o()}),A=y(C(),c()),j=h({amountCents:g(T),bookingId:g(C()),bookingStatus:g(C()),clientSecret:g(C()),currency:g(l(`USD`)),id:C(),message:C(),priceLabel:g(C()),publishableKey:C(),regularAmountCents:g(T),serviceName:g(C()),squarePaymentId:g(C()),start:A,status:v([`review`,`payment_pending`,`payment_action_required`,`payment_failed`,`paid`,`booking_pending`,`booking_created`,`external_payment_pending`,`complete`,`manual_refund_required`]),stripeAccountId:g(p(C())),timeZone:g(C())}),M=h({accessToken:y(C(),b(/^[A-Za-z0-9_-]{43}$/)),expiresAt:A}),N=h({amountCents:T,currency:l(`USD`),memberPrice:p(h({label:C()})),regularAmountCents:T,serviceVariationId:y(C(),d(1))}),P=e=>_(N,e),F=e=>_(k,e),I=e=>_(h({message:C(),slots:a(A)}),e),L=e=>_(j,e),R=e=>_(p(j),e);function z(e){let t=S(E,e);return t.success?t.output:null}const B=e=>_(M,e),V=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,H=/^[A-Za-z0-9_-]{43}$/,U=/^\d{4}-\d{2}-\d{2}$/,W=/^ctoken_[A-Za-z0-9]+$/;function G(a){if(!V.test(a.businessKey)||a.businessKey.length>80)throw TypeError(`businessKey must be a valid booking business key.`);let o=e({...a,communitySlug:a.businessKey,requestTimeoutMs:a.requestTimeoutMs??6e4},`businessKey`),s=t({communitySlug:``,environment:o.environment,getContext:()=>({businessKey:a.businessKey}),onError:o.onError,resourceContextName:`lockerverse_bookings`,sentryDsn:o.sentryDsn}),{requestJson:c}=r(o.fetchImplementation,s,o.requestTimeoutMs),l=`${o.apiBaseUrl}/v2/booking-businesses/${o.resourceSlug}`;async function u(e,t){let n=t===void 0?await a.getAccessToken():t;if(t!==null&&(n===null||!H.test(n)))throw new i({code:`booking_request_failed`,message:`Booking access is not ready. Check your saved booking before trying again.`,operation:e,reportable:!1,status:401});let r=new Headers;return n!==null&&r.set(`Authorization`,`Bearer ${n}`),r}async function d(e,t,r,a,o){let d={code:`booking_request_failed`,message:`Unable to complete the booking request. Check the saved state before trying payment again.`,operation:t,report:!1};try{let s=await u(t,o),f={cache:`no-store`,credentials:`omit`,headers:s,method:a===void 0?`GET`:`POST`,redirect:`error`};a!==void 0&&(f.body=JSON.stringify(a),s.set(`Content-Type`,`application/json`));let p=await c(`${l}${e}`,f,r,d,d);if(!p.ok)throw new i({...d,message:[401,403].includes(p.response.status)?`Booking access has expired or is not valid. Your saved attempt is retained.`:d.message,recoveryRecommended:!0,reportable:p.response.status>=500,status:p.response.status});return n(p.value)}catch(e){throw s(e instanceof i?e:new i({...d,recoveryRecommended:!0,reportable:!1}))}}return{availability(e,t){if(!U.test(e))throw TypeError(`date must use YYYY-MM-DD in the business time zone.`);let n=new URLSearchParams({date:e});return t!==void 0&&n.set(`serviceVariationId`,t),d(`/slots?${n}`,`find_booking_availability`,I)},businessKey:a.businessKey,async configuration(){let e=await d(`/config`,`load_booking_configuration`,F);if(e.business.key!==a.businessKey)throw s(new i({code:`booking_request_failed`,message:`The booking response does not match this business.`,operation:`load_booking_configuration`,reportable:!0}));return e},confirm(e){if(!W.test(e)||e.length>512)throw TypeError(`A valid payment confirmation token is required.`);return d(`/confirm`,`confirm_booking`,L,{confirmationToken:e})},createSession(e){if(e!==void 0&&!H.test(e))throw TypeError(`A valid existing booking session is required.`);return d(`/session`,`create_booking_session`,B,{},e??null)},initialize(e){if(!(U.test(e.date)&&Number.isFinite(Date.parse(e.start))))throw TypeError(`Select an available booking date and time.`);let t=e.customer===void 0?void 0:z(e.customer);if(t===null)throw TypeError(`Enter your name, email and international phone number.`);let n={date:e.date,start:e.start};return e.serviceVariationId!==void 0&&(n.serviceVariationId=e.serviceVariationId),t!==void 0&&(n.customer=t),d(`/attempt`,`initialize_booking`,L,n)},price(e,t){let n=t.trim();if(!(e&&n.includes(`@`))||n.length>254)throw TypeError(`Choose a service and enter a valid email.`);return d(`/price`,`quote_booking_price`,P,{email:n,serviceVariationId:e})},recover:()=>d(`/recover`,`recover_booking`,R,{})}}export{i as LockerverseSdkError,G as createLockerverseBookingsClient};
|
|
2
2
|
//# sourceMappingURL=bookings.js.map
|
package/dist/bookings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bookings.js","names":[],"sources":["../src/booking-schemas.ts","../src/booking-client.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters -- These schema parsers are the untrusted HTTP JSON boundary. */\nimport {\n array,\n boolean,\n email,\n isoTimestamp,\n literal,\n maxLength,\n minLength,\n minValue,\n nullable,\n number,\n object,\n optional,\n parse,\n picklist,\n pipe,\n regex,\n safeInteger,\n safeParse,\n string,\n trim,\n} from \"valibot\";\n\nconst nonnegativeInteger = pipe(number(), safeInteger(), minValue(0));\nconst customerSchema = object({\n email: pipe(string(), trim(), email(), maxLength(254)),\n name: pipe(string(), trim(), minLength(1), maxLength(120)),\n phone: pipe(string(), regex(/^\\+[1-9]\\d{7,14}$/)),\n});\nconst serviceFields = {\n amountCents: nonnegativeInteger,\n currency: literal(\"USD\"),\n durationMinutes: pipe(number(), safeInteger(), minValue(1)),\n name: string(),\n};\nconst businessSchema = object({\n environment: optional(picklist([\"sandbox\", \"production\"])),\n key: string(),\n name: string(),\n service: object(serviceFields),\n services: optional(\n array(\n object({\n ...serviceFields,\n memberPrice: optional(\n object({ amountCents: nonnegativeInteger, label: string() })\n ),\n serviceVariationId: pipe(string(), minLength(1)),\n })\n )\n ),\n timeZone: string(),\n});\nconst configurationSchema = object({\n business: businessSchema,\n diagnosticCode: optional(string()),\n lockerverse: boolean(),\n message: string(),\n payment: optional(\n object({\n publishableKey: pipe(string(), regex(/^pk_(?:test|live)_/)),\n stripeAccountId: nullable(pipe(string(), regex(/^acct_[A-Za-z0-9]+$/))),\n })\n ),\n ready: boolean(),\n reviewer: boolean(),\n square: boolean(),\n});\nconst instant = pipe(string(), isoTimestamp());\nconst attemptSchema = object({\n amountCents: optional(nonnegativeInteger),\n bookingId: optional(string()),\n bookingStatus: optional(string()),\n clientSecret: optional(string()),\n currency: optional(literal(\"USD\")),\n id: string(),\n message: string(),\n priceLabel: optional(string()),\n publishableKey: string(),\n regularAmountCents: optional(nonnegativeInteger),\n serviceName: optional(string()),\n squarePaymentId: optional(string()),\n start: instant,\n status: picklist([\n \"review\",\n \"payment_pending\",\n \"payment_action_required\",\n \"payment_failed\",\n \"paid\",\n \"booking_pending\",\n \"booking_created\",\n \"external_payment_pending\",\n \"complete\",\n \"manual_refund_required\",\n ]),\n stripeAccountId: optional(nullable(string())),\n timeZone: optional(string()),\n});\nconst sessionSchema = object({\n accessToken: pipe(string(), regex(/^[A-Za-z0-9_-]{43}$/)),\n expiresAt: instant,\n});\n\nconst priceSchema = object({\n amountCents: nonnegativeInteger,\n currency: literal(\"USD\"),\n memberPrice: nullable(object({ label: string() })),\n regularAmountCents: nonnegativeInteger,\n serviceVariationId: pipe(string(), minLength(1)),\n});\n\nexport const parseBookingPrice = (value: unknown) => parse(priceSchema, value);\nexport const parseBookingConfiguration = (value: unknown) =>\n parse(configurationSchema, value);\nexport const parseBookingAvailability = (value: unknown) =>\n parse(object({ message: string(), slots: array(instant) }), value);\nexport const parseBookingAttempt = (value: unknown) =>\n parse(attemptSchema, value);\nexport const parseBookingRecovery = (value: unknown) =>\n parse(nullable(attemptSchema), value);\nexport function parseBookingCustomer(value: unknown) {\n const result = safeParse(customerSchema, value);\n return result.success ? result.output : null;\n}\nexport const parseBookingSession = (value: unknown) =>\n parse(sessionSchema, value);\n","import {\n parseBookingAttempt,\n parseBookingAvailability,\n parseBookingConfiguration,\n parseBookingCustomer,\n parseBookingPrice,\n parseBookingRecovery,\n parseBookingSession,\n} from \"./booking-schemas.ts\";\nimport type {\n CreateLockerverseBookingsOptions,\n LockerverseBookingSelection,\n LockerverseBookingsClient,\n} from \"./booking-types.ts\";\nimport { deepFreeze } from \"./deep-freeze.ts\";\nimport { resolveResourceEnvironment } from \"./environment.ts\";\nimport { createSdkErrorReporter } from \"./error-reporting.ts\";\nimport { createTransport } from \"./transport.ts\";\nimport { LockerverseSdkError, type LockerverseSdkOperation } from \"./types.ts\";\n\nconst BUSINESS_KEY = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nconst ACCESS_TOKEN = /^[A-Za-z0-9_-]{43}$/;\nconst DATE = /^\\d{4}-\\d{2}-\\d{2}$/;\nconst CONFIRMATION_TOKEN = /^ctoken_[A-Za-z0-9]+$/;\n\n/** Business identity is public; the token is obtained only at request time. */\nexport function createLockerverseBookingsClient(\n options: CreateLockerverseBookingsOptions\n): LockerverseBookingsClient {\n if (\n !BUSINESS_KEY.test(options.businessKey) ||\n options.businessKey.length > 80\n ) {\n throw new TypeError(\"businessKey must be a valid booking business key.\");\n }\n // Reuse the SDK environment/URL rules with this business as the resource identity.\n const runtime = resolveResourceEnvironment(\n {\n ...options,\n communitySlug: options.businessKey,\n requestTimeoutMs: options.requestTimeoutMs ?? 60_000,\n },\n \"businessKey\"\n );\n const reportError = createSdkErrorReporter({\n communitySlug: \"\",\n environment: runtime.environment,\n getContext: () => ({ businessKey: options.businessKey }),\n onError: runtime.onError,\n resourceContextName: \"lockerverse_bookings\",\n sentryDsn: runtime.sentryDsn,\n });\n const { requestJson } = createTransport(\n runtime.fetchImplementation,\n reportError,\n runtime.requestTimeoutMs\n );\n const baseUrl = `${runtime.apiBaseUrl}/v2/booking-businesses/${runtime.resourceSlug}`;\n\n async function requestHeaders(\n operation: LockerverseSdkOperation,\n sessionToken?: string | null\n ) {\n const token =\n sessionToken === undefined\n ? await options.getAccessToken()\n : sessionToken;\n if (\n sessionToken !== null &&\n (token === null || !ACCESS_TOKEN.test(token))\n ) {\n throw new LockerverseSdkError({\n code: \"booking_request_failed\",\n message:\n \"Booking access is not ready. Check your saved booking before trying again.\",\n operation,\n reportable: false,\n status: 401,\n });\n }\n const headers = new Headers();\n if (token !== null) {\n headers.set(\"Authorization\", `Bearer ${token}`);\n }\n return headers;\n }\n\n async function request<T>(\n path: string,\n operation: LockerverseSdkOperation,\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- The transport parses untrusted JSON through this boundary.\n parser: (value: unknown) => T,\n body?:\n | LockerverseBookingSelection\n | { confirmationToken: string }\n | { serviceVariationId: string; email: string }\n | Record<string, never>,\n sessionToken?: string | null\n ): Promise<T> {\n const context = {\n code: \"booking_request_failed\" as const,\n message:\n \"Unable to complete the booking request. Check the saved state before trying payment again.\",\n operation,\n report: false,\n };\n try {\n const headers = await requestHeaders(operation, sessionToken);\n const init: RequestInit = {\n cache: \"no-store\",\n credentials: \"omit\",\n headers,\n method: body === undefined ? \"GET\" : \"POST\",\n redirect: \"error\",\n };\n if (body !== undefined) {\n init.body = JSON.stringify(body);\n headers.set(\"Content-Type\", \"application/json\");\n }\n const response = await requestJson(\n `${baseUrl}${path}`,\n init,\n parser,\n context,\n context\n );\n if (!response.ok) {\n throw new LockerverseSdkError({\n ...context,\n message: [401, 403].includes(response.response.status)\n ? \"Booking access has expired or is not valid. Your saved attempt is retained.\"\n : context.message,\n recoveryRecommended: true,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n return deepFreeze(response.value);\n } catch (error) {\n throw reportError(\n error instanceof LockerverseSdkError\n ? error\n : new LockerverseSdkError({\n ...context,\n recoveryRecommended: true,\n reportable: false,\n })\n );\n }\n }\n\n return {\n availability(date, serviceVariationId) {\n if (!DATE.test(date)) {\n throw new TypeError(\n \"date must use YYYY-MM-DD in the business time zone.\"\n );\n }\n const query = new URLSearchParams({ date });\n if (serviceVariationId !== undefined) {\n query.set(\"serviceVariationId\", serviceVariationId);\n }\n return request(\n `/slots?${query}`,\n \"find_booking_availability\",\n parseBookingAvailability\n );\n },\n businessKey: options.businessKey,\n async configuration() {\n const result = await request(\n \"/config\",\n \"load_booking_configuration\",\n parseBookingConfiguration\n );\n if (result.business.key !== options.businessKey) {\n throw reportError(\n new LockerverseSdkError({\n code: \"booking_request_failed\",\n message: \"The booking response does not match this business.\",\n operation: \"load_booking_configuration\",\n reportable: true,\n })\n );\n }\n return result;\n },\n confirm(confirmationToken) {\n if (\n !CONFIRMATION_TOKEN.test(confirmationToken) ||\n confirmationToken.length > 512\n ) {\n throw new TypeError(\"A valid payment confirmation token is required.\");\n }\n return request(\"/confirm\", \"confirm_booking\", parseBookingAttempt, {\n confirmationToken,\n });\n },\n createSession(previousAccessToken) {\n if (\n previousAccessToken !== undefined &&\n !ACCESS_TOKEN.test(previousAccessToken)\n ) {\n throw new TypeError(\"A valid existing booking session is required.\");\n }\n return request(\n \"/session\",\n \"create_booking_session\",\n parseBookingSession,\n {},\n previousAccessToken ?? null\n );\n },\n initialize(selection) {\n if (\n !(\n DATE.test(selection.date) &&\n Number.isFinite(Date.parse(selection.start))\n )\n ) {\n throw new TypeError(\"Select an available booking date and time.\");\n }\n const customer =\n selection.customer === undefined\n ? undefined\n : parseBookingCustomer(selection.customer);\n if (customer === null) {\n throw new TypeError(\n \"Enter your name, email and international phone number.\"\n );\n }\n const body: LockerverseBookingSelection = {\n date: selection.date,\n start: selection.start,\n };\n if (selection.serviceVariationId !== undefined) {\n body.serviceVariationId = selection.serviceVariationId;\n }\n if (customer !== undefined) {\n body.customer = customer;\n }\n return request(\n \"/attempt\",\n \"initialize_booking\",\n parseBookingAttempt,\n body\n );\n },\n price(serviceVariationId, email) {\n const customerEmail = email.trim();\n if (\n !(serviceVariationId && customerEmail.includes(\"@\")) ||\n customerEmail.length > 254\n ) {\n throw new TypeError(\"Choose a service and enter a valid email.\");\n }\n return request(\"/price\", \"quote_booking_price\", parseBookingPrice, {\n email: customerEmail,\n serviceVariationId,\n });\n },\n recover: () =>\n request(\"/recover\", \"recover_booking\", parseBookingRecovery, {}),\n };\n}\n"],"mappings":"kXAwBA,MAAM,EAAqB,EAAK,EAAO,EAAG,EAAY,EAAG,EAAS,CAAC,CAAC,EAC9D,EAAiB,EAAO,CAC5B,MAAO,EAAK,EAAO,EAAG,EAAK,EAAG,EAAM,EAAG,EAAU,GAAG,CAAC,EACrD,KAAM,EAAK,EAAO,EAAG,EAAK,EAAG,EAAU,CAAC,EAAG,EAAU,GAAG,CAAC,EACzD,MAAO,EAAK,EAAO,EAAG,EAAM,mBAAmB,CAAC,CAClD,CAAC,EACK,EAAgB,CACpB,YAAa,EACb,SAAU,EAAQ,KAAK,EACvB,gBAAiB,EAAK,EAAO,EAAG,EAAY,EAAG,EAAS,CAAC,CAAC,EAC1D,KAAM,EAAO,CACf,EACM,EAAiB,EAAO,CAC5B,YAAa,EAAS,EAAS,CAAC,UAAW,YAAY,CAAC,CAA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E,OAAO,EAAQ,SAAU,sBAAuB,EAAmB,CACjE,MAAO,EACP,oBACF,CAAC,CACH,EACA,YACE,EAAQ,WAAY,kBAAmB,EAAsB,CAAC,CAAC,CACnE,CACF"}
|
|
1
|
+
{"version":3,"file":"bookings.js","names":[],"sources":["../src/booking-schemas.ts","../src/booking-client.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters -- These schema parsers are the untrusted HTTP JSON boundary. */\nimport {\n array,\n boolean,\n email,\n isoTimestamp,\n literal,\n maxLength,\n minLength,\n minValue,\n nullable,\n number,\n object,\n optional,\n parse,\n picklist,\n pipe,\n regex,\n safeInteger,\n safeParse,\n string,\n trim,\n} from \"valibot\";\n\nconst nonnegativeInteger = pipe(number(), safeInteger(), minValue(0));\nconst customerSchema = object({\n email: pipe(string(), trim(), email(), maxLength(254)),\n name: pipe(string(), trim(), minLength(1), maxLength(120)),\n phone: pipe(string(), regex(/^\\+[1-9]\\d{7,14}$/)),\n});\nconst serviceFields = {\n amountCents: nonnegativeInteger,\n currency: literal(\"USD\"),\n durationMinutes: pipe(number(), safeInteger(), minValue(1)),\n name: string(),\n};\nconst businessSchema = object({\n communityId: optional(string()),\n environment: optional(picklist([\"sandbox\", \"production\"])),\n key: string(),\n name: string(),\n service: object(serviceFields),\n services: optional(\n array(\n object({\n ...serviceFields,\n memberPrice: optional(\n object({ amountCents: nonnegativeInteger, label: string() })\n ),\n serviceVariationId: pipe(string(), minLength(1)),\n })\n )\n ),\n timeZone: string(),\n});\nconst configurationSchema = object({\n business: businessSchema,\n diagnosticCode: optional(string()),\n lockerverse: boolean(),\n message: string(),\n payment: optional(\n object({\n publishableKey: pipe(string(), regex(/^pk_(?:test|live)_/)),\n stripeAccountId: nullable(pipe(string(), regex(/^acct_[A-Za-z0-9]+$/))),\n })\n ),\n ready: boolean(),\n reviewer: boolean(),\n square: boolean(),\n});\nconst instant = pipe(string(), isoTimestamp());\nconst attemptSchema = object({\n amountCents: optional(nonnegativeInteger),\n bookingId: optional(string()),\n bookingStatus: optional(string()),\n clientSecret: optional(string()),\n currency: optional(literal(\"USD\")),\n id: string(),\n message: string(),\n priceLabel: optional(string()),\n publishableKey: string(),\n regularAmountCents: optional(nonnegativeInteger),\n serviceName: optional(string()),\n squarePaymentId: optional(string()),\n start: instant,\n status: picklist([\n \"review\",\n \"payment_pending\",\n \"payment_action_required\",\n \"payment_failed\",\n \"paid\",\n \"booking_pending\",\n \"booking_created\",\n \"external_payment_pending\",\n \"complete\",\n \"manual_refund_required\",\n ]),\n stripeAccountId: optional(nullable(string())),\n timeZone: optional(string()),\n});\nconst sessionSchema = object({\n accessToken: pipe(string(), regex(/^[A-Za-z0-9_-]{43}$/)),\n expiresAt: instant,\n});\n\nconst priceSchema = object({\n amountCents: nonnegativeInteger,\n currency: literal(\"USD\"),\n memberPrice: nullable(object({ label: string() })),\n regularAmountCents: nonnegativeInteger,\n serviceVariationId: pipe(string(), minLength(1)),\n});\n\nexport const parseBookingPrice = (value: unknown) => parse(priceSchema, value);\nexport const parseBookingConfiguration = (value: unknown) =>\n parse(configurationSchema, value);\nexport const parseBookingAvailability = (value: unknown) =>\n parse(object({ message: string(), slots: array(instant) }), value);\nexport const parseBookingAttempt = (value: unknown) =>\n parse(attemptSchema, value);\nexport const parseBookingRecovery = (value: unknown) =>\n parse(nullable(attemptSchema), value);\nexport function parseBookingCustomer(value: unknown) {\n const result = safeParse(customerSchema, value);\n return result.success ? result.output : null;\n}\nexport const parseBookingSession = (value: unknown) =>\n parse(sessionSchema, value);\n","import {\n parseBookingAttempt,\n parseBookingAvailability,\n parseBookingConfiguration,\n parseBookingCustomer,\n parseBookingPrice,\n parseBookingRecovery,\n parseBookingSession,\n} from \"./booking-schemas.ts\";\nimport type {\n CreateLockerverseBookingsOptions,\n LockerverseBookingSelection,\n LockerverseBookingsClient,\n} from \"./booking-types.ts\";\nimport { deepFreeze } from \"./deep-freeze.ts\";\nimport { resolveResourceEnvironment } from \"./environment.ts\";\nimport { createSdkErrorReporter } from \"./error-reporting.ts\";\nimport { createTransport } from \"./transport.ts\";\nimport { LockerverseSdkError, type LockerverseSdkOperation } from \"./types.ts\";\n\nconst BUSINESS_KEY = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nconst ACCESS_TOKEN = /^[A-Za-z0-9_-]{43}$/;\nconst DATE = /^\\d{4}-\\d{2}-\\d{2}$/;\nconst CONFIRMATION_TOKEN = /^ctoken_[A-Za-z0-9]+$/;\n\n/** Business identity is public; the token is obtained only at request time. */\nexport function createLockerverseBookingsClient(\n options: CreateLockerverseBookingsOptions\n): LockerverseBookingsClient {\n if (\n !BUSINESS_KEY.test(options.businessKey) ||\n options.businessKey.length > 80\n ) {\n throw new TypeError(\"businessKey must be a valid booking business key.\");\n }\n // Reuse the SDK environment/URL rules with this business as the resource identity.\n const runtime = resolveResourceEnvironment(\n {\n ...options,\n communitySlug: options.businessKey,\n requestTimeoutMs: options.requestTimeoutMs ?? 60_000,\n },\n \"businessKey\"\n );\n const reportError = createSdkErrorReporter({\n communitySlug: \"\",\n environment: runtime.environment,\n getContext: () => ({ businessKey: options.businessKey }),\n onError: runtime.onError,\n resourceContextName: \"lockerverse_bookings\",\n sentryDsn: runtime.sentryDsn,\n });\n const { requestJson } = createTransport(\n runtime.fetchImplementation,\n reportError,\n runtime.requestTimeoutMs\n );\n const baseUrl = `${runtime.apiBaseUrl}/v2/booking-businesses/${runtime.resourceSlug}`;\n\n async function requestHeaders(\n operation: LockerverseSdkOperation,\n sessionToken?: string | null\n ) {\n const token =\n sessionToken === undefined\n ? await options.getAccessToken()\n : sessionToken;\n if (\n sessionToken !== null &&\n (token === null || !ACCESS_TOKEN.test(token))\n ) {\n throw new LockerverseSdkError({\n code: \"booking_request_failed\",\n message:\n \"Booking access is not ready. Check your saved booking before trying again.\",\n operation,\n reportable: false,\n status: 401,\n });\n }\n const headers = new Headers();\n if (token !== null) {\n headers.set(\"Authorization\", `Bearer ${token}`);\n }\n return headers;\n }\n\n async function request<T>(\n path: string,\n operation: LockerverseSdkOperation,\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- The transport parses untrusted JSON through this boundary.\n parser: (value: unknown) => T,\n body?:\n | LockerverseBookingSelection\n | { confirmationToken: string }\n | { serviceVariationId: string; email: string }\n | Record<string, never>,\n sessionToken?: string | null\n ): Promise<T> {\n const context = {\n code: \"booking_request_failed\" as const,\n message:\n \"Unable to complete the booking request. Check the saved state before trying payment again.\",\n operation,\n report: false,\n };\n try {\n const headers = await requestHeaders(operation, sessionToken);\n const init: RequestInit = {\n cache: \"no-store\",\n credentials: \"omit\",\n headers,\n method: body === undefined ? \"GET\" : \"POST\",\n redirect: \"error\",\n };\n if (body !== undefined) {\n init.body = JSON.stringify(body);\n headers.set(\"Content-Type\", \"application/json\");\n }\n const response = await requestJson(\n `${baseUrl}${path}`,\n init,\n parser,\n context,\n context\n );\n if (!response.ok) {\n throw new LockerverseSdkError({\n ...context,\n message: [401, 403].includes(response.response.status)\n ? \"Booking access has expired or is not valid. Your saved attempt is retained.\"\n : context.message,\n recoveryRecommended: true,\n reportable: response.response.status >= 500,\n status: response.response.status,\n });\n }\n return deepFreeze(response.value);\n } catch (error) {\n throw reportError(\n error instanceof LockerverseSdkError\n ? error\n : new LockerverseSdkError({\n ...context,\n recoveryRecommended: true,\n reportable: false,\n })\n );\n }\n }\n\n return {\n availability(date, serviceVariationId) {\n if (!DATE.test(date)) {\n throw new TypeError(\n \"date must use YYYY-MM-DD in the business time zone.\"\n );\n }\n const query = new URLSearchParams({ date });\n if (serviceVariationId !== undefined) {\n query.set(\"serviceVariationId\", serviceVariationId);\n }\n return request(\n `/slots?${query}`,\n \"find_booking_availability\",\n parseBookingAvailability\n );\n },\n businessKey: options.businessKey,\n async configuration() {\n const result = await request(\n \"/config\",\n \"load_booking_configuration\",\n parseBookingConfiguration\n );\n if (result.business.key !== options.businessKey) {\n throw reportError(\n new LockerverseSdkError({\n code: \"booking_request_failed\",\n message: \"The booking response does not match this business.\",\n operation: \"load_booking_configuration\",\n reportable: true,\n })\n );\n }\n return result;\n },\n confirm(confirmationToken) {\n if (\n !CONFIRMATION_TOKEN.test(confirmationToken) ||\n confirmationToken.length > 512\n ) {\n throw new TypeError(\"A valid payment confirmation token is required.\");\n }\n return request(\"/confirm\", \"confirm_booking\", parseBookingAttempt, {\n confirmationToken,\n });\n },\n createSession(previousAccessToken) {\n if (\n previousAccessToken !== undefined &&\n !ACCESS_TOKEN.test(previousAccessToken)\n ) {\n throw new TypeError(\"A valid existing booking session is required.\");\n }\n return request(\n \"/session\",\n \"create_booking_session\",\n parseBookingSession,\n {},\n previousAccessToken ?? null\n );\n },\n initialize(selection) {\n if (\n !(\n DATE.test(selection.date) &&\n Number.isFinite(Date.parse(selection.start))\n )\n ) {\n throw new TypeError(\"Select an available booking date and time.\");\n }\n const customer =\n selection.customer === undefined\n ? undefined\n : parseBookingCustomer(selection.customer);\n if (customer === null) {\n throw new TypeError(\n \"Enter your name, email and international phone number.\"\n );\n }\n const body: LockerverseBookingSelection = {\n date: selection.date,\n start: selection.start,\n };\n if (selection.serviceVariationId !== undefined) {\n body.serviceVariationId = selection.serviceVariationId;\n }\n if (customer !== undefined) {\n body.customer = customer;\n }\n return request(\n \"/attempt\",\n \"initialize_booking\",\n parseBookingAttempt,\n body\n );\n },\n price(serviceVariationId, email) {\n const customerEmail = email.trim();\n if (\n !(serviceVariationId && customerEmail.includes(\"@\")) ||\n customerEmail.length > 254\n ) {\n throw new TypeError(\"Choose a service and enter a valid email.\");\n }\n return request(\"/price\", \"quote_booking_price\", parseBookingPrice, {\n email: customerEmail,\n serviceVariationId,\n });\n },\n recover: () =>\n request(\"/recover\", \"recover_booking\", parseBookingRecovery, {}),\n };\n}\n"],"mappings":"kXAwBA,MAAM,EAAqB,EAAK,EAAO,EAAG,EAAY,EAAG,EAAS,CAAC,CAAC,EAC9D,EAAiB,EAAO,CAC5B,MAAO,EAAK,EAAO,EAAG,EAAK,EAAG,EAAM,EAAG,EAAU,GAAG,CAAC,E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C,GAAI,IAAa,KACf,MAAU,UACR,wDACF,EAEF,IAAM,EAAoC,CACxC,KAAM,EAAU,KAChB,MAAO,EAAU,KACnB,EAOA,OANI,EAAU,qBAAuB,IAAA,KACnC,EAAK,mBAAqB,EAAU,oBAElC,IAAa,IAAA,KACf,EAAK,SAAW,GAEX,EACL,WACA,qBACA,EACA,CACF,CACF,EACA,MAAM,EAAoB,EAAO,CAC/B,IAAM,EAAgB,EAAM,KAAK,EACjC,GACE,EAAE,GAAsB,EAAc,SAAS,GAAG,IAClD,EAAc,OAAS,IAEvB,MAAU,UAAU,2CAA2C,EAEjE,OAAO,EAAQ,SAAU,sBAAuB,EAAmB,CACjE,MAAO,EACP,oBACF,CAAC,CACH,EACA,YACE,EAAQ,WAAY,kBAAmB,EAAsB,CAAC,CAAC,CACnE,CACF"}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=`0.2.
|
|
1
|
+
const e=`0.2.258`;var t=class extends Error{failureKind;code;operation;reportable;recoveryRecommended;sdkVersion;serverCode;status;constructor({failureKind:t,code:n,message:r,operation:i,reportable:a,recoveryRecommended:o=!1,serverCode:s,status:c}){super(r),this.name=`LockerverseSdkError`,this.failureKind=t,this.code=n,this.operation=i,this.reportable=a,this.recoveryRecommended=o,this.sdkVersion=e,this.serverCode=s,this.status=c}};export{t as n,e as t};
|
|
2
2
|
//# sourceMappingURL=types.js.map
|