@proconnect-gouv/proconnect.identite 15.0.0 → 16.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 (43) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/connectors/index.d.ts +2 -1
  3. package/dist/connectors/index.d.ts.map +1 -1
  4. package/dist/connectors/index.js +2 -1
  5. package/dist/managers/certification/certification-score.d.ts +16 -0
  6. package/dist/managers/certification/certification-score.d.ts.map +1 -1
  7. package/dist/managers/certification/certification-score.js +65 -41
  8. package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.d.ts +3 -0
  9. package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.d.ts.map +1 -0
  10. package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.js +12 -0
  11. package/dist/repositories/authenticator/index.d.ts +1 -0
  12. package/dist/repositories/authenticator/index.d.ts.map +1 -1
  13. package/dist/repositories/authenticator/index.js +1 -0
  14. package/dist/repositories/oidc-client/upsert-authorization-request.d.ts +1 -1
  15. package/dist/repositories/oidc-client/upsert-authorization-request.d.ts.map +1 -1
  16. package/dist/repositories/oidc-client/upsert-authorization-request.js +6 -4
  17. package/dist/services/organization/get-membership-changes-by-domain-verification.d.ts +18 -0
  18. package/dist/services/organization/get-membership-changes-by-domain-verification.d.ts.map +1 -0
  19. package/dist/services/organization/get-membership-changes-by-domain-verification.js +21 -0
  20. package/dist/services/organization/index.d.ts +1 -1
  21. package/dist/services/organization/index.d.ts.map +1 -1
  22. package/dist/services/organization/index.js +1 -1
  23. package/dist/types/authorization-request.d.ts +2 -0
  24. package/dist/types/authorization-request.d.ts.map +1 -1
  25. package/dist/types/authorization-request.js +4 -1
  26. package/package.json +1 -1
  27. package/src/connectors/index.ts +2 -0
  28. package/src/managers/certification/certification-score.test.ts +64 -1
  29. package/src/managers/certification/certification-score.ts +84 -50
  30. package/src/repositories/authenticator/delete-all-authenticators-by-user-id.test.ts +51 -0
  31. package/src/repositories/authenticator/delete-all-authenticators-by-user-id.ts +22 -0
  32. package/src/repositories/authenticator/index.ts +1 -0
  33. package/src/repositories/oidc-client/upsert-authorization-request.test.ts +18 -5
  34. package/src/repositories/oidc-client/upsert-authorization-request.ts +6 -3
  35. package/src/services/organization/get-membership-changes-by-domain-verification.test.ts +91 -0
  36. package/src/services/organization/get-membership-changes-by-domain-verification.ts +46 -0
  37. package/src/services/organization/index.ts +1 -1
  38. package/src/types/authorization-request.ts +5 -1
  39. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts +0 -9
  40. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts.map +0 -1
  41. package/dist/services/organization/get-member-ids-promoted-by-domain.js +0 -11
  42. package/src/services/organization/get-member-ids-promoted-by-domain.test.ts +0 -100
  43. package/src/services/organization/get-member-ids-promoted-by-domain.ts +0 -27
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @proconnect-gouv/proconnect.identite
2
2
 
3
+ ## 16.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#2453](https://github.com/proconnect-gouv/proconnect-identite/pull/2453) [`918ab32`](https://github.com/proconnect-gouv/proconnect-identite/commit/918ab32555b01df0363e8d531b6c6a4331ef0970) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Remplace `getMemberIdsPromotedByDomain` (`services/organization`) par `getMembershipChangesByDomainVerification({ domain, members, verification_type })`, la règle unique de ce qu'un domaine validé ou refusé fait aux membres de l'organisation dont l'email est sur ce domaine. Pour un type validé, elle renvoie `{ kind: "domain_approved", promoted_members, verification_type }` avec les membres non vérifiés ou `domain_not_verified_yet` ; pour un type refusé, `{ kind: "domain_refused", removed_members, verification_type }` avec tous les membres du domaine, quel que soit leur rattachement.
8
+
9
+ - [#2429](https://github.com/proconnect-gouv/proconnect-identite/pull/2429) [`304e89d`](https://github.com/proconnect-gouv/proconnect-identite/commit/304e89d2169c5a112af5d1465799151ebf9a871a) Thanks [@douglasduteil](https://github.com/douglasduteil)! - AuthorizationRequestOutcomeEnum gagne la valeur signed_out : une ligne de users_oidc_clients avec outcome = 'signed_out' enregistre une déconnexion demandée par un service ; un match exhaustif sur l'enum doit traiter ce cas. Ajout de la colonne sid à users_oidc_clients (identifiant de session oidc-provider propre au service) : BaseAuthorizationRequest gagne sid obligatoire, et upsertAuthorizationRequest le conserve quand une écriture suivante de la même interaction n'en a pas
10
+
11
+ ### Minor Changes
12
+
13
+ - [#2445](https://github.com/proconnect-gouv/proconnect-identite/pull/2445) [`efdd64d`](https://github.com/proconnect-gouv/proconnect-identite/commit/efdd64d8c342b586c76ac4e6717323d4486bf16d) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Le runtime ajoute `certificationDirigeantActivities` (schémas zod des actions `certification_dirigeant.certified`, `.close_matched`, `.not_matched` et `.not_covered`) et `getCertificationDirigeantActivity`, qui transforme le résultat de `processCertificationDirigeant` en l'une de ces actions. `outcome` porte le registre consulté, la raison d'un échec et, pour une correspondance partielle seulement, `diff` : pour chaque critère discordant, la valeur FranceConnect et celle du registre, telles que reçues (`raw`) et telles que comparées (`compared`). Ces schémas ne font pas encore partie de `activityContextSchemas` : l'application qui les écrit les passe à `createIdentiteRuntime` comme ses propres actions, et un lecteur du journal les ajoute à ses schémas. identite exporte `compareCriteria`, d'où `certificationScore` tire désormais ses critères concordants.
14
+
3
15
  ## 15.0.0
4
16
 
5
17
  ### Major Changes
@@ -368,6 +368,7 @@ export declare function createContext({ api_entreprise_client, api_insee_client,
368
368
  authenticator: import("../types/authenticator.js").BaseAuthenticator;
369
369
  }) => Promise<import("../types/authenticator.js").Authenticator>;
370
370
  delete: (user_id: number, credential_id: string) => Promise<boolean>;
371
+ deleteAllByUserId: (user_id: number) => Promise<boolean>;
371
372
  find: (user_id: number, serialized_credential_id: string) => Promise<import("../types/authenticator.js").Authenticator | undefined>;
372
373
  findByUserId: (user_id: number) => Promise<import("../types/authenticator.js").Authenticator[]>;
373
374
  update: (credential_id: import("../types/authenticator.js").Base64URLString, { counter, last_used_at, usage_count }: Partial<import("../types/authenticator.js").BaseAuthenticator>) => Promise<import("../types/authenticator.js").Authenticator>;
@@ -494,7 +495,7 @@ export declare function createContext({ api_entreprise_client, api_insee_client,
494
495
  };
495
496
  oidc_clients: {
496
497
  findByClientId: (client_id: string) => Promise<import("../types/oidc-client.js").OidcClient | undefined>;
497
- upsertAuthorizationRequest: ({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, interaction_cid, outcome, }: import("../types/authorization-request.js").BaseAuthorizationRequest) => Promise<import("../types/authorization-request.js").AuthorizationRequest>;
498
+ upsertAuthorizationRequest: ({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, interaction_cid, outcome, sid, }: import("../types/authorization-request.js").BaseAuthorizationRequest) => Promise<import("../types/authorization-request.js").AuthorizationRequest>;
498
499
  };
499
500
  organizations: {
500
501
  findById: (id: number) => Promise<import("../types/organization.js").Organization | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectors/index.ts"],"names":[],"mappings":"AA0DA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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yBAEX,CAAC;2BACL,CAAD;sCAAkC,CAAC;uCACH,CAAC;wCACA,CAAC;kDAG3B,CAAC;yCAGP,CAAD;4CAEC,CAAD;2DAEC,CAAC;2DAEe,CAAC;+CAEf,CAAC;mDAAiE,CAAC;iDAC1B,CAAC;2DACD,CAAC;+DAC9C,CAAC;yDAKE,CAAC;iEAEkC,CAAC;6DAI1B,CAAC;;;;;;wCAQe,CAAC;kDAEd,CAAC;wDAEU,CAAC;iDACP,CAAC;;;;;kCAGK,CAAC;;qBACP,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAhFkF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2IxG;AACD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  //
2
- import { createAuthenticatorFactory, deleteAuthenticatorFactory, findAuthenticatorFactory, findAuthenticatorsByUserIdFactory, updateAuthenticatorFactory, } from "#src/repositories/authenticator";
2
+ import { createAuthenticatorFactory, deleteAllAuthenticatorsByUserIdFactory, deleteAuthenticatorFactory, findAuthenticatorFactory, findAuthenticatorsByUserIdFactory, updateAuthenticatorFactory, } from "#src/repositories/authenticator";
3
3
  import { findEmailInDeliverabilityWhiteListFactory } from "#src/repositories/email-deliverability-whitelist";
4
4
  import { addDomainFactory, findEmailDomainsByOrganizationIdFactory, } from "#src/repositories/email-domain";
5
5
  import { findFranceconnectUserinfoFactory } from "#src/repositories/franceconnect_userinfo";
@@ -23,6 +23,7 @@ export function createContext({ api_entreprise_client, api_insee_client, api_reg
23
23
  authenticators: {
24
24
  create: createAuthenticatorFactory({ pg }),
25
25
  delete: deleteAuthenticatorFactory({ pg }),
26
+ deleteAllByUserId: deleteAllAuthenticatorsByUserIdFactory({ pg }),
26
27
  find: findAuthenticatorFactory({ pg }),
27
28
  findByUserId: findAuthenticatorsByUserIdFactory({ pg }),
28
29
  update: updateAuthenticatorFactory({ pg }),
@@ -29,4 +29,20 @@ export type MatchCriteria = z.output<typeof MatchCriteria>;
29
29
  * @returns Score from 0 to 5
30
30
  */
31
31
  export declare function certificationScore(identitePivot: IdentityVector, sourceDirigeant: IdentityVector): Set<"family_name" | "gender" | "birth_country" | "birth_date" | "birth_place" | "first_name">;
32
+ /**
33
+ * Compares each evaluated criterion and keeps, for both sides, the value as
34
+ * received (`raw`) and the value actually compared (`compared`).
35
+ */
36
+ export declare function compareCriteria(identitePivot: IdentityVector, sourceDirigeant: IdentityVector): {
37
+ criterion: "family_name" | "gender" | "birth_country" | "birth_date" | "birth_place" | "first_name";
38
+ franceconnect: {
39
+ compared: string | null;
40
+ raw: string | null;
41
+ };
42
+ matched: boolean;
43
+ source: {
44
+ compared: string | null;
45
+ raw: string | null;
46
+ };
47
+ }[];
32
48
  //# sourceMappingURL=certification-score.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"certification-score.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/certification-score.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,CAAC,MAAM,QAAQ,CAAC;AAMvB,eAAO,MAAM,aAAa;;;;;;;EAOxB,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,cAAc,EAC7B,eAAe,EAAE,cAAc,iGAmEhC"}
1
+ {"version":3,"file":"certification-score.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/certification-score.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,CAAC,MAAM,QAAQ,CAAC;AAMvB,eAAO,MAAM,aAAa;;;;;;;EAOxB,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,cAAc,EAC7B,eAAe,EAAE,cAAc,iGAOhC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,cAAc,EAC7B,eAAe,EAAE,cAAc;;;;;;;;;;;IA0DhC"}
@@ -31,51 +31,75 @@ export const MatchCriteria = z.enum([
31
31
  * @returns Score from 0 to 5
32
32
  */
33
33
  export function certificationScore(identitePivot, sourceDirigeant) {
34
- const matches = new Set();
34
+ return new Set(compareCriteria(identitePivot, sourceDirigeant)
35
+ .filter(({ matched }) => matched)
36
+ .map(({ criterion }) => criterion));
37
+ }
38
+ /**
39
+ * Compares each evaluated criterion and keeps, for both sides, the value as
40
+ * received (`raw`) and the value actually compared (`compared`).
41
+ */
42
+ export function compareCriteria(identitePivot, sourceDirigeant) {
35
43
  // 1. Family name match (after normalization)
36
- const normalizedFamilyNamePivot = normalizeText(identitePivot.family_name);
37
- const normalizedFamilyNameSource = normalizeText(sourceDirigeant.family_name);
38
- if (normalizedFamilyNamePivot &&
39
- normalizedFamilyNameSource &&
40
- normalizedFamilyNamePivot === normalizedFamilyNameSource) {
41
- matches.add(MatchCriteria.enum.family_name);
42
- }
44
+ const family_name = compare({
45
+ criterion: MatchCriteria.enum.family_name,
46
+ franceconnect: identitePivot.family_name,
47
+ match: bothPresentAndEqual,
48
+ normalize: normalizeText,
49
+ source: sourceDirigeant.family_name,
50
+ });
43
51
  // 2. First name match (first name only, after normalization)
44
- const firstNamePivot = extractFirstName(identitePivot.given_name);
45
- const firstNameSource = extractFirstName(sourceDirigeant.given_name);
46
- if (firstNamePivot && firstNameSource && firstNamePivot === firstNameSource) {
47
- matches.add(MatchCriteria.enum.first_name);
48
- }
52
+ const first_name = compare({
53
+ criterion: MatchCriteria.enum.first_name,
54
+ franceconnect: identitePivot.given_name,
55
+ match: bothPresentAndEqual,
56
+ normalize: extractFirstName,
57
+ source: sourceDirigeant.given_name,
58
+ });
49
59
  // 3. Gender match (match or absent in source)
50
- if (!sourceDirigeant.gender ||
51
- identitePivot.gender === sourceDirigeant.gender) {
52
- matches.add(MatchCriteria.enum.gender);
53
- }
60
+ const gender = compare({
61
+ criterion: MatchCriteria.enum.gender,
62
+ franceconnect: identitePivot.gender,
63
+ match: (pivot, source) => !source || pivot === source,
64
+ source: sourceDirigeant.gender,
65
+ });
54
66
  // 4. Birth date match (exact match)
55
- if (identitePivot.birthdate &&
56
- sourceDirigeant.birthdate &&
57
- identitePivot.birthdate.getTime() === sourceDirigeant.birthdate.getTime()) {
58
- matches.add(MatchCriteria.enum.birth_date);
59
- }
67
+ const birth_date = compare({
68
+ criterion: MatchCriteria.enum.birth_date,
69
+ franceconnect: identitePivot.birthdate?.toISOString() ?? null,
70
+ match: bothPresentAndEqual,
71
+ source: sourceDirigeant.birthdate?.toISOString() ?? null,
72
+ });
60
73
  // 5. Birth place match (different logic for French vs foreigners)
61
74
  const isFrench = !identitePivot.birthcountry || identitePivot.birthcountry === "99100";
62
- if (isFrench) {
63
- // For French: check commune code (with conversion)
64
- const communePivot = convertCommuneCode(identitePivot.birthplace);
65
- const communeSource = convertCommuneCode(sourceDirigeant.birthplace);
66
- // Match if equal or if source has no commune data
67
- if (!communeSource || (communePivot && communePivot === communeSource)) {
68
- matches.add(MatchCriteria.enum.birth_place);
69
- }
70
- }
71
- else {
72
- // For foreigners: check country code (with conversion if needed from RNE)
73
- // Both should already be in COG format (99XXX)
74
- if (identitePivot.birthcountry === null ||
75
- sourceDirigeant.birthcountry === null ||
76
- identitePivot.birthcountry === sourceDirigeant.birthcountry) {
77
- matches.add(MatchCriteria.enum.birth_country);
78
- }
79
- }
80
- return matches;
75
+ const birth = isFrench
76
+ ? // For French: commune code (with conversion), match if source has none
77
+ compare({
78
+ criterion: MatchCriteria.enum.birth_place,
79
+ franceconnect: identitePivot.birthplace,
80
+ match: (pivot, source) => !source || (!!pivot && pivot === source),
81
+ normalize: convertCommuneCode,
82
+ source: sourceDirigeant.birthplace,
83
+ })
84
+ : // For foreigners: country code (COG 99XXX), match if either side has none
85
+ compare({
86
+ criterion: MatchCriteria.enum.birth_country,
87
+ franceconnect: identitePivot.birthcountry,
88
+ match: (pivot, source) => pivot === null || source === null || pivot === source,
89
+ source: sourceDirigeant.birthcountry,
90
+ });
91
+ return [family_name, first_name, gender, birth_date, birth];
92
+ }
93
+ function bothPresentAndEqual(pivot, source) {
94
+ return !!pivot && !!source && pivot === source;
95
+ }
96
+ function compare({ criterion, franceconnect, match, normalize = (value) => value, source, }) {
97
+ const compared_franceconnect = normalize(franceconnect);
98
+ const compared_source = normalize(source);
99
+ return {
100
+ criterion,
101
+ franceconnect: { compared: compared_franceconnect, raw: franceconnect },
102
+ matched: match(compared_franceconnect, compared_source),
103
+ source: { compared: compared_source, raw: source },
104
+ };
81
105
  }
@@ -0,0 +1,3 @@
1
+ import type { DatabaseContext } from "#src/types";
2
+ export declare function deleteAllAuthenticatorsByUserIdFactory({ pg, }: DatabaseContext): (user_id: number) => Promise<boolean>;
3
+ //# sourceMappingURL=delete-all-authenticators-by-user-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete-all-authenticators-by-user-id.d.ts","sourceRoot":"","sources":["../../../src/repositories/authenticator/delete-all-authenticators-by-user-id.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAKlD,wBAAgB,sCAAsC,CAAC,EACrD,EAAE,GACH,EAAE,eAAe,IACsC,SAAS,MAAM,sBAWtE"}
@@ -0,0 +1,12 @@
1
+ //
2
+ import {} from "pg";
3
+ //
4
+ export function deleteAllAuthenticatorsByUserIdFactory({ pg, }) {
5
+ return async function deleteAllAuthenticatorsByUserId(user_id) {
6
+ const { rowCount, affectedRows } = (await pg.query(`
7
+ DELETE FROM authenticators
8
+ WHERE user_id = $1
9
+ RETURNING *`, [user_id]));
10
+ return (affectedRows ?? rowCount ?? 0) > 0;
11
+ };
12
+ }
@@ -1,4 +1,5 @@
1
1
  export * from "./create-authenticator.js";
2
+ export * from "./delete-all-authenticators-by-user-id.js";
2
3
  export * from "./delete-authenticator.js";
3
4
  export * from "./find-authenticator.js";
4
5
  export * from "./find-authenticators-by-user-id.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/authenticator/index.ts"],"names":[],"mappings":"AAEA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,qCAAqC,CAAC;AACpD,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/authenticator/index.ts"],"names":[],"mappings":"AAEA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,qCAAqC,CAAC;AACpD,cAAc,2BAA2B,CAAC"}
@@ -1,5 +1,6 @@
1
1
  //
2
2
  export * from "./create-authenticator.js";
3
+ export * from "./delete-all-authenticators-by-user-id.js";
3
4
  export * from "./delete-authenticator.js";
4
5
  export * from "./find-authenticator.js";
5
6
  export * from "./find-authenticators-by-user-id.js";
@@ -1,3 +1,3 @@
1
1
  import type { AuthorizationRequest, BaseAuthorizationRequest, DatabaseContext } from "#src/types";
2
- export declare function upsertAuthorizationRequestFactory({ pg }: DatabaseContext): ({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, interaction_cid, outcome, }: BaseAuthorizationRequest) => Promise<AuthorizationRequest>;
2
+ export declare function upsertAuthorizationRequestFactory({ pg }: DatabaseContext): ({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, interaction_cid, outcome, sid, }: BaseAuthorizationRequest) => Promise<AuthorizationRequest>;
3
3
  //# sourceMappingURL=upsert-authorization-request.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upsert-authorization-request.d.ts","sourceRoot":"","sources":["../../../src/repositories/oidc-client/upsert-authorization-request.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EAChB,MAAM,YAAY,CAAC;AAKpB,wBAAgB,iCAAiC,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,mGAQ9C,wBAAwB,mCA6B5B"}
1
+ {"version":3,"file":"upsert-authorization-request.d.ts","sourceRoot":"","sources":["../../../src/repositories/oidc-client/upsert-authorization-request.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EAChB,MAAM,YAAY,CAAC;AAKpB,wBAAgB,iCAAiC,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,wGAS9C,wBAAwB,mCA+B5B"}
@@ -2,18 +2,19 @@
2
2
  import {} from "pg";
3
3
  //
4
4
  export function upsertAuthorizationRequestFactory({ pg }) {
5
- return async function upsertAuthorizationRequest({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, interaction_cid, outcome, }) {
5
+ return async function upsertAuthorizationRequest({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, interaction_cid, outcome, sid, }) {
6
6
  const { rows } = await pg.query(`
7
7
  INSERT INTO users_oidc_clients
8
- (user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, interaction_cid, outcome)
9
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
8
+ (user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, interaction_cid, outcome, sid)
9
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
10
10
  ON CONFLICT (interaction_cid) WHERE interaction_cid IS NOT NULL
11
11
  DO UPDATE SET
12
12
  organization_id = EXCLUDED.organization_id,
13
13
  outcome = EXCLUDED.outcome,
14
+ sid = COALESCE(EXCLUDED.sid, users_oidc_clients.sid),
14
15
  updated_at = EXCLUDED.updated_at,
15
16
  user_id = EXCLUDED.user_id
16
- RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id, interaction_cid, outcome;
17
+ RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id, interaction_cid, outcome, sid;
17
18
  `, [
18
19
  user_id,
19
20
  oidc_client_id,
@@ -24,6 +25,7 @@ RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, cr
24
25
  new Date(),
25
26
  interaction_cid,
26
27
  outcome,
28
+ sid,
27
29
  ]);
28
30
  return rows.shift();
29
31
  };
@@ -0,0 +1,18 @@
1
+ import { type EmailDomainNoPendingVerificationType } from "#src/types";
2
+ export declare function getMembershipChangesByDomainVerification<Member extends {
3
+ email: string;
4
+ verification_type: string;
5
+ }>({ domain, members, verification_type, }: {
6
+ domain: string;
7
+ members: ReadonlyArray<Member>;
8
+ verification_type: EmailDomainNoPendingVerificationType;
9
+ }): {
10
+ kind: "domain_approved";
11
+ promoted_members: Member[];
12
+ verification_type: "official_contact" | "trackdechets_postal_mail" | "verified" | "external";
13
+ } | {
14
+ kind: "domain_refused";
15
+ removed_members: Member[];
16
+ verification_type: "blacklisted" | "refused";
17
+ };
18
+ //# sourceMappingURL=get-membership-changes-by-domain-verification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-membership-changes-by-domain-verification.d.ts","sourceRoot":"","sources":["../../../src/services/organization/get-membership-changes-by-domain-verification.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,oCAAoC,EAC1C,MAAM,YAAY,CAAC;AAMpB,wBAAgB,wCAAwC,CACtD,MAAM,SAAS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,EAC3D,EACA,MAAM,EACN,OAAO,EACP,iBAAiB,GAClB,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC/B,iBAAiB,EAAE,oCAAoC,CAAC;CACzD;;;;;;;;EAqBA"}
@@ -0,0 +1,21 @@
1
+ //
2
+ import { EmailDomainApprovedVerificationValues, EmailDomainRejectedVerificationValues, SuperWeakLinkEnum, UnverifiedLinkEnum, } from "#src/types";
3
+ import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
4
+ import { match } from "ts-pattern";
5
+ //
6
+ export function getMembershipChangesByDomainVerification({ domain, members, verification_type, }) {
7
+ const domain_members = members.filter(({ email }) => getEmailDomain(email) === domain);
8
+ return match(verification_type)
9
+ .with(...EmailDomainApprovedVerificationValues, (verification_type) => ({
10
+ kind: "domain_approved",
11
+ promoted_members: domain_members.filter(({ verification_type }) => UnverifiedLinkEnum.safeParse(verification_type).success ||
12
+ SuperWeakLinkEnum.safeParse(verification_type).success),
13
+ verification_type,
14
+ }))
15
+ .with(...EmailDomainRejectedVerificationValues, (verification_type) => ({
16
+ kind: "domain_refused",
17
+ removed_members: domain_members,
18
+ verification_type,
19
+ }))
20
+ .exhaustive();
21
+ }
@@ -1,5 +1,5 @@
1
1
  export * from "./compute-service-public-info.js";
2
- export * from "./get-member-ids-promoted-by-domain.js";
2
+ export * from "./get-membership-changes-by-domain-verification.js";
3
3
  export * from "./is-domain-allowed-for-organization.js";
4
4
  export * from "./is-entreprise-unipersonnelle.js";
5
5
  export * from "./is-organization-covered-by-certification-dirigeant.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/organization/index.ts"],"names":[],"mappings":"AAEA,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yDAAyD,CAAC;AACxE,cAAc,oCAAoC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/organization/index.ts"],"names":[],"mappings":"AAEA,cAAc,kCAAkC,CAAC;AACjD,cAAc,oDAAoD,CAAC;AACnE,cAAc,yCAAyC,CAAC;AACxD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yDAAyD,CAAC;AACxE,cAAc,oCAAoC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  //
2
2
  export * from "./compute-service-public-info.js";
3
- export * from "./get-member-ids-promoted-by-domain.js";
3
+ export * from "./get-membership-changes-by-domain-verification.js";
4
4
  export * from "./is-domain-allowed-for-organization.js";
5
5
  export * from "./is-entreprise-unipersonnelle.js";
6
6
  export * from "./is-organization-covered-by-certification-dirigeant.js";
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  export declare const AuthorizationRequestOutcomeEnum: z.ZodEnum<{
3
+ signed_out: "signed_out";
3
4
  succeeded: "succeeded";
4
5
  }>;
5
6
  export type AuthorizationRequestOutcome = z.output<typeof AuthorizationRequestOutcomeEnum>;
@@ -11,6 +12,7 @@ export interface BaseAuthorizationRequest {
11
12
  user_ip_address: string | null;
12
13
  interaction_cid: string | null;
13
14
  outcome: AuthorizationRequestOutcome | null;
15
+ sid: string | null;
14
16
  }
15
17
  export interface AuthorizationRequest extends BaseAuthorizationRequest {
16
18
  id: number;
@@ -1 +1 @@
1
- {"version":3,"file":"authorization-request.d.ts","sourceRoot":"","sources":["../../src/types/authorization-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,+BAA+B;;EAAwB,CAAC;AAErE,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAChD,OAAO,+BAA+B,CACvC,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,2BAA2B,GAAG,IAAI,CAAC;CAC7C;AAED,MAAM,WAAW,oBAAqB,SAAQ,wBAAwB;IACpE,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB"}
1
+ {"version":3,"file":"authorization-request.d.ts","sourceRoot":"","sources":["../../src/types/authorization-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,+BAA+B;;;EAG1C,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAChD,OAAO,+BAA+B,CACvC,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,2BAA2B,GAAG,IAAI,CAAC;IAC5C,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,oBAAqB,SAAQ,wBAAwB;IACpE,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB"}
@@ -1,2 +1,5 @@
1
1
  import { z } from "zod";
2
- export const AuthorizationRequestOutcomeEnum = z.enum(["succeeded"]);
2
+ export const AuthorizationRequestOutcomeEnum = z.enum([
3
+ "signed_out",
4
+ "succeeded",
5
+ ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proconnect-gouv/proconnect.identite",
3
- "version": "15.0.0",
3
+ "version": "16.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": {
@@ -2,6 +2,7 @@
2
2
 
3
3
  import {
4
4
  createAuthenticatorFactory,
5
+ deleteAllAuthenticatorsByUserIdFactory,
5
6
  deleteAuthenticatorFactory,
6
7
  findAuthenticatorFactory,
7
8
  findAuthenticatorsByUserIdFactory,
@@ -84,6 +85,7 @@ export function createContext({
84
85
  authenticators: {
85
86
  create: createAuthenticatorFactory({ pg }),
86
87
  delete: deleteAuthenticatorFactory({ pg }),
88
+ deleteAllByUserId: deleteAllAuthenticatorsByUserIdFactory({ pg }),
87
89
  find: findAuthenticatorFactory({ pg }),
88
90
  findByUserId: findAuthenticatorsByUserIdFactory({ pg }),
89
91
  update: updateAuthenticatorFactory({ pg }),
@@ -2,7 +2,7 @@
2
2
 
3
3
  import assert from "node:assert/strict";
4
4
  import { describe, it } from "node:test";
5
- import { certificationScore } from "./certification-score.js";
5
+ import { certificationScore, compareCriteria } from "./certification-score.js";
6
6
 
7
7
  //
8
8
 
@@ -343,3 +343,66 @@ describe("certification scoring", () => {
343
343
  );
344
344
  });
345
345
  });
346
+
347
+ describe("compareCriteria", () => {
348
+ it("keeps the received and the compared value of each side", () => {
349
+ assert.deepStrictEqual(
350
+ compareCriteria(
351
+ {
352
+ birthcountry: "99100",
353
+ birthdate: new Date("1946-08-17"),
354
+ birthplace: "47019",
355
+ family_name: "Bernard",
356
+ gender: "male",
357
+ given_name: "Jean-Pierre Paul",
358
+ },
359
+ {
360
+ birthcountry: null,
361
+ birthdate: new Date("1946-08-18"),
362
+ birthplace: "47209",
363
+ family_name: "BERNARD",
364
+ gender: null,
365
+ given_name: "Jean Pierre",
366
+ },
367
+ ),
368
+ [
369
+ {
370
+ criterion: "family_name",
371
+ franceconnect: { compared: "BERNARD", raw: "Bernard" },
372
+ matched: true,
373
+ source: { compared: "BERNARD", raw: "BERNARD" },
374
+ },
375
+ {
376
+ criterion: "first_name",
377
+ franceconnect: { compared: "JEAN", raw: "Jean-Pierre Paul" },
378
+ matched: true,
379
+ source: { compared: "JEAN", raw: "Jean Pierre" },
380
+ },
381
+ {
382
+ criterion: "gender",
383
+ franceconnect: { compared: "male", raw: "male" },
384
+ matched: true,
385
+ source: { compared: null, raw: null },
386
+ },
387
+ {
388
+ criterion: "birth_date",
389
+ franceconnect: {
390
+ compared: "1946-08-17T00:00:00.000Z",
391
+ raw: "1946-08-17T00:00:00.000Z",
392
+ },
393
+ matched: false,
394
+ source: {
395
+ compared: "1946-08-18T00:00:00.000Z",
396
+ raw: "1946-08-18T00:00:00.000Z",
397
+ },
398
+ },
399
+ {
400
+ criterion: "birth_place",
401
+ franceconnect: { compared: "47209", raw: "47019" },
402
+ matched: true,
403
+ source: { compared: "47209", raw: "47209" },
404
+ },
405
+ ],
406
+ );
407
+ });
408
+ });
@@ -40,69 +40,103 @@ export function certificationScore(
40
40
  identitePivot: IdentityVector,
41
41
  sourceDirigeant: IdentityVector,
42
42
  ) {
43
- const matches = new Set<MatchCriteria>();
43
+ return new Set(
44
+ compareCriteria(identitePivot, sourceDirigeant)
45
+ .filter(({ matched }) => matched)
46
+ .map(({ criterion }) => criterion),
47
+ );
48
+ }
44
49
 
50
+ /**
51
+ * Compares each evaluated criterion and keeps, for both sides, the value as
52
+ * received (`raw`) and the value actually compared (`compared`).
53
+ */
54
+ export function compareCriteria(
55
+ identitePivot: IdentityVector,
56
+ sourceDirigeant: IdentityVector,
57
+ ) {
45
58
  // 1. Family name match (after normalization)
46
- const normalizedFamilyNamePivot = normalizeText(identitePivot.family_name);
47
- const normalizedFamilyNameSource = normalizeText(sourceDirigeant.family_name);
48
-
49
- if (
50
- normalizedFamilyNamePivot &&
51
- normalizedFamilyNameSource &&
52
- normalizedFamilyNamePivot === normalizedFamilyNameSource
53
- ) {
54
- matches.add(MatchCriteria.enum.family_name);
55
- }
59
+ const family_name = compare({
60
+ criterion: MatchCriteria.enum.family_name,
61
+ franceconnect: identitePivot.family_name,
62
+ match: bothPresentAndEqual,
63
+ normalize: normalizeText,
64
+ source: sourceDirigeant.family_name,
65
+ });
56
66
 
57
67
  // 2. First name match (first name only, after normalization)
58
- const firstNamePivot = extractFirstName(identitePivot.given_name);
59
- const firstNameSource = extractFirstName(sourceDirigeant.given_name);
60
-
61
- if (firstNamePivot && firstNameSource && firstNamePivot === firstNameSource) {
62
- matches.add(MatchCriteria.enum.first_name);
63
- }
68
+ const first_name = compare({
69
+ criterion: MatchCriteria.enum.first_name,
70
+ franceconnect: identitePivot.given_name,
71
+ match: bothPresentAndEqual,
72
+ normalize: extractFirstName,
73
+ source: sourceDirigeant.given_name,
74
+ });
64
75
 
65
76
  // 3. Gender match (match or absent in source)
66
- if (
67
- !sourceDirigeant.gender ||
68
- identitePivot.gender === sourceDirigeant.gender
69
- ) {
70
- matches.add(MatchCriteria.enum.gender);
71
- }
77
+ const gender = compare({
78
+ criterion: MatchCriteria.enum.gender,
79
+ franceconnect: identitePivot.gender,
80
+ match: (pivot, source) => !source || pivot === source,
81
+ source: sourceDirigeant.gender,
82
+ });
72
83
 
73
84
  // 4. Birth date match (exact match)
74
- if (
75
- identitePivot.birthdate &&
76
- sourceDirigeant.birthdate &&
77
- identitePivot.birthdate.getTime() === sourceDirigeant.birthdate.getTime()
78
- ) {
79
- matches.add(MatchCriteria.enum.birth_date);
80
- }
85
+ const birth_date = compare({
86
+ criterion: MatchCriteria.enum.birth_date,
87
+ franceconnect: identitePivot.birthdate?.toISOString() ?? null,
88
+ match: bothPresentAndEqual,
89
+ source: sourceDirigeant.birthdate?.toISOString() ?? null,
90
+ });
81
91
 
82
92
  // 5. Birth place match (different logic for French vs foreigners)
83
93
  const isFrench =
84
94
  !identitePivot.birthcountry || identitePivot.birthcountry === "99100";
95
+ const birth = isFrench
96
+ ? // For French: commune code (with conversion), match if source has none
97
+ compare({
98
+ criterion: MatchCriteria.enum.birth_place,
99
+ franceconnect: identitePivot.birthplace,
100
+ match: (pivot, source) => !source || (!!pivot && pivot === source),
101
+ normalize: convertCommuneCode,
102
+ source: sourceDirigeant.birthplace,
103
+ })
104
+ : // For foreigners: country code (COG 99XXX), match if either side has none
105
+ compare({
106
+ criterion: MatchCriteria.enum.birth_country,
107
+ franceconnect: identitePivot.birthcountry,
108
+ match: (pivot, source) =>
109
+ pivot === null || source === null || pivot === source,
110
+ source: sourceDirigeant.birthcountry,
111
+ });
85
112
 
86
- if (isFrench) {
87
- // For French: check commune code (with conversion)
88
- const communePivot = convertCommuneCode(identitePivot.birthplace);
89
- const communeSource = convertCommuneCode(sourceDirigeant.birthplace);
113
+ return [family_name, first_name, gender, birth_date, birth];
114
+ }
115
+
116
+ function bothPresentAndEqual(pivot: string | null, source: string | null) {
117
+ return !!pivot && !!source && pivot === source;
118
+ }
90
119
 
91
- // Match if equal or if source has no commune data
92
- if (!communeSource || (communePivot && communePivot === communeSource)) {
93
- matches.add(MatchCriteria.enum.birth_place);
94
- }
95
- } else {
96
- // For foreigners: check country code (with conversion if needed from RNE)
97
- // Both should already be in COG format (99XXX)
98
- if (
99
- identitePivot.birthcountry === null ||
100
- sourceDirigeant.birthcountry === null ||
101
- identitePivot.birthcountry === sourceDirigeant.birthcountry
102
- ) {
103
- matches.add(MatchCriteria.enum.birth_country);
104
- }
105
- }
120
+ function compare({
121
+ criterion,
122
+ franceconnect,
123
+ match,
124
+ normalize = (value) => value,
125
+ source,
126
+ }: {
127
+ criterion: MatchCriteria;
128
+ franceconnect: string | null;
129
+ match: (pivot: string | null, source: string | null) => boolean;
130
+ normalize?: (value: string | null) => string | null;
131
+ source: string | null;
132
+ }) {
133
+ const compared_franceconnect = normalize(franceconnect);
134
+ const compared_source = normalize(source);
106
135
 
107
- return matches;
136
+ return {
137
+ criterion,
138
+ franceconnect: { compared: compared_franceconnect, raw: franceconnect },
139
+ matched: match(compared_franceconnect, compared_source),
140
+ source: { compared: compared_source, raw: source },
141
+ };
108
142
  }
@@ -0,0 +1,51 @@
1
+ //
2
+
3
+ import { emptyDatabase, migrate, pg } from "#testing";
4
+ import assert from "node:assert/strict";
5
+ import { before, beforeEach, suite, test } from "node:test";
6
+ import { deleteAllAuthenticatorsByUserIdFactory } from "./delete-all-authenticators-by-user-id.js";
7
+
8
+ //
9
+
10
+ const deleteAllAuthenticatorsByUserId = deleteAllAuthenticatorsByUserIdFactory({
11
+ pg: pg as any,
12
+ });
13
+
14
+ suite("deleteAllAuthenticatorsByUserIdFactory", () => {
15
+ before(migrate);
16
+ beforeEach(emptyDatabase);
17
+
18
+ test("should delete all the authenticators of the user only", async () => {
19
+ await pg.sql`
20
+ INSERT INTO users
21
+ (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
22
+ VALUES
23
+ (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque'),
24
+ (2, 'rogal.dorn@imperialfists.world', '4444-04-04', '4444-04-04', 'rogal', 'dorn', 'i', 'primarque')
25
+ ;
26
+ `;
27
+ await pg.sql`
28
+ INSERT INTO authenticators
29
+ (credential_id, credential_public_key, counter, credential_backed_up, user_id, usage_count, user_verified)
30
+ VALUES
31
+ ('CRED1', '\\x00', 0, false, 1, 0, true),
32
+ ('CRED2', '\\x00', 0, false, 1, 0, true),
33
+ ('CRED3', '\\x00', 0, false, 2, 0, true)
34
+ ;
35
+ `;
36
+
37
+ const result = await deleteAllAuthenticatorsByUserId(1);
38
+
39
+ assert.equal(result, true);
40
+ const { rows } = await pg.query(
41
+ "SELECT credential_id FROM authenticators ORDER BY credential_id",
42
+ );
43
+ assert.deepEqual(rows, [{ credential_id: "CRED3" }]);
44
+ });
45
+
46
+ test("should return false when the user has no authenticator", async () => {
47
+ const result = await deleteAllAuthenticatorsByUserId(1);
48
+
49
+ assert.equal(result, false);
50
+ });
51
+ });
@@ -0,0 +1,22 @@
1
+ //
2
+
3
+ import type { DatabaseContext } from "#src/types";
4
+ import { type QueryResult } from "pg";
5
+
6
+ //
7
+
8
+ export function deleteAllAuthenticatorsByUserIdFactory({
9
+ pg,
10
+ }: DatabaseContext) {
11
+ return async function deleteAllAuthenticatorsByUserId(user_id: number) {
12
+ const { rowCount, affectedRows } = (await pg.query(
13
+ `
14
+ DELETE FROM authenticators
15
+ WHERE user_id = $1
16
+ RETURNING *`,
17
+ [user_id],
18
+ )) as QueryResult & { affectedRows?: number };
19
+
20
+ return (affectedRows ?? rowCount ?? 0) > 0;
21
+ };
22
+ }
@@ -1,6 +1,7 @@
1
1
  //
2
2
 
3
3
  export * from "./create-authenticator.js";
4
+ export * from "./delete-all-authenticators-by-user-id.js";
4
5
  export * from "./delete-authenticator.js";
5
6
  export * from "./find-authenticator.js";
6
7
  export * from "./find-authenticators-by-user-id.js";
@@ -40,12 +40,14 @@ suite("upsertAuthorizationRequestFactory", () => {
40
40
  user_ip_address: "127.0.0.1",
41
41
  interaction_cid: "Rex5_Tq4tBqqwz0xPTJyd",
42
42
  outcome: "succeeded",
43
+ sid: "ulthwe",
43
44
  });
44
45
 
45
46
  assert.equal(authorizationRequest.user_id, 1);
46
47
  assert.equal(authorizationRequest.oidc_client_id, 1);
47
48
  assert.equal(authorizationRequest.interaction_cid, "Rex5_Tq4tBqqwz0xPTJyd");
48
49
  assert.equal(authorizationRequest.outcome, "succeeded");
50
+ assert.equal(authorizationRequest.sid, "ulthwe");
49
51
  });
50
52
 
51
53
  test("should update the authorization request of the same interaction", async () => {
@@ -60,36 +62,47 @@ suite("upsertAuthorizationRequestFactory", () => {
60
62
  ...request,
61
63
  interaction_cid: "caliban",
62
64
  outcome: null,
65
+ sid: null,
63
66
  });
64
67
  await upsertAuthorizationRequest({
65
68
  ...request,
66
69
  interaction_cid: "fallen",
67
70
  outcome: null,
71
+ sid: "rock",
68
72
  });
69
73
  await upsertAuthorizationRequest({
70
74
  ...request,
71
75
  interaction_cid: "caliban",
72
76
  outcome: "succeeded",
77
+ sid: "rock",
78
+ });
79
+ await upsertAuthorizationRequest({
80
+ ...request,
81
+ interaction_cid: "fallen",
82
+ outcome: null,
83
+ sid: null,
73
84
  });
74
85
  await upsertAuthorizationRequest({
75
86
  ...request,
76
87
  interaction_cid: null,
77
88
  outcome: "succeeded",
89
+ sid: "rock",
78
90
  });
79
91
  await upsertAuthorizationRequest({
80
92
  ...request,
81
93
  interaction_cid: null,
82
94
  outcome: "succeeded",
95
+ sid: "rock",
83
96
  });
84
97
 
85
98
  const { rows } = await pg.query(
86
- "SELECT interaction_cid, outcome FROM users_oidc_clients ORDER BY id",
99
+ "SELECT interaction_cid, outcome, sid FROM users_oidc_clients ORDER BY id",
87
100
  );
88
101
  assert.deepEqual(rows, [
89
- { interaction_cid: "caliban", outcome: "succeeded" },
90
- { interaction_cid: "fallen", outcome: null },
91
- { interaction_cid: null, outcome: "succeeded" },
92
- { interaction_cid: null, outcome: "succeeded" },
102
+ { interaction_cid: "caliban", outcome: "succeeded", sid: "rock" },
103
+ { interaction_cid: "fallen", outcome: null, sid: "rock" },
104
+ { interaction_cid: null, outcome: "succeeded", sid: "rock" },
105
+ { interaction_cid: null, outcome: "succeeded", sid: "rock" },
93
106
  ]);
94
107
  });
95
108
  });
@@ -18,19 +18,21 @@ export function upsertAuthorizationRequestFactory({ pg }: DatabaseContext) {
18
18
  user_ip_address,
19
19
  interaction_cid,
20
20
  outcome,
21
+ sid,
21
22
  }: BaseAuthorizationRequest) {
22
23
  const { rows }: QueryResult<AuthorizationRequest> = await pg.query(
23
24
  `
24
25
  INSERT INTO users_oidc_clients
25
- (user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, interaction_cid, outcome)
26
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
26
+ (user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, interaction_cid, outcome, sid)
27
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
27
28
  ON CONFLICT (interaction_cid) WHERE interaction_cid IS NOT NULL
28
29
  DO UPDATE SET
29
30
  organization_id = EXCLUDED.organization_id,
30
31
  outcome = EXCLUDED.outcome,
32
+ sid = COALESCE(EXCLUDED.sid, users_oidc_clients.sid),
31
33
  updated_at = EXCLUDED.updated_at,
32
34
  user_id = EXCLUDED.user_id
33
- RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id, interaction_cid, outcome;
35
+ RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id, interaction_cid, outcome, sid;
34
36
  `,
35
37
  [
36
38
  user_id,
@@ -42,6 +44,7 @@ RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, cr
42
44
  new Date(),
43
45
  interaction_cid,
44
46
  outcome,
47
+ sid,
45
48
  ],
46
49
  );
47
50
 
@@ -0,0 +1,91 @@
1
+ //
2
+
3
+ import { getMembershipChangesByDomainVerification } from "#src/services/organization";
4
+ import assert from "node:assert/strict";
5
+ import { describe, it } from "node:test";
6
+
7
+ //
8
+
9
+ const unverified_darkangels = [
10
+ {
11
+ email: "lion.eljonson@darkangels.world",
12
+ verification_type: "no_validation_means_available",
13
+ },
14
+ {
15
+ email: "cat.eljonson@darkangels.world",
16
+ verification_type: "no_verification_means_for_entreprise_unipersonnelle",
17
+ },
18
+ {
19
+ email: "tiger.eljonson@darkangels.world",
20
+ verification_type: "no_verification_means_for_small_association",
21
+ },
22
+ {
23
+ email: "wolf.eljonson@darkangels.world",
24
+ verification_type: "no_verification_means_for_small_organization",
25
+ },
26
+ {
27
+ email: "mouse.eljonson@darkangels.world",
28
+ verification_type: "domain_not_verified_yet",
29
+ },
30
+ ];
31
+
32
+ const verified_darkangels = [
33
+ {
34
+ email: "luther@darkangels.world",
35
+ verification_type: "organization_dirigeant",
36
+ },
37
+ { email: "azrael@darkangels.world", verification_type: "domain" },
38
+ {
39
+ email: "belial@darkangels.world",
40
+ verification_type: "official_contact_email",
41
+ },
42
+ ];
43
+
44
+ const other_domains = [
45
+ {
46
+ email: "leman.russ@spacewolves.world",
47
+ verification_type: "no_validation_means_available",
48
+ },
49
+ {
50
+ email: "cypher@fallen.darkangels.world",
51
+ verification_type: "no_validation_means_available",
52
+ },
53
+ ];
54
+
55
+ const members = [
56
+ ...unverified_darkangels,
57
+ ...verified_darkangels,
58
+ ...other_domains,
59
+ ];
60
+
61
+ describe("getMembershipChangesByDomainVerification", () => {
62
+ it("should promote the unverified and super weak members of an approved domain", () => {
63
+ assert.deepEqual(
64
+ getMembershipChangesByDomainVerification({
65
+ domain: "darkangels.world",
66
+ members,
67
+ verification_type: "verified",
68
+ }),
69
+ {
70
+ kind: "domain_approved",
71
+ promoted_members: unverified_darkangels,
72
+ verification_type: "verified",
73
+ },
74
+ );
75
+ });
76
+
77
+ it("should remove every member of a refused domain, whatever their link", () => {
78
+ assert.deepEqual(
79
+ getMembershipChangesByDomainVerification({
80
+ domain: "darkangels.world",
81
+ members,
82
+ verification_type: "refused",
83
+ }),
84
+ {
85
+ kind: "domain_refused",
86
+ removed_members: [...unverified_darkangels, ...verified_darkangels],
87
+ verification_type: "refused",
88
+ },
89
+ );
90
+ });
91
+ });
@@ -0,0 +1,46 @@
1
+ //
2
+
3
+ import {
4
+ EmailDomainApprovedVerificationValues,
5
+ EmailDomainRejectedVerificationValues,
6
+ SuperWeakLinkEnum,
7
+ UnverifiedLinkEnum,
8
+ type EmailDomainNoPendingVerificationType,
9
+ } from "#src/types";
10
+ import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
11
+ import { match } from "ts-pattern";
12
+
13
+ //
14
+
15
+ export function getMembershipChangesByDomainVerification<
16
+ Member extends { email: string; verification_type: string },
17
+ >({
18
+ domain,
19
+ members,
20
+ verification_type,
21
+ }: {
22
+ domain: string;
23
+ members: ReadonlyArray<Member>;
24
+ verification_type: EmailDomainNoPendingVerificationType;
25
+ }) {
26
+ const domain_members = members.filter(
27
+ ({ email }) => getEmailDomain(email) === domain,
28
+ );
29
+
30
+ return match(verification_type)
31
+ .with(...EmailDomainApprovedVerificationValues, (verification_type) => ({
32
+ kind: "domain_approved" as const,
33
+ promoted_members: domain_members.filter(
34
+ ({ verification_type }) =>
35
+ UnverifiedLinkEnum.safeParse(verification_type).success ||
36
+ SuperWeakLinkEnum.safeParse(verification_type).success,
37
+ ),
38
+ verification_type,
39
+ }))
40
+ .with(...EmailDomainRejectedVerificationValues, (verification_type) => ({
41
+ kind: "domain_refused" as const,
42
+ removed_members: domain_members,
43
+ verification_type,
44
+ }))
45
+ .exhaustive();
46
+ }
@@ -1,7 +1,7 @@
1
1
  //
2
2
 
3
3
  export * from "./compute-service-public-info.js";
4
- export * from "./get-member-ids-promoted-by-domain.js";
4
+ export * from "./get-membership-changes-by-domain-verification.js";
5
5
  export * from "./is-domain-allowed-for-organization.js";
6
6
  export * from "./is-entreprise-unipersonnelle.js";
7
7
  export * from "./is-organization-covered-by-certification-dirigeant.js";
@@ -1,6 +1,9 @@
1
1
  import { z } from "zod";
2
2
 
3
- export const AuthorizationRequestOutcomeEnum = z.enum(["succeeded"]);
3
+ export const AuthorizationRequestOutcomeEnum = z.enum([
4
+ "signed_out",
5
+ "succeeded",
6
+ ]);
4
7
 
5
8
  export type AuthorizationRequestOutcome = z.output<
6
9
  typeof AuthorizationRequestOutcomeEnum
@@ -14,6 +17,7 @@ export interface BaseAuthorizationRequest {
14
17
  user_ip_address: string | null;
15
18
  interaction_cid: string | null;
16
19
  outcome: AuthorizationRequestOutcome | null;
20
+ sid: string | null;
17
21
  }
18
22
 
19
23
  export interface AuthorizationRequest extends BaseAuthorizationRequest {
@@ -1,9 +0,0 @@
1
- export declare function getMemberIdsPromotedByDomain({ domain, members, }: {
2
- domain: string;
3
- members: ReadonlyArray<{
4
- email: string;
5
- id: number;
6
- verification_type: string;
7
- }>;
8
- }): number[];
9
- //# sourceMappingURL=get-member-ids-promoted-by-domain.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-member-ids-promoted-by-domain.d.ts","sourceRoot":"","sources":["../../../src/services/organization/get-member-ids-promoted-by-domain.ts"],"names":[],"mappings":"AAOA,wBAAgB,4BAA4B,CAAC,EAC3C,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,iBAAiB,EAAE,MAAM,CAAC;KAC3B,CAAC,CAAC;CACJ,YASA"}
@@ -1,11 +0,0 @@
1
- //
2
- import { SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
3
- import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
4
- //
5
- export function getMemberIdsPromotedByDomain({ domain, members, }) {
6
- return members
7
- .filter(({ email, verification_type }) => getEmailDomain(email) === domain &&
8
- (UnverifiedLinkEnum.safeParse(verification_type).success ||
9
- SuperWeakLinkEnum.safeParse(verification_type).success))
10
- .map(({ id }) => id);
11
- }
@@ -1,100 +0,0 @@
1
- //
2
-
3
- import { getMemberIdsPromotedByDomain } from "#src/services/organization";
4
- import assert from "node:assert/strict";
5
- import { describe, it } from "node:test";
6
-
7
- //
8
-
9
- describe("getMemberIdsPromotedByDomain", () => {
10
- it("should promote unverified and super weak members of the domain", () => {
11
- assert.deepEqual(
12
- getMemberIdsPromotedByDomain({
13
- domain: "darkangels.world",
14
- members: [
15
- {
16
- email: "lion.eljonson@darkangels.world",
17
- id: 1,
18
- verification_type: "no_validation_means_available",
19
- },
20
- {
21
- email: "cat.eljonson@darkangels.world",
22
- id: 2,
23
- verification_type:
24
- "no_verification_means_for_entreprise_unipersonnelle",
25
- },
26
- {
27
- email: "tiger.eljonson@darkangels.world",
28
- id: 3,
29
- verification_type: "no_verification_means_for_small_association",
30
- },
31
- {
32
- email: "wolf.eljonson@darkangels.world",
33
- id: 4,
34
- verification_type: "no_verification_means_for_small_organization",
35
- },
36
- {
37
- email: "mouse.eljonson@darkangels.world",
38
- id: 5,
39
- verification_type: "domain_not_verified_yet",
40
- },
41
- ],
42
- }),
43
- [1, 2, 3, 4, 5],
44
- );
45
- });
46
-
47
- it("should not promote members of another domain", () => {
48
- assert.deepEqual(
49
- getMemberIdsPromotedByDomain({
50
- domain: "darkangels.world",
51
- members: [
52
- {
53
- email: "foo@bar.world",
54
- id: 1,
55
- verification_type: "no_validation_means_available",
56
- },
57
- {
58
- email: "luther@sub.darkangels.world",
59
- id: 2,
60
- verification_type: "no_validation_means_available",
61
- },
62
- ],
63
- }),
64
- [],
65
- );
66
- });
67
-
68
- it("should not promote members with a verified link", () => {
69
- assert.deepEqual(
70
- getMemberIdsPromotedByDomain({
71
- domain: "darkangels.world",
72
- members: [
73
- {
74
- email: "lion.eljonson@darkangels.world",
75
- id: 1,
76
- verification_type: "organization_dirigeant",
77
- },
78
- {
79
- email: "azrael@darkangels.world",
80
- id: 2,
81
- verification_type: "domain",
82
- },
83
- {
84
- email: "belial@darkangels.world",
85
- id: 3,
86
- verification_type: "official_contact_email",
87
- },
88
- ],
89
- }),
90
- [],
91
- );
92
- });
93
-
94
- it("should not promote anyone without members", () => {
95
- assert.deepEqual(
96
- getMemberIdsPromotedByDomain({ domain: "darkangels.world", members: [] }),
97
- [],
98
- );
99
- });
100
- });
@@ -1,27 +0,0 @@
1
- //
2
-
3
- import { SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
4
- import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
5
-
6
- //
7
-
8
- export function getMemberIdsPromotedByDomain({
9
- domain,
10
- members,
11
- }: {
12
- domain: string;
13
- members: ReadonlyArray<{
14
- email: string;
15
- id: number;
16
- verification_type: string;
17
- }>;
18
- }) {
19
- return members
20
- .filter(
21
- ({ email, verification_type }) =>
22
- getEmailDomain(email) === domain &&
23
- (UnverifiedLinkEnum.safeParse(verification_type).success ||
24
- SuperWeakLinkEnum.safeParse(verification_type).success),
25
- )
26
- .map(({ id }) => id);
27
- }