@proconnect-gouv/proconnect.identite 10.0.2 → 10.2.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.
- package/CHANGELOG.md +18 -0
- package/dist/connectors/index.d.ts +87 -45
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +31 -53
- package/dist/managers/organization/adapters/api_entreprise.d.ts +3 -3
- package/dist/managers/organization/adapters/api_entreprise.d.ts.map +1 -1
- package/dist/managers/organization/adapters/api_entreprise.js +30 -27
- package/dist/managers/organization/adapters/index.d.ts +1 -0
- package/dist/managers/organization/adapters/index.d.ts.map +1 -1
- package/dist/managers/organization/adapters/index.js +1 -0
- package/dist/managers/organization/adapters/rne.d.ts +4 -0
- package/dist/managers/organization/adapters/rne.d.ts.map +1 -0
- package/dist/managers/organization/adapters/rne.js +7 -0
- package/dist/managers/organization/get-organization-info.d.ts +2 -1
- package/dist/managers/organization/get-organization-info.d.ts.map +1 -1
- package/dist/managers/organization/get-organization-info.js +27 -7
- package/dist/managers/user/assign-user-verification-type-to-domain.d.ts.map +1 -1
- package/dist/managers/user/assign-user-verification-type-to-domain.js +3 -3
- package/dist/repositories/authenticator/find-authenticators-by-user-id.d.ts +3 -0
- package/dist/repositories/authenticator/find-authenticators-by-user-id.d.ts.map +1 -0
- package/dist/repositories/authenticator/{get-authenticators-by-user-id.js → find-authenticators-by-user-id.js} +2 -2
- package/dist/repositories/authenticator/index.d.ts +1 -1
- package/dist/repositories/authenticator/index.d.ts.map +1 -1
- package/dist/repositories/authenticator/index.js +1 -1
- package/dist/repositories/authenticator/update-authenticator.d.ts +1 -2
- package/dist/repositories/authenticator/update-authenticator.d.ts.map +1 -1
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts +4 -0
- package/dist/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.d.ts.map +1 -0
- package/dist/repositories/{user → franceconnect_userinfo}/delete-franceconnect-userinfo.js +2 -2
- package/dist/repositories/{user/get-franceconnect-user-info.d.ts → franceconnect_userinfo/find-franceconnect-userinfo.d.ts} +2 -3
- package/dist/repositories/franceconnect_userinfo/find-franceconnect-userinfo.d.ts.map +1 -0
- package/dist/repositories/{user/get-franceconnect-user-info.js → franceconnect_userinfo/find-franceconnect-userinfo.js} +2 -2
- package/dist/repositories/franceconnect_userinfo/index.d.ts +4 -0
- package/dist/repositories/franceconnect_userinfo/index.d.ts.map +1 -0
- package/dist/repositories/franceconnect_userinfo/index.js +3 -0
- package/dist/repositories/franceconnect_userinfo/upsert-franceconnect-userinfo.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/delete-official-contact-email-verification.d.ts +3 -0
- package/dist/repositories/official-contact-email-verification/delete-official-contact-email-verification.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/delete-official-contact-email-verification.js +12 -0
- package/dist/repositories/official-contact-email-verification/find-official-contact-email-verification.d.ts +10 -0
- package/dist/repositories/official-contact-email-verification/find-official-contact-email-verification.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/find-official-contact-email-verification.js +13 -0
- package/dist/repositories/official-contact-email-verification/index.d.ts +4 -0
- package/dist/repositories/official-contact-email-verification/index.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/index.js +4 -0
- package/dist/repositories/official-contact-email-verification/upsert-official-contact-email-verification.d.ts +10 -0
- package/dist/repositories/official-contact-email-verification/upsert-official-contact-email-verification.d.ts.map +1 -0
- package/dist/repositories/official-contact-email-verification/upsert-official-contact-email-verification.js +19 -0
- package/dist/repositories/organization/find-by-user-id.d.ts +0 -3
- package/dist/repositories/organization/find-by-user-id.d.ts.map +1 -1
- package/dist/repositories/organization/find-by-user-id.js +10 -14
- package/dist/repositories/organization/find-organization-by-id.d.ts +4 -0
- package/dist/repositories/organization/find-organization-by-id.d.ts.map +1 -0
- package/dist/repositories/organization/{find-by-id.js → find-organization-by-id.js} +2 -2
- package/dist/repositories/organization/{get-users-by-organization.d.ts → find-users-by-organization.d.ts} +2 -6
- package/dist/repositories/organization/find-users-by-organization.d.ts.map +1 -0
- package/dist/repositories/organization/find-users-by-organization.js +19 -0
- package/dist/repositories/organization/get-organization-by-id.d.ts +3 -0
- package/dist/repositories/organization/get-organization-by-id.d.ts.map +1 -0
- package/dist/repositories/organization/get-organization-by-id.js +15 -0
- package/dist/repositories/organization/index.d.ts +3 -5
- package/dist/repositories/organization/index.d.ts.map +1 -1
- package/dist/repositories/organization/index.js +3 -5
- package/dist/repositories/organization/upsert.d.ts.map +1 -1
- package/dist/repositories/organization/upsert.js +8 -3
- package/dist/repositories/user/index.d.ts +0 -3
- package/dist/repositories/user/index.d.ts.map +1 -1
- package/dist/repositories/user/index.js +0 -3
- package/dist/repositories/{organization/link-user-to-organization.d.ts → user_organisation/create-user-organization.d.ts} +2 -6
- package/dist/repositories/user_organisation/create-user-organization.d.ts.map +1 -0
- package/dist/repositories/{organization/link-user-to-organization.js → user_organisation/create-user-organization.js} +2 -3
- package/dist/repositories/user_organisation/delete-user-organization.d.ts +3 -0
- package/dist/repositories/user_organisation/delete-user-organization.d.ts.map +1 -0
- package/dist/repositories/{organization → user_organisation}/delete-user-organization.js +4 -2
- package/dist/repositories/{organization/get-user-organization-link.d.ts → user_organisation/find-user-organization.d.ts} +3 -6
- package/dist/repositories/user_organisation/find-user-organization.d.ts.map +1 -0
- package/dist/repositories/user_organisation/find-user-organization.js +20 -0
- package/dist/repositories/user_organisation/index.d.ts +5 -0
- package/dist/repositories/user_organisation/index.d.ts.map +1 -0
- package/dist/repositories/user_organisation/index.js +4 -0
- package/dist/repositories/{user/update-user-organization-link.d.ts → user_organisation/update-user-organization.d.ts} +3 -7
- package/dist/repositories/user_organisation/update-user-organization.d.ts.map +1 -0
- package/dist/repositories/{user/update-user-organization-link.js → user_organisation/update-user-organization.js} +2 -2
- package/dist/types/authenticator.d.ts +3 -1
- package/dist/types/authenticator.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/official-contact-email-verification.d.ts +23 -0
- package/dist/types/official-contact-email-verification.d.ts.map +1 -0
- package/dist/types/official-contact-email-verification.js +15 -0
- package/dist/types/organization-info.d.ts +10 -3
- package/dist/types/organization-info.d.ts.map +1 -1
- package/dist/types/organization-info.js +5 -1
- package/dist/types/organization.d.ts +2 -1
- package/dist/types/organization.d.ts.map +1 -1
- package/dist/types/user-organization-link.d.ts +5 -7
- package/dist/types/user-organization-link.d.ts.map +1 -1
- package/dist/types/user-organization-link.js +4 -6
- package/package.json +5 -5
- package/src/connectors/index.ts +83 -53
- package/src/managers/organization/adapters/api_entreprise.test.ts +6 -6
- package/src/managers/organization/adapters/api_entreprise.test.ts.snapshot +4 -4
- package/src/managers/organization/adapters/api_entreprise.ts +41 -31
- package/src/managers/organization/adapters/index.ts +1 -0
- package/src/managers/organization/adapters/rne.ts +14 -0
- package/src/managers/organization/get-organization-info.test.ts +66 -19
- package/src/managers/organization/get-organization-info.test.ts.snapshot +31 -3
- package/src/managers/organization/get-organization-info.ts +44 -13
- package/src/managers/organization/mark-domain-as-verified.test.ts +2 -3
- package/src/managers/user/assign-user-verification-type-to-domain.test.ts +7 -8
- package/src/managers/user/assign-user-verification-type-to-domain.ts +8 -5
- package/src/repositories/authenticator/{get-authenticators-by-user-id.test.ts → find-authenticators-by-user-id.test.ts} +5 -5
- package/src/repositories/authenticator/{get-authenticators-by-user-id.ts → find-authenticators-by-user-id.ts} +2 -2
- package/src/repositories/authenticator/index.ts +1 -1
- package/src/repositories/authenticator/update-authenticator.ts +1 -1
- package/src/repositories/{user → franceconnect_userinfo}/delete-franceconnect-userinfo.test.ts +7 -7
- package/src/repositories/franceconnect_userinfo/delete-franceconnect-userinfo.ts +21 -0
- package/src/repositories/{user/get-franceconnect-user-info.test.ts → franceconnect_userinfo/find-franceconnect-userinfo.test.ts} +5 -5
- package/src/repositories/{user/get-franceconnect-user-info.ts → franceconnect_userinfo/find-franceconnect-userinfo.ts} +2 -6
- package/src/repositories/franceconnect_userinfo/index.ts +3 -0
- package/src/repositories/official-contact-email-verification/delete-official-contact-email-verification.test.ts +106 -0
- package/src/repositories/official-contact-email-verification/delete-official-contact-email-verification.ts +29 -0
- package/src/repositories/official-contact-email-verification/find-official-contact-email-verification.test.ts +136 -0
- package/src/repositories/official-contact-email-verification/find-official-contact-email-verification.ts +31 -0
- package/src/repositories/official-contact-email-verification/index.ts +5 -0
- package/src/repositories/official-contact-email-verification/upsert-official-contact-email-verification.test.ts +170 -0
- package/src/repositories/official-contact-email-verification/upsert-official-contact-email-verification.ts +38 -0
- package/src/repositories/organization/find-by-user-id.test.ts +5 -6
- package/src/repositories/organization/find-by-user-id.test.ts.snapshot +6 -12
- package/src/repositories/organization/find-by-user-id.ts +10 -14
- package/src/repositories/organization/{find-by-id.test.ts → find-organization-by-id.test.ts} +5 -4
- package/src/repositories/organization/{find-by-id.ts → find-organization-by-id.ts} +3 -3
- package/src/repositories/organization/{get-users-by-organization.test.ts → find-users-by-organization.test.ts} +9 -8
- package/src/repositories/organization/{get-users-by-organization.test.ts.snapshot → find-users-by-organization.test.ts.snapshot} +2 -5
- package/src/repositories/organization/find-users-by-organization.ts +38 -0
- package/src/repositories/organization/get-organization-by-id.test.ts +37 -0
- package/src/repositories/organization/get-organization-by-id.ts +19 -0
- package/src/repositories/organization/index.ts +3 -5
- package/src/repositories/organization/upsert.ts +9 -1
- package/src/repositories/organization/upset.test.ts +2 -0
- package/src/repositories/user/index.ts +0 -3
- package/src/repositories/{organization/link-user-to-organization.test.ts → user_organisation/create-user-organization.test.ts} +2 -2
- package/src/repositories/{organization/link-user-to-organization.test.ts.snapshot → user_organisation/create-user-organization.test.ts.snapshot} +0 -6
- package/src/repositories/{organization/link-user-to-organization.ts → user_organisation/create-user-organization.ts} +1 -7
- package/src/repositories/{organization → user_organisation}/delete-user-organization.ts +6 -7
- package/src/repositories/{organization/get-user-organization-link.test.ts → user_organisation/find-user-organization.test.ts} +5 -5
- package/src/repositories/user_organisation/find-user-organization.ts +35 -0
- package/src/repositories/user_organisation/index.ts +4 -0
- package/src/repositories/{user/update-user-organization-link.test.ts → user_organisation/update-user-organization.test.ts} +10 -8
- package/src/repositories/{user/update-user-organization-link.ts → user_organisation/update-user-organization.ts} +9 -9
- package/src/services/organization/compute-service-public-info.test.ts +10 -0
- package/src/types/authenticator.ts +10 -5
- package/src/types/index.ts +1 -0
- package/src/types/official-contact-email-verification.ts +32 -0
- package/src/types/organization-info.ts +14 -3
- package/src/types/organization.ts +19 -1
- package/src/types/user-organization-link.ts +9 -8
- package/dist/repositories/authenticator/get-authenticators-by-user-id.d.ts +0 -3
- package/dist/repositories/authenticator/get-authenticators-by-user-id.d.ts.map +0 -1
- package/dist/repositories/organization/delete-user-organization.d.ts +0 -6
- package/dist/repositories/organization/delete-user-organization.d.ts.map +0 -1
- package/dist/repositories/organization/find-by-id.d.ts +0 -4
- package/dist/repositories/organization/find-by-id.d.ts.map +0 -1
- package/dist/repositories/organization/get-user-organization-link.d.ts.map +0 -1
- package/dist/repositories/organization/get-user-organization-link.js +0 -23
- package/dist/repositories/organization/get-users-by-organization.d.ts.map +0 -1
- package/dist/repositories/organization/get-users-by-organization.js +0 -23
- package/dist/repositories/organization/link-user-to-organization.d.ts.map +0 -1
- package/dist/repositories/user/delete-franceconnect-userinfo.d.ts +0 -4
- package/dist/repositories/user/delete-franceconnect-userinfo.d.ts.map +0 -1
- package/dist/repositories/user/get-franceconnect-user-info.d.ts.map +0 -1
- package/dist/repositories/user/update-user-organization-link.d.ts.map +0 -1
- package/dist/repositories/user/upsert-franceconnect-userinfo.d.ts.map +0 -1
- package/src/repositories/organization/get-user-organization-link.ts +0 -34
- package/src/repositories/organization/get-users-by-organization.ts +0 -46
- package/src/repositories/user/delete-franceconnect-userinfo.ts +0 -21
- package/tsconfig.lib.tsbuildinfo +0 -1
- /package/dist/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.d.ts +0 -0
- /package/dist/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.js +0 -0
- /package/src/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.test.ts +0 -0
- /package/src/repositories/{user → franceconnect_userinfo}/upsert-franceconnect-userinfo.ts +0 -0
- /package/src/repositories/{organization → user_organisation}/delete-user-organization.test.ts +0 -0
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { before, beforeEach, describe, it } from "node:test";
|
|
6
|
-
import {
|
|
6
|
+
import { findUsersByOrganizationFactory } from "./find-users-by-organization.js";
|
|
7
7
|
|
|
8
8
|
//
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const findUsersByOrganization = findUsersByOrganizationFactory({
|
|
11
|
+
pg: pg as any,
|
|
12
|
+
});
|
|
11
13
|
|
|
12
|
-
describe("
|
|
14
|
+
describe("findUsersByOrganizationFactory", () => {
|
|
13
15
|
before(migrate);
|
|
14
16
|
beforeEach(emptyDatabase);
|
|
15
17
|
|
|
@@ -32,19 +34,18 @@ describe("getUsersByOrganizationFactory", () => {
|
|
|
32
34
|
|
|
33
35
|
await pg.sql`
|
|
34
36
|
INSERT INTO users_organizations
|
|
35
|
-
|
|
36
|
-
VALUES
|
|
37
|
-
(1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_available', false, null, null)
|
|
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')
|
|
38
39
|
;
|
|
39
40
|
`;
|
|
40
41
|
|
|
41
|
-
const user = await
|
|
42
|
+
const user = await findUsersByOrganization(1);
|
|
42
43
|
|
|
43
44
|
t.assert.snapshot(user);
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
it("❎ fail to find users for unknown organization id", async () => {
|
|
47
|
-
const user = await
|
|
48
|
+
const user = await findUsersByOrganization(42);
|
|
48
49
|
assert.deepEqual(user, []);
|
|
49
50
|
});
|
|
50
51
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
exports[`
|
|
1
|
+
exports[`findUsersByOrganizationFactory > should find users by organization id 1`] = `
|
|
2
2
|
[
|
|
3
3
|
{
|
|
4
4
|
"id": 1,
|
|
@@ -29,10 +29,7 @@ exports[`getUsersByOrganizationFactory > should find users by organization id 1`
|
|
|
29
29
|
"is_external": false,
|
|
30
30
|
"verification_type": "no_verification_means_available",
|
|
31
31
|
"verified_at": null,
|
|
32
|
-
"has_been_greeted": false
|
|
33
|
-
"needs_official_contact_email_verification": false,
|
|
34
|
-
"official_contact_email_verification_token": null,
|
|
35
|
-
"official_contact_email_verification_sent_at": null
|
|
32
|
+
"has_been_greeted": false
|
|
36
33
|
}
|
|
37
34
|
]
|
|
38
35
|
`;
|
|
@@ -0,0 +1,38 @@
|
|
|
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(
|
|
14
|
+
organization_id: number,
|
|
15
|
+
additionalWhereClause: string = "",
|
|
16
|
+
additionalParams: any[] = [],
|
|
17
|
+
) {
|
|
18
|
+
const connection = pg;
|
|
19
|
+
const baseParams = [organization_id];
|
|
20
|
+
|
|
21
|
+
const { rows }: QueryResult<User & BaseUserOrganizationLink> =
|
|
22
|
+
await connection.query(
|
|
23
|
+
`
|
|
24
|
+
SELECT u.*,
|
|
25
|
+
uo.is_external,
|
|
26
|
+
uo.verification_type,
|
|
27
|
+
uo.verified_at,
|
|
28
|
+
uo.has_been_greeted
|
|
29
|
+
FROM users u
|
|
30
|
+
INNER JOIN users_organizations AS uo ON uo.user_id = u.id
|
|
31
|
+
WHERE uo.organization_id = $1
|
|
32
|
+
${additionalWhereClause}`,
|
|
33
|
+
[...baseParams, ...additionalParams],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return rows;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import { OrganizationNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
7
|
+
import { getOrganizationByIdFactory } from "./get-organization-by-id.js";
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
const getOrganizationById = getOrganizationByIdFactory({ pg: pg as any });
|
|
12
|
+
|
|
13
|
+
suite("getOrganizationByIdFactory", () => {
|
|
14
|
+
before(migrate);
|
|
15
|
+
beforeEach(emptyDatabase);
|
|
16
|
+
|
|
17
|
+
test("should throw OrganizationNotFoundError when not found", async () => {
|
|
18
|
+
await assert.rejects(
|
|
19
|
+
() => getOrganizationById(1),
|
|
20
|
+
(err: unknown) => err instanceof OrganizationNotFoundError,
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("should return the organization when it exists", async () => {
|
|
25
|
+
await pg.sql`
|
|
26
|
+
INSERT INTO organizations
|
|
27
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
28
|
+
VALUES
|
|
29
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
30
|
+
;
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
const Organization = await getOrganizationById(1);
|
|
34
|
+
|
|
35
|
+
assert.equal(Organization.id, 1);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { type DatabaseContext, type Organization } from "#src/types";
|
|
4
|
+
import { OrganizationNotFoundError } from "@proconnect-gouv/proconnect.identite/errors";
|
|
5
|
+
import { findOrganizationByIdFactory } from "./find-organization-by-id.js";
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
export function getOrganizationByIdFactory({ pg }: DatabaseContext) {
|
|
10
|
+
const findOrganizationById = findOrganizationByIdFactory({ pg });
|
|
11
|
+
|
|
12
|
+
return async function getOrganizationById(id: number): Promise<Organization> {
|
|
13
|
+
const organization = await findOrganizationById(id);
|
|
14
|
+
if (!organization) {
|
|
15
|
+
throw new OrganizationNotFoundError(`Organization ${id} not found`);
|
|
16
|
+
}
|
|
17
|
+
return organization;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
-
export * from "./delete-user-organization.js";
|
|
4
|
-
export * from "./find-by-id.js";
|
|
5
3
|
export * from "./find-by-siret.js";
|
|
6
4
|
export * from "./find-by-user-id.js";
|
|
7
5
|
export * from "./find-by-verified-email-domain.js";
|
|
6
|
+
export * from "./find-organization-by-id.js";
|
|
8
7
|
export * from "./find-pending-by-user-id.js";
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./get-
|
|
11
|
-
export * from "./link-user-to-organization.js";
|
|
8
|
+
export * from "./find-users-by-organization.js";
|
|
9
|
+
export * from "./get-organization-by-id.js";
|
|
12
10
|
export * from "./upsert.js";
|
|
@@ -36,6 +36,7 @@ export function upsertFactory({ pg }: DatabaseContext) {
|
|
|
36
36
|
cached_categorie_juridique,
|
|
37
37
|
cached_libelle_categorie_juridique,
|
|
38
38
|
cached_siege_social,
|
|
39
|
+
cached_denomination_usuelle_etablissement_principal,
|
|
39
40
|
} = toPartialOrganization(organizationInfo);
|
|
40
41
|
|
|
41
42
|
const { rows }: QueryResult<Organization> = await pg.query(
|
|
@@ -61,12 +62,13 @@ export function upsertFactory({ pg }: DatabaseContext) {
|
|
|
61
62
|
cached_categorie_juridique,
|
|
62
63
|
cached_libelle_categorie_juridique,
|
|
63
64
|
cached_siege_social,
|
|
65
|
+
cached_denomination_usuelle_etablissement_principal,
|
|
64
66
|
organization_info_fetched_at,
|
|
65
67
|
updated_at,
|
|
66
68
|
created_at
|
|
67
69
|
)
|
|
68
70
|
VALUES
|
|
69
|
-
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)
|
|
71
|
+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)
|
|
70
72
|
ON CONFLICT (siret)
|
|
71
73
|
DO UPDATE
|
|
72
74
|
SET (
|
|
@@ -89,6 +91,7 @@ export function upsertFactory({ pg }: DatabaseContext) {
|
|
|
89
91
|
cached_categorie_juridique,
|
|
90
92
|
cached_libelle_categorie_juridique,
|
|
91
93
|
cached_siege_social,
|
|
94
|
+
cached_denomination_usuelle_etablissement_principal,
|
|
92
95
|
organization_info_fetched_at,
|
|
93
96
|
updated_at
|
|
94
97
|
) = (
|
|
@@ -111,6 +114,7 @@ export function upsertFactory({ pg }: DatabaseContext) {
|
|
|
111
114
|
EXCLUDED.cached_categorie_juridique,
|
|
112
115
|
EXCLUDED.cached_libelle_categorie_juridique,
|
|
113
116
|
EXCLUDED.cached_siege_social,
|
|
117
|
+
EXCLUDED.cached_denomination_usuelle_etablissement_principal,
|
|
114
118
|
EXCLUDED.organization_info_fetched_at,
|
|
115
119
|
EXCLUDED.updated_at
|
|
116
120
|
)
|
|
@@ -136,6 +140,7 @@ export function upsertFactory({ pg }: DatabaseContext) {
|
|
|
136
140
|
cached_categorie_juridique,
|
|
137
141
|
cached_libelle_categorie_juridique,
|
|
138
142
|
cached_siege_social,
|
|
143
|
+
cached_denomination_usuelle_etablissement_principal,
|
|
139
144
|
new Date(),
|
|
140
145
|
new Date(),
|
|
141
146
|
new Date(),
|
|
@@ -157,6 +162,8 @@ function toPartialOrganization(organization_info: OrganizationInfo) {
|
|
|
157
162
|
categorieJuridique: cached_categorie_juridique,
|
|
158
163
|
codeOfficielGeographique: cached_code_officiel_geographique,
|
|
159
164
|
codePostal: cached_code_postal,
|
|
165
|
+
denominationUsuelleEtablissementPrincipal:
|
|
166
|
+
cached_denomination_usuelle_etablissement_principal,
|
|
160
167
|
enseigne: cached_enseigne,
|
|
161
168
|
estActive: cached_est_active,
|
|
162
169
|
estDiffusible: cached_est_diffusible,
|
|
@@ -188,6 +195,7 @@ function toPartialOrganization(organization_info: OrganizationInfo) {
|
|
|
188
195
|
cached_libelle,
|
|
189
196
|
cached_nom_complet,
|
|
190
197
|
cached_siege_social,
|
|
198
|
+
cached_denomination_usuelle_etablissement_principal,
|
|
191
199
|
cached_statut_diffusion,
|
|
192
200
|
cached_tranche_effectifs_unite_legale,
|
|
193
201
|
cached_tranche_effectifs,
|
|
@@ -44,6 +44,7 @@ suite("upset", () => {
|
|
|
44
44
|
cached_statut_diffusion: null,
|
|
45
45
|
cached_tranche_effectifs: null,
|
|
46
46
|
cached_tranche_effectifs_unite_legale: null,
|
|
47
|
+
cached_denomination_usuelle_etablissement_principal: null,
|
|
47
48
|
created_at: new Date("4444-04-04"),
|
|
48
49
|
id: 1,
|
|
49
50
|
organization_info_fetched_at: new Date("4444-04-04"),
|
|
@@ -87,6 +88,7 @@ suite("upset", () => {
|
|
|
87
88
|
cached_statut_diffusion: null,
|
|
88
89
|
cached_tranche_effectifs: null,
|
|
89
90
|
cached_tranche_effectifs_unite_legale: null,
|
|
91
|
+
cached_denomination_usuelle_etablissement_principal: null,
|
|
90
92
|
created_at: new Date("1967-12-19"),
|
|
91
93
|
id: 1,
|
|
92
94
|
organization_info_fetched_at: new Date("4444-04-04"),
|
|
@@ -7,7 +7,4 @@ export * from "./find-by-id.js";
|
|
|
7
7
|
export * from "./find-by-magic-link-token.js";
|
|
8
8
|
export * from "./find-by-reset-password-token.js";
|
|
9
9
|
export * from "./get-by-id.js";
|
|
10
|
-
export * from "./get-franceconnect-user-info.js";
|
|
11
|
-
export * from "./update-user-organization-link.js";
|
|
12
10
|
export * from "./update.js";
|
|
13
|
-
export * from "./upsert-franceconnect-userinfo.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { LinkEnum } from "#src/types";
|
|
2
2
|
import { emptyDatabase, migrate, pg } from "#testing";
|
|
3
3
|
import { before, beforeEach, mock, suite, test } from "node:test";
|
|
4
|
-
import {
|
|
4
|
+
import { createUserOrganizationFactory } from "./create-user-organization.js";
|
|
5
5
|
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
-
const linkUserToOrganization =
|
|
8
|
+
const linkUserToOrganization = createUserOrganizationFactory({ pg: pg as any });
|
|
9
9
|
|
|
10
10
|
suite("linkUserToOrganizationFactory", () => {
|
|
11
11
|
before(migrate);
|
|
@@ -7,9 +7,6 @@ exports[`linkUserToOrganizationFactory > should link user to organization 1`] =
|
|
|
7
7
|
"updated_at": "4444-04-04T00:00:00.000Z",
|
|
8
8
|
"verification_type": "domain_not_verified_yet",
|
|
9
9
|
"has_been_greeted": false,
|
|
10
|
-
"needs_official_contact_email_verification": false,
|
|
11
|
-
"official_contact_email_verification_token": null,
|
|
12
|
-
"official_contact_email_verification_sent_at": null,
|
|
13
10
|
"verified_at": "4444-04-04T00:00:00.000Z"
|
|
14
11
|
}
|
|
15
12
|
`;
|
|
@@ -23,9 +20,6 @@ exports[`linkUserToOrganizationFactory > should mark a user as organization_diri
|
|
|
23
20
|
"updated_at": "4444-04-04T00:00:00.000Z",
|
|
24
21
|
"verification_type": "organization_dirigeant",
|
|
25
22
|
"has_been_greeted": false,
|
|
26
|
-
"needs_official_contact_email_verification": false,
|
|
27
|
-
"official_contact_email_verification_token": null,
|
|
28
|
-
"official_contact_email_verification_sent_at": null,
|
|
29
23
|
"verified_at": "4444-04-04T00:00:00.000Z"
|
|
30
24
|
}
|
|
31
25
|
`;
|
|
@@ -6,10 +6,9 @@ import type {
|
|
|
6
6
|
} from "#src/types";
|
|
7
7
|
import type { QueryResult } from "pg";
|
|
8
8
|
|
|
9
|
-
export function
|
|
9
|
+
export function createUserOrganizationFactory({ pg }: DatabaseContext) {
|
|
10
10
|
return async function linkUserToOrganization({
|
|
11
11
|
is_external = false,
|
|
12
|
-
needs_official_contact_email_verification = false,
|
|
13
12
|
organization_id,
|
|
14
13
|
user_id,
|
|
15
14
|
verification_type,
|
|
@@ -18,7 +17,6 @@ export function linkUserToOrganizationFactory({ pg }: DatabaseContext) {
|
|
|
18
17
|
hashToPostgresParams<UserOrganizationLink>({
|
|
19
18
|
created_at: new Date(),
|
|
20
19
|
is_external,
|
|
21
|
-
needs_official_contact_email_verification,
|
|
22
20
|
organization_id,
|
|
23
21
|
updated_at: new Date(),
|
|
24
22
|
user_id,
|
|
@@ -39,7 +37,3 @@ export function linkUserToOrganizationFactory({ pg }: DatabaseContext) {
|
|
|
39
37
|
return rows.shift()!;
|
|
40
38
|
};
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
export type LinkUserToOrganizationHandler = ReturnType<
|
|
44
|
-
typeof linkUserToOrganizationFactory
|
|
45
|
-
>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
-
import type { DatabaseContext } from "#src/types";
|
|
3
|
+
import type { DatabaseContext, FindUserOrganizationLink } from "#src/types";
|
|
4
4
|
import type { QueryResult } from "pg";
|
|
5
5
|
|
|
6
6
|
//
|
|
@@ -9,14 +9,13 @@ export function deleteUserOrganizationFactory({ pg }: DatabaseContext) {
|
|
|
9
9
|
return async function deleteUserOrganization({
|
|
10
10
|
user_id,
|
|
11
11
|
organization_id,
|
|
12
|
-
}: {
|
|
13
|
-
user_id: number;
|
|
14
|
-
organization_id: number;
|
|
15
|
-
}) {
|
|
12
|
+
}: FindUserOrganizationLink) {
|
|
16
13
|
const { rowCount, affectedRows } = (await pg.query(
|
|
17
14
|
`
|
|
18
|
-
DELETE
|
|
19
|
-
|
|
15
|
+
DELETE
|
|
16
|
+
FROM users_organizations
|
|
17
|
+
WHERE user_id = $1
|
|
18
|
+
AND organization_id = $2`,
|
|
20
19
|
[user_id, organization_id],
|
|
21
20
|
)) as QueryResult & { affectedRows?: number };
|
|
22
21
|
|
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
-
import {
|
|
6
|
+
import { findUserOrganizationFactory } from "./find-user-organization.js";
|
|
7
7
|
|
|
8
8
|
//
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const findUserOrganization = findUserOrganizationFactory({
|
|
11
11
|
pg: pg as any,
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
suite("
|
|
14
|
+
suite("findUserOrganizationFactory", () => {
|
|
15
15
|
before(migrate);
|
|
16
16
|
beforeEach(emptyDatabase);
|
|
17
17
|
|
|
18
18
|
test("should return undefined when the link does not exist", async () => {
|
|
19
|
-
const link = await
|
|
19
|
+
const link = await findUserOrganization({ organization_id: 1, user_id: 1 });
|
|
20
20
|
|
|
21
21
|
assert.equal(link, undefined);
|
|
22
22
|
});
|
|
@@ -44,7 +44,7 @@ suite("getUserOrganizationLinkFactory", () => {
|
|
|
44
44
|
;
|
|
45
45
|
`;
|
|
46
46
|
|
|
47
|
-
const link = await
|
|
47
|
+
const link = await findUserOrganization({ organization_id: 1, user_id: 1 });
|
|
48
48
|
|
|
49
49
|
assert.equal(link?.user_id, 1);
|
|
50
50
|
assert.equal(link?.organization_id, 1);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
DatabaseContext,
|
|
5
|
+
FindUserOrganizationLink,
|
|
6
|
+
UserOrganizationLink,
|
|
7
|
+
} from "#src/types";
|
|
8
|
+
import { type QueryResult } from "pg";
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
export function findUserOrganizationFactory({ pg }: DatabaseContext) {
|
|
13
|
+
return async function findUserOrganization({
|
|
14
|
+
organization_id,
|
|
15
|
+
user_id,
|
|
16
|
+
}: FindUserOrganizationLink) {
|
|
17
|
+
const { rows }: QueryResult<UserOrganizationLink> = await pg.query(
|
|
18
|
+
`
|
|
19
|
+
SELECT user_id,
|
|
20
|
+
organization_id,
|
|
21
|
+
is_external,
|
|
22
|
+
created_at,
|
|
23
|
+
updated_at,
|
|
24
|
+
verification_type,
|
|
25
|
+
verified_at,
|
|
26
|
+
has_been_greeted
|
|
27
|
+
FROM users_organizations
|
|
28
|
+
WHERE organization_id = $1
|
|
29
|
+
AND user_id = $2`,
|
|
30
|
+
[organization_id, user_id],
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return rows.shift();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
-
import {
|
|
6
|
+
import { updateUserOrganizationFactory } from "./update-user-organization.js";
|
|
7
7
|
|
|
8
8
|
//
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const updateUserOrganization = updateUserOrganizationFactory({
|
|
11
11
|
pg: pg as any,
|
|
12
12
|
});
|
|
13
13
|
|
|
@@ -32,15 +32,17 @@ suite("updateUserOrganizationLink", () => {
|
|
|
32
32
|
`;
|
|
33
33
|
await pg.sql`
|
|
34
34
|
INSERT INTO users_organizations
|
|
35
|
-
|
|
36
|
-
VALUES
|
|
37
|
-
(1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_available', false, null, null)
|
|
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')
|
|
38
37
|
;
|
|
39
38
|
`;
|
|
40
39
|
|
|
41
|
-
const user = await
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const user = await updateUserOrganization(
|
|
41
|
+
{ organization_id: 1, user_id: 1 },
|
|
42
|
+
{
|
|
43
|
+
is_external: true,
|
|
44
|
+
},
|
|
45
|
+
);
|
|
44
46
|
assert.ok(user.is_external);
|
|
45
47
|
});
|
|
46
48
|
});
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
3
|
import { hashToPostgresParams } from "#src/services/postgres";
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
DatabaseContext,
|
|
6
|
+
FindUserOrganizationLink,
|
|
7
|
+
User,
|
|
8
|
+
UserOrganizationLink,
|
|
9
|
+
} from "#src/types";
|
|
5
10
|
import type { QueryResult } from "pg";
|
|
6
11
|
|
|
7
12
|
//
|
|
8
13
|
|
|
9
|
-
export function
|
|
10
|
-
return async function
|
|
11
|
-
organization_id:
|
|
12
|
-
user_id: number,
|
|
14
|
+
export function updateUserOrganizationFactory({ pg }: DatabaseContext) {
|
|
15
|
+
return async function updateUserOrganization(
|
|
16
|
+
{ organization_id, user_id }: FindUserOrganizationLink,
|
|
13
17
|
fieldsToUpdate: Partial<UserOrganizationLink>,
|
|
14
18
|
) {
|
|
15
19
|
const connection = pg;
|
|
@@ -36,7 +40,3 @@ export function updateUserOrganizationLinkFactory({ pg }: DatabaseContext) {
|
|
|
36
40
|
return rows.shift()!;
|
|
37
41
|
};
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
export type UpdateUserOrganizationLinkHandler = ReturnType<
|
|
41
|
-
typeof updateUserOrganizationLinkFactory
|
|
42
|
-
>;
|
|
@@ -66,6 +66,16 @@ describe("computeServicePublicInfo", () => {
|
|
|
66
66
|
assert.equal(result.isServicePublic, false);
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
+
it("should return right roles for administration centrale", () => {
|
|
70
|
+
const result = computeServicePublicInfo({
|
|
71
|
+
siret: "26270289700014",
|
|
72
|
+
cached_categorie_juridique: "7364",
|
|
73
|
+
cached_etat_administratif: "A",
|
|
74
|
+
});
|
|
75
|
+
assert.equal(result.isServicePublic, true);
|
|
76
|
+
assert.equal(result.isAdministrationEtat, true);
|
|
77
|
+
});
|
|
78
|
+
|
|
69
79
|
it("should return false for closed entities", () => {
|
|
70
80
|
const closed_org = {
|
|
71
81
|
siret: "12345678900123",
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export type Base64URLString = string;
|
|
4
|
+
export type AuthenticatorTransportFuture =
|
|
5
|
+
| "ble"
|
|
6
|
+
| "cable"
|
|
7
|
+
| "hybrid"
|
|
8
|
+
| "internal"
|
|
9
|
+
| "nfc"
|
|
10
|
+
| "smart-card"
|
|
11
|
+
| "usb";
|
|
12
|
+
export type CredentialDeviceType = "singleDevice" | "multiDevice";
|
|
8
13
|
|
|
9
14
|
//
|
|
10
15
|
|
package/src/types/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./email-domain.js";
|
|
|
8
8
|
export * from "./franceconnect.js";
|
|
9
9
|
export * from "./identity-vector.js";
|
|
10
10
|
export * from "./moderation.js";
|
|
11
|
+
export * from "./official-contact-email-verification.js";
|
|
11
12
|
export * from "./oidc-client.js";
|
|
12
13
|
export * from "./organization-info.js";
|
|
13
14
|
export * from "./organization.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const BaseOfficialContactEmailVerificationSchema = z.object({
|
|
4
|
+
organization_id: z.number(),
|
|
5
|
+
sent_at: z.date().nullable(),
|
|
6
|
+
token: z.string().nullable(),
|
|
7
|
+
user_id: z.number(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export type BaseOfficialContactEmailVerification = z.output<
|
|
11
|
+
typeof BaseOfficialContactEmailVerificationSchema
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
export const OfficialContactEmailVerificationSchema =
|
|
15
|
+
BaseOfficialContactEmailVerificationSchema.extend({
|
|
16
|
+
created_at: z.date(),
|
|
17
|
+
updated_at: z.date(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export type OfficialContactEmailVerification = z.output<
|
|
21
|
+
typeof OfficialContactEmailVerificationSchema
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
export const FindOfficialContactEmailVerificationSchema =
|
|
25
|
+
OfficialContactEmailVerificationSchema.pick({
|
|
26
|
+
organization_id: true,
|
|
27
|
+
user_id: true,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export type FindOfficialContactEmailVerification = z.output<
|
|
31
|
+
typeof FindOfficialContactEmailVerificationSchema
|
|
32
|
+
>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
//
|
|
2
|
-
import type { TrancheEffectifs } from "@proconnect-gouv/proconnect.api_entreprise/types";
|
|
3
2
|
import { z } from "zod";
|
|
3
|
+
import type { TrancheEffectifs } from "./organization.js";
|
|
4
4
|
|
|
5
5
|
//
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const ApiEntrepriseOrganizationInfoSchema = z.object({
|
|
8
8
|
activitePrincipale: z.string(),
|
|
9
9
|
adresse: z.string(),
|
|
10
10
|
categorieJuridique: z.string(),
|
|
@@ -30,4 +30,15 @@ export const OrganizationInfoSchema = z.object({
|
|
|
30
30
|
trancheEffectifsUniteLegale: z.string().nullable(),
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
const ApiRneOrganizationInfoSchema = z.object({
|
|
34
|
+
denominationUsuelleEtablissementPrincipal: z.string().nullable(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export type ApiEntrepriseOrganizationInfo = z.output<
|
|
38
|
+
typeof ApiEntrepriseOrganizationInfoSchema
|
|
39
|
+
>;
|
|
40
|
+
export type ApiRneOrganizationInfo = z.output<
|
|
41
|
+
typeof ApiRneOrganizationInfoSchema
|
|
42
|
+
>;
|
|
43
|
+
export type OrganizationInfo = ApiEntrepriseOrganizationInfo &
|
|
44
|
+
ApiRneOrganizationInfo;
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export type TrancheEffectifs =
|
|
4
|
+
| "NN"
|
|
5
|
+
| "00"
|
|
6
|
+
| "01"
|
|
7
|
+
| "02"
|
|
8
|
+
| "03"
|
|
9
|
+
| "11"
|
|
10
|
+
| "12"
|
|
11
|
+
| "21"
|
|
12
|
+
| "22"
|
|
13
|
+
| "31"
|
|
14
|
+
| "32"
|
|
15
|
+
| "41"
|
|
16
|
+
| "42"
|
|
17
|
+
| "51"
|
|
18
|
+
| "52"
|
|
19
|
+
| "53"
|
|
20
|
+
| null;
|
|
4
21
|
|
|
5
22
|
//
|
|
6
23
|
|
|
@@ -27,5 +44,6 @@ export interface Organization {
|
|
|
27
44
|
cached_categorie_juridique: string | null;
|
|
28
45
|
cached_libelle_categorie_juridique: string | null;
|
|
29
46
|
cached_siege_social: boolean | null;
|
|
47
|
+
cached_denomination_usuelle_etablissement_principal: string | null;
|
|
30
48
|
organization_info_fetched_at: Date | null;
|
|
31
49
|
}
|