Skip to content

Commit

Permalink
feat(email): isolate is free email fn
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Oct 18, 2024
1 parent 3cb488a commit 7d239dc
Show file tree
Hide file tree
Showing 9 changed files with 700 additions and 617 deletions.
1,248 changes: 635 additions & 613 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@fullhuman/postcss-purgecss": "^6.0.0",
"@gouvfr/dsfr": "^1.12.1",
"@numerique-gouv/crisp": "https://github.com/douglasduteil/crisp/releases/download/v1.6.1/douglasduteil-crisp-1.6.1.tgz",
"@numerique-gouv/moncomptepro.free-email": "workspace:*",
"@panva/jose": "^1.9.3",
"@sentry/node": "^7.112.2",
"@sentry/tracing": "^7.114.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/free-email/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
tsconfig.tsbuildinfo
27 changes: 27 additions & 0 deletions packages/free-email/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@numerique-gouv/moncomptepro.free-email",
"version": "0.0.0",
"private": true,
"type": "module",
"exports": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"scripts": {
"build": "tsc --build",
"dev": "npm run build -- --watch --preserveWatchOutput",
"check": "npm run build -- --noEmit"
},
"dependencies": {
"is-disposable-email-domain": "^1.0.7"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.0"
}
}
11 changes: 11 additions & 0 deletions packages/free-email/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//

import { isFree } from "is-disposable-email-domain";
import mostUsedFreeEmailDomains from "./most-used-free-email-domains";

//

export function isAFreeDomain(domain: string) {
// heavily inspired from https://stackoverflow.com/questions/71232973/check-email-domain-type-personal-email-or-company-email#answer-72640757
return isFree(domain) || mostUsedFreeEmailDomains.includes(domain);
}
File renamed without changes.
15 changes: 15 additions & 0 deletions packages/free-email/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"composite": true,
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"rootDir": "src",
"types": ["./types"],
"module": "Preserve",
"moduleResolution": "Bundler",
"verbatimModuleSyntax": true
},
"extends": "@tsconfig/node22/tsconfig.json",
"references": []
}
5 changes: 5 additions & 0 deletions packages/free-email/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//

declare module "is-disposable-email-domain" {
function isFree(email: string): boolean;
}
8 changes: 4 additions & 4 deletions src/services/email.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// heavily inspired from https://stackoverflow.com/questions/71232973/check-email-domain-type-personal-email-or-company-email#answer-72640757
import { isFree } from "is-disposable-email-domain";
//

import { isAFreeDomain } from "@numerique-gouv/moncomptepro.free-email";

Check failure on line 3 in src/services/email.ts

View workflow job for this annotation

GitHub Actions / test

Cannot find module '@numerique-gouv/moncomptepro.free-email' or its corresponding type declarations.
import { parse_host } from "tld-extract";
import {
FEATURE_CONSIDER_ALL_EMAIL_DOMAINS_AS_FREE,
FEATURE_CONSIDER_ALL_EMAIL_DOMAINS_AS_NON_FREE,
} from "../config/env";
import mostUsedFreeEmailDomains from "../data/most-used-free-email-domains";

export const isAFreeEmailProvider = (domain: string) => {
if (FEATURE_CONSIDER_ALL_EMAIL_DOMAINS_AS_FREE) {
Expand All @@ -16,7 +16,7 @@ export const isAFreeEmailProvider = (domain: string) => {
return false;
}

return isFree(domain) || mostUsedFreeEmailDomains.includes(domain);
return isAFreeDomain(domain);
};

export const getEmailDomain = (email: string) => {
Expand Down

0 comments on commit 7d239dc

Please sign in to comment.