Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and Stainless Bot committed Aug 21, 2024
1 parent 0d40bff commit d0947ca
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 132 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-84392d5435837ba78c74394f5a4ffef0d321c39a1a0bcfbae757d5c7ea05a5af.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/new%2Fblockaid-29480a66e8a72214e787b87da7b894ec067f43f2487b276b21f045f90c2a2ff6.yml
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Blockaid from '@blockaid/client';

const client = new Blockaid({
apiKey: process.env['BLOCKAID_CLIENT_API_KEY'], // This is the default and can be omitted
environment: 'direct', // defaults to 'production'
});

async function main() {
Expand Down Expand Up @@ -56,7 +55,6 @@ import Blockaid from '@blockaid/client';

const client = new Blockaid({
apiKey: process.env['BLOCKAID_CLIENT_API_KEY'], // This is the default and can be omitted
environment: 'direct', // defaults to 'production'
});

async function main() {
Expand Down
69 changes: 13 additions & 56 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,11 @@ 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 {
/**
* Authentication method to api.blockaid.io
*/
apiKey?: string | null | undefined;

/**
* Authentication method to direct.api.blockaid.io
* Defaults to process.env['BLOCKAID_CLIENT_API_KEY'].
*/
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`
*/
environment?: Environment;
apiKey?: string | undefined;

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

private _options: ClientOptions;

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

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

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

evm: API.Evm = new API.Evm(this);
Expand All @@ -166,23 +139,7 @@ export class Blockaid extends Core.APIClient {
};
}

protected override validateHeaders(headers: Core.Headers, customHeaders: Core.Headers) {
if (this.apiKey && headers['x-api-key']) {
return;
}
if (customHeaders['x-api-key'] === null) {
return;
}

throw new Error(
'Could not resolve authentication method. Expected the apiKey to be set. Or for the "X-API-Key" headers to be explicitly omitted',
);
}

protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
if (this.apiKey == null) {
return {};
}
return { 'X-API-Key': this.apiKey };
}

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/bitcoin/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/evm/json-rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/evm/post-transaction-bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/evm/post-transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/evm/transaction-bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/evm/transaction-raw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/evm/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/evm/user-operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/site.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/solana/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/solana/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/starknet/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/stellar/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/token-bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
1 change: 0 additions & 1 deletion tests/api-resources/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Response } from 'node-fetch';

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

Expand Down
Loading

0 comments on commit d0947ca

Please sign in to comment.