@proconnect-gouv/proconnect.identite 1.7.0 → 2.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.
- package/CHANGELOG.md +12 -0
- package/dist/connectors/index.d.ts +110 -0
- package/dist/connectors/index.d.ts.map +1 -0
- package/dist/connectors/index.js +45 -0
- package/dist/managers/organization/adapters/api_entreprise.d.ts +1 -1
- package/dist/managers/organization/mark-domain-as-verified.d.ts +2 -12
- package/dist/managers/organization/mark-domain-as-verified.d.ts.map +1 -1
- package/dist/managers/organization/mark-domain-as-verified.js +9 -10
- package/dist/managers/user/assign-user-verification-type-to-domain.d.ts +2 -9
- 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 +4 -3
- package/dist/services/organization/is-public-service.d.ts +1 -1
- package/dist/services/organization/is-public-service.d.ts.map +1 -1
- package/dist/types/organization-info.d.ts +1 -1
- package/dist/types/user-organization-link.js +2 -2
- package/package.json +1 -1
- package/src/connectors/index.ts +51 -0
- package/src/managers/organization/mark-domain-as-verified.test.ts +50 -64
- package/src/managers/organization/mark-domain-as-verified.ts +13 -33
- package/src/managers/user/assign-user-verification-type-to-domain.test.ts +87 -78
- package/src/managers/user/assign-user-verification-type-to-domain.ts +5 -16
- package/src/services/organization/is-public-service.ts +4 -1
- package/src/types/user-organization-link.ts +2 -2
- package/testing/index.ts +2 -0
- package/tsconfig.lib.tsbuildinfo +1 -1
- package/src/managers/organization/mark-domain-as-verified.test.ts.snapshot +0 -53
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @proconnect-gouv/proconnect.identite
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#1844](https://github.com/proconnect-gouv/proconnect-identite/pull/1844) [`a957ae4`](https://github.com/proconnect-gouv/proconnect-identite/commit/a957ae4c60f0c1567e02102173dae12f84f5be18) Thanks [@douglasduteil](https://github.com/douglasduteil)! - ♻️ Utilisation d'un context global pour utiliser les managers
|
|
8
|
+
|
|
9
|
+
## 1.7.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1858](https://github.com/proconnect-gouv/proconnect-identite/pull/1858) [`91607a8`](https://github.com/proconnect-gouv/proconnect-identite/commit/91607a8ee6193f1fad76a874a09d043ba179d826) Thanks [@BenoitSerrano](https://github.com/BenoitSerrano)! - Le typage de la fonction isPublicService oblige à passer tous les paramètres de Organization à la fonction, alors que seuls trois d'entre eux nous intéresse
|
|
14
|
+
|
|
3
15
|
## 1.7.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type Pool } from "pg";
|
|
2
|
+
export declare function createContext(pg: Pool): {
|
|
3
|
+
repository: {
|
|
4
|
+
email_domains: {
|
|
5
|
+
addDomain: ({ organization_id, domain, verification_type, }: {
|
|
6
|
+
organization_id: number;
|
|
7
|
+
domain: string;
|
|
8
|
+
verification_type: import("../types/email-domain.js").EmailDomainVerificationType;
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
id: number;
|
|
11
|
+
organization_id: number;
|
|
12
|
+
domain: string;
|
|
13
|
+
verification_type: "official_contact" | "trackdechets_postal_mail" | "verified" | "external" | "not_verified_yet" | "blacklisted" | "refused";
|
|
14
|
+
can_be_suggested: boolean;
|
|
15
|
+
verified_at: Date | null;
|
|
16
|
+
created_at: Date;
|
|
17
|
+
updated_at: Date;
|
|
18
|
+
}>;
|
|
19
|
+
deleteEmailDomainsByVerificationTypes: ({ organization_id, domain, domain_verification_types, }: {
|
|
20
|
+
organization_id: import("../types/email-domain.js").EmailDomain["organization_id"];
|
|
21
|
+
domain_verification_types: import("../types/email-domain.js").EmailDomainVerificationType[];
|
|
22
|
+
domain: import("../types/email-domain.js").EmailDomain["domain"];
|
|
23
|
+
}) => Promise<import("pg").QueryResult<any>>;
|
|
24
|
+
findEmailDomainsByOrganizationId: (organization_id: number) => Promise<{
|
|
25
|
+
id: number;
|
|
26
|
+
organization_id: number;
|
|
27
|
+
domain: string;
|
|
28
|
+
verification_type: "official_contact" | "trackdechets_postal_mail" | "verified" | "external" | "not_verified_yet" | "blacklisted" | "refused";
|
|
29
|
+
can_be_suggested: boolean;
|
|
30
|
+
verified_at: Date | null;
|
|
31
|
+
created_at: Date;
|
|
32
|
+
updated_at: Date;
|
|
33
|
+
}[]>;
|
|
34
|
+
};
|
|
35
|
+
organizations: {
|
|
36
|
+
findById: (id: number) => Promise<import("../types/organization.js").Organization | undefined>;
|
|
37
|
+
findByUserId: (userId: number) => Promise<(import("../types/organization.js").Organization & {
|
|
38
|
+
is_external: boolean;
|
|
39
|
+
verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association";
|
|
40
|
+
verified_at: Date | null;
|
|
41
|
+
has_been_greeted: boolean;
|
|
42
|
+
needs_official_contact_email_verification: boolean;
|
|
43
|
+
official_contact_email_verification_token: string | null;
|
|
44
|
+
official_contact_email_verification_sent_at: Date | null;
|
|
45
|
+
})[]>;
|
|
46
|
+
getUsers: (organization_id: number, additionalWhereClause?: string, additionalParams?: any[]) => Promise<(import("../types/user.js").User & {
|
|
47
|
+
is_external: boolean;
|
|
48
|
+
verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association";
|
|
49
|
+
verified_at: Date | null;
|
|
50
|
+
has_been_greeted: boolean;
|
|
51
|
+
needs_official_contact_email_verification: boolean;
|
|
52
|
+
official_contact_email_verification_token: string | null;
|
|
53
|
+
official_contact_email_verification_sent_at: Date | null;
|
|
54
|
+
})[]>;
|
|
55
|
+
};
|
|
56
|
+
users_organizations: {
|
|
57
|
+
update: (organization_id: number, user_id: number, fieldsToUpdate: Partial<import("../types/user-organization-link.js").UserOrganizationLink>) => Promise<{
|
|
58
|
+
is_external: boolean;
|
|
59
|
+
verification_type: "domain" | "organization_dirigeant" | "code_sent_to_official_contact_email" | "imported_from_coop_mediation_numerique" | "imported_from_inclusion_connect" | "in_liste_dirigeants_rna" | "in_liste_dirigeants_rne" | "official_contact_email" | "ordre_professionnel_domain" | "proof_received" | "verified_by_coop_mediation_numerique" | "bypassed" | "domain_not_verified_yet" | "no_validation_means_available" | "no_verification_means_for_entreprise_unipersonnelle" | "no_verification_means_for_small_association";
|
|
60
|
+
verified_at: Date | null;
|
|
61
|
+
has_been_greeted: boolean;
|
|
62
|
+
needs_official_contact_email_verification: boolean;
|
|
63
|
+
official_contact_email_verification_token: string | null;
|
|
64
|
+
official_contact_email_verification_sent_at: Date | null;
|
|
65
|
+
user_id: number;
|
|
66
|
+
organization_id: number;
|
|
67
|
+
created_at: Date;
|
|
68
|
+
updated_at: Date;
|
|
69
|
+
}>;
|
|
70
|
+
};
|
|
71
|
+
users: {
|
|
72
|
+
create: ({ email, encrypted_password, }: {
|
|
73
|
+
email: string;
|
|
74
|
+
encrypted_password?: string | null;
|
|
75
|
+
}) => Promise<import("../types/user.js").User>;
|
|
76
|
+
findByEmail: (email: string) => Promise<import("../types/user.js").User | undefined>;
|
|
77
|
+
findById: (id: number) => Promise<import("../types/user.js").User | undefined>;
|
|
78
|
+
getById: (id: number) => Promise<import("../types/user.js").User>;
|
|
79
|
+
getFranceConnectUserInfo: (user_id: number) => Promise<{
|
|
80
|
+
birthcountry: string;
|
|
81
|
+
birthdate: Date;
|
|
82
|
+
birthplace: string;
|
|
83
|
+
family_name: string;
|
|
84
|
+
gender: string;
|
|
85
|
+
given_name: string;
|
|
86
|
+
sub: string;
|
|
87
|
+
created_at: Date;
|
|
88
|
+
updated_at: Date;
|
|
89
|
+
user_id: number;
|
|
90
|
+
preferred_username?: string | undefined;
|
|
91
|
+
} | undefined>;
|
|
92
|
+
update: (id: number, fieldsToUpdate: Partial<import("../types/user.js").User>) => Promise<import("../types/user.js").User>;
|
|
93
|
+
upsetFranceconnectUserinfo: (value: Pick<import("../types/franceconnect.js").FranceConnectUserInfo, "user_id"> & Partial<import("../types/franceconnect.js").FranceConnectUserInfo>) => Promise<{
|
|
94
|
+
birthcountry: string;
|
|
95
|
+
birthdate: Date;
|
|
96
|
+
birthplace: string;
|
|
97
|
+
family_name: string;
|
|
98
|
+
gender: string;
|
|
99
|
+
given_name: string;
|
|
100
|
+
sub: string;
|
|
101
|
+
created_at: Date;
|
|
102
|
+
updated_at: Date;
|
|
103
|
+
user_id: number;
|
|
104
|
+
preferred_username?: string | undefined;
|
|
105
|
+
}>;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
export type Context = ReturnType<typeof createContext>;
|
|
110
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectors/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC;AAkB/B,wBAAgB,aAAa,CAAC,EAAE,EAAE,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAfgE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4CtG;AACD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//
|
|
2
|
+
import {} from "pg";
|
|
3
|
+
import { addDomainFactory } from "../repositories/email-domain/add-domain.js";
|
|
4
|
+
import { deleteEmailDomainsByVerificationTypesFactory } from "../repositories/email-domain/delete-email-domains-by-verification-types.js";
|
|
5
|
+
import { findEmailDomainsByOrganizationIdFactory } from "../repositories/email-domain/find-email-domains-by-organization-id.js";
|
|
6
|
+
import { findByIdFactory as findOrganizationByIdFactory } from "../repositories/organization/find-by-id.js";
|
|
7
|
+
import { findByUserIdFactory } from "../repositories/organization/find-by-user-id.js";
|
|
8
|
+
import { getUsersByOrganizationFactory } from "../repositories/organization/get-users-by-organization.js";
|
|
9
|
+
import { createUserFactory } from "../repositories/user/create.js";
|
|
10
|
+
import { findByEmailFactory } from "../repositories/user/find-by-email.js";
|
|
11
|
+
import { findByIdFactory as findUserByIdFactory } from "../repositories/user/find-by-id.js";
|
|
12
|
+
import { getByIdFactory } from "../repositories/user/get-by-id.js";
|
|
13
|
+
import { getFranceConnectUserInfoFactory } from "../repositories/user/get-franceconnect-user-info.js";
|
|
14
|
+
import { updateUserOrganizationLinkFactory } from "../repositories/user/update-user-organization-link.js";
|
|
15
|
+
import { updateUserFactory } from "../repositories/user/update.js";
|
|
16
|
+
import { upsertFranceconnectUserinfoFactory } from "../repositories/user/upsert-franceconnect-userinfo.js";
|
|
17
|
+
//
|
|
18
|
+
export function createContext(pg) {
|
|
19
|
+
return {
|
|
20
|
+
repository: {
|
|
21
|
+
email_domains: {
|
|
22
|
+
addDomain: addDomainFactory({ pg }),
|
|
23
|
+
deleteEmailDomainsByVerificationTypes: deleteEmailDomainsByVerificationTypesFactory({ pg }),
|
|
24
|
+
findEmailDomainsByOrganizationId: findEmailDomainsByOrganizationIdFactory({ pg }),
|
|
25
|
+
},
|
|
26
|
+
organizations: {
|
|
27
|
+
findById: findOrganizationByIdFactory({ pg }),
|
|
28
|
+
findByUserId: findByUserIdFactory({ pg }),
|
|
29
|
+
getUsers: getUsersByOrganizationFactory({ pg }),
|
|
30
|
+
},
|
|
31
|
+
users_organizations: {
|
|
32
|
+
update: updateUserOrganizationLinkFactory({ pg }),
|
|
33
|
+
},
|
|
34
|
+
users: {
|
|
35
|
+
create: createUserFactory({ pg }),
|
|
36
|
+
findByEmail: findByEmailFactory({ pg }),
|
|
37
|
+
findById: findUserByIdFactory({ pg }),
|
|
38
|
+
getById: getByIdFactory({ pg }),
|
|
39
|
+
getFranceConnectUserInfo: getFranceConnectUserInfoFactory({ pg }),
|
|
40
|
+
update: updateUserFactory({ pg }),
|
|
41
|
+
upsetFranceconnectUserinfo: upsertFranceconnectUserinfoFactory({ pg }),
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -20,7 +20,7 @@ export declare function toPartialOrganization(organization_info: OrganizationInf
|
|
|
20
20
|
cached_siege_social: boolean;
|
|
21
21
|
cached_statut_diffusion: "diffusible" | "partiellement_diffusible" | "non_diffusible";
|
|
22
22
|
cached_tranche_effectifs_unite_legale: string | null;
|
|
23
|
-
cached_tranche_effectifs: "
|
|
23
|
+
cached_tranche_effectifs: "NN" | "00" | "01" | "02" | "03" | "11" | "12" | "21" | "22" | "31" | "32" | "41" | "42" | "51" | "52" | "53" | null;
|
|
24
24
|
siret: string;
|
|
25
25
|
};
|
|
26
26
|
//# sourceMappingURL=api_entreprise.d.ts.map
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { FindByIdHandler, GetUsersByOrganizationHandler } from "#src/repositories/organization";
|
|
3
|
-
import type { UpdateUserOrganizationLinkHandler } from "#src/repositories/user";
|
|
1
|
+
import type { Context } from "#src/connectors";
|
|
4
2
|
import { type EmailDomainNoPendingVerificationType } from "#src/types";
|
|
5
|
-
|
|
6
|
-
addDomain: AddDomainHandler;
|
|
7
|
-
deleteEmailDomainsByVerificationTypes: DeleteEmailDomainsByVerificationTypesHandler;
|
|
8
|
-
findOrganizationById: FindByIdHandler;
|
|
9
|
-
getUsers: GetUsersByOrganizationHandler;
|
|
10
|
-
updateUserOrganizationLink: UpdateUserOrganizationLinkHandler;
|
|
11
|
-
};
|
|
12
|
-
export declare function markDomainAsVerifiedFactory({ addDomain, deleteEmailDomainsByVerificationTypes, findOrganizationById, getUsers, updateUserOrganizationLink, }: FactoryDependencies): ({ organization_id, domain, domain_verification_type, }: {
|
|
3
|
+
export declare function markDomainAsVerifiedFactory(context: Context): ({ organization_id, domain, domain_verification_type, }: {
|
|
13
4
|
organization_id: number;
|
|
14
5
|
domain: string;
|
|
15
6
|
domain_verification_type: EmailDomainNoPendingVerificationType;
|
|
@@ -24,5 +15,4 @@ export declare function markDomainAsVerifiedFactory({ addDomain, deleteEmailDoma
|
|
|
24
15
|
updated_at: Date;
|
|
25
16
|
}>;
|
|
26
17
|
export type MarkDomainAsVerifiedHandler = ReturnType<typeof markDomainAsVerifiedFactory>;
|
|
27
|
-
export {};
|
|
28
18
|
//# sourceMappingURL=mark-domain-as-verified.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mark-domain-as-verified.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/mark-domain-as-verified.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mark-domain-as-verified.d.ts","sourceRoot":"","sources":["../../../src/managers/organization/mark-domain-as-verified.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAGL,KAAK,oCAAoC,EAK1C,MAAM,YAAY,CAAC;AAOpB,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,IAQf,wDAIxC;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,oCAAoC,CAAC;CAChE;;;;;;;;;GAgFF;AAED,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAClD,OAAO,2BAA2B,CACnC,CAAC"}
|
|
@@ -4,13 +4,12 @@ import { assignUserVerificationTypeToDomainFactory } from "#src/managers/user";
|
|
|
4
4
|
import { EmailDomainApprovedVerificationTypes, EmailDomainPendingVerificationTypes, EmailDomainRejectedVerificationTypes, } from "#src/types";
|
|
5
5
|
import { isEmpty } from "lodash-es";
|
|
6
6
|
import { match } from "ts-pattern";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
7
|
+
//
|
|
8
|
+
export function markDomainAsVerifiedFactory(context) {
|
|
9
|
+
const assignUserVerificationTypeToDomain = assignUserVerificationTypeToDomainFactory(context);
|
|
10
|
+
const { repository: { email_domains, organizations }, } = context;
|
|
12
11
|
return async function markDomainAsVerified({ organization_id, domain, domain_verification_type, }) {
|
|
13
|
-
const organization = await
|
|
12
|
+
const organization = await organizations.findById(organization_id);
|
|
14
13
|
if (isEmpty(organization)) {
|
|
15
14
|
throw new NotFoundError();
|
|
16
15
|
}
|
|
@@ -31,7 +30,7 @@ export function markDomainAsVerifiedFactory({ addDomain, deleteEmailDomainsByVer
|
|
|
31
30
|
.exhaustive();
|
|
32
31
|
};
|
|
33
32
|
async function markDomainAsApproved({ organization_id, domain, domain_verification_type, }) {
|
|
34
|
-
await deleteEmailDomainsByVerificationTypes({
|
|
33
|
+
await email_domains.deleteEmailDomainsByVerificationTypes({
|
|
35
34
|
organization_id,
|
|
36
35
|
domain,
|
|
37
36
|
domain_verification_types: [
|
|
@@ -39,14 +38,14 @@ export function markDomainAsVerifiedFactory({ addDomain, deleteEmailDomainsByVer
|
|
|
39
38
|
...EmailDomainPendingVerificationTypes,
|
|
40
39
|
],
|
|
41
40
|
});
|
|
42
|
-
return addDomain({
|
|
41
|
+
return email_domains.addDomain({
|
|
43
42
|
organization_id,
|
|
44
43
|
domain,
|
|
45
44
|
verification_type: domain_verification_type,
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
47
|
async function markDomainAsRejected({ organization_id, domain, domain_verification_type, }) {
|
|
49
|
-
await deleteEmailDomainsByVerificationTypes({
|
|
48
|
+
await email_domains.deleteEmailDomainsByVerificationTypes({
|
|
50
49
|
organization_id,
|
|
51
50
|
domain,
|
|
52
51
|
domain_verification_types: [
|
|
@@ -54,7 +53,7 @@ export function markDomainAsVerifiedFactory({ addDomain, deleteEmailDomainsByVer
|
|
|
54
53
|
...EmailDomainRejectedVerificationTypes,
|
|
55
54
|
],
|
|
56
55
|
});
|
|
57
|
-
return addDomain({
|
|
56
|
+
return email_domains.addDomain({
|
|
58
57
|
organization_id,
|
|
59
58
|
domain,
|
|
60
59
|
verification_type: domain_verification_type,
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
type FactoryDependencies = {
|
|
4
|
-
getUsers: GetUsersByOrganizationHandler;
|
|
5
|
-
updateUserOrganizationLink: UpdateUserOrganizationLinkHandler;
|
|
6
|
-
};
|
|
7
|
-
export declare function assignUserVerificationTypeToDomainFactory({ getUsers, updateUserOrganizationLink, }: FactoryDependencies): (organization_id: number, domain: string) => Promise<void>;
|
|
8
|
-
export type AssignUserVerificationTypeToDomainFactoryHandler = ReturnType<typeof assignUserVerificationTypeToDomainFactory>;
|
|
9
|
-
export {};
|
|
1
|
+
import type { Context } from "#src/connectors";
|
|
2
|
+
export declare function assignUserVerificationTypeToDomainFactory({ repository: { organizations, users_organizations }, }: Context): (organization_id: number, domain: string) => Promise<void>;
|
|
10
3
|
//# sourceMappingURL=assign-user-verification-type-to-domain.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assign-user-verification-type-to-domain.d.ts","sourceRoot":"","sources":["../../../src/managers/user/assign-user-verification-type-to-domain.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"assign-user-verification-type-to-domain.d.ts","sourceRoot":"","sources":["../../../src/managers/user/assign-user-verification-type-to-domain.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAO/C,wBAAgB,yCAAyC,CAAC,EACxD,UAAU,EAAE,EAAE,aAAa,EAAE,mBAAmB,EAAE,GACnD,EAAE,OAAO,IAEN,iBAAiB,MAAM,EACvB,QAAQ,MAAM,mBAwBjB"}
|
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
import { LinkTypes, SuperWeakLinkTypes, UnverifiedLinkTypes } from "#src/types";
|
|
3
3
|
import { getEmailDomain } from "@proconnect-gouv/proconnect.core/services/email";
|
|
4
4
|
import { match } from "ts-pattern";
|
|
5
|
-
|
|
5
|
+
//
|
|
6
|
+
export function assignUserVerificationTypeToDomainFactory({ repository: { organizations, users_organizations }, }) {
|
|
6
7
|
return async function assignUserVerificationTypeToDomain(organization_id, domain) {
|
|
7
|
-
const usersInOrganization = await getUsers(organization_id);
|
|
8
|
+
const usersInOrganization = await organizations.getUsers(organization_id);
|
|
8
9
|
await Promise.all(usersInOrganization.map(({ id, email, verification_type: link_verification_type }) => {
|
|
9
10
|
const userDomain = getEmailDomain(email);
|
|
10
11
|
if (userDomain === domain &&
|
|
11
12
|
match(link_verification_type)
|
|
12
13
|
.with(...UnverifiedLinkTypes, ...SuperWeakLinkTypes, () => true)
|
|
13
14
|
.otherwise(() => false)) {
|
|
14
|
-
return
|
|
15
|
+
return users_organizations.update(organization_id, id, {
|
|
15
16
|
verification_type: LinkTypes.enum.domain,
|
|
16
17
|
});
|
|
17
18
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Organization } from "#src/types";
|
|
2
|
-
export declare const isPublicService: ({ cached_categorie_juridique, cached_etat_administratif, siret, }: Organization) => boolean;
|
|
2
|
+
export declare const isPublicService: ({ cached_categorie_juridique, cached_etat_administratif, siret, }: Pick<Organization, "cached_categorie_juridique" | "cached_etat_administratif" | "siret">) => boolean;
|
|
3
3
|
//# sourceMappingURL=is-public-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-public-service.d.ts","sourceRoot":"","sources":["../../../src/services/organization/is-public-service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAQ/C,eAAO,MAAM,eAAe,GAAI,mEAI7B,YAAY,KAAG,
|
|
1
|
+
{"version":3,"file":"is-public-service.d.ts","sourceRoot":"","sources":["../../../src/services/organization/is-public-service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAQ/C,eAAO,MAAM,eAAe,GAAI,mEAI7B,IAAI,CACL,YAAY,EACZ,4BAA4B,GAAG,2BAA2B,GAAG,OAAO,CACrE,KAAG,OAiCH,CAAC"}
|
|
@@ -21,7 +21,7 @@ export declare const OrganizationInfoSchema: z.ZodObject<{
|
|
|
21
21
|
partiellement_diffusible: "partiellement_diffusible";
|
|
22
22
|
non_diffusible: "non_diffusible";
|
|
23
23
|
}>;
|
|
24
|
-
trancheEffectifs: z.ZodNullable<z.ZodCustom<"
|
|
24
|
+
trancheEffectifs: z.ZodNullable<z.ZodCustom<"NN" | "00" | "01" | "02" | "03" | "11" | "12" | "21" | "22" | "31" | "32" | "41" | "42" | "51" | "52" | "53" | null, "NN" | "00" | "01" | "02" | "03" | "11" | "12" | "21" | "22" | "31" | "32" | "41" | "42" | "51" | "52" | "53" | null>>;
|
|
25
25
|
trancheEffectifsUniteLegale: z.ZodNullable<z.ZodString>;
|
|
26
26
|
}, z.core.$strip>;
|
|
27
27
|
export type OrganizationInfo = z.output<typeof OrganizationInfoSchema>;
|
|
@@ -52,7 +52,7 @@ export const InsertUserOrganizationLinkSchema = UserOrganizationLinkSchema.pick(
|
|
|
52
52
|
organization_id: true,
|
|
53
53
|
user_id: true,
|
|
54
54
|
verification_type: true,
|
|
55
|
-
}).
|
|
55
|
+
}).extend(UserOrganizationLinkSchema.pick({
|
|
56
56
|
is_external: true,
|
|
57
57
|
needs_official_contact_email_verification: true,
|
|
58
|
-
}).partial());
|
|
58
|
+
}).partial().shape);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/identite#readme",
|
|
5
5
|
"bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
|
|
6
6
|
"repository": {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { type Pool } from "pg";
|
|
4
|
+
import { addDomainFactory } from "../repositories/email-domain/add-domain.js";
|
|
5
|
+
import { deleteEmailDomainsByVerificationTypesFactory } from "../repositories/email-domain/delete-email-domains-by-verification-types.js";
|
|
6
|
+
import { findEmailDomainsByOrganizationIdFactory } from "../repositories/email-domain/find-email-domains-by-organization-id.js";
|
|
7
|
+
import { findByIdFactory as findOrganizationByIdFactory } from "../repositories/organization/find-by-id.js";
|
|
8
|
+
import { findByUserIdFactory } from "../repositories/organization/find-by-user-id.js";
|
|
9
|
+
import { getUsersByOrganizationFactory } from "../repositories/organization/get-users-by-organization.js";
|
|
10
|
+
import { createUserFactory } from "../repositories/user/create.js";
|
|
11
|
+
import { findByEmailFactory } from "../repositories/user/find-by-email.js";
|
|
12
|
+
import { findByIdFactory as findUserByIdFactory } from "../repositories/user/find-by-id.js";
|
|
13
|
+
import { getByIdFactory } from "../repositories/user/get-by-id.js";
|
|
14
|
+
import { getFranceConnectUserInfoFactory } from "../repositories/user/get-franceconnect-user-info.js";
|
|
15
|
+
import { updateUserOrganizationLinkFactory } from "../repositories/user/update-user-organization-link.js";
|
|
16
|
+
import { updateUserFactory } from "../repositories/user/update.js";
|
|
17
|
+
import { upsertFranceconnectUserinfoFactory } from "../repositories/user/upsert-franceconnect-userinfo.js";
|
|
18
|
+
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
export function createContext(pg: Pool) {
|
|
22
|
+
return {
|
|
23
|
+
repository: {
|
|
24
|
+
email_domains: {
|
|
25
|
+
addDomain: addDomainFactory({ pg }),
|
|
26
|
+
deleteEmailDomainsByVerificationTypes:
|
|
27
|
+
deleteEmailDomainsByVerificationTypesFactory({ pg }),
|
|
28
|
+
findEmailDomainsByOrganizationId:
|
|
29
|
+
findEmailDomainsByOrganizationIdFactory({ pg }),
|
|
30
|
+
},
|
|
31
|
+
organizations: {
|
|
32
|
+
findById: findOrganizationByIdFactory({ pg }),
|
|
33
|
+
findByUserId: findByUserIdFactory({ pg }),
|
|
34
|
+
getUsers: getUsersByOrganizationFactory({ pg }),
|
|
35
|
+
},
|
|
36
|
+
users_organizations: {
|
|
37
|
+
update: updateUserOrganizationLinkFactory({ pg }),
|
|
38
|
+
},
|
|
39
|
+
users: {
|
|
40
|
+
create: createUserFactory({ pg }),
|
|
41
|
+
findByEmail: findByEmailFactory({ pg }),
|
|
42
|
+
findById: findUserByIdFactory({ pg }),
|
|
43
|
+
getById: getByIdFactory({ pg }),
|
|
44
|
+
getFranceConnectUserInfo: getFranceConnectUserInfoFactory({ pg }),
|
|
45
|
+
update: updateUserFactory({ pg }),
|
|
46
|
+
upsetFranceconnectUserinfo: upsertFranceconnectUserinfoFactory({ pg }),
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export type Context = ReturnType<typeof createContext>;
|
|
@@ -1,89 +1,75 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
1
3
|
import { NotFoundError } from "#src/errors";
|
|
2
|
-
import {
|
|
3
|
-
type AddDomainHandler,
|
|
4
|
-
type DeleteEmailDomainsByVerificationTypesHandler,
|
|
5
|
-
} from "#src/repositories/email-domain";
|
|
6
|
-
import type {
|
|
7
|
-
FindByIdHandler,
|
|
8
|
-
GetUsersByOrganizationHandler,
|
|
9
|
-
} from "#src/repositories/organization";
|
|
10
|
-
import type { UpdateUserOrganizationLinkHandler } from "#src/repositories/user";
|
|
11
|
-
import type { BaseUserOrganizationLink, Organization, User } from "#src/types";
|
|
4
|
+
import { context, emptyDatabase, migrate, pg } from "#testing";
|
|
12
5
|
import assert from "node:assert/strict";
|
|
13
|
-
import { describe, it
|
|
6
|
+
import { before, beforeEach, describe, it } from "node:test";
|
|
14
7
|
import { markDomainAsVerifiedFactory } from "./mark-domain-as-verified.js";
|
|
15
8
|
|
|
16
9
|
//
|
|
17
10
|
|
|
11
|
+
const markDomainAsVerified = markDomainAsVerifiedFactory(context);
|
|
12
|
+
|
|
18
13
|
describe("markDomainAsVerified", () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Promise.resolve({} as any),
|
|
22
|
-
);
|
|
23
|
-
const deleteEmailDomainsByVerificationTypes =
|
|
24
|
-
mock.fn<DeleteEmailDomainsByVerificationTypesHandler>(() =>
|
|
25
|
-
Promise.resolve({} as any),
|
|
26
|
-
);
|
|
27
|
-
const updateUserOrganizationLink =
|
|
28
|
-
mock.fn<UpdateUserOrganizationLinkHandler>(() =>
|
|
29
|
-
Promise.resolve({} as any),
|
|
30
|
-
);
|
|
14
|
+
before(migrate);
|
|
15
|
+
beforeEach(emptyDatabase);
|
|
31
16
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
17
|
+
it("should update organization members", async () => {
|
|
18
|
+
await pg.sql`
|
|
19
|
+
INSERT INTO organizations
|
|
20
|
+
(id, cached_libelle, cached_nom_complet, siret, created_at, updated_at)
|
|
21
|
+
VALUES
|
|
22
|
+
(1, 'Dark Angels', 'Dark Angels Legion', '🦁', '4444-04-04', '4444-04-04')
|
|
23
|
+
;
|
|
24
|
+
`;
|
|
25
|
+
await pg.sql`
|
|
26
|
+
INSERT INTO users (id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
27
|
+
VALUES (1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'Lion', 'El''Jonson', '0', 'Primarque')
|
|
28
|
+
`;
|
|
29
|
+
await pg.sql`
|
|
30
|
+
INSERT INTO users_organizations
|
|
31
|
+
(user_id, organization_id, created_at, updated_at, is_external, verification_type, needs_official_contact_email_verification, official_contact_email_verification_token, official_contact_email_verification_sent_at)
|
|
32
|
+
VALUES
|
|
33
|
+
(1, 1, '4444-04-04', '4444-04-04', false, 'no_verification_means_for_entreprise_unipersonnelle', false, null, null)
|
|
34
|
+
;
|
|
35
|
+
`;
|
|
36
|
+
await pg.sql`
|
|
37
|
+
INSERT INTO email_domains (organization_id, domain, verification_type)
|
|
38
|
+
VALUES (1, 'darkangels.world', 'not_verified_yet')
|
|
39
|
+
`;
|
|
50
40
|
|
|
51
41
|
await markDomainAsVerified({
|
|
52
42
|
domain: "darkangels.world",
|
|
53
43
|
domain_verification_type: "verified",
|
|
54
|
-
organization_id:
|
|
44
|
+
organization_id: 1,
|
|
55
45
|
});
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
// user verification_type should be updated to "domain"
|
|
48
|
+
const { rows: userLinks } = await pg.sql`
|
|
49
|
+
SELECT user_id, verification_type
|
|
50
|
+
FROM users_organizations
|
|
51
|
+
WHERE organization_id = 1
|
|
52
|
+
`;
|
|
53
|
+
assert.deepEqual(userLinks, [{ user_id: 1, verification_type: "domain" }]);
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
55
|
+
// old email_domain records should be replaced with "verified"
|
|
56
|
+
const { rows: emailDomains } = await pg.sql`
|
|
57
|
+
SELECT domain, verification_type
|
|
58
|
+
FROM email_domains
|
|
59
|
+
WHERE organization_id = 1
|
|
60
|
+
ORDER BY verification_type
|
|
61
|
+
`;
|
|
62
|
+
assert.deepEqual(emailDomains, [
|
|
63
|
+
{ domain: "darkangels.world", verification_type: "verified" },
|
|
64
|
+
]);
|
|
71
65
|
});
|
|
72
66
|
|
|
73
67
|
it("❎ throws NotFoundError for unknown organization", async () => {
|
|
74
|
-
const markDomainAsVerified = markDomainAsVerifiedFactory({
|
|
75
|
-
addDomain: () => Promise.reject(),
|
|
76
|
-
deleteEmailDomainsByVerificationTypes: () => Promise.reject(),
|
|
77
|
-
findOrganizationById: () => Promise.resolve(undefined),
|
|
78
|
-
getUsers: () => Promise.reject(),
|
|
79
|
-
updateUserOrganizationLink: () => Promise.reject(),
|
|
80
|
-
});
|
|
81
|
-
|
|
82
68
|
await assert.rejects(
|
|
83
69
|
markDomainAsVerified({
|
|
84
70
|
domain: "darkangels.world",
|
|
85
71
|
domain_verification_type: "verified",
|
|
86
|
-
organization_id:
|
|
72
|
+
organization_id: 999,
|
|
87
73
|
}),
|
|
88
74
|
new NotFoundError(""),
|
|
89
75
|
);
|