@jphil/bookwhen-client 0.3.0 → 0.3.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 +35 -24
- package/dist/index.d.ts +199 -2
- package/dist/index.js +6575 -0
- package/dist/index.js.map +1 -0
- package/package.json +15 -22
- package/dist/index.es.js +0 -260
- package/dist/index.es.js.map +0 -1
- package/dist/src/client/BookwhenClient.d.ts +0 -40
- package/dist/src/index.d.ts +0 -3
- package/dist/src/request/BookwhenRequest.d.ts +0 -46
- package/dist/src/request/httpStatusCodes.d.ts +0 -3
- package/dist/src/services/event/Event.d.ts +0 -32
- package/dist/src/services/event/EventInterfaces.d.ts +0 -53
- package/dist/src/services/event/EventSchemas.d.ts +0 -12
- package/dist/src/services/event/EventTypes.d.ts +0 -36
- package/dist/src/types/GlobalTypes.d.ts +0 -21
- package/dist/src/utils/http-utils.d.ts +0 -3
package/README.md
CHANGED
|
@@ -32,8 +32,9 @@ pnpm add @jphil/bookwhen-client
|
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
As `axios` and `zod` are peer dependencies, ensure they are also installed in your project:
|
|
35
|
+
|
|
35
36
|
```bash
|
|
36
|
-
pnpm add axios zod
|
|
37
|
+
pnpm add axios zod
|
|
37
38
|
# or npm install axios zod
|
|
38
39
|
# or yarn add axios zod
|
|
39
40
|
```
|
|
@@ -47,15 +48,15 @@ This library is distributed as an ES module. The following usage pattern applies
|
|
|
47
48
|
import { createBookwhenClient } from '@jphil/bookwhen-client';
|
|
48
49
|
|
|
49
50
|
// create the client
|
|
50
|
-
const client = createBookwhenClient({
|
|
51
|
+
const client = createBookwhenClient({
|
|
51
52
|
apiKey: 'your-API-key',
|
|
52
|
-
debug: true
|
|
53
|
+
debug: true, // Optional: enables request logging
|
|
53
54
|
});
|
|
54
55
|
|
|
55
56
|
// Get a single event
|
|
56
57
|
const event = await client.events.getById({
|
|
57
58
|
eventId: 'some-id',
|
|
58
|
-
includes: ['location', 'tickets']
|
|
59
|
+
includes: ['location', 'tickets'], // Optional: include related resources
|
|
59
60
|
});
|
|
60
61
|
|
|
61
62
|
// get all events
|
|
@@ -63,19 +64,19 @@ const events = await client.events.getMultiple();
|
|
|
63
64
|
|
|
64
65
|
// get all events in 2025 tagged with 'workshop'
|
|
65
66
|
const events_2025 = await client.events.getMultiple({
|
|
66
|
-
filters: {
|
|
67
|
+
filters: {
|
|
68
|
+
// Optional: filter by various
|
|
67
69
|
from: '20250101',
|
|
68
70
|
to: '20251231',
|
|
69
|
-
tag: ['workshop']
|
|
71
|
+
tag: ['workshop'],
|
|
70
72
|
},
|
|
71
|
-
includes: ['location']
|
|
73
|
+
includes: ['location'], // Optional: Include related resources
|
|
72
74
|
});
|
|
73
|
-
|
|
74
75
|
```
|
|
75
76
|
|
|
76
77
|
(N.B. Ensure you wrap the above statements in try/catch blocks to catch errors which could be thrown)
|
|
77
78
|
|
|
78
|
-
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)
|
|
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)
|
|
79
80
|
|
|
80
81
|
Services for the other models in the API are in the pipeline.
|
|
81
82
|
|
|
@@ -93,34 +94,40 @@ If you are using a JavaScript bundler (like Webpack, Rollup, Vite, Parcel, etc.)
|
|
|
93
94
|
import { createBookwhenClient } from '@jphil/bookwhen-client';
|
|
94
95
|
// ... rest of your code
|
|
95
96
|
```
|
|
97
|
+
|
|
96
98
|
Ensure that `axios` and `zod` are also installed in your project, as they are peer dependencies. Your bundler will typically handle resolving these.
|
|
97
99
|
|
|
98
100
|
### Directly with `<script type="module">` (Advanced)
|
|
99
101
|
|
|
100
102
|
For direct usage in a browser via `<script type="module">` without a bundler, you will need to:
|
|
103
|
+
|
|
101
104
|
1. Ensure ES module versions of `axios` and `zod` are accessible to your page (e.g., served locally or via a CDN).
|
|
102
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`.
|
|
103
106
|
|
|
104
107
|
Example import map:
|
|
108
|
+
|
|
105
109
|
```html
|
|
106
110
|
<script type="importmap">
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
+
}
|
|
112
117
|
}
|
|
113
|
-
}
|
|
114
118
|
</script>
|
|
115
119
|
<script type="module">
|
|
116
120
|
import { createBookwhenClient } from '@jphil/bookwhen-client';
|
|
117
121
|
// ...
|
|
118
122
|
</script>
|
|
119
123
|
```
|
|
124
|
+
|
|
120
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.
|
|
121
126
|
|
|
122
127
|
### Important Note on API Keys in Client-Side Usage
|
|
123
|
-
|
|
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
|
+
|
|
124
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.
|
|
125
132
|
- This library enables access to Bookwhen API endpoints based on the permissions granted to the API key you provide.
|
|
126
133
|
|
|
@@ -135,6 +142,7 @@ The library provides comprehensive error handling that works consistently in bot
|
|
|
135
142
|
- `timestamp`: The time the error occurred.
|
|
136
143
|
|
|
137
144
|
### Error Types
|
|
145
|
+
|
|
138
146
|
- `NETWORK_ERROR`: Indicates a failure in API communication (e.g., DNS resolution, connection refused).
|
|
139
147
|
- `SECURITY_ERROR`: Specific to browsers, indicates security restrictions prevented API access (e.g., CORS issues not handled by the server, mixed content).
|
|
140
148
|
- `API_ERROR`: The Bookwhen API returned an error response (e.g., 4xx or 5xx status code). The `context` may include `statusCode` and `responseData`.
|
|
@@ -142,10 +150,12 @@ The library provides comprehensive error handling that works consistently in bot
|
|
|
142
150
|
- `UNKNOWN_ERROR`: An unexpected error occurred within the library.
|
|
143
151
|
|
|
144
152
|
Example:
|
|
153
|
+
|
|
145
154
|
```typescript
|
|
146
155
|
try {
|
|
147
|
-
await client.events.getById({eventId: 'invalid-id'});
|
|
148
|
-
} catch (error: any) {
|
|
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
|
|
149
159
|
console.error(`Error Code: ${error.code}`);
|
|
150
160
|
console.error(`Message: ${error.message}`);
|
|
151
161
|
if (error.code === 'API_ERROR') {
|
|
@@ -176,16 +186,19 @@ Please see the docs in the CONTRIBUTIONS.md file, thanks!
|
|
|
176
186
|
[refining]
|
|
177
187
|
|
|
178
188
|
From main branch on local:
|
|
189
|
+
|
|
179
190
|
- Pull latest code
|
|
180
191
|
- git checkout -b some-new-branch
|
|
181
192
|
- git commit -m 'feat(context): my latest work on feature x'
|
|
182
193
|
- git push, copy URL
|
|
183
194
|
|
|
184
195
|
On github
|
|
196
|
+
|
|
185
197
|
> Open PR on github
|
|
186
198
|
> Perfect, merge when checks pass
|
|
187
199
|
|
|
188
200
|
On local:
|
|
201
|
+
|
|
189
202
|
- checkout main
|
|
190
203
|
- git pull
|
|
191
204
|
- git branch -d release (so we have a clean release branch)
|
|
@@ -195,17 +208,15 @@ On local:
|
|
|
195
208
|
- git push
|
|
196
209
|
|
|
197
210
|
On github:
|
|
211
|
+
|
|
198
212
|
- Open PR main <- release on github
|
|
199
|
-
> Perfect, merge when checks pass (check why no build)
|
|
213
|
+
> Perfect, merge when checks pass (check why no build)
|
|
200
214
|
|
|
201
215
|
On local:
|
|
216
|
+
|
|
202
217
|
- git checkout main
|
|
203
218
|
- git tag -a vx.x.x -m 'release vx.x.x'
|
|
204
|
-
- git push origin vx.x.x
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
219
|
+
- git push origin vx.x.x <<<< RELEASE to github and NPM
|
|
209
220
|
|
|
210
221
|
## Roadmap
|
|
211
222
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,199 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Client for the Bookwhen API.
|
|
6
|
+
*
|
|
7
|
+
* @see https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml#/ClassPass/get_class_passes__class_pass_id_
|
|
8
|
+
*/
|
|
9
|
+
declare class BookwhenClient {
|
|
10
|
+
private axiosInstance;
|
|
11
|
+
private eventService?;
|
|
12
|
+
private readonly isBrowser;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new instance of the BookwhenClient class.
|
|
15
|
+
* @param axiosInstance - Configured Axios instance for making HTTP requests.
|
|
16
|
+
* @throws Error if axiosInstance is not provided.
|
|
17
|
+
*/
|
|
18
|
+
constructor(axiosInstance: AxiosInstance);
|
|
19
|
+
/**
|
|
20
|
+
* Gets the EventService instance.
|
|
21
|
+
*
|
|
22
|
+
* Available methods:
|
|
23
|
+
* - getById(params: GetEventByIdParams): Promise<BookwhenEvent>
|
|
24
|
+
* - getMultiple(params: GetMultipleEventsParams): Promise<BookwhenEvent[]>
|
|
25
|
+
*
|
|
26
|
+
* @returns The EventService instance.
|
|
27
|
+
*/
|
|
28
|
+
get events(): EventService;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare interface BookwhenClientOptions {
|
|
32
|
+
apiKey: string;
|
|
33
|
+
baseURL?: string;
|
|
34
|
+
debug?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export declare interface BookwhenError {
|
|
38
|
+
code: 'NETWORK_ERROR' | 'SECURITY_ERROR' | 'API_ERROR' | 'CONFIG_ERROR' | 'UNKNOWN_ERROR';
|
|
39
|
+
message: string;
|
|
40
|
+
isBrowser: boolean;
|
|
41
|
+
context?: {
|
|
42
|
+
browser?: {
|
|
43
|
+
isSecure?: boolean;
|
|
44
|
+
userAgent?: string;
|
|
45
|
+
};
|
|
46
|
+
timestamp: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare interface BookwhenEvent {
|
|
51
|
+
id: string;
|
|
52
|
+
type: string;
|
|
53
|
+
attributes: EventAttributes;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates an instance of Axios with the provided API key.
|
|
58
|
+
* @param apiKey - The API key used for authentication.
|
|
59
|
+
* @returns The Axios instance.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createBookwhenClient(options: BookwhenClientOptions): BookwhenClient;
|
|
62
|
+
|
|
63
|
+
declare interface EventAttributes {
|
|
64
|
+
title: string;
|
|
65
|
+
details: string;
|
|
66
|
+
all_day: boolean;
|
|
67
|
+
start_at: string;
|
|
68
|
+
end_at: string;
|
|
69
|
+
attendee_limit: number;
|
|
70
|
+
attendee_count: number;
|
|
71
|
+
waiting_list: boolean;
|
|
72
|
+
max_tickets_per_booking: number;
|
|
73
|
+
tags: string[];
|
|
74
|
+
event_image: EventImage;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export declare type EventFilters = {
|
|
78
|
+
[K in keyof EventFiltersMap]?: EventFiltersMap[K];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
declare interface EventFiltersMap {
|
|
82
|
+
calendar?: string[];
|
|
83
|
+
entry?: string[];
|
|
84
|
+
location?: string[];
|
|
85
|
+
tag?: string[];
|
|
86
|
+
title?: string[];
|
|
87
|
+
detail?: string[];
|
|
88
|
+
from?: string;
|
|
89
|
+
to?: string;
|
|
90
|
+
compact?: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare interface EventImage {
|
|
94
|
+
image_url: string;
|
|
95
|
+
alt_ratio_16x9_1x_url: string;
|
|
96
|
+
alt_ratio_16x9_2x_url: string;
|
|
97
|
+
alt_ratio_16x9_3x_url: string;
|
|
98
|
+
alt_ratio_4x3_1x_url: string;
|
|
99
|
+
alt_ratio_4x3_2x_url: string;
|
|
100
|
+
alt_ratio_4x3_3x_url: string;
|
|
101
|
+
alt_ratio_1x1_1x_url: string;
|
|
102
|
+
alt_ratio_1x1_2x_url: string;
|
|
103
|
+
alt_ratio_1x1_3x_url: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export declare type EventResource = 'location' | 'attachments' | 'tickets' | 'tickets.events' | 'tickets.class_passes';
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Service class for managing events in the Bookwhen API.
|
|
110
|
+
*/
|
|
111
|
+
declare class EventService implements IEventService {
|
|
112
|
+
private axiosInstance;
|
|
113
|
+
/**
|
|
114
|
+
* Initializes EventService with an Axios instance for dependency injection.
|
|
115
|
+
* @param axiosInstance - The Axios instance to use for API requests.
|
|
116
|
+
*/
|
|
117
|
+
constructor(axiosInstance: AxiosInstance);
|
|
118
|
+
/**
|
|
119
|
+
* Retrieves a single event by its ID from the Bookwhen API.
|
|
120
|
+
*
|
|
121
|
+
* @param {Object} param - The parameters for retrieving an event.
|
|
122
|
+
* @param {string} param.eventId - The ID of the event to retrieve.
|
|
123
|
+
* @param {string} [param.include] - Optional parameter to include additional data.
|
|
124
|
+
* @returns {Promise<BookwhenEvent>} A Promise that resolves to the BookwhenEvent object.
|
|
125
|
+
*/
|
|
126
|
+
getById(params: z.infer<typeof GetEventByIdParamsSchema>): Promise<BookwhenEvent>;
|
|
127
|
+
/**
|
|
128
|
+
* Retrieves multiple events based on filtering and pagination parameters.
|
|
129
|
+
*
|
|
130
|
+
* @param {GetMultipleEventsParams} params - Optional parameters for filtering and pagination.
|
|
131
|
+
* @return {Promise<BookwhenEvent[]>} A Promise that resolves to an array of BookwhenEvent objects.
|
|
132
|
+
*/
|
|
133
|
+
getMultiple(params?: GetMultipleEventsParams): Promise<BookwhenEvent[]>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export declare interface Filters {
|
|
137
|
+
[key: string]: string | string[] | boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Parameters for querying a single event from the Bookwhen API, including optional include parameter.
|
|
142
|
+
* @param eventId The unique identifier of the event.
|
|
143
|
+
* @param include Optional parameter to include additional data.
|
|
144
|
+
*/
|
|
145
|
+
export declare interface GetEventByIdParams {
|
|
146
|
+
eventId: string;
|
|
147
|
+
includes?: EventResource[];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
declare const GetEventByIdParamsSchema: z.ZodObject<{
|
|
151
|
+
eventId: z.ZodString;
|
|
152
|
+
includes: z.ZodOptional<z.ZodArray<z.ZodEnum<["location", "attachments", "tickets", "tickets.events", "tickets.class_passes"]>, "many">>;
|
|
153
|
+
}, "strip", z.ZodTypeAny, {
|
|
154
|
+
eventId: string;
|
|
155
|
+
includes?: ("location" | "attachments" | "tickets" | "tickets.events" | "tickets.class_passes")[] | undefined;
|
|
156
|
+
}, {
|
|
157
|
+
eventId: string;
|
|
158
|
+
includes?: ("location" | "attachments" | "tickets" | "tickets.events" | "tickets.class_passes")[] | undefined;
|
|
159
|
+
}>;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Represents the parameters for getting multiple events.
|
|
163
|
+
* @param filter The filter parameters to apply to the query.
|
|
164
|
+
* @param include The data to side load and include with the returned events.
|
|
165
|
+
*/
|
|
166
|
+
export declare interface GetMultipleEventsParams {
|
|
167
|
+
filters?: EventFilters;
|
|
168
|
+
includes?: EventResource[];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export declare interface HttpStatus {
|
|
172
|
+
code: number;
|
|
173
|
+
message: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Interface for services handling events via the Bookwhen API V2.
|
|
178
|
+
*/
|
|
179
|
+
export declare interface IEventService {
|
|
180
|
+
/**
|
|
181
|
+
* Retrieves a single event by its ID.
|
|
182
|
+
* @param eventId The unique identifier of the event.
|
|
183
|
+
* @param include Optional parameter to include additional data.
|
|
184
|
+
* @returns A Promise that resolves to an Event object, as defined by the Bookwhen API data structure.
|
|
185
|
+
*/
|
|
186
|
+
getById(params: GetEventByIdParams): Promise<BookwhenEvent>;
|
|
187
|
+
/**
|
|
188
|
+
* Retrieves multiple events based on specified parameters.
|
|
189
|
+
* @param params Optional parameters to filter and control the list of returned events, according to what the Bookwhen API supports.
|
|
190
|
+
* @returns A Promise that resolves to an array of Event objects.
|
|
191
|
+
*/
|
|
192
|
+
getMultiple?(params?: GetMultipleEventsParams): Promise<BookwhenEvent[]>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export declare type Resource = string;
|
|
196
|
+
|
|
197
|
+
export declare type Resources = Resource[];
|
|
198
|
+
|
|
199
|
+
export { }
|