export const buildConnectorsStatus = (chargingStation: ChargingStation): ConnectorStatus[] => {
return [...chargingStation.connectors.values()].map(
- ({ transactionSetInterval, ...connectorStatusRest }) => connectorStatusRest
+ ({ transactionSetInterval, ...connectorStatus }) => connectorStatus
)
}
// eslint-disable-next-line array-callback-return
return [...chargingStation.evses.values()].map(evseStatus => {
const connectorsStatus = [...evseStatus.connectors.values()].map(
- ({ transactionSetInterval, ...connectorStatusRest }) => connectorStatusRest
+ ({ transactionSetInterval, ...connectorStatus }) => connectorStatus
)
let status: EvseStatusConfiguration
switch (outputFormat) {
type UIServerConfigurationSection
} from '@/types'
-import { randomUUID } from './Utils'
+import { randomUUID, validateUUID } from './Utils'
type ResponseHandler = {
procedureName: ProcedureName
try {
response = JSON.parse(messageEvent.data) as ProtocolResponse
} catch (error) {
- useToast().error('Invalid response format')
- console.error('Invalid response format', error)
+ useToast().error('Invalid response JSON format')
+ console.error('Invalid response JSON format', error)
return
}
const [uuid, responsePayload] = response
+ if (!validateUUID(uuid)) {
+ useToast().error('Response UUID field is invalid')
+ console.error('Response UUID field is invalid:', response)
+ return
+ }
+
if (this.responseHandlers.has(uuid)) {
const { procedureName, resolve, reject } = this.responseHandlers.get(uuid)!
switch (responsePayload.status) {
return crypto.randomUUID()
}
+export const validateUUID = (
+ uuid: `${string}-${string}-${string}-${string}-${string}`
+): uuid is `${string}-${string}-${string}-${string}-${string}` => {
+ return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(uuid)
+}
+
export const useUIClient = (): UIClient => {
return UIClient.getInstance()
}