Socket
Socket
Sign inDemoInstall

qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

2

lib/index.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib"),utils_1=require("qcloud-iotexplorer-appdev-sdk/lib/utils"),SyncGatewaySubDevicePlugin=function(){function e(){}return e.install=function(e){var t=new SyncGatewaySubDeviceImplements(this);e.plugins.syncGatewaySubDevicePlugin={sync:t.syncGatewaySubDevice.bind(t),syncByList:t.syncGatewaySubDeviceByList.bind(t)}},e}();exports.default=SyncGatewaySubDevicePlugin;var SyncGatewaySubDeviceImplements=function(){function e(e){this.sdk=e}return e.prototype.syncGatewaySubDeviceByList=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,i,s,a,r=this;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return t={},i={},e.forEach((function(e){var s=e.ProductId,a=e.DeviceId,r=e.DeviceName,n=e.DeviceType,c=e.GatewayDeviceId;a||(a=s+"/"+r),2===n&&c&&(i[c]||(i[c]=[]),i[c].push(e)),1===n&&(t[a]=e)})),[4,Promise.all(Object.keys(t).map((function(e){return tslib_1.__awaiter(r,void 0,void 0,(function(){var s;return tslib_1.__generator(this,(function(a){switch(a.label){case 0:return[4,this.syncGatewaySubDevice(t[e],{subDeviceAlreadyInFamilyList:i[e]})];case 1:return s=a.sent(),[2,tslib_1.__assign(tslib_1.__assign({},s),{gatewayDeviceInfo:t[e]})]}}))}))})))];case 1:return s=n.sent(),a=!1,s.forEach((function(t){var i=t.gatewayDeviceInfo,s=t.diffResult;s.add.forEach((function(t){a=!0,t.success?e.push(tslib_1.__assign(tslib_1.__assign({},t.deviceInfo),{isShareDevice:i.isShareDevice})):utils_1.logger.debug("该子设备添加失败",t)})),s.remove.forEach((function(t){a=!0;var i=e.findIndex((function(e){return e.DeviceId===t.deviceInfo.DeviceId}));e.splice(i,1),utils_1.logger.debug("删除子设备",t.deviceInfo,i,e)}))})),a&&this.sdk.reporter.info("sync-gateway-subdevice-result",{data:s}),[2,{deviceList:e,syncResults:s}]}}))}))},e.prototype.syncGatewaySubDevice=function(e,t){var i=(void 0===t?{}:t).subDeviceAlreadyInFamilyList;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,s,a,r,n,c,u,o,v,l,d,f=this;return tslib_1.__generator(this,(function(_){switch(_.label){case 0:return a={subDeviceList:[],diffResult:s={add:[],remove:[]}},"string"!=typeof e?[3,2]:[4,this.sdk.requestApi("AppGetDevice",{DeviceId:e})];case 1:e=_.sent(),_.label=2;case 2:return r=e.ProductId,n=e.DeviceName,c=e.FamilyId,1!==e.DeviceType||"~virtualDev"===e.DeviceName?(utils_1.logger.debug("无需同步子设备",e),[2,a]):(u=[],t||u.push(utils_1.fetchAllList((function(e){var t=e.offset,i=e.limit;return f._getGatewayBindDeviceList({GatewayProductId:r,GatewayDeviceName:n,Offset:t,Limit:i})})).then((function(e){return t=e}))),i||u.push(utils_1.fetchAllList((function(e){var t=e.offset,s=e.limit;return f._getFamilySubDeviceList({GatewayProductId:r,GatewayDeviceName:n,Offset:t,Limit:s}).then((function(e){return i=e}))}))),[4,Promise.all(u)]);case 3:return _.sent(),o={},v={},t.forEach((function(e){return o[e.DeviceId]=e})),i.forEach((function(e){return v[e.DeviceId]=e})),t.forEach((function(e){v[e.DeviceId]?a.subDeviceList.push(tslib_1.__assign(tslib_1.__assign({},e),v[e.DeviceId])):s.add.push({success:!1,deviceInfo:e})})),i.forEach((function(e){o[e.DeviceId]||s.remove.push({success:!1,deviceInfo:e})})),utils_1.logger.debug("syncGatewaySubDeviceList",{result:a,diffResult:s,subDeviceList:t,subDeviceAlreadyInFamilyList:i}),l=s.add.map((function(e){return tslib_1.__awaiter(f,void 0,void 0,(function(){var t,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this.sdk.requestApi("AppBindSubDeviceInFamily",{ProductId:e.deviceInfo.ProductId,DeviceName:e.deviceInfo.DeviceName,GatewayProductId:r,GatewayDeviceName:n})];case 1:return t=s.sent().Data.AppDeviceInfo,a.subDeviceList.push(tslib_1.__assign(tslib_1.__assign({},e.deviceInfo),t)),e.success=!0,[3,3];case 2:return i=s.sent(),utils_1.logger.error("Sync subdevice to family fail",i),e.success=!1,e.error=i,[3,3];case 3:return[2]}}))}))})),d=s.remove.map((function(e){return tslib_1.__awaiter(f,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),c?[4,this.sdk.requestApi("AppDeleteDeviceInFamily",{FamilyId:c,DeviceId:e.deviceInfo.DeviceId})]:[3,2];case 1:i.sent(),i.label=2;case 2:return e.success=!0,[3,4];case 3:return t=i.sent(),utils_1.logger.warn("Remove extra device from family fail",t),e.success=!1,e.error=t,[3,4];case 4:return[2]}}))}))})),[4,Promise.all(tslib_1.__spread(l,d))];case 4:return _.sent(),[2,a]}}))}))},e.prototype._getGatewayBindDeviceList=function(e){var t=e.GatewayProductId,i=e.GatewayDeviceName,s=e.ProductId,a=void 0===s?"":s,r=e.Limit,n=e.Offset;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,s,c;return tslib_1.__generator(this,(function(u){switch(u.label){case 0:return[4,this.sdk.requestApi("AppGetGatewayBindDeviceList",{GatewayProductId:t,GatewayDeviceName:i,ProductId:a,Limit:r,Offset:n})];case 1:return e=u.sent(),s=e.DeviceList,c=e.Total,[2,{list:s,total:c}]}}))}))},e.prototype._getFamilySubDeviceList=function(e){var t=e.GatewayProductId,i=e.GatewayDeviceName,s=e.Offset,a=void 0===s?0:s,r=e.Limit,n=void 0===r?100:r;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,s,r;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return[4,this.sdk.requestApi("AppGetFamilySubDeviceList",{GatewayProductId:t,GatewayDeviceName:i,Offset:a,Limit:n})];case 1:return e=c.sent(),s=e.DeviceList,r=e.Total,[2,{list:s,total:r}]}}))}))},e}();
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib"),utils_1=require("qcloud-iotexplorer-appdev-sdk/lib/utils"),SyncGatewaySubDevicePlugin=function(){function e(){}return e.install=function(e){var t=new SyncGatewaySubDeviceImplements(e);e.plugins.syncGatewaySubDevicePlugin={sync:t.syncGatewaySubDevice.bind(t),syncByList:t.syncGatewaySubDeviceByList.bind(t)}},e}();exports.default=SyncGatewaySubDevicePlugin;var SyncGatewaySubDeviceImplements=function(){function e(e){this.sdk=e}return e.prototype.syncGatewaySubDeviceByList=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,i,s,r,a=this;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return t={},i={},e.forEach((function(e){var s=e.ProductId,r=e.DeviceId,a=e.DeviceName,n=e.DeviceType,c=e.GatewayDeviceId;r||(r=s+"/"+a),2===n&&c&&(i[c]||(i[c]=[]),i[c].push(e)),1===n&&(t[r]=e)})),[4,Promise.all(Object.keys(t).map((function(e){return tslib_1.__awaiter(a,void 0,void 0,(function(){var s;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:return[4,this.syncGatewaySubDevice(t[e],{subDeviceAlreadyInFamilyList:i[e]})];case 1:return s=r.sent(),[2,tslib_1.__assign(tslib_1.__assign({},s),{gatewayDeviceInfo:t[e]})]}}))}))})))];case 1:return s=n.sent(),r=!1,s.forEach((function(t){var i=t.gatewayDeviceInfo,s=t.diffResult;s.add.forEach((function(t){r=!0,t.success?e.push(tslib_1.__assign(tslib_1.__assign({},t.deviceInfo),{isShareDevice:i.isShareDevice})):utils_1.logger.debug("该子设备添加失败",t)})),s.remove.forEach((function(t){r=!0;var i=e.findIndex((function(e){return e.DeviceId===t.deviceInfo.DeviceId}));e.splice(i,1),utils_1.logger.debug("删除子设备",t.deviceInfo,i,e)}))})),r&&this.sdk.reporter.info("sync-gateway-subdevice-result",{data:s}),[2,{deviceList:e,syncResults:s}]}}))}))},e.prototype.syncGatewaySubDevice=function(e,t){var i=(void 0===t?{}:t).subDeviceAlreadyInFamilyList;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,s,r,a,n,c,u,o,l,v,d,f=this;return tslib_1.__generator(this,(function(_){switch(_.label){case 0:return r={subDeviceList:[],diffResult:s={add:[],remove:[]}},"string"!=typeof e?[3,2]:[4,this.sdk.requestApi("AppGetDevice",{DeviceId:e})];case 1:e=_.sent(),_.label=2;case 2:return a=e.ProductId,n=e.DeviceName,c=e.FamilyId,1!==e.DeviceType||"~virtualDev"===e.DeviceName?(utils_1.logger.debug("无需同步子设备",e),[2,r]):(u=[],t||u.push(utils_1.fetchAllList((function(e){var t=e.offset,i=e.limit;return f._getGatewayBindDeviceList({GatewayProductId:a,GatewayDeviceName:n,Offset:t,Limit:i})})).then((function(e){return t=e}))),i||u.push(utils_1.fetchAllList((function(e){var t=e.offset,i=e.limit;return f._getFamilySubDeviceList({GatewayProductId:a,GatewayDeviceName:n,Offset:t,Limit:i})})).then((function(e){return i=e}))),[4,Promise.all(u)]);case 3:return _.sent(),o={},l={},t.forEach((function(e){return o[e.DeviceId]=e})),i.forEach((function(e){return l[e.DeviceId]=e})),t.forEach((function(e){l[e.DeviceId]?r.subDeviceList.push(tslib_1.__assign(tslib_1.__assign({},e),l[e.DeviceId])):s.add.push({success:!1,deviceInfo:e})})),i.forEach((function(e){o[e.DeviceId]||s.remove.push({success:!1,deviceInfo:e})})),utils_1.logger.debug("syncGatewaySubDeviceList",{result:r,diffResult:s,subDeviceList:t,subDeviceAlreadyInFamilyList:i}),v=s.add.map((function(e){return tslib_1.__awaiter(f,void 0,void 0,(function(){var t,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this.sdk.requestApi("AppBindSubDeviceInFamily",{ProductId:e.deviceInfo.ProductId,DeviceName:e.deviceInfo.DeviceName,GatewayProductId:a,GatewayDeviceName:n})];case 1:return t=s.sent().Data.AppDeviceInfo,r.subDeviceList.push(tslib_1.__assign(tslib_1.__assign({},e.deviceInfo),t)),e.success=!0,[3,3];case 2:return i=s.sent(),utils_1.logger.error("Sync subdevice to family fail",i),e.success=!1,e.error=i,[3,3];case 3:return[2]}}))}))})),d=s.remove.map((function(e){return tslib_1.__awaiter(f,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),c?[4,this.sdk.requestApi("AppDeleteDeviceInFamily",{FamilyId:c,DeviceId:e.deviceInfo.DeviceId})]:[3,2];case 1:i.sent(),i.label=2;case 2:return e.success=!0,[3,4];case 3:return t=i.sent(),utils_1.logger.warn("Remove extra device from family fail",t),e.success=!1,e.error=t,[3,4];case 4:return[2]}}))}))})),[4,Promise.all(tslib_1.__spread(v,d))];case 4:return _.sent(),utils_1.logger.debug("sync result for "+(e||{}).DeviceId,r),[2,r]}}))}))},e.prototype._getGatewayBindDeviceList=function(e){var t=e.GatewayProductId,i=e.GatewayDeviceName,s=e.ProductId,r=void 0===s?"":s,a=e.Limit,n=e.Offset;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,s,c;return tslib_1.__generator(this,(function(u){switch(u.label){case 0:return[4,this.sdk.requestApi("AppGetGatewayBindDeviceList",{GatewayProductId:t,GatewayDeviceName:i,ProductId:r,Limit:a,Offset:n})];case 1:return e=u.sent(),s=e.DeviceList,c=e.Total,[2,{list:s,total:c}]}}))}))},e.prototype._getFamilySubDeviceList=function(e){var t=e.GatewayProductId,i=e.GatewayDeviceName,s=e.Offset,r=void 0===s?0:s,a=e.Limit,n=void 0===a?100:a;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,s,a;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return[4,this.sdk.requestApi("AppGetFamilySubDeviceList",{GatewayProductId:t,GatewayDeviceName:i,Offset:r,Limit:n})];case 1:return e=c.sent(),s=e.DeviceList,a=e.Total,[2,{list:s,total:a}]}}))}))},e}();
//# sourceMappingURL=index.js.map
{
"name": "qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice",
"version": "1.0.2",
"version": "1.0.3",
"description": "",

@@ -8,3 +8,4 @@ "main": "lib/index.js",

"build": "rm -rf lib && npx tsc -p tsconfig.json -t es5 --outDir lib && node ../../bin/minify.js -p plugin-sync-gateway-subdevice -t lib",
"typing": "cd @types && tsc"
"typing": "cd @types && tsc",
"dev": "rm -rf lib && npx tsc -p tsconfig.json -t es5 --outDir lib --watch"
},

@@ -20,3 +21,3 @@ "author": "xiaoyuze88@gmail.com",

},
"gitHead": "cf347ee5c5f666392dd5bee533dbbe19a092cafe"
"gitHead": "7379f5c97c66fa2b145a565acb7ea301f682b89f"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc