UNPKG

tickethead-sdk

Version:

SDK for the Tickethead API

107 lines 4.6 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.PdfService = void 0; const query_1 = require("../common/query"); class PdfService { constructor(client, version) { this.client = client; this.version = version; } /** * Returns true if the service is reachable * * @returns Services' online status */ health() { return __awaiter(this, void 0, void 0, function* () { try { const res = yield this.client.get(`pdf/health`); if (res.data.status.toLowerCase() === 'ok') { return { online: true }; } } catch (e) { // Do nothing } return { online: false }; }); } /** * Create a PDF template for a specific organizer * Requires the `event.event.create` org level permission for the organizer * @param orgName.name The specified organizer * @param template The PDF template that should be created * @throws `ApiError` when the QR code image is missing */ createPdfTemplate(orgName, template) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`/pdf/v1/organizer/${orgName.name}/template`, template); return res.data.data; }); } /** * Update an existing PDF template * Requires the `event.event.create` org level permission for the organizer * @param id.id ID of the PDF template * @param id.organizerId Name of the organizer * @param template The updated PDF template * @throws `ApiError` when the QR code image is missing */ updatePdfTemplate(id, template) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.patch(`/pdf/v1/organizer/${id.organizerId}/template/${id.id}`, template); return res.data.data; }); } /** * Get a single PDF template by the ID * Requires the `event.event.create` org level permission for the organizer * @param id.id The PDF templates ID * @param id.organizerId Name of the organizer the PDF template is belonging to */ getSinglePdfTemplate(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`/pdf/v1/organizer/${id.organizerId}/template/${id.id}`); return res.data.data; }); } /** * Query the PDF template for a specific organizer * Requires the `event.event.create` org level permission for the organizer * @param orgName.name Name of the organizer the PDF templates are belonging to * @param query.name Query PDF templates by the `name` */ getListPdfTemplate(orgName_1) { return __awaiter(this, arguments, void 0, function* (orgName, query = {}) { const res = yield this.client.get(`/pdf/v1/organizer/${orgName.name}/template?${(0, query_1.getStringifiedQuery)(query)}`); const data = res.data; return { data: data.data, paging: { limit: data.limit, offset: data.offset, total: data.total }, }; }); } /** * Render a PDF with a custom template. Requires event permission for any organizer. * @param request.template The custom Scriban template created with our PDF template editor * @param request.pdfTicket Data that will be passed to the template * @returns Rendered PDF */ renderPdfWithCustomTemplate(request) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`/pdf/v1/organizer/custom-template/ticket`, request, { responseType: 'blob' }); return res.data; }); } } exports.PdfService = PdfService; //# sourceMappingURL=service.js.map