From 5fd3ab7b3334daf0ddd12e4319ccd6d8f9c9f071 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 23 Aug 2024 20:10:04 +0000 Subject: [PATCH] feat(api): manual updates (#219) --- README.md | 2 -- src/index.ts | 27 ++------------------------- tests/index.test.ts | 13 ------------- 3 files changed, 2 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 8dbf9b6f..b8acb8d8 100755 --- a/README.md +++ b/README.md @@ -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: 'sandbox', // defaults to 'production' }); async function main() { @@ -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: 'sandbox', // defaults to 'production' }); async function main() { diff --git a/src/index.ts b/src/index.ts index 99c8c462..0bd4f564 100755 --- a/src/index.ts +++ b/src/index.ts @@ -6,27 +6,12 @@ import { type Agent } from './_shims/index'; import * as Core from './core'; import * as API from './resources/index'; -const environments = { - production: 'https://api.blockaid.io', - sandbox: 'text', -}; -type Environment = keyof typeof environments; - export interface ClientOptions { /** * Defaults to process.env['BLOCKAID_CLIENT_API_KEY']. */ apiKey?: string | undefined; - /** - * Specifies the environment to use for the API. - * - * Each environment maps to a different base URL: - * - `production` corresponds to `https://api.blockaid.io` - * - `sandbox` corresponds to `text` - */ - environment?: Environment; - /** * Override the default base URL for the API, e.g., "https://api.example.com/v2/" * @@ -96,7 +81,6 @@ export class Blockaid extends Core.APIClient { * API Client for interfacing with the Blockaid API. * * @param {string | undefined} [opts.apiKey=process.env['BLOCKAID_CLIENT_API_KEY'] ?? undefined] - * @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. @@ -119,18 +103,11 @@ export class Blockaid extends Core.APIClient { const options: ClientOptions = { apiKey, ...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, diff --git a/tests/index.test.ts b/tests/index.test.ts index d4b31dc5..78259459 100755 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -159,19 +159,6 @@ describe('instantiate client', () => { 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({ 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({ apiKey: 'My API Key', baseURL: null, environment: 'production' }); - expect(client.baseURL).toEqual('https://api.blockaid.io'); - }); }); test('maxRetries option is correctly set', () => {