fix: web3.js fork fetch for browsers
This commit is contained in:
parent
9f1b876c74
commit
da28badcaa
File diff suppressed because it is too large
Load Diff
|
@ -64,10 +64,10 @@
|
||||||
"borsh": "^0.7.0",
|
"borsh": "^0.7.0",
|
||||||
"bs58": "^4.0.1",
|
"bs58": "^4.0.1",
|
||||||
"buffer": "6.0.1",
|
"buffer": "6.0.1",
|
||||||
"cross-fetch": "^3.1.4",
|
|
||||||
"fast-stable-stringify": "^1.0.0",
|
"fast-stable-stringify": "^1.0.0",
|
||||||
"jayson": "^3.4.4",
|
"jayson": "^3.4.4",
|
||||||
"js-sha3": "^0.8.0",
|
"js-sha3": "^0.8.0",
|
||||||
|
"node-fetch": "2",
|
||||||
"rpc-websockets": "^7.4.2",
|
"rpc-websockets": "^7.4.2",
|
||||||
"secp256k1": "^4.0.2",
|
"secp256k1": "^4.0.2",
|
||||||
"superstruct": "^0.14.2",
|
"superstruct": "^0.14.2",
|
||||||
|
@ -98,6 +98,7 @@
|
||||||
"@types/mocha": "^9.0.0",
|
"@types/mocha": "^9.0.0",
|
||||||
"@types/mz": "^2.7.3",
|
"@types/mz": "^2.7.3",
|
||||||
"@types/node": "^17.0.24",
|
"@types/node": "^17.0.24",
|
||||||
|
"@types/node-fetch": "2",
|
||||||
"@types/secp256k1": "^4.0.1",
|
"@types/secp256k1": "^4.0.1",
|
||||||
"@types/sinon": "^10.0.0",
|
"@types/sinon": "^10.0.0",
|
||||||
"@types/sinon-chai": "^3.2.8",
|
"@types/sinon-chai": "^3.2.8",
|
||||||
|
|
|
@ -101,7 +101,7 @@ function generateConfig(configType, format) {
|
||||||
'crypto-hash',
|
'crypto-hash',
|
||||||
'jayson/lib/client/browser',
|
'jayson/lib/client/browser',
|
||||||
'js-sha3',
|
'js-sha3',
|
||||||
'cross-fetch',
|
'node-fetch',
|
||||||
'rpc-websockets',
|
'rpc-websockets',
|
||||||
'secp256k1',
|
'secp256k1',
|
||||||
'superstruct',
|
'superstruct',
|
||||||
|
@ -113,7 +113,7 @@ function generateConfig(configType, format) {
|
||||||
case 'browser':
|
case 'browser':
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case 'iife': {
|
case 'iife': {
|
||||||
config.external = ['http', 'https'];
|
config.external = ['http', 'https', 'node-fetch'];
|
||||||
|
|
||||||
config.output = [
|
config.output = [
|
||||||
{
|
{
|
||||||
|
@ -161,6 +161,7 @@ function generateConfig(configType, format) {
|
||||||
'https',
|
'https',
|
||||||
'jayson/lib/client/browser',
|
'jayson/lib/client/browser',
|
||||||
'js-sha3',
|
'js-sha3',
|
||||||
|
'node-fetch',
|
||||||
'rpc-websockets',
|
'rpc-websockets',
|
||||||
'secp256k1',
|
'secp256k1',
|
||||||
'superstruct',
|
'superstruct',
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
export const Headers = globalThis.Headers;
|
||||||
|
export const Request = globalThis.Request;
|
||||||
|
export const Response = globalThis.Response;
|
||||||
|
export default globalThis.fetch;
|
|
@ -1,6 +1,5 @@
|
||||||
import bs58 from 'bs58';
|
import bs58 from 'bs58';
|
||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
import crossFetch from 'cross-fetch';
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import fastStableStringify from 'fast-stable-stringify';
|
import fastStableStringify from 'fast-stable-stringify';
|
||||||
import {
|
import {
|
||||||
|
@ -28,6 +27,7 @@ import RpcClient from 'jayson/lib/client/browser';
|
||||||
import {AgentManager} from './agent-manager';
|
import {AgentManager} from './agent-manager';
|
||||||
import {EpochSchedule} from './epoch-schedule';
|
import {EpochSchedule} from './epoch-schedule';
|
||||||
import {SendTransactionError} from './errors';
|
import {SendTransactionError} from './errors';
|
||||||
|
import fetchImpl, {Response} from './fetch-impl';
|
||||||
import {NonceAccount} from './nonce-account';
|
import {NonceAccount} from './nonce-account';
|
||||||
import {PublicKey} from './publickey';
|
import {PublicKey} from './publickey';
|
||||||
import {Signer} from './keypair';
|
import {Signer} from './keypair';
|
||||||
|
@ -959,7 +959,7 @@ function createRpcClient(
|
||||||
fetchMiddleware?: FetchMiddleware,
|
fetchMiddleware?: FetchMiddleware,
|
||||||
disableRetryOnRateLimit?: boolean,
|
disableRetryOnRateLimit?: boolean,
|
||||||
): RpcClient {
|
): RpcClient {
|
||||||
const fetch = customFetch ? customFetch : crossFetch;
|
const fetch = customFetch ? customFetch : fetchImpl;
|
||||||
let agentManager: AgentManager | undefined;
|
let agentManager: AgentManager | undefined;
|
||||||
if (!process.env.BROWSER) {
|
if (!process.env.BROWSER) {
|
||||||
agentManager = new AgentManager(useHttps);
|
agentManager = new AgentManager(useHttps);
|
||||||
|
@ -2160,7 +2160,10 @@ export type ConfirmedSignatureInfo = {
|
||||||
*/
|
*/
|
||||||
export type HttpHeaders = {[header: string]: string};
|
export type HttpHeaders = {[header: string]: string};
|
||||||
|
|
||||||
export type FetchFn = typeof crossFetch;
|
/**
|
||||||
|
* The type of the JavaScript `fetch()` API
|
||||||
|
*/
|
||||||
|
export type FetchFn = typeof fetchImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A callback used to augment the outgoing HTTP request
|
* A callback used to augment the outgoing HTTP request
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import * as nodeFetch from 'node-fetch';
|
||||||
|
|
||||||
|
export * from 'node-fetch';
|
||||||
|
export default async function (
|
||||||
|
input: nodeFetch.RequestInfo,
|
||||||
|
init?: nodeFetch.RequestInit,
|
||||||
|
): Promise<nodeFetch.Response> {
|
||||||
|
const processedInput =
|
||||||
|
typeof input === 'string' && input.slice(0, 2) === '//'
|
||||||
|
? 'https:' + input
|
||||||
|
: input;
|
||||||
|
return await nodeFetch.default(processedInput, init);
|
||||||
|
}
|
|
@ -2,5 +2,6 @@
|
||||||
"entryPoints": ["src/index.ts"],
|
"entryPoints": ["src/index.ts"],
|
||||||
"excludeInternal": true,
|
"excludeInternal": true,
|
||||||
"excludePrivate": true,
|
"excludePrivate": true,
|
||||||
|
"intentionallyNotExported": ["src/fetch-impl.ts:default"],
|
||||||
"out": "doc"
|
"out": "doc"
|
||||||
}
|
}
|
|
@ -1852,6 +1852,14 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
|
|
||||||
|
"@types/node-fetch@2":
|
||||||
|
version "2.6.1"
|
||||||
|
resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.1.tgz#8f127c50481db65886800ef496f20bbf15518975"
|
||||||
|
integrity sha512-oMqjURCaxoSIsHSr1E47QHzbmzNR5rK8McHuNb11BOM9cHcIK3Avy0s/b2JlXHoQGTYS3NsvWzV1M0iK7l0wbA==
|
||||||
|
dependencies:
|
||||||
|
"@types/node" "*"
|
||||||
|
form-data "^3.0.0"
|
||||||
|
|
||||||
"@types/node@*", "@types/node@>=12", "@types/node@^17.0.24":
|
"@types/node@*", "@types/node@>=12", "@types/node@^17.0.24":
|
||||||
version "17.0.35"
|
version "17.0.35"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.35.tgz#635b7586086d51fb40de0a2ec9d1014a5283ba4a"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.35.tgz#635b7586086d51fb40de0a2ec9d1014a5283ba4a"
|
||||||
|
@ -2745,9 +2753,10 @@ columnify@~1.5.4:
|
||||||
strip-ansi "^3.0.0"
|
strip-ansi "^3.0.0"
|
||||||
wcwidth "^1.0.0"
|
wcwidth "^1.0.0"
|
||||||
|
|
||||||
combined-stream@^1.0.6, combined-stream@~1.0.6:
|
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
|
||||||
version "1.0.8"
|
version "1.0.8"
|
||||||
resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz"
|
resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
|
||||||
|
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
|
||||||
dependencies:
|
dependencies:
|
||||||
delayed-stream "~1.0.0"
|
delayed-stream "~1.0.0"
|
||||||
|
|
||||||
|
@ -3758,6 +3767,15 @@ forever-agent@~0.6.1:
|
||||||
version "0.6.1"
|
version "0.6.1"
|
||||||
resolved "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz"
|
resolved "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz"
|
||||||
|
|
||||||
|
form-data@^3.0.0:
|
||||||
|
version "3.0.1"
|
||||||
|
resolved "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
|
||||||
|
integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
|
||||||
|
dependencies:
|
||||||
|
asynckit "^0.4.0"
|
||||||
|
combined-stream "^1.0.8"
|
||||||
|
mime-types "^2.1.12"
|
||||||
|
|
||||||
form-data@~2.3.2:
|
form-data@~2.3.2:
|
||||||
version "2.3.3"
|
version "2.3.3"
|
||||||
resolved "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz"
|
resolved "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz"
|
||||||
|
@ -5454,9 +5472,10 @@ node-emoji@^1.10.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
lodash "^4.17.21"
|
lodash "^4.17.21"
|
||||||
|
|
||||||
node-fetch@2.6.7, node-fetch@^2.6.1, node-fetch@^2.6.7, node-fetch@~2.6.1:
|
node-fetch@2, node-fetch@2.6.7, node-fetch@^2.6.1, node-fetch@^2.6.7, node-fetch@~2.6.1:
|
||||||
version "2.6.7"
|
version "2.6.7"
|
||||||
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz"
|
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
|
||||||
|
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
whatwg-url "^5.0.0"
|
whatwg-url "^5.0.0"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue