Socket
Socket
Sign inDemoInstall

@oada/client

Package Overview
Dependencies
Maintainers
8
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oada/client - npm Package Compare versions

Comparing version 1.1.0-alpha to 1.1.0

2

dist/client.d.ts

@@ -9,3 +9,2 @@ import { WebSocketClient } from "./websocket";

_ws?: WebSocketClient;
pingInterval?: number;
}

@@ -29,2 +28,3 @@ export declare type Response = SocketResponse;

contentType?: string;
revIfMatch?: number;
tree?: object;

@@ -31,0 +31,0 @@ timeout?: number;

@@ -24,3 +24,3 @@ "use strict";

this._concurrency = config.concurrency || this._concurrency;
this._ws = new websocket_1.WebSocketClient(this._domain, this._concurrency, config.pingInterval);
this._ws = new websocket_1.WebSocketClient(this._domain, this._concurrency);
}

@@ -139,2 +139,3 @@ clone(token) {

if (request.tree) {
let retryCount = 0;
let linkObj = null;

@@ -148,9 +149,28 @@ let newResourcePathArray = [];

const partialPath = utils.toStringPath(partialPathArray);
if (await this._resourceExists(partialPath)) {
const resourceCheckResult = await this._resourceExists(partialPath);
if (resourceCheckResult.exist) {
if (linkObj && newResourcePathArray.length > 0) {
await this.put({
const linkPutResponse = await this.put({
path: utils.toStringPath(newResourcePathArray),
contentType,
data: linkObj,
revIfMatch: 1,
}).catch((msg) => {
if (msg.status == 412) {
return msg;
}
else {
throw new Error(`Error: ${msg.statusText}`);
}
});
if (linkPutResponse.status == 412) {
if (retryCount++ < 5) {
await utils.delay(1000 * (retryCount * retryCount + Math.random()));
i = pathArray.length - 1;
continue;
}
else {
throw Error("If-match failed.");
}
}
}

@@ -181,6 +201,5 @@ break;

method: "put",
headers: {
authorization: `Bearer ${this._token}`,
"content-type": contentType,
},
headers: Object.assign({ authorization: `Bearer ${this._token}`, "content-type": contentType }, (request.revIfMatch && {
"if-match": request.revIfMatch.toString(),
})),
path: request.path,

@@ -240,4 +259,5 @@ data: request.data,

async _resourceExists(path) {
if (path === "/resources")
return true;
if (path === "/resources") {
return { exist: true };
}
const headResponse = await this.head({

@@ -257,6 +277,6 @@ path,

if (headResponse.status == 200) {
return true;
return { exist: true, rev: headResponse.headers["x-oada-rev"] };
}
else if (headResponse.status == 404) {
return false;
return { exist: false };
}

@@ -263,0 +283,0 @@ else {

@@ -7,1 +7,2 @@ export declare function toStringPath(path: Array<string>): string;

export declare function createNestedObject(obj: object, nestPath: Array<string>): object;
export declare function delay(ms: number): Promise<unknown>;

@@ -69,2 +69,6 @@ "use strict";

exports.createNestedObject = createNestedObject;
function delay(ms) {
return new Promise((_) => setTimeout(_, ms));
}
exports.delay = delay;
//# sourceMappingURL=utils.js.map

@@ -5,3 +5,3 @@ import { Json, Change } from ".";

path: string;
method: "head" | "get" | "put" | "post" | "delete" | "watch" | "unwatch" | "ping";
method: "head" | "get" | "put" | "post" | "delete" | "watch" | "unwatch";
headers: Record<string, string>;

@@ -29,10 +29,3 @@ data?: Json;

private _q;
private _pingInterval;
private _timeoutTimerID;
private _pingTimerID;
constructor(domain: string, concurrency?: number, pingInterval?: number);
private _sendPing;
private _resetReconnectTimers;
private _reconnect;
private _connect;
constructor(domain: string, concurrency?: number);
disconnect(): Promise<void>;

@@ -39,0 +32,0 @@ isConnected(): boolean;

@@ -34,36 +34,7 @@ "use strict";

class WebSocketClient {
constructor(domain, concurrency = 10, pingInterval = 60000) {
constructor(domain, concurrency = 10) {
this._domain = domain;
this._requests = new Map();
this._q = new p_queue_1.default({ concurrency });
this._q.on("active", () => {
trace(`WS Queue. Size: ${this._q.size} pending: ${this._q.pending}`);
});
this._status = ConnectionStatus.Connecting;
this._ws = this._connect();
this._pingInterval = pingInterval;
this._pingTimerID = setTimeout(this._sendPing.bind(this), this._pingInterval);
this._timeoutTimerID = setTimeout(this._reconnect.bind(this), this._pingInterval + 5000);
}
_sendPing() {
const pingRequest = {
method: "ping",
headers: { authorization: "" },
path: "",
};
this.request(pingRequest);
}
_resetReconnectTimers() {
clearTimeout(this._timeoutTimerID);
clearTimeout(this._pingTimerID);
this._pingTimerID = setTimeout(this._sendPing.bind(this), this._pingInterval);
this._timeoutTimerID = setTimeout(this._reconnect.bind(this), this._pingInterval + 5000);
}
_reconnect() {
this._ws = this._connect();
this._resetReconnectTimers();
}
_connect() {
this._status = ConnectionStatus.Connecting;
return new Promise((resolve) => {
this._ws = new Promise((resolve) => {
const ws = new WebSocket("wss://" + this._domain, {

@@ -81,2 +52,6 @@ origin: "https://" + this._domain,

});
this._q = new p_queue_1.default({ concurrency });
this._q.on("active", () => {
trace(`WS Queue. Size: ${this._q.size} pending: ${this._q.pending}`);
});
}

@@ -127,3 +102,2 @@ async disconnect() {

_receive(m) {
this._resetReconnectTimers();
try {

@@ -130,0 +104,0 @@ const msg = JSON.parse(m.data.toString());

{
"name": "@oada/client",
"version": "1.1.0-alpha",
"version": "1.1.0",
"description": "A lightweight client tool to interact with an OADA-compliant server",

@@ -20,3 +20,3 @@ "main": "dist/index.js",

"dependencies": {
"@oada/types": "^1.2.0-beta.5",
"@oada/types": "^1.0.6",
"debug": "^4.1.1",

@@ -23,0 +23,0 @@ "isomorphic-ws": "^4.0.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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