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

@ledgerhq/live-network

Package Overview
Dependencies
Maintainers
7
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ledgerhq/live-network - npm Package Compare versions

Comparing version 1.2.1-nightly.1 to 1.2.1-nightly.2

9

CHANGELOG.md
# @ledgerhq/live-network
## 1.2.1-nightly.2
### Patch Changes
- [#6566](https://github.com/LedgerHQ/ledger-live/pull/6566) [`cfb97f7`](https://github.com/LedgerHQ/ledger-live/commit/cfb97f7d5c81824815522e8699b7469047b1513a) Thanks [@cgrellard-ledger](https://github.com/cgrellard-ledger)! - Prevent unnecessary http retries when 422
- Updated dependencies [[`cfb97f7`](https://github.com/LedgerHQ/ledger-live/commit/cfb97f7d5c81824815522e8699b7469047b1513a)]:
- @ledgerhq/live-promise@0.0.4-nightly.0
## 1.2.1-nightly.1

@@ -4,0 +13,0 @@

@@ -89,2 +89,3 @@ var _a;

method,
msg,
};

@@ -134,2 +135,10 @@ return (status || "").toString().startsWith("4")

maxRetry: getEnv("GET_CALLS_RETRY"),
retryCondition: error => {
if (error && error.status) {
// A 422 shouldn't be retried without change as explained in this documentation
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422
return error.status !== 422;
}
return true;
},
});

@@ -136,0 +145,0 @@ }

62

lib-es/network.test.js

@@ -0,9 +1,23 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import axios from "axios";
import { getEnv, setEnv } from "@ledgerhq/live-env";
import { requestInterceptor, responseInterceptor } from "./network";
import network, { requestInterceptor, responseInterceptor } from "./network";
import * as logs from "@ledgerhq/logs";
jest.mock("axios");
const mockedAxios = jest.mocked(axios);
describe("network", () => {
const DEFAULT_ENABLE_NETWORK_LOGS = getEnv("ENABLE_NETWORK_LOGS");
const DEFAULT_GET_CALLS_RETRY = getEnv("GET_CALLS_RETRY");
afterEach(() => {
// restore the spy created with spyOn
jest.restoreAllMocks();
jest.clearAllMocks();
// Restore DEFAULT_ENABLE_NETWORK_LOGS

@@ -93,4 +107,50 @@ setEnv("ENABLE_NETWORK_LOGS", DEFAULT_ENABLE_NETWORK_LOGS);

});
test("should retry request when unsuccessful and response status is not 422", () => __awaiter(void 0, void 0, void 0, function* () {
const response = {
config: {
baseURL: "baseURL",
url: "url",
data: "data",
},
data: "data",
status: 500,
statusText: "Error",
headers: {},
};
try {
mockedAxios.mockImplementation(() => Promise.reject(response));
yield network({
method: "GET",
url: "https://google.com",
});
// eslint-disable-next-line no-empty
}
catch (_a) { }
expect(mockedAxios).toHaveBeenCalledTimes(DEFAULT_GET_CALLS_RETRY + 1);
}));
test("should not retry request when response status is 422", () => __awaiter(void 0, void 0, void 0, function* () {
const response = {
config: {
baseURL: "baseURL",
url: "url",
data: "data",
},
data: "data",
status: 422,
statusText: "Error",
headers: {},
};
mockedAxios.mockImplementation(() => Promise.reject(response));
try {
yield network({
method: "GET",
url: "https://google.com",
});
// eslint-disable-next-line no-empty
}
catch (_b) { }
expect(mockedAxios).toHaveBeenCalledTimes(1);
}));
});
});
//# sourceMappingURL=network.test.js.map

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

method,
msg,
};

@@ -143,2 +144,10 @@ return (status || "").toString().startsWith("4")

maxRetry: (0, live_env_1.getEnv)("GET_CALLS_RETRY"),
retryCondition: error => {
if (error && error.status) {
// A 422 shouldn't be retried without change as explained in this documentation
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422
return error.status !== 422;
}
return true;
},
});

@@ -145,0 +154,0 @@ }

@@ -25,11 +25,28 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const live_env_1 = require("@ledgerhq/live-env");
const network_1 = require("./network");
const network_1 = __importStar(require("./network"));
const logs = __importStar(require("@ledgerhq/logs"));
jest.mock("axios");
const mockedAxios = jest.mocked(axios_1.default);
describe("network", () => {
const DEFAULT_ENABLE_NETWORK_LOGS = (0, live_env_1.getEnv)("ENABLE_NETWORK_LOGS");
const DEFAULT_GET_CALLS_RETRY = (0, live_env_1.getEnv)("GET_CALLS_RETRY");
afterEach(() => {
// restore the spy created with spyOn
jest.restoreAllMocks();
jest.clearAllMocks();
// Restore DEFAULT_ENABLE_NETWORK_LOGS

@@ -119,4 +136,50 @@ (0, live_env_1.setEnv)("ENABLE_NETWORK_LOGS", DEFAULT_ENABLE_NETWORK_LOGS);

});
test("should retry request when unsuccessful and response status is not 422", () => __awaiter(void 0, void 0, void 0, function* () {
const response = {
config: {
baseURL: "baseURL",
url: "url",
data: "data",
},
data: "data",
status: 500,
statusText: "Error",
headers: {},
};
try {
mockedAxios.mockImplementation(() => Promise.reject(response));
yield (0, network_1.default)({
method: "GET",
url: "https://google.com",
});
// eslint-disable-next-line no-empty
}
catch (_a) { }
expect(mockedAxios).toHaveBeenCalledTimes(DEFAULT_GET_CALLS_RETRY + 1);
}));
test("should not retry request when response status is 422", () => __awaiter(void 0, void 0, void 0, function* () {
const response = {
config: {
baseURL: "baseURL",
url: "url",
data: "data",
},
data: "data",
status: 422,
statusText: "Error",
headers: {},
};
mockedAxios.mockImplementation(() => Promise.reject(response));
try {
yield (0, network_1.default)({
method: "GET",
url: "https://google.com",
});
// eslint-disable-next-line no-empty
}
catch (_b) { }
expect(mockedAxios).toHaveBeenCalledTimes(1);
}));
});
});
//# sourceMappingURL=network.test.js.map

4

package.json
{
"name": "@ledgerhq/live-network",
"version": "1.2.1-nightly.1",
"version": "1.2.1-nightly.2",
"description": "Ledger Live network and cache utilities",

@@ -57,3 +57,3 @@ "keywords": [

"@ledgerhq/live-env": "^2.0.1-nightly.0",
"@ledgerhq/live-promise": "^0.0.3",
"@ledgerhq/live-promise": "^0.0.4-nightly.0",
"@ledgerhq/logs": "^6.12.0"

@@ -60,0 +60,0 @@ },

@@ -0,7 +1,13 @@

import axios from "axios";
import { getEnv, setEnv } from "@ledgerhq/live-env";
import { requestInterceptor, responseInterceptor } from "./network";
import network, { requestInterceptor, responseInterceptor } from "./network";
import * as logs from "@ledgerhq/logs";
jest.mock("axios");
const mockedAxios = jest.mocked(axios);
describe("network", () => {
const DEFAULT_ENABLE_NETWORK_LOGS = getEnv("ENABLE_NETWORK_LOGS");
const DEFAULT_GET_CALLS_RETRY = getEnv("GET_CALLS_RETRY");

@@ -11,2 +17,3 @@ afterEach(() => {

jest.restoreAllMocks();
jest.clearAllMocks();

@@ -114,3 +121,51 @@ // Restore DEFAULT_ENABLE_NETWORK_LOGS

});
test("should retry request when unsuccessful and response status is not 422", async () => {
const response = {
config: {
baseURL: "baseURL",
url: "url",
data: "data",
},
data: "data",
status: 500,
statusText: "Error",
headers: {},
};
try {
mockedAxios.mockImplementation(() => Promise.reject(response));
await network({
method: "GET",
url: "https://google.com",
});
// eslint-disable-next-line no-empty
} catch {}
expect(mockedAxios).toHaveBeenCalledTimes(DEFAULT_GET_CALLS_RETRY + 1);
});
test("should not retry request when response status is 422", async () => {
const response = {
config: {
baseURL: "baseURL",
url: "url",
data: "data",
},
data: "data",
status: 422,
statusText: "Error",
headers: {},
};
mockedAxios.mockImplementation(() => Promise.reject(response));
try {
await network({
method: "GET",
url: "https://google.com",
});
// eslint-disable-next-line no-empty
} catch {}
expect(mockedAxios).toHaveBeenCalledTimes(1);
});
});
});

@@ -121,2 +121,3 @@ import { LedgerAPI4xx, LedgerAPI5xx, NetworkDown } from "@ledgerhq/errors";

method,
msg,
};

@@ -172,2 +173,10 @@ return (status || "").toString().startsWith("4")

maxRetry: getEnv("GET_CALLS_RETRY"),
retryCondition: error => {
if (error && error.status) {
// A 422 shouldn't be retried without change as explained in this documentation
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422
return error.status !== 422;
}
return true;
},
});

@@ -174,0 +183,0 @@ } else {

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

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

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