UNPKG

@awhere/api

Version:

The awesome aWhere API for JavaScript.

92 lines 3.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var axios_1 = __importDefault(require("axios")); var socket_io_client_1 = __importDefault(require("socket.io-client")); var utils_1 = require("./utils"); var BasicAuth = /** @class */ (function () { function BasicAuth(props) { this._username = props.username; this._password = props.password; this._aWhereUrl = props.aWhereUrl; this._locale = props.locale || undefined; } Object.defineProperty(BasicAuth.prototype, "username", { get: function () { return this._username; }, set: function (value) { this._username = value; }, enumerable: false, configurable: true }); Object.defineProperty(BasicAuth.prototype, "password", { get: function () { return this._password; }, set: function (value) { this._password = value; }, enumerable: false, configurable: true }); Object.defineProperty(BasicAuth.prototype, "aWhereUrl", { get: function () { return this._aWhereUrl; }, set: function (value) { this._aWhereUrl = value; }, enumerable: false, configurable: true }); Object.defineProperty(BasicAuth.prototype, "locale", { get: function () { return this._locale; }, set: function (value) { this._locale = value; }, enumerable: false, configurable: true }); Object.defineProperty(BasicAuth.prototype, "request", { get: function () { if (!this._request) { this._request = axios_1.default.create({ baseURL: "".concat(this._aWhereUrl).concat(utils_1.endpoint.api), auth: { username: this._username, password: this._password, }, }); } return this._request; }, enumerable: false, configurable: true }); Object.defineProperty(BasicAuth.prototype, "socket", { get: function () { if (!this._socket) { var url = new URL("".concat(this._aWhereUrl).concat(utils_1.endpoint.api, "/realtime")); var path = url.pathname.replace(/(\/\/)/gi, '/').replace(/(\/$)/, ''); this._socket = (0, socket_io_client_1.default)(url.origin, { path: path, query: { username: this._username, password: this._password }, transports: ['websocket'], autoConnect: false, }); } return this._socket; }, enumerable: false, configurable: true }); return BasicAuth; }()); exports.default = BasicAuth; //# sourceMappingURL=BasicAuth.js.map