@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.
Files changed (49) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/activity/activity-context-schemas.d.ts +22 -0
  3. package/dist/activity/activity-context-schemas.d.ts.map +1 -1
  4. package/dist/certification/activities.d.ts +64 -0
  5. package/dist/certification/activities.d.ts.map +1 -0
  6. package/dist/certification/activities.js +78 -0
  7. package/dist/certification/index.d.ts +2 -0
  8. package/dist/certification/index.d.ts.map +1 -0
  9. package/dist/certification/index.js +2 -0
  10. package/dist/domains/activities.d.ts +22 -0
  11. package/dist/domains/activities.d.ts.map +1 -1
  12. package/dist/domains/activities.js +20 -1
  13. package/dist/domains/change-email-domain-verification.d.ts +29 -0
  14. package/dist/domains/change-email-domain-verification.d.ts.map +1 -0
  15. package/dist/domains/change-email-domain-verification.js +167 -0
  16. package/dist/domains/index.d.ts +1 -1
  17. package/dist/domains/index.d.ts.map +1 -1
  18. package/dist/domains/index.js +1 -1
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1 -0
  22. package/dist/runtime/create-identite-runtime.d.ts +24 -20
  23. package/dist/runtime/create-identite-runtime.d.ts.map +1 -1
  24. package/dist/runtime/create-identite-runtime.js +6 -2
  25. package/package.json +3 -3
  26. package/src/certification/activities.test.ts +128 -0
  27. package/src/certification/activities.ts +103 -0
  28. package/src/certification/index.ts +3 -0
  29. package/src/domains/activities.ts +23 -1
  30. package/src/domains/{mark-domain-as-verified.test.ts → change-email-domain-verification.test.ts} +100 -10
  31. package/src/domains/change-email-domain-verification.ts +305 -0
  32. package/src/domains/index.ts +1 -1
  33. package/src/franceconnect/connect-franceconnect.test.ts +4 -4
  34. package/src/franceconnect/disconnect-franceconnect.test.ts +4 -4
  35. package/src/index.ts +1 -0
  36. package/src/memberships/add-membership.test.ts +4 -4
  37. package/src/memberships/remove-membership.test.ts +4 -4
  38. package/src/memberships/update-membership.test.ts +6 -6
  39. package/src/moderations/open-moderation.test.ts +2 -2
  40. package/src/runtime/create-identite-runtime.test.ts +12 -59
  41. package/src/runtime/create-identite-runtime.ts +6 -2
  42. package/src/users/change-password.test.ts +2 -2
  43. package/src/users/delete-user.test.ts +4 -4
  44. package/src/users/reset-mfa.test.ts +5 -5
  45. package/src/users/update-personal-informations.test.ts +2 -2
  46. package/dist/domains/mark-domain-as-verified.d.ts +0 -25
  47. package/dist/domains/mark-domain-as-verified.d.ts.map +0 -1
  48. package/dist/domains/mark-domain-as-verified.js +0 -103
  49. package/src/domains/mark-domain-as-verified.ts +0 -174
@@ -1,25 +0,0 @@
1
- import type { RuntimeContext } from "#src/activity";
2
- import { type EmailDomainApprovedVerificationType } from "@proconnect-gouv/proconnect.identite/types";
3
- type MarkDomainAsVerifiedOutcome = {
4
- kind: "domain_verified";
5
- activity_id: number;
6
- email_domain: {
7
- id: number;
8
- verification_type: EmailDomainApprovedVerificationType;
9
- };
10
- promoted_members: ReadonlyArray<{
11
- previous_verification_type: string;
12
- user_id: number;
13
- }>;
14
- replaced_verification_types: ReadonlyArray<string>;
15
- } | {
16
- kind: "organization_not_found";
17
- organization_id: number;
18
- };
19
- export declare function markDomainAsVerifiedFactory({ actor, app, db, }: RuntimeContext): ({ domain, domain_verification_type, organization_id, }: {
20
- domain: string;
21
- domain_verification_type: EmailDomainApprovedVerificationType;
22
- organization_id: number;
23
- }) => Promise<MarkDomainAsVerifiedOutcome>;
24
- export {};
25
- //# sourceMappingURL=mark-domain-as-verified.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mark-domain-as-verified.d.ts","sourceRoot":"","sources":["../../src/domains/mark-domain-as-verified.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AAOtE,OAAO,EAKL,KAAK,mCAAmC,EACzC,MAAM,4CAA4C,CAAC;AAKpD,KAAK,2BAA2B,GAC5B;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,iBAAiB,EAAE,mCAAmC,CAAC;KACxD,CAAC;IACF,gBAAgB,EAAE,aAAa,CAAC;QAC9B,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;AAEhE,wBAAgB,2BAA2B,CAAC,EAC1C,KAAK,EACL,GAAG,EACH,EAAE,GACH,EAAE,cAAc,IACsB,wDAIlC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,mCAAmC,CAAC;IAC9D,eAAe,EAAE,MAAM,CAAC;CACzB,KAAG,OAAO,CAAC,2BAA2B,CAAC,CA4HzC"}
@@ -1,103 +0,0 @@
1
- //
2
- import { insertActivity } from "#src/journal";
3
- import { email_domains, users_organizations, } from "@proconnect-gouv/proconnect.identite.database/drizzle";
4
- import { getMemberIdsPromotedByDomain } 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 markDomainAsVerifiedFactory({ actor, app, db, }) {
8
- return function markDomainAsVerified({ domain, domain_verification_type, organization_id, }) {
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 memberships = await tx.query.users_organizations.findMany({
18
- columns: { user_id: true, verification_type: true },
19
- where: (table, { eq }) => eq(table.organization_id, organization_id),
20
- with: { user: { columns: { email: true } } },
21
- });
22
- const members = memberships.map(({ user: { email }, user_id, verification_type }) => ({
23
- email,
24
- id: user_id,
25
- verification_type,
26
- }));
27
- const promoted_member_ids = getMemberIdsPromotedByDomain({
28
- domain,
29
- members,
30
- });
31
- const promoted_members = memberships
32
- .filter(({ user_id }) => promoted_member_ids.includes(user_id))
33
- .map(({ user_id, verification_type }) => ({
34
- previous_verification_type: verification_type,
35
- user_id,
36
- }));
37
- const replaced = await tx
38
- .delete(email_domains)
39
- .where(and(eq(email_domains.organization_id, organization_id), eq(email_domains.domain, domain), inArray(email_domains.verification_type, [
40
- ...EmailDomainApprovedVerificationValues,
41
- ...EmailDomainPendingVerificationValues,
42
- ...EmailDomainRejectedVerificationValues,
43
- ])))
44
- .returning({ verification_type: email_domains.verification_type });
45
- const [email_domain] = await tx
46
- .insert(email_domains)
47
- .values({
48
- domain,
49
- organization_id,
50
- verification_type: domain_verification_type,
51
- verified_at: sql `now()`,
52
- })
53
- .returning({ id: email_domains.id });
54
- const replaced_verification_types = replaced.map(({ verification_type }) => verification_type);
55
- const { activity_id } = await insertActivity(tx, {
56
- action: "domain.verified",
57
- actor,
58
- app,
59
- context: {
60
- inputs: { domain, verification_type: domain_verification_type },
61
- outcome: {
62
- email_domain_id: email_domain.id,
63
- replaced_verification_types,
64
- },
65
- },
66
- organization_id,
67
- });
68
- if (promoted_member_ids.length > 0) {
69
- await tx
70
- .update(users_organizations)
71
- .set({
72
- updated_at: sql `now()`,
73
- verification_type: LinkEnum.enum.domain,
74
- })
75
- .where(and(eq(users_organizations.organization_id, organization_id), inArray(users_organizations.user_id, promoted_member_ids)));
76
- for (const { previous_verification_type, user_id, } of promoted_members) {
77
- await insertActivity(tx, {
78
- action: "member.promoted",
79
- actor: { type: "app", job: "domain.promote_members" },
80
- app,
81
- cause_activity_id: activity_id,
82
- context: {
83
- inputs: { previous_verification_type },
84
- outcome: { verification_type: LinkEnum.enum.domain },
85
- },
86
- organization_id,
87
- user_id,
88
- });
89
- }
90
- }
91
- return {
92
- kind: "domain_verified",
93
- activity_id,
94
- email_domain: {
95
- id: email_domain.id,
96
- verification_type: domain_verification_type,
97
- },
98
- promoted_members,
99
- replaced_verification_types,
100
- };
101
- });
102
- };
103
- }
@@ -1,174 +0,0 @@
1
- //
2
-
3
- import type { ActivityContexts, RuntimeContext } from "#src/activity";
4
- import { insertActivity } from "#src/journal";
5
- import {
6
- email_domains,
7
- users_organizations,
8
- } from "@proconnect-gouv/proconnect.identite.database/drizzle";
9
- import { getMemberIdsPromotedByDomain } from "@proconnect-gouv/proconnect.identite/services/organization";
10
- import {
11
- EmailDomainApprovedVerificationValues,
12
- EmailDomainPendingVerificationValues,
13
- EmailDomainRejectedVerificationValues,
14
- LinkEnum,
15
- type EmailDomainApprovedVerificationType,
16
- } from "@proconnect-gouv/proconnect.identite/types";
17
- import { and, eq, inArray, sql } from "drizzle-orm";
18
-
19
- //
20
-
21
- type MarkDomainAsVerifiedOutcome =
22
- | {
23
- kind: "domain_verified";
24
- activity_id: number;
25
- email_domain: {
26
- id: number;
27
- verification_type: EmailDomainApprovedVerificationType;
28
- };
29
- promoted_members: ReadonlyArray<{
30
- previous_verification_type: string;
31
- user_id: number;
32
- }>;
33
- replaced_verification_types: ReadonlyArray<string>;
34
- }
35
- | { kind: "organization_not_found"; organization_id: number };
36
-
37
- export function markDomainAsVerifiedFactory({
38
- actor,
39
- app,
40
- db,
41
- }: RuntimeContext) {
42
- return function markDomainAsVerified({
43
- domain,
44
- domain_verification_type,
45
- organization_id,
46
- }: {
47
- domain: string;
48
- domain_verification_type: EmailDomainApprovedVerificationType;
49
- organization_id: number;
50
- }): Promise<MarkDomainAsVerifiedOutcome> {
51
- return db.transaction(async (tx) => {
52
- const organization = await tx.query.organizations.findFirst({
53
- columns: { id: true },
54
- where: (table, { eq }) => eq(table.id, organization_id),
55
- });
56
-
57
- if (!organization) {
58
- return { kind: "organization_not_found", organization_id };
59
- }
60
-
61
- const memberships = await tx.query.users_organizations.findMany({
62
- columns: { user_id: true, verification_type: true },
63
- where: (table, { eq }) => eq(table.organization_id, organization_id),
64
- with: { user: { columns: { email: true } } },
65
- });
66
- const members = memberships.map(
67
- ({ user: { email }, user_id, verification_type }) => ({
68
- email,
69
- id: user_id,
70
- verification_type,
71
- }),
72
- );
73
-
74
- const promoted_member_ids = getMemberIdsPromotedByDomain({
75
- domain,
76
- members,
77
- });
78
-
79
- const promoted_members = memberships
80
- .filter(({ user_id }) => promoted_member_ids.includes(user_id))
81
- .map(({ user_id, verification_type }) => ({
82
- previous_verification_type: verification_type,
83
- user_id,
84
- }));
85
-
86
- const replaced = await tx
87
- .delete(email_domains)
88
- .where(
89
- and(
90
- eq(email_domains.organization_id, organization_id),
91
- eq(email_domains.domain, domain),
92
- inArray(email_domains.verification_type, [
93
- ...EmailDomainApprovedVerificationValues,
94
- ...EmailDomainPendingVerificationValues,
95
- ...EmailDomainRejectedVerificationValues,
96
- ]),
97
- ),
98
- )
99
- .returning({ verification_type: email_domains.verification_type });
100
-
101
- const [email_domain] = await tx
102
- .insert(email_domains)
103
- .values({
104
- domain,
105
- organization_id,
106
- verification_type: domain_verification_type,
107
- verified_at: sql`now()`,
108
- })
109
- .returning({ id: email_domains.id });
110
-
111
- const replaced_verification_types = replaced.map(
112
- ({ verification_type }) => verification_type,
113
- );
114
-
115
- const { activity_id } = await insertActivity<ActivityContexts>(tx, {
116
- action: "domain.verified",
117
- actor,
118
- app,
119
- context: {
120
- inputs: { domain, verification_type: domain_verification_type },
121
- outcome: {
122
- email_domain_id: email_domain.id,
123
- replaced_verification_types,
124
- },
125
- },
126
- organization_id,
127
- });
128
-
129
- if (promoted_member_ids.length > 0) {
130
- await tx
131
- .update(users_organizations)
132
- .set({
133
- updated_at: sql`now()`,
134
- verification_type: LinkEnum.enum.domain,
135
- })
136
- .where(
137
- and(
138
- eq(users_organizations.organization_id, organization_id),
139
- inArray(users_organizations.user_id, promoted_member_ids),
140
- ),
141
- );
142
-
143
- for (const {
144
- previous_verification_type,
145
- user_id,
146
- } of promoted_members) {
147
- await insertActivity<ActivityContexts>(tx, {
148
- action: "member.promoted",
149
- actor: { type: "app", job: "domain.promote_members" },
150
- app,
151
- cause_activity_id: activity_id,
152
- context: {
153
- inputs: { previous_verification_type },
154
- outcome: { verification_type: LinkEnum.enum.domain },
155
- },
156
- organization_id,
157
- user_id,
158
- });
159
- }
160
- }
161
-
162
- return {
163
- kind: "domain_verified",
164
- activity_id,
165
- email_domain: {
166
- id: email_domain.id,
167
- verification_type: domain_verification_type,
168
- },
169
- promoted_members,
170
- replaced_verification_types,
171
- };
172
- });
173
- };
174
- }