Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@oada/client

Package Overview
Dependencies
Maintainers
8
Versions
77
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 2.3.1 to 2.4.0

dist/fetch.d.ts

3

dist/http.d.ts

@@ -10,2 +10,5 @@ /// <reference types="node" />

private initialConnection;
private concurrency;
private context;
private ws?;
constructor(domain: string, token: string, concurrency?: number);

@@ -12,0 +15,0 @@ disconnect(): Promise<void>;

52

dist/http.js
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -6,3 +13,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
const cross_fetch_1 = __importDefault(require("cross-fetch"));
const fetch_1 = __importStar(require("./fetch"));
const events_1 = require("events");

@@ -12,2 +19,3 @@ const ksuid_1 = __importDefault(require("ksuid"));

const debug_1 = __importDefault(require("debug"));
const websocket_1 = require("./websocket");
const trace = debug_1.default("@oada/client:http:trace");

@@ -25,2 +33,3 @@ const warn = debug_1.default("@oada/client:http:warn");

super();
this.context = fetch_1.context ? fetch_1.context() : { fetch: fetch_1.default };
this._domain = domain.match(/^http/) ? domain : `https://${domain}`;

@@ -31,6 +40,8 @@ this._domain = this._domain.replace(/\/$/, "");

trace(`Opening the HTTP connection to HEAD ${this._domain}/bookmarks w/ headers authorization: Bearer ${this._token}`);
this.initialConnection = cross_fetch_1.default(`${this._domain}/bookmarks`, {
this.initialConnection = this.context
.fetch(`${this._domain}/bookmarks`, {
method: "HEAD",
headers: { authorization: `Bearer ${this._token}` },
}).then((result) => {
})
.then((result) => {
trace("Initial HEAD returned status: ", result.status);

@@ -48,2 +59,3 @@ if (result.status < 400) {

});
this.concurrency = concurrency;
this._q = new p_queue_1.default({ concurrency });

@@ -55,3 +67,6 @@ this._q.on("active", () => {

async disconnect() {
var _a, _b, _c;
this._status = ConnectionStatus.Disconnected;
await ((_b = (_a = this.context).disconnectAll) === null || _b === void 0 ? void 0 : _b.call(_a));
await ((_c = this.ws) === null || _c === void 0 ? void 0 : _c.disconnect());
this.emit("close");

@@ -65,10 +80,14 @@ }

}
request(req, callback, timeout) {
async request(req, callback, timeout) {
var _a;
trace("Starting http request: ", req);
if (req.method === "watch" || req.method === "unwatch") {
throw new Error("HTTP (i.e. non-WebSocket) Client cannot do watches");
if (req.method === "watch" || req.method === "unwatch" || callback) {
warn("WATCH/UNWATCH not currently supported for http(2), falling-back to ws");
if (!this.ws) {
const domain = this._domain.replace(/^https?:\/\//, "");
this.ws = new websocket_1.WebSocketClient(domain, this.concurrency);
await this.ws.awaitConnection();
}
return (_a = this.ws) === null || _a === void 0 ? void 0 : _a.request(req, callback, timeout);
}
if (callback) {
throw new Error("HTTP (i.e. non-WebSocket) Client cannot handle a watch callback");
}
if (!req.requestId)

@@ -87,7 +106,9 @@ req.requestId = ksuid_1.default.randomSync().string;

}
const result = await cross_fetch_1.default(`${this._domain}${req.path}`, {
const result = await this.context
.fetch(`${this._domain}${req.path}`, {
method: req.method.toUpperCase(),
body: JSON.stringify(req.data),
headers: req.headers,
}).then((res) => {
})
.then((res) => {
if (timedout)

@@ -104,3 +125,10 @@ throw new Error("Request timeout");

const headers = {};
result.headers.forEach((value, key) => (headers[key] = value));
if (Array.isArray(result.headers)) {
result.headers.forEach((value, key) => (headers[key] = value));
}
else {
for (const [key, value] of result.headers.entries()) {
headers[key] = value;
}
}
const length = +(result.headers.get("content-length") || 0);

@@ -107,0 +135,0 @@ let data = null;

{
"name": "@oada/client",
"version": "2.3.1",
"version": "2.4.0",
"description": "A lightweight client tool to interact with an OADA-compliant server",
"repository": "https://github.com/OADA/client",
"main": "dist/index.js",
"browser": {
"./lib/fetch": "cross-fetch"
},
"react-native": {
"./lib/fetch": "cross-fetch"
},
"types": "dist/index.d.ts",

@@ -12,3 +18,3 @@ "files": [

"scripts": {
"test": "mocha -r ts-node/register test/**/*.test.ts",
"test": "mocha -r ts-node/register test/**/*.test.ts --timeout 10000",
"build": "tsc",

@@ -26,2 +32,3 @@ "prettier": "prettier --write '{lib,test}/**/*.ts'",

"debug": "^4.1.1",
"fetch-h2": "^2.5.1",
"isomorphic-ws": "^4.0.1",

@@ -28,0 +35,0 @@ "ksuid": "^1.2.0",

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