@toruslabs/session-manager
Version:
42 lines (38 loc) • 984 B
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { patch, put, post, get } from '@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 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 };