@jphil/bookwhen-client 0.4.1 → 0.5.1

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/README.md CHANGED
@@ -1,232 +1,118 @@
1
1
  # `@jphil/bookwhen-client`
2
2
 
3
- A universal API client library for the [Bookwhen](https://www.bookwhen.com) booking platform [API (v2)](https://api.bookwhen.com/v2), written in TypeScript for both NodeJS and browser environments.
3
+ TypeScript client for the [Bookwhen API v2](https://api.bookwhen.com/v2), built for Node.js and browser environments.
4
4
 
5
- ## Table of Contents
5
+ This package is currently pre-1.0 and under active development.
6
6
 
7
- - [Overview](#overview)
8
- - [Features](#features)
9
- - [Installation](#installation)
10
- - [Usage](#usage)
11
- - [Configuration](#configuration)
12
- - [Contributing](#contributing)
13
- - [Roadmap](#roadmap)
14
- - [License](#license)
7
+ ## Quick Start
15
8
 
16
- ## Overview
17
-
18
- You'll likely be at least somewhat familiar with the [Bookwhen](https://www.bookwhen.com) booking platform if you've landed here. But if not, you'll want to have a look at their [API (v2) documentation](https://api.bookwhen.com/v2). There's also a nice [Swagger style layout of the Bookwhen API v2 docs](https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml)
19
-
20
- ## Features
21
-
22
- - Provides an easy way to access Bookwhen API from both NodeJS and browsers
23
- - Browser-compatible with proper CORS handling
24
- - Provides fully typed methods for each model (so far just the Events model) provided in the Bookwhen API v2
25
-
26
- ## Installation
27
-
28
- Install via pnpm:
9
+ Install the library and peer dependencies:
29
10
 
30
11
  ```bash
31
- pnpm add @jphil/bookwhen-client
12
+ pnpm add @jphil/bookwhen-client axios zod
32
13
  ```
33
14
 
34
- As `axios` and `zod` are peer dependencies, ensure they are also installed in your project:
35
-
36
- ```bash
37
- pnpm add axios zod
38
- # or npm install axios zod
39
- # or yarn add axios zod
40
- ```
41
-
42
- ## Usage
43
-
44
- This library is distributed as an ES module. The following usage pattern applies to modern Node.js environments (with `type: "module"` in your `package.json` or when using `.mjs` files) and browser environments when using a bundler. For direct browser usage without a bundler, see the [Browser Usage](#browser-usage) section below.
15
+ Create a client and fetch events:
45
16
 
46
17
  ```typescript
47
- // import the client factory
48
18
  import { createBookwhenClient } from '@jphil/bookwhen-client';
49
19
 
50
- // create the client
51
20
  const client = createBookwhenClient({
52
- apiKey: 'your-API-key',
53
- debug: true, // Optional: enables request logging
21
+ apiKey: process.env.BOOKWHEN_API_KEY!,
54
22
  });
55
23
 
56
- // Get a single event
57
- const event = await client.events.getById({
58
- eventId: 'some-id',
59
- includes: ['location', 'tickets'], // Optional: include related resources
24
+ const response = await client.events.getMultiple({
25
+ filters: { from: '20250101', to: '20251231' },
26
+ includes: ['location', 'tickets'],
60
27
  });
61
28
 
62
- // get all events
63
- const events = await client.events.getMultiple();
64
-
65
- // get all events in 2025 tagged with 'workshop'
66
- const events_2025 = await client.events.getMultiple({
67
- filters: {
68
- // Optional: filter by various
69
- from: '20250101',
70
- to: '20251231',
71
- tag: ['workshop'],
72
- },
73
- includes: ['location'], // Optional: Include related resources
74
- });
29
+ const events = response.data;
30
+ const included = response.included;
75
31
  ```
76
32
 
77
- (N.B. Ensure you wrap the above statements in try/catch blocks to catch errors which could be thrown)
33
+ ## API Coverage
78
34
 
79
- 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)
35
+ Bookwhen resources currently implemented in this client:
80
36
 
81
- Services for the other models in the API are in the pipeline.
37
+ | Resource | Status | Endpoints |
38
+ | ------------ | ----------- | ------------------------------------------------ |
39
+ | Events | Implemented | `/events`, `/events/{event_id}` |
40
+ | Tickets | Implemented | `/tickets`, `/tickets/{ticket_id}` |
41
+ | Locations | Implemented | `/locations`, `/locations/{location_id}` |
42
+ | Attachments | Implemented | `/attachments`, `/attachments/{attachment_id}` |
43
+ | Class passes | Implemented | `/class_passes`, `/class_passes/{class_pass_id}` |
82
44
 
83
- N.B. This library is still a pre-1.0.0 WIP, please use accordingly, and pls submit issues for any bugs!
45
+ Reference docs:
84
46
 
85
- ## Browser Usage
47
+ - Bookwhen API docs: https://api.bookwhen.com/v2
48
+ - Swagger layout: https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml
86
49
 
87
- The client is well-suited for browser environments.
50
+ ## Response Shape
88
51
 
89
- ### With a Bundler (Recommended for Browser Projects)
90
-
91
- If you are using a JavaScript bundler (like Webpack, Rollup, Vite, Parcel, etc.) in your browser project, you can import and use the client as shown in the main [Usage](#usage) section:
52
+ Service methods return full JSON:API response envelopes (not just `data`).
92
53
 
93
54
  ```typescript
94
- import { createBookwhenClient } from '@jphil/bookwhen-client';
95
- // ... rest of your code
96
- ```
97
-
98
- Ensure that `axios` and `zod` are also installed in your project, as they are peer dependencies. Your bundler will typically handle resolving these.
99
-
100
- ### Directly with `<script type="module">` (Advanced)
101
-
102
- For direct usage in a browser via `<script type="module">` without a bundler, you will need to:
103
-
104
- 1. Ensure ES module versions of `axios` and `zod` are accessible to your page (e.g., served locally or via a CDN).
105
- 2. Use an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) to tell the browser how to resolve the module specifiers for `@jphil/bookwhen-client`, `axios`, and `zod`.
106
-
107
- Example import map:
55
+ const eventResponse = await client.events.getById({
56
+ eventId: 'ev-123',
57
+ includes: ['location'],
58
+ });
108
59
 
109
- ```html
110
- <script type="importmap">
111
- {
112
- "imports": {
113
- "@jphil/bookwhen-client": "/node_modules/@jphil/bookwhen-client/dist/index.es.js",
114
- "axios": "/node_modules/axios/dist/esm/axios.js",
115
- "zod": "/node_modules/zod/lib/index.mjs"
116
- }
117
- }
118
- </script>
119
- <script type="module">
120
- import { createBookwhenClient } from '@jphil/bookwhen-client';
121
- // ...
122
- </script>
60
+ eventResponse.data;
61
+ eventResponse.included;
62
+ eventResponse.links;
63
+ eventResponse.meta;
123
64
  ```
124
65
 
125
- Note: The exact paths in the import map will depend on how you serve these dependencies. Usage with a bundler is generally simpler for browser projects.
126
-
127
- ### Important Note on API Keys in Client-Side Usage
128
-
129
- When using this library in a browser (client-side), your Bookwhen API key will necessarily be included in the client-side code and thus visible.
130
-
131
- - It is crucial to use an API key that has the minimum necessary permissions for the operations you intend to perform from the client-side.
132
- - This library enables access to Bookwhen API endpoints based on the permissions granted to the API key you provide.
133
-
134
- ## Error Handling
135
-
136
- The library provides comprehensive error handling that works consistently in both Node.js and browser environments. Custom error objects thrown by the library will have the following properties:
137
-
138
- - `code`: An error code string identifying the type of error (e.g., `NETWORK_ERROR`, `API_ERROR`).
139
- - `message`: A human-readable description of the error.
140
- - `isBrowser`: A boolean indicating if the error occurred in a browser environment.
141
- - `context`: An object containing additional details, which may include the original error, status codes, etc.
142
- - `timestamp`: The time the error occurred.
143
-
144
- ### Error Types
145
-
146
- - `NETWORK_ERROR`: Indicates a failure in API communication (e.g., DNS resolution, connection refused).
147
- - `SECURITY_ERROR`: Specific to browsers, indicates security restrictions prevented API access (e.g., CORS issues not handled by the server, mixed content).
148
- - `API_ERROR`: The Bookwhen API returned an error response (e.g., 4xx or 5xx status code). The `context` may include `statusCode` and `responseData`.
149
- - `CONFIG_ERROR`: The client was configured incorrectly (e.g., missing API key).
150
- - `UNKNOWN_ERROR`: An unexpected error occurred within the library.
151
-
152
- Example:
66
+ Relationship helper utilities are exported:
153
67
 
154
68
  ```typescript
155
- try {
156
- await client.events.getById({ eventId: 'invalid-id' });
157
- } catch (error: any) {
158
- // It's good practice to type the error if you have custom error types defined
159
- console.error(`Error Code: ${error.code}`);
160
- console.error(`Message: ${error.message}`);
161
- if (error.code === 'API_ERROR') {
162
- console.error('API Error Details:', error.context?.responseData);
163
- } else if (error.code === 'NETWORK_ERROR') {
164
- // Handle network issues, maybe retry or inform user
165
- }
166
- // Other error handling...
167
- }
69
+ import {
70
+ resolveJsonApiRelationships,
71
+ resolveJsonApiResource,
72
+ } from '@jphil/bookwhen-client';
73
+
74
+ const resolvedMany = resolveJsonApiRelationships(
75
+ response.data,
76
+ response.included,
77
+ );
78
+ const resolvedOne = resolveJsonApiResource(
79
+ eventResponse.data,
80
+ eventResponse.included,
81
+ );
168
82
  ```
169
83
 
170
- ## Configuration
171
-
172
- Required configuration:
173
-
174
- - **apiKey**: Your Bookwhen API key (required)
175
-
176
- API requests to the Bookwhen API are authenticated using Basic Authentication with the API Key as the username and a blank password.
177
-
178
- API keys can be generated in the [API tokens setup area of your Bookwhen account](https://admin.bookwhen.com/settings/api_access_permission_sets). (This will link to the API settings page in your Bookwhen account if you have one and are logged into your admin account)
84
+ ## Browser Notes
179
85
 
180
- ## Contributing
86
+ - The library works in browser contexts and includes browser-aware error handling.
87
+ - Client-side API keys are visible to users; use least-privilege Bookwhen API tokens.
181
88
 
182
- Please see the docs in the CONTRIBUTIONS.md file, thanks!
89
+ ## Development
183
90
 
184
- ## Mainainter release process
91
+ Common local commands:
185
92
 
186
- [refining]
187
-
188
- From main branch on local:
189
-
190
- - Pull latest code
191
- - git checkout -b some-new-branch
192
- - git commit -m 'feat(context): my latest work on feature x'
193
- - git push, copy URL
194
-
195
- On github
196
-
197
- > Open PR on github
198
- > Perfect, merge when checks pass
199
-
200
- On local:
201
-
202
- - checkout main
203
- - git pull
204
- - git branch -d release (so we have a clean release branch)
205
- - git checkout -b release
206
- - pnpm changeset (provide changelog message, commit will occur after)
207
- - pnpm changeset version (bumps version numbers, and updates changelog, and commits >>> note new version number)
208
- - git push
209
-
210
- On github:
93
+ ```bash
94
+ pnpm install
95
+ pnpm test
96
+ pnpm build
97
+ pnpm lint
98
+ ```
211
99
 
212
- - Open PR main <- release on github
213
- > Perfect, merge when checks pass (check why no build)
100
+ ## Documentation
214
101
 
215
- On local:
102
+ Project docs are intentionally lightweight and living:
216
103
 
217
- - git checkout main
218
- - git tag -a vx.x.x -m 'release vx.x.x'
219
- - git push origin vx.x.x <<<< RELEASE to github and NPM
104
+ - [CONTRIBUTING.md](CONTRIBUTING.md) - Contribution workflow and release notes
105
+ - [TODO.md](TODO.md) - Active work and backlog
106
+ - [DECISIONS.md](DECISIONS.md) - Architectural decisions
107
+ - [LEARNINGS.md](LEARNINGS.md) - Validated findings and gotchas
108
+ - [AGENTS.md](AGENTS.md) - Context and constraints for coding agents
220
109
 
221
110
  ## Roadmap
222
111
 
223
- - Proceed towards a 1.0.0 with community feedback.
224
- - Keep up with any future changes or additions to the [Bookwhen API](https://api.bookwhen.com/v2).
225
-
226
- ### Todos
227
-
228
- @see the issue queue.
112
+ - Expand coverage to remaining Bookwhen v2 content models.
113
+ - Continue improving test depth across browser and Node environments.
114
+ - Iterate toward a stable 1.0 release with community feedback.
229
115
 
230
116
  ## License
231
117
 
232
- ISC License. See [LICENSE](LICENSE) for more information.
118
+ ISC License. See [LICENSE](LICENSE).