🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

onshape

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onshape - npm Package Compare versions

Comparing version
0.1.2
to
0.1.3
+30
-6
dist/api/client.js

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

const node_url_1 = require("node:url");
const promises_1 = require("node:timers/promises");
const READ_RETRY_STATUSES = new Set([408, 429, 500, 502, 503, 504]);
const MAX_READ_ATTEMPTS = 5;
const MAX_RETRY_DELAY_MS = 10_000;
class HttpError extends Error {

@@ -54,9 +58,15 @@ status;

async requestJson(url) {
const response = await this.fetchWithAuthRedirects(url, {
Accept: "application/json;charset=UTF-8; qs=0.09",
});
if (!response.ok) {
throw new HttpError(response.status, await responseDetail(response));
for (let attempt = 1; attempt <= MAX_READ_ATTEMPTS; attempt += 1) {
const response = await this.fetchWithAuthRedirects(url, {
Accept: "application/json;charset=UTF-8; qs=0.09",
});
if (response.ok) {
return response.json();
}
if (!READ_RETRY_STATUSES.has(response.status) || attempt === MAX_READ_ATTEMPTS) {
throw new HttpError(response.status, await responseDetail(response));
}
await (0, promises_1.setTimeout)(retryDelayMs(response, attempt));
}
return response.json();
throw new Error("unreachable read retry state");
}

@@ -100,1 +110,15 @@ async fetchWithAuthRedirects(url, headers, method = "GET", body) {

}
function retryDelayMs(response, attempt) {
const retryAfter = response.headers.get("retry-after");
if (retryAfter) {
const seconds = Number(retryAfter);
if (Number.isFinite(seconds) && seconds >= 0) {
return Math.min(seconds * 1000, MAX_RETRY_DELAY_MS);
}
const dateMs = Date.parse(retryAfter);
if (Number.isFinite(dateMs)) {
return Math.min(Math.max(dateMs - Date.now(), 0), MAX_RETRY_DELAY_MS);
}
}
return Math.min(500 * 2 ** (attempt - 1), MAX_RETRY_DELAY_MS);
}
+1
-1
{
"name": "onshape",
"version": "0.1.2",
"version": "0.1.3",
"description": "Node.js CLI for Onshape CAD automation with the same JSON contract as onshape-cli.",

@@ -5,0 +5,0 @@ "license": "MIT",