New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.10.1 to 4.11.0

56

dist/cloudvision-connector.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('a-msgpack'), require('uuid'), require('base64-js')) :
typeof define === 'function' && define.amd ? define(['exports', 'a-msgpack', 'uuid', 'base64-js'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CloudvisionConnector = {}, global.msgpack, global.uuid, global['base64-js']));
}(this, (function (exports, aMsgpack, uuid, base64Js) { 'use strict';
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CloudvisionConnector = {}, global.msgpack, global.uuid, global["base64-js"]));
})(this, (function (exports, aMsgpack, uuid, base64Js) { 'use strict';

@@ -1398,71 +1398,47 @@ /* eslint-disable @typescript-eslint/prefer-for-of */

enumerable: true,
get: function () {
return aMsgpack.Bool;
}
get: function () { return aMsgpack.Bool; }
});
Object.defineProperty(exports, 'Float32', {
enumerable: true,
get: function () {
return aMsgpack.Float32;
}
get: function () { return aMsgpack.Float32; }
});
Object.defineProperty(exports, 'Float64', {
enumerable: true,
get: function () {
return aMsgpack.Float64;
}
get: function () { return aMsgpack.Float64; }
});
Object.defineProperty(exports, 'Int', {
enumerable: true,
get: function () {
return aMsgpack.Int;
}
get: function () { return aMsgpack.Int; }
});
Object.defineProperty(exports, 'NeatTypeSerializer', {
enumerable: true,
get: function () {
return aMsgpack.NeatTypeSerializer;
}
get: function () { return aMsgpack.NeatTypeSerializer; }
});
Object.defineProperty(exports, 'NeatTypes', {
enumerable: true,
get: function () {
return aMsgpack.NeatTypes;
}
get: function () { return aMsgpack.NeatTypes; }
});
Object.defineProperty(exports, 'Nil', {
enumerable: true,
get: function () {
return aMsgpack.Nil;
}
get: function () { return aMsgpack.Nil; }
});
Object.defineProperty(exports, 'Pointer', {
enumerable: true,
get: function () {
return aMsgpack.Pointer;
}
get: function () { return aMsgpack.Pointer; }
});
Object.defineProperty(exports, 'Str', {
enumerable: true,
get: function () {
return aMsgpack.Str;
}
get: function () { return aMsgpack.Str; }
});
Object.defineProperty(exports, 'createBaseType', {
enumerable: true,
get: function () {
return aMsgpack.createBaseType;
}
get: function () { return aMsgpack.createBaseType; }
});
Object.defineProperty(exports, 'isJsbi', {
enumerable: true,
get: function () {
return aMsgpack.isJsbi;
}
get: function () { return aMsgpack.isJsbi; }
});
Object.defineProperty(exports, 'isNeatType', {
enumerable: true,
get: function () {
return aMsgpack.isNeatType;
}
get: function () { return aMsgpack.isNeatType; }
});

@@ -1489,3 +1465,3 @@ exports.ACTIVE_CODE = ACTIVE_CODE;

exports.SUBSCRIBE = SUBSCRIBE;
exports['default'] = Connector;
exports["default"] = Connector;
exports.fromBinaryKey = fromBinaryKey;

@@ -1497,2 +1473,2 @@ exports.sanitizeOptions = sanitizeOptions;

})));
}));

@@ -1400,71 +1400,47 @@ 'use strict';

enumerable: true,
get: function () {
return aMsgpack.Bool;
}
get: function () { return aMsgpack.Bool; }
});
Object.defineProperty(exports, 'Float32', {
enumerable: true,
get: function () {
return aMsgpack.Float32;
}
get: function () { return aMsgpack.Float32; }
});
Object.defineProperty(exports, 'Float64', {
enumerable: true,
get: function () {
return aMsgpack.Float64;
}
get: function () { return aMsgpack.Float64; }
});
Object.defineProperty(exports, 'Int', {
enumerable: true,
get: function () {
return aMsgpack.Int;
}
get: function () { return aMsgpack.Int; }
});
Object.defineProperty(exports, 'NeatTypeSerializer', {
enumerable: true,
get: function () {
return aMsgpack.NeatTypeSerializer;
}
get: function () { return aMsgpack.NeatTypeSerializer; }
});
Object.defineProperty(exports, 'NeatTypes', {
enumerable: true,
get: function () {
return aMsgpack.NeatTypes;
}
get: function () { return aMsgpack.NeatTypes; }
});
Object.defineProperty(exports, 'Nil', {
enumerable: true,
get: function () {
return aMsgpack.Nil;
}
get: function () { return aMsgpack.Nil; }
});
Object.defineProperty(exports, 'Pointer', {
enumerable: true,
get: function () {
return aMsgpack.Pointer;
}
get: function () { return aMsgpack.Pointer; }
});
Object.defineProperty(exports, 'Str', {
enumerable: true,
get: function () {
return aMsgpack.Str;
}
get: function () { return aMsgpack.Str; }
});
Object.defineProperty(exports, 'createBaseType', {
enumerable: true,
get: function () {
return aMsgpack.createBaseType;
}
get: function () { return aMsgpack.createBaseType; }
});
Object.defineProperty(exports, 'isJsbi', {
enumerable: true,
get: function () {
return aMsgpack.isJsbi;
}
get: function () { return aMsgpack.isJsbi; }
});
Object.defineProperty(exports, 'isNeatType', {
enumerable: true,
get: function () {
return aMsgpack.isNeatType;
}
get: function () { return aMsgpack.isNeatType; }
});

@@ -1491,5 +1467,5 @@ exports.ACTIVE_CODE = ACTIVE_CODE;

exports.SUBSCRIBE = SUBSCRIBE;
exports['default'] = Connector;
exports["default"] = Connector;
exports.fromBinaryKey = fromBinaryKey;
exports.sanitizeOptions = sanitizeOptions;
exports.toBinaryKey = toBinaryKey;
{
"name": "cloudvision-connector",
"version": "4.10.1",
"version": "4.11.0",
"description": "A module to communicate with the CloudVision API server",

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

"dependencies": {
"a-msgpack": "4.10.1",
"a-msgpack": "4.11.0",
"base64-js": "1.5.1",
"jsbi": "3.2.4",
"jsbi": "3.2.5",
"uuid": "8.3.2"

@@ -66,3 +66,3 @@ },

"@rollup/plugin-commonjs": "20.0.0",
"@rollup/plugin-node-resolve": "13.0.4",
"@rollup/plugin-node-resolve": "13.0.5",
"@rollup/plugin-replace": "3.0.0",

@@ -72,7 +72,7 @@ "@rollup/plugin-typescript": "8.2.5",

"@types/imurmurhash": "0.1.1",
"@types/jest": "27.0.1",
"@types/jest": "27.0.2",
"@types/js-yaml": "4.0.3",
"@types/uuid": "8.3.1",
"@typescript-eslint/eslint-plugin": "4.31.1",
"@typescript-eslint/parser": "4.31.1",
"@typescript-eslint/eslint-plugin": "4.32.0",
"@typescript-eslint/parser": "4.32.0",
"babel-eslint": "10.1.0",

@@ -82,12 +82,12 @@ "cross-env": "7.0.3",

"eslint-config-arista-js": "2.0.1",
"eslint-config-arista-ts": "2.0.0",
"eslint-config-arista-ts": "2.0.1",
"eslint-plugin-arista": "0.2.2",
"eslint-plugin-import": "2.23.4",
"jest": "27.2.0",
"jest-environment-jsdom": "27.2.0",
"jest": "27.2.4",
"jest-environment-jsdom": "27.2.4",
"js-yaml": "4.1.0",
"mock-socket": "9.0.3",
"mock-socket": "9.0.5",
"prettier": "2.4.1",
"rimraf": "3.0.2",
"rollup": "2.56.3",
"rollup": "2.58.0",
"rollup-plugin-terser": "7.0.2",

@@ -99,5 +99,5 @@ "ts-jest": "27.0.5",

"typedoc-plugin-markdown": "3.1.1",
"typescript": "4.3.5"
"typescript": "4.4.3"
},
"gitHead": "1f8ec56ecf2cb2198e2a12004031166acf916562"
"gitHead": "154739fb83ceb96aa20e2e9f5d6cfb4a7932052d"
}
# CloudVision Connector
The CloudVision Connector is a simple JavaScript module using WebSockets that enables you to transmit data over an open connection with the CloudVision API server. The CloudVision Connector supports subscribing to data, which lets clients receive streaming updates as data changes in real-time.
The CloudVision Connector is a simple JavaScript module using WebSockets that enables you to
transmit data over an open connection with the CloudVision API server. The CloudVision Connector
supports subscribing to data, which lets clients receive streaming updates as data changes in
real-time.

@@ -26,2 +29,3 @@ ## Installation

#### Getting Datasets
```js

@@ -42,3 +46,5 @@ const parseDatasets = (err, datasets) => {...};

You can also get datasets use `getWithOptions` (see details below). This is done by calling `getWithOptions` with `Connector.DEVICES_DATASET_ID` as the first parameter.
You can also get datasets use `getWithOptions` (see details below). This is done by calling
`getWithOptions` with `Connector.DEVICES_DATASET_ID` as the first parameter.
```js

@@ -52,12 +58,17 @@ const parseDevices = (err, datasets) => {...};

#### Getting Data
The CloudVision Connector allows you to query notifications for multiple paths on a dataset, as well as multiple paths within multiple datasets.
The CloudVision Connector allows you to query notifications for multiple paths on a dataset, as well
as multiple paths within multiple datasets.
##### getWithOptions(query, callback, options)
Returns all notifications that match the given query and options.
- `query`: an object in the shape of a query (see "Query")
- `callback`: a function that is called when notifications are received (see "Notifications Callback")
- `options`: an object in the shape of query options (see "Options")
- **Returns**: the token (unique identifier) of the request.
- `query`: an object in the shape of a query (see "Query")
- `callback`: a function that is called when notifications are received (see "Notifications Callback")
- `options`: an object in the shape of query options (see "Options")
- **Returns**: the token (unique identifier) of the request.
##### Example
```js

@@ -94,13 +105,18 @@ const query = [{

#### Subscribing to Data
In addition to getting data, you can use the same query to subscribe to any updates to the data as it changes.
In addition to getting data, you can use the same query to subscribe to any updates to the data as
it changes.
##### getAndSubscribe(query, callback, options)
Returns all notifications that match the given query and options, in addition to subscribing to updates. This will return notifications as new updates to the data requested come in.
- `query`: an object in the shape of a query (see "Query")
- `callback`: a function that is called when notifications are received (see "Notifications Callback")
- `options`: an object in the shape of query options (see "Options")
- **Returns**: a the subscription identifier. This is an object constaining the token and the callback
Returns all notifications that match the given query and options, in addition to subscribing to
updates. This will return notifications as new updates to the data requested come in.
- `query`: an object in the shape of a query (see "Query")
- `callback`: a function that is called when notifications are received (see "Notifications Callback")
- `options`: an object in the shape of query options (see "Options")
- **Returns**: a the subscription identifier. This is an object constaining the token and the callback
##### Example
```js

@@ -133,2 +149,3 @@ const query = [{

#### Notifications Callback
This is the callback, which is called when notifications are received.

@@ -141,5 +158,6 @@

Arguments:
- `err`: either a string or `null`. If `null` then there is no error. If it is a string, then an error occurred.
- `res`: an object with the properties `dataset` and `notifications`.
e.g.
- `err`: either a string or `null`. If `null` then there is no error. If it is a string, then an error occurred.
- `res`: an object with the properties `dataset` and `notifications`. e.g.
```js

@@ -155,36 +173,52 @@ res = {

```
Each `[...]` above is an array of notifications which each have a `timestamp`, `path`, collection of `updates`, and `deletes` (see "Data Model" section for more information).
- status: An object with the status code and a message. See the "Notification Statuses" section for more details.
- `token`: The token id that was created for the request.
Each `[...]` above is an array of notifications which each have a `timestamp`, `path`, collection of
`updates`, and `deletes` (see "Data Model" section for more information).
- status: An object with the status code and a message. See the "Notification Statuses" section for more details.
- `token`: The token id that was created for the request.
#### Notification Statuses
A status object has an optional `message` key containing a string describing the status, in addition to a `code` key with the code number.
Possible status codes:
|Code|JS Constant|Description|
|1001|EOF_CODE|Signals that this is the last notification for the request|
|3001|ACTIVE_CODE|Signals that the stream (subscription), has been established|
A status object has an optional `message` key containing a string describing the status, in addition
to a `code` key with the code number.
Possible status codes: |Code|JS Constant|Description| |1001|EOF_CODE|Signals that this is the last
notification for the request| |3001|ACTIVE_CODE|Signals that the stream (subscription), has been
established|
#### Options
There are a number of options you can supply to the query which limit it's scope. Options are passed as an object, where the **key** is the name of the option and the **value** is the value for that option.
The options are `start`, `end` and `versions`. There are different combinations of options that are valid, each of them is listed below.
There are a number of options you can supply to the query which limit it's scope. Options are passed
as an object, where the **key** is the name of the option and the **value** is the value for that
option.
The options are `start`, `end` and `versions`. There are different combinations of options that are
valid, each of them is listed below.
Range query (returns one or more data points):
- `start`: the epoch timestamp in (milliseconds) of the first data point.
- `end`: the epoch timestamp in (milliseconds) of the last data point.
- `start`: the epoch timestamp in (milliseconds) of the first data point.
- `end`: the epoch timestamp in (milliseconds) of the last data point.
Point in time query (returns exactly one data point):
- `end`: the epoch timestamp in (milliseconds) of the data point.
- `end`: the epoch timestamp in (milliseconds) of the data point.
Limit query (returns `versions` + 1 number of data points):
- `end`: the epoch timestamp in (milliseconds) of the last data point.
- `versions`: the number of versions of data (in the past) to request in addition to the data point for `end`.
- `end`: the epoch timestamp in (milliseconds) of the last data point.
- `versions`: the number of versions of data (in the past) to request in addition to the data point for `end`.
#### Query
A query is an array of objects with a **dataset** key and **paths** key.
The value of each **dataset** is an object with a **type** (the type of the dataset, which can be **device** or **app**) and **name** (the identifier for the dataset e.g. 'JPE13262133') key.
The value of each **dataset** is an object with a **type** (the type of the dataset, which can be
**device** or **app**) and **name** (the identifier for the dataset e.g. 'JPE13262133') key.
The value of the **paths** key is an array of objects with a **path_elements** (an array of the component parts of a path) key and an optional **keys** key. The value of **keys** is an object that defines the shape of how you want the data to be returned. Think of it like a map that points to certain fields in CloudVision api.
The value of the **paths** key is an array of objects with a **path_elements** (an array of the
component parts of a path) key and an optional **keys** key. The value of **keys** is an object that
defines the shape of how you want the data to be returned. Think of it like a map that points to
certain fields in CloudVision api.

@@ -211,2 +245,3 @@ ```js

##### Example
```js

@@ -243,7 +278,12 @@ const handleResponse = (err, res) => {...};

#### Connecting to the Server
You can connect to the CloudVision API server with any kind of WebSocket. This connector uses the regular browser WebSocket, but it also allows you to pass in your own custom implementation of a standard WebSocket.
You can also connect via secure WebSockets (`wss`), which uses the same SSL certificate as `https` does.
You can connect to the CloudVision API server with any kind of WebSocket. This connector uses the
regular browser WebSocket, but it also allows you to pass in your own custom implementation of a
standard WebSocket.
You can also connect via secure WebSockets (`wss`), which uses the same SSL certificate as `https`
does.
If you are using wss, you will need to get the authentication cookie from the CVP auth service.
```js

@@ -262,16 +302,13 @@ const authUrl = 'https://example.cloudvision.api-server/cvpservice/login/authenticate.do';

window.fetch(
authUrl,
{
window
.fetch(authUrl, {
method: 'POST',
credentials: 'include',
body: JSON.stringify({ userId, password }),
}
).then(
(response) => {
})
.then((response) => {
// Handle JSON response
return response.json();
}
).then(
(jsonResp) => {
})
.then((jsonResp) => {
if (jsonResp.sessionId) {

@@ -284,9 +321,11 @@ // We got a session id, so we are now logged in

}
}
).catch(
})
.catch
// Error handling for failed request
);
();
```
Once you have completed this request successfully, you will have the authentication cookie which will be sent along with the request to open the WebSocket.
Once you have completed this request successfully, you will have the authentication cookie which
will be sent along with the request to open the WebSocket.
```js

@@ -315,8 +354,15 @@ // Import module

#### Listening to the Connection Status
The `Connector.connection` function adds a status-accepting callback to a `Connector` and returns an unbinding function that may be used to remove the callback. The status passed to the callback is either `Connector.CONNECTED`, or `Connector.DISCONNECTED`. Additionally, the WebSocket event (see WebSocket documentation) is passed as the second argument.
- `Connector.CONNECTED` is emitted once the WebSocket connection has been established and the client is authenticated. At this point requests can be sent and the server will start sending responses.
The `Connector.connection` function adds a status-accepting callback to a `Connector` and returns an
unbinding function that may be used to remove the callback. The status passed to the callback is
either `Connector.CONNECTED`, or `Connector.DISCONNECTED`. Additionally, the WebSocket event (see
WebSocket documentation) is passed as the second argument.
- `Connector.CONNECTED` is emitted once the WebSocket connection has been established and the client
is authenticated. At this point requests can be sent and the server will start sending responses.
- `Connector.DISCONNECTED` is emitted when the WebSocket is hung up.
##### Example
```js

@@ -354,9 +400,21 @@ function statusCallback(status, wsEvent) {

## Data Endcoding
Data returned from the CloudVision APi is both JSON and NEAT (more strict MessagePack) encoded. Additionally NEAT encoded values are base64 encoded for transport. The notification body is JSON encoded, while `key` and `value` attributes of the notification are NEAT encoded. The parser inside the cloudvision-connector library takes care of decoding and encoding notifications for you. Note that when notifications are decoded they are decoded into an object keyed key the notification key. Since keys can be non strings, the key is the base64 NEAT encoded value. The value of this object contains both the decoded `key` and `value`.
Data returned from the CloudVision APi is both JSON and NEAT (more strict MessagePack) encoded.
Additionally NEAT encoded values are base64 encoded for transport. The notification body is JSON
encoded, while `key` and `value` attributes of the notification are NEAT encoded. The parser inside
the cloudvision-connector library takes care of decoding and encoding notifications for you. Note
that when notifications are decoded they are decoded into an object keyed key the notification key.
Since keys can be non strings, the key is the base64 NEAT encoded value. The value of this object
contains both the decoded `key` and `value`.
## What is NEAT?
NEAT is MessagePack with some alterations listed below:
- All strings are binary encoded
- Maps and Object keys are encoded in order of binary value of the key. This means `{ a: 'b', c: 'd' }` and `{ c: 'd', a: 'b' }` are encoded as the same NEAT value.
- Support for pointer values via the `Pointer` extention type
- Support for wildcard values via the `Wildcard` extention type

@@ -371,23 +429,26 @@

```
at the root
and then
```shell
npm run build:try
```
in the **packages/cloudvision-connector** directory
Then open **index.html** in your browser. In the developer console
CloudVision Connector will be available as **window.CloudVisionConnector**.
Then open **index.html** in your browser. In the developer console CloudVision Connector will be
available as **window.CloudVisionConnector**.
### Examples
Create the connector: `conn = new window.CloudVisionConnector()`
Connect to an API server: `conn.run('ws://example.cloudvision.api-server/api/v3/wrpc/')`
Run a query: `conn.getWithOptions(window.CloudVisionConnector.DEVICES_DATASET_ID
, (err, res) => console.log(err, res))`
Create the connector: `conn = new window.CloudVisionConnector()` Connect to an API server:
`conn.run('ws://example.cloudvision.api-server/api/v3/wrpc/')` Run a query:
`conn.getWithOptions(window.CloudVisionConnector.DEVICES_DATASET_ID , (err, res) => console.log(err, res))`
## Contributing
Contributing pull requests are welcomed for this repository. Please note that all contributions require 100% code test cases and 100% code coverage, otherwise the pull request will be rejected.
Contributing pull requests are welcomed for this repository. Please note that all contributions
require 100% code test cases and 100% code coverage, otherwise the pull request will be rejected.

@@ -394,0 +455,0 @@ ## License

@@ -193,4 +193,4 @@ // Copyright (c) 2018, Arista Networks, Inc.

} catch (err) {
log(ERROR, err);
callback(err, undefined, undefined, closeToken);
log(ERROR, err as string);
callback(err as string, undefined, undefined, closeToken);
}

@@ -347,3 +347,3 @@ return closeToken;

} catch (err) {
log(ERROR, err);
log(ERROR, err as string);
return;

@@ -424,3 +424,3 @@ }

} catch (err) {
log(ERROR, err);
log(ERROR, err as string);
// notifAndUnBindCallback(err, undefined, undefined, token);

@@ -427,0 +427,0 @@ this.events.emit(token, err, undefined, undefined);

@@ -30,3 +30,3 @@ import { CloudVisionParams, CloudVisionPublishRequest, ConnectionCallback, GetCommand, NotifCallback, ServiceRequest, StreamCommand, SubscriptionIdentifier } from '../types';

constructor(options?: ConnectorOptions, websocketClass?: {
new (url: string, protocols?: string | string[] | undefined): WebSocket;
new (url: string | URL, protocols?: string | string[] | undefined): WebSocket;
prototype: WebSocket;

@@ -33,0 +33,0 @@ readonly CLOSED: number;

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