@solana/web3.js 1.43.1 → 1.43.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.43.1",
3
+ "version": "1.43.2",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -64,10 +64,10 @@
64
64
  "borsh": "^0.7.0",
65
65
  "bs58": "^4.0.1",
66
66
  "buffer": "6.0.1",
67
- "cross-fetch": "^3.1.4",
68
67
  "fast-stable-stringify": "^1.0.0",
69
68
  "jayson": "^3.4.4",
70
69
  "js-sha3": "^0.8.0",
70
+ "node-fetch": "2",
71
71
  "rpc-websockets": "^7.4.2",
72
72
  "secp256k1": "^4.0.2",
73
73
  "superstruct": "^0.14.2",
@@ -81,10 +81,10 @@
81
81
  "@babel/preset-typescript": "^7.12.16",
82
82
  "@babel/register": "^7.12.13",
83
83
  "@commitlint/config-conventional": "^15.0.0",
84
- "@commitlint/travis-cli": "^16.2.3",
85
- "@rollup/plugin-alias": "^3.1.2",
84
+ "@commitlint/travis-cli": "^17.0.0",
85
+ "@rollup/plugin-alias": "^3.1.9",
86
86
  "@rollup/plugin-babel": "^5.2.3",
87
- "@rollup/plugin-commonjs": "^21.0.0",
87
+ "@rollup/plugin-commonjs": "^22.0.0",
88
88
  "@rollup/plugin-json": "^4.1.0",
89
89
  "@rollup/plugin-multi-entry": "^4.0.0",
90
90
  "@rollup/plugin-node-resolve": "^13.0.0",
@@ -98,6 +98,7 @@
98
98
  "@types/mocha": "^9.0.0",
99
99
  "@types/mz": "^2.7.3",
100
100
  "@types/node": "^17.0.24",
101
+ "@types/node-fetch": "2",
101
102
  "@types/secp256k1": "^4.0.1",
102
103
  "@types/sinon": "^10.0.0",
103
104
  "@types/sinon-chai": "^3.2.8",
@@ -0,0 +1,4 @@
1
+ export const Headers = globalThis.Headers;
2
+ export const Request = globalThis.Request;
3
+ export const Response = globalThis.Response;
4
+ export default globalThis.fetch;
package/src/connection.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import bs58 from 'bs58';
2
2
  import {Buffer} from 'buffer';
3
- import crossFetch from 'cross-fetch';
4
3
  // @ts-ignore
5
4
  import fastStableStringify from 'fast-stable-stringify';
6
5
  import {
@@ -28,6 +27,7 @@ import RpcClient from 'jayson/lib/client/browser';
28
27
  import {AgentManager} from './agent-manager';
29
28
  import {EpochSchedule} from './epoch-schedule';
30
29
  import {SendTransactionError} from './errors';
30
+ import fetchImpl, {Response} from './fetch-impl';
31
31
  import {NonceAccount} from './nonce-account';
32
32
  import {PublicKey} from './publickey';
33
33
  import {Signer} from './keypair';
@@ -955,27 +955,25 @@ function createRpcClient(
955
955
  url: string,
956
956
  useHttps: boolean,
957
957
  httpHeaders?: HttpHeaders,
958
- customFetch?: typeof crossFetch,
958
+ customFetch?: FetchFn,
959
959
  fetchMiddleware?: FetchMiddleware,
960
960
  disableRetryOnRateLimit?: boolean,
961
961
  ): RpcClient {
962
- const fetch = customFetch ? customFetch : crossFetch;
962
+ const fetch = customFetch ? customFetch : fetchImpl;
963
963
  let agentManager: AgentManager | undefined;
964
964
  if (!process.env.BROWSER) {
965
965
  agentManager = new AgentManager(useHttps);
966
966
  }
967
967
 
968
- let fetchWithMiddleware:
969
- | ((url: string, options: any) => Promise<Response>)
970
- | undefined;
968
+ let fetchWithMiddleware: FetchFn | undefined;
971
969
 
972
970
  if (fetchMiddleware) {
973
- fetchWithMiddleware = async (url: string, options: any) => {
974
- const modifiedFetchArgs = await new Promise<[string, any]>(
971
+ fetchWithMiddleware = async (info, init) => {
972
+ const modifiedFetchArgs = await new Promise<Parameters<FetchFn>>(
975
973
  (resolve, reject) => {
976
974
  try {
977
- fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) =>
978
- resolve([modifiedUrl, modifiedOptions]),
975
+ fetchMiddleware(info, init, (modifiedInfo, modifiedInit) =>
976
+ resolve([modifiedInfo, modifiedInit]),
979
977
  );
980
978
  } catch (error) {
981
979
  reject(error);
@@ -2162,13 +2160,18 @@ export type ConfirmedSignatureInfo = {
2162
2160
  */
2163
2161
  export type HttpHeaders = {[header: string]: string};
2164
2162
 
2163
+ /**
2164
+ * The type of the JavaScript `fetch()` API
2165
+ */
2166
+ export type FetchFn = typeof fetchImpl;
2167
+
2165
2168
  /**
2166
2169
  * A callback used to augment the outgoing HTTP request
2167
2170
  */
2168
2171
  export type FetchMiddleware = (
2169
- url: string,
2170
- options: any,
2171
- fetch: (modifiedUrl: string, modifiedOptions: any) => void,
2172
+ info: Parameters<FetchFn>[0],
2173
+ init: Parameters<FetchFn>[1],
2174
+ fetch: (...a: Parameters<FetchFn>) => void,
2172
2175
  ) => void;
2173
2176
 
2174
2177
  /**
@@ -2182,7 +2185,7 @@ export type ConnectionConfig = {
2182
2185
  /** Optional HTTP headers object */
2183
2186
  httpHeaders?: HttpHeaders;
2184
2187
  /** Optional custom fetch function */
2185
- fetch?: typeof crossFetch;
2188
+ fetch?: FetchFn;
2186
2189
  /** Optional fetch middleware callback */
2187
2190
  fetchMiddleware?: FetchMiddleware;
2188
2191
  /** Optional Disable retrying calls when server responds with HTTP 429 (Too Many Requests) */
@@ -0,0 +1,13 @@
1
+ import * as nodeFetch from 'node-fetch';
2
+
3
+ export * from 'node-fetch';
4
+ export default async function (
5
+ input: nodeFetch.RequestInfo,
6
+ init?: nodeFetch.RequestInit,
7
+ ): Promise<nodeFetch.Response> {
8
+ const processedInput =
9
+ typeof input === 'string' && input.slice(0, 2) === '//'
10
+ ? 'https:' + input
11
+ : input;
12
+ return await nodeFetch.default(processedInput, init);
13
+ }