From 64711607bff8fd3f8412d54c53c15aac7cf4d052 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Wed, 26 Jun 2024 15:13:45 +0000 Subject: [PATCH] feat(api): update via SDK Studio --- .stats.yml | 2 +- api.md | 1 + src/resources/contacts/companies.ts | 56 +++++++++++++++++++ src/resources/contacts/contacts.ts | 1 + src/resources/contacts/index.ts | 8 ++- .../api-resources/contacts/companies.test.ts | 29 ++++++++++ 6 files changed, 95 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index efeff6c4..14c5e154 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 107 +configured_endpoints: 108 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/intercom%2Fintercom-a202b2b4aa0e356eb61376a3bf484132be2e9e3bff3796e1fe4606ab2a3734fd.yml diff --git a/api.md b/api.md index 60532c78..e511a390 100644 --- a/api.md +++ b/api.md @@ -175,6 +175,7 @@ Types: Methods: - client.contacts.companies.create(contactId, { ...params }) -> Company +- client.contacts.companies.list(contactId, { ...params }) -> ContactAttachedCompanies - client.contacts.companies.delete(contactId, id, { ...params }) -> Company ## Notes diff --git a/src/resources/contacts/companies.ts b/src/resources/contacts/companies.ts index 8b807658..53b859ee 100644 --- a/src/resources/contacts/companies.ts +++ b/src/resources/contacts/companies.ts @@ -28,6 +28,35 @@ export class Companies extends APIResource { }); } + /** + * You can fetch a list of companies that are associated to a contact. + */ + list( + contactId: string, + params?: CompanyListParams, + options?: Core.RequestOptions, + ): Core.APIPromise; + list(contactId: string, options?: Core.RequestOptions): Core.APIPromise; + list( + contactId: string, + params: CompanyListParams | Core.RequestOptions = {}, + options?: Core.RequestOptions, + ): Core.APIPromise { + if (isRequestOptions(params)) { + return this.list(contactId, {}, params); + } + const { 'Intercom-Version': intercomVersion } = params; + return this._client.get(`/contacts/${contactId}/companies`, { + ...options, + headers: { + ...(intercomVersion?.toString() != null ? + { 'Intercom-Version': intercomVersion?.toString() } + : undefined), + ...options?.headers, + }, + }); + } + /** * You can detach a company from a single contact. */ @@ -147,6 +176,32 @@ export interface CompanyCreateParams { | 'Unstable'; } +export interface CompanyListParams { + /** + * Intercom API version.By default, it's equal to the version set in the app + * package. + */ + 'Intercom-Version'?: + | '1.0' + | '1.1' + | '1.2' + | '1.3' + | '1.4' + | '2.0' + | '2.1' + | '2.2' + | '2.3' + | '2.4' + | '2.5' + | '2.6' + | '2.7' + | '2.8' + | '2.9' + | '2.10' + | '2.11' + | 'Unstable'; +} + export interface CompanyDeleteParams { /** * Intercom API version.By default, it's equal to the version set in the app @@ -176,5 +231,6 @@ export interface CompanyDeleteParams { export namespace Companies { export import ContactAttachedCompanies = CompaniesAPI.ContactAttachedCompanies; export import CompanyCreateParams = CompaniesAPI.CompanyCreateParams; + export import CompanyListParams = CompaniesAPI.CompanyListParams; export import CompanyDeleteParams = CompaniesAPI.CompanyDeleteParams; } diff --git a/src/resources/contacts/contacts.ts b/src/resources/contacts/contacts.ts index 80106f2d..1adbb695 100644 --- a/src/resources/contacts/contacts.ts +++ b/src/resources/contacts/contacts.ts @@ -883,6 +883,7 @@ export namespace Contacts { export import Companies = CompaniesAPI.Companies; export import ContactAttachedCompanies = CompaniesAPI.ContactAttachedCompanies; export import CompanyCreateParams = CompaniesAPI.CompanyCreateParams; + export import CompanyListParams = CompaniesAPI.CompanyListParams; export import CompanyDeleteParams = CompaniesAPI.CompanyDeleteParams; export import Notes = NotesAPI.Notes; export import NoteList = NotesAPI.NoteList; diff --git a/src/resources/contacts/index.ts b/src/resources/contacts/index.ts index 0ab97535..a0d1b301 100644 --- a/src/resources/contacts/index.ts +++ b/src/resources/contacts/index.ts @@ -16,7 +16,13 @@ export { ContactUnarchiveParams, Contacts, } from './contacts'; -export { ContactAttachedCompanies, CompanyCreateParams, CompanyDeleteParams, Companies } from './companies'; +export { + ContactAttachedCompanies, + CompanyCreateParams, + CompanyListParams, + CompanyDeleteParams, + Companies, +} from './companies'; export { ContactSegments, SegmentListParams, Segments } from './segments'; export { NoteList, NoteCreateParams, NoteListParams, Notes } from './notes'; export { diff --git a/tests/api-resources/contacts/companies.test.ts b/tests/api-resources/contacts/companies.test.ts index e2c306a2..731132a6 100644 --- a/tests/api-resources/contacts/companies.test.ts +++ b/tests/api-resources/contacts/companies.test.ts @@ -29,6 +29,35 @@ describe('resource companies', () => { }); }); + test('list', async () => { + const responsePromise = intercom.contacts.companies.list('string'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('list: request options instead of params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + intercom.contacts.companies.list('string', { path: '/_stainless_unknown_path' }), + ).rejects.toThrow(Intercom.NotFoundError); + }); + + test('list: request options and params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + intercom.contacts.companies.list( + 'string', + { 'Intercom-Version': '2.11' }, + { path: '/_stainless_unknown_path' }, + ), + ).rejects.toThrow(Intercom.NotFoundError); + }); + test('delete', async () => { const responsePromise = intercom.contacts.companies.delete( '58a430d35458202d41b1e65b',