Skip to content

Commit

Permalink
Merge pull request #12 from Find-AI/release-please--branches--main--c…
Browse files Browse the repository at this point in the history
…hanges--next--components--find-ai

release: 0.1.0-alpha.4
  • Loading branch information
philipithomas authored Sep 26, 2024
2 parents 8748ba6 + 8e5d0e4 commit 91e09ae
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.3"
".": "0.1.0-alpha.4"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 6 additions & 2 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 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');
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
27 changes: 26 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
*
Expand Down Expand Up @@ -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.
Expand All @@ -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`,
};
Expand All @@ -96,6 +115,8 @@ export class FindAI extends Core.APIClient {
});

this._options = options;

this.apiKey = apiKey;
}

companyEnrichment: API.CompanyEnrichment = new API.CompanyEnrichment(this);
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion tests/api-resources/company-enrichment/enrich.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
5 changes: 4 additions & 1 deletion tests/api-resources/people-enrichment/enrich.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
5 changes: 4 additions & 1 deletion tests/api-resources/searches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
60 changes: 43 additions & 17 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 FindAI({
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 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');
});

test('multiple default query params', () => {
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');
});
});

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 }), {
Expand All @@ -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(
Expand All @@ -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');
});

Expand All @@ -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', () => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 });

Expand All @@ -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({
Expand Down Expand Up @@ -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({
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 91e09ae

Please sign in to comment.