Skip to content

Commit

Permalink
Merge branch 'main' into MNTOR-3726
Browse files Browse the repository at this point in the history
  • Loading branch information
mansaj authored Nov 1, 2024
2 parents db9b80e + 08ccb2f commit a163c17
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 411 deletions.
770 changes: 391 additions & 379 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
"npm": "10.1.0"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.675.0",
"@aws-sdk/lib-storage": "^3.675.0",
"@aws-sdk/client-s3": "^3.679.0",
"@aws-sdk/lib-storage": "^3.679.0",
"@fluent/bundle": "^0.18.0",
"@fluent/langneg": "^0.7.0",
"@fluent/react": "^0.15.2",
Expand Down
23 changes: 0 additions & 23 deletions src/app/api/v1/user/breaches/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,6 @@ export interface BreachResolutionRequest {
resolutionsChecked: Array<HibpBreachDataTypes[keyof HibpBreachDataTypes]>;
}

// Get breaches data
export async function GET(req: NextRequest) {
const token = await getToken({ req });
if (typeof token?.subscriber?.fxa_uid === "string") {
// Signed in
try {
const subscriber = await getSubscriberByFxaUid(token.subscriber?.fxa_uid);
const allBreaches = await getBreaches();
const breaches = await getAllEmailsAndBreaches(subscriber, allBreaches);
const successResponse = {
success: true,
breaches,
};
return NextResponse.json(successResponse);
} catch (e) {
logger.error(e);
return NextResponse.json({ success: false }, { status: 500 });
}
} else {
return NextResponse.json({ success: false }, { status: 401 });
}
}

export async function PUT(req: NextRequest) {
const token = await getToken({ req });
if (typeof token?.subscriber?.fxa_uid === "string") {
Expand Down
7 changes: 5 additions & 2 deletions src/db/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import knex from "knex";
import knexConfig from "./knexfile.js";

let connection: knex.Knex;
export default function createDbConnection(): knex.Knex {
/* c8 ignore start */
if (process.env.NODE_ENV === "development") {
Expand All @@ -15,9 +16,11 @@ export default function createDbConnection(): knex.Knex {
);
}

return (global as unknown as Record<string, knex.Knex>)[client];
connection ??= (global as unknown as Record<string, knex.Knex>)[client];
return connection;
}
/* c8 ignore stop */

return knex(knexConfig as knex.Knex.Config);
connection ??= knex(knexConfig as knex.Knex.Config);
return connection;
}
4 changes: 2 additions & 2 deletions src/db/tables/subscriber_email_preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ async function unsubscribeMonthlyMonitorReportForUnsubscribeToken(
sub = await getEmailPreferenceForUnsubscribeToken(unsubscribeToken);

if (
typeof sub.id === "number" &&
typeof sub?.id === "number" &&
sub.monthly_monitor_report_free === false
) {
logger.info(
"unsubscribe_monthly_monitor_report_for_unsubscribe_token_already_unsubscribed",
);
} else if (typeof sub.id === "number") {
} else if (typeof sub?.id === "number") {
await updateEmailPreferenceForSubscriber(sub.id, true, {
monthly_monitor_report_free: false,
});
Expand Down
8 changes: 5 additions & 3 deletions src/scripts/cronjobs/monthlyActivityFree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@

import { SubscriberRow } from "knex/types/tables";
import { getFreeSubscribersWaitingForMonthlyEmail } from "../../db/tables/subscribers";
import { getLatestOnerepScanResults } from "../../db/tables/onerep_scans";
import { updateEmailPreferenceForSubscriber } from "../../db/tables/subscriber_email_preferences";
import { initEmail, sendEmail, closeEmailPool } from "../../utils/email";
import { renderEmail } from "../../emails/renderEmail";
import { MonthlyActivityFreeEmail } from "../../emails/templates/monthlyActivityFree/MonthlyActivityFreeEmail";
import { getCronjobL10n } from "../../app/functions/l10n/cronjobs";
import { sanitizeSubscriberRow } from "../../app/functions/server/sanitize";
import { getDashboardSummary } from "../../app/functions/server/dashboard";
import { getLatestOnerepScanResults } from "../../db/tables/onerep_scans";
import { getSubscriberBreaches } from "../../app/functions/server/getSubscriberBreaches";
import { refreshStoredScanResults } from "../../app/functions/server/refreshStoredScanResults";
import { getSignupLocaleCountry } from "../../emails/functions/getSignupLocaleCountry";
import { updateEmailPreferenceForSubscriber } from "../../db/tables/subscriber_email_preferences";
import createDbConnection from "../../db/connect";
import { logger } from "../../app/functions/server/logging";
import { getMonthlyActivityFreeUnsubscribeLink } from "../../app/functions/cronjobs/unsubscribeLinks";

void run();
await run();
await createDbConnection().destroy();

async function run() {
const batchSize = Number.parseInt(
Expand Down

0 comments on commit a163c17

Please sign in to comment.