@proconnect-gouv/proconnect.identite 10.1.0 → 10.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/connectors/index.d.ts +38 -0
  3. package/dist/connectors/index.d.ts.map +1 -1
  4. package/dist/managers/certification/normalize.d.ts.map +1 -1
  5. package/dist/managers/certification/normalize.js +8 -20
  6. package/dist/managers/organization/adapters/api_entreprise.d.ts +2 -2
  7. package/dist/managers/organization/adapters/api_entreprise.d.ts.map +1 -1
  8. package/dist/managers/organization/adapters/api_entreprise.js +30 -27
  9. package/dist/managers/organization/adapters/index.d.ts +1 -0
  10. package/dist/managers/organization/adapters/index.d.ts.map +1 -1
  11. package/dist/managers/organization/adapters/index.js +1 -0
  12. package/dist/managers/organization/adapters/rne.d.ts +4 -0
  13. package/dist/managers/organization/adapters/rne.d.ts.map +1 -0
  14. package/dist/managers/organization/adapters/rne.js +7 -0
  15. package/dist/managers/organization/get-organization-info.d.ts +2 -1
  16. package/dist/managers/organization/get-organization-info.d.ts.map +1 -1
  17. package/dist/managers/organization/get-organization-info.js +27 -7
  18. package/dist/repositories/organization/upsert.d.ts.map +1 -1
  19. package/dist/repositories/organization/upsert.js +8 -3
  20. package/dist/types/organization-info.d.ts +8 -2
  21. package/dist/types/organization-info.d.ts.map +1 -1
  22. package/dist/types/organization-info.js +4 -1
  23. package/dist/types/organization.d.ts +1 -0
  24. package/dist/types/organization.d.ts.map +1 -1
  25. package/package.json +7 -7
  26. package/src/managers/certification/normalize.test.ts +15 -0
  27. package/src/managers/certification/normalize.ts +9 -20
  28. package/src/managers/organization/adapters/api_entreprise.test.ts +6 -6
  29. package/src/managers/organization/adapters/api_entreprise.test.ts.snapshot +4 -4
  30. package/src/managers/organization/adapters/api_entreprise.ts +41 -31
  31. package/src/managers/organization/adapters/index.ts +1 -0
  32. package/src/managers/organization/adapters/rne.ts +14 -0
  33. package/src/managers/organization/get-organization-info.test.ts +66 -19
  34. package/src/managers/organization/get-organization-info.test.ts.snapshot +31 -3
  35. package/src/managers/organization/get-organization-info.ts +44 -13
  36. package/src/repositories/organization/find-by-user-id.test.ts.snapshot +3 -0
  37. package/src/repositories/organization/find-organization-by-id.test.ts +1 -0
  38. package/src/repositories/organization/upsert.ts +9 -1
  39. package/src/repositories/organization/upset.test.ts +2 -0
  40. package/src/types/organization-info.ts +13 -2
  41. package/src/types/organization.ts +1 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @proconnect-gouv/proconnect.identite
2
2
 
3
+ ## 10.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2174](https://github.com/proconnect-gouv/proconnect-identite/pull/2174) [`bdc9f6d`](https://github.com/proconnect-gouv/proconnect-identite/commit/bdc9f6d34c80b3a5fe1bb3ad9f97212a8e913932) Thanks [@Dev-next-gen](https://github.com/Dev-next-gen)! - normalizeText retire tous les diacritiques (ñ, ã, á, ř…) et traite pareil les accents composés et décomposés
8
+ - Updated dependencies [[`4c83789`](https://github.com/proconnect-gouv/proconnect-identite/commit/4c837898d9c1e2781525aed02d7b53cc4f755f11)]:
9
+ - @proconnect-gouv/proconnect.annuaire_entreprises@3.0.4
10
+
11
+ ## 10.2.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#2082](https://github.com/proconnect-gouv/proconnect-identite/pull/2082) [`7abdcbe`](https://github.com/proconnect-gouv/proconnect-identite/commit/7abdcbe0a863f5955f6b5f46b547d70d1d748a91) Thanks [@BenoitSerrano](https://github.com/BenoitSerrano)! - récupération de la dénomination usuelle de l'établissement dans les organization info
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [[`7abdcbe`](https://github.com/proconnect-gouv/proconnect-identite/commit/7abdcbe0a863f5955f6b5f46b547d70d1d748a91)]:
20
+ - @proconnect-gouv/proconnect.api_entreprise@2.3.0
21
+ - @proconnect-gouv/proconnect.registre_national_entreprises@4.1.0
22
+
3
23
  ## 10.1.0
4
24
 
5
25
  ### Minor Changes
@@ -316,11 +316,49 @@ export declare function createContext({ api_entreprise_client, api_insee_client,
316
316
  genre?: "1" | "2" | undefined;
317
317
  lieuDeNaissance?: string | undefined;
318
318
  codePostalNaissance?: string | undefined;
319
+ paysNaissance?: string | undefined;
319
320
  codeInseeGeographique?: string | undefined;
320
321
  codePaysNaissance?: string | undefined;
321
322
  } | undefined;
322
323
  } | undefined;
323
324
  }[]>;
325
+ findCompanyBySiren: (siren: string) => Promise<{
326
+ id?: string | undefined;
327
+ formality?: {
328
+ content?: {
329
+ personneMorale?: {
330
+ composition?: {
331
+ pouvoirs?: {
332
+ typeDePersonne?: "INDIVIDU" | "PERSONNE_MORALE" | undefined;
333
+ actif?: boolean | undefined;
334
+ individu?: {
335
+ descriptionPersonne?: {
336
+ dateDeNaissance?: string | undefined;
337
+ nom?: string | undefined;
338
+ prenoms?: string[] | undefined;
339
+ genre?: "1" | "2" | undefined;
340
+ lieuDeNaissance?: string | undefined;
341
+ codePostalNaissance?: string | undefined;
342
+ paysNaissance?: string | undefined;
343
+ codeInseeGeographique?: string | undefined;
344
+ codePaysNaissance?: string | undefined;
345
+ } | undefined;
346
+ } | undefined;
347
+ }[] | undefined;
348
+ } | undefined;
349
+ } | undefined;
350
+ personnePhysique?: {
351
+ etablissementPrincipal?: {
352
+ descriptionEtablissement?: {
353
+ nomCommercial?: string | undefined;
354
+ } | undefined;
355
+ } | undefined;
356
+ } | undefined;
357
+ } | undefined;
358
+ diffusionINSEE?: string | undefined;
359
+ } | undefined;
360
+ siren?: string | undefined;
361
+ }>;
324
362
  };
325
363
  };
326
364
  repository: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectors/index.ts"],"names":[],"mappings":"AAgEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAC5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AIf,CAAA;4CACwB,CAAC;2DAGzB,CAAA;2DAEa,CAAC;+CAEL,CAAC;mDAEC,CAAC;iDACoB,CAAA;2DACf,CAAC;+DACA,CAAC;yDAAuE,CAAC;iEAKjF,CAAC;6DAGF,CAAC;;;;;;wCAUN,CAAH;kDACG,CAAD;wDACqB,CAAC;iDAEf,CAAC;;;;;kCAKL,CAAR;;qBAA0D,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAhFpC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCADjB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkJP;AACD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/normalize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CA2CrE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAM7E"}
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/normalize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAgCrE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAM7E"}
@@ -15,29 +15,17 @@ export function normalizeText(text) {
15
15
  return "";
16
16
  // Convert to uppercase
17
17
  let normalized = text.toUpperCase();
18
- // Replace accented characters with their simple versions
19
- const accentMap = {
20
- À: "A",
21
- Â: "A",
22
- Ä: "A",
23
- Ç: "C",
24
- É: "E",
25
- È: "E",
26
- Ê: "E",
27
- Ë: "E",
28
- Î: "I",
29
- Ï: "I",
30
- Ô: "O",
31
- Ö: "O",
32
- Ù: "U",
33
- Û: "U",
34
- Ü: "U",
35
- Ÿ: "Y",
18
+ // Replace accented characters with their simple versions: decompose them
19
+ // (NFD) and drop the combining marks, so that every Latin diacritic is
20
+ // covered and precomposed and decomposed inputs normalize the same way
21
+ normalized = normalized.normalize("NFD").replace(/\p{M}/gu, "");
22
+ // Ligatures do not decompose
23
+ const ligatureMap = {
36
24
  Æ: "AE",
37
25
  Œ: "OE",
38
26
  };
39
- for (const [accented, simple] of Object.entries(accentMap)) {
40
- normalized = normalized.replaceAll(accented, simple);
27
+ for (const [ligature, simple] of Object.entries(ligatureMap)) {
28
+ normalized = normalized.replaceAll(ligature, simple);
41
29
  }
42
30
  // Replace special characters (including ' and -) with spaces
43
31
  // Keep only letters, digits, and spaces
@@ -1,7 +1,7 @@
1
1
  import "#src/types";
2
- import { type OrganizationInfo } from "#src/types";
2
+ import { type ApiEntrepriseOrganizationInfo, type OrganizationInfo } from "#src/types";
3
3
  import type { InseeSireneEstablishmentSiretResponseData } from "@proconnect-gouv/proconnect.api_entreprise/types";
4
- export declare function toOrganizationInfo(siretData: InseeSireneEstablishmentSiretResponseData): OrganizationInfo;
4
+ export declare function toApiEntrepriseOrganizationInfo(apiEntrepriseData: InseeSireneEstablishmentSiretResponseData): ApiEntrepriseOrganizationInfo;
5
5
  export declare function toPartialOrganization(organization_info: OrganizationInfo): {
6
6
  cached_activite_principale: string;
7
7
  cached_adresse: string;
@@ -1 +1 @@
1
- {"version":3,"file":"api_entreprise.d.ts","sourceRoot":"","sources":["../../../../src/managers/organization/adapters/api_entreprise.ts"],"names":[],"mappings":"AAEA,OAAO,YAAY,CAAC;AACpB,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAOpB,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,kDAAkD,CAAC;AAKlH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,yCAAyC,GACnD,gBAAgB,CA0DlB;AAED,wBAAgB,qBAAqB,CAAC,iBAAiB,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;EA8CxE"}
1
+ {"version":3,"file":"api_entreprise.d.ts","sourceRoot":"","sources":["../../../../src/managers/organization/adapters/api_entreprise.ts"],"names":[],"mappings":"AAEA,OAAO,YAAY,CAAC;AACpB,OAAO,EAEL,KAAK,6BAA6B,EAElC,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAOpB,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,kDAAkD,CAAC;AAKlH,wBAAgB,+BAA+B,CAC7C,iBAAiB,EAAE,yCAAyC,GAC3D,6BAA6B,CA+D/B;AAED,wBAAgB,qBAAqB,CAAC,iBAAiB,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;EAkDxE"}
@@ -1,51 +1,54 @@
1
1
  //
2
2
  import "#src/types";
3
- import { OrganizationInfoSchema, } from "#src/types";
3
+ import { ApiEntrepriseOrganizationInfoSchema, } from "#src/types";
4
4
  import { formatAddress, formatMainActivity, formatNomComplet, libelleFromCodeEffectif, } from "@proconnect-gouv/proconnect.api_entreprise/formatters";
5
5
  import { capitalize } from "lodash-es";
6
6
  //
7
- export function toOrganizationInfo(siretData) {
8
- const isPartiallyNonDiffusible = siretData.status_diffusion === "partiellement_diffusible";
9
- const enseigne = siretData.enseigne ?? "";
7
+ export function toApiEntrepriseOrganizationInfo(apiEntrepriseData) {
8
+ const isPartiallyNonDiffusible = apiEntrepriseData.status_diffusion === "partiellement_diffusible";
9
+ const enseigne = apiEntrepriseData.enseigne ?? "";
10
10
  const nomComplet = isPartiallyNonDiffusible
11
11
  ? "Nom inconnu"
12
12
  : formatNomComplet({
13
- denominationUniteLegale: siretData.unite_legale.personne_morale_attributs.raison_sociale ?? "",
14
- nomUniteLegale: siretData.unite_legale.personne_physique_attributs.nom_naissance,
15
- nomUsageUniteLegale: siretData.unite_legale.personne_physique_attributs.nom_usage,
16
- prenomUsuelUniteLegale: siretData.unite_legale.personne_physique_attributs.prenom_usuel,
17
- sigleUniteLegale: siretData.unite_legale.personne_morale_attributs.sigle,
13
+ denominationUniteLegale: apiEntrepriseData.unite_legale.personne_morale_attributs
14
+ .raison_sociale ?? "",
15
+ nomUniteLegale: apiEntrepriseData.unite_legale.personne_physique_attributs
16
+ .nom_naissance,
17
+ nomUsageUniteLegale: apiEntrepriseData.unite_legale.personne_physique_attributs.nom_usage,
18
+ prenomUsuelUniteLegale: apiEntrepriseData.unite_legale.personne_physique_attributs
19
+ .prenom_usuel,
20
+ sigleUniteLegale: apiEntrepriseData.unite_legale.personne_morale_attributs.sigle,
18
21
  });
19
22
  const libelle = isPartiallyNonDiffusible
20
23
  ? "Nom inconnu"
21
24
  : `${nomComplet}${enseigne ? ` - ${capitalize(enseigne)}` : ""}`;
22
25
  const trancheEffectifs = isPartiallyNonDiffusible
23
26
  ? null
24
- : siretData.tranche_effectif_salarie.code;
27
+ : apiEntrepriseData.tranche_effectif_salarie.code;
25
28
  const trancheEffectifsUniteLegale = isPartiallyNonDiffusible
26
29
  ? null
27
- : siretData.unite_legale.tranche_effectif_salarie.code;
30
+ : apiEntrepriseData.unite_legale.tranche_effectif_salarie.code;
28
31
  const codePostal = isPartiallyNonDiffusible
29
- ? siretData.adresse.code_commune
30
- : siretData.adresse.code_postal;
31
- return OrganizationInfoSchema.parse({
32
- activitePrincipale: siretData.activite_principale.code ?? "",
33
- adresse: formatAddress(siretData.adresse),
34
- categorieJuridique: siretData.unite_legale.forme_juridique.code ?? "",
35
- codeOfficielGeographique: siretData.adresse.code_commune ?? "",
32
+ ? apiEntrepriseData.adresse.code_commune
33
+ : apiEntrepriseData.adresse.code_postal;
34
+ return ApiEntrepriseOrganizationInfoSchema.parse({
35
+ activitePrincipale: apiEntrepriseData.activite_principale.code ?? "",
36
+ adresse: formatAddress(apiEntrepriseData.adresse),
37
+ categorieJuridique: apiEntrepriseData.unite_legale.forme_juridique.code ?? "",
38
+ codeOfficielGeographique: apiEntrepriseData.adresse.code_commune ?? "",
36
39
  codePostal,
37
40
  enseigne,
38
- estActive: siretData.etat_administratif === "A",
39
- estDiffusible: siretData.status_diffusion === "diffusible",
40
- etatAdministratif: siretData.unite_legale.etat_administratif,
41
+ estActive: apiEntrepriseData.etat_administratif === "A",
42
+ estDiffusible: apiEntrepriseData.status_diffusion === "diffusible",
43
+ etatAdministratif: apiEntrepriseData.unite_legale.etat_administratif,
41
44
  libelle,
42
- libelleActivitePrincipale: formatMainActivity(siretData.activite_principale),
43
- libelleCategorieJuridique: siretData.unite_legale.forme_juridique.libelle,
44
- libelleTrancheEffectif: libelleFromCodeEffectif(siretData.tranche_effectif_salarie.intitule, siretData.tranche_effectif_salarie.date_reference),
45
+ libelleActivitePrincipale: formatMainActivity(apiEntrepriseData.activite_principale),
46
+ libelleCategorieJuridique: apiEntrepriseData.unite_legale.forme_juridique.libelle,
47
+ libelleTrancheEffectif: libelleFromCodeEffectif(apiEntrepriseData.tranche_effectif_salarie.intitule, apiEntrepriseData.tranche_effectif_salarie.date_reference),
45
48
  nomComplet,
46
- siegeSocial: siretData.siege_social,
47
- siret: siretData.siret,
48
- statutDiffusion: siretData.status_diffusion,
49
+ siegeSocial: apiEntrepriseData.siege_social,
50
+ siret: apiEntrepriseData.siret,
51
+ statutDiffusion: apiEntrepriseData.status_diffusion,
49
52
  trancheEffectifs,
50
53
  trancheEffectifsUniteLegale,
51
54
  });
@@ -1,2 +1,3 @@
1
1
  export * from "./api_entreprise.js";
2
+ export * from "./rne.js";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/managers/organization/adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/managers/organization/adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC"}
@@ -1 +1,2 @@
1
1
  export * from "./api_entreprise.js";
2
+ export * from "./rne.js";
@@ -0,0 +1,4 @@
1
+ import type { ApiRneOrganizationInfo } from "#src/types";
2
+ import type { ReponseCompany } from "@proconnect-gouv/proconnect.registre_national_entreprises/types";
3
+ export declare function toApiRneOrganizationInfo(rneData: ReponseCompany | undefined): ApiRneOrganizationInfo;
4
+ //# sourceMappingURL=rne.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rne.d.ts","sourceRoot":"","sources":["../../../../src/managers/organization/adapters/rne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iEAAiE,CAAC;AAItG,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,cAAc,GAAG,SAAS,GAClC,sBAAsB,CAMxB"}
@@ -0,0 +1,7 @@
1
+ //
2
+ export function toApiRneOrganizationInfo(rneData) {
3
+ return {
4
+ denominationUsuelleEtablissementPrincipal: rneData?.formality?.content?.personnePhysique?.etablissementPrincipal
5
+ ?.descriptionEtablissement?.nomCommercial || null,
6
+ };
7
+ }
@@ -1,5 +1,6 @@
1
1
  import { type OrganizationInfo } from "#src/types";
2
2
  import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entreprise/api";
3
- export declare function getOrganizationInfoFactory(config: ApiEntrepriseClient): (siretOrSiren: string) => Promise<OrganizationInfo>;
3
+ import type { ApiRegistreNationalEntreprisesClient } from "@proconnect-gouv/proconnect.registre_national_entreprises/api";
4
+ export declare function getOrganizationInfoFactory(apiEntrepriseClient: ApiEntrepriseClient, apiRneClient: ApiRegistreNationalEntreprisesClient): (siretOrSiren: string) => Promise<OrganizationInfo>;
4
5
  export type GetOrganizationInfoHandler = ReturnType<typeof getOrganizationInfoFactory>;
5
6
  //# 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":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAS1F,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,mBAAmB,IAIlE,cAAc,MAAM,KACnB,OAAO,CAAC,gBAAgB,CAAC,CAiC7B;AAED,MAAM,MAAM,0BAA0B,GAAG,UAAU,CACjD,OAAO,0BAA0B,CAClC,CAAC"}
1
+ {"version":3,"file":"get-organization-info.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/get-organization-info.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAK1F,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AAM1H,wBAAgB,0BAA0B,CACxC,mBAAmB,EAAE,mBAAmB,EACxC,YAAY,EAAE,oCAAoC,IAGhD,cAAc,MAAM,KACnB,OAAO,CAAC,gBAAgB,CAAC,CAyD7B;AAED,MAAM,MAAM,0BAA0B,GAAG,UAAU,CACjD,OAAO,0BAA0B,CAClC,CAAC"}
@@ -3,26 +3,46 @@ import { InvalidSiretError, NotFoundError } from "#src/errors";
3
3
  import {} from "#src/types";
4
4
  import { ApiEntrepriseConnectionError, ApiEntrepriseInvalidSiret, } from "@proconnect-gouv/proconnect.api_entreprise/types";
5
5
  import * as ApiEntreprise from "./adapters/api_entreprise.js";
6
+ import * as ApiRne from "./adapters/rne.js";
6
7
  //
7
- export function getOrganizationInfoFactory(config) {
8
- const { findBySiren, findBySiret } = config;
8
+ export function getOrganizationInfoFactory(apiEntrepriseClient, apiRneClient) {
9
9
  return async function getOrganizationInfo(siretOrSiren) {
10
+ let organizationInfo;
10
11
  try {
11
- let establishment;
12
+ let apiEntrepriseOrganizationInfo;
13
+ let apiRneOrganizationInfo;
12
14
  if (siretOrSiren.match(/^\d{14}$/)) {
13
- establishment = ApiEntreprise.toOrganizationInfo(await findBySiret(siretOrSiren));
15
+ apiEntrepriseOrganizationInfo =
16
+ ApiEntreprise.toApiEntrepriseOrganizationInfo(await apiEntrepriseClient.findBySiret(siretOrSiren));
14
17
  }
15
18
  else if (siretOrSiren.match(/^\d{9}$/)) {
16
- establishment = ApiEntreprise.toOrganizationInfo(await findBySiren(siretOrSiren));
19
+ apiEntrepriseOrganizationInfo =
20
+ ApiEntreprise.toApiEntrepriseOrganizationInfo(await apiEntrepriseClient.findBySiren(siretOrSiren));
17
21
  }
18
22
  else {
19
23
  throw new InvalidSiretError();
20
24
  }
21
- const { statutDiffusion } = establishment;
25
+ const { statutDiffusion } = apiEntrepriseOrganizationInfo;
22
26
  if (statutDiffusion === "non_diffusible") {
23
27
  throw new NotFoundError();
24
28
  }
25
- return establishment;
29
+ organizationInfo = {
30
+ ...apiEntrepriseOrganizationInfo,
31
+ denominationUsuelleEtablissementPrincipal: null,
32
+ };
33
+ const siren = siretOrSiren.length === 14 ? siretOrSiren.slice(0, 9) : siretOrSiren;
34
+ try {
35
+ const apiRneData = await apiRneClient.findCompanyBySiren(siren);
36
+ apiRneOrganizationInfo = ApiRne.toApiRneOrganizationInfo(apiRneData);
37
+ organizationInfo = {
38
+ ...organizationInfo,
39
+ ...apiRneOrganizationInfo,
40
+ };
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;
26
46
  }
27
47
  catch (e) {
28
48
  if (ApiEntrepriseInvalidSiret.isInvalidSiret(e))
@@ -1 +1 @@
1
- {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/upsert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAKpB,wBAAgB,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,8BAG1B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,gBAAgB,CAAC;CACpC,2BAgIF;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
1
+ {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/upsert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAKpB,wBAAgB,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,8BAG1B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,gBAAgB,CAAC;CACpC,2BAqIF;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
@@ -2,7 +2,7 @@
2
2
  //
3
3
  export function upsertFactory({ pg }) {
4
4
  return async function upsert({ siret, organizationInfo, }) {
5
- const { cached_libelle, cached_nom_complet, cached_enseigne, cached_tranche_effectifs, cached_tranche_effectifs_unite_legale, cached_libelle_tranche_effectif, cached_etat_administratif, cached_est_active, cached_statut_diffusion, cached_est_diffusible, cached_adresse, cached_code_postal, cached_code_officiel_geographique, cached_activite_principale, cached_libelle_activite_principale, cached_categorie_juridique, cached_libelle_categorie_juridique, cached_siege_social, } = toPartialOrganization(organizationInfo);
5
+ const { cached_libelle, cached_nom_complet, cached_enseigne, cached_tranche_effectifs, cached_tranche_effectifs_unite_legale, cached_libelle_tranche_effectif, cached_etat_administratif, cached_est_active, cached_statut_diffusion, cached_est_diffusible, cached_adresse, cached_code_postal, cached_code_officiel_geographique, cached_activite_principale, cached_libelle_activite_principale, cached_categorie_juridique, cached_libelle_categorie_juridique, cached_siege_social, cached_denomination_usuelle_etablissement_principal, } = toPartialOrganization(organizationInfo);
6
6
  const { rows } = await pg.query(`
7
7
  INSERT INTO organizations
8
8
  (
@@ -25,12 +25,13 @@ export function upsertFactory({ pg }) {
25
25
  cached_categorie_juridique,
26
26
  cached_libelle_categorie_juridique,
27
27
  cached_siege_social,
28
+ cached_denomination_usuelle_etablissement_principal,
28
29
  organization_info_fetched_at,
29
30
  updated_at,
30
31
  created_at
31
32
  )
32
33
  VALUES
33
- ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)
34
+ ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)
34
35
  ON CONFLICT (siret)
35
36
  DO UPDATE
36
37
  SET (
@@ -53,6 +54,7 @@ export function upsertFactory({ pg }) {
53
54
  cached_categorie_juridique,
54
55
  cached_libelle_categorie_juridique,
55
56
  cached_siege_social,
57
+ cached_denomination_usuelle_etablissement_principal,
56
58
  organization_info_fetched_at,
57
59
  updated_at
58
60
  ) = (
@@ -75,6 +77,7 @@ export function upsertFactory({ pg }) {
75
77
  EXCLUDED.cached_categorie_juridique,
76
78
  EXCLUDED.cached_libelle_categorie_juridique,
77
79
  EXCLUDED.cached_siege_social,
80
+ EXCLUDED.cached_denomination_usuelle_etablissement_principal,
78
81
  EXCLUDED.organization_info_fetched_at,
79
82
  EXCLUDED.updated_at
80
83
  )
@@ -99,6 +102,7 @@ export function upsertFactory({ pg }) {
99
102
  cached_categorie_juridique,
100
103
  cached_libelle_categorie_juridique,
101
104
  cached_siege_social,
105
+ cached_denomination_usuelle_etablissement_principal,
102
106
  new Date(),
103
107
  new Date(),
104
108
  new Date(),
@@ -108,7 +112,7 @@ export function upsertFactory({ pg }) {
108
112
  }
109
113
  //
110
114
  function toPartialOrganization(organization_info) {
111
- const { activitePrincipale: cached_activite_principale, adresse: cached_adresse, categorieJuridique: cached_categorie_juridique, codeOfficielGeographique: cached_code_officiel_geographique, codePostal: cached_code_postal, enseigne: cached_enseigne, estActive: cached_est_active, estDiffusible: cached_est_diffusible, etatAdministratif: cached_etat_administratif, libelle: cached_libelle, libelleActivitePrincipale: cached_libelle_activite_principale, libelleCategorieJuridique: cached_libelle_categorie_juridique, libelleTrancheEffectif: cached_libelle_tranche_effectif, nomComplet: cached_nom_complet, siegeSocial: cached_siege_social, siret, statutDiffusion: cached_statut_diffusion, trancheEffectifs: cached_tranche_effectifs, trancheEffectifsUniteLegale: cached_tranche_effectifs_unite_legale, } = organization_info;
115
+ const { activitePrincipale: cached_activite_principale, adresse: cached_adresse, categorieJuridique: cached_categorie_juridique, codeOfficielGeographique: cached_code_officiel_geographique, codePostal: cached_code_postal, denominationUsuelleEtablissementPrincipal: cached_denomination_usuelle_etablissement_principal, enseigne: cached_enseigne, estActive: cached_est_active, estDiffusible: cached_est_diffusible, etatAdministratif: cached_etat_administratif, libelle: cached_libelle, libelleActivitePrincipale: cached_libelle_activite_principale, libelleCategorieJuridique: cached_libelle_categorie_juridique, libelleTrancheEffectif: cached_libelle_tranche_effectif, nomComplet: cached_nom_complet, siegeSocial: cached_siege_social, siret, statutDiffusion: cached_statut_diffusion, trancheEffectifs: cached_tranche_effectifs, trancheEffectifsUniteLegale: cached_tranche_effectifs_unite_legale, } = organization_info;
112
116
  return {
113
117
  cached_activite_principale,
114
118
  cached_adresse,
@@ -125,6 +129,7 @@ function toPartialOrganization(organization_info) {
125
129
  cached_libelle,
126
130
  cached_nom_complet,
127
131
  cached_siege_social,
132
+ cached_denomination_usuelle_etablissement_principal,
128
133
  cached_statut_diffusion,
129
134
  cached_tranche_effectifs_unite_legale,
130
135
  cached_tranche_effectifs,
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import type { TrancheEffectifs } from "./organization.js";
3
- export declare const OrganizationInfoSchema: z.ZodObject<{
3
+ export declare const ApiEntrepriseOrganizationInfoSchema: z.ZodObject<{
4
4
  activitePrincipale: z.ZodString;
5
5
  adresse: z.ZodString;
6
6
  categorieJuridique: z.ZodString;
@@ -25,5 +25,11 @@ export declare const OrganizationInfoSchema: z.ZodObject<{
25
25
  trancheEffectifs: z.ZodNullable<z.ZodCustom<TrancheEffectifs, TrancheEffectifs>>;
26
26
  trancheEffectifsUniteLegale: z.ZodNullable<z.ZodString>;
27
27
  }, z.core.$strip>;
28
- export type OrganizationInfo = z.output<typeof OrganizationInfoSchema>;
28
+ declare const ApiRneOrganizationInfoSchema: z.ZodObject<{
29
+ denominationUsuelleEtablissementPrincipal: z.ZodNullable<z.ZodString>;
30
+ }, z.core.$strip>;
31
+ export type ApiEntrepriseOrganizationInfo = z.output<typeof ApiEntrepriseOrganizationInfoSchema>;
32
+ export type ApiRneOrganizationInfo = z.output<typeof ApiRneOrganizationInfoSchema>;
33
+ export type OrganizationInfo = ApiEntrepriseOrganizationInfo & ApiRneOrganizationInfo;
34
+ export {};
29
35
  //# sourceMappingURL=organization-info.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"organization-info.d.ts","sourceRoot":"","sources":["../../src/types/organization-info.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAI1D,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;iBAwBjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
1
+ {"version":3,"file":"organization-info.d.ts","sourceRoot":"","sources":["../../src/types/organization-info.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAI1D,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;;;;;;iBAwB9C,CAAC;AAEH,QAAA,MAAM,4BAA4B;;iBAEhC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAClD,OAAO,mCAAmC,CAC3C,CAAC;AACF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAC3C,OAAO,4BAA4B,CACpC,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,6BAA6B,GAC1D,sBAAsB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  //
2
2
  import { z } from "zod";
3
3
  //
4
- export const OrganizationInfoSchema = z.object({
4
+ export const ApiEntrepriseOrganizationInfoSchema = z.object({
5
5
  activitePrincipale: z.string(),
6
6
  adresse: z.string(),
7
7
  categorieJuridique: z.string(),
@@ -26,3 +26,6 @@ export const OrganizationInfoSchema = z.object({
26
26
  trancheEffectifs: z.custom().nullable(),
27
27
  trancheEffectifsUniteLegale: z.string().nullable(),
28
28
  });
29
+ const ApiRneOrganizationInfoSchema = z.object({
30
+ denominationUsuelleEtablissementPrincipal: z.string().nullable(),
31
+ });
@@ -22,6 +22,7 @@ export interface Organization {
22
22
  cached_categorie_juridique: string | null;
23
23
  cached_libelle_categorie_juridique: string | null;
24
24
  cached_siege_social: boolean | null;
25
+ cached_denomination_usuelle_etablissement_principal: string | null;
25
26
  organization_info_fetched_at: Date | null;
26
27
  }
27
28
  //# sourceMappingURL=organization.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"organization.d.ts","sourceRoot":"","sources":["../../src/types/organization.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GACxB,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI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AAI,GAAG,IAAI,CAAC;CAC3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proconnect-gouv/proconnect.identite",
3
- "version": "10.1.0",
3
+ "version": "10.2.1",
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": {
@@ -51,12 +51,12 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "@electric-sql/pglite": "^0.3.12",
54
- "@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.2",
55
- "@proconnect-gouv/proconnect.api_entreprise": "^2.2.0",
54
+ "@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.4",
55
+ "@proconnect-gouv/proconnect.api_entreprise": "^2.3.0",
56
56
  "@proconnect-gouv/proconnect.core": "^1.0.0",
57
57
  "@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
58
58
  "@proconnect-gouv/proconnect.insee": "^2.0.0",
59
- "@proconnect-gouv/proconnect.registre_national_entreprises": "^4.0.0",
59
+ "@proconnect-gouv/proconnect.registre_national_entreprises": "^4.1.0",
60
60
  "@types/node": "^22.18.6",
61
61
  "@types/pg": "^8.15.5",
62
62
  "await-to-js": "^3.0.0",
@@ -65,11 +65,11 @@
65
65
  "tsx": "^4.20.3"
66
66
  },
67
67
  "peerDependencies": {
68
- "@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.2",
69
- "@proconnect-gouv/proconnect.api_entreprise": "^2.2.0",
68
+ "@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.4",
69
+ "@proconnect-gouv/proconnect.api_entreprise": "^2.3.0",
70
70
  "@proconnect-gouv/proconnect.core": "^1.0.0",
71
71
  "@proconnect-gouv/proconnect.insee": "^2.0.0",
72
- "@proconnect-gouv/proconnect.registre_national_entreprises": "^4.0.0"
72
+ "@proconnect-gouv/proconnect.registre_national_entreprises": "^4.1.0"
73
73
  },
74
74
  "peerDependenciesMeta": {
75
75
  "@proconnect-gouv/proconnect.annuaire_entreprises": {
@@ -17,6 +17,17 @@ describe("normalizeText", () => {
17
17
  assert.equal(normalizeText("Hélène"), "HELENE");
18
18
  });
19
19
 
20
+ it("removes diacritics outside the French alphabet", () => {
21
+ assert.equal(normalizeText("Muñoz"), "MUNOZ");
22
+ assert.equal(normalizeText("João"), "JOAO");
23
+ assert.equal(normalizeText("Ángel Íñigo"), "ANGEL INIGO");
24
+ assert.equal(normalizeText("Dvořák"), "DVORAK");
25
+ });
26
+
27
+ it("normalizes decomposed and precomposed accents the same way", () => {
28
+ assert.equal(normalizeText("He\u0301le\u0300ne"), "HELENE");
29
+ });
30
+
20
31
  it("replaces special characters with spaces", () => {
21
32
  assert.equal(normalizeText("Jean-Pierre"), "JEAN PIERRE");
22
33
  assert.equal(normalizeText("O'Connor"), "O CONNOR");
@@ -60,6 +71,10 @@ describe("extractFirstName", () => {
60
71
  assert.equal(extractFirstName("Marie-Thérèse"), "MARIE");
61
72
  });
62
73
 
74
+ it("keeps the whole first name when it has a non-French diacritic", () => {
75
+ assert.equal(extractFirstName("João Pedro"), "JOAO");
76
+ });
77
+
63
78
  it("handles single name", () => {
64
79
  assert.equal(extractFirstName("Jean"), "JEAN");
65
80
  });
@@ -17,30 +17,19 @@ export function normalizeText(text: string | null | undefined): string {
17
17
  // Convert to uppercase
18
18
  let normalized = text.toUpperCase();
19
19
 
20
- // Replace accented characters with their simple versions
21
- const accentMap: Record<string, string> = {
22
- À: "A",
23
- Â: "A",
24
- Ä: "A",
25
- Ç: "C",
26
- É: "E",
27
- È: "E",
28
- Ê: "E",
29
- Ë: "E",
30
- Î: "I",
31
- Ï: "I",
32
- Ô: "O",
33
- Ö: "O",
34
- Ù: "U",
35
- Û: "U",
36
- Ü: "U",
37
- Ÿ: "Y",
20
+ // Replace accented characters with their simple versions: decompose them
21
+ // (NFD) and drop the combining marks, so that every Latin diacritic is
22
+ // covered and precomposed and decomposed inputs normalize the same way
23
+ normalized = normalized.normalize("NFD").replace(/\p{M}/gu, "");
24
+
25
+ // Ligatures do not decompose
26
+ const ligatureMap: Record<string, string> = {
38
27
  Æ: "AE",
39
28
  Œ: "OE",
40
29
  };
41
30
 
42
- for (const [accented, simple] of Object.entries(accentMap)) {
43
- normalized = normalized.replaceAll(accented, simple);
31
+ for (const [ligature, simple] of Object.entries(ligatureMap)) {
32
+ normalized = normalized.replaceAll(ligature, simple);
44
33
  }
45
34
 
46
35
  // Replace special characters (including ' and -) with spaces
@@ -7,25 +7,25 @@ import {
7
7
  RogalDornEntrepreneur,
8
8
  } from "@proconnect-gouv/proconnect.api_entreprise/testing/seed/v3-insee-sirene-etablissements-siret";
9
9
  import { suite, test } from "node:test";
10
- import { toOrganizationInfo } from "./api_entreprise.js";
10
+ import { toApiEntrepriseOrganizationInfo } from "./api_entreprise.js";
11
11
 
12
- suite("toOrganizationInfo", () => {
12
+ suite("toApiEntrepriseOrganizationInfo", () => {
13
13
  test("AppleEuropeInc", (t) => {
14
- const organization = toOrganizationInfo(AppleEuropeInc);
14
+ const organization = toApiEntrepriseOrganizationInfo(AppleEuropeInc);
15
15
  t.assert.snapshot(organization);
16
16
  });
17
17
 
18
18
  test("Commune de clamart - Mairie", (t) => {
19
- const organization = toOrganizationInfo(MaireClamart);
19
+ const organization = toApiEntrepriseOrganizationInfo(MaireClamart);
20
20
  t.assert.snapshot(organization);
21
21
  });
22
22
 
23
23
  test("RogalDornEntrepreneur", (t) => {
24
- const organization = toOrganizationInfo(RogalDornEntrepreneur);
24
+ const organization = toApiEntrepriseOrganizationInfo(RogalDornEntrepreneur);
25
25
  t.assert.snapshot(organization);
26
26
  });
27
27
  test("Papillon", (t) => {
28
- const organization = toOrganizationInfo(Papillon);
28
+ const organization = toApiEntrepriseOrganizationInfo(Papillon);
29
29
  t.assert.snapshot(organization);
30
30
  });
31
31
  });
@@ -1,4 +1,4 @@
1
- exports[`toOrganizationInfo > AppleEuropeInc 1`] = `
1
+ exports[`toApiEntrepriseOrganizationInfo > AppleEuropeInc 1`] = `
2
2
  {
3
3
  "activitePrincipale": "70.22Z",
4
4
  "adresse": "100 west ten wilmington delawa, 99404, ETATS-UNIS",
@@ -22,7 +22,7 @@ exports[`toOrganizationInfo > AppleEuropeInc 1`] = `
22
22
  }
23
23
  `;
24
24
 
25
- exports[`toOrganizationInfo > Commune de clamart - Mairie 1`] = `
25
+ exports[`toApiEntrepriseOrganizationInfo > Commune de clamart - Mairie 1`] = `
26
26
  {
27
27
  "activitePrincipale": "84.11Z",
28
28
  "adresse": "1 place maurice gunsbourg, 92140 Clamart",
@@ -46,7 +46,7 @@ exports[`toOrganizationInfo > Commune de clamart - Mairie 1`] = `
46
46
  }
47
47
  `;
48
48
 
49
- exports[`toOrganizationInfo > Papillon 1`] = `
49
+ exports[`toApiEntrepriseOrganizationInfo > Papillon 1`] = `
50
50
  {
51
51
  "activitePrincipale": "47.59A",
52
52
  "adresse": "5-7, 5 rue du moulin aux moines, 72650 La chapelle-saint-aubin",
@@ -70,7 +70,7 @@ exports[`toOrganizationInfo > Papillon 1`] = `
70
70
  }
71
71
  `;
72
72
 
73
- exports[`toOrganizationInfo > RogalDornEntrepreneur 1`] = `
73
+ exports[`toApiEntrepriseOrganizationInfo > RogalDornEntrepreneur 1`] = `
74
74
  {
75
75
  "activitePrincipale": "62.02A",
76
76
  "adresse": "06155 Vallauris",
@@ -2,7 +2,8 @@
2
2
 
3
3
  import "#src/types";
4
4
  import {
5
- OrganizationInfoSchema,
5
+ ApiEntrepriseOrganizationInfoSchema,
6
+ type ApiEntrepriseOrganizationInfo,
6
7
  type Organization,
7
8
  type OrganizationInfo,
8
9
  } from "#src/types";
@@ -17,25 +18,28 @@ import { capitalize } from "lodash-es";
17
18
 
18
19
  //
19
20
 
20
- export function toOrganizationInfo(
21
- siretData: InseeSireneEstablishmentSiretResponseData,
22
- ): OrganizationInfo {
21
+ export function toApiEntrepriseOrganizationInfo(
22
+ apiEntrepriseData: InseeSireneEstablishmentSiretResponseData,
23
+ ): ApiEntrepriseOrganizationInfo {
23
24
  const isPartiallyNonDiffusible =
24
- siretData.status_diffusion === "partiellement_diffusible";
25
- const enseigne = siretData.enseigne ?? "";
25
+ apiEntrepriseData.status_diffusion === "partiellement_diffusible";
26
+ const enseigne = apiEntrepriseData.enseigne ?? "";
26
27
  const nomComplet = isPartiallyNonDiffusible
27
28
  ? "Nom inconnu"
28
29
  : formatNomComplet({
29
30
  denominationUniteLegale:
30
- siretData.unite_legale.personne_morale_attributs.raison_sociale ?? "",
31
+ apiEntrepriseData.unite_legale.personne_morale_attributs
32
+ .raison_sociale ?? "",
31
33
  nomUniteLegale:
32
- siretData.unite_legale.personne_physique_attributs.nom_naissance,
34
+ apiEntrepriseData.unite_legale.personne_physique_attributs
35
+ .nom_naissance,
33
36
  nomUsageUniteLegale:
34
- siretData.unite_legale.personne_physique_attributs.nom_usage,
37
+ apiEntrepriseData.unite_legale.personne_physique_attributs.nom_usage,
35
38
  prenomUsuelUniteLegale:
36
- siretData.unite_legale.personne_physique_attributs.prenom_usuel,
39
+ apiEntrepriseData.unite_legale.personne_physique_attributs
40
+ .prenom_usuel,
37
41
  sigleUniteLegale:
38
- siretData.unite_legale.personne_morale_attributs.sigle,
42
+ apiEntrepriseData.unite_legale.personne_morale_attributs.sigle,
39
43
  });
40
44
  const libelle = isPartiallyNonDiffusible
41
45
  ? "Nom inconnu"
@@ -43,37 +47,39 @@ export function toOrganizationInfo(
43
47
 
44
48
  const trancheEffectifs = isPartiallyNonDiffusible
45
49
  ? null
46
- : siretData.tranche_effectif_salarie.code;
50
+ : apiEntrepriseData.tranche_effectif_salarie.code;
47
51
  const trancheEffectifsUniteLegale = isPartiallyNonDiffusible
48
52
  ? null
49
- : siretData.unite_legale.tranche_effectif_salarie.code;
53
+ : apiEntrepriseData.unite_legale.tranche_effectif_salarie.code;
50
54
  const codePostal = isPartiallyNonDiffusible
51
- ? siretData.adresse.code_commune
52
- : siretData.adresse.code_postal;
55
+ ? apiEntrepriseData.adresse.code_commune
56
+ : apiEntrepriseData.adresse.code_postal;
53
57
 
54
- return OrganizationInfoSchema.parse({
55
- activitePrincipale: siretData.activite_principale.code ?? "",
56
- adresse: formatAddress(siretData.adresse),
57
- categorieJuridique: siretData.unite_legale.forme_juridique.code ?? "",
58
- codeOfficielGeographique: siretData.adresse.code_commune ?? "",
58
+ return ApiEntrepriseOrganizationInfoSchema.parse({
59
+ activitePrincipale: apiEntrepriseData.activite_principale.code ?? "",
60
+ adresse: formatAddress(apiEntrepriseData.adresse),
61
+ categorieJuridique:
62
+ apiEntrepriseData.unite_legale.forme_juridique.code ?? "",
63
+ codeOfficielGeographique: apiEntrepriseData.adresse.code_commune ?? "",
59
64
  codePostal,
60
65
  enseigne,
61
- estActive: siretData.etat_administratif === "A",
62
- estDiffusible: siretData.status_diffusion === "diffusible",
63
- etatAdministratif: siretData.unite_legale.etat_administratif,
66
+ estActive: apiEntrepriseData.etat_administratif === "A",
67
+ estDiffusible: apiEntrepriseData.status_diffusion === "diffusible",
68
+ etatAdministratif: apiEntrepriseData.unite_legale.etat_administratif,
64
69
  libelle,
65
70
  libelleActivitePrincipale: formatMainActivity(
66
- siretData.activite_principale,
71
+ apiEntrepriseData.activite_principale,
67
72
  ),
68
- libelleCategorieJuridique: siretData.unite_legale.forme_juridique.libelle,
73
+ libelleCategorieJuridique:
74
+ apiEntrepriseData.unite_legale.forme_juridique.libelle,
69
75
  libelleTrancheEffectif: libelleFromCodeEffectif(
70
- siretData.tranche_effectif_salarie.intitule,
71
- siretData.tranche_effectif_salarie.date_reference,
76
+ apiEntrepriseData.tranche_effectif_salarie.intitule,
77
+ apiEntrepriseData.tranche_effectif_salarie.date_reference,
72
78
  ),
73
79
  nomComplet,
74
- siegeSocial: siretData.siege_social,
75
- siret: siretData.siret,
76
- statutDiffusion: siretData.status_diffusion,
80
+ siegeSocial: apiEntrepriseData.siege_social,
81
+ siret: apiEntrepriseData.siret,
82
+ statutDiffusion: apiEntrepriseData.status_diffusion,
77
83
  trancheEffectifs,
78
84
  trancheEffectifsUniteLegale,
79
85
  });
@@ -123,6 +129,10 @@ export function toPartialOrganization(organization_info: OrganizationInfo) {
123
129
  siret,
124
130
  } satisfies Omit<
125
131
  Organization,
126
- "created_at" | "id" | "updated_at" | "organization_info_fetched_at"
132
+ | "created_at"
133
+ | "id"
134
+ | "updated_at"
135
+ | "organization_info_fetched_at"
136
+ | "cached_denomination_usuelle_etablissement_principal"
127
137
  >;
128
138
  }
@@ -1 +1,2 @@
1
1
  export * from "./api_entreprise.js";
2
+ export * from "./rne.js";
@@ -0,0 +1,14 @@
1
+ import type { ApiRneOrganizationInfo } from "#src/types";
2
+ import type { ReponseCompany } from "@proconnect-gouv/proconnect.registre_national_entreprises/types";
3
+
4
+ //
5
+
6
+ export function toApiRneOrganizationInfo(
7
+ rneData: ReponseCompany | undefined,
8
+ ): ApiRneOrganizationInfo {
9
+ return {
10
+ denominationUsuelleEtablissementPrincipal:
11
+ rneData?.formality?.content?.personnePhysique?.etablissementPrincipal
12
+ ?.descriptionEtablissement?.nomCommercial || null,
13
+ };
14
+ }
@@ -1,47 +1,94 @@
1
1
  import { NotFoundError } from "#src/errors";
2
2
  import {
3
3
  CommunautéDeCommunes,
4
+ FergusMacDonaldEntrepreneur as FergusMacDonalEntrepreneurApiEntreprise,
4
5
  RogalDornEntrepreneur,
5
6
  } from "@proconnect-gouv/proconnect.api_entreprise/testing/seed/v3-insee-sirene-etablissements-siret";
6
7
  import type { InseeSireneEstablishmentSiretResponseData } from "@proconnect-gouv/proconnect.api_entreprise/types";
8
+ import { FergusMacDonaldEntrepreneur as FergusMacDonaldEntrepreneurRne } from "@proconnect-gouv/proconnect.registre_national_entreprises/testing/seed";
7
9
  import assert from "node:assert/strict";
8
10
  import { suite, test } from "node:test";
9
11
  import { getOrganizationInfoFactory } from "./get-organization-info.js";
10
12
 
11
13
  suite("getOrganizationInfo", () => {
12
14
  test("should return valid payload for diffusible siret", async (t) => {
13
- const getOrganizationInfo = getOrganizationInfoFactory({
14
- findBySiren: () => Promise.reject(),
15
- findBySiret: () => Promise.resolve(CommunautéDeCommunes),
16
- });
15
+ const getOrganizationInfo = getOrganizationInfoFactory(
16
+ {
17
+ findBySiren: () => Promise.reject(),
18
+ findBySiret: () => Promise.resolve(CommunautéDeCommunes),
19
+ findMandatairesSociauxBySiren: () => Promise.reject(),
20
+ },
21
+ {
22
+ findCompanyBySiren: () => Promise.reject(),
23
+ findPouvoirsBySiren: () => Promise.reject(),
24
+ },
25
+ );
17
26
  t.assert.snapshot(await getOrganizationInfo("20007184300060"));
18
27
  });
19
28
 
20
29
  test("should return valid payload for diffusible siren", async (t) => {
21
- const getOrganizationInfo = getOrganizationInfoFactory({
22
- findBySiren: () => Promise.resolve(CommunautéDeCommunes),
23
- findBySiret: () => Promise.reject(),
24
- });
30
+ const getOrganizationInfo = getOrganizationInfoFactory(
31
+ {
32
+ findBySiren: () => Promise.resolve(CommunautéDeCommunes),
33
+ findBySiret: () => Promise.reject(),
34
+ findMandatairesSociauxBySiren: () => Promise.reject(),
35
+ },
36
+ {
37
+ findCompanyBySiren: () => Promise.reject(),
38
+ findPouvoirsBySiren: () => Promise.reject(),
39
+ },
40
+ );
41
+ t.assert.snapshot(await getOrganizationInfo("200071843"));
42
+ });
43
+
44
+ test("should return valid payload for diffusible siren with RNE info", async (t) => {
45
+ const getOrganizationInfo = getOrganizationInfoFactory(
46
+ {
47
+ findBySiren: () =>
48
+ Promise.resolve(FergusMacDonalEntrepreneurApiEntreprise),
49
+ findBySiret: () => Promise.reject(),
50
+ findMandatairesSociauxBySiren: () => Promise.reject(),
51
+ },
52
+ {
53
+ findCompanyBySiren: () =>
54
+ Promise.resolve(FergusMacDonaldEntrepreneurRne),
55
+ findPouvoirsBySiren: () => Promise.reject(),
56
+ },
57
+ );
25
58
  t.assert.snapshot(await getOrganizationInfo("200071843"));
26
59
  });
27
60
 
28
61
  test("should show partial data for partially non diffusible établissement", async (t) => {
29
- const getOrganizationInfo = getOrganizationInfoFactory({
30
- findBySiren: () => Promise.reject(),
31
- findBySiret: () => Promise.resolve(RogalDornEntrepreneur),
32
- });
62
+ const getOrganizationInfo = getOrganizationInfoFactory(
63
+ {
64
+ findBySiren: () => Promise.reject(),
65
+ findBySiret: () => Promise.resolve(RogalDornEntrepreneur),
66
+ findMandatairesSociauxBySiren: () => Promise.reject(),
67
+ },
68
+ {
69
+ findCompanyBySiren: () => Promise.reject(),
70
+ findPouvoirsBySiren: () => Promise.reject(),
71
+ },
72
+ );
33
73
 
34
74
  t.assert.snapshot(await getOrganizationInfo("94957325700019"));
35
75
  });
36
76
 
37
77
  test.skip("should throw for totally non diffusible établissement", async () => {
38
- const getOrganizationInfo = getOrganizationInfoFactory({
39
- findBySiren: () => Promise.reject(),
40
- findBySiret: () =>
41
- Promise.resolve({
42
- status_diffusion: "non_diffusible",
43
- } as InseeSireneEstablishmentSiretResponseData),
44
- });
78
+ const getOrganizationInfo = getOrganizationInfoFactory(
79
+ {
80
+ findBySiren: () => Promise.reject(),
81
+ findBySiret: () =>
82
+ Promise.resolve({
83
+ status_diffusion: "non_diffusible",
84
+ } as InseeSireneEstablishmentSiretResponseData),
85
+ findMandatairesSociauxBySiren: () => Promise.reject(),
86
+ },
87
+ {
88
+ findCompanyBySiren: () => Promise.reject(),
89
+ findPouvoirsBySiren: () => Promise.reject(),
90
+ },
91
+ );
45
92
  await assert.rejects(getOrganizationInfo("53512638700013"), NotFoundError);
46
93
  });
47
94
  });
@@ -18,7 +18,33 @@ exports[`getOrganizationInfo > should return valid payload for diffusible siren
18
18
  "siret": "20007184300060",
19
19
  "statutDiffusion": "diffusible",
20
20
  "trancheEffectifs": "22",
21
- "trancheEffectifsUniteLegale": "22"
21
+ "trancheEffectifsUniteLegale": "22",
22
+ "denominationUsuelleEtablissementPrincipal": null
23
+ }
24
+ `;
25
+
26
+ exports[`getOrganizationInfo > should return valid payload for diffusible siren with RNE info 1`] = `
27
+ {
28
+ "activitePrincipale": "55.20Z",
29
+ "adresse": "4 lieu-dit bechemoure, 87200 Saint-martin-de-jussac",
30
+ "categorieJuridique": "1000",
31
+ "codeOfficielGeographique": "87164",
32
+ "codePostal": "87200",
33
+ "enseigne": "",
34
+ "estActive": true,
35
+ "estDiffusible": true,
36
+ "etatAdministratif": "A",
37
+ "libelle": "Fergus Macdonald",
38
+ "libelleActivitePrincipale": "55.20Z - Hébergement touristique et autre hébergement de courte durée",
39
+ "libelleCategorieJuridique": "Entrepreneur individuel",
40
+ "libelleTrancheEffectif": "Unités non employeuses",
41
+ "nomComplet": "Fergus Macdonald",
42
+ "siegeSocial": true,
43
+ "siret": "84951084700015",
44
+ "statutDiffusion": "diffusible",
45
+ "trancheEffectifs": "NN",
46
+ "trancheEffectifsUniteLegale": "NN",
47
+ "denominationUsuelleEtablissementPrincipal": "FMPI"
22
48
  }
23
49
  `;
24
50
 
@@ -42,7 +68,8 @@ exports[`getOrganizationInfo > should return valid payload for diffusible siret
42
68
  "siret": "20007184300060",
43
69
  "statutDiffusion": "diffusible",
44
70
  "trancheEffectifs": "22",
45
- "trancheEffectifsUniteLegale": "22"
71
+ "trancheEffectifsUniteLegale": "22",
72
+ "denominationUsuelleEtablissementPrincipal": null
46
73
  }
47
74
  `;
48
75
 
@@ -66,6 +93,7 @@ exports[`getOrganizationInfo > should show partial data for partially non diffus
66
93
  "siret": "94957325700019",
67
94
  "statutDiffusion": "partiellement_diffusible",
68
95
  "trancheEffectifs": null,
69
- "trancheEffectifsUniteLegale": null
96
+ "trancheEffectifsUniteLegale": null,
97
+ "denominationUsuelleEtablissementPrincipal": null
70
98
  }
71
99
  `;
@@ -1,44 +1,75 @@
1
1
  //
2
2
 
3
3
  import { InvalidSiretError, NotFoundError } from "#src/errors";
4
- import { type OrganizationInfo } from "#src/types";
4
+ import {
5
+ type ApiEntrepriseOrganizationInfo,
6
+ type ApiRneOrganizationInfo,
7
+ type OrganizationInfo,
8
+ } from "#src/types";
5
9
  import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entreprise/api";
6
10
  import {
7
11
  ApiEntrepriseConnectionError,
8
12
  ApiEntrepriseInvalidSiret,
9
13
  } from "@proconnect-gouv/proconnect.api_entreprise/types";
14
+ import type { ApiRegistreNationalEntreprisesClient } from "@proconnect-gouv/proconnect.registre_national_entreprises/api";
10
15
  import * as ApiEntreprise from "./adapters/api_entreprise.js";
16
+ import * as ApiRne from "./adapters/rne.js";
11
17
 
12
18
  //
13
19
 
14
- export function getOrganizationInfoFactory(config: ApiEntrepriseClient) {
15
- const { findBySiren, findBySiret } = config;
16
-
20
+ export function getOrganizationInfoFactory(
21
+ apiEntrepriseClient: ApiEntrepriseClient,
22
+ apiRneClient: ApiRegistreNationalEntreprisesClient,
23
+ ) {
17
24
  return async function getOrganizationInfo(
18
25
  siretOrSiren: string,
19
26
  ): Promise<OrganizationInfo> {
27
+ let organizationInfo: OrganizationInfo;
20
28
  try {
21
- let establishment: OrganizationInfo;
29
+ let apiEntrepriseOrganizationInfo: ApiEntrepriseOrganizationInfo;
30
+ let apiRneOrganizationInfo: ApiRneOrganizationInfo;
22
31
 
23
32
  if (siretOrSiren.match(/^\d{14}$/)) {
24
- establishment = ApiEntreprise.toOrganizationInfo(
25
- await findBySiret(siretOrSiren),
26
- );
33
+ apiEntrepriseOrganizationInfo =
34
+ ApiEntreprise.toApiEntrepriseOrganizationInfo(
35
+ await apiEntrepriseClient.findBySiret(siretOrSiren),
36
+ );
27
37
  } else if (siretOrSiren.match(/^\d{9}$/)) {
28
- establishment = ApiEntreprise.toOrganizationInfo(
29
- await findBySiren(siretOrSiren),
30
- );
38
+ apiEntrepriseOrganizationInfo =
39
+ ApiEntreprise.toApiEntrepriseOrganizationInfo(
40
+ await apiEntrepriseClient.findBySiren(siretOrSiren),
41
+ );
31
42
  } else {
32
43
  throw new InvalidSiretError();
33
44
  }
34
45
 
35
- const { statutDiffusion } = establishment;
46
+ const { statutDiffusion } = apiEntrepriseOrganizationInfo;
36
47
 
37
48
  if (statutDiffusion === "non_diffusible") {
38
49
  throw new NotFoundError();
39
50
  }
51
+ organizationInfo = {
52
+ ...apiEntrepriseOrganizationInfo,
53
+ denominationUsuelleEtablissementPrincipal: null,
54
+ };
55
+
56
+ const siren =
57
+ siretOrSiren.length === 14 ? siretOrSiren.slice(0, 9) : siretOrSiren;
58
+ try {
59
+ const apiRneData = await apiRneClient.findCompanyBySiren(siren);
60
+ apiRneOrganizationInfo = ApiRne.toApiRneOrganizationInfo(apiRneData);
61
+ organizationInfo = {
62
+ ...organizationInfo,
63
+ ...apiRneOrganizationInfo,
64
+ };
65
+ } catch (error) {
66
+ console.error(
67
+ `RNE data will be undefined for this organization (${siren}); an error occurred while fetching it`,
68
+ error,
69
+ );
70
+ }
40
71
 
41
- return establishment;
72
+ return organizationInfo;
42
73
  } catch (e) {
43
74
  if (ApiEntrepriseInvalidSiret.isInvalidSiret(e))
44
75
  throw new InvalidSiretError();
@@ -24,6 +24,7 @@ exports[`findByUserIdFactory > should return multiple organizations when user ha
24
24
  "organization_info_fetched_at": null,
25
25
  "cached_code_officiel_geographique": null,
26
26
  "cached_siege_social": null,
27
+ "cached_denomination_usuelle_etablissement_principal": null,
27
28
  "is_external": false,
28
29
  "verification_type": "necron",
29
30
  "verified_at": null,
@@ -53,6 +54,7 @@ exports[`findByUserIdFactory > should return multiple organizations when user ha
53
54
  "organization_info_fetched_at": null,
54
55
  "cached_code_officiel_geographique": null,
55
56
  "cached_siege_social": null,
57
+ "cached_denomination_usuelle_etablissement_principal": null,
56
58
  "is_external": true,
57
59
  "verification_type": "alliance",
58
60
  "verified_at": null,
@@ -87,6 +89,7 @@ exports[`findByUserIdFactory > should return single organization when user has o
87
89
  "organization_info_fetched_at": null,
88
90
  "cached_code_officiel_geographique": null,
89
91
  "cached_siege_social": null,
92
+ "cached_denomination_usuelle_etablissement_principal": null,
90
93
  "is_external": false,
91
94
  "verification_type": "imperial",
92
95
  "verified_at": null,
@@ -42,6 +42,7 @@ suite("findOrganizationByIdFactory", () => {
42
42
  cached_statut_diffusion: null,
43
43
  cached_tranche_effectifs_unite_legale: null,
44
44
  cached_tranche_effectifs: null,
45
+ cached_denomination_usuelle_etablissement_principal: null,
45
46
  created_at: new Date("1967-12-19"),
46
47
  organization_info_fetched_at: null,
47
48
  id: 1,
@@ -36,6 +36,7 @@ export function upsertFactory({ pg }: DatabaseContext) {
36
36
  cached_categorie_juridique,
37
37
  cached_libelle_categorie_juridique,
38
38
  cached_siege_social,
39
+ cached_denomination_usuelle_etablissement_principal,
39
40
  } = toPartialOrganization(organizationInfo);
40
41
 
41
42
  const { rows }: QueryResult<Organization> = await pg.query(
@@ -61,12 +62,13 @@ export function upsertFactory({ pg }: DatabaseContext) {
61
62
  cached_categorie_juridique,
62
63
  cached_libelle_categorie_juridique,
63
64
  cached_siege_social,
65
+ cached_denomination_usuelle_etablissement_principal,
64
66
  organization_info_fetched_at,
65
67
  updated_at,
66
68
  created_at
67
69
  )
68
70
  VALUES
69
- ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)
71
+ ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)
70
72
  ON CONFLICT (siret)
71
73
  DO UPDATE
72
74
  SET (
@@ -89,6 +91,7 @@ export function upsertFactory({ pg }: DatabaseContext) {
89
91
  cached_categorie_juridique,
90
92
  cached_libelle_categorie_juridique,
91
93
  cached_siege_social,
94
+ cached_denomination_usuelle_etablissement_principal,
92
95
  organization_info_fetched_at,
93
96
  updated_at
94
97
  ) = (
@@ -111,6 +114,7 @@ export function upsertFactory({ pg }: DatabaseContext) {
111
114
  EXCLUDED.cached_categorie_juridique,
112
115
  EXCLUDED.cached_libelle_categorie_juridique,
113
116
  EXCLUDED.cached_siege_social,
117
+ EXCLUDED.cached_denomination_usuelle_etablissement_principal,
114
118
  EXCLUDED.organization_info_fetched_at,
115
119
  EXCLUDED.updated_at
116
120
  )
@@ -136,6 +140,7 @@ export function upsertFactory({ pg }: DatabaseContext) {
136
140
  cached_categorie_juridique,
137
141
  cached_libelle_categorie_juridique,
138
142
  cached_siege_social,
143
+ cached_denomination_usuelle_etablissement_principal,
139
144
  new Date(),
140
145
  new Date(),
141
146
  new Date(),
@@ -157,6 +162,8 @@ function toPartialOrganization(organization_info: OrganizationInfo) {
157
162
  categorieJuridique: cached_categorie_juridique,
158
163
  codeOfficielGeographique: cached_code_officiel_geographique,
159
164
  codePostal: cached_code_postal,
165
+ denominationUsuelleEtablissementPrincipal:
166
+ cached_denomination_usuelle_etablissement_principal,
160
167
  enseigne: cached_enseigne,
161
168
  estActive: cached_est_active,
162
169
  estDiffusible: cached_est_diffusible,
@@ -188,6 +195,7 @@ function toPartialOrganization(organization_info: OrganizationInfo) {
188
195
  cached_libelle,
189
196
  cached_nom_complet,
190
197
  cached_siege_social,
198
+ cached_denomination_usuelle_etablissement_principal,
191
199
  cached_statut_diffusion,
192
200
  cached_tranche_effectifs_unite_legale,
193
201
  cached_tranche_effectifs,
@@ -44,6 +44,7 @@ suite("upset", () => {
44
44
  cached_statut_diffusion: null,
45
45
  cached_tranche_effectifs: null,
46
46
  cached_tranche_effectifs_unite_legale: null,
47
+ cached_denomination_usuelle_etablissement_principal: null,
47
48
  created_at: new Date("4444-04-04"),
48
49
  id: 1,
49
50
  organization_info_fetched_at: new Date("4444-04-04"),
@@ -87,6 +88,7 @@ suite("upset", () => {
87
88
  cached_statut_diffusion: null,
88
89
  cached_tranche_effectifs: null,
89
90
  cached_tranche_effectifs_unite_legale: null,
91
+ cached_denomination_usuelle_etablissement_principal: null,
90
92
  created_at: new Date("1967-12-19"),
91
93
  id: 1,
92
94
  organization_info_fetched_at: new Date("4444-04-04"),
@@ -4,7 +4,7 @@ import type { TrancheEffectifs } from "./organization.js";
4
4
 
5
5
  //
6
6
 
7
- export const OrganizationInfoSchema = z.object({
7
+ export const ApiEntrepriseOrganizationInfoSchema = z.object({
8
8
  activitePrincipale: z.string(),
9
9
  adresse: z.string(),
10
10
  categorieJuridique: z.string(),
@@ -30,4 +30,15 @@ export const OrganizationInfoSchema = z.object({
30
30
  trancheEffectifsUniteLegale: z.string().nullable(),
31
31
  });
32
32
 
33
- export type OrganizationInfo = z.output<typeof OrganizationInfoSchema>;
33
+ const ApiRneOrganizationInfoSchema = z.object({
34
+ denominationUsuelleEtablissementPrincipal: z.string().nullable(),
35
+ });
36
+
37
+ export type ApiEntrepriseOrganizationInfo = z.output<
38
+ typeof ApiEntrepriseOrganizationInfoSchema
39
+ >;
40
+ export type ApiRneOrganizationInfo = z.output<
41
+ typeof ApiRneOrganizationInfoSchema
42
+ >;
43
+ export type OrganizationInfo = ApiEntrepriseOrganizationInfo &
44
+ ApiRneOrganizationInfo;
@@ -44,5 +44,6 @@ export interface Organization {
44
44
  cached_categorie_juridique: string | null;
45
45
  cached_libelle_categorie_juridique: string | null;
46
46
  cached_siege_social: boolean | null;
47
+ cached_denomination_usuelle_etablissement_principal: string | null;
47
48
  organization_info_fetched_at: Date | null;
48
49
  }