web3-rpc-providers
Advanced tools
Comparing version 1.0.0-dev.cbcfc18.0 to 1.0.0-dev.d9d0391.0
import { BaseWeb3Error } from 'web3-errors'; | ||
export declare class QuickNodeRateLimitError extends BaseWeb3Error { | ||
code: number; | ||
constructor(); | ||
constructor(error?: Error); | ||
} |
@@ -23,4 +23,4 @@ "use strict"; | ||
class QuickNodeRateLimitError extends web3_errors_1.BaseWeb3Error { | ||
constructor() { | ||
super(`Too many requests, Quicknode has reached its rate limit.`); | ||
constructor(error) { | ||
super(`You've reach the rate limit of free RPC calls from our Partner Quick Nodes. There are two options you can either create a paid Quick Nodes account and get 20% off for 2 months using WEB3JS referral code, or use Free public RPC endpoint.`, error); | ||
this.code = ERR_QUICK_NODE_RATE_LIMIT; | ||
@@ -27,0 +27,0 @@ } |
@@ -5,2 +5,3 @@ import { QuickNodeProvider } from './web3_provider_quicknode.js'; | ||
export * from './web3_provider.js'; | ||
export declare const mainnet: QuickNodeProvider; | ||
export * from './errors.js'; | ||
export declare const mainnet: QuickNodeProvider<import("web3-types").EthExecutionAPI>; |
@@ -38,4 +38,5 @@ "use strict"; | ||
__exportStar(require("./web3_provider.js"), exports); | ||
__exportStar(require("./errors.js"), exports); | ||
// default providers | ||
exports.mainnet = new web3_provider_quicknode_js_1.QuickNodeProvider(); | ||
//# sourceMappingURL=index.js.map |
@@ -0,6 +1,8 @@ | ||
import { EthExecutionAPI, JsonRpcResponseWithResult, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec } from "web3-types"; | ||
import { Transport, Network } from "./types.js"; | ||
import { Web3ExternalProvider } from "./web3_provider.js"; | ||
export declare class QuickNodeProvider extends Web3ExternalProvider { | ||
export declare class QuickNodeProvider<API extends Web3APISpec = EthExecutionAPI> extends Web3ExternalProvider { | ||
constructor(network?: Network, transport?: Transport, token?: string, host?: string); | ||
request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method>>(payload: Web3APIPayload<EthExecutionAPI, Method>, requestOptions?: RequestInit): Promise<JsonRpcResponseWithResult<ResultType>>; | ||
getRPCURL(network: Network, transport: Transport, _token: string, _host: string): string; | ||
} |
@@ -18,6 +18,17 @@ "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()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.QuickNodeProvider = void 0; | ||
const web3_errors_1 = require("web3-errors"); | ||
const types_js_1 = require("./types.js"); | ||
const web3_provider_js_1 = require("./web3_provider.js"); | ||
const errors_js_1 = require("./errors.js"); | ||
const isValid = (str) => str !== undefined && str.trim().length > 0; | ||
@@ -28,2 +39,18 @@ class QuickNodeProvider extends web3_provider_js_1.Web3ExternalProvider { | ||
} | ||
request(payload, requestOptions) { | ||
const _super = Object.create(null, { | ||
request: { get: () => super.request } | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield _super.request.call(this, payload, requestOptions); | ||
} | ||
catch (error) { | ||
if (error instanceof web3_errors_1.ResponseError && error.statusCode === 429) { | ||
throw new errors_js_1.QuickNodeRateLimitError(error); | ||
} | ||
throw error; | ||
} | ||
}); | ||
} | ||
// eslint-disable-next-line class-methods-use-this | ||
@@ -30,0 +57,0 @@ getRPCURL(network, transport, _token, _host) { |
@@ -34,6 +34,4 @@ "use strict"; | ||
const web3_providers_ws_1 = __importDefault(require("web3-providers-ws")); | ||
const web3_validator_1 = require("web3-validator"); | ||
const web3_utils_1 = require("web3-utils"); | ||
const types_js_1 = require("./types.js"); | ||
const errors_js_1 = require("./errors.js"); | ||
/* | ||
@@ -60,8 +58,3 @@ This class can be used to create new providers only when there is custom logic required in each Request method like | ||
if (this.transport === types_js_1.Transport.HTTPS) { | ||
const res = yield (this.provider.request(payload, requestOptions)); | ||
if (typeof res === 'object' && !(0, web3_validator_1.isNullish)(res) && 'error' in res && !(0, web3_validator_1.isNullish)(res.error) && 'code' in res.error && res.error.code === 429) { | ||
// rate limiting error by quicknode; | ||
throw new errors_js_1.QuickNodeRateLimitError(); | ||
} | ||
return res; | ||
return yield (this.provider.request(payload, requestOptions)); | ||
} | ||
@@ -68,0 +61,0 @@ return this.provider.request(payload); |
@@ -20,4 +20,4 @@ /* | ||
export class QuickNodeRateLimitError extends BaseWeb3Error { | ||
constructor() { | ||
super(`Too many requests, Quicknode has reached its rate limit.`); | ||
constructor(error) { | ||
super(`You've reach the rate limit of free RPC calls from our Partner Quick Nodes. There are two options you can either create a paid Quick Nodes account and get 20% off for 2 months using WEB3JS referral code, or use Free public RPC endpoint.`, error); | ||
this.code = ERR_QUICK_NODE_RATE_LIMIT; | ||
@@ -24,0 +24,0 @@ } |
@@ -21,4 +21,5 @@ /* | ||
export * from './web3_provider.js'; | ||
export * from './errors.js'; | ||
// default providers | ||
export const mainnet = new QuickNodeProvider(); | ||
//# sourceMappingURL=index.js.map |
@@ -17,4 +17,15 @@ /* | ||
*/ | ||
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 { ResponseError } from "web3-errors"; | ||
import { Transport, Network } from "./types.js"; | ||
import { Web3ExternalProvider } from "./web3_provider.js"; | ||
import { QuickNodeRateLimitError } from "./errors.js"; | ||
const isValid = (str) => str !== undefined && str.trim().length > 0; | ||
@@ -25,2 +36,18 @@ export class QuickNodeProvider extends Web3ExternalProvider { | ||
} | ||
request(payload, requestOptions) { | ||
const _super = Object.create(null, { | ||
request: { get: () => super.request } | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield _super.request.call(this, payload, requestOptions); | ||
} | ||
catch (error) { | ||
if (error instanceof ResponseError && error.statusCode === 429) { | ||
throw new QuickNodeRateLimitError(error); | ||
} | ||
throw error; | ||
} | ||
}); | ||
} | ||
// eslint-disable-next-line class-methods-use-this | ||
@@ -27,0 +54,0 @@ getRPCURL(network, transport, _token, _host) { |
@@ -28,6 +28,4 @@ /* | ||
import WebSocketProvider from "web3-providers-ws"; | ||
import { isNullish } from "web3-validator"; | ||
import { Eip1193Provider } from "web3-utils"; | ||
import { Transport } from "./types.js"; | ||
import { QuickNodeRateLimitError } from './errors.js'; | ||
/* | ||
@@ -54,8 +52,3 @@ This class can be used to create new providers only when there is custom logic required in each Request method like | ||
if (this.transport === Transport.HTTPS) { | ||
const res = yield (this.provider.request(payload, requestOptions)); | ||
if (typeof res === 'object' && !isNullish(res) && 'error' in res && !isNullish(res.error) && 'code' in res.error && res.error.code === 429) { | ||
// rate limiting error by quicknode; | ||
throw new QuickNodeRateLimitError(); | ||
} | ||
return res; | ||
return yield (this.provider.request(payload, requestOptions)); | ||
} | ||
@@ -62,0 +55,0 @@ return this.provider.request(payload); |
import { BaseWeb3Error } from 'web3-errors'; | ||
export declare class QuickNodeRateLimitError extends BaseWeb3Error { | ||
code: number; | ||
constructor(); | ||
constructor(error?: Error); | ||
} | ||
//# sourceMappingURL=errors.d.ts.map |
@@ -5,3 +5,4 @@ import { QuickNodeProvider } from './web3_provider_quicknode.js'; | ||
export * from './web3_provider.js'; | ||
export declare const mainnet: QuickNodeProvider; | ||
export * from './errors.js'; | ||
export declare const mainnet: QuickNodeProvider<import("web3-types").EthExecutionAPI>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,7 +1,9 @@ | ||
import { EthExecutionAPI, JsonRpcResponseWithResult, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec } from "web3-types"; | ||
import { Transport, Network } from "./types.js"; | ||
import { Web3ExternalProvider } from "./web3_provider.js"; | ||
export declare class QuickNodeProvider extends Web3ExternalProvider { | ||
export declare class QuickNodeProvider<API extends Web3APISpec = EthExecutionAPI> extends Web3ExternalProvider { | ||
constructor(network?: Network, transport?: Transport, token?: string, host?: string); | ||
request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method>>(payload: Web3APIPayload<EthExecutionAPI, Method>, requestOptions?: RequestInit): Promise<JsonRpcResponseWithResult<ResultType>>; | ||
getRPCURL(network: Network, transport: Transport, _token: string, _host: string): string; | ||
} | ||
//# sourceMappingURL=web3_provider_quicknode.d.ts.map |
{ | ||
"name": "web3-rpc-providers", | ||
"version": "1.0.0-dev.cbcfc18.0+cbcfc18", | ||
"version": "1.0.0-dev.d9d0391.0+d9d0391", | ||
"description": "Web3 Providers package", | ||
@@ -52,2 +52,3 @@ "main": "./lib/commonjs/index.js", | ||
"eslint-plugin-import": "^2.26.0", | ||
"isomorphic-ws": "^5.0.0", | ||
"jest": "^29.7.0", | ||
@@ -60,10 +61,10 @@ "jest-extended": "^3.0.1", | ||
"dependencies": { | ||
"web3-errors": "1.2.1-dev.cbcfc18.0+cbcfc18", | ||
"web3-providers-http": "4.1.1-dev.cbcfc18.0+cbcfc18", | ||
"web3-providers-ws": "4.0.9-dev.cbcfc18.0+cbcfc18", | ||
"web3-types": "1.7.1-dev.cbcfc18.0+cbcfc18", | ||
"web3-utils": "4.3.2-dev.cbcfc18.0+cbcfc18", | ||
"web3-validator": "2.0.7-dev.cbcfc18.0+cbcfc18" | ||
"web3-errors": "1.2.2-dev.d9d0391.0+d9d0391", | ||
"web3-providers-http": "4.1.1-dev.d9d0391.0+d9d0391", | ||
"web3-providers-ws": "4.0.9-dev.d9d0391.0+d9d0391", | ||
"web3-types": "1.7.1-dev.d9d0391.0+d9d0391", | ||
"web3-utils": "4.3.2-dev.d9d0391.0+d9d0391", | ||
"web3-validator": "2.0.7-dev.d9d0391.0+d9d0391" | ||
}, | ||
"gitHead": "cbcfc1878502008349f805a2e82e9263a02b717e" | ||
"gitHead": "d9d0391003f2e1d874d39dd43427e1b18b104d8b" | ||
} |
@@ -19,3 +19,2 @@ /* | ||
import { BaseWeb3Error } from 'web3-errors'; | ||
import { } from 'web3-types'; | ||
@@ -26,5 +25,5 @@ const ERR_QUICK_NODE_RATE_LIMIT = 1300; | ||
public constructor() { | ||
super(`Too many requests, Quicknode has reached its rate limit.`); | ||
public constructor(error?: Error) { | ||
super(`You've reach the rate limit of free RPC calls from our Partner Quick Nodes. There are two options you can either create a paid Quick Nodes account and get 20% off for 2 months using WEB3JS referral code, or use Free public RPC endpoint.`, error); | ||
} | ||
} |
@@ -23,4 +23,5 @@ /* | ||
export * from './web3_provider.js'; | ||
export * from './errors.js'; | ||
// default providers | ||
export const mainnet = new QuickNodeProvider(); |
@@ -18,8 +18,13 @@ /* | ||
import { EthExecutionAPI, JsonRpcResponseWithResult, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec } from "web3-types"; | ||
import { ResponseError } from "web3-errors"; | ||
import { Transport, Network } from "./types.js"; | ||
import { Web3ExternalProvider } from "./web3_provider.js"; | ||
import { QuickNodeRateLimitError } from "./errors.js"; | ||
const isValid = (str: string) => str !== undefined && str.trim().length > 0; | ||
export class QuickNodeProvider extends Web3ExternalProvider { | ||
export class QuickNodeProvider< | ||
API extends Web3APISpec = EthExecutionAPI, | ||
> extends Web3ExternalProvider { | ||
@@ -36,2 +41,20 @@ public constructor( | ||
public async request< | ||
Method extends Web3APIMethod<API>, | ||
ResultType = Web3APIReturnType<API, Method>, | ||
>( | ||
payload: Web3APIPayload<EthExecutionAPI, Method>, | ||
requestOptions?: RequestInit, | ||
): Promise<JsonRpcResponseWithResult<ResultType>> { | ||
try { | ||
return await super.request(payload, requestOptions); | ||
} catch (error) { | ||
if (error instanceof ResponseError && error.statusCode === 429){ | ||
throw new QuickNodeRateLimitError(error); | ||
} | ||
throw error; | ||
} | ||
} | ||
// eslint-disable-next-line class-methods-use-this | ||
@@ -38,0 +61,0 @@ public getRPCURL(network: Network, |
@@ -20,3 +20,2 @@ /* | ||
import WebSocketProvider from "web3-providers-ws"; | ||
import { isNullish } from "web3-validator"; | ||
import { | ||
@@ -33,3 +32,2 @@ EthExecutionAPI, JsonRpcResult, ProviderConnectInfo, ProviderMessage, | ||
import { Transport, Network } from "./types.js"; | ||
import { QuickNodeRateLimitError } from './errors.js'; | ||
@@ -44,4 +42,4 @@ /* | ||
export abstract class Web3ExternalProvider < | ||
API extends Web3APISpec = EthExecutionAPI, | ||
export abstract class Web3ExternalProvider< | ||
API extends Web3APISpec = EthExecutionAPI, | ||
> extends Eip1193Provider { | ||
@@ -52,3 +50,3 @@ | ||
public abstract getRPCURL(network: Network,transport: Transport,token: string, host: string): string; | ||
public abstract getRPCURL(network: Network, transport: Transport, token: string, host: string): string; | ||
@@ -60,3 +58,3 @@ public constructor( | ||
host: string) { | ||
super(); | ||
@@ -82,14 +80,7 @@ | ||
if (this.transport === Transport.HTTPS) { | ||
const res = await ( (this.provider as HttpProvider).request(payload, requestOptions)) as unknown as JsonRpcResponseWithResult<ResultType>; | ||
if (typeof res === 'object' && !isNullish(res) && 'error' in res && !isNullish(res.error) && 'code' in res.error && (res.error as { code: number }).code === 429){ | ||
// rate limiting error by quicknode; | ||
throw new QuickNodeRateLimitError(); | ||
} | ||
return res; | ||
} | ||
return await ((this.provider as HttpProvider).request(payload, requestOptions)) as unknown as JsonRpcResponseWithResult<ResultType>; | ||
} | ||
return (this.provider as WebSocketProvider).request(payload); | ||
} | ||
@@ -96,0 +87,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
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
75218
999
13