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.3.0-nightly.0 to 1.3.0-nightly.1

lib-es/batcher/index.d.ts

8

.unimportedrc.json
{
"entry": ["src/network.ts", "src/cache.ts"],
"entry": [
"src/batcher/index.ts",
"src/batcher/types.ts",
"src/cache.ts",
"src/index.ts",
"src/network.ts"
],
"ignoreUnimported": [],
"ignoreUnresolved": []
}
# @ledgerhq/live-network
## 1.3.0-nightly.1
### Minor Changes
- [#6819](https://github.com/LedgerHQ/ledger-live/pull/6819) [`326cae0`](https://github.com/LedgerHQ/ledger-live/commit/326cae088cc33795536deb1d868c86e8dbeb6a13) Thanks [@sprohaszka-ledger](https://github.com/sprohaszka-ledger)! - Add Batcher to live-network and partition Axios types
### Patch Changes
- Updated dependencies [[`6d44f25`](https://github.com/LedgerHQ/ledger-live/commit/6d44f255c5b2f453c61d0b754807db1f76d7174e)]:
- @ledgerhq/live-env@2.1.0-nightly.1
## 1.3.0-nightly.0

@@ -4,0 +15,0 @@

@@ -1,3 +0,2 @@

import type { AxiosError, AxiosRequestConfig } from "axios";
import { AxiosPromise, AxiosResponse } from "axios";
import { AxiosPromise, AxiosResponse, type AxiosError, type AxiosRequestConfig } from "axios";
type Metadata = {

@@ -18,4 +17,29 @@ startTime: number;

export declare const errorInterceptor: (error: InterceptedError) => InterceptedError;
export type LiveNetworkRequest<T> = {
url?: string;
method?: "GET" | "POST" | "PUT" | "DELETE";
headers?: Record<string, string | number | boolean>;
baseURL?: string;
params?: unknown;
data?: T;
timeout?: number;
};
export type LiveNetworkResponse<T> = {
data: T;
status: number;
};
/**
* Network call
* @param request
* @returns
*/
export declare const newImplementation: <T = unknown, U = unknown>(request: LiveNetworkRequest<U>) => Promise<LiveNetworkResponse<T>>;
/**
* Network call
* @deprecated Use new method by updating your import: `@ledgerhq/live-network`
* @param arg Axios request type
* @returns Axios response type
*/
declare const implementation: <T = any>(arg: AxiosRequestConfig) => AxiosPromise<T>;
export default implementation;
//# sourceMappingURL=network.d.ts.map

@@ -0,2 +1,12 @@

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 _a;
import axios from "axios";
import { LedgerAPI4xx, LedgerAPI5xx, NetworkDown } from "@ledgerhq/errors";

@@ -6,4 +16,2 @@ import { changes, getEnv } from "@ledgerhq/live-env";

import { log } from "@ledgerhq/logs";
import axios from "axios";
import invariant from "invariant";
export const requestInterceptor = (request) => {

@@ -126,4 +134,41 @@ if (!getEnv("ENABLE_NETWORK_LOGS")) {

};
/**
* Network call
* @param request
* @returns
*/
export const newImplementation = (request) => __awaiter(void 0, void 0, void 0, function* () {
let response;
if (!("method" in request)) {
request.method = "GET";
}
if (request.method === "GET") {
if (!("timeout" in request)) {
request.timeout = getEnv("GET_CALLS_TIMEOUT");
}
response = yield retry(() => axios(request), {
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;
},
});
}
else {
response = yield axios(request);
}
const { data, status } = response;
return { data, status };
});
/**
* Network call
* @deprecated Use new method by updating your import: `@ledgerhq/live-network`
* @param arg Axios request type
* @returns Axios response type
*/
const implementation = (arg) => {
invariant(typeof arg === "object", "network takes an object as parameter");
let promise;

@@ -130,0 +175,0 @@ if (arg.method === "GET") {

@@ -1,3 +0,2 @@

import type { AxiosError, AxiosRequestConfig } from "axios";
import { AxiosPromise, AxiosResponse } from "axios";
import { AxiosPromise, AxiosResponse, type AxiosError, type AxiosRequestConfig } from "axios";
type Metadata = {

@@ -18,4 +17,29 @@ startTime: number;

export declare const errorInterceptor: (error: InterceptedError) => InterceptedError;
export type LiveNetworkRequest<T> = {
url?: string;
method?: "GET" | "POST" | "PUT" | "DELETE";
headers?: Record<string, string | number | boolean>;
baseURL?: string;
params?: unknown;
data?: T;
timeout?: number;
};
export type LiveNetworkResponse<T> = {
data: T;
status: number;
};
/**
* Network call
* @param request
* @returns
*/
export declare const newImplementation: <T = unknown, U = unknown>(request: LiveNetworkRequest<U>) => Promise<LiveNetworkResponse<T>>;
/**
* Network call
* @deprecated Use new method by updating your import: `@ledgerhq/live-network`
* @param arg Axios request type
* @returns Axios response type
*/
declare const implementation: <T = any>(arg: AxiosRequestConfig) => AxiosPromise<T>;
export default implementation;
//# sourceMappingURL=network.d.ts.map
"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) {

@@ -7,3 +16,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.errorInterceptor = exports.responseInterceptor = exports.requestInterceptor = void 0;
exports.newImplementation = exports.errorInterceptor = exports.responseInterceptor = exports.requestInterceptor = void 0;
const axios_1 = __importDefault(require("axios"));
const errors_1 = require("@ledgerhq/errors");

@@ -13,4 +23,2 @@ const live_env_1 = require("@ledgerhq/live-env");

const logs_1 = require("@ledgerhq/logs");
const axios_1 = __importDefault(require("axios"));
const invariant_1 = __importDefault(require("invariant"));
const requestInterceptor = (request) => {

@@ -136,4 +144,42 @@ if (!(0, live_env_1.getEnv)("ENABLE_NETWORK_LOGS")) {

};
/**
* Network call
* @param request
* @returns
*/
const newImplementation = (request) => __awaiter(void 0, void 0, void 0, function* () {
let response;
if (!("method" in request)) {
request.method = "GET";
}
if (request.method === "GET") {
if (!("timeout" in request)) {
request.timeout = (0, live_env_1.getEnv)("GET_CALLS_TIMEOUT");
}
response = yield (0, live_promise_1.retry)(() => (0, axios_1.default)(request), {
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;
},
});
}
else {
response = yield (0, axios_1.default)(request);
}
const { data, status } = response;
return { data, status };
});
exports.newImplementation = newImplementation;
/**
* Network call
* @deprecated Use new method by updating your import: `@ledgerhq/live-network`
* @param arg Axios request type
* @returns Axios response type
*/
const implementation = (arg) => {
(0, invariant_1.default)(typeof arg === "object", "network takes an object as parameter");
let promise;

@@ -140,0 +186,0 @@ if (arg.method === "GET") {

30

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

@@ -21,8 +21,2 @@ "keywords": [

"*": {
"*.json": [
"*.json"
],
"*": [
"lib/*"
],
"lib/*": [

@@ -33,2 +27,9 @@ "lib/*"

"lib-es/*"
],
"batcher": [
"lib/batcher/index"
],
"*": [
"lib/*",
"lib/batcher/*"
]

@@ -42,2 +43,10 @@ }

"./lib-es/*.js": "./lib-es/*.js",
"./batcher": {
"require": "./lib/batcher/index.js",
"default": "./lib-es/batcher/index.js"
},
"./batcher/*": {
"require": "./lib/batcher/*.js",
"default": "./lib-es/batcher/*.js"
},
"./*": {

@@ -51,2 +60,6 @@ "require": "./lib/*.js",

},
".": {
"require": "./lib/index.js",
"default": "./lib-es/index.js"
},
"./package.json": "./package.json"

@@ -57,6 +70,5 @@ },

"axios": "0.26.1",
"invariant": "^2.2.2",
"lru-cache": "^7.14.1",
"@ledgerhq/errors": "^6.17.0-nightly.0",
"@ledgerhq/live-env": "^2.1.0-nightly.0",
"@ledgerhq/live-env": "^2.1.0-nightly.1",
"@ledgerhq/live-promise": "^0.1.0-nightly.0",

@@ -63,0 +75,0 @@ "@ledgerhq/logs": "^6.12.0"

@@ -0,1 +1,8 @@

import axios, {
AxiosPromise,
AxiosResponse,
type AxiosError,
type AxiosRequestConfig,
type Method,
} from "axios";
import { LedgerAPI4xx, LedgerAPI5xx, NetworkDown } from "@ledgerhq/errors";

@@ -5,5 +12,2 @@ import { changes, getEnv } from "@ledgerhq/live-env";

import { log } from "@ledgerhq/logs";
import type { AxiosError, AxiosRequestConfig, Method } from "axios";
import axios, { AxiosPromise, AxiosResponse } from "axios";
import invariant from "invariant";

@@ -162,4 +166,60 @@ type Metadata = { startTime: number };

export type LiveNetworkRequest<T> = {
url?: string;
method?: "GET" | "POST" | "PUT" | "DELETE";
headers?: Record<string, string | number | boolean>;
baseURL?: string;
params?: unknown;
data?: T;
timeout?: number;
};
export type LiveNetworkResponse<T> = {
data: T;
status: number;
};
/**
* Network call
* @param request
* @returns
*/
export const newImplementation = async <T = unknown, U = unknown>(
request: LiveNetworkRequest<U>,
): Promise<LiveNetworkResponse<T>> => {
let response: AxiosResponse<T>;
if (!("method" in request)) {
request.method = "GET";
}
if (request.method === "GET") {
if (!("timeout" in request)) {
request.timeout = getEnv("GET_CALLS_TIMEOUT");
}
response = await retry(() => axios(request), {
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;
},
});
} else {
response = await axios(request);
}
const { data, status } = response;
return { data, status };
};
/**
* Network call
* @deprecated Use new method by updating your import: `@ledgerhq/live-network`
* @param arg Axios request type
* @returns Axios response type
*/
const implementation = <T = any>(arg: AxiosRequestConfig): AxiosPromise<T> => {
invariant(typeof arg === "object", "network takes an object as parameter");
let promise: AxiosPromise;

@@ -166,0 +226,0 @@

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