@proconnect-gouv/proconnect.core 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @proconnect-gouv/proconnect.core
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2246](https://github.com/proconnect-gouv/proconnect-identite/pull/2246) [`d7a9f69`](https://github.com/proconnect-gouv/proconnect-identite/commit/d7a9f69111ae9fe6b9c99a38e64258acc0663686) Thanks [@douglasduteil](https://github.com/douglasduteil)! - 🔒 les fonctions isAFreeDomain et getEmailDomain sont plus robustes et acceptent une plus grande variété de paramètres
8
+
3
9
  ## 1.0.2
4
10
 
5
11
  ### Patch Changes
@@ -5,13 +5,17 @@ var mostUsedFreeEmailDomains = require('#src/data/most-used-free-email-domains')
5
5
  var isDisposableEmailDomain = require('is-disposable-email-domain');
6
6
 
7
7
  function getEmailDomain(email) {
8
+ if (!email) {
9
+ throw new Error("Empty string");
10
+ }
8
11
  const parts = email.split("@");
9
12
  const host = parts[parts.length - 1];
10
13
  const { sub, domain } = tldExtract.parse_host(host, { allowDotlessTLD: true });
11
14
  return [sub, domain].filter(Boolean).join(".");
12
15
  }
13
16
 
14
- function isAFreeDomain(domain) {
17
+ function isAFreeDomain(string) {
18
+ const domain = getEmailDomain(string);
15
19
  return isDisposableEmailDomain.isFree(domain) || mostUsedFreeEmailDomains.includes(domain);
16
20
  }
17
21
 
@@ -7,7 +7,7 @@
7
7
  */
8
8
  declare function getEmailDomain(email: string): string;
9
9
 
10
- declare function isAFreeDomain(domain: string): boolean;
10
+ declare function isAFreeDomain(string: string): boolean;
11
11
 
12
12
  export { getEmailDomain, isAFreeDomain };
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sources":["../../../src/services/email/get-email-domain.ts","../../../src/services/email/is-a-free-domain.ts"],"mappings":"AAMA;;;;;;;AAOA,iBAAgB,cAAc;;ACN9B,iBAAgB,aAAa","names":[]}
1
+ {"version":3,"file":"index.d.ts","sources":["../../../src/services/email/get-email-domain.ts","../../../src/services/email/is-a-free-domain.ts"],"mappings":"AAMA;;;;;;;AAOA,iBAAgB,cAAc;;ACJ9B,iBAAgB,aAAa","names":[]}
@@ -3,13 +3,17 @@ import mostUsedFreeEmailDomains from '#src/data/most-used-free-email-domains';
3
3
  import { isFree } from 'is-disposable-email-domain';
4
4
 
5
5
  function getEmailDomain(email) {
6
+ if (!email) {
7
+ throw new Error("Empty string");
8
+ }
6
9
  const parts = email.split("@");
7
10
  const host = parts[parts.length - 1];
8
11
  const { sub, domain } = parse_host(host, { allowDotlessTLD: true });
9
12
  return [sub, domain].filter(Boolean).join(".");
10
13
  }
11
14
 
12
- function isAFreeDomain(domain) {
15
+ function isAFreeDomain(string) {
16
+ const domain = getEmailDomain(string);
13
17
  return isFree(domain) || mostUsedFreeEmailDomains.includes(domain);
14
18
  }
15
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proconnect-gouv/proconnect.core",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/core#readme",
5
5
  "bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
6
6
  "repository": {
@@ -20,6 +20,10 @@ describe("getEmailDomain", () => {
20
20
  email: "user@subdomain.domain.org",
21
21
  domain: "subdomain.domain.org",
22
22
  },
23
+ {
24
+ email: "domain.org",
25
+ domain: "domain.org",
26
+ },
23
27
  ];
24
28
 
25
29
  data.forEach(({ email, domain }) => {
@@ -27,4 +31,22 @@ describe("getEmailDomain", () => {
27
31
  assert.equal(getEmailDomain(email), domain);
28
32
  });
29
33
  });
34
+
35
+ const errors: { email: string; error: { name: string; message: RegExp } }[] =
36
+ [
37
+ {
38
+ email: "",
39
+ error: { name: "Error", message: /Empty string/ },
40
+ },
41
+ {
42
+ email: "jean",
43
+ error: { name: "Error", message: /Invalid TLD/ },
44
+ },
45
+ ];
46
+
47
+ errors.forEach(({ email, error }) => {
48
+ it(`should throw on ${JSON.stringify(email)}`, () => {
49
+ assert.throws(() => getEmailDomain(email), error);
50
+ });
51
+ });
30
52
  });
@@ -12,6 +12,10 @@ import { parse_host } from "tld-extract";
12
12
  * @returns the domain of the email address
13
13
  */
14
14
  export function getEmailDomain(email: string) {
15
+ if (!email) {
16
+ throw new Error("Empty string");
17
+ }
18
+
15
19
  const parts = email.split("@");
16
20
  const host = parts[parts.length - 1];
17
21
  const { sub, domain } = parse_host(host, { allowDotlessTLD: true });
@@ -14,9 +14,11 @@ describe("isAFreeDomain", () => {
14
14
  "outlook.com",
15
15
  "aol.com",
16
16
  "yopmail.com",
17
+ "9business.fr",
17
18
  ].forEach((domain) => {
18
- it(`should return true for free domains "${domain}"`, () => {
19
+ it(`should return true for free domains and emails using "${domain}"`, () => {
19
20
  assert.equal(isAFreeDomain(domain), true);
21
+ assert.equal(isAFreeDomain(`user@${domain}`), true);
20
22
  });
21
23
  });
22
24
 
@@ -2,10 +2,13 @@
2
2
 
3
3
  import mostUsedFreeEmailDomains from "#src/data/most-used-free-email-domains";
4
4
  import { isFree } from "is-disposable-email-domain";
5
+ import { getEmailDomain } from "./get-email-domain.js";
5
6
 
6
7
  //
7
8
 
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
9
+ // heavily inspired from https://stackoverflow.com/questions/71232973/check-email-domain-type-personal-email-or-company-email#answer-72640757
10
+ export function isAFreeDomain(string: string) {
11
+ const domain = getEmailDomain(string);
12
+
10
13
  return isFree(domain) || mostUsedFreeEmailDomains.includes(domain);
11
14
  }