From 9297cfeb0ad8d38cb1a0dd489185fd45599a9481 Mon Sep 17 00:00:00 2001 From: Michele Esposito <34438276+mikesposito@users.noreply.github.com> Date: Thu, 30 May 2024 15:50:36 +0200 Subject: [PATCH] refactor: apply suggestions from @mcmire Co-authored-by: Elliot Winkler --- .../src/PhishingDetector.ts | 38 +++++++++++++++++-- packages/phishing-controller/src/utils.ts | 2 +- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/packages/phishing-controller/src/PhishingDetector.ts b/packages/phishing-controller/src/PhishingDetector.ts index 8811948f72..0c1e13f1b2 100644 --- a/packages/phishing-controller/src/PhishingDetector.ts +++ b/packages/phishing-controller/src/PhishingDetector.ts @@ -44,11 +44,41 @@ export type PhishingDetectorConfiguration = { tolerance: number; }; +/** + * Represents the result of checking a domain. + */ export type PhishingDetectorResult = { + /** + * The name of the configuration object in which the domain was found within + * an allowlist, blocklist, or fuzzylist. + */ name?: string; + /** + * The version associated with the configuration object in which the domain + * was found within an allowlist, blocklist, or fuzzylist. + */ version?: string; + /** + * Whether the domain is regarded as allowed (true) or not (false). + */ result: boolean; + /** + * A normalized version of the domain, which is only constructed if the domain + * is found within a list. + */ match?: string; + /** + * Which type of list in which the domain was found. + * + * - "allowlist" means that the domain was found in the allowlist. + * - "blocklist" means that the domain was found in the blocklist. + * - "fuzzy" means that the domain was found in the fuzzylist. + * - "blacklist" means that the domain was found in a blacklist of a legacy + * configuration object. + * - "whitelist" means that the domain was found in a whitelist of a legacy + * configuration object. + * - "all" means that the domain was not found in any list. + */ type: 'all' | 'fuzzy' | 'blocklist' | 'allowlist' | 'blacklist' | 'whitelist'; }; @@ -97,7 +127,7 @@ export class PhishingDetector { const result = this.#check(domain); if (this.#legacyConfig) { - let legacyType = result.type as PhishingDetectorResult['type']; + let legacyType = result.type; if (legacyType === 'allowlist') { legacyType = 'whitelist'; } else if (legacyType === 'blocklist') { @@ -127,7 +157,7 @@ export class PhishingDetector { name, result: false, type: 'allowlist', - version: String(version), + version: version === undefined ? version : String(version), }; } } @@ -143,7 +173,7 @@ export class PhishingDetector { name, result: true, type: 'blocklist', - version: String(version), + version: version === undefined ? version : String(version), }; } @@ -165,7 +195,7 @@ export class PhishingDetector { match, result: true, type: 'fuzzy', - version: String(version), + version: version === undefined ? version : String(version), }; } } diff --git a/packages/phishing-controller/src/utils.ts b/packages/phishing-controller/src/utils.ts index b6fc717181..650a2125c1 100644 --- a/packages/phishing-controller/src/utils.ts +++ b/packages/phishing-controller/src/utils.ts @@ -180,7 +180,7 @@ export const getDefaultPhishingDetectorConfig = (override?: { export const processConfigs = (configs: PhishingDetectorList[] = []) => { return configs.map((config) => { validateConfig(config); - return Object.assign({}, config, getDefaultPhishingDetectorConfig(config)); + return { ...config, ...getDefaultPhishingDetectorConfig(config) }; }); };