diff --git a/.github/workflows/test-build-server.yml b/.github/workflows/test-build-server.yml index e34ca8c1b..7a8e21937 100644 --- a/.github/workflows/test-build-server.yml +++ b/.github/workflows/test-build-server.yml @@ -17,4 +17,4 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Build image - run: docker build . --file ./Server/docker/Dockerfile --tag $IMAGE_NAME + run: docker build . --file ./Server/deploy.Dockerfile --tag $IMAGE_NAME diff --git a/.gitignore b/.gitignore index 3acf3ba6d..9886c801d 100644 --- a/.gitignore +++ b/.gitignore @@ -209,5 +209,97 @@ package-lock.json /Server/data/postgresql /Swarm/data/postgresql -# Intellij -.idea/ \ No newline at end of file +# Created by https://www.toptal.com/developers/gitignore/api/intellij+all +# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +#!.idea/codeStyles // todo potentially comment back in when vscode and intellij configs are supported +#!.idea/runConfigurations // todo potentially comment back in when vscode and intellij configs are supported + +# End of https://www.toptal.com/developers/gitignore/api/intellij+all + +data diff --git a/00_Base/package.json b/00_Base/package.json index ee23320d0..952f2865f 100644 --- a/00_Base/package.json +++ b/00_Base/package.json @@ -2,17 +2,17 @@ "name": "@citrineos/base", "version": "1.0.0", "description": "The base module for OCPP v2.0.1 including all interfaces. This module is not intended to be used directly, but rather as a dependency for other modules.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { "prepublish": "npx eslint ./src", - "prepare": "npm run build", - "build": "tsc", "generate-interfaces": "node json-schema-processor.js", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "npm run clean && tsc -p tsconfig.json", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -37,5 +37,6 @@ "tslog": "^4.9.2", "uuid": "^9.0.0", "zod": "^3.22.2" - } + }, + "workspace": "../" } diff --git a/00_Base/src/index.ts b/00_Base/src/index.ts index cd8cdf33d..02b5b93db 100644 --- a/00_Base/src/index.ts +++ b/00_Base/src/index.ts @@ -171,4 +171,6 @@ export const CALL_RESULT_SCHEMA_MAP: Map = new Map { + const eventGroup: EventGroup = source as EventGroup; + if (!eventGroup) { + throw new Error(`Invalid event group soruce ${source}"`); + } + return eventGroup; +} + export { IMessage, Message } from "./Message"; export { IMessageHandler } from "./MessageHandler"; export { IMessageSender } from "./MessageSender"; diff --git a/00_Base/tsconfig.json b/00_Base/tsconfig.json index 5cebe347b..098d9daf0 100644 --- a/00_Base/tsconfig.json +++ b/00_Base/tsconfig.json @@ -1,21 +1,12 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" - ] + "compilerOptions": { + "outDir": "./dist/", + "composite": true, + "rootDir": "./src" + } } \ No newline at end of file diff --git a/01_Data/package.json b/01_Data/package.json index 0b0efbdf7..a8565a273 100644 --- a/01_Data/package.json +++ b/01_Data/package.json @@ -2,17 +2,16 @@ "name": "@citrineos/data", "version": "1.0.0", "description": "The OCPP data module which includes all persistence layer implementation.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { - "install-base": "cd ../00_Base && npm run build && npm pack && cd ../01_Data && npm install ../00_Base/citrineos-base-1.0.0.tgz", "prepublish": "npx eslint", - "prepare": "npm run build", - "build": "tsc", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "npm run clean && tsc -p tsconfig.json", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -27,7 +26,8 @@ "typescript": "^5.0.4" }, "dependencies": { - "@citrineos/base": "file:../00_Base/citrineos-base-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@types/sequelize": "^4.28.20", "bcrypt": "^5.1.1", "pg": "^8.11.3", "pg-hstore": "^2.3.4", @@ -37,5 +37,6 @@ }, "engines": { "node": ">=18" - } + }, + "workspace": "../" } diff --git a/01_Data/src/index.ts b/01_Data/src/index.ts index 2762af0de..9d5affee8 100644 --- a/01_Data/src/index.ts +++ b/01_Data/src/index.ts @@ -4,4 +4,15 @@ // SPDX-License-Identifier: Apache 2.0 export * as sequelize from "./layers/sequelize"; -export * from "./interfaces"; \ No newline at end of file +export * from "./interfaces"; +export { + Boot, + Component, + DeviceModelRepository, + MeterValue, + Subscription, + Tariff, + Transaction, + Variable, + VariableAttribute +} from "./layers/sequelize"; // todo export better as these seem to be used in other modules \ No newline at end of file diff --git a/01_Data/src/layers/sequelize/model/DeviceModel/VariableStatus.ts b/01_Data/src/layers/sequelize/model/DeviceModel/VariableStatus.ts index da5591857..ff0cb21a7 100644 --- a/01_Data/src/layers/sequelize/model/DeviceModel/VariableStatus.ts +++ b/01_Data/src/layers/sequelize/model/DeviceModel/VariableStatus.ts @@ -2,10 +2,9 @@ // // SPDX-License-Identifier: Apache 2.0 -import { Namespace, CustomDataType } from "@citrineos/base"; -import { StatusInfoType } from "@citrineos/base/lib/ocpp/model/types/SetVariablesResponse"; -import { Table, Model, BelongsTo, Column, DataType, ForeignKey } from "sequelize-typescript"; -import { VariableAttribute } from "./VariableAttribute"; +import {CustomDataType, Namespace, StatusInfoType} from "@citrineos/base"; +import {BelongsTo, Column, DataType, ForeignKey, Model, Table} from "sequelize-typescript"; +import {VariableAttribute} from "./VariableAttribute"; @Table export class VariableStatus extends Model { diff --git a/01_Data/src/layers/sequelize/model/VariableMonitoring/VariableMonitoringStatus.ts b/01_Data/src/layers/sequelize/model/VariableMonitoring/VariableMonitoringStatus.ts index 6816af366..93a6f2273 100644 --- a/01_Data/src/layers/sequelize/model/VariableMonitoring/VariableMonitoringStatus.ts +++ b/01_Data/src/layers/sequelize/model/VariableMonitoring/VariableMonitoringStatus.ts @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache 2.0 import {CustomDataType, Namespace} from "@citrineos/base"; -import {StatusInfoType} from "@citrineos/base/lib/ocpp/model/types/SetVariableMonitoringResponse"; +import {StatusInfoType} from "@citrineos/base"; import {BelongsTo, Column, DataType, ForeignKey, Model, Table} from "sequelize-typescript"; import {VariableMonitoring} from "./VariableMonitoring"; diff --git a/01_Data/tsconfig.json b/01_Data/tsconfig.json index db3598d5e..f48be3c5e 100644 --- a/01_Data/tsconfig.json +++ b/01_Data/tsconfig.json @@ -1,20 +1,17 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "composite": true, + "rootDir": "./src" + }, + "references": [ + { + "path": "../00_Base" + } ] } \ No newline at end of file diff --git a/02_Util/package.json b/02_Util/package.json index 314f21f47..7cb3e02f7 100644 --- a/02_Util/package.json +++ b/02_Util/package.json @@ -2,18 +2,16 @@ "name": "@citrineos/util", "version": "1.0.0", "description": "The OCPP util module which supplies helpful utilities like cache and queue connectors, etc.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { "prepublish": "npx eslint ./src", - "prepare": "npm run build", - "build": "tsc", - "install-base": "cd ../00_Base && npm run build && npm pack && cd ../02_Util && npm install ../00_Base/citrineos-base-1.0.0.tgz", - "install-data": "cd ../01_Data && npm run build && npm pack && cd ../02_Util && npm install ../01_Data/citrineos-data-1.0.0.tgz", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "npm run clean && tsc -p tsconfig.json", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -35,8 +33,8 @@ "typescript": "^5.0.4" }, "dependencies": { - "@citrineos/base": "file:../00_Base/citrineos-base-1.0.0.tgz", - "@citrineos/data": "file:../01_Data/citrineos-data-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@citrineos/data": "1.0.0", "@directus/sdk": "^15.0.3", "@fastify/swagger": "^8.10.1", "@fastify/swagger-ui": "^1.9.3", @@ -51,5 +49,6 @@ "redis": "^4.6.6", "tslog": "^4.8.2", "uuid": "^9.0.0" - } + }, + "workspace": "../" } diff --git a/02_Util/tsconfig.json b/02_Util/tsconfig.json index 5cebe347b..fad4e4aaf 100644 --- a/02_Util/tsconfig.json +++ b/02_Util/tsconfig.json @@ -1,21 +1,20 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "composite": true, + "rootDir": "./src" + }, + "references": [ + { + "path": "../00_Base" + }, + { + "path": "../01_Data" + } ] } \ No newline at end of file diff --git a/03_Modules/Certificates/package.json b/03_Modules/Certificates/package.json index d2e94aa0b..10a332cc4 100644 --- a/03_Modules/Certificates/package.json +++ b/03_Modules/Certificates/package.json @@ -2,20 +2,16 @@ "name": "@citrineos/certificates", "version": "1.0.0", "description": "The certificates module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { "prepublish": "npx eslint", - "prepare": "npm run build", - "build": "tsc", - "refresh-base": "cd ../../00_Base && npm run build && npm pack && cd ../03_Modules/Certificates && npm install ../../00_Base/citrineos-base-1.0.0.tgz", - "refresh-data": "cd ../../01_Data && npm run build && npm pack && cd ../03_Modules/Certificates && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "refresh-util": "cd ../../02_Util && npm run build && npm pack && cd ../03_Modules/Certificates && npm install ../../02_Util/citrineos-util-1.0.0.tgz", - "install-all": "npm install ../../00_Base/citrineos-base-1.0.0.tgz && npm install ../../02_Util/citrineos-util-1.0.0.tgz && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "npm run clean && tsc -p tsconfig.json", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -29,10 +25,11 @@ "typescript": "^5.0.4" }, "dependencies": { - "@citrineos/base": "file:../../00_Base/citrineos-base-1.0.0.tgz", - "@citrineos/data": "file:../../01_Data/citrineos-data-1.0.0.tgz", - "@citrineos/util": "file:../../02_Util/citrineos-util-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@citrineos/data": "1.0.0", + "@citrineos/util": "1.0.0", "fastify": "^4.22.2", "node-forge": "^1.3.1" - } + }, + "workspace": "../../" } \ No newline at end of file diff --git a/03_Modules/Certificates/tsconfig.json b/03_Modules/Certificates/tsconfig.json index 5cebe347b..348e4d9e7 100644 --- a/03_Modules/Certificates/tsconfig.json +++ b/03_Modules/Certificates/tsconfig.json @@ -1,21 +1,23 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "rootDir": "./src", + "composite": true + }, + "references": [ + { + "path": "../../00_Base" + }, + { + "path": "../../01_Data" + }, + { + "path": "../../02_Util" + } ] } \ No newline at end of file diff --git a/03_Modules/Configuration/package.json b/03_Modules/Configuration/package.json index d02bd8ac4..04d70f93d 100644 --- a/03_Modules/Configuration/package.json +++ b/03_Modules/Configuration/package.json @@ -2,20 +2,16 @@ "name": "@citrineos/configuration", "version": "1.0.0", "description": "The configuration module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { "prepublish": "npx eslint", - "prepare": "npm run build", - "build": "tsc", - "refresh-base": "cd ../../00_Base && npm run build && npm pack && cd ../03_Modules/Configuration && npm install ../../00_Base/citrineos-base-1.0.0.tgz", - "refresh-data": "cd ../../01_Data && npm run build && npm pack && cd ../03_Modules/Configuration && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "refresh-util": "cd ../../02_Util && npm run build && npm pack && cd ../03_Modules/Configuration && npm install ../../02_Util/citrineos-util-1.0.0.tgz", - "install-all": "npm install ../../00_Base/citrineos-base-1.0.0.tgz && npm install ../../02_Util/citrineos-util-1.0.0.tgz && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "npm run clean && tsc -p tsconfig.json", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -35,9 +31,10 @@ "typescript": "5.0.4" }, "dependencies": { - "@citrineos/base": "file:../../00_Base/citrineos-base-1.0.0.tgz", - "@citrineos/data": "file:../../01_Data/citrineos-data-1.0.0.tgz", - "@citrineos/util": "file:../../02_Util/citrineos-util-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@citrineos/data": "1.0.0", + "@citrineos/util": "1.0.0", "uuid": "^9.0.1" - } + }, + "workspace": "../../" } \ No newline at end of file diff --git a/03_Modules/Configuration/src/module/api.ts b/03_Modules/Configuration/src/module/api.ts index 9a85338bb..94d354ecd 100644 --- a/03_Modules/Configuration/src/module/api.ts +++ b/03_Modules/Configuration/src/module/api.ts @@ -3,11 +3,7 @@ // // SPDX-License-Identifier: Apache 2.0 -import { Boot } from '@citrineos/data/lib/layers/sequelize'; -import { FastifyInstance, FastifyRequest } from 'fastify'; import { ILogObj, Logger } from 'tslog'; -import { IConfigurationModuleApi } from './interface'; -import { ConfigurationModule } from './module'; import { AbstractModuleApi, AsMessageEndpoint, @@ -15,11 +11,23 @@ import { SetNetworkProfileRequestSchema, SetNetworkProfileRequest, IMessageConfirmation, + ClearDisplayMessageRequestSchema, + ClearDisplayMessageRequest, + GetDisplayMessagesRequestSchema, + GetDisplayMessagesRequest, + SetDisplayMessageRequestSchema, + SetDisplayMessageRequest, + MessageInfoType, + PublishFirmwareRequestSchema, + PublishFirmwareRequest, + UnpublishFirmwareRequestSchema, + UnpublishFirmwareRequest, UpdateFirmwareRequestSchema, UpdateFirmwareRequest, ResetRequestSchema, - ChangeAvailabilityRequestSchema, ResetRequest, + ChangeAvailabilityRequestSchema, + ChangeAvailabilityRequest, TriggerMessageRequestSchema, TriggerMessageRequest, AsDataEndpoint, @@ -27,22 +35,15 @@ import { HttpMethod, BootConfigSchema, BootNotificationResponse, - BootConfig, - ChangeAvailabilityRequest, - PublishFirmwareRequestSchema, - ClearDisplayMessageRequest, - ClearDisplayMessageRequestSchema, - GetDisplayMessagesRequest, - GetDisplayMessagesRequestSchema, - PublishFirmwareRequest, - SetDisplayMessageRequest, - SetDisplayMessageRequestSchema, - UnpublishFirmwareRequest, - UnpublishFirmwareRequestSchema, - MessageInfoType -} from '@citrineos/base'; -import { ChargingStationKeyQuerySchema, ChargingStationKeyQuerystring } from '@citrineos/data'; + BootConfig +} from "@citrineos/base"; +import { FastifyInstance, FastifyRequest } from 'fastify'; +import { ChargingStationKeyQuerySchema, ChargingStationKeyQuerystring, Boot } from "@citrineos/data"; import { validateLanguageTag } from "@citrineos/util"; +import { IConfigurationModuleApi } from "./interface"; +import { ConfigurationModule } from "./module"; + + /** * Server API for the Configuration component. @@ -107,7 +108,7 @@ export class ConfigurationModuleApi extends AbstractModuleApi { - this._logger.debug("Heartbeat response sent: ", messageConfirmation) - }); + .then(messageConfirmation => { + this._logger.debug("Heartbeat response sent: ", messageConfirmation) + }); } @AsHandler(CallAction.NotifyDisplayMessages) @@ -538,9 +536,9 @@ export class ConfigurationModule extends AbstractModule { }; this.sendCallResultWithMessage(message, response) - .then(messageConfirmation => { - this._logger.debug("NotifyDisplayMessages response sent: ", messageConfirmation) - }); + .then(messageConfirmation => { + this._logger.debug("NotifyDisplayMessages response sent: ", messageConfirmation) + }); } @AsHandler(CallAction.FirmwareStatusNotification) @@ -556,9 +554,9 @@ export class ConfigurationModule extends AbstractModule { const response: FirmwareStatusNotificationResponse = {}; this.sendCallResultWithMessage(message, response) - .then(messageConfirmation => { - this._logger.debug("FirmwareStatusNotification response sent: ", messageConfirmation) - }); + .then(messageConfirmation => { + this._logger.debug("FirmwareStatusNotification response sent: ", messageConfirmation) + }); } @AsHandler(CallAction.DataTransfer) @@ -572,9 +570,9 @@ export class ConfigurationModule extends AbstractModule { const response: DataTransferResponse = { status: DataTransferStatusEnumType.Rejected, statusInfo: { reasonCode: ErrorCode.NotImplemented } }; this.sendCallResultWithMessage(message, response) - .then(messageConfirmation => { - this._logger.debug("DataTransfer response sent: ", messageConfirmation) - }); + .then(messageConfirmation => { + this._logger.debug("DataTransfer response sent: ", messageConfirmation) + }); } /** @@ -608,8 +606,8 @@ export class ConfigurationModule extends AbstractModule { @AsHandler(CallAction.SetDisplayMessage) protected async _handleSetDisplayMessage( - message: IMessage, - props?: HandlerProperties + message: IMessage, + props?: HandlerProperties ): Promise { this._logger.debug("SetDisplayMessage response received:", message, props); @@ -618,7 +616,7 @@ export class ConfigurationModule extends AbstractModule { // we trigger a get all display messages request to update stored message info in db if (status == DisplayMessageStatusEnumType.Accepted) { await this._messageInfoRepository.deactivateAllByStationId(message.context.stationId) - await this.sendCall(message.context.stationId, message.context.tenantId, CallAction.GetDisplayMessages, {requestId: Math.floor(Math.random() * 1000)} as GetDisplayMessagesRequest); + await this.sendCall(message.context.stationId, message.context.tenantId, CallAction.GetDisplayMessages, { requestId: Math.floor(Math.random() * 1000) } as GetDisplayMessagesRequest); } } @@ -664,8 +662,8 @@ export class ConfigurationModule extends AbstractModule { @AsHandler(CallAction.ClearDisplayMessage) protected async _handleClearDisplayMessage( - message: IMessage, - props?: HandlerProperties + message: IMessage, + props?: HandlerProperties ): Promise { this._logger.debug("ClearDisplayMessage response received:", message, props); @@ -674,7 +672,7 @@ export class ConfigurationModule extends AbstractModule { // we trigger a get all display messages request to update stored message info in db if (status == ClearMessageStatusEnumType.Accepted) { await this._messageInfoRepository.deactivateAllByStationId(message.context.stationId) - await this.sendCall(message.context.stationId, message.context.tenantId, CallAction.GetDisplayMessages, {requestId: Math.floor(Math.random() * 1000)} as GetDisplayMessagesRequest); + await this.sendCall(message.context.stationId, message.context.tenantId, CallAction.GetDisplayMessages, { requestId: Math.floor(Math.random() * 1000) } as GetDisplayMessagesRequest); } } } \ No newline at end of file diff --git a/03_Modules/Configuration/src/module/services.ts b/03_Modules/Configuration/src/module/services.ts index d0f974446..776af9a0b 100644 --- a/03_Modules/Configuration/src/module/services.ts +++ b/03_Modules/Configuration/src/module/services.ts @@ -3,8 +3,7 @@ // SPDX-License-Identifier: Apache 2.0 import { AttributeEnumType } from "@citrineos/base"; -import { IDeviceModelRepository } from "@citrineos/data"; -import { VariableAttribute } from "@citrineos/data/lib/layers/sequelize"; +import { IDeviceModelRepository, VariableAttribute } from "@citrineos/data"; export class DeviceModelService { diff --git a/03_Modules/Configuration/tsconfig.json b/03_Modules/Configuration/tsconfig.json index 5cebe347b..348e4d9e7 100644 --- a/03_Modules/Configuration/tsconfig.json +++ b/03_Modules/Configuration/tsconfig.json @@ -1,21 +1,23 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "rootDir": "./src", + "composite": true + }, + "references": [ + { + "path": "../../00_Base" + }, + { + "path": "../../01_Data" + }, + { + "path": "../../02_Util" + } ] } \ No newline at end of file diff --git a/03_Modules/EVDriver/package.json b/03_Modules/EVDriver/package.json index 617a8f6f3..b84467904 100644 --- a/03_Modules/EVDriver/package.json +++ b/03_Modules/EVDriver/package.json @@ -2,20 +2,16 @@ "name": "@citrineos/evdriver", "version": "1.0.0", "description": "The EVDriver module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { "prepublish": "npx eslint", - "prepare": "npm run build", - "build": "tsc", - "refresh-base": "cd ../../00_Base && npm run build && npm pack && cd ../03_Modules/EVDriver && npm install ../../00_Base/citrineos-base-1.0.0.tgz", - "refresh-data": "cd ../../01_Data && npm run build && npm pack && cd ../03_Modules/EVDriver && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "refresh-util": "cd ../../02_Util && npm run build && npm pack && cd ../03_Modules/EVDriver && npm install ../../02_Util/citrineos-util-1.0.0.tgz", - "install-all": "npm install ../../00_Base/citrineos-base-1.0.0.tgz && npm install ../../02_Util/citrineos-util-1.0.0.tgz && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "npm run clean && tsc -p tsconfig.json", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -28,9 +24,10 @@ "typescript": "^5.0.4" }, "dependencies": { - "@citrineos/base": "file:../../00_Base/citrineos-base-1.0.0.tgz", - "@citrineos/data": "file:../../01_Data/citrineos-data-1.0.0.tgz", - "@citrineos/util": "file:../../02_Util/citrineos-util-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@citrineos/data": "1.0.0", + "@citrineos/util": "1.0.0", "fastify": "^4.22.2" - } + }, + "workspace": "../../" } \ No newline at end of file diff --git a/03_Modules/EVDriver/src/module/module.ts b/03_Modules/EVDriver/src/module/module.ts index d3af2ae83..48da28a87 100644 --- a/03_Modules/EVDriver/src/module/module.ts +++ b/03_Modules/EVDriver/src/module/module.ts @@ -33,8 +33,7 @@ import { SystemConfig, UnlockConnectorResponse } from "@citrineos/base"; -import {IAuthorizationRepository, IDeviceModelRepository, ITariffRepository, sequelize} from "@citrineos/data"; -import {Tariff, VariableAttribute} from "@citrineos/data/lib/layers/sequelize"; +import {IAuthorizationRepository, IDeviceModelRepository, ITariffRepository, sequelize, Tariff, VariableAttribute} from "@citrineos/data"; import {RabbitMqReceiver, RabbitMqSender, Timer} from "@citrineos/util"; import deasyncPromise from "deasync-promise"; import {ILogObj, Logger} from 'tslog'; diff --git a/03_Modules/EVDriver/tsconfig.json b/03_Modules/EVDriver/tsconfig.json index 5cebe347b..348e4d9e7 100644 --- a/03_Modules/EVDriver/tsconfig.json +++ b/03_Modules/EVDriver/tsconfig.json @@ -1,21 +1,23 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "rootDir": "./src", + "composite": true + }, + "references": [ + { + "path": "../../00_Base" + }, + { + "path": "../../01_Data" + }, + { + "path": "../../02_Util" + } ] } \ No newline at end of file diff --git a/03_Modules/Monitoring/package.json b/03_Modules/Monitoring/package.json index 00f792c06..1056520b2 100644 --- a/03_Modules/Monitoring/package.json +++ b/03_Modules/Monitoring/package.json @@ -2,20 +2,16 @@ "name": "@citrineos/monitoring", "version": "1.0.0", "description": "The monitoring module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { "prepublish": "npx eslint", - "prepare": "npm run build", - "build": "tsc", - "refresh-base": "cd ../../00_Base && npm run build && npm pack && cd ../03_Modules/Monitoring && npm install ../../00_Base/citrineos-base-1.0.0.tgz", - "refresh-data": "cd ../../01_Data && npm run build && npm pack && cd ../03_Modules/Monitoring && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "refresh-util": "cd ../../02_Util && npm run build && npm pack && cd ../03_Modules/Monitoring && npm install ../../02_Util/citrineos-util-1.0.0.tgz", - "install-all": "npm install ../../00_Base/citrineos-base-1.0.0.tgz && npm install ../../02_Util/citrineos-util-1.0.0.tgz && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "npm run clean && tsc -p tsconfig.json", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -28,9 +24,10 @@ "typescript": "^5.0.4" }, "dependencies": { - "@citrineos/base": "file:../../00_Base/citrineos-base-1.0.0.tgz", - "@citrineos/data": "file:../../01_Data/citrineos-data-1.0.0.tgz", - "@citrineos/util": "file:../../02_Util/citrineos-util-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@citrineos/data": "1.0.0", + "@citrineos/util": "1.0.0", "fastify": "^4.22.2" - } + }, + "workspace": "../../" } \ No newline at end of file diff --git a/03_Modules/Monitoring/src/module/api.ts b/03_Modules/Monitoring/src/module/api.ts index f73aa8c8b..766cc9e5b 100644 --- a/03_Modules/Monitoring/src/module/api.ts +++ b/03_Modules/Monitoring/src/module/api.ts @@ -3,40 +3,48 @@ // // SPDX-License-Identifier: Apache 2.0 -import { ILogObj, Logger } from 'tslog'; -import { IMonitoringModuleApi } from './interface'; -import { MonitoringModule } from './module'; -import { CreateOrUpdateVariableAttributeQuerySchema, CreateOrUpdateVariableAttributeQuerystring, sequelize, VariableAttributeQuerySchema, VariableAttributeQuerystring } from '@citrineos/data'; +import {ILogObj, Logger} from 'tslog'; +import {IMonitoringModuleApi} from './interface'; +import {MonitoringModule} from './module'; +import { + CreateOrUpdateVariableAttributeQuerySchema, + CreateOrUpdateVariableAttributeQuerystring, + sequelize, + VariableAttributeQuerySchema, + VariableAttributeQuerystring +} from '@citrineos/data'; import { AbstractModuleApi, + AsDataEndpoint, AsMessageEndpoint, CallAction, - SetVariablesRequestSchema, - SetVariablesRequest, - IMessageConfirmation, - SetVariableDataType, - GetVariablesRequestSchema, - GetVariablesRequest, + ClearVariableMonitoringRequest, + ClearVariableMonitoringRequestSchema, + DataEnumType, GetVariableDataType, - AsDataEndpoint, - Namespace, + GetVariablesRequest, + GetVariablesRequestSchema, HttpMethod, - ReportDataTypeSchema, + IMessageConfirmation, + MonitorEnumType, + Namespace, ReportDataType, - SetVariableStatusEnumType, - ClearVariableMonitoringRequest, - ClearVariableMonitoringRequestSchema, + ReportDataTypeSchema, SetMonitoringBaseRequest, SetMonitoringBaseRequestSchema, + SetMonitoringDataType, SetMonitoringLevelRequest, SetMonitoringLevelRequestSchema, + SetVariableDataType, SetVariableMonitoringRequest, SetVariableMonitoringRequestSchema, - SetMonitoringDataType, MonitorEnumType, DataEnumType + SetVariablesRequest, + SetVariablesRequestSchema, + SetVariableStatusEnumType } from '@citrineos/base'; -import { FastifyInstance, FastifyRequest } from 'fastify'; -import { Variable, Component } from '@citrineos/data/lib/layers/sequelize'; -import {getBatches, getSizeOfRequest} from "@citrineos/util/lib/util/parser"; +import {FastifyInstance, FastifyRequest} from 'fastify'; +import {Component, Variable} from '@citrineos/data'; +import {getBatches, getSizeOfRequest} from "@citrineos/util"; /** * Server API for the Monitoring module. diff --git a/03_Modules/Monitoring/src/module/services.ts b/03_Modules/Monitoring/src/module/services.ts index f23bac371..f84ad7f81 100644 --- a/03_Modules/Monitoring/src/module/services.ts +++ b/03_Modules/Monitoring/src/module/services.ts @@ -3,9 +3,7 @@ // SPDX-License-Identifier: Apache 2.0 import { AttributeEnumType } from "@citrineos/base"; -import { IDeviceModelRepository } from "@citrineos/data"; -import { VariableAttribute } from "@citrineos/data/lib/layers/sequelize"; - +import { IDeviceModelRepository, VariableAttribute } from "@citrineos/data"; export class DeviceModelService { protected _deviceModelRepository: IDeviceModelRepository; diff --git a/03_Modules/Monitoring/tsconfig.json b/03_Modules/Monitoring/tsconfig.json index 5cebe347b..348e4d9e7 100644 --- a/03_Modules/Monitoring/tsconfig.json +++ b/03_Modules/Monitoring/tsconfig.json @@ -1,21 +1,23 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "rootDir": "./src", + "composite": true + }, + "references": [ + { + "path": "../../00_Base" + }, + { + "path": "../../01_Data" + }, + { + "path": "../../02_Util" + } ] } \ No newline at end of file diff --git a/03_Modules/OcppRouter/package.json b/03_Modules/OcppRouter/package.json index 9a929078f..fa8d612ba 100644 --- a/03_Modules/OcppRouter/package.json +++ b/03_Modules/OcppRouter/package.json @@ -2,20 +2,16 @@ "name": "@citrineos/ocpprouter", "version": "1.0.0", "description": "The ocpprouter module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { "prepublish": "npx eslint", - "prepare": "npm run build", - "build": "tsc", - "refresh-base": "cd ../../00_Base && npm run build && npm pack && cd ../03_Modules/OcppRouter && npm install ../../00_Base/citrineos-base-1.0.0.tgz", - "refresh-data": "cd ../../01_Data && npm run build && npm pack && cd ../03_Modules/OcppRouter && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "refresh-util": "cd ../../02_Util && npm run build && npm pack && cd ../03_Modules/OcppRouter && npm install ../../02_Util/citrineos-util-1.0.0.tgz", - "install-all": "npm install ../../00_Base/citrineos-base-1.0.0.tgz && npm install ../../02_Util/citrineos-util-1.0.0.tgz && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "test": "echo \"Error: no test specified\" && exit 1" + "compile": "npm run clean && tsc -p tsconfig.json", + "test": "echo \"Error: no test specified\" && exit 1", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -30,11 +26,12 @@ "typescript": "^5.0.4" }, "dependencies": { - "@citrineos/base": "file:../../00_Base/citrineos-base-1.0.0.tgz", - "@citrineos/data": "file:../../01_Data/citrineos-data-1.0.0.tgz", - "@citrineos/util": "file:../../02_Util/citrineos-util-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@citrineos/data": "1.0.0", + "@citrineos/util": "1.0.0", "fastify": "^4.22.2", "node-forge": "^1.3.1", "uuid": "^9.0.0" - } + }, + "workspace": "../../" } \ No newline at end of file diff --git a/03_Modules/OcppRouter/src/module/api.ts b/03_Modules/OcppRouter/src/module/api.ts index e88c8a522..0d6d04544 100644 --- a/03_Modules/OcppRouter/src/module/api.ts +++ b/03_Modules/OcppRouter/src/module/api.ts @@ -3,13 +3,12 @@ // // SPDX-License-Identifier: Apache 2.0 -import { AbstractModuleApi, AsDataEndpoint, CallAction, HttpMethod, MessageOrigin, Namespace } from '@citrineos/base'; +import { AbstractModuleApi, AsDataEndpoint, CallAction, HttpMethod, Namespace } from '@citrineos/base'; import { FastifyInstance, FastifyRequest } from 'fastify'; import { ILogObj, Logger } from 'tslog'; import { IAdminApi } from './interface'; import { MessageRouterImpl } from './router'; -import { ChargingStationKeyQuerystring, ModelKeyQuerystring } from '@citrineos/data'; -import { Subscription } from '@citrineos/data/lib/layers/sequelize'; +import { ChargingStationKeyQuerystring, ModelKeyQuerystring, Subscription } from '@citrineos/data'; /** * Admin API for the OcppRouter. diff --git a/03_Modules/OcppRouter/tsconfig.json b/03_Modules/OcppRouter/tsconfig.json index 5cebe347b..348e4d9e7 100644 --- a/03_Modules/OcppRouter/tsconfig.json +++ b/03_Modules/OcppRouter/tsconfig.json @@ -1,21 +1,23 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "rootDir": "./src", + "composite": true + }, + "references": [ + { + "path": "../../00_Base" + }, + { + "path": "../../01_Data" + }, + { + "path": "../../02_Util" + } ] } \ No newline at end of file diff --git a/03_Modules/Reporting/package.json b/03_Modules/Reporting/package.json index 7e9ad9a0a..83e488e13 100644 --- a/03_Modules/Reporting/package.json +++ b/03_Modules/Reporting/package.json @@ -2,20 +2,16 @@ "name": "@citrineos/reporting", "version": "1.0.0", "description": "The reporting module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { "prepublish": "npx eslint", - "prepare": "npm run build", - "build": "tsc", - "refresh-base": "cd ../../00_Base && npm run build && npm pack && cd ../03_Modules/Reporting && npm install ../../00_Base/citrineos-base-1.0.0.tgz", - "refresh-data": "cd ../../01_Data && npm run build && npm pack && cd ../03_Modules/Reporting && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "refresh-util": "cd ../../02_Util && npm run build && npm pack && cd ../03_Modules/Reporting && npm install ../../02_Util/citrineos-util-1.0.0.tgz", - "install-all": "npm install ../../00_Base/citrineos-base-1.0.0.tgz && npm install ../../02_Util/citrineos-util-1.0.0.tgz && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "npm run clean && tsc -p tsconfig.json", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -28,9 +24,10 @@ "typescript": "^5.0.4" }, "dependencies": { - "@citrineos/base": "file:../../00_Base/citrineos-base-1.0.0.tgz", - "@citrineos/data": "file:../../01_Data/citrineos-data-1.0.0.tgz", - "@citrineos/util": "file:../../02_Util/citrineos-util-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@citrineos/data": "1.0.0", + "@citrineos/util": "1.0.0", "fastify": "^4.22.2" - } + }, + "workspace": "../../" } \ No newline at end of file diff --git a/03_Modules/Reporting/src/module/api.ts b/03_Modules/Reporting/src/module/api.ts index dd210182f..338ce9104 100644 --- a/03_Modules/Reporting/src/module/api.ts +++ b/03_Modules/Reporting/src/module/api.ts @@ -25,7 +25,7 @@ import { import { FastifyInstance } from 'fastify'; import { IReportingModuleApi } from './interface'; import { ReportingModule } from './module'; -import {getBatches, getSizeOfRequest} from "@citrineos/util/lib/util/parser"; +import {getBatches, getSizeOfRequest} from "@citrineos/util"; /** * Server API for the Reporting module. diff --git a/03_Modules/Reporting/src/module/module.ts b/03_Modules/Reporting/src/module/module.ts index e6c78bd34..93e490304 100644 --- a/03_Modules/Reporting/src/module/module.ts +++ b/03_Modules/Reporting/src/module/module.ts @@ -5,32 +5,32 @@ import { AbstractModule, + AsHandler, CallAction, - SystemConfig, - ICache, - IMessageSender, - IMessageHandler, + CustomerInformationResponse, EventGroup, - AsHandler, - IMessage, - NotifyReportRequest, + GenericDeviceModelStatusEnumType, + GetBaseReportResponse, + GetLogResponse, + GetMonitoringReportResponse, + GetReportResponse, HandlerProperties, - SetVariableStatusEnumType, - NotifyReportResponse, - NotifyMonitoringReportRequest, - NotifyMonitoringReportResponse, + ICache, + IMessage, + IMessageHandler, + IMessageSender, LogStatusNotificationRequest, LogStatusNotificationResponse, NotifyCustomerInformationRequest, NotifyCustomerInformationResponse, - GetBaseReportResponse, + NotifyMonitoringReportRequest, + NotifyMonitoringReportResponse, + NotifyReportRequest, + NotifyReportResponse, SecurityEventNotificationRequest, SecurityEventNotificationResponse, - CustomerInformationResponse, - GetLogResponse, - GetMonitoringReportResponse, - GetReportResponse, - GenericDeviceModelStatusEnumType + SetVariableStatusEnumType, + SystemConfig } from "@citrineos/base"; import { IDeviceModelRepository, @@ -38,12 +38,12 @@ import { IVariableMonitoringRepository, sequelize } from "@citrineos/data"; -import { Component, Variable } from "@citrineos/data/lib/layers/sequelize"; -import { RabbitMqReceiver, RabbitMqSender, Timer } from "@citrineos/util"; +import {Component, Variable} from "@citrineos/data"; +import {RabbitMqReceiver, RabbitMqSender, Timer} from "@citrineos/util"; import deasyncPromise from "deasync-promise"; -import { ILogObj, Logger } from 'tslog'; +import {ILogObj, Logger} from 'tslog'; import {DeviceModelService} from "./services"; -import {StatusInfoType} from "@citrineos/base/lib/ocpp/model/types/GetMonitoringReportResponse"; +import {StatusInfoType} from "@citrineos/base"; /** * Component that handles provisioning related messages. diff --git a/03_Modules/Reporting/src/module/services.ts b/03_Modules/Reporting/src/module/services.ts index 11a614f8b..bf739d593 100644 --- a/03_Modules/Reporting/src/module/services.ts +++ b/03_Modules/Reporting/src/module/services.ts @@ -4,7 +4,7 @@ import {IDeviceModelRepository} from "@citrineos/data"; import {AttributeEnumType} from "@citrineos/base"; -import {VariableAttribute} from "@citrineos/data/lib/layers/sequelize"; +import {VariableAttribute} from "@citrineos/data"; export class DeviceModelService { protected _deviceModelRepository: IDeviceModelRepository; diff --git a/03_Modules/Reporting/tsconfig.json b/03_Modules/Reporting/tsconfig.json index 5cebe347b..348e4d9e7 100644 --- a/03_Modules/Reporting/tsconfig.json +++ b/03_Modules/Reporting/tsconfig.json @@ -1,21 +1,23 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "rootDir": "./src", + "composite": true + }, + "references": [ + { + "path": "../../00_Base" + }, + { + "path": "../../01_Data" + }, + { + "path": "../../02_Util" + } ] } \ No newline at end of file diff --git a/03_Modules/SmartCharging/package.json b/03_Modules/SmartCharging/package.json index 683a06fd8..972efb9ec 100644 --- a/03_Modules/SmartCharging/package.json +++ b/03_Modules/SmartCharging/package.json @@ -2,20 +2,16 @@ "name": "@citrineos/smartcharging", "version": "1.0.0", "description": "The smartcharging module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { "prepublish": "npx eslint", - "prepare": "npm run build", - "build": "tsc", - "refresh-base": "cd ../../00_Base && npm run build && npm pack && cd ../03_Modules/SmartCharging && npm install ../../00_Base/citrineos-base-1.0.0.tgz", - "refresh-data": "cd ../../01_Data && npm run build && npm pack && cd ../03_Modules/SmartCharging && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "refresh-util": "cd ../../02_Util && npm run build && npm pack && cd ../03_Modules/SmartCharging && npm install ../../02_Util/citrineos-util-1.0.0.tgz", - "install-all": "npm install ../../00_Base/citrineos-base-1.0.0.tgz && npm install ../../02_Util/citrineos-util-1.0.0.tgz && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "npm run clean && tsc -p tsconfig.json", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -28,9 +24,10 @@ "typescript": "^5.0.4" }, "dependencies": { - "@citrineos/base": "file:../../00_Base/citrineos-base-1.0.0.tgz", - "@citrineos/data": "file:../../01_Data/citrineos-data-1.0.0.tgz", - "@citrineos/util": "file:../../02_Util/citrineos-util-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@citrineos/data": "1.0.0", + "@citrineos/util": "1.0.0", "fastify": "^4.22.2" - } + }, + "workspace": "../../" } \ No newline at end of file diff --git a/03_Modules/SmartCharging/tsconfig.json b/03_Modules/SmartCharging/tsconfig.json index 5cebe347b..348e4d9e7 100644 --- a/03_Modules/SmartCharging/tsconfig.json +++ b/03_Modules/SmartCharging/tsconfig.json @@ -1,21 +1,23 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "rootDir": "./src", + "composite": true + }, + "references": [ + { + "path": "../../00_Base" + }, + { + "path": "../../01_Data" + }, + { + "path": "../../02_Util" + } ] } \ No newline at end of file diff --git a/03_Modules/Transactions/package.json b/03_Modules/Transactions/package.json index ae589eac5..098fc00dc 100644 --- a/03_Modules/Transactions/package.json +++ b/03_Modules/Transactions/package.json @@ -2,20 +2,16 @@ "name": "@citrineos/transactions", "version": "1.0.0", "description": "The transactions module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "lib" + "dist" ], "scripts": { "prepublish": "npx eslint", - "prepare": "npm run build", - "build": "tsc", - "refresh-base": "cd ../../00_Base && npm run build && npm pack && cd ../03_Modules/Transactions && npm install ../../00_Base/citrineos-base-1.0.0.tgz", - "refresh-data": "cd ../../01_Data && npm run build && npm pack && cd ../03_Modules/Transactions && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "refresh-util": "cd ../../02_Util && npm run build && npm pack && cd ../03_Modules/Transactions && npm install ../../02_Util/citrineos-util-1.0.0.tgz", - "install-all": "npm install ../../00_Base/citrineos-base-1.0.0.tgz && npm install ../../02_Util/citrineos-util-1.0.0.tgz && npm install ../../01_Data/citrineos-data-1.0.0.tgz", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "npm run clean && tsc -p tsconfig.json", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo" }, "keywords": [ "ocpp", @@ -28,9 +24,10 @@ "typescript": "^5.0.4" }, "dependencies": { - "@citrineos/base": "file:../../00_Base/citrineos-base-1.0.0.tgz", - "@citrineos/data": "file:../../01_Data/citrineos-data-1.0.0.tgz", - "@citrineos/util": "file:../../02_Util/citrineos-util-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@citrineos/data": "1.0.0", + "@citrineos/util": "1.0.0", "fastify": "^4.22.2" - } + }, + "workspace": "../../" } \ No newline at end of file diff --git a/03_Modules/Transactions/src/module/api.ts b/03_Modules/Transactions/src/module/api.ts index 0b8ae71dc..d92ee6070 100644 --- a/03_Modules/Transactions/src/module/api.ts +++ b/03_Modules/Transactions/src/module/api.ts @@ -3,18 +3,12 @@ // // SPDX-License-Identifier: Apache 2.0 -import { TransactionEventQuerySchema, TransactionEventQuerystring, TariffSchema } from "@citrineos/data"; +import { TransactionEventQuerySchema, TransactionEventQuerystring,Tariff, TariffSchema, CreateOrUpdateTariffQuerySchema, CreateOrUpdateTariffQueryString, TariffQuerySchema, TariffQueryString } from "@citrineos/data"; import { ILogObj, Logger } from 'tslog'; import { ITransactionsModuleApi } from './interface'; import { TransactionsModule } from './module'; import { AbstractModuleApi, AsDataEndpoint, Namespace, CostUpdatedRequest, CostUpdatedRequestSchema, HttpMethod, TransactionEventRequest, TransactionType, AsMessageEndpoint, CallAction, GetTransactionStatusRequestSchema, GetTransactionStatusRequest, IMessageConfirmation } from "@citrineos/base"; import { FastifyInstance, FastifyRequest } from "fastify"; -import { - CreateOrUpdateTariffQuerySchema, - CreateOrUpdateTariffQueryString, - TariffQuerySchema, TariffQueryString -} from "@citrineos/data/lib/interfaces/queries/Tariff"; -import {Tariff} from "@citrineos/data/lib/layers/sequelize"; /** * Server API for the transaction module. diff --git a/03_Modules/Transactions/src/module/module.ts b/03_Modules/Transactions/src/module/module.ts index c45cce754..ce61cfd01 100644 --- a/03_Modules/Transactions/src/module/module.ts +++ b/03_Modules/Transactions/src/module/module.ts @@ -31,12 +31,15 @@ import { IAuthorizationRepository, IDeviceModelRepository, ITariffRepository, ITransactionEventRepository, - sequelize + MeterValue, + sequelize, + Tariff, + Transaction, + VariableAttribute } from "@citrineos/data"; import { RabbitMqReceiver, RabbitMqSender, Timer} from "@citrineos/util"; import deasyncPromise from "deasync-promise"; import { ILogObj, Logger } from 'tslog'; -import { MeterValue, Tariff, Transaction, VariableAttribute } from "@citrineos/data/lib/layers/sequelize"; /** * Component that handles transaction related messages. diff --git a/03_Modules/Transactions/tsconfig.json b/03_Modules/Transactions/tsconfig.json index 5cebe347b..348e4d9e7 100644 --- a/03_Modules/Transactions/tsconfig.json +++ b/03_Modules/Transactions/tsconfig.json @@ -1,21 +1,23 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "rootDir": "./src", + "composite": true + }, + "references": [ + { + "path": "../../00_Base" + }, + { + "path": "../../01_Data" + }, + { + "path": "../../02_Util" + } ] } \ No newline at end of file diff --git a/README.md b/README.md index 5f762c640..db1038831 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,30 @@ # Welcome to CitrineOS -CitrineOS is an open-source project aimed at providing a modular server runtime for managing Electric Vehicle (EV) charging infrastructure. This README will guide you through the process of installing and running CitrineOS. +CitrineOS is an open-source project aimed at providing a modular server runtime for managing Electric Vehicle (EV) +charging infrastructure. This README will guide you through the process of installing and running CitrineOS. -This is the main part of CitrineOS containing the actual charging station management logic, OCPP message routing and all modules. +This is the main part of CitrineOS containing the actual charging station management logic, OCPP message routing and all +modules. -All other documentation and the issue tracking can be found in our main repository here: https://github.com/citrineos/citrineos. +All other documentation and the issue tracking can be found in our main repository +here: https://github.com/citrineos/citrineos. ## Overview -CitrineOS is developed in TypeScript and runs on `NodeJS` with [ws](https://github.com/websockets/ws) and [fastify](https://fastify.dev/). +CitrineOS is developed in TypeScript and runs on `NodeJS` with [ws](https://github.com/websockets/ws) +and [fastify](https://fastify.dev/). The system features: - Dynamic OCPP 2.0.1 message schema validation, prior to transmission using `AJV` - Generated OpenAPIv3 specification for easy developer access - Configurable logical modules with decorators - - `@AsHandler` to handle incoming OCPP 2.0.1 messages - - `@AsMessageEndpoint` to expose functions allowing to send messages to charging stations - - `@AsDataEndpoint` to expose CRUD access to entities defined in `10_Data` + - `@AsHandler` to handle incoming OCPP 2.0.1 messages + - `@AsMessageEndpoint` to expose functions allowing to send messages to charging stations + - `@AsDataEndpoint` to expose CRUD access to entities defined in `10_Data` - Utilities to connect and extend various message broker and cache mechanisms - - Currently supported brokers are `RabbitMQ` and Google Cloud `PubSub` - - Currently supported caches are `In Memory` and `Redis` + - Currently supported brokers are `RabbitMQ` and Google Cloud `PubSub` + - Currently supported caches are `In Memory` and `Redis` For more information on the project go to [citrineos.github.io](https://citrineos.github.io). @@ -33,6 +37,7 @@ Before you begin, make sure you have the following installed on your system: - Node.js (v18 or higher): [Download Node.js](https://nodejs.org/) - npm (Node Package Manager): [Download npm](https://www.npmjs.com/get-npm) - Docker (Optional). Version >= 20.10: [Download Docker](https://docs.docker.com/get-docker/) + ### Installation 1. Clone the CitrineOS repository to your local machine: @@ -41,45 +46,74 @@ Before you begin, make sure you have the following installed on your system: git clone https://github.com/citrineos/citrineos-core ``` -1. Navigate to the CitrineOS Server directory: +1. Install project dependencies from root dir: - ```shell - cd citrineos-core/Server - ``` + ```shell + npm run install-all + ``` -1. Install project dependencies: +1. Build project from root dir: ```shell - ./unix-init-install-all.sh + npm run build ``` -1. Start the server and its supporting infrastructure with: +1. The docker container should be initialized from `cd /Server` by running `docker-compose -f ./docker-compose.yml up -d` or + by using the IntelliJ `Server` Run Configuration which was created for this purpose. - ```shell - docker-compose up -d - ``` +1. Running `docker-compose.yml` will ensure that the container is configured to expose the `:9229` debugging + port for the underlying NodeJS process. A variety of tools can be utilized to establish a debugger connection + with the exposed localhost 9229 port which is forwarded to the NodeJS service running within docker. The IntelliJ + `Attach Debugger` Run Configuration was made to attach to a debugging session. ### Starting the Server without Docker CitrineOS requires configuration to allow your OCPP 2.0.1 compliant charging stations to connect. -We recommend running and developing the project with the `docker-compose` set-up. +We recommend running and developing the project with the `docker-compose` set-up via the existing Run Configurations. +Additional Run Configurations should be made for other IDEs (ex VSCode). -To change necessary configuration for execution outside of `docker-compose`, please adjust the configuration file at `50_Server/src/config/envs/local.ts`. Make sure any changes to the local configuration do not make it into your PR. +To change necessary configuration for execution outside of `docker-compose`, please adjust the configuration file +at `50_Server/src/config/envs/local.ts`. Make sure any changes to the local configuration do not make it into your PR. ### Starting the Server To start the CitrineOS server, run the following command: ```shell -npm run start-unix:local +cd Server +npm run start:local ``` -This will launch the CitrineOS server with the specified configuration. +This will launch the CitrineOS server with the specified configuration. The debugger will be available +on port 9229. + +### Attaching Debugger + +Whether you run the application with Docker or locally with npm, you should be able to attach a debugger. +With debugger attached you should be able to set breakpoints in the TS code right from your IDE and debug +with ease. + +### Attaching Debugger before execution using `--inspect-brk` + +You can modify `nodemon.json` exec command from: + +```shell +node --inspect=0.0.0.0:9229 --nolazy -r ts-node/register +``` + +to + +```shell +node --inspect-brk=0.0.0.0:9229 --nolazy -r ts-node/register +``` + +which will wait for the debugger to attach before proceeding with execution. ### Usage -You can now connect your OCPP 2.0.1 compliant charging stations to the CitrineOS server. Make sure to configure the charging stations to point to the server's IP address and port as specified in the config.json file. +You can now connect your OCPP 2.0.1 compliant charging stations to the CitrineOS server. Make sure to configure the +charging stations to point to the server's IP address and port as specified in the config.json file. ## Information on Docker setup @@ -92,19 +126,19 @@ a common integrated development environment. Once Docker is running, the following services should be available: -- **CitrineOS** (service name: citrineos) with ports - - `8080`: webserver http - [Swagger](http://localhost:8080/docs) - - `8081`: websocket server tcp connection without auth - - `8082`: websocket server tcp connection with basic http auth -- **RabbitMQ Broker** (service name: amqp-broker) with ports - - `5672`: amqp tcp connection - - `15672`: RabbitMQ [management interface](http://localhost:15672) -- **PostgreSQL** (service name: ocpp-db), PostgreSQL database for persistence - - `5432`: sql tcp connection -- **Directus** (service name: directus) on port 8055 with endpoints - - `:8055/admin`: web interface (login = admin@citrineos.com:CitrineOS!) - -These three services are defined in `Server/docker-compose.yml` and they +- **CitrineOS** (service name: citrineos) with ports + - `8080`: webserver http - [Swagger](http://localhost:8080/docs) + - `8081`: websocket server tcp connection without auth + - `8082`: websocket server tcp connection with basic http auth +- **RabbitMQ Broker** (service name: amqp-broker) with ports + - `5672`: amqp tcp connection + - `15672`: RabbitMQ [management interface](http://localhost:15672) +- **PostgreSQL** (service name: ocpp-db), PostgreSQL database for persistence + - `5432`: sql tcp connection +- **Directus** (service name: directus) on port 8055 with endpoints + - `:8055/admin`: web interface (login = admin@citrineos.com:CitrineOS!) + +These three services are defined in `docker-compose.yml` and they live inside the docker network `docker_default` with their respective ports. By default these ports are directly accessible by using `localhost:8080` for example. @@ -114,16 +148,20 @@ localhost, you need to access `localhost:15672`. ## Generating OCPP Interfaces -All CitrineOS interfaces for OCPP 2.0.1-defined schemas were procedurally generated using the script in 00_Base/json-schema-processor.js. +All CitrineOS interfaces for OCPP 2.0.1-defined schemas were procedurally generated using the script in +00_Base/json-schema-processor.js. It can be rerun: + ```shell npm run generate-interfaces -- ../../Path/To/OCPP-2.0.1_part3_JSON_schemas ``` + This will replace all the files in `00_Base/src/ocpp/model/`, ## Contributing -We welcome contributions from the community. If you would like to contribute to CitrineOS, please follow our [contribution guidelines](https://github.com/citrineos/citrineos/blob/main/CONTRIBUTING.md). +We welcome contributions from the community. If you would like to contribute to CitrineOS, please follow +our [contribution guidelines](https://github.com/citrineos/citrineos/blob/main/CONTRIBUTING.md). ## Licensing @@ -131,7 +169,8 @@ CitrineOS and its subprojects are licensed under the Apache License, Version 2.0 ## Support and Contact -If you have any questions or need assistance, feel free to reach out to us on our community forum or create an issue on the GitHub repository. +If you have any questions or need assistance, feel free to reach out to us on our community forum or create an issue on +the GitHub repository. ## Roadmap diff --git a/Server/.dockerignore b/Server/.dockerignore new file mode 100644 index 000000000..9905ce70e --- /dev/null +++ b/Server/.dockerignore @@ -0,0 +1,19 @@ +../node_modules +dist +*.log +*.lock +.dockerignore +Server/deploy.Dockerfile +Server/docker-compose.yml + +Server/dist +00_Base/dist +01_Data/dist +02_Util/dist +03_Modules/Certificates/dist +03_Modules/Configuration/dist +03_Modules/EVDriver/dist +03_Modules/Monitoring/dist +03_Modules/Reporting/dist +03_Modules/SmartCharging/dist +03_Modules/Transactions/dist \ No newline at end of file diff --git a/Server/deploy.Dockerfile b/Server/deploy.Dockerfile new file mode 100644 index 000000000..b26c3c25c --- /dev/null +++ b/Server/deploy.Dockerfile @@ -0,0 +1,15 @@ +FROM node:18 + +WORKDIR /usr/local/apps/citrineos + +COPY ../ . + +RUN npm i && npm run build + +# TODO remove src files + +EXPOSE ${PORT} + +WORKDIR /usr/local/apps/citrineos/Server + +CMD ["npm", "run", "start"] diff --git a/Server/docker-compose.swarm.yml b/Server/docker-compose.swarm.yml new file mode 100644 index 000000000..66ee50c52 --- /dev/null +++ b/Server/docker-compose.swarm.yml @@ -0,0 +1,229 @@ +version: '3' +services: + amqp-broker: + image: rabbitmq:3-management + ports: + - 15672:15672 + - 5672:5672 + environment: + RABBITMQ_DEFAULT_USER: 'guest' + RABBITMQ_DEFAULT_PASS: 'guest' + volumes: + - ./data/rabbitmq:/var/lib/rabbitmq + healthcheck: + test: rabbitmq-diagnostics -q ping + interval: 10s + timeout: 10s + retries: 3 + ocpp-db: + image: citrineos/postgres:preseeded + ports: + - 5432:5432 + volumes: + - ./data/postgresql/pgdata:/var/lib/postgresql/data + environment: + POSTGRES_DB: citrine + POSTGRES_USER: citrine + POSTGRES_PASSWORD: "citrine" + redis: + build: + context: .. + dockerfile: .redis.Dockerfile + ports: + - "6379:6379" + healthcheck: + test: [ "CMD", "redis-cli", "ping" ] + interval: 10s + timeout: 5s + retries: 3 + directus: + image: directus/directus:latest + ports: + - 8055:8055 + volumes: + - ./data/directus/uploads:/directus/uploads + - ./data/directus/extensions:/directus/extensions + environment: + KEY: '1234567890' + SECRET: '0987654321' + ADMIN_EMAIL: 'admin@citrineos.com' + ADMIN_PASSWORD: 'CitrineOS!' + DB_CLIENT: 'pg' + DB_HOST: ocpp-db + DB_PORT: 5432 + DB_DATABASE: 'citrine' + DB_USER: 'citrine' + DB_PASSWORD: 'citrine' + WEBSOCKETS_ENABLED: 'true' + citrine: + build: + context: .. + dockerfile: ./Server/deploy.Dockerfile + depends_on: + ocpp-db: + condition: service_started + amqp-broker: + condition: service_healthy + redis: + condition: service_healthy + ports: + - 8080:8080 + - 8081:8081 + - 8082:8082 + expose: + - 8080-8082 + environment: + CITRINEOS_UTIL_DIRECTUS_USERNAME: 'admin@citrineos.com' + CITRINEOS_UTIL_DIRECTUS_PASSWORD: 'CitrineOS!' + APP_NAME: 'general' + certificates: + build: + context: .. + dockerfile: ./Server/deploy.Dockerfile + depends_on: + ocpp-db: + condition: service_started + amqp-broker: + condition: service_healthy + redis: + condition: service_healthy + ports: + - 8083:8083 + expose: + - 8083 + environment: + CITRINEOS_UTIL_DIRECTUS_USERNAME: 'admin@citrineos.com' + CITRINEOS_UTIL_DIRECTUS_PASSWORD: 'CitrineOS!' + APP_NAME: 'certificates' + configuration: + build: + context: ../.. + dockerfile: .deploy.Dockerfile + depends_on: + ocpp-db: + condition: service_started + amqp-broker: + condition: service_healthy + redis: + condition: service_healthy + ports: + - 8084:8084 + expose: + - 8084 + volumes: + - ./:/usr/configuration + - /usr/configuration/node_modules + environment: + CITRINEOS_UTIL_DIRECTUS_USERNAME: 'admin@citrineos.com' + CITRINEOS_UTIL_DIRECTUS_PASSWORD: 'CitrineOS!' + APP_NAME: 'configuration' + evdriver: + build: + context: ../.. + dockerfile: .deploy.Dockerfile + depends_on: + ocpp-db: + condition: service_started + amqp-broker: + condition: service_healthy + redis: + condition: service_healthy + ports: + - 8085:8085 + expose: + - 8085 + volumes: + - ./:/usr/evdriver + - /usr/evdriver/node_modules + environment: + CITRINEOS_UTIL_DIRECTUS_USERNAME: 'admin@citrineos.com' + CITRINEOS_UTIL_DIRECTUS_PASSWORD: 'CitrineOS!' + APP_NAME: 'evdriver' + monitoring: + build: + context: ../.. + dockerfile: .deploy.Dockerfile + depends_on: + ocpp-db: + condition: service_started + amqp-broker: + condition: service_healthy + redis: + condition: service_healthy + ports: + - 8086:8086 + expose: + - 8086 + volumes: + - ./:/usr/monitoring + - /usr/monitoring/node_modules + environment: + CITRINEOS_UTIL_DIRECTUS_USERNAME: 'admin@citrineos.com' + CITRINEOS_UTIL_DIRECTUS_PASSWORD: 'CitrineOS!' + APP_NAME: 'monitoring' + reporting: + build: + context: ../.. + dockerfile: .deploy.Dockerfile + depends_on: + ocpp-db: + condition: service_started + amqp-broker: + condition: service_healthy + redis: + condition: service_healthy + ports: + - 8087:8087 + expose: + - 8087 + volumes: + - ./:/usr/reporting + - /usr/reporting/node_modules + environment: + CITRINEOS_UTIL_DIRECTUS_USERNAME: 'admin@citrineos.com' + CITRINEOS_UTIL_DIRECTUS_PASSWORD: 'CitrineOS!' + APP_NAME: 'reporting' + smartcharging: + build: + context: ../.. + dockerfile: .deploy.Dockerfile + depends_on: + ocpp-db: + condition: service_started + amqp-broker: + condition: service_healthy + redis: + condition: service_healthy + ports: + - 8088:8088 + expose: + - 8088 + volumes: + - ./:/usr/smartcharging + - /usr/smartcharging/node_modules + environment: + CITRINEOS_UTIL_DIRECTUS_USERNAME: 'admin@citrineos.com' + CITRINEOS_UTIL_DIRECTUS_PASSWORD: 'CitrineOS!' + APP_NAME: 'smartcharging' + transactions: + build: + context: ../.. + dockerfile: .deploy.Dockerfile + depends_on: + ocpp-db: + condition: service_started + amqp-broker: + condition: service_healthy + redis: + condition: service_healthy + ports: + - 8089:8089 + expose: + - 8089 + volumes: + - ./:/usr/transactions + - /usr/transactions/node_modules + environment: + CITRINEOS_UTIL_DIRECTUS_USERNAME: 'admin@citrineos.com' + CITRINEOS_UTIL_DIRECTUS_PASSWORD: 'CitrineOS!' + APP_NAME: 'transactions' diff --git a/Server/docker-compose.yml b/Server/docker-compose.yml index 917c6b336..e57a50473 100644 --- a/Server/docker-compose.yml +++ b/Server/docker-compose.yml @@ -26,24 +26,57 @@ services: POSTGRES_USER: citrine POSTGRES_PASSWORD: "citrine" healthcheck: - test: ["CMD-SHELL", "pg_isready", "-d", "db_prod"] + test: [ "CMD-SHELL", "pg_isready", "-d", "db_prod" ] interval: 30s timeout: 60s retries: 5 - start_period: 80s + start_period: 80s redis: image: redis:latest ports: - "6379:6379" healthcheck: - test: ["CMD", "redis-cli", "ping"] + test: [ "CMD", "redis-cli", "ping" ] interval: 10s timeout: 5s retries: 3 citrine: build: - context: ../ - dockerfile: ./Server/docker/Dockerfile + context: .. + dockerfile: ./Server/local.Dockerfile + volumes: + - ../:/usr/local/apps/citrineos + - /usr/local/apps/citrineos/node_modules + - /usr/local/apps/citrineos/Server/node_modules + - /usr/local/apps/citrineos/00_Base/node_modules + - /usr/local/apps/citrineos/01_Data/node_modules + - /usr/local/apps/citrineos/02_Util/node_modules + - /usr/local/apps/citrineos/03_Modules/Certificates/node_modules + - /usr/local/apps/citrineos/03_Modules/Configuration/node_modules + - /usr/local/apps/citrineos/03_Modules/EVDriver/node_modules + - /usr/local/apps/citrineos/03_Modules/Monitoring/node_modules + - /usr/local/apps/citrineos/03_Modules/OcppRouter/node_modules + - /usr/local/apps/citrineos/03_Modules/Reporting/node_modules + - /usr/local/apps/citrineos/03_Modules/SmartCharging/node_modules + - /usr/local/apps/citrineos/03_Modules/Transactions/node_modules + - /usr/local/apps/citrineos/dist/ + - /usr/local/apps/citrineos/Server/dist/ + - /usr/local/apps/citrineos/00_Base/dist/ + - /usr/local/apps/citrineos/01_Data/dist/ + - /usr/local/apps/citrineos/02_Util/dist/ + - /usr/local/apps/citrineos/03_Modules/Certificates/dist/ + - /usr/local/apps/citrineos/03_Modules/Configuration/dist/ + - /usr/local/apps/citrineos/03_Modules/EVDriver/dist/ + - /usr/local/apps/citrineos/03_Modules/Monitoring/dist/ + - /usr/local/apps/citrineos/03_Modules/OcppRouter/dist/ + - /usr/local/apps/citrineos/03_Modules/Reporting/dist/ + - /usr/local/apps/citrineos/03_Modules/SmartCharging/dist/ + - /usr/local/apps/citrineos/03_Modules/Transactions/dist/ + environment: + APP_NAME: "all" + APP_ENV: "docker" + CITRINEOS_UTIL_DIRECTUS_USERNAME: 'admin@citrineos.com' + CITRINEOS_UTIL_DIRECTUS_PASSWORD: 'CitrineOS!' depends_on: ocpp-db: condition: service_started @@ -55,9 +88,8 @@ services: - 8080:8080 - 8081:8081 - 8082:8082 - environment: - CITRINEOS_UTIL_DIRECTUS_USERNAME: 'admin@citrineos.com' - CITRINEOS_UTIL_DIRECTUS_PASSWORD: 'CitrineOS!' + - 9229:9229 + directus: image: directus/directus:latest ports: @@ -69,6 +101,7 @@ services: ocpp-db: condition: service_healthy environment: + APP_NAME: 'all' KEY: '1234567890' SECRET: '0987654321' ADMIN_EMAIL: 'admin@citrineos.com' @@ -79,4 +112,4 @@ services: DB_DATABASE: 'citrine' DB_USER: 'citrine' DB_PASSWORD: 'citrine' - WEBSOCKETS_ENABLED: 'true' + WEBSOCKETS_ENABLED: 'true' \ No newline at end of file diff --git a/Server/docker/.dockerignore b/Server/docker/.dockerignore deleted file mode 100644 index 198a2e52a..000000000 --- a/Server/docker/.dockerignore +++ /dev/null @@ -1,10 +0,0 @@ -node_modules -lib -data -.eslintrc.json -.gitignore -*.tgz -*.sh -*.js -*.md -*.log \ No newline at end of file diff --git a/Server/docker/Dockerfile b/Server/docker/Dockerfile deleted file mode 100644 index 23968440e..000000000 --- a/Server/docker/Dockerfile +++ /dev/null @@ -1,172 +0,0 @@ -FROM node:18 as base - -# To work from package-lock.json for consistency, replace 'package' with 'package*' and 'install' with 'ci' -# This will not work for package-lock files generated on Windows machines. - -# Build citrineos-base module -FROM base as citrineos-base-builder -COPY /00_Base/package.json /usr/00_Base/ -RUN npm install --ignore-scripts=true --prefix /usr/00_Base - -COPY /00_Base/tsconfig.json /usr/00_Base/ -COPY /00_Base/src /usr/00_Base/src -RUN npm run build --prefix /usr/00_Base -RUN cd /usr/00_Base && npm pack - -# Build citrineos-data module -FROM base as citrineos-data-builder -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY /01_Data/package.json /usr/01_Data/ -RUN npm install --ignore-scripts=true --prefix /usr/01_Data - -COPY /01_Data/tsconfig.json /usr/01_Data/ -COPY /01_Data/src /usr/01_Data/src -RUN npm run build --prefix /usr/01_Data -RUN cd /usr/01_Data && npm pack - -# Build citrineos-util module -FROM base as citrineos-util-builder -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY --from=citrineos-data-builder /usr/01_Data/*.tgz /usr/01_Data/ -COPY /02_Util/package.json /usr/02_Util/ -RUN npm install --ignore-scripts=true --prefix /usr/02_Util - -COPY /02_Util/tsconfig.json /usr/02_Util/ -COPY /02_Util/src /usr/02_Util/src -RUN npm run build --prefix /usr/02_Util -RUN cd /usr/02_Util && npm pack - -# Build citrineos-ocpprouter module -FROM base as citrineos-ocpprouter-builder -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY --from=citrineos-data-builder /usr/01_Data/*.tgz /usr/01_Data/ -COPY --from=citrineos-util-builder /usr/02_Util/*.tgz /usr/02_Util/ -COPY /03_Modules/OcppRouter/package.json /usr/03_Modules/OcppRouter/ -RUN npm install --ignore-scripts=true --prefix /usr/03_Modules/OcppRouter - -COPY /03_Modules/OcppRouter/tsconfig.json /usr/03_Modules/OcppRouter/ -COPY /03_Modules/OcppRouter/src /usr/03_Modules/OcppRouter/src -RUN npm run build --prefix /usr/03_Modules/OcppRouter -RUN cd /usr/03_Modules/OcppRouter && npm pack - -# Build citrineos-certificates module -FROM base as citrineos-certificates-builder -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY --from=citrineos-data-builder /usr/01_Data/*.tgz /usr/01_Data/ -COPY --from=citrineos-util-builder /usr/02_Util/*.tgz /usr/02_Util/ -COPY /03_Modules/Certificates/package.json /usr/03_Modules/Certificates/ -RUN npm install --ignore-scripts=true --prefix /usr/03_Modules/Certificates - -COPY /03_Modules/Certificates/tsconfig.json /usr/03_Modules/Certificates/ -COPY /03_Modules/Certificates/src /usr/03_Modules/Certificates/src -RUN npm run build --prefix /usr/03_Modules/Certificates -RUN cd /usr/03_Modules/Certificates && npm pack - -# Build citrineos-configuration module -FROM base as citrineos-configuration-builder -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY --from=citrineos-data-builder /usr/01_Data/*.tgz /usr/01_Data/ -COPY --from=citrineos-util-builder /usr/02_Util/*.tgz /usr/02_Util/ -COPY /03_Modules/Configuration/package.json /usr/03_Modules/Configuration/ -RUN npm install --ignore-scripts=true --prefix /usr/03_Modules/Configuration - -COPY /03_Modules/Configuration/tsconfig.json /usr/03_Modules/Configuration/ -COPY /03_Modules/Configuration/src /usr/03_Modules/Configuration/src -RUN npm run build --prefix /usr/03_Modules/Configuration -RUN cd /usr/03_Modules/Configuration && npm pack - -# Build citrineos-evdriver module -FROM base as citrineos-evdriver-builder -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY --from=citrineos-data-builder /usr/01_Data/*.tgz /usr/01_Data/ -COPY --from=citrineos-util-builder /usr/02_Util/*.tgz /usr/02_Util/ -COPY /03_Modules/EVDriver/package.json /usr/03_Modules/EVDriver/ -RUN npm install --ignore-scripts=true --prefix /usr/03_Modules/EVDriver - -COPY /03_Modules/EVDriver/tsconfig.json /usr/03_Modules/EVDriver/ -COPY /03_Modules/EVDriver/src /usr/03_Modules/EVDriver/src -RUN npm run build --prefix /usr/03_Modules/EVDriver -RUN cd /usr/03_Modules/EVDriver && npm pack - -# Build citrineos-monitoring module -FROM base as citrineos-monitoring-builder -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY --from=citrineos-data-builder /usr/01_Data/*.tgz /usr/01_Data/ -COPY --from=citrineos-util-builder /usr/02_Util/*.tgz /usr/02_Util/ -COPY /03_Modules/Monitoring/package.json /usr/03_Modules/Monitoring/ -RUN npm install --ignore-scripts=true --prefix /usr/03_Modules/Monitoring - -COPY /03_Modules/Monitoring/tsconfig.json /usr/03_Modules/Monitoring/ -COPY /03_Modules/Monitoring/src /usr/03_Modules/Monitoring/src -RUN npm run build --prefix /usr/03_Modules/Monitoring -RUN cd /usr/03_Modules/Monitoring && npm pack - -# Build citrineos-reporting module -FROM base as citrineos-reporting-builder -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY --from=citrineos-data-builder /usr/01_Data/*.tgz /usr/01_Data/ -COPY --from=citrineos-util-builder /usr/02_Util/*.tgz /usr/02_Util/ -COPY /03_Modules/Reporting/package.json /usr/03_Modules/Reporting/ -RUN npm install --ignore-scripts=true --prefix /usr/03_Modules/Reporting - -COPY /03_Modules/Reporting/tsconfig.json /usr/03_Modules/Reporting/ -COPY /03_Modules/Reporting/src /usr/03_Modules/Reporting/src -RUN npm run build --prefix /usr/03_Modules/Reporting -RUN cd /usr/03_Modules/Reporting && npm pack - -# Build citrineos-smartcharging module -FROM base as citrineos-smartcharging-builder -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY --from=citrineos-data-builder /usr/01_Data/*.tgz /usr/01_Data/ -COPY --from=citrineos-util-builder /usr/02_Util/*.tgz /usr/02_Util/ -COPY /03_Modules/SmartCharging/package.json /usr/03_Modules/SmartCharging/ -RUN npm install --ignore-scripts=true --prefix /usr/03_Modules/SmartCharging - -COPY /03_Modules/SmartCharging/tsconfig.json /usr/03_Modules/SmartCharging/ -COPY /03_Modules/SmartCharging/src /usr/03_Modules/SmartCharging/src -RUN npm run build --prefix /usr/03_Modules/SmartCharging -RUN cd /usr/03_Modules/SmartCharging && npm pack - -# Build citrineos-transactions module -FROM base as citrineos-transactions-builder -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY --from=citrineos-data-builder /usr/01_Data/*.tgz /usr/01_Data/ -COPY --from=citrineos-util-builder /usr/02_Util/*.tgz /usr/02_Util/ -COPY /03_Modules/Transactions/package.json /usr/03_Modules/Transactions/ -RUN npm install --ignore-scripts=true --prefix /usr/03_Modules/Transactions - -COPY /03_Modules/Transactions/tsconfig.json /usr/03_Modules/Transactions/ -COPY /03_Modules/Transactions/src /usr/03_Modules/Transactions/src -RUN npm run build --prefix /usr/03_Modules/Transactions -RUN cd /usr/03_Modules/Transactions && npm pack - -# Final stage to assemble the server -FROM base as final-stage -WORKDIR /usr/server - -# Copy .tgz files from each builder stage -COPY --from=citrineos-base-builder /usr/00_Base/*.tgz /usr/00_Base/ -COPY --from=citrineos-data-builder /usr/01_Data/*.tgz /usr/01_Data/ -COPY --from=citrineos-util-builder /usr/02_Util/*.tgz /usr/02_Util/ -COPY --from=citrineos-ocpprouter-builder /usr/03_Modules/OcppRouter/*.tgz /usr/03_Modules/OcppRouter/ -COPY --from=citrineos-certificates-builder /usr/03_Modules/Certificates/*.tgz /usr/03_Modules/Certificates/ -COPY --from=citrineos-configuration-builder /usr/03_Modules/Configuration/*.tgz /usr/03_Modules/Configuration/ -COPY --from=citrineos-evdriver-builder /usr/03_Modules/EVDriver/*.tgz /usr/03_Modules/EVDriver/ -COPY --from=citrineos-monitoring-builder /usr/03_Modules/Monitoring/*.tgz /usr/03_Modules/Monitoring/ -COPY --from=citrineos-reporting-builder /usr/03_Modules/Reporting/*.tgz /usr/03_Modules/Reporting/ -COPY --from=citrineos-smartcharging-builder /usr/03_Modules/SmartCharging/*.tgz /usr/03_Modules/SmartCharging/ -COPY --from=citrineos-transactions-builder /usr/03_Modules/Transactions/*.tgz /usr/03_Modules/Transactions/ - -COPY /Server/package.json ./ -RUN npm install --ignore-scripts=true -RUN npm rebuild bcrypt --build-from-source -RUN npm rebuild deasync --build-from-source - -COPY /Server/nodemon.json ./ -COPY /Server/tsconfig.json ./ -COPY /Server/src ./src -RUN npm run build - -ARG BUILD_ARG_APP_ENV="docker" -ENV BUILD_APP_ENV=$BUILD_ARG_APP_ENV -CMD npm run start-unix:"$BUILD_APP_ENV" \ No newline at end of file diff --git a/Server/init.sh b/Server/init.sh deleted file mode 100644 index 79ec6b9ec..000000000 --- a/Server/init.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -npm run install-all - -docker-compose up -d \ No newline at end of file diff --git a/Server/local.Dockerfile b/Server/local.Dockerfile new file mode 100644 index 000000000..4b64f7006 --- /dev/null +++ b/Server/local.Dockerfile @@ -0,0 +1,15 @@ +FROM node:18 + +WORKDIR /usr/local/apps/citrineos + +COPY .. . + +RUN npm run clean +RUN npm run install-all +RUN npm run build + +EXPOSE ${PORT} + +WORKDIR /usr/local/apps/citrineos/Server + +CMD ["npm", "run", "start:local-docker"] diff --git a/Server/nodemon.json b/Server/nodemon.json index 56f8c16d7..278648983 100644 --- a/Server/nodemon.json +++ b/Server/nodemon.json @@ -1,11 +1,15 @@ { - "watch": [ - "src" - ], - "ext": ".ts,.js", - "ignore": [], - "exec": "npx ts-node ./src/index.ts", - "events": { - "crash": "nodemon --delay 500ms -L" - } + "watch": [ + "src", + "../00_Base", + "../01_Data", + "../02_Util", + "../03_Modules" + ], + "ext": ".ts,.js", + "ignore": [], + "exec": "node --inspect=0.0.0.0:9229 --nolazy -r ts-node/register", + "events": { + "crash": "nodemon --delay 500ms -L" + } } \ No newline at end of file diff --git a/Server/package.json b/Server/package.json index fd9b156bb..9f9b92610 100644 --- a/Server/package.json +++ b/Server/package.json @@ -5,25 +5,16 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { - "prepublish": "npm run build", - "install-base": "cd ../00_Base && npm install && npm run build && npm pack && cd ../Server && npm install ../00_Base/citrineos-base-1.0.0.tgz", - "install-util": "cd ../02_Util && npm install ../00_Base/citrineos-base-1.0.0.tgz && npm run build && npm pack && cd ../Server && npm install ../02_Util/citrineos-util-1.0.0.tgz", - "install-data": "cd ../01_Data && npm install ../00_Base/citrineos-base-1.0.0.tgz && npm run build && npm pack && cd ../Server && npm install ../01_Data/citrineos-data-1.0.0.tgz", - "install-ocpprouter": "cd ../03_Modules/OcppRouter && npm run install-all && npm install && npm run build && npm pack && cd ../../Server && npm install ../03_Modules/OcppRouter/citrineos-ocpprouter-1.0.0.tgz", - "install-certificates": "cd ../03_Modules/Certificates && npm run install-all && npm install && npm run build && npm pack && cd ../../Server && npm install ../03_Modules/Certificates/citrineos-certificates-1.0.0.tgz", - "install-configuration": "cd ../03_Modules/Configuration && npm run install-all && npm install && npm run build && npm pack && cd ../../Server && npm install ../03_Modules/Configuration/citrineos-configuration-1.0.0.tgz", - "install-evdriver": "cd ../03_Modules/EVDriver && npm run install-all && npm install && npm run build && npm pack && cd ../../Server && npm install ../03_Modules/EVDriver/citrineos-evdriver-1.0.0.tgz", - "install-monitoring": "cd ../03_Modules/Monitoring && npm run install-all && npm install && npm run build && npm pack && cd ../../Server && npm install ../03_Modules/Monitoring/citrineos-monitoring-1.0.0.tgz", - "install-reporting": "cd ../03_Modules/Reporting && npm run install-all && npm install && npm run build && npm pack && cd ../../Server && npm install ../03_Modules/Reporting/citrineos-reporting-1.0.0.tgz", - "install-smartcharging": "cd ../03_Modules/SmartCharging && npm run install-all && npm install && npm run build && npm pack && cd ../../Server && npm install ../03_Modules/Reporting/citrineos-smartcharging-1.0.0.tgz", - "install-transactions": "cd ../03_Modules/Transactions && npm run install-all && npm install && npm run build && npm pack && cd ../../Server && npm install ../03_Modules/Transactions/citrineos-transactions-1.0.0.tgz", - "install-all": "npm run install-base && npm run install-data && npm run install-util && npm run install-configuration && npm run install-evdriver && npm run install-reporting && npm run install-transactions && npm run install-monitoring", "clean-all-windows": "del package-lock.json && cd ../00_Base && del package-lock.json && rmdir lib /s /q && cd ../02_Util && del package-lock.json && rmdir lib /s /q && cd ../01_Data && del package-lock.json && rmdir lib /s /q && cd ../03_Modules/Configuration && del package-lock.json && rmdir lib /s /q && cd ../03_Modules/EVDriver && del package-lock.json && rmdir lib /s /q && cd ../03_Modules/Reporting && del package-lock.json && rmdir lib /s /q && cd ../03_Modules/Transactions && del package-lock.json && rmdir lib /s /q && cd ../03_Modules/Monitoring && del package-lock.json && rmdir lib /s /q", - "build": "tsc", "start-unix:docker": "export APP_ENV=docker && npx nodemon", "start-unix:local": "export APP_ENV=local && export CITRINEOS_DATA_SEQUELIZE_HOST=127.0.0.1 && npx nodemon", "start-windows:local": "set APP_ENV=local && RefreshEnv.cmd && npx nodemon", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "clean": "rm -rf package-lock.json dist node_modules tsconfig.tsbuildinfo", + "compile": "npm run clean && tsc -p tsconfig.json", + "start": "APP_NAME=all APP_ENV=local node --inspect=0.0.0.0:9229 dist/index.js", + "start:local-docker": "nodemon src/index.ts", + "start:local": "APP_NAME=all APP_ENV=local nodemon src/index.ts" }, "keywords": [ "ocpp", @@ -42,17 +33,16 @@ "typescript": "^5.0.4" }, "dependencies": { - "@citrineos/base": "file:../00_Base/citrineos-base-1.0.0.tgz", - "@citrineos/certificates": "file:../03_Modules/Certificates/citrineos-certificates-1.0.0.tgz", - "@citrineos/configuration": "file:../03_Modules/Configuration/citrineos-configuration-1.0.0.tgz", - "@citrineos/data": "file:../01_Data/citrineos-data-1.0.0.tgz", - "@citrineos/evdriver": "file:../03_Modules/EVDriver/citrineos-evdriver-1.0.0.tgz", - "@citrineos/monitoring": "file:../03_Modules/Monitoring/citrineos-monitoring-1.0.0.tgz", - "@citrineos/ocpprouter": "file:../03_Modules/OcppRouter/citrineos-ocpprouter-1.0.0.tgz", - "@citrineos/reporting": "file:../03_Modules/Reporting/citrineos-reporting-1.0.0.tgz", - "@citrineos/smartcharging": "file:../03_Modules/SmartCharging/citrineos-smartcharging-1.0.0.tgz", - "@citrineos/transactions": "file:../03_Modules/Transactions/citrineos-transactions-1.0.0.tgz", - "@citrineos/util": "file:../02_Util/citrineos-util-1.0.0.tgz", + "@citrineos/base": "1.0.0", + "@citrineos/certificates": "1.0.0", + "@citrineos/configuration": "1.0.0", + "@citrineos/data": "1.0.0", + "@citrineos/evdriver": "1.0.0", + "@citrineos/monitoring": "1.0.0", + "@citrineos/reporting": "1.0.0", + "@citrineos/smartcharging": "1.0.0", + "@citrineos/transactions": "1.0.0", + "@citrineos/util": "1.0.0", "@fastify/type-provider-json-schema-to-ts": "^2.2.2", "ajv": "^8.12.0", "fastify": "^4.22.2", @@ -67,5 +57,6 @@ "optionalDependencies": { "bufferutil": "^4.0.8", "utf-8-validate": "^6.0.3" - } + }, + "workspace": "../" } diff --git a/Server/redis.Dockerfile b/Server/redis.Dockerfile new file mode 100644 index 000000000..d885cff6b --- /dev/null +++ b/Server/redis.Dockerfile @@ -0,0 +1,5 @@ +FROM redis:6.2 as base + +COPY /data/redis/redis.conf /usr/local/etc/redis/ + +CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ] \ No newline at end of file diff --git a/Server/src/config/envs/docker.ts b/Server/src/config/envs/docker.ts index a63ebef7e..05b3e33b7 100644 --- a/Server/src/config/envs/docker.ts +++ b/Server/src/config/envs/docker.ts @@ -65,7 +65,7 @@ export function createDockerConfig() { }, swagger: { path: "/docs", - logoPath: "/usr/server/src/assets/logo.png", + logoPath: "/usr/local/apps/citrineos/server/src/assets/logo.png", exposeData: true, exposeMessage: true }, diff --git a/Server/src/config/envs/swarm.docker.ts b/Server/src/config/envs/swarm.docker.ts new file mode 100644 index 000000000..b0209da7f --- /dev/null +++ b/Server/src/config/envs/swarm.docker.ts @@ -0,0 +1,117 @@ +// Copyright Contributors to the CitrineOS Project +// +// SPDX-License-Identifier: Apache 2.0 + +import { RegistrationStatusEnumType, defineConfig } from "@citrineos/base"; + +export function createDockerConfig() { + return defineConfig({ + env: "development", + centralSystem: { + host: "0.0.0.0", + port: 8080 + }, + modules: { + certificates: { + endpointPrefix: "certificates", + host: "0.0.0.0", + port: 8083 + }, + configuration: { + heartbeatInterval: 60, + bootRetryInterval: 15, + unknownChargerStatus: RegistrationStatusEnumType.Accepted, + getBaseReportOnPending: true, + bootWithRejectedVariables: true, + autoAccept: true, + endpointPrefix: "configuration", + host: "0.0.0.0", + port: 8084 + }, + evdriver: { + endpointPrefix: "evdriver", + host: "0.0.0.0", + port: 8085 + }, + monitoring: { + endpointPrefix: "monitoring", + host: "0.0.0.0", + port: 8086 + }, + reporting: { + endpointPrefix: "reporting", + host: "0.0.0.0", + port: 8087 + }, + smartcharging: { + endpointPrefix: "smartcharging", + host: "0.0.0.0", + port: 8088 + }, + transactions: { + endpointPrefix: "transactions", + host: "0.0.0.0", + port: 8089 + }, + }, + data: { + sequelize: { + host: "ocpp-db", + port: 5432, + database: "citrine", + dialect: "postgres", + username: "citrine", + password: "citrine", + storage: "", + sync: false + } + }, + util: { + cache: { + redis: { + host: "redis", + port: 6379, + } + }, + messageBroker: { + amqp: { + url: "amqp://guest:guest@amqp-broker:5672", + exchange: "citrineos", + } + }, + swagger: { + path: "/docs", + logoPath: "/usr/local/apps/citrineos/server/src/assets/logo.png", + exposeData: true, + exposeMessage: true + }, + directus: { + host: "directus", + port: 8055, + generateFlows: true + }, + networkConnection: { + websocketServers: [{ + id: "0", + securityProfile: 0, + allowUnknownChargingStations: true, + pingInterval: 60, + host: "0.0.0.0", + port: 8081, + protocol: "ocpp2.0.1" + }, { + id: "1", + securityProfile: 1, + allowUnknownChargingStations: false, + pingInterval: 60, + host: "0.0.0.0", + port: 8082, + protocol: "ocpp2.0.1" + }] + } + }, + logLevel: 2, // debug + maxCallLengthSeconds: 5, + maxCachingSeconds: 10 + }); +} \ No newline at end of file diff --git a/Server/src/index.ts b/Server/src/index.ts index 876e28f47..35985e1ad 100644 --- a/Server/src/index.ts +++ b/Server/src/index.ts @@ -3,189 +3,352 @@ // // SPDX-License-Identifier: Apache 2.0 -import { IAuthenticator, ICache, IMessageHandler, IMessageSender, IModule, IModuleApi, SystemConfig } from '@citrineos/base'; -import { MonitoringModule, MonitoringModuleApi } from '@citrineos/monitoring'; -import { Authenticator, DirectusUtil, MemoryCache, RabbitMqReceiver, RabbitMqSender, WebsocketNetworkConnection, initSwagger } from '@citrineos/util'; -import { JsonSchemaToTsProvider } from '@fastify/type-provider-json-schema-to-ts'; -import Ajv from "ajv"; -import addFormats from "ajv-formats" -import fastify, { FastifyInstance } from 'fastify'; -import { ILogObj, Logger } from 'tslog'; -import { systemConfig } from './config'; -import { MessageRouterImpl, AdminApi } from '@citrineos/ocpprouter'; -import { ConfigurationModule, ConfigurationModuleApi } from '@citrineos/configuration'; -import { TransactionsModule, TransactionsModuleApi } from '@citrineos/transactions'; -import { CertificatesModule, CertificatesModuleApi } from '@citrineos/certificates'; -import { EVDriverModule, EVDriverModuleApi } from '@citrineos/evdriver'; -import { ReportingModule, ReportingModuleApi } from '@citrineos/reporting'; -import { SmartChargingModule, SmartChargingModuleApi } from '@citrineos/smartcharging'; -import { sequelize } from '@citrineos/data'; - -class CitrineOSServer { - - /** - * Fields - */ - private _config: SystemConfig; - private _modules: Array; - private _apis: Array; - private _authenticator: IAuthenticator; - private _networkConnection: WebsocketNetworkConnection; - private _logger: Logger; - private _server: FastifyInstance; - private _cache: ICache; - private _ajv: Ajv; - - /** - * Constructor for the class. - * - * @param {FastifyInstance} server - optional Fastify server instance - * @param {Ajv} ajv - optional Ajv JSON schema validator instance - */ - constructor(config: SystemConfig, server?: FastifyInstance, ajv?: Ajv, cache?: ICache) { - - // Set system config - // TODO: Create and export config schemas for each util module, such as amqp, redis, kafka, etc, to avoid passing them possibly invalid configuration - if (!config.util.messageBroker.amqp) { - throw new Error("This server implementation requires amqp configuration for rabbitMQ."); - } - this._config = config; +import { + type AbstractModule, + type AbstractModuleApi, + EventGroup, + eventGroupFromString, + type IAuthenticator, + type ICache, + type IMessageHandler, + type IMessageSender, + type IModule, + type IModuleApi, + type SystemConfig +} from '@citrineos/base' +import {MonitoringModule, MonitoringModuleApi} from '@citrineos/monitoring' +import { + Authenticator, + DirectusUtil, + initSwagger, + MemoryCache, + RabbitMqReceiver, + RabbitMqSender, + RedisCache, + WebsocketNetworkConnection +} from '@citrineos/util' +import {type JsonSchemaToTsProvider} from '@fastify/type-provider-json-schema-to-ts' +import Ajv from 'ajv' +import addFormats from 'ajv-formats' +import fastify, {type FastifyInstance} from 'fastify' +import {type ILogObj, Logger} from 'tslog' +import {systemConfig} from './config' +import {ConfigurationModule, ConfigurationModuleApi} from '@citrineos/configuration' +import {TransactionsModule, TransactionsModuleApi} from '@citrineos/transactions' +import {CertificatesModule, CertificatesModuleApi} from '@citrineos/certificates' +import {EVDriverModule, EVDriverModuleApi} from '@citrineos/evdriver' +import {ReportingModule, ReportingModuleApi} from '@citrineos/reporting' +import {SmartChargingModule, SmartChargingModuleApi} from '@citrineos/smartcharging' +import {sequelize} from '@citrineos/data' +import { + type FastifyRouteSchemaDef, + type FastifySchemaCompiler, + type FastifyValidationResult +} from 'fastify/types/schema' +import {MessageRouterImpl} from '@citrineos/ocpprouter' - // Create server instance - this._server = server || fastify().withTypeProvider(); +interface ModuleConfig { + ModuleClass: new (...args: any[]) => AbstractModule + ModuleApiClass: new (...args: any[]) => AbstractModuleApi + configModule: any // todo type? +} - // Add health check - this._server.get('/health', async () => { - return { status: 'healthy' }; - }); +export class CitrineOSServer { + /** + * Fields + */ + private readonly _config: SystemConfig + private readonly _logger: Logger + private readonly _server: FastifyInstance + private readonly _cache: ICache + private readonly _ajv: Ajv + private readonly modules: IModule[] = [] + private readonly apis: IModuleApi[] = [] + private host?: string + private port?: number + private eventGroup?: EventGroup + private _authenticator?: IAuthenticator + private _networkConnection?: WebsocketNetworkConnection - // Create Ajv JSON schema validator instance - this._ajv = ajv || new Ajv({ removeAdditional: "all", useDefaults: true, coerceTypes: "array", strict: false }); - addFormats(this._ajv, { mode: "fast", formats: ["date-time"] }); + /** + * Constructor for the class. + * + * @param {EventGroup} appName - app type + * @param {SystemConfig} config - config + * @param {FastifyInstance} server - optional Fastify server instance + * @param {Ajv} ajv - optional Ajv JSON schema validator instance + */ + // todo rename event group to type + constructor(appName: string, config: SystemConfig, server?: FastifyInstance, ajv?: Ajv, cache?: ICache) { + // Set system config + // TODO: Create and export config schemas for each util module, such as amqp, redis, kafka, etc, to avoid passing them possibly invalid configuration + if (!config.util.messageBroker.amqp) { + throw new Error('This server implementation requires amqp configuration for rabbitMQ.') + } + this._config = config - // Initialize parent logger - this._logger = new Logger({ - name: "CitrineOS Logger", - minLevel: systemConfig.logLevel, - hideLogPositionForProduction: systemConfig.env === "production", - //Disable colors for cloud deployment as some cloud logging environments such as cloudwatch can not interpret colors - stylePrettyLogs: process.env.DEPLOYMENT_TARGET != "cloud" + // Create server instance + this._server = server || fastify().withTypeProvider() - }); + // Add health check + this.initHealthCheck() - // Set cache implementation - this._cache = cache || new MemoryCache(); + // Create Ajv JSON schema validator instance + this._ajv = this.initAjv(ajv) + this.addAjvFormats() - // Initialize Swagger if enabled - if (this._config.util.swagger) { - initSwagger(this._config, this._server); - } + // Initialize parent logger + this._logger = this.initLogger() - // Add Directus Message API flow creation if enabled - if (this._config.util.directus?.generateFlows) { - const directusUtil = new DirectusUtil(this._config, this._logger); - this._server.addHook("onRoute", directusUtil.addDirectusMessageApiFlowsFastifyRouteHook.bind(directusUtil)); - this._server.addHook('onReady', async () => { - this._logger.info('Directus actions initialization finished'); - }); - } + // Force sync database + this.forceDbSync() - // Register AJV for schema validation - this._server.setValidatorCompiler(({ schema, method, url, httpPart }) => { - return this._ajv.compile(schema); - }); - - // Force sync database - sequelize.DefaultSequelizeInstance.getInstance(this._config, this._logger, true); - - this._authenticator = new Authenticator(this._cache, new sequelize.LocationRepository(config, this._logger), new sequelize.DeviceModelRepository(config, this._logger), this._logger); - - const router = new MessageRouterImpl(this._config, this._cache, this._createSender(), this._createHandler(), async (identifier: string, message: string) => false, this._logger, this._ajv); - - this._networkConnection = new WebsocketNetworkConnection(this._config, this._cache, this._authenticator, router, this._logger); - - // Initialize modules & APIs - // Always initialize APIs after SwaggerUI - const configurationModule = new ConfigurationModule(this._config, this._cache, this._createSender(), this._createHandler(), this._logger); - const evdriverModule = new EVDriverModule(this._config, this._cache, this._createSender(), this._createHandler(), this._logger); - const monitoringModule = new MonitoringModule(this._config, this._cache, this._createSender(), this._createHandler(), this._logger); - const reportingModule = new ReportingModule(this._config, this._cache, this._createSender(), this._createHandler(), this._logger); - const transactionsModule = new TransactionsModule(this._config, this._cache, this._createSender(), this._createHandler(), this._logger); - this._modules = [ - router, - configurationModule, - evdriverModule, - monitoringModule, - reportingModule, - transactionsModule - ] - this._apis = [ - new AdminApi(router, this._server, this._logger), - new ConfigurationModuleApi(configurationModule, this._server, this._logger), - new EVDriverModuleApi(evdriverModule, this._server, this._logger), - new MonitoringModuleApi(monitoringModule, this._server, this._logger), - new ReportingModuleApi(reportingModule, this._server, this._logger), - new TransactionsModuleApi(transactionsModule, this._server, this._logger), - ]; - if (this._config.modules.certificates) { - const certificatesModule = new CertificatesModule(this._config, this._cache, this._createSender(), this._createHandler(), this._logger) - this._modules.push(certificatesModule); - this._apis.push(new CertificatesModuleApi(certificatesModule, this._server, this._logger)); - } - if (this._config.modules.smartcharging) { - const smartchargingModule = new SmartChargingModule(this._config, this._cache, this._createSender(), this._createHandler(), this._logger) - this._modules.push(smartchargingModule); - this._apis.push(new SmartChargingModuleApi(smartchargingModule, this._server, this._logger)); - } + // Set cache implementation + this._cache = this.initCache(cache) - process.on('SIGINT', this.shutdown.bind(this)); - process.on('SIGTERM', this.shutdown.bind(this)); - process.on('SIGQUIT', this.shutdown.bind(this)); + // Initialize Swagger if enabled + this.initSwagger() + + // Add Directus Message API flow creation if enabled + if (this._config.util.directus?.generateFlows) { + const directusUtil = new DirectusUtil(this._config, this._logger) + this._server.addHook('onRoute', directusUtil.addDirectusMessageApiFlowsFastifyRouteHook.bind(directusUtil)) + this._server.addHook('onReady', async () => { + this._logger?.info('Directus actions initialization finished') + }) } - protected _createSender(): IMessageSender { - return new RabbitMqSender(this._config, this._logger); + // Register AJV for schema validation + this.registerAjv() + + // Initialize module & API + // Always initialize API after SwaggerUI + this.initSystem(appName) + + process.on('SIGINT', this.shutdown.bind(this)) + process.on('SIGTERM', this.shutdown.bind(this)) + process.on('SIGQUIT', this.shutdown.bind(this)) + } + + private initHealthCheck() { + this._server.get('/health', async () => { + return {status: 'healthy'} + }) + } + + private initAjv(ajv?: Ajv) { + return ajv || new Ajv({ + removeAdditional: 'all', + useDefaults: true, + coerceTypes: 'array', + strict: false + }) + } + + private addAjvFormats() { + addFormats(this._ajv, { + mode: 'fast', + formats: ['date-time'] + }) + } + + private initLogger() { + return new Logger({ + name: 'CitrineOS Logger', + minLevel: systemConfig.logLevel, + hideLogPositionForProduction: systemConfig.env === 'production', + // Disable colors for cloud deployment as some cloude logging environments such as cloudwatch can not interpret colors + stylePrettyLogs: process.env.DEPLOYMENT_TARGET !== 'cloud' + }) + } + + private forceDbSync() { + sequelize.DefaultSequelizeInstance.getInstance(this._config, this._logger, true) + } + + private initCache(cache?: ICache): ICache { + return cache || (this._config.util.cache.redis + ? new RedisCache({ + socket: { + host: this._config.util.cache.redis.host, + port: this._config.util.cache.redis.port + } + }) + : new MemoryCache()) + } + + private initSwagger() { + if (this._config.util.swagger) { + initSwagger(this._config, this._server) } + } - protected _createHandler(): IMessageHandler { - return new RabbitMqReceiver(this._config, this._logger); + private registerAjv() { + // todo type schema instead of any + const fastifySchemaCompiler: FastifySchemaCompiler = (routeSchema: FastifyRouteSchemaDef) => { + return this._ajv?.compile(routeSchema.schema) as FastifyValidationResult } + this._server.setValidatorCompiler(fastifySchemaCompiler) + } + + private initNetworkConnection() { + this._authenticator = new Authenticator(this._cache, new sequelize.LocationRepository(this._config, this._logger), new sequelize.DeviceModelRepository(this._config, this._logger), this._logger) - shutdown() { + const router = new MessageRouterImpl(this._config, this._cache, this._createSender(), this._createHandler(), async (identifier: string, message: string) => false, this._logger, this._ajv) - // Shut down all modules and ocpp router - this._modules.forEach(module => { - module.shutdown(); - }); - this._networkConnection.shutdown(); + this._networkConnection = new WebsocketNetworkConnection(this._config, this._cache, this._authenticator, router, this._logger) + } - // Shutdown server - this._server.close(); + private initAllModules() { + [ + this.getModuleConfig(EventGroup.Certificates), + this.getModuleConfig(EventGroup.Configuration), + this.getModuleConfig(EventGroup.EVDriver), + this.getModuleConfig(EventGroup.Monitoring), + this.getModuleConfig(EventGroup.Reporting), + this.getModuleConfig(EventGroup.SmartCharging), + this.getModuleConfig(EventGroup.Transactions) + ].forEach(moduleConfig => { + this.initModule(moduleConfig) + }) + } - setTimeout(() => { - console.log("Exiting..."); - process.exit(1); - }, 2000); + private initModule(moduleConfig: ModuleConfig) { + if (moduleConfig.configModule !== null) { + const module = new moduleConfig.ModuleClass( + this._config, + this._cache, + this._createSender(), + this._createHandler(), + this._logger + ) + this.modules.push(module) + this.apis.push( + new moduleConfig.ModuleApiClass( + module, + this._server, + this._logger + ) + ) + // TODO: take actions to make sure module has correct subscriptions and log proof + this._logger?.info(`${moduleConfig.ModuleClass.name} module started...`) + if (this.eventGroup !== EventGroup.All) { + this.host = moduleConfig.configModule.host as string + this.port = moduleConfig.configModule.port as number + } + } else { + throw new Error(`No config for ${this.eventGroup} module`) } + } - run(): Promise { - try { - return this._server.listen({ - port: this._config.centralSystem.port, - host: this._config.centralSystem.host - }).then(address => { - this._logger.info(`Server listening at ${address}`); - }).catch(error => { - this._logger.error(error); - process.exit(1); - }); - } catch (error) { - return Promise.reject(error); + private getModuleConfig(appName: EventGroup): ModuleConfig { + switch (appName) { + case EventGroup.Certificates: + return { + ModuleClass: CertificatesModule, + ModuleApiClass: CertificatesModuleApi, + configModule: this._config.modules.certificates + } + case EventGroup.Configuration: + return { + ModuleClass: ConfigurationModule, + ModuleApiClass: ConfigurationModuleApi, + configModule: this._config.modules.configuration + } + case EventGroup.EVDriver: + return { + ModuleClass: EVDriverModule, + ModuleApiClass: EVDriverModuleApi, + configModule: this._config.modules.evdriver + } + case EventGroup.Monitoring: + return { + ModuleClass: MonitoringModule, + ModuleApiClass: MonitoringModuleApi, + configModule: this._config.modules.monitoring } + case EventGroup.Reporting: + return { + ModuleClass: ReportingModule, + ModuleApiClass: ReportingModuleApi, + configModule: this._config.modules.reporting + } + case EventGroup.SmartCharging: + return { + ModuleClass: SmartChargingModule, + ModuleApiClass: SmartChargingModuleApi, + configModule: this._config.modules.smartcharging + } + case EventGroup.Transactions: + return { + ModuleClass: TransactionsModule, + ModuleApiClass: TransactionsModuleApi, + configModule: this._config.modules.transactions + } + default: + throw new Error('Unhandled module type: ' + appName) + } + } + + private initSystem(appName: string) { + this.eventGroup = eventGroupFromString(appName) + if (this.eventGroup === EventGroup.All) { + this.initAllModules() + } else if (this.eventGroup === EventGroup.General) { + this.initNetworkConnection() + } else { + const moduleConfig: ModuleConfig = this.getModuleConfig(this.eventGroup) + this.initModule(moduleConfig) + } + } + + protected _createSender(): IMessageSender { + return new RabbitMqSender(this._config, this._logger) + } + + protected _createHandler(): IMessageHandler { + return new RabbitMqReceiver(this._config, this._logger) + } + + shutdown() { + // todo shut down depending on setup + // Shut down all modules and central system + this.modules.forEach(module => { + module.shutdown() + }) + this._networkConnection?.shutdown() + + // Shutdown server + this._server.close().then() // todo async? + + setTimeout(() => { + console.log('Exiting...') + process.exit(1) + }, 2000) + } + + async run(): Promise { + try { + await this._server.listen({ + host: this.host, + port: this.port + }).then(address => { + this._logger?.info(`Server listening at ${address}`) + }).catch(error => { + this._logger?.error(error) + process.exit(1) + }) + // TODO Push config to microservices + } catch (error) { + await Promise.reject(error) } + } } -new CitrineOSServer(systemConfig).run().catch(error => { - console.error(error); - process.exit(1); -}); \ No newline at end of file +new CitrineOSServer( + process.env.APP_NAME as EventGroup, + systemConfig +).run().catch((error: any) => { + console.error(error) + process.exit(1) +}) diff --git a/Server/tsconfig.json b/Server/tsconfig.json index 5cebe347b..1aaec51ee 100644 --- a/Server/tsconfig.json +++ b/Server/tsconfig.json @@ -1,21 +1,47 @@ { - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "skipLibCheck": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "lib", - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true - }, + "extends": "../tsconfig.build.json", "include": [ - "src" + "src/**/*.ts", + "src/**/*.json" ], - "exclude": [ - "node_modules", - "**/__tests__/*" + "compilerOptions": { + "outDir": "./dist/", + "rootDir": "./src", + "composite": true + }, + "references": [ + { + "path": "../00_Base" + }, + { + "path": "../01_Data" + }, + { + "path": "../02_Util" + }, + { + "path": "../03_Modules/Certificates" + }, + { + "path": "../03_Modules/Configuration" + }, + { + "path": "../03_Modules/EVDriver" + }, + { + "path": "../03_Modules/Monitoring" + }, + { + "path": "../03_Modules/OcppRouter" + }, + { + "path": "../03_Modules/Reporting" + }, + { + "path": "../03_Modules/SmartCharging" + }, + { + "path": "../03_Modules/Transactions" + } ] } \ No newline at end of file diff --git a/Server/unix-init-install-all.sh b/Server/unix-init-install-all.sh deleted file mode 100755 index e6b2eb128..000000000 --- a/Server/unix-init-install-all.sh +++ /dev/null @@ -1,187 +0,0 @@ -#!/bin/bash - -docker network create --driver=bridge citrine-network || echo "Network already exists." - -execute_commands() { - local commands=("$@") - for cmd in "${commands[@]}"; do - echo "Executing: $cmd" - eval "$cmd" - - if [ $? -ne 0 ]; then - echo "Error executing $cmd" - exit 1 - fi - done -} - -# Commands for each module -base_commands=( - "cd ../00_Base" - "rm -rf ./lib" - "rm -f citrineos-base-1.0.0.tgz" - "npm install" - "npm pack" -) - -data_commands=( - "cd ../01_Data" - "rm -rf ./lib" - "rm -f citrineos-data-1.0.0.tgz" - "npm install ../00_Base/citrineos-base-1.0.0.tgz" - "npm install" - "npm pack" -) - -util_commands=( - "cd ../02_Util" - "rm -rf ./lib" - "rm -f citrineos-util-1.0.0.tgz" - "npm install ../00_Base/citrineos-base-1.0.0.tgz" - "npm install ../01_Data/citrineos-data-1.0.0.tgz" - "npm install" - "npm pack" -) - -ocpprouter_commands=( - "cd ../03_Modules/OcppRouter" - "rm -rf ./lib" - "rm -f citrineos-ocpprouter-1.0.0.tgz" - "npm install ../../00_Base/citrineos-base-1.0.0.tgz" - "npm install ../../01_Data/citrineos-data-1.0.0.tgz" - "npm install ../../02_Util/citrineos-util-1.0.0.tgz" - "npm install" - "npm pack" -) - -certificates_commands=( - "cd ../03_Modules/Certificates" - "rm -rf ./lib" - "rm -f citrineos-certificates-1.0.0.tgz" - "npm install ../../00_Base/citrineos-base-1.0.0.tgz" - "npm install ../../01_Data/citrineos-data-1.0.0.tgz" - "npm install ../../02_Util/citrineos-util-1.0.0.tgz" - "npm install" - "npm pack" -) - -configuration_commands=( - "cd ../03_Modules/Configuration" - "rm -rf ./lib" - "rm -f citrineos-configuration-1.0.0.tgz" - "npm install ../../00_Base/citrineos-base-1.0.0.tgz" - "npm install ../../01_Data/citrineos-data-1.0.0.tgz" - "npm install ../../02_Util/citrineos-util-1.0.0.tgz" - "npm install" - "npm pack" -) - -evdriver_commands=( - "cd ../03_Modules/EVDriver" - "rm -rf ./lib" - "rm -f citrineos-evdriver-1.0.0.tgz" - "npm install ../../00_Base/citrineos-base-1.0.0.tgz" - "npm install ../../01_Data/citrineos-data-1.0.0.tgz" - "npm install ../../02_Util/citrineos-util-1.0.0.tgz" - "npm install" - "npm pack" -) - -monitoring_commands=( - "cd ../03_Modules/Monitoring" - "rm -rf ./lib" - "rm -f citrineos-monitoring-1.0.0.tgz" - "npm install ../../00_Base/citrineos-base-1.0.0.tgz" - "npm install ../../01_Data/citrineos-data-1.0.0.tgz" - "npm install ../../02_Util/citrineos-util-1.0.0.tgz" - "npm install" - "npm pack" -) - -reporting_commands=( - "cd ../03_Modules/Reporting" - "rm -rf ./lib" - "rm -f citrineos-reporting-1.0.0.tgz" - "npm install ../../00_Base/citrineos-base-1.0.0.tgz" - "npm install ../../01_Data/citrineos-data-1.0.0.tgz" - "npm install ../../02_Util/citrineos-util-1.0.0.tgz" - "npm install" - "npm pack" -) - -smartcharging_commands=( - "cd ../03_Modules/SmartCharging" - "rm -rf ./lib" - "rm -f citrineos-smartcharging-1.0.0.tgz" - "npm install ../../00_Base/citrineos-base-1.0.0.tgz" - "npm install ../../01_Data/citrineos-data-1.0.0.tgz" - "npm install ../../02_Util/citrineos-util-1.0.0.tgz" - "npm install" - "npm pack" -) - -transactions_commands=( - "cd ../03_Modules/Transactions" - "rm -rf ./lib" - "rm -f citrineos-transactions-1.0.0.tgz" - "npm install ../../00_Base/citrineos-base-1.0.0.tgz" - "npm install ../../01_Data/citrineos-data-1.0.0.tgz" - "npm install ../../02_Util/citrineos-util-1.0.0.tgz" - "npm install" - "npm pack" -) - -ocpp_server_commands=( - "cd ../Server" - "rm -rf ./lib" - "npm install ../00_Base/citrineos-base-1.0.0.tgz" - "npm install ../01_Data/citrineos-data-1.0.0.tgz" - "npm install ../02_Util/citrineos-util-1.0.0.tgz" - "npm install ../03_Modules/OcppRouter/citrineos-ocpprouter-1.0.0.tgz" - "npm install ../03_Modules/Certificates/citrineos-certificates-1.0.0.tgz" - "npm install ../03_Modules/Configuration/citrineos-configuration-1.0.0.tgz" - "npm install ../03_Modules/EVDriver/citrineos-evdriver-1.0.0.tgz" - "npm install ../03_Modules/Monitoring/citrineos-monitoring-1.0.0.tgz" - "npm install ../03_Modules/Reporting/citrineos-reporting-1.0.0.tgz" - "npm install ../03_Modules/SmartCharging/citrineos-smartcharging-1.0.0.tgz" - "npm install ../03_Modules/Transactions/citrineos-transactions-1.0.0.tgz" - "npm install" -) - -# Execute commands for each module -execute_commands "${base_commands[@]}" -execute_commands "${data_commands[@]}" -execute_commands "${util_commands[@]}" -execute_commands "${ocpprouter_commands[@]}"& -pid_ocpprouter=$! -execute_commands "${certificates_commands[@]}"& -pid_certificates=$! -execute_commands "${configuration_commands[@]}"& -pid_configuration=$! -execute_commands "${evdriver_commands[@]}"& -pid_evdriver=$! -execute_commands "${monitoring_commands[@]}"& -pid_monitoring=$! -execute_commands "${reporting_commands[@]}"& -pid_reporting=$! -execute_commands "${smartcharging_commands[@]}"& -pid_smartcharging=$! -execute_commands "${transactions_commands[@]}"& -pid_transactions=$! - - - -wait $pid_ocpprouter -wait $pid_certificates -wait $pid_configuration -wait $pid_evdriver -wait $pid_monitoring -wait $pid_reporting -wait $pid_smartcharging -wait $pid_transactions - -echo "Dependancy Installation Completed! Now initializing the OCPP server..." - -execute_commands "${ocpp_server_commands[@]}" - -echo "All commands executed successfully!" \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 000000000..376eec40e --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "@citrineos/workspace", + "version": "1.0.0", + "private": true, + "devDependencies": { + "@types/node": "^20.11.20", + "concurrently": "^8.2.2", + "nodemon": "^3.1.0", + "typescript": "^5.3.3" + }, + "scripts": { + "install-all": "npm i --verbose", + "clean": "rm -rf package-lock.json **/package-lock.json **/**/package-lock.json dist **/dist **/**/dist node_modules **/node_modules **/**/node_modules tsconfig.tsbuildinfo **/tsconfig.tsbuildinfo **/**/tsconfig.tsbuildinfo", + "build": "tsc --build --verbose" + }, + "dependencies": { + "@citrineos/server": "1.0.0" + }, + "workspaces": [ + "./00_Base", + "./01_Data", + "./02_Util", + "./03_Modules/Certificates", + "./03_Modules/Configuration", + "./03_Modules/EVDriver", + "./03_Modules/Monitoring", + "./03_Modules/OcppRouter", + "./03_Modules/Reporting", + "./03_Modules/SmartCharging", + "./03_Modules/Transactions", + "./Server" + ] +} diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 000000000..2c4fd9fa8 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,22 @@ +{ + "exclude": [ + "**/*.test.ts", + "**/*.stub.ts", + "node_modules", + "**/__tests__/*", + "dist" + ], + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "strict": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "declaration": true, + "resolveJsonModule": true, + "esModuleInterop": true, + "sourceMap": true + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..80628f030 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "rootDir": "./", + "outDir": "./dist/" + }, + "references": [ + { + "path": "./Server" + } + ] +} \ No newline at end of file