@proconnect-gouv/proconnect.identite 10.0.0 → 10.0.2
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 +30 -0
- package/dist/connectors/index.d.ts +154 -0
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/index.js +60 -0
- 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/repositories/authenticator/create-authenticator.d.ts +6 -0
- package/dist/repositories/authenticator/create-authenticator.d.ts.map +1 -0
- package/dist/repositories/authenticator/create-authenticator.js +37 -0
- package/dist/repositories/authenticator/delete-authenticator.d.ts +3 -0
- package/dist/repositories/authenticator/delete-authenticator.d.ts.map +1 -0
- package/dist/repositories/authenticator/delete-authenticator.js +13 -0
- package/dist/repositories/authenticator/find-authenticator.d.ts +3 -0
- package/dist/repositories/authenticator/find-authenticator.d.ts.map +1 -0
- package/dist/repositories/authenticator/find-authenticator.js +14 -0
- package/dist/repositories/authenticator/get-authenticators-by-user-id.d.ts +3 -0
- package/dist/repositories/authenticator/get-authenticators-by-user-id.d.ts.map +1 -0
- package/dist/repositories/authenticator/get-authenticators-by-user-id.js +13 -0
- package/dist/repositories/authenticator/index.d.ts +6 -0
- package/dist/repositories/authenticator/index.d.ts.map +1 -0
- package/dist/repositories/authenticator/index.js +6 -0
- package/dist/repositories/authenticator/update-authenticator.d.ts +4 -0
- package/dist/repositories/authenticator/update-authenticator.d.ts.map +1 -0
- package/dist/repositories/authenticator/update-authenticator.js +13 -0
- package/dist/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.d.ts +3 -0
- package/dist/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.d.ts.map +1 -0
- package/dist/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.js +15 -0
- package/dist/repositories/email-deliverability-whitelist/index.d.ts +2 -0
- package/dist/repositories/email-deliverability-whitelist/index.d.ts.map +1 -0
- package/dist/repositories/email-deliverability-whitelist/index.js +2 -0
- package/dist/repositories/moderation/create-moderation.d.ts +22 -0
- package/dist/repositories/moderation/create-moderation.d.ts.map +1 -0
- package/dist/repositories/moderation/create-moderation.js +21 -0
- package/dist/repositories/moderation/delete-moderation.d.ts +3 -0
- package/dist/repositories/moderation/delete-moderation.d.ts.map +1 -0
- package/dist/repositories/moderation/delete-moderation.js +12 -0
- package/dist/repositories/moderation/find-moderation-by-id.d.ts +16 -0
- package/dist/repositories/moderation/find-moderation-by-id.d.ts.map +1 -0
- package/dist/repositories/moderation/find-moderation-by-id.js +13 -0
- package/dist/repositories/moderation/find-pending-moderation.d.ts +20 -0
- package/dist/repositories/moderation/find-pending-moderation.d.ts.map +1 -0
- package/dist/repositories/moderation/find-pending-moderation.js +16 -0
- package/dist/repositories/moderation/find-rejected-moderation.d.ts +20 -0
- package/dist/repositories/moderation/find-rejected-moderation.d.ts.map +1 -0
- package/dist/repositories/moderation/find-rejected-moderation.js +17 -0
- package/dist/repositories/moderation/get-moderation-by-id.d.ts +3 -0
- package/dist/repositories/moderation/get-moderation-by-id.d.ts.map +1 -0
- package/dist/repositories/moderation/get-moderation-by-id.js +15 -0
- package/dist/repositories/moderation/index.d.ts +8 -0
- package/dist/repositories/moderation/index.d.ts.map +1 -0
- package/dist/repositories/moderation/index.js +8 -0
- package/dist/repositories/moderation/reopen-moderation.d.ts +20 -0
- package/dist/repositories/moderation/reopen-moderation.d.ts.map +1 -0
- package/dist/repositories/moderation/reopen-moderation.js +17 -0
- package/dist/repositories/oidc-client/add-connection.d.ts +3 -0
- package/dist/repositories/oidc-client/add-connection.d.ts.map +1 -0
- package/dist/repositories/oidc-client/add-connection.js +22 -0
- package/dist/repositories/oidc-client/find-by-client-id.d.ts +3 -0
- package/dist/repositories/oidc-client/find-by-client-id.d.ts.map +1 -0
- package/dist/repositories/oidc-client/find-by-client-id.js +14 -0
- package/dist/repositories/oidc-client/index.d.ts +3 -0
- package/dist/repositories/oidc-client/index.d.ts.map +1 -0
- package/dist/repositories/oidc-client/index.js +3 -0
- package/dist/repositories/organization/delete-user-organization.d.ts +6 -0
- package/dist/repositories/organization/delete-user-organization.d.ts.map +1 -0
- package/dist/repositories/organization/delete-user-organization.js +10 -0
- package/dist/repositories/organization/find-by-siret.d.ts +3 -0
- package/dist/repositories/organization/find-by-siret.d.ts.map +1 -0
- package/dist/repositories/organization/find-by-siret.js +13 -0
- package/dist/repositories/organization/find-by-verified-email-domain.d.ts +6 -0
- package/dist/repositories/organization/find-by-verified-email-domain.d.ts.map +1 -0
- package/dist/repositories/organization/find-by-verified-email-domain.js +21 -0
- package/dist/repositories/organization/find-pending-by-user-id.d.ts +6 -0
- package/dist/repositories/organization/find-pending-by-user-id.d.ts.map +1 -0
- package/dist/repositories/organization/find-pending-by-user-id.js +18 -0
- package/dist/repositories/organization/get-user-organization-link.d.ts +15 -0
- package/dist/repositories/organization/get-user-organization-link.d.ts.map +1 -0
- package/dist/repositories/organization/get-user-organization-link.js +23 -0
- package/dist/repositories/organization/index.d.ts +5 -0
- package/dist/repositories/organization/index.d.ts.map +1 -1
- package/dist/repositories/organization/index.js +5 -0
- package/dist/repositories/user/delete-franceconnect-userinfo.d.ts +4 -0
- package/dist/repositories/user/delete-franceconnect-userinfo.d.ts.map +1 -0
- package/dist/repositories/user/delete-franceconnect-userinfo.js +10 -0
- package/dist/repositories/user/delete.d.ts +3 -0
- package/dist/repositories/user/delete.d.ts.map +1 -0
- package/dist/repositories/user/delete.js +11 -0
- package/dist/repositories/user/find-by-magic-link-token.d.ts +3 -0
- package/dist/repositories/user/find-by-magic-link-token.d.ts.map +1 -0
- package/dist/repositories/user/find-by-magic-link-token.js +12 -0
- package/dist/repositories/user/find-by-reset-password-token.d.ts +3 -0
- package/dist/repositories/user/find-by-reset-password-token.d.ts.map +1 -0
- package/dist/repositories/user/find-by-reset-password-token.js +12 -0
- package/dist/repositories/user/index.d.ts +3 -0
- package/dist/repositories/user/index.d.ts.map +1 -1
- package/dist/repositories/user/index.js +3 -0
- package/dist/services/organization/compute-service-public-info.d.ts.map +1 -1
- package/dist/services/organization/compute-service-public-info.js +7 -6
- package/dist/types/authenticator.d.ts +18 -0
- package/dist/types/authenticator.d.ts.map +1 -0
- package/dist/types/authenticator.js +2 -0
- package/dist/types/connection.d.ts +13 -0
- package/dist/types/connection.d.ts.map +1 -0
- package/dist/types/connection.js +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -0
- package/dist/types/oidc-client.d.ts +19 -0
- package/dist/types/oidc-client.d.ts.map +1 -0
- package/dist/types/oidc-client.js +2 -0
- package/package.json +3 -3
- package/src/connectors/index.ts +61 -0
- package/src/errors/index.ts +7 -0
- package/src/repositories/authenticator/create-authenticator.test.ts +44 -0
- package/src/repositories/authenticator/create-authenticator.ts +66 -0
- package/src/repositories/authenticator/delete-authenticator.test.ts +42 -0
- package/src/repositories/authenticator/delete-authenticator.ts +24 -0
- package/src/repositories/authenticator/find-authenticator.test.ts +42 -0
- package/src/repositories/authenticator/find-authenticator.ts +25 -0
- package/src/repositories/authenticator/get-authenticators-by-user-id.test.ts +45 -0
- package/src/repositories/authenticator/get-authenticators-by-user-id.ts +21 -0
- package/src/repositories/authenticator/index.ts +7 -0
- package/src/repositories/authenticator/update-authenticator.test.ts +41 -0
- package/src/repositories/authenticator/update-authenticator.ts +29 -0
- package/src/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.test.ts +45 -0
- package/src/repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.ts +24 -0
- package/src/repositories/email-deliverability-whitelist/index.ts +3 -0
- package/src/repositories/moderation/create-moderation.test.ts +43 -0
- package/src/repositories/moderation/create-moderation.ts +45 -0
- package/src/repositories/moderation/delete-moderation.test.ts +49 -0
- package/src/repositories/moderation/delete-moderation.ts +19 -0
- package/src/repositories/moderation/find-moderation-by-id.test.ts +49 -0
- package/src/repositories/moderation/find-moderation-by-id.ts +20 -0
- package/src/repositories/moderation/find-pending-moderation.test.ts +57 -0
- package/src/repositories/moderation/find-pending-moderation.ts +35 -0
- package/src/repositories/moderation/find-rejected-moderation.test.ts +57 -0
- package/src/repositories/moderation/find-rejected-moderation.ts +37 -0
- package/src/repositories/moderation/get-moderation-by-id.test.ts +51 -0
- package/src/repositories/moderation/get-moderation-by-id.ts +19 -0
- package/src/repositories/moderation/index.ts +9 -0
- package/src/repositories/moderation/reopen-moderation.test.ts +48 -0
- package/src/repositories/moderation/reopen-moderation.ts +36 -0
- package/src/repositories/oidc-client/add-connection.test.ts +43 -0
- package/src/repositories/oidc-client/add-connection.ts +36 -0
- package/src/repositories/oidc-client/find-by-client-id.test.ts +35 -0
- package/src/repositories/oidc-client/find-by-client-id.ts +22 -0
- package/src/repositories/oidc-client/index.ts +4 -0
- package/src/repositories/organization/delete-user-organization.test.ts +55 -0
- package/src/repositories/organization/delete-user-organization.ts +25 -0
- package/src/repositories/organization/find-by-siret.test.ts +35 -0
- package/src/repositories/organization/find-by-siret.ts +21 -0
- package/src/repositories/organization/find-by-verified-email-domain.test.ts +46 -0
- package/src/repositories/organization/find-by-verified-email-domain.ts +33 -0
- package/src/repositories/organization/find-pending-by-user-id.test.ts +51 -0
- package/src/repositories/organization/find-pending-by-user-id.ts +27 -0
- package/src/repositories/organization/get-user-organization-link.test.ts +52 -0
- package/src/repositories/organization/get-user-organization-link.ts +34 -0
- package/src/repositories/organization/index.ts +5 -0
- package/src/repositories/user/delete-franceconnect-userinfo.test.ts +47 -0
- package/src/repositories/user/delete-franceconnect-userinfo.ts +21 -0
- package/src/repositories/user/delete.test.ts +35 -0
- package/src/repositories/user/delete.ts +19 -0
- package/src/repositories/user/find-by-magic-link-token.test.ts +35 -0
- package/src/repositories/user/find-by-magic-link-token.ts +20 -0
- package/src/repositories/user/find-by-reset-password-token.test.ts +37 -0
- package/src/repositories/user/find-by-reset-password-token.ts +20 -0
- package/src/repositories/user/index.ts +3 -0
- package/src/services/organization/compute-service-public-info.ts +8 -7
- package/src/types/authenticator.ts +27 -0
- package/src/types/connection.ts +15 -0
- package/src/types/index.ts +3 -0
- package/src/types/oidc-client.ts +20 -0
- package/tsconfig.lib.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/user/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,oCAAoC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/repositories/user/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,oCAAoC,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
//
|
|
2
2
|
export * from "./create.js";
|
|
3
|
+
export * from "./delete.js";
|
|
3
4
|
export * from "./find-by-email.js";
|
|
4
5
|
export * from "./find-by-id.js";
|
|
6
|
+
export * from "./find-by-magic-link-token.js";
|
|
7
|
+
export * from "./find-by-reset-password-token.js";
|
|
5
8
|
export * from "./get-by-id.js";
|
|
6
9
|
export * from "./get-franceconnect-user-info.js";
|
|
7
10
|
export * from "./update-user-organization-link.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compute-service-public-info.d.ts","sourceRoot":"","sources":["../../../src/services/organization/compute-service-public-info.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"compute-service-public-info.d.ts","sourceRoot":"","sources":["../../../src/services/organization/compute-service-public-info.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAO/C,eAAO,MAAM,wBAAwB,GAAI,mEAItC,IAAI,CACL,YAAY,EACZ,4BAA4B,GAAG,2BAA2B,GAAG,OAAO,CACrE,KAAG;IACF,eAAe,EAAE,OAAO,CAAC;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,4BAA4B,CAAC,EAAE,OAAO,CAAC;CA8CxC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//
|
|
2
|
-
import { ADMINISTRATION_BLACKLIST,
|
|
2
|
+
import { ADMINISTRATION_BLACKLIST, ADMINISTRATION_WHITELIST, ADMINISTRATIONS, } from "@proconnect-gouv/proconnect.annuaire_entreprises";
|
|
3
3
|
export const computeServicePublicInfo = ({ cached_categorie_juridique, siret, cached_etat_administratif, }) => {
|
|
4
4
|
// Check if nature juridique is undefined/null
|
|
5
5
|
if (!cached_categorie_juridique) {
|
|
@@ -14,12 +14,13 @@ export const computeServicePublicInfo = ({ cached_categorie_juridique, siret, ca
|
|
|
14
14
|
if (cached_etat_administratif === "C") {
|
|
15
15
|
return { isServicePublic: false };
|
|
16
16
|
}
|
|
17
|
-
if (ADMINISTRATION_ETAT_WHITELIST.includes(siren)) {
|
|
18
|
-
return { isServicePublic: true, isAdministrationEtat: true };
|
|
19
|
-
}
|
|
20
17
|
// Check if entity is in whitelist (takes priority)
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const administrationInWhitelist = ADMINISTRATION_WHITELIST.find((ADMINISTRATION) => ADMINISTRATION.siren === siren);
|
|
19
|
+
if (administrationInWhitelist) {
|
|
20
|
+
return {
|
|
21
|
+
isServicePublic: true,
|
|
22
|
+
isAdministrationEtat: administrationInWhitelist.isAdministrationEtat,
|
|
23
|
+
};
|
|
23
24
|
}
|
|
24
25
|
const ADMINISTRATION = ADMINISTRATIONS.find((ADMINISTRATION) => cached_categorie_juridique === `${ADMINISTRATION.codeJuridique}`);
|
|
25
26
|
if (!ADMINISTRATION) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AuthenticatorTransportFuture, Base64URLString, CredentialDeviceType } from "@simplewebauthn/server";
|
|
2
|
+
export interface BaseAuthenticator {
|
|
3
|
+
credential_id: Base64URLString;
|
|
4
|
+
credential_public_key: Uint8Array;
|
|
5
|
+
counter: number;
|
|
6
|
+
credential_device_type: CredentialDeviceType;
|
|
7
|
+
credential_backed_up: boolean;
|
|
8
|
+
transports?: AuthenticatorTransportFuture[];
|
|
9
|
+
display_name: string | null;
|
|
10
|
+
last_used_at: Date | null;
|
|
11
|
+
usage_count: number;
|
|
12
|
+
user_verified: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface Authenticator extends BaseAuthenticator {
|
|
15
|
+
user_id: number;
|
|
16
|
+
created_at: Date;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=authenticator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticator.d.ts","sourceRoot":"","sources":["../../src/types/authenticator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,EACf,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAIhC,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,eAAe,CAAC;IAC/B,qBAAqB,EAAE,UAAU,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB,EAAE,oBAAoB,CAAC;IAC7C,oBAAoB,EAAE,OAAO,CAAC;IAC9B,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;IAC5C,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,IAAI,CAAC;CAClB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface BaseConnection {
|
|
2
|
+
user_id: number;
|
|
3
|
+
oidc_client_id: number;
|
|
4
|
+
organization_id: number | null;
|
|
5
|
+
sp_name: string | null;
|
|
6
|
+
user_ip_address: string | null;
|
|
7
|
+
}
|
|
8
|
+
export interface Connection extends BaseConnection {
|
|
9
|
+
id: number;
|
|
10
|
+
created_at: Date;
|
|
11
|
+
updated_at: Date;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/types/connection.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,UAAW,SAAQ,cAAc;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
export * from "./authenticator.js";
|
|
1
2
|
export * from "./claims.js";
|
|
3
|
+
export * from "./connection.js";
|
|
2
4
|
export * from "./contexts.js";
|
|
3
5
|
export * from "./email-domain.js";
|
|
4
6
|
export * from "./franceconnect.js";
|
|
5
7
|
export * from "./identity-vector.js";
|
|
6
8
|
export * from "./moderation.js";
|
|
9
|
+
export * from "./oidc-client.js";
|
|
7
10
|
export * from "./organization-info.js";
|
|
8
11
|
export * from "./organization.js";
|
|
9
12
|
export * from "./user-organization-link.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,WAAW,CAAC"}
|
package/dist/types/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
//
|
|
2
|
+
export * from "./authenticator.js";
|
|
2
3
|
export * from "./claims.js";
|
|
4
|
+
export * from "./connection.js";
|
|
3
5
|
export * from "./contexts.js";
|
|
4
6
|
export * from "./email-domain.js";
|
|
5
7
|
export * from "./franceconnect.js";
|
|
6
8
|
export * from "./identity-vector.js";
|
|
7
9
|
export * from "./moderation.js";
|
|
10
|
+
export * from "./oidc-client.js";
|
|
8
11
|
export * from "./organization-info.js";
|
|
9
12
|
export * from "./organization.js";
|
|
10
13
|
export * from "./user-organization-link.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface OidcClient {
|
|
2
|
+
id: number;
|
|
3
|
+
client_description: string | null;
|
|
4
|
+
created_at: Date;
|
|
5
|
+
updated_at: Date;
|
|
6
|
+
client_name: string;
|
|
7
|
+
client_id: string;
|
|
8
|
+
client_secret: string;
|
|
9
|
+
redirect_uris: string[];
|
|
10
|
+
post_logout_redirect_uris: string[];
|
|
11
|
+
scope: string;
|
|
12
|
+
client_uri: string | null;
|
|
13
|
+
userinfo_signed_response_alg: string | null;
|
|
14
|
+
id_token_signed_response_alg: string | null;
|
|
15
|
+
authorization_signed_response_alg: string | null;
|
|
16
|
+
introspection_signed_response_alg: string | null;
|
|
17
|
+
is_proconnect_federation: boolean;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=oidc-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-client.d.ts","sourceRoot":"","sources":["../../src/types/oidc-client.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,yBAAyB,EAAE,MAAM,EAAE,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,4BAA4B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,4BAA4B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,iCAAiC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjD,iCAAiC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjD,wBAAwB,EAAE,OAAO,CAAC;CACnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.identite",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.2",
|
|
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.2",
|
|
55
55
|
"@proconnect-gouv/proconnect.api_entreprise": "^2.2.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.2",
|
|
69
69
|
"@proconnect-gouv/proconnect.api_entreprise": "^2.2.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
|
@@ -4,15 +4,41 @@ import type { ApiEntrepriseClient } from "@proconnect-gouv/proconnect.api_entrep
|
|
|
4
4
|
import type { ApiInseeClient } from "@proconnect-gouv/proconnect.insee/api";
|
|
5
5
|
import type { ApiRegistreNationalEntreprisesClient } from "@proconnect-gouv/proconnect.registre_national_entreprises/api";
|
|
6
6
|
import { type Pool } from "pg";
|
|
7
|
+
import { createAuthenticatorFactory } from "../repositories/authenticator/create-authenticator.js";
|
|
8
|
+
import { deleteAuthenticatorFactory } from "../repositories/authenticator/delete-authenticator.js";
|
|
9
|
+
import { findAuthenticatorFactory } from "../repositories/authenticator/find-authenticator.js";
|
|
10
|
+
import { getAuthenticatorsByUserIdFactory } from "../repositories/authenticator/get-authenticators-by-user-id.js";
|
|
11
|
+
import { updateAuthenticatorFactory } from "../repositories/authenticator/update-authenticator.js";
|
|
12
|
+
import { findEmailInDeliverabilityWhiteListFactory } from "../repositories/email-deliverability-whitelist/find-email-in-deliverability-white-list.js";
|
|
7
13
|
import { addDomainFactory } from "../repositories/email-domain/add-domain.js";
|
|
8
14
|
import { deleteEmailDomainsByVerificationTypesFactory } from "../repositories/email-domain/delete-email-domains-by-verification-types.js";
|
|
9
15
|
import { findEmailDomainsByOrganizationIdFactory } from "../repositories/email-domain/find-email-domains-by-organization-id.js";
|
|
16
|
+
import { createModerationFactory } from "../repositories/moderation/create-moderation.js";
|
|
17
|
+
import { deleteModerationFactory } from "../repositories/moderation/delete-moderation.js";
|
|
18
|
+
import { findModerationByIdFactory } from "../repositories/moderation/find-moderation-by-id.js";
|
|
19
|
+
import { findPendingModerationFactory } from "../repositories/moderation/find-pending-moderation.js";
|
|
20
|
+
import { findRejectedModerationFactory } from "../repositories/moderation/find-rejected-moderation.js";
|
|
21
|
+
import { getModerationByIdFactory } from "../repositories/moderation/get-moderation-by-id.js";
|
|
22
|
+
import { reopenModerationFactory } from "../repositories/moderation/reopen-moderation.js";
|
|
23
|
+
import { addConnectionFactory } from "../repositories/oidc-client/add-connection.js";
|
|
24
|
+
import { findByClientIdFactory } from "../repositories/oidc-client/find-by-client-id.js";
|
|
25
|
+
import { deleteUserOrganizationFactory } from "../repositories/organization/delete-user-organization.js";
|
|
10
26
|
import { findByIdFactory as findOrganizationByIdFactory } from "../repositories/organization/find-by-id.js";
|
|
27
|
+
import { findBySiretFactory } from "../repositories/organization/find-by-siret.js";
|
|
11
28
|
import { findByUserIdFactory } from "../repositories/organization/find-by-user-id.js";
|
|
29
|
+
import { findByVerifiedEmailDomainFactory } from "../repositories/organization/find-by-verified-email-domain.js";
|
|
30
|
+
import { findPendingByUserIdFactory } from "../repositories/organization/find-pending-by-user-id.js";
|
|
31
|
+
import { getUserOrganizationLinkFactory } from "../repositories/organization/get-user-organization-link.js";
|
|
12
32
|
import { getUsersByOrganizationFactory } from "../repositories/organization/get-users-by-organization.js";
|
|
33
|
+
import { linkUserToOrganizationFactory } from "../repositories/organization/link-user-to-organization.js";
|
|
34
|
+
import { upsertFactory } from "../repositories/organization/upsert.js";
|
|
13
35
|
import { createUserFactory } from "../repositories/user/create.js";
|
|
36
|
+
import { deleteFranceConnectUserInfoFactory } from "../repositories/user/delete-franceconnect-userinfo.js";
|
|
37
|
+
import { deleteUserFactory } from "../repositories/user/delete.js";
|
|
14
38
|
import { findByEmailFactory } from "../repositories/user/find-by-email.js";
|
|
15
39
|
import { findByIdFactory as findUserByIdFactory } from "../repositories/user/find-by-id.js";
|
|
40
|
+
import { findByMagicLinkTokenFactory } from "../repositories/user/find-by-magic-link-token.js";
|
|
41
|
+
import { findByResetPasswordTokenFactory } from "../repositories/user/find-by-reset-password-token.js";
|
|
16
42
|
import { getByIdFactory } from "../repositories/user/get-by-id.js";
|
|
17
43
|
import { getFranceConnectUserInfoFactory } from "../repositories/user/get-franceconnect-user-info.js";
|
|
18
44
|
import { updateUserOrganizationLinkFactory } from "../repositories/user/update-user-organization-link.js";
|
|
@@ -39,6 +65,17 @@ export function createContext({
|
|
|
39
65
|
rne: api_registre_national_entreprises_client,
|
|
40
66
|
},
|
|
41
67
|
repository: {
|
|
68
|
+
authenticators: {
|
|
69
|
+
createAuthenticator: createAuthenticatorFactory({ pg }),
|
|
70
|
+
deleteAuthenticator: deleteAuthenticatorFactory({ pg }),
|
|
71
|
+
findAuthenticator: findAuthenticatorFactory({ pg }),
|
|
72
|
+
getAuthenticatorsByUserId: getAuthenticatorsByUserIdFactory({ pg }),
|
|
73
|
+
updateAuthenticator: updateAuthenticatorFactory({ pg }),
|
|
74
|
+
},
|
|
75
|
+
email_deliverability_whitelist: {
|
|
76
|
+
findEmailInDeliverabilityWhiteList:
|
|
77
|
+
findEmailInDeliverabilityWhiteListFactory({ pg }),
|
|
78
|
+
},
|
|
42
79
|
email_domains: {
|
|
43
80
|
addDomain: addDomainFactory({ pg }),
|
|
44
81
|
deleteEmailDomainsByVerificationTypes:
|
|
@@ -46,18 +83,42 @@ export function createContext({
|
|
|
46
83
|
findEmailDomainsByOrganizationId:
|
|
47
84
|
findEmailDomainsByOrganizationIdFactory({ pg }),
|
|
48
85
|
},
|
|
86
|
+
moderations: {
|
|
87
|
+
create: createModerationFactory({ pg }),
|
|
88
|
+
delete: deleteModerationFactory({ pg }),
|
|
89
|
+
findById: findModerationByIdFactory({ pg }),
|
|
90
|
+
findPending: findPendingModerationFactory({ pg }),
|
|
91
|
+
findRejected: findRejectedModerationFactory({ pg }),
|
|
92
|
+
getById: getModerationByIdFactory({ pg }),
|
|
93
|
+
reopen: reopenModerationFactory({ pg }),
|
|
94
|
+
},
|
|
95
|
+
oidc_clients: {
|
|
96
|
+
addConnection: addConnectionFactory({ pg }),
|
|
97
|
+
findByClientId: findByClientIdFactory({ pg }),
|
|
98
|
+
},
|
|
49
99
|
organizations: {
|
|
100
|
+
deleteUserOrganization: deleteUserOrganizationFactory({ pg }),
|
|
50
101
|
findById: findOrganizationByIdFactory({ pg }),
|
|
102
|
+
findBySiret: findBySiretFactory({ pg }),
|
|
51
103
|
findByUserId: findByUserIdFactory({ pg }),
|
|
104
|
+
findByVerifiedEmailDomain: findByVerifiedEmailDomainFactory({ pg }),
|
|
105
|
+
findPendingByUserId: findPendingByUserIdFactory({ pg }),
|
|
106
|
+
getUserOrganizationLink: getUserOrganizationLinkFactory({ pg }),
|
|
52
107
|
getUsers: getUsersByOrganizationFactory({ pg }),
|
|
108
|
+
linkUserToOrganization: linkUserToOrganizationFactory({ pg }),
|
|
109
|
+
upsert: upsertFactory({ pg }),
|
|
53
110
|
},
|
|
54
111
|
users_organizations: {
|
|
55
112
|
update: updateUserOrganizationLinkFactory({ pg }),
|
|
56
113
|
},
|
|
57
114
|
users: {
|
|
58
115
|
create: createUserFactory({ pg }),
|
|
116
|
+
delete: deleteUserFactory({ pg }),
|
|
117
|
+
deleteFranceConnectUserInfo: deleteFranceConnectUserInfoFactory({ pg }),
|
|
59
118
|
findByEmail: findByEmailFactory({ pg }),
|
|
60
119
|
findById: findUserByIdFactory({ pg }),
|
|
120
|
+
findByMagicLinkToken: findByMagicLinkTokenFactory({ pg }),
|
|
121
|
+
findByResetPasswordToken: findByResetPasswordTokenFactory({ pg }),
|
|
61
122
|
getById: getByIdFactory({ pg }),
|
|
62
123
|
getFranceConnectUserInfo: getFranceConnectUserInfoFactory({ pg }),
|
|
63
124
|
update: updateUserFactory({ pg }),
|
package/src/errors/index.ts
CHANGED
|
@@ -7,6 +7,13 @@ export class InvalidSiretError extends Error {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export class ModerationNotFoundError extends Error {
|
|
11
|
+
constructor(message?: string, options?: ErrorOptions) {
|
|
12
|
+
super(message, options);
|
|
13
|
+
this.name = "ModerationNotFoundError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
export class NotFoundError extends Error {
|
|
11
18
|
constructor(message?: string, options?: ErrorOptions) {
|
|
12
19
|
super(message, options);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { createAuthenticatorFactory } from "./create-authenticator.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const createAuthenticator = createAuthenticatorFactory({ pg: pg as any });
|
|
11
|
+
|
|
12
|
+
suite("createAuthenticatorFactory", () => {
|
|
13
|
+
before(migrate);
|
|
14
|
+
beforeEach(emptyDatabase);
|
|
15
|
+
|
|
16
|
+
test("should insert and return the authenticator", async () => {
|
|
17
|
+
await pg.sql`
|
|
18
|
+
INSERT INTO users
|
|
19
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
20
|
+
VALUES
|
|
21
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
22
|
+
;
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
const result = await createAuthenticator({
|
|
26
|
+
user_id: 1,
|
|
27
|
+
authenticator: {
|
|
28
|
+
credential_id: "CRED1",
|
|
29
|
+
credential_public_key: new Uint8Array([0]),
|
|
30
|
+
counter: 0,
|
|
31
|
+
credential_device_type: "singleDevice",
|
|
32
|
+
credential_backed_up: false,
|
|
33
|
+
transports: ["usb"],
|
|
34
|
+
display_name: "Yardrean's Blade",
|
|
35
|
+
last_used_at: null,
|
|
36
|
+
usage_count: 0,
|
|
37
|
+
user_verified: true,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
assert.equal(result.credential_id, "CRED1");
|
|
42
|
+
assert.equal(result.user_id, 1);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
Authenticator,
|
|
5
|
+
BaseAuthenticator,
|
|
6
|
+
DatabaseContext,
|
|
7
|
+
} from "#src/types";
|
|
8
|
+
import { type QueryResult } from "pg";
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
export function createAuthenticatorFactory({ pg }: DatabaseContext) {
|
|
13
|
+
return async function createAuthenticator({
|
|
14
|
+
user_id,
|
|
15
|
+
authenticator: {
|
|
16
|
+
credential_id,
|
|
17
|
+
credential_public_key,
|
|
18
|
+
counter,
|
|
19
|
+
credential_device_type,
|
|
20
|
+
credential_backed_up,
|
|
21
|
+
transports,
|
|
22
|
+
display_name,
|
|
23
|
+
last_used_at,
|
|
24
|
+
usage_count,
|
|
25
|
+
user_verified,
|
|
26
|
+
},
|
|
27
|
+
}: {
|
|
28
|
+
user_id: number;
|
|
29
|
+
authenticator: BaseAuthenticator;
|
|
30
|
+
}) {
|
|
31
|
+
const { rows }: QueryResult<Authenticator> = await pg.query(
|
|
32
|
+
`
|
|
33
|
+
INSERT INTO authenticators
|
|
34
|
+
(user_id,
|
|
35
|
+
credential_id,
|
|
36
|
+
credential_public_key,
|
|
37
|
+
counter,
|
|
38
|
+
credential_device_type,
|
|
39
|
+
credential_backed_up,
|
|
40
|
+
transports,
|
|
41
|
+
display_name,
|
|
42
|
+
created_at,
|
|
43
|
+
last_used_at,
|
|
44
|
+
usage_count,
|
|
45
|
+
user_verified)
|
|
46
|
+
VALUES
|
|
47
|
+
($1, $2, $3, $4, $5, $6, $7, $8, NOW(), $9, $10, $11)
|
|
48
|
+
RETURNING *;`,
|
|
49
|
+
[
|
|
50
|
+
user_id,
|
|
51
|
+
credential_id,
|
|
52
|
+
credential_public_key,
|
|
53
|
+
counter,
|
|
54
|
+
credential_device_type,
|
|
55
|
+
credential_backed_up,
|
|
56
|
+
transports,
|
|
57
|
+
display_name,
|
|
58
|
+
last_used_at,
|
|
59
|
+
usage_count,
|
|
60
|
+
user_verified,
|
|
61
|
+
],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return rows.shift()!;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { deleteAuthenticatorFactory } from "./delete-authenticator.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const deleteAuthenticator = deleteAuthenticatorFactory({ pg: pg as any });
|
|
11
|
+
|
|
12
|
+
suite("deleteAuthenticatorFactory", () => {
|
|
13
|
+
before(migrate);
|
|
14
|
+
beforeEach(emptyDatabase);
|
|
15
|
+
|
|
16
|
+
test("should return true when the authenticator exists", async () => {
|
|
17
|
+
await pg.sql`
|
|
18
|
+
INSERT INTO users
|
|
19
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
20
|
+
VALUES
|
|
21
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
22
|
+
;
|
|
23
|
+
`;
|
|
24
|
+
await pg.sql`
|
|
25
|
+
INSERT INTO authenticators
|
|
26
|
+
(credential_id, credential_public_key, counter, credential_backed_up, user_id, usage_count, user_verified)
|
|
27
|
+
VALUES
|
|
28
|
+
('CRED1', '\\x00', 0, false, 1, 0, true)
|
|
29
|
+
;
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
const result = await deleteAuthenticator(1, "CRED1");
|
|
33
|
+
|
|
34
|
+
assert.equal(result, true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("should return false when the authenticator does not exist", async () => {
|
|
38
|
+
const result = await deleteAuthenticator(1, "absent");
|
|
39
|
+
|
|
40
|
+
assert.equal(result, false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { DatabaseContext } from "#src/types";
|
|
4
|
+
import { type QueryResult } from "pg";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export function deleteAuthenticatorFactory({ pg }: DatabaseContext) {
|
|
9
|
+
return async function deleteAuthenticator(
|
|
10
|
+
user_id: number,
|
|
11
|
+
credential_id: string,
|
|
12
|
+
) {
|
|
13
|
+
const { rowCount, affectedRows } = (await pg.query(
|
|
14
|
+
`
|
|
15
|
+
DELETE FROM authenticators
|
|
16
|
+
WHERE user_id = $1
|
|
17
|
+
and credential_id = $2
|
|
18
|
+
RETURNING *`,
|
|
19
|
+
[user_id, credential_id],
|
|
20
|
+
)) as QueryResult & { affectedRows?: number };
|
|
21
|
+
|
|
22
|
+
return (affectedRows ?? rowCount ?? 0) > 0;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { findAuthenticatorFactory } from "./find-authenticator.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const findAuthenticator = findAuthenticatorFactory({ pg: pg as any });
|
|
11
|
+
|
|
12
|
+
suite("findAuthenticatorFactory", () => {
|
|
13
|
+
before(migrate);
|
|
14
|
+
beforeEach(emptyDatabase);
|
|
15
|
+
|
|
16
|
+
test("should return undefined when the authenticator does not exist", async () => {
|
|
17
|
+
const authenticator = await findAuthenticator(1, "absent");
|
|
18
|
+
|
|
19
|
+
assert.equal(authenticator, undefined);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("should return the authenticator when it exists", async () => {
|
|
23
|
+
await pg.sql`
|
|
24
|
+
INSERT INTO users
|
|
25
|
+
(id, email, created_at, updated_at, given_name, family_name, phone_number, job)
|
|
26
|
+
VALUES
|
|
27
|
+
(1, 'lion.eljonson@darkangels.world', '4444-04-04', '4444-04-04', 'lion', 'el''jonson', 'i', 'primarque')
|
|
28
|
+
;
|
|
29
|
+
`;
|
|
30
|
+
await pg.sql`
|
|
31
|
+
INSERT INTO authenticators
|
|
32
|
+
(credential_id, credential_public_key, counter, credential_backed_up, user_id, usage_count, user_verified)
|
|
33
|
+
VALUES
|
|
34
|
+
('CRED1', '\\x00', 0, false, 1, 0, true)
|
|
35
|
+
;
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
const authenticator = await findAuthenticator(1, "CRED1");
|
|
39
|
+
|
|
40
|
+
assert.equal(authenticator?.credential_id, "CRED1");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { Authenticator, DatabaseContext } from "#src/types";
|
|
4
|
+
import { type QueryResult } from "pg";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export function findAuthenticatorFactory({ pg }: DatabaseContext) {
|
|
9
|
+
return async function findAuthenticator(
|
|
10
|
+
user_id: number,
|
|
11
|
+
serialized_credential_id: string,
|
|
12
|
+
) {
|
|
13
|
+
const { rows }: QueryResult<Authenticator> = await pg.query(
|
|
14
|
+
`
|
|
15
|
+
SELECT *
|
|
16
|
+
FROM authenticators
|
|
17
|
+
WHERE user_id = $1
|
|
18
|
+
and credential_id = $2
|
|
19
|
+
`,
|
|
20
|
+
[user_id, serialized_credential_id],
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return rows.shift();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { emptyDatabase, migrate, pg } from "#testing";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { before, beforeEach, suite, test } from "node:test";
|
|
6
|
+
import { getAuthenticatorsByUserIdFactory } from "./get-authenticators-by-user-id.js";
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
const getAuthenticatorsByUserId = getAuthenticatorsByUserIdFactory({
|
|
11
|
+
pg: pg as any,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
suite("getAuthenticatorsByUserIdFactory", () => {
|
|
15
|
+
before(migrate);
|
|
16
|
+
beforeEach(emptyDatabase);
|
|
17
|
+
|
|
18
|
+
test("should return empty array when user has no authenticators", async () => {
|
|
19
|
+
const authenticators = await getAuthenticatorsByUserId(1);
|
|
20
|
+
|
|
21
|
+
assert.deepEqual(authenticators, []);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("should return authenticators for a user", async () => {
|
|
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 authenticators
|
|
34
|
+
(credential_id, credential_public_key, counter, credential_backed_up, user_id, usage_count, user_verified)
|
|
35
|
+
VALUES
|
|
36
|
+
('CRED1', '\\x00', 0, false, 1, 0, true)
|
|
37
|
+
;
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const authenticators = await getAuthenticatorsByUserId(1);
|
|
41
|
+
|
|
42
|
+
assert.equal(authenticators.length, 1);
|
|
43
|
+
assert.equal(authenticators[0]?.credential_id, "CRED1");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { Authenticator, DatabaseContext } from "#src/types";
|
|
4
|
+
import { type QueryResult } from "pg";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export function getAuthenticatorsByUserIdFactory({ pg }: DatabaseContext) {
|
|
9
|
+
return async function getAuthenticatorsByUserId(user_id: number) {
|
|
10
|
+
const { rows }: QueryResult<Authenticator> = await pg.query(
|
|
11
|
+
`
|
|
12
|
+
SELECT *
|
|
13
|
+
FROM authenticators
|
|
14
|
+
WHERE user_id = $1
|
|
15
|
+
`,
|
|
16
|
+
[user_id],
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return rows;
|
|
20
|
+
};
|
|
21
|
+
}
|