2023-04-28 18:28:01 +00:00
|
|
|
import wrap from './wrap';
|
|
|
|
interface Route {
|
|
|
|
Name: string;
|
|
|
|
}
|
|
|
|
|
2023-04-29 11:11:03 +00:00
|
|
|
type Operation = 'replace' | 'move_up' | 'move_down' | 'delete' | 'add';
|
2023-04-28 18:28:01 +00:00
|
|
|
|
|
|
|
function get() {
|
|
|
|
return wrap(fetch('/cosmos/api/config', {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
function set(values) {
|
|
|
|
return wrap(fetch('/cosmos/api/config', {
|
|
|
|
method: 'PUT',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify(values),
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
function restart() {
|
|
|
|
return fetch('/cosmos/api/restart', {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-01 10:00:45 +00:00
|
|
|
function canSendEmail() {
|
|
|
|
return wrap(fetch('/cosmos/api/can-send-email', {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2023-04-28 18:28:01 +00:00
|
|
|
async function rawUpdateRoute(routeName: string, operation: Operation, newRoute?: Route): Promise<void> {
|
|
|
|
const payload = {
|
|
|
|
routeName,
|
|
|
|
operation,
|
|
|
|
newRoute,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (operation === 'replace') {
|
|
|
|
if (!newRoute) throw new Error('newRoute must be provided for replace operation');
|
|
|
|
}
|
|
|
|
|
|
|
|
return wrap(fetch('/cosmos/api/config', {
|
|
|
|
method: 'PATCH',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify(payload),
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function replaceRoute(routeName: string, newRoute: Route): Promise<void> {
|
|
|
|
return rawUpdateRoute(routeName, 'replace', newRoute);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function moveRouteUp(routeName: string): Promise<void> {
|
|
|
|
return rawUpdateRoute(routeName, 'move_up');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function moveRouteDown(routeName: string): Promise<void> {
|
|
|
|
return rawUpdateRoute(routeName, 'move_down');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteRoute(routeName: string): Promise<void> {
|
|
|
|
return rawUpdateRoute(routeName, 'delete');
|
|
|
|
}
|
2023-04-29 11:11:03 +00:00
|
|
|
async function addRoute(newRoute: Route): Promise<void> {
|
|
|
|
return rawUpdateRoute("", 'add', newRoute);
|
|
|
|
}
|
|
|
|
|
2023-04-28 18:28:01 +00:00
|
|
|
export {
|
|
|
|
get,
|
|
|
|
set,
|
|
|
|
restart,
|
|
|
|
rawUpdateRoute,
|
|
|
|
replaceRoute,
|
|
|
|
moveRouteUp,
|
|
|
|
moveRouteDown,
|
|
|
|
deleteRoute,
|
2023-04-29 11:11:03 +00:00
|
|
|
addRoute,
|
2023-05-01 10:00:45 +00:00
|
|
|
canSendEmail,
|
2023-04-28 18:28:01 +00:00
|
|
|
};
|