@solana/web3.js 1.5.1 → 1.6.1

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/lib/index.iife.js CHANGED
@@ -16974,7 +16974,23 @@ var solanaWeb3 = (function (exports) {
16974
16974
  logs: nullable(array(string()))
16975
16975
  }));
16976
16976
 
16977
- function createRpcClient(url, useHttps) {
16977
+ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware) {
16978
+
16979
+ let fetchWithMiddleware;
16980
+
16981
+ if (fetchMiddleware) {
16982
+ fetchWithMiddleware = (url, options) => {
16983
+ return new Promise((resolve, reject) => {
16984
+ fetchMiddleware(url, options, async (url, options) => {
16985
+ try {
16986
+ resolve(await browser$1(url, options));
16987
+ } catch (error) {
16988
+ reject(error);
16989
+ }
16990
+ });
16991
+ });
16992
+ };
16993
+ }
16978
16994
 
16979
16995
  const clientBrowser = new browser(async (request, callback) => {
16980
16996
  const agent = undefined;
@@ -16982,9 +16998,9 @@ var solanaWeb3 = (function (exports) {
16982
16998
  method: 'POST',
16983
16999
  body: request,
16984
17000
  agent,
16985
- headers: {
17001
+ headers: Object.assign({
16986
17002
  'Content-Type': 'application/json'
16987
- }
17003
+ }, httpHeaders || {})
16988
17004
  };
16989
17005
 
16990
17006
  try {
@@ -16993,7 +17009,11 @@ var solanaWeb3 = (function (exports) {
16993
17009
  let waitTime = 500;
16994
17010
 
16995
17011
  for (;;) {
16996
- res = await browser$1(url, options);
17012
+ if (fetchWithMiddleware) {
17013
+ res = await fetchWithMiddleware(url, options);
17014
+ } else {
17015
+ res = await browser$1(url, options);
17016
+ }
16997
17017
 
16998
17018
  if (res.status !== 429
16999
17019
  /* Too many requests */
@@ -17620,9 +17640,9 @@ var solanaWeb3 = (function (exports) {
17620
17640
  * Establish a JSON RPC connection
17621
17641
  *
17622
17642
  * @param endpoint URL to the fullnode JSON RPC endpoint
17623
- * @param commitment optional default commitment level
17643
+ * @param commitmentOrConfig optional default commitment level or optional ConnectionConfig configuration object
17624
17644
  */
17625
- constructor(endpoint, commitment) {
17645
+ constructor(endpoint, commitmentOrConfig) {
17626
17646
  _defineProperty(this, "_commitment", void 0);
17627
17647
 
17628
17648
  _defineProperty(this, "_rpcEndpoint", void 0);
@@ -17674,10 +17694,20 @@ var solanaWeb3 = (function (exports) {
17674
17694
  this._rpcEndpoint = endpoint;
17675
17695
  let url = urlParse(endpoint);
17676
17696
  const useHttps = url.protocol === 'https:';
17677
- this._rpcClient = createRpcClient(url.href);
17697
+ let httpHeaders;
17698
+ let fetchMiddleware;
17699
+
17700
+ if (commitmentOrConfig && typeof commitmentOrConfig === 'string') {
17701
+ this._commitment = commitmentOrConfig;
17702
+ } else if (commitmentOrConfig) {
17703
+ this._commitment = commitmentOrConfig.commitment;
17704
+ httpHeaders = commitmentOrConfig.httpHeaders;
17705
+ fetchMiddleware = commitmentOrConfig.fetchMiddleware;
17706
+ }
17707
+
17708
+ this._rpcClient = createRpcClient(url.href, useHttps, httpHeaders, fetchMiddleware);
17678
17709
  this._rpcRequest = createRpcRequest(this._rpcClient);
17679
17710
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
17680
- this._commitment = commitment;
17681
17711
  this._blockhashInfo = {
17682
17712
  recentBlockhash: null,
17683
17713
  lastFetch: 0,