UNPKG

tickethead-sdk

Version:

SDK for the Tickethead API

709 lines 26.2 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AccountService = void 0; const query_string_1 = __importDefault(require("query-string")); const types_1 = require("./types"); const query_1 = require("../common/query"); /** * Service class for account API calls. */ class AccountService { 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 organizer with the given name or id. * Currently an organizer only has one workspace. * * @param req name of the organizer * @returns Seats workspaces for the organizer * @throws `NotFoundError` */ getSeatsWorkspacesForOrganizer(req) { return __awaiter(this, void 0, void 0, function* () { const query = query_string_1.default.stringify({ organizer_name: req.id, }, { arrayFormat: 'comma' }); const res = yield this.client.get(`account/${this.version}/seats-workspace?${query}`); return res.data.data; }); } /** * List all organizers * * @returns array of Organizer objects */ listOrganizers() { return __awaiter(this, arguments, void 0, function* (query = {}) { const queryString = (0, query_1.getStringifiedQuery)(query); const res = yield this.client.get(`account/${this.version}/organizer?${queryString}`); return res.data.data; }); } /** * Returns the organizer with the given name or id. * * @param req id or name of the organizer * @returns Organizer object * @throws `NotFoundError` */ getOrganizer(req) { return __awaiter(this, void 0, void 0, function* () { const query = query_string_1.default.stringify({ fields: req.fields, }, { arrayFormat: 'comma' }); const res = yield this.client.get(`account/${this.version}/organizer/${req.id}?${query}`); return res.data.data; }); } /** * Create an organizer * * @param org New organizer data * @returns Organizer object * @throws `BadRequestError` */ createOrganizer(org) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/organizer`, org); return res.data.data; }); } /** * Updates an organizer * * @param id.id name or id of the organizer * @param org updated organizer data * @returns Organizer object */ updateOrganizer(id, org) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.patch(`account/${this.version}/organizer/${id.id}`, org); return res.data.data; }); } /** * Returns the user with the given id. * * @param req id of the user * @returns User object * @throws `NotFoundError` */ getUser(req) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/user/${req.id}`); return res.data.data; }); } /** * Returns the user with the given email. * * @param email email of the user * @returns User object * @throws `NotFoundError` */ getUserByEmail(email) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/user/email/${email.email}`); return res.data.data; }); } /** * Creates a new user * * @param user User data * @returns User object * @throws `BadRequestError` */ createUser(user) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/user`, user); return res.data.data; }); } /** * Creates and adds an user to an organizer * * @param user User data and permissions * @returns User object * @throws `BadRequestError` */ inviteUser(user) { return __awaiter(this, void 0, void 0, function* () { if (user.grantedPermissions != null) { user.role = types_1.Roles.Custom; } const res = yield this.client.post(`account/${this.version}/user/invite`, user); return res.data.data; }); } /** * Update a user * If a new email is sent, it needs to be confirmed * * @param user User data * @returns User object * @throws `BadRequestError`, `NotFoundError` */ updateUser(id, user) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.patch(`account/${this.version}/user/${id.id}`, user); return res.data.data; }); } /** * Initiate password reset process for a given email (i.e. user) * * @param email of the user which wants to reset the password */ resetUserPassword(email) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/user/password/reset`, { email: email.email }); return res.data.data; }); } /** * Complete the password reset process * * @param data reset code and the new password */ confirmPasswordReset(data) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/user/password/${data.resetCode}`, { password: data.password }); return res.data.data; }); } /** * Resend the verification link to an unverified user. * * @param email Email of the user for which the verification link should be resent. If unspecified, resend the link for the current user. * @throws `BadRequestError` if the user is already verified. * ForbiddenError if the user without correct privileges tries to resend an email for another user * @deprecated replace with resendEmailVerification in-place */ resendUserVerification(email) { return __awaiter(this, void 0, void 0, function* () { yield this.resendEmailVerification(email); }); } /** * Resend the verification link to an unverified user. * * @param email Email of the user for which the verification link should be resent. If unspecified, resend the link for the current user. * @throws `BadRequestError` if the user is already verified. * ForbiddenError if the user without correct privileges tries to resend an email for another user */ resendEmailVerification(email) { return __awaiter(this, void 0, void 0, function* () { const body = {}; if (email === null || email === void 0 ? void 0 : email.email) { body.email = email.email; } yield this.client.post(`account/${this.version}/user/verify/resend`, body); }); } /** * Verifies the email of the user with the verification code received by email * * @param code An object containing the email verification code * @throws `NotFoundError` if the code does not exist * @throws `BadRequestError` if the code has expired */ verifyEmail(code) { return __awaiter(this, void 0, void 0, function* () { yield this.client.get(`account/${this.version}/user/verify/${code.code}`); }); } /** * Sends a phone verification SMS to the currently authorized user * * @throws `BadRequestError` if the phone number is not in the correct format (E164) * @throws `BadRequestError` if the user is already verified * @throws `BadRequestError` if it is too soon to send a new code * @throws `NotFoundError` if the authorization is for a user which was deleted * */ sendPhoneVerification() { return __awaiter(this, void 0, void 0, function* () { yield this.client.post(`account/${this.version}/user/verify/phone/request`, {}); }); } /** * The verification code is delivered to the user's phone. * You can request it again with the `sendPhoneVerification` method. * The user doesn't have to be logged in to verify their account. * * @param code An object containing the code the user received on their phone * @param credentials Optionally, if the user hasn't logged in, you can verify the phone by providing the credentials here. * @throws `BadRequestError` if you don't provide authorization or credentials * @throws `NotFoundError` if the user does not exist * */ verifyPhone(code, credentials) { return __awaiter(this, void 0, void 0, function* () { let body = {}; if (credentials != null) { body = credentials; } const res = yield this.client.post(`account/${this.version}/user/verify/phone/${code.code}`, body); return res.data.data; }); } /** * Deletes a user * * @param id ID of the user to delete * @throws `NotFoundError` */ deleteUser(id) { return __awaiter(this, void 0, void 0, function* () { yield this.client.delete(`account/${this.version}/user/${id.id}`); }); } /** * List users belonging to a specific organizer. * * @param id.id Id or name of the organizer * @param query Additional fields that should be fetched with the users. */ listUsersInOrganization(id_1) { return __awaiter(this, arguments, void 0, function* (id, query = {}) { const queryString = (0, query_1.getStringifiedQuery)(query); const res = yield this.client.get(`account/${this.version}/organizer/${id.id}/users?${queryString}`); return res.data.data; }); } /** * Use this method to list the users. * @param query.email Query the users by the email * @param query.deleted Only returns deleted users */ listUsers() { return __awaiter(this, arguments, void 0, function* (query = {}) { const queryString = (0, query_1.getStringifiedQuery)(query); const res = yield this.client.get(`account/${this.version}/user?${queryString}`); return res.data.data; }); } /** * Gets public info for a user with the enrollment id * * @param id enrollment ID of the user * @throws `NotFoundError` */ checkEnrollment(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/user/enrollment/${id.enrollmentId}`); return res.data.data; }); } /** * Set a user's permissions. * The caller need to have the `*.change_permission` permission for each class of permissions which are granted. * * @param id Id of the user * @param perms Set of new permissions for the user * @returns User object * @throws `BadRequestError`, `NotFoundError`, `ForbiddenError` */ setPermissions(id, perms) { return __awaiter(this, void 0, void 0, function* () { // Granted permissions object won't be used otherwise if (perms.grantedPermissions != null) { perms.role = types_1.Roles.Custom; } const res = yield this.client.patch(`account/${this.version}/user/${id.id}/permission`, perms); return res.data.data; }); } /** * Creates a new certificate and private key for a user. * If there is no authorization, a new user and their wallet will be created. * * @returns User IDs, certificate and private key */ createWallet() { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/certificate/enroll`, {}); return res.data.data; }); } /** * Renews the certificate and private key for a user. * * @returns User IDs, certificate and private key */ renewWallet() { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/certificate/renew`, {}); return res.data.data; }); } /** * Revoke the user's certificate. * * @returns User IDs, certificate and private key * @throws `BadRequestError` if the certificate revocation failed * @throws `NotFoundError` if the user hasn't created a wallet */ revokeWallet(data) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/certificate/revoke`, data); return res.data.data; }); } /** * Return the market rules for the given ruleset * @param marketRulesetId * @returns */ getMarketControlSettings(marketRulesetId) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/market-control/${marketRulesetId.id}`); return res.data.data; }); } /** * Create a secondary market ruleset for an organizer * @param marketRuleset Ruleset data */ createMarketControlSettings(marketRuleset) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/market-control`, marketRuleset); return res.data.data; }); } /** * Update a secondary market ruleset * @param id Id of the ruleset * @param marketRuleset Updated ruleset data */ updateMarketControlSettings(id, marketRuleset) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.patch(`account/${this.version}/market-control/${id.id}`, marketRuleset); return res.data.data; }); } /** * Delete a secondary market ruleset * @param id Id of the ruleset */ deleteMarketControlSettings(id) { return __awaiter(this, void 0, void 0, function* () { yield this.client.delete(`account/${this.version}/market-control/${id.id}`); }); } /** * Fetch QR code data for publishing the ruleset on the chain * @param id Id of the ruleset */ getMarketControlSettingsQRCodePayload(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/market-control/${id.id}/qr-payload`); return res.data.data; }); } /** * List the secondary market rulesets */ listMarketControlSettings() { return __awaiter(this, arguments, void 0, function* (query = {}) { const queryString = (0, query_1.getStringifiedQuery)(query); const res = yield this.client.get(`account/${this.version}/market-control?${queryString}`); return res.data.data; }); } /** * Get fee by id * @param id Id of the fee */ getFee(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/fee/${id.id}`); return res.data.data; }); } /** * List fees * @param query search parameters */ listFees(query) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/fee?${(0, query_1.getStringifiedQuery)(query)}`); return res.data.data; }); } /** * Create a fee for the organizer. Requires administrative rights. * @param fee Fee data */ createFee(fee) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/fee`, fee); return res.data.data; }); } /** * Update fee data. Requires administrative rights. * @param id Id of the fee * @param fee Updated fee data */ updateFee(id, fee) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.patch(`account/${this.version}/fee/${id.id}`, fee); return res.data.data; }); } /** * List all registered KYC levels */ listKycLevels() { return __awaiter(this, arguments, void 0, function* (query = {}) { const queryString = (0, query_1.getStringifiedQuery)(query); const res = yield this.client.get(`account/${this.version}/kyc?${queryString}`); return res.data.data; }); } /** * List all registered currencies */ listCurrencies() { return __awaiter(this, arguments, void 0, function* (query = {}) { const queryString = (0, query_1.getStringifiedQuery)(query); const res = yield this.client.get(`account/${this.version}/currency?${queryString}`); return res.data.data; }); } /** * Starts the onboarding process for the payment provider * * @param id.id name or id of the organizer * @param onboardPayload return and refresh urls * @returns redirect url */ onboardStripeConnect(id, onboardPayload) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/organizer/${id.id}/onboard/stripe`, onboardPayload); return res.data.data; }); } /** * Gets the onboarding status for the payment provider * * @param id.id name or id of the organizer * @returns data about the completeness of the onboarding process */ getStripeConnectStatus(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/organizer/${id.id}/onboard/stripe`); return res.data.data; }); } /** * Returns a guest access token for our reporting dashboard * * @param req parameters for the dashboard token * @returns token used for accessing the dashboard */ getReportingToken(req) { return __awaiter(this, void 0, void 0, function* () { const payload = { dashboardId: req.dashboardId, }; if (req.eventId) { payload.eventId = req.eventId; } if (req.parentEventId) { payload.parentEventId = req.parentEventId; } const res = yield this.client.post(`account/${this.version}/organizer/${req.organizerId}/report/token`, payload); return res.data.data; }); } /** * Get a domain by its ID * @param id Id of the domain */ getDomain(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/domain/${id.id}`); return res.data.data; }); } /** * Lists or searches for domains. Returns associated organizers for each domain. */ listDomains(queryReq) { return __awaiter(this, void 0, void 0, function* () { const query = query_string_1.default.stringify(queryReq); const res = yield this.client.get(`account/${this.version}/domain?${query}`); return res.data.data; }); } /** * Create a domain for the organizer. Requires permissions for that organizer. * @param domain Domain name and either the organizer ID or the organizer name */ createDomain(domain) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/domain`, domain); return res.data.data; }); } /** * Update domain data. Requires permissions for that organizer. * @param id Id of the domain * @param domain Updated domain name */ updateDomain(id, domain) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.patch(`account/${this.version}/domain/${id.id}`, domain); return res.data.data; }); } /** * Delete a domain. Requires permissions for that organizer. * @param id Id of the domain */ deleteDomain(id) { return __awaiter(this, void 0, void 0, function* () { yield this.client.delete(`account/${this.version}/domain/${id.id}`); }); } /** * Get a newsletter by its ID */ getNewsletter(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/newsletter/${id.id}`); return res.data.data; }); } /** * Lists all newsletters */ listNewsletters(queryReq) { return __awaiter(this, void 0, void 0, function* () { const query = query_string_1.default.stringify(queryReq); const res = yield this.client.get(`account/${this.version}/newsletter?${query}`); return res.data.data; }); } /** * Create a newsletter. Requires permissions for the main organizer. * @param newsletter Subject and content. It will be put in the `info` email template. */ createNewsletter(newsletter) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/newsletter`, newsletter); return res.data.data; }); } /** * Update newsletter content. Requires permissions for the main organizer. * @param id ID of the newsletter * @param newsletter Updated content */ updateNewsletter(id, newsletter) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.patch(`account/${this.version}/newsletter/${id.id}`, newsletter); return res.data.data; }); } /** * Delete a newsletter. Requires permissions for the main organizer. */ deleteNewsletter(id) { return __awaiter(this, void 0, void 0, function* () { yield this.client.delete(`account/${this.version}/newsletter/${id.id}`); }); } /** * Sends out the emails containing the newsletter content. * Requires permissions for the main organizer. * The newsletter will be marked as sent, but it can still be updated and resent. * * @param id ID of the newsletter to send */ sendNewsletter(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/newsletter/${id.id}/send`, {}); return res.data.data; }); } /** * Creates new branding settings for the organizer. * @param id.id organizer id * @param brandingData branding data */ createBrandingSettings(id, brandingData) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`account/${this.version}/organizer/${id.id}/branding`, brandingData); return res.data.data; }); } /** * Updates branding settings for the organizer. * @param id.id organizer id * @param brandingData updated branding data */ updateBrandingSettings(id, brandingData) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.patch(`account/${this.version}/organizer/${id.id}/branding`, brandingData); return res.data.data; }); } /** * Returns branding settings for the organizer. * @param id.id organizer id */ getBrandingSettings(id) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`account/${this.version}/organizer/${id.id}/branding`); return res.data.data; }); } /** * Deletes branding settings for the organizer. * @param id.id organizer id */ deleteBrandingSettings(id) { return __awaiter(this, void 0, void 0, function* () { yield this.client.delete(`account/${this.version}/organizer/${id.id}/branding`); }); } } exports.AccountService = AccountService; //# sourceMappingURL=service.js.map