@proconnect-gouv/proconnect.identite 11.0.0 → 12.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.
- package/CHANGELOG.md +19 -0
- package/dist/managers/certification/process-certification-dirigeant.d.ts +28 -1
- package/dist/managers/certification/process-certification-dirigeant.d.ts.map +1 -1
- package/dist/managers/certification/process-certification-dirigeant.js +17 -5
- package/dist/managers/organization/get-organization-info.d.ts +21 -1
- package/dist/managers/organization/get-organization-info.d.ts.map +1 -1
- package/dist/managers/organization/get-organization-info.js +44 -41
- package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts +9 -0
- package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts.map +1 -0
- package/dist/services/organization/get-member-ids-promoted-by-domain.js +11 -0
- package/dist/services/organization/index.d.ts +1 -0
- package/dist/services/organization/index.d.ts.map +1 -1
- package/dist/services/organization/index.js +1 -0
- package/package.json +1 -1
- package/src/managers/certification/process-certification-dirigeant.test.ts +12 -1
- package/src/managers/certification/process-certification-dirigeant.ts +23 -4
- package/src/managers/organization/get-organization-info.test.ts +75 -4
- package/src/managers/organization/get-organization-info.test.ts.snapshot +104 -80
- package/src/managers/organization/get-organization-info.ts +63 -56
- package/src/services/organization/get-member-ids-promoted-by-domain.test.ts +100 -0
- package/src/services/organization/get-member-ids-promoted-by-domain.ts +27 -0
- package/src/services/organization/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @proconnect-gouv/proconnect.identite
|
|
2
2
|
|
|
3
|
+
## 12.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#2362](https://github.com/proconnect-gouv/proconnect-identite/pull/2362) [`da31f6d`](https://github.com/proconnect-gouv/proconnect-identite/commit/da31f6d036c7569c0184962bb9bc6d14d12f04a1) Thanks [@douglasduteil](https://github.com/douglasduteil)! - `getOrganizationInfo` et `processCertificationDirigeant` renvoient leurs issues au lieu d'écrire dans la console ou de lever des erreurs.
|
|
8
|
+
|
|
9
|
+
Migration :
|
|
10
|
+
- `getOrganizationInfo` renvoie un `OrganizationInfoLookup` : faites un `match` sur `kind` au lieu d'attraper `InvalidSiretError`, `NotFoundError` ou `ApiEntrepriseConnectionError`.
|
|
11
|
+
- `found` : les données sont dans `organization_info` ; `rne.kind` vaut `enriched`, ou `failed` avec l'`exception` du registre national des entreprises.
|
|
12
|
+
- `invalid_siret` : le SIRET ou SIREN est mal formé ou refusé par entreprise.api.gouv.fr ; `exception` est une `InvalidSiretError` dont la `cause` porte le refus d'entreprise.api.gouv.fr.
|
|
13
|
+
- `not_diffusible` : l'établissement n'est pas diffusible.
|
|
14
|
+
- `api_entreprise_failed` : entreprise.api.gouv.fr a échoué, avec l'`exception`.
|
|
15
|
+
- `processCertificationDirigeant` ajoute `details.source_selection` (`SourceSelection`) : `preferred`, ou `fallback` avec l'`exception` du registre national des entreprises quand les mandataires viennent d'entreprise.api.gouv.fr.
|
|
16
|
+
- Les erreurs `InvalidSiretError`, `NotFoundError` et `ApiEntrepriseConnectionError` restent exportées.
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- [#2365](https://github.com/proconnect-gouv/proconnect-identite/pull/2365) [`e47d7dd`](https://github.com/proconnect-gouv/proconnect-identite/commit/e47d7dd69c76c7b8c8dc8094c8ec4ac574278e75) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute `getMemberIdsPromotedByDomain` dans `services/organization` : à partir d'un domaine et des membres d'une organisation, renvoie les identifiants des membres à promouvoir au rattachement `domain`.
|
|
21
|
+
|
|
3
22
|
## 11.0.0
|
|
4
23
|
|
|
5
24
|
### Major Changes
|
|
@@ -8,6 +8,12 @@ export declare const CertificationDirigeantDataSource: z.ZodEnum<{
|
|
|
8
8
|
}>;
|
|
9
9
|
export type CertificationDirigeantDataSource = z.infer<typeof CertificationDirigeantDataSource>;
|
|
10
10
|
export declare function getCertificationDirigeantDataSourceLabels(dataSource: CertificationDirigeantDataSource): string;
|
|
11
|
+
export type SourceSelection = {
|
|
12
|
+
kind: "fallback";
|
|
13
|
+
exception: unknown;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "preferred";
|
|
16
|
+
};
|
|
11
17
|
export declare function processCertificationDirigeantFactory(context: Context): (organization: Organization, franceconnect_userinfo: FranceConnectUserInfo) => Promise<{
|
|
12
18
|
details: {
|
|
13
19
|
dirigeant: null;
|
|
@@ -21,13 +27,15 @@ export declare function processCertificationDirigeantFactory(context: Context):
|
|
|
21
27
|
given_name: string | null;
|
|
22
28
|
};
|
|
23
29
|
source: null;
|
|
30
|
+
source_selection: {
|
|
31
|
+
kind: "preferred";
|
|
32
|
+
};
|
|
24
33
|
};
|
|
25
34
|
cause: "organisation_not_covered";
|
|
26
35
|
ok: boolean;
|
|
27
36
|
} | {
|
|
28
37
|
details: {
|
|
29
38
|
dirigeant: undefined;
|
|
30
|
-
matches: Set<unknown>;
|
|
31
39
|
identity: {
|
|
32
40
|
birthcountry: string | null;
|
|
33
41
|
birthdate: Date | null;
|
|
@@ -36,7 +44,17 @@ export declare function processCertificationDirigeantFactory(context: Context):
|
|
|
36
44
|
gender: "male" | "female" | null;
|
|
37
45
|
given_name: string | null;
|
|
38
46
|
};
|
|
47
|
+
matches: Set<unknown>;
|
|
39
48
|
source: "api.insee.fr/api-sirene/private" | "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux" | "registre-national-entreprises.inpi.fr/api";
|
|
49
|
+
source_selection: {
|
|
50
|
+
kind: "preferred";
|
|
51
|
+
exception?: undefined;
|
|
52
|
+
} | {
|
|
53
|
+
exception: unknown;
|
|
54
|
+
kind: "fallback";
|
|
55
|
+
} | {
|
|
56
|
+
kind: "preferred";
|
|
57
|
+
};
|
|
40
58
|
};
|
|
41
59
|
cause: "no_candidates";
|
|
42
60
|
ok: boolean;
|
|
@@ -60,6 +78,15 @@ export declare function processCertificationDirigeantFactory(context: Context):
|
|
|
60
78
|
given_name: string | null;
|
|
61
79
|
};
|
|
62
80
|
source: "api.insee.fr/api-sirene/private" | "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux" | "registre-national-entreprises.inpi.fr/api";
|
|
81
|
+
source_selection: {
|
|
82
|
+
kind: "preferred";
|
|
83
|
+
exception?: undefined;
|
|
84
|
+
} | {
|
|
85
|
+
exception: unknown;
|
|
86
|
+
kind: "fallback";
|
|
87
|
+
} | {
|
|
88
|
+
kind: "preferred";
|
|
89
|
+
};
|
|
63
90
|
};
|
|
64
91
|
cause: "exact_match" | "close_match" | "below_threshold";
|
|
65
92
|
ok: boolean;
|
|
@@ -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,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;
|
|
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;AAID,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC;AAqC1B,wBAAgB,oCAAoC,CAAC,OAAO,EAAE,OAAO,IAMjE,cAAc,YAAY,EAC1B,wBAAwB,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EhD"}
|
|
@@ -22,7 +22,6 @@ const CERTIFICATION_DIRIGEANT_DATA_SOURCE_LABELS = {
|
|
|
22
22
|
export function getCertificationDirigeantDataSourceLabels(dataSource) {
|
|
23
23
|
return CERTIFICATION_DIRIGEANT_DATA_SOURCE_LABELS[dataSource];
|
|
24
24
|
}
|
|
25
|
-
//
|
|
26
25
|
async function getMandatairesSociaux({ client: { api_entreprise, rne } }, siren) {
|
|
27
26
|
try {
|
|
28
27
|
const pouvoirs = await rne.findPouvoirsBySiren(siren);
|
|
@@ -30,15 +29,19 @@ async function getMandatairesSociaux({ client: { api_entreprise, rne } }, siren)
|
|
|
30
29
|
return {
|
|
31
30
|
dirigeants,
|
|
32
31
|
source: CertificationDirigeantDataSource.enum["registre-national-entreprises.inpi.fr/api"],
|
|
32
|
+
source_selection: { kind: "preferred" },
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
catch (
|
|
36
|
-
console.error(error);
|
|
35
|
+
catch (exception) {
|
|
37
36
|
const mandataires = await api_entreprise.findMandatairesSociauxBySiren(siren);
|
|
38
37
|
const dirigeants = mandataires.map(ApiEntreprise.toIdentityVector);
|
|
39
38
|
return {
|
|
40
39
|
dirigeants,
|
|
41
40
|
source: CertificationDirigeantDataSource.enum["entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux"],
|
|
41
|
+
source_selection: {
|
|
42
|
+
exception,
|
|
43
|
+
kind: "fallback",
|
|
44
|
+
},
|
|
42
45
|
};
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -52,6 +55,7 @@ export function processCertificationDirigeantFactory(context) {
|
|
|
52
55
|
matches: new Set(),
|
|
53
56
|
identity: NullIdentityVector,
|
|
54
57
|
source: null,
|
|
58
|
+
source_selection: { kind: "preferred" },
|
|
55
59
|
},
|
|
56
60
|
cause: "organisation_not_covered",
|
|
57
61
|
ok: false,
|
|
@@ -63,20 +67,27 @@ export function processCertificationDirigeantFactory(context) {
|
|
|
63
67
|
"Entrepreneur individuel"
|
|
64
68
|
? CertificationDirigeantDataSource.enum["api.insee.fr/api-sirene/private"]
|
|
65
69
|
: CertificationDirigeantDataSource.enum["registre-national-entreprises.inpi.fr/api"];
|
|
66
|
-
const { dirigeants, source } = await match(preferredDataSource)
|
|
70
|
+
const { dirigeants, source, source_selection } = await match(preferredDataSource)
|
|
67
71
|
.with("api.insee.fr/api-sirene/private", async () => ({
|
|
68
72
|
dirigeants: await insee
|
|
69
73
|
.findBySiren(siren)
|
|
70
74
|
.then(INSEE.toIdentityVector)
|
|
71
75
|
.then((vector) => [vector]),
|
|
72
76
|
source: CertificationDirigeantDataSource.enum["api.insee.fr/api-sirene/private"],
|
|
77
|
+
source_selection: { kind: "preferred" },
|
|
73
78
|
}))
|
|
74
79
|
.with("registre-national-entreprises.inpi.fr/api", () => getMandatairesSociaux(context, siren))
|
|
75
80
|
.exhaustive();
|
|
76
81
|
const result = match_identity_to_dirigeant(identity, dirigeants);
|
|
77
82
|
if (result.kind === "no_candidates") {
|
|
78
83
|
return {
|
|
79
|
-
details: {
|
|
84
|
+
details: {
|
|
85
|
+
dirigeant: undefined,
|
|
86
|
+
identity,
|
|
87
|
+
matches: new Set(),
|
|
88
|
+
source,
|
|
89
|
+
source_selection,
|
|
90
|
+
},
|
|
80
91
|
cause: result.kind,
|
|
81
92
|
ok: false,
|
|
82
93
|
};
|
|
@@ -87,6 +98,7 @@ export function processCertificationDirigeantFactory(context) {
|
|
|
87
98
|
matches: result.closest.matches,
|
|
88
99
|
identity,
|
|
89
100
|
source,
|
|
101
|
+
source_selection,
|
|
90
102
|
},
|
|
91
103
|
cause: result.kind,
|
|
92
104
|
ok: result.kind === "exact_match",
|
|
@@ -1,6 +1,26 @@
|
|
|
1
|
+
import { InvalidSiretError } from "#src/errors";
|
|
1
2
|
import { type OrganizationInfo } from "#src/types";
|
|
2
3
|
import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entreprise/api";
|
|
3
4
|
import type { ApiRegistreNationalEntreprisesClient } from "@proconnect-gouv/proconnect.registre_national_entreprises/api";
|
|
4
|
-
export
|
|
5
|
+
export type RneEnrichment = {
|
|
6
|
+
kind: "enriched";
|
|
7
|
+
} | {
|
|
8
|
+
kind: "failed";
|
|
9
|
+
exception: unknown;
|
|
10
|
+
};
|
|
11
|
+
export type OrganizationInfoLookup = {
|
|
12
|
+
kind: "api_entreprise_failed";
|
|
13
|
+
exception: unknown;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "found";
|
|
16
|
+
organization_info: OrganizationInfo;
|
|
17
|
+
rne: RneEnrichment;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "invalid_siret";
|
|
20
|
+
exception: InvalidSiretError;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "not_diffusible";
|
|
23
|
+
};
|
|
24
|
+
export declare function getOrganizationInfoFactory(apiEntrepriseClient: ApiEntrepriseClient, apiRneClient: ApiRegistreNationalEntreprisesClient): (siretOrSiren: string) => Promise<OrganizationInfoLookup>;
|
|
5
25
|
export type GetOrganizationInfoHandler = ReturnType<typeof getOrganizationInfoFactory>;
|
|
6
26
|
//# sourceMappingURL=get-organization-info.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-organization-info.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/get-organization-info.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-organization-info.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/get-organization-info.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAK1F,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AAM1H,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAE3C,MAAM,MAAM,sBAAsB,GAC9B;IAAE,IAAI,EAAE,uBAAuB,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,iBAAiB,EAAE,gBAAgB,CAAC;IAAC,GAAG,EAAE,aAAa,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,SAAS,EAAE,iBAAiB,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAE/B,wBAAgB,0BAA0B,CACxC,mBAAmB,EAAE,mBAAmB,EACxC,YAAY,EAAE,oCAAoC,IAShD,cAAc,MAAM,KACnB,OAAO,CAAC,sBAAsB,CAAC,CAoDnC;AAED,MAAM,MAAM,0BAA0B,GAAG,UAAU,CACjD,OAAO,0BAA0B,CAClC,CAAC"}
|
|
@@ -1,53 +1,56 @@
|
|
|
1
1
|
//
|
|
2
|
-
import { InvalidSiretError
|
|
2
|
+
import { InvalidSiretError } from "#src/errors";
|
|
3
3
|
import {} from "#src/types";
|
|
4
|
-
import {
|
|
4
|
+
import { ApiEntrepriseInvalidSiret, } from "@proconnect-gouv/proconnect.api_entreprise/types";
|
|
5
5
|
import * as ApiEntreprise from "./adapters/api_entreprise.js";
|
|
6
6
|
import * as ApiRne from "./adapters/rne.js";
|
|
7
|
-
//
|
|
8
7
|
export function getOrganizationInfoFactory(apiEntrepriseClient, apiRneClient) {
|
|
8
|
+
async function findApiEntrepriseData(siretOrSiren) {
|
|
9
|
+
if (/^\d{14}$/.test(siretOrSiren))
|
|
10
|
+
return apiEntrepriseClient.findBySiret(siretOrSiren);
|
|
11
|
+
return apiEntrepriseClient.findBySiren(siretOrSiren);
|
|
12
|
+
}
|
|
9
13
|
return async function getOrganizationInfo(siretOrSiren) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (siretOrSiren.match(/^\d{14}$/)) {
|
|
15
|
-
apiEntrepriseOrganizationInfo =
|
|
16
|
-
ApiEntreprise.toApiEntrepriseOrganizationInfo(await apiEntrepriseClient.findBySiret(siretOrSiren));
|
|
17
|
-
}
|
|
18
|
-
else if (siretOrSiren.match(/^\d{9}$/)) {
|
|
19
|
-
apiEntrepriseOrganizationInfo =
|
|
20
|
-
ApiEntreprise.toApiEntrepriseOrganizationInfo(await apiEntrepriseClient.findBySiren(siretOrSiren));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
throw new InvalidSiretError();
|
|
24
|
-
}
|
|
25
|
-
const { statutDiffusion } = apiEntrepriseOrganizationInfo;
|
|
26
|
-
if (statutDiffusion === "non_diffusible") {
|
|
27
|
-
throw new NotFoundError();
|
|
28
|
-
}
|
|
29
|
-
organizationInfo = {
|
|
30
|
-
...apiEntrepriseOrganizationInfo,
|
|
31
|
-
denominationUsuelleEtablissementPrincipal: null,
|
|
14
|
+
if (!/^(\d{9}|\d{14})$/.test(siretOrSiren))
|
|
15
|
+
return {
|
|
16
|
+
exception: new InvalidSiretError("siret or siren must be 9 or 14 digits"),
|
|
17
|
+
kind: "invalid_siret",
|
|
32
18
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
19
|
+
let apiEntrepriseData;
|
|
20
|
+
try {
|
|
21
|
+
apiEntrepriseData = await findApiEntrepriseData(siretOrSiren);
|
|
22
|
+
}
|
|
23
|
+
catch (exception) {
|
|
24
|
+
if (ApiEntrepriseInvalidSiret.isInvalidSiret(exception))
|
|
25
|
+
return {
|
|
26
|
+
exception: new InvalidSiretError("rejected by entreprise.api.gouv.fr", { cause: exception }),
|
|
27
|
+
kind: "invalid_siret",
|
|
40
28
|
};
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
console.error(`RNE data will be undefined for this organization (${siren}); an error occurred while fetching it`, error);
|
|
44
|
-
}
|
|
45
|
-
return organizationInfo;
|
|
29
|
+
return { exception, kind: "api_entreprise_failed" };
|
|
46
30
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
31
|
+
if (apiEntrepriseData.status_diffusion === "non_diffusible")
|
|
32
|
+
return { kind: "not_diffusible" };
|
|
33
|
+
const organizationInfo = {
|
|
34
|
+
...ApiEntreprise.toApiEntrepriseOrganizationInfo(apiEntrepriseData),
|
|
35
|
+
denominationUsuelleEtablissementPrincipal: null,
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
const apiRneData = await apiRneClient.findCompanyBySiren(siretOrSiren.slice(0, 9));
|
|
39
|
+
return {
|
|
40
|
+
kind: "found",
|
|
41
|
+
organization_info: {
|
|
42
|
+
...organizationInfo,
|
|
43
|
+
...ApiRne.toApiRneOrganizationInfo(apiRneData),
|
|
44
|
+
},
|
|
45
|
+
rne: { kind: "enriched" },
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (exception) {
|
|
49
|
+
return {
|
|
50
|
+
kind: "found",
|
|
51
|
+
organization_info: organizationInfo,
|
|
52
|
+
rne: { exception, kind: "failed" },
|
|
53
|
+
};
|
|
51
54
|
}
|
|
52
55
|
};
|
|
53
56
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function getMemberIdsPromotedByDomain({ domain, members, }: {
|
|
2
|
+
domain: string;
|
|
3
|
+
members: ReadonlyArray<{
|
|
4
|
+
email: string;
|
|
5
|
+
id: number;
|
|
6
|
+
verification_type: string;
|
|
7
|
+
}>;
|
|
8
|
+
}): number[];
|
|
9
|
+
//# sourceMappingURL=get-member-ids-promoted-by-domain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-member-ids-promoted-by-domain.d.ts","sourceRoot":"","sources":["../../../src/services/organization/get-member-ids-promoted-by-domain.ts"],"names":[],"mappings":"AAOA,wBAAgB,4BAA4B,CAAC,EAC3C,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,iBAAiB,EAAE,MAAM,CAAC;KAC3B,CAAC,CAAC;CACJ,YASA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
|
|
3
|
+
import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
|
|
4
|
+
//
|
|
5
|
+
export function getMemberIdsPromotedByDomain({ domain, members, }) {
|
|
6
|
+
return members
|
|
7
|
+
.filter(({ email, verification_type }) => getEmailDomain(email) === domain &&
|
|
8
|
+
(UnverifiedLinkEnum.safeParse(verification_type).success ||
|
|
9
|
+
SuperWeakLinkEnum.safeParse(verification_type).success))
|
|
10
|
+
.map(({ id }) => id);
|
|
11
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./compute-service-public-info.js";
|
|
2
|
+
export * from "./get-member-ids-promoted-by-domain.js";
|
|
2
3
|
export * from "./is-domain-allowed-for-organization.js";
|
|
3
4
|
export * from "./is-entreprise-unipersonnelle.js";
|
|
4
5
|
export * from "./is-organization-covered-by-certification-dirigeant.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/organization/index.ts"],"names":[],"mappings":"AAEA,cAAc,kCAAkC,CAAC;AACjD,cAAc,yCAAyC,CAAC;AACxD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yDAAyD,CAAC;AACxE,cAAc,oCAAoC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/organization/index.ts"],"names":[],"mappings":"AAEA,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yDAAyD,CAAC;AACxE,cAAc,oCAAoC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
//
|
|
2
2
|
export * from "./compute-service-public-info.js";
|
|
3
|
+
export * from "./get-member-ids-promoted-by-domain.js";
|
|
3
4
|
export * from "./is-domain-allowed-for-organization.js";
|
|
4
5
|
export * from "./is-entreprise-unipersonnelle.js";
|
|
5
6
|
export * from "./is-organization-covered-by-certification-dirigeant.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.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": {
|
|
@@ -65,6 +65,7 @@ describe("processCertificationDirigeantFactory", () => {
|
|
|
65
65
|
]),
|
|
66
66
|
identity: IdentityVectorSchema.parse(LiElJonsonFranceConnectUserInfo),
|
|
67
67
|
source: "api.insee.fr/api-sirene/private",
|
|
68
|
+
source_selection: { kind: "preferred" },
|
|
68
69
|
},
|
|
69
70
|
ok: true,
|
|
70
71
|
});
|
|
@@ -92,6 +93,7 @@ describe("processCertificationDirigeantFactory", () => {
|
|
|
92
93
|
]),
|
|
93
94
|
identity: IdentityVectorSchema.parse(RogalDornFranceConnectUserInfo),
|
|
94
95
|
source: "api.insee.fr/api-sirene/private",
|
|
96
|
+
source_selection: { kind: "preferred" },
|
|
95
97
|
},
|
|
96
98
|
ok: true,
|
|
97
99
|
});
|
|
@@ -114,6 +116,7 @@ describe("processCertificationDirigeantFactory", () => {
|
|
|
114
116
|
matches: new Set(["gender", "birth_country"]),
|
|
115
117
|
identity: IdentityVectorSchema.parse(RogalDornFranceConnectUserInfo),
|
|
116
118
|
source: "api.insee.fr/api-sirene/private",
|
|
119
|
+
source_selection: { kind: "preferred" },
|
|
117
120
|
},
|
|
118
121
|
ok: false,
|
|
119
122
|
});
|
|
@@ -142,6 +145,7 @@ describe("processCertificationDirigeantFactory", () => {
|
|
|
142
145
|
]),
|
|
143
146
|
identity: IdentityVectorSchema.parse(RogalDornFranceConnectUserInfo),
|
|
144
147
|
source: "registre-national-entreprises.inpi.fr/api",
|
|
148
|
+
source_selection: { kind: "preferred" },
|
|
145
149
|
},
|
|
146
150
|
ok: true,
|
|
147
151
|
});
|
|
@@ -170,12 +174,17 @@ describe("processCertificationDirigeantFactory", () => {
|
|
|
170
174
|
]),
|
|
171
175
|
identity: IdentityVectorSchema.parse(AmberleyVailFranceConnectUserInfo),
|
|
172
176
|
source: "registre-national-entreprises.inpi.fr/api",
|
|
177
|
+
source_selection: { kind: "preferred" },
|
|
173
178
|
},
|
|
174
179
|
ok: true,
|
|
175
180
|
});
|
|
176
181
|
});
|
|
177
182
|
|
|
178
|
-
it("should match Rogal Dorn
|
|
183
|
+
it("should match Rogal Dorn in Infogreffe when RNE fails", async () => {
|
|
184
|
+
const exception = new Error("RNE unavailable");
|
|
185
|
+
api_registre_national_entreprises_mock_client.findPouvoirsBySiren.mock.mockImplementationOnce(
|
|
186
|
+
() => Promise.reject(exception),
|
|
187
|
+
);
|
|
179
188
|
api_entreprise_mock_client.findMandatairesSociauxBySiren.mock.mockImplementationOnce(
|
|
180
189
|
() => Promise.resolve([UlysseToriMandataire, RogalDornMandataire]),
|
|
181
190
|
);
|
|
@@ -199,6 +208,7 @@ describe("processCertificationDirigeantFactory", () => {
|
|
|
199
208
|
identity: IdentityVectorSchema.parse(RogalDornFranceConnectUserInfo),
|
|
200
209
|
source:
|
|
201
210
|
"entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux",
|
|
211
|
+
source_selection: { exception, kind: "fallback" },
|
|
202
212
|
},
|
|
203
213
|
ok: true,
|
|
204
214
|
});
|
|
@@ -221,6 +231,7 @@ describe("processCertificationDirigeantFactory", () => {
|
|
|
221
231
|
identity: IdentityVectorSchema.parse(LiElJonsonFranceConnectUserInfo),
|
|
222
232
|
matches: new Set(),
|
|
223
233
|
source: "registre-national-entreprises.inpi.fr/api",
|
|
234
|
+
source_selection: { kind: "preferred" },
|
|
224
235
|
},
|
|
225
236
|
ok: false,
|
|
226
237
|
});
|
|
@@ -44,6 +44,10 @@ export function getCertificationDirigeantDataSourceLabels(
|
|
|
44
44
|
|
|
45
45
|
//
|
|
46
46
|
|
|
47
|
+
export type SourceSelection =
|
|
48
|
+
| { kind: "fallback"; exception: unknown }
|
|
49
|
+
| { kind: "preferred" };
|
|
50
|
+
|
|
47
51
|
async function getMandatairesSociaux(
|
|
48
52
|
{ client: { api_entreprise, rne } }: Context,
|
|
49
53
|
siren: string,
|
|
@@ -58,9 +62,9 @@ async function getMandatairesSociaux(
|
|
|
58
62
|
CertificationDirigeantDataSource.enum[
|
|
59
63
|
"registre-national-entreprises.inpi.fr/api"
|
|
60
64
|
],
|
|
65
|
+
source_selection: { kind: "preferred" } satisfies SourceSelection,
|
|
61
66
|
};
|
|
62
|
-
} catch (
|
|
63
|
-
console.error(error);
|
|
67
|
+
} catch (exception) {
|
|
64
68
|
const mandataires =
|
|
65
69
|
await api_entreprise.findMandatairesSociauxBySiren(siren);
|
|
66
70
|
const dirigeants = mandataires.map(ApiEntreprise.toIdentityVector);
|
|
@@ -71,6 +75,10 @@ async function getMandatairesSociaux(
|
|
|
71
75
|
CertificationDirigeantDataSource.enum[
|
|
72
76
|
"entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux"
|
|
73
77
|
],
|
|
78
|
+
source_selection: {
|
|
79
|
+
exception,
|
|
80
|
+
kind: "fallback",
|
|
81
|
+
} satisfies SourceSelection,
|
|
74
82
|
};
|
|
75
83
|
}
|
|
76
84
|
}
|
|
@@ -91,6 +99,7 @@ export function processCertificationDirigeantFactory(context: Context) {
|
|
|
91
99
|
matches: new Set(),
|
|
92
100
|
identity: NullIdentityVector,
|
|
93
101
|
source: null,
|
|
102
|
+
source_selection: { kind: "preferred" } satisfies SourceSelection,
|
|
94
103
|
},
|
|
95
104
|
cause: "organisation_not_covered" as const,
|
|
96
105
|
ok: false,
|
|
@@ -110,7 +119,9 @@ export function processCertificationDirigeantFactory(context: Context) {
|
|
|
110
119
|
"registre-national-entreprises.inpi.fr/api"
|
|
111
120
|
];
|
|
112
121
|
|
|
113
|
-
const { dirigeants, source } = await match(
|
|
122
|
+
const { dirigeants, source, source_selection } = await match(
|
|
123
|
+
preferredDataSource,
|
|
124
|
+
)
|
|
114
125
|
.with("api.insee.fr/api-sirene/private", async () => ({
|
|
115
126
|
dirigeants: await insee
|
|
116
127
|
.findBySiren(siren)
|
|
@@ -120,6 +131,7 @@ export function processCertificationDirigeantFactory(context: Context) {
|
|
|
120
131
|
CertificationDirigeantDataSource.enum[
|
|
121
132
|
"api.insee.fr/api-sirene/private"
|
|
122
133
|
],
|
|
134
|
+
source_selection: { kind: "preferred" } satisfies SourceSelection,
|
|
123
135
|
}))
|
|
124
136
|
.with("registre-national-entreprises.inpi.fr/api", () =>
|
|
125
137
|
getMandatairesSociaux(context, siren),
|
|
@@ -130,7 +142,13 @@ export function processCertificationDirigeantFactory(context: Context) {
|
|
|
130
142
|
|
|
131
143
|
if (result.kind === "no_candidates") {
|
|
132
144
|
return {
|
|
133
|
-
details: {
|
|
145
|
+
details: {
|
|
146
|
+
dirigeant: undefined,
|
|
147
|
+
identity,
|
|
148
|
+
matches: new Set(),
|
|
149
|
+
source,
|
|
150
|
+
source_selection,
|
|
151
|
+
},
|
|
134
152
|
cause: result.kind,
|
|
135
153
|
ok: false,
|
|
136
154
|
};
|
|
@@ -142,6 +160,7 @@ export function processCertificationDirigeantFactory(context: Context) {
|
|
|
142
160
|
matches: result.closest.matches,
|
|
143
161
|
identity,
|
|
144
162
|
source,
|
|
163
|
+
source_selection,
|
|
145
164
|
},
|
|
146
165
|
cause: result.kind,
|
|
147
166
|
ok: result.kind === "exact_match",
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InvalidSiretError } from "#src/errors";
|
|
2
2
|
import {
|
|
3
3
|
CommunautéDeCommunes,
|
|
4
4
|
FergusMacDonaldEntrepreneur as FergusMacDonalEntrepreneurApiEntreprise,
|
|
5
5
|
RogalDornEntrepreneur,
|
|
6
6
|
} from "@proconnect-gouv/proconnect.api_entreprise/testing/seed/v3-insee-sirene-etablissements-siret";
|
|
7
|
-
import
|
|
7
|
+
import {
|
|
8
|
+
ApiEntrepriseError,
|
|
9
|
+
type InseeSireneEstablishmentSiretResponseData,
|
|
10
|
+
} from "@proconnect-gouv/proconnect.api_entreprise/types";
|
|
8
11
|
import { FergusMacDonaldEntrepreneur as FergusMacDonaldEntrepreneurRne } from "@proconnect-gouv/proconnect.registre_national_entreprises/testing/seed";
|
|
9
12
|
import assert from "node:assert/strict";
|
|
10
13
|
import { suite, test } from "node:test";
|
|
@@ -74,7 +77,7 @@ suite("getOrganizationInfo", () => {
|
|
|
74
77
|
t.assert.snapshot(await getOrganizationInfo("94957325700019"));
|
|
75
78
|
});
|
|
76
79
|
|
|
77
|
-
test
|
|
80
|
+
test("should return not_diffusible for totally non diffusible établissement", async () => {
|
|
78
81
|
const getOrganizationInfo = getOrganizationInfoFactory(
|
|
79
82
|
{
|
|
80
83
|
findBySiren: () => Promise.reject(),
|
|
@@ -89,6 +92,74 @@ suite("getOrganizationInfo", () => {
|
|
|
89
92
|
findPouvoirsBySiren: () => Promise.reject(),
|
|
90
93
|
},
|
|
91
94
|
);
|
|
92
|
-
|
|
95
|
+
assert.deepEqual(await getOrganizationInfo("53512638700013"), {
|
|
96
|
+
kind: "not_diffusible",
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("should return invalid_siret for a malformed input", async () => {
|
|
101
|
+
const getOrganizationInfo = getOrganizationInfoFactory(
|
|
102
|
+
{
|
|
103
|
+
findBySiren: () => Promise.reject(),
|
|
104
|
+
findBySiret: () => Promise.reject(),
|
|
105
|
+
findMandatairesSociauxBySiren: () => Promise.reject(),
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
findCompanyBySiren: () => Promise.reject(),
|
|
109
|
+
findPouvoirsBySiren: () => Promise.reject(),
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
assert.deepEqual(await getOrganizationInfo("1234"), {
|
|
113
|
+
exception: new InvalidSiretError("siret or siren must be 9 or 14 digits"),
|
|
114
|
+
kind: "invalid_siret",
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("should return invalid_siret when entreprise.api.gouv.fr rejects the siret", async () => {
|
|
119
|
+
const rejection = new ApiEntrepriseError({
|
|
120
|
+
errors: [
|
|
121
|
+
{
|
|
122
|
+
code: "00302",
|
|
123
|
+
detail: "Le numéro de siret n'est pas correctement formatté",
|
|
124
|
+
title: "Entité non traitable",
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
const getOrganizationInfo = getOrganizationInfoFactory(
|
|
129
|
+
{
|
|
130
|
+
findBySiren: () => Promise.reject(),
|
|
131
|
+
findBySiret: () => Promise.reject(rejection),
|
|
132
|
+
findMandatairesSociauxBySiren: () => Promise.reject(),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
findCompanyBySiren: () => Promise.reject(),
|
|
136
|
+
findPouvoirsBySiren: () => Promise.reject(),
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
assert.deepEqual(await getOrganizationInfo("20007184300061"), {
|
|
140
|
+
exception: new InvalidSiretError("rejected by entreprise.api.gouv.fr", {
|
|
141
|
+
cause: rejection,
|
|
142
|
+
}),
|
|
143
|
+
kind: "invalid_siret",
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("should return api_entreprise_failed when entreprise.api.gouv.fr fails", async () => {
|
|
148
|
+
const exception = new Error("ECONNRESET");
|
|
149
|
+
const getOrganizationInfo = getOrganizationInfoFactory(
|
|
150
|
+
{
|
|
151
|
+
findBySiren: () => Promise.reject(),
|
|
152
|
+
findBySiret: () => Promise.reject(exception),
|
|
153
|
+
findMandatairesSociauxBySiren: () => Promise.reject(),
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
findCompanyBySiren: () => Promise.reject(),
|
|
157
|
+
findPouvoirsBySiren: () => Promise.reject(),
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
assert.deepEqual(await getOrganizationInfo("20007184300060"), {
|
|
161
|
+
exception,
|
|
162
|
+
kind: "api_entreprise_failed",
|
|
163
|
+
});
|
|
93
164
|
});
|
|
94
165
|
});
|
|
@@ -1,99 +1,123 @@
|
|
|
1
1
|
exports[`getOrganizationInfo > should return valid payload for diffusible siren 1`] = `
|
|
2
2
|
{
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
"kind": "found",
|
|
4
|
+
"organization_info": {
|
|
5
|
+
"activitePrincipale": "84.11Z",
|
|
6
|
+
"adresse": "3 rue maison de vatimesnil, 27150 Etrepagny",
|
|
7
|
+
"categorieJuridique": "7346",
|
|
8
|
+
"codeOfficielGeographique": "27226",
|
|
9
|
+
"codePostal": "27150",
|
|
10
|
+
"enseigne": "",
|
|
11
|
+
"estActive": true,
|
|
12
|
+
"estDiffusible": true,
|
|
13
|
+
"etatAdministratif": "A",
|
|
14
|
+
"libelle": "Cc du vexin normand",
|
|
15
|
+
"libelleActivitePrincipale": "84.11Z - Administration publique générale",
|
|
16
|
+
"libelleCategorieJuridique": "Communauté de communes",
|
|
17
|
+
"libelleTrancheEffectif": "100 à 199 salariés, en 2022",
|
|
18
|
+
"nomComplet": "Cc du vexin normand",
|
|
19
|
+
"siegeSocial": true,
|
|
20
|
+
"siret": "20007184300060",
|
|
21
|
+
"statutDiffusion": "diffusible",
|
|
22
|
+
"trancheEffectifs": "22",
|
|
23
|
+
"trancheEffectifsUniteLegale": "22",
|
|
24
|
+
"denominationUsuelleEtablissementPrincipal": null
|
|
25
|
+
},
|
|
26
|
+
"rne": {
|
|
27
|
+
"kind": "failed"
|
|
28
|
+
}
|
|
23
29
|
}
|
|
24
30
|
`;
|
|
25
31
|
|
|
26
32
|
exports[`getOrganizationInfo > should return valid payload for diffusible siren with RNE info 1`] = `
|
|
27
33
|
{
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
"kind": "found",
|
|
35
|
+
"organization_info": {
|
|
36
|
+
"activitePrincipale": "55.20Z",
|
|
37
|
+
"adresse": "4 lieu-dit bechemoure, 87200 Saint-martin-de-jussac",
|
|
38
|
+
"categorieJuridique": "1000",
|
|
39
|
+
"codeOfficielGeographique": "87164",
|
|
40
|
+
"codePostal": "87200",
|
|
41
|
+
"enseigne": "",
|
|
42
|
+
"estActive": true,
|
|
43
|
+
"estDiffusible": true,
|
|
44
|
+
"etatAdministratif": "A",
|
|
45
|
+
"libelle": "Fergus Macdonald",
|
|
46
|
+
"libelleActivitePrincipale": "55.20Z - Hébergement touristique et autre hébergement de courte durée",
|
|
47
|
+
"libelleCategorieJuridique": "Entrepreneur individuel",
|
|
48
|
+
"libelleTrancheEffectif": "Unités non employeuses",
|
|
49
|
+
"nomComplet": "Fergus Macdonald",
|
|
50
|
+
"siegeSocial": true,
|
|
51
|
+
"siret": "84951084700015",
|
|
52
|
+
"statutDiffusion": "diffusible",
|
|
53
|
+
"trancheEffectifs": "NN",
|
|
54
|
+
"trancheEffectifsUniteLegale": "NN",
|
|
55
|
+
"denominationUsuelleEtablissementPrincipal": "FMPI"
|
|
56
|
+
},
|
|
57
|
+
"rne": {
|
|
58
|
+
"kind": "enriched"
|
|
59
|
+
}
|
|
48
60
|
}
|
|
49
61
|
`;
|
|
50
62
|
|
|
51
63
|
exports[`getOrganizationInfo > should return valid payload for diffusible siret 1`] = `
|
|
52
64
|
{
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
"kind": "found",
|
|
66
|
+
"organization_info": {
|
|
67
|
+
"activitePrincipale": "84.11Z",
|
|
68
|
+
"adresse": "3 rue maison de vatimesnil, 27150 Etrepagny",
|
|
69
|
+
"categorieJuridique": "7346",
|
|
70
|
+
"codeOfficielGeographique": "27226",
|
|
71
|
+
"codePostal": "27150",
|
|
72
|
+
"enseigne": "",
|
|
73
|
+
"estActive": true,
|
|
74
|
+
"estDiffusible": true,
|
|
75
|
+
"etatAdministratif": "A",
|
|
76
|
+
"libelle": "Cc du vexin normand",
|
|
77
|
+
"libelleActivitePrincipale": "84.11Z - Administration publique générale",
|
|
78
|
+
"libelleCategorieJuridique": "Communauté de communes",
|
|
79
|
+
"libelleTrancheEffectif": "100 à 199 salariés, en 2022",
|
|
80
|
+
"nomComplet": "Cc du vexin normand",
|
|
81
|
+
"siegeSocial": true,
|
|
82
|
+
"siret": "20007184300060",
|
|
83
|
+
"statutDiffusion": "diffusible",
|
|
84
|
+
"trancheEffectifs": "22",
|
|
85
|
+
"trancheEffectifsUniteLegale": "22",
|
|
86
|
+
"denominationUsuelleEtablissementPrincipal": null
|
|
87
|
+
},
|
|
88
|
+
"rne": {
|
|
89
|
+
"kind": "failed"
|
|
90
|
+
}
|
|
73
91
|
}
|
|
74
92
|
`;
|
|
75
93
|
|
|
76
94
|
exports[`getOrganizationInfo > should show partial data for partially non diffusible établissement 1`] = `
|
|
77
95
|
{
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
"kind": "found",
|
|
97
|
+
"organization_info": {
|
|
98
|
+
"activitePrincipale": "62.02A",
|
|
99
|
+
"adresse": "06155 Vallauris",
|
|
100
|
+
"categorieJuridique": "1000",
|
|
101
|
+
"codeOfficielGeographique": "06155",
|
|
102
|
+
"codePostal": "06155",
|
|
103
|
+
"enseigne": "",
|
|
104
|
+
"estActive": true,
|
|
105
|
+
"estDiffusible": false,
|
|
106
|
+
"etatAdministratif": "A",
|
|
107
|
+
"libelle": "Nom inconnu",
|
|
108
|
+
"libelleActivitePrincipale": "62.02A - Conseil en systèmes et logiciels informatiques",
|
|
109
|
+
"libelleCategorieJuridique": "Entrepreneur individuel",
|
|
110
|
+
"libelleTrancheEffectif": "",
|
|
111
|
+
"nomComplet": "Nom inconnu",
|
|
112
|
+
"siegeSocial": true,
|
|
113
|
+
"siret": "94957325700019",
|
|
114
|
+
"statutDiffusion": "partiellement_diffusible",
|
|
115
|
+
"trancheEffectifs": null,
|
|
116
|
+
"trancheEffectifsUniteLegale": null,
|
|
117
|
+
"denominationUsuelleEtablissementPrincipal": null
|
|
118
|
+
},
|
|
119
|
+
"rne": {
|
|
120
|
+
"kind": "failed"
|
|
121
|
+
}
|
|
98
122
|
}
|
|
99
123
|
`;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
-
import { InvalidSiretError
|
|
4
|
-
import {
|
|
5
|
-
type ApiEntrepriseOrganizationInfo,
|
|
6
|
-
type ApiRneOrganizationInfo,
|
|
7
|
-
type OrganizationInfo,
|
|
8
|
-
} from "#src/types";
|
|
3
|
+
import { InvalidSiretError } from "#src/errors";
|
|
4
|
+
import { type OrganizationInfo } from "#src/types";
|
|
9
5
|
import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entreprise/api";
|
|
10
6
|
import {
|
|
11
|
-
ApiEntrepriseConnectionError,
|
|
12
7
|
ApiEntrepriseInvalidSiret,
|
|
8
|
+
type InseeSireneEstablishmentSiretResponseData,
|
|
13
9
|
} from "@proconnect-gouv/proconnect.api_entreprise/types";
|
|
14
10
|
import type { ApiRegistreNationalEntreprisesClient } from "@proconnect-gouv/proconnect.registre_national_entreprises/api";
|
|
15
11
|
import * as ApiEntreprise from "./adapters/api_entreprise.js";
|
|
@@ -17,67 +13,78 @@ import * as ApiRne from "./adapters/rne.js";
|
|
|
17
13
|
|
|
18
14
|
//
|
|
19
15
|
|
|
16
|
+
export type RneEnrichment =
|
|
17
|
+
| { kind: "enriched" }
|
|
18
|
+
| { kind: "failed"; exception: unknown };
|
|
19
|
+
|
|
20
|
+
export type OrganizationInfoLookup =
|
|
21
|
+
| { kind: "api_entreprise_failed"; exception: unknown }
|
|
22
|
+
| { kind: "found"; organization_info: OrganizationInfo; rne: RneEnrichment }
|
|
23
|
+
| { kind: "invalid_siret"; exception: InvalidSiretError }
|
|
24
|
+
| { kind: "not_diffusible" };
|
|
25
|
+
|
|
20
26
|
export function getOrganizationInfoFactory(
|
|
21
27
|
apiEntrepriseClient: ApiEntrepriseClient,
|
|
22
28
|
apiRneClient: ApiRegistreNationalEntreprisesClient,
|
|
23
29
|
) {
|
|
30
|
+
async function findApiEntrepriseData(siretOrSiren: string) {
|
|
31
|
+
if (/^\d{14}$/.test(siretOrSiren))
|
|
32
|
+
return apiEntrepriseClient.findBySiret(siretOrSiren);
|
|
33
|
+
return apiEntrepriseClient.findBySiren(siretOrSiren);
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
return async function getOrganizationInfo(
|
|
25
37
|
siretOrSiren: string,
|
|
26
|
-
): Promise<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
apiEntrepriseOrganizationInfo =
|
|
34
|
-
ApiEntreprise.toApiEntrepriseOrganizationInfo(
|
|
35
|
-
await apiEntrepriseClient.findBySiret(siretOrSiren),
|
|
36
|
-
);
|
|
37
|
-
} else if (siretOrSiren.match(/^\d{9}$/)) {
|
|
38
|
-
apiEntrepriseOrganizationInfo =
|
|
39
|
-
ApiEntreprise.toApiEntrepriseOrganizationInfo(
|
|
40
|
-
await apiEntrepriseClient.findBySiren(siretOrSiren),
|
|
41
|
-
);
|
|
42
|
-
} else {
|
|
43
|
-
throw new InvalidSiretError();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const { statutDiffusion } = apiEntrepriseOrganizationInfo;
|
|
47
|
-
|
|
48
|
-
if (statutDiffusion === "non_diffusible") {
|
|
49
|
-
throw new NotFoundError();
|
|
50
|
-
}
|
|
51
|
-
organizationInfo = {
|
|
52
|
-
...apiEntrepriseOrganizationInfo,
|
|
53
|
-
denominationUsuelleEtablissementPrincipal: null,
|
|
38
|
+
): Promise<OrganizationInfoLookup> {
|
|
39
|
+
if (!/^(\d{9}|\d{14})$/.test(siretOrSiren))
|
|
40
|
+
return {
|
|
41
|
+
exception: new InvalidSiretError(
|
|
42
|
+
"siret or siren must be 9 or 14 digits",
|
|
43
|
+
),
|
|
44
|
+
kind: "invalid_siret",
|
|
54
45
|
};
|
|
55
46
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
let apiEntrepriseData: InseeSireneEstablishmentSiretResponseData;
|
|
48
|
+
try {
|
|
49
|
+
apiEntrepriseData = await findApiEntrepriseData(siretOrSiren);
|
|
50
|
+
} catch (exception) {
|
|
51
|
+
if (ApiEntrepriseInvalidSiret.isInvalidSiret(exception))
|
|
52
|
+
return {
|
|
53
|
+
exception: new InvalidSiretError(
|
|
54
|
+
"rejected by entreprise.api.gouv.fr",
|
|
55
|
+
{ cause: exception },
|
|
56
|
+
),
|
|
57
|
+
kind: "invalid_siret",
|
|
64
58
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
59
|
+
return { exception, kind: "api_entreprise_failed" };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (apiEntrepriseData.status_diffusion === "non_diffusible")
|
|
63
|
+
return { kind: "not_diffusible" };
|
|
71
64
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
const organizationInfo: OrganizationInfo = {
|
|
66
|
+
...ApiEntreprise.toApiEntrepriseOrganizationInfo(apiEntrepriseData),
|
|
67
|
+
denominationUsuelleEtablissementPrincipal: null,
|
|
68
|
+
};
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
try {
|
|
71
|
+
const apiRneData = await apiRneClient.findCompanyBySiren(
|
|
72
|
+
siretOrSiren.slice(0, 9),
|
|
80
73
|
);
|
|
74
|
+
return {
|
|
75
|
+
kind: "found",
|
|
76
|
+
organization_info: {
|
|
77
|
+
...organizationInfo,
|
|
78
|
+
...ApiRne.toApiRneOrganizationInfo(apiRneData),
|
|
79
|
+
},
|
|
80
|
+
rne: { kind: "enriched" },
|
|
81
|
+
};
|
|
82
|
+
} catch (exception) {
|
|
83
|
+
return {
|
|
84
|
+
kind: "found",
|
|
85
|
+
organization_info: organizationInfo,
|
|
86
|
+
rne: { exception, kind: "failed" },
|
|
87
|
+
};
|
|
81
88
|
}
|
|
82
89
|
};
|
|
83
90
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { getMemberIdsPromotedByDomain } from "#src/services/organization";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { describe, it } from "node:test";
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
describe("getMemberIdsPromotedByDomain", () => {
|
|
10
|
+
it("should promote unverified and super weak members of the domain", () => {
|
|
11
|
+
assert.deepEqual(
|
|
12
|
+
getMemberIdsPromotedByDomain({
|
|
13
|
+
domain: "darkangels.world",
|
|
14
|
+
members: [
|
|
15
|
+
{
|
|
16
|
+
email: "lion.eljonson@darkangels.world",
|
|
17
|
+
id: 1,
|
|
18
|
+
verification_type: "no_validation_means_available",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
email: "cat.eljonson@darkangels.world",
|
|
22
|
+
id: 2,
|
|
23
|
+
verification_type:
|
|
24
|
+
"no_verification_means_for_entreprise_unipersonnelle",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
email: "tiger.eljonson@darkangels.world",
|
|
28
|
+
id: 3,
|
|
29
|
+
verification_type: "no_verification_means_for_small_association",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
email: "wolf.eljonson@darkangels.world",
|
|
33
|
+
id: 4,
|
|
34
|
+
verification_type: "no_verification_means_for_small_organization",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
email: "mouse.eljonson@darkangels.world",
|
|
38
|
+
id: 5,
|
|
39
|
+
verification_type: "domain_not_verified_yet",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
}),
|
|
43
|
+
[1, 2, 3, 4, 5],
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should not promote members of another domain", () => {
|
|
48
|
+
assert.deepEqual(
|
|
49
|
+
getMemberIdsPromotedByDomain({
|
|
50
|
+
domain: "darkangels.world",
|
|
51
|
+
members: [
|
|
52
|
+
{
|
|
53
|
+
email: "foo@bar.world",
|
|
54
|
+
id: 1,
|
|
55
|
+
verification_type: "no_validation_means_available",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
email: "luther@sub.darkangels.world",
|
|
59
|
+
id: 2,
|
|
60
|
+
verification_type: "no_validation_means_available",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
}),
|
|
64
|
+
[],
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should not promote members with a verified link", () => {
|
|
69
|
+
assert.deepEqual(
|
|
70
|
+
getMemberIdsPromotedByDomain({
|
|
71
|
+
domain: "darkangels.world",
|
|
72
|
+
members: [
|
|
73
|
+
{
|
|
74
|
+
email: "lion.eljonson@darkangels.world",
|
|
75
|
+
id: 1,
|
|
76
|
+
verification_type: "organization_dirigeant",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
email: "azrael@darkangels.world",
|
|
80
|
+
id: 2,
|
|
81
|
+
verification_type: "domain",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
email: "belial@darkangels.world",
|
|
85
|
+
id: 3,
|
|
86
|
+
verification_type: "official_contact_email",
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
}),
|
|
90
|
+
[],
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should not promote anyone without members", () => {
|
|
95
|
+
assert.deepEqual(
|
|
96
|
+
getMemberIdsPromotedByDomain({ domain: "darkangels.world", members: [] }),
|
|
97
|
+
[],
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
|
|
4
|
+
import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export function getMemberIdsPromotedByDomain({
|
|
9
|
+
domain,
|
|
10
|
+
members,
|
|
11
|
+
}: {
|
|
12
|
+
domain: string;
|
|
13
|
+
members: ReadonlyArray<{
|
|
14
|
+
email: string;
|
|
15
|
+
id: number;
|
|
16
|
+
verification_type: string;
|
|
17
|
+
}>;
|
|
18
|
+
}) {
|
|
19
|
+
return members
|
|
20
|
+
.filter(
|
|
21
|
+
({ email, verification_type }) =>
|
|
22
|
+
getEmailDomain(email) === domain &&
|
|
23
|
+
(UnverifiedLinkEnum.safeParse(verification_type).success ||
|
|
24
|
+
SuperWeakLinkEnum.safeParse(verification_type).success),
|
|
25
|
+
)
|
|
26
|
+
.map(({ id }) => id);
|
|
27
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
3
|
export * from "./compute-service-public-info.js";
|
|
4
|
+
export * from "./get-member-ids-promoted-by-domain.js";
|
|
4
5
|
export * from "./is-domain-allowed-for-organization.js";
|
|
5
6
|
export * from "./is-entreprise-unipersonnelle.js";
|
|
6
7
|
export * from "./is-organization-covered-by-certification-dirigeant.js";
|