Skip to content

Commit

Permalink
chore: add linter to api + types redundancy removal
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvincent committed Oct 5, 2023
1 parent 04ecb02 commit 4692dbf
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 114 deletions.
13 changes: 13 additions & 0 deletions apps/api-v2/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
// Add your custom rules here
"@typescript-eslint/no-explicit-any": "off"
}
}
6 changes: 5 additions & 1 deletion apps/api-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"db:migrate": "prisma migrate deploy",
"schema:generate": "prisma generate",
"db:start": "docker-compose up -d",
"db:setup": "npm run db:start && npm run db:migrate"
"db:setup": "npm run db:start && npm run db:migrate",
"lint": "eslint --ext .ts src"
},
"keywords": [],
"author": "Vincent Vu <[email protected]>",
Expand All @@ -33,6 +34,9 @@
"@types/passport-google-oauth20": "^2.0.11",
"@types/response-time": "^2.3.5",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"eslint": "^8.50.0",
"jest": "^29.6.4",
"jest-express": "^1.12.0",
"prisma": "^5.2.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/api-v2/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Server } from "http";
import config from "../config";

let httpServer: Server;
let { app } = createApp();
const { app } = createApp();

beforeEach(() => {
// run the server first
Expand Down
2 changes: 1 addition & 1 deletion apps/api-v2/src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import config from "./config";
import pino from "pino";

// only enable logging to axiom in production
export let loggerOptions: any = {};
export let loggerOptions: Record<string, any> = {};
if (process.env.NODE_ENV === "production") {
loggerOptions = {
transport: {
Expand Down
69 changes: 37 additions & 32 deletions apps/api-v2/src/routers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import config from "../config";
import jwt from "jsonwebtoken";
import {
EncodedProfileTokenClaims,
IAuthCtx,
IAuthPassportCallbackCtx,
SupernovaResponse,
} from "../types";
import { authenticateJWTMiddleware } from "../mws";
import { prisma, redis } from "../db";
import { redis } from "../db";
import { logger } from "../logging";
import { Strategy as GoogleStrategy } from "passport-google-oauth20";
import { getAuthContext } from "../utils";
Expand Down Expand Up @@ -143,41 +142,47 @@ export default function buildAuthRouter(): Router {
);
});

router.get("/auth/logout", authenticateJWTMiddleware, async (req, res) => {
try {
const userAuthCtx = getAuthContext(req);
// delete the refresh token from redis (stored as a KV pair of user ID -> refresh token)
if (userAuthCtx.sub === undefined) {
logger.error(
`userAuthCtx.sub is undefined; userAuthCtx=${JSON.stringify(
userAuthCtx
)}`
);
return res.status(400).send(
new SupernovaResponse({
error: "Internal Server Error",
message: "Failed to logout user",
})
);
}
await redis.connect();
const resdel = await redis.del(userAuthCtx.sub);
await redis.disconnect();
// didn't delete anything
if (resdel === 0) {
router.get(
"/auth/logout",
authenticateJWTMiddleware,
async (req, res, next) => {
try {
const userAuthCtx = getAuthContext(req);
// delete the refresh token from redis (stored as a KV pair of user ID -> refresh token)
if (userAuthCtx.sub === undefined) {
logger.error(
`userAuthCtx.sub is undefined; userAuthCtx=${JSON.stringify(
userAuthCtx
)}`
);
return res.status(400).send(
new SupernovaResponse({
error: "Internal Server Error",
message: "Failed to logout user",
})
);
}
await redis.connect();
const resdel = await redis.del(userAuthCtx.sub);
await redis.disconnect();
// didn't delete anything
if (resdel === 0) {
return res.status(200).send(
new SupernovaResponse({
message: "User has already been logged out",
})
);
}
return res.status(200).send(
new SupernovaResponse({
message: "User has already been logged out",
message: "User logged out",
})
);
} catch (err) {
return next(err);
}
return res.status(200).send(
new SupernovaResponse({
message: "User logged out",
})
);
} catch (err) {}
});
}
);

return router;
}
2 changes: 1 addition & 1 deletion apps/api-v2/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Profile } from "passport-google-oauth20";
import jwt from "jsonwebtoken";

export interface ISupernovaResponse<T extends any> {
export interface ISupernovaResponse<T> {
data?: T;
error?: string;
message?: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/api-v2/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-v2/components/command-center.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Mousetrap from "mousetrap";
import React from "react";
import { Kbd } from "./kbd";
import { SupernovaCommand } from "../types/command";
import { ISupernovaTask } from "../types/supernova-task";
import { ISupernovaTask } from "@supernova/types";
import { twMerge } from "tailwind-merge";
import { ibmPlexMono } from "./fonts";
import { SupernovaGlobeLogoImage } from "./icons";
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-v2/components/supernova-task.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { ArrowRightIcon } from "./icons";
import * as React from "react";
import { ISupernovaTask } from "../types/supernova-task";
import { ISupernovaTask } from "@supernova/types";
import { CustomCheckbox } from "./checkbox";
import { DurationWidget } from "./duration-widget";
import { StartTimeWidget } from "./start-time-widget";
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-v2/components/task-builder-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
RenderLeafProps,
} from "slate-react";
import { Descendant } from "slate";
import { ISupernovaTask } from "../types/supernova-task";
import { ISupernovaTask } from "@supernova/types";
import {
extractExpectedDuration,
START_AT_SLATE_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-v2/services/local-db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Database from "tauri-plugin-sql-api";
import { ISupernovaTask } from "../types/supernova-task";
import { ISupernovaTask } from "@supernova/types";

export namespace LocalDB {
// delete the table supernova_tasks if it exists
Expand Down
9 changes: 0 additions & 9 deletions apps/desktop-v2/types/supernova-task.ts

This file was deleted.

Loading

1 comment on commit 4692dbf

@vercel
Copy link

@vercel vercel bot commented on 4692dbf Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.