@proconnect-gouv/proconnect.identite.runtime 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/activity/activity-context-schemas.d.ts +22 -0
- package/dist/activity/activity-context-schemas.d.ts.map +1 -1
- package/dist/certification/activities.d.ts +64 -0
- package/dist/certification/activities.d.ts.map +1 -0
- package/dist/certification/activities.js +78 -0
- package/dist/certification/index.d.ts +2 -0
- package/dist/certification/index.d.ts.map +1 -0
- package/dist/certification/index.js +2 -0
- package/dist/domains/activities.d.ts +22 -0
- package/dist/domains/activities.d.ts.map +1 -1
- package/dist/domains/activities.js +20 -1
- package/dist/domains/change-email-domain-verification.d.ts +29 -0
- package/dist/domains/change-email-domain-verification.d.ts.map +1 -0
- package/dist/domains/change-email-domain-verification.js +167 -0
- package/dist/domains/index.d.ts +1 -1
- package/dist/domains/index.d.ts.map +1 -1
- package/dist/domains/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/runtime/create-identite-runtime.d.ts +24 -20
- package/dist/runtime/create-identite-runtime.d.ts.map +1 -1
- package/dist/runtime/create-identite-runtime.js +6 -2
- package/package.json +3 -3
- package/src/certification/activities.test.ts +128 -0
- package/src/certification/activities.ts +103 -0
- package/src/certification/index.ts +3 -0
- package/src/domains/activities.ts +23 -1
- package/src/domains/{mark-domain-as-verified.test.ts → change-email-domain-verification.test.ts} +100 -10
- package/src/domains/change-email-domain-verification.ts +305 -0
- package/src/domains/index.ts +1 -1
- package/src/franceconnect/connect-franceconnect.test.ts +4 -4
- package/src/franceconnect/disconnect-franceconnect.test.ts +4 -4
- package/src/index.ts +1 -0
- package/src/memberships/add-membership.test.ts +4 -4
- package/src/memberships/remove-membership.test.ts +4 -4
- package/src/memberships/update-membership.test.ts +6 -6
- package/src/moderations/open-moderation.test.ts +2 -2
- package/src/runtime/create-identite-runtime.test.ts +12 -59
- package/src/runtime/create-identite-runtime.ts +6 -2
- package/src/users/change-password.test.ts +2 -2
- package/src/users/delete-user.test.ts +4 -4
- package/src/users/reset-mfa.test.ts +5 -5
- package/src/users/update-personal-informations.test.ts +2 -2
- package/dist/domains/mark-domain-as-verified.d.ts +0 -25
- package/dist/domains/mark-domain-as-verified.d.ts.map +0 -1
- package/dist/domains/mark-domain-as-verified.js +0 -103
- package/src/domains/mark-domain-as-verified.ts +0 -174
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @proconnect-gouv/proconnect.identite.runtime
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`b214548`](https://github.com/proconnect-gouv/proconnect-identite/commit/b214548ebe9fbcf93cff73053502fcb3e2643ab5)]:
|
|
8
|
+
- @proconnect-gouv/proconnect.identite.database@3.0.0
|
|
9
|
+
|
|
10
|
+
## 0.6.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [#2445](https://github.com/proconnect-gouv/proconnect-identite/pull/2445) [`efdd64d`](https://github.com/proconnect-gouv/proconnect-identite/commit/efdd64d8c342b586c76ac4e6717323d4486bf16d) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Le runtime ajoute `certificationDirigeantActivities` (schémas zod des actions `certification_dirigeant.certified`, `.close_matched`, `.not_matched` et `.not_covered`) et `getCertificationDirigeantActivity`, qui transforme le résultat de `processCertificationDirigeant` en l'une de ces actions. `outcome` porte le registre consulté, la raison d'un échec et, pour une correspondance partielle seulement, `diff` : pour chaque critère discordant, la valeur FranceConnect et celle du registre, telles que reçues (`raw`) et telles que comparées (`compared`). Ces schémas ne font pas encore partie de `activityContextSchemas` : l'application qui les écrit les passe à `createIdentiteRuntime` comme ses propres actions, et un lecteur du journal les ajoute à ses schémas. identite exporte `compareCriteria`, d'où `certificationScore` tire désormais ses critères concordants.
|
|
15
|
+
|
|
16
|
+
- [#2453](https://github.com/proconnect-gouv/proconnect-identite/pull/2453) [`918ab32`](https://github.com/proconnect-gouv/proconnect-identite/commit/918ab32555b01df0363e8d531b6c6a4331ef0970) Thanks [@douglasduteil](https://github.com/douglasduteil)! - Remplace la commande `markDomainAsVerified` par `changeEmailDomainVerification({ domain, organization_id, verification_type })`, qui accepte aussi les types refusés (`refused`, `blacklisted`). Une validation garde le comportement précédent (`domain.verified` et `member.promoted`). Un refus remplace les états du domaine sans `verified_at`, journalise `domain.refused` sous l’acteur reçu, retire de l’organisation chaque membre dont l’email est sur ce domaine et journalise une ligne `member.removed` par membre sous l’acteur `{ type: "app", job: "domain.remove_members" }`, avec `cause_activity_id`. L’issue unique `domain_verification_changed` porte `promoted_members` et `removed_members`. `activityContextSchemas` décrit désormais `domain.refused` : hyyypertool doit retirer sa propre définition et sa transaction de refus en passant à cette version.
|
|
17
|
+
|
|
18
|
+
- [#2451](https://github.com/proconnect-gouv/proconnect-identite/pull/2451) [`0b133b6`](https://github.com/proconnect-gouv/proconnect-identite/commit/0b133b61cbe46af2347fc1eb1eaee8302ebfb94c) Thanks [@douglasduteil](https://github.com/douglasduteil)! - `activityContextSchemas` décrit l’action `domain.removed`, écrite jusqu’ici par hyyypertool seul : `inputs.domain`, `outcome.email_domain_id` et `outcome.previous_verification_type`. hyyypertool doit retirer sa propre définition de `domain.removed` en passant à cette version.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`efdd64d`](https://github.com/proconnect-gouv/proconnect-identite/commit/efdd64d8c342b586c76ac4e6717323d4486bf16d), [`918ab32`](https://github.com/proconnect-gouv/proconnect-identite/commit/918ab32555b01df0363e8d531b6c6a4331ef0970), [`304e89d`](https://github.com/proconnect-gouv/proconnect-identite/commit/304e89d2169c5a112af5d1465799151ebf9a871a)]:
|
|
23
|
+
- @proconnect-gouv/proconnect.identite@16.0.0
|
|
24
|
+
- @proconnect-gouv/proconnect.identite.database@2.1.0
|
|
25
|
+
|
|
3
26
|
## 0.5.0
|
|
4
27
|
|
|
5
28
|
### Minor Changes
|
|
@@ -130,6 +130,28 @@ export declare const activityContextSchemas: {
|
|
|
130
130
|
connected_at: import("zod").ZodString;
|
|
131
131
|
}, import("zod/v4/core").$strip>;
|
|
132
132
|
}, import("zod/v4/core").$strip>;
|
|
133
|
+
"domain.refused": import("zod").ZodObject<{
|
|
134
|
+
inputs: import("zod").ZodObject<{
|
|
135
|
+
domain: import("zod").ZodString;
|
|
136
|
+
verification_type: import("zod").ZodEnum<{
|
|
137
|
+
blacklisted: "blacklisted";
|
|
138
|
+
refused: "refused";
|
|
139
|
+
}>;
|
|
140
|
+
}, import("zod/v4/core").$strip>;
|
|
141
|
+
outcome: import("zod").ZodObject<{
|
|
142
|
+
email_domain_id: import("zod").ZodNumber;
|
|
143
|
+
replaced_verification_types: import("zod").ZodArray<import("zod").ZodString>;
|
|
144
|
+
}, import("zod/v4/core").$strip>;
|
|
145
|
+
}, import("zod/v4/core").$strip>;
|
|
146
|
+
"domain.removed": import("zod").ZodObject<{
|
|
147
|
+
inputs: import("zod").ZodObject<{
|
|
148
|
+
domain: import("zod").ZodString;
|
|
149
|
+
}, import("zod/v4/core").$strip>;
|
|
150
|
+
outcome: import("zod").ZodObject<{
|
|
151
|
+
email_domain_id: import("zod").ZodNumber;
|
|
152
|
+
previous_verification_type: import("zod").ZodString;
|
|
153
|
+
}, import("zod/v4/core").$strip>;
|
|
154
|
+
}, import("zod/v4/core").$strip>;
|
|
133
155
|
"domain.verified": import("zod").ZodObject<{
|
|
134
156
|
inputs: import("zod").ZodObject<{
|
|
135
157
|
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":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI7C,eAAO,MAAM,sBAAsB
|
|
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"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ActivityOf, ContextsOf } from "#src/activity";
|
|
2
|
+
import { type processCertificationDirigeantFactory } from "@proconnect-gouv/proconnect.identite/managers/certification";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
export declare const certificationDirigeantActivities: {
|
|
5
|
+
"certification_dirigeant.certified": z.ZodObject<{
|
|
6
|
+
inputs: z.ZodObject<{}, z.core.$strip>;
|
|
7
|
+
outcome: z.ZodObject<{
|
|
8
|
+
source: z.ZodEnum<{
|
|
9
|
+
"api.insee.fr/api-sirene/private": "api.insee.fr/api-sirene/private";
|
|
10
|
+
"entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux": "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux";
|
|
11
|
+
"registre-national-entreprises.inpi.fr/api": "registre-national-entreprises.inpi.fr/api";
|
|
12
|
+
}>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
"certification_dirigeant.close_matched": z.ZodObject<{
|
|
16
|
+
inputs: z.ZodObject<{}, z.core.$strip>;
|
|
17
|
+
outcome: z.ZodObject<{
|
|
18
|
+
diff: z.ZodRecord<z.ZodEnum<{
|
|
19
|
+
family_name: "family_name";
|
|
20
|
+
gender: "gender";
|
|
21
|
+
birth_country: "birth_country";
|
|
22
|
+
birth_date: "birth_date";
|
|
23
|
+
birth_place: "birth_place";
|
|
24
|
+
first_name: "first_name";
|
|
25
|
+
}> & z.core.$partial, z.ZodObject<{
|
|
26
|
+
franceconnect: z.ZodObject<{
|
|
27
|
+
compared: z.ZodNullable<z.ZodString>;
|
|
28
|
+
raw: z.ZodNullable<z.ZodString>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
source: z.ZodObject<{
|
|
31
|
+
compared: z.ZodNullable<z.ZodString>;
|
|
32
|
+
raw: z.ZodNullable<z.ZodString>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
}, z.core.$strip>>;
|
|
35
|
+
source: z.ZodEnum<{
|
|
36
|
+
"api.insee.fr/api-sirene/private": "api.insee.fr/api-sirene/private";
|
|
37
|
+
"entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux": "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux";
|
|
38
|
+
"registre-national-entreprises.inpi.fr/api": "registre-national-entreprises.inpi.fr/api";
|
|
39
|
+
}>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
"certification_dirigeant.not_covered": z.ZodObject<{
|
|
43
|
+
inputs: z.ZodObject<{}, z.core.$strip>;
|
|
44
|
+
outcome: z.ZodObject<{}, z.core.$strip>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
"certification_dirigeant.not_matched": z.ZodObject<{
|
|
47
|
+
inputs: z.ZodObject<{}, z.core.$strip>;
|
|
48
|
+
outcome: z.ZodObject<{
|
|
49
|
+
reason: z.ZodEnum<{
|
|
50
|
+
below_threshold: "below_threshold";
|
|
51
|
+
no_candidates: "no_candidates";
|
|
52
|
+
}>;
|
|
53
|
+
source: z.ZodEnum<{
|
|
54
|
+
"api.insee.fr/api-sirene/private": "api.insee.fr/api-sirene/private";
|
|
55
|
+
"entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux": "entreprise.api.gouv.fr/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux";
|
|
56
|
+
"registre-national-entreprises.inpi.fr/api": "registre-national-entreprises.inpi.fr/api";
|
|
57
|
+
}>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
};
|
|
61
|
+
type CertificationDirigeantResult = Awaited<ReturnType<ReturnType<typeof processCertificationDirigeantFactory>>>;
|
|
62
|
+
export declare function getCertificationDirigeantActivity(result: CertificationDirigeantResult): ActivityOf<ContextsOf<typeof certificationDirigeantActivities>>;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=activities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/certification/activities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAIL,KAAK,oCAAoC,EAC1C,MAAM,6DAA6D,CAAC;AACrE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AASzB,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4B5C,CAAC;AAIF,KAAK,4BAA4B,GAAG,OAAO,CACzC,UAAU,CAAC,UAAU,CAAC,OAAO,oCAAoC,CAAC,CAAC,CACpE,CAAC;AAEF,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,4BAA4B,GACnC,UAAU,CAAC,UAAU,CAAC,OAAO,gCAAgC,CAAC,CAAC,CA0CjE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { CertificationDirigeantDataSource, compareCriteria, MatchCriteria, } from "@proconnect-gouv/proconnect.identite/managers/certification";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//
|
|
5
|
+
const ComparedValue = z.object({
|
|
6
|
+
compared: z.string().nullable(),
|
|
7
|
+
raw: z.string().nullable(),
|
|
8
|
+
});
|
|
9
|
+
export const certificationDirigeantActivities = {
|
|
10
|
+
"certification_dirigeant.certified": z.object({
|
|
11
|
+
inputs: z.object({}),
|
|
12
|
+
outcome: z.object({
|
|
13
|
+
source: CertificationDirigeantDataSource,
|
|
14
|
+
}),
|
|
15
|
+
}),
|
|
16
|
+
"certification_dirigeant.close_matched": z.object({
|
|
17
|
+
inputs: z.object({}),
|
|
18
|
+
outcome: z.object({
|
|
19
|
+
diff: z.partialRecord(MatchCriteria, z.object({ franceconnect: ComparedValue, source: ComparedValue })),
|
|
20
|
+
source: CertificationDirigeantDataSource,
|
|
21
|
+
}),
|
|
22
|
+
}),
|
|
23
|
+
"certification_dirigeant.not_covered": z.object({
|
|
24
|
+
inputs: z.object({}),
|
|
25
|
+
outcome: z.object({}),
|
|
26
|
+
}),
|
|
27
|
+
"certification_dirigeant.not_matched": z.object({
|
|
28
|
+
inputs: z.object({}),
|
|
29
|
+
outcome: z.object({
|
|
30
|
+
reason: z.enum(["below_threshold", "no_candidates"]),
|
|
31
|
+
source: CertificationDirigeantDataSource,
|
|
32
|
+
}),
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
export function getCertificationDirigeantActivity(result) {
|
|
36
|
+
switch (result.cause) {
|
|
37
|
+
case "organisation_not_covered":
|
|
38
|
+
return {
|
|
39
|
+
action: "certification_dirigeant.not_covered",
|
|
40
|
+
context: { inputs: {}, outcome: {} },
|
|
41
|
+
};
|
|
42
|
+
case "exact_match":
|
|
43
|
+
return {
|
|
44
|
+
action: "certification_dirigeant.certified",
|
|
45
|
+
context: { inputs: {}, outcome: { source: result.details.source } },
|
|
46
|
+
};
|
|
47
|
+
case "close_match":
|
|
48
|
+
return {
|
|
49
|
+
action: "certification_dirigeant.close_matched",
|
|
50
|
+
context: {
|
|
51
|
+
inputs: {},
|
|
52
|
+
outcome: {
|
|
53
|
+
diff: Object.fromEntries(compareCriteria(result.details.identity, result.details.dirigeant)
|
|
54
|
+
.filter(({ matched }) => !matched)
|
|
55
|
+
.map(({ criterion, franceconnect, source }) => [
|
|
56
|
+
criterion,
|
|
57
|
+
{ franceconnect, source },
|
|
58
|
+
])),
|
|
59
|
+
source: result.details.source,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
case "below_threshold":
|
|
64
|
+
case "no_candidates":
|
|
65
|
+
return {
|
|
66
|
+
action: "certification_dirigeant.not_matched",
|
|
67
|
+
context: {
|
|
68
|
+
inputs: {},
|
|
69
|
+
outcome: { reason: result.cause, source: result.details.source },
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
default:
|
|
73
|
+
return assert_never(result);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function assert_never(value) {
|
|
77
|
+
throw new Error(`Unhandled certification result: ${JSON.stringify(value)}`);
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/certification/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC"}
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
2
|
export declare const domainActivities: {
|
|
3
|
+
"domain.refused": z.ZodObject<{
|
|
4
|
+
inputs: z.ZodObject<{
|
|
5
|
+
domain: z.ZodString;
|
|
6
|
+
verification_type: z.ZodEnum<{
|
|
7
|
+
blacklisted: "blacklisted";
|
|
8
|
+
refused: "refused";
|
|
9
|
+
}>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
outcome: z.ZodObject<{
|
|
12
|
+
email_domain_id: z.ZodNumber;
|
|
13
|
+
replaced_verification_types: z.ZodArray<z.ZodString>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
"domain.removed": z.ZodObject<{
|
|
17
|
+
inputs: z.ZodObject<{
|
|
18
|
+
domain: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
outcome: z.ZodObject<{
|
|
21
|
+
email_domain_id: z.ZodNumber;
|
|
22
|
+
previous_verification_type: z.ZodString;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
}, z.core.$strip>;
|
|
3
25
|
"domain.verified": z.ZodObject<{
|
|
4
26
|
inputs: z.ZodObject<{
|
|
5
27
|
domain: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/domains/activities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/domains/activities.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8B5B,CAAC"}
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
//
|
|
2
|
-
import { EmailDomainApprovedVerificationEnum } from "@proconnect-gouv/proconnect.identite/types";
|
|
2
|
+
import { EmailDomainApprovedVerificationEnum, EmailDomainRejectedVerificationEnum, } from "@proconnect-gouv/proconnect.identite/types";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
//
|
|
5
5
|
export const domainActivities = {
|
|
6
|
+
"domain.refused": z.object({
|
|
7
|
+
inputs: z.object({
|
|
8
|
+
domain: z.string(),
|
|
9
|
+
verification_type: EmailDomainRejectedVerificationEnum,
|
|
10
|
+
}),
|
|
11
|
+
outcome: z.object({
|
|
12
|
+
email_domain_id: z.number(),
|
|
13
|
+
replaced_verification_types: z.array(z.string()),
|
|
14
|
+
}),
|
|
15
|
+
}),
|
|
16
|
+
"domain.removed": z.object({
|
|
17
|
+
inputs: z.object({
|
|
18
|
+
domain: z.string(),
|
|
19
|
+
}),
|
|
20
|
+
outcome: z.object({
|
|
21
|
+
email_domain_id: z.number(),
|
|
22
|
+
previous_verification_type: z.string(),
|
|
23
|
+
}),
|
|
24
|
+
}),
|
|
6
25
|
"domain.verified": z.object({
|
|
7
26
|
inputs: z.object({
|
|
8
27
|
domain: z.string(),
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RuntimeContext } from "#src/activity";
|
|
2
|
+
import { type EmailDomainNoPendingVerificationType } from "@proconnect-gouv/proconnect.identite/types";
|
|
3
|
+
type ChangeEmailDomainVerificationOutcome = {
|
|
4
|
+
kind: "domain_verification_changed";
|
|
5
|
+
activity_id: number;
|
|
6
|
+
email_domain: {
|
|
7
|
+
id: number;
|
|
8
|
+
verification_type: EmailDomainNoPendingVerificationType;
|
|
9
|
+
};
|
|
10
|
+
promoted_members: ReadonlyArray<{
|
|
11
|
+
previous_verification_type: string;
|
|
12
|
+
user_id: number;
|
|
13
|
+
}>;
|
|
14
|
+
removed_members: ReadonlyArray<{
|
|
15
|
+
previous_verification_type: string;
|
|
16
|
+
user_id: number;
|
|
17
|
+
}>;
|
|
18
|
+
replaced_verification_types: ReadonlyArray<string>;
|
|
19
|
+
} | {
|
|
20
|
+
kind: "organization_not_found";
|
|
21
|
+
organization_id: number;
|
|
22
|
+
};
|
|
23
|
+
export declare function changeEmailDomainVerificationFactory({ actor, app, db, }: RuntimeContext): ({ domain, organization_id, verification_type, }: {
|
|
24
|
+
domain: string;
|
|
25
|
+
organization_id: number;
|
|
26
|
+
verification_type: EmailDomainNoPendingVerificationType;
|
|
27
|
+
}) => Promise<ChangeEmailDomainVerificationOutcome>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=change-email-domain-verification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-email-domain-verification.d.ts","sourceRoot":"","sources":["../../src/domains/change-email-domain-verification.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAQtE,OAAO,EAKL,KAAK,oCAAoC,EAC1C,MAAM,4CAA4C,CAAC;AAKpD,KAAK,oCAAoC,GACrC;IACE,IAAI,EAAE,6BAA6B,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,iBAAiB,EAAE,oCAAoC,CAAC;KACzD,CAAC;IACF,gBAAgB,EAAE,aAAa,CAAC;QAC9B,0BAA0B,EAAE,MAAM,CAAC;QACnC,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;IACH,eAAe,EAAE,aAAa,CAAC;QAC7B,0BAA0B,EAAE,MAAM,CAAC;QACnC,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;IACH,2BAA2B,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACpD,GACD;IAAE,IAAI,EAAE,wBAAwB,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC;AAIhE,wBAAgB,oCAAoC,CAAC,EACnD,KAAK,EACL,GAAG,EACH,EAAE,GACH,EAAE,cAAc,IAC+B,iDAI3C;IACD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,oCAAoC,CAAC;CACzD,KAAG,OAAO,CAAC,oCAAoC,CAAC,CAkGlD"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { insertActivity } from "#src/journal";
|
|
3
|
+
import { email_domains, users_organizations, } from "@proconnect-gouv/proconnect.identite.database/drizzle";
|
|
4
|
+
import { getMembershipChangesByDomainVerification } from "@proconnect-gouv/proconnect.identite/services/organization";
|
|
5
|
+
import { EmailDomainApprovedVerificationValues, EmailDomainPendingVerificationValues, EmailDomainRejectedVerificationValues, LinkEnum, } from "@proconnect-gouv/proconnect.identite/types";
|
|
6
|
+
import { and, eq, inArray, sql } from "drizzle-orm";
|
|
7
|
+
export function changeEmailDomainVerificationFactory({ actor, app, db, }) {
|
|
8
|
+
return function changeEmailDomainVerification({ domain, organization_id, verification_type, }) {
|
|
9
|
+
return db.transaction(async (tx) => {
|
|
10
|
+
const organization = await tx.query.organizations.findFirst({
|
|
11
|
+
columns: { id: true },
|
|
12
|
+
where: (table, { eq }) => eq(table.id, organization_id),
|
|
13
|
+
});
|
|
14
|
+
if (!organization) {
|
|
15
|
+
return { kind: "organization_not_found", organization_id };
|
|
16
|
+
}
|
|
17
|
+
const changes = getMembershipChangesByDomainVerification({
|
|
18
|
+
domain,
|
|
19
|
+
members: await findMembers(tx, { organization_id }),
|
|
20
|
+
verification_type,
|
|
21
|
+
});
|
|
22
|
+
switch (changes.kind) {
|
|
23
|
+
case "domain_approved": {
|
|
24
|
+
const { email_domain_id, replaced_verification_types } = await replaceEmailDomain(tx, {
|
|
25
|
+
domain,
|
|
26
|
+
organization_id,
|
|
27
|
+
verification_type: changes.verification_type,
|
|
28
|
+
verified_at: sql `now()`,
|
|
29
|
+
});
|
|
30
|
+
const { activity_id } = await insertActivity(tx, {
|
|
31
|
+
action: "domain.verified",
|
|
32
|
+
actor,
|
|
33
|
+
app,
|
|
34
|
+
context: {
|
|
35
|
+
inputs: { domain, verification_type: changes.verification_type },
|
|
36
|
+
outcome: { email_domain_id, replaced_verification_types },
|
|
37
|
+
},
|
|
38
|
+
organization_id,
|
|
39
|
+
});
|
|
40
|
+
await promoteMembers(tx, {
|
|
41
|
+
app,
|
|
42
|
+
cause_activity_id: activity_id,
|
|
43
|
+
members: changes.promoted_members,
|
|
44
|
+
organization_id,
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
kind: "domain_verification_changed",
|
|
48
|
+
activity_id,
|
|
49
|
+
email_domain: { id: email_domain_id, verification_type },
|
|
50
|
+
promoted_members: changes.promoted_members.map(toPreviousMembership),
|
|
51
|
+
removed_members: [],
|
|
52
|
+
replaced_verification_types,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
case "domain_refused": {
|
|
56
|
+
const { email_domain_id, replaced_verification_types } = await replaceEmailDomain(tx, {
|
|
57
|
+
domain,
|
|
58
|
+
organization_id,
|
|
59
|
+
verification_type: changes.verification_type,
|
|
60
|
+
verified_at: null,
|
|
61
|
+
});
|
|
62
|
+
const { activity_id } = await insertActivity(tx, {
|
|
63
|
+
action: "domain.refused",
|
|
64
|
+
actor,
|
|
65
|
+
app,
|
|
66
|
+
context: {
|
|
67
|
+
inputs: { domain, verification_type: changes.verification_type },
|
|
68
|
+
outcome: { email_domain_id, replaced_verification_types },
|
|
69
|
+
},
|
|
70
|
+
organization_id,
|
|
71
|
+
});
|
|
72
|
+
await removeMembers(tx, {
|
|
73
|
+
app,
|
|
74
|
+
cause_activity_id: activity_id,
|
|
75
|
+
members: changes.removed_members,
|
|
76
|
+
organization_id,
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
kind: "domain_verification_changed",
|
|
80
|
+
activity_id,
|
|
81
|
+
email_domain: { id: email_domain_id, verification_type },
|
|
82
|
+
promoted_members: [],
|
|
83
|
+
removed_members: changes.removed_members.map(toPreviousMembership),
|
|
84
|
+
replaced_verification_types,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
default: {
|
|
88
|
+
const unhandled_changes = changes;
|
|
89
|
+
throw new Error(`Unhandled membership changes: ${JSON.stringify(unhandled_changes)}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//
|
|
96
|
+
async function findMembers(tx, { organization_id }) {
|
|
97
|
+
const memberships = await tx.query.users_organizations.findMany({
|
|
98
|
+
columns: { is_external: true, user_id: true, verification_type: true },
|
|
99
|
+
where: (table, { eq }) => eq(table.organization_id, organization_id),
|
|
100
|
+
with: { user: { columns: { email: true } } },
|
|
101
|
+
});
|
|
102
|
+
return memberships.map(({ is_external, user: { email }, user_id, verification_type }) => ({
|
|
103
|
+
email,
|
|
104
|
+
is_external,
|
|
105
|
+
user_id,
|
|
106
|
+
verification_type,
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
async function replaceEmailDomain(tx, { domain, organization_id, verification_type, verified_at, }) {
|
|
110
|
+
const replaced = await tx
|
|
111
|
+
.delete(email_domains)
|
|
112
|
+
.where(and(eq(email_domains.organization_id, organization_id), eq(email_domains.domain, domain), inArray(email_domains.verification_type, [
|
|
113
|
+
...EmailDomainApprovedVerificationValues,
|
|
114
|
+
...EmailDomainPendingVerificationValues,
|
|
115
|
+
...EmailDomainRejectedVerificationValues,
|
|
116
|
+
])))
|
|
117
|
+
.returning({ verification_type: email_domains.verification_type });
|
|
118
|
+
const [email_domain] = await tx
|
|
119
|
+
.insert(email_domains)
|
|
120
|
+
.values({ domain, organization_id, verification_type, verified_at })
|
|
121
|
+
.returning({ id: email_domains.id });
|
|
122
|
+
return {
|
|
123
|
+
email_domain_id: email_domain.id,
|
|
124
|
+
replaced_verification_types: replaced.map(({ verification_type }) => verification_type),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async function promoteMembers(tx, { app, cause_activity_id, members, organization_id, }) {
|
|
128
|
+
if (members.length === 0)
|
|
129
|
+
return;
|
|
130
|
+
await tx
|
|
131
|
+
.update(users_organizations)
|
|
132
|
+
.set({ updated_at: sql `now()`, verification_type: LinkEnum.enum.domain })
|
|
133
|
+
.where(and(eq(users_organizations.organization_id, organization_id), inArray(users_organizations.user_id, members.map(({ user_id }) => user_id))));
|
|
134
|
+
for (const { user_id, verification_type } of members) {
|
|
135
|
+
await insertActivity(tx, {
|
|
136
|
+
action: "member.promoted",
|
|
137
|
+
actor: { type: "app", job: "domain.promote_members" },
|
|
138
|
+
app,
|
|
139
|
+
cause_activity_id,
|
|
140
|
+
context: {
|
|
141
|
+
inputs: { previous_verification_type: verification_type },
|
|
142
|
+
outcome: { verification_type: LinkEnum.enum.domain },
|
|
143
|
+
},
|
|
144
|
+
organization_id,
|
|
145
|
+
user_id,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async function removeMembers(tx, { app, cause_activity_id, members, organization_id, }) {
|
|
150
|
+
if (members.length === 0)
|
|
151
|
+
return;
|
|
152
|
+
await tx.delete(users_organizations).where(and(eq(users_organizations.organization_id, organization_id), inArray(users_organizations.user_id, members.map(({ user_id }) => user_id))));
|
|
153
|
+
for (const { is_external, user_id, verification_type } of members) {
|
|
154
|
+
await insertActivity(tx, {
|
|
155
|
+
action: "member.removed",
|
|
156
|
+
actor: { type: "app", job: "domain.remove_members" },
|
|
157
|
+
app,
|
|
158
|
+
cause_activity_id,
|
|
159
|
+
context: { inputs: {}, outcome: { is_external, verification_type } },
|
|
160
|
+
organization_id,
|
|
161
|
+
user_id,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function toPreviousMembership({ user_id, verification_type }) {
|
|
166
|
+
return { previous_verification_type: verification_type, user_id };
|
|
167
|
+
}
|
package/dist/domains/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/domains/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/domains/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,uCAAuC,CAAC"}
|
package/dist/domains/index.js
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,30 @@ export declare function createIdentiteRuntime<OwnContexts extends ContextMap & {
|
|
|
21
21
|
organization_id: number;
|
|
22
22
|
user_id: number;
|
|
23
23
|
}>;
|
|
24
|
+
changeEmailDomainVerification: ({ domain, organization_id, verification_type, }: {
|
|
25
|
+
domain: string;
|
|
26
|
+
organization_id: number;
|
|
27
|
+
verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainNoPendingVerificationType;
|
|
28
|
+
}) => Promise<{
|
|
29
|
+
kind: "domain_verification_changed";
|
|
30
|
+
activity_id: number;
|
|
31
|
+
email_domain: {
|
|
32
|
+
id: number;
|
|
33
|
+
verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainNoPendingVerificationType;
|
|
34
|
+
};
|
|
35
|
+
promoted_members: ReadonlyArray<{
|
|
36
|
+
previous_verification_type: string;
|
|
37
|
+
user_id: number;
|
|
38
|
+
}>;
|
|
39
|
+
removed_members: ReadonlyArray<{
|
|
40
|
+
previous_verification_type: string;
|
|
41
|
+
user_id: number;
|
|
42
|
+
}>;
|
|
43
|
+
replaced_verification_types: ReadonlyArray<string>;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "organization_not_found";
|
|
46
|
+
organization_id: number;
|
|
47
|
+
}>;
|
|
24
48
|
changePassword: ({ encrypted_password, source, user_id, }: {
|
|
25
49
|
encrypted_password: string;
|
|
26
50
|
source: "reset_password" | "signup";
|
|
@@ -67,26 +91,6 @@ export declare function createIdentiteRuntime<OwnContexts extends ContextMap & {
|
|
|
67
91
|
kind: "franceconnect_identity_not_found";
|
|
68
92
|
user_id: number;
|
|
69
93
|
}>;
|
|
70
|
-
markDomainAsVerified: ({ domain, domain_verification_type, organization_id, }: {
|
|
71
|
-
domain: string;
|
|
72
|
-
domain_verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainApprovedVerificationType;
|
|
73
|
-
organization_id: number;
|
|
74
|
-
}) => Promise<{
|
|
75
|
-
kind: "domain_verified";
|
|
76
|
-
activity_id: number;
|
|
77
|
-
email_domain: {
|
|
78
|
-
id: number;
|
|
79
|
-
verification_type: import("@proconnect-gouv/proconnect.identite/types").EmailDomainApprovedVerificationType;
|
|
80
|
-
};
|
|
81
|
-
promoted_members: ReadonlyArray<{
|
|
82
|
-
previous_verification_type: string;
|
|
83
|
-
user_id: number;
|
|
84
|
-
}>;
|
|
85
|
-
replaced_verification_types: ReadonlyArray<string>;
|
|
86
|
-
} | {
|
|
87
|
-
kind: "organization_not_found";
|
|
88
|
-
organization_id: number;
|
|
89
|
-
}>;
|
|
90
94
|
openModeration: ({ organization_id, sp_name, ticket_id, type, user_id, }: {
|
|
91
95
|
organization_id: number;
|
|
92
96
|
sp_name?: string | null;
|
|
@@ -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;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;;
|
|
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;;uBAJe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAnB/B,gCACI;;;;;;;;;;;;;;;;;mBAWU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;qBA8BL,mBAAmB,YACb,UAAU,CAAC,WAAW,CAAC,GAAG,eAAe;;;;;;;;sBA3CpC,kCACM,WAAW;;;;;;uBAuB7B,CAAC;;;;;;;8BAGC,CAAC;6BAEN,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BV"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//
|
|
2
|
-
import {
|
|
2
|
+
import { changeEmailDomainVerificationFactory } from "#src/domains";
|
|
3
3
|
import { connectFranceConnectFactory, disconnectFranceConnectFactory, } from "#src/franceconnect";
|
|
4
4
|
import { insertActivity } from "#src/journal";
|
|
5
5
|
import { addMembershipFactory, removeMembershipFactory, updateMembershipFactory, } from "#src/memberships";
|
|
@@ -11,6 +11,11 @@ export function createIdentiteRuntime({ app, db }) {
|
|
|
11
11
|
as(actor) {
|
|
12
12
|
return {
|
|
13
13
|
addMembership: addMembershipFactory({ actor, app, db }),
|
|
14
|
+
changeEmailDomainVerification: changeEmailDomainVerificationFactory({
|
|
15
|
+
actor,
|
|
16
|
+
app,
|
|
17
|
+
db,
|
|
18
|
+
}),
|
|
14
19
|
changePassword: changePasswordFactory({ actor, app, db }),
|
|
15
20
|
connectFranceConnect: connectFranceConnectFactory({ actor, app, db }),
|
|
16
21
|
deleteUser: deleteUserFactory({ actor, app, db }),
|
|
@@ -19,7 +24,6 @@ export function createIdentiteRuntime({ app, db }) {
|
|
|
19
24
|
app,
|
|
20
25
|
db,
|
|
21
26
|
}),
|
|
22
|
-
markDomainAsVerified: markDomainAsVerifiedFactory({ actor, app, db }),
|
|
23
27
|
openModeration: openModerationFactory({ actor, app, db }),
|
|
24
28
|
removeMembership: removeMembershipFactory({ actor, app, db }),
|
|
25
29
|
record: (tx, activity) => insertActivity(tx, { ...activity, actor, app }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite.runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"test": "tsc --noEmit && tsx --test --test-reporter=spec"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@proconnect-gouv/proconnect.identite": "^
|
|
36
|
-
"@proconnect-gouv/proconnect.identite.database": "^
|
|
35
|
+
"@proconnect-gouv/proconnect.identite": "^16.0.0",
|
|
36
|
+
"@proconnect-gouv/proconnect.identite.database": "^3.0.0",
|
|
37
37
|
"zod": "^4.6.7"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|