@solana/rpc-transport-http
Advanced tools
Comparing version 2.0.0-experimental.9a26b88 to 2.0.0-experimental.9ce1f51
@@ -0,1 +1,3 @@ | ||
import { SolanaError, SOLANA_ERROR__RPC_TRANSPORT_HTTP_ERROR, SOLANA_ERROR__RPC_TRANSPORT_HEADER_FORBIDDEN } from '@solana/errors'; | ||
// ../build-scripts/env-shim.ts | ||
@@ -6,17 +8,2 @@ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
var e = globalThis.fetch; | ||
// src/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
statusCode; | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
// src/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
@@ -58,5 +45,5 @@ accept: true, | ||
if (badHeaders.length > 0) { | ||
throw new Error( | ||
`${badHeaders.length > 1 ? "These headers are" : "This header is"} forbidden: \`${badHeaders.join("`, `")}\`. Learn more at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.` | ||
); | ||
throw new SolanaError(SOLANA_ERROR__RPC_TRANSPORT_HEADER_FORBIDDEN, { | ||
headers: badHeaders | ||
}); | ||
} | ||
@@ -113,3 +100,3 @@ } | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
throw new SolanaError(SOLANA_ERROR__RPC_TRANSPORT_HTTP_ERROR, { | ||
message: response.statusText, | ||
@@ -116,0 +103,0 @@ statusCode: response.status |
@@ -0,1 +1,3 @@ | ||
import { SolanaError, SOLANA_ERROR__RPC_TRANSPORT_HTTP_ERROR, SOLANA_ERROR__RPC_TRANSPORT_HEADER_FORBIDDEN } from '@solana/errors'; | ||
// ../build-scripts/env-shim.ts | ||
@@ -6,17 +8,2 @@ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
var e = globalThis.fetch; | ||
// src/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
statusCode; | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
// src/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
@@ -58,5 +45,5 @@ accept: true, | ||
if (badHeaders.length > 0) { | ||
throw new Error( | ||
`${badHeaders.length > 1 ? "These headers are" : "This header is"} forbidden: \`${badHeaders.join("`, `")}\`. Learn more at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.` | ||
); | ||
throw new SolanaError(SOLANA_ERROR__RPC_TRANSPORT_HEADER_FORBIDDEN, { | ||
headers: badHeaders | ||
}); | ||
} | ||
@@ -113,3 +100,3 @@ } | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
throw new SolanaError(SOLANA_ERROR__RPC_TRANSPORT_HTTP_ERROR, { | ||
message: response.statusText, | ||
@@ -116,0 +103,0 @@ statusCode: response.status |
@@ -0,1 +1,2 @@ | ||
import { SolanaError, SOLANA_ERROR__RPC_TRANSPORT_HTTP_ERROR, SOLANA_ERROR__RPC_TRANSPORT_HEADER_FORBIDDEN } from '@solana/errors'; | ||
import { fetch } from 'undici'; | ||
@@ -5,17 +6,2 @@ | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// src/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
statusCode; | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
// src/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
@@ -57,5 +43,5 @@ accept: true, | ||
if (badHeaders.length > 0) { | ||
throw new Error( | ||
`${badHeaders.length > 1 ? "These headers are" : "This header is"} forbidden: \`${badHeaders.join("`, `")}\`. Learn more at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.` | ||
); | ||
throw new SolanaError(SOLANA_ERROR__RPC_TRANSPORT_HEADER_FORBIDDEN, { | ||
headers: badHeaders | ||
}); | ||
} | ||
@@ -105,3 +91,3 @@ } | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
throw new SolanaError(SOLANA_ERROR__RPC_TRANSPORT_HTTP_ERROR, { | ||
message: response.statusText, | ||
@@ -108,0 +94,0 @@ statusCode: response.status |
{ | ||
"name": "@solana/rpc-transport-http", | ||
"version": "2.0.0-experimental.9a26b88", | ||
"version": "2.0.0-experimental.9ce1f51", | ||
"description": "An RPC transport that uses HTTP requests", | ||
@@ -50,3 +50,4 @@ "exports": { | ||
"undici": "^6.6.2", | ||
"@solana/rpc-spec": "2.0.0-experimental.9a26b88" | ||
"@solana/errors": "2.0.0-experimental.9ce1f51", | ||
"@solana/rpc-spec": "2.0.0-experimental.9ce1f51" | ||
}, | ||
@@ -53,0 +54,0 @@ "bundlewatch": { |
@@ -219,3 +219,27 @@ [![npm][npm-image]][npm-url] | ||
```ts | ||
// TODO: Your turn; send us a pull request with an example. | ||
import { RpcTransport } from '@solana/rpc-spec'; | ||
import { createHttpTransport } from '@solana/rpc-transport-http'; | ||
// Create a transport for each RPC server | ||
const transports = [ | ||
createHttpTransport({ url: 'https://mainnet-beta.my-server-1.com' }), | ||
createHttpTransport({ url: 'https://mainnet-beta.my-server-2.com' }), | ||
createHttpTransport({ url: 'https://mainnet-beta.my-server-2.com' }), | ||
]; | ||
// A failover transport that will try each transport in order until one succeeds before failing | ||
async function failoverTransport<TResponse>(...args: Parameters<RpcTransport>): Promise<TResponse> { | ||
let requestError; | ||
for (const transport of transports) { | ||
try { | ||
return await transport(...args); | ||
} catch (err) { | ||
requestError = err; | ||
console.error(err); | ||
} | ||
} | ||
throw requestError; | ||
} | ||
``` |
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
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
245
79150
3
20
631
+ Added@solana/errors@2.0.0-experimental.9ce1f51(transitive)
+ Added@solana/rpc-spec@2.0.0-experimental.9ce1f51(transitive)
+ Added@solana/rpc-spec-types@2.0.0-experimental.9ce1f51(transitive)
+ Addedchalk@5.4.1(transitive)
+ Addedcommander@12.1.0(transitive)
- Removed@solana/rpc-spec@2.0.0-experimental.9a26b88(transitive)
- Removed@solana/rpc-spec-types@2.0.0-experimental.9a26b88(transitive)