Skip to content

Commit 8a0ce8c

Browse files
committed
feat(email): isolate is free email fn
1 parent 3cb488a commit 8a0ce8c

File tree

11 files changed

+719
-619
lines changed

11 files changed

+719
-619
lines changed

package-lock.json

Lines changed: 635 additions & 613 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@fullhuman/postcss-purgecss": "^6.0.0",
4343
"@gouvfr/dsfr": "^1.12.1",
4444
"@numerique-gouv/crisp": "https://github.com/douglasduteil/crisp/releases/download/v1.6.1/douglasduteil-crisp-1.6.1.tgz",
45+
"@numerique-gouv/moncomptepro.free-email": "workspace:*",
4546
"@panva/jose": "^1.9.3",
4647
"@sentry/node": "^7.112.2",
4748
"@sentry/tracing": "^7.114.0",

packages/free-email/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
tsconfig.tsbuildinfo

packages/free-email/package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "@numerique-gouv/moncomptepro.free-email",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"exports": {
7+
".": {
8+
"require": {
9+
"types": "./dist/index.d.ts",
10+
"default": "./dist/index.js"
11+
},
12+
"import": {
13+
"types": "./dist/index.d.ts",
14+
"default": "./dist/index.js"
15+
},
16+
"types": "./dist/index.d.ts",
17+
"default": "./dist/index.js"
18+
},
19+
"./data/*": {
20+
"require": {
21+
"types": "./dist/data/*.d.ts",
22+
"default": "./dist/data/*.js"
23+
},
24+
"import": {
25+
"types": "./dist/data/*.d.ts",
26+
"default": "./dist/data/*.js"
27+
},
28+
"types": "./dist/data/*.d.ts",
29+
"default": "./dist/data/*.js"
30+
}
31+
},
32+
"scripts": {
33+
"build": "tsc --build",
34+
"dev": "npm run build -- --watch --preserveWatchOutput",
35+
"check": "npm run build -- --noEmit"
36+
},
37+
"dependencies": {
38+
"is-disposable-email-domain": "^1.0.7"
39+
},
40+
"devDependencies": {
41+
"@tsconfig/node22": "^22.0.0"
42+
}
43+
}
File renamed without changes.

packages/free-email/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
3+
import { isFree } from "is-disposable-email-domain";
4+
import mostUsedFreeEmailDomains from "./data/most-used-free-email-domains";
5+
6+
//
7+
8+
export function isAFreeDomain(domain: string) {
9+
// heavily inspired from https://stackoverflow.com/questions/71232973/check-email-domain-type-personal-email-or-company-email#answer-72640757
10+
return isFree(domain) || mostUsedFreeEmailDomains.includes(domain);
11+
}

packages/free-email/tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"declaration": true,
5+
"declarationMap": true,
6+
"outDir": "./dist",
7+
"rootDir": "src",
8+
"types": ["./types"],
9+
"module": "Preserve",
10+
"moduleResolution": "Bundler",
11+
"verbatimModuleSyntax": true
12+
},
13+
"extends": "@tsconfig/node22/tsconfig.json",
14+
"references": []
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//
2+
3+
declare module "is-disposable-email-domain" {
4+
function isFree(email: string): boolean;
5+
}

src/services/did-you-mean.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import mostUsedFreeEmailDomains from "@numerique-gouv/moncomptepro.free-email/data/most-used-free-email-domains";
12
import { run as spellCheckEmail } from "@zootools/email-spell-checker";
23
import gouvfrDomains from "../data/gouvfr-domains";
3-
import mostUsedFreeEmailDomains from "../data/most-used-free-email-domains";
44
import otherGouvDomains from "../data/other-gouv-domains";
55

66
// Display an email suggestion for most used public domains

src/services/email.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// heavily inspired from https://stackoverflow.com/questions/71232973/check-email-domain-type-personal-email-or-company-email#answer-72640757
2-
import { isFree } from "is-disposable-email-domain";
1+
//
2+
3+
import { isAFreeDomain } from "@numerique-gouv/moncomptepro.free-email";
34
import { parse_host } from "tld-extract";
45
import {
56
FEATURE_CONSIDER_ALL_EMAIL_DOMAINS_AS_FREE,
67
FEATURE_CONSIDER_ALL_EMAIL_DOMAINS_AS_NON_FREE,
78
} from "../config/env";
8-
import mostUsedFreeEmailDomains from "../data/most-used-free-email-domains";
99

1010
export const isAFreeEmailProvider = (domain: string) => {
1111
if (FEATURE_CONSIDER_ALL_EMAIL_DOMAINS_AS_FREE) {
@@ -16,7 +16,7 @@ export const isAFreeEmailProvider = (domain: string) => {
1616
return false;
1717
}
1818

19-
return isFree(domain) || mostUsedFreeEmailDomains.includes(domain);
19+
return isAFreeDomain(domain);
2020
};
2121

2222
export const getEmailDomain = (email: string) => {

0 commit comments

Comments
 (0)