UNPKG

@toruslabs/session-manager

Version:
43 lines (39 loc) 1.02 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { patch, put, post, get } from '@toruslabs/http-helpers'; import { padHexString } from './util.js'; class BaseSessionManager { constructor() { _defineProperty(this, "sessionId", void 0); } checkSessionParams() { if (!this.sessionId) throw new Error("Session id is required"); this.sessionId = padHexString(this.sessionId); } /** * 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 get(url, options); case "POST": return post(url, data, options); case "PUT": return put(url, data, options); case "PATCH": return patch(url, data, options); } throw new Error("Invalid method type"); } } export { BaseSessionManager };