Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 155 additions & 2 deletions lib/close.com.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,24 @@ declare module 'closecrm-node' {
[key: string]: any;
}

export interface WhatsAppMessage extends Activity {
_type: 'WhatsAppMessage';
external_whatsapp_message_id: string;
message_markdown: string;
message_html?: string;
direction?: 'incoming' | 'outgoing';
status?: string;
response_to_id?: string;
integration_link?: string;
attachments?: Array<{
url: string;
filename: string;
content_type: string;
size?: number;
}>;
[key: string]: any;
}

export interface Task {
id: string;
lead_id?: string;
Expand All @@ -221,13 +239,41 @@ declare module 'closecrm-node' {
accepts_multiple_values?: boolean;
editable_with_roles?: string[];
required?: boolean;
custom_object_type_id?: string;
organization_id: string;
created_by?: string;
date_created: string;
date_updated: string;
[key: string]: any;
}

export interface CustomObjectType {
id: string;
name: string;
name_plural: string;
description?: string;
api_create_only?: boolean;
editable_with_roles?: string[];
fields?: CustomField[];
back_reference_fields?: CustomField[];
organization_id: string;
date_created: string;
date_updated: string;
[key: string]: any;
}

export interface CustomObject {
id: string;
custom_object_type_id: string;
lead_id: string;
name: string;
custom?: Record<string, any>;
date_created: string;
date_updated: string;
organization_id: string;
[key: string]: any;
}

export interface User {
id: string;
email: string;
Expand Down Expand Up @@ -438,13 +484,22 @@ declare module 'closecrm-node' {
delete(id: string): Promise<void>;
}

export interface WhatsAppMessageResource {
search(options?: SearchOptions): Promise<PaginatedResponse<WhatsAppMessage>>;
create(data: Partial<WhatsAppMessage>, queryParams?: { send_to_inbox?: boolean }): Promise<WhatsAppMessage>;
read(id: string): Promise<WhatsAppMessage>;
update(id: string, data: Partial<WhatsAppMessage>): Promise<WhatsAppMessage>;
delete(id: string): Promise<void>;
}

export interface ActivityResource {
search(options?: SearchOptions): Promise<PaginatedResponse<Activity>>;
note: NoteResource;
email: EmailResource;
call: CallResource;
sms: SMSResource;
meeting: MeetingResource;
whatsapp_message: WhatsAppMessageResource;
}

export interface OpportunityResource {
Expand Down Expand Up @@ -476,6 +531,7 @@ declare module 'closecrm-node' {
contact: CustomFieldSubResource;
opportunity: CustomFieldSubResource;
activity: CustomFieldSubResource;
custom_object_type: CustomFieldSubResource;
}

export interface CustomActivityResource {
Expand All @@ -486,6 +542,22 @@ declare module 'closecrm-node' {
delete(type: string, id: string): Promise<void>;
}

export interface CustomObjectTypeResource {
list(options?: SearchOptions): Promise<PaginatedResponse<CustomObjectType>>;
create(data: Partial<CustomObjectType>): Promise<CustomObjectType>;
read(id: string): Promise<CustomObjectType>;
update(id: string, data: Partial<CustomObjectType>): Promise<CustomObjectType>;
delete(id: string): Promise<void>;
}

export interface CustomObjectResource {
list(options?: SearchOptions): Promise<PaginatedResponse<CustomObject>>;
create(data: Partial<CustomObject>): Promise<CustomObject>;
read(id: string): Promise<CustomObject>;
update(id: string, data: Partial<CustomObject>): Promise<CustomObject>;
delete(id: string): Promise<void>;
}

export interface UserResource {
me(): Promise<User>;
list(options?: SearchOptions): Promise<PaginatedResponse<User>>;
Expand Down Expand Up @@ -553,8 +625,87 @@ declare module 'closecrm-node' {
}

export interface ReportResource {
list(options?: SearchOptions): Promise<PaginatedResponse<Report>>;
read(id: string, options?: SearchOptions): Promise<Report>;
// List predefined metrics used in activity reports
activity_metrics(): Promise<PaginatedResponse<any>>;

// Get an activity report
activity(data: {
datetime_range?: { start: string; end: string };
relative_range?: string;
query?: any;
users?: string[];
type: 'overview' | 'comparison';
metrics: string[];
}): Promise<any>;

// Get sent emails report grouped by template
sent_emails(organizationId: string, options?: {
user_id?: string;
date_start?: string;
date_end?: string;
}): Promise<any>;

// Get lead status change report
lead_statuses(organizationId: string, options?: {
date_start?: string;
date_end?: string;
query?: string;
smart_view_id?: string;
}): Promise<any>;

// Get opportunity status change report
opportunity_statuses(organizationId: string, options?: {
user_id?: string;
date_start?: string;
date_end?: string;
query?: string;
smart_view_id?: string;
}): Promise<any>;

// Get custom report
custom(organizationId: string, options?: {
query?: string;
x?: string;
y?: string;
interval?: string;
transform_y?: 'sum' | 'avg' | 'min' | 'max';
group_by?: string;
start?: string;
end?: string;
}): Promise<any>;

// Get custom report fields
custom_fields(): Promise<any>;

// Get opportunity funnel report (totals)
funnel_totals(data: {
pipeline: string;
type: 'created-cohort' | 'active-stage-cohort';
report_relative_range?: string;
report_datetime_range?: { start: string; end: string };
cohort_relative_range?: string;
cohort_datetime_range?: { start: string; end: string };
compared_relative_range?: string;
compared_datetime_range?: string;
compared_custom_range?: { start: string; end: string };
query?: any;
users?: string[];
}): Promise<any>;

// Get opportunity funnel report (stages)
funnel_stages(data: {
pipeline: string;
type: 'created-cohort' | 'active-stage-cohort';
report_relative_range?: string;
report_datetime_range?: { start: string; end: string };
cohort_relative_range?: string;
cohort_datetime_range?: { start: string; end: string };
compared_relative_range?: string;
compared_datetime_range?: string;
compared_custom_range?: { start: string; end: string };
query?: any;
users?: string[];
}): Promise<any>;
}

export interface EventResource {
Expand Down Expand Up @@ -618,6 +769,8 @@ declare module 'closecrm-node' {
task: TaskResource;
custom_field: CustomFieldResource;
custom_activity: CustomActivityResource;
custom_object_type: CustomObjectTypeResource;
custom_object: CustomObjectResource;
user: UserResource;
organization: OrganizationResource;
pipeline: PipelineResource;
Expand Down
70 changes: 68 additions & 2 deletions lib/close.com.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Closecom {
this._initTasks();
this._initCustomFields();
this._initCustomActivities();
this._initCustomObjects();
this._initUsers();
this._initOrganizations();
this._initPipelines();
Expand Down Expand Up @@ -138,6 +139,17 @@ class Closecom {
read: (id) => this._get(`/activity/meeting/${id}/`),
update: (id, data) => this._put(`/activity/meeting/${id}/`, data),
delete: (id) => this._delete(`/activity/meeting/${id}/`)
},

whatsapp_message: {
search: (options = {}) => this._get('/activity/whatsapp_message/', this._normalizeSearchParams({ ...options })),
create: (data, queryParams = {}) => {
const path = '/activity/whatsapp_message/';
return this._request({ method: 'POST', path, body: data, params: queryParams });
},
read: (id) => this._get(`/activity/whatsapp_message/${id}/`),
update: (id, data) => this._put(`/activity/whatsapp_message/${id}/`, data),
delete: (id) => this._delete(`/activity/whatsapp_message/${id}/`)
}
};
}
Expand Down Expand Up @@ -194,6 +206,14 @@ class Closecom {
read: (id) => this._get(`/custom_field/activity/${id}/`),
update: (id, data) => this._put(`/custom_field/activity/${id}/`, data),
delete: (id) => this._delete(`/custom_field/activity/${id}/`)
},

custom_object_type: {
list: () => this._get('/custom_field/custom_object_type/'),
create: (data) => this._post('/custom_field/custom_object_type/', data),
read: (id) => this._get(`/custom_field/custom_object_type/${id}/`),
update: (id, data) => this._put(`/custom_field/custom_object_type/${id}/`, data),
delete: (id) => this._delete(`/custom_field/custom_object_type/${id}/`)
}
};
}
Expand All @@ -208,6 +228,24 @@ class Closecom {
};
}

_initCustomObjects() {
this.custom_object_type = {
list: (options = {}) => this._get('/custom_object_type/', this._normalizeSearchParams({ ...options })),
create: (data) => this._post('/custom_object_type/', data),
read: (id) => this._get(`/custom_object_type/${id}/`),
update: (id, data) => this._put(`/custom_object_type/${id}/`, data),
delete: (id) => this._delete(`/custom_object_type/${id}/`)
};

this.custom_object = {
list: (options = {}) => this._get('/custom_object/', this._normalizeSearchParams({ ...options })),
create: (data) => this._post('/custom_object/', data),
read: (id) => this._get(`/custom_object/${id}/`),
update: (id, data) => this._put(`/custom_object/${id}/`, data),
delete: (id) => this._delete(`/custom_object/${id}/`)
};
}

_initUsers() {
this.user = {
me: () => this._get('/me/'),
Expand Down Expand Up @@ -299,8 +337,36 @@ class Closecom {

_initReports() {
this.report = {
list: (options = {}) => this._get('/report/', this._normalizeSearchParams({ ...options })),
read: (id, options = {}) => this._get(`/report/${id}/`, this._normalizeSearchParams({ ...options }))
// List predefined metrics used in activity reports
activity_metrics: () => this._get('/report/activity/metrics/'),

// Get an activity report (POST)
activity: (data) => this._post('/report/activity/', data),

// Get sent emails report grouped by template
sent_emails: (organizationId, options = {}) =>
this._get(`/report/sent_emails/${organizationId}/`, this._normalizeSearchParams({ ...options })),

// Get lead status change report
lead_statuses: (organizationId, options = {}) =>
this._get(`/report/statuses/lead/${organizationId}/`, this._normalizeSearchParams({ ...options })),

// Get opportunity status change report
opportunity_statuses: (organizationId, options = {}) =>
this._get(`/report/statuses/opportunity/${organizationId}/`, this._normalizeSearchParams({ ...options })),

// Get custom report
custom: (organizationId, options = {}) =>
this._get(`/report/custom/${organizationId}/`, this._normalizeSearchParams({ ...options })),

// Get custom report fields
custom_fields: () => this._get('/report/custom/fields/'),

// Get opportunity funnel report (totals)
funnel_totals: (data) => this._post('/report/funnel/opportunity/totals/', data),

// Get opportunity funnel report (stages)
funnel_stages: (data) => this._post('/report/funnel/opportunity/stages/', data)
};
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "closecrm-node",
"version": "1.0.2",
"version": "1.0.3",
"description": "Unofficial Close.com API client for Node.js with TypeScript support",
"main": "lib/close.com.js",
"types": "lib/close.com.d.ts",
Expand Down
Loading
Loading