Merge branch 'main' into fix-local-env-default

This commit is contained in:
mansaj 2024-07-17 08:30:14 -07:00 коммит произвёл GitHub
Родитель eacb3b7a3f bb1e38cd08
Коммит b0bbee7d14
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 20 добавлений и 15 удалений

Просмотреть файл

@ -12,6 +12,7 @@
"dev:cron:first-data-broker-removal-fixed": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/firstDataBrokerRemovalFixed.tsx",
"dev:cron:monthly-activity": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/monthlyActivity.tsx",
"dev:cron:db-delete-unverified-subscribers": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/deleteUnverifiedSubscribers.ts",
"dev:cron:db-pull-breaches": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/syncBreaches.ts",
"dev:cron:onerep-limits-alert": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/onerepStatsAlert.ts",
"dev:nimbus": "node --watch-path config/nimbus.yaml src/scripts/build/nimbusTypes.js",
"build": "npm run get-location-data && npm run build-glean && npm run build-nimbus && next build && npm run build-cronjobs",
@ -27,7 +28,7 @@
"cron:monthly-activity": "node dist/scripts/cronjobs/monthlyActivity.js",
"cron:breach-alerts": "node src/scripts/emailBreachAlerts.js",
"cron:db-delete-unverified-subscribers": "node dist/scripts/cronjobs/deleteUnverifiedSubscribers.js",
"cron:db-pull-breaches": "node src/scripts/syncBreaches.js",
"cron:db-pull-breaches": "node dist/scripts/cronjobs/syncBreaches.js",
"cron:remote-settings-pull-breaches": "node scripts/updatebreaches.js",
"cron:onerep-limits-alert": "node dist/scripts/cronjobs/onerepStatsAlert.js",
"db:migrate": "node -r dotenv-flow/config node_modules/knex/bin/cli.js migrate:latest --knexfile src/db/knexfile.js",

Просмотреть файл

@ -88,8 +88,8 @@ async function upsertBreaches(hibpBreaches) {
/**
* Update logo path of a breach by name
*
* @param {string} name
* @param {string} faviconUrl
* @param {string} name
* @param {string | null} faviconUrl
*/
// Not covered by tests; mostly side-effects. See test-coverage.md#mock-heavy
/* c8 ignore start */

Просмотреть файл

@ -12,13 +12,14 @@
import { readdir } from "node:fs/promises";
import os from "node:os";
import Sentry from "@sentry/nextjs";
import { req, formatDataClassesArray } from "../utils/hibp.js";
import { req, formatDataClassesArray } from "../../utils/hibp.js";
import {
getAllBreaches,
upsertBreaches,
updateBreachFaviconUrl,
} from "../db/tables/breaches.js";
import { uploadToS3 } from "./s3.js";
} from "../../db/tables/breaches.js";
import { uploadToS3 } from "../s3.js";
import type { Breach } from "../../app/functions/universal/breach.js";
const SENTRY_SLUG = "cron-sync-breaches";
@ -32,7 +33,7 @@ const checkInId = Sentry.captureCheckIn({
status: "in_progress",
});
export async function getBreachIcons(breaches) {
export async function getBreachIcons(breaches: Breach[]) {
// make logofolder if it doesn't exist
const logoFolder = os.tmpdir();
console.log(`Logo folder: ${logoFolder}`);
@ -82,20 +83,19 @@ export async function getBreachIcons(breaches) {
}
// Get breaches and upserts to DB
const breachesResponse = await req("/breaches");
const breaches = [];
const breachesResponse: Breach[] = await req("/breaches");
const breaches: Breach[] = [];
const seen = new Set();
for (const breach of breachesResponse) {
breach.DataClasses = formatDataClassesArray(breach.DataClasses);
breach.LogoPath = /[^/]*$/.exec(breach.LogoPath)[0];
breach.LogoPath = /[^/]*$/.exec(breach.LogoPath)![0];
breaches.push(breach);
seen.add(breach.Name + breach.BreachDate);
// sanity check: corrupt data structure
if (!isValidBreach(breach))
throw new Error(
"Breach data structure is not valid",
JSON.stringify(breach),
"Breach data structure is not valid: " + JSON.stringify(breach),
);
}
@ -128,10 +128,10 @@ setTimeout(process.exit, 1000);
/**
* Null check for some required field
*
* @param {object} breach breach object from HIBP
* @param breach breach object from HIBP
* @returns Boolean is it a valid breach
*/
function isValidBreach(breach) {
function isValidBreach(breach: Breach) {
return (
breach.Name !== undefined &&
breach.BreachDate !== undefined &&

Просмотреть файл

@ -24,6 +24,10 @@ const s3 = new S3({
},
});
/**
* @param {string} fileName
* @param {Buffer} fileStream
*/
export async function uploadToS3(fileName, fileStream) {
console.log("Attempt to upload to s3: ", fileName);
const uploadParams = {
@ -37,7 +41,7 @@ export async function uploadToS3(fileName, fileStream) {
params: uploadParams,
}).done();
console.log("Successfully uploaded data to " + Bucket + "/" + fileName);
} catch (err) {
} catch (/** @type {any} */ err) {
console.error(err, err.stack);
}
}