@ledgerhq/live-network
Advanced tools
Comparing version 1.2.2 to 1.3.0-next.0
{ | ||
"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-next.0 | ||
### Minor Changes | ||
- [#6596](https://github.com/LedgerHQ/ledger-live/pull/6596) [`77fa530`](https://github.com/LedgerHQ/ledger-live/commit/77fa530c8626df94fa7f9c0a8b3a99f2efa7cb11) Thanks [@KVNLS](https://github.com/KVNLS)! - Upgrade React Native to version 0.73.6 | ||
- [#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 [[`77fa530`](https://github.com/LedgerHQ/ledger-live/commit/77fa530c8626df94fa7f9c0a8b3a99f2efa7cb11), [`815ae3d`](https://github.com/LedgerHQ/ledger-live/commit/815ae3dae8027823854ada837df3dc983d09b10f), [`cec1599`](https://github.com/LedgerHQ/ledger-live/commit/cec1599a41aa1a18a249e34312164bc93b63972f), [`6d44f25`](https://github.com/LedgerHQ/ledger-live/commit/6d44f255c5b2f453c61d0b754807db1f76d7174e), [`6623cd1`](https://github.com/LedgerHQ/ledger-live/commit/6623cd13102bd8340bd7d4dfdd469934527985c3), [`6552679`](https://github.com/LedgerHQ/ledger-live/commit/65526794bb4d1fbc7e286c0e1c0b6d021413fc8c)]: | ||
- @ledgerhq/errors@6.17.0-next.0 | ||
- @ledgerhq/live-promise@0.1.0-next.0 | ||
- @ledgerhq/live-env@2.1.0-next.0 | ||
## 1.2.2 | ||
@@ -4,0 +19,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") { |
{ | ||
"name": "@ledgerhq/live-network", | ||
"version": "1.2.2", | ||
"version": "1.3.0-next.0", | ||
"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,7 +70,6 @@ }, | ||
"axios": "0.26.1", | ||
"invariant": "^2.2.2", | ||
"lru-cache": "^7.14.1", | ||
"@ledgerhq/errors": "^6.16.4", | ||
"@ledgerhq/live-env": "^2.0.2", | ||
"@ledgerhq/live-promise": "^0.0.4", | ||
"@ledgerhq/errors": "^6.17.0-next.0", | ||
"@ledgerhq/live-env": "^2.1.0-next.0", | ||
"@ledgerhq/live-promise": "^0.1.0-next.0", | ||
"@ledgerhq/logs": "^6.12.0" | ||
@@ -64,0 +76,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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122706
6
62
1791
2
+ Added@ledgerhq/live-promise@0.1.0(transitive)
- Removedinvariant@^2.2.2
- Removed@ledgerhq/live-promise@0.0.4(transitive)
- Removedinvariant@2.2.4(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)