slate/common/actions.js
2020-08-19 11:17:12 -07:00

136 lines
2.9 KiB
JavaScript

import "isomorphic-fetch";
import * as Strings from "~/common/strings";
const REQUEST_HEADERS = {
Accept: "application/json",
"Content-Type": "application/json",
};
const DEFAULT_OPTIONS = {
method: "POST",
headers: REQUEST_HEADERS,
credentials: "include",
};
const returnJSON = async (route, options) => {
const response = await fetch(route, options);
const json = await response.json();
return json;
};
export const health = async (data = {}) => {
return await returnJSON(`/api/_`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data: { buckets: data.buckets } }),
});
};
export const sendFilecoin = async (data) => {
if (Strings.isEmpty(data.source)) {
return null;
}
if (Strings.isEmpty(data.target)) {
return null;
}
if (!data.amount) {
return null;
}
return await returnJSON(`/api/addresses/send`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const updateViewer = async (data) => {
return await returnJSON(`/api/users/update`, {
...DEFAULT_OPTIONS,
body: JSON.stringify(data),
});
};
export const signIn = async (data) => {
return await returnJSON(`/api/sign-in`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const hydrateAuthenticatedUser = async () => {
return await returnJSON(`/api/hydrate`, {
...DEFAULT_OPTIONS,
});
};
export const deleteViewer = async () => {
return await returnJSON(`/api/users/delete`, {
...DEFAULT_OPTIONS,
});
};
export const createUser = async (data) => {
return await returnJSON(`/api/users/create`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const checkCIDStatus = async (data) => {
return await returnJSON(`/api/data/cid-status`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const createSlate = async (data) => {
return await returnJSON(`/api/slates/create`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const updateSlate = async (data) => {
return await returnJSON(`/api/slates/update`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const deleteSlate = async (data) => {
return await returnJSON(`/api/slates/delete`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const deleteSlateItem = async (data) => {
return await returnJSON(`/api/slates/remove-item`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const generateAPIKey = async () => {
return await returnJSON(`/api/keys/generate`, {
...DEFAULT_OPTIONS,
});
};
export const deleteAPIKey = async (data) => {
return await returnJSON(`/api/keys/delete`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const deleteBucketItem = async (data) => {
return await returnJSON(`/api/data/remove`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};