@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
@@ -21,6 +21,41 @@ export declare function createIdentiteRuntime<OwnContexts extends ContextMap & {
21
21
  organization_id: number;
22
22
  user_id: number;
23
23
  }>;
24
+ changeEmailDomainVerification: ({ domain, organization_id, verification_type, }: {
25
+ domain: string;
26
+ organization_id: number;
27
+ verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainNoPendingVerificationType;
28
+ }) => Promise<{
29
+ kind: "domain_verification_changed";
30
+ activity_id: number;
31
+ email_domain: {
32
+ id: number;
33
+ verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainNoPendingVerificationType;
34
+ };
35
+ promoted_members: ReadonlyArray<{
36
+ previous_verification_type: string;
37
+ user_id: number;
38
+ }>;
39
+ removed_members: ReadonlyArray<{
40
+ previous_verification_type: string;
41
+ user_id: number;
42
+ }>;
43
+ replaced_verification_types: ReadonlyArray<string>;
44
+ } | {
45
+ kind: "organization_not_found";
46
+ organization_id: number;
47
+ }>;
48
+ changePassword: ({ encrypted_password, source, user_id, }: {
49
+ encrypted_password: string;
50
+ source: "reset_password" | "signup";
51
+ user_id: number;
52
+ }) => Promise<{
53
+ kind: "password_changed";
54
+ activity_id: number;
55
+ previous: {
56
+ email_verified: boolean;
57
+ };
58
+ }>;
24
59
  connectFranceConnect: ({ user_id, user_info, }: {
25
60
  user_id: number;
26
61
  user_info: import("@proconnect-gouv/proconnect.identite/types").FranceConnectUserInfoResponse;
@@ -56,26 +91,6 @@ export declare function createIdentiteRuntime<OwnContexts extends ContextMap & {
56
91
  kind: "franceconnect_identity_not_found";
57
92
  user_id: number;
58
93
  }>;
59
- markDomainAsVerified: ({ domain, domain_verification_type, organization_id, }: {
60
- domain: string;
61
- domain_verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainApprovedVerificationType;
62
- organization_id: number;
63
- }) => Promise<{
64
- kind: "domain_verified";
65
- activity_id: number;
66
- email_domain: {
67
- id: number;
68
- verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainApprovedVerificationType;
69
- };
70
- promoted_members: ReadonlyArray<{
71
- previous_verification_type: string;
72
- user_id: number;
73
- }>;
74
- replaced_verification_types: ReadonlyArray<string>;
75
- } | {
76
- kind: "organization_not_found";
77
- organization_id: number;
78
- }>;
79
94
  openModeration: ({ organization_id, sp_name, ticket_id, type, user_id, }: {
80
95
  organization_id: number;
81
96
  sp_name?: string | null;
@@ -143,6 +158,31 @@ export declare function createIdentiteRuntime<OwnContexts extends ContextMap & {
143
158
  organization_id: number;
144
159
  user_id: number;
145
160
  }>;
161
+ updatePersonalInformations: ({ information, user_id, }: {
162
+ information: Partial<Pick<import("@proconnect-gouv/proconnect.identite/types").User, "family_name" | "given_name" | "job" | "phone_number">>;
163
+ user_id: number;
164
+ }) => Promise<{
165
+ kind: "info_changed";
166
+ activity_id: number;
167
+ next: {
168
+ given_name: string | null;
169
+ family_name: string | null;
170
+ phone_number: string | null;
171
+ job: string | null;
172
+ };
173
+ previous: {
174
+ given_name: string | null;
175
+ family_name: string | null;
176
+ phone_number: string | null;
177
+ job: string | null;
178
+ };
179
+ } | {
180
+ kind: "info_unchanged";
181
+ user_id: number;
182
+ } | {
183
+ kind: "user_not_found";
184
+ user_id: number;
185
+ }>;
146
186
  };
147
187
  };
148
188
  //# sourceMappingURL=create-identite-runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-identite-runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/create-identite-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,KAAK,EACL,UAAU,EACV,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAiBzD,wBAAgB,qBAAqB,CACnC,WAAW,SAAS,UAAU,GAAG;KAC9B,MAAM,IAAI,MAAM,gBAAgB,CAAC,CAAC,EAAE,KAAK;CAC3C,GAAG,EAAE,EACN,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC;cAE9B,KAAK;;uBADf,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAjBQ,gCACI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAWc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;qBAoBlB,mBAAmB,YACb,UAAU,CAAC,WAAW,CAAC,GAAG,eAAe;;;;;;;;sBAhCxD,kCAAmC,WACpC;;;;;;uBAmBK,CAAC;;;;;;;8BAEqB,CAAC;6BAA0B,CAAC;;;;;;;;;;;;;;;;;;EAiB1D"}
1
+ {"version":3,"file":"create-identite-runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/create-identite-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,KAAK,EACL,UAAU,EACV,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAsBzD,wBAAgB,qBAAqB,CACnC,WAAW,SAAS,UAAU,GAAG;KAC9B,MAAM,IAAI,MAAM,gBAAgB,CAAC,CAAC,EAAE,KAAK;CAC3C,GAAG,EAAE,EACN,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC;cAE9B,KAAK;;uBAJe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAnB/B,gCACI;;;;;;;;;;;;;;;;;mBAWU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;qBA8BL,mBAAmB,YACb,UAAU,CAAC,WAAW,CAAC,GAAG,eAAe;;;;;;;;sBA3CpC,kCACM,WAAW;;;;;;uBAuB7B,CAAC;;;;;;;8BAGC,CAAC;6BAEN,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BV"}
@@ -1,16 +1,22 @@
1
1
  //
2
- import { markDomainAsVerifiedFactory } from "#src/domains";
2
+ import { changeEmailDomainVerificationFactory } from "#src/domains";
3
3
  import { connectFranceConnectFactory, disconnectFranceConnectFactory, } from "#src/franceconnect";
4
4
  import { insertActivity } from "#src/journal";
5
5
  import { addMembershipFactory, removeMembershipFactory, updateMembershipFactory, } from "#src/memberships";
6
6
  import { openModerationFactory } from "#src/moderations";
7
- import { deleteUserFactory, resetMfaFactory } from "#src/users";
7
+ import { changePasswordFactory, deleteUserFactory, resetMfaFactory, updatePersonalInformationsFactory, } from "#src/users";
8
8
  //
9
9
  export function createIdentiteRuntime({ app, db }) {
10
10
  return {
11
11
  as(actor) {
12
12
  return {
13
13
  addMembership: addMembershipFactory({ actor, app, db }),
14
+ changeEmailDomainVerification: changeEmailDomainVerificationFactory({
15
+ actor,
16
+ app,
17
+ db,
18
+ }),
19
+ changePassword: changePasswordFactory({ actor, app, db }),
14
20
  connectFranceConnect: connectFranceConnectFactory({ actor, app, db }),
15
21
  deleteUser: deleteUserFactory({ actor, app, db }),
16
22
  disconnectFranceConnect: disconnectFranceConnectFactory({
@@ -18,12 +24,16 @@ export function createIdentiteRuntime({ app, db }) {
18
24
  app,
19
25
  db,
20
26
  }),
21
- markDomainAsVerified: markDomainAsVerifiedFactory({ actor, app, db }),
22
27
  openModeration: openModerationFactory({ actor, app, db }),
23
28
  removeMembership: removeMembershipFactory({ actor, app, db }),
24
29
  record: (tx, activity) => insertActivity(tx, { ...activity, actor, app }),
25
30
  resetMfa: resetMfaFactory({ actor, app, db }),
26
31
  updateMembership: updateMembershipFactory({ actor, app, db }),
32
+ updatePersonalInformations: updatePersonalInformationsFactory({
33
+ actor,
34
+ app,
35
+ db,
36
+ }),
27
37
  };
28
38
  },
29
39
  };
@@ -15,6 +15,22 @@ export declare const userActivities: {
15
15
  }, z.core.$strip>>;
16
16
  }, z.core.$strip>;
17
17
  }, z.core.$strip>;
18
+ "user.info_changed": z.ZodObject<{
19
+ inputs: z.ZodObject<{
20
+ family_name: z.ZodNullable<z.ZodString>;
21
+ given_name: z.ZodNullable<z.ZodString>;
22
+ job: z.ZodNullable<z.ZodString>;
23
+ phone_number: z.ZodNullable<z.ZodString>;
24
+ }, z.core.$strip>;
25
+ outcome: z.ZodObject<{
26
+ previous: z.ZodObject<{
27
+ family_name: z.ZodNullable<z.ZodString>;
28
+ given_name: z.ZodNullable<z.ZodString>;
29
+ job: z.ZodNullable<z.ZodString>;
30
+ phone_number: z.ZodNullable<z.ZodString>;
31
+ }, z.core.$strip>;
32
+ }, z.core.$strip>;
33
+ }, z.core.$strip>;
18
34
  "user.mfa_reset": z.ZodObject<{
19
35
  inputs: z.ZodObject<{
20
36
  user_id: z.ZodNumber;
@@ -29,5 +45,18 @@ export declare const userActivities: {
29
45
  }, z.core.$strip>;
30
46
  }, z.core.$strip>;
31
47
  }, z.core.$strip>;
48
+ "user.password_changed": z.ZodObject<{
49
+ inputs: z.ZodObject<{
50
+ source: z.ZodEnum<{
51
+ reset_password: "reset_password";
52
+ signup: "signup";
53
+ }>;
54
+ }, z.core.$strip>;
55
+ outcome: z.ZodObject<{
56
+ previous: z.ZodObject<{
57
+ email_verified: z.ZodBoolean;
58
+ }, z.core.$strip>;
59
+ }, z.core.$strip>;
60
+ }, z.core.$strip>;
32
61
  };
33
62
  //# sourceMappingURL=activities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/users/activities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgC1B,CAAC"}
1
+ {"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/users/activities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAWzB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8C1B,CAAC"}
@@ -1,6 +1,12 @@
1
1
  //
2
2
  import * as z from "zod";
3
3
  //
4
+ const userInformation = z.object({
5
+ family_name: z.string().nullable(),
6
+ given_name: z.string().nullable(),
7
+ job: z.string().nullable(),
8
+ phone_number: z.string().nullable(),
9
+ });
4
10
  export const userActivities = {
5
11
  "user.deleted": z.object({
6
12
  inputs: z.object({
@@ -17,6 +23,12 @@ export const userActivities = {
17
23
  })),
18
24
  }),
19
25
  }),
26
+ "user.info_changed": z.object({
27
+ inputs: userInformation,
28
+ outcome: z.object({
29
+ previous: userInformation,
30
+ }),
31
+ }),
20
32
  "user.mfa_reset": z.object({
21
33
  inputs: z.object({
22
34
  user_id: z.number(),
@@ -31,4 +43,12 @@ export const userActivities = {
31
43
  }),
32
44
  }),
33
45
  }),
46
+ "user.password_changed": z.object({
47
+ inputs: z.object({
48
+ source: z.enum(["reset_password", "signup"]),
49
+ }),
50
+ outcome: z.object({
51
+ previous: z.object({ email_verified: z.boolean() }),
52
+ }),
53
+ }),
34
54
  };
@@ -0,0 +1,16 @@
1
+ import type { RuntimeContext } from "#src/activity";
2
+ type PasswordSource = "reset_password" | "signup";
3
+ type ChangePasswordOutcome = {
4
+ kind: "password_changed";
5
+ activity_id: number;
6
+ previous: {
7
+ email_verified: boolean;
8
+ };
9
+ };
10
+ export declare function changePasswordFactory({ actor, app, db }: RuntimeContext): ({ encrypted_password, source, user_id, }: {
11
+ encrypted_password: string;
12
+ source: PasswordSource;
13
+ user_id: number;
14
+ }) => Promise<ChangePasswordOutcome>;
15
+ export {};
16
+ //# sourceMappingURL=change-password.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"change-password.d.ts","sourceRoot":"","sources":["../../src/users/change-password.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAQtE,KAAK,cAAc,GAAG,gBAAgB,GAAG,QAAQ,CAAC;AAElD,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,kBAAkB,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE;QAAE,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;CACvC,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,cAAc,IACvC,0CAI5B;IACD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,qBAAqB,CAAC,CAoCnC"}
@@ -0,0 +1,38 @@
1
+ //
2
+ import { insertActivity } from "#src/journal";
3
+ import { users } from "@proconnect-gouv/proconnect.identite.database/drizzle";
4
+ import { UserNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
5
+ import { eq, sql } from "drizzle-orm";
6
+ export function changePasswordFactory({ actor, app, db }) {
7
+ return function changePassword({ encrypted_password, source, user_id, }) {
8
+ return db.transaction(async (tx) => {
9
+ const [previous] = await tx
10
+ .select({ email_verified: users.email_verified })
11
+ .from(users)
12
+ .where(eq(users.id, user_id))
13
+ .for("update");
14
+ if (!previous) {
15
+ throw new UserNotFoundError(`user ${user_id} not found`);
16
+ }
17
+ await tx
18
+ .update(users)
19
+ .set({
20
+ email_verified: source === "reset_password",
21
+ email_verified_at: source === "reset_password" ? sql `now()` : null,
22
+ encrypted_password,
23
+ reset_password_sent_at: source === "reset_password" ? null : undefined,
24
+ reset_password_token: source === "reset_password" ? null : undefined,
25
+ updated_at: sql `now()`,
26
+ })
27
+ .where(eq(users.id, user_id));
28
+ const { activity_id } = await insertActivity(tx, {
29
+ action: "user.password_changed",
30
+ actor,
31
+ app,
32
+ context: { inputs: { source }, outcome: { previous } },
33
+ user_id,
34
+ });
35
+ return { kind: "password_changed", activity_id, previous };
36
+ });
37
+ };
38
+ }
@@ -1,4 +1,6 @@
1
1
  export * from "./activities.js";
2
+ export * from "./change-password.js";
2
3
  export * from "./delete-user.js";
3
4
  export * from "./reset-mfa.js";
5
+ export * from "./update-personal-informations.js";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/users/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/users/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mCAAmC,CAAC"}
@@ -1,4 +1,6 @@
1
1
  //
2
2
  export * from "./activities.js";
3
+ export * from "./change-password.js";
3
4
  export * from "./delete-user.js";
4
5
  export * from "./reset-mfa.js";
6
+ export * from "./update-personal-informations.js";
@@ -0,0 +1,21 @@
1
+ import type { RuntimeContext } from "#src/activity";
2
+ import type { User } from "@proconnect-gouv/proconnect.identite/types";
3
+ type PersonalInformation = Pick<User, "family_name" | "given_name" | "job" | "phone_number">;
4
+ type UpdatePersonalInformationsOutcome = {
5
+ kind: "info_changed";
6
+ activity_id: number;
7
+ next: PersonalInformation;
8
+ previous: PersonalInformation;
9
+ } | {
10
+ kind: "info_unchanged";
11
+ user_id: number;
12
+ } | {
13
+ kind: "user_not_found";
14
+ user_id: number;
15
+ };
16
+ export declare function updatePersonalInformationsFactory({ actor, app, db, }: RuntimeContext): ({ information, user_id, }: {
17
+ information: Partial<Pick<User, "family_name" | "given_name" | "job" | "phone_number">>;
18
+ user_id: number;
19
+ }) => Promise<UpdatePersonalInformationsOutcome>;
20
+ export {};
21
+ //# sourceMappingURL=update-personal-informations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-personal-informations.d.ts","sourceRoot":"","sources":["../../src/users/update-personal-informations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AAKvE,KAAK,mBAAmB,GAAG,IAAI,CAC7B,IAAI,EACJ,aAAa,GAAG,YAAY,GAAG,KAAK,GAAG,cAAc,CACtD,CAAC;AAEF,KAAK,iCAAiC,GAClC;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,mBAAmB,CAAC;IAC1B,QAAQ,EAAE,mBAAmB,CAAC;CAC/B,GACD;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,wBAAgB,iCAAiC,CAAC,EAChD,KAAK,EACL,GAAG,EACH,EAAE,GACH,EAAE,cAAc,IAC4B,2BAGxC;IACD,WAAW,EAAE,OAAO,CAClB,IAAI,CAAC,IAAI,EAAE,aAAa,GAAG,YAAY,GAAG,KAAK,GAAG,cAAc,CAAC,CAClE,CAAC;IACF,OAAO,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,iCAAiC,CAAC,CA0D/C"}
@@ -0,0 +1,53 @@
1
+ //
2
+ import { insertActivity } from "#src/journal";
3
+ import { users } from "@proconnect-gouv/proconnect.identite.database/drizzle";
4
+ import { eq, sql } from "drizzle-orm";
5
+ export function updatePersonalInformationsFactory({ actor, app, db, }) {
6
+ return function updatePersonalInformations({ information, user_id, }) {
7
+ return db.transaction(async (tx) => {
8
+ const [previous] = await tx
9
+ .select({
10
+ family_name: users.family_name,
11
+ given_name: users.given_name,
12
+ job: users.job,
13
+ phone_number: users.phone_number,
14
+ })
15
+ .from(users)
16
+ .where(eq(users.id, user_id))
17
+ .for("update");
18
+ if (!previous) {
19
+ return { kind: "user_not_found", user_id };
20
+ }
21
+ const next = {
22
+ family_name: information.family_name !== undefined
23
+ ? information.family_name
24
+ : previous.family_name,
25
+ given_name: information.given_name !== undefined
26
+ ? information.given_name
27
+ : previous.given_name,
28
+ job: information.job !== undefined ? information.job : previous.job,
29
+ phone_number: information.phone_number !== undefined
30
+ ? information.phone_number
31
+ : previous.phone_number,
32
+ };
33
+ if (next.family_name === previous.family_name &&
34
+ next.given_name === previous.given_name &&
35
+ next.job === previous.job &&
36
+ next.phone_number === previous.phone_number) {
37
+ return { kind: "info_unchanged", user_id };
38
+ }
39
+ await tx
40
+ .update(users)
41
+ .set({ ...next, updated_at: sql `now()` })
42
+ .where(eq(users.id, user_id));
43
+ const { activity_id } = await insertActivity(tx, {
44
+ action: "user.info_changed",
45
+ actor,
46
+ app,
47
+ context: { inputs: next, outcome: { previous } },
48
+ user_id,
49
+ });
50
+ return { kind: "info_changed", activity_id, next, previous };
51
+ });
52
+ };
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proconnect-gouv/proconnect.identite.runtime",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/runtime#readme",
5
5
  "bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
6
6
  "repository": {
@@ -32,8 +32,8 @@
32
32
  "test": "tsc --noEmit && tsx --test --test-reporter=spec"
33
33
  },
34
34
  "dependencies": {
35
- "@proconnect-gouv/proconnect.identite": "^14.0.0",
36
- "@proconnect-gouv/proconnect.identite.database": "^1.12.0",
35
+ "@proconnect-gouv/proconnect.identite": "^16.0.0",
36
+ "@proconnect-gouv/proconnect.identite.database": "^2.1.0",
37
37
  "zod": "^4.6.7"
38
38
  },
39
39
  "devDependencies": {
@@ -0,0 +1,128 @@
1
+ //
2
+
3
+ import assert from "node:assert/strict";
4
+ import { describe, it } from "node:test";
5
+ import {
6
+ certificationDirigeantActivities,
7
+ getCertificationDirigeantActivity,
8
+ } from "./activities.js";
9
+
10
+ //
11
+
12
+ type Result = Parameters<typeof getCertificationDirigeantActivity>[0];
13
+
14
+ const ulysse = {
15
+ birthcountry: "99100",
16
+ birthdate: new Date("1992-09-07"),
17
+ birthplace: "13055",
18
+ family_name: "Tosi",
19
+ gender: "male",
20
+ given_name: "Ulysse",
21
+ } as const;
22
+
23
+ function result_of({
24
+ cause,
25
+ dirigeant = ulysse,
26
+ source = "registre-national-entreprises.inpi.fr/api",
27
+ }: {
28
+ cause: Result["cause"];
29
+ dirigeant?: Record<string, unknown>;
30
+ source?: string | null;
31
+ }) {
32
+ return {
33
+ cause,
34
+ details: { dirigeant, identity: ulysse, matches: new Set(), source },
35
+ ok: cause === "exact_match",
36
+ } as unknown as Result;
37
+ }
38
+
39
+ describe("getCertificationDirigeantActivity", () => {
40
+ it("records the registry of a certified dirigeant", () => {
41
+ assert.deepEqual(
42
+ getCertificationDirigeantActivity(result_of({ cause: "exact_match" })),
43
+ {
44
+ action: "certification_dirigeant.certified",
45
+ context: {
46
+ inputs: {},
47
+ outcome: { source: "registre-national-entreprises.inpi.fr/api" },
48
+ },
49
+ },
50
+ );
51
+ });
52
+
53
+ it("records only the differing criteria of a close match, as received and as compared", () => {
54
+ assert.deepEqual(
55
+ getCertificationDirigeantActivity(
56
+ result_of({
57
+ cause: "close_match",
58
+ dirigeant: { ...ulysse, given_name: "Ulisse" },
59
+ }),
60
+ ),
61
+ {
62
+ action: "certification_dirigeant.close_matched",
63
+ context: {
64
+ inputs: {},
65
+ outcome: {
66
+ diff: {
67
+ first_name: {
68
+ franceconnect: { compared: "ULYSSE", raw: "Ulysse" },
69
+ source: { compared: "ULISSE", raw: "Ulisse" },
70
+ },
71
+ },
72
+ source: "registre-national-entreprises.inpi.fr/api",
73
+ },
74
+ },
75
+ },
76
+ );
77
+ });
78
+
79
+ it("records why no dirigeant matched", () => {
80
+ assert.deepEqual(
81
+ getCertificationDirigeantActivity(result_of({ cause: "no_candidates" })),
82
+ {
83
+ action: "certification_dirigeant.not_matched",
84
+ context: {
85
+ inputs: {},
86
+ outcome: {
87
+ reason: "no_candidates",
88
+ source: "registre-national-entreprises.inpi.fr/api",
89
+ },
90
+ },
91
+ },
92
+ );
93
+ });
94
+
95
+ it("records an uncovered organization without any registry", () => {
96
+ assert.deepEqual(
97
+ getCertificationDirigeantActivity(
98
+ result_of({ cause: "organisation_not_covered", source: null }),
99
+ ),
100
+ {
101
+ action: "certification_dirigeant.not_covered",
102
+ context: { inputs: {}, outcome: {} },
103
+ },
104
+ );
105
+ });
106
+
107
+ it("builds contexts their published schema accepts", () => {
108
+ for (const cause of [
109
+ "below_threshold",
110
+ "close_match",
111
+ "exact_match",
112
+ "no_candidates",
113
+ "organisation_not_covered",
114
+ ] as const) {
115
+ const { action, context } = getCertificationDirigeantActivity(
116
+ result_of({
117
+ cause,
118
+ dirigeant: { ...ulysse, birthdate: null, family_name: "Tozi" },
119
+ }),
120
+ );
121
+
122
+ assert.deepEqual(
123
+ certificationDirigeantActivities[action].parse(context),
124
+ context,
125
+ );
126
+ }
127
+ });
128
+ });
@@ -0,0 +1,103 @@
1
+ //
2
+
3
+ import type { ActivityOf, ContextsOf } from "#src/activity";
4
+ import {
5
+ CertificationDirigeantDataSource,
6
+ compareCriteria,
7
+ MatchCriteria,
8
+ type processCertificationDirigeantFactory,
9
+ } from "@proconnect-gouv/proconnect.identite/managers/certification";
10
+ import * as z from "zod";
11
+
12
+ //
13
+
14
+ const ComparedValue = z.object({
15
+ compared: z.string().nullable(),
16
+ raw: z.string().nullable(),
17
+ });
18
+
19
+ export const certificationDirigeantActivities = {
20
+ "certification_dirigeant.certified": z.object({
21
+ inputs: z.object({}),
22
+ outcome: z.object({
23
+ source: CertificationDirigeantDataSource,
24
+ }),
25
+ }),
26
+ "certification_dirigeant.close_matched": z.object({
27
+ inputs: z.object({}),
28
+ outcome: z.object({
29
+ diff: z.partialRecord(
30
+ MatchCriteria,
31
+ z.object({ franceconnect: ComparedValue, source: ComparedValue }),
32
+ ),
33
+ source: CertificationDirigeantDataSource,
34
+ }),
35
+ }),
36
+ "certification_dirigeant.not_covered": z.object({
37
+ inputs: z.object({}),
38
+ outcome: z.object({}),
39
+ }),
40
+ "certification_dirigeant.not_matched": z.object({
41
+ inputs: z.object({}),
42
+ outcome: z.object({
43
+ reason: z.enum(["below_threshold", "no_candidates"]),
44
+ source: CertificationDirigeantDataSource,
45
+ }),
46
+ }),
47
+ };
48
+
49
+ //
50
+
51
+ type CertificationDirigeantResult = Awaited<
52
+ ReturnType<ReturnType<typeof processCertificationDirigeantFactory>>
53
+ >;
54
+
55
+ export function getCertificationDirigeantActivity(
56
+ result: CertificationDirigeantResult,
57
+ ): ActivityOf<ContextsOf<typeof certificationDirigeantActivities>> {
58
+ switch (result.cause) {
59
+ case "organisation_not_covered":
60
+ return {
61
+ action: "certification_dirigeant.not_covered",
62
+ context: { inputs: {}, outcome: {} },
63
+ };
64
+ case "exact_match":
65
+ return {
66
+ action: "certification_dirigeant.certified",
67
+ context: { inputs: {}, outcome: { source: result.details.source } },
68
+ };
69
+ case "close_match":
70
+ return {
71
+ action: "certification_dirigeant.close_matched",
72
+ context: {
73
+ inputs: {},
74
+ outcome: {
75
+ diff: Object.fromEntries(
76
+ compareCriteria(result.details.identity, result.details.dirigeant)
77
+ .filter(({ matched }) => !matched)
78
+ .map(({ criterion, franceconnect, source }) => [
79
+ criterion,
80
+ { franceconnect, source },
81
+ ]),
82
+ ),
83
+ source: result.details.source,
84
+ },
85
+ },
86
+ };
87
+ case "below_threshold":
88
+ case "no_candidates":
89
+ return {
90
+ action: "certification_dirigeant.not_matched",
91
+ context: {
92
+ inputs: {},
93
+ outcome: { reason: result.cause, source: result.details.source },
94
+ },
95
+ };
96
+ default:
97
+ return assert_never(result);
98
+ }
99
+ }
100
+
101
+ function assert_never(value: never): never {
102
+ throw new Error(`Unhandled certification result: ${JSON.stringify(value)}`);
103
+ }
@@ -0,0 +1,3 @@
1
+ //
2
+
3
+ export * from "./activities.js";