ocpp-ws-io 2.2.1 → 2.2.2

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,169 @@
1
+ import { a0 as ServerOptions, Y as RouterConfig, a as OCPPServerClient, o as CORSOptions, M as MiddlewareFunction, O as OCPPServer, b as OCPPServerStats, c as OCPPProtocol, A as AllMethodNames, d as OCPPRequestType, C as CallOptions, e as OCPPResponseType, f as CloseOptions } from './types-xFfIgIuS.mjs';
2
+ import { IncomingMessage } from 'node:http';
3
+ import { Type, DynamicModule, ForwardReference, OnModuleInit, OnModuleDestroy, NestMiddleware } from '@nestjs/common';
4
+ import { HttpAdapterHost, DiscoveryService, MetadataScanner } from '@nestjs/core';
5
+ import 'ws';
6
+ import 'node:https';
7
+ import 'node:events';
8
+ import 'node:stream';
9
+ import 'node:tls';
10
+ import 'voltlog-io';
11
+ import 'ajv';
12
+
13
+ declare const OCPP_GATEWAY_METADATA = "ocpp:gateway";
14
+ declare const OCPP_MESSAGE_EVENT_METADATA = "ocpp:message_event";
15
+ declare const OCPP_WILDCARD_EVENT_METADATA = "ocpp:wildcard_event";
16
+ declare const OCPP_AUTH_METADATA = "ocpp:auth";
17
+ declare const OCPP_CONNECTION_MIDDLEWARE_METADATA = "ocpp:connection_middleware";
18
+ declare const OCPP_RPC_MIDDLEWARE_METADATA = "ocpp:rpc_middleware";
19
+ declare const OCPP_CORS_METADATA = "ocpp:cors";
20
+ declare const PARAM_ARGS_METADATA = "ocpp:params_args";
21
+ declare const OCPP_SERVER_OPTIONS = "OCPP_SERVER_OPTIONS";
22
+ declare const OCPP_SERVER_INSTANCE = "OCPP_SERVER_INSTANCE";
23
+
24
+ interface OcppGatewayOptions extends RouterConfig {
25
+ path?: string;
26
+ }
27
+ interface OcppNestOptions {
28
+ /**
29
+ * Automatically attach the OCPP upgrade handler to Nest's HTTP server.
30
+ * Defaults to true.
31
+ */
32
+ autoAttach?: boolean;
33
+ /**
34
+ * Only pass matching upgrade requests to OCPP. This is useful when the same
35
+ * Nest app also owns Socket.IO or other WebSocket gateways.
36
+ */
37
+ upgradePathPrefix?: string | string[];
38
+ /**
39
+ * Advanced upgrade filter. Return true to let OCPP handle the request.
40
+ */
41
+ upgradeFilter?: (pathname: string, req: IncomingMessage) => boolean;
42
+ }
43
+ type OcppModuleOptions = ServerOptions & OcppNestOptions;
44
+ interface OcppOptionsFactory {
45
+ createOcppOptions(): Promise<OcppModuleOptions> | OcppModuleOptions;
46
+ }
47
+ interface OcppModuleAsyncOptions {
48
+ imports?: Array<Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference>;
49
+ inject?: any[];
50
+ useFactory?: (...args: any[]) => Promise<OcppModuleOptions> | OcppModuleOptions;
51
+ useClass?: Type<OcppOptionsFactory>;
52
+ useExisting?: Type<OcppOptionsFactory>;
53
+ }
54
+ interface OnOcppClientConnected {
55
+ onOcppClientConnected(client: OCPPServerClient): void | Promise<void>;
56
+ }
57
+ interface OnOcppClientDisconnected {
58
+ onOcppClientDisconnected(client: OCPPServerClient, code: number, reason: string): void | Promise<void>;
59
+ }
60
+ interface OnOcppClientError {
61
+ onOcppClientError(client: OCPPServerClient, error: Error): void | Promise<void>;
62
+ }
63
+ declare enum OcppParamType {
64
+ CLIENT = 0,
65
+ MESSAGE = 1,
66
+ PARAMS = 2,
67
+ CONTEXT = 3,
68
+ IDENTITY = 4,
69
+ PATH = 5,
70
+ SESSION = 6,
71
+ PATH_PARAMS = 7,
72
+ PROTOCOL = 8,
73
+ MESSAGE_ID = 9,
74
+ HANDSHAKE = 10
75
+ }
76
+ interface OcppParamMetadata {
77
+ type: OcppParamType;
78
+ data?: string;
79
+ }
80
+
81
+ declare const OcppGateway: (pathOrOptions?: string | OcppGatewayOptions) => ClassDecorator;
82
+ declare const OcppCors: (options: CORSOptions) => ClassDecorator;
83
+ declare const UseOcppRpcMiddleware: (...middlewares: MiddlewareFunction<any>[]) => ClassDecorator;
84
+
85
+ interface OcppMessageEventMetadata {
86
+ action: string;
87
+ protocol?: string;
88
+ }
89
+ declare const OcppMessageEvent: (action: string, protocol?: string) => MethodDecorator;
90
+ declare const OcppWildcardEvent: () => MethodDecorator;
91
+ declare const OcppAuth: () => MethodDecorator;
92
+ declare const OcppConnectionMiddleware: () => MethodDecorator;
93
+
94
+ declare const Client: () => ParameterDecorator;
95
+ declare const Message: () => ParameterDecorator;
96
+ declare const Params: () => ParameterDecorator;
97
+ declare const Context: () => ParameterDecorator;
98
+ declare const Identity: () => ParameterDecorator;
99
+ declare const Path: () => ParameterDecorator;
100
+ declare const Session: () => ParameterDecorator;
101
+ declare const PathParam: (name?: string) => ParameterDecorator;
102
+ declare const Protocol: () => ParameterDecorator;
103
+ declare const MessageId: () => ParameterDecorator;
104
+ declare const Handshake: () => ParameterDecorator;
105
+
106
+ declare class OcppService implements OnModuleInit, OnModuleDestroy {
107
+ private readonly ocppServer;
108
+ private readonly options;
109
+ private readonly httpAdapterHost?;
110
+ private attachedHttpServer?;
111
+ private readonly gatewayPatterns;
112
+ private acceptAllUpgrades;
113
+ private readonly upgradeHandler;
114
+ constructor(ocppServer: OCPPServer, options?: OcppModuleOptions, httpAdapterHost?: HttpAdapterHost | undefined);
115
+ onModuleInit(): void;
116
+ onModuleDestroy(): Promise<void>;
117
+ get server(): OCPPServer;
118
+ get clients(): ReadonlySet<OCPPServerClient>;
119
+ stats(): OCPPServerStats;
120
+ getClient(identity: string): OCPPServerClient | undefined;
121
+ getLocalClient(identity: string): OCPPServerClient | undefined;
122
+ hasLocalClient(identity: string): boolean;
123
+ hasClient(identity: string): Promise<boolean>;
124
+ sendToClient<V extends OCPPProtocol, M extends AllMethodNames<V>>(identity: string, version: V, method: M, params: OCPPRequestType<V, M>, options?: CallOptions): Promise<OCPPResponseType<V, M> | undefined>;
125
+ sendToClient<M extends AllMethodNames<any>>(identity: string, method: M, params: OCPPRequestType<any, M>, options?: CallOptions): Promise<OCPPResponseType<any, M> | undefined>;
126
+ sendToClient<TResult = any>(identity: string, method: string, params: Record<string, any>, options?: CallOptions): Promise<TResult | undefined>;
127
+ safeSendToClient<V extends OCPPProtocol, M extends AllMethodNames<V>>(identity: string, version: V, method: M, params: OCPPRequestType<V, M>, options?: CallOptions): Promise<OCPPResponseType<V, M> | undefined>;
128
+ safeSendToClient<M extends AllMethodNames<any>>(identity: string, method: M, params: OCPPRequestType<any, M>, options?: CallOptions): Promise<OCPPResponseType<any, M> | undefined>;
129
+ safeSendToClient<TResult = any>(identity: string, method: string, params: Record<string, any>, options?: CallOptions): Promise<TResult | undefined>;
130
+ close(options?: CloseOptions): Promise<void>;
131
+ registerUpgradePath(pattern?: string | RegExp): void;
132
+ private handleUpgrade;
133
+ private shouldHandleUpgrade;
134
+ private getPathname;
135
+ private normalizePrefixes;
136
+ private matchesPattern;
137
+ }
138
+
139
+ declare class OcppExplorer implements OnModuleInit {
140
+ private readonly discoveryService;
141
+ private readonly metadataScanner;
142
+ private readonly server;
143
+ private readonly service?;
144
+ private readonly logger;
145
+ constructor(discoveryService: DiscoveryService, metadataScanner: MetadataScanner, server: OCPPServer, service?: OcppService | undefined);
146
+ onModuleInit(): void;
147
+ explore(): void;
148
+ private executeWithParams;
149
+ private normalizeParamMetadata;
150
+ }
151
+
152
+ interface OcppRequest {
153
+ ocppServer: OCPPServer;
154
+ ocpp: OcppService;
155
+ }
156
+ declare class OcppMiddleware implements NestMiddleware {
157
+ private readonly ocppService;
158
+ constructor(ocppService: OcppService);
159
+ use(req: OcppRequest, _res: unknown, next: () => void): void;
160
+ }
161
+
162
+ declare class OcppModule {
163
+ readonly _isModule = true;
164
+ static forRoot(options?: OcppModuleOptions): DynamicModule;
165
+ static forRootAsync(options: OcppModuleAsyncOptions): DynamicModule;
166
+ private static createAsyncOptionsProvider;
167
+ }
168
+
169
+ export { Client, Context, Handshake, Identity, Message, MessageId, OCPP_AUTH_METADATA, OCPP_CONNECTION_MIDDLEWARE_METADATA, OCPP_CORS_METADATA, OCPP_GATEWAY_METADATA, OCPP_MESSAGE_EVENT_METADATA, OCPP_RPC_MIDDLEWARE_METADATA, OCPP_SERVER_INSTANCE, OCPP_SERVER_OPTIONS, OCPP_WILDCARD_EVENT_METADATA, OcppAuth, OcppConnectionMiddleware, OcppCors, OcppExplorer, OcppGateway, type OcppGatewayOptions, OcppMessageEvent, type OcppMessageEventMetadata, OcppMiddleware, OcppModule, type OcppModuleAsyncOptions, type OcppModuleOptions, type OcppNestOptions, type OcppOptionsFactory, type OcppParamMetadata, OcppParamType, type OcppRequest, OcppService, OcppWildcardEvent, type OnOcppClientConnected, type OnOcppClientDisconnected, type OnOcppClientError, PARAM_ARGS_METADATA, Params, Path, PathParam, Protocol, Session, UseOcppRpcMiddleware };
@@ -0,0 +1,169 @@
1
+ import { a0 as ServerOptions, Y as RouterConfig, a as OCPPServerClient, o as CORSOptions, M as MiddlewareFunction, O as OCPPServer, b as OCPPServerStats, c as OCPPProtocol, A as AllMethodNames, d as OCPPRequestType, C as CallOptions, e as OCPPResponseType, f as CloseOptions } from './types-xFfIgIuS.js';
2
+ import { IncomingMessage } from 'node:http';
3
+ import { Type, DynamicModule, ForwardReference, OnModuleInit, OnModuleDestroy, NestMiddleware } from '@nestjs/common';
4
+ import { HttpAdapterHost, DiscoveryService, MetadataScanner } from '@nestjs/core';
5
+ import 'ws';
6
+ import 'node:https';
7
+ import 'node:events';
8
+ import 'node:stream';
9
+ import 'node:tls';
10
+ import 'voltlog-io';
11
+ import 'ajv';
12
+
13
+ declare const OCPP_GATEWAY_METADATA = "ocpp:gateway";
14
+ declare const OCPP_MESSAGE_EVENT_METADATA = "ocpp:message_event";
15
+ declare const OCPP_WILDCARD_EVENT_METADATA = "ocpp:wildcard_event";
16
+ declare const OCPP_AUTH_METADATA = "ocpp:auth";
17
+ declare const OCPP_CONNECTION_MIDDLEWARE_METADATA = "ocpp:connection_middleware";
18
+ declare const OCPP_RPC_MIDDLEWARE_METADATA = "ocpp:rpc_middleware";
19
+ declare const OCPP_CORS_METADATA = "ocpp:cors";
20
+ declare const PARAM_ARGS_METADATA = "ocpp:params_args";
21
+ declare const OCPP_SERVER_OPTIONS = "OCPP_SERVER_OPTIONS";
22
+ declare const OCPP_SERVER_INSTANCE = "OCPP_SERVER_INSTANCE";
23
+
24
+ interface OcppGatewayOptions extends RouterConfig {
25
+ path?: string;
26
+ }
27
+ interface OcppNestOptions {
28
+ /**
29
+ * Automatically attach the OCPP upgrade handler to Nest's HTTP server.
30
+ * Defaults to true.
31
+ */
32
+ autoAttach?: boolean;
33
+ /**
34
+ * Only pass matching upgrade requests to OCPP. This is useful when the same
35
+ * Nest app also owns Socket.IO or other WebSocket gateways.
36
+ */
37
+ upgradePathPrefix?: string | string[];
38
+ /**
39
+ * Advanced upgrade filter. Return true to let OCPP handle the request.
40
+ */
41
+ upgradeFilter?: (pathname: string, req: IncomingMessage) => boolean;
42
+ }
43
+ type OcppModuleOptions = ServerOptions & OcppNestOptions;
44
+ interface OcppOptionsFactory {
45
+ createOcppOptions(): Promise<OcppModuleOptions> | OcppModuleOptions;
46
+ }
47
+ interface OcppModuleAsyncOptions {
48
+ imports?: Array<Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference>;
49
+ inject?: any[];
50
+ useFactory?: (...args: any[]) => Promise<OcppModuleOptions> | OcppModuleOptions;
51
+ useClass?: Type<OcppOptionsFactory>;
52
+ useExisting?: Type<OcppOptionsFactory>;
53
+ }
54
+ interface OnOcppClientConnected {
55
+ onOcppClientConnected(client: OCPPServerClient): void | Promise<void>;
56
+ }
57
+ interface OnOcppClientDisconnected {
58
+ onOcppClientDisconnected(client: OCPPServerClient, code: number, reason: string): void | Promise<void>;
59
+ }
60
+ interface OnOcppClientError {
61
+ onOcppClientError(client: OCPPServerClient, error: Error): void | Promise<void>;
62
+ }
63
+ declare enum OcppParamType {
64
+ CLIENT = 0,
65
+ MESSAGE = 1,
66
+ PARAMS = 2,
67
+ CONTEXT = 3,
68
+ IDENTITY = 4,
69
+ PATH = 5,
70
+ SESSION = 6,
71
+ PATH_PARAMS = 7,
72
+ PROTOCOL = 8,
73
+ MESSAGE_ID = 9,
74
+ HANDSHAKE = 10
75
+ }
76
+ interface OcppParamMetadata {
77
+ type: OcppParamType;
78
+ data?: string;
79
+ }
80
+
81
+ declare const OcppGateway: (pathOrOptions?: string | OcppGatewayOptions) => ClassDecorator;
82
+ declare const OcppCors: (options: CORSOptions) => ClassDecorator;
83
+ declare const UseOcppRpcMiddleware: (...middlewares: MiddlewareFunction<any>[]) => ClassDecorator;
84
+
85
+ interface OcppMessageEventMetadata {
86
+ action: string;
87
+ protocol?: string;
88
+ }
89
+ declare const OcppMessageEvent: (action: string, protocol?: string) => MethodDecorator;
90
+ declare const OcppWildcardEvent: () => MethodDecorator;
91
+ declare const OcppAuth: () => MethodDecorator;
92
+ declare const OcppConnectionMiddleware: () => MethodDecorator;
93
+
94
+ declare const Client: () => ParameterDecorator;
95
+ declare const Message: () => ParameterDecorator;
96
+ declare const Params: () => ParameterDecorator;
97
+ declare const Context: () => ParameterDecorator;
98
+ declare const Identity: () => ParameterDecorator;
99
+ declare const Path: () => ParameterDecorator;
100
+ declare const Session: () => ParameterDecorator;
101
+ declare const PathParam: (name?: string) => ParameterDecorator;
102
+ declare const Protocol: () => ParameterDecorator;
103
+ declare const MessageId: () => ParameterDecorator;
104
+ declare const Handshake: () => ParameterDecorator;
105
+
106
+ declare class OcppService implements OnModuleInit, OnModuleDestroy {
107
+ private readonly ocppServer;
108
+ private readonly options;
109
+ private readonly httpAdapterHost?;
110
+ private attachedHttpServer?;
111
+ private readonly gatewayPatterns;
112
+ private acceptAllUpgrades;
113
+ private readonly upgradeHandler;
114
+ constructor(ocppServer: OCPPServer, options?: OcppModuleOptions, httpAdapterHost?: HttpAdapterHost | undefined);
115
+ onModuleInit(): void;
116
+ onModuleDestroy(): Promise<void>;
117
+ get server(): OCPPServer;
118
+ get clients(): ReadonlySet<OCPPServerClient>;
119
+ stats(): OCPPServerStats;
120
+ getClient(identity: string): OCPPServerClient | undefined;
121
+ getLocalClient(identity: string): OCPPServerClient | undefined;
122
+ hasLocalClient(identity: string): boolean;
123
+ hasClient(identity: string): Promise<boolean>;
124
+ sendToClient<V extends OCPPProtocol, M extends AllMethodNames<V>>(identity: string, version: V, method: M, params: OCPPRequestType<V, M>, options?: CallOptions): Promise<OCPPResponseType<V, M> | undefined>;
125
+ sendToClient<M extends AllMethodNames<any>>(identity: string, method: M, params: OCPPRequestType<any, M>, options?: CallOptions): Promise<OCPPResponseType<any, M> | undefined>;
126
+ sendToClient<TResult = any>(identity: string, method: string, params: Record<string, any>, options?: CallOptions): Promise<TResult | undefined>;
127
+ safeSendToClient<V extends OCPPProtocol, M extends AllMethodNames<V>>(identity: string, version: V, method: M, params: OCPPRequestType<V, M>, options?: CallOptions): Promise<OCPPResponseType<V, M> | undefined>;
128
+ safeSendToClient<M extends AllMethodNames<any>>(identity: string, method: M, params: OCPPRequestType<any, M>, options?: CallOptions): Promise<OCPPResponseType<any, M> | undefined>;
129
+ safeSendToClient<TResult = any>(identity: string, method: string, params: Record<string, any>, options?: CallOptions): Promise<TResult | undefined>;
130
+ close(options?: CloseOptions): Promise<void>;
131
+ registerUpgradePath(pattern?: string | RegExp): void;
132
+ private handleUpgrade;
133
+ private shouldHandleUpgrade;
134
+ private getPathname;
135
+ private normalizePrefixes;
136
+ private matchesPattern;
137
+ }
138
+
139
+ declare class OcppExplorer implements OnModuleInit {
140
+ private readonly discoveryService;
141
+ private readonly metadataScanner;
142
+ private readonly server;
143
+ private readonly service?;
144
+ private readonly logger;
145
+ constructor(discoveryService: DiscoveryService, metadataScanner: MetadataScanner, server: OCPPServer, service?: OcppService | undefined);
146
+ onModuleInit(): void;
147
+ explore(): void;
148
+ private executeWithParams;
149
+ private normalizeParamMetadata;
150
+ }
151
+
152
+ interface OcppRequest {
153
+ ocppServer: OCPPServer;
154
+ ocpp: OcppService;
155
+ }
156
+ declare class OcppMiddleware implements NestMiddleware {
157
+ private readonly ocppService;
158
+ constructor(ocppService: OcppService);
159
+ use(req: OcppRequest, _res: unknown, next: () => void): void;
160
+ }
161
+
162
+ declare class OcppModule {
163
+ readonly _isModule = true;
164
+ static forRoot(options?: OcppModuleOptions): DynamicModule;
165
+ static forRootAsync(options: OcppModuleAsyncOptions): DynamicModule;
166
+ private static createAsyncOptionsProvider;
167
+ }
168
+
169
+ export { Client, Context, Handshake, Identity, Message, MessageId, OCPP_AUTH_METADATA, OCPP_CONNECTION_MIDDLEWARE_METADATA, OCPP_CORS_METADATA, OCPP_GATEWAY_METADATA, OCPP_MESSAGE_EVENT_METADATA, OCPP_RPC_MIDDLEWARE_METADATA, OCPP_SERVER_INSTANCE, OCPP_SERVER_OPTIONS, OCPP_WILDCARD_EVENT_METADATA, OcppAuth, OcppConnectionMiddleware, OcppCors, OcppExplorer, OcppGateway, type OcppGatewayOptions, OcppMessageEvent, type OcppMessageEventMetadata, OcppMiddleware, OcppModule, type OcppModuleAsyncOptions, type OcppModuleOptions, type OcppNestOptions, type OcppOptionsFactory, type OcppParamMetadata, OcppParamType, type OcppRequest, OcppService, OcppWildcardEvent, type OnOcppClientConnected, type OnOcppClientDisconnected, type OnOcppClientError, PARAM_ARGS_METADATA, Params, Path, PathParam, Protocol, Session, UseOcppRpcMiddleware };