particle-api-js 9.2.0 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/README.md +34 -6
- package/dist/particle.min.js +2 -2
- package/dist/particle.min.js.map +1 -1
- package/docs/api.md +102 -102
- package/lib/Agent.js +6 -1
- package/lib/Agent.js.map +1 -1
- package/lib/Particle.js +8 -0
- package/lib/Particle.js.map +1 -1
- package/package.json +1 -1
- package/test/Agent.spec.js +23 -1
- package/test/Particle.spec.js +15 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -27,23 +27,51 @@ $ bower install particle-api-js
|
|
|
27
27
|
|
|
28
28
|
## Development
|
|
29
29
|
|
|
30
|
+
|
|
30
31
|
All essential commands are available at the root via `npm run <script name>` - e.g. `npm run lint`. To view the available commands, run: `npm run`
|
|
31
32
|
|
|
32
33
|
<details id="develop-run-tests">
|
|
33
34
|
<summary><b>How to run your tests</b></summary>
|
|
34
35
|
<p>
|
|
35
36
|
|
|
36
|
-
to
|
|
37
|
+
The `Agent` integration tests ([source](./test/Agent.integration.js)) depend on a real HTTP api backend and a valid Particle access token. Be sure to set relevant environment variables to avoid test failures. You can prefix commands test commands like this `PARTICLE_API_BASE_URL=<url> PARTICLE_API_TOKEN=<token> npm test`
|
|
38
|
+
|
|
39
|
+
`npm test` runs the tests.
|
|
40
|
+
|
|
41
|
+
`npm run coverage` shows code coverage
|
|
42
|
+
|
|
43
|
+
`npm run test:browser` runs tests in a browser via [karma](https://karma-runner.github.io/latest/index.html).
|
|
37
44
|
|
|
38
|
-
`npm test`
|
|
45
|
+
`npm run test:ci` runs tests in the exact same way CI system does
|
|
39
46
|
|
|
40
|
-
|
|
47
|
+
</p>
|
|
48
|
+
</details>
|
|
49
|
+
|
|
50
|
+
<details id="develop-run-locally">
|
|
51
|
+
<summary><b>How to write scripts that execute against local code changes?</b></summary>
|
|
52
|
+
<p>
|
|
53
|
+
|
|
54
|
+
Source code lives in the `./src` directory and is built for release via the `npm run compile` command. To create a simple script file to test your changes, follow these steps:
|
|
55
|
+
|
|
56
|
+
1. create a `js` file on your local machine: `touch my-api-test.js` (somewhere outside of the root of this repo)
|
|
57
|
+
2. within your test `js` file, init the api client like so:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
const ParticleAPI = require('./path/to/particle-api-js'); // Make sure to substitute to correct path
|
|
61
|
+
const api = new ParticleAPI();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
3. add in any api calls, etc required to validate you changes
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
const devices = await api.listDevices({ auth: '<particle-auth-token>' });
|
|
68
|
+
console.log('MY DEVICES:', devices);
|
|
69
|
+
```
|
|
41
70
|
|
|
42
|
-
|
|
71
|
+
4. run it: `node ./path/to/my-api-test.js`
|
|
43
72
|
|
|
44
|
-
|
|
73
|
+
_NOTE: Requiring the root directory works via the `main` field specified in Particle API JS' `package.json` file ([docs](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#main))_
|
|
45
74
|
|
|
46
|
-
`npm run test:browser`
|
|
47
75
|
|
|
48
76
|
</p>
|
|
49
77
|
</details>
|
package/dist/particle.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Particle = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
2
|
-
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var _keys=require("babel-runtime/core-js/object/keys"),_keys2=_interopRequireDefault(_keys),_slicedToArray2=require("babel-runtime/helpers/slicedToArray"),_slicedToArray3=_interopRequireDefault(_slicedToArray2),_entries=require("babel-runtime/core-js/object/entries"),_entries2=_interopRequireDefault(_entries),_getIterator2=require("babel-runtime/core-js/get-iterator"),_getIterator3=_interopRequireDefault(_getIterator2),_assign=require("babel-runtime/core-js/object/assign"),_assign2=_interopRequireDefault(_assign),_promise=require("babel-runtime/core-js/promise"),_promise2=_interopRequireDefault(_promise),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_superagent=require("superagent"),_superagent2=_interopRequireDefault(_superagent),_superagentPrefix=require("superagent-prefix"),_superagentPrefix2=_interopRequireDefault(_superagentPrefix),Agent=function(){function e(t){(0,_classCallCheck3.default)(this,e),this.
|
|
2
|
+
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var _keys=require("babel-runtime/core-js/object/keys"),_keys2=_interopRequireDefault(_keys),_slicedToArray2=require("babel-runtime/helpers/slicedToArray"),_slicedToArray3=_interopRequireDefault(_slicedToArray2),_entries=require("babel-runtime/core-js/object/entries"),_entries2=_interopRequireDefault(_entries),_getIterator2=require("babel-runtime/core-js/get-iterator"),_getIterator3=_interopRequireDefault(_getIterator2),_assign=require("babel-runtime/core-js/object/assign"),_assign2=_interopRequireDefault(_assign),_promise=require("babel-runtime/core-js/promise"),_promise2=_interopRequireDefault(_promise),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_superagent=require("superagent"),_superagent2=_interopRequireDefault(_superagent),_superagentPrefix=require("superagent-prefix"),_superagentPrefix2=_interopRequireDefault(_superagentPrefix),Agent=function(){function e(t){(0,_classCallCheck3.default)(this,e),this.setBaseUrl(t)}return(0,_createClass3.default)(e,[{key:"setBaseUrl",value:function(e){this.prefix=(0,_superagentPrefix2.default)(e)}},{key:"get",value:function(e){var t=e.uri,r=e.auth,a=e.headers,i=e.query,u=e.context;return this.request({uri:t,method:"get",auth:r,headers:a,query:i,context:u})}},{key:"head",value:function(e){var t=e.uri,r=e.auth,a=e.headers,i=e.query,u=e.context;return this.request({uri:t,method:"head",auth:r,headers:a,query:i,context:u})}},{key:"post",value:function(e){var t=e.uri,r=e.headers,a=e.data,i=e.auth,u=e.context;return this.request({uri:t,method:"post",auth:i,headers:r,data:a,context:u})}},{key:"put",value:function(e){var t=e.uri,r=e.auth,a=e.headers,i=e.data,u=e.context;return this.request({uri:t,method:"put",auth:r,headers:a,data:i,context:u})}},{key:"delete",value:function(e){var t=e.uri,r=e.auth,a=e.headers,i=e.data,u=e.context;return this.request({uri:t,method:"delete",auth:r,headers:a,data:i,context:u})}},{key:"request",value:function(e){var t=e.uri,r=e.method,a=e.headers,i=void 0===a?void 0:a,u=e.data,o=void 0===u?void 0:u,n=e.auth,s=e.query,l=void 0===s?void 0:s,d=e.form,f=void 0===d?void 0:d,c=e.files,h=void 0===c?void 0:c,_=e.context,v=void 0===_?void 0:_,p=e.raw,y=void 0!==p&&p,m=this._sanitizeFiles(h);return this._request({uri:t,method:r,headers:i,data:o,auth:n,query:l,form:f,context:v,files:m,raw:y})}},{key:"_request",value:function(e){var t=e.uri,r=e.method,a=e.headers,i=e.data,u=e.auth,o=e.query,n=e.form,s=e.files,l=e.context,d=e.raw,f=this._buildRequest({uri:t,method:r,headers:a,data:i,auth:u,query:o,form:n,context:l,files:s});return d?f:this._promiseResponse(f)}},{key:"_promiseResponse",value:function(e){var t=this;return new _promise2.default(function(r,a){return t._sendRequest(e,r,a)})}},{key:"_sendRequest",value:function(e,t,r){e.end(function(a,i){var u=i&&i.body;if(a){var o=e.url,n=a.status,s=(n?"HTTP error "+n:"Network error")+" from "+o,l=void 0;u&&u.error_description&&(s+=" - "+u.error_description,l=u.error_description);var d=new Error(s);(0,_assign2.default)(d,{statusCode:n,errorDescription:s,shortErrorDescription:l,error:a,body:u}),r(d)}else t({body:u,statusCode:i.statusCode})})}},{key:"_buildRequest",value:function(e){var t=e.uri,r=e.method,a=e.headers,i=e.data,u=e.auth,o=e.query,n=e.form,s=e.files,l=e.context,d=e.makerequest,f=void 0===d?_superagent2.default:d,c=f(r,t);if(this.prefix&&c.use(this.prefix),this._authorizationHeader(c,u),l&&this._applyContext(c,l),o&&c.query(o),a&&c.set(a),s){var h=!0,_=!1,v=void 0;try{for(var p,y=(0,_getIterator3.default)((0,_entries2.default)(s));!(h=(p=y.next()).done);h=!0){var m=(0,_slicedToArray3.default)(p.value,2),q=m[0],x=m[1],k={filepath:x.path};this.isForBrowser(f)&&(k=x.path),c.attach(q,x.data,k)}}catch(e){_=!0,v=e}finally{try{!h&&y.return&&y.return()}finally{if(_)throw v}}if(n){var g=!0,b=!1,C=void 0;try{for(var R,j=(0,_getIterator3.default)((0,_entries2.default)(n));!(g=(R=j.next()).done);g=!0){var P=(0,_slicedToArray3.default)(R.value,2),q=P[0],w=P[1];c.field(q,w)}}catch(e){b=!0,C=e}finally{try{!g&&j.return&&j.return()}finally{if(b)throw C}}}}else n?(c.type("form"),c.send(n)):i&&c.send(i);return c}},{key:"isForBrowser",value:function(){return!!(arguments.length>0&&void 0!==arguments[0]?arguments[0]:_superagent2.default).getXHR}},{key:"_applyContext",value:function(e,t){t.tool&&this._addToolContext(e,t.tool),t.project&&this._addProjectContext(e,t.project)}},{key:"_addToolContext",value:function(e,t){var r="";if(t.name&&(r+=this._toolIdent(t),t.components)){var a=!0,i=!1,u=void 0;try{for(var o,n=(0,_getIterator3.default)(t.components);!(a=(o=n.next()).done);a=!0){var s=o.value;r+=", "+this._toolIdent(s)}}catch(e){i=!0,u=e}finally{try{!a&&n.return&&n.return()}finally{if(i)throw u}}}r&&e.set("X-Particle-Tool",r)}},{key:"_toolIdent",value:function(e){return this._nameAtVersion(e.name,e.version)}},{key:"_nameAtVersion",value:function(e,t){var r="";return e&&(r+=e,t&&(r+="@"+t)),r}},{key:"_addProjectContext",value:function(e,t){var r=this._buildSemicolonSeparatedProperties(t,"name");r&&e.set("X-Particle-Project",r)}},{key:"_buildSemicolonSeparatedProperties",value:function(e,t){var r="";if(e[t]){r+=e[t];for(var a in e)a!==t&&e.hasOwnProperty(a)&&(r+="; "+a+"="+e[a])}return r}},{key:"_authorizationHeader",value:function(e,t){return t&&(void 0!==t.username?e.auth(t.username,t.password):e.set({Authorization:"Bearer "+t})),e}},{key:"_sanitizeFiles",value:function(e){var t=void 0;return e&&(t={},(0,_keys2.default)(e).forEach(function(r,a){t[a?"file"+(a+1):"file"]={data:e[r],path:r}})),t}}]),e}();exports.default=Agent,module.exports=exports.default;
|
|
3
3
|
},{"babel-runtime/core-js/get-iterator":8,"babel-runtime/core-js/object/assign":10,"babel-runtime/core-js/object/entries":13,"babel-runtime/core-js/object/keys":15,"babel-runtime/core-js/promise":17,"babel-runtime/helpers/classCallCheck":20,"babel-runtime/helpers/createClass":21,"babel-runtime/helpers/slicedToArray":24,"superagent":170,"superagent-prefix":168}],2:[function(require,module,exports){
|
|
4
4
|
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var _getIterator2=require("babel-runtime/core-js/get-iterator"),_getIterator3=_interopRequireDefault(_getIterator2),_assign=require("babel-runtime/core-js/object/assign"),_assign2=_interopRequireDefault(_assign),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_Particle=require("./Particle"),_Particle2=_interopRequireDefault(_Particle),_Library=require("./Library"),_Library2=_interopRequireDefault(_Library),Client=function(){function e(t){var r=t.auth,a=t.api,i=void 0===a?new _Particle2.default:a;(0,_classCallCheck3.default)(this,e),(0,_assign2.default)(this,{auth:r,api:i})}return(0,_createClass3.default)(e,[{key:"ready",value:function(){return Boolean(this.auth)}},{key:"libraries",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.api.listLibraries((0,_assign2.default)({},t,{auth:this.auth})).then(function(t){return(t.body.data||[]).map(function(t){return new _Library2.default(e,t)})})}},{key:"library",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.api.getLibrary((0,_assign2.default)({},r,{name:e,auth:this.auth})).then(function(e){var r=e.body.data||{};return new _Library2.default(t,r)})}},{key:"libraryVersions",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.api.getLibraryVersions((0,_assign2.default)({},r,{name:e,auth:this.auth})).then(function(e){return(e.body.data||[]).map(function(e){return new _Library2.default(t,e)})})}},{key:"contributeLibrary",value:function(e){var t=this;return this.api.contributeLibrary({archive:e,auth:this.auth}).then(function(e){var r=e.body.data||{};return new _Library2.default(t,r)},function(e){t._throwError(e)})}},{key:"publishLibrary",value:function(e){var t=this;return this.api.publishLibrary({name:e,auth:this.auth}).then(function(e){var r=e.body.data||{};return new _Library2.default(t,r)},function(e){t._throwError(e)})}},{key:"deleteLibrary",value:function(e){var t=this,r=e.name,a=e.force;return this.api.deleteLibrary({name:r,force:a,auth:this.auth}).then(function(){return!0},function(e){return t._throwError(e)})}},{key:"_throwError",value:function(e){if(e.body&&e.body.errors){var t=e.body.errors.map(function(e){return e.message}).join("\n");throw new Error(t)}throw e}},{key:"downloadFile",value:function(e){return this.api.downloadFile({uri:e})}},{key:"compileCode",value:function(e,t,r){return this.api.compileCode({files:e,platformId:t,targetVersion:r,auth:this.auth})}},{key:"signalDevice",value:function(e){var t=e.signal,r=e.deviceId;return this.api.signalDevice({signal:t,deviceId:r,auth:this.auth})}},{key:"listDevices",value:function(){return this.api.listDevices({auth:this.auth})}},{key:"listBuildTargets",value:function(){return this.api.listBuildTargets({onlyFeatured:!0,auth:this.auth}).then(function(e){var t=[],r=!0,a=!1,i=void 0;try{for(var n,u=(0,_getIterator3.default)(e.body.targets);!(r=(n=u.next()).done);r=!0){var l=n.value,o=!0,s=!1,h=void 0;try{for(var c,f=(0,_getIterator3.default)(l.platforms);!(o=(c=f.next()).done);o=!0){var d=c.value;t.push({version:l.version,platform:d,prerelease:l.prereleases.indexOf(d)>-1,firmware_vendor:l.firmware_vendor})}}catch(e){s=!0,h=e}finally{try{!o&&f.return&&f.return()}finally{if(s)throw h}}}}catch(e){a=!0,i=e}finally{try{!r&&u.return&&u.return()}finally{if(a)throw i}}return t},function(){})}},{key:"trackingIdentity",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.full,r=void 0!==t&&t,a=e.context;return this.api.trackingIdentity({full:r,context:a,auth:this.auth}).then(function(e){return e.body})}}]),e}();exports.default=Client,module.exports=exports.default;
|
|
5
5
|
},{"./Library":5,"./Particle":6,"babel-runtime/core-js/get-iterator":8,"babel-runtime/core-js/object/assign":10,"babel-runtime/helpers/classCallCheck":20,"babel-runtime/helpers/createClass":21}],3:[function(require,module,exports){
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},{"babel-runtime/core-js/object/get-prototype-of":14,"babel-runtime/core-js/promise":17,"babel-runtime/helpers/classCallCheck":20,"babel-runtime/helpers/createClass":21,"babel-runtime/helpers/inherits":22,"babel-runtime/helpers/possibleConstructorReturn":23,"events":136,"http":145,"https":145,"url":176}],5:[function(require,module,exports){
|
|
10
10
|
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var _promise=require("babel-runtime/core-js/promise"),_promise2=_interopRequireDefault(_promise),_assign=require("babel-runtime/core-js/object/assign"),_assign2=_interopRequireDefault(_assign),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),Library=function(){function e(r,t){(0,_classCallCheck3.default)(this,e),Object.defineProperty(this,"client",{value:r}),this._assignAttributes(t),this.downloadUrl=t.links&&t.links.download}return(0,_createClass3.default)(e,[{key:"_assignAttributes",value:function(e){(0,_assign2.default)(this,e.attributes)}},{key:"download",value:function(){return this.downloadUrl?this.client.downloadFile(this.downloadUrl):_promise2.default.reject(new Error("No download URL for this library"))}}]),e}();exports.default=Library,module.exports=exports.default;
|
|
11
11
|
},{"babel-runtime/core-js/object/assign":10,"babel-runtime/core-js/promise":17,"babel-runtime/helpers/classCallCheck":20,"babel-runtime/helpers/createClass":21}],6:[function(require,module,exports){
|
|
12
|
-
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var _assign=require("babel-runtime/core-js/object/assign"),_assign2=_interopRequireDefault(_assign),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_superagentBinaryParser=require("./superagent-binary-parser"),_superagentBinaryParser2=_interopRequireDefault(_superagentBinaryParser),_Defaults=require("./Defaults"),_Defaults2=_interopRequireDefault(_Defaults),_EventStream=require("./EventStream"),_EventStream2=_interopRequireDefault(_EventStream),_Agent=require("./Agent"),_Agent2=_interopRequireDefault(_Agent),_Client=require("./Client"),_Client2=_interopRequireDefault(_Client),Particle=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,_classCallCheck3.default)(this,e),(0,_assign2.default)(this,_Defaults2.default,t),this.context={},this.agent=new _Agent2.default(this.baseUrl)}return(0,_createClass3.default)(e,[{key:"_isValidContext",value:function(e,t){return("tool"===e||"project"===e)&&void 0!==t}},{key:"setContext",value:function(e,t){if(void 0!==t){if(!this._isValidContext(e,t))throw Error("uknown context name or undefined context: "+e);this.context[e]=t}}},{key:"_buildContext",value:function(e){return(0,_assign2.default)(this.context,e)}},{key:"login",value:function(e){var t=e.username,r=e.password,a=e.tokenDuration,u=void 0===a?this.tokenDuration:a,n=e.headers,i=e.context;return this.request({uri:"/oauth/token",method:"post",headers:n,form:{username:t,password:r,grant_type:"password",client_id:this.clientId,client_secret:this.clientSecret,expires_in:u},context:i})}},{key:"sendOtp",value:function(e){var t=e.mfaToken,r=e.otp,a=e.headers,u=e.context;return this.request({uri:"/oauth/token",method:"post",headers:a,form:{grant_type:"urn:custom:mfa-otp",mfa_token:t,otp:r,client_id:this.clientId,client_secret:this.clientSecret},context:u})}},{key:"enableMfa",value:function(e){var t=e.auth,r=e.headers,a=e.context;return this.get({uri:"/v1/user/mfa-enable",auth:t,headers:r,context:a})}},{key:"confirmMfa",value:function(e){var t=e.mfaToken,r=e.otp,a=e.invalidateTokens,u=void 0!==a&&a,n=e.auth,i=e.headers,s=e.context,o={mfa_token:t,otp:r};return u&&(o.invalidate_tokens=!0),this.post({uri:"/v1/user/mfa-enable",auth:n,headers:i,data:o,context:s})}},{key:"disableMfa",value:function(e){var t=e.currentPassword,r=e.auth,a=e.headers,u=e.context;return this.put({uri:"/v1/user/mfa-disable",auth:r,headers:a,data:{current_password:t},context:u})}},{key:"createCustomer",value:function(e){var t=e.email,r=e.password,a=e.product,u=e.headers,n=e.context;return this.request({uri:"/v1/products/"+a+"/customers",method:"post",headers:u,form:{email:t,password:r,grant_type:"client_credentials",client_id:this.clientId,client_secret:this.clientSecret},context:n})}},{key:"loginAsClientOwner",value:function(e){var t=e.headers,r=e.context;return this.request({uri:"/oauth/token",method:"post",headers:t,form:{grant_type:"client_credentials",client_id:this.clientId,client_secret:this.clientSecret},context:r})}},{key:"createUser",value:function(e){var t=e.username,r=e.password,a=e.accountInfo,u=e.headers,n=e.context;return this.post({uri:"/v1/users",headers:u,data:{username:t,password:r,account_info:a},context:n})}},{key:"verifyUser",value:function(e){var t=e.token,r=e.headers,a=e.context;return this.post({uri:"/v1/user/verify",headers:r,data:{token:t},context:a})}},{key:"resetPassword",value:function(e){var t=e.username,r=e.headers,a=e.context;return this.post({uri:"/v1/user/password-reset",headers:r,data:{username:t},context:a})}},{key:"deleteAccessToken",value:function(e){var t=e.username,r=e.password,a=e.token,u=e.headers,n=e.context;return this.delete({uri:"/v1/access_tokens/"+a,auth:{username:t,password:r},headers:u,data:{access_token:a},context:n})}},{key:"deleteCurrentAccessToken",value:function(e){var t=e.auth,r=e.headers,a=e.context;return this.delete({uri:"/v1/access_tokens/current",auth:t,headers:r,context:a})}},{key:"deleteActiveAccessTokens",value:function(e){var t=e.auth,r=e.headers,a=e.context;return this.delete({uri:"/v1/access_tokens",auth:t,headers:r,context:a})}},{key:"deleteUser",value:function(e){var t=e.auth,r=e.password,a=e.headers,u=e.context;return this.delete({uri:"/v1/user",data:{password:r},auth:t,headers:a,context:u})}},{key:"listAccessTokens",value:function(e){var t=e.username,r=e.password,a=e.otp,u=e.headers,n=e.context;return this.get({uri:"/v1/access_tokens",auth:{username:t,password:r},query:a?{otp:a}:void 0,headers:u,context:n})}},{key:"trackingIdentity",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.full,r=void 0!==t&&t,a=e.auth,u=e.headers,n=e.context;return this.get({uri:"/v1/user/identify",auth:a,headers:u,query:r?void 0:{tracking:1},context:n})}},{key:"listDevices",value:function(e){var t=e.deviceId,r=e.deviceName,a=e.groups,u=e.sortAttr,n=e.sortDir,i=e.page,s=e.perPage,o=e.product,c=e.auth,d=e.headers,h=e.context,v=void 0,l=void 0;return o?(v="/v1/products/"+o+"/devices",a=Array.isArray(a)?a.join(","):void 0,l={deviceId:t,deviceName:r,groups:a,sortAttr:u,sortDir:n,page:i,per_page:s}):v="/v1/devices",this.get({uri:v,auth:c,headers:d,query:l,context:h})}},{key:"getDevice",value:function(e){var t=e.deviceId,r=e.product,a=e.auth,u=e.headers,n=e.context,i=this.deviceUri({deviceId:t,product:r});return this.get({uri:i,auth:a,headers:u,context:n})}},{key:"claimDevice",value:function(e){var t=e.deviceId,r=e.requestTransfer,a=e.auth,u=e.headers,n=e.context;return this.post({uri:"/v1/devices",auth:a,headers:u,data:{id:t,request_transfer:!!r},context:n})}},{key:"addDeviceToProduct",value:function(e){var t=e.deviceId,r=e.product,a=e.file,u=e.auth,n=e.headers,i=e.context,s=void 0,o=void 0;return a?s={file:a}:t&&(o={id:t}),this.request({uri:"/v1/products/"+r+"/devices",method:"post",headers:n,data:o,files:s,auth:u,context:i})}},{key:"removeDevice",value:function(e){var t=e.deviceId,r=e.deny,a=e.product,u=e.auth,n=e.headers,i=e.context,s=this.deviceUri({deviceId:t,product:a}),o=a?{deny:r}:void 0;return this.delete({uri:s,data:o,auth:u,headers:n,context:i})}},{key:"removeDeviceOwner",value:function(e){var t=e.deviceId,r=e.product,a=e.auth,u=e.headers,n=e.context,i="/v1/products/"+r+"/devices/"+t+"/owner";return this.delete({uri:i,auth:a,headers:u,context:n})}},{key:"renameDevice",value:function(e){var t=e.deviceId,r=e.name,a=e.product,u=e.auth,n=e.headers,i=e.context;return this.updateDevice({deviceId:t,name:r,product:a,auth:u,headers:n,context:i})}},{key:"signalDevice",value:function(e){var t=e.deviceId,r=e.signal,a=e.product,u=e.auth,n=e.headers,i=e.context;return this.updateDevice({deviceId:t,signal:r,product:a,auth:u,headers:n,context:i})}},{key:"setDeviceNotes",value:function(e){var t=e.deviceId,r=e.notes,a=e.product,u=e.auth,n=e.headers,i=e.context;return this.updateDevice({deviceId:t,notes:r,product:a,auth:u,headers:n,context:i})}},{key:"markAsDevelopmentDevice",value:function(e){var t=e.deviceId,r=e.development,a=void 0===r||r,u=e.product,n=e.auth,i=e.headers,s=e.context;return this.updateDevice({deviceId:t,development:a,product:u,auth:n,headers:i,context:s})}},{key:"lockDeviceProductFirmware",value:function(e){var t=e.deviceId,r=e.desiredFirmwareVersion,a=e.flash,u=e.product,n=e.auth,i=e.context;return this.updateDevice({deviceId:t,desiredFirmwareVersion:r,flash:a,product:u,auth:n,context:i})}},{key:"unlockDeviceProductFirmware",value:function(e){var t=e.deviceId,r=e.product,a=e.auth,u=e.headers,n=e.context;return this.updateDevice({deviceId:t,desiredFirmwareVersion:null,product:r,auth:a,headers:u,context:n})}},{key:"updateDevice",value:function(e){var t=e.deviceId,r=e.name,a=e.signal,u=e.notes,n=e.development,i=e.desiredFirmwareVersion,s=e.flash,o=e.product,c=e.auth,d=e.headers,h=e.context;void 0!==a&&(a=a?"1":"0");var v=this.deviceUri({deviceId:t,product:o}),l=o?{name:r,signal:a,notes:u,development:n,desired_firmware_version:i,flash:s}:{name:r,signal:a,notes:u};return this.put({uri:v,auth:c,headers:d,data:l,context:h})}},{key:"provisionDevice",value:function(e){var t=e.productId,r=e.auth,a=e.headers,u=e.context;return this.post({uri:"/v1/devices",auth:r,headers:a,data:{product_id:t},context:u})}},{key:"getClaimCode",value:function(e){var t=e.iccid,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/device_claims":"/v1/device_claims";return this.post({uri:i,auth:a,headers:u,data:{iccid:t},context:n})}},{key:"validatePromoCode",value:function(e){var t=e.promoCode,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/promo_code/"+t,auth:r,headers:a,context:u})}},{key:"changeProduct",value:function(e){var t=e.deviceId,r=e.productId,a=e.auth,u=e.headers,n=e.context;return this.put({uri:"/v1/devices/"+t,auth:a,headers:u,data:{product_id:r},context:n})}},{key:"getVariable",value:function(e){var t=e.deviceId,r=e.name,a=e.product,u=e.auth,n=e.headers,i=e.context,s=a?"/v1/products/"+a+"/devices/"+t+"/"+r:"/v1/devices/"+t+"/"+r;return this.get({uri:s,auth:u,headers:n,context:i})}},{key:"flashDevice",value:function(e){var t=e.deviceId,r=e.product,a=e.files,u=e.targetVersion,n=e.auth,i=e.headers,s=e.context,o=this.deviceUri({deviceId:t,product:r}),c={};return u?c.build_target_version=u:c.latest="true",this.request({uri:o,method:"put",auth:n,headers:i,files:a,form:c,context:s})}},{key:"flashTinker",value:function(e){var t=e.deviceId,r=e.auth,a=e.headers,u=e.context;return console&&console.warning&&console.warning("Particle.flashTinker is deprecated"),this.put({uri:"/v1/devices/"+t,headers:a,data:{app:"tinker"},auth:r,context:u})}},{key:"compileCode",value:function(e){var t=e.files,r=e.platformId,a=e.targetVersion,u=e.auth,n=e.headers,i=e.context,s={platform_id:r};return a?s.build_target_version=a:s.latest="true",this.request({uri:"/v1/binaries",method:"post",auth:u,headers:n,files:t,form:s,context:i})}},{key:"downloadFirmwareBinary",value:function(e){var t=e.binaryId,r=e.auth,a=e.headers,u=e.context,n=this.request({uri:"/v1/binaries/"+t,method:"get",auth:r,headers:a,context:u,raw:!0});return this._provideFileData(n)}},{key:"sendPublicKey",value:function(e){var t=e.deviceId,r=e.key,a=e.algorithm,u=e.auth,n=e.headers,i=e.context;return this.post({uri:"/v1/provisioning/"+t,auth:u,headers:n,data:{deviceID:t,publicKey:"string"==typeof r?r:r.toString(),filename:"particle-api",order:"manual_"+Date.now(),algorithm:a||"rsa"},context:i})}},{key:"callFunction",value:function(e){var t=e.deviceId,r=e.name,a=e.argument,u=e.product,n=e.auth,i=e.headers,s=e.context,o=u?"/v1/products/"+u+"/devices/"+t+"/"+r:"/v1/devices/"+t+"/"+r;return this.post({uri:o,auth:n,headers:i,data:{args:a},context:s})}},{key:"getEventStream",value:function(e){var t=e.deviceId,r=e.name,a=e.org,u=e.product,n=e.auth,i="/v1/";return a&&(i+="orgs/"+a+"/"),u&&(i+="products/"+u+"/"),t&&(i+="devices/","mine"!==t.toLowerCase()&&(i+=t+"/")),i+="events",r&&(i+="/"+encodeURIComponent(r)),new _EventStream2.default(""+this.baseUrl+i,n).connect()}},{key:"publishEvent",value:function(e){var t=e.name,r=e.data,a=e.isPrivate,u=e.product,n=e.auth,i=e.headers,s=e.context,o=u?"/v1/products/"+u+"/events":"/v1/devices/events",c={name:t,data:r,private:a};return this.post({uri:o,auth:n,headers:i,data:c,context:s})}},{key:"createWebhook",value:function(e){var t=e.event,r=e.url,a=e.device,u=e.rejectUnauthorized,n=e.noDefaults,i=e.hook,s=e.product,o=e.auth,c=e.headers,d=e.context,h=s?"/v1/products/"+s+"/webhooks":"/v1/webhooks",v={event:t,url:r,deviceId:a,rejectUnauthorized:u,noDefaults:n};return i&&(v.requestType=i.method,v.auth=i.auth,v.headers=i.headers,v.query=i.query,v.json=i.json,v.form=i.form,v.body=i.body,v.responseTemplate=i.responseTemplate,v.responseTopic=i.responseEvent,v.errorResponseTopic=i.errorResponseEvent),v.requestType||(v.requestType="POST"),this.post({uri:h,auth:o,headers:c,data:v,context:d})}},{key:"deleteWebhook",value:function(e){var t=e.hookId,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/webhooks/"+t:"/v1/webhooks/"+t;return this.delete({uri:i,auth:a,headers:u,context:n})}},{key:"listWebhooks",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context,n=t?"/v1/products/"+t+"/webhooks":"/v1/webhooks";return this.get({uri:n,auth:r,headers:a,context:u})}},{key:"createIntegration",value:function(e){var t=e.event,r=e.settings,a=e.deviceId,u=e.product,n=e.auth,i=e.headers,s=e.context,o=u?"/v1/products/"+u+"/integrations":"/v1/integrations",c=(0,_assign2.default)({event:t,deviceid:a},r);return this.post({uri:o,data:c,auth:n,headers:i,context:s})}},{key:"editIntegration",value:function(e){var t=e.integrationId,r=e.event,a=e.settings,u=e.deviceId,n=e.product,i=e.auth,s=e.headers,o=e.context,c=n?"/v1/products/"+n+"/integrations/"+t:"/v1/integrations/"+t,d=(0,_assign2.default)({event:r,deviceid:u},a);return this.put({uri:c,auth:i,headers:s,data:d,context:o})}},{key:"deleteIntegration",value:function(e){var t=e.integrationId,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/integrations/"+t:"/v1/integrations/"+t;return this.delete({uri:i,auth:a,headers:u,context:n})}},{key:"listIntegrations",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context,n=t?"/v1/products/"+t+"/integrations":"/v1/integrations";return this.get({uri:n,auth:r,headers:a,context:u})}},{key:"getUserInfo",value:function(e){var t=e.auth,r=e.headers,a=e.context;return this.get({uri:"/v1/user",auth:t,headers:r,context:a})}},{key:"setUserInfo",value:function(e){var t=e.accountInfo,r=e.auth,a=e.headers,u=e.context,n={account_info:t};return this.put({uri:"/v1/user",auth:r,headers:a,data:n,context:u})}},{key:"changeUsername",value:function(e){var t=e.currentPassword,r=e.username,a=e.invalidateTokens,u=void 0!==a&&a,n=e.auth,i=e.headers,s=e.context,o={username:r,current_password:t};return u&&(o.invalidate_tokens=!0),this.put({uri:"/v1/user",auth:n,headers:i,data:o,context:s})}},{key:"changeUserPassword",value:function(e){var t=e.currentPassword,r=e.password,a=e.invalidateTokens,u=void 0!==a&&a,n=e.auth,i=e.headers,s=e.context,o={password:r,current_password:t};return u&&(o.invalidate_tokens=!0),this.put({uri:"/v1/user",auth:n,headers:i,data:o,context:s})}},{key:"listSIMs",value:function(e){var t=e.iccid,r=e.deviceId,a=e.deviceName,u=e.page,n=e.perPage,i=e.product,s=e.auth,o=e.headers,c=e.context,d=i?"/v1/products/"+i+"/sims":"/v1/sims",h=i?{iccid:t,deviceId:r,deviceName:a,page:u,per_page:n}:void 0;return this.get({uri:d,auth:s,headers:o,query:h,context:c})}},{key:"getSIMDataUsage",value:function(e){var t=e.iccid,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/sims/"+t+"/data_usage":"/v1/sims/"+t+"/data_usage";return this.get({uri:i,auth:a,headers:u,context:n})}},{key:"getFleetDataUsage",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/products/"+t+"/sims/data_usage",auth:r,headers:a,context:u})}},{key:"checkSIM",value:function(e){var t=e.iccid,r=e.auth,a=e.headers,u=e.context;return this.head({uri:"/v1/sims/"+t,auth:r,headers:a,context:u})}},{key:"activateSIM",value:function(e){var t=e.iccid,r=e.iccids,a=e.country,u=e.promoCode,n=e.product,i=e.auth,s=e.headers,o=e.context;r=r||[t];var c=n?"/v1/products/"+n+"/sims":"/v1/sims/"+t,d=n?{sims:r,country:a}:{country:a,promoCode:u,action:"activate"},h=n?"post":"put";return this.request({uri:c,method:h,headers:s,data:d,auth:i,context:o})}},{key:"deactivateSIM",value:function(e){var t=e.iccid,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/sims/"+t:"/v1/sims/"+t,s={action:"deactivate"};return this.put({uri:i,auth:a,headers:u,data:s,context:n})}},{key:"reactivateSIM",value:function(e){var t=e.iccid,r=e.mbLimit,a=e.product,u=e.auth,n=e.headers,i=e.context,s=a?"/v1/products/"+a+"/sims/"+t:"/v1/sims/"+t,o={mb_limit:r,action:"reactivate"};return this.put({uri:s,auth:u,headers:n,data:o,context:i})}},{key:"updateSIM",value:function(e){var t=e.iccid,r=e.mbLimit,a=e.product,u=e.auth,n=e.headers,i=e.context,s=a?"/v1/products/"+a+"/sims/"+t:"/v1/sims/"+t,o={mb_limit:r};return this.put({uri:s,auth:u,headers:n,data:o,context:i})}},{key:"removeSIM",value:function(e){var t=e.iccid,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/sims/"+t:"/v1/sims/"+t;return this.delete({uri:i,auth:a,headers:u,context:n})}},{key:"listBuildTargets",value:function(e){var t=e.onlyFeatured,r=e.auth,a=e.headers,u=e.context,n=t?{featured:!!t}:void 0;return this.get({uri:"/v1/build_targets",auth:r,headers:a,query:n,context:u})}},{key:"listLibraries",value:function(e){var t=e.page,r=e.limit,a=e.filter,u=e.sort,n=e.architectures,i=e.category,s=e.scope,o=e.excludeScopes,c=e.auth,d=e.headers,h=e.context;return this.get({uri:"/v1/libraries",auth:c,headers:d,query:{page:t,filter:a,limit:r,sort:u,architectures:this._asList(n),category:i,scope:s,excludeScopes:this._asList(o)},context:h})}},{key:"_asList",value:function(e){return Array.isArray(e)?e.join(","):e}},{key:"getLibrary",value:function(e){var t=e.name,r=e.version,a=e.auth,u=e.headers,n=e.context;return this.get({uri:"/v1/libraries/"+t,auth:a,headers:u,query:{version:r},context:n})}},{key:"getLibraryVersions",value:function(e){var t=e.name,r=e.page,a=e.limit,u=e.auth,n=e.headers,i=e.context;return this.get({uri:"/v1/libraries/"+t+"/versions",auth:u,headers:n,query:{page:r,limit:a},context:i})}},{key:"contributeLibrary",value:function(e){var t=e.archive,r=e.auth,a=e.headers,u=e.context,n={"archive.tar.gz":t};return this.request({uri:"/v1/libraries",method:"post",auth:r,headers:a,files:n,context:u})}},{key:"publishLibrary",value:function(e){var t=e.name,r=e.auth,a=e.headers,u=e.context;return this.request({uri:"/v1/libraries/"+t,method:"patch",auth:r,headers:a,data:{visibility:"public"},context:u})}},{key:"deleteLibrary",value:function(e){var t=e.name,r=e.force,a=e.auth,u=e.headers,n=e.context;return this.delete({uri:"/v1/libraries/"+t,auth:a,headers:u,data:{force:r},context:n})}},{key:"downloadFile",value:function(e){var t=e.uri,r=e.headers,a=e.context,u=this.request({uri:t,method:"get",headers:r,context:a,raw:!0});return this._provideFileData(u)}},{key:"listOAuthClients",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context,n=t?"/v1/products/"+t+"/clients":"/v1/clients";return this.get({uri:n,auth:r,headers:a,context:u})}},{key:"createOAuthClient",value:function(e){var t=e.name,r=e.type,a=e.redirect_uri,u=e.scope,n=e.product,i=e.auth,s=e.headers,o=e.context,c=n?"/v1/products/"+n+"/clients":"/v1/clients",d={name:t,type:r,redirect_uri:a,scope:u};return this.post({uri:c,auth:i,headers:s,data:d,context:o})}},{key:"updateOAuthClient",value:function(e){var t=e.clientId,r=e.name,a=e.scope,u=e.product,n=e.auth,i=e.headers,s=e.context,o=u?"/v1/products/"+u+"/clients/"+t:"/v1/clients/"+t,c={name:r,scope:a};return this.put({uri:o,data:c,auth:n,headers:i,context:s})}},{key:"deleteOAuthClient",value:function(e){var t=e.clientId,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/clients/"+t:"/v1/clients/"+t;return this.delete({uri:i,auth:a,headers:u,context:n})}},{key:"listProducts",value:function(e){var t=e.auth,r=e.headers,a=e.context;return this.get({uri:"/v1/products",auth:t,headers:r,context:a})}},{key:"getProduct",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/products/"+t,auth:r,headers:a,context:u})}},{key:"listProductFirmware",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/products/"+t+"/firmware",auth:r,headers:a,context:u})}},{key:"uploadProductFirmware",value:function(e){var t=e.file,r=e.version,a=e.title,u=e.description,n=e.product,i=e.auth,s=e.headers,o=e.context;return this.request({uri:"/v1/products/"+n+"/firmware",method:"post",auth:i,headers:s,form:{version:r,title:a,description:u},files:{"firmware.bin":t},context:o})}},{key:"getProductFirmware",value:function(e){var t=e.version,r=e.product,a=e.auth,u=e.headers,n=e.context;return this.get({uri:"/v1/products/"+r+"/firmware/"+t,auth:a,headers:u,context:n})}},{key:"updateProductFirmware",value:function(e){var t=e.version,r=e.title,a=e.description,u=e.product,n=e.auth,i=e.headers,s=e.context,o="/v1/products/"+u+"/firmware/"+t;return this.put({uri:o,auth:n,headers:i,data:{title:r,description:a},context:s})}},{key:"downloadProductFirmware",value:function(e){var t=e.version,r=e.product,a=e.auth,u=e.headers,n=e.context,i=this.request({uri:"/v1/products/"+r+"/firmware/"+t+"/binary",method:"get",auth:a,headers:u,context:n,raw:!0});return this._provideFileData(i)}},{key:"_provideFileData",value:function(e){return e=this.agent.isForBrowser()?e.responseType("arraybuffer").then(function(e){return e.body=e.xhr.response,e}):e.buffer(!0).parse(_superagentBinaryParser2.default),e.then(function(e){return e.body})}},{key:"releaseProductFirmware",value:function(e){var t=e.version,r=e.product,a=e.auth,u=e.headers,n=e.context,i="/v1/products/"+r+"/firmware/release";return this.put({uri:i,auth:a,headers:u,data:{version:t},context:n})}},{key:"listTeamMembers",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/products/"+t+"/team",auth:r,headers:a,context:u})}},{key:"inviteTeamMember",value:function(e){var t=e.username,r=e.product,a=e.auth,u=e.headers,n=e.context;return this.post({uri:"/v1/products/"+r+"/team",auth:a,headers:u,data:{username:t},context:n})}},{key:"removeTeamMember",value:function(e){var t=e.username,r=e.product,a=e.auth,u=e.headers,n=e.context;return this.delete({uri:"/v1/products/"+r+"/team/"+t,auth:a,headers:u,context:n})}},{key:"lookupSerialNumber",value:function(e){var t=e.serialNumber,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/serial_numbers/"+t,auth:r,headers:a,context:u})}},{key:"createMeshNetwork",value:function(e){var t=e.name,r=e.deviceId,a=e.iccid,u=e.auth,n=e.headers,i=e.context;return this.post({uri:"/v1/networks",auth:u,headers:n,data:{name:t,device_id:r,iccid:a},context:i})}},{key:"removeMeshNetwork",value:function(e){var t=e.networkId,r=e.auth,a=e.headers,u=e.context;return this.delete({uri:"/v1/networks/"+t,auth:r,headers:a,context:u})}},{key:"listMeshNetworks",value:function(e){var t=e.page,r=e.perPage,a=e.auth,u=e.headers,n=e.context,i=t?{page:t,per_page:r}:void 0;return this.get({uri:"/v1/networks",auth:a,headers:u,query:i,context:n})}},{key:"getMeshNetwork",value:function(e){var t=e.networkId,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/networks/"+t,auth:r,headers:a,context:u})}},{key:"updateMeshNetwork",value:function(e){var t=e.networkId,r=e.action,a=e.deviceId,u=e.auth,n=e.headers,i=e.context;return this.put({uri:"/v1/networks/"+t,auth:u,headers:n,data:{action:r,device_id:a},context:i})}},{key:"addMeshNetworkDevice",value:function(e){var t=e.networkId,r=e.deviceId,a=e.auth,u=e.headers,n=e.context;return this.updateMeshNetwork({action:"add-device",networkId:t,deviceId:r,auth:a,headers:u,context:n})}},{key:"removeMeshNetworkDevice",value:function(e){var t=e.networkId,r=e.deviceId,a=e.auth,u=e.headers,n=e.context;return t?this.updateMeshNetwork({action:"remove-device",networkId:t,deviceId:r,auth:a,headers:u,context:n}):this.delete({uri:"/v1/devices/"+r+"/network",auth:a,headers:u,context:n})}},{key:"listMeshNetworkDevices",value:function(e){var t=e.networkId,r=e.role,a=e.page,u=e.perPage,n=e.auth,i=e.headers,s=e.context,o=r||a?{role:r,page:a,per_page:u}:void 0;return this.get({uri:"/v1/networks/"+t+"/devices",auth:n,headers:i,query:o,context:s})}},{key:"getProductConfiguration",value:function(e){var t=e.auth,r=e.product,a=e.headers,u=e.context;return this.get({uri:"/v1/products/"+r+"/config",auth:t,headers:a,context:u})}},{key:"getProductConfigurationSchema",value:function(e){var t=e.auth,r=e.product,a=e.headers,u=void 0===a?{}:a,n=e.context;return u.accept="application/schema+json",this.get({uri:"/v1/products/"+r+"/config",auth:t,headers:u,context:n})}},{key:"getProductDeviceConfiguration",value:function(e){var t=e.auth,r=e.product,a=e.deviceId,u=e.headers,n=e.context;return this.get({uri:"/v1/products/"+r+"/config/"+a,auth:t,headers:u,context:n})}},{key:"getProductDeviceConfigurationSchema",value:function(e){var t=e.auth,r=e.product,a=e.deviceId,u=e.headers,n=e.context;return u.accept="application/schema+json",this.get({uri:"/v1/products/"+r+"/config/"+a,auth:t,headers:u,context:n})}},{key:"setProductConfiguration",value:function(e){var t=e.auth,r=e.product,a=e.config,u=e.headers,n=e.context;return this.put({uri:"/v1/products/"+r+"/config",auth:t,data:a,headers:u,context:n})}},{key:"setProductDeviceConfiguration",value:function(e){var t=e.auth,r=e.product,a=e.deviceId,u=e.config,n=e.headers,i=e.context;return this.put({uri:"/v1/products/"+r+"/config/"+a,data:u,auth:t,headers:n,context:i})}},{key:"getProductLocations",value:function(e){var t=e.auth,r=e.product,a=e.dateRange,u=e.rectBl,n=e.rectTr,i=e.deviceId,s=e.deviceName,o=e.groups,c=e.page,d=e.perPage,h=e.headers,v=e.context;return this.get({uri:"/v1/products/"+r+"/locations",query:{date_range:a,rect_bl:u,rect_tr:n,device_id:i,device_name:s,groups:o,page:c,per_page:d},auth:t,headers:h,context:v})}},{key:"getProductDeviceLocations",value:function(e){var t=e.auth,r=e.product,a=e.dateRange,u=e.rectBl,n=e.rectTr,i=e.deviceId,s=e.headers,o=e.context;return this.get({uri:"/v1/products/"+r+"/locations/"+i,query:{date_range:a,rect_bl:u,rect_tr:n},auth:t,headers:s,context:o})}},{key:"deviceUri",value:function(e){var t=e.deviceId,r=e.product;return r?"/v1/products/"+r+"/devices/"+t:"/v1/devices/"+t}},{key:"get",value:function(e){var t=e.uri,r=e.auth,a=e.headers,u=e.query,n=e.context;return n=this._buildContext(n),this.agent.get({uri:t,auth:r,headers:a,query:u,context:n})}},{key:"head",value:function(e){var t=e.uri,r=e.auth,a=e.headers,u=e.query,n=e.context;return n=this._buildContext(n),this.agent.head({uri:t,auth:r,headers:a,query:u,context:n})}},{key:"post",value:function(e){var t=e.uri,r=e.auth,a=e.headers,u=e.data,n=e.context;return n=this._buildContext(n),this.agent.post({uri:t,auth:r,headers:a,data:u,context:n})}},{key:"put",value:function(e){var t=e.uri,r=e.auth,a=e.headers,u=e.data,n=e.context;return n=this._buildContext(n),this.agent.put({uri:t,auth:r,headers:a,data:u,context:n})}},{key:"delete",value:function(e){var t=e.uri,r=e.auth,a=e.headers,u=e.data,n=e.context;return n=this._buildContext(n),this.agent.delete({uri:t,auth:r,headers:a,data:u,context:n})}},{key:"request",value:function(e){return e.context=this._buildContext(e.context),this.agent.request(e)}},{key:"client",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new _Client2.default((0,_assign2.default)({api:this},e))}}]),e}();Particle.prototype.removeAccessToken=Particle.prototype.deleteAccessToken,exports.default=Particle,module.exports=exports.default;
|
|
12
|
+
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var _assign=require("babel-runtime/core-js/object/assign"),_assign2=_interopRequireDefault(_assign),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_superagentBinaryParser=require("./superagent-binary-parser"),_superagentBinaryParser2=_interopRequireDefault(_superagentBinaryParser),_Defaults=require("./Defaults"),_Defaults2=_interopRequireDefault(_Defaults),_EventStream=require("./EventStream"),_EventStream2=_interopRequireDefault(_EventStream),_Agent=require("./Agent"),_Agent2=_interopRequireDefault(_Agent),_Client=require("./Client"),_Client2=_interopRequireDefault(_Client),Particle=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,_classCallCheck3.default)(this,e),(0,_assign2.default)(this,_Defaults2.default,t),this.context={},this.agent=new _Agent2.default(this.baseUrl)}return(0,_createClass3.default)(e,[{key:"_isValidContext",value:function(e,t){return("tool"===e||"project"===e)&&void 0!==t}},{key:"setContext",value:function(e,t){if(void 0!==t){if(!this._isValidContext(e,t))throw Error("uknown context name or undefined context: "+e);this.context[e]=t}}},{key:"_buildContext",value:function(e){return(0,_assign2.default)(this.context,e)}},{key:"login",value:function(e){var t=e.username,r=e.password,a=e.tokenDuration,u=void 0===a?this.tokenDuration:a,n=e.headers,i=e.context;return this.request({uri:"/oauth/token",method:"post",headers:n,form:{username:t,password:r,grant_type:"password",client_id:this.clientId,client_secret:this.clientSecret,expires_in:u},context:i})}},{key:"sendOtp",value:function(e){var t=e.mfaToken,r=e.otp,a=e.headers,u=e.context;return this.request({uri:"/oauth/token",method:"post",headers:a,form:{grant_type:"urn:custom:mfa-otp",mfa_token:t,otp:r,client_id:this.clientId,client_secret:this.clientSecret},context:u})}},{key:"enableMfa",value:function(e){var t=e.auth,r=e.headers,a=e.context;return this.get({uri:"/v1/user/mfa-enable",auth:t,headers:r,context:a})}},{key:"confirmMfa",value:function(e){var t=e.mfaToken,r=e.otp,a=e.invalidateTokens,u=void 0!==a&&a,n=e.auth,i=e.headers,s=e.context,o={mfa_token:t,otp:r};return u&&(o.invalidate_tokens=!0),this.post({uri:"/v1/user/mfa-enable",auth:n,headers:i,data:o,context:s})}},{key:"disableMfa",value:function(e){var t=e.currentPassword,r=e.auth,a=e.headers,u=e.context;return this.put({uri:"/v1/user/mfa-disable",auth:r,headers:a,data:{current_password:t},context:u})}},{key:"createCustomer",value:function(e){var t=e.email,r=e.password,a=e.product,u=e.headers,n=e.context;return this.request({uri:"/v1/products/"+a+"/customers",method:"post",headers:u,form:{email:t,password:r,grant_type:"client_credentials",client_id:this.clientId,client_secret:this.clientSecret},context:n})}},{key:"loginAsClientOwner",value:function(e){var t=e.headers,r=e.context;return this.request({uri:"/oauth/token",method:"post",headers:t,form:{grant_type:"client_credentials",client_id:this.clientId,client_secret:this.clientSecret},context:r})}},{key:"createUser",value:function(e){var t=e.username,r=e.password,a=e.accountInfo,u=e.headers,n=e.context;return this.post({uri:"/v1/users",headers:u,data:{username:t,password:r,account_info:a},context:n})}},{key:"verifyUser",value:function(e){var t=e.token,r=e.headers,a=e.context;return this.post({uri:"/v1/user/verify",headers:r,data:{token:t},context:a})}},{key:"resetPassword",value:function(e){var t=e.username,r=e.headers,a=e.context;return this.post({uri:"/v1/user/password-reset",headers:r,data:{username:t},context:a})}},{key:"deleteAccessToken",value:function(e){var t=e.username,r=e.password,a=e.token,u=e.headers,n=e.context;return this.delete({uri:"/v1/access_tokens/"+a,auth:{username:t,password:r},headers:u,data:{access_token:a},context:n})}},{key:"deleteCurrentAccessToken",value:function(e){var t=e.auth,r=e.headers,a=e.context;return this.delete({uri:"/v1/access_tokens/current",auth:t,headers:r,context:a})}},{key:"deleteActiveAccessTokens",value:function(e){var t=e.auth,r=e.headers,a=e.context;return this.delete({uri:"/v1/access_tokens",auth:t,headers:r,context:a})}},{key:"deleteUser",value:function(e){var t=e.auth,r=e.password,a=e.headers,u=e.context;return this.delete({uri:"/v1/user",data:{password:r},auth:t,headers:a,context:u})}},{key:"listAccessTokens",value:function(e){var t=e.username,r=e.password,a=e.otp,u=e.headers,n=e.context;return this.get({uri:"/v1/access_tokens",auth:{username:t,password:r},query:a?{otp:a}:void 0,headers:u,context:n})}},{key:"trackingIdentity",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.full,r=void 0!==t&&t,a=e.auth,u=e.headers,n=e.context;return this.get({uri:"/v1/user/identify",auth:a,headers:u,query:r?void 0:{tracking:1},context:n})}},{key:"listDevices",value:function(e){var t=e.deviceId,r=e.deviceName,a=e.groups,u=e.sortAttr,n=e.sortDir,i=e.page,s=e.perPage,o=e.product,c=e.auth,d=e.headers,h=e.context,v=void 0,l=void 0;return o?(v="/v1/products/"+o+"/devices",a=Array.isArray(a)?a.join(","):void 0,l={deviceId:t,deviceName:r,groups:a,sortAttr:u,sortDir:n,page:i,per_page:s}):v="/v1/devices",this.get({uri:v,auth:c,headers:d,query:l,context:h})}},{key:"getDevice",value:function(e){var t=e.deviceId,r=e.product,a=e.auth,u=e.headers,n=e.context,i=this.deviceUri({deviceId:t,product:r});return this.get({uri:i,auth:a,headers:u,context:n})}},{key:"claimDevice",value:function(e){var t=e.deviceId,r=e.requestTransfer,a=e.auth,u=e.headers,n=e.context;return this.post({uri:"/v1/devices",auth:a,headers:u,data:{id:t,request_transfer:!!r},context:n})}},{key:"addDeviceToProduct",value:function(e){var t=e.deviceId,r=e.product,a=e.file,u=e.auth,n=e.headers,i=e.context,s=void 0,o=void 0;return a?s={file:a}:t&&(o={id:t}),this.request({uri:"/v1/products/"+r+"/devices",method:"post",headers:n,data:o,files:s,auth:u,context:i})}},{key:"removeDevice",value:function(e){var t=e.deviceId,r=e.deny,a=e.product,u=e.auth,n=e.headers,i=e.context,s=this.deviceUri({deviceId:t,product:a}),o=a?{deny:r}:void 0;return this.delete({uri:s,data:o,auth:u,headers:n,context:i})}},{key:"removeDeviceOwner",value:function(e){var t=e.deviceId,r=e.product,a=e.auth,u=e.headers,n=e.context,i="/v1/products/"+r+"/devices/"+t+"/owner";return this.delete({uri:i,auth:a,headers:u,context:n})}},{key:"renameDevice",value:function(e){var t=e.deviceId,r=e.name,a=e.product,u=e.auth,n=e.headers,i=e.context;return this.updateDevice({deviceId:t,name:r,product:a,auth:u,headers:n,context:i})}},{key:"signalDevice",value:function(e){var t=e.deviceId,r=e.signal,a=e.product,u=e.auth,n=e.headers,i=e.context;return this.updateDevice({deviceId:t,signal:r,product:a,auth:u,headers:n,context:i})}},{key:"setDeviceNotes",value:function(e){var t=e.deviceId,r=e.notes,a=e.product,u=e.auth,n=e.headers,i=e.context;return this.updateDevice({deviceId:t,notes:r,product:a,auth:u,headers:n,context:i})}},{key:"markAsDevelopmentDevice",value:function(e){var t=e.deviceId,r=e.development,a=void 0===r||r,u=e.product,n=e.auth,i=e.headers,s=e.context;return this.updateDevice({deviceId:t,development:a,product:u,auth:n,headers:i,context:s})}},{key:"lockDeviceProductFirmware",value:function(e){var t=e.deviceId,r=e.desiredFirmwareVersion,a=e.flash,u=e.product,n=e.auth,i=e.context;return this.updateDevice({deviceId:t,desiredFirmwareVersion:r,flash:a,product:u,auth:n,context:i})}},{key:"unlockDeviceProductFirmware",value:function(e){var t=e.deviceId,r=e.product,a=e.auth,u=e.headers,n=e.context;return this.updateDevice({deviceId:t,desiredFirmwareVersion:null,product:r,auth:a,headers:u,context:n})}},{key:"updateDevice",value:function(e){var t=e.deviceId,r=e.name,a=e.signal,u=e.notes,n=e.development,i=e.desiredFirmwareVersion,s=e.flash,o=e.product,c=e.auth,d=e.headers,h=e.context;void 0!==a&&(a=a?"1":"0");var v=this.deviceUri({deviceId:t,product:o}),l=o?{name:r,signal:a,notes:u,development:n,desired_firmware_version:i,flash:s}:{name:r,signal:a,notes:u};return this.put({uri:v,auth:c,headers:d,data:l,context:h})}},{key:"provisionDevice",value:function(e){var t=e.productId,r=e.auth,a=e.headers,u=e.context;return this.post({uri:"/v1/devices",auth:r,headers:a,data:{product_id:t},context:u})}},{key:"getClaimCode",value:function(e){var t=e.iccid,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/device_claims":"/v1/device_claims";return this.post({uri:i,auth:a,headers:u,data:{iccid:t},context:n})}},{key:"validatePromoCode",value:function(e){var t=e.promoCode,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/promo_code/"+t,auth:r,headers:a,context:u})}},{key:"changeProduct",value:function(e){var t=e.deviceId,r=e.productId,a=e.auth,u=e.headers,n=e.context;return this.put({uri:"/v1/devices/"+t,auth:a,headers:u,data:{product_id:r},context:n})}},{key:"getVariable",value:function(e){var t=e.deviceId,r=e.name,a=e.product,u=e.auth,n=e.headers,i=e.context,s=a?"/v1/products/"+a+"/devices/"+t+"/"+r:"/v1/devices/"+t+"/"+r;return this.get({uri:s,auth:u,headers:n,context:i})}},{key:"flashDevice",value:function(e){var t=e.deviceId,r=e.product,a=e.files,u=e.targetVersion,n=e.auth,i=e.headers,s=e.context,o=this.deviceUri({deviceId:t,product:r}),c={};return u?c.build_target_version=u:c.latest="true",this.request({uri:o,method:"put",auth:n,headers:i,files:a,form:c,context:s})}},{key:"flashTinker",value:function(e){var t=e.deviceId,r=e.auth,a=e.headers,u=e.context;return console&&console.warning&&console.warning("Particle.flashTinker is deprecated"),this.put({uri:"/v1/devices/"+t,headers:a,data:{app:"tinker"},auth:r,context:u})}},{key:"compileCode",value:function(e){var t=e.files,r=e.platformId,a=e.targetVersion,u=e.auth,n=e.headers,i=e.context,s={platform_id:r};return a?s.build_target_version=a:s.latest="true",this.request({uri:"/v1/binaries",method:"post",auth:u,headers:n,files:t,form:s,context:i})}},{key:"downloadFirmwareBinary",value:function(e){var t=e.binaryId,r=e.auth,a=e.headers,u=e.context,n=this.request({uri:"/v1/binaries/"+t,method:"get",auth:r,headers:a,context:u,raw:!0});return this._provideFileData(n)}},{key:"sendPublicKey",value:function(e){var t=e.deviceId,r=e.key,a=e.algorithm,u=e.auth,n=e.headers,i=e.context;return this.post({uri:"/v1/provisioning/"+t,auth:u,headers:n,data:{deviceID:t,publicKey:"string"==typeof r?r:r.toString(),filename:"particle-api",order:"manual_"+Date.now(),algorithm:a||"rsa"},context:i})}},{key:"callFunction",value:function(e){var t=e.deviceId,r=e.name,a=e.argument,u=e.product,n=e.auth,i=e.headers,s=e.context,o=u?"/v1/products/"+u+"/devices/"+t+"/"+r:"/v1/devices/"+t+"/"+r;return this.post({uri:o,auth:n,headers:i,data:{args:a},context:s})}},{key:"getEventStream",value:function(e){var t=e.deviceId,r=e.name,a=e.org,u=e.product,n=e.auth,i="/v1/";return a&&(i+="orgs/"+a+"/"),u&&(i+="products/"+u+"/"),t&&(i+="devices/","mine"!==t.toLowerCase()&&(i+=t+"/")),i+="events",r&&(i+="/"+encodeURIComponent(r)),new _EventStream2.default(""+this.baseUrl+i,n).connect()}},{key:"publishEvent",value:function(e){var t=e.name,r=e.data,a=e.isPrivate,u=e.product,n=e.auth,i=e.headers,s=e.context,o=u?"/v1/products/"+u+"/events":"/v1/devices/events",c={name:t,data:r,private:a};return this.post({uri:o,auth:n,headers:i,data:c,context:s})}},{key:"createWebhook",value:function(e){var t=e.event,r=e.url,a=e.device,u=e.rejectUnauthorized,n=e.noDefaults,i=e.hook,s=e.product,o=e.auth,c=e.headers,d=e.context,h=s?"/v1/products/"+s+"/webhooks":"/v1/webhooks",v={event:t,url:r,deviceId:a,rejectUnauthorized:u,noDefaults:n};return i&&(v.requestType=i.method,v.auth=i.auth,v.headers=i.headers,v.query=i.query,v.json=i.json,v.form=i.form,v.body=i.body,v.responseTemplate=i.responseTemplate,v.responseTopic=i.responseEvent,v.errorResponseTopic=i.errorResponseEvent),v.requestType||(v.requestType="POST"),this.post({uri:h,auth:o,headers:c,data:v,context:d})}},{key:"deleteWebhook",value:function(e){var t=e.hookId,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/webhooks/"+t:"/v1/webhooks/"+t;return this.delete({uri:i,auth:a,headers:u,context:n})}},{key:"listWebhooks",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context,n=t?"/v1/products/"+t+"/webhooks":"/v1/webhooks";return this.get({uri:n,auth:r,headers:a,context:u})}},{key:"createIntegration",value:function(e){var t=e.event,r=e.settings,a=e.deviceId,u=e.product,n=e.auth,i=e.headers,s=e.context,o=u?"/v1/products/"+u+"/integrations":"/v1/integrations",c=(0,_assign2.default)({event:t,deviceid:a},r);return this.post({uri:o,data:c,auth:n,headers:i,context:s})}},{key:"editIntegration",value:function(e){var t=e.integrationId,r=e.event,a=e.settings,u=e.deviceId,n=e.product,i=e.auth,s=e.headers,o=e.context,c=n?"/v1/products/"+n+"/integrations/"+t:"/v1/integrations/"+t,d=(0,_assign2.default)({event:r,deviceid:u},a);return this.put({uri:c,auth:i,headers:s,data:d,context:o})}},{key:"deleteIntegration",value:function(e){var t=e.integrationId,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/integrations/"+t:"/v1/integrations/"+t;return this.delete({uri:i,auth:a,headers:u,context:n})}},{key:"listIntegrations",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context,n=t?"/v1/products/"+t+"/integrations":"/v1/integrations";return this.get({uri:n,auth:r,headers:a,context:u})}},{key:"getUserInfo",value:function(e){var t=e.auth,r=e.headers,a=e.context;return this.get({uri:"/v1/user",auth:t,headers:r,context:a})}},{key:"setUserInfo",value:function(e){var t=e.accountInfo,r=e.auth,a=e.headers,u=e.context,n={account_info:t};return this.put({uri:"/v1/user",auth:r,headers:a,data:n,context:u})}},{key:"changeUsername",value:function(e){var t=e.currentPassword,r=e.username,a=e.invalidateTokens,u=void 0!==a&&a,n=e.auth,i=e.headers,s=e.context,o={username:r,current_password:t};return u&&(o.invalidate_tokens=!0),this.put({uri:"/v1/user",auth:n,headers:i,data:o,context:s})}},{key:"changeUserPassword",value:function(e){var t=e.currentPassword,r=e.password,a=e.invalidateTokens,u=void 0!==a&&a,n=e.auth,i=e.headers,s=e.context,o={password:r,current_password:t};return u&&(o.invalidate_tokens=!0),this.put({uri:"/v1/user",auth:n,headers:i,data:o,context:s})}},{key:"listSIMs",value:function(e){var t=e.iccid,r=e.deviceId,a=e.deviceName,u=e.page,n=e.perPage,i=e.product,s=e.auth,o=e.headers,c=e.context,d=i?"/v1/products/"+i+"/sims":"/v1/sims",h=i?{iccid:t,deviceId:r,deviceName:a,page:u,per_page:n}:void 0;return this.get({uri:d,auth:s,headers:o,query:h,context:c})}},{key:"getSIMDataUsage",value:function(e){var t=e.iccid,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/sims/"+t+"/data_usage":"/v1/sims/"+t+"/data_usage";return this.get({uri:i,auth:a,headers:u,context:n})}},{key:"getFleetDataUsage",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/products/"+t+"/sims/data_usage",auth:r,headers:a,context:u})}},{key:"checkSIM",value:function(e){var t=e.iccid,r=e.auth,a=e.headers,u=e.context;return this.head({uri:"/v1/sims/"+t,auth:r,headers:a,context:u})}},{key:"activateSIM",value:function(e){var t=e.iccid,r=e.iccids,a=e.country,u=e.promoCode,n=e.product,i=e.auth,s=e.headers,o=e.context;r=r||[t];var c=n?"/v1/products/"+n+"/sims":"/v1/sims/"+t,d=n?{sims:r,country:a}:{country:a,promoCode:u,action:"activate"},h=n?"post":"put";return this.request({uri:c,method:h,headers:s,data:d,auth:i,context:o})}},{key:"deactivateSIM",value:function(e){var t=e.iccid,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/sims/"+t:"/v1/sims/"+t,s={action:"deactivate"};return this.put({uri:i,auth:a,headers:u,data:s,context:n})}},{key:"reactivateSIM",value:function(e){var t=e.iccid,r=e.mbLimit,a=e.product,u=e.auth,n=e.headers,i=e.context,s=a?"/v1/products/"+a+"/sims/"+t:"/v1/sims/"+t,o={mb_limit:r,action:"reactivate"};return this.put({uri:s,auth:u,headers:n,data:o,context:i})}},{key:"updateSIM",value:function(e){var t=e.iccid,r=e.mbLimit,a=e.product,u=e.auth,n=e.headers,i=e.context,s=a?"/v1/products/"+a+"/sims/"+t:"/v1/sims/"+t,o={mb_limit:r};return this.put({uri:s,auth:u,headers:n,data:o,context:i})}},{key:"removeSIM",value:function(e){var t=e.iccid,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/sims/"+t:"/v1/sims/"+t;return this.delete({uri:i,auth:a,headers:u,context:n})}},{key:"listBuildTargets",value:function(e){var t=e.onlyFeatured,r=e.auth,a=e.headers,u=e.context,n=t?{featured:!!t}:void 0;return this.get({uri:"/v1/build_targets",auth:r,headers:a,query:n,context:u})}},{key:"listLibraries",value:function(e){var t=e.page,r=e.limit,a=e.filter,u=e.sort,n=e.architectures,i=e.category,s=e.scope,o=e.excludeScopes,c=e.auth,d=e.headers,h=e.context;return this.get({uri:"/v1/libraries",auth:c,headers:d,query:{page:t,filter:a,limit:r,sort:u,architectures:this._asList(n),category:i,scope:s,excludeScopes:this._asList(o)},context:h})}},{key:"_asList",value:function(e){return Array.isArray(e)?e.join(","):e}},{key:"getLibrary",value:function(e){var t=e.name,r=e.version,a=e.auth,u=e.headers,n=e.context;return this.get({uri:"/v1/libraries/"+t,auth:a,headers:u,query:{version:r},context:n})}},{key:"getLibraryVersions",value:function(e){var t=e.name,r=e.page,a=e.limit,u=e.auth,n=e.headers,i=e.context;return this.get({uri:"/v1/libraries/"+t+"/versions",auth:u,headers:n,query:{page:r,limit:a},context:i})}},{key:"contributeLibrary",value:function(e){var t=e.archive,r=e.auth,a=e.headers,u=e.context,n={"archive.tar.gz":t};return this.request({uri:"/v1/libraries",method:"post",auth:r,headers:a,files:n,context:u})}},{key:"publishLibrary",value:function(e){var t=e.name,r=e.auth,a=e.headers,u=e.context;return this.request({uri:"/v1/libraries/"+t,method:"patch",auth:r,headers:a,data:{visibility:"public"},context:u})}},{key:"deleteLibrary",value:function(e){var t=e.name,r=e.force,a=e.auth,u=e.headers,n=e.context;return this.delete({uri:"/v1/libraries/"+t,auth:a,headers:u,data:{force:r},context:n})}},{key:"downloadFile",value:function(e){var t=e.uri,r=e.headers,a=e.context,u=this.request({uri:t,method:"get",headers:r,context:a,raw:!0});return this._provideFileData(u)}},{key:"listOAuthClients",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context,n=t?"/v1/products/"+t+"/clients":"/v1/clients";return this.get({uri:n,auth:r,headers:a,context:u})}},{key:"createOAuthClient",value:function(e){var t=e.name,r=e.type,a=e.redirect_uri,u=e.scope,n=e.product,i=e.auth,s=e.headers,o=e.context,c=n?"/v1/products/"+n+"/clients":"/v1/clients",d={name:t,type:r,redirect_uri:a,scope:u};return this.post({uri:c,auth:i,headers:s,data:d,context:o})}},{key:"updateOAuthClient",value:function(e){var t=e.clientId,r=e.name,a=e.scope,u=e.product,n=e.auth,i=e.headers,s=e.context,o=u?"/v1/products/"+u+"/clients/"+t:"/v1/clients/"+t,c={name:r,scope:a};return this.put({uri:o,data:c,auth:n,headers:i,context:s})}},{key:"deleteOAuthClient",value:function(e){var t=e.clientId,r=e.product,a=e.auth,u=e.headers,n=e.context,i=r?"/v1/products/"+r+"/clients/"+t:"/v1/clients/"+t;return this.delete({uri:i,auth:a,headers:u,context:n})}},{key:"listProducts",value:function(e){var t=e.auth,r=e.headers,a=e.context;return this.get({uri:"/v1/products",auth:t,headers:r,context:a})}},{key:"getProduct",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/products/"+t,auth:r,headers:a,context:u})}},{key:"listProductFirmware",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/products/"+t+"/firmware",auth:r,headers:a,context:u})}},{key:"uploadProductFirmware",value:function(e){var t=e.file,r=e.version,a=e.title,u=e.description,n=e.product,i=e.auth,s=e.headers,o=e.context;return this.request({uri:"/v1/products/"+n+"/firmware",method:"post",auth:i,headers:s,form:{version:r,title:a,description:u},files:{"firmware.bin":t},context:o})}},{key:"getProductFirmware",value:function(e){var t=e.version,r=e.product,a=e.auth,u=e.headers,n=e.context;return this.get({uri:"/v1/products/"+r+"/firmware/"+t,auth:a,headers:u,context:n})}},{key:"updateProductFirmware",value:function(e){var t=e.version,r=e.title,a=e.description,u=e.product,n=e.auth,i=e.headers,s=e.context,o="/v1/products/"+u+"/firmware/"+t;return this.put({uri:o,auth:n,headers:i,data:{title:r,description:a},context:s})}},{key:"downloadProductFirmware",value:function(e){var t=e.version,r=e.product,a=e.auth,u=e.headers,n=e.context,i=this.request({uri:"/v1/products/"+r+"/firmware/"+t+"/binary",method:"get",auth:a,headers:u,context:n,raw:!0});return this._provideFileData(i)}},{key:"_provideFileData",value:function(e){return e=this.agent.isForBrowser()?e.responseType("arraybuffer").then(function(e){return e.body=e.xhr.response,e}):e.buffer(!0).parse(_superagentBinaryParser2.default),e.then(function(e){return e.body})}},{key:"releaseProductFirmware",value:function(e){var t=e.version,r=e.product,a=e.auth,u=e.headers,n=e.context,i="/v1/products/"+r+"/firmware/release";return this.put({uri:i,auth:a,headers:u,data:{version:t},context:n})}},{key:"listTeamMembers",value:function(e){var t=e.product,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/products/"+t+"/team",auth:r,headers:a,context:u})}},{key:"inviteTeamMember",value:function(e){var t=e.username,r=e.product,a=e.auth,u=e.headers,n=e.context;return this.post({uri:"/v1/products/"+r+"/team",auth:a,headers:u,data:{username:t},context:n})}},{key:"removeTeamMember",value:function(e){var t=e.username,r=e.product,a=e.auth,u=e.headers,n=e.context;return this.delete({uri:"/v1/products/"+r+"/team/"+t,auth:a,headers:u,context:n})}},{key:"lookupSerialNumber",value:function(e){var t=e.serialNumber,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/serial_numbers/"+t,auth:r,headers:a,context:u})}},{key:"createMeshNetwork",value:function(e){var t=e.name,r=e.deviceId,a=e.iccid,u=e.auth,n=e.headers,i=e.context;return this.post({uri:"/v1/networks",auth:u,headers:n,data:{name:t,device_id:r,iccid:a},context:i})}},{key:"removeMeshNetwork",value:function(e){var t=e.networkId,r=e.auth,a=e.headers,u=e.context;return this.delete({uri:"/v1/networks/"+t,auth:r,headers:a,context:u})}},{key:"listMeshNetworks",value:function(e){var t=e.page,r=e.perPage,a=e.auth,u=e.headers,n=e.context,i=t?{page:t,per_page:r}:void 0;return this.get({uri:"/v1/networks",auth:a,headers:u,query:i,context:n})}},{key:"getMeshNetwork",value:function(e){var t=e.networkId,r=e.auth,a=e.headers,u=e.context;return this.get({uri:"/v1/networks/"+t,auth:r,headers:a,context:u})}},{key:"updateMeshNetwork",value:function(e){var t=e.networkId,r=e.action,a=e.deviceId,u=e.auth,n=e.headers,i=e.context;return this.put({uri:"/v1/networks/"+t,auth:u,headers:n,data:{action:r,device_id:a},context:i})}},{key:"addMeshNetworkDevice",value:function(e){var t=e.networkId,r=e.deviceId,a=e.auth,u=e.headers,n=e.context;return this.updateMeshNetwork({action:"add-device",networkId:t,deviceId:r,auth:a,headers:u,context:n})}},{key:"removeMeshNetworkDevice",value:function(e){var t=e.networkId,r=e.deviceId,a=e.auth,u=e.headers,n=e.context;return t?this.updateMeshNetwork({action:"remove-device",networkId:t,deviceId:r,auth:a,headers:u,context:n}):this.delete({uri:"/v1/devices/"+r+"/network",auth:a,headers:u,context:n})}},{key:"listMeshNetworkDevices",value:function(e){var t=e.networkId,r=e.role,a=e.page,u=e.perPage,n=e.auth,i=e.headers,s=e.context,o=r||a?{role:r,page:a,per_page:u}:void 0;return this.get({uri:"/v1/networks/"+t+"/devices",auth:n,headers:i,query:o,context:s})}},{key:"getProductConfiguration",value:function(e){var t=e.auth,r=e.product,a=e.headers,u=e.context;return this.get({uri:"/v1/products/"+r+"/config",auth:t,headers:a,context:u})}},{key:"getProductConfigurationSchema",value:function(e){var t=e.auth,r=e.product,a=e.headers,u=void 0===a?{}:a,n=e.context;return u.accept="application/schema+json",this.get({uri:"/v1/products/"+r+"/config",auth:t,headers:u,context:n})}},{key:"getProductDeviceConfiguration",value:function(e){var t=e.auth,r=e.product,a=e.deviceId,u=e.headers,n=e.context;return this.get({uri:"/v1/products/"+r+"/config/"+a,auth:t,headers:u,context:n})}},{key:"getProductDeviceConfigurationSchema",value:function(e){var t=e.auth,r=e.product,a=e.deviceId,u=e.headers,n=e.context;return u.accept="application/schema+json",this.get({uri:"/v1/products/"+r+"/config/"+a,auth:t,headers:u,context:n})}},{key:"setProductConfiguration",value:function(e){var t=e.auth,r=e.product,a=e.config,u=e.headers,n=e.context;return this.put({uri:"/v1/products/"+r+"/config",auth:t,data:a,headers:u,context:n})}},{key:"setProductDeviceConfiguration",value:function(e){var t=e.auth,r=e.product,a=e.deviceId,u=e.config,n=e.headers,i=e.context;return this.put({uri:"/v1/products/"+r+"/config/"+a,data:u,auth:t,headers:n,context:i})}},{key:"getProductLocations",value:function(e){var t=e.auth,r=e.product,a=e.dateRange,u=e.rectBl,n=e.rectTr,i=e.deviceId,s=e.deviceName,o=e.groups,c=e.page,d=e.perPage,h=e.headers,v=e.context;return this.get({uri:"/v1/products/"+r+"/locations",query:{date_range:a,rect_bl:u,rect_tr:n,device_id:i,device_name:s,groups:o,page:c,per_page:d},auth:t,headers:h,context:v})}},{key:"getProductDeviceLocations",value:function(e){var t=e.auth,r=e.product,a=e.dateRange,u=e.rectBl,n=e.rectTr,i=e.deviceId,s=e.headers,o=e.context;return this.get({uri:"/v1/products/"+r+"/locations/"+i,query:{date_range:a,rect_bl:u,rect_tr:n},auth:t,headers:s,context:o})}},{key:"deviceUri",value:function(e){var t=e.deviceId,r=e.product;return r?"/v1/products/"+r+"/devices/"+t:"/v1/devices/"+t}},{key:"get",value:function(e){var t=e.uri,r=e.auth,a=e.headers,u=e.query,n=e.context;return n=this._buildContext(n),this.agent.get({uri:t,auth:r,headers:a,query:u,context:n})}},{key:"head",value:function(e){var t=e.uri,r=e.auth,a=e.headers,u=e.query,n=e.context;return n=this._buildContext(n),this.agent.head({uri:t,auth:r,headers:a,query:u,context:n})}},{key:"post",value:function(e){var t=e.uri,r=e.auth,a=e.headers,u=e.data,n=e.context;return n=this._buildContext(n),this.agent.post({uri:t,auth:r,headers:a,data:u,context:n})}},{key:"put",value:function(e){var t=e.uri,r=e.auth,a=e.headers,u=e.data,n=e.context;return n=this._buildContext(n),this.agent.put({uri:t,auth:r,headers:a,data:u,context:n})}},{key:"delete",value:function(e){var t=e.uri,r=e.auth,a=e.headers,u=e.data,n=e.context;return n=this._buildContext(n),this.agent.delete({uri:t,auth:r,headers:a,data:u,context:n})}},{key:"request",value:function(e){return e.context=this._buildContext(e.context),this.agent.request(e)}},{key:"client",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new _Client2.default((0,_assign2.default)({api:this},e))}},{key:"setBaseUrl",value:function(e){this.agent.setBaseUrl(e)}}]),e}();Particle.prototype.removeAccessToken=Particle.prototype.deleteAccessToken,exports.default=Particle,module.exports=exports.default;
|
|
13
13
|
},{"./Agent":1,"./Client":2,"./Defaults":3,"./EventStream":4,"./superagent-binary-parser":7,"babel-runtime/core-js/object/assign":10,"babel-runtime/helpers/classCallCheck":20,"babel-runtime/helpers/createClass":21}],7:[function(require,module,exports){
|
|
14
14
|
(function (Buffer){
|
|
15
15
|
"use strict";function binaryParser(e,r){var t=[];e.on("data",function(e){return t.push(e)}),e.on("end",function(){return r(null,Buffer.concat(t))})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=binaryParser,module.exports=exports.default;
|