Skip to content

Commit 7b14a25

Browse files
committed
chore(tsc): fix noPropertyAccessFromIndexSignature error
1 parent 175d6ff commit 7b14a25

File tree

7 files changed

+56
-20
lines changed

7 files changed

+56
-20
lines changed

src/config/env.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
// load variable from .env file, only used in local dev env
22
import "dotenv/config";
33

4+
declare global {
5+
namespace NodeJS {
6+
interface ProcessEnv {
7+
CONSIDER_ALL_EMAIL_DOMAINS_AS_FREE: "True" | "False";
8+
CONSIDER_ALL_EMAIL_DOMAINS_AS_NON_FREE: "True" | "False";
9+
DISABLE_SECURITY_RESPONSE_HEADERS: "True" | "False";
10+
DISPLAY_TEST_ENV_WARNING: "True" | "False";
11+
DO_NOT_AUTHENTICATE_BROWSER: "True" | "False";
12+
DO_NOT_CHECK_EMAIL_DELIVERABILITY: "True" | "False";
13+
DO_NOT_RATE_LIMIT: "True" | "False";
14+
DO_NOT_SEND_MAIL: "True" | "False";
15+
DO_NOT_USE_ANNUAIRE_EMAILS: "True" | "False";
16+
ENABLE_FIXED_ACR: "True" | "False";
17+
SECURE_COOKIES: "true" | "false";
18+
SYMMETRIC_ENCRYPTION_KEY: string;
19+
}
20+
}
21+
}
22+
423
export const {
524
NODE_ENV,
625
DEPLOY_ENV = "preview",
@@ -35,8 +54,7 @@ if (!process.env.SYMMETRIC_ENCRYPTION_KEY) {
3554
"The SYMMETRIC_ENCRYPTION_KEY environment variable should be 32 bytes long! Use crypto.randomBytes(32).toString('base64') to generate one.",
3655
);
3756
}
38-
export const SYMMETRIC_ENCRYPTION_KEY: string = process.env
39-
.SYMMETRIC_ENCRYPTION_KEY as string;
57+
export const SYMMETRIC_ENCRYPTION_KEY = process.env.SYMMETRIC_ENCRYPTION_KEY;
4058

4159
export const MONCOMPTEPRO_LABEL = "MonComptePro";
4260
export const MONCOMPTEPRO_IDENTIFIER = new URL(MONCOMPTEPRO_HOST).hostname;

src/config/oidc-provider-configuration.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { Request } from "express";
2-
import { Configuration } from "oidc-provider";
2+
import { Configuration, type UnknownObject } from "oidc-provider";
33
import { destroyAuthenticatedSession } from "../managers/session/authenticated";
44
import epochTime from "../services/epoch-time";
55
import { findAccount } from "../services/oidc-account-adapter";
66
import policy from "../services/oidc-policy";
77
import { renderWithEjsLayout } from "../services/renderer";
88

9+
//
10+
11+
export interface OIDCContextParams extends UnknownObject {
12+
scope: string;
13+
prompt: "select_organization" | "update_userinfo";
14+
}
15+
916
export const oidcProviderConfiguration = ({
1017
sessionTtlInSeconds = 14 * 24 * 60 * 60,
1118
shortTokenTtlInSeconds = 10 * 60,
@@ -85,6 +92,7 @@ export const oidcProviderConfiguration = ({
8592
if (!ctx.oidc.session || !ctx.oidc.client || !ctx.oidc.params) {
8693
return undefined;
8794
}
95+
const oidcContextParams = ctx.oidc.params as OIDCContextParams;
8896
const grantId = ctx.oidc.session.grantIdFor(ctx.oidc.client.clientId);
8997

9098
let grant;
@@ -111,7 +119,7 @@ export const oidcProviderConfiguration = ({
111119

112120
// event existing grant should be updated, as requested scopes might
113121
// be different
114-
grant.addOIDCScope(ctx.oidc.params.scope as string);
122+
grant.addOIDCScope(oidcContextParams.scope);
115123
await grant.save();
116124
return grant;
117125
},

src/controllers/user/official-contact-email-verification.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ export const postOfficialContactEmailVerificationMiddleware = async (
113113

114114
return next();
115115
} catch (error) {
116+
const { organization_id } = req.params;
116117
if (
117-
req.params?.organization_id &&
118+
organization_id &&
118119
(error instanceof InvalidTokenError || error instanceof ZodError)
119120
) {
120121
return res.redirect(
121-
`/users/official-contact-email-verification/${req.params.organization_id}?notification=invalid_verify_email_code`,
122+
`/users/official-contact-email-verification/${organization_id}?notification=invalid_verify_email_code`,
122123
);
123124
}
124125

src/managers/oidc-client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as Sentry from "@sentry/node";
22
import { isEmpty, isString } from "lodash-es";
33
import { KoaContextWithOIDC } from "oidc-provider";
44
import { NotFoundError } from "../config/errors";
5+
import type { OIDCContextParams } from "../config/oidc-provider-configuration";
56
import {
67
addConnection,
78
findByClientId,
@@ -25,7 +26,7 @@ export const recordNewConnection = async ({
2526
accountId: string;
2627
// tricky way to get the non exported Client type
2728
client: NonNullable<KoaContextWithOIDC["oidc"]["client"]>;
28-
params: KoaContextWithOIDC["oidc"]["params"];
29+
params: OIDCContextParams;
2930
}): Promise<Connection> => {
3031
const user_id = parseInt(accountId, 10);
3132

src/middlewares/connection-count.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Sentry from "@sentry/node";
22
import { NextFunction } from "express";
33
import { KoaContextWithOIDC } from "oidc-provider";
4+
import type { OIDCContextParams } from "../config/oidc-provider-configuration";
45
import { recordNewConnection } from "../managers/oidc-client";
56
import { logger } from "../services/log";
67

@@ -39,7 +40,7 @@ export const connectionCountMiddleware = async (
3940
await recordNewConnection({
4041
accountId: ctx.oidc.session.accountId,
4142
client: ctx.oidc.client,
42-
params: ctx.oidc.params,
43+
params: ctx.oidc.params as OIDCContextParams,
4344
});
4445
} else {
4546
// This is unexpected, we log it in sentry

src/routers/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const apiRouter = () => {
9191

9292
return res
9393
.status(statusCode)
94-
.json({ message: err.message || err.statusMessage });
94+
.json({ message: err.message || err["statusMessage"] });
9595
},
9696
);
9797

src/services/oidc-policy.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
import { interactionPolicy } from "oidc-provider";
1+
import { interactionPolicy, type InteractionResults } from "oidc-provider";
2+
import type { OIDCContextParams } from "../config/oidc-provider-configuration";
23
import { getSelectedOrganizationId } from "../repositories/redis/selected-organization";
34
import { mustReturnOneOrganizationInPayload } from "./must-return-one-organization-in-payload";
45

6+
//
7+
8+
interface OidcInteractionResults extends InteractionResults {
9+
select_organization?: boolean;
10+
update_userinfo?: boolean;
11+
}
12+
//
13+
514
const { Prompt, Check, base } = interactionPolicy;
615

716
const policy = base();
@@ -26,11 +35,9 @@ policy.add(
2635
) &&
2736
!selectedOrganizationId
2837
) {
29-
// @ts-ignore
3038
return Check.REQUEST_PROMPT;
3139
}
3240

33-
// @ts-ignore
3441
return Check.NO_NEED_TO_PROMPT;
3542
},
3643
),
@@ -47,15 +54,15 @@ policy.add(
4754
"interaction_required",
4855
async (ctx) => {
4956
const { oidc } = ctx;
57+
const oidcContextParams = ctx.oidc.params as OIDCContextParams;
58+
const oidcContextResult = oidc.result as OidcInteractionResults;
5059
if (
51-
ctx.params.prompt === "select_organization" &&
52-
!oidc.result?.select_organization
60+
oidcContextParams.prompt === "select_organization" &&
61+
!oidcContextResult?.select_organization
5362
) {
54-
// @ts-ignore
5563
return Check.REQUEST_PROMPT;
5664
}
5765

58-
// @ts-ignore
5966
return Check.NO_NEED_TO_PROMPT;
6067
},
6168
),
@@ -72,15 +79,15 @@ policy.add(
7279
"interaction_required",
7380
async (ctx) => {
7481
const { oidc } = ctx;
82+
const oidcContextParams = oidc.params as OIDCContextParams;
83+
const oidcContextResult = oidc.result as OidcInteractionResults;
7584
if (
76-
ctx.params.prompt === "update_userinfo" &&
77-
!oidc.result?.update_userinfo
85+
oidcContextParams.prompt === "update_userinfo" &&
86+
!oidcContextResult?.update_userinfo
7887
) {
79-
// @ts-ignore
8088
return Check.REQUEST_PROMPT;
8189
}
8290

83-
// @ts-ignore
8491
return Check.NO_NEED_TO_PROMPT;
8592
},
8693
),

0 commit comments

Comments
 (0)