@proconnect-gouv/proconnect.identite 10.3.0 → 10.4.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 +11 -0
- package/dist/connectors/index.d.ts +1 -1
- package/dist/managers/certification/match-identity-to-dirigeant.d.ts +44 -0
- package/dist/managers/certification/match-identity-to-dirigeant.d.ts.map +1 -0
- package/dist/managers/certification/match-identity-to-dirigeant.js +32 -0
- package/dist/managers/certification/process-certification-dirigeant.d.ts.map +1 -1
- package/dist/managers/certification/process-certification-dirigeant.js +1 -29
- package/dist/managers/organization/mark-domain-as-verified.d.ts.map +1 -1
- package/dist/managers/organization/mark-domain-as-verified.js +2 -0
- package/dist/repositories/moderation/get-moderation-by-id.d.ts.map +1 -1
- package/dist/repositories/moderation/get-moderation-by-id.js +1 -1
- package/dist/repositories/organization/find-users-by-organization.d.ts +1 -1
- package/dist/repositories/organization/find-users-by-organization.d.ts.map +1 -1
- package/dist/repositories/organization/find-users-by-organization.js +3 -6
- package/package.json +3 -3
- package/src/managers/certification/match-identity-to-dirigeant.test.ts +62 -0
- package/src/managers/certification/match-identity-to-dirigeant.ts +40 -0
- package/src/managers/certification/process-certification-dirigeant.ts +1 -35
- package/src/managers/organization/mark-domain-as-verified.test.ts +174 -0
- package/src/managers/organization/mark-domain-as-verified.ts +2 -0
- package/src/repositories/moderation/get-moderation-by-id.test.ts +1 -1
- package/src/repositories/moderation/get-moderation-by-id.ts +1 -1
- package/src/repositories/organization/find-users-by-organization.ts +4 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @proconnect-gouv/proconnect.identite
|
|
2
2
|
|
|
3
|
+
## 10.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#2154](https://github.com/proconnect-gouv/proconnect-identite/pull/2154) [`6894647`](https://github.com/proconnect-gouv/proconnect-identite/commit/6894647574f1482cf9a7064dc5188d09cf9ded2a) Thanks [@douglasduteil](https://github.com/douglasduteil)! - suppression des paramètres inutilisés additionalWhereClause et additionalParams de findUsersByOrganization
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`d7a9f69`](https://github.com/proconnect-gouv/proconnect-identite/commit/d7a9f69111ae9fe6b9c99a38e64258acc0663686)]:
|
|
12
|
+
- @proconnect-gouv/proconnect.core@1.1.0
|
|
13
|
+
|
|
3
14
|
## 10.3.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
|
@@ -536,7 +536,7 @@ export declare function createContext({ api_entreprise_client, api_insee_client,
|
|
|
536
536
|
findPendingByUserId: (user_id: number) => Promise<(import("../types/organization.js").Organization & {
|
|
537
537
|
moderation_id: number;
|
|
538
538
|
})[]>;
|
|
539
|
-
findUsers: (organization_id: number
|
|
539
|
+
findUsers: (organization_id: number) => Promise<(import("../types/user.js").User & {
|
|
540
540
|
is_external: boolean;
|
|
541
541
|
verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association" | "no_verification_means_for_small_organization";
|
|
542
542
|
verified_at: Date | null;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { IdentityVector } from "#src/types";
|
|
2
|
+
export declare function match_identity_to_dirigeant(identity: IdentityVector, dirigeants: IdentityVector[]): {
|
|
3
|
+
kind: "exact_match";
|
|
4
|
+
closest: {
|
|
5
|
+
dirigeant: {
|
|
6
|
+
birthcountry: string | null;
|
|
7
|
+
birthdate: Date | null;
|
|
8
|
+
birthplace: string | null;
|
|
9
|
+
family_name: string | null;
|
|
10
|
+
gender: "male" | "female" | null;
|
|
11
|
+
given_name: string | null;
|
|
12
|
+
};
|
|
13
|
+
matches: Set<"family_name" | "gender" | "birth_country" | "birth_date" | "birth_place" | "first_name">;
|
|
14
|
+
};
|
|
15
|
+
} | {
|
|
16
|
+
kind: "close_match";
|
|
17
|
+
closest: {
|
|
18
|
+
dirigeant: {
|
|
19
|
+
birthcountry: string | null;
|
|
20
|
+
birthdate: Date | null;
|
|
21
|
+
birthplace: string | null;
|
|
22
|
+
family_name: string | null;
|
|
23
|
+
gender: "male" | "female" | null;
|
|
24
|
+
given_name: string | null;
|
|
25
|
+
};
|
|
26
|
+
matches: Set<"family_name" | "gender" | "birth_country" | "birth_date" | "birth_place" | "first_name">;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
kind: "below_threshold";
|
|
30
|
+
closest: {
|
|
31
|
+
dirigeant: {
|
|
32
|
+
birthcountry: string | null;
|
|
33
|
+
birthdate: Date | null;
|
|
34
|
+
birthplace: string | null;
|
|
35
|
+
family_name: string | null;
|
|
36
|
+
gender: "male" | "female" | null;
|
|
37
|
+
given_name: string | null;
|
|
38
|
+
};
|
|
39
|
+
matches: Set<"family_name" | "gender" | "birth_country" | "birth_date" | "birth_place" | "first_name">;
|
|
40
|
+
};
|
|
41
|
+
} | {
|
|
42
|
+
kind: "no_candidates";
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=match-identity-to-dirigeant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-identity-to-dirigeant.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/match-identity-to-dirigeant.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMjD,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,cAAc,EACxB,UAAU,EAAE,cAAc,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6B7B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { match } from "ts-pattern";
|
|
3
|
+
import { certificationScore } from "./certification-score.js";
|
|
4
|
+
//
|
|
5
|
+
export function match_identity_to_dirigeant(identity, dirigeants) {
|
|
6
|
+
if (dirigeants.length === 0)
|
|
7
|
+
return { kind: "no_candidates" };
|
|
8
|
+
const [closest] = dirigeants
|
|
9
|
+
.map((dirigeant) => ({
|
|
10
|
+
dirigeant,
|
|
11
|
+
matches: certificationScore(identity, dirigeant),
|
|
12
|
+
}))
|
|
13
|
+
.toSorted((a, b) => b.matches.size - a.matches.size); // Sort by score descending (higher is better)
|
|
14
|
+
// According to the specification, only score of 5 (perfect match) is certified
|
|
15
|
+
return match(closest.matches.size)
|
|
16
|
+
.with(5, () => ({
|
|
17
|
+
kind: "exact_match",
|
|
18
|
+
closest,
|
|
19
|
+
}))
|
|
20
|
+
.with(4, () => ({
|
|
21
|
+
kind: "close_match",
|
|
22
|
+
closest,
|
|
23
|
+
}))
|
|
24
|
+
.with(3, () => ({
|
|
25
|
+
kind: "close_match",
|
|
26
|
+
closest,
|
|
27
|
+
}))
|
|
28
|
+
.otherwise(() => ({
|
|
29
|
+
kind: "below_threshold",
|
|
30
|
+
closest,
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-certification-dirigeant.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/process-certification-dirigeant.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAEL,KAAK,qBAAqB,
|
|
1
|
+
{"version":3,"file":"process-certification-dirigeant.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/process-certification-dirigeant.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,CAAC,MAAM,QAAQ,CAAC;AASvB,eAAO,MAAM,gCAAgC;;;;EAI3C,CAAC;AAEH,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CACpD,OAAO,gCAAgC,CACxC,CAAC;AAWF,wBAAgB,yCAAyC,CACvD,UAAU,EAAE,gCAAgC,UAG7C;AAmCD,wBAAgB,oCAAoC,CAAC,OAAO,EAAE,OAAO,IAMjE,cAAc,YAAY,EAC1B,wBAAwB,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEhD"}
|
|
@@ -7,7 +7,7 @@ import * as ApiEntreprise from "./adapters/api_entreprise.js";
|
|
|
7
7
|
import * as FranceConnect from "./adapters/franceconnect.js";
|
|
8
8
|
import * as INSEE from "./adapters/insee.js";
|
|
9
9
|
import * as RNE from "./adapters/rne.js";
|
|
10
|
-
import {
|
|
10
|
+
import { match_identity_to_dirigeant } from "./match-identity-to-dirigeant.js";
|
|
11
11
|
//
|
|
12
12
|
export const CertificationDirigeantDataSource = z.enum([
|
|
13
13
|
"api.insee.fr/api-sirene/private",
|
|
@@ -42,34 +42,6 @@ async function getMandatairesSociaux({ client: { api_entreprise, rne } }, siren)
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
function match_identity_to_dirigeant(identity, dirigeants) {
|
|
46
|
-
if (dirigeants.length === 0)
|
|
47
|
-
return { kind: "no_candidates" };
|
|
48
|
-
const [closest] = dirigeants
|
|
49
|
-
.map((dirigeant) => ({
|
|
50
|
-
dirigeant,
|
|
51
|
-
matches: certificationScore(identity, dirigeant),
|
|
52
|
-
}))
|
|
53
|
-
.toSorted((a, b) => b.matches.size - a.matches.size); // Sort by score descending (higher is better)
|
|
54
|
-
// According to the specification, only score of 5 (perfect match) is certified
|
|
55
|
-
return match(closest.matches.size)
|
|
56
|
-
.with(5, () => ({
|
|
57
|
-
kind: "exact_match",
|
|
58
|
-
closest,
|
|
59
|
-
}))
|
|
60
|
-
.with(4, () => ({
|
|
61
|
-
kind: "close_match",
|
|
62
|
-
closest,
|
|
63
|
-
}))
|
|
64
|
-
.with(3, () => ({
|
|
65
|
-
kind: "close_match",
|
|
66
|
-
closest,
|
|
67
|
-
}))
|
|
68
|
-
.otherwise(() => ({
|
|
69
|
-
kind: "below_threshold",
|
|
70
|
-
closest,
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
45
|
export function processCertificationDirigeantFactory(context) {
|
|
74
46
|
const { client: { insee }, } = context;
|
|
75
47
|
return async function processCertificationDirigeant(organization, franceconnect_userinfo) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mark-domain-as-verified.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/mark-domain-as-verified.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAGL,KAAK,oCAAoC,EAK1C,MAAM,YAAY,CAAC;AAOpB,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,IAQf,wDAIxC;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,oCAAoC,CAAC;CAChE;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"mark-domain-as-verified.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/mark-domain-as-verified.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAGL,KAAK,oCAAoC,EAK1C,MAAM,YAAY,CAAC;AAOpB,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,IAQf,wDAIxC;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,oCAAoC,CAAC;CAChE;;;;;;;;;GAkFF;AAED,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAClD,OAAO,2BAA2B,CACnC,CAAC"}
|
|
@@ -36,6 +36,7 @@ export function markDomainAsVerifiedFactory(context) {
|
|
|
36
36
|
domain_verification_types: [
|
|
37
37
|
...EmailDomainApprovedVerificationValues,
|
|
38
38
|
...EmailDomainPendingVerificationValues,
|
|
39
|
+
...EmailDomainRejectedVerificationValues,
|
|
39
40
|
],
|
|
40
41
|
});
|
|
41
42
|
return email_domains.addDomain({
|
|
@@ -49,6 +50,7 @@ export function markDomainAsVerifiedFactory(context) {
|
|
|
49
50
|
organization_id,
|
|
50
51
|
domain,
|
|
51
52
|
domain_verification_types: [
|
|
53
|
+
...EmailDomainApprovedVerificationValues,
|
|
52
54
|
...EmailDomainPendingVerificationValues,
|
|
53
55
|
...EmailDomainRejectedVerificationValues,
|
|
54
56
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-moderation-by-id.d.ts","sourceRoot":"","sources":["../../../src/repositories/moderation/get-moderation-by-id.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-moderation-by-id.d.ts","sourceRoot":"","sources":["../../../src/repositories/moderation/get-moderation-by-id.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAKnE,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IAGtB,IAAI,MAAM,KAAG,OAAO,CAAC,UAAU,CAAC,CAOzE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//
|
|
2
|
+
import { ModerationNotFoundError } from "#src/errors";
|
|
2
3
|
import {} from "#src/types";
|
|
3
|
-
import { ModerationNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
|
|
4
4
|
import { findModerationByIdFactory } from "./find-moderation-by-id.js";
|
|
5
5
|
//
|
|
6
6
|
export function getModerationByIdFactory({ pg }) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DatabaseContext, User } from "#src/types";
|
|
2
|
-
export declare function findUsersByOrganizationFactory({ pg }: DatabaseContext): (organization_id: number
|
|
2
|
+
export declare function findUsersByOrganizationFactory({ pg }: DatabaseContext): (organization_id: number) => Promise<(User & {
|
|
3
3
|
is_external: boolean;
|
|
4
4
|
verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association" | "no_verification_means_for_small_organization";
|
|
5
5
|
verified_at: Date | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-users-by-organization.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/find-users-by-organization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,eAAe,EACf,IAAI,EACL,MAAM,YAAY,CAAC;AAKpB,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"find-users-by-organization.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/find-users-by-organization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,eAAe,EACf,IAAI,EACL,MAAM,YAAY,CAAC;AAKpB,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,iBAAiB,MAAM;;;;;MAiBtE"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
//
|
|
2
2
|
//
|
|
3
3
|
export function findUsersByOrganizationFactory({ pg }) {
|
|
4
|
-
return async function findUsersByOrganization(organization_id
|
|
5
|
-
const
|
|
6
|
-
const baseParams = [organization_id];
|
|
7
|
-
const { rows } = await connection.query(`
|
|
4
|
+
return async function findUsersByOrganization(organization_id) {
|
|
5
|
+
const { rows } = await pg.query(`
|
|
8
6
|
SELECT u.*,
|
|
9
7
|
uo.is_external,
|
|
10
8
|
uo.verification_type,
|
|
@@ -12,8 +10,7 @@ export function findUsersByOrganizationFactory({ pg }) {
|
|
|
12
10
|
uo.has_been_greeted
|
|
13
11
|
FROM users u
|
|
14
12
|
INNER JOIN users_organizations AS uo ON uo.user_id = u.id
|
|
15
|
-
WHERE uo.organization_id = $1
|
|
16
|
-
${additionalWhereClause}`, [...baseParams, ...additionalParams]);
|
|
13
|
+
WHERE uo.organization_id = $1`, [organization_id]);
|
|
17
14
|
return rows;
|
|
18
15
|
};
|
|
19
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.0",
|
|
4
4
|
"homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/identite#readme",
|
|
5
5
|
"bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@electric-sql/pglite": "^0.3.12",
|
|
54
54
|
"@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.5",
|
|
55
55
|
"@proconnect-gouv/proconnect.api_entreprise": "^2.3.0",
|
|
56
|
-
"@proconnect-gouv/proconnect.core": "^1.
|
|
56
|
+
"@proconnect-gouv/proconnect.core": "^1.1.0",
|
|
57
57
|
"@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
|
|
58
58
|
"@proconnect-gouv/proconnect.insee": "^2.0.0",
|
|
59
59
|
"@proconnect-gouv/proconnect.registre_national_entreprises": "^4.1.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.5",
|
|
69
69
|
"@proconnect-gouv/proconnect.api_entreprise": "^2.3.0",
|
|
70
|
-
"@proconnect-gouv/proconnect.core": "^1.
|
|
70
|
+
"@proconnect-gouv/proconnect.core": "^1.1.0",
|
|
71
71
|
"@proconnect-gouv/proconnect.insee": "^2.0.0",
|
|
72
72
|
"@proconnect-gouv/proconnect.registre_national_entreprises": "^4.1.0"
|
|
73
73
|
},
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import { match_identity_to_dirigeant } from "./match-identity-to-dirigeant.js";
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
const identity = {
|
|
10
|
+
birthcountry: null,
|
|
11
|
+
birthdate: new Date("1946-08-17"),
|
|
12
|
+
birthplace: "75001",
|
|
13
|
+
family_name: "Bernard",
|
|
14
|
+
gender: "male" as const,
|
|
15
|
+
given_name: "Stéphane",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe("match_identity_to_dirigeant", () => {
|
|
19
|
+
it("returns no_candidates for an empty dirigeants list", () => {
|
|
20
|
+
assert.deepEqual(match_identity_to_dirigeant(identity, []), {
|
|
21
|
+
kind: "no_candidates",
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("returns exact_match for a score of 5", () => {
|
|
26
|
+
const result = match_identity_to_dirigeant(identity, [identity]);
|
|
27
|
+
assert.equal(result.kind, "exact_match");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("returns close_match for a score of 4", () => {
|
|
31
|
+
const dirigeant = { ...identity, family_name: "DuMoulin" };
|
|
32
|
+
const result = match_identity_to_dirigeant(identity, [dirigeant]);
|
|
33
|
+
assert.equal(result.kind, "close_match");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("returns close_match for a score of 3", () => {
|
|
37
|
+
const dirigeant = {
|
|
38
|
+
...identity,
|
|
39
|
+
family_name: "DuMoulin",
|
|
40
|
+
given_name: "Robert",
|
|
41
|
+
};
|
|
42
|
+
const result = match_identity_to_dirigeant(identity, [dirigeant]);
|
|
43
|
+
assert.equal(result.kind, "close_match");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("returns below_threshold for a score under 3", () => {
|
|
47
|
+
const dirigeant = {
|
|
48
|
+
...identity,
|
|
49
|
+
family_name: "DuMoulin",
|
|
50
|
+
given_name: "Robert",
|
|
51
|
+
gender: "female" as const,
|
|
52
|
+
};
|
|
53
|
+
const result = match_identity_to_dirigeant(identity, [dirigeant]);
|
|
54
|
+
assert.equal(result.kind, "below_threshold");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("picks the highest-scoring candidate among several", () => {
|
|
58
|
+
const weak = { ...identity, family_name: "DuMoulin", given_name: "Robert" };
|
|
59
|
+
const result = match_identity_to_dirigeant(identity, [weak, identity]);
|
|
60
|
+
assert.equal(result.kind, "exact_match");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { IdentityVector } from "#src/types";
|
|
4
|
+
import { match } from "ts-pattern";
|
|
5
|
+
import { certificationScore } from "./certification-score.js";
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
export function match_identity_to_dirigeant(
|
|
10
|
+
identity: IdentityVector,
|
|
11
|
+
dirigeants: IdentityVector[],
|
|
12
|
+
) {
|
|
13
|
+
if (dirigeants.length === 0) return { kind: "no_candidates" as const };
|
|
14
|
+
|
|
15
|
+
const [closest] = dirigeants
|
|
16
|
+
.map((dirigeant) => ({
|
|
17
|
+
dirigeant,
|
|
18
|
+
matches: certificationScore(identity, dirigeant),
|
|
19
|
+
}))
|
|
20
|
+
.toSorted((a, b) => b.matches.size - a.matches.size); // Sort by score descending (higher is better)
|
|
21
|
+
|
|
22
|
+
// According to the specification, only score of 5 (perfect match) is certified
|
|
23
|
+
return match(closest.matches.size)
|
|
24
|
+
.with(5, () => ({
|
|
25
|
+
kind: "exact_match" as const,
|
|
26
|
+
closest,
|
|
27
|
+
}))
|
|
28
|
+
.with(4, () => ({
|
|
29
|
+
kind: "close_match" as const,
|
|
30
|
+
closest,
|
|
31
|
+
}))
|
|
32
|
+
.with(3, () => ({
|
|
33
|
+
kind: "close_match" as const,
|
|
34
|
+
closest,
|
|
35
|
+
}))
|
|
36
|
+
.otherwise(() => ({
|
|
37
|
+
kind: "below_threshold" as const,
|
|
38
|
+
closest,
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
@@ -5,7 +5,6 @@ import { isOrganizationCoveredByCertificationDirigeant } from "#src/services/org
|
|
|
5
5
|
import {
|
|
6
6
|
NullIdentityVector,
|
|
7
7
|
type FranceConnectUserInfo,
|
|
8
|
-
type IdentityVector,
|
|
9
8
|
type Organization,
|
|
10
9
|
} from "#src/types";
|
|
11
10
|
import { match } from "ts-pattern";
|
|
@@ -14,7 +13,7 @@ import * as ApiEntreprise from "./adapters/api_entreprise.js";
|
|
|
14
13
|
import * as FranceConnect from "./adapters/franceconnect.js";
|
|
15
14
|
import * as INSEE from "./adapters/insee.js";
|
|
16
15
|
import * as RNE from "./adapters/rne.js";
|
|
17
|
-
import {
|
|
16
|
+
import { match_identity_to_dirigeant } from "./match-identity-to-dirigeant.js";
|
|
18
17
|
|
|
19
18
|
//
|
|
20
19
|
|
|
@@ -76,39 +75,6 @@ async function getMandatairesSociaux(
|
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
function match_identity_to_dirigeant(
|
|
80
|
-
identity: IdentityVector,
|
|
81
|
-
dirigeants: IdentityVector[],
|
|
82
|
-
) {
|
|
83
|
-
if (dirigeants.length === 0) return { kind: "no_candidates" as const };
|
|
84
|
-
|
|
85
|
-
const [closest] = dirigeants
|
|
86
|
-
.map((dirigeant) => ({
|
|
87
|
-
dirigeant,
|
|
88
|
-
matches: certificationScore(identity, dirigeant),
|
|
89
|
-
}))
|
|
90
|
-
.toSorted((a, b) => b.matches.size - a.matches.size); // Sort by score descending (higher is better)
|
|
91
|
-
|
|
92
|
-
// According to the specification, only score of 5 (perfect match) is certified
|
|
93
|
-
return match(closest.matches.size)
|
|
94
|
-
.with(5, () => ({
|
|
95
|
-
kind: "exact_match" as const,
|
|
96
|
-
closest,
|
|
97
|
-
}))
|
|
98
|
-
.with(4, () => ({
|
|
99
|
-
kind: "close_match" as const,
|
|
100
|
-
closest,
|
|
101
|
-
}))
|
|
102
|
-
.with(3, () => ({
|
|
103
|
-
kind: "close_match" as const,
|
|
104
|
-
closest,
|
|
105
|
-
}))
|
|
106
|
-
.otherwise(() => ({
|
|
107
|
-
kind: "below_threshold" as const,
|
|
108
|
-
closest,
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
78
|
export function processCertificationDirigeantFactory(context: Context) {
|
|
113
79
|
const {
|
|
114
80
|
client: { insee },
|
|
@@ -63,6 +63,180 @@ describe("markDomainAsVerified", () => {
|
|
|
63
63
|
]);
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
it("approving a domain should replace an existing rejection for the same domain", async () => {
|
|
67
|
+
await pg.sql`
|
|
68
|
+
INSERT INTO organizations
|
|
69
|
+
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
70
|
+
VALUES
|
|
71
|
+
(1, 'Night Lords', 'Night Lords Legion', '🦇', '4444-04-04', '4444-04-04')
|
|
72
|
+
;
|
|
73
|
+
`;
|
|
74
|
+
await pg.sql`
|
|
75
|
+
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
76
|
+
VALUES (1, 'nightlords.world', 'refused')
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
await markDomainAsVerified({
|
|
80
|
+
domain: "nightlords.world",
|
|
81
|
+
domain_verification_type: "verified",
|
|
82
|
+
organization_id: 1,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const { rows: emailDomains } = await pg.sql`
|
|
86
|
+
SELECT domain, verification_type
|
|
87
|
+
FROM email_domains
|
|
88
|
+
WHERE organization_id = 1
|
|
89
|
+
ORDER BY verification_type
|
|
90
|
+
`;
|
|
91
|
+
assert.deepEqual(emailDomains, [
|
|
92
|
+
{ domain: "nightlords.world", verification_type: "verified" },
|
|
93
|
+
]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("rejecting a domain should replace an existing approval for the same domain", async () => {
|
|
97
|
+
await pg.sql`
|
|
98
|
+
INSERT INTO organizations
|
|
99
|
+
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
100
|
+
VALUES
|
|
101
|
+
(1, 'Thousand Sons', 'Thousand Sons Legion', '📖', '4444-04-04', '4444-04-04')
|
|
102
|
+
;
|
|
103
|
+
`;
|
|
104
|
+
await pg.sql`
|
|
105
|
+
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
106
|
+
VALUES (1, 'thousandsons.world', 'verified')
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
await markDomainAsVerified({
|
|
110
|
+
domain: "thousandsons.world",
|
|
111
|
+
domain_verification_type: "refused",
|
|
112
|
+
organization_id: 1,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const { rows: emailDomains } = await pg.sql`
|
|
116
|
+
SELECT domain, verification_type
|
|
117
|
+
FROM email_domains
|
|
118
|
+
WHERE organization_id = 1
|
|
119
|
+
ORDER BY verification_type
|
|
120
|
+
`;
|
|
121
|
+
assert.deepEqual(emailDomains, [
|
|
122
|
+
{ domain: "thousandsons.world", verification_type: "refused" },
|
|
123
|
+
]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should reject a pending domain", async () => {
|
|
127
|
+
await pg.sql`
|
|
128
|
+
INSERT INTO organizations
|
|
129
|
+
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
130
|
+
VALUES
|
|
131
|
+
(1, 'Black Legion', 'Black Legion Warband', '👁️', '4444-04-04', '4444-04-04')
|
|
132
|
+
;
|
|
133
|
+
`;
|
|
134
|
+
await pg.sql`
|
|
135
|
+
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
136
|
+
VALUES (1, 'blacklegion.world', 'not_verified_yet')
|
|
137
|
+
`;
|
|
138
|
+
|
|
139
|
+
await markDomainAsVerified({
|
|
140
|
+
domain: "blacklegion.world",
|
|
141
|
+
domain_verification_type: "refused",
|
|
142
|
+
organization_id: 1,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const { rows: emailDomains } = await pg.sql`
|
|
146
|
+
SELECT domain, verification_type
|
|
147
|
+
FROM email_domains
|
|
148
|
+
WHERE organization_id = 1
|
|
149
|
+
ORDER BY verification_type
|
|
150
|
+
`;
|
|
151
|
+
assert.deepEqual(emailDomains, [
|
|
152
|
+
{ domain: "blacklegion.world", verification_type: "refused" },
|
|
153
|
+
]);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("rejecting a domain should not demote an already domain-verified member", async () => {
|
|
157
|
+
await pg.sql`
|
|
158
|
+
INSERT INTO organizations
|
|
159
|
+
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
160
|
+
VALUES
|
|
161
|
+
(1, 'Word Bearers', 'Word Bearers Legion', '🔥', '4444-04-04', '4444-04-04')
|
|
162
|
+
;
|
|
163
|
+
`;
|
|
164
|
+
await pg.sql`
|
|
165
|
+
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
166
|
+
VALUES (1, 'lorgar.aurelian@wordbearers.world', '4444-04-04', '4444-04-04', 'Lorgar', 'Aurelian', '0', 'Primarque')
|
|
167
|
+
`;
|
|
168
|
+
await pg.sql`
|
|
169
|
+
INSERT INTO users_organizations
|
|
170
|
+
(user_id, organization_id, created_at, updated_at, is_external, verification_type)
|
|
171
|
+
VALUES
|
|
172
|
+
(1, 1, '4444-04-04', '4444-04-04', false, 'domain')
|
|
173
|
+
;
|
|
174
|
+
`;
|
|
175
|
+
await pg.sql`
|
|
176
|
+
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
177
|
+
VALUES (1, 'wordbearers.world', 'not_verified_yet')
|
|
178
|
+
`;
|
|
179
|
+
|
|
180
|
+
await markDomainAsVerified({
|
|
181
|
+
domain: "wordbearers.world",
|
|
182
|
+
domain_verification_type: "refused",
|
|
183
|
+
organization_id: 1,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const { rows: userLinks } = await pg.sql`
|
|
187
|
+
SELECT user_id, verification_type
|
|
188
|
+
FROM users_organizations
|
|
189
|
+
WHERE organization_id = 1
|
|
190
|
+
`;
|
|
191
|
+
assert.deepEqual(userLinks, [{ user_id: 1, verification_type: "domain" }]);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("approving a domain should only promote eligible member links", async () => {
|
|
195
|
+
await pg.sql`
|
|
196
|
+
INSERT INTO organizations
|
|
197
|
+
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
198
|
+
VALUES
|
|
199
|
+
(1, 'Emperor''s Children', 'Emperor''s Children Legion', '🎭', '4444-04-04', '4444-04-04')
|
|
200
|
+
;
|
|
201
|
+
`;
|
|
202
|
+
await pg.sql`
|
|
203
|
+
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
204
|
+
VALUES
|
|
205
|
+
(1, 'fulgrim@emperorschildren.world', '4444-04-04', '4444-04-04', 'Fulgrim', 'Primarque', '0', 'Primarque'),
|
|
206
|
+
(2, 'lucius@emperorschildren.world', '4444-04-04', '4444-04-04', 'Lucius', 'The Eternal', '0', 'Champion')
|
|
207
|
+
;
|
|
208
|
+
`;
|
|
209
|
+
await pg.sql`
|
|
210
|
+
INSERT INTO users_organizations
|
|
211
|
+
(user_id, organization_id, created_at, updated_at, is_external, verification_type)
|
|
212
|
+
VALUES
|
|
213
|
+
(1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle'),
|
|
214
|
+
(2, 1, '4444-04-04', '4444-04-04', false, 'organization_dirigeant')
|
|
215
|
+
;
|
|
216
|
+
`;
|
|
217
|
+
await pg.sql`
|
|
218
|
+
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
219
|
+
VALUES (1, 'emperorschildren.world', 'not_verified_yet')
|
|
220
|
+
`;
|
|
221
|
+
|
|
222
|
+
await markDomainAsVerified({
|
|
223
|
+
domain: "emperorschildren.world",
|
|
224
|
+
domain_verification_type: "verified",
|
|
225
|
+
organization_id: 1,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const { rows: userLinks } = await pg.sql`
|
|
229
|
+
SELECT user_id, verification_type
|
|
230
|
+
FROM users_organizations
|
|
231
|
+
WHERE organization_id = 1
|
|
232
|
+
ORDER BY user_id
|
|
233
|
+
`;
|
|
234
|
+
assert.deepEqual(userLinks, [
|
|
235
|
+
{ user_id: 1, verification_type: "domain" },
|
|
236
|
+
{ user_id: 2, verification_type: "organization_dirigeant" },
|
|
237
|
+
]);
|
|
238
|
+
});
|
|
239
|
+
|
|
66
240
|
it("❎ throws NotFoundError for unknown organization", async () => {
|
|
67
241
|
await assert.rejects(
|
|
68
242
|
markDomainAsVerified({
|
|
@@ -80,6 +80,7 @@ export function markDomainAsVerifiedFactory(context: Context) {
|
|
|
80
80
|
domain_verification_types: [
|
|
81
81
|
...EmailDomainApprovedVerificationValues,
|
|
82
82
|
...EmailDomainPendingVerificationValues,
|
|
83
|
+
...EmailDomainRejectedVerificationValues,
|
|
83
84
|
],
|
|
84
85
|
});
|
|
85
86
|
return email_domains.addDomain({
|
|
@@ -103,6 +104,7 @@ export function markDomainAsVerifiedFactory(context: Context) {
|
|
|
103
104
|
organization_id,
|
|
104
105
|
domain,
|
|
105
106
|
domain_verification_types: [
|
|
107
|
+
...EmailDomainApprovedVerificationValues,
|
|
106
108
|
...EmailDomainPendingVerificationValues,
|
|
107
109
|
...EmailDomainRejectedVerificationValues,
|
|
108
110
|
],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
+
import { ModerationNotFoundError } from "#src/errors";
|
|
3
4
|
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
-
import { ModerationNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
|
|
5
5
|
import assert from "node:assert/strict";
|
|
6
6
|
import { before, beforeEach, suite, test } from "node:test";
|
|
7
7
|
import { getModerationByIdFactory } from "./get-moderation-by-id.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
+
import { ModerationNotFoundError } from "#src/errors";
|
|
3
4
|
import { type DatabaseContext, type Moderation } from "#src/types";
|
|
4
|
-
import { ModerationNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
|
|
5
5
|
import { findModerationByIdFactory } from "./find-moderation-by-id.js";
|
|
6
6
|
|
|
7
7
|
//
|
|
@@ -10,16 +10,9 @@ import type { QueryResult } from "pg";
|
|
|
10
10
|
//
|
|
11
11
|
|
|
12
12
|
export function findUsersByOrganizationFactory({ pg }: DatabaseContext) {
|
|
13
|
-
return async function findUsersByOrganization(
|
|
14
|
-
organization_id: number,
|
|
15
|
-
additionalWhereClause: string = "",
|
|
16
|
-
additionalParams: any[] = [],
|
|
17
|
-
) {
|
|
18
|
-
const connection = pg;
|
|
19
|
-
const baseParams = [organization_id];
|
|
20
|
-
|
|
13
|
+
return async function findUsersByOrganization(organization_id: number) {
|
|
21
14
|
const { rows }: QueryResult<User & BaseUserOrganizationLink> =
|
|
22
|
-
await
|
|
15
|
+
await pg.query(
|
|
23
16
|
`
|
|
24
17
|
SELECT u.*,
|
|
25
18
|
uo.is_external,
|
|
@@ -28,9 +21,8 @@ export function findUsersByOrganizationFactory({ pg }: DatabaseContext) {
|
|
|
28
21
|
uo.has_been_greeted
|
|
29
22
|
FROM users u
|
|
30
23
|
INNER JOIN users_organizations AS uo ON uo.user_id = u.id
|
|
31
|
-
WHERE uo.organization_id = $1
|
|
32
|
-
|
|
33
|
-
[...baseParams, ...additionalParams],
|
|
24
|
+
WHERE uo.organization_id = $1`,
|
|
25
|
+
[organization_id],
|
|
34
26
|
);
|
|
35
27
|
|
|
36
28
|
return rows;
|