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

Commit

Permalink
fix(nestjs-new-template): Update dependencies and update source for it
Browse files Browse the repository at this point in the history
  • Loading branch information
EndyKaufman committed Sep 21, 2018
1 parent d10afd7 commit e8c76f5
Show file tree
Hide file tree
Showing 9 changed files with 3,942 additions and 3,737 deletions.
7,492 changes: 3,850 additions & 3,642 deletions src/nestjs/new/files/__root__/package-lock.__json__

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions src/nestjs/new/files/__root__/package.__json__
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"clean": "./node_modules/.bin/del-cli dist www/docs database/sqlitedb.db",
"format": "prettier --write \"src/**/*.ts\"",
"start:dev": "cross-env DB_SOURCE_EXT=ts nodemon",
"start:prod": "cross-env NODE_ENV=production ./node_modules/.bin/pm2 start dist/main.js --name <%=name%>",
"start:prod": "cross-env NODE_ENV=production ./node_modules/.bin/pm2 start dist/main.js --name <%=name%>",
"start:hmr": "cross-env NODE_ENV=production node dist/main.hmr.js",
"start": "node dist/main.js",
"stop": "./node_modules/.bin/pm2 kill",
Expand All @@ -68,11 +68,11 @@
"prepare": "run-s prepare:core prepare:auth"
},
"dependencies": {
"@nestjs/common": "^5.1.0",
"@nestjs/core": "^5.1.0",
"@nestjs/passport": "^1.1.0",
"@nestjs/swagger": "^2.2.0",
"@nestjs/typeorm": "^5.1.0",
"@nestjs/common": "^5.3.7",
"@nestjs/core": "^5.3.7",
"@nestjs/passport": "^5.1.0",
"@nestjs/swagger": "^2.5.1",
"@nestjs/typeorm": "^5.2.2",
"@types/passport-facebook-token": "^0.4.33",
"@types/passport-local": "^1.0.33",
"chmod": "^0.2.1",
Expand All @@ -83,7 +83,7 @@
"dotenv": "^6.0.0",
"fastify-formbody": "^2.0.1",
"jsonwebtoken": "^8.3.0",
"node-django-hashers": "^1.1.1",
"node-django-hashers": "^1.1.6",
"passport": "^0.4.0",
"passport-facebook-token": "^3.3.0",
"passport-google-plus-token": "^2.1.0",
Expand All @@ -102,32 +102,32 @@
"node_modules"
],
"devDependencies": {
"@nestjs/testing": "^5.1.0",
"@rucken/cli": "^3.1.1",
"@nestjs/testing": "^5.3.7",
"@rucken/cli": "^3.1.5",
"@types/dotenv": "^4.0.3",
"@types/express": "^4.16.0",
"@types/jest": "^23.3.1",
"@types/jest": "^23.3.2",
"@types/jsonwebtoken": "^7.2.8",
"@types/node": "^10.5.6",
"@types/supertest": "^2.0.5",
"conventional-changelog-cli": "^2.0.1",
"@types/node": "^10.10.1",
"@types/supertest": "^2.0.6",
"conventional-changelog-cli": "^2.0.5",
"conventional-commits-detector": "^0.1.1",
"conventional-recommended-bump": "^4.0.0",
"conventional-recommended-bump": "^4.0.1",
"cross-env": "^5.2.0",
"jest": "^23.4.2",
"nodemon": "^1.18.3",
"jest": "^23.6.0",
"nodemon": "^1.18.4",
"npm-run-all": "^4.1.3",
"pm2": "^3.0.4",
"prettier": "^1.14.0",
"pm2": "^3.1.3",
"prettier": "^1.14.3",
"showdown": "^1.8.6",
"supertest": "^3.1.0",
"ts-jest": "^23.1.2",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.0",
"tsconfig-paths": "^3.5.0",
"supertest": "^3.3.0",
"ts-jest": "^23.10.1",
"ts-loader": "^5.1.1",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.6.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.14.0",
"webpack": "^4.16.4",
"tslint-config-prettier": "^1.15.0",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.0",
"webpack-node-externals": "^1.7.2"
},
Expand All @@ -149,4 +149,4 @@
},
"coverageDirectory": "../coverage"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// workaround: wrong inject token
import { IAuthConfig } from '../interfaces/auth-config.interface';

export const defaultAuthConfig: IAuthConfig = {
debug: false,
demo: false,
port: 5000,
protocol: 'http',
domain: 'localhost'
};
export const AUTH_CONFIG_TOKEN: string = 'AuthConfigToken';
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import {
GOOGLE_PLUS_CONFIG_TOKEN
} from '../configs/google-plus.config';
import { defaultJwtConfig, JWT_CONFIG_TOKEN } from '../configs/jwt.config';
import { defaultAuthConfig, AUTH_CONFIG_TOKEN } from './auth.config';

export const configs = [
{
provide: AUTH_CONFIG_TOKEN,
useValue: defaultAuthConfig
},
{
provide: JWT_CONFIG_TOKEN,
useValue: defaultJwtConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,30 @@
import {
Body,
Controller,
Get,
HttpCode,
HttpStatus,
Post,
Req,
Inject,
Logger
} from '@nestjs/common';
import { Body, Controller, Get, HttpCode, HttpStatus, Inject, Logger, Post, Req } from '@nestjs/common';
import { ApiResponse, ApiUseTags } from '@nestjs/swagger';
import { OutAccountDto } from '@<%=name%>/core-nestjs';
import { plainToClass } from 'class-transformer';
import { UserTokenDto } from '../dto/user-token.dto';
import { JsonWebTokenError } from 'jsonwebtoken';
import { AUTH_CONFIG_TOKEN } from '../configs/auth.config';
import { FacebookSignInDto } from '../dto/facebook-signIn.dto';
import { FacebookTokenDto } from '../dto/facebook-token.dto';
import { GooglePlusSignInDto } from '../dto/google-plus-signIn.dto';
import { SignInDto } from '../dto/sign-in.dto';
import { RedirectUriDto } from '../dto/redirect-uri.dto';
import { SignInDto } from '../dto/sign-in.dto';
import { SignUpDto } from '../dto/sign-up.dto';
import { TokenDto } from '../dto/token.dto';
import { UserTokenDto } from '../dto/user-token.dto';
import { IAuthConfig } from '../interfaces/auth-config.interface';
import { IJwtPayload } from '../interfaces/jwt-payload.interface';
import { AuthService } from '../services/auth.service';
import { TokenService } from '../services/token.service';
import { IJwtPayload } from '../interfaces/jwt-payload.interface';
import {
OutAccountDto,
OutUserDto,
CORE_CONFIG_TOKEN,
ICoreConfig
} from '@<%=name%>/core-nestjs';
import { JsonWebTokenError } from 'jsonwebtoken';

@ApiUseTags('auth')
@Controller('/api/auth')
export class AuthController {
constructor(
@Inject(CORE_CONFIG_TOKEN) private readonly coreConfig: ICoreConfig,
@Inject(AUTH_CONFIG_TOKEN) private readonly authConfig: IAuthConfig,
private readonly authService: AuthService,
private readonly tokenService: TokenService
) {}
) { }
@HttpCode(HttpStatus.OK)
@Post('signin')
@ApiResponse({
Expand Down Expand Up @@ -109,7 +96,7 @@ export class AuthController {
AuthController.name + ':requestFacebookRedirectUrl#origin'
);
return this.authService.requestFacebookRedirectUri(
req.get('origin') || this.coreConfig.protocol + '://' + req.get('host')
req.get('origin') || this.authConfig.protocol + '://' + req.get('host')
);
}
@HttpCode(HttpStatus.OK)
Expand All @@ -128,7 +115,7 @@ export class AuthController {
);
return this.authService.facebookSignIn(
facebookSignInDto.code,
req.get('origin') || this.coreConfig.protocol + '://' + req.get('host')
req.get('origin') || this.authConfig.protocol + '://' + req.get('host')
);
}
@HttpCode(HttpStatus.OK)
Expand Down Expand Up @@ -156,7 +143,7 @@ export class AuthController {
AuthController.name + ':requestGoogleRedirectUri#origin'
);
return this.authService.requestGoogleRedirectUri(
req.get('origin') || this.coreConfig.protocol + '://' + req.get('host')
req.get('origin') || this.authConfig.protocol + '://' + req.get('host')
);
}
@HttpCode(HttpStatus.OK)
Expand All @@ -172,7 +159,7 @@ export class AuthController {
Logger.log(req.get('origin'), AuthController.name + ':googleSignIn#origin');
return this.authService.googleSignIn(
googleSignInDto.code,
req.get('origin') || this.coreConfig.protocol + '://' + req.get('host')
req.get('origin') || this.authConfig.protocol + '://' + req.get('host')
);
}
@HttpCode(HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// workaround: wrong inject token
export interface IAuthConfig {
debug: boolean;
demo: boolean;
port?: number;
externalPort?: number;
domain?: string;
protocol?: 'http' | 'https';
indexFile?: string;
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
import {
BadRequestException,
ConflictException,
HttpService,
Inject,
Injectable,
Logger
} from '@nestjs/common';
import {
CORE_CONFIG_TOKEN,
CustomError,
GroupsService,
ICoreConfig,
User,
UsersService
} from '@<%=name%>/core-nestjs';
import { BadRequestException, ConflictException, HttpService, Inject, Injectable, Logger } from '@nestjs/common';
import { CustomError, GroupsService, User, UsersService } from '@<%=name%>/core-nestjs';
import { plainToClass } from 'class-transformer';
import { stringify } from 'querystring';
import { map } from 'rxjs/operators';
import { AUTH_CONFIG_TOKEN } from '../configs/auth.config';
import { FACEBOOK_CONFIG_TOKEN } from '../configs/facebook.config';
import { GOOGLE_PLUS_CONFIG_TOKEN } from '../configs/google-plus.config';
import { SignInDto } from '../dto/sign-in.dto';
import { RedirectUriDto } from '../dto/redirect-uri.dto';
import { SignInDto } from '../dto/sign-in.dto';
import { SignUpDto } from '../dto/sign-up.dto';
import { IAuthConfig } from '../interfaces/auth-config.interface';
import { IFacebookConfig } from '../interfaces/facebook-config.interface';
import { IGooglePlusConfig } from '../interfaces/google-plus-config.interface';
@Injectable()
export class AuthService {
private localUri: string;

constructor(
@Inject(CORE_CONFIG_TOKEN) private readonly coreConfig: ICoreConfig,
@Inject(AUTH_CONFIG_TOKEN) private readonly authConfig: IAuthConfig,
@Inject(FACEBOOK_CONFIG_TOKEN) private readonly fbConfig: IFacebookConfig,
@Inject(GOOGLE_PLUS_CONFIG_TOKEN)
private readonly googlePlusConfig: IGooglePlusConfig,
private readonly httpService: HttpService,
private readonly usersService: UsersService,
private readonly groupsService: GroupsService
) {
if (this.coreConfig.port) {
this.localUri = `http://${this.coreConfig.domain}:${
this.coreConfig.port
}`;
if (this.authConfig.port) {
this.localUri = `http://${this.authConfig.domain}:${
this.authConfig.port
}`;
} else {
this.localUri = `http://${this.coreConfig.domain}`;
this.localUri = `http://${this.authConfig.domain}`;
}
}
async info(options: { id: number }) {
Expand Down Expand Up @@ -77,7 +65,7 @@ export class AuthService {
throw new ConflictException(
`User with email "${options.email}" is exists`
);
} catch (error) {}
} catch (error) { }
}
if (options.username) {
try {
Expand All @@ -87,7 +75,7 @@ export class AuthService {
throw new ConflictException(
`User with username "${options.username}" is exists`
);
} catch (error) {}
} catch (error) { }
}
const group = this.groupsService.getGroupByName({ name: 'user' });
const newUser = await plainToClass(User, options).setPassword(
Expand All @@ -104,7 +92,7 @@ export class AuthService {
];
const redirect_uri: string = `${
this.fbConfig.login_dialog_uri
}?${queryParams.join('&')}`.replace('{host}', host);
}?${queryParams.join('&')}`.replace('{host}', host);
Logger.log(redirect_uri, AuthService.name + ':requestFacebookRedirectUri');
return {
redirect_uri
Expand Down Expand Up @@ -161,9 +149,9 @@ export class AuthService {
);
throw new BadRequestException(
error &&
error.response &&
error.response.data &&
error.response.data.error
error.response &&
error.response.data &&
error.response.data.error
? error.response.data.error.message
: error.message
);
Expand All @@ -178,7 +166,7 @@ export class AuthService {
];
const redirect_uri: string = `${
this.googlePlusConfig.login_dialog_uri
}?${queryParams.join('&')}`.replace('{host}', host);
}?${queryParams.join('&')}`.replace('{host}', host);
Logger.log(redirect_uri, AuthService.name + ':requestGoogleRedirectUri');
return {
redirect_uri
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { Inject, Injectable, MethodNotAllowedException } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import {
CORE_CONFIG_TOKEN,
ICoreConfig,
UsersService
} from '@<%=name%>/core-nestjs';
import { Repository } from 'typeorm';
import { AUTH_CONFIG_TOKEN } from '../configs/auth.config';
import { OauthTokensAccesstoken } from '../entities/oauth-tokens-accesstoken.entity';
import { IAuthConfig } from '../interfaces/auth-config.interface';

@Injectable()
export class OauthTokensAccesstokensService {
constructor(
@Inject(CORE_CONFIG_TOKEN) private readonly coreConfig: ICoreConfig,
@Inject(AUTH_CONFIG_TOKEN) private readonly authConfig: IAuthConfig,
@InjectRepository(OauthTokensAccesstoken)
private readonly repository: Repository<OauthTokensAccesstoken>
) {}
) { }
async create(options: { item: OauthTokensAccesstoken }) {
try {
options.item = await this.repository.save(options.item);
Expand Down Expand Up @@ -82,9 +79,9 @@ export class OauthTokensAccesstokensService {
}
options.sort =
options.sort &&
new OauthTokensAccesstoken().hasOwnProperty(
options.sort.replace('-', '')
)
new OauthTokensAccesstoken().hasOwnProperty(
options.sort.replace('-', '')
)
? options.sort
: '-id';
const field = options.sort.replace('-', '');
Expand Down
1 change: 0 additions & 1 deletion src/nestjs/new/files/__root__/tslint.__json__
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"defaultSeverity": "error",
"extends": [
"tslint:recommended",
"tslint:latest",
"tslint-config-prettier"
],
"jsRules": {
Expand Down

0 comments on commit e8c76f5

Please sign in to comment.