@jay-framework/wix-bookings 0.25.1 → 0.25.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { createJayService, makeJayInit, makeJayStackComponent, phaseOutput, RenderPipeline, makeJayQuery, makeJayAction } from "@jay-framework/fullstack-component";
2
2
  import { registerService, getService } from "@jay-framework/stack-server-runtime";
3
- import { wixFetch, WixApiError, WIX_CLIENT_SERVICE } from "@jay-framework/wix-server-client";
4
- import { l as loadWixBookingsConfig } from "./config-loader-C7I2yXpp.js";
3
+ import { WIX_CLIENT_SERVICE } from "@jay-framework/wix-server-client";
4
+ import { l as loadWixBookingsConfig } from "./config-loader-sfgwfXPV.js";
5
+ import { wixFetch, WixApiError } from "@jay-framework/wix-server-client/client";
6
+ import { createJayContext } from "@jay-framework/runtime";
7
+ const WIX_BOOKINGS_SERVICE = createJayService("WixBookingsService");
5
8
  const MAX_SLOTS_PER_QUERY = 200;
6
9
  const SERVICES_PAGE_SIZE = 100;
7
- const WIX_BOOKINGS_SERVICE = createJayService("WixBookingsService");
8
10
  function formatPrice(service) {
9
11
  const price = service.payment?.fixed?.price;
10
12
  if (!price?.value) {
@@ -118,7 +120,12 @@ async function calculateBookingCart(client, cartId) {
118
120
  return wixFetch(client, `/ecom/v2/carts/${cartId}/calculate`, { method: "POST", body: {} });
119
121
  }
120
122
  async function placeBookingOrder(client, cartId) {
121
- await wixFetch(client, `/ecom/v2/carts/${cartId}/place-order`, { method: "POST", body: {} });
123
+ const res = await wixFetch(
124
+ client,
125
+ `/ecom/v2/carts/${cartId}/place-order`,
126
+ { method: "POST", body: {} }
127
+ );
128
+ return { orderId: res?.orderId };
122
129
  }
123
130
  async function createBookingRedirectSession(client, cartId, postFlowUrl) {
124
131
  return wixFetch(client, "/headless/v1/redirect-session", {
@@ -258,8 +265,8 @@ async function resolvePaidCheckoutRedirectUrl(wixClient, cartId, postFlowUrl) {
258
265
  }
259
266
  return checkoutUrl;
260
267
  }
261
- function provideWixBookingsService(wixClient, config) {
262
- const service = {
268
+ function createWixBookingsService(wixClient, config) {
269
+ return {
263
270
  async listServices() {
264
271
  const items = await queryBookingServices(wixClient, config.bookingAppId);
265
272
  return items.filter((item) => !item.hidden).map((item) => mapService(item));
@@ -308,12 +315,16 @@ function provideWixBookingsService(wixClient, config) {
308
315
  endDate: input.slot.localEndDate,
309
316
  timezone: input.timezone,
310
317
  location: { locationType: "OWNER_BUSINESS" },
311
- resourceSelections: [
312
- {
313
- resourceTypeId: config.staffResourceTypeId,
314
- selectionMethod: "ANY_RESOURCE"
315
- }
316
- ]
318
+ // Any staff member of the configured staff resource type; without one, the slot's own (a class
319
+ // session names its staff; Wix rejects an empty resource type id).
320
+ ...config.staffResourceTypeId ? {
321
+ resourceSelections: [
322
+ {
323
+ resourceTypeId: config.staffResourceTypeId,
324
+ selectionMethod: "ANY_RESOURCE"
325
+ }
326
+ ]
327
+ } : {}
317
328
  };
318
329
  if (input.serviceType === "APPOINTMENT") {
319
330
  slotData.scheduleId = input.slot.scheduleId;
@@ -342,10 +353,13 @@ function provideWixBookingsService(wixClient, config) {
342
353
  );
343
354
  return { outcome: "redirect", redirectUrl };
344
355
  }
345
- await placeBookingOrder(wixClient, cartId);
346
- return { outcome: "confirmed" };
356
+ const { orderId } = await placeBookingOrder(wixClient, cartId);
357
+ return { outcome: "confirmed", ...orderId ? { orderId } : {} };
347
358
  }
348
359
  };
360
+ }
361
+ function provideWixBookingsService(wixClient, config) {
362
+ const service = createWixBookingsService(wixClient, config);
349
363
  registerService(WIX_BOOKINGS_SERVICE, service);
350
364
  return service;
351
365
  }
@@ -356,7 +370,7 @@ const init = makeJayInit().withServer(async () => {
356
370
  provideWixBookingsService(wixClient, config);
357
371
  console.log(`[wix-bookings] Booking app ID: ${config.bookingAppId}`);
358
372
  console.log("[wix-bookings] Server initialization complete");
359
- return {};
373
+ return { config };
360
374
  });
361
375
  async function renderSlowlyChanging(_props, bookings) {
362
376
  try {
@@ -411,10 +425,119 @@ const listSlots = makeJayQuery("wixBookings.listSlots").withServices(WIX_BOOKING
411
425
  const createBooking = makeJayAction("wixBookings.createBooking").withServices(WIX_BOOKINGS_SERVICE).withHandler(
412
426
  async (input, bookings) => bookings.createBooking(input)
413
427
  );
428
+ function canBookOnline(features, type, step) {
429
+ if (type === "COURSE") return step !== "form" || features.courses;
430
+ return type === "CLASS" ? features.groups : features.appointments;
431
+ }
432
+ const WIX_BOOKINGS_CONTEXT = createJayContext("wix:bookings");
433
+ function createWixBookingsContext(wixClient, config) {
434
+ let settings;
435
+ const readSettings = () => {
436
+ if (!settings) {
437
+ settings = wixFetch(
438
+ wixClient,
439
+ "/_api/bookings-settings/v2/settings?fields=FEATURES&fields=SITE_PROPERTIES"
440
+ ).then((res) => res.bookingsSettings).catch(() => {
441
+ settings = void 0;
442
+ return void 0;
443
+ });
444
+ }
445
+ return settings;
446
+ };
447
+ const service = createWixBookingsService(wixClient, config);
448
+ const ownBookings = async (filter) => {
449
+ const res = await wixFetch(wixClient, "/_api/bookings-reader/v2/extended-bookings/query", {
450
+ method: "POST",
451
+ body: {
452
+ query: { filter, cursorPaging: { limit: 100 } },
453
+ withBookingAllowedActions: false
454
+ }
455
+ }).catch(() => ({ extendedBookings: [] }));
456
+ return (res.extendedBookings ?? []).map((e) => e.booking ?? {});
457
+ };
458
+ return {
459
+ async features() {
460
+ const f = (await readSettings())?.features ?? {};
461
+ return {
462
+ groups: Boolean(f.bookingsGroups?.enabled),
463
+ appointments: Boolean(f.bookingsAppointments?.enabled),
464
+ courses: Boolean(f.bookingsCourses?.enabled),
465
+ payments: Boolean(f.bookingsPayments?.enabled)
466
+ };
467
+ },
468
+ async timeZone() {
469
+ return (await readSettings())?.siteProperties?.timeZone ?? "UTC";
470
+ },
471
+ async serviceBySlug(slug) {
472
+ const res = await wixFetch(
473
+ wixClient,
474
+ "/bookings/v2/services/query",
475
+ {
476
+ method: "POST",
477
+ body: {
478
+ query: {
479
+ filter: { "supportedSlugs.name": slug, hidden: false },
480
+ paging: { limit: 1 }
481
+ }
482
+ }
483
+ }
484
+ );
485
+ return res.services?.[0];
486
+ },
487
+ serviceById(id) {
488
+ return getBookingServiceById(wixClient, id);
489
+ },
490
+ async timeSlots(query) {
491
+ const res = await wixFetch(
492
+ wixClient,
493
+ "/_api/service-availability/v2/time-slots/event",
494
+ {
495
+ method: "POST",
496
+ body: {
497
+ serviceIds: query.serviceIds,
498
+ timeZone: query.timeZone,
499
+ fromLocalDate: query.fromLocalDate,
500
+ toLocalDate: query.toLocalDate,
501
+ includeNonBookable: query.includeNonBookable ?? true,
502
+ ...query.maxSlotsPerDay ? { maxSlotsPerDay: query.maxSlotsPerDay } : {},
503
+ eventFilter: {},
504
+ cursorPaging: { limit: query.limit ?? 1e3 }
505
+ }
506
+ }
507
+ );
508
+ return res.timeSlots ?? [];
509
+ },
510
+ createBooking: service.createBooking,
511
+ async serviceBookings(serviceId) {
512
+ return (await ownBookings({
513
+ "bookedEntity.slot.serviceId": serviceId,
514
+ status: { $in: ["CONFIRMED", "PENDING"] }
515
+ })).filter((b) => b.id || b.startDate);
516
+ },
517
+ async bookingById(bookingId) {
518
+ return (await ownBookings({ id: bookingId }))[0];
519
+ },
520
+ async orderById(orderId) {
521
+ try {
522
+ const res = await wixFetch(
523
+ wixClient,
524
+ `/ecom/v1/orders/${encodeURIComponent(orderId)}`
525
+ );
526
+ return res.order;
527
+ } catch (error) {
528
+ if (error instanceof WixApiError) return void 0;
529
+ throw error;
530
+ }
531
+ }
532
+ };
533
+ }
414
534
  export {
535
+ WIX_BOOKINGS_CONTEXT,
415
536
  WIX_BOOKINGS_SERVICE,
416
537
  bookingFlow,
538
+ canBookOnline,
417
539
  createBooking,
540
+ createWixBookingsContext,
418
541
  init,
419
542
  listServices,
420
543
  listSlots,
package/dist/tools.js CHANGED
@@ -2,7 +2,7 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { hasService } from "@jay-framework/stack-server-runtime";
4
4
  import { WIX_FORMS_SERVICE } from "@jay-framework/wix-forms";
5
- import { l as loadWixBookingsConfig } from "./config-loader-C7I2yXpp.js";
5
+ import { l as loadWixBookingsConfig } from "./config-loader-sfgwfXPV.js";
6
6
  const CONFIG_FILE = ".wix-bookings.yaml";
7
7
  const CONFIG_TEMPLATE = `# Wix Bookings Configuration
8
8
  #
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/wix-bookings",
3
- "version": "0.25.1",
3
+ "version": "0.25.5",
4
4
  "type": "module",
5
5
  "description": "Wix Bookings package for Jay Framework — browse services, pick slots, submit participant details, complete checkout",
6
6
  "license": "Apache-2.0",
@@ -19,7 +19,10 @@
19
19
  "types": "./dist/index.client.d.ts",
20
20
  "default": "./dist/index.client.js"
21
21
  },
22
- "./tools": "./dist/tools.js",
22
+ "./tools": {
23
+ "types": "./dist/tools.d.ts",
24
+ "default": "./dist/tools.js"
25
+ },
23
26
  "./plugin.yaml": "./plugin.yaml",
24
27
  "./booking-flow.jay-contract": "./dist/contracts/booking-flow.jay-contract",
25
28
  "./list-services.jay-action": "./dist/actions/list-services.jay-action",
@@ -40,15 +43,15 @@
40
43
  "test": "vitest run"
41
44
  },
42
45
  "dependencies": {
43
- "@jay-framework/component": "^0.25.1",
44
- "@jay-framework/fullstack-component": "^0.25.1",
45
- "@jay-framework/reactive": "^0.25.1",
46
- "@jay-framework/runtime": "^0.25.1",
47
- "@jay-framework/secure": "^0.25.1",
48
- "@jay-framework/stack-client-runtime": "^0.25.1",
49
- "@jay-framework/stack-server-runtime": "^0.25.1",
50
- "@jay-framework/wix-forms": "^0.25.1",
51
- "@jay-framework/wix-server-client": "^0.25.1",
46
+ "@jay-framework/component": "^0.25.5",
47
+ "@jay-framework/fullstack-component": "^0.25.5",
48
+ "@jay-framework/reactive": "^0.25.5",
49
+ "@jay-framework/runtime": "^0.25.5",
50
+ "@jay-framework/secure": "^0.25.5",
51
+ "@jay-framework/stack-client-runtime": "^0.25.5",
52
+ "@jay-framework/stack-server-runtime": "^0.25.5",
53
+ "@jay-framework/wix-forms": "^0.25.5",
54
+ "@jay-framework/wix-server-client": "^0.25.5",
52
55
  "@wix/sdk": "^1.21.5",
53
56
  "js-yaml": "^4.1.0"
54
57
  },
@@ -56,10 +59,10 @@
56
59
  "@babel/core": "^7.23.7",
57
60
  "@babel/preset-env": "^7.23.8",
58
61
  "@babel/preset-typescript": "^7.23.3",
59
- "@jay-framework/compiler-jay-stack": "^0.25.1",
60
- "@jay-framework/jay-cli": "^0.25.1",
61
- "@jay-framework/jay-stack-cli": "^0.25.1",
62
- "@jay-framework/vite-plugin": "^0.25.1",
62
+ "@jay-framework/compiler-jay-stack": "^0.25.5",
63
+ "@jay-framework/jay-cli": "^0.25.5",
64
+ "@jay-framework/jay-stack-cli": "^0.25.5",
65
+ "@jay-framework/vite-plugin": "^0.25.5",
63
66
  "@jay-framework/wix-dev-environment": "^0.6.12",
64
67
  "nodemon": "^3.0.3",
65
68
  "rimraf": "^5.0.5",
@@ -1,194 +0,0 @@
1
- import * as _jay_framework_fullstack_component from '@jay-framework/fullstack-component';
2
- import { Signals } from '@jay-framework/fullstack-component';
3
- import * as _jay_framework_component from '@jay-framework/component';
4
- import { HTMLElementProxy, HTMLElementCollectionProxy } from '@jay-framework/runtime';
5
-
6
- declare const init: _jay_framework_fullstack_component.JayInit<{}>;
7
-
8
- interface ServiceOfBookingFlowViewState {
9
- id: string,
10
- name: string,
11
- description: string,
12
- type: string,
13
- durationLabel: string,
14
- priceLabel: string,
15
- formId: string
16
- }
17
-
18
- interface SlotOfBookingFlowViewState {
19
- id: string,
20
- label: string,
21
- localStartDate: string,
22
- localEndDate: string,
23
- scheduleId: string,
24
- eventId: string
25
- }
26
-
27
- interface FormFieldOfBookingFlowViewState {
28
- target: string,
29
- label: string,
30
- type: string,
31
- required: boolean
32
- }
33
-
34
- interface BookingFlowViewState {
35
- services: Array<ServiceOfBookingFlowViewState>,
36
- servicesLoading: boolean,
37
- showNoServices: boolean,
38
- hasSlots: boolean,
39
- servicesError: string,
40
- showServices: boolean,
41
- showSlots: boolean,
42
- showForm: boolean,
43
- selectedServiceName: string,
44
- slots: Array<SlotOfBookingFlowViewState>,
45
- slotsLoading: boolean,
46
- slotsMessage: string,
47
- formFields: Array<FormFieldOfBookingFlowViewState>,
48
- formLoading: boolean,
49
- isBooking: boolean,
50
- bookingStatus: string,
51
- bookingError: string
52
- }
53
-
54
- type BookingFlowSlowViewState = {};
55
-
56
- type BookingFlowFastViewState = Pick<BookingFlowViewState, 'servicesLoading' | 'showNoServices' | 'hasSlots' | 'servicesError' | 'showServices' | 'showSlots' | 'showForm' | 'selectedServiceName' | 'slotsLoading' | 'slotsMessage' | 'formLoading' | 'isBooking' | 'bookingStatus' | 'bookingError'> & {
57
- services: Array<BookingFlowViewState['services'][number]>;
58
- slots: Array<BookingFlowViewState['slots'][number]>;
59
- formFields: Array<BookingFlowViewState['formFields'][number]>;
60
- };
61
-
62
- type BookingFlowInteractiveViewState = Pick<BookingFlowViewState, 'servicesLoading' | 'showNoServices' | 'hasSlots' | 'servicesError' | 'showServices' | 'showSlots' | 'showForm' | 'selectedServiceName' | 'slotsLoading' | 'slotsMessage' | 'formLoading' | 'isBooking' | 'bookingStatus' | 'bookingError'> & {
63
- services: Array<BookingFlowViewState['services'][number]>;
64
- slots: Array<BookingFlowViewState['slots'][number]>;
65
- formFields: Array<BookingFlowViewState['formFields'][number]>;
66
- };
67
-
68
-
69
- interface BookingFlowRefs {
70
- bookButton: HTMLElementProxy<BookingFlowViewState, HTMLButtonElement>,
71
- backButton: HTMLElementProxy<BookingFlowViewState, HTMLButtonElement>,
72
- services: {
73
- serviceButtons: HTMLElementCollectionProxy<ServiceOfBookingFlowViewState, HTMLButtonElement>
74
- },
75
- slots: {
76
- slotButtons: HTMLElementCollectionProxy<SlotOfBookingFlowViewState, HTMLButtonElement>
77
- },
78
- formFields: {
79
- formInputs: HTMLElementCollectionProxy<FormFieldOfBookingFlowViewState, HTMLInputElement>
80
- }
81
- }
82
-
83
- type BookingServiceType = 'APPOINTMENT' | 'CLASS';
84
- interface BookingServiceView {
85
- id: string;
86
- name: string;
87
- type: BookingServiceType;
88
- description: string;
89
- priceLabel: string;
90
- durationLabel: string;
91
- formId: string;
92
- }
93
- interface BookingSlotView {
94
- id: string;
95
- localStartDate: string;
96
- localEndDate: string;
97
- label: string;
98
- scheduleId?: string;
99
- eventId?: string;
100
- serviceType: BookingServiceType;
101
- }
102
- interface BookingFormFieldView {
103
- target: string;
104
- label: string;
105
- type: 'STRING' | 'EMAIL' | 'PHONE' | 'NUMBER' | 'URL';
106
- required: boolean;
107
- }
108
- type CreateBookingOutcome = {
109
- outcome: 'confirmed';
110
- } | {
111
- outcome: 'redirect';
112
- redirectUrl: string;
113
- };
114
-
115
- interface WixBookingsService {
116
- listServices(): Promise<BookingServiceView[]>;
117
- listSlots(input: {
118
- serviceId: string;
119
- serviceType: BookingServiceType;
120
- timezone?: string;
121
- windowDays?: number;
122
- }): Promise<BookingSlotView[]>;
123
- createBooking(input: {
124
- serviceId: string;
125
- serviceType: BookingServiceType;
126
- slot: {
127
- localStartDate: string;
128
- localEndDate: string;
129
- scheduleId?: string;
130
- eventId?: string;
131
- };
132
- formValues: Record<string, string>;
133
- timezone: string;
134
- siteOrigin: string;
135
- paymentPreference?: 'ONLINE' | 'OFFLINE';
136
- }): Promise<CreateBookingOutcome>;
137
- }
138
- declare const WIX_BOOKINGS_SERVICE: _jay_framework_fullstack_component.ServiceMarker<WixBookingsService>;
139
-
140
- interface BookingFlowCarryForward {
141
- services: BookingServiceView[];
142
- servicesError?: string;
143
- }
144
- declare const bookingFlow: _jay_framework_fullstack_component.JayStackComponentDefinition<BookingFlowRefs, BookingFlowSlowViewState, BookingFlowFastViewState, BookingFlowInteractiveViewState, [BookingFlowCarryForward, WixBookingsService], [Signals<BookingFlowFastViewState>, BookingFlowCarryForward], object, {}, _jay_framework_component.JayComponentCore<object, BookingFlowInteractiveViewState>>;
145
-
146
- declare const listServices: _jay_framework_fullstack_component.JayAction<Record<string, never>, {
147
- services: BookingServiceView[];
148
- }> & _jay_framework_fullstack_component.JayActionDefinition<Record<string, never>, {
149
- services: BookingServiceView[];
150
- }, [WixBookingsService]>;
151
- declare const listSlots: _jay_framework_fullstack_component.JayAction<{
152
- serviceId: string;
153
- serviceType: "APPOINTMENT" | "CLASS";
154
- timezone?: string;
155
- windowDays?: number;
156
- }, {
157
- slots: BookingSlotView[];
158
- }> & _jay_framework_fullstack_component.JayActionDefinition<{
159
- serviceId: string;
160
- serviceType: "APPOINTMENT" | "CLASS";
161
- timezone?: string;
162
- windowDays?: number;
163
- }, {
164
- slots: BookingSlotView[];
165
- }, [WixBookingsService]>;
166
- declare const createBooking: _jay_framework_fullstack_component.JayAction<{
167
- serviceId: string;
168
- serviceType: "APPOINTMENT" | "CLASS";
169
- slot: {
170
- localStartDate: string;
171
- localEndDate: string;
172
- scheduleId?: string;
173
- eventId?: string;
174
- };
175
- formValues: Record<string, string>;
176
- timezone: string;
177
- siteOrigin: string;
178
- paymentPreference?: "ONLINE" | "OFFLINE";
179
- }, CreateBookingOutcome> & _jay_framework_fullstack_component.JayActionDefinition<{
180
- serviceId: string;
181
- serviceType: "APPOINTMENT" | "CLASS";
182
- slot: {
183
- localStartDate: string;
184
- localEndDate: string;
185
- scheduleId?: string;
186
- eventId?: string;
187
- };
188
- formValues: Record<string, string>;
189
- timezone: string;
190
- siteOrigin: string;
191
- paymentPreference?: "ONLINE" | "OFFLINE";
192
- }, CreateBookingOutcome, [WixBookingsService]>;
193
-
194
- export { type BookingServiceView as B, type CreateBookingOutcome as C, type WixBookingsService as W, listSlots as a, bookingFlow as b, createBooking as c, WIX_BOOKINGS_SERVICE as d, type BookingSlotView as e, type BookingFormFieldView as f, init as i, listServices as l };