Project Setup & Generation
Commands for scaffolding projects, generating types, and managing certificates.
ocpp generate
Generates a custom protocol's TypeScript types, the augmentation that declares it to ocpp-ws-io, and its strict-mode validator, all from one JSON schema file, so the types and what strict mode validates always agree.
Usage
ocpp generate [options]Options
| Option | Alias | Default | Description |
|---|---|---|---|
--schema | -s | - | Schema URL or local file path. |
--name | -n | - | Subprotocol name (e.g. my-custom-protocol). |
--out | -o | ./@types/ocpp-ws-io | Output directory for the generated files. |
Example
ocpp generate --schema ./custom-schemas/station.json --name vendor-extensions --out ./src/typesOutput
| File | What it holds |
|---|---|
<name>.ts | The request and response types of each action, the SEND messages (unconfirmed, as in OCPP 2.1), and the …Methods and …SendMethods maps. An object the schema leaves open (no additionalProperties: false) takes any JSON keys. |
augment.d.ts | Declares the protocol in OCPPMethodMap, and in OCPPSendMethodMap when it has SEND messages, so clients, servers and routes configured with it are typed. |
<name>.validator.ts | The strict-mode validator, createValidator("<protocol>", schemas), typed with the protocol. |
Schema $ids name the actions: urn:<Action>.req and urn:<Action>.conf (as in OCPP 1.6 and 2.0.1), urn:<Action>Request and urn:<Action>Response (as in OCPP 2.1), and urn:<Message> for a SEND message.
import { OCPPServer } from "ocpp-ws-io";
import { vendorExtensionsValidator } from "./types/vendorextensions.validator.js";
const server = new OCPPServer({
protocols: ["ocpp2.0.1", "vendor-extensions"],
strictMode: true,
strictModeValidators: [vendorExtensionsValidator],
});Run ocpp generate again when the schemas change: it rewrites all three files together.
ocpp certs
A local TLS Certificate Authority (CA) manager. It helps you generate self-signed certificates for development and testing of secure WebSocket connections (WSS).
Usage
ocpp certs [options]Options
| Option | Alias | Default | Description |
|---|---|---|---|
--type | -t | server | Type of certificate to generate: ca, server, or client. |
--identity | -i | - | Common Name (CN) for the certificate (e.g., CP-001, localhost). |
--out | -o | ./certs | Output directory for generated certificates and keys. |
Workflow Example
-
Generate a Root CA:
ocpp certs --type caThis creates
ca.keyandca.crt. -
Generate a Server Certificate (signed by CA):
ocpp certs --type server --identity localhostThis creates
server.keyandserver.crt. -
Generate a Client Certificate (for a Charge Point):
ocpp certs --type client --identity CP-001This creates
client.keyandclient.crt.