UNPKG

@hubs101/booking-api-skd-client

Version:
415 lines (414 loc) 21.1 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseAPI = exports.getPublicExhibitionGroupsByCategory = exports.getPublicSpeakerGroupsByCategory = exports.getVisitor = exports.postInbound = exports.postVisitor = exports.getPublicCoLocatedEventsByEventId = exports.getPublicGroupDetailsById = exports.getPublicEventPageDetailsBySlug = exports.getPublicPortfolioEvents = exports.getPublicEventDetailsBySlug = exports.getPublicEventDetailsById = exports.getPublicPortfoliosByAccount = exports.getPublicAttendees = exports.getPublicTicketGroupsByEvent = exports.postPublicBookings = exports.postPublicBookingsMutation = exports.postPublicBookingsCheck = exports.getPublicPaymentMethods = exports.checkDiscountTicket = exports.getParamsTicket = exports.getTicketById = exports.getTicketByCode = exports.getPublicTickets = exports.getPublicEventExhibitions = exports.getPublicAgenda = exports.getPublicEvents = exports.assignTicketTo = exports.getPublicTicketDetails = void 0; const api_1 = require("./api"); const handleFetchErrors_1 = require("./handleFetchErrors"); const utils_1 = require("./utils"); const getPublicTicketDetails = ({ baseUrl, id, access, }) => __awaiter(void 0, void 0, void 0, function* () { let response; if (id) { response = yield fetch(`${(0, api_1.getApiPath)(baseUrl).PUBLIC_BOOKINGS}/${id}?access=${access}`); } const data = yield (response === null || response === void 0 ? void 0 : response.json()); const result = data === null || data === void 0 ? void 0 : data.result; return ((result === null || result === void 0 ? void 0 : result.data) || result); }); exports.getPublicTicketDetails = getPublicTicketDetails; const assignTicketTo = ({ baseUrl, id, access, reference, assignee, }) => __awaiter(void 0, void 0, void 0, function* () { var _a; let result; if (id) { result = yield (0, utils_1.postRequest)(`${(0, api_1.getApiPath)(baseUrl).PUBLIC_BOOKINGS}/${id}/assign/${reference}?access=${access}`, assignee); } return ((_a = result === null || result === void 0 ? void 0 : result.result) === null || _a === void 0 ? void 0 : _a.data) || (result === null || result === void 0 ? void 0 : result.result); }); exports.assignTicketTo = assignTicketTo; const getPublicEvents = ({ baseUrl, page = 0, slug, language, }) => __awaiter(void 0, void 0, void 0, function* () { const response = yield fetch(`${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}?limit=100&page=${page}${slug ? "&slug=" + slug : ""}${language ? "&lang=" + language : ""}`); const data = yield response.json(); (0, handleFetchErrors_1.handleFetchErrors)(data); return { events: data, }; }); exports.getPublicEvents = getPublicEvents; const getPublicAgenda = ({ baseUrl, page = 0, eventId, language, }) => __awaiter(void 0, void 0, void 0, function* () { var _b; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}/${eventId}/agenda?limit=100&page=${page}${language ? "&lang=" + language : ""}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { const agenda = (_b = data === null || data === void 0 ? void 0 : data.result) === null || _b === void 0 ? void 0 : _b.data; return agenda; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicAgenda = getPublicAgenda; const getPublicEventExhibitions = ({ baseUrl, page = 0, eventId, language, }) => __awaiter(void 0, void 0, void 0, function* () { var _c; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}/${eventId}/exhibitions?limit=2000&${page ? "&page=" + page : ""}${language ? "&lang=" + language : ""}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { const exhibitions = (_c = data === null || data === void 0 ? void 0 : data.result) === null || _c === void 0 ? void 0 : _c.data; return exhibitions; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicEventExhibitions = getPublicEventExhibitions; const getPublicTickets = ({ baseUrl, page = 0, ticketCode, eventSlug, language, }) => __awaiter(void 0, void 0, void 0, function* () { const response = yield fetch(`${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_TICKETS}?limit=2000&page=${page}${ticketCode ? "&code=" + ticketCode : ""}${eventSlug ? "&slug=" + eventSlug : ""}${language ? "&lang=" + language : ""}`); const data = yield response.json(); (0, handleFetchErrors_1.handleFetchErrors)(data); return { tickets: data, }; }); exports.getPublicTickets = getPublicTickets; const getTicketByCode = ({ baseUrl, code, }) => __awaiter(void 0, void 0, void 0, function* () { var _d; if (!code) return; const response = yield fetch(`${(0, api_1.getApiPath)(baseUrl).PUBLIC_TICKETS}?code=${code}`); const data = yield response.json(); const result = data.result; return { ticket: (_d = result.data) === null || _d === void 0 ? void 0 : _d[0], }; }); exports.getTicketByCode = getTicketByCode; const getTicketById = ({ baseUrl, id, }) => __awaiter(void 0, void 0, void 0, function* () { var _e; if (!id) return; const response = yield fetch(`${(0, api_1.getApiPath)(baseUrl).PUBLIC_TICKETS}?id=${id}`); const data = yield response.json(); const result = data.result; return { ticket: (_e = result.data) === null || _e === void 0 ? void 0 : _e[0], }; }); exports.getTicketById = getTicketById; const getParamsTicket = ({ baseUrl, params, }) => __awaiter(void 0, void 0, void 0, function* () { var _f; if (!params) return; const response = yield fetch(`${(0, api_1.getApiPath)(baseUrl).PUBLIC_TICKETS}?${params}`); const data = yield response.json(); const result = data.result; return { ticket: (_f = result.data) === null || _f === void 0 ? void 0 : _f[0], }; }); exports.getParamsTicket = getParamsTicket; const checkDiscountTicket = ({ baseUrl, ticketsIds, discountCode, language, eventId, }) => __awaiter(void 0, void 0, void 0, function* () { const ticketsIdsParam = ticketsIds.join(","); const response = yield fetch(`${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_TICKETS}/discount?tickets=${ticketsIdsParam}&code=${discountCode}${language ? "&lang=" + language : ""}&event=${eventId}`); const data = yield response.json(); (0, handleFetchErrors_1.handleFetchErrors)(data); return { discount: data, }; }); exports.checkDiscountTicket = checkDiscountTicket; const getPublicPaymentMethods = ({ id, baseUrl, language, }) => __awaiter(void 0, void 0, void 0, function* () { const response = yield fetch(`${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}/${id}/payment-methods${language ? "?lang=" + language : ""}`); const data = yield (response === null || response === void 0 ? void 0 : response.json()); (0, handleFetchErrors_1.handleFetchErrors)(data); return { paymentMethods: data, }; }); exports.getPublicPaymentMethods = getPublicPaymentMethods; const postPublicBookingsCheck = ({ baseUrl, bookingCheck, language, }) => __awaiter(void 0, void 0, void 0, function* () { var _g; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).PUBLIC_BOOKINGS}/check${language ? "?lang=" + language : ""}`; const response = yield fetch(endpointURL, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(bookingCheck), }); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { const bookingsCheck = (_g = data === null || data === void 0 ? void 0 : data.result) === null || _g === void 0 ? void 0 : _g.data; return bookingsCheck; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.postPublicBookingsCheck = postPublicBookingsCheck; const postPublicBookingsMutation = ({ baseUrl, bookingCheck, language, }) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.postPublicBookings)({ baseUrl, bookingCheck, language, }); }); exports.postPublicBookingsMutation = postPublicBookingsMutation; const postPublicBookings = ({ baseUrl, bookingCheck, language, }) => __awaiter(void 0, void 0, void 0, function* () { const response = yield fetch(`${(0, api_1.getApiPath)(baseUrl).PUBLIC_BOOKINGS}${language ? "?lang=" + language : ""}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(bookingCheck), }); const data = yield response.json(); (0, handleFetchErrors_1.handleFetchErrors)(data); return { bookings: data, }; }); exports.postPublicBookings = postPublicBookings; const getPublicTicketGroupsByEvent = ({ baseUrl, eventId, language, }) => __awaiter(void 0, void 0, void 0, function* () { const response = yield fetch(`${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_TICKETS}/groups?event=${eventId}${language ? "&lang=" + language : ""}`); const data = yield (response === null || response === void 0 ? void 0 : response.json()); (0, handleFetchErrors_1.handleFetchErrors)(data); return { ticketGroups: data, }; }); exports.getPublicTicketGroupsByEvent = getPublicTicketGroupsByEvent; const getPublicAttendees = ({ baseUrl, eventId, params, }) => __awaiter(void 0, void 0, void 0, function* () { var _h; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}/${eventId}/attendees${params ? params : ""}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { return { attendees: (_h = data === null || data === void 0 ? void 0 : data.result) === null || _h === void 0 ? void 0 : _h.data, }; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicAttendees = getPublicAttendees; const getPublicPortfoliosByAccount = ({ baseUrl, accountId, page = 1, slug, }) => __awaiter(void 0, void 0, void 0, function* () { const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_ACCOUNTS}/${accountId}/portfolios?limit=100&page=${page}${slug ? "&slug=" + slug : ""}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { const portfolios = data === null || data === void 0 ? void 0 : data.result; return portfolios; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicPortfoliosByAccount = getPublicPortfoliosByAccount; const getPublicEventDetailsById = ({ baseUrl, eventId, }) => __awaiter(void 0, void 0, void 0, function* () { var _j; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}/${eventId}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { const eventDetails = (_j = data === null || data === void 0 ? void 0 : data.result) === null || _j === void 0 ? void 0 : _j.data; return eventDetails; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicEventDetailsById = getPublicEventDetailsById; const getPublicEventDetailsBySlug = ({ baseUrl, eventSlug, }) => __awaiter(void 0, void 0, void 0, function* () { var _k; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}?slug=${eventSlug}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { const eventDetails = (_k = data === null || data === void 0 ? void 0 : data.result) === null || _k === void 0 ? void 0 : _k.data; return eventDetails; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicEventDetailsBySlug = getPublicEventDetailsBySlug; const getPublicPortfolioEvents = ({ baseUrl, accountId, portfolioSlug, params, }) => __awaiter(void 0, void 0, void 0, function* () { const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_ACCOUNTS}/${accountId}/portfolios/${portfolioSlug}/events?limit=100${params}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { const events = data === null || data === void 0 ? void 0 : data.result; return events; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicPortfolioEvents = getPublicPortfolioEvents; const getPublicEventPageDetailsBySlug = ({ baseUrl, eventId, pageSlug, }) => __awaiter(void 0, void 0, void 0, function* () { var _l; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}/${eventId}/pages/${pageSlug}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { return (_l = data === null || data === void 0 ? void 0 : data.result) === null || _l === void 0 ? void 0 : _l.data; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicEventPageDetailsBySlug = getPublicEventPageDetailsBySlug; const getPublicGroupDetailsById = ({ baseUrl, groupId, }) => __awaiter(void 0, void 0, void 0, function* () { var _m; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_GROUPS}/${groupId}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { return (_m = data === null || data === void 0 ? void 0 : data.result) === null || _m === void 0 ? void 0 : _m.data; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicGroupDetailsById = getPublicGroupDetailsById; const getPublicCoLocatedEventsByEventId = ({ baseUrl, eventId, }) => __awaiter(void 0, void 0, void 0, function* () { var _o; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}/${eventId}/colocated-events`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { return (_o = data === null || data === void 0 ? void 0 : data.result) === null || _o === void 0 ? void 0 : _o.data; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicCoLocatedEventsByEventId = getPublicCoLocatedEventsByEventId; const postVisitor = ({ visitorData, }) => __awaiter(void 0, void 0, void 0, function* () { const endpointURL = api_1.INBOUND_URL.VISITOR; const response = yield fetch(endpointURL, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(visitorData), }); const data = (yield response.json()); if (data) { const visitor = data === null || data === void 0 ? void 0 : data.data; return visitor; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.postVisitor = postVisitor; const postInbound = ({ inboundData, secret, }) => __awaiter(void 0, void 0, void 0, function* () { const endpointURL = `${api_1.INBOUND_URL.INBOUND}?secret=${secret}`; const response = yield fetch(endpointURL, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(inboundData), }); const data = (yield response.json()); if (data) { return data; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.postInbound = postInbound; const getVisitor = ({ visitorId, secret, }) => __awaiter(void 0, void 0, void 0, function* () { const endpointURL = `${api_1.INBOUND_URL.VISITOR}/${visitorId}/?secret=${secret}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data) { return data === null || data === void 0 ? void 0 : data.data; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getVisitor = getVisitor; const getPublicSpeakerGroupsByCategory = ({ baseUrl, eventId, category, }) => __awaiter(void 0, void 0, void 0, function* () { var _p; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}/${eventId}/groups/speaker/${category}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { return (_p = data === null || data === void 0 ? void 0 : data.result) === null || _p === void 0 ? void 0 : _p.data; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicSpeakerGroupsByCategory = getPublicSpeakerGroupsByCategory; const getPublicExhibitionGroupsByCategory = ({ baseUrl, eventId, category, }) => __awaiter(void 0, void 0, void 0, function* () { var _q; const endpointURL = `${(0, api_1.getApiPath)(baseUrl).WEBSITE_PUBLIC_EVENTS}/${eventId}/groups/exhibition/${category}`; const response = yield fetch(endpointURL); const data = (yield response.json()); if (data === null || data === void 0 ? void 0 : data.result) { return (_q = data === null || data === void 0 ? void 0 : data.result) === null || _q === void 0 ? void 0 : _q.data; } else { (0, handleFetchErrors_1.handleFetchErrors)(data, endpointURL); return undefined; } }); exports.getPublicExhibitionGroupsByCategory = getPublicExhibitionGroupsByCategory; exports.BaseAPI = { getPublicEvents: exports.getPublicEvents, getPublicTicketDetails: exports.getPublicTicketDetails, assignTicketTo: exports.assignTicketTo, getPublicTickets: exports.getPublicTickets, getTicketByCode: exports.getTicketByCode, getTicketById: exports.getTicketById, getParamsTicket: exports.getParamsTicket, checkDiscountTicket: exports.checkDiscountTicket, getPublicPaymentMethods: exports.getPublicPaymentMethods, postPublicBookingsCheck: exports.postPublicBookingsCheck, postPublicBookingsMutation: exports.postPublicBookingsMutation, postPublicBookings: exports.postPublicBookings, getPublicTicketGroupsByEvent: exports.getPublicTicketGroupsByEvent, getPublicAttendees: exports.getPublicAttendees, getPublicPortfoliosByAccount: exports.getPublicPortfoliosByAccount, getPublicEventDetailsById: exports.getPublicEventDetailsById, getPublicEventDetailsBySlug: exports.getPublicEventDetailsBySlug, getPublicPortfolioEvents: exports.getPublicPortfolioEvents, getPublicEventPageDetailsBySlug: exports.getPublicEventPageDetailsBySlug, getPublicGroupDetailsById: exports.getPublicGroupDetailsById, getPublicCoLocatedEventsByEventId: exports.getPublicCoLocatedEventsByEventId, getPublicEventExhibitions: exports.getPublicEventExhibitions, postVisitor: exports.postVisitor, postInbound: exports.postInbound, getPublicSpeakerGroupsByCategory: exports.getPublicSpeakerGroupsByCategory, getPublicExhibitionGroupsByCategory: exports.getPublicExhibitionGroupsByCategory };