UNPKG

coconut-open-api-js

Version:
1,417 lines (1,384 loc) 80.1 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var axios = _interopDefault(require('axios')); var uuid = _interopDefault(require('uuid/v4')); function legacyEncode(str) { return encodeURIComponent(str) .replace(/%3A/gi, ':') .replace(/%24/g, '$') .replace(/%2C/gi, ',') .replace(/%20/g, '+') .replace(/%5B/gi, '[') .replace(/%5D/gi, ']'); } function isURLSearchParams(value) { return typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams; } function legacyParamsSerializer(params) { if (!params) { return ''; } if (isURLSearchParams(params)) { return params.toString(); } var parts = []; Object.keys(params).forEach(function (rawKey) { var val = params[rawKey]; if (val === null || typeof val === 'undefined') { return; } var key = rawKey; if (Array.isArray(val)) { key = key + '[]'; } else { val = [val]; } val.forEach(function (v) { if (v === null || typeof v === 'undefined') { return; } if (v instanceof Date) { v = v.toISOString(); } else if (v && typeof v === 'object') { v = JSON.stringify(v); } parts.push(legacyEncode(key) + '=' + legacyEncode(v)); }); }); return parts.join('&'); } var Client = function (domain) { return axios.create({ baseURL: domain ? "https://".concat(domain, ".coconutcalendar.com/api/v2/open") : "".concat(window.location.origin, "/api/v2/open"), headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest', }, paramsSerializer: { serialize: legacyParamsSerializer, }, }); }; var Days = (function () { function Days() { } Object.defineProperty(Days, "SUNDAY", { get: function () { return 0; }, enumerable: false, configurable: true }); Object.defineProperty(Days, "MONDAY", { get: function () { return 1; }, enumerable: false, configurable: true }); Object.defineProperty(Days, "TUESDAY", { get: function () { return 2; }, enumerable: false, configurable: true }); Object.defineProperty(Days, "WEDNESDAY", { get: function () { return 3; }, enumerable: false, configurable: true }); Object.defineProperty(Days, "THURSDAY", { get: function () { return 4; }, enumerable: false, configurable: true }); Object.defineProperty(Days, "FRIDAY", { get: function () { return 5; }, enumerable: false, configurable: true }); Object.defineProperty(Days, "SATURDAY", { get: function () { return 6; }, enumerable: false, configurable: true }); return Days; }()); var MeetingMethods = (function () { function MeetingMethods() { } Object.defineProperty(MeetingMethods, "AT_LOCATION", { get: function () { return 1; }, enumerable: false, configurable: true }); Object.defineProperty(MeetingMethods, "PHONE_CALL", { get: function () { return 2; }, enumerable: false, configurable: true }); Object.defineProperty(MeetingMethods, "VIDEO_CALL", { get: function () { return 3; }, enumerable: false, configurable: true }); Object.defineProperty(MeetingMethods, "OFF_SITE", { get: function () { return 4; }, enumerable: false, configurable: true }); return MeetingMethods; }()); var Notifications = (function () { function Notifications() { } Object.defineProperty(Notifications, "CLIENT", { get: function () { return { client: true, }; }, enumerable: false, configurable: true }); Object.defineProperty(Notifications, "USER", { get: function () { return { user: true, }; }, enumerable: false, configurable: true }); Object.defineProperty(Notifications, "ALL", { get: function () { return { client: true, user: true, }; }, enumerable: false, configurable: true }); return Notifications; }()); var Origins = (function () { function Origins() { } Object.defineProperty(Origins, "UNKNOWN", { get: function () { return 0; }, enumerable: false, configurable: true }); Object.defineProperty(Origins, "API", { get: function () { return 4; }, enumerable: false, configurable: true }); Object.defineProperty(Origins, "MODERN_CLIENT_VIEW", { get: function () { return 9; }, enumerable: false, configurable: true }); return Origins; }()); var Visibilities = (function () { function Visibilities() { } Object.defineProperty(Visibilities, "PUBLIC", { get: function () { return 0; }, enumerable: false, configurable: true }); Object.defineProperty(Visibilities, "ALL", { get: function () { return 1; }, enumerable: false, configurable: true }); return Visibilities; }()); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __awaiter(thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } var Model = (function () { function Model() { this.attributes = {}; } Model.prototype.getAttributes = function () { return this.attributes; }; return Model; }()); var Answer = (function (_super) { __extends(Answer, _super); function Answer() { var _this = _super.call(this) || this; _this.attributes = { question: null, value: null, }; return _this; } Answer.prototype.for = function (question) { this.attributes.question = question; return this; }; Answer.prototype.is = function (value) { this.attributes.value = value; return this; }; Answer.prototype.transform = function () { return { attributes: { question_id: this.attributes.question, value: this.attributes.value, }, type: 'answers', }; }; return Answer; }(Model)); var Attendee = (function (_super) { __extends(Attendee, _super); function Attendee() { var _this = _super.call(this) || this; _this.attributes = { email: null, first_name: null, identifier: null, last_name: null, }; return _this; } Attendee.prototype.alias = function (alias) { this.attributes.alias = alias; return this; }; Attendee.prototype.answers = function (answers) { this.attributes.answers = Array.isArray(answers) ? answers : [answers]; return this; }; Attendee.prototype.as = function (identifier) { this.attributes.identifier = identifier; return this; }; Attendee.prototype.located = function (details) { this.attributes = __assign(__assign({}, this.attributes), details); return this; }; Attendee.prototype.messagable = function (messageable) { if (messageable === void 0) { messageable = true; } this.attributes.messagable = messageable; return this; }; Attendee.prototype.named = function (first, last) { this.attributes.first_name = first; this.attributes.last_name = last; return this; }; Attendee.prototype.provided = function (notes) { this.attributes.notes = notes; return this; }; Attendee.prototype.reachable = function (details) { this.attributes = __assign(__assign({}, this.attributes), details); return this; }; Attendee.prototype.responses = function (responses) { this.attributes.responses = Array.isArray(responses) ? responses : [responses]; return this; }; Attendee.prototype.speaks = function (language) { this.attributes.language = language; return this; }; Attendee.prototype.transform = function () { var parameters = this.parameters(); var answers = this.attributes.answers || []; if (answers.length > 0) { parameters = __assign(__assign({}, parameters), { relationships: { answers: { data: answers.map(function (answer) { return answer.transform(); }), }, } }); } var responses = this.attributes.responses || []; if (responses.length > 0) { parameters = __assign(__assign({}, parameters), { relationships: { responses: { data: responses.map(function (response) { return response.transform(); }), }, } }); } return parameters; }; Attendee.prototype.parameters = function () { var attributes = { address: this.attributes.address, cell_phone: this.attributes.cell_phone, city: this.attributes.city, country: this.attributes.country, email: this.attributes.email, external_id: this.attributes.alias, first_name: this.attributes.first_name, lang: this.attributes.language, last_name: this.attributes.last_name, notes: this.attributes.notes, phone: this.attributes.phone, prov_state: this.attributes.region, receive_sms: this.attributes.messagable, timezone: this.attributes.timezone, work_phone: this.attributes.work_phone, zip_postal: this.attributes.postcode, }; Object.keys(attributes).forEach(function (key) { var value = attributes[key]; if (value === undefined || value === null) { delete attributes[key]; } }); var parameters = { type: 'attendees', }; if (this.attributes.identifier) { parameters.id = this.attributes.identifier; } if (Object.keys(attributes).length > 0) { parameters.attributes = attributes; } return parameters; }; return Attendee; }(Model)); var Client$1 = (function (_super) { __extends(Client, _super); function Client() { var _this = _super.call(this) || this; _this.attributes = { email: null, first_name: null, last_name: null, receive_sms: false, }; return _this; } Client.prototype.alias = function (alias) { this.attributes.alias = alias; return this; }; Client.prototype.answers = function (answers) { this.attributes.answers = Array.isArray(answers) ? answers : [answers]; return this; }; Client.prototype.messagable = function (messageable) { if (messageable === void 0) { messageable = true; } this.attributes.receive_sms = messageable; return this; }; Client.prototype.named = function (first, last) { this.attributes.first_name = first; this.attributes.last_name = last; return this; }; Client.prototype.provided = function (notes) { this.attributes.notes = notes; return this; }; Client.prototype.reachable = function (details) { this.attributes = __assign(__assign({}, this.attributes), details); return this; }; Client.prototype.speaks = function (language) { this.attributes.lang = language; return this; }; Client.prototype.transform = function () { var parameters = this.parameters(); var answers = this.attributes.answers || []; if (answers.length > 0) { parameters = __assign(__assign({}, parameters), { relationships: { answers: { data: answers.map(function (answer) { return answer.transform(); }), }, } }); } return parameters; }; Client.prototype.parameters = function () { var attributes = { cell_phone: this.attributes.cell_phone, email: this.attributes.email, external_id: this.attributes.alias, first_name: this.attributes.first_name, lang: this.attributes.lang, last_name: this.attributes.last_name, notes: this.attributes.notes, receive_sms: this.attributes.receive_sms, }; Object.keys(attributes).forEach(function (key) { var value = attributes[key]; if (value === undefined || value === null) { delete attributes[key]; } }); var parameters = { type: 'client', }; if (Object.keys(attributes).length > 0) { parameters.attributes = attributes; } return parameters; }; return Client; }(Model)); var NEXT_AVAILABLE = 1; var CERTAIN_DAYS = 2; var Preference = (function (_super) { __extends(Preference, _super); function Preference() { var _this = _super.call(this) || this; _this.attributes = { day: null, end: null, start: null, type: null, }; return _this; } Preference.now = function () { var today = new Date(); var date = "".concat(today.getFullYear(), "-").concat(today.getMonth() + 1, "-").concat(today.getDate()); var time = "".concat(today.getHours(), ":").concat(today.getMinutes(), ":").concat(today.getSeconds()); return "".concat(date, " ").concat(time); }; Preference.prototype.between = function (start, end) { this.attributes.end = end; this.attributes.start = start; return this; }; Preference.prototype.next = function () { this.attributes.type = NEXT_AVAILABLE; return this; }; Preference.prototype.on = function (day) { this.attributes.day = day; this.attributes.type = CERTAIN_DAYS; return this; }; Preference.prototype.transform = function () { var attributes = this.attributes; Object.keys(attributes).forEach(function (key) { var value = attributes[key]; if (value === undefined || value === null) { delete attributes[key]; } }); if (attributes.type === Preference.NEXT_AVAILABLE) { attributes.start = Preference.now(); } return { attributes: this.attributes, type: 'request-preferences', }; }; Object.defineProperty(Preference, "NEXT_AVAILABLE", { get: function () { return NEXT_AVAILABLE; }, enumerable: false, configurable: true }); Object.defineProperty(Preference, "CERTAIN_DAYS", { get: function () { return CERTAIN_DAYS; }, enumerable: false, configurable: true }); return Preference; }(Model)); var Response = (function (_super) { __extends(Response, _super); function Response() { var _this = _super.call(this) || this; _this.attributes = { option: null, question: null, value: null, }; return _this; } Response.prototype.for = function (question) { this.attributes.question = question; return this; }; Response.prototype.is = function (value) { this.attributes.value = value; return this; }; Response.prototype.selected = function (option) { this.attributes.option = option; return this; }; Response.prototype.transform = function () { var attributes = { form_question_id: this.attributes.question, }; if (this.attributes.option) { attributes.form_option_id = this.attributes.option; } if (this.attributes.value) { attributes.value = this.attributes.value; } return { attributes: attributes, type: 'responses', }; }; return Response; }(Model)); var Conditional = (function () { function Conditional() { } Conditional.prototype.when = function (condition, callback) { if (condition) { callback(this); } return this; }; return Conditional; }()); var Appointment = (function (_super) { __extends(Appointment, _super); function Appointment(client) { var _this = _super.call(this) || this; _this.client = client; _this.filters = {}; _this.meta = {}; _this.relationships = { attendees: [], }; _this.utm = {}; _this.uploadedFiles = []; return _this; } Appointment.prototype.actingAs = function (identifier) { this.meta.booker = identifier; return this; }; Appointment.prototype.add = function (appointment) { return __awaiter(this, void 0, void 0, function () { var formData_1; return __generator(this, function (_a) { switch (_a.label) { case 0: if (!(this.uploadedFiles.length > 0)) return [3, 2]; formData_1 = new FormData(); formData_1.append('contentType', 'application/json; ext=bulk'); formData_1.append('data', JSON.stringify(this.addParams())); this.uploadedFiles.forEach(function (uploadedFile) { formData_1.append(uploadedFile.key, uploadedFile.file); }); formData_1.append('_method', 'PUT'); return [4, this.client.post("appointments/".concat(appointment, "/attendees"), formData_1)]; case 1: return [2, _a.sent()]; case 2: return [4, this.client.put("appointments/".concat(appointment, "/attendees"), this.addParams(), { headers: { 'Content-Type': 'application/json; ext=bulk', }, })]; case 3: return [2, _a.sent()]; } }); }); }; Appointment.prototype.at = function (location) { this.filters.location = location; return this; }; Appointment.prototype.attendedBy = function (users) { this.filters.users = users; return this; }; Appointment.prototype.book = function () { return __awaiter(this, void 0, void 0, function () { var formData_2; return __generator(this, function (_a) { switch (_a.label) { case 0: if (!(this.uploadedFiles.length > 0)) return [3, 2]; formData_2 = new FormData(); formData_2.append('data', JSON.stringify(this.params())); this.uploadedFiles.forEach(function (uploadedFile) { formData_2.append(uploadedFile.key, uploadedFile.file); }); return [4, this.client.post('appointments', formData_2)]; case 1: return [2, _a.sent()]; case 2: return [4, this.client.post('appointments', this.params())]; case 3: return [2, _a.sent()]; } }); }); }; Appointment.prototype.by = function (user) { this.filters.user = user; return this; }; Appointment.prototype.campaign = function (campaign) { this.utm.campaign = campaign; return this; }; Appointment.prototype.cancel = function (appointment, attendee, code) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4, this.client.delete("appointments/".concat(appointment, "/").concat(attendee), { data: this.params(), params: { code: code }, })]; case 1: return [2, _a.sent()]; } }); }); }; Appointment.prototype.content = function (content) { this.utm.content = content; return this; }; Appointment.prototype.for = function (services) { this.filters.services = services; return this; }; Appointment.prototype.get = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4, this.client.get('appointments', { params: this.filters.matchers, })]; case 1: return [2, _a.sent()]; } }); }); }; Appointment.prototype.in = function (timezone) { this.filters.timezone = timezone; return this; }; Appointment.prototype.matching = function (matchers) { this.filters.matchers = matchers; return this; }; Appointment.prototype.medium = function (medium) { this.utm.medium = medium; return this; }; Appointment.prototype.method = function (method) { this.filters.method = method; return this; }; Appointment.prototype.notify = function (notifications) { this.filters.notifications = notifications; return this; }; Appointment.prototype.recaptcha = function (recaptchaToken) { this.filters.recaptcha_token = recaptchaToken; return this; }; Appointment.prototype.reschedule = function (appointment, code) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4, this.client.patch("appointments/".concat(appointment, "?code=").concat(code), this.rescheduleParams(appointment))]; case 1: return [2, _a.sent()]; } }); }); }; Appointment.prototype.shortcut = function (shortcut) { this.filters.shortcut = shortcut; return this; }; Appointment.prototype.starting = function (start) { this.filters.start = start; return this; }; Appointment.prototype.source = function (source) { this.utm.source = source; return this; }; Appointment.prototype.supporting = function (locale) { this.filters.locale = locale; return this; }; Appointment.prototype.term = function (term) { this.utm.term = term; return this; }; Appointment.prototype.through = function (origin) { this.filters.through = origin; return this; }; Appointment.prototype.uploads = function (uploadedFiles) { this.uploadedFiles = uploadedFiles; return this; }; Appointment.prototype.via = function (invitation) { this.filters.invitation = invitation; return this; }; Appointment.prototype.with = function (attendees) { this.relationships.attendees = Array.isArray(attendees) ? attendees : [attendees]; return this; }; Appointment.prototype.withInviteOnly = function (inviteOnlyResources) { if (inviteOnlyResources === void 0) { inviteOnlyResources = true; } this.filters.invite_only_resources = inviteOnlyResources; return this; }; Appointment.prototype.withinUserCategory = function (userCategory) { this.filters.user_category = userCategory; return this; }; Appointment.prototype.withoutMeetingLink = function (skipMeetingLinkGeneration) { if (skipMeetingLinkGeneration === void 0) { skipMeetingLinkGeneration = true; } this.filters.skip_meeting_link_generation = skipMeetingLinkGeneration; return this; }; Appointment.prototype.workflow = function (workflow) { this.filters.workflow = workflow; return this; }; Appointment.prototype.addParams = function () { var params = { data: this.transformAttendees(), }; if (this.meta.booker) { params.meta = { booker: this.meta.booker, }; } if (this.filters.through) { params.meta = __assign(__assign({}, params.meta), { origin: this.filters.through }); } if (this.filters.notifications) { params.meta = __assign(__assign({}, params.meta), { notify: this.filters.notifications }); } return params; }; Appointment.prototype.hasUtm = function () { return !!this.utm.campaign || !!this.utm.content || !!this.utm.medium || !!this.utm.source || !!this.utm.term; }; Appointment.prototype.params = function () { if (this.relationships.attendees.length === 0) { return {}; } var params = { data: { relationships: { attendees: { data: this.transformAttendees(), }, }, type: 'appointments', }, }; if (this.filters.location || this.filters.services || this.filters.start) { params.data.attributes = { invitation_id: null, location_id: this.filters.location, service_id: this.filters.services, staff_id: null, start: this.filters.start, supported_locale: this.filters.locale || null, }; if (this.filters.recaptcha_token) { params.data.attributes.recaptcha_token = this.filters.recaptcha_token; } if (this.filters.user) { params.data.attributes.staff_id = this.filters.user; } if (this.filters.user_category) { params.data.attributes.staff_category_id = this.filters.user_category; } if (this.filters.users) { params.data.attributes.additional_staff_id = this.filters.users; } if (this.filters.invitation) { params.data.attributes.invitation_id = this.filters.invitation; } if (this.filters.invite_only_resources) { params.data.attributes.invite_only_resources = Number(this.filters.invite_only_resources); } if (this.filters.method) { params.data.attributes.meeting_method = this.filters.method; } if (this.filters.through) { params.data.attributes.booked_through = this.filters.through; } if (this.filters.timezone) { params.data.attributes.timezone = this.filters.timezone; } if (this.filters.shortcut) { params.data.attributes.booking_shortcut_id = this.filters.shortcut; } if (this.filters.workflow) { params.data.attributes.workflow_id = this.filters.workflow; } } if (this.filters.notifications) { params = __assign(__assign({}, params), { meta: { notify: this.filters.notifications, } }); } if (this.hasUtm()) { params = __assign(__assign({}, params), { meta: __assign(__assign({}, params.meta), { utm: __assign(__assign(__assign(__assign(__assign({}, (this.utm.campaign && { campaign: this.utm.campaign })), (this.utm.content && { content: this.utm.content })), (this.utm.medium && { medium: this.utm.medium })), (this.utm.source && { source: this.utm.source })), (this.utm.term && { term: this.utm.term })) }) }); } if (this.meta.booker) { params = __assign(__assign({}, params), { meta: __assign(__assign({}, params.meta), { booker: this.meta.booker }) }); } if (this.filters.skip_meeting_link_generation) { params = __assign(__assign({}, params), { meta: __assign(__assign({}, params.meta), { skip_meeting_link_generation: this.filters.skip_meeting_link_generation }) }); } return params; }; Appointment.prototype.rescheduleParams = function (appointment) { var params = { data: { attributes: { start: this.filters.start, }, id: appointment, type: 'appointments', }, }; if (this.filters.timezone) { params.data.attributes.timezone = this.filters.timezone; } if (this.filters.notifications) { params = __assign(__assign({}, params), { meta: { notify: this.filters.notifications, } }); } if (this.filters.skip_meeting_link_generation) { params = __assign(__assign({}, params), { meta: __assign(__assign({}, params.meta), { skip_meeting_link_generation: this.filters.skip_meeting_link_generation }) }); } return params; }; Appointment.prototype.transformAttendees = function () { return this.relationships.attendees.map(function (attendee) { return attendee.transform(); }); }; return Appointment; }(Conditional)); var Forms = (function () { function Forms() { } Object.defineProperty(Forms, "CANCELLATION", { get: function () { return 1; }, enumerable: false, configurable: true }); return Forms; }()); function combine(params, parameters) { Object.keys(parameters).forEach(function (parameter) { params["filter[".concat(parameter, "]")] = parameters[parameter]; }); return params; } var Form = (function () { function Form(client) { this.client = client; this.filters = {}; this.page = null; this.parameters = {}; this.sortable = null; this.limit = null; } Form.prototype.cancellations = function () { this.filters.type = Forms.CANCELLATION; this.parameters.include = 'questions.options'; return this; }; Form.prototype.get = function () { return __awaiter(this, void 0, void 0, function () { var parameters, params; return __generator(this, function (_a) { switch (_a.label) { case 0: parameters = this.params(); params = {}; if (Object.keys(parameters).length) { params = combine(params, parameters); } if (this.parameters.include) { params.include = this.parameters.include; } if (this.limit) { params.limit = this.limit; } if (this.page) { params.page = this.page; } if (this.sortable) { params.sort = this.sortable; } return [4, this.client.get('forms', { params: params })]; case 1: return [2, _a.sent()]; } }); }); }; Form.prototype.on = function (page) { this.page = page; return this; }; Form.prototype.sortBy = function (sortable) { this.sortable = sortable; return this; }; Form.prototype.take = function (limit) { this.limit = limit; return this; }; Form.prototype.params = function () { var params = {}; if (typeof this.filters.type !== 'undefined') { params.type = this.filters.type; } return params; }; return Form; }()); var STORAGE_KEY = 'location-details-token'; function remove() { sessionStorage.removeItem(STORAGE_KEY); } function retrieve() { var token = sessionStorage.getItem(STORAGE_KEY); if (token) { return token; } sessionStorage.setItem(STORAGE_KEY, (token = uuid())); return token; } var Location = (function (_super) { __extends(Location, _super); function Location(client) { var _this = _super.call(this) || this; _this.client = client; _this.filters = {}; _this.page = null; _this.sortable = null; _this.limit = null; return _this; } Location.prototype.assigned = function (assigned) { if (assigned === void 0) { assigned = true; } this.filters.assigned = assigned; return this; }; Location.prototype.containing = function (user) { this.filters.user = user; return this; }; Location.prototype.details = function (identifier) { return __awaiter(this, void 0, void 0, function () { var headers; return __generator(this, function (_a) { switch (_a.label) { case 0: headers = { 'x-location-details-token': retrieve(), }; remove(); return [4, this.client.get("location-details/".concat(identifier), { headers: headers })]; case 1: return [2, _a.sent()]; } }); }); }; Location.prototype.get = function () { return __awaiter(this, void 0, void 0, function () { var parameters, params; return __generator(this, function (_a) { switch (_a.label) { case 0: parameters = this.params(); params = {}; if (Object.keys(parameters).length) { params = combine(params, parameters); } if (this.limit) { params.limit = this.limit; } if (this.page) { params.page = this.page; } if (this.sortable) { params.sort = this.sortable; } return [4, this.client.get('locations', { params: params })]; case 1: return [2, _a.sent()]; } }); }); }; Location.prototype.invitable = function () { this.filters.invitable = 1; return this; }; Location.prototype.group = function (isGroup) { if (isGroup === void 0) { isGroup = true; } this.filters.group_service = isGroup; return this; }; Location.prototype.located = function (details) { var _this = this; var keys = Object.keys(details); keys.map(function (key) { _this.filters[key] = details[key]; }); return this; }; Location.prototype.on = function (page) { this.page = page; return this; }; Location.prototype.preferred = function () { this.filters.preferred = 1; return this; }; Location.prototype.physical = function () { this.filters.virtual = 0; return this; }; Location.prototype.providing = function (services) { this.filters.services = services; return this; }; Location.prototype.sortBy = function (sortable) { this.sortable = sortable; return this; }; Location.prototype.suggest = function (query) { return __awaiter(this, void 0, void 0, function () { var headers, params; return __generator(this, function (_a) { switch (_a.label) { case 0: headers = { 'x-location-details-token': retrieve(), }; params = combine({}, { query: query }); return [4, this.client.get('location-suggestions', { headers: headers, params: params })]; case 1: return [2, _a.sent()]; } }); }); }; Location.prototype.supporting = function (method) { this.filters.method = method; return this; }; Location.prototype.take = function (limit) { this.limit = limit; return this; }; Location.prototype.through = function (resource) { this.filters.resource = resource; return this; }; Location.prototype.virtual = function () { this.filters.virtual = 1; return this; }; Location.prototype.withInviteOnly = function (inviteOnlyResources) { if (inviteOnlyResources === void 0) { inviteOnlyResources = true; } this.filters.invite_only_resources = inviteOnlyResources; return this; }; Location.prototype.withinUserCategory = function (userCategory) { this.filters.user_category = userCategory; return this; }; Location.prototype.params = function () { var params = {}; if (typeof this.filters.assigned !== 'undefined') { params.assignments = Number(this.filters.assigned); } if (typeof this.filters.city !== 'undefined') { params.city = this.filters.city; } if (typeof this.filters.country !== 'undefined') { params.country = this.filters.country; } if (typeof this.filters.group_service !== 'undefined') { params.group_service = Number(this.filters.group_service); } if (typeof this.filters.invitable !== 'undefined') { params.invite_only = this.filters.invitable; } if (this.filters.invite_only_resources) { params.invite_only_resources = Number(this.filters.invite_only_resources); } if (typeof this.filters.method !== 'undefined') { params.client_view_meeting_method = this.filters.method; } if (typeof this.filters.preferred !== 'undefined') { params.preferred = this.filters.preferred; } if (typeof this.filters.region !== 'undefined') { params.province = this.filters.region; } if (typeof this.filters.resource !== 'undefined') { params.resource = this.filters.resource; } if (typeof this.filters.services !== 'undefined') { params.service = this.filters.services; } if (typeof this.filters.user !== 'undefined') { params.user = this.filters.user; } if (typeof this.filters.user_category !== 'undefined') { params.user_category = this.filters.user_category; } if (typeof this.filters.virtual !== 'undefined') { params.virtual = this.filters.virtual; } return params; }; return Location; }(Conditional)); var Question = (function (_super) { __extends(Question, _super); function Question(client) { var _this = _super.call(this) || this; _this.client = client; _this.filters = {}; _this.page = null; _this.sortable = null; _this.limit = null; return _this; } Question.prototype.for = function (services) { this.filters.services = services; return this; }; Question.prototype.get = function () { return __awaiter(this, void 0, void 0, function () { var parameters, params; return __generator(this, function (_a) { switch (_a.label) { case 0: parameters = this.params(); params = {}; if (Object.keys(parameters).length) { params = combine(params, parameters); } if (this.limit) { params.limit = this.limit; } if (this.page) { params.page = this.page; } if (this.sortable) { params.sort = this.sortable; } return [4, this.client.get('questions', { params: params })]; case 1: return [2, _a.sent()]; } }); }); }; Question.prototype.on = function (page) { this.page = page; return this; }; Question.prototype.sortBy = function (sortable) { this.sortable = sortable; return this; }; Question.prototype.take = function (limit) { this.limit = limit; return this; }; Question.prototype.params = function () { var params = {}; if (typeof this.filters.services !== 'undefined') { params.matching = this.filters.services; } return params; }; return Question; }(Conditional)); var QueueAppointment = (function (_super) { __extends(QueueAppointment, _super); function QueueAppointment(client) { var _this = _super.call(this) || this; _this.client = client; _this.filters = {}; _this.meta = {}; _this.relationships = { client: { data: null, }, }; _this.utm = {}; return _this; } QueueAppointment.prototype.actingAs = function (identifier) { this.meta.booker = identifier; return this; }; QueueAppointment.prototype.at = function (location) { this.filters.location = location; return this; }; QueueAppointment.prototype.for = function (service) { this.filters.service = service; return this; }; QueueAppointment.prototype.method = function (method) { this.filters.method = method; return this; }; QueueAppointment.prototype.provided = function (notes) { this.filters.notes = notes; return this; }; QueueAppointment.prototype.through = function (origin) { this.filters.through = origin; return this; }; QueueAppointment.prototype.with = function (client) { this.relationships.client.data = client; return this; }; QueueAppointment.prototype.workflow = function (workflow) { this.filters.workflow = workflow; return this; }; QueueAppointment.prototype.recaptcha = function (recaptchaToken) { this.filters.recaptcha_token = recaptchaToken; return this; }; QueueAppointment.prototype.language = function (locale) { this.filters.lang = locale; return this; }; QueueAppointment.prototype.preferredLanguage = function (locale) { this.filters.preferred_lang = locale; return this; }; QueueAppointment.prototype.preferredStaff = function (id) { this.filters.preferred_staff_id = id; return this; }; QueueAppointment.prototype.campaign = function (campaign) { this.utm.campaign = campaign; return this; }; QueueAppointment.prototype.content = function (content) { this.utm.