@proconnect-gouv/proconnect.identite 14.0.0 → 16.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 (69) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/connectors/index.d.ts +2 -7
  3. package/dist/connectors/index.d.ts.map +1 -1
  4. package/dist/connectors/index.js +3 -3
  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/repositories/authenticator/delete-all-authenticators-by-user-id.d.ts +3 -0
  9. package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.d.ts.map +1 -0
  10. package/dist/repositories/authenticator/delete-all-authenticators-by-user-id.js +12 -0
  11. package/dist/repositories/authenticator/index.d.ts +1 -0
  12. package/dist/repositories/authenticator/index.d.ts.map +1 -1
  13. package/dist/repositories/authenticator/index.js +1 -0
  14. package/dist/repositories/oidc-client/upsert-authorization-request.d.ts +1 -1
  15. package/dist/repositories/oidc-client/upsert-authorization-request.d.ts.map +1 -1
  16. package/dist/repositories/oidc-client/upsert-authorization-request.js +6 -4
  17. package/dist/repositories/organization/find-by-user-id.d.ts +0 -1
  18. package/dist/repositories/organization/find-by-user-id.d.ts.map +1 -1
  19. package/dist/repositories/organization/find-by-user-id.js +1 -2
  20. package/dist/repositories/organization/index.d.ts +0 -1
  21. package/dist/repositories/organization/index.d.ts.map +1 -1
  22. package/dist/repositories/organization/index.js +0 -1
  23. package/dist/repositories/user_organisation/find-user-organization.d.ts +0 -1
  24. package/dist/repositories/user_organisation/find-user-organization.d.ts.map +1 -1
  25. package/dist/repositories/user_organisation/find-user-organization.js +1 -2
  26. package/dist/repositories/user_organisation/get-user-organization.d.ts +0 -1
  27. package/dist/repositories/user_organisation/get-user-organization.d.ts.map +1 -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/authorization-request.d.ts +2 -0
  35. package/dist/types/authorization-request.d.ts.map +1 -1
  36. package/dist/types/authorization-request.js +4 -1
  37. package/dist/types/user-organization-link.d.ts +0 -2
  38. package/dist/types/user-organization-link.d.ts.map +1 -1
  39. package/dist/types/user-organization-link.js +0 -1
  40. package/package.json +1 -1
  41. package/src/connectors/index.ts +2 -2
  42. package/src/managers/certification/certification-score.test.ts +64 -1
  43. package/src/managers/certification/certification-score.ts +84 -50
  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 -0
  47. package/src/repositories/oidc-client/upsert-authorization-request.test.ts +18 -5
  48. package/src/repositories/oidc-client/upsert-authorization-request.ts +6 -3
  49. package/src/repositories/organization/find-by-user-id.test.ts +5 -5
  50. package/src/repositories/organization/find-by-user-id.test.ts.snapshot +3 -6
  51. package/src/repositories/organization/find-by-user-id.ts +1 -2
  52. package/src/repositories/organization/index.ts +0 -1
  53. package/src/repositories/user_organisation/find-user-organization.ts +1 -2
  54. package/src/repositories/user_organisation/get-user-organization.test.ts +0 -1
  55. package/src/services/organization/get-membership-changes-by-domain-verification.test.ts +91 -0
  56. package/src/services/organization/get-membership-changes-by-domain-verification.ts +46 -0
  57. package/src/services/organization/index.ts +1 -1
  58. package/src/types/authorization-request.ts +5 -1
  59. package/src/types/user-organization-link.ts +0 -1
  60. package/dist/repositories/organization/find-by-verified-email-domain.d.ts +0 -6
  61. package/dist/repositories/organization/find-by-verified-email-domain.d.ts.map +0 -1
  62. package/dist/repositories/organization/find-by-verified-email-domain.js +0 -21
  63. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts +0 -9
  64. package/dist/services/organization/get-member-ids-promoted-by-domain.d.ts.map +0 -1
  65. package/dist/services/organization/get-member-ids-promoted-by-domain.js +0 -11
  66. package/src/repositories/organization/find-by-verified-email-domain.test.ts +0 -46
  67. package/src/repositories/organization/find-by-verified-email-domain.ts +0 -33
  68. package/src/services/organization/get-member-ids-promoted-by-domain.test.ts +0 -100
  69. package/src/services/organization/get-member-ids-promoted-by-domain.ts +0 -27
@@ -1,7 +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
+ export * from "./get-membership-changes-by-domain-verification.js";
5
5
  export * from "./is-domain-allowed-for-organization.js";
6
6
  export * from "./is-entreprise-unipersonnelle.js";
7
7
  export * from "./is-organization-covered-by-certification-dirigeant.js";
@@ -1,6 +1,9 @@
1
1
  import { z } from "zod";
2
2
 
3
- export const AuthorizationRequestOutcomeEnum = z.enum(["succeeded"]);
3
+ export const AuthorizationRequestOutcomeEnum = z.enum([
4
+ "signed_out",
5
+ "succeeded",
6
+ ]);
4
7
 
5
8
  export type AuthorizationRequestOutcome = z.output<
6
9
  typeof AuthorizationRequestOutcomeEnum
@@ -14,6 +17,7 @@ export interface BaseAuthorizationRequest {
14
17
  user_ip_address: string | null;
15
18
  interaction_cid: string | null;
16
19
  outcome: AuthorizationRequestOutcome | null;
20
+ sid: string | null;
17
21
  }
18
22
 
19
23
  export interface AuthorizationRequest extends BaseAuthorizationRequest {
@@ -54,7 +54,6 @@ export const BaseUserOrganizationLinkSchema = z.object({
54
54
  verification_type: LinkEnum,
55
55
  // updated when verification_type is changed
56
56
  verified_at: z.date().or(z.literal(null)),
57
- has_been_greeted: z.boolean(),
58
57
  });
59
58
 
60
59
  export type BaseUserOrganizationLink = z.output<
@@ -1,6 +0,0 @@
1
- import type { DatabaseContext } from "#src/types";
2
- import { type Organization } from "#src/types";
3
- export declare function findByVerifiedEmailDomainFactory({ pg }: DatabaseContext): (email_domain: string) => Promise<(Organization & {
4
- member_count: number;
5
- })[]>;
6
- //# sourceMappingURL=find-by-verified-email-domain.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"find-by-verified-email-domain.d.ts","sourceRoot":"","sources":["../../../src/repositories/organization/find-by-verified-email-domain.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AAKpB,wBAAgB,gCAAgC,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IACtB,cAAc,MAAM;kBACP,MAAM;MAmBpE"}
@@ -1,21 +0,0 @@
1
- //
2
- import { EmailDomainApprovedVerificationValues, } from "#src/types";
3
- import {} from "pg";
4
- //
5
- export function findByVerifiedEmailDomainFactory({ pg }) {
6
- return async function findByVerifiedEmailDomain(email_domain) {
7
- const { rows } = await pg.query(`
8
- SELECT o.*, count(u.id)::int as member_count
9
- FROM organizations o
10
- INNER JOIN email_domains ed ON ed.organization_id = o.id
11
- LEFT JOIN users_organizations uo ON uo.organization_id = o.id
12
- LEFT JOIN users u ON u.id = uo.user_id
13
- AND substring(u.email FROM '@(.+)$') = $1
14
- WHERE o.cached_est_active = 'true'
15
- AND ed.domain = $1
16
- AND ed.verification_type = ANY ($2)
17
- GROUP BY o.id
18
- ORDER BY member_count DESC NULLS LAST;`, [email_domain, EmailDomainApprovedVerificationValues]);
19
- return rows;
20
- };
21
- }
@@ -1,9 +0,0 @@
1
- export declare function getMemberIdsPromotedByDomain({ domain, members, }: {
2
- domain: string;
3
- members: ReadonlyArray<{
4
- email: string;
5
- id: number;
6
- verification_type: string;
7
- }>;
8
- }): number[];
9
- //# sourceMappingURL=get-member-ids-promoted-by-domain.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-member-ids-promoted-by-domain.d.ts","sourceRoot":"","sources":["../../../src/services/organization/get-member-ids-promoted-by-domain.ts"],"names":[],"mappings":"AAOA,wBAAgB,4BAA4B,CAAC,EAC3C,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,iBAAiB,EAAE,MAAM,CAAC;KAC3B,CAAC,CAAC;CACJ,YASA"}
@@ -1,11 +0,0 @@
1
- //
2
- import { SuperWeakLinkEnum, UnverifiedLinkEnum } from "#src/types";
3
- import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
4
- //
5
- export function getMemberIdsPromotedByDomain({ domain, members, }) {
6
- return members
7
- .filter(({ email, verification_type }) => getEmailDomain(email) === domain &&
8
- (UnverifiedLinkEnum.safeParse(verification_type).success ||
9
- SuperWeakLinkEnum.safeParse(verification_type).success))
10
- .map(({ id }) => id);
11
- }
@@ -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,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
- }