Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

evrythng-extended

evrythng484.7.2

Javascript SDK to communicate with EVRYTHNG REST API

evrythng, everything, thng, evt, iot, internet of things, wot, web of things, thng-hub, hub, mqtt, thng-scan, scanthng

readme

EVRYTHNG Client Javascript SDK (Extended)

evrythng-extended.js is an extended version of evrythng.js that adds Operator administrative capabilities (read about Scope and Permissions). This means you need your Account Operator API key, which you can find in your Account settings page.

evrythng-extended.js can be used both in Web applications (Browser) and embedded/server applications using Node.js. The difference being the transport layer - Browser's XHR vs Node's HTTP.

evrythng-extended.js is intended for administrative operations only - the same sort of actions you would do on the EVRYTHNG Dashboard. Be sure to never include your EVRYTHNG Operator API key in any public source code (read more about Scope Permissions). You can use it in a server-side application or if you dynamically retrieve the Operator API key from a server call.

See Related Tools below for other usages.

Installation

Node.js

npm install evrythng-extended --save

Browsers

Note: Most Web Applications will not need the extended features and should use the core version of evrythng.js instead.

With Bower
bower install evrythng-extended --save

The Bower package is AMD-compatible. This means you can load it asynchronously using tools like Require.js or simply dropping the script tag into your HTML page:

<script src="bower_components/evrythng-extended/dist/evrythng-extended.js"></script>

See Usage below for more details.

Load from CDN

Add the script tag into your HTML page:

<script src="//cdn.evrythng.com/toolkit/evrythng-js-sdk/evrythng-extended-4.7.2.min.js"></script>

Or always get the latest release (warning, new releases might break your code!):

<script src="//cdn.evrythng.com/toolkit/evrythng-js-sdk/evrythng-extended.js"></script>
<script src="//cdn.evrythng.com/toolkit/evrythng-js-sdk/evrythng-extended.min.js"></script>

For HTTPS you need to use:

<script src="//d10ka0m22z5ju5.cloudfront.net/toolkit/evrythng-js-sdk/evrythng-extended-4.7.2.min.js"></script>
<script src="//d10ka0m22z5ju5.cloudfront.net/toolkit/evrythng-js-sdk/evrythng-extended.js"></script>
<script src="//d10ka0m22z5ju5.cloudfront.net/toolkit/evrythng-js-sdk/evrythng-extended.min.js"></script>

Usage

evrythng-extended.js works exactly the same way as evrythng.js, just with more resources (endpoints). See all Operator permissions in API key permissions and the usage examples in evrythng.js documentation.

Note: DO NOT include your Operator API Key in any public code. This includes committing to any public repositories (GitHub, BitBucket, etc.). If you have done so, you can reset your key in your Account settings page.

For advanced usage and options, see Documentation below.

Node.js

var EVT = require('evrythng-extended');

// Initialise Operator Scope
var operator = new EVT.Operator(OPERATOR_API_KEY);
...

// Or with Trusted App Scope
var app = new EVT.TrustedApp(TRUSTED_APP_API_KEY);

RequireJS (AMD)

requirejs.config({
  paths: {
    'evrythng-extended': '../bower_components/evrythng-extended/dist/evrythng-extended'
  }
});

require(['evrythng-extended'], function (EVT) {

  var operator = new EVT.Operator(OPERATOR_API_KEY);
  ...

});

Globals

If you aren't using any of the above script loading mechanisms, the EVT module is available as a browser global (EVT):

var operator = new EVT.Operator(OPERATOR_API_KEY);
...

Examples

General

Read all Thngs in your account (not scoped):

operator.thng().read().then(function(thngs){
  console.log(thngs);

  // Delete a Thng
  thngs[0].delete();
});

Create an action type:

operator.actionType().create({
  name: '_orderPizza',
  customFields: {
    displayname: 'Order Pizza Now!'
  }
});

Read default redirection of a Thng:

EVT.api({
  apiUrl: 'https://tn.gg',
  url: '/redirections',
  params: {
    evrythngId: '12345'
  },
  authorization: OPERATOR_API_KEY
}).then(function(redirections){
  console.log(redirections);
});

Get QR code:

EVT.api({
  apiUrl: 'https://tn.gg',
  url: '/1234.png',
  headers: {
    accept: 'image/png'
  }
});

Documentation

The EVRYTHNG API has evrythng.js examples whenever applicable. If you'd like to see what's going on under the hood, check out the Annotated Source.

Source Maps

Source Maps are available, which means that when using the minified version, if you open Developer Tools (Chrome, Safari, Firefox), .map files will be downloaded to help you debug code using the original uncompressed version of the library.

evrythng.js

evrythng.js is the core version of evrythng.js intended to be used in public applications and/or devices.

evrythng-scan.js

evrythng-scan.js is an evrythng.js plugin that lets you identify Products and Thngs right from your browser, without using a standalone QR Code scanning app. It also supports Image Recognition.

evrythng-mqtt.js

evrythng-mqtt is an evrythng.js plugin for Node.js that adds support for real-time MQTT methods to any resource.

evrythng-hub.js

evrythng-hub is an evrythng.js plugin for both Browser and Node.js that adds smart routing of local requests when in the context of a Thng-Hub Gateway.

License

Apache 2.0 License, check LICENSE.txt

Copyright (c) EVRYTHNG Ltd.

changelog

v4.7.2 (11-15-2017)

Bug fixes

-Places: Do not geolocate place with id

v4.7.1 (30-06-2017)

Features

-Policies: Allow single Policy access.

v4.7.0 (29-06-2017)

Features

-Policies: Add Policy resource to Roles.

v4.6.0 (09-06-2017)

Features

-Schemas: Add Schema resource in Operator scope.

v4.5.1 (30-05-2017)

Bug fixes

-Permissions: Add support for old Permission API.

v4.5.0 (25-04-2017)

Features

-Permissions: Add Permission resource to Roles.

v4.4.1 (25-04-2017)

Bug fixes

  • HTTP: Fix incorrect Content-Type header check in Node.

v4.4.0 (03-04-2017)

Features

-Roles: Add Role resource in Operator and User scope.

v4.3.0 (30-01-2017)

Features

  • Files: CRD access in the Operator scope.

v4.2.0 (10-01-2017)

Features

  • Scopes: Read data from any scope on creation via $init.

v4.1.0 (12-10-2016)

Features

  • Reactor scripts: Add nested reactor script status resource app.reactor.script().status().

v4.0.1 (11-10-2016)

Bug fixes

  • Auth: Allow to pass FB initialization settings
  • Auth: Read user details when login in application

v4.0.0 (04-10-2016)

Breaking changes

  • Reactor logs: Move app.reactorLog() resource within the app.reactor.log() namespace (only available in evrythng-extended.js).
  • Search: Global .search() has been removed to match API. Use filters instead.
  • Multimedia: Multimedia resource has been removed to match API.

Features

  • Reactor schedules: Add Reactor schedules resource in the app.reactor.schedule() namespace (only available in evrythng-extended.js).
  • Reactor scripts: Add Reactor scripts resource in the app.reactor.script() namespace (only available in evrythng-extended.js).

v3.7.0 (16-06-2016)

Features

  • Collections: Add nested collection resource operator.collection('id').collection().

v3.6.1 (09-06-2016)

Bug fixes

  • Iterator API: Use sortOrder=DESCENDING param by default.
  • Application: Reject application.$init promise if app does not exist.
  • AJAX Headers: Fix response headers not being handled correctly.

v3.6.0 (02-06-2016)

Features

  • Batches: CRUD access in the Operator scope.
  • Batch tasks: CR access in the Batch resource.

v3.5.0 (12-05-2016)

Features

  • Iterator API: Async generator iterator() added to every Resource, supporting looping through the new pagination links.
  • Utils: Added forEachAsync() utility to loop through async generator values.
  • Utils: Added spawn() utility to run through generator function.

Breaking changes

  • Count: count() method on the Resource has been removed.

Bug fixes

  • AJAX Headers: Header values were being lowercased.

v3.4.4 (26-04-2016)

Bug fixes

  • Request interceptors: Added Promise support for request interceptors.

v3.4.3 (26-01-2016)

Changes

  • Callback API: Make deprecation warning mutable.

v3.4.2 (22-12-2015)

Changes

  • Errors: Added code and moreInfo and removed message and type to/from EVT.js errors.
  • Callback API: Added deprecation when callbacks are executed.

v3.4.1 (14-12-2015)

Changes

  • Transport: Common transport module for Node.js and Browser.

v3.4.0 (02-12-2015)

Features

  • Projects: CRUD access in the Operator scope.
  • Applications: CRUD access in the Project resource.
  • Reactor Logs: RD access in the Operator scope.
  • Actions: allow to override global Geolocation setting per request.

v3.3.2 (27-10-2015)

Bug fixes

  • Resource path: newly created entities have wrong resource path [#37].

v3.3.1 (09-09-2015)

Bug fixes

  • Properties: normalize arguments with falsy values (e.g. 0, false) on property creation or update.

v3.3.0 (07-09-2015)

Features

  • Trusted App: updated permissions for TrustedApp scope.
  • Custom headers: allow to setup custom headers with headers object option.
  • Action Types: CRUD access like other entities.
  • Filters: escape special characters for filter param when using object notation.

Bug fixes

  • Properties: normalize arguments on creation, just like updates. Read properties with special characters.
  • Empty fields: empty fields not being sent to API request.
  • Encoding: nested params objects (e.g. filters) are only encoded once.

v3.2.0 (10-08-2015)

Features

  • Trusted App: scope to use with you Application Secret Key, mainly used in Reactor scripts (only available in evrythng-extended.js).

Breaking changes

  • plugins: EVT.use() to install plugin is now synchronous. Callback has been removed. Required dependencies now use $inject property instead of requires.

v3.1.2 (25-06-2015)

Features

  • documentation: clearer usage and installation steps. Consistent format from other libs.

v3.1.1 (19-06-2015)

Bug fixes

  • package.json: Github url with git:// protocol.

v3.1.0 (17-06-2015)

Bug fixes

  • xhr: responses without headers were being ignored.

Features

  • interceptors: setup request and response interceptors globally or as a one-off request settings.
  • plugins: ability to install/use plugins for additional functionality.

Breaking changes

  • synchronous requests: sync option removed for Node.js vs Browser consistency and to promote best practices.