@jphil/bookwhen-client 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jphil/bookwhen-client",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "TypeScript client for the Bookwhen API (v2)",
|
|
5
5
|
"private": false,
|
|
6
|
+
"type": "module",
|
|
6
7
|
"main": "./dist/index.js",
|
|
7
8
|
"module": "./dist/index.js",
|
|
8
9
|
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
9
17
|
"keywords": [
|
|
10
18
|
"bookwhen",
|
|
11
19
|
"booking",
|
|
12
20
|
"api client"
|
|
13
21
|
],
|
|
14
|
-
"type": "module",
|
|
15
22
|
"author": {
|
|
16
23
|
"name": "Justin Philpott",
|
|
17
24
|
"email": "justin@jphil.dev"
|
|
@@ -42,6 +49,7 @@
|
|
|
42
49
|
"@typescript-eslint/eslint-plugin": "^8.13.0",
|
|
43
50
|
"@typescript-eslint/parser": "^8.13.0",
|
|
44
51
|
"@vitest/coverage-v8": "2.1.3",
|
|
52
|
+
"axios": "^1.7.7",
|
|
45
53
|
"c8": "^10.1.2",
|
|
46
54
|
"commitizen": "^4.3.1",
|
|
47
55
|
"cz-conventional-changelog": "^3.3.0",
|
|
@@ -55,13 +63,13 @@
|
|
|
55
63
|
"playwright": "^1.52.0",
|
|
56
64
|
"playwright-msw": "^3.0.1",
|
|
57
65
|
"prettier": "^3.3.3",
|
|
66
|
+
"start-server-and-test": "^2.0.12",
|
|
58
67
|
"tsup": "^8.3.4",
|
|
59
68
|
"typescript": "^5.6.3",
|
|
60
69
|
"vite": "^5.4.10",
|
|
61
70
|
"vite-plugin-dts": "^4.5.3",
|
|
62
71
|
"vite-tsconfig-paths": "^5.1.0",
|
|
63
72
|
"vitest": "^2.1.3",
|
|
64
|
-
"axios": "^1.7.7",
|
|
65
73
|
"zod": "^3.23.8"
|
|
66
74
|
},
|
|
67
75
|
"config": {
|
|
@@ -73,36 +81,21 @@
|
|
|
73
81
|
"axios": "^1.7.0",
|
|
74
82
|
"zod": "^3.23.0"
|
|
75
83
|
},
|
|
76
|
-
"dependencies": {},
|
|
77
|
-
"exports": {
|
|
78
|
-
".": {
|
|
79
|
-
"types": "./dist/index.d.ts",
|
|
80
|
-
"browser": "./dist/index.es.js",
|
|
81
|
-
"node": "./dist/index.js",
|
|
82
|
-
"import": "./dist/index.es.js",
|
|
83
|
-
"default": "./dist/index.es.js"
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
"browser": "./dist/index.es.js",
|
|
87
84
|
"scripts": {
|
|
88
85
|
"dev": "vitest",
|
|
89
86
|
"preview": "vite preview --config vite.preview.config.ts",
|
|
90
87
|
"build": "vite build -c vite.library.config.ts",
|
|
91
88
|
"build:node": "vite build -c vite.test.config.ts",
|
|
92
89
|
"lint": "tsc",
|
|
93
|
-
"test": "
|
|
90
|
+
"serve:test:browser": "http-server . -p 3000 -c-1",
|
|
94
91
|
"test:browser": "playwright test",
|
|
95
92
|
"test:node": "vitest run",
|
|
96
|
-
"
|
|
93
|
+
"test": "pnpm test:node && pnpm build && start-server-and-test serve:test:browser http://localhost:3000 test:browser",
|
|
94
|
+
"test:node:coverage": "vitest run --coverage",
|
|
97
95
|
"type-check": "tsc --noEmit",
|
|
98
96
|
"check-exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
|
|
99
97
|
"prettier-check": "prettier --check 'src/**/*.ts'",
|
|
100
98
|
"format": "prettier --write 'src/**/*.ts' README.md",
|
|
101
|
-
"pre-commit": "pnpm lint && pnpm build"
|
|
102
|
-
"commit": "cz",
|
|
103
|
-
"prepush": "pnpm test",
|
|
104
|
-
"local-release": "changeset version && changeset publish",
|
|
105
|
-
"release": "pnpm lint && pnpm test && pnpm build && changeset publish",
|
|
106
|
-
"ci": "pnpm test && pnpm check-exports && pnpm build"
|
|
99
|
+
"pre-commit": "pnpm lint && pnpm build && pnpm test && pnpm check-exports"
|
|
107
100
|
}
|
|
108
101
|
}
|
package/dist/index.es.js
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
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
|
package/dist/index.es.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,CA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AA;AAC3E,IAAA,aAAA,CAAc,SAAS,eAAkB,GAAA,IAAA,CAAA;AAAA,GAC3C;AAEA,EAAA,aAAA,CAAc,aAAa,QAAS,CAAA,GAAA;AAAA,IAClC,CAAC,QAAa,KAAA,QAAA;AAAA,IACd,CAAC,KAAU,KAAA;AACT,MAAA,IAAI,MAAM,QAAU,EAAA;AAClB,QAAM,MAAA,MAAA,GAAS,MAAM,QAAS,CAAA,MAAA,CAAA;AAC9B,QAAM,MAAA,WAAA,GAAc,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,40 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { EventService } from '../services/event/Event.js';
|
|
3
|
-
/**
|
|
4
|
-
* Client for the Bookwhen API.
|
|
5
|
-
*
|
|
6
|
-
* @see https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml#/ClassPass/get_class_passes__class_pass_id_
|
|
7
|
-
*/
|
|
8
|
-
export declare class BookwhenClient {
|
|
9
|
-
private axiosInstance;
|
|
10
|
-
private eventService?;
|
|
11
|
-
private readonly isBrowser;
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new instance of the BookwhenClient class.
|
|
14
|
-
* @param axiosInstance - Configured Axios instance for making HTTP requests.
|
|
15
|
-
* @throws Error if axiosInstance is not provided.
|
|
16
|
-
*/
|
|
17
|
-
constructor(axiosInstance: AxiosInstance);
|
|
18
|
-
/**
|
|
19
|
-
* Gets the EventService instance.
|
|
20
|
-
*
|
|
21
|
-
* Available methods:
|
|
22
|
-
* - getById(params: GetEventByIdParams): Promise<BookwhenEvent>
|
|
23
|
-
* - getMultiple(params: GetMultipleEventsParams): Promise<BookwhenEvent[]>
|
|
24
|
-
*
|
|
25
|
-
* @returns The EventService instance.
|
|
26
|
-
*/
|
|
27
|
-
get events(): EventService;
|
|
28
|
-
}
|
|
29
|
-
interface BookwhenClientOptions {
|
|
30
|
-
apiKey: string;
|
|
31
|
-
baseURL?: string;
|
|
32
|
-
debug?: boolean;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Creates an instance of Axios with the provided API key.
|
|
36
|
-
* @param apiKey - The API key used for authentication.
|
|
37
|
-
* @returns The Axios instance.
|
|
38
|
-
*/
|
|
39
|
-
export declare function createBookwhenClient(options: BookwhenClientOptions): BookwhenClient;
|
|
40
|
-
export {};
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Resources, Filters } from '../types/GlobalTypes.js';
|
|
2
|
-
/**
|
|
3
|
-
* QueryBuilder class to help build query strings for Bookwhen API requests.
|
|
4
|
-
*/
|
|
5
|
-
export declare class BookwhenRequest {
|
|
6
|
-
private path;
|
|
7
|
-
private filters;
|
|
8
|
-
private includes;
|
|
9
|
-
constructor(path: string);
|
|
10
|
-
/**
|
|
11
|
-
* Adds filters to the BookwhenQuery object.
|
|
12
|
-
* @param filters - An array of key-value pairs representing the filters to be added.
|
|
13
|
-
*
|
|
14
|
-
* Example resultant query strings:
|
|
15
|
-
* /v2/events?filter[from]=20200401&filter[to]=20200404
|
|
16
|
-
* /v2/events?filter[tag]=tag%20one,tag%20two
|
|
17
|
-
* /v2/events?filter[title]=advanced,pro&filter[detail]=masterclass
|
|
18
|
-
*
|
|
19
|
-
* @see https://petstore.swagger.io/?url=https://api.bookwhen.com/v2/openapi.yaml
|
|
20
|
-
*
|
|
21
|
-
* @returns The updated BookwhenQuery object.
|
|
22
|
-
*/
|
|
23
|
-
addFilters(filters: Filters): BookwhenRequest;
|
|
24
|
-
/**
|
|
25
|
-
* Adds an include query parameter to the BookwhenRequest object.
|
|
26
|
-
* @param includes - An array of strings representing the resources to include.
|
|
27
|
-
*
|
|
28
|
-
* @returns The updated BookwhenRequest object.
|
|
29
|
-
*
|
|
30
|
-
* @throws Error if any include is not a valid string.
|
|
31
|
-
*/
|
|
32
|
-
addIncludes(includes: Resources): BookwhenRequest;
|
|
33
|
-
/**
|
|
34
|
-
* Does the actual work of putting together a valid query string given:
|
|
35
|
-
* - filters
|
|
36
|
-
* - includes
|
|
37
|
-
* - segments
|
|
38
|
-
*
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
build(): string;
|
|
42
|
-
/**
|
|
43
|
-
* @returns the constructed query string
|
|
44
|
-
*/
|
|
45
|
-
toString(): string;
|
|
46
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { IEventService, GetMultipleEventsParams } from './EventInterfaces.js';
|
|
2
|
-
import { BookwhenEvent } from './EventTypes.js';
|
|
3
|
-
import { AxiosInstance } from 'axios';
|
|
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 declare class EventService implements IEventService {
|
|
10
|
-
private 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: AxiosInstance);
|
|
16
|
-
/**
|
|
17
|
-
* Retrieves a single event by its ID from the Bookwhen API.
|
|
18
|
-
*
|
|
19
|
-
* @param {Object} param - The parameters for retrieving an event.
|
|
20
|
-
* @param {string} param.eventId - The ID of the event to retrieve.
|
|
21
|
-
* @param {string} [param.include] - Optional parameter to include additional data.
|
|
22
|
-
* @returns {Promise<BookwhenEvent>} A Promise that resolves to the BookwhenEvent object.
|
|
23
|
-
*/
|
|
24
|
-
getById(params: z.infer<typeof GetEventByIdParamsSchema>): Promise<BookwhenEvent>;
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves multiple events based on filtering and pagination parameters.
|
|
27
|
-
*
|
|
28
|
-
* @param {GetMultipleEventsParams} params - Optional parameters for filtering and pagination.
|
|
29
|
-
* @return {Promise<BookwhenEvent[]>} A Promise that resolves to an array of BookwhenEvent objects.
|
|
30
|
-
*/
|
|
31
|
-
getMultiple(params?: GetMultipleEventsParams): Promise<BookwhenEvent[]>;
|
|
32
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { BookwhenEvent } from './EventTypes.js';
|
|
2
|
-
/**
|
|
3
|
-
* Interface for services handling events via the Bookwhen API V2.
|
|
4
|
-
*/
|
|
5
|
-
export interface IEventService {
|
|
6
|
-
/**
|
|
7
|
-
* Retrieves a single event by its ID.
|
|
8
|
-
* @param eventId The unique identifier of the event.
|
|
9
|
-
* @param include Optional parameter to include additional data.
|
|
10
|
-
* @returns A Promise that resolves to an Event object, as defined by the Bookwhen API data structure.
|
|
11
|
-
*/
|
|
12
|
-
getById(params: GetEventByIdParams): Promise<BookwhenEvent>;
|
|
13
|
-
/**
|
|
14
|
-
* Retrieves multiple events based on specified parameters.
|
|
15
|
-
* @param params Optional parameters to filter and control the list of returned events, according to what the Bookwhen API supports.
|
|
16
|
-
* @returns A Promise that resolves to an array of Event objects.
|
|
17
|
-
*/
|
|
18
|
-
getMultiple?(params?: GetMultipleEventsParams): Promise<BookwhenEvent[]>;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Parameters for querying a single event from the Bookwhen API, including optional include parameter.
|
|
22
|
-
* @param eventId The unique identifier of the event.
|
|
23
|
-
* @param include Optional parameter to include additional data.
|
|
24
|
-
*/
|
|
25
|
-
export interface GetEventByIdParams {
|
|
26
|
-
eventId: string;
|
|
27
|
-
includes?: EventResource[];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Represents the parameters for getting multiple events.
|
|
31
|
-
* @param filter The filter parameters to apply to the query.
|
|
32
|
-
* @param include The data to side load and include with the returned events.
|
|
33
|
-
*/
|
|
34
|
-
export interface GetMultipleEventsParams {
|
|
35
|
-
filters?: EventFilters;
|
|
36
|
-
includes?: EventResource[];
|
|
37
|
-
}
|
|
38
|
-
interface EventFiltersMap {
|
|
39
|
-
calendar?: string[];
|
|
40
|
-
entry?: string[];
|
|
41
|
-
location?: string[];
|
|
42
|
-
tag?: string[];
|
|
43
|
-
title?: string[];
|
|
44
|
-
detail?: string[];
|
|
45
|
-
from?: string;
|
|
46
|
-
to?: string;
|
|
47
|
-
compact?: boolean;
|
|
48
|
-
}
|
|
49
|
-
export type EventFilters = {
|
|
50
|
-
[K in keyof EventFiltersMap]?: EventFiltersMap[K];
|
|
51
|
-
};
|
|
52
|
-
export type EventResource = 'location' | 'attachments' | 'tickets' | 'tickets.events' | 'tickets.class_passes';
|
|
53
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export declare const EventResourceSchema: z.ZodEnum<["location", "attachments", "tickets", "tickets.events", "tickets.class_passes"]>;
|
|
3
|
-
export declare const GetEventByIdParamsSchema: z.ZodObject<{
|
|
4
|
-
eventId: z.ZodString;
|
|
5
|
-
includes: z.ZodOptional<z.ZodArray<z.ZodEnum<["location", "attachments", "tickets", "tickets.events", "tickets.class_passes"]>, "many">>;
|
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
eventId: string;
|
|
8
|
-
includes?: ("location" | "attachments" | "tickets" | "tickets.events" | "tickets.class_passes")[] | undefined;
|
|
9
|
-
}, {
|
|
10
|
-
eventId: string;
|
|
11
|
-
includes?: ("location" | "attachments" | "tickets" | "tickets.events" | "tickets.class_passes")[] | undefined;
|
|
12
|
-
}>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export interface EventImage {
|
|
2
|
-
image_url: string;
|
|
3
|
-
alt_ratio_16x9_1x_url: string;
|
|
4
|
-
alt_ratio_16x9_2x_url: string;
|
|
5
|
-
alt_ratio_16x9_3x_url: string;
|
|
6
|
-
alt_ratio_4x3_1x_url: string;
|
|
7
|
-
alt_ratio_4x3_2x_url: string;
|
|
8
|
-
alt_ratio_4x3_3x_url: string;
|
|
9
|
-
alt_ratio_1x1_1x_url: string;
|
|
10
|
-
alt_ratio_1x1_2x_url: string;
|
|
11
|
-
alt_ratio_1x1_3x_url: string;
|
|
12
|
-
}
|
|
13
|
-
export interface EventAttributes {
|
|
14
|
-
title: string;
|
|
15
|
-
details: string;
|
|
16
|
-
all_day: boolean;
|
|
17
|
-
start_at: string;
|
|
18
|
-
end_at: string;
|
|
19
|
-
attendee_limit: number;
|
|
20
|
-
attendee_count: number;
|
|
21
|
-
waiting_list: boolean;
|
|
22
|
-
max_tickets_per_booking: number;
|
|
23
|
-
tags: string[];
|
|
24
|
-
event_image: EventImage;
|
|
25
|
-
}
|
|
26
|
-
export interface BookwhenEvent {
|
|
27
|
-
id: string;
|
|
28
|
-
type: string;
|
|
29
|
-
attributes: EventAttributes;
|
|
30
|
-
}
|
|
31
|
-
export interface EventsResponse {
|
|
32
|
-
data: BookwhenEvent[];
|
|
33
|
-
}
|
|
34
|
-
export interface EventResponse {
|
|
35
|
-
data: BookwhenEvent;
|
|
36
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
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;
|