Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
chore: bump eslint to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianAndersen committed Dec 16, 2024
1 parent 0544dc3 commit fc54894
Show file tree
Hide file tree
Showing 60 changed files with 367 additions and 354 deletions.
15 changes: 0 additions & 15 deletions .eslintignore

This file was deleted.

57 changes: 0 additions & 57 deletions .eslintrc.cjs

This file was deleted.

72 changes: 72 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// @ts-check
// remember: "plugin:deprecation/recommended",
import eslint from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
import deprecationPlugin from "eslint-plugin-deprecation";
import importPlugin from "eslint-plugin-import";
import noRelativeImportPathsPlugin from "eslint-plugin-no-relative-import-paths";
import tseslint from "typescript-eslint";
//import tsParser from "@typescript-eslint/parser";
//import ts from "@typescript-eslint/eslint-plugin";

// TODO: enable eslint-plugin-import (absolute imports) when it is properly supported with flat configs

export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.strict,
tseslint.configs.stylistic,
// importPlugin.flatConfigs.recommended,
// importPlugin.flatConfigs.typescript,
{
files: ["**/*.{js,mjs,cjs,ts}"],
plugins: {
"no-relative-import-paths": noRelativeImportPathsPlugin,
import: importPlugin,
deprecation: deprecationPlugin,
},
/*
languageOptions: {
parser: tsParser,
parserOptions: {
project: ["tsconfig.json"],
},
},
*/
rules: {
//...ts.configs["recommended-requiring-type-checking"].rules,
//...ts.configs["stylistic-type-checked"].rules,
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_" },
],
"no-relative-import-paths/no-relative-import-paths": [
"error",
{
rootDir: "src",
prefix: "@",
},
],
/** @see https://medium.com/weekly-webtips/how-to-sort-imports-like-a-pro-in-typescript-4ee8afd7258a */
"import/order": [
"error",
{
groups: [
"builtin",
"external",
"internal",
["sibling", "parent"],
"index",
"unknown",
],
"newlines-between": "always",
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
/** */
},
},
eslintConfigPrettier,
);
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"serve": "node ./dist/index.js",
"prettier": "prettier --write . --ignore-path=.gitignore",
"prettier:check": "prettier --check . --ignore-path=.gitignore",
"lint": "eslint .",
"lint": "eslint src --ignore-pattern \"**/*.spec.ts\"",
"type-check": "tsc --noEmit",
"test": "API_ENV=test mocha \"src/**/*.spec.ts\""
},
Expand Down Expand Up @@ -56,7 +56,7 @@
"passport-google-oauth20": "^2.0.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"pdfkit": "^0.15.1",
"pdfkit": "^0.15.2",
"qrcode": "^1.5.4",
"qs": "^6.13.1",
"request": "^2.88.0",
Expand All @@ -66,11 +66,12 @@
"winston": "^3.17.0"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"chai": "^4.4.1",
"chai-as-promised": "^7.1.1",
"eslint": "^8.57.1",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-deprecation": "^3.0.0",
Expand All @@ -82,7 +83,8 @@
"sinon": "^18.0.0",
"sinon-chai": "^3.6.0",
"tsx": "^4.19.2",
"typescript": "^5.7.2"
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.0"
},
"repository": {
"type": "git",
Expand Down
62 changes: 30 additions & 32 deletions src/auth/bl.auth.ts → src/auth/initAuthEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,39 @@ import { UserHandler } from "@/auth/user/user.handler";
import { SeCrypto } from "@/crypto/se.crypto";
import { SEResponseHandler } from "@/response/se.response.handler";

export class BlAuth {
constructor(router: Router) {
const userHandler = new UserHandler();
export function initAuthEndpoints(router: Router) {
const userHandler = new UserHandler();

const localLoginPasswordValidator = new LocalLoginPasswordValidator(
new SeCrypto(),
);
const localLoginPasswordValidator = new LocalLoginPasswordValidator(
new SeCrypto(),
);

const localLoginHandler = new LocalLoginHandler();
const seCrypto = new SeCrypto();
const saltGenerator = new SaltGenerator();
const hashedPasswordGenerator = new HashedPasswordGenerator(
saltGenerator,
seCrypto,
);
const providerIdGenerator = new ProviderIdGenerator(seCrypto);
const localLoginCreator = new LocalLoginCreator(
hashedPasswordGenerator,
providerIdGenerator,
);
const localLoginValidator = new LocalLoginValidator(
localLoginHandler,
localLoginPasswordValidator,
localLoginCreator,
userHandler,
);
const resHandler = new SEResponseHandler();
const localLoginHandler = new LocalLoginHandler();
const seCrypto = new SeCrypto();
const saltGenerator = new SaltGenerator();
const hashedPasswordGenerator = new HashedPasswordGenerator(
saltGenerator,
seCrypto,
);
const providerIdGenerator = new ProviderIdGenerator(seCrypto);
const localLoginCreator = new LocalLoginCreator(
hashedPasswordGenerator,
providerIdGenerator,
);
const localLoginValidator = new LocalLoginValidator(
localLoginHandler,
localLoginPasswordValidator,
localLoginCreator,
userHandler,
);
const resHandler = new SEResponseHandler();

const tokenHandler = new TokenHandler(userHandler);
const tokenHandler = new TokenHandler(userHandler);

new AccessTokenAuth();
new AccessTokenAuth();

new GoogleAuth(router, resHandler);
new FacebookAuth(router, resHandler);
new LocalAuth(router, localLoginValidator, resHandler, tokenHandler);
new TokenEndpoint(router, resHandler, tokenHandler);
}
new GoogleAuth(router, resHandler);
new FacebookAuth(router, resHandler);
new LocalAuth(router, localLoginValidator, resHandler, tokenHandler);
new TokenEndpoint(router, resHandler, tokenHandler);
}
4 changes: 2 additions & 2 deletions src/auth/token/access-token/access-token.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UserPermission } from "@boklisten/bl-model";

export type AccessToken = {
export interface AccessToken {
iss: string;
aud: string;
expiresIn: string;
Expand All @@ -9,4 +9,4 @@ export type AccessToken = {
username: string;
permission: UserPermission;
details: string;
};
}
4 changes: 2 additions & 2 deletions src/auth/token/refresh/refresh-token.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export type RefreshToken = {
export interface RefreshToken {
iss: string;
aud: string;
expiresIn: string;
iat: number;
sub: string;
username: string;
};
}
2 changes: 1 addition & 1 deletion src/auth/token/refresh/refresh-token.validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("RefreshTokenValidator", () => {
sign(
{ username: "test", iat: Math.floor(Date.now() / 1000) - 10000 },
"test",
{ expiresIn: "1s" }, // eslint-disable-next-line @typescript-eslint/ban-ts-comment
{ expiresIn: "1s" },
(error, refreshToken) => {
refreshTokenValidator
.validate(refreshToken)
Expand Down
12 changes: 6 additions & 6 deletions src/auth/token/se.token.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { BlError, UserPermission } from "@boklisten/bl-model";
import { sign, verify } from "jsonwebtoken";

export type JwtPayload = {
export interface JwtPayload {
iss: string;
aud: string;
iat: number;
exp: number;
permission: UserPermission;
blid: string;
username: string;
};
}

export type ValidCustomJwtPayload = {
export interface ValidCustomJwtPayload {
permissions?: string[];
blid?: string;
username?: string;
};
}

export type JwtOptions = {
export interface JwtOptions {
exp: number;
aud: string;
iss: string;
};
}

export class SEToken {
private options: JwtOptions;
Expand Down
8 changes: 5 additions & 3 deletions src/auth/user/user.handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ const testUser = {
} as User;

describe("UserHandler", () => {
const userStorage: BlDocumentStorage<User> = new BlDocumentStorage(
const userStorage = new BlDocumentStorage<User>(
BlCollectionName.Users,
UserSchema,
);
const emailValidationHelper: EmailValidationHelper =
new EmailValidationHelper();
const userDetailStorage: BlDocumentStorage<UserDetail> =
new BlDocumentStorage(BlCollectionName.UserDetails, userDetailSchema);
const userDetailStorage = new BlDocumentStorage<UserDetail>(
BlCollectionName.UserDetails,
userDetailSchema,
);
const localLoginHandler: LocalLoginHandler = new LocalLoginHandler();
const userHandler = new UserHandler(
userDetailStorage,
Expand Down
2 changes: 0 additions & 2 deletions src/bl-error/bl-error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { BlError, BlapiErrorResponse } from "@boklisten/bl-model";
import { logger } from "@/logger/logger";

export class BlErrorHandler {
constructor() {}

public createBlapiErrorResponse(err: unknown): BlapiErrorResponse {
const blError =
err instanceof BlError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class OrderToCustomerItemGenerator {
order,
orderItem,
);
customerItem.viewableFor = [customerDetail.blid!];
customerItem.viewableFor = [customerDetail?.blid ?? ""];
customerItems.push(customerItem);
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe("CustomerItemPostHook", () => {
const customerItemValidator = new CustomerItemValidator(customerItemStorage);
const customerItemPostHook = new CustomerItemPostHook(
customerItemValidator,
customerItemStorage,
userDetailStorage,
orderStorage,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export class CustomerItemPostHook extends Hook {

constructor(
customerItemValidator?: CustomerItemValidator,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
customerItemStorage?: BlDocumentStorage<CustomerItem>,
userDetailStorage?: BlDocumentStorage<UserDetail>,
orderStorage?: BlDocumentStorage<Order>,
userDetailHelper?: UserDetailHelper,
Expand Down Expand Up @@ -112,7 +109,7 @@ export class CustomerItemPostHook extends Hook {
}

return this._orderStorage
.get(customerItem.orders[0]!)
.get(customerItem.orders[0] ?? "")
.then((order: Order) => {
//update the corresponding orderItem with customerItem
for (const orderItem of order.orderItems) {
Expand Down
Loading

0 comments on commit fc54894

Please sign in to comment.