Skip to content

Commit f01c5ca

Browse files
authored
0.5.4.3 🚀 (#398)
* chore: add extra events (#397) * chore: save logging to file * chore: hide fields feature flags * feat: right click context * fix: hide scroll * fix: create first issue tbn * fix: portal nav fix * fix: portal layout ui * chore: code cleanuo * chore: favicon
1 parent 2d511e8 commit f01c5ca

File tree

34 files changed

+1935
-415
lines changed

34 files changed

+1935
-415
lines changed

apps/api/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ dist
104104
.tern-port
105105

106106
/uploads
107+
108+
logs.log

apps/api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"mailparser": "^3.6.5",
5656
"nodemailer": "^6.9.7",
5757
"openid-client": "^5.7.0",
58+
"pino": "^9.5.0",
5859
"posthog-node": "^3.1.3",
5960
"prisma": "5.6.0",
6061
"samlify": "^2.8.11",

apps/api/src/controllers/auth.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ function generateRandomPassword(length: number): string {
4646
return password;
4747
}
4848

49+
async function tracking(event: string, properties: any) {
50+
const client = track();
51+
52+
client.capture({
53+
event: event,
54+
properties: properties,
55+
distinctId: "uuid",
56+
});
57+
}
58+
4959
export function authRoutes(fastify: FastifyInstance) {
5060
// Register a new user
5161
fastify.post(
@@ -175,7 +185,7 @@ export function authRoutes(fastify: FastifyInstance) {
175185
const hog = track();
176186

177187
hog.capture({
178-
event: "user_registered",
188+
event: "user_registered_external",
179189
distinctId: user.id,
180190
});
181191

@@ -339,6 +349,8 @@ export function authRoutes(fastify: FastifyInstance) {
339349
},
340350
});
341351

352+
await tracking("user_logged_in_password", {});
353+
342354
const data = {
343355
id: user!.id,
344356
email: user!.email,
@@ -523,13 +535,11 @@ export function authRoutes(fastify: FastifyInstance) {
523535
// Retrieve user information
524536
const userInfo = await oidcClient.userinfo(tokens.access_token);
525537

526-
console.log(userInfo);
527-
528538
let user = await prisma.user.findUnique({
529539
where: { email: userInfo.email },
530540
});
531541

532-
console.log(user);
542+
await tracking("user_logged_in_oidc", {});
533543

534544
if (!user) {
535545
// Create a new basic user
@@ -665,6 +675,8 @@ export function authRoutes(fastify: FastifyInstance) {
665675
},
666676
});
667677

678+
await tracking("user_logged_in_oauth", {});
679+
668680
// Send Response
669681
reply.send({
670682
token: signed_token,
@@ -757,6 +769,8 @@ export function authRoutes(fastify: FastifyInstance) {
757769
external_user: user!.external_user,
758770
};
759771

772+
await tracking("user_profile", {});
773+
760774
reply.send({
761775
user: data,
762776
});
@@ -1008,6 +1022,8 @@ export function authRoutes(fastify: FastifyInstance) {
10081022
},
10091023
});
10101024

1025+
await tracking("user_first_login", {});
1026+
10111027
reply.send({ success: true });
10121028
}
10131029
}

apps/api/src/controllers/config.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@ const nodemailer = require("nodemailer");
1010

1111
import { checkToken } from "../lib/jwt";
1212
import { prisma } from "../prisma";
13-
import { emit } from "process";
1413
import { createTransportProvider } from "../lib/nodemailer/transport";
14+
import { track } from "../lib/hog";
15+
16+
async function tracking(event: string, properties: any) {
17+
const client = track();
18+
19+
client.capture({
20+
event: event,
21+
properties: properties,
22+
distinctId: "uuid",
23+
});
24+
}
1525

1626
export function configRoutes(fastify: FastifyInstance) {
1727
// Check auth method
@@ -87,6 +97,8 @@ export function configRoutes(fastify: FastifyInstance) {
8797
});
8898
}
8999

100+
await tracking("oidc_provider_updated", {});
101+
90102
reply.send({
91103
success: true,
92104
message: "OIDC config Provider updated!",
@@ -152,6 +164,8 @@ export function configRoutes(fastify: FastifyInstance) {
152164
});
153165
}
154166

167+
await tracking("oauth_provider_updated", {});
168+
155169
reply.send({
156170
success: true,
157171
message: "SSO Provider updated!",
@@ -183,6 +197,8 @@ export function configRoutes(fastify: FastifyInstance) {
183197
// Delete the OAuth provider
184198
await prisma.oAuthProvider.deleteMany({});
185199

200+
await tracking("sso_provider_deleted", {});
201+
186202
reply.send({
187203
success: true,
188204
message: "SSO Provider deleted!",
@@ -211,14 +227,7 @@ export function configRoutes(fastify: FastifyInstance) {
211227
},
212228
});
213229

214-
if (config === null) {
215-
reply.send({
216-
success: true,
217-
active: false,
218-
});
219-
}
220-
221-
if (config?.active) {
230+
if (config && config?.active) {
222231
const provider = await createTransportProvider();
223232

224233
await new Promise((resolve, reject) => {
@@ -247,7 +256,6 @@ export function configRoutes(fastify: FastifyInstance) {
247256
reply.send({
248257
success: true,
249258
active: false,
250-
email: config,
251259
});
252260
}
253261
}

apps/api/src/controllers/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function dataRoutes(fastify: FastifyInstance) {
6767

6868
if (token) {
6969
const result = await prisma.ticket.count({
70-
where: { userId: null, hidden: false },
70+
where: { userId: null, hidden: false, isComplete: false },
7171
});
7272

7373
reply.send({ count: result });

apps/api/src/controllers/notebook.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
22
import { checkToken } from "../lib/jwt";
33
import { checkSession } from "../lib/session";
44
import { prisma } from "../prisma";
5+
import { track } from "../lib/hog";
6+
7+
async function tracking(event: string, properties: any) {
8+
const client = track();
9+
10+
client.capture({
11+
event: event,
12+
properties: properties,
13+
distinctId: "uuid",
14+
});
15+
16+
client.shutdownAsync();
17+
}
518

619
export function notebookRoutes(fastify: FastifyInstance) {
720
// Create a new entry
@@ -25,6 +38,8 @@ export function notebookRoutes(fastify: FastifyInstance) {
2538
},
2639
});
2740

41+
await tracking("note_created", {});
42+
2843
const { id } = data;
2944

3045
reply.status(200).send({ success: true, id });

apps/api/src/controllers/queue.ts

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
33
import { checkToken } from "../lib/jwt";
44
import { prisma } from "../prisma";
55
import { 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

720
export 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
);

apps/api/src/controllers/ticket.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,20 +443,29 @@ export function ticketRoutes(fastify: FastifyInstance) {
443443
const { user, id }: any = request.body;
444444

445445
if (token) {
446-
const assigned = await prisma.user.update({
447-
where: { id: user },
448-
data: {
449-
tickets: {
450-
connect: {
451-
id: id,
446+
if (user) {
447+
const assigned = await prisma.user.update({
448+
where: { id: user },
449+
data: {
450+
tickets: {
451+
connect: {
452+
id: id,
453+
},
452454
},
453455
},
454-
},
455-
});
456+
});
456457

457-
const { email } = assigned;
458+
const { email } = assigned;
458459

459-
await sendAssignedEmail(email);
460+
await sendAssignedEmail(email);
461+
} else {
462+
await prisma.ticket.update({
463+
where: { id: id },
464+
data: {
465+
userId: null,
466+
},
467+
});
468+
}
460469

461470
reply.send({
462471
success: true,

0 commit comments

Comments
 (0)