Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Aug 25, 2024
1 parent ca3c8a5 commit b9ad536
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 32 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-e165d6d6b700d6d0c120d3e71a4a89dbae1a400ede3ba11423b0cf1c24091644.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/new%2Fblockaid-0e40c0f74d67ae7c457e8b74f8b02620b5bdfb14f624ed7cbc46ecd74059a3ac.yml
5 changes: 4 additions & 1 deletion tests/api-resources/bitcoin/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/evm/json-rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/evm/post-transaction-bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/evm/post-transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/evm/transaction-bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/evm/transaction-raw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/evm/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/evm/user-operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/site.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/solana/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/solana/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/starknet/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/stellar/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/token-bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

const client = new Blockaid({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' });
const client = new Blockaid({
apiKey: 'My API Key',
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: 4 additions & 1 deletion tests/api-resources/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import Blockaid from '@blockaid/client';
import { Response } from 'node-fetch';

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

describe('resource token', () => {
test('report: only required params', async () => {
Expand Down
60 changes: 44 additions & 16 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('instantiate client', () => {
const client = new Blockaid({
baseURL: 'http://localhost:5000/',
defaultHeaders: { 'X-My-Default-Header': '2' },
apiKey: 'My API Key',
});

test('they are used in the request', () => {
Expand Down Expand Up @@ -51,27 +52,37 @@ describe('instantiate client', () => {

describe('defaultQuery', () => {
test('with null query params given', () => {
const client = new Blockaid({ baseURL: 'http://localhost:5000/', defaultQuery: { apiVersion: 'foo' } });
const client = new Blockaid({
baseURL: 'http://localhost:5000/',
defaultQuery: { apiVersion: 'foo' },
apiKey: 'My API Key',
});
expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/foo?apiVersion=foo');
});

test('multiple default query params', () => {
const client = new Blockaid({
baseURL: 'http://localhost:5000/',
defaultQuery: { apiVersion: 'foo', hello: 'world' },
apiKey: 'My API Key',
});
expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/foo?apiVersion=foo&hello=world');
});

test('overriding with `undefined`', () => {
const client = new Blockaid({ baseURL: 'http://localhost:5000/', defaultQuery: { hello: 'world' } });
const client = new Blockaid({
baseURL: 'http://localhost:5000/',
defaultQuery: { hello: 'world' },
apiKey: 'My API Key',
});
expect(client.buildURL('/foo', { hello: undefined })).toEqual('http://localhost:5000/foo');
});
});

test('custom fetch', async () => {
const client = new Blockaid({
baseURL: 'http://localhost:5000/',
apiKey: 'My API Key',
fetch: (url) => {
return Promise.resolve(
new Response(JSON.stringify({ url, custom: true }), {
Expand All @@ -88,6 +99,7 @@ describe('instantiate client', () => {
test('custom signal', async () => {
const client = new Blockaid({
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
fetch: (...args) => {
return new Promise((resolve, reject) =>
setTimeout(
Expand All @@ -112,12 +124,12 @@ describe('instantiate client', () => {

describe('baseUrl', () => {
test('trailing slash', () => {
const client = new Blockaid({ baseURL: 'http://localhost:5000/custom/path/' });
const client = new Blockaid({ baseURL: 'http://localhost:5000/custom/path/', apiKey: 'My API Key' });
expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/custom/path/foo');
});

test('no trailing slash', () => {
const client = new Blockaid({ baseURL: 'http://localhost:5000/custom/path' });
const client = new Blockaid({ baseURL: 'http://localhost:5000/custom/path', apiKey: 'My API Key' });
expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/custom/path/foo');
});

Expand All @@ -126,52 +138,68 @@ describe('instantiate client', () => {
});

test('explicit option', () => {
const client = new Blockaid({ baseURL: 'https://example.com' });
const client = new Blockaid({ baseURL: 'https://example.com', apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://example.com');
});

test('env variable', () => {
process.env['BLOCKAID_BASE_URL'] = 'https://example.com/from_env';
const client = new Blockaid({});
const client = new Blockaid({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://example.com/from_env');
});

test('empty env variable', () => {
process.env['BLOCKAID_BASE_URL'] = ''; // empty
const client = new Blockaid({});
const client = new Blockaid({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://api.blockaid.io');
});

test('blank env variable', () => {
process.env['BLOCKAID_BASE_URL'] = ' '; // blank
const client = new Blockaid({});
const client = new Blockaid({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://api.blockaid.io');
});

test('env variable with environment', () => {
process.env['BLOCKAID_BASE_URL'] = 'https://example.com/from_env';

expect(() => new Blockaid({ environment: 'production' })).toThrowErrorMatchingInlineSnapshot(
expect(
() => new Blockaid({ apiKey: 'My API Key', environment: 'production' }),
).toThrowErrorMatchingInlineSnapshot(
`"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"`,
);

const client = new Blockaid({ baseURL: null, environment: 'production' });
const client = new Blockaid({ apiKey: 'My API Key', baseURL: null, environment: 'production' });
expect(client.baseURL).toEqual('https://api.blockaid.io');
});
});

test('maxRetries option is correctly set', () => {
const client = new Blockaid({ maxRetries: 4 });
const client = new Blockaid({ maxRetries: 4, apiKey: 'My API Key' });
expect(client.maxRetries).toEqual(4);

// default
const client2 = new Blockaid({});
const client2 = new Blockaid({ apiKey: 'My API Key' });
expect(client2.maxRetries).toEqual(2);
});

test('with environment variable arguments', () => {
// set options via env var
process.env['BLOCKAID_CLIENT_API_KEY'] = 'My API Key';
const client = new Blockaid();
expect(client.apiKey).toBe('My API Key');
});

test('with overriden environment variable arguments', () => {
// set options via env var
process.env['BLOCKAID_CLIENT_API_KEY'] = 'another My API Key';
const client = new Blockaid({ apiKey: 'My API Key' });
expect(client.apiKey).toBe('My API Key');
});
});

describe('request building', () => {
const client = new Blockaid({});
const client = new Blockaid({ apiKey: 'My API Key' });

describe('Content-Length', () => {
test('handles multi-byte characters', () => {
Expand Down Expand Up @@ -213,7 +241,7 @@ describe('retries', () => {
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};

const client = new Blockaid({ timeout: 10, fetch: testFetch });
const client = new Blockaid({ apiKey: 'My API Key', timeout: 10, fetch: testFetch });

expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });
expect(count).toEqual(2);
Expand All @@ -240,7 +268,7 @@ describe('retries', () => {
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};

const client = new Blockaid({ fetch: testFetch });
const client = new Blockaid({ apiKey: 'My API Key', fetch: testFetch });

expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });
expect(count).toEqual(2);
Expand All @@ -267,7 +295,7 @@ describe('retries', () => {
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};

const client = new Blockaid({ fetch: testFetch });
const client = new Blockaid({ apiKey: 'My API Key', fetch: testFetch });

expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });
expect(count).toEqual(2);
Expand Down

0 comments on commit b9ad536

Please sign in to comment.