Skip to content

Commit

Permalink
refactor: apply suggestions from @mcmire
Browse files Browse the repository at this point in the history
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
  • Loading branch information
mikesposito and mcmire authored May 30, 2024
1 parent e9f7052 commit 9297cfe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
38 changes: 34 additions & 4 deletions packages/phishing-controller/src/PhishingDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};

Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -127,7 +157,7 @@ export class PhishingDetector {
name,
result: false,
type: 'allowlist',
version: String(version),
version: version === undefined ? version : String(version),
};
}
}
Expand All @@ -143,7 +173,7 @@ export class PhishingDetector {
name,
result: true,
type: 'blocklist',
version: String(version),
version: version === undefined ? version : String(version),
};
}

Expand All @@ -165,7 +195,7 @@ export class PhishingDetector {
match,
result: true,
type: 'fuzzy',
version: String(version),
version: version === undefined ? version : String(version),
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/phishing-controller/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
});
};

Expand Down

0 comments on commit 9297cfe

Please sign in to comment.