getHashId,
getIdTagsFile,
getMaxNumberOfEvses,
+ getMessageTypeString,
getNumberOfReservableConnectors,
getPhaseRotationValue,
hasFeatureProfile,
} from './Helpers.js'
import { IdTagsCache } from './IdTagsCache.js'
import {
- getMessageTypeString,
OCPP16IncomingRequestService,
OCPP16RequestService,
OCPP16ResponseService,
import type { EventEmitter } from 'node:events'
-import chalk from 'chalk'
import {
addDays,
addSeconds,
ConnectorStatusEnum,
CurrentType,
type EvseTemplate,
+ MessageType,
OCPPVersion,
RecurrencyKindType,
type Reservation,
isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : ''
}`
logger.warn(`${logPrefix} ${logMsg}`)
- console.warn(`${chalk.green(logPrefix)} ${chalk.yellow(logMsg)}`)
}
}
}
return randomSerialNumberSuffix
}
+
+export const getMessageTypeString = (messageType: MessageType | undefined): string => {
+ switch (messageType) {
+ case MessageType.CALL_ERROR_MESSAGE:
+ return 'error'
+ case MessageType.CALL_MESSAGE:
+ return 'request'
+ case MessageType.CALL_RESULT_MESSAGE:
+ return 'response'
+ default:
+ return 'unknown'
+ }
+}
checkChargingStationState,
getConnectorChargingProfiles,
getIdTagsFile,
+ getMessageTypeString,
hasFeatureProfile,
hasPendingReservation,
hasPendingReservations,
import type { ChargingStation } from '../../ChargingStation.js'
+import { BaseError } from '../../../exception/index.js'
import {
type CertificateHashDataChainType,
type CertificateHashDataType,
issuerCertPem?: string
): CertificateHashDataType {
if (!this.validateCertificateFormat(pemData)) {
- throw new Error('Invalid PEM certificate format')
+ throw new BaseError('Invalid PEM certificate format')
}
const algorithmName = this.getHashAlgorithmName(hashAlgorithm)
// Check if resolved path is within the base directory
if (!fileResolved.startsWith(baseResolved + sep) && fileResolved !== baseResolved) {
- throw new Error(
+ throw new BaseError(
`Path traversal attempt detected: certificate path '${certificateFileName}' resolves outside base directory`
)
}
import { millisecondsToSeconds } from 'date-fns'
+import { BaseError } from '../../../exception/index.js'
import {
AttributeEnumType,
type ComponentType,
private getStationId (chargingStation: ChargingStation): string {
const stationId = chargingStation.stationInfo?.hashId
if (stationId == null) {
- throw new Error('ChargingStation has no stationInfo.hashId, cannot identify station')
+ throw new BaseError('ChargingStation has no stationInfo.hashId, cannot identify station')
}
return stationId
}
handleSendMessageError,
logger,
} from '../../utils/index.js'
+import { getMessageTypeString } from '../index.js'
import { OCPPConstants } from './OCPPConstants.js'
-import {
- ajvErrorsToErrorType,
- convertDateToISOString,
- getMessageTypeString,
-} from './OCPPServiceUtils.js'
+import { ajvErrorsToErrorType, convertDateToISOString } from './OCPPServiceUtils.js'
type Ajv = _Ajv.default
// eslint-disable-next-line @typescript-eslint/no-redeclare
type MeasurandPerPhaseSampledValueTemplates,
type MeasurandValues,
MessageTrigger,
- MessageType,
type MeterValue,
MeterValueContext,
MeterValueLocation,
value: number
}
-export const getMessageTypeString = (messageType: MessageType | undefined): string => {
- switch (messageType) {
- case MessageType.CALL_ERROR_MESSAGE:
- return 'error'
- case MessageType.CALL_MESSAGE:
- return 'request'
- case MessageType.CALL_RESULT_MESSAGE:
- return 'response'
- default:
- return 'unknown'
- }
-}
-
export const buildStatusNotificationRequest = (
chargingStation: ChargingStation,
commandParams: StatusNotificationRequest
buildMeterValue,
buildStatusNotificationRequest,
buildTransactionEndMeterValue,
- getMessageTypeString,
isIdTagAuthorized,
sendAndSetConnectorStatus,
} from './OCPPServiceUtils.js'
RequestCommand,
} from '../types/index.js'
-import { getMessageTypeString } from '../charging-station/ocpp/OCPPServiceUtils.js'
+import { getMessageTypeString } from '../charging-station/index.js'
import { logger } from './Logger.js'
import { isNotEmptyString } from './Utils.js'
getChargingStationId,
getHashId,
getMaxNumberOfEvses,
+ getMessageTypeString,
getPhaseRotationValue,
hasPendingReservation,
hasPendingReservations,
type ChargingStationTemplate,
type ConnectorStatus,
ConnectorStatusEnum,
+ MessageType,
type MeterValue,
OCPPVersion,
type Reservation,
assert.strictEqual(connectorStatus.MeterValues.length, 1)
})
})
+
+ await describe('getMessageTypeString', async () => {
+ await it('should return "request" for MessageType.CALL_MESSAGE', () => {
+ assert.strictEqual(getMessageTypeString(MessageType.CALL_MESSAGE), 'request')
+ })
+
+ await it('should return "response" for MessageType.CALL_RESULT_MESSAGE', () => {
+ assert.strictEqual(getMessageTypeString(MessageType.CALL_RESULT_MESSAGE), 'response')
+ })
+
+ await it('should return "error" for MessageType.CALL_ERROR_MESSAGE', () => {
+ assert.strictEqual(getMessageTypeString(MessageType.CALL_ERROR_MESSAGE), 'error')
+ })
+
+ await it('should return "unknown" for undefined', () => {
+ assert.strictEqual(getMessageTypeString(undefined), 'unknown')
+ })
+ })
})
* @description Verifies pure utility functions exported from OCPPServiceUtils
*
* Covers:
- * - getMessageTypeString — converts MessageType enum to human-readable string
* - ajvErrorsToErrorType — maps AJV validation errors to OCPP ErrorType
* - convertDateToISOString — recursively converts Date objects to ISO strings in-place
* - OCPPServiceUtils.isConnectorIdValid — validates connector ID ranges
import {
ajvErrorsToErrorType,
convertDateToISOString,
- getMessageTypeString,
OCPPServiceUtils,
} from '../../../src/charging-station/ocpp/OCPPServiceUtils.js'
-import {
- ErrorType,
- IncomingRequestCommand,
- type JsonType,
- MessageType,
-} from '../../../src/types/index.js'
+import { ErrorType, IncomingRequestCommand, type JsonType } from '../../../src/types/index.js'
import { standardCleanup } from '../../helpers/TestLifecycleHelpers.js'
/**
standardCleanup()
})
- await describe('getMessageTypeString', async () => {
- await it('should return "request" for MessageType.CALL_MESSAGE', () => {
- assert.strictEqual(getMessageTypeString(MessageType.CALL_MESSAGE), 'request')
- })
-
- await it('should return "response" for MessageType.CALL_RESULT_MESSAGE', () => {
- assert.strictEqual(getMessageTypeString(MessageType.CALL_RESULT_MESSAGE), 'response')
- })
-
- await it('should return "error" for MessageType.CALL_ERROR_MESSAGE', () => {
- assert.strictEqual(getMessageTypeString(MessageType.CALL_ERROR_MESSAGE), 'error')
- })
-
- await it('should return "unknown" for undefined', () => {
- assert.strictEqual(getMessageTypeString(undefined), 'unknown')
- })
- })
-
await describe('ajvErrorsToErrorType', async () => {
await it('should return FormatViolation for null errors', () => {
assert.strictEqual(ajvErrorsToErrorType(null), ErrorType.FORMAT_VIOLATION)