diff --git a/types/intercom-client/Company.d.ts b/types/intercom-client/Company.d.ts new file mode 100644 index 0000000000..ee20d80863 --- /dev/null +++ b/types/intercom-client/Company.d.ts @@ -0,0 +1,33 @@ + +export interface CompanyIdentifier { + company_id: string +} + +export interface Company { + readonly "type": "company", + readonly "id": string, + readonly app_id?: string, + company_id?: string, + plan?: string | { type: string, id: string, name: string }, + remote_created_at?: number, + name?: string, + readonly "updated_at": number, + readonly "created_at": number, + size?: number, + website?: string, + industry?: string, + monthly_spend?: number, + session_count?: number, + user_count?: number, + custom_attributes?: { + [key: string]: any + }, + +} + +export interface List { + "type": "company.list", + "total_count": number, + "companies": (Company & CompanyIdentifier)[], + "pages": { "next"?: string, "page": number, "per_page": number, "total_pages": number } +} \ No newline at end of file diff --git a/types/intercom-client/IntercomError.d.ts b/types/intercom-client/IntercomError.d.ts new file mode 100644 index 0000000000..c0ed687a3c --- /dev/null +++ b/types/intercom-client/IntercomError.d.ts @@ -0,0 +1,14 @@ + +export interface IntercomError { + statusCode: number, + body: { + type: "error.list", + request_id: string, + errors: Array<{ + code: string, //"400", + message: string + }> + }, + headers: { status: string } & { [k: string]: string } +} + diff --git a/types/intercom-client/User.d.ts b/types/intercom-client/User.d.ts index 880b8b5681..5b5450f35d 100644 --- a/types/intercom-client/User.d.ts +++ b/types/intercom-client/User.d.ts @@ -1,4 +1,4 @@ -import {Company} from "intercom-client"; +import { Company } from "./Company"; export type UserIdentifier = { "id": string } | { "user_id": string } | { "email": string } diff --git a/types/intercom-client/index.d.ts b/types/intercom-client/index.d.ts index 4d9e572da0..c9c9fc3364 100644 --- a/types/intercom-client/index.d.ts +++ b/types/intercom-client/index.d.ts @@ -3,8 +3,16 @@ // Definitions by: Jinesh Shah , Josef Hornych // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 +/// + import { List as UserList, User, UserIdentifier } from './User'; +import { CompanyIdentifier, List as CompanyList, Company } from './Company'; import { Scroll } from './Scroll'; +import { IntercomError } from './IntercomError'; + +import { IncomingMessage } from 'http'; + +export { IntercomError }; export interface IdentityVerificationOptions { secretKey: string; @@ -20,22 +28,30 @@ export class Client { constructor(username: string, password: string); users: Users; + companies: Companies; } -export interface Company { - readonly "id": string; +export class ApiResponse extends IncomingMessage { + body: T; } +export type callback = ((d: T) => void) | ((err: IntercomError, d: T) => void); + export class Users { - create(user: Partial): Promise; + create(user: Partial): Promise>; + create(user: Partial, cb: callback>): void; - update(user: UserIdentifier & Partial): Promise; + update(user: UserIdentifier & Partial): Promise>; + update(user: UserIdentifier & Partial, cb: callback>): void; - find(identifier: UserIdentifier): Promise; + find(identifier: UserIdentifier): Promise>; + find(identifier: UserIdentifier, cb: callback>): void; - list(): Promise; + list(): Promise>; + list(cb: callback>): void; - listBy(params: {tag_id: string, segment_id: string}): Promise; + listBy(params: {tag_id?: string, segment_id?: string}): Promise>; + listBy(params: {tag_id?: string, segment_id?: string}, cb: callback>): void; scroll: Scroll; @@ -43,3 +59,24 @@ export class Users { requestPermanentDeletion(): Promise<{id: number}>; } + +export class Companies { + create(company: CompanyIdentifier & Partial): Promise>; + create(company: CompanyIdentifier & Partial, cb: callback>): void; + + update(company: CompanyIdentifier & Partial): Promise>; + update(company: CompanyIdentifier & Partial, cb: callback>): void; + + find(identifier: CompanyIdentifier): Promise>; + find(identifier: CompanyIdentifier, cb: callback>): void; + + list(): Promise>; + list(cb: callback>): void; + + listBy(params: {tag_id?: string, segment_id?: string}): Promise>; + listBy(params: {tag_id?: string, segment_id?: string}, cb: callback>): void; + + scroll: Scroll; + + archive(): Promise; +}