diff --git a/src/back/collections/password-reset-intents.test.ts b/src/back/collections/password-reset-intents.test.ts index 772ba8f..2465963 100644 --- a/src/back/collections/password-reset-intents.test.ts +++ b/src/back/collections/password-reset-intents.test.ts @@ -86,7 +86,7 @@ describe("password-reset-intents", function () { (message) => message.recipients[0] == "" ); assert.equal(messages.length, 1); - assert.equal(messages[0].recipients.length, 1); - assert.equal(messages[0].recipients[0], ""); + assert.equal(messages[0]?.recipients.length, 1); + assert.equal(messages[0]?.recipients[0], ""); })); }); diff --git a/src/back/collections/user-roles.ts b/src/back/collections/user-roles.ts index 61a513e..4a67080 100644 --- a/src/back/collections/user-roles.ts +++ b/src/back/collections/user-roles.ts @@ -23,6 +23,9 @@ export default class UserRoles extends Collection { await super.init(app, collection_name); app.on("started", async () => { const roles = app.collections["user-roles"]; + if (!roles) { + throw new Error("roles undefined"); + } for (const action of ["create", "delete"]) { const policy = roles.getPolicy(action); if (policy instanceof Policies.Public) { diff --git a/src/back/collections/users.ts b/src/back/collections/users.ts index c3452ac..f111ade 100644 --- a/src/back/collections/users.ts +++ b/src/back/collections/users.ts @@ -42,6 +42,9 @@ export default class Users extends Collections.users { } public static async getRoles(ctx: Context) { + if (!ctx.app.collections["user-roles"]) { + throw new Error("user-roles undefined"); + } const rolesEntries = await ctx.app.collections["user-roles"] .list(ctx) .filter({ user: ctx.user_id || "" }) diff --git a/src/back/email-templates/password-reset.ts b/src/back/email-templates/password-reset.ts index 61aacb3..8df9c52 100644 --- a/src/back/email-templates/password-reset.ts +++ b/src/back/email-templates/password-reset.ts @@ -13,7 +13,9 @@ export default async function PasswordResetTemplate( if (!matching_users.items.length) { throw new Errors.NotFound("No user with that email"); } - + if (!matching_users.items[0]) { + throw new Error("matching_users.items[0] undefined"); + } const username = matching_users.items[0].get("username"); return EmailTemplates.Simple(app, { diff --git a/src/back/policy-types/roles.ts b/src/back/policy-types/roles.ts index 89a2479..563d9c2 100644 --- a/src/back/policy-types/roles.ts +++ b/src/back/policy-types/roles.ts @@ -12,6 +12,9 @@ export class Roles extends Policy { async countMatchingRoles(context: Context) { const user_id = context.user_id; context.app.Logger.debug2("ROLES", "Checking the roles for user", user_id); + if (!context.app.collections["user-roles"]) { + throw new Error(`context.app.collections["user-roles"] undefined`); + } const user_roles = await context.app.collections["user-roles"] .list(context) .filter({ user: user_id }) diff --git a/src/back/routes/component-preview/component-preview-actions.ts b/src/back/routes/component-preview/component-preview-actions.ts index a4bad36..b2b831c 100644 --- a/src/back/routes/component-preview/component-preview-actions.ts +++ b/src/back/routes/component-preview/component-preview-actions.ts @@ -10,6 +10,10 @@ import { makeJDDContext } from "../../jdd-context.js"; function moveElement(array: Array, fromIndex: number, toIndex: number): Array { const element = array.splice(fromIndex, 1)[0]; + if (!element) { + console.error("element is undefined"); + return array; + } array.splice(toIndex, 0, element); return array; } diff --git a/src/back/routes/components.sreact.tsx b/src/back/routes/components.sreact.tsx index 38cb76c..656c478 100644 --- a/src/back/routes/components.sreact.tsx +++ b/src/back/routes/components.sreact.tsx @@ -15,6 +15,9 @@ export const actionName = "Components"; export default new (class JddcomponentDebuggerPage extends JDDPage { renderParameterButtons(state: JDDPageState): Stringifiable { const all_components = super.getRegistryComponents(); + if (!state.components[0]) { + console.error("No components are present in state.components"); + } return (
@@ -26,7 +29,11 @@ export default new (class JddcomponentDebuggerPage extends JDDPage { {Object.entries(all_components).map(([name]) => ( @@ -40,7 +47,11 @@ export default new (class JddcomponentDebuggerPage extends JDDPage { actions = ComponentPreviewActions; async getInitialState(ctx: BaseContext) { - const [component_name, component] = Object.entries(registry.getAll())[0]; + const component_constants = Object.entries(registry.getAll())[0]; + if (!component_constants) { + throw new Error("Constant component_name or component is udefined"); + } + const [component_name, component] = component_constants; const initial_state = { components: [ { diff --git a/src/back/util.ts b/src/back/util.ts index ae08d9b..b1da618 100644 --- a/src/back/util.ts +++ b/src/back/util.ts @@ -32,10 +32,12 @@ export function shuffle(array: T[]): T[] { currentIndex--; // And swap it with the current element. - [array_copy[currentIndex], array_copy[randomIndex]] = [ - array_copy[randomIndex], - array_copy[currentIndex], - ]; + const new_value = [array_copy[randomIndex], array_copy[currentIndex]]; + if (new_value[0] && new_value[1]) { + [array_copy[currentIndex], array_copy[randomIndex]] = new_value; + } else { + console.error("One of array_copy's values is undefined"); + } } return array_copy; } diff --git a/tsconfig-back.json b/tsconfig-back.json index 2eef0d0..3ee7ee5 100644 --- a/tsconfig-back.json +++ b/tsconfig-back.json @@ -6,7 +6,6 @@ "noImplicitThis": true, "strictNullChecks": true, "target": "ES2019", - "esModuleInterop": true, "lib": ["es2021"], "outDir": "./dist/back", "keyofStringsOnly": true, @@ -18,7 +17,8 @@ "resolveJsonModule": true, "sourceMap": true, "skipLibCheck": true, - "esModuleInterop": true + "esModuleInterop": true, + "noUncheckedIndexedAccess": true }, "include": ["./src/back/*", "./src/back/**/*", "./src/back/routes/common/navbar.ts"], "exclude": ["./src/front", "./src/**/*.stimulus.ts"], diff --git a/tsconfig-front.json b/tsconfig-front.json index f0176a5..cf6b83e 100644 --- a/tsconfig-front.json +++ b/tsconfig-front.json @@ -4,7 +4,8 @@ "target": "ES6", "lib": ["dom", "es2021"], "skipLibCheck": true, - "esModuleInterop": true + "esModuleInterop": true, + "noUncheckedIndexedAccess": true }, "include": ["./src/front", "./src/**/*.stimulus.ts"] }