diff --git a/sdks/typescript/README.md b/sdks/typescript/README.md index b33fc04..48017e5 100644 --- a/sdks/typescript/README.md +++ b/sdks/typescript/README.md @@ -1,4 +1,4 @@ -# @thecompaniesapi/sdk +# The Companies API SDK for TypeScript [![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] @@ -6,95 +6,550 @@ [![JSDocs][jsdocs-src]][jsdocs-href] [![License][license-src]][license-href] -A TypeScript SDK for [The Companies API](https://www.thecompaniesapi.com), providing type-safe access to the API. +A fully-featured TypeScript SDK for [The Companies API](https://www.thecompaniesapi.com), providing type-safe access to company data, locations, industries, technologies, job titles, lists, and more. -## Features +If you need more details about a specific endpoint, you can find the corresponding documentation in [the API reference](https://www.thecompaniesapi.com/api). + +You can also contact us on our [livechat](https://www.thecompaniesapi.com/) if you have any questions. + +## 🚀 Features - Type-safe API client with full TypeScript support from our [OpenAPI](https://api.thecompaniesapi.com/v2/openapi) schema -- Search companies using our complete search engine API -- Enrich companies on demand using actions or sync enrichment requests -- Manage your lists of companies -- Request and track specific actions -- Get analytics about a search query or a list -- Ask question on any company and get structured answers +- Powerful search capabilities with filters, sorting and pagination +- Real-time company enrichment with both synchronous and asynchronous options +- Create and manage your company lists +- Track and monitor enrichment actions and requests +- Generate detailed analytics and insights for searches and lists +- Natural language querying for structured company information +- Lightweight with minimal dependencies +- Promise-based async/await interface -## Installation +## 📦 Installation ```bash +# with npm npm install @thecompaniesapi/sdk -# or + +# with yarn yarn add @thecompaniesapi/sdk -# or + +# with pnpm pnpm add @thecompaniesapi/sdk ``` -## Usage +## 🔑 Initialize the client -Get your API key from [your settings page](https://www.thecompaniesapi.com/settings/api-tokens). +Get your API token from [your settings page](https://www.thecompaniesapi.com/settings/api-tokens) and initialize our client with `createClient`. + +The API token is required to authenticate your requests and should be kept secure. Never commit your API token to version control or share it publicly. ```typescript -import { createClient } from '@thecompaniesapi/sdk' +import createClient from '@thecompaniesapi/sdk' -// Create a base client const tca = createClient({ - apiKey: 'your-api-key', + apiKey: 'your-api-token', +}) +``` + +## 🏬 Companies + +### Search companies + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-search) + +🔍 To learn more about our query system, please read our [use case documentation](https://www.thecompaniesapi.com/use-cases/companies-search-engine). + +```typescript +// Search companies by industry and size +await tca.searchCompanies({ + query: [ + { attribute: 'about.industries', operator: 'or', sign: 'equals', values: ['computer-software'] }, + { attribute: 'about.totalEmployees', operator: 'or', sign: 'equals', values: ['10-50'] } + ], + size: 25 +}) + +const companies = response.data.companies // Companies that match the query +const meta = response.data.meta // Meta information +``` + +### Search companies by name + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-search-name) + +```typescript +const response = await tca.searchCompaniesByName({ + name: 'The Companies API', + size: 2 +}) + +const companies = response.data.companies // Companies that match the name +const meta = response.data.meta // Meta information +``` + +### Search companies using a prompt + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-search-prompt) + +```typescript +// Search 25 companies for a specific prompt +const response = await tca.searchCompaniesByPrompt({ + prompt: 'SaaS Companies in the United States with more than 100 employees', + size: 25 }) + +const companies = response.data.companies // Companies that match the prompt +const meta = response.data.meta // Meta information +``` + +### Search similar companies + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-search-similar) + +```typescript +// Search 25 companies that are similar to Crisp and Intercom +const response = await tca.searchSimilarCompanies({ + domains: ['crisp.chat', 'intercom.com'], + size: 25 +}) + +const companies = response.data.companies // Companies that are similar to the domains +const meta = response.data.meta // Meta information ``` -## Examples +### Count companies matching your query -### Fetch a company data +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-count) ```typescript -// Fetch a company data if it exists in our database -const { data } = await tca.fetchCompany({ +// Count how many companies are in the computer-software industry +const response = await tca.countCompanies({ + query: [ + { + attribute: 'about.industries', + operator: 'or', + sign: 'equals', + values: ['computer-software'] + } + ] +}) + +const count = response.data // Number of companies that match the query +``` + +### Enrich a company from a domain name + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-enrich-from-domain) + +```typescript +// Fetch company data from our database without enrichment (faster response) +const response = await tca.fetchCompany({ domain: 'microsoft.com' }) -// Fetch a company data and enrich it if it doesn't exist -const { data } = await tca.fetchCompany({ +const company = response.data // The company profile + +// Fetch company data and re-analyze it in real-time to get fresh, up-to-date information (slower but more accurate) +const response = await tca.fetchCompany({ + domain: 'microsoft.com', + refresh: true +}) + +const company = response.data // The company profile +``` + +### Enrich a company from an email + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-enrich-from-email) + +```typescript +// Fetch the company profile behind a professional email address +const response = await tca.fetchCompanyByEmail({ + email: 'jack@openai.com' +}) + +const company = response.data // The company profile +``` + +### Enrich a company from a social network URL + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-enrich-from-social-network-url) + +```typescript +// Fetch the company profile behind a social network URL +const response = await tca.fetchCompanyBySocial({ + linkedin: 'https://www.linkedin.com/company/apple' +}) + +const company = response.data // The company profile +``` + +### Find a company email patterns + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-find-email-patterns) + +```typescript +// Fetch the company email patterns for a specific domain +const response = await tca.fetchCompanyEmailPatterns({ + domain: 'apple.com' +}) + +const patterns = response.data // The company email patterns +``` + +### Ask a question about a company + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-ask) + +```typescript +// Ask what products a company offers using its domain +const response = await tca.askCompany({ domain: 'microsoft.com', - sync: true + question: 'What products does this company offer?', + model: 'large', // 'small' is also available + fields: [ + { + key: 'products', + type: 'array|string', + description: 'The products that the company offers' + } + ] +}) + +const answer = response.data.answer // Structured AI response +const meta = response.data.meta // Meta information +``` + +### Fetch the context of a company + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-fetch-context) + +```typescript +// Get AI-generated strategic insights about a company +const response = await tca.fetchCompanyContext({ + domain: 'microsoft.com' }) + +const context = response.data.context // Includes market, model, differentiators, etc. +const meta = response.data.meta // Meta information ``` -### Searching companies +### Fetch analytics data for a query or your lists + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-fetch-analytics) ```typescript -const { data } = await tca.searchCompanies({ +// Analyze company distribution by business type +const response = await tca.fetchCompaniesAnalytics({ + attribute: 'about.businessType', query: [ { - attribute: 'about.industries', + attribute: 'locations.headquarters.country.code', operator: 'or', sign: 'equals', - values: ['higher-education'] + values: ['us', 'gb', 'fr'] } - ], - size: 3 + ] }) + +const analytics = response.data.data // Aggregated values +const meta = response.data.meta // Meta information ``` -### Add companies to your lists +### Export analytics data in multiple formats for a search + +📖 [Documentation](https://www.thecompaniesapi.com/api#companies-export-analytics) ```typescript -// Create a new list -const { data: myNewList } = await tca.createList({ - name: 'My list', +// Export analytics to CSV +const response = await tca.exportCompaniesAnalytics({ + format: 'csv', + attributes: ['about.industries', 'about.totalEmployees'], + query: [ + { + attribute: 'technologies.active', + operator: 'or', + sign: 'equals', + values: ['shopify'] + } + ] }) -// Add companies to the list -const { data } = await tca.addCompaniesToList({ - listId: myNewList.id, - companies: ['microsoft.com', 'apple.com'] +const analytics = response.data.data // Aggregated values +const meta = response.data.meta // Meta information +``` + +## 🎯 Actions + +### Request an action on one or more companies + +📖 [Documentation](https://www.thecompaniesapi.com/api#actions-request-action) + +```typescript +// Request an enrichment job on multiple companies +const response = await tca.requestAction({ + domains: ['microsoft.com', 'apple.com'], + job: 'enrich-companies', + estimate: false +}) + +const actions = response.data.actions // Track this via fetchActions +const meta = response.data.meta // Meta information +``` + +### Fetch the actions for your actions + +📖 [Documentation](https://www.thecompaniesapi.com/api#actions-fetch) + +```typescript +// Fetch recent actions +const response = await tca.fetchActions({ + status: 'completed', + page: 1, + size: 5 }) + +const actions = response.data.actions // Actions that match the query +const meta = response.data.meta // Meta information +``` + +## 🏭 Industries + +### Search industries + +📖 [Documentation](https://www.thecompaniesapi.com/api#industries-search) + +```typescript +// Search industries by keyword +const response = await tca.searchIndustries({ + search: 'software', + size: 10 +}) + +const industries = response.data.industries // Industries that match the keyword +const meta = response.data.meta // Meta information +``` + +### Find similar industries + +📖 [Documentation](https://www.thecompaniesapi.com/api#industries-find-similar) + +```typescript +// Find industries similar to given ones +const response = await tca.searchIndustriesSimilar({ + industries: ['saas', 'fintech'] +}) + +const similar = response.data.industries // Industries that are similar to the given ones +const meta = response.data.meta // Meta information +``` + +## ⚛️ Technologies + +### Search technologies + +📖 [Documentation](https://www.thecompaniesapi.com/api#technologies-search) + +```typescript +// Search technologies by keyword +const response = await tca.searchTechnologies({ + search: 'shopify', + size: 10 +}) + +const technologies = response.data.technologies // Technologies that match the keyword +const meta = response.data.meta // Meta information +``` + +## 🌍 Locations + +### Search cities + +📖 [Documentation](https://www.thecompaniesapi.com/api#locations-search-cities) + +```typescript +// Search cities by name +const response = await tca.searchCities({ + search: 'new york', + size: 5 +}) + +const cities = response.data.cities // Cities that match the name +const meta = response.data.meta // Meta information +``` + +### Search counties + +📖 [Documentation](https://www.thecompaniesapi.com/api#locations-search-counties) + +```typescript +// Search counties by name +const response = await tca.searchCounties({ + search: 'orange', + size: 5 +}) + +const counties = response.data.counties // Counties that match the name +const meta = response.data.meta // Meta information +``` + +### Search states + +📖 [Documentation](https://www.thecompaniesapi.com/api#locations-search-states) + +```typescript +// Search states by name +const response = await tca.searchStates({ + search: 'california', + size: 5 +}) + +const states = response.data.states // States that match the name +const meta = response.data.meta // Meta information +``` + +### Search countries + +📖 [Documentation](https://www.thecompaniesapi.com/api#locations-search-countries) + +```typescript +// Search countries by name +const response = await tca.searchCountries({ + search: 'france', + size: 5 +}) + +const countries = response.data.countries // Countries that match the name +const meta = response.data.meta // Meta information +``` + +### Search continents + +📖 [Documentation](https://www.thecompaniesapi.com/api#locations-search-continents) + +```typescript +// Search continents by name +const response = await tca.searchContinents({ + search: 'asia', + size: 5 +}) + +const continents = response.data.continents // Continents that match the name +const meta = response.data.meta // Meta information +``` + +## 💼 Job titles + +### Enrich a job title from its name + +📖 [Documentation](https://www.thecompaniesapi.com/api#job-titles-enrich-from-name) + +```typescript +// Enrich "chief marketing officer" +const response = await tca.enrichJobTitles({ + name: 'chief marketing officer' +}) + +const jobTitle = response.data // Contains department, seniority, etc. +``` + +## 📋 Lists + +### Fetch your lists + +📖 [Documentation](https://www.thecompaniesapi.com/api#lists-fetch-lists) + +```typescript +// Fetch your lists +const response = await tca.fetchLists() + +const lists = response.data.lists // Lists that match the query +const meta = response.data.meta // Meta information +``` + +### Create a list of companies + +📖 [Documentation](https://www.thecompaniesapi.com/api#lists-create-list) + +```typescript +// Create a list of companies +const response = await tca.createList({ + name: 'My SaaS List', + type: 'companies' +}) + +const newList = response.data // The new list +``` + +### Fetch companies in your list + +📖 [Documentation](https://www.thecompaniesapi.com/api#lists-fetch-companies) + +```typescript +// Fetch companies in a list +const response = await tca.fetchCompaniesInList({ + listId: 1234 +}) + +const companies = response.data.companies // Companies that match the list +const meta = response.data.meta // Meta information +``` + +### Add or remove companies in your list + +📖 [Documentation](https://www.thecompaniesapi.com/api#lists-toggle-companies) + +```typescript +// Add companies to a list +const response = await tca.addCompaniesToList({ + listId: 1234, + companies: ['apple.com', 'stripe.com'] +}) + +const list = response.data // The updated list +``` + +## 👥 Teams + +### Fetch your team + +📖 [Documentation](https://www.thecompaniesapi.com/api#teams-fetch-team) + +```typescript +// Fetch your team details +const response = await tca.fetchTeam() + +const team = response.data // Your team details +``` + +## 🔧 Utilities + +### Fetch the health of the API + +📖 [Documentation](https://www.thecompaniesapi.com/api#utilities-fetch-open-api) + +```typescript +// Check API health status +const response = await tca.fetchApiHealth() + +const health = response.data // The health of the API +``` + +### Fetch the OpenAPI schema + +📖 [Documentation](https://www.thecompaniesapi.com/api#utilities-fetch-open-api) + +```typescript +// Fetch OpenAPI schema +const response = await tca.fetchOpenApi() + +const schema = response.data // The OpenAPI schema ``` ## License [MIT](./LICENSE) License © [TheCompaniesAPI](https://github.com/thecompaniesapi) - - [npm-version-src]: https://img.shields.io/npm/v/@thecompaniesapi/sdk?style=flat&colorA=080f12&colorB=1fa669 [npm-version-href]: https://npmjs.com/package/@thecompaniesapi/sdk [npm-downloads-src]: https://img.shields.io/npm/dm/@thecompaniesapi/sdk?style=flat&colorA=080f12&colorB=1fa669 diff --git a/sdks/typescript/src/schema.ts b/sdks/typescript/src/schema.ts index 49b0901..a0104f0 100644 --- a/sdks/typescript/src/schema.ts +++ b/sdks/typescript/src/schema.ts @@ -128,7 +128,7 @@ export interface paths { cookie?: never } /** @description Get similar companies from one or many domains. */ - get: operations['searchCompaniesSimilar'] + get: operations['searchSimilarCompanies'] put?: never post?: never delete?: never @@ -145,10 +145,10 @@ export interface paths { cookie?: never } /** @description Get the count of companies using a segmentation query. */ - get: operations['fetchCompaniesCount'] + get: operations['countCompanies'] put?: never /** @description Get the count of companies using a segmentation body. */ - post: operations['fetchCompaniesCountPost'] + post: operations['countCompaniesPost'] delete?: never options?: never head?: never @@ -180,7 +180,7 @@ export interface paths { cookie?: never } /** @description Get a company data by social media. */ - get: operations['fetchCompanyBySocials'] + get: operations['fetchCompanyBySocial'] put?: never post?: never delete?: never @@ -515,6 +515,23 @@ export interface paths { patch: operations['updateTeam'] trace?: never } + '/v2/user': { + parameters: { + query?: never + header?: never + path?: never + cookie?: never + } + /** @description Get current user information. */ + get: operations['fetchUser'] + put?: never + post?: never + delete?: never + options?: never + head?: never + patch?: never + trace?: never + } } export type webhooks = Record export interface components { @@ -612,7 +629,7 @@ export interface components { /** @enum {string} */ job?: 'ask-domain' | 'ask-list' | 'enrich-companies' | 'enrich-list' | 'cleanup-list' /** @enum {string} */ - model?: 'claude' | 'claude-mini' | 'cousteau' | 'gpt' | 'gpt-mini' | 'groq' | 'groq-mini' | 'llama4' | 'nllb' | 'nuextract' | 'phi3' + model?: 'claude' | 'claude-mini' | 'cousteau' | 'gpt' | 'gpt-mini' | 'groq' | 'groq-mini' | 'llama3' | 'llama4' | 'nllb' | 'nuextract' | 'phi3' query?: components['schemas']['SegmentationCondition'][] question?: string team?: components['schemas']['Team'] @@ -2654,7 +2671,7 @@ export interface operations { 'application/json': { details?: unknown /** @enum {string} */ - messages: 'invalidListId' + messages: 'invalidListId' | 'typeMissing' status: number } } @@ -2673,6 +2690,20 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'invalidPromptId' + status: number + } + } + } } } searchCompanies: { @@ -2731,6 +2762,20 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } } } searchCompaniesPost: { @@ -2795,11 +2840,26 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } } } fetchCompany: { parameters: { query?: { + simplified?: boolean sync?: boolean } header?: never @@ -2833,6 +2893,34 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } + /** @description The error message */ + 404: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'companyNotFound' + status: number + } + } + } } } searchCompaniesByName: { @@ -2876,6 +2964,20 @@ export interface operations { } } /** @description The error message */ + 400: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'companyNameEmpty' + status: number + } + } + } + /** @description The error message */ 401: { headers: { [name: string]: unknown @@ -2889,6 +2991,20 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } } } searchCompaniesByPrompt: { @@ -2943,9 +3059,23 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } } } - searchCompaniesSimilar: { + searchSimilarCompanies: { parameters: { query: { domains: string[] @@ -2997,9 +3127,23 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } } } - fetchCompaniesCount: { + countCompanies: { parameters: { query?: { actionId?: number @@ -3038,9 +3182,23 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } } } - fetchCompaniesCountPost: { + countCompaniesPost: { parameters: { query?: never header?: never @@ -3083,6 +3241,20 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } } } fetchCompanyByEmail: { @@ -3090,6 +3262,7 @@ export interface operations { query: { email: string simplified?: boolean + sync?: boolean } header?: never path?: never @@ -3141,9 +3314,23 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } } } - fetchCompanyBySocials: { + fetchCompanyBySocial: { parameters: { query?: { angellist?: string @@ -3156,6 +3343,7 @@ export interface operations { simplified?: boolean snapchat?: string souncloud?: string + sync?: boolean tiktok?: string twitter?: string wellfound?: string @@ -3190,6 +3378,20 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } } } fetchCompanyEmailPatterns: { @@ -3229,6 +3431,34 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } + /** @description The error message */ + 404: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'companyNotFound' + status: number + } + } + } } } askCompany: { @@ -3326,6 +3556,34 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } + /** @description The error message */ + 404: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'companyNotFound' + status: number + } + } + } } } fetchCompanyContext: { @@ -3373,6 +3631,34 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'noCreditsRemaining' + status: number + } + } + } + /** @description The error message */ + 404: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'companyNotFound' + status: number + } + } + } } } fetchCompaniesAnalytics: { @@ -3995,6 +4281,20 @@ export interface operations { } } /** @description The error message */ + 400: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'listNotFound' + status: number + } + } + } + /** @description The error message */ 401: { headers: { [name: string]: unknown @@ -4008,6 +4308,20 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'userCurrentTeamIsNotInstanceOwner' + status: number + } + } + } } } fetchCompaniesInList: { @@ -4052,6 +4366,20 @@ export interface operations { } } /** @description The error message */ + 400: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'listNotFound' + status: number + } + } + } + /** @description The error message */ 401: { headers: { [name: string]: unknown @@ -4065,6 +4393,20 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'userCurrentTeamIsNotInstanceOwner' + status: number + } + } + } } } fetchCompaniesInListPost: { @@ -4115,6 +4457,20 @@ export interface operations { } } /** @description The error message */ + 400: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'listNotFound' + status: number + } + } + } + /** @description The error message */ 401: { headers: { [name: string]: unknown @@ -4128,6 +4484,20 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'userCurrentTeamIsNotInstanceOwner' + status: number + } + } + } } } listsToggleCompanies: { @@ -4146,6 +4516,7 @@ export interface operations { action: 'attach' | 'detach' companyIds?: number[] domains?: string[] + sync?: boolean } } } @@ -4160,6 +4531,20 @@ export interface operations { } } /** @description The error message */ + 400: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'listNotFound' + status: number + } + } + } + /** @description The error message */ 401: { headers: { [name: string]: unknown @@ -4173,6 +4558,34 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'userCurrentTeamIsNotInstanceOwner' + status: number + } + } + } + /** @description The error message */ + 404: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'companyNotFound' + status: number + } + } + } } } fetchTeam: { @@ -4209,6 +4622,34 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'userNotInTeam' + status: number + } + } + } + /** @description The error message */ + 404: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'teamNotFound' + status: number + } + } + } } } updateTeam: { @@ -4253,9 +4694,71 @@ export interface operations { } } } + /** @description The error message */ + 403: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'userNotInTeam' + status: number + } + } + } + /** @description The error message */ + 404: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'teamNotFound' + status: number + } + } + } + } + } + fetchUser: { + parameters: { + query?: never + header?: never + path?: never + cookie?: never + } + requestBody?: never + responses: { + /** @description Get current user information. */ + 200: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': '' | components['schemas']['User'] + } + } + /** @description The error message */ + 401: { + headers: { + [name: string]: unknown + } + content: { + 'application/json': { + details?: unknown + /** @enum {string} */ + messages: 'tokenNotFound' | 'invalidApiSecret' | 'missingApiSecret' | 'userNotAuthenticated' + status: number + } + } + } } } } -export const operationsMap = { fetchApiHealth: { path: '/', method: 'get', pathParams: [] }, fetchOpenApi: { path: '/v2/openapi', method: 'get', pathParams: [] }, fetchActions: { path: '/v2/actions', method: 'get', pathParams: [] }, requestAction: { path: '/v2/actions', method: 'post', pathParams: [] }, searchCompanies: { path: '/v2/companies', method: 'get', pathParams: [] }, searchCompaniesPost: { path: '/v2/companies', method: 'post', pathParams: [] }, fetchCompany: { path: '/v2/companies/{domain}', method: 'get', pathParams: ['domain'] }, searchCompaniesByName: { path: '/v2/companies/by-name', method: 'get', pathParams: [] }, searchCompaniesByPrompt: { path: '/v2/companies/by-prompt', method: 'get', pathParams: [] }, searchCompaniesSimilar: { path: '/v2/companies/similar', method: 'get', pathParams: [] }, fetchCompaniesCount: { path: '/v2/companies/count', method: 'get', pathParams: [] }, fetchCompaniesCountPost: { path: '/v2/companies/count', method: 'post', pathParams: [] }, fetchCompanyByEmail: { path: '/v2/companies/by-email', method: 'get', pathParams: [] }, fetchCompanyBySocials: { path: '/v2/companies/by-social', method: 'get', pathParams: [] }, fetchCompanyEmailPatterns: { path: '/v2/companies/{domain}/email-patterns', method: 'get', pathParams: ['domain'] }, askCompany: { path: '/v2/companies/{domain}/ask', method: 'get', pathParams: ['domain'] }, fetchCompanyContext: { path: '/v2/companies/{domain}/context', method: 'get', pathParams: ['domain'] }, fetchCompaniesAnalytics: { path: '/v2/companies/analytics', method: 'get', pathParams: [] }, exportCompaniesAnalytics: { path: '/v2/companies/analytics/export', method: 'get', pathParams: [] }, searchIndustries: { path: '/v2/industries', method: 'get', pathParams: [] }, searchIndustriesSimilar: { path: '/v2/industries/similar', method: 'get', pathParams: [] }, searchTechnologies: { path: '/v2/technologies', method: 'get', pathParams: [] }, searchCities: { path: '/v2/locations/cities', method: 'get', pathParams: [] }, searchCounties: { path: '/v2/locations/counties', method: 'get', pathParams: [] }, searchCountries: { path: '/v2/locations/countries', method: 'get', pathParams: [] }, searchStates: { path: '/v2/locations/states', method: 'get', pathParams: [] }, searchContinents: { path: '/v2/locations/continents', method: 'get', pathParams: [] }, enrichJobTitles: { path: '/v2/job-titles/enrich', method: 'get', pathParams: [] }, fetchLists: { path: '/v2/lists', method: 'get', pathParams: [] }, createList: { path: '/v2/lists', method: 'post', pathParams: [] }, updateList: { path: '/v2/lists/{listId}', method: 'patch', pathParams: ['listId'] }, fetchCompaniesInList: { path: '/v2/lists/{listId}/companies', method: 'get', pathParams: ['listId'] }, fetchCompaniesInListPost: { path: '/v2/lists/{listId}/companies', method: 'post', pathParams: ['listId'] }, listsToggleCompanies: { path: '/v2/lists/{listId}/companies/toggle', method: 'post', pathParams: ['listId'] }, fetchTeam: { path: '/v2/teams/{teamId}', method: 'get', pathParams: ['teamId'] }, updateTeam: { path: '/v2/teams/{teamId}', method: 'patch', pathParams: ['teamId'] } } as const +export const operationsMap = { fetchApiHealth: { path: '/', method: 'get', pathParams: [] }, fetchOpenApi: { path: '/v2/openapi', method: 'get', pathParams: [] }, fetchActions: { path: '/v2/actions', method: 'get', pathParams: [] }, requestAction: { path: '/v2/actions', method: 'post', pathParams: [] }, searchCompanies: { path: '/v2/companies', method: 'get', pathParams: [] }, searchCompaniesPost: { path: '/v2/companies', method: 'post', pathParams: [] }, fetchCompany: { path: '/v2/companies/{domain}', method: 'get', pathParams: ['domain'] }, searchCompaniesByName: { path: '/v2/companies/by-name', method: 'get', pathParams: [] }, searchCompaniesByPrompt: { path: '/v2/companies/by-prompt', method: 'get', pathParams: [] }, searchSimilarCompanies: { path: '/v2/companies/similar', method: 'get', pathParams: [] }, countCompanies: { path: '/v2/companies/count', method: 'get', pathParams: [] }, countCompaniesPost: { path: '/v2/companies/count', method: 'post', pathParams: [] }, fetchCompanyByEmail: { path: '/v2/companies/by-email', method: 'get', pathParams: [] }, fetchCompanyBySocial: { path: '/v2/companies/by-social', method: 'get', pathParams: [] }, fetchCompanyEmailPatterns: { path: '/v2/companies/{domain}/email-patterns', method: 'get', pathParams: ['domain'] }, askCompany: { path: '/v2/companies/{domain}/ask', method: 'get', pathParams: ['domain'] }, fetchCompanyContext: { path: '/v2/companies/{domain}/context', method: 'get', pathParams: ['domain'] }, fetchCompaniesAnalytics: { path: '/v2/companies/analytics', method: 'get', pathParams: [] }, exportCompaniesAnalytics: { path: '/v2/companies/analytics/export', method: 'get', pathParams: [] }, searchIndustries: { path: '/v2/industries', method: 'get', pathParams: [] }, searchIndustriesSimilar: { path: '/v2/industries/similar', method: 'get', pathParams: [] }, searchTechnologies: { path: '/v2/technologies', method: 'get', pathParams: [] }, searchCities: { path: '/v2/locations/cities', method: 'get', pathParams: [] }, searchCounties: { path: '/v2/locations/counties', method: 'get', pathParams: [] }, searchCountries: { path: '/v2/locations/countries', method: 'get', pathParams: [] }, searchStates: { path: '/v2/locations/states', method: 'get', pathParams: [] }, searchContinents: { path: '/v2/locations/continents', method: 'get', pathParams: [] }, enrichJobTitles: { path: '/v2/job-titles/enrich', method: 'get', pathParams: [] }, fetchLists: { path: '/v2/lists', method: 'get', pathParams: [] }, createList: { path: '/v2/lists', method: 'post', pathParams: [] }, updateList: { path: '/v2/lists/{listId}', method: 'patch', pathParams: ['listId'] }, fetchCompaniesInList: { path: '/v2/lists/{listId}/companies', method: 'get', pathParams: ['listId'] }, fetchCompaniesInListPost: { path: '/v2/lists/{listId}/companies', method: 'post', pathParams: ['listId'] }, listsToggleCompanies: { path: '/v2/lists/{listId}/companies/toggle', method: 'post', pathParams: ['listId'] }, fetchTeam: { path: '/v2/teams/{teamId}', method: 'get', pathParams: ['teamId'] }, updateTeam: { path: '/v2/teams/{teamId}', method: 'patch', pathParams: ['teamId'] }, fetchUser: { path: '/v2/user', method: 'get', pathParams: [] } } as const export type OperationsMap = { [K in keyof operations]: typeof operationsMap[K] } diff --git a/sdks/typescript/src/sdk.ts b/sdks/typescript/src/sdk.ts index 55e61b8..0e7214a 100644 --- a/sdks/typescript/src/sdk.ts +++ b/sdks/typescript/src/sdk.ts @@ -10,7 +10,7 @@ const defaultParams = { type TcaClient = Client -export function createHttpClient( +function createHttpClient( params: { apiKey?: string apiUrl?: string @@ -66,7 +66,7 @@ type OperationsClient = { ) => Promise> } -export function createClient( +export default function createClient( params: { apiKey?: string apiUrl?: string diff --git a/sdks/typescript/typescript.test.ts b/sdks/typescript/typescript.test.ts index 0b9ce7a..c0c59da 100644 --- a/sdks/typescript/typescript.test.ts +++ b/sdks/typescript/typescript.test.ts @@ -1,43 +1,34 @@ import { describe, expect, it } from 'vitest' import { operationsMap } from './src/schema' -import { createClient, createHttpClient } from './src/sdk' +import createClient from './src/sdk' function getTcaClient(overwriteParams?: { apiKey?: string apiUrl?: string }) { - const base = createHttpClient({ + const client = createClient({ apiKey: process.env.TCA_API_KEY, apiUrl: process.env.TCA_API_URL, ...(overwriteParams || {}), }) - const operations = createClient({ - apiKey: process.env.TCA_API_KEY, - apiUrl: process.env.TCA_API_URL, - ...(overwriteParams || {}), - }) - - return { base, operations } + return client } describe('should', () => { it('can create client', () => { - const { base, operations } = getTcaClient() + const client = getTcaClient() - expect(base).toBeDefined() - expect(operations).toBeDefined() - expect(Object.keys(operations).length).toEqual(Object.keys(operationsMap).length) + expect(client).toBeDefined() + expect(Object.keys(client).length).toEqual(Object.keys(operationsMap).length) }) it('can fetch openapi client', async () => { - const { base, operations } = getTcaClient() + const client = getTcaClient() - const { data } = await base.GET('/v2/openapi') - const { data: dataOperations } = await operations.fetchOpenApi() + const { data } = await client.fetchOpenApi() expect(data).toBeDefined() - expect(dataOperations).toBeDefined() // Get operations from schema const operationsCount = Object.values(data?.paths || {}).reduce( @@ -46,56 +37,25 @@ describe('should', () => { }, 0, ) - const operationsCountOperations = Object.values(dataOperations?.paths || {}).reduce( - (acc, operations) => { - return acc + Object.keys(operations as Record).length - }, - 0, - ) // Compare operations from pulled schema with operations built locally expect(operationsCount).toEqual(Object.keys(operationsMap).length) - expect(operationsCountOperations).toEqual(Object.keys(operationsMap).length) }) it('can fetch company', async () => { - const { base, operations } = getTcaClient() + const client = getTcaClient() - const { data } = await base.GET('/v2/companies/{domain}', { - params: { - path: { - domain: 'microsoft.com', - }, - }, - }) - - const { data: dataOperations } = await operations.fetchCompany({ + const { data } = await client.fetchCompany({ domain: 'microsoft.com', }) expect(data).toBeDefined() - expect(dataOperations).toBeDefined() }) it('can search companies with post and get params', async () => { - const { base, operations } = getTcaClient() - - const { data } = await base.GET('/v2/companies', { - params: { - query: { - query: [ - { - attribute: 'about.industries', - operator: 'or', - sign: 'equals', - values: ['higher-education'], - }, - ], - size: 3, - }, - }, - }) - const { data: dataOperations } = await operations.searchCompanies({ + const client = getTcaClient() + + const { data } = await client.searchCompanies({ query: [ { attribute: 'about.industries', @@ -107,21 +67,7 @@ describe('should', () => { size: 3, }) - const { data: dataPost } = await base.POST('/v2/companies', { - body: { - query: [ - { - attribute: 'about.industries', - operator: 'or', - sign: 'equals', - values: ['higher-education'], - }, - ], - size: 3, - }, - }) - - const { data: dataOperationsPost } = await operations.searchCompaniesPost({ + const { data: dataPost } = await client.searchCompaniesPost({ query: [ { attribute: 'about.industries', @@ -133,16 +79,13 @@ describe('should', () => { size: 3, }) - const companiesNames = data?.companies.map(company => company.about?.name).sort() - const companiesNamesOperations = dataOperations?.companies.map(company => company.about?.name).sort() - const companiesNamesPost = dataPost?.companies.map(company => company.about?.name).sort() - const companiesNamesOperationsPost = dataOperationsPost?.companies.map(company => company.about?.name).sort() + const companiesNames = data?.companies.map((company: any) => company.about?.name).sort() + const companiesNamesPost = dataPost?.companies.map((company: any) => company.about?.name).sort() expect(JSON.stringify(companiesNames)).toEqual(JSON.stringify(companiesNamesPost)) - expect(JSON.stringify(companiesNamesOperations)).toEqual(JSON.stringify(companiesNamesOperationsPost)) expect(data?.companies.length).toBe(3) - expect(data?.companies?.filter(company => company.about?.industries?.includes('higher-education')).length).toBe(3) + expect(data?.companies?.filter((company: any) => company.about?.industries?.includes('higher-education')).length).toBe(3) expect(dataPost?.companies.length).toBe(3) - expect(dataPost?.companies?.filter(company => company.about?.industries?.includes('higher-education')).length).toBe(3) + expect(dataPost?.companies?.filter((company: any) => company.about?.industries?.includes('higher-education')).length).toBe(3) }) })