@proconnect-gouv/proconnect.identite 10.2.1 → 10.3.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 +14 -0
- package/dist/connectors/index.d.ts +10 -0
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +2 -1
- package/dist/errors/index.d.ts +3 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +6 -0
- package/dist/managers/franceconnect/openid-client.d.ts +1 -1
- package/dist/managers/franceconnect/openid-client.d.ts.map +1 -1
- package/dist/managers/franceconnect/openid-client.js +4 -2
- package/dist/repositories/user_organisation/get-user-organization.d.ts +12 -0
- package/dist/repositories/user_organisation/get-user-organization.d.ts.map +1 -0
- package/dist/repositories/user_organisation/get-user-organization.js +15 -0
- package/dist/repositories/user_organisation/index.d.ts +1 -0
- package/dist/repositories/user_organisation/index.d.ts.map +1 -1
- package/dist/repositories/user_organisation/index.js +1 -0
- package/package.json +3 -3
- package/src/connectors/index.ts +2 -0
- package/src/errors/index.ts +7 -0
- package/src/managers/franceconnect/openid-client.ts +5 -3
- package/src/repositories/user_organisation/get-user-organization.test.ts +63 -0
- package/src/repositories/user_organisation/get-user-organization.ts +22 -0
- package/src/repositories/user_organisation/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @proconnect-gouv/proconnect.identite
|
|
2
2
|
|
|
3
|
+
## 10.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#2175](https://github.com/proconnect-gouv/proconnect-identite/pull/2175) [`ab7f8af`](https://github.com/proconnect-gouv/proconnect-identite/commit/ab7f8af1394f815d9b7fa25726d7b482cc80b632) Thanks [@rdubigny](https://github.com/rdubigny)! - ajout de la fonction getUserOrganization dans les repositories
|
|
8
|
+
|
|
9
|
+
## 10.2.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#2170](https://github.com/proconnect-gouv/proconnect-identite/pull/2170) [`5fc628d`](https://github.com/proconnect-gouv/proconnect-identite/commit/5fc628d82e7b2ae0bcc1961d5d7a7e3f1fd0c7d2) Thanks [@BenoitSerrano](https://github.com/BenoitSerrano)! - renommage de la variable allowLocalhost pour FranceConnect en allowInsecureRequests
|
|
14
|
+
- Updated dependencies [[`9a0ca7c`](https://github.com/proconnect-gouv/proconnect-identite/commit/9a0ca7c55d8ad6dd70cd49f6ddf470a4ee436f42)]:
|
|
15
|
+
- @proconnect-gouv/proconnect.annuaire_entreprises@3.0.5
|
|
16
|
+
|
|
3
17
|
## 10.2.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -570,6 +570,16 @@ export declare function createContext({ api_entreprise_client, api_insee_client,
|
|
|
570
570
|
created_at: Date;
|
|
571
571
|
updated_at: Date;
|
|
572
572
|
} | undefined>;
|
|
573
|
+
get: ({ organization_id, user_id, }: import("../types/user-organization-link.js").FindUserOrganizationLink) => Promise<{
|
|
574
|
+
is_external: boolean;
|
|
575
|
+
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" | "no_verification_means_for_small_organization";
|
|
576
|
+
verified_at: Date | null;
|
|
577
|
+
has_been_greeted: boolean;
|
|
578
|
+
user_id: number;
|
|
579
|
+
organization_id: number;
|
|
580
|
+
created_at: Date;
|
|
581
|
+
updated_at: Date;
|
|
582
|
+
}>;
|
|
573
583
|
update: ({ organization_id, user_id }: import("../types/user-organization-link.js").FindUserOrganizationLink, fieldsToUpdate: Partial<import("../types/user-organization-link.js").UserOrganizationLink>) => Promise<{
|
|
574
584
|
is_external: boolean;
|
|
575
585
|
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" | "no_verification_means_for_small_organization";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectors/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectors/index.ts"],"names":[],"mappings":"AAiEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AAC1H,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC;AAI/B,wBAAgB,aAAa,CAAC,EAC5B,qBAAqB,EACrB,gBAAgB,EAChB,wCAAwC,EACxC,EAAE,GACH,EAAE;IACD,qBAAqB,EAAE,mBAAmB,CAAC;IAC3C,gBAAgB,EAAE,cAAc,CAAC;IACjC,wCAAwC,EAAE,oCAAoC,CAAC;IAC/E,EAAE,EAAE,IAAI,CAAC;CACV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCAgFwxF,CAAC;oBAAkC,CAAC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AAL;6CACU,CAAC;6CAEL,CAAC;mCAEF,CAAN;yDAC4B,CAAC;mCAEZ,CAAC;mDACF,CAAC;yCACX,CAAR;6CACkB,CAAC;;;;;8BArIjB,CAAD;qBACqB,CAAC;wBAErB,CAAC;uCACQ,CAAC;uCACQ,CAAC;2BAEnB,CAAA;+BACY,CAAC;6BAEV,CAAC;uCAEQ,CAAC;2CACQ,CAAC;qCACI,CAAC;6CACU,CAAC;yCAElB,CAAC;;;;;kBAME,CAAC;yBACG,CAAC;2BACR,CAAC;sCACI,CAAC;uCAE1B,CAAF;wCACmB,CAAC;kDAEJ,CAAC;yCAIf,CAAA;4CACwB,CAAC;2DAGzB,CAAA;2DAEa,CAAC;+CAEL,CAAC;mDAEI,CAAC;iDAEd,CAAC;2DAA4E,CAAC;+DACd,CAAC;yDACN,CAAC;iEAC5C,CAAC;6DAMlB,CAAA;;;;;;wCAQC,CAAA;kDAGgB,CAAC;wDACO,CAAC;iDACc,CAAC;;;;;kCAM1B,CAAC;;qBACU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAjFN,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCADjB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoJP;AACD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
package/dist/connectors/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { deleteOfficialContactEmailVerificationFactory, findOfficialContactEmail
|
|
|
8
8
|
import { addConnectionFactory, findByClientIdFactory, } from "#src/repositories/oidc-client";
|
|
9
9
|
import { findBySiretFactory, findByUserIdFactory, findByVerifiedEmailDomainFactory, findOrganizationByIdFactory, findPendingByUserIdFactory, findUsersByOrganizationFactory, getOrganizationByIdFactory, upsertFactory, } from "#src/repositories/organization";
|
|
10
10
|
import { createUserFactory, deleteUserFactory, findByEmailFactory, findByMagicLinkTokenFactory, findByResetPasswordTokenFactory, findByIdFactory as findUserByIdFactory, getByIdFactory, updateUserFactory, } from "#src/repositories/user";
|
|
11
|
-
import { createUserOrganizationFactory, deleteUserOrganizationFactory, findUserOrganizationFactory, updateUserOrganizationFactory, } from "#src/repositories/user_organisation";
|
|
11
|
+
import { createUserOrganizationFactory, deleteUserOrganizationFactory, findUserOrganizationFactory, getUserOrganizationFactory, updateUserOrganizationFactory, } from "#src/repositories/user_organisation";
|
|
12
12
|
import {} from "pg";
|
|
13
13
|
//
|
|
14
14
|
export function createContext({ api_entreprise_client, api_insee_client, api_registre_national_entreprises_client, pg, }) {
|
|
@@ -66,6 +66,7 @@ export function createContext({ api_entreprise_client, api_insee_client, api_reg
|
|
|
66
66
|
create: createUserOrganizationFactory({ pg }),
|
|
67
67
|
delete: deleteUserOrganizationFactory({ pg }),
|
|
68
68
|
find: findUserOrganizationFactory({ pg }),
|
|
69
|
+
get: getUserOrganizationFactory({ pg }),
|
|
69
70
|
update: updateUserOrganizationFactory({ pg }),
|
|
70
71
|
},
|
|
71
72
|
users: {
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -13,4 +13,7 @@ export declare class OrganizationNotFoundError extends Error {
|
|
|
13
13
|
export declare class UserNotFoundError extends Error {
|
|
14
14
|
constructor(message?: string, options?: ErrorOptions);
|
|
15
15
|
}
|
|
16
|
+
export declare class LinkNotFoundError extends Error {
|
|
17
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
18
|
+
}
|
|
16
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":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HANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openid-client.d.ts","sourceRoot":"","sources":["../../../src/managers/franceconnect/openid-client.ts"],"names":[],"mappings":"AAMA,OAAO,EAUL,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAKvB,MAAM,MAAM,gCAAgC,GAAG;IAC7C,
|
|
1
|
+
{"version":3,"file":"openid-client.d.ts","sourceRoot":"","sources":["../../../src/managers/franceconnect/openid-client.ts"],"names":[],"mappings":"AAMA,OAAO,EAUL,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAKvB,MAAM,MAAM,gCAAgC,GAAG;IAC7C,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAClC,MAAM,EAAE,GAAG,CAAC;CACb,CAAC;AAEF,wBAAgB,oCAAoC,CAClD,MAAM,EAAE,gCAAgC,wDAczC;AAED,MAAM,MAAM,oCAAoC,GAAG,UAAU,CAC3D,OAAO,oCAAoC,CAC5C,CAAC;AAEF,wBAAgB,gBAAgB;;;EAK/B;AAED,wBAAgB,kCAAkC,CAChD,gBAAgB,EAAE,oCAAoC,EACtD,UAAU,EAAE;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf,IAG0C,OAAO,MAAM,EAAE,OAAO,MAAM,kBAaxE;AAED,wBAAgB,2BAA2B,CACzC,gBAAgB,EAAE,oCAAoC,IAEX,YAAY;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,GAAG,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB;;;;;;;;;;;;GA0BF;AAED,wBAAgB,wCAAwC,CACtD,gBAAgB,EAAE,oCAAoC,IAGpD,eAAe,MAAM,EACrB,0BAA0B,MAAM,EAChC,OAAO,MAAM,kBAShB"}
|
|
@@ -3,9 +3,11 @@ import { FranceConnectUserInfoResponseSchema, } from "#src/types";
|
|
|
3
3
|
import { allowInsecureRequests, authorizationCodeGrant, buildAuthorizationUrl, buildEndSessionUrl, ClientSecretBasic, discovery, fetchUserInfo, randomNonce, randomState, } from "openid-client";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
export function getFranceConnectConfigurationFactory(params) {
|
|
6
|
-
const {
|
|
6
|
+
const { clientId, clientSecret, metadata, server } = params;
|
|
7
7
|
return function getFranceConnectConfiguration() {
|
|
8
|
-
return discovery(server, clientId, metadata, ClientSecretBasic(clientSecret),
|
|
8
|
+
return discovery(server, clientId, metadata, ClientSecretBasic(clientSecret), params.allowInsecureRequests
|
|
9
|
+
? { execute: [allowInsecureRequests] }
|
|
10
|
+
: undefined);
|
|
9
11
|
};
|
|
10
12
|
}
|
|
11
13
|
export function createOidcChecks() {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DatabaseContext, FindUserOrganizationLink } from "#src/types";
|
|
2
|
+
export declare function getUserOrganizationFactory({ pg }: DatabaseContext): ({ organization_id, user_id, }: FindUserOrganizationLink) => Promise<{
|
|
3
|
+
is_external: boolean;
|
|
4
|
+
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" | "no_verification_means_for_small_organization";
|
|
5
|
+
verified_at: Date | null;
|
|
6
|
+
has_been_greeted: boolean;
|
|
7
|
+
user_id: number;
|
|
8
|
+
organization_id: number;
|
|
9
|
+
created_at: Date;
|
|
10
|
+
updated_at: Date;
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=get-user-organization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-user-organization.d.ts","sourceRoot":"","sources":["../../../src/repositories/user_organisation/get-user-organization.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAM5E,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,EAAE,EAAE,eAAe,IAEtB,+BAGvC,wBAAwB;;;;;;;;;GAO5B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//
|
|
2
|
+
import { LinkNotFoundError } from "#src/errors";
|
|
3
|
+
import { isEmpty } from "lodash-es";
|
|
4
|
+
import { findUserOrganizationFactory } from "./find-user-organization.js";
|
|
5
|
+
//
|
|
6
|
+
export function getUserOrganizationFactory({ pg }) {
|
|
7
|
+
const findUserOrganization = findUserOrganizationFactory({ pg });
|
|
8
|
+
return async function getUserOrganization({ organization_id, user_id, }) {
|
|
9
|
+
const link = await findUserOrganization({ organization_id, user_id });
|
|
10
|
+
if (isEmpty(link)) {
|
|
11
|
+
throw new LinkNotFoundError("Link not found");
|
|
12
|
+
}
|
|
13
|
+
return link;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./create-user-organization.js";
|
|
2
2
|
export * from "./delete-user-organization.js";
|
|
3
3
|
export * from "./find-user-organization.js";
|
|
4
|
+
export * from "./get-user-organization.js";
|
|
4
5
|
export * from "./update-user-organization.js";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/user_organisation/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/user_organisation/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.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": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@electric-sql/pglite": "^0.3.12",
|
|
54
|
-
"@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.
|
|
54
|
+
"@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.5",
|
|
55
55
|
"@proconnect-gouv/proconnect.api_entreprise": "^2.3.0",
|
|
56
56
|
"@proconnect-gouv/proconnect.core": "^1.0.0",
|
|
57
57
|
"@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"tsx": "^4.20.3"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.
|
|
68
|
+
"@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.5",
|
|
69
69
|
"@proconnect-gouv/proconnect.api_entreprise": "^2.3.0",
|
|
70
70
|
"@proconnect-gouv/proconnect.core": "^1.0.0",
|
|
71
71
|
"@proconnect-gouv/proconnect.insee": "^2.0.0",
|
package/src/connectors/index.ts
CHANGED
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
createUserOrganizationFactory,
|
|
61
61
|
deleteUserOrganizationFactory,
|
|
62
62
|
findUserOrganizationFactory,
|
|
63
|
+
getUserOrganizationFactory,
|
|
63
64
|
updateUserOrganizationFactory,
|
|
64
65
|
} from "#src/repositories/user_organisation";
|
|
65
66
|
import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entreprise/api";
|
|
@@ -137,6 +138,7 @@ export function createContext({
|
|
|
137
138
|
create: createUserOrganizationFactory({ pg }),
|
|
138
139
|
delete: deleteUserOrganizationFactory({ pg }),
|
|
139
140
|
find: findUserOrganizationFactory({ pg }),
|
|
141
|
+
get: getUserOrganizationFactory({ pg }),
|
|
140
142
|
update: updateUserOrganizationFactory({ pg }),
|
|
141
143
|
},
|
|
142
144
|
users: {
|
package/src/errors/index.ts
CHANGED
|
@@ -34,3 +34,10 @@ export class UserNotFoundError extends Error {
|
|
|
34
34
|
this.name = "UserNotFoundError";
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
export class LinkNotFoundError extends Error {
|
|
39
|
+
constructor(message?: string, options?: ErrorOptions) {
|
|
40
|
+
super(message, options);
|
|
41
|
+
this.name = "LinkNotFoundError";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -21,7 +21,7 @@ import { z } from "zod";
|
|
|
21
21
|
//
|
|
22
22
|
|
|
23
23
|
export type FranceConnectConfigurationParams = {
|
|
24
|
-
|
|
24
|
+
allowInsecureRequests?: boolean;
|
|
25
25
|
clientId: string;
|
|
26
26
|
clientSecret: string;
|
|
27
27
|
metadata: Partial<ClientMetadata>;
|
|
@@ -31,14 +31,16 @@ export type FranceConnectConfigurationParams = {
|
|
|
31
31
|
export function getFranceConnectConfigurationFactory(
|
|
32
32
|
params: FranceConnectConfigurationParams,
|
|
33
33
|
) {
|
|
34
|
-
const {
|
|
34
|
+
const { clientId, clientSecret, metadata, server } = params;
|
|
35
35
|
return function getFranceConnectConfiguration() {
|
|
36
36
|
return discovery(
|
|
37
37
|
server,
|
|
38
38
|
clientId,
|
|
39
39
|
metadata,
|
|
40
40
|
ClientSecretBasic(clientSecret),
|
|
41
|
-
|
|
41
|
+
params.allowInsecureRequests
|
|
42
|
+
? { execute: [allowInsecureRequests] }
|
|
43
|
+
: undefined,
|
|
42
44
|
);
|
|
43
45
|
};
|
|
44
46
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { LinkNotFoundError } from "#src/errors";
|
|
4
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
7
|
+
import { getUserOrganizationFactory } from "./get-user-organization.js";
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
const getUserOrganization = getUserOrganizationFactory({ pg: pg as any });
|
|
12
|
+
|
|
13
|
+
suite("getUserOrganizationFactory", () => {
|
|
14
|
+
before(migrate);
|
|
15
|
+
beforeEach(emptyDatabase);
|
|
16
|
+
|
|
17
|
+
test("should get the link between a user and an organization", async () => {
|
|
18
|
+
await pg.sql`
|
|
19
|
+
INSERT INTO organizations
|
|
20
|
+
(cached_libelle, cached_nom_complet, id, siret, created_at, updated_at)
|
|
21
|
+
VALUES
|
|
22
|
+
('Necron', 'Necrontyr', 1, '⚰️', '1967-12-19', '1967-12-19')
|
|
23
|
+
;
|
|
24
|
+
`;
|
|
25
|
+
await pg.sql`
|
|
26
|
+
INSERT INTO users
|
|
27
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
28
|
+
VALUES
|
|
29
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
30
|
+
;
|
|
31
|
+
`;
|
|
32
|
+
await pg.sql`
|
|
33
|
+
INSERT INTO users_organizations
|
|
34
|
+
(user_id, organization_id, created_at, updated_at, verification_type)
|
|
35
|
+
VALUES
|
|
36
|
+
(1, 1, '4444-04-04', '4444-04-04', 'domain_not_verified_yet')
|
|
37
|
+
;
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const link = await getUserOrganization({
|
|
41
|
+
organization_id: 1,
|
|
42
|
+
user_id: 1,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
assert.deepEqual(link, {
|
|
46
|
+
created_at: new Date("4444-04-04"),
|
|
47
|
+
has_been_greeted: false,
|
|
48
|
+
is_external: false,
|
|
49
|
+
organization_id: 1,
|
|
50
|
+
updated_at: new Date("4444-04-04"),
|
|
51
|
+
user_id: 1,
|
|
52
|
+
verification_type: "domain_not_verified_yet",
|
|
53
|
+
verified_at: null,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("❎ fail to find a link that does not exist", async () => {
|
|
58
|
+
await assert.rejects(
|
|
59
|
+
getUserOrganization({ organization_id: 42, user_id: 42 }),
|
|
60
|
+
new LinkNotFoundError("Link not found"),
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { LinkNotFoundError } from "#src/errors";
|
|
4
|
+
import type { DatabaseContext, FindUserOrganizationLink } from "#src/types";
|
|
5
|
+
import { isEmpty } from "lodash-es";
|
|
6
|
+
import { findUserOrganizationFactory } from "./find-user-organization.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
export function getUserOrganizationFactory({ pg }: DatabaseContext) {
|
|
11
|
+
const findUserOrganization = findUserOrganizationFactory({ pg });
|
|
12
|
+
return async function getUserOrganization({
|
|
13
|
+
organization_id,
|
|
14
|
+
user_id,
|
|
15
|
+
}: FindUserOrganizationLink) {
|
|
16
|
+
const link = await findUserOrganization({ organization_id, user_id });
|
|
17
|
+
if (isEmpty(link)) {
|
|
18
|
+
throw new LinkNotFoundError("Link not found");
|
|
19
|
+
}
|
|
20
|
+
return link;
|
|
21
|
+
};
|
|
22
|
+
}
|