ocpp-ws-io 2.1.15 → 2.2.0

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/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { O as OCPPPlugin } from './types-BZXEmDQ1.js';
1
+ import { O as OCPPPlugin } from './types-BunMs45p.js';
2
2
  import 'ws';
3
3
  import 'node:https';
4
4
  import 'node:http';
@@ -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;
@@ -5669,6 +5679,30 @@ interface AuthAccept<TSession = Record<string, unknown>> {
5669
5679
  session?: TSession;
5670
5680
  }
5671
5681
  type AuthCallback<TSession = Record<string, unknown>> = (ctx: AuthContext<TSession>) => void | Promise<void>;
5682
+ /** Indicates whether a message is incoming (from peer) or outgoing (to peer) */
5683
+ type MessageDirection = "IN" | "OUT";
5684
+ /**
5685
+ * Enriched context for message events, combining metadata from middleware
5686
+ * and message flow tracking. Uses type intersection since MiddlewareContext is a union.
5687
+ */
5688
+ type MessageEventContext = MiddlewareContext & {
5689
+ /** Message timestamp (ISO 8601) */
5690
+ timestamp: string;
5691
+ /** Latency in milliseconds (only for responses/results) */
5692
+ latencyMs?: number;
5693
+ };
5694
+ /**
5695
+ * Enriched message event payload with direction and context.
5696
+ * Replaces the simple OCPPMessage tuple for better observability.
5697
+ */
5698
+ interface MessageEventPayload {
5699
+ /** The raw OCPP message */
5700
+ message: OCPPMessage;
5701
+ /** Direction of the message: IN (from peer) or OUT (to peer) */
5702
+ direction: MessageDirection;
5703
+ /** Enriched context with metadata */
5704
+ ctx: MessageEventContext;
5705
+ }
5672
5706
  interface ClientEvents {
5673
5707
  open: [{
5674
5708
  response: IncomingMessage;
@@ -5689,7 +5723,7 @@ interface ClientEvents {
5689
5723
  attempt: number;
5690
5724
  delay: number;
5691
5725
  }];
5692
- message: [OCPPMessage];
5726
+ message: [MessageEventPayload];
5693
5727
  call: [OCPPCall];
5694
5728
  callResult: [OCPPCallResult];
5695
5729
  callError: [OCPPCallError];
@@ -5740,6 +5774,8 @@ interface ServerEvents {
5740
5774
  close: [];
5741
5775
  /** I3: Structured security event for SIEM/audit pipelines */
5742
5776
  securityEvent: [SecurityEvent];
5777
+ /** Enriched message event with direction and context */
5778
+ message: [MessageEventPayload];
5743
5779
  connection: [
5744
5780
  socket: WebSocket.WebSocket,
5745
5781
  request: node_http.IncomingMessage
@@ -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;
@@ -5669,6 +5679,30 @@ interface AuthAccept<TSession = Record<string, unknown>> {
5669
5679
  session?: TSession;
5670
5680
  }
5671
5681
  type AuthCallback<TSession = Record<string, unknown>> = (ctx: AuthContext<TSession>) => void | Promise<void>;
5682
+ /** Indicates whether a message is incoming (from peer) or outgoing (to peer) */
5683
+ type MessageDirection = "IN" | "OUT";
5684
+ /**
5685
+ * Enriched context for message events, combining metadata from middleware
5686
+ * and message flow tracking. Uses type intersection since MiddlewareContext is a union.
5687
+ */
5688
+ type MessageEventContext = MiddlewareContext & {
5689
+ /** Message timestamp (ISO 8601) */
5690
+ timestamp: string;
5691
+ /** Latency in milliseconds (only for responses/results) */
5692
+ latencyMs?: number;
5693
+ };
5694
+ /**
5695
+ * Enriched message event payload with direction and context.
5696
+ * Replaces the simple OCPPMessage tuple for better observability.
5697
+ */
5698
+ interface MessageEventPayload {
5699
+ /** The raw OCPP message */
5700
+ message: OCPPMessage;
5701
+ /** Direction of the message: IN (from peer) or OUT (to peer) */
5702
+ direction: MessageDirection;
5703
+ /** Enriched context with metadata */
5704
+ ctx: MessageEventContext;
5705
+ }
5672
5706
  interface ClientEvents {
5673
5707
  open: [{
5674
5708
  response: IncomingMessage;
@@ -5689,7 +5723,7 @@ interface ClientEvents {
5689
5723
  attempt: number;
5690
5724
  delay: number;
5691
5725
  }];
5692
- message: [OCPPMessage];
5726
+ message: [MessageEventPayload];
5693
5727
  call: [OCPPCall];
5694
5728
  callResult: [OCPPCallResult];
5695
5729
  callError: [OCPPCallError];
@@ -5740,6 +5774,8 @@ interface ServerEvents {
5740
5774
  close: [];
5741
5775
  /** I3: Structured security event for SIEM/audit pipelines */
5742
5776
  securityEvent: [SecurityEvent];
5777
+ /** Enriched message event with direction and context */
5778
+ message: [MessageEventPayload];
5743
5779
  connection: [
5744
5780
  socket: WebSocket.WebSocket,
5745
5781
  request: node_http.IncomingMessage
package/package.json CHANGED
@@ -1,111 +1,115 @@
1
1
  {
2
- "name": "ocpp-ws-io",
3
- "version": "2.1.15",
4
- "description": "Type-safe OCPP 1.6 & 2.0.1 WebSocket RPC client & server. Build EV charging CSMS platforms with Redis clustering, strict validation, and DDoS protection.",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/rohittiwari-dev/ocpp-ws-io.git"
8
- },
9
- "main": "dist/index.js",
10
- "module": "dist/index.mjs",
11
- "types": "dist/index.d.ts",
12
- "exports": {
13
- ".": {
14
- "types": "./dist/index.d.ts",
15
- "import": "./dist/index.mjs",
16
- "require": "./dist/index.js"
17
- },
18
- "./adapters/redis": {
19
- "types": "./dist/adapters/redis.d.ts",
20
- "import": "./dist/adapters/redis.mjs",
21
- "require": "./dist/adapters/redis.js"
22
- },
23
- "./browser": {
24
- "types": "./dist/browser.d.ts",
25
- "import": "./dist/browser.mjs",
26
- "require": "./dist/browser.js"
27
- },
28
- "./logger": {
29
- "types": "./dist/logger.d.ts",
30
- "import": "./dist/logger.mjs",
31
- "require": "./dist/logger.js"
32
- },
33
- "./plugins": {
34
- "types": "./dist/plugins.d.ts",
35
- "import": "./dist/plugins.mjs",
36
- "require": "./dist/plugins.js"
37
- }
38
- },
39
- "scripts": {
40
- "build": "tsup",
41
- "generate": "node scripts/generate-types.js",
42
- "test": "vitest run",
43
- "test:watch": "vitest",
44
- "test:coverage": "vitest run --coverage",
45
- "prepublishOnly": "npm run build"
46
- },
47
- "engines": {
48
- "node": ">=18.0.0"
49
- },
50
- "keywords": [
51
- "ocpp",
52
- "ocpp-j",
53
- "ocpp1.6",
54
- "ocpp1.6j",
55
- "ocpp2.0.1",
56
- "ocpp2.1",
57
- "websocket",
58
- "rpc",
59
- "json-rpc",
60
- "ev-charging",
61
- "evse",
62
- "csms",
63
- "cpo",
64
- "emsp",
65
- "charge-point",
66
- "charging-station",
67
- "charge-point-simulator",
68
- "smart-charging",
69
- "electric-vehicle",
70
- "e-mobility",
71
- "iso15118",
72
- "type-safe",
73
- "typescript",
74
- "nodejs",
75
- "redis",
76
- "clustering",
77
- "pubsub",
78
- "browser",
79
- "simulator",
80
- "ocpp-simulator",
81
- "nodejs-library",
82
- "testing-cli",
83
- "ocpp-testing",
84
- "ocpp-implementation",
85
- "ocpp-docs"
86
- ],
87
- "author": "Rohit Tiwari <rohit@rohittiwari.me>",
88
- "homepage": "https://ocpp-ws-io.rohittiwari.me",
89
- "bugs": {
90
- "url": "https://github.com/rohittiwari-dev/ocpp-ws-io/issues"
91
- },
92
- "files": [
93
- "dist"
94
- ],
95
- "license": "MIT",
96
- "dependencies": {
97
- "ajv": "^8.18.0",
98
- "ajv-formats": "^3.0.1",
99
- "voltlog-io": "^1.0.8",
100
- "ws": "^8.19.0"
101
- },
102
- "devDependencies": {
103
- "@types/node": "^22.19.11",
104
- "@types/ws": "^8.18.1",
105
- "@vitest/coverage-v8": "^3.2.4",
106
- "ioredis-mock": "^8.13.1",
107
- "tsup": "^8.5.1",
108
- "typescript": "^5.9.3",
109
- "vitest": "^3.2.4"
110
- }
2
+ "name": "ocpp-ws-io",
3
+ "version": "2.2.0",
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
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/rohittiwari-dev/ocpp-ws-io.git"
8
+ },
9
+ "main": "dist/index.js",
10
+ "module": "dist/index.mjs",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.js"
17
+ },
18
+ "./adapters/redis": {
19
+ "types": "./dist/adapters/redis.d.ts",
20
+ "import": "./dist/adapters/redis.mjs",
21
+ "require": "./dist/adapters/redis.js"
22
+ },
23
+ "./browser": {
24
+ "types": "./dist/browser.d.ts",
25
+ "import": "./dist/browser.mjs",
26
+ "require": "./dist/browser.js"
27
+ },
28
+ "./logger": {
29
+ "types": "./dist/logger.d.ts",
30
+ "import": "./dist/logger.mjs",
31
+ "require": "./dist/logger.js"
32
+ },
33
+ "./plugins": {
34
+ "types": "./dist/plugins.d.ts",
35
+ "import": "./dist/plugins.mjs",
36
+ "require": "./dist/plugins.js"
37
+ }
38
+ },
39
+ "scripts": {
40
+ "build": "tsup",
41
+ "generate": "node scripts/generate-types.js",
42
+ "test": "vitest run",
43
+ "test:watch": "vitest",
44
+ "test:coverage": "vitest run --coverage",
45
+ "prepublishOnly": "npm run build"
46
+ },
47
+ "engines": {
48
+ "node": ">=18.0.0"
49
+ },
50
+ "keywords": [
51
+ "ocpp",
52
+ "ocpp-rpc",
53
+ "ocpp-j",
54
+ "ocpp1.6",
55
+ "ocpp1.6j",
56
+ "ocpp2.0.1",
57
+ "ocpp2.0.1j",
58
+ "ocpp2.1",
59
+ "websocket",
60
+ "ocpp-websocket",
61
+ "rpc",
62
+ "websocket-rpc",
63
+ "json-rpc",
64
+ "ocpp-client",
65
+ "ocpp-server",
66
+ "charge-point",
67
+ "charging-station",
68
+ "ev-charging",
69
+ "evse",
70
+ "csms",
71
+ "cpo",
72
+ "emsp",
73
+ "wamp",
74
+ "rpc-server",
75
+ "rpc-client",
76
+ "type-safe",
77
+ "typescript",
78
+ "node",
79
+ "nodejs",
80
+ "redis",
81
+ "redis-pubsub",
82
+ "clustering",
83
+ "browser",
84
+ "simulator",
85
+ "ocpp-simulator",
86
+ "testing-cli",
87
+ "ocpp-testing",
88
+ "ocpp-implementation",
89
+ "ocpp-protocol"
90
+ ],
91
+ "author": "Rohit Tiwari <rohit@rohittiwari.me>",
92
+ "homepage": "https://ocpp-ws-io.rohittiwari.me",
93
+ "bugs": {
94
+ "url": "https://github.com/rohittiwari-dev/ocpp-ws-io/issues"
95
+ },
96
+ "files": [
97
+ "dist"
98
+ ],
99
+ "license": "MIT",
100
+ "dependencies": {
101
+ "ajv": "^8.18.0",
102
+ "ajv-formats": "^3.0.1",
103
+ "voltlog-io": "^1.0.8",
104
+ "ws": "^8.19.0"
105
+ },
106
+ "devDependencies": {
107
+ "@types/node": "^22.19.11",
108
+ "@types/ws": "^8.18.1",
109
+ "@vitest/coverage-v8": "^3.2.4",
110
+ "ioredis-mock": "^8.13.1",
111
+ "tsup": "^8.5.1",
112
+ "typescript": "^5.9.3",
113
+ "vitest": "^3.2.4"
114
+ }
111
115
  }