Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Aug 21, 2024
1 parent 8b9c997 commit 0b32a8b
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 19
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/new%2Fblockaid-5e4d0576b2d38134571cb327258a600c25f8caa892fe15739b0c6dd6f0af182c.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/new%2Fblockaid-d12231e708d72c768cb8fbda6c19928542f3f854c6e916c1cfb27b50885cfff2.yml
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ The full API of this library can be found in [api.md](api.md).
```js
import Blockaid from '@blockaid/client';

const client = new Blockaid();
const client = new Blockaid({
environment: 'direct', // defaults to 'production'
});

async function main() {
const transactionScanResponse = await client.evm.jsonRpc.scan({
Expand Down Expand Up @@ -51,7 +53,9 @@ This library includes TypeScript definitions for all request params and response
```ts
import Blockaid from '@blockaid/client';

const client = new Blockaid();
const client = new Blockaid({
environment: 'direct', // defaults to 'production'
});

async function main() {
const params: Blockaid.Evm.JsonRpcScanParams = {
Expand Down Expand Up @@ -134,7 +138,6 @@ You can use the `maxRetries` option to configure or disable this:
// Configure the default for all requests:
const client = new Blockaid({
maxRetries: 0, // default is 2
apiKey: 'My API Key',
});

// Or, configure per-request:
Expand All @@ -152,7 +155,6 @@ Requests time out after 1 minute by default. You can configure this with a `time
// Configure the default for all requests:
const client = new Blockaid({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
apiKey: 'My API Key',
});

// Override per-request:
Expand Down Expand Up @@ -308,7 +310,6 @@ import { HttpsProxyAgent } from 'https-proxy-agent';
// Configure the default for all requests:
const client = new Blockaid({
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
apiKey: 'My API Key',
});

// Override per-request:
Expand Down
53 changes: 40 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,31 @@ import { type Agent } from './_shims/index';
import * as Core from './core';
import * as API from './resources/index';

const environments = {
production: 'https://api.blockaid.io',
direct: 'https://direct.api.blockaid.io',
};
type Environment = keyof typeof environments;

export interface ClientOptions {
/**
* Defaults to process.env['BLOCKAID_CLIENT_API_KEY'].
* Authentication method to api.blockaid.io
*/
apiKey?: string | null | undefined;

/**
* Authentication method to direct.api.blockaid.io
*/
clientId?: string | null | undefined;

/**
* Specifies the environment to use for the API.
*
* Each environment maps to a different base URL:
* - `production` corresponds to `https://api.blockaid.io`
* - `direct` corresponds to `https://direct.api.blockaid.io`
*/
apiKey?: string | undefined;
environment?: Environment;

/**
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
Expand Down Expand Up @@ -73,14 +93,17 @@ export interface ClientOptions {
* API Client for interfacing with the Blockaid API.
*/
export class Blockaid extends Core.APIClient {
apiKey: string;
apiKey: string | null;
clientId: string | null;

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 | null | undefined} [opts.apiKey=process.env['BLOCKAID_CLIENT_API_KEY'] ?? null]
* @param {string | null | undefined} [opts.clientId=process.env['BLOCKAID_CLIENT_ID_KEY'] ?? null]
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
* @param {string} [opts.baseURL=process.env['BLOCKAID_BASE_URL'] ?? https://api.blockaid.io] - 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.
Expand All @@ -91,23 +114,26 @@ export class Blockaid extends Core.APIClient {
*/
constructor({
baseURL = Core.readEnv('BLOCKAID_BASE_URL'),
apiKey = Core.readEnv('BLOCKAID_CLIENT_API_KEY'),
apiKey = Core.readEnv('BLOCKAID_CLIENT_API_KEY') ?? null,
clientId = Core.readEnv('BLOCKAID_CLIENT_ID_KEY') ?? null,
...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,
clientId,
...opts,
baseURL: baseURL || `https://api.blockaid.io`,
baseURL,
environment: opts.environment ?? 'production',
};

if (baseURL && opts.environment) {
throw new Errors.BlockaidError(
'Ambiguous URL; The `baseURL` option (or BLOCKAID_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
);
}

super({
baseURL: options.baseURL!,
baseURL: options.baseURL || environments[options.environment || 'production'],
timeout: options.timeout ?? 60000 /* 1 minute */,
httpAgent: options.httpAgent,
maxRetries: options.maxRetries,
Expand All @@ -117,6 +143,7 @@ export class Blockaid extends Core.APIClient {
this._options = options;

this.apiKey = apiKey;
this.clientId = clientId;
}

evm: API.Evm = new API.Evm(this);
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/bitcoin/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource transaction', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/evm/json-rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource jsonRpc', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/evm/post-transaction-bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource postTransactionBulk', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/evm/post-transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource postTransaction', () => {
test('report: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/evm/transaction-bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource transactionBulk', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/evm/transaction-raw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource transactionRaw', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/evm/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource transaction', () => {
test('report: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/evm/user-operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource userOperation', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/site.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource site', () => {
test('report: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/solana/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource address', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/solana/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource message', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/starknet/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource transaction', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/stellar/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource transaction', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/token-bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource tokenBulk', () => {
test('scan: only required params', async () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/api-resources/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });

describe('resource token', () => {
test('report: only required params', async () => {
Expand Down
Loading

0 comments on commit 0b32a8b

Please sign in to comment.