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.2 to 4.5.3

11

CHANGELOG.md

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

## [4.5.3](https://github.com/aristanetworks/cloudvision/compare/v4.5.2...v4.5.3) (2020-07-29)
### Bug Fixes
* **cloudvision-connector:** export needed constants and types ([#141](https://github.com/aristanetworks/cloudvision/issues/141)) ([2875718](https://github.com/aristanetworks/cloudvision/commit/2875718b62ed97ee7879f6a0e86ae66f8286fae7))
## [4.5.2](https://github.com/aristanetworks/cloudvision/compare/v4.5.1...v4.5.2) (2020-07-28)

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

4

dist/cloudvision-connector.js

@@ -1659,5 +1659,9 @@ (function (global, factory) {

exports.ACTIVE_CODE = ACTIVE_CODE;
exports.APP_DATASET_TYPE = APP_DATASET_TYPE;
exports.CONNECTED = CONNECTED;
exports.DEVICE_DATASET_TYPE = DEVICE_DATASET_TYPE;
exports.DISCONNECTED = DISCONNECTED;
exports.EOF = EOF;
exports.EOF_CODE = EOF_CODE;
exports.GET_REQUEST_COMPLETED = GET_REQUEST_COMPLETED;
exports.Parser = Parser;

@@ -1664,0 +1668,0 @@ exports.default = Connector;

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 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})}));
!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 E(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 k(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 T(e,t){return A({command:e,params:t})}function N(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 _(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 D(e){const t=e.searchType;let n="ANY";return t&&m.has(t)&&(n=t),{search:e.search||"",searchType:n}}function q(e){return n.fromByteArray(t.encode(e,{extensionCodec:t.Codec}))}class w{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=T(e,t),i={command:e,encodedParams:q(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",w.DISCONNECTED,e)}closeCommand(e,t,n){const s=T("close",t),i={command:"close",encodedParams:q(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=_(e,this.events);return n?this.closeCommand(e,n,t):null}closeStream(e,t){const n=_(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",w.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=T(e,t),i={command:e,encodedParams:q(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)}}w.CONNECTED="connected",w.DISCONNECTED="disconnected";class P extends w{closeSubscriptions(e,t){return this.closeStreams(e,N(t))}getAndSubscribe(e,t,n){if(!O(e,t))return null;if(!k(n,t))return null;const s=E(n),i={query:e,start:s.start,end:s.end,versions:s.versions};return this.stream("getAndSubscribe",i,N(t))}getApps(e){const t={types:["app"]};return this.get("getDatasets",t,N(e))}getDatasets(e){const t={types:["app","device"]};return this.get("getDatasets",t,N(e))}getDevices(e){const t=["device"];return this.get("getDatasets",{types:t},N(e))}getCommandToken(e,t){return T(e,t)}getWithOptions(e,t,n){if("DEVICES_DATASET_ID"===e)return this.getDatasets(t),null;if(!O(e,t))return null;if(!k(n,t))return null;const{start:s,end:i,versions:r}=E(n),o={query:e,start:s,end:i,versions:r};return this.get("get",o,N(t,n))}runService(e,t){this.requestService(e,N(t))}runStreamingService(e,t){return e?this.stream("serviceRequest",e,N(t)):(t("`request` param cannot be empty"),null)}searchWithOptions(e,t,n){if(!O(e,t,!0))return null;if(!k(n,t))return null;const{start:s,end:i}=E(n),r=D(n),o={query:e,start:s,end:i,search:r.search,searchType:r.searchType};return this.search(o,N(t,n))}searchSubscribe(e,t,n={search:""}){if(!O(e,t,!0))return null;const s=D(n);return this.stream("alpha/searchSubscribe",{query:e,search:s.search,searchType:s.searchType},N(t))}subscribe(e,t){return O(e,t)?this.stream("subscribe",{query:e},N(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.PAUSE="pause",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=h,e.default=P,e.fromBinaryKey=function(e,s=!0){return t.decode(n.toByteArray(e),{extensionCodec:t.Codec,useJSBI:s})},e.hashObject=A,e.sanitizeOptions=E,e.toBinaryKey=q,Object.defineProperty(e,"__esModule",{value:!0})}));

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

export default Connector;
export { ACTIVE_CODE, CONNECTED, DISCONNECTED, EOF_CODE, Parser, fromBinaryKey, hashObject, sanitizeOptions, toBinaryKey };
export { ACTIVE_CODE, APP_DATASET_TYPE, CONNECTED, DEVICE_DATASET_TYPE, DISCONNECTED, EOF, EOF_CODE, GET_REQUEST_COMPLETED, Parser, fromBinaryKey, hashObject, sanitizeOptions, toBinaryKey };

@@ -1661,5 +1661,9 @@ 'use strict';

exports.ACTIVE_CODE = ACTIVE_CODE;
exports.APP_DATASET_TYPE = APP_DATASET_TYPE;
exports.CONNECTED = CONNECTED;
exports.DEVICE_DATASET_TYPE = DEVICE_DATASET_TYPE;
exports.DISCONNECTED = DISCONNECTED;
exports.EOF = EOF;
exports.EOF_CODE = EOF_CODE;
exports.GET_REQUEST_COMPLETED = GET_REQUEST_COMPLETED;
exports.Parser = Parser;

@@ -1666,0 +1670,0 @@ exports.default = Connector;

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

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

"dependencies": {
"a-msgpack": "4.5.1",
"a-msgpack": "4.5.3",
"base64-js": "1.3.1",

@@ -83,3 +83,3 @@ "imurmurhash": "0.1.4",

"rollup-plugin-terser": "5.3.0",
"ts-jest": "26.1.3",
"ts-jest": "26.1.4",
"tslib": "2.0.0",

@@ -91,3 +91,3 @@ "typedoc": "0.17.8",

},
"gitHead": "b7aa5c5483e4f234b593e89c3c482f3907b07d6a"
"gitHead": "81855b9a1e7289dd3e6760cc576bd70af5199ef2"
}

@@ -35,3 +35,12 @@ // Copyright (c) 2018, Arista Networks, Inc.

export { default as Parser } from './Parser';
export { ACTIVE_CODE, CONNECTED, DISCONNECTED, EOF_CODE } from './constants';
export {
ACTIVE_CODE,
APP_DATASET_TYPE,
CONNECTED,
DEVICE_DATASET_TYPE,
DISCONNECTED,
EOF,
EOF_CODE,
GET_REQUEST_COMPLETED,
} from './constants';
export { fromBinaryKey, hashObject, toBinaryKey, sanitizeOptions } from './utils';
export { createBaseType, isJsbi, isNeatType, Bool, Float32, Float64, Int, NeatTypes, NeatTypeSerializer, Nil, Pointer, Str, } from 'a-msgpack';
export { default } from './Connector';
export { default as Parser } from './Parser';
export { ACTIVE_CODE, CONNECTED, DISCONNECTED, EOF_CODE } from './constants';
export { ACTIVE_CODE, APP_DATASET_TYPE, CONNECTED, DEVICE_DATASET_TYPE, DISCONNECTED, EOF, EOF_CODE, GET_REQUEST_COMPLETED, } from './constants';
export { fromBinaryKey, hashObject, toBinaryKey, sanitizeOptions } from './utils';

@@ -9,3 +9,3 @@ import { PathElements, Timestamp } from 'a-msgpack';

export interface CloudVisionStatus {
code: number;
code?: number;
message?: string;

@@ -12,0 +12,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