particle-api-js 9.3.0 → 9.4.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # changelog
2
2
 
3
+ ## 9.4.0 - 14 June 2022
4
+
5
+ * Adds `.setDefaultAuth(auth)` so token authenticated methods don't need to pass their own auth token.
6
+ * Adds support for `auth` option in Particle constructor, calls `.setDefaultAuth()` if provided
7
+ * Fixes bug where `.setBaseUrl(baseUrl)` was not honored for `.getEventStream()` method (sc-105035)
8
+
3
9
  ## 9.3.0 - 8 June 2022
4
10
  * Adds `.setBaseUrl(baseUrl)` to override backend api endpoint
5
11
 
@@ -3,13 +3,13 @@
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){
6
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default={baseUrl:"https://api.particle.io",clientSecret:"particle-api",clientId:"particle-api",tokenDuration:7776e3},module.exports=exports.default;
6
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default={baseUrl:"https://api.particle.io",clientSecret:"particle-api",clientId:"particle-api",tokenDuration:7776e3,auth:void 0},module.exports=exports.default;
7
7
  },{}],4:[function(require,module,exports){
8
8
  "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),_getPrototypeOf=require("babel-runtime/core-js/object/get-prototype-of"),_getPrototypeOf2=_interopRequireDefault(_getPrototypeOf),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_http=require("http"),_http2=_interopRequireDefault(_http),_https=require("https"),_https2=_interopRequireDefault(_https),_url=require("url"),_url2=_interopRequireDefault(_url),_events=require("events"),EventStream=function(e){function t(e,r){(0,_classCallCheck3.default)(this,t);var i=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||(0,_getPrototypeOf2.default)(t)).call(this));return i.uri=e,i.token=r,i.reconnectInterval=2e3,i.timeout=13e3,i.data="",i.buf="",i.parse=i.parse.bind(i),i.end=i.end.bind(i),i.idleTimeoutExpired=i.idleTimeoutExpired.bind(i),i}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"connect",value:function(){var e=this;return new _promise2.default(function(t,r){var i=_url2.default.parse(e.uri),n=i.hostname,o=i.protocol,s=i.port,u=i.path;e.origin=o+"//"+n+(s?":"+s:"");var a="https:"===o,l=a?_https2.default:_http2.default,c=l.request({hostname:n,protocol:o,path:u+"?access_token="+e.token,method:"get",port:parseInt(s,10)||(a?443:80),mode:"prefer-streaming"});e.req=c;var f=!1,h=setTimeout(function(){e.req&&e.req.abort(),r({error:new Error("Timeout"),errorDescription:"Timeout connecting to "+e.uri})},e.timeout);c.on("error",function(t){clearTimeout(h),f?e.end():r({error:t,errorDescription:"Network error from "+e.uri})}),c.on("response",function(i){clearTimeout(h);var n=i.statusCode;if(200!==n){var o="";return i.on("data",function(e){return o+=e}),void i.on("end",function(){try{o=JSON.parse(o)}catch(e){}finally{var t="HTTP error "+n+" from "+e.uri;o&&o.error_description&&(t+=" - "+o.error_description),r({statusCode:n,errorDescription:t,body:o}),e.req=void 0}})}e.data="",e.buf="",f=!0,i.on("data",e.parse),i.once("end",e.end),e.startIdleTimeout(),t(e)}),c.end()})}},{key:"abort",value:function(){this.req&&(this.req.abort(),this.req=void 0),this.removeAllListeners()}},{key:"emitSafe",value:function(e,t){try{this.emit(e,t)}catch(t){"error"!==e&&this.emitSafe("error",t)}}},{key:"end",value:function(){this.stopIdleTimeout(),this.req&&(this.req=void 0,this.emitSafe("disconnect"),this.reconnect())}},{key:"reconnect",value:function(){var e=this;setTimeout(function(){if(e.isOffline())return void e.reconnect();e.emitSafe("reconnect"),e.connect().then(function(){e.emitSafe("reconnect-success")}).catch(function(t){e.emitSafe("reconnect-error",t),e.reconnect()})},this.reconnectInterval)}},{key:"isOffline",value:function(){return"undefined"!=typeof navigator&&!navigator.hasOwnProperty("onLine")&&!navigator.onLine}},{key:"startIdleTimeout",value:function(){this.stopIdleTimeout(),this.idleTimeout=setTimeout(this.idleTimeoutExpired,this.timeout)}},{key:"stopIdleTimeout",value:function(){this.idleTimeout&&(clearTimeout(this.idleTimeout),this.idleTimeout=null)}},{key:"idleTimeoutExpired",value:function(){this.req&&(this.req.abort(),this.end())}},{key:"parse",value:function(e){this.startIdleTimeout(),this.buf+=e;for(var t=0,r=this.buf.length,i=!1;t<r;){i&&("\n"===this.buf[t]&&++t,i=!1);for(var n=-1,o=-1,s=t;n<0&&s<r;++s){var u=this.buf[s];":"===u?o<0&&(o=s-t):"\r"===u?(i=!0,n=s-t):"\n"===u&&(n=s-t)}if(n<0)break;this.parseEventStreamLine(t,o,n),t+=n+1}t===r?this.buf="":t>0&&(this.buf=this.buf.slice(t))}},{key:"parseEventStreamLine",value:function(e,t,r){if(0===r)try{if(this.data.length>0&&this.event){var i=JSON.parse(this.data);i.name=this.eventName||"",this.emitSafe("event",i)}}catch(e){}finally{this.data="",this.eventName=void 0,this.event=!1}else if(t>0){var n=this.buf.slice(e,e+t),o=0;o=" "!==this.buf[e+t+1]?t+1:t+2,e+=o;var s=r-o,u=this.buf.slice(e,e+s);"data"===n?this.data+=u+"\n":"event"===n&&(this.eventName=u,this.event=!0)}}}]),t}(_events.EventEmitter);exports.default=EventStream,module.exports=exports.default;
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))}},{key:"setBaseUrl",value:function(e){this.agent.setBaseUrl(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),t.auth&&this.setDefaultAuth(t.auth),(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("unknown 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)),n=this._getActiveAuthToken(n),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:"setDefaultAuth",value:function(e){if("string"!=typeof e||0===e.length)throw new Error("Must pass a non-empty string");this._defaultAuth=e}},{key:"_getActiveAuthToken",value:function(e){return e||this._defaultAuth}},{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),r=this._getActiveAuthToken(r),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),r=this._getActiveAuthToken(r),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),r=this._getActiveAuthToken(r),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),r=this._getActiveAuthToken(r),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),r=this._getActiveAuthToken(r),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),e.auth=this._getActiveAuthToken(e.auth),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.baseUrl=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;