@proconnect-gouv/proconnect.identite.runtime 0.4.0 → 0.6.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 (57) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/activity/activity-context-schemas.d.ts +51 -0
  3. package/dist/activity/activity-context-schemas.d.ts.map +1 -1
  4. package/dist/certification/activities.d.ts +64 -0
  5. package/dist/certification/activities.d.ts.map +1 -0
  6. package/dist/certification/activities.js +78 -0
  7. package/dist/certification/index.d.ts +2 -0
  8. package/dist/certification/index.d.ts.map +1 -0
  9. package/dist/certification/index.js +2 -0
  10. package/dist/domains/activities.d.ts +22 -0
  11. package/dist/domains/activities.d.ts.map +1 -1
  12. package/dist/domains/activities.js +20 -1
  13. package/dist/domains/change-email-domain-verification.d.ts +29 -0
  14. package/dist/domains/change-email-domain-verification.d.ts.map +1 -0
  15. package/dist/domains/change-email-domain-verification.js +167 -0
  16. package/dist/domains/index.d.ts +1 -1
  17. package/dist/domains/index.d.ts.map +1 -1
  18. package/dist/domains/index.js +1 -1
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1 -0
  22. package/dist/runtime/create-identite-runtime.d.ts +60 -20
  23. package/dist/runtime/create-identite-runtime.d.ts.map +1 -1
  24. package/dist/runtime/create-identite-runtime.js +13 -3
  25. package/dist/users/activities.d.ts +29 -0
  26. package/dist/users/activities.d.ts.map +1 -1
  27. package/dist/users/activities.js +20 -0
  28. package/dist/users/change-password.d.ts +16 -0
  29. package/dist/users/change-password.d.ts.map +1 -0
  30. package/dist/users/change-password.js +38 -0
  31. package/dist/users/index.d.ts +2 -0
  32. package/dist/users/index.d.ts.map +1 -1
  33. package/dist/users/index.js +2 -0
  34. package/dist/users/update-personal-informations.d.ts +21 -0
  35. package/dist/users/update-personal-informations.d.ts.map +1 -0
  36. package/dist/users/update-personal-informations.js +53 -0
  37. package/package.json +3 -3
  38. package/src/certification/activities.test.ts +128 -0
  39. package/src/certification/activities.ts +103 -0
  40. package/src/certification/index.ts +3 -0
  41. package/src/domains/activities.ts +23 -1
  42. package/src/domains/{mark-domain-as-verified.test.ts → change-email-domain-verification.test.ts} +98 -8
  43. package/src/domains/change-email-domain-verification.ts +305 -0
  44. package/src/domains/index.ts +1 -1
  45. package/src/index.ts +1 -0
  46. package/src/runtime/create-identite-runtime.test.ts +20 -28
  47. package/src/runtime/create-identite-runtime.ts +18 -3
  48. package/src/users/activities.ts +21 -0
  49. package/src/users/change-password.test.ts +91 -0
  50. package/src/users/change-password.ts +64 -0
  51. package/src/users/index.ts +2 -0
  52. package/src/users/update-personal-informations.test.ts +113 -0
  53. package/src/users/update-personal-informations.ts +97 -0
  54. package/dist/domains/mark-domain-as-verified.d.ts +0 -25
  55. package/dist/domains/mark-domain-as-verified.d.ts.map +0 -1
  56. package/dist/domains/mark-domain-as-verified.js +0 -103
  57. package/src/domains/mark-domain-as-verified.ts +0 -174
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @proconnect-gouv/proconnect.identite.runtime
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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.
8
+
9
+ - [#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 la commande `markDomainAsVerified` par `changeEmailDomainVerification({ domain, organization_id, verification_type })`, qui accepte aussi les types refusés (`refused`, `blacklisted`). Une validation garde le comportement précédent (`domain.verified` et `member.promoted`). Un refus remplace les états du domaine sans `verified_at`, journalise `domain.refused` sous l’acteur reçu, retire de l’organisation chaque membre dont l’email est sur ce domaine et journalise une ligne `member.removed` par membre sous l’acteur `{ type: "app", job: "domain.remove_members" }`, avec `cause_activity_id`. L’issue unique `domain_verification_changed` porte `promoted_members` et `removed_members`. `activityContextSchemas` décrit désormais `domain.refused` : hyyypertool doit retirer sa propre définition et sa transaction de refus en passant à cette version.
10
+
11
+ - [#2451](https://github.com/proconnect-gouv/proconnect-identite/pull/2451) [`0b133b6`](https://github.com/proconnect-gouv/proconnect-identite/commit/0b133b61cbe46af2347fc1eb1eaee8302ebfb94c) Thanks [@douglasduteil](https://github.com/douglasduteil)! - `activityContextSchemas` décrit l’action `domain.removed`, écrite jusqu’ici par hyyypertool seul : `inputs.domain`, `outcome.email_domain_id` et `outcome.previous_verification_type`. hyyypertool doit retirer sa propre définition de `domain.removed` en passant à cette version.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [[`efdd64d`](https://github.com/proconnect-gouv/proconnect-identite/commit/efdd64d8c342b586c76ac4e6717323d4486bf16d), [`918ab32`](https://github.com/proconnect-gouv/proconnect-identite/commit/918ab32555b01df0363e8d531b6c6a4331ef0970), [`304e89d`](https://github.com/proconnect-gouv/proconnect-identite/commit/304e89d2169c5a112af5d1465799151ebf9a871a)]:
16
+ - @proconnect-gouv/proconnect.identite@16.0.0
17
+ - @proconnect-gouv/proconnect.identite.database@2.1.0
18
+
19
+ ## 0.5.0
20
+
21
+ ### Minor Changes
22
+
23
+ - [#2407](https://github.com/proconnect-gouv/proconnect-identite/pull/2407) [`c801a10`](https://github.com/proconnect-gouv/proconnect-identite/commit/c801a108fd71b38f179dd2e21f62fc440e56fee6) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute la commande `updatePersonalInformations` et le schéma `user.info_changed` : le changement de nom, téléphone ou fonction est journalisé avec les valeurs précédentes, et une demande sans changement n'écrit rien.
24
+
25
+ - [#2408](https://github.com/proconnect-gouv/proconnect-identite/pull/2408) [`478e680`](https://github.com/proconnect-gouv/proconnect-identite/commit/478e680e7f83f4c24f37e84f9134856dbaa753a2) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute la commande `changePassword` et le schéma `user.password_changed` : un mot de passe défini à la réinitialisation ou à l'inscription est journalisé avec l'état précédent, sans jamais écrire le mot de passe ni son empreinte.
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [[`c1167a1`](https://github.com/proconnect-gouv/proconnect-identite/commit/c1167a150b16060ca704059e98040414bbf7a009), [`33604f3`](https://github.com/proconnect-gouv/proconnect-identite/commit/33604f32fb4393ec60e413f0b7bace8e94ac22fc), [`c1167a1`](https://github.com/proconnect-gouv/proconnect-identite/commit/c1167a150b16060ca704059e98040414bbf7a009)]:
30
+ - @proconnect-gouv/proconnect.identite.database@2.0.0
31
+ - @proconnect-gouv/proconnect.identite@15.0.0
32
+
3
33
  ## 0.4.0
4
34
 
5
35
  ### Minor Changes
@@ -15,6 +15,22 @@ export declare const activityContextSchemas: {
15
15
  }, import("zod/v4/core").$strip>>;
16
16
  }, import("zod/v4/core").$strip>;
17
17
  }, import("zod/v4/core").$strip>;
18
+ "user.info_changed": import("zod").ZodObject<{
19
+ inputs: import("zod").ZodObject<{
20
+ family_name: import("zod").ZodNullable<import("zod").ZodString>;
21
+ given_name: import("zod").ZodNullable<import("zod").ZodString>;
22
+ job: import("zod").ZodNullable<import("zod").ZodString>;
23
+ phone_number: import("zod").ZodNullable<import("zod").ZodString>;
24
+ }, import("zod/v4/core").$strip>;
25
+ outcome: import("zod").ZodObject<{
26
+ previous: import("zod").ZodObject<{
27
+ family_name: import("zod").ZodNullable<import("zod").ZodString>;
28
+ given_name: import("zod").ZodNullable<import("zod").ZodString>;
29
+ job: import("zod").ZodNullable<import("zod").ZodString>;
30
+ phone_number: import("zod").ZodNullable<import("zod").ZodString>;
31
+ }, import("zod/v4/core").$strip>;
32
+ }, import("zod/v4/core").$strip>;
33
+ }, import("zod/v4/core").$strip>;
18
34
  "user.mfa_reset": import("zod").ZodObject<{
19
35
  inputs: import("zod").ZodObject<{
20
36
  user_id: import("zod").ZodNumber;
@@ -29,6 +45,19 @@ export declare const activityContextSchemas: {
29
45
  }, import("zod/v4/core").$strip>;
30
46
  }, import("zod/v4/core").$strip>;
31
47
  }, import("zod/v4/core").$strip>;
48
+ "user.password_changed": import("zod").ZodObject<{
49
+ inputs: import("zod").ZodObject<{
50
+ source: import("zod").ZodEnum<{
51
+ reset_password: "reset_password";
52
+ signup: "signup";
53
+ }>;
54
+ }, import("zod/v4/core").$strip>;
55
+ outcome: import("zod").ZodObject<{
56
+ previous: import("zod").ZodObject<{
57
+ email_verified: import("zod").ZodBoolean;
58
+ }, import("zod/v4/core").$strip>;
59
+ }, import("zod/v4/core").$strip>;
60
+ }, import("zod/v4/core").$strip>;
32
61
  "moderation.opened": import("zod").ZodObject<{
33
62
  inputs: import("zod").ZodObject<{
34
63
  sp_name: import("zod").ZodNullable<import("zod").ZodString>;
@@ -101,6 +130,28 @@ export declare const activityContextSchemas: {
101
130
  connected_at: import("zod").ZodString;
102
131
  }, import("zod/v4/core").$strip>;
103
132
  }, import("zod/v4/core").$strip>;
133
+ "domain.refused": import("zod").ZodObject<{
134
+ inputs: import("zod").ZodObject<{
135
+ domain: import("zod").ZodString;
136
+ verification_type: import("zod").ZodEnum<{
137
+ blacklisted: "blacklisted";
138
+ refused: "refused";
139
+ }>;
140
+ }, import("zod/v4/core").$strip>;
141
+ outcome: import("zod").ZodObject<{
142
+ email_domain_id: import("zod").ZodNumber;
143
+ replaced_verification_types: import("zod").ZodArray<import("zod").ZodString>;
144
+ }, import("zod/v4/core").$strip>;
145
+ }, import("zod/v4/core").$strip>;
146
+ "domain.removed": import("zod").ZodObject<{
147
+ inputs: import("zod").ZodObject<{
148
+ domain: import("zod").ZodString;
149
+ }, import("zod/v4/core").$strip>;
150
+ outcome: import("zod").ZodObject<{
151
+ email_domain_id: import("zod").ZodNumber;
152
+ previous_verification_type: import("zod").ZodString;
153
+ }, import("zod/v4/core").$strip>;
154
+ }, import("zod/v4/core").$strip>;
104
155
  "domain.verified": import("zod").ZodObject<{
105
156
  inputs: import("zod").ZodObject<{
106
157
  domain: import("zod").ZodString;
@@ -1 +1 @@
1
- {"version":3,"file":"activity-context-schemas.d.ts","sourceRoot":"","sources":["../../src/activity/activity-context-schemas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI7C,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAMlC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
1
+ {"version":3,"file":"activity-context-schemas.d.ts","sourceRoot":"","sources":["../../src/activity/activity-context-schemas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI7C,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAMlC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,64 @@
1
+ import type { ActivityOf, ContextsOf } from "#src/activity";
2
+ import { type processCertificationDirigeantFactory } from "@proconnect-gouv/proconnect.identite/managers/certification";
3
+ import * as z from "zod";
4
+ export declare const certificationDirigeantActivities: {
5
+ "certification_dirigeant.certified": z.ZodObject<{
6
+ inputs: z.ZodObject<{}, z.core.$strip>;
7
+ outcome: z.ZodObject<{
8
+ source: z.ZodEnum<{
9
+ "api.insee.fr/api-sirene/private": "api.insee.fr/api-sirene/private";
10
+ "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux": "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux";
11
+ "registre-national-entreprises.inpi.fr/api": "registre-national-entreprises.inpi.fr/api";
12
+ }>;
13
+ }, z.core.$strip>;
14
+ }, z.core.$strip>;
15
+ "certification_dirigeant.close_matched": z.ZodObject<{
16
+ inputs: z.ZodObject<{}, z.core.$strip>;
17
+ outcome: z.ZodObject<{
18
+ diff: z.ZodRecord<z.ZodEnum<{
19
+ family_name: "family_name";
20
+ gender: "gender";
21
+ birth_country: "birth_country";
22
+ birth_date: "birth_date";
23
+ birth_place: "birth_place";
24
+ first_name: "first_name";
25
+ }> & z.core.$partial, z.ZodObject<{
26
+ franceconnect: z.ZodObject<{
27
+ compared: z.ZodNullable<z.ZodString>;
28
+ raw: z.ZodNullable<z.ZodString>;
29
+ }, z.core.$strip>;
30
+ source: z.ZodObject<{
31
+ compared: z.ZodNullable<z.ZodString>;
32
+ raw: z.ZodNullable<z.ZodString>;
33
+ }, z.core.$strip>;
34
+ }, z.core.$strip>>;
35
+ source: z.ZodEnum<{
36
+ "api.insee.fr/api-sirene/private": "api.insee.fr/api-sirene/private";
37
+ "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux": "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux";
38
+ "registre-national-entreprises.inpi.fr/api": "registre-national-entreprises.inpi.fr/api";
39
+ }>;
40
+ }, z.core.$strip>;
41
+ }, z.core.$strip>;
42
+ "certification_dirigeant.not_covered": z.ZodObject<{
43
+ inputs: z.ZodObject<{}, z.core.$strip>;
44
+ outcome: z.ZodObject<{}, z.core.$strip>;
45
+ }, z.core.$strip>;
46
+ "certification_dirigeant.not_matched": z.ZodObject<{
47
+ inputs: z.ZodObject<{}, z.core.$strip>;
48
+ outcome: z.ZodObject<{
49
+ reason: z.ZodEnum<{
50
+ below_threshold: "below_threshold";
51
+ no_candidates: "no_candidates";
52
+ }>;
53
+ source: z.ZodEnum<{
54
+ "api.insee.fr/api-sirene/private": "api.insee.fr/api-sirene/private";
55
+ "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux": "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux";
56
+ "registre-national-entreprises.inpi.fr/api": "registre-national-entreprises.inpi.fr/api";
57
+ }>;
58
+ }, z.core.$strip>;
59
+ }, z.core.$strip>;
60
+ };
61
+ type CertificationDirigeantResult = Awaited<ReturnType<ReturnType<typeof processCertificationDirigeantFactory>>>;
62
+ export declare function getCertificationDirigeantActivity(result: CertificationDirigeantResult): ActivityOf<ContextsOf<typeof certificationDirigeantActivities>>;
63
+ export {};
64
+ //# sourceMappingURL=activities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/certification/activities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAIL,KAAK,oCAAoC,EAC1C,MAAM,6DAA6D,CAAC;AACrE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AASzB,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4B5C,CAAC;AAIF,KAAK,4BAA4B,GAAG,OAAO,CACzC,UAAU,CAAC,UAAU,CAAC,OAAO,oCAAoC,CAAC,CAAC,CACpE,CAAC;AAEF,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,4BAA4B,GACnC,UAAU,CAAC,UAAU,CAAC,OAAO,gCAAgC,CAAC,CAAC,CA0CjE"}
@@ -0,0 +1,78 @@
1
+ //
2
+ import { CertificationDirigeantDataSource, compareCriteria, MatchCriteria, } from "@proconnect-gouv/proconnect.identite/managers/certification";
3
+ import * as z from "zod";
4
+ //
5
+ const ComparedValue = z.object({
6
+ compared: z.string().nullable(),
7
+ raw: z.string().nullable(),
8
+ });
9
+ export const certificationDirigeantActivities = {
10
+ "certification_dirigeant.certified": z.object({
11
+ inputs: z.object({}),
12
+ outcome: z.object({
13
+ source: CertificationDirigeantDataSource,
14
+ }),
15
+ }),
16
+ "certification_dirigeant.close_matched": z.object({
17
+ inputs: z.object({}),
18
+ outcome: z.object({
19
+ diff: z.partialRecord(MatchCriteria, z.object({ franceconnect: ComparedValue, source: ComparedValue })),
20
+ source: CertificationDirigeantDataSource,
21
+ }),
22
+ }),
23
+ "certification_dirigeant.not_covered": z.object({
24
+ inputs: z.object({}),
25
+ outcome: z.object({}),
26
+ }),
27
+ "certification_dirigeant.not_matched": z.object({
28
+ inputs: z.object({}),
29
+ outcome: z.object({
30
+ reason: z.enum(["below_threshold", "no_candidates"]),
31
+ source: CertificationDirigeantDataSource,
32
+ }),
33
+ }),
34
+ };
35
+ export function getCertificationDirigeantActivity(result) {
36
+ switch (result.cause) {
37
+ case "organisation_not_covered":
38
+ return {
39
+ action: "certification_dirigeant.not_covered",
40
+ context: { inputs: {}, outcome: {} },
41
+ };
42
+ case "exact_match":
43
+ return {
44
+ action: "certification_dirigeant.certified",
45
+ context: { inputs: {}, outcome: { source: result.details.source } },
46
+ };
47
+ case "close_match":
48
+ return {
49
+ action: "certification_dirigeant.close_matched",
50
+ context: {
51
+ inputs: {},
52
+ outcome: {
53
+ diff: Object.fromEntries(compareCriteria(result.details.identity, result.details.dirigeant)
54
+ .filter(({ matched }) => !matched)
55
+ .map(({ criterion, franceconnect, source }) => [
56
+ criterion,
57
+ { franceconnect, source },
58
+ ])),
59
+ source: result.details.source,
60
+ },
61
+ },
62
+ };
63
+ case "below_threshold":
64
+ case "no_candidates":
65
+ return {
66
+ action: "certification_dirigeant.not_matched",
67
+ context: {
68
+ inputs: {},
69
+ outcome: { reason: result.cause, source: result.details.source },
70
+ },
71
+ };
72
+ default:
73
+ return assert_never(result);
74
+ }
75
+ }
76
+ function assert_never(value) {
77
+ throw new Error(`Unhandled certification result: ${JSON.stringify(value)}`);
78
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./activities.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/certification/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ //
2
+ export * from "./activities.js";
@@ -1,5 +1,27 @@
1
1
  import * as z from "zod";
2
2
  export declare const domainActivities: {
3
+ "domain.refused": z.ZodObject<{
4
+ inputs: z.ZodObject<{
5
+ domain: z.ZodString;
6
+ verification_type: z.ZodEnum<{
7
+ blacklisted: "blacklisted";
8
+ refused: "refused";
9
+ }>;
10
+ }, z.core.$strip>;
11
+ outcome: z.ZodObject<{
12
+ email_domain_id: z.ZodNumber;
13
+ replaced_verification_types: z.ZodArray<z.ZodString>;
14
+ }, z.core.$strip>;
15
+ }, z.core.$strip>;
16
+ "domain.removed": z.ZodObject<{
17
+ inputs: z.ZodObject<{
18
+ domain: z.ZodString;
19
+ }, z.core.$strip>;
20
+ outcome: z.ZodObject<{
21
+ email_domain_id: z.ZodNumber;
22
+ previous_verification_type: z.ZodString;
23
+ }, z.core.$strip>;
24
+ }, z.core.$strip>;
3
25
  "domain.verified": z.ZodObject<{
4
26
  inputs: z.ZodObject<{
5
27
  domain: z.ZodString;
@@ -1 +1 @@
1
- {"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/domains/activities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;CAW5B,CAAC"}
1
+ {"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/domains/activities.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8B5B,CAAC"}
@@ -1,8 +1,27 @@
1
1
  //
2
- import { EmailDomainApprovedVerificationEnum } from "@proconnect-gouv/proconnect.identite/types";
2
+ import { EmailDomainApprovedVerificationEnum, EmailDomainRejectedVerificationEnum, } from "@proconnect-gouv/proconnect.identite/types";
3
3
  import * as z from "zod";
4
4
  //
5
5
  export const domainActivities = {
6
+ "domain.refused": z.object({
7
+ inputs: z.object({
8
+ domain: z.string(),
9
+ verification_type: EmailDomainRejectedVerificationEnum,
10
+ }),
11
+ outcome: z.object({
12
+ email_domain_id: z.number(),
13
+ replaced_verification_types: z.array(z.string()),
14
+ }),
15
+ }),
16
+ "domain.removed": z.object({
17
+ inputs: z.object({
18
+ domain: z.string(),
19
+ }),
20
+ outcome: z.object({
21
+ email_domain_id: z.number(),
22
+ previous_verification_type: z.string(),
23
+ }),
24
+ }),
6
25
  "domain.verified": z.object({
7
26
  inputs: z.object({
8
27
  domain: z.string(),
@@ -0,0 +1,29 @@
1
+ import type { RuntimeContext } from "#src/activity";
2
+ import { type EmailDomainNoPendingVerificationType } from "@proconnect-gouv/proconnect.identite/types";
3
+ type ChangeEmailDomainVerificationOutcome = {
4
+ kind: "domain_verification_changed";
5
+ activity_id: number;
6
+ email_domain: {
7
+ id: number;
8
+ verification_type: EmailDomainNoPendingVerificationType;
9
+ };
10
+ promoted_members: ReadonlyArray<{
11
+ previous_verification_type: string;
12
+ user_id: number;
13
+ }>;
14
+ removed_members: ReadonlyArray<{
15
+ previous_verification_type: string;
16
+ user_id: number;
17
+ }>;
18
+ replaced_verification_types: ReadonlyArray<string>;
19
+ } | {
20
+ kind: "organization_not_found";
21
+ organization_id: number;
22
+ };
23
+ export declare function changeEmailDomainVerificationFactory({ actor, app, db, }: RuntimeContext): ({ domain, organization_id, verification_type, }: {
24
+ domain: string;
25
+ organization_id: number;
26
+ verification_type: EmailDomainNoPendingVerificationType;
27
+ }) => Promise<ChangeEmailDomainVerificationOutcome>;
28
+ export {};
29
+ //# sourceMappingURL=change-email-domain-verification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"change-email-domain-verification.d.ts","sourceRoot":"","sources":["../../src/domains/change-email-domain-verification.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAQtE,OAAO,EAKL,KAAK,oCAAoC,EAC1C,MAAM,4CAA4C,CAAC;AAKpD,KAAK,oCAAoC,GACrC;IACE,IAAI,EAAE,6BAA6B,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,iBAAiB,EAAE,oCAAoC,CAAC;KACzD,CAAC;IACF,gBAAgB,EAAE,aAAa,CAAC;QAC9B,0BAA0B,EAAE,MAAM,CAAC;QACnC,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;IACH,eAAe,EAAE,aAAa,CAAC;QAC7B,0BAA0B,EAAE,MAAM,CAAC;QACnC,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;IACH,2BAA2B,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACpD,GACD;IAAE,IAAI,EAAE,wBAAwB,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC;AAIhE,wBAAgB,oCAAoC,CAAC,EACnD,KAAK,EACL,GAAG,EACH,EAAE,GACH,EAAE,cAAc,IAC+B,iDAI3C;IACD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,oCAAoC,CAAC;CACzD,KAAG,OAAO,CAAC,oCAAoC,CAAC,CAkGlD"}
@@ -0,0 +1,167 @@
1
+ //
2
+ import { insertActivity } from "#src/journal";
3
+ import { email_domains, users_organizations, } from "@proconnect-gouv/proconnect.identite.database/drizzle";
4
+ import { getMembershipChangesByDomainVerification } from "@proconnect-gouv/proconnect.identite/services/organization";
5
+ import { EmailDomainApprovedVerificationValues, EmailDomainPendingVerificationValues, EmailDomainRejectedVerificationValues, LinkEnum, } from "@proconnect-gouv/proconnect.identite/types";
6
+ import { and, eq, inArray, sql } from "drizzle-orm";
7
+ export function changeEmailDomainVerificationFactory({ actor, app, db, }) {
8
+ return function changeEmailDomainVerification({ domain, organization_id, verification_type, }) {
9
+ return db.transaction(async (tx) => {
10
+ const organization = await tx.query.organizations.findFirst({
11
+ columns: { id: true },
12
+ where: (table, { eq }) => eq(table.id, organization_id),
13
+ });
14
+ if (!organization) {
15
+ return { kind: "organization_not_found", organization_id };
16
+ }
17
+ const changes = getMembershipChangesByDomainVerification({
18
+ domain,
19
+ members: await findMembers(tx, { organization_id }),
20
+ verification_type,
21
+ });
22
+ switch (changes.kind) {
23
+ case "domain_approved": {
24
+ const { email_domain_id, replaced_verification_types } = await replaceEmailDomain(tx, {
25
+ domain,
26
+ organization_id,
27
+ verification_type: changes.verification_type,
28
+ verified_at: sql `now()`,
29
+ });
30
+ const { activity_id } = await insertActivity(tx, {
31
+ action: "domain.verified",
32
+ actor,
33
+ app,
34
+ context: {
35
+ inputs: { domain, verification_type: changes.verification_type },
36
+ outcome: { email_domain_id, replaced_verification_types },
37
+ },
38
+ organization_id,
39
+ });
40
+ await promoteMembers(tx, {
41
+ app,
42
+ cause_activity_id: activity_id,
43
+ members: changes.promoted_members,
44
+ organization_id,
45
+ });
46
+ return {
47
+ kind: "domain_verification_changed",
48
+ activity_id,
49
+ email_domain: { id: email_domain_id, verification_type },
50
+ promoted_members: changes.promoted_members.map(toPreviousMembership),
51
+ removed_members: [],
52
+ replaced_verification_types,
53
+ };
54
+ }
55
+ case "domain_refused": {
56
+ const { email_domain_id, replaced_verification_types } = await replaceEmailDomain(tx, {
57
+ domain,
58
+ organization_id,
59
+ verification_type: changes.verification_type,
60
+ verified_at: null,
61
+ });
62
+ const { activity_id } = await insertActivity(tx, {
63
+ action: "domain.refused",
64
+ actor,
65
+ app,
66
+ context: {
67
+ inputs: { domain, verification_type: changes.verification_type },
68
+ outcome: { email_domain_id, replaced_verification_types },
69
+ },
70
+ organization_id,
71
+ });
72
+ await removeMembers(tx, {
73
+ app,
74
+ cause_activity_id: activity_id,
75
+ members: changes.removed_members,
76
+ organization_id,
77
+ });
78
+ return {
79
+ kind: "domain_verification_changed",
80
+ activity_id,
81
+ email_domain: { id: email_domain_id, verification_type },
82
+ promoted_members: [],
83
+ removed_members: changes.removed_members.map(toPreviousMembership),
84
+ replaced_verification_types,
85
+ };
86
+ }
87
+ default: {
88
+ const unhandled_changes = changes;
89
+ throw new Error(`Unhandled membership changes: ${JSON.stringify(unhandled_changes)}`);
90
+ }
91
+ }
92
+ });
93
+ };
94
+ }
95
+ //
96
+ async function findMembers(tx, { organization_id }) {
97
+ const memberships = await tx.query.users_organizations.findMany({
98
+ columns: { is_external: true, user_id: true, verification_type: true },
99
+ where: (table, { eq }) => eq(table.organization_id, organization_id),
100
+ with: { user: { columns: { email: true } } },
101
+ });
102
+ return memberships.map(({ is_external, user: { email }, user_id, verification_type }) => ({
103
+ email,
104
+ is_external,
105
+ user_id,
106
+ verification_type,
107
+ }));
108
+ }
109
+ async function replaceEmailDomain(tx, { domain, organization_id, verification_type, verified_at, }) {
110
+ const replaced = await tx
111
+ .delete(email_domains)
112
+ .where(and(eq(email_domains.organization_id, organization_id), eq(email_domains.domain, domain), inArray(email_domains.verification_type, [
113
+ ...EmailDomainApprovedVerificationValues,
114
+ ...EmailDomainPendingVerificationValues,
115
+ ...EmailDomainRejectedVerificationValues,
116
+ ])))
117
+ .returning({ verification_type: email_domains.verification_type });
118
+ const [email_domain] = await tx
119
+ .insert(email_domains)
120
+ .values({ domain, organization_id, verification_type, verified_at })
121
+ .returning({ id: email_domains.id });
122
+ return {
123
+ email_domain_id: email_domain.id,
124
+ replaced_verification_types: replaced.map(({ verification_type }) => verification_type),
125
+ };
126
+ }
127
+ async function promoteMembers(tx, { app, cause_activity_id, members, organization_id, }) {
128
+ if (members.length === 0)
129
+ return;
130
+ await tx
131
+ .update(users_organizations)
132
+ .set({ updated_at: sql `now()`, verification_type: LinkEnum.enum.domain })
133
+ .where(and(eq(users_organizations.organization_id, organization_id), inArray(users_organizations.user_id, members.map(({ user_id }) => user_id))));
134
+ for (const { user_id, verification_type } of members) {
135
+ await insertActivity(tx, {
136
+ action: "member.promoted",
137
+ actor: { type: "app", job: "domain.promote_members" },
138
+ app,
139
+ cause_activity_id,
140
+ context: {
141
+ inputs: { previous_verification_type: verification_type },
142
+ outcome: { verification_type: LinkEnum.enum.domain },
143
+ },
144
+ organization_id,
145
+ user_id,
146
+ });
147
+ }
148
+ }
149
+ async function removeMembers(tx, { app, cause_activity_id, members, organization_id, }) {
150
+ if (members.length === 0)
151
+ return;
152
+ await tx.delete(users_organizations).where(and(eq(users_organizations.organization_id, organization_id), inArray(users_organizations.user_id, members.map(({ user_id }) => user_id))));
153
+ for (const { is_external, user_id, verification_type } of members) {
154
+ await insertActivity(tx, {
155
+ action: "member.removed",
156
+ actor: { type: "app", job: "domain.remove_members" },
157
+ app,
158
+ cause_activity_id,
159
+ context: { inputs: {}, outcome: { is_external, verification_type } },
160
+ organization_id,
161
+ user_id,
162
+ });
163
+ }
164
+ }
165
+ function toPreviousMembership({ user_id, verification_type }) {
166
+ return { previous_verification_type: verification_type, user_id };
167
+ }
@@ -1,3 +1,3 @@
1
1
  export * from "./activities.js";
2
- export * from "./mark-domain-as-verified.js";
2
+ export * from "./change-email-domain-verification.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/domains/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/domains/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,uCAAuC,CAAC"}
@@ -1,3 +1,3 @@
1
1
  //
2
2
  export * from "./activities.js";
3
- export * from "./mark-domain-as-verified.js";
3
+ export * from "./change-email-domain-verification.js";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./activity/index.js";
2
+ export * from "./certification/index.js";
2
3
  export * from "./database/index.js";
3
4
  export * from "./runtime/index.js";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  //
2
2
  export * from "./activity/index.js";
3
+ export * from "./certification/index.js";
3
4
  export * from "./database/index.js";
4
5
  export * from "./runtime/index.js";