UNPKG

@toruslabs/session-manager

Version:
44 lines (39 loc) 1.06 kB
'use strict'; var _defineProperty = require('@babel/runtime/helpers/defineProperty'); var httpHelpers = require('@toruslabs/http-helpers'); class BaseSessionManager { constructor() { _defineProperty(this, "sessionId", void 0); } checkSessionParams() { if (!this.sessionId) throw new Error("Session id is required"); this.sessionId = this.sessionId.padStart(64, "0"); } /** * Common handler method for making an http request. * * Note: Embed all the query parameters in the path itself. */ request({ method = "GET", url, data = {}, headers = {} }) { const options = { headers }; switch (method) { case "GET": return httpHelpers.get(url, options); case "POST": return httpHelpers.post(url, data, options); case "PUT": return httpHelpers.put(url, data, options); case "PATCH": return httpHelpers.patch(url, data, options); } throw new Error("Invalid method type"); } } exports.BaseSessionManager = BaseSessionManager;