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

creator-js-client

v2.0.2

Published

JS client library for creator device server.

Downloads

15

Readme

logo

Creator JS client

This js client allows you to use The Creator IoT Framework, giving the possibility to quickly implement a client, to consume the Device Server REST API.

build status


Table of Contents

Getting Started

To install the client

$ npm install creator-js-client

Jump Start

In order to be able to utilize this library you will have to sign up for a creator account. You can do so going through the Creator Developer Console

After signing up, you will need to create an access key and secret pair from the API keys section of the console. These will gain you access to the Creator REST API while using this library.

You can then create an instance of the library as follows:

var creator = require('creator-js-client')('CREATOR_ACCESS_KEY', 'CREATOR_ACCESS_SECRET');

Please note that you can also set the following environment variables for the library to use.

  • CREATOR_ACCESS_KEY
  • CREATOR_ACCESS_SECRET

and then

var creator = require('creator-js-client')();

Now you should have a working instance of the library that you can use to access your resources RESTfully.

As you may already know, creator rest api is using what is called the HATEOAS REST application structure which means that you need to follow links in order to reach to certain resources. This library will do that for you. Please keep reading!

Accessing The Resources

Using this library you have two main ways of accessing resources.

  1. Using the raw request method
  2. Using the service layer functions

Please note that regrdless of the method chosen to access resources, data types of the arguments that you pass in are very important. For example if you are filtering down for the ObjectID 3201 then it needs to be passed in as a String -> '3201' rather than in the form of an integer.

1. The Request Method

The request method provide a very flexible way of accessing any resource you would like to interact with.

The structure for this method is as follows:

creator.request({
    // Options
}, function(data){
    // Do something with data
});

Now this method can be used to GET, POST, PUT or DELETE resources on the API.

GET example

creator.request({
    steps: ['clients']
}, function(clients){
    console.log(clients);
});

This will fetch you an array of your clients talking to the DeviceServer.

PUT example

creator.request({
    method: 'PUT',
    steps: ['clients', {Name: 'CLIENT_NAME'}, 'objecttypes', {ObjectTypeID: '3201'}, 'instances', {InstanceID: '0'}],
    data: {
        DigitalOutputState: true
    }
}, function(cb){});

When you run this function, it will navigate until it finds the instance at the end of the steps option and set the DigitalOutputState to true.

Available Options

You can set the following options when calling the request(); method

creator.request({
    follow: true, //defaults to true, if this is set to true steps should be provided
    method: 'PUT', // defaults to GET 
    steps: ['accesskeys'], // steps for navigator to follow 
    data: {
        // data if method is set to 'PUT'
    },
    timeout: 31000, // defaults to 31000
    headers: {}, // HTTP request headers are automatically set and we do not recommend overwriting them
    relativeEntryPoint: '/clients' // this option can be set if you know where to begin within the Creator DeviceServer API, can be useful to cut down steps
}, function(cb){});

2. Service Layer functions

These functions provide a great way of accessing a resource very quickly without dealing with any technical details at all.

An example would be:

creator.clients.getClients();

The callback fed into the function above will be called, with an array of clients that you have talking to our Creator DeviceServer. A typical response example, containing one AwaLWM2 client - "ci40-board":

{
  "PageInfo": {
    "TotalCount": 1,
    "ItemsCount": 1,
    "StartIndex": 0
  },
  "Items": [
    {
      "Name": "ci40-board",
      "Links": [
        ...
      ]
    }
  ]
}

Available service layers

  • Client Services - via creator.clients
    • getClients(cb());
    • getClientByName(clientName, cb());
  • Metrics Services - via creator.metrics
    • getUserMetrics(cb());
    • getClientMetrics(clientName, cb());
  • Object Resource Services - via creator.resources
    • getClientObjects(clientName, cb());
    • getClientObject(clientName, objectID, cb());
    • getClientObjectInstanceByID(clientName, objectID, instanceID, cb());
    • writeClientObjectInstanceByID(clientName, objectID, instanceID, data, cb());
  • Subscription Services - via creator.subscriptions
    • getUserSubscriptions(cb());
    • getClientSubscriptions(clientName, cb());

Please note that the high level API is to be expanded to cover more areas of the DeviceServer.

Test

You can run the command below to initiate the mocha tests. Please note that the aforementioned ENV variables need to be set for the test script to work properly.

$ npm test

Help

If you have any problems installing or utilising the creator node library, please look into our Creator Forum.

Otherwise, If you have come across a nasty bug or would like to suggest new features to be added then please go ahead and open an issue or a pull request against this repo.

License

Please see the license file for a detailed explanation.

Contributing

Any Bug fixes and/or feature enhancements are welcome. Please see the contributing file for a detailed explanation.