@proconnect-gouv/proconnect.identite 1.7.1 → 3.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.
Files changed (29) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/connectors/index.d.ts +110 -0
  3. package/dist/connectors/index.d.ts.map +1 -0
  4. package/dist/connectors/index.js +45 -0
  5. package/dist/managers/certification/process-certification-dirigeant.d.ts +5 -8
  6. package/dist/managers/certification/process-certification-dirigeant.d.ts.map +1 -1
  7. package/dist/managers/certification/process-certification-dirigeant.js +5 -5
  8. package/dist/managers/organization/adapters/api_entreprise.d.ts +1 -1
  9. package/dist/managers/organization/get-organization-info.d.ts +2 -2
  10. package/dist/managers/organization/get-organization-info.d.ts.map +1 -1
  11. package/dist/managers/organization/mark-domain-as-verified.d.ts +2 -12
  12. package/dist/managers/organization/mark-domain-as-verified.d.ts.map +1 -1
  13. package/dist/managers/organization/mark-domain-as-verified.js +9 -10
  14. package/dist/managers/user/assign-user-verification-type-to-domain.d.ts +2 -9
  15. package/dist/managers/user/assign-user-verification-type-to-domain.d.ts.map +1 -1
  16. package/dist/managers/user/assign-user-verification-type-to-domain.js +4 -3
  17. package/dist/types/organization-info.d.ts +1 -1
  18. package/package.json +4 -4
  19. package/src/connectors/index.ts +51 -0
  20. package/src/managers/certification/process-certification-dirigeant.test.ts +21 -21
  21. package/src/managers/certification/process-certification-dirigeant.ts +12 -15
  22. package/src/managers/organization/get-organization-info.ts +2 -4
  23. package/src/managers/organization/mark-domain-as-verified.test.ts +50 -64
  24. package/src/managers/organization/mark-domain-as-verified.ts +13 -33
  25. package/src/managers/user/assign-user-verification-type-to-domain.test.ts +87 -78
  26. package/src/managers/user/assign-user-verification-type-to-domain.ts +5 -16
  27. package/testing/index.ts +2 -0
  28. package/tsconfig.lib.tsbuildinfo +1 -1
  29. package/src/managers/organization/mark-domain-as-verified.test.ts.snapshot +0 -53
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @proconnect-gouv/proconnect.identite
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#1843](https://github.com/proconnect-gouv/proconnect-identite/pull/1843) [`c07b628`](https://github.com/proconnect-gouv/proconnect-identite/commit/c07b628d7daac833faa728d814132842a6518566) Thanks [@douglasduteil](https://github.com/douglasduteil)! - ♻️ Changement de nom des apis
8
+
9
+ ## 2.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - [#1844](https://github.com/proconnect-gouv/proconnect-identite/pull/1844) [`a957ae4`](https://github.com/proconnect-gouv/proconnect-identite/commit/a957ae4c60f0c1567e02102173dae12f84f5be18) Thanks [@douglasduteil](https://github.com/douglasduteil)! - ♻️ Utilisation d'un context global pour utiliser les managers
14
+
3
15
  ## 1.7.1
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,110 @@
1
+ import { type Pool } from "pg";
2
+ export declare function createContext(pg: Pool): {
3
+ repository: {
4
+ email_domains: {
5
+ addDomain: ({ organization_id, domain, verification_type, }: {
6
+ organization_id: number;
7
+ domain: string;
8
+ verification_type: import("../types/email-domain.js").EmailDomainVerificationType;
9
+ }) => Promise<{
10
+ id: number;
11
+ organization_id: number;
12
+ domain: string;
13
+ verification_type: "official_contact" | "trackdechets_postal_mail" | "verified" | "external" | "not_verified_yet" | "blacklisted" | "refused";
14
+ can_be_suggested: boolean;
15
+ verified_at: Date | null;
16
+ created_at: Date;
17
+ updated_at: Date;
18
+ }>;
19
+ deleteEmailDomainsByVerificationTypes: ({ organization_id, domain, domain_verification_types, }: {
20
+ organization_id: import("../types/email-domain.js").EmailDomain["organization_id"];
21
+ domain_verification_types: import("../types/email-domain.js").EmailDomainVerificationType[];
22
+ domain: import("../types/email-domain.js").EmailDomain["domain"];
23
+ }) => Promise<import("pg").QueryResult<any>>;
24
+ findEmailDomainsByOrganizationId: (organization_id: number) => Promise<{
25
+ id: number;
26
+ organization_id: number;
27
+ domain: string;
28
+ verification_type: "official_contact" | "trackdechets_postal_mail" | "verified" | "external" | "not_verified_yet" | "blacklisted" | "refused";
29
+ can_be_suggested: boolean;
30
+ verified_at: Date | null;
31
+ created_at: Date;
32
+ updated_at: Date;
33
+ }[]>;
34
+ };
35
+ organizations: {
36
+ findById: (id: number) => Promise<import("../types/organization.js").Organization | undefined>;
37
+ findByUserId: (userId: number) => Promise<(import("../types/organization.js").Organization & {
38
+ is_external: boolean;
39
+ verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association";
40
+ verified_at: Date | null;
41
+ has_been_greeted: boolean;
42
+ needs_official_contact_email_verification: boolean;
43
+ official_contact_email_verification_token: string | null;
44
+ official_contact_email_verification_sent_at: Date | null;
45
+ })[]>;
46
+ getUsers: (organization_id: number, additionalWhereClause?: string, additionalParams?: any[]) => Promise<(import("../types/user.js").User & {
47
+ is_external: boolean;
48
+ verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association";
49
+ verified_at: Date | null;
50
+ has_been_greeted: boolean;
51
+ needs_official_contact_email_verification: boolean;
52
+ official_contact_email_verification_token: string | null;
53
+ official_contact_email_verification_sent_at: Date | null;
54
+ })[]>;
55
+ };
56
+ users_organizations: {
57
+ update: (organization_id: number, user_id: number, fieldsToUpdate: Partial<import("../types/user-organization-link.js").UserOrganizationLink>) => Promise<{
58
+ is_external: boolean;
59
+ verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association";
60
+ verified_at: Date | null;
61
+ has_been_greeted: boolean;
62
+ needs_official_contact_email_verification: boolean;
63
+ official_contact_email_verification_token: string | null;
64
+ official_contact_email_verification_sent_at: Date | null;
65
+ user_id: number;
66
+ organization_id: number;
67
+ created_at: Date;
68
+ updated_at: Date;
69
+ }>;
70
+ };
71
+ users: {
72
+ create: ({ email, encrypted_password, }: {
73
+ email: string;
74
+ encrypted_password?: string | null;
75
+ }) => Promise<import("../types/user.js").User>;
76
+ findByEmail: (email: string) => Promise<import("../types/user.js").User | undefined>;
77
+ findById: (id: number) => Promise<import("../types/user.js").User | undefined>;
78
+ getById: (id: number) => Promise<import("../types/user.js").User>;
79
+ getFranceConnectUserInfo: (user_id: number) => Promise<{
80
+ birthcountry: string;
81
+ birthdate: Date;
82
+ birthplace: string;
83
+ family_name: string;
84
+ gender: string;
85
+ given_name: string;
86
+ sub: string;
87
+ created_at: Date;
88
+ updated_at: Date;
89
+ user_id: number;
90
+ preferred_username?: string | undefined;
91
+ } | undefined>;
92
+ update: (id: number, fieldsToUpdate: Partial<import("../types/user.js").User>) => Promise<import("../types/user.js").User>;
93
+ upsetFranceconnectUserinfo: (value: Pick<import("../types/franceconnect.js").FranceConnectUserInfo, "user_id"> & Partial<import("../types/franceconnect.js").FranceConnectUserInfo>) => Promise<{
94
+ birthcountry: string;
95
+ birthdate: Date;
96
+ birthplace: string;
97
+ family_name: string;
98
+ gender: string;
99
+ given_name: string;
100
+ sub: string;
101
+ created_at: Date;
102
+ updated_at: Date;
103
+ user_id: number;
104
+ preferred_username?: string | undefined;
105
+ }>;
106
+ };
107
+ };
108
+ };
109
+ export type Context = ReturnType<typeof createContext>;
110
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectors/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC;AAkB/B,wBAAgB,aAAa,CAAC,EAAE,EAAE,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAfgE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4CtG;AACD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
@@ -0,0 +1,45 @@
1
+ //
2
+ import {} from "pg";
3
+ import { addDomainFactory } from "../repositories/email-domain/add-domain.js";
4
+ import { deleteEmailDomainsByVerificationTypesFactory } from "../repositories/email-domain/delete-email-domains-by-verification-types.js";
5
+ import { findEmailDomainsByOrganizationIdFactory } from "../repositories/email-domain/find-email-domains-by-organization-id.js";
6
+ import { findByIdFactory as findOrganizationByIdFactory } from "../repositories/organization/find-by-id.js";
7
+ import { findByUserIdFactory } from "../repositories/organization/find-by-user-id.js";
8
+ import { getUsersByOrganizationFactory } from "../repositories/organization/get-users-by-organization.js";
9
+ import { createUserFactory } from "../repositories/user/create.js";
10
+ import { findByEmailFactory } from "../repositories/user/find-by-email.js";
11
+ import { findByIdFactory as findUserByIdFactory } from "../repositories/user/find-by-id.js";
12
+ import { getByIdFactory } from "../repositories/user/get-by-id.js";
13
+ import { getFranceConnectUserInfoFactory } from "../repositories/user/get-franceconnect-user-info.js";
14
+ import { updateUserOrganizationLinkFactory } from "../repositories/user/update-user-organization-link.js";
15
+ import { updateUserFactory } from "../repositories/user/update.js";
16
+ import { upsertFranceconnectUserinfoFactory } from "../repositories/user/upsert-franceconnect-userinfo.js";
17
+ //
18
+ export function createContext(pg) {
19
+ return {
20
+ repository: {
21
+ email_domains: {
22
+ addDomain: addDomainFactory({ pg }),
23
+ deleteEmailDomainsByVerificationTypes: deleteEmailDomainsByVerificationTypesFactory({ pg }),
24
+ findEmailDomainsByOrganizationId: findEmailDomainsByOrganizationIdFactory({ pg }),
25
+ },
26
+ organizations: {
27
+ findById: findOrganizationByIdFactory({ pg }),
28
+ findByUserId: findByUserIdFactory({ pg }),
29
+ getUsers: getUsersByOrganizationFactory({ pg }),
30
+ },
31
+ users_organizations: {
32
+ update: updateUserOrganizationLinkFactory({ pg }),
33
+ },
34
+ users: {
35
+ create: createUserFactory({ pg }),
36
+ findByEmail: findByEmailFactory({ pg }),
37
+ findById: findUserByIdFactory({ pg }),
38
+ getById: getByIdFactory({ pg }),
39
+ getFranceConnectUserInfo: getFranceConnectUserInfoFactory({ pg }),
40
+ update: updateUserFactory({ pg }),
41
+ upsetFranceconnectUserinfo: upsertFranceconnectUserinfoFactory({ pg }),
42
+ },
43
+ },
44
+ };
45
+ }
@@ -1,15 +1,12 @@
1
1
  import { type FranceConnectUserInfo, type Organization } from "#src/types";
2
- import type { ApiEntrepriseInfogreffeRepository } from "@proconnect-gouv/proconnect.api_entreprise/api";
3
- import type { FindUniteLegaleBySirenHandler } from "@proconnect-gouv/proconnect.insee/api";
2
+ import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entreprise/api";
3
+ import type { ApiInseeClient } from "@proconnect-gouv/proconnect.insee/api";
4
4
  import type { FindPouvoirsBySirenHandler } from "@proconnect-gouv/proconnect.registre_national_entreprises/api";
5
5
  import z from "zod/v4";
6
6
  type ProcessCertificationDirigeantConfig = {
7
- ApiEntrepriseInfogreffeRepository: Pick<ApiEntrepriseInfogreffeRepository, "findMandatairesSociauxBySiren">;
8
- EQUALITY_THRESHOLD?: number;
9
- InseeApiRepository: {
10
- findBySiren: FindUniteLegaleBySirenHandler;
11
- };
12
- RegistreNationalEntreprisesApiRepository: {
7
+ ApiEntrepriseClient: Pick<ApiEntrepriseClient, "findMandatairesSociauxBySiren">;
8
+ InseeApiClient: ApiInseeClient;
9
+ RegistreNationalEntreprisesApiClient: {
13
10
  findPouvoirsBySiren: FindPouvoirsBySirenHandler;
14
11
  };
15
12
  };
@@ -1 +1 @@
1
- {"version":3,"file":"process-certification-dirigeant.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/process-certification-dirigeant.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,qBAAqB,EAE1B,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,gDAAgD,CAAC;AACxG,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+DAA+D,CAAC;AAEhH,OAAO,CAAC,MAAM,QAAQ,CAAC;AASvB,KAAK,mCAAmC,GAAG;IACzC,iCAAiC,EAAE,IAAI,CACrC,iCAAiC,EACjC,+BAA+B,CAChC,CAAC;IACF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE;QAAE,WAAW,EAAE,6BAA6B,CAAA;KAAE,CAAC;IACnE,wCAAwC,EAAE;QACxC,mBAAmB,EAAE,0BAA0B,CAAC;KACjD,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,gCAAgC;;;;EAI3C,CAAC;AAEH,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CACpD,OAAO,gCAAgC,CACxC,CAAC;AAWF,wBAAgB,yCAAyC,CACvD,UAAU,EAAE,gCAAgC,UAG7C;AA0ED,wBAAgB,oCAAoC,CAClD,MAAM,EAAE,mCAAmC,IAKzC,cAAc,YAAY,EAC1B,wBAAwB,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEhD"}
1
+ {"version":3,"file":"process-certification-dirigeant.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/process-certification-dirigeant.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,qBAAqB,EAE1B,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+DAA+D,CAAC;AAEhH,OAAO,CAAC,MAAM,QAAQ,CAAC;AASvB,KAAK,mCAAmC,GAAG;IACzC,mBAAmB,EAAE,IAAI,CACvB,mBAAmB,EACnB,+BAA+B,CAChC,CAAC;IACF,cAAc,EAAE,cAAc,CAAC;IAC/B,oCAAoC,EAAE;QACpC,mBAAmB,EAAE,0BAA0B,CAAC;KACjD,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,gCAAgC;;;;EAI3C,CAAC;AAEH,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CACpD,OAAO,gCAAgC,CACxC,CAAC;AAWF,wBAAgB,yCAAyC,CACvD,UAAU,EAAE,gCAAgC,UAG7C;AAwED,wBAAgB,oCAAoC,CAClD,MAAM,EAAE,mCAAmC,IAKzC,cAAc,YAAY,EAC1B,wBAAwB,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEhD"}
@@ -22,9 +22,9 @@ export function getCertificationDirigeantDataSourceLabels(dataSource) {
22
22
  return CERTIFICATION_DIRIGEANT_DATA_SOURCE_LABELS[dataSource];
23
23
  }
24
24
  //
25
- async function getMandatairesSociaux({ RegistreNationalEntreprisesApiRepository, ApiEntrepriseInfogreffeRepository, }, siren) {
25
+ async function getMandatairesSociaux({ RegistreNationalEntreprisesApiClient, ApiEntrepriseClient, }, siren) {
26
26
  try {
27
- const pouvoirs = await RegistreNationalEntreprisesApiRepository.findPouvoirsBySiren(siren);
27
+ const pouvoirs = await RegistreNationalEntreprisesApiClient.findPouvoirsBySiren(siren);
28
28
  const dirigeants = pouvoirs.map(RNE.toIdentityVector);
29
29
  return {
30
30
  dirigeants,
@@ -33,7 +33,7 @@ async function getMandatairesSociaux({ RegistreNationalEntreprisesApiRepository,
33
33
  }
34
34
  catch (error) {
35
35
  console.error(error);
36
- const mandataires = await ApiEntrepriseInfogreffeRepository.findMandatairesSociauxBySiren(siren);
36
+ const mandataires = await ApiEntrepriseClient.findMandatairesSociauxBySiren(siren);
37
37
  const dirigeants = mandataires.map(ApiEntreprise.toIdentityVector);
38
38
  return {
39
39
  dirigeants,
@@ -70,7 +70,7 @@ function match_identity_to_dirigeant(identity, dirigeants) {
70
70
  }));
71
71
  }
72
72
  export function processCertificationDirigeantFactory(config) {
73
- const { InseeApiRepository } = config;
73
+ const { InseeApiClient } = config;
74
74
  return async function processCertificationDirigeant(organization, franceconnect_userinfo) {
75
75
  if (!isOrganizationCoveredByCertificationDirigeant(organization)) {
76
76
  return {
@@ -92,7 +92,7 @@ export function processCertificationDirigeantFactory(config) {
92
92
  : CertificationDirigeantDataSource.enum["registre-national-entreprises.inpi.fr/api"];
93
93
  const { dirigeants, source } = await match(preferredDataSource)
94
94
  .with("api.insee.fr/api-sirene/private", async () => ({
95
- dirigeants: await InseeApiRepository.findBySiren(siren)
95
+ dirigeants: await InseeApiClient.findBySiren(siren)
96
96
  .then(INSEE.toIdentityVector)
97
97
  .then((vector) => [vector]),
98
98
  source: CertificationDirigeantDataSource.enum["api.insee.fr/api-sirene/private"],
@@ -20,7 +20,7 @@ export declare function toPartialOrganization(organization_info: OrganizationInf
20
20
  cached_siege_social: boolean;
21
21
  cached_statut_diffusion: "diffusible" | "partiellement_diffusible" | "non_diffusible";
22
22
  cached_tranche_effectifs_unite_legale: string | null;
23
- cached_tranche_effectifs: "11" | "12" | "21" | "22" | "31" | "32" | "41" | "42" | "51" | "52" | "53" | "NN" | "00" | "01" | "02" | "03" | null;
23
+ cached_tranche_effectifs: "NN" | "00" | "01" | "02" | "03" | "11" | "12" | "21" | "22" | "31" | "32" | "41" | "42" | "51" | "52" | "53" | null;
24
24
  siret: string;
25
25
  };
26
26
  //# sourceMappingURL=api_entreprise.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { type OrganizationInfo } from "#src/types";
2
- import type { ApiEntrepriseInseeRepository } from "@proconnect-gouv/proconnect.api_entreprise/api";
3
- export declare function getOrganizationInfoFactory(config: ApiEntrepriseInseeRepository): (siretOrSiren: string) => Promise<OrganizationInfo>;
2
+ import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entreprise/api";
3
+ export declare function getOrganizationInfoFactory(config: ApiEntrepriseClient): (siretOrSiren: string) => Promise<OrganizationInfo>;
4
4
  export type GetOrganizationInfoHandler = ReturnType<typeof getOrganizationInfoFactory>;
5
5
  //# 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,4BAA4B,EAAE,MAAM,gDAAgD,CAAC;AASnG,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,4BAA4B,IAKlC,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,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,15 +1,6 @@
1
- import type { AddDomainHandler, DeleteEmailDomainsByVerificationTypesHandler } from "#src/repositories/email-domain";
2
- import type { FindByIdHandler, GetUsersByOrganizationHandler } from "#src/repositories/organization";
3
- import type { UpdateUserOrganizationLinkHandler } from "#src/repositories/user";
1
+ import type { Context } from "#src/connectors";
4
2
  import { type EmailDomainNoPendingVerificationType } from "#src/types";
5
- type FactoryDependencies = {
6
- addDomain: AddDomainHandler;
7
- deleteEmailDomainsByVerificationTypes: DeleteEmailDomainsByVerificationTypesHandler;
8
- findOrganizationById: FindByIdHandler;
9
- getUsers: GetUsersByOrganizationHandler;
10
- updateUserOrganizationLink: UpdateUserOrganizationLinkHandler;
11
- };
12
- export declare function markDomainAsVerifiedFactory({ addDomain, deleteEmailDomainsByVerificationTypes, findOrganizationById, getUsers, updateUserOrganizationLink, }: FactoryDependencies): ({ organization_id, domain, domain_verification_type, }: {
3
+ export declare function markDomainAsVerifiedFactory(context: Context): ({ organization_id, domain, domain_verification_type, }: {
13
4
  organization_id: number;
14
5
  domain: string;
15
6
  domain_verification_type: EmailDomainNoPendingVerificationType;
@@ -24,5 +15,4 @@ export declare function markDomainAsVerifiedFactory({ addDomain, deleteEmailDoma
24
15
  updated_at: Date;
25
16
  }>;
26
17
  export type MarkDomainAsVerifiedHandler = ReturnType<typeof markDomainAsVerifiedFactory>;
27
- export {};
28
18
  //# sourceMappingURL=mark-domain-as-verified.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mark-domain-as-verified.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/mark-domain-as-verified.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAChB,4CAA4C,EAC7C,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC9B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAGL,KAAK,oCAAoC,EAK1C,MAAM,YAAY,CAAC;AAOpB,KAAK,mBAAmB,GAAG;IACzB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,qCAAqC,EAAE,4CAA4C,CAAC;IACpF,oBAAoB,EAAE,eAAe,CAAC;IACtC,QAAQ,EAAE,6BAA6B,CAAC;IACxC,0BAA0B,EAAE,iCAAiC,CAAC;CAC/D,CAAC;AAEF,wBAAgB,2BAA2B,CAAC,EAC1C,SAAS,EACT,qCAAqC,EACrC,oBAAoB,EACpB,QAAQ,EACR,0BAA0B,GAC3B,EAAE,mBAAmB,IAMuB,wDAIxC;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,oCAAoC,CAAC;CAChE;;;;;;;;;GAgFF;AAED,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAClD,OAAO,2BAA2B,CACnC,CAAC"}
1
+ {"version":3,"file":"mark-domain-as-verified.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/mark-domain-as-verified.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAGL,KAAK,oCAAoC,EAK1C,MAAM,YAAY,CAAC;AAOpB,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,IAQf,wDAIxC;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,oCAAoC,CAAC;CAChE;;;;;;;;;GAgFF;AAED,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAClD,OAAO,2BAA2B,CACnC,CAAC"}
@@ -4,13 +4,12 @@ import { assignUserVerificationTypeToDomainFactory } from "#src/managers/user";
4
4
  import { EmailDomainApprovedVerificationTypes, EmailDomainPendingVerificationTypes, EmailDomainRejectedVerificationTypes, } from "#src/types";
5
5
  import { isEmpty } from "lodash-es";
6
6
  import { match } from "ts-pattern";
7
- export function markDomainAsVerifiedFactory({ addDomain, deleteEmailDomainsByVerificationTypes, findOrganizationById, getUsers, updateUserOrganizationLink, }) {
8
- const assignUserVerificationTypeToDomain = assignUserVerificationTypeToDomainFactory({
9
- getUsers,
10
- updateUserOrganizationLink,
11
- });
7
+ //
8
+ export function markDomainAsVerifiedFactory(context) {
9
+ const assignUserVerificationTypeToDomain = assignUserVerificationTypeToDomainFactory(context);
10
+ const { repository: { email_domains, organizations }, } = context;
12
11
  return async function markDomainAsVerified({ organization_id, domain, domain_verification_type, }) {
13
- const organization = await findOrganizationById(organization_id);
12
+ const organization = await organizations.findById(organization_id);
14
13
  if (isEmpty(organization)) {
15
14
  throw new NotFoundError();
16
15
  }
@@ -31,7 +30,7 @@ export function markDomainAsVerifiedFactory({ addDomain, deleteEmailDomainsByVer
31
30
  .exhaustive();
32
31
  };
33
32
  async function markDomainAsApproved({ organization_id, domain, domain_verification_type, }) {
34
- await deleteEmailDomainsByVerificationTypes({
33
+ await email_domains.deleteEmailDomainsByVerificationTypes({
35
34
  organization_id,
36
35
  domain,
37
36
  domain_verification_types: [
@@ -39,14 +38,14 @@ export function markDomainAsVerifiedFactory({ addDomain, deleteEmailDomainsByVer
39
38
  ...EmailDomainPendingVerificationTypes,
40
39
  ],
41
40
  });
42
- return addDomain({
41
+ return email_domains.addDomain({
43
42
  organization_id,
44
43
  domain,
45
44
  verification_type: domain_verification_type,
46
45
  });
47
46
  }
48
47
  async function markDomainAsRejected({ organization_id, domain, domain_verification_type, }) {
49
- await deleteEmailDomainsByVerificationTypes({
48
+ await email_domains.deleteEmailDomainsByVerificationTypes({
50
49
  organization_id,
51
50
  domain,
52
51
  domain_verification_types: [
@@ -54,7 +53,7 @@ export function markDomainAsVerifiedFactory({ addDomain, deleteEmailDomainsByVer
54
53
  ...EmailDomainRejectedVerificationTypes,
55
54
  ],
56
55
  });
57
- return addDomain({
56
+ return email_domains.addDomain({
58
57
  organization_id,
59
58
  domain,
60
59
  verification_type: domain_verification_type,
@@ -1,10 +1,3 @@
1
- import type { GetUsersByOrganizationHandler } from "#src/repositories/organization";
2
- import type { UpdateUserOrganizationLinkHandler } from "#src/repositories/user";
3
- type FactoryDependencies = {
4
- getUsers: GetUsersByOrganizationHandler;
5
- updateUserOrganizationLink: UpdateUserOrganizationLinkHandler;
6
- };
7
- export declare function assignUserVerificationTypeToDomainFactory({ getUsers, updateUserOrganizationLink, }: FactoryDependencies): (organization_id: number, domain: string) => Promise<void>;
8
- export type AssignUserVerificationTypeToDomainFactoryHandler = ReturnType<typeof assignUserVerificationTypeToDomainFactory>;
9
- export {};
1
+ import type { Context } from "#src/connectors";
2
+ export declare function assignUserVerificationTypeToDomainFactory({ repository: { organizations, users_organizations }, }: Context): (organization_id: number, domain: string) => Promise<void>;
10
3
  //# sourceMappingURL=assign-user-verification-type-to-domain.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assign-user-verification-type-to-domain.d.ts","sourceRoot":"","sources":["../../../src/managers/user/assign-user-verification-type-to-domain.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;AAOhF,KAAK,mBAAmB,GAAG;IACzB,QAAQ,EAAE,6BAA6B,CAAC;IACxC,0BAA0B,EAAE,iCAAiC,CAAC;CAC/D,CAAC;AAEF,wBAAgB,yCAAyC,CAAC,EACxD,QAAQ,EACR,0BAA0B,GAC3B,EAAE,mBAAmB,IAElB,iBAAiB,MAAM,EACvB,QAAQ,MAAM,mBAwBjB;AAED,MAAM,MAAM,gDAAgD,GAAG,UAAU,CACvE,OAAO,yCAAyC,CACjD,CAAC"}
1
+ {"version":3,"file":"assign-user-verification-type-to-domain.d.ts","sourceRoot":"","sources":["../../../src/managers/user/assign-user-verification-type-to-domain.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAO/C,wBAAgB,yCAAyC,CAAC,EACxD,UAAU,EAAE,EAAE,aAAa,EAAE,mBAAmB,EAAE,GACnD,EAAE,OAAO,IAEN,iBAAiB,MAAM,EACvB,QAAQ,MAAM,mBAwBjB"}
@@ -2,16 +2,17 @@
2
2
  import { LinkTypes, SuperWeakLinkTypes, UnverifiedLinkTypes } from "#src/types";
3
3
  import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
4
4
  import { match } from "ts-pattern";
5
- export function assignUserVerificationTypeToDomainFactory({ getUsers, updateUserOrganizationLink, }) {
5
+ //
6
+ export function assignUserVerificationTypeToDomainFactory({ repository: { organizations, users_organizations }, }) {
6
7
  return async function assignUserVerificationTypeToDomain(organization_id, domain) {
7
- const usersInOrganization = await getUsers(organization_id);
8
+ const usersInOrganization = await organizations.getUsers(organization_id);
8
9
  await Promise.all(usersInOrganization.map(({ id, email, verification_type: link_verification_type }) => {
9
10
  const userDomain = getEmailDomain(email);
10
11
  if (userDomain === domain &&
11
12
  match(link_verification_type)
12
13
  .with(...UnverifiedLinkTypes, ...SuperWeakLinkTypes, () => true)
13
14
  .otherwise(() => false)) {
14
- return updateUserOrganizationLink(organization_id, id, {
15
+ return users_organizations.update(organization_id, id, {
15
16
  verification_type: LinkTypes.enum.domain,
16
17
  });
17
18
  }
@@ -21,7 +21,7 @@ export declare const OrganizationInfoSchema: z.ZodObject<{
21
21
  partiellement_diffusible: "partiellement_diffusible";
22
22
  non_diffusible: "non_diffusible";
23
23
  }>;
24
- trancheEffectifs: z.ZodNullable<z.ZodCustom<"11" | "12" | "21" | "22" | "31" | "32" | "41" | "42" | "51" | "52" | "53" | "NN" | "00" | "01" | "02" | "03" | null, "11" | "12" | "21" | "22" | "31" | "32" | "41" | "42" | "51" | "52" | "53" | "NN" | "00" | "01" | "02" | "03" | null>>;
24
+ trancheEffectifs: z.ZodNullable<z.ZodCustom<"NN" | "00" | "01" | "02" | "03" | "11" | "12" | "21" | "22" | "31" | "32" | "41" | "42" | "51" | "52" | "53" | null, "NN" | "00" | "01" | "02" | "03" | "11" | "12" | "21" | "22" | "31" | "32" | "41" | "42" | "51" | "52" | "53" | null>>;
25
25
  trancheEffectifsUniteLegale: z.ZodNullable<z.ZodString>;
26
26
  }, z.core.$strip>;
27
27
  export type OrganizationInfo = z.output<typeof OrganizationInfoSchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proconnect-gouv/proconnect.identite",
3
- "version": "1.7.1",
3
+ "version": "3.0.0",
4
4
  "homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/identite#readme",
5
5
  "bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
6
6
  "repository": {
@@ -51,11 +51,11 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "@electric-sql/pglite": "^0.3.12",
54
- "@proconnect-gouv/proconnect.annuaire_entreprises": "^1.1.0",
55
- "@proconnect-gouv/proconnect.api_entreprise": "^1.1.0",
54
+ "@proconnect-gouv/proconnect.annuaire_entreprises": "^1.1.4",
55
+ "@proconnect-gouv/proconnect.api_entreprise": "^2.0.0",
56
56
  "@proconnect-gouv/proconnect.core": "^1.0.0",
57
57
  "@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
58
- "@proconnect-gouv/proconnect.insee": "^1.0.1",
58
+ "@proconnect-gouv/proconnect.insee": "^2.0.0",
59
59
  "@types/node": "^22.18.6",
60
60
  "@types/pg": "^8.15.5",
61
61
  "await-to-js": "^3.0.0",
@@ -0,0 +1,51 @@
1
+ //
2
+
3
+ import { type Pool } from "pg";
4
+ import { addDomainFactory } from "../repositories/email-domain/add-domain.js";
5
+ import { deleteEmailDomainsByVerificationTypesFactory } from "../repositories/email-domain/delete-email-domains-by-verification-types.js";
6
+ import { findEmailDomainsByOrganizationIdFactory } from "../repositories/email-domain/find-email-domains-by-organization-id.js";
7
+ import { findByIdFactory as findOrganizationByIdFactory } from "../repositories/organization/find-by-id.js";
8
+ import { findByUserIdFactory } from "../repositories/organization/find-by-user-id.js";
9
+ import { getUsersByOrganizationFactory } from "../repositories/organization/get-users-by-organization.js";
10
+ import { createUserFactory } from "../repositories/user/create.js";
11
+ import { findByEmailFactory } from "../repositories/user/find-by-email.js";
12
+ import { findByIdFactory as findUserByIdFactory } from "../repositories/user/find-by-id.js";
13
+ import { getByIdFactory } from "../repositories/user/get-by-id.js";
14
+ import { getFranceConnectUserInfoFactory } from "../repositories/user/get-franceconnect-user-info.js";
15
+ import { updateUserOrganizationLinkFactory } from "../repositories/user/update-user-organization-link.js";
16
+ import { updateUserFactory } from "../repositories/user/update.js";
17
+ import { upsertFranceconnectUserinfoFactory } from "../repositories/user/upsert-franceconnect-userinfo.js";
18
+
19
+ //
20
+
21
+ export function createContext(pg: Pool) {
22
+ return {
23
+ repository: {
24
+ email_domains: {
25
+ addDomain: addDomainFactory({ pg }),
26
+ deleteEmailDomainsByVerificationTypes:
27
+ deleteEmailDomainsByVerificationTypesFactory({ pg }),
28
+ findEmailDomainsByOrganizationId:
29
+ findEmailDomainsByOrganizationIdFactory({ pg }),
30
+ },
31
+ organizations: {
32
+ findById: findOrganizationByIdFactory({ pg }),
33
+ findByUserId: findByUserIdFactory({ pg }),
34
+ getUsers: getUsersByOrganizationFactory({ pg }),
35
+ },
36
+ users_organizations: {
37
+ update: updateUserOrganizationLinkFactory({ pg }),
38
+ },
39
+ users: {
40
+ create: createUserFactory({ pg }),
41
+ findByEmail: findByEmailFactory({ pg }),
42
+ findById: findUserByIdFactory({ pg }),
43
+ getById: getByIdFactory({ pg }),
44
+ getFranceConnectUserInfo: getFranceConnectUserInfoFactory({ pg }),
45
+ update: updateUserFactory({ pg }),
46
+ upsetFranceconnectUserinfo: upsertFranceconnectUserinfoFactory({ pg }),
47
+ },
48
+ },
49
+ };
50
+ }
51
+ export type Context = ReturnType<typeof createContext>;
@@ -35,13 +35,13 @@ import { processCertificationDirigeantFactory } from "./process-certification-di
35
35
  describe("processCertificationDirigeantFactory", () => {
36
36
  it("should recognize a user as executive of a auto-entrepreneur", async () => {
37
37
  const processCertificationDirigeant = processCertificationDirigeantFactory({
38
- ApiEntrepriseInfogreffeRepository: {
38
+ ApiEntrepriseClient: {
39
39
  findMandatairesSociauxBySiren: () => Promise.reject(new Error("💣")),
40
40
  },
41
- RegistreNationalEntreprisesApiRepository: {
41
+ RegistreNationalEntreprisesApiClient: {
42
42
  findPouvoirsBySiren: () => Promise.reject(new Error("💣")),
43
43
  },
44
- InseeApiRepository: {
44
+ InseeApiClient: {
45
45
  findBySiren: () => Promise.resolve(LiElJonsonEstablishment),
46
46
  },
47
47
  });
@@ -71,13 +71,13 @@ describe("processCertificationDirigeantFactory", () => {
71
71
 
72
72
  it("should recognize a foreign user as executive of a auto-entrepreneur", async () => {
73
73
  const processCertificationDirigeant = processCertificationDirigeantFactory({
74
- ApiEntrepriseInfogreffeRepository: {
74
+ ApiEntrepriseClient: {
75
75
  findMandatairesSociauxBySiren: () => Promise.reject(new Error("💣")),
76
76
  },
77
- RegistreNationalEntreprisesApiRepository: {
77
+ RegistreNationalEntreprisesApiClient: {
78
78
  findPouvoirsBySiren: () => Promise.reject(new Error("💣")),
79
79
  },
80
- InseeApiRepository: {
80
+ InseeApiClient: {
81
81
  findBySiren: () => Promise.resolve(RogalDornEstablishment),
82
82
  },
83
83
  });
@@ -107,13 +107,13 @@ describe("processCertificationDirigeantFactory", () => {
107
107
 
108
108
  it("should not match another mandataire", async () => {
109
109
  const processCertificationDirigeant = processCertificationDirigeantFactory({
110
- ApiEntrepriseInfogreffeRepository: {
110
+ ApiEntrepriseClient: {
111
111
  findMandatairesSociauxBySiren: () => Promise.reject(new Error("💣")),
112
112
  },
113
- RegistreNationalEntreprisesApiRepository: {
113
+ RegistreNationalEntreprisesApiClient: {
114
114
  findPouvoirsBySiren: () => Promise.reject(new Error("💣")),
115
115
  },
116
- InseeApiRepository: {
116
+ InseeApiClient: {
117
117
  findBySiren: () => Promise.resolve(LiElJonsonEstablishment),
118
118
  },
119
119
  });
@@ -137,14 +137,14 @@ describe("processCertificationDirigeantFactory", () => {
137
137
 
138
138
  it("should match Rogal Dorn among the executive of Papillon in RNE", async () => {
139
139
  const processCertificationDirigeant = processCertificationDirigeantFactory({
140
- ApiEntrepriseInfogreffeRepository: {
140
+ ApiEntrepriseClient: {
141
141
  findMandatairesSociauxBySiren: () => Promise.reject(new Error("💣")),
142
142
  },
143
- RegistreNationalEntreprisesApiRepository: {
143
+ RegistreNationalEntreprisesApiClient: {
144
144
  findPouvoirsBySiren: () =>
145
145
  Promise.resolve([UlysseTosiPouvoir, RogalDornPouvoir]),
146
146
  },
147
- InseeApiRepository: {
147
+ InseeApiClient: {
148
148
  findBySiren: () => Promise.reject(new Error("💣")),
149
149
  },
150
150
  });
@@ -174,14 +174,14 @@ describe("processCertificationDirigeantFactory", () => {
174
174
 
175
175
  it("should match Amberley Vail among the executive of Papillon in RNE", async () => {
176
176
  const processCertificationDirigeant = processCertificationDirigeantFactory({
177
- ApiEntrepriseInfogreffeRepository: {
177
+ ApiEntrepriseClient: {
178
178
  findMandatairesSociauxBySiren: () => Promise.reject(new Error("💣")),
179
179
  },
180
- RegistreNationalEntreprisesApiRepository: {
180
+ RegistreNationalEntreprisesApiClient: {
181
181
  findPouvoirsBySiren: () =>
182
182
  Promise.resolve([UlysseTosiPouvoir, AmberleyVailPouvoir]),
183
183
  },
184
- InseeApiRepository: {
184
+ InseeApiClient: {
185
185
  findBySiren: () => Promise.reject(new Error("💣")),
186
186
  },
187
187
  });
@@ -211,14 +211,14 @@ describe("processCertificationDirigeantFactory", () => {
211
211
 
212
212
  it("should match Rogal Dorn among the executive of Papillon in Infogreffe", async () => {
213
213
  const processCertificationDirigeant = processCertificationDirigeantFactory({
214
- ApiEntrepriseInfogreffeRepository: {
214
+ ApiEntrepriseClient: {
215
215
  findMandatairesSociauxBySiren: () =>
216
216
  Promise.resolve([UlysseToriMandataire, RogalDornMandataire]),
217
217
  },
218
- RegistreNationalEntreprisesApiRepository: {
218
+ RegistreNationalEntreprisesApiClient: {
219
219
  findPouvoirsBySiren: () => Promise.reject(new Error("💣")),
220
220
  },
221
- InseeApiRepository: {
221
+ InseeApiClient: {
222
222
  findBySiren: () => Promise.reject(new Error("💣")),
223
223
  },
224
224
  });
@@ -249,13 +249,13 @@ describe("processCertificationDirigeantFactory", () => {
249
249
 
250
250
  it("❎ fail with no mandataires", async () => {
251
251
  const processCertificationDirigeant = processCertificationDirigeantFactory({
252
- ApiEntrepriseInfogreffeRepository: {
252
+ ApiEntrepriseClient: {
253
253
  findMandatairesSociauxBySiren: () => Promise.reject(new Error("💣")),
254
254
  },
255
- RegistreNationalEntreprisesApiRepository: {
255
+ RegistreNationalEntreprisesApiClient: {
256
256
  findPouvoirsBySiren: () => Promise.resolve([]),
257
257
  },
258
- InseeApiRepository: {
258
+ InseeApiClient: {
259
259
  findBySiren: () => Promise.reject(new Error("💣")),
260
260
  },
261
261
  });