UNPKG

tickethead-sdk

Version:

SDK for the Tickethead API

89 lines 3.56 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.ValidatorService = void 0; const query_1 = require("../common/query"); /** * Service class for validator API calls. */ class ValidatorService { 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(`account/health`); if (res.data.status === 'ok') { return { online: true }; } } catch (e) { // Do nothing } return { online: false }; }); } /** * Returns the validator using the given token * * @param token token for fetching the validator * @returns Validator object * @throws `NotFoundError` */ getValidatorByToken(token) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/organizer/validator/${token.token}`); return res.data.data; }); } getExportedValidators(id, query) { return __awaiter(this, void 0, void 0, function* () { const queryStringified = (0, query_1.getStringifiedQuery)({ event_id: query.event_id, }); const res = yield this.client.get(`account/${this.version}/organizer/${id.id}/validator/export?${queryStringified}`); return res.data.data; }); } /** * Creates a new user which can validate tickets for the specified org. * @param organizerId.id Name or ID of the organizer to whom the validator belongs to * @param validator Validator data (eventId which signals for which event is the validator) * @returns new Validator */ createValidator(organizerId, validator) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/organizer/${organizerId.id}/validator`, validator); return res.data.data; }); } /** * Fetches validator data. * @param id.organizerId Name or ID of the organizer to whom the validator belongs to * @param id.id ID of the validator to be fetched * @returns requested Validator */ getValidator(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/organizer/${id.organizerId}/validator/${id.id}`); return res.data.data; }); } } exports.ValidatorService = ValidatorService; //# sourceMappingURL=service.js.map