npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-ocpi

v1.0.10

Published

An OCPI library for Node.js

Downloads

117

Readme

node-ocpi Library Documentation

Tests Made with Love Electric Vehicle Eco Friendly Tree

Overview

node-ocpi is an advanced Node.js library designed for implementing the Open Charge Point Interface (OCPI) protocol. Offering structured models and comprehensive validation for various OCPI entities, it serves as an essential toolkit for developers in the electric vehicle (EV) charging station domain.

Features

  • Extensive models for key OCPI entities including Location, EVSE, Connector, CDR, Command, Feedback, Meter, Reservation, Tariff, User, Transaction, Credentials, ChargingProfilePeriod, ChargingProfile, ActiveChargingProfile, ChargingProfileResponse, ActiveChargingProfileResult, ChargingProfileResult, ClearProfileResult, SetChargingProfile, CommandResult, CommandResponse, DisplayText, EnergyContract, LocationReferences, Token, AuthorizationInfo, and OCPIResponse.
  • Robust validation for OCPI-compliant data structures to ensure data integrity and accuracy.
  • Compatible with a wide range of OCPI operations and functionalities, enhancing EV charging station services development.

Installation

Install node-ocpi using npm:

npm install https://github.com/hyndex/node-ocpi

Usage

Import the required models from node-ocpi:

const {
    Location, EVSE, Connector, CDR, Command, Feedback, Meter, Reservation, Tariff, User, Transaction, Credentials,
    ChargingProfilePeriod, ChargingProfile, ActiveChargingProfile, ChargingProfileResponse, ActiveChargingProfileResult, ChargingProfileResult, ClearProfileResult, SetChargingProfile,
    CommandResult, CommandResponse,
    DisplayText, EnergyContract, LocationReferences, Token, AuthorizationInfo, OCPIResponse
} = require('node-ocpi');

Model Usage Examples

Location Example

const location = new Location({ /* Location data */ });
location.validate();

CommandResult Example

const commandResult = new CommandResult({
    result: 'ACCEPTED',
    message: 'Command successfully executed'
});
commandResult.validate();

CommandResponse Example

const commandResponse = new CommandResponse({
    result: 'REJECTED',
    timeout: 30,
    message: 'Command could not be executed'
});
commandResponse.validate();

OCPIResponse Example

const ocpiResponse = new OCPIResponse({
    statusCode: 2000,
    statusMessage: 'Success',
    timestamp: new Date().toISOString(),
    data: { /* Your data object or array */ }
});
OCPIResponse.schema(YOUR_MODEL_SCHEMA).validate(ocpiResponse);

... (Continue with other models similarly)

Integration with Express.js

Integrate node-ocpi in Express.js applications for efficient handling of OCPI data:

const express = require('express');
const { Location } = require('node-ocpi');

const app = express();
app.use(express.json());

app.post('/locations', (req, res) => {
  try {
    const location = new Location(req.body);
    location.validate();
    res.status(201).send(location);
  } catch (error) {
    res.status(400).send(error.message);
  }
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Contributing

Contributions are welcome:

  1. Fork the repository.
  2. Create a new feature branch.
  3. Develop your feature or fix.
  4. Write or adapt tests.
  5. Update the documentation.
  6. Commit and push your changes.
  7. Submit a pull request.

License

node-ocpi is released under the MIT License. See LICENSE for details.