Skip to content

Commit

Permalink
[Refactor] #8704 Optimize StartUp Time For Core Package (#8739)
Browse files Browse the repository at this point in the history
* wip: #8704 startup API logger time on initialization

* Update yarn.lock

* wip: #8704 startup API logger time on initialization

* fix: #8704 updated profiling service

* chore(deps): remove unnecessary perf_hooks package

* updated app bootstrap logger

* fix: update code for router module

* fix: update code for router module

* fix: update code for router module

* fix: improved repository structure

* wip: improved repository structure

* wip: improved repository structure

* wip: improved repository structure

* fix: improved guards for auth controller methods

* fix: removed unnecessary exports of orm modules

* fix: remove `index.ts` (Barrel Files) in module repository directories

* fix(cspell): typo spelling :-)

* fix(deepscan): removed unnecessary import
  • Loading branch information
rahul-rocket authored Jan 21, 2025
1 parent 7ae484c commit 69ab8f9
Show file tree
Hide file tree
Showing 567 changed files with 3,255 additions and 5,011 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
"migration:generate": "yarn db:migration migration:generate",
"migration:create": "yarn db:migration migration:create",
"migration:command": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn --cwd ./packages/core",
"seed:base": "cross-env NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json",
"seed:base": "cross-env NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn run build:package:api && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json",
"seed": "yarn seed:base ./apps/api/src/seed.ts",
"seed:ever": "yarn seed:base ./apps/api/src/seed-ever.ts",
"seed:all": "yarn seed:base ./apps/api/src/seed-all.ts",
"seed:jobs": "yarn seed:base ./apps/api/src/seed-jobs.ts",
"seed:module": "yarn seed:base ./apps/api/src/seed-module.ts --name",
"seed:prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=12288 yarn build:package:all:prod && yarn run config:prod && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed.ts",
"seed:prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=12288 yarn run build:package:api:prod && yarn run config:prod && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed.ts",
"prebuild": "rimraf dist coverage",
"bootstrap": "yarn install --ignore-scripts && yarn postinstall.manual",
"build": "yarn build:package:all && concurrently --raw \"yarn build:api\" \"yarn build:gauzy\"",
Expand Down
22 changes: 8 additions & 14 deletions packages/auth/src/lib/auth0/auth0.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Response, Request } from 'express';
import { Public } from '@gauzy/common';
import { SocialAuthService } from './../social-auth.service';
import { IIncomingRequest, RequestCtx } from './../request-context.decorator';

@Controller('auth0')
@UseGuards(AuthGuard('auth0'))
@Public()
@Controller('/auth')
export class Auth0Controller {
constructor(public readonly service: SocialAuthService) {}

Expand All @@ -14,9 +16,8 @@ export class Auth0Controller {
*
* @param req - The incoming request object, typically used to access request data or user information.
*/
@Get('')
@UseGuards(AuthGuard('auth0'))
auth0Login(@Req() req: any) {}
@Get('/auth0')
auth0Login(@Req() _: Request) {}

/**
* Handles the callback from Auth0 after a successful login.
Expand All @@ -25,17 +26,10 @@ export class Auth0Controller {
* @param res - The response object used to send a redirect or response to the client.
* @returns {Promise<void>} - A promise that resolves after redirecting the user.
*/
@Get('callback')
@UseGuards(AuthGuard('auth0'))
async auth0LoginCallback(
@RequestCtx() requestCtx: IIncomingRequest,
@Res() res
) {
@Get('/auth0/callback')
async auth0LoginCallback(@RequestCtx() requestCtx: IIncomingRequest, @Res() res: Response) {
const { user } = requestCtx;
const {
success,
authData
} = await this.service.validateOAuthLoginEmail(user.emails);
const { success, authData } = await this.service.validateOAuthLoginEmail(user.emails);
return this.service.routeRedirect(success, authData, res);
}
}
19 changes: 7 additions & 12 deletions packages/auth/src/lib/facebook/facebook.controller.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Response, Request } from 'express';
import { FeatureFlagEnabledGuard, FeatureFlag, Public } from '@gauzy/common';
import { FeatureEnum } from '@gauzy/contracts';
import { SocialAuthService } from './../social-auth.service';
import { IIncomingRequest, RequestCtx } from './../request-context.decorator';

@Controller()
@UseGuards(FeatureFlagEnabledGuard, AuthGuard('facebook'))
@FeatureFlag(FeatureEnum.FEATURE_FACEBOOK_LOGIN)
@Public()
@Controller('/auth')
export class FacebookController {

constructor(
public readonly service: SocialAuthService
) { }
constructor(public readonly service: SocialAuthService) {}

/**
* Initiates Facebook login.
*
* @param req
*/
@Get('facebook')
facebookLogin(@Req() req: any) { }
@Get('/facebook')
facebookLogin(@Req() _: Request) {}

/**
* Facebook login callback endpoint.
Expand All @@ -30,11 +28,8 @@ export class FacebookController {
* @param res - The response object.
* @returns The result of the Facebook login callback.
*/
@Get('facebook/callback')
async facebookLoginCallback(
@RequestCtx() requestCtx: IIncomingRequest,
@Res() res
) {
@Get('/facebook/callback')
async facebookLoginCallback(@RequestCtx() requestCtx: IIncomingRequest, @Res() res: Response) {
const { user } = requestCtx;
const { success, authData } = await this.service.validateOAuthLoginEmail(user.emails);
return this.service.routeRedirect(success, authData, res);
Expand Down
21 changes: 7 additions & 14 deletions packages/auth/src/lib/github/github.controller.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Request, Response } from 'express';
import { Response, Request } from 'express';
import { FeatureFlag, FeatureFlagEnabledGuard, Public } from '@gauzy/common';
import { FeatureEnum } from '@gauzy/contracts';
import { SocialAuthService } from './../social-auth.service';
import { IIncomingRequest, RequestCtx } from './../request-context.decorator';

@Controller()
@UseGuards(FeatureFlagEnabledGuard, AuthGuard('github'))
@FeatureFlag(FeatureEnum.FEATURE_GITHUB_LOGIN)
@Public()
@Controller('/auth')
export class GithubController {

constructor(
public readonly service: SocialAuthService
) { }
constructor(public readonly service: SocialAuthService) {}

/**
* Initiates GitHub login.
*
* @param req
*/
@Get('github')
@UseGuards(FeatureFlagEnabledGuard, AuthGuard('github'))
@Get('/github')
githubLogin(@Req() _req: Request) {
// This method is empty because AuthGuard('github') initiates the GitHub login
// The user will be redirected to the GitHub login page by Passport
Expand All @@ -34,12 +31,8 @@ export class GithubController {
* @param _res - The response object.
* @returns The result of the GitHub login callback.
*/
@Get('github/callback')
@UseGuards(FeatureFlagEnabledGuard, AuthGuard('github'))
async githubLoginCallback(
@RequestCtx() _req: IIncomingRequest,
@Res() _res: Response
) {
@Get('/github/callback')
async githubLoginCallback(@RequestCtx() _req: IIncomingRequest, @Res() _res: Response) {
const { user } = _req;

// To-DO: Determine the frontend URL based on the request
Expand Down
16 changes: 7 additions & 9 deletions packages/auth/src/lib/google/google.controller.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Response, Request } from 'express';
import { FeatureFlagEnabledGuard, FeatureFlag, Public } from '@gauzy/common';
import { SocialAuthService } from './../social-auth.service';
import { IIncomingRequest, RequestCtx } from './../request-context.decorator';
import { FeatureEnum } from '@gauzy/contracts';

@Controller()
@UseGuards(FeatureFlagEnabledGuard, AuthGuard('google'))
@FeatureFlag(FeatureEnum.FEATURE_GOOGLE_LOGIN)
@Public()
@Controller('/auth')
export class GoogleController {
constructor(public readonly service: SocialAuthService) { }
constructor(public readonly service: SocialAuthService) {}

/**
* Initiates Google login.
*
* @param req
*/
@Get('google')
googleLogin(@Req() req: any) { }
@Get('/google')
googleLogin(@Req() _: Request) {}

/**
* Google login callback endpoint.
Expand All @@ -27,11 +28,8 @@ export class GoogleController {
* @param res - The response object.
* @returns The result of the Google login callback.
*/
@Get('google/callback')
async googleLoginCallback(
@RequestCtx() requestCtx: IIncomingRequest,
@Res() res
) {
@Get('/google/callback')
async googleLoginCallback(@RequestCtx() requestCtx: IIncomingRequest, @Res() res: Response) {
const { user } = requestCtx;
const { success, authData } = await this.service.validateOAuthLoginEmail(user.emails);
return this.service.routeRedirect(success, authData, res);
Expand Down
19 changes: 7 additions & 12 deletions packages/auth/src/lib/linkedin/linkedin.controller.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Response, Request } from 'express';
import { FeatureFlagEnabledGuard, FeatureFlag, Public } from '@gauzy/common';
import { FeatureEnum } from '@gauzy/contracts';
import { SocialAuthService } from './../social-auth.service';
import { IIncomingRequest, RequestCtx } from './../request-context.decorator';

@Controller()
@UseGuards(FeatureFlagEnabledGuard, AuthGuard('linkedin'))
@FeatureFlag(FeatureEnum.FEATURE_LINKEDIN_LOGIN)
@Public()
@Controller('/auth')
export class LinkedinController {

constructor(
public readonly service: SocialAuthService
) { }
constructor(public readonly service: SocialAuthService) {}

/**
* Initiates LinkedIn login.
*
* @param req
*/
@Get('linkedin')
linkedinLogin(@Req() req: any) { }
@Get('/linkedin')
linkedinLogin(@Req() _: Request) {}

/**
* LinkedIn login callback endpoint.
Expand All @@ -30,11 +28,8 @@ export class LinkedinController {
* @param res - The response object.
* @returns The result of the LinkedIn login callback.
*/
@Get('linkedin/callback')
async linkedinLoginCallback(
@RequestCtx() requestCtx: IIncomingRequest,
@Res() res
) {
@Get('/linkedin/callback')
async linkedinLoginCallback(@RequestCtx() requestCtx: IIncomingRequest, @Res() res: Response) {
const { user } = requestCtx;
const { success, authData } = await this.service.validateOAuthLoginEmail(user.emails);

Expand Down
19 changes: 7 additions & 12 deletions packages/auth/src/lib/microsoft/microsoft.controller.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Response, Request } from 'express';
import { FeatureFlagEnabledGuard, FeatureFlag, Public } from '@gauzy/common';
import { FeatureEnum } from '@gauzy/contracts';
import { SocialAuthService } from './../social-auth.service';
import { IIncomingRequest, RequestCtx } from './../request-context.decorator';

@Controller()
@UseGuards(FeatureFlagEnabledGuard, AuthGuard('microsoft'))
@FeatureFlag(FeatureEnum.FEATURE_MICROSOFT_LOGIN)
@Public()
@Controller('/auth')
export class MicrosoftController {

constructor(
public readonly service: SocialAuthService
) { }
constructor(public readonly service: SocialAuthService) {}

/**
* Initiates Microsoft login.
*
* @param req
*/
@Get('microsoft')
microsoftLogin(@Req() req: any) { }
@Get('/microsoft')
microsoftLogin(@Req() _: Request) {}

/**
* Microsoft login callback endpoint.
Expand All @@ -30,11 +28,8 @@ export class MicrosoftController {
* @param res - The response object.
* @returns The result of the Microsoft login callback.
*/
@Get('microsoft/callback')
async microsoftLoginCallback(
@RequestCtx() requestCtx: IIncomingRequest,
@Res() res
) {
@Get('/microsoft/callback')
async microsoftLoginCallback(@RequestCtx() requestCtx: IIncomingRequest, @Res() res: Response) {
const { user } = requestCtx;
const { success, authData } = await this.service.validateOAuthLoginEmail(user.emails);
return this.service.routeRedirect(success, authData, res);
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/lib/social-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class SocialAuthService extends BaseSocialAuth {
this.clientBaseUrl = this.configService.get('clientBaseUrl') as Extract<keyof IEnvironment, string>;
}

public validateOAuthLoginEmail(args: []): any { }
public validateOAuthLoginEmail(args: []): any {}

/**
* Generate a hash for the provided password.
Expand Down
19 changes: 7 additions & 12 deletions packages/auth/src/lib/twitter/twitter.controller.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Response, Request } from 'express';
import { FeatureFlagEnabledGuard, FeatureFlag, Public } from '@gauzy/common';
import { FeatureEnum } from '@gauzy/contracts';
import { SocialAuthService } from './../social-auth.service';
import { IIncomingRequest, RequestCtx } from './../request-context.decorator';

@Controller()
@UseGuards(FeatureFlagEnabledGuard, AuthGuard('twitter'))
@FeatureFlag(FeatureEnum.FEATURE_TWITTER_LOGIN)
@Public()
@Controller('/auth')
export class TwitterController {

constructor(
public readonly service: SocialAuthService
) { }
constructor(public readonly service: SocialAuthService) {}

/**
* Initiates Twitter login.
*
* @param req
*/
@Get('twitter')
twitterLogin(@Req() req: any) { }
@Get('/twitter')
twitterLogin(@Req() _: Request) {}

/**
* Twitter login callback endpoint.
Expand All @@ -30,11 +28,8 @@ export class TwitterController {
* @param res - The response object.
* @returns The result of the Twitter login callback.
*/
@Get('twitter/callback')
async twitterLoginCallback(
@RequestCtx() requestCtx: IIncomingRequest,
@Res() res: any
) {
@Get('/twitter/callback')
async twitterLoginCallback(@RequestCtx() requestCtx: IIncomingRequest, @Res() res: Response) {
const { user } = requestCtx;
const { success, authData } = await this.service.validateOAuthLoginEmail(user.emails);
return this.service.routeRedirect(success, authData, res);
Expand Down
Loading

0 comments on commit 69ab8f9

Please sign in to comment.