@proconnect-gouv/proconnect.identite.runtime 0.5.0 → 0.6.1
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 +23 -0
- package/dist/activity/activity-context-schemas.d.ts +22 -0
- package/dist/activity/activity-context-schemas.d.ts.map +1 -1
- package/dist/certification/activities.d.ts +64 -0
- package/dist/certification/activities.d.ts.map +1 -0
- package/dist/certification/activities.js +78 -0
- package/dist/certification/index.d.ts +2 -0
- package/dist/certification/index.d.ts.map +1 -0
- package/dist/certification/index.js +2 -0
- package/dist/domains/activities.d.ts +22 -0
- package/dist/domains/activities.d.ts.map +1 -1
- package/dist/domains/activities.js +20 -1
- package/dist/domains/change-email-domain-verification.d.ts +29 -0
- package/dist/domains/change-email-domain-verification.d.ts.map +1 -0
- package/dist/domains/change-email-domain-verification.js +167 -0
- package/dist/domains/index.d.ts +1 -1
- package/dist/domains/index.d.ts.map +1 -1
- package/dist/domains/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/runtime/create-identite-runtime.d.ts +24 -20
- package/dist/runtime/create-identite-runtime.d.ts.map +1 -1
- package/dist/runtime/create-identite-runtime.js +6 -2
- package/package.json +3 -3
- package/src/certification/activities.test.ts +128 -0
- package/src/certification/activities.ts +103 -0
- package/src/certification/index.ts +3 -0
- package/src/domains/activities.ts +23 -1
- package/src/domains/{mark-domain-as-verified.test.ts → change-email-domain-verification.test.ts} +100 -10
- package/src/domains/change-email-domain-verification.ts +305 -0
- package/src/domains/index.ts +1 -1
- package/src/franceconnect/connect-franceconnect.test.ts +4 -4
- package/src/franceconnect/disconnect-franceconnect.test.ts +4 -4
- package/src/index.ts +1 -0
- package/src/memberships/add-membership.test.ts +4 -4
- package/src/memberships/remove-membership.test.ts +4 -4
- package/src/memberships/update-membership.test.ts +6 -6
- package/src/moderations/open-moderation.test.ts +2 -2
- package/src/runtime/create-identite-runtime.test.ts +12 -59
- package/src/runtime/create-identite-runtime.ts +6 -2
- package/src/users/change-password.test.ts +2 -2
- package/src/users/delete-user.test.ts +4 -4
- package/src/users/reset-mfa.test.ts +5 -5
- package/src/users/update-personal-informations.test.ts +2 -2
- package/dist/domains/mark-domain-as-verified.d.ts +0 -25
- package/dist/domains/mark-domain-as-verified.d.ts.map +0 -1
- package/dist/domains/mark-domain-as-verified.js +0 -103
- package/src/domains/mark-domain-as-verified.ts +0 -174
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { ActivityContexts, RuntimeContext } from "#src/activity";
|
|
4
|
+
import type { IdentiteTransaction } from "#src/database";
|
|
5
|
+
import { insertActivity } from "#src/journal";
|
|
6
|
+
import {
|
|
7
|
+
email_domains,
|
|
8
|
+
users_organizations,
|
|
9
|
+
} from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
10
|
+
import { getMembershipChangesByDomainVerification } from "@proconnect-gouv/proconnect.identite/services/organization";
|
|
11
|
+
import {
|
|
12
|
+
EmailDomainApprovedVerificationValues,
|
|
13
|
+
EmailDomainPendingVerificationValues,
|
|
14
|
+
EmailDomainRejectedVerificationValues,
|
|
15
|
+
LinkEnum,
|
|
16
|
+
type EmailDomainNoPendingVerificationType,
|
|
17
|
+
} from "@proconnect-gouv/proconnect.identite/types";
|
|
18
|
+
import { and, eq, inArray, sql, type SQL } from "drizzle-orm";
|
|
19
|
+
|
|
20
|
+
//
|
|
21
|
+
|
|
22
|
+
type ChangeEmailDomainVerificationOutcome =
|
|
23
|
+
| {
|
|
24
|
+
kind: "domain_verification_changed";
|
|
25
|
+
activity_id: number;
|
|
26
|
+
email_domain: {
|
|
27
|
+
id: number;
|
|
28
|
+
verification_type: EmailDomainNoPendingVerificationType;
|
|
29
|
+
};
|
|
30
|
+
promoted_members: ReadonlyArray<{
|
|
31
|
+
previous_verification_type: string;
|
|
32
|
+
user_id: number;
|
|
33
|
+
}>;
|
|
34
|
+
removed_members: ReadonlyArray<{
|
|
35
|
+
previous_verification_type: string;
|
|
36
|
+
user_id: number;
|
|
37
|
+
}>;
|
|
38
|
+
replaced_verification_types: ReadonlyArray<string>;
|
|
39
|
+
}
|
|
40
|
+
| { kind: "organization_not_found"; organization_id: number };
|
|
41
|
+
|
|
42
|
+
type Member = Awaited<ReturnType<typeof findMembers>>[number];
|
|
43
|
+
|
|
44
|
+
export function changeEmailDomainVerificationFactory({
|
|
45
|
+
actor,
|
|
46
|
+
app,
|
|
47
|
+
db,
|
|
48
|
+
}: RuntimeContext) {
|
|
49
|
+
return function changeEmailDomainVerification({
|
|
50
|
+
domain,
|
|
51
|
+
organization_id,
|
|
52
|
+
verification_type,
|
|
53
|
+
}: {
|
|
54
|
+
domain: string;
|
|
55
|
+
organization_id: number;
|
|
56
|
+
verification_type: EmailDomainNoPendingVerificationType;
|
|
57
|
+
}): Promise<ChangeEmailDomainVerificationOutcome> {
|
|
58
|
+
return db.transaction(async (tx) => {
|
|
59
|
+
const organization = await tx.query.organizations.findFirst({
|
|
60
|
+
columns: { id: true },
|
|
61
|
+
where: (table, { eq }) => eq(table.id, organization_id),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!organization) {
|
|
65
|
+
return { kind: "organization_not_found", organization_id };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const changes = getMembershipChangesByDomainVerification({
|
|
69
|
+
domain,
|
|
70
|
+
members: await findMembers(tx, { organization_id }),
|
|
71
|
+
verification_type,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
switch (changes.kind) {
|
|
75
|
+
case "domain_approved": {
|
|
76
|
+
const { email_domain_id, replaced_verification_types } =
|
|
77
|
+
await replaceEmailDomain(tx, {
|
|
78
|
+
domain,
|
|
79
|
+
organization_id,
|
|
80
|
+
verification_type: changes.verification_type,
|
|
81
|
+
verified_at: sql`now()`,
|
|
82
|
+
});
|
|
83
|
+
const { activity_id } = await insertActivity<ActivityContexts>(tx, {
|
|
84
|
+
action: "domain.verified",
|
|
85
|
+
actor,
|
|
86
|
+
app,
|
|
87
|
+
context: {
|
|
88
|
+
inputs: { domain, verification_type: changes.verification_type },
|
|
89
|
+
outcome: { email_domain_id, replaced_verification_types },
|
|
90
|
+
},
|
|
91
|
+
organization_id,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
await promoteMembers(tx, {
|
|
95
|
+
app,
|
|
96
|
+
cause_activity_id: activity_id,
|
|
97
|
+
members: changes.promoted_members,
|
|
98
|
+
organization_id,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
kind: "domain_verification_changed",
|
|
103
|
+
activity_id,
|
|
104
|
+
email_domain: { id: email_domain_id, verification_type },
|
|
105
|
+
promoted_members:
|
|
106
|
+
changes.promoted_members.map(toPreviousMembership),
|
|
107
|
+
removed_members: [],
|
|
108
|
+
replaced_verification_types,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
case "domain_refused": {
|
|
112
|
+
const { email_domain_id, replaced_verification_types } =
|
|
113
|
+
await replaceEmailDomain(tx, {
|
|
114
|
+
domain,
|
|
115
|
+
organization_id,
|
|
116
|
+
verification_type: changes.verification_type,
|
|
117
|
+
verified_at: null,
|
|
118
|
+
});
|
|
119
|
+
const { activity_id } = await insertActivity<ActivityContexts>(tx, {
|
|
120
|
+
action: "domain.refused",
|
|
121
|
+
actor,
|
|
122
|
+
app,
|
|
123
|
+
context: {
|
|
124
|
+
inputs: { domain, verification_type: changes.verification_type },
|
|
125
|
+
outcome: { email_domain_id, replaced_verification_types },
|
|
126
|
+
},
|
|
127
|
+
organization_id,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
await removeMembers(tx, {
|
|
131
|
+
app,
|
|
132
|
+
cause_activity_id: activity_id,
|
|
133
|
+
members: changes.removed_members,
|
|
134
|
+
organization_id,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
kind: "domain_verification_changed",
|
|
139
|
+
activity_id,
|
|
140
|
+
email_domain: { id: email_domain_id, verification_type },
|
|
141
|
+
promoted_members: [],
|
|
142
|
+
removed_members: changes.removed_members.map(toPreviousMembership),
|
|
143
|
+
replaced_verification_types,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
default: {
|
|
147
|
+
const unhandled_changes: never = changes;
|
|
148
|
+
throw new Error(
|
|
149
|
+
`Unhandled membership changes: ${JSON.stringify(unhandled_changes)}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
//
|
|
158
|
+
|
|
159
|
+
async function findMembers(
|
|
160
|
+
tx: IdentiteTransaction,
|
|
161
|
+
{ organization_id }: { organization_id: number },
|
|
162
|
+
) {
|
|
163
|
+
const memberships = await tx.query.users_organizations.findMany({
|
|
164
|
+
columns: { is_external: true, user_id: true, verification_type: true },
|
|
165
|
+
where: (table, { eq }) => eq(table.organization_id, organization_id),
|
|
166
|
+
with: { user: { columns: { email: true } } },
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return memberships.map(
|
|
170
|
+
({ is_external, user: { email }, user_id, verification_type }) => ({
|
|
171
|
+
email,
|
|
172
|
+
is_external,
|
|
173
|
+
user_id,
|
|
174
|
+
verification_type,
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function replaceEmailDomain(
|
|
180
|
+
tx: IdentiteTransaction,
|
|
181
|
+
{
|
|
182
|
+
domain,
|
|
183
|
+
organization_id,
|
|
184
|
+
verification_type,
|
|
185
|
+
verified_at,
|
|
186
|
+
}: {
|
|
187
|
+
domain: string;
|
|
188
|
+
organization_id: number;
|
|
189
|
+
verification_type: EmailDomainNoPendingVerificationType;
|
|
190
|
+
verified_at: SQL | null;
|
|
191
|
+
},
|
|
192
|
+
) {
|
|
193
|
+
const replaced = await tx
|
|
194
|
+
.delete(email_domains)
|
|
195
|
+
.where(
|
|
196
|
+
and(
|
|
197
|
+
eq(email_domains.organization_id, organization_id),
|
|
198
|
+
eq(email_domains.domain, domain),
|
|
199
|
+
inArray(email_domains.verification_type, [
|
|
200
|
+
...EmailDomainApprovedVerificationValues,
|
|
201
|
+
...EmailDomainPendingVerificationValues,
|
|
202
|
+
...EmailDomainRejectedVerificationValues,
|
|
203
|
+
]),
|
|
204
|
+
),
|
|
205
|
+
)
|
|
206
|
+
.returning({ verification_type: email_domains.verification_type });
|
|
207
|
+
|
|
208
|
+
const [email_domain] = await tx
|
|
209
|
+
.insert(email_domains)
|
|
210
|
+
.values({ domain, organization_id, verification_type, verified_at })
|
|
211
|
+
.returning({ id: email_domains.id });
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
email_domain_id: email_domain.id,
|
|
215
|
+
replaced_verification_types: replaced.map(
|
|
216
|
+
({ verification_type }) => verification_type,
|
|
217
|
+
),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function promoteMembers(
|
|
222
|
+
tx: IdentiteTransaction,
|
|
223
|
+
{
|
|
224
|
+
app,
|
|
225
|
+
cause_activity_id,
|
|
226
|
+
members,
|
|
227
|
+
organization_id,
|
|
228
|
+
}: Pick<RuntimeContext, "app"> & {
|
|
229
|
+
cause_activity_id: number;
|
|
230
|
+
members: ReadonlyArray<Member>;
|
|
231
|
+
organization_id: number;
|
|
232
|
+
},
|
|
233
|
+
) {
|
|
234
|
+
if (members.length === 0) return;
|
|
235
|
+
|
|
236
|
+
await tx
|
|
237
|
+
.update(users_organizations)
|
|
238
|
+
.set({ updated_at: sql`now()`, verification_type: LinkEnum.enum.domain })
|
|
239
|
+
.where(
|
|
240
|
+
and(
|
|
241
|
+
eq(users_organizations.organization_id, organization_id),
|
|
242
|
+
inArray(
|
|
243
|
+
users_organizations.user_id,
|
|
244
|
+
members.map(({ user_id }) => user_id),
|
|
245
|
+
),
|
|
246
|
+
),
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
for (const { user_id, verification_type } of members) {
|
|
250
|
+
await insertActivity<ActivityContexts>(tx, {
|
|
251
|
+
action: "member.promoted",
|
|
252
|
+
actor: { type: "app", job: "domain.promote_members" },
|
|
253
|
+
app,
|
|
254
|
+
cause_activity_id,
|
|
255
|
+
context: {
|
|
256
|
+
inputs: { previous_verification_type: verification_type },
|
|
257
|
+
outcome: { verification_type: LinkEnum.enum.domain },
|
|
258
|
+
},
|
|
259
|
+
organization_id,
|
|
260
|
+
user_id,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function removeMembers(
|
|
266
|
+
tx: IdentiteTransaction,
|
|
267
|
+
{
|
|
268
|
+
app,
|
|
269
|
+
cause_activity_id,
|
|
270
|
+
members,
|
|
271
|
+
organization_id,
|
|
272
|
+
}: Pick<RuntimeContext, "app"> & {
|
|
273
|
+
cause_activity_id: number;
|
|
274
|
+
members: ReadonlyArray<Member>;
|
|
275
|
+
organization_id: number;
|
|
276
|
+
},
|
|
277
|
+
) {
|
|
278
|
+
if (members.length === 0) return;
|
|
279
|
+
|
|
280
|
+
await tx.delete(users_organizations).where(
|
|
281
|
+
and(
|
|
282
|
+
eq(users_organizations.organization_id, organization_id),
|
|
283
|
+
inArray(
|
|
284
|
+
users_organizations.user_id,
|
|
285
|
+
members.map(({ user_id }) => user_id),
|
|
286
|
+
),
|
|
287
|
+
),
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
for (const { is_external, user_id, verification_type } of members) {
|
|
291
|
+
await insertActivity<ActivityContexts>(tx, {
|
|
292
|
+
action: "member.removed",
|
|
293
|
+
actor: { type: "app", job: "domain.remove_members" },
|
|
294
|
+
app,
|
|
295
|
+
cause_activity_id,
|
|
296
|
+
context: { inputs: {}, outcome: { is_external, verification_type } },
|
|
297
|
+
organization_id,
|
|
298
|
+
user_id,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function toPreviousMembership({ user_id, verification_type }: Member) {
|
|
304
|
+
return { previous_verification_type: verification_type, user_id };
|
|
305
|
+
}
|
package/src/domains/index.ts
CHANGED
|
@@ -26,20 +26,20 @@ async function setup() {
|
|
|
26
26
|
|
|
27
27
|
await db.insert(schema.users).values([
|
|
28
28
|
{
|
|
29
|
-
created_at: "4444-04-04",
|
|
29
|
+
created_at: new Date("4444-04-04"),
|
|
30
30
|
email: "jean.valjean@republic.fr",
|
|
31
31
|
family_name: "Fauchelevent",
|
|
32
32
|
given_name: "Jeannot",
|
|
33
33
|
id: 1,
|
|
34
|
-
updated_at: "4444-04-04",
|
|
34
|
+
updated_at: new Date("4444-04-04"),
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
|
-
created_at: "4444-04-04",
|
|
37
|
+
created_at: new Date("4444-04-04"),
|
|
38
38
|
email: "cosette@republic.fr",
|
|
39
39
|
family_name: "Fauchelevent",
|
|
40
40
|
given_name: "Cosette",
|
|
41
41
|
id: 2,
|
|
42
|
-
updated_at: "4444-04-04",
|
|
42
|
+
updated_at: new Date("4444-04-04"),
|
|
43
43
|
},
|
|
44
44
|
]);
|
|
45
45
|
|
|
@@ -14,16 +14,16 @@ async function setup() {
|
|
|
14
14
|
|
|
15
15
|
await db.insert(schema.users).values([
|
|
16
16
|
{
|
|
17
|
-
created_at: "4444-04-04",
|
|
17
|
+
created_at: new Date("4444-04-04"),
|
|
18
18
|
email: "jean.valjean@republic.fr",
|
|
19
19
|
id: 1,
|
|
20
|
-
updated_at: "4444-04-04",
|
|
20
|
+
updated_at: new Date("4444-04-04"),
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
created_at: "4444-04-04",
|
|
23
|
+
created_at: new Date("4444-04-04"),
|
|
24
24
|
email: "cosette@republic.fr",
|
|
25
25
|
id: 2,
|
|
26
|
-
updated_at: "4444-04-04",
|
|
26
|
+
updated_at: new Date("4444-04-04"),
|
|
27
27
|
},
|
|
28
28
|
]);
|
|
29
29
|
await db.insert(schema.franceconnect_userinfo).values({
|
package/src/index.ts
CHANGED
|
@@ -14,16 +14,16 @@ async function setup() {
|
|
|
14
14
|
await db.insert(schema.organizations).values({ id: 1, siret: "🦁" });
|
|
15
15
|
await db.insert(schema.users).values([
|
|
16
16
|
{
|
|
17
|
-
created_at: "4444-04-04",
|
|
17
|
+
created_at: new Date("4444-04-04"),
|
|
18
18
|
email: "jean.valjean@republic.fr",
|
|
19
19
|
id: 1,
|
|
20
|
-
updated_at: "4444-04-04",
|
|
20
|
+
updated_at: new Date("4444-04-04"),
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
created_at: "4444-04-04",
|
|
23
|
+
created_at: new Date("4444-04-04"),
|
|
24
24
|
email: "cosette@republic.fr",
|
|
25
25
|
id: 2,
|
|
26
|
-
updated_at: "4444-04-04",
|
|
26
|
+
updated_at: new Date("4444-04-04"),
|
|
27
27
|
},
|
|
28
28
|
]);
|
|
29
29
|
await db.insert(schema.users_organizations).values({
|
|
@@ -17,16 +17,16 @@ async function setup() {
|
|
|
17
17
|
]);
|
|
18
18
|
await db.insert(schema.users).values([
|
|
19
19
|
{
|
|
20
|
-
created_at: "4444-04-04",
|
|
20
|
+
created_at: new Date("4444-04-04"),
|
|
21
21
|
email: "lion.eljonson@darkangels.world",
|
|
22
22
|
id: 1,
|
|
23
|
-
updated_at: "4444-04-04",
|
|
23
|
+
updated_at: new Date("4444-04-04"),
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
|
-
created_at: "4444-04-04",
|
|
26
|
+
created_at: new Date("4444-04-04"),
|
|
27
27
|
email: "azrael@darkangels.world",
|
|
28
28
|
id: 2,
|
|
29
|
-
updated_at: "4444-04-04",
|
|
29
|
+
updated_at: new Date("4444-04-04"),
|
|
30
30
|
},
|
|
31
31
|
]);
|
|
32
32
|
await db.insert(schema.users_organizations).values([
|
|
@@ -14,22 +14,22 @@ async function setup() {
|
|
|
14
14
|
await db.insert(schema.organizations).values([{ id: 1, siret: "🦁" }]);
|
|
15
15
|
await db.insert(schema.users).values([
|
|
16
16
|
{
|
|
17
|
-
created_at: "4444-04-04",
|
|
17
|
+
created_at: new Date("4444-04-04"),
|
|
18
18
|
email: "lion.eljonson@darkangels.world",
|
|
19
19
|
id: 1,
|
|
20
|
-
updated_at: "4444-04-04",
|
|
20
|
+
updated_at: new Date("4444-04-04"),
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
created_at: "4444-04-04",
|
|
23
|
+
created_at: new Date("4444-04-04"),
|
|
24
24
|
email: "azrael@darkangels.world",
|
|
25
25
|
id: 2,
|
|
26
|
-
updated_at: "4444-04-04",
|
|
26
|
+
updated_at: new Date("4444-04-04"),
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
|
-
created_at: "4444-04-04",
|
|
29
|
+
created_at: new Date("4444-04-04"),
|
|
30
30
|
email: "sanguinius@darkangels.world",
|
|
31
31
|
id: 3,
|
|
32
|
-
updated_at: "4444-04-04",
|
|
32
|
+
updated_at: new Date("4444-04-04"),
|
|
33
33
|
},
|
|
34
34
|
]);
|
|
35
35
|
await db.insert(schema.users_organizations).values([
|
|
@@ -12,10 +12,10 @@ async function setup() {
|
|
|
12
12
|
const db = await createTestDatabase();
|
|
13
13
|
|
|
14
14
|
await db.insert(schema.users).values({
|
|
15
|
-
created_at: "4444-04-04",
|
|
15
|
+
created_at: new Date("4444-04-04"),
|
|
16
16
|
email: "jean.valjean@republic.fr",
|
|
17
17
|
id: 1,
|
|
18
|
-
updated_at: "4444-04-04",
|
|
18
|
+
updated_at: new Date("4444-04-04"),
|
|
19
19
|
});
|
|
20
20
|
await db.insert(schema.organizations).values({
|
|
21
21
|
created_at: "4444-04-04",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
3
|
import type { ContextsOf } from "#src/activity";
|
|
4
|
-
import type { IdentiteTransaction } from "#src/database";
|
|
5
4
|
import { createIdentiteRuntime } from "#src/runtime";
|
|
6
5
|
import { createTestDatabase, readActivityLogs } from "#testing";
|
|
7
6
|
import assert from "node:assert/strict";
|
|
@@ -11,31 +10,23 @@ import * as z from "zod";
|
|
|
11
10
|
//
|
|
12
11
|
|
|
13
12
|
const hyyypertool_activities = {
|
|
14
|
-
"
|
|
13
|
+
"moderation.commented": z.object({
|
|
15
14
|
inputs: z.object({
|
|
16
|
-
|
|
17
|
-
verification_type: z.literal("refused"),
|
|
15
|
+
comment: z.string(),
|
|
18
16
|
}),
|
|
19
17
|
outcome: z.object({
|
|
20
|
-
|
|
21
|
-
replaced_verification_types: z.array(z.string()),
|
|
18
|
+
moderation_id: z.number(),
|
|
22
19
|
}),
|
|
23
20
|
}),
|
|
24
21
|
};
|
|
25
22
|
|
|
26
23
|
type HyyypertoolActivityContexts = ContextsOf<typeof hyyypertool_activities>;
|
|
27
24
|
|
|
28
|
-
const
|
|
29
|
-
action: "
|
|
25
|
+
const darkangels_commented = {
|
|
26
|
+
action: "moderation.commented" as const,
|
|
30
27
|
context: {
|
|
31
|
-
inputs: {
|
|
32
|
-
|
|
33
|
-
verification_type: "refused" as const,
|
|
34
|
-
},
|
|
35
|
-
outcome: {
|
|
36
|
-
email_domain_id: 7,
|
|
37
|
-
replaced_verification_types: ["not_verified_yet"],
|
|
38
|
-
},
|
|
28
|
+
inputs: { comment: "darkangels.world looks legit" },
|
|
29
|
+
outcome: { moderation_id: 7 },
|
|
39
30
|
},
|
|
40
31
|
organization_id: 1,
|
|
41
32
|
};
|
|
@@ -48,7 +39,7 @@ async function setup() {
|
|
|
48
39
|
moderator: createIdentiteRuntime<HyyypertoolActivityContexts>({
|
|
49
40
|
app: "hyyypertool",
|
|
50
41
|
db,
|
|
51
|
-
}).as({ type: "moderator", sub: "moderator+
|
|
42
|
+
}).as({ type: "moderator", sub: "moderator+comments-darkangels.world" }),
|
|
52
43
|
};
|
|
53
44
|
}
|
|
54
45
|
|
|
@@ -57,18 +48,18 @@ describe("record", () => {
|
|
|
57
48
|
const { db, moderator } = await setup();
|
|
58
49
|
|
|
59
50
|
const outcome = await db.transaction((tx) =>
|
|
60
|
-
moderator.record(tx,
|
|
51
|
+
moderator.record(tx, darkangels_commented),
|
|
61
52
|
);
|
|
62
53
|
|
|
63
54
|
assert.deepEqual(outcome, { activity_id: 1 });
|
|
64
55
|
assert.deepEqual(await readActivityLogs(db), [
|
|
65
56
|
{
|
|
66
|
-
action: "
|
|
67
|
-
actor_ref: "moderator+
|
|
57
|
+
action: "moderation.commented",
|
|
58
|
+
actor_ref: "moderator+comments-darkangels.world",
|
|
68
59
|
actor_type: "moderator",
|
|
69
60
|
app: "hyyypertool",
|
|
70
61
|
cause_activity_id: null,
|
|
71
|
-
context:
|
|
62
|
+
context: darkangels_commented.context,
|
|
72
63
|
interaction_cid: null,
|
|
73
64
|
moderation_id: null,
|
|
74
65
|
organization_id: 1,
|
|
@@ -76,42 +67,4 @@ describe("record", () => {
|
|
|
76
67
|
},
|
|
77
68
|
]);
|
|
78
69
|
});
|
|
79
|
-
|
|
80
|
-
it("🚫 does not compile another owner's action, a mismatched context, the bare database or an overlapping owner", async () => {
|
|
81
|
-
const { db } = await setup();
|
|
82
|
-
const { record } = createIdentiteRuntime<HyyypertoolActivityContexts>({
|
|
83
|
-
app: "hyyypertool",
|
|
84
|
-
db,
|
|
85
|
-
}).as({ type: "moderator", sub: "moderator" });
|
|
86
|
-
|
|
87
|
-
void ((tx: IdentiteTransaction) =>
|
|
88
|
-
record(tx, {
|
|
89
|
-
// @ts-expect-error domain.verified belongs to the runtime, only markDomainAsVerified writes it
|
|
90
|
-
action: "domain.verified",
|
|
91
|
-
context: darkangels_refused.context,
|
|
92
|
-
}));
|
|
93
|
-
|
|
94
|
-
void ((tx: IdentiteTransaction) =>
|
|
95
|
-
record(tx, {
|
|
96
|
-
action: "domain.refused",
|
|
97
|
-
// @ts-expect-error the context does not match domain.refused
|
|
98
|
-
context: { inputs: { domain: "darkangels.world" }, outcome: {} },
|
|
99
|
-
}));
|
|
100
|
-
|
|
101
|
-
void (() =>
|
|
102
|
-
// @ts-expect-error the bare database is not a transaction
|
|
103
|
-
record(db, darkangels_refused));
|
|
104
|
-
|
|
105
|
-
type OverlappingContexts = {
|
|
106
|
-
"domain.verified": HyyypertoolActivityContexts["domain.refused"];
|
|
107
|
-
};
|
|
108
|
-
// @ts-expect-error domain.verified is already defined by the runtime
|
|
109
|
-
void createIdentiteRuntime<OverlappingContexts>({ app: "hyyypertool", db });
|
|
110
|
-
|
|
111
|
-
void ((tx: IdentiteTransaction) =>
|
|
112
|
-
createIdentiteRuntime({ app: "proconnect-identite", db })
|
|
113
|
-
.as({ type: "app", job: "join.official_contact" })
|
|
114
|
-
// @ts-expect-error proconnect-identite has no app-only action to record
|
|
115
|
-
.record(tx, darkangels_refused));
|
|
116
|
-
});
|
|
117
70
|
});
|
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
RuntimeContext,
|
|
10
10
|
} from "#src/activity";
|
|
11
11
|
import type { IdentiteTransaction } from "#src/database";
|
|
12
|
-
import {
|
|
12
|
+
import { changeEmailDomainVerificationFactory } from "#src/domains";
|
|
13
13
|
import {
|
|
14
14
|
connectFranceConnectFactory,
|
|
15
15
|
disconnectFranceConnectFactory,
|
|
@@ -39,6 +39,11 @@ export function createIdentiteRuntime<
|
|
|
39
39
|
as(actor: Actor) {
|
|
40
40
|
return {
|
|
41
41
|
addMembership: addMembershipFactory({ actor, app, db }),
|
|
42
|
+
changeEmailDomainVerification: changeEmailDomainVerificationFactory({
|
|
43
|
+
actor,
|
|
44
|
+
app,
|
|
45
|
+
db,
|
|
46
|
+
}),
|
|
42
47
|
changePassword: changePasswordFactory({ actor, app, db }),
|
|
43
48
|
connectFranceConnect: connectFranceConnectFactory({ actor, app, db }),
|
|
44
49
|
deleteUser: deleteUserFactory({ actor, app, db }),
|
|
@@ -47,7 +52,6 @@ export function createIdentiteRuntime<
|
|
|
47
52
|
app,
|
|
48
53
|
db,
|
|
49
54
|
}),
|
|
50
|
-
markDomainAsVerified: markDomainAsVerifiedFactory({ actor, app, db }),
|
|
51
55
|
openModeration: openModerationFactory({ actor, app, db }),
|
|
52
56
|
removeMembership: removeMembershipFactory({ actor, app, db }),
|
|
53
57
|
record: (
|
|
@@ -11,11 +11,11 @@ import { describe, it } from "node:test";
|
|
|
11
11
|
async function setup() {
|
|
12
12
|
const db = await createTestDatabase();
|
|
13
13
|
await db.insert(schema.users).values({
|
|
14
|
-
created_at: "4444-04-04",
|
|
14
|
+
created_at: new Date("4444-04-04"),
|
|
15
15
|
email: "jean.valjean@republic.fr",
|
|
16
16
|
id: 1,
|
|
17
17
|
reset_password_token: "token",
|
|
18
|
-
updated_at: "4444-04-04",
|
|
18
|
+
updated_at: new Date("4444-04-04"),
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
return {
|
|
@@ -14,18 +14,18 @@ async function setup() {
|
|
|
14
14
|
|
|
15
15
|
await db.insert(schema.users).values([
|
|
16
16
|
{
|
|
17
|
-
created_at: "4444-04-04",
|
|
17
|
+
created_at: new Date("4444-04-04"),
|
|
18
18
|
email: "jean.valjean@republic.fr",
|
|
19
19
|
family_name: "Valjean",
|
|
20
20
|
given_name: "Jean",
|
|
21
21
|
id: 1,
|
|
22
|
-
updated_at: "4444-04-04",
|
|
22
|
+
updated_at: new Date("4444-04-04"),
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
|
-
created_at: "4444-04-04",
|
|
25
|
+
created_at: new Date("4444-04-04"),
|
|
26
26
|
email: "cosette@republic.fr",
|
|
27
27
|
id: 2,
|
|
28
|
-
updated_at: "4444-04-04",
|
|
28
|
+
updated_at: new Date("4444-04-04"),
|
|
29
29
|
},
|
|
30
30
|
]);
|
|
31
31
|
await db.insert(schema.organizations).values([
|
|
@@ -14,21 +14,21 @@ async function setup() {
|
|
|
14
14
|
|
|
15
15
|
await db.insert(schema.users).values([
|
|
16
16
|
{
|
|
17
|
-
created_at: "4444-04-04",
|
|
17
|
+
created_at: new Date("4444-04-04"),
|
|
18
18
|
email: "jean.valjean@republic.fr",
|
|
19
19
|
email_verified: true,
|
|
20
20
|
encrypted_password: "🔑",
|
|
21
21
|
encrypted_totp_key: "🔐",
|
|
22
22
|
force_2fa: true,
|
|
23
23
|
id: 1,
|
|
24
|
-
totp_key_verified_at: "4444-04-04",
|
|
25
|
-
updated_at: "4444-04-04",
|
|
24
|
+
totp_key_verified_at: new Date("4444-04-04"),
|
|
25
|
+
updated_at: new Date("4444-04-04"),
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
created_at: "4444-04-04",
|
|
28
|
+
created_at: new Date("4444-04-04"),
|
|
29
29
|
email: "cosette@republic.fr",
|
|
30
30
|
id: 2,
|
|
31
|
-
updated_at: "4444-04-04",
|
|
31
|
+
updated_at: new Date("4444-04-04"),
|
|
32
32
|
},
|
|
33
33
|
]);
|
|
34
34
|
await db.insert(schema.authenticators).values([
|
|
@@ -11,10 +11,10 @@ import { describe, it } from "node:test";
|
|
|
11
11
|
async function setup() {
|
|
12
12
|
const db = await createTestDatabase();
|
|
13
13
|
await db.insert(schema.users).values({
|
|
14
|
-
created_at: "4444-04-04",
|
|
14
|
+
created_at: new Date("4444-04-04"),
|
|
15
15
|
email: "jean.valjean@republic.fr",
|
|
16
16
|
id: 1,
|
|
17
|
-
updated_at: "4444-04-04",
|
|
17
|
+
updated_at: new Date("4444-04-04"),
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
return {
|