2022-07-21 18:39:33 +02:00
|
|
|
import {
|
|
|
|
CreateOrUpdateNode,
|
|
|
|
Domain,
|
|
|
|
DomainSpecificNodeResponse,
|
|
|
|
MonitoringResponse,
|
|
|
|
MonitoringState,
|
|
|
|
MonitoringToken,
|
|
|
|
NodeResponse,
|
|
|
|
NodeTokenResponse,
|
|
|
|
OnlineState,
|
|
|
|
Site,
|
|
|
|
StoredNode,
|
2022-08-04 15:31:01 +02:00
|
|
|
} from "../shared/types";
|
2022-05-26 13:58:01 +02:00
|
|
|
|
2020-06-30 01:10:18 +02:00
|
|
|
export * from "./config";
|
2022-07-21 12:07:18 +02:00
|
|
|
export * from "./database";
|
2020-06-30 01:10:18 +02:00
|
|
|
export * from "./logger";
|
2022-08-04 15:31:01 +02:00
|
|
|
export * from "../shared/types";
|
2020-06-30 01:10:18 +02:00
|
|
|
|
2020-04-10 00:43:15 +02:00
|
|
|
export type NodeStateData = {
|
2022-08-23 20:08:53 +02:00
|
|
|
site?: Site;
|
|
|
|
domain?: Domain;
|
|
|
|
state: OnlineState;
|
|
|
|
};
|
2020-04-10 00:43:15 +02:00
|
|
|
|
2022-07-21 18:39:33 +02:00
|
|
|
export function toCreateOrUpdateNode(node: StoredNode): CreateOrUpdateNode {
|
|
|
|
return {
|
|
|
|
nickname: node.nickname,
|
|
|
|
email: node.email,
|
|
|
|
hostname: node.hostname,
|
|
|
|
coords: node.coords,
|
|
|
|
key: node.key,
|
|
|
|
mac: node.mac,
|
|
|
|
monitoring: node.monitoringState !== MonitoringState.DISABLED,
|
2022-08-23 20:08:53 +02:00
|
|
|
};
|
2022-07-21 18:39:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function toNodeResponse(node: StoredNode): NodeResponse {
|
|
|
|
return {
|
|
|
|
token: node.token,
|
|
|
|
nickname: node.nickname,
|
|
|
|
email: node.email,
|
|
|
|
hostname: node.hostname,
|
|
|
|
coords: node.coords,
|
|
|
|
key: node.key,
|
|
|
|
mac: node.mac,
|
|
|
|
monitoring: node.monitoringState !== MonitoringState.DISABLED,
|
|
|
|
monitoringConfirmed: node.monitoringState === MonitoringState.ACTIVE,
|
|
|
|
monitoringState: node.monitoringState,
|
|
|
|
modifiedAt: node.modifiedAt,
|
2022-08-23 20:08:53 +02:00
|
|
|
};
|
2022-07-21 18:39:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function toNodeTokenResponse(node: StoredNode): NodeTokenResponse {
|
|
|
|
return {
|
|
|
|
token: node.token,
|
|
|
|
node: toNodeResponse(node),
|
2022-08-23 20:08:53 +02:00
|
|
|
};
|
2022-07-21 18:39:33 +02:00
|
|
|
}
|
|
|
|
|
2022-08-23 20:08:53 +02:00
|
|
|
export function toDomainSpecificNodeResponse(
|
|
|
|
node: StoredNode,
|
|
|
|
nodeStateData: NodeStateData
|
|
|
|
): DomainSpecificNodeResponse {
|
2022-07-21 18:39:33 +02:00
|
|
|
return {
|
2022-07-22 17:11:08 +02:00
|
|
|
token: node.token,
|
|
|
|
nickname: node.nickname,
|
|
|
|
email: node.email,
|
|
|
|
hostname: node.hostname,
|
|
|
|
coords: node.coords,
|
|
|
|
key: node.key,
|
|
|
|
mac: node.mac,
|
|
|
|
monitoring: node.monitoringState !== MonitoringState.DISABLED,
|
|
|
|
monitoringConfirmed: node.monitoringState === MonitoringState.ACTIVE,
|
|
|
|
monitoringState: node.monitoringState,
|
|
|
|
modifiedAt: node.modifiedAt,
|
2022-07-21 18:39:33 +02:00
|
|
|
site: nodeStateData.site,
|
|
|
|
domain: nodeStateData.domain,
|
|
|
|
onlineState: nodeStateData.state,
|
2022-08-23 20:08:53 +02:00
|
|
|
};
|
2022-07-21 18:39:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function toMonitoringResponse(node: StoredNode): MonitoringResponse {
|
|
|
|
return {
|
|
|
|
hostname: node.hostname,
|
|
|
|
mac: node.mac,
|
|
|
|
email: node.email,
|
|
|
|
monitoring: node.monitoringState !== MonitoringState.DISABLED,
|
|
|
|
monitoringConfirmed: node.monitoringState === MonitoringState.ACTIVE,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-10 00:43:15 +02:00
|
|
|
export type NodeSecrets = {
|
2022-08-23 20:08:53 +02:00
|
|
|
monitoringToken?: MonitoringToken;
|
2020-04-10 00:43:15 +02:00
|
|
|
};
|