@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @proconnect-gouv/proconnect.identite.runtime
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#2407](https://github.com/proconnect-gouv/proconnect-identite/pull/2407) [`c801a10`](https://github.com/proconnect-gouv/proconnect-identite/commit/c801a108fd71b38f179dd2e21f62fc440e56fee6) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute la commande `updatePersonalInformations` et le schéma `user.info_changed` : le changement de nom, téléphone ou fonction est journalisé avec les valeurs précédentes, et une demande sans changement n'écrit rien.
|
|
8
|
+
|
|
9
|
+
- [#2408](https://github.com/proconnect-gouv/proconnect-identite/pull/2408) [`478e680`](https://github.com/proconnect-gouv/proconnect-identite/commit/478e680e7f83f4c24f37e84f9134856dbaa753a2) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute la commande `changePassword` et le schéma `user.password_changed` : un mot de passe défini à la réinitialisation ou à l'inscription est journalisé avec l'état précédent, sans jamais écrire le mot de passe ni son empreinte.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`c1167a1`](https://github.com/proconnect-gouv/proconnect-identite/commit/c1167a150b16060ca704059e98040414bbf7a009), [`33604f3`](https://github.com/proconnect-gouv/proconnect-identite/commit/33604f32fb4393ec60e413f0b7bace8e94ac22fc), [`c1167a1`](https://github.com/proconnect-gouv/proconnect-identite/commit/c1167a150b16060ca704059e98040414bbf7a009)]:
|
|
14
|
+
- @proconnect-gouv/proconnect.identite.database@2.0.0
|
|
15
|
+
- @proconnect-gouv/proconnect.identite@15.0.0
|
|
16
|
+
|
|
17
|
+
## 0.4.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- [#2387](https://github.com/proconnect-gouv/proconnect-identite/pull/2387) [`e4b4789`](https://github.com/proconnect-gouv/proconnect-identite/commit/e4b4789b5eb0ad01d9b4ce216fe81cce40a2c70b) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute la commande `addMembership` : elle crée, dans une seule transaction, le rattachement d'un utilisateur à une organisation et journalise l'action `member.joined` sous l'acteur reçu, avec le `verification_type` et l'`is_external` dans `inputs`. Elle renvoie l'issue `member_joined` (avec `activity_id` et le rattachement) ou `member_already_exists` (avec `organization_id` et `user_id`, sans rien écrire ni modifier le rattachement existant).
|
|
22
|
+
|
|
23
|
+
- [#2389](https://github.com/proconnect-gouv/proconnect-identite/pull/2389) [`cc30f4f`](https://github.com/proconnect-gouv/proconnect-identite/commit/cc30f4f98277b7833b7ca5949f5617916be3b2e2) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute la commande `deleteUser` : elle supprime, dans une seule transaction, le compte d'un utilisateur et journalise l'action `user.deleted` sous l'acteur reçu, avec dans `inputs` l'entrée de la commande (`user_id`) et dans `outcome` son résultat : l'email, le prénom et le nom du compte supprimé ainsi que ses rattachements (`organization_id`, `is_external`, `verification_type`) supprimés avec lui. La ligne reste lisible après la suppression : `activity_logs` n'a pas de clé étrangère vers `users`. Elle renvoie l'issue `user_deleted` (avec `previous` et `activity_id`) ou `user_not_found` (avec `user_id`, sans rien écrire).
|
|
24
|
+
|
|
25
|
+
- [#2386](https://github.com/proconnect-gouv/proconnect-identite/pull/2386) [`0791585`](https://github.com/proconnect-gouv/proconnect-identite/commit/0791585ecd627035cb1a633dbc20956a08f58ad7) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute les commandes `connectFranceConnect` et `disconnectFranceConnect` : elles lient ou délie, dans une seule transaction, l'identité FranceConnect d'un utilisateur et journalisent `franceconnect.connected` ou `franceconnect.disconnected` sous l'acteur reçu, avec `inputs` vide et, dans `outcome`, la date de création du rattachement FranceConnect. `connectFranceConnect` recopie aussi les noms FranceConnect sur l'utilisateur ; elle renvoie l'issue `franceconnect_connected` (avec `activity_id`, `connected_at` et les noms posés) ou `user_not_found`. `disconnectFranceConnect` renvoie `franceconnect_disconnected` (avec `activity_id` et `connected_at`) ou `franceconnect_identity_not_found`, sans rien écrire.
|
|
26
|
+
|
|
27
|
+
- [#2390](https://github.com/proconnect-gouv/proconnect-identite/pull/2390) [`03426c3`](https://github.com/proconnect-gouv/proconnect-identite/commit/03426c325f3439e0ee9587a2088d51e62589fe04) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute la commande `openModeration` : elle crée, dans une seule transaction, une modération en attente (`pending`) et journalise l'action `moderation.opened` sous l'acteur reçu, avec le `type` de modération et le `sp_name` dans `inputs`, et les colonnes `moderation_id`, `organization_id` et `user_id` renseignées. Elle renvoie l'issue `moderation_opened` (avec `activity_id` et l'`id` de la modération).
|
|
28
|
+
|
|
29
|
+
- [#2384](https://github.com/proconnect-gouv/proconnect-identite/pull/2384) [`27b202a`](https://github.com/proconnect-gouv/proconnect-identite/commit/27b202a9a33f7143c9e62e4831e24341ce320749) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute la commande `removeMembership` : elle supprime, dans une seule transaction, le rattachement d'un utilisateur à une organisation et journalise l'action `member.removed` sous l'acteur reçu, avec `inputs` vide et, dans `outcome`, le `is_external` et le `verification_type` du rattachement supprimé. Elle renvoie l'issue `member_removed` (avec `previous` et `activity_id`) ou `membership_not_found` (avec `organization_id` et `user_id`, sans rien écrire). Le type `Actor` accepte `{ type: "user", user_id }`, journalisé avec `actor_type` `user` et `actor_ref` égal à l'identifiant.
|
|
30
|
+
|
|
31
|
+
- [#2392](https://github.com/proconnect-gouv/proconnect-identite/pull/2392) [`3c541dd`](https://github.com/proconnect-gouv/proconnect-identite/commit/3c541dd8fe07ef45e11339c3d07e796c9e2b9f41) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute la commande `resetMfa` : elle réinitialise, dans une seule transaction, l'accès d'un utilisateur — suppression de ses clés d'accès (`authenticators`), clé TOTP effacée, mot de passe effacé, email marqué non vérifié, `force_2fa` désactivé — et journalise l'action `user.mfa_reset` sous l'acteur reçu, avec dans `inputs` l'identifiant de l'utilisateur et dans `outcome.previous` l'état d'avant (nombre de clés d'accès, email vérifié, mot de passe configuré, clé TOTP configurée, `force_2fa`). Elle renvoie l'issue `mfa_reset` (avec `previous` et `activity_id`) ou `user_not_found` (avec `user_id`, sans rien écrire).
|
|
32
|
+
|
|
33
|
+
- [#2391](https://github.com/proconnect-gouv/proconnect-identite/pull/2391) [`c8d53f1`](https://github.com/proconnect-gouv/proconnect-identite/commit/c8d53f17eeb1b0caff4b5e9031f7cee2b31dec1b) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Ajoute la commande `updateMembership` : elle modifie, dans une seule transaction, le `is_external` et/ou le `verification_type` du rattachement d'un utilisateur à une organisation et journalise l'action `member.updated` sous l'acteur reçu, avec dans `inputs` les champs demandés et dans `outcome.previous` le `is_external` et le `verification_type` d'avant. Un nouveau `verification_type` remet `verified_at` à maintenant, ou à `null` pour `domain_not_verified_yet` ; `renew_verification: true` le remet à maintenant même quand le `verification_type` ne change pas (renouvellement d'une certification). Elle renvoie l'issue `member_updated` (avec `previous` et `activity_id`), `membership_unchanged` si rien ne change, ou `membership_not_found` (avec `organization_id` et `user_id`) ; ces deux dernières n'écrivent rien.
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [[`e4b4789`](https://github.com/proconnect-gouv/proconnect-identite/commit/e4b4789b5eb0ad01d9b4ce216fe81cce40a2c70b), [`03426c3`](https://github.com/proconnect-gouv/proconnect-identite/commit/03426c325f3439e0ee9587a2088d51e62589fe04), [`cc30f4f`](https://github.com/proconnect-gouv/proconnect-identite/commit/cc30f4f98277b7833b7ca5949f5617916be3b2e2), [`0791585`](https://github.com/proconnect-gouv/proconnect-identite/commit/0791585ecd627035cb1a633dbc20956a08f58ad7), [`27b202a`](https://github.com/proconnect-gouv/proconnect-identite/commit/27b202a9a33f7143c9e62e4831e24341ce320749), [`c8d53f1`](https://github.com/proconnect-gouv/proconnect-identite/commit/c8d53f17eeb1b0caff4b5e9031f7cee2b31dec1b)]:
|
|
38
|
+
- @proconnect-gouv/proconnect.identite@14.0.0
|
|
39
|
+
|
|
3
40
|
## 0.3.1
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
|
@@ -1,5 +1,77 @@
|
|
|
1
1
|
import type { ContextsOf } from "./types.js";
|
|
2
2
|
export declare const activityContextSchemas: {
|
|
3
|
+
"user.deleted": import("zod").ZodObject<{
|
|
4
|
+
inputs: import("zod").ZodObject<{
|
|
5
|
+
user_id: import("zod").ZodNumber;
|
|
6
|
+
}, import("zod/v4/core").$strip>;
|
|
7
|
+
outcome: import("zod").ZodObject<{
|
|
8
|
+
email: import("zod").ZodString;
|
|
9
|
+
family_name: import("zod").ZodNullable<import("zod").ZodString>;
|
|
10
|
+
given_name: import("zod").ZodNullable<import("zod").ZodString>;
|
|
11
|
+
memberships: import("zod").ZodArray<import("zod").ZodObject<{
|
|
12
|
+
is_external: import("zod").ZodBoolean;
|
|
13
|
+
organization_id: import("zod").ZodNumber;
|
|
14
|
+
verification_type: import("zod").ZodString;
|
|
15
|
+
}, import("zod/v4/core").$strip>>;
|
|
16
|
+
}, import("zod/v4/core").$strip>;
|
|
17
|
+
}, import("zod/v4/core").$strip>;
|
|
18
|
+
"user.info_changed": import("zod").ZodObject<{
|
|
19
|
+
inputs: import("zod").ZodObject<{
|
|
20
|
+
family_name: import("zod").ZodNullable<import("zod").ZodString>;
|
|
21
|
+
given_name: import("zod").ZodNullable<import("zod").ZodString>;
|
|
22
|
+
job: import("zod").ZodNullable<import("zod").ZodString>;
|
|
23
|
+
phone_number: import("zod").ZodNullable<import("zod").ZodString>;
|
|
24
|
+
}, import("zod/v4/core").$strip>;
|
|
25
|
+
outcome: import("zod").ZodObject<{
|
|
26
|
+
previous: import("zod").ZodObject<{
|
|
27
|
+
family_name: import("zod").ZodNullable<import("zod").ZodString>;
|
|
28
|
+
given_name: import("zod").ZodNullable<import("zod").ZodString>;
|
|
29
|
+
job: import("zod").ZodNullable<import("zod").ZodString>;
|
|
30
|
+
phone_number: import("zod").ZodNullable<import("zod").ZodString>;
|
|
31
|
+
}, import("zod/v4/core").$strip>;
|
|
32
|
+
}, import("zod/v4/core").$strip>;
|
|
33
|
+
}, import("zod/v4/core").$strip>;
|
|
34
|
+
"user.mfa_reset": import("zod").ZodObject<{
|
|
35
|
+
inputs: import("zod").ZodObject<{
|
|
36
|
+
user_id: import("zod").ZodNumber;
|
|
37
|
+
}, import("zod/v4/core").$strip>;
|
|
38
|
+
outcome: import("zod").ZodObject<{
|
|
39
|
+
previous: import("zod").ZodObject<{
|
|
40
|
+
authenticators: import("zod").ZodNumber;
|
|
41
|
+
email_verified: import("zod").ZodBoolean;
|
|
42
|
+
force_2fa: import("zod").ZodBoolean;
|
|
43
|
+
password_configured: import("zod").ZodBoolean;
|
|
44
|
+
totp_configured: import("zod").ZodBoolean;
|
|
45
|
+
}, import("zod/v4/core").$strip>;
|
|
46
|
+
}, import("zod/v4/core").$strip>;
|
|
47
|
+
}, import("zod/v4/core").$strip>;
|
|
48
|
+
"user.password_changed": import("zod").ZodObject<{
|
|
49
|
+
inputs: import("zod").ZodObject<{
|
|
50
|
+
source: import("zod").ZodEnum<{
|
|
51
|
+
reset_password: "reset_password";
|
|
52
|
+
signup: "signup";
|
|
53
|
+
}>;
|
|
54
|
+
}, import("zod/v4/core").$strip>;
|
|
55
|
+
outcome: import("zod").ZodObject<{
|
|
56
|
+
previous: import("zod").ZodObject<{
|
|
57
|
+
email_verified: import("zod").ZodBoolean;
|
|
58
|
+
}, import("zod/v4/core").$strip>;
|
|
59
|
+
}, import("zod/v4/core").$strip>;
|
|
60
|
+
}, import("zod/v4/core").$strip>;
|
|
61
|
+
"moderation.opened": import("zod").ZodObject<{
|
|
62
|
+
inputs: import("zod").ZodObject<{
|
|
63
|
+
sp_name: import("zod").ZodNullable<import("zod").ZodString>;
|
|
64
|
+
type: import("zod").ZodString;
|
|
65
|
+
}, import("zod/v4/core").$strip>;
|
|
66
|
+
outcome: import("zod").ZodObject<{}, import("zod/v4/core").$strip>;
|
|
67
|
+
}, import("zod/v4/core").$strip>;
|
|
68
|
+
"member.joined": import("zod").ZodObject<{
|
|
69
|
+
inputs: import("zod").ZodObject<{
|
|
70
|
+
is_external: import("zod").ZodBoolean;
|
|
71
|
+
verification_type: import("zod").ZodString;
|
|
72
|
+
}, import("zod/v4/core").$strip>;
|
|
73
|
+
outcome: import("zod").ZodObject<{}, import("zod/v4/core").$strip>;
|
|
74
|
+
}, import("zod/v4/core").$strip>;
|
|
3
75
|
"member.promoted": import("zod").ZodObject<{
|
|
4
76
|
inputs: import("zod").ZodObject<{
|
|
5
77
|
previous_verification_type: import("zod").ZodString;
|
|
@@ -26,6 +98,38 @@ export declare const activityContextSchemas: {
|
|
|
26
98
|
}>;
|
|
27
99
|
}, import("zod/v4/core").$strip>;
|
|
28
100
|
}, import("zod/v4/core").$strip>;
|
|
101
|
+
"member.removed": import("zod").ZodObject<{
|
|
102
|
+
inputs: import("zod").ZodObject<{}, import("zod/v4/core").$strip>;
|
|
103
|
+
outcome: import("zod").ZodObject<{
|
|
104
|
+
is_external: import("zod").ZodBoolean;
|
|
105
|
+
verification_type: import("zod").ZodString;
|
|
106
|
+
}, import("zod/v4/core").$strip>;
|
|
107
|
+
}, import("zod/v4/core").$strip>;
|
|
108
|
+
"member.updated": import("zod").ZodObject<{
|
|
109
|
+
inputs: import("zod").ZodObject<{
|
|
110
|
+
is_external: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
111
|
+
renew_verification: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
112
|
+
verification_type: import("zod").ZodOptional<import("zod").ZodString>;
|
|
113
|
+
}, import("zod/v4/core").$strip>;
|
|
114
|
+
outcome: import("zod").ZodObject<{
|
|
115
|
+
previous: import("zod").ZodObject<{
|
|
116
|
+
is_external: import("zod").ZodBoolean;
|
|
117
|
+
verification_type: import("zod").ZodString;
|
|
118
|
+
}, import("zod/v4/core").$strip>;
|
|
119
|
+
}, import("zod/v4/core").$strip>;
|
|
120
|
+
}, import("zod/v4/core").$strip>;
|
|
121
|
+
"franceconnect.connected": import("zod").ZodObject<{
|
|
122
|
+
inputs: import("zod").ZodObject<{}, import("zod/v4/core").$strip>;
|
|
123
|
+
outcome: import("zod").ZodObject<{
|
|
124
|
+
connected_at: import("zod").ZodString;
|
|
125
|
+
}, import("zod/v4/core").$strip>;
|
|
126
|
+
}, import("zod/v4/core").$strip>;
|
|
127
|
+
"franceconnect.disconnected": import("zod").ZodObject<{
|
|
128
|
+
inputs: import("zod").ZodObject<{}, import("zod/v4/core").$strip>;
|
|
129
|
+
outcome: import("zod").ZodObject<{
|
|
130
|
+
connected_at: import("zod").ZodString;
|
|
131
|
+
}, import("zod/v4/core").$strip>;
|
|
132
|
+
}, import("zod/v4/core").$strip>;
|
|
29
133
|
"domain.verified": import("zod").ZodObject<{
|
|
30
134
|
inputs: import("zod").ZodObject<{
|
|
31
135
|
domain: import("zod").ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activity-context-schemas.d.ts","sourceRoot":"","sources":["../../src/activity/activity-context-schemas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"activity-context-schemas.d.ts","sourceRoot":"","sources":["../../src/activity/activity-context-schemas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI7C,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAMlC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
//
|
|
2
2
|
import { domainActivities } from "#src/domains";
|
|
3
|
+
import { franceconnectActivities } from "#src/franceconnect";
|
|
3
4
|
import { membershipActivities } from "#src/memberships";
|
|
5
|
+
import { moderationActivities } from "#src/moderations";
|
|
6
|
+
import { userActivities } from "#src/users";
|
|
4
7
|
//
|
|
5
8
|
export const activityContextSchemas = {
|
|
6
9
|
...domainActivities,
|
|
10
|
+
...franceconnectActivities,
|
|
7
11
|
...membershipActivities,
|
|
12
|
+
...moderationActivities,
|
|
13
|
+
...userActivities,
|
|
8
14
|
};
|
package/dist/activity/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/activity/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAC;AAI9B,MAAM,MAAM,KAAK,GACb;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/activity/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAC;AAI9B,MAAM,MAAM,KAAK,GACb;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,MAAM,MAAM,GAAG,GAAG,aAAa,GAAG,qBAAqB,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;IACT,EAAE,EAAE,gBAAgB,CAAC;CACtB,CAAC;AAEF,KAAK,YAAY,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE1D,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAEtD,MAAM,MAAM,UAAU,CACpB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,IACrD;KAAG,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;CAAE,CAAC;AAE5D,MAAM,MAAM,UAAU,CAAC,QAAQ,SAAS,UAAU,IAAI;KACnD,MAAM,IAAI,MAAM,QAAQ,GAAG,MAAM,GAAG;QACnC,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;KAC3B;CACF,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC;AAE3B,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const franceconnectActivities: {
|
|
3
|
+
"franceconnect.connected": z.ZodObject<{
|
|
4
|
+
inputs: z.ZodObject<{}, z.core.$strip>;
|
|
5
|
+
outcome: z.ZodObject<{
|
|
6
|
+
connected_at: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
"franceconnect.disconnected": z.ZodObject<{
|
|
10
|
+
inputs: z.ZodObject<{}, z.core.$strip>;
|
|
11
|
+
outcome: z.ZodObject<{
|
|
12
|
+
connected_at: z.ZodString;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=activities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/franceconnect/activities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;CAanC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//
|
|
4
|
+
export const franceconnectActivities = {
|
|
5
|
+
"franceconnect.connected": z.object({
|
|
6
|
+
inputs: z.object({}),
|
|
7
|
+
outcome: z.object({
|
|
8
|
+
connected_at: z.string(),
|
|
9
|
+
}),
|
|
10
|
+
}),
|
|
11
|
+
"franceconnect.disconnected": z.object({
|
|
12
|
+
inputs: z.object({}),
|
|
13
|
+
outcome: z.object({
|
|
14
|
+
connected_at: z.string(),
|
|
15
|
+
}),
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RuntimeContext } from "#src/activity";
|
|
2
|
+
import type { FranceConnectUserInfoResponse } from "@proconnect-gouv/proconnect.identite/types";
|
|
3
|
+
type ConnectFranceConnectOutcome = {
|
|
4
|
+
kind: "franceconnect_connected";
|
|
5
|
+
activity_id: number;
|
|
6
|
+
connected_at: string;
|
|
7
|
+
user: {
|
|
8
|
+
family_name: string;
|
|
9
|
+
given_name: string;
|
|
10
|
+
};
|
|
11
|
+
} | {
|
|
12
|
+
kind: "user_not_found";
|
|
13
|
+
user_id: number;
|
|
14
|
+
};
|
|
15
|
+
export declare function connectFranceConnectFactory({ actor, app, db, }: RuntimeContext): ({ user_id, user_info, }: {
|
|
16
|
+
user_id: number;
|
|
17
|
+
user_info: FranceConnectUserInfoResponse;
|
|
18
|
+
}) => Promise<ConnectFranceConnectOutcome>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=connect-franceconnect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-franceconnect.d.ts","sourceRoot":"","sources":["../../src/franceconnect/connect-franceconnect.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAMtE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,4CAA4C,CAAC;AAKhG,KAAK,2BAA2B,GAC5B;IACE,IAAI,EAAE,yBAAyB,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE;QACJ,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,GACD;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,wBAAgB,2BAA2B,CAAC,EAC1C,KAAK,EACL,GAAG,EACH,EAAE,GACH,EAAE,cAAc,IACsB,yBAGlC;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,6BAA6B,CAAC;CAC1C,KAAG,OAAO,CAAC,2BAA2B,CAAC,CA2DzC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { franceconnect_userinfo, users, } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { eq, sql } from "drizzle-orm";
|
|
5
|
+
export function connectFranceConnectFactory({ actor, app, db, }) {
|
|
6
|
+
return function connectFranceConnect({ user_id, user_info, }) {
|
|
7
|
+
return db.transaction(async (tx) => {
|
|
8
|
+
const user = await tx.query.users.findFirst({
|
|
9
|
+
columns: { id: true },
|
|
10
|
+
where: (table, { eq }) => eq(table.id, user_id),
|
|
11
|
+
});
|
|
12
|
+
if (!user) {
|
|
13
|
+
return { kind: "user_not_found", user_id };
|
|
14
|
+
}
|
|
15
|
+
const given_name = user_info.given_name.split(" ")[0];
|
|
16
|
+
const family_name = user_info.preferred_username || user_info.family_name;
|
|
17
|
+
await tx
|
|
18
|
+
.update(users)
|
|
19
|
+
.set({ family_name, given_name, updated_at: sql `now()` })
|
|
20
|
+
.where(eq(users.id, user_id));
|
|
21
|
+
const identity = {
|
|
22
|
+
birthcountry: user_info.birthcountry,
|
|
23
|
+
birthdate: user_info.birthdate.toISOString(),
|
|
24
|
+
birthplace: user_info.birthplace,
|
|
25
|
+
family_name: user_info.family_name,
|
|
26
|
+
gender: user_info.gender,
|
|
27
|
+
given_name: user_info.given_name,
|
|
28
|
+
preferred_username: user_info.preferred_username,
|
|
29
|
+
sub: user_info.sub,
|
|
30
|
+
updated_at: sql `now()`,
|
|
31
|
+
user_id,
|
|
32
|
+
};
|
|
33
|
+
const [franceconnect_identity] = await tx
|
|
34
|
+
.insert(franceconnect_userinfo)
|
|
35
|
+
.values(identity)
|
|
36
|
+
.onConflictDoUpdate({
|
|
37
|
+
target: franceconnect_userinfo.user_id,
|
|
38
|
+
set: identity,
|
|
39
|
+
})
|
|
40
|
+
.returning({ created_at: franceconnect_userinfo.created_at });
|
|
41
|
+
const { activity_id } = await insertActivity(tx, {
|
|
42
|
+
action: "franceconnect.connected",
|
|
43
|
+
actor,
|
|
44
|
+
app,
|
|
45
|
+
context: {
|
|
46
|
+
inputs: {},
|
|
47
|
+
outcome: { connected_at: franceconnect_identity.created_at },
|
|
48
|
+
},
|
|
49
|
+
user_id,
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
kind: "franceconnect_connected",
|
|
53
|
+
activity_id,
|
|
54
|
+
connected_at: franceconnect_identity.created_at,
|
|
55
|
+
user: { family_name, given_name },
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RuntimeContext } from "#src/activity";
|
|
2
|
+
type DisconnectFranceConnectOutcome = {
|
|
3
|
+
kind: "franceconnect_disconnected";
|
|
4
|
+
activity_id: number;
|
|
5
|
+
connected_at: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "franceconnect_identity_not_found";
|
|
8
|
+
user_id: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function disconnectFranceConnectFactory({ actor, app, db, }: RuntimeContext): ({ user_id, }: {
|
|
11
|
+
user_id: number;
|
|
12
|
+
}) => Promise<DisconnectFranceConnectOutcome>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=disconnect-franceconnect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disconnect-franceconnect.d.ts","sourceRoot":"","sources":["../../src/franceconnect/disconnect-franceconnect.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAOtE,KAAK,8BAA8B,GAC/B;IACE,IAAI,EAAE,4BAA4B,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,GACD;IAAE,IAAI,EAAE,kCAAkC,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,wBAAgB,8BAA8B,CAAC,EAC7C,KAAK,EACL,GAAG,EACH,EAAE,GACH,EAAE,cAAc,IACyB,cAErC;IACD,OAAO,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,8BAA8B,CAAC,CA0B5C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { franceconnect_userinfo } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { eq } from "drizzle-orm";
|
|
5
|
+
export function disconnectFranceConnectFactory({ actor, app, db, }) {
|
|
6
|
+
return function disconnectFranceConnect({ user_id, }) {
|
|
7
|
+
return db.transaction(async (tx) => {
|
|
8
|
+
const [previous] = await tx
|
|
9
|
+
.delete(franceconnect_userinfo)
|
|
10
|
+
.where(eq(franceconnect_userinfo.user_id, user_id))
|
|
11
|
+
.returning({ created_at: franceconnect_userinfo.created_at });
|
|
12
|
+
if (!previous) {
|
|
13
|
+
return { kind: "franceconnect_identity_not_found", user_id };
|
|
14
|
+
}
|
|
15
|
+
const { activity_id } = await insertActivity(tx, {
|
|
16
|
+
action: "franceconnect.disconnected",
|
|
17
|
+
actor,
|
|
18
|
+
app,
|
|
19
|
+
context: { inputs: {}, outcome: { connected_at: previous.created_at } },
|
|
20
|
+
user_id,
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
kind: "franceconnect_disconnected",
|
|
24
|
+
activity_id,
|
|
25
|
+
connected_at: previous.created_at,
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/franceconnect/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC"}
|
|
@@ -14,6 +14,12 @@ function toActorColumns({ actor, app }) {
|
|
|
14
14
|
return { actor_ref: actor.job, actor_type: "app", app };
|
|
15
15
|
case "moderator":
|
|
16
16
|
return { actor_ref: actor.sub, actor_type: "moderator", app };
|
|
17
|
+
case "user":
|
|
18
|
+
return {
|
|
19
|
+
actor_ref: String(actor.user_id),
|
|
20
|
+
actor_type: "user",
|
|
21
|
+
app,
|
|
22
|
+
};
|
|
17
23
|
default: {
|
|
18
24
|
const unhandled_actor = actor;
|
|
19
25
|
throw new Error(`Unhandled actor: ${JSON.stringify(unhandled_actor)}`);
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
2
|
export declare const membershipActivities: {
|
|
3
|
+
"member.joined": z.ZodObject<{
|
|
4
|
+
inputs: z.ZodObject<{
|
|
5
|
+
is_external: z.ZodBoolean;
|
|
6
|
+
verification_type: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
outcome: z.ZodObject<{}, z.core.$strip>;
|
|
9
|
+
}, z.core.$strip>;
|
|
3
10
|
"member.promoted": z.ZodObject<{
|
|
4
11
|
inputs: z.ZodObject<{
|
|
5
12
|
previous_verification_type: z.ZodString;
|
|
@@ -26,5 +33,25 @@ export declare const membershipActivities: {
|
|
|
26
33
|
}>;
|
|
27
34
|
}, z.core.$strip>;
|
|
28
35
|
}, z.core.$strip>;
|
|
36
|
+
"member.removed": z.ZodObject<{
|
|
37
|
+
inputs: z.ZodObject<{}, z.core.$strip>;
|
|
38
|
+
outcome: z.ZodObject<{
|
|
39
|
+
is_external: z.ZodBoolean;
|
|
40
|
+
verification_type: z.ZodString;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
"member.updated": z.ZodObject<{
|
|
44
|
+
inputs: z.ZodObject<{
|
|
45
|
+
is_external: z.ZodOptional<z.ZodBoolean>;
|
|
46
|
+
renew_verification: z.ZodOptional<z.ZodBoolean>;
|
|
47
|
+
verification_type: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
outcome: z.ZodObject<{
|
|
50
|
+
previous: z.ZodObject<{
|
|
51
|
+
is_external: z.ZodBoolean;
|
|
52
|
+
verification_type: z.ZodString;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
}, z.core.$strip>;
|
|
29
56
|
};
|
|
30
57
|
//# sourceMappingURL=activities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/memberships/activities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,oBAAoB
|
|
1
|
+
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/memberships/activities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoChC,CAAC"}
|
|
@@ -3,6 +3,13 @@ import { LinkEnum } from "@proconnect-gouv/proconnect.identite/types";
|
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
//
|
|
5
5
|
export const membershipActivities = {
|
|
6
|
+
"member.joined": z.object({
|
|
7
|
+
inputs: z.object({
|
|
8
|
+
is_external: z.boolean(),
|
|
9
|
+
verification_type: z.string(),
|
|
10
|
+
}),
|
|
11
|
+
outcome: z.object({}),
|
|
12
|
+
}),
|
|
6
13
|
"member.promoted": z.object({
|
|
7
14
|
inputs: z.object({
|
|
8
15
|
previous_verification_type: z.string(),
|
|
@@ -11,4 +18,24 @@ export const membershipActivities = {
|
|
|
11
18
|
verification_type: LinkEnum,
|
|
12
19
|
}),
|
|
13
20
|
}),
|
|
21
|
+
"member.removed": z.object({
|
|
22
|
+
inputs: z.object({}),
|
|
23
|
+
outcome: z.object({
|
|
24
|
+
is_external: z.boolean(),
|
|
25
|
+
verification_type: z.string(),
|
|
26
|
+
}),
|
|
27
|
+
}),
|
|
28
|
+
"member.updated": z.object({
|
|
29
|
+
inputs: z.object({
|
|
30
|
+
is_external: z.boolean().optional(),
|
|
31
|
+
renew_verification: z.boolean().optional(),
|
|
32
|
+
verification_type: z.string().optional(),
|
|
33
|
+
}),
|
|
34
|
+
outcome: z.object({
|
|
35
|
+
previous: z.object({
|
|
36
|
+
is_external: z.boolean(),
|
|
37
|
+
verification_type: z.string(),
|
|
38
|
+
}),
|
|
39
|
+
}),
|
|
40
|
+
}),
|
|
14
41
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RuntimeContext } from "#src/activity";
|
|
2
|
+
import type { LinkType } from "@proconnect-gouv/proconnect.identite/types";
|
|
3
|
+
type AddMembershipOutcome = {
|
|
4
|
+
kind: "member_joined";
|
|
5
|
+
activity_id: number;
|
|
6
|
+
membership: {
|
|
7
|
+
organization_id: number;
|
|
8
|
+
user_id: number;
|
|
9
|
+
};
|
|
10
|
+
} | {
|
|
11
|
+
kind: "member_already_exists";
|
|
12
|
+
organization_id: number;
|
|
13
|
+
user_id: number;
|
|
14
|
+
};
|
|
15
|
+
export declare function addMembershipFactory({ actor, app, db }: RuntimeContext): ({ is_external, organization_id, user_id, verification_type, }: {
|
|
16
|
+
is_external?: boolean;
|
|
17
|
+
organization_id: number;
|
|
18
|
+
user_id: number;
|
|
19
|
+
verification_type: LinkType;
|
|
20
|
+
}) => Promise<AddMembershipOutcome>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=add-membership.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-membership.d.ts","sourceRoot":"","sources":["../../src/memberships/add-membership.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAC;AAK3E,KAAK,oBAAoB,GACrB;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE;QACV,eAAe,EAAE,MAAM,CAAC;QACxB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,GACD;IACE,IAAI,EAAE,uBAAuB,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEN,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,cAAc,IACvC,+DAK3B;IACD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,QAAQ,CAAC;CAC7B,KAAG,OAAO,CAAC,oBAAoB,CAAC,CA2ClC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { users_organizations } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { sql } from "drizzle-orm";
|
|
5
|
+
export function addMembershipFactory({ actor, app, db }) {
|
|
6
|
+
return function addMembership({ is_external = false, organization_id, user_id, verification_type, }) {
|
|
7
|
+
return db.transaction(async (tx) => {
|
|
8
|
+
const [membership] = await tx
|
|
9
|
+
.insert(users_organizations)
|
|
10
|
+
.values({
|
|
11
|
+
created_at: sql `now()`,
|
|
12
|
+
is_external,
|
|
13
|
+
organization_id,
|
|
14
|
+
updated_at: sql `now()`,
|
|
15
|
+
user_id,
|
|
16
|
+
verification_type,
|
|
17
|
+
verified_at: sql `now()`,
|
|
18
|
+
})
|
|
19
|
+
.onConflictDoNothing({
|
|
20
|
+
target: [
|
|
21
|
+
users_organizations.user_id,
|
|
22
|
+
users_organizations.organization_id,
|
|
23
|
+
],
|
|
24
|
+
})
|
|
25
|
+
.returning({
|
|
26
|
+
organization_id: users_organizations.organization_id,
|
|
27
|
+
user_id: users_organizations.user_id,
|
|
28
|
+
});
|
|
29
|
+
if (!membership) {
|
|
30
|
+
return { kind: "member_already_exists", organization_id, user_id };
|
|
31
|
+
}
|
|
32
|
+
const { activity_id } = await insertActivity(tx, {
|
|
33
|
+
action: "member.joined",
|
|
34
|
+
actor,
|
|
35
|
+
app,
|
|
36
|
+
context: {
|
|
37
|
+
inputs: { is_external, verification_type },
|
|
38
|
+
outcome: {},
|
|
39
|
+
},
|
|
40
|
+
organization_id,
|
|
41
|
+
user_id,
|
|
42
|
+
});
|
|
43
|
+
return { kind: "member_joined", activity_id, membership };
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memberships/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memberships/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RuntimeContext } from "#src/activity";
|
|
2
|
+
type RemoveMembershipOutcome = {
|
|
3
|
+
kind: "member_removed";
|
|
4
|
+
activity_id: number;
|
|
5
|
+
previous: {
|
|
6
|
+
is_external: boolean;
|
|
7
|
+
verification_type: string;
|
|
8
|
+
};
|
|
9
|
+
} | {
|
|
10
|
+
kind: "membership_not_found";
|
|
11
|
+
organization_id: number;
|
|
12
|
+
user_id: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function removeMembershipFactory({ actor, app, db }: RuntimeContext): ({ organization_id, user_id, }: {
|
|
15
|
+
organization_id: number;
|
|
16
|
+
user_id: number;
|
|
17
|
+
}) => Promise<RemoveMembershipOutcome>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=remove-membership.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-membership.d.ts","sourceRoot":"","sources":["../../src/memberships/remove-membership.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAOtE,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,CAAC;AAE/E,wBAAgB,uBAAuB,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,cAAc,IACvC,+BAG9B;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,uBAAuB,CAAC,CA+BrC"}
|