@proconnect-gouv/proconnect.identite 10.5.0 → 12.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 (53) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/connectors/index.d.ts +1 -1
  3. package/dist/connectors/index.d.ts.map +1 -1
  4. package/dist/connectors/index.js +2 -2
  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/repositories/oidc-client/index.d.ts +1 -1
  12. package/dist/repositories/oidc-client/index.d.ts.map +1 -1
  13. package/dist/repositories/oidc-client/index.js +1 -1
  14. package/dist/repositories/oidc-client/upsert-authorization-request.d.ts +3 -0
  15. package/dist/repositories/oidc-client/upsert-authorization-request.d.ts.map +1 -0
  16. package/dist/repositories/oidc-client/upsert-authorization-request.js +30 -0
  17. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts +9 -0
  18. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts.map +1 -0
  19. package/dist/services/organization/get-member-ids-promoted-by-domain.js +11 -0
  20. package/dist/services/organization/index.d.ts +1 -0
  21. package/dist/services/organization/index.d.ts.map +1 -1
  22. package/dist/services/organization/index.js +1 -0
  23. package/dist/types/authorization-request.d.ts +20 -0
  24. package/dist/types/authorization-request.d.ts.map +1 -0
  25. package/dist/types/authorization-request.js +2 -0
  26. package/dist/types/index.d.ts +1 -1
  27. package/dist/types/index.d.ts.map +1 -1
  28. package/dist/types/index.js +1 -1
  29. package/package.json +1 -1
  30. package/src/connectors/index.ts +2 -2
  31. package/src/managers/certification/process-certification-dirigeant.test.ts +12 -1
  32. package/src/managers/certification/process-certification-dirigeant.ts +23 -4
  33. package/src/managers/organization/get-organization-info.test.ts +75 -4
  34. package/src/managers/organization/get-organization-info.test.ts.snapshot +104 -80
  35. package/src/managers/organization/get-organization-info.ts +63 -56
  36. package/src/repositories/oidc-client/index.ts +1 -1
  37. package/src/repositories/oidc-client/upsert-authorization-request.test.ts +95 -0
  38. package/src/repositories/oidc-client/upsert-authorization-request.ts +50 -0
  39. package/src/services/organization/get-member-ids-promoted-by-domain.test.ts +100 -0
  40. package/src/services/organization/get-member-ids-promoted-by-domain.ts +27 -0
  41. package/src/services/organization/index.ts +1 -0
  42. package/src/types/authorization-request.ts +23 -0
  43. package/src/types/index.ts +1 -1
  44. package/testing/index.ts +2 -0
  45. package/dist/repositories/oidc-client/add-connection.d.ts +0 -3
  46. package/dist/repositories/oidc-client/add-connection.d.ts.map +0 -1
  47. package/dist/repositories/oidc-client/add-connection.js +0 -22
  48. package/dist/types/connection.d.ts +0 -13
  49. package/dist/types/connection.d.ts.map +0 -1
  50. package/dist/types/connection.js +0 -2
  51. package/src/repositories/oidc-client/add-connection.test.ts +0 -43
  52. package/src/repositories/oidc-client/add-connection.ts +0 -36
  53. package/src/types/connection.ts +0 -15
@@ -0,0 +1,50 @@
1
+ //
2
+
3
+ import type {
4
+ AuthorizationRequest,
5
+ BaseAuthorizationRequest,
6
+ DatabaseContext,
7
+ } from "#src/types";
8
+ import { type QueryResult } from "pg";
9
+
10
+ //
11
+
12
+ export function upsertAuthorizationRequestFactory({ pg }: DatabaseContext) {
13
+ return async function upsertAuthorizationRequest({
14
+ user_id,
15
+ oidc_client_id,
16
+ organization_id,
17
+ sp_name,
18
+ user_ip_address,
19
+ interaction_cid,
20
+ outcome,
21
+ }: BaseAuthorizationRequest) {
22
+ const { rows }: QueryResult<AuthorizationRequest> = await pg.query(
23
+ `
24
+ INSERT INTO users_oidc_clients
25
+ (user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, interaction_cid, outcome)
26
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
27
+ ON CONFLICT (interaction_cid) WHERE interaction_cid IS NOT NULL
28
+ DO UPDATE SET
29
+ organization_id = EXCLUDED.organization_id,
30
+ outcome = EXCLUDED.outcome,
31
+ updated_at = EXCLUDED.updated_at,
32
+ user_id = EXCLUDED.user_id
33
+ RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id, interaction_cid, outcome;
34
+ `,
35
+ [
36
+ user_id,
37
+ oidc_client_id,
38
+ organization_id,
39
+ sp_name,
40
+ user_ip_address,
41
+ new Date(),
42
+ new Date(),
43
+ interaction_cid,
44
+ outcome,
45
+ ],
46
+ );
47
+
48
+ return rows.shift()!;
49
+ };
50
+ }
@@ -0,0 +1,100 @@
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
+ });
@@ -0,0 +1,27 @@
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
+ }
@@ -1,6 +1,7 @@
1
1
  //
2
2
 
3
3
  export * from "./compute-service-public-info.js";
4
+ export * from "./get-member-ids-promoted-by-domain.js";
4
5
  export * from "./is-domain-allowed-for-organization.js";
5
6
  export * from "./is-entreprise-unipersonnelle.js";
6
7
  export * from "./is-organization-covered-by-certification-dirigeant.js";
@@ -0,0 +1,23 @@
1
+ import { z } from "zod";
2
+
3
+ export const AuthorizationRequestOutcomeEnum = z.enum(["succeeded"]);
4
+
5
+ export type AuthorizationRequestOutcome = z.output<
6
+ typeof AuthorizationRequestOutcomeEnum
7
+ >;
8
+
9
+ export interface BaseAuthorizationRequest {
10
+ user_id: number;
11
+ oidc_client_id: number;
12
+ organization_id: number | null;
13
+ sp_name: string | null;
14
+ user_ip_address: string | null;
15
+ interaction_cid: string | null;
16
+ outcome: AuthorizationRequestOutcome | null;
17
+ }
18
+
19
+ export interface AuthorizationRequest extends BaseAuthorizationRequest {
20
+ id: number;
21
+ created_at: Date;
22
+ updated_at: Date;
23
+ }
@@ -1,8 +1,8 @@
1
1
  //
2
2
 
3
3
  export * from "./authenticator.js";
4
+ export * from "./authorization-request.js";
4
5
  export * from "./claims.js";
5
- export * from "./connection.js";
6
6
  export * from "./contexts.js";
7
7
  export * from "./email-domain.js";
8
8
  export * from "./franceconnect.js";
package/testing/index.ts CHANGED
@@ -39,6 +39,8 @@ export async function emptyDatabase() {
39
39
  await pg.sql`ALTER SEQUENCE users_id_seq RESTART WITH 1`;
40
40
  await pg.sql`delete from email_domains;`;
41
41
  await pg.sql`ALTER SEQUENCE email_domains_id_seq RESTART WITH 1`;
42
+ await pg.sql`delete from oidc_clients;`;
43
+ await pg.sql`ALTER SEQUENCE oidc_clients_id_seq RESTART WITH 1`;
42
44
  }
43
45
 
44
46
  //
@@ -1,3 +0,0 @@
1
- import type { BaseConnection, Connection, DatabaseContext } from "#src/types";
2
- export declare function addConnectionFactory({ pg }: DatabaseContext): ({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, }: BaseConnection) => Promise<Connection>;
3
- //# sourceMappingURL=add-connection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"add-connection.d.ts","sourceRoot":"","sources":["../../../src/repositories/oidc-client/add-connection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAK9E,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,yEAMjC,cAAc,yBAqBlB"}
@@ -1,22 +0,0 @@
1
- //
2
- import {} from "pg";
3
- //
4
- export function addConnectionFactory({ pg }) {
5
- return async function addConnection({ user_id, oidc_client_id, organization_id, sp_name, user_ip_address, }) {
6
- const { rows } = await pg.query(`
7
- INSERT INTO users_oidc_clients
8
- (user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at)
9
- VALUES ($1, $2, $3, $4, $5, $6, $7)
10
- RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id;
11
- `, [
12
- user_id,
13
- oidc_client_id,
14
- organization_id,
15
- sp_name,
16
- user_ip_address,
17
- new Date(),
18
- new Date(),
19
- ]);
20
- return rows.shift();
21
- };
22
- }
@@ -1,13 +0,0 @@
1
- export interface BaseConnection {
2
- user_id: number;
3
- oidc_client_id: number;
4
- organization_id: number | null;
5
- sp_name: string | null;
6
- user_ip_address: string | null;
7
- }
8
- export interface Connection extends BaseConnection {
9
- id: number;
10
- created_at: Date;
11
- updated_at: Date;
12
- }
13
- //# sourceMappingURL=connection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/types/connection.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,UAAW,SAAQ,cAAc;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB"}
@@ -1,2 +0,0 @@
1
- //
2
- export {};
@@ -1,43 +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 { addConnectionFactory } from "./add-connection.js";
7
-
8
- //
9
-
10
- const addConnection = addConnectionFactory({ pg: pg as any });
11
-
12
- suite("addConnectionFactory", () => {
13
- before(migrate);
14
- beforeEach(emptyDatabase);
15
-
16
- test("should insert and return the connection", 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
- await pg.sql`
25
- INSERT INTO oidc_clients
26
- (id, client_id, client_name, client_secret, created_at, updated_at)
27
- VALUES
28
- (1, '⚔️', 'Dark Angels', 'secret', '4444-04-04', '4444-04-04')
29
- ;
30
- `;
31
-
32
- const connection = await addConnection({
33
- user_id: 1,
34
- oidc_client_id: 1,
35
- organization_id: null,
36
- sp_name: "proconnect",
37
- user_ip_address: "127.0.0.1",
38
- });
39
-
40
- assert.equal(connection.user_id, 1);
41
- assert.equal(connection.oidc_client_id, 1);
42
- });
43
- });
@@ -1,36 +0,0 @@
1
- //
2
-
3
- import type { BaseConnection, Connection, DatabaseContext } from "#src/types";
4
- import { type QueryResult } from "pg";
5
-
6
- //
7
-
8
- export function addConnectionFactory({ pg }: DatabaseContext) {
9
- return async function addConnection({
10
- user_id,
11
- oidc_client_id,
12
- organization_id,
13
- sp_name,
14
- user_ip_address,
15
- }: BaseConnection) {
16
- const { rows }: QueryResult<Connection> = await pg.query(
17
- `
18
- INSERT INTO users_oidc_clients
19
- (user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at)
20
- VALUES ($1, $2, $3, $4, $5, $6, $7)
21
- RETURNING user_id, oidc_client_id, organization_id, sp_name, user_ip_address, created_at, updated_at, id;
22
- `,
23
- [
24
- user_id,
25
- oidc_client_id,
26
- organization_id,
27
- sp_name,
28
- user_ip_address,
29
- new Date(),
30
- new Date(),
31
- ],
32
- );
33
-
34
- return rows.shift()!;
35
- };
36
- }
@@ -1,15 +0,0 @@
1
- //
2
-
3
- export interface BaseConnection {
4
- user_id: number;
5
- oidc_client_id: number;
6
- organization_id: number | null;
7
- sp_name: string | null;
8
- user_ip_address: string | null;
9
- }
10
-
11
- export interface Connection extends BaseConnection {
12
- id: number;
13
- created_at: Date;
14
- updated_at: Date;
15
- }