UNPKG

@ohmunity/whereby

Version:

WhereBy unofficial sdk (whereby.com)

89 lines (88 loc) 3.46 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(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); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var node_fetch_1 = __importDefault(require("node-fetch")); var BASE_URL = 'https://api.whereby.dev/v1'; var WhereBy = /** @class */ (function () { function WhereBy(token) { this.token = null; this.token = token; } WhereBy.prototype._call = function (url, method, options) { var _this = this; if (!this.token) { throw new Error('Token is required'); } return new Promise(function (resolve) { node_fetch_1.default(BASE_URL + url, { method: method, body: (options === null || options === void 0 ? void 0 : options.body) ? JSON.stringify(options === null || options === void 0 ? void 0 : options.body) : undefined, headers: { 'Content-Type': 'application/json', Authorization: "Bearer " + _this.token, }, }) .then(function (r) { return r.json(); }) .then(function (response) { if (response.error) { resolve({ success: false, error: new Error(response.error), }); } else { resolve({ success: true, data: response, }); } }) .catch(function (err) { resolve({ success: false, error: err, }); }); }); }; WhereBy.prototype.createMeeting = function (_a) { var startDate = _a.startDate, endDate = _a.endDate, includeHostRoomUrl = _a.includeHostRoomUrl, moreOptions = __rest(_a, ["startDate", "endDate", "includeHostRoomUrl"]); return this._call('/meetings', 'POST', { body: __assign({ startDate: startDate.toISOString(), endDate: endDate.toISOString(), fields: includeHostRoomUrl ? ['hostRoomUrl'] : undefined }, moreOptions), }); }; WhereBy.prototype.meeting = function (id) { return this._call("/meetings/" + id, 'GET'); }; WhereBy.prototype.deleteMeeting = function (id) { return this._call("/meetings/" + id, 'DELETE'); }; return WhereBy; }()); exports.default = WhereBy;