@proconnect-gouv/proconnect.identite 13.0.0 → 15.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 (84) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/connectors/index.d.ts +0 -62
  3. package/dist/connectors/index.d.ts.map +1 -1
  4. package/dist/connectors/index.js +5 -13
  5. package/dist/repositories/franceconnect_userinfo/index.d.ts +0 -2
  6. package/dist/repositories/franceconnect_userinfo/index.d.ts.map +1 -1
  7. package/dist/repositories/franceconnect_userinfo/index.js +0 -2
  8. package/dist/repositories/moderation/index.d.ts +0 -1
  9. package/dist/repositories/moderation/index.d.ts.map +1 -1
  10. package/dist/repositories/moderation/index.js +0 -1
  11. package/dist/repositories/organization/find-by-user-id.d.ts +0 -1
  12. package/dist/repositories/organization/find-by-user-id.d.ts.map +1 -1
  13. package/dist/repositories/organization/find-by-user-id.js +1 -2
  14. package/dist/repositories/organization/index.d.ts +0 -1
  15. package/dist/repositories/organization/index.d.ts.map +1 -1
  16. package/dist/repositories/organization/index.js +0 -1
  17. package/dist/repositories/user/index.d.ts +0 -1
  18. package/dist/repositories/user/index.d.ts.map +1 -1
  19. package/dist/repositories/user/index.js +0 -1
  20. package/dist/repositories/user_organisation/find-user-organization.d.ts +0 -1
  21. package/dist/repositories/user_organisation/find-user-organization.d.ts.map +1 -1
  22. package/dist/repositories/user_organisation/find-user-organization.js +1 -2
  23. package/dist/repositories/user_organisation/get-user-organization.d.ts +0 -1
  24. package/dist/repositories/user_organisation/get-user-organization.d.ts.map +1 -1
  25. package/dist/repositories/user_organisation/index.d.ts +0 -3
  26. package/dist/repositories/user_organisation/index.d.ts.map +1 -1
  27. package/dist/repositories/user_organisation/index.js +0 -3
  28. package/dist/types/user-organization-link.d.ts +0 -2
  29. package/dist/types/user-organization-link.d.ts.map +1 -1
  30. package/dist/types/user-organization-link.js +0 -1
  31. package/package.json +3 -3
  32. package/src/connectors/index.ts +1 -19
  33. package/src/repositories/franceconnect_userinfo/index.ts +0 -2
  34. package/src/repositories/moderation/index.ts +0 -1
  35. package/src/repositories/organization/find-by-user-id.test.ts +5 -5
  36. package/src/repositories/organization/find-by-user-id.test.ts.snapshot +3 -6
  37. package/src/repositories/organization/find-by-user-id.ts +1 -2
  38. package/src/repositories/organization/index.ts +0 -1
  39. package/src/repositories/user/index.ts +0 -1
  40. package/src/repositories/user_organisation/find-user-organization.ts +1 -2
  41. package/src/repositories/user_organisation/get-user-organization.test.ts +0 -1
  42. package/src/repositories/user_organisation/index.ts +0 -3
  43. package/src/types/user-organization-link.ts +0 -1
  44. package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts +0 -4
  45. package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts.map +0 -1
  46. package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.js +0 -10
  47. package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.d.ts +0 -16
  48. package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.d.ts.map +0 -1
  49. package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.js +0 -23
  50. package/dist/repositories/moderation/create-moderation.d.ts +0 -22
  51. package/dist/repositories/moderation/create-moderation.d.ts.map +0 -1
  52. package/dist/repositories/moderation/create-moderation.js +0 -21
  53. package/dist/repositories/organization/find-by-verified-email-domain.d.ts +0 -6
  54. package/dist/repositories/organization/find-by-verified-email-domain.d.ts.map +0 -1
  55. package/dist/repositories/organization/find-by-verified-email-domain.js +0 -21
  56. package/dist/repositories/user/delete.d.ts +0 -3
  57. package/dist/repositories/user/delete.d.ts.map +0 -1
  58. package/dist/repositories/user/delete.js +0 -11
  59. package/dist/repositories/user_organisation/create-user-organization.d.ts +0 -12
  60. package/dist/repositories/user_organisation/create-user-organization.d.ts.map +0 -1
  61. package/dist/repositories/user_organisation/create-user-organization.js +0 -21
  62. package/dist/repositories/user_organisation/delete-user-organization.d.ts +0 -3
  63. package/dist/repositories/user_organisation/delete-user-organization.d.ts.map +0 -1
  64. package/dist/repositories/user_organisation/delete-user-organization.js +0 -12
  65. package/dist/repositories/user_organisation/update-user-organization.d.ts +0 -12
  66. package/dist/repositories/user_organisation/update-user-organization.d.ts.map +0 -1
  67. package/dist/repositories/user_organisation/update-user-organization.js +0 -20
  68. package/src/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.test.ts +0 -47
  69. package/src/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.ts +0 -21
  70. package/src/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.test.ts +0 -102
  71. package/src/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.ts +0 -41
  72. package/src/repositories/moderation/create-moderation.test.ts +0 -43
  73. package/src/repositories/moderation/create-moderation.ts +0 -45
  74. package/src/repositories/organization/find-by-verified-email-domain.test.ts +0 -46
  75. package/src/repositories/organization/find-by-verified-email-domain.ts +0 -33
  76. package/src/repositories/user/delete.test.ts +0 -35
  77. package/src/repositories/user/delete.ts +0 -19
  78. package/src/repositories/user_organisation/create-user-organization.test.ts +0 -66
  79. package/src/repositories/user_organisation/create-user-organization.test.ts.snapshot +0 -25
  80. package/src/repositories/user_organisation/create-user-organization.ts +0 -39
  81. package/src/repositories/user_organisation/delete-user-organization.test.ts +0 -55
  82. package/src/repositories/user_organisation/delete-user-organization.ts +0 -24
  83. package/src/repositories/user_organisation/update-user-organization.test.ts +0 -48
  84. package/src/repositories/user_organisation/update-user-organization.ts +0 -42
@@ -1,46 +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 { findByVerifiedEmailDomainFactory } from "./find-by-verified-email-domain.js";
7
-
8
- //
9
-
10
- const findByVerifiedEmailDomain = findByVerifiedEmailDomainFactory({
11
- pg: pg as any,
12
- });
13
-
14
- suite("findByVerifiedEmailDomainFactory", () => {
15
- before(migrate);
16
- beforeEach(emptyDatabase);
17
-
18
- test("should return empty array when no organization matches the domain", async () => {
19
- const organizations = await findByVerifiedEmailDomain("absent.world");
20
-
21
- assert.deepEqual(organizations, []);
22
- });
23
-
24
- test("should return matching organization with member_count", async () => {
25
- await pg.sql`
26
- INSERT INTO organizations
27
- (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at, cached_est_active)
28
- VALUES
29
- ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19', 'true')
30
- ;
31
- `;
32
- await pg.sql`
33
- INSERT INTO email_domains
34
- (organization_id, domain, verification_type, created_at, updated_at)
35
- VALUES
36
- (1, 'darkangels.world', 'verified', '4444-04-04', '4444-04-04')
37
- ;
38
- `;
39
-
40
- const organizations = await findByVerifiedEmailDomain("darkangels.world");
41
-
42
- assert.equal(organizations.length, 1);
43
- assert.equal(organizations[0]?.id, 1);
44
- assert.equal(organizations[0]?.member_count, 0);
45
- });
46
- });
@@ -1,33 +0,0 @@
1
- //
2
-
3
- import type { DatabaseContext } from "#src/types";
4
- import {
5
- EmailDomainApprovedVerificationValues,
6
- type Organization,
7
- } from "#src/types";
8
- import { type QueryResult } from "pg";
9
-
10
- //
11
-
12
- export function findByVerifiedEmailDomainFactory({ pg }: DatabaseContext) {
13
- return async function findByVerifiedEmailDomain(email_domain: string) {
14
- const { rows }: QueryResult<Organization & { member_count: number }> =
15
- await pg.query(
16
- `
17
- SELECT o.*, count(u.id)::int as member_count
18
- FROM organizations o
19
- INNER JOIN email_domains ed ON ed.organization_id = o.id
20
- LEFT JOIN users_organizations uo ON uo.organization_id = o.id
21
- LEFT JOIN users u ON u.id = uo.user_id
22
- AND substring(u.email FROM '@(.+)$') = $1
23
- WHERE o.cached_est_active = 'true'
24
- AND ed.domain = $1
25
- AND ed.verification_type = ANY ($2)
26
- GROUP BY o.id
27
- ORDER BY member_count DESC NULLS LAST;`,
28
- [email_domain, EmailDomainApprovedVerificationValues],
29
- );
30
-
31
- return rows;
32
- };
33
- }
@@ -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 { deleteUserFactory } from "./delete.js";
7
-
8
- //
9
-
10
- const deleteUser = deleteUserFactory({ pg: pg as any });
11
-
12
- suite("deleteUserFactory", () => {
13
- before(migrate);
14
- beforeEach(emptyDatabase);
15
-
16
- test("should return true when the user exists", async () => {
17
- await pg.sql`
18
- INSERT INTO users
19
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
20
- VALUES
21
- (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
22
- ;
23
- `;
24
-
25
- const result = await deleteUser(1);
26
-
27
- assert.equal(result, true);
28
- });
29
-
30
- test("should return false when the user does not exist", async () => {
31
- const result = await deleteUser(999);
32
-
33
- assert.equal(result, false);
34
- });
35
- });
@@ -1,19 +0,0 @@
1
- //
2
-
3
- import type { DatabaseContext } from "#src/types";
4
- import { type QueryResult } from "pg";
5
-
6
- //
7
-
8
- export function deleteUserFactory({ pg }: DatabaseContext) {
9
- return async function deleteUser(id: number) {
10
- const { rowCount, affectedRows } = (await pg.query(
11
- `
12
- DELETE FROM users
13
- WHERE id = $1`,
14
- [id],
15
- )) as QueryResult & { affectedRows?: number };
16
-
17
- return (affectedRows ?? rowCount ?? 0) > 0;
18
- };
19
- }
@@ -1,66 +0,0 @@
1
- import { LinkEnum } from "#src/types";
2
- import { emptyDatabase, migrate, pg } from "#testing";
3
- import { before, beforeEach, mock, suite, test } from "node:test";
4
- import { createUserOrganizationFactory } from "./create-user-organization.js";
5
-
6
- //
7
-
8
- const linkUserToOrganization = createUserOrganizationFactory({ pg: pg as any });
9
-
10
- suite("linkUserToOrganizationFactory", () => {
11
- before(migrate);
12
- beforeEach(emptyDatabase);
13
- before(() => {
14
- mock.timers.enable({ apis: ["Date"], now: new Date("4444-04-04") });
15
- });
16
-
17
- test("should link user to organization", async (t) => {
18
- await pg.sql`
19
- INSERT INTO organizations
20
- (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
21
- VALUES
22
- ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
23
- ;
24
- `;
25
- await pg.sql`
26
- INSERT INTO users
27
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
28
- VALUES
29
- (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
30
- ;
31
- `;
32
-
33
- const userOrganizationLink = await linkUserToOrganization({
34
- organization_id: 1,
35
- user_id: 1,
36
- verification_type: LinkEnum.enum.domain_not_verified_yet,
37
- });
38
-
39
- t.assert.snapshot(userOrganizationLink);
40
- });
41
-
42
- test("should mark a user as organization_dirigeant", async (t) => {
43
- await pg.sql`
44
- INSERT INTO organizations
45
- (cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
46
- VALUES
47
- ('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
48
- ;
49
- `;
50
- await pg.sql`
51
- INSERT INTO users
52
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
53
- VALUES
54
- (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
55
- ;
56
- `;
57
-
58
- const userOrganizationLink = await linkUserToOrganization({
59
- organization_id: 1,
60
- user_id: 1,
61
- verification_type: LinkEnum.enum.organization_dirigeant,
62
- });
63
-
64
- t.assert.snapshot(userOrganizationLink);
65
- });
66
- });
@@ -1,25 +0,0 @@
1
- exports[`linkUserToOrganizationFactory > should link user to organization 1`] = `
2
- {
3
- "user_id": 1,
4
- "organization_id": 1,
5
- "is_external": false,
6
- "created_at": "4444-04-04T00:00:00.000Z",
7
- "updated_at": "4444-04-04T00:00:00.000Z",
8
- "verification_type": "domain_not_verified_yet",
9
- "has_been_greeted": false,
10
- "verified_at": "4444-04-04T00:00:00.000Z"
11
- }
12
- `;
13
-
14
- exports[`linkUserToOrganizationFactory > should mark a user as organization_dirigeant 1`] = `
15
- {
16
- "user_id": 1,
17
- "organization_id": 1,
18
- "is_external": false,
19
- "created_at": "4444-04-04T00:00:00.000Z",
20
- "updated_at": "4444-04-04T00:00:00.000Z",
21
- "verification_type": "organization_dirigeant",
22
- "has_been_greeted": false,
23
- "verified_at": "4444-04-04T00:00:00.000Z"
24
- }
25
- `;
@@ -1,39 +0,0 @@
1
- import { hashToPostgresParams } from "#src/services/postgres";
2
- import type {
3
- DatabaseContext,
4
- InsertUserOrganizationLink,
5
- UserOrganizationLink,
6
- } from "#src/types";
7
- import type { QueryResult } from "pg";
8
-
9
- export function createUserOrganizationFactory({ pg }: DatabaseContext) {
10
- return async function linkUserToOrganization({
11
- is_external = false,
12
- organization_id,
13
- user_id,
14
- verification_type,
15
- }: InsertUserOrganizationLink) {
16
- const { paramsString, valuesString, values } =
17
- hashToPostgresParams<UserOrganizationLink>({
18
- created_at: new Date(),
19
- is_external,
20
- organization_id,
21
- updated_at: new Date(),
22
- user_id,
23
- verification_type,
24
- verified_at: verification_type ? new Date() : undefined,
25
- });
26
-
27
- const { rows }: QueryResult<UserOrganizationLink> = await pg.query(
28
- `
29
- INSERT INTO users_organizations
30
- ${paramsString}
31
- VALUES
32
- ${valuesString}
33
- RETURNING *;`,
34
- values,
35
- );
36
-
37
- return rows.shift()!;
38
- };
39
- }
@@ -1,55 +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 { deleteUserOrganizationFactory } from "./delete-user-organization.js";
7
-
8
- //
9
-
10
- const deleteUserOrganization = deleteUserOrganizationFactory({ pg: pg as any });
11
-
12
- suite("deleteUserOrganizationFactory", () => {
13
- before(migrate);
14
- beforeEach(emptyDatabase);
15
-
16
- test("should return true when the link exists", 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
- await pg.sql`
25
- INSERT INTO users
26
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
27
- VALUES
28
- (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
29
- ;
30
- `;
31
- await pg.sql`
32
- INSERT INTO users_organizations
33
- (user_id, organization_id, created_at, updated_at, verification_type)
34
- VALUES
35
- (1, 1, '4444-04-04', '4444-04-04', 'domain_not_verified_yet')
36
- ;
37
- `;
38
-
39
- const result = await deleteUserOrganization({
40
- user_id: 1,
41
- organization_id: 1,
42
- });
43
-
44
- assert.equal(result, true);
45
- });
46
-
47
- test("should return false when the link does not exist", async () => {
48
- const result = await deleteUserOrganization({
49
- user_id: 999,
50
- organization_id: 999,
51
- });
52
-
53
- assert.equal(result, false);
54
- });
55
- });
@@ -1,24 +0,0 @@
1
- //
2
-
3
- import type { DatabaseContext, FindUserOrganizationLink } from "#src/types";
4
- import type { QueryResult } from "pg";
5
-
6
- //
7
-
8
- export function deleteUserOrganizationFactory({ pg }: DatabaseContext) {
9
- return async function deleteUserOrganization({
10
- user_id,
11
- organization_id,
12
- }: FindUserOrganizationLink) {
13
- const { rowCount, affectedRows } = (await pg.query(
14
- `
15
- DELETE
16
- FROM users_organizations
17
- WHERE user_id = $1
18
- AND organization_id = $2`,
19
- [user_id, organization_id],
20
- )) as QueryResult & { affectedRows?: number };
21
-
22
- return (affectedRows ?? rowCount ?? 0) > 0;
23
- };
24
- }
@@ -1,48 +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 { updateUserOrganizationFactory } from "./update-user-organization.js";
7
-
8
- //
9
-
10
- const updateUserOrganization = updateUserOrganizationFactory({
11
- pg: pg as any,
12
- });
13
-
14
- suite("updateUserOrganizationLink", () => {
15
- before(migrate);
16
- beforeEach(emptyDatabase);
17
-
18
- test("should update the user organization link", async () => {
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
- await pg.sql`
27
- INSERT INTO users
28
- (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
29
- VALUES
30
- (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', 'I', 'Primarque')
31
- ;
32
- `;
33
- await pg.sql`
34
- INSERT INTO users_organizations
35
- (user_id, organization_id, created_at, updated_at, is_external, verification_type)
36
- VALUES (1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_available')
37
- ;
38
- `;
39
-
40
- const user = await updateUserOrganization(
41
- { organization_id: 1, user_id: 1 },
42
- {
43
- is_external: true,
44
- },
45
- );
46
- assert.ok(user.is_external);
47
- });
48
- });
@@ -1,42 +0,0 @@
1
- //
2
-
3
- import { hashToPostgresParams } from "#src/services/postgres";
4
- import type {
5
- DatabaseContext,
6
- FindUserOrganizationLink,
7
- User,
8
- UserOrganizationLink,
9
- } from "#src/types";
10
- import type { QueryResult } from "pg";
11
-
12
- //
13
-
14
- export function updateUserOrganizationFactory({ pg }: DatabaseContext) {
15
- return async function updateUserOrganization(
16
- { organization_id, user_id }: FindUserOrganizationLink,
17
- fieldsToUpdate: Partial<UserOrganizationLink>,
18
- ) {
19
- const connection = pg;
20
-
21
- const fieldsToUpdateWithTimestamps = {
22
- ...fieldsToUpdate,
23
- updated_at: new Date(),
24
- };
25
-
26
- const { paramsString, valuesString, values } = hashToPostgresParams<User>(
27
- fieldsToUpdateWithTimestamps,
28
- );
29
-
30
- const { rows }: QueryResult<UserOrganizationLink> = await connection.query(
31
- `
32
- UPDATE users_organizations SET ${paramsString} = ${valuesString}
33
- WHERE organization_id = $${values.length + 1}
34
- AND user_id = $${values.length + 2}
35
- RETURNING *
36
- `,
37
- [...values, organization_id, user_id],
38
- );
39
-
40
- return rows.shift()!;
41
- };
42
- }