Skip to content

Commit ab7812c

Browse files
committed
feat(api): update via SDK Studio
1 parent 2a37e9d commit ab7812c

File tree

8 files changed

+164
-9
lines changed

8 files changed

+164
-9
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 107
1+
configured_endpoints: 108
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/intercom%2Fintercom-8db47de304da2cbdfa6db6fd50025e9d1d4ade3d8e75569120483556b1583be6.yml

api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Methods:
116116
- <code title="put /companies/{id}">client.companies.<a href="./src/resources/companies/companies.ts">update</a>(id, { ...params }) -> Company</code>
117117
- <code title="post /companies/list">client.companies.<a href="./src/resources/companies/companies.ts">list</a>({ ...params }) -> CompanyList</code>
118118
- <code title="delete /companies/{id}">client.companies.<a href="./src/resources/companies/companies.ts">delete</a>(id, { ...params }) -> DeletedCompanyObject</code>
119+
- <code title="get /companies">client.companies.<a href="./src/resources/companies/companies.ts">retrieveList</a>({ ...params }) -> CompanyList</code>
119120
- <code title="get /companies/scroll">client.companies.<a href="./src/resources/companies/companies.ts">scroll</a>({ ...params }) -> CompanyScroll | null</code>
120121

121122
## Contacts

src/core.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
type HeadersInit,
1919
} from './_shims/index';
2020
export { type Response };
21-
import { isMultipartBody } from './uploads';
21+
import { BlobLike, isBlobLike, isMultipartBody } from './uploads';
2222
export {
2323
maybeMultipartFormRequestOptions,
2424
multipartFormRequestOptions,
@@ -235,7 +235,17 @@ export abstract class APIClient {
235235
path: string,
236236
opts?: PromiseOrValue<RequestOptions<Req>>,
237237
): APIPromise<Rsp> {
238-
return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts })));
238+
return this.request(
239+
Promise.resolve(opts).then(async (opts) => {
240+
const body =
241+
opts && isBlobLike(opts?.body) ? new DataView(await opts.body.arrayBuffer())
242+
: opts?.body instanceof DataView ? opts.body
243+
: opts?.body instanceof ArrayBuffer ? new DataView(opts.body)
244+
: opts && ArrayBuffer.isView(opts?.body) ? new DataView(opts.body.buffer)
245+
: opts?.body;
246+
return { method, path, ...opts, body };
247+
}),
248+
);
239249
}
240250

241251
getAPIList<Item, PageClass extends AbstractPage<Item> = AbstractPage<Item>>(
@@ -257,6 +267,8 @@ export abstract class APIClient {
257267
const encoded = encoder.encode(body);
258268
return encoded.length.toString();
259269
}
270+
} else if (ArrayBuffer.isView(body)) {
271+
return body.byteLength.toString();
260272
}
261273

262274
return null;
@@ -266,7 +278,9 @@ export abstract class APIClient {
266278
const { method, path, query, headers: headers = {} } = options;
267279

268280
const body =
269-
isMultipartBody(options.body) ? options.body.body
281+
ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
282+
options.body
283+
: isMultipartBody(options.body) ? options.body.body
270284
: options.body ? JSON.stringify(options.body, null, 2)
271285
: null;
272286
const contentLength = this.calculateContentLength(body);
@@ -721,7 +735,9 @@ export type Headers = Record<string, string | null | undefined>;
721735
export type DefaultQuery = Record<string, string | undefined>;
722736
export type KeysEnum<T> = { [P in keyof Required<T>]: true };
723737

724-
export type RequestOptions<Req = unknown | Record<string, unknown> | Readable> = {
738+
export type RequestOptions<
739+
Req = unknown | Record<string, unknown> | Readable | BlobLike | ArrayBufferView | ArrayBuffer,
740+
> = {
725741
method?: HTTPMethod;
726742
path?: string;
727743
query?: Req | undefined;
@@ -735,6 +751,7 @@ export type RequestOptions<Req = unknown | Record<string, unknown> | Readable> =
735751
signal?: AbortSignal | undefined | null;
736752
idempotencyKey?: string;
737753

754+
__binaryRequest?: boolean | undefined;
738755
__binaryResponse?: boolean | undefined;
739756
};
740757

@@ -755,6 +772,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
755772
signal: true,
756773
idempotencyKey: true,
757774

775+
__binaryRequest: true,
758776
__binaryResponse: true,
759777
};
760778

@@ -767,10 +785,11 @@ export const isRequestOptions = (obj: unknown): obj is RequestOptions => {
767785
);
768786
};
769787

770-
export type FinalRequestOptions<Req = unknown | Record<string, unknown> | Readable> = RequestOptions<Req> & {
771-
method: HTTPMethod;
772-
path: string;
773-
};
788+
export type FinalRequestOptions<Req = unknown | Record<string, unknown> | Readable | DataView> =
789+
RequestOptions<Req> & {
790+
method: HTTPMethod;
791+
path: string;
792+
};
774793

775794
declare const Deno: any;
776795
declare const EdgeRuntime: any;

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ export namespace Intercom {
260260
export import CompanyUpdateParams = API.CompanyUpdateParams;
261261
export import CompanyListParams = API.CompanyListParams;
262262
export import CompanyDeleteParams = API.CompanyDeleteParams;
263+
export import CompanyRetrieveListParams = API.CompanyRetrieveListParams;
263264
export import CompanyScrollParams = API.CompanyScrollParams;
264265

265266
export import Contacts = API.Contacts;

src/resources/companies/companies.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,45 @@ export class Companies extends APIResource {
179179
});
180180
}
181181

182+
/**
183+
* You can fetch a single company by passing in `company_id` or `name`.
184+
*
185+
* `https://api.intercom.io/companies?name={name}`
186+
*
187+
* `https://api.intercom.io/companies?company_id={company_id}`
188+
*
189+
* You can fetch all companies and filter by `segment_id` or `tag_id` as a query
190+
* parameter.
191+
*
192+
* `https://api.intercom.io/companies?tag_id={tag_id}`
193+
*
194+
* `https://api.intercom.io/companies?segment_id={segment_id}`
195+
*/
196+
retrieveList(
197+
params?: CompanyRetrieveListParams,
198+
options?: Core.RequestOptions,
199+
): Core.APIPromise<CompanyList>;
200+
retrieveList(options?: Core.RequestOptions): Core.APIPromise<CompanyList>;
201+
retrieveList(
202+
params: CompanyRetrieveListParams | Core.RequestOptions = {},
203+
options?: Core.RequestOptions,
204+
): Core.APIPromise<CompanyList> {
205+
if (isRequestOptions(params)) {
206+
return this.retrieveList({}, params);
207+
}
208+
const { 'Intercom-Version': intercomVersion, ...query } = params;
209+
return this._client.get('/companies', {
210+
query,
211+
...options,
212+
headers: {
213+
...(intercomVersion?.toString() != null ?
214+
{ 'Intercom-Version': intercomVersion?.toString() }
215+
: undefined),
216+
...options?.headers,
217+
},
218+
});
219+
}
220+
182221
/**
183222
* The `list all companies` functionality does not work well for huge datasets, and can result in errors and performance problems when paging deeply. The Scroll API provides an efficient mechanism for iterating over all companies in a dataset.
184223
*
@@ -591,6 +630,62 @@ export interface CompanyDeleteParams {
591630
| 'Unstable';
592631
}
593632

633+
export interface CompanyRetrieveListParams {
634+
/**
635+
* Query param: The `company_id` of the company to filter by.
636+
*/
637+
company_id?: string;
638+
639+
/**
640+
* Query param: The `name` of the company to filter by.
641+
*/
642+
name?: string;
643+
644+
/**
645+
* Query param: The page of results to fetch. Defaults to first page
646+
*/
647+
page?: number;
648+
649+
/**
650+
* Query param: How many results to display per page. Defaults to 15
651+
*/
652+
per_page?: number;
653+
654+
/**
655+
* Query param: The `segment_id` of the company to filter by.
656+
*/
657+
segment_id?: string;
658+
659+
/**
660+
* Query param: The `tag_id` of the company to filter by.
661+
*/
662+
tag_id?: string;
663+
664+
/**
665+
* Header param: Intercom API version.By default, it's equal to the version set in
666+
* the app package.
667+
*/
668+
'Intercom-Version'?:
669+
| '1.0'
670+
| '1.1'
671+
| '1.2'
672+
| '1.3'
673+
| '1.4'
674+
| '2.0'
675+
| '2.1'
676+
| '2.2'
677+
| '2.3'
678+
| '2.4'
679+
| '2.5'
680+
| '2.6'
681+
| '2.7'
682+
| '2.8'
683+
| '2.9'
684+
| '2.10'
685+
| '2.11'
686+
| 'Unstable';
687+
}
688+
594689
export interface CompanyScrollParams {
595690
/**
596691
* Query param:
@@ -631,6 +726,7 @@ export namespace Companies {
631726
export import CompanyUpdateParams = CompaniesAPI.CompanyUpdateParams;
632727
export import CompanyListParams = CompaniesAPI.CompanyListParams;
633728
export import CompanyDeleteParams = CompaniesAPI.CompanyDeleteParams;
729+
export import CompanyRetrieveListParams = CompaniesAPI.CompanyRetrieveListParams;
634730
export import CompanyScrollParams = CompaniesAPI.CompanyScrollParams;
635731
export import Contacts = ContactsAPI.Contacts;
636732
export import CompanyAttachedContacts = ContactsAPI.CompanyAttachedContacts;

src/resources/companies/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export {
1111
CompanyUpdateParams,
1212
CompanyListParams,
1313
CompanyDeleteParams,
14+
CompanyRetrieveListParams,
1415
CompanyScrollParams,
1516
Companies,
1617
} from './companies';

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export {
2525
CompanyUpdateParams,
2626
CompanyListParams,
2727
CompanyDeleteParams,
28+
CompanyRetrieveListParams,
2829
CompanyScrollParams,
2930
Companies,
3031
} from './companies/companies';

tests/api-resources/companies/companies.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,42 @@ describe('resource companies', () => {
165165
).rejects.toThrow(Intercom.NotFoundError);
166166
});
167167

168+
test('retrieveList', async () => {
169+
const responsePromise = intercom.companies.retrieveList();
170+
const rawResponse = await responsePromise.asResponse();
171+
expect(rawResponse).toBeInstanceOf(Response);
172+
const response = await responsePromise;
173+
expect(response).not.toBeInstanceOf(Response);
174+
const dataAndResponse = await responsePromise.withResponse();
175+
expect(dataAndResponse.data).toBe(response);
176+
expect(dataAndResponse.response).toBe(rawResponse);
177+
});
178+
179+
test('retrieveList: request options instead of params are passed correctly', async () => {
180+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
181+
await expect(intercom.companies.retrieveList({ path: '/_stainless_unknown_path' })).rejects.toThrow(
182+
Intercom.NotFoundError,
183+
);
184+
});
185+
186+
test('retrieveList: request options and params are passed correctly', async () => {
187+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
188+
await expect(
189+
intercom.companies.retrieveList(
190+
{
191+
company_id: 'string',
192+
name: 'string',
193+
page: 0,
194+
per_page: 0,
195+
segment_id: 'string',
196+
tag_id: 'string',
197+
'Intercom-Version': '2.11',
198+
},
199+
{ path: '/_stainless_unknown_path' },
200+
),
201+
).rejects.toThrow(Intercom.NotFoundError);
202+
});
203+
168204
test('scroll', async () => {
169205
const responsePromise = intercom.companies.scroll();
170206
const rawResponse = await responsePromise.asResponse();

0 commit comments

Comments
 (0)