UI Protocol: add Authorize command support
[e-mobility-charging-stations-simulator.git] / src / types / UIProtocol.ts
1 import type { JsonObject } from './JsonType';
2 import type { BroadcastChannelResponsePayload } from './WorkerBroadcastChannel';
3
4 export enum Protocol {
5 UI = 'ui',
6 }
7
8 export enum ApplicationProtocol {
9 HTTP = 'http',
10 WS = 'ws',
11 }
12
13 export enum AuthenticationType {
14 BASIC_AUTH = 'basic-auth',
15 }
16
17 export enum ProtocolVersion {
18 '0.0.1' = '0.0.1',
19 }
20
21 export type ProtocolRequest = [string, ProcedureName, RequestPayload];
22 export type ProtocolResponse = [string, ResponsePayload];
23
24 export type ProtocolRequestHandler = (
25 uuid?: string,
26 payload?: RequestPayload
27 ) => undefined | Promise<undefined> | ResponsePayload | Promise<ResponsePayload>;
28
29 export enum ProcedureName {
30 LIST_CHARGING_STATIONS = 'listChargingStations',
31 START_CHARGING_STATION = 'startChargingStation',
32 STOP_CHARGING_STATION = 'stopChargingStation',
33 START_SIMULATOR = 'startSimulator',
34 STOP_SIMULATOR = 'stopSimulator',
35 OPEN_CONNECTION = 'openConnection',
36 CLOSE_CONNECTION = 'closeConnection',
37 START_TRANSACTION = 'startTransaction',
38 STOP_TRANSACTION = 'stopTransaction',
39 START_AUTOMATIC_TRANSACTION_GENERATOR = 'startAutomaticTransactionGenerator',
40 STOP_AUTOMATIC_TRANSACTION_GENERATOR = 'stopAutomaticTransactionGenerator',
41 AUTHORIZE = 'authorize',
42 STATUS_NOTIFICATION = 'statusNotification',
43 HEARTBEAT = 'heartbeat',
44 }
45
46 export interface RequestPayload extends JsonObject {
47 hashIds?: string[];
48 connectorIds?: number[];
49 }
50
51 export enum ResponseStatus {
52 SUCCESS = 'success',
53 FAILURE = 'failure',
54 }
55
56 export interface ResponsePayload extends JsonObject {
57 status: ResponseStatus;
58 hashIdsSucceeded?: string[];
59 hashIdsFailed?: string[];
60 responsesFailed?: BroadcastChannelResponsePayload[];
61 }