From c242d55f9712823e28e3f3af656b1dc27e539523 Mon Sep 17 00:00:00 2001 From: Saulo Tauil Date: Tue, 19 Jun 2018 02:29:01 -0700 Subject: [PATCH 1/6] Extending and fixing intercom api typings --- types/intercom-client/Company.d.ts | 31 ++++++++++++++ types/intercom-client/IntercomError.d.ts | 16 +++++++ types/intercom-client/User.d.ts | 2 +- types/intercom-client/index.d.ts | 53 ++++++++++++++++++++---- 4 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 types/intercom-client/Company.d.ts create mode 100644 types/intercom-client/IntercomError.d.ts diff --git a/types/intercom-client/Company.d.ts b/types/intercom-client/Company.d.ts new file mode 100644 index 0000000000..8fedb015c6 --- /dev/null +++ b/types/intercom-client/Company.d.ts @@ -0,0 +1,31 @@ + +export type 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..44482e4e03 --- /dev/null +++ b/types/intercom-client/IntercomError.d.ts @@ -0,0 +1,16 @@ + +export interface IntercomError { + statusCode: number, + body: { + type: "error.list", + request_id: string, + errors: [ + { + 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..8ffdea477f 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; +type ApiResponse = IncomingMessage & { + body: T } +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,26 @@ 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; +} From 8aa65706fa1191b62c1730e7a40ac9d59e7447bb Mon Sep 17 00:00:00 2001 From: Saulo Tauil Date: Tue, 19 Jun 2018 02:37:55 -0700 Subject: [PATCH 2/6] fix linter --- types/intercom-client/index.d.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/types/intercom-client/index.d.ts b/types/intercom-client/index.d.ts index 8ffdea477f..b08e26f9ad 100644 --- a/types/intercom-client/index.d.ts +++ b/types/intercom-client/index.d.ts @@ -6,9 +6,9 @@ /// import { List as UserList, User, UserIdentifier } from './User'; -import { CompanyIdentifier, List as CompanyList, Company } from './Company' +import { CompanyIdentifier, List as CompanyList, Company } from './Company'; import { Scroll } from './Scroll'; -import { IntercomError } from './IntercomError' +import { IntercomError } from './IntercomError'; import { IncomingMessage } from 'http'; @@ -31,11 +31,11 @@ export class Client { companies: Companies; } -type ApiResponse = IncomingMessage & { +export type ApiResponse = IncomingMessage & { body: T -} +}; -type callback = ((d: T) => void) | ((err: IntercomError, d: T) => void); +export type callback = ((d: T) => void) | ((err: IntercomError, d: T) => void); export class Users { create(user: Partial): Promise>; @@ -60,9 +60,7 @@ export class Users { requestPermanentDeletion(): Promise<{id: number}>; } - export class Companies { - create(company: CompanyIdentifier & Partial): Promise>; create(company: CompanyIdentifier & Partial, cb: callback>): void; From 01d036688ee13bed63ba3af009031051aea202e9 Mon Sep 17 00:00:00 2001 From: Saulo Tauil Date: Wed, 20 Jun 2018 20:10:07 -0700 Subject: [PATCH 3/6] Converting CompanyIdentifier to interface --- types/intercom-client/Company.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/intercom-client/Company.d.ts b/types/intercom-client/Company.d.ts index 8fedb015c6..ee20d80863 100644 --- a/types/intercom-client/Company.d.ts +++ b/types/intercom-client/Company.d.ts @@ -1,5 +1,7 @@ -export type CompanyIdentifier = {company_id: string } +export interface CompanyIdentifier { + company_id: string +} export interface Company { readonly "type": "company", From 00bb6a0a747075135e88af9981b0cee7286a0249 Mon Sep 17 00:00:00 2001 From: Saulo Tauil Date: Wed, 20 Jun 2018 20:14:55 -0700 Subject: [PATCH 4/6] converting ApiResponse to class --- types/intercom-client/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/intercom-client/index.d.ts b/types/intercom-client/index.d.ts index b08e26f9ad..036da724dd 100644 --- a/types/intercom-client/index.d.ts +++ b/types/intercom-client/index.d.ts @@ -31,9 +31,9 @@ export class Client { companies: Companies; } -export type ApiResponse = IncomingMessage & { +export class ApiResponse extends IncomingMessage { body: T -}; +} export type callback = ((d: T) => void) | ((err: IntercomError, d: T) => void); From a461a4c4e2571cdfa8d4b639a33a3851ebebe096 Mon Sep 17 00:00:00 2001 From: Saulo Tauil Date: Wed, 20 Jun 2018 20:20:16 -0700 Subject: [PATCH 5/6] Turning IntercomError.errors a more clear array type --- types/intercom-client/IntercomError.d.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/types/intercom-client/IntercomError.d.ts b/types/intercom-client/IntercomError.d.ts index 44482e4e03..c0ed687a3c 100644 --- a/types/intercom-client/IntercomError.d.ts +++ b/types/intercom-client/IntercomError.d.ts @@ -2,15 +2,13 @@ export interface IntercomError { statusCode: number, body: { - type: "error.list", - request_id: string, - errors: [ - { - code: string, //"400", - message: string - } - ] + type: "error.list", + request_id: string, + errors: Array<{ + code: string, //"400", + message: string + }> }, - headers: { status: string } & {[k: string]: string} + headers: { status: string } & { [k: string]: string } } From 39d98dbf3e88908f6be274110ea41d6adb22f30d Mon Sep 17 00:00:00 2001 From: Saulo Tauil Date: Wed, 20 Jun 2018 20:24:57 -0700 Subject: [PATCH 6/6] fixing tslint --- types/intercom-client/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/intercom-client/index.d.ts b/types/intercom-client/index.d.ts index 036da724dd..c9c9fc3364 100644 --- a/types/intercom-client/index.d.ts +++ b/types/intercom-client/index.d.ts @@ -32,7 +32,7 @@ export class Client { } export class ApiResponse extends IncomingMessage { - body: T + body: T; } export type callback = ((d: T) => void) | ((err: IntercomError, d: T) => void);