Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cloudvision-connector

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cloudvision-connector - npm Package Compare versions

Comparing version 4.5.1 to 4.5.2

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [4.5.2](https://github.com/aristanetworks/cloudvision/compare/v4.5.1...v4.5.2) (2020-07-28)
### Bug Fixes
* **cloudvision-connector:** add service request to Conenctor ([#139](https://github.com/aristanetworks/cloudvision/issues/139)) ([972440f](https://github.com/aristanetworks/cloudvision/commit/972440fb85fe1bf0f0a0df9f89a74e26f54be2bb))
## [4.5.1](https://github.com/aristanetworks/cloudvision/compare/v4.5.0...v4.5.1) (2020-07-28)

@@ -8,0 +19,0 @@

1

dist/cloudvision-connector.js

@@ -1583,2 +1583,3 @@ (function (global, factory) {

Connector.SEARCH = SEARCH;
Connector.SERVICE_REQUEST = SERVICE_REQUEST;
Connector.SUBSCRIBE = SUBSCRIBE;

@@ -1585,0 +1586,0 @@

2

dist/cloudvision-connector.min.js

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("a-msgpack"),require("base64-js"),require("imurmurhash")):"function"==typeof define&&define.amd?define(["exports","a-msgpack","base64-js","imurmurhash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CloudvisionConnector={},e.msgpack,e["base64-js"],e.MurmurHash3)}(this,(function(e,t,n,s){"use strict";s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s;const i=e=>t.encode(e,{extensionCodec:t.Codec}),r=e=>t.decode(e,{extensionCodec:t.Codec,useJSBI:!0});function o(e){const t=[];for(let s=0;s<e.length;s+=1)t.push(n.fromByteArray(i(e[s])));return t}function a(e){const t={path_elements:[],timestamp:0};t.path_elements=function(e){const t=[];for(let s=0;s<e.length;s+=1)t.push(r(n.toByteArray(e[s])));return t}(e.path_elements||[]);let s="";return e.timestamp.nanos&&(s+=e.timestamp.nanos),s=s.padStart(9,"0"),t.timestamp=parseInt((""+e.timestamp.seconds+s).slice(0,13),10),e.updates&&(t.updates=function(e){const t={};for(let s=0;s<e.length;s+=1){const i=e[s].key,o=e[s].value,a=r(n.toByteArray(i)),c=r(n.toByteArray(o));t[i]={key:a,value:c}}return t}(e.updates)),e.deletes&&(t.deletes=function(e){const t={};for(let s=0;s<e.length;s+=1){const i=e[s];t[i]={key:r(n.toByteArray(i))}}return t}(e.deletes)),e.delete_all&&(t.deletes={}),t}function c(e,t){const n=a(t);e.notifications[JSON.stringify(n.path_elements)]?e.notifications[JSON.stringify(n.path_elements)].push(n):e.notifications[JSON.stringify(n.path_elements)]=[n]}function u(e,t){if(e.timestamp.seconds<t.timestamp.seconds)return-1;if(e.timestamp.seconds>t.timestamp.seconds)return 1;if(e.timestamp.nanos&&t.timestamp.nanos){if(e.timestamp.nanos<t.timestamp.nanos)return-1;if(e.timestamp.nanos>t.timestamp.nanos)return 1}return e.timestamp.nanos?t.timestamp.nanos?0:1:-1}function l(e){const t={timestamp:e.timestamp};return e.path_elements&&e.path_elements.length&&(t.path_elements=o(e.path_elements)),e.updates&&(t.updates=function(e){const t=[];for(let s=0;s<e.length;s+=1){const r=e[s].key,o=e[s].value;t.push({key:n.fromByteArray(i(r)),value:n.fromByteArray(i(o))})}return t}(e.updates)),e.deletes&&(Object.keys(e.deletes).length?t.deletes=function(e){const t=[];for(let s=0;s<e.length;s+=1){const r=e[s];t.push(n.fromByteArray(i(r)))}return t}(e.deletes):t.delete_all=!0),t}class h{static parse(e,t){const n=JSON.parse(e),s=n.result;if(s&&!s.datasets&&s.notifications){const e=function(e,t){if(e.notifications.sort(u),t){const t={dataset:e.dataset,metadata:e.metadata||{},notifications:{}};for(let n=0;n<e.notifications.length;n+=1){c(t,e.notifications[n])}return t}const n={dataset:e.dataset,metadata:e.metadata||{},notifications:[]};for(let t=0;t<e.notifications.length;t+=1){const s=a(e.notifications[t]);n.notifications.push(s)}return n}(s,t);return{error:n.error,result:e,status:n.status,token:n.token}}return{error:n.error,result:n.result,status:n.status,token:n.token}}static stringify(e){const t=Object.assign({},e.params);return h.isQuery(t)&&(t.query=function(e){const t=[];for(let s=0;s<e.length;s+=1){const r={dataset:e[s].dataset,paths:[]},a=e[s];for(let e=0;e<a.paths.length;e+=1){const t=a.paths[e],s={path_elements:[]},c=[];if(t.keys&&Array.isArray(t.keys)){for(let e=0;e<t.keys.length;e+=1)c.push(n.fromByteArray(i(t.keys[e])));s.keys=c}s.path_elements=o(t.path_elements),r.paths.push(s)}t.push(r)}return t}(t.query)),h.isPublish(t)&&(t.batch=function(e){const t=[],n={dataset:e.dataset,notifications:t};if(Array.isArray(e.notifications))for(let n=0;n<e.notifications.length;n+=1)t.push(l(e.notifications[n]));else{const n=Object.keys(e.notifications);for(let s=0;s<n.length;s+=1){const i=n[s];for(let n=0;n<e.notifications[i].length;n+=1)t.push(l(e.notifications[i][n]))}}return n}(t.batch)),JSON.stringify({token:e.token,command:e.command,params:t})}static isQuery(e){const t=e;return void 0!==t.query&&Array.isArray(t.query)}static isPublish(e){const t=e;return void 0!==t.sync&&void 0!==t.batch}}const d="ERROR",m=new Set(["ANY","IP","MAC"]),f="cloudvision-connector",p={command:"NO_COMMAND",token:"NO_TOKEN",encodedParams:"NO_PARAMS"};class g{constructor(){this.events=new Map,this.requestContext=new Map}getEventsMap(){return this.events}getRequestContextMap(){return this.requestContext}has(e){return this.events.has(e)}bind(e,t,n){let s=this.events.get(e);return s?s.push(n):(s=[n],this.events.set(e,s),this.requestContext.set(e,t)),s.length}unbind(e,t){const n=this.events.get(e);if(!n)return null;const s=n.indexOf(t);-1!==s&&(n.splice(s,1),this.events.set(e,n));const i=n.length;return 0===i&&(this.events.delete(e),this.requestContext.delete(e)),i}unbindAll(e){this.events.delete(e),this.requestContext.delete(e)}emit(e,...t){const n=this.events.get(e);if(n)for(let s=n.length-1;s>=0;s-=1){const i=this.requestContext.get(e)||p;n[s](i,...t)}}close(){this.events.clear(),this.requestContext.clear()}}function y(){}class b{constructor(e){this.enableInstrumentation=!1,e&&(this.enableInstrumentation=!0),this.instrumentedCommands=e?e.commands:[],this.startFunction=e?e.start:y,this.infoFunction=e?e.info:y,this.endFunction=e?e.end:y}callStart(e,t){this.enableInstrumentation&&this.instrumentedCommands.includes(e)&&this.startFunction(t)}callInfo(e,t,n){this.enableInstrumentation&&this.instrumentedCommands.includes(e)&&this.infoFunction(t,n)}callEnd(e,t){this.enableInstrumentation&&this.instrumentedCommands.includes(e)&&this.endFunction(t)}}function S(e,t,n,s){const i=t?`${e}: ${t}`:e+": No message provided",r=n?`Status Code: ${n.code}, Status Message: ${n.message}`:void 0,o=s?"Request Token: "+s:void 0;switch(console.groupCollapsed("[[ CloudVision Connector ]]"),e){case d:o&&console.error(o),console.error(i),r&&console.error(r);break;case"WARN":o&&console.warn(o),console.warn(i),r&&console.warn(r);break;default:o&&console.log(o),console.log(i),r&&console.log(r)}console.groupEnd()}function v(e){return"number"==typeof e&&e>0}function C(e){return e/1e15>1}function k(e){const{start:t,end:n,versions:s}=e;let i,r,o;return v(t)&&(i=Math.floor(t)*(C(t)?1:1e6)),v(n)&&(r=Math.floor(n)*(C(n)?1:1e6)),v(s)&&(o=Math.floor(s)),{start:i,end:r,versions:o}}function O(e,t){const{start:n,end:s,versions:i}=e;return n&&s&&n>=s?(t(function(e,t,n){return`invalid params: start: ${e}, end: ${t}, versions: ${n||"undefined"}`}(n,s,i)),!1):!n||!i||(t("Defining start and versions is invalid"),!1)}function E(e,t,n=!1){return Array.isArray(e)?!!(n||e&&e.length)||(t("`query` param cannot be empty"),!1):(t("`query` param must be an array"),!1)}function A(e){return function e(t,n){const s=Object.keys(t);for(let i=0;i<s.length;i+=1){const r=s[i],o=t[r];o&&"object"==typeof o?n.hash(r.toString()).hash(e(o,n)):n.hash(r+""+o)}return n.result().toString()}(e,s())}function N(e,t){return A({command:e,params:t})}function w(e,t={}){return(n,s,i,r,o)=>{if(i&&1001===i.code)return void e(null,void 0,i,r,o);if(n)return e(`Error: ${n}\nOptions: ${JSON.stringify(t)}`,void 0,i,r,o),void e(null,void 0,{code:1001},r,o);const a=s;if(a&&a.datasets)return void e(null,a,i,r,o);const c=s;(c&&c.dataset||c)&&e(null,c,i,r,o)}}function T(e,t){const n={};if(Array.isArray(e)){const s=e.length;for(let i=0;i<s;i+=1){const{token:s,callback:r}=e[i];0===t.unbind(s,r)&&(n[s]=!0)}}else{const{token:s,callback:i}=e;0===t.unbind(s,i)&&(n[s]=!0)}return Object.keys(n).length?n:null}function q(e){const t=e.searchType;let n="ANY";return t&&m.has(t)&&(n=t),{search:e.search||"",searchType:n}}function D(e){return n.fromByteArray(t.encode(e,{extensionCodec:t.Codec}))}class _{constructor(e={batchResults:!0,debugMode:!1,pauseStreams:!1},t=WebSocket,n=h){this.connectorOptions=e,this.isRunning=!1,this.connectionEvents=new g,this.events=new g,this.closingStreams=new Map,this.waitingStreams=new Map,this.activeStreams=new Set,this.activeRequests=new Set,this.WebSocket=t,this.Parser=n,this.instrumentation=new b(e.instrumentationConfig)}get websocket(){return this.ws}get connectionEmitter(){return this.connectionEvents}get eventsEmitter(){return this.events}get streams(){return this.activeStreams}get streamInClosingState(){return this.closingStreams}addWaitingStream(e,t,n,s,i){const r=this.waitingStreams.get(e)||[];r.push([t,n,i,s]),this.waitingStreams.set(e,r)}callCommand(e,t,n){if(!this.isRunning)return n("Connection is down"),null;const s=N(e,t),i={command:e,encodedParams:D(t),token:s};if(this.activeRequests.has(s)){const e=this.makeQueuedCallbackWithUnbind(s,n);this.events.bind(s,i,e)}else{this.activeRequests.add(s);const r=this.makeCallbackWithUnbind(s,n);this.events.bind(s,i,r),this.sendMessageOrError(s,e,t,i)}return s}cleanUpConnections(){this.activeStreams.clear(),this.events.close()}close(){this.closeWs(new CloseEvent("close")),this.connectionEvents.close(),this.ws.close()}closeWs(e){this.isRunning=!1,this.cleanUpConnections(),this.connectionEvents.emit("connection",_.DISCONNECTED,e)}closeCommand(e,t,n){const s=N("close",t),i={command:"close",encodedParams:D(e),token:s};this.setStreamClosingState(e,s,i,n);try{this.sendMessage(s,"close",i,t)}catch(t){S(d,t),this.removeStreamClosingState(e,s),n(t,void 0,void 0,s)}return s}closeStreams(e,t){const n=T(e,this.events);return n?this.closeCommand(e,n,t):null}closeStream(e,t){const n=T(e,this.events);return n?this.closeCommand(e,n,t):null}connection(e){const t=(t,n,s)=>{e(n,s)};return this.connectionEvents.bind("connection",{command:"connection",encodedParams:"",token:""},t),()=>{this.connectionEvents.unbind("connection",t)}}enableOptions(e){this.connectorOptions.pauseStreams?this.pause({pauseStreams:!0},e):e(null)}get(e,t,n){return this.callCommand(e,t,n)}makeCallbackWithUnbind(e,t){const n=(s,i,r,o)=>{i&&(this.activeRequests.delete(e),this.events.unbind(e,n),this.instrumentation.callInfo(s.command,s,{error:i})),this.instrumentation.callEnd(s.command,s),t(i,r,o,e,s)};return n}makeQueuedCallbackWithUnbind(e,t){const n=(s,i,r,o)=>{i&&(this.events.unbind(e,n),t(i,r,o,e,s))};return n}publish(e,t){return this.callCommand("publish",e,t)}removeStreamClosingState(e,t){if(Array.isArray(e)){const n=e.length;for(let s=0;s<n;s+=1){const{token:n}=e[s];this.closingStreams.delete(n);const i=this.waitingStreams.get(t);if(i){const e=i.length;for(let n=0;n<e;n+=1)this.reSubscribeStream(i[n],t)}}}else{this.closingStreams.delete(e.token);const n=this.waitingStreams.get(t);n&&this.reSubscribeStream(n[0],t)}}requestService(e,t){return this.callCommand("serviceRequest",e,t)}reSubscribeStream(e,t){this.events.unbindAll(t),this.waitingStreams.delete(t),this.sendMessage(...e)}resume(e,t){return this.callCommand("resume",e,t)}run(e){this.runWithWs(new this.WebSocket(e))}runWithWs(e){this.ws=e,this.ws.onopen=e=>{this.isRunning||(this.isRunning=!0,this.enableOptions((t,n,s,i)=>{s&&1001!==s.code&&S(d,t,s,i),this.connectionEvents.emit("connection",_.CONNECTED,e)}))},this.ws.onclose=e=>{this.closeWs(e)},this.ws.onmessage=e=>{var t;if("string"!=typeof e.data)return;let n;try{n=this.Parser.parse(e.data,this.connectorOptions.batchResults),this.connectorOptions.debugMode&&self.postMessage({response:n,source:f,timestamp:Date.now()},"*")}catch(e){return void S(d,e)}if(!n||!n.token)return void S(d,"No message body or message token");const{error:s,status:i,token:r}=n;if(s)this.events.emit(r,s,n.result,i);else if(function(e,t,n,s){if(t&&Object.keys(t).length)return;const i=e;!i.dataset||i.dataset.name?!i.dataset||i.dataset.type?!i.dataset||i.notifications?s||!i.dataset||Array.isArray(i.notifications)||S(d,"Key 'notifications' is not an array",void 0,n):S(d,"No key 'notifications' found in response",void 0,n):S(d,"No key 'type' found in dataset",void 0,n):S(d,"No key 'name' found in dataset",void 0,n)}(n.result,i,r,this.connectorOptions.batchResults),i&&1002===i.code){const e=(e,t,n)=>{e&&S(d,e,n)};this.resume({token:r},e)}else this.events.emit(r,null,n.result,i),(null===(t=n.result)||void 0===t?void 0:t.metadata)&&"EOF"===n.result.metadata.GetRequest&&this.events.emit(r,null,null,{message:"GetRequest",code:1001})}}search(e,t){return this.callCommand("alpha/search",e,t)}sendMessage(e,t,n,s){this.connectorOptions.debugMode&&self.postMessage({request:{token:e,command:t,params:s},source:f,timestamp:Date.now()},"*"),this.instrumentation.callStart(t,n),this.ws.send(this.Parser.stringify({token:e,command:t,params:s}))}sendMessageOrError(e,t,n,s){try{this.sendMessage(e,t,s,n)}catch(t){S(d,t),this.events.emit(e,t,void 0,void 0)}}setStreamClosingState(e,t,n,s){if(Array.isArray(e)){const n=e.length;for(let s=0;s<n;s+=1){const{token:n}=e[s],i=this.closingStreams.get(n);this.waitingStreams.delete(i||""),this.closingStreams.set(n,t)}}else this.closingStreams.set(e.token,t);this.events.bind(t,n,(n,i,r,o)=>{this.removeStreamClosingState(e,t),s(i,r,o,t,n)})}stream(e,t,n){if(!this.isRunning)return n("Connection is down"),null;const s=N(e,t),i={command:e,encodedParams:D(t),token:s},r=(e,t,o,a)=>{t&&(this.events.unbind(s,r),this.instrumentation.callInfo(i.command,i,{error:t}),this.instrumentation.callEnd(e.command,e)),a&&3001===a.code&&(this.activeStreams.add(s),this.instrumentation.callInfo(i.command,i,{message:"stream active"})),n(t,o,a,s,e)};if(1===this.events.bind(s,i,r)){const n=this.closingStreams.get(s);n?this.addWaitingStream(n,s,e,t,i):this.sendMessageOrError(s,e,t,i)}else this.activeStreams.has(s)&&n(null,void 0,{code:3001},s,i);return{token:s,callback:r}}pause(e,t){return this.callCommand("pause",e,t)}}_.CONNECTED="connected",_.DISCONNECTED="disconnected";class I extends _{closeSubscriptions(e,t){return this.closeStreams(e,w(t))}getAndSubscribe(e,t,n){if(!E(e,t))return null;if(!O(n,t))return null;const s=k(n),i={query:e,start:s.start,end:s.end,versions:s.versions};return this.stream("getAndSubscribe",i,w(t))}getApps(e){const t={types:["app"]};return this.get("getDatasets",t,w(e))}getDatasets(e){const t={types:["app","device"]};return this.get("getDatasets",t,w(e))}getDevices(e){const t=["device"];return this.get("getDatasets",{types:t},w(e))}getCommandToken(e,t){return N(e,t)}getWithOptions(e,t,n){if("DEVICES_DATASET_ID"===e)return this.getDatasets(t),null;if(!E(e,t))return null;if(!O(n,t))return null;const{start:s,end:i,versions:r}=k(n),o={query:e,start:s,end:i,versions:r};return this.get("get",o,w(t,n))}runService(e,t){this.requestService(e,w(t))}runStreamingService(e,t){return e?this.stream("serviceRequest",e,w(t)):(t("`request` param cannot be empty"),null)}searchWithOptions(e,t,n){if(!E(e,t,!0))return null;if(!O(n,t))return null;const{start:s,end:i}=k(n),r=q(n),o={query:e,start:s,end:i,search:r.search,searchType:r.searchType};return this.search(o,w(t,n))}searchSubscribe(e,t,n={search:""}){if(!E(e,t,!0))return null;const s=q(n);return this.stream("alpha/searchSubscribe",{query:e,search:s.search,searchType:s.searchType},w(t))}subscribe(e,t){return E(e,t)?this.stream("subscribe",{query:e},w(t)):null}writeSync(e,t){this.publish({sync:!0,batch:{dataset:e.dataset,notifications:e.notifications}},function(e){return(t,n,s)=>{s&&1001===s.code?e(!0):t&&e(!1,`Error: ${t}\n`)}}(t))}}I.CLOSE="close",I.DEVICES_DATASET_ID="DEVICES_DATASET_ID",I.GET_DATASETS="getDatasets",I.GET="get",I.GET_AND_SUBSCRIBE="getAndSubscribe",I.ID=f,I.PAUSE="pause",I.PUBLISH="publish",I.SEARCH_SUBSCRIBE="alpha/searchSubscribe",I.SEARCH="alpha/search",I.SUBSCRIBE="subscribe",Object.defineProperty(e,"Bool",{enumerable:!0,get:function(){return t.Bool}}),Object.defineProperty(e,"Float32",{enumerable:!0,get:function(){return t.Float32}}),Object.defineProperty(e,"Float64",{enumerable:!0,get:function(){return t.Float64}}),Object.defineProperty(e,"Int",{enumerable:!0,get:function(){return t.Int}}),Object.defineProperty(e,"NeatTypeSerializer",{enumerable:!0,get:function(){return t.NeatTypeSerializer}}),Object.defineProperty(e,"NeatTypes",{enumerable:!0,get:function(){return t.NeatTypes}}),Object.defineProperty(e,"Nil",{enumerable:!0,get:function(){return t.Nil}}),Object.defineProperty(e,"Pointer",{enumerable:!0,get:function(){return t.Pointer}}),Object.defineProperty(e,"Str",{enumerable:!0,get:function(){return t.Str}}),Object.defineProperty(e,"createBaseType",{enumerable:!0,get:function(){return t.createBaseType}}),Object.defineProperty(e,"isJsbi",{enumerable:!0,get:function(){return t.isJsbi}}),Object.defineProperty(e,"isNeatType",{enumerable:!0,get:function(){return t.isNeatType}}),e.ACTIVE_CODE=3001,e.CONNECTED="connected",e.DISCONNECTED="disconnected",e.EOF_CODE=1001,e.Parser=h,e.default=I,e.fromBinaryKey=function(e,s=!0){return t.decode(n.toByteArray(e),{extensionCodec:t.Codec,useJSBI:s})},e.hashObject=A,e.sanitizeOptions=k,e.toBinaryKey=D,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("a-msgpack"),require("base64-js"),require("imurmurhash")):"function"==typeof define&&define.amd?define(["exports","a-msgpack","base64-js","imurmurhash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CloudvisionConnector={},e.msgpack,e["base64-js"],e.MurmurHash3)}(this,(function(e,t,n,s){"use strict";s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s;const i=e=>t.encode(e,{extensionCodec:t.Codec}),r=e=>t.decode(e,{extensionCodec:t.Codec,useJSBI:!0});function o(e){const t=[];for(let s=0;s<e.length;s+=1)t.push(n.fromByteArray(i(e[s])));return t}function a(e){const t={path_elements:[],timestamp:0};t.path_elements=function(e){const t=[];for(let s=0;s<e.length;s+=1)t.push(r(n.toByteArray(e[s])));return t}(e.path_elements||[]);let s="";return e.timestamp.nanos&&(s+=e.timestamp.nanos),s=s.padStart(9,"0"),t.timestamp=parseInt((""+e.timestamp.seconds+s).slice(0,13),10),e.updates&&(t.updates=function(e){const t={};for(let s=0;s<e.length;s+=1){const i=e[s].key,o=e[s].value,a=r(n.toByteArray(i)),c=r(n.toByteArray(o));t[i]={key:a,value:c}}return t}(e.updates)),e.deletes&&(t.deletes=function(e){const t={};for(let s=0;s<e.length;s+=1){const i=e[s];t[i]={key:r(n.toByteArray(i))}}return t}(e.deletes)),e.delete_all&&(t.deletes={}),t}function c(e,t){const n=a(t);e.notifications[JSON.stringify(n.path_elements)]?e.notifications[JSON.stringify(n.path_elements)].push(n):e.notifications[JSON.stringify(n.path_elements)]=[n]}function u(e,t){if(e.timestamp.seconds<t.timestamp.seconds)return-1;if(e.timestamp.seconds>t.timestamp.seconds)return 1;if(e.timestamp.nanos&&t.timestamp.nanos){if(e.timestamp.nanos<t.timestamp.nanos)return-1;if(e.timestamp.nanos>t.timestamp.nanos)return 1}return e.timestamp.nanos?t.timestamp.nanos?0:1:-1}function l(e){const t={timestamp:e.timestamp};return e.path_elements&&e.path_elements.length&&(t.path_elements=o(e.path_elements)),e.updates&&(t.updates=function(e){const t=[];for(let s=0;s<e.length;s+=1){const r=e[s].key,o=e[s].value;t.push({key:n.fromByteArray(i(r)),value:n.fromByteArray(i(o))})}return t}(e.updates)),e.deletes&&(Object.keys(e.deletes).length?t.deletes=function(e){const t=[];for(let s=0;s<e.length;s+=1){const r=e[s];t.push(n.fromByteArray(i(r)))}return t}(e.deletes):t.delete_all=!0),t}class h{static parse(e,t){const n=JSON.parse(e),s=n.result;if(s&&!s.datasets&&s.notifications){const e=function(e,t){if(e.notifications.sort(u),t){const t={dataset:e.dataset,metadata:e.metadata||{},notifications:{}};for(let n=0;n<e.notifications.length;n+=1){c(t,e.notifications[n])}return t}const n={dataset:e.dataset,metadata:e.metadata||{},notifications:[]};for(let t=0;t<e.notifications.length;t+=1){const s=a(e.notifications[t]);n.notifications.push(s)}return n}(s,t);return{error:n.error,result:e,status:n.status,token:n.token}}return{error:n.error,result:n.result,status:n.status,token:n.token}}static stringify(e){const t=Object.assign({},e.params);return h.isQuery(t)&&(t.query=function(e){const t=[];for(let s=0;s<e.length;s+=1){const r={dataset:e[s].dataset,paths:[]},a=e[s];for(let e=0;e<a.paths.length;e+=1){const t=a.paths[e],s={path_elements:[]},c=[];if(t.keys&&Array.isArray(t.keys)){for(let e=0;e<t.keys.length;e+=1)c.push(n.fromByteArray(i(t.keys[e])));s.keys=c}s.path_elements=o(t.path_elements),r.paths.push(s)}t.push(r)}return t}(t.query)),h.isPublish(t)&&(t.batch=function(e){const t=[],n={dataset:e.dataset,notifications:t};if(Array.isArray(e.notifications))for(let n=0;n<e.notifications.length;n+=1)t.push(l(e.notifications[n]));else{const n=Object.keys(e.notifications);for(let s=0;s<n.length;s+=1){const i=n[s];for(let n=0;n<e.notifications[i].length;n+=1)t.push(l(e.notifications[i][n]))}}return n}(t.batch)),JSON.stringify({token:e.token,command:e.command,params:t})}static isQuery(e){const t=e;return void 0!==t.query&&Array.isArray(t.query)}static isPublish(e){const t=e;return void 0!==t.sync&&void 0!==t.batch}}const d="ERROR",m=new Set(["ANY","IP","MAC"]),f="cloudvision-connector",p={command:"NO_COMMAND",token:"NO_TOKEN",encodedParams:"NO_PARAMS"};class g{constructor(){this.events=new Map,this.requestContext=new Map}getEventsMap(){return this.events}getRequestContextMap(){return this.requestContext}has(e){return this.events.has(e)}bind(e,t,n){let s=this.events.get(e);return s?s.push(n):(s=[n],this.events.set(e,s),this.requestContext.set(e,t)),s.length}unbind(e,t){const n=this.events.get(e);if(!n)return null;const s=n.indexOf(t);-1!==s&&(n.splice(s,1),this.events.set(e,n));const i=n.length;return 0===i&&(this.events.delete(e),this.requestContext.delete(e)),i}unbindAll(e){this.events.delete(e),this.requestContext.delete(e)}emit(e,...t){const n=this.events.get(e);if(n)for(let s=n.length-1;s>=0;s-=1){const i=this.requestContext.get(e)||p;n[s](i,...t)}}close(){this.events.clear(),this.requestContext.clear()}}function y(){}class b{constructor(e){this.enableInstrumentation=!1,e&&(this.enableInstrumentation=!0),this.instrumentedCommands=e?e.commands:[],this.startFunction=e?e.start:y,this.infoFunction=e?e.info:y,this.endFunction=e?e.end:y}callStart(e,t){this.enableInstrumentation&&this.instrumentedCommands.includes(e)&&this.startFunction(t)}callInfo(e,t,n){this.enableInstrumentation&&this.instrumentedCommands.includes(e)&&this.infoFunction(t,n)}callEnd(e,t){this.enableInstrumentation&&this.instrumentedCommands.includes(e)&&this.endFunction(t)}}function S(e,t,n,s){const i=t?`${e}: ${t}`:e+": No message provided",r=n?`Status Code: ${n.code}, Status Message: ${n.message}`:void 0,o=s?"Request Token: "+s:void 0;switch(console.groupCollapsed("[[ CloudVision Connector ]]"),e){case d:o&&console.error(o),console.error(i),r&&console.error(r);break;case"WARN":o&&console.warn(o),console.warn(i),r&&console.warn(r);break;default:o&&console.log(o),console.log(i),r&&console.log(r)}console.groupEnd()}function v(e){return"number"==typeof e&&e>0}function C(e){return e/1e15>1}function k(e){const{start:t,end:n,versions:s}=e;let i,r,o;return v(t)&&(i=Math.floor(t)*(C(t)?1:1e6)),v(n)&&(r=Math.floor(n)*(C(n)?1:1e6)),v(s)&&(o=Math.floor(s)),{start:i,end:r,versions:o}}function E(e,t){const{start:n,end:s,versions:i}=e;return n&&s&&n>=s?(t(function(e,t,n){return`invalid params: start: ${e}, end: ${t}, versions: ${n||"undefined"}`}(n,s,i)),!1):!n||!i||(t("Defining start and versions is invalid"),!1)}function O(e,t,n=!1){return Array.isArray(e)?!!(n||e&&e.length)||(t("`query` param cannot be empty"),!1):(t("`query` param must be an array"),!1)}function A(e){return function e(t,n){const s=Object.keys(t);for(let i=0;i<s.length;i+=1){const r=s[i],o=t[r];o&&"object"==typeof o?n.hash(r.toString()).hash(e(o,n)):n.hash(r+""+o)}return n.result().toString()}(e,s())}function N(e,t){return A({command:e,params:t})}function T(e,t={}){return(n,s,i,r,o)=>{if(i&&1001===i.code)return void e(null,void 0,i,r,o);if(n)return e(`Error: ${n}\nOptions: ${JSON.stringify(t)}`,void 0,i,r,o),void e(null,void 0,{code:1001},r,o);const a=s;if(a&&a.datasets)return void e(null,a,i,r,o);const c=s;(c&&c.dataset||c)&&e(null,c,i,r,o)}}function w(e,t){const n={};if(Array.isArray(e)){const s=e.length;for(let i=0;i<s;i+=1){const{token:s,callback:r}=e[i];0===t.unbind(s,r)&&(n[s]=!0)}}else{const{token:s,callback:i}=e;0===t.unbind(s,i)&&(n[s]=!0)}return Object.keys(n).length?n:null}function q(e){const t=e.searchType;let n="ANY";return t&&m.has(t)&&(n=t),{search:e.search||"",searchType:n}}function D(e){return n.fromByteArray(t.encode(e,{extensionCodec:t.Codec}))}class _{constructor(e={batchResults:!0,debugMode:!1,pauseStreams:!1},t=WebSocket,n=h){this.connectorOptions=e,this.isRunning=!1,this.connectionEvents=new g,this.events=new g,this.closingStreams=new Map,this.waitingStreams=new Map,this.activeStreams=new Set,this.activeRequests=new Set,this.WebSocket=t,this.Parser=n,this.instrumentation=new b(e.instrumentationConfig)}get websocket(){return this.ws}get connectionEmitter(){return this.connectionEvents}get eventsEmitter(){return this.events}get streams(){return this.activeStreams}get streamInClosingState(){return this.closingStreams}addWaitingStream(e,t,n,s,i){const r=this.waitingStreams.get(e)||[];r.push([t,n,i,s]),this.waitingStreams.set(e,r)}callCommand(e,t,n){if(!this.isRunning)return n("Connection is down"),null;const s=N(e,t),i={command:e,encodedParams:D(t),token:s};if(this.activeRequests.has(s)){const e=this.makeQueuedCallbackWithUnbind(s,n);this.events.bind(s,i,e)}else{this.activeRequests.add(s);const r=this.makeCallbackWithUnbind(s,n);this.events.bind(s,i,r),this.sendMessageOrError(s,e,t,i)}return s}cleanUpConnections(){this.activeStreams.clear(),this.events.close()}close(){this.closeWs(new CloseEvent("close")),this.connectionEvents.close(),this.ws.close()}closeWs(e){this.isRunning=!1,this.cleanUpConnections(),this.connectionEvents.emit("connection",_.DISCONNECTED,e)}closeCommand(e,t,n){const s=N("close",t),i={command:"close",encodedParams:D(e),token:s};this.setStreamClosingState(e,s,i,n);try{this.sendMessage(s,"close",i,t)}catch(t){S(d,t),this.removeStreamClosingState(e,s),n(t,void 0,void 0,s)}return s}closeStreams(e,t){const n=w(e,this.events);return n?this.closeCommand(e,n,t):null}closeStream(e,t){const n=w(e,this.events);return n?this.closeCommand(e,n,t):null}connection(e){const t=(t,n,s)=>{e(n,s)};return this.connectionEvents.bind("connection",{command:"connection",encodedParams:"",token:""},t),()=>{this.connectionEvents.unbind("connection",t)}}enableOptions(e){this.connectorOptions.pauseStreams?this.pause({pauseStreams:!0},e):e(null)}get(e,t,n){return this.callCommand(e,t,n)}makeCallbackWithUnbind(e,t){const n=(s,i,r,o)=>{i&&(this.activeRequests.delete(e),this.events.unbind(e,n),this.instrumentation.callInfo(s.command,s,{error:i})),this.instrumentation.callEnd(s.command,s),t(i,r,o,e,s)};return n}makeQueuedCallbackWithUnbind(e,t){const n=(s,i,r,o)=>{i&&(this.events.unbind(e,n),t(i,r,o,e,s))};return n}publish(e,t){return this.callCommand("publish",e,t)}removeStreamClosingState(e,t){if(Array.isArray(e)){const n=e.length;for(let s=0;s<n;s+=1){const{token:n}=e[s];this.closingStreams.delete(n);const i=this.waitingStreams.get(t);if(i){const e=i.length;for(let n=0;n<e;n+=1)this.reSubscribeStream(i[n],t)}}}else{this.closingStreams.delete(e.token);const n=this.waitingStreams.get(t);n&&this.reSubscribeStream(n[0],t)}}requestService(e,t){return this.callCommand("serviceRequest",e,t)}reSubscribeStream(e,t){this.events.unbindAll(t),this.waitingStreams.delete(t),this.sendMessage(...e)}resume(e,t){return this.callCommand("resume",e,t)}run(e){this.runWithWs(new this.WebSocket(e))}runWithWs(e){this.ws=e,this.ws.onopen=e=>{this.isRunning||(this.isRunning=!0,this.enableOptions((t,n,s,i)=>{s&&1001!==s.code&&S(d,t,s,i),this.connectionEvents.emit("connection",_.CONNECTED,e)}))},this.ws.onclose=e=>{this.closeWs(e)},this.ws.onmessage=e=>{var t;if("string"!=typeof e.data)return;let n;try{n=this.Parser.parse(e.data,this.connectorOptions.batchResults),this.connectorOptions.debugMode&&self.postMessage({response:n,source:f,timestamp:Date.now()},"*")}catch(e){return void S(d,e)}if(!n||!n.token)return void S(d,"No message body or message token");const{error:s,status:i,token:r}=n;if(s)this.events.emit(r,s,n.result,i);else if(function(e,t,n,s){if(t&&Object.keys(t).length)return;const i=e;!i.dataset||i.dataset.name?!i.dataset||i.dataset.type?!i.dataset||i.notifications?s||!i.dataset||Array.isArray(i.notifications)||S(d,"Key 'notifications' is not an array",void 0,n):S(d,"No key 'notifications' found in response",void 0,n):S(d,"No key 'type' found in dataset",void 0,n):S(d,"No key 'name' found in dataset",void 0,n)}(n.result,i,r,this.connectorOptions.batchResults),i&&1002===i.code){const e=(e,t,n)=>{e&&S(d,e,n)};this.resume({token:r},e)}else this.events.emit(r,null,n.result,i),(null===(t=n.result)||void 0===t?void 0:t.metadata)&&"EOF"===n.result.metadata.GetRequest&&this.events.emit(r,null,null,{message:"GetRequest",code:1001})}}search(e,t){return this.callCommand("alpha/search",e,t)}sendMessage(e,t,n,s){this.connectorOptions.debugMode&&self.postMessage({request:{token:e,command:t,params:s},source:f,timestamp:Date.now()},"*"),this.instrumentation.callStart(t,n),this.ws.send(this.Parser.stringify({token:e,command:t,params:s}))}sendMessageOrError(e,t,n,s){try{this.sendMessage(e,t,s,n)}catch(t){S(d,t),this.events.emit(e,t,void 0,void 0)}}setStreamClosingState(e,t,n,s){if(Array.isArray(e)){const n=e.length;for(let s=0;s<n;s+=1){const{token:n}=e[s],i=this.closingStreams.get(n);this.waitingStreams.delete(i||""),this.closingStreams.set(n,t)}}else this.closingStreams.set(e.token,t);this.events.bind(t,n,(n,i,r,o)=>{this.removeStreamClosingState(e,t),s(i,r,o,t,n)})}stream(e,t,n){if(!this.isRunning)return n("Connection is down"),null;const s=N(e,t),i={command:e,encodedParams:D(t),token:s},r=(e,t,o,a)=>{t&&(this.events.unbind(s,r),this.instrumentation.callInfo(i.command,i,{error:t}),this.instrumentation.callEnd(e.command,e)),a&&3001===a.code&&(this.activeStreams.add(s),this.instrumentation.callInfo(i.command,i,{message:"stream active"})),n(t,o,a,s,e)};if(1===this.events.bind(s,i,r)){const n=this.closingStreams.get(s);n?this.addWaitingStream(n,s,e,t,i):this.sendMessageOrError(s,e,t,i)}else this.activeStreams.has(s)&&n(null,void 0,{code:3001},s,i);return{token:s,callback:r}}pause(e,t){return this.callCommand("pause",e,t)}}_.CONNECTED="connected",_.DISCONNECTED="disconnected";class I extends _{closeSubscriptions(e,t){return this.closeStreams(e,T(t))}getAndSubscribe(e,t,n){if(!O(e,t))return null;if(!E(n,t))return null;const s=k(n),i={query:e,start:s.start,end:s.end,versions:s.versions};return this.stream("getAndSubscribe",i,T(t))}getApps(e){const t={types:["app"]};return this.get("getDatasets",t,T(e))}getDatasets(e){const t={types:["app","device"]};return this.get("getDatasets",t,T(e))}getDevices(e){const t=["device"];return this.get("getDatasets",{types:t},T(e))}getCommandToken(e,t){return N(e,t)}getWithOptions(e,t,n){if("DEVICES_DATASET_ID"===e)return this.getDatasets(t),null;if(!O(e,t))return null;if(!E(n,t))return null;const{start:s,end:i,versions:r}=k(n),o={query:e,start:s,end:i,versions:r};return this.get("get",o,T(t,n))}runService(e,t){this.requestService(e,T(t))}runStreamingService(e,t){return e?this.stream("serviceRequest",e,T(t)):(t("`request` param cannot be empty"),null)}searchWithOptions(e,t,n){if(!O(e,t,!0))return null;if(!E(n,t))return null;const{start:s,end:i}=k(n),r=q(n),o={query:e,start:s,end:i,search:r.search,searchType:r.searchType};return this.search(o,T(t,n))}searchSubscribe(e,t,n={search:""}){if(!O(e,t,!0))return null;const s=q(n);return this.stream("alpha/searchSubscribe",{query:e,search:s.search,searchType:s.searchType},T(t))}subscribe(e,t){return O(e,t)?this.stream("subscribe",{query:e},T(t)):null}writeSync(e,t){this.publish({sync:!0,batch:{dataset:e.dataset,notifications:e.notifications}},function(e){return(t,n,s)=>{s&&1001===s.code?e(!0):t&&e(!1,`Error: ${t}\n`)}}(t))}}I.CLOSE="close",I.DEVICES_DATASET_ID="DEVICES_DATASET_ID",I.GET_DATASETS="getDatasets",I.GET="get",I.GET_AND_SUBSCRIBE="getAndSubscribe",I.ID=f,I.PAUSE="pause",I.PUBLISH="publish",I.SEARCH_SUBSCRIBE="alpha/searchSubscribe",I.SEARCH="alpha/search",I.SERVICE_REQUEST="serviceRequest",I.SUBSCRIBE="subscribe",Object.defineProperty(e,"Bool",{enumerable:!0,get:function(){return t.Bool}}),Object.defineProperty(e,"Float32",{enumerable:!0,get:function(){return t.Float32}}),Object.defineProperty(e,"Float64",{enumerable:!0,get:function(){return t.Float64}}),Object.defineProperty(e,"Int",{enumerable:!0,get:function(){return t.Int}}),Object.defineProperty(e,"NeatTypeSerializer",{enumerable:!0,get:function(){return t.NeatTypeSerializer}}),Object.defineProperty(e,"NeatTypes",{enumerable:!0,get:function(){return t.NeatTypes}}),Object.defineProperty(e,"Nil",{enumerable:!0,get:function(){return t.Nil}}),Object.defineProperty(e,"Pointer",{enumerable:!0,get:function(){return t.Pointer}}),Object.defineProperty(e,"Str",{enumerable:!0,get:function(){return t.Str}}),Object.defineProperty(e,"createBaseType",{enumerable:!0,get:function(){return t.createBaseType}}),Object.defineProperty(e,"isJsbi",{enumerable:!0,get:function(){return t.isJsbi}}),Object.defineProperty(e,"isNeatType",{enumerable:!0,get:function(){return t.isNeatType}}),e.ACTIVE_CODE=3001,e.CONNECTED="connected",e.DISCONNECTED="disconnected",e.EOF_CODE=1001,e.Parser=h,e.default=I,e.fromBinaryKey=function(e,s=!0){return t.decode(n.toByteArray(e),{extensionCodec:t.Codec,useJSBI:s})},e.hashObject=A,e.sanitizeOptions=k,e.toBinaryKey=D,Object.defineProperty(e,"__esModule",{value:!0})}));

@@ -1580,2 +1580,3 @@ import { encode, Codec, decode } from 'a-msgpack';

Connector.SEARCH = SEARCH;
Connector.SERVICE_REQUEST = SERVICE_REQUEST;
Connector.SUBSCRIBE = SUBSCRIBE;

@@ -1582,0 +1583,0 @@

@@ -1585,2 +1585,3 @@ 'use strict';

Connector.SEARCH = SEARCH;
Connector.SERVICE_REQUEST = SERVICE_REQUEST;
Connector.SUBSCRIBE = SUBSCRIBE;

@@ -1587,0 +1588,0 @@

{
"name": "cloudvision-connector",
"version": "4.5.1",
"version": "4.5.2",
"description": "A module to communicate with the CloudVision API server",

@@ -89,3 +89,3 @@ "author": "extensions@arista.com",

},
"gitHead": "fc553478325375457d63f781e89d8d9f94e27aa2"
"gitHead": "b7aa5c5483e4f234b593e89c3c482f3907b07d6a"
}

@@ -72,2 +72,4 @@ import {

public static SERVICE_REQUEST: typeof SERVICE_REQUEST = SERVICE_REQUEST;
public static SUBSCRIBE: typeof SUBSCRIBE = SUBSCRIBE;

@@ -74,0 +76,0 @@

import { CloudVisionParams, NotifCallback, Options, PublishCallback, PublishRequest, Query, SearchOptions, ServiceRequest, SubscriptionIdentifier, WsCommand } from '../types';
import Wrpc from './Wrpc';
import { CLOSE, DEVICES_DATASET_ID, GET, GET_AND_SUBSCRIBE, GET_DATASETS, ID, PAUSE, PUBLISH, SEARCH, SEARCH_SUBSCRIBE, SUBSCRIBE } from './constants';
import { CLOSE, DEVICES_DATASET_ID, GET, GET_AND_SUBSCRIBE, GET_DATASETS, ID, PAUSE, PUBLISH, SEARCH, SEARCH_SUBSCRIBE, SERVICE_REQUEST, SUBSCRIBE } from './constants';
/**

@@ -21,2 +21,3 @@ * The Connector uses WebSocket to enable transmission of data over an

static SEARCH: typeof SEARCH;
static SERVICE_REQUEST: typeof SERVICE_REQUEST;
static SUBSCRIBE: typeof SUBSCRIBE;

@@ -23,0 +24,0 @@ /**

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc