@jay-framework/wix-bookings 0.24.1 → 0.24.2

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.
Files changed (2) hide show
  1. package/dist/index.js +123 -134
  2. package/package.json +14 -14
package/dist/index.js CHANGED
@@ -1,21 +1,10 @@
1
- import { makeJayInit, createJayService, makeJayStackComponent, phaseOutput, RenderPipeline, makeJayQuery, makeJayAction } from "@jay-framework/fullstack-component";
2
- import { getService, hasService, registerService } from "@jay-framework/stack-server-runtime";
3
- import { WIX_CLIENT_SERVICE, wixFetch, WixApiError } from "@jay-framework/wix-server-client";
1
+ import { createJayService, makeJayInit, makeJayStackComponent, phaseOutput, RenderPipeline, makeJayQuery, makeJayAction } from "@jay-framework/fullstack-component";
2
+ import { registerService, getService, hasService } from "@jay-framework/stack-server-runtime";
3
+ import { wixFetch, WixApiError, WIX_CLIENT_SERVICE } from "@jay-framework/wix-server-client";
4
4
  import fs from "node:fs";
5
5
  import path from "node:path";
6
- import { WIX_FORMS_SERVICE } from "@jay-framework/wix-forms";
7
6
  import yaml from "js-yaml";
8
- const init = makeJayInit().withServer(async () => {
9
- console.log("[wix-bookings] Initializing server-side bookings service...");
10
- const { loadWixBookingsConfig: loadWixBookingsConfig2 } = await Promise.resolve().then(() => configLoader);
11
- const { provideWixBookingsService: provideWixBookingsService2 } = await Promise.resolve().then(() => wixBookingsService);
12
- const wixClient = getService(WIX_CLIENT_SERVICE);
13
- const config = loadWixBookingsConfig2(process.cwd());
14
- provideWixBookingsService2(wixClient, config);
15
- console.log(`[wix-bookings] Booking app ID: ${config.bookingAppId}`);
16
- console.log("[wix-bookings] Server initialization complete");
17
- return {};
18
- });
7
+ import { WIX_FORMS_SERVICE } from "@jay-framework/wix-forms";
19
8
  const CONFIG_FILE$1 = ".wix-bookings.yaml";
20
9
  const DEFAULTS = {
21
10
  bookingAppId: "",
@@ -36,122 +25,9 @@ function loadWixBookingsConfig(projectRoot) {
36
25
  postCheckoutUrl: raw.postCheckoutUrl ?? DEFAULTS.postCheckoutUrl
37
26
  };
38
27
  }
39
- const configLoader = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
40
- __proto__: null,
41
- loadWixBookingsConfig
42
- }, Symbol.toStringTag, { value: "Module" }));
43
- const CONFIG_FILE = ".wix-bookings.yaml";
44
- const CONFIG_TEMPLATE = `# Wix Bookings Configuration
45
- #
46
- # bookingAppId — Wix Bookings app ID on your site
47
- bookingAppId: ""
48
-
49
- # staffResourceTypeId — resource type for staff selection (site-specific)
50
- staffResourceTypeId: ""
51
-
52
- slotWindowDays: 14
53
- postCheckoutUrl: "/book"
54
- `;
55
- async function setupWixBookings(ctx) {
56
- if (ctx.initError) {
57
- return {
58
- status: "error",
59
- message: `Service init failed (is wix-server-client configured?). ${ctx.initError.message}`
60
- };
61
- }
62
- if (!hasService(WIX_FORMS_SERVICE)) {
63
- return {
64
- status: "error",
65
- message: "wix-bookings requires the wix-forms plugin. Add wix-forms to your project plugins and run setup before wix-bookings."
66
- };
67
- }
68
- const configCreated = [];
69
- const configPath = path.join(ctx.configDir, CONFIG_FILE);
70
- if (!fs.existsSync(configPath)) {
71
- if (!fs.existsSync(ctx.configDir)) {
72
- fs.mkdirSync(ctx.configDir, { recursive: true });
73
- }
74
- fs.writeFileSync(configPath, CONFIG_TEMPLATE, "utf-8");
75
- configCreated.push(`config/${CONFIG_FILE}`);
76
- }
77
- const config = loadWixBookingsConfig(ctx.projectRoot);
78
- const missing = [];
79
- if (!config.bookingAppId) {
80
- missing.push("bookingAppId");
81
- }
82
- if (!config.staffResourceTypeId) {
83
- missing.push("staffResourceTypeId");
84
- }
85
- if (missing.length) {
86
- return {
87
- status: "needs-config",
88
- configCreated,
89
- message: `Set ${missing.join(", ")} in config/${CONFIG_FILE}`
90
- };
91
- }
92
- return {
93
- status: "configured",
94
- configCreated,
95
- message: `Wix Bookings configured (app: ${config.bookingAppId})`
96
- };
97
- }
98
- const setup = setupWixBookings;
99
- const WIX_BOOKINGS_SERVICE = createJayService("WixBookingsService");
100
- async function renderSlowlyChanging(_props, bookings) {
101
- try {
102
- const services = await bookings.listServices();
103
- return phaseOutput({ services }, { services });
104
- } catch (error) {
105
- const rawMessage = error instanceof Error ? error.message : "Could not load booking services.";
106
- const message = rawMessage.includes("403") ? "Bookings API access denied. Add Wix Bookings permission to your API key in the Wix dashboard." : rawMessage || "Could not load booking services.";
107
- console.error("[booking-flow] listServices failed:", error);
108
- return phaseOutput({ services: [] }, { services: [], servicesError: message });
109
- }
110
- }
111
- async function renderFastChanging(_props, carryForward) {
112
- const Pipeline = RenderPipeline.for();
113
- return Pipeline.ok(null).toPhaseOutput(() => ({
114
- viewState: {
115
- services: carryForward.services,
116
- servicesLoading: false,
117
- servicesError: carryForward.servicesError ?? "",
118
- showNoServices: carryForward.services.length === 0 && !carryForward.servicesError,
119
- hasSlots: false,
120
- showServices: true,
121
- showSlots: false,
122
- showForm: false,
123
- selectedServiceName: "",
124
- slots: [],
125
- slotsLoading: false,
126
- slotsMessage: "",
127
- formFields: [],
128
- formLoading: false,
129
- isBooking: false,
130
- bookingStatus: "",
131
- bookingError: ""
132
- },
133
- carryForward: {
134
- services: carryForward.services,
135
- servicesError: carryForward.servicesError
136
- }
137
- }));
138
- }
139
- const bookingFlow = makeJayStackComponent().withProps().withServices(WIX_BOOKINGS_SERVICE).withSlowlyRender(renderSlowlyChanging).withFastRender(renderFastChanging).withInteractiveMark();
140
- const listServices = makeJayQuery("wixBookings.listServices").withServices(WIX_BOOKINGS_SERVICE).withCaching({ maxAge: 300 }).withHandler(async (_input, bookings) => {
141
- const services = await bookings.listServices();
142
- return { services };
143
- });
144
- const listSlots = makeJayQuery("wixBookings.listSlots").withServices(WIX_BOOKINGS_SERVICE).withHandler(
145
- async (input, bookings) => {
146
- const slots = await bookings.listSlots(input);
147
- return { slots };
148
- }
149
- );
150
- const createBooking = makeJayAction("wixBookings.createBooking").withServices(WIX_BOOKINGS_SERVICE).withHandler(
151
- async (input, bookings) => bookings.createBooking(input)
152
- );
153
28
  const MAX_SLOTS_PER_QUERY = 200;
154
29
  const SERVICES_PAGE_SIZE = 100;
30
+ const WIX_BOOKINGS_SERVICE = createJayService("WixBookingsService");
155
31
  function formatPrice(service) {
156
32
  const price = service.payment?.fixed?.price;
157
33
  if (!price?.value) {
@@ -496,11 +372,124 @@ function provideWixBookingsService(wixClient, config) {
496
372
  registerService(WIX_BOOKINGS_SERVICE, service);
497
373
  return service;
498
374
  }
499
- const wixBookingsService = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
500
- __proto__: null,
501
- WIX_BOOKINGS_SERVICE,
502
- provideWixBookingsService
503
- }, Symbol.toStringTag, { value: "Module" }));
375
+ const init = makeJayInit().withServer(async () => {
376
+ console.log("[wix-bookings] Initializing server-side bookings service...");
377
+ const wixClient = getService(WIX_CLIENT_SERVICE);
378
+ const config = loadWixBookingsConfig(process.cwd());
379
+ provideWixBookingsService(wixClient, config);
380
+ console.log(`[wix-bookings] Booking app ID: ${config.bookingAppId}`);
381
+ console.log("[wix-bookings] Server initialization complete");
382
+ return {};
383
+ });
384
+ const CONFIG_FILE = ".wix-bookings.yaml";
385
+ const CONFIG_TEMPLATE = `# Wix Bookings Configuration
386
+ #
387
+ # bookingAppId — Wix Bookings app ID on your site
388
+ bookingAppId: ""
389
+
390
+ # staffResourceTypeId — resource type for staff selection (site-specific)
391
+ staffResourceTypeId: ""
392
+
393
+ slotWindowDays: 14
394
+ postCheckoutUrl: "/book"
395
+ `;
396
+ async function setupWixBookings(ctx) {
397
+ if (ctx.initError) {
398
+ return {
399
+ status: "error",
400
+ message: `Service init failed (is wix-server-client configured?). ${ctx.initError.message}`
401
+ };
402
+ }
403
+ if (!hasService(WIX_FORMS_SERVICE)) {
404
+ return {
405
+ status: "error",
406
+ message: "wix-bookings requires the wix-forms plugin. Add wix-forms to your project plugins and run setup before wix-bookings."
407
+ };
408
+ }
409
+ const configCreated = [];
410
+ const configPath = path.join(ctx.configDir, CONFIG_FILE);
411
+ if (!fs.existsSync(configPath)) {
412
+ if (!fs.existsSync(ctx.configDir)) {
413
+ fs.mkdirSync(ctx.configDir, { recursive: true });
414
+ }
415
+ fs.writeFileSync(configPath, CONFIG_TEMPLATE, "utf-8");
416
+ configCreated.push(`config/${CONFIG_FILE}`);
417
+ }
418
+ const config = loadWixBookingsConfig(ctx.projectRoot);
419
+ const missing = [];
420
+ if (!config.bookingAppId) {
421
+ missing.push("bookingAppId");
422
+ }
423
+ if (!config.staffResourceTypeId) {
424
+ missing.push("staffResourceTypeId");
425
+ }
426
+ if (missing.length) {
427
+ return {
428
+ status: "needs-config",
429
+ configCreated,
430
+ message: `Set ${missing.join(", ")} in config/${CONFIG_FILE}`
431
+ };
432
+ }
433
+ return {
434
+ status: "configured",
435
+ configCreated,
436
+ message: `Wix Bookings configured (app: ${config.bookingAppId})`
437
+ };
438
+ }
439
+ const setup = setupWixBookings;
440
+ async function renderSlowlyChanging(_props, bookings) {
441
+ try {
442
+ const services = await bookings.listServices();
443
+ return phaseOutput({ services }, { services });
444
+ } catch (error) {
445
+ const rawMessage = error instanceof Error ? error.message : "Could not load booking services.";
446
+ const message = rawMessage.includes("403") ? "Bookings API access denied. Add Wix Bookings permission to your API key in the Wix dashboard." : rawMessage || "Could not load booking services.";
447
+ console.error("[booking-flow] listServices failed:", error);
448
+ return phaseOutput({ services: [] }, { services: [], servicesError: message });
449
+ }
450
+ }
451
+ async function renderFastChanging(_props, carryForward) {
452
+ const Pipeline = RenderPipeline.for();
453
+ return Pipeline.ok(null).toPhaseOutput(() => ({
454
+ viewState: {
455
+ services: carryForward.services,
456
+ servicesLoading: false,
457
+ servicesError: carryForward.servicesError ?? "",
458
+ showNoServices: carryForward.services.length === 0 && !carryForward.servicesError,
459
+ hasSlots: false,
460
+ showServices: true,
461
+ showSlots: false,
462
+ showForm: false,
463
+ selectedServiceName: "",
464
+ slots: [],
465
+ slotsLoading: false,
466
+ slotsMessage: "",
467
+ formFields: [],
468
+ formLoading: false,
469
+ isBooking: false,
470
+ bookingStatus: "",
471
+ bookingError: ""
472
+ },
473
+ carryForward: {
474
+ services: carryForward.services,
475
+ servicesError: carryForward.servicesError
476
+ }
477
+ }));
478
+ }
479
+ const bookingFlow = makeJayStackComponent().withProps().withServices(WIX_BOOKINGS_SERVICE).withSlowlyRender(renderSlowlyChanging).withFastRender(renderFastChanging).withInteractiveMark();
480
+ const listServices = makeJayQuery("wixBookings.listServices").withServices(WIX_BOOKINGS_SERVICE).withCaching({ maxAge: 300 }).withHandler(async (_input, bookings) => {
481
+ const services = await bookings.listServices();
482
+ return { services };
483
+ });
484
+ const listSlots = makeJayQuery("wixBookings.listSlots").withServices(WIX_BOOKINGS_SERVICE).withHandler(
485
+ async (input, bookings) => {
486
+ const slots = await bookings.listSlots(input);
487
+ return { slots };
488
+ }
489
+ );
490
+ const createBooking = makeJayAction("wixBookings.createBooking").withServices(WIX_BOOKINGS_SERVICE).withHandler(
491
+ async (input, bookings) => bookings.createBooking(input)
492
+ );
504
493
  export {
505
494
  WIX_BOOKINGS_SERVICE,
506
495
  bookingFlow,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/wix-bookings",
3
- "version": "0.24.1",
3
+ "version": "0.24.2",
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",
@@ -39,15 +39,15 @@
39
39
  "test": "vitest run"
40
40
  },
41
41
  "dependencies": {
42
- "@jay-framework/component": "^0.24.1",
43
- "@jay-framework/fullstack-component": "^0.24.1",
44
- "@jay-framework/reactive": "^0.24.1",
45
- "@jay-framework/runtime": "^0.24.1",
46
- "@jay-framework/secure": "^0.24.1",
47
- "@jay-framework/stack-client-runtime": "^0.24.1",
48
- "@jay-framework/stack-server-runtime": "^0.24.1",
49
- "@jay-framework/wix-forms": "^0.24.1",
50
- "@jay-framework/wix-server-client": "^0.24.1",
42
+ "@jay-framework/component": "^0.24.2",
43
+ "@jay-framework/fullstack-component": "^0.24.2",
44
+ "@jay-framework/reactive": "^0.24.2",
45
+ "@jay-framework/runtime": "^0.24.2",
46
+ "@jay-framework/secure": "^0.24.2",
47
+ "@jay-framework/stack-client-runtime": "^0.24.2",
48
+ "@jay-framework/stack-server-runtime": "^0.24.2",
49
+ "@jay-framework/wix-forms": "^0.24.2",
50
+ "@jay-framework/wix-server-client": "^0.24.2",
51
51
  "@wix/sdk": "^1.21.5",
52
52
  "js-yaml": "^4.1.0"
53
53
  },
@@ -55,10 +55,10 @@
55
55
  "@babel/core": "^7.23.7",
56
56
  "@babel/preset-env": "^7.23.8",
57
57
  "@babel/preset-typescript": "^7.23.3",
58
- "@jay-framework/compiler-jay-stack": "^0.24.1",
59
- "@jay-framework/jay-cli": "^0.24.1",
60
- "@jay-framework/jay-stack-cli": "^0.24.1",
61
- "@jay-framework/vite-plugin": "^0.24.1",
58
+ "@jay-framework/compiler-jay-stack": "^0.24.2",
59
+ "@jay-framework/jay-cli": "^0.24.2",
60
+ "@jay-framework/jay-stack-cli": "^0.24.2",
61
+ "@jay-framework/vite-plugin": "^0.24.2",
62
62
  "@jay-framework/wix-dev-environment": "^0.6.12",
63
63
  "nodemon": "^3.0.3",
64
64
  "rimraf": "^5.0.5",