@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,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,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mCAAmC,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
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RuntimeContext } from "#src/activity";
|
|
2
|
+
import type { User } from "@proconnect-gouv/proconnect.identite/types";
|
|
3
|
+
type PersonalInformation = Pick<User, "family_name" | "given_name" | "job" | "phone_number">;
|
|
4
|
+
type UpdatePersonalInformationsOutcome = {
|
|
5
|
+
kind: "info_changed";
|
|
6
|
+
activity_id: number;
|
|
7
|
+
next: PersonalInformation;
|
|
8
|
+
previous: PersonalInformation;
|
|
9
|
+
} | {
|
|
10
|
+
kind: "info_unchanged";
|
|
11
|
+
user_id: number;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "user_not_found";
|
|
14
|
+
user_id: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function updatePersonalInformationsFactory({ actor, app, db, }: RuntimeContext): ({ information, user_id, }: {
|
|
17
|
+
information: Partial<Pick<User, "family_name" | "given_name" | "job" | "phone_number">>;
|
|
18
|
+
user_id: number;
|
|
19
|
+
}) => Promise<UpdatePersonalInformationsOutcome>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=update-personal-informations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-personal-informations.d.ts","sourceRoot":"","sources":["../../src/users/update-personal-informations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AAKvE,KAAK,mBAAmB,GAAG,IAAI,CAC7B,IAAI,EACJ,aAAa,GAAG,YAAY,GAAG,KAAK,GAAG,cAAc,CACtD,CAAC;AAEF,KAAK,iCAAiC,GAClC;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,mBAAmB,CAAC;IAC1B,QAAQ,EAAE,mBAAmB,CAAC;CAC/B,GACD;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,wBAAgB,iCAAiC,CAAC,EAChD,KAAK,EACL,GAAG,EACH,EAAE,GACH,EAAE,cAAc,IAC4B,2BAGxC;IACD,WAAW,EAAE,OAAO,CAClB,IAAI,CAAC,IAAI,EAAE,aAAa,GAAG,YAAY,GAAG,KAAK,GAAG,cAAc,CAAC,CAClE,CAAC;IACF,OAAO,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,iCAAiC,CAAC,CA0D/C"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { users } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { eq, sql } from "drizzle-orm";
|
|
5
|
+
export function updatePersonalInformationsFactory({ actor, app, db, }) {
|
|
6
|
+
return function updatePersonalInformations({ information, user_id, }) {
|
|
7
|
+
return db.transaction(async (tx) => {
|
|
8
|
+
const [previous] = await tx
|
|
9
|
+
.select({
|
|
10
|
+
family_name: users.family_name,
|
|
11
|
+
given_name: users.given_name,
|
|
12
|
+
job: users.job,
|
|
13
|
+
phone_number: users.phone_number,
|
|
14
|
+
})
|
|
15
|
+
.from(users)
|
|
16
|
+
.where(eq(users.id, user_id))
|
|
17
|
+
.for("update");
|
|
18
|
+
if (!previous) {
|
|
19
|
+
return { kind: "user_not_found", user_id };
|
|
20
|
+
}
|
|
21
|
+
const next = {
|
|
22
|
+
family_name: information.family_name !== undefined
|
|
23
|
+
? information.family_name
|
|
24
|
+
: previous.family_name,
|
|
25
|
+
given_name: information.given_name !== undefined
|
|
26
|
+
? information.given_name
|
|
27
|
+
: previous.given_name,
|
|
28
|
+
job: information.job !== undefined ? information.job : previous.job,
|
|
29
|
+
phone_number: information.phone_number !== undefined
|
|
30
|
+
? information.phone_number
|
|
31
|
+
: previous.phone_number,
|
|
32
|
+
};
|
|
33
|
+
if (next.family_name === previous.family_name &&
|
|
34
|
+
next.given_name === previous.given_name &&
|
|
35
|
+
next.job === previous.job &&
|
|
36
|
+
next.phone_number === previous.phone_number) {
|
|
37
|
+
return { kind: "info_unchanged", user_id };
|
|
38
|
+
}
|
|
39
|
+
await tx
|
|
40
|
+
.update(users)
|
|
41
|
+
.set({ ...next, updated_at: sql `now()` })
|
|
42
|
+
.where(eq(users.id, user_id));
|
|
43
|
+
const { activity_id } = await insertActivity(tx, {
|
|
44
|
+
action: "user.info_changed",
|
|
45
|
+
actor,
|
|
46
|
+
app,
|
|
47
|
+
context: { inputs: next, outcome: { previous } },
|
|
48
|
+
user_id,
|
|
49
|
+
});
|
|
50
|
+
return { kind: "info_changed", activity_id, next, previous };
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite.runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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,8 +32,8 @@
|
|
|
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.database": "^
|
|
35
|
+
"@proconnect-gouv/proconnect.identite": "^15.0.0",
|
|
36
|
+
"@proconnect-gouv/proconnect.identite.database": "^2.0.0",
|
|
36
37
|
"zod": "^4.6.7"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
@@ -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
|
|