@proconnect-gouv/proconnect.identite 15.0.0 → 17.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 (101) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/connectors/index.d.ts +2 -72
  3. package/dist/connectors/index.d.ts.map +1 -1
  4. package/dist/connectors/index.js +5 -14
  5. package/dist/managers/certification/certification-score.d.ts +16 -0
  6. package/dist/managers/certification/certification-score.d.ts.map +1 -1
  7. package/dist/managers/certification/certification-score.js +65 -41
  8. package/dist/managers/certification/process-certification-dirigeant.d.ts.map +1 -1
  9. package/dist/managers/organization/get-organization-info.d.ts.map +1 -1
  10. package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.d.ts +3 -0
  11. package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.d.ts.map +1 -0
  12. package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.js +12 -0
  13. package/dist/repositories/authenticator/index.d.ts +1 -1
  14. package/dist/repositories/authenticator/index.d.ts.map +1 -1
  15. package/dist/repositories/authenticator/index.js +1 -1
  16. package/dist/repositories/moderation/index.d.ts +0 -2
  17. package/dist/repositories/moderation/index.d.ts.map +1 -1
  18. package/dist/repositories/moderation/index.js +0 -2
  19. package/dist/repositories/oidc-client/upsert-authorization-request.d.ts +1 -1
  20. package/dist/repositories/oidc-client/upsert-authorization-request.d.ts.map +1 -1
  21. package/dist/repositories/oidc-client/upsert-authorization-request.js +6 -4
  22. package/dist/repositories/organization/index.d.ts +0 -2
  23. package/dist/repositories/organization/index.d.ts.map +1 -1
  24. package/dist/repositories/organization/index.js +0 -2
  25. package/dist/repositories/user/index.d.ts +0 -1
  26. package/dist/repositories/user/index.d.ts.map +1 -1
  27. package/dist/repositories/user/index.js +0 -1
  28. package/dist/services/organization/get-membership-changes-by-domain-verification.d.ts +18 -0
  29. package/dist/services/organization/get-membership-changes-by-domain-verification.d.ts.map +1 -0
  30. package/dist/services/organization/get-membership-changes-by-domain-verification.js +21 -0
  31. package/dist/services/organization/index.d.ts +1 -1
  32. package/dist/services/organization/index.d.ts.map +1 -1
  33. package/dist/services/organization/index.js +1 -1
  34. package/dist/types/authenticator.d.ts.map +1 -1
  35. package/dist/types/authorization-request.d.ts +2 -0
  36. package/dist/types/authorization-request.d.ts.map +1 -1
  37. package/dist/types/authorization-request.js +4 -1
  38. package/package.json +2 -2
  39. package/src/connectors/index.ts +2 -17
  40. package/src/managers/certification/certification-score.test.ts +64 -1
  41. package/src/managers/certification/certification-score.ts +84 -50
  42. package/src/managers/certification/process-certification-dirigeant.ts +1 -2
  43. package/src/managers/organization/get-organization-info.ts +1 -2
  44. package/src/repositories/authenticator/delete-all-authenticators-by-user-id.test.ts +51 -0
  45. package/src/repositories/authenticator/delete-all-authenticators-by-user-id.ts +22 -0
  46. package/src/repositories/authenticator/index.ts +1 -1
  47. package/src/repositories/moderation/index.ts +0 -2
  48. package/src/repositories/oidc-client/upsert-authorization-request.test.ts +18 -5
  49. package/src/repositories/oidc-client/upsert-authorization-request.ts +6 -3
  50. package/src/repositories/organization/index.ts +0 -2
  51. package/src/repositories/user/index.ts +0 -1
  52. package/src/services/organization/get-membership-changes-by-domain-verification.test.ts +91 -0
  53. package/src/services/organization/get-membership-changes-by-domain-verification.ts +46 -0
  54. package/src/services/organization/index.ts +1 -1
  55. package/src/types/authenticator.ts +1 -7
  56. package/src/types/authorization-request.ts +5 -1
  57. package/testing/index.ts +2 -1
  58. package/dist/repositories/authenticator/update-authenticator.d.ts +0 -3
  59. package/dist/repositories/authenticator/update-authenticator.d.ts.map +0 -1
  60. package/dist/repositories/authenticator/update-authenticator.js +0 -13
  61. package/dist/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.d.ts +0 -3
  62. package/dist/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.d.ts.map +0 -1
  63. package/dist/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.js +0 -15
  64. package/dist/repositories/email-deliverability-whitelist/index.d.ts +0 -2
  65. package/dist/repositories/email-deliverability-whitelist/index.d.ts.map +0 -1
  66. package/dist/repositories/email-deliverability-whitelist/index.js +0 -2
  67. package/dist/repositories/moderation/find-pending-moderation.d.ts +0 -20
  68. package/dist/repositories/moderation/find-pending-moderation.d.ts.map +0 -1
  69. package/dist/repositories/moderation/find-pending-moderation.js +0 -16
  70. package/dist/repositories/moderation/find-rejected-moderation.d.ts +0 -20
  71. package/dist/repositories/moderation/find-rejected-moderation.d.ts.map +0 -1
  72. package/dist/repositories/moderation/find-rejected-moderation.js +0 -17
  73. package/dist/repositories/organization/find-by-siret.d.ts +0 -3
  74. package/dist/repositories/organization/find-by-siret.d.ts.map +0 -1
  75. package/dist/repositories/organization/find-by-siret.js +0 -13
  76. package/dist/repositories/organization/find-pending-by-user-id.d.ts +0 -6
  77. package/dist/repositories/organization/find-pending-by-user-id.d.ts.map +0 -1
  78. package/dist/repositories/organization/find-pending-by-user-id.js +0 -18
  79. package/dist/repositories/user/find-by-reset-password-token.d.ts +0 -29
  80. package/dist/repositories/user/find-by-reset-password-token.d.ts.map +0 -1
  81. package/dist/repositories/user/find-by-reset-password-token.js +0 -12
  82. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts +0 -9
  83. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts.map +0 -1
  84. package/dist/services/organization/get-member-ids-promoted-by-domain.js +0 -11
  85. package/src/repositories/authenticator/update-authenticator.test.ts +0 -41
  86. package/src/repositories/authenticator/update-authenticator.ts +0 -29
  87. package/src/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.test.ts +0 -45
  88. package/src/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.ts +0 -24
  89. package/src/repositories/email-deliverability-whitelist/index.ts +0 -3
  90. package/src/repositories/moderation/find-pending-moderation.test.ts +0 -57
  91. package/src/repositories/moderation/find-pending-moderation.ts +0 -35
  92. package/src/repositories/moderation/find-rejected-moderation.test.ts +0 -57
  93. package/src/repositories/moderation/find-rejected-moderation.ts +0 -37
  94. package/src/repositories/organization/find-by-siret.test.ts +0 -35
  95. package/src/repositories/organization/find-by-siret.ts +0 -21
  96. package/src/repositories/organization/find-pending-by-user-id.test.ts +0 -51
  97. package/src/repositories/organization/find-pending-by-user-id.ts +0 -27
  98. package/src/repositories/user/find-by-reset-password-token.test.ts +0 -37
  99. package/src/repositories/user/find-by-reset-password-token.ts +0 -20
  100. package/src/services/organization/get-member-ids-promoted-by-domain.test.ts +0 -100
  101. package/src/services/organization/get-member-ids-promoted-by-domain.ts +0 -27
@@ -1,57 +0,0 @@
1
- //
2
-
3
- import { emptyDatabase, migrate, pg } from "#testing";
4
- import assert from "node:assert/strict";
5
- import { before, beforeEach, suite, test } from "node:test";
6
- import { findPendingModerationFactory } from "./find-pending-moderation.js";
7
-
8
- //
9
-
10
- const findPendingModeration = findPendingModerationFactory({ pg: pg as any });
11
-
12
- suite("findPendingModerationFactory", () => {
13
- before(migrate);
14
- beforeEach(emptyDatabase);
15
-
16
- test("should return undefined when no pending moderation exists", async () => {
17
- const moderation = await findPendingModeration({
18
- user_id: 1,
19
- organization_id: 1,
20
- type: "organization_join_block",
21
- });
22
-
23
- assert.equal(moderation, undefined);
24
- });
25
-
26
- test("should return the pending moderation", async () => {
27
- await pg.sql`
28
- INSERT INTO organizations
29
- (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
30
- VALUES
31
- ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
32
- ;
33
- `;
34
- await pg.sql`
35
- INSERT INTO users
36
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
37
- VALUES
38
- (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
39
- ;
40
- `;
41
- await pg.sql`
42
- INSERT INTO moderations
43
- (id, user_id, organization_id, type, status, created_at)
44
- VALUES
45
- (1, 1, 1, 'organization_join_block', 'pending', '4444-04-04')
46
- ;
47
- `;
48
-
49
- const moderation = await findPendingModeration({
50
- user_id: 1,
51
- organization_id: 1,
52
- type: "organization_join_block",
53
- });
54
-
55
- assert.equal(moderation?.id, 1);
56
- });
57
- });
@@ -1,35 +0,0 @@
1
- //
2
-
3
- import {
4
- type DatabaseContext,
5
- type Moderation,
6
- type ModerationType,
7
- } from "#src/types";
8
- import { type QueryResult } from "pg";
9
-
10
- //
11
-
12
- export function findPendingModerationFactory({ pg }: DatabaseContext) {
13
- return async function findPendingModeration({
14
- user_id,
15
- organization_id,
16
- type,
17
- }: {
18
- user_id: number;
19
- organization_id: number;
20
- type: ModerationType;
21
- }) {
22
- const { rows }: QueryResult<Moderation> = await pg.query(
23
- `
24
- SELECT *
25
- FROM moderations
26
- WHERE user_id = $1
27
- AND organization_id = $2
28
- AND type = $3
29
- AND moderated_at IS NULL;`,
30
- [user_id, organization_id, type],
31
- );
32
-
33
- return rows.shift();
34
- };
35
- }
@@ -1,57 +0,0 @@
1
- //
2
-
3
- import { emptyDatabase, migrate, pg } from "#testing";
4
- import assert from "node:assert/strict";
5
- import { before, beforeEach, suite, test } from "node:test";
6
- import { findRejectedModerationFactory } from "./find-rejected-moderation.js";
7
-
8
- //
9
-
10
- const findRejectedModeration = findRejectedModerationFactory({ pg: pg as any });
11
-
12
- suite("findRejectedModerationFactory", () => {
13
- before(migrate);
14
- beforeEach(emptyDatabase);
15
-
16
- test("should return undefined when no rejected moderation exists", async () => {
17
- const moderation = await findRejectedModeration({
18
- user_id: 1,
19
- organization_id: 1,
20
- type: "organization_join_block",
21
- });
22
-
23
- assert.equal(moderation, undefined);
24
- });
25
-
26
- test("should return the rejected moderation", async () => {
27
- await pg.sql`
28
- INSERT INTO organizations
29
- (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
30
- VALUES
31
- ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
32
- ;
33
- `;
34
- await pg.sql`
35
- INSERT INTO users
36
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
37
- VALUES
38
- (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
39
- ;
40
- `;
41
- await pg.sql`
42
- INSERT INTO moderations
43
- (id, user_id, organization_id, type, status, moderated_at, created_at)
44
- VALUES
45
- (1, 1, 1, 'organization_join_block', 'rejected', '4444-04-04', '4444-04-04')
46
- ;
47
- `;
48
-
49
- const moderation = await findRejectedModeration({
50
- user_id: 1,
51
- organization_id: 1,
52
- type: "organization_join_block",
53
- });
54
-
55
- assert.equal(moderation?.id, 1);
56
- });
57
- });
@@ -1,37 +0,0 @@
1
- //
2
-
3
- import {
4
- ModerationStatusSchema,
5
- type DatabaseContext,
6
- type Moderation,
7
- type ModerationType,
8
- } from "#src/types";
9
- import { type QueryResult } from "pg";
10
-
11
- //
12
-
13
- export function findRejectedModerationFactory({ pg }: DatabaseContext) {
14
- return async function findRejectedModeration({
15
- user_id,
16
- organization_id,
17
- type,
18
- }: {
19
- user_id: number;
20
- organization_id: number;
21
- type: ModerationType;
22
- }) {
23
- const { rows }: QueryResult<Moderation> = await pg.query(
24
- `
25
- SELECT *
26
- FROM moderations
27
- WHERE user_id = $1
28
- AND organization_id = $2
29
- AND type = $3
30
- AND moderated_at IS NOT NULL
31
- AND status = $4;`,
32
- [user_id, organization_id, type, ModerationStatusSchema.enum.rejected],
33
- );
34
-
35
- return rows.shift();
36
- };
37
- }
@@ -1,35 +0,0 @@
1
- //
2
-
3
- import { emptyDatabase, migrate, pg } from "#testing";
4
- import assert from "node:assert/strict";
5
- import { before, beforeEach, suite, test } from "node:test";
6
- import { findBySiretFactory } from "./find-by-siret.js";
7
-
8
- //
9
-
10
- const findBySiret = findBySiretFactory({ pg: pg as any });
11
-
12
- suite("findBySiretFactory", () => {
13
- before(migrate);
14
- beforeEach(emptyDatabase);
15
-
16
- test("should find the organization by siret", async () => {
17
- await pg.sql`
18
- INSERT INTO organizations
19
- (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
20
- VALUES
21
- ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
22
- ;
23
- `;
24
-
25
- const organization = await findBySiret("⚰️");
26
-
27
- assert.equal(organization?.id, 1);
28
- });
29
-
30
- test("should return undefined when siret does not exist", async () => {
31
- const organization = await findBySiret("absent");
32
-
33
- assert.equal(organization, undefined);
34
- });
35
- });
@@ -1,21 +0,0 @@
1
- //
2
-
3
- import type { DatabaseContext, Organization } from "#src/types";
4
- import { type QueryResult } from "pg";
5
-
6
- //
7
-
8
- export function findBySiretFactory({ pg }: DatabaseContext) {
9
- return async function findBySiret(siret: string) {
10
- const { rows }: QueryResult<Organization> = await pg.query(
11
- `
12
- SELECT *
13
- FROM organizations
14
- WHERE siret = $1
15
- `,
16
- [siret],
17
- );
18
-
19
- return rows.shift();
20
- };
21
- }
@@ -1,51 +0,0 @@
1
- //
2
-
3
- import { emptyDatabase, migrate, pg } from "#testing";
4
- import assert from "node:assert/strict";
5
- import { before, beforeEach, suite, test } from "node:test";
6
- import { findPendingByUserIdFactory } from "./find-pending-by-user-id.js";
7
-
8
- //
9
-
10
- const findPendingByUserId = findPendingByUserIdFactory({ pg: pg as any });
11
-
12
- suite("findPendingByUserIdFactory", () => {
13
- before(migrate);
14
- beforeEach(emptyDatabase);
15
-
16
- test("should return empty array when user has no pending moderations", async () => {
17
- const organizations = await findPendingByUserId(42);
18
-
19
- assert.deepEqual(organizations, []);
20
- });
21
-
22
- test("should return pending organizations for a user", async () => {
23
- await pg.sql`
24
- INSERT INTO organizations
25
- (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
26
- VALUES
27
- ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
28
- ;
29
- `;
30
- await pg.sql`
31
- INSERT INTO users
32
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
33
- VALUES
34
- (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
35
- ;
36
- `;
37
- await pg.sql`
38
- INSERT INTO moderations
39
- (id, user_id, organization_id, type, created_at, moderated_at, comment)
40
- VALUES
41
- (1, 1, 1, 'organization_join_block', '4444-04-04', NULL, 'pending')
42
- ;
43
- `;
44
-
45
- const organizations = await findPendingByUserId(1);
46
-
47
- assert.equal(organizations.length, 1);
48
- assert.equal(organizations[0]?.id, 1);
49
- assert.equal(organizations[0]?.moderation_id, 1);
50
- });
51
- });
@@ -1,27 +0,0 @@
1
- //
2
-
3
- import type { DatabaseContext } from "#src/types";
4
- import { ModerationTypeSchema, type Organization } from "#src/types";
5
- import { type QueryResult } from "pg";
6
-
7
- //
8
-
9
- export function findPendingByUserIdFactory({ pg }: DatabaseContext) {
10
- return async function findPendingByUserId(user_id: number) {
11
- const { rows }: QueryResult<Organization & { moderation_id: number }> =
12
- await pg.query(
13
- `
14
- SELECT o.*, m.id as moderation_id
15
- FROM moderations m
16
- INNER JOIN organizations o on o.id = m.organization_id
17
- WHERE m.user_id = $1
18
- AND m.type = $2
19
- AND m.moderated_at IS NULL
20
- ORDER BY m.created_at
21
- `,
22
- [user_id, ModerationTypeSchema.enum.organization_join_block],
23
- );
24
-
25
- return rows;
26
- };
27
- }
@@ -1,37 +0,0 @@
1
- //
2
-
3
- import { emptyDatabase, migrate, pg } from "#testing";
4
- import assert from "node:assert/strict";
5
- import { before, beforeEach, suite, test } from "node:test";
6
- import { findByResetPasswordTokenFactory } from "./find-by-reset-password-token.js";
7
-
8
- //
9
-
10
- const findByResetPasswordToken = findByResetPasswordTokenFactory({
11
- pg: pg as any,
12
- });
13
-
14
- suite("findByResetPasswordTokenFactory", () => {
15
- before(migrate);
16
- beforeEach(emptyDatabase);
17
-
18
- test("should find a user by reset_password_token", async () => {
19
- await pg.sql`
20
- INSERT INTO users
21
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job, reset_password_token)
22
- VALUES
23
- (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque', 'TOKEN')
24
- ;
25
- `;
26
-
27
- const user = await findByResetPasswordToken("TOKEN");
28
-
29
- assert.equal(user?.id, 1);
30
- });
31
-
32
- test("should return undefined when the token does not exist", async () => {
33
- const user = await findByResetPasswordToken("absent");
34
-
35
- assert.equal(user, undefined);
36
- });
37
- });
@@ -1,20 +0,0 @@
1
- //
2
-
3
- import type { DatabaseContext, User } from "#src/types";
4
- import { type QueryResult } from "pg";
5
-
6
- //
7
-
8
- export function findByResetPasswordTokenFactory({ pg }: DatabaseContext) {
9
- return async function findByResetPasswordToken(reset_password_token: string) {
10
- const { rows }: QueryResult<User> = await pg.query(
11
- `
12
- SELECT *
13
- FROM users WHERE reset_password_token = $1
14
- `,
15
- [reset_password_token],
16
- );
17
-
18
- return rows.shift();
19
- };
20
- }
@@ -1,100 +0,0 @@
1
- //
2
-
3
- import { getMemberIdsPromotedByDomain } from "#src/services/organization";
4
- import assert from "node:assert/strict";
5
- import { describe, it } from "node:test";
6
-
7
- //
8
-
9
- describe("getMemberIdsPromotedByDomain", () => {
10
- it("should promote unverified and super weak members of the domain", () => {
11
- assert.deepEqual(
12
- getMemberIdsPromotedByDomain({
13
- domain: "darkangels.world",
14
- members: [
15
- {
16
- email: "lion.eljonson@darkangels.world",
17
- id: 1,
18
- verification_type: "no_validation_means_available",
19
- },
20
- {
21
- email: "cat.eljonson@darkangels.world",
22
- id: 2,
23
- verification_type:
24
- "no_verification_means_for_entreprise_unipersonnelle",
25
- },
26
- {
27
- email: "tiger.eljonson@darkangels.world",
28
- id: 3,
29
- verification_type: "no_verification_means_for_small_association",
30
- },
31
- {
32
- email: "wolf.eljonson@darkangels.world",
33
- id: 4,
34
- verification_type: "no_verification_means_for_small_organization",
35
- },
36
- {
37
- email: "mouse.eljonson@darkangels.world",
38
- id: 5,
39
- verification_type: "domain_not_verified_yet",
40
- },
41
- ],
42
- }),
43
- [1, 2, 3, 4, 5],
44
- );
45
- });
46
-
47
- it("should not promote members of another domain", () => {
48
- assert.deepEqual(
49
- getMemberIdsPromotedByDomain({
50
- domain: "darkangels.world",
51
- members: [
52
- {
53
- email: "foo@bar.world",
54
- id: 1,
55
- verification_type: "no_validation_means_available",
56
- },
57
- {
58
- email: "luther@sub.darkangels.world",
59
- id: 2,
60
- verification_type: "no_validation_means_available",
61
- },
62
- ],
63
- }),
64
- [],
65
- );
66
- });
67
-
68
- it("should not promote members with a verified link", () => {
69
- assert.deepEqual(
70
- getMemberIdsPromotedByDomain({
71
- domain: "darkangels.world",
72
- members: [
73
- {
74
- email: "lion.eljonson@darkangels.world",
75
- id: 1,
76
- verification_type: "organization_dirigeant",
77
- },
78
- {
79
- email: "azrael@darkangels.world",
80
- id: 2,
81
- verification_type: "domain",
82
- },
83
- {
84
- email: "belial@darkangels.world",
85
- id: 3,
86
- verification_type: "official_contact_email",
87
- },
88
- ],
89
- }),
90
- [],
91
- );
92
- });
93
-
94
- it("should not promote anyone without members", () => {
95
- assert.deepEqual(
96
- getMemberIdsPromotedByDomain({ domain: "darkangels.world", members: [] }),
97
- [],
98
- );
99
- });
100
- });
@@ -1,27 +0,0 @@
1
- //
2
-
3
- import { SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
4
- import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
5
-
6
- //
7
-
8
- export function getMemberIdsPromotedByDomain({
9
- domain,
10
- members,
11
- }: {
12
- domain: string;
13
- members: ReadonlyArray<{
14
- email: string;
15
- id: number;
16
- verification_type: string;
17
- }>;
18
- }) {
19
- return members
20
- .filter(
21
- ({ email, verification_type }) =>
22
- getEmailDomain(email) === domain &&
23
- (UnverifiedLinkEnum.safeParse(verification_type).success ||
24
- SuperWeakLinkEnum.safeParse(verification_type).success),
25
- )
26
- .map(({ id }) => id);
27
- }