@@ -3,6 +3,19 @@ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
33import { checkToken } from "../lib/jwt" ;
44import { prisma } from "../prisma" ;
55import { OAuth2Client } from "google-auth-library" ;
6+ import { track } from "../lib/hog" ;
7+
8+ async function tracking ( event : string , properties : any ) {
9+ const client = track ( ) ;
10+
11+ client . capture ( {
12+ event : event ,
13+ properties : properties ,
14+ distinctId : "uuid" ,
15+ } ) ;
16+
17+ client . shutdownAsync ( ) ;
18+ }
619
720export function emailQueueRoutes ( fastify : FastifyInstance ) {
821 // Create a new email queue
@@ -41,26 +54,47 @@ export function emailQueueRoutes(fastify: FastifyInstance) {
4154 } ) ;
4255
4356 // generate redirect uri
44- if ( serviceType === "gmail" ) {
45- const google = new OAuth2Client ( clientId , clientSecret , redirectUri ) ;
46-
47- const authorizeUrl = google . generateAuthUrl ( {
48- access_type : "offline" ,
49- scope : "https://mail.google.com" ,
50- prompt : "consent" ,
51- state : mailbox . id ,
52- } ) ;
53-
54- reply . send ( {
55- success : true ,
56- message : "Gmail imap provider created!" ,
57- authorizeUrl : authorizeUrl ,
58- } ) ;
57+ switch ( serviceType ) {
58+ case "gmail" :
59+ const google = new OAuth2Client (
60+ clientId ,
61+ clientSecret ,
62+ redirectUri
63+ ) ;
64+
65+ const authorizeUrl = google . generateAuthUrl ( {
66+ access_type : "offline" ,
67+ scope : "https://mail.google.com" ,
68+ prompt : "consent" ,
69+ state : mailbox . id ,
70+ } ) ;
71+
72+ tracking ( "gmail_provider_created" , {
73+ provider : "gmail" ,
74+ } ) ;
75+
76+ reply . send ( {
77+ success : true ,
78+ message : "Gmail imap provider created!" ,
79+ authorizeUrl : authorizeUrl ,
80+ } ) ;
81+ break ;
82+ case "other" :
83+ tracking ( "imap_provider_created" , {
84+ provider : "other" ,
85+ } ) ;
86+
87+ reply . send ( {
88+ success : true ,
89+ message : "Other service type created!" ,
90+ } ) ;
91+ break ;
92+ default :
93+ reply . send ( {
94+ success : false ,
95+ message : "Unsupported service type" ,
96+ } ) ;
5997 }
60-
61- reply . send ( {
62- success : true ,
63- } ) ;
6498 }
6599 }
66100 ) ;
0 commit comments