@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,29 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { users_organizations } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { and, eq } from "drizzle-orm";
|
|
5
|
+
export function removeMembershipFactory({ actor, app, db }) {
|
|
6
|
+
return function removeMembership({ organization_id, user_id, }) {
|
|
7
|
+
return db.transaction(async (tx) => {
|
|
8
|
+
const [previous] = await tx
|
|
9
|
+
.delete(users_organizations)
|
|
10
|
+
.where(and(eq(users_organizations.organization_id, organization_id), eq(users_organizations.user_id, user_id)))
|
|
11
|
+
.returning({
|
|
12
|
+
is_external: users_organizations.is_external,
|
|
13
|
+
verification_type: users_organizations.verification_type,
|
|
14
|
+
});
|
|
15
|
+
if (!previous) {
|
|
16
|
+
return { kind: "membership_not_found", organization_id, user_id };
|
|
17
|
+
}
|
|
18
|
+
const { activity_id } = await insertActivity(tx, {
|
|
19
|
+
action: "member.removed",
|
|
20
|
+
actor,
|
|
21
|
+
app,
|
|
22
|
+
context: { inputs: {}, outcome: previous },
|
|
23
|
+
organization_id,
|
|
24
|
+
user_id,
|
|
25
|
+
});
|
|
26
|
+
return { kind: "member_removed", activity_id, previous };
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RuntimeContext } from "#src/activity";
|
|
2
|
+
import { type LinkType } from "@proconnect-gouv/proconnect.identite/types";
|
|
3
|
+
type UpdateMembershipOutcome = {
|
|
4
|
+
kind: "member_updated";
|
|
5
|
+
activity_id: number;
|
|
6
|
+
previous: {
|
|
7
|
+
is_external: boolean;
|
|
8
|
+
verification_type: string;
|
|
9
|
+
};
|
|
10
|
+
} | {
|
|
11
|
+
kind: "membership_not_found";
|
|
12
|
+
organization_id: number;
|
|
13
|
+
user_id: number;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "membership_unchanged";
|
|
16
|
+
organization_id: number;
|
|
17
|
+
user_id: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function updateMembershipFactory({ actor, app, db }: RuntimeContext): ({ is_external, organization_id, renew_verification, user_id, verification_type, }: {
|
|
20
|
+
is_external?: boolean;
|
|
21
|
+
organization_id: number;
|
|
22
|
+
user_id: number;
|
|
23
|
+
} & ({
|
|
24
|
+
renew_verification: true;
|
|
25
|
+
verification_type: LinkType;
|
|
26
|
+
} | {
|
|
27
|
+
renew_verification?: false;
|
|
28
|
+
verification_type?: LinkType;
|
|
29
|
+
})) => Promise<UpdateMembershipOutcome>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=update-membership.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-membership.d.ts","sourceRoot":"","sources":["../../src/memberships/update-membership.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,EAEL,KAAK,QAAQ,EACd,MAAM,4CAA4C,CAAC;AAKpD,KAAK,uBAAuB,GACxB;IACE,IAAI,EAAE,gBAAgB,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE;QACR,WAAW,EAAE,OAAO,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH,GACD;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,eAAe,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,eAAe,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,wBAAgB,uBAAuB,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,cAAc,IACvC,mFAM9B;IACD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,CACA;IAAE,kBAAkB,EAAE,IAAI,CAAC;IAAC,iBAAiB,EAAE,QAAQ,CAAA;CAAE,GACzD;IAAE,kBAAkB,CAAC,EAAE,KAAK,CAAC;IAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAA;CAAE,CAC/D,KAAG,OAAO,CAAC,uBAAuB,CAAC,CAkErC"}
|
|
@@ -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,69 @@ 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
|
+
changePassword: ({ encrypted_password, source, user_id, }: {
|
|
25
|
+
encrypted_password: string;
|
|
26
|
+
source: "reset_password" | "signup";
|
|
27
|
+
user_id: number;
|
|
28
|
+
}) => Promise<{
|
|
29
|
+
kind: "password_changed";
|
|
30
|
+
activity_id: number;
|
|
31
|
+
previous: {
|
|
32
|
+
email_verified: boolean;
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
connectFranceConnect: ({ user_id, user_info, }: {
|
|
36
|
+
user_id: number;
|
|
37
|
+
user_info: import("@proconnect-gouv/proconnect.identite/types").FranceConnectUserInfoResponse;
|
|
38
|
+
}) => Promise<{
|
|
39
|
+
kind: "franceconnect_connected";
|
|
40
|
+
activity_id: number;
|
|
41
|
+
connected_at: string;
|
|
42
|
+
user: {
|
|
43
|
+
family_name: string;
|
|
44
|
+
given_name: string;
|
|
45
|
+
};
|
|
46
|
+
} | {
|
|
47
|
+
kind: "user_not_found";
|
|
48
|
+
user_id: number;
|
|
49
|
+
}>;
|
|
50
|
+
deleteUser: ({ user_id, }: {
|
|
51
|
+
user_id: number;
|
|
52
|
+
}) => Promise<{
|
|
53
|
+
kind: "user_deleted";
|
|
54
|
+
activity_id: number;
|
|
55
|
+
previous: ActivityContexts["user.deleted"]["outcome"];
|
|
56
|
+
} | {
|
|
57
|
+
kind: "user_not_found";
|
|
58
|
+
user_id: number;
|
|
59
|
+
}>;
|
|
60
|
+
disconnectFranceConnect: ({ user_id, }: {
|
|
61
|
+
user_id: number;
|
|
62
|
+
}) => Promise<{
|
|
63
|
+
kind: "franceconnect_disconnected";
|
|
64
|
+
activity_id: number;
|
|
65
|
+
connected_at: string;
|
|
66
|
+
} | {
|
|
67
|
+
kind: "franceconnect_identity_not_found";
|
|
68
|
+
user_id: number;
|
|
69
|
+
}>;
|
|
7
70
|
markDomainAsVerified: ({ domain, domain_verification_type, organization_id, }: {
|
|
8
71
|
domain: string;
|
|
9
72
|
domain_verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainApprovedVerificationType;
|
|
@@ -24,9 +87,98 @@ export declare function createIdentiteRuntime<OwnContexts extends ContextMap & {
|
|
|
24
87
|
kind: "organization_not_found";
|
|
25
88
|
organization_id: number;
|
|
26
89
|
}>;
|
|
90
|
+
openModeration: ({ organization_id, sp_name, ticket_id, type, user_id, }: {
|
|
91
|
+
organization_id: number;
|
|
92
|
+
sp_name?: string | null;
|
|
93
|
+
ticket_id: string | null;
|
|
94
|
+
type: import("@proconnect-gouv/proconnect.identite/types").ModerationType;
|
|
95
|
+
user_id: number;
|
|
96
|
+
}) => Promise<{
|
|
97
|
+
kind: "moderation_opened";
|
|
98
|
+
activity_id: number;
|
|
99
|
+
moderation: {
|
|
100
|
+
id: number;
|
|
101
|
+
};
|
|
102
|
+
}>;
|
|
103
|
+
removeMembership: ({ organization_id, user_id, }: {
|
|
104
|
+
organization_id: number;
|
|
105
|
+
user_id: number;
|
|
106
|
+
}) => Promise<{
|
|
107
|
+
kind: "member_removed";
|
|
108
|
+
activity_id: number;
|
|
109
|
+
previous: {
|
|
110
|
+
is_external: boolean;
|
|
111
|
+
verification_type: string;
|
|
112
|
+
};
|
|
113
|
+
} | {
|
|
114
|
+
kind: "membership_not_found";
|
|
115
|
+
organization_id: number;
|
|
116
|
+
user_id: number;
|
|
117
|
+
}>;
|
|
27
118
|
record: (tx: IdentiteTransaction, activity: ActivityOf<OwnContexts> & ActivityTargets) => Promise<{
|
|
28
119
|
activity_id: number;
|
|
29
120
|
}>;
|
|
121
|
+
resetMfa: ({ user_id, }: {
|
|
122
|
+
user_id: number;
|
|
123
|
+
}) => Promise<{
|
|
124
|
+
kind: "mfa_reset";
|
|
125
|
+
activity_id: number;
|
|
126
|
+
previous: ActivityContexts["user.mfa_reset"]["outcome"]["previous"];
|
|
127
|
+
} | {
|
|
128
|
+
kind: "user_not_found";
|
|
129
|
+
user_id: number;
|
|
130
|
+
}>;
|
|
131
|
+
updateMembership: ({ is_external, organization_id, renew_verification, user_id, verification_type, }: {
|
|
132
|
+
is_external?: boolean;
|
|
133
|
+
organization_id: number;
|
|
134
|
+
user_id: number;
|
|
135
|
+
} & ({
|
|
136
|
+
renew_verification: true;
|
|
137
|
+
verification_type: import("@proconnect-gouv/proconnect.identite/types").LinkType;
|
|
138
|
+
} | {
|
|
139
|
+
renew_verification?: false;
|
|
140
|
+
verification_type?: import("@proconnect-gouv/proconnect.identite/types").LinkType;
|
|
141
|
+
})) => Promise<{
|
|
142
|
+
kind: "member_updated";
|
|
143
|
+
activity_id: number;
|
|
144
|
+
previous: {
|
|
145
|
+
is_external: boolean;
|
|
146
|
+
verification_type: string;
|
|
147
|
+
};
|
|
148
|
+
} | {
|
|
149
|
+
kind: "membership_not_found";
|
|
150
|
+
organization_id: number;
|
|
151
|
+
user_id: number;
|
|
152
|
+
} | {
|
|
153
|
+
kind: "membership_unchanged";
|
|
154
|
+
organization_id: number;
|
|
155
|
+
user_id: number;
|
|
156
|
+
}>;
|
|
157
|
+
updatePersonalInformations: ({ information, user_id, }: {
|
|
158
|
+
information: Partial<Pick<import("@proconnect-gouv/proconnect.identite/types").User, "family_name" | "given_name" | "job" | "phone_number">>;
|
|
159
|
+
user_id: number;
|
|
160
|
+
}) => Promise<{
|
|
161
|
+
kind: "info_changed";
|
|
162
|
+
activity_id: number;
|
|
163
|
+
next: {
|
|
164
|
+
given_name: string | null;
|
|
165
|
+
family_name: string | null;
|
|
166
|
+
phone_number: string | null;
|
|
167
|
+
job: string | null;
|
|
168
|
+
};
|
|
169
|
+
previous: {
|
|
170
|
+
given_name: string | null;
|
|
171
|
+
family_name: string | null;
|
|
172
|
+
phone_number: string | null;
|
|
173
|
+
job: string | null;
|
|
174
|
+
};
|
|
175
|
+
} | {
|
|
176
|
+
kind: "info_unchanged";
|
|
177
|
+
user_id: number;
|
|
178
|
+
} | {
|
|
179
|
+
kind: "user_not_found";
|
|
180
|
+
user_id: number;
|
|
181
|
+
}>;
|
|
30
182
|
};
|
|
31
183
|
};
|
|
32
184
|
//# 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;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;;uBAJwB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAnB/B,gCACI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAWU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;qBA0Bd,mBAAmB,YACb,UAAU,CAAC,WAAW,CAAC,GAAG,eAAe;;;;;;;;sBAtCxD,kCAAmC,WACpC;;;;;;uBAuBI,CAAA;;;;;;;8BAE2B,CAAC;6BAA0B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwB9D"}
|
|
@@ -1,13 +1,35 @@
|
|
|
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 { changePasswordFactory, deleteUserFactory, resetMfaFactory, updatePersonalInformationsFactory, } 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
|
+
changePassword: changePasswordFactory({ actor, app, db }),
|
|
15
|
+
connectFranceConnect: connectFranceConnectFactory({ actor, app, db }),
|
|
16
|
+
deleteUser: deleteUserFactory({ actor, app, db }),
|
|
17
|
+
disconnectFranceConnect: disconnectFranceConnectFactory({
|
|
18
|
+
actor,
|
|
19
|
+
app,
|
|
20
|
+
db,
|
|
21
|
+
}),
|
|
9
22
|
markDomainAsVerified: markDomainAsVerifiedFactory({ actor, app, db }),
|
|
23
|
+
openModeration: openModerationFactory({ actor, app, db }),
|
|
24
|
+
removeMembership: removeMembershipFactory({ actor, app, db }),
|
|
10
25
|
record: (tx, activity) => insertActivity(tx, { ...activity, actor, app }),
|
|
26
|
+
resetMfa: resetMfaFactory({ actor, app, db }),
|
|
27
|
+
updateMembership: updateMembershipFactory({ actor, app, db }),
|
|
28
|
+
updatePersonalInformations: updatePersonalInformationsFactory({
|
|
29
|
+
actor,
|
|
30
|
+
app,
|
|
31
|
+
db,
|
|
32
|
+
}),
|
|
11
33
|
};
|
|
12
34
|
},
|
|
13
35
|
};
|
|
@@ -0,0 +1,62 @@
|
|
|
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.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>;
|
|
34
|
+
"user.mfa_reset": z.ZodObject<{
|
|
35
|
+
inputs: z.ZodObject<{
|
|
36
|
+
user_id: z.ZodNumber;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
outcome: z.ZodObject<{
|
|
39
|
+
previous: z.ZodObject<{
|
|
40
|
+
authenticators: z.ZodNumber;
|
|
41
|
+
email_verified: z.ZodBoolean;
|
|
42
|
+
force_2fa: z.ZodBoolean;
|
|
43
|
+
password_configured: z.ZodBoolean;
|
|
44
|
+
totp_configured: z.ZodBoolean;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
}, z.core.$strip>;
|
|
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>;
|
|
61
|
+
};
|
|
62
|
+
//# 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;AAWzB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8C1B,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//
|
|
2
|
+
import * as z from "zod";
|
|
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
|
+
});
|
|
10
|
+
export const userActivities = {
|
|
11
|
+
"user.deleted": z.object({
|
|
12
|
+
inputs: z.object({
|
|
13
|
+
user_id: z.number(),
|
|
14
|
+
}),
|
|
15
|
+
outcome: z.object({
|
|
16
|
+
email: z.string(),
|
|
17
|
+
family_name: z.string().nullable(),
|
|
18
|
+
given_name: z.string().nullable(),
|
|
19
|
+
memberships: z.array(z.object({
|
|
20
|
+
is_external: z.boolean(),
|
|
21
|
+
organization_id: z.number(),
|
|
22
|
+
verification_type: z.string(),
|
|
23
|
+
})),
|
|
24
|
+
}),
|
|
25
|
+
}),
|
|
26
|
+
"user.info_changed": z.object({
|
|
27
|
+
inputs: userInformation,
|
|
28
|
+
outcome: z.object({
|
|
29
|
+
previous: userInformation,
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
"user.mfa_reset": z.object({
|
|
33
|
+
inputs: z.object({
|
|
34
|
+
user_id: z.number(),
|
|
35
|
+
}),
|
|
36
|
+
outcome: z.object({
|
|
37
|
+
previous: z.object({
|
|
38
|
+
authenticators: z.number(),
|
|
39
|
+
email_verified: z.boolean(),
|
|
40
|
+
force_2fa: z.boolean(),
|
|
41
|
+
password_configured: z.boolean(),
|
|
42
|
+
totp_configured: z.boolean(),
|
|
43
|
+
}),
|
|
44
|
+
}),
|
|
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
|
+
}),
|
|
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
|
+
}
|
|
@@ -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"}
|