1.0.0 • Published 6 years ago

@nrfcloud/api-client-javascript v1.0.0

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
6 years ago

nRF Cloud JavaScript API Client

npm preview version Build Status Test Coverage
Greenkeeper badge semantic-release
Commitizen friendly
DeepScan Grade Known Vulnerabilities Maintainability

Provides the JavaScript API client for the nRFCloud.com REST API.

:warning: This is a preview release and might be changed without notice.

API Client

The API client is available on npm:

npm i @nrfcloud/api-client-javascript@preview

You also need to install the updated models.

npm i @nrfcloud/models@next

Browser

const {Client} = require('@nrfcloud/api-client-javascript')

const client = new Client(token);
client
  .registerGateway('foo')
  .then(res => {
      console.log(res)
  })

Node.js

npm i isomorphic-fetch es6-promise
require('es6-promise').polyfill()
require('isomorphic-fetch')

const {Client} = require('@nrfcloud/api-client-javascript')

...

Testing with the API client

A testing API Gateway can provide an /token endpoint which returns a Cognito User Pool Identity Token so it is not required to use the AWS Cognito SDK.

Example:

npm i @nrfcloud/api-client-javascript@preview @nrfcloud/models@next isomorphic-fetch es6-promise
require('es6-promise').polyfill();
require('isomorphic-fetch');
const { Client } = require('@nrfcloud/api-client-javascript');

const endpoint = 'https://1ewo2b2jmj.execute-api.us-east-1.amazonaws.com/dev';
const username = 'changeme'; // nrfcloud.com email
const password = 'changeme';

(async () => {

   // This is an undocumented endpoint, which will only be on dev / test stages
   const res = await fetch(`${endpoint}/token`, {
      method: 'POST',
      body: JSON.stringify({ username, password })
   });
   const { token } = await res.json();

   // Construct a client
   const client = new Client(token, endpoint);
   client
      .listTenants('true')
      .then(([{ id }]) => client.registerGateway(id))
      .then(res => {
         console.log(res)
      })
      .catch(err => {
         console.error(err)
      })
})();
1.6.1

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago