realtimex-crm 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{DealList-BDM22iSt.js → DealList-SBRy_lx8.js} +2 -2
- package/dist/assets/{DealList-BDM22iSt.js.map → DealList-SBRy_lx8.js.map} +1 -1
- package/dist/assets/{index-ClhQN0YK.js → index-Br4zr5YA.js} +2 -2
- package/dist/assets/{index-ClhQN0YK.js.map → index-Br4zr5YA.js.map} +1 -1
- package/dist/index.html +1 -1
- package/dist/stats.html +1 -1
- package/package.json +1 -1
- package/supabase/functions/api-v1-activities/index.ts +47 -57
- package/supabase/migrations/20251226082639_fix_contacts_summary_fts_columns.sql +73 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "realtimex-crm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "RealTimeX CRM - A full-featured CRM built with React, shadcn-admin-kit, and Supabase. Fork of Atomic CRM with RealTimeX App SDK integration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -73,65 +73,55 @@ async function createActivity(apiKey: any, req: Request) {
|
|
|
73
73
|
const body = await req.json();
|
|
74
74
|
const { type, ...activityData } = body;
|
|
75
75
|
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.from("contactNotes")
|
|
80
|
-
.insert({
|
|
81
|
-
...activityData,
|
|
82
|
-
sales_id: apiKey.sales_id,
|
|
83
|
-
})
|
|
84
|
-
.select()
|
|
85
|
-
.single();
|
|
76
|
+
// Map activity type to table and validate
|
|
77
|
+
let tableName: string;
|
|
78
|
+
let responseType: string;
|
|
86
79
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
.from("dealNotes")
|
|
116
|
-
.insert({
|
|
117
|
-
...activityData,
|
|
118
|
-
sales_id: apiKey.sales_id,
|
|
119
|
-
})
|
|
120
|
-
.select()
|
|
121
|
-
.single();
|
|
80
|
+
switch (type) {
|
|
81
|
+
case "note":
|
|
82
|
+
case "contact_note":
|
|
83
|
+
tableName = "contactNotes";
|
|
84
|
+
responseType = "contact_note";
|
|
85
|
+
break;
|
|
86
|
+
case "company_note":
|
|
87
|
+
tableName = "companyNotes";
|
|
88
|
+
responseType = "company_note";
|
|
89
|
+
break;
|
|
90
|
+
case "deal_note":
|
|
91
|
+
tableName = "dealNotes";
|
|
92
|
+
responseType = "deal_note";
|
|
93
|
+
break;
|
|
94
|
+
case "task_note":
|
|
95
|
+
tableName = "taskNotes";
|
|
96
|
+
responseType = "task_note";
|
|
97
|
+
break;
|
|
98
|
+
case "task":
|
|
99
|
+
tableName = "tasks";
|
|
100
|
+
responseType = "task";
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
return createErrorResponse(
|
|
104
|
+
400,
|
|
105
|
+
"Invalid activity type. Must be 'contact_note', 'company_note', 'deal_note', 'task_note', or 'task'"
|
|
106
|
+
);
|
|
107
|
+
}
|
|
122
108
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
109
|
+
// Insert activity
|
|
110
|
+
const { data, error } = await supabaseAdmin
|
|
111
|
+
.from(tableName)
|
|
112
|
+
.insert({
|
|
113
|
+
...activityData,
|
|
114
|
+
sales_id: apiKey.sales_id,
|
|
115
|
+
})
|
|
116
|
+
.select()
|
|
117
|
+
.single();
|
|
126
118
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
headers: { "Content-Type": "application/json", ...corsHeaders },
|
|
130
|
-
});
|
|
131
|
-
} else {
|
|
132
|
-
return createErrorResponse(
|
|
133
|
-
400,
|
|
134
|
-
"Invalid activity type. Must be 'note', 'contact_note', 'task', or 'deal_note'"
|
|
135
|
-
);
|
|
119
|
+
if (error) {
|
|
120
|
+
return createErrorResponse(400, error.message);
|
|
136
121
|
}
|
|
122
|
+
|
|
123
|
+
return new Response(JSON.stringify({ data, type: responseType }), {
|
|
124
|
+
status: 201,
|
|
125
|
+
headers: { "Content-Type": "application/json", ...corsHeaders },
|
|
126
|
+
});
|
|
137
127
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
-- Fix contacts_summary view to include email_fts and phone_fts columns for search functionality
|
|
2
|
+
-- The previous migration used c.* which doesn't include computed columns
|
|
3
|
+
|
|
4
|
+
DROP VIEW IF EXISTS contacts_summary CASCADE;
|
|
5
|
+
|
|
6
|
+
CREATE VIEW contacts_summary
|
|
7
|
+
WITH (security_invoker=on)
|
|
8
|
+
AS
|
|
9
|
+
SELECT
|
|
10
|
+
-- Explicit contact columns
|
|
11
|
+
c.id,
|
|
12
|
+
c.first_name,
|
|
13
|
+
c.last_name,
|
|
14
|
+
c.gender,
|
|
15
|
+
c.title,
|
|
16
|
+
c.email_jsonb,
|
|
17
|
+
c.phone_jsonb,
|
|
18
|
+
c.background,
|
|
19
|
+
c.avatar,
|
|
20
|
+
c.first_seen,
|
|
21
|
+
c.last_seen,
|
|
22
|
+
c.has_newsletter,
|
|
23
|
+
c.status,
|
|
24
|
+
c.tags,
|
|
25
|
+
c.company_id,
|
|
26
|
+
c.sales_id,
|
|
27
|
+
c.linkedin_url,
|
|
28
|
+
c.internal_heartbeat_score,
|
|
29
|
+
c.internal_heartbeat_status,
|
|
30
|
+
c.internal_heartbeat_updated_at,
|
|
31
|
+
c.external_heartbeat_status,
|
|
32
|
+
c.external_heartbeat_checked_at,
|
|
33
|
+
c.email_validation_status,
|
|
34
|
+
c.email_last_bounced_at,
|
|
35
|
+
c.linkedin_profile_status,
|
|
36
|
+
c.employment_verified_at,
|
|
37
|
+
|
|
38
|
+
-- Computed full-text search columns
|
|
39
|
+
jsonb_path_query_array(c.email_jsonb, '$[*].email')::text as email_fts,
|
|
40
|
+
jsonb_path_query_array(c.phone_jsonb, '$[*].number')::text as phone_fts,
|
|
41
|
+
|
|
42
|
+
-- Company relationship
|
|
43
|
+
comp.name as company_name,
|
|
44
|
+
|
|
45
|
+
-- Task and note aggregations
|
|
46
|
+
COUNT(DISTINCT t.id) as nb_tasks,
|
|
47
|
+
COUNT(DISTINCT cn.id) as nb_notes,
|
|
48
|
+
COUNT(DISTINCT t.id) FILTER (WHERE t.done_date IS NULL) as nb_open_tasks,
|
|
49
|
+
|
|
50
|
+
-- Task completion metrics
|
|
51
|
+
COUNT(DISTINCT t.id) FILTER (WHERE t.done_date IS NOT NULL) as nb_completed_tasks,
|
|
52
|
+
CASE
|
|
53
|
+
WHEN COUNT(DISTINCT t.id) > 0
|
|
54
|
+
THEN ROUND(COUNT(DISTINCT t.id) FILTER (WHERE t.done_date IS NOT NULL)::numeric / COUNT(DISTINCT t.id), 2)
|
|
55
|
+
ELSE 0
|
|
56
|
+
END as task_completion_rate,
|
|
57
|
+
|
|
58
|
+
-- Activity timestamps
|
|
59
|
+
MAX(cn.date) as last_note_date,
|
|
60
|
+
MAX(t.due_date) as last_task_activity,
|
|
61
|
+
|
|
62
|
+
-- Computed engagement indicator (days since last activity)
|
|
63
|
+
LEAST(
|
|
64
|
+
COALESCE(EXTRACT(EPOCH FROM (now() - c.last_seen))/86400, 999999),
|
|
65
|
+
COALESCE(EXTRACT(EPOCH FROM (now() - MAX(cn.date)))/86400, 999999),
|
|
66
|
+
COALESCE(EXTRACT(EPOCH FROM (now() - MAX(t.due_date)))/86400, 999999)
|
|
67
|
+
)::integer as days_since_last_activity
|
|
68
|
+
|
|
69
|
+
FROM contacts c
|
|
70
|
+
LEFT JOIN "contactNotes" cn ON c.id = cn.contact_id
|
|
71
|
+
LEFT JOIN tasks t ON c.id = t.contact_id
|
|
72
|
+
LEFT JOIN companies comp ON c.company_id = comp.id
|
|
73
|
+
GROUP BY c.id, comp.name;
|