realtimex-crm 0.7.14 → 0.9.1

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.
Files changed (32) hide show
  1. package/dist/assets/{DealList-CZvo7G6M.js → DealList-DnGVfS15.js} +2 -2
  2. package/dist/assets/{DealList-CZvo7G6M.js.map → DealList-DnGVfS15.js.map} +1 -1
  3. package/dist/assets/index-DPrpo5Xq.js +159 -0
  4. package/dist/assets/index-DPrpo5Xq.js.map +1 -0
  5. package/dist/assets/index-kM1Og1AS.css +1 -0
  6. package/dist/index.html +1 -1
  7. package/dist/stats.html +1 -1
  8. package/package.json +2 -1
  9. package/src/components/atomic-crm/integrations/ApiKeysTab.tsx +184 -0
  10. package/src/components/atomic-crm/integrations/CreateApiKeyDialog.tsx +217 -0
  11. package/src/components/atomic-crm/integrations/IntegrationsPage.tsx +34 -0
  12. package/src/components/atomic-crm/integrations/WebhooksTab.tsx +402 -0
  13. package/src/components/atomic-crm/layout/Header.tsx +14 -1
  14. package/src/components/atomic-crm/root/CRM.tsx +2 -0
  15. package/src/components/supabase/change-password-page.tsx +9 -1
  16. package/src/components/supabase/forgot-password-page.tsx +30 -0
  17. package/src/components/supabase/layout.tsx +6 -2
  18. package/src/components/ui/alert-dialog.tsx +155 -0
  19. package/src/lib/api-key-utils.ts +22 -0
  20. package/supabase/functions/_shared/apiKeyAuth.ts +171 -0
  21. package/supabase/functions/_shared/webhookSignature.ts +23 -0
  22. package/supabase/functions/api-v1-activities/index.ts +137 -0
  23. package/supabase/functions/api-v1-companies/index.ts +166 -0
  24. package/supabase/functions/api-v1-contacts/index.ts +171 -0
  25. package/supabase/functions/api-v1-deals/index.ts +166 -0
  26. package/supabase/functions/webhook-dispatcher/index.ts +133 -0
  27. package/supabase/migrations/20251219120000_api_integrations.sql +133 -0
  28. package/supabase/migrations/20251219120100_webhook_triggers.sql +171 -0
  29. package/supabase/migrations/20251219120200_webhook_cron.sql +26 -0
  30. package/dist/assets/index-CdoQZFIX.css +0 -1
  31. package/dist/assets/index-D0sWLaB1.js +0 -153
  32. package/dist/assets/index-D0sWLaB1.js.map +0 -1
@@ -0,0 +1,402 @@
1
+ import { useState } from "react";
2
+ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { useDataProvider, useNotify, useGetIdentity } from "ra-core";
4
+ import { useForm } from "react-hook-form";
5
+ import { generateApiKey } from "@/lib/api-key-utils";
6
+ import { Button } from "@/components/ui/button";
7
+ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
8
+ import { Plus, Trash2, Power, PowerOff } from "lucide-react";
9
+ import { Badge } from "@/components/ui/badge";
10
+ import { format } from "date-fns";
11
+ import {
12
+ Dialog,
13
+ DialogContent,
14
+ DialogDescription,
15
+ DialogHeader,
16
+ DialogTitle,
17
+ } from "@/components/ui/dialog";
18
+ import { Input } from "@/components/ui/input";
19
+ import { Label } from "@/components/ui/label";
20
+ import { Checkbox } from "@/components/ui/checkbox";
21
+ import {
22
+ AlertDialog,
23
+ AlertDialogAction,
24
+ AlertDialogCancel,
25
+ AlertDialogContent,
26
+ AlertDialogDescription,
27
+ AlertDialogFooter,
28
+ AlertDialogHeader,
29
+ AlertDialogTitle,
30
+ } from "@/components/ui/alert-dialog";
31
+
32
+ const AVAILABLE_EVENTS = [
33
+ { value: "contact.created", label: "Contact Created", category: "Contacts" },
34
+ { value: "contact.updated", label: "Contact Updated", category: "Contacts" },
35
+ { value: "contact.deleted", label: "Contact Deleted", category: "Contacts" },
36
+ { value: "company.created", label: "Company Created", category: "Companies" },
37
+ { value: "company.updated", label: "Company Updated", category: "Companies" },
38
+ { value: "company.deleted", label: "Company Deleted", category: "Companies" },
39
+ { value: "deal.created", label: "Deal Created", category: "Deals" },
40
+ { value: "deal.updated", label: "Deal Updated", category: "Deals" },
41
+ { value: "deal.deleted", label: "Deal Deleted", category: "Deals" },
42
+ {
43
+ value: "deal.stage_changed",
44
+ label: "Deal Stage Changed",
45
+ category: "Deals",
46
+ },
47
+ { value: "deal.won", label: "Deal Won", category: "Deals" },
48
+ { value: "deal.lost", label: "Deal Lost", category: "Deals" },
49
+ { value: "task.completed", label: "Task Completed", category: "Tasks" },
50
+ ];
51
+
52
+ export const WebhooksTab = () => {
53
+ const [showCreateDialog, setShowCreateDialog] = useState(false);
54
+ const [webhookToDelete, setWebhookToDelete] = useState<number | null>(null);
55
+ const dataProvider = useDataProvider();
56
+ const notify = useNotify();
57
+ const queryClient = useQueryClient();
58
+
59
+ const { data: webhooks, isLoading } = useQuery({
60
+ queryKey: ["webhooks"],
61
+ queryFn: async () => {
62
+ const { data } = await dataProvider.getList("webhooks", {
63
+ pagination: { page: 1, perPage: 100 },
64
+ sort: { field: "created_at", order: "DESC" },
65
+ filter: {},
66
+ });
67
+ return data;
68
+ },
69
+ });
70
+
71
+ const deleteMutation = useMutation({
72
+ mutationFn: async (id: number) => {
73
+ await dataProvider.delete("webhooks", { id, previousData: {} });
74
+ },
75
+ onSuccess: () => {
76
+ queryClient.invalidateQueries({ queryKey: ["webhooks"] });
77
+ notify("Webhook deleted successfully");
78
+ setWebhookToDelete(null);
79
+ },
80
+ onError: () => {
81
+ notify("Failed to delete webhook", { type: "error" });
82
+ },
83
+ });
84
+
85
+ const toggleMutation = useMutation({
86
+ mutationFn: async ({ id, is_active }: { id: number; is_active: boolean }) => {
87
+ await dataProvider.update("webhooks", {
88
+ id,
89
+ data: { is_active },
90
+ previousData: {},
91
+ });
92
+ },
93
+ onSuccess: () => {
94
+ queryClient.invalidateQueries({ queryKey: ["webhooks"] });
95
+ notify("Webhook updated successfully");
96
+ },
97
+ onError: () => {
98
+ notify("Failed to update webhook", { type: "error" });
99
+ },
100
+ });
101
+
102
+ return (
103
+ <div className="space-y-4">
104
+ <div className="flex justify-between items-center">
105
+ <p className="text-sm text-muted-foreground">
106
+ Webhooks notify external systems when events occur in your CRM.
107
+ </p>
108
+ <Button onClick={() => setShowCreateDialog(true)}>
109
+ <Plus className="h-4 w-4 mr-2" />
110
+ Create Webhook
111
+ </Button>
112
+ </div>
113
+
114
+ {isLoading ? (
115
+ <Card>
116
+ <CardContent className="py-8 text-center text-muted-foreground">
117
+ Loading...
118
+ </CardContent>
119
+ </Card>
120
+ ) : webhooks && webhooks.length > 0 ? (
121
+ <div className="space-y-3">
122
+ {webhooks.map((webhook: any) => (
123
+ <WebhookCard
124
+ key={webhook.id}
125
+ webhook={webhook}
126
+ onDelete={() => setWebhookToDelete(webhook.id)}
127
+ onToggle={() =>
128
+ toggleMutation.mutate({
129
+ id: webhook.id,
130
+ is_active: !webhook.is_active,
131
+ })
132
+ }
133
+ />
134
+ ))}
135
+ </div>
136
+ ) : (
137
+ <Card>
138
+ <CardContent className="py-12 text-center">
139
+ <p className="text-muted-foreground mb-4">No webhooks yet</p>
140
+ <Button onClick={() => setShowCreateDialog(true)}>
141
+ <Plus className="h-4 w-4 mr-2" />
142
+ Create your first webhook
143
+ </Button>
144
+ </CardContent>
145
+ </Card>
146
+ )}
147
+
148
+ <CreateWebhookDialog
149
+ open={showCreateDialog}
150
+ onClose={() => setShowCreateDialog(false)}
151
+ />
152
+
153
+ <AlertDialog
154
+ open={webhookToDelete !== null}
155
+ onOpenChange={() => setWebhookToDelete(null)}
156
+ >
157
+ <AlertDialogContent>
158
+ <AlertDialogHeader>
159
+ <AlertDialogTitle>Delete Webhook?</AlertDialogTitle>
160
+ <AlertDialogDescription>
161
+ This will permanently delete this webhook. No more events will be
162
+ sent to this endpoint. This action cannot be undone.
163
+ </AlertDialogDescription>
164
+ </AlertDialogHeader>
165
+ <AlertDialogFooter>
166
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
167
+ <AlertDialogAction
168
+ onClick={() =>
169
+ webhookToDelete && deleteMutation.mutate(webhookToDelete)
170
+ }
171
+ className="bg-destructive hover:bg-destructive/90"
172
+ >
173
+ Delete
174
+ </AlertDialogAction>
175
+ </AlertDialogFooter>
176
+ </AlertDialogContent>
177
+ </AlertDialog>
178
+ </div>
179
+ );
180
+ };
181
+
182
+ const WebhookCard = ({
183
+ webhook,
184
+ onDelete,
185
+ onToggle,
186
+ }: {
187
+ webhook: any;
188
+ onDelete: () => void;
189
+ onToggle: () => void;
190
+ }) => {
191
+ return (
192
+ <Card>
193
+ <CardHeader className="pb-3">
194
+ <div className="flex justify-between items-start">
195
+ <div className="flex-1">
196
+ <CardTitle className="text-lg">{webhook.name}</CardTitle>
197
+ <p className="text-sm text-muted-foreground mt-1 break-all">
198
+ {webhook.url}
199
+ </p>
200
+ <div className="flex flex-wrap gap-1 mt-2">
201
+ {webhook.is_active ? (
202
+ <Badge variant="default">Active</Badge>
203
+ ) : (
204
+ <Badge variant="secondary">Inactive</Badge>
205
+ )}
206
+ {webhook.events &&
207
+ webhook.events.slice(0, 3).map((event: string) => (
208
+ <Badge key={event} variant="outline">
209
+ {event}
210
+ </Badge>
211
+ ))}
212
+ {webhook.events && webhook.events.length > 3 && (
213
+ <Badge variant="outline">+{webhook.events.length - 3} more</Badge>
214
+ )}
215
+ </div>
216
+ </div>
217
+ <div className="flex gap-2">
218
+ <Button variant="ghost" size="icon" onClick={onToggle}>
219
+ {webhook.is_active ? (
220
+ <PowerOff className="h-4 w-4" />
221
+ ) : (
222
+ <Power className="h-4 w-4" />
223
+ )}
224
+ </Button>
225
+ <Button variant="ghost" size="icon" onClick={onDelete}>
226
+ <Trash2 className="h-4 w-4 text-destructive" />
227
+ </Button>
228
+ </div>
229
+ </div>
230
+ </CardHeader>
231
+ <CardContent>
232
+ <div className="text-xs text-muted-foreground space-y-1">
233
+ <p>Created: {format(new Date(webhook.created_at), "PPP")}</p>
234
+ {webhook.last_triggered_at && (
235
+ <p>
236
+ Last triggered:{" "}
237
+ {format(new Date(webhook.last_triggered_at), "PPp")}
238
+ </p>
239
+ )}
240
+ {webhook.failure_count > 0 && (
241
+ <p className="text-destructive">
242
+ Failed deliveries: {webhook.failure_count}
243
+ </p>
244
+ )}
245
+ </div>
246
+ </CardContent>
247
+ </Card>
248
+ );
249
+ };
250
+
251
+ const CreateWebhookDialog = ({
252
+ open,
253
+ onClose,
254
+ }: {
255
+ open: boolean;
256
+ onClose: () => void;
257
+ }) => {
258
+ const dataProvider = useDataProvider();
259
+ const notify = useNotify();
260
+ const queryClient = useQueryClient();
261
+ const { identity } = useGetIdentity();
262
+
263
+ const { register, handleSubmit, watch, setValue, reset } = useForm({
264
+ defaultValues: {
265
+ name: "",
266
+ url: "",
267
+ events: [] as string[],
268
+ },
269
+ });
270
+
271
+ const createMutation = useMutation({
272
+ mutationFn: async (values: any) => {
273
+ // Generate a random secret for webhook signature
274
+ const secret = generateApiKey();
275
+
276
+ await dataProvider.create("webhooks", {
277
+ data: {
278
+ name: values.name,
279
+ url: values.url,
280
+ events: values.events,
281
+ is_active: true,
282
+ secret,
283
+ sales_id: identity?.id,
284
+ created_by_sales_id: identity?.id,
285
+ },
286
+ });
287
+ },
288
+ onSuccess: () => {
289
+ queryClient.invalidateQueries({ queryKey: ["webhooks"] });
290
+ notify("Webhook created successfully");
291
+ reset();
292
+ onClose();
293
+ },
294
+ onError: () => {
295
+ notify("Failed to create webhook", { type: "error" });
296
+ },
297
+ });
298
+
299
+ const toggleEvent = (event: string) => {
300
+ const currentEvents = watch("events");
301
+ if (currentEvents.includes(event)) {
302
+ setValue(
303
+ "events",
304
+ currentEvents.filter((e) => e !== event)
305
+ );
306
+ } else {
307
+ setValue("events", [...currentEvents, event]);
308
+ }
309
+ };
310
+
311
+ const handleClose = () => {
312
+ reset();
313
+ onClose();
314
+ };
315
+
316
+ // Group events by category
317
+ const eventsByCategory = AVAILABLE_EVENTS.reduce((acc, event) => {
318
+ if (!acc[event.category]) {
319
+ acc[event.category] = [];
320
+ }
321
+ acc[event.category].push(event);
322
+ return acc;
323
+ }, {} as Record<string, typeof AVAILABLE_EVENTS>);
324
+
325
+ return (
326
+ <Dialog open={open} onOpenChange={handleClose}>
327
+ <DialogContent className="sm:max-w-[600px] max-h-[80vh] overflow-y-auto">
328
+ <DialogHeader>
329
+ <DialogTitle>Create Webhook</DialogTitle>
330
+ <DialogDescription>
331
+ Create a new webhook to receive event notifications
332
+ </DialogDescription>
333
+ </DialogHeader>
334
+
335
+ <form
336
+ onSubmit={handleSubmit((values) => createMutation.mutate(values))}
337
+ >
338
+ <div className="space-y-4">
339
+ <div className="space-y-2">
340
+ <Label htmlFor="name">Name</Label>
341
+ <Input
342
+ id="name"
343
+ placeholder="e.g., Slack Notifications"
344
+ {...register("name", { required: true })}
345
+ />
346
+ </div>
347
+
348
+ <div className="space-y-2">
349
+ <Label htmlFor="url">Webhook URL</Label>
350
+ <Input
351
+ id="url"
352
+ type="url"
353
+ placeholder="https://example.com/webhook"
354
+ {...register("url", { required: true })}
355
+ />
356
+ </div>
357
+
358
+ <div className="space-y-2">
359
+ <Label>Events to Subscribe</Label>
360
+ <div className="space-y-3 max-h-60 overflow-y-auto border rounded-md p-3">
361
+ {Object.entries(eventsByCategory).map(([category, events]) => (
362
+ <div key={category}>
363
+ <p className="text-sm font-semibold mb-2">{category}</p>
364
+ <div className="space-y-2 ml-2">
365
+ {events.map((event) => (
366
+ <div
367
+ key={event.value}
368
+ className="flex items-center space-x-2"
369
+ >
370
+ <Checkbox
371
+ id={event.value}
372
+ checked={watch("events").includes(event.value)}
373
+ onCheckedChange={() => toggleEvent(event.value)}
374
+ />
375
+ <label
376
+ htmlFor={event.value}
377
+ className="text-sm cursor-pointer"
378
+ >
379
+ {event.label}
380
+ </label>
381
+ </div>
382
+ ))}
383
+ </div>
384
+ </div>
385
+ ))}
386
+ </div>
387
+ </div>
388
+
389
+ <div className="flex justify-end gap-2">
390
+ <Button type="button" variant="outline" onClick={handleClose}>
391
+ Cancel
392
+ </Button>
393
+ <Button type="submit" disabled={createMutation.isPending}>
394
+ Create
395
+ </Button>
396
+ </div>
397
+ </div>
398
+ </form>
399
+ </DialogContent>
400
+ </Dialog>
401
+ );
402
+ };
@@ -3,7 +3,7 @@ import {
3
3
  DropdownMenuLabel,
4
4
  DropdownMenuSeparator,
5
5
  } from "@/components/ui/dropdown-menu";
6
- import { Database, Settings, User } from "lucide-react";
6
+ import { Database, Settings, User, Webhook } from "lucide-react";
7
7
  import { CanAccess } from "ra-core";
8
8
  import { Link, matchPath, useLocation } from "react-router";
9
9
  import { RefreshButton } from "@/components/admin/refresh-button";
@@ -64,6 +64,7 @@ const Header = () => {
64
64
  <UserMenu>
65
65
  <ConfigurationMenu />
66
66
  <DatabaseMenu />
67
+ <IntegrationsMenu />
67
68
  <CanAccess resource="sales" action="list">
68
69
  <UsersMenu />
69
70
  </CanAccess>
@@ -165,4 +166,16 @@ const DatabaseMenu = () => {
165
166
  );
166
167
  };
167
168
 
169
+ const IntegrationsMenu = () => {
170
+ const { onClose } = useUserMenu() ?? {};
171
+ return (
172
+ <DropdownMenuItem asChild onClick={onClose}>
173
+ <Link to="/integrations" className="flex items-center gap-2">
174
+ <Webhook className="h-4 w-4" />
175
+ Integrations
176
+ </Link>
177
+ </DropdownMenuItem>
178
+ );
179
+ };
180
+
168
181
  export default Header;
@@ -26,6 +26,7 @@ import {
26
26
  import sales from "../sales";
27
27
  import { DatabasePage } from "../settings/DatabasePage";
28
28
  import { SettingsPage } from "../settings/SettingsPage";
29
+ import { IntegrationsPage } from "../integrations/IntegrationsPage";
29
30
  import type { ConfigurationContextValue } from "./ConfigurationContext";
30
31
  import { ConfigurationProvider } from "./ConfigurationContext";
31
32
  import {
@@ -163,6 +164,7 @@ export const CRM = ({
163
164
  <CustomRoutes>
164
165
  <Route path={SettingsPage.path} element={<SettingsPage />} />
165
166
  <Route path={DatabasePage.path} element={<DatabasePage />} />
167
+ <Route path={IntegrationsPage.path} element={<IntegrationsPage />} />
166
168
  </CustomRoutes>
167
169
  <Resource name="deals" {...deals} />
168
170
  <Resource name="contacts" {...contacts} />
@@ -5,7 +5,7 @@ import type { FieldValues, SubmitHandler } from "react-hook-form";
5
5
  import { TextInput } from "@/components/admin/text-input";
6
6
  import { Button } from "@/components/ui/button";
7
7
  import { supabase } from "@/components/atomic-crm/providers/supabase/supabase";
8
- import { useNavigate } from "react-router";
8
+ import { useNavigate, Link } from "react-router";
9
9
 
10
10
  interface FormData {
11
11
  password: string;
@@ -112,6 +112,14 @@ export const ChangePasswordPage = () => {
112
112
  {loading ? "Updating..." : "Update password"}
113
113
  </Button>
114
114
  </Form>
115
+ <div className="text-center">
116
+ <Link
117
+ to="/"
118
+ className="text-sm text-muted-foreground hover:text-primary underline-offset-4 hover:underline"
119
+ >
120
+ Back to login
121
+ </Link>
122
+ </div>
115
123
  </Layout>
116
124
  );
117
125
  };
@@ -6,6 +6,7 @@ import { TextInput } from "@/components/admin/text-input";
6
6
  import { Button } from "@/components/ui/button";
7
7
  import { OtpInput } from "@/components/supabase/otp-input";
8
8
  import { supabase } from "@/components/atomic-crm/providers/supabase/supabase";
9
+ import { Link } from "react-router";
9
10
 
10
11
  interface EmailFormData {
11
12
  email: string;
@@ -175,6 +176,14 @@ export const ForgotPasswordPage = () => {
175
176
  })}
176
177
  </Button>
177
178
  </Form>
179
+ <div className="text-center">
180
+ <Link
181
+ to="/"
182
+ className="text-sm text-muted-foreground hover:text-primary underline-offset-4 hover:underline"
183
+ >
184
+ Back to login
185
+ </Link>
186
+ </div>
178
187
  </>
179
188
  ) : (
180
189
  <>
@@ -220,8 +229,29 @@ export const ForgotPasswordPage = () => {
220
229
  >
221
230
  Resend code
222
231
  </Button>
232
+ <Button
233
+ type="button"
234
+ variant="ghost"
235
+ className="cursor-pointer w-full"
236
+ disabled={loading}
237
+ onClick={() => {
238
+ setStep('email');
239
+ setOtp('');
240
+ setOtpError(false);
241
+ }}
242
+ >
243
+ ← Back to email
244
+ </Button>
223
245
  </div>
224
246
  </div>
247
+ <div className="text-center">
248
+ <Link
249
+ to="/"
250
+ className="text-sm text-muted-foreground hover:text-primary underline-offset-4 hover:underline"
251
+ >
252
+ Back to login
253
+ </Link>
254
+ </div>
225
255
  </>
226
256
  )}
227
257
  </Layout>
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { Link } from "react-router";
2
3
  import { Notification } from "@/components/admin/notification";
3
4
  import { useConfigurationContext } from "@/components/atomic-crm/root/ConfigurationContext";
4
5
 
@@ -10,10 +11,13 @@ export const Layout = ({ children }: React.PropsWithChildren) => {
10
11
  <div className="container relative grid flex-col items-center justify-center sm:max-w-none lg:grid-cols-2 lg:px-0">
11
12
  <div className="relative hidden h-full flex-col bg-muted p-10 text-white dark:border-r lg:flex">
12
13
  <div className="absolute inset-0 bg-zinc-900" />
13
- <div className="relative z-20 flex items-center text-lg font-medium">
14
+ <Link
15
+ to="/"
16
+ className="relative z-20 flex items-center text-lg font-medium no-underline text-white hover:opacity-80 transition-opacity"
17
+ >
14
18
  <img className="h-6 mr-2" src={darkModeLogo} alt={title} />
15
19
  {title}
16
- </div>
20
+ </Link>
17
21
  </div>
18
22
  <div className="lg:p-8">
19
23
  <div className="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]">