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.4 to 4.5.5

8

CHANGELOG.md

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

## [4.5.5](https://github.com/aristanetworks/cloudvision/compare/v4.5.4...v4.5.5) (2020-09-16)
**Note:** Version bump only for package cloudvision-connector
## [4.5.4](https://github.com/aristanetworks/cloudvision/compare/v4.5.3...v4.5.4) (2020-08-10)

@@ -8,0 +16,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("uuid"),require("base64-js")):"function"==typeof define&&define.amd?define(["exports","a-msgpack","uuid","base64-js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CloudvisionConnector={},e.msgpack,e.uuid,e["base64-js"])}(this,(function(e,t,n,s){"use strict";const r=e=>t.encode(e,{extensionCodec:t.Codec}),o=e=>t.decode(e,{extensionCodec:t.Codec,useJSBI:!0});function i(e){const t=[];for(let n=0;n<e.length;n+=1)t.push(s.fromByteArray(r(e[n])));return t}function a(e){const t={path_elements:[],timestamp:0};t.path_elements=function(e){const t=[];for(let n=0;n<e.length;n+=1)t.push(o(s.toByteArray(e[n])));return t}(e.path_elements||[]);let n="";return e.timestamp.nanos&&(n+=e.timestamp.nanos),n=n.padStart(9,"0"),t.timestamp=parseInt((""+e.timestamp.seconds+n).slice(0,13),10),e.updates&&(t.updates=function(e){const t={};for(let n=0;n<e.length;n+=1){const r=e[n].key,i=e[n].value,a=o(s.toByteArray(r)),c=o(s.toByteArray(i));t[r]={key:a,value:c}}return t}(e.updates)),e.deletes&&(t.deletes=function(e){const t={};for(let n=0;n<e.length;n+=1){const r=e[n];t[r]={key:o(s.toByteArray(r))}}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=i(e.path_elements)),e.updates&&(t.updates=function(e){const t=[];for(let n=0;n<e.length;n+=1){const o=e[n].key,i=e[n].value;t.push({key:s.fromByteArray(r(o)),value:s.fromByteArray(r(i))})}return t}(e.updates)),e.deletes&&(Object.keys(e.deletes).length?t.deletes=function(e){const t=[];for(let n=0;n<e.length;n+=1){const o=e[n];t.push(s.fromByteArray(r(o)))}return t}(e.deletes):t.delete_all=!0),t}class d{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 d.isQuery(t)&&(t.query=function(e){const t=[];for(let n=0;n<e.length;n+=1){const o={dataset:e[n].dataset,paths:[]},a=e[n];for(let e=0;e<a.paths.length;e+=1){const t=a.paths[e],n={path_elements:[]},c=[];if(t.keys&&Array.isArray(t.keys)){for(let e=0;e<t.keys.length;e+=1)c.push(s.fromByteArray(r(t.keys[e])));n.keys=c}n.path_elements=i(t.path_elements),o.paths.push(n)}t.push(o)}return t}(t.query)),d.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 r=n[s];for(let n=0;n<e.notifications[r].length;n+=1)t.push(l(e.notifications[r][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 h="ERROR",m=new Set(["ANY","IP","MAC"]),f="cloudvision-connector",p={command:"NO_COMMAND",token:"NO_TOKEN",encodedParams:"NO_PARAMS"};class y{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 r=n.length;return 0===r&&(this.events.delete(e),this.requestContext.delete(e)),r}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 r=this.requestContext.get(e)||p;n[s](r,...t)}}close(){this.events.clear(),this.requestContext.clear()}}function b(){}class g{constructor(e){this.enableInstrumentation=!1,e&&(this.enableInstrumentation=!0),this.instrumentedCommands=e?e.commands:[],this.startFunction=e?e.start:b,this.infoFunction=e?e.info:b,this.endFunction=e?e.end:b}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 v(e,t,n,s){const r=t?`${e}: ${t}`:e+": No message provided",o=n?`Status Code: ${n.code}, Status Message: ${n.message}`:void 0,i=s?"Request Token: "+s:void 0;switch(console.groupCollapsed("[[ CloudVision Connector ]]"),e){case h:i&&console.error(i),console.error(r),o&&console.error(o);break;case"WARN":i&&console.warn(i),console.warn(r),o&&console.warn(o);break;default:i&&console.log(i),console.log(r),o&&console.log(o)}console.groupEnd()}function E(e){return"number"==typeof e&&e>0}function C(e){return e/1e15>1}function S(e){const{start:t,end:n,versions:s}=e;let r,o,i;return E(t)&&(r=Math.floor(t)*(C(t)?1:1e6)),E(n)&&(o=Math.floor(n)*(C(n)?1:1e6)),E(s)&&(i=Math.floor(s)),{start:r,end:o,versions:i}}function O(e,t){const{start:n,end:s,versions:r}=e;return n&&s&&n>=s?(t(function(e,t,n){return`invalid params: start: ${e}, end: ${t}, versions: ${n||"undefined"}`}(n,s,r)),!1):!n||!r||(t("Defining start and versions is invalid"),!1)}function k(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,t={}){return(n,s,r,o,i)=>{if(r&&1001===r.code)return void e(null,void 0,r,o,i);if(n)return e(`Error: ${n}\nOptions: ${JSON.stringify(t)}`,void 0,r,o,i),void e(null,void 0,{code:1001},o,i);const a=s;if(a&&a.datasets)return void e(null,a,r,o,i);const c=s;(c&&c.dataset||c)&&e(null,c,r,o,i)}}function T(e,t){const n={};if(Array.isArray(e)){const s=e.length;for(let r=0;r<s;r+=1){const{token:s,callback:o}=e[r];0===t.unbind(s,o)&&(n[s]=!0)}}else{const{token:s,callback:r}=e;0===t.unbind(s,r)&&(n[s]=!0)}return Object.keys(n).length?n:null}function N(e){const t=e.searchType;let n="ANY";return t&&m.has(t)&&(n=t),{search:e.search||"",searchType:n}}function _(e){return s.fromByteArray(t.encode(e,{extensionCodec:t.Codec}))}class D{constructor(e={batchResults:!0,debugMode:!1},t=WebSocket,n=d){this.connectorOptions=e,this.isRunning=!1,this.connectionEvents=new y,this.events=new y,this.WebSocket=t,this.Parser=n,this.instrumentation=new g(e.instrumentationConfig)}get websocket(){return this.ws}get connectionEmitter(){return this.connectionEvents}get eventsEmitter(){return this.events}callCommand(e,t,s){if(!this.isRunning)return s("Connection is down"),null;const r=n.v4(),o={command:e,encodedParams:_(t),token:r},i=this.makeCallbackWithUnbind(r,s);return this.events.bind(r,o,i),this.sendMessageOrError(r,e,t,o),r}cleanUpConnections(){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",D.DISCONNECTED,e)}closeCommand(e,t,s){const r=n.v4(),o={command:"close",encodedParams:_(e),token:r},i=this.makeCallbackWithUnbind(r,s);this.events.bind(r,o,i);try{this.sendMessage(r,"close",o,t)}catch(e){v(h,e),s(e,void 0,void 0,r)}return r}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)}}get(e,t,n){return this.callCommand(e,t,n)}makeCallbackWithUnbind(e,t){const n=(s,r,o,i)=>{r&&(this.events.unbind(e,n),this.instrumentation.callInfo(s.command,s,{error:r})),this.instrumentation.callEnd(s.command,s),t(r,o,i,e,s)};return n}publish(e,t){return this.callCommand("publish",e,t)}requestService(e,t){return this.callCommand("serviceRequest",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.connectionEvents.emit("connection",D.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 v(h,e)}if(!n||!n.token)return void v(h,"No message body or message token");const{error:s,status:r,token:o}=n;s?this.events.emit(o,s,n.result,r):(!function(e,t,n,s){if(t&&Object.keys(t).length)return;const r=e;!r.dataset||r.dataset.name?!r.dataset||r.dataset.type?!r.dataset||r.notifications?s||!r.dataset||Array.isArray(r.notifications)||v(h,"Key 'notifications' is not an array",void 0,n):v(h,"No key 'notifications' found in response",void 0,n):v(h,"No key 'type' found in dataset",void 0,n):v(h,"No key 'name' found in dataset",void 0,n)}(n.result,r,o,this.connectorOptions.batchResults),this.events.emit(o,null,n.result,r),(null===(t=n.result)||void 0===t?void 0:t.metadata)&&"EOF"===n.result.metadata.GetRequest&&this.events.emit(o,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){v(h,t),this.events.emit(e,t,void 0,void 0)}}stream(e,t,s){if(!this.isRunning)return s("Connection is down"),null;const r=n.v4(),o={command:e,encodedParams:_(t),token:r},i=(e,t,n,a)=>{t&&(this.events.unbind(r,i),this.instrumentation.callInfo(o.command,o,{error:t}),this.instrumentation.callEnd(e.command,e)),a&&3001===a.code&&this.instrumentation.callInfo(o.command,o,{message:"stream active"}),s(t,n,a,r,e)};return this.events.bind(r,o,i),this.sendMessageOrError(r,e,t,o),{token:r,callback:i}}}D.CONNECTED="connected",D.DISCONNECTED="disconnected";class P extends D{closeSubscriptions(e,t){return this.closeStreams(e,A(t))}getAndSubscribe(e,t,n){if(!k(e,t))return null;if(!O(n,t))return null;const s=S(n),r={query:e,start:s.start,end:s.end,versions:s.versions};return this.stream("getAndSubscribe",r,A(t))}getApps(e){const t={types:["app"]};return this.get("getDatasets",t,A(e))}getDatasets(e){const t={types:["app","device"]};return this.get("getDatasets",t,A(e))}getDevices(e){const t=["device"];return this.get("getDatasets",{types:t},A(e))}getWithOptions(e,t,n){if("DEVICES_DATASET_ID"===e)return this.getDatasets(t),null;if(!k(e,t))return null;if(!O(n,t))return null;const{start:s,end:r,versions:o}=S(n),i={query:e,start:s,end:r,versions:o};return this.get("get",i,A(t,n))}runService(e,t){this.requestService(e,A(t))}runStreamingService(e,t){return e?this.stream("serviceRequest",e,A(t)):(t("`request` param cannot be empty"),null)}searchWithOptions(e,t,n){if(!k(e,t,!0))return null;if(!O(n,t))return null;const{start:s,end:r}=S(n),o=N(n),i={query:e,start:s,end:r,search:o.search,searchType:o.searchType};return this.search(i,A(t,n))}searchSubscribe(e,t,n={search:""}){if(!k(e,t,!0))return null;const s=N(n);return this.stream("alpha/searchSubscribe",{query:e,search:s.search,searchType:s.searchType},A(t))}subscribe(e,t){return k(e,t)?this.stream("subscribe",{query:e},A(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))}}P.CLOSE="close",P.DEVICES_DATASET_ID="DEVICES_DATASET_ID",P.GET_DATASETS="getDatasets",P.GET="get",P.GET_AND_SUBSCRIBE="getAndSubscribe",P.ID=f,P.PUBLISH="publish",P.SEARCH_SUBSCRIBE="alpha/searchSubscribe",P.SEARCH="alpha/search",P.SERVICE_REQUEST="serviceRequest",P.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.APP_DATASET_TYPE="app",e.CONNECTED="connected",e.DEVICE_DATASET_TYPE="device",e.DISCONNECTED="disconnected",e.EOF="EOF",e.EOF_CODE=1001,e.GET_REQUEST_COMPLETED="GetRequest",e.Parser=d,e.default=P,e.fromBinaryKey=function(e,n=!0){return t.decode(s.toByteArray(e),{extensionCodec:t.Codec,useJSBI:n})},e.sanitizeOptions=S,e.toBinaryKey=_,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("a-msgpack"),require("uuid"),require("base64-js")):"function"==typeof define&&define.amd?define(["exports","a-msgpack","uuid","base64-js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CloudvisionConnector={},e.msgpack,e.uuid,e["base64-js"])}(this,(function(e,t,n,s){"use strict";const r=e=>t.encode(e,{extensionCodec:t.Codec}),o=e=>t.decode(e,{extensionCodec:t.Codec,useJSBI:!0});function i(e){const t=[];for(let n=0;n<e.length;n+=1)t.push(s.fromByteArray(r(e[n])));return t}function a(e){const t={path_elements:[],timestamp:0};t.path_elements=function(e){const t=[];for(let n=0;n<e.length;n+=1)t.push(o(s.toByteArray(e[n])));return t}(e.path_elements||[]);let n="";return e.timestamp.nanos&&(n+=e.timestamp.nanos),n=n.padStart(9,"0"),t.timestamp=parseInt((""+e.timestamp.seconds+n).slice(0,13),10),e.updates&&(t.updates=function(e){const t={};for(let n=0;n<e.length;n+=1){const r=e[n].key,i=e[n].value,a=o(s.toByteArray(r)),c=o(s.toByteArray(i));t[r]={key:a,value:c}}return t}(e.updates)),e.deletes&&(t.deletes=function(e){const t={};for(let n=0;n<e.length;n+=1){const r=e[n];t[r]={key:o(s.toByteArray(r))}}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=i(e.path_elements)),e.updates&&(t.updates=function(e){const t=[];for(let n=0;n<e.length;n+=1){const o=e[n].key,i=e[n].value;t.push({key:s.fromByteArray(r(o)),value:s.fromByteArray(r(i))})}return t}(e.updates)),e.deletes&&(Object.keys(e.deletes).length?t.deletes=function(e){const t=[];for(let n=0;n<e.length;n+=1){const o=e[n];t.push(s.fromByteArray(r(o)))}return t}(e.deletes):t.delete_all=!0),t}class d{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 d.isQuery(t)&&(t.query=function(e){const t=[];for(let n=0;n<e.length;n+=1){const o={dataset:e[n].dataset,paths:[]},a=e[n];for(let e=0;e<a.paths.length;e+=1){const t=a.paths[e],n={path_elements:[]},c=[];if(t.keys&&Array.isArray(t.keys)){for(let e=0;e<t.keys.length;e+=1)c.push(s.fromByteArray(r(t.keys[e])));n.keys=c}n.path_elements=i(t.path_elements),o.paths.push(n)}t.push(o)}return t}(t.query)),d.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 r=n[s];for(let n=0;n<e.notifications[r].length;n+=1)t.push(l(e.notifications[r][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 h="ERROR",m=1001,f="GetRequest",p="close",y="DEVICES_DATASET_ID",g="getDatasets",b="getAndSubscribe",v="publish",E="subscribe",C="alpha/search",S="alpha/searchSubscribe",O="serviceRequest",k="app",A="device",T=new Set(["ANY","IP","MAC"]),N="connected",_="disconnected",P="cloudvision-connector",D={command:"NO_COMMAND",token:"NO_TOKEN",encodedParams:"NO_PARAMS"};class q{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 r=n.length;return 0===r&&(this.events.delete(e),this.requestContext.delete(e)),r}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 r=this.requestContext.get(e)||D;n[s](r,...t)}}close(){this.events.clear(),this.requestContext.clear()}}function I(){}class R{constructor(e){this.enableInstrumentation=!1,e&&(this.enableInstrumentation=!0),this.instrumentedCommands=e?e.commands:[],this.startFunction=e?e.start:I,this.infoFunction=e?e.info:I,this.endFunction=e?e.end:I}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 B(e,t,n,s){const r=t?`${e}: ${t}`:e+": No message provided",o=n?`Status Code: ${n.code}, Status Message: ${n.message}`:void 0,i=s?"Request Token: "+s:void 0;switch(console.groupCollapsed("[[ CloudVision Connector ]]"),e){case h:i&&console.error(i),console.error(r),o&&console.error(o);break;case"WARN":i&&console.warn(i),console.warn(r),o&&console.warn(o);break;default:i&&console.log(i),console.log(r),o&&console.log(o)}console.groupEnd()}function w(e){return"number"==typeof e&&e>0}function M(e){return e/1e15>1}function j(e){const{start:t,end:n,versions:s}=e;let r,o,i;return w(t)&&(r=Math.floor(t)*(M(t)?1:1e6)),w(n)&&(o=Math.floor(n)*(M(n)?1:1e6)),w(s)&&(i=Math.floor(s)),{start:r,end:o,versions:i}}function x(e,t){const{start:n,end:s,versions:r}=e;return n&&s&&n>=s?(t(function(e,t,n){return`invalid params: start: ${e}, end: ${t}, versions: ${n||"undefined"}`}(n,s,r)),!1):!n||!r||(t("Defining start and versions is invalid"),!1)}function W(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 F(e,t={}){return(n,s,r,o,i)=>{if(r&&r.code===m)return void e(null,void 0,r,o,i);if(n)return e(`Error: ${n}\nOptions: ${JSON.stringify(t)}`,void 0,r,o,i),void e(null,void 0,{code:m},o,i);const a=s;if(a&&a.datasets)return void e(null,a,r,o,i);const c=s;(c&&c.dataset||c)&&e(null,c,r,o,i)}}function U(e,t){const n={};if(Array.isArray(e)){const s=e.length;for(let r=0;r<s;r+=1){const{token:s,callback:o}=e[r];0===t.unbind(s,o)&&(n[s]=!0)}}else{const{token:s,callback:r}=e;0===t.unbind(s,r)&&(n[s]=!0)}return Object.keys(n).length?n:null}function J(e){const t=e.searchType;let n="ANY";return t&&T.has(t)&&(n=t),{search:e.search||"",searchType:n}}function $(e){return s.fromByteArray(t.encode(e,{extensionCodec:t.Codec}))}class G{constructor(e={batchResults:!0,debugMode:!1},t=WebSocket,n=d){this.connectorOptions=e,this.isRunning=!1,this.connectionEvents=new q,this.events=new q,this.WebSocket=t,this.Parser=n,this.instrumentation=new R(e.instrumentationConfig)}get websocket(){return this.ws}get connectionEmitter(){return this.connectionEvents}get eventsEmitter(){return this.events}callCommand(e,t,s){if(!this.isRunning)return s("Connection is down"),null;const r=n.v4(),o={command:e,encodedParams:$(t),token:r},i=this.makeCallbackWithUnbind(r,s);return this.events.bind(r,o,i),this.sendMessageOrError(r,e,t,o),r}cleanUpConnections(){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",G.DISCONNECTED,e)}closeCommand(e,t,s){const r=n.v4(),o={command:p,encodedParams:$(e),token:r},i=this.makeCallbackWithUnbind(r,s);this.events.bind(r,o,i);try{this.sendMessage(r,p,o,t)}catch(e){B(h,e),s(e,void 0,void 0,r)}return r}closeStreams(e,t){const n=U(e,this.events);return n?this.closeCommand(e,n,t):null}closeStream(e,t){const n=U(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)}}get(e,t,n){return this.callCommand(e,t,n)}makeCallbackWithUnbind(e,t){const n=(s,r,o,i)=>{r&&(this.events.unbind(e,n),this.instrumentation.callInfo(s.command,s,{error:r})),this.instrumentation.callEnd(s.command,s),t(r,o,i,e,s)};return n}publish(e,t){return this.callCommand(v,e,t)}requestService(e,t){return this.callCommand(O,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.connectionEvents.emit("connection",G.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:P,timestamp:Date.now()},"*")}catch(e){return void B(h,e)}if(!n||!n.token)return void B(h,"No message body or message token");const{error:s,status:r,token:o}=n;s?this.events.emit(o,s,n.result,r):(!function(e,t,n,s){if(t&&Object.keys(t).length)return;const r=e;!r.dataset||r.dataset.name?!r.dataset||r.dataset.type?!r.dataset||r.notifications?s||!r.dataset||Array.isArray(r.notifications)||B(h,"Key 'notifications' is not an array",void 0,n):B(h,"No key 'notifications' found in response",void 0,n):B(h,"No key 'type' found in dataset",void 0,n):B(h,"No key 'name' found in dataset",void 0,n)}(n.result,r,o,this.connectorOptions.batchResults),this.events.emit(o,null,n.result,r),(null===(t=n.result)||void 0===t?void 0:t.metadata)&&"EOF"===n.result.metadata.GetRequest&&this.events.emit(o,null,null,{message:f,code:m}))}}search(e,t){return this.callCommand(C,e,t)}sendMessage(e,t,n,s){this.connectorOptions.debugMode&&self.postMessage({request:{token:e,command:t,params:s},source:P,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){B(h,t),this.events.emit(e,t,void 0,void 0)}}stream(e,t,s){if(!this.isRunning)return s("Connection is down"),null;const r=n.v4(),o={command:e,encodedParams:$(t),token:r},i=(e,t,n,a)=>{t&&(this.events.unbind(r,i),this.instrumentation.callInfo(o.command,o,{error:t}),this.instrumentation.callEnd(e.command,e)),a&&3001===a.code&&this.instrumentation.callInfo(o.command,o,{message:"stream active"}),s(t,n,a,r,e)};return this.events.bind(r,o,i),this.sendMessageOrError(r,e,t,o),{token:r,callback:i}}}G.CONNECTED=N,G.DISCONNECTED=_;class V extends G{closeSubscriptions(e,t){return this.closeStreams(e,F(t))}getAndSubscribe(e,t,n){if(!W(e,t))return null;if(!x(n,t))return null;const s=j(n),r={query:e,start:s.start,end:s.end,versions:s.versions};return this.stream(b,r,F(t))}getApps(e){const t={types:[k]};return this.get(g,t,F(e))}getDatasets(e){const t={types:[k,A]};return this.get(g,t,F(e))}getDevices(e){const t=[A];return this.get(g,{types:t},F(e))}getWithOptions(e,t,n){if(e===y)return this.getDatasets(t),null;if(!W(e,t))return null;if(!x(n,t))return null;const{start:s,end:r,versions:o}=j(n),i={query:e,start:s,end:r,versions:o};return this.get("get",i,F(t,n))}runService(e,t){this.requestService(e,F(t))}runStreamingService(e,t){return e?this.stream(O,e,F(t)):(t("`request` param cannot be empty"),null)}searchWithOptions(e,t,n){if(!W(e,t,!0))return null;if(!x(n,t))return null;const{start:s,end:r}=j(n),o=J(n),i={query:e,start:s,end:r,search:o.search,searchType:o.searchType};return this.search(i,F(t,n))}searchSubscribe(e,t,n={search:""}){if(!W(e,t,!0))return null;const s=J(n);return this.stream(S,{query:e,search:s.search,searchType:s.searchType},F(t))}subscribe(e,t){return W(e,t)?this.stream(E,{query:e},F(t)):null}writeSync(e,t){this.publish({sync:!0,batch:{dataset:e.dataset,notifications:e.notifications}},function(e){return(t,n,s)=>{s&&s.code===m?e(!0):t&&e(!1,`Error: ${t}\n`)}}(t))}}V.CLOSE=p,V.DEVICES_DATASET_ID=y,V.GET_DATASETS=g,V.GET="get",V.GET_AND_SUBSCRIBE=b,V.ID=P,V.PUBLISH=v,V.SEARCH_SUBSCRIBE=S,V.SEARCH=C,V.SERVICE_REQUEST=O,V.SUBSCRIBE=E,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.APP_DATASET_TYPE=k,e.CONNECTED=N,e.DEVICE_DATASET_TYPE=A,e.DISCONNECTED=_,e.EOF="EOF",e.EOF_CODE=m,e.GET_REQUEST_COMPLETED=f,e.Parser=d,e.default=V,e.fromBinaryKey=function(e,n=!0){return t.decode(s.toByteArray(e),{extensionCodec:t.Codec,useJSBI:n})},e.sanitizeOptions=j,e.toBinaryKey=$,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "cloudvision-connector",
"version": "4.5.4",
"version": "4.5.5",
"description": "A module to communicate with the CloudVision API server",

@@ -53,5 +53,5 @@ "author": "extensions@arista.com",

"dependencies": {
"a-msgpack": "4.5.4",
"a-msgpack": "4.5.5",
"base64-js": "1.3.1",
"jsbi": "3.1.2",
"jsbi": "3.1.4",
"uuid": "8.3.0"

@@ -61,6 +61,6 @@ },

"@arista/prettier-config": "1.1.3",
"@rollup/plugin-commonjs": "14.0.0",
"@rollup/plugin-node-resolve": "8.4.0",
"@rollup/plugin-commonjs": "15.0.0",
"@rollup/plugin-node-resolve": "9.0.0",
"@rollup/plugin-replace": "2.3.2",
"@rollup/plugin-typescript": "4.1.2",
"@rollup/plugin-typescript": "6.0.0",
"@types/base64-js": "1.2.5",

@@ -70,25 +70,25 @@ "@types/imurmurhash": "0.1.1",

"@types/js-yaml": "3.12.4",
"@types/uuid": "8.0.1",
"@types/uuid": "8.3.0",
"cross-env": "7.0.2",
"eslint": "6.8.0",
"eslint-config-airbnb-base": "14.1.0",
"eslint-config-arista-js": "1.1.27",
"eslint-config-arista-ts": "1.1.22",
"eslint-plugin-arista": "0.1.36",
"eslint-config-arista-js": "1.1.28",
"eslint-config-arista-ts": "1.1.23",
"eslint-plugin-arista": "0.1.37",
"eslint-plugin-import": "2.22.0",
"jest": "26.2.2",
"jest": "26.4.2",
"js-yaml": "3.14.0",
"mock-socket": "9.0.3",
"prettier": "2.0.5",
"prettier": "2.1.2",
"rimraf": "3.0.2",
"rollup": "2.23.1",
"rollup-plugin-terser": "5.3.0",
"ts-jest": "26.1.4",
"rollup": "2.26.11",
"rollup-plugin-terser": "7.0.2",
"ts-jest": "26.3.0",
"tslib": "2.0.1",
"typedoc": "0.18.0",
"typedoc-neo-theme": "1.0.9",
"typedoc-plugin-markdown": "2.2.17",
"typescript": "3.9.7"
"typedoc": "0.19.1",
"typedoc-neo-theme": "1.0.10",
"typedoc-plugin-markdown": "2.4.2",
"typescript": "4.0.2"
},
"gitHead": "b83bd7e4e375363ba8e3cff8f5255b08139f79aa"
"gitHead": "6fe11c395fa562d8e1a2e2aaccbde7162114aba8"
}

@@ -265,3 +265,3 @@ # CloudVision Connector

}
)then(
).then(
(jsonResp) => {

@@ -268,0 +268,0 @@ if (jsonResp.sessionId) {

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