Adding more types to intercom-client (#26936)

This commit is contained in:
Saulo Tauil
2018-07-05 10:14:24 -07:00
committed by Mohamed Hegazy
parent eb868d6677
commit b42074d845
4 changed files with 84 additions and 3 deletions
+1 -3
View File
@@ -1,7 +1,5 @@
export interface CompanyIdentifier {
company_id: string
}
export type CompanyIdentifier = { id: string } | { company_id: string }
export interface Company {
readonly "type": "company",
+24
View File
@@ -0,0 +1,24 @@
interface IntercomUserIdId { intercom_user_id: string }
interface UserIdId { user_id: string }
interface EmailIdId { email: string }
export type EventIdentifier = IntercomUserIdId | UserIdId | EmailIdId;
export interface Event extends Partial<UserIdId>, Partial<IntercomUserIdId>, Partial<EmailIdId> {
readonly id: string,
created_at: number,
event_name: string,
metadata?: any;
}
export type ListParam = EventIdentifier & {
type: 'user',
per_page?: number, // max 100
}
export interface List {
"type": "event.list",
"total_count": number,
"events": (Event)[],
"pages": { "next"?: string, "page": number, "per_page": number, "total_pages": number }
}
+30
View File
@@ -0,0 +1,30 @@
import { UserIdentifier } from "./User";
export interface TagIdentifier {
id: string
}
export interface Tag extends Partial<TagIdentifier> {
readonly type: "tag",
readonly id: string,
name: string,
}
export interface List {
"type": "tag.list",
"total_count": number,
"tags": (Tag)[],
"pages": { "next"?: string, "page": number, "per_page": number, "total_pages": number }
}
interface TagUsers {
name: string,
users: UserIdentifier[]
}
interface TagCompanies {
name: string,
users: { id: string }[]
}
type TagOper = TagCompanies | TagUsers;
+29
View File
@@ -7,6 +7,8 @@
import { List as UserList, User, UserIdentifier } from './User';
import { CompanyIdentifier, List as CompanyList, Company } from './Company';
import { TagIdentifier, List as TagList, Tag, TagOper } from './Tag';
import { List as EventList, Event, ListParam as EventListParam } from './Event';
import { Scroll } from './Scroll';
import { IntercomError } from './IntercomError';
@@ -29,6 +31,8 @@ export class Client {
users: Users;
companies: Companies;
tags: Tags;
events: Events;
}
export class ApiResponse<T> extends IncomingMessage {
@@ -80,3 +84,28 @@ export class Companies {
archive(): Promise<Company>;
}
export class Tags {
create(tag: Partial<Tag>): Promise<ApiResponse<Tag>>;
create(tag: Partial<Tag>, cb: callback<ApiResponse<Tag>>): void;
tag(tagOper: TagOper): Promise<ApiResponse<Tag>>;
tag(tagOper: TagOper, cb: callback<ApiResponse<Tag>>): void;
untag(tagOper: TagOper): Promise<ApiResponse<Tag>>;
untag(tagOper: TagOper, cb: callback<ApiResponse<Tag>>): void;
delete(tag: TagIdentifier): Promise<IncomingMessage>;
delete(tag: TagIdentifier, cb: callback<IncomingMessage>): void;
list(): Promise<ApiResponse<TagList>>;
list(cb: callback<ApiResponse<TagList>>): void;
}
export class Events {
create(event: Partial<Event>): Promise<IncomingMessage>;
create(event: Partial<Event>, cb: callback<IncomingMessage>): void;
listBy(params: EventListParam): Promise<ApiResponse<CompanyList>>;
listBy(params: EventListParam, cb: callback<ApiResponse<CompanyList>>): void;
}