@proconnect-gouv/proconnect.identite 10.2.2 → 10.4.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 (39) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/connectors/index.d.ts +11 -1
  3. package/dist/connectors/index.d.ts.map +1 -1
  4. package/dist/connectors/index.js +2 -1
  5. package/dist/errors/index.d.ts +3 -0
  6. package/dist/errors/index.d.ts.map +1 -1
  7. package/dist/errors/index.js +6 -0
  8. package/dist/managers/certification/match-identity-to-dirigeant.d.ts +44 -0
  9. package/dist/managers/certification/match-identity-to-dirigeant.d.ts.map +1 -0
  10. package/dist/managers/certification/match-identity-to-dirigeant.js +32 -0
  11. package/dist/managers/certification/process-certification-dirigeant.d.ts.map +1 -1
  12. package/dist/managers/certification/process-certification-dirigeant.js +1 -29
  13. package/dist/managers/organization/mark-domain-as-verified.d.ts.map +1 -1
  14. package/dist/managers/organization/mark-domain-as-verified.js +2 -0
  15. package/dist/repositories/moderation/get-moderation-by-id.d.ts.map +1 -1
  16. package/dist/repositories/moderation/get-moderation-by-id.js +1 -1
  17. package/dist/repositories/organization/find-users-by-organization.d.ts +1 -1
  18. package/dist/repositories/organization/find-users-by-organization.d.ts.map +1 -1
  19. package/dist/repositories/organization/find-users-by-organization.js +3 -6
  20. package/dist/repositories/user_organisation/get-user-organization.d.ts +12 -0
  21. package/dist/repositories/user_organisation/get-user-organization.d.ts.map +1 -0
  22. package/dist/repositories/user_organisation/get-user-organization.js +15 -0
  23. package/dist/repositories/user_organisation/index.d.ts +1 -0
  24. package/dist/repositories/user_organisation/index.d.ts.map +1 -1
  25. package/dist/repositories/user_organisation/index.js +1 -0
  26. package/package.json +3 -3
  27. package/src/connectors/index.ts +2 -0
  28. package/src/errors/index.ts +7 -0
  29. package/src/managers/certification/match-identity-to-dirigeant.test.ts +62 -0
  30. package/src/managers/certification/match-identity-to-dirigeant.ts +40 -0
  31. package/src/managers/certification/process-certification-dirigeant.ts +1 -35
  32. package/src/managers/organization/mark-domain-as-verified.test.ts +174 -0
  33. package/src/managers/organization/mark-domain-as-verified.ts +2 -0
  34. package/src/repositories/moderation/get-moderation-by-id.test.ts +1 -1
  35. package/src/repositories/moderation/get-moderation-by-id.ts +1 -1
  36. package/src/repositories/organization/find-users-by-organization.ts +4 -12
  37. package/src/repositories/user_organisation/get-user-organization.test.ts +63 -0
  38. package/src/repositories/user_organisation/get-user-organization.ts +22 -0
  39. package/src/repositories/user_organisation/index.ts +1 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @proconnect-gouv/proconnect.identite
2
2
 
3
+ ## 10.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2154](https://github.com/proconnect-gouv/proconnect-identite/pull/2154) [`6894647`](https://github.com/proconnect-gouv/proconnect-identite/commit/6894647574f1482cf9a7064dc5188d09cf9ded2a) Thanks [@douglasduteil](https://github.com/douglasduteil)! - suppression des paramètres inutilisés additionalWhereClause et additionalParams de findUsersByOrganization
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`d7a9f69`](https://github.com/proconnect-gouv/proconnect-identite/commit/d7a9f69111ae9fe6b9c99a38e64258acc0663686)]:
12
+ - @proconnect-gouv/proconnect.core@1.1.0
13
+
14
+ ## 10.3.0
15
+
16
+ ### Minor Changes
17
+
18
+ - [#2175](https://github.com/proconnect-gouv/proconnect-identite/pull/2175) [`ab7f8af`](https://github.com/proconnect-gouv/proconnect-identite/commit/ab7f8af1394f815d9b7fa25726d7b482cc80b632) Thanks [@rdubigny](https://github.com/rdubigny)! - ajout de la fonction getUserOrganization dans les repositories
19
+
3
20
  ## 10.2.2
4
21
 
5
22
  ### Patch Changes
@@ -536,7 +536,7 @@ export declare function createContext({ api_entreprise_client, api_insee_client,
536
536
  findPendingByUserId: (user_id: number) => Promise<(import("../types/organization.js").Organization & {
537
537
  moderation_id: number;
538
538
  })[]>;
539
- findUsers: (organization_id: number, additionalWhereClause?: string, additionalParams?: any[]) => Promise<(import("../types/user.js").User & {
539
+ findUsers: (organization_id: number) => Promise<(import("../types/user.js").User & {
540
540
  is_external: boolean;
541
541
  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" | "no_verification_means_for_small_organization";
542
542
  verified_at: Date | null;
@@ -570,6 +570,16 @@ export declare function createContext({ api_entreprise_client, api_insee_client,
570
570
  created_at: Date;
571
571
  updated_at: Date;
572
572
  } | undefined>;
573
+ get: ({ organization_id, user_id, }: import("../types/user-organization-link.js").FindUserOrganizationLink) => Promise<{
574
+ is_external: boolean;
575
+ 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" | "no_verification_means_for_small_organization";
576
+ verified_at: Date | null;
577
+ has_been_greeted: boolean;
578
+ user_id: number;
579
+ organization_id: number;
580
+ created_at: Date;
581
+ updated_at: Date;
582
+ }>;
573
583
  update: ({ organization_id, user_id }: import("../types/user-organization-link.js").FindUserOrganizationLink, fieldsToUpdate: Partial<import("../types/user-organization-link.js").UserOrganizationLink>) => Promise<{
574
584
  is_external: boolean;
575
585
  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" | "no_verification_means_for_small_organization";
@@ -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;AAC5E,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AAC1H,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC;AAI/B,wBAAgB,aAAa,CAAC,EAC5B,qBAAqB,EACrB,gBAAgB,EAChB,wCAAwC,EACxC,EAAE,GACH,EAAE;IACD,qBAAqB,EAAE,mBAAmB,CAAC;IAC3C,gBAAgB,EAAE,cAAc,CAAC;IACjC,wCAAwC,EAAE,oCAAoC,CAAC;IAC/E,EAAE,EAAE,IAAI,CAAC;CACV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCA+Eu2F,CAAC;oBAAkC,CAAC;;mBAAmG,CAAC;sBAA2C,CAAC;8BAAmD,CAAC;wCAA6D,CAAC;8BAAmD,CAAC;8BAAmD,CAAC;mCAAwD,CAAC;2BAAgD,CAAC;gCAAqD,CAAC;8BAAmD,CAAC;2BAAgD,CAAC;8BAAmD,CAAC;;;;;qBAvJ98G,CAAC;qBAEpF,CAAC;0CAEZ,CAAC;sCACS,CAAC;uCAEI,CAAC;wCA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCADjB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoJP;AACD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
@@ -8,7 +8,7 @@ import { deleteOfficialContactEmailVerificationFactory, findOfficialContactEmail
8
8
  import { addConnectionFactory, findByClientIdFactory, } from "#src/repositories/oidc-client";
9
9
  import { findBySiretFactory, findByUserIdFactory, findByVerifiedEmailDomainFactory, findOrganizationByIdFactory, findPendingByUserIdFactory, findUsersByOrganizationFactory, getOrganizationByIdFactory, upsertFactory, } from "#src/repositories/organization";
10
10
  import { createUserFactory, deleteUserFactory, findByEmailFactory, findByMagicLinkTokenFactory, findByResetPasswordTokenFactory, findByIdFactory as findUserByIdFactory, getByIdFactory, updateUserFactory, } from "#src/repositories/user";
11
- import { createUserOrganizationFactory, deleteUserOrganizationFactory, findUserOrganizationFactory, updateUserOrganizationFactory, } from "#src/repositories/user_organisation";
11
+ import { createUserOrganizationFactory, deleteUserOrganizationFactory, findUserOrganizationFactory, getUserOrganizationFactory, updateUserOrganizationFactory, } from "#src/repositories/user_organisation";
12
12
  import {} from "pg";
13
13
  //
14
14
  export function createContext({ api_entreprise_client, api_insee_client, api_registre_national_entreprises_client, pg, }) {
@@ -66,6 +66,7 @@ export function createContext({ api_entreprise_client, api_insee_client, api_reg
66
66
  create: createUserOrganizationFactory({ pg }),
67
67
  delete: deleteUserOrganizationFactory({ pg }),
68
68
  find: findUserOrganizationFactory({ pg }),
69
+ get: getUserOrganizationFactory({ pg }),
69
70
  update: updateUserOrganizationFactory({ pg }),
70
71
  },
71
72
  users: {
@@ -13,4 +13,7 @@ export declare class OrganizationNotFoundError extends Error {
13
13
  export declare class UserNotFoundError extends Error {
14
14
  constructor(message?: string, options?: ErrorOptions);
15
15
  }
16
+ export declare class LinkNotFoundError extends Error {
17
+ constructor(message?: string, options?: ErrorOptions);
18
+ }
16
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAEA,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD;AAED,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD;AAED,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD;AAED,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAEA,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD;AAED,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD;AAED,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD;AAED,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD;AAED,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD"}
@@ -29,3 +29,9 @@ export class UserNotFoundError extends Error {
29
29
  this.name = "UserNotFoundError";
30
30
  }
31
31
  }
32
+ export class LinkNotFoundError extends Error {
33
+ constructor(message, options) {
34
+ super(message, options);
35
+ this.name = "LinkNotFoundError";
36
+ }
37
+ }
@@ -0,0 +1,44 @@
1
+ import type { IdentityVector } from "#src/types";
2
+ export declare function match_identity_to_dirigeant(identity: IdentityVector, dirigeants: IdentityVector[]): {
3
+ kind: "exact_match";
4
+ closest: {
5
+ dirigeant: {
6
+ birthcountry: string | null;
7
+ birthdate: Date | null;
8
+ birthplace: string | null;
9
+ family_name: string | null;
10
+ gender: "male" | "female" | null;
11
+ given_name: string | null;
12
+ };
13
+ matches: Set<"family_name" | "gender" | "birth_country" | "birth_date" | "birth_place" | "first_name">;
14
+ };
15
+ } | {
16
+ kind: "close_match";
17
+ closest: {
18
+ dirigeant: {
19
+ birthcountry: string | null;
20
+ birthdate: Date | null;
21
+ birthplace: string | null;
22
+ family_name: string | null;
23
+ gender: "male" | "female" | null;
24
+ given_name: string | null;
25
+ };
26
+ matches: Set<"family_name" | "gender" | "birth_country" | "birth_date" | "birth_place" | "first_name">;
27
+ };
28
+ } | {
29
+ kind: "below_threshold";
30
+ closest: {
31
+ dirigeant: {
32
+ birthcountry: string | null;
33
+ birthdate: Date | null;
34
+ birthplace: string | null;
35
+ family_name: string | null;
36
+ gender: "male" | "female" | null;
37
+ given_name: string | null;
38
+ };
39
+ matches: Set<"family_name" | "gender" | "birth_country" | "birth_date" | "birth_place" | "first_name">;
40
+ };
41
+ } | {
42
+ kind: "no_candidates";
43
+ };
44
+ //# sourceMappingURL=match-identity-to-dirigeant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match-identity-to-dirigeant.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/match-identity-to-dirigeant.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMjD,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,cAAc,EACxB,UAAU,EAAE,cAAc,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6B7B"}
@@ -0,0 +1,32 @@
1
+ //
2
+ import { match } from "ts-pattern";
3
+ import { certificationScore } from "./certification-score.js";
4
+ //
5
+ export function match_identity_to_dirigeant(identity, dirigeants) {
6
+ if (dirigeants.length === 0)
7
+ return { kind: "no_candidates" };
8
+ const [closest] = dirigeants
9
+ .map((dirigeant) => ({
10
+ dirigeant,
11
+ matches: certificationScore(identity, dirigeant),
12
+ }))
13
+ .toSorted((a, b) => b.matches.size - a.matches.size); // Sort by score descending (higher is better)
14
+ // According to the specification, only score of 5 (perfect match) is certified
15
+ return match(closest.matches.size)
16
+ .with(5, () => ({
17
+ kind: "exact_match",
18
+ closest,
19
+ }))
20
+ .with(4, () => ({
21
+ kind: "close_match",
22
+ closest,
23
+ }))
24
+ .with(3, () => ({
25
+ kind: "close_match",
26
+ closest,
27
+ }))
28
+ .otherwise(() => ({
29
+ kind: "below_threshold",
30
+ closest,
31
+ }));
32
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"process-certification-dirigeant.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/process-certification-dirigeant.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAEL,KAAK,qBAAqB,EAE1B,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,CAAC,MAAM,QAAQ,CAAC;AASvB,eAAO,MAAM,gCAAgC;;;;EAI3C,CAAC;AAEH,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CACpD,OAAO,gCAAgC,CACxC,CAAC;AAWF,wBAAgB,yCAAyC,CACvD,UAAU,EAAE,gCAAgC,UAG7C;AAoED,wBAAgB,oCAAoC,CAAC,OAAO,EAAE,OAAO,IAMjE,cAAc,YAAY,EAC1B,wBAAwB,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEhD"}
1
+ {"version":3,"file":"process-certification-dirigeant.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/process-certification-dirigeant.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,CAAC,MAAM,QAAQ,CAAC;AASvB,eAAO,MAAM,gCAAgC;;;;EAI3C,CAAC;AAEH,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CACpD,OAAO,gCAAgC,CACxC,CAAC;AAWF,wBAAgB,yCAAyC,CACvD,UAAU,EAAE,gCAAgC,UAG7C;AAmCD,wBAAgB,oCAAoC,CAAC,OAAO,EAAE,OAAO,IAMjE,cAAc,YAAY,EAC1B,wBAAwB,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEhD"}
@@ -7,7 +7,7 @@ import * as ApiEntreprise from "./adapters/api_entreprise.js";
7
7
  import * as FranceConnect from "./adapters/franceconnect.js";
8
8
  import * as INSEE from "./adapters/insee.js";
9
9
  import * as RNE from "./adapters/rne.js";
10
- import { certificationScore } from "./certification-score.js";
10
+ import { match_identity_to_dirigeant } from "./match-identity-to-dirigeant.js";
11
11
  //
12
12
  export const CertificationDirigeantDataSource = z.enum([
13
13
  "api.insee.fr/api-sirene/private",
@@ -42,34 +42,6 @@ async function getMandatairesSociaux({ client: { api_entreprise, rne } }, siren)
42
42
  };
43
43
  }
44
44
  }
45
- function match_identity_to_dirigeant(identity, dirigeants) {
46
- if (dirigeants.length === 0)
47
- return { kind: "no_candidates" };
48
- const [closest] = dirigeants
49
- .map((dirigeant) => ({
50
- dirigeant,
51
- matches: certificationScore(identity, dirigeant),
52
- }))
53
- .toSorted((a, b) => b.matches.size - a.matches.size); // Sort by score descending (higher is better)
54
- // According to the specification, only score of 5 (perfect match) is certified
55
- return match(closest.matches.size)
56
- .with(5, () => ({
57
- kind: "exact_match",
58
- closest,
59
- }))
60
- .with(4, () => ({
61
- kind: "close_match",
62
- closest,
63
- }))
64
- .with(3, () => ({
65
- kind: "close_match",
66
- closest,
67
- }))
68
- .otherwise(() => ({
69
- kind: "below_threshold",
70
- closest,
71
- }));
72
- }
73
45
  export function processCertificationDirigeantFactory(context) {
74
46
  const { client: { insee }, } = context;
75
47
  return async function processCertificationDirigeant(organization, franceconnect_userinfo) {
@@ -1 +1 @@
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"}
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;;;;;;;;;GAkFF;AAED,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAClD,OAAO,2BAA2B,CACnC,CAAC"}
@@ -36,6 +36,7 @@ export function markDomainAsVerifiedFactory(context) {
36
36
  domain_verification_types: [
37
37
  ...EmailDomainApprovedVerificationValues,
38
38
  ...EmailDomainPendingVerificationValues,
39
+ ...EmailDomainRejectedVerificationValues,
39
40
  ],
40
41
  });
41
42
  return email_domains.addDomain({
@@ -49,6 +50,7 @@ export function markDomainAsVerifiedFactory(context) {
49
50
  organization_id,
50
51
  domain,
51
52
  domain_verification_types: [
53
+ ...EmailDomainApprovedVerificationValues,
52
54
  ...EmailDomainPendingVerificationValues,
53
55
  ...EmailDomainRejectedVerificationValues,
54
56
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"get-moderation-by-id.d.ts","sourceRoot":"","sources":["../../../src/repositories/moderation/get-moderation-by-id.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAMnE,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IAGtB,IAAI,MAAM,KAAG,OAAO,CAAC,UAAU,CAAC,CAOzE"}
1
+ {"version":3,"file":"get-moderation-by-id.d.ts","sourceRoot":"","sources":["../../../src/repositories/moderation/get-moderation-by-id.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAKnE,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IAGtB,IAAI,MAAM,KAAG,OAAO,CAAC,UAAU,CAAC,CAOzE"}
@@ -1,6 +1,6 @@
1
1
  //
2
+ import { ModerationNotFoundError } from "#src/errors";
2
3
  import {} from "#src/types";
3
- import { ModerationNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
4
4
  import { findModerationByIdFactory } from "./find-moderation-by-id.js";
5
5
  //
6
6
  export function getModerationByIdFactory({ pg }) {
@@ -1,5 +1,5 @@
1
1
  import type { DatabaseContext, User } from "#src/types";
2
- export declare function findUsersByOrganizationFactory({ pg }: DatabaseContext): (organization_id: number, additionalWhereClause?: string, additionalParams?: any[]) => Promise<(User & {
2
+ export declare function findUsersByOrganizationFactory({ pg }: DatabaseContext): (organization_id: number) => Promise<(User & {
3
3
  is_external: boolean;
4
4
  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" | "no_verification_means_for_small_organization";
5
5
  verified_at: Date | null;
@@ -1 +1 @@
1
- {"version":3,"file":"find-users-by-organization.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/find-users-by-organization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,eAAe,EACf,IAAI,EACL,MAAM,YAAY,CAAC;AAKpB,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IAElE,iBAAiB,MAAM,EACvB,wBAAuB,MAAW,EAClC,mBAAkB,GAAG,EAAO;;;;;MAsB/B"}
1
+ {"version":3,"file":"find-users-by-organization.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/find-users-by-organization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,eAAe,EACf,IAAI,EACL,MAAM,YAAY,CAAC;AAKpB,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,iBAAiB,MAAM;;;;;MAiBtE"}
@@ -1,10 +1,8 @@
1
1
  //
2
2
  //
3
3
  export function findUsersByOrganizationFactory({ pg }) {
4
- return async function findUsersByOrganization(organization_id, additionalWhereClause = "", additionalParams = []) {
5
- const connection = pg;
6
- const baseParams = [organization_id];
7
- const { rows } = await connection.query(`
4
+ return async function findUsersByOrganization(organization_id) {
5
+ const { rows } = await pg.query(`
8
6
  SELECT u.*,
9
7
  uo.is_external,
10
8
  uo.verification_type,
@@ -12,8 +10,7 @@ export function findUsersByOrganizationFactory({ pg }) {
12
10
  uo.has_been_greeted
13
11
  FROM users u
14
12
  INNER JOIN users_organizations AS uo ON uo.user_id = u.id
15
- WHERE uo.organization_id = $1
16
- ${additionalWhereClause}`, [...baseParams, ...additionalParams]);
13
+ WHERE uo.organization_id = $1`, [organization_id]);
17
14
  return rows;
18
15
  };
19
16
  }
@@ -0,0 +1,12 @@
1
+ import type { DatabaseContext, FindUserOrganizationLink } from "#src/types";
2
+ export declare function getUserOrganizationFactory({ pg }: DatabaseContext): ({ organization_id, user_id, }: FindUserOrganizationLink) => Promise<{
3
+ is_external: boolean;
4
+ 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" | "no_verification_means_for_small_organization";
5
+ verified_at: Date | null;
6
+ has_been_greeted: boolean;
7
+ user_id: number;
8
+ organization_id: number;
9
+ created_at: Date;
10
+ updated_at: Date;
11
+ }>;
12
+ //# sourceMappingURL=get-user-organization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-user-organization.d.ts","sourceRoot":"","sources":["../../../src/repositories/user_organisation/get-user-organization.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAM5E,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IAEtB,+BAGvC,wBAAwB;;;;;;;;;GAO5B"}
@@ -0,0 +1,15 @@
1
+ //
2
+ import { LinkNotFoundError } from "#src/errors";
3
+ import { isEmpty } from "lodash-es";
4
+ import { findUserOrganizationFactory } from "./find-user-organization.js";
5
+ //
6
+ export function getUserOrganizationFactory({ pg }) {
7
+ const findUserOrganization = findUserOrganizationFactory({ pg });
8
+ return async function getUserOrganization({ organization_id, user_id, }) {
9
+ const link = await findUserOrganization({ organization_id, user_id });
10
+ if (isEmpty(link)) {
11
+ throw new LinkNotFoundError("Link not found");
12
+ }
13
+ return link;
14
+ };
15
+ }
@@ -1,5 +1,6 @@
1
1
  export * from "./create-user-organization.js";
2
2
  export * from "./delete-user-organization.js";
3
3
  export * from "./find-user-organization.js";
4
+ export * from "./get-user-organization.js";
4
5
  export * from "./update-user-organization.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/user_organisation/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/user_organisation/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from "./create-user-organization.js";
2
2
  export * from "./delete-user-organization.js";
3
3
  export * from "./find-user-organization.js";
4
+ export * from "./get-user-organization.js";
4
5
  export * from "./update-user-organization.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proconnect-gouv/proconnect.identite",
3
- "version": "10.2.2",
3
+ "version": "10.4.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": {
@@ -53,7 +53,7 @@
53
53
  "@electric-sql/pglite": "^0.3.12",
54
54
  "@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.5",
55
55
  "@proconnect-gouv/proconnect.api_entreprise": "^2.3.0",
56
- "@proconnect-gouv/proconnect.core": "^1.0.0",
56
+ "@proconnect-gouv/proconnect.core": "^1.1.0",
57
57
  "@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
58
58
  "@proconnect-gouv/proconnect.insee": "^2.0.0",
59
59
  "@proconnect-gouv/proconnect.registre_national_entreprises": "^4.1.0",
@@ -67,7 +67,7 @@
67
67
  "peerDependencies": {
68
68
  "@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.5",
69
69
  "@proconnect-gouv/proconnect.api_entreprise": "^2.3.0",
70
- "@proconnect-gouv/proconnect.core": "^1.0.0",
70
+ "@proconnect-gouv/proconnect.core": "^1.1.0",
71
71
  "@proconnect-gouv/proconnect.insee": "^2.0.0",
72
72
  "@proconnect-gouv/proconnect.registre_national_entreprises": "^4.1.0"
73
73
  },
@@ -60,6 +60,7 @@ import {
60
60
  createUserOrganizationFactory,
61
61
  deleteUserOrganizationFactory,
62
62
  findUserOrganizationFactory,
63
+ getUserOrganizationFactory,
63
64
  updateUserOrganizationFactory,
64
65
  } from "#src/repositories/user_organisation";
65
66
  import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entreprise/api";
@@ -137,6 +138,7 @@ export function createContext({
137
138
  create: createUserOrganizationFactory({ pg }),
138
139
  delete: deleteUserOrganizationFactory({ pg }),
139
140
  find: findUserOrganizationFactory({ pg }),
141
+ get: getUserOrganizationFactory({ pg }),
140
142
  update: updateUserOrganizationFactory({ pg }),
141
143
  },
142
144
  users: {
@@ -34,3 +34,10 @@ export class UserNotFoundError extends Error {
34
34
  this.name = "UserNotFoundError";
35
35
  }
36
36
  }
37
+
38
+ export class LinkNotFoundError extends Error {
39
+ constructor(message?: string, options?: ErrorOptions) {
40
+ super(message, options);
41
+ this.name = "LinkNotFoundError";
42
+ }
43
+ }
@@ -0,0 +1,62 @@
1
+ //
2
+
3
+ import assert from "node:assert/strict";
4
+ import { describe, it } from "node:test";
5
+ import { match_identity_to_dirigeant } from "./match-identity-to-dirigeant.js";
6
+
7
+ //
8
+
9
+ const identity = {
10
+ birthcountry: null,
11
+ birthdate: new Date("1946-08-17"),
12
+ birthplace: "75001",
13
+ family_name: "Bernard",
14
+ gender: "male" as const,
15
+ given_name: "Stéphane",
16
+ };
17
+
18
+ describe("match_identity_to_dirigeant", () => {
19
+ it("returns no_candidates for an empty dirigeants list", () => {
20
+ assert.deepEqual(match_identity_to_dirigeant(identity, []), {
21
+ kind: "no_candidates",
22
+ });
23
+ });
24
+
25
+ it("returns exact_match for a score of 5", () => {
26
+ const result = match_identity_to_dirigeant(identity, [identity]);
27
+ assert.equal(result.kind, "exact_match");
28
+ });
29
+
30
+ it("returns close_match for a score of 4", () => {
31
+ const dirigeant = { ...identity, family_name: "DuMoulin" };
32
+ const result = match_identity_to_dirigeant(identity, [dirigeant]);
33
+ assert.equal(result.kind, "close_match");
34
+ });
35
+
36
+ it("returns close_match for a score of 3", () => {
37
+ const dirigeant = {
38
+ ...identity,
39
+ family_name: "DuMoulin",
40
+ given_name: "Robert",
41
+ };
42
+ const result = match_identity_to_dirigeant(identity, [dirigeant]);
43
+ assert.equal(result.kind, "close_match");
44
+ });
45
+
46
+ it("returns below_threshold for a score under 3", () => {
47
+ const dirigeant = {
48
+ ...identity,
49
+ family_name: "DuMoulin",
50
+ given_name: "Robert",
51
+ gender: "female" as const,
52
+ };
53
+ const result = match_identity_to_dirigeant(identity, [dirigeant]);
54
+ assert.equal(result.kind, "below_threshold");
55
+ });
56
+
57
+ it("picks the highest-scoring candidate among several", () => {
58
+ const weak = { ...identity, family_name: "DuMoulin", given_name: "Robert" };
59
+ const result = match_identity_to_dirigeant(identity, [weak, identity]);
60
+ assert.equal(result.kind, "exact_match");
61
+ });
62
+ });
@@ -0,0 +1,40 @@
1
+ //
2
+
3
+ import type { IdentityVector } from "#src/types";
4
+ import { match } from "ts-pattern";
5
+ import { certificationScore } from "./certification-score.js";
6
+
7
+ //
8
+
9
+ export function match_identity_to_dirigeant(
10
+ identity: IdentityVector,
11
+ dirigeants: IdentityVector[],
12
+ ) {
13
+ if (dirigeants.length === 0) return { kind: "no_candidates" as const };
14
+
15
+ const [closest] = dirigeants
16
+ .map((dirigeant) => ({
17
+ dirigeant,
18
+ matches: certificationScore(identity, dirigeant),
19
+ }))
20
+ .toSorted((a, b) => b.matches.size - a.matches.size); // Sort by score descending (higher is better)
21
+
22
+ // According to the specification, only score of 5 (perfect match) is certified
23
+ return match(closest.matches.size)
24
+ .with(5, () => ({
25
+ kind: "exact_match" as const,
26
+ closest,
27
+ }))
28
+ .with(4, () => ({
29
+ kind: "close_match" as const,
30
+ closest,
31
+ }))
32
+ .with(3, () => ({
33
+ kind: "close_match" as const,
34
+ closest,
35
+ }))
36
+ .otherwise(() => ({
37
+ kind: "below_threshold" as const,
38
+ closest,
39
+ }));
40
+ }
@@ -5,7 +5,6 @@ import { isOrganizationCoveredByCertificationDirigeant } from "#src/services/org
5
5
  import {
6
6
  NullIdentityVector,
7
7
  type FranceConnectUserInfo,
8
- type IdentityVector,
9
8
  type Organization,
10
9
  } from "#src/types";
11
10
  import { match } from "ts-pattern";
@@ -14,7 +13,7 @@ import * as ApiEntreprise from "./adapters/api_entreprise.js";
14
13
  import * as FranceConnect from "./adapters/franceconnect.js";
15
14
  import * as INSEE from "./adapters/insee.js";
16
15
  import * as RNE from "./adapters/rne.js";
17
- import { certificationScore } from "./certification-score.js";
16
+ import { match_identity_to_dirigeant } from "./match-identity-to-dirigeant.js";
18
17
 
19
18
  //
20
19
 
@@ -76,39 +75,6 @@ async function getMandatairesSociaux(
76
75
  }
77
76
  }
78
77
 
79
- function match_identity_to_dirigeant(
80
- identity: IdentityVector,
81
- dirigeants: IdentityVector[],
82
- ) {
83
- if (dirigeants.length === 0) return { kind: "no_candidates" as const };
84
-
85
- const [closest] = dirigeants
86
- .map((dirigeant) => ({
87
- dirigeant,
88
- matches: certificationScore(identity, dirigeant),
89
- }))
90
- .toSorted((a, b) => b.matches.size - a.matches.size); // Sort by score descending (higher is better)
91
-
92
- // According to the specification, only score of 5 (perfect match) is certified
93
- return match(closest.matches.size)
94
- .with(5, () => ({
95
- kind: "exact_match" as const,
96
- closest,
97
- }))
98
- .with(4, () => ({
99
- kind: "close_match" as const,
100
- closest,
101
- }))
102
- .with(3, () => ({
103
- kind: "close_match" as const,
104
- closest,
105
- }))
106
- .otherwise(() => ({
107
- kind: "below_threshold" as const,
108
- closest,
109
- }));
110
- }
111
-
112
78
  export function processCertificationDirigeantFactory(context: Context) {
113
79
  const {
114
80
  client: { insee },
@@ -63,6 +63,180 @@ describe("markDomainAsVerified", () => {
63
63
  ]);
64
64
  });
65
65
 
66
+ it("approving a domain should replace an existing rejection for the same domain", async () => {
67
+ await pg.sql`
68
+ INSERT INTO organizations
69
+ (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
70
+ VALUES
71
+ (1, 'Night Lords', 'Night Lords Legion', '🦇', '4444-04-04', '4444-04-04')
72
+ ;
73
+ `;
74
+ await pg.sql`
75
+ INSERT INTO email_domains (organization_id, domain, verification_type)
76
+ VALUES (1, 'nightlords.world', 'refused')
77
+ `;
78
+
79
+ await markDomainAsVerified({
80
+ domain: "nightlords.world",
81
+ domain_verification_type: "verified",
82
+ organization_id: 1,
83
+ });
84
+
85
+ const { rows: emailDomains } = await pg.sql`
86
+ SELECT domain, verification_type
87
+ FROM email_domains
88
+ WHERE organization_id = 1
89
+ ORDER BY verification_type
90
+ `;
91
+ assert.deepEqual(emailDomains, [
92
+ { domain: "nightlords.world", verification_type: "verified" },
93
+ ]);
94
+ });
95
+
96
+ it("rejecting a domain should replace an existing approval for the same domain", async () => {
97
+ await pg.sql`
98
+ INSERT INTO organizations
99
+ (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
100
+ VALUES
101
+ (1, 'Thousand Sons', 'Thousand Sons Legion', '📖', '4444-04-04', '4444-04-04')
102
+ ;
103
+ `;
104
+ await pg.sql`
105
+ INSERT INTO email_domains (organization_id, domain, verification_type)
106
+ VALUES (1, 'thousandsons.world', 'verified')
107
+ `;
108
+
109
+ await markDomainAsVerified({
110
+ domain: "thousandsons.world",
111
+ domain_verification_type: "refused",
112
+ organization_id: 1,
113
+ });
114
+
115
+ const { rows: emailDomains } = await pg.sql`
116
+ SELECT domain, verification_type
117
+ FROM email_domains
118
+ WHERE organization_id = 1
119
+ ORDER BY verification_type
120
+ `;
121
+ assert.deepEqual(emailDomains, [
122
+ { domain: "thousandsons.world", verification_type: "refused" },
123
+ ]);
124
+ });
125
+
126
+ it("should reject a pending domain", async () => {
127
+ await pg.sql`
128
+ INSERT INTO organizations
129
+ (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
130
+ VALUES
131
+ (1, 'Black Legion', 'Black Legion Warband', '👁️', '4444-04-04', '4444-04-04')
132
+ ;
133
+ `;
134
+ await pg.sql`
135
+ INSERT INTO email_domains (organization_id, domain, verification_type)
136
+ VALUES (1, 'blacklegion.world', 'not_verified_yet')
137
+ `;
138
+
139
+ await markDomainAsVerified({
140
+ domain: "blacklegion.world",
141
+ domain_verification_type: "refused",
142
+ organization_id: 1,
143
+ });
144
+
145
+ const { rows: emailDomains } = await pg.sql`
146
+ SELECT domain, verification_type
147
+ FROM email_domains
148
+ WHERE organization_id = 1
149
+ ORDER BY verification_type
150
+ `;
151
+ assert.deepEqual(emailDomains, [
152
+ { domain: "blacklegion.world", verification_type: "refused" },
153
+ ]);
154
+ });
155
+
156
+ it("rejecting a domain should not demote an already domain-verified member", async () => {
157
+ await pg.sql`
158
+ INSERT INTO organizations
159
+ (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
160
+ VALUES
161
+ (1, 'Word Bearers', 'Word Bearers Legion', '🔥', '4444-04-04', '4444-04-04')
162
+ ;
163
+ `;
164
+ await pg.sql`
165
+ INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
166
+ VALUES (1, 'lorgar.aurelian@wordbearers.world', '4444-04-04', '4444-04-04', 'Lorgar', 'Aurelian', '0', 'Primarque')
167
+ `;
168
+ await pg.sql`
169
+ INSERT INTO users_organizations
170
+ (user_id, organization_id, created_at, updated_at, is_external, verification_type)
171
+ VALUES
172
+ (1, 1, '4444-04-04', '4444-04-04', false, 'domain')
173
+ ;
174
+ `;
175
+ await pg.sql`
176
+ INSERT INTO email_domains (organization_id, domain, verification_type)
177
+ VALUES (1, 'wordbearers.world', 'not_verified_yet')
178
+ `;
179
+
180
+ await markDomainAsVerified({
181
+ domain: "wordbearers.world",
182
+ domain_verification_type: "refused",
183
+ organization_id: 1,
184
+ });
185
+
186
+ const { rows: userLinks } = await pg.sql`
187
+ SELECT user_id, verification_type
188
+ FROM users_organizations
189
+ WHERE organization_id = 1
190
+ `;
191
+ assert.deepEqual(userLinks, [{ user_id: 1, verification_type: "domain" }]);
192
+ });
193
+
194
+ it("approving a domain should only promote eligible member links", async () => {
195
+ await pg.sql`
196
+ INSERT INTO organizations
197
+ (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
198
+ VALUES
199
+ (1, 'Emperor''s Children', 'Emperor''s Children Legion', '🎭', '4444-04-04', '4444-04-04')
200
+ ;
201
+ `;
202
+ await pg.sql`
203
+ INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
204
+ VALUES
205
+ (1, 'fulgrim@emperorschildren.world', '4444-04-04', '4444-04-04', 'Fulgrim', 'Primarque', '0', 'Primarque'),
206
+ (2, 'lucius@emperorschildren.world', '4444-04-04', '4444-04-04', 'Lucius', 'The Eternal', '0', 'Champion')
207
+ ;
208
+ `;
209
+ await pg.sql`
210
+ INSERT INTO users_organizations
211
+ (user_id, organization_id, created_at, updated_at, is_external, verification_type)
212
+ VALUES
213
+ (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle'),
214
+ (2, 1, '4444-04-04', '4444-04-04', false, 'organization_dirigeant')
215
+ ;
216
+ `;
217
+ await pg.sql`
218
+ INSERT INTO email_domains (organization_id, domain, verification_type)
219
+ VALUES (1, 'emperorschildren.world', 'not_verified_yet')
220
+ `;
221
+
222
+ await markDomainAsVerified({
223
+ domain: "emperorschildren.world",
224
+ domain_verification_type: "verified",
225
+ organization_id: 1,
226
+ });
227
+
228
+ const { rows: userLinks } = await pg.sql`
229
+ SELECT user_id, verification_type
230
+ FROM users_organizations
231
+ WHERE organization_id = 1
232
+ ORDER BY user_id
233
+ `;
234
+ assert.deepEqual(userLinks, [
235
+ { user_id: 1, verification_type: "domain" },
236
+ { user_id: 2, verification_type: "organization_dirigeant" },
237
+ ]);
238
+ });
239
+
66
240
  it("❎ throws NotFoundError for unknown organization", async () => {
67
241
  await assert.rejects(
68
242
  markDomainAsVerified({
@@ -80,6 +80,7 @@ export function markDomainAsVerifiedFactory(context: Context) {
80
80
  domain_verification_types: [
81
81
  ...EmailDomainApprovedVerificationValues,
82
82
  ...EmailDomainPendingVerificationValues,
83
+ ...EmailDomainRejectedVerificationValues,
83
84
  ],
84
85
  });
85
86
  return email_domains.addDomain({
@@ -103,6 +104,7 @@ export function markDomainAsVerifiedFactory(context: Context) {
103
104
  organization_id,
104
105
  domain,
105
106
  domain_verification_types: [
107
+ ...EmailDomainApprovedVerificationValues,
106
108
  ...EmailDomainPendingVerificationValues,
107
109
  ...EmailDomainRejectedVerificationValues,
108
110
  ],
@@ -1,7 +1,7 @@
1
1
  //
2
2
 
3
+ import { ModerationNotFoundError } from "#src/errors";
3
4
  import { emptyDatabase, migrate, pg } from "#testing";
4
- import { ModerationNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
5
5
  import assert from "node:assert/strict";
6
6
  import { before, beforeEach, suite, test } from "node:test";
7
7
  import { getModerationByIdFactory } from "./get-moderation-by-id.js";
@@ -1,7 +1,7 @@
1
1
  //
2
2
 
3
+ import { ModerationNotFoundError } from "#src/errors";
3
4
  import { type DatabaseContext, type Moderation } from "#src/types";
4
- import { ModerationNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
5
5
  import { findModerationByIdFactory } from "./find-moderation-by-id.js";
6
6
 
7
7
  //
@@ -10,16 +10,9 @@ import type { QueryResult } from "pg";
10
10
  //
11
11
 
12
12
  export function findUsersByOrganizationFactory({ pg }: DatabaseContext) {
13
- return async function findUsersByOrganization(
14
- organization_id: number,
15
- additionalWhereClause: string = "",
16
- additionalParams: any[] = [],
17
- ) {
18
- const connection = pg;
19
- const baseParams = [organization_id];
20
-
13
+ return async function findUsersByOrganization(organization_id: number) {
21
14
  const { rows }: QueryResult<User & BaseUserOrganizationLink> =
22
- await connection.query(
15
+ await pg.query(
23
16
  `
24
17
  SELECT u.*,
25
18
  uo.is_external,
@@ -28,9 +21,8 @@ export function findUsersByOrganizationFactory({ pg }: DatabaseContext) {
28
21
  uo.has_been_greeted
29
22
  FROM users u
30
23
  INNER JOIN users_organizations AS uo ON uo.user_id = u.id
31
- WHERE uo.organization_id = $1
32
- ${additionalWhereClause}`,
33
- [...baseParams, ...additionalParams],
24
+ WHERE uo.organization_id = $1`,
25
+ [organization_id],
34
26
  );
35
27
 
36
28
  return rows;
@@ -0,0 +1,63 @@
1
+ //
2
+
3
+ import { LinkNotFoundError } from "#src/errors";
4
+ import { emptyDatabase, migrate, pg } from "#testing";
5
+ import assert from "node:assert/strict";
6
+ import { before, beforeEach, suite, test } from "node:test";
7
+ import { getUserOrganizationFactory } from "./get-user-organization.js";
8
+
9
+ //
10
+
11
+ const getUserOrganization = getUserOrganizationFactory({ pg: pg as any });
12
+
13
+ suite("getUserOrganizationFactory", () => {
14
+ before(migrate);
15
+ beforeEach(emptyDatabase);
16
+
17
+ test("should get the link between a user and an organization", async () => {
18
+ await pg.sql`
19
+ INSERT INTO organizations
20
+ (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
21
+ VALUES
22
+ ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
23
+ ;
24
+ `;
25
+ await pg.sql`
26
+ INSERT INTO users
27
+ (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
28
+ VALUES
29
+ (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
30
+ ;
31
+ `;
32
+ await pg.sql`
33
+ INSERT INTO users_organizations
34
+ (user_id, organization_id, created_at, updated_at, verification_type)
35
+ VALUES
36
+ (1, 1, '4444-04-04', '4444-04-04', 'domain_not_verified_yet')
37
+ ;
38
+ `;
39
+
40
+ const link = await getUserOrganization({
41
+ organization_id: 1,
42
+ user_id: 1,
43
+ });
44
+
45
+ assert.deepEqual(link, {
46
+ created_at: new Date("4444-04-04"),
47
+ has_been_greeted: false,
48
+ is_external: false,
49
+ organization_id: 1,
50
+ updated_at: new Date("4444-04-04"),
51
+ user_id: 1,
52
+ verification_type: "domain_not_verified_yet",
53
+ verified_at: null,
54
+ });
55
+ });
56
+
57
+ test("❎ fail to find a link that does not exist", async () => {
58
+ await assert.rejects(
59
+ getUserOrganization({ organization_id: 42, user_id: 42 }),
60
+ new LinkNotFoundError("Link not found"),
61
+ );
62
+ });
63
+ });
@@ -0,0 +1,22 @@
1
+ //
2
+
3
+ import { LinkNotFoundError } from "#src/errors";
4
+ import type { DatabaseContext, FindUserOrganizationLink } from "#src/types";
5
+ import { isEmpty } from "lodash-es";
6
+ import { findUserOrganizationFactory } from "./find-user-organization.js";
7
+
8
+ //
9
+
10
+ export function getUserOrganizationFactory({ pg }: DatabaseContext) {
11
+ const findUserOrganization = findUserOrganizationFactory({ pg });
12
+ return async function getUserOrganization({
13
+ organization_id,
14
+ user_id,
15
+ }: FindUserOrganizationLink) {
16
+ const link = await findUserOrganization({ organization_id, user_id });
17
+ if (isEmpty(link)) {
18
+ throw new LinkNotFoundError("Link not found");
19
+ }
20
+ return link;
21
+ };
22
+ }
@@ -1,4 +1,5 @@
1
1
  export * from "./create-user-organization.js";
2
2
  export * from "./delete-user-organization.js";
3
3
  export * from "./find-user-organization.js";
4
+ export * from "./get-user-organization.js";
4
5
  export * from "./update-user-organization.js";