@jay-framework/wix-bookings 0.24.1 → 0.24.3

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.
@@ -0,0 +1,26 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import yaml from "js-yaml";
4
+ const CONFIG_FILE = ".wix-bookings.yaml";
5
+ const DEFAULTS = {
6
+ bookingAppId: "",
7
+ staffResourceTypeId: "",
8
+ slotWindowDays: 14,
9
+ postCheckoutUrl: "/"
10
+ };
11
+ function loadWixBookingsConfig(projectRoot) {
12
+ const configPath = path.join(projectRoot, "config", CONFIG_FILE);
13
+ if (!fs.existsSync(configPath)) {
14
+ return { ...DEFAULTS };
15
+ }
16
+ const raw = yaml.load(fs.readFileSync(configPath, "utf-8"));
17
+ return {
18
+ bookingAppId: raw.bookingAppId ?? DEFAULTS.bookingAppId,
19
+ staffResourceTypeId: raw.staffResourceTypeId ?? DEFAULTS.staffResourceTypeId,
20
+ slotWindowDays: raw.slotWindowDays ?? DEFAULTS.slotWindowDays,
21
+ postCheckoutUrl: raw.postCheckoutUrl ?? DEFAULTS.postCheckoutUrl
22
+ };
23
+ }
24
+ export {
25
+ loadWixBookingsConfig as l
26
+ };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,10 @@
1
1
  import { W as WixBookingsService } from './index.client-CBlxQDjy.js';
2
2
  export { f as BookingFormFieldView, B as BookingServiceView, e as BookingSlotView, C as CreateBookingOutcome, d as WIX_BOOKINGS_SERVICE, b as bookingFlow, c as createBooking, i as init, l as listServices, a as listSlots } from './index.client-CBlxQDjy.js';
3
- import { PluginSetupContext, PluginSetupResult } from '@jay-framework/stack-server-runtime';
4
3
  import { WixClient } from '@wix/sdk';
5
4
  import '@jay-framework/fullstack-component';
6
5
  import '@jay-framework/component';
7
6
  import '@jay-framework/runtime';
8
7
 
9
- declare function setupWixBookings(ctx: PluginSetupContext): Promise<PluginSetupResult>;
10
- declare const setup: typeof setupWixBookings;
11
-
12
8
  interface WixBookingsConfig {
13
9
  bookingAppId: string;
14
10
  staffResourceTypeId: string;
@@ -18,4 +14,4 @@ interface WixBookingsConfig {
18
14
 
19
15
  declare function provideWixBookingsService(wixClient: WixClient, config: WixBookingsConfig): WixBookingsService;
20
16
 
21
- export { WixBookingsService, provideWixBookingsService, setup, setupWixBookings };
17
+ export { WixBookingsService, provideWixBookingsService };
package/dist/index.js CHANGED
@@ -1,157 +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";
4
- import fs from "node:fs";
5
- import path from "node:path";
6
- import { WIX_FORMS_SERVICE } from "@jay-framework/wix-forms";
7
- 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
- });
19
- const CONFIG_FILE$1 = ".wix-bookings.yaml";
20
- const DEFAULTS = {
21
- bookingAppId: "",
22
- staffResourceTypeId: "",
23
- slotWindowDays: 14,
24
- postCheckoutUrl: "/"
25
- };
26
- function loadWixBookingsConfig(projectRoot) {
27
- const configPath = path.join(projectRoot, "config", CONFIG_FILE$1);
28
- if (!fs.existsSync(configPath)) {
29
- return { ...DEFAULTS };
30
- }
31
- const raw = yaml.load(fs.readFileSync(configPath, "utf-8"));
32
- return {
33
- bookingAppId: raw.bookingAppId ?? DEFAULTS.bookingAppId,
34
- staffResourceTypeId: raw.staffResourceTypeId ?? DEFAULTS.staffResourceTypeId,
35
- slotWindowDays: raw.slotWindowDays ?? DEFAULTS.slotWindowDays,
36
- postCheckoutUrl: raw.postCheckoutUrl ?? DEFAULTS.postCheckoutUrl
37
- };
38
- }
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
- );
1
+ import { createJayService, makeJayInit, makeJayStackComponent, phaseOutput, RenderPipeline, makeJayQuery, makeJayAction } from "@jay-framework/fullstack-component";
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";
153
5
  const MAX_SLOTS_PER_QUERY = 200;
154
6
  const SERVICES_PAGE_SIZE = 100;
7
+ const WIX_BOOKINGS_SERVICE = createJayService("WixBookingsService");
155
8
  function formatPrice(service) {
156
9
  const price = service.payment?.fixed?.price;
157
10
  if (!price?.value) {
@@ -496,11 +349,68 @@ function provideWixBookingsService(wixClient, config) {
496
349
  registerService(WIX_BOOKINGS_SERVICE, service);
497
350
  return service;
498
351
  }
499
- const wixBookingsService = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
500
- __proto__: null,
501
- WIX_BOOKINGS_SERVICE,
502
- provideWixBookingsService
503
- }, Symbol.toStringTag, { value: "Module" }));
352
+ const init = makeJayInit().withServer(async () => {
353
+ console.log("[wix-bookings] Initializing server-side bookings service...");
354
+ const wixClient = getService(WIX_CLIENT_SERVICE);
355
+ const config = loadWixBookingsConfig(process.cwd());
356
+ provideWixBookingsService(wixClient, config);
357
+ console.log(`[wix-bookings] Booking app ID: ${config.bookingAppId}`);
358
+ console.log("[wix-bookings] Server initialization complete");
359
+ return {};
360
+ });
361
+ async function renderSlowlyChanging(_props, bookings) {
362
+ try {
363
+ const services = await bookings.listServices();
364
+ return phaseOutput({ services }, { services });
365
+ } catch (error) {
366
+ const rawMessage = error instanceof Error ? error.message : "Could not load booking services.";
367
+ 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.";
368
+ console.error("[booking-flow] listServices failed:", error);
369
+ return phaseOutput({ services: [] }, { services: [], servicesError: message });
370
+ }
371
+ }
372
+ async function renderFastChanging(_props, carryForward) {
373
+ const Pipeline = RenderPipeline.for();
374
+ return Pipeline.ok(null).toPhaseOutput(() => ({
375
+ viewState: {
376
+ services: carryForward.services,
377
+ servicesLoading: false,
378
+ servicesError: carryForward.servicesError ?? "",
379
+ showNoServices: carryForward.services.length === 0 && !carryForward.servicesError,
380
+ hasSlots: false,
381
+ showServices: true,
382
+ showSlots: false,
383
+ showForm: false,
384
+ selectedServiceName: "",
385
+ slots: [],
386
+ slotsLoading: false,
387
+ slotsMessage: "",
388
+ formFields: [],
389
+ formLoading: false,
390
+ isBooking: false,
391
+ bookingStatus: "",
392
+ bookingError: ""
393
+ },
394
+ carryForward: {
395
+ services: carryForward.services,
396
+ servicesError: carryForward.servicesError
397
+ }
398
+ }));
399
+ }
400
+ const bookingFlow = makeJayStackComponent().withProps().withServices(WIX_BOOKINGS_SERVICE).withSlowlyRender(renderSlowlyChanging).withFastRender(renderFastChanging).withInteractiveMark();
401
+ const listServices = makeJayQuery("wixBookings.listServices").withServices(WIX_BOOKINGS_SERVICE).withCaching({ maxAge: 300 }).withHandler(async (_input, bookings) => {
402
+ const services = await bookings.listServices();
403
+ return { services };
404
+ });
405
+ const listSlots = makeJayQuery("wixBookings.listSlots").withServices(WIX_BOOKINGS_SERVICE).withHandler(
406
+ async (input, bookings) => {
407
+ const slots = await bookings.listSlots(input);
408
+ return { slots };
409
+ }
410
+ );
411
+ const createBooking = makeJayAction("wixBookings.createBooking").withServices(WIX_BOOKINGS_SERVICE).withHandler(
412
+ async (input, bookings) => bookings.createBooking(input)
413
+ );
504
414
  export {
505
415
  WIX_BOOKINGS_SERVICE,
506
416
  bookingFlow,
@@ -508,7 +418,5 @@ export {
508
418
  init,
509
419
  listServices,
510
420
  listSlots,
511
- provideWixBookingsService,
512
- setup,
513
- setupWixBookings
421
+ provideWixBookingsService
514
422
  };
@@ -0,0 +1,6 @@
1
+ import { PluginSetupContext, PluginSetupResult } from '@jay-framework/stack-server-runtime';
2
+
3
+ declare function setupWixBookings(ctx: PluginSetupContext): Promise<PluginSetupResult>;
4
+ declare const setup: typeof setupWixBookings;
5
+
6
+ export { setup, setupWixBookings };
package/dist/tools.js ADDED
@@ -0,0 +1,65 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { hasService } from "@jay-framework/stack-server-runtime";
4
+ import { WIX_FORMS_SERVICE } from "@jay-framework/wix-forms";
5
+ import { l as loadWixBookingsConfig } from "./config-loader-C7I2yXpp.js";
6
+ const CONFIG_FILE = ".wix-bookings.yaml";
7
+ const CONFIG_TEMPLATE = `# Wix Bookings Configuration
8
+ #
9
+ # bookingAppId — Wix Bookings app ID on your site
10
+ bookingAppId: ""
11
+
12
+ # staffResourceTypeId — resource type for staff selection (site-specific)
13
+ staffResourceTypeId: ""
14
+
15
+ slotWindowDays: 14
16
+ postCheckoutUrl: "/book"
17
+ `;
18
+ async function setupWixBookings(ctx) {
19
+ if (ctx.initError) {
20
+ return {
21
+ status: "error",
22
+ message: `Service init failed (is wix-server-client configured?). ${ctx.initError.message}`
23
+ };
24
+ }
25
+ if (!hasService(WIX_FORMS_SERVICE)) {
26
+ return {
27
+ status: "error",
28
+ message: "wix-bookings requires the wix-forms plugin. Add wix-forms to your project plugins and run setup before wix-bookings."
29
+ };
30
+ }
31
+ const configCreated = [];
32
+ const configPath = path.join(ctx.configDir, CONFIG_FILE);
33
+ if (!fs.existsSync(configPath)) {
34
+ if (!fs.existsSync(ctx.configDir)) {
35
+ fs.mkdirSync(ctx.configDir, { recursive: true });
36
+ }
37
+ fs.writeFileSync(configPath, CONFIG_TEMPLATE, "utf-8");
38
+ configCreated.push(`config/${CONFIG_FILE}`);
39
+ }
40
+ const config = loadWixBookingsConfig(ctx.projectRoot);
41
+ const missing = [];
42
+ if (!config.bookingAppId) {
43
+ missing.push("bookingAppId");
44
+ }
45
+ if (!config.staffResourceTypeId) {
46
+ missing.push("staffResourceTypeId");
47
+ }
48
+ if (missing.length) {
49
+ return {
50
+ status: "needs-config",
51
+ configCreated,
52
+ message: `Set ${missing.join(", ")} in config/${CONFIG_FILE}`
53
+ };
54
+ }
55
+ return {
56
+ status: "configured",
57
+ configCreated,
58
+ message: `Wix Bookings configured (app: ${config.bookingAppId})`
59
+ };
60
+ }
61
+ const setup = setupWixBookings;
62
+ export {
63
+ setup,
64
+ setupWixBookings
65
+ };
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.3",
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,6 +19,7 @@
19
19
  "types": "./dist/index.client.d.ts",
20
20
  "default": "./dist/index.client.js"
21
21
  },
22
+ "./tools": "./dist/tools.js",
22
23
  "./plugin.yaml": "./plugin.yaml",
23
24
  "./booking-flow.jay-contract": "./dist/contracts/booking-flow.jay-contract",
24
25
  "./list-services.jay-action": "./dist/actions/list-services.jay-action",
@@ -32,22 +33,22 @@
32
33
  "build:client": "vite build",
33
34
  "build:server": "vite build --ssr",
34
35
  "build:copy-contract": "mkdir -p dist/contracts && cp lib/contracts/*.jay-contract* dist/contracts/ && mkdir -p dist/actions && cp lib/actions/*.jay-action dist/actions/",
35
- "build:types": "tsup lib/index.ts lib/index.client.ts --dts-only --format esm",
36
+ "build:types": "tsup lib/index.ts lib/index.client.ts lib/tools.ts --dts-only --format esm",
36
37
  "build:check-types": "tsc",
37
38
  "clean": "rimraf dist",
38
39
  "confirm": "npm run clean && npm run build && npm run test",
39
40
  "test": "vitest run"
40
41
  },
41
42
  "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",
43
+ "@jay-framework/component": "^0.24.3",
44
+ "@jay-framework/fullstack-component": "^0.24.3",
45
+ "@jay-framework/reactive": "^0.24.3",
46
+ "@jay-framework/runtime": "^0.24.3",
47
+ "@jay-framework/secure": "^0.24.3",
48
+ "@jay-framework/stack-client-runtime": "^0.24.3",
49
+ "@jay-framework/stack-server-runtime": "^0.24.3",
50
+ "@jay-framework/wix-forms": "^0.24.3",
51
+ "@jay-framework/wix-server-client": "^0.24.3",
51
52
  "@wix/sdk": "^1.21.5",
52
53
  "js-yaml": "^4.1.0"
53
54
  },
@@ -55,10 +56,10 @@
55
56
  "@babel/core": "^7.23.7",
56
57
  "@babel/preset-env": "^7.23.8",
57
58
  "@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",
59
+ "@jay-framework/compiler-jay-stack": "^0.24.3",
60
+ "@jay-framework/jay-cli": "^0.24.3",
61
+ "@jay-framework/jay-stack-cli": "^0.24.3",
62
+ "@jay-framework/vite-plugin": "^0.24.3",
62
63
  "@jay-framework/wix-dev-environment": "^0.6.12",
63
64
  "nodemon": "^3.0.3",
64
65
  "rimraf": "^5.0.5",