@proconnect-gouv/proconnect.identite 11.0.0 → 13.0.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/connectors/index.d.ts +0 -37
  3. package/dist/connectors/index.d.ts.map +1 -1
  4. package/dist/connectors/index.js +2 -4
  5. package/dist/managers/certification/process-certification-dirigeant.d.ts +28 -1
  6. package/dist/managers/certification/process-certification-dirigeant.d.ts.map +1 -1
  7. package/dist/managers/certification/process-certification-dirigeant.js +17 -5
  8. package/dist/managers/organization/get-organization-info.d.ts +21 -1
  9. package/dist/managers/organization/get-organization-info.d.ts.map +1 -1
  10. package/dist/managers/organization/get-organization-info.js +44 -41
  11. package/dist/managers/organization/index.d.ts +0 -1
  12. package/dist/managers/organization/index.d.ts.map +1 -1
  13. package/dist/managers/organization/index.js +0 -1
  14. package/dist/repositories/email-domain/index.d.ts +0 -3
  15. package/dist/repositories/email-domain/index.d.ts.map +1 -1
  16. package/dist/repositories/email-domain/index.js +0 -1
  17. package/dist/repositories/organization/index.d.ts +0 -1
  18. package/dist/repositories/organization/index.d.ts.map +1 -1
  19. package/dist/repositories/organization/index.js +0 -1
  20. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts +9 -0
  21. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts.map +1 -0
  22. package/dist/services/organization/get-member-ids-promoted-by-domain.js +11 -0
  23. package/dist/services/organization/index.d.ts +1 -0
  24. package/dist/services/organization/index.d.ts.map +1 -1
  25. package/dist/services/organization/index.js +1 -0
  26. package/package.json +1 -1
  27. package/src/connectors/index.ts +0 -5
  28. package/src/managers/certification/process-certification-dirigeant.test.ts +12 -1
  29. package/src/managers/certification/process-certification-dirigeant.ts +23 -4
  30. package/src/managers/organization/get-organization-info.test.ts +75 -4
  31. package/src/managers/organization/get-organization-info.test.ts.snapshot +104 -80
  32. package/src/managers/organization/get-organization-info.ts +63 -56
  33. package/src/managers/organization/index.ts +0 -1
  34. package/src/repositories/email-domain/index.ts +0 -3
  35. package/src/repositories/organization/index.ts +0 -1
  36. package/src/services/organization/get-member-ids-promoted-by-domain.test.ts +100 -0
  37. package/src/services/organization/get-member-ids-promoted-by-domain.ts +27 -0
  38. package/src/services/organization/index.ts +1 -0
  39. package/dist/managers/organization/mark-domain-as-verified.d.ts +0 -18
  40. package/dist/managers/organization/mark-domain-as-verified.d.ts.map +0 -1
  41. package/dist/managers/organization/mark-domain-as-verified.js +0 -64
  42. package/dist/managers/user/assign-user-verification-type-to-domain.d.ts +0 -3
  43. package/dist/managers/user/assign-user-verification-type-to-domain.d.ts.map +0 -1
  44. package/dist/managers/user/assign-user-verification-type-to-domain.js +0 -20
  45. package/dist/managers/user/index.d.ts +0 -2
  46. package/dist/managers/user/index.d.ts.map +0 -1
  47. package/dist/managers/user/index.js +0 -1
  48. package/dist/repositories/email-domain/delete-email-domains-by-verification-types.d.ts +0 -8
  49. package/dist/repositories/email-domain/delete-email-domains-by-verification-types.d.ts.map +0 -1
  50. package/dist/repositories/email-domain/delete-email-domains-by-verification-types.js +0 -19
  51. package/dist/repositories/organization/find-users-by-organization.d.ts +0 -34
  52. package/dist/repositories/organization/find-users-by-organization.d.ts.map +0 -1
  53. package/dist/repositories/organization/find-users-by-organization.js +0 -16
  54. package/src/managers/organization/mark-domain-as-verified.test.ts +0 -250
  55. package/src/managers/organization/mark-domain-as-verified.ts +0 -123
  56. package/src/managers/user/assign-user-verification-type-to-domain.test.ts +0 -105
  57. package/src/managers/user/assign-user-verification-type-to-domain.ts +0 -40
  58. package/src/managers/user/index.ts +0 -1
  59. package/src/repositories/email-domain/delete-email-domains-by-verification-types.test.ts +0 -49
  60. package/src/repositories/email-domain/delete-email-domains-by-verification-types.ts +0 -45
  61. package/src/repositories/organization/find-users-by-organization.test.ts +0 -51
  62. package/src/repositories/organization/find-users-by-organization.test.ts.snapshot +0 -35
  63. package/src/repositories/organization/find-users-by-organization.ts +0 -30
@@ -1,123 +0,0 @@
1
- //
2
-
3
- import type { Context } from "#src/connectors";
4
- import { NotFoundError } from "#src/errors";
5
- import { assignUserVerificationTypeToDomainFactory } from "#src/managers/user";
6
- import {
7
- type EmailDomainApprovedVerificationType,
8
- EmailDomainApprovedVerificationValues,
9
- type EmailDomainNoPendingVerificationType,
10
- EmailDomainPendingVerificationValues,
11
- type EmailDomainRejectedVerificationType,
12
- EmailDomainRejectedVerificationValues,
13
- type EmailDomainVerificationType,
14
- } from "#src/types";
15
-
16
- import { isEmpty } from "lodash-es";
17
- import { match } from "ts-pattern";
18
-
19
- //
20
-
21
- export function markDomainAsVerifiedFactory(context: Context) {
22
- const assignUserVerificationTypeToDomain =
23
- assignUserVerificationTypeToDomainFactory(context);
24
-
25
- const {
26
- repository: { email_domains, organizations },
27
- } = context;
28
-
29
- return async function markDomainAsVerified({
30
- organization_id,
31
- domain,
32
- domain_verification_type,
33
- }: {
34
- organization_id: number;
35
- domain: string;
36
- domain_verification_type: EmailDomainNoPendingVerificationType;
37
- }) {
38
- const organization = await organizations.findById(organization_id);
39
-
40
- if (isEmpty(organization)) {
41
- throw new NotFoundError();
42
- }
43
-
44
- return match(domain_verification_type)
45
- .with(
46
- ...EmailDomainApprovedVerificationValues,
47
- async (approved_verification_type) => {
48
- await assignUserVerificationTypeToDomain(organization_id, domain);
49
- return markDomainAsApproved({
50
- organization_id,
51
- domain,
52
- domain_verification_type: approved_verification_type,
53
- });
54
- },
55
- )
56
- .with(
57
- ...EmailDomainRejectedVerificationValues,
58
- (rejected_verification_type) =>
59
- markDomainAsRejected({
60
- organization_id,
61
- domain,
62
- domain_verification_type: rejected_verification_type,
63
- }),
64
- )
65
- .exhaustive();
66
- };
67
-
68
- async function markDomainAsApproved({
69
- organization_id,
70
- domain,
71
- domain_verification_type,
72
- }: {
73
- organization_id: number;
74
- domain: string;
75
- domain_verification_type: EmailDomainApprovedVerificationType;
76
- }) {
77
- await email_domains.deleteEmailDomainsByVerificationTypes({
78
- organization_id,
79
- domain,
80
- domain_verification_types: [
81
- ...EmailDomainApprovedVerificationValues,
82
- ...EmailDomainPendingVerificationValues,
83
- ...EmailDomainRejectedVerificationValues,
84
- ],
85
- });
86
- return email_domains.addDomain({
87
- organization_id,
88
- domain,
89
- verification_type:
90
- domain_verification_type as EmailDomainVerificationType,
91
- });
92
- }
93
-
94
- async function markDomainAsRejected({
95
- organization_id,
96
- domain,
97
- domain_verification_type,
98
- }: {
99
- organization_id: number;
100
- domain: string;
101
- domain_verification_type: EmailDomainRejectedVerificationType;
102
- }) {
103
- await email_domains.deleteEmailDomainsByVerificationTypes({
104
- organization_id,
105
- domain,
106
- domain_verification_types: [
107
- ...EmailDomainApprovedVerificationValues,
108
- ...EmailDomainPendingVerificationValues,
109
- ...EmailDomainRejectedVerificationValues,
110
- ],
111
- });
112
- return email_domains.addDomain({
113
- organization_id,
114
- domain,
115
- verification_type:
116
- domain_verification_type as EmailDomainVerificationType,
117
- });
118
- }
119
- }
120
-
121
- export type MarkDomainAsVerifiedHandler = ReturnType<
122
- typeof markDomainAsVerifiedFactory
123
- >;
@@ -1,105 +0,0 @@
1
- //
2
-
3
- import { context, emptyDatabase, migrate, pg } from "#testing";
4
- import assert from "node:assert/strict";
5
- import { before, beforeEach, describe, it } from "node:test";
6
- import { assignUserVerificationTypeToDomainFactory } from "./assign-user-verification-type-to-domain.js";
7
-
8
- //
9
-
10
- const assignUserVerificationTypeToDomain =
11
- assignUserVerificationTypeToDomainFactory(context);
12
-
13
- describe("assignUserVerificationTypeToDomain", () => {
14
- before(migrate);
15
- beforeEach(emptyDatabase);
16
-
17
- it("should update some organization members", async () => {
18
- await pg.sql`
19
- INSERT INTO organizations
20
- (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
21
- VALUES
22
- (1, 'Dark Angels', 'Dark Angels Legion', '🦁', '4444-04-04', '4444-04-04')
23
- ;
24
- `;
25
- // user from a different domain — should not be updated
26
- await pg.sql`
27
- INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
28
- VALUES (1, 'foo@bar.world', '4444-04-04', '4444-04-04', 'Foo', 'Bar', '0', 'None')
29
- `;
30
- // user matching domain but already "verified" — should not be updated
31
- await pg.sql`
32
- INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
33
- VALUES (2, 'foo@darkangels.world', '4444-04-04', '4444-04-04', 'Foo', 'DA', '0', 'None')
34
- `;
35
- // user with no_validation_means_available — should be updated
36
- await pg.sql`
37
- INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
38
- VALUES (3, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', '0', 'Primarque')
39
- `;
40
- // user with no_verification_means_for_entreprise_unipersonnelle — should be updated
41
- await pg.sql`
42
- INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
43
- VALUES (4, 'cat.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Cat', 'El''Jonson', '0', 'Scout')
44
- `;
45
- // user with no_verification_means_for_small_association — should be updated
46
- await pg.sql`
47
- INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
48
- VALUES (5, 'tiger.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Tiger', 'El''Jonson', '0', 'Scout')
49
- `;
50
- // user with domain_not_verified_yet — should be updated
51
- await pg.sql`
52
- INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
53
- VALUES (6, 'mouse.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Mouse', 'El''Jonson', '0', 'Scout')
54
- `;
55
-
56
- // link all users to the organization
57
- await pg.sql`
58
- INSERT INTO users_organizations
59
- (user_id, organization_id, created_at, updated_at, is_external, verification_type)
60
- VALUES (1, 1, '4444-04-04', '4444-04-04', false, 'no_validation_means_available'),
61
- (2, 1, '4444-04-04', '4444-04-04', false, 'verified'),
62
- (3, 1, '4444-04-04', '4444-04-04', false, 'no_validation_means_available'),
63
- (4, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle'),
64
- (5, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_small_association'),
65
- (6, 1, '4444-04-04', '4444-04-04', false, 'domain_not_verified_yet')
66
- ;
67
- `;
68
-
69
- await assignUserVerificationTypeToDomain(1, "darkangels.world");
70
-
71
- // verify that the 4 matching users were updated to "domain"
72
- const { rows } = await pg.sql`
73
- SELECT user_id, verification_type
74
- FROM users_organizations
75
- WHERE organization_id = 1
76
- ORDER BY user_id
77
- `;
78
-
79
- assert.deepEqual(rows, [
80
- { user_id: 1, verification_type: "no_validation_means_available" }, // different domain
81
- { user_id: 2, verification_type: "verified" }, // already verified
82
- { user_id: 3, verification_type: "domain" },
83
- { user_id: 4, verification_type: "domain" },
84
- { user_id: 5, verification_type: "domain" },
85
- { user_id: 6, verification_type: "domain" },
86
- ]);
87
- });
88
-
89
- it("❎ should update nothing if no organization members", async () => {
90
- await pg.sql`
91
- INSERT INTO organizations
92
- (id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
93
- VALUES
94
- (1, 'Empty', 'Empty Org', '🫥', '4444-04-04', '4444-04-04')
95
- ;
96
- `;
97
-
98
- await assignUserVerificationTypeToDomain(1, "darkangels.world");
99
-
100
- const { rows } = await pg.sql`
101
- SELECT * FROM users_organizations WHERE organization_id = 1
102
- `;
103
- assert.deepEqual(rows, []);
104
- });
105
- });
@@ -1,40 +0,0 @@
1
- //
2
-
3
- import type { Context } from "#src/connectors";
4
- import { LinkEnum, SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
5
- import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
6
-
7
- //
8
-
9
- export function assignUserVerificationTypeToDomainFactory({
10
- repository: { organizations, users_organizations },
11
- }: Context) {
12
- return async function assignUserVerificationTypeToDomain(
13
- organization_id: number,
14
- domain: string,
15
- ) {
16
- const usersInOrganization = await organizations.findUsers(organization_id);
17
-
18
- await Promise.all(
19
- usersInOrganization.map(
20
- ({ id: user_id, email, verification_type: link_verification_type }) => {
21
- const userDomain = getEmailDomain(email);
22
- if (
23
- userDomain === domain &&
24
- (UnverifiedLinkEnum.safeParse(link_verification_type).success ||
25
- SuperWeakLinkEnum.safeParse(link_verification_type).success)
26
- ) {
27
- return users_organizations.update(
28
- { organization_id, user_id },
29
- {
30
- verification_type: LinkEnum.enum.domain,
31
- },
32
- );
33
- }
34
-
35
- return null;
36
- },
37
- ),
38
- );
39
- };
40
- }
@@ -1 +0,0 @@
1
- export * from "./assign-user-verification-type-to-domain.js";
@@ -1,49 +0,0 @@
1
- //
2
-
3
- import { emptyDatabase, migrate, pg } from "#testing";
4
- import assert from "node:assert/strict";
5
- import { before, beforeEach, describe, it } from "node:test";
6
- import { deleteEmailDomainsByVerificationTypesFactory } from "./delete-email-domains-by-verification-types.js";
7
-
8
- //
9
-
10
- const deleteEmailDomainsByVerificationTypes =
11
- deleteEmailDomainsByVerificationTypesFactory({
12
- pg: pg as any,
13
- });
14
-
15
- describe("deleteEmailDomainsByVerificationTypesFactory", function () {
16
- before(migrate);
17
- beforeEach(emptyDatabase);
18
-
19
- it("should delete domain verification type NULL and 'verified'", async () => {
20
- await pg.sql`
21
- INSERT INTO organizations
22
- (id, siret, created_at, updated_at)
23
- VALUES
24
- (1, '66204244933106', '3333-03-03', '3333-04-04')
25
- ;
26
- `;
27
-
28
- await pg.sql`
29
- INSERT INTO email_domains
30
- (domain, organization_id, verification_type)
31
- VALUES
32
- ('darkangels.world', 1, 'not_verified_yet'),
33
- ('darkangels.world', 1, 'verified')
34
- ;
35
- `;
36
-
37
- const result = await deleteEmailDomainsByVerificationTypes({
38
- domain: "darkangels.world",
39
- organization_id: 1,
40
- domain_verification_types: ["not_verified_yet", "verified"],
41
- });
42
-
43
- assert.deepEqual(result, {
44
- affectedRows: 2,
45
- fields: [],
46
- rows: [],
47
- });
48
- });
49
- });
@@ -1,45 +0,0 @@
1
- //
2
-
3
- import type {
4
- DatabaseContext,
5
- EmailDomain,
6
- EmailDomainVerificationType,
7
- } from "#src/types";
8
-
9
- //
10
-
11
- export function deleteEmailDomainsByVerificationTypesFactory({
12
- pg,
13
- }: DatabaseContext) {
14
- return async function deleteEmailDomainsByVerificationTypes({
15
- organization_id,
16
- domain,
17
- domain_verification_types,
18
- }: {
19
- organization_id: EmailDomain["organization_id"];
20
- domain_verification_types: EmailDomainVerificationType[];
21
- domain: EmailDomain["domain"];
22
- }) {
23
- const SQL_VERIFICATION_TYPES = domain_verification_types
24
- .map((type) => `verification_type = '${type}'`)
25
- .join(" OR ");
26
-
27
- return pg.query(
28
- `
29
- DELETE FROM email_domains
30
- WHERE
31
- ${[
32
- "organization_id = $1",
33
- "domain = $2",
34
- `(${SQL_VERIFICATION_TYPES})`,
35
- ].join(" AND ")}
36
- ;
37
- `,
38
- [organization_id, domain],
39
- );
40
- };
41
- }
42
-
43
- export type DeleteEmailDomainsByVerificationTypesHandler = ReturnType<
44
- typeof deleteEmailDomainsByVerificationTypesFactory
45
- >;
@@ -1,51 +0,0 @@
1
- //
2
-
3
- import { emptyDatabase, migrate, pg } from "#testing";
4
- import assert from "node:assert/strict";
5
- import { before, beforeEach, describe, it } from "node:test";
6
- import { findUsersByOrganizationFactory } from "./find-users-by-organization.js";
7
-
8
- //
9
-
10
- const findUsersByOrganization = findUsersByOrganizationFactory({
11
- pg: pg as any,
12
- });
13
-
14
- describe("findUsersByOrganizationFactory", () => {
15
- before(migrate);
16
- beforeEach(emptyDatabase);
17
-
18
- it("should find users by organization id", async (t) => {
19
- await pg.sql`
20
- INSERT INTO organizations
21
- (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
22
- VALUES
23
- ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
24
- ;
25
- `;
26
-
27
- await pg.sql`
28
- INSERT INTO users
29
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
30
- VALUES
31
- (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
32
- ;
33
- `;
34
-
35
- await pg.sql`
36
- INSERT INTO users_organizations
37
- (user_id, organization_id, created_at, updated_at, is_external, verification_type)
38
- VALUES (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_available')
39
- ;
40
- `;
41
-
42
- const user = await findUsersByOrganization(1);
43
-
44
- t.assert.snapshot(user);
45
- });
46
-
47
- it("❎ fail to find users for unknown organization id", async () => {
48
- const user = await findUsersByOrganization(42);
49
- assert.deepEqual(user, []);
50
- });
51
- });
@@ -1,35 +0,0 @@
1
- exports[`findUsersByOrganizationFactory > should find users by organization id 1`] = `
2
- [
3
- {
4
- "id": 1,
5
- "email": "lion.eljonson@darkangels.world",
6
- "encrypted_password": null,
7
- "reset_password_token": null,
8
- "reset_password_sent_at": null,
9
- "sign_in_count": 0,
10
- "last_sign_in_at": null,
11
- "created_at": "4444-04-04T00:00:00.000Z",
12
- "updated_at": "4444-04-04T00:00:00.000Z",
13
- "email_verified": false,
14
- "verify_email_token": null,
15
- "verify_email_sent_at": null,
16
- "given_name": "lion",
17
- "family_name": "el'jonson",
18
- "phone_number": "i",
19
- "job": "primarque",
20
- "magic_link_token": null,
21
- "magic_link_sent_at": null,
22
- "email_verified_at": null,
23
- "current_challenge": null,
24
- "needs_inclusionconnect_welcome_page": false,
25
- "needs_inclusionconnect_onboarding_help": false,
26
- "encrypted_totp_key": null,
27
- "totp_key_verified_at": null,
28
- "force_2fa": false,
29
- "is_external": false,
30
- "verification_type": "no_verification_means_available",
31
- "verified_at": null,
32
- "has_been_greeted": false
33
- }
34
- ]
35
- `;
@@ -1,30 +0,0 @@
1
- //
2
-
3
- import type {
4
- BaseUserOrganizationLink,
5
- DatabaseContext,
6
- User,
7
- } from "#src/types";
8
- import type { QueryResult } from "pg";
9
-
10
- //
11
-
12
- export function findUsersByOrganizationFactory({ pg }: DatabaseContext) {
13
- return async function findUsersByOrganization(organization_id: number) {
14
- const { rows }: QueryResult<User & BaseUserOrganizationLink> =
15
- await pg.query(
16
- `
17
- SELECT u.*,
18
- uo.is_external,
19
- uo.verification_type,
20
- uo.verified_at,
21
- uo.has_been_greeted
22
- FROM users u
23
- INNER JOIN users_organizations AS uo ON uo.user_id = u.id
24
- WHERE uo.organization_id = $1`,
25
- [organization_id],
26
- );
27
-
28
- return rows;
29
- };
30
- }