ocpp-ws-io 2.1.7 → 2.1.9
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 +1 -1
- package/dist/adapters/redis.d.mts +2 -1
- package/dist/adapters/redis.d.ts +2 -1
- package/dist/adapters/redis.js +27 -6
- package/dist/adapters/redis.js.map +1 -1
- package/dist/adapters/redis.mjs +27 -6
- package/dist/adapters/redis.mjs.map +1 -1
- package/dist/browser.d.mts +1129 -6
- package/dist/browser.d.ts +1129 -6
- package/dist/browser.js +34 -20
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +34 -20
- package/dist/browser.mjs.map +1 -1
- package/dist/index-C0mn42-8.d.mts +161 -0
- package/dist/index-s9f97CmV.d.ts +161 -0
- package/dist/index.d.mts +131 -291
- package/dist/index.d.ts +131 -291
- package/dist/index.js +658 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +672 -80
- package/dist/index.mjs.map +1 -1
- package/dist/plugins.d.mts +246 -0
- package/dist/plugins.d.ts +246 -0
- package/dist/plugins.js +370 -0
- package/dist/plugins.js.map +1 -0
- package/dist/plugins.mjs +350 -0
- package/dist/plugins.mjs.map +1 -0
- package/dist/{index-BRblF1XV.d.mts → types-BZXEmDQ1.d.mts} +468 -89
- package/dist/{index-BRblF1XV.d.ts → types-BZXEmDQ1.d.ts} +468 -89
- package/package.json +13 -9
- package/assets/banner.svg +0 -31
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { E as EventAdapterInterface, A as AuthCallback, L as LoggerLike, a as LoggingConfig, M as MiddlewareFunction, b as MiddlewareContext,
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { E as EventAdapterInterface, A as AuthCallback, L as LoggerLike, a as LoggingConfig, M as MiddlewareFunction, b as MiddlewareContext, O as OCPPPlugin, C as ConnectionMiddleware, V as Validator } from './types-BZXEmDQ1.mjs';
|
|
2
|
+
export { c as AllMethodNames, d as AnyOCPPProtocol, e as AuthAccept, f as CORSOptions, g as CallHandler, h as CallOptions, i as ClientEvents, j as ClientOptions, k as CloseOptions, l as CompressionOptions, m as ConnectionContext, n as ConnectionState, H as HandlerContext, o as HandshakeInfo, p as ListenOptions, q as MessageType, r as MiddlewareNext, s as MiddlewareStack, N as NOREPLY, t as OCPP16Methods, u as OCPP201Methods, v as OCPP21Methods, w as OCPPCall, x as OCPPCallError, y as OCPPCallResult, z as OCPPClient, B as OCPPMessage, D as OCPPMethodMap, F as OCPPProtocol, G as OCPPProtocolKey, I as OCPPRequestType, J as OCPPResponseType, K as OCPPRouter, P as OCPPServer, Q as OCPPServerClient, R as RateLimitOptions, S as RouterConfig, T as SecurityProfile, U as ServerEvents, W as ServerOptions, X as SessionData, Y as TLSOptions, Z as TypedEventEmitter, _ as WildcardHandler, $ as createRouter, a0 as createValidator } from './types-BZXEmDQ1.mjs';
|
|
3
|
+
import { R as RedisPubSubDriver, S as StreamEntry } from './index-C0mn42-8.mjs';
|
|
4
|
+
export { a as RedisAdapter } from './index-C0mn42-8.mjs';
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
5
6
|
import 'ws';
|
|
6
7
|
import 'node:https';
|
|
7
|
-
import 'node:
|
|
8
|
+
import 'node:http';
|
|
9
|
+
import 'node:stream';
|
|
8
10
|
import 'node:tls';
|
|
9
11
|
import 'voltlog-io';
|
|
10
12
|
import 'ajv';
|
|
@@ -51,6 +53,109 @@ declare class InMemoryAdapter implements EventAdapterInterface {
|
|
|
51
53
|
*/
|
|
52
54
|
declare function defineAdapter(adapter: EventAdapterInterface): EventAdapterInterface;
|
|
53
55
|
|
|
56
|
+
interface ClusterNode {
|
|
57
|
+
host: string;
|
|
58
|
+
port: number;
|
|
59
|
+
}
|
|
60
|
+
interface ClusterDriverOptions {
|
|
61
|
+
/** Seed nodes for the Redis Cluster */
|
|
62
|
+
nodes: ClusterNode[];
|
|
63
|
+
/** NAT mapping for Docker/k8s environments */
|
|
64
|
+
natMap?: Record<string, {
|
|
65
|
+
host: string;
|
|
66
|
+
port: number;
|
|
67
|
+
}>;
|
|
68
|
+
/** Additional ioredis options passed to the Cluster constructor */
|
|
69
|
+
redisOptions?: Record<string, unknown>;
|
|
70
|
+
/** Key prefix (used for hash tag generation) */
|
|
71
|
+
prefix?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Redis Cluster driver that implements `RedisPubSubDriver`.
|
|
75
|
+
* Requires `ioredis` as a peer dependency.
|
|
76
|
+
*
|
|
77
|
+
* Hash-tag strategy:
|
|
78
|
+
* - Presence keys: `{identity}` → sharded by station identity
|
|
79
|
+
* - Stream keys: `{nodeId}` → sharded by server node ID
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const driver = createClusterDriver({
|
|
84
|
+
* nodes: [{ host: '10.0.0.1', port: 6379 }, { host: '10.0.0.2', port: 6379 }],
|
|
85
|
+
* });
|
|
86
|
+
* const adapter = new RedisAdapter({ pubClient: {}, subClient: {}, driverFactory: () => driver });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare class ClusterDriver implements RedisPubSubDriver {
|
|
90
|
+
private _cluster;
|
|
91
|
+
private _subscriber;
|
|
92
|
+
private _handlers;
|
|
93
|
+
constructor(_options: ClusterDriverOptions);
|
|
94
|
+
publish(channel: string, message: string): Promise<void>;
|
|
95
|
+
subscribe(channel: string, handler: (message: string) => void): Promise<void>;
|
|
96
|
+
unsubscribe(channel: string): Promise<void>;
|
|
97
|
+
set(key: string, value: string, ttlSeconds?: number): Promise<void>;
|
|
98
|
+
get(key: string): Promise<string | null>;
|
|
99
|
+
mget(keys: string[]): Promise<(string | null)[]>;
|
|
100
|
+
del(key: string): Promise<void>;
|
|
101
|
+
xadd(stream: string, args: Record<string, string>, maxLen?: number): Promise<string>;
|
|
102
|
+
xaddBatch(messages: {
|
|
103
|
+
stream: string;
|
|
104
|
+
args: Record<string, string>;
|
|
105
|
+
}[], maxLen?: number): Promise<void>;
|
|
106
|
+
xread(streams: {
|
|
107
|
+
key: string;
|
|
108
|
+
id: string;
|
|
109
|
+
}[], count?: number, block?: number): Promise<StreamEntry[] | null>;
|
|
110
|
+
xlen(stream: string): Promise<number>;
|
|
111
|
+
disconnect(): Promise<void>;
|
|
112
|
+
setPresenceBatch(entries: {
|
|
113
|
+
key: string;
|
|
114
|
+
value: string;
|
|
115
|
+
ttlSeconds: number;
|
|
116
|
+
}[]): Promise<void>;
|
|
117
|
+
expire(key: string, ttlSeconds: number): Promise<void>;
|
|
118
|
+
onError(handler: (err: Error) => void): () => void;
|
|
119
|
+
onReconnect(handler: () => void): () => void;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
interface AdaptiveLimiterOptions {
|
|
123
|
+
/** CPU usage % at which limits start tightening (default: 70) */
|
|
124
|
+
cpuThresholdPercent?: number;
|
|
125
|
+
/** Memory usage % at which limits start tightening (default: 85) */
|
|
126
|
+
memThresholdPercent?: number;
|
|
127
|
+
/** Cooldown before the multiplier recovers after an overload (default: 10000ms) */
|
|
128
|
+
cooldownMs?: number;
|
|
129
|
+
/** How often to sample system metrics (default: 2000ms) */
|
|
130
|
+
sampleIntervalMs?: number;
|
|
131
|
+
}
|
|
132
|
+
interface AdaptedEvent {
|
|
133
|
+
multiplier: number;
|
|
134
|
+
cpuPercent: number;
|
|
135
|
+
memPercent: number;
|
|
136
|
+
}
|
|
137
|
+
declare class AdaptiveLimiter extends EventEmitter {
|
|
138
|
+
private _cpuThreshold;
|
|
139
|
+
private _memThreshold;
|
|
140
|
+
private _cooldownMs;
|
|
141
|
+
private _sampleInterval;
|
|
142
|
+
private _timer;
|
|
143
|
+
private _lastOverloadTime;
|
|
144
|
+
private _multiplier;
|
|
145
|
+
private _prevCpuUsage;
|
|
146
|
+
private _prevTimestamp;
|
|
147
|
+
constructor(options?: AdaptiveLimiterOptions);
|
|
148
|
+
/** Current rate multiplier: 1.0 = normal, 0.25 = heavily throttled */
|
|
149
|
+
get multiplier(): number;
|
|
150
|
+
/** Start periodic sampling */
|
|
151
|
+
start(): void;
|
|
152
|
+
/** Stop sampling and reset multiplier */
|
|
153
|
+
stop(): void;
|
|
154
|
+
private _sample;
|
|
155
|
+
on(event: "adapted", listener: (data: AdaptedEvent) => void): this;
|
|
156
|
+
emit(event: "adapted", data: AdaptedEvent): boolean;
|
|
157
|
+
}
|
|
158
|
+
|
|
54
159
|
declare class TimeoutError extends Error {
|
|
55
160
|
constructor(message?: string);
|
|
56
161
|
}
|
|
@@ -139,6 +244,26 @@ declare class RPCFrameworkError extends RPCGenericError {
|
|
|
139
244
|
* This provides immediate IDE autocomplete for the `ConnectionContext`.
|
|
140
245
|
*/
|
|
141
246
|
declare function defineMiddleware(mw: ConnectionMiddleware): ConnectionMiddleware;
|
|
247
|
+
/**
|
|
248
|
+
* Utility to define and strongly-type an `OCPPPlugin` object.
|
|
249
|
+
* Provides full IDE autocomplete for all lifecycle hooks.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* import { createPlugin } from 'ocpp-ws-io';
|
|
254
|
+
*
|
|
255
|
+
* const metricsPlugin = createPlugin({
|
|
256
|
+
* name: 'metrics',
|
|
257
|
+
* onInit(server) { console.log('Metrics plugin ready'); },
|
|
258
|
+
* onConnection(client) { metrics.gauge('connections').inc(); },
|
|
259
|
+
* onDisconnect(client) { metrics.gauge('connections').dec(); },
|
|
260
|
+
* onClose() { metrics.flush(); },
|
|
261
|
+
* });
|
|
262
|
+
*
|
|
263
|
+
* server.plugin(metricsPlugin);
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
declare function createPlugin(plugin: OCPPPlugin): OCPPPlugin;
|
|
142
267
|
/**
|
|
143
268
|
* Utility to define and strongly-type an RPC Middleware function.
|
|
144
269
|
* This provides immediate IDE autocomplete for the `MiddlewareContext`
|
|
@@ -197,293 +322,8 @@ declare class LRUMap<K, V> extends Map<K, V> {
|
|
|
197
322
|
get(key: K): V | undefined;
|
|
198
323
|
}
|
|
199
324
|
|
|
200
|
-
/**
|
|
201
|
-
* Compiled regex pattern for RegExp-based route fallback.
|
|
202
|
-
* Only used when a user registers a RegExp pattern (not string patterns).
|
|
203
|
-
* @internal
|
|
204
|
-
*/
|
|
205
|
-
interface CompiledRegexPattern {
|
|
206
|
-
regex: RegExp;
|
|
207
|
-
paramNames: string[];
|
|
208
|
-
}
|
|
209
|
-
declare const OCPPRouter_base: new () => TypedEventEmitter<ServerEvents>;
|
|
210
|
-
/**
|
|
211
|
-
* OCPPRouter — An Express-like Connection dispatcher.
|
|
212
|
-
* Isolated handler for a specific set of matching URL route patterns.
|
|
213
|
-
*
|
|
214
|
-
* String patterns are matched via radix trie (O(k) lookup, managed by OCPPServer).
|
|
215
|
-
* RegExp patterns fall back to linear matching.
|
|
216
|
-
*/
|
|
217
|
-
declare class OCPPRouter extends OCPPRouter_base {
|
|
218
|
-
/** Raw registered patterns (strings and/or RegExp) for reference. */
|
|
219
|
-
patterns: Array<string | RegExp>;
|
|
220
|
-
/** Connection middlewares attached to this router. */
|
|
221
|
-
middlewares: ConnectionMiddleware[];
|
|
222
|
-
/** Auth callback for this route endpoint. */
|
|
223
|
-
authCallback: AuthCallback<unknown> | null;
|
|
224
|
-
/** Route-level CORS options. */
|
|
225
|
-
_routeCORS?: CORSOptions;
|
|
226
|
-
/** Route-level config overrides. */
|
|
227
|
-
_routeConfig?: RouterConfig;
|
|
228
|
-
/**
|
|
229
|
-
* Compiled RegExp patterns for fallback linear matching.
|
|
230
|
-
* Only populated when RegExp patterns are registered.
|
|
231
|
-
* @internal
|
|
232
|
-
*/
|
|
233
|
-
_regexPatterns: CompiledRegexPattern[];
|
|
234
|
-
constructor(patterns?: Array<string | RegExp>, middlewares?: ConnectionMiddleware[]);
|
|
235
|
-
/**
|
|
236
|
-
* Appends URL paths or regular expressions to this router's match condition.
|
|
237
|
-
* String patterns are stored for trie insertion by OCPPServer.
|
|
238
|
-
* RegExp patterns are compiled for linear fallback matching.
|
|
239
|
-
*/
|
|
240
|
-
route(...patterns: Array<string | RegExp>): this;
|
|
241
|
-
/**
|
|
242
|
-
* Appends connection middlewares to this router's execution chain.
|
|
243
|
-
*/
|
|
244
|
-
use(...middlewares: ConnectionMiddleware[]): this;
|
|
245
|
-
/**
|
|
246
|
-
* Applies specific CORS rules to connections matching this router's paths.
|
|
247
|
-
*/
|
|
248
|
-
cors(options: CORSOptions): this;
|
|
249
|
-
/**
|
|
250
|
-
* Overrides global connection settings (e.g. timeouts, protocols) for this router.
|
|
251
|
-
*/
|
|
252
|
-
config(options: RouterConfig): this;
|
|
253
|
-
/**
|
|
254
|
-
* Registers an authentication and protocol-negotiation callback for this route endpoint.
|
|
255
|
-
*/
|
|
256
|
-
auth<TSession = Record<string, unknown>>(callback: AuthCallback<TSession>): this;
|
|
257
|
-
/**
|
|
258
|
-
* Binds a version-specific OCPP message handler directly to all clients that match this route.
|
|
259
|
-
*
|
|
260
|
-
* @throws {Error} AT RUNTIME when a client connects, if a handler for this version and method is already registered for that client.
|
|
261
|
-
*/
|
|
262
|
-
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;
|
|
263
|
-
/**
|
|
264
|
-
* Binds a custom/extension message handler directly to all clients that match this route.
|
|
265
|
-
*
|
|
266
|
-
* @throws {Error} AT RUNTIME when a client connects, if a handler for this protocol and method is already registered for that client.
|
|
267
|
-
*/
|
|
268
|
-
handle<S extends string>(version: S extends OCPPProtocol ? never : S, method: string, handler: (context: RouterHandlerContext<Record<string, any>>) => any): this;
|
|
269
|
-
/**
|
|
270
|
-
* Binds a message handler directly to all clients that match this route using the default protocol.
|
|
271
|
-
*
|
|
272
|
-
* @throws {Error} AT RUNTIME when a client connects, if a handler for this method is already registered for that client.
|
|
273
|
-
*/
|
|
274
|
-
handle<M extends AllMethodNames<OCPPProtocol>>(method: M, handler: (context: RouterHandlerContext<OCPPRequestType<OCPPProtocol, M>>) => OCPPResponseType<OCPPProtocol, M> | Promise<OCPPResponseType<OCPPProtocol, M>>): this;
|
|
275
|
-
/**
|
|
276
|
-
* Binds a custom/extension method not in the typed map.
|
|
277
|
-
*
|
|
278
|
-
* @throws {Error} AT RUNTIME when a client connects, if a handler for this method is already registered for that client.
|
|
279
|
-
*/
|
|
280
|
-
handle(method: string, handler: (context: RouterHandlerContext<Record<string, any>>) => any): this;
|
|
281
|
-
/**
|
|
282
|
-
* Binds a wildcard handler to all clients that match this route.
|
|
283
|
-
*
|
|
284
|
-
* @throws {Error} AT RUNTIME when a client connects, if a wildcard handler is already registered for that client.
|
|
285
|
-
*/
|
|
286
|
-
handle(handler: RouterWildcardHandler): this;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Creates a standalone, modular `OCPPRouter` instance that can be attached
|
|
290
|
-
* to an `OCPPServer` later via `server.attachRouters()`.
|
|
291
|
-
*/
|
|
292
|
-
declare function createRouter(...patterns: Array<string | RegExp>): OCPPRouter;
|
|
293
|
-
|
|
294
|
-
declare const OCPPServer_base: new () => TypedEventEmitter<ServerEvents>;
|
|
295
|
-
/**
|
|
296
|
-
* OCPPServer — A typed WebSocket RPC server for OCPP communication.
|
|
297
|
-
*
|
|
298
|
-
* Supports all 3 OCPP Security Profiles:
|
|
299
|
-
* - Profile 1: Basic Auth over unsecured WS
|
|
300
|
-
* - Profile 2: TLS + Basic Auth (HTTPS server)
|
|
301
|
-
* - Profile 3: Mutual TLS (HTTPS server with requestCert)
|
|
302
|
-
*/
|
|
303
|
-
declare class OCPPServer extends OCPPServer_base {
|
|
304
|
-
private _options;
|
|
305
|
-
/** Radix trie for O(k) route matching (string patterns). */
|
|
306
|
-
private _trie;
|
|
307
|
-
/** Global middleware routers (server.use() with no patterns — catch-all). */
|
|
308
|
-
private _globalMiddlewareRouters;
|
|
309
|
-
/** Routers with RegExp patterns (fallback linear scan). */
|
|
310
|
-
private _regexRouters;
|
|
311
|
-
private _clients;
|
|
312
|
-
private _clientsByIdentity;
|
|
313
|
-
private _httpServers;
|
|
314
|
-
private _wss;
|
|
315
|
-
private _state;
|
|
316
|
-
private _adapter;
|
|
317
|
-
private _httpServerAbortControllers;
|
|
318
|
-
private _logger;
|
|
319
|
-
private _globalCORS?;
|
|
320
|
-
private _connectionBuckets;
|
|
321
|
-
private readonly _nodeId;
|
|
322
|
-
private _sessions;
|
|
323
|
-
private _gcInterval;
|
|
324
|
-
private readonly _sessionTimeoutMs;
|
|
325
|
-
constructor(options?: ServerOptions);
|
|
326
|
-
get log(): LoggerLikeNotOptional;
|
|
327
|
-
/**
|
|
328
|
-
* Returns a readonly set of all currently connected OCPPServerClient instances.
|
|
329
|
-
*/
|
|
330
|
-
get clients(): ReadonlySet<OCPPServerClient>;
|
|
331
|
-
/**
|
|
332
|
-
* Returns the current server state (OPEN, CLOSING, CLOSED).
|
|
333
|
-
*/
|
|
334
|
-
get state(): "OPEN" | "CLOSING" | "CLOSED";
|
|
335
|
-
/**
|
|
336
|
-
* Returns current node observability statistics
|
|
337
|
-
* (e.g. connected socket count, tracked memory sessions, and process CPU/Memory usage).
|
|
338
|
-
* Fully compatible with Loki/Prometheus node metric ingestion.
|
|
339
|
-
*/
|
|
340
|
-
stats(): OCPPServerStats;
|
|
341
|
-
/**
|
|
342
|
-
* Returns observability statistics from the active Event Adapter (e.g. Redis).
|
|
343
|
-
* Useful for tracking consumer backlog and enabling Horizontal Pod Autoscaling.
|
|
344
|
-
*/
|
|
345
|
-
adapterMetrics(): Promise<Record<string, unknown> | null>;
|
|
346
|
-
/**
|
|
347
|
-
* Synchronously returns the OCPPServerClient instance if the specific identity
|
|
348
|
-
* is connected to THIS local server node.
|
|
349
|
-
* Note: In a clustered environment, clients connected to other nodes will NOT be returned here.
|
|
350
|
-
*
|
|
351
|
-
* @param identity The client identity (username/station ID)
|
|
352
|
-
*/
|
|
353
|
-
getLocalClient(identity: string): OCPPServerClient | undefined;
|
|
354
|
-
/**
|
|
355
|
-
* Synchronously checks if the specific identity is connected to THIS local server node.
|
|
356
|
-
* Note: In a clustered environment, this will return false if the client is connected to another node.
|
|
357
|
-
*
|
|
358
|
-
* @param identity The client identity (username/station ID)
|
|
359
|
-
*/
|
|
360
|
-
hasLocalClient(identity: string): boolean;
|
|
361
|
-
/**
|
|
362
|
-
* Asynchronously checks if the specific identity is connected to the server.
|
|
363
|
-
* In a single-node setup, this checks the local connections.
|
|
364
|
-
* In a clustered setup (with a pub/sub adapter), this will also check the global presence registry
|
|
365
|
-
* to see if the client is connected to ANY node in the cluster.
|
|
366
|
-
*
|
|
367
|
-
* @param identity The client identity (username/station ID)
|
|
368
|
-
*/
|
|
369
|
-
isClientConnected(identity: string): Promise<boolean>;
|
|
370
|
-
/**
|
|
371
|
-
* Applies global CORS rules to all incoming connections before routing.
|
|
372
|
-
*/
|
|
373
|
-
cors(options: CORSOptions): this;
|
|
374
|
-
/**
|
|
375
|
-
* Registers a new routing dispatcher for multiplexing connections.
|
|
376
|
-
* `server.route("/api/:tenant").use(middleware).auth(cb).on("client", ...)`
|
|
377
|
-
*/
|
|
378
|
-
route(...patterns: Array<string | RegExp>): OCPPRouter;
|
|
379
|
-
/**
|
|
380
|
-
* Attaches one or more standalone modular routers created via `createRouter()`.
|
|
381
|
-
* This is useful for separating route definitions across different files.
|
|
382
|
-
*/
|
|
383
|
-
attachRouters(...routers: OCPPRouter[]): this;
|
|
384
|
-
/**
|
|
385
|
-
* Registers a new middleware chain, acting as a wildcard/catch-all router if no patterns are added.
|
|
386
|
-
* `server.use(middleware).route("/api").on("client", ...)`
|
|
387
|
-
*/
|
|
388
|
-
use(...middlewares: ConnectionMiddleware[]): OCPPRouter;
|
|
389
|
-
/**
|
|
390
|
-
* Registers a top-level auth handler, returning a router to attach `.on()` or `.use()`.
|
|
391
|
-
*/
|
|
392
|
-
auth<TSession = Record<string, unknown>>(callback: AuthCallback<TSession>): OCPPRouter;
|
|
393
|
-
/**
|
|
394
|
-
* Routes a router into the appropriate internal structure:
|
|
395
|
-
* - String patterns → radix trie (O(k) lookup)
|
|
396
|
-
* - RegExp patterns → linear fallback array
|
|
397
|
-
* - No patterns → global middleware (catch-all)
|
|
398
|
-
* @internal
|
|
399
|
-
*/
|
|
400
|
-
private _registerRouter;
|
|
401
|
-
listen(port?: number, host?: string, options?: ListenOptions): Promise<Server>;
|
|
402
|
-
/**
|
|
403
|
-
* Hot-reloads the TLS certificate on all active HTTPS servers without
|
|
404
|
-
* dropping any existing WebSocket connections.
|
|
405
|
-
*
|
|
406
|
-
* **When to use:** Call this whenever your TLS certificate is renewed —
|
|
407
|
-
* for example, after a Let's Encrypt auto-renewal (every ~90 days).
|
|
408
|
-
* Without this, you would need to restart the Node.js process to pick up
|
|
409
|
-
* the new certificate, disconnecting all connected charging stations.
|
|
410
|
-
*
|
|
411
|
-
* **How to use:**
|
|
412
|
-
* ```ts
|
|
413
|
-
* server.updateTLS({ cert: newCert, key: newKey });
|
|
414
|
-
* ```
|
|
415
|
-
*
|
|
416
|
-
* **Optional:** Only relevant if you are terminating TLS directly in Node.js
|
|
417
|
-
* (i.e. `SecurityProfile.TLS_BASIC_AUTH` or `TLS_CLIENT_CERT`). If you are
|
|
418
|
-
* running behind a reverse proxy (Nginx, AWS ALB, etc.) that handles TLS,
|
|
419
|
-
* you do not need this method — just rotate the cert on the proxy.
|
|
420
|
-
*
|
|
421
|
-
* @throws If the server is not using a TLS Security Profile.
|
|
422
|
-
*/
|
|
423
|
-
updateTLS(tlsOpts: TLSOptions): void;
|
|
424
|
-
get handleUpgrade(): (req: IncomingMessage, socket: Duplex, head: Buffer) => Promise<void>;
|
|
425
|
-
/**
|
|
426
|
-
* Core upgrade handler. Follows a strict pipeline:
|
|
427
|
-
*
|
|
428
|
-
* 1. Validate socket readyState & upgrade header
|
|
429
|
-
* 2. Parse URL → identity + endpoint
|
|
430
|
-
* 3. Enable TCP Keep-Alive
|
|
431
|
-
* 4. Parse & negotiate subprotocols
|
|
432
|
-
* 5. Parse Basic Auth (via modular parseBasicAuth)
|
|
433
|
-
* 6. Extract TLS client certificate (Profile 3)
|
|
434
|
-
* 7. Build HandshakeInfo
|
|
435
|
-
* 8. Run auth callback with AbortController + handshake timeout
|
|
436
|
-
* 9. Complete WebSocket upgrade
|
|
437
|
-
* 10. Create OCPPServerClient
|
|
438
|
-
*/
|
|
439
|
-
private _handleUpgrade;
|
|
440
|
-
private _updateSessionActivity;
|
|
441
|
-
close(options?: CloseOptions): Promise<void>;
|
|
442
|
-
reconfigure(options: Partial<ServerOptions>): void;
|
|
443
|
-
/**
|
|
444
|
-
* Send a request to a specific client (local or remote).
|
|
445
|
-
*
|
|
446
|
-
* 1. Checks local clients.
|
|
447
|
-
* 2. Checks Presence Registry -> Unicast.
|
|
448
|
-
* 3. Fallback: Broadcast.
|
|
449
|
-
*/
|
|
450
|
-
/**
|
|
451
|
-
* Send a request to a specific client (local or remote).
|
|
452
|
-
*
|
|
453
|
-
* 1. Checks local clients.
|
|
454
|
-
* 2. Checks Presence Registry -> Unicast.
|
|
455
|
-
* 3. Fallback: Error (Client not found).
|
|
456
|
-
*/
|
|
457
|
-
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>;
|
|
458
|
-
sendToClient<M extends AllMethodNames<any>>(identity: string, method: M, params: OCPPRequestType<any, M>, options?: CallOptions): Promise<OCPPResponseType<any, M> | undefined>;
|
|
459
|
-
sendToClient<_T = any>(identity: string, method: string, params: Record<string, any>, options?: CallOptions): Promise<any | undefined>;
|
|
460
|
-
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>;
|
|
461
|
-
safeSendToClient<M extends AllMethodNames<any>>(identity: string, method: M, params: OCPPRequestType<any, M>, options?: CallOptions): Promise<OCPPResponseType<any, M> | undefined>;
|
|
462
|
-
safeSendToClient<_T = any>(identity: string, method: string, params: Record<string, any>, options?: CallOptions): Promise<any | undefined>;
|
|
463
|
-
setAdapter(adapter: EventAdapterInterface): Promise<void>;
|
|
464
|
-
private _onBroadcast;
|
|
465
|
-
private _onUnicast;
|
|
466
|
-
publish(channel: string, data: unknown): Promise<void>;
|
|
467
|
-
broadcast<V extends AllMethodNames<any>>(method: V, params: OCPPRequestType<any, V>): Promise<void>;
|
|
468
|
-
/**
|
|
469
|
-
* Send a specific method & params to a list of specific clients efficiently.
|
|
470
|
-
* This leverages adapter pipelining (e.g. Redis .pipeline()) to minimize network overhead
|
|
471
|
-
* when communicating with thousands of nodes simultaneously.
|
|
472
|
-
*
|
|
473
|
-
* @param identities Array of target client identities
|
|
474
|
-
* @param method The OCPP method to send
|
|
475
|
-
* @param params The request parameters
|
|
476
|
-
* @param options Call options
|
|
477
|
-
*/
|
|
478
|
-
broadcastBatch<V extends AllMethodNames<any>>(identities: string[], method: V, params: OCPPRequestType<any, V>, options?: CallOptions): Promise<void>;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
325
|
declare function getStandardValidators(): Validator[];
|
|
482
326
|
|
|
483
|
-
/**
|
|
484
|
-
* Instantiate a typed RPCError from a string error code.
|
|
485
|
-
* Returns an RPCGenericError if the code is not recognized.
|
|
486
|
-
*/
|
|
487
327
|
declare function createRPCError(code: string, message?: string, details?: Record<string, unknown>): RPCError;
|
|
488
328
|
/**
|
|
489
329
|
* Convert an Error (or subclass) into a plain, JSON-safe object.
|
|
@@ -502,4 +342,4 @@ declare function getErrorPlainObject(err: Error): Record<string, unknown>;
|
|
|
502
342
|
*/
|
|
503
343
|
declare function getPackageIdent(): string;
|
|
504
344
|
|
|
505
|
-
export {
|
|
345
|
+
export { type AdaptedEvent, AdaptiveLimiter, type AdaptiveLimiterOptions, AuthCallback, ClusterDriver, type ClusterDriverOptions, type ClusterNode, ConnectionMiddleware, EventAdapterInterface, InMemoryAdapter, LRUMap, LoggerLike, LoggingConfig, MiddlewareFunction, OCPPPlugin, type RPCError, RPCFormatViolationError, RPCFormationViolationError, RPCFrameworkError, RPCGenericError, RPCInternalError, RPCMessageTypeNotSupportedError, RPCNotImplementedError, RPCNotSupportedError, RPCOccurrenceConstraintViolationError, RPCPropertyConstraintViolationError, RPCProtocolError, RPCSecurityError, RPCTypeConstraintViolationError, TimeoutError, UnexpectedHttpResponse, Validator, WebsocketUpgradeError, combineAuth, createLoggingMiddleware, createPlugin, createRPCError, defineAdapter, defineAuth, defineMiddleware, defineRpcMiddleware, getErrorPlainObject, getPackageIdent, getStandardValidators };
|