@proconnect-gouv/proconnect.identite 11.0.0 → 13.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 +25 -0
- package/dist/connectors/index.d.ts +0 -37
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +2 -4
- 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/managers/organization/index.d.ts +0 -1
- package/dist/managers/organization/index.d.ts.map +1 -1
- package/dist/managers/organization/index.js +0 -1
- package/dist/repositories/email-domain/index.d.ts +0 -3
- package/dist/repositories/email-domain/index.d.ts.map +1 -1
- package/dist/repositories/email-domain/index.js +0 -1
- package/dist/repositories/organization/index.d.ts +0 -1
- package/dist/repositories/organization/index.d.ts.map +1 -1
- package/dist/repositories/organization/index.js +0 -1
- 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/connectors/index.ts +0 -5
- 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/managers/organization/index.ts +0 -1
- package/src/repositories/email-domain/index.ts +0 -3
- package/src/repositories/organization/index.ts +0 -1
- 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/dist/managers/organization/mark-domain-as-verified.d.ts +0 -18
- package/dist/managers/organization/mark-domain-as-verified.d.ts.map +0 -1
- package/dist/managers/organization/mark-domain-as-verified.js +0 -64
- package/dist/managers/user/assign-user-verification-type-to-domain.d.ts +0 -3
- package/dist/managers/user/assign-user-verification-type-to-domain.d.ts.map +0 -1
- package/dist/managers/user/assign-user-verification-type-to-domain.js +0 -20
- package/dist/managers/user/index.d.ts +0 -2
- package/dist/managers/user/index.d.ts.map +0 -1
- package/dist/managers/user/index.js +0 -1
- package/dist/repositories/email-domain/delete-email-domains-by-verification-types.d.ts +0 -8
- package/dist/repositories/email-domain/delete-email-domains-by-verification-types.d.ts.map +0 -1
- package/dist/repositories/email-domain/delete-email-domains-by-verification-types.js +0 -19
- package/dist/repositories/organization/find-users-by-organization.d.ts +0 -34
- package/dist/repositories/organization/find-users-by-organization.d.ts.map +0 -1
- package/dist/repositories/organization/find-users-by-organization.js +0 -16
- package/src/managers/organization/mark-domain-as-verified.test.ts +0 -250
- package/src/managers/organization/mark-domain-as-verified.ts +0 -123
- package/src/managers/user/assign-user-verification-type-to-domain.test.ts +0 -105
- package/src/managers/user/assign-user-verification-type-to-domain.ts +0 -40
- package/src/managers/user/index.ts +0 -1
- package/src/repositories/email-domain/delete-email-domains-by-verification-types.test.ts +0 -49
- package/src/repositories/email-domain/delete-email-domains-by-verification-types.ts +0 -45
- package/src/repositories/organization/find-users-by-organization.test.ts +0 -51
- package/src/repositories/organization/find-users-by-organization.test.ts.snapshot +0 -35
- package/src/repositories/organization/find-users-by-organization.ts +0 -30
|
@@ -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
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
export * from "./add-domain.js";
|
|
2
|
-
export * from "./delete-email-domains-by-verification-types.js";
|
|
3
2
|
export * from "./find-email-domains-by-organization-id.js";
|
|
4
3
|
|
|
5
4
|
import type { AddDomainHandler } from "./add-domain.js";
|
|
6
|
-
import type { DeleteEmailDomainsByVerificationTypesHandler } from "./delete-email-domains-by-verification-types.js";
|
|
7
5
|
import type { FindEmailDomainsByOrganizationIdHandler } from "./find-email-domains-by-organization-id.js";
|
|
8
6
|
|
|
9
7
|
export type EmailDomainRepository = {
|
|
10
8
|
addDomain: AddDomainHandler;
|
|
11
|
-
deleteEmailDomainsByVerificationTypes: DeleteEmailDomainsByVerificationTypesHandler;
|
|
12
9
|
findEmailDomainsByOrganizationId: FindEmailDomainsByOrganizationIdHandler;
|
|
13
10
|
};
|
|
@@ -5,6 +5,5 @@ export * from "./find-by-user-id.js";
|
|
|
5
5
|
export * from "./find-by-verified-email-domain.js";
|
|
6
6
|
export * from "./find-organization-by-id.js";
|
|
7
7
|
export * from "./find-pending-by-user-id.js";
|
|
8
|
-
export * from "./find-users-by-organization.js";
|
|
9
8
|
export * from "./get-organization-by-id.js";
|
|
10
9
|
export * from "./upsert.js";
|