@jay-framework/wix-bookings 0.24.0

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,119 @@
1
+ Wix Bookings plugin setup — service list, slot picker, participant form, and checkout.
2
+
3
+ ## What wix-bookings provides
4
+
5
+ One headless contract and three server actions:
6
+
7
+ - **booking-flow** — full booking UI (services → slots → form → checkout)
8
+ - **listServices** — query available booking services
9
+ - **listSlots** — query availability for a selected service
10
+ - **createBooking** — create booking, handle paid (redirect) or free (place-order) checkout
11
+
12
+ ## Prerequisites
13
+
14
+ 1. `@jay-framework/wix-server-client` configured (`config/.wix.yaml`)
15
+ 2. `@jay-framework/wix-forms` for participant field schema (`getFormSummary`)
16
+ 3. Wix site with Bookings app enabled and published
17
+
18
+ ## Setup steps
19
+
20
+ ### 1. Config file
21
+
22
+ Running `jay-stack setup wix-bookings` creates `config/.wix-bookings.yaml`:
23
+
24
+ ```yaml
25
+ bookingAppId: ""
26
+ staffResourceTypeId: ""
27
+ slotWindowDays: 14
28
+ postCheckoutUrl: "/book"
29
+ ```
30
+
31
+ | Field | Purpose |
32
+ |-------|---------|
33
+ | `bookingAppId` | Wix Bookings app ID on the site |
34
+ | `staffResourceTypeId` | Resource type for `ANY_RESOURCE` staff selection |
35
+ | `slotWindowDays` | How far ahead to query slots (default 14) |
36
+ | `postCheckoutUrl` | Relative path after paid checkout (e.g. `/book`) |
37
+
38
+ ### 2. API key permissions
39
+
40
+ Configure in [Wix API Keys Manager](https://manage.wix.com/account/api-keys). Each step needs its own permission; Wix returns **403** until the right scope is granted.
41
+
42
+ | Permission | Needed for | Symptom if missing |
43
+ |------------|------------|-------------------|
44
+ | **Wix Bookings** | List services, slots, create booking | 403 on `/bookings/v2/services/query` — page shows no services |
45
+ | **Wix eCommerce** (Write Carts v2) | Create cart, calculate, place-order | 403 on `/ecom/v2/carts` after Confirm Booking |
46
+ | **Headless** (redirect sessions) | Paid checkout redirect | 403 on `/headless/v1/redirect-session` |
47
+
48
+ Also enable **Wix Forms** on the API key (via `wix-forms` plugin) for participant field schema.
49
+
50
+ ### 3. Headless settings (not API key)
51
+
52
+ Under **Dashboard → Settings → Development & integrations → Headless Settings → your client** (same `clientId` as `config/.wix.yaml`):
53
+
54
+ | Setting | Purpose | Symptom if missing |
55
+ |---------|---------|-------------------|
56
+ | **Allowed redirect domains** | `postFlowUrl` after hosted checkout | 400 on `POST /headless/v1/redirect-session` |
57
+ | **Allowed authorization redirect URIs** | Member login (unrelated to bookings) | OAuth login errors |
58
+
59
+ For local dev, add **`localhost:3000`** under **Allowed redirect domains** (domain only — no `http://`).
60
+
61
+ The Wix site must be **published** — hosted checkout uses the published site.
62
+
63
+ ### 4. Booking page
64
+
65
+ ```html
66
+ <script type="application/jay-headless"
67
+ plugin="@jay-framework/wix-bookings"
68
+ contract="booking-flow"
69
+ key="booking">
70
+ </script>
71
+
72
+ <jay:booking-flow>
73
+ <!-- service list, slot picker, form, checkout UI -->
74
+ </jay:booking-flow>
75
+ ```
76
+
77
+ ## Server flow
78
+
79
+ ```
80
+ listServices → listSlots → getFormSummary (wix-forms) → createBooking
81
+ → POST /bookings/v2/bookings
82
+ → POST /ecom/v2/carts
83
+ → POST /ecom/v2/carts/{id}/calculate
84
+ → if total > 0: redirect to Wix hosted checkout
85
+ → else: POST /ecom/v2/carts/{id}/place-order
86
+ ```
87
+
88
+ Paid checkout uses **ecom Cart v2** + **Headless redirect session** — not `@jay-framework/wix-cart` (which uses ecom v1).
89
+
90
+ ## Redirect session endpoint
91
+
92
+ | Endpoint | Used by | Bookings? |
93
+ |----------|---------|-----------|
94
+ | `POST /headless/v1/redirect-session` | Bookings plugin | Correct |
95
+ | `POST /redirects-api/v1/redirect-session` | `@jay-framework/wix-cart` | Wrong — 404 for bookings flow |
96
+
97
+ Request body (paid booking):
98
+
99
+ ```json
100
+ {
101
+ "ecomCheckout": { "checkoutId": "<cartId>" },
102
+ "callbacks": { "postFlowUrl": "https://your-app.example/book" }
103
+ }
104
+ ```
105
+
106
+ In ecom Cart v2, **cart ID is the checkout ID**.
107
+
108
+ ## Verification checklist
109
+
110
+ - [ ] Services list on booking page
111
+ - [ ] Slot selection and form submit
112
+ - [ ] Paid service redirects to Wix hosted checkout
113
+ - [ ] Complete payment on hosted checkout and confirm order in Wix dashboard
114
+ - [ ] Free or pay-in-person service — confirm place-order path shows confirmation without redirect
115
+ - [ ] Return URL — after checkout, Wix redirects to `postCheckoutUrl`
116
+
117
+ Do not show "Booking confirmed!" solely because the user returned to the page — `postFlowUrl` fires when the user finishes or abandons checkout.
118
+
119
+ See `wix-bookings-troubleshooting.md` for progressive 403s and implementation pitfalls.
@@ -0,0 +1,55 @@
1
+ Wix Bookings troubleshooting — progressive 403s, redirect errors, and verification.
2
+
3
+ ## Progressive 403 errors
4
+
5
+ Wix returns **403** until each required permission is granted. Fix them in order as you test the flow:
6
+
7
+ 1. **Services list empty / 403 on `/bookings/v2/services/query`**
8
+ - Enable **Wix Bookings** on API key
9
+
10
+ 2. **403 on `/ecom/v2/carts` after Confirm Booking**
11
+ - Enable **Wix eCommerce** (Write Carts v2 / Manage eCommerce) on API key
12
+
13
+ 3. **403 on `/headless/v1/redirect-session`**
14
+ - Enable **Headless** (redirect sessions) on API key
15
+
16
+ For local smoke tests, **All site permissions** is acceptable temporarily.
17
+
18
+ ## Headless redirect errors
19
+
20
+ | Error | Cause | Fix |
21
+ |-------|-------|-----|
22
+ | 400 on redirect-session | `postFlowUrl` domain not in Headless allowlist | Add `localhost:3000` (or deployed domain) to **Allowed redirect domains** |
23
+ | 404 on redirect-session | Wrong endpoint `/redirects-api/v1/redirect-session` | Use `/headless/v1/redirect-session` only |
24
+ | 428 SITE_NOT_PUBLISHED | Site not published | Publish the Wix site |
25
+
26
+ **Fallback:** If redirect-session fails with 400/404, the service falls back to `POST /ecom/v2/carts/{cartId}/get-checkout-url`. That opens Wix checkout but may not return to your `postFlowUrl`.
27
+
28
+ ## Implementation pitfalls
29
+
30
+ | Issue | Cause | Fix |
31
+ |-------|-------|-----|
32
+ | Browser crash `createRequire is not defined` | Server bundle imported in client | Use `index.client.ts` for client; dynamic imports in `init.ts` |
33
+ | Contract validation failed | Arrays as `dataType: array` | Use `sub-contract` + `repeated: true` |
34
+ | `getService(WIX_CLIENT_SERVICE)` wrong shape | Assumed `{ wixClient }` wrapper | Service returns `WixClient` directly |
35
+ | Paid checkout 400 | `postFlowUrl` domain not in Headless allowlist | Add domain to **Allowed redirect domains** |
36
+ | Paid checkout 404 | Wrong redirect endpoint | Use `/headless/v1/redirect-session`, not redirects-api |
37
+
38
+ ## Participant form fields empty
39
+
40
+ Bookings loads participant fields via `getFormSummary` from `@jay-framework/wix-forms`:
41
+
42
+ - Ensure `wix-forms` is set up and API key has **Wix Forms** permission
43
+ - Service must have a `form._id` in the Wix Bookings schema
44
+
45
+ ## Do not assume success from redirect alone
46
+
47
+ `postFlowUrl` fires when the user **finishes or abandons** checkout. For production, look up booking/order status rather than showing confirmation solely on page return.
48
+
49
+ ## Config troubleshooting
50
+
51
+ | Symptom | Check |
52
+ |---------|-------|
53
+ | No services | `bookingAppId` in `config/.wix-bookings.yaml` |
54
+ | Slot query fails | `staffResourceTypeId` matches site resource type |
55
+ | Wrong return URL after checkout | `postCheckoutUrl` in config |
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@jay-framework/wix-bookings",
3
+ "version": "0.24.0",
4
+ "type": "module",
5
+ "description": "Wix Bookings package for Jay Framework — browse services, pick slots, submit participant details, complete checkout",
6
+ "license": "Apache-2.0",
7
+ "main": "dist/index.js",
8
+ "files": [
9
+ "dist",
10
+ "plugin.yaml",
11
+ "agent-kit"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "./client": {
19
+ "types": "./dist/index.client.d.ts",
20
+ "default": "./dist/index.client.js"
21
+ },
22
+ "./plugin.yaml": "./plugin.yaml",
23
+ "./booking-flow.jay-contract": "./dist/contracts/booking-flow.jay-contract",
24
+ "./list-services.jay-action": "./dist/actions/list-services.jay-action",
25
+ "./list-slots.jay-action": "./dist/actions/list-slots.jay-action",
26
+ "./create-booking.jay-action": "./dist/actions/create-booking.jay-action"
27
+ },
28
+ "scripts": {
29
+ "build": "npm run clean && npm run definitions && npm run build:client && npm run build:server && npm run build:copy-contract && npm run build:types && npm run validate",
30
+ "definitions": "jay-cli definitions lib",
31
+ "validate": "jay-stack-cli validate-plugin",
32
+ "build:client": "vite build",
33
+ "build:server": "vite build --ssr",
34
+ "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:check-types": "tsc",
37
+ "clean": "rimraf dist",
38
+ "confirm": "npm run clean && npm run build && npm run test",
39
+ "test": "vitest run"
40
+ },
41
+ "dependencies": {
42
+ "@jay-framework/component": "^0.24.0",
43
+ "@jay-framework/fullstack-component": "^0.24.0",
44
+ "@jay-framework/reactive": "^0.24.0",
45
+ "@jay-framework/runtime": "^0.24.0",
46
+ "@jay-framework/secure": "^0.24.0",
47
+ "@jay-framework/stack-client-runtime": "^0.24.0",
48
+ "@jay-framework/stack-server-runtime": "^0.24.0",
49
+ "@jay-framework/wix-forms": "^0.24.0",
50
+ "@jay-framework/wix-server-client": "^0.24.0",
51
+ "@wix/sdk": "^1.21.5",
52
+ "js-yaml": "^4.1.0"
53
+ },
54
+ "devDependencies": {
55
+ "@babel/core": "^7.23.7",
56
+ "@babel/preset-env": "^7.23.8",
57
+ "@babel/preset-typescript": "^7.23.3",
58
+ "@jay-framework/compiler-jay-stack": "^0.24.0",
59
+ "@jay-framework/jay-cli": "^0.24.0",
60
+ "@jay-framework/jay-stack-cli": "^0.24.0",
61
+ "@jay-framework/vite-plugin": "^0.24.0",
62
+ "@jay-framework/wix-dev-environment": "^0.6.12",
63
+ "nodemon": "^3.0.3",
64
+ "rimraf": "^5.0.5",
65
+ "tslib": "^2.6.2",
66
+ "tsup": "^8.5.1",
67
+ "typescript": "^5.3.3",
68
+ "vite": "^5.0.11",
69
+ "vitest": "^1.2.0"
70
+ }
71
+ }
package/plugin.yaml ADDED
@@ -0,0 +1,23 @@
1
+ name: wix-bookings
2
+ # No module field for NPM packages - uses package main export by default
3
+
4
+ contracts:
5
+ - name: booking-flow
6
+ contract: booking-flow.jay-contract
7
+ component: bookingFlow
8
+ description: Full booking flow (service list, slot picker, form, checkout)
9
+
10
+ services:
11
+ - name: wix-bookings
12
+ marker: WIX_BOOKINGS_SERVICE
13
+ description: Server-side Bookings + ecom v2 checkout APIs
14
+
15
+ actions:
16
+ - name: listServices
17
+ action: list-services.jay-action
18
+ - name: listSlots
19
+ action: list-slots.jay-action
20
+ - name: createBooking
21
+ action: create-booking.jay-action
22
+
23
+ setup: setupWixBookings