UNPKG

coconut-open-api-js

Version:
2,139 lines 76.8 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'));

var Client = function (domain) {
    return axios.create({
        baseURL: domain ? "https://" + domain + ".coconutcalendar.com/api/v2/open" : window.location.origin + "/api/v2/open",
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
            'X-Requested-With': 'XMLHttpRequest',
        },
    });
};

var Days = (function () {
    function Days() {
    }
    Object.defineProperty(Days, "SUNDAY", {
        get: function () {
            return 0;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Days, "MONDAY", {
        get: function () {
            return 1;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Days, "TUESDAY", {
        get: function () {
            return 2;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Days, "WEDNESDAY", {
        get: function () {
            return 3;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Days, "THURSDAY", {
        get: function () {
            return 4;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Days, "FRIDAY", {
        get: function () {
            return 5;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Days, "SATURDAY", {
        get: function () {
            return 6;
        },
        enumerable: true,
        configurable: true
    });
    return Days;
}());

var MeetingMethods = (function () {
    function MeetingMethods() {
    }
    Object.defineProperty(MeetingMethods, "AT_LOCATION", {
        get: function () {
            return 1;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MeetingMethods, "PHONE_CALL", {
        get: function () {
            return 2;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MeetingMethods, "VIDEO_CALL", {
        get: function () {
            return 3;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MeetingMethods, "OFF_SITE", {
        get: function () {
            return 4;
        },
        enumerable: true,
        configurable: true
    });
    return MeetingMethods;
}());

var Notifications = (function () {
    function Notifications() {
    }
    Object.defineProperty(Notifications, "CLIENT", {
        get: function () {
            return {
                client: true,
            };
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Notifications, "USER", {
        get: function () {
            return {
                user: true,
            };
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Notifications, "ALL", {
        get: function () {
            return {
                client: true,
                user: true,
            };
        },
        enumerable: true,
        configurable: true
    });
    return Notifications;
}());

var Origins = (function () {
    function Origins() {
    }
    Object.defineProperty(Origins, "UNKNOWN", {
        get: function () {
            return 0;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Origins, "API", {
        get: function () {
            return 4;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Origins, "MODERN_CLIENT_VIEW", {
        get: function () {
            return 9;
        },
        enumerable: true,
        configurable: true
    });
    return Origins;
}());

var Visibilities = (function () {
    function Visibilities() {
    }
    Object.defineProperty(Visibilities, "PUBLIC", {
        get: function () {
            return 0;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Visibilities, "ALL", {
        get: function () {
            return 1;
        },
        enumerable: true,
        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({}, 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({}, 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({}, parameters, { relationships: {
                    answers: {
                        data: answers.map(function (answer) { return answer.transform(); }),
                    },
                } });
        }
        var responses = this.attributes.responses || [];
        if (responses.length > 0) {
            parameters = __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({}, 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({}, 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 = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate();
        var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
        return date + " " + 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: true,
        configurable: true
    });
    Object.defineProperty(Preference, "CERTAIN_DAYS", {
        get: function () {
            return CERTAIN_DAYS;
        },
        enumerable: true,
        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/" + appointment + "/attendees", formData_1)];
                    case 1: return [2, _a.sent()];
                    case 2: return [4, this.client.put("appointments/" + 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/" + appointment + "/" + 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/" + appointment + "?code=" + 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({}, params.meta, { origin: this.filters.through });
        }
        if (this.filters.notifications) {
            params.meta = __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({}, params, { meta: {
                    notify: this.filters.notifications,
                } });
        }
        if (this.hasUtm()) {
            params = __assign({}, params, { meta: __assign({}, params.meta, { utm: __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({}, params, { meta: __assign({}, params.meta, { booker: this.meta.booker }) });
        }
        if (this.filters.skip_meeting_link_generation) {
            params = __assign({}, params, { meta: __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({}, params, { meta: {
                    notify: this.filters.notifications,
                } });
        }
        if (this.filters.skip_meeting_link_generation) {
            params = __assign({}, params, { meta: __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: true,
        configurable: true
    });
    return Forms;
}());

function combine(params, parameters) {
    Object.keys(parameters).forEach(function (parameter) {
        params["filter[" + 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/" + 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.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.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.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.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.content = content;
        return this;
    };
    QueueAppointment.prototype.medium = function (medium) {
        this.utm.medium = medium;
        return this;
    };
    QueueAppointment.prototype.source = function (source) {
        this.utm.source = source;
        return this;
    };
    QueueAppointment.prototype.term = function (term) {
        this.utm.term = term;
        return this;
    };
    QueueAppointment.prototype.book = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4, this.client.post('queue-appointments', this.params())];
                    case 1: return [2, _a.sent()];
                }
            });
        });
    };
    QueueAppointment.prototype.hasUtm = function () {
        return !!this.utm.campaign || !!this.utm.content || !!this.utm.medium || !!this.utm.source || !!this.utm.term;
    };
    QueueAppointment.prototype.params = function () {
        if (this.relationships.client.data === null) {
            return {};
        }
        var params = {
            data: {
                attributes: __assign({ location_id: this.filters.location, meeting_method: this.filters.method, service_id: this.filters.service }, (this.filters.preferred_staff_id && { preferred_staff_id: this.filters.preferred_staff_id }), (this.filters.preferred_lang && { preferred_lang: this.filters.preferred_lang }), (this.filters.lang && { lang: this.filters.lang }), (this.filters.workflow && { workflow_id: this.filters.workflow }), (this.filters.notes && { notes: this.filters.notes }), (this.filters.through && { booked_through: this.filters.through }), (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 })),
                relationships: {
                    client: {
                        data: this.relationships.client.data.transform(),
                    },
                },
                type: 'queue-appointments',
            },
        };
        if (this.filters.method) {
            params.data.attributes.meeting_method = this.filters.method;
        }
        if (this.filters.through) {
            params.data.attributes.booked_through = this.filters.through;
        }
        return params;
    };
    return QueueAppointment;
}(Conditional));

var Service = (function (_super) {
    __extends(Service, _super);
    function Service(client) {
        var _this = _super.call(this) || this;
        _this.client = client;
        _this.filters = {};
        _this.page = null;
        _this.sortable = null;
        _this.limit = null;
        return _this;
    }
    Service.prototype.assigned = function (assigned) {
        if (assigned === void 0) { assigned = true; }
        this.filters.assigned = assigned;
        return this;
    };
    Service.prototype.at = function (location) {
        this.filters.location = location;
        return this;
    };
    Service.prototype.by = function (user) {
        this.filters.user = user;
        return this;
    };
    Service.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('services', { params: params })];
                    case 1: return [2, _a.sent()];
                }
            });
        });
    };
    Service.prototype.group = function () {
        this.filters.group = 1;
        return this;
    };
    Service.prototype.in = function (category) {
        this.filters.category = category;
        return this;
    };
    Service.prototype.individual = function () {
        this.filters.group = 0;
        return this;
    };
    Service.prototype.invitable = function () {
        this.filters.invitable = 1;
        return this;
    };
    Service.prototype.located = function (details) {
        var _this = this;
        var keys = Object.keys(details);
        keys.map(function (key) {
            _this.filters[key] = details[key];
        });
        return this;
    };
    Service.prototype.preferred = function () {
        this.filters.preferred = 1;
        return this;
    };
    Service.prototype.on = function (page) {
        this.page = page;
        return this;
    };
    Service.prototype.sortBy = function (sortable) {
        this.sortable = sortable;
        return this;
    };
    Service.prototype.supporting = function (method) {
        this.filters.method = method;
        return this;
    };
    Service.prototype.take = function (limit) {
        this.limit = limit;
        return this;
    };
    Service.prototype.through = function (resource) {
        this.filters.resource = resource;
        return this;
    };
    Service.prototype.withInviteOnly = function (inviteOnlyResources) {
        if (inviteOnlyResources === void 0) { inviteOnlyResources = true; }
        this.filters.invite_only_resources = inviteOnlyResources;
        return this;
    };
    Service.prototype.withinLocationCategory = function (locationCategory) {
        this.filters.location_category = locationCategory;
        return this;
    };
    Service.prototype.withinUserCategory = function (userCategory) {
        this.filters.user_category = userCategory;
        return this;
    };
    Service.prototype.params = function () {
        var params = {};
        if (typeof this.filters.assigned !== 'undefined') {
            params.assignments = Number(this.filters.assigned);
        }
        if (typeof this.filters.category !== 'undefined') {
            params.category = this.filters.category;
        }
        if (typeof this.filters.group !== 'undefined') {
            params.group = this.filters.group;
        }
        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.location !== 'undefined') {
            params.location = this.filters.location;
        }
        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.user !== 'undefined') {
            params.user = this.filters.user;
        }
        if (typeof this.filters.location_category !== 'undefined') {
            params.location_category = this.filters.location_category;
        }
        if (typeof this.filters.user_category !== 'undefined') {
            params.user_category = this.filters.user_category;
        }
        return params;
    };
    return Service;
}(Conditional));

var Setting = (function () {
    function Setting(client) {
        this.client = client;
    }
    Setting.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('settings')];
                    case 1: return [2, _a.sent()];
                }
            });
        });
    };
    return Setting;
}());

var TimeSlot = (function (_super) {
    __extends(TimeSlot, _super);
    function TimeSlot(client) {
        var _this = _super.call(this) || this;
        _this.client = client;
        _this.filters = {};
        return _this;
    }
    TimeSlot.prototype.at = function (location) {
        this.filters.location = location;
        return this;
    };
    TimeSlot.prototype.attendedBy = function (users) {
        this.filters.users = users;
        return this;
    };
    TimeSlot.prototype.between = function (start, end) {
        this.filters.start = start;
        this.filters.end = end;
        return this;
    };
    TimeSlot.prototype.by = function (user) {
        this.filters.user = user;
        return this;
    };
    TimeSlot.prototype.excluding = function (exclusion) {
        this.filters.exclusion = exclusion;
        return this;
    };
    TimeSlot.prototype.for = function (services) {
        this.filters.services = services;
        return this;
    };
    TimeSlot.prototype.get = function () {
        return __awaiter(this, void 0, void 0, function () {
            var params;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        params = {
                            end: this.filters.end,
                            location_id: this.filters.location,
                            service_id: this.filters.services,
                            start: this.filters.start,
                        };
                        if (this.filters.exclusion) {
                            params.exclusion = this.filters.exclusion;
                        }
                        if (this.filters.google) {
                            params.google = this.filters.google;
                        }
                        if (this.filters.invite_only_resources) {
                            params.invite_only_resources = Number(this.filters.invite_only_resources);
                        }
                        if (this.filters.locales) {
                            params.supported_locales = this.filters.locales;
                        }
                        if (this.filters.location_category) {
                            params.location_category_id = this.filters.location_category;
                        }
                        if (this.filters.method) {
                            params.meeting_method = this.filters.method;
                        }
                        if (this.filters.timezone) {
                            params.timezone = this.filters.timezone;
                        }
                        if (this.filters.user) {
                            params.staff_id = this.filters.user;
                        }
                        if (this.filters.user_category) {
                            params.staff_category_id = this.filters.user_category;
                        }
                        if (this.filters.users) {
                            params.additional_staff_id = this.filters.users;
                        }
                        if (this.filters.visibility) {
                            params.visibility = this.filters.visibility;
                        }
                        return [4, this.client.get('times', { params: params })];
                    case 1: return [2, _a.sent()];
                }
            });
        });
    };
    TimeSlot.prototype.google = function (token) {
        this.filters.google = token;
        return this;
    };
    TimeSlot.prototype.in = function (timezone) {
        this.filters.timezone = timezone;
        return this;
    };
    TimeSlot.prototype.method = function (method) {
        this.filters.method = method;
        return this;
    };
    TimeSlot.prototype.supporting = function (locales) {
        this.filters.locales = locales;
        return this;
    };
    TimeSlot.prototype.visibility = function (visibility) {
        this.filters.visibility = visibility;
        return this;
    };
    TimeSlot.prototype.withInviteOnly = function (inviteOnlyResources) {
        if (inviteOnlyResources === void 0) { inviteOnlyResources = true; }
        this.filters.invite_only_resources = inviteOnlyResources;
        return this;
    };
    TimeSlot.prototype.withinLocationCategory = function (locationCategory) {
        this.filters.location_category = locationCategory;
        return this;
    };
    TimeSlot.prototype.withinUserCategory = function (userCategory) {
        this.filters.user_category = userCategory;
        return this;
    };
    return TimeSlot;
}(Conditional));

var Timezone = (function () {
    function Timezone(client) {
        this.client = client;
    }
    Timezone.prototype.get = function (country) {
        return __awaiter(this, void 0, void 0, function () {
            var url;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        url = 'timezones';
                        if (country) {
                            url += "/" + country;
                        }
                        return [4, this.client.get(url)];
                    case 1: return [2, _a.sent()];
                }
            });
        });
    };
    return Timezone;
}());

var User = (function (_super) {
    __extends(User, _super);
    function User(client) {
        var _this = _super.call(this) || this;
        _this.client = client;
        _this.filters = {};
        _this.page = null;
        _this.sortable = null;
        _this.limit = null;
        return _this;
    }
    User.prototype.assigned = function (assigned) {
        if (assigned === void 0) { assigned = true; }
        this.filters.assigned = assigned;
        return this;
    };
    User.prototype.at = function (location) {
        this.filters.location = location;
        return this;
    };
    User.prototype.find = function (user) {
        this.filters.user = user;
        return this;
    };
    User.prototype.located = function (details) {
        var _this = this;
        var keys = Object.keys(details);
        keys.map(function (key) {
            _this.filters[key] = details[key];
        });
        return this;
    };
    User.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('users', { params: params })];
                    case 1: return [2, _a.sent()];
                }
            });
        });
    };
    User.prototype.on = function (page) {
        this.page = page;
        return this;
    };
    User.prototype.performing = function (services) {
        this.filters.services = services;
        return this;
    };
    User.prototype.sortBy = function (sortable) {
        this.sortable = sortable;
        return this;
    };
    User.prototype.supporting = function (method) {
        this.filters.method = method;
        return this;
    };
    User.prototype.through = function (resource) {
        this.filters.resource = resource;
        return this;
    };
    User.prototype.take = function (limit) {
        this.limit = limit;
        return this;
    };
    User.prototype.withInviteOnly = function (inviteOnlyResources) {
        if (inviteOnlyResources === void 0) { inviteOnlyResources = true; }
        this.filters.invite_only_resources = inviteOnlyResources;
        return this;
    };
    User.prototype.withinLocationCategory = function (locationCategory) {
        this.filters.location_category = locationCategory;
        return this;
    };
    User.prototype.withinUserCategory = function (category) {
        this.filters.category = category;
        return this;
    };
    User.prototype.withoutRemoteStaffOnly = function (withoutRemoteStaffOnly) {
        if (withoutRemoteStaffOnly === void 0) { withoutRemoteStaffOnly = true; }
        this.filters.without_remote_staff_only = withoutRemoteStaffOnly;
        return this;
    };
    User.prototype.availableInLobby = function (lobbyLocationId) {
        this.filters.lobby_location_id = lobbyLocationId;
        return this;
    };
    User.prototype.params = function () {
        var params = {};
        if (typeof this.filters.assigned !== 'undefined') {
            params.assignments = this.filters.assigned;
        }
        if (typeof this.filters.category !== 'undefined') {
            params.category = this.filters.category;
        }
        if (this.filters.invite_only_resources) {
            params.invite_only_resources = Number(this.filters.invite_only_resources);
        }
        if (typeof this.filters.location !== 'undefined') {
            params.location = this.filters.location;
        }
        if (typeof this.filters.location_category !== 'undefined') {
            params.location_category = this.filters.location_category;
        }
        if (typeof this.filters.lobby_location_id !== 'undefined') {
            params.lobby_location_id = this.filters.lobby_location_id;
        }
        if (typeof this.filters.method !== 'undefined') {
            params.client_view_meeting_method = this.filters.method;
            params.meeting_method = this.filters.method;
        }
        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.location !== 'undefined' &&
            this.filters.without_remote_staff_only === true) {
            params.without_remote_staff_only_at_location = this.filters.location;
        }
        return params;
    };
    return User;
}(Conditional));

var WaitList = (function (_super) {
    __extends(WaitList, _super);
    function WaitList(client) {
        var _this = _super.call(this) || this;
        _this.attributes = {};
        _this.client = client;
        _this.parameters = {};
        _this.relationships = {};
        return _this;
    }
    WaitList.prototype.add = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4, this.client.post('requests', this.params())];
                    case 1: return [2, _a.sent()];
                }
            });
        });
    };
    WaitList.prototype.at = function (location) {
        this.relationships.location = location;
        return this;
    };
    WaitList.prototype.belonging = function (client) {
        this.parameters.client = client;
        return this;
    };
    WaitList.prototype.find = function (list) {
        return __awaiter(this, void 0, void 0, function () {
            var params, _a, client, include;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        params = {};
                        _a = this.parameters, client = _a.client, include = _a.include;
                        if (include) {
                            params.include = include;
                        }
                        return [4, this.client.get("clients/" + client + "/requests/" + list, { params: params })];
                    case 1: return [2, _b.sent()];
                }
            });
        });
    };
    WaitList.prototype.for = function (attendee) {
        this.relationships.attendee = attendee;
        return this;
    };
    WaitList.prototype.include = function (includes) {
        this.parameters.include = includes;
        return this;
    };
    WaitList.prototype.prefers = function (preferences) {
        this.relationships.preferences = Array.isArray(preferences) ? preferences : [preferences];
        return this;
    };
    WaitList.prototype.provided = function (notes) {
        this.attributes.notes = notes;
        return this;
    };
    WaitList.prototype.remove = function (list) {
        return __awaiter(this, void 0, void 0, function () {
            var client;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        client = this.parameters.client;
                        return [4, this.client.delete("clients/" + client + "/requests/" + list)];
                    case 1: return [2, _a.sent()];
                }
            });
        });
    };
    WaitList.prototype.seeking = function (service) {
        this.relationships.service = service;
        return this;
    };
    WaitList.prototype.update = function (list) {
        return __awaiter(this, void 0, void 0, function () {
            var client;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        client = this.parameters.client;
                        return [4, this.client.patch("clients/" + client + "/requests/" + list, this.params())];
                    case 1: return [2, _a.sent()];
                }
            });
        });
    };
    WaitList.prototype.with = function (user) {
        this.relationships.user = user;
        return this;
    };
    WaitList.prototype.params = function () {
        var params = {
            data: {
                attributes: {},
                relationships: {},
                type: 'requests',
            },
        };
        if (this.relationships.attendee) {
            var attendee = this.relationships.attendee.transform();
            params.data.relationships.client = {
                data: __assign({}, attendee, { type: 'clients' }),
            };
        }
        if (this.relationships.location) {
            params.data.relationships.location = {
                data: {
                    id: String(this.relationships.location),
                    type: 'locations',
                },
            };
        }
        if (this.relationships.preferences) {
            var preferences = this.relationships.preferences.map(function (preference) {
                return preference.transform();
            });
            params.data.relationships.preferences = {
                data: preferences,
            };
        }
        if (this.relationships.service) {
            params.data.relationships.service = {
                data: {
                    id: String(this.relationships.service),
                    type: 'services',
                },
            };
        }
        if (this.attributes.notes) {
            params.data.attributes.details = this.attributes.notes;
        }
        if (this.relationships.user) {
            params.data.relationships.user = {
                data: {
                    id: String(this.relationships.user),
                    type: 'users',
                },
            };
        }
        return params;
    };
    return WaitList;
}(Conditional));

var WaitTime = (function (_super) {
    __extends(WaitTime, _super);
    function WaitTime(client) {
        var _this = _super.call(this) || this;
        _this.client = client;
        _this.limit = null;
        _this.location = null;
        _this.page = null;
        return _this;
    }
    WaitTime.prototype.at = function (location) {
        this.location = location;
        return this;
    };
    WaitTime.prototype.get = function () {
        return __awaiter(this, void 0, void 0, function () {
            var params, location;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        params = {};
                        location = '';
                        if (this.location != null) {
                            location = this.location;
                        }
                        if (this.limit) {
                            params.limit = this.limit;
                        }
                        if (this.page) {
                            params.page = this.page;
                        }
                        return [4, this.client.get(location ? "wait-time-average/" + location : 'wait-time-average', { params: params })];
                    case 1: return [2, _a.sent()];
                }
            });
        });
    };
    WaitTime.prototype.on = function (page) {
        this.page = page;
        return this;
    };
    WaitTime.prototype.take = function (limit) {
        this.limit = limit;
        return this;
    };
    return WaitTime;
}(Conditional));

var OpenApi = (function () {
    function OpenApi(domain) {
        this.client = Client(domain);
        this.domain = domain;
        this.appointment = new Appointment(this.client);
        this.queueAppointment = new QueueAppointment(this.client);
        this.form = new Form(this.client);
        this.list = new WaitList(this.client);
        this.location = new Location(this.client);
        this.question = new Question(this.client);
        this.service = new Service(this.client);
        this.setting = new Setting(this.client);
        this.slot = new TimeSlot(this.client);
        this.timezone = new Timezone(this.client);
        this.user = new User(this.client);
        this.waitTime = new WaitTime(this.client);
    }
    OpenApi.prototype.appointments = function () {
        return this.appointment;
    };
    OpenApi.prototype.queueAppointments = function () {
        return this.queueAppointment;
    };
    OpenApi.prototype.forms = function () {
        return this.form;
    };
    OpenApi.prototype.locale = function (locale) {
        this.client.defaults.params = { lang: locale };
        this.client.defaults.headers.common['Accept-Language'] = locale;
        return this;
    };
    OpenApi.prototype.lists = function () {
        return this.list;
    };
    OpenApi.prototype.locations = function () {
        return this.location;
    };
    OpenApi.prototype.questions = function () {
        return this.question;
    };
    OpenApi.prototype.services = function () {
        return this.service;
    };
    OpenApi.prototype.settings = function () {
        return this.setting;
    };
    OpenApi.prototype.slots = function () {
        return this.slot;
    };
    OpenApi.prototype.timezones = function () {
        return this.timezone;
    };
    OpenApi.prototype.users = function () {
        return this.user;
    };
    OpenApi.prototype.waitTimes = function () {
        return this.waitTime;
    };
    return OpenApi;
}());

exports.Answer = Answer;
exports.Attendee = Attendee;
exports.Client = Client$1;
exports.Days = Days;
exports.MeetingMethods = MeetingMethods;
exports.Notifications = Notifications;
exports.Origins = Origins;
exports.Preference = Preference;
exports.Response = Response;
exports.Visibilities = Visibilities;
exports.OpenApi = OpenApi;