@jphil/bookwhen-client 0.4.2 → 0.6.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 +67 -300
- package/dist/index.d.ts +371 -2
- package/dist/index.js +282 -1
- package/dist/index.js.map +1 -1
- package/package.json +20 -19
package/dist/index.js
CHANGED
|
@@ -6481,7 +6481,8 @@ class EventService {
|
|
|
6481
6481
|
}
|
|
6482
6482
|
}
|
|
6483
6483
|
/**
|
|
6484
|
-
* Retrieves
|
|
6484
|
+
* Retrieves a single page of events based on filtering and pagination parameters.
|
|
6485
|
+
* The Bookwhen API returns up to 20 events per page by default.
|
|
6485
6486
|
*
|
|
6486
6487
|
* @param {GetMultipleEventsParams} params - Optional parameters for filtering and pagination.
|
|
6487
6488
|
* @return {Promise<EventsResponse>} A Promise that resolves to the full JSON:API response object.
|
|
@@ -6497,6 +6498,258 @@ class EventService {
|
|
|
6497
6498
|
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES);
|
|
6498
6499
|
}
|
|
6499
6500
|
}
|
|
6501
|
+
/**
|
|
6502
|
+
* Retrieves all events matching the given filters, automatically following
|
|
6503
|
+
* pagination links to fetch every page of results.
|
|
6504
|
+
*
|
|
6505
|
+
* The returned response contains the combined `data` and deduplicated
|
|
6506
|
+
* `included` arrays from all pages.
|
|
6507
|
+
*
|
|
6508
|
+
* @param {GetMultipleEventsParams} params - Optional parameters for filtering.
|
|
6509
|
+
* @return {Promise<EventsResponse>} A Promise that resolves to the combined JSON:API response.
|
|
6510
|
+
*/
|
|
6511
|
+
async getAll(params = {}) {
|
|
6512
|
+
const firstPage = await this.getMultiple(params);
|
|
6513
|
+
if (!firstPage?.data || !firstPage.links?.next) {
|
|
6514
|
+
return firstPage;
|
|
6515
|
+
}
|
|
6516
|
+
const allData = [...firstPage.data];
|
|
6517
|
+
const includedById = /* @__PURE__ */ new Map();
|
|
6518
|
+
if (firstPage.included) {
|
|
6519
|
+
for (const item of firstPage.included) {
|
|
6520
|
+
includedById.set(`${item.type}:${item.id}`, item);
|
|
6521
|
+
}
|
|
6522
|
+
}
|
|
6523
|
+
let nextUrl = firstPage.links.next;
|
|
6524
|
+
while (nextUrl) {
|
|
6525
|
+
try {
|
|
6526
|
+
const page = (await this.axiosInstance.get(nextUrl)).data;
|
|
6527
|
+
if (page.data) {
|
|
6528
|
+
allData.push(...page.data);
|
|
6529
|
+
}
|
|
6530
|
+
if (page.included) {
|
|
6531
|
+
for (const item of page.included) {
|
|
6532
|
+
includedById.set(`${item.type}:${item.id}`, item);
|
|
6533
|
+
}
|
|
6534
|
+
}
|
|
6535
|
+
nextUrl = page.links?.next;
|
|
6536
|
+
} catch (error) {
|
|
6537
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES);
|
|
6538
|
+
}
|
|
6539
|
+
}
|
|
6540
|
+
return {
|
|
6541
|
+
data: allData,
|
|
6542
|
+
included: includedById.size > 0 ? Array.from(includedById.values()) : void 0
|
|
6543
|
+
};
|
|
6544
|
+
}
|
|
6545
|
+
}
|
|
6546
|
+
const TicketResourceSchema = z.enum([
|
|
6547
|
+
"class_passes",
|
|
6548
|
+
"events",
|
|
6549
|
+
"events.location",
|
|
6550
|
+
"events.tickets",
|
|
6551
|
+
"events.attachments"
|
|
6552
|
+
]);
|
|
6553
|
+
const GetTicketByIdParamsSchema = z.object({
|
|
6554
|
+
ticketId: z.string().min(1, "Invalid ticket ID"),
|
|
6555
|
+
includes: TicketResourceSchema.array().optional()
|
|
6556
|
+
});
|
|
6557
|
+
const GetMultipleTicketsParamsSchema = z.object({
|
|
6558
|
+
eventId: z.string().min(1, "Invalid event ID"),
|
|
6559
|
+
includes: TicketResourceSchema.array().optional()
|
|
6560
|
+
});
|
|
6561
|
+
class TicketService {
|
|
6562
|
+
constructor(axiosInstance) {
|
|
6563
|
+
__publicField(this, "axiosInstance");
|
|
6564
|
+
this.axiosInstance = axiosInstance;
|
|
6565
|
+
}
|
|
6566
|
+
async getById(params) {
|
|
6567
|
+
try {
|
|
6568
|
+
const validParams = GetTicketByIdParamsSchema.parse(params);
|
|
6569
|
+
const query = new BookwhenRequest(`/tickets/${validParams.ticketId}`);
|
|
6570
|
+
if (validParams.includes) {
|
|
6571
|
+
query.addIncludes(validParams.includes);
|
|
6572
|
+
}
|
|
6573
|
+
const response = await this.axiosInstance.get(`${query}`);
|
|
6574
|
+
return response.data;
|
|
6575
|
+
} catch (error) {
|
|
6576
|
+
if (error instanceof z.ZodError) {
|
|
6577
|
+
const errorMessages = error.errors.map((e) => e.message).join(", ");
|
|
6578
|
+
throw new Error(
|
|
6579
|
+
`tickets.getById: Schema Validation failed: ${errorMessages}`
|
|
6580
|
+
);
|
|
6581
|
+
}
|
|
6582
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES, {
|
|
6583
|
+
404: {
|
|
6584
|
+
code: 404,
|
|
6585
|
+
message: "Ticket not found. Please check the ticket ID and try again."
|
|
6586
|
+
}
|
|
6587
|
+
});
|
|
6588
|
+
}
|
|
6589
|
+
}
|
|
6590
|
+
async getMultiple(params) {
|
|
6591
|
+
try {
|
|
6592
|
+
const validParams = GetMultipleTicketsParamsSchema.parse(params);
|
|
6593
|
+
const queryParts = [`event=${encodeURIComponent(validParams.eventId)}`];
|
|
6594
|
+
if (validParams.includes?.length) {
|
|
6595
|
+
queryParts.push(`include=${validParams.includes.join(",")}`);
|
|
6596
|
+
}
|
|
6597
|
+
const response = await this.axiosInstance.get(
|
|
6598
|
+
`/tickets?${queryParts.join("&")}`
|
|
6599
|
+
);
|
|
6600
|
+
return response.data;
|
|
6601
|
+
} catch (error) {
|
|
6602
|
+
if (error instanceof z.ZodError) {
|
|
6603
|
+
const errorMessages = error.errors.map((e) => e.message).join(", ");
|
|
6604
|
+
throw new Error(
|
|
6605
|
+
`tickets.getMultiple: Schema Validation failed: ${errorMessages}`
|
|
6606
|
+
);
|
|
6607
|
+
}
|
|
6608
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES);
|
|
6609
|
+
}
|
|
6610
|
+
}
|
|
6611
|
+
}
|
|
6612
|
+
const GetLocationByIdParamsSchema = z.object({
|
|
6613
|
+
locationId: z.string().min(1, "Invalid location ID")
|
|
6614
|
+
});
|
|
6615
|
+
class LocationService {
|
|
6616
|
+
constructor(axiosInstance) {
|
|
6617
|
+
__publicField(this, "axiosInstance");
|
|
6618
|
+
this.axiosInstance = axiosInstance;
|
|
6619
|
+
}
|
|
6620
|
+
async getById(params) {
|
|
6621
|
+
try {
|
|
6622
|
+
const validParams = GetLocationByIdParamsSchema.parse(params);
|
|
6623
|
+
const query = new BookwhenRequest(`/locations/${validParams.locationId}`);
|
|
6624
|
+
const response = await this.axiosInstance.get(
|
|
6625
|
+
`${query}`
|
|
6626
|
+
);
|
|
6627
|
+
return response.data;
|
|
6628
|
+
} catch (error) {
|
|
6629
|
+
if (error instanceof z.ZodError) {
|
|
6630
|
+
const errorMessages = error.errors.map((e) => e.message).join(", ");
|
|
6631
|
+
throw new Error(
|
|
6632
|
+
`locations.getById: Schema Validation failed: ${errorMessages}`
|
|
6633
|
+
);
|
|
6634
|
+
}
|
|
6635
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES, {
|
|
6636
|
+
404: {
|
|
6637
|
+
code: 404,
|
|
6638
|
+
message: "Location not found. Please check the location ID and try again."
|
|
6639
|
+
}
|
|
6640
|
+
});
|
|
6641
|
+
}
|
|
6642
|
+
}
|
|
6643
|
+
async getMultiple(params = {}) {
|
|
6644
|
+
try {
|
|
6645
|
+
const query = new BookwhenRequest("/locations");
|
|
6646
|
+
if (params.filters) {
|
|
6647
|
+
query.addFilters(params.filters);
|
|
6648
|
+
}
|
|
6649
|
+
const response = await this.axiosInstance.get(
|
|
6650
|
+
`${query}`
|
|
6651
|
+
);
|
|
6652
|
+
return response.data;
|
|
6653
|
+
} catch (error) {
|
|
6654
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES);
|
|
6655
|
+
}
|
|
6656
|
+
}
|
|
6657
|
+
}
|
|
6658
|
+
const GetAttachmentByIdParamsSchema = z.object({
|
|
6659
|
+
attachmentId: z.string().min(1, "Invalid attachment ID")
|
|
6660
|
+
});
|
|
6661
|
+
class AttachmentService {
|
|
6662
|
+
constructor(axiosInstance) {
|
|
6663
|
+
__publicField(this, "axiosInstance");
|
|
6664
|
+
this.axiosInstance = axiosInstance;
|
|
6665
|
+
}
|
|
6666
|
+
async getById(params) {
|
|
6667
|
+
try {
|
|
6668
|
+
const validParams = GetAttachmentByIdParamsSchema.parse(params);
|
|
6669
|
+
const query = new BookwhenRequest(
|
|
6670
|
+
`/attachments/${validParams.attachmentId}`
|
|
6671
|
+
);
|
|
6672
|
+
const response = await this.axiosInstance.get(
|
|
6673
|
+
`${query}`
|
|
6674
|
+
);
|
|
6675
|
+
return response.data;
|
|
6676
|
+
} catch (error) {
|
|
6677
|
+
if (error instanceof z.ZodError) {
|
|
6678
|
+
const errorMessages = error.errors.map((e) => e.message).join(", ");
|
|
6679
|
+
throw new Error(
|
|
6680
|
+
`attachments.getById: Schema Validation failed: ${errorMessages}`
|
|
6681
|
+
);
|
|
6682
|
+
}
|
|
6683
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES, {
|
|
6684
|
+
404: {
|
|
6685
|
+
code: 404,
|
|
6686
|
+
message: "Attachment not found. Please check the attachment ID and try again."
|
|
6687
|
+
}
|
|
6688
|
+
});
|
|
6689
|
+
}
|
|
6690
|
+
}
|
|
6691
|
+
async getMultiple(params = {}) {
|
|
6692
|
+
try {
|
|
6693
|
+
const query = new BookwhenRequest("/attachments");
|
|
6694
|
+
if (params.filters) {
|
|
6695
|
+
query.addFilters(params.filters);
|
|
6696
|
+
}
|
|
6697
|
+
const response = await this.axiosInstance.get(
|
|
6698
|
+
`${query}`
|
|
6699
|
+
);
|
|
6700
|
+
return response.data;
|
|
6701
|
+
} catch (error) {
|
|
6702
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES);
|
|
6703
|
+
}
|
|
6704
|
+
}
|
|
6705
|
+
}
|
|
6706
|
+
const GetClassPassByIdParamsSchema = z.object({
|
|
6707
|
+
classPassId: z.string().min(1, "Invalid class pass ID")
|
|
6708
|
+
});
|
|
6709
|
+
class ClassPassService {
|
|
6710
|
+
constructor(axiosInstance) {
|
|
6711
|
+
__publicField(this, "axiosInstance");
|
|
6712
|
+
this.axiosInstance = axiosInstance;
|
|
6713
|
+
}
|
|
6714
|
+
async getById(params) {
|
|
6715
|
+
try {
|
|
6716
|
+
const validParams = GetClassPassByIdParamsSchema.parse(params);
|
|
6717
|
+
const query = new BookwhenRequest(
|
|
6718
|
+
`/class_passes/${validParams.classPassId}`
|
|
6719
|
+
);
|
|
6720
|
+
const response = await this.axiosInstance.get(
|
|
6721
|
+
`${query}`
|
|
6722
|
+
);
|
|
6723
|
+
return response.data;
|
|
6724
|
+
} catch (error) {
|
|
6725
|
+
if (error instanceof z.ZodError) {
|
|
6726
|
+
const errorMessages = error.errors.map((e) => e.message).join(", ");
|
|
6727
|
+
throw new Error(
|
|
6728
|
+
`classPasses.getById: Schema Validation failed: ${errorMessages}`
|
|
6729
|
+
);
|
|
6730
|
+
}
|
|
6731
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES, {
|
|
6732
|
+
404: {
|
|
6733
|
+
code: 404,
|
|
6734
|
+
message: "Class pass not found. Please check the class pass ID and try again."
|
|
6735
|
+
}
|
|
6736
|
+
});
|
|
6737
|
+
}
|
|
6738
|
+
}
|
|
6739
|
+
async getMultiple(params = {}) {
|
|
6740
|
+
try {
|
|
6741
|
+
const query = new BookwhenRequest("/class_passes");
|
|
6742
|
+
if (params.filters) {
|
|
6743
|
+
query.addFilters(params.filters);
|
|
6744
|
+
}
|
|
6745
|
+
const response = await this.axiosInstance.get(
|
|
6746
|
+
`${query}`
|
|
6747
|
+
);
|
|
6748
|
+
return response.data;
|
|
6749
|
+
} catch (error) {
|
|
6750
|
+
handleServiceHTTPErrors(error, SERVICE_HTTP_STATUS_CODES);
|
|
6751
|
+
}
|
|
6752
|
+
}
|
|
6500
6753
|
}
|
|
6501
6754
|
class BookwhenClient {
|
|
6502
6755
|
/**
|
|
@@ -6506,6 +6759,10 @@ class BookwhenClient {
|
|
|
6506
6759
|
*/
|
|
6507
6760
|
constructor(axiosInstance) {
|
|
6508
6761
|
__publicField(this, "eventService");
|
|
6762
|
+
__publicField(this, "ticketService");
|
|
6763
|
+
__publicField(this, "locationService");
|
|
6764
|
+
__publicField(this, "attachmentService");
|
|
6765
|
+
__publicField(this, "classPassService");
|
|
6509
6766
|
__publicField(this, "isBrowser");
|
|
6510
6767
|
this.axiosInstance = axiosInstance;
|
|
6511
6768
|
this.isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
@@ -6528,6 +6785,30 @@ class BookwhenClient {
|
|
|
6528
6785
|
}
|
|
6529
6786
|
return this.eventService;
|
|
6530
6787
|
}
|
|
6788
|
+
get tickets() {
|
|
6789
|
+
if (!this.ticketService) {
|
|
6790
|
+
this.ticketService = new TicketService(this.axiosInstance);
|
|
6791
|
+
}
|
|
6792
|
+
return this.ticketService;
|
|
6793
|
+
}
|
|
6794
|
+
get locations() {
|
|
6795
|
+
if (!this.locationService) {
|
|
6796
|
+
this.locationService = new LocationService(this.axiosInstance);
|
|
6797
|
+
}
|
|
6798
|
+
return this.locationService;
|
|
6799
|
+
}
|
|
6800
|
+
get attachments() {
|
|
6801
|
+
if (!this.attachmentService) {
|
|
6802
|
+
this.attachmentService = new AttachmentService(this.axiosInstance);
|
|
6803
|
+
}
|
|
6804
|
+
return this.attachmentService;
|
|
6805
|
+
}
|
|
6806
|
+
get classPasses() {
|
|
6807
|
+
if (!this.classPassService) {
|
|
6808
|
+
this.classPassService = new ClassPassService(this.axiosInstance);
|
|
6809
|
+
}
|
|
6810
|
+
return this.classPassService;
|
|
6811
|
+
}
|
|
6531
6812
|
}
|
|
6532
6813
|
function createBookwhenClient(options) {
|
|
6533
6814
|
const {
|