{"_id":"@8devices/restserver-api","_rev":"1-a0bf5fb9ac42b730e853582954c1336f","name":"@8devices/restserver-api","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@8devices/restserver-api","version":"0.0.1","description":"8devices sensor network REST server API and demo","main":"index.js","scripts":{"test":"istanbul cover node_modules/mocha/bin/_mocha tests/*.test.js && codecov"},"repository":{"type":"git","url":"git+https://github.com/8devices/restserver-api.git"},"author":{"name":"Giedrius Medzevicius","email":"giedrius@8devices.com"},"license":"MIT","bugs":{"url":"https://github.com/8devices/restserver-api/issues"},"homepage":"https://github.com/8devices/restserver-api#readme","dependencies":{"body-parser":"^1.18.2","coap":"^0.21.0","express":"^4.16.3","ip":"^1.1.5","node-rest-client":"^3.1.0"},"devDependencies":{"chai":"^4.1.2","eslint":"^4.19.1","eslint-config-airbnb-base":"^12.1.0","eslint-plugin-import":"^2.9.0","mocha":"^5.0.4","nock":"^9.2.3","istanbul":"^0.4.5","codecov":"^3.0.0","jsdoc-to-markdown":"^4.0.1"},"directories":{"test":"tests"},"gitHead":"08d895732fde289b9b45d3679ddc7293586bd461","_id":"@8devices/restserver-api@0.0.1","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"giedrius","email":"giedrius@8devices.com"},"dist":{"integrity":"sha512-HmE1834fFxBiu9YZheeXET/OWMULc0RxG9Al/tBriCrw9sU0YXW8vBlOtP47fYlsT2wt5Kmd7briKI/QADDZ7A==","shasum":"169a06a58fb9e23bf6b37beb11e25c53043b5d09","tarball":"https://registry.npmjs.org/@8devices/restserver-api/-/restserver-api-0.0.1.tgz","fileCount":19,"unpackedSize":167721,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbygNBCRA9TVsSAnZWagAAWucP/jVDQqQab6BjssUcGEvm\ngccBOsMREPA2ekfZYqy93tLK/o5BsLO/jQ2PQXnELT3FFxS+fEFuogrV04Sz\nTgJ/pn5iB11Yk5C9FvtZ8wN75iVX0mTIzDiu358hFnSbqUllkr9LRHvY5wYY\nyuxd/JZl9AzLUdoiunKg7Yil5nWkjA5c33ItDAFCvw3GvpCIV7R0+y2iZjxa\nwci3LGm/u5/PwAXiNVl2MPIPCOyvjJ8oqkRUSIWKrDJchmYCa6LZD+YHuMMl\nhRTAqcJ1dOQ1h90E4gxSgncbMsNjBkxEq3sUerP20aqn5fYKpg2CPoz5+yUK\n/d/6bcfdyVPqFdlxnl5go6gpiAPFXJfJgO3dwJ0l+M74YbNDCPJektgslPyV\ny6/oD2DMaKZuSoEHH/i4rv47D1o6yXPUQdKTp8/tQn3qJnb1C+hkFETLrG4x\ntMzthSk3ANJLTu8llI8xbLTHqC1/VmiLk5jbMvJXOPx82EDTF9i4tQHk8KPv\nOLWhafrLObr4VBMwkA9zbdVvKeCSlqhELIUlUtYio+TpWUF9JyQOT6iwEplQ\n4Bs+6I3vZ0cBKyqcQFzxK/egc3yQOryQ/3Mrfs7+KPcZkfGjbcbwLvlqZb2I\nefsGRgghcWEjJXRHesVvs8xJZLijIRMVh7oV38fuZJ8JJXF7D4W2he/wCgeQ\nKATj\r\n=kOeQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGmiSVyJEOdd11RnEySBocqvB4QiN9aDtg9pOxjkjMhcAiBzX6EqGHo+ZNz07OWAziIyba8Hsk3C06sHFsZ37wHEqQ=="}]},"maintainers":[{"name":"giedrius","email":"giedrius@8devices.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/restserver-api_0.0.1_1539965760353_0.10218603353724487"},"_hasShrinkwrap":false}},"time":{"created":"2018-10-19T16:16:00.190Z","0.0.1":"2018-10-19T16:16:00.446Z","modified":"2022-04-04T10:50:05.890Z"},"maintainers":[{"name":"giedrius","email":"giedrius@8devices.com"}],"description":"8devices sensor network REST server API and demo","homepage":"https://github.com/8devices/restserver-api#readme","repository":{"type":"git","url":"git+https://github.com/8devices/restserver-api.git"},"author":{"name":"Giedrius Medzevicius","email":"giedrius@8devices.com"},"bugs":{"url":"https://github.com/8devices/restserver-api/issues"},"license":"MIT","readme":"[![Build Status](https://travis-ci.org/8devices/restserver-api.svg?branch=master)](https://travis-ci.org/8devices/restserver-api)\n[![codecov](https://codecov.io/gh/8devices/restserver-api/branch/master/graph/badge.svg)](https://codecov.io/gh/8devices/restserver-api)\n# restserver-api\n**Example program**\nThis example shows basic restserver-api usage.\n```js\nconst restAPI = require('restserver-api');\n\nconst { Lwm2m } = restAPI;\nconst { RESOURCE_TYPE, encodeResource, decodeResource } = Lwm2m.TLV;\n\nconsole.log('Initialize service and endpoint');\nconst service = new restAPI.Service();\nconst device = new restAPI.Device(service, 'urn:uuid:17200d69-ec9b-43b3-9051-73df2207907c');\n\nconsole.log('Encode resource to TLV format');\nconst tlvBuffer = encodeResource({\n  identifier: 3,\n  type: RESOURCE_TYPE.INTEGER,\n  value: 60\n});\n\nconsole.log('Start service');\nservice.start().then(() => {\n  console.log('Service started');\n  console.log('Writing into device\\'s resource');\n  device.write('/3/0/7', (status) => {\n    console.log('Received response with status: ', status);\n    console.log('Stopping service');\n    service.stop().then(() => {\n      console.log('Service stopped');\n    });\n  }, tlvBuffer);\n});\n```\n## Classes\n\n<dl>\n<dt><a href=\"#Device\">Device</a></dt>\n<dd><p>This class represents device (endpoint).</p>\n</dd>\n<dt><a href=\"#Service\">Service</a></dt>\n<dd><p>This class represents REST API service.</p>\n</dd>\n</dl>\n\n## Constants\n\n<dl>\n<dt><a href=\"#TYPE\">TYPE</a></dt>\n<dd><p>Represents LwM2M variable (identifier) types (OBJECT_INSTANCE,\nMULTIPLE_RESOURCE, RESOURCE_INSTANCE, RESOURCE).</p>\n</dd>\n<dt><a href=\"#RESOURCE_TYPE\">RESOURCE_TYPE</a></dt>\n<dd><p>Represents resource type (NONE, BOOLEAN, INTEGER, FLOAT, STRING, OPAQUE).</p>\n</dd>\n</dl>\n\n## Functions\n\n<dl>\n<dt><a href=\"#getDictionaryByValue\">getDictionaryByValue(dictionaryList, keyName, value)</a> ⇒ <code>Object</code> | <code>string</code> | <code>number</code></dt>\n<dd><p>Gets dictionary by given name of the key and value.</p>\n</dd>\n<dt><a href=\"#encodeResourceValue\">encodeResourceValue(resource)</a> ⇒ <code>object</code></dt>\n<dd><p>Encodes value of the resource.</p>\n</dd>\n<dt><a href=\"#decodeResourceValue\">decodeResourceValue(buffer, resource)</a> ⇒ <code>Object</code> | <code>string</code> | <code>number</code> | <code>boolean</code></dt>\n<dd><p>Decodes value of the resource.</p>\n</dd>\n<dt><a href=\"#encode\">encode(object)</a> ⇒ <code>object</code></dt>\n<dd><p>Encodes ant type of instance (Object instance, multiple resources, resources instance, resource).</p>\n</dd>\n<dt><a href=\"#encodeResourceInstance\">encodeResourceInstance(resourceInstance)</a> ⇒ <code>object</code></dt>\n<dd><p>Encodes resource instance to TLV buffer.</p>\n</dd>\n<dt><a href=\"#encodeMultipleResourcesTLV\">encodeMultipleResourcesTLV(resources)</a> ⇒ <code>object</code></dt>\n<dd><p>Encodes multiple resource values to TLV buffer.</p>\n</dd>\n<dt><a href=\"#encodeResource\">encodeResource(resource)</a> ⇒ <code>object</code></dt>\n<dd><p>Encodes resource to TLV buffer.</p>\n</dd>\n<dt><a href=\"#encodeObjectInstance\">encodeObjectInstance(objectInstance)</a> ⇒ <code>object</code></dt>\n<dd><p>Encodes LwM2M object instance to TLV buffer.</p>\n</dd>\n<dt><a href=\"#encodeObject\">encodeObject(object)</a> ⇒ <code>object</code></dt>\n<dd><p>Encodes LwM2M object to TLV buffer.</p>\n</dd>\n<dt><a href=\"#decode\">decode(buffer)</a> ⇒ <code>object</code></dt>\n<dd><p>Decodes any TLV buffer.</p>\n</dd>\n<dt><a href=\"#decodeResourceInstance\">decodeResourceInstance(buffer, resources)</a> ⇒ <code>object</code></dt>\n<dd><p>Decodes resource instance.</p>\n</dd>\n<dt><a href=\"#decodeResourceInstanceValue\">decodeResourceInstanceValue(buffer, resourceInstance)</a> ⇒ <code>object</code></dt>\n<dd><p>Decodes resource instance value</p>\n</dd>\n<dt><a href=\"#decodeResource\">decodeResource(buffer, resource)</a> ⇒ <code>object</code></dt>\n<dd><p>Decodes resource.</p>\n</dd>\n<dt><a href=\"#decodeObjectInstance\">decodeObjectInstance(buffer, objectInstance)</a> ⇒ <code>object</code></dt>\n<dd><p>Decodes object instance from TLV buffer.</p>\n</dd>\n<dt><a href=\"#decodeObject\">decodeObject(buffer, object)</a> ⇒ <code>object</code></dt>\n<dd><p>Decodes LwM2M object to TLV buffer.</p>\n</dd>\n</dl>\n\n<a name=\"Device\"></a>\n\n## Device\nThis class represents device (endpoint).\n\n**Kind**: global class  \n\n* [Device](#Device)\n    * [new Device(service, id)](#new_Device_new)\n    * [.getObjects()](#Device+getObjects) ⇒ <code>Promise</code>\n    * [.read(path, callback)](#Device+read) ⇒ <code>Promise</code>\n    * [.write(path, callback, payload, type)](#Device+write) ⇒ <code>Promise</code>\n    * [.execute(path, callback, payload, type)](#Device+execute) ⇒ <code>Promise</code>\n    * [.observe(path, callback)](#Device+observe) ⇒ <code>Promise</code>\n    * [.cancelObserve(path)](#Device+cancelObserve) ⇒ <code>Promise</code>\n\n<a name=\"new_Device_new\"></a>\n\n### new Device(service, id)\nConstructor initiliazes given service object, device's id\nand starts listening for events emited by service (when device\nregisters, updates, deregisters, sends data), handles \"async\nresponses\" and emits \"register\", \"update\", \"deregister\" events.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| service | <code>object</code> | Service object |\n| id | <code>string</code> | Endpoint id |\n\n**Example**  \n```js\nconst restAPI = require('restserver-api');\n\nconst service = new restAPI.Service(serviceOptions);\nconst device = new restAPI.Device(service, 'deviceId');\n```\n<a name=\"Device+getObjects\"></a>\n\n### device.getObjects() ⇒ <code>Promise</code>\nSends request to get all device's objects.\n\n**Kind**: instance method of [<code>Device</code>](#Device)  \n**Returns**: <code>Promise</code> - Promise object with device's objects  \n**Example**  \n```js\ndevice.getObjects().then((resp) => {\n  // resp = [ { uri: '/1/0' }, { uri: '/2/0' }, ... ]\n}).catch((err) => {\n  // err - exception message object or status code\n});\n```\n<a name=\"Device+read\"></a>\n\n### device.read(path, callback) ⇒ <code>Promise</code>\nSends request to read device's resource data.\n\n**Kind**: instance method of [<code>Device</code>](#Device)  \n**Returns**: <code>Promise</code> - Promise with async response id  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| path | <code>string</code> | Resource path |\n| callback | <code>function</code> | Callback which will be called when async response is received |\n\n**Example**  \n```js\ndevice.read(path, (status, payload) => {\n  // status = 200\n  // payload = 4RbaAA==\n}).then((asyncResponseId) => {\n  // asyncResponseId = 1533889157#42f26784-1a8d-4861-36aa-d88f\n}).catch((err) => {\n  // err - exception object or status code\n});\n```\n<a name=\"Device+write\"></a>\n\n### device.write(path, callback, payload, type) ⇒ <code>Promise</code>\nSends request to write a value into device's resource.\n\n**Kind**: instance method of [<code>Device</code>](#Device)  \n**Returns**: <code>Promise</code> - Promise with async response id  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| path | <code>string</code> |  | Resource path |\n| callback | <code>function</code> |  | Callback which will be called when async response is received |\n| payload | <code>buffer</code> |  | Data (optional) |\n| type | <code>string</code> | <code>&quot;application/vnd.oma.lwm2m+tlv&quot;</code> | Content type (optional) |\n\n**Example**  \n```js\ndevice.write(path, (status) => {\n  // status = 202\n}, payload).then((asyncResponseId) => {\n  // asyncResponseId = 1533889926#870a3f17-3e21-b6ad-f63d-5cfe\n}).catch((err) => {\n  // err - exception object or status code\n});\n```\n<a name=\"Device+execute\"></a>\n\n### device.execute(path, callback, payload, type) ⇒ <code>Promise</code>\nSends request to execute device's resource.\n\n**Kind**: instance method of [<code>Device</code>](#Device)  \n**Returns**: <code>Promise</code> - Promise with async response id  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| path | <code>string</code> |  | Resource path |\n| callback | <code>function</code> |  | Callback which will be called when async response is received |\n| payload | <code>buffer</code> |  | Data (optional) |\n| type | <code>string</code> | <code>&quot;text/plain&quot;</code> | Content type (optional) |\n\n**Example**  \n```js\ndevice.execute(path, (status) => {\n  // status = 202\n}).then((asyncResponseId) => {\n  // asyncResponseId = 1533889926#870a3f17-3e21-b6ad-f63d-5cfe\n}).catch((err) => {\n  // err - exception object or status code\n});\n```\n<a name=\"Device+observe\"></a>\n\n### device.observe(path, callback) ⇒ <code>Promise</code>\nSends request to subscribe to resource.\n\n**Kind**: instance method of [<code>Device</code>](#Device)  \n**Returns**: <code>Promise</code> - Promise with async response id  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| path | <code>string</code> | Resource path |\n| callback | <code>function</code> | Callback which will be called when async response is received |\n\n**Example**  \n```js\ndevice.observe(path, (status, payload) => {\n  // status = 200\n  // payload = 4RbaAA==\n}).then((asyncResponseId) => {\n  // asyncResponseId = 1533889157#42f26784-1a8d-4861-36aa-d88f\n}).catch((err) => {\n  // err - exception object or status code\n});\n```\n<a name=\"Device+cancelObserve\"></a>\n\n### device.cancelObserve(path) ⇒ <code>Promise</code>\nSends request to cancel subscriptions.\n\n**Kind**: instance method of [<code>Device</code>](#Device)  \n**Returns**: <code>Promise</code> - Promise with HTTP status code  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| path | <code>string</code> | Resource path |\n\n**Example**  \n```js\ndevice.cancelObserve(path).then((status) => {\n  // status - status code\n}).catch((err) => {\n  // err - exception object\n});\n```\n<a name=\"Service\"></a>\n\n## Service\nThis class represents REST API service.\n\n**Kind**: global class  \n\n* [Service](#Service)\n    * [new Service(opts)](#new_Service_new)\n    * [.start(opts)](#Service+start) ⇒ <code>Promise</code>\n    * [.stop()](#Service+stop) ⇒ <code>Promise</code>\n    * [.authenticate()](#Service+authenticate) ⇒ <code>Promise</code>\n    * [.registerNotificationCallback()](#Service+registerNotificationCallback) ⇒ <code>Promise</code>\n    * [.deleteNotificationCallback()](#Service+deleteNotificationCallback) ⇒ <code>Promise</code>\n    * [.checkNotificationCallback()](#Service+checkNotificationCallback) ⇒ <code>Promise</code>\n    * [.pullNotification()](#Service+pullNotification) ⇒ <code>Promise</code>\n    * [.getDevices()](#Service+getDevices) ⇒ <code>Promise</code>\n    * [.getVersion()](#Service+getVersion) ⇒ <code>Promise</code>\n    * [.get(path)](#Service+get) ⇒ <code>Promise</code>\n    * [.put(path, argument, type)](#Service+put) ⇒ <code>Promise</code>\n    * [.delete(path)](#Service+delete) ⇒ <code>Promise</code>\n    * [.post(path, argument, type)](#Service+post) ⇒ <code>Promise</code>\n\n<a name=\"new_Service_new\"></a>\n\n### new Service(opts)\nInitializes default configurations. Reconfigures with given options.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| opts | <code>object</code> | Options object (optional) |\n\n**Example**  \n```js\nconst options = {\n  // REST server's address\n  host: 'http://localhost:8888',\n  // CA certificate\n  ca: '',\n  // authentication (true or false)\n  authentication: false,\n  username: '',\n  password: '',\n  // notification polling (true or false)\n  polling: false,\n  // time between each poll in miliseconds\n  interval: 1234,\n  // port for socket listener (not relevant if polling is enabled)\n  port: 5728,\n};\nnew Service(options);\n```\n<a name=\"Service+start\"></a>\n\n### service.start(opts) ⇒ <code>Promise</code>\n(Re)starts authentication,\nsocket listener creation and notification callback registration\nor notification polling processes.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise which fulfills when service is started  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| opts | <code>object</code> | Options object (optional) |\n\n**Example**  \n```js\nservice.start().then(() => {\n  // started service\n}).catch((err) => {\n  // err - exception object\n});\n```\n**Example** *(Passing options object)*  \n```js\nconst options = {\n  // REST server's address\n  host: 'http://localhost:8888',\n  // CA certificate\n  ca: '',\n  // authentication (true or false)\n  authentication: false,\n  username: '',\n  password: '',\n  // notification polling (true or false)\n  polling: false,\n  // time between each poll in miliseconds\n  interval: 1234,\n  // port for socket listener (not relevant if polling is enabled)\n  port: 5728,\n};\nservice.start(options);\n```\n<a name=\"Service+stop\"></a>\n\n### service.stop() ⇒ <code>Promise</code>\nStops receiving and processing events\nStops this service and all it's subservices\nthat were started in start().\nCleans up resources\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise which fulfills when service is stopped  \n**Example**  \n```js\nservice.stop().then(() => {\n  // stopped service\n});\n```\n<a name=\"Service+authenticate\"></a>\n\n### service.authenticate() ⇒ <code>Promise</code>\nSends request to authenticate user.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise with authentication data (token and after what time it expires)  \n**Example**  \n```js\nservice.authenticate().then((resp) => {\n  // resp = { access_token: 'token-value', expires_in: 3600 }\n}).catch((err) => {\n  // err - exception message object or status code\n});\n```\n<a name=\"Service+registerNotificationCallback\"></a>\n\n### service.registerNotificationCallback() ⇒ <code>Promise</code>\nSends request to register notification callback.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise which fulfills when notification callback is registered  \n**Example**  \n```js\nservice.registerNotificationCallback().then(() => {\n  // notification callback has been registered\n}).catch((err) => {\n  // err - exception object or status code\n});\n```\n<a name=\"Service+deleteNotificationCallback\"></a>\n\n### service.deleteNotificationCallback() ⇒ <code>Promise</code>\nSends request to delete notification callback.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise with HTTP status code  \n**Example**  \n```js\nservice.deleteNotificationCallback().then((status) => {\n  // status - status code\n}).catch((err) => {\n  // err - exception object\n});\n```\n<a name=\"Service+checkNotificationCallback\"></a>\n\n### service.checkNotificationCallback() ⇒ <code>Promise</code>\nSends request to check whether or not notification callback is registered.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise with notification callback data  \n**Example**  \n```js\nservice.checkNotificationCallback().then((resp) => {\n  // resp = { url: 'http://localhost:5728/notification', headers: {} }\n}).catch((err) => {\n  // err - exception message object or status code\n});\n```\n<a name=\"Service+pullNotification\"></a>\n\n### service.pullNotification() ⇒ <code>Promise</code>\nSends request to get pending/queued notifications.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise with notification data (registrations,\nderegistrations, updates, async responses)  \n**Example**  \n```js\nservice.pullNotification().then((resp) => {\n  // resp = { registrations: [...], 'reg-updates': [...], ... }\n}).catch((err) => {\n  // err - exception object\n});\n```\n<a name=\"Service+getDevices\"></a>\n\n### service.getDevices() ⇒ <code>Promise</code>\nSends request to get all registered endpoints.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise with a list of endpoints  \n**Example**  \n```js\nservice.getDevices().then((resp) => {\n  // resp = [ { name: 'uuid-4567', type: '8dev_3700', ... }, ... ]\n}).catch((err) => {\n  // err - exception message object or status code\n});\n```\n<a name=\"Service+getVersion\"></a>\n\n### service.getVersion() ⇒ <code>Promise</code>\nSends request to get REST server version.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise with REST server's version  \n**Example**  \n```js\nservice.getVersion().then((resp) => {\n  // resp = '1.0.0'\n}).catch((err) => {\n  // err - exception object\n});\n```\n<a name=\"Service+get\"></a>\n\n### service.get(path) ⇒ <code>Promise</code>\nPerforms GET requests with given path.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise with data and response object  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| path | <code>string</code> | Request path |\n\n**Example**  \n```js\nservice.get(path).then((dataAndResponse) => {\n  // dataAndResponse.data - data object\n  // dataAndResponse.resp - response object\n}).catch((err) => {\n  // err - exception object\n});\n```\n<a name=\"Service+put\"></a>\n\n### service.put(path, argument, type) ⇒ <code>Promise</code>\nPerforms PUT requests with given path, data and data type.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise with data and response object  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| path | <code>string</code> |  | Request path |\n| argument | <code>object</code> |  | Data which will be sent (optional) |\n| type | <code>string</code> | <code>&quot;application/vnd.oma.lwm2m+tlv&quot;</code> | Data type (optional) |\n\n<a name=\"Service+delete\"></a>\n\n### service.delete(path) ⇒ <code>Promise</code>\nPerforms DELETE requests with given path.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise with data and response object  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| path | <code>string</code> | Request path |\n\n<a name=\"Service+post\"></a>\n\n### service.post(path, argument, type) ⇒ <code>Promise</code>\nPerforms POST requests with given path, data and data type.\n\n**Kind**: instance method of [<code>Service</code>](#Service)  \n**Returns**: <code>Promise</code> - Promise with data and response object  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| path | <code>string</code> |  | Request path |\n| argument | <code>object</code> |  | Data which will be sent (optional) |\n| type | <code>string</code> | <code>&quot;application/vnd.oma.lwm2m+tlv&quot;</code> | Data type (optional) |\n\n<a name=\"TYPE\"></a>\n\n## TYPE\nRepresents LwM2M variable (identifier) types (OBJECT_INSTANCE,\nMULTIPLE_RESOURCE, RESOURCE_INSTANCE, RESOURCE).\n\n**Kind**: global constant  \n<a name=\"RESOURCE_TYPE\"></a>\n\n## RESOURCE_TYPE\nRepresents resource type (NONE, BOOLEAN, INTEGER, FLOAT, STRING, OPAQUE).\n\n**Kind**: global constant  \n<a name=\"getDictionaryByValue\"></a>\n\n## getDictionaryByValue(dictionaryList, keyName, value) ⇒ <code>Object</code> \\| <code>string</code> \\| <code>number</code>\nGets dictionary by given name of the key and value.\n\n**Kind**: global function  \n**Returns**: <code>Object</code> \\| <code>string</code> \\| <code>number</code> - dictionary  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| dictionaryList | <code>object</code> | Dictionary list. |\n| keyName | <code>Object</code> \\| <code>string</code> | Name of the key |\n| value | <code>Object</code> \\| <code>string</code> \\| <code>number</code> | Value |\n\n<a name=\"encodeResourceValue\"></a>\n\n## encodeResourceValue(resource) ⇒ <code>object</code>\nEncodes value of the resource.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - buffer - Buffer of encoded value.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| resource | <code>object</code> | Object which stores resource value and value's type. |\n\n**Example**  \n```js\nconst resource = {\n type: TLV.RESOURCE_TYPE.INTEGER,\n value: 1\n};\n\nconst encodedValue = encodeResourceValue(resource);\n// encodedValue = <Buffer 01>\n```\n<a name=\"decodeResourceValue\"></a>\n\n## decodeResourceValue(buffer, resource) ⇒ <code>Object</code> \\| <code>string</code> \\| <code>number</code> \\| <code>boolean</code>\nDecodes value of the resource.\n\n**Kind**: global function  \n**Returns**: <code>Object</code> \\| <code>string</code> \\| <code>number</code> \\| <code>boolean</code> - value - Decoded value in specified type  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| buffer | <code>object</code> | Buffer which will be decoded. |\n| resource | <code>object</code> | Object which stores resource value's type. |\n\n**Example**  \n```js\nconst buffer = Buffer.from([0x01]);\nconst resource = {\n  type: TLV.RESOURCE_TYPE.INTEGER,\n};\n\nconst decodedValue = decodeResourceValue(buffer, resource);\n// decodedValue = 1\n```\n<a name=\"encode\"></a>\n\n## encode(object) ⇒ <code>object</code>\nEncodes ant type of instance (Object instance, multiple resources, resources instance, resource).\n\n**Kind**: global function  \n**Returns**: <code>object</code> - buffer - encoded TLV buffer.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| object | <code>object</code> | object which stores type, identifier and value. |\n\n**Example**  \n```js\nconst resource = {\n  identifier: 5850,\n  type: TLV.RESOURCE_TYPE.BOOLEAN,\n  value: true\n};\n\nconst encoded = encode({\n  type: TYPE.RESOURCE,\n  identifier: resource.identifier,\n  value: encodeResourceValue(resource),\n});\n// encoded = <Buffer e1 16 da 01>\n```\n<a name=\"encodeResourceInstance\"></a>\n\n## encodeResourceInstance(resourceInstance) ⇒ <code>object</code>\nEncodes resource instance to TLV buffer.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - buffer - Buffer in TLV format  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| resourceInstance | <code>object</code> | Object which stores resource identifier, value and it's type. |\n\n**Example**  \n```js\nconst resourceInstance = {\n  identifier: 5850,\n  type: TLV.RESOURCE_TYPE.BOOLEAN,\n  value: true\n};\n\nconst encoded = encodeResourceInstance(resourceInstance);\n// encoded = <Buffer e1 16 da 01>\n```\n<a name=\"encodeMultipleResourcesTLV\"></a>\n\n## encodeMultipleResourcesTLV(resources) ⇒ <code>object</code>\nEncodes multiple resource values to TLV buffer.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - buffer - TLV buffer.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| resources | <code>object</code> | Object which stores identifier, resource type, and multiple values. |\n\n**Example**  \n```js\nconst resources = {\n  identifier: 5850,\n  type: TLV.RESOURCE_TYPE.BOOLEAN,\n  value: [true, false]\n};\n\nconst encoded = encodeMultipleResources(resources);\n// encoded = <Buffer a6 16 da 41 00 01 41 01 00>\n```\n<a name=\"encodeResource\"></a>\n\n## encodeResource(resource) ⇒ <code>object</code>\nEncodes resource to TLV buffer.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - buffer - TLV buffer.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| resource | <code>object</code> | Object which stores resource identifier, type and value. |\n\n**Example**  \n```js\nconst resource = {\n  identifier: 5850,\n  type: TLV.RESOURCE_TYPE.BOOLEAN,\n  value: true\n};\n\nconst encoded = encodeResourcez(resource);\n// encoded = <Buffer e1 16 da 01>\n```\n<a name=\"encodeObjectInstance\"></a>\n\n## encodeObjectInstance(objectInstance) ⇒ <code>object</code>\nEncodes LwM2M object instance to TLV buffer.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - buffer - TLV buffer.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| objectInstance | <code>object</code> | LwM2M object. |\n\n**Example**  \n```js\nconst objectInstance = {\n  identifier: 0,\n  resources: [\n    {\n      identifier: 5815,\n      type: TLV.RESOURCE_TYPE.FLOAT,\n      value: 999.99\n    }\n  ]\n};\n\nconst encoded = encodeObjectInstanceTLV(objectInstance);\n// encoded = <Buffer 07 00 e4 16 b7 44 79 ff 5c>\n```\n<a name=\"encodeObject\"></a>\n\n## encodeObject(object) ⇒ <code>object</code>\nEncodes LwM2M object to TLV buffer.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - buffer - TLV buffer.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| object | <code>object</code> | LwM2M object. |\n\n**Example**  \n```js\nconst object = {\n  identifier: 3305,\n  objectInstances: [{\n    identifier: 0,\n    resources: [\n      {\n        identifier: 5815,\n        type: TLV.RESOURCE_TYPE.FLOAT,\n        value: 999.99\n      }\n    ]\n  }]\n};\n\nconst encoded = encodeObject(object);\n// encoded = <Buffer 07 00 e4 16 b7 44 79 ff 5c>\n```\n<a name=\"decode\"></a>\n\n## decode(buffer) ⇒ <code>object</code>\nDecodes any TLV buffer.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - object - Decoded object.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| buffer | <code>object</code> | encoded TLV buffer. |\n\n**Example**  \n```js\nconst buffer = Buffer.from([0xe1, 0x16, 0xda, 0x01]);\n\nconst decoded = TLV.decode(buffer);\n// decoded = { type: 3, identifier: 5850, value: <Buffer 01>, tlvSize: 4 }\n```\n<a name=\"decodeResourceInstance\"></a>\n\n## decodeResourceInstance(buffer, resources) ⇒ <code>object</code>\nDecodes resource instance.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - decodedResource - Object which stores resource identifier,\ntlvSize resource type and value.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| buffer | <code>object</code> | Resource instance TLV buffer. |\n| resources | <code>object</code> | Object which stores resource identifier and resource type. |\n\n**Example**  \n```js\nconst buffer = Buffer.from([0x61, 0x16, 0xda, 0x01]);\nconst resources = {\n  identifier: 5850,\n  type: TLV.RESOURCE_TYPE.BOOLEAN,\n};\n\nconst decoded = decodeResourceInstance(buffer, resources);\n// decoded = { identifier: 5850, tlvSize: 4, type: TLV.RESOURCE_TYPE.BOOLEAN, value: true }\n```\n<a name=\"decodeResourceInstanceValue\"></a>\n\n## decodeResourceInstanceValue(buffer, resourceInstance) ⇒ <code>object</code>\nDecodes resource instance value\n\n**Kind**: global function  \n**Returns**: <code>object</code> - decodedResourceValue - Decoded resource value  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| buffer | <code>object</code> | Resource instance value TLV buffer |\n| resourceInstance | <code>object</code> | Object which stores resource type |\n\n**Example**  \n```js\nconst buffer = Buffer.from([0x01]);\nconst resourceInstance = {\n  type: TLV.RESOURCE_TYPE.INTEGER,\n};\n\nconst decoded = decodeResourceInstance(buffer, resources);\n// decoded = 1\n```\n<a name=\"decodeResource\"></a>\n\n## decodeResource(buffer, resource) ⇒ <code>object</code>\nDecodes resource.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - buffer - Decoded resource.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| buffer | <code>object</code> | Resource TLV buffer |\n| resource | <code>object</code> | Object which stores identifier and resource type. |\n\n**Example**  \n```js\nconst buffer = Buffer.from([0xe1, 0x16, 0xda, 0x01]);\nconst resource = {\n  identifier: 5850,\n  type: TLV.RESOURCE_TYPE.BOOLEAN,\n};\n\nconst decoded = decodeResource(buffer, resource);\n// decoded = { identifier: 5850, type: 1, value: true, tlvSize: 4 }\n```\n<a name=\"decodeObjectInstance\"></a>\n\n## decodeObjectInstance(buffer, objectInstance) ⇒ <code>object</code>\nDecodes object instance from TLV buffer.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - object - Decoded object instance.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| buffer | <code>object</code> | TLV buffer. |\n| objectInstance | <code>object</code> | Object which stores object instance identifier and resources. |\n\n**Example**  \n```js\nconst buffer = Buffer.from([0x07, 0x00, 0xe4, 0x16, 0xb7, 0x44, 0x79, 0xff, 0x5c]);\nconst objectInstance: {\n  identifier: 0,\n  resources: [\n    {\n      identifier: 5815,\n      type: TLV.RESOURCE_TYPE.FLOAT,\n    },\n  ]\n};\n\nconst decoded = decodeObjectInstance(buffer, objectInstance);\n// decoded = { identifier: 0, resources: [ { identifier: 5815, type: 3 } ] }\n```\n<a name=\"decodeObject\"></a>\n\n## decodeObject(buffer, object) ⇒ <code>object</code>\nDecodes LwM2M object to TLV buffer.\n\n**Kind**: global function  \n**Returns**: <code>object</code> - object - Decoded object.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| buffer | <code>object</code> | TLV buffer. |\n| object | <code>object</code> | Object which stores object instances with their resources. |\n\n**Example**  \n```js\nconst buffer = Buffer.from([0x07, 0x00, 0xe4, 0x16, 0xb7, 0x44, 0x79, 0xff, 0x5c]);\nconst object = {\n  identifier: 3305,\n  objectInstances: [{\n    identifier: 0,\n    resources: [\n      {\n        identifier: 5815,\n        type: TLV.RESOURCE_TYPE.FLOAT,\n      },\n    ]\n  }]\n};\n\nconst decoded = decodeObject(buffer, object);\n/*\ndecoded = {\n  identifier: 3305,\n  objectInstances: [\n    {\n      identifier: 0,\n      resources: [\n        {\n          identifier: 5815,\n          type: 3,\n          value: 999.989990234375,\n          tlvSize: 7\n        }\n      ]\n    }\n  ]\n}\n*/\n```\n","readmeFilename":"README.md"}