@zetra/citrineos-reporting 1.8.3-fork.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ export { ReportingOcpp16Api } from './module/1.6/MessageApi.js';
2
+ export { ReportingOcpp201Api } from './module/2.0.1/MessageApi.js';
3
+ export type { IReportingModuleApi } from './module/interface.js';
4
+ export { ReportingModule } from './module/module.js';
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ export { ReportingOcpp16Api } from './module/1.6/MessageApi.js';
5
+ export { ReportingOcpp201Api } from './module/2.0.1/MessageApi.js';
6
+ export { ReportingModule } from './module/module.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,sCAAsC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { ILogObj } from 'tslog';
2
+ import { Logger } from 'tslog';
3
+ import type { CallAction, IMessageConfirmation } from '@citrineos/base';
4
+ import { AbstractModuleApi, OCPP1_6 } from '@citrineos/base';
5
+ import type { FastifyInstance } from 'fastify';
6
+ import type { IReportingModuleApi } from '../interface.js';
7
+ import { ReportingModule } from '../module.js';
8
+ /**
9
+ * Server API for the Reporting module (OCPP 1.6).
10
+ */
11
+ export declare class ReportingOcpp16Api extends AbstractModuleApi<ReportingModule> implements IReportingModuleApi {
12
+ /**
13
+ * Constructs a new instance of the class.
14
+ *
15
+ * @param {ReportingModule} reportingModule - The Reporting module.
16
+ * @param {FastifyInstance} server - The Fastify server instance.
17
+ * @param {Logger<ILogObj>} [logger] - The logger instance.
18
+ */
19
+ constructor(reportingModule: ReportingModule, server: FastifyInstance, logger?: Logger<ILogObj>);
20
+ getDiagnostics(identifier: string[], request: OCPP1_6.GetDiagnosticsRequest, callbackUrl?: string, tenantId?: number): Promise<IMessageConfirmation[]>;
21
+ /**
22
+ * Overrides superclass method to generate the URL path based on the input {@link CallAction}
23
+ * and the module's endpoint prefix configuration.
24
+ *
25
+ * @param {CallAction} input - The input {@link CallAction}.
26
+ * @return {string} - The generated URL path.
27
+ */
28
+ protected _toMessagePath(input: CallAction): string;
29
+ }
@@ -0,0 +1,52 @@
1
+ // SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
5
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9
+ };
10
+ var __metadata = (this && this.__metadata) || function (k, v) {
11
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
12
+ };
13
+ import { Logger } from 'tslog';
14
+ import { AbstractModuleApi, AsMessageEndpoint, DEFAULT_TENANT_ID, OCPP1_6, OCPP1_6_CallAction, OCPPVersion, } from '@citrineos/base';
15
+ import { ReportingModule } from '../module.js';
16
+ /**
17
+ * Server API for the Reporting module (OCPP 1.6).
18
+ */
19
+ export class ReportingOcpp16Api extends AbstractModuleApi {
20
+ /**
21
+ * Constructs a new instance of the class.
22
+ *
23
+ * @param {ReportingModule} reportingModule - The Reporting module.
24
+ * @param {FastifyInstance} server - The Fastify server instance.
25
+ * @param {Logger<ILogObj>} [logger] - The logger instance.
26
+ */
27
+ constructor(reportingModule, server, logger) {
28
+ super(reportingModule, server, OCPPVersion.OCPP1_6, logger);
29
+ }
30
+ getDiagnostics(identifier, request, callbackUrl, tenantId = DEFAULT_TENANT_ID) {
31
+ const results = identifier.map((id) => this._module.sendCall(id, tenantId, OCPPVersion.OCPP1_6, OCPP1_6_CallAction.GetDiagnostics, request, callbackUrl));
32
+ return Promise.all(results);
33
+ }
34
+ /**
35
+ * Overrides superclass method to generate the URL path based on the input {@link CallAction}
36
+ * and the module's endpoint prefix configuration.
37
+ *
38
+ * @param {CallAction} input - The input {@link CallAction}.
39
+ * @return {string} - The generated URL path.
40
+ */
41
+ _toMessagePath(input) {
42
+ const endpointPrefix = this._module.config.modules.reporting.endpointPrefix;
43
+ return super._toMessagePath(input, endpointPrefix);
44
+ }
45
+ }
46
+ __decorate([
47
+ AsMessageEndpoint(OCPP1_6_CallAction.GetDiagnostics, OCPP1_6.GetDiagnosticsRequestSchema),
48
+ __metadata("design:type", Function),
49
+ __metadata("design:paramtypes", [Array, Object, String, Number]),
50
+ __metadata("design:returntype", Promise)
51
+ ], ReportingOcpp16Api.prototype, "getDiagnostics", null);
52
+ //# sourceMappingURL=MessageApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessageApi.js","sourceRoot":"","sources":["../../../src/module/1.6/MessageApi.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,sCAAsC;;;;;;;;;;AAGtC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,OAAO,EACP,kBAAkB,EAClB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,kBACX,SAAQ,iBAAkC;IAG1C;;;;;;OAMG;IACH,YAAY,eAAgC,EAAE,MAAuB,EAAE,MAAwB;QAC7F,KAAK,CAAC,eAAe,EAAE,MAAM,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IAGD,cAAc,CACZ,UAAoB,EACpB,OAAsC,EACtC,WAAoB,EACpB,WAAmB,iBAAiB;QAEpC,MAAM,OAAO,GAAoC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACrE,IAAI,CAAC,OAAO,CAAC,QAAQ,CACnB,EAAE,EACF,QAAQ,EACR,WAAW,CAAC,OAAO,EACnB,kBAAkB,CAAC,cAAc,EACjC,OAAO,EACP,WAAW,CACZ,CACF,CAAC;QACF,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACO,cAAc,CAAC,KAAiB;QACxC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC;QAC5E,OAAO,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACrD,CAAC;CACF;AA9BC;IADC,iBAAiB,CAAC,kBAAkB,CAAC,cAAc,EAAE,OAAO,CAAC,2BAA2B,CAAC;;;;wDAkBzF"}
@@ -0,0 +1,34 @@
1
+ import type { ILogObj } from 'tslog';
2
+ import { Logger } from 'tslog';
3
+ import type { CallAction, IMessageConfirmation } from '@citrineos/base';
4
+ import { AbstractModuleApi, OCPP2_0_1 } from '@citrineos/base';
5
+ import type { FastifyInstance } from 'fastify';
6
+ import type { IReportingModuleApi } from '../interface.js';
7
+ import { ReportingModule } from '../module.js';
8
+ /**
9
+ * Server API for the Reporting module.
10
+ */
11
+ export declare class ReportingOcpp201Api extends AbstractModuleApi<ReportingModule> implements IReportingModuleApi {
12
+ private readonly _componentDeviceDataCtrlr;
13
+ /**
14
+ * Constructs a new instance of the class.
15
+ *
16
+ * @param {ReportingModule} reportingModule - The Reporting module.
17
+ * @param {FastifyInstance} server - The Fastify server instance.
18
+ * @param {Logger<ILogObj>} [logger] - The logger instance.
19
+ */
20
+ constructor(reportingModule: ReportingModule, server: FastifyInstance, logger?: Logger<ILogObj>);
21
+ getBaseReport(identifier: string[], request: OCPP2_0_1.GetBaseReportRequest, callbackUrl?: string, tenantId?: number): Promise<IMessageConfirmation[]>;
22
+ getCustomReport(identifier: string, request: OCPP2_0_1.GetReportRequest, callbackUrl?: string, tenantId?: number): Promise<IMessageConfirmation>;
23
+ getMonitoringReport(identifier: string, request: OCPP2_0_1.GetMonitoringReportRequest, callbackUrl?: string, tenantId?: number): Promise<IMessageConfirmation>;
24
+ getLog(identifier: string[], request: OCPP2_0_1.GetLogRequest, callbackUrl?: string, tenantId?: number): Promise<IMessageConfirmation[]>;
25
+ customerInformation(identifier: string[], request: OCPP2_0_1.CustomerInformationRequest, callbackUrl?: string, tenantId?: number): Promise<IMessageConfirmation[]>;
26
+ /**
27
+ * Overrides superclass method to generate the URL path based on the input {@link CallAction}
28
+ * and the module's endpoint prefix configuration.
29
+ *
30
+ * @param {CallAction} input - The input {@link CallAction}.
31
+ * @return {string} - The generated URL path.
32
+ */
33
+ protected _toMessagePath(input: CallAction): string;
34
+ }
@@ -0,0 +1,166 @@
1
+ // SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
5
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9
+ };
10
+ var __metadata = (this && this.__metadata) || function (k, v) {
11
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
12
+ };
13
+ import { Logger } from 'tslog';
14
+ import { AbstractModuleApi, AsMessageEndpoint, DEFAULT_TENANT_ID, OCPP2_0_1, OCPP2_0_1_CallAction, OCPPVersion, } from '@citrineos/base';
15
+ import { ReportingModule } from '../module.js';
16
+ import { getBatches, getSizeOfRequest } from '@citrineos/util';
17
+ /**
18
+ * Server API for the Reporting module.
19
+ */
20
+ export class ReportingOcpp201Api extends AbstractModuleApi {
21
+ _componentDeviceDataCtrlr = 'DeviceDataCtrlr';
22
+ /**
23
+ * Constructs a new instance of the class.
24
+ *
25
+ * @param {ReportingModule} reportingModule - The Reporting module.
26
+ * @param {FastifyInstance} server - The Fastify server instance.
27
+ * @param {Logger<ILogObj>} [logger] - The logger instance.
28
+ */
29
+ constructor(reportingModule, server, logger) {
30
+ super(reportingModule, server, OCPPVersion.OCPP2_0_1, logger);
31
+ }
32
+ getBaseReport(identifier, request, callbackUrl, tenantId = DEFAULT_TENANT_ID) {
33
+ // For each station, send the GetBaseReport call
34
+ const results = identifier.map((id) => this._module.sendCall(id, tenantId, OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.GetBaseReport, request, callbackUrl));
35
+ return Promise.all(results);
36
+ }
37
+ async getCustomReport(identifier, request, callbackUrl, tenantId = DEFAULT_TENANT_ID) {
38
+ // if request size is bigger than BytesPerMessageGetReport, return error
39
+ const bytesPerMessageGetReport = await this._module._deviceModelService.getBytesPerMessageByComponentAndVariableInstanceAndStationId(this._componentDeviceDataCtrlr, OCPP2_0_1_CallAction.GetReport, tenantId, identifier);
40
+ const requestBytes = getSizeOfRequest(request);
41
+ if (bytesPerMessageGetReport && requestBytes > bytesPerMessageGetReport) {
42
+ const errorMsg = `The request is too big. The max size is ${bytesPerMessageGetReport} bytes.`;
43
+ this._logger.error(errorMsg);
44
+ return { success: false, payload: errorMsg };
45
+ }
46
+ const componentVariables = request.componentVariable;
47
+ if (componentVariables.length === 0) {
48
+ // Send everything in one call
49
+ return await this._module.sendCall(identifier, tenantId, OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.GetReport, request, callbackUrl);
50
+ }
51
+ // Batching logic
52
+ let itemsPerMessageGetReport = await this._module._deviceModelService.getItemsPerMessageByComponentAndVariableInstanceAndStationId(this._componentDeviceDataCtrlr, OCPP2_0_1_CallAction.GetReport, tenantId, identifier);
53
+ itemsPerMessageGetReport =
54
+ itemsPerMessageGetReport === null ? componentVariables.length : itemsPerMessageGetReport;
55
+ const confirmations = [];
56
+ // Using multiple calls if needed
57
+ for (const [index, batch] of getBatches(componentVariables, itemsPerMessageGetReport).entries()) {
58
+ try {
59
+ const batchResult = await this._module.sendCall(identifier, tenantId, OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.GetReport, {
60
+ componentVariable: batch,
61
+ componentCriteria: request.componentCriteria,
62
+ requestId: request.requestId,
63
+ }, callbackUrl);
64
+ confirmations.push({
65
+ success: batchResult.success,
66
+ batch: `[${index}:${index + batch.length}]`,
67
+ message: `${batchResult.payload}`,
68
+ });
69
+ }
70
+ catch (error) {
71
+ confirmations.push({
72
+ success: false,
73
+ batch: `[${index}:${index + batch.length}]`,
74
+ message: `${error}`,
75
+ });
76
+ }
77
+ }
78
+ // Returns a single IMessageConfirmation containing details of each batched call
79
+ return { success: true, payload: confirmations };
80
+ }
81
+ async getMonitoringReport(identifier, request, callbackUrl, tenantId = DEFAULT_TENANT_ID) {
82
+ // If monitoringCriteria & componentVariable are both empty, just call once
83
+ const componentVariable = request.componentVariable;
84
+ const monitoringCriteria = request.monitoringCriteria;
85
+ if (componentVariable.length === 0 && monitoringCriteria.length === 0) {
86
+ return await this._module.sendCall(identifier, tenantId, OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.GetMonitoringReport, request, callbackUrl);
87
+ }
88
+ // Otherwise, do batching if needed
89
+ let itemsPerMessageGetReport = await this._module._deviceModelService.getItemsPerMessageByComponentAndVariableInstanceAndStationId(this._componentDeviceDataCtrlr, OCPP2_0_1_CallAction.GetReport, tenantId, identifier);
90
+ itemsPerMessageGetReport =
91
+ itemsPerMessageGetReport === null ? componentVariable.length : itemsPerMessageGetReport;
92
+ const confirmations = [];
93
+ for (const [index, batch] of getBatches(componentVariable, itemsPerMessageGetReport).entries()) {
94
+ try {
95
+ const batchResult = await this._module.sendCall(identifier, tenantId, OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.GetMonitoringReport, {
96
+ componentVariable: batch,
97
+ monitoringCriteria,
98
+ requestId: request.requestId,
99
+ }, callbackUrl);
100
+ confirmations.push({
101
+ success: batchResult.success,
102
+ batch: `[${index}:${index + batch.length}]`,
103
+ message: `${batchResult.payload}`,
104
+ });
105
+ }
106
+ catch (error) {
107
+ confirmations.push({
108
+ success: false,
109
+ batch: `[${index}:${index + batch.length}]`,
110
+ message: `${error}`,
111
+ });
112
+ }
113
+ }
114
+ return { success: true, payload: confirmations };
115
+ }
116
+ getLog(identifier, request, callbackUrl, tenantId = DEFAULT_TENANT_ID) {
117
+ const results = identifier.map((id) => this._module.sendCall(id, tenantId, OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.GetLog, request, callbackUrl));
118
+ return Promise.all(results);
119
+ }
120
+ customerInformation(identifier, request, callbackUrl, tenantId = DEFAULT_TENANT_ID) {
121
+ const results = identifier.map((id) => this._module.sendCall(id, tenantId, OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.CustomerInformation, request, callbackUrl));
122
+ return Promise.all(results);
123
+ }
124
+ /**
125
+ * Overrides superclass method to generate the URL path based on the input {@link CallAction}
126
+ * and the module's endpoint prefix configuration.
127
+ *
128
+ * @param {CallAction} input - The input {@link CallAction}.
129
+ * @return {string} - The generated URL path.
130
+ */
131
+ _toMessagePath(input) {
132
+ const endpointPrefix = this._module.config.modules.reporting.endpointPrefix;
133
+ return super._toMessagePath(input, endpointPrefix);
134
+ }
135
+ }
136
+ __decorate([
137
+ AsMessageEndpoint(OCPP2_0_1_CallAction.GetBaseReport, OCPP2_0_1.GetBaseReportRequestSchema),
138
+ __metadata("design:type", Function),
139
+ __metadata("design:paramtypes", [Array, Object, String, Number]),
140
+ __metadata("design:returntype", Promise)
141
+ ], ReportingOcpp201Api.prototype, "getBaseReport", null);
142
+ __decorate([
143
+ AsMessageEndpoint(OCPP2_0_1_CallAction.GetReport, OCPP2_0_1.GetReportRequestSchema),
144
+ __metadata("design:type", Function),
145
+ __metadata("design:paramtypes", [String, Object, String, Number]),
146
+ __metadata("design:returntype", Promise)
147
+ ], ReportingOcpp201Api.prototype, "getCustomReport", null);
148
+ __decorate([
149
+ AsMessageEndpoint(OCPP2_0_1_CallAction.GetMonitoringReport, OCPP2_0_1.GetMonitoringReportRequestSchema),
150
+ __metadata("design:type", Function),
151
+ __metadata("design:paramtypes", [String, Object, String, Number]),
152
+ __metadata("design:returntype", Promise)
153
+ ], ReportingOcpp201Api.prototype, "getMonitoringReport", null);
154
+ __decorate([
155
+ AsMessageEndpoint(OCPP2_0_1_CallAction.GetLog, OCPP2_0_1.GetLogRequestSchema),
156
+ __metadata("design:type", Function),
157
+ __metadata("design:paramtypes", [Array, Object, String, Number]),
158
+ __metadata("design:returntype", Promise)
159
+ ], ReportingOcpp201Api.prototype, "getLog", null);
160
+ __decorate([
161
+ AsMessageEndpoint(OCPP2_0_1_CallAction.CustomerInformation, OCPP2_0_1.CustomerInformationRequestSchema),
162
+ __metadata("design:type", Function),
163
+ __metadata("design:paramtypes", [Array, Object, String, Number]),
164
+ __metadata("design:returntype", Promise)
165
+ ], ReportingOcpp201Api.prototype, "customerInformation", null);
166
+ //# sourceMappingURL=MessageApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessageApi.js","sourceRoot":"","sources":["../../../src/module/2.0.1/MessageApi.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,sCAAsC;;;;;;;;;;AAGt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AAC,MAAM,EAAE,SAAS,CAAC,mBAAmB,CAAC;;;;iDAkB7E;AAMD;IAJC,iBAAiB,CAChB,oBAAoB,CAAC,mBAAmB,EACxC,SAAS,CAAC,gCAAgC,CAC3C;;;;8DAkBA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Interface for the authorization module.
3
+ */
4
+ export interface IReportingModuleApi {
5
+ }
@@ -0,0 +1,5 @@
1
+ // SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ export {};
5
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/module/interface.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,sCAAsC"}
@@ -0,0 +1,78 @@
1
+ import type { BootstrapConfig, CallAction, HandlerProperties, ICache, IMessage, IMessageHandler, IMessageSender, SystemConfig } from '@citrineos/base';
2
+ import { AbstractModule, OCPP1_6, OCPP2_0_1, OCPPValidator } from '@citrineos/base';
3
+ import type { IDeviceModelRepository, IOCPPMessageRepository, ISecurityEventRepository, IVariableMonitoringRepository } from '@citrineos/data';
4
+ import type { ILogObj } from 'tslog';
5
+ import { Logger } from 'tslog';
6
+ import { DeviceModelService } from './services.js';
7
+ /**
8
+ * Component that handles provisioning related messages.
9
+ */
10
+ export declare class ReportingModule extends AbstractModule {
11
+ /**
12
+ * Get Base Report variables. While NotifyReport requests correlated with a GetBaseReport's requestId
13
+ * are still being sent, cache value is 'ongoing'. Once a NotifyReport with tbc === false (or undefined)
14
+ * is received, cache value is 'complete'.
15
+ */
16
+ static readonly GET_BASE_REPORT_REQUEST_ID_MAX = 10000000;
17
+ static readonly GET_BASE_REPORT_ONGOING_CACHE_VALUE = "ongoing";
18
+ static readonly GET_BASE_REPORT_COMPLETE_CACHE_VALUE = "complete";
19
+ _deviceModelService: DeviceModelService;
20
+ /**
21
+ * Fields
22
+ */
23
+ _requests: CallAction[];
24
+ _responses: CallAction[];
25
+ protected _securityEventRepository: ISecurityEventRepository;
26
+ protected _variableMonitoringRepository: IVariableMonitoringRepository;
27
+ protected _ocppMessageRepository: IOCPPMessageRepository;
28
+ /**
29
+ * This is the constructor function that initializes the {@link ReportingModule}.
30
+ *
31
+ * @param {BootstrapConfig & SystemConfig} config - The `config` contains configuration settings for the module.
32
+ *
33
+ * @param {ICache} [cache] - The cache instance which is shared among the modules & Central System to pass information such as blacklisted actions or boot status.
34
+ *
35
+ * @param {IMessageSender} [sender] - The `sender` parameter is an optional parameter that represents an instance of the {@link IMessageSender} interface.
36
+ * It is used to send messages from the central system to external systems or devices. If no `sender` is provided, a default {@link RabbitMqSender} instance is created and used.
37
+ *
38
+ * @param {IMessageHandler} [handler] - The `handler` parameter is an optional parameter that represents an instance of the {@link IMessageHandler} interface.
39
+ * It is used to handle incoming messages and dispatch them to the appropriate methods or functions. If no `handler` is provided, a default {@link RabbitMqReceiver} instance is created and used.
40
+ *
41
+ * @param {Logger<ILogObj>} [logger] - The `logger` parameter is an optional parameter that represents an instance of {@link Logger<ILogObj>}.
42
+ * It is used to propagate system wide logger settings and will serve as the parent logger for any sub-component logging. If no `logger` is provided, a default {@link Logger<ILogObj>} instance is created and used.
43
+ *
44
+ * @param {IDeviceModelRepository} [deviceModelRepository] - An optional parameter of type {@link IDeviceModelRepository} which represents a repository for accessing and manipulating variable data.
45
+ * If no `deviceModelRepository` is provided, a default {@link sequelize:deviceModelRepository} instance is created and used.
46
+ *
47
+ * @param {ISecurityEventRepository} [securityEventRepository] - An optional parameter of type {@link ISecurityEventRepository} which represents a repository for accessing security event notification data.
48
+ *
49
+ * @param {IVariableMonitoringRepository} [variableMonitoringRepository] - An optional parameter of type {@link IVariableMonitoringRepository} which represents a repository for accessing and manipulating monitoring data.
50
+ */
51
+ constructor(config: BootstrapConfig & SystemConfig, cache: ICache, sender?: IMessageSender, handler?: IMessageHandler, logger?: Logger<ILogObj>, ocppValidator?: OCPPValidator, deviceModelRepository?: IDeviceModelRepository, securityEventRepository?: ISecurityEventRepository, variableMonitoringRepository?: IVariableMonitoringRepository, ocppMessageRepository?: IOCPPMessageRepository);
52
+ /**
53
+ * Constructor
54
+ */
55
+ protected _deviceModelRepository: IDeviceModelRepository;
56
+ get deviceModelRepository(): IDeviceModelRepository;
57
+ /**
58
+ * Handle Requests
59
+ */
60
+ protected _handleLogStatusNotification(message: IMessage<OCPP2_0_1.LogStatusNotificationRequest>, props?: HandlerProperties): Promise<void>;
61
+ protected _handleNotifyCustomerInformation(message: IMessage<OCPP2_0_1.NotifyCustomerInformationRequest>, props?: HandlerProperties): Promise<void>;
62
+ protected _handleNotifyMonitoringReport(message: IMessage<OCPP2_0_1.NotifyMonitoringReportRequest>, props?: HandlerProperties): Promise<void>;
63
+ protected _handleNotifyReport(message: IMessage<OCPP2_0_1.NotifyReportRequest>, props?: HandlerProperties): Promise<void>;
64
+ protected _handleSecurityEventNotification(message: IMessage<OCPP2_0_1.SecurityEventNotificationRequest>, props?: HandlerProperties): Promise<void>;
65
+ /**
66
+ * Handle responses
67
+ */
68
+ protected _handleGetBaseReport(message: IMessage<OCPP2_0_1.GetBaseReportResponse>, props?: HandlerProperties): void;
69
+ protected _handleGetReport(message: IMessage<OCPP2_0_1.GetReportResponse>, props?: HandlerProperties): void;
70
+ protected _handleGetMonitoringReport(message: IMessage<OCPP2_0_1.GetMonitoringReportResponse>, props?: HandlerProperties): Promise<void>;
71
+ protected _handleGetLog(message: IMessage<OCPP2_0_1.GetLogResponse>, props?: HandlerProperties): void;
72
+ protected _handleCustomerInformation(message: IMessage<OCPP2_0_1.CustomerInformationResponse>, props?: HandlerProperties): void;
73
+ /**
74
+ * OCPP 1.6 Handlers
75
+ */
76
+ protected _handleDiagnosticsStatusNotification(message: IMessage<OCPP1_6.DiagnosticsStatusNotificationRequest>, props?: HandlerProperties): Promise<void>;
77
+ protected _handleGetDiagnostics(message: IMessage<OCPP1_6.GetDiagnosticsResponse>, props?: HandlerProperties): void;
78
+ }
@@ -0,0 +1,308 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { AbstractModule, AsHandler, ErrorCode, EventGroup, Namespace, OCPP1_6, OCPP1_6_CallAction, OCPP2_0_1, OCPP2_0_1_CallAction, OcppError, OCPPValidator, OCPPVersion, } from '@citrineos/base';
11
+ import { Component, sequelize, Variable } from '@citrineos/data';
12
+ import { RabbitMqReceiver, RabbitMqSender } from '@citrineos/util';
13
+ import { Logger } from 'tslog';
14
+ import { DeviceModelService } from './services.js';
15
+ /**
16
+ * Component that handles provisioning related messages.
17
+ */
18
+ export class ReportingModule extends AbstractModule {
19
+ /**
20
+ * Get Base Report variables. While NotifyReport requests correlated with a GetBaseReport's requestId
21
+ * are still being sent, cache value is 'ongoing'. Once a NotifyReport with tbc === false (or undefined)
22
+ * is received, cache value is 'complete'.
23
+ */
24
+ static GET_BASE_REPORT_REQUEST_ID_MAX = 10000000; // 10,000,000
25
+ static GET_BASE_REPORT_ONGOING_CACHE_VALUE = 'ongoing';
26
+ static GET_BASE_REPORT_COMPLETE_CACHE_VALUE = 'complete';
27
+ _deviceModelService;
28
+ /**
29
+ * Fields
30
+ */
31
+ _requests = [];
32
+ _responses = [];
33
+ _securityEventRepository;
34
+ _variableMonitoringRepository;
35
+ _ocppMessageRepository;
36
+ /**
37
+ * This is the constructor function that initializes the {@link ReportingModule}.
38
+ *
39
+ * @param {BootstrapConfig & SystemConfig} config - The `config` contains configuration settings for the module.
40
+ *
41
+ * @param {ICache} [cache] - The cache instance which is shared among the modules & Central System to pass information such as blacklisted actions or boot status.
42
+ *
43
+ * @param {IMessageSender} [sender] - The `sender` parameter is an optional parameter that represents an instance of the {@link IMessageSender} interface.
44
+ * It is used to send messages from the central system to external systems or devices. If no `sender` is provided, a default {@link RabbitMqSender} instance is created and used.
45
+ *
46
+ * @param {IMessageHandler} [handler] - The `handler` parameter is an optional parameter that represents an instance of the {@link IMessageHandler} interface.
47
+ * It is used to handle incoming messages and dispatch them to the appropriate methods or functions. If no `handler` is provided, a default {@link RabbitMqReceiver} instance is created and used.
48
+ *
49
+ * @param {Logger<ILogObj>} [logger] - The `logger` parameter is an optional parameter that represents an instance of {@link Logger<ILogObj>}.
50
+ * It is used to propagate system wide logger settings and will serve as the parent logger for any sub-component logging. If no `logger` is provided, a default {@link Logger<ILogObj>} instance is created and used.
51
+ *
52
+ * @param {IDeviceModelRepository} [deviceModelRepository] - An optional parameter of type {@link IDeviceModelRepository} which represents a repository for accessing and manipulating variable data.
53
+ * If no `deviceModelRepository` is provided, a default {@link sequelize:deviceModelRepository} instance is created and used.
54
+ *
55
+ * @param {ISecurityEventRepository} [securityEventRepository] - An optional parameter of type {@link ISecurityEventRepository} which represents a repository for accessing security event notification data.
56
+ *
57
+ * @param {IVariableMonitoringRepository} [variableMonitoringRepository] - An optional parameter of type {@link IVariableMonitoringRepository} which represents a repository for accessing and manipulating monitoring data.
58
+ */
59
+ constructor(config, cache, sender, handler, logger, ocppValidator, deviceModelRepository, securityEventRepository, variableMonitoringRepository, ocppMessageRepository) {
60
+ super(config, cache, handler || new RabbitMqReceiver(config, logger), sender || new RabbitMqSender(config, logger), EventGroup.Reporting, logger, ocppValidator);
61
+ this._requests = config.modules.reporting.requests;
62
+ this._responses = config.modules.reporting.responses;
63
+ this._deviceModelRepository =
64
+ deviceModelRepository || new sequelize.SequelizeDeviceModelRepository(config, this._logger);
65
+ this._securityEventRepository =
66
+ securityEventRepository ||
67
+ new sequelize.SequelizeSecurityEventRepository(config, this._logger);
68
+ this._variableMonitoringRepository =
69
+ variableMonitoringRepository ||
70
+ new sequelize.SequelizeVariableMonitoringRepository(config, this._logger);
71
+ this._ocppMessageRepository =
72
+ ocppMessageRepository || new sequelize.SequelizeOCPPMessageRepository(config, this._logger);
73
+ this._deviceModelService = new DeviceModelService(this._deviceModelRepository);
74
+ }
75
+ /**
76
+ * Constructor
77
+ */
78
+ _deviceModelRepository;
79
+ get deviceModelRepository() {
80
+ return this._deviceModelRepository;
81
+ }
82
+ /**
83
+ * Handle Requests
84
+ */
85
+ async _handleLogStatusNotification(message, props) {
86
+ this._logger.debug('LogStatusNotification received:', message, props);
87
+ // TODO: LogStatusNotification is usually triggered. Ideally, it should be sent to the callbackUrl from the message api that sent the trigger message
88
+ // Validate requestId requirement
89
+ // requestId is mandatory unless message was triggered by TriggerMessageRequest AND no log upload ongoing
90
+ if (!message.payload.requestId) {
91
+ await this.sendCallErrorWithMessage(message, new OcppError(message.context.correlationId, ErrorCode.OccurrenceConstraintViolation, 'RequestId is required.'));
92
+ return;
93
+ }
94
+ // Create response
95
+ const response = {};
96
+ const messageConfirmation = await this.sendCallResultWithMessage(message, response);
97
+ this._logger.debug('LogStatusNotification response sent: ', messageConfirmation);
98
+ }
99
+ async _handleNotifyCustomerInformation(message, props) {
100
+ this._logger.debug('NotifyCustomerInformation request received:', message, props);
101
+ // Validate requestId was provided in a previous CustomerInformationRequest
102
+ const requestId = message.payload.requestId;
103
+ const previousRequest = await this._ocppMessageRepository.readAllByQuery(message.context.tenantId, {
104
+ where: {
105
+ tenantId: message.context.tenantId,
106
+ stationId: message.context.stationId,
107
+ action: OCPP2_0_1_CallAction.CustomerInformation,
108
+ message: {
109
+ requestId: requestId,
110
+ },
111
+ },
112
+ limit: 1,
113
+ }, Namespace.OCPPMessage);
114
+ if (!previousRequest || previousRequest.length === 0) {
115
+ await this.sendCallErrorWithMessage(message, new OcppError(message.context.correlationId, ErrorCode.PropertyConstraintViolation, 'RequestId was not provided in a CustomerInformationRequest.'));
116
+ return;
117
+ }
118
+ // Create response
119
+ const response = {};
120
+ const messageConfirmation = await this.sendCallResultWithMessage(message, response);
121
+ this._logger.debug('NotifyCustomerInformation response sent: ', messageConfirmation);
122
+ }
123
+ async _handleNotifyMonitoringReport(message, props) {
124
+ this._logger.debug('NotifyMonitoringReport request received:', message, props);
125
+ for (const monitorType of message.payload.monitor ? message.payload.monitor : []) {
126
+ const stationId = message.context.stationId;
127
+ const [component, variable] = await this._deviceModelRepository.findOrCreateEvseAndComponentAndVariable(message.context.tenantId, monitorType.component, monitorType.variable);
128
+ await this._variableMonitoringRepository.createOrUpdateByMonitoringDataTypeAndStationId(message.context.tenantId, monitorType, component ? component.id : null, variable ? variable.id : null, stationId);
129
+ }
130
+ // Create response
131
+ const response = {};
132
+ const messageConfirmation = await this.sendCallResultWithMessage(message, response);
133
+ this._logger.debug('NotifyMonitoringReport response sent: ', messageConfirmation);
134
+ }
135
+ async _handleNotifyReport(message, props) {
136
+ this._logger.info('NotifyReport received:', message, props);
137
+ const timestamp = message.payload.generatedAt;
138
+ try {
139
+ for (const reportDataType of message.payload.reportData ? message.payload.reportData : []) {
140
+ // To keep consistency with VariableAttributeType defined in OCPP 2.0.1:
141
+ // mutability: Default is ReadWrite when omitted.
142
+ // if it is not present, we set it to ReadWrite
143
+ for (const variableAttr of reportDataType.variableAttribute) {
144
+ if (!variableAttr.mutability) {
145
+ variableAttr.mutability = OCPP2_0_1.MutabilityEnumType.ReadWrite;
146
+ }
147
+ }
148
+ const variableAttributes = await this._deviceModelRepository.createOrUpdateDeviceModelByStationId(message.context.tenantId, reportDataType, message.context.stationId, timestamp);
149
+ for (const variableAttribute of variableAttributes) {
150
+ // Reload is necessary because in createOrUpdateDeviceModelByStationId does not do eager loading
151
+ await variableAttribute.reload({
152
+ include: [Component, Variable],
153
+ });
154
+ await this._deviceModelRepository.updateResultByStationId(message.context.tenantId, {
155
+ attributeType: variableAttribute.type,
156
+ attributeStatus: OCPP2_0_1.SetVariableStatusEnumType.Accepted,
157
+ attributeStatusInfo: { reasonCode: message.action },
158
+ component: variableAttribute.component,
159
+ variable: variableAttribute.variable,
160
+ }, message.context.stationId, timestamp);
161
+ }
162
+ }
163
+ }
164
+ catch (error) {
165
+ if (error.name === 'SequelizeForeignKeyConstraintError') {
166
+ await this.sendCallErrorWithMessage(message, new OcppError(message.context.correlationId, ErrorCode.PropertyConstraintViolation, 'Referenced entity does not exist.'));
167
+ return;
168
+ }
169
+ throw error;
170
+ }
171
+ if (!message.payload.tbc) {
172
+ // Default if omitted is false
173
+ const success = await this._cache.set(message.payload.requestId.toString(), ReportingModule.GET_BASE_REPORT_COMPLETE_CACHE_VALUE, message.context.stationId);
174
+ this._logger.info('Completed', success, message.payload.requestId);
175
+ }
176
+ else {
177
+ // tbc (to be continued) is true
178
+ // Continue to set get base report ongoing. Will extend the timeout.
179
+ const success = await this._cache.set(message.payload.requestId.toString(), ReportingModule.GET_BASE_REPORT_ONGOING_CACHE_VALUE, message.context.stationId, this.config.maxCachingSeconds);
180
+ this._logger.info('Ongoing', success, message.payload.requestId);
181
+ }
182
+ // Create response
183
+ const response = {};
184
+ await this.sendCallResultWithMessage(message, response);
185
+ this._logger.debug('NotifyReport response sent:', message, props);
186
+ }
187
+ async _handleSecurityEventNotification(message, props) {
188
+ this._logger.debug('SecurityEventNotification request received:', message, props);
189
+ await this._securityEventRepository.createByStationId(message.context.tenantId, message.payload, message.context.stationId);
190
+ await this.sendCallResultWithMessage(message, {});
191
+ }
192
+ /**
193
+ * Handle responses
194
+ */
195
+ _handleGetBaseReport(message, props) {
196
+ this._logger.debug('GetBaseReport response received:', message, props);
197
+ }
198
+ _handleGetReport(message, props) {
199
+ this._logger.debug('GetReport response received:', message, props);
200
+ const status = message.payload.status;
201
+ const statusInfo = message.payload.statusInfo;
202
+ if (status === OCPP2_0_1.GenericDeviceModelStatusEnumType.Rejected ||
203
+ status === OCPP2_0_1.GenericDeviceModelStatusEnumType.NotSupported) {
204
+ this._logger.error('Failed to get report.', status, statusInfo?.reasonCode, statusInfo?.additionalInfo);
205
+ }
206
+ }
207
+ async _handleGetMonitoringReport(message, props) {
208
+ this._logger.debug('GetMonitoringReport response received:', message, props);
209
+ const status = message.payload.status;
210
+ const statusInfo = message.payload.statusInfo;
211
+ if (status === OCPP2_0_1.GenericDeviceModelStatusEnumType.Rejected ||
212
+ status === OCPP2_0_1.GenericDeviceModelStatusEnumType.NotSupported) {
213
+ this._logger.error('Failed to get monitoring report.', status, statusInfo?.reasonCode, statusInfo?.additionalInfo);
214
+ }
215
+ }
216
+ _handleGetLog(message, props) {
217
+ this._logger.debug('GetLog response received:', message, props);
218
+ }
219
+ _handleCustomerInformation(message, props) {
220
+ this._logger.debug('CustomerInformation response received:', message, props);
221
+ }
222
+ /**
223
+ * OCPP 1.6 Handlers
224
+ */
225
+ async _handleDiagnosticsStatusNotification(message, props) {
226
+ this._logger.debug('DiagnosticsStatusNotification received:', message, props);
227
+ // Create response
228
+ const response = {};
229
+ const messageConfirmation = await this.sendCallResultWithMessage(message, response);
230
+ this._logger.debug('DiagnosticsStatusNotification response sent: ', messageConfirmation);
231
+ }
232
+ _handleGetDiagnostics(message, props) {
233
+ this._logger.debug('GetDiagnostics response received:', message, props);
234
+ }
235
+ }
236
+ __decorate([
237
+ AsHandler(OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.LogStatusNotification),
238
+ __metadata("design:type", Function),
239
+ __metadata("design:paramtypes", [Object, Object]),
240
+ __metadata("design:returntype", Promise)
241
+ ], ReportingModule.prototype, "_handleLogStatusNotification", null);
242
+ __decorate([
243
+ AsHandler(OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.NotifyCustomerInformation),
244
+ __metadata("design:type", Function),
245
+ __metadata("design:paramtypes", [Object, Object]),
246
+ __metadata("design:returntype", Promise)
247
+ ], ReportingModule.prototype, "_handleNotifyCustomerInformation", null);
248
+ __decorate([
249
+ AsHandler(OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.NotifyMonitoringReport),
250
+ __metadata("design:type", Function),
251
+ __metadata("design:paramtypes", [Object, Object]),
252
+ __metadata("design:returntype", Promise)
253
+ ], ReportingModule.prototype, "_handleNotifyMonitoringReport", null);
254
+ __decorate([
255
+ AsHandler(OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.NotifyReport),
256
+ __metadata("design:type", Function),
257
+ __metadata("design:paramtypes", [Object, Object]),
258
+ __metadata("design:returntype", Promise)
259
+ ], ReportingModule.prototype, "_handleNotifyReport", null);
260
+ __decorate([
261
+ AsHandler(OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.SecurityEventNotification),
262
+ __metadata("design:type", Function),
263
+ __metadata("design:paramtypes", [Object, Object]),
264
+ __metadata("design:returntype", Promise)
265
+ ], ReportingModule.prototype, "_handleSecurityEventNotification", null);
266
+ __decorate([
267
+ AsHandler(OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.GetBaseReport),
268
+ __metadata("design:type", Function),
269
+ __metadata("design:paramtypes", [Object, Object]),
270
+ __metadata("design:returntype", void 0)
271
+ ], ReportingModule.prototype, "_handleGetBaseReport", null);
272
+ __decorate([
273
+ AsHandler(OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.GetReport),
274
+ __metadata("design:type", Function),
275
+ __metadata("design:paramtypes", [Object, Object]),
276
+ __metadata("design:returntype", void 0)
277
+ ], ReportingModule.prototype, "_handleGetReport", null);
278
+ __decorate([
279
+ AsHandler(OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.GetMonitoringReport),
280
+ __metadata("design:type", Function),
281
+ __metadata("design:paramtypes", [Object, Object]),
282
+ __metadata("design:returntype", Promise)
283
+ ], ReportingModule.prototype, "_handleGetMonitoringReport", null);
284
+ __decorate([
285
+ AsHandler(OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.GetLog),
286
+ __metadata("design:type", Function),
287
+ __metadata("design:paramtypes", [Object, Object]),
288
+ __metadata("design:returntype", void 0)
289
+ ], ReportingModule.prototype, "_handleGetLog", null);
290
+ __decorate([
291
+ AsHandler(OCPPVersion.OCPP2_0_1, OCPP2_0_1_CallAction.CustomerInformation),
292
+ __metadata("design:type", Function),
293
+ __metadata("design:paramtypes", [Object, Object]),
294
+ __metadata("design:returntype", void 0)
295
+ ], ReportingModule.prototype, "_handleCustomerInformation", null);
296
+ __decorate([
297
+ AsHandler(OCPPVersion.OCPP1_6, OCPP1_6_CallAction.DiagnosticsStatusNotification),
298
+ __metadata("design:type", Function),
299
+ __metadata("design:paramtypes", [Object, Object]),
300
+ __metadata("design:returntype", Promise)
301
+ ], ReportingModule.prototype, "_handleDiagnosticsStatusNotification", null);
302
+ __decorate([
303
+ AsHandler(OCPPVersion.OCPP1_6, OCPP1_6_CallAction.GetDiagnostics),
304
+ __metadata("design:type", Function),
305
+ __metadata("design:paramtypes", [Object, Object]),
306
+ __metadata("design:returntype", void 0)
307
+ ], ReportingModule.prototype, "_handleGetDiagnostics", null);
308
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/module/module.ts"],"names":[],"mappings":";;;;;;;;;AAaA,OAAO,EACL,cAAc,EACd,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,OAAO,EACP,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,aAAa,EACb,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,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;AAGe;IADf,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,oBAAoB,CAAC,YAAY,CAAC;;;;0DAoFnE;AAGe;IADf,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,oBAAoB,CAAC,yBAAyB,CAAC;;;;uEAehF;AAOS;IADT,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,oBAAoB,CAAC,aAAa,CAAC;;;;2DAMpE;AAGS;IADT,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,oBAAoB,CAAC,SAAS,CAAC;;;;uDAoBhE;AAGe;IADf,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,oBAAoB,CAAC,mBAAmB,CAAC;;;;iEAoB1E;AAGS;IADT,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,oBAAoB,CAAC,MAAM,CAAC;;;;oDAM7D;AAGS;IADT,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,oBAAoB,CAAC,mBAAmB,CAAC;;;;iEAM1E;AAOe;IADf,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,kBAAkB,CAAC,6BAA6B,CAAC;;;;2EAYhF;AAGS;IADT,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,kBAAkB,CAAC,cAAc,CAAC;;;;4DAMjE"}
@@ -0,0 +1,23 @@
1
+ import type { IDeviceModelRepository } from '@citrineos/data';
2
+ export declare class DeviceModelService {
3
+ protected _deviceModelRepository: IDeviceModelRepository;
4
+ constructor(deviceModelRepository: IDeviceModelRepository);
5
+ /**
6
+ * Fetches the ItemsPerMessage attribute from the device model.
7
+ * Returns null if no such attribute exists.
8
+ * @param stationId Charging station identifier.
9
+ * @returns ItemsPerMessage as a number or null if no such attribute exists.
10
+ */
11
+ getItemsPerMessageByComponentAndVariableInstanceAndStationId(componentName: string, variableInstance: string, tenantId: number, stationId: string): Promise<number | null>;
12
+ /**
13
+ * Fetches the BytesPerMessage attribute from the device model.
14
+ * Returns null if no such attribute exists.
15
+ * It is possible for there to be multiple BytesPerMessage attributes if component instances or evses
16
+ * are associated with alternate options. That structure is not supported by this logic, and that
17
+ * structure is a violation of Part 2 - Specification of OCPP 2.0.1.
18
+ * In that case, the first attribute will be returned.
19
+ * @param stationId Charging station identifier.
20
+ * @returns BytesPerMessage as a number or null if no such attribute exists.
21
+ */
22
+ getBytesPerMessageByComponentAndVariableInstanceAndStationId(componentName: string, variableInstance: string, tenantId: number, stationId: string): Promise<number | null>;
23
+ }
@@ -0,0 +1,63 @@
1
+ import { VariableAttribute } from '@citrineos/data';
2
+ import { OCPP2_0_1 } from '@citrineos/base';
3
+ export class DeviceModelService {
4
+ _deviceModelRepository;
5
+ constructor(deviceModelRepository) {
6
+ this._deviceModelRepository = deviceModelRepository;
7
+ }
8
+ /**
9
+ * Fetches the ItemsPerMessage attribute from the device model.
10
+ * Returns null if no such attribute exists.
11
+ * @param stationId Charging station identifier.
12
+ * @returns ItemsPerMessage as a number or null if no such attribute exists.
13
+ */
14
+ async getItemsPerMessageByComponentAndVariableInstanceAndStationId(componentName, variableInstance, tenantId, stationId) {
15
+ const itemsPerMessageAttributes = await this._deviceModelRepository.readAllByQuerystring(tenantId, {
16
+ tenantId: tenantId,
17
+ stationId: stationId,
18
+ component_name: componentName,
19
+ variable_name: 'ItemsPerMessage',
20
+ variable_instance: variableInstance,
21
+ type: OCPP2_0_1.AttributeEnumType.Actual,
22
+ });
23
+ if (itemsPerMessageAttributes.length === 0) {
24
+ return null;
25
+ }
26
+ else {
27
+ // It is possible for itemsPerMessageAttributes.length > 1 if component instances or evses
28
+ // are associated with alternate options. That structure is not supported by this logic, and that
29
+ // structure is a violation of Part 2 - Specification of OCPP 2.0.1.
30
+ return Number(itemsPerMessageAttributes[0].value);
31
+ }
32
+ }
33
+ /**
34
+ * Fetches the BytesPerMessage attribute from the device model.
35
+ * Returns null if no such attribute exists.
36
+ * It is possible for there to be multiple BytesPerMessage attributes if component instances or evses
37
+ * are associated with alternate options. That structure is not supported by this logic, and that
38
+ * structure is a violation of Part 2 - Specification of OCPP 2.0.1.
39
+ * In that case, the first attribute will be returned.
40
+ * @param stationId Charging station identifier.
41
+ * @returns BytesPerMessage as a number or null if no such attribute exists.
42
+ */
43
+ async getBytesPerMessageByComponentAndVariableInstanceAndStationId(componentName, variableInstance, tenantId, stationId) {
44
+ const bytesPerMessageAttributes = await this._deviceModelRepository.readAllByQuerystring(tenantId, {
45
+ tenantId: tenantId,
46
+ stationId: stationId,
47
+ component_name: componentName,
48
+ variable_name: 'BytesPerMessage',
49
+ variable_instance: variableInstance,
50
+ type: OCPP2_0_1.AttributeEnumType.Actual,
51
+ });
52
+ if (bytesPerMessageAttributes.length === 0) {
53
+ return null;
54
+ }
55
+ else {
56
+ // It is possible for bytesPerMessageAttributes.length > 1 if component instances or evses
57
+ // are associated with alternate options. That structure is not supported by this logic, and that
58
+ // structure is a violation of Part 2 - Specification of OCPP 2.0.1.
59
+ return Number(bytesPerMessageAttributes[0].value);
60
+ }
61
+ }
62
+ }
63
+ //# sourceMappingURL=services.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.js","sourceRoot":"","sources":["../../src/module/services.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,kBAAkB;IACnB,sBAAsB,CAAyB;IAEzD,YAAY,qBAA6C;QACvD,IAAI,CAAC,sBAAsB,GAAG,qBAAqB,CAAC;IACtD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,4DAA4D,CAChE,aAAqB,EACrB,gBAAwB,EACxB,QAAgB,EAChB,SAAiB;QAEjB,MAAM,yBAAyB,GAC7B,MAAM,IAAI,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,QAAQ,EAAE;YAC/D,QAAQ,EAAE,QAAQ;YAClB,SAAS,EAAE,SAAS;YACpB,cAAc,EAAE,aAAa;YAC7B,aAAa,EAAE,iBAAiB;YAChC,iBAAiB,EAAE,gBAAgB;YACnC,IAAI,EAAE,SAAS,CAAC,iBAAiB,CAAC,MAAM;SACzC,CAAC,CAAC;QACL,IAAI,yBAAyB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,0FAA0F;YAC1F,iGAAiG;YACjG,oEAAoE;YACpE,OAAO,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,4DAA4D,CAChE,aAAqB,EACrB,gBAAwB,EACxB,QAAgB,EAChB,SAAiB;QAEjB,MAAM,yBAAyB,GAC7B,MAAM,IAAI,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,QAAQ,EAAE;YAC/D,QAAQ,EAAE,QAAQ;YAClB,SAAS,EAAE,SAAS;YACpB,cAAc,EAAE,aAAa;YAC7B,aAAa,EAAE,iBAAiB;YAChC,iBAAiB,EAAE,gBAAgB;YACnC,IAAI,EAAE,SAAS,CAAC,iBAAiB,CAAC,MAAM;SACzC,CAAC,CAAC;QACL,IAAI,yBAAyB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,0FAA0F;YAC1F,iGAAiG;YACjG,oEAAoE;YACpE,OAAO,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@zetra/citrineos-reporting",
3
+ "version": "1.8.3-fork.1",
4
+ "type": "module",
5
+ "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.",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "prepublish": "npx eslint",
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "keywords": [
16
+ "ocpp",
17
+ "ocpp_v201"
18
+ ],
19
+ "license": "Apache-2.0",
20
+ "dependencies": {
21
+ "@zetra/citrineos-base": "1.8.3-fork.1",
22
+ "@zetra/citrineos-data": "1.8.3-fork.1",
23
+ "@zetra/citrineos-util": "1.8.3-fork.1"
24
+ }
25
+ }