
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
iot-stack-client
Advanced tools
A client library written in Typescript to interact with the IoT-stack API. Link back to the full documentation here.
This library makes use of RxJS (Reactive Extensions for JavaScript). RxJS is a library for reactive programming using observables that makes it easier to compose asynchronous or callback-based code (RxJS). We make use of version 6 and its syntax: no more use of method chaining, put using the pipe()
operator instead), for more information on that see the RxJS 6 migration section.
RxJS 6 comes as a peer dependency.
The client has a clear purpose:
The client uses keycloak's javascript library to connect to our back-end keycloak Authorization Server. This should handle:
With the client you create Endpoints. These endpoints can be acted on with methods like execute()
or get()
. An endpoint takes an API uri as argument. This means that the HTTP REST api is as important to you, as this API.
npm install iot-stack-client rxjs --save
To start you need to create an IotClient instance with a proper options object. Do this through the static create
facory function. This will return an Observable, because setting everything up is an asnychronous operation. By subscribing to the client you know for sure that it is initialized.
import { pipe } from 'rxjs';
import { share, flatMap } from 'rxjs/operators';
# Create shareable observable. (caches the client object)
const options = {
config: {
host: 'https://idlab-iot.tengu.io',
apiVersion: 'v1',
realm: 'idlab-iot',
clientId: 'my-client',
},
initOptions: {
checkLoginIframe: false
}
}
let clientObs = IotClient.create(options).pipe(share());
# Use it to request the scopes you have access to
clientObs
.pipe(
flatMap(client => client.endpoint('/context/scopes').get())
)
.subscribe(
console.log,
console.error
)
The .pipe(share())
operator at the end allows you to subscribe with different listeneres, without reinitializing the client each time. This way you can start every interaction with the client as an rx chain from clientObs
.
In the Swagger UI (see full IoT-stack documentation) you can see which datastructures are returned.
Datastructures
Purpose | Use method | Description |
---|---|---|
Pull TemporalPage | .temporalPageEndpoint(uri) : TPageEndpoint | Getting data in the TemporalPage format |
Stream TemporalPage data | .streamEndpoint(uri): StreamEndpoint | Stream current data in TemporalPage format |
Use any other API call | .endpoint(uri) : Endpoint | Execute any other API call |
Methods
Object | Method | Description |
---|---|---|
TPageEndpoint | .execute(): Obserable<TPageResponse> | Executes the call, if a range was requested, it will automatically request the whole range. |
StreamEndpoint | .connect(options) : Observable<TPage> | Connects with this endpoint as an eventsource. Use options to filter the stream. |
Endpoint | .get(): Observable<AjaxResponse> | Executes a get on a normal endpoint. |
Endpoint | .post(body): Observable<AjaxResponse> | Executes a post on a normal endpoint. |
Endpoint | .put(body): Observable<AjaxResponse> | Executes a put on a normal endpoint. |
Endpoint | .delete(): Observable<AjaxResponse> | Executes a delete on a normal endpoint. |
All these methods will add Auth headers as needed. And try to refresh the token if it expired.
To request timerange, you do what you would do with the HTTP REST API. For instance:
# Make timestamp eg. with moment library
const now = moment().valueOf();
const yesterday = moment().subtract(1,'day').valueOf();
const uri = '/scopes/myscope/locations/u155/airquality.no2/events?from='+yesterday+'+&to='+now;
# Use shared observable
clientObs
.pipe(
flatMap(client => client.temporalPageEndpoint(uri).execute())
)
.subscribe(
data => console.log(data),
error => console.error(error),
() => console.log('done')
);
If you are logged in it will handle all the tokens in the headers for you.
FAQs
Typescript client to intereact with the IoT-stack on higher level
The npm package iot-stack-client receives a total of 10 weekly downloads. As such, iot-stack-client popularity was classified as not popular.
We found that iot-stack-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.