Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump @types/express from 4.17.21 to 5.0.0 #1982

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@nestjs/testing": "^10.4.4",
"@types/amqplib": "^0",
"@types/cookie-parser": "^1.4.7",
"@types/express": "^4.17.21",
"@types/express": "^5.0.0",
"@types/jest": "29.5.13",
"@types/jsonwebtoken": "^9",
"@types/lodash": "^4.17.9",
Expand Down
3 changes: 2 additions & 1 deletion src/domain/accounts/accounts.repository.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { Account } from '@/domain/accounts/entities/account.entity';
import { UpsertAccountDataSettingsDto } from '@/domain/accounts/entities/upsert-account-data-settings.dto.entity';
import { AuthPayload } from '@/domain/auth/entities/auth-payload.entity';
import { Module } from '@nestjs/common';
import { Request } from 'express';

export const IAccountsRepository = Symbol('IAccountsRepository');

export interface IAccountsRepository {
createAccount(args: {
authPayload: AuthPayload;
address: `0x${string}`;
clientIp: string;
clientIp: Request['ip'];
}): Promise<Account>;

getAccount(args: {
Expand Down
43 changes: 43 additions & 0 deletions src/domain/accounts/accounts.repository.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { AccountsRepository } from '@/domain/accounts/accounts.repository';
import { authPayloadDtoBuilder } from '@/domain/auth/entities/__tests__/auth-payload-dto.entity.builder';
import { AuthPayload } from '@/domain/auth/entities/auth-payload.entity';
import { IAccountsDatasource } from '@/domain/interfaces/accounts.datasource.interface';
import { faker } from '@faker-js/faker/.';
import { UnauthorizedException } from '@nestjs/common';
import { getAddress } from 'viem';

const mockAccountsDatasource = {
createAccount: jest.fn(),
} as jest.MockedObjectDeep<IAccountsDatasource>;

describe('AccountsRepository', () => {
let target: AccountsRepository;

beforeEach(() => {
jest.resetAllMocks();

target = new AccountsRepository(mockAccountsDatasource);
});

/**
* This is tested here instead of the controller as it is currently
* not possible to remove the IP from a request in supertest.
*/
describe('createAccount', () => {
it('should throw an UnauthorizedException if there is no IP present in the request', async () => {
const signerAddress = getAddress(faker.finance.ethereumAddress());
const authPayloadDto = authPayloadDtoBuilder()
.with('signer_address', signerAddress)
.build();
const authPayload = new AuthPayload(authPayloadDto);

await expect(
target.createAccount({
authPayload,
address: signerAddress,
clientIp: undefined,
}),
).rejects.toThrow(UnauthorizedException);
});
});
});
5 changes: 3 additions & 2 deletions src/domain/accounts/accounts.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { UpsertAccountDataSettingsDto } from '@/domain/accounts/entities/upsert-
import { AuthPayload } from '@/domain/auth/entities/auth-payload.entity';
import { IAccountsDatasource } from '@/domain/interfaces/accounts.datasource.interface';
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
import { Request } from 'express';

@Injectable()
export class AccountsRepository implements IAccountsRepository {
Expand All @@ -20,9 +21,9 @@ export class AccountsRepository implements IAccountsRepository {
async createAccount(args: {
authPayload: AuthPayload;
address: `0x${string}`;
clientIp: string;
clientIp: Request['ip'];
}): Promise<Account> {
if (!args.authPayload.isForSigner(args.address)) {
if (!args.clientIp || !args.authPayload.isForSigner(args.address)) {
throw new UnauthorizedException();
}
const account = await this.datasource.createAccount({
Expand Down
3 changes: 2 additions & 1 deletion src/routes/accounts/accounts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Account } from '@/routes/accounts/entities/account.entity';
import { CreateAccountDto } from '@/routes/accounts/entities/create-account.dto.entity';
import { UpsertAccountDataSettingsDto } from '@/routes/accounts/entities/upsert-account-data-settings.dto.entity';
import { Inject, Injectable } from '@nestjs/common';
import { Request } from 'express';

@Injectable()
export class AccountsService {
Expand All @@ -20,7 +21,7 @@ export class AccountsService {
async createAccount(args: {
authPayload: AuthPayload;
createAccountDto: CreateAccountDto;
clientIp: string;
clientIp: Request['ip'];
}): Promise<Account> {
const domainAccount = await this.accountsRepository.createAccount({
authPayload: args.authPayload,
Expand Down
28 changes: 26 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,19 @@ __metadata:
languageName: node
linkType: hard

"@types/express@npm:*, @types/express@npm:^4.17.21":
"@types/express-serve-static-core@npm:^5.0.0":
version: 5.0.0
resolution: "@types/express-serve-static-core@npm:5.0.0"
dependencies:
"@types/node": "npm:*"
"@types/qs": "npm:*"
"@types/range-parser": "npm:*"
"@types/send": "npm:*"
checksum: 10/fc40cdeae61113d8b2335f4b0f9334a7a64388a0931f2e98f8fc9bdadd0b13b501a70da14c256ae4aa140db49bd2eff75a99a683266d561e62540784a61dc489
languageName: node
linkType: hard

"@types/express@npm:*":
version: 4.17.21
resolution: "@types/express@npm:4.17.21"
dependencies:
Expand All @@ -1824,6 +1836,18 @@ __metadata:
languageName: node
linkType: hard

"@types/express@npm:^5.0.0":
version: 5.0.0
resolution: "@types/express@npm:5.0.0"
dependencies:
"@types/body-parser": "npm:*"
"@types/express-serve-static-core": "npm:^5.0.0"
"@types/qs": "npm:*"
"@types/serve-static": "npm:*"
checksum: 10/45b199ab669caa33e6badafeebf078e277ea95042309d325a04b1ec498f33d33fd5a4ae9c8e358342367b178fe454d7323c5dfc8002bf27070b210a2c6cc11f0
languageName: node
linkType: hard

"@types/graceful-fs@npm:^4.1.3":
version: 4.1.5
resolution: "@types/graceful-fs@npm:4.1.5"
Expand Down Expand Up @@ -7268,7 +7292,7 @@ __metadata:
"@safe-global/safe-deployments": "npm:^1.37.9"
"@types/amqplib": "npm:^0"
"@types/cookie-parser": "npm:^1.4.7"
"@types/express": "npm:^4.17.21"
"@types/express": "npm:^5.0.0"
"@types/jest": "npm:29.5.13"
"@types/jsonwebtoken": "npm:^9"
"@types/lodash": "npm:^4.17.9"
Expand Down