mirror of https://github.com/Budibase/budibase.git
21 changed files with 109 additions and 20 deletions
@ -1,5 +1,6 @@ |
|||
const env = require("../src/environment") |
|||
|
|||
env._set("SELF_HOSTED", "1") |
|||
env._set("NODE_ENV", "jest") |
|||
env._set("JWT_SECRET", "test-jwtsecret") |
|||
env._set("LOG_LEVEL", "silent") |
|||
|
|||
@ -0,0 +1,22 @@ |
|||
const API = require("./api") |
|||
const env = require("../environment") |
|||
|
|||
const api = new API(env.ACCOUNT_PORTAL_URL) |
|||
|
|||
// TODO: Authorization
|
|||
|
|||
exports.getAccount = async email => { |
|||
const payload = { |
|||
email, |
|||
} |
|||
const response = await api.post(`/api/accounts/search`, { |
|||
body: payload, |
|||
}) |
|||
const json = await response.json() |
|||
|
|||
if (response.status !== 200) { |
|||
throw Error(`Error getting account by email ${email}`, json) |
|||
} |
|||
|
|||
return json[0] |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
const fetch = require("node-fetch") |
|||
class API { |
|||
constructor(host) { |
|||
this.host = host |
|||
} |
|||
|
|||
apiCall = |
|||
method => |
|||
async (url = "", options = {}) => { |
|||
if (!options.headers) { |
|||
options.headers = {} |
|||
} |
|||
|
|||
if (!options.headers["Content-Type"]) { |
|||
options.headers = { |
|||
"Content-Type": "application/json", |
|||
Accept: "application/json", |
|||
...options.headers, |
|||
} |
|||
} |
|||
|
|||
let json = options.headers["Content-Type"] === "application/json" |
|||
|
|||
const requestOptions = { |
|||
method: method, |
|||
body: json ? JSON.stringify(options.body) : options.body, |
|||
headers: options.headers, |
|||
// TODO: See if this is necessary
|
|||
credentials: "include", |
|||
} |
|||
|
|||
const resp = await fetch(`${this.host}${url}`, requestOptions) |
|||
|
|||
return resp |
|||
} |
|||
|
|||
post = this.apiCall("POST") |
|||
get = this.apiCall("GET") |
|||
patch = this.apiCall("PATCH") |
|||
del = this.apiCall("DELETE") |
|||
put = this.apiCall("PUT") |
|||
} |
|||
|
|||
module.exports = API |
|||
Loading…
Reference in new issue