ocpp-ws-io 2.1.3
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.
- package/README.md +397 -0
- package/dist/adapters/redis.d.mts +9 -0
- package/dist/adapters/redis.d.ts +9 -0
- package/dist/adapters/redis.js +423 -0
- package/dist/adapters/redis.js.map +1 -0
- package/dist/adapters/redis.mjs +396 -0
- package/dist/adapters/redis.mjs.map +1 -0
- package/dist/browser.d.mts +5036 -0
- package/dist/browser.d.ts +5036 -0
- package/dist/browser.js +1303 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.mjs +1284 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/index-BixJj_yJ.d.mts +5325 -0
- package/dist/index-BixJj_yJ.d.ts +5325 -0
- package/dist/index.d.mts +449 -0
- package/dist/index.d.ts +449 -0
- package/dist/index.js +39469 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +39399 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.d.mts +1 -0
- package/dist/logger.d.ts +1 -0
- package/dist/logger.js +25 -0
- package/dist/logger.js.map +1 -0
- package/dist/logger.mjs +3 -0
- package/dist/logger.mjs.map +1 -0
- package/package.json +111 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { E as EventAdapterInterface, A as AuthCallback, L as LoggerLike, a as LoggingConfig, M as MiddlewareFunction, b as MiddlewareContext, C as ConnectionMiddleware, T as TypedEventEmitter, S as ServerEvents, c as CORSOptions, R as RouterConfig, O as OCPPProtocol, d as AllMethodNames, e as RouterHandlerContext, f as OCPPRequestType, g as OCPPResponseType, h as RouterWildcardHandler, i as ServerOptions, j as LoggerLikeNotOptional, k as OCPPServerClient, l as OCPPServerStats, m as ListenOptions, n as CloseOptions, o as CallOptions, V as Validator } from './index-BixJj_yJ.mjs';
|
|
2
|
+
export { p as AnyOCPPProtocol, q as AuthAccept, r as CallHandler, s as ClientEvents, t as ClientOptions, u as ConnectionContext, v as ConnectionState, H as HandlerContext, w as HandshakeInfo, x as MessageType, y as MiddlewareNext, z as MiddlewareStack, N as NOREPLY, B as OCPP16Methods, D as OCPP201Methods, F as OCPP21Methods, G as OCPPCall, I as OCPPCallError, J as OCPPCallResult, K as OCPPClient, P as OCPPMessage, Q as OCPPMethodMap, U as OCPPProtocolKey, W as RedisAdapter, X as SecurityProfile, Y as SessionData, Z as TLSOptions, _ as WildcardHandler, $ as createValidator } from './index-BixJj_yJ.mjs';
|
|
3
|
+
import { Server, IncomingMessage } from 'node:http';
|
|
4
|
+
import { Duplex } from 'node:stream';
|
|
5
|
+
import 'ws';
|
|
6
|
+
import 'node:https';
|
|
7
|
+
import 'node:events';
|
|
8
|
+
import 'node:tls';
|
|
9
|
+
import 'voltlog-io';
|
|
10
|
+
import 'ajv';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* In-memory event adapter for single-process use.
|
|
14
|
+
* Events are dispatched synchronously within the same process.
|
|
15
|
+
*/
|
|
16
|
+
declare class InMemoryAdapter implements EventAdapterInterface {
|
|
17
|
+
private _channels;
|
|
18
|
+
publish(channel: string, data: unknown): Promise<void>;
|
|
19
|
+
publishBatch(messages: {
|
|
20
|
+
channel: string;
|
|
21
|
+
data: unknown;
|
|
22
|
+
}[]): Promise<void>;
|
|
23
|
+
subscribe(channel: string, handler: (data: unknown) => void): Promise<void>;
|
|
24
|
+
unsubscribe(channel: string): Promise<void>;
|
|
25
|
+
disconnect(): Promise<void>;
|
|
26
|
+
private _presence;
|
|
27
|
+
setPresence(identity: string, nodeId: string, _ttl: number): Promise<void>;
|
|
28
|
+
getPresence(identity: string): Promise<string | null>;
|
|
29
|
+
getPresenceBatch(identities: string[]): Promise<(string | null)[]>;
|
|
30
|
+
removePresence(identity: string): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Helper function to create a custom EventAdapter without needing to define a rigid Class.
|
|
34
|
+
* Provides full TypeScript inference for the `EventAdapterInterface`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const myAdapter = defineAdapter({
|
|
39
|
+
* publish: async (channel, data) => { ... },
|
|
40
|
+
* subscribe: async (channel, handler) => { ... },
|
|
41
|
+
* unsubscribe: async (channel) => { ... },
|
|
42
|
+
* disconnect: async () => { ... }
|
|
43
|
+
* });
|
|
44
|
+
* server.setAdapter(myAdapter);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare function defineAdapter(adapter: EventAdapterInterface): EventAdapterInterface;
|
|
48
|
+
|
|
49
|
+
declare class TimeoutError extends Error {
|
|
50
|
+
constructor(message?: string);
|
|
51
|
+
}
|
|
52
|
+
declare class UnexpectedHttpResponse extends Error {
|
|
53
|
+
readonly statusCode: number;
|
|
54
|
+
readonly headers: Record<string, string | string[] | undefined>;
|
|
55
|
+
constructor(message: string, statusCode: number, headers?: Record<string, string | string[] | undefined>);
|
|
56
|
+
}
|
|
57
|
+
declare class WebsocketUpgradeError extends Error {
|
|
58
|
+
constructor(message?: string);
|
|
59
|
+
}
|
|
60
|
+
interface RPCError extends Error {
|
|
61
|
+
readonly rpcErrorCode: string;
|
|
62
|
+
readonly rpcErrorMessage: string;
|
|
63
|
+
readonly details: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
declare class RPCGenericError extends Error implements RPCError {
|
|
66
|
+
readonly rpcErrorCode: string;
|
|
67
|
+
readonly rpcErrorMessage: string;
|
|
68
|
+
readonly details: Record<string, unknown>;
|
|
69
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
70
|
+
}
|
|
71
|
+
declare class RPCNotImplementedError extends RPCGenericError {
|
|
72
|
+
readonly rpcErrorCode = "NotImplemented";
|
|
73
|
+
readonly rpcErrorMessage = "Requested method is not known";
|
|
74
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
75
|
+
}
|
|
76
|
+
declare class RPCNotSupportedError extends RPCGenericError {
|
|
77
|
+
readonly rpcErrorCode = "NotSupported";
|
|
78
|
+
readonly rpcErrorMessage = "Requested method is recognised but not supported";
|
|
79
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
80
|
+
}
|
|
81
|
+
declare class RPCInternalError extends RPCGenericError {
|
|
82
|
+
readonly rpcErrorCode = "InternalError";
|
|
83
|
+
readonly rpcErrorMessage = "An internal error occurred and the receiver was not able to process the requested action successfully";
|
|
84
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
85
|
+
}
|
|
86
|
+
declare class RPCProtocolError extends RPCGenericError {
|
|
87
|
+
readonly rpcErrorCode = "ProtocolError";
|
|
88
|
+
readonly rpcErrorMessage = "Payload for action is incomplete";
|
|
89
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
90
|
+
}
|
|
91
|
+
declare class RPCSecurityError extends RPCGenericError {
|
|
92
|
+
readonly rpcErrorCode = "SecurityError";
|
|
93
|
+
readonly rpcErrorMessage = "During the processing of action a security issue occurred preventing receiver from completing the action successfully";
|
|
94
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
95
|
+
}
|
|
96
|
+
declare class RPCFormationViolationError extends RPCGenericError {
|
|
97
|
+
readonly rpcErrorCode = "FormationViolation";
|
|
98
|
+
readonly rpcErrorMessage = "Payload for action is syntactically incorrect or not conform the PDU structure for action";
|
|
99
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
100
|
+
}
|
|
101
|
+
declare class RPCFormatViolationError extends RPCGenericError {
|
|
102
|
+
readonly rpcErrorCode = "FormatViolation";
|
|
103
|
+
readonly rpcErrorMessage = "Payload is syntactically correct but at least one field contains an invalid value";
|
|
104
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
105
|
+
}
|
|
106
|
+
declare class RPCPropertyConstraintViolationError extends RPCGenericError {
|
|
107
|
+
readonly rpcErrorCode = "PropertyConstraintViolation";
|
|
108
|
+
readonly rpcErrorMessage = "Payload is syntactically correct but at least one of the fields violates data type constraints";
|
|
109
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
110
|
+
}
|
|
111
|
+
declare class RPCOccurrenceConstraintViolationError extends RPCGenericError {
|
|
112
|
+
readonly rpcErrorCode = "OccurrenceConstraintViolation";
|
|
113
|
+
readonly rpcErrorMessage = "Payload for action is syntactically correct but at least one of the fields violates occurrence constraints";
|
|
114
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
115
|
+
}
|
|
116
|
+
declare class RPCTypeConstraintViolationError extends RPCGenericError {
|
|
117
|
+
readonly rpcErrorCode = "TypeConstraintViolation";
|
|
118
|
+
readonly rpcErrorMessage = "Payload for action is syntactically correct but at least one of the fields violates type constraints";
|
|
119
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
120
|
+
}
|
|
121
|
+
declare class RPCMessageTypeNotSupportedError extends RPCGenericError {
|
|
122
|
+
readonly rpcErrorCode = "MessageTypeNotSupported";
|
|
123
|
+
readonly rpcErrorMessage = "A message with a Message Type Number received that is not supported by this implementation";
|
|
124
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
125
|
+
}
|
|
126
|
+
declare class RPCFrameworkError extends RPCGenericError {
|
|
127
|
+
readonly rpcErrorCode = "RpcFrameworkError";
|
|
128
|
+
readonly rpcErrorMessage = "Content of the call is not a valid RPC request";
|
|
129
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Utility to define and strongly-type a ConnectionMiddleware function.
|
|
134
|
+
* This provides immediate IDE autocomplete for the `ConnectionContext`.
|
|
135
|
+
*/
|
|
136
|
+
declare function defineMiddleware(mw: ConnectionMiddleware): ConnectionMiddleware;
|
|
137
|
+
/**
|
|
138
|
+
* Utility to define and strongly-type an RPC Middleware function.
|
|
139
|
+
* This provides immediate IDE autocomplete for the `MiddlewareContext`
|
|
140
|
+
* used when passing middleware to `client.use()`.
|
|
141
|
+
*/
|
|
142
|
+
declare function defineRpcMiddleware<TContext = MiddlewareContext>(mw: MiddlewareFunction<TContext>): MiddlewareFunction<TContext>;
|
|
143
|
+
/**
|
|
144
|
+
* Utility to define and strongly-type an AuthCallback function.
|
|
145
|
+
* This provides immediate IDE autocomplete for the handshake and arguments.
|
|
146
|
+
*/
|
|
147
|
+
declare function defineAuth<TSession = Record<string, unknown>>(cb: AuthCallback<TSession>): AuthCallback<TSession>;
|
|
148
|
+
/**
|
|
149
|
+
* Combines multiple AuthCallback functions sequentially.
|
|
150
|
+
*
|
|
151
|
+
* Flow matching standard middleware logic:
|
|
152
|
+
* - If one callback `reject(err)` is called, the loop drops the connection instantly.
|
|
153
|
+
* - If one callback `accept(opts)` is called, the loop terminates and grants the connection.
|
|
154
|
+
* - If the loop finishes without anyone calling accept, it rejects with 401 Unauthorized.
|
|
155
|
+
*/
|
|
156
|
+
declare function combineAuth(...cbs: AuthCallback[]): AuthCallback;
|
|
157
|
+
/**
|
|
158
|
+
* Creates a middleware that logs all RPC exchanges using the provided logger.
|
|
159
|
+
* Logs start/end of calls and results with duration.
|
|
160
|
+
*/
|
|
161
|
+
declare function createLoggingMiddleware(logger: LoggerLike, identity: string, config?: LoggingConfig | boolean): MiddlewareFunction<MiddlewareContext, any>;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Compiled regex pattern for RegExp-based route fallback.
|
|
165
|
+
* Only used when a user registers a RegExp pattern (not string patterns).
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
interface CompiledRegexPattern {
|
|
169
|
+
regex: RegExp;
|
|
170
|
+
paramNames: string[];
|
|
171
|
+
}
|
|
172
|
+
declare const OCPPRouter_base: new () => TypedEventEmitter<ServerEvents>;
|
|
173
|
+
/**
|
|
174
|
+
* OCPPRouter — An Express-like Connection dispatcher.
|
|
175
|
+
* Isolated handler for a specific set of matching URL route patterns.
|
|
176
|
+
*
|
|
177
|
+
* String patterns are matched via radix trie (O(k) lookup, managed by OCPPServer).
|
|
178
|
+
* RegExp patterns fall back to linear matching.
|
|
179
|
+
*/
|
|
180
|
+
declare class OCPPRouter extends OCPPRouter_base {
|
|
181
|
+
/** Raw registered patterns (strings and/or RegExp) for reference. */
|
|
182
|
+
patterns: Array<string | RegExp>;
|
|
183
|
+
/** Connection middlewares attached to this router. */
|
|
184
|
+
middlewares: ConnectionMiddleware[];
|
|
185
|
+
/** Auth callback for this route endpoint. */
|
|
186
|
+
authCallback: AuthCallback<unknown> | null;
|
|
187
|
+
/** Route-level CORS options. */
|
|
188
|
+
_routeCORS?: CORSOptions;
|
|
189
|
+
/** Route-level config overrides. */
|
|
190
|
+
_routeConfig?: RouterConfig;
|
|
191
|
+
/**
|
|
192
|
+
* Compiled RegExp patterns for fallback linear matching.
|
|
193
|
+
* Only populated when RegExp patterns are registered.
|
|
194
|
+
* @internal
|
|
195
|
+
*/
|
|
196
|
+
_regexPatterns: CompiledRegexPattern[];
|
|
197
|
+
constructor(patterns?: Array<string | RegExp>, middlewares?: ConnectionMiddleware[]);
|
|
198
|
+
/**
|
|
199
|
+
* Appends URL paths or regular expressions to this router's match condition.
|
|
200
|
+
* String patterns are stored for trie insertion by OCPPServer.
|
|
201
|
+
* RegExp patterns are compiled for linear fallback matching.
|
|
202
|
+
*/
|
|
203
|
+
route(...patterns: Array<string | RegExp>): this;
|
|
204
|
+
/**
|
|
205
|
+
* Appends connection middlewares to this router's execution chain.
|
|
206
|
+
*/
|
|
207
|
+
use(...middlewares: ConnectionMiddleware[]): this;
|
|
208
|
+
/**
|
|
209
|
+
* Applies specific CORS rules to connections matching this router's paths.
|
|
210
|
+
*/
|
|
211
|
+
cors(options: CORSOptions): this;
|
|
212
|
+
/**
|
|
213
|
+
* Overrides global connection settings (e.g. timeouts, protocols) for this router.
|
|
214
|
+
*/
|
|
215
|
+
config(options: RouterConfig): this;
|
|
216
|
+
/**
|
|
217
|
+
* Registers an authentication and protocol-negotiation callback for this route endpoint.
|
|
218
|
+
*/
|
|
219
|
+
auth<TSession = Record<string, unknown>>(callback: AuthCallback<TSession>): this;
|
|
220
|
+
/**
|
|
221
|
+
* Binds a version-specific OCPP message handler directly to all clients that match this route.
|
|
222
|
+
*
|
|
223
|
+
* @throws {Error} AT RUNTIME when a client connects, if a handler for this version and method is already registered for that client.
|
|
224
|
+
*/
|
|
225
|
+
handle<V extends OCPPProtocol, M extends AllMethodNames<V>>(version: V, method: M, handler: (context: RouterHandlerContext<OCPPRequestType<V, M>>) => OCPPResponseType<V, M> | Promise<OCPPResponseType<V, M>>): this;
|
|
226
|
+
/**
|
|
227
|
+
* Binds a custom/extension message handler directly to all clients that match this route.
|
|
228
|
+
*
|
|
229
|
+
* @throws {Error} AT RUNTIME when a client connects, if a handler for this protocol and method is already registered for that client.
|
|
230
|
+
*/
|
|
231
|
+
handle<S extends string>(version: S extends OCPPProtocol ? never : S, method: string, handler: (context: RouterHandlerContext<Record<string, any>>) => any): this;
|
|
232
|
+
/**
|
|
233
|
+
* Binds a message handler directly to all clients that match this route using the default protocol.
|
|
234
|
+
*
|
|
235
|
+
* @throws {Error} AT RUNTIME when a client connects, if a handler for this method is already registered for that client.
|
|
236
|
+
*/
|
|
237
|
+
handle<M extends AllMethodNames<OCPPProtocol>>(method: M, handler: (context: RouterHandlerContext<OCPPRequestType<OCPPProtocol, M>>) => OCPPResponseType<OCPPProtocol, M> | Promise<OCPPResponseType<OCPPProtocol, M>>): this;
|
|
238
|
+
/**
|
|
239
|
+
* Binds a custom/extension method not in the typed map.
|
|
240
|
+
*
|
|
241
|
+
* @throws {Error} AT RUNTIME when a client connects, if a handler for this method is already registered for that client.
|
|
242
|
+
*/
|
|
243
|
+
handle(method: string, handler: (context: RouterHandlerContext<Record<string, any>>) => any): this;
|
|
244
|
+
/**
|
|
245
|
+
* Binds a wildcard handler to all clients that match this route.
|
|
246
|
+
*
|
|
247
|
+
* @throws {Error} AT RUNTIME when a client connects, if a wildcard handler is already registered for that client.
|
|
248
|
+
*/
|
|
249
|
+
handle(handler: RouterWildcardHandler): this;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Creates a standalone, modular `OCPPRouter` instance that can be attached
|
|
253
|
+
* to an `OCPPServer` later via `server.attachRouters()`.
|
|
254
|
+
*/
|
|
255
|
+
declare function createRouter(...patterns: Array<string | RegExp>): OCPPRouter;
|
|
256
|
+
|
|
257
|
+
declare const OCPPServer_base: new () => TypedEventEmitter<ServerEvents>;
|
|
258
|
+
/**
|
|
259
|
+
* OCPPServer — A typed WebSocket RPC server for OCPP communication.
|
|
260
|
+
*
|
|
261
|
+
* Supports all 3 OCPP Security Profiles:
|
|
262
|
+
* - Profile 1: Basic Auth over unsecured WS
|
|
263
|
+
* - Profile 2: TLS + Basic Auth (HTTPS server)
|
|
264
|
+
* - Profile 3: Mutual TLS (HTTPS server with requestCert)
|
|
265
|
+
*/
|
|
266
|
+
declare class OCPPServer extends OCPPServer_base {
|
|
267
|
+
private _options;
|
|
268
|
+
/** Radix trie for O(k) route matching (string patterns). */
|
|
269
|
+
private _trie;
|
|
270
|
+
/** Global middleware routers (server.use() with no patterns — catch-all). */
|
|
271
|
+
private _globalMiddlewareRouters;
|
|
272
|
+
/** Routers with RegExp patterns (fallback linear scan). */
|
|
273
|
+
private _regexRouters;
|
|
274
|
+
private _clients;
|
|
275
|
+
private _clientsByIdentity;
|
|
276
|
+
private _httpServers;
|
|
277
|
+
private _wss;
|
|
278
|
+
private _state;
|
|
279
|
+
private _adapter;
|
|
280
|
+
private _httpServerAbortControllers;
|
|
281
|
+
private _logger;
|
|
282
|
+
private _globalCORS?;
|
|
283
|
+
private readonly _nodeId;
|
|
284
|
+
private _sessions;
|
|
285
|
+
private _gcInterval;
|
|
286
|
+
private readonly _sessionTimeoutMs;
|
|
287
|
+
constructor(options?: ServerOptions);
|
|
288
|
+
get log(): LoggerLikeNotOptional;
|
|
289
|
+
/**
|
|
290
|
+
* Returns a readonly set of all currently connected OCPPServerClient instances.
|
|
291
|
+
*/
|
|
292
|
+
get clients(): ReadonlySet<OCPPServerClient>;
|
|
293
|
+
/**
|
|
294
|
+
* Returns the current server state (OPEN, CLOSING, CLOSED).
|
|
295
|
+
*/
|
|
296
|
+
get state(): "OPEN" | "CLOSING" | "CLOSED";
|
|
297
|
+
/**
|
|
298
|
+
* Returns current node observability statistics
|
|
299
|
+
* (e.g. connected socket count, tracked memory sessions, and process CPU/Memory usage).
|
|
300
|
+
* Fully compatible with Loki/Prometheus node metric ingestion.
|
|
301
|
+
*/
|
|
302
|
+
stats(): OCPPServerStats;
|
|
303
|
+
/**
|
|
304
|
+
* Returns observability statistics from the active Event Adapter (e.g. Redis).
|
|
305
|
+
* Useful for tracking consumer backlog and enabling Horizontal Pod Autoscaling.
|
|
306
|
+
*/
|
|
307
|
+
adapterMetrics(): Promise<Record<string, unknown> | null>;
|
|
308
|
+
/**
|
|
309
|
+
* Synchronously returns the OCPPServerClient instance if the specific identity
|
|
310
|
+
* is connected to THIS local server node.
|
|
311
|
+
* Note: In a clustered environment, clients connected to other nodes will NOT be returned here.
|
|
312
|
+
*
|
|
313
|
+
* @param identity The client identity (username/station ID)
|
|
314
|
+
*/
|
|
315
|
+
getLocalClient(identity: string): OCPPServerClient | undefined;
|
|
316
|
+
/**
|
|
317
|
+
* Synchronously checks if the specific identity is connected to THIS local server node.
|
|
318
|
+
* Note: In a clustered environment, this will return false if the client is connected to another node.
|
|
319
|
+
*
|
|
320
|
+
* @param identity The client identity (username/station ID)
|
|
321
|
+
*/
|
|
322
|
+
hasLocalClient(identity: string): boolean;
|
|
323
|
+
/**
|
|
324
|
+
* Asynchronously checks if the specific identity is connected to the server.
|
|
325
|
+
* In a single-node setup, this checks the local connections.
|
|
326
|
+
* In a clustered setup (with a pub/sub adapter), this will also check the global presence registry
|
|
327
|
+
* to see if the client is connected to ANY node in the cluster.
|
|
328
|
+
*
|
|
329
|
+
* @param identity The client identity (username/station ID)
|
|
330
|
+
*/
|
|
331
|
+
isClientConnected(identity: string): Promise<boolean>;
|
|
332
|
+
/**
|
|
333
|
+
* Applies global CORS rules to all incoming connections before routing.
|
|
334
|
+
*/
|
|
335
|
+
cors(options: CORSOptions): this;
|
|
336
|
+
/**
|
|
337
|
+
* Registers a new routing dispatcher for multiplexing connections.
|
|
338
|
+
* `server.route("/api/:tenant").use(middleware).auth(cb).on("client", ...)`
|
|
339
|
+
*/
|
|
340
|
+
route(...patterns: Array<string | RegExp>): OCPPRouter;
|
|
341
|
+
/**
|
|
342
|
+
* Attaches one or more standalone modular routers created via `createRouter()`.
|
|
343
|
+
* This is useful for separating route definitions across different files.
|
|
344
|
+
*/
|
|
345
|
+
attachRouters(...routers: OCPPRouter[]): this;
|
|
346
|
+
/**
|
|
347
|
+
* Registers a new middleware chain, acting as a wildcard/catch-all router if no patterns are added.
|
|
348
|
+
* `server.use(middleware).route("/api").on("client", ...)`
|
|
349
|
+
*/
|
|
350
|
+
use(...middlewares: ConnectionMiddleware[]): OCPPRouter;
|
|
351
|
+
/**
|
|
352
|
+
* Registers a top-level auth handler, returning a router to attach `.on()` or `.use()`.
|
|
353
|
+
*/
|
|
354
|
+
auth<TSession = Record<string, unknown>>(callback: AuthCallback<TSession>): OCPPRouter;
|
|
355
|
+
/**
|
|
356
|
+
* Routes a router into the appropriate internal structure:
|
|
357
|
+
* - String patterns → radix trie (O(k) lookup)
|
|
358
|
+
* - RegExp patterns → linear fallback array
|
|
359
|
+
* - No patterns → global middleware (catch-all)
|
|
360
|
+
* @internal
|
|
361
|
+
*/
|
|
362
|
+
private _registerRouter;
|
|
363
|
+
listen(port?: number, host?: string, options?: ListenOptions): Promise<Server>;
|
|
364
|
+
get handleUpgrade(): (req: IncomingMessage, socket: Duplex, head: Buffer) => Promise<void>;
|
|
365
|
+
/**
|
|
366
|
+
* Core upgrade handler. Follows a strict pipeline:
|
|
367
|
+
*
|
|
368
|
+
* 1. Validate socket readyState & upgrade header
|
|
369
|
+
* 2. Parse URL → identity + endpoint
|
|
370
|
+
* 3. Enable TCP Keep-Alive
|
|
371
|
+
* 4. Parse & negotiate subprotocols
|
|
372
|
+
* 5. Parse Basic Auth (via modular parseBasicAuth)
|
|
373
|
+
* 6. Extract TLS client certificate (Profile 3)
|
|
374
|
+
* 7. Build HandshakeInfo
|
|
375
|
+
* 8. Run auth callback with AbortController + handshake timeout
|
|
376
|
+
* 9. Complete WebSocket upgrade
|
|
377
|
+
* 10. Create OCPPServerClient
|
|
378
|
+
*/
|
|
379
|
+
private _handleUpgrade;
|
|
380
|
+
private _updateSessionActivity;
|
|
381
|
+
close(options?: CloseOptions): Promise<void>;
|
|
382
|
+
reconfigure(options: Partial<ServerOptions>): void;
|
|
383
|
+
/**
|
|
384
|
+
* Send a request to a specific client (local or remote).
|
|
385
|
+
*
|
|
386
|
+
* 1. Checks local clients.
|
|
387
|
+
* 2. Checks Presence Registry -> Unicast.
|
|
388
|
+
* 3. Fallback: Broadcast.
|
|
389
|
+
*/
|
|
390
|
+
/**
|
|
391
|
+
* Send a request to a specific client (local or remote).
|
|
392
|
+
*
|
|
393
|
+
* 1. Checks local clients.
|
|
394
|
+
* 2. Checks Presence Registry -> Unicast.
|
|
395
|
+
* 3. Fallback: Error (Client not found).
|
|
396
|
+
*/
|
|
397
|
+
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>;
|
|
398
|
+
sendToClient<M extends AllMethodNames<any>>(identity: string, method: M, params: OCPPRequestType<any, M>, options?: CallOptions): Promise<OCPPResponseType<any, M> | undefined>;
|
|
399
|
+
sendToClient<_T = any>(identity: string, method: string, params: Record<string, any>, options?: CallOptions): Promise<any | undefined>;
|
|
400
|
+
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>;
|
|
401
|
+
safeSendToClient<M extends AllMethodNames<any>>(identity: string, method: M, params: OCPPRequestType<any, M>, options?: CallOptions): Promise<OCPPResponseType<any, M> | undefined>;
|
|
402
|
+
safeSendToClient<_T = any>(identity: string, method: string, params: Record<string, any>, options?: CallOptions): Promise<any | undefined>;
|
|
403
|
+
setAdapter(adapter: EventAdapterInterface): Promise<void>;
|
|
404
|
+
private _onBroadcast;
|
|
405
|
+
private _onUnicast;
|
|
406
|
+
publish(channel: string, data: unknown): Promise<void>;
|
|
407
|
+
broadcast<V extends AllMethodNames<any>>(method: V, params: OCPPRequestType<any, V>): Promise<void>;
|
|
408
|
+
/**
|
|
409
|
+
* Send a specific method & params to a list of specific clients efficiently.
|
|
410
|
+
* This leverages adapter pipelining (e.g. Redis .pipeline()) to minimize network overhead
|
|
411
|
+
* when communicating with thousands of nodes simultaneously.
|
|
412
|
+
*
|
|
413
|
+
* @param identities Array of target client identities
|
|
414
|
+
* @param method The OCPP method to send
|
|
415
|
+
* @param params The request parameters
|
|
416
|
+
* @param options Call options
|
|
417
|
+
*/
|
|
418
|
+
broadcastBatch<V extends AllMethodNames<any>>(identities: string[], method: V, params: OCPPRequestType<any, V>, options?: CallOptions): Promise<void>;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Pre-built validators for all supported OCPP protocol versions.
|
|
423
|
+
* These are automatically registered when strict mode is enabled.
|
|
424
|
+
*/
|
|
425
|
+
declare const standardValidators: Validator[];
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Instantiate a typed RPCError from a string error code.
|
|
429
|
+
* Returns an RPCGenericError if the code is not recognized.
|
|
430
|
+
*/
|
|
431
|
+
declare function createRPCError(code: string, message?: string, details?: Record<string, unknown>): RPCError;
|
|
432
|
+
/**
|
|
433
|
+
* Convert an Error (or subclass) into a plain, JSON-safe object.
|
|
434
|
+
*
|
|
435
|
+
* Extracts well-known properties explicitly rather than relying on
|
|
436
|
+
* Object.getOwnPropertyNames to avoid exposing internal fields and
|
|
437
|
+
* to guarantee a stable output shape.
|
|
438
|
+
*
|
|
439
|
+
* If a property holds a non-serializable value (functions, symbols,
|
|
440
|
+
* circular references), it is silently skipped.
|
|
441
|
+
*/
|
|
442
|
+
declare function getErrorPlainObject(err: Error): Record<string, unknown>;
|
|
443
|
+
/**
|
|
444
|
+
* Get the package identifier string used in HTTP headers and logging.
|
|
445
|
+
* Format: `ocpp-ws-io/1.0.0`
|
|
446
|
+
*/
|
|
447
|
+
declare function getPackageIdent(): string;
|
|
448
|
+
|
|
449
|
+
export { AllMethodNames, AuthCallback, CORSOptions, CallOptions, CloseOptions, ConnectionMiddleware, EventAdapterInterface, InMemoryAdapter, ListenOptions, LoggerLike, LoggingConfig, MiddlewareFunction, OCPPProtocol, OCPPRequestType, OCPPResponseType, OCPPRouter, OCPPServer, OCPPServerClient, type RPCError, RPCFormatViolationError, RPCFormationViolationError, RPCFrameworkError, RPCGenericError, RPCInternalError, RPCMessageTypeNotSupportedError, RPCNotImplementedError, RPCNotSupportedError, RPCOccurrenceConstraintViolationError, RPCPropertyConstraintViolationError, RPCProtocolError, RPCSecurityError, RPCTypeConstraintViolationError, RouterConfig, ServerEvents, ServerOptions, TimeoutError, TypedEventEmitter, UnexpectedHttpResponse, Validator, WebsocketUpgradeError, combineAuth, createLoggingMiddleware, createRPCError, createRouter, defineAdapter, defineAuth, defineMiddleware, defineRpcMiddleware, getErrorPlainObject, getPackageIdent, standardValidators };
|