Skip to content

Commit

Permalink
Merge branch 'main' into hp/fix/lint-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshPatel5940 authored Jan 9, 2024
2 parents 9701783 + b15dbb0 commit 1163431
Show file tree
Hide file tree
Showing 95 changed files with 17,631 additions and 513 deletions.
7 changes: 5 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ DATABASE_URL=postgresql://postgres:<your-project-password>@db.<your-project-name
SUPABASE_API_URL=https://<your-project-name>.supabase.co
SUPABASE_ANON_KEY=

RESEND_API_KEY=re_
SMTP_HOST=
SMTP_PORT=
SMTP_EMAIL_ADDRESS=
SMTP_PASSWORD=
FROM_EMAIL="your-name <[email protected]>"

JWT_SECRET=secret

FROM_EMAIL="your-name <[email protected]>"
WEB_FRONTEND_URL=https://keyshade.xyz
WORKSPACE_FRONTEND_URL=https://app.keyshade.xyz
42 changes: 42 additions & 0 deletions .github/workflows/auto-assign.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Auto-assign issue on /attempt comment

on:
issue_comment:
types: [created]

jobs:
auto-assign:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const comment = context.payload.comment;
const issue = context.issue;
const owner = "keyshade-xyz";
const repo = "keyshade"
if (comment.body.startsWith('/attempt')) {
if (!issue.assignee) {
await github.rest.issues.addAssignees({
owner,
repo,
issue_number: issue.number,
assignees: [comment.user.login]
});
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: 'Assigned the issue to you!'
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: 'This issue is already assigned. Tag a maintainer if you need to take over.'
});
}
}
9 changes: 9 additions & 0 deletions CONTRIBUTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ Before reporting a bug, please check our list of [open issues](https://github.co

If you have ideas for improvements or new features we would love to hear them. Please provide as much detail as possible so we can fully understand your ideas. You can [create a new issue](https://github.com/keyshade-xyz/keyshade/issues/new/choose) to share your suggestions.

## Self Assigning Issues

1. To express interest in working on an issue, simply type `/attempt` at the beginning of a comment.
2. If the issue is unassigned, it will be automatically assigned to you. ✨
3. If the issue is already assigned, you'll receive a message indicating the need to contact a maintainer to discuss reassignment.

**Example:**
`/attempt` I'd like to work on this issue.

## Code Contribution

Please ensure your pull request adheres to the following guidelines:
Expand Down
1 change: 0 additions & 1 deletion apps/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"outputPath": "dist/apps/api",
"main": "apps/api/src/main.ts",
"tsConfig": "apps/api/tsconfig.app.json",
"assets": ["apps/api/src/assets"],
"webpackConfig": "apps/api/webpack.config.js"
},
"configurations": {
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Controller, Get } from '@nestjs/common'
import { Public } from '../decorators/public.decorator'
import { ApiTags } from '@nestjs/swagger'

@ApiTags('App Controller')
@Controller()
export class AppController {
constructor() {}
Expand Down
12 changes: 8 additions & 4 deletions apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { PassportModule } from '@nestjs/passport'
import { AuthModule } from '../auth/auth.module'
import { PrismaModule } from '../prisma/prisma.module'
import { CommonModule } from '../common/common.module'
import { ResendModule } from '../resend/resend.module'
import { MailModule } from '../mail/mail.module'
import { APP_GUARD } from '@nestjs/core'
import { AuthGuard } from '../auth/auth.guard'
import { AuthGuard } from '../auth/guard/auth.guard'
import { UserModule } from '../user/user.module'
import { ProjectModule } from '../project/project.module'
import { EnvironmentModule } from '../environment/environment.module'

@Module({
controllers: [AppController],
Expand All @@ -22,9 +24,11 @@ import { UserModule } from '../user/user.module'
AuthModule,
PrismaModule,
CommonModule,
ResendModule,
MailModule,
SupabaseModule,
UserModule
UserModule,
ProjectModule,
EnvironmentModule
],
providers: [
{
Expand Down
Empty file removed apps/api/src/assets/.gitkeep
Empty file.
24 changes: 0 additions & 24 deletions apps/api/src/auth/auth.controller.ts

This file was deleted.

18 changes: 14 additions & 4 deletions apps/api/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Module } from '@nestjs/common'
import { AuthService } from './auth.service'
import { AuthController } from './auth.controller'
import { AuthService } from './service/auth.service'
import { AuthController } from './controller/auth.controller'
import { JwtModule } from '@nestjs/jwt'
import { UserModule } from '../user/user.module'
import { AUTH_REPOSITORY } from './repository/interface.repository'
import { AuthRepository } from './repository/auth.repository'

@Module({
imports: [
Expand All @@ -13,9 +16,16 @@ import { JwtModule } from '@nestjs/jwt'
issuer: 'keyshade.xyz',
algorithm: 'HS256'
}
})
}),
UserModule
],
providers: [
AuthService,
{
provide: AUTH_REPOSITORY,
useClass: AuthRepository
}
],
providers: [AuthService],
controllers: [AuthController]
})
export class AuthModule {}
29 changes: 0 additions & 29 deletions apps/api/src/auth/auth.service.spec.ts

This file was deleted.

35 changes: 35 additions & 0 deletions apps/api/src/auth/controller/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Test, TestingModule } from '@nestjs/testing'
import { MockAuthRepository } from '../repository/mock.repository'
import { AUTH_REPOSITORY } from '../repository/interface.repository'
import { AuthService } from '../service/auth.service'
import { MAIL_SERVICE } from '../../mail/services/interface.service'
import { MockMailService } from '../../mail/services/mock.service'
import { JwtService } from '@nestjs/jwt'
import { PrismaService } from '../../prisma/prisma.service'
import { AuthController } from './auth.controller'
import { USER_REPOSITORY } from '../../user/repository/interface.repository'
import { MockUserRepository } from '../../user/repository/mock.repository'

describe('AuthController', () => {
let controller: AuthController

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
providers: [
AuthService,
{ provide: MAIL_SERVICE, useClass: MockMailService },
{ provide: AUTH_REPOSITORY, useClass: MockAuthRepository },
{ provide: USER_REPOSITORY, useClass: MockUserRepository },
JwtService,
PrismaService
]
}).compile()

controller = module.get<AuthController>(AuthController)
})

it('should be defined', () => {
expect(controller).toBeDefined()
})
})
74 changes: 74 additions & 0 deletions apps/api/src/auth/controller/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Controller, HttpStatus, Param, Post, Query } from '@nestjs/common'
import { AuthService } from '../service/auth.service'
import { UserAuthenticatedResponse } from '../auth.types'
import { Public } from '../../decorators/public.decorator'
import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger'

@ApiTags('Auth Controller')
@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}

@Public()
@Post('send-otp/:email')
@ApiOperation({
summary: 'Send OTP',
description:
'This endpoint sends OTPs to an email address. The OTP can then be used to generate valid tokens'
})
@ApiParam({
name: 'email',
description: 'Email to send OTP',
required: true
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Send OTP successfully'
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Email is invalid'
})
async sendOtp(
@Param('email')
email: string
): Promise<void> {
await this.authService.sendOtp(email)
}

@Public()
@Post('validate-otp')
@ApiOperation({
summary: 'Validate OTP',
description:
'This endpoint validates OTPs. If the OTP is valid, it returns a valid token along with the user details'
})
@ApiParam({
name: 'email',
description: 'Email to send OTP',
required: true
})
@ApiParam({
name: 'otp',
description: 'OTP to validate',
required: true
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Validate OTP successfully'
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Email not found'
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'OTP is invalid'
})
async validateOtp(
@Query('email') email: string,
@Query('otp') otp: string
): Promise<UserAuthenticatedResponse> {
return await this.authService.validateOtp(email, otp)
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ import {
CanActivate,
ExecutionContext,
ForbiddenException,
Inject,
Injectable
} from '@nestjs/common'
import { JwtService } from '@nestjs/jwt'
import { Request } from 'express'
import { PrismaRepository } from '../prisma/prisma.repository'
import { Reflector } from '@nestjs/core'
import { IS_PUBLIC_KEY } from '../decorators/public.decorator'
import { IS_PUBLIC_KEY } from '../../decorators/public.decorator'
import {
IUserRepository,
USER_REPOSITORY
} from '../../user/repository/interface.repository'

@Injectable()
export class AuthGuard implements CanActivate {
constructor(
private jwtService: JwtService,
private repository: PrismaRepository,
@Inject(USER_REPOSITORY) private repository: IUserRepository,
private reflector: Reflector
) {}

Expand Down
Loading

0 comments on commit 1163431

Please sign in to comment.