Skip to content

Commit

Permalink
chore: add extra events (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 authored Nov 8, 2024
1 parent d7bcf6b commit 51b446b
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 128 deletions.
24 changes: 20 additions & 4 deletions apps/api/src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ function generateRandomPassword(length: number): string {
return password;
}

async function tracking(event: string, properties: any) {
const client = track();

client.capture({
event: event,
properties: properties,
distinctId: "uuid",
});
}

export function authRoutes(fastify: FastifyInstance) {
// Register a new user
fastify.post(
Expand Down Expand Up @@ -175,7 +185,7 @@ export function authRoutes(fastify: FastifyInstance) {
const hog = track();

hog.capture({
event: "user_registered",
event: "user_registered_external",
distinctId: user.id,
});

Expand Down Expand Up @@ -339,6 +349,8 @@ export function authRoutes(fastify: FastifyInstance) {
},
});

await tracking("user_logged_in_password", {});

const data = {
id: user!.id,
email: user!.email,
Expand Down Expand Up @@ -523,13 +535,11 @@ export function authRoutes(fastify: FastifyInstance) {
// Retrieve user information
const userInfo = await oidcClient.userinfo(tokens.access_token);

console.log(userInfo);

let user = await prisma.user.findUnique({
where: { email: userInfo.email },
});

console.log(user);
await tracking("user_logged_in_oidc", {});

if (!user) {
// Create a new basic user
Expand Down Expand Up @@ -665,6 +675,8 @@ export function authRoutes(fastify: FastifyInstance) {
},
});

await tracking("user_logged_in_oauth", {});

// Send Response
reply.send({
token: signed_token,
Expand Down Expand Up @@ -757,6 +769,8 @@ export function authRoutes(fastify: FastifyInstance) {
external_user: user!.external_user,
};

await tracking("user_profile", {});

reply.send({
user: data,
});
Expand Down Expand Up @@ -1008,6 +1022,8 @@ export function authRoutes(fastify: FastifyInstance) {
},
});

await tracking("user_first_login", {});

reply.send({ success: true });
}
}
Expand Down
18 changes: 17 additions & 1 deletion apps/api/src/controllers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ const nodemailer = require("nodemailer");

import { checkToken } from "../lib/jwt";
import { prisma } from "../prisma";
import { emit } from "process";
import { createTransportProvider } from "../lib/nodemailer/transport";
import { track } from "../lib/hog";

async function tracking(event: string, properties: any) {
const client = track();

client.capture({
event: event,
properties: properties,
distinctId: "uuid",
});
}

export function configRoutes(fastify: FastifyInstance) {
// Check auth method
Expand Down Expand Up @@ -87,6 +97,8 @@ export function configRoutes(fastify: FastifyInstance) {
});
}

await tracking("oidc_provider_updated", {});

reply.send({
success: true,
message: "OIDC config Provider updated!",
Expand Down Expand Up @@ -152,6 +164,8 @@ export function configRoutes(fastify: FastifyInstance) {
});
}

await tracking("oauth_provider_updated", {});

reply.send({
success: true,
message: "SSO Provider updated!",
Expand Down Expand Up @@ -183,6 +197,8 @@ export function configRoutes(fastify: FastifyInstance) {
// Delete the OAuth provider
await prisma.oAuthProvider.deleteMany({});

await tracking("sso_provider_deleted", {});

reply.send({
success: true,
message: "SSO Provider deleted!",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/controllers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function dataRoutes(fastify: FastifyInstance) {

if (token) {
const result = await prisma.ticket.count({
where: { userId: null, hidden: false },
where: { userId: null, hidden: false, isComplete: false },
});

reply.send({ count: result });
Expand Down
15 changes: 15 additions & 0 deletions apps/api/src/controllers/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { checkToken } from "../lib/jwt";
import { checkSession } from "../lib/session";
import { prisma } from "../prisma";
import { track } from "../lib/hog";

async function tracking(event: string, properties: any) {
const client = track();

client.capture({
event: event,
properties: properties,
distinctId: "uuid",
});

client.shutdownAsync();
}

export function notebookRoutes(fastify: FastifyInstance) {
// Create a new entry
Expand All @@ -25,6 +38,8 @@ export function notebookRoutes(fastify: FastifyInstance) {
},
});

await tracking("note_created", {});

const { id } = data;

reply.status(200).send({ success: true, id });
Expand Down
72 changes: 53 additions & 19 deletions apps/api/src/controllers/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { checkToken } from "../lib/jwt";
import { prisma } from "../prisma";
import { OAuth2Client } from "google-auth-library";
import { track } from "../lib/hog";

async function tracking(event: string, properties: any) {
const client = track();

client.capture({
event: event,
properties: properties,
distinctId: "uuid",
});

client.shutdownAsync();
}

export function emailQueueRoutes(fastify: FastifyInstance) {
// Create a new email queue
Expand Down Expand Up @@ -41,26 +54,47 @@ export function emailQueueRoutes(fastify: FastifyInstance) {
});

// generate redirect uri
if (serviceType === "gmail") {
const google = new OAuth2Client(clientId, clientSecret, redirectUri);

const authorizeUrl = google.generateAuthUrl({
access_type: "offline",
scope: "https://mail.google.com",
prompt: "consent",
state: mailbox.id,
});

reply.send({
success: true,
message: "Gmail imap provider created!",
authorizeUrl: authorizeUrl,
});
switch (serviceType) {
case "gmail":
const google = new OAuth2Client(
clientId,
clientSecret,
redirectUri
);

const authorizeUrl = google.generateAuthUrl({
access_type: "offline",
scope: "https://mail.google.com",
prompt: "consent",
state: mailbox.id,
});

tracking("gmail_provider_created", {
provider: "gmail",
});

reply.send({
success: true,
message: "Gmail imap provider created!",
authorizeUrl: authorizeUrl,
});
break;
case "other":
tracking("imap_provider_created", {
provider: "other",
});

reply.send({
success: true,
message: "Other service type created!",
});
break;
default:
reply.send({
success: false,
message: "Unsupported service type",
});
}

reply.send({
success: true,
});
}
}
);
Expand Down
103 changes: 0 additions & 103 deletions apps/api/src/controllers/todos.ts

This file was deleted.

11 changes: 11 additions & 0 deletions apps/api/src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";

import { checkToken } from "../lib/jwt";
import { prisma } from "../prisma";
import { track } from "../lib/hog";

export function userRoutes(fastify: FastifyInstance) {
// All users
Expand Down Expand Up @@ -69,6 +70,16 @@ export function userRoutes(fastify: FastifyInstance) {
},
});


const client = track();

client.capture({
event: "user_created",
distinctId: "uuid",
});

client.shutdownAsync();

reply.send({
success: true,
});
Expand Down
Loading

0 comments on commit 51b446b

Please sign in to comment.