You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

zod-ocpp

Package Overview
Dependencies
Maintainers
0
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod-ocpp

Typescript Open Charge Point Protocol v1.6 (ocpp1.6j) validate schema with zod.

1.0.17
latest
Source
npmnpm
Version published
Maintainers
0
Created
Source

zod-ocpp

zod-ocpp is a TypeScript library that provides validation schemas for the Open Charge Point Protocol (OCPP) 1.6J specification using the Zod library. It allows you to validate OCPP 1.6J request and response payloads against the official specification.

Table of contents

Installation

You can install zod-ocpp using npm:

npm install zod-ocpp

Example

Call Validate message

import { CallSchema } from 'zod-ocpp';

const message = [2, '4ae886ab-407d-45a7-839c-3632cf108f53', "Heartbeat", {}];

const result = CallSchema.safeParse(requestPayload);

if (result.success) {
  console.log('Valid payload');
  console.log(result.data);
} else {
  console.error('Invalid payload:', result.error);
}

CallResult Validate message

import { CallResultSchema } from 'zod-ocpp';

const message = [3, '4ae886ab-407d-45a7-839c-3632cf108f53', {currentTime: '2024-03-31T15:01:21.325Z'}];

const result = CallResultSchema.safeParse(message);

if (result.success) {
  console.log('Valid payload');
  console.log(result.data);
} else {
  console.error('Invalid payload:', result.error);
}

CallError Validate message

import { CallErrorSchema } from 'zod-ocpp';

const message = [4, '4ae886ab-407d-45a7-839c-3632cf108f53', 'NotSupported', 'Not support this protocol', {}];

const result = CallErrorSchema.safeParse(message);

if (result.success) {
  console.log('Valid payload');
  console.log(result.data);
} else {
  console.error('Invalid payload:', result.error);
}

BootNotification Validate payload

Request

import { BootNotificationRequestSchema } from 'zod-ocpp';

const requestPayload = {
  chargePointVendor: 'VendorX',
  chargePointModel: 'ModelA',
  chargePointSerialNumber: '123456789',
  chargeBoxSerialNumber: '987654321',
  firmwareVersion: '1.2.3',
  iccid: '89012345678901234567',
  imsi: '123456789012345',
  meterType: 'Metertype1',
  meterSerialNumber: 'ABC123',
};

const result = BootNotificationRequestSchema.safeParse(requestPayload);

if (result.success) {
  console.log('Valid payload');
} else {
  console.error('Invalid payload:', result.error);
}

Response

import { BootNotificationResponseSchema } from 'zod-ocpp';

const responsePayload = {
  status: 'Accepted',
  currentTime: '2024-03-31T15:01:21.325Z',
  interval: 300,
};

const result = BootNotificationResponseSchema.safeParse(responsePayload);

if (result.success) {
  console.log('Valid payload');
  console.log(result.data);
} else {
  console.error('Invalid payload:', result.error);
}

Schema and Enum

Message

Configuration

Types

Keywords

ocpp

FAQs

Package last updated on 16 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts