mpp-sdk
Version:
SDK to talk to the Memento Payments Platform
87 lines (86 loc) • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const base_js_1 = require("./base.js");
const errors_js_1 = require("../errors.js");
class UsersEndpoint extends base_js_1.BaseEndpoint {
/**
* Gets the user by the id. Returns regular User object if
* the user fetched is the current user. Otherwise returns
* the public user object.
* @param id user id
*/
getById(id) {
return this.doRequest({
url: `/users/${id}`,
method: "GET",
});
}
search(data) {
return this.doRequest({
url: "/users/search",
method: "POST",
data,
});
}
recents() {
return this.doRequest({
url: "/users/recents",
method: "GET",
});
}
/**
* Create a user. Newly created users are auto logged in.
* @param data
*/
create(data) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const result = yield this.doRequest({
url: "/users",
method: "POST",
data,
});
// Store auth token and remove from output
yield this.config.storage.storeAuthToken(result.data.authentication_token);
delete result.data.authentication_token;
return result;
});
}
current() {
return this.doRequest({
url: "/users/current",
method: "GET",
});
}
updateCurrent(data) {
return this.doRequest({
url: "/users/current",
method: "PATCH",
data,
});
}
/**
* Checks whether the given username is taken. Returns true if the username
* is available.
* @param username
*/
checkUsername(username) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
yield this.doRequest({
url: "/check_username",
method: "POST",
data: { username },
});
return true;
}
catch (e) {
if (e instanceof errors_js_1.ValidationError) {
return false;
}
throw e;
}
});
}
}
exports.default = UsersEndpoint;