Comparing version 0.0.1 to 0.0.2
@@ -45,2 +45,5 @@ import axios from "axios"; | ||
.then((res) => { | ||
if (res.data.isError) { | ||
return { error: true, data: res.data }; | ||
} | ||
return { error: false, data: res.data }; | ||
@@ -71,2 +74,5 @@ }) | ||
.then((res) => { | ||
if (res.data.isError) { | ||
return { error: true, data: res.data }; | ||
} | ||
const sto = JSON.stringify(res.data.result.avatar); | ||
@@ -132,2 +138,5 @@ localStorage.setItem("user", sto); | ||
.then((response) => { | ||
if (res.data.isError) { | ||
return { error: true, data: res.data }; | ||
} | ||
return { error: false, data: response.data }; | ||
@@ -134,0 +143,0 @@ }) |
@@ -1,2 +0,1 @@ | ||
//ts-check | ||
import axios from "axios"; | ||
@@ -14,14 +13,19 @@ import Auth from "../auth/auth.js"; | ||
async callLogin(obj = this) { | ||
const credentials = JSON.parse(localStorage.getItem("login")); | ||
const auth = new Auth(); | ||
await auth.login(credentials); | ||
let user = JSON.parse(localStorage.getItem("user")); | ||
obj.token = { jwtToken: user.jwtToken, refresh: user.refreshToken }; | ||
console.log(obj); | ||
return obj.token; | ||
if (JSON.parse(localStorage.getItem("login"))) { | ||
const credentials = JSON.parse(localStorage.getItem("login")); | ||
const auth = new Auth(); | ||
const ret = await auth.login(credentials); | ||
if (ret.error) return -1; | ||
let user = JSON.parse(localStorage.getItem("user")); | ||
obj.token = { jwtToken: user.jwtToken, refresh: user.refreshToken }; | ||
console.log(obj); | ||
return obj.token; | ||
} else return -1; | ||
} | ||
async getAll(token = {}) { | ||
await this.callLogin(); | ||
if (this.token) { | ||
const temp = await this.callLogin(); | ||
if (temp === -1) { | ||
return { error: true, data: { message: "You are not logged in!" } }; | ||
} else if (this.token) { | ||
token = this.token; | ||
@@ -41,2 +45,5 @@ } | ||
.then(function (response) { | ||
if (res.data.isError) { | ||
return { error: true, data: res.data }; | ||
} | ||
return { error: false, data: response.data }; | ||
@@ -52,4 +59,7 @@ }) | ||
async get(id) { | ||
await this.callLogin(); | ||
let token = this.token; | ||
const temp = await this.callLogin(); | ||
let token; | ||
if (temp === -1) | ||
return { error: true, data: { message: "You are not logged in!" } }; | ||
else token = temp; | ||
@@ -68,2 +78,5 @@ const config = { | ||
.then(function (response) { | ||
if (res.data.isError) { | ||
return { error: true, data: res.data }; | ||
} | ||
return { error: false, data: response.data }; | ||
@@ -77,3 +90,6 @@ }) | ||
async update(id, data) { | ||
await this.callLogin(); | ||
let temp = await this.callLogin(); | ||
if (temp === -1) | ||
return { error: true, data: { message: "You are not logged in!" } }; | ||
else token = temp; | ||
@@ -86,3 +102,3 @@ data = JSON.stringify(data); | ||
headers: { | ||
Authorization: `Bearer ${this.token.jwtToken}`, | ||
Authorization: `Bearer ${token.jwtToken}`, | ||
Cookie: `refreshToken=${token.refresh}`, | ||
@@ -96,2 +112,5 @@ "Content-Type": "application/json", | ||
.then(function (response) { | ||
if (res.data.isError) { | ||
return { error: true, data: res.data }; | ||
} | ||
return { error: false, data: response.data }; | ||
@@ -107,3 +126,6 @@ }) | ||
async delete(id) { | ||
await this.callLogin(); | ||
let temp = await this.callLogin(); | ||
if (temp === -1) | ||
return { error: true, data: { message: "You are not logged in!" } }; | ||
else token = temp; | ||
const config = { | ||
@@ -113,3 +135,3 @@ method: "delete", | ||
headers: { | ||
Authorization: `Bearer ${this.token.jwtToken}`, | ||
Authorization: `Bearer ${token.jwtToken}`, | ||
"Content-Type": "application/json", | ||
@@ -121,2 +143,5 @@ }, | ||
.then(function (response) { | ||
if (res.data.isError) { | ||
return { error: true, data: res.data }; | ||
} | ||
return { error: false, data: response.data }; | ||
@@ -140,3 +165,6 @@ }) | ||
) { | ||
await this.callLogin(); | ||
let temp = await this.callLogin(); | ||
if (temp === -1) | ||
return { error: true, data: { message: "You are not logged in!" } }; | ||
else token = temp; | ||
@@ -147,3 +175,3 @@ const config = { | ||
headers: { | ||
Authorization: `Bearer ${this.token.jwtToken}`, | ||
Authorization: `Bearer ${token.jwtToken}`, | ||
"Content-Type": "application/json", | ||
@@ -155,2 +183,5 @@ }, | ||
.then(function (response) { | ||
if (res.data.isError) { | ||
return { error: true, data: res.data }; | ||
} | ||
return { error: false, data: response.data }; | ||
@@ -174,3 +205,6 @@ }) | ||
) { | ||
await this.callLogin(); | ||
let temp = await this.callLogin(); | ||
if (temp === -1) | ||
return { error: true, data: { message: "You are not logged in!" } }; | ||
else token = temp; | ||
data = JSON.stringify(data); | ||
@@ -189,2 +223,5 @@ | ||
.then(function (response) { | ||
if (res.data.isError) { | ||
return { error: true, data: res.data }; | ||
} | ||
return { error: false, data: response.data }; | ||
@@ -191,0 +228,0 @@ }) |
import Auth from "./auth/auth.js"; | ||
import Avatar from "./avatar/avatar.js"; | ||
import Karma from "./karma/karma.js"; | ||
import NFT from "./nft/nft.js"; | ||
export default { | ||
Auth, | ||
Avatar, | ||
Karma, | ||
NFT, | ||
}; |
@@ -11,2 +11,4 @@ import axios from "axios"; | ||
this.token = await this.avatar.callLogin(); | ||
if (this.token === -1) | ||
return { error: true, data: { message: "You are not logged in!" } }; | ||
@@ -21,6 +23,6 @@ const config = { | ||
axios(config) | ||
return axios(config) | ||
.then(function (response) { | ||
if (response.data.isError) return { error: true, data: response.data }; | ||
else return { error: true, data: response.data }; | ||
else return { error: false, data: response.data }; | ||
}) | ||
@@ -31,4 +33,60 @@ .catch(function (error) { | ||
} | ||
async removeKarmaFromAvatar( | ||
id, | ||
data = { | ||
karmaType: "", | ||
karmaSourceType: "", | ||
karamSourceTitle: "", | ||
karmaSourceDesc: "", | ||
} | ||
) { | ||
this.token = await this.avatar.callLogin(); | ||
if (this.token === -1) | ||
return { error: true, data: { message: "You are not logged in!" } }; | ||
data = JSON.stringify(data); | ||
const config = { | ||
method: "post", | ||
url: `https://api.oasisplatform.world/api/karma/RemoveKarmaFromAvatar/${id}`, | ||
headers: { | ||
Authorization: `Bearer ${this.token.jwtToken}`, | ||
}, | ||
data, | ||
}; | ||
return axios(config) | ||
.then(function (response) { | ||
if (response.data.isError) return { error: true, data: response.data }; | ||
else return { error: false, data: response.data }; | ||
}) | ||
.catch(function (error) { | ||
return { error: true, data: error }; | ||
}); | ||
} | ||
async getKarmaAkashicRecordsForAvatar(id) { | ||
this.token = await this.avatar.callLogin(); | ||
if (this.token === -1) | ||
return { error: true, data: { message: "You are not logged in!" } }; | ||
const config = { | ||
method: "get", | ||
url: `https://api.oasisplatform.world/api/karma/getKarmaAkashicRecordsForAvatar/${id}`, | ||
headers: { | ||
Authorization: `Bearer ${this.token.jwtToken}`, | ||
}, | ||
}; | ||
return axios(config) | ||
.then(function (response) { | ||
if (response.data.isError) return { error: true, data: response.data }; | ||
else return { error: false, data: response.data }; | ||
}) | ||
.catch(function (error) { | ||
return { error: true, data: error }; | ||
}); | ||
} | ||
} | ||
export default Karma; |
{ | ||
"name": "oasis-api", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A JavaScript proxy for the Oasis API. To be used only in the browser.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19687
9
586