@proconnect-gouv/proconnect.identite.runtime 0.3.1 → 0.4.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 +23 -0
- package/dist/activity/activity-context-schemas.d.ts +75 -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 +116 -0
- package/dist/runtime/create-identite-runtime.d.ts.map +1 -1
- package/dist/runtime/create-identite-runtime.js +16 -0
- package/dist/users/activities.d.ts +33 -0
- package/dist/users/activities.d.ts.map +1 -0
- package/dist/users/activities.js +34 -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 +4 -0
- package/dist/users/index.d.ts.map +1 -0
- package/dist/users/index.js +4 -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/package.json +4 -3
- 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 +23 -0
- package/src/users/activities.ts +39 -0
- package/src/users/delete-user.test.ts +142 -0
- package/src/users/delete-user.ts +60 -0
- package/src/users/index.ts +5 -0
- package/src/users/reset-mfa.test.ts +128 -0
- package/src/users/reset-mfa.ts +79 -0
- package/testing/index.ts +25 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { users_organizations } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { SuperWeakLinkEnum, } from "@proconnect-gouv/proconnect.identite/types";
|
|
5
|
+
import { and, eq, sql } from "drizzle-orm";
|
|
6
|
+
export function updateMembershipFactory({ actor, app, db }) {
|
|
7
|
+
return function updateMembership({ is_external, organization_id, renew_verification, user_id, verification_type, }) {
|
|
8
|
+
return db.transaction(async (tx) => {
|
|
9
|
+
const link = and(eq(users_organizations.organization_id, organization_id), eq(users_organizations.user_id, user_id));
|
|
10
|
+
const [previous] = await tx
|
|
11
|
+
.select({
|
|
12
|
+
is_external: users_organizations.is_external,
|
|
13
|
+
verification_type: users_organizations.verification_type,
|
|
14
|
+
})
|
|
15
|
+
.from(users_organizations)
|
|
16
|
+
.where(link)
|
|
17
|
+
.for("update");
|
|
18
|
+
if (!previous) {
|
|
19
|
+
return { kind: "membership_not_found", organization_id, user_id };
|
|
20
|
+
}
|
|
21
|
+
if (renew_verification !== true &&
|
|
22
|
+
(is_external ?? previous.is_external) === previous.is_external &&
|
|
23
|
+
(verification_type ?? previous.verification_type) ===
|
|
24
|
+
previous.verification_type) {
|
|
25
|
+
return { kind: "membership_unchanged", organization_id, user_id };
|
|
26
|
+
}
|
|
27
|
+
const fields = {
|
|
28
|
+
...(is_external === undefined ? {} : { is_external }),
|
|
29
|
+
...(verification_type === undefined ? {} : { verification_type }),
|
|
30
|
+
};
|
|
31
|
+
const inputs = {
|
|
32
|
+
...fields,
|
|
33
|
+
...(renew_verification === true ? { renew_verification: true } : {}),
|
|
34
|
+
};
|
|
35
|
+
await tx
|
|
36
|
+
.update(users_organizations)
|
|
37
|
+
.set({
|
|
38
|
+
...fields,
|
|
39
|
+
...(verification_type === undefined
|
|
40
|
+
? {}
|
|
41
|
+
: {
|
|
42
|
+
verified_at: SuperWeakLinkEnum.safeParse(verification_type)
|
|
43
|
+
.success
|
|
44
|
+
? null
|
|
45
|
+
: sql `now()`,
|
|
46
|
+
}),
|
|
47
|
+
updated_at: sql `now()`,
|
|
48
|
+
})
|
|
49
|
+
.where(link);
|
|
50
|
+
const { activity_id } = await insertActivity(tx, {
|
|
51
|
+
action: "member.updated",
|
|
52
|
+
actor,
|
|
53
|
+
app,
|
|
54
|
+
context: { inputs, outcome: { previous } },
|
|
55
|
+
organization_id,
|
|
56
|
+
user_id,
|
|
57
|
+
});
|
|
58
|
+
return { kind: "member_updated", activity_id, previous };
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const moderationActivities: {
|
|
3
|
+
"moderation.opened": z.ZodObject<{
|
|
4
|
+
inputs: z.ZodObject<{
|
|
5
|
+
sp_name: z.ZodNullable<z.ZodString>;
|
|
6
|
+
type: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
outcome: z.ZodObject<{}, z.core.$strip>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=activities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/moderations/activities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,oBAAoB;;;;;;;;CAQhC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/moderations/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RuntimeContext } from "#src/activity";
|
|
2
|
+
import { type ModerationType } from "@proconnect-gouv/proconnect.identite/types";
|
|
3
|
+
type OpenModerationOutcome = {
|
|
4
|
+
kind: "moderation_opened";
|
|
5
|
+
activity_id: number;
|
|
6
|
+
moderation: {
|
|
7
|
+
id: number;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare function openModerationFactory({ actor, app, db }: RuntimeContext): ({ organization_id, sp_name, ticket_id, type, user_id, }: {
|
|
11
|
+
organization_id: number;
|
|
12
|
+
sp_name?: string | null;
|
|
13
|
+
ticket_id: string | null;
|
|
14
|
+
type: ModerationType;
|
|
15
|
+
user_id: number;
|
|
16
|
+
}) => Promise<OpenModerationOutcome>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=open-moderation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-moderation.d.ts","sourceRoot":"","sources":["../../src/moderations/open-moderation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,4CAA4C,CAAC;AAIpD,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,cAAc,IACvC,yDAM5B;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,qBAAqB,CAAC,CA2BnC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { moderations } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { ModerationStatusSchema, } from "@proconnect-gouv/proconnect.identite/types";
|
|
5
|
+
export function openModerationFactory({ actor, app, db }) {
|
|
6
|
+
return function openModeration({ organization_id, sp_name = null, ticket_id, type, user_id, }) {
|
|
7
|
+
return db.transaction(async (tx) => {
|
|
8
|
+
const [moderation] = await tx
|
|
9
|
+
.insert(moderations)
|
|
10
|
+
.values({
|
|
11
|
+
organization_id,
|
|
12
|
+
sp_name,
|
|
13
|
+
status: ModerationStatusSchema.enum.pending,
|
|
14
|
+
ticket_id,
|
|
15
|
+
type,
|
|
16
|
+
user_id,
|
|
17
|
+
})
|
|
18
|
+
.returning({ id: moderations.id });
|
|
19
|
+
const { activity_id } = await insertActivity(tx, {
|
|
20
|
+
action: "moderation.opened",
|
|
21
|
+
actor,
|
|
22
|
+
app,
|
|
23
|
+
context: { inputs: { sp_name, type }, outcome: {} },
|
|
24
|
+
moderation_id: moderation.id,
|
|
25
|
+
organization_id,
|
|
26
|
+
user_id,
|
|
27
|
+
});
|
|
28
|
+
return { kind: "moderation_opened", activity_id, moderation };
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -4,6 +4,58 @@ export declare function createIdentiteRuntime<OwnContexts extends ContextMap & {
|
|
|
4
4
|
[Action in keyof ActivityContexts]?: never;
|
|
5
5
|
} = {}>({ app, db }: Omit<RuntimeContext, "actor">): {
|
|
6
6
|
as(actor: Actor): {
|
|
7
|
+
addMembership: ({ is_external, organization_id, user_id, verification_type, }: {
|
|
8
|
+
is_external?: boolean;
|
|
9
|
+
organization_id: number;
|
|
10
|
+
user_id: number;
|
|
11
|
+
verification_type: import("@proconnect-gouv/proconnect.identite/types").LinkType;
|
|
12
|
+
}) => Promise<{
|
|
13
|
+
kind: "member_joined";
|
|
14
|
+
activity_id: number;
|
|
15
|
+
membership: {
|
|
16
|
+
organization_id: number;
|
|
17
|
+
user_id: number;
|
|
18
|
+
};
|
|
19
|
+
} | {
|
|
20
|
+
kind: "member_already_exists";
|
|
21
|
+
organization_id: number;
|
|
22
|
+
user_id: number;
|
|
23
|
+
}>;
|
|
24
|
+
connectFranceConnect: ({ user_id, user_info, }: {
|
|
25
|
+
user_id: number;
|
|
26
|
+
user_info: import("@proconnect-gouv/proconnect.identite/types").FranceConnectUserInfoResponse;
|
|
27
|
+
}) => Promise<{
|
|
28
|
+
kind: "franceconnect_connected";
|
|
29
|
+
activity_id: number;
|
|
30
|
+
connected_at: string;
|
|
31
|
+
user: {
|
|
32
|
+
family_name: string;
|
|
33
|
+
given_name: string;
|
|
34
|
+
};
|
|
35
|
+
} | {
|
|
36
|
+
kind: "user_not_found";
|
|
37
|
+
user_id: number;
|
|
38
|
+
}>;
|
|
39
|
+
deleteUser: ({ user_id, }: {
|
|
40
|
+
user_id: number;
|
|
41
|
+
}) => Promise<{
|
|
42
|
+
kind: "user_deleted";
|
|
43
|
+
activity_id: number;
|
|
44
|
+
previous: ActivityContexts["user.deleted"]["outcome"];
|
|
45
|
+
} | {
|
|
46
|
+
kind: "user_not_found";
|
|
47
|
+
user_id: number;
|
|
48
|
+
}>;
|
|
49
|
+
disconnectFranceConnect: ({ user_id, }: {
|
|
50
|
+
user_id: number;
|
|
51
|
+
}) => Promise<{
|
|
52
|
+
kind: "franceconnect_disconnected";
|
|
53
|
+
activity_id: number;
|
|
54
|
+
connected_at: string;
|
|
55
|
+
} | {
|
|
56
|
+
kind: "franceconnect_identity_not_found";
|
|
57
|
+
user_id: number;
|
|
58
|
+
}>;
|
|
7
59
|
markDomainAsVerified: ({ domain, domain_verification_type, organization_id, }: {
|
|
8
60
|
domain: string;
|
|
9
61
|
domain_verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainApprovedVerificationType;
|
|
@@ -24,9 +76,73 @@ export declare function createIdentiteRuntime<OwnContexts extends ContextMap & {
|
|
|
24
76
|
kind: "organization_not_found";
|
|
25
77
|
organization_id: number;
|
|
26
78
|
}>;
|
|
79
|
+
openModeration: ({ organization_id, sp_name, ticket_id, type, user_id, }: {
|
|
80
|
+
organization_id: number;
|
|
81
|
+
sp_name?: string | null;
|
|
82
|
+
ticket_id: string | null;
|
|
83
|
+
type: import("@proconnect-gouv/proconnect.identite/types").ModerationType;
|
|
84
|
+
user_id: number;
|
|
85
|
+
}) => Promise<{
|
|
86
|
+
kind: "moderation_opened";
|
|
87
|
+
activity_id: number;
|
|
88
|
+
moderation: {
|
|
89
|
+
id: number;
|
|
90
|
+
};
|
|
91
|
+
}>;
|
|
92
|
+
removeMembership: ({ organization_id, user_id, }: {
|
|
93
|
+
organization_id: number;
|
|
94
|
+
user_id: number;
|
|
95
|
+
}) => Promise<{
|
|
96
|
+
kind: "member_removed";
|
|
97
|
+
activity_id: number;
|
|
98
|
+
previous: {
|
|
99
|
+
is_external: boolean;
|
|
100
|
+
verification_type: string;
|
|
101
|
+
};
|
|
102
|
+
} | {
|
|
103
|
+
kind: "membership_not_found";
|
|
104
|
+
organization_id: number;
|
|
105
|
+
user_id: number;
|
|
106
|
+
}>;
|
|
27
107
|
record: (tx: IdentiteTransaction, activity: ActivityOf<OwnContexts> & ActivityTargets) => Promise<{
|
|
28
108
|
activity_id: number;
|
|
29
109
|
}>;
|
|
110
|
+
resetMfa: ({ user_id, }: {
|
|
111
|
+
user_id: number;
|
|
112
|
+
}) => Promise<{
|
|
113
|
+
kind: "mfa_reset";
|
|
114
|
+
activity_id: number;
|
|
115
|
+
previous: ActivityContexts["user.mfa_reset"]["outcome"]["previous"];
|
|
116
|
+
} | {
|
|
117
|
+
kind: "user_not_found";
|
|
118
|
+
user_id: number;
|
|
119
|
+
}>;
|
|
120
|
+
updateMembership: ({ is_external, organization_id, renew_verification, user_id, verification_type, }: {
|
|
121
|
+
is_external?: boolean;
|
|
122
|
+
organization_id: number;
|
|
123
|
+
user_id: number;
|
|
124
|
+
} & ({
|
|
125
|
+
renew_verification: true;
|
|
126
|
+
verification_type: import("@proconnect-gouv/proconnect.identite/types").LinkType;
|
|
127
|
+
} | {
|
|
128
|
+
renew_verification?: false;
|
|
129
|
+
verification_type?: import("@proconnect-gouv/proconnect.identite/types").LinkType;
|
|
130
|
+
})) => Promise<{
|
|
131
|
+
kind: "member_updated";
|
|
132
|
+
activity_id: number;
|
|
133
|
+
previous: {
|
|
134
|
+
is_external: boolean;
|
|
135
|
+
verification_type: string;
|
|
136
|
+
};
|
|
137
|
+
} | {
|
|
138
|
+
kind: "membership_not_found";
|
|
139
|
+
organization_id: number;
|
|
140
|
+
user_id: number;
|
|
141
|
+
} | {
|
|
142
|
+
kind: "membership_unchanged";
|
|
143
|
+
organization_id: number;
|
|
144
|
+
user_id: number;
|
|
145
|
+
}>;
|
|
30
146
|
};
|
|
31
147
|
};
|
|
32
148
|
//# 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;
|
|
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,13 +1,29 @@
|
|
|
1
1
|
//
|
|
2
2
|
import { markDomainAsVerifiedFactory } from "#src/domains";
|
|
3
|
+
import { connectFranceConnectFactory, disconnectFranceConnectFactory, } from "#src/franceconnect";
|
|
3
4
|
import { insertActivity } from "#src/journal";
|
|
5
|
+
import { addMembershipFactory, removeMembershipFactory, updateMembershipFactory, } from "#src/memberships";
|
|
6
|
+
import { openModerationFactory } from "#src/moderations";
|
|
7
|
+
import { deleteUserFactory, resetMfaFactory } from "#src/users";
|
|
4
8
|
//
|
|
5
9
|
export function createIdentiteRuntime({ app, db }) {
|
|
6
10
|
return {
|
|
7
11
|
as(actor) {
|
|
8
12
|
return {
|
|
13
|
+
addMembership: addMembershipFactory({ actor, app, db }),
|
|
14
|
+
connectFranceConnect: connectFranceConnectFactory({ actor, app, db }),
|
|
15
|
+
deleteUser: deleteUserFactory({ actor, app, db }),
|
|
16
|
+
disconnectFranceConnect: disconnectFranceConnectFactory({
|
|
17
|
+
actor,
|
|
18
|
+
app,
|
|
19
|
+
db,
|
|
20
|
+
}),
|
|
9
21
|
markDomainAsVerified: markDomainAsVerifiedFactory({ actor, app, db }),
|
|
22
|
+
openModeration: openModerationFactory({ actor, app, db }),
|
|
23
|
+
removeMembership: removeMembershipFactory({ actor, app, db }),
|
|
10
24
|
record: (tx, activity) => insertActivity(tx, { ...activity, actor, app }),
|
|
25
|
+
resetMfa: resetMfaFactory({ actor, app, db }),
|
|
26
|
+
updateMembership: updateMembershipFactory({ actor, app, db }),
|
|
11
27
|
};
|
|
12
28
|
},
|
|
13
29
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const userActivities: {
|
|
3
|
+
"user.deleted": z.ZodObject<{
|
|
4
|
+
inputs: z.ZodObject<{
|
|
5
|
+
user_id: z.ZodNumber;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
outcome: z.ZodObject<{
|
|
8
|
+
email: z.ZodString;
|
|
9
|
+
family_name: z.ZodNullable<z.ZodString>;
|
|
10
|
+
given_name: z.ZodNullable<z.ZodString>;
|
|
11
|
+
memberships: z.ZodArray<z.ZodObject<{
|
|
12
|
+
is_external: z.ZodBoolean;
|
|
13
|
+
organization_id: z.ZodNumber;
|
|
14
|
+
verification_type: z.ZodString;
|
|
15
|
+
}, z.core.$strip>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
"user.mfa_reset": z.ZodObject<{
|
|
19
|
+
inputs: z.ZodObject<{
|
|
20
|
+
user_id: z.ZodNumber;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
outcome: z.ZodObject<{
|
|
23
|
+
previous: z.ZodObject<{
|
|
24
|
+
authenticators: z.ZodNumber;
|
|
25
|
+
email_verified: z.ZodBoolean;
|
|
26
|
+
force_2fa: z.ZodBoolean;
|
|
27
|
+
password_configured: z.ZodBoolean;
|
|
28
|
+
totp_configured: z.ZodBoolean;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=activities.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//
|
|
4
|
+
export const userActivities = {
|
|
5
|
+
"user.deleted": z.object({
|
|
6
|
+
inputs: z.object({
|
|
7
|
+
user_id: z.number(),
|
|
8
|
+
}),
|
|
9
|
+
outcome: z.object({
|
|
10
|
+
email: z.string(),
|
|
11
|
+
family_name: z.string().nullable(),
|
|
12
|
+
given_name: z.string().nullable(),
|
|
13
|
+
memberships: z.array(z.object({
|
|
14
|
+
is_external: z.boolean(),
|
|
15
|
+
organization_id: z.number(),
|
|
16
|
+
verification_type: z.string(),
|
|
17
|
+
})),
|
|
18
|
+
}),
|
|
19
|
+
}),
|
|
20
|
+
"user.mfa_reset": z.object({
|
|
21
|
+
inputs: z.object({
|
|
22
|
+
user_id: z.number(),
|
|
23
|
+
}),
|
|
24
|
+
outcome: z.object({
|
|
25
|
+
previous: z.object({
|
|
26
|
+
authenticators: z.number(),
|
|
27
|
+
email_verified: z.boolean(),
|
|
28
|
+
force_2fa: z.boolean(),
|
|
29
|
+
password_configured: z.boolean(),
|
|
30
|
+
totp_configured: z.boolean(),
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ActivityContexts, RuntimeContext } from "#src/activity";
|
|
2
|
+
type DeleteUserOutcome = {
|
|
3
|
+
kind: "user_deleted";
|
|
4
|
+
activity_id: number;
|
|
5
|
+
previous: ActivityContexts["user.deleted"]["outcome"];
|
|
6
|
+
} | {
|
|
7
|
+
kind: "user_not_found";
|
|
8
|
+
user_id: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function deleteUserFactory({ actor, app, db }: RuntimeContext): ({ user_id, }: {
|
|
11
|
+
user_id: number;
|
|
12
|
+
}) => Promise<DeleteUserOutcome>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=delete-user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-user.d.ts","sourceRoot":"","sources":["../../src/users/delete-user.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAOtE,KAAK,iBAAiB,GAClB;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC;CACvD,GACD;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,wBAAgB,iBAAiB,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,cAAc,IACvC,cAExB;IACD,OAAO,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,iBAAiB,CAAC,CAqC/B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { users } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { eq } from "drizzle-orm";
|
|
5
|
+
export function deleteUserFactory({ actor, app, db }) {
|
|
6
|
+
return function deleteUser({ user_id, }) {
|
|
7
|
+
return db.transaction(async (tx) => {
|
|
8
|
+
const memberships = await tx.query.users_organizations.findMany({
|
|
9
|
+
columns: {
|
|
10
|
+
is_external: true,
|
|
11
|
+
organization_id: true,
|
|
12
|
+
verification_type: true,
|
|
13
|
+
},
|
|
14
|
+
orderBy: (table, { asc }) => asc(table.organization_id),
|
|
15
|
+
where: (table, { eq }) => eq(table.user_id, user_id),
|
|
16
|
+
});
|
|
17
|
+
const [user] = await tx
|
|
18
|
+
.delete(users)
|
|
19
|
+
.where(eq(users.id, user_id))
|
|
20
|
+
.returning({
|
|
21
|
+
email: users.email,
|
|
22
|
+
family_name: users.family_name,
|
|
23
|
+
given_name: users.given_name,
|
|
24
|
+
});
|
|
25
|
+
if (!user) {
|
|
26
|
+
return { kind: "user_not_found", user_id };
|
|
27
|
+
}
|
|
28
|
+
const previous = { ...user, memberships };
|
|
29
|
+
const { activity_id } = await insertActivity(tx, {
|
|
30
|
+
action: "user.deleted",
|
|
31
|
+
actor,
|
|
32
|
+
app,
|
|
33
|
+
context: { inputs: { user_id }, outcome: previous },
|
|
34
|
+
user_id,
|
|
35
|
+
});
|
|
36
|
+
return { kind: "user_deleted", activity_id, previous };
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ActivityContexts, RuntimeContext } from "#src/activity";
|
|
2
|
+
type ResetMfaOutcome = {
|
|
3
|
+
kind: "mfa_reset";
|
|
4
|
+
activity_id: number;
|
|
5
|
+
previous: ActivityContexts["user.mfa_reset"]["outcome"]["previous"];
|
|
6
|
+
} | {
|
|
7
|
+
kind: "user_not_found";
|
|
8
|
+
user_id: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function resetMfaFactory({ actor, app, db }: RuntimeContext): ({ user_id, }: {
|
|
11
|
+
user_id: number;
|
|
12
|
+
}) => Promise<ResetMfaOutcome>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=reset-mfa.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reset-mfa.d.ts","sourceRoot":"","sources":["../../src/users/reset-mfa.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAUtE,KAAK,eAAe,GAChB;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,CAAC;CACrE,GACD;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,cAAc,IACvC,cAEtB;IACD,OAAO,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,eAAe,CAAC,CAqD7B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { authenticators, users, } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { eq, sql } from "drizzle-orm";
|
|
5
|
+
export function resetMfaFactory({ actor, app, db }) {
|
|
6
|
+
return function resetMfa({ user_id, }) {
|
|
7
|
+
return db.transaction(async (tx) => {
|
|
8
|
+
const [previousUser] = await tx
|
|
9
|
+
.select({
|
|
10
|
+
email_verified: users.email_verified,
|
|
11
|
+
force_2fa: users.force_2fa,
|
|
12
|
+
password_configured: sql `${users.encrypted_password} is not null`,
|
|
13
|
+
totp_configured: sql `${users.encrypted_totp_key} is not null`,
|
|
14
|
+
})
|
|
15
|
+
.from(users)
|
|
16
|
+
.where(eq(users.id, user_id))
|
|
17
|
+
.for("update");
|
|
18
|
+
if (!previousUser) {
|
|
19
|
+
return { kind: "user_not_found", user_id };
|
|
20
|
+
}
|
|
21
|
+
const removedAuthenticators = await tx
|
|
22
|
+
.delete(authenticators)
|
|
23
|
+
.where(eq(authenticators.user_id, user_id))
|
|
24
|
+
.returning({ credential_id: authenticators.credential_id });
|
|
25
|
+
await tx
|
|
26
|
+
.update(users)
|
|
27
|
+
.set({
|
|
28
|
+
email_verified: false,
|
|
29
|
+
encrypted_password: null,
|
|
30
|
+
encrypted_totp_key: null,
|
|
31
|
+
force_2fa: false,
|
|
32
|
+
totp_key_verified_at: null,
|
|
33
|
+
updated_at: sql `now()`,
|
|
34
|
+
})
|
|
35
|
+
.where(eq(users.id, user_id));
|
|
36
|
+
const previous = {
|
|
37
|
+
authenticators: removedAuthenticators.length,
|
|
38
|
+
email_verified: previousUser.email_verified,
|
|
39
|
+
force_2fa: previousUser.force_2fa,
|
|
40
|
+
password_configured: previousUser.password_configured,
|
|
41
|
+
totp_configured: previousUser.totp_configured,
|
|
42
|
+
};
|
|
43
|
+
const { activity_id } = await insertActivity(tx, {
|
|
44
|
+
action: "user.mfa_reset",
|
|
45
|
+
actor,
|
|
46
|
+
app,
|
|
47
|
+
context: { inputs: { user_id }, outcome: { previous } },
|
|
48
|
+
user_id,
|
|
49
|
+
});
|
|
50
|
+
return { kind: "mfa_reset", activity_id, 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.
|
|
3
|
+
"version": "0.4.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": {
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"#src/*": {
|
|
16
16
|
"types": "./dist/*/index.d.ts",
|
|
17
17
|
"default": "./dist/*/index.js"
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
|
+
"#testing": "./testing/index.ts"
|
|
19
20
|
},
|
|
20
21
|
"exports": {
|
|
21
22
|
".": {
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"test": "tsc --noEmit && tsx --test --test-reporter=spec"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@proconnect-gouv/proconnect.identite": "^
|
|
35
|
+
"@proconnect-gouv/proconnect.identite": "^14.0.0",
|
|
35
36
|
"@proconnect-gouv/proconnect.identite.database": "^1.12.0",
|
|
36
37
|
"zod": "^4.6.7"
|
|
37
38
|
},
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
3
|
import { domainActivities } from "#src/domains";
|
|
4
|
+
import { franceconnectActivities } from "#src/franceconnect";
|
|
4
5
|
import { membershipActivities } from "#src/memberships";
|
|
6
|
+
import { moderationActivities } from "#src/moderations";
|
|
7
|
+
import { userActivities } from "#src/users";
|
|
5
8
|
import type { ContextsOf } from "./types.js";
|
|
6
9
|
|
|
7
10
|
//
|
|
8
11
|
|
|
9
12
|
export const activityContextSchemas = {
|
|
10
13
|
...domainActivities,
|
|
14
|
+
...franceconnectActivities,
|
|
11
15
|
...membershipActivities,
|
|
16
|
+
...moderationActivities,
|
|
17
|
+
...userActivities,
|
|
12
18
|
};
|
|
13
19
|
|
|
14
20
|
export type ActivityContexts = ContextsOf<typeof activityContextSchemas>;
|
package/src/activity/types.ts
CHANGED
|
@@ -7,7 +7,8 @@ import type * as z from "zod";
|
|
|
7
7
|
|
|
8
8
|
export type Actor =
|
|
9
9
|
| { type: "app"; job: string }
|
|
10
|
-
| { type: "moderator"; sub: string }
|
|
10
|
+
| { type: "moderator"; sub: string }
|
|
11
|
+
| { type: "user"; user_id: number };
|
|
11
12
|
|
|
12
13
|
export type App = "hyyypertool" | "proconnect-identite";
|
|
13
14
|
|