@proconnect-gouv/proconnect.identite.runtime 0.3.1 → 0.5.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.
- package/CHANGELOG.md +37 -0
- package/dist/activity/activity-context-schemas.d.ts +104 -0
- package/dist/activity/activity-context-schemas.d.ts.map +1 -1
- package/dist/activity/activity-context-schemas.js +6 -0
- package/dist/activity/types.d.ts +3 -0
- package/dist/activity/types.d.ts.map +1 -1
- package/dist/franceconnect/activities.d.ts +16 -0
- package/dist/franceconnect/activities.d.ts.map +1 -0
- package/dist/franceconnect/activities.js +17 -0
- package/dist/franceconnect/connect-franceconnect.d.ts +20 -0
- package/dist/franceconnect/connect-franceconnect.d.ts.map +1 -0
- package/dist/franceconnect/connect-franceconnect.js +59 -0
- package/dist/franceconnect/disconnect-franceconnect.d.ts +14 -0
- package/dist/franceconnect/disconnect-franceconnect.d.ts.map +1 -0
- package/dist/franceconnect/disconnect-franceconnect.js +29 -0
- package/dist/franceconnect/index.d.ts +4 -0
- package/dist/franceconnect/index.d.ts.map +1 -0
- package/dist/franceconnect/index.js +4 -0
- package/dist/journal/insert-activity.js +6 -0
- package/dist/memberships/activities.d.ts +27 -0
- package/dist/memberships/activities.d.ts.map +1 -1
- package/dist/memberships/activities.js +27 -0
- package/dist/memberships/add-membership.d.ts +22 -0
- package/dist/memberships/add-membership.d.ts.map +1 -0
- package/dist/memberships/add-membership.js +46 -0
- package/dist/memberships/index.d.ts +3 -0
- package/dist/memberships/index.d.ts.map +1 -1
- package/dist/memberships/index.js +3 -0
- package/dist/memberships/remove-membership.d.ts +19 -0
- package/dist/memberships/remove-membership.d.ts.map +1 -0
- package/dist/memberships/remove-membership.js +29 -0
- package/dist/memberships/update-membership.d.ts +31 -0
- package/dist/memberships/update-membership.d.ts.map +1 -0
- package/dist/memberships/update-membership.js +61 -0
- package/dist/moderations/activities.d.ts +11 -0
- package/dist/moderations/activities.d.ts.map +1 -0
- package/dist/moderations/activities.js +12 -0
- package/dist/moderations/index.d.ts +3 -0
- package/dist/moderations/index.d.ts.map +1 -0
- package/dist/moderations/index.js +3 -0
- package/dist/moderations/open-moderation.d.ts +18 -0
- package/dist/moderations/open-moderation.d.ts.map +1 -0
- package/dist/moderations/open-moderation.js +31 -0
- package/dist/runtime/create-identite-runtime.d.ts +152 -0
- package/dist/runtime/create-identite-runtime.d.ts.map +1 -1
- package/dist/runtime/create-identite-runtime.js +22 -0
- package/dist/users/activities.d.ts +62 -0
- package/dist/users/activities.d.ts.map +1 -0
- package/dist/users/activities.js +54 -0
- package/dist/users/change-password.d.ts +16 -0
- package/dist/users/change-password.d.ts.map +1 -0
- package/dist/users/change-password.js +38 -0
- package/dist/users/delete-user.d.ts +14 -0
- package/dist/users/delete-user.d.ts.map +1 -0
- package/dist/users/delete-user.js +39 -0
- package/dist/users/index.d.ts +6 -0
- package/dist/users/index.d.ts.map +1 -0
- package/dist/users/index.js +6 -0
- package/dist/users/reset-mfa.d.ts +14 -0
- package/dist/users/reset-mfa.d.ts.map +1 -0
- package/dist/users/reset-mfa.js +53 -0
- package/dist/users/update-personal-informations.d.ts +21 -0
- package/dist/users/update-personal-informations.d.ts.map +1 -0
- package/dist/users/update-personal-informations.js +53 -0
- package/package.json +5 -4
- package/src/activity/activity-context-schemas.ts +6 -0
- package/src/activity/types.ts +2 -1
- package/src/domains/mark-domain-as-verified.test.ts +162 -243
- package/src/franceconnect/activities.ts +20 -0
- package/src/franceconnect/connect-franceconnect.test.ts +197 -0
- package/src/franceconnect/connect-franceconnect.ts +96 -0
- package/src/franceconnect/disconnect-franceconnect.test.ts +94 -0
- package/src/franceconnect/disconnect-franceconnect.ts +53 -0
- package/src/franceconnect/index.ts +5 -0
- package/src/journal/insert-activity.ts +6 -0
- package/src/memberships/activities.ts +27 -0
- package/src/memberships/add-membership.test.ts +129 -0
- package/src/memberships/add-membership.ts +80 -0
- package/src/memberships/index.ts +3 -0
- package/src/memberships/remove-membership.test.ts +122 -0
- package/src/memberships/remove-membership.ts +59 -0
- package/src/memberships/update-membership.test.ts +202 -0
- package/src/memberships/update-membership.ts +106 -0
- package/src/moderations/activities.ts +15 -0
- package/src/moderations/index.ts +4 -0
- package/src/moderations/open-moderation.test.ts +99 -0
- package/src/moderations/open-moderation.ts +59 -0
- package/src/runtime/create-identite-runtime.test.ts +20 -51
- package/src/runtime/create-identite-runtime.ts +34 -0
- package/src/users/activities.ts +60 -0
- package/src/users/change-password.test.ts +91 -0
- package/src/users/change-password.ts +64 -0
- package/src/users/delete-user.test.ts +142 -0
- package/src/users/delete-user.ts +60 -0
- package/src/users/index.ts +7 -0
- package/src/users/reset-mfa.test.ts +128 -0
- package/src/users/reset-mfa.ts +79 -0
- package/src/users/update-personal-informations.test.ts +113 -0
- package/src/users/update-personal-informations.ts +97 -0
- package/testing/index.ts +25 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { IdentiteDatabase } from "#src/database";
|
|
4
|
+
import { createIdentiteRuntime } from "#src/runtime";
|
|
5
|
+
import { createTestDatabase, readActivityLogs } from "#testing";
|
|
6
|
+
import * as schema from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { describe, it } from "node:test";
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
async function setup() {
|
|
13
|
+
const db = await createTestDatabase();
|
|
14
|
+
|
|
15
|
+
await db.insert(schema.users).values([
|
|
16
|
+
{
|
|
17
|
+
created_at: "4444-04-04",
|
|
18
|
+
email: "jean.valjean@republic.fr",
|
|
19
|
+
email_verified: true,
|
|
20
|
+
encrypted_password: "🔑",
|
|
21
|
+
encrypted_totp_key: "🔐",
|
|
22
|
+
force_2fa: true,
|
|
23
|
+
id: 1,
|
|
24
|
+
totp_key_verified_at: "4444-04-04",
|
|
25
|
+
updated_at: "4444-04-04",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
created_at: "4444-04-04",
|
|
29
|
+
email: "cosette@republic.fr",
|
|
30
|
+
id: 2,
|
|
31
|
+
updated_at: "4444-04-04",
|
|
32
|
+
},
|
|
33
|
+
]);
|
|
34
|
+
await db.insert(schema.authenticators).values([
|
|
35
|
+
{
|
|
36
|
+
counter: 0,
|
|
37
|
+
credential_backed_up: true,
|
|
38
|
+
credential_id: "jean-passkey",
|
|
39
|
+
credential_public_key: new Uint8Array(),
|
|
40
|
+
user_id: 1,
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
db,
|
|
46
|
+
runtime: createIdentiteRuntime({ app: "hyyypertool", db }).as({
|
|
47
|
+
sub: "moderator-1",
|
|
48
|
+
type: "moderator",
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("resetMfa", () => {
|
|
54
|
+
it("✅ clears the credentials and the MFA factors and journals them under the moderator", async () => {
|
|
55
|
+
const { db, runtime } = await setup();
|
|
56
|
+
|
|
57
|
+
const outcome = await runtime.resetMfa({ user_id: 1 });
|
|
58
|
+
|
|
59
|
+
const previous = {
|
|
60
|
+
authenticators: 1,
|
|
61
|
+
email_verified: true,
|
|
62
|
+
force_2fa: true,
|
|
63
|
+
password_configured: true,
|
|
64
|
+
totp_configured: true,
|
|
65
|
+
};
|
|
66
|
+
assert.deepEqual(outcome, { kind: "mfa_reset", activity_id: 1, previous });
|
|
67
|
+
assert.deepEqual(await mfaState(db), [
|
|
68
|
+
{
|
|
69
|
+
authenticators: [],
|
|
70
|
+
email_verified: false,
|
|
71
|
+
encrypted_password: null,
|
|
72
|
+
encrypted_totp_key: null,
|
|
73
|
+
force_2fa: false,
|
|
74
|
+
id: 2,
|
|
75
|
+
totp_key_verified_at: null,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
authenticators: [],
|
|
79
|
+
email_verified: false,
|
|
80
|
+
encrypted_password: null,
|
|
81
|
+
encrypted_totp_key: null,
|
|
82
|
+
force_2fa: false,
|
|
83
|
+
id: 1,
|
|
84
|
+
totp_key_verified_at: null,
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
assert.deepEqual(await readActivityLogs(db), [
|
|
88
|
+
{
|
|
89
|
+
action: "user.mfa_reset",
|
|
90
|
+
actor_ref: "moderator-1",
|
|
91
|
+
actor_type: "moderator",
|
|
92
|
+
app: "hyyypertool",
|
|
93
|
+
cause_activity_id: null,
|
|
94
|
+
context: { inputs: { user_id: 1 }, outcome: { previous } },
|
|
95
|
+
interaction_cid: null,
|
|
96
|
+
moderation_id: null,
|
|
97
|
+
organization_id: null,
|
|
98
|
+
user_id: 1,
|
|
99
|
+
},
|
|
100
|
+
]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("❎ returns user_not_found and journals nothing for a missing account", async () => {
|
|
104
|
+
const { db, runtime } = await setup();
|
|
105
|
+
const before = await mfaState(db);
|
|
106
|
+
|
|
107
|
+
const outcome = await runtime.resetMfa({ user_id: 999 });
|
|
108
|
+
|
|
109
|
+
assert.deepEqual(outcome, { kind: "user_not_found", user_id: 999 });
|
|
110
|
+
assert.deepEqual(await mfaState(db), before);
|
|
111
|
+
assert.deepEqual(await readActivityLogs(db), []);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
function mfaState(db: IdentiteDatabase) {
|
|
116
|
+
return db.query.users.findMany({
|
|
117
|
+
columns: {
|
|
118
|
+
email_verified: true,
|
|
119
|
+
encrypted_password: true,
|
|
120
|
+
encrypted_totp_key: true,
|
|
121
|
+
force_2fa: true,
|
|
122
|
+
id: true,
|
|
123
|
+
totp_key_verified_at: true,
|
|
124
|
+
},
|
|
125
|
+
orderBy: (table, { desc }) => desc(table.id),
|
|
126
|
+
with: { authenticators: { columns: { credential_id: true } } },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { ActivityContexts, RuntimeContext } from "#src/activity";
|
|
4
|
+
import { insertActivity } from "#src/journal";
|
|
5
|
+
import {
|
|
6
|
+
authenticators,
|
|
7
|
+
users,
|
|
8
|
+
} from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
9
|
+
import { eq, sql } from "drizzle-orm";
|
|
10
|
+
|
|
11
|
+
//
|
|
12
|
+
|
|
13
|
+
type ResetMfaOutcome =
|
|
14
|
+
| {
|
|
15
|
+
kind: "mfa_reset";
|
|
16
|
+
activity_id: number;
|
|
17
|
+
previous: ActivityContexts["user.mfa_reset"]["outcome"]["previous"];
|
|
18
|
+
}
|
|
19
|
+
| { kind: "user_not_found"; user_id: number };
|
|
20
|
+
|
|
21
|
+
export function resetMfaFactory({ actor, app, db }: RuntimeContext) {
|
|
22
|
+
return function resetMfa({
|
|
23
|
+
user_id,
|
|
24
|
+
}: {
|
|
25
|
+
user_id: number;
|
|
26
|
+
}): Promise<ResetMfaOutcome> {
|
|
27
|
+
return db.transaction(async (tx) => {
|
|
28
|
+
const [previousUser] = await tx
|
|
29
|
+
.select({
|
|
30
|
+
email_verified: users.email_verified,
|
|
31
|
+
force_2fa: users.force_2fa,
|
|
32
|
+
password_configured: sql<boolean>`${users.encrypted_password} is not null`,
|
|
33
|
+
totp_configured: sql<boolean>`${users.encrypted_totp_key} is not null`,
|
|
34
|
+
})
|
|
35
|
+
.from(users)
|
|
36
|
+
.where(eq(users.id, user_id))
|
|
37
|
+
.for("update");
|
|
38
|
+
|
|
39
|
+
if (!previousUser) {
|
|
40
|
+
return { kind: "user_not_found", user_id };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const removedAuthenticators = await tx
|
|
44
|
+
.delete(authenticators)
|
|
45
|
+
.where(eq(authenticators.user_id, user_id))
|
|
46
|
+
.returning({ credential_id: authenticators.credential_id });
|
|
47
|
+
|
|
48
|
+
await tx
|
|
49
|
+
.update(users)
|
|
50
|
+
.set({
|
|
51
|
+
email_verified: false,
|
|
52
|
+
encrypted_password: null,
|
|
53
|
+
encrypted_totp_key: null,
|
|
54
|
+
force_2fa: false,
|
|
55
|
+
totp_key_verified_at: null,
|
|
56
|
+
updated_at: sql`now()`,
|
|
57
|
+
})
|
|
58
|
+
.where(eq(users.id, user_id));
|
|
59
|
+
|
|
60
|
+
const previous = {
|
|
61
|
+
authenticators: removedAuthenticators.length,
|
|
62
|
+
email_verified: previousUser.email_verified,
|
|
63
|
+
force_2fa: previousUser.force_2fa,
|
|
64
|
+
password_configured: previousUser.password_configured,
|
|
65
|
+
totp_configured: previousUser.totp_configured,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const { activity_id } = await insertActivity<ActivityContexts>(tx, {
|
|
69
|
+
action: "user.mfa_reset",
|
|
70
|
+
actor,
|
|
71
|
+
app,
|
|
72
|
+
context: { inputs: { user_id }, outcome: { previous } },
|
|
73
|
+
user_id,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return { kind: "mfa_reset", activity_id, previous };
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { createIdentiteRuntime } from "#src/runtime";
|
|
4
|
+
import { createTestDatabase, readActivityLogs } from "#testing";
|
|
5
|
+
import * as schema from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { describe, it } from "node:test";
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
async function setup() {
|
|
12
|
+
const db = await createTestDatabase();
|
|
13
|
+
await db.insert(schema.users).values({
|
|
14
|
+
created_at: "4444-04-04",
|
|
15
|
+
email: "jean.valjean@republic.fr",
|
|
16
|
+
id: 1,
|
|
17
|
+
updated_at: "4444-04-04",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
db,
|
|
22
|
+
runtime: createIdentiteRuntime({ app: "proconnect-identite", db }).as({
|
|
23
|
+
type: "user",
|
|
24
|
+
user_id: 1,
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("updatePersonalInformations", () => {
|
|
30
|
+
it("✅ changes the profile and journals the previous values", async () => {
|
|
31
|
+
const { db, runtime } = await setup();
|
|
32
|
+
|
|
33
|
+
const outcome = await runtime.updatePersonalInformations({
|
|
34
|
+
information: {
|
|
35
|
+
family_name: "Valjean",
|
|
36
|
+
given_name: "Jean",
|
|
37
|
+
job: "Maire",
|
|
38
|
+
phone_number: null,
|
|
39
|
+
},
|
|
40
|
+
user_id: 1,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
assert.deepEqual(outcome, {
|
|
44
|
+
kind: "info_changed",
|
|
45
|
+
activity_id: 1,
|
|
46
|
+
next: {
|
|
47
|
+
family_name: "Valjean",
|
|
48
|
+
given_name: "Jean",
|
|
49
|
+
job: "Maire",
|
|
50
|
+
phone_number: null,
|
|
51
|
+
},
|
|
52
|
+
previous: {
|
|
53
|
+
family_name: null,
|
|
54
|
+
given_name: null,
|
|
55
|
+
job: null,
|
|
56
|
+
phone_number: null,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
assert.deepEqual(await readActivityLogs(db), [
|
|
60
|
+
{
|
|
61
|
+
action: "user.info_changed",
|
|
62
|
+
actor_ref: "1",
|
|
63
|
+
actor_type: "user",
|
|
64
|
+
app: "proconnect-identite",
|
|
65
|
+
cause_activity_id: null,
|
|
66
|
+
context: {
|
|
67
|
+
inputs: {
|
|
68
|
+
family_name: "Valjean",
|
|
69
|
+
given_name: "Jean",
|
|
70
|
+
job: "Maire",
|
|
71
|
+
phone_number: null,
|
|
72
|
+
},
|
|
73
|
+
outcome: {
|
|
74
|
+
previous: {
|
|
75
|
+
family_name: null,
|
|
76
|
+
given_name: null,
|
|
77
|
+
job: null,
|
|
78
|
+
phone_number: null,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
interaction_cid: null,
|
|
83
|
+
moderation_id: null,
|
|
84
|
+
organization_id: null,
|
|
85
|
+
user_id: 1,
|
|
86
|
+
},
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("❎ writes nothing when the profile does not change", async () => {
|
|
91
|
+
const { db, runtime } = await setup();
|
|
92
|
+
|
|
93
|
+
const outcome = await runtime.updatePersonalInformations({
|
|
94
|
+
information: { given_name: null },
|
|
95
|
+
user_id: 1,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
assert.deepEqual(outcome, { kind: "info_unchanged", user_id: 1 });
|
|
99
|
+
assert.deepEqual(await readActivityLogs(db), []);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("❎ returns user_not_found and journals nothing", async () => {
|
|
103
|
+
const { db, runtime } = await setup();
|
|
104
|
+
|
|
105
|
+
const outcome = await runtime.updatePersonalInformations({
|
|
106
|
+
information: { given_name: "Jean" },
|
|
107
|
+
user_id: 42,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
assert.deepEqual(outcome, { kind: "user_not_found", user_id: 42 });
|
|
111
|
+
assert.deepEqual(await readActivityLogs(db), []);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { ActivityContexts, RuntimeContext } from "#src/activity";
|
|
4
|
+
import { insertActivity } from "#src/journal";
|
|
5
|
+
import { users } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
6
|
+
import type { User } from "@proconnect-gouv/proconnect.identite/types";
|
|
7
|
+
import { eq, sql } from "drizzle-orm";
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
type PersonalInformation = Pick<
|
|
12
|
+
User,
|
|
13
|
+
"family_name" | "given_name" | "job" | "phone_number"
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
type UpdatePersonalInformationsOutcome =
|
|
17
|
+
| {
|
|
18
|
+
kind: "info_changed";
|
|
19
|
+
activity_id: number;
|
|
20
|
+
next: PersonalInformation;
|
|
21
|
+
previous: PersonalInformation;
|
|
22
|
+
}
|
|
23
|
+
| { kind: "info_unchanged"; user_id: number }
|
|
24
|
+
| { kind: "user_not_found"; user_id: number };
|
|
25
|
+
|
|
26
|
+
export function updatePersonalInformationsFactory({
|
|
27
|
+
actor,
|
|
28
|
+
app,
|
|
29
|
+
db,
|
|
30
|
+
}: RuntimeContext) {
|
|
31
|
+
return function updatePersonalInformations({
|
|
32
|
+
information,
|
|
33
|
+
user_id,
|
|
34
|
+
}: {
|
|
35
|
+
information: Partial<
|
|
36
|
+
Pick<User, "family_name" | "given_name" | "job" | "phone_number">
|
|
37
|
+
>;
|
|
38
|
+
user_id: number;
|
|
39
|
+
}): Promise<UpdatePersonalInformationsOutcome> {
|
|
40
|
+
return db.transaction(async (tx) => {
|
|
41
|
+
const [previous] = await tx
|
|
42
|
+
.select({
|
|
43
|
+
family_name: users.family_name,
|
|
44
|
+
given_name: users.given_name,
|
|
45
|
+
job: users.job,
|
|
46
|
+
phone_number: users.phone_number,
|
|
47
|
+
})
|
|
48
|
+
.from(users)
|
|
49
|
+
.where(eq(users.id, user_id))
|
|
50
|
+
.for("update");
|
|
51
|
+
|
|
52
|
+
if (!previous) {
|
|
53
|
+
return { kind: "user_not_found", user_id };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const next = {
|
|
57
|
+
family_name:
|
|
58
|
+
information.family_name !== undefined
|
|
59
|
+
? information.family_name
|
|
60
|
+
: previous.family_name,
|
|
61
|
+
given_name:
|
|
62
|
+
information.given_name !== undefined
|
|
63
|
+
? information.given_name
|
|
64
|
+
: previous.given_name,
|
|
65
|
+
job: information.job !== undefined ? information.job : previous.job,
|
|
66
|
+
phone_number:
|
|
67
|
+
information.phone_number !== undefined
|
|
68
|
+
? information.phone_number
|
|
69
|
+
: previous.phone_number,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (
|
|
73
|
+
next.family_name === previous.family_name &&
|
|
74
|
+
next.given_name === previous.given_name &&
|
|
75
|
+
next.job === previous.job &&
|
|
76
|
+
next.phone_number === previous.phone_number
|
|
77
|
+
) {
|
|
78
|
+
return { kind: "info_unchanged", user_id };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
await tx
|
|
82
|
+
.update(users)
|
|
83
|
+
.set({ ...next, updated_at: sql`now()` })
|
|
84
|
+
.where(eq(users.id, user_id));
|
|
85
|
+
|
|
86
|
+
const { activity_id } = await insertActivity<ActivityContexts>(tx, {
|
|
87
|
+
action: "user.info_changed",
|
|
88
|
+
actor,
|
|
89
|
+
app,
|
|
90
|
+
context: { inputs: next, outcome: { previous } },
|
|
91
|
+
user_id,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return { kind: "info_changed", activity_id, next, previous };
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
}
|
package/testing/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { IdentiteDatabase } from "#src/database";
|
|
4
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
5
|
+
import * as schema from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
6
|
+
import { migrate } from "@proconnect-gouv/proconnect.identite.database/pglite/migrator";
|
|
7
|
+
import { sql } from "drizzle-orm";
|
|
8
|
+
import { drizzle } from "drizzle-orm/pglite";
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
export async function createTestDatabase() {
|
|
13
|
+
const pg = new PGlite();
|
|
14
|
+
await migrate(pg);
|
|
15
|
+
const db = drizzle(pg, { schema });
|
|
16
|
+
await db.execute(sql`SET search_path TO public`);
|
|
17
|
+
return db;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function readActivityLogs(db: IdentiteDatabase) {
|
|
21
|
+
return db.query.activity_logs.findMany({
|
|
22
|
+
columns: { created_at: false, id: false },
|
|
23
|
+
orderBy: (table, { asc }) => asc(table.id),
|
|
24
|
+
});
|
|
25
|
+
}
|
package/tsconfig.json
CHANGED