New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@todesktop/client-comm-server

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@todesktop/client-comm-server - npm Package Compare versions

Comparing version 0.48.0 to 0.49.0

3

dist/index.d.ts

@@ -21,5 +21,2 @@ export declare type HandleBroadcastFunc<Request extends Record<string, any>, Response> = (callback: (data: Request) => Response | Promise<Response>) => () => void;

export declare function checkIfCommServerRunning(ports: number[]): Promise<boolean | undefined>;
export declare class NotRunningError extends Error {
code: string;
}
declare type SuccessResponse<T> = {

@@ -26,0 +23,0 @@ success: true;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.NotRunningError = exports.checkIfCommServerRunning = exports.createBroadcastService = void 0;
exports.checkIfCommServerRunning = exports.createBroadcastService = void 0;
const client_util_1 = require("@todesktop/client-util");

@@ -77,51 +77,14 @@ const client_core_1 = require("@todesktop/client-core");

exports.checkIfCommServerRunning = checkIfCommServerRunning;
class NotRunningError extends Error {
constructor() {
super(...arguments);
this.code = "ENOTRUNNING";
}
}
exports.NotRunningError = NotRunningError;
const isValidResponse = (response) => {
return (response !== null && typeof response === "object" && "success" in response);
};
function fetchWithFallback(ports, path) {
return __awaiter(this, void 0, void 0, function* () {
for (const port of ports) {
let response;
let throwImmediately = false;
try {
response = yield fetch(new URL(path, `http://localhost:${port}`));
const response = yield fetch(new URL(path, `http://localhost:${port}`));
return response.json();
}
catch (e) {
// If the promise rejects then it's a network error.
// The promise won’t reject on HTTP error status even if the response is an HTTP 404 or 500
break;
// ignore
}
try {
const json = yield response.json();
if (isValidResponse(json)) {
if (json.success) {
return json;
}
else if (!json.success && "error" in json) {
throwImmediately = true;
throw new Error(json.error);
}
}
}
catch (e) {
if (throwImmediately) {
// This looks like our server is running but it's responding with an error so throw immediately.
throw e;
}
else if (ports.indexOf(port) === ports.length - 1) {
// This is the last port in the list and it's throwing an unknown error (not a network error).
// This usually means there is a different server running on the same port.
throw e;
}
// Otherwise, we'll continue to the next port or throw `NotRunningError`.
}
}
throw new NotRunningError("Communication server is not running");
throw new Error("Failed to fetch");
});

@@ -128,0 +91,0 @@ }

2

package.json
{
"name": "@todesktop/client-comm-server",
"version": "0.48.0",
"version": "0.49.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -87,48 +87,15 @@ import { checkIfCompatibleWithPlugin } from "@todesktop/client-util";

export class NotRunningError extends Error {
code = "ENOTRUNNING";
}
const isValidResponse = <T>(response: unknown): response is ResponseData<T> => {
return (
response !== null && typeof response === "object" && "success" in response
);
};
async function fetchWithFallback<T>(
ports: number[],
path: string
): Promise<SuccessResponse<T>> {
): FetchResponse<T> {
for (const port of ports) {
let response: Response;
let throwImmediately = false;
try {
response = await fetch(new URL(path, `http://localhost:${port}`));
const response = await fetch(new URL(path, `http://localhost:${port}`));
return response.json();
} catch (e) {
// If the promise rejects then it's a network error.
// The promise won’t reject on HTTP error status even if the response is an HTTP 404 or 500
break;
// ignore
}
try {
const json = await response.json();
if (isValidResponse<T>(json)) {
if (json.success) {
return json;
} else if (!json.success && "error" in json) {
throwImmediately = true;
throw new Error(json.error);
}
}
} catch (e) {
if (throwImmediately) {
// This looks like our server is running but it's responding with an error so throw immediately.
throw e;
} else if (ports.indexOf(port) === ports.length - 1) {
// This is the last port in the list and it's throwing an unknown error (not a network error).
// This usually means there is a different server running on the same port.
throw e;
}
// Otherwise, we'll continue to the next port or throw `NotRunningError`.
}
}
throw new NotRunningError("Communication server is not running");
throw new Error("Failed to fetch");
}

@@ -145,3 +112,2 @@

type ErrorResponse = { success: false; error: string };
type ResponseData<T> = SuccessResponse<T> | ErrorResponse;
type FetchResponse<T> = Promise<ResponseData<T>>;
type FetchResponse<T> = Promise<SuccessResponse<T> | ErrorResponse | undefined>;
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