Skip to content

Commit b89a2c7

Browse files
committed
Enabled strict null checks
1 parent 97ea662 commit b89a2c7

66 files changed

Lines changed: 213 additions & 213 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@churchapps/helpers": minor
3+
"@churchapps/apihelper": patch
4+
"@churchapps/apphelper": patch
5+
---
6+
7+
Enable full TypeScript strict mode across helpers, apihelper, and apphelper (tech-debt audit item 3). All three packages now extend a shared `tsconfig.base.json` that ships in the helpers package, so consuming apps can opt in via `"extends": "@churchapps/helpers/tsconfig.base.json"`. Fixes are type-level and behavior-preserving; notable declaration changes: `ApiHelper.onRequest`/`onError` are now optional, and several component props/state types widened to `| null` to reflect actual runtime values.

apihelper/src/auth/CustomAuthProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ export class CustomAuthProvider implements interfaces.AuthProvider {
1212
const authHeader = req.headers.authorization;
1313
if (authHeader) {
1414
const token = authHeader.split(" ")[1];
15-
if (!token) return null;
15+
if (!token) return null as unknown as Principal;
1616
const decoded = jwt.verify(token, EnvironmentBase.jwtSecret);
1717

1818
const result = decoded ? new Principal(typeof decoded === "object" && decoded !== null ? decoded as Record<string, unknown> : {}) : null;
1919
if (result) result.details.jwt = token;
20-
return result;
20+
return result as Principal;
2121
}
2222

23-
return null;
23+
return null as unknown as Principal;
2424
}
2525
}

apihelper/src/controllers/ErrorController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export class ErrorController extends CustomBaseController {
1616
this.logger.log(req.body[0].application, "info", e);
1717
}*/
1818
req.body.forEach(error => {
19-
let fullMessage = error.message;
19+
let fullMessage = error.message || "";
2020
if (error.additionalDetails !== undefined) fullMessage += "\n" + error.additionalDetails;
2121
// if (au !== null) fullMessage += "\nUser: " + au.id + " Church: " + au.churchId;
22-
this.logger.log(error.application, error.level, fullMessage);
22+
this.logger.log(error.application || "unknown", error.level || "error", fullMessage);
2323
});
2424
await this.logger.flush();
2525
return req.body;

apihelper/src/helpers/AwsHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class AwsHelper {
127127
Key: key
128128
});
129129
const response = await this.getClient().send(command);
130-
return await response.Body?.transformToString();
130+
return (await response.Body?.transformToString()) ?? null;
131131
} catch (error) {
132132
console.error("Error reading from S3:", error);
133133
return null;

apihelper/src/helpers/DB.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class DB {
77
// wraps in promise
88
static async getConnection() {
99
const promise: Promise<PoolConnection> = new Promise((resolve, reject) => {
10-
Pool.current.getConnection((ex: QueryError | null, conn: PoolConnection) => { if (ex) reject(ex); else resolve(conn); });
10+
Pool.current.getConnection((ex, conn) => { if (ex) reject(ex); else resolve(conn); });
1111
});
1212
const connection: PoolConnection = await promise;
1313
return connection;

apihelper/src/helpers/EmailHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class EmailHelper {
9191
await transporter.sendMail({ from, to, subject, html: body, replyTo });
9292
}
9393
}
94-
return null;
94+
return;
9595
} catch (err) {
9696
throw err;
9797
}

apihelper/src/helpers/EnvironmentBase.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export class EnvironmentBase {
5555
EnvironmentBase.jwtSecret = process.env.JWT_SECRET || await AwsHelper.readParameter(`/${appEnv}/jwtSecret`);
5656
EnvironmentBase.mailSystem = jsonData.mailSystem as string;
5757
EnvironmentBase.s3Bucket = jsonData.s3Bucket as string;
58-
EnvironmentBase.smtpHost = process.env.SMTP_HOST;
59-
EnvironmentBase.smtpPass = process.env.SMTP_PASS;
58+
EnvironmentBase.smtpHost = process.env.SMTP_HOST ?? "";
59+
EnvironmentBase.smtpPass = process.env.SMTP_PASS ?? "";
6060
EnvironmentBase.smtpSecure = process.env.SMTP_SECURE === "true";
61-
EnvironmentBase.smtpUser = process.env.SMTP_USER;
61+
EnvironmentBase.smtpUser = process.env.SMTP_USER ?? "";
6262
}
6363

6464
}

apihelper/src/helpers/LoggingHelper.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import WinstonCloudWatch from "winston-cloudwatch";
44
import { EnvironmentBase } from "./EnvironmentBase.js";
55

66
export class LoggingHelper {
7-
private static _current: LoggingHelper = null;
7+
private static _current: LoggingHelper | null = null;
88
public static getCurrent = () => {
9-
if (LoggingHelper._current === null) {
10-
LoggingHelper._current = new LoggingHelper();
11-
LoggingHelper._current.init("API");
9+
if (!LoggingHelper._current) {
10+
const current = new LoggingHelper();
11+
current.init("API");
12+
LoggingHelper._current = current;
1213
}
1314
return LoggingHelper._current;
1415
};
1516

16-
private _logger: winston.Logger = null;
17-
private wc: WinstonCloudWatch;
17+
private _logger: winston.Logger | null = null;
18+
private wc?: WinstonCloudWatch;
1819
private pendingMessages = false;
1920
private logGroupName = EnvironmentBase.appName + "_" + EnvironmentBase.appEnv;
2021
private logDestination = "console";
@@ -26,14 +27,14 @@ export class LoggingHelper {
2627
public info(msg: string | object) {
2728
if (this._logger === null) this.init("API");
2829
this.pendingMessages = true;
29-
this._logger.info(msg);
30+
this._logger!.info(msg);
3031
}
3132

3233
public log(streamName: string, level: string, msg: string | object) {
3334
if (this._logger === null) this.init(streamName);
3435
this.pendingMessages = true;
35-
if (level === "info") this._logger.info(msg);
36-
else this._logger.error(msg);
36+
if (level === "info") this._logger!.info(msg);
37+
else this._logger!.error(msg);
3738
}
3839

3940
private init(streamName: string) {

apihelper/src/helpers/Pool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class Pool {
2626
if ((field.type === "BIT") && (field.length === 1)) {
2727
try {
2828
const bytes = field.buffer();
29-
return (bytes[0] === 1);
29+
return (bytes?.[0] === 1);
3030
} catch { return false; }
3131
}
3232
return useDefaultTypeCasting();

apihelper/tsconfig.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
{
2+
"extends": "../helpers/tsconfig.base.json",
23
"compilerOptions": {
34
"module": "NodeNext",
45
"moduleResolution": "NodeNext",
5-
"esModuleInterop": true,
6-
"allowSyntheticDefaultImports": true,
76
"lib": ["ES2020", "DOM"],
87
"experimentalDecorators": true,
98
"emitDecoratorMetadata": true,
109
"target": "ES2020",
11-
"noImplicitAny": true,
1210
"sourceMap": true,
1311
"outDir": "dist",
1412
"baseUrl": ".",
15-
"strict": false,
1613
"declaration": true,
17-
"declarationMap": true,
18-
"skipLibCheck": true,
19-
"forceConsistentCasingInFileNames": true,
20-
"resolveJsonModule": true,
21-
"isolatedModules": true
14+
"declarationMap": true
2215
},
2316
"include": ["src/**/*"],
2417
"exclude": ["node_modules", "dist"]
25-
}
18+
}

0 commit comments

Comments
 (0)