@jphil/bookwhen-client 0.2.5 → 0.3.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.
- package/README.md +127 -7
- package/dist/index.d.ts +2 -3
- package/dist/index.es.js +260 -0
- package/dist/index.es.js.map +1 -0
- package/dist/{client → src/client}/BookwhenClient.d.ts +2 -1
- package/dist/{index.js → src/index.d.ts} +0 -1
- package/dist/{request → src/request}/BookwhenRequest.d.ts +1 -1
- package/dist/{request → src/request}/httpStatusCodes.d.ts +1 -1
- package/dist/{services → src/services}/event/Event.d.ts +3 -3
- package/dist/{services → src/services}/event/EventInterfaces.d.ts +1 -1
- package/dist/src/types/GlobalTypes.d.ts +21 -0
- package/dist/src/utils/http-utils.d.ts +3 -0
- package/package.json +29 -9
- package/dist/client/BookwhenClient.js +0 -78
- package/dist/client/BookwhenClient.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/request/BookwhenRequest.js +0 -116
- package/dist/request/BookwhenRequest.js.map +0 -1
- package/dist/request/httpStatusCodes.js +0 -15
- package/dist/request/httpStatusCodes.js.map +0 -1
- package/dist/services/event/Event.js +0 -72
- package/dist/services/event/Event.js.map +0 -1
- package/dist/services/event/EventInterfaces.js +0 -3
- package/dist/services/event/EventInterfaces.js.map +0 -1
- package/dist/services/event/EventSchemas.js +0 -8
- package/dist/services/event/EventSchemas.js.map +0 -1
- package/dist/services/event/EventTypes.js +0 -2
- package/dist/services/event/EventTypes.js.map +0 -1
- package/dist/types/GlobalTypes.d.ts +0 -9
- package/dist/types/GlobalTypes.js +0 -2
- package/dist/types/GlobalTypes.js.map +0 -1
- package/dist/utils/http-utils.d.ts +0 -8
- package/dist/utils/http-utils.js +0 -19
- package/dist/utils/http-utils.js.map +0 -1
- /package/dist/{services → src/services}/event/EventSchemas.d.ts +0 -0
- /package/dist/{services → src/services}/event/EventTypes.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@jphil/bookwhen-client`
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
@@ -19,7 +19,8 @@ You'll likely be at least somewhat familiar with the [Bookwhen](https://www.book
|
|
|
19
19
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
22
|
-
- Provides an easy way to
|
|
22
|
+
- Provides an easy way to access Bookwhen API from both NodeJS and browsers
|
|
23
|
+
- Browser-compatible with proper CORS handling
|
|
23
24
|
- Provides fully typed methods for each model (so far just the Events model) provided in the Bookwhen API v2
|
|
24
25
|
|
|
25
26
|
## Installation
|
|
@@ -30,8 +31,17 @@ Install via pnpm:
|
|
|
30
31
|
pnpm add @jphil/bookwhen-client
|
|
31
32
|
```
|
|
32
33
|
|
|
34
|
+
As `axios` and `zod` are peer dependencies, ensure they are also installed in your project:
|
|
35
|
+
```bash
|
|
36
|
+
pnpm add axios zod
|
|
37
|
+
# or npm install axios zod
|
|
38
|
+
# or yarn add axios zod
|
|
39
|
+
```
|
|
40
|
+
|
|
33
41
|
## Usage
|
|
34
42
|
|
|
43
|
+
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.
|
|
44
|
+
|
|
35
45
|
```typescript
|
|
36
46
|
// import the client factory
|
|
37
47
|
import { createBookwhenClient } from '@jphil/bookwhen-client';
|
|
@@ -69,11 +79,87 @@ Valid filters and includes for each method are detailed in the [API v2 docs](htt
|
|
|
69
79
|
|
|
70
80
|
Services for the other models in the API are in the pipeline.
|
|
71
81
|
|
|
72
|
-
N.B. This library is still a pre-1.0.0 WIP, please use accordingly!
|
|
82
|
+
N.B. This library is still a pre-1.0.0 WIP, please use accordingly, and pls submit issues for any bugs!
|
|
83
|
+
|
|
84
|
+
## Browser Usage
|
|
85
|
+
|
|
86
|
+
The client is well-suited for browser environments.
|
|
87
|
+
|
|
88
|
+
### With a Bundler (Recommended for Browser Projects)
|
|
89
|
+
|
|
90
|
+
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:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { createBookwhenClient } from '@jphil/bookwhen-client';
|
|
94
|
+
// ... rest of your code
|
|
95
|
+
```
|
|
96
|
+
Ensure that `axios` and `zod` are also installed in your project, as they are peer dependencies. Your bundler will typically handle resolving these.
|
|
97
|
+
|
|
98
|
+
### Directly with `<script type="module">` (Advanced)
|
|
99
|
+
|
|
100
|
+
For direct usage in a browser via `<script type="module">` without a bundler, you will need to:
|
|
101
|
+
1. Ensure ES module versions of `axios` and `zod` are accessible to your page (e.g., served locally or via a CDN).
|
|
102
|
+
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
|
+
|
|
104
|
+
Example import map:
|
|
105
|
+
```html
|
|
106
|
+
<script type="importmap">
|
|
107
|
+
{
|
|
108
|
+
"imports": {
|
|
109
|
+
"@jphil/bookwhen-client": "/node_modules/@jphil/bookwhen-client/dist/index.es.js",
|
|
110
|
+
"axios": "/node_modules/axios/dist/esm/axios.js",
|
|
111
|
+
"zod": "/node_modules/zod/lib/index.mjs"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
</script>
|
|
115
|
+
<script type="module">
|
|
116
|
+
import { createBookwhenClient } from '@jphil/bookwhen-client';
|
|
117
|
+
// ...
|
|
118
|
+
</script>
|
|
119
|
+
```
|
|
120
|
+
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
|
+
|
|
122
|
+
### Important Note on API Keys in Client-Side Usage
|
|
123
|
+
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.
|
|
124
|
+
- 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
|
+
- This library enables access to Bookwhen API endpoints based on the permissions granted to the API key you provide.
|
|
126
|
+
|
|
127
|
+
## Error Handling
|
|
128
|
+
|
|
129
|
+
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:
|
|
130
|
+
|
|
131
|
+
- `code`: An error code string identifying the type of error (e.g., `NETWORK_ERROR`, `API_ERROR`).
|
|
132
|
+
- `message`: A human-readable description of the error.
|
|
133
|
+
- `isBrowser`: A boolean indicating if the error occurred in a browser environment.
|
|
134
|
+
- `context`: An object containing additional details, which may include the original error, status codes, etc.
|
|
135
|
+
- `timestamp`: The time the error occurred.
|
|
136
|
+
|
|
137
|
+
### Error Types
|
|
138
|
+
- `NETWORK_ERROR`: Indicates a failure in API communication (e.g., DNS resolution, connection refused).
|
|
139
|
+
- `SECURITY_ERROR`: Specific to browsers, indicates security restrictions prevented API access (e.g., CORS issues not handled by the server, mixed content).
|
|
140
|
+
- `API_ERROR`: The Bookwhen API returned an error response (e.g., 4xx or 5xx status code). The `context` may include `statusCode` and `responseData`.
|
|
141
|
+
- `CONFIG_ERROR`: The client was configured incorrectly (e.g., missing API key).
|
|
142
|
+
- `UNKNOWN_ERROR`: An unexpected error occurred within the library.
|
|
143
|
+
|
|
144
|
+
Example:
|
|
145
|
+
```typescript
|
|
146
|
+
try {
|
|
147
|
+
await client.events.getById({eventId: 'invalid-id'});
|
|
148
|
+
} catch (error: any) { // It's good practice to type the error if you have custom error types defined
|
|
149
|
+
console.error(`Error Code: ${error.code}`);
|
|
150
|
+
console.error(`Message: ${error.message}`);
|
|
151
|
+
if (error.code === 'API_ERROR') {
|
|
152
|
+
console.error('API Error Details:', error.context?.responseData);
|
|
153
|
+
} else if (error.code === 'NETWORK_ERROR') {
|
|
154
|
+
// Handle network issues, maybe retry or inform user
|
|
155
|
+
}
|
|
156
|
+
// Other error handling...
|
|
157
|
+
}
|
|
158
|
+
```
|
|
73
159
|
|
|
74
160
|
## Configuration
|
|
75
161
|
|
|
76
|
-
Required configuration
|
|
162
|
+
Required configuration:
|
|
77
163
|
|
|
78
164
|
- **apiKey**: Your Bookwhen API key (required)
|
|
79
165
|
|
|
@@ -85,6 +171,42 @@ API keys can be generated in the [API tokens setup area of your Bookwhen account
|
|
|
85
171
|
|
|
86
172
|
Please see the docs in the CONTRIBUTIONS.md file, thanks!
|
|
87
173
|
|
|
174
|
+
## Mainainter release process
|
|
175
|
+
|
|
176
|
+
[refining]
|
|
177
|
+
|
|
178
|
+
From main branch on local:
|
|
179
|
+
- Pull latest code
|
|
180
|
+
- git checkout -b some-new-branch
|
|
181
|
+
- git commit -m 'feat(context): my latest work on feature x'
|
|
182
|
+
- git push, copy URL
|
|
183
|
+
|
|
184
|
+
On github
|
|
185
|
+
> Open PR on github
|
|
186
|
+
> Perfect, merge when checks pass
|
|
187
|
+
|
|
188
|
+
On local:
|
|
189
|
+
- checkout main
|
|
190
|
+
- git pull
|
|
191
|
+
- git branch -d release (so we have a clean release branch)
|
|
192
|
+
- git checkout -b release
|
|
193
|
+
- pnpm changeset (provide changelog message, commit will occur after)
|
|
194
|
+
- pnpm changeset version (bumps version numbers, and updates changelog, and commits >>> note new version number)
|
|
195
|
+
- git push
|
|
196
|
+
|
|
197
|
+
On github:
|
|
198
|
+
- Open PR main <- release on github
|
|
199
|
+
> Perfect, merge when checks pass (check why no build)
|
|
200
|
+
|
|
201
|
+
On local:
|
|
202
|
+
- git checkout main
|
|
203
|
+
- git tag -a vx.x.x -m 'release vx.x.x'
|
|
204
|
+
- git push origin vx.x.x <<<< RELEASE to github and NPM
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
88
210
|
## Roadmap
|
|
89
211
|
|
|
90
212
|
- Proceed towards a 1.0.0 with community feedback.
|
|
@@ -92,9 +214,7 @@ Please see the docs in the CONTRIBUTIONS.md file, thanks!
|
|
|
92
214
|
|
|
93
215
|
### Todos
|
|
94
216
|
|
|
95
|
-
|
|
96
|
-
- [] put Zod in place in more areas to strengthen runtime type guards
|
|
97
|
-
- [] write services for the other models in the API
|
|
217
|
+
@see the issue queue.
|
|
98
218
|
|
|
99
219
|
## License
|
|
100
220
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export
|
|
3
|
-
export { createBookwhenClient } from './client/BookwhenClient.js';
|
|
1
|
+
export * from './src/index'
|
|
2
|
+
export {}
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function handleServiceHTTPErrors(error, statusCodes, methodErrors = {}) {
|
|
5
|
+
if (error.response) {
|
|
6
|
+
const status = error.response.status;
|
|
7
|
+
const errorMessage = methodErrors[status]?.message || statusCodes[status]?.message || `Unhandled service error with status code: ${status}`;
|
|
8
|
+
throw new Error(errorMessage);
|
|
9
|
+
}
|
|
10
|
+
throw new Error("An unexpected network or client error occurred");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const CLIENT_HTTP_STATUS_CODES = {
|
|
14
|
+
400: { code: 400, message: "BookwhenClient: Bad request" },
|
|
15
|
+
401: { code: 401, message: "BookwhenClient: Unauthorized - check your API key" },
|
|
16
|
+
403: { code: 403, message: "BookwhenClient: Forbidden - check your permissions" },
|
|
17
|
+
500: { code: 500, message: "BookwhenClient: Internal server error" },
|
|
18
|
+
502: { code: 502, message: "BookwhenClient: Bad gateway" },
|
|
19
|
+
503: { code: 503, message: "BookwhenClient: Service unavailable" },
|
|
20
|
+
504: { code: 504, message: "BookwhenClient: Gateway timeout" }
|
|
21
|
+
};
|
|
22
|
+
const SERVICE_HTTP_STATUS_CODES = {
|
|
23
|
+
400: { code: 400, message: "BookwhenClient: Bad request" },
|
|
24
|
+
404: { code: 404, message: "BookwhenClient: The requested resource could not be found" },
|
|
25
|
+
429: { code: 429, message: "BookwhenClient: Rate limit exceeded" }
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
class BookwhenRequest {
|
|
29
|
+
path = "";
|
|
30
|
+
filters = [];
|
|
31
|
+
includes = [];
|
|
32
|
+
constructor(path) {
|
|
33
|
+
try {
|
|
34
|
+
if (!path) {
|
|
35
|
+
throw new Error("Path is required");
|
|
36
|
+
}
|
|
37
|
+
this.path = path;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw new Error("BookwhenQuery error: " + error.message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Adds filters to the BookwhenQuery object.
|
|
44
|
+
* @param filters - An array of key-value pairs representing the filters to be added.
|
|
45
|
+
*
|
|
46
|
+
* Example resultant query strings:
|
|
47
|
+
* /v2/events?filter[from]=20200401&filter[to]=20200404
|
|
48
|
+
* /v2/events?filter[tag]=tag%20one,tag%20two
|
|
49
|
+
* /v2/events?filter[title]=advanced,pro&filter[detail]=masterclass
|
|
50
|
+
*
|
|
51
|
+
* @see https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml
|
|
52
|
+
*
|
|
53
|
+
* @returns The updated BookwhenQuery object.
|
|
54
|
+
*/
|
|
55
|
+
addFilters(filters) {
|
|
56
|
+
try {
|
|
57
|
+
for (let key in filters) {
|
|
58
|
+
let value = filters[key];
|
|
59
|
+
if (Array.isArray(value) && value && value.length > 0) {
|
|
60
|
+
const encodedValues = value.filter((v) => typeof v === "string" && v.length > 0).map((v) => encodeURIComponent(v)).join(",");
|
|
61
|
+
this.filters.push(`filter[${encodeURIComponent(key)}]=${encodedValues}`);
|
|
62
|
+
} else if (typeof value === "string" && value !== "") {
|
|
63
|
+
if (key.length === 0) {
|
|
64
|
+
throw new Error("Invalid filter key" + key);
|
|
65
|
+
}
|
|
66
|
+
this.filters.push(`filter[${encodeURIComponent(key)}]=${encodeURIComponent(value)}`);
|
|
67
|
+
} else if (typeof value === "undefined" && value !== "") {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw new Error("BookwhenQuery error: " + error.message);
|
|
72
|
+
}
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Adds an include query parameter to the BookwhenRequest object.
|
|
77
|
+
* @param includes - An array of strings representing the resources to include.
|
|
78
|
+
*
|
|
79
|
+
* @returns The updated BookwhenRequest object.
|
|
80
|
+
*
|
|
81
|
+
* @throws Error if any include is not a valid string.
|
|
82
|
+
*/
|
|
83
|
+
addIncludes(includes) {
|
|
84
|
+
try {
|
|
85
|
+
const validIncludes = includes.filter((include) => include.length > 0);
|
|
86
|
+
if (validIncludes.length !== includes.length) {
|
|
87
|
+
throw new Error("Invalid includes");
|
|
88
|
+
}
|
|
89
|
+
if (validIncludes.length > 0) {
|
|
90
|
+
const includeQuery = validIncludes.join(",");
|
|
91
|
+
this.includes.push(`include=${includeQuery}`);
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {
|
|
94
|
+
throw new Error("BookwhenQuery error: " + error.message);
|
|
95
|
+
}
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Does the actual work of putting together a valid query string given:
|
|
100
|
+
* - filters
|
|
101
|
+
* - includes
|
|
102
|
+
* - segments
|
|
103
|
+
*
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
build() {
|
|
107
|
+
let queryString = "";
|
|
108
|
+
if (this.filters.length > 0) {
|
|
109
|
+
queryString += this.filters.join("&");
|
|
110
|
+
}
|
|
111
|
+
if (this.includes.length > 0) {
|
|
112
|
+
queryString += queryString ? "&" : "";
|
|
113
|
+
queryString += this.includes.join("&");
|
|
114
|
+
}
|
|
115
|
+
const cleanedPath = this.path.replace(/^\/+/, "");
|
|
116
|
+
return `/${cleanedPath}${queryString ? "?" + queryString : ""}`;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @returns the constructed query string
|
|
120
|
+
*/
|
|
121
|
+
toString() {
|
|
122
|
+
return this.build();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const EventResourceSchema = z.enum(["location", "attachments", "tickets", "tickets.events", "tickets.class_passes"]);
|
|
127
|
+
const GetEventByIdParamsSchema = z.object({
|
|
128
|
+
eventId: z.string().min(1, "Invalid event ID"),
|
|
129
|
+
includes: EventResourceSchema.array().optional()
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
class EventService {
|
|
133
|
+
axiosInstance;
|
|
134
|
+
/**
|
|
135
|
+
* Initializes EventService with an Axios instance for dependency injection.
|
|
136
|
+
* @param axiosInstance - The Axios instance to use for API requests.
|
|
137
|
+
*/
|
|
138
|
+
constructor(axiosInstance) {
|
|
139
|
+
this.axiosInstance = axiosInstance;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves a single event by its ID from the Bookwhen API.
|
|
143
|
+
*
|
|
144
|
+
* @param {Object} param - The parameters for retrieving an event.
|
|
145
|
+
* @param {string} param.eventId - The ID of the event to retrieve.
|
|
146
|
+
* @param {string} [param.include] - Optional parameter to include additional data.
|
|
147
|
+
* @returns {Promise<BookwhenEvent>} A Promise that resolves to the BookwhenEvent object.
|
|
148
|
+
*/
|
|
149
|
+
async getById(params) {
|
|
150
|
+
try {
|
|
151
|
+
const validParams = GetEventByIdParamsSchema.parse(params);
|
|
152
|
+
const query = new BookwhenRequest(`/events/${validParams.eventId}`);
|
|
153
|
+
if (validParams.includes) {
|
|
154
|
+
query.addIncludes(validParams.includes);
|
|
155
|
+
}
|
|
156
|
+
const response = await this.axiosInstance.get(`${query}`);
|
|
157
|
+
return response.data?.data;
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (error instanceof z.ZodError) {
|
|
160
|
+
const errorMessages = error.errors.map((e) => e.message).join(", ");
|
|
161
|
+
throw new Error(`events.getById: Schema Validation failed: ${errorMessages}`);
|
|
162
|
+
} else {
|
|
163
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES, {
|
|
164
|
+
404: {
|
|
165
|
+
code: 404,
|
|
166
|
+
message: "Event not found. Please check the event ID and try again."
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Retrieves multiple events based on filtering and pagination parameters.
|
|
174
|
+
*
|
|
175
|
+
* @param {GetMultipleEventsParams} params - Optional parameters for filtering and pagination.
|
|
176
|
+
* @return {Promise<BookwhenEvent[]>} A Promise that resolves to an array of BookwhenEvent objects.
|
|
177
|
+
*/
|
|
178
|
+
async getMultiple(params = {}) {
|
|
179
|
+
try {
|
|
180
|
+
const query = new BookwhenRequest("/events");
|
|
181
|
+
if (params.includes) query.addIncludes(params.includes);
|
|
182
|
+
if (params.filters) query.addFilters(params.filters);
|
|
183
|
+
const response = await this.axiosInstance.get(`${query}`);
|
|
184
|
+
return response.data.data;
|
|
185
|
+
} catch (error) {
|
|
186
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
class BookwhenClient {
|
|
192
|
+
/**
|
|
193
|
+
* Creates a new instance of the BookwhenClient class.
|
|
194
|
+
* @param axiosInstance - Configured Axios instance for making HTTP requests.
|
|
195
|
+
* @throws Error if axiosInstance is not provided.
|
|
196
|
+
*/
|
|
197
|
+
constructor(axiosInstance) {
|
|
198
|
+
this.axiosInstance = axiosInstance;
|
|
199
|
+
this.isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
200
|
+
if (!axiosInstance) {
|
|
201
|
+
throw new Error("BookwhenClient - you must provide an axios instance");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
eventService;
|
|
205
|
+
isBrowser;
|
|
206
|
+
/**
|
|
207
|
+
* Gets the EventService instance.
|
|
208
|
+
*
|
|
209
|
+
* Available methods:
|
|
210
|
+
* - getById(params: GetEventByIdParams): Promise<BookwhenEvent>
|
|
211
|
+
* - getMultiple(params: GetMultipleEventsParams): Promise<BookwhenEvent[]>
|
|
212
|
+
*
|
|
213
|
+
* @returns The EventService instance.
|
|
214
|
+
*/
|
|
215
|
+
get events() {
|
|
216
|
+
if (!this.eventService) {
|
|
217
|
+
this.eventService = new EventService(this.axiosInstance);
|
|
218
|
+
}
|
|
219
|
+
return this.eventService;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function createBookwhenClient(options) {
|
|
223
|
+
const { apiKey, baseURL = "https://api.bookwhen.com/v2", debug = false } = options;
|
|
224
|
+
const axiosInstance = axios.create({
|
|
225
|
+
baseURL,
|
|
226
|
+
auth: { username: apiKey, password: "" }
|
|
227
|
+
});
|
|
228
|
+
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
|
|
229
|
+
axiosInstance.defaults.withCredentials = true;
|
|
230
|
+
}
|
|
231
|
+
axiosInstance.interceptors.response.use(
|
|
232
|
+
(response) => response,
|
|
233
|
+
(error) => {
|
|
234
|
+
if (error.response) {
|
|
235
|
+
const status = error.response.status;
|
|
236
|
+
const clientError = CLIENT_HTTP_STATUS_CODES[status];
|
|
237
|
+
if (clientError) {
|
|
238
|
+
return Promise.reject(new Error(clientError.message));
|
|
239
|
+
}
|
|
240
|
+
} else if (error.request) {
|
|
241
|
+
throw new Error("No response received from the server");
|
|
242
|
+
} else {
|
|
243
|
+
throw new Error("An error occurred setting up the request");
|
|
244
|
+
}
|
|
245
|
+
return Promise.reject(error);
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
if (debug) {
|
|
249
|
+
axiosInstance.interceptors.request.use((request) => {
|
|
250
|
+
console.log("Bookwhen Request Debug:", {
|
|
251
|
+
request
|
|
252
|
+
});
|
|
253
|
+
return request;
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return new BookwhenClient(axiosInstance);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export { createBookwhenClient };
|
|
260
|
+
//# sourceMappingURL=index.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/utils/http-utils.ts","../src/request/httpStatusCodes.ts","../src/request/BookwhenRequest.ts","../src/services/event/EventSchemas.ts","../src/services/event/Event.ts","../src/client/BookwhenClient.ts"],"sourcesContent":["import { AxiosError } from 'axios';\nimport type { BookwhenError, HttpStatus } from '../types/GlobalTypes.js';\n\nexport function handleApiError(error: unknown, isBrowser: boolean): BookwhenError {\n const timestamp = Date.now();\n \n // Handle Axios errors\n if (error instanceof AxiosError) {\n return {\n code: 'NETWORK_ERROR',\n message: isBrowser \n ? 'Failed to communicate with Bookwhen API'\n : `Network error: ${error.message}`,\n isBrowser,\n context: { timestamp }\n };\n }\n\n // Handle browser security errors\n if (isBrowser && (error instanceof DOMException || (error instanceof Error && error.name === 'SecurityError'))) {\n return {\n code: 'SECURITY_ERROR',\n message: 'Browser security restriction prevented API access',\n isBrowser: true,\n context: isBrowser ? {\n browser: {\n isSecure: typeof window !== 'undefined' ? window.isSecureContext : undefined,\n userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined\n },\n timestamp\n } : { timestamp }\n };\n }\n\n // Fallback for unknown errors\n return {\n code: 'UNKNOWN_ERROR',\n message: isBrowser \n ? 'An unexpected error occurred'\n : String(error),\n isBrowser,\n context: { timestamp }\n };\n}\n\n// Keep existing error handler for backwards compatibility\nexport function handleServiceHTTPErrors(error: any, statusCodes: Record<number, HttpStatus>, methodErrors: Record<number, HttpStatus> = {}): never {\n if (error.response) {\n const status = error.response.status;\n const errorMessage = methodErrors[status]?.message || statusCodes[status]?.message || `Unhandled service error with status code: ${status}`;\n throw new Error(errorMessage);\n }\n throw new Error(\"An unexpected network or client error occurred\");\n}\n","import type { HttpStatus } from '../types/GlobalTypes.js';\n\nexport const CLIENT_HTTP_STATUS_CODES: Record<number, HttpStatus> = {\n 400: { code: 400, message: 'BookwhenClient: Bad request' },\n 401: { code: 401, message: 'BookwhenClient: Unauthorized - check your API key' },\n 403: { code: 403, message: 'BookwhenClient: Forbidden - check your permissions' },\n 500: { code: 500, message: 'BookwhenClient: Internal server error' },\n 502: { code: 502, message: 'BookwhenClient: Bad gateway' },\n 503: { code: 503, message: 'BookwhenClient: Service unavailable' },\n 504: { code: 504, message: 'BookwhenClient: Gateway timeout' },\n};\n\nexport const SERVICE_HTTP_STATUS_CODES: Record<number, HttpStatus> = {\n 400: { code: 400, message: 'BookwhenClient: Bad request' },\n 404: { code: 404, message: 'BookwhenClient: The requested resource could not be found' },\n 429: { code: 429, message: 'BookwhenClient: Rate limit exceeded' },\n};","import type { Resources, Filters } from \"../types/GlobalTypes.js\";\nimport z from 'zod';\n\n/**\n * QueryBuilder class to help build query strings for Bookwhen API requests.\n */\nexport class BookwhenRequest {\n \n private path: string = '';\n private filters: string[] = [];\n private includes: string[] = [];\n \n constructor(path: string) {\n try {\n if (!path) {\n throw new Error('Path is required');\n }\n this.path = path;\n } catch (error) {\n throw new Error(\"BookwhenQuery error: \" + (error as Error).message);\n } \n }\n\n /**\n * Adds filters to the BookwhenQuery object.\n * @param filters - An array of key-value pairs representing the filters to be added.\n * \n * Example resultant query strings: \n * /v2/events?filter[from]=20200401&filter[to]=20200404\n * /v2/events?filter[tag]=tag%20one,tag%20two\n * /v2/events?filter[title]=advanced,pro&filter[detail]=masterclass\n * \n * @see https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml\n * \n * @returns The updated BookwhenQuery object.\n */\n public addFilters(filters: Filters): BookwhenRequest {\n // @todo add zod validation for filters?\n try {\n for (let key in filters) {\n let value = filters[key];\n if (Array.isArray(value) && value && value.length > 0) {\n const encodedValues = value\n .filter((v: string) => typeof v === 'string' && v.length > 0)\n .map((v: string) => encodeURIComponent(v))\n .join(',');\n\n this.filters.push(`filter[${encodeURIComponent(key)}]=${encodedValues}`);\n } else if (typeof value === 'string' && value !== '') {\n if (key.length === 0) {\n throw new Error('Invalid filter key' + key);\n }\n this.filters.push(`filter[${encodeURIComponent(key)}]=${encodeURIComponent(value)}`)\n } else if (typeof value === 'undefined' && value !== '') {\n // ignore undefined values\n }\n }\n } catch (error) {\n throw new Error(\"BookwhenQuery error: \" + (error as Error).message);\n }\n return this;\n }\n\n /**\n * Adds an include query parameter to the BookwhenRequest object.\n * @param includes - An array of strings representing the resources to include.\n * \n * @returns The updated BookwhenRequest object.\n * \n * @throws Error if any include is not a valid string.\n */\n public addIncludes(includes: Resources): BookwhenRequest {\n try {\n const validIncludes = includes.filter((include: string) => include.length > 0);\n if (validIncludes.length !== includes.length) {\n throw new Error('Invalid includes');\n }\n if (validIncludes.length > 0) {\n const includeQuery = validIncludes.join(',');\n this.includes.push(`include=${includeQuery}`);\n }\n } catch (error) {\n throw new Error(\"BookwhenQuery error: \" + (error as Error).message);\n }\n return this;\n }\n\n /**\n * Does the actual work of putting together a valid query string given:\n * - filters\n * - includes\n * - segments\n * \n * @returns \n */\n build(): string {\n let queryString = '';\n \n // Concatenate filters and includes, if any\n if (this.filters.length > 0) {\n queryString += this.filters.join('&');\n }\n if (this.includes.length > 0) {\n // Add '&' if filters already added to queryString\n queryString += queryString ? '&' : '';\n queryString += this.includes.join('&');\n }\n \n // Strip any leading slashes from this.path\n const cleanedPath = this.path.replace(/^\\/+/, '');\n \n // Return the full URI, including query string only if it's non-empty\n return `/${cleanedPath}${queryString ? '?' + queryString : ''}`;\n }\n\n /**\n * @returns the constructed query string\n */\n toString(): string {\n return this.build();\n }\n}\n","import { z } from 'zod';\n\nexport const EventResourceSchema = z.enum(['location', 'attachments', 'tickets', 'tickets.events', 'tickets.class_passes']);\n\n// Define GetEventByIdParams schema\nexport const GetEventByIdParamsSchema = z.object({\n eventId: z.string().min(1, 'Invalid event ID'),\n includes: EventResourceSchema.array().optional(),\n});\n","// src/services/EventService.ts\nimport type { IEventService, GetMultipleEventsParams, GetEventByIdParams } from './EventInterfaces.js';\nimport type { EventsResponse, EventResponse, BookwhenEvent } from './EventTypes.js';\nimport { handleServiceHTTPErrors } from '../../utils/http-utils.js';\nimport { SERVICE_HTTP_STATUS_CODES } from '../../request/httpStatusCodes.js'; \nimport { BookwhenRequest } from '../../request/BookwhenRequest.js';\nimport type { AxiosInstance } from 'axios';\nimport { GetEventByIdParamsSchema } from './EventSchemas.js';\nimport { z } from 'zod';\n\n/**\n * Service class for managing events in the Bookwhen API.\n */\nexport class EventService implements IEventService {\n\n private axiosInstance: AxiosInstance;\n\n /**\n * Initializes EventService with an Axios instance for dependency injection.\n * @param axiosInstance - The Axios instance to use for API requests.\n */\n constructor(axiosInstance: AxiosInstance) {\n this.axiosInstance = axiosInstance;\n }\n\n /**\n * Retrieves a single event by its ID from the Bookwhen API.\n * \n * @param {Object} param - The parameters for retrieving an event.\n * @param {string} param.eventId - The ID of the event to retrieve.\n * @param {string} [param.include] - Optional parameter to include additional data.\n * @returns {Promise<BookwhenEvent>} A Promise that resolves to the BookwhenEvent object.\n */\n async getById(params: z.infer<typeof GetEventByIdParamsSchema>): Promise<BookwhenEvent> {\n try {\n const validParams = GetEventByIdParamsSchema.parse(params);\n\n const query = new BookwhenRequest(`/events/${validParams.eventId}`);\n if (validParams.includes) {\n query.addIncludes(validParams.includes);\n }\n\n const response = await this.axiosInstance.get<EventResponse>(`${query}`);\n return response.data?.data;\n } catch (error) {\n if (error instanceof z.ZodError) {\n const errorMessages = error.errors.map(e => e.message).join(', ');\n throw new Error(`events.getById: Schema Validation failed: ${errorMessages}`);\n } else {\n handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES, {\n 404: {\n code: 404,\n message: 'Event not found. Please check the event ID and try again.',\n },\n });\n }\n }\n }\n\n /**\n * Retrieves multiple events based on filtering and pagination parameters.\n * \n * @param {GetMultipleEventsParams} params - Optional parameters for filtering and pagination.\n * @return {Promise<BookwhenEvent[]>} A Promise that resolves to an array of BookwhenEvent objects.\n */\n async getMultiple(params: GetMultipleEventsParams = {}): Promise<BookwhenEvent[]> {\n try {\n const query = new BookwhenRequest('/events');\n if (params.includes) query.addIncludes(params.includes);\n if (params.filters) query.addFilters(params.filters);\n\n const response = await this.axiosInstance.get<EventsResponse>(`${query}`); // uses the toString method\n return response.data.data;\n } catch (error) {\n handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES);\n }\n }\n}\n","// src/clients/BookwhenClient.ts\nimport axios from 'axios';\nimport type { AxiosInstance } from 'axios';\nimport { EventService } from '../services/event/Event.js'; // Ensure this file and class are setup accordingly\nimport { CLIENT_HTTP_STATUS_CODES } from '../request/httpStatusCodes.js';\n\n/**\n * Client for the Bookwhen API.\n * \n * @see https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml#/ClassPass/get_class_passes__class_pass_id_\n */\nexport class BookwhenClient {\n private eventService?: EventService;\n private readonly isBrowser: boolean;\n\n /**\n * Creates a new instance of the BookwhenClient class.\n * @param axiosInstance - Configured Axios instance for making HTTP requests.\n * @throws Error if axiosInstance is not provided.\n */\n constructor(private axiosInstance: AxiosInstance) {\n this.isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\n if (!axiosInstance) {\n throw new Error('BookwhenClient - you must provide an axios instance');\n }\n }\n\n /** \n * Gets the EventService instance.\n * \n * Available methods:\n * - getById(params: GetEventByIdParams): Promise<BookwhenEvent>\n * - getMultiple(params: GetMultipleEventsParams): Promise<BookwhenEvent[]>\n * \n * @returns The EventService instance.\n */\n get events(): EventService {\n if (!this.eventService) {\n this.eventService = new EventService(this.axiosInstance);\n }\n return this.eventService;\n }\n}\n\ninterface BookwhenClientOptions {\n apiKey: string;\n baseURL?: string;\n debug?: boolean;\n}\n\n/**\n * Creates an instance of Axios with the provided API key.\n * @param apiKey - The API key used for authentication.\n * @returns The Axios instance.\n */\nexport function createBookwhenClient(options: BookwhenClientOptions): BookwhenClient {\n const { apiKey, baseURL = 'https://api.bookwhen.com/v2', debug = false } = options;\n\n const axiosInstance = axios.create({\n baseURL: baseURL,\n auth: { username: apiKey, password: '' },\n });\n\n if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {\n axiosInstance.defaults.withCredentials = true;\n }\n\n axiosInstance.interceptors.response.use(\n (response) => response,\n (error) => {\n if (error.response) {\n const status = error.response.status;\n const clientError = CLIENT_HTTP_STATUS_CODES[status];\n if (clientError) {\n return Promise.reject(new Error(clientError.message));\n }\n } else if (error.request) {\n throw new Error('No response received from the server');\n } else {\n throw new Error('An error occurred setting up the request');\n }\n return Promise.reject(error);\n },\n );\n\n if(debug) {\n // Add a request interceptor to log the details\n axiosInstance.interceptors.request.use(request => {\n console.log('Bookwhen Request Debug:', {\n request: request\n });\n return request;\n });\n }\n\n return new BookwhenClient(axiosInstance);\n}\n"],"names":[],"mappings":";;;AA8CO,SAAS,uBAAwB,CAAA,KAAA,EAAY,WAAyC,EAAA,YAAA,GAA2C,EAAW,EAAA;AACjJ,EAAA,IAAI,MAAM,QAAU,EAAA;AAClB,IAAM,MAAA,MAAA,GAAS,MAAM,QAAS,CAAA,MAAA,CAAA;AAC9B,IAAM,MAAA,YAAA,GAAe,YAAa,CAAA,MAAM,CAAG,EAAA,OAAA,IAAW,YAAY,MAAM,CAAA,EAAG,OAAW,IAAA,CAAA,0CAAA,EAA6C,MAAM,CAAA,CAAA,CAAA;AACzI,IAAM,MAAA,IAAI,MAAM,YAAY,CAAA,CAAA;AAAA,GAC9B;AACA,EAAM,MAAA,IAAI,MAAM,gDAAgD,CAAA,CAAA;AAClE;;ACnDO,MAAM,wBAAuD,GAAA;AAAA,EAClE,GAAK,EAAA,EAAE,IAAM,EAAA,GAAA,EAAK,SAAS,6BAA8B,EAAA;AAAA,EACzD,GAAK,EAAA,EAAE,IAAM,EAAA,GAAA,EAAK,SAAS,mDAAoD,EAAA;AAAA,EAC/E,GAAK,EAAA,EAAE,IAAM,EAAA,GAAA,EAAK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c,yBAAyB,MAAM,CAAA,CAAA;AACnD,QAAA,IAAI,WAAa,EAAA;AACf,UAAA,OAAO,QAAQ,MAAO,CAAA,IAAI,KAAM,CAAA,WAAA,CAAY,OAAO,CAAC,CAAA,CAAA;AAAA,SACtD;AAAA,OACF,MAAA,IAAW,MAAM,OAAS,EAAA;AACxB,QAAM,MAAA,IAAI,MAAM,sCAAsC,CAAA,CAAA;AAAA,OACjD,MAAA;AACL,QAAM,MAAA,IAAI,MAAM,0CAA0C,CAAA,CAAA;AAAA,OAC5D;AACA,MAAO,OAAA,OAAA,CAAQ,OAAO,KAAK,CAAA,CAAA;AAAA,KAC7B;AAAA,GACF,CAAA;AAEA,EAAA,IAAG,KAAO,EAAA;AAER,IAAc,aAAA,CAAA,YAAA,CAAa,OAAQ,CAAA,GAAA,CAAI,CAAW,OAAA,KAAA;AAChD,MAAA,OAAA,CAAQ,IAAI,yBAA2B,EAAA;AAAA,QACrC,OAAA;AAAA,OACD,CAAA,CAAA;AACD,MAAO,OAAA,OAAA,CAAA;AAAA,KACR,CAAA,CAAA;AAAA,GACH;AAEA,EAAO,OAAA,IAAI,eAAe,aAAa,CAAA,CAAA;AACzC;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
2
|
import { EventService } from '../services/event/Event.js';
|
|
3
3
|
/**
|
|
4
4
|
* Client for the Bookwhen API.
|
|
@@ -8,6 +8,7 @@ import { EventService } from '../services/event/Event.js';
|
|
|
8
8
|
export declare class BookwhenClient {
|
|
9
9
|
private axiosInstance;
|
|
10
10
|
private eventService?;
|
|
11
|
+
private readonly isBrowser;
|
|
11
12
|
/**
|
|
12
13
|
* Creates a new instance of the BookwhenClient class.
|
|
13
14
|
* @param axiosInstance - Configured Axios instance for making HTTP requests.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { IEventService, GetMultipleEventsParams } from './EventInterfaces.js';
|
|
2
|
+
import { BookwhenEvent } from './EventTypes.js';
|
|
3
|
+
import { AxiosInstance } from 'axios';
|
|
4
4
|
import { GetEventByIdParamsSchema } from './EventSchemas.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
/**
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface HttpStatus {
|
|
2
|
+
code: number;
|
|
3
|
+
message: string;
|
|
4
|
+
}
|
|
5
|
+
export type Resource = string;
|
|
6
|
+
export type Resources = Resource[];
|
|
7
|
+
export interface Filters {
|
|
8
|
+
[key: string]: string | string[] | boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface BookwhenError {
|
|
11
|
+
code: 'NETWORK_ERROR' | 'SECURITY_ERROR' | 'API_ERROR' | 'CONFIG_ERROR' | 'UNKNOWN_ERROR';
|
|
12
|
+
message: string;
|
|
13
|
+
isBrowser: boolean;
|
|
14
|
+
context?: {
|
|
15
|
+
browser?: {
|
|
16
|
+
isSecure?: boolean;
|
|
17
|
+
userAgent?: string;
|
|
18
|
+
};
|
|
19
|
+
timestamp: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BookwhenError, HttpStatus } from '../types/GlobalTypes.js';
|
|
2
|
+
export declare function handleApiError(error: unknown, isBrowser: boolean): BookwhenError;
|
|
3
|
+
export declare function handleServiceHTTPErrors(error: any, statusCodes: Record<number, HttpStatus>, methodErrors?: Record<number, HttpStatus>): never;
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jphil/bookwhen-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "TypeScript client for the Bookwhen API (v2)",
|
|
5
5
|
"private": false,
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
8
9
|
"keywords": [
|
|
9
10
|
"bookwhen",
|
|
10
11
|
"booking",
|
|
@@ -34,6 +35,9 @@
|
|
|
34
35
|
"@changesets/cli": "^2.27.9",
|
|
35
36
|
"@commitlint/cli": "^19.5.0",
|
|
36
37
|
"@commitlint/config-conventional": "^19.5.0",
|
|
38
|
+
"@mswjs/data": "^0.16.2",
|
|
39
|
+
"@mswjs/http-middleware": "^0.10.3",
|
|
40
|
+
"@playwright/test": "^1.52.0",
|
|
37
41
|
"@types/node": "^22.9.0",
|
|
38
42
|
"@typescript-eslint/eslint-plugin": "^8.13.0",
|
|
39
43
|
"@typescript-eslint/parser": "^8.13.0",
|
|
@@ -45,34 +49,50 @@
|
|
|
45
49
|
"eslint": "^9.13.0",
|
|
46
50
|
"eslint-config-prettier": "^9.1.0",
|
|
47
51
|
"eslint-plugin-prettier": "^5.2.1",
|
|
52
|
+
"http-server": "^14.1.1",
|
|
48
53
|
"husky": "^9.1.6",
|
|
54
|
+
"msw": "^2.7.5",
|
|
55
|
+
"playwright": "^1.52.0",
|
|
56
|
+
"playwright-msw": "^3.0.1",
|
|
49
57
|
"prettier": "^3.3.3",
|
|
50
58
|
"tsup": "^8.3.4",
|
|
51
59
|
"typescript": "^5.6.3",
|
|
52
60
|
"vite": "^5.4.10",
|
|
61
|
+
"vite-plugin-dts": "^4.5.3",
|
|
53
62
|
"vite-tsconfig-paths": "^5.1.0",
|
|
54
|
-
"vitest": "^2.1.3"
|
|
63
|
+
"vitest": "^2.1.3",
|
|
64
|
+
"axios": "^1.7.7",
|
|
65
|
+
"zod": "^3.23.8"
|
|
55
66
|
},
|
|
56
67
|
"config": {
|
|
57
68
|
"commitizen": {
|
|
58
69
|
"path": "./node_modules/cz-conventional-changelog"
|
|
59
70
|
}
|
|
60
71
|
},
|
|
61
|
-
"
|
|
62
|
-
"axios": "^1.7.
|
|
63
|
-
"zod": "^3.23.
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"axios": "^1.7.0",
|
|
74
|
+
"zod": "^3.23.0"
|
|
64
75
|
},
|
|
76
|
+
"dependencies": {},
|
|
65
77
|
"exports": {
|
|
66
78
|
".": {
|
|
67
79
|
"types": "./dist/index.d.ts",
|
|
68
|
-
"
|
|
80
|
+
"browser": "./dist/index.es.js",
|
|
81
|
+
"node": "./dist/index.js",
|
|
82
|
+
"import": "./dist/index.es.js",
|
|
83
|
+
"default": "./dist/index.es.js"
|
|
69
84
|
}
|
|
70
85
|
},
|
|
86
|
+
"browser": "./dist/index.es.js",
|
|
71
87
|
"scripts": {
|
|
72
88
|
"dev": "vitest",
|
|
73
|
-
"
|
|
89
|
+
"preview": "vite preview --config vite.preview.config.ts",
|
|
90
|
+
"build": "vite build -c vite.library.config.ts",
|
|
91
|
+
"build:node": "vite build -c vite.test.config.ts",
|
|
74
92
|
"lint": "tsc",
|
|
75
93
|
"test": "vitest run",
|
|
94
|
+
"test:browser": "playwright test",
|
|
95
|
+
"test:node": "vitest run",
|
|
76
96
|
"coverage": "vitest run --coverage",
|
|
77
97
|
"type-check": "tsc --noEmit",
|
|
78
98
|
"check-exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// src/clients/BookwhenClient.ts
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import { EventService } from '../services/event/Event.js'; // Ensure this file and class are setup accordingly
|
|
4
|
-
import { CLIENT_HTTP_STATUS_CODES } from '../request/httpStatusCodes.js';
|
|
5
|
-
/**
|
|
6
|
-
* Client for the Bookwhen API.
|
|
7
|
-
*
|
|
8
|
-
* @see https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml#/ClassPass/get_class_passes__class_pass_id_
|
|
9
|
-
*/
|
|
10
|
-
export class BookwhenClient {
|
|
11
|
-
axiosInstance;
|
|
12
|
-
eventService;
|
|
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) {
|
|
19
|
-
this.axiosInstance = axiosInstance;
|
|
20
|
-
if (!axiosInstance) {
|
|
21
|
-
throw new Error('BookwhenClient - you must provide an axios instance');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Gets the EventService instance.
|
|
26
|
-
*
|
|
27
|
-
* Available methods:
|
|
28
|
-
* - getById(params: GetEventByIdParams): Promise<BookwhenEvent>
|
|
29
|
-
* - getMultiple(params: GetMultipleEventsParams): Promise<BookwhenEvent[]>
|
|
30
|
-
*
|
|
31
|
-
* @returns The EventService instance.
|
|
32
|
-
*/
|
|
33
|
-
get events() {
|
|
34
|
-
if (!this.eventService) {
|
|
35
|
-
this.eventService = new EventService(this.axiosInstance);
|
|
36
|
-
}
|
|
37
|
-
return this.eventService;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Creates an instance of Axios with the provided API key.
|
|
42
|
-
* @param apiKey - The API key used for authentication.
|
|
43
|
-
* @returns The Axios instance.
|
|
44
|
-
*/
|
|
45
|
-
export function createBookwhenClient(options) {
|
|
46
|
-
const { apiKey, baseURL = 'https://api.bookwhen.com/v2', debug = false } = options;
|
|
47
|
-
const axiosInstance = axios.create({
|
|
48
|
-
baseURL: baseURL,
|
|
49
|
-
auth: { username: apiKey, password: '' },
|
|
50
|
-
});
|
|
51
|
-
axiosInstance.interceptors.response.use((response) => response, (error) => {
|
|
52
|
-
if (error.response) {
|
|
53
|
-
const status = error.response.status;
|
|
54
|
-
const clientError = CLIENT_HTTP_STATUS_CODES[status];
|
|
55
|
-
if (clientError) {
|
|
56
|
-
return Promise.reject(new Error(clientError.message));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else if (error.request) {
|
|
60
|
-
throw new Error('No response received from the server');
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
throw new Error('An error occurred setting up the request');
|
|
64
|
-
}
|
|
65
|
-
return Promise.reject(error);
|
|
66
|
-
});
|
|
67
|
-
if (debug) {
|
|
68
|
-
// Add a request interceptor to log the details
|
|
69
|
-
axiosInstance.interceptors.request.use(request => {
|
|
70
|
-
console.log('Bookwhen Request Debug:', {
|
|
71
|
-
request: request
|
|
72
|
-
});
|
|
73
|
-
return request;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return new BookwhenClient(axiosInstance);
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=BookwhenClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BookwhenClient.js","sourceRoot":"","sources":["../../src/client/BookwhenClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC,CAAE,mDAAmD;AAC/G,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE;;;;GAIG;AACH,MAAM,OAAO,cAAc;IAQL;IAPZ,YAAY,CAAgB;IAEpC;;;;OAIG;IACH,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAC9C,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IAED;;;;;;;;OAQG;IACH,IAAI,MAAM;QACR,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF;AAQD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAA8B;IACjE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,6BAA6B,EAAE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js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,qCAAqC,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
/**
|
|
3
|
-
* QueryBuilder class to help build query strings for Bookwhen API requests.
|
|
4
|
-
*/
|
|
5
|
-
export class BookwhenRequest {
|
|
6
|
-
path = '';
|
|
7
|
-
filters = [];
|
|
8
|
-
includes = [];
|
|
9
|
-
constructor(path) {
|
|
10
|
-
try {
|
|
11
|
-
if (!path) {
|
|
12
|
-
throw new Error('Path is required');
|
|
13
|
-
}
|
|
14
|
-
this.path = path;
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
throw new Error("BookwhenQuery error: " + error.message);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Adds filters to the BookwhenQuery object.
|
|
22
|
-
* @param filters - An array of key-value pairs representing the filters to be added.
|
|
23
|
-
*
|
|
24
|
-
* Example resultant query strings:
|
|
25
|
-
* /v2/events?filter[from]=20200401&filter[to]=20200404
|
|
26
|
-
* /v2/events?filter[tag]=tag%20one,tag%20two
|
|
27
|
-
* /v2/events?filter[title]=advanced,pro&filter[detail]=masterclass
|
|
28
|
-
*
|
|
29
|
-
* @see https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml
|
|
30
|
-
*
|
|
31
|
-
* @returns The updated BookwhenQuery object.
|
|
32
|
-
*/
|
|
33
|
-
addFilters(filters) {
|
|
34
|
-
// @todo add zod validation for filters?
|
|
35
|
-
try {
|
|
36
|
-
for (let key in filters) {
|
|
37
|
-
let value = filters[key];
|
|
38
|
-
if (Array.isArray(value) && value && value.length > 0) {
|
|
39
|
-
const encodedValues = value
|
|
40
|
-
.filter((v) => typeof v === 'string' && v.length > 0)
|
|
41
|
-
.map((v) => encodeURIComponent(v))
|
|
42
|
-
.join(',');
|
|
43
|
-
this.filters.push(`filter[${encodeURIComponent(key)}]=${encodedValues}`);
|
|
44
|
-
}
|
|
45
|
-
else if (typeof value === 'string' && value !== '') {
|
|
46
|
-
if (key.length === 0) {
|
|
47
|
-
throw new Error('Invalid filter key' + key);
|
|
48
|
-
}
|
|
49
|
-
this.filters.push(`filter[${encodeURIComponent(key)}]=${encodeURIComponent(value)}`);
|
|
50
|
-
}
|
|
51
|
-
else if (typeof value === 'undefined' && value !== '') {
|
|
52
|
-
// ignore undefined values
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
throw new Error("BookwhenQuery error: " + error.message);
|
|
58
|
-
}
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Adds an include query parameter to the BookwhenRequest object.
|
|
63
|
-
* @param includes - An array of strings representing the resources to include.
|
|
64
|
-
*
|
|
65
|
-
* @returns The updated BookwhenRequest object.
|
|
66
|
-
*
|
|
67
|
-
* @throws Error if any include is not a valid string.
|
|
68
|
-
*/
|
|
69
|
-
addIncludes(includes) {
|
|
70
|
-
try {
|
|
71
|
-
const validIncludes = includes.filter((include) => include.length > 0);
|
|
72
|
-
if (validIncludes.length !== includes.length) {
|
|
73
|
-
throw new Error('Invalid includes');
|
|
74
|
-
}
|
|
75
|
-
if (validIncludes.length > 0) {
|
|
76
|
-
const includeQuery = validIncludes.join(',');
|
|
77
|
-
this.includes.push(`include=${includeQuery}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
throw new Error("BookwhenQuery error: " + error.message);
|
|
82
|
-
}
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Does the actual work of putting together a valid query string given:
|
|
87
|
-
* - filters
|
|
88
|
-
* - includes
|
|
89
|
-
* - segments
|
|
90
|
-
*
|
|
91
|
-
* @returns
|
|
92
|
-
*/
|
|
93
|
-
build() {
|
|
94
|
-
let queryString = '';
|
|
95
|
-
// Concatenate filters and includes, if any
|
|
96
|
-
if (this.filters.length > 0) {
|
|
97
|
-
queryString += this.filters.join('&');
|
|
98
|
-
}
|
|
99
|
-
if (this.includes.length > 0) {
|
|
100
|
-
// Add '&' if filters already added to queryString
|
|
101
|
-
queryString += queryString ? '&' : '';
|
|
102
|
-
queryString += this.includes.join('&');
|
|
103
|
-
}
|
|
104
|
-
// Strip any leading slashes from this.path
|
|
105
|
-
const cleanedPath = this.path.replace(/^\/+/, '');
|
|
106
|
-
// Return the full URI, including query string only if it's non-empty
|
|
107
|
-
return `/${cleanedPath}${queryString ? '?' + queryString : ''}`;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* @returns the constructed query string
|
|
111
|
-
*/
|
|
112
|
-
toString() {
|
|
113
|
-
return this.build();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=BookwhenRequest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BookwhenRequest.js","sourceRoot":"","sources":["../../src/request/BookwhenRequest.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB;;GAEG;AACH,MAAM,OAAO,eAAe;IAElB,IAAI,GAAW,EAAE,CAAC;IAClB,OAAO,GAAa,EAAE,CAAC;IACvB,QAAQ,GAAa,EAAE,CAAC;IAEhC,YAAY,IAAY;QACtB,IAAI,CAAC;YACH,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;YACtC,CAAC;YACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAI,KAAe,C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,IAAI,CAAC,GAAG,CAAC,CAAC;QACzC,CAAC;QAED,2CAA2C;QAC3C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAElD,qEAAqE;QACrE,OAAO,IAAI,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAClE,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const CLIENT_HTTP_STATUS_CODES = {
|
|
2
|
-
400: { code: 400, message: 'BookwhenClient: Bad request' },
|
|
3
|
-
401: { code: 401, message: 'BookwhenClient: Unauthorized - check your API key' },
|
|
4
|
-
403: { code: 403, message: 'BookwhenClient: Forbidden - check your permissions' },
|
|
5
|
-
500: { code: 500, message: 'BookwhenClient: Internal server error' },
|
|
6
|
-
502: { code: 502, message: 'BookwhenClient: Bad gateway' },
|
|
7
|
-
503: { code: 503, message: 'BookwhenClient: Service unavailable' },
|
|
8
|
-
504: { code: 504, message: 'BookwhenClient: Gateway timeout' },
|
|
9
|
-
};
|
|
10
|
-
export const SERVICE_HTTP_STATUS_CODES = {
|
|
11
|
-
400: { code: 400, message: 'BookwhenClient: Bad request' },
|
|
12
|
-
404: { code: 404, message: 'BookwhenClient: The requested resource could not be found' },
|
|
13
|
-
429: { code: 429, message: 'BookwhenClient: Rate limit exceeded' },
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=httpStatusCodes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"httpStatusCodes.js","sourceRoot":"","sources":["../../src/request/httpStatusCodes.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,wBAAwB,GAA+B;IAClE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,6BAA6B,EAAE;IAC1D,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,mDAAmD,EAAE;IAChF,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,oDAAoD,EAAE;IACjF,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,uCAAuC,EAAE;IACpE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,6BAA6B,EAAE;IAC1D,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,qCAAqC,EAAE;IAClE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,iCAAiC,EAAE;CAC/D,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAA+B;IACnE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,6BAA6B,EAAE;IAC1D,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,2DAA2D,EAAE;IACxF,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,qCAAqC,EAAE;CACnE,CAAC"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { handleServiceHTTPErrors } from '../../utils/http-utils.js';
|
|
2
|
-
import { SERVICE_HTTP_STATUS_CODES } from '../../request/httpStatusCodes.js';
|
|
3
|
-
import { BookwhenRequest } from '../../request/BookwhenRequest.js';
|
|
4
|
-
import { GetEventByIdParamsSchema } from './EventSchemas.js';
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
/**
|
|
7
|
-
* Service class for managing events in the Bookwhen API.
|
|
8
|
-
*/
|
|
9
|
-
export class EventService {
|
|
10
|
-
axiosInstance;
|
|
11
|
-
/**
|
|
12
|
-
* Initializes EventService with an Axios instance for dependency injection.
|
|
13
|
-
* @param axiosInstance - The Axios instance to use for API requests.
|
|
14
|
-
*/
|
|
15
|
-
constructor(axiosInstance) {
|
|
16
|
-
this.axiosInstance = axiosInstance;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves a single event by its ID from the Bookwhen API.
|
|
20
|
-
*
|
|
21
|
-
* @param {Object} param - The parameters for retrieving an event.
|
|
22
|
-
* @param {string} param.eventId - The ID of the event to retrieve.
|
|
23
|
-
* @param {string} [param.include] - Optional parameter to include additional data.
|
|
24
|
-
* @returns {Promise<BookwhenEvent>} A Promise that resolves to the BookwhenEvent object.
|
|
25
|
-
*/
|
|
26
|
-
async getById(params) {
|
|
27
|
-
try {
|
|
28
|
-
const validParams = GetEventByIdParamsSchema.parse(params);
|
|
29
|
-
const query = new BookwhenRequest(`/events/${validParams.eventId}`);
|
|
30
|
-
if (validParams.includes) {
|
|
31
|
-
query.addIncludes(validParams.includes);
|
|
32
|
-
}
|
|
33
|
-
const response = await this.axiosInstance.get(`${query}`);
|
|
34
|
-
return response.data?.data;
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
if (error instanceof z.ZodError) {
|
|
38
|
-
const errorMessages = error.errors.map(e => e.message).join(', ');
|
|
39
|
-
throw new Error(`events.getById: Schema Validation failed: ${errorMessages}`);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES, {
|
|
43
|
-
404: {
|
|
44
|
-
code: 404,
|
|
45
|
-
message: 'Event not found. Please check the event ID and try again.',
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Retrieves multiple events based on filtering and pagination parameters.
|
|
53
|
-
*
|
|
54
|
-
* @param {GetMultipleEventsParams} params - Optional parameters for filtering and pagination.
|
|
55
|
-
* @return {Promise<BookwhenEvent[]>} A Promise that resolves to an array of BookwhenEvent objects.
|
|
56
|
-
*/
|
|
57
|
-
async getMultiple(params = {}) {
|
|
58
|
-
try {
|
|
59
|
-
const query = new BookwhenRequest('/events');
|
|
60
|
-
if (params.includes)
|
|
61
|
-
query.addIncludes(params.includes);
|
|
62
|
-
if (params.filters)
|
|
63
|
-
query.addFilters(params.filters);
|
|
64
|
-
const response = await this.axiosInstance.get(`${query}`); // uses the toString method
|
|
65
|
-
return response.data.data;
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=Event.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Event.js","sourceRoot":"","sources":["../../../src/services/event/Event.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,OAAO,YAAY;IAEf,aAAa,CAAgB;IAErC;;;OAGG;IACH,YAAY,aAA4B;QACtC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CAAC,MAAgD;QAC5D,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,wBAAwB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAE3D,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,WAAW,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC;YACpE,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;gBACzB,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAC1C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,CAAC;QAC5D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventInterfaces.js","sourceRoot":"","sources":["../../../src/services/event/EventInterfaces.ts"],"names":[],"mappings":"AAqDC,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export const EventResourceSchema = z.enum(['location', 'attachments', 'tickets', 'tickets.events', 'tickets.class_passes']);
|
|
3
|
-
// Define GetEventByIdParams schema
|
|
4
|
-
export const GetEventByIdParamsSchema = z.object({
|
|
5
|
-
eventId: z.string().min(1, 'Invalid event ID'),
|
|
6
|
-
includes: EventResourceSchema.array().optional(),
|
|
7
|
-
});
|
|
8
|
-
//# sourceMappingURL=EventSchemas.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventSchemas.js","sourceRoot":"","sources":["../../../src/services/event/EventSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAE5H,mCAAmC;AACnC,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,kBAAkB,CAAC;IAC9C,QAAQ,EAAE,mBAAmB,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE;CACjD,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventTypes.js","sourceRoot":"","sources":["../../../src/services/event/EventTypes.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalTypes.js","sourceRoot":"","sources":["../../src/types/GlobalTypes.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { HttpStatus } from '../types/GlobalTypes.js';
|
|
2
|
-
/**
|
|
3
|
-
* Handles errors for service methods
|
|
4
|
-
* @param error The error object caught in service methods.
|
|
5
|
-
* @param statusCodes General service-level status codes and messages.
|
|
6
|
-
* @param methodErrors Optional method-specific error messages.
|
|
7
|
-
*/
|
|
8
|
-
export declare function handleServiceHTTPErrors(error: any, statusCodes: Record<number, HttpStatus>, methodErrors?: Record<number, HttpStatus>): never;
|
package/dist/utils/http-utils.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Handles errors for service methods
|
|
3
|
-
* @param error The error object caught in service methods.
|
|
4
|
-
* @param statusCodes General service-level status codes and messages.
|
|
5
|
-
* @param methodErrors Optional method-specific error messages.
|
|
6
|
-
*/
|
|
7
|
-
export function handleServiceHTTPErrors(error, statusCodes, methodErrors = {}) {
|
|
8
|
-
if (error.response) {
|
|
9
|
-
const status = error.response.status;
|
|
10
|
-
// First, check for method-specific errors, then fall back to general service errors
|
|
11
|
-
const errorMessage = methodErrors[status]?.message || statusCodes[status]?.message || `Unhandled service error with status code: ${status}`;
|
|
12
|
-
throw new Error(errorMessage);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
// If no response was received, this is likely a serious client or network issue
|
|
16
|
-
throw new Error("An unexpected network or client error occurred, with no response property.");
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=http-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-utils.js","sourceRoot":"","sources":["../../src/utils/http-utils.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAU,EAAE,WAAuC,EAAE,eAA2C,EAAE;IACxI,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjB,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrC,oFAAoF;QACpF,MAAM,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,IAAI,6CAA6C,MAAM,EAAE,CAAC;QAC5I,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACJ,gFAAgF;QAChF,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;IAClG,CAAC;AACH,CAAC"}
|
|
File without changes
|
|
File without changes
|