chirpstack/api/js
Orne Brocaar 103e4298fb Add device-profile option to configure region configuration.
By selecting a region configuration, devices using the device-profile
will only stick to the selected region configuration, rather than the
configurations provided by the selected region common-name.

This change also renames the region 'name' option to 'id' in the region
configuration, as well it adds a 'description' to provide a human
readable description, which is used in the drop-down in the UI.

This also fixes the JS API generation. In a previous commit the the
protobuf package was updated, but the latest protobuf compiler no longer
supports generating JS code (this now requires an external plugin). This
has been fixed.

Please note that if you have implemented custom ADR algorithms that are
referring to the 'regionName' key, that you must change this to
'regionConfigId' (see the ADR code example).
2023-01-09 12:04:10 +00:00
..
api Add device-profile option to configure region configuration. 2023-01-09 12:04:10 +00:00
common Re-generate API + update code. 2022-12-05 11:46:36 +00:00
google/api Re-generate API + update code. 2022-12-05 11:46:36 +00:00
gw Re-generate API + update code. 2022-12-05 11:46:36 +00:00
integration Re-generate API + update code. 2022-12-05 11:46:36 +00:00
meta Re-generate API + update code. 2022-12-05 11:46:36 +00:00
Makefile Implement api request logging to Redis Streams. 2022-11-28 10:59:28 +00:00
package.json Bump version to 4.1.3 2022-12-27 11:14:43 +00:00
README.md Initial commit. 2022-04-06 21:18:32 +01:00
yarn.lock Update JS API dependencies to latest versions. 2022-12-13 10:57:54 +00:00

chirpstack-api

ChirpStack gRPC API message and service wrappers for Javascript. Typescript definitions are included.

Install

With npm:

npm install @chirpstack/chirpstack-api --save

Or with yarn:

yarn add @chirpstack/chirpstack-api

Usage

All messages, services, constants, etc. are auto-generated from the ChirpStack protobuf definitions. The result is that this package structure matches that of the protobuf definitions. There is no ES6 index gathering all of the exports, so full import/require paths should be used. The generated code is all callback based, but can be promisified.

The protobuf definitions can be found here: https://github.com/brocaar/chirpstack-api/tree/master/protobuf

The generated code all depends on the grpc package, and for most use cases you will probably need to make use of the grpc package directly as well. This is seen in the example below.

Example

This example shows how to log in to ChirpStack via the gRPC API and then create a gRPC metadata object containing the JWT. This metadata could then be passed to any future requests that require authorization.

import * as grpc from '@grpc/grpc-js';

import * as internalService from '@chirpstack/chirpstack-api/as/external/api/internal_grpc_pb';
import * as internalMessages from '@chirpstack/chirpstack-api/as/external/api/internal_pb';

// Create the client for the 'internal' service
const internalServiceClient = new internalService.InternalServiceClient(
    'localhost:8080',
    grpc.credentials.createInsecure()
);

// Create and build the login request message
const loginRequest = new internalMessages.LoginRequest();

loginRequest.setEmail('email');
loginRequest.setPassword('password');

// Send the login request
internalServiceClient.login(loginRequest, (error, response) => {
    // Build a gRPC metadata object, setting the authorization key to the JWT we
    // got back from logging in.
    const metadata = new grpc.Metadata();
    metadata.set('authorization', response.getJwt());

    // This metadata can now be passed for requests to APIs that require authorization
    // e.g.
    // deviceServiceClient.create(createDeviceRequest, metadata, callback);
});