From e14b417b3de1475bbae725acae9b2b60952fc583 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Fri, 3 May 2024 12:45:40 +0300 Subject: [PATCH 01/11] Update email template --- apps/vpnmanager/src/lib/email/sender.ts | 5 +-- apps/vpnmanager/src/lib/email/templates.ts | 36 ++++++++++++++-------- apps/vpnmanager/src/lib/processUsers.ts | 1 + apps/vpnmanager/src/types.d.ts | 2 +- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/apps/vpnmanager/src/lib/email/sender.ts b/apps/vpnmanager/src/lib/email/sender.ts index 63f8aae28..416e8d195 100644 --- a/apps/vpnmanager/src/lib/email/sender.ts +++ b/apps/vpnmanager/src/lib/email/sender.ts @@ -6,9 +6,10 @@ import { emailKeyTemplate } from "./templates"; interface MailSender { recipient: string; key: string; + name: string; } -export async function sendVpnKeyEmail({ recipient: to, key }: MailSender) { +export async function sendVpnKeyEmail({ recipient: to, key, name }: MailSender) { try { const sendGridApiKey = process.env.VPN_MANAGER_SENDGRID_API_KEY as string; if (!sendGridApiKey) { @@ -25,7 +26,7 @@ export async function sendVpnKeyEmail({ recipient: to, key }: MailSender) { to, from, subject, - html: emailKeyTemplate(key), + html: emailKeyTemplate(key, name), }; await sgMail.send(message); } catch (error) { diff --git a/apps/vpnmanager/src/lib/email/templates.ts b/apps/vpnmanager/src/lib/email/templates.ts index 6cd42d702..4317f9a75 100644 --- a/apps/vpnmanager/src/lib/email/templates.ts +++ b/apps/vpnmanager/src/lib/email/templates.ts @@ -1,14 +1,24 @@ -export function emailKeyTemplate(key: string) { - return `
-

- Follow the instructions on your Invitation Link to download the Outline app and get connected. -

-

Having trouble accessing the invitation link?

-
    -
  1. Copy your access key: ${key}
  2. -
  3. Follow our invitation instructions on GitHub: https://github.com/Jigsaw-Code/outline-client/blob/master/docs/invitation_instructions.md
  4. -
-
`; +export function emailKeyTemplate(key: string, name: string) { + return ` +
+ +

Hi ${name},

+

Thanks for indicating interest in using Outline VPN.

+

Use the following instructions to set it up on your devices:

+ +
    +
  1. Download and install the Outline app for your device:
  2. + +
  3. Copy your Access key ${key}
  4. +
  5. Open the Outline client app. If your access key is auto-detected, tap 'Connect'. If your access key is not auto-detected, paste it in the field, then tap 'Connect'. You are good to go!
  6. +
+ +
` } diff --git a/apps/vpnmanager/src/lib/processUsers.ts b/apps/vpnmanager/src/lib/processUsers.ts index 269570426..d35d0b49a 100644 --- a/apps/vpnmanager/src/lib/processUsers.ts +++ b/apps/vpnmanager/src/lib/processUsers.ts @@ -32,6 +32,7 @@ export async function processUser(item: SheetRow) { await sendVpnKeyEmail({ recipient: user?.name ?? "", key: user?.accessUrl ?? "", + name: item?.member ?? user?.name }); return { ...item, diff --git a/apps/vpnmanager/src/types.d.ts b/apps/vpnmanager/src/types.d.ts index 15ec3fb97..98c2736c8 100644 --- a/apps/vpnmanager/src/types.d.ts +++ b/apps/vpnmanager/src/types.d.ts @@ -33,7 +33,7 @@ export interface OutlineServerMetrics { export interface SheetRow { emailAddressCreated: string; emailAddress: string; - name: string; + member: string; outlineKeyCreated: string; startDate: string; endDate: string; From 7e0c3ef0ab5797de1c72c799915d1ab2f72ad666 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Fri, 3 May 2024 13:45:44 +0300 Subject: [PATCH 02/11] Load Sentry --- apps/vpnmanager/package.json | 2 +- apps/vpnmanager/scripts/processGsheet.ts | 2 ++ apps/vpnmanager/sentry.client.config.ts | 2 +- apps/vpnmanager/sentry.edge.config.ts | 2 +- apps/vpnmanager/sentry.server.config.ts | 15 +++++++++------ apps/vpnmanager/src/lib/email/sender.ts | 6 +++++- apps/vpnmanager/src/lib/email/templates.ts | 2 +- apps/vpnmanager/src/lib/processUsers.ts | 2 +- pnpm-lock.yaml | 2 +- 9 files changed, 22 insertions(+), 13 deletions(-) diff --git a/apps/vpnmanager/package.json b/apps/vpnmanager/package.json index dbc49f65a..4b45a1e2b 100644 --- a/apps/vpnmanager/package.json +++ b/apps/vpnmanager/package.json @@ -22,7 +22,7 @@ "@mui/utils": "^5.14.20", "@next/env": "^14.1.4", "@sendgrid/mail": "^8.1.1", - "@sentry/nextjs": "^7.105.0", + "@sentry/nextjs": "^7.106.1", "@svgr/webpack": "^8.1.0", "@types/jest": "^29.5.12", "googleapis": "^133.0.0", diff --git a/apps/vpnmanager/scripts/processGsheet.ts b/apps/vpnmanager/scripts/processGsheet.ts index 2a137d0df..2fb3639b8 100644 --- a/apps/vpnmanager/scripts/processGsheet.ts +++ b/apps/vpnmanager/scripts/processGsheet.ts @@ -1,6 +1,8 @@ import { processNewUsers } from "@/vpnmanager/lib/processUsers"; import { loadEnvConfig } from "@next/env"; +import { initSentry } from "../sentry.server.config"; +initSentry(); const projectDir = process.cwd(); loadEnvConfig(projectDir); diff --git a/apps/vpnmanager/sentry.client.config.ts b/apps/vpnmanager/sentry.client.config.ts index d4ca649c7..63d96bd47 100644 --- a/apps/vpnmanager/sentry.client.config.ts +++ b/apps/vpnmanager/sentry.client.config.ts @@ -3,7 +3,7 @@ import * as Sentry from "@sentry/nextjs"; Sentry.init({ dsn: process.env.SENTRY_DSN, tracesSampleRate: 1, - environment: process.env.SENTRY_ENV, + environment: process.env.SENTRY_ENV ?? "local", debug: false, replaysOnErrorSampleRate: 1.0, replaysSessionSampleRate: 0.1, diff --git a/apps/vpnmanager/sentry.edge.config.ts b/apps/vpnmanager/sentry.edge.config.ts index 458a9f886..5a5ad8d6d 100644 --- a/apps/vpnmanager/sentry.edge.config.ts +++ b/apps/vpnmanager/sentry.edge.config.ts @@ -2,7 +2,7 @@ import * as Sentry from "@sentry/nextjs"; Sentry.init({ dsn: process.env.SENTRY_DSN, - environment: process.env.SENTRY_ENV, + environment: process.env.SENTRY_ENV ?? "local", tracesSampleRate: 1, debug: false, }); diff --git a/apps/vpnmanager/sentry.server.config.ts b/apps/vpnmanager/sentry.server.config.ts index 458a9f886..2d5dbac05 100644 --- a/apps/vpnmanager/sentry.server.config.ts +++ b/apps/vpnmanager/sentry.server.config.ts @@ -1,8 +1,11 @@ import * as Sentry from "@sentry/nextjs"; -Sentry.init({ - dsn: process.env.SENTRY_DSN, - environment: process.env.SENTRY_ENV, - tracesSampleRate: 1, - debug: false, -}); +export function initSentry() { + Sentry.init({ + dsn: process.env.SENTRY_DSN, + environment: process.env.SENTRY_ENV ?? "local", + tracesSampleRate: 1, + }); +} + +initSentry(); diff --git a/apps/vpnmanager/src/lib/email/sender.ts b/apps/vpnmanager/src/lib/email/sender.ts index 416e8d195..b5a41dcfd 100644 --- a/apps/vpnmanager/src/lib/email/sender.ts +++ b/apps/vpnmanager/src/lib/email/sender.ts @@ -9,7 +9,11 @@ interface MailSender { name: string; } -export async function sendVpnKeyEmail({ recipient: to, key, name }: MailSender) { +export async function sendVpnKeyEmail({ + recipient: to, + key, + name, +}: MailSender) { try { const sendGridApiKey = process.env.VPN_MANAGER_SENDGRID_API_KEY as string; if (!sendGridApiKey) { diff --git a/apps/vpnmanager/src/lib/email/templates.ts b/apps/vpnmanager/src/lib/email/templates.ts index 4317f9a75..fded006b1 100644 --- a/apps/vpnmanager/src/lib/email/templates.ts +++ b/apps/vpnmanager/src/lib/email/templates.ts @@ -20,5 +20,5 @@ export function emailKeyTemplate(key: string, name: string) {
  • Open the Outline client app. If your access key is auto-detected, tap 'Connect'. If your access key is not auto-detected, paste it in the field, then tap 'Connect'. You are good to go!
  • - ` + `; } diff --git a/apps/vpnmanager/src/lib/processUsers.ts b/apps/vpnmanager/src/lib/processUsers.ts index d35d0b49a..5424f7385 100644 --- a/apps/vpnmanager/src/lib/processUsers.ts +++ b/apps/vpnmanager/src/lib/processUsers.ts @@ -32,7 +32,7 @@ export async function processUser(item: SheetRow) { await sendVpnKeyEmail({ recipient: user?.name ?? "", key: user?.accessUrl ?? "", - name: item?.member ?? user?.name + name: item?.member ?? user?.name, }); return { ...item, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9d00cce1f..8c8ea16f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -978,7 +978,7 @@ importers: specifier: ^8.1.1 version: 8.1.1 "@sentry/nextjs": - specifier: ^7.105.0 + specifier: ^7.106.1 version: 7.106.1(next@14.1.3)(react@18.2.0)(webpack@5.89.0) "@svgr/webpack": specifier: ^8.1.0 From 060a45d185f2b6f4cf617c0a48cddcebc4b2a88f Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 6 May 2024 11:06:40 +0300 Subject: [PATCH 03/11] Email key template --- apps/vpnmanager/src/lib/email/sender.ts | 1 + apps/vpnmanager/src/lib/email/templates.ts | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vpnmanager/src/lib/email/sender.ts b/apps/vpnmanager/src/lib/email/sender.ts index b5a41dcfd..1f1317aa3 100644 --- a/apps/vpnmanager/src/lib/email/sender.ts +++ b/apps/vpnmanager/src/lib/email/sender.ts @@ -33,6 +33,7 @@ export async function sendVpnKeyEmail({ html: emailKeyTemplate(key, name), }; await sgMail.send(message); + Sentry.captureMessage(`Email sent to "${to}" ${emailKeyTemplate(key, name)}`, 'info'); } catch (error) { Sentry.captureException(error); } diff --git a/apps/vpnmanager/src/lib/email/templates.ts b/apps/vpnmanager/src/lib/email/templates.ts index fded006b1..880928cfb 100644 --- a/apps/vpnmanager/src/lib/email/templates.ts +++ b/apps/vpnmanager/src/lib/email/templates.ts @@ -3,7 +3,6 @@ export function emailKeyTemplate(key: string, name: string) {

    Hi ${name},

    -

    Thanks for indicating interest in using Outline VPN.

    Use the following instructions to set it up on your devices:

      From 0f2e016e0184072e59dfa4f9f67f53ea7a19ff3c Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 6 May 2024 11:08:16 +0300 Subject: [PATCH 04/11] Hide email key --- apps/vpnmanager/src/lib/email/sender.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vpnmanager/src/lib/email/sender.ts b/apps/vpnmanager/src/lib/email/sender.ts index 1f1317aa3..f94693bda 100644 --- a/apps/vpnmanager/src/lib/email/sender.ts +++ b/apps/vpnmanager/src/lib/email/sender.ts @@ -33,7 +33,7 @@ export async function sendVpnKeyEmail({ html: emailKeyTemplate(key, name), }; await sgMail.send(message); - Sentry.captureMessage(`Email sent to "${to}" ${emailKeyTemplate(key, name)}`, 'info'); + Sentry.captureMessage(`Email sent to "${to}" ${emailKeyTemplate("*hidden*", name)}`, 'info'); } catch (error) { Sentry.captureException(error); } From be8085009ec93e1b3c6aaf1a50813e57aecbcde9 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 6 May 2024 11:13:00 +0300 Subject: [PATCH 05/11] Fix lint issues --- apps/vpnmanager/src/lib/email/sender.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/vpnmanager/src/lib/email/sender.ts b/apps/vpnmanager/src/lib/email/sender.ts index f94693bda..af75c2b11 100644 --- a/apps/vpnmanager/src/lib/email/sender.ts +++ b/apps/vpnmanager/src/lib/email/sender.ts @@ -33,7 +33,10 @@ export async function sendVpnKeyEmail({ html: emailKeyTemplate(key, name), }; await sgMail.send(message); - Sentry.captureMessage(`Email sent to "${to}" ${emailKeyTemplate("*hidden*", name)}`, 'info'); + Sentry.captureMessage( + `Email sent to "${to}" ${emailKeyTemplate("*hidden*", name)}`, + "info", + ); } catch (error) { Sentry.captureException(error); } From e39232cc04fc70a6d3c400d992c628eb6cfc67f0 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 6 May 2024 11:32:32 +0300 Subject: [PATCH 06/11] Update email template --- apps/vpnmanager/src/lib/email/templates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vpnmanager/src/lib/email/templates.ts b/apps/vpnmanager/src/lib/email/templates.ts index 880928cfb..a657e4139 100644 --- a/apps/vpnmanager/src/lib/email/templates.ts +++ b/apps/vpnmanager/src/lib/email/templates.ts @@ -3,7 +3,7 @@ export function emailKeyTemplate(key: string, name: string) {

      Hi ${name},

      -

      Use the following instructions to set it up on your devices:

      +

      Use the following instructions to set up Outline VPN on your devices:

      1. Download and install the Outline app for your device:
      2. From f64763bb9ba33c506861a8b365845ff1af3331c0 Mon Sep 17 00:00:00 2001 From: Vincent Otieno Date: Mon, 6 May 2024 12:31:15 +0300 Subject: [PATCH 07/11] Apply suggestions from code review Co-authored-by: Clemence Kyara --- apps/vpnmanager/sentry.server.config.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/apps/vpnmanager/sentry.server.config.ts b/apps/vpnmanager/sentry.server.config.ts index 2d5dbac05..c5e7f64d1 100644 --- a/apps/vpnmanager/sentry.server.config.ts +++ b/apps/vpnmanager/sentry.server.config.ts @@ -1,11 +1,5 @@ import * as Sentry from "@sentry/nextjs"; export function initSentry() { - Sentry.init({ - dsn: process.env.SENTRY_DSN, - environment: process.env.SENTRY_ENV ?? "local", - tracesSampleRate: 1, - }); + Sentry.init(); } - -initSentry(); From 0c6c0949166a5b09d54e536a6634cc64b3b31d05 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 6 May 2024 12:34:26 +0300 Subject: [PATCH 08/11] Update template --- apps/vpnmanager/sentry.server.config.ts | 10 +++++++++- apps/vpnmanager/src/lib/email/sender.ts | 21 +++++++++++---------- apps/vpnmanager/src/lib/email/templates.ts | 2 +- apps/vpnmanager/src/lib/processUsers.ts | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/apps/vpnmanager/sentry.server.config.ts b/apps/vpnmanager/sentry.server.config.ts index c5e7f64d1..477064d0b 100644 --- a/apps/vpnmanager/sentry.server.config.ts +++ b/apps/vpnmanager/sentry.server.config.ts @@ -1,5 +1,13 @@ import * as Sentry from "@sentry/nextjs"; +const options = { + dsn: process.env.SENTRY_DSN, + environment: process.env.SENTRY_ENV ?? "local", + tracesSampleRate: 1, +} + +Sentry.init(options); + export function initSentry() { - Sentry.init(); + Sentry.init(options); } diff --git a/apps/vpnmanager/src/lib/email/sender.ts b/apps/vpnmanager/src/lib/email/sender.ts index af75c2b11..25372a9af 100644 --- a/apps/vpnmanager/src/lib/email/sender.ts +++ b/apps/vpnmanager/src/lib/email/sender.ts @@ -4,16 +4,12 @@ import * as Sentry from "@sentry/nextjs"; import { emailKeyTemplate } from "./templates"; interface MailSender { - recipient: string; + to: string; key: string; name: string; } -export async function sendVpnKeyEmail({ - recipient: to, - key, - name, -}: MailSender) { +export async function sendVpnKeyEmail({ to, key, name }: MailSender) { try { const sendGridApiKey = process.env.VPN_MANAGER_SENDGRID_API_KEY as string; if (!sendGridApiKey) { @@ -33,10 +29,15 @@ export async function sendVpnKeyEmail({ html: emailKeyTemplate(key, name), }; await sgMail.send(message); - Sentry.captureMessage( - `Email sent to "${to}" ${emailKeyTemplate("*hidden*", name)}`, - "info", - ); + Sentry.withScope((scope) => { + scope.setLevel("info"); + scope.setUser({ + id: to, + email: to, + }); + scope.addAttachment({ filename: "email.html", data: emailKeyTemplate("*hidden*", name)}) + Sentry.captureMessage("Outline key sent"); + }); } catch (error) { Sentry.captureException(error); } diff --git a/apps/vpnmanager/src/lib/email/templates.ts b/apps/vpnmanager/src/lib/email/templates.ts index a657e4139..90e11261a 100644 --- a/apps/vpnmanager/src/lib/email/templates.ts +++ b/apps/vpnmanager/src/lib/email/templates.ts @@ -18,6 +18,6 @@ export function emailKeyTemplate(key: string, name: string) {
      3. Copy your Access key ${key}
      4. Open the Outline client app. If your access key is auto-detected, tap 'Connect'. If your access key is not auto-detected, paste it in the field, then tap 'Connect'. You are good to go!
      - +

      NOTE: The same key can be used for multiple devices.

      `; } diff --git a/apps/vpnmanager/src/lib/processUsers.ts b/apps/vpnmanager/src/lib/processUsers.ts index 5424f7385..680b92123 100644 --- a/apps/vpnmanager/src/lib/processUsers.ts +++ b/apps/vpnmanager/src/lib/processUsers.ts @@ -30,7 +30,7 @@ export async function processUser(item: SheetRow) { } } await sendVpnKeyEmail({ - recipient: user?.name ?? "", + to: user?.name ?? "", key: user?.accessUrl ?? "", name: item?.member ?? user?.name, }); From 7b0a0efcbf5d796c2e3e34eea8018675b0e60e6b Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 6 May 2024 12:35:21 +0300 Subject: [PATCH 09/11] Fix lint issues --- apps/vpnmanager/src/lib/email/sender.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/vpnmanager/src/lib/email/sender.ts b/apps/vpnmanager/src/lib/email/sender.ts index 25372a9af..bb7069dd4 100644 --- a/apps/vpnmanager/src/lib/email/sender.ts +++ b/apps/vpnmanager/src/lib/email/sender.ts @@ -35,7 +35,10 @@ export async function sendVpnKeyEmail({ to, key, name }: MailSender) { id: to, email: to, }); - scope.addAttachment({ filename: "email.html", data: emailKeyTemplate("*hidden*", name)}) + scope.addAttachment({ + filename: "email.html", + data: emailKeyTemplate("*hidden*", name), + }); Sentry.captureMessage("Outline key sent"); }); } catch (error) { From 2c32caf102cea305252e192d92aec14e9cc203c6 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 6 May 2024 12:39:23 +0300 Subject: [PATCH 10/11] FIx failing build --- apps/vpnmanager/sentry.server.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/vpnmanager/sentry.server.config.ts b/apps/vpnmanager/sentry.server.config.ts index 477064d0b..869ae5737 100644 --- a/apps/vpnmanager/sentry.server.config.ts +++ b/apps/vpnmanager/sentry.server.config.ts @@ -1,10 +1,10 @@ import * as Sentry from "@sentry/nextjs"; -const options = { +const options = { dsn: process.env.SENTRY_DSN, environment: process.env.SENTRY_ENV ?? "local", tracesSampleRate: 1, -} +}; Sentry.init(options); From 992213ca9509807dbed9ba64d0d1ec20b2b2f586 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 6 May 2024 14:09:54 +0300 Subject: [PATCH 11/11] Remove id in sentry --- apps/vpnmanager/src/lib/email/sender.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/vpnmanager/src/lib/email/sender.ts b/apps/vpnmanager/src/lib/email/sender.ts index bb7069dd4..8bbcc4bf7 100644 --- a/apps/vpnmanager/src/lib/email/sender.ts +++ b/apps/vpnmanager/src/lib/email/sender.ts @@ -32,7 +32,6 @@ export async function sendVpnKeyEmail({ to, key, name }: MailSender) { Sentry.withScope((scope) => { scope.setLevel("info"); scope.setUser({ - id: to, email: to, }); scope.addAttachment({