Added available services
MODIFY
src/server/ocpi/router/cpo/CPORouter.ts
src/server/ocpi/router/cpo/CPORouter.ts
/* eslint-disable @typescript-eslint/no-misused-promises */
-import { OCPIServerRoute, ServerAction } from '../../../../types/Server';
+import { OCPIServerRoute, OCPIServerRouteVersions, ServerAction } from '../../../../types/Server';
import express, { NextFunction, Request, Response } from 'express';
import CPOCdrsRouterV211 from './V2.1.1/CPOCdrsRouterV211';
@@ -32,7 +32,10 @@ export default class CPORouter {
}
protected buildRouteCpoV211(): void {
- this.router.use('/2.1.1', [
+ this.router.get(`/${OCPIServerRouteVersions.VERSION_211}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(CPOVersionsService.getSupportedServices.bind(this), ServerAction.OCPI_CPO_GET_SERVICES, req, res, next);
+ });
+ this.router.use(`/${OCPIServerRouteVersions.VERSION_211}`, [
new CPOLocationsRouterV211().buildRoutes(),
new CPOTokensRouterV211().buildRoutes(),
new CPOCdrsRouterV211().buildRoutes(),

MODIFY
src/server/ocpi/router/emsp/EMSPRouter.ts
src/server/ocpi/router/emsp/EMSPRouter.ts
+import { OCPIServerRoute, OCPIServerRouteVersions, ServerAction } from '../../../../types/Server';
/* eslint-disable @typescript-eslint/no-misused-promises */
-import { OCPIServerRoute, ServerAction } from '../../../../types/Server';
import express, { NextFunction, Request, Response } from 'express';
import CPOEMSPCredentialsRouterV211 from '../common/V2.1.1/CPOEMSPCredentialsRouterV211';
@@ -10,11 +10,8 @@ import EMSPSessionsRouterV211 from './V2.1.1/EMSPSessionsRouterV211';
import EMSPTariffsRouterV211 from './V2.1.1/EMSPTariffsRouterV211';
import EMSPTokensRouterV211 from './V2.1.1/EMSPTokensRouterV211';
import EMSPVersionsService from '../../service/emsp/EMSPVersionsService';
-import OCPIUtils from '../../OCPIUtils';
-import OCPIUtilsService from '../../service/OCPIUtilsService';
import RouterUtils from '../../../../utils/RouterUtils';
-const VERSION = '2.1.1';
export default class EMSPRouter {
private router: express.Router;
@@ -35,10 +32,10 @@ export default class EMSPRouter {
}
protected buildRouteEmspV211(): void {
- this.router.get(`/${VERSION}`, async (req: Request, res: Response, next: NextFunction) => {
- await RouterUtils.handleServerAction(this.getSupportedServices.bind(this), ServerAction.OCPI_CPO_GET_SERVICES, req, res, next);
+ this.router.get(`/${OCPIServerRouteVersions.VERSION_211}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(EMSPVersionsService.getSupportedServices.bind(this), ServerAction.OCPI_EMSP_GET_SERVICES, req, res, next);
});
- this.router.use(`/${VERSION}`, [
+ this.router.use(`/${OCPIServerRouteVersions.VERSION_211}`, [
new EMSPTokensRouterV211().buildRoutes(),
new EMSPLocationsRouterV211().buildRoutes(),
new EMSPSessionsRouterV211().buildRoutes(),
@@ -48,14 +45,4 @@ export default class EMSPRouter {
new CPOEMSPCredentialsRouterV211().buildRoutes(),
]);
}
-
- protected getSupportedServices(action: ServerAction, req: Request, res: Response, next: NextFunction): void {
- const identifiers = Array.from(Object.values(OCPIServerRoute));
- const fullUrl = OCPIUtilsService.getServiceUrl(req, 'emsp');
- // Build payload
- const supportedEndpoints = identifiers.map((identifier: string) => ({ identifier, url: `${fullUrl}/${identifier}/` }));
- // Return payload
- res.json(OCPIUtils.success({ 'version': VERSION, 'endpoints': supportedEndpoints }));
- next();
- }
}

MODIFY
src/server/ocpi/service/cpo/CPOVersionsService.ts
src/server/ocpi/service/cpo/CPOVersionsService.ts
import { NextFunction, Request, Response } from 'express';
+import { OCPIServerRoute, OCPIServerRouteVersions, ServerAction } from '../../../../types/Server';
import OCPIUtils from '../../OCPIUtils';
-import { ServerAction } from '../../../../types/Server';
+import OCPIUtilsService from '../OCPIUtilsService';
export default class CPOVersionsService {
public static handleGetVersions(action: ServerAction, req: Request, res: Response, next: NextFunction): void {
try {
const versions = [
{
- version: '2.1.1',
- url: `https://${req.get('host')}/ocpi/cpo/2.1.1/`
+ version: OCPIServerRouteVersions.VERSION_211,
+ url: `https://${req.get('host')}/ocpi/cpo/${OCPIServerRouteVersions.VERSION_211}/`
}
];
res.json(OCPIUtils.success(versions));
@@ -17,4 +18,14 @@ export default class CPOVersionsService {
next(error);
}
}
+
+ public static getSupportedServices(action: ServerAction, req: Request, res: Response, next: NextFunction): void {
+ const identifiers = Array.from(Object.values(OCPIServerRoute)).filter((identifier) => (identifier !== 'versions'));
+ const fullUrl = OCPIUtilsService.getServiceUrl(req, 'emsp');
+ // Build payload
+ const supportedEndpoints = identifiers.map((identifier: string) => ({ identifier, url: `${fullUrl}/${OCPIServerRouteVersions.VERSION_211}/${identifier}/` }));
+ // Return payload
+ res.json(OCPIUtils.success({ 'version': OCPIServerRouteVersions.VERSION_211, 'endpoints': supportedEndpoints }));
+ next();
+ }
}

MODIFY
src/server/ocpi/service/emsp/EMSPVersionsService.ts
src/server/ocpi/service/emsp/EMSPVersionsService.ts
import { NextFunction, Request, Response } from 'express';
+import { OCPIServerRoute, OCPIServerRouteVersions, ServerAction } from '../../../../types/Server';
import OCPIUtils from '../../OCPIUtils';
-import { ServerAction } from '../../../../types/Server';
+import OCPIUtilsService from '../OCPIUtilsService';
export default class EMSPVersionsService {
public static handleGetVersions(action: ServerAction, req: Request, res: Response, next: NextFunction): void {
try {
const versions = [
{
- version: '2.1.1',
- url: `https://${req.get('host')}/ocpi/emsp/2.1.1/`
+ version: OCPIServerRouteVersions.VERSION_211,
+ url: `https://${req.get('host')}/ocpi/emsp/${OCPIServerRouteVersions.VERSION_211}/`
}
];
res.json(OCPIUtils.success(versions));
@@ -17,4 +18,14 @@ export default class EMSPVersionsService {
next(error);
}
}
+
+ public static getSupportedServices(action: ServerAction, req: Request, res: Response, next: NextFunction): void {
+ const identifiers = Array.from(Object.values(OCPIServerRoute)).filter((identifier) => (identifier !== 'versions'));
+ const fullUrl = OCPIUtilsService.getServiceUrl(req, 'emsp');
+ // Build payload
+ const supportedEndpoints = identifiers.map((identifier: string) => ({ identifier, url: `${fullUrl}/${OCPIServerRouteVersions.VERSION_211}/${identifier}/` }));
+ // Return payload
+ res.json(OCPIUtils.success({ 'version': OCPIServerRouteVersions.VERSION_211, 'endpoints': supportedEndpoints }));
+ next();
+ }
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -166,6 +166,7 @@ export enum ServerAction {
OCPI_CPO_AUTHORIZE_TOKEN = 'OcpiCpoAuthorizeToken',
OCPI_CPO_GET_TARIFFS = 'OcpiCpoGetTariffs',
+ OCPI_EMSP_GET_SERVICES = 'OcpiEmspGetServices',
OCPI_EMSP_COMMAND = 'OcpiEmspCommand',
OCPI_EMSP_AUTHORIZE_TOKEN = 'OcpiEmspAuthorizeToken',
OCPI_EMSP_UPDATE_LOCATION = 'OcpiEmspUpdateLocation',
@@ -674,14 +675,18 @@ export enum RESTServerRoute {
}
export enum OCPIServerRoute {
- OCPI_VERSIONS = 'versions',
+ OCPI_CREDENTIALS = 'credentials',
OCPI_LOCATIONS = 'locations',
+ OCPI_TOKENS = 'tokens',
+ OCPI_SESSIONS = 'sessions',
OCPI_CDRS = 'cdrs',
OCPI_COMMANDS = 'commands',
- OCPI_TOKENS = 'tokens',
- OCPI_CREDENTIALS = 'credentials',
OCPI_TARIFFS = 'tariffs',
- OCPI_SESSIONS = 'sessions',
+ OCPI_VERSIONS = 'versions',
+}
+
+export enum OCPIServerRouteVersions {
+ VERSION_211 = '2.1.1'
}
export enum ServerProtocol {

MODIFY
src/types/ocpi/OCPIStatusCode.ts
src/types/ocpi/OCPIStatusCode.ts
export class OCPIStatusCode {
// 1*** SUCCESS
- static readonly CODE_1000_SUCCESS = new OCPIStatusCode(1000, 'Success');
+ public static readonly CODE_1000_SUCCESS = new OCPIStatusCode(1000, 'Success');
// 2*** CLIENT ERROR
- static readonly CODE_2000_GENERIC_CLIENT_ERROR = new OCPIStatusCode(2000, 'Generic Client Error');
- static readonly CODE_2001_INVALID_PARAMETER_ERROR = new OCPIStatusCode(2001, 'Invalid or Missing Parameters');
- static readonly CODE_2002_NOT_ENOUGH_INFORMATION_ERROR = new OCPIStatusCode(2002, 'Not enough information');
- static readonly CODE_2003_UNKNOWN_LOCATION_ERROR = new OCPIStatusCode(2003, 'Unknown Location');
+ public static readonly CODE_2000_GENERIC_CLIENT_ERROR = new OCPIStatusCode(2000, 'Generic Client Error');
+ public static readonly CODE_2001_INVALID_PARAMETER_ERROR = new OCPIStatusCode(2001, 'Invalid or Missing Parameters');
+ public static readonly CODE_2002_NOT_ENOUGH_INFORMATION_ERROR = new OCPIStatusCode(2002, 'Not enough information');
+ public static readonly CODE_2003_UNKNOWN_LOCATION_ERROR = new OCPIStatusCode(2003, 'Unknown Location');
// 3*** SERVER ERROR
- static readonly CODE_3000_GENERIC_SERVER_ERROR = new OCPIStatusCode(3000, 'Generic Server Error');
- static readonly CODE_3001_UNABLE_TO_USE_CLIENT_API_ERROR = new OCPIStatusCode(3001, 'Unable to Use Client API');
- static readonly CODE_3002_UNSUPPORTED_VERSION_ERROR = new OCPIStatusCode(3002, 'Unsupported Version');
- static readonly CODE_3003_NO_MATCHING_ENDPOINTS_ERROR = new OCPIStatusCode(3003, 'No Matching Endpoints');
+ public static readonly CODE_3000_GENERIC_SERVER_ERROR = new OCPIStatusCode(3000, 'Generic Server Error');
+ public static readonly CODE_3001_UNABLE_TO_USE_CLIENT_API_ERROR = new OCPIStatusCode(3001, 'Unable to Use Client API');
+ public static readonly CODE_3002_UNSUPPORTED_VERSION_ERROR = new OCPIStatusCode(3002, 'Unsupported Version');
+ public static readonly CODE_3003_NO_MATCHING_ENDPOINTS_ERROR = new OCPIStatusCode(3003, 'No Matching Endpoints');
// Private to disallow creating other instances of this type
private constructor(public readonly status_code: number, public readonly status_message: string) {

Added available services