slate/common/actions.js

222 lines
5.0 KiB
JavaScript
Raw Normal View History

2020-06-19 06:57:57 +03:00
import "isomorphic-fetch";
2020-02-19 09:30:47 +03:00
2020-06-19 06:57:57 +03:00
import * as Strings from "~/common/strings";
2020-02-19 09:30:47 +03:00
const REQUEST_HEADERS = {
2020-06-19 06:57:57 +03:00
Accept: "application/json",
"Content-Type": "application/json",
2020-02-19 09:30:47 +03:00
};
2020-08-07 05:17:49 +03:00
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;
};
2020-08-19 21:17:12 +03:00
export const health = async (data = {}) => {
return await returnJSON(`/api/_`, {
...DEFAULT_OPTIONS,
2020-08-19 21:17:12 +03:00
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;
2020-02-19 09:30:47 +03:00
}
if (!data.amount) {
return null;
2020-02-19 09:30:47 +03:00
}
2020-08-07 05:17:49 +03:00
return await returnJSON(`/api/addresses/send`, {
...DEFAULT_OPTIONS,
2020-08-27 07:24:49 +03:00
body: JSON.stringify({ data }),
});
};
export const checkUsername = async (data) => {
return await returnJSON(`/api/users/check`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const archive = async () => {
return await returnJSON(`/api/data/archive`, {
...DEFAULT_OPTIONS,
});
};
export const getNetworkDirectory = async () => {
return await returnJSON(`/api/directory`, {
...DEFAULT_OPTIONS,
});
};
2020-08-27 07:24:49 +03:00
export const getSlateBySlatename = async (data) => {
return await returnJSON(`/api/search/slates/${data.query}`, {
...DEFAULT_OPTIONS,
2020-09-03 09:00:02 +03:00
body: JSON.stringify({ data }),
});
};
export const getSlateById = async (data) => {
return await returnJSON(`/api/slates/get`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
2020-08-07 05:17:49 +03:00
});
2020-02-19 09:30:47 +03:00
};
export const deleteTrustRelationship = async (data) => {
return await returnJSON(`/api/users/trust-delete`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const updateTrustRelationship = async (data) => {
return await returnJSON(`/api/users/trust-update`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const createTrustRelationship = async (data) => {
return await returnJSON(`/api/users/trust`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const createSubscription = async (data) => {
return await returnJSON(`/api/subscribe`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const search = async (data) => {
if (Strings.isEmpty(data.query)) {
return { decorator: "NO_SERVER_TRIP", data: { results: [] } };
}
return await returnJSON(`/api/search/${data.query}`, {
...DEFAULT_OPTIONS,
body: JSON.stringify(data),
});
};
export const updateViewer = async (data) => {
2020-08-07 05:17:49 +03:00
return await returnJSON(`/api/users/update`, {
...DEFAULT_OPTIONS,
body: JSON.stringify(data),
2020-08-07 05:17:49 +03:00
});
};
export const signIn = async (data) => {
2020-08-07 05:17:49 +03:00
return await returnJSON(`/api/sign-in`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
2020-08-07 05:17:49 +03:00
});
};
export const hydrateAuthenticatedUser = async () => {
2020-08-07 05:17:49 +03:00
return await returnJSON(`/api/hydrate`, {
...DEFAULT_OPTIONS,
});
};
export const deleteViewer = async () => {
2020-08-07 05:17:49 +03:00
return await returnJSON(`/api/users/delete`, {
...DEFAULT_OPTIONS,
});
};
export const createUser = async (data) => {
2020-08-07 05:17:49 +03:00
return await returnJSON(`/api/users/create`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
2020-08-07 05:17:49 +03:00
});
};
export const checkCIDStatus = async (data) => {
2020-08-07 05:17:49 +03:00
return await returnJSON(`/api/data/cid-status`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
2020-08-07 05:17:49 +03:00
});
};
export const createSlate = async (data) => {
2020-08-07 05:17:49 +03:00
return await returnJSON(`/api/slates/create`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
2020-08-07 05:17:49 +03:00
});
};
export const updateSlate = async (data) => {
2020-08-07 05:17:49 +03:00
return await returnJSON(`/api/slates/update`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
2020-08-07 05:17:49 +03:00
});
};
2020-08-07 05:17:49 +03:00
export const deleteSlate = async (data) => {
return await returnJSON(`/api/slates/delete`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
2020-08-07 05:17:49 +03:00
export const deleteSlateItem = async (data) => {
return await returnJSON(`/api/slates/remove-item`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
2020-08-07 05:17:49 +03:00
export const generateAPIKey = async () => {
return await returnJSON(`/api/keys/generate`, {
...DEFAULT_OPTIONS,
});
};
export const deleteAPIKey = async (data) => {
2020-08-07 05:17:49 +03:00
return await returnJSON(`/api/keys/delete`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
2020-08-07 05:17:49 +03:00
});
};
export const deleteBucketItem = async (data) => {
return await returnJSON(`/api/data/remove`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
2020-09-03 06:26:56 +03:00
export const getSerializedSlate = async (data) => {
return await returnJSON(`/api/slates/get-serialized`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};
export const getSerializedProfile = async (data) => {
return await returnJSON(`/api/users/get-serialized`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};