ocpp-ws-io 2.1.15 → 2.2.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.
- package/README.md +271 -170
- package/dist/adapters/redis.d.mts +2 -2
- package/dist/adapters/redis.d.ts +2 -2
- package/dist/adapters/redis.js +1 -1
- package/dist/adapters/redis.mjs +1 -1
- package/dist/browser.d.mts +11 -0
- package/dist/browser.d.ts +11 -0
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/{index-s9f97CmV.d.ts → index-BefjKqkS.d.ts} +1 -1
- package/dist/{index-C0mn42-8.d.mts → index-Defn9aOS.d.mts} +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -7
- package/dist/index.mjs +7 -7
- package/dist/plugins.d.mts +1017 -26
- package/dist/plugins.d.ts +1017 -26
- package/dist/plugins.js +1 -1
- package/dist/plugins.mjs +1 -1
- package/dist/{types-BZXEmDQ1.d.mts → types-BHIHsj__.d.mts} +144 -3
- package/dist/{types-BZXEmDQ1.d.ts → types-BHIHsj__.d.ts} +144 -3
- package/package.json +17 -13
|
@@ -4735,6 +4735,16 @@ declare class OCPPClient<P extends OCPPProtocol = OCPPProtocol> extends OCPPClie
|
|
|
4735
4735
|
sendRaw(message: string): void;
|
|
4736
4736
|
reconfigure(options: Partial<ClientOptions>): void;
|
|
4737
4737
|
protected _attachWebsocket(ws: WebSocket__default): void;
|
|
4738
|
+
/**
|
|
4739
|
+
* Build an enriched message event context from middleware context.
|
|
4740
|
+
* Adds timestamp and optional latency metadata.
|
|
4741
|
+
*/
|
|
4742
|
+
private _buildMessageEventContext;
|
|
4743
|
+
/**
|
|
4744
|
+
* Emit a message event with enriched payload (direction + context).
|
|
4745
|
+
* Replaces separate call/callResult/callError events for unified observability.
|
|
4746
|
+
*/
|
|
4747
|
+
private _emitMessageEvent;
|
|
4738
4748
|
protected _onMessage(rawData: WebSocket__default.RawData, preParsed?: unknown): void;
|
|
4739
4749
|
private _handleIncomingCall;
|
|
4740
4750
|
private _handleCallResult;
|
|
@@ -4762,6 +4772,11 @@ declare class OCPPClient<P extends OCPPProtocol = OCPPProtocol> extends OCPPClie
|
|
|
4762
4772
|
private _callWithRetry;
|
|
4763
4773
|
/** Maximum bytes allowed in the ws send buffer before applying backpressure (512KB) */
|
|
4764
4774
|
private static readonly _BACKPRESSURE_THRESHOLD;
|
|
4775
|
+
/**
|
|
4776
|
+
* Protected hook for plugins to intercept outbound messages before serialization.
|
|
4777
|
+
* Return `false` to suppress the message transmission.
|
|
4778
|
+
*/
|
|
4779
|
+
protected _invokeBeforeSend(_message: OCPPMessage): boolean | Promise<boolean>;
|
|
4765
4780
|
/**
|
|
4766
4781
|
* Wraps ws.send() with backpressure protection.
|
|
4767
4782
|
* If bufferedAmount exceeds the threshold, waits for the buffer to drain
|
|
@@ -4826,6 +4841,8 @@ declare class WorkerPool {
|
|
|
4826
4841
|
declare class OCPPServerClient extends OCPPClient {
|
|
4827
4842
|
private _serverSession;
|
|
4828
4843
|
private _serverHandshake;
|
|
4844
|
+
/** Plugins passed from OCPPServer for hook execution */
|
|
4845
|
+
private _serverPlugins;
|
|
4829
4846
|
constructor(options: ClientOptions, context: {
|
|
4830
4847
|
ws: WebSocket$1;
|
|
4831
4848
|
handshake: HandshakeInfo;
|
|
@@ -4835,11 +4852,14 @@ declare class OCPPServerClient extends OCPPClient {
|
|
|
4835
4852
|
adaptiveMultiplier?: () => number;
|
|
4836
4853
|
/** Optional worker pool for off-thread JSON parsing */
|
|
4837
4854
|
workerPool?: WorkerPool;
|
|
4855
|
+
/** Plugins from the server for hook execution */
|
|
4856
|
+
plugins?: OCPPPlugin[];
|
|
4838
4857
|
});
|
|
4839
4858
|
private _rateLimits;
|
|
4840
4859
|
private _adaptiveMultiplier;
|
|
4841
4860
|
private _workerPool;
|
|
4842
4861
|
private _checkRateLimit;
|
|
4862
|
+
protected _invokeBeforeSend(message: OCPPMessage): boolean | Promise<boolean>;
|
|
4843
4863
|
private _attachServerWebsocket;
|
|
4844
4864
|
private _handleRateLimitExceeded;
|
|
4845
4865
|
/**
|
|
@@ -4899,6 +4919,7 @@ declare class OCPPServer extends OCPPServer_base {
|
|
|
4899
4919
|
private _adaptiveLimiter;
|
|
4900
4920
|
private _plugins;
|
|
4901
4921
|
private _workerPool;
|
|
4922
|
+
private _telemetryInterval;
|
|
4902
4923
|
private readonly _nodeId;
|
|
4903
4924
|
private _sessions;
|
|
4904
4925
|
private _gcInterval;
|
|
@@ -4977,6 +4998,11 @@ declare class OCPPServer extends OCPPServer_base {
|
|
|
4977
4998
|
* ```
|
|
4978
4999
|
*/
|
|
4979
5000
|
plugin(...plugins: OCPPPlugin[]): this;
|
|
5001
|
+
/**
|
|
5002
|
+
* Starts the periodic telemetry push engine if configured.
|
|
5003
|
+
* Pushes OCPPServerStats to all plugins implementing onTelemetry.
|
|
5004
|
+
*/
|
|
5005
|
+
private _startTelemetryPush;
|
|
4980
5006
|
/**
|
|
4981
5007
|
* Registers middleware chain(s) as a wildcard/catch-all router.
|
|
4982
5008
|
*
|
|
@@ -5621,6 +5647,15 @@ interface ServerOptionsBase {
|
|
|
5621
5647
|
* (default: false)
|
|
5622
5648
|
*/
|
|
5623
5649
|
compression?: boolean | CompressionOptions;
|
|
5650
|
+
/**
|
|
5651
|
+
* Telemetry configuration for plugin stats push.
|
|
5652
|
+
* When configured and plugins implement `onTelemetry`, the server will
|
|
5653
|
+
* push `OCPPServerStats` at the configured interval.
|
|
5654
|
+
* - `{ pushIntervalMs: 10000 }` → push stats every 10s
|
|
5655
|
+
* - `{ pushIntervalMs: 0 }` → disable periodic push
|
|
5656
|
+
* (default: disabled)
|
|
5657
|
+
*/
|
|
5658
|
+
telemetry?: TelemetryConfig;
|
|
5624
5659
|
}
|
|
5625
5660
|
/** When strictMode is enabled, protocols MUST be specified */
|
|
5626
5661
|
interface StrictServerOptions extends ServerOptionsBase {
|
|
@@ -5633,6 +5668,13 @@ interface RelaxedServerOptions extends ServerOptionsBase {
|
|
|
5633
5668
|
protocols?: AnyOCPPProtocol[];
|
|
5634
5669
|
}
|
|
5635
5670
|
type ServerOptions = StrictServerOptions | RelaxedServerOptions;
|
|
5671
|
+
interface TelemetryConfig {
|
|
5672
|
+
/**
|
|
5673
|
+
* Interval in ms to push server stats to plugins via `onTelemetry`.
|
|
5674
|
+
* Set to 0 to disable. (default: 0 — disabled)
|
|
5675
|
+
*/
|
|
5676
|
+
pushIntervalMs?: number;
|
|
5677
|
+
}
|
|
5636
5678
|
interface OCPPServerStats {
|
|
5637
5679
|
/** Number of currently connected WebSockets */
|
|
5638
5680
|
connectedClients: number;
|
|
@@ -5669,6 +5711,30 @@ interface AuthAccept<TSession = Record<string, unknown>> {
|
|
|
5669
5711
|
session?: TSession;
|
|
5670
5712
|
}
|
|
5671
5713
|
type AuthCallback<TSession = Record<string, unknown>> = (ctx: AuthContext<TSession>) => void | Promise<void>;
|
|
5714
|
+
/** Indicates whether a message is incoming (from peer) or outgoing (to peer) */
|
|
5715
|
+
type MessageDirection = "IN" | "OUT";
|
|
5716
|
+
/**
|
|
5717
|
+
* Enriched context for message events, combining metadata from middleware
|
|
5718
|
+
* and message flow tracking. Uses type intersection since MiddlewareContext is a union.
|
|
5719
|
+
*/
|
|
5720
|
+
type MessageEventContext = MiddlewareContext & {
|
|
5721
|
+
/** Message timestamp (ISO 8601) */
|
|
5722
|
+
timestamp: string;
|
|
5723
|
+
/** Latency in milliseconds (only for responses/results) */
|
|
5724
|
+
latencyMs?: number;
|
|
5725
|
+
};
|
|
5726
|
+
/**
|
|
5727
|
+
* Enriched message event payload with direction and context.
|
|
5728
|
+
* Replaces the simple OCPPMessage tuple for better observability.
|
|
5729
|
+
*/
|
|
5730
|
+
interface MessageEventPayload {
|
|
5731
|
+
/** The raw OCPP message */
|
|
5732
|
+
message: OCPPMessage;
|
|
5733
|
+
/** Direction of the message: IN (from peer) or OUT (to peer) */
|
|
5734
|
+
direction: MessageDirection;
|
|
5735
|
+
/** Enriched context with metadata */
|
|
5736
|
+
ctx: MessageEventContext;
|
|
5737
|
+
}
|
|
5672
5738
|
interface ClientEvents {
|
|
5673
5739
|
open: [{
|
|
5674
5740
|
response: IncomingMessage;
|
|
@@ -5689,7 +5755,7 @@ interface ClientEvents {
|
|
|
5689
5755
|
attempt: number;
|
|
5690
5756
|
delay: number;
|
|
5691
5757
|
}];
|
|
5692
|
-
message: [
|
|
5758
|
+
message: [MessageEventPayload];
|
|
5693
5759
|
call: [OCPPCall];
|
|
5694
5760
|
callResult: [OCPPCallResult];
|
|
5695
5761
|
callError: [OCPPCallError];
|
|
@@ -5697,6 +5763,20 @@ interface ClientEvents {
|
|
|
5697
5763
|
message: string;
|
|
5698
5764
|
error: Error;
|
|
5699
5765
|
}];
|
|
5766
|
+
handlerError: [{
|
|
5767
|
+
method: string;
|
|
5768
|
+
error: Error;
|
|
5769
|
+
}];
|
|
5770
|
+
pongTimeout: [{
|
|
5771
|
+
identity: string;
|
|
5772
|
+
}];
|
|
5773
|
+
backpressure: [{
|
|
5774
|
+
identity: string;
|
|
5775
|
+
bufferedAmount: number;
|
|
5776
|
+
}];
|
|
5777
|
+
rateLimitExceeded: [{
|
|
5778
|
+
rawData: unknown;
|
|
5779
|
+
}];
|
|
5700
5780
|
ping: [];
|
|
5701
5781
|
pong: [];
|
|
5702
5782
|
strictValidationFailure: [{
|
|
@@ -5711,7 +5791,7 @@ interface ClientEvents {
|
|
|
5711
5791
|
*/
|
|
5712
5792
|
interface SecurityEvent {
|
|
5713
5793
|
/** Event type identifier */
|
|
5714
|
-
type: "AUTH_FAILED" | "RATE_LIMIT_EXCEEDED" | "UPGRADE_ABORTED" | "CONNECTION_RATE_LIMIT" | "INVALID_PAYLOAD";
|
|
5794
|
+
type: "AUTH_FAILED" | "RATE_LIMIT_EXCEEDED" | "UPGRADE_ABORTED" | "CONNECTION_RATE_LIMIT" | "INVALID_PAYLOAD" | "ANOMALY_RAPID_RECONNECT" | "ANOMALY_AUTH_BRUTE_FORCE" | "ANOMALY_MESSAGE_FUZZING" | "ANOMALY_IDENTITY_COLLISION";
|
|
5715
5795
|
/** Station identity (if known) */
|
|
5716
5796
|
identity?: string;
|
|
5717
5797
|
/** Remote IP address */
|
|
@@ -5740,6 +5820,8 @@ interface ServerEvents {
|
|
|
5740
5820
|
close: [];
|
|
5741
5821
|
/** I3: Structured security event for SIEM/audit pipelines */
|
|
5742
5822
|
securityEvent: [SecurityEvent];
|
|
5823
|
+
/** Enriched message event with direction and context */
|
|
5824
|
+
message: [MessageEventPayload];
|
|
5743
5825
|
connection: [
|
|
5744
5826
|
socket: WebSocket.WebSocket,
|
|
5745
5827
|
request: node_http.IncomingMessage
|
|
@@ -5803,6 +5885,54 @@ interface OCPPPlugin {
|
|
|
5803
5885
|
onDisconnect?(client: OCPPServerClient, code: number, reason: string): void;
|
|
5804
5886
|
/** Called during server.close() for plugin cleanup */
|
|
5805
5887
|
onClose?(): void | Promise<void>;
|
|
5888
|
+
/**
|
|
5889
|
+
* Called for every OCPP message (IN + OUT, CALL + CALLRESULT + CALLERROR).
|
|
5890
|
+
* Provides unified observability over all message traffic.
|
|
5891
|
+
*/
|
|
5892
|
+
onMessage?(client: OCPPServerClient, payload: MessageEventPayload): void | Promise<void>;
|
|
5893
|
+
/**
|
|
5894
|
+
* Called before a received message is parsed/routed.
|
|
5895
|
+
* Return `false` to silently drop the message.
|
|
5896
|
+
*/
|
|
5897
|
+
onBeforeReceive?(client: OCPPServerClient, rawData: unknown): undefined | boolean | Promise<undefined | boolean>;
|
|
5898
|
+
/**
|
|
5899
|
+
* Called before a message is transmitted on the wire.
|
|
5900
|
+
* Return `false` to suppress the send.
|
|
5901
|
+
*/
|
|
5902
|
+
onBeforeSend?(client: OCPPServerClient, message: OCPPMessage): undefined | boolean | Promise<undefined | boolean>;
|
|
5903
|
+
/** WebSocket-level or protocol-level error */
|
|
5904
|
+
onError?(client: OCPPServerClient, error: Error): void | Promise<void>;
|
|
5905
|
+
/** Malformed / unparseable message received */
|
|
5906
|
+
onBadMessage?(client: OCPPServerClient, rawMessage: string, error: Error): void | Promise<void>;
|
|
5907
|
+
/** Schema validation failure (strictMode) */
|
|
5908
|
+
onValidationFailure?(client: OCPPServerClient, message: unknown, error: Error): void | Promise<void>;
|
|
5909
|
+
/** Message dropped or client disconnected due to rate limiting */
|
|
5910
|
+
onRateLimitExceeded?(client: OCPPServerClient, rawData: unknown): void | Promise<void>;
|
|
5911
|
+
/** User handler threw an error during CALL processing */
|
|
5912
|
+
onHandlerError?(client: OCPPServerClient, method: string, error: Error): void | Promise<void>;
|
|
5913
|
+
/** Structured security events (AUTH_FAILED, UPGRADE_ABORTED, etc.) */
|
|
5914
|
+
onSecurityEvent?(event: SecurityEvent): void | Promise<void>;
|
|
5915
|
+
/** Auth attempt failed — visible even when onConnection never fires */
|
|
5916
|
+
onAuthFailed?(handshake: HandshakeInfo, code: number, reason: string): void | Promise<void>;
|
|
5917
|
+
/** Existing client with same identity was evicted by a new connection */
|
|
5918
|
+
onEviction?(evictedClient: OCPPServerClient, newClient: OCPPServerClient): void | Promise<void>;
|
|
5919
|
+
/** Send buffer exceeded backpressure threshold (512KB — slow client) */
|
|
5920
|
+
onBackpressure?(client: OCPPServerClient, bufferedAmount: number): void | Promise<void>;
|
|
5921
|
+
/** Pong not received within timeout — dead peer detected */
|
|
5922
|
+
onPongTimeout?(client: OCPPServerClient): void | Promise<void>;
|
|
5923
|
+
/** Periodic server stats snapshot (opt-in via `telemetry.pushIntervalMs`) */
|
|
5924
|
+
onTelemetry?(stats: OCPPServerStats, adapterMetrics?: Record<string, unknown>): void | Promise<void>;
|
|
5925
|
+
/**
|
|
5926
|
+
* Plugin contributes custom Prometheus metric lines to the /metrics endpoint.
|
|
5927
|
+
* Return an array of Prometheus exposition format strings.
|
|
5928
|
+
*/
|
|
5929
|
+
getCustomMetrics?(): string[] | Promise<string[]>;
|
|
5930
|
+
/** Server options changed via server.reconfigure() */
|
|
5931
|
+
onReconfigure?(newOptions: Partial<ServerOptions>, oldOptions: ServerOptions): void | Promise<void>;
|
|
5932
|
+
/** TLS certificates hot-reloaded via server.updateTLS() */
|
|
5933
|
+
onTLSUpdate?(tlsOpts: TLSOptions): void | Promise<void>;
|
|
5934
|
+
/** Server entering CLOSING state — pre-shutdown hook (before clients are drained) */
|
|
5935
|
+
onClosing?(): void | Promise<void>;
|
|
5806
5936
|
}
|
|
5807
5937
|
declare const NOREPLY: unique symbol;
|
|
5808
5938
|
type MiddlewareContext = {
|
|
@@ -5827,6 +5957,17 @@ type MiddlewareContext = {
|
|
|
5827
5957
|
messageId: string;
|
|
5828
5958
|
error: OCPPCallError;
|
|
5829
5959
|
method: string;
|
|
5960
|
+
} | {
|
|
5961
|
+
type: "outgoing_result";
|
|
5962
|
+
messageId: string;
|
|
5963
|
+
method: string;
|
|
5964
|
+
payload: unknown;
|
|
5965
|
+
} | {
|
|
5966
|
+
type: "outgoing_error";
|
|
5967
|
+
messageId: string;
|
|
5968
|
+
method: string;
|
|
5969
|
+
errorCode: string;
|
|
5970
|
+
errorDescription: string;
|
|
5830
5971
|
};
|
|
5831
5972
|
|
|
5832
5973
|
interface BaseConnectionContext {
|
|
@@ -5849,4 +5990,4 @@ interface AuthContext<TSession = Record<string, unknown>> extends BaseConnection
|
|
|
5849
5990
|
}
|
|
5850
5991
|
type ConnectionMiddleware = (ctx: ConnectionContext) => Promise<void> | void;
|
|
5851
5992
|
|
|
5852
|
-
export {
|
|
5993
|
+
export { type ServerOptions as $, type AuthCallback as A, type OCPPCallError as B, type ConnectionMiddleware as C, type OCPPCallResult as D, type EventAdapterInterface as E, OCPPClient as F, type OCPPMessage as G, type HandlerContext as H, type OCPPMethodMap as I, type OCPPProtocol as J, type OCPPProtocolKey as K, type LoggerLike as L, type MiddlewareFunction as M, NOREPLY as N, type OCPPPlugin as O, type OCPPRequestType as P, type OCPPResponseType as Q, OCPPRouter as R, OCPPServer as S, OCPPServerClient as T, type OCPPServerStats as U, Validator as V, type RateLimitOptions as W, type RouterConfig as X, type SecurityEvent as Y, SecurityProfile as Z, type ServerEvents as _, type LoggingConfig as a, type SessionData as a0, type TLSOptions as a1, type TelemetryConfig as a2, type TypedEventEmitter as a3, type WildcardHandler as a4, createRouter as a5, createValidator as a6, type MiddlewareContext as b, type AllMethodNames as c, type AnyOCPPProtocol as d, type AuthAccept as e, type CORSOptions as f, type CallHandler as g, type CallOptions as h, type ClientEvents as i, type ClientOptions as j, type CloseOptions as k, type CompressionOptions as l, type ConnectionContext as m, ConnectionState as n, type HandshakeInfo as o, type ListenOptions as p, type MessageDirection as q, type MessageEventContext as r, type MessageEventPayload as s, MessageType as t, type MiddlewareNext as u, MiddlewareStack as v, type OCPP16Methods as w, type OCPP201Methods as x, type OCPP21Methods as y, type OCPPCall as z };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ocpp-ws-io",
|
|
3
|
-
"version": "2.1
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.2.1",
|
|
4
|
+
"description": "OCPP RPC WebSocket client and server for OCPP 1.6J, 2.0.1, and 2.1. Type-safe TypeScript toolkit for EV charging, CSMS backends, Redis scaling, and protocol validation.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/rohittiwari-dev/ocpp-ws-io.git"
|
|
@@ -42,47 +42,51 @@
|
|
|
42
42
|
"test": "vitest run",
|
|
43
43
|
"test:watch": "vitest",
|
|
44
44
|
"test:coverage": "vitest run --coverage",
|
|
45
|
-
"prepublishOnly": "
|
|
45
|
+
"prepublishOnly": "bun run build"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=18.0.0"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"ocpp",
|
|
52
|
+
"ocpp-rpc",
|
|
52
53
|
"ocpp-j",
|
|
53
54
|
"ocpp1.6",
|
|
54
55
|
"ocpp1.6j",
|
|
55
56
|
"ocpp2.0.1",
|
|
57
|
+
"ocpp2.0.1j",
|
|
56
58
|
"ocpp2.1",
|
|
57
59
|
"websocket",
|
|
60
|
+
"ocpp-websocket",
|
|
58
61
|
"rpc",
|
|
62
|
+
"websocket-rpc",
|
|
59
63
|
"json-rpc",
|
|
64
|
+
"ocpp-client",
|
|
65
|
+
"ocpp-server",
|
|
66
|
+
"charge-point",
|
|
67
|
+
"charging-station",
|
|
60
68
|
"ev-charging",
|
|
61
69
|
"evse",
|
|
62
70
|
"csms",
|
|
63
71
|
"cpo",
|
|
64
72
|
"emsp",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"smart-charging",
|
|
69
|
-
"electric-vehicle",
|
|
70
|
-
"e-mobility",
|
|
71
|
-
"iso15118",
|
|
73
|
+
"wamp",
|
|
74
|
+
"rpc-server",
|
|
75
|
+
"rpc-client",
|
|
72
76
|
"type-safe",
|
|
73
77
|
"typescript",
|
|
78
|
+
"node",
|
|
74
79
|
"nodejs",
|
|
75
80
|
"redis",
|
|
81
|
+
"redis-pubsub",
|
|
76
82
|
"clustering",
|
|
77
|
-
"pubsub",
|
|
78
83
|
"browser",
|
|
79
84
|
"simulator",
|
|
80
85
|
"ocpp-simulator",
|
|
81
|
-
"nodejs-library",
|
|
82
86
|
"testing-cli",
|
|
83
87
|
"ocpp-testing",
|
|
84
88
|
"ocpp-implementation",
|
|
85
|
-
"ocpp-
|
|
89
|
+
"ocpp-protocol"
|
|
86
90
|
],
|
|
87
91
|
"author": "Rohit Tiwari <rohit@rohittiwari.me>",
|
|
88
92
|
"homepage": "https://ocpp-ws-io.rohittiwari.me",
|