diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 17473a2..b3b5e58 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.3" + ".": "0.1.0-alpha.4" } diff --git a/.stats.yml b/.stats.yml index a4796bb..79f3b26 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/find-ai%2Ffind-ai-f45934597cf41099fa75c9b28ddb560d912602d210d2411f861dd6973b6fd8d4.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/find-ai%2Ffind-ai-bf9b5b8a950e0a79b0bf1911bf01feb5a3575113be8f5d24f7b487351f3470c5.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index dd594d3..75d442e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.1.0-alpha.4 (2024-09-26) + +Full Changelog: [v0.1.0-alpha.3...v0.1.0-alpha.4](https://github.com/Find-AI/find-ai-node/compare/v0.1.0-alpha.3...v0.1.0-alpha.4) + +### Features + +* **api:** manual updates updated ([#11](https://github.com/Find-AI/find-ai-node/issues/11)) ([b31020a](https://github.com/Find-AI/find-ai-node/commit/b31020aae1e3aba52c213f3ac6bdb9106214a6e2)) + ## 0.1.0-alpha.3 (2024-09-26) Full Changelog: [v0.1.0-alpha.2...v0.1.0-alpha.3](https://github.com/Find-AI/find-ai-node/compare/v0.1.0-alpha.2...v0.1.0-alpha.3) diff --git a/README.md b/README.md index 78d9029..8ddbe25 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,9 @@ The full API of this library can be found in [api.md](api.md). ```js import FindAI from 'find-ai'; -const client = new FindAI(); +const client = new FindAI({ + apiKey: process.env['FIND_AI_API_KEY'], // This is the default and can be omitted +}); async function main() { const searches = await client.searches.retrieve('id'); @@ -39,7 +41,9 @@ This library includes TypeScript definitions for all request params and response ```ts import FindAI from 'find-ai'; -const client = new FindAI(); +const client = new FindAI({ + apiKey: process.env['FIND_AI_API_KEY'], // This is the default and can be omitted +}); async function main() { const searches: FindAI.SearchRetrieveResponse = await client.searches.retrieve('id'); diff --git a/package.json b/package.json index b7279c1..629e561 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "find-ai", - "version": "0.1.0-alpha.3", + "version": "0.1.0-alpha.4", "description": "The official TypeScript library for the Find AI API", "author": "Find AI ", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 7f1dd98..57a30d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,11 @@ import * as Core from './core'; import * as API from './resources/index'; export interface ClientOptions { + /** + * Defaults to process.env['FIND_AI_API_KEY']. + */ + apiKey?: string | undefined; + /** * Override the default base URL for the API, e.g., "https://api.example.com/v2/" * @@ -68,11 +73,14 @@ export interface ClientOptions { * API Client for interfacing with the Find AI API. */ export class FindAI extends Core.APIClient { + apiKey: string; + private _options: ClientOptions; /** * API Client for interfacing with the Find AI API. * + * @param {string | undefined} [opts.apiKey=process.env['FIND_AI_API_KEY'] ?? undefined] * @param {string} [opts.baseURL=process.env['FIND_AI_BASE_URL'] ?? https://usefind.ai/found] - 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. @@ -81,8 +89,19 @@ export class FindAI extends Core.APIClient { * @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('FIND_AI_BASE_URL'), ...opts }: ClientOptions = {}) { + constructor({ + baseURL = Core.readEnv('FIND_AI_BASE_URL'), + apiKey = Core.readEnv('FIND_AI_API_KEY'), + ...opts + }: ClientOptions = {}) { + if (apiKey === undefined) { + throw new Errors.FindAIError( + "The FIND_AI_API_KEY environment variable is missing or empty; either provide it, or instantiate the FindAI client with an apiKey option, like new FindAI({ apiKey: 'My API Key' }).", + ); + } + const options: ClientOptions = { + apiKey, ...opts, baseURL: baseURL || `https://usefind.ai/found`, }; @@ -96,6 +115,8 @@ export class FindAI extends Core.APIClient { }); this._options = options; + + this.apiKey = apiKey; } companyEnrichment: API.CompanyEnrichment = new API.CompanyEnrichment(this); @@ -113,6 +134,10 @@ export class FindAI extends Core.APIClient { }; } + protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers { + return { Authorization: this.apiKey }; + } + static FindAI = this; static DEFAULT_TIMEOUT = 60000; // 1 minute diff --git a/src/version.ts b/src/version.ts index a64b06c..fe6d1df 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.1.0-alpha.3'; // x-release-please-version +export const VERSION = '0.1.0-alpha.4'; // x-release-please-version diff --git a/tests/api-resources/company-enrichment/enrich.test.ts b/tests/api-resources/company-enrichment/enrich.test.ts index 53238c2..59436ff 100644 --- a/tests/api-resources/company-enrichment/enrich.test.ts +++ b/tests/api-resources/company-enrichment/enrich.test.ts @@ -3,7 +3,10 @@ import FindAI from 'find-ai'; import { Response } from 'node-fetch'; -const client = new FindAI({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' }); +const client = new FindAI({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); describe('resource enrich', () => { test('create', async () => { diff --git a/tests/api-resources/people-enrichment/enrich.test.ts b/tests/api-resources/people-enrichment/enrich.test.ts index b727b62..a516720 100644 --- a/tests/api-resources/people-enrichment/enrich.test.ts +++ b/tests/api-resources/people-enrichment/enrich.test.ts @@ -3,7 +3,10 @@ import FindAI from 'find-ai'; import { Response } from 'node-fetch'; -const client = new FindAI({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' }); +const client = new FindAI({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); describe('resource enrich', () => { test('create', async () => { diff --git a/tests/api-resources/searches.test.ts b/tests/api-resources/searches.test.ts index 659a3a6..e2ea3c3 100644 --- a/tests/api-resources/searches.test.ts +++ b/tests/api-resources/searches.test.ts @@ -3,7 +3,10 @@ import FindAI from 'find-ai'; import { Response } from 'node-fetch'; -const client = new FindAI({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' }); +const client = new FindAI({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); describe('resource searches', () => { test('create', async () => { diff --git a/tests/index.test.ts b/tests/index.test.ts index 209c3a9..e9e6dab 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -23,6 +23,7 @@ describe('instantiate client', () => { const client = new FindAI({ baseURL: 'http://localhost:5000/', defaultHeaders: { 'X-My-Default-Header': '2' }, + apiKey: 'My API Key', }); test('they are used in the request', () => { @@ -51,7 +52,11 @@ describe('instantiate client', () => { describe('defaultQuery', () => { test('with null query params given', () => { - const client = new FindAI({ baseURL: 'http://localhost:5000/', defaultQuery: { apiVersion: 'foo' } }); + const client = new FindAI({ + baseURL: 'http://localhost:5000/', + defaultQuery: { apiVersion: 'foo' }, + apiKey: 'My API Key', + }); expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/foo?apiVersion=foo'); }); @@ -59,12 +64,17 @@ describe('instantiate client', () => { const client = new FindAI({ 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 FindAI({ baseURL: 'http://localhost:5000/', defaultQuery: { hello: 'world' } }); + const client = new FindAI({ + baseURL: 'http://localhost:5000/', + defaultQuery: { hello: 'world' }, + apiKey: 'My API Key', + }); expect(client.buildURL('/foo', { hello: undefined })).toEqual('http://localhost:5000/foo'); }); }); @@ -72,6 +82,7 @@ describe('instantiate client', () => { test('custom fetch', async () => { const client = new FindAI({ baseURL: 'http://localhost:5000/', + apiKey: 'My API Key', fetch: (url) => { return Promise.resolve( new Response(JSON.stringify({ url, custom: true }), { @@ -88,6 +99,7 @@ describe('instantiate client', () => { test('custom signal', async () => { const client = new FindAI({ 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( @@ -112,12 +124,12 @@ describe('instantiate client', () => { describe('baseUrl', () => { test('trailing slash', () => { - const client = new FindAI({ baseURL: 'http://localhost:5000/custom/path/' }); + const client = new FindAI({ 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 FindAI({ baseURL: 'http://localhost:5000/custom/path' }); + const client = new FindAI({ baseURL: 'http://localhost:5000/custom/path', apiKey: 'My API Key' }); expect(client.buildURL('/foo', null)).toEqual('http://localhost:5000/custom/path/foo'); }); @@ -126,41 +138,55 @@ describe('instantiate client', () => { }); test('explicit option', () => { - const client = new FindAI({ baseURL: 'https://example.com' }); + const client = new FindAI({ baseURL: 'https://example.com', apiKey: 'My API Key' }); expect(client.baseURL).toEqual('https://example.com'); }); test('env variable', () => { process.env['FIND_AI_BASE_URL'] = 'https://example.com/from_env'; - const client = new FindAI({}); + const client = new FindAI({ apiKey: 'My API Key' }); expect(client.baseURL).toEqual('https://example.com/from_env'); }); test('empty env variable', () => { process.env['FIND_AI_BASE_URL'] = ''; // empty - const client = new FindAI({}); + const client = new FindAI({ apiKey: 'My API Key' }); expect(client.baseURL).toEqual('https://usefind.ai/found'); }); test('blank env variable', () => { process.env['FIND_AI_BASE_URL'] = ' '; // blank - const client = new FindAI({}); + const client = new FindAI({ apiKey: 'My API Key' }); expect(client.baseURL).toEqual('https://usefind.ai/found'); }); }); test('maxRetries option is correctly set', () => { - const client = new FindAI({ maxRetries: 4 }); + const client = new FindAI({ maxRetries: 4, apiKey: 'My API Key' }); expect(client.maxRetries).toEqual(4); // default - const client2 = new FindAI({}); + const client2 = new FindAI({ apiKey: 'My API Key' }); expect(client2.maxRetries).toEqual(2); }); + + test('with environment variable arguments', () => { + // set options via env var + process.env['FIND_AI_API_KEY'] = 'My API Key'; + const client = new FindAI(); + expect(client.apiKey).toBe('My API Key'); + }); + + test('with overriden environment variable arguments', () => { + // set options via env var + process.env['FIND_AI_API_KEY'] = 'another My API Key'; + const client = new FindAI({ apiKey: 'My API Key' }); + expect(client.apiKey).toBe('My API Key'); + }); }); describe('request building', () => { - const client = new FindAI({}); + const client = new FindAI({ apiKey: 'My API Key' }); describe('Content-Length', () => { test('handles multi-byte characters', () => { @@ -202,7 +228,7 @@ describe('retries', () => { return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } }); }; - const client = new FindAI({ timeout: 10, fetch: testFetch }); + const client = new FindAI({ apiKey: 'My API Key', timeout: 10, fetch: testFetch }); expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 }); expect(count).toEqual(2); @@ -232,7 +258,7 @@ describe('retries', () => { return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } }); }; - const client = new FindAI({ fetch: testFetch, maxRetries: 4 }); + const client = new FindAI({ apiKey: 'My API Key', fetch: testFetch, maxRetries: 4 }); expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 }); @@ -256,7 +282,7 @@ describe('retries', () => { capturedRequest = init; return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } }); }; - const client = new FindAI({ fetch: testFetch, maxRetries: 4 }); + const client = new FindAI({ apiKey: 'My API Key', fetch: testFetch, maxRetries: 4 }); expect( await client.request({ @@ -285,7 +311,7 @@ describe('retries', () => { capturedRequest = init; return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } }); }; - const client = new FindAI({ fetch: testFetch, maxRetries: 4 }); + const client = new FindAI({ apiKey: 'My API Key', fetch: testFetch, maxRetries: 4 }); expect( await client.request({ @@ -312,7 +338,7 @@ describe('retries', () => { return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } }); }; - const client = new FindAI({ fetch: testFetch }); + const client = new FindAI({ apiKey: 'My API Key', fetch: testFetch }); expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 }); expect(count).toEqual(2); @@ -339,7 +365,7 @@ describe('retries', () => { return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } }); }; - const client = new FindAI({ fetch: testFetch }); + const client = new FindAI({ apiKey: 'My API Key', fetch: testFetch }); expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 }); expect(count).toEqual(2);