Skip to content

Commit

Permalink
Merge branch 'next' into dependabot/npm_and_yarn/apps/web/next-14.2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismayuresh authored Nov 21, 2024
2 parents 0892c77 + 770fd18 commit 367ea86
Show file tree
Hide file tree
Showing 475 changed files with 31,179 additions and 17,683 deletions.
9 changes: 9 additions & 0 deletions apps/api/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"loader": "ts-node/esm",
"extensions": [
"ts"
],
"spec": [
"src/**/**/*.spec.ts"
]
}
2 changes: 1 addition & 1 deletion apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18.16.1-bullseye-slim
FROM node:20.13.1-bullseye-slim

COPY apps/api/src/config/default.cf /usr/local/etc/isolate

Expand Down
39 changes: 21 additions & 18 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@impler/api",
"version": "0.24.1",
"version": "0.27.1",
"author": "implerhq",
"license": "MIT",
"private": true,
Expand All @@ -16,23 +16,25 @@
"lint": "eslint src",
"lint:fix": "pnpm lint -- --fix",
"migration": "cross-env NODE_ENV=local MIGRATION=true ts-node --require tsconfig-paths/register --transpileOnly",
"test": "cross-env TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit src/**/**/*.spec.ts"
"test": "cross-env TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit"
},
"dependencies": {
"@impler/dal": "^0.24.1",
"@impler/services": "^0.24.1",
"@impler/shared": "^0.24.1",
"@nestjs/common": "^9.1.2",
"@nestjs/core": "^9.1.2",
"@nestjs/jwt": "^10.0.1",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.1.2",
"@nestjs/platform-socket.io": "9.4.3",
"@nestjs/platform-ws": "9.4.3",
"@nestjs/schedule": "^4.1.0",
"@nestjs/swagger": "^6.1.2",
"@nestjs/terminus": "^9.1.3",
"@nestjs/websockets": "9.4.3",
"@amplitude/analytics-node": "^1.3.6",
"@impler/client": "workspace:^",
"@impler/dal": "workspace:^",
"@impler/services": "workspace:^",
"@impler/shared": "workspace:^",
"@nestjs/common": "^10.4.4",
"@nestjs/core": "^10.4.4",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.4.4",
"@nestjs/platform-socket.io": "10.4.4",
"@nestjs/platform-ws": "10.4.4",
"@nestjs/schedule": "^4.1.1",
"@nestjs/swagger": "^7.4.2",
"@nestjs/terminus": "^10.2.3",
"@nestjs/websockets": "10.4.4",
"@sentry/node": "^7.112.2",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
Expand All @@ -45,11 +47,12 @@
"class-validator": "^0.14.0",
"compression": "^1.7.4",
"cookie-parser": "^1.4.6",
"cron": "^3.1.7",
"cron": "^3.1.9",
"date-fns": "^2.30.0",
"dayjs": "^1.11.11",
"dotenv": "^16.0.2",
"envalid": "^7.3.1",
"exceljs": "^4.4.0",
"hat": "^0.0.3",
"jsonwebtoken": "^9.0.0",
"jszip": "^3.10.1",
Expand All @@ -68,7 +71,7 @@
"xml2js": "^0.6.2"
},
"devDependencies": {
"@nestjs/cli": "^9.1.5",
"@nestjs/cli": "^10.4.5",
"@types/bcryptjs": "^2.4.2",
"@types/body-parser": "^1.19.2",
"@types/chai": "^4.3.4",
Expand Down
3 changes: 3 additions & 0 deletions apps/api/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
2 changes: 2 additions & 0 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { EnvironmentModule } from './app/environment/environment.module';
import { ActivityModule } from './app/activity/activity.module';
import { UserModule } from './app/user/user.module';
import { ImportJobsModule } from 'app/import-jobs/import-jobs.module';
import { TeamModule } from 'app/team/team.module';

const modules: Array<Type | DynamicModule | Promise<DynamicModule> | ForwardReference> = [
ProjectModule,
Expand All @@ -31,6 +32,7 @@ const modules: Array<Type | DynamicModule | Promise<DynamicModule> | ForwardRefe
EnvironmentModule,
ActivityModule,
ImportJobsModule,
TeamModule,
];

const providers = [Logger];
Expand Down
53 changes: 29 additions & 24 deletions apps/api/src/app/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
UseInterceptors,
} from '@nestjs/common';

import { IJwtPayload } from '@impler/shared';
import { constructQueryString, IJwtPayload, UserRolesEnum } from '@impler/shared';
import { AuthService } from './services/auth.service';
import { IStrategyResponse } from '@shared/types/auth.types';
import { CONSTANTS, COOKIE_CONFIG } from '@shared/constants';
Expand All @@ -37,8 +37,6 @@ import {
OnboardUser,
RegisterUser,
ResetPassword,
LoginUserCommand,
RegisterUserCommand,
ResetPasswordCommand,
RequestForgotPassword,
RequestForgotPasswordCommand,
Expand Down Expand Up @@ -76,7 +74,10 @@ export class AuthController {

@Get('/github/callback')
@UseGuards(AuthGuard('github'))
async githubCallback(@StrategyUser() strategyUser: IStrategyResponse, @Res() response: Response) {
async githubCallback(
@Res({ passthrough: true }) response: Response,
@StrategyUser() strategyUser: IStrategyResponse
) {
if (!strategyUser || !strategyUser.token) {
return response.redirect(`${process.env.WEB_BASE_URL}/auth/signin?error=AuthenticationError`);
}
Expand All @@ -88,11 +89,7 @@ export class AuthController {
if (strategyUser.showAddProject) {
queryObj.showAddProject = true;
}
for (const key in queryObj) {
if (queryObj.hasOwnProperty(key)) {
url += `${url.includes('?') ? '&' : '?'}${key}=${queryObj[key]}`;
}
}
url += constructQueryString(queryObj);

response.cookie(CONSTANTS.AUTH_COOKIE_NAME, strategyUser.token, {
...COOKIE_CONFIG,
Expand Down Expand Up @@ -133,7 +130,7 @@ export class AuthController {

@Post('/register')
async register(@Body() body: RegisterUserDto, @Res() response: Response) {
const registeredUser = await this.registerUser.execute(RegisterUserCommand.create(body));
const registeredUser = await this.registerUser.execute(body);

response.cookie(CONSTANTS.AUTH_COOKIE_NAME, registeredUser.token, {
...COOKIE_CONFIG,
Expand All @@ -160,22 +157,31 @@ export class AuthController {
@UserSession() user: IJwtPayload,
@Res({ passthrough: true }) res: Response
) {
const projectWithEnvironment = await this.onboardUser.execute({
_userId: user._id,
projectName: body.projectName,
role: body.role,
companySize: body.companySize,
source: body.source,
});
const projectWithEnvironment = await this.onboardUser.execute(
{
_userId: user._id,
projectName: body.projectName,
role: body.role,
companySize: body.companySize,
source: body.source,
},
user.email
);

const userApiKey = projectWithEnvironment.environment.apiKeys.find(
(apiKey) => apiKey._userId.toString() === user._id
);

const token = this.authService.getSignedToken(
{
_id: user._id,
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
role: userApiKey.role as UserRolesEnum,
profilePicture: user.profilePicture,
isEmailVerified: user.isEmailVerified,
accessToken: projectWithEnvironment.environment.apiKeys[0].key,
accessToken: projectWithEnvironment.environment.key,
},
projectWithEnvironment.project._id
);
Expand All @@ -189,12 +195,11 @@ export class AuthController {

@Post('/login')
async login(@Body() body: LoginUserDto, @Res() response: Response) {
const loginUser = await this.loginUser.execute(
LoginUserCommand.create({
email: body.email,
password: body.password,
})
);
const loginUser = await this.loginUser.execute({
email: body.email,
password: body.password,
invitationId: body.invitationId,
});

response.cookie(CONSTANTS.AUTH_COOKIE_NAME, loginUser.token, {
...COOKIE_CONFIG,
Expand Down
9 changes: 8 additions & 1 deletion apps/api/src/app/auth/dtos/login-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsDefined, IsString, IsEmail } from 'class-validator';
import { IsDefined, IsString, IsEmail, IsOptional } from 'class-validator';

export class LoginUserDto {
@ApiProperty({
Expand All @@ -15,4 +15,11 @@ export class LoginUserDto {
@IsString()
@IsDefined()
password: string;

@ApiProperty({
description: 'InvitationId to accept invitation later on',
})
@IsString()
@IsOptional()
invitationId?: string;
}
9 changes: 8 additions & 1 deletion apps/api/src/app/auth/dtos/register-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsDefined, IsString, IsEmail } from 'class-validator';
import { IsDefined, IsString, IsEmail, IsOptional } from 'class-validator';

export class RegisterUserDto {
@ApiProperty({
Expand Down Expand Up @@ -29,4 +29,11 @@ export class RegisterUserDto {
@IsString()
@IsDefined()
password: string;

@ApiProperty({
description: 'InvitationId to accept invitation later on',
})
@IsString()
@IsOptional()
invitationId?: string;
}
27 changes: 9 additions & 18 deletions apps/api/src/app/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as bcrypt from 'bcryptjs';
import { JwtService } from '@nestjs/jwt';
import { Injectable, UnauthorizedException } from '@nestjs/common';

import { IJwtPayload } from '@impler/shared';
import { IJwtPayload, UserRolesEnum } from '@impler/shared';
import { CONSTANTS, LEAD_SIGNUP_USING } from '@shared/constants';
import { UserEntity, UserRepository, EnvironmentRepository } from '@impler/dal';
import { UserNotFoundException } from '@shared/exceptions/user-not-found.exception';
Expand Down Expand Up @@ -31,6 +31,7 @@ export class AuthService {
lastName: profile.lastName,
signupMethod: LEAD_SIGNUP_USING.GITHUB,
profilePicture: profile.avatar_url,
role: UserRolesEnum.ADMIN,
...(provider ? { tokens: [provider] } : {}),
};
user = await this.userRepository.create(userObj);
Expand All @@ -54,6 +55,7 @@ export class AuthService {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: apiKey?.role as UserRolesEnum,
profilePicture: user.profilePicture,
accessToken: apiKey?.apiKey,
isEmailVerified: user.isEmailVerified,
Expand Down Expand Up @@ -89,6 +91,7 @@ export class AuthService {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: apiKey.role as UserRolesEnum,
accessToken: apiKey?.apiKey,
isEmailVerified: user.isEmailVerified,
},
Expand All @@ -109,6 +112,7 @@ export class AuthService {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: apiKey.role as UserRolesEnum,
accessToken: apiKey?.apiKey,
isEmailVerified: user.isEmailVerified,
},
Expand All @@ -122,6 +126,7 @@ export class AuthService {
firstName: string;
lastName: string;
email: string;
role?: UserRolesEnum;
isEmailVerified: boolean;
profilePicture?: string;
accessToken?: string;
Expand All @@ -134,6 +139,7 @@ export class AuthService {
{
_id: user._id,
_projectId,
role: user.role,
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
Expand Down Expand Up @@ -173,23 +179,7 @@ export class AuthService {
const environment = await this.environmentRepository.findByApiKey(apiKey);
if (!environment) throw new UnauthorizedException('API Key not found!');

const key = environment.apiKeys.find((i) => i.key === apiKey);
if (!key) throw new UnauthorizedException('API Key not found!');

const user = await this.getUser({ _id: key._userId });
if (!user) throw new UnauthorizedException('User not found!');

return this.getSignedToken(
{
_id: user._id,
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
accessToken: apiKey,
isEmailVerified: user.isEmailVerified,
},
environment._projectId
);
if (apiKey !== environment.key) throw new UnauthorizedException('API Key not found!');
}

async generateUserToken(user: UserEntity) {
Expand All @@ -201,6 +191,7 @@ export class AuthService {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: apiKey.role as UserRolesEnum,
accessToken: apiKey?.apiKey,
isEmailVerified: user.isEmailVerified,
},
Expand Down
10 changes: 1 addition & 9 deletions apps/api/src/app/auth/usecases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { RequestForgotPassword } from './request-forgot-password/request-forgot-

import { Verify } from './verify/verify.usecase';
import { ResendOTP } from './resend-otp/resend-otp.usecase';
import { LoginUserCommand } from './login-user/login-user.command';
import { OnboardUserCommand } from './onboard-user/onboard-user.command';
import { RegisterUserCommand } from './register-user/register-user.command';
import { ResetPasswordCommand } from './reset-password/reset-password.command';
import { RequestForgotPasswordCommand } from './request-forgot-password/request-forgot-pasword.command';

Expand Down Expand Up @@ -38,11 +36,5 @@ export const USE_CASES = [
//
];

export { OnboardUserCommand, ResetPasswordCommand, RequestForgotPasswordCommand };
export { Verify, RegisterUser, LoginUser, RequestForgotPassword, ResetPassword, OnboardUser, ResendOTP, UpdateUser };
export {
LoginUserCommand,
OnboardUserCommand,
RegisterUserCommand,
ResetPasswordCommand,
RequestForgotPasswordCommand,
};
11 changes: 2 additions & 9 deletions apps/api/src/app/auth/usecases/login-user/login-user.command.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { IsDefined, IsEmail, IsString } from 'class-validator';
import { BaseCommand } from '@shared/commands/base.command';

export class LoginUserCommand extends BaseCommand {
@IsEmail()
@IsDefined()
export class LoginUserCommand {
email: string;

@IsString()
@IsDefined()
password: string;
invitationId?: string;
}
Loading

0 comments on commit 367ea86

Please sign in to comment.