@solana/rpc-transport
Advanced tools
Comparing version 2.0.0-experimental.847f0a9 to 2.0.0-experimental.92a60c3
@@ -1,7 +0,4 @@ | ||
import 'node-fetch'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// ../fetch-impl-browser/dist/index.browser.js | ||
var { fetch } = globalThis; | ||
var src_default = fetch; | ||
// src/http-request-errors.ts | ||
@@ -18,14 +15,72 @@ var SolanaHttpError = class extends Error { | ||
}; | ||
async function makeHttpRequest({ payload, url }) { | ||
// src/http-request-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
accept: true, | ||
"content-length": true, | ||
"content-type": true | ||
}; | ||
var FORBIDDEN_HEADERS = { | ||
"accept-charset": true, | ||
"accept-encoding": true, | ||
"access-control-request-headers": true, | ||
"access-control-request-method": true, | ||
connection: true, | ||
"content-length": true, | ||
cookie: true, | ||
date: true, | ||
dnt: true, | ||
expect: true, | ||
host: true, | ||
"keep-alive": true, | ||
origin: true, | ||
"permissions-policy": true, | ||
// No currently available Typescript technique allows you to match on a prefix. | ||
// 'proxy-':true, | ||
// 'sec-':true, | ||
referer: true, | ||
te: true, | ||
trailer: true, | ||
"transfer-encoding": true, | ||
upgrade: true, | ||
via: true | ||
}; | ||
function assertIsAllowedHttpRequestHeaders(headers) { | ||
const badHeaders = Object.keys(headers).filter((headerName) => { | ||
const lowercaseHeaderName = headerName.toLowerCase(); | ||
return DISALLOWED_HEADERS[headerName.toLowerCase()] === true || FORBIDDEN_HEADERS[headerName.toLowerCase()] === true || lowercaseHeaderName.startsWith("proxy-") || lowercaseHeaderName.startsWith("sec-"); | ||
}); | ||
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.` | ||
); | ||
} | ||
} | ||
function normalizeHeaders(headers) { | ||
const out = {}; | ||
for (const headerName in headers) { | ||
out[headerName.toLowerCase()] = headers[headerName]; | ||
} | ||
return out; | ||
} | ||
// ../fetch-impl/dist/index.browser.js | ||
var e = globalThis.fetch; | ||
// src/http-request.ts | ||
async function makeHttpRequest({ headers, payload, signal, url }) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
body: JSON.stringify(payload), | ||
body, | ||
headers: { | ||
"Content-type": "application/json" | ||
...headers && normalizeHeaders(headers), | ||
// Keep these headers lowercase so they will override any user-supplied headers above. | ||
accept: "application/json", | ||
"content-length": body.length.toString(), | ||
"content-type": "application/json; charset=utf-8" | ||
}, | ||
method: "POST" | ||
method: "POST", | ||
signal | ||
}; | ||
let response; | ||
{ | ||
response = await src_default(url, requestInfo); | ||
} | ||
const response = await e(url, requestInfo); | ||
if (!response.ok) { | ||
@@ -74,7 +129,9 @@ throw new SolanaHttpError({ | ||
const overrides = { | ||
async send() { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
url: transportConfig.url | ||
@@ -93,6 +150,8 @@ }); | ||
const overrides = { | ||
async sendBatch() { | ||
async sendBatch(options) { | ||
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params)); | ||
const responses = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
url: transportConfig.url | ||
@@ -140,2 +199,5 @@ }); | ||
function createJsonRpcTransport(transportConfig) { | ||
if (__DEV__ && transportConfig.headers) { | ||
assertIsAllowedHttpRequestHeaders(transportConfig.headers); | ||
} | ||
return makeProxy(transportConfig); | ||
@@ -142,0 +204,0 @@ } |
@@ -1,7 +0,4 @@ | ||
import 'node-fetch'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// ../fetch-impl-browser/dist/index.browser.js | ||
var { fetch } = globalThis; | ||
var src_default = fetch; | ||
// src/http-request-errors.ts | ||
@@ -18,14 +15,72 @@ var SolanaHttpError = class extends Error { | ||
}; | ||
async function makeHttpRequest({ payload, url }) { | ||
// src/http-request-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
accept: true, | ||
"content-length": true, | ||
"content-type": true | ||
}; | ||
var FORBIDDEN_HEADERS = { | ||
"accept-charset": true, | ||
"accept-encoding": true, | ||
"access-control-request-headers": true, | ||
"access-control-request-method": true, | ||
connection: true, | ||
"content-length": true, | ||
cookie: true, | ||
date: true, | ||
dnt: true, | ||
expect: true, | ||
host: true, | ||
"keep-alive": true, | ||
origin: true, | ||
"permissions-policy": true, | ||
// No currently available Typescript technique allows you to match on a prefix. | ||
// 'proxy-':true, | ||
// 'sec-':true, | ||
referer: true, | ||
te: true, | ||
trailer: true, | ||
"transfer-encoding": true, | ||
upgrade: true, | ||
via: true | ||
}; | ||
function assertIsAllowedHttpRequestHeaders(headers) { | ||
const badHeaders = Object.keys(headers).filter((headerName) => { | ||
const lowercaseHeaderName = headerName.toLowerCase(); | ||
return DISALLOWED_HEADERS[headerName.toLowerCase()] === true || FORBIDDEN_HEADERS[headerName.toLowerCase()] === true || lowercaseHeaderName.startsWith("proxy-") || lowercaseHeaderName.startsWith("sec-"); | ||
}); | ||
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.` | ||
); | ||
} | ||
} | ||
function normalizeHeaders(headers) { | ||
const out = {}; | ||
for (const headerName in headers) { | ||
out[headerName.toLowerCase()] = headers[headerName]; | ||
} | ||
return out; | ||
} | ||
// ../fetch-impl/dist/index.browser.js | ||
var e = globalThis.fetch; | ||
// src/http-request.ts | ||
async function makeHttpRequest({ headers, payload, signal, url }) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
body: JSON.stringify(payload), | ||
body, | ||
headers: { | ||
"Content-type": "application/json" | ||
...headers && normalizeHeaders(headers), | ||
// Keep these headers lowercase so they will override any user-supplied headers above. | ||
accept: "application/json", | ||
"content-length": body.length.toString(), | ||
"content-type": "application/json; charset=utf-8" | ||
}, | ||
method: "POST" | ||
method: "POST", | ||
signal | ||
}; | ||
let response; | ||
{ | ||
response = await src_default(url, requestInfo); | ||
} | ||
const response = await e(url, requestInfo); | ||
if (!response.ok) { | ||
@@ -74,7 +129,9 @@ throw new SolanaHttpError({ | ||
const overrides = { | ||
async send() { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
url: transportConfig.url | ||
@@ -93,6 +150,8 @@ }); | ||
const overrides = { | ||
async sendBatch() { | ||
async sendBatch(options) { | ||
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params)); | ||
const responses = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
url: transportConfig.url | ||
@@ -140,2 +199,5 @@ }); | ||
function createJsonRpcTransport(transportConfig) { | ||
if (__DEV__ && transportConfig.headers) { | ||
assertIsAllowedHttpRequestHeaders(transportConfig.headers); | ||
} | ||
return makeProxy(transportConfig); | ||
@@ -142,0 +204,0 @@ } |
@@ -1,3 +0,6 @@ | ||
import fetchImplNode from 'node-fetch'; | ||
import t from 'node-fetch'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// src/http-request-errors.ts | ||
@@ -14,14 +17,70 @@ var SolanaHttpError = class extends Error { | ||
}; | ||
async function makeHttpRequest({ payload, url }) { | ||
// src/http-request-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
accept: true, | ||
"content-length": true, | ||
"content-type": true | ||
}; | ||
var FORBIDDEN_HEADERS = { | ||
"accept-charset": true, | ||
"accept-encoding": true, | ||
"access-control-request-headers": true, | ||
"access-control-request-method": true, | ||
connection: true, | ||
"content-length": true, | ||
cookie: true, | ||
date: true, | ||
dnt: true, | ||
expect: true, | ||
host: true, | ||
"keep-alive": true, | ||
origin: true, | ||
"permissions-policy": true, | ||
// No currently available Typescript technique allows you to match on a prefix. | ||
// 'proxy-':true, | ||
// 'sec-':true, | ||
referer: true, | ||
te: true, | ||
trailer: true, | ||
"transfer-encoding": true, | ||
upgrade: true, | ||
via: true | ||
}; | ||
function assertIsAllowedHttpRequestHeaders(headers) { | ||
const badHeaders = Object.keys(headers).filter((headerName) => { | ||
const lowercaseHeaderName = headerName.toLowerCase(); | ||
return DISALLOWED_HEADERS[headerName.toLowerCase()] === true || FORBIDDEN_HEADERS[headerName.toLowerCase()] === true || lowercaseHeaderName.startsWith("proxy-") || lowercaseHeaderName.startsWith("sec-"); | ||
}); | ||
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.` | ||
); | ||
} | ||
} | ||
function normalizeHeaders(headers) { | ||
const out = {}; | ||
for (const headerName in headers) { | ||
out[headerName.toLowerCase()] = headers[headerName]; | ||
} | ||
return out; | ||
} | ||
var f = t; | ||
// src/http-request.ts | ||
async function makeHttpRequest({ headers, payload, signal, url }) { | ||
const body = JSON.stringify(payload); | ||
const requestInfo = { | ||
body: JSON.stringify(payload), | ||
body, | ||
headers: { | ||
"Content-type": "application/json" | ||
...headers && normalizeHeaders(headers), | ||
// Keep these headers lowercase so they will override any user-supplied headers above. | ||
accept: "application/json", | ||
"content-length": body.length.toString(), | ||
"content-type": "application/json; charset=utf-8" | ||
}, | ||
method: "POST" | ||
method: "POST", | ||
signal | ||
}; | ||
let response; | ||
{ | ||
response = await fetchImplNode(url, requestInfo); | ||
} | ||
const response = await f(url, requestInfo); | ||
if (!response.ok) { | ||
@@ -70,7 +129,9 @@ throw new SolanaHttpError({ | ||
const overrides = { | ||
async send() { | ||
async send(options) { | ||
const { methodName, params, responseProcessor } = pendingRequest; | ||
const payload = createJsonRpcMessage(methodName, params); | ||
const response = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
url: transportConfig.url | ||
@@ -89,6 +150,8 @@ }); | ||
const overrides = { | ||
async sendBatch() { | ||
async sendBatch(options) { | ||
const payload = pendingRequests.map(({ methodName, params }) => createJsonRpcMessage(methodName, params)); | ||
const responses = await makeHttpRequest({ | ||
headers: transportConfig.headers, | ||
payload, | ||
signal: options?.abortSignal, | ||
url: transportConfig.url | ||
@@ -136,2 +199,5 @@ }); | ||
function createJsonRpcTransport(transportConfig) { | ||
if (__DEV__ && transportConfig.headers) { | ||
assertIsAllowedHttpRequestHeaders(transportConfig.headers); | ||
} | ||
return makeProxy(transportConfig); | ||
@@ -138,0 +204,0 @@ } |
@@ -0,7 +1,10 @@ | ||
import { AllowedHttpRequestHeaders } from './http-request-headers'; | ||
type Config = Readonly<{ | ||
headers?: AllowedHttpRequestHeaders; | ||
payload: unknown; | ||
signal?: AbortSignal; | ||
url: string; | ||
}>; | ||
export declare function makeHttpRequest<TResponse>({ payload, url }: Config): Promise<TResponse>; | ||
export declare function makeHttpRequest<TResponse>({ headers, payload, signal, url }: Config): Promise<TResponse>; | ||
export {}; | ||
//# sourceMappingURL=http-request.d.ts.map |
@@ -0,1 +1,2 @@ | ||
import { AllowedHttpRequestHeaders } from '../http-request-headers'; | ||
/** | ||
@@ -7,5 +8,9 @@ * Public API. | ||
}; | ||
export type SendOptions = Readonly<{ | ||
abortSignal?: AbortSignal; | ||
}>; | ||
export type Transport<TRpcMethods> = TransportMethods<TRpcMethods>; | ||
export type TransportConfig<TRpcMethods> = Readonly<{ | ||
api: IRpcApi<TRpcMethods>; | ||
headers?: AllowedHttpRequestHeaders; | ||
url: string; | ||
@@ -19,7 +24,7 @@ }>; | ||
export interface ArmedTransportOwnMethods<TResponse> { | ||
send(): Promise<TResponse>; | ||
send(options?: SendOptions): Promise<TResponse>; | ||
} | ||
export type ArmedTransport<TRpcMethods, TResponse> = ArmedTransportMethods<TRpcMethods, TResponse> & ArmedTransportOwnMethods<TResponse>; | ||
export interface ArmedBatchTransportOwnMethods<TResponses> { | ||
sendBatch(): Promise<TResponses>; | ||
sendBatch(options?: SendOptions): Promise<TResponses>; | ||
} | ||
@@ -26,0 +31,0 @@ export type ArmedBatchTransport<TRpcMethods, TResponses extends unknown[]> = ArmedBatchTransportMethods<TRpcMethods, TResponses> & ArmedBatchTransportOwnMethods<TResponses>; |
{ | ||
"name": "@solana/rpc-transport", | ||
"version": "2.0.0-experimental.847f0a9", | ||
"version": "2.0.0-experimental.92a60c3", | ||
"description": "Network transports for accessing the Solana JSON RPC API", | ||
@@ -53,3 +53,2 @@ "exports": { | ||
"@types/jest": "^29.5.0", | ||
"@types/node-fetch": "2", | ||
"@typescript-eslint/eslint-plugin": "^5.57.1", | ||
@@ -64,3 +63,3 @@ "@typescript-eslint/parser": "^5.57.1", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"jest-fetch-mock": "^3.0.3", | ||
"jest-fetch-mock-fork": "^3.0.4", | ||
"jest-runner-eslint": "^2.0.0", | ||
@@ -72,7 +71,6 @@ "jest-runner-prettier": "^1.0.0", | ||
"tsup": "6.7.0", | ||
"turbo": "^1.6.3", | ||
"typescript": "^5.0.3", | ||
"version-from-git": "^1.1.1", | ||
"@solana/fetch-impl-browser": "0.0.0-development", | ||
"build-scripts": "0.0.0", | ||
"fetch-impl": "0.0.0", | ||
"test-config": "0.0.0", | ||
@@ -90,4 +88,3 @@ "tsconfig": "0.0.0" | ||
"dependencies": { | ||
"node-fetch": "^2.6.7", | ||
"@solana/keys": "2.0.0-experimental.847f0a9" | ||
"node-fetch": "^3.3.1" | ||
}, | ||
@@ -94,0 +91,0 @@ "scripts": { |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
147852
1
26
1322
0
22
+ Addeddata-uri-to-buffer@4.0.1(transitive)
+ Addedfetch-blob@3.2.0(transitive)
+ Addedformdata-polyfill@4.0.10(transitive)
+ Addednode-domexception@1.0.0(transitive)
+ Addednode-fetch@3.3.2(transitive)
+ Addedweb-streams-polyfill@3.3.3(transitive)
- Removed@solana/keys@2.0.0-experimental.847f0a9(transitive)
- Removedbase-x@4.0.0(transitive)
- Removedbs58@5.0.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
Updatednode-fetch@^3.3.1