ocpp-ws-io 1.0.0-alpha
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.
Potentially problematic release.
This version of ocpp-ws-io might be problematic. Click here for more details.
- package/.github/workflows/publish.yml +52 -0
- package/LICENSE +21 -0
- package/README.md +773 -0
- package/dist/adapters/redis.d.mts +73 -0
- package/dist/adapters/redis.d.ts +73 -0
- package/dist/adapters/redis.js +96 -0
- package/dist/adapters/redis.js.map +1 -0
- package/dist/adapters/redis.mjs +71 -0
- package/dist/adapters/redis.mjs.map +1 -0
- package/dist/index.d.mts +268 -0
- package/dist/index.d.ts +268 -0
- package/dist/index.js +38919 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +38855 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types-6LVUoXof.d.mts +284 -0
- package/dist/types-6LVUoXof.d.ts +284 -0
- package/package.json +59 -0
- package/src/adapters/adapter.ts +40 -0
- package/src/adapters/redis.ts +144 -0
- package/src/client.ts +882 -0
- package/src/errors.ts +183 -0
- package/src/event-buffer.ts +73 -0
- package/src/index.ts +68 -0
- package/src/queue.ts +65 -0
- package/src/schemas/ocpp1_6.json +2376 -0
- package/src/schemas/ocpp2_0_1.json +11878 -0
- package/src/schemas/ocpp2_1.json +23176 -0
- package/src/server-client.ts +65 -0
- package/src/server.ts +374 -0
- package/src/standard-validators.ts +18 -0
- package/src/types.ts +316 -0
- package/src/util.ts +119 -0
- package/src/validator.ts +148 -0
- package/src/ws-util.ts +186 -0
- package/test/adapter.test.ts +88 -0
- package/test/client.test.ts +297 -0
- package/test/errors.test.ts +132 -0
- package/test/queue.test.ts +133 -0
- package/test/server.test.ts +274 -0
- package/test/util.test.ts +103 -0
- package/test/ws-util.test.ts +93 -0
- package/tsconfig.json +25 -0
- package/tsup.config.ts +16 -0
- package/vitest.config.ts +10 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import * as node_http from 'node:http';
|
|
2
|
+
import { Server, IncomingMessage } from 'node:http';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
import WebSocket, { WebSocket as WebSocket$1 } from 'ws';
|
|
5
|
+
import { C as ClientOptions, a as ConnectionState, S as SecurityProfile, b as CloseOptions, W as WildcardHandler, c as CallHandler, d as CallOptions, H as HandshakeInfo, e as ServerOptions, A as AuthCallback, L as ListenOptions, E as EventAdapterInterface, V as Validator } from './types-6LVUoXof.js';
|
|
6
|
+
export { f as AuthAccept, g as ClientEvents, h as HandlerContext, M as MessageType, N as NOREPLY, O as OCPPCall, i as OCPPCallError, j as OCPPCallResult, k as OCPPMessage, l as OCPPProtocol, m as ServerEvents, n as SessionData, T as TLSOptions, o as createValidator } from './types-6LVUoXof.js';
|
|
7
|
+
import { Duplex } from 'node:stream';
|
|
8
|
+
import 'node:https';
|
|
9
|
+
import 'node:tls';
|
|
10
|
+
import 'ajv';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* OCPPClient — A typed WebSocket RPC client for OCPP communication.
|
|
14
|
+
*
|
|
15
|
+
* Supports all 3 OCPP Security Profiles:
|
|
16
|
+
* - Profile 1: Basic Auth over unsecured WS
|
|
17
|
+
* - Profile 2: TLS + Basic Auth
|
|
18
|
+
* - Profile 3: Mutual TLS (client certificates)
|
|
19
|
+
*/
|
|
20
|
+
declare class OCPPClient extends EventEmitter {
|
|
21
|
+
static readonly CONNECTING: 0;
|
|
22
|
+
static readonly OPEN: 1;
|
|
23
|
+
static readonly CLOSING: 2;
|
|
24
|
+
static readonly CLOSED: 3;
|
|
25
|
+
protected _options: Required<Pick<ClientOptions, "identity" | "endpoint" | "callTimeoutMs" | "pingIntervalMs" | "deferPingsOnActivity" | "callConcurrency" | "maxBadMessages" | "respondWithDetailedErrors" | "reconnect" | "maxReconnects" | "backoffMin" | "backoffMax">> & ClientOptions;
|
|
26
|
+
protected _state: ConnectionState;
|
|
27
|
+
protected _ws: WebSocket | null;
|
|
28
|
+
protected _protocol: string | undefined;
|
|
29
|
+
protected _identity: string;
|
|
30
|
+
private _handlers;
|
|
31
|
+
private _wildcardHandler;
|
|
32
|
+
private _pendingCalls;
|
|
33
|
+
private _pendingResponses;
|
|
34
|
+
private _callQueue;
|
|
35
|
+
private _pingTimer;
|
|
36
|
+
private _closePromise;
|
|
37
|
+
private _reconnectAttempt;
|
|
38
|
+
private _reconnectTimer;
|
|
39
|
+
private _badMessageCount;
|
|
40
|
+
private _lastActivity;
|
|
41
|
+
private _validators;
|
|
42
|
+
private _strictProtocols;
|
|
43
|
+
protected _handshake: unknown;
|
|
44
|
+
constructor(options: ClientOptions);
|
|
45
|
+
get identity(): string;
|
|
46
|
+
get protocol(): string | undefined;
|
|
47
|
+
get state(): ConnectionState;
|
|
48
|
+
get securityProfile(): SecurityProfile;
|
|
49
|
+
connect(): Promise<{
|
|
50
|
+
response: node_http.IncomingMessage;
|
|
51
|
+
}>;
|
|
52
|
+
private _connectInternal;
|
|
53
|
+
close(options?: CloseOptions): Promise<{
|
|
54
|
+
code: number;
|
|
55
|
+
reason: string;
|
|
56
|
+
}>;
|
|
57
|
+
private _closeInternal;
|
|
58
|
+
handle<TParams = unknown, TResult = unknown>(methodOrHandler: string | WildcardHandler, handler?: CallHandler<TParams, TResult>): void;
|
|
59
|
+
removeHandler(method?: string): void;
|
|
60
|
+
removeAllHandlers(): void;
|
|
61
|
+
call<TResult = unknown>(method: string, params?: unknown, options?: CallOptions): Promise<TResult>;
|
|
62
|
+
private _sendCall;
|
|
63
|
+
/**
|
|
64
|
+
* Send a raw string message over the WebSocket (use with caution).
|
|
65
|
+
*/
|
|
66
|
+
sendRaw(message: string): void;
|
|
67
|
+
reconfigure(options: Partial<ClientOptions>): void;
|
|
68
|
+
protected _attachWebsocket(ws: WebSocket): void;
|
|
69
|
+
private _onMessage;
|
|
70
|
+
private _handleIncomingCall;
|
|
71
|
+
private _handleCallResult;
|
|
72
|
+
private _handleCallError;
|
|
73
|
+
private _onBadMessage;
|
|
74
|
+
private _onClose;
|
|
75
|
+
private _scheduleReconnect;
|
|
76
|
+
private _startPing;
|
|
77
|
+
private _stopPing;
|
|
78
|
+
private _recordActivity;
|
|
79
|
+
private _setupValidators;
|
|
80
|
+
private _validateOutbound;
|
|
81
|
+
private _validateInbound;
|
|
82
|
+
private _findValidator;
|
|
83
|
+
private _buildEndpoint;
|
|
84
|
+
private _buildWsOptions;
|
|
85
|
+
private _cleanup;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* OCPPServerClient — A server-side client representation.
|
|
90
|
+
*
|
|
91
|
+
* Created by OCPPServer when a charging station connects.
|
|
92
|
+
* Extends OCPPClient but is pre-connected (cannot call connect()).
|
|
93
|
+
*/
|
|
94
|
+
declare class OCPPServerClient extends OCPPClient {
|
|
95
|
+
private _serverSession;
|
|
96
|
+
private _serverHandshake;
|
|
97
|
+
constructor(options: ClientOptions, context: {
|
|
98
|
+
ws: WebSocket$1;
|
|
99
|
+
handshake: HandshakeInfo;
|
|
100
|
+
session: Record<string, unknown>;
|
|
101
|
+
});
|
|
102
|
+
/**
|
|
103
|
+
* Session data associated with this client connection.
|
|
104
|
+
*/
|
|
105
|
+
get session(): Record<string, unknown>;
|
|
106
|
+
/**
|
|
107
|
+
* Handshake information from the initial connection.
|
|
108
|
+
*/
|
|
109
|
+
get handshake(): HandshakeInfo;
|
|
110
|
+
/**
|
|
111
|
+
* Server clients cannot initiate connections.
|
|
112
|
+
* @throws Always throws — use OCPPClient for outbound connections.
|
|
113
|
+
*/
|
|
114
|
+
connect(): Promise<never>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* OCPPServer — A typed WebSocket RPC server for OCPP communication.
|
|
119
|
+
*
|
|
120
|
+
* Supports all 3 OCPP Security Profiles:
|
|
121
|
+
* - Profile 1: Basic Auth over unsecured WS
|
|
122
|
+
* - Profile 2: TLS + Basic Auth (HTTPS server)
|
|
123
|
+
* - Profile 3: Mutual TLS (HTTPS server with requestCert)
|
|
124
|
+
*/
|
|
125
|
+
declare class OCPPServer extends EventEmitter {
|
|
126
|
+
private _options;
|
|
127
|
+
private _authCallback;
|
|
128
|
+
private _clients;
|
|
129
|
+
private _httpServers;
|
|
130
|
+
private _wss;
|
|
131
|
+
private _adapter;
|
|
132
|
+
private _httpServerAbortControllers;
|
|
133
|
+
constructor(options?: ServerOptions);
|
|
134
|
+
get clients(): ReadonlySet<OCPPServerClient>;
|
|
135
|
+
auth(callback: AuthCallback): void;
|
|
136
|
+
listen(port?: number, host?: string, options?: ListenOptions): Promise<Server>;
|
|
137
|
+
get handleUpgrade(): (req: IncomingMessage, socket: Duplex, head: Buffer) => Promise<void>;
|
|
138
|
+
private _handleUpgrade;
|
|
139
|
+
close(options?: CloseOptions): Promise<void>;
|
|
140
|
+
reconfigure(options: Partial<ServerOptions>): void;
|
|
141
|
+
setAdapter(adapter: EventAdapterInterface): void;
|
|
142
|
+
publish(channel: string, data: unknown): Promise<void>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Pre-built validators for all supported OCPP protocol versions.
|
|
147
|
+
* These are automatically registered when strict mode is enabled.
|
|
148
|
+
*/
|
|
149
|
+
declare const standardValidators: Validator[];
|
|
150
|
+
|
|
151
|
+
declare class TimeoutError extends Error {
|
|
152
|
+
constructor(message?: string);
|
|
153
|
+
}
|
|
154
|
+
declare class UnexpectedHttpResponse extends Error {
|
|
155
|
+
readonly statusCode: number;
|
|
156
|
+
readonly headers: Record<string, string | string[] | undefined>;
|
|
157
|
+
constructor(message: string, statusCode: number, headers?: Record<string, string | string[] | undefined>);
|
|
158
|
+
}
|
|
159
|
+
declare class WebsocketUpgradeError extends Error {
|
|
160
|
+
constructor(message?: string);
|
|
161
|
+
}
|
|
162
|
+
interface RPCError extends Error {
|
|
163
|
+
readonly rpcErrorCode: string;
|
|
164
|
+
readonly rpcErrorMessage: string;
|
|
165
|
+
readonly details: Record<string, unknown>;
|
|
166
|
+
}
|
|
167
|
+
declare class RPCGenericError extends Error implements RPCError {
|
|
168
|
+
readonly rpcErrorCode: string;
|
|
169
|
+
readonly rpcErrorMessage: string;
|
|
170
|
+
readonly details: Record<string, unknown>;
|
|
171
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
172
|
+
}
|
|
173
|
+
declare class RPCNotImplementedError extends RPCGenericError {
|
|
174
|
+
readonly rpcErrorCode = "NotImplemented";
|
|
175
|
+
readonly rpcErrorMessage = "Requested method is not known";
|
|
176
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
177
|
+
}
|
|
178
|
+
declare class RPCNotSupportedError extends RPCGenericError {
|
|
179
|
+
readonly rpcErrorCode = "NotSupported";
|
|
180
|
+
readonly rpcErrorMessage = "Requested method is recognised but not supported";
|
|
181
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
182
|
+
}
|
|
183
|
+
declare class RPCInternalError extends RPCGenericError {
|
|
184
|
+
readonly rpcErrorCode = "InternalError";
|
|
185
|
+
readonly rpcErrorMessage = "An internal error occurred and the receiver was not able to process the requested action successfully";
|
|
186
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
187
|
+
}
|
|
188
|
+
declare class RPCProtocolError extends RPCGenericError {
|
|
189
|
+
readonly rpcErrorCode = "ProtocolError";
|
|
190
|
+
readonly rpcErrorMessage = "Payload for action is incomplete";
|
|
191
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
192
|
+
}
|
|
193
|
+
declare class RPCSecurityError extends RPCGenericError {
|
|
194
|
+
readonly rpcErrorCode = "SecurityError";
|
|
195
|
+
readonly rpcErrorMessage = "During the processing of action a security issue occurred preventing receiver from completing the action successfully";
|
|
196
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
197
|
+
}
|
|
198
|
+
declare class RPCFormationViolationError extends RPCGenericError {
|
|
199
|
+
readonly rpcErrorCode = "FormationViolation";
|
|
200
|
+
readonly rpcErrorMessage = "Payload for action is syntactically incorrect or not conform the PDU structure for action";
|
|
201
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
202
|
+
}
|
|
203
|
+
declare class RPCFormatViolationError extends RPCGenericError {
|
|
204
|
+
readonly rpcErrorCode = "FormatViolation";
|
|
205
|
+
readonly rpcErrorMessage = "Payload is syntactically correct but at least one field contains an invalid value";
|
|
206
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
207
|
+
}
|
|
208
|
+
declare class RPCPropertyConstraintViolationError extends RPCGenericError {
|
|
209
|
+
readonly rpcErrorCode = "PropertyConstraintViolation";
|
|
210
|
+
readonly rpcErrorMessage = "Payload is syntactically correct but at least one of the fields violates data type constraints";
|
|
211
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
212
|
+
}
|
|
213
|
+
declare class RPCOccurrenceConstraintViolationError extends RPCGenericError {
|
|
214
|
+
readonly rpcErrorCode = "OccurrenceConstraintViolation";
|
|
215
|
+
readonly rpcErrorMessage = "Payload for action is syntactically correct but at least one of the fields violates occurrence constraints";
|
|
216
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
217
|
+
}
|
|
218
|
+
declare class RPCTypeConstraintViolationError extends RPCGenericError {
|
|
219
|
+
readonly rpcErrorCode = "TypeConstraintViolation";
|
|
220
|
+
readonly rpcErrorMessage = "Payload for action is syntactically correct but at least one of the fields violates type constraints";
|
|
221
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
222
|
+
}
|
|
223
|
+
declare class RPCMessageTypeNotSupportedError extends RPCGenericError {
|
|
224
|
+
readonly rpcErrorCode = "MessageTypeNotSupported";
|
|
225
|
+
readonly rpcErrorMessage = "A message with a Message Type Number received that is not supported by this implementation";
|
|
226
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
227
|
+
}
|
|
228
|
+
declare class RPCFrameworkError extends RPCGenericError {
|
|
229
|
+
readonly rpcErrorCode = "RpcFrameworkError";
|
|
230
|
+
readonly rpcErrorMessage = "Content of the call is not a valid RPC request";
|
|
231
|
+
constructor(message?: string, details?: Record<string, unknown>);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Instantiate a typed RPCError from a string error code.
|
|
236
|
+
* Returns an RPCGenericError if the code is not recognized.
|
|
237
|
+
*/
|
|
238
|
+
declare function createRPCError(code: string, message?: string, details?: Record<string, unknown>): RPCError;
|
|
239
|
+
/**
|
|
240
|
+
* Convert an Error (or subclass) into a plain, JSON-safe object.
|
|
241
|
+
*
|
|
242
|
+
* Extracts well-known properties explicitly rather than relying on
|
|
243
|
+
* Object.getOwnPropertyNames to avoid exposing internal fields and
|
|
244
|
+
* to guarantee a stable output shape.
|
|
245
|
+
*
|
|
246
|
+
* If a property holds a non-serializable value (functions, symbols,
|
|
247
|
+
* circular references), it is silently skipped.
|
|
248
|
+
*/
|
|
249
|
+
declare function getErrorPlainObject(err: Error): Record<string, unknown>;
|
|
250
|
+
/**
|
|
251
|
+
* Get the package identifier string used in HTTP headers and logging.
|
|
252
|
+
* Format: `ocpp-ws-io/1.0.0`
|
|
253
|
+
*/
|
|
254
|
+
declare function getPackageIdent(): string;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* In-memory event adapter for single-process use.
|
|
258
|
+
* Events are dispatched synchronously within the same process.
|
|
259
|
+
*/
|
|
260
|
+
declare class InMemoryAdapter implements EventAdapterInterface {
|
|
261
|
+
private _channels;
|
|
262
|
+
publish(channel: string, data: unknown): Promise<void>;
|
|
263
|
+
subscribe(channel: string, handler: (data: unknown) => void): Promise<void>;
|
|
264
|
+
unsubscribe(channel: string): Promise<void>;
|
|
265
|
+
disconnect(): Promise<void>;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export { AuthCallback, CallHandler, CallOptions, ClientOptions, CloseOptions, ConnectionState, EventAdapterInterface, HandshakeInfo, InMemoryAdapter, ListenOptions, OCPPClient, OCPPServer, OCPPServerClient, type RPCError, RPCFormatViolationError, RPCFormationViolationError, RPCFrameworkError, RPCGenericError, RPCInternalError, RPCMessageTypeNotSupportedError, RPCNotImplementedError, RPCNotSupportedError, RPCOccurrenceConstraintViolationError, RPCPropertyConstraintViolationError, RPCProtocolError, RPCSecurityError, RPCTypeConstraintViolationError, SecurityProfile, ServerOptions, TimeoutError, UnexpectedHttpResponse, Validator, WebsocketUpgradeError, WildcardHandler, createRPCError, getErrorPlainObject, getPackageIdent, standardValidators };
|