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.6.5 to 4.7.0

11

CHANGELOG.md

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

# [4.7.0](https://github.com/aristanetworks/cloudvision/compare/v4.6.5...v4.7.0) (2021-03-08)
### Features
* **connector:** add GET_REGIONS_AND_CLUSTERS method ([#366](https://github.com/aristanetworks/cloudvision/issues/366)) ([c26369c](https://github.com/aristanetworks/cloudvision/commit/c26369c536d5910ecc772e1f2f7a7db1132cf227))
## [4.6.5](https://github.com/aristanetworks/cloudvision/compare/v4.6.4...v4.6.5) (2021-01-20)

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

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

const GET_AND_SUBSCRIBE = 'getAndSubscribe';
const GET_REGIONS_AND_CLUSTERS = 'getRegionsAndClusters';
const PUBLISH = 'publish';

@@ -1248,2 +1249,8 @@ const SUBSCRIBE = 'subscribe';

/**
* Returns a list of regions and associated clusters.
*/
getRegionsAndClusters(callback) {
return this.get(GET_REGIONS_AND_CLUSTERS, {}, makeNotifCallback(callback));
}
/**
* Returns all notifications that match the given query and options.

@@ -1250,0 +1257,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=1001,f="GetRequest",p="close",y="DEVICES_DATASET_ID",g="get",b="getDatasets",E="getAndSubscribe",v="publish",C="subscribe",S="alpha/search",A="alpha/searchSubscribe",O="serviceRequest",T="app",k="config",_="device",N=[T,k,_],P=new Set(["ANY","IP","MAC"]),D="connected",I="disconnected",R="cloudvision-connector",B={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)||B;n[s](r,...t)}}close(){this.events.clear(),this.requestContext.clear()}}function w(){}class M{constructor(e){this.enableInstrumentation=!1,e&&(this.enableInstrumentation=!0),this.instrumentedCommands=e?e.commands:[],this.startFunction=e?e.start:w,this.infoFunction=e?e.info:w,this.endFunction=e?e.end:w}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 j(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 x(e){return"number"==typeof e&&e>0}function U(e){return e/1e15>1}function W(e){const{start:t,end:n,versions:s}=e;let r,o,i;return x(t)&&(r=Math.floor(t)*(U(t)?1:1e6)),x(n)&&(o=Math.floor(n)*(U(n)?1:1e6)),x(s)&&(i=Math.floor(s)),{start:r,end:o,versions:i}}function F(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 $(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 G(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 J(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 L(e){const t=e.searchType;let n="ANY";return t&&P.has(t)&&(n=t),{search:e.search||"",searchType:n}}function V(e){return s.fromByteArray(t.encode(e,{extensionCodec:t.Codec}))}class H{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 M(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:V(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",H.DISCONNECTED,e)}closeCommand(e,t,s){const r=n.v4(),o={command:p,encodedParams:V(e),token:r},i=this.makeCallbackWithUnbind(r,s);this.events.bind(r,o,i);try{this.sendMessage(r,p,o,t)}catch(e){j(h,e),s(e,void 0,void 0,r)}return r}closeStreams(e,t){const n=J(e,this.events);return n?this.closeCommand(e,n,t):null}closeStream(e,t){const n=J(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",H.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:R,timestamp:Date.now()},"*")}catch(e){return void j(h,e)}if(!n||!n.token)return void j(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)||j(h,"Key 'notifications' is not an array",void 0,n):j(h,"No key 'notifications' found in response",void 0,n):j(h,"No key 'type' found in dataset",void 0,n):j(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(S,e,t)}sendMessage(e,t,n,s){this.connectorOptions.debugMode&&self.postMessage({request:{token:e,command:t,params:s},source:R,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){j(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:V(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}}}H.CONNECTED=D,H.DISCONNECTED=I;class Y extends H{closeSubscriptions(e,t){return this.closeStreams(e,G(t))}getAndSubscribe(e,t,n){if(!$(e,t))return null;if(!F(n,t))return null;const s=W(n),r={query:e,start:s.start,end:s.end,versions:s.versions};return this.stream(E,r,G(t))}getApps(e){const t={types:[T]};return this.get(b,t,G(e))}getConfigs(e){const t={types:[k]};return this.get(b,t,G(e))}getDatasets(e){const t={types:N};return this.get(b,t,G(e))}getDevices(e){const t={types:[_]};return this.get(b,t,G(e))}getWithOptions(e,t,n){if(e===y)return this.getDatasets(t),null;if(!$(e,t))return null;if(!F(n,t))return null;const{start:s,end:r,versions:o}=W(n),i={query:e,start:s,end:r,versions:o};return this.get(g,i,G(t,n))}runService(e,t){this.requestService(e,G(t))}runStreamingService(e,t){return e?this.stream(O,e,G(t)):(t("`request` param cannot be empty"),null)}searchWithOptions(e,t,n){if(!$(e,t,!0))return null;if(!F(n,t))return null;const{start:s,end:r}=W(n),o=L(n),i={query:e,start:s,end:r,search:o.search,searchType:o.searchType};return this.search(i,G(t,n))}searchSubscribe(e,t,n={search:""}){if(!$(e,t,!0))return null;const s=L(n);return this.stream(A,{query:e,search:s.search,searchType:s.searchType},G(t))}subscribe(e,t){return $(e,t)?this.stream(C,{query:e},G(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))}}Y.CLOSE=p,Y.DEVICES_DATASET_ID=y,Y.GET_DATASETS=b,Y.GET=g,Y.GET_AND_SUBSCRIBE=E,Y.ID=R,Y.PUBLISH=v,Y.SEARCH_SUBSCRIBE=A,Y.SEARCH=S,Y.SERVICE_REQUEST=O,Y.SUBSCRIBE=C,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.ALL_DATASET_TYPES=N,e.APP_DATASET_TYPE=T,e.CLOSE=p,e.CONFIG_DATASET_TYPE=k,e.CONNECTED=D,e.DEVICE_DATASET_TYPE=_,e.DISCONNECTED=I,e.EOF="EOF",e.EOF_CODE=m,e.GET=g,e.GET_AND_SUBSCRIBE=E,e.GET_DATASETS=b,e.GET_REQUEST_COMPLETED=f,e.PUBLISH=v,e.Parser=d,e.SEARCH=S,e.SEARCH_SUBSCRIBE=A,e.SERVICE_REQUEST=O,e.SUBSCRIBE=C,e.default=Y,e.fromBinaryKey=function(e,n=!0){return t.decode(s.toByteArray(e),{extensionCodec:t.Codec,useJSBI:n})},e.sanitizeOptions=W,e.toBinaryKey=V,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="get",b="getDatasets",E="getAndSubscribe",v="publish",C="subscribe",S="alpha/search",A="alpha/searchSubscribe",O="serviceRequest",T="app",k="config",_="device",N=[T,k,_],P=new Set(["ANY","IP","MAC"]),D="connected",I="disconnected",R="cloudvision-connector",B={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)||B;n[s](r,...t)}}close(){this.events.clear(),this.requestContext.clear()}}function w(){}class M{constructor(e){this.enableInstrumentation=!1,e&&(this.enableInstrumentation=!0),this.instrumentedCommands=e?e.commands:[],this.startFunction=e?e.start:w,this.infoFunction=e?e.info:w,this.endFunction=e?e.end:w}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 j(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 x(e){return"number"==typeof e&&e>0}function U(e){return e/1e15>1}function W(e){const{start:t,end:n,versions:s}=e;let r,o,i;return x(t)&&(r=Math.floor(t)*(U(t)?1:1e6)),x(n)&&(o=Math.floor(n)*(U(n)?1:1e6)),x(s)&&(i=Math.floor(s)),{start:r,end:o,versions:i}}function F(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 $(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 G(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 J(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 L(e){const t=e.searchType;let n="ANY";return t&&P.has(t)&&(n=t),{search:e.search||"",searchType:n}}function V(e){return s.fromByteArray(t.encode(e,{extensionCodec:t.Codec}))}class H{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 M(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:V(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",H.DISCONNECTED,e)}closeCommand(e,t,s){const r=n.v4(),o={command:p,encodedParams:V(e),token:r},i=this.makeCallbackWithUnbind(r,s);this.events.bind(r,o,i);try{this.sendMessage(r,p,o,t)}catch(e){j(h,e),s(e,void 0,void 0,r)}return r}closeStreams(e,t){const n=J(e,this.events);return n?this.closeCommand(e,n,t):null}closeStream(e,t){const n=J(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",H.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:R,timestamp:Date.now()},"*")}catch(e){return void j(h,e)}if(!n||!n.token)return void j(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)||j(h,"Key 'notifications' is not an array",void 0,n):j(h,"No key 'notifications' found in response",void 0,n):j(h,"No key 'type' found in dataset",void 0,n):j(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(S,e,t)}sendMessage(e,t,n,s){this.connectorOptions.debugMode&&self.postMessage({request:{token:e,command:t,params:s},source:R,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){j(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:V(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}}}H.CONNECTED=D,H.DISCONNECTED=I;class Y extends H{closeSubscriptions(e,t){return this.closeStreams(e,G(t))}getAndSubscribe(e,t,n){if(!$(e,t))return null;if(!F(n,t))return null;const s=W(n),r={query:e,start:s.start,end:s.end,versions:s.versions};return this.stream(E,r,G(t))}getApps(e){const t={types:[T]};return this.get(b,t,G(e))}getConfigs(e){const t={types:[k]};return this.get(b,t,G(e))}getDatasets(e){const t={types:N};return this.get(b,t,G(e))}getDevices(e){const t={types:[_]};return this.get(b,t,G(e))}getRegionsAndClusters(e){return this.get("getRegionsAndClusters",{},G(e))}getWithOptions(e,t,n){if(e===y)return this.getDatasets(t),null;if(!$(e,t))return null;if(!F(n,t))return null;const{start:s,end:r,versions:o}=W(n),i={query:e,start:s,end:r,versions:o};return this.get(g,i,G(t,n))}runService(e,t){this.requestService(e,G(t))}runStreamingService(e,t){return e?this.stream(O,e,G(t)):(t("`request` param cannot be empty"),null)}searchWithOptions(e,t,n){if(!$(e,t,!0))return null;if(!F(n,t))return null;const{start:s,end:r}=W(n),o=L(n),i={query:e,start:s,end:r,search:o.search,searchType:o.searchType};return this.search(i,G(t,n))}searchSubscribe(e,t,n={search:""}){if(!$(e,t,!0))return null;const s=L(n);return this.stream(A,{query:e,search:s.search,searchType:s.searchType},G(t))}subscribe(e,t){return $(e,t)?this.stream(C,{query:e},G(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))}}Y.CLOSE=p,Y.DEVICES_DATASET_ID=y,Y.GET_DATASETS=b,Y.GET=g,Y.GET_AND_SUBSCRIBE=E,Y.ID=R,Y.PUBLISH=v,Y.SEARCH_SUBSCRIBE=A,Y.SEARCH=S,Y.SERVICE_REQUEST=O,Y.SUBSCRIBE=C,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.ALL_DATASET_TYPES=N,e.APP_DATASET_TYPE=T,e.CLOSE=p,e.CONFIG_DATASET_TYPE=k,e.CONNECTED=D,e.DEVICE_DATASET_TYPE=_,e.DISCONNECTED=I,e.EOF="EOF",e.EOF_CODE=m,e.GET=g,e.GET_AND_SUBSCRIBE=E,e.GET_DATASETS=b,e.GET_REQUEST_COMPLETED=f,e.PUBLISH=v,e.Parser=d,e.SEARCH=S,e.SEARCH_SUBSCRIBE=A,e.SERVICE_REQUEST=O,e.SUBSCRIBE=C,e.default=Y,e.fromBinaryKey=function(e,n=!0){return t.decode(s.toByteArray(e),{extensionCodec:t.Codec,useJSBI:n})},e.sanitizeOptions=W,e.toBinaryKey=V,Object.defineProperty(e,"__esModule",{value:!0})}));

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

const GET_AND_SUBSCRIBE = 'getAndSubscribe';
const GET_REGIONS_AND_CLUSTERS = 'getRegionsAndClusters';
const PUBLISH = 'publish';

@@ -1247,2 +1248,8 @@ const SUBSCRIBE = 'subscribe';

/**
* Returns a list of regions and associated clusters.
*/
getRegionsAndClusters(callback) {
return this.get(GET_REGIONS_AND_CLUSTERS, {}, makeNotifCallback(callback));
}
/**
* Returns all notifications that match the given query and options.

@@ -1249,0 +1256,0 @@ *

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

const GET_AND_SUBSCRIBE = 'getAndSubscribe';
const GET_REGIONS_AND_CLUSTERS = 'getRegionsAndClusters';
const PUBLISH = 'publish';

@@ -1250,2 +1251,8 @@ const SUBSCRIBE = 'subscribe';

/**
* Returns a list of regions and associated clusters.
*/
getRegionsAndClusters(callback) {
return this.get(GET_REGIONS_AND_CLUSTERS, {}, makeNotifCallback(callback));
}
/**
* Returns all notifications that match the given query and options.

@@ -1252,0 +1259,0 @@ *

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

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

"dependencies": {
"a-msgpack": "4.6.5",
"a-msgpack": "4.7.0",
"base64-js": "1.5.1",

@@ -65,6 +65,6 @@ "jsbi": "3.1.4",

"@arista/prettier-config": "1.1.4",
"@rollup/plugin-commonjs": "17.0.0",
"@rollup/plugin-node-resolve": "11.1.0",
"@rollup/plugin-commonjs": "17.1.0",
"@rollup/plugin-node-resolve": "11.2.0",
"@rollup/plugin-replace": "2.3.4",
"@rollup/plugin-typescript": "8.1.0",
"@rollup/plugin-typescript": "8.2.0",
"@types/base64-js": "1.3.0",

@@ -78,5 +78,5 @@ "@types/imurmurhash": "0.1.1",

"eslint-config-airbnb-base": "14.2.1",
"eslint-config-arista-js": "1.1.35",
"eslint-config-arista-ts": "1.4.5",
"eslint-plugin-arista": "0.1.44",
"eslint-config-arista-js": "1.1.36",
"eslint-config-arista-ts": "1.4.6",
"eslint-plugin-arista": "0.1.45",
"eslint-plugin-import": "2.22.1",

@@ -88,5 +88,5 @@ "jest": "26.6.3",

"rimraf": "3.0.2",
"rollup": "2.37.0",
"rollup": "2.40.0",
"rollup-plugin-terser": "7.0.2",
"ts-jest": "26.4.4",
"ts-jest": "26.5.3",
"tslib": "2.1.0",

@@ -96,5 +96,5 @@ "typedoc": "0.19.2",

"typedoc-plugin-markdown": "3.1.1",
"typescript": "4.1.3"
"typescript": "4.2.3"
},
"gitHead": "0e3485561e6ed10dc80244316f32b9c513e4d5b1"
"gitHead": "aeb322bccdbbf904fdf84c292bc160cb662119a1"
}

@@ -26,2 +26,3 @@ import {

GET_DATASETS,
GET_REGIONS_AND_CLUSTERS,
ID,

@@ -201,2 +202,9 @@ PUBLISH,

/**
* Returns a list of regions and associated clusters.
*/
public getRegionsAndClusters(callback: NotifCallback): string | null {
return this.get(GET_REGIONS_AND_CLUSTERS, {}, makeNotifCallback(callback));
}
/**
* Returns all notifications that match the given query and options.

@@ -203,0 +211,0 @@ *

@@ -48,2 +48,3 @@ // Copyright (c) 2018, Arista Networks, Inc.

export const GET_AND_SUBSCRIBE = 'getAndSubscribe';
export const GET_REGIONS_AND_CLUSTERS = 'getRegionsAndClusters';
export const PUBLISH = 'publish';

@@ -50,0 +51,0 @@ export const SUBSCRIBE = 'subscribe';

@@ -102,2 +102,6 @@ import { NotifCallback, Options, PublishCallback, PublishRequest, Query, SearchOptions, ServiceRequest, SubscriptionIdentifier } from '../types';

/**
* Returns a list of regions and associated clusters.
*/
getRegionsAndClusters(callback: NotifCallback): string | null;
/**
* Returns all notifications that match the given query and options.

@@ -104,0 +108,0 @@ *

@@ -24,2 +24,3 @@ import { RequestContext, SearchType } from '../types';

export declare const GET_AND_SUBSCRIBE = "getAndSubscribe";
export declare const GET_REGIONS_AND_CLUSTERS = "getRegionsAndClusters";
export declare const PUBLISH = "publish";

@@ -26,0 +27,0 @@ export declare const SUBSCRIBE = "subscribe";

import { NeatType, PathElements } from 'a-msgpack';
import { CLOSE, GET, GET_AND_SUBSCRIBE, GET_DATASETS, PUBLISH, SEARCH, SEARCH_SUBSCRIBE, SEARCH_TYPE_ANY, SEARCH_TYPE_IP, SEARCH_TYPE_MAC, SERVICE_REQUEST, SUBSCRIBE } from '../src/constants';
export declare type GetCommand = typeof GET | typeof GET_DATASETS | typeof SEARCH;
import { CLOSE, GET, GET_AND_SUBSCRIBE, GET_DATASETS, GET_REGIONS_AND_CLUSTERS, PUBLISH, SEARCH, SEARCH_SUBSCRIBE, SEARCH_TYPE_ANY, SEARCH_TYPE_IP, SEARCH_TYPE_MAC, SERVICE_REQUEST, SUBSCRIBE } from '../src/constants';
export declare type GetCommand = typeof GET | typeof GET_DATASETS | typeof GET_REGIONS_AND_CLUSTERS | typeof SEARCH;
/** @deprecated: Use `GetCommand`. */

@@ -5,0 +5,0 @@ export declare type GetCommands = GetCommand;

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