From ccc675e73aa38ba8770040947885cc88cc9e56dc Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 5 May 2024 08:24:43 +0000 Subject: [PATCH] feat(api): OpenAPI spec update via Stainless API (#6) --- .stats.yml | 2 +- api.md | 1 + src/client.ts | 187 ------------------------- src/index.ts | 192 +++++++++++++++++++++++++- src/resources/evm/evm.ts | 19 +++ src/resources/evm/index.ts | 1 + src/resources/evm/json-rpc.ts | 4 +- src/resources/evm/transaction-bulk.ts | 4 +- src/resources/evm/transaction-raw.ts | 4 +- src/resources/evm/transaction.ts | 4 +- src/resources/evm/user-operation.ts | 4 +- src/resources/index.ts | 1 + 12 files changed, 219 insertions(+), 204 deletions(-) delete mode 100644 src/client.ts diff --git a/.stats.yml b/.stats.yml index ce24876..853db1c 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 6 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/new%2Fblockaid-35e92c2ca8e7a8cd7c2f58d0fe2f217585365bd24e68c6ee61b9f11a1cbf68a7.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/new%2Fblockaid-0a3a1edcd6cde656bca8286fc360c0fd563e4799386d109ada1a440c0c23af14.yml diff --git a/api.md b/api.md index 6a2d2a7..3e0b7df 100644 --- a/api.md +++ b/api.md @@ -16,6 +16,7 @@ Types: - Metadata - NativeDiff - NonercTokenDetails +- SupportedChain - TransactionBulkResponse - TransactionScanFeature - TransactionScanResponse diff --git a/src/client.ts b/src/client.ts deleted file mode 100644 index 689d44d..0000000 --- a/src/client.ts +++ /dev/null @@ -1,187 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -import * as Core from './core'; -import * as Errors from './error'; -import { type Agent } from './_shims/index'; -import * as Uploads from './uploads'; -import * as API from '@blockaid/client/resources/index'; - -export interface ClientOptions { - /** - * Defaults to process.env['BLOCKAID_CLIENT_API_KEY']. - */ - apiKey?: string | undefined; - - /** - * Override the default base URL for the API, e.g., "https://api.example.com/v2/" - * - * Defaults to process.env['BLOCKAID_BASE_URL']. - */ - baseURL?: string | null | undefined; - - /** - * The maximum amount of time (in milliseconds) that the client should wait for a response - * from the server before timing out a single request. - * - * Note that request timeouts are retried by default, so in a worst-case scenario you may wait - * much longer than this timeout before the promise succeeds or fails. - */ - timeout?: number; - - /** - * An HTTP agent used to manage HTTP(S) connections. - * - * If not provided, an agent will be constructed by default in the Node.js environment, - * otherwise no agent is used. - */ - httpAgent?: Agent; - - /** - * Specify a custom `fetch` function implementation. - * - * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is - * defined globally. - */ - fetch?: Core.Fetch | undefined; - - /** - * The maximum number of times that the client will retry a request in case of a - * temporary failure, like a network error or a 5XX error from the server. - * - * @default 2 - */ - maxRetries?: number; - - /** - * Default headers to include with every request to the API. - * - * These can be removed in individual requests by explicitly setting the - * header to `undefined` or `null` in request options. - */ - defaultHeaders?: Core.Headers; - - /** - * Default query parameters to include with every request to the API. - * - * These can be removed in individual requests by explicitly setting the - * param to `undefined` in request options. - */ - defaultQuery?: Core.DefaultQuery; -} - -/** API Client for interfacing with the Blockaid API. */ -export class Blockaid extends Core.APIClient { - apiKey: string; - - private _options: ClientOptions; - - /** - * API Client for interfacing with the Blockaid API. - * - * @param {string | undefined} [opts.apiKey=process.env['BLOCKAID_CLIENT_API_KEY'] ?? undefined] - * @param {string} [opts.baseURL=process.env['BLOCKAID_BASE_URL'] ?? https://api.blockaid.io/v0] - Override the default base URL for the API. - * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. - * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections. - * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. - * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. - * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API. - * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API. - */ - constructor({ - baseURL = Core.readEnv('BLOCKAID_BASE_URL'), - apiKey = Core.readEnv('BLOCKAID_CLIENT_API_KEY'), - ...opts - }: ClientOptions = {}) { - if (apiKey === undefined) { - throw new Errors.BlockaidError( - "The BLOCKAID_CLIENT_API_KEY environment variable is missing or empty; either provide it, or instantiate the Blockaid client with an apiKey option, like new Blockaid({ apiKey: 'My API Key' }).", - ); - } - - const options: ClientOptions = { - apiKey, - ...opts, - baseURL: baseURL || `https://api.blockaid.io/v0`, - }; - - super({ - baseURL: options.baseURL!, - timeout: options.timeout ?? 60000 /* 1 minute */, - httpAgent: options.httpAgent, - maxRetries: options.maxRetries, - fetch: options.fetch, - }); - this._options = options; - - this.apiKey = apiKey; - } - - evm: API.Evm = new API.Evm(this); - site: API.Site = new API.Site(this); - - protected override defaultQuery(): Core.DefaultQuery | undefined { - return this._options.defaultQuery; - } - - protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers { - return { - ...super.defaultHeaders(opts), - ...this._options.defaultHeaders, - }; - } - - protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers { - return { 'X-API-Key': this.apiKey }; - } - - static Blockaid = this; - - static BlockaidError = Errors.BlockaidError; - static APIError = Errors.APIError; - static APIConnectionError = Errors.APIConnectionError; - static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError; - static APIUserAbortError = Errors.APIUserAbortError; - static NotFoundError = Errors.NotFoundError; - static ConflictError = Errors.ConflictError; - static RateLimitError = Errors.RateLimitError; - static BadRequestError = Errors.BadRequestError; - static AuthenticationError = Errors.AuthenticationError; - static InternalServerError = Errors.InternalServerError; - static PermissionDeniedError = Errors.PermissionDeniedError; - static UnprocessableEntityError = Errors.UnprocessableEntityError; - - static toFile = Uploads.toFile; - static fileFromPath = Uploads.fileFromPath; -} - -export namespace Blockaid { - export import RequestOptions = Core.RequestOptions; - - export import Evm = API.Evm; - export import AddressAssetDiff = API.AddressAssetDiff; - export import AddressAssetExposure = API.AddressAssetExposure; - export import Erc1155Diff = API.Erc1155Diff; - export import Erc1155Exposure = API.Erc1155Exposure; - export import Erc1155TokenDetails = API.Erc1155TokenDetails; - export import Erc20Diff = API.Erc20Diff; - export import Erc20Exposure = API.Erc20Exposure; - export import Erc20TokenDetails = API.Erc20TokenDetails; - export import Erc721Diff = API.Erc721Diff; - export import Erc721Exposure = API.Erc721Exposure; - export import Erc721TokenDetails = API.Erc721TokenDetails; - export import Metadata = API.Metadata; - export import NativeDiff = API.NativeDiff; - export import NonercTokenDetails = API.NonercTokenDetails; - export import TransactionBulkResponse = API.TransactionBulkResponse; - export import TransactionScanFeature = API.TransactionScanFeature; - export import TransactionScanResponse = API.TransactionScanResponse; - export import TransactionSimulation = API.TransactionSimulation; - export import TransactionValidation = API.TransactionValidation; - export import UsdDiff = API.UsdDiff; - - export import Site = API.Site; - export import SiteScanHitResponse = API.SiteScanHitResponse; - export import SiteScanMissResponse = API.SiteScanMissResponse; - export import SiteScanResponse = API.SiteScanResponse; - export import SiteScanParams = API.SiteScanParams; -} diff --git a/src/index.ts b/src/index.ts index 56da5e1..3cad70e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,158 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +import * as Core from './core'; import * as Errors from './error'; +import { type Agent } from './_shims/index'; import * as Uploads from './uploads'; -import { Blockaid } from './client'; +import * as API from '@blockaid/client/resources/index'; -export { Blockaid }; -export default Blockaid; +export interface ClientOptions { + /** + * Defaults to process.env['BLOCKAID_CLIENT_API_KEY']. + */ + apiKey?: string | undefined; -export import toFile = Uploads.toFile; -export import fileFromPath = Uploads.fileFromPath; + /** + * Override the default base URL for the API, e.g., "https://api.example.com/v2/" + * + * Defaults to process.env['BLOCKAID_BASE_URL']. + */ + baseURL?: string | null | undefined; + + /** + * The maximum amount of time (in milliseconds) that the client should wait for a response + * from the server before timing out a single request. + * + * Note that request timeouts are retried by default, so in a worst-case scenario you may wait + * much longer than this timeout before the promise succeeds or fails. + */ + timeout?: number; + + /** + * An HTTP agent used to manage HTTP(S) connections. + * + * If not provided, an agent will be constructed by default in the Node.js environment, + * otherwise no agent is used. + */ + httpAgent?: Agent; + + /** + * Specify a custom `fetch` function implementation. + * + * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is + * defined globally. + */ + fetch?: Core.Fetch | undefined; + + /** + * The maximum number of times that the client will retry a request in case of a + * temporary failure, like a network error or a 5XX error from the server. + * + * @default 2 + */ + maxRetries?: number; + + /** + * Default headers to include with every request to the API. + * + * These can be removed in individual requests by explicitly setting the + * header to `undefined` or `null` in request options. + */ + defaultHeaders?: Core.Headers; + + /** + * Default query parameters to include with every request to the API. + * + * These can be removed in individual requests by explicitly setting the + * param to `undefined` in request options. + */ + defaultQuery?: Core.DefaultQuery; +} + +/** API Client for interfacing with the Blockaid API. */ +export class Blockaid extends Core.APIClient { + apiKey: string; + + private _options: ClientOptions; + + /** + * API Client for interfacing with the Blockaid API. + * + * @param {string | undefined} [opts.apiKey=process.env['BLOCKAID_CLIENT_API_KEY'] ?? undefined] + * @param {string} [opts.baseURL=process.env['BLOCKAID_BASE_URL'] ?? https://api.blockaid.io/v0] - Override the default base URL for the API. + * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. + * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections. + * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. + * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. + * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API. + * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API. + */ + constructor({ + baseURL = Core.readEnv('BLOCKAID_BASE_URL'), + apiKey = Core.readEnv('BLOCKAID_CLIENT_API_KEY'), + ...opts + }: ClientOptions = {}) { + if (apiKey === undefined) { + throw new Errors.BlockaidError( + "The BLOCKAID_CLIENT_API_KEY environment variable is missing or empty; either provide it, or instantiate the Blockaid client with an apiKey option, like new Blockaid({ apiKey: 'My API Key' }).", + ); + } + + const options: ClientOptions = { + apiKey, + ...opts, + baseURL: baseURL || `https://api.blockaid.io/v0`, + }; + + super({ + baseURL: options.baseURL!, + timeout: options.timeout ?? 60000 /* 1 minute */, + httpAgent: options.httpAgent, + maxRetries: options.maxRetries, + fetch: options.fetch, + }); + this._options = options; + + this.apiKey = apiKey; + } + + evm: API.Evm = new API.Evm(this); + site: API.Site = new API.Site(this); + + protected override defaultQuery(): Core.DefaultQuery | undefined { + return this._options.defaultQuery; + } + + protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers { + return { + ...super.defaultHeaders(opts), + ...this._options.defaultHeaders, + }; + } + + protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers { + return { 'X-API-Key': this.apiKey }; + } + + static Blockaid = this; + + static BlockaidError = Errors.BlockaidError; + static APIError = Errors.APIError; + static APIConnectionError = Errors.APIConnectionError; + static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError; + static APIUserAbortError = Errors.APIUserAbortError; + static NotFoundError = Errors.NotFoundError; + static ConflictError = Errors.ConflictError; + static RateLimitError = Errors.RateLimitError; + static BadRequestError = Errors.BadRequestError; + static AuthenticationError = Errors.AuthenticationError; + static InternalServerError = Errors.InternalServerError; + static PermissionDeniedError = Errors.PermissionDeniedError; + static UnprocessableEntityError = Errors.UnprocessableEntityError; + + static toFile = Uploads.toFile; + static fileFromPath = Uploads.fileFromPath; +} export const { BlockaidError, @@ -26,4 +170,40 @@ export const { UnprocessableEntityError, } = Errors; -export * from './client'; +export import toFile = Uploads.toFile; +export import fileFromPath = Uploads.fileFromPath; + +export namespace Blockaid { + export import RequestOptions = Core.RequestOptions; + + export import Evm = API.Evm; + export import AddressAssetDiff = API.AddressAssetDiff; + export import AddressAssetExposure = API.AddressAssetExposure; + export import Erc1155Diff = API.Erc1155Diff; + export import Erc1155Exposure = API.Erc1155Exposure; + export import Erc1155TokenDetails = API.Erc1155TokenDetails; + export import Erc20Diff = API.Erc20Diff; + export import Erc20Exposure = API.Erc20Exposure; + export import Erc20TokenDetails = API.Erc20TokenDetails; + export import Erc721Diff = API.Erc721Diff; + export import Erc721Exposure = API.Erc721Exposure; + export import Erc721TokenDetails = API.Erc721TokenDetails; + export import Metadata = API.Metadata; + export import NativeDiff = API.NativeDiff; + export import NonercTokenDetails = API.NonercTokenDetails; + export import SupportedChain = API.SupportedChain; + export import TransactionBulkResponse = API.TransactionBulkResponse; + export import TransactionScanFeature = API.TransactionScanFeature; + export import TransactionScanResponse = API.TransactionScanResponse; + export import TransactionSimulation = API.TransactionSimulation; + export import TransactionValidation = API.TransactionValidation; + export import UsdDiff = API.UsdDiff; + + export import Site = API.Site; + export import SiteScanHitResponse = API.SiteScanHitResponse; + export import SiteScanMissResponse = API.SiteScanMissResponse; + export import SiteScanResponse = API.SiteScanResponse; + export import SiteScanParams = API.SiteScanParams; +} + +export default Blockaid; diff --git a/src/resources/evm/evm.ts b/src/resources/evm/evm.ts index 9f0d3ef..2da764c 100644 --- a/src/resources/evm/evm.ts +++ b/src/resources/evm/evm.ts @@ -341,6 +341,24 @@ export interface NonercTokenDetails { symbol?: string; } +/** + * An enumeration. + */ +export type SupportedChain = + | 'arbitrum' + | 'avalanche' + | 'base' + | 'base-sepolia' + | 'bsc' + | 'ethereum' + | 'optimism' + | 'polygon' + | 'zksync' + | 'zora' + | 'linea' + | 'blast' + | 'unknown'; + export interface TransactionBulkResponse { block?: string; @@ -647,6 +665,7 @@ export namespace Evm { export import Metadata = EvmAPI.Metadata; export import NativeDiff = EvmAPI.NativeDiff; export import NonercTokenDetails = EvmAPI.NonercTokenDetails; + export import SupportedChain = EvmAPI.SupportedChain; export import TransactionBulkResponse = EvmAPI.TransactionBulkResponse; export import TransactionScanFeature = EvmAPI.TransactionScanFeature; export import TransactionScanResponse = EvmAPI.TransactionScanResponse; diff --git a/src/resources/evm/index.ts b/src/resources/evm/index.ts index 680817b..1c549c7 100644 --- a/src/resources/evm/index.ts +++ b/src/resources/evm/index.ts @@ -15,6 +15,7 @@ export { Metadata, NativeDiff, NonercTokenDetails, + SupportedChain, TransactionBulkResponse, TransactionScanFeature, TransactionScanResponse, diff --git a/src/resources/evm/json-rpc.ts b/src/resources/evm/json-rpc.ts index a0389b7..0be52ac 100644 --- a/src/resources/evm/json-rpc.ts +++ b/src/resources/evm/json-rpc.ts @@ -21,9 +21,9 @@ export class JsonRpc extends APIResource { export interface JsonRpcScanParams { /** - * The chain name + * An enumeration. */ - chain: string; + chain: EvmAPI.SupportedChain; /** * JSON-RPC request that was received by the wallet. diff --git a/src/resources/evm/transaction-bulk.ts b/src/resources/evm/transaction-bulk.ts index 5a2c3ae..8d1ef80 100644 --- a/src/resources/evm/transaction-bulk.ts +++ b/src/resources/evm/transaction-bulk.ts @@ -24,9 +24,9 @@ export type TransactionBulkScanResponse = Array; export interface TransactionBulkScanParams { /** - * The chain name + * An enumeration. */ - chain: string; + chain: EvmAPI.SupportedChain; /** * Transaction bulk parameters diff --git a/src/resources/evm/transaction-raw.ts b/src/resources/evm/transaction-raw.ts index a458c73..86fa6b9 100644 --- a/src/resources/evm/transaction-raw.ts +++ b/src/resources/evm/transaction-raw.ts @@ -27,9 +27,9 @@ export interface TransactionRawScanParams { account_address: string; /** - * The chain name + * An enumeration. */ - chain: string; + chain: EvmAPI.SupportedChain; /** * Hex string of the raw transaction data diff --git a/src/resources/evm/transaction.ts b/src/resources/evm/transaction.ts index 0cedfa3..89102ab 100644 --- a/src/resources/evm/transaction.ts +++ b/src/resources/evm/transaction.ts @@ -27,9 +27,9 @@ export interface TransactionScanParams { account_address: string; /** - * The chain name + * An enumeration. */ - chain: string; + chain: EvmAPI.SupportedChain; /** * Transaction parameters diff --git a/src/resources/evm/user-operation.ts b/src/resources/evm/user-operation.ts index 7f7ac01..dadf3f4 100644 --- a/src/resources/evm/user-operation.ts +++ b/src/resources/evm/user-operation.ts @@ -21,9 +21,9 @@ export class UserOperation extends APIResource { export interface UserOperationScanParams { /** - * The chain name + * An enumeration. */ - chain: string; + chain: EvmAPI.SupportedChain; /** * The user operation request that was received by the wallet diff --git a/src/resources/index.ts b/src/resources/index.ts index 7817ab9..f2e63cd 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -15,6 +15,7 @@ export { Metadata, NativeDiff, NonercTokenDetails, + SupportedChain, TransactionBulkResponse, TransactionScanFeature, TransactionScanResponse,