@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 +70 -184
- package/dist/index.d.ts +350 -0
- package/dist/index.js +236 -0
- package/dist/index.js.map +1 -1
- package/package.json +20 -19
package/README.md
CHANGED
|
@@ -1,232 +1,118 @@
|
|
|
1
1
|
# `@jphil/bookwhen-client`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript client for the [Bookwhen API v2](https://api.bookwhen.com/v2), built for Node.js and browser environments.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This package is currently pre-1.0 and under active development.
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
53
|
-
debug: true, // Optional: enables request logging
|
|
21
|
+
apiKey: process.env.BOOKWHEN_API_KEY!,
|
|
54
22
|
});
|
|
55
23
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
63
|
-
const
|
|
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
|
-
|
|
33
|
+
## API Coverage
|
|
78
34
|
|
|
79
|
-
|
|
35
|
+
Bookwhen resources currently implemented in this client:
|
|
80
36
|
|
|
81
|
-
|
|
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
|
-
|
|
45
|
+
Reference docs:
|
|
84
46
|
|
|
85
|
-
|
|
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
|
-
|
|
50
|
+
## Response Shape
|
|
88
51
|
|
|
89
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
89
|
+
## Development
|
|
183
90
|
|
|
184
|
-
|
|
91
|
+
Common local commands:
|
|
185
92
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
213
|
-
> Perfect, merge when checks pass (check why no build)
|
|
100
|
+
## Documentation
|
|
214
101
|
|
|
215
|
-
|
|
102
|
+
Project docs are intentionally lightweight and living:
|
|
216
103
|
|
|
217
|
-
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
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
|
-
-
|
|
224
|
-
-
|
|
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)
|
|
118
|
+
ISC License. See [LICENSE](LICENSE).
|