@jphil/bookwhen-client 0.0.10 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -8
- package/dist/client/BookwhenClient.d.ts +38 -0
- package/dist/client/BookwhenClient.integration.test.d.ts +1 -0
- package/dist/client/BookwhenClient.integration.test.js +78 -0
- package/dist/client/BookwhenClient.integration.test.js.map +1 -0
- package/dist/client/BookwhenClient.js +69 -0
- package/dist/client/BookwhenClient.js.map +1 -0
- package/dist/client/BookwhenClient.unit.test.d.ts +1 -0
- package/dist/client/BookwhenClient.unit.test.js +70 -0
- package/dist/client/BookwhenClient.unit.test.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +4 -3
- package/dist/index.test.js.map +1 -1
- package/dist/request/BookwhenRequest.d.ts +46 -0
- package/dist/request/BookwhenRequest.js +126 -0
- package/dist/request/BookwhenRequest.js.map +1 -0
- package/dist/request/BookwhenRequest.unit.test.d.ts +1 -0
- package/dist/request/BookwhenRequest.unit.test.js +141 -0
- package/dist/request/BookwhenRequest.unit.test.js.map +1 -0
- package/dist/request/httpStatusCodes.d.ts +3 -0
- package/dist/request/httpStatusCodes.js +15 -0
- package/dist/request/httpStatusCodes.js.map +1 -0
- package/dist/services/event/Event.d.ts +32 -0
- package/dist/services/event/Event.js +72 -0
- package/dist/services/event/Event.js.map +1 -0
- package/dist/services/event/Event.unit.test.d.ts +1 -0
- package/dist/services/event/Event.unit.test.js +104 -0
- package/dist/services/event/Event.unit.test.js.map +1 -0
- package/dist/services/event/EventInterfaces.d.ts +53 -0
- package/dist/services/event/EventInterfaces.js +3 -0
- package/dist/services/event/EventInterfaces.js.map +1 -0
- package/dist/services/event/EventSchemas.d.ts +12 -0
- package/dist/services/event/EventSchemas.js +8 -0
- package/dist/services/event/EventSchemas.js.map +1 -0
- package/dist/services/event/EventTypes.d.ts +36 -0
- package/dist/services/event/EventTypes.js +2 -0
- package/dist/services/event/EventTypes.js.map +1 -0
- package/dist/types/GlobalTypes.d.ts +9 -0
- package/dist/types/GlobalTypes.js +2 -0
- package/dist/types/GlobalTypes.js.map +1 -0
- package/dist/utils/http-utils.d.ts +8 -0
- package/dist/utils/http-utils.js +19 -0
- package/dist/utils/http-utils.js.map +1 -0
- package/package.json +11 -2
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { BookwhenRequest } from './BookwhenRequest.js';
|
|
3
|
+
describe('BookwhenRequest', () => {
|
|
4
|
+
const testpath = "path";
|
|
5
|
+
describe('path handling', () => {
|
|
6
|
+
it('should return a /"path" when called with "path"', () => {
|
|
7
|
+
const request = new BookwhenRequest(testpath);
|
|
8
|
+
expect(request.toString()).toBe('/' + testpath);
|
|
9
|
+
});
|
|
10
|
+
it('should throw an error if the path is empty', () => {
|
|
11
|
+
expect(() => new BookwhenRequest('')).toThrow('Path is required');
|
|
12
|
+
});
|
|
13
|
+
it('should throw an error if the path is undefined', () => {
|
|
14
|
+
expect(() => new BookwhenRequest(undefined)).toThrow('Path is required');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('addIncludes', () => {
|
|
18
|
+
it('should return the given path with an empty string when no resources are provided', () => {
|
|
19
|
+
const resources = [];
|
|
20
|
+
const query = new BookwhenRequest(testpath);
|
|
21
|
+
query.addIncludes(resources);
|
|
22
|
+
expect(query.toString()).toEqual('/' + testpath);
|
|
23
|
+
});
|
|
24
|
+
it('should return a query string with a single resource', () => {
|
|
25
|
+
const resources = ['resource1'];
|
|
26
|
+
const query = new BookwhenRequest(testpath);
|
|
27
|
+
query.addIncludes(resources);
|
|
28
|
+
expect(query.toString()).toEqual('/' + testpath + '?include=resource1');
|
|
29
|
+
});
|
|
30
|
+
it('should return a query string with multiple resources separated by commas', () => {
|
|
31
|
+
const resources = ['resource1', 'resource2', 'resource3'];
|
|
32
|
+
const query = new BookwhenRequest(testpath);
|
|
33
|
+
query.addIncludes(resources);
|
|
34
|
+
expect(query.toString()).toEqual('/' + testpath + '?include=resource1,resource2,resource3');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('addFilters', () => {
|
|
38
|
+
it('should return a query with no filters, if an empty filters array is given', () => {
|
|
39
|
+
const filters = {};
|
|
40
|
+
const query = new BookwhenRequest(testpath);
|
|
41
|
+
query.addFilters(filters);
|
|
42
|
+
expect(query.toString()).toEqual('/' + testpath);
|
|
43
|
+
});
|
|
44
|
+
it('should return a query string with a single filter', () => {
|
|
45
|
+
const filters = { 'key': "value" };
|
|
46
|
+
const query = new BookwhenRequest(testpath);
|
|
47
|
+
query.addFilters(filters);
|
|
48
|
+
expect(query.toString()).toEqual('/' + testpath + '?filter[key]=value');
|
|
49
|
+
});
|
|
50
|
+
it('should return a query string with a single filter and multiple values', () => {
|
|
51
|
+
const filters = { 'key': ['value one', 'value two'] };
|
|
52
|
+
const query = new BookwhenRequest(testpath);
|
|
53
|
+
query.addFilters(filters);
|
|
54
|
+
expect(query.toString()).toEqual('/' + testpath + '?filter[key]=value%20one,value%20two');
|
|
55
|
+
});
|
|
56
|
+
it('should return a query string with multiple filters where values are strings', () => {
|
|
57
|
+
const filters = {
|
|
58
|
+
title: 'advanced',
|
|
59
|
+
detail: 'masterclass',
|
|
60
|
+
};
|
|
61
|
+
const query = new BookwhenRequest(testpath);
|
|
62
|
+
query.addFilters(filters);
|
|
63
|
+
expect(query.toString()).toEqual('/' + testpath + '?filter[title]=advanced&filter[detail]=masterclass');
|
|
64
|
+
});
|
|
65
|
+
it('should return a query string with multiple filters where values are arrays of strings', () => {
|
|
66
|
+
const filters = {
|
|
67
|
+
title: ['title1', 'title2'],
|
|
68
|
+
detail: ['detail1', 'detail2', 'detail3'],
|
|
69
|
+
};
|
|
70
|
+
const query = new BookwhenRequest(testpath);
|
|
71
|
+
query.addFilters(filters);
|
|
72
|
+
expect(query.toString()).toEqual('/' + testpath + '?filter[title]=title1,title2&filter[detail]=detail1,detail2,detail3');
|
|
73
|
+
});
|
|
74
|
+
it('should ignore empty string filter values', () => {
|
|
75
|
+
const filters = { key: '', key2: 'value' };
|
|
76
|
+
const query = new BookwhenRequest(testpath);
|
|
77
|
+
query.addFilters(filters);
|
|
78
|
+
expect(query.toString()).toEqual('/' + testpath + '?filter[key2]=value');
|
|
79
|
+
});
|
|
80
|
+
it('should ignore undefined filter values', () => {
|
|
81
|
+
const filters = { key: undefined, key2: 'value' };
|
|
82
|
+
const query = new BookwhenRequest(testpath);
|
|
83
|
+
query.addFilters(filters);
|
|
84
|
+
expect(query.toString()).toEqual('/' + testpath + '?filter[key2]=value');
|
|
85
|
+
});
|
|
86
|
+
it('should ignore null filter values', () => {
|
|
87
|
+
const filters = { key: null, key2: 'value' };
|
|
88
|
+
const query = new BookwhenRequest(testpath);
|
|
89
|
+
query.addFilters(filters);
|
|
90
|
+
expect(query.toString()).toEqual('/' + testpath + '?filter[key2]=value');
|
|
91
|
+
});
|
|
92
|
+
it('should ignore an "empty array" filter value', () => {
|
|
93
|
+
const filters = { key: [] };
|
|
94
|
+
const query = new BookwhenRequest(testpath);
|
|
95
|
+
query.addFilters(filters);
|
|
96
|
+
expect(query.toString()).toEqual('/' + testpath);
|
|
97
|
+
});
|
|
98
|
+
it('should ignore empty string elements, where a filter value is an array', () => {
|
|
99
|
+
const filters = { key: ['', 'value'] };
|
|
100
|
+
const query = new BookwhenRequest(testpath);
|
|
101
|
+
expect(query.toString()).toEqual('/' + testpath);
|
|
102
|
+
});
|
|
103
|
+
it('should ignore undefined array elements, where a filter value is an array', () => {
|
|
104
|
+
const filters = { key: [undefined, 'value'], key2: 'value2' };
|
|
105
|
+
const query = new BookwhenRequest(testpath);
|
|
106
|
+
query.addFilters(filters);
|
|
107
|
+
expect(query.toString()).toEqual('/' + testpath + '?filter[key]=value&filter[key2]=value2');
|
|
108
|
+
});
|
|
109
|
+
it('should ignore null array elements, where a filter value is an array', () => {
|
|
110
|
+
const filters = { key: [null, 'value'], key2: 'value2' };
|
|
111
|
+
const query = new BookwhenRequest(testpath);
|
|
112
|
+
query.addFilters(filters);
|
|
113
|
+
expect(query.toString()).toEqual('/' + testpath + '?filter[key]=value&filter[key2]=value2');
|
|
114
|
+
});
|
|
115
|
+
it('should return a query string with a single filter when value is an array with a single value', () => {
|
|
116
|
+
const filters = { key: ['value'] };
|
|
117
|
+
const query = new BookwhenRequest(testpath);
|
|
118
|
+
query.addFilters(filters);
|
|
119
|
+
expect(query.toString()).toEqual('/' + testpath + '?filter[key]=value');
|
|
120
|
+
});
|
|
121
|
+
it('should build a URL query string from the provided parameters, skipping invalid value types', () => {
|
|
122
|
+
const params = {
|
|
123
|
+
key1: 'value1',
|
|
124
|
+
key2: ['value2', null, 'value3', ''],
|
|
125
|
+
key3: undefined,
|
|
126
|
+
key4: ['key3skipped', undefined, '123'],
|
|
127
|
+
key5: "1234",
|
|
128
|
+
key6: null,
|
|
129
|
+
key7: undefined,
|
|
130
|
+
key8: [],
|
|
131
|
+
key9: 'undefined',
|
|
132
|
+
};
|
|
133
|
+
const expectedFilterString = '/path?filter[key1]=value1&filter[key2]=value2,value3&filter[key4]=key3skipped,123&filter[key5]=1234&filter[key9]=undefined';
|
|
134
|
+
const query = new BookwhenRequest(testpath);
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
query.addFilters(params);
|
|
137
|
+
expect(query.toString()).toEqual(expectedFilterString);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
//# sourceMappingURL=BookwhenRequest.unit.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BookwhenRequest.unit.test.js","sourceRoot":"","sources":["../../src/request/BookwhenRequest.unit.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,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B,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IEventService, GetMultipleEventsParams } from './EventInterfaces.js';
|
|
2
|
+
import type { BookwhenEvent } from './EventTypes.js';
|
|
3
|
+
import type { 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
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
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AI,KAAK,CAAC,6CAA6C,aAAa,EAAE,CAAC,CAAC;YAChF,CAAC;iBAAM,CAAC;gBACN,uBAAuB,CAAC,KAAK,EAAE,yBAAyB,EAAE;oBACxD,GAAG,EAAE;wBACH,IAAI,EAAE,GAAG;wBACT,OAAO,EAAE,2DAA2D;qBACrE;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,WAAW,CAAC,SAAkC,EAAE;QACpD,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,SAAS,CAAC,CAAC;YAC7C,IAAI,MAAM,CAAC,QAAQ;gBAAE,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACxD,IAAI,MAAM,CAAC,OAAO;gBAAE,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAErD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAiB,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,2BAA2B;YACtG,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uBAAuB,CAAC,KAAK,EAAE,yBAAyB,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { EventService } from './Event.js';
|
|
4
|
+
describe('EventService', () => {
|
|
5
|
+
let eventService;
|
|
6
|
+
let mockAxiosInstance;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
// Create a mock instance of axios for dependency injection
|
|
9
|
+
mockAxiosInstance = axios.create();
|
|
10
|
+
eventService = new EventService(mockAxiosInstance); // Inject mock axios instance
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
vi.restoreAllMocks();
|
|
14
|
+
});
|
|
15
|
+
it('should retrieve a single event by ID', async () => {
|
|
16
|
+
const eventId = '123';
|
|
17
|
+
const eventData = {
|
|
18
|
+
id: eventId,
|
|
19
|
+
};
|
|
20
|
+
// Mock Axios request using vi.spyOn
|
|
21
|
+
mockAxiosInstance.get = vi.fn().mockResolvedValue({ data: { data: eventData } });
|
|
22
|
+
const result = await eventService.getById({ eventId });
|
|
23
|
+
expect(mockAxiosInstance.get).toHaveBeenCalledWith(`/events/${eventId}`);
|
|
24
|
+
expect(result).toEqual(eventData);
|
|
25
|
+
});
|
|
26
|
+
it('should handle error when retrieving a single event by ID', async () => {
|
|
27
|
+
const eventId = '123';
|
|
28
|
+
const errorMessage = 'Event not found. Please check the event ID and try again.';
|
|
29
|
+
// Mock Axios request using vi.spyOn
|
|
30
|
+
vi.spyOn(mockAxiosInstance, 'get').mockRejectedValue({
|
|
31
|
+
response: {
|
|
32
|
+
status: 404,
|
|
33
|
+
data: { message: errorMessage }
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
expect(eventService.getById({ eventId })).rejects.toThrow(errorMessage);
|
|
37
|
+
});
|
|
38
|
+
it('should handle error when retrieving multiple events', async () => {
|
|
39
|
+
const errorMessage = 'BookwhenClient: The requested resource could not be found';
|
|
40
|
+
// Mock Axios request using vi.spyOn
|
|
41
|
+
vi.spyOn(mockAxiosInstance, 'get').mockRejectedValue({
|
|
42
|
+
response: {
|
|
43
|
+
status: 404,
|
|
44
|
+
data: { message: errorMessage }
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
expect(eventService.getMultiple()).rejects.toThrow(errorMessage);
|
|
48
|
+
expect(mockAxiosInstance.get).toHaveBeenCalledWith('/events');
|
|
49
|
+
});
|
|
50
|
+
it('should retrieve multiple events', async () => {
|
|
51
|
+
const eventsData = [
|
|
52
|
+
{ id: '1', type: 'event' },
|
|
53
|
+
{ id: '2', type: 'event' },
|
|
54
|
+
];
|
|
55
|
+
// Mock Axios request using vi.spyOn
|
|
56
|
+
vi.spyOn(mockAxiosInstance, 'get').mockResolvedValue({ data: { data: eventsData } });
|
|
57
|
+
const result = await eventService.getMultiple();
|
|
58
|
+
expect(result).toEqual(eventsData);
|
|
59
|
+
});
|
|
60
|
+
it('should retrieve multiple events with filters', async () => {
|
|
61
|
+
const filters = {
|
|
62
|
+
title: ['Test Event'],
|
|
63
|
+
from: 'test',
|
|
64
|
+
detail: ['Event Details'],
|
|
65
|
+
};
|
|
66
|
+
const eventsData = [
|
|
67
|
+
{ id: '1', type: 'event' },
|
|
68
|
+
{ id: '2', type: 'event' },
|
|
69
|
+
];
|
|
70
|
+
// Mock Axios request using vi.spyOn
|
|
71
|
+
vi.spyOn(mockAxiosInstance, 'get').mockResolvedValue({ data: { data: eventsData } });
|
|
72
|
+
const result = await eventService.getMultiple({ filters });
|
|
73
|
+
expect(result).toEqual(eventsData);
|
|
74
|
+
expect(mockAxiosInstance.get).toHaveBeenCalledWith('/events?filter[title]=Test%20Event&filter[from]=test&filter[detail]=Event%20Details');
|
|
75
|
+
});
|
|
76
|
+
it('should retrieve multiple events with includes', async () => {
|
|
77
|
+
const includes = ['location', 'attachments'];
|
|
78
|
+
const eventsData = [
|
|
79
|
+
{ id: '1', type: 'event' },
|
|
80
|
+
{ id: '2', type: 'event' },
|
|
81
|
+
];
|
|
82
|
+
// Mock Axios request using vi.spyOn
|
|
83
|
+
vi.spyOn(mockAxiosInstance, 'get').mockResolvedValue({ data: { data: eventsData } });
|
|
84
|
+
const result = await eventService.getMultiple({ includes });
|
|
85
|
+
expect(result).toEqual(eventsData);
|
|
86
|
+
expect(mockAxiosInstance.get).toHaveBeenCalledWith('/events?include=location,attachments');
|
|
87
|
+
});
|
|
88
|
+
it('should retrieve multiple events with includes and filters', async () => {
|
|
89
|
+
const includes = ['location', 'tickets'];
|
|
90
|
+
const filters = {
|
|
91
|
+
title: ['Workshop'],
|
|
92
|
+
start_at: ['2023-01-01']
|
|
93
|
+
};
|
|
94
|
+
const eventsData = [
|
|
95
|
+
{ id: '1', type: 'event' },
|
|
96
|
+
{ id: '2', type: 'event' },
|
|
97
|
+
];
|
|
98
|
+
vi.spyOn(mockAxiosInstance, 'get').mockResolvedValue({ data: { data: eventsData } });
|
|
99
|
+
const result = await eventService.getMultiple({ filters, includes });
|
|
100
|
+
expect(result).toEqual(eventsData);
|
|
101
|
+
expect(mockAxiosInstance.get).toHaveBeenCalledWith('/events?filter[title]=Workshop&filter[start_at]=2023-01-01&include=location,tickets');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=Event.unit.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Event.unit.test.js","sourceRoot":"","sources":["../../../src/services/event/Event.unit.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EACF,EAAE,EACH,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI1C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,YAA0B,CAAC;IAC/B,IAAI,iBAAgC,CAAC;IAErC,UAAU,CAAC,GAAG,EAAE;QACd,2DAA2D;QAC3D,iBAAiB,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QACnC,YAAY,GAAG,IAAI,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC,6BAA6B;IACnF,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,eAAe,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QACpD,MAAM,OAAO,GAAG,KAAK,CAAC;QACtB,MAAM,SAAS,GAA2B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E,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE;YAC1B,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE;SAC3B,CAAC;QAEF,EAAE,CAAC,KAAK,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;QAErF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;QACrE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAA6B,CAAC,CAAC;QACtD,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAAC,qFAAqF,CAAC,CAAC;IAC5I,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { 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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventInterfaces.js","sourceRoot":"","sources":["../../../src/services/event/EventInterfaces.ts"],"names":[],"mappings":"AAqDC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}>;
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventTypes.js","sourceRoot":"","sources":["../../../src/services/event/EventTypes.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GlobalTypes.js","sourceRoot":"","sources":["../../src/types/GlobalTypes.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|