diff --git a/auth.config.mjs b/auth.config.mjs index 024d8ca..df2f44b 100644 --- a/auth.config.mjs +++ b/auth.config.mjs @@ -2,6 +2,13 @@ import Slack from "@auth/core/providers/slack"; import { defineConfig } from "auth-astro"; import { db, like, and, User, Organization } from "astro:db"; +import { LogSnag } from "logsnag"; + +const logsnag = new LogSnag({ + token: "f269dd8e8ec57f9a73737e76c5e0024a", + project: "magicsnap", +}); + export default defineConfig({ providers: [ Slack({ @@ -49,6 +56,41 @@ export default defineConfig({ role: "admin", }); + await logsnag.track({ + channel: "signups", + event: "signup", + user_id: profile["https://slack.com/user_id"], + description: "User signed up as an admin", + icon: "🚀", + tags: { + team: profile["https://slack.com/team_id"], + role: "admin", + }, + }); + + await logsnag.track({ + channel: "actions", + event: "joined_team", + user_id: profile["https://slack.com/user_id"], + description: "User joined a team", + icon: "🤝", + tags: { + team: profile["https://slack.com/team_id"], + role: "admin", + }, + }); + + await logsnag.identify({ + user_id: profile["https://slack.com/user_id"], + properties: { + email: profile.email, + name: profile.name, + image: profile.picture, + team: profile["https://slack.com/team_id"], + role: "admin", + }, + }); + role[0] = { role: "admin" }; } else { await db.insert(User).values({ @@ -60,10 +102,68 @@ export default defineConfig({ role: "user", }); + await logsnag.track({ + channel: "signups", + event: "signup", + user_id: profile["https://slack.com/user_id"], + description: "User signed up as a user", + icon: "🚀", + tags: { + team: profile["https://slack.com/team_id"], + role: "user", + }, + }); + + await logsnag.track({ + channel: "actions", + event: "joined_team", + user_id: profile["https://slack.com/user_id"], + description: "User joined a team", + icon: "🤝", + tags: { + team: profile["https://slack.com/team_id"], + role: "user", + }, + }); + + await logsnag.identify({ + user_id: profile["https://slack.com/user_id"], + properties: { + email: profile.email, + name: profile.name, + image: profile.picture, + team: profile["https://slack.com/team_id"], + role: "user", + }, + }); + role[0] = { role: "user" }; } } else { role[0] = { role: "guest" }; + + await logsnag.track({ + channel: "signups", + event: "signup", + user_id: profile["https://slack.com/user_id"], + description: "User signed up as a guest", + icon: "🚀", + tags: { + team: profile["https://slack.com/team_id"], + role: "guest", + }, + }); + + await logsnag.identify({ + user_id: profile["https://slack.com/user_id"], + properties: { + email: profile.email, + name: profile.name, + image: profile.picture, + team: profile["https://slack.com/team_id"], + role: "guest", + }, + }); } } diff --git a/bun.lockb b/bun.lockb index 048c98c..1439a7d 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index b96307e..c6a2096 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "astro": "^4.5.10", "auth-astro": "^4.1.1", "jwt-decode": "^4.0.0", + "logsnag": "^1.0.0", "magick.css": "^1.0.5", "normalize.css": "^8.0.1", "prettier": "^3.2.5", diff --git a/src/pages/api/remind.ts b/src/pages/api/remind.ts index d90005d..804eff0 100644 --- a/src/pages/api/remind.ts +++ b/src/pages/api/remind.ts @@ -1,5 +1,11 @@ import type { APIRoute } from "astro" import { db, User, Organization, Event } from "astro:db"; +import { LogSnag } from "logsnag"; + +const logsnag = new LogSnag({ + token: "f269dd8e8ec57f9a73737e76c5e0024a", + project: "magicsnap", +}); export const POST: APIRoute = async ({ request }) => { // get authorization header @@ -20,6 +26,13 @@ export const POST: APIRoute = async ({ request }) => { return diffHours < 24 && diffHours > 0 }) + await logsnag.track({ + channel: "api", + event: "reminder-sent", + description: `Sent reminder to ${users.length} users in ${organizations.length} different organizations about ${eventsHappeningToday.length} events happening today`, + icon: "📬", + }); + return new Response(JSON.stringify({ ok: true, eventsHappeningToday: eventsHappeningToday, users: users, organizations: organizations }), { status: 200 }) diff --git a/src/pages/dashboard.astro b/src/pages/dashboard.astro index 6fd4572..ec4fdd9 100644 --- a/src/pages/dashboard.astro +++ b/src/pages/dashboard.astro @@ -44,6 +44,13 @@ if (!session) { }); } +import { LogSnag } from "logsnag"; + +const logsnag = new LogSnag({ + token: "f269dd8e8ec57f9a73737e76c5e0024a", + project: "magicsnap", +}); + import { db, Event, User } from "astro:db"; import { like } from "astro:db"; @@ -102,6 +109,13 @@ if (Astro.request.method === "POST") { statusNotGoing: statusNotGoing.join(","), }) .where(like(Event.id, eventID)); + + await logsnag.track({ + channel: "actions", + event: "event_status_change", + icon: "📅", + user_id: session.user.id, + }); } } else if (data.get("delete") != null) { if (session.user.role != "admin") { @@ -110,6 +124,13 @@ if (Astro.request.method === "POST") { const eventID = data.get("eventID") as string; await db.delete(Event).where(like(Event.id, eventID)); + + await logsnag.track({ + channel: "actions", + event: "event_delete", + icon: "📅", + user_id: session.user.id, + }); } else if (data.get("newEvent") != null) { if (!data.has("name") || !data.has("date") || !data.has("time") || !data.has("location") || !data.has("comments")) { @@ -135,6 +156,13 @@ if (Astro.request.method === "POST") { .join(","), }; await db.insert(Event).values(event); + + await logsnag.track({ + channel: "actions", + event: "event_create", + icon: "📅", + user_id: session.user.id, + }); } } catch (error) { if (error instanceof Error) { diff --git a/src/pages/join/[joinCode].astro b/src/pages/join/[joinCode].astro index 85c628c..39ca5b4 100644 --- a/src/pages/join/[joinCode].astro +++ b/src/pages/join/[joinCode].astro @@ -9,6 +9,13 @@ import { Invite } from "astro:db"; import { like } from "astro:db"; import { Organization } from "astro:db"; +import { LogSnag } from "logsnag"; + +const logsnag = new LogSnag({ + token: "f269dd8e8ec57f9a73737e76c5e0024a", + project: "magicsnap", +}); + type ExtendedSession = { team: string; teamName: string; @@ -75,6 +82,14 @@ if (session && session.user.role === "guest") { name: session.teamName, image: session.teamImage, }); + + await logsnag.track({ + channel: "join-code", + event: "create-team", + icon: "🪄", + user_id: session.user.id, + notify: true, + }); } --- diff --git a/src/pages/messages.astro b/src/pages/messages.astro index 2bc3f47..f961a6a 100644 --- a/src/pages/messages.astro +++ b/src/pages/messages.astro @@ -43,6 +43,13 @@ if (!session) { }); } +import { LogSnag } from "logsnag"; + +const logsnag = new LogSnag({ + token: "f269dd8e8ec57f9a73737e76c5e0024a", + project: "magicsnap", +}); + import { db, like, and, User, Organization } from "astro:db"; let users = await db.select().from(User).where(like(User.team, session.team)); @@ -146,6 +153,13 @@ if (Astro.request.method === "POST") { ok: true, message: `Message sent successfully to ${userList.length} users.`, }; + + await logsnag.track({ + channel: "actions", + event: "message_sent", + icon: "📧", + user_id: session.user.id, + }); } } } else {