From afd89d0e4f8e96777e5432b087affd0dc6acdf52 Mon Sep 17 00:00:00 2001 From: cdoe Date: Tue, 5 Nov 2019 15:23:37 -0600 Subject: [PATCH] [intercom-client] Add separate User type for creating and updating (#40035) --- types/intercom-client/User.d.ts | 134 ++++++++++++++++--------------- types/intercom-client/index.d.ts | 15 ++-- 2 files changed, 79 insertions(+), 70 deletions(-) diff --git a/types/intercom-client/User.d.ts b/types/intercom-client/User.d.ts index 5b5450f35d..ec58c376b5 100644 --- a/types/intercom-client/User.d.ts +++ b/types/intercom-client/User.d.ts @@ -1,85 +1,91 @@ -import { Company } from "./Company"; +import { Company } from './Company'; -export type UserIdentifier = { "id": string } | { "user_id": string } | { "email": string } +export type UserIdentifier = { id: string } | { user_id: string } | { email: string }; export interface Avatar { - "type": "avatar", - "image_url": string | null + type: 'avatar'; + image_url: string | null; } export interface SocialProfile { - "name": "Twitter", - readonly "id": string | null, - "username": string | null, - "url": string | null + name: 'Twitter'; + readonly id: string | null; + username: string | null; + url: string | null; } export interface Segment { - readonly "id": string + readonly id: string; } export interface Tag { - readonly "id": string + readonly id: string; } export interface LocationData { - "type": "location_data", - "city_name": string | null, - "continent_code": string | null, - "country_code": string | null, - "country_name": string | null, - "latitude": number | null, - "longitude": number | null, - "postal_code": string | null, - "region_name": string | null, - "timezone": string | null + type: 'location_data'; + city_name: string | null; + continent_code: string | null; + country_code: string | null; + country_name: string | null; + latitude: number | null; + longitude: number | null; + postal_code: string | null; + region_name: string | null; + timezone: string | null; } -export interface User { - "type": "user" | "contact", - readonly "id": string, - "user_id": string | null, - "email": string | null, - "app_id"?: string, - "phone": string | null, - "name": string | null, - readonly "updated_at": number, - "last_seen_ip": string | null, - "unsubscribed_from_emails": boolean, - "last_request_at": number | null, - "signed_up_at": number | null, - readonly "created_at": number, - "session_count": number, - "user_agent_data": string | null, - "pseudonym": string | null, - "anonymous": boolean, - "custom_attributes": { - [key: string]: any - }, - "avatar": Avatar, - "location_data": LocationData | {}, - "social_profiles": { - "type": "social_profile.list", - "social_profiles": SocialProfile[] - }, - "companies": { - "type": "company.list", - "companies": Company[] - }, - "segments": { - "type": "segment.list", - "segments": Segment[] +interface BaseUser { + type: 'user' | 'contact'; + readonly id: string; + user_id: string | null; + email: string | null; + app_id?: string; + phone: string | null; + name: string | null; + readonly updated_at: number; + last_seen_ip: string | null; + unsubscribed_from_emails: boolean; + last_request_at: number | null; + signed_up_at: number | null; + readonly created_at: number; + session_count: number; + user_agent_data: string | null; + pseudonym: string | null; + anonymous: boolean; + custom_attributes: { + [key: string]: any; + }; + avatar: Avatar; +} - }, - "tags": { - "type": "tag.list", - "tags": Tag[] - } +export interface User extends BaseUser { + location_data: LocationData | {}; + social_profiles: { + type: 'social_profile.list'; + social_profiles: SocialProfile[]; + }; + companies: { + type: 'company.list'; + companies: Company[]; + }; + segments: { + type: 'segment.list'; + segments: Segment[]; + }; + tags: { + type: 'tag.list'; + tags: Tag[]; + }; +} + +export interface CreateUpdateUser extends BaseUser { + companies: Partial[]; } export interface List { - "type": "user.list", - "total_count": number, - "users": User[], - "pages": { "next"?: string, "page": number, "per_page": number, "total_pages": number } -} \ No newline at end of file + type: 'user.list'; + total_count: number; + users: User[]; + pages: { next?: string; page: number; per_page: number; total_pages: number }; +} diff --git a/types/intercom-client/index.d.ts b/types/intercom-client/index.d.ts index d458ae97a7..6eddd1b686 100644 --- a/types/intercom-client/index.d.ts +++ b/types/intercom-client/index.d.ts @@ -1,11 +1,14 @@ // Type definitions for intercom-client 2.11 // Project: https://github.com/intercom/intercom-node -// Definitions by: Jinesh Shah , Josef Hornych , Mikhail Monchak +// Definitions by: Jinesh Shah +// Josef Hornych +// Mikhail Monchak +// Chris Doe // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 /// -import { List as UserList, User, UserIdentifier } from './User'; +import { List as UserList, User, UserIdentifier, CreateUpdateUser } from './User'; import { List as LeadList, Lead, LeadIdentifier } from './Lead'; import { Visitor, VisitorIdentifier } from './Visitor'; import { CompanyIdentifier, List as CompanyList, Company } from './Company'; @@ -47,11 +50,11 @@ export class ApiResponse extends IncomingMessage { export type callback = ((d: T) => void) | ((err: IntercomError, d: T) => void); export class Users { - create(user: Partial): Promise>; - create(user: Partial, cb: callback>): void; + create(user: Partial): Promise>; + create(user: Partial, cb: callback>): void; - update(user: UserIdentifier & Partial): Promise>; - update(user: UserIdentifier & Partial, cb: callback>): void; + update(user: UserIdentifier & Partial): Promise>; + update(user: UserIdentifier & Partial, cb: callback>): void; find(identifier: UserIdentifier): Promise>; find(identifier: UserIdentifier, cb: callback>): void;