@jphil/bookwhen-client 0.4.1 → 0.4.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/README.md +131 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -8,6 +8,10 @@ A universal API client library for the [Bookwhen](https://www.bookwhen.com) book
8
8
  - [Features](#features)
9
9
  - [Installation](#installation)
10
10
  - [Usage](#usage)
11
+ - [JSON:API Response Structure](#jsonapi-response-structure)
12
+ - [Migration from v0.3.2](#migration-from-v032)
13
+ - [Browser Usage](#browser-usage)
14
+ - [Error Handling](#error-handling)
11
15
  - [Configuration](#configuration)
12
16
  - [Contributing](#contributing)
13
17
  - [Roadmap](#roadmap)
@@ -22,6 +26,9 @@ You'll likely be at least somewhat familiar with the [Bookwhen](https://www.book
22
26
  - Provides an easy way to access Bookwhen API from both NodeJS and browsers
23
27
  - Browser-compatible with proper CORS handling
24
28
  - Provides fully typed methods for each model (so far just the Events model) provided in the Bookwhen API v2
29
+ - **Full JSON:API compliance** with access to included resources, links, and meta data
30
+ - **Relationship resolution utilities** for working with included data
31
+ - **Type-safe JSON:API response interfaces** with proper TypeScript support
25
32
 
26
33
  ## Installation
27
34
 
@@ -53,17 +60,19 @@ const client = createBookwhenClient({
53
60
  debug: true, // Optional: enables request logging
54
61
  });
55
62
 
56
- // Get a single event
57
- const event = await client.events.getById({
63
+ // Get a single event - returns full JSON:API response
64
+ const eventResponse = await client.events.getById({
58
65
  eventId: 'some-id',
59
66
  includes: ['location', 'tickets'], // Optional: include related resources
60
67
  });
68
+ const event = eventResponse.data; // Access the event data
61
69
 
62
- // get all events
63
- const events = await client.events.getMultiple();
70
+ // get all events - returns full JSON:API response
71
+ const eventsResponse = await client.events.getMultiple();
72
+ const events = eventsResponse.data; // Access the events array
64
73
 
65
- // get all events in 2025 tagged with 'workshop'
66
- const events_2025 = await client.events.getMultiple({
74
+ // get all events in 2025 tagged with 'workshop' with included locations
75
+ const events2025Response = await client.events.getMultiple({
67
76
  filters: {
68
77
  // Optional: filter by various
69
78
  from: '20250101',
@@ -72,12 +81,121 @@ const events_2025 = await client.events.getMultiple({
72
81
  },
73
82
  includes: ['location'], // Optional: Include related resources
74
83
  });
84
+ const events2025 = events2025Response.data; // Access the events array
85
+ const includedLocations = events2025Response.included; // Access included location data
75
86
  ```
76
87
 
77
88
  (N.B. Ensure you wrap the above statements in try/catch blocks to catch errors which could be thrown)
78
89
 
79
90
  Valid filters and includes for each method are detailed in the [API v2 docs](https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml)
80
91
 
92
+ ## JSON:API Response Structure
93
+
94
+ Service methods now return full JSON:API response objects instead of just data arrays. This provides access to all data returned by the Bookwhen API, including included resources, links, and metadata.
95
+
96
+ ### Response Structure Example
97
+
98
+ ```typescript
99
+ const response = await client.events.getMultiple({
100
+ includes: ['location', 'tickets']
101
+ });
102
+
103
+ // response structure:
104
+ {
105
+ data: [
106
+ {
107
+ id: 'ev-123',
108
+ type: 'event',
109
+ attributes: {
110
+ title: 'Thai massage with Justin',
111
+ start_at: '2025-11-02T11:00:00.000+00:00',
112
+ // ... other event attributes
113
+ },
114
+ relationships: {
115
+ location: { data: { id: 'loc-1', type: 'location' } },
116
+ tickets: { data: [{ id: 'ticket-1', type: 'ticket' }] }
117
+ }
118
+ }
119
+ ],
120
+ included: [
121
+ {
122
+ id: 'loc-1',
123
+ type: 'location',
124
+ attributes: {
125
+ address_text: 'MovingStillness Studio\nColdean\nBrighton',
126
+ latitude: 50.8608545,
127
+ longitude: -0.1070177
128
+ }
129
+ },
130
+ {
131
+ id: 'ticket-1',
132
+ type: 'ticket',
133
+ attributes: {
134
+ name: 'Standard Ticket',
135
+ price: 100,
136
+ available: true
137
+ }
138
+ }
139
+ ],
140
+ links: {
141
+ self: 'https://api.bookwhen.com/v2/events'
142
+ },
143
+ meta: {
144
+ // Optional metadata
145
+ }
146
+ }
147
+ ```
148
+
149
+ ### Working with Included Data
150
+
151
+ The library provides utility functions to help resolve relationships between resources:
152
+
153
+ ```typescript
154
+ import { resolveJsonApiRelationships, resolveJsonApiResource } from '@jphil/bookwhen-client';
155
+
156
+ // For multiple events
157
+ const eventsResponse = await client.events.getMultiple({
158
+ includes: ['location', 'tickets']
159
+ });
160
+
161
+ // Resolve relationships for all events
162
+ const resolvedEvents = resolveJsonApiRelationships(
163
+ eventsResponse.data,
164
+ eventsResponse.included
165
+ );
166
+
167
+ // For a single event
168
+ const eventResponse = await client.events.getById({
169
+ eventId: 'ev-123',
170
+ includes: ['location']
171
+ });
172
+
173
+ // Resolve relationships for a single event
174
+ const resolvedEvent = resolveJsonApiResource(
175
+ eventResponse.data,
176
+ eventResponse.included
177
+ );
178
+ ```
179
+
180
+ ## Migration from v0.3.2
181
+
182
+ Version 0.4.0 introduces breaking changes to return full JSON:API responses:
183
+
184
+ ### Before (v0.3.2)
185
+ ```typescript
186
+ const events = await client.events.getMultiple(); // BookwhenEvent[]
187
+ const event = await client.events.getById({ eventId: '123' }); // BookwhenEvent
188
+ ```
189
+
190
+ ### After (v0.4.0)
191
+ ```typescript
192
+ const response = await client.events.getMultiple(); // EventsResponse
193
+ const events = response.data; // BookwhenEvent[]
194
+
195
+ const eventResponse = await client.events.getById({ eventId: '123' }); // EventResponse
196
+ const event = eventResponse.data; // BookwhenEvent
197
+ ```
198
+
81
199
  Services for the other models in the API are in the pipeline.
82
200
 
83
201
  N.B. This library is still a pre-1.0.0 WIP, please use accordingly, and pls submit issues for any bugs!
@@ -192,10 +310,10 @@ From main branch on local:
192
310
  - git commit -m 'feat(context): my latest work on feature x'
193
311
  - git push, copy URL
194
312
 
195
- On github
313
+ On github/local:
196
314
 
197
- > Open PR on github
198
- > Perfect, merge when checks pass
315
+ - Open PR on github
316
+ - Perfect the PR, merge when checks pass
199
317
 
200
318
  On local:
201
319
 
@@ -203,18 +321,19 @@ On local:
203
321
  - git pull
204
322
  - git branch -d release (so we have a clean release branch)
205
323
  - git checkout -b release
206
- - pnpm changeset (provide changelog message, commit will occur after)
324
+ - pnpm changeset (provide changelog message - commit will occur in next step, not this one)
207
325
  - pnpm changeset version (bumps version numbers, and updates changelog, and commits >>> note new version number)
208
326
  - git push
209
327
 
210
328
  On github:
211
329
 
212
- - Open PR main <- release on github
213
- > Perfect, merge when checks pass (check why no build)
330
+ - Open PR for release to merge into main
331
+ - Perfect the PR, merge when checks pass (check why no build)
214
332
 
215
333
  On local:
216
334
 
217
335
  - git checkout main
336
+ - git pull
218
337
  - git tag -a vx.x.x -m 'release vx.x.x'
219
338
  - git push origin vx.x.x <<<< RELEASE to github and NPM
220
339
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jphil/bookwhen-client",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "TypeScript client for the Bookwhen API (v2)",
5
5
  "private": false,
6
6
  "type": "module",