@proconnect-gouv/proconnect.core 1.0.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.md +61 -0
  3. package/dist/data/index.cjs +282 -0
  4. package/dist/data/index.d.ts +7 -0
  5. package/dist/data/index.js +278 -0
  6. package/dist/most-used-free-email-domains-BiH62xhh.cjs +21 -0
  7. package/dist/most-used-free-email-domains-CtdkKumB.js +19 -0
  8. package/dist/security/index.cjs +8013 -0
  9. package/dist/security/index.d.ts +31 -0
  10. package/dist/security/index.js +7998 -0
  11. package/dist/services/email/index.cjs +19 -0
  12. package/dist/services/email/index.d.ts +12 -0
  13. package/dist/services/email/index.js +16 -0
  14. package/dist/services/oidc/index.cjs +10 -0
  15. package/dist/services/oidc/index.d.ts +19 -0
  16. package/dist/services/oidc/index.js +8 -0
  17. package/dist/services/suggestion/index.cjs +20 -0
  18. package/dist/services/suggestion/index.d.ts +3 -0
  19. package/dist/services/suggestion/index.js +18 -0
  20. package/package.json +92 -0
  21. package/src/data/diceware-wordlist-fr-alt.ts +7780 -0
  22. package/src/data/gouvfr-domains.ts +246 -0
  23. package/src/data/index.ts +3 -0
  24. package/src/data/most-used-free-email-domains.ts +18 -0
  25. package/src/data/other-gouv-domains.ts +41 -0
  26. package/src/security/generate-diceware-password.test.ts +26 -0
  27. package/src/security/generate-diceware-password.ts +25 -0
  28. package/src/security/generate-pin-token.test.ts +19 -0
  29. package/src/security/generate-pin-token.ts +13 -0
  30. package/src/security/generate-token.test.ts +14 -0
  31. package/src/security/generate-token.ts +9 -0
  32. package/src/security/get-trusted-referrer-path.test.ts +49 -0
  33. package/src/security/get-trusted-referrer-path.ts +34 -0
  34. package/src/security/hash-password.test.ts +16 -0
  35. package/src/security/hash-password.ts +10 -0
  36. package/src/security/index.ts +15 -0
  37. package/src/security/is-domain-valid.test.ts +28 -0
  38. package/src/security/is-domain-valid.ts +28 -0
  39. package/src/security/is-email-valid.test.ts +71 -0
  40. package/src/security/is-email-valid.ts +44 -0
  41. package/src/security/is-name-valid.test.ts +61 -0
  42. package/src/security/is-name-valid.ts +5 -0
  43. package/src/security/is-password-secure.test.ts +53 -0
  44. package/src/security/is-password-secure.ts +25 -0
  45. package/src/security/is-phone-number-valid.test.ts +44 -0
  46. package/src/security/is-phone-number-valid.ts +19 -0
  47. package/src/security/is-siret-valid.test.ts +36 -0
  48. package/src/security/is-siret-valid.ts +15 -0
  49. package/src/security/is-visible-string.test.ts +30 -0
  50. package/src/security/is-visible-string.ts +7 -0
  51. package/src/security/owasp-password-strength-tester.ts +149 -0
  52. package/src/security/validate-password.test.ts +27 -0
  53. package/src/security/validate-password.ts +16 -0
  54. package/src/services/email/get-email-domain.test.ts +30 -0
  55. package/src/services/email/get-email-domain.ts +20 -0
  56. package/src/services/email/index.ts +4 -0
  57. package/src/services/email/is-a-free-domain.test.ts +26 -0
  58. package/src/services/email/is-a-free-domain.ts +11 -0
  59. package/src/services/oidc/contains-essential-acrs.test.ts +63 -0
  60. package/src/services/oidc/contains-essential-acrs.ts +24 -0
  61. package/src/services/oidc/index.ts +2 -0
  62. package/src/services/oidc/prompt.ts +11 -0
  63. package/src/services/suggestion/did-you-mean.test.ts +29 -0
  64. package/src/services/suggestion/did-you-mean.ts +19 -0
  65. package/src/services/suggestion/index.ts +3 -0
  66. package/tsconfig.json +11 -0
  67. package/tsconfig.lib.json +9 -0
  68. package/types/index.d.ts +4 -0
  69. package/types/is-disposable-email-domain.d.ts +5 -0
  70. package/types/tld-extract.d.ts +12 -0
@@ -0,0 +1,63 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { containsEssentialAcrs } from "./contains-essential-acrs.js";
4
+
5
+ describe("containsEssentialAcrs", () => {
6
+ const cases: [
7
+ string,
8
+ Parameters<typeof containsEssentialAcrs>,
9
+ ReturnType<typeof containsEssentialAcrs>,
10
+ ][] = [
11
+ [
12
+ "should return true for essential_acr reasons",
13
+ [
14
+ {
15
+ details: {
16
+ acr: {
17
+ essential: true,
18
+ value: "https://proconnect.gouv.fr/assurance/self-asserted",
19
+ },
20
+ },
21
+ name: "login",
22
+ reasons: ["essential_acr"],
23
+ },
24
+ ],
25
+ true,
26
+ ],
27
+ [
28
+ "should return true for essential_acrs reasons",
29
+ [
30
+ {
31
+ details: {
32
+ acr: {
33
+ essential: true,
34
+ values: [
35
+ "https://proconnect.gouv.fr/assurance/self-asserted",
36
+ "https://proconnect.gouv.fr/assurance/consistency-checked",
37
+ ],
38
+ },
39
+ },
40
+ name: "login",
41
+ reasons: ["essential_acrs"],
42
+ },
43
+ ],
44
+ true,
45
+ ],
46
+ [
47
+ "should return false for unknown 💁 login name",
48
+ [{ details: { acr: {} }, name: "💁", reasons: [] }],
49
+ false,
50
+ ],
51
+ [
52
+ "should return false for non unknown 🦆 reasons",
53
+ [{ details: {}, name: "login", reasons: ["🦆"] }],
54
+ false,
55
+ ],
56
+ ];
57
+
58
+ for (const [title, parameters, expected] of cases) {
59
+ it(title, () => {
60
+ assert.equal(containsEssentialAcrs(...parameters), expected);
61
+ });
62
+ }
63
+ });
@@ -0,0 +1,24 @@
1
+ //
2
+
3
+ import type { PromptDetail } from "oidc-provider";
4
+ import type { EssentialAcrPromptDetail } from "./prompt.js";
5
+
6
+ //
7
+
8
+ /**
9
+ * Check if a prompt contains essential acrs
10
+ * @param prompt the oidc-provider {@link PromptDetail}
11
+ */
12
+ export function containsEssentialAcrs(
13
+ prompt: PromptDetail,
14
+ ): prompt is EssentialAcrPromptDetail {
15
+ if (
16
+ prompt.name === "login" &&
17
+ (prompt.reasons.includes("essential_acr") ||
18
+ prompt.reasons.includes("essential_acrs"))
19
+ ) {
20
+ return true;
21
+ }
22
+
23
+ return false;
24
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./contains-essential-acrs.js";
2
+ export * from "./prompt.js";
@@ -0,0 +1,11 @@
1
+ //
2
+
3
+ import type { PromptDetail } from "oidc-provider";
4
+
5
+ //
6
+
7
+ export interface EssentialAcrPromptDetail extends PromptDetail {
8
+ details: {
9
+ acr: { essential: boolean; value?: string; values?: string[] };
10
+ };
11
+ }
@@ -0,0 +1,29 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { getDidYouMeanSuggestion } from "./did-you-mean.js";
4
+
5
+ describe("getDidYouMeanSuggestion", () => {
6
+ const emailAddresses = [
7
+ ["agent@gmil.com", "agent@gmail.com"],
8
+ ["agent@wanadoo.rf", "agent@wanadoo.fr"],
9
+ ["agent@beta.gouv.rf", "agent@beta.gouv.fr"],
10
+ ["agent@beta.gouvfr", "agent@beta.gouv.fr"],
11
+ ["agent@beta.gov.fr", "agent@beta.gouv.fr"],
12
+ ["agent@betagouv.rf", "agent@betagouv.fr"],
13
+ [
14
+ "agent@gendarmerie.interieure.gouv.fr",
15
+ "agent@gendarmerie.interieur.gouv.fr",
16
+ ],
17
+ [
18
+ "agent@gendarmerie.interieur.gouv.frl",
19
+ "agent@gendarmerie.interieur.gouv.fr",
20
+ ],
21
+ ["agent@nomatch", ""],
22
+ ];
23
+
24
+ emailAddresses.forEach(([inputEmail, suggestedEmail]) => {
25
+ it(`should suggest corrected email for ${inputEmail}`, () => {
26
+ assert.equal(getDidYouMeanSuggestion(inputEmail), suggestedEmail);
27
+ });
28
+ });
29
+ });
@@ -0,0 +1,19 @@
1
+ import gouvfrDomains from "#src/data/gouvfr-domains";
2
+ import mostUsedFreeEmailDomains from "#src/data/most-used-free-email-domains";
3
+ import otherGouvDomains from "#src/data/other-gouv-domains";
4
+ import { run as spellCheckEmail } from "@zootools/email-spell-checker";
5
+
6
+ // Display an email suggestion for most used public domains
7
+ export function getDidYouMeanSuggestion(email: string): string {
8
+ const suggestedEmail = spellCheckEmail({
9
+ domains: [
10
+ ...gouvfrDomains,
11
+ ...otherGouvDomains,
12
+ ...mostUsedFreeEmailDomains,
13
+ ],
14
+ topLevelDomains: ["fr", "com", "net"],
15
+ email,
16
+ });
17
+
18
+ return suggestedEmail?.full ? suggestedEmail.full : "";
19
+ }
@@ -0,0 +1,3 @@
1
+ //
2
+
3
+ export * from "./did-you-mean.js";
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationMap": true,
5
+ "outDir": "./dist",
6
+ "rootDir": "src",
7
+ "types": ["node", "./types"]
8
+ },
9
+ "extends": "@proconnect-gouv/proconnect.devtools.typescript/base/tsconfig.json",
10
+ "references": []
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist",
4
+ "rootDir": "./src"
5
+ },
6
+ "exclude": ["src/**/*.test.ts"],
7
+ "extends": "./tsconfig.json",
8
+ "include": ["src"]
9
+ }
@@ -0,0 +1,4 @@
1
+ //
2
+
3
+ /// <reference path="./is-disposable-email-domain.d.ts" />
4
+ /// <reference path="./tld-extract.d.ts" />
@@ -0,0 +1,5 @@
1
+ //
2
+
3
+ declare module "is-disposable-email-domain" {
4
+ function isFree(email: string): boolean;
5
+ }
@@ -0,0 +1,12 @@
1
+ //
2
+
3
+ declare module "tld-extract" {
4
+ function parse_host(
5
+ domain: string,
6
+ { allowDotlessTLD: boolean },
7
+ ): {
8
+ tld: string;
9
+ domain: string;
10
+ sub: string;
11
+ };
12
+ }