@proconnect-gouv/proconnect.identite 10.5.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 +25 -0
- package/dist/connectors/index.d.ts +1 -1
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +2 -2
- 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/repositories/oidc-client/index.d.ts +1 -1
- package/dist/repositories/oidc-client/index.d.ts.map +1 -1
- package/dist/repositories/oidc-client/index.js +1 -1
- package/dist/repositories/oidc-client/upsert-authorization-request.d.ts +3 -0
- package/dist/repositories/oidc-client/upsert-authorization-request.d.ts.map +1 -0
- package/dist/repositories/oidc-client/upsert-authorization-request.js +30 -0
- 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/dist/types/authorization-request.d.ts +20 -0
- package/dist/types/authorization-request.d.ts.map +1 -0
- package/dist/types/authorization-request.js +2 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/package.json +1 -1
- package/src/connectors/index.ts +2 -2
- 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/repositories/oidc-client/index.ts +1 -1
- package/src/repositories/oidc-client/upsert-authorization-request.test.ts +95 -0
- package/src/repositories/oidc-client/upsert-authorization-request.ts +50 -0
- 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/src/types/authorization-request.ts +23 -0
- package/src/types/index.ts +1 -1
- package/testing/index.ts +2 -0
- package/dist/repositories/oidc-client/add-connection.d.ts +0 -3
- package/dist/repositories/oidc-client/add-connection.d.ts.map +0 -1
- package/dist/repositories/oidc-client/add-connection.js +0 -22
- package/dist/types/connection.d.ts +0 -13
- package/dist/types/connection.d.ts.map +0 -1
- package/dist/types/connection.js +0 -2
- package/src/repositories/oidc-client/add-connection.test.ts +0 -43
- package/src/repositories/oidc-client/add-connection.ts +0 -36
- package/src/types/connection.ts +0 -15
|
@@ -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,95 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { upsertAuthorizationRequestFactory } from "./upsert-authorization-request.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const upsertAuthorizationRequest = upsertAuthorizationRequestFactory({
|
|
11
|
+
pg: pg as any,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
suite("upsertAuthorizationRequestFactory", () => {
|
|
15
|
+
before(migrate);
|
|
16
|
+
beforeEach(emptyDatabase);
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
await pg.sql`
|
|
19
|
+
INSERT INTO users
|
|
20
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
21
|
+
VALUES
|
|
22
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
23
|
+
;
|
|
24
|
+
`;
|
|
25
|
+
await pg.sql`
|
|
26
|
+
INSERT INTO oidc_clients
|
|
27
|
+
(id, client_id, client_name, client_secret, created_at, updated_at)
|
|
28
|
+
VALUES
|
|
29
|
+
(1, '⚔️', 'Dark Angels', 'secret', '4444-04-04', '4444-04-04')
|
|
30
|
+
;
|
|
31
|
+
`;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("should insert and return the authorization request", async () => {
|
|
35
|
+
const authorizationRequest = await upsertAuthorizationRequest({
|
|
36
|
+
user_id: 1,
|
|
37
|
+
oidc_client_id: 1,
|
|
38
|
+
organization_id: null,
|
|
39
|
+
sp_name: "proconnect",
|
|
40
|
+
user_ip_address: "127.0.0.1",
|
|
41
|
+
interaction_cid: "Rex5_Tq4tBqqwz0xPTJyd",
|
|
42
|
+
outcome: "succeeded",
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
assert.equal(authorizationRequest.user_id, 1);
|
|
46
|
+
assert.equal(authorizationRequest.oidc_client_id, 1);
|
|
47
|
+
assert.equal(authorizationRequest.interaction_cid, "Rex5_Tq4tBqqwz0xPTJyd");
|
|
48
|
+
assert.equal(authorizationRequest.outcome, "succeeded");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("should update the authorization request of the same interaction", async () => {
|
|
52
|
+
const request = {
|
|
53
|
+
user_id: 1,
|
|
54
|
+
oidc_client_id: 1,
|
|
55
|
+
organization_id: null,
|
|
56
|
+
sp_name: null,
|
|
57
|
+
user_ip_address: null,
|
|
58
|
+
};
|
|
59
|
+
await upsertAuthorizationRequest({
|
|
60
|
+
...request,
|
|
61
|
+
interaction_cid: "caliban",
|
|
62
|
+
outcome: null,
|
|
63
|
+
});
|
|
64
|
+
await upsertAuthorizationRequest({
|
|
65
|
+
...request,
|
|
66
|
+
interaction_cid: "fallen",
|
|
67
|
+
outcome: null,
|
|
68
|
+
});
|
|
69
|
+
await upsertAuthorizationRequest({
|
|
70
|
+
...request,
|
|
71
|
+
interaction_cid: "caliban",
|
|
72
|
+
outcome: "succeeded",
|
|
73
|
+
});
|
|
74
|
+
await upsertAuthorizationRequest({
|
|
75
|
+
...request,
|
|
76
|
+
interaction_cid: null,
|
|
77
|
+
outcome: "succeeded",
|
|
78
|
+
});
|
|
79
|
+
await upsertAuthorizationRequest({
|
|
80
|
+
...request,
|
|
81
|
+
interaction_cid: null,
|
|
82
|
+
outcome: "succeeded",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const { rows } = await pg.query(
|
|
86
|
+
"SELECT interaction_cid, outcome FROM users_oidc_clients ORDER BY id",
|
|
87
|
+
);
|
|
88
|
+
assert.deepEqual(rows, [
|
|
89
|
+
{ interaction_cid: "caliban", outcome: "succeeded" },
|
|
90
|
+
{ interaction_cid: "fallen", outcome: null },
|
|
91
|
+
{ interaction_cid: null, outcome: "succeeded" },
|
|
92
|
+
{ interaction_cid: null, outcome: "succeeded" },
|
|
93
|
+
]);
|
|
94
|
+
});
|
|
95
|
+
});
|