# @chargetrip/javascript-sdk

> Javascript developer kit

Latest version **1.3.6** (published 2025-02-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install @chargetrip/javascript-sdk
pnpm add @chargetrip/javascript-sdk
yarn add @chargetrip/javascript-sdk
bun add @chargetrip/javascript-sdk
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.6 |
| Published | 2025-02-27 |
| First published | 2025-02-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 11 |
| Unpacked size | 484.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | wouter125, timkuilman, laurensvdmaas, chargetrip-dev |

## Links

- npm: https://www.npmjs.com/package/@chargetrip/javascript-sdk
- npm.io page: https://npm.io/package/@chargetrip/javascript-sdk

## Dependencies (11)

- [geojson](https://npm.io/package/geojson.md) ^0.5.0
- [graphql](https://npm.io/package/graphql.md) ^16.9.0
- [graphql-ws](https://npm.io/package/graphql-ws.md) ^5.16.0
- [@turf/along](https://npm.io/package/@turf/along.md) ^7.2.0
- [@turf/length](https://npm.io/package/@turf/length.md) ^7.2.0
- [@turf/helpers](https://npm.io/package/@turf/helpers.md) ^7.2.0
- [ts-method-cache](https://npm.io/package/ts-method-cache.md) ^3.3.1
- [@mapbox/polyline](https://npm.io/package/@mapbox/polyline.md) ^1.2.1
- [@rollup/plugin-commonjs](https://npm.io/package/@rollup/plugin-commonjs.md) ^28.0.2
- [@chargetrip/vue3-components](https://npm.io/package/@chargetrip/vue3-components.md) ^4.0.0-beta.83
- [@turf/nearest-point-on-line](https://npm.io/package/@turf/nearest-point-on-line.md) ^7.2.0

## Recent versions

- 1.3.6 (latest) — 2025-02-27
- 1.3.5 — 2025-02-25
- 1.3.4 — 2025-02-25
- 1.3.3 — 2025-02-25
- 1.3.2 — 2025-02-21
- 1.3.1 — 2025-02-20
- 1.3.0 — 2025-02-20
- 1.2.24 — 2025-02-20
- 1.2.23 — 2025-02-19
- 1.2.22 — 2025-02-18
- 1.2.21 — 2025-02-18
- 1.2.20 — 2025-02-18
- 1.2.19 — 2025-02-18
- 1.2.18 — 2025-02-18
- 1.2.17 — 2025-02-18
- … 31 more at https://npm.io/package/@chargetrip/javascript-sdk/versions

## README

# Javascript SDK

The development folder has a small app that uses all the modules, use this for example / development.

Note: some of modules require specific propties. Check the types the module you want to use and make sure you're query matches, type-errors/runtime errors will be thrown if it doesn't match the spec

## Fetcher

Simple fetcher for GraphQL endpoints, initialize like:

```
const fetcher = new Fetcher({
    headers: {
      Referer: 'http://localhost:5174/',
      'content-type': 'application/json',
      'x-app-id': 'YOUR_APP_ID_HERE',
      'x-client-id': 'YOUR_CLIENT_ID_HERE',
    },
    baseUrl: "https://chargetrip.io",
    wsBaseUrl: "wss://chargetrip.io"
})
```

You can fetch any query you want with `query<Query, Variables>()` (you can obtain the VehicleQuery type with [codegen](https://the-guild.dev/graphql/codegen/docs/getting-started)):

```
const response = await fetcher.query<VehicleQuery, VehicleQueryVariables>({
  query: VEHICLE_QUERY,
  variables: { id: vehicleId },
})
```

The fetcher class also has a build in `getRoute` method which automatically starts a subscription if the route has status `pending` or `processing`:

```
fetcher.getRoute<GetRouteV2Query, RouteV2Subscription, GetRouteV2QueryVariables>({
  query: ROUTE_QUERY,
  subscription: ROUTE_SUBSCRIPTION,
  variables: { id: routeId },
})
```

## Breakdown (exact name tbd.)

Used for rendering the journey/route overview, use like:

_Parameters:_

```
export interface BreakdownConfig {
  legs: BreakdownLegInput[];
  departureDate?: Date;
  stations?: BreakdownStationInput[]; // Provide your own stations and we will attach them to the output.
}
```

Usage:

```
const module = new BreakdownModule({
    legs: route.recommended?.legs.filter(isDefined) || [],
    stations: stations
})
```

Now that the module is initiated we can use it to get the following:

```
module.isReady // Promise to wait for stations to load, only if you pass the fetcher, otherwise it will be ready instantly.
module.originName // legs[0].origin.properties?.name
module.destinationName // legs[this.legs.length - 1].destination.properties?.name
module.totalCost // Total cost of the route.
module.breakdown // BreakdownItem[]
```

## Mapbox

Usage:

```
const module = new MapboxHelper({
  map: map, // Mapbox Map reference
  stations: stations,
  routeDetails: routeDetails,
  styling: Styling,
})
```

Now that the module is initiated we can use it to get the following:

```
module.draw() // Draws everything below
module.drawPolyline // Draws polyline + polyline border
module.drawMarkers // Draws origin / destination / stations / mapbox markers
module.drawOrigin
module.drawDestination
module.addMarker // Add a custom marker
module.drawStations
module.drawAlternativeStations

module.center // Centers map based on route polyline.
module.toggleAlternativeStations
module.toggleLayerVisibility
module.setLayerVisibility
module.addLayerToMap
module.removeAllLayers
module.removeAllMarkers
module.removeLayer
module.setRouteDetails // update route details, automatically re-draws the layers
module.setStations // update stations, automatically re-draws the layers
```

## Pricing

Usage:

```
const module = new Pricing({ evses: station?.evses?.filter(isDefined) || [] })
```

Now that the module is initiated we can use it to get the following:

```
module.standards // List of reduced connector standards with supported powers
module.getPrice({ connector: connector, partnerId: partner }) // Get price by partner id
```

After module.getPrice we get the full pricing object, you can calculate prices yourself or use `PriceFormatter` to handle this for you.

Usage:

```
const module = new PriceFormatter({ price: price, consumption: 50, duration: 60 * 15 })
module.currency // Currency used.
module.totalPrice // Total price of charging
module.flatFee // Flat fee (included in total price).
module.idleFee // Idle fee (included in total price).
```

---
_Source: https://npm.io/package/@chargetrip/javascript-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
