You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@anephenix/sarus

Package Overview
Dependencies
Maintainers
0
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anephenix/sarus - npm Package Compare versions

Comparing version

to
0.6.12

__tests__/index/utils.test.ts
# CHANGELOG
### 0.6.12 - Saturday 15th February, 2025
- Added notes to FUTURE.md file
- Merge pull request #503 from anephenix/dependabot/npm_and_yarn/types/node-22.13.4
- Merge pull request #504 from anephenix/dependabot/npm_and_yarn/prettier-3.5.1
- Bump prettier from 3.5.0 to 3.5.1
- Bump @types/node from 22.13.2 to 22.13.4
- Merge pull request #502 from anephenix/dependabot/npm_and_yarn/types/node-22.13.2
- Bump @types/node from 22.13.1 to 22.13.2
- Merge pull request #501 from anephenix/dependabot/npm_and_yarn/babel/parser-7.26.8
- Merge pull request #500 from anephenix/dependabot/npm_and_yarn/prettier-3.5.0
- Merge pull request #499 from anephenix/dependabot/npm_and_yarn/babel/types-7.26.8
- Bump @babel/parser from 7.26.7 to 7.26.8
- Bump prettier from 3.4.2 to 3.5.0
- Bump @babel/types from 7.26.7 to 7.26.8
- Merge pull request #498 from anephenix/dependabot/npm_and_yarn/types/node-22.13.1
- Bump @types/node from 22.13.0 to 22.13.1
- Merge pull request #497 from anephenix/dependabot/npm_and_yarn/types/node-22.13.0
- Bump @types/node from 22.12.0 to 22.13.0
- Updated Readme
- Adjusted some code and add size-limit checks
- Merge pull request #496 from anephenix/dependabot/npm_and_yarn/types/node-22.12.0
- Bump @types/node from 22.10.10 to 22.12.0
### 0.6.11 - Friday 24th January, 2025

@@ -4,0 +28,0 @@

27

dist/index.js

@@ -16,2 +16,3 @@ "use strict";

var dataTransformer_1 = require("./lib/dataTransformer");
var utils_1 = require("./lib/utils");
/**

@@ -46,26 +47,2 @@ * Retrieves the storage API for the browser

};
var validateWebSocketUrl = function (rawUrl) {
var url;
try {
// Alternatively, we can also check with URL.canParse(), but since we need
// the URL object anyway to validate the protocol, we go ahead and parse it
// here.
url = new URL(rawUrl);
}
catch (e) {
// TypeError, as specified by WHATWG URL Standard:
// https://url.spec.whatwg.org/#url-class (see constructor steps)
if (!(e instanceof TypeError)) {
throw e;
}
// Untested - our URL mock does not give us an instance of TypeError
var message = e.message;
throw new Error("The WebSocket URL is not valid: ".concat(message));
}
var protocol = url.protocol;
if (!constants_1.ALLOWED_PROTOCOLS.includes(protocol)) {
throw new Error("Expected the WebSocket URL to have protocol 'ws:' or 'wss:', got '".concat(protocol, "' instead."));
}
return url;
};
/*

@@ -147,3 +124,3 @@ * Calculate the exponential backoff delay for a given number of connection

// Sets the WebSocket server url for the client to connect to.
this.url = validateWebSocketUrl(url);
this.url = (0, utils_1.validateWebSocketUrl)(url);
// Sets the binaryType of the data being sent over the connection

@@ -150,0 +127,0 @@ this.binaryType = binaryType;

@@ -17,2 +17,5 @@ Scenario:

This feels like a feature that could be supported by [Hub](https://github.com/anephenix/hub),
as that is where WebSocket server logic is kept to support this.
Feature:

@@ -19,0 +22,0 @@

{
"name": "@anephenix/sarus",
"version": "0.6.11",
"version": "0.6.12",
"description": "A WebSocket JavaScript library",

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

"@babel/types": "^7.22.5",
"@size-limit/preset-small-lib": "^11.1.6",
"@types/jest": "^29.5.2",

@@ -40,2 +41,3 @@ "@types/node": "^22.10.5",

"prettier": "^3.0.3",
"size-limit": "^11.1.6",
"ts-jest": "^29.1.0",

@@ -51,2 +53,3 @@ "ts-node": "^10.9.2",

"publish-patch-release": "npm run prepare-patch-release && git push origin master && git push --tags",
"size": "size-limit",
"test": "jest --coverage",

@@ -71,2 +74,8 @@ "update-changelog": "npx ts-node scripts/update-changelog.ts",

],
"size-limit": [
{
"path": "dist/index.js",
"limit": "10 kB"
}
],
"license": "MIT",

@@ -73,0 +82,0 @@ "bugs": {

@@ -464,2 +464,2 @@ # Sarus

© 2020 Anephenix OÜ. Sarus is licensed under the MIT License.
© 2025 Anephenix OÜ. Sarus is licensed under the MIT License.
// File Dependencies
import {
ALLOWED_PROTOCOLS,
WS_EVENT_NAMES,
DATA_STORAGE_TYPES,
DEFAULT_EVENT_LISTENERS_OBJECT,
} from "./lib/constants";
import { WS_EVENT_NAMES, DATA_STORAGE_TYPES } from "./lib/constants";
import { serialize, deserialize } from "./lib/dataTransformer";

@@ -13,2 +8,3 @@ import {

} from "./lib/validators";
import { validateWebSocketUrl } from "./lib/utils";

@@ -51,28 +47,2 @@ interface StorageParams {

const validateWebSocketUrl = (rawUrl: string): URL => {
let url: URL;
try {
// Alternatively, we can also check with URL.canParse(), but since we need
// the URL object anyway to validate the protocol, we go ahead and parse it
// here.
url = new URL(rawUrl);
} catch (e) {
// TypeError, as specified by WHATWG URL Standard:
// https://url.spec.whatwg.org/#url-class (see constructor steps)
if (!(e instanceof TypeError)) {
throw e;
}
// Untested - our URL mock does not give us an instance of TypeError
const { message } = e;
throw new Error(`The WebSocket URL is not valid: ${message}`);
}
const { protocol } = url;
if (!ALLOWED_PROTOCOLS.includes(protocol)) {
throw new Error(
`Expected the WebSocket URL to have protocol 'ws:' or 'wss:', got '${protocol}' instead.`,
);
}
return url;
};
export interface ExponentialBackoffParams {

@@ -79,0 +49,0 @@ backoffRate: number;