"@types/express": "^4.17.13",
"@types/mocha": "^9.1.1",
"@types/mochawesome": "^6.2.1",
- "@types/node": "^18.7.6",
+ "@types/node": "^18.7.8",
"@types/proper-lockfile": "^4.1.2",
"@types/tar": "^6.1.2",
"@types/uuid": "^8.3.4",
}
},
"node_modules/@types/node": {
- "version": "18.7.6",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.6.tgz",
- "integrity": "sha512-EdxgKRXgYsNITy5mjjXjVE/CS8YENSdhiagGrLqjG0pvA2owgJ6i4l7wy/PFZGC0B1/H20lWKN7ONVDNYDZm7A=="
+ "version": "18.7.8",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.8.tgz",
+ "integrity": "sha512-/YP55EMK2341JkODUb8DM9O0x1SIz2aBvyF33Uf1c76St3VpsMXEIW0nxuKkq/5cxnbz0RD9cfwNZHEAZQD3ag=="
},
"node_modules/@types/object-path": {
"version": "0.11.1",
}
},
"node_modules/new-github-release-url/node_modules/type-fest": {
- "version": "2.18.0",
- "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.18.0.tgz",
- "integrity": "sha512-pRS+/yrW5TjPPHNOvxhbNZexr2bS63WjrMU8a+VzEBhUi9Tz1pZeD+vQz3ut0svZ46P+SRqMEPnJmk2XnvNzTw==",
+ "version": "2.18.1",
+ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.18.1.tgz",
+ "integrity": "sha512-UKCINsd4qiATXD6OIlnQw9t1ux/n2ld+Nl0kzPbCONhCaUIS/BhJbNw14w6584HCQWf3frBK8vmWnGZq/sbPHQ==",
"dev": true,
"engines": {
"node": ">=12.20"
}
},
"node_modules/release-it/node_modules/boxen/node_modules/type-fest": {
- "version": "2.18.0",
- "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.18.0.tgz",
- "integrity": "sha512-pRS+/yrW5TjPPHNOvxhbNZexr2bS63WjrMU8a+VzEBhUi9Tz1pZeD+vQz3ut0svZ46P+SRqMEPnJmk2XnvNzTw==",
+ "version": "2.18.1",
+ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.18.1.tgz",
+ "integrity": "sha512-UKCINsd4qiATXD6OIlnQw9t1ux/n2ld+Nl0kzPbCONhCaUIS/BhJbNw14w6584HCQWf3frBK8vmWnGZq/sbPHQ==",
"dev": true,
"engines": {
"node": ">=12.20"
}
},
"@types/node": {
- "version": "18.7.6",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.6.tgz",
- "integrity": "sha512-EdxgKRXgYsNITy5mjjXjVE/CS8YENSdhiagGrLqjG0pvA2owgJ6i4l7wy/PFZGC0B1/H20lWKN7ONVDNYDZm7A=="
+ "version": "18.7.8",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.8.tgz",
+ "integrity": "sha512-/YP55EMK2341JkODUb8DM9O0x1SIz2aBvyF33Uf1c76St3VpsMXEIW0nxuKkq/5cxnbz0RD9cfwNZHEAZQD3ag=="
},
"@types/object-path": {
"version": "0.11.1",
},
"dependencies": {
"type-fest": {
- "version": "2.18.0",
- "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.18.0.tgz",
- "integrity": "sha512-pRS+/yrW5TjPPHNOvxhbNZexr2bS63WjrMU8a+VzEBhUi9Tz1pZeD+vQz3ut0svZ46P+SRqMEPnJmk2XnvNzTw==",
+ "version": "2.18.1",
+ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.18.1.tgz",
+ "integrity": "sha512-UKCINsd4qiATXD6OIlnQw9t1ux/n2ld+Nl0kzPbCONhCaUIS/BhJbNw14w6584HCQWf3frBK8vmWnGZq/sbPHQ==",
"dev": true
}
}
},
"dependencies": {
"type-fest": {
- "version": "2.18.0",
- "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.18.0.tgz",
- "integrity": "sha512-pRS+/yrW5TjPPHNOvxhbNZexr2bS63WjrMU8a+VzEBhUi9Tz1pZeD+vQz3ut0svZ46P+SRqMEPnJmk2XnvNzTw==",
+ "version": "2.18.1",
+ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.18.1.tgz",
+ "integrity": "sha512-UKCINsd4qiATXD6OIlnQw9t1ux/n2ld+Nl0kzPbCONhCaUIS/BhJbNw14w6584HCQWf3frBK8vmWnGZq/sbPHQ==",
"dev": true
}
}
"@types/express": "^4.17.13",
"@types/mocha": "^9.1.1",
"@types/mochawesome": "^6.2.1",
- "@types/node": "^18.7.6",
+ "@types/node": "^18.7.8",
"@types/proper-lockfile": "^4.1.2",
"@types/tar": "^6.1.2",
"@types/uuid": "^8.3.4",
ChargingStationUtils.isIncomingRequestCommandSupported(commandName, chargingStation)
) {
try {
- if (this.jsonSchemas.has(commandName)) {
- this.validateIncomingRequestPayload(
- chargingStation,
- commandName,
- this.jsonSchemas.get(commandName),
- commandPayload
- );
- } else {
- logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: No JSON schema found for command ${commandName} PDU validation`
- );
- }
+ this.validatePayload(chargingStation, commandName, commandPayload);
// Call the method to build the response
response = await this.incomingRequestHandlers.get(commandName)(
chargingStation,
);
}
+ private validatePayload(
+ chargingStation: ChargingStation,
+ commandName: OCPP16IncomingRequestCommand,
+ commandPayload: JsonType
+ ): boolean {
+ if (this.jsonSchemas.has(commandName)) {
+ return this.validateIncomingRequestPayload(
+ chargingStation,
+ commandName,
+ this.jsonSchemas.get(commandName),
+ commandPayload
+ );
+ }
+ logger.warn(
+ `${chargingStation.logPrefix()} ${moduleName}.incomingRequestHandler: No JSON schema found for command ${commandName} PDU validation`
+ );
+ return false;
+ }
+
// Simulate charging station restart
private handleRequestReset(
chargingStation: ChargingStation,
commandName,
commandParams
);
- if (this.jsonSchemas.has(commandName)) {
- this.validateRequestPayload(
- chargingStation,
- commandName,
- this.jsonSchemas.get(commandName),
- requestPayload
- );
- } else {
- logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.requestHandler: No JSON schema found for command ${commandName} PDU validation`
- );
- }
+ this.validatePayload(chargingStation, commandName, requestPayload);
return (await this.sendMessage(
chargingStation,
Utils.generateUUID(),
);
}
}
+
+ private validatePayload<Request extends JsonType>(
+ chargingStation: ChargingStation,
+ commandName: OCPP16RequestCommand,
+ requestPayload: Request
+ ): boolean {
+ if (this.jsonSchemas.has(commandName)) {
+ return this.validateRequestPayload(
+ chargingStation,
+ commandName,
+ this.jsonSchemas.get(commandName),
+ requestPayload
+ );
+ }
+ logger.warn(
+ `${chargingStation.logPrefix()} ${moduleName}.requestHandler: No JSON schema found for command ${commandName} PDU validation`
+ );
+ return false;
+ }
}
ChargingStationUtils.isRequestCommandSupported(commandName, chargingStation)
) {
try {
- if (this.jsonSchemas.has(commandName)) {
- this.validateResponsePayload(
- chargingStation,
- commandName,
- this.jsonSchemas.get(commandName),
- payload
- );
- } else {
- logger.warn(
- `${chargingStation.logPrefix()} ${moduleName}.responseHandler: No JSON schema found for command ${commandName} PDU validation`
- );
- }
+ this.validatePayload(chargingStation, commandName, payload);
await this.responseHandlers.get(commandName)(chargingStation, payload, requestPayload);
} catch (error) {
logger.error(chargingStation.logPrefix() + ' Handle request response error: %j', error);
}
}
+ private validatePayload(
+ chargingStation: ChargingStation,
+ commandName: OCPP16RequestCommand,
+ payload: JsonType
+ ): boolean {
+ if (this.jsonSchemas.has(commandName)) {
+ return this.validateResponsePayload(
+ chargingStation,
+ commandName,
+ this.jsonSchemas.get(commandName),
+ payload
+ );
+ }
+ logger.warn(
+ `${chargingStation.logPrefix()} ${moduleName}.responseHandler: No JSON schema found for command ${commandName} PDU validation`
+ );
+ return false;
+ }
+
private handleResponseBootNotification(
chargingStation: ChargingStation,
payload: OCPP16BootNotificationResponse